package ws import "time" // 客户端 → 服务端消息 type ClientMessage struct { Type string `json:"type"` // message | voice_input | ping SessionID string `json:"session_id"` Mode string `json:"mode"` // text | voice_msg | voice_assistant Content string `json:"content"` AudioData string `json:"audio_data,omitempty"` // base64 Timestamp int64 `json:"timestamp"` } // 服务端 → 客户端消息 type ServerMessage struct { Type string `json:"type"` // response | segment | audio | error | device_update MessageID string `json:"message_id"` Text string `json:"text,omitempty"` Segments []VoiceSegment `json:"segments,omitempty"` // 断句数组 FullAudioURL string `json:"full_audio_url,omitempty"` ResponseMode string `json:"response_mode"` ToolCalls []ToolCall `json:"tool_calls,omitempty"` Error string `json:"error,omitempty"` Timestamp int64 `json:"timestamp"` } type VoiceSegment struct { Index int `json:"index"` Text string `json:"text"` AudioURL string `json:"audio_url"` DurationMs int `json:"duration_ms"` } type ToolCall struct { Name string `json:"name"` Arguments map[string]interface{} `json:"arguments"` Result interface{} `json:"result,omitempty"` } // WebSocket客户端 type Client struct { Hub *Hub Conn *websocket.Conn // 使用 gorilla/websocket Send chan []byte UserID string SessionID string } // 连接池 type Hub struct { Clients map[*Client]bool Broadcast chan []byte Register chan *Client Unregister chan *Client }