@agentick/shared 0.0.1
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/LICENSE +21 -0
- package/README.md +322 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/.tsbuildinfo.build +1 -0
- package/dist/block-types.d.ts +85 -0
- package/dist/block-types.d.ts.map +1 -0
- package/dist/block-types.js +98 -0
- package/dist/block-types.js.map +1 -0
- package/dist/blocks.d.ts +396 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +209 -0
- package/dist/blocks.js.map +1 -0
- package/dist/devtools.d.ts +672 -0
- package/dist/devtools.d.ts.map +1 -0
- package/dist/devtools.js +445 -0
- package/dist/devtools.js.map +1 -0
- package/dist/errors.d.ts +335 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +529 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity.d.ts +99 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +116 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +55 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +83 -0
- package/dist/input.js.map +1 -0
- package/dist/messages.d.ts +98 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +81 -0
- package/dist/messages.js.map +1 -0
- package/dist/model-catalog.d.ts +144 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +861 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/models.d.ts +173 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +10 -0
- package/dist/models.js.map +1 -0
- package/dist/protocol.d.ts +257 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +41 -0
- package/dist/protocol.js.map +1 -0
- package/dist/streaming.d.ts +635 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +134 -0
- package/dist/streaming.js.map +1 -0
- package/dist/testing/fixtures.d.ts +250 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +827 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/helpers.d.ts +95 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/helpers.js +271 -0
- package/dist/testing/helpers.js.map +1 -0
- package/dist/testing/index.d.ts +42 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +70 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/timeline.d.ts +59 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +11 -0
- package/dist/timeline.js.map +1 -0
- package/dist/tools.d.ts +220 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +63 -0
- package/dist/tools.js.map +1 -0
- package/dist/utils/entity-ids.d.ts +26 -0
- package/dist/utils/entity-ids.d.ts.map +1 -0
- package/dist/utils/entity-ids.js +44 -0
- package/dist/utils/entity-ids.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge-deep.d.ts +10 -0
- package/dist/utils/merge-deep.d.ts.map +1 -0
- package/dist/utils/merge-deep.js +33 -0
- package/dist/utils/merge-deep.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Fixtures
|
|
3
|
+
*
|
|
4
|
+
* Factory functions for creating test data with sensible defaults.
|
|
5
|
+
* All functions accept partial overrides for flexibility.
|
|
6
|
+
*/
|
|
7
|
+
import { BlockType } from "../block-types";
|
|
8
|
+
import { StopReason, } from "../streaming";
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// ID Generation
|
|
11
|
+
// =============================================================================
|
|
12
|
+
let idCounter = 0;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a unique test ID
|
|
15
|
+
*/
|
|
16
|
+
export function testId(prefix = "test") {
|
|
17
|
+
return `${prefix}-${++idCounter}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reset the ID counter (call in beforeEach)
|
|
21
|
+
*/
|
|
22
|
+
export function resetTestIds() {
|
|
23
|
+
idCounter = 0;
|
|
24
|
+
}
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// Content Block Fixtures
|
|
27
|
+
// =============================================================================
|
|
28
|
+
/**
|
|
29
|
+
* Create a text block
|
|
30
|
+
*/
|
|
31
|
+
export function createTextBlock(text = "Test text content", overrides = {}) {
|
|
32
|
+
return {
|
|
33
|
+
type: "text",
|
|
34
|
+
text,
|
|
35
|
+
...overrides,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create an image block with URL source
|
|
40
|
+
*/
|
|
41
|
+
export function createImageBlock(url = "https://example.com/image.png", overrides = {}) {
|
|
42
|
+
return {
|
|
43
|
+
type: "image",
|
|
44
|
+
source: { type: "url", url },
|
|
45
|
+
...overrides,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create an image block with base64 source
|
|
50
|
+
*/
|
|
51
|
+
export function createBase64ImageBlock(data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", mimeType = "image/png", overrides = {}) {
|
|
52
|
+
return {
|
|
53
|
+
type: "image",
|
|
54
|
+
source: { type: "base64", data, mimeType },
|
|
55
|
+
...overrides,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a tool use block
|
|
60
|
+
*/
|
|
61
|
+
export function createToolUseBlock(name = "test_tool", input = {}, overrides = {}) {
|
|
62
|
+
return {
|
|
63
|
+
type: "tool_use",
|
|
64
|
+
toolUseId: overrides.toolUseId ?? testId("tool-use"),
|
|
65
|
+
name,
|
|
66
|
+
input,
|
|
67
|
+
...overrides,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a tool result block
|
|
72
|
+
*/
|
|
73
|
+
export function createToolResultBlock(toolUseId, content = [createTextBlock("Tool result")], overrides = {}) {
|
|
74
|
+
return {
|
|
75
|
+
type: "tool_result",
|
|
76
|
+
toolUseId,
|
|
77
|
+
name: overrides.name ?? "test_tool",
|
|
78
|
+
content,
|
|
79
|
+
isError: false,
|
|
80
|
+
...overrides,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create an error tool result block
|
|
85
|
+
*/
|
|
86
|
+
export function createErrorToolResultBlock(toolUseId, errorMessage = "Tool execution failed", overrides = {}) {
|
|
87
|
+
return createToolResultBlock(toolUseId, [createTextBlock(errorMessage)], {
|
|
88
|
+
...overrides,
|
|
89
|
+
isError: true,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a reasoning block
|
|
94
|
+
*/
|
|
95
|
+
export function createReasoningBlock(text = "Let me think about this...", overrides = {}) {
|
|
96
|
+
return {
|
|
97
|
+
type: "reasoning",
|
|
98
|
+
text,
|
|
99
|
+
...overrides,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a code block
|
|
104
|
+
*/
|
|
105
|
+
export function createCodeBlock(text = "console.log('Hello');", language = "typescript", overrides = {}) {
|
|
106
|
+
return {
|
|
107
|
+
type: "code",
|
|
108
|
+
text,
|
|
109
|
+
language: language,
|
|
110
|
+
...overrides,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// =============================================================================
|
|
114
|
+
// Message Fixtures
|
|
115
|
+
// =============================================================================
|
|
116
|
+
/**
|
|
117
|
+
* Create a user message
|
|
118
|
+
*/
|
|
119
|
+
export function createUserMessage(content = "Hello", overrides = {}) {
|
|
120
|
+
const contentBlocks = typeof content === "string" ? [createTextBlock(content)] : content;
|
|
121
|
+
return {
|
|
122
|
+
id: overrides.id ?? testId("msg"),
|
|
123
|
+
role: "user",
|
|
124
|
+
content: contentBlocks,
|
|
125
|
+
...overrides,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create an assistant message
|
|
130
|
+
*/
|
|
131
|
+
export function createAssistantMessage(content = "Hello! How can I help?", overrides = {}) {
|
|
132
|
+
const contentBlocks = typeof content === "string" ? [createTextBlock(content)] : content;
|
|
133
|
+
return {
|
|
134
|
+
id: overrides.id ?? testId("msg"),
|
|
135
|
+
role: "assistant",
|
|
136
|
+
content: contentBlocks,
|
|
137
|
+
...overrides,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a system message
|
|
142
|
+
*/
|
|
143
|
+
export function createSystemMessage(content = "You are a helpful assistant.", overrides = {}) {
|
|
144
|
+
return {
|
|
145
|
+
id: overrides.id ?? testId("msg"),
|
|
146
|
+
role: "system",
|
|
147
|
+
content: [createTextBlock(content)],
|
|
148
|
+
...overrides,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a tool message (tool result)
|
|
153
|
+
*/
|
|
154
|
+
export function createToolMessage(toolUseId, content = [createTextBlock("Tool result")], overrides = {}) {
|
|
155
|
+
return {
|
|
156
|
+
id: overrides.id ?? testId("msg"),
|
|
157
|
+
role: "tool",
|
|
158
|
+
content,
|
|
159
|
+
...overrides,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a conversation (array of messages)
|
|
164
|
+
*/
|
|
165
|
+
export function createConversation(exchanges) {
|
|
166
|
+
const messages = [];
|
|
167
|
+
for (const exchange of exchanges) {
|
|
168
|
+
messages.push(createUserMessage(exchange.user));
|
|
169
|
+
messages.push(createAssistantMessage(exchange.assistant));
|
|
170
|
+
}
|
|
171
|
+
return messages;
|
|
172
|
+
}
|
|
173
|
+
// =============================================================================
|
|
174
|
+
// Tool Fixtures
|
|
175
|
+
// =============================================================================
|
|
176
|
+
/**
|
|
177
|
+
* Create a tool definition
|
|
178
|
+
*/
|
|
179
|
+
export function createToolDefinition(name = "test_tool", overrides = {}) {
|
|
180
|
+
return {
|
|
181
|
+
name,
|
|
182
|
+
description: overrides.description ?? `A test tool called ${name}`,
|
|
183
|
+
input: overrides.input ?? {
|
|
184
|
+
type: "object",
|
|
185
|
+
properties: {
|
|
186
|
+
value: { type: "string", description: "Input value" },
|
|
187
|
+
},
|
|
188
|
+
required: ["value"],
|
|
189
|
+
},
|
|
190
|
+
...overrides,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Create an agent tool call
|
|
195
|
+
*/
|
|
196
|
+
export function createToolCall(name = "test_tool", input = { input: "test" }, overrides = {}) {
|
|
197
|
+
return {
|
|
198
|
+
id: overrides.id ?? testId("call"),
|
|
199
|
+
name,
|
|
200
|
+
input,
|
|
201
|
+
...overrides,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Create an agent tool result
|
|
206
|
+
*/
|
|
207
|
+
export function createToolResult(toolUseId, content = [createTextBlock("Result")], overrides = {}) {
|
|
208
|
+
return {
|
|
209
|
+
toolUseId,
|
|
210
|
+
name: overrides.name ?? "test_tool",
|
|
211
|
+
success: overrides.success ?? true,
|
|
212
|
+
content,
|
|
213
|
+
...overrides,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// =============================================================================
|
|
217
|
+
// StreamEvent Fixtures (New typed event system)
|
|
218
|
+
// =============================================================================
|
|
219
|
+
/**
|
|
220
|
+
* Create a StreamEventBase with default values.
|
|
221
|
+
* All StreamEvent types extend this base.
|
|
222
|
+
*/
|
|
223
|
+
export function createEventBase(tick = 1, overrides = {}) {
|
|
224
|
+
return {
|
|
225
|
+
id: overrides.id ?? testId("evt"),
|
|
226
|
+
sequence: overrides.sequence ?? 0, // In tests, sequence defaults to 0; in production, session assigns monotonically increasing values
|
|
227
|
+
tick,
|
|
228
|
+
timestamp: overrides.timestamp ?? new Date().toISOString(),
|
|
229
|
+
raw: overrides.raw,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// -----------------------------------------------------------------------------
|
|
233
|
+
// Content Events
|
|
234
|
+
// -----------------------------------------------------------------------------
|
|
235
|
+
/**
|
|
236
|
+
* Create a content_start event
|
|
237
|
+
*/
|
|
238
|
+
export function createContentStartEvent(blockType = BlockType.TEXT, blockIndex = 0, overrides = {}) {
|
|
239
|
+
return {
|
|
240
|
+
type: "content_start",
|
|
241
|
+
blockType,
|
|
242
|
+
blockIndex,
|
|
243
|
+
...createEventBase(overrides.tick, overrides),
|
|
244
|
+
...overrides,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create a content_delta event
|
|
249
|
+
*/
|
|
250
|
+
export function createContentDeltaEvent(delta, blockType = BlockType.TEXT, blockIndex = 0, overrides = {}) {
|
|
251
|
+
return {
|
|
252
|
+
type: "content_delta",
|
|
253
|
+
blockType,
|
|
254
|
+
blockIndex,
|
|
255
|
+
delta,
|
|
256
|
+
...createEventBase(overrides.tick, overrides),
|
|
257
|
+
...overrides,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Create a content_end event
|
|
262
|
+
*/
|
|
263
|
+
export function createContentEndEvent(blockType = BlockType.TEXT, blockIndex = 0, overrides = {}) {
|
|
264
|
+
return {
|
|
265
|
+
type: "content_end",
|
|
266
|
+
blockType,
|
|
267
|
+
blockIndex,
|
|
268
|
+
...createEventBase(overrides.tick, overrides),
|
|
269
|
+
...overrides,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Create a content (complete) event
|
|
274
|
+
*/
|
|
275
|
+
export function createContentEvent(content, blockIndex = 0, overrides = {}) {
|
|
276
|
+
const now = new Date().toISOString();
|
|
277
|
+
return {
|
|
278
|
+
type: "content",
|
|
279
|
+
blockIndex,
|
|
280
|
+
content,
|
|
281
|
+
startedAt: overrides.startedAt ?? now,
|
|
282
|
+
completedAt: overrides.completedAt ?? now,
|
|
283
|
+
...createEventBase(overrides.tick, overrides),
|
|
284
|
+
...overrides,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// -----------------------------------------------------------------------------
|
|
288
|
+
// Reasoning Events
|
|
289
|
+
// -----------------------------------------------------------------------------
|
|
290
|
+
/**
|
|
291
|
+
* Create a reasoning_start event
|
|
292
|
+
*/
|
|
293
|
+
export function createReasoningStartEvent(blockIndex = 0, overrides = {}) {
|
|
294
|
+
return {
|
|
295
|
+
type: "reasoning_start",
|
|
296
|
+
blockIndex,
|
|
297
|
+
...createEventBase(overrides.tick, overrides),
|
|
298
|
+
...overrides,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create a reasoning_delta event
|
|
303
|
+
*/
|
|
304
|
+
export function createReasoningDeltaEvent(delta, blockIndex = 0, overrides = {}) {
|
|
305
|
+
return {
|
|
306
|
+
type: "reasoning_delta",
|
|
307
|
+
blockIndex,
|
|
308
|
+
delta,
|
|
309
|
+
...createEventBase(overrides.tick, overrides),
|
|
310
|
+
...overrides,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Create a reasoning_end event
|
|
315
|
+
*/
|
|
316
|
+
export function createReasoningEndEvent(blockIndex = 0, overrides = {}) {
|
|
317
|
+
return {
|
|
318
|
+
type: "reasoning_end",
|
|
319
|
+
blockIndex,
|
|
320
|
+
...createEventBase(overrides.tick, overrides),
|
|
321
|
+
...overrides,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Create a reasoning (complete) event
|
|
326
|
+
*/
|
|
327
|
+
export function createReasoningCompleteEvent(reasoning, blockIndex = 0, overrides = {}) {
|
|
328
|
+
const now = new Date().toISOString();
|
|
329
|
+
return {
|
|
330
|
+
type: "reasoning",
|
|
331
|
+
blockIndex,
|
|
332
|
+
reasoning,
|
|
333
|
+
startedAt: overrides.startedAt ?? now,
|
|
334
|
+
completedAt: overrides.completedAt ?? now,
|
|
335
|
+
...createEventBase(overrides.tick, overrides),
|
|
336
|
+
...overrides,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
// -----------------------------------------------------------------------------
|
|
340
|
+
// Message Events
|
|
341
|
+
// -----------------------------------------------------------------------------
|
|
342
|
+
/**
|
|
343
|
+
* Create a message_start event
|
|
344
|
+
*/
|
|
345
|
+
export function createMessageStartEvent(model, overrides = {}) {
|
|
346
|
+
return {
|
|
347
|
+
type: "message_start",
|
|
348
|
+
role: "assistant",
|
|
349
|
+
model,
|
|
350
|
+
...createEventBase(overrides.tick, overrides),
|
|
351
|
+
...overrides,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Create a message_end event
|
|
356
|
+
*/
|
|
357
|
+
export function createMessageEndEvent(stopReason = StopReason.STOP, usage, overrides = {}) {
|
|
358
|
+
return {
|
|
359
|
+
type: "message_end",
|
|
360
|
+
stopReason,
|
|
361
|
+
usage,
|
|
362
|
+
...createEventBase(overrides.tick, overrides),
|
|
363
|
+
...overrides,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Create a message (complete) event
|
|
368
|
+
*/
|
|
369
|
+
export function createMessageCompleteEvent(message, stopReason = StopReason.STOP, overrides = {}) {
|
|
370
|
+
const now = new Date().toISOString();
|
|
371
|
+
return {
|
|
372
|
+
type: "message",
|
|
373
|
+
message,
|
|
374
|
+
stopReason,
|
|
375
|
+
usage: overrides.usage,
|
|
376
|
+
model: overrides.model,
|
|
377
|
+
startedAt: overrides.startedAt ?? now,
|
|
378
|
+
completedAt: overrides.completedAt ?? now,
|
|
379
|
+
...createEventBase(overrides.tick, overrides),
|
|
380
|
+
...overrides,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
// -----------------------------------------------------------------------------
|
|
384
|
+
// Tool Call Events
|
|
385
|
+
// -----------------------------------------------------------------------------
|
|
386
|
+
/**
|
|
387
|
+
* Create a tool_call_start event
|
|
388
|
+
*/
|
|
389
|
+
export function createToolCallStartEvent(name, callId = testId("call"), blockIndex = 0, overrides = {}) {
|
|
390
|
+
return {
|
|
391
|
+
type: "tool_call_start",
|
|
392
|
+
callId,
|
|
393
|
+
name,
|
|
394
|
+
blockIndex,
|
|
395
|
+
...createEventBase(overrides.tick, overrides),
|
|
396
|
+
...overrides,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Create a tool_call_delta event
|
|
401
|
+
*/
|
|
402
|
+
export function createToolCallDeltaEvent(callId, delta, blockIndex = 0, overrides = {}) {
|
|
403
|
+
return {
|
|
404
|
+
type: "tool_call_delta",
|
|
405
|
+
callId,
|
|
406
|
+
blockIndex,
|
|
407
|
+
delta,
|
|
408
|
+
...createEventBase(overrides.tick, overrides),
|
|
409
|
+
...overrides,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Create a tool_call_end event
|
|
414
|
+
*/
|
|
415
|
+
export function createToolCallEndEvent(callId, blockIndex = 0, overrides = {}) {
|
|
416
|
+
return {
|
|
417
|
+
type: "tool_call_end",
|
|
418
|
+
callId,
|
|
419
|
+
blockIndex,
|
|
420
|
+
...createEventBase(overrides.tick, overrides),
|
|
421
|
+
...overrides,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Create a tool_call (complete) event
|
|
426
|
+
*/
|
|
427
|
+
export function createToolCallCompleteEvent(name, input = {}, callId = testId("call"), blockIndex = 0, overrides = {}) {
|
|
428
|
+
const now = new Date().toISOString();
|
|
429
|
+
return {
|
|
430
|
+
type: "tool_call",
|
|
431
|
+
callId,
|
|
432
|
+
blockIndex,
|
|
433
|
+
name,
|
|
434
|
+
input,
|
|
435
|
+
startedAt: overrides.startedAt ?? now,
|
|
436
|
+
completedAt: overrides.completedAt ?? now,
|
|
437
|
+
...createEventBase(overrides.tick, overrides),
|
|
438
|
+
...overrides,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
// -----------------------------------------------------------------------------
|
|
442
|
+
// Error Events
|
|
443
|
+
// -----------------------------------------------------------------------------
|
|
444
|
+
/**
|
|
445
|
+
* Create a stream error event
|
|
446
|
+
*/
|
|
447
|
+
export function createStreamErrorEvent(message, code, overrides = {}) {
|
|
448
|
+
return {
|
|
449
|
+
type: "error",
|
|
450
|
+
error: { message, code },
|
|
451
|
+
...createEventBase(overrides.tick, overrides),
|
|
452
|
+
...overrides,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
// =============================================================================
|
|
456
|
+
// OrchestrationStreamEvent Fixtures (Orchestration events)
|
|
457
|
+
// =============================================================================
|
|
458
|
+
// -----------------------------------------------------------------------------
|
|
459
|
+
// Execution Events
|
|
460
|
+
// -----------------------------------------------------------------------------
|
|
461
|
+
/**
|
|
462
|
+
* Create an execution_start event
|
|
463
|
+
*/
|
|
464
|
+
export function createExecutionStartEvent(executionId = testId("exec"), overrides = {}) {
|
|
465
|
+
return {
|
|
466
|
+
type: "execution_start",
|
|
467
|
+
executionId,
|
|
468
|
+
parentExecutionId: overrides.parentExecutionId,
|
|
469
|
+
rootExecutionId: overrides.rootExecutionId,
|
|
470
|
+
componentName: overrides.componentName,
|
|
471
|
+
sessionId: overrides.sessionId,
|
|
472
|
+
metadata: overrides.metadata,
|
|
473
|
+
...createEventBase(overrides.tick, overrides),
|
|
474
|
+
...overrides,
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Create an execution_end event
|
|
479
|
+
*/
|
|
480
|
+
export function createExecutionEndEvent(executionId, output = null, overrides = {}) {
|
|
481
|
+
return {
|
|
482
|
+
type: "execution_end",
|
|
483
|
+
executionId,
|
|
484
|
+
output,
|
|
485
|
+
parentExecutionId: overrides.parentExecutionId,
|
|
486
|
+
rootExecutionId: overrides.rootExecutionId,
|
|
487
|
+
sessionId: overrides.sessionId,
|
|
488
|
+
metadata: overrides.metadata,
|
|
489
|
+
...createEventBase(overrides.tick, overrides),
|
|
490
|
+
...overrides,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Create an execution (complete) event
|
|
495
|
+
*/
|
|
496
|
+
export function createExecutionCompleteEvent(executionId = testId("exec"), output = null, overrides = {}) {
|
|
497
|
+
const now = new Date().toISOString();
|
|
498
|
+
return {
|
|
499
|
+
type: "execution",
|
|
500
|
+
executionId,
|
|
501
|
+
output,
|
|
502
|
+
usage: overrides.usage ?? createUsageStats(),
|
|
503
|
+
stopReason: overrides.stopReason ?? StopReason.STOP,
|
|
504
|
+
ticks: overrides.ticks ?? 1,
|
|
505
|
+
parentExecutionId: overrides.parentExecutionId,
|
|
506
|
+
rootExecutionId: overrides.rootExecutionId,
|
|
507
|
+
sessionId: overrides.sessionId,
|
|
508
|
+
metadata: overrides.metadata,
|
|
509
|
+
startedAt: overrides.startedAt ?? now,
|
|
510
|
+
completedAt: overrides.completedAt ?? now,
|
|
511
|
+
...createEventBase(overrides.tick, overrides),
|
|
512
|
+
...overrides,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
// -----------------------------------------------------------------------------
|
|
516
|
+
// Result Events
|
|
517
|
+
// -----------------------------------------------------------------------------
|
|
518
|
+
/**
|
|
519
|
+
* Create a session result event.
|
|
520
|
+
*/
|
|
521
|
+
export function createResultStreamEvent(result = {
|
|
522
|
+
response: "Test response",
|
|
523
|
+
outputs: {},
|
|
524
|
+
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
|
|
525
|
+
stopReason: StopReason.STOP,
|
|
526
|
+
}, overrides = {}) {
|
|
527
|
+
return {
|
|
528
|
+
type: "result",
|
|
529
|
+
result,
|
|
530
|
+
...createEventBase(overrides.tick, overrides),
|
|
531
|
+
...overrides,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
// -----------------------------------------------------------------------------
|
|
535
|
+
// Tick Events
|
|
536
|
+
// -----------------------------------------------------------------------------
|
|
537
|
+
/**
|
|
538
|
+
* Create a tick_start event
|
|
539
|
+
*/
|
|
540
|
+
export function createTickStartEvent(tickNumber = 1, overrides = {}) {
|
|
541
|
+
const base = createEventBase(tickNumber, overrides);
|
|
542
|
+
return {
|
|
543
|
+
type: "tick_start",
|
|
544
|
+
...base,
|
|
545
|
+
tick: tickNumber, // Override base.tick with explicit tickNumber
|
|
546
|
+
...overrides,
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Create a tick_end event
|
|
551
|
+
*/
|
|
552
|
+
export function createTickEndEvent(tickNumber = 1, usage, overrides = {}) {
|
|
553
|
+
const base = createEventBase(tickNumber, overrides);
|
|
554
|
+
return {
|
|
555
|
+
type: "tick_end",
|
|
556
|
+
...base,
|
|
557
|
+
tick: tickNumber, // Override base.tick with explicit tickNumber
|
|
558
|
+
usage,
|
|
559
|
+
...overrides,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Create a tick (complete) event
|
|
564
|
+
*/
|
|
565
|
+
export function createTickCompleteEvent(tickNumber = 1, overrides = {}) {
|
|
566
|
+
const now = new Date().toISOString();
|
|
567
|
+
const base = createEventBase(tickNumber, overrides);
|
|
568
|
+
return {
|
|
569
|
+
type: "tick",
|
|
570
|
+
...base,
|
|
571
|
+
tick: tickNumber, // Override base.tick with explicit tickNumber
|
|
572
|
+
usage: overrides.usage ?? createUsageStats(),
|
|
573
|
+
stopReason: overrides.stopReason ?? StopReason.STOP,
|
|
574
|
+
startedAt: overrides.startedAt ?? now,
|
|
575
|
+
completedAt: overrides.completedAt ?? now,
|
|
576
|
+
...overrides,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
// -----------------------------------------------------------------------------
|
|
580
|
+
// Tool Result Events
|
|
581
|
+
// -----------------------------------------------------------------------------
|
|
582
|
+
/**
|
|
583
|
+
* Create a tool_result event
|
|
584
|
+
*/
|
|
585
|
+
export function createToolResultEvent(callId, name, result, executedBy = "engine", overrides = {}) {
|
|
586
|
+
const now = new Date().toISOString();
|
|
587
|
+
return {
|
|
588
|
+
type: "tool_result",
|
|
589
|
+
callId,
|
|
590
|
+
name,
|
|
591
|
+
result,
|
|
592
|
+
isError: overrides.isError ?? false,
|
|
593
|
+
executedBy,
|
|
594
|
+
startedAt: overrides.startedAt ?? now,
|
|
595
|
+
completedAt: overrides.completedAt ?? now,
|
|
596
|
+
...createEventBase(overrides.tick, overrides),
|
|
597
|
+
...overrides,
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Create an error tool_result event
|
|
602
|
+
*/
|
|
603
|
+
export function createErrorToolResultEvent(callId, name, errorMessage, executedBy = "engine", overrides = {}) {
|
|
604
|
+
return createToolResultEvent(callId, name, { error: errorMessage }, executedBy, {
|
|
605
|
+
...overrides,
|
|
606
|
+
isError: true,
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
// -----------------------------------------------------------------------------
|
|
610
|
+
// Tool Confirmation Events
|
|
611
|
+
// -----------------------------------------------------------------------------
|
|
612
|
+
/**
|
|
613
|
+
* Create a tool_confirmation_required event
|
|
614
|
+
*/
|
|
615
|
+
export function createToolConfirmationRequiredEvent(callId, name, input = {}, message = "Confirm tool execution?", overrides = {}) {
|
|
616
|
+
return {
|
|
617
|
+
type: "tool_confirmation_required",
|
|
618
|
+
callId,
|
|
619
|
+
name,
|
|
620
|
+
input,
|
|
621
|
+
message,
|
|
622
|
+
...createEventBase(overrides.tick, overrides),
|
|
623
|
+
...overrides,
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Create a tool_confirmation_result event
|
|
628
|
+
*/
|
|
629
|
+
export function createToolConfirmationResultEvent(callId, confirmed, always, overrides = {}) {
|
|
630
|
+
return {
|
|
631
|
+
type: "tool_confirmation_result",
|
|
632
|
+
callId,
|
|
633
|
+
confirmed,
|
|
634
|
+
always,
|
|
635
|
+
...createEventBase(overrides.tick, overrides),
|
|
636
|
+
...overrides,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
// -----------------------------------------------------------------------------
|
|
640
|
+
// Engine Error Events
|
|
641
|
+
// -----------------------------------------------------------------------------
|
|
642
|
+
/**
|
|
643
|
+
* Create an engine_error event
|
|
644
|
+
*/
|
|
645
|
+
export function createEngineErrorEvent(message, code, overrides = {}) {
|
|
646
|
+
return {
|
|
647
|
+
type: "engine_error",
|
|
648
|
+
error: { message, code },
|
|
649
|
+
...createEventBase(overrides.tick, overrides),
|
|
650
|
+
...overrides,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
// -----------------------------------------------------------------------------
|
|
654
|
+
// Fork Events
|
|
655
|
+
// -----------------------------------------------------------------------------
|
|
656
|
+
/**
|
|
657
|
+
* Create a fork_start event
|
|
658
|
+
*/
|
|
659
|
+
export function createForkStartEvent(forkId = testId("fork"), parentExecutionId = testId("exec"), branches = ["branch-0", "branch-1"], strategy = "race", overrides = {}) {
|
|
660
|
+
return {
|
|
661
|
+
type: "fork_start",
|
|
662
|
+
forkId,
|
|
663
|
+
parentExecutionId,
|
|
664
|
+
strategy,
|
|
665
|
+
branches,
|
|
666
|
+
branchCount: branches.length,
|
|
667
|
+
input: overrides.input,
|
|
668
|
+
...createEventBase(overrides.tick, overrides),
|
|
669
|
+
...overrides,
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Create a fork_end event
|
|
674
|
+
*/
|
|
675
|
+
export function createForkEndEvent(forkId, parentExecutionId, results = {}, overrides = {}) {
|
|
676
|
+
return {
|
|
677
|
+
type: "fork_end",
|
|
678
|
+
forkId,
|
|
679
|
+
parentExecutionId,
|
|
680
|
+
selectedBranch: overrides.selectedBranch,
|
|
681
|
+
results,
|
|
682
|
+
usage: overrides.usage,
|
|
683
|
+
...createEventBase(overrides.tick, overrides),
|
|
684
|
+
...overrides,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
// -----------------------------------------------------------------------------
|
|
688
|
+
// Spawn Events
|
|
689
|
+
// -----------------------------------------------------------------------------
|
|
690
|
+
/**
|
|
691
|
+
* Create a spawn_start event
|
|
692
|
+
*/
|
|
693
|
+
export function createSpawnStartEvent(spawnId = testId("spawn"), parentExecutionId = testId("exec"), childExecutionId = testId("exec"), overrides = {}) {
|
|
694
|
+
return {
|
|
695
|
+
type: "spawn_start",
|
|
696
|
+
spawnId,
|
|
697
|
+
parentExecutionId,
|
|
698
|
+
childExecutionId,
|
|
699
|
+
componentName: overrides.componentName,
|
|
700
|
+
label: overrides.label,
|
|
701
|
+
input: overrides.input,
|
|
702
|
+
...createEventBase(overrides.tick, overrides),
|
|
703
|
+
...overrides,
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Create a spawn_end event
|
|
708
|
+
*/
|
|
709
|
+
export function createSpawnEndEvent(spawnId, parentExecutionId, childExecutionId, output = null, overrides = {}) {
|
|
710
|
+
return {
|
|
711
|
+
type: "spawn_end",
|
|
712
|
+
spawnId,
|
|
713
|
+
parentExecutionId,
|
|
714
|
+
childExecutionId,
|
|
715
|
+
output,
|
|
716
|
+
isError: overrides.isError ?? false,
|
|
717
|
+
usage: overrides.usage,
|
|
718
|
+
...createEventBase(overrides.tick, overrides),
|
|
719
|
+
...overrides,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
// =============================================================================
|
|
723
|
+
// StreamEvent Sequences (for testing streaming flows)
|
|
724
|
+
// =============================================================================
|
|
725
|
+
/**
|
|
726
|
+
* Create a sequence of StreamEvents for a simple text response.
|
|
727
|
+
*
|
|
728
|
+
* Follows the pattern: message_start → content_start → content_delta* → content_end → content → message_end → message
|
|
729
|
+
*/
|
|
730
|
+
export function createTextStreamEventSequence(text, chunkSize = 10, tick = 1) {
|
|
731
|
+
const events = [];
|
|
732
|
+
events.push(createMessageStartEvent(undefined, { tick }));
|
|
733
|
+
events.push(createContentStartEvent(BlockType.TEXT, 0, { tick }));
|
|
734
|
+
// Split text into delta chunks
|
|
735
|
+
for (let i = 0; i < text.length; i += chunkSize) {
|
|
736
|
+
events.push(createContentDeltaEvent(text.slice(i, i + chunkSize), BlockType.TEXT, 0, { tick }));
|
|
737
|
+
}
|
|
738
|
+
events.push(createContentEndEvent(BlockType.TEXT, 0, { tick }));
|
|
739
|
+
events.push(createContentEvent(createTextBlock(text), 0, { tick }));
|
|
740
|
+
events.push(createMessageEndEvent(StopReason.STOP, undefined, { tick }));
|
|
741
|
+
// Final message event with fully-formed message
|
|
742
|
+
events.push(createMessageCompleteEvent(createAssistantMessage([createTextBlock(text)]), StopReason.STOP, {
|
|
743
|
+
tick,
|
|
744
|
+
}));
|
|
745
|
+
return events;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Create a sequence of StreamEvents for a tool call.
|
|
749
|
+
*
|
|
750
|
+
* Follows the pattern: message_start → tool_call_start → tool_call_delta* → tool_call_end → tool_call → message_end → message
|
|
751
|
+
*/
|
|
752
|
+
export function createToolCallEventSequence(toolName, toolInput, tick = 1) {
|
|
753
|
+
const events = [];
|
|
754
|
+
const callId = testId("call");
|
|
755
|
+
events.push(createMessageStartEvent(undefined, { tick }));
|
|
756
|
+
events.push(createToolCallStartEvent(toolName, callId, 0, { tick }));
|
|
757
|
+
events.push(createToolCallDeltaEvent(callId, JSON.stringify(toolInput), 0, { tick }));
|
|
758
|
+
events.push(createToolCallEndEvent(callId, 0, { tick }));
|
|
759
|
+
events.push(createToolCallCompleteEvent(toolName, toolInput, callId, 0, { tick }));
|
|
760
|
+
events.push(createMessageEndEvent(StopReason.TOOL_USE, undefined, { tick }));
|
|
761
|
+
// Final message event with fully-formed message containing the tool use block
|
|
762
|
+
events.push(createMessageCompleteEvent(createAssistantMessage([createToolUseBlock(toolName, toolInput, { toolUseId: callId })]), StopReason.TOOL_USE, { tick }));
|
|
763
|
+
return events;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Create a sequence of OrchestrationStreamEvents for a Fork operation.
|
|
767
|
+
*
|
|
768
|
+
* Note: Branch-level events are not included - each branch runs as a
|
|
769
|
+
* separate execution with its own stream. Subscribe to those executions
|
|
770
|
+
* directly if you need branch-level observability.
|
|
771
|
+
*/
|
|
772
|
+
export function createForkEventSequence(branchCount = 2, strategy = "race", input, tick = 1) {
|
|
773
|
+
const events = [];
|
|
774
|
+
const forkId = testId("fork");
|
|
775
|
+
const parentExecutionId = testId("exec");
|
|
776
|
+
const branches = Array.from({ length: branchCount }, (_, i) => `branch-${i}`);
|
|
777
|
+
// Fork start
|
|
778
|
+
events.push(createForkStartEvent(forkId, parentExecutionId, branches, strategy, { tick, input }));
|
|
779
|
+
// Fork end with results (branches run as separate executions)
|
|
780
|
+
const results = {};
|
|
781
|
+
branches.forEach((branch, i) => {
|
|
782
|
+
results[branch] = { result: `output-${i}` };
|
|
783
|
+
});
|
|
784
|
+
events.push(createForkEndEvent(forkId, parentExecutionId, results, {
|
|
785
|
+
tick,
|
|
786
|
+
selectedBranch: strategy === "race" ? branches[0] : undefined,
|
|
787
|
+
usage: createUsageStats(),
|
|
788
|
+
}));
|
|
789
|
+
return events;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Create a sequence of OrchestrationStreamEvents for a Spawn operation
|
|
793
|
+
*/
|
|
794
|
+
export function createSpawnEventSequence(componentName = "ChildAgent", input, output = { result: "spawned result" }, tick = 1) {
|
|
795
|
+
const events = [];
|
|
796
|
+
const spawnId = testId("spawn");
|
|
797
|
+
const parentExecutionId = testId("exec");
|
|
798
|
+
const childExecutionId = testId("exec");
|
|
799
|
+
events.push(createSpawnStartEvent(spawnId, parentExecutionId, childExecutionId, {
|
|
800
|
+
tick,
|
|
801
|
+
componentName,
|
|
802
|
+
input,
|
|
803
|
+
}));
|
|
804
|
+
events.push(createSpawnEndEvent(spawnId, parentExecutionId, childExecutionId, output, {
|
|
805
|
+
tick,
|
|
806
|
+
usage: createUsageStats(),
|
|
807
|
+
}));
|
|
808
|
+
return events;
|
|
809
|
+
}
|
|
810
|
+
// =============================================================================
|
|
811
|
+
// Utility Fixtures
|
|
812
|
+
// =============================================================================
|
|
813
|
+
/**
|
|
814
|
+
* Create a token usage object
|
|
815
|
+
*/
|
|
816
|
+
export function createUsageStats(overrides = {}) {
|
|
817
|
+
return {
|
|
818
|
+
inputTokens: overrides.inputTokens ?? 10,
|
|
819
|
+
outputTokens: overrides.outputTokens ?? 20,
|
|
820
|
+
totalTokens: overrides.totalTokens ?? 30,
|
|
821
|
+
reasoningTokens: overrides.reasoningTokens,
|
|
822
|
+
cachedInputTokens: overrides.cachedInputTokens,
|
|
823
|
+
ticks: overrides.ticks ?? 1,
|
|
824
|
+
cacheCreationTokens: overrides.cacheCreationTokens,
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
//# sourceMappingURL=fixtures.js.map
|