package protocol // ============================================================ // [协议] 版本化消息结构(JSON-RPC 风格) // 前端 / Go / Python 三方应对齐同一套字段名 // 真正接线时:Go 做路由,Python 实现 method 业务 // ============================================================ // Request 通用请求信封 type Request struct { ProtocolVersion string `json:"protocolVersion"` // 必须 = protocol.Version ID string `json:"id"` Method string `json:"method"` // 例: "agent.plan_next" / "device.tap" Params any `json:"params,omitempty"` } // Response 通用响应信封 type Response struct { ProtocolVersion string `json:"protocolVersion"` ID string `json:"id"` Result any `json:"result,omitempty"` Error *Error `json:"error,omitempty"` } // Error 结构化错误 type Error struct { Code int `json:"code"` Message string `json:"message"` } // ---- 常用 method 常量(避免魔法字符串)---- const ( MethodAgentHealth = "agent.health" MethodAgentPlanNext = "agent.plan_next" // 看图+对话 → 下一步操作 MethodAgentChat = "agent.chat" // 纯对话(可先接云端 API) ) // PlanNextParams agent.plan_next 入参(骨架,后续扩展) type PlanNextParams struct { SessionID string `json:"sessionId"` DeviceID string `json:"deviceId"` FrameBase64 string `json:"frameBase64,omitempty"` // 当前帧;空则由 Core 现截 UserMessage string `json:"userMessage,omitempty"` } // PlanNextResult 模型规划出的下一步(骨架) type PlanNextResult struct { Thought string `json:"thought"` Actions []DeviceAction `json:"actions"` } // DeviceAction 设备动作(由 Device Core 执行) type DeviceAction struct { Type string `json:"type"` // tap | swipe | key | text | wait X float64 `json:"x,omitempty"` Y float64 `json:"y,omitempty"` X2 float64 `json:"x2,omitempty"` Y2 float64 `json:"y2,omitempty"` Text string `json:"text,omitempty"` Key string `json:"key,omitempty"` MS int `json:"ms,omitempty"` }