Skip to content

WebSocket Protocol 🟑 BETA

The chat transport. One socket carries every chat frame; control frames are distinguished by a type field.

Handshake

Item Value Source
Path /ws (bot from the query string) or /ws/{bot} botserver/src/main_module/server/run_axum_server.rs
Reserved segments attendant β€” the console stream lives at /api/attendance/ws, not under /ws botserver/src/core/bot/ws/handler.rs
Unknown bot 404 with {"error": "bot_not_found", "message", "bot_name"} botserver/src/core/bot/ws/handler.rs

Query parameters (WsQuery in botserver/src/core/bot/ws/handler.rs):

Parameter Meaning
access_token suite/cloud token; when valid it determines the identity
bot_name bot name or slug when the path does not carry it
session_id session to resume; a fresh UUID is generated when absent or invalid
user_id guest identity hint β€” never trusted for an authenticated session

message_type values

From botlib/src/message_types.rs:

Value Constant Meaning
0 EXTERNAL message from an external system
1 USER user message β€” the default for an inbound chat frame
2 BOT_RESPONSE bot answer, streamed as chunks
3 CONTINUE keep processing
4 SUGGESTION suggestion button
5 CONTEXT_CHANGE context switch
6 TOOL_EXEC run the tool directly β€” bypasses the LLM
7 SYSTEM system notice
8 SWITCHER_TOGGLE switcher UI toggle
9 UI_ACTION UI action plan (__ui_plan__)

Chat frame (BotResponse)

Every chat message, in both directions, is this JSON object (botlib/src/models/messaging.rs):

Field Type Always present
bot_id String yes
user_id String yes
session_id String yes
channel String yes
content String yes
message_type MessageType yes
stream_token Option<String> no
is_complete bool yes
suggestions Vec<Suggestion> no
switchers Vec<Switcher> no
context_name Option<String> no
context_length usize yes
context_max_length usize yes
reasoning String no

Control frames (client β†’ server)

type Sent by
run_cancel botserver/src/core/bot/ws/session/inbound.rs, botui/ui/suite/chat/chat-turn-state.js, botui/ui/suite/chat/modules/71_run_timeline.js
run_resume botserver/src/core/bot/ws/session/inbound.rs, botui/ui/suite/chat/modules/71_run_timeline_frames.js
run_takeover botserver/src/core/bot/ws/session/inbound.rs, botui/ui/suite/chat/modules/71_run_timeline.js

Frames the server emits

type Emitted from
CUSTOM botserver/src/core/bot/ws/session/takeover.rs, botserver/src/core/bot/ws/stream/turn.rs
connected botserver/src/core/bot/ws/session.rs
gb.steer botserver/src/core/bot/ws/stream/turn.rs
gb.steering_queued botserver/src/core/bot/ws/session/inbound.rs
message_received botserver/src/core/bot/ws/session.rs, botserver/src/core/bot/ws/session/inbound.rs
rate_limited botserver/src/core/bot/ws/session.rs
run_cancelled botserver/src/core/bot/ws/session/inbound.rs
run_resume_done botserver/src/core/bot/ws/session/resume.rs
run_takeover_ack botserver/src/core/bot/ws/session/takeover.rs

CUSTOM is an envelope: the interesting part is data.name.

data.name Meaning
gb.steer steering notice published on the run bus
gb.takeover takeover state change (payload.state, payload.surface)

Delivery rules

Rule Evidence
A turn is acknowledged with message_received; the client clears its retry timer only on that frame botserver/src/core/bot/ws/session/inbound.rs
A message that arrives while a run is active is queued as steering and acknowledged with gb.steering_queued same file
run_cancel cancels the thread and answers run_cancelled same file
run_resume replays only frames after last_seq and finishes with run_resume_done botserver/src/core/bot/ws/session/resume.rs
run_takeover requires the session owner and answers run_takeover_ack (or a denial frame) botserver/src/core/bot/ws/session/takeover.rs

Frame bodies are built with serde_json::json! at each call site, so no single Rust struct describes them; the tables above list the type values the code actually emits. Fields not shown here are not part of a contract.

See also