/** * Gateway WebSocket Client * Provides a typed interface for Gateway RPC calls */ import { GatewayManager } from './manager'; /** * Channel types supported by OpenClaw */ export type ChannelType = 'whatsapp' | 'telegram' | 'discord' | 'slack' | 'wechat'; /** * Channel status */ export interface Channel { id: string; type: ChannelType; name: string; status: 'connected' | 'disconnected' | 'connecting' | 'error'; lastActivity?: string; error?: string; } /** * Skill definition */ export interface Skill { id: string; name: string; description: string; enabled: boolean; category?: string; icon?: string; configurable?: boolean; } /** * Chat message */ export interface ChatMessage { id: string; role: 'user' | 'assistant' | 'system'; content: string; timestamp: string; channel?: string; toolCalls?: ToolCall[]; } /** * Tool call in a message */ export interface ToolCall { id: string; name: string; arguments: Record; result?: unknown; status: 'pending' | 'running' | 'completed' | 'error'; } /** * Gateway Client * Typed wrapper around GatewayManager for making RPC calls */ export class GatewayClient { constructor(private manager: GatewayManager) {} // ==================== Channel Methods ==================== /** * List all channels */ async listChannels(): Promise { return this.manager.rpc('channels.list'); } /** * Get channel by ID */ async getChannel(channelId: string): Promise { return this.manager.rpc('channels.get', { channelId }); } /** * Connect a channel */ async connectChannel(channelId: string): Promise { return this.manager.rpc('channels.connect', { channelId }); } /** * Disconnect a channel */ async disconnectChannel(channelId: string): Promise { return this.manager.rpc('channels.disconnect', { channelId }); } /** * Get QR code for channel connection (e.g., WhatsApp) */ async getChannelQRCode(channelType: ChannelType): Promise { return this.manager.rpc('channels.getQRCode', { channelType }); } // ==================== Skill Methods ==================== /** * List all skills */ async listSkills(): Promise { return this.manager.rpc('skills.list'); } /** * Enable a skill */ async enableSkill(skillId: string): Promise { return this.manager.rpc('skills.enable', { skillId }); } /** * Disable a skill */ async disableSkill(skillId: string): Promise { return this.manager.rpc('skills.disable', { skillId }); } /** * Get skill configuration */ async getSkillConfig(skillId: string): Promise> { return this.manager.rpc>('skills.getConfig', { skillId }); } /** * Update skill configuration */ async updateSkillConfig(skillId: string, config: Record): Promise { return this.manager.rpc('skills.updateConfig', { skillId, config }); } // ==================== Chat Methods ==================== /** * Send a chat message */ async sendMessage(content: string, channelId?: string): Promise { return this.manager.rpc('chat.send', { content, channelId }); } /** * Get chat history */ async getChatHistory(limit = 50, offset = 0): Promise { return this.manager.rpc('chat.history', { limit, offset }); } /** * Clear chat history */ async clearChatHistory(): Promise { return this.manager.rpc('chat.clear'); } // ==================== System Methods ==================== /** * Get Gateway health status */ async getHealth(): Promise<{ status: string; uptime: number }> { return this.manager.rpc<{ status: string; uptime: number }>('system.health'); } /** * Get Gateway configuration */ async getConfig(): Promise> { return this.manager.rpc>('system.config'); } /** * Update Gateway configuration */ async updateConfig(config: Record): Promise { return this.manager.rpc('system.updateConfig', config); } }