opc uses it for every command that watches a session (opc wait, opc watch, opc -p, the interactive screen).
Open
GET /live on the API (wss://app.opencomputer.dev/api/managed-agents/computer/live), a WebSocket upgrade offering the subprotocol oc.live.v1. Without it, or without an upgrade: 426 upgrade_required.
The connection needs
sessions:read. The server answers with oc.live.v1 only, never the bearer subprotocol.
Every frame is one JSON text message of at most 64 kB. The client’s first frame is hello; the server answers ready:
expiresAt is when the credential expires, when it does. Send {"t":"auth","token":"..."} with a fresh credential of the same person before then; a credential of anyone else closes the socket with 4003. {"t":"ping"} is answered {"t":"pong"}.
Streams
after is a cursor from an events page or an earlier range. subd carries the stream’s head. {"t":"unsub","stream":"..."} stops a stream. A connection watches at most 32 sessions; past that, error with too_many_subscriptions. Watching a session never resumes it.
Following a session
Hold one cursor per session and compare it for equality only; never read inside it.- Read events over HTTP until
hasMoreis false, keeping the page’scursor. subtoevents:<id>with that cursor asafter, and todeltas:<id>if you show text as it is written.- Apply each
eventsframe whosefromis your cursor, then hold itsto. One whosetois your cursor is a repeat: ignore it. - On anything else (a
subdorbehindwhoseheadis not your cursor, or aneventsframe that does not start at it), read over HTTP from your cursor, then go on.
behind is sent when a range is too large for one frame: the events are read over HTTP.
Deltas
offset is where data’s text starts in its block. When it is not the length you hold, send {"t":"block","session":"cs_...","blockId":"..."}: the answer is a delta with whole: true whose text replaces the block. Each block’s completed event (message.completed, reasoning.completed, tool.completed) carries the whole text, so a client may ignore deltas. Delta types: API schema.
Close codes
Reconnect with backoff,
hello, and sub again with each session’s cursor: nothing is lost, because Live holds nothing a client cannot read over HTTP.