Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

README.md

65 lines1.7 KB

1# Stream Processor Test Panel
2​
3A visual testing tool for validating the TanStack AI stream processor.
4​
5## Features
6​
7- **Drop Zone**: Drag & drop JSON trace files to test
8- **Sample Traces**: Pre-loaded examples from unit tests
9- **Step-through Mode**: Process chunks one at a time
10- **Side-by-side View**: See raw chunks and parsed output
11​
12## Usage
13​
14```bash
15# From workspace root
16pnpm install
17cd testing/panel
18pnpm dev
19```
20​
21Then open http://localhost:3010
22​
23## Creating Trace Files
24​
25Trace files are automatically created when you use the chat interface with a `traceId`. The `api.chat` route wraps the adapter with `wrapAdapterForRecording`, which writes a `ChunkRecording` (see `src/lib/recording.ts`) to a file when the stream completes.
26​
27You can also create trace files programmatically by subscribing to `aiEventClient` events with `createEventRecording`, which reconstructs the same `ChunkRecording` (AG-UI `StreamChunk`s) from the devtools event stream:
28​
29```typescript
30import { createEventRecording } from '@/lib/recording'
31​
32// Create a recording instance that listens to aiEventClient events
33const recording = createEventRecording('tmp/my-trace.json', 'my-trace-id')
34​
35// When done, clean up
36recording.stop()
37```
38​
39Either path captures:
40​
41- Stream chunks (content, tool calls, tool results, done, errors, thinking)
42- Final accumulated content
43- Tool calls and their results
44- Finish reason
45​
46## Trace Format
47​
48```json
50 "version": "1.0",
51 "timestamp": 1234567890,
52 "chunks": [
53 {
54 "chunk": { "type": "content", "delta": "Hello", ... },
55 "timestamp": 1234567891,
56 "index": 0
57 }
58 ],
59 "result": {
60 "content": "Hello world",
61 "toolCalls": [],
62 "finishReason": "stop"
63 }
65```