/** * Gateway types - Core type definitions for the OpenClaw Gateway */ import type { ChannelConfig } from "../channels/base.js"; /** Gateway server configuration */ export interface GatewayConfig { /** HTTP server port (default: 18789) */ port: number; /** WebSocket path (default: /ws) */ wsPath: string; /** Static files directory */ publicDir: string; /** Session storage directory */ sessionDir: string; /** Enable debug logging */ debug: boolean; /** CORS origins */ corsOrigins: string[]; } /** Gateway server interface */ export interface GatewayServer { /** Start the gateway server */ start(): Promise; /** Stop the gateway server */ stop(): Promise; /** Get current server status */ getStatus(): ServerStatus; } /** Server status */ export interface ServerStatus { running: boolean; port: number; startTime?: Date; connections: number; sessions: number; } /** WebSocket connection wrapper */ export interface WebSocketConnection { /** Connection ID */ id: string; /** Connection type (client, node, channel) */ type: ConnectionType; /** Connected agent ID (if applicable) */ agentId?: string; /** Session key (if applicable) */ sessionKey?: string; /** Send message to this connection */ send(data: unknown): void; /** Close the connection */ close(): void; /** Check if connection is alive */ isAlive: boolean; /** Last activity timestamp */ lastActivity: Date; } /** Connection types */ export type ConnectionType = "client" | "node" | "channel" | "dashboard"; /** Session key format: agent:{agentId}:{channel}:{scope}:{identifier} */ export type SessionKey = string; /** Session data */ export interface Session { /** Session key */ key: SessionKey; /** Session ID (UUID) */ id: string; /** Agent ID */ agentId: string; /** Channel type */ channel: string; /** Scope (dm, group, thread) */ scope: ChannelScope; /** Identifier (user ID, group ID, etc.) */ identifier: string; /** Creation timestamp */ createdAt: Date; /** Last activity timestamp */ lastActivity: Date; /** Message count */ messageCount: number; /** Token count */ tokenCount: number; /** Session state */ state: SessionState; /** Transcript file path */ transcriptPath: string; } /** Session states */ export type SessionState = "idle" | "active" | "paused" | "error"; /** Channel scopes */ export type ChannelScope = "dm" | "group" | "thread" | "channel"; /** Inbound message from a channel */ export interface InboundMessage { /** Message ID */ id: string; /** Session key */ sessionKey: SessionKey; /** Agent ID */ agentId: string; /** Channel type */ channel: string; /** Sender information */ sender: SenderInfo; /** Message content */ content: MessageContent; /** Timestamp */ timestamp: Date; /** Reply to message ID (for threads) */ replyTo?: string; /** Thread ID */ threadId?: string; } /** Sender information */ export interface SenderInfo { /** User ID */ id: string; /** Display name */ name: string; /** Username/handle */ username?: string; /** Avatar URL */ avatar?: string; /** Is admin/owner */ isAdmin?: boolean; /** Guild/Server ID (Discord) */ guildId?: string; /** Team ID (Slack) */ teamId?: string; /** Account ID (for multi-account channels) */ accountId?: string; } /** Message content types */ export type MessageContent = TextContent | ImageContent | FileContent | CommandContent; /** Text content */ export interface TextContent { type: "text"; text: string; } /** Image content */ export interface ImageContent { type: "image"; url: string; mimeType?: string; caption?: string; } /** File content */ export interface FileContent { type: "file"; url: string; name: string; mimeType?: string; size?: number; } /** Command content (e.g., /reset, /new) */ export interface CommandContent { type: "command"; command: string; args: string[]; } /** Outbound message to a channel */ export interface OutboundMessage { /** Message ID */ id: string; /** Session key */ sessionKey: SessionKey; /** Target channel */ channel: string; /** Target identifier */ target: string; /** Message content parts */ parts: OutboundPart[]; /** Reply to message ID */ replyTo?: string; /** Thread ID */ threadId?: string; /** Metadata */ metadata?: Record; } /** Outbound message part */ export type OutboundPart = { type: "text"; text: string; } | { type: "image"; url: string; caption?: string; } | { type: "file"; url: string; name: string; } | { type: "typing"; } | { type: "reaction"; emoji: string; messageId: string; } | { type: "card"; title: string; content: string; actions?: CardAction[]; }; /** Card action button */ export interface CardAction { label: string; action: string; data?: unknown; } /** Route resolution result */ export interface RouteResolution { /** Resolved agent ID */ agentId: string; /** Session key */ sessionKey: SessionKey; /** Channel configuration */ channelConfig: ChannelConfig; /** Binding matched */ binding: ChannelBinding; } /** Channel binding configuration */ export interface ChannelBinding { /** Agent ID */ agentId: string; /** Channel type */ channel: string; /** Binding type */ bindType: "peer" | "guild" | "team" | "account" | "channel" | "default"; /** Binding value */ bindValue: string; /** Access control */ access: AccessControlConfig; } /** Access control configuration */ export interface AccessControlConfig { /** DM access policy */ dmPolicy: "pairing" | "allowlist" | "open"; /** Allowlist for DM */ dmAllowlist?: string[]; /** Group access policy */ groupPolicy: "mention" | "allowlist" | "open"; /** Group allowlist */ groupAllowlist?: string[]; } /** Gateway events */ export interface GatewayEventMap { "connection:open": { connectionId: string; type: ConnectionType; }; "connection:close": { connectionId: string; reason: string; }; "message:inbound": InboundMessage; "message:outbound": OutboundMessage; "session:create": Session; "session:update": Session; "session:close": { sessionKey: SessionKey; }; "agent:start": { sessionKey: SessionKey; agentId: string; }; "agent:stop": { sessionKey: SessionKey; agentId: string; }; error: { source: string; error: Error; }; } /** Event listener type */ export type GatewayEventListener = (data: GatewayEventMap[T]) => void; //# sourceMappingURL=index.d.ts.map