Documentation
¶
Index ¶
- Constants
- func EncodeResponse(resp *JSONRPCResponse) ([]byte, error)
- func RegisterAcpMethods(registry *MethodRegistry, cfg *config.Config, acpManager *acp.Manager)
- type AcpCancelParams
- type AcpCloseParams
- type AcpListParams
- type AcpSetConfigOptionParams
- type AcpSetModeParams
- type AcpSpawnParams
- type AcpStatusParams
- type Connection
- type Handler
- type JSONRPCRequest
- type JSONRPCResponse
- type MessageType
- type MethodHandler
- type MethodRegistry
- type RPCError
- type Server
- type WebSocketConfig
Constants ¶
const ( ErrorParseError = -32700 ErrorInvalidRequest = -32600 ErrorMethodNotFound = -32601 ErrorInvalidParams = -32602 ErrorInternalError = -32603 )
Error codes
const ProtocolVersion = "1.0"
ProtocolVersion 当前协议版本
Variables ¶
This section is empty.
Functions ¶
func EncodeResponse ¶
func EncodeResponse(resp *JSONRPCResponse) ([]byte, error)
EncodeResponse 编码响应
func RegisterAcpMethods ¶ added in v0.3.2
func RegisterAcpMethods(registry *MethodRegistry, cfg *config.Config, acpManager *acp.Manager)
RegisterAcpMethods registers ACP-related gateway methods.
Types ¶
type AcpCancelParams ¶ added in v0.3.2
type AcpCancelParams struct {
SessionKey string `json:"session_key"`
Reason string `json:"reason,omitempty"`
}
AcpCancelParams parameters for acp_cancel method
type AcpCloseParams ¶ added in v0.3.2
type AcpCloseParams struct {
SessionKey string `json:"session_key"`
Reason string `json:"reason,omitempty"`
RequireAcpSession bool `json:"require_acp_session,omitempty"`
ClearMeta bool `json:"clear_meta,omitempty"`
}
AcpCloseParams parameters for acp_close method
type AcpListParams ¶ added in v0.3.2
type AcpListParams struct {
Limit int `json:"limit,omitempty"`
}
AcpListParams parameters for acp_list method
type AcpSetConfigOptionParams ¶ added in v0.3.2
type AcpSetConfigOptionParams struct {
SessionKey string `json:"session_key"`
Key string `json:"key"`
Value string `json:"value"`
}
AcpSetConfigOptionParams parameters for acp_set_config_option method
type AcpSetModeParams ¶ added in v0.3.2
type AcpSetModeParams struct {
SessionKey string `json:"session_key"`
RuntimeMode string `json:"runtime_mode"`
}
AcpSetModeParams parameters for acp_set_mode method
type AcpSpawnParams ¶ added in v0.3.2
type AcpSpawnParams struct {
Task string `json:"task"`
Label string `json:"label,omitempty"`
AgentID string `json:"agent_id,omitempty"`
Cwd string `json:"cwd,omitempty"`
Mode string `json:"mode,omitempty"` // "run" or "session"
Thread bool `json:"thread,omitempty"` // Whether to bind to a thread
// Context for thread binding
AgentChannel string `json:"agent_channel,omitempty"`
AgentAccountID string `json:"agent_account_id,omitempty"`
AgentTo string `json:"agent_to,omitempty"`
AgentThreadID string `json:"agent_thread_id,omitempty"`
}
AcpSpawnParams parameters for acp_spawn method
type AcpStatusParams ¶ added in v0.3.2
type AcpStatusParams struct {
SessionKey string `json:"session_key"`
}
AcpStatusParams parameters for acp_status method
type Connection ¶
Connection WebSocket 连接
func NewConnection ¶
func NewConnection(ws *websocket.Conn, cfg *WebSocketConfig) *Connection
NewConnection 创建连接
func (*Connection) SendJSON ¶
func (c *Connection) SendJSON(v interface{}) error
SendJSON 发送 JSON 消息
func (*Connection) SendMessage ¶
func (c *Connection) SendMessage(messageType int, data []byte) error
SendMessage 发送消息
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler WebSocket 消息处理器
func NewHandler ¶
func NewHandler(messageBus *bus.MessageBus, sessionMgr *session.Manager, channelMgr *channels.Manager, cronSvc *cron.Service, acpMgr interface{}, cfg *config.Config) *Handler
NewHandler 创建处理器
func (*Handler) BroadcastNotification ¶
BroadcastNotification 广播通知
func (*Handler) HandleRequest ¶
func (h *Handler) HandleRequest(sessionID string, req *JSONRPCRequest) *JSONRPCResponse
HandleRequest 处理请求
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id,omitempty"` // 通知可以没有ID
Method string `json:"method"`
Params map[string]interface{} `json:"params,omitempty"`
}
JSONRPCRequest JSON-RPC 请求
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id,omitempty"`
Result interface{} `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
JSONRPCResponse JSON-RPC 响应
func NewErrorResponse ¶
func NewErrorResponse(id string, code int, message string) *JSONRPCResponse
NewErrorResponse 创建错误响应
func NewSuccessResponse ¶
func NewSuccessResponse(id string, result interface{}) *JSONRPCResponse
NewSuccessResponse 创建成功响应
type MessageType ¶
type MessageType string
MessageType 消息类型
const ( // Request 请求 MessageTypeRequest MessageType = "request" // Response 响应 MessageTypeResponse MessageType = "response" // Notification 通知 MessageTypeNotification MessageType = "notification" )
type MethodHandler ¶
MethodHandler 方法处理器
type MethodRegistry ¶
type MethodRegistry struct {
// contains filtered or unexported fields
}
MethodRegistry 方法注册表
func (*MethodRegistry) Call ¶
func (r *MethodRegistry) Call(method string, sessionID string, params map[string]interface{}) (interface{}, error)
Call 调用方法
func (*MethodRegistry) Register ¶
func (r *MethodRegistry) Register(method string, handler MethodHandler)
Register 注册方法
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
}
RPCError RPC 错误
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server HTTP 网关服务器
func NewServer ¶
func NewServer(cfg *config.Config, messageBus *bus.MessageBus, channelMgr *channels.Manager, sessionMgr *session.Manager, cronSvc *cron.Service, acpMgr interface{}) *Server
NewServer 创建网关服务器
func (*Server) SetWebSocketConfig ¶
func (s *Server) SetWebSocketConfig(cfg *WebSocketConfig)
SetWebSocketConfig 设置 WebSocket 配置
type WebSocketConfig ¶
type WebSocketConfig struct {
Host string
Port int
Path string
EnableAuth bool
AuthToken string
PingInterval time.Duration
PongTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
MaxMessageSize int64
// TLS 配置
EnableTLS bool
CertFile string
KeyFile string
}
WebSocketConfig WebSocket 配置