/** * Gateway WebSocket Client * Provides a typed interface for Gateway RPC calls */ import { GatewayManager, GatewayStatus } from './manager'; /** * Channel types supported by OpenClaw */ export type ChannelType = 'whatsapp' | 'telegram' | 'discord' | 'wechat'; /** * Channel status */ export interface Channel { id: string; type: ChannelType; name: string; status: 'connected' | 'disconnected' | 'connecting' | 'error'; lastActivity?: string; error?: string; config?: Record; } /** * Skill definition */ export interface Skill { id: string; name: string; description: string; enabled: boolean; category?: string; icon?: string; configurable?: boolean; version?: string; author?: string; } /** * Skill bundle definition */ export interface SkillBundle { id: string; name: string; description: string; skills: string[]; icon?: string; recommended?: boolean; } /** * Chat message */ export interface ChatMessage { id: string; role: 'user' | 'assistant' | 'system'; content: string; timestamp: string; channel?: string; toolCalls?: ToolCall[]; metadata?: Record; } /** * Tool call in a message */ export interface ToolCall { id: string; name: string; arguments: Record; result?: unknown; status: 'pending' | 'running' | 'completed' | 'error'; duration?: number; } /** * Cron task definition */ export interface CronTask { id: string; name: string; schedule: string; command: string; enabled: boolean; lastRun?: string; nextRun?: string; status: 'idle' | 'running' | 'error'; error?: string; } /** * Provider configuration */ export interface ProviderConfig { id: string; name: string; type: 'openai' | 'anthropic' | 'ollama' | 'custom'; apiKey?: string; baseUrl?: string; model?: string; enabled: boolean; } /** * Gateway Client * Typed wrapper around GatewayManager for making RPC calls */ export class GatewayClient { constructor(private manager: GatewayManager) { } /** * Get current gateway status */ getStatus(): GatewayStatus { return this.manager.getStatus(); } /** * Check if gateway is connected */ isConnected(): boolean { return this.manager.isConnected(); } // ==================== 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'); } // ==================== Cron Methods ==================== /** * List all cron tasks */ async listCronTasks(): Promise { return this.manager.rpc('cron.list'); } /** * Create a new cron task */ async createCronTask(task: Omit): Promise { return this.manager.rpc('cron.create', task); } /** * Update a cron task */ async updateCronTask(taskId: string, updates: Partial): Promise { return this.manager.rpc('cron.update', { taskId, ...updates }); } /** * Delete a cron task */ async deleteCronTask(taskId: string): Promise { return this.manager.rpc('cron.delete', { taskId }); } /** * Run a cron task immediately */ async runCronTask(taskId: string): Promise { return this.manager.rpc('cron.run', { taskId }); } // ==================== Provider Methods ==================== /** * List configured AI providers */ async listProviders(): Promise { return this.manager.rpc('providers.list'); } /** * Add or update a provider */ async setProvider(provider: ProviderConfig): Promise { return this.manager.rpc('providers.set', provider); } /** * Remove a provider */ async removeProvider(providerId: string): Promise { return this.manager.rpc('providers.remove', { providerId }); } /** * Test provider connection */ async testProvider(providerId: string): Promise<{ success: boolean; error?: string }> { return this.manager.rpc<{ success: boolean; error?: string }>('providers.test', { providerId }); } // ==================== System Methods ==================== /** * Get Gateway health status */ async getHealth(): Promise<{ status: string; uptime: number; version?: string }> { return this.manager.rpc<{ status: string; uptime: number; version?: string }>('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); } /** * Get Gateway version info */ async getVersion(): Promise<{ version: string; nodeVersion?: string; platform?: string }> { return this.manager.rpc<{ version: string; nodeVersion?: string; platform?: string }>('system.version'); } /** * Get available skill bundles */ async getSkillBundles(): Promise { return this.manager.rpc('skills.bundles'); } /** * Install a skill bundle */ async installBundle(bundleId: string): Promise { return this.manager.rpc('skills.installBundle', { bundleId }); } }