Events
Consume the shared Agentdock event contract and reduce it into UI state.
runtime.stream(run) returns an async iterable of JSON-safe AgentEvent
objects. pipe() encodes those events as SSE and toResponse() exposes them
in a Web Response. Import event types and reducer utilities from
@agentdock-ai/contracts.
import {
createAgentReducerState,
reduceAgentEvent,
} from "@agentdock-ai/contracts";
let state = createAgentReducerState();
for await (const event of runtime.stream(run)) {
state = reduceAgentEvent(state, event);
render(state);
}The contract covers run lifecycle, messages and content deltas, tool calls,
progress and results, interrupts, usage, errors, and cancellation. Event names
use dots: for example, run.started, message.part.delta, tool.completed,
interrupt.required, and run.completed. Arbitrary graph output remains
application-specific.
Each invocation has a fresh runId and sequence starting at 1. Treat native
message and tool identifiers as opaque correlation values. Apply resumed
invocation events to the existing reducer state, or hydrate pending native
control state using runtime.getResumeState(threadId), whose seed has
runId: null. Load history separately with runtime.getMessages(threadId).
Agentdock does not write event bookkeeping to graph checkpoints. No state schema extension is required. The application owns rendering and persistence of reduced state. Agentdock UI provides a React store and editable chat components for consumers of this same contract.

