package gobridge import "encoding/json" // 消息类型常量 const ( TypeCall = "call" // Go → Python: 调用请求 TypeResult = "result" // Python → Go: 调用结果 TypeError = "error" // 双向: 错误响应 TypeChunk = "chunk" // 双向: 流数据块 TypeEnd = "end" // 双向: 流结束标记 TypeCancel = "cancel" // Go → Python: 取消正在执行的调用(ctx 取消时发送) ) // Message 是 Go 与 Python 之间传输的消息结构 // 使用 4 字节大端长度前缀 + JSON 编码 type Message struct { ID uint64 `json:"id"` Type string `json:"type"` Method string `json:"method,omitempty"` Args json.RawMessage `json:"args,omitempty"` StreamInput bool `json:"stream_input,omitempty"` // 是否有流式输入参数 StreamArgIdx int `json:"stream_arg_idx,omitempty"` // 流式参数在 args 中的下标 Data json.RawMessage `json:"data,omitempty"` // 结果/数据块内容 Error string `json:"error,omitempty"` }