fix(gateway): redact audio payloads from chat history · openclaw/openclaw@0e761cd
steipete
·
2026-04-23
·
via Recent Commits to openclaw:main
File tree
src/gateway/server-methods
| Original file line number | Diff line number | Diff line change |
|---|
@@ -700,6 +700,17 @@ function sanitizeChatHistoryContentBlock(
|
700 | 700 | entry.bytes = bytes; |
701 | 701 | changed = true; |
702 | 702 | } |
| 703 | +if (type === "audio" && entry.source && typeof entry.source === "object") { |
| 704 | +const source = { ...(entry.source as Record<string, unknown>) }; |
| 705 | +if (source.type === "base64" && typeof source.data === "string") { |
| 706 | +const bytes = Buffer.byteLength(source.data, "utf8"); |
| 707 | +delete source.data; |
| 708 | +source.omitted = true; |
| 709 | +source.bytes = bytes; |
| 710 | +entry.source = source; |
| 711 | +changed = true; |
| 712 | +} |
| 713 | +} |
703 | 714 | return { block: changed ? entry : block, changed }; |
704 | 715 | } |
705 | 716 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -263,6 +263,46 @@ describe("injectTimestamp", () => {
|
263 | 263 | }); |
264 | 264 | |
265 | 265 | describe("sanitizeChatHistoryMessages", () => { |
| 266 | +it("redacts base64 audio content blocks from chat history", () => { |
| 267 | +const data = Buffer.from("voice-bytes").toString("base64"); |
| 268 | +const result = sanitizeChatHistoryMessages([ |
| 269 | +{ |
| 270 | +role: "assistant", |
| 271 | +content: [ |
| 272 | +{ type: "text", text: "Audio reply" }, |
| 273 | +{ |
| 274 | +type: "audio", |
| 275 | +source: { |
| 276 | +type: "base64", |
| 277 | +media_type: "audio/mp3", |
| 278 | + data, |
| 279 | +}, |
| 280 | +}, |
| 281 | +], |
| 282 | +timestamp: 1, |
| 283 | +}, |
| 284 | +]); |
| 285 | + |
| 286 | +expect(result).toEqual([ |
| 287 | +{ |
| 288 | +role: "assistant", |
| 289 | +content: [ |
| 290 | +{ type: "text", text: "Audio reply" }, |
| 291 | +{ |
| 292 | +type: "audio", |
| 293 | +source: { |
| 294 | +type: "base64", |
| 295 | +media_type: "audio/mp3", |
| 296 | +omitted: true, |
| 297 | +bytes: Buffer.byteLength(data, "utf8"), |
| 298 | +}, |
| 299 | +}, |
| 300 | +], |
| 301 | +timestamp: 1, |
| 302 | +}, |
| 303 | +]); |
| 304 | +}); |
| 305 | + |
266 | 306 | it("drops commentary-only assistant entries when phase exists only in textSignature", () => { |
267 | 307 | const result = sanitizeChatHistoryMessages([ |
268 | 308 | { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。