@livekit/agents 1.0.34 → 1.0.36

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.
Files changed (117) hide show
  1. package/dist/cli.cjs.map +1 -1
  2. package/dist/inference/api_protos.d.cts +4 -4
  3. package/dist/inference/api_protos.d.ts +4 -4
  4. package/dist/inference/llm.cjs +30 -3
  5. package/dist/inference/llm.cjs.map +1 -1
  6. package/dist/inference/llm.d.cts +3 -1
  7. package/dist/inference/llm.d.ts +3 -1
  8. package/dist/inference/llm.d.ts.map +1 -1
  9. package/dist/inference/llm.js +30 -3
  10. package/dist/inference/llm.js.map +1 -1
  11. package/dist/ipc/inference_proc_executor.cjs.map +1 -1
  12. package/dist/ipc/job_proc_executor.cjs.map +1 -1
  13. package/dist/ipc/job_proc_lazy_main.cjs +1 -1
  14. package/dist/ipc/job_proc_lazy_main.cjs.map +1 -1
  15. package/dist/ipc/job_proc_lazy_main.js +1 -1
  16. package/dist/ipc/job_proc_lazy_main.js.map +1 -1
  17. package/dist/llm/chat_context.cjs +20 -2
  18. package/dist/llm/chat_context.cjs.map +1 -1
  19. package/dist/llm/chat_context.d.cts +9 -0
  20. package/dist/llm/chat_context.d.ts +9 -0
  21. package/dist/llm/chat_context.d.ts.map +1 -1
  22. package/dist/llm/chat_context.js +20 -2
  23. package/dist/llm/chat_context.js.map +1 -1
  24. package/dist/llm/llm.cjs.map +1 -1
  25. package/dist/llm/llm.d.cts +1 -0
  26. package/dist/llm/llm.d.ts +1 -0
  27. package/dist/llm/llm.d.ts.map +1 -1
  28. package/dist/llm/llm.js.map +1 -1
  29. package/dist/llm/provider_format/openai.cjs +43 -20
  30. package/dist/llm/provider_format/openai.cjs.map +1 -1
  31. package/dist/llm/provider_format/openai.d.ts.map +1 -1
  32. package/dist/llm/provider_format/openai.js +43 -20
  33. package/dist/llm/provider_format/openai.js.map +1 -1
  34. package/dist/llm/provider_format/openai.test.cjs +35 -0
  35. package/dist/llm/provider_format/openai.test.cjs.map +1 -1
  36. package/dist/llm/provider_format/openai.test.js +35 -0
  37. package/dist/llm/provider_format/openai.test.js.map +1 -1
  38. package/dist/llm/provider_format/utils.cjs +1 -1
  39. package/dist/llm/provider_format/utils.cjs.map +1 -1
  40. package/dist/llm/provider_format/utils.d.ts.map +1 -1
  41. package/dist/llm/provider_format/utils.js +1 -1
  42. package/dist/llm/provider_format/utils.js.map +1 -1
  43. package/dist/voice/agent_activity.cjs +19 -19
  44. package/dist/voice/agent_activity.cjs.map +1 -1
  45. package/dist/voice/agent_activity.d.ts.map +1 -1
  46. package/dist/voice/agent_activity.js +19 -19
  47. package/dist/voice/agent_activity.js.map +1 -1
  48. package/dist/voice/agent_session.cjs +64 -25
  49. package/dist/voice/agent_session.cjs.map +1 -1
  50. package/dist/voice/agent_session.d.cts +25 -1
  51. package/dist/voice/agent_session.d.ts +25 -1
  52. package/dist/voice/agent_session.d.ts.map +1 -1
  53. package/dist/voice/agent_session.js +64 -25
  54. package/dist/voice/agent_session.js.map +1 -1
  55. package/dist/voice/background_audio.cjs.map +1 -1
  56. package/dist/voice/generation.cjs +2 -1
  57. package/dist/voice/generation.cjs.map +1 -1
  58. package/dist/voice/generation.d.ts.map +1 -1
  59. package/dist/voice/generation.js +2 -1
  60. package/dist/voice/generation.js.map +1 -1
  61. package/dist/voice/index.cjs +14 -1
  62. package/dist/voice/index.cjs.map +1 -1
  63. package/dist/voice/index.d.cts +1 -0
  64. package/dist/voice/index.d.ts +1 -0
  65. package/dist/voice/index.d.ts.map +1 -1
  66. package/dist/voice/index.js +3 -1
  67. package/dist/voice/index.js.map +1 -1
  68. package/dist/voice/room_io/room_io.cjs +1 -0
  69. package/dist/voice/room_io/room_io.cjs.map +1 -1
  70. package/dist/voice/room_io/room_io.d.ts.map +1 -1
  71. package/dist/voice/room_io/room_io.js +1 -0
  72. package/dist/voice/room_io/room_io.js.map +1 -1
  73. package/dist/voice/speech_handle.cjs +12 -3
  74. package/dist/voice/speech_handle.cjs.map +1 -1
  75. package/dist/voice/speech_handle.d.cts +12 -2
  76. package/dist/voice/speech_handle.d.ts +12 -2
  77. package/dist/voice/speech_handle.d.ts.map +1 -1
  78. package/dist/voice/speech_handle.js +10 -2
  79. package/dist/voice/speech_handle.js.map +1 -1
  80. package/dist/voice/testing/index.cjs +52 -0
  81. package/dist/voice/testing/index.cjs.map +1 -0
  82. package/dist/voice/testing/index.d.cts +20 -0
  83. package/dist/voice/testing/index.d.ts +20 -0
  84. package/dist/voice/testing/index.d.ts.map +1 -0
  85. package/dist/voice/testing/index.js +31 -0
  86. package/dist/voice/testing/index.js.map +1 -0
  87. package/dist/voice/testing/run_result.cjs +477 -0
  88. package/dist/voice/testing/run_result.cjs.map +1 -0
  89. package/dist/voice/testing/run_result.d.cts +226 -0
  90. package/dist/voice/testing/run_result.d.ts +226 -0
  91. package/dist/voice/testing/run_result.d.ts.map +1 -0
  92. package/dist/voice/testing/run_result.js +451 -0
  93. package/dist/voice/testing/run_result.js.map +1 -0
  94. package/dist/voice/testing/types.cjs +46 -0
  95. package/dist/voice/testing/types.cjs.map +1 -0
  96. package/dist/voice/testing/types.d.cts +83 -0
  97. package/dist/voice/testing/types.d.ts +83 -0
  98. package/dist/voice/testing/types.d.ts.map +1 -0
  99. package/dist/voice/testing/types.js +19 -0
  100. package/dist/voice/testing/types.js.map +1 -0
  101. package/package.json +3 -3
  102. package/src/inference/llm.ts +42 -3
  103. package/src/ipc/job_proc_lazy_main.ts +1 -1
  104. package/src/llm/chat_context.ts +32 -2
  105. package/src/llm/llm.ts +1 -0
  106. package/src/llm/provider_format/openai.test.ts +40 -0
  107. package/src/llm/provider_format/openai.ts +46 -19
  108. package/src/llm/provider_format/utils.ts +5 -1
  109. package/src/voice/agent_activity.ts +24 -22
  110. package/src/voice/agent_session.ts +73 -28
  111. package/src/voice/generation.ts +1 -0
  112. package/src/voice/index.ts +1 -0
  113. package/src/voice/room_io/room_io.ts +1 -0
  114. package/src/voice/speech_handle.ts +24 -4
  115. package/src/voice/testing/index.ts +49 -0
  116. package/src/voice/testing/run_result.ts +576 -0
  117. package/src/voice/testing/types.ts +118 -0
