Collects the assistant's reply and sends it back to the context as an
AssistantMessage once it's known how much of it people heard.
Place it last, after TTS. Text from rounds that end in tool calls (a spoken preamble such as "let me check", or the tools stage's progress message) joins the final reply.
What was said
The LLM's text arrives long before its audio has played, so the reply's
text alone doesn't say what people heard. The collector keeps a ledger of
the reply as it passes: each TTSText chunk and how many ms of
OutputAudio followed it. Then:
- The reply plays to the end. The message goes upstream when its
audio should have finished (
LLMResponseEndcomes as soon as the audio is made, often seconds earlier), with the full text. Meanwhile anAssistantDraftwith that text goes upstream atLLMResponseEnd, so a reply that starts while it plays knows what's being said. - An interruption cuts it off. The runner flushes the output and
pushes
AudioFlushedwith how many ms never played. What was queued minus that is how far playback got; the ledger turns that into text: whole chunks that played, and the share of the words of the chunk that was playing, in proportion to how much of its audio played. That goes upstream markedinterrupted?: true. If noAudioFlushedcomes within:flush_timeout_ms, it assumes everything queued was heard.
Before any audio, nothing was heard, so an interrupted reply's text is
empty. With voice: false (no TTS) the text is what was said: an
interrupted reply keeps what the LLM wrote before the interruption.
Options: :voice (default true), :flush_timeout_ms (1000),
:playout_margin_ms (100, added to the expected end of playback).
Summary
Functions
The text of chunks ({text, ms}, oldest first) that played_ms of
audio covers: whole chunks, then the share of the next chunk's words that
its played audio covers, rounded down. Chunks with no audio weren't heard.