File
Blob: src/shared/protocol.ts
| 1 | // Terminal WebSocket protocol types โ shared between client and worker. |
| 2 | // |
| 3 | // Wire format: |
| 4 | // Binary frames = terminal I/O (ANSI/VT byte stream) |
| 5 | // Text frames = JSON control / status messages |
| 6 | |
| 7 | // --------------------------------------------------------------------------- |
| 8 | // Client โ Server |
| 9 | // --------------------------------------------------------------------------- |
| 10 | |
| 11 | export interface ResizeMessage { |
| 12 | type: "resize"; |
| 13 | cols: number; |
| 14 | rows: number; |
| 15 | } |
| 16 | |
| 17 | export type ClientControlMessage = ResizeMessage; |
| 18 | |
| 19 | // --------------------------------------------------------------------------- |
| 20 | // Server โ Client |
| 21 | // --------------------------------------------------------------------------- |
| 22 | |
| 23 | export interface ReadyMessage { |
| 24 | type: "ready"; |
| 25 | } |
| 26 | |
| 27 | export interface ExitMessage { |
| 28 | type: "exit"; |
| 29 | code: number; |
| 30 | signal?: string; |
| 31 | } |
| 32 | |
| 33 | export interface ErrorMessage { |
| 34 | type: "error"; |
| 35 | message: string; |
| 36 | } |
| 37 | |
| 38 | export type ServerStatusMessage = ReadyMessage | ExitMessage | ErrorMessage; |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | // Connection state (client-side) |
| 42 | // --------------------------------------------------------------------------- |
| 43 | |
| 44 | export type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting" | "ended" | "error"; |
| 45 | |
| 46 | // --------------------------------------------------------------------------- |
| 47 | // Session management |
| 48 | // --------------------------------------------------------------------------- |
| 49 | |
| 50 | export interface CreateSessionRequest { |
| 51 | id: string; |
| 52 | cwd?: string; |
| 53 | env?: Record<string, string>; |
| 54 | labels?: Record<string, string>; |
| 55 | } |
| 56 | |
| 57 | export interface SessionInfo { |
| 58 | id: string; |
| 59 | cwd: string; |
| 60 | } |
| 61 | |
| 62 | export interface ApiError { |
| 63 | error: string; |
| 64 | code: string; |
| 65 | } |