


























1+import { describe, expect, it } from "vitest";
2+import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js";
3+import type { TelegramPromptContextEntry } from "./bot-message-context.types.js";
4+5+const telegramChatWindowContext: TelegramPromptContextEntry = {
6+label: "Conversation context",
7+source: "telegram",
8+type: "chat_window",
9+payload: {
10+order: "chronological",
11+relation: "selected_for_current_message",
12+messages: [
13+{
14+message_id: "10",
15+sender: "Pat",
16+timestamp_ms: 1_700_000_000_000,
17+body: "Earlier DM turn already in the transcript",
18+},
19+],
20+},
21+};
22+23+describe("buildTelegramMessageContext prompt context", () => {
24+it("omits Telegram chat-window context for existing unthreaded private DM sessions", async () => {
25+const ctx = await buildTelegramMessageContextForTest({
26+message: {
27+chat: { id: 1234, type: "private", first_name: "Pat" },
28+from: { id: 1234, first_name: "Pat" },
29+text: "continue",
30+},
31+promptContext: [telegramChatWindowContext],
32+sessionRuntime: {
33+readSessionUpdatedAt: ({ sessionKey }) =>
34+sessionKey === "agent:main:main" ? 1_700_000_000_000 : undefined,
35+},
36+});
37+38+expect(ctx?.ctxPayload.SessionKey).toBe("agent:main:main");
39+expect(ctx?.ctxPayload.UntrustedStructuredContext).toBeUndefined();
40+});
41+42+it("keeps Telegram chat-window context for fresh private DM sessions", async () => {
43+const ctx = await buildTelegramMessageContextForTest({
44+message: {
45+chat: { id: 1234, type: "private", first_name: "Pat" },
46+from: { id: 1234, first_name: "Pat" },
47+text: "start",
48+},
49+promptContext: [telegramChatWindowContext],
50+});
51+52+expect(ctx?.ctxPayload.UntrustedStructuredContext).toEqual([telegramChatWindowContext]);
53+});
54+55+it("keeps Telegram chat-window context for existing private DM replies", async () => {
56+const ctx = await buildTelegramMessageContextForTest({
57+message: {
58+chat: { id: 1234, type: "private", first_name: "Pat" },
59+from: { id: 1234, first_name: "Pat" },
60+text: "replying with context",
61+reply_to_message: {
62+chat: { id: 1234, type: "private", first_name: "Pat" },
63+from: { id: 1234, first_name: "Pat" },
64+text: "older referenced turn",
65+date: 1_700_000_000,
66+message_id: 10,
67+},
68+},
69+promptContext: [telegramChatWindowContext],
70+sessionRuntime: {
71+readSessionUpdatedAt: ({ sessionKey }) =>
72+sessionKey === "agent:main:main" ? 1_700_000_000_000 : undefined,
73+},
74+});
75+76+expect(ctx?.ctxPayload.UntrustedStructuredContext).toEqual([telegramChatWindowContext]);
77+});
78+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。