Documentation
¶
Index ¶
- Constants
- func RunBridge(gatewayURL, password, agentID, agentName string) error
- type AgentEvent
- type AgentIdentity
- type AgentParams
- type AgentSummary
- type AgentsListResult
- type BridgeModel
- type BridgeStatus
- type ChallengePayload
- type ChannelStatus
- type ChannelsStatusResult
- type ChatEvent
- type ChatHistoryParams
- type ChatMessage
- type ChatSendParams
- type Client
- func (c *Client) AgentSend(ctx context.Context, params AgentParams) error
- func (c *Client) ChannelsStatus(ctx context.Context) (json.RawMessage, error)
- func (c *Client) ChatHistory(ctx context.Context, sessionKey string, limit int) (json.RawMessage, error)
- func (c *Client) ChatSend(ctx context.Context, sessionKey, message string) error
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) ConnectWithReconnect(ctx context.Context) error
- func (c *Client) Events() <-chan *GatewayEvent
- func (c *Client) Health(ctx context.Context) error
- func (c *Client) Hello() *HelloOk
- func (c *Client) ListAgents(ctx context.Context) (*AgentsListResult, error)
- func (c *Client) ListSessions(ctx context.Context, agentID string) ([]SessionEntry, error)
- func (c *Client) Request(ctx context.Context, method string, params any) (json.RawMessage, error)
- type ClientInfo
- type ConnectAuth
- type ConnectParams
- type ErrorShape
- type EventFrame
- type Features
- type GatewayEvent
- type HelloAuth
- type HelloOk
- type HelloPolicy
- type HistoryMessage
- type HistoryResponse
- type OpenClawOptions
- type PresenceEntry
- type RequestFrame
- type ResponseFrame
- type ServerInfo
- type SessionDefaults
- type SessionEntry
- type SessionsListParams
- type ShutdownPayload
- type Snapshot
- type StateVersion
- type TickPayload
Constants ¶
const ( FrameTypeRequest = "req" FrameTypeResponse = "res" FrameTypeEvent = "event" )
Frame types for the gateway WebSocket protocol.
const (
// Default gateway URL (loopback only).
DefaultGatewayURL = "ws://127.0.0.1:31337"
)
const ProtocolVersion = 3
Protocol version supported by this client.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AgentEvent ¶
type AgentEvent struct {
RunID string `json:"runId"`
Seq int `json:"seq"`
Stream string `json:"stream"` // "assistant", "lifecycle", "tool", "result"
Ts int64 `json:"ts"`
Data map[string]any `json:"data"`
SessionKey string `json:"sessionKey,omitempty"`
AgentID string `json:"agentId,omitempty"`
}
AgentEvent is a streaming event from agent execution.
type AgentIdentity ¶
type AgentIdentity struct {
Name string `json:"name,omitempty"`
Theme string `json:"theme,omitempty"`
Emoji string `json:"emoji,omitempty"`
Avatar string `json:"avatar,omitempty"`
AvatarURL string `json:"avatarUrl,omitempty"`
}
AgentIdentity holds display info for an agent.
type AgentParams ¶
type AgentParams struct {
Message string `json:"message"`
AgentID string `json:"agentId,omitempty"`
SessionKey string `json:"sessionKey,omitempty"`
Channel string `json:"channel,omitempty"`
Deliver *bool `json:"deliver,omitempty"`
To string `json:"to,omitempty"`
AccountID string `json:"accountId,omitempty"`
ReplyChannel string `json:"replyChannel,omitempty"`
ReplyAccountID string `json:"replyAccountId,omitempty"`
ThreadID string `json:"threadId,omitempty"`
GroupID string `json:"groupId,omitempty"`
IdempotencyKey string `json:"idempotencyKey"`
}
AgentParams for sending a message to an agent via the "agent" RPC method.
type AgentSummary ¶
type AgentSummary struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Identity *AgentIdentity `json:"identity,omitempty"`
}
AgentSummary is returned by agents.list.
type AgentsListResult ¶
type AgentsListResult struct {
DefaultID string `json:"defaultId"`
MainKey string `json:"mainKey"`
Scope string `json:"scope"`
Agents []AgentSummary `json:"agents"`
}
AgentsListResult is the response from agents.list.
type BridgeModel ¶
type BridgeModel struct {
// contains filtered or unexported fields
}
BridgeModel is the bubbletea model for the OpenClaw bridge TUI.
func NewBridgeModel ¶
func NewBridgeModel(gatewayURL, password, agentID, agentName string) *BridgeModel
NewBridgeModel creates a new bridge TUI model.
func (*BridgeModel) Init ¶
func (m *BridgeModel) Init() tea.Cmd
func (*BridgeModel) View ¶
func (m *BridgeModel) View() string
type BridgeStatus ¶
type BridgeStatus int
BridgeStatus represents the connection state shown in the bridge header.
const ( BridgeStatusDisconnected BridgeStatus = iota BridgeStatusConnecting BridgeStatusConnected BridgeStatusProcessing BridgeStatusReconnecting )
func (BridgeStatus) String ¶
func (s BridgeStatus) String() string
type ChallengePayload ¶
type ChallengePayload struct {
Nonce string `json:"nonce"`
}
ChallengePayload is the payload of a "connect.challenge" event.
type ChannelStatus ¶
type ChannelStatus struct {
Enabled bool `json:"enabled"`
Connected bool `json:"connected"`
Guilds int `json:"guilds,omitempty"`
Error string `json:"error,omitempty"`
}
ChannelStatus represents the status of a communication channel.
type ChannelsStatusResult ¶
type ChannelsStatusResult struct {
Discord *ChannelStatus `json:"discord,omitempty"`
}
ChannelsStatusResult is the response from channels.status.
type ChatEvent ¶
type ChatEvent struct {
RunID string `json:"runId"`
SessionKey string `json:"sessionKey"`
Seq int `json:"seq"`
State string `json:"state"` // "delta", "final", "aborted", "error"
Message json.RawMessage `json:"message,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
Usage json.RawMessage `json:"usage,omitempty"`
StopReason string `json:"stopReason,omitempty"`
}
ChatEvent is a streaming chat event from the gateway.
type ChatHistoryParams ¶
type ChatHistoryParams struct {
SessionKey string `json:"sessionKey"`
Limit int `json:"limit,omitempty"`
}
ChatHistoryParams for chat.history.
type ChatMessage ¶
type ChatMessage struct {
Timestamp time.Time
Sender string
Content string
Direction string // "inbound" (from Discord), "outbound" (from bridge), "system"
AgentID string
RunID string // tracks which conversation turn this belongs to
}
ChatMessage is a normalized message for display in the bridge TUI.
type ChatSendParams ¶
type ChatSendParams struct {
SessionKey string `json:"sessionKey"`
Message string `json:"message"`
Thinking string `json:"thinking,omitempty"`
Deliver *bool `json:"deliver,omitempty"`
TimeoutMs int `json:"timeoutMs,omitempty"`
IdempotencyKey string `json:"idempotencyKey"`
}
ChatSendParams are parameters for chat.send.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to the OpenClaw gateway via WebSocket JSON-RPC.
func (*Client) AgentSend ¶
func (c *Client) AgentSend(ctx context.Context, params AgentParams) error
AgentSend sends a message to an agent via the "agent" RPC method. Unlike ChatSend (which uses "chat.send" for webchat-only), this routes through the full agent pipeline and can deliver responses to external channels like Discord.
func (*Client) ChannelsStatus ¶
ChannelsStatus returns the status of communication channels.
func (*Client) ChatHistory ¶
func (c *Client) ChatHistory(ctx context.Context, sessionKey string, limit int) (json.RawMessage, error)
ChatHistory retrieves recent messages from a session.
func (*Client) Connect ¶
Connect establishes the WebSocket connection and completes the challenge/response handshake.
func (*Client) ConnectWithReconnect ¶
ConnectWithReconnect connects and automatically reconnects on disconnection.
func (*Client) Events ¶
func (c *Client) Events() <-chan *GatewayEvent
Events returns a channel of gateway events for the caller to consume.
func (*Client) Hello ¶
Hello returns the hello-ok response from the gateway, available after Connect.
func (*Client) ListAgents ¶
func (c *Client) ListAgents(ctx context.Context) (*AgentsListResult, error)
ListAgents returns all configured agents.
func (*Client) ListSessions ¶
ListSessions returns sessions for an agent.
type ClientInfo ¶
type ClientInfo struct {
ID string `json:"id"`
DisplayName string `json:"displayName,omitempty"`
Version string `json:"version"`
Platform string `json:"platform"`
DeviceFamily string `json:"deviceFamily,omitempty"`
ModelIdentifier string `json:"modelIdentifier,omitempty"`
Mode string `json:"mode"`
InstanceID string `json:"instanceId,omitempty"`
}
ClientInfo identifies this client to the gateway.
type ConnectAuth ¶
type ConnectAuth struct {
Token string `json:"token,omitempty"`
DeviceToken string `json:"deviceToken,omitempty"`
Password string `json:"password,omitempty"`
}
ConnectAuth holds authentication credentials for the connect request.
type ConnectParams ¶
type ConnectParams struct {
MinProtocol int `json:"minProtocol"`
MaxProtocol int `json:"maxProtocol"`
Client ClientInfo `json:"client"`
Caps []string `json:"caps,omitempty"`
Role string `json:"role,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Auth *ConnectAuth `json:"auth,omitempty"`
Locale string `json:"locale,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
}
ConnectParams are sent in the "connect" request.
type ErrorShape ¶
type ErrorShape struct {
Code string `json:"code"`
Message string `json:"message"`
Details any `json:"details,omitempty"`
Retryable bool `json:"retryable,omitempty"`
RetryAfterMs int `json:"retryAfterMs,omitempty"`
}
ErrorShape is the error object in a failed response.
func (*ErrorShape) Error ¶
func (e *ErrorShape) Error() string
type EventFrame ¶
type EventFrame struct {
Type string `json:"type"`
Event string `json:"event"`
Payload json.RawMessage `json:"payload,omitempty"`
Seq *int `json:"seq,omitempty"`
StateVersion *StateVersion `json:"stateVersion,omitempty"`
}
EventFrame is a server-pushed event.
type GatewayEvent ¶
type GatewayEvent struct {
Name string // Event name (e.g., "chat", "tick", "agent", "presence")
Payload json.RawMessage // Raw payload for caller to unmarshal
Seq *int // Optional sequence number
}
GatewayEvent wraps an event frame for consumers.
type HelloAuth ¶
type HelloAuth struct {
DeviceToken string `json:"deviceToken,omitempty"`
Role string `json:"role"`
Scopes []string `json:"scopes"`
IssuedAtMs int64 `json:"issuedAtMs,omitempty"`
}
HelloAuth is returned in hello-ok with auth tokens.
type HelloOk ¶
type HelloOk struct {
Type string `json:"type"` // "hello-ok"
Protocol int `json:"protocol"`
Server ServerInfo `json:"server"`
Features Features `json:"features"`
Snapshot Snapshot `json:"snapshot"`
Auth *HelloAuth `json:"auth,omitempty"`
Policy HelloPolicy `json:"policy"`
}
HelloOk is the payload of a successful "connect" response.
type HelloPolicy ¶
type HelloPolicy struct {
MaxPayload int `json:"maxPayload"`
MaxBufferedBytes int `json:"maxBufferedBytes"`
TickIntervalMs int `json:"tickIntervalMs"`
}
HelloPolicy defines connection limits.
type HistoryMessage ¶
type HistoryMessage struct {
Role string `json:"role"` // "user", "assistant", "system"
Timestamp int64 `json:"timestamp"`
Content json.RawMessage `json:"content"` // string or []ContentBlock
}
HistoryMessage is a message from chat history.
type HistoryResponse ¶
type HistoryResponse struct {
SessionKey string `json:"sessionKey"`
Messages []HistoryMessage `json:"messages"`
}
HistoryResponse is the response from chat.history.
type OpenClawOptions ¶
type OpenClawOptions struct {
AgentID string `json:"agent_id"`
AgentName string `json:"agent_name,omitempty"`
}
OpenClawOptions is stored in ToolOptionsJSON to identify which agent a session bridges.
type PresenceEntry ¶
type PresenceEntry struct {
Host string `json:"host,omitempty"`
IP string `json:"ip,omitempty"`
Version string `json:"version,omitempty"`
Platform string `json:"platform,omitempty"`
DeviceFamily string `json:"deviceFamily,omitempty"`
ModelIdentifier string `json:"modelIdentifier,omitempty"`
Mode string `json:"mode,omitempty"`
LastInputSeconds *int `json:"lastInputSeconds,omitempty"`
Reason string `json:"reason,omitempty"`
Tags []string `json:"tags,omitempty"`
Text string `json:"text,omitempty"`
Ts int64 `json:"ts"`
DeviceID string `json:"deviceId,omitempty"`
Roles []string `json:"roles,omitempty"`
Scopes []string `json:"scopes,omitempty"`
InstanceID string `json:"instanceId,omitempty"`
}
PresenceEntry represents a connected client's presence info.
type RequestFrame ¶
type RequestFrame struct {
Type string `json:"type"`
ID string `json:"id"`
Method string `json:"method"`
Params any `json:"params,omitempty"`
}
RequestFrame is a JSON-RPC request sent to the gateway.
type ResponseFrame ¶
type ResponseFrame struct {
Type string `json:"type"`
ID string `json:"id"`
OK bool `json:"ok"`
Payload json.RawMessage `json:"payload,omitempty"`
Error *ErrorShape `json:"error,omitempty"`
}
ResponseFrame is a JSON-RPC response from the gateway.
type ServerInfo ¶
ServerInfo identifies the gateway server.
type SessionDefaults ¶
type SessionDefaults struct {
DefaultAgentID string `json:"defaultAgentId"`
MainKey string `json:"mainKey"`
MainSessionKey string `json:"mainSessionKey"`
Scope string `json:"scope,omitempty"`
}
SessionDefaults from the snapshot.
type SessionEntry ¶
type SessionEntry struct {
Key string `json:"key"`
SessionID string `json:"sessionId,omitempty"`
AgentID string `json:"agentId,omitempty"`
Title string `json:"title,omitempty"`
DerivedTitle string `json:"derivedTitle,omitempty"`
Label string `json:"label,omitempty"`
LastMessage json.RawMessage `json:"lastMessage,omitempty"`
LastActiveMs int64 `json:"lastActiveMs,omitempty"`
CreatedMs int64 `json:"createdMs,omitempty"`
MessageCount int `json:"messageCount,omitempty"`
SpawnedBy string `json:"spawnedBy,omitempty"`
}
SessionEntry is returned by sessions.list.
type SessionsListParams ¶
type SessionsListParams struct {
Limit int `json:"limit,omitempty"`
ActiveMinutes int `json:"activeMinutes,omitempty"`
IncludeGlobal bool `json:"includeGlobal,omitempty"`
IncludeUnknown bool `json:"includeUnknown,omitempty"`
IncludeDerivedTitles bool `json:"includeDerivedTitles,omitempty"`
IncludeLastMessage bool `json:"includeLastMessage,omitempty"`
Label string `json:"label,omitempty"`
SpawnedBy string `json:"spawnedBy,omitempty"`
AgentID string `json:"agentId,omitempty"`
Search string `json:"search,omitempty"`
}
SessionsListParams are parameters for sessions.list.
type ShutdownPayload ¶
type ShutdownPayload struct {
Reason string `json:"reason"`
RestartExpectedMs int `json:"restartExpectedMs,omitempty"`
}
ShutdownPayload is the payload of a "shutdown" event.
type Snapshot ¶
type Snapshot struct {
Presence []PresenceEntry `json:"presence"`
Health json.RawMessage `json:"health"`
StateVersion StateVersion `json:"stateVersion"`
UptimeMs int64 `json:"uptimeMs"`
ConfigPath string `json:"configPath,omitempty"`
StateDir string `json:"stateDir,omitempty"`
SessionDefaults *SessionDefaults `json:"sessionDefaults,omitempty"`
AuthMode string `json:"authMode,omitempty"`
}
Snapshot is the initial state snapshot in hello-ok.
type StateVersion ¶
StateVersion tracks presence and health versions for differential updates.
type TickPayload ¶
type TickPayload struct {
Ts int64 `json:"ts"`
}
TickPayload is the payload of a "tick" heartbeat event.