Typed engine event stream: the openseek run/serve stdout wire contract.
Dependencies
| Package | Contents | Targets | Deps |
|---|---|---|---|
| bobzhang/openseek_protocol | Event, Usage, Command, SteerKind, to_json, parse | js, wasm, wasm-gc, native | core/json |
| bobzhang/openseek_protocol/emit | emit (to_json + stdout writer) | native | async, above |
{"event":"assistant_delta","content":"Hel"}// Report an event. The line is `to_json`, nothing more.
@emit.emit(AssistantDelta(content="Hel"))
@emit.emit(AgentAborted(reason="interrupted"))
// Or build the line without logging it — what the desktop host forwards for a
// compaction whose engine died before reporting one itself.
let line = CompactionFailed(error="engine exited").to_json()
// Read one back. `None` means "not an event this engine emits" — an unknown
// name or a malformed payload — so a client stays tolerant of a newer engine.
match @protocol.parse(line) {
Some(AssistantDelta(content~)) => render(content)
Some(_) | None => ()
}// A controller writes a line.
let line = (Prompt(text="do it") : @protocol.Command).to_jsonl()
// The engine reads one back. `Err` is a line it cannot read — and only that:
// whether a readable command is *acceptable* is the engine's to say, which is
// why `serve`, not `parse`, refuses a blank goal.
match @protocol.Command::parse(line) {
Ok(Prompt(text~)) => start_turn(text)
Ok(_) => ()
Err(message) => report(message)
}pub(all) enum Command {
Prompt(text~ : String, submission_id~ : String?)
Steer(kind~ : SteerKind, text~ : String)
Compact
Cancel
JobsSnapshot(request_id~ : String)
JobStop(request_id~ : String, generation~ : String, job_id~ : String)
GoalSet(text~ : String, auto~ : Bool)
GoalClear
ApprovalDecision(id~ : String, allow~ : Bool)
} derive(Eq, Debug)pub(all) enum Event {
AgentSetupFailed(error~ : String)
AgentStep(step~ : Int)
StreamRetry(attempt~ : Int, max_attempts~ : Int, reason~ : String)
AgentAborted(reason~ : String)
AgentFinished(answer~ : String)
MaxStepsExhausted
TurnFailed(error~ : String)
AssistantDelta(content~ : String)
ReasoningDelta(content~ : String)
AssistantMessage(content~ : String)
ReasoningMessage(content~ : String)
Usage(usage~ : Usage)
ToolResult(tool_call_id~ : String, tool_name~ : String, is_error~ : Bool, content~ : String, brief~ : String?)
ToolCallDecodeError(tool_call_id~ : String, tool_name~ : String, error~ : String)
ApprovalRequested(id~ : String, tool_name~ : String, detail~ : String, body~ : String?)
ApprovalResolved(id~ : String, outcome~ : String)
SteerApplied(kind~ : String, content~ : String)
SteerDropped(content~ : String)
BackgroundNotice(content~ : String)
JobChanged(kind~ : JobEventKind, job~ : JobRecord)
JobsSnapshot(request_id~ : String, jobs~ : Array[JobRecord])
JobStopResult(request_id~ : String, generation~ : String, job_id~ : String, outcome~ : JobStopOutcome)
GoalUpdated(goal~ : String?)
GoalBlocked(reason~ : String)
GoalUnblocked
GoalCheck(content~ : String)
GoalReminder(content~ : String)
GoalContinue(remaining~ : Int)
GoalBudgetExhausted(turns~ : Int)
PlanReminder(content~ : String)
CompactionStarted(from_sequence~ : Int, to_sequence~ : Int)
CompactionFinished(from_sequence~ : Int, to_sequence~ : Int, summary~ : String)
CompactionFailed(error~ : String)
AutoCompactionStarted(from_sequence~ : Int, to_sequence~ : Int)
AutoCompactionFinished(from_sequence~ : Int, to_sequence~ : Int, summary~ : String)
AutoCompactionFailed(error~ : String)
ContextYield(to_sequence~ : Int, answer~ : String)
SubrunStarted(id~ : String, kind~ : String, label~ : String)
SubrunFinished(id~ : String, status~ : String, steps~ : Int, prompt_tokens~ : Int, completion_tokens~ : Int)
WorkflowStarted(id~ : String, journal~ : String, events~ : String, first_child~ : Int, child_count~ : Int)
WorkflowFinished(id~ : String)
SessionStarted(session~ : String, session_root~ : String, workspace_root~ : String?)
SessionError(error~ : String)
WorkspaceCreated(dir~ : String)
CommandError(error~ : String)
FleetStarted(runs~ : Int, task~ : String)
McpConfigIgnored(reason~ : String)
McpConfigUnreadable(path~ : String, error~ : String)
McpConfigInvalid(path~ : String, error~ : String)
McpToolsRegistered(servers~ : Int, tools~ : Int, names~ : Array[String])
McpToolDuplicate(server~ : String, tool~ : String)
McpToolRenamed(from~ : String, to~ : String)
McpToolsCapped(server~ : String, kept~ : Int)
McpServerSkippedOverCap(server~ : String)
McpConnectFailed(server~ : String, error~ : String)
McpListToolsFailed(server~ : String, error~ : String)
McpListToolsTimeout(server~ : String)
McpNoTools(server~ : String)
} derive(Eq, Debug)pub(all) struct JobRecord {
generation : String
id : String
revision : Int
command : String
description : String?
cwd : String?
state : JobState
started_at_ms : Int64
backgrounded_at_ms : Int64
finished_at_ms : Int64?
last_output_at_ms : Int64?
output_file : String?
output_persistent : Bool
output_bytes : Int64
output_chars : Int
output_truncated : Bool
invalid_utf8 : Bool
output_error : String?
persistence_error : String?
cleanup_error : String?
} derive(Eq, Debug)impl ToJson for JobStopOutcomeimpl FromJson for JobStopOutcomefn job_id_from_storage(name : String) -> Stringfn job_storage_name(id : String) -> Stringfn split_child_session_id(id : String) -> (String, Int)?fn valid_job_component(value : String) -> BoolInstall
Download zipTyped engine event stream: the openseek run/serve stdout wire contract.
Dependencies