openclaw

package
v1.7.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrameTypeRequest  = "req"
	FrameTypeResponse = "res"
	FrameTypeEvent    = "event"
)

Frame types for the gateway WebSocket protocol.

View Source
const (
	// Default gateway URL (loopback only).
	DefaultGatewayURL = "ws://127.0.0.1:31337"
)
View Source
const ProtocolVersion = 3

Protocol version supported by this client.

Variables

This section is empty.

Functions

func RunBridge

func RunBridge(gatewayURL, password, agentID, agentName string) error

RunBridge launches the bridge TUI as a bubbletea program.

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) Update

func (m *BridgeModel) Update(msg tea.Msg) (tea.Model, 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 NewClient

func NewClient(url, password string) *Client

NewClient creates a new OpenClaw gateway client.

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

func (c *Client) ChannelsStatus(ctx context.Context) (json.RawMessage, error)

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) ChatSend

func (c *Client) ChatSend(ctx context.Context, sessionKey, message string) error

ChatSend sends a message to a session.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client and WebSocket connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes the WebSocket connection and completes the challenge/response handshake.

func (*Client) ConnectWithReconnect

func (c *Client) ConnectWithReconnect(ctx context.Context) error

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) Health

func (c *Client) Health(ctx context.Context) error

Health checks gateway health.

func (*Client) Hello

func (c *Client) Hello() *HelloOk

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

func (c *Client) ListSessions(ctx context.Context, agentID string) ([]SessionEntry, error)

ListSessions returns sessions for an agent.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method string, params any) (json.RawMessage, error)

Request sends a JSON-RPC request and waits for the response.

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 Features

type Features struct {
	Methods []string `json:"methods"`
	Events  []string `json:"events"`
}

Features lists supported methods and events.

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

type ServerInfo struct {
	Version string `json:"version"`
	ConnID  string `json:"connId"`
}

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

type StateVersion struct {
	Presence int `json:"presence"`
	Health   int `json:"health"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL