/** * Wire Protocol type definitions for the WebSocket Relay. * * All frames are JSON text with snake_case field names, discriminated by * the `type` field. Null/undefined fields are omitted on the wire. * * This is the CANONICAL source. bot-app and local-server re-export from here. * * @see docs/refactor-plan-websocket-relay.md — Phase 0 */ /** Current wire protocol version. Client must validate on `connected` handshake. */ export declare const PROTOCOL_VERSION = 1; /** Content format for message payloads. */ export type ContentFormat = 'text' | 'html' | 'markdown'; /** Supported image media types (matches Claude API). */ export type ImageMediaType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp'; /** An image attachment embedded in a MessageFrame. */ export interface ImageAttachment { /** Unique ID for this attachment (uuid). */ id: string; /** MIME type of the image. */ media_type: ImageMediaType; /** Base64-encoded image data. */ data: string; /** Original filename from Teams, if available. */ filename?: string; /** Image size in bytes (before base64 encoding). */ size_bytes?: number; } /** Handshake confirmation sent after WebSocket upgrade + JWT validation. */ export interface ConnectedFrame { readonly type: 'connected'; /** Wire protocol version. Client must disconnect if mismatched. */ protocol_version: number; /** Number of offline-buffered messages about to be replayed. */ buffered_count: number; } /** Marks the start of offline buffer replay. */ export interface BufferedStartFrame { readonly type: 'buffered_start'; /** Number of buffered messages to follow. */ count: number; } /** * A user message forwarded from Teams via the Gateway. * * The Gateway abstracts away Teams-specific fields (activityId, serviceUrl). * Those are stored in the Gateway's ReplyContext, not sent to the client. */ export interface MessageFrame { readonly type: 'message'; /** Source channel identifier. Always `"cloud"` for Gateway-originated messages. */ channel: string; /** Unique ID for this inbound message (`cid_{uuid}`). Used to bind reply routing. */ channel_id: string; /** Sender's Entra Object ID (OID). */ sender_id: string; /** Sender's display name. */ sender_name: string; /** Message body. */ content: string; /** Format of the content field. */ content_format: ContentFormat; /** Conversation/thread identifier. */ thread_id: string; /** * Session key for this user+conversation pair. * Format: `cloud_teams:{oid}:{conversationId}`. */ session_key: string; /** ISO 8601 timestamp of when the message was received by the Gateway. */ timestamp: string; /** Optional key-value metadata (e.g. `{ source: "cloud_teams", tenant_id: "..." }`). */ metadata?: Record; /** Image attachments (base64-encoded). Omitted when message has no images. */ attachments?: ImageAttachment[]; /** Bot Framework activity ID of the original message. Used for Graph API reactions. */ activity_id?: string; /** Teams conversation type: 'personal', 'channel', 'groupChat'. */ conversation_type?: string; } /** Marks the end of offline buffer replay. */ export interface BufferedEndFrame { readonly type: 'buffered_end'; } /** Server heartbeat. Client must reply with a `pong` within 15 seconds. */ export interface PingFrame { readonly type: 'ping'; } /** Error notification from the Gateway. */ export interface ErrorFrame { readonly type: 'error'; /** Machine-readable error code (e.g. `"reply_context_expired"`). */ code: string; /** The channel_id this error relates to, if applicable. */ channel_id?: string; /** Human-readable error description. */ message: string; } /** Reserved: admin/portal data query forwarded to local-server. */ export interface AdminRequestFrame { readonly type: 'admin_request'; /** Unique request ID for correlating the response. */ request_id: string; /** API endpoint path being queried. */ endpoint: string; /** HTTP method (GET, POST, etc.). */ method: string; /** Optional request body as a JSON string. */ body?: string; } /** * User's choice from an interactive ask-user card, forwarded from Teams. * * Sent by the Gateway when the user submits an Adaptive Card created in * response to an earlier `AskChoiceFrame`. Routed to the local-server that * originated the ask (via deviceId binding). */ export interface ChoiceResponseFrame { readonly type: 'choice_response'; /** Correlates to the ask_id from the original AskChoiceFrame. */ ask_id: string; /** Session key the ask was created for (defense-in-depth routing check). */ session_key: string; /** * IDs of the options the user selected. Empty when cancelled. * For single-select asks, contains exactly one ID. For multi-select, * one or more. */ selected_ids: string[]; /** True when the user cancelled (no selection) — e.g. card expired. */ cancelled?: boolean; /** * Reason for cancellation. Only meaningful when `cancelled` is true. * - `expired`: card was clicked but the ask tracker is gone (gateway restart, etc.) * - `user_cancel`: user explicitly dismissed (reserved; not currently surfaced) */ cancel_reason?: 'expired' | 'user_cancel'; } /** Discriminated union of all frames sent from Gateway to local-server. */ export type ServerFrame = ConnectedFrame | BufferedStartFrame | MessageFrame | BufferedEndFrame | PingFrame | ErrorFrame | AdminRequestFrame | ChoiceResponseFrame; /** Heartbeat reply. Must be sent within 15 seconds of receiving a `ping`. */ export interface PongFrame { readonly type: 'pong'; } /** Agent's final reply to a user message. Deletes the associated ReplyContext. */ export interface ResponseFrame { readonly type: 'response'; /** The channel_id from the original MessageFrame this is replying to. */ channel_id: string; /** Reply content. */ content: string; /** Content format. Defaults to `"text"` if omitted. */ format?: ContentFormat; /** Thread ID for threaded replies. */ thread_id?: string; } /** Reserved: intermediate notification (e.g. approval card). Keeps ReplyContext alive. */ export interface NotificationFrame { readonly type: 'notification'; /** The channel_id this notification relates to. */ channel_id: string; /** Notification content. */ content: string; /** Content format. */ format?: ContentFormat; } /** Reserved: streaming token chunk. ReplyContext deleted when `done` is true. */ export interface ChunkFrame { readonly type: 'chunk'; /** The channel_id this chunk belongs to. */ channel_id: string; /** Chunk content (partial token or text). */ content: string; /** Optional chunk type discriminator. */ chunk_type?: string; /** Whether this is the final chunk in the stream. */ done: boolean; } /** Typing indicator. Keeps ReplyContext alive. */ export interface TypingFrame { readonly type: 'typing'; /** The channel_id to show typing in. */ channel_id: string; } /** * Proactive push message (no ReplyContext needed). * * If `session_key` is provided, the Gateway delivers to that specific * conversation. Otherwise, it falls back to the OID's most recently * active conversation. */ export interface PushFrame { readonly type: 'push'; /** Push content. */ content: string; /** Content format. */ format?: ContentFormat; /** Optional title for the push message. */ title?: string; /** * Target session key for directed delivery. * Format: `cloud_teams:{oid}:{conversationId}`. * If omitted, falls back to the sender's most recently active conversation. */ session_key?: string; /** * Target Teams channel conversation ID for channel-directed delivery. * When set, the Gateway sends to this channel as the bot (proactive message). * Format: `19:xxx@thread.tacv2`. */ target_channel_id?: string; /** * OID (AAD Object ID) of a user to @mention in the channel message. * Only effective when `target_channel_id` is set. */ mention_oid?: string; /** Display name for the @mention. */ mention_name?: string; } /** Reserved: response to an admin_request. */ export interface AdminResponseFrame { readonly type: 'admin_response'; /** The request_id from the corresponding AdminRequestFrame. */ request_id: string; /** HTTP status code of the response. */ status: number; /** Optional response body as a JSON string. */ body?: string; } /** A cached Teams conversation reference for sync on reconnect. */ export interface SyncConversationEntry { session_key: string; service_url: string; conversation_id: string; conversation_type: string; tenant_id: string; } /** Bulk-sync cached conversation references from client to gateway on reconnect. */ export interface SyncConversationsFrame { readonly type: 'sync_conversations'; conversations: SyncConversationEntry[]; } /** A single option presented to the user in an ask-user card. */ export interface ChoiceOption { /** Server-assigned stable ID (e.g. "0", "1", ...). Echoed back in ChoiceResponseFrame. */ id: string; /** Display text shown on the choice control. */ title: string; /** Optional secondary descriptive text rendered under the title. */ description?: string; } /** * Render an interactive multiple-choice card in the user's Teams * conversation and await their selection. * * Sent from the local-server to the Gateway when the agent invokes the * `ask_user` MCP tool. The Gateway resolves the bound device for the * session and posts an Adaptive Card to the corresponding Teams thread. * The user's selection arrives back as a `ChoiceResponseFrame`. */ export interface AskChoiceFrame { readonly type: 'ask_choice'; /** Unique correlation ID for this ask (e.g. `ask_{uuid}`). */ ask_id: string; /** Session key whose conversation should receive the card. */ session_key: string; /** The prompt question shown above the choices. */ question: string; /** Optional longer description rendered between question and choices. */ description?: string; /** The list of options the user can choose from (min 2, max 10). */ options: ChoiceOption[]; /** Whether multiple options can be selected at once. Default false. */ multi_select?: boolean; } /** Discriminated union of all frames sent from local-server to Gateway. */ export type ClientFrame = PongFrame | ResponseFrame | NotificationFrame | ChunkFrame | TypingFrame | PushFrame | AdminResponseFrame | SyncConversationsFrame | AskChoiceFrame; /** All valid server frame type strings. */ export type ServerFrameType = ServerFrame['type']; /** All valid client frame type strings. */ export type ClientFrameType = ClientFrame['type']; /** * All valid server frame type strings (canonical, for runtime validation). * Update this array when adding new ServerFrame variants. */ export declare const ALL_SERVER_FRAME_TYPES: readonly ["connected", "buffered_start", "message", "buffered_end", "ping", "error", "admin_request", "choice_response"]; /** * All valid client frame type strings (canonical, for runtime validation). * Update this array when adding new ClientFrame variants. */ export declare const ALL_CLIENT_FRAME_TYPES: readonly ["pong", "response", "notification", "chunk", "typing", "push", "admin_response", "sync_conversations", "ask_choice"];