| 138 | * Helper to create simple text content chunks (AG-UI format) |
| 139 | */ |
| 140 | export function createTextChunks( |
| 141 | text: string, |
| 142 | messageId: string = 'msg-1', |
| 143 | model: string = 'test', |
| 144 | ): Array<StreamChunk> { |
| 145 | const chunks: Array<StreamChunk> = [] |
| 146 | let accumulated = '' |
| 147 | const runId = `run-${messageId}` |
| 148 | const threadId = `thread-${messageId}` |
| 149 | |
| 150 | for (const chunk of text) { |
| 151 | accumulated += chunk |
| 152 | chunks.push({ |
| 153 | type: 'TEXT_MESSAGE_CONTENT', |
| 154 | messageId, |
| 155 | model, |
| 156 | timestamp: Date.now(), |
| 157 | delta: chunk, |
| 158 | content: accumulated, |
| 159 | } as StreamChunk) |
| 160 | } |
| 161 | |
| 162 | chunks.push({ |
| 163 | type: 'RUN_FINISHED', |
| 164 | runId, |
| 165 | threadId, |
| 166 | model, |
| 167 | timestamp: Date.now(), |
| 168 | finishReason: 'stop', |
| 169 | } as StreamChunk) |
| 170 | |
| 171 | return chunks |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Helper to create custom event chunks |