* Extracts text content from a completed interaction's outputs array. * The outputs array can contain text, thought, google_search_result, and other types. * We concatenate all text outputs to get the full research report.
(outputs: Interactions.Interaction['outputs'])
| 470 | * We concatenate all text outputs to get the full research report. |
| 471 | */ |
| 472 | function extractTextFromInteractionOutputs(outputs: Interactions.Interaction['outputs']): string { |
| 473 | if (!outputs || outputs.length === 0) return '' |
| 474 | |
| 475 | const textParts: string[] = [] |
| 476 | for (const output of outputs) { |
| 477 | if (output.type === 'text') { |
| 478 | const text = (output as Interactions.TextContent).text |
| 479 | if (text) textParts.push(text) |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | return textParts.join('\n\n') |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Extracts token usage from an Interaction's Usage object. |
no test coverage detected