ws

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ws provides a Phoenix Channel client over WebSocket for consuming real-time agent events from reef-core.

Index

Constants

View Source
const (
	HeartbeatInterval = 30 * time.Second
	HeartbeatTimeout  = 10 * time.Second
	ReconnectMin      = 1 * time.Second
	ReconnectMax      = 30 * time.Second
)

Phoenix protocol constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages a WebSocket connection to reef-core's Phoenix Channel endpoint. It joins channels, sends heartbeats, and dispatches incoming events as Bubble Tea messages via program.Send().

func New

func New(serverURL, token string) *Client

New creates a Client. Call Connect to start the connection.

func (*Client) Close

func (c *Client) Close()

Close shuts down the WebSocket client gracefully.

func (*Client) Connect

func (c *Client) Connect(p *tea.Program)

Connect opens the WebSocket, starts heartbeat, joins pod:events, and begins reading messages. Handles reconnection internally with exponential backoff. Must be called from a goroutine.

func (*Client) JoinAgent

func (c *Client) JoinAgent(agentID string) error

JoinAgent joins the agent:<id> channel, leaving any previously joined agent channel. Safe to call from any goroutine.

func (*Client) LeaveAgent

func (c *Client) LeaveAgent() error

LeaveAgent leaves the current agent channel.

type CompletePayload

type CompletePayload struct {
	Result string `json:"result"`
}

CompletePayload carries a task completion event.

type CostPayload

type CostPayload struct {
	Sats int64 `json:"sats"`
}

CostPayload carries a spend event.

type ErrorPayload

type ErrorPayload struct {
	Message string `json:"message"`
}

ErrorPayload carries an agent error event.

type LifecyclePayload

type LifecyclePayload struct {
	AgentID string `json:"agent_id"`
	Name    string `json:"name,omitempty"`
	Code    int    `json:"code,omitempty"`
}

LifecyclePayload carries agent started/exited events on pod:events.

type PhoenixMsg

type PhoenixMsg struct {
	JoinRef string `json:"join_ref"`
	Ref     string `json:"ref"`
	Topic   string `json:"topic"`
	Event   string `json:"event"`
	Payload any    `json:"payload"`
}

PhoenixMsg is the JSON envelope used by Phoenix Channels. Every message over the WebSocket uses this shape.

type StreamPayload

type StreamPayload struct {
	Data string `json:"data"`
}

StreamPayload carries agent text output.

type ToolCallPayload

type ToolCallPayload struct {
	Tool string `json:"tool"`
}

ToolCallPayload carries a tool invocation event.

type WsAgentExited

type WsAgentExited struct {
	AgentID string
	Code    int
}

WsAgentExited signals an agent left the pod.

type WsAgentStarted

type WsAgentStarted struct{ AgentID, Name string }

WsAgentStarted signals a new agent joined the pod.

type WsCompleteMsg

type WsCompleteMsg struct{ AgentID, Result string }

WsCompleteMsg signals task completion.

type WsConnectedMsg

type WsConnectedMsg struct{}

WsConnectedMsg signals the WebSocket connected successfully.

type WsCostMsg

type WsCostMsg struct {
	AgentID string
	Sats    int64
}

WsCostMsg carries a per-agent spend event from the AgentChannel. It is only delivered while an agent:<id> topic is joined — typically when the Inspector is open on that agent.

type WsDisconnectedMsg

type WsDisconnectedMsg struct{ Err error }

WsDisconnectedMsg signals the WebSocket disconnected.

type WsErrorMsg

type WsErrorMsg struct{ AgentID, Message string }

WsErrorMsg carries an agent error.

type WsPodCostMsg

type WsPodCostMsg struct {
	AgentID string
	Sats    int64
}

WsPodCostMsg carries a pod-wide spend event from the PodEventsChannel. It is delivered for every agent_cost broadcast regardless of which (if any) agent channel is currently joined, so the Budget tab stays live even when no Inspector is open.

type WsStreamMsg

type WsStreamMsg struct{ AgentID, Data string }

WsStreamMsg carries streaming text output from an agent.

type WsToolCallMsg

type WsToolCallMsg struct{ AgentID, Tool string }

WsToolCallMsg carries a tool invocation event.

Jump to

Keyboard shortcuts

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