* Collapses a ProviderRequest into a single input string and optional system instruction * for the Interactions API, which takes a flat input rather than a messages array. * * Deep research is single-turn only — it takes one research query and returns a report. * Memory/conversation history is h
(request: ProviderRequest)
| 435 | * the last user message is used as input. System messages are passed via system_instruction. |
| 436 | */ |
| 437 | function collapseMessagesToInput(request: ProviderRequest): { |
| 438 | input: string |
| 439 | systemInstruction: string | undefined |
| 440 | } { |
| 441 | const systemParts: string[] = [] |
| 442 | const userParts: string[] = [] |
| 443 | |
| 444 | if (request.systemPrompt) { |
| 445 | systemParts.push(request.systemPrompt) |
| 446 | } |
| 447 | |
| 448 | if (request.messages) { |
| 449 | for (const msg of request.messages) { |
| 450 | if (msg.role === 'system' && msg.content) { |
| 451 | systemParts.push(msg.content) |
| 452 | } else if (msg.role === 'user' && msg.content) { |
| 453 | userParts.push(msg.content) |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | return { |
| 459 | input: |
| 460 | userParts.length > 0 |
| 461 | ? userParts[userParts.length - 1] |
| 462 | : 'Please conduct research on the provided topic.', |
| 463 | systemInstruction: systemParts.length > 0 ? systemParts.join('\n\n') : undefined, |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * Extracts text content from a completed interaction's outputs array. |
no test coverage detected