Open History to see the last commit
1/**
2 * Sample trace files for testing the stream processor
3 *
4 * These are extracted from unit tests in @tanstack/ai-client
5 */
6
7import type { ChunkRecording } from '@tanstack/ai'
8
9// Helper to create a base recording
10function createRecording(chunks: any[]): ChunkRecording {
11 return {
12 version: '1.0',
13 timestamp: Date.now(),
14 chunks: chunks.map((chunk, index) => ({
15 chunk,
16 timestamp: Date.now() + index * 10,
17 index,
18 })),
19 }
20}
21
22/**
23 * Simple text streaming - "Hello world!" character by character
24 */
25export const textSimple = createRecording([
26 {
27 type: 'content',
28 id: 'msg-1',
29 model: 'test',
30 timestamp: Date.now(),
31 delta: 'H',
32 content: 'H',
33 role: 'assistant',
34 },
35 {
36 type: 'content',
37 id: 'msg-1',
38 model: 'test',
39 timestamp: Date.now(),
40 delta: 'e',
41 content: 'He',
42 role: 'assistant',
43 },
44 {
45 type: 'content',
46 id: 'msg-1',
47 model: 'test',
48 timestamp: Date.now(),
49 delta: 'l',
50 content: 'Hel',
51 role: 'assistant',
52 },
53 {
54 type: 'content',
55 id: 'msg-1',
56 model: 'test',
57 timestamp: Date.now(),
58 delta: 'l',
59 content: 'Hell',
60 role: 'assistant',
61 },
62 {
63 type: 'content',
64 id: 'msg-1',
65 model: 'test',
66 timestamp: Date.now(),
67 delta: 'o',
68 content: 'Hello',
69 role: 'assistant',
70 },
71 {
72 type: 'content',
73 id: 'msg-1',
74 model: 'test',
75 timestamp: Date.now(),
76 delta: ' ',
77 content: 'Hello ',
78 role: 'assistant',
79 },
80 {
81 type: 'content',
82 id: 'msg-1',
83 model: 'test',
84 timestamp: Date.now(),
85 delta: 'w',
86 content: 'Hello w',
87 role: 'assistant',
88 },
89 {
90 type: 'content',
91 id: 'msg-1',
92 model: 'test',
93 timestamp: Date.now(),
94 delta: 'o',
95 content: 'Hello wo',
96 role: 'assistant',
97 },
98 {
99 type: 'content',
100 id: 'msg-1',
101 model: 'test',
102 timestamp: Date.now(),
103 delta: 'r',
104 content: 'Hello wor',
105 role: 'assistant',
106 },
107 {
108 type: 'content',
109 id: 'msg-1',
110 model: 'test',
111 timestamp: Date.now(),
112 delta: 'l',
113 content: 'Hello worl',
114 role: 'assistant',
115 },
116 {
117 type: 'content',
118 id: 'msg-1',
119 model: 'test',
120 timestamp: Date.now(),
121 delta: 'd',
122 content: 'Hello world',
123 role: 'assistant',
124 },
125 {
126 type: 'content',
127 id: 'msg-1',
128 model: 'test',
129 timestamp: Date.now(),
130 delta: '!',
131 content: 'Hello world!',
132 role: 'assistant',
133 },
134 {
135 type: 'done',
136 id: 'msg-1',
137 model: 'test',
138 timestamp: Date.now(),
139 finishReason: 'stop',
140 },
141])
142
143/**
144 * Text with punctuation - multiple sentences
145 */
146export const textPunctuation = createRecording([
147 {
148 type: 'content',
149 id: 'msg-1',
150 model: 'test',
151 timestamp: Date.now(),
152 delta: 'Hello',
153 content: 'Hello',
154 role: 'assistant',
155 },
156 {
157 type: 'content',
158 id: 'msg-1',
159 model: 'test',
160 timestamp: Date.now(),
161 delta: ' world',
162 content: 'Hello world',
163 role: 'assistant',
164 },
165 {
166 type: 'content',
167 id: 'msg-1',
168 model: 'test',
169 timestamp: Date.now(),
170 delta: '!',
171 content: 'Hello world!',
172 role: 'assistant',
173 },
174 {
175 type: 'content',
176 id: 'msg-1',
177 model: 'test',
178 timestamp: Date.now(),
179 delta: ' How',
180 content: 'Hello world! How',
181 role: 'assistant',
182 },
183 {
184 type: 'content',
185 id: 'msg-1',
186 model: 'test',
187 timestamp: Date.now(),
188 delta: ' are',
189 content: 'Hello world! How are',
190 role: 'assistant',
191 },
192 {
193 type: 'content',
194 id: 'msg-1',
195 model: 'test',
196 timestamp: Date.now(),
197 delta: ' you?',
198 content: 'Hello world! How are you?',
199 role: 'assistant',
200 },
201 {
202 type: 'done',
203 id: 'msg-1',
204 model: 'test',
205 timestamp: Date.now(),
206 finishReason: 'stop',
207 },
208])
209
210/**
211 * Single tool call with streaming arguments
212 */
213export const toolCallSingle = createRecording([
214 {
215 type: 'tool_call',
216 id: 'msg-1',
217 model: 'test',
218 timestamp: Date.now(),
219 toolCall: {
220 id: 'call_1',
221 type: 'function',
222 function: { name: 'getWeather', arguments: '{"lo' },
223 },
224 index: 0,
225 },
226 {
227 type: 'tool_call',
228 id: 'msg-1',
229 model: 'test',
230 timestamp: Date.now(),
231 toolCall: {
232 id: 'call_1',
233 type: 'function',
234 function: { name: 'getWeather', arguments: 'cation":' },
235 },
236 index: 0,
237 },
238 {
239 type: 'tool_call',
240 id: 'msg-1',
241 model: 'test',
242 timestamp: Date.now(),
243 toolCall: {
244 id: 'call_1',
245 type: 'function',
246 function: { name: 'getWeather', arguments: ' "Paris"}' },
247 },
248 index: 0,
249 },
250 {
251 type: 'done',
252 id: 'msg-1',
253 model: 'test',
254 timestamp: Date.now(),
255 finishReason: 'tool_calls',
256 },
257])
258
259/**
260 * Multiple parallel tool calls
261 */
262export const toolCallParallel = createRecording([
263 {
264 type: 'tool_call',
265 id: 'msg-1',
266 model: 'test',
267 timestamp: Date.now(),
268 toolCall: {
269 id: 'call_1',
270 type: 'function',
271 function: { name: 'getWeather', arguments: '{"lo' },
272 },
273 index: 0,
274 },
275 {
276 type: 'tool_call',
277 id: 'msg-1',
278 model: 'test',
279 timestamp: Date.now(),
280 toolCall: {
281 id: 'call_2',
282 type: 'function',
283 function: { name: 'getTime', arguments: '{"ci' },
284 },
285 index: 1,
286 },
287 {
288 type: 'tool_call',
289 id: 'msg-1',
290 model: 'test',
291 timestamp: Date.now(),
292 toolCall: {
293 id: 'call_1',
294 type: 'function',
295 function: { name: 'getWeather', arguments: 'cation":"Paris"}' },
296 },
297 index: 0,
298 },
299 {
300 type: 'tool_call',
301 id: 'msg-1',
302 model: 'test',
303 timestamp: Date.now(),
304 toolCall: {
305 id: 'call_2',
306 type: 'function',
307 function: { name: 'getTime', arguments: 'ty":"Tokyo"}' },
308 },
309 index: 1,
310 },
311 {
312 type: 'done',
313 id: 'msg-1',
314 model: 'test',
315 timestamp: Date.now(),
316 finishReason: 'tool_calls',
317 },
318])
319
320/**
321 * Tool call followed by text (tool result response)
322 */
323export const toolCallWithText = createRecording([
324 {
325 type: 'tool_call',
326 id: 'msg-1',
327 model: 'test',
328 timestamp: Date.now(),
329 toolCall: {
330 id: 'call_1',
331 type: 'function',
332 function: { name: 'getWeather', arguments: '{"location":"Paris"}' },
333 },
334 index: 0,
335 },
336 {
337 type: 'content',
338 id: 'msg-1',
339 model: 'test',
340 timestamp: Date.now(),
341 delta: 'The weather in Paris is',
342 content: 'The weather in Paris is',
343 role: 'assistant',
344 },
345 {
346 type: 'content',
347 id: 'msg-1',
348 model: 'test',
349 timestamp: Date.now(),
350 delta: ' sunny',
351 content: 'The weather in Paris is sunny',
352 role: 'assistant',
353 },
354 {
355 type: 'content',
356 id: 'msg-1',
357 model: 'test',
358 timestamp: Date.now(),
359 delta: ' and warm.',
360 content: 'The weather in Paris is sunny and warm.',
361 role: 'assistant',
362 },
363 {
364 type: 'done',
365 id: 'msg-1',
366 model: 'test',
367 timestamp: Date.now(),
368 finishReason: 'stop',
369 },
370])
371
372/**
373 * Tool result chunk
374 */
375export const toolResult = createRecording([
376 {
377 type: 'tool_call',
378 id: 'msg-1',
379 model: 'test',
380 timestamp: Date.now(),
381 toolCall: {
382 id: 'call_1',
383 type: 'function',
384 function: { name: 'calculate', arguments: '{"expression":"2+2"}' },
385 },
386 index: 0,
387 },
388 {
389 type: 'done',
390 id: 'msg-1',
391 model: 'test',
392 timestamp: Date.now(),
393 finishReason: 'tool_calls',
394 },
395 {
396 type: 'tool_result',
397 id: 'msg-2',
398 model: 'test',
399 timestamp: Date.now(),
400 toolCallId: 'call_1',
401 content: '4',
402 },
403 {
404 type: 'content',
405 id: 'msg-2',
406 model: 'test',
407 timestamp: Date.now(),
408 delta: 'The result is 4.',
409 content: 'The result is 4.',
410 role: 'assistant',
411 },
412 {
413 type: 'done',
414 id: 'msg-2',
415 model: 'test',
416 timestamp: Date.now(),
417 finishReason: 'stop',
418 },
419])
420
421/**
422 * Thinking/reasoning chunks (Claude-style)
423 */
424export const thinking = createRecording([
425 {
426 type: 'thinking',
427 id: 'msg-1',
428 model: 'test',
429 timestamp: Date.now(),
430 delta: 'Let me think about this...',
431 content: 'Let me think about this...',
432 },
433 {
434 type: 'thinking',
435 id: 'msg-1',
436 model: 'test',
437 timestamp: Date.now(),
438 delta: ' I need to consider the weather patterns.',
439 content:
440 'Let me think about this... I need to consider the weather patterns.',
441 },
442 {
443 type: 'content',
444 id: 'msg-1',
445 model: 'test',
446 timestamp: Date.now(),
447 delta: 'Based on my analysis, ',
448 content: 'Based on my analysis, ',
449 role: 'assistant',
450 },
451 {
452 type: 'content',
453 id: 'msg-1',
454 model: 'test',
455 timestamp: Date.now(),
456 delta: 'it looks like rain.',
457 content: 'Based on my analysis, it looks like rain.',
458 role: 'assistant',
459 },
460 {
461 type: 'done',
462 id: 'msg-1',
463 model: 'test',
464 timestamp: Date.now(),
465 finishReason: 'stop',
466 },
467])
468
469/**
470 * Approval requested flow
471 */
472export const approvalRequested = createRecording([
473 {
474 type: 'tool_call',
475 id: 'msg-1',
476 model: 'test',
477 timestamp: Date.now(),
478 toolCall: {
479 id: 'call_1',
480 type: 'function',
481 function: { name: 'deleteFile', arguments: '{"path":"/tmp/test.txt"}' },
482 },
483 index: 0,
484 },
485 {
486 type: 'done',
487 id: 'msg-1',
488 model: 'test',
489 timestamp: Date.now(),
490 finishReason: 'tool_calls',
491 },
492 {
493 type: 'approval-requested',
494 id: 'msg-1',
495 model: 'test',
496 timestamp: Date.now(),
497 toolCallId: 'call_1',
498 toolName: 'deleteFile',
499 input: { path: '/tmp/test.txt' },
500 approval: { id: 'approval_call_1', needsApproval: true },
501 },
502])
503
504/**
505 * Client tool input available
506 */
507export const toolInputAvailable = createRecording([
508 {
509 type: 'tool_call',
510 id: 'msg-1',
511 model: 'test',
512 timestamp: Date.now(),
513 toolCall: {
514 id: 'call_1',
515 type: 'function',
516 function: { name: 'getUserLocation', arguments: '{}' },
517 },
518 index: 0,
519 },
520 {
521 type: 'done',
522 id: 'msg-1',
523 model: 'test',
524 timestamp: Date.now(),
525 finishReason: 'tool_calls',
526 },
527 {
528 type: 'tool-input-available',
529 id: 'msg-1',
530 model: 'test',
531 timestamp: Date.now(),
532 toolCallId: 'call_1',
533 toolName: 'getUserLocation',
534 input: {},
535 },
536])
537
538/**
539 * Error chunk
540 */
541export const error = createRecording([
542 {
543 type: 'content',
544 id: 'msg-1',
545 model: 'test',
546 timestamp: Date.now(),
547 delta: 'Starting...',
548 content: 'Starting...',
549 role: 'assistant',
550 },
551 {
552 type: 'error',
553 id: 'msg-1',
554 model: 'test',
555 timestamp: Date.now(),
556 error: { message: 'Rate limit exceeded', code: 'rate_limit' },
557 },
558])
559
560/**
561 * Delta-only chunks (no accumulated content)
562 */
563export const deltaOnly = createRecording([
564 {
565 type: 'content',
566 id: 'msg-1',
567 model: 'test',
568 timestamp: Date.now(),
569 delta: 'Hello',
570 },
571 {
572 type: 'content',
573 id: 'msg-1',
574 model: 'test',
575 timestamp: Date.now(),
576 delta: ' world',
577 },
578 {
579 type: 'content',
580 id: 'msg-1',
581 model: 'test',
582 timestamp: Date.now(),
583 delta: '!',
584 },
585 {
586 type: 'done',
587 id: 'msg-1',
588 model: 'test',
589 timestamp: Date.now(),
590 finishReason: 'stop',
591 },
592])