@livekit/agents 1.0.36-dev.0 → 1.0.37
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/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/inference/utils.cjs +2 -15
- package/dist/inference/utils.cjs.map +1 -1
- package/dist/inference/utils.d.cts +0 -1
- package/dist/inference/utils.d.ts +0 -1
- package/dist/inference/utils.d.ts.map +1 -1
- package/dist/inference/utils.js +1 -13
- package/dist/inference/utils.js.map +1 -1
- package/dist/stream/stream_channel.cjs +0 -3
- package/dist/stream/stream_channel.cjs.map +1 -1
- package/dist/stream/stream_channel.d.cts +2 -3
- package/dist/stream/stream_channel.d.ts +2 -3
- package/dist/stream/stream_channel.d.ts.map +1 -1
- package/dist/stream/stream_channel.js +0 -3
- package/dist/stream/stream_channel.js.map +1 -1
- package/dist/telemetry/trace_types.cjs +0 -15
- package/dist/telemetry/trace_types.cjs.map +1 -1
- package/dist/telemetry/trace_types.d.cts +0 -5
- package/dist/telemetry/trace_types.d.ts +0 -5
- package/dist/telemetry/trace_types.d.ts.map +1 -1
- package/dist/telemetry/trace_types.js +0 -10
- package/dist/telemetry/trace_types.js.map +1 -1
- package/dist/voice/agent_activity.cjs +19 -68
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +0 -14
- package/dist/voice/agent_activity.d.ts +0 -14
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +19 -68
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +65 -37
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +25 -4
- package/dist/voice/agent_session.d.ts +25 -4
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +65 -37
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/audio_recognition.cjs +2 -124
- package/dist/voice/audio_recognition.cjs.map +1 -1
- package/dist/voice/audio_recognition.d.cts +1 -32
- package/dist/voice/audio_recognition.d.ts +1 -32
- package/dist/voice/audio_recognition.d.ts.map +1 -1
- package/dist/voice/audio_recognition.js +2 -127
- package/dist/voice/audio_recognition.js.map +1 -1
- package/dist/voice/index.cjs +14 -1
- package/dist/voice/index.cjs.map +1 -1
- package/dist/voice/index.d.cts +1 -0
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +3 -1
- package/dist/voice/index.js.map +1 -1
- package/dist/voice/room_io/room_io.cjs +1 -0
- 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 +1 -0
- package/dist/voice/room_io/room_io.js.map +1 -1
- package/dist/voice/speech_handle.cjs +12 -3
- package/dist/voice/speech_handle.cjs.map +1 -1
- package/dist/voice/speech_handle.d.cts +12 -2
- package/dist/voice/speech_handle.d.ts +12 -2
- package/dist/voice/speech_handle.d.ts.map +1 -1
- package/dist/voice/speech_handle.js +10 -2
- package/dist/voice/speech_handle.js.map +1 -1
- package/dist/voice/testing/index.cjs +54 -0
- package/dist/voice/testing/index.cjs.map +1 -0
- package/dist/voice/testing/index.d.cts +20 -0
- package/dist/voice/testing/index.d.ts +20 -0
- package/dist/voice/testing/index.d.ts.map +1 -0
- package/dist/voice/testing/index.js +33 -0
- package/dist/voice/testing/index.js.map +1 -0
- package/dist/voice/testing/run_result.cjs +766 -0
- package/dist/voice/testing/run_result.cjs.map +1 -0
- package/dist/voice/testing/run_result.d.cts +374 -0
- package/dist/voice/testing/run_result.d.ts +374 -0
- package/dist/voice/testing/run_result.d.ts.map +1 -0
- package/dist/voice/testing/run_result.js +739 -0
- package/dist/voice/testing/run_result.js.map +1 -0
- package/dist/{inference/interruption/index.cjs → voice/testing/types.cjs} +24 -12
- package/dist/voice/testing/types.cjs.map +1 -0
- package/dist/voice/testing/types.d.cts +83 -0
- package/dist/voice/testing/types.d.ts +83 -0
- package/dist/voice/testing/types.d.ts.map +1 -0
- package/dist/voice/testing/types.js +19 -0
- package/dist/voice/testing/types.js.map +1 -0
- package/package.json +3 -4
- package/src/index.ts +0 -2
- package/src/inference/utils.ts +0 -15
- package/src/stream/stream_channel.ts +2 -6
- package/src/telemetry/trace_types.ts +0 -7
- package/src/voice/agent_activity.ts +24 -83
- package/src/voice/agent_session.ts +74 -49
- package/src/voice/audio_recognition.ts +1 -161
- package/src/voice/index.ts +1 -0
- package/src/voice/room_io/room_io.ts +1 -0
- package/src/voice/speech_handle.ts +24 -4
- package/src/voice/testing/index.ts +50 -0
- package/src/voice/testing/run_result.ts +937 -0
- package/src/voice/testing/types.ts +118 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.cjs +0 -152
- package/dist/inference/interruption/AdaptiveInterruptionDetector.cjs.map +0 -1
- package/dist/inference/interruption/AdaptiveInterruptionDetector.d.cts +0 -50
- package/dist/inference/interruption/AdaptiveInterruptionDetector.d.ts +0 -50
- package/dist/inference/interruption/AdaptiveInterruptionDetector.d.ts.map +0 -1
- package/dist/inference/interruption/AdaptiveInterruptionDetector.js +0 -125
- package/dist/inference/interruption/AdaptiveInterruptionDetector.js.map +0 -1
- package/dist/inference/interruption/InterruptionStream.cjs +0 -310
- package/dist/inference/interruption/InterruptionStream.cjs.map +0 -1
- package/dist/inference/interruption/InterruptionStream.d.cts +0 -57
- package/dist/inference/interruption/InterruptionStream.d.ts +0 -57
- package/dist/inference/interruption/InterruptionStream.d.ts.map +0 -1
- package/dist/inference/interruption/InterruptionStream.js +0 -288
- package/dist/inference/interruption/InterruptionStream.js.map +0 -1
- package/dist/inference/interruption/defaults.cjs +0 -76
- package/dist/inference/interruption/defaults.cjs.map +0 -1
- package/dist/inference/interruption/defaults.d.cts +0 -14
- package/dist/inference/interruption/defaults.d.ts +0 -14
- package/dist/inference/interruption/defaults.d.ts.map +0 -1
- package/dist/inference/interruption/defaults.js +0 -42
- package/dist/inference/interruption/defaults.js.map +0 -1
- package/dist/inference/interruption/errors.cjs +0 -2
- package/dist/inference/interruption/errors.cjs.map +0 -1
- package/dist/inference/interruption/errors.d.cts +0 -2
- package/dist/inference/interruption/errors.d.ts +0 -2
- package/dist/inference/interruption/errors.d.ts.map +0 -1
- package/dist/inference/interruption/errors.js +0 -1
- package/dist/inference/interruption/errors.js.map +0 -1
- package/dist/inference/interruption/http_transport.cjs +0 -57
- package/dist/inference/interruption/http_transport.cjs.map +0 -1
- package/dist/inference/interruption/http_transport.d.cts +0 -23
- package/dist/inference/interruption/http_transport.d.ts +0 -23
- package/dist/inference/interruption/http_transport.d.ts.map +0 -1
- package/dist/inference/interruption/http_transport.js +0 -33
- package/dist/inference/interruption/http_transport.js.map +0 -1
- package/dist/inference/interruption/index.cjs.map +0 -1
- package/dist/inference/interruption/index.d.cts +0 -5
- package/dist/inference/interruption/index.d.ts +0 -5
- package/dist/inference/interruption/index.d.ts.map +0 -1
- package/dist/inference/interruption/index.js +0 -7
- package/dist/inference/interruption/index.js.map +0 -1
- package/dist/inference/interruption/interruption.cjs +0 -85
- package/dist/inference/interruption/interruption.cjs.map +0 -1
- package/dist/inference/interruption/interruption.d.cts +0 -48
- package/dist/inference/interruption/interruption.d.ts +0 -48
- package/dist/inference/interruption/interruption.d.ts.map +0 -1
- package/dist/inference/interruption/interruption.js +0 -59
- package/dist/inference/interruption/interruption.js.map +0 -1
- package/dist/inference/utils.test.cjs +0 -20
- package/dist/inference/utils.test.cjs.map +0 -1
- package/dist/inference/utils.test.js +0 -19
- package/dist/inference/utils.test.js.map +0 -1
- package/dist/utils/ws_transport.cjs +0 -51
- package/dist/utils/ws_transport.cjs.map +0 -1
- package/dist/utils/ws_transport.d.cts +0 -9
- package/dist/utils/ws_transport.d.ts +0 -9
- package/dist/utils/ws_transport.d.ts.map +0 -1
- package/dist/utils/ws_transport.js +0 -17
- package/dist/utils/ws_transport.js.map +0 -1
- package/dist/utils/ws_transport.test.cjs +0 -212
- package/dist/utils/ws_transport.test.cjs.map +0 -1
- package/dist/utils/ws_transport.test.js +0 -211
- package/dist/utils/ws_transport.test.js.map +0 -1
- package/src/inference/interruption/AdaptiveInterruptionDetector.ts +0 -166
- package/src/inference/interruption/InterruptionStream.ts +0 -397
- package/src/inference/interruption/defaults.ts +0 -33
- package/src/inference/interruption/errors.ts +0 -0
- package/src/inference/interruption/http_transport.ts +0 -61
- package/src/inference/interruption/index.ts +0 -4
- package/src/inference/interruption/interruption.ts +0 -88
- package/src/inference/utils.test.ts +0 -31
- package/src/utils/ws_transport.test.ts +0 -282
- package/src/utils/ws_transport.ts +0 -22
|
@@ -0,0 +1,766 @@
|
|
|
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 run_result_exports = {};
|
|
20
|
+
__export(run_result_exports, {
|
|
21
|
+
AgentHandoffAssert: () => AgentHandoffAssert,
|
|
22
|
+
AssertionError: () => AssertionError,
|
|
23
|
+
EventAssert: () => EventAssert,
|
|
24
|
+
EventRangeAssert: () => EventRangeAssert,
|
|
25
|
+
FunctionCallAssert: () => FunctionCallAssert,
|
|
26
|
+
FunctionCallOutputAssert: () => FunctionCallOutputAssert,
|
|
27
|
+
MessageAssert: () => MessageAssert,
|
|
28
|
+
RunAssert: () => RunAssert,
|
|
29
|
+
RunResult: () => RunResult
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(run_result_exports);
|
|
32
|
+
var import_zod = require("zod");
|
|
33
|
+
var import_chat_context = require("../../llm/chat_context.cjs");
|
|
34
|
+
var import_tool_context = require("../../llm/tool_context.cjs");
|
|
35
|
+
var import_utils = require("../../utils.cjs");
|
|
36
|
+
var import_speech_handle = require("../speech_handle.cjs");
|
|
37
|
+
var import_types = require("./types.cjs");
|
|
38
|
+
const evalsVerbose = parseInt(process.env.LIVEKIT_EVALS_VERBOSE || "0", 10);
|
|
39
|
+
class RunResult {
|
|
40
|
+
_events = [];
|
|
41
|
+
doneFut = new import_utils.Future();
|
|
42
|
+
userInput;
|
|
43
|
+
handles = /* @__PURE__ */ new Set();
|
|
44
|
+
lastSpeechHandle;
|
|
45
|
+
runAssert;
|
|
46
|
+
// TODO(brian): Add typed output support for parity with Python
|
|
47
|
+
// - Add outputType?: new (...args: unknown[]) => T
|
|
48
|
+
// - Add finalOutput?: T
|
|
49
|
+
// - Implement markDone() to extract final_output from SpeechHandle.maybeRunFinalOutput
|
|
50
|
+
// - See Python: run_result.py lines 182-201
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.userInput = options == null ? void 0 : options.userInput;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* List of all recorded events generated during the run.
|
|
56
|
+
*/
|
|
57
|
+
get events() {
|
|
58
|
+
return this._events;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Provides an assertion helper for verifying the run events.
|
|
62
|
+
*/
|
|
63
|
+
get expect() {
|
|
64
|
+
if (evalsVerbose) {
|
|
65
|
+
const eventsStr = formatEvents(this._events).map((line) => ` ${line}`).join("\n");
|
|
66
|
+
console.log(
|
|
67
|
+
`
|
|
68
|
+
+ RunResult {
|
|
69
|
+
userInput: "${this.userInput}"
|
|
70
|
+
events: [
|
|
71
|
+
${eventsStr}
|
|
72
|
+
]
|
|
73
|
+
}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (!this.runAssert) {
|
|
77
|
+
this.runAssert = new RunAssert(this);
|
|
78
|
+
}
|
|
79
|
+
return this.runAssert;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the final output of the run after completion.
|
|
83
|
+
*
|
|
84
|
+
* @throws Error - Not implemented yet.
|
|
85
|
+
*/
|
|
86
|
+
get finalOutput() {
|
|
87
|
+
throw new Error("finalOutput is not yet implemented in JS.");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Indicates whether the run has finished processing all events.
|
|
91
|
+
*/
|
|
92
|
+
done() {
|
|
93
|
+
return this.doneFut.done;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wait for the RunResult to complete. Returns `this` for method chaining.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const result = session.run({ userInput: 'Hi!' });
|
|
101
|
+
* await result.wait(); // waits for completion
|
|
102
|
+
* result.expect.nextEvent().isMessage({ role: 'assistant' });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
async wait() {
|
|
106
|
+
await this.doneFut.await;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
* Records an agent handoff event.
|
|
112
|
+
*/
|
|
113
|
+
_agentHandoff(params) {
|
|
114
|
+
const event = {
|
|
115
|
+
type: "agent_handoff",
|
|
116
|
+
item: params.item,
|
|
117
|
+
oldAgent: params.oldAgent,
|
|
118
|
+
newAgent: params.newAgent
|
|
119
|
+
};
|
|
120
|
+
const index = this._findInsertionIndex(event.item.createdAt);
|
|
121
|
+
this._events.splice(index, 0, event);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
* Called when a chat item is added during the run.
|
|
126
|
+
*/
|
|
127
|
+
_itemAdded(item) {
|
|
128
|
+
if (this.doneFut.done) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let event;
|
|
132
|
+
if (item.type === "message") {
|
|
133
|
+
event = { type: "message", item };
|
|
134
|
+
} else if (item.type === "function_call") {
|
|
135
|
+
event = { type: "function_call", item };
|
|
136
|
+
} else if (item.type === "function_call_output") {
|
|
137
|
+
event = { type: "function_call_output", item };
|
|
138
|
+
}
|
|
139
|
+
if (event) {
|
|
140
|
+
const index = this._findInsertionIndex(item.createdAt);
|
|
141
|
+
this._events.splice(index, 0, event);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
* Watch a speech handle or task for completion.
|
|
147
|
+
*/
|
|
148
|
+
_watchHandle(handle) {
|
|
149
|
+
this.handles.add(handle);
|
|
150
|
+
if ((0, import_speech_handle.isSpeechHandle)(handle)) {
|
|
151
|
+
handle._addItemAddedCallback(this._itemAdded.bind(this));
|
|
152
|
+
}
|
|
153
|
+
handle.addDoneCallback(() => {
|
|
154
|
+
this._markDoneIfNeeded(handle);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @internal
|
|
159
|
+
* Unwatch a handle.
|
|
160
|
+
*/
|
|
161
|
+
_unwatchHandle(handle) {
|
|
162
|
+
this.handles.delete(handle);
|
|
163
|
+
if ((0, import_speech_handle.isSpeechHandle)(handle)) {
|
|
164
|
+
handle._removeItemAddedCallback(this._itemAdded.bind(this));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
_markDoneIfNeeded(handle) {
|
|
168
|
+
if ((0, import_speech_handle.isSpeechHandle)(handle)) {
|
|
169
|
+
this.lastSpeechHandle = handle;
|
|
170
|
+
}
|
|
171
|
+
if ([...this.handles].every((h) => (0, import_speech_handle.isSpeechHandle)(h) ? h.done() : h.done)) {
|
|
172
|
+
this._markDone();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
_markDone() {
|
|
176
|
+
if (!this.doneFut.done) {
|
|
177
|
+
this.doneFut.resolve();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Find the correct insertion index to maintain chronological order.
|
|
182
|
+
*/
|
|
183
|
+
_findInsertionIndex(createdAt) {
|
|
184
|
+
for (let i = this._events.length - 1; i >= 0; i--) {
|
|
185
|
+
if (this._events[i].item.createdAt <= createdAt) {
|
|
186
|
+
return i + 1;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
class RunAssert {
|
|
193
|
+
_events;
|
|
194
|
+
_currentIndex = 0;
|
|
195
|
+
constructor(runResult) {
|
|
196
|
+
this._events = runResult.events;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Access a specific event by index for assertions.
|
|
200
|
+
* Supports negative indices (e.g., -1 for last event).
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* result.expect.at(0).isMessage({ role: 'user' });
|
|
205
|
+
* result.expect.at(-1).isMessage({ role: 'assistant' });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
at(index) {
|
|
209
|
+
let normalizedIndex = index;
|
|
210
|
+
if (index < 0) {
|
|
211
|
+
normalizedIndex = this._events.length + index;
|
|
212
|
+
}
|
|
213
|
+
if (normalizedIndex < 0 || normalizedIndex >= this._events.length) {
|
|
214
|
+
this._raiseWithDebugInfo(
|
|
215
|
+
`at(${index}) out of range (total events: ${this._events.length})`,
|
|
216
|
+
normalizedIndex
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return new EventAssert(this._events[normalizedIndex], this, normalizedIndex);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Advance to the next event, optionally filtering by type.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* result.expect.nextEvent().isMessage({ role: 'assistant' });
|
|
227
|
+
* result.expect.nextEvent({ type: 'function_call' }).isFunctionCall({ name: 'foo' });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
nextEvent(options) {
|
|
231
|
+
while (true) {
|
|
232
|
+
const evAssert = this._currentEvent();
|
|
233
|
+
this._currentIndex++;
|
|
234
|
+
if (!(options == null ? void 0 : options.type) || evAssert.event().type === options.type) {
|
|
235
|
+
return evAssert;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Skip a specified number of upcoming events without assertions.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* result.expect.skipNext(2);
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
skipNext(count = 1) {
|
|
248
|
+
for (let i = 0; i < count; i++) {
|
|
249
|
+
if (this._currentIndex >= this._events.length) {
|
|
250
|
+
this._raiseWithDebugInfo(`Tried to skip ${count} event(s), but only ${i} were available.`);
|
|
251
|
+
}
|
|
252
|
+
this._currentIndex++;
|
|
253
|
+
}
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Conditionally skip the next event if it matches the specified criteria.
|
|
258
|
+
* Returns the event assertion if matched and skipped, or undefined if not matched.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* // Skip optional assistant message before function call
|
|
263
|
+
* result.expect.skipNextEventIf({ type: 'message', role: 'assistant' });
|
|
264
|
+
* result.expect.nextEvent().isFunctionCall({ name: 'foo' });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
skipNextEventIf(options) {
|
|
268
|
+
if (this._currentIndex >= this._events.length) {
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const evAssert = this._currentEvent();
|
|
273
|
+
if (options.type === "message") {
|
|
274
|
+
const { role } = options;
|
|
275
|
+
const result = evAssert.isMessage({ role });
|
|
276
|
+
this._currentIndex++;
|
|
277
|
+
return result;
|
|
278
|
+
} else if (options.type === "function_call") {
|
|
279
|
+
const { name, args } = options;
|
|
280
|
+
const result = evAssert.isFunctionCall({
|
|
281
|
+
name,
|
|
282
|
+
args
|
|
283
|
+
});
|
|
284
|
+
this._currentIndex++;
|
|
285
|
+
return result;
|
|
286
|
+
} else if (options.type === "function_call_output") {
|
|
287
|
+
const { output, isError } = options;
|
|
288
|
+
const result = evAssert.isFunctionCallOutput({
|
|
289
|
+
output,
|
|
290
|
+
isError
|
|
291
|
+
});
|
|
292
|
+
this._currentIndex++;
|
|
293
|
+
return result;
|
|
294
|
+
} else if (options.type === "agent_handoff") {
|
|
295
|
+
const { newAgentType } = options;
|
|
296
|
+
const result = evAssert.isAgentHandoff({ newAgentType });
|
|
297
|
+
this._currentIndex++;
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
} catch {
|
|
301
|
+
return void 0;
|
|
302
|
+
}
|
|
303
|
+
return void 0;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Get an EventRangeAssert for a range of events.
|
|
307
|
+
* Similar to Python's slice access: expect[0:3] or expect[:]
|
|
308
|
+
*
|
|
309
|
+
* @param start - Start index (inclusive), defaults to 0
|
|
310
|
+
* @param end - End index (exclusive), defaults to events.length
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* // Search all events
|
|
315
|
+
* result.expect.range().containsFunctionCall({ name: 'foo' });
|
|
316
|
+
* // Search first 3 events
|
|
317
|
+
* result.expect.range(0, 3).containsMessage({ role: 'assistant' });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
range(start, end) {
|
|
321
|
+
const startIdx = start ?? 0;
|
|
322
|
+
const endIdx = end ?? this._events.length;
|
|
323
|
+
const events = this._events.slice(startIdx, endIdx);
|
|
324
|
+
return new EventRangeAssert(events, this, { start: startIdx, end: endIdx });
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Assert that a function call matching criteria exists anywhere in the events.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* result.expect.containsFunctionCall({ name: 'order_item' });
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
containsFunctionCall(options) {
|
|
335
|
+
return this.range().containsFunctionCall(options);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Assert that a message matching criteria exists anywhere in the events.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* result.expect.containsMessage({ role: 'assistant' });
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
containsMessage(options) {
|
|
346
|
+
return this.range().containsMessage(options);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Assert that a function call output matching criteria exists anywhere in the events.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* result.expect.containsFunctionCallOutput({ isError: false });
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
containsFunctionCallOutput(options) {
|
|
357
|
+
return this.range().containsFunctionCallOutput(options);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Assert that an agent handoff matching criteria exists anywhere in the events.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* result.expect.containsAgentHandoff({ newAgentType: MyAgent });
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
containsAgentHandoff(options) {
|
|
368
|
+
return this.range().containsAgentHandoff(options);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Assert that there are no further events.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* result.expect.noMoreEvents();
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
noMoreEvents() {
|
|
379
|
+
if (this._currentIndex < this._events.length) {
|
|
380
|
+
const event = this._events[this._currentIndex];
|
|
381
|
+
this._raiseWithDebugInfo(`Expected no more events, but found: ${event.type}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
_currentEvent() {
|
|
385
|
+
if (this._currentIndex >= this._events.length) {
|
|
386
|
+
this._raiseWithDebugInfo("Expected another event, but none left.");
|
|
387
|
+
}
|
|
388
|
+
return this.at(this._currentIndex);
|
|
389
|
+
}
|
|
390
|
+
/** @internal */
|
|
391
|
+
_raiseWithDebugInfo(message, index) {
|
|
392
|
+
const markerIndex = index ?? this._currentIndex;
|
|
393
|
+
const eventsStr = formatEvents(this._events, markerIndex).join("\n");
|
|
394
|
+
throw new AssertionError(`${message}
|
|
395
|
+
Context around failure:
|
|
396
|
+
${eventsStr}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
class EventAssert {
|
|
400
|
+
_event;
|
|
401
|
+
_parent;
|
|
402
|
+
_index;
|
|
403
|
+
constructor(event, parent, index) {
|
|
404
|
+
this._event = event;
|
|
405
|
+
this._parent = parent;
|
|
406
|
+
this._index = index;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Get the underlying event.
|
|
410
|
+
*/
|
|
411
|
+
event() {
|
|
412
|
+
return this._event;
|
|
413
|
+
}
|
|
414
|
+
_raise(message) {
|
|
415
|
+
this._parent._raiseWithDebugInfo(message, this._index);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Verify this event is a message with optional role matching.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* result.expect.nextEvent().isMessage({ role: 'assistant' });
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
isMessage(options) {
|
|
426
|
+
if (!(0, import_types.isChatMessageEvent)(this._event)) {
|
|
427
|
+
this._raise(`Expected ChatMessageEvent, got ${this._event.type}`);
|
|
428
|
+
}
|
|
429
|
+
if ((options == null ? void 0 : options.role) && this._event.item.role !== options.role) {
|
|
430
|
+
this._raise(`Expected role '${options.role}', got '${this._event.item.role}'`);
|
|
431
|
+
}
|
|
432
|
+
return new MessageAssert(this._event, this._parent, this._index);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Verify this event is a function call with optional name/args matching.
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```typescript
|
|
439
|
+
* result.expect.nextEvent().isFunctionCall({ name: 'order_item', args: { id: 'big_mac' } });
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
isFunctionCall(options) {
|
|
443
|
+
if (!(0, import_types.isFunctionCallEvent)(this._event)) {
|
|
444
|
+
this._raise(`Expected FunctionCallEvent, got ${this._event.type}`);
|
|
445
|
+
}
|
|
446
|
+
if ((options == null ? void 0 : options.name) && this._event.item.name !== options.name) {
|
|
447
|
+
this._raise(`Expected call name '${options.name}', got '${this._event.item.name}'`);
|
|
448
|
+
}
|
|
449
|
+
if (options == null ? void 0 : options.args) {
|
|
450
|
+
let actual;
|
|
451
|
+
try {
|
|
452
|
+
actual = JSON.parse(this._event.item.args);
|
|
453
|
+
} catch {
|
|
454
|
+
this._raise(`Failed to parse function call arguments: ${this._event.item.args}`);
|
|
455
|
+
}
|
|
456
|
+
for (const [key, value] of Object.entries(options.args)) {
|
|
457
|
+
if (!(key in actual) || actual[key] !== value) {
|
|
458
|
+
this._raise(
|
|
459
|
+
`For key '${key}', expected ${JSON.stringify(value)}, got ${JSON.stringify(actual[key])}`
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return new FunctionCallAssert(this._event, this._parent, this._index);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Verify this event is a function call output with optional matching.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```typescript
|
|
471
|
+
* result.expect.nextEvent().isFunctionCallOutput({ isError: false });
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
isFunctionCallOutput(options) {
|
|
475
|
+
if (!(0, import_types.isFunctionCallOutputEvent)(this._event)) {
|
|
476
|
+
this._raise(`Expected FunctionCallOutputEvent, got ${this._event.type}`);
|
|
477
|
+
}
|
|
478
|
+
if ((options == null ? void 0 : options.output) !== void 0 && this._event.item.output !== options.output) {
|
|
479
|
+
this._raise(`Expected output '${options.output}', got '${this._event.item.output}'`);
|
|
480
|
+
}
|
|
481
|
+
if ((options == null ? void 0 : options.isError) !== void 0 && this._event.item.isError !== options.isError) {
|
|
482
|
+
this._raise(`Expected isError=${options.isError}, got ${this._event.item.isError}`);
|
|
483
|
+
}
|
|
484
|
+
return new FunctionCallOutputAssert(this._event, this._parent, this._index);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Verify this event is an agent handoff with optional type matching.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* result.expect.nextEvent().isAgentHandoff({ newAgentType: MyAgent });
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
isAgentHandoff(options) {
|
|
495
|
+
if (!(0, import_types.isAgentHandoffEvent)(this._event)) {
|
|
496
|
+
this._raise(`Expected AgentHandoffEvent, got ${this._event.type}`);
|
|
497
|
+
}
|
|
498
|
+
const event = this._event;
|
|
499
|
+
if (options == null ? void 0 : options.newAgentType) {
|
|
500
|
+
const actualType = event.newAgent.constructor.name;
|
|
501
|
+
if (!(event.newAgent instanceof options.newAgentType)) {
|
|
502
|
+
this._raise(`Expected new_agent '${options.newAgentType.name}', got '${actualType}'`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return new AgentHandoffAssert(event, this._parent, this._index);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
class EventRangeAssert {
|
|
509
|
+
_events;
|
|
510
|
+
_parent;
|
|
511
|
+
_range;
|
|
512
|
+
constructor(events, parent, range) {
|
|
513
|
+
this._events = events;
|
|
514
|
+
this._parent = parent;
|
|
515
|
+
this._range = range;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Assert that a function call matching criteria exists in this event range.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```typescript
|
|
522
|
+
* result.expect.range(0, 3).containsFunctionCall({ name: 'foo' });
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
containsFunctionCall(options) {
|
|
526
|
+
for (let idx = 0; idx < this._events.length; idx++) {
|
|
527
|
+
const ev = this._events[idx];
|
|
528
|
+
const candidate = new EventAssert(ev, this._parent, this._range.start + idx);
|
|
529
|
+
try {
|
|
530
|
+
return candidate.isFunctionCall(options);
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
this._parent._raiseWithDebugInfo(
|
|
535
|
+
`No FunctionCallEvent satisfying criteria found in range [${this._range.start}:${this._range.end}]`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Assert that a message matching criteria exists in this event range.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```typescript
|
|
543
|
+
* result.expect.range(0, 2).containsMessage({ role: 'assistant' });
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
containsMessage(options) {
|
|
547
|
+
for (let idx = 0; idx < this._events.length; idx++) {
|
|
548
|
+
const ev = this._events[idx];
|
|
549
|
+
const candidate = new EventAssert(ev, this._parent, this._range.start + idx);
|
|
550
|
+
try {
|
|
551
|
+
return candidate.isMessage(options);
|
|
552
|
+
} catch {
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
this._parent._raiseWithDebugInfo(
|
|
556
|
+
`No ChatMessageEvent matching criteria found in range [${this._range.start}:${this._range.end}]`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Assert that a function call output matching criteria exists in this event range.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```typescript
|
|
564
|
+
* result.expect.range(1, 4).containsFunctionCallOutput({ isError: true });
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
containsFunctionCallOutput(options) {
|
|
568
|
+
for (let idx = 0; idx < this._events.length; idx++) {
|
|
569
|
+
const ev = this._events[idx];
|
|
570
|
+
const candidate = new EventAssert(ev, this._parent, this._range.start + idx);
|
|
571
|
+
try {
|
|
572
|
+
return candidate.isFunctionCallOutput(options);
|
|
573
|
+
} catch {
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
this._parent._raiseWithDebugInfo(
|
|
577
|
+
`No FunctionCallOutputEvent matching criteria found in range [${this._range.start}:${this._range.end}]`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Assert that an agent handoff matching criteria exists in this event range.
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```typescript
|
|
585
|
+
* result.expect.range(0, 3).containsAgentHandoff({ newAgentType: MyAgent });
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
containsAgentHandoff(options) {
|
|
589
|
+
for (let idx = 0; idx < this._events.length; idx++) {
|
|
590
|
+
const ev = this._events[idx];
|
|
591
|
+
const candidate = new EventAssert(ev, this._parent, this._range.start + idx);
|
|
592
|
+
try {
|
|
593
|
+
return candidate.isAgentHandoff(options);
|
|
594
|
+
} catch {
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
this._parent._raiseWithDebugInfo(
|
|
598
|
+
`No AgentHandoffEvent matching criteria found in range [${this._range.start}:${this._range.end}]`
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
class MessageAssert extends EventAssert {
|
|
603
|
+
constructor(event, parent, index) {
|
|
604
|
+
super(event, parent, index);
|
|
605
|
+
}
|
|
606
|
+
event() {
|
|
607
|
+
return this._event;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Evaluate whether the message fulfills the given intent using an LLM.
|
|
611
|
+
*
|
|
612
|
+
* @param llm - LLM instance for judgment
|
|
613
|
+
* @param options - Options containing the intent description
|
|
614
|
+
* @returns Self for chaining further assertions
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* await result.expect
|
|
619
|
+
* .nextEvent()
|
|
620
|
+
* .isMessage({ role: 'assistant' })
|
|
621
|
+
* .judge(llm, { intent: 'should ask for the drink size' });
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
async judge(llm, options) {
|
|
625
|
+
const { intent } = options;
|
|
626
|
+
const content = this._event.item.content;
|
|
627
|
+
const msgContent = typeof content === "string" ? content : Array.isArray(content) ? content.filter((c) => typeof c === "string").join(" ") : "";
|
|
628
|
+
if (!msgContent) {
|
|
629
|
+
this._raise("The chat message is empty.");
|
|
630
|
+
}
|
|
631
|
+
if (!intent) {
|
|
632
|
+
this._raise("Intent is required to judge the message.");
|
|
633
|
+
}
|
|
634
|
+
const checkIntentTool = (0, import_tool_context.tool)({
|
|
635
|
+
description: "Determines whether the message correctly fulfills the given intent. Returns success=true if the message satisfies the intent, false otherwise. Provide a concise reason justifying the result.",
|
|
636
|
+
parameters: import_zod.z.object({
|
|
637
|
+
success: import_zod.z.boolean().describe("Whether the message satisfies the intent"),
|
|
638
|
+
reason: import_zod.z.string().describe("A concise explanation justifying the result")
|
|
639
|
+
}),
|
|
640
|
+
execute: async ({ success: success2, reason: reason2 }) => {
|
|
641
|
+
return { success: success2, reason: reason2 };
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
const chatCtx = import_chat_context.ChatContext.empty();
|
|
645
|
+
chatCtx.addMessage({
|
|
646
|
+
role: "system",
|
|
647
|
+
content: "You are a test evaluator for conversational agents.\nYou will be shown a message and a target intent. Determine whether the message accomplishes the intent.\nOnly respond by calling the `check_intent(success: bool, reason: str)` function with your final judgment.\nBe strict: if the message does not clearly fulfill the intent, return `success = false` and explain why."
|
|
648
|
+
});
|
|
649
|
+
chatCtx.addMessage({
|
|
650
|
+
role: "user",
|
|
651
|
+
content: `Check if the following message fulfills the given intent.
|
|
652
|
+
|
|
653
|
+
Intent:
|
|
654
|
+
${intent}
|
|
655
|
+
|
|
656
|
+
Message:
|
|
657
|
+
${msgContent}`
|
|
658
|
+
});
|
|
659
|
+
let toolArgs;
|
|
660
|
+
const stream = llm.chat({
|
|
661
|
+
chatCtx,
|
|
662
|
+
toolCtx: { check_intent: checkIntentTool },
|
|
663
|
+
toolChoice: { type: "function", function: { name: "check_intent" } },
|
|
664
|
+
extraKwargs: { temperature: 0 }
|
|
665
|
+
});
|
|
666
|
+
for await (const chunk of stream) {
|
|
667
|
+
if (!chunk.delta) continue;
|
|
668
|
+
if (chunk.delta.toolCalls && chunk.delta.toolCalls.length > 0) {
|
|
669
|
+
const toolCall = chunk.delta.toolCalls[0];
|
|
670
|
+
if (toolCall.args) {
|
|
671
|
+
try {
|
|
672
|
+
toolArgs = JSON.parse(toolCall.args);
|
|
673
|
+
} catch {
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (!toolArgs) {
|
|
679
|
+
this._raise("LLM did not return any arguments for evaluation.");
|
|
680
|
+
}
|
|
681
|
+
const { success, reason } = toolArgs;
|
|
682
|
+
if (!success) {
|
|
683
|
+
this._raise(`Judgment failed: ${reason}`);
|
|
684
|
+
} else if (evalsVerbose) {
|
|
685
|
+
const printMsg = msgContent.length > 30 ? msgContent.slice(0, 30).replace(/\n/g, "\\n") + "..." : msgContent;
|
|
686
|
+
console.log(`- Judgment succeeded for \`${printMsg}\`: \`${reason}\``);
|
|
687
|
+
}
|
|
688
|
+
return this;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
class FunctionCallAssert extends EventAssert {
|
|
692
|
+
constructor(event, parent, index) {
|
|
693
|
+
super(event, parent, index);
|
|
694
|
+
}
|
|
695
|
+
event() {
|
|
696
|
+
return this._event;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
class FunctionCallOutputAssert extends EventAssert {
|
|
700
|
+
constructor(event, parent, index) {
|
|
701
|
+
super(event, parent, index);
|
|
702
|
+
}
|
|
703
|
+
event() {
|
|
704
|
+
return this._event;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
class AgentHandoffAssert extends EventAssert {
|
|
708
|
+
constructor(event, parent, index) {
|
|
709
|
+
super(event, parent, index);
|
|
710
|
+
}
|
|
711
|
+
event() {
|
|
712
|
+
return this._event;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
class AssertionError extends Error {
|
|
716
|
+
constructor(message) {
|
|
717
|
+
var _a;
|
|
718
|
+
super(message);
|
|
719
|
+
this.name = "AssertionError";
|
|
720
|
+
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, this, AssertionError);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function formatEvents(events, selectedIndex) {
|
|
724
|
+
var _a;
|
|
725
|
+
const lines = [];
|
|
726
|
+
for (let i = 0; i < events.length; i++) {
|
|
727
|
+
const event = events[i];
|
|
728
|
+
let prefix = "";
|
|
729
|
+
if (selectedIndex !== void 0) {
|
|
730
|
+
prefix = i === selectedIndex ? ">>>" : " ";
|
|
731
|
+
}
|
|
732
|
+
let line;
|
|
733
|
+
if ((0, import_types.isChatMessageEvent)(event)) {
|
|
734
|
+
const { role, content, interrupted } = event.item;
|
|
735
|
+
const textContent = typeof content === "string" ? content : Array.isArray(content) ? content.filter((c) => typeof c === "string").join(" ") : "";
|
|
736
|
+
const truncated = textContent.length > 50 ? textContent.slice(0, 50) + "..." : textContent;
|
|
737
|
+
line = `${prefix}[${i}] { type: "message", role: "${role}", content: "${truncated}", interrupted: ${interrupted} }`;
|
|
738
|
+
} else if ((0, import_types.isFunctionCallEvent)(event)) {
|
|
739
|
+
const { name, args } = event.item;
|
|
740
|
+
line = `${prefix}[${i}] { type: "function_call", name: "${name}", args: ${args} }`;
|
|
741
|
+
} else if ((0, import_types.isFunctionCallOutputEvent)(event)) {
|
|
742
|
+
const { output, isError } = event.item;
|
|
743
|
+
const truncated = output.length > 50 ? output.slice(0, 50) + "..." : output;
|
|
744
|
+
line = `${prefix}[${i}] { type: "function_call_output", output: "${truncated}", isError: ${isError} }`;
|
|
745
|
+
} else if ((0, import_types.isAgentHandoffEvent)(event)) {
|
|
746
|
+
line = `${prefix}[${i}] { type: "agent_handoff", oldAgent: "${(_a = event.oldAgent) == null ? void 0 : _a.constructor.name}", newAgent: "${event.newAgent.constructor.name}" }`;
|
|
747
|
+
} else {
|
|
748
|
+
line = `${prefix}[${i}] ${event}`;
|
|
749
|
+
}
|
|
750
|
+
lines.push(line);
|
|
751
|
+
}
|
|
752
|
+
return lines;
|
|
753
|
+
}
|
|
754
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
755
|
+
0 && (module.exports = {
|
|
756
|
+
AgentHandoffAssert,
|
|
757
|
+
AssertionError,
|
|
758
|
+
EventAssert,
|
|
759
|
+
EventRangeAssert,
|
|
760
|
+
FunctionCallAssert,
|
|
761
|
+
FunctionCallOutputAssert,
|
|
762
|
+
MessageAssert,
|
|
763
|
+
RunAssert,
|
|
764
|
+
RunResult
|
|
765
|
+
});
|
|
766
|
+
//# sourceMappingURL=run_result.cjs.map
|