fix(auto-reply): move volatile inbound flags out of system metadata

Co-authored-by: aidiffuser <aidiffuser@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-23 19:05:57 +00:00
parent cf38339f25
commit 31e4c21b67
3 changed files with 49 additions and 11 deletions

View File

@@ -57,6 +57,24 @@ describe("buildInboundMetaSystemPrompt", () => {
expect(payload["sender_id"]).toBeUndefined();
});
it("does not include per-turn flags in system metadata", () => {
const prompt = buildInboundMetaSystemPrompt({
ReplyToBody: "quoted",
ForwardedFrom: "sender",
ThreadStarterBody: "starter",
InboundHistory: [{ sender: "a", body: "b", timestamp: 1 }],
WasMentioned: true,
OriginatingTo: "telegram:-1001249586642",
OriginatingChannel: "telegram",
Provider: "telegram",
Surface: "telegram",
ChatType: "group",
} as TemplateContext);
const payload = parseInboundMetaPayload(prompt);
expect(payload["flags"]).toBeUndefined();
});
it("omits sender_id when blank", () => {
const prompt = buildInboundMetaSystemPrompt({
MessageSid: "458",
@@ -183,6 +201,25 @@ describe("buildInboundUserContextPrefix", () => {
expect(conversationInfo["sender_id"]).toBe("289522496");
});
it("includes dynamic per-turn flags in conversation info", () => {
const text = buildInboundUserContextPrefix({
ChatType: "group",
WasMentioned: true,
ReplyToBody: "quoted",
ForwardedFrom: "sender",
ThreadStarterBody: "starter",
InboundHistory: [{ sender: "a", body: "b", timestamp: 1 }],
} as TemplateContext);
const conversationInfo = parseConversationInfoPayload(text);
expect(conversationInfo["is_group_chat"]).toBe(true);
expect(conversationInfo["was_mentioned"]).toBe(true);
expect(conversationInfo["has_reply_context"]).toBe(true);
expect(conversationInfo["has_forwarded_context"]).toBe(true);
expect(conversationInfo["has_thread_starter"]).toBe(true);
expect(conversationInfo["history_count"]).toBe(1);
});
it("trims sender_id in conversation info", () => {
const text = buildInboundUserContextPrefix({
ChatType: "group",