Companion

Properties

Link copied to clipboard
const val METADATA_KEY: String

Message.metadata key holding {threadId, runIds}: the runs that produced the reply.

Functions

Link copied to clipboard
fun compact(events: List<JsonObject>): List<JsonObject>

The events compacted as AG-UI's reference client does (compactEvents in @ag-ui/client, AG-UI serialization §Compaction): each text message's and tool call's deltas become one …_CONTENT / TOOL_CALL_ARGS event, events that arrived mid-stream follow the stream they interrupted, and each run's state events become one STATE_SNAPSHOT from the last snapshot on (deltas with no snapshot before them stay as they are). Collapsed events keep the metadata of what they replace (merged key by key) and the time of the last one. Like the reference, it reorders (a run's state moves to its end, mid-stream events after their stream), so it suits archiving finished runs; keep the log as recorded for event-level replay.

Link copied to clipboard
fun eventsOf(events: List<JsonObject>, runIds: Collection<String>): List<JsonObject>

The events of runIds in events, in log order.

Link copied to clipboard
fun replay(events: List<JsonObject>, speed: Float = 1.0f, maxGapMs: Long): Flow<ChatEvent>

Plays events (one reply's runs, see eventsOf) back through the AG-UI event parser, pausing between events as long as the run did (speed 2 is twice as fast; gaps are capped at maxGapMs so waiting for a model does not stall the replay).

Link copied to clipboard
fun runsOf(message: Message): Pair<String, List<String>>?

The thread and runs message came from, when an AgUiBackend with a log produced it.