mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:08:26 +00:00
fix(ui): strip inbound metadata blocks and guard reply-tag streaming (clean rewrite) (#22346)
* fix(ui): strip inbound metadata blocks from user messages * chore: clean up metadata-strip format and changelog credit * Update src/shared/chat-envelope.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This commit is contained in:
@@ -39,4 +39,35 @@ describe("stripEnvelopeFromMessage", () => {
|
||||
const result = stripEnvelopeFromMessage(input) as { content?: string };
|
||||
expect(result.content).toBe("note\n[message_id: 123]");
|
||||
});
|
||||
test("removes inbound un-bracketed conversation info blocks from user messages", () => {
|
||||
const input = {
|
||||
role: "user",
|
||||
content:
|
||||
'Conversation info (untrusted metadata):\n```json\n{\n "message_id": "123"\n}\n```\n\nHello there',
|
||||
};
|
||||
const result = stripEnvelopeFromMessage(input) as { content?: string };
|
||||
expect(result.content).toBe("Hello there");
|
||||
});
|
||||
|
||||
test("removes all inbound metadata blocks before user text", () => {
|
||||
const input = {
|
||||
role: "user",
|
||||
content:
|
||||
'Thread starter (untrusted, for context):\n```json\n{"seed": 1}\n```\n\nSender (untrusted metadata):\n```json\n{"name": "alice"}\n```\n\nActual user message',
|
||||
};
|
||||
const result = stripEnvelopeFromMessage(input) as { content?: string };
|
||||
expect(result.content).toBe("Actual user message");
|
||||
});
|
||||
|
||||
test("does not strip metadata-like blocks that are not a prefix", () => {
|
||||
const input = {
|
||||
role: "user",
|
||||
content:
|
||||
'Actual text\nConversation info (untrusted metadata):\n```json\n{"message_id": "123"}\n```\n\nFollow-up',
|
||||
};
|
||||
const result = stripEnvelopeFromMessage(input) as { content?: string };
|
||||
expect(result.content).toBe(
|
||||
'Actual text\nConversation info (untrusted metadata):\n```json\n{"message_id": "123"}\n```\n\nFollow-up',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user