UiTranscriptReducer

class UiTranscriptReducer(onWarning: (String) -> Unit = {})

Folds an AG-UI event stream into a UiTranscript.

Reads the events rather than the upstream SDK's AgentState, and that is a deliberate substitution rather than a duplication. AgentState is a transcript -- an assistant message with one content string and a separate toolCalls list, and reasoning in a sibling channel keyed by its own message id -- and the relative order of a sentence and the tool call that followed it is not recoverable from it. Ordering is the property this whole model is for, and the event stream is the only place it survives. Everything else this library takes from upstream: the event types are upstream's, and so are the transport, the SSE parser and the event verifier that produce them. See docs/decisions/0001-riding-on-the-upstream-kotlin-sdk.md.

Not thread-safe. Feed it from one coroutine -- foldToTranscript does.

Parameters

onWarning

called for the two failures the specification requires a consumer to survive rather than fail a run on: an ACTIVITY_DELTA naming a message that does not exist, and a well-formed patch that does not apply. Both are repaired by the producer's next snapshot.

Constructors

Link copied to clipboard
constructor(onWarning: (String) -> Unit = {})

Properties

Link copied to clipboard

The transcript as of the last accept or appendUserMessage.

Functions

Link copied to clipboard
fun accept(event: BaseEvent): UiTranscript

Applies one event and returns the transcript it produced.

Link copied to clipboard
fun appendUserMessage(message: UserMessage): UiTranscript

Appends a message the client composed itself, and returns the transcript it produced.