/** * WebSocket Relay client — connects to the Cloud Gateway's /connect endpoint. * * Handles authentication, reconnection with exponential backoff, heartbeat, * inbound message processing (@mention stripping, HTML→Markdown), and a * send queue with overflow protection. * * @see docs/refactor-plan-websocket-relay.md — Phase 3 */ import { type MessageFrame, type AskChoiceFrame, type ChoiceResponseFrame, type ContentFormat } from './types.js'; type MessageHandler = (frame: MessageFrame) => void | Promise; type ChoiceResponseHandler = (frame: ChoiceResponseFrame) => void | Promise; export interface CloudChannelOpts { deviceId: string; deviceName: string; } export declare class CloudChannel { private readonly deviceOpts; private readonly gatewayUrl; private ws; private _connected; private _disconnecting; private _authFailed; private reconnectAttempt; private reconnectTimer; private heartbeatTimer; private readonly queue; private _flushing; private messageHandler; private choiceResponseHandler; private readonly conversationCache; constructor(gatewayUrl: string, deviceOpts: CloudChannelOpts); /** Start the connection loop. Idempotent — does nothing if already connected/connecting. */ connect(): void; /** Gracefully close. Stops reconnecting. */ disconnect(): void; /** Current connection state. */ isConnected(): boolean; /** * Register a handler for inbound MessageFrames. * The frame's content will have @mentions stripped and HTML converted to Markdown. */ onMessage(handler: MessageHandler): void; /** * Register a handler for inbound ChoiceResponseFrames (user clicks on an * ask_user Adaptive Card). Called from the ask infrastructure at startup. */ onChoiceResponse(handler: ChoiceResponseHandler): void; /** Send an ask_user choice card frame to be rendered as an Adaptive Card in Teams. */ sendAskChoice(frame: AskChoiceFrame): void; /** Send a response frame (agent's final reply to a user message). */ sendResponse(channelId: string, content: string, format?: ContentFormat): void; /** Send a typing indicator (best-effort, bypasses queue like pong). */ sendTyping(channelId: string): void; /** Send a proactive push message. */ sendPush(content: string, opts?: { format?: ContentFormat; title?: string; sessionKey?: string; targetChannelId?: string; mentionOid?: string; mentionName?: string; }): void; private readToken; private attemptConnect; private handleDisconnect; private scheduleReconnect; /** Fast reconnect after server restart — short random delay, no backoff. */ private scheduleServerRestartReconnect; /** Start/reset the heartbeat watchdog. Called on connect and on every ping received. */ private resetHeartbeatWatchdog; /** Stop the heartbeat watchdog. */ private clearHeartbeatWatchdog; /** Force-close a stale connection and trigger reconnect. */ private handleStaleConnection; private handleRawMessage; private dispatchFrame; private handleConnected; private handleMessage; private handleChoiceResponse; private syncConversationsToGateway; private sendPongDirect; private enqueue; private flushQueue; } export {};