WebChannel v1 Protocol
Protocol types are defined in src/lib/protocol/types.ts; runtime behavior in client is implemented in src/lib/protocol/client.svelte.ts.
Envelope Shape
{
"v": 1,
"type": "event_name",
"session_id": "string",
"agent_id": "optional",
"request_id": "optional",
"payload": {}
}
Client validation requires:
v === 1typein known event set- non-empty
session_id
Event Types
Client -> Runtime
pairing_requestuser_messageapproval_response
Runtime -> Client
pairing_resultassistant_chunkassistant_finaltool_calltool_resultapproval_requesterror
Pairing Flow
- open websocket connection
- send
pairing_request(PIN + optional client pub key) - receive
pairing_resultwithaccess_token - optionally derive E2E shared key and persist auth state
E2E Payload Format
{
"nonce": "base64url",
"ciphertext": "base64url"
}
Crypto path in code:
- X25519 key exchange
- SHA-256 based key derivation
- ChaCha20-Poly1305 payload encryption
Reconnect Policy
Reconnect is attempted only when:
- close was unexpected
- previous state was
pairedorchatting - valid access token exists
Backoff parameters:
- base delay:
1000ms - max delay:
30000ms - jitter:
delay * (0.5 + Math.random() * 0.5)