@@ -0,0 +1,451 @@
1
+ import { Future } from "../../utils.js";
2
+ import { isSpeechHandle } from "../speech_handle.js";
3
+ import {
4
+ isAgentHandoffEvent,
5
+ isChatMessageEvent,
6
+ isFunctionCallEvent,
7
+ isFunctionCallOutputEvent
8
+ } from "./types.js";
9
+ const evalsVerbose = parseInt(process.env.LIVEKIT_EVALS_VERBOSE || "0", 10);
10
+ class RunResult {
11
+ _events = [];
12
+ doneFut = new Future();
13
+ userInput;
14
+ handles = /* @__PURE__ */ new Set();
15
+ lastSpeechHandle;
16
+ runAssert;
17
+ // TODO(brian): Add typed output support for parity with Python
18
+ // - Add outputType?: new (...args: unknown[]) => T
19
+ // - Add finalOutput?: T
20
+ // - Implement markDone() to extract final_output from SpeechHandle.maybeRunFinalOutput
21
+ // - See Python: run_result.py lines 182-201
22
+ constructor(options) {
23
+ this.userInput = options == null ? void 0 : options.userInput;
24
+ }
25
+ /**
26
+ * List of all recorded events generated during the run.
27
+ */
28
+ get events() {
29
+ return this._events;
30
+ }
31
+ /**
32
+ * Provides an assertion helper for verifying the run events.
33
+ */
34
+ get expect() {
35
+ if (evalsVerbose) {
36
+ const eventsStr = formatEvents(this._events).map((line) => ` ${line}`).join("\n");
37
+ console.log(
38
+ `
39
+ + RunResult {
40
+ userInput: "${this.userInput}"
41
+ events: [
42
+ ${eventsStr}
43
+ ]
44
+ }`
45
+ );
46
+ }
47
+ if (!this.runAssert) {
48
+ this.runAssert = new RunAssert(this);
49
+ }
50
+ return this.runAssert;
51
+ }
52
+ /**
53
+ * Returns the final output of the run after completion.
54
+ *
55
+ * @throws Error - Not implemented yet.
56
+ */
57
+ get finalOutput() {
58
+ throw new Error("finalOutput is not yet implemented in JS.");
59
+ }
60
+ /**
61
+ * Indicates whether the run has finished processing all events.
62
+ */
63
+ done() {
64
+ return this.doneFut.done;
65
+ }
66
+ /**
67
+ * Wait for the RunResult to complete. Returns `this` for method chaining.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const result = session.run({ userInput: 'Hi!' });
72
+ * await result.wait(); // waits for completion
73
+ * result.expect.nextEvent().isMessage({ role: 'assistant' });
74
+ * ```
75
+ */
76
+ async wait() {
77
+ await this.doneFut.await;
78
+ return this;
79
+ }
80
+ /**
81
+ * @internal
82
+ * Records an agent handoff event.
83
+ */
84
+ _agentHandoff(params) {
85
+ const event = {
86
+ type: "agent_handoff",
87
+ item: params.item,
88
+ oldAgent: params.oldAgent,
89
+ newAgent: params.newAgent
90
+ };
91
+ const index = this._findInsertionIndex(event.item.createdAt);
92
+ this._events.splice(index, 0, event);
93
+ }
94
+ /**
95
+ * @internal
96
+ * Called when a chat item is added during the run.
97
+ */
98
+ _itemAdded(item) {
99
+ if (this.doneFut.done) {
100
+ return;
101
+ }
102
+ let event;
103
+ if (item.type === "message") {
104
+ event = { type: "message", item };
105
+ } else if (item.type === "function_call") {
106
+ event = { type: "function_call", item };
107
+ } else if (item.type === "function_call_output") {
108
+ event = { type: "function_call_output", item };
109
+ }
110
+ if (event) {
111
+ const index = this._findInsertionIndex(item.createdAt);
112
+ this._events.splice(index, 0, event);
113
+ }
114
+ }
115
+ /**
116
+ * @internal
117
+ * Watch a speech handle or task for completion.
118
+ */
119
+ _watchHandle(handle) {
120
+ this.handles.add(handle);
121
+ if (isSpeechHandle(handle)) {
122
+ handle._addItemAddedCallback(this._itemAdded.bind(this));
123
+ }
124
+ handle.addDoneCallback(() => {
125
+ this._markDoneIfNeeded(handle);
126
+ });
127
+ }
128
+ /**
129
+ * @internal
130
+ * Unwatch a handle.
131
+ */
132
+ _unwatchHandle(handle) {
133
+ this.handles.delete(handle);
134
+ if (isSpeechHandle(handle)) {
135
+ handle._removeItemAddedCallback(this._itemAdded.bind(this));
136
+ }
137
+ }
138
+ _markDoneIfNeeded(handle) {
139
+ if (isSpeechHandle(handle)) {
140
+ this.lastSpeechHandle = handle;
141
+ }
142
+ if ([...this.handles].every((h) => isSpeechHandle(h) ? h.done() : h.done)) {
143
+ this._markDone();
144
+ }
145
+ }
146
+ _markDone() {
147
+ if (!this.doneFut.done) {
148
+ this.doneFut.resolve();
149
+ }
150
+ }
151
+ /**
152
+ * Find the correct insertion index to maintain chronological order.
153
+ */
154
+ _findInsertionIndex(createdAt) {
155
+ for (let i = this._events.length - 1; i >= 0; i--) {
156
+ if (this._events[i].item.createdAt <= createdAt) {
157
+ return i + 1;
158
+ }
159
+ }
160
+ return 0;
161
+ }
162
+ }
163
+ class RunAssert {
164
+ _events;
165
+ _currentIndex = 0;
166
+ // TODO(brian): Add range access for parity with Python __getitem__ slice support.
167
+ // - Add range(start?, end?) method returning EventRangeAssert
168
+ // - EventRangeAssert should have containsFunctionCall(), containsMessage() methods
169
+ // See Python run_result.py lines 247-251 for reference.
170
+ constructor(runResult) {
171
+ this._events = runResult.events;
172
+ }
173
+ /**
174
+ * Access a specific event by index for assertions.
175
+ * Supports negative indices (e.g., -1 for last event).
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * result.expect.at(0).isMessage({ role: 'user' });
180
+ * result.expect.at(-1).isMessage({ role: 'assistant' });
181
+ * ```
182
+ */
183
+ at(index) {
184
+ let normalizedIndex = index;
185
+ if (index < 0) {
186
+ normalizedIndex = this._events.length + index;
187
+ }
188
+ if (normalizedIndex < 0 || normalizedIndex >= this._events.length) {
189
+ this._raiseWithDebugInfo(
190
+ `at(${index}) out of range (total events: ${this._events.length})`,
191
+ normalizedIndex
192
+ );
193
+ }
194
+ return new EventAssert(this._events[normalizedIndex], this, normalizedIndex);
195
+ }
196
+ /**
197
+ * Advance to the next event, optionally filtering by type.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * result.expect.nextEvent().isMessage({ role: 'assistant' });
202
+ * result.expect.nextEvent({ type: 'function_call' }).isFunctionCall({ name: 'foo' });
203
+ * ```
204
+ */
205
+ nextEvent(options) {
206
+ while (true) {
207
+ const evAssert = this._currentEvent();
208
+ this._currentIndex++;
209
+ if (!(options == null ? void 0 : options.type) || evAssert.event().type === options.type) {
210
+ return evAssert;
211
+ }
212
+ }
213
+ }
214
+ /**
215
+ * Skip a specified number of upcoming events without assertions.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * result.expect.skipNext(2);
220
+ * ```
221
+ */
222
+ skipNext(count = 1) {
223
+ for (let i = 0; i < count; i++) {
224
+ if (this._currentIndex >= this._events.length) {
225
+ this._raiseWithDebugInfo(`Tried to skip ${count} event(s), but only ${i} were available.`);
226
+ }
227
+ this._currentIndex++;
228
+ }
229
+ return this;
230
+ }
231
+ /**
232
+ * Assert that there are no further events.
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * result.expect.noMoreEvents();
237
+ * ```
238
+ */
239
+ noMoreEvents() {
240
+ if (this._currentIndex < this._events.length) {
241
+ const event = this._events[this._currentIndex];
242
+ this._raiseWithDebugInfo(`Expected no more events, but found: ${event.type}`);
243
+ }
244
+ }
245
+ _currentEvent() {
246
+ if (this._currentIndex >= this._events.length) {
247
+ this._raiseWithDebugInfo("Expected another event, but none left.");
248
+ }
249
+ return this.at(this._currentIndex);
250
+ }
251
+ /** @internal */
252
+ _raiseWithDebugInfo(message, index) {
253
+ const markerIndex = index ?? this._currentIndex;
254
+ const eventsStr = formatEvents(this._events, markerIndex).join("\n");
255
+ throw new AssertionError(`${message}
256
+ Context around failure:
257
+ ${eventsStr}`);
258
+ }
259
+ }
260
+ class EventAssert {
261
+ _event;
262
+ _parent;
263
+ _index;
264
+ constructor(event, parent, index) {
265
+ this._event = event;
266
+ this._parent = parent;
267
+ this._index = index;
268
+ }
269
+ /**
270
+ * Get the underlying event.
271
+ */
272
+ event() {
273
+ return this._event;
274
+ }
275
+ _raise(message) {
276
+ this._parent._raiseWithDebugInfo(message, this._index);
277
+ }
278
+ /**
279
+ * Verify this event is a message with optional role matching.
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * result.expect.nextEvent().isMessage({ role: 'assistant' });
284
+ * ```
285
+ */
286
+ isMessage(options) {
287
+ if (!isChatMessageEvent(this._event)) {
288
+ this._raise(`Expected ChatMessageEvent, got ${this._event.type}`);
289
+ }
290
+ if ((options == null ? void 0 : options.role) && this._event.item.role !== options.role) {
291
+ this._raise(`Expected role '${options.role}', got '${this._event.item.role}'`);
292
+ }
293
+ return new MessageAssert(this._event, this._parent, this._index);
294
+ }
295
+ /**
296
+ * Verify this event is a function call with optional name/args matching.
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * result.expect.nextEvent().isFunctionCall({ name: 'order_item', args: { id: 'big_mac' } });
301
+ * ```
302
+ */
303
+ isFunctionCall(options) {
304
+ if (!isFunctionCallEvent(this._event)) {
305
+ this._raise(`Expected FunctionCallEvent, got ${this._event.type}`);
306
+ }
307
+ if ((options == null ? void 0 : options.name) && this._event.item.name !== options.name) {
308
+ this._raise(`Expected call name '${options.name}', got '${this._event.item.name}'`);
309
+ }
310
+ if (options == null ? void 0 : options.args) {
311
+ let actual;
312
+ try {
313
+ actual = JSON.parse(this._event.item.args);
314
+ } catch {
315
+ this._raise(`Failed to parse function call arguments: ${this._event.item.args}`);
316
+ }
317
+ for (const [key, value] of Object.entries(options.args)) {
318
+ if (!(key in actual) || actual[key] !== value) {
319
+ this._raise(
320
+ `For key '${key}', expected ${JSON.stringify(value)}, got ${JSON.stringify(actual[key])}`
321
+ );
322
+ }
323
+ }
324
+ }
325
+ return new FunctionCallAssert(this._event, this._parent, this._index);
326
+ }
327
+ /**
328
+ * Verify this event is a function call output with optional matching.
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * result.expect.nextEvent().isFunctionCallOutput({ isError: false });
333
+ * ```
334
+ */
335
+ isFunctionCallOutput(options) {
336
+ if (!isFunctionCallOutputEvent(this._event)) {
337
+ this._raise(`Expected FunctionCallOutputEvent, got ${this._event.type}`);
338
+ }
339
+ if ((options == null ? void 0 : options.output) !== void 0 && this._event.item.output !== options.output) {
340
+ this._raise(`Expected output '${options.output}', got '${this._event.item.output}'`);
341
+ }
342
+ if ((options == null ? void 0 : options.isError) !== void 0 && this._event.item.isError !== options.isError) {
343
+ this._raise(`Expected isError=${options.isError}, got ${this._event.item.isError}`);
344
+ }
345
+ return new FunctionCallOutputAssert(this._event, this._parent, this._index);
346
+ }
347
+ /**
348
+ * Verify this event is an agent handoff with optional type matching.
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * result.expect.nextEvent().isAgentHandoff({ newAgentType: MyAgent });
353
+ * ```
354
+ */
355
+ isAgentHandoff(options) {
356
+ if (!isAgentHandoffEvent(this._event)) {
357
+ this._raise(`Expected AgentHandoffEvent, got ${this._event.type}`);
358
+ }
359
+ const event = this._event;
360
+ if (options == null ? void 0 : options.newAgentType) {
361
+ const actualType = event.newAgent.constructor.name;
362
+ if (!(event.newAgent instanceof options.newAgentType)) {
363
+ this._raise(`Expected new_agent '${options.newAgentType.name}', got '${actualType}'`);
364
+ }
365
+ }
366
+ return new AgentHandoffAssert(event, this._parent, this._index);
367
+ }
368
+ }
369
+ class MessageAssert extends EventAssert {
370
+ constructor(event, parent, index) {
371
+ super(event, parent, index);
372
+ }
373
+ event() {
374
+ return this._event;
375
+ }
376
+ // Phase 3: judge() method will be added here
377
+ }
378
+ class FunctionCallAssert extends EventAssert {
379
+ constructor(event, parent, index) {
380
+ super(event, parent, index);
381
+ }
382
+ event() {
383
+ return this._event;
384
+ }
385
+ }
386
+ class FunctionCallOutputAssert extends EventAssert {
387
+ constructor(event, parent, index) {
388
+ super(event, parent, index);
389
+ }
390
+ event() {
391
+ return this._event;
392
+ }
393
+ }
394
+ class AgentHandoffAssert extends EventAssert {
395
+ constructor(event, parent, index) {
396
+ super(event, parent, index);
397
+ }
398
+ event() {
399
+ return this._event;
400
+ }
401
+ }
402
+ class AssertionError extends Error {
403
+ constructor(message) {
404
+ var _a;
405
+ super(message);
406
+ this.name = "AssertionError";
407
+ (_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, this, AssertionError);
408
+ }
409
+ }
410
+ function formatEvents(events, selectedIndex) {
411
+ var _a;
412
+ const lines = [];
413
+ for (let i = 0; i < events.length; i++) {
414
+ const event = events[i];
415
+ let prefix = "";
416
+ if (selectedIndex !== void 0) {
417
+ prefix = i === selectedIndex ? ">>>" : " ";
418
+ }
419
+ let line;
420
+ if (isChatMessageEvent(event)) {
421
+ const { role, content, interrupted } = event.item;
422
+ const textContent = typeof content === "string" ? content : Array.isArray(content) ? content.filter((c) => typeof c === "string").join(" ") : "";
423
+ const truncated = textContent.length > 50 ? textContent.slice(0, 50) + "..." : textContent;
424
+ line = `${prefix}[${i}] { type: "message", role: "${role}", content: "${truncated}", interrupted: ${interrupted} }`;
425
+ } else if (isFunctionCallEvent(event)) {
426
+ const { name, args } = event.item;
427
+ line = `${prefix}[${i}] { type: "function_call", name: "${name}", args: ${args} }`;
428
+ } else if (isFunctionCallOutputEvent(event)) {
429
+ const { output, isError } = event.item;
430
+ const truncated = output.length > 50 ? output.slice(0, 50) + "..." : output;
431
+ line = `${prefix}[${i}] { type: "function_call_output", output: "${truncated}", isError: ${isError} }`;
432
+ } else if (isAgentHandoffEvent(event)) {
433
+ line = `${prefix}[${i}] { type: "agent_handoff", oldAgent: "${(_a = event.oldAgent) == null ? void 0 : _a.constructor.name}", newAgent: "${event.newAgent.constructor.name}" }`;
434
+ } else {
435
+ line = `${prefix}[${i}] ${event}`;
436
+ }
437
+ lines.push(line);
438
+ }
439
+ return lines;
440
+ }
441
+ export {
442
+ AgentHandoffAssert,
443
+ AssertionError,
444
+ EventAssert,
445
+ FunctionCallAssert,
446
+ FunctionCallOutputAssert,
447
+ MessageAssert,
448
+ RunAssert,
449
+ RunResult
450
+ };
451
+ //# sourceMappingURL=run_result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/voice/testing/run_result.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AgentHandoffItem, ChatItem } from '../../llm/chat_context.js';\nimport type { Task } from '../../utils.js';\nimport { Future } from '../../utils.js';\nimport type { Agent } from '../agent.js';\nimport { type SpeechHandle, isSpeechHandle } from '../speech_handle.js';\nimport {\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n} from './types.js';\n\n// Environment variable for verbose output\nconst evalsVerbose = parseInt(process.env.LIVEKIT_EVALS_VERBOSE || '0', 10);\n\n/**\n * Result of a test run containing recorded events and assertion utilities.\n *\n * @example\n * ```typescript\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n */\nexport class RunResult<T = unknown> {\n private _events: RunEvent[] = [];\n private doneFut = new Future<void>();\n private userInput?: string;\n\n private handles: Set<SpeechHandle | Task<void>> = new Set();\n private lastSpeechHandle?: SpeechHandle;\n private runAssert?: RunAssert;\n\n // TODO(brian): Add typed output support for parity with Python\n // - Add outputType?: new (...args: unknown[]) => T\n // - Add finalOutput?: T\n // - Implement markDone() to extract final_output from SpeechHandle.maybeRunFinalOutput\n // - See Python: run_result.py lines 182-201\n\n constructor(options?: { userInput?: string }) {\n this.userInput = options?.userInput;\n }\n\n /**\n * List of all recorded events generated during the run.\n */\n get events(): RunEvent[] {\n return this._events;\n }\n\n /**\n * Provides an assertion helper for verifying the run events.\n */\n get expect(): RunAssert {\n if (evalsVerbose) {\n const eventsStr = formatEvents(this._events)\n .map((line) => ` ${line}`)\n .join('\\n');\n console.log(\n `\\n+ RunResult {\\n userInput: \"${this.userInput}\"\\n events: [\\n${eventsStr}\\n ]\\n }`,\n );\n }\n\n // Cache the RunAssert so cursor position persists across multiple .expect accesses\n if (!this.runAssert) {\n this.runAssert = new RunAssert(this);\n }\n return this.runAssert;\n }\n\n /**\n * Returns the final output of the run after completion.\n *\n * @throws Error - Not implemented yet.\n */\n get finalOutput(): T {\n // TODO(brian): Implement typed output support after AgentTask is implemented.\n throw new Error('finalOutput is not yet implemented in JS.');\n }\n\n /**\n * Indicates whether the run has finished processing all events.\n */\n done(): boolean {\n return this.doneFut.done;\n }\n\n /**\n * Wait for the RunResult to complete. Returns `this` for method chaining.\n *\n * @example\n * ```ts\n * const result = session.run({ userInput: 'Hi!' });\n * await result.wait(); // waits for completion\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * ```\n */\n async wait(): Promise<this> {\n await this.doneFut.await;\n return this;\n }\n\n /**\n * @internal\n * Records an agent handoff event.\n */\n _agentHandoff(params: { item: AgentHandoffItem; oldAgent?: Agent; newAgent: Agent }): void {\n const event: AgentHandoffEvent = {\n type: 'agent_handoff',\n item: params.item,\n oldAgent: params.oldAgent,\n newAgent: params.newAgent,\n };\n const index = this._findInsertionIndex(event.item.createdAt);\n this._events.splice(index, 0, event);\n }\n\n /**\n * @internal\n * Called when a chat item is added during the run.\n */\n _itemAdded(item: ChatItem): void {\n if (this.doneFut.done) {\n return;\n }\n\n let event: RunEvent | undefined;\n\n if (item.type === 'message') {\n event = { type: 'message', item } as ChatMessageEvent;\n } else if (item.type === 'function_call') {\n event = { type: 'function_call', item } as FunctionCallEvent;\n } else if (item.type === 'function_call_output') {\n event = { type: 'function_call_output', item } as FunctionCallOutputEvent;\n }\n\n if (event) {\n const index = this._findInsertionIndex(item.createdAt);\n this._events.splice(index, 0, event);\n }\n }\n\n /**\n * @internal\n * Watch a speech handle or task for completion.\n */\n _watchHandle(handle: SpeechHandle | Task<void>): void {\n this.handles.add(handle);\n\n if (isSpeechHandle(handle)) {\n handle._addItemAddedCallback(this._itemAdded.bind(this));\n }\n\n handle.addDoneCallback(() => {\n this._markDoneIfNeeded(handle);\n });\n }\n\n /**\n * @internal\n * Unwatch a handle.\n */\n _unwatchHandle(handle: SpeechHandle | Task<void>): void {\n this.handles.delete(handle);\n\n if (isSpeechHandle(handle)) {\n handle._removeItemAddedCallback(this._itemAdded.bind(this));\n }\n }\n\n private _markDoneIfNeeded(handle: SpeechHandle | Task<void>): void {\n if (isSpeechHandle(handle)) {\n this.lastSpeechHandle = handle;\n }\n\n if ([...this.handles].every((h) => (isSpeechHandle(h) ? h.done() : h.done))) {\n this._markDone();\n }\n }\n\n private _markDone(): void {\n // TODO(brian): Implement final output support after AgentTask is implemented.\n // See Python run_result.py _mark_done() for reference:\n // - Check lastSpeechHandle._maybeRunFinalOutput\n // - Validate output type matches expected type\n // - Set exception or resolve based on output\n if (!this.doneFut.done) {\n this.doneFut.resolve();\n }\n }\n\n /**\n * Find the correct insertion index to maintain chronological order.\n */\n private _findInsertionIndex(createdAt: number): number {\n for (let i = this._events.length - 1; i >= 0; i--) {\n if (this._events[i]!.item.createdAt <= createdAt) {\n return i + 1;\n }\n }\n return 0;\n }\n}\n\n/**\n * Assertion helper for verifying run events in sequence.\n */\nexport class RunAssert {\n private _events: RunEvent[];\n private _currentIndex = 0;\n\n // TODO(brian): Add range access for parity with Python __getitem__ slice support.\n // - Add range(start?, end?) method returning EventRangeAssert\n // - EventRangeAssert should have containsFunctionCall(), containsMessage() methods\n // See Python run_result.py lines 247-251 for reference.\n\n constructor(runResult: RunResult) {\n this._events = runResult.events;\n }\n\n /**\n * Access a specific event by index for assertions.\n * Supports negative indices (e.g., -1 for last event).\n *\n * @example\n * ```typescript\n * result.expect.at(0).isMessage({ role: 'user' });\n * result.expect.at(-1).isMessage({ role: 'assistant' });\n * ```\n */\n at(index: number): EventAssert {\n let normalizedIndex = index;\n if (index < 0) {\n normalizedIndex = this._events.length + index;\n }\n\n if (normalizedIndex < 0 || normalizedIndex >= this._events.length) {\n this._raiseWithDebugInfo(\n `at(${index}) out of range (total events: ${this._events.length})`,\n normalizedIndex,\n );\n }\n\n return new EventAssert(this._events[normalizedIndex]!, this, normalizedIndex);\n }\n\n /**\n * Advance to the next event, optionally filtering by type.\n *\n * @example\n * ```typescript\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.nextEvent({ type: 'function_call' }).isFunctionCall({ name: 'foo' });\n * ```\n */\n nextEvent(options?: { type?: EventType }): EventAssert {\n while (true) {\n const evAssert = this._currentEvent();\n this._currentIndex++;\n\n if (!options?.type || evAssert.event().type === options.type) {\n return evAssert;\n }\n }\n }\n\n /**\n * Skip a specified number of upcoming events without assertions.\n *\n * @example\n * ```typescript\n * result.expect.skipNext(2);\n * ```\n */\n skipNext(count: number = 1): this {\n for (let i = 0; i < count; i++) {\n if (this._currentIndex >= this._events.length) {\n this._raiseWithDebugInfo(`Tried to skip ${count} event(s), but only ${i} were available.`);\n }\n this._currentIndex++;\n }\n return this;\n }\n\n /**\n * Assert that there are no further events.\n *\n * @example\n * ```typescript\n * result.expect.noMoreEvents();\n * ```\n */\n noMoreEvents(): void {\n if (this._currentIndex < this._events.length) {\n const event = this._events[this._currentIndex]!;\n this._raiseWithDebugInfo(`Expected no more events, but found: ${event.type}`);\n }\n }\n\n private _currentEvent(): EventAssert {\n if (this._currentIndex >= this._events.length) {\n this._raiseWithDebugInfo('Expected another event, but none left.');\n }\n return this.at(this._currentIndex);\n }\n\n /** @internal */\n _raiseWithDebugInfo(message: string, index?: number): never {\n const markerIndex = index ?? this._currentIndex;\n const eventsStr = formatEvents(this._events, markerIndex).join('\\n');\n throw new AssertionError(`${message}\\nContext around failure:\\n${eventsStr}`);\n }\n}\n\n/**\n * Assertion wrapper for a single event.\n */\nexport class EventAssert {\n protected _event: RunEvent;\n protected _parent: RunAssert;\n protected _index: number;\n\n constructor(event: RunEvent, parent: RunAssert, index: number) {\n this._event = event;\n this._parent = parent;\n this._index = index;\n }\n\n /**\n * Get the underlying event.\n */\n event(): RunEvent {\n return this._event;\n }\n\n protected _raise(message: string): never {\n this._parent._raiseWithDebugInfo(message, this._index);\n }\n\n /**\n * Verify this event is a message with optional role matching.\n *\n * @example\n * ```typescript\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * ```\n */\n isMessage(options?: MessageAssertOptions): MessageAssert {\n if (!isChatMessageEvent(this._event)) {\n this._raise(`Expected ChatMessageEvent, got ${this._event.type}`);\n }\n\n if (options?.role && this._event.item.role !== options.role) {\n this._raise(`Expected role '${options.role}', got '${this._event.item.role}'`);\n }\n\n return new MessageAssert(this._event, this._parent, this._index);\n }\n\n /**\n * Verify this event is a function call with optional name/args matching.\n *\n * @example\n * ```typescript\n * result.expect.nextEvent().isFunctionCall({ name: 'order_item', args: { id: 'big_mac' } });\n * ```\n */\n isFunctionCall(options?: FunctionCallAssertOptions): FunctionCallAssert {\n if (!isFunctionCallEvent(this._event)) {\n this._raise(`Expected FunctionCallEvent, got ${this._event.type}`);\n }\n\n if (options?.name && this._event.item.name !== options.name) {\n this._raise(`Expected call name '${options.name}', got '${this._event.item.name}'`);\n }\n\n if (options?.args) {\n let actual: Record<string, unknown>;\n try {\n actual = JSON.parse(this._event.item.args);\n } catch {\n this._raise(`Failed to parse function call arguments: ${this._event.item.args}`);\n }\n\n for (const [key, value] of Object.entries(options.args)) {\n if (!(key in actual) || actual[key] !== value) {\n this._raise(\n `For key '${key}', expected ${JSON.stringify(value)}, got ${JSON.stringify(actual[key])}`,\n );\n }\n }\n }\n\n return new FunctionCallAssert(this._event, this._parent, this._index);\n }\n\n /**\n * Verify this event is a function call output with optional matching.\n *\n * @example\n * ```typescript\n * result.expect.nextEvent().isFunctionCallOutput({ isError: false });\n * ```\n */\n isFunctionCallOutput(options?: FunctionCallOutputAssertOptions): FunctionCallOutputAssert {\n if (!isFunctionCallOutputEvent(this._event)) {\n this._raise(`Expected FunctionCallOutputEvent, got ${this._event.type}`);\n }\n\n if (options?.output !== undefined && this._event.item.output !== options.output) {\n this._raise(`Expected output '${options.output}', got '${this._event.item.output}'`);\n }\n\n if (options?.isError !== undefined && this._event.item.isError !== options.isError) {\n this._raise(`Expected isError=${options.isError}, got ${this._event.item.isError}`);\n }\n\n return new FunctionCallOutputAssert(this._event, this._parent, this._index);\n }\n\n /**\n * Verify this event is an agent handoff with optional type matching.\n *\n * @example\n * ```typescript\n * result.expect.nextEvent().isAgentHandoff({ newAgentType: MyAgent });\n * ```\n */\n isAgentHandoff(options?: AgentHandoffAssertOptions): AgentHandoffAssert {\n if (!isAgentHandoffEvent(this._event)) {\n this._raise(`Expected AgentHandoffEvent, got ${this._event.type}`);\n }\n\n // Cast to the correct type after validation\n const event = this._event as AgentHandoffEvent;\n\n if (options?.newAgentType) {\n const actualType = event.newAgent.constructor.name;\n if (!(event.newAgent instanceof options.newAgentType)) {\n this._raise(`Expected new_agent '${options.newAgentType.name}', got '${actualType}'`);\n }\n }\n\n return new AgentHandoffAssert(event, this._parent, this._index);\n }\n}\n\n/**\n * Assertion wrapper for message events.\n */\nexport class MessageAssert extends EventAssert {\n protected declare _event: ChatMessageEvent;\n\n constructor(event: ChatMessageEvent, parent: RunAssert, index: number) {\n super(event, parent, index);\n }\n\n override event(): ChatMessageEvent {\n return this._event;\n }\n\n // Phase 3: judge() method will be added here\n}\n\n/**\n * Assertion wrapper for function call events.\n */\nexport class FunctionCallAssert extends EventAssert {\n protected declare _event: FunctionCallEvent;\n\n constructor(event: FunctionCallEvent, parent: RunAssert, index: number) {\n super(event, parent, index);\n }\n\n override event(): FunctionCallEvent {\n return this._event;\n }\n}\n\n/**\n * Assertion wrapper for function call output events.\n */\nexport class FunctionCallOutputAssert extends EventAssert {\n protected declare _event: FunctionCallOutputEvent;\n\n constructor(event: FunctionCallOutputEvent, parent: RunAssert, index: number) {\n super(event, parent, index);\n }\n\n override event(): FunctionCallOutputEvent {\n return this._event;\n }\n}\n\n/**\n * Assertion wrapper for agent handoff events.\n */\nexport class AgentHandoffAssert extends EventAssert {\n protected declare _event: AgentHandoffEvent;\n\n constructor(event: AgentHandoffEvent, parent: RunAssert, index: number) {\n super(event, parent, index);\n }\n\n override event(): AgentHandoffEvent {\n return this._event;\n }\n}\n\n/**\n * Custom assertion error for test failures.\n */\nexport class AssertionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'AssertionError';\n Error.captureStackTrace?.(this, AssertionError);\n }\n}\n\n/**\n * Format events for debug output, optionally marking a selected index.\n */\nfunction formatEvents(events: RunEvent[], selectedIndex?: number): string[] {\n const lines: string[] = [];\n\n for (let i = 0; i < events.length; i++) {\n const event = events[i]!;\n let prefix = '';\n if (selectedIndex !== undefined) {\n prefix = i === selectedIndex ? '>>>' : ' ';\n }\n\n let line: string;\n if (isChatMessageEvent(event)) {\n const { role, content, interrupted } = event.item;\n const textContent =\n typeof content === 'string'\n ? content\n : Array.isArray(content)\n ? content.filter((c): c is string => typeof c === 'string').join(' ')\n : '';\n const truncated = textContent.length > 50 ? textContent.slice(0, 50) + '...' : textContent;\n line = `${prefix}[${i}] { type: \"message\", role: \"${role}\", content: \"${truncated}\", interrupted: ${interrupted} }`;\n } else if (isFunctionCallEvent(event)) {\n const { name, args } = event.item;\n line = `${prefix}[${i}] { type: \"function_call\", name: \"${name}\", args: ${args} }`;\n } else if (isFunctionCallOutputEvent(event)) {\n const { output, isError } = event.item;\n const truncated = output.length > 50 ? output.slice(0, 50) + '...' : output;\n line = `${prefix}[${i}] { type: \"function_call_output\", output: \"${truncated}\", isError: ${isError} }`;\n } else if (isAgentHandoffEvent(event)) {\n line = `${prefix}[${i}] { type: \"agent_handoff\", oldAgent: \"${event.oldAgent?.constructor.name}\", newAgent: \"${event.newAgent.constructor.name}\" }`;\n } else {\n line = `${prefix}[${i}] ${event}`;\n }\n\n lines.push(line);\n }\n\n return lines;\n}\n"],"mappings":"AAKA,SAAS,cAAc;AAEvB,SAA4B,sBAAsB;AAClD;AAAA,EAWE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,MAAM,eAAe,SAAS,QAAQ,IAAI,yBAAyB,KAAK,EAAE;AAYnE,MAAM,UAAuB;AAAA,EAC1B,UAAsB,CAAC;AAAA,EACvB,UAAU,I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AAI;AAAA,IAChF,WAAW,0BAA0B,KAAK,GAAG;AAC3C,YAAM,EAAE,QAAQ,QAAQ,IAAI,MAAM;AAClC,YAAM,YAAY,OAAO,SAAS,KAAK,OAAO,MAAM,GAAG,EAAE,IAAI,QAAQ;AACrE,aAAO,GAAG,MAAM,IAAI,CAAC,8CAA8C,SAAS,eAAe,OAAO;AAAA,IACpG,WAAW,oBAAoB,KAAK,GAAG;AACrC,aAAO,GAAG,MAAM,IAAI,CAAC,0CAAyC,WAAM,aAAN,mBAAgB,YAAY,IAAI,iBAAiB,MAAM,SAAS,YAAY,IAAI;AAAA,IAChJ,OAAO;AACL,aAAO,GAAG,MAAM,IAAI,CAAC,KAAK,KAAK;AAAA,IACjC;AAEA,UAAM,KAAK,IAAI;AAAA,EACjB;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var types_exports = {};
20
+ __export(types_exports, {
21
+ isAgentHandoffEvent: () => isAgentHandoffEvent,
22
+ isChatMessageEvent: () => isChatMessageEvent,
23
+ isFunctionCallEvent: () => isFunctionCallEvent,
24
+ isFunctionCallOutputEvent: () => isFunctionCallOutputEvent
25
+ });
26
+ module.exports = __toCommonJS(types_exports);
27
+ function isChatMessageEvent(event) {
28
+ return event.type === "message";
29
+ }
30
+ function isFunctionCallEvent(event) {
31
+ return event.type === "function_call";
32
+ }
33
+ function isFunctionCallOutputEvent(event) {
34
+ return event.type === "function_call_output";
35
+ }
36
+ function isAgentHandoffEvent(event) {
37
+ return event.type === "agent_handoff";
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ isAgentHandoffEvent,
42
+ isChatMessageEvent,
43
+ isFunctionCallEvent,
44
+ isFunctionCallOutputEvent
45
+ });
46
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/voice/testing/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type {\n AgentHandoffItem,\n ChatMessage,\n ChatRole,\n FunctionCall,\n FunctionCallOutput,\n} from '../../llm/chat_context.js';\nimport type { Agent } from '../agent.js';\n\n/**\n * Event representing an assistant or user message in the conversation.\n */\nexport interface ChatMessageEvent {\n type: 'message';\n item: ChatMessage;\n}\n\n/**\n * Event representing a function/tool call initiated by the LLM.\n */\nexport interface FunctionCallEvent {\n type: 'function_call';\n item: FunctionCall;\n}\n\n/**\n * Event representing the output/result of a function call.\n */\nexport interface FunctionCallOutputEvent {\n type: 'function_call_output';\n item: FunctionCallOutput;\n}\n\n/**\n * Event representing an agent handoff (switching from one agent to another).\n */\nexport interface AgentHandoffEvent {\n type: 'agent_handoff';\n item: AgentHandoffItem;\n oldAgent?: Agent;\n newAgent: Agent;\n}\n\n/**\n * Union type of all possible run events that can occur during a test run.\n */\nexport type RunEvent =\n | ChatMessageEvent\n | FunctionCallEvent\n | FunctionCallOutputEvent\n | AgentHandoffEvent;\n\n/**\n * Type guard to check if an event is a ChatMessageEvent.\n */\nexport function isChatMessageEvent(event: RunEvent): event is ChatMessageEvent {\n return event.type === 'message';\n}\n\n/**\n * Type guard to check if an event is a FunctionCallEvent.\n */\nexport function isFunctionCallEvent(event: RunEvent): event is FunctionCallEvent {\n return event.type === 'function_call';\n}\n\n/**\n * Type guard to check if an event is a FunctionCallOutputEvent.\n */\nexport function isFunctionCallOutputEvent(event: RunEvent): event is FunctionCallOutputEvent {\n return event.type === 'function_call_output';\n}\n\n/**\n * Type guard to check if an event is an AgentHandoffEvent.\n */\nexport function isAgentHandoffEvent(event: RunEvent): event is AgentHandoffEvent {\n return event.type === 'agent_handoff';\n}\n\n/**\n * Options for message assertion.\n */\nexport interface MessageAssertOptions {\n role?: ChatRole;\n}\n\n/**\n * Options for function call assertion.\n */\nexport interface FunctionCallAssertOptions {\n name?: string;\n args?: Record<string, unknown>;\n}\n\n/**\n * Options for function call output assertion.\n */\nexport interface FunctionCallOutputAssertOptions {\n output?: string;\n isError?: boolean;\n}\n\n/**\n * Options for agent handoff assertion.\n */\nexport interface AgentHandoffAssertOptions {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n newAgentType?: new (...args: any[]) => Agent;\n}\n\n/**\n * Event type literals for type-safe event filtering.\n */\nexport type EventType = 'message' | 'function_call' | 'function_call_output' | 'agent_handoff';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0DO,SAAS,mBAAmB,OAA4C;AAC7E,SAAO,MAAM,SAAS;AACxB;AAKO,SAAS,oBAAoB,OAA6C;AAC/E,SAAO,MAAM,SAAS;AACxB;AAKO,SAAS,0BAA0B,OAAmD;AAC3F,SAAO,MAAM,SAAS;AACxB;AAKO,SAAS,oBAAoB,OAA6C;AAC/E,SAAO,MAAM,SAAS;AACxB;","names":[]}
@@ -0,0 +1,83 @@
1
+ import type { AgentHandoffItem, ChatMessage, ChatRole, FunctionCall, FunctionCallOutput } from '../../llm/chat_context.js';
2
+ import type { Agent } from '../agent.js';
3
+ /**
4
+ * Event representing an assistant or user message in the conversation.
5
+ */
6
+ export interface ChatMessageEvent {
7
+ type: 'message';
8
+ item: ChatMessage;
9
+ }
10
+ /**
11
+ * Event representing a function/tool call initiated by the LLM.
12
+ */
13
+ export interface FunctionCallEvent {
14
+ type: 'function_call';
15
+ item: FunctionCall;
16
+ }
17
+ /**
18
+ * Event representing the output/result of a function call.
19
+ */
20
+ export interface FunctionCallOutputEvent {
21
+ type: 'function_call_output';
22
+ item: FunctionCallOutput;
23
+ }
24
+ /**
25
+ * Event representing an agent handoff (switching from one agent to another).
26
+ */
27
+ export interface AgentHandoffEvent {
28
+ type: 'agent_handoff';
29
+ item: AgentHandoffItem;
30
+ oldAgent?: Agent;
31
+ newAgent: Agent;
32
+ }
33
+ /**
34
+ * Union type of all possible run events that can occur during a test run.
35
+ */
36
+ export type RunEvent = ChatMessageEvent | FunctionCallEvent | FunctionCallOutputEvent | AgentHandoffEvent;
37
+ /**
38
+ * Type guard to check if an event is a ChatMessageEvent.
39
+ */
40
+ export declare function isChatMessageEvent(event: RunEvent): event is ChatMessageEvent;
41
+ /**
42
+ * Type guard to check if an event is a FunctionCallEvent.
43
+ */
44
+ export declare function isFunctionCallEvent(event: RunEvent): event is FunctionCallEvent;
45
+ /**
46
+ * Type guard to check if an event is a FunctionCallOutputEvent.
47
+ */
48
+ export declare function isFunctionCallOutputEvent(event: RunEvent): event is FunctionCallOutputEvent;
49
+ /**
50
+ * Type guard to check if an event is an AgentHandoffEvent.
51
+ */
52
+ export declare function isAgentHandoffEvent(event: RunEvent): event is AgentHandoffEvent;
53
+ /**
54
+ * Options for message assertion.
55
+ */
56
+ export interface MessageAssertOptions {
57
+ role?: ChatRole;
58
+ }
59
+ /**
60
+ * Options for function call assertion.
61
+ */
62
+ export interface FunctionCallAssertOptions {
63
+ name?: string;
64
+ args?: Record<string, unknown>;
65
+ }
66
+ /**
67
+ * Options for function call output assertion.
68
+ */
69
+ export interface FunctionCallOutputAssertOptions {
70
+ output?: string;
71
+ isError?: boolean;
72
+ }
73
+ /**
74
+ * Options for agent handoff assertion.
75
+ */
76
+ export interface AgentHandoffAssertOptions {
77
+ newAgentType?: new (...args: any[]) => Agent;
78
+ }
79
+ /**
80
+ * Event type literals for type-safe event filtering.
81
+ */
82
+ export type EventType = 'message' | 'function_call' | 'function_call_output' | 'agent_handoff';
83
+ //# sourceMappingURL=types.d.ts.map