package ws // 客户端 → 服务端消息 type ClientMessage struct { Type string `json:"type"` // message | voice_input | ping | history 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 | pong | history_response | stream_chunk | stream_end MessageID string `json:"message_id"` Text string `json:"text,omitempty"` Content string `json:"content,omitempty"` // stream_chunk 的增量文本 Role string `json:"role,omitempty"` // stream 消息的角色 SessionID string `json:"session_id,omitempty"` // 会话 ID 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"` Messages []Message `json:"messages,omitempty"` // 历史消息列表 } 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"` }