fix (webchat): omit direct conversation labels from inbound metadata context

This commit is contained in:
Vignesh Natarajan
2026-02-14 19:40:21 -08:00
parent d355fecd4d
commit a378fac081
2 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import type { TemplateContext } from "../templating.js";
import { buildInboundUserContextPrefix } from "./inbound-meta.js";
describe("buildInboundUserContextPrefix", () => {
it("omits conversation label block for direct chats", () => {
const text = buildInboundUserContextPrefix({
ChatType: "direct",
ConversationLabel: "openclaw-tui",
} as TemplateContext);
expect(text).toBe("");
});
it("keeps conversation label for group chats", () => {
const text = buildInboundUserContextPrefix({
ChatType: "group",
ConversationLabel: "ops-room",
} as TemplateContext);
expect(text).toContain("Conversation info (untrusted metadata):");
expect(text).toContain('"conversation_label": "ops-room"');
});
});

View File

@@ -52,7 +52,7 @@ export function buildInboundUserContextPrefix(ctx: TemplateContext): string {
const isDirect = !chatType || chatType === "direct";
const conversationInfo = {
conversation_label: safeTrim(ctx.ConversationLabel),
conversation_label: isDirect ? undefined : safeTrim(ctx.ConversationLabel),
group_subject: safeTrim(ctx.GroupSubject),
group_channel: safeTrim(ctx.GroupChannel),
group_space: safeTrim(ctx.GroupSpace),