browser

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() engine.Plugin

New creates a new browser IO plugin.

Types

type Adapter

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

Adapter implements a WebSocket-based UI adapter.

func NewAdapter

func NewAdapter(hub *Hub, sessionID string) *Adapter

NewAdapter creates a browser UI adapter backed by the given hub.

func (*Adapter) OnApprovalResponse

func (a *Adapter) OnApprovalResponse(handler func(ui.ApprovalResponseMessage))

OnApprovalResponse registers the callback for approval responses.

func (*Adapter) OnCancel

func (a *Adapter) OnCancel(handler func())

OnCancel registers the callback for cancel requests.

func (*Adapter) OnInput

func (a *Adapter) OnInput(handler func(clientID string, msg ui.InputMessage))

OnInput registers the callback for user input messages.

The handler is given the originating client id as well as the message, which the shared ui.UIAdapter shape does not carry. It is needed here and nowhere else: this transport's per-request context (the X-Nexus-* headers of the WebSocket upgrade) is held per connection, and only the client id identifies which connection a message arrived on when several browsers are attached to one session.

func (*Adapter) OnResume

func (a *Adapter) OnResume(handler func())

OnResume registers the callback for resume requests.

func (*Adapter) RequestApproval

func (a *Adapter) RequestApproval(msg ui.ApprovalRequestMessage) (ui.ApprovalResponseMessage, error)

RequestApproval sends an approval request and blocks until the user responds.

func (*Adapter) RequestHumanInput

func (a *Adapter) RequestHumanInput(msg ui.HITLRequestMessage) (ui.HITLResponseMessage, error)

RequestHumanInput sends a hitl request to all clients and blocks until one responds.

func (*Adapter) SendCancelComplete

func (a *Adapter) SendCancelComplete(turnID string, resumable bool) error

SendCancelComplete notifies clients that a cancellation completed.

func (*Adapter) SendCodeExecStdout

func (a *Adapter) SendCodeExecStdout(msg ui.CodeExecStdoutMessage) error

SendCodeExecStdout streams a chunk of run_code script stdout to all clients.

func (*Adapter) SendFileChanged

func (a *Adapter) SendFileChanged(path string, action string) error

SendFileChanged notifies clients that a session file was created or updated.

func (*Adapter) SendOutput

func (a *Adapter) SendOutput(msg ui.OutputMessage) error

SendOutput sends a complete output message to all clients.

func (*Adapter) SendPlanDisplay

func (a *Adapter) SendPlanDisplay(msg ui.PlanDisplayMessage) error

SendPlanDisplay sends a plan overview to all clients.

func (*Adapter) SendPlanUpdate

func (a *Adapter) SendPlanUpdate(msg ui.PlanDisplayMessage) error

SendPlanUpdate sends an updated plan with current step statuses to all clients.

func (*Adapter) SendStatus

func (a *Adapter) SendStatus(msg ui.StatusMessage) error

SendStatus sends a status update to all clients.

func (*Adapter) SendStreamChunk

func (a *Adapter) SendStreamChunk(msg ui.StreamChunkMessage) error

SendStreamChunk sends a streaming chunk to all clients.

func (*Adapter) SendStreamEnd

func (a *Adapter) SendStreamEnd(msg ui.StreamEndMessage) error

SendStreamEnd signals the end of a stream to all clients.

func (*Adapter) SendStreamHold

func (a *Adapter) SendStreamHold(msg ui.StreamHoldMessage) error

SendStreamHold announces that an output gate suspended the stream, or released it again.

func (*Adapter) SendStreamRetract

func (a *Adapter) SendStreamRetract(msg ui.StreamRetractMessage) error

SendStreamRetract tells clients to disown the text rendered for a turn whose stream a gate blocked.

func (*Adapter) SendThinking

func (a *Adapter) SendThinking(msg ui.ThinkingMessage) error

SendThinking sends an intermediate thinking step to all clients.

func (*Adapter) SendWorkerStatus

func (a *Adapter) SendWorkerStatus(msg ui.WorkerStatusMessage) error

SendWorkerStatus emits a subagent lifecycle event to all clients. One envelope per bus event in the subagent.started/iteration/complete sequence; the frontend correlates by SpawnID.

