/** * Wire protocol types for tunnel communication between * CLI client and Cloudflare Worker * * Mirrors apps/tunnel-worker/src/protocol.ts (the worker copy also * carries response-capture fields the CLI does not consume). */ export interface TunnelRequest { type: 'request'; requestId: string; method: string; path: string; headers: Record; body: string | null; /** Standby replay: the request arrived while the client was disconnected. */ buffered?: boolean; /** Standby replay: original arrival time (ms epoch). */ receivedAt?: number; /** Standby replay: HTTP status the worker already served for this request. */ servedStatus?: number; /** * The server already answered this request (server-side answering / * dynamic response rules) - the client displays it, never responds. */ answered?: boolean; /** Inbound signature verdict, when the session has verification armed. */ verify?: { status: 'valid' | 'invalid' | 'missing'; provider: string; reason?: string; }; } export interface TunnelResponse { type: 'response'; requestId: string; status: number; headers: Record; body: string | null; } export interface Ping { type: 'ping'; timestamp: number; } export interface Pong { type: 'pong'; timestamp: number; } export interface Connected { type: 'connected'; subdomain: string; publicUrl: string; } export interface ErrorMessage { type: 'error'; message: string; code?: string; } export interface Closing { type: 'closing'; reason: string; } export interface Notice { type: 'notice'; code: 'try_session_state' | 'try_quota_exhausted' | 'standby_state'; requestCount?: number; maxRequests?: number; expiresAt?: string; /** standby_state: requests buffered while disconnected, replayed next. */ buffered?: number; /** standby_state: requests dropped to the buffer cap since the last replay. */ dropped?: number; } export interface VerifySet { type: 'verify'; verify: { provider: string; secret: string; toleranceSec?: number; } | null; } export type TunnelMessage = TunnelRequest | TunnelResponse | Ping | Pong | Connected | ErrorMessage | Closing | Notice | VerifySet; export declare function parseMessage(data: string): TunnelMessage | null; export declare function serializeMessage(msg: TunnelMessage): string;