refactor: 统一实时协议类型并扩展会话状态字段
This commit is contained in:
@@ -8,15 +8,22 @@ import "encoding/json"
|
||||
type MsgType string
|
||||
|
||||
const (
|
||||
MsgStart MsgType = "start" // Begin recording session
|
||||
MsgStop MsgType = "stop" // End recording session
|
||||
MsgPaste MsgType = "paste" // Re-paste a history item
|
||||
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"`
|
||||
Text string `json:"text,omitempty"` // Only for "paste"
|
||||
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"`
|
||||
}
|
||||
@@ -24,17 +31,33 @@ type ClientMsg struct {
|
||||
// ── Server → Client messages ──
|
||||
|
||||
const (
|
||||
MsgPartial MsgType = "partial" // Interim ASR result
|
||||
MsgFinal MsgType = "final" // Final ASR result
|
||||
MsgPasted MsgType = "pasted" // Paste confirmed
|
||||
MsgError MsgType = "error" // Error notification
|
||||
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"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Message string `json:"message,omitempty"` // For errors
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user