( filePath: string, traceId?: string, )
| 45 | * // Call recording.stop() when done to unsubscribe |
| 46 | */ |
| 47 | export function createEventRecording( |
| 48 | filePath: string, |
| 49 | traceId?: string, |
| 50 | ): { |
| 51 | stop: () => void |
| 52 | getStreamId: () => string | undefined |
| 53 | } { |
| 54 | // Track active streams and their data |
| 55 | const activeStreams = new Map< |
| 56 | string, |
| 57 | { |
| 58 | streamId: string |
| 59 | requestId: string |
| 60 | model: string |
| 61 | provider: string |
| 62 | chunks: Array<{ |
| 63 | chunk: StreamChunk |
| 64 | timestamp: number |
| 65 | index: number |
| 66 | }> |
| 67 | accumulatedContent: string |
| 68 | toolCalls: Map<string, RecordedToolCall> |
| 69 | finishReason: string | null |
| 70 | traceId?: string |
| 71 | } |
| 72 | >() |
| 73 | |
| 74 | // Track which streamId belongs to this recording (if traceId is provided) |
| 75 | let recordingStreamId: string | undefined |
| 76 | |
| 77 | let chunkIndex = 0 |
| 78 | |
| 79 | // Helper to reconstruct StreamChunk from events |
| 80 | const createContentChunk = ( |
| 81 | content: string, |
| 82 | delta: string | undefined, |
| 83 | model: string, |
| 84 | timestamp: number, |
| 85 | id: string, |
| 86 | ): StreamChunk => ({ |
| 87 | type: 'content', |
| 88 | content, |
| 89 | delta: delta ?? '', |
| 90 | model, |
| 91 | timestamp, |
| 92 | id, |
| 93 | }) |
| 94 | |
| 95 | const createToolCallChunk = ( |
| 96 | toolCallId: string, |
| 97 | toolName: string, |
| 98 | index: number, |
| 99 | arguments_: string, |
| 100 | model: string, |
| 101 | timestamp: number, |
| 102 | id: string, |
| 103 | ): StreamChunk => ({ |
| 104 | type: 'tool_call', |
nothing calls this directly
no test coverage detected