mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 06:07:28 +00:00
fix(chat): preserve sender labels in dashboard history
This commit is contained in:
@@ -66,8 +66,9 @@ describe("stripEnvelopeFromMessage", () => {
|
||||
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 };
|
||||
const result = stripEnvelopeFromMessage(input) as { content?: string; senderLabel?: string };
|
||||
expect(result.content).toBe("Actual user message");
|
||||
expect(result.senderLabel).toBe("alice");
|
||||
});
|
||||
|
||||
test("strips metadata-like blocks even when not a prefix", () => {
|
||||
|
||||
@@ -1,8 +1,39 @@
|
||||
import { stripInboundMetadata } from "../auto-reply/reply/strip-inbound-meta.js";
|
||||
import {
|
||||
extractInboundSenderLabel,
|
||||
stripInboundMetadata,
|
||||
} from "../auto-reply/reply/strip-inbound-meta.js";
|
||||
import { stripEnvelope, stripMessageIdHints } from "../shared/chat-envelope.js";
|
||||
|
||||
export { stripEnvelope };
|
||||
|
||||
function extractMessageSenderLabel(entry: Record<string, unknown>): string | null {
|
||||
if (typeof entry.senderLabel === "string" && entry.senderLabel.trim()) {
|
||||
return entry.senderLabel.trim();
|
||||
}
|
||||
if (typeof entry.content === "string") {
|
||||
return extractInboundSenderLabel(entry.content);
|
||||
}
|
||||
if (Array.isArray(entry.content)) {
|
||||
for (const item of entry.content) {
|
||||
if (!item || typeof item !== "object") {
|
||||
continue;
|
||||
}
|
||||
const text = (item as { text?: unknown }).text;
|
||||
if (typeof text !== "string") {
|
||||
continue;
|
||||
}
|
||||
const senderLabel = extractInboundSenderLabel(text);
|
||||
if (senderLabel) {
|
||||
return senderLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof entry.text === "string") {
|
||||
return extractInboundSenderLabel(entry.text);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function stripEnvelopeFromContentWithRole(
|
||||
content: unknown[],
|
||||
stripUserEnvelope: boolean,
|
||||
@@ -42,6 +73,11 @@ export function stripEnvelopeFromMessage(message: unknown): unknown {
|
||||
|
||||
let changed = false;
|
||||
const next: Record<string, unknown> = { ...entry };
|
||||
const senderLabel = stripUserEnvelope ? extractMessageSenderLabel(entry) : null;
|
||||
if (senderLabel && entry.senderLabel !== senderLabel) {
|
||||
next.senderLabel = senderLabel;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (typeof entry.content === "string") {
|
||||
const inboundStripped = stripInboundMetadata(entry.content);
|
||||
|
||||
Reference in New Issue
Block a user