Function: deriveAPIMessages()
deriveAPIMessages(
segments):ChatMessage[]
Defined in: core/dist/types/segments/derivation.d.ts:25
Derive ChatMessage[] from StreamSegment[] for API calls.
This converts the segment-based representation into the message format expected by OpenAI/Anthropic APIs:
- UserSegments become { role: 'user', content } messages
- Groups text segments into assistant message content
- Converts ToolCallSegments to tool_calls array
- Splits tool results into separate 'tool' role messages
When segments contain UserSegments, they act as turn boundaries — assistant content is flushed before each user message.
Parameters
segments
Array of StreamSegment (may include UserSegments)
Returns
Array of ChatMessage for API calls