Skip to main content

rpc

Function rpc 

Source
pub async fn rpc(
    harness: &AgentHarness,
    agent_events: Option<Receiver<AgentEvent>>,
    model_catalog: Vec<Model>,
    ui_dialog: UiDialogMailbox,
) -> i32
Expand description

rpc mode: a headless JSONL command loop (the server-side agent).

Reads one JSON command per line from stdin ({id?, type, ...}), drives the main lane, and writes one JSON object per line to stdout:

  • fine-grained AgentEvents via [agent_event_json] (each carries type),
  • a {"type":"response","id":<id>,"status":"ok"|"error",...} per command.

Commands: prompt (streams the run), abort, get_state, set_model, set_thinking_level, set_active_tools, ping, stop. stop (or stdin EOF) ends the loop. This is the process rpi-server spawns and that rpi --connect talks to. Mirrors TS runRpcMode / modes/rpc.

The extension UiDialog mailbox is bridged over the same channel: the host emits {"type":"ui_dialog_request","requestId","toolCallId","ui"}, and the client answers with {"type":"ui_dialog_response","requestId","answer"} (or "cancelled":true). A prompt runs in its own task so this loop keeps reading — that is what lets abort and dialog answers arrive mid-run.