@livekit/agents 1.0.47 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/beta/index.cjs +29 -0
- package/dist/beta/index.cjs.map +1 -0
- package/dist/beta/index.d.cts +2 -0
- package/dist/beta/index.d.ts +2 -0
- package/dist/beta/index.d.ts.map +1 -0
- package/dist/beta/index.js +7 -0
- package/dist/beta/index.js.map +1 -0
- package/dist/beta/workflows/index.cjs +29 -0
- package/dist/beta/workflows/index.cjs.map +1 -0
- package/dist/beta/workflows/index.d.cts +2 -0
- package/dist/beta/workflows/index.d.ts +2 -0
- package/dist/beta/workflows/index.d.ts.map +1 -0
- package/dist/beta/workflows/index.js +7 -0
- package/dist/beta/workflows/index.js.map +1 -0
- package/dist/beta/workflows/task_group.cjs +162 -0
- package/dist/beta/workflows/task_group.cjs.map +1 -0
- package/dist/beta/workflows/task_group.d.cts +32 -0
- package/dist/beta/workflows/task_group.d.ts +32 -0
- package/dist/beta/workflows/task_group.d.ts.map +1 -0
- package/dist/beta/workflows/task_group.js +138 -0
- package/dist/beta/workflows/task_group.js.map +1 -0
- package/dist/cpu.cjs +189 -0
- package/dist/cpu.cjs.map +1 -0
- package/dist/cpu.d.cts +24 -0
- package/dist/cpu.d.ts +24 -0
- package/dist/cpu.d.ts.map +1 -0
- package/dist/cpu.js +152 -0
- package/dist/cpu.js.map +1 -0
- package/dist/cpu.test.cjs +227 -0
- package/dist/cpu.test.cjs.map +1 -0
- package/dist/cpu.test.js +204 -0
- package/dist/cpu.test.js.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inference/api_protos.d.cts +59 -59
- package/dist/inference/api_protos.d.ts +59 -59
- package/dist/inference/llm.cjs.map +1 -1
- package/dist/inference/llm.d.cts +1 -1
- package/dist/inference/llm.d.ts +1 -1
- package/dist/inference/llm.d.ts.map +1 -1
- package/dist/inference/llm.js.map +1 -1
- package/dist/inference/tts.cjs.map +1 -1
- package/dist/inference/tts.d.cts +6 -0
- package/dist/inference/tts.d.ts +6 -0
- package/dist/inference/tts.d.ts.map +1 -1
- package/dist/inference/tts.js.map +1 -1
- package/dist/llm/chat_context.cjs +89 -1
- package/dist/llm/chat_context.cjs.map +1 -1
- package/dist/llm/chat_context.d.cts +10 -1
- package/dist/llm/chat_context.d.ts +10 -1
- package/dist/llm/chat_context.d.ts.map +1 -1
- package/dist/llm/chat_context.js +89 -1
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/chat_context.test.cjs +43 -0
- package/dist/llm/chat_context.test.cjs.map +1 -1
- package/dist/llm/chat_context.test.js +43 -0
- package/dist/llm/chat_context.test.js.map +1 -1
- package/dist/llm/index.cjs +2 -0
- package/dist/llm/index.cjs.map +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +3 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/provider_format/index.d.cts +1 -1
- package/dist/llm/provider_format/index.d.ts +1 -1
- package/dist/llm/tool_context.cjs +7 -0
- package/dist/llm/tool_context.cjs.map +1 -1
- package/dist/llm/tool_context.d.cts +10 -2
- package/dist/llm/tool_context.d.ts +10 -2
- package/dist/llm/tool_context.d.ts.map +1 -1
- package/dist/llm/tool_context.js +6 -0
- package/dist/llm/tool_context.js.map +1 -1
- package/dist/utils.cjs +1 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/voice/agent.cjs +9 -0
- package/dist/voice/agent.cjs.map +1 -1
- package/dist/voice/agent.d.cts +1 -0
- package/dist/voice/agent.d.ts +1 -0
- package/dist/voice/agent.d.ts.map +1 -1
- package/dist/voice/agent.js +9 -0
- package/dist/voice/agent.js.map +1 -1
- package/dist/voice/agent_activity.cjs +67 -16
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +7 -0
- package/dist/voice/agent_activity.d.ts +7 -0
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +68 -17
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +27 -1
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +6 -0
- package/dist/voice/agent_session.d.ts +6 -0
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +27 -1
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/room_io/room_io.cjs +11 -2
- package/dist/voice/room_io/room_io.cjs.map +1 -1
- package/dist/voice/room_io/room_io.d.ts.map +1 -1
- package/dist/voice/room_io/room_io.js +12 -3
- package/dist/voice/room_io/room_io.js.map +1 -1
- package/dist/voice/testing/fake_llm.cjs +127 -0
- package/dist/voice/testing/fake_llm.cjs.map +1 -0
- package/dist/voice/testing/fake_llm.d.cts +30 -0
- package/dist/voice/testing/fake_llm.d.ts +30 -0
- package/dist/voice/testing/fake_llm.d.ts.map +1 -0
- package/dist/voice/testing/fake_llm.js +103 -0
- package/dist/voice/testing/fake_llm.js.map +1 -0
- package/dist/voice/testing/index.cjs +3 -0
- package/dist/voice/testing/index.cjs.map +1 -1
- package/dist/voice/testing/index.d.cts +1 -0
- package/dist/voice/testing/index.d.ts +1 -0
- package/dist/voice/testing/index.d.ts.map +1 -1
- package/dist/voice/testing/index.js +2 -0
- package/dist/voice/testing/index.js.map +1 -1
- package/dist/worker.cjs +6 -29
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +6 -19
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/beta/index.ts +9 -0
- package/src/beta/workflows/index.ts +9 -0
- package/src/beta/workflows/task_group.ts +194 -0
- package/src/cpu.test.ts +239 -0
- package/src/cpu.ts +173 -0
- package/src/index.ts +2 -1
- package/src/inference/llm.ts +2 -0
- package/src/inference/tts.ts +8 -1
- package/src/llm/chat_context.test.ts +48 -0
- package/src/llm/chat_context.ts +123 -0
- package/src/llm/index.ts +1 -0
- package/src/llm/tool_context.ts +14 -0
- package/src/utils.ts +5 -0
- package/src/voice/agent.ts +11 -0
- package/src/voice/agent_activity.ts +102 -16
- package/src/voice/agent_session.ts +33 -2
- package/src/voice/room_io/room_io.ts +14 -3
- package/src/voice/testing/fake_llm.ts +138 -0
- package/src/voice/testing/index.ts +2 -0
- package/src/worker.ts +34 -50
package/dist/llm/chat_context.js
CHANGED
|
@@ -36,19 +36,22 @@ class ChatMessage {
|
|
|
36
36
|
interrupted;
|
|
37
37
|
hash;
|
|
38
38
|
createdAt;
|
|
39
|
+
extra;
|
|
39
40
|
constructor(params) {
|
|
40
41
|
const {
|
|
41
42
|
role,
|
|
42
43
|
content,
|
|
43
44
|
id = shortuuid("item_"),
|
|
44
45
|
interrupted = false,
|
|
45
|
-
createdAt = Date.now()
|
|
46
|
+
createdAt = Date.now(),
|
|
47
|
+
extra = {}
|
|
46
48
|
} = params;
|
|
47
49
|
this.id = id;
|
|
48
50
|
this.role = role;
|
|
49
51
|
this.content = Array.isArray(content) ? content : [content];
|
|
50
52
|
this.interrupted = interrupted;
|
|
51
53
|
this.createdAt = createdAt;
|
|
54
|
+
this.extra = extra;
|
|
52
55
|
}
|
|
53
56
|
static create(params) {
|
|
54
57
|
return new ChatMessage(params);
|
|
@@ -284,11 +287,13 @@ class ChatContext {
|
|
|
284
287
|
const idx = this._items.findIndex((i) => i.id === itemId);
|
|
285
288
|
return idx !== -1 ? idx : void 0;
|
|
286
289
|
}
|
|
290
|
+
// TODO(parity): Add excludeConfigUpdate option when AgentConfigUpdate is ported
|
|
287
291
|
copy(options = {}) {
|
|
288
292
|
const {
|
|
289
293
|
excludeFunctionCall = false,
|
|
290
294
|
excludeInstructions = false,
|
|
291
295
|
excludeEmptyMessage = false,
|
|
296
|
+
excludeHandoff = false,
|
|
292
297
|
toolCtx
|
|
293
298
|
} = options;
|
|
294
299
|
const items = [];
|
|
@@ -304,6 +309,9 @@ class ChatContext {
|
|
|
304
309
|
if (excludeEmptyMessage && isChatMessage(item) && item.content.length === 0) {
|
|
305
310
|
continue;
|
|
306
311
|
}
|
|
312
|
+
if (excludeHandoff && item.type === "agent_handoff") {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
307
315
|
if (toolCtx !== void 0 && isToolCallOrOutput(item) && toolCtx[item.name] === void 0) {
|
|
308
316
|
continue;
|
|
309
317
|
}
|
|
@@ -311,6 +319,7 @@ class ChatContext {
|
|
|
311
319
|
}
|
|
312
320
|
return new ChatContext(items);
|
|
313
321
|
}
|
|
322
|
+
// TODO(parity): Add excludeConfigUpdate option when AgentConfigUpdate is ported
|
|
314
323
|
merge(other, options = {}) {
|
|
315
324
|
const { excludeFunctionCall = false, excludeInstructions = false } = options;
|
|
316
325
|
const existingIds = new Set(this._items.map((item) => item.id));
|
|
@@ -478,6 +487,85 @@ class ChatContext {
|
|
|
478
487
|
}
|
|
479
488
|
return true;
|
|
480
489
|
}
|
|
490
|
+
async _summarize(llm, options = {}) {
|
|
491
|
+
var _a, _b;
|
|
492
|
+
const { keepLastTurns = 2 } = options;
|
|
493
|
+
const toSummarize = [];
|
|
494
|
+
for (const item of this._items) {
|
|
495
|
+
if (item.type !== "message") continue;
|
|
496
|
+
if (item.role !== "user" && item.role !== "assistant") continue;
|
|
497
|
+
if (((_a = item.extra) == null ? void 0 : _a.is_summary) === true) continue;
|
|
498
|
+
const text = (item.textContent ?? "").trim();
|
|
499
|
+
if (text) {
|
|
500
|
+
toSummarize.push(item);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (toSummarize.length === 0) {
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
const tailN = Math.max(0, Math.min(toSummarize.length, keepLastTurns * 2));
|
|
507
|
+
let head;
|
|
508
|
+
let tail;
|
|
509
|
+
if (tailN === 0) {
|
|
510
|
+
head = toSummarize;
|
|
511
|
+
tail = [];
|
|
512
|
+
} else {
|
|
513
|
+
head = toSummarize.slice(0, -tailN);
|
|
514
|
+
tail = toSummarize.slice(-tailN);
|
|
515
|
+
}
|
|
516
|
+
if (head.length === 0) {
|
|
517
|
+
return this;
|
|
518
|
+
}
|
|
519
|
+
const sourceText = head.map((m) => `${m.role}: ${(m.textContent ?? "").trim()}`).join("\n").trim();
|
|
520
|
+
if (!sourceText) {
|
|
521
|
+
return this;
|
|
522
|
+
}
|
|
523
|
+
const promptCtx = new ChatContext();
|
|
524
|
+
promptCtx.addMessage({
|
|
525
|
+
role: "system",
|
|
526
|
+
content: "Compress older chat history into a short, faithful summary.\nFocus on user goals, constraints, decisions, key facts/preferences/entities, and pending tasks.\nExclude chit-chat and greetings. Be concise."
|
|
527
|
+
});
|
|
528
|
+
promptCtx.addMessage({
|
|
529
|
+
role: "user",
|
|
530
|
+
content: `Conversation to summarize:
|
|
531
|
+
|
|
532
|
+
${sourceText}`
|
|
533
|
+
});
|
|
534
|
+
const chunks = [];
|
|
535
|
+
for await (const chunk of llm.chat({ chatCtx: promptCtx })) {
|
|
536
|
+
if ((_b = chunk.delta) == null ? void 0 : _b.content) {
|
|
537
|
+
chunks.push(chunk.delta.content);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const summary = chunks.join("").trim();
|
|
541
|
+
if (!summary) {
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
const tailStartTs = tail.length > 0 ? tail[0].createdAt : Infinity;
|
|
545
|
+
const preserved = [];
|
|
546
|
+
for (const it of this._items) {
|
|
547
|
+
if ((it.type === "function_call" || it.type === "function_call_output") && it.createdAt < tailStartTs) {
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (it.type === "message" && (it.role === "user" || it.role === "assistant")) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
preserved.push(it);
|
|
554
|
+
}
|
|
555
|
+
this._items = preserved;
|
|
556
|
+
const createdAtHint = tail.length > 0 ? tail[0].createdAt - 1e-3 : head[head.length - 1].createdAt + 1e-3;
|
|
557
|
+
this.addMessage({
|
|
558
|
+
role: "assistant",
|
|
559
|
+
content: `[history summary]
|
|
560
|
+
${summary}`,
|
|
561
|
+
createdAt: createdAtHint,
|
|
562
|
+
extra: { is_summary: true }
|
|
563
|
+
});
|
|
564
|
+
for (const msg of tail) {
|
|
565
|
+
this.insert(msg);
|
|
566
|
+
}
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
481
569
|
/**
|
|
482
570
|
* Indicates whether the context is read-only
|
|
483
571
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/llm/chat_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AudioFrame, VideoFrame } from '@livekit/rtc-node';\nimport { createImmutableArray, shortuuid } from '../utils.js';\nimport { type ProviderFormat, toChatCtx } from './provider_format/index.js';\nimport type { JSONObject, JSONValue, ToolContext } from './tool_context.js';\n\nexport type ChatRole = 'developer' | 'system' | 'user' | 'assistant';\nexport interface ImageContent {\n id: string;\n\n type: 'image_content';\n\n /**\n * Either a string URL or a VideoFrame object.\n */\n image: string | VideoFrame;\n\n inferenceDetail: 'auto' | 'high' | 'low';\n\n inferenceWidth?: number;\n\n inferenceHeight?: number;\n\n mimeType?: string;\n\n _cache: Record<any, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AudioContent {\n type: 'audio_content';\n\n frame: AudioFrame[];\n\n transcript?: string;\n}\n\nexport type ChatContent = ImageContent | AudioContent | string;\n\nexport function createImageContent(params: {\n image: string | VideoFrame;\n id?: string;\n inferenceDetail?: 'auto' | 'high' | 'low';\n inferenceWidth?: number;\n inferenceHeight?: number;\n mimeType?: string;\n}): ImageContent {\n const {\n image,\n id = shortuuid('img_'),\n inferenceDetail = 'auto',\n inferenceWidth,\n inferenceHeight,\n mimeType,\n } = params;\n\n return {\n id,\n type: 'image_content',\n image,\n inferenceDetail,\n inferenceWidth,\n inferenceHeight,\n mimeType,\n _cache: {},\n };\n}\n\nexport function createAudioContent(params: {\n frame: AudioFrame[];\n transcript?: string;\n}): AudioContent {\n const { frame, transcript } = params;\n\n return {\n type: 'audio_content',\n frame,\n transcript,\n };\n}\n\nexport class ChatMessage {\n readonly id: string;\n\n readonly type = 'message' as const;\n\n readonly role: ChatRole;\n\n content: ChatContent[];\n\n interrupted: boolean;\n\n hash?: Uint8Array;\n\n createdAt: number;\n\n constructor(params: {\n role: ChatRole;\n content: ChatContent[] | string;\n id?: string;\n interrupted?: boolean;\n createdAt?: number;\n }) {\n const {\n role,\n content,\n id = shortuuid('item_'),\n interrupted = false,\n createdAt = Date.now(),\n } = params;\n this.id = id;\n this.role = role;\n this.content = Array.isArray(content) ? content : [content];\n this.interrupted = interrupted;\n this.createdAt = createdAt;\n }\n\n static create(params: {\n role: ChatRole;\n content: ChatContent[] | string;\n id?: string;\n interrupted?: boolean;\n createdAt?: number;\n }) {\n return new ChatMessage(params);\n }\n\n /**\n * Returns a single string with all text parts of the message joined by new\n * lines. If no string content is present, returns `null`.\n */\n get textContent(): string | undefined {\n const parts = this.content.filter((c): c is string => typeof c === 'string');\n return parts.length > 0 ? parts.join('\\n') : undefined;\n }\n\n toJSONContent(): JSONValue[] {\n return this.content.map((c) => {\n if (typeof c === 'string') {\n return c as JSONValue;\n } else if (c.type === 'image_content') {\n return {\n id: c.id,\n type: c.type,\n image: c.image,\n inferenceDetail: c.inferenceDetail,\n inferenceWidth: c.inferenceWidth,\n inferenceHeight: c.inferenceHeight,\n mimeType: c.mimeType,\n } as JSONObject;\n } else {\n return {\n type: c.type,\n transcript: c.transcript,\n } as JSONObject;\n }\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n role: this.role,\n content: this.toJSONContent(),\n interrupted: this.interrupted,\n };\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport class FunctionCall {\n readonly id: string;\n\n readonly type = 'function_call' as const;\n\n callId: string;\n\n args: string;\n\n name: string;\n\n createdAt: number;\n\n extra: Record<string, unknown>;\n /**\n * Optional grouping identifier for parallel tool calls.\n */\n groupId?: string;\n\n /**\n * Opaque signature for Gemini thinking mode.\n * When using Gemini 3+ models with thinking enabled, this signature must be\n * preserved and returned with function responses to maintain thought context.\n */\n thoughtSignature?: string;\n\n constructor(params: {\n callId: string;\n name: string;\n args: string;\n id?: string;\n createdAt?: number;\n extra?: Record<string, unknown>;\n groupId?: string;\n thoughtSignature?: string;\n }) {\n const {\n callId,\n name,\n args,\n id = shortuuid('item_'),\n createdAt = Date.now(),\n extra = {},\n groupId,\n thoughtSignature,\n } = params;\n this.id = id;\n this.callId = callId;\n this.args = args;\n this.name = name;\n this.createdAt = createdAt;\n this.extra = { ...extra };\n this.groupId = groupId;\n this.thoughtSignature =\n thoughtSignature ??\n (typeof this.extra.google === 'object' && this.extra.google !== null\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.extra.google as any).thoughtSignature ||\n (this.extra.google as any).thought_signature\n : undefined);\n }\n\n static create(params: {\n callId: string;\n name: string;\n args: string;\n id?: string;\n createdAt?: number;\n extra?: Record<string, unknown>;\n groupId?: string;\n thoughtSignature?: string;\n }) {\n return new FunctionCall(params);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n callId: this.callId,\n name: this.name,\n args: this.args,\n };\n\n if (Object.keys(this.extra).length > 0) {\n result.extra = this.extra as JSONValue;\n }\n\n if (this.groupId) {\n result.groupId = this.groupId;\n }\n\n if (this.thoughtSignature) {\n result.thoughtSignature = this.thoughtSignature;\n }\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport class FunctionCallOutput {\n readonly id: string;\n\n readonly type = 'function_call_output' as const;\n\n name = '';\n\n callId: string;\n\n output: string;\n\n isError: boolean;\n\n createdAt: number;\n\n constructor(params: {\n callId: string;\n output: string;\n isError: boolean;\n id?: string;\n createdAt?: number;\n name?: string;\n }) {\n const {\n callId,\n output,\n isError,\n id = shortuuid('item_'),\n createdAt = Date.now(),\n name = '',\n } = params;\n this.id = id;\n this.callId = callId;\n this.output = output;\n this.isError = isError;\n this.name = name;\n this.createdAt = createdAt;\n }\n\n static create(params: {\n callId: string;\n output: string;\n isError: boolean;\n id?: string;\n createdAt?: number;\n name?: string;\n }) {\n return new FunctionCallOutput(params);\n }\n\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n name: this.name,\n callId: this.callId,\n output: this.output,\n isError: this.isError,\n };\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport class AgentHandoffItem {\n readonly id: string;\n\n readonly type = 'agent_handoff' as const;\n\n oldAgentId: string | undefined;\n\n newAgentId: string;\n\n createdAt: number;\n\n constructor(params: {\n oldAgentId?: string;\n newAgentId: string;\n id?: string;\n createdAt?: number;\n }) {\n const { oldAgentId, newAgentId, id = shortuuid('item_'), createdAt = Date.now() } = params;\n this.id = id;\n this.oldAgentId = oldAgentId;\n this.newAgentId = newAgentId;\n this.createdAt = createdAt;\n }\n\n static create(params: {\n oldAgentId?: string;\n newAgentId: string;\n id?: string;\n createdAt?: number;\n }) {\n return new AgentHandoffItem(params);\n }\n\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n newAgentId: this.newAgentId,\n };\n\n if (this.oldAgentId !== undefined) {\n result.oldAgentId = this.oldAgentId;\n }\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport type ChatItem = ChatMessage | FunctionCall | FunctionCallOutput | AgentHandoffItem;\n\nexport class ChatContext {\n protected _items: ChatItem[];\n\n constructor(items?: ChatItem[]) {\n this._items = items ? items : [];\n }\n\n static empty(): ChatContext {\n return new ChatContext([]);\n }\n\n get items(): ChatItem[] {\n return this._items;\n }\n\n set items(items: ChatItem[]) {\n this._items = items;\n }\n\n /**\n * Add a new message to the context and return it.\n */\n addMessage(params: {\n role: ChatRole;\n content: ChatContent[] | string;\n id?: string;\n interrupted?: boolean;\n createdAt?: number;\n }): ChatMessage {\n const msg = new ChatMessage(params);\n if (params.createdAt !== undefined) {\n const idx = this.findInsertionIndex(params.createdAt);\n this._items.splice(idx, 0, msg);\n } else {\n this._items.push(msg);\n }\n return msg;\n }\n\n /**\n * Insert a single item or multiple items based on their `createdAt` field so\n * that the array keeps its chronological order.\n */\n insert(item: ChatItem | ChatItem[]): void {\n const arr = Array.isArray(item) ? item : [item];\n for (const it of arr) {\n const idx = this.findInsertionIndex(it.createdAt);\n this._items.splice(idx, 0, it);\n }\n }\n\n getById(itemId: string): ChatItem | undefined {\n return this._items.find((i) => i.id === itemId);\n }\n\n indexById(itemId: string): number | undefined {\n const idx = this._items.findIndex((i) => i.id === itemId);\n return idx !== -1 ? idx : undefined;\n }\n\n copy(\n options: {\n excludeFunctionCall?: boolean;\n excludeInstructions?: boolean;\n excludeEmptyMessage?: boolean;\n toolCtx?: ToolContext<any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n } = {},\n ): ChatContext {\n const {\n excludeFunctionCall = false,\n excludeInstructions = false,\n excludeEmptyMessage = false,\n toolCtx,\n } = options;\n const items: ChatItem[] = [];\n\n const isToolCallOrOutput = (item: ChatItem): item is FunctionCall | FunctionCallOutput =>\n ['function_call', 'function_call_output'].includes(item.type);\n const isChatMessage = (item: ChatItem): item is ChatMessage => item.type === 'message';\n\n for (const item of this._items) {\n if (excludeFunctionCall && isToolCallOrOutput(item)) {\n continue;\n }\n\n if (\n excludeInstructions &&\n isChatMessage(item) &&\n ['system', 'developer'].includes(item.role)\n ) {\n continue;\n }\n\n if (excludeEmptyMessage && isChatMessage(item) && item.content.length === 0) {\n continue;\n }\n\n if (toolCtx !== undefined && isToolCallOrOutput(item) && toolCtx[item.name] === undefined) {\n continue;\n }\n\n items.push(item);\n }\n\n return new ChatContext(items);\n }\n\n merge(\n other: ChatContext,\n options: {\n excludeFunctionCall?: boolean;\n excludeInstructions?: boolean;\n } = {},\n ): ChatContext {\n const { excludeFunctionCall = false, excludeInstructions = false } = options;\n const existingIds = new Set(this._items.map((item) => item.id));\n\n for (const item of other.items) {\n if (excludeFunctionCall && ['function_call', 'function_call_output'].includes(item.type)) {\n continue;\n }\n\n if (\n excludeInstructions &&\n item.type === 'message' &&\n (item.role === 'system' || item.role === 'developer')\n ) {\n continue;\n }\n\n if (existingIds.has(item.id)) {\n continue;\n }\n\n const idx = this.findInsertionIndex(item.createdAt);\n this._items.splice(idx, 0, item);\n existingIds.add(item.id);\n }\n\n return this;\n }\n\n truncate(maxItems: number): ChatContext {\n if (maxItems <= 0) return this;\n\n const instructions = this._items.find((i) => i.type === 'message' && i.role === 'system') as\n | ChatMessage\n | undefined;\n\n let newItems = this._items.slice(-maxItems);\n\n // Ensure the first item is not a function-call artefact.\n while (\n newItems.length > 0 &&\n ['function_call', 'function_call_output'].includes(newItems[0]!.type)\n ) {\n newItems.shift();\n }\n\n if (instructions) {\n // At this point `instructions` is defined, so it is safe to pass to `includes`.\n if (!newItems.includes(instructions)) {\n newItems = [instructions, ...newItems];\n }\n }\n\n // replace the items in place to keep the reference\n this._items.splice(0, this._items.length, ...newItems);\n return this;\n }\n\n toJSON(\n options: {\n excludeImage?: boolean;\n excludeAudio?: boolean;\n excludeTimestamp?: boolean;\n excludeFunctionCall?: boolean;\n } = {},\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): JSONObject {\n const {\n excludeImage = true,\n excludeAudio = true,\n excludeTimestamp = true,\n excludeFunctionCall = false,\n } = options;\n\n const items: ChatItem[] = [];\n\n for (const item of this._items) {\n let processedItem = item;\n\n if (excludeFunctionCall && ['function_call', 'function_call_output'].includes(item.type)) {\n continue;\n }\n\n if (item.type === 'message') {\n processedItem = ChatMessage.create({\n role: item.role,\n content: item.content,\n id: item.id,\n interrupted: item.interrupted,\n createdAt: item.createdAt,\n });\n\n // Filter content based on options\n if (excludeImage) {\n processedItem.content = processedItem.content.filter((c) => {\n return !(typeof c === 'object' && c.type === 'image_content');\n });\n }\n\n if (excludeAudio) {\n processedItem.content = processedItem.content.filter((c) => {\n return !(typeof c === 'object' && c.type === 'audio_content');\n });\n }\n }\n\n items.push(processedItem);\n }\n\n return {\n items: items.map((item) => item.toJSON(excludeTimestamp)),\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async toProviderFormat(format: ProviderFormat, injectDummyUserMessage: boolean = true) {\n return await toChatCtx(format, this, injectDummyUserMessage);\n }\n\n /**\n * Internal helper used by `truncate` & `addMessage` to find the correct\n * insertion index for a timestamp so the list remains sorted.\n */\n private findInsertionIndex(createdAt: number): number {\n for (let i = this._items.length - 1; i >= 0; i -= 1) {\n const item = this._items[i];\n if (item!.createdAt <= createdAt) {\n return i + 1;\n }\n }\n return 0;\n }\n\n /**\n * Return true if `other` has the same sequence of items with matching\n * essential fields (IDs, types, and payload) as this context.\n *\n * Comparison rules:\n * - Messages: compares the full `content` list, `role` and `interrupted`.\n * - Function calls: compares `name`, `callId`, and `args`.\n * - Function call outputs: compares `name`, `callId`, `output`, and `isError`.\n *\n * Does not consider timestamps or other metadata.\n */\n isEquivalent(other: ChatContext): boolean {\n if (this === other) {\n return true;\n }\n\n if (this.items.length !== other.items.length) {\n return false;\n }\n\n for (let i = 0; i < this.items.length; i++) {\n const a = this.items[i]!;\n const b = other.items[i]!;\n\n if (a.id !== b.id || a.type !== b.type) {\n return false;\n }\n\n if (a.type === 'message' && b.type === 'message') {\n if (\n a.role !== b.role ||\n a.interrupted !== b.interrupted ||\n !this.compareContent(a.content, b.content)\n ) {\n return false;\n }\n } else if (a.type === 'function_call' && b.type === 'function_call') {\n if (\n a.name !== b.name ||\n a.callId !== b.callId ||\n a.args !== b.args ||\n a.thoughtSignature !== b.thoughtSignature ||\n a.groupId !== b.groupId ||\n JSON.stringify(a.extra) !== JSON.stringify(b.extra)\n ) {\n return false;\n }\n } else if (a.type === 'function_call_output' && b.type === 'function_call_output') {\n if (\n a.name !== b.name ||\n a.callId !== b.callId ||\n a.output !== b.output ||\n a.isError !== b.isError\n ) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n /**\n * Compare two content arrays for equality.\n */\n private compareContent(a: ChatContent[], b: ChatContent[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n for (let i = 0; i < a.length; i++) {\n const contentA = a[i]!;\n const contentB = b[i]!;\n\n if (typeof contentA === 'string' && typeof contentB === 'string') {\n if (contentA !== contentB) {\n return false;\n }\n continue;\n }\n\n if (typeof contentA !== typeof contentB) {\n return false;\n }\n\n if (typeof contentA === 'object' && typeof contentB === 'object') {\n if (contentA.type === 'image_content' && contentB.type === 'image_content') {\n if (\n contentA.id !== contentB.id ||\n contentA.image !== contentB.image ||\n contentA.inferenceDetail !== contentB.inferenceDetail ||\n contentA.inferenceWidth !== contentB.inferenceWidth ||\n contentA.inferenceHeight !== contentB.inferenceHeight ||\n contentA.mimeType !== contentB.mimeType\n ) {\n return false;\n }\n } else if (contentA.type === 'audio_content' && contentB.type === 'audio_content') {\n if (contentA.frame.length !== contentB.frame.length) {\n return false;\n }\n if (contentA.transcript !== contentB.transcript) {\n return false;\n }\n } else {\n return false;\n }\n }\n }\n\n return true;\n }\n\n /**\n * Indicates whether the context is read-only\n */\n get readonly(): boolean {\n return false;\n }\n}\n\nexport class ReadonlyChatContext extends ChatContext {\n static readonly errorMsg =\n 'Please use .copy() and agent.update_chat_ctx() to modify the chat context.';\n\n constructor(items: ChatItem[]) {\n super(createImmutableArray(items, ReadonlyChatContext.errorMsg));\n }\n\n get items(): ChatItem[] {\n return this._items;\n }\n\n set items(items: ChatItem[]) {\n throw new Error(\n `Cannot set items on a read-only chat context. ${ReadonlyChatContext.errorMsg}`,\n );\n }\n\n get readonly(): boolean {\n return true;\n }\n}\n"],"mappings":"AAIA,SAAS,sBAAsB,iBAAiB;AAChD,SAA8B,iBAAiB;AAmCxC,SAAS,mBAAmB,QAOlB;AACf,QAAM;AAAA,IACJ;AAAA,IACA,KAAK,UAAU,MAAM;AAAA,IACrB,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,CAAC;AAAA,EACX;AACF;AAEO,SAAS,mBAAmB,QAGlB;AACf,QAAM,EAAE,OAAO,WAAW,IAAI;AAE9B,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAY;AAAA,EACd;AAAA,EAEA,OAAO;AAAA,EAEP;AAAA,EAET;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA,YAAY,QAMT;AACD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,KAAK,UAAU,OAAO;AAAA,MACtB,cAAc;AAAA,MACd,YAAY,KAAK,IAAI;AAAA,IACvB,IAAI;AACJ,SAAK,KAAK;AACV,SAAK,OAAO;AACZ,SAAK,UAAU,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAC1D,SAAK,cAAc;AACnB,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,OAAO,OAAO,QAMX;AACD,WAAO,IAAI,YAAY,MAAM;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAA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A;AAAA;AAAA;AAAA,EAKA,IAAI,WAAoB;AACtB,WAAO;AAAA,EACT;AACF;AAEO,MAAM,4BAA4B,YAAY;AAAA,EACnD,OAAgB,WACd;AAAA,EAEF,YAAY,OAAmB;AAC7B,UAAM,qBAAqB,OAAO,oBAAoB,QAAQ,CAAC;AAAA,EACjE;AAAA,EAEA,IAAI,QAAoB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,MAAM,OAAmB;AAC3B,UAAM,IAAI;AAAA,MACR,iDAAiD,oBAAoB,QAAQ;AAAA,IAC/E;AAAA,EACF;AAAA,EAEA,IAAI,WAAoB;AACtB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/llm/chat_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AudioFrame, VideoFrame } from '@livekit/rtc-node';\nimport { createImmutableArray, shortuuid } from '../utils.js';\nimport type { LLM } from './llm.js';\nimport { type ProviderFormat, toChatCtx } from './provider_format/index.js';\nimport type { JSONObject, JSONValue, ToolContext } from './tool_context.js';\n\nexport type ChatRole = 'developer' | 'system' | 'user' | 'assistant';\nexport interface ImageContent {\n id: string;\n\n type: 'image_content';\n\n /**\n * Either a string URL or a VideoFrame object.\n */\n image: string | VideoFrame;\n\n inferenceDetail: 'auto' | 'high' | 'low';\n\n inferenceWidth?: number;\n\n inferenceHeight?: number;\n\n mimeType?: string;\n\n _cache: Record<any, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AudioContent {\n type: 'audio_content';\n\n frame: AudioFrame[];\n\n transcript?: string;\n}\n\nexport type ChatContent = ImageContent | AudioContent | string;\n\nexport function createImageContent(params: {\n image: string | VideoFrame;\n id?: string;\n inferenceDetail?: 'auto' | 'high' | 'low';\n inferenceWidth?: number;\n inferenceHeight?: number;\n mimeType?: string;\n}): ImageContent {\n const {\n image,\n id = shortuuid('img_'),\n inferenceDetail = 'auto',\n inferenceWidth,\n inferenceHeight,\n mimeType,\n } = params;\n\n return {\n id,\n type: 'image_content',\n image,\n inferenceDetail,\n inferenceWidth,\n inferenceHeight,\n mimeType,\n _cache: {},\n };\n}\n\nexport function createAudioContent(params: {\n frame: AudioFrame[];\n transcript?: string;\n}): AudioContent {\n const { frame, transcript } = params;\n\n return {\n type: 'audio_content',\n frame,\n transcript,\n };\n}\n\nexport class ChatMessage {\n readonly id: string;\n\n readonly type = 'message' as const;\n\n readonly role: ChatRole;\n\n content: ChatContent[];\n\n interrupted: boolean;\n\n hash?: Uint8Array;\n\n createdAt: number;\n\n extra: Record<string, unknown>;\n\n constructor(params: {\n role: ChatRole;\n content: ChatContent[] | string;\n id?: string;\n interrupted?: boolean;\n createdAt?: number;\n extra?: Record<string, unknown>;\n }) {\n const {\n role,\n content,\n id = shortuuid('item_'),\n interrupted = false,\n createdAt = Date.now(),\n extra = {},\n } = params;\n this.id = id;\n this.role = role;\n this.content = Array.isArray(content) ? content : [content];\n this.interrupted = interrupted;\n this.createdAt = createdAt;\n this.extra = extra;\n }\n\n static create(params: {\n role: ChatRole;\n content: ChatContent[] | string;\n id?: string;\n interrupted?: boolean;\n createdAt?: number;\n extra?: Record<string, unknown>;\n }) {\n return new ChatMessage(params);\n }\n\n /**\n * Returns a single string with all text parts of the message joined by new\n * lines. If no string content is present, returns `null`.\n */\n get textContent(): string | undefined {\n const parts = this.content.filter((c): c is string => typeof c === 'string');\n return parts.length > 0 ? parts.join('\\n') : undefined;\n }\n\n toJSONContent(): JSONValue[] {\n return this.content.map((c) => {\n if (typeof c === 'string') {\n return c as JSONValue;\n } else if (c.type === 'image_content') {\n return {\n id: c.id,\n type: c.type,\n image: c.image,\n inferenceDetail: c.inferenceDetail,\n inferenceWidth: c.inferenceWidth,\n inferenceHeight: c.inferenceHeight,\n mimeType: c.mimeType,\n } as JSONObject;\n } else {\n return {\n type: c.type,\n transcript: c.transcript,\n } as JSONObject;\n }\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n role: this.role,\n content: this.toJSONContent(),\n interrupted: this.interrupted,\n };\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport class FunctionCall {\n readonly id: string;\n\n readonly type = 'function_call' as const;\n\n callId: string;\n\n args: string;\n\n name: string;\n\n createdAt: number;\n\n extra: Record<string, unknown>;\n /**\n * Optional grouping identifier for parallel tool calls.\n */\n groupId?: string;\n\n /**\n * Opaque signature for Gemini thinking mode.\n * When using Gemini 3+ models with thinking enabled, this signature must be\n * preserved and returned with function responses to maintain thought context.\n */\n thoughtSignature?: string;\n\n constructor(params: {\n callId: string;\n name: string;\n args: string;\n id?: string;\n createdAt?: number;\n extra?: Record<string, unknown>;\n groupId?: string;\n thoughtSignature?: string;\n }) {\n const {\n callId,\n name,\n args,\n id = shortuuid('item_'),\n createdAt = Date.now(),\n extra = {},\n groupId,\n thoughtSignature,\n } = params;\n this.id = id;\n this.callId = callId;\n this.args = args;\n this.name = name;\n this.createdAt = createdAt;\n this.extra = { ...extra };\n this.groupId = groupId;\n this.thoughtSignature =\n thoughtSignature ??\n (typeof this.extra.google === 'object' && this.extra.google !== null\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.extra.google as any).thoughtSignature ||\n (this.extra.google as any).thought_signature\n : undefined);\n }\n\n static create(params: {\n callId: string;\n name: string;\n args: string;\n id?: string;\n createdAt?: number;\n extra?: Record<string, unknown>;\n groupId?: string;\n thoughtSignature?: string;\n }) {\n return new FunctionCall(params);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n callId: this.callId,\n name: this.name,\n args: this.args,\n };\n\n if (Object.keys(this.extra).length > 0) {\n result.extra = this.extra as JSONValue;\n }\n\n if (this.groupId) {\n result.groupId = this.groupId;\n }\n\n if (this.thoughtSignature) {\n result.thoughtSignature = this.thoughtSignature;\n }\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport class FunctionCallOutput {\n readonly id: string;\n\n readonly type = 'function_call_output' as const;\n\n name = '';\n\n callId: string;\n\n output: string;\n\n isError: boolean;\n\n createdAt: number;\n\n constructor(params: {\n callId: string;\n output: string;\n isError: boolean;\n id?: string;\n createdAt?: number;\n name?: string;\n }) {\n const {\n callId,\n output,\n isError,\n id = shortuuid('item_'),\n createdAt = Date.now(),\n name = '',\n } = params;\n this.id = id;\n this.callId = callId;\n this.output = output;\n this.isError = isError;\n this.name = name;\n this.createdAt = createdAt;\n }\n\n static create(params: {\n callId: string;\n output: string;\n isError: boolean;\n id?: string;\n createdAt?: number;\n name?: string;\n }) {\n return new FunctionCallOutput(params);\n }\n\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n name: this.name,\n callId: this.callId,\n output: this.output,\n isError: this.isError,\n };\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\nexport class AgentHandoffItem {\n readonly id: string;\n\n readonly type = 'agent_handoff' as const;\n\n oldAgentId: string | undefined;\n\n newAgentId: string;\n\n createdAt: number;\n\n constructor(params: {\n oldAgentId?: string;\n newAgentId: string;\n id?: string;\n createdAt?: number;\n }) {\n const { oldAgentId, newAgentId, id = shortuuid('item_'), createdAt = Date.now() } = params;\n this.id = id;\n this.oldAgentId = oldAgentId;\n this.newAgentId = newAgentId;\n this.createdAt = createdAt;\n }\n\n static create(params: {\n oldAgentId?: string;\n newAgentId: string;\n id?: string;\n createdAt?: number;\n }) {\n return new AgentHandoffItem(params);\n }\n\n toJSON(excludeTimestamp: boolean = false): JSONValue {\n const result: JSONValue = {\n id: this.id,\n type: this.type,\n newAgentId: this.newAgentId,\n };\n\n if (this.oldAgentId !== undefined) {\n result.oldAgentId = this.oldAgentId;\n }\n\n if (!excludeTimestamp) {\n result.createdAt = this.createdAt;\n }\n\n return result;\n }\n}\n\n// TODO(parity): Add AgentConfigUpdate type to ChatItem union\nexport type ChatItem = ChatMessage | FunctionCall | FunctionCallOutput | AgentHandoffItem;\n\nexport class ChatContext {\n protected _items: ChatItem[];\n\n constructor(items?: ChatItem[]) {\n this._items = items ? items : [];\n }\n\n static empty(): ChatContext {\n return new ChatContext([]);\n }\n\n get items(): ChatItem[] {\n return this._items;\n }\n\n set items(items: ChatItem[]) {\n this._items = items;\n }\n\n /**\n * Add a new message to the context and return it.\n */\n addMessage(params: {\n role: ChatRole;\n content: ChatContent[] | string;\n id?: string;\n interrupted?: boolean;\n createdAt?: number;\n extra?: Record<string, unknown>;\n }): ChatMessage {\n const msg = new ChatMessage(params);\n if (params.createdAt !== undefined) {\n const idx = this.findInsertionIndex(params.createdAt);\n this._items.splice(idx, 0, msg);\n } else {\n this._items.push(msg);\n }\n return msg;\n }\n\n /**\n * Insert a single item or multiple items based on their `createdAt` field so\n * that the array keeps its chronological order.\n */\n insert(item: ChatItem | ChatItem[]): void {\n const arr = Array.isArray(item) ? item : [item];\n for (const it of arr) {\n const idx = this.findInsertionIndex(it.createdAt);\n this._items.splice(idx, 0, it);\n }\n }\n\n getById(itemId: string): ChatItem | undefined {\n return this._items.find((i) => i.id === itemId);\n }\n\n indexById(itemId: string): number | undefined {\n const idx = this._items.findIndex((i) => i.id === itemId);\n return idx !== -1 ? idx : undefined;\n }\n\n // TODO(parity): Add excludeConfigUpdate option when AgentConfigUpdate is ported\n copy(\n options: {\n excludeFunctionCall?: boolean;\n excludeInstructions?: boolean;\n excludeEmptyMessage?: boolean;\n excludeHandoff?: boolean;\n toolCtx?: ToolContext<any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n } = {},\n ): ChatContext {\n const {\n excludeFunctionCall = false,\n excludeInstructions = false,\n excludeEmptyMessage = false,\n excludeHandoff = false,\n toolCtx,\n } = options;\n const items: ChatItem[] = [];\n\n const isToolCallOrOutput = (item: ChatItem): item is FunctionCall | FunctionCallOutput =>\n ['function_call', 'function_call_output'].includes(item.type);\n const isChatMessage = (item: ChatItem): item is ChatMessage => item.type === 'message';\n\n for (const item of this._items) {\n if (excludeFunctionCall && isToolCallOrOutput(item)) {\n continue;\n }\n\n if (\n excludeInstructions &&\n isChatMessage(item) &&\n ['system', 'developer'].includes(item.role)\n ) {\n continue;\n }\n\n if (excludeEmptyMessage && isChatMessage(item) && item.content.length === 0) {\n continue;\n }\n\n if (excludeHandoff && item.type === 'agent_handoff') {\n continue;\n }\n\n if (toolCtx !== undefined && isToolCallOrOutput(item) && toolCtx[item.name] === undefined) {\n continue;\n }\n\n items.push(item);\n }\n\n return new ChatContext(items);\n }\n\n // TODO(parity): Add excludeConfigUpdate option when AgentConfigUpdate is ported\n merge(\n other: ChatContext,\n options: {\n excludeFunctionCall?: boolean;\n excludeInstructions?: boolean;\n } = {},\n ): ChatContext {\n const { excludeFunctionCall = false, excludeInstructions = false } = options;\n const existingIds = new Set(this._items.map((item) => item.id));\n\n for (const item of other.items) {\n if (excludeFunctionCall && ['function_call', 'function_call_output'].includes(item.type)) {\n continue;\n }\n\n if (\n excludeInstructions &&\n item.type === 'message' &&\n (item.role === 'system' || item.role === 'developer')\n ) {\n continue;\n }\n\n if (existingIds.has(item.id)) {\n continue;\n }\n\n const idx = this.findInsertionIndex(item.createdAt);\n this._items.splice(idx, 0, item);\n existingIds.add(item.id);\n }\n\n return this;\n }\n\n truncate(maxItems: number): ChatContext {\n if (maxItems <= 0) return this;\n\n const instructions = this._items.find((i) => i.type === 'message' && i.role === 'system') as\n | ChatMessage\n | undefined;\n\n let newItems = this._items.slice(-maxItems);\n\n // Ensure the first item is not a function-call artefact.\n while (\n newItems.length > 0 &&\n ['function_call', 'function_call_output'].includes(newItems[0]!.type)\n ) {\n newItems.shift();\n }\n\n if (instructions) {\n // At this point `instructions` is defined, so it is safe to pass to `includes`.\n if (!newItems.includes(instructions)) {\n newItems = [instructions, ...newItems];\n }\n }\n\n // replace the items in place to keep the reference\n this._items.splice(0, this._items.length, ...newItems);\n return this;\n }\n\n toJSON(\n options: {\n excludeImage?: boolean;\n excludeAudio?: boolean;\n excludeTimestamp?: boolean;\n excludeFunctionCall?: boolean;\n } = {},\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): JSONObject {\n const {\n excludeImage = true,\n excludeAudio = true,\n excludeTimestamp = true,\n excludeFunctionCall = false,\n } = options;\n\n const items: ChatItem[] = [];\n\n for (const item of this._items) {\n let processedItem = item;\n\n if (excludeFunctionCall && ['function_call', 'function_call_output'].includes(item.type)) {\n continue;\n }\n\n if (item.type === 'message') {\n processedItem = ChatMessage.create({\n role: item.role,\n content: item.content,\n id: item.id,\n interrupted: item.interrupted,\n createdAt: item.createdAt,\n });\n\n // Filter content based on options\n if (excludeImage) {\n processedItem.content = processedItem.content.filter((c) => {\n return !(typeof c === 'object' && c.type === 'image_content');\n });\n }\n\n if (excludeAudio) {\n processedItem.content = processedItem.content.filter((c) => {\n return !(typeof c === 'object' && c.type === 'audio_content');\n });\n }\n }\n\n items.push(processedItem);\n }\n\n return {\n items: items.map((item) => item.toJSON(excludeTimestamp)),\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async toProviderFormat(format: ProviderFormat, injectDummyUserMessage: boolean = true) {\n return await toChatCtx(format, this, injectDummyUserMessage);\n }\n\n /**\n * Internal helper used by `truncate` & `addMessage` to find the correct\n * insertion index for a timestamp so the list remains sorted.\n */\n private findInsertionIndex(createdAt: number): number {\n for (let i = this._items.length - 1; i >= 0; i -= 1) {\n const item = this._items[i];\n if (item!.createdAt <= createdAt) {\n return i + 1;\n }\n }\n return 0;\n }\n\n /**\n * Return true if `other` has the same sequence of items with matching\n * essential fields (IDs, types, and payload) as this context.\n *\n * Comparison rules:\n * - Messages: compares the full `content` list, `role` and `interrupted`.\n * - Function calls: compares `name`, `callId`, and `args`.\n * - Function call outputs: compares `name`, `callId`, `output`, and `isError`.\n *\n * Does not consider timestamps or other metadata.\n */\n isEquivalent(other: ChatContext): boolean {\n if (this === other) {\n return true;\n }\n\n if (this.items.length !== other.items.length) {\n return false;\n }\n\n for (let i = 0; i < this.items.length; i++) {\n const a = this.items[i]!;\n const b = other.items[i]!;\n\n if (a.id !== b.id || a.type !== b.type) {\n return false;\n }\n\n if (a.type === 'message' && b.type === 'message') {\n if (\n a.role !== b.role ||\n a.interrupted !== b.interrupted ||\n !this.compareContent(a.content, b.content)\n ) {\n return false;\n }\n } else if (a.type === 'function_call' && b.type === 'function_call') {\n if (\n a.name !== b.name ||\n a.callId !== b.callId ||\n a.args !== b.args ||\n a.thoughtSignature !== b.thoughtSignature ||\n a.groupId !== b.groupId ||\n JSON.stringify(a.extra) !== JSON.stringify(b.extra)\n ) {\n return false;\n }\n } else if (a.type === 'function_call_output' && b.type === 'function_call_output') {\n if (\n a.name !== b.name ||\n a.callId !== b.callId ||\n a.output !== b.output ||\n a.isError !== b.isError\n ) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n /**\n * Compare two content arrays for equality.\n */\n private compareContent(a: ChatContent[], b: ChatContent[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n for (let i = 0; i < a.length; i++) {\n const contentA = a[i]!;\n const contentB = b[i]!;\n\n if (typeof contentA === 'string' && typeof contentB === 'string') {\n if (contentA !== contentB) {\n return false;\n }\n continue;\n }\n\n if (typeof contentA !== typeof contentB) {\n return false;\n }\n\n if (typeof contentA === 'object' && typeof contentB === 'object') {\n if (contentA.type === 'image_content' && contentB.type === 'image_content') {\n if (\n contentA.id !== contentB.id ||\n contentA.image !== contentB.image ||\n contentA.inferenceDetail !== contentB.inferenceDetail ||\n contentA.inferenceWidth !== contentB.inferenceWidth ||\n contentA.inferenceHeight !== contentB.inferenceHeight ||\n contentA.mimeType !== contentB.mimeType\n ) {\n return false;\n }\n } else if (contentA.type === 'audio_content' && contentB.type === 'audio_content') {\n if (contentA.frame.length !== contentB.frame.length) {\n return false;\n }\n if (contentA.transcript !== contentB.transcript) {\n return false;\n }\n } else {\n return false;\n }\n }\n }\n\n return true;\n }\n\n async _summarize(llm: LLM, options: { keepLastTurns?: number } = {}): Promise<ChatContext> {\n const { keepLastTurns = 2 } = options;\n\n const toSummarize: ChatMessage[] = [];\n for (const item of this._items) {\n if (item.type !== 'message') continue;\n if (item.role !== 'user' && item.role !== 'assistant') continue;\n if (item.extra?.is_summary === true) continue;\n\n const text = (item.textContent ?? '').trim();\n if (text) {\n toSummarize.push(item);\n }\n }\n\n if (toSummarize.length === 0) {\n return this;\n }\n\n const tailN = Math.max(0, Math.min(toSummarize.length, keepLastTurns * 2));\n let head: ChatMessage[];\n let tail: ChatMessage[];\n if (tailN === 0) {\n head = toSummarize;\n tail = [];\n } else {\n head = toSummarize.slice(0, -tailN);\n tail = toSummarize.slice(-tailN);\n }\n\n if (head.length === 0) {\n return this;\n }\n\n const sourceText = head\n .map((m) => `${m.role}: ${(m.textContent ?? '').trim()}`)\n .join('\\n')\n .trim();\n\n if (!sourceText) {\n return this;\n }\n\n // TODO: refactor this into LLMStream.collect API.\n const promptCtx = new ChatContext();\n promptCtx.addMessage({\n role: 'system',\n content:\n 'Compress older chat history into a short, faithful summary.\\n' +\n 'Focus on user goals, constraints, decisions, key facts/preferences/entities, and pending tasks.\\n' +\n 'Exclude chit-chat and greetings. Be concise.',\n });\n promptCtx.addMessage({\n role: 'user',\n content: `Conversation to summarize:\\n\\n${sourceText}`,\n });\n\n const chunks: string[] = [];\n for await (const chunk of llm.chat({ chatCtx: promptCtx })) {\n if (chunk.delta?.content) {\n chunks.push(chunk.delta.content);\n }\n }\n\n const summary = chunks.join('').trim();\n if (!summary) {\n return this;\n }\n\n const tailStartTs = tail.length > 0 ? tail[0]!.createdAt : Infinity;\n\n const preserved: ChatItem[] = [];\n for (const it of this._items) {\n if (\n (it.type === 'function_call' || it.type === 'function_call_output') &&\n it.createdAt < tailStartTs\n ) {\n continue;\n }\n\n if (it.type === 'message' && (it.role === 'user' || it.role === 'assistant')) {\n continue;\n }\n\n preserved.push(it);\n }\n\n this._items = preserved;\n\n const createdAtHint =\n tail.length > 0 ? tail[0]!.createdAt - 1e-3 : head[head.length - 1]!.createdAt + 1e-3;\n\n this.addMessage({\n role: 'assistant',\n content: `[history summary]\\n${summary}`,\n createdAt: createdAtHint,\n extra: { is_summary: true },\n });\n\n for (const msg of tail) {\n this.insert(msg);\n }\n\n return this;\n }\n\n /**\n * Indicates whether the context is read-only\n */\n get readonly(): boolean {\n return false;\n }\n}\n\nexport class ReadonlyChatContext extends ChatContext {\n static readonly errorMsg =\n 'Please use .copy() and agent.update_chat_ctx() to modify the chat context.';\n\n constructor(items: ChatItem[]) {\n super(createImmutableArray(items, ReadonlyChatContext.errorMsg));\n }\n\n get items(): ChatItem[] {\n return this._items;\n }\n\n set items(items: ChatItem[]) {\n throw new Error(\n `Cannot set items on a read-only chat context. ${ReadonlyChatContext.errorMsg}`,\n );\n }\n\n get readonly(): boolean {\n return true;\n }\n}\n"],"mappings":"AAIA,SAAS,sBAAsB,iBAAiB;AAEhD,SAA8B,iBAAiB;AAmCxC,SAAS,mBAAmB,QAOlB;AACf,QAAM;AAAA,IACJ;AAAA,IACA,KAAK,UAAU,MAAM;AAAA,IACrB,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,CAAC;AAAA,EACX;AACF;AAEO,SAAS,mBAAmB,QAGlB;AACf,QAAM,EAAE,OAAO,WAAW,IAAI;AAE9B,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAY;AAAA,EACd;AAAA,EAEA,OAAO;AAAA,EAEP;AAAA,EAET;AAAA,EAEA;AAA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A,MACN,SAAS;AAAA,EAAsB,OAAO;AAAA,MACtC,WAAW;AAAA,MACX,OAAO,EAAE,YAAY,KAAK;AAAA,IAC5B,CAAC;AAED,eAAW,OAAO,MAAM;AACtB,WAAK,OAAO,GAAG;AAAA,IACjB;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,WAAoB;AACtB,WAAO;AAAA,EACT;AACF;AAEO,MAAM,4BAA4B,YAAY;AAAA,EACnD,OAAgB,WACd;AAAA,EAEF,YAAY,OAAmB;AAC7B,UAAM,qBAAqB,OAAO,oBAAoB,QAAQ,CAAC;AAAA,EACjE;AAAA,EAEA,IAAI,QAAoB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,MAAM,OAAmB;AAC3B,UAAM,IAAI;AAAA,MACR,iDAAiD,oBAAoB,QAAQ;AAAA,IAC/E;AAAA,EACF;AAAA,EAEA,IAAI,WAAoB;AACtB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var import_vitest = require("vitest");
|
|
3
|
+
var import_log = require("../log.cjs");
|
|
4
|
+
var import_fake_llm = require("../voice/testing/fake_llm.cjs");
|
|
3
5
|
var import_chat_context = require("./chat_context.cjs");
|
|
6
|
+
(0, import_log.initializeLogger)({ pretty: false, level: "error" });
|
|
4
7
|
(0, import_vitest.describe)("ChatContext.toJSON", () => {
|
|
5
8
|
(0, import_vitest.it)("should match snapshot for empty context", () => {
|
|
6
9
|
const context = new import_chat_context.ChatContext();
|
|
@@ -232,6 +235,46 @@ var import_chat_context = require("./chat_context.cjs");
|
|
|
232
235
|
).toMatchSnapshot("message-properties-full");
|
|
233
236
|
});
|
|
234
237
|
});
|
|
238
|
+
(0, import_vitest.describe)("ChatContext._summarize", () => {
|
|
239
|
+
(0, import_vitest.it)("keeps chronological timestamps with summary + tail", async () => {
|
|
240
|
+
const ctx = new import_chat_context.ChatContext();
|
|
241
|
+
ctx.addMessage({ role: "system", content: "System prompt", createdAt: 0 });
|
|
242
|
+
ctx.addMessage({ role: "user", content: "hello", createdAt: 1e3 });
|
|
243
|
+
ctx.addMessage({ role: "assistant", content: "hi there", createdAt: 2e3 });
|
|
244
|
+
ctx.insert(
|
|
245
|
+
new import_chat_context.FunctionCallOutput({
|
|
246
|
+
callId: "call_1",
|
|
247
|
+
name: "lookup",
|
|
248
|
+
output: '{"ok":true}',
|
|
249
|
+
isError: false,
|
|
250
|
+
createdAt: 3500
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
ctx.addMessage({ role: "user", content: "my color is blue", createdAt: 3e3 });
|
|
254
|
+
ctx.addMessage({ role: "assistant", content: "noted", createdAt: 4e3 });
|
|
255
|
+
const fake = new import_fake_llm.FakeLLM([
|
|
256
|
+
{
|
|
257
|
+
input: "Conversation to summarize:\n\nuser: hello\nassistant: hi there",
|
|
258
|
+
content: "condensed head"
|
|
259
|
+
}
|
|
260
|
+
]);
|
|
261
|
+
await ctx._summarize(fake, { keepLastTurns: 1 });
|
|
262
|
+
const summary = ctx.items.find(
|
|
263
|
+
(item) => {
|
|
264
|
+
var _a;
|
|
265
|
+
return item.type === "message" && item.role === "assistant" && ((_a = item.extra) == null ? void 0 : _a.is_summary) === true;
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
(0, import_vitest.expect)(summary).toBeDefined();
|
|
269
|
+
if (!summary || summary.type !== "message") {
|
|
270
|
+
throw new Error("summary message is missing");
|
|
271
|
+
}
|
|
272
|
+
(0, import_vitest.expect)(summary.createdAt).toBeCloseTo(2999.999, 6);
|
|
273
|
+
const createdAts = ctx.items.map((item) => item.createdAt);
|
|
274
|
+
const sorted = [...createdAts].sort((a, b) => a - b);
|
|
275
|
+
(0, import_vitest.expect)(createdAts).toEqual(sorted);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
235
278
|
(0, import_vitest.describe)("ReadonlyChatContext with immutable array", () => {
|
|
236
279
|
(0, import_vitest.it)("should have readonly property set to true", () => {
|
|
237
280
|
const items = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/llm/chat_context.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { describe, expect, it } from 'vitest';\nimport {\n type AudioContent,\n ChatContext,\n type ChatItem,\n ChatMessage,\n FunctionCall,\n FunctionCallOutput,\n type ImageContent,\n ReadonlyChatContext,\n} from './chat_context.js';\n\ndescribe('ChatContext.toJSON', () => {\n it('should match snapshot for empty context', () => {\n const context = new ChatContext();\n expect(context.toJSON()).toMatchSnapshot();\n });\n\n it('should match snapshot for simple conversation', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'msg_system_1',\n role: 'system',\n content: 'You are a helpful assistant.',\n createdAt: 1000000000,\n });\n\n context.addMessage({\n id: 'msg_user_1',\n role: 'user',\n content: 'Hello, how are you?',\n createdAt: 1000000001,\n });\n\n context.addMessage({\n id: 'msg_assistant_1',\n role: 'assistant',\n content: \"I'm doing well, thank you! How can I help you today?\",\n createdAt: 1000000002,\n });\n\n expect(context.toJSON()).toMatchSnapshot('simple-conversation-no-timestamps');\n\n expect(context.toJSON({ excludeTimestamp: false })).toMatchSnapshot(\n 'simple-conversation-with-timestamps',\n );\n });\n\n it('should match snapshot for multimodal content', () => {\n const context = new ChatContext();\n\n const imageContent: ImageContent = {\n id: 'img_test_1',\n type: 'image_content',\n image: 'https://example.com/test-image.jpg',\n inferenceDetail: 'high',\n inferenceWidth: 1024,\n inferenceHeight: 768,\n mimeType: 'image/jpeg',\n _cache: {},\n };\n\n const audioContent: AudioContent = {\n type: 'audio_content',\n frame: [], // This won't be included in JSON\n transcript: 'This is a test audio transcript',\n };\n\n context.addMessage({\n id: 'msg_user_2',\n role: 'user',\n content: [\n 'Check out this image and audio:',\n imageContent,\n audioContent,\n 'What do you think?',\n ],\n createdAt: 2000000000,\n });\n\n expect(context.toJSON()).toMatchSnapshot('multimodal-default-exclusions');\n\n expect(\n context.toJSON({\n excludeImage: false,\n excludeAudio: true,\n }),\n ).toMatchSnapshot('multimodal-with-images-only');\n\n expect(\n context.toJSON({\n excludeImage: true,\n excludeAudio: false,\n }),\n ).toMatchSnapshot('multimodal-with-audio-only');\n\n expect(\n context.toJSON({\n excludeImage: false,\n excludeAudio: false,\n excludeTimestamp: false,\n }),\n ).toMatchSnapshot('multimodal-full-content');\n });\n\n it('should match snapshot for function calls', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'msg_user_3',\n role: 'user',\n content: \"What's the weather in Paris?\",\n createdAt: 3000000000,\n });\n\n const functionCall = new FunctionCall({\n id: 'func_call_1',\n callId: 'call_weather_123',\n name: 'get_weather',\n args: '{\"location\": \"Paris, France\", \"unit\": \"celsius\"}',\n createdAt: 3000000001,\n });\n context.insert(functionCall);\n\n const functionOutput = new FunctionCallOutput({\n id: 'func_output_1',\n callId: 'call_weather_123',\n name: 'get_weather',\n output: '{\"temperature\": 22, \"condition\": \"partly cloudy\", \"humidity\": 65}',\n isError: false,\n createdAt: 3000000002,\n });\n context.insert(functionOutput);\n\n context.addMessage({\n id: 'msg_assistant_2',\n role: 'assistant',\n content: 'The weather in Paris is currently 22°C and partly cloudy with 65% humidity.',\n createdAt: 3000000003,\n });\n\n expect(context.toJSON()).toMatchSnapshot('conversation-with-function-calls');\n\n expect(\n context.toJSON({\n excludeFunctionCall: true,\n }),\n ).toMatchSnapshot('conversation-without-function-calls');\n\n expect(\n context.toJSON({\n excludeTimestamp: false,\n }),\n ).toMatchSnapshot('conversation-with-function-calls-and-timestamps');\n });\n\n it('should match snapshot for edge cases', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'msg_empty_1',\n role: 'user',\n content: [],\n createdAt: 5000000000,\n });\n\n const silentAudio: AudioContent = {\n type: 'audio_content',\n frame: [],\n transcript: undefined,\n };\n\n context.addMessage({\n id: 'msg_silent_audio',\n role: 'user',\n content: [silentAudio],\n createdAt: 5000000001,\n });\n\n context.addMessage({\n id: 'msg_multi_text',\n role: 'assistant',\n content: ['Part 1. ', 'Part 2. ', 'Part 3.'],\n createdAt: 5000000002,\n });\n\n const minimalCall = new FunctionCall({\n id: 'func_minimal',\n callId: 'minimal',\n name: 'test',\n args: '{}',\n createdAt: 5000000003,\n });\n context.insert(minimalCall);\n\n const namelessOutput = new FunctionCallOutput({\n id: 'func_output_nameless',\n callId: 'minimal',\n output: 'OK',\n isError: false,\n createdAt: 5000000004,\n });\n context.insert(namelessOutput);\n\n context.addMessage({\n id: 'msg_special_chars',\n role: 'user',\n content:\n 'Test with special chars: \\n\\t\\r \"quotes\" \\'apostrophes\\' \\\\backslashes\\\\ {braces} [brackets]',\n createdAt: 5000000005,\n });\n\n expect(context.toJSON()).toMatchSnapshot('edge-cases-default');\n expect(\n context.toJSON({\n excludeTimestamp: false,\n excludeAudio: false,\n }),\n ).toMatchSnapshot('edge-cases-with-details');\n });\n\n it('should match snapshot for message property variations', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'custom-message-id-123',\n role: 'user',\n content: 'Message with custom ID',\n createdAt: 6000000000,\n });\n\n context.addMessage({\n id: 'msg_interrupted',\n role: 'assistant',\n content: 'This response was interrupted...',\n interrupted: true,\n createdAt: 6000000001,\n });\n\n context.addMessage({\n id: 'msg_dev_2',\n role: 'developer',\n content: 'Developer message',\n createdAt: 6000000002,\n });\n\n context.addMessage({\n id: 'msg_system_3',\n role: 'system',\n content: 'System message',\n createdAt: 6000000003,\n });\n\n const detailedImage: ImageContent = {\n id: 'img_detailed',\n type: 'image_content',\n image: 'https://example.com/image.jpg',\n inferenceDetail: 'low',\n inferenceWidth: 512,\n inferenceHeight: 512,\n mimeType: 'image/png',\n _cache: { cached: true },\n };\n\n context.addMessage({\n id: 'msg_with_image',\n role: 'user',\n content: ['Image with all properties:', detailedImage],\n createdAt: 6000000004,\n });\n\n expect(context.toJSON()).toMatchSnapshot('message-properties-default');\n expect(\n context.toJSON({\n excludeImage: false,\n excludeTimestamp: false,\n }),\n ).toMatchSnapshot('message-properties-full');\n });\n});\n\ndescribe('ReadonlyChatContext with immutable array', () => {\n it('should have readonly property set to true', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n\n expect(readonlyContext.readonly).toBe(true);\n });\n\n it('should prevent setting items property', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n expect(() => {\n readonlyContext.items = [];\n }).toThrow(\n `Cannot set items on a read-only chat context. Please use .copy() and agent.update_chat_ctx() to modify the chat context.`,\n );\n });\n\n it('should prevent modifications through array methods', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n const newItem = new ChatMessage({\n id: 'msg_2',\n role: 'assistant',\n content: ['Response'],\n interrupted: false,\n createdAt: Date.now(),\n });\n\n const mutableItems = readonlyContext.items;\n expect(() => mutableItems.push(newItem)).toThrow(\n 'Cannot call push() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.pop()).toThrow(\n 'Cannot call pop() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.shift()).toThrow(\n 'Cannot call shift() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.unshift(newItem)).toThrow(\n 'Cannot call unshift() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.splice(0, 1)).toThrow(\n 'Cannot call splice() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.sort()).toThrow(\n 'Cannot call sort() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.reverse()).toThrow(\n 'Cannot call reverse() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.fill(newItem)).toThrow(\n 'Cannot call fill() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.copyWithin(0, 1)).toThrow(\n 'Cannot call copyWithin() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n });\n\n it('should prevent bracket notation assignment and deletion', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n const newItem = new ChatMessage({\n id: 'msg_2',\n role: 'assistant',\n content: ['Response'],\n interrupted: false,\n createdAt: Date.now(),\n });\n\n expect(() => {\n readonlyContext.items[0] = newItem;\n }).toThrow(\n 'Cannot assign to read-only array index \"0\". Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => {\n delete readonlyContext.items[0];\n }).toThrow(\n 'Cannot delete read-only array index \"0\". Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => {\n readonlyContext.items[99] = newItem;\n }).toThrow(\n 'Cannot assign to read-only array index \"99\". Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n });\n\n it('should allow read operations on the immutable array', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test 1'],\n interrupted: false,\n createdAt: 1000,\n }),\n new ChatMessage({\n id: 'msg_2',\n role: 'assistant',\n content: ['Test 2'],\n interrupted: false,\n createdAt: 2000,\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n\n expect(readonlyContext.items.length).toBe(2);\n expect(readonlyContext.items[0]).toEqual(items[0]);\n expect(readonlyContext.items[1]).toEqual(items[1]);\n expect(readonlyContext.items.find((item: ChatItem) => item.id === 'msg_2')).toEqual(items[1]);\n expect(readonlyContext.items.map((item: ChatItem) => item.id)).toEqual(['msg_1', 'msg_2']);\n expect(\n readonlyContext.items.filter(\n (item: ChatItem) => item.type === 'message' && item.role === 'user',\n ),\n ).toHaveLength(1);\n\n // forEach should work for reading\n const ids: string[] = [];\n readonlyContext.items.forEach((item) => ids.push(item.id));\n expect(ids).toEqual(['msg_1', 'msg_2']);\n });\n});\n\ndescribe('ChatContext.isEquivalent', () => {\n it('should return true for same reference', () => {\n const ctx = new ChatContext();\n ctx.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n expect(ctx.isEquivalent(ctx)).toBe(true);\n });\n\n it('should return true for identical empty contexts', () => {\n const ctx1 = new ChatContext();\n const ctx2 = new ChatContext();\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for contexts with different lengths', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n ctx2.addMessage({\n id: 'msg_2',\n role: 'assistant',\n content: 'Hi',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for contexts with different item IDs', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_2',\n role: 'user',\n content: 'Hello',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for contexts with different item types', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'msg_1',\n callId: 'call_1',\n name: 'test',\n args: '{}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n describe('message comparison', () => {\n it('should return true for identical messages', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: false,\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: false,\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for messages with different roles', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'assistant',\n content: 'Hello',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for messages with different interrupted flags', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: false,\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: true,\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for messages with different content', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'World',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return true for messages with identical array content', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello', 'World'],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello', 'World'],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for messages with different array content', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello', 'World'],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello'],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return true for messages with identical image content', () => {\n const imageContent: ImageContent = {\n id: 'img_1',\n type: 'image_content',\n image: 'https://example.com/image.jpg',\n inferenceDetail: 'high',\n inferenceWidth: 1024,\n inferenceHeight: 768,\n mimeType: 'image/jpeg',\n _cache: {},\n };\n\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', imageContent],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', { ...imageContent }],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for messages with different image content', () => {\n const imageContent1: ImageContent = {\n id: 'img_1',\n type: 'image_content',\n image: 'https://example.com/image1.jpg',\n inferenceDetail: 'high',\n _cache: {},\n };\n\n const imageContent2: ImageContent = {\n id: 'img_2',\n type: 'image_content',\n image: 'https://example.com/image2.jpg',\n inferenceDetail: 'high',\n _cache: {},\n };\n\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', imageContent1],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', imageContent2],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n });\n\n describe('function call comparison', () => {\n it('should return true for identical function calls', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for function calls with different names', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_time',\n args: '{}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function calls with different call IDs', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_2',\n name: 'get_weather',\n args: '{}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function calls with different arguments', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"London\"}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should ignore timestamps', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n createdAt: 1000,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n createdAt: 2000,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n });\n\n describe('function call output comparison', () => {\n it('should return true for identical function call outputs', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for function call outputs with different names', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_time',\n output: '{}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function call outputs with different call IDs', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_2',\n name: 'get_weather',\n output: '{}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function call outputs with different output values', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 25}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function call outputs with different error flags', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: 'Error occurred',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: 'Error occurred',\n isError: true,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should ignore timestamps', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n createdAt: 1000,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n createdAt: 2000,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n });\n\n describe('complex context comparison', () => {\n it('should return true for identical complex contexts', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'What is the weather?',\n });\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n ctx1.addMessage({\n id: 'msg_2',\n role: 'assistant',\n content: 'The weather is 22°C',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'What is the weather?',\n });\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n ctx2.addMessage({\n id: 'msg_2',\n role: 'assistant',\n content: 'The weather is 22°C',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n });\n});\n"],"mappings":";AAGA,oBAAqC;AACrC,0BASO;AAAA,IAEP,wBAAS,sBAAsB,MAAM;AACnC,wBAAG,2CAA2C,MAAM;AAClD,UAAM,UAAU,IAAI,gCAAY;AAChC,8BAAO,QAAQ,OAAO,CAAC,EAAE,gBAAgB;AAAA,EAC3C,CAAC;AAED,wBAAG,iDAAiD,MAAM;AACxD,UAAM,UAAU,IAAI,gCAAY;AAEhC,YAAQ,WAAW;AAAA,MACjB,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,MACT,WAAW;AAAA,IACb,CAAC;AAED,YAAQ,WAAW;AAAA,MACjB,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,MACT,WAAW;AAAA,IACb,CAAC;AAED,YAAQ,WAAW;AAAA,MACjB,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,MACT,WAAW;AAAA,IACb,CAAC;AAED,8BAAO,QAAQ,OAAO,CAAC,EAAE,gBAAgB,mCAAmC;AAE5E,8BAAO,QAAQ,OAAO,EAAE,kBAAkB,MAAM,CAAC,CAAC,EAAE;AAAA,MAClD;AAAA,IACF;AAAA,EACF,CAAC;AAED,wBAAG,gDAAgD,MAAM;AACvD,UAAM,UAAU,IAAI,gCAAY;AAEhC,UAAM,eAA6B;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,MACP,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,UAAU;AAAA,MACV,QAAQ,CAAC;AAAA,IACX;AAEA,UAAM,eAA6B;AAAA,MACjC,MAAM;AAAA,MACN,OAAO,CAAC;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AAS;AAAA,MACX,CAAC;AAED,gCAAO,KAAK,aAAa,IAAI,CAAC,EAAE,KAAK,IAAI;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/llm/chat_context.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { describe, expect, it } from 'vitest';\nimport { initializeLogger } from '../log.js';\nimport { FakeLLM } from '../voice/testing/fake_llm.js';\nimport {\n type AudioContent,\n ChatContext,\n type ChatItem,\n ChatMessage,\n FunctionCall,\n FunctionCallOutput,\n type ImageContent,\n ReadonlyChatContext,\n} from './chat_context.js';\n\ninitializeLogger({ pretty: false, level: 'error' });\n\ndescribe('ChatContext.toJSON', () => {\n it('should match snapshot for empty context', () => {\n const context = new ChatContext();\n expect(context.toJSON()).toMatchSnapshot();\n });\n\n it('should match snapshot for simple conversation', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'msg_system_1',\n role: 'system',\n content: 'You are a helpful assistant.',\n createdAt: 1000000000,\n });\n\n context.addMessage({\n id: 'msg_user_1',\n role: 'user',\n content: 'Hello, how are you?',\n createdAt: 1000000001,\n });\n\n context.addMessage({\n id: 'msg_assistant_1',\n role: 'assistant',\n content: \"I'm doing well, thank you! How can I help you today?\",\n createdAt: 1000000002,\n });\n\n expect(context.toJSON()).toMatchSnapshot('simple-conversation-no-timestamps');\n\n expect(context.toJSON({ excludeTimestamp: false })).toMatchSnapshot(\n 'simple-conversation-with-timestamps',\n );\n });\n\n it('should match snapshot for multimodal content', () => {\n const context = new ChatContext();\n\n const imageContent: ImageContent = {\n id: 'img_test_1',\n type: 'image_content',\n image: 'https://example.com/test-image.jpg',\n inferenceDetail: 'high',\n inferenceWidth: 1024,\n inferenceHeight: 768,\n mimeType: 'image/jpeg',\n _cache: {},\n };\n\n const audioContent: AudioContent = {\n type: 'audio_content',\n frame: [], // This won't be included in JSON\n transcript: 'This is a test audio transcript',\n };\n\n context.addMessage({\n id: 'msg_user_2',\n role: 'user',\n content: [\n 'Check out this image and audio:',\n imageContent,\n audioContent,\n 'What do you think?',\n ],\n createdAt: 2000000000,\n });\n\n expect(context.toJSON()).toMatchSnapshot('multimodal-default-exclusions');\n\n expect(\n context.toJSON({\n excludeImage: false,\n excludeAudio: true,\n }),\n ).toMatchSnapshot('multimodal-with-images-only');\n\n expect(\n context.toJSON({\n excludeImage: true,\n excludeAudio: false,\n }),\n ).toMatchSnapshot('multimodal-with-audio-only');\n\n expect(\n context.toJSON({\n excludeImage: false,\n excludeAudio: false,\n excludeTimestamp: false,\n }),\n ).toMatchSnapshot('multimodal-full-content');\n });\n\n it('should match snapshot for function calls', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'msg_user_3',\n role: 'user',\n content: \"What's the weather in Paris?\",\n createdAt: 3000000000,\n });\n\n const functionCall = new FunctionCall({\n id: 'func_call_1',\n callId: 'call_weather_123',\n name: 'get_weather',\n args: '{\"location\": \"Paris, France\", \"unit\": \"celsius\"}',\n createdAt: 3000000001,\n });\n context.insert(functionCall);\n\n const functionOutput = new FunctionCallOutput({\n id: 'func_output_1',\n callId: 'call_weather_123',\n name: 'get_weather',\n output: '{\"temperature\": 22, \"condition\": \"partly cloudy\", \"humidity\": 65}',\n isError: false,\n createdAt: 3000000002,\n });\n context.insert(functionOutput);\n\n context.addMessage({\n id: 'msg_assistant_2',\n role: 'assistant',\n content: 'The weather in Paris is currently 22°C and partly cloudy with 65% humidity.',\n createdAt: 3000000003,\n });\n\n expect(context.toJSON()).toMatchSnapshot('conversation-with-function-calls');\n\n expect(\n context.toJSON({\n excludeFunctionCall: true,\n }),\n ).toMatchSnapshot('conversation-without-function-calls');\n\n expect(\n context.toJSON({\n excludeTimestamp: false,\n }),\n ).toMatchSnapshot('conversation-with-function-calls-and-timestamps');\n });\n\n it('should match snapshot for edge cases', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'msg_empty_1',\n role: 'user',\n content: [],\n createdAt: 5000000000,\n });\n\n const silentAudio: AudioContent = {\n type: 'audio_content',\n frame: [],\n transcript: undefined,\n };\n\n context.addMessage({\n id: 'msg_silent_audio',\n role: 'user',\n content: [silentAudio],\n createdAt: 5000000001,\n });\n\n context.addMessage({\n id: 'msg_multi_text',\n role: 'assistant',\n content: ['Part 1. ', 'Part 2. ', 'Part 3.'],\n createdAt: 5000000002,\n });\n\n const minimalCall = new FunctionCall({\n id: 'func_minimal',\n callId: 'minimal',\n name: 'test',\n args: '{}',\n createdAt: 5000000003,\n });\n context.insert(minimalCall);\n\n const namelessOutput = new FunctionCallOutput({\n id: 'func_output_nameless',\n callId: 'minimal',\n output: 'OK',\n isError: false,\n createdAt: 5000000004,\n });\n context.insert(namelessOutput);\n\n context.addMessage({\n id: 'msg_special_chars',\n role: 'user',\n content:\n 'Test with special chars: \\n\\t\\r \"quotes\" \\'apostrophes\\' \\\\backslashes\\\\ {braces} [brackets]',\n createdAt: 5000000005,\n });\n\n expect(context.toJSON()).toMatchSnapshot('edge-cases-default');\n expect(\n context.toJSON({\n excludeTimestamp: false,\n excludeAudio: false,\n }),\n ).toMatchSnapshot('edge-cases-with-details');\n });\n\n it('should match snapshot for message property variations', () => {\n const context = new ChatContext();\n\n context.addMessage({\n id: 'custom-message-id-123',\n role: 'user',\n content: 'Message with custom ID',\n createdAt: 6000000000,\n });\n\n context.addMessage({\n id: 'msg_interrupted',\n role: 'assistant',\n content: 'This response was interrupted...',\n interrupted: true,\n createdAt: 6000000001,\n });\n\n context.addMessage({\n id: 'msg_dev_2',\n role: 'developer',\n content: 'Developer message',\n createdAt: 6000000002,\n });\n\n context.addMessage({\n id: 'msg_system_3',\n role: 'system',\n content: 'System message',\n createdAt: 6000000003,\n });\n\n const detailedImage: ImageContent = {\n id: 'img_detailed',\n type: 'image_content',\n image: 'https://example.com/image.jpg',\n inferenceDetail: 'low',\n inferenceWidth: 512,\n inferenceHeight: 512,\n mimeType: 'image/png',\n _cache: { cached: true },\n };\n\n context.addMessage({\n id: 'msg_with_image',\n role: 'user',\n content: ['Image with all properties:', detailedImage],\n createdAt: 6000000004,\n });\n\n expect(context.toJSON()).toMatchSnapshot('message-properties-default');\n expect(\n context.toJSON({\n excludeImage: false,\n excludeTimestamp: false,\n }),\n ).toMatchSnapshot('message-properties-full');\n });\n});\n\ndescribe('ChatContext._summarize', () => {\n it('keeps chronological timestamps with summary + tail', async () => {\n const ctx = new ChatContext();\n ctx.addMessage({ role: 'system', content: 'System prompt', createdAt: 0 });\n ctx.addMessage({ role: 'user', content: 'hello', createdAt: 1000 });\n ctx.addMessage({ role: 'assistant', content: 'hi there', createdAt: 2000 });\n ctx.insert(\n new FunctionCallOutput({\n callId: 'call_1',\n name: 'lookup',\n output: '{\"ok\":true}',\n isError: false,\n createdAt: 3500,\n }),\n );\n ctx.addMessage({ role: 'user', content: 'my color is blue', createdAt: 3000 });\n ctx.addMessage({ role: 'assistant', content: 'noted', createdAt: 4000 });\n\n const fake = new FakeLLM([\n {\n input: 'Conversation to summarize:\\n\\nuser: hello\\nassistant: hi there',\n content: 'condensed head',\n },\n ]);\n\n await ctx._summarize(fake, { keepLastTurns: 1 });\n\n const summary = ctx.items.find(\n (item) =>\n item.type === 'message' && item.role === 'assistant' && item.extra?.is_summary === true,\n );\n expect(summary).toBeDefined();\n if (!summary || summary.type !== 'message') {\n throw new Error('summary message is missing');\n }\n\n expect(summary.createdAt).toBeCloseTo(2999.999, 6);\n\n const createdAts = ctx.items.map((item) => item.createdAt);\n const sorted = [...createdAts].sort((a, b) => a - b);\n expect(createdAts).toEqual(sorted);\n });\n});\n\ndescribe('ReadonlyChatContext with immutable array', () => {\n it('should have readonly property set to true', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n\n expect(readonlyContext.readonly).toBe(true);\n });\n\n it('should prevent setting items property', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n expect(() => {\n readonlyContext.items = [];\n }).toThrow(\n `Cannot set items on a read-only chat context. Please use .copy() and agent.update_chat_ctx() to modify the chat context.`,\n );\n });\n\n it('should prevent modifications through array methods', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n const newItem = new ChatMessage({\n id: 'msg_2',\n role: 'assistant',\n content: ['Response'],\n interrupted: false,\n createdAt: Date.now(),\n });\n\n const mutableItems = readonlyContext.items;\n expect(() => mutableItems.push(newItem)).toThrow(\n 'Cannot call push() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.pop()).toThrow(\n 'Cannot call pop() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.shift()).toThrow(\n 'Cannot call shift() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.unshift(newItem)).toThrow(\n 'Cannot call unshift() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.splice(0, 1)).toThrow(\n 'Cannot call splice() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.sort()).toThrow(\n 'Cannot call sort() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.reverse()).toThrow(\n 'Cannot call reverse() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.fill(newItem)).toThrow(\n 'Cannot call fill() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => mutableItems.copyWithin(0, 1)).toThrow(\n 'Cannot call copyWithin() on a read-only array. Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n });\n\n it('should prevent bracket notation assignment and deletion', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test'],\n interrupted: false,\n createdAt: Date.now(),\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n const newItem = new ChatMessage({\n id: 'msg_2',\n role: 'assistant',\n content: ['Response'],\n interrupted: false,\n createdAt: Date.now(),\n });\n\n expect(() => {\n readonlyContext.items[0] = newItem;\n }).toThrow(\n 'Cannot assign to read-only array index \"0\". Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => {\n delete readonlyContext.items[0];\n }).toThrow(\n 'Cannot delete read-only array index \"0\". Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n\n expect(() => {\n readonlyContext.items[99] = newItem;\n }).toThrow(\n 'Cannot assign to read-only array index \"99\". Please use .copy() and agent.update_chat_ctx() to modify the chat context.',\n );\n });\n\n it('should allow read operations on the immutable array', () => {\n const items: ChatItem[] = [\n new ChatMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Test 1'],\n interrupted: false,\n createdAt: 1000,\n }),\n new ChatMessage({\n id: 'msg_2',\n role: 'assistant',\n content: ['Test 2'],\n interrupted: false,\n createdAt: 2000,\n }),\n ];\n const readonlyContext = new ReadonlyChatContext(items);\n\n expect(readonlyContext.items.length).toBe(2);\n expect(readonlyContext.items[0]).toEqual(items[0]);\n expect(readonlyContext.items[1]).toEqual(items[1]);\n expect(readonlyContext.items.find((item: ChatItem) => item.id === 'msg_2')).toEqual(items[1]);\n expect(readonlyContext.items.map((item: ChatItem) => item.id)).toEqual(['msg_1', 'msg_2']);\n expect(\n readonlyContext.items.filter(\n (item: ChatItem) => item.type === 'message' && item.role === 'user',\n ),\n ).toHaveLength(1);\n\n // forEach should work for reading\n const ids: string[] = [];\n readonlyContext.items.forEach((item) => ids.push(item.id));\n expect(ids).toEqual(['msg_1', 'msg_2']);\n });\n});\n\ndescribe('ChatContext.isEquivalent', () => {\n it('should return true for same reference', () => {\n const ctx = new ChatContext();\n ctx.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n expect(ctx.isEquivalent(ctx)).toBe(true);\n });\n\n it('should return true for identical empty contexts', () => {\n const ctx1 = new ChatContext();\n const ctx2 = new ChatContext();\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for contexts with different lengths', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n ctx2.addMessage({\n id: 'msg_2',\n role: 'assistant',\n content: 'Hi',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for contexts with different item IDs', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_2',\n role: 'user',\n content: 'Hello',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for contexts with different item types', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'msg_1',\n callId: 'call_1',\n name: 'test',\n args: '{}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n describe('message comparison', () => {\n it('should return true for identical messages', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: false,\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: false,\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for messages with different roles', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'assistant',\n content: 'Hello',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for messages with different interrupted flags', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: false,\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n interrupted: true,\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for messages with different content', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'Hello',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'World',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return true for messages with identical array content', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello', 'World'],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello', 'World'],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for messages with different array content', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello', 'World'],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Hello'],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return true for messages with identical image content', () => {\n const imageContent: ImageContent = {\n id: 'img_1',\n type: 'image_content',\n image: 'https://example.com/image.jpg',\n inferenceDetail: 'high',\n inferenceWidth: 1024,\n inferenceHeight: 768,\n mimeType: 'image/jpeg',\n _cache: {},\n };\n\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', imageContent],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', { ...imageContent }],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for messages with different image content', () => {\n const imageContent1: ImageContent = {\n id: 'img_1',\n type: 'image_content',\n image: 'https://example.com/image1.jpg',\n inferenceDetail: 'high',\n _cache: {},\n };\n\n const imageContent2: ImageContent = {\n id: 'img_2',\n type: 'image_content',\n image: 'https://example.com/image2.jpg',\n inferenceDetail: 'high',\n _cache: {},\n };\n\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', imageContent1],\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: ['Check this:', imageContent2],\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n });\n\n describe('function call comparison', () => {\n it('should return true for identical function calls', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for function calls with different names', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_time',\n args: '{}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function calls with different call IDs', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_2',\n name: 'get_weather',\n args: '{}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function calls with different arguments', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"London\"}',\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should ignore timestamps', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n createdAt: 1000,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{}',\n createdAt: 2000,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n });\n\n describe('function call output comparison', () => {\n it('should return true for identical function call outputs', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n\n it('should return false for function call outputs with different names', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_time',\n output: '{}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function call outputs with different call IDs', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_2',\n name: 'get_weather',\n output: '{}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function call outputs with different output values', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 25}',\n isError: false,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should return false for function call outputs with different error flags', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: 'Error occurred',\n isError: false,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: 'Error occurred',\n isError: true,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(false);\n });\n\n it('should ignore timestamps', () => {\n const ctx1 = new ChatContext();\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n createdAt: 1000,\n }),\n );\n\n const ctx2 = new ChatContext();\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{}',\n isError: false,\n createdAt: 2000,\n }),\n );\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n });\n\n describe('complex context comparison', () => {\n it('should return true for identical complex contexts', () => {\n const ctx1 = new ChatContext();\n ctx1.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'What is the weather?',\n });\n ctx1.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n ctx1.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n ctx1.addMessage({\n id: 'msg_2',\n role: 'assistant',\n content: 'The weather is 22°C',\n });\n\n const ctx2 = new ChatContext();\n ctx2.addMessage({\n id: 'msg_1',\n role: 'user',\n content: 'What is the weather?',\n });\n ctx2.insert(\n new FunctionCall({\n id: 'func_1',\n callId: 'call_1',\n name: 'get_weather',\n args: '{\"location\": \"Paris\"}',\n }),\n );\n ctx2.insert(\n new FunctionCallOutput({\n id: 'output_1',\n callId: 'call_1',\n name: 'get_weather',\n output: '{\"temperature\": 22}',\n isError: false,\n }),\n );\n ctx2.addMessage({\n id: 'msg_2',\n role: 'assistant',\n content: 'The weather is 22°C',\n });\n\n expect(ctx1.isEquivalent(ctx2)).toBe(true);\n });\n });\n});\n"],"mappings":";AAGA,oBAAqC;AACrC,iBAAiC;AACjC,sBAAwB;AACxB,0BASO;AAAA,IAEP,6BAAiB,EAA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