func (*Adapter) SendWorkflowStatus

func (a *Adapter) SendWorkflowStatus(msg ui.WorkflowStatusMessage) error

SendWorkflowStatus emits a structured workflow progress update to all clients. One envelope per workflow.progress bus event; the frontend renders the latest payload in a sticky workflow indicator at the top of the chat surface.

func (*Adapter) Sessions

func (a *Adapter) Sessions() []ui.SessionInfo

Sessions returns info about connected browser sessions.

func (*Adapter) Start

func (a *Adapter) Start(_ context.Context) error

Start is a no-op for the browser adapter; the HTTP server is started separately.

func (*Adapter) Stop

func (a *Adapter) Stop(_ context.Context) error

Stop is a no-op; shutdown is handled by the server.

type Client

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

Client represents a single WebSocket connection.

type Hub

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

Hub manages WebSocket client connections and broadcasts messages.

func NewHub

func NewHub(logger *slog.Logger) *Hub

NewHub creates a new connection hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(data []byte)

Broadcast sends raw JSON bytes to all connected clients.

func (*Hub) BroadcastEnvelope

func (h *Hub) BroadcastEnvelope(env ui.Envelope) error

BroadcastEnvelope marshals an envelope and broadcasts it.

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) Close

func (h *Hub) Close()

Close closes all client connections and removes them from the hub.

func (*Hub) Headers

func (h *Hub) Headers(clientID string) map[string]string

Headers returns the X-Nexus-* headers of the named client's upgrade request, or nil when the client is unknown or sent none. The map is the one stored at Register and must not be mutated by the caller; nothing in this package writes it after the client is registered.

func (*Hub) OnMessage

func (h *Hub) OnMessage(fn func(clientID string, env ui.Envelope))

OnMessage registers a callback for inbound client messages.

func (*Hub) Register

func (h *Hub) Register(client *Client)

Register adds a client to the hub and starts its read/write pumps.

func (*Hub) ServeClient

func (h *Hub) ServeClient(ctx context.Context, client *Client)

ServeClient starts the read and write pumps for a client.

func (*Hub) Sessions

func (h *Hub) Sessions() []ui.SessionInfo

Sessions returns session info for all connected clients.

func (*Hub) Unregister

func (h *Hub) Unregister(id string)

Unregister removes a client from the hub and closes its send channel.

type Plugin

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

Plugin is the browser IO plugin that serves a web UI over HTTP/WebSocket.

func (*Plugin) Capabilities

func (p *Plugin) Capabilities() []engine.Capability

func (*Plugin) ConfigSchema

func (p *Plugin) ConfigSchema() []byte

ConfigSchema implements engine.ConfigSchemaProvider.

func (*Plugin) Dependencies

func (p *Plugin) Dependencies() []string

func (*Plugin) Emissions

func (p *Plugin) Emissions() []string

func (*Plugin) ID

func (p *Plugin) ID() string

func (*Plugin) Init

func (p *Plugin) Init(ctx engine.PluginContext) error

Init creates the hub, adapter, and server, then wires event handlers.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Ready

func (p *Plugin) Ready() error

Ready starts the HTTP server and optionally opens the browser.

func (*Plugin) Requires

func (p *Plugin) Requires() []engine.Requirement

func (*Plugin) Shutdown

func (p *Plugin) Shutdown(ctx context.Context) error

Shutdown stops the server and unsubscribes from events.

func (*Plugin) Subscriptions

func (p *Plugin) Subscriptions() []engine.EventSubscription

func (*Plugin) Version

func (p *Plugin) Version() string

type Server

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

Server handles HTTP requests and WebSocket upgrades for the browser UI.

func NewServer

func NewServer(hub *Hub, session *engine.SessionWorkspace, logger *slog.Logger, host string, port int, capabilities map[string][]string, bus engine.EventBus) *Server

NewServer creates a new HTTP server for the browser UI. capabilities is the boot-time capability → provider-IDs map, used to answer feature probes without string-matching specific plugin IDs. bus is the engine event bus, used to drive the admin reload-config endpoint.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server's listen address.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP server.

func (*Server) Start

func (s *Server) Start() error

Start begins listening for HTTP connections.

Jump to

Keyboard shortcuts

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