( thinkingContent: string, textContent: string = '', messageId: string = 'msg-1', model: string = 'test', )
| 350 | * Helper to create thinking chunks (AG-UI format using STEP_FINISHED for thinking) |
| 351 | */ |
| 352 | export function createThinkingChunks( |
| 353 | thinkingContent: string, |
| 354 | textContent: string = '', |
| 355 | messageId: string = 'msg-1', |
| 356 | model: string = 'test', |
| 357 | ): Array<StreamChunk> { |
| 358 | const chunks: Array<StreamChunk> = [] |
| 359 | let accumulatedThinking = '' |
| 360 | const runId = `run-${messageId}` |
| 361 | const stepId = `step-${messageId}` |
| 362 | |
| 363 | // Add thinking chunks via STEP_FINISHED events |
| 364 | for (const chunk of thinkingContent) { |
| 365 | accumulatedThinking += chunk |
| 366 | chunks.push({ |
| 367 | type: 'STEP_FINISHED', |
| 368 | stepName: stepId, |
| 369 | stepId, |
| 370 | model, |
| 371 | timestamp: Date.now(), |
| 372 | delta: chunk, |
| 373 | content: accumulatedThinking, |
| 374 | } as StreamChunk) |
| 375 | } |
| 376 | |
| 377 | // Optionally add text content after thinking |
| 378 | if (textContent) { |
| 379 | let accumulatedText = '' |
| 380 | for (const chunk of textContent) { |
| 381 | accumulatedText += chunk |
| 382 | chunks.push({ |
| 383 | type: 'TEXT_MESSAGE_CONTENT', |
| 384 | messageId, |
| 385 | model, |
| 386 | timestamp: Date.now(), |
| 387 | delta: chunk, |
| 388 | content: accumulatedText, |
| 389 | } as StreamChunk) |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | chunks.push({ |
| 394 | type: 'RUN_FINISHED', |
| 395 | runId, |
| 396 | threadId: `thread-${messageId}`, |
| 397 | model, |
| 398 | timestamp: Date.now(), |
| 399 | finishReason: 'stop', |
| 400 | } as StreamChunk) |
| 401 | |
| 402 | return chunks |
| 403 | } |
no test coverage detected