package ws import "encoding/json" // ── Client → Server messages ── // MsgType enumerates known message types. type MsgType string const ( MsgHello MsgType = "hello" MsgStart MsgType = "start" MsgStop MsgType = "stop" MsgPaste MsgType = "paste" MsgPing MsgType = "ping" MsgPong MsgType = "pong" ) // ClientMsg is a JSON control message from the phone. type ClientMsg struct { Type MsgType `json:"type"` SessionID string `json:"sessionId,omitempty"` Seq int64 `json:"seq,omitempty"` Text string `json:"text,omitempty"` // Only for "paste" Version int `json:"version,omitempty"` TS int64 `json:"ts,omitempty"` // Future extension: dynamic hotwords (Phase 2) // Hotwords []string `json:"hotwords,omitempty"` } // ── Server → Client messages ── const ( MsgReady MsgType = "ready" MsgState MsgType = "state" MsgStartAck MsgType = "start_ack" MsgStopAck MsgType = "stop_ack" MsgPartial MsgType = "partial" MsgFinal MsgType = "final" MsgPasted MsgType = "pasted" MsgError MsgType = "error" ) const ( StateIdle = "idle" StateRecording = "recording" StateStopping = "stopping" ) // ServerMsg is a JSON message sent to the phone. type ServerMsg struct { Type MsgType `json:"type"` State string `json:"state,omitempty"` SessionID string `json:"sessionId,omitempty"` Seq int64 `json:"seq,omitempty"` Text string `json:"text,omitempty"` Message string `json:"message,omitempty"` // For errors Code string `json:"code,omitempty"` Retryable bool `json:"retryable,omitempty"` TS int64 `json:"ts,omitempty"` } func (m ServerMsg) Bytes() []byte { b, _ := json.Marshal(m) return b }