ws

package
v1.1.67 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ws implements the serve WebSocket channel runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMessage

type ClientMessage struct {
	Type       string `json:"type"`
	Content    string `json:"content,omitempty"`
	ApprovalID string `json:"approval_id,omitempty"`
	Approved   bool   `json:"approved,omitempty"`
	QuestionID string `json:"question_id,omitempty"`
	Answer     string `json:"answer,omitempty"`
}

ClientMessage represents a message from the WebSocket client.

type Dispatcher

type Dispatcher interface {
	HandleWSMessage(ctx context.Context, connID, text string, eventCh chan<- WSEvent) error
	ListSessions() []SessionInfo
	RemoveSession(key string)
	ResolveApproval(approvalID string, approved bool) bool
	ResolveQuestion(questionID, answer string) bool
}

Dispatcher is the interface the runtime uses to dispatch messages.

type MemoryStore

type MemoryStore interface {
	Read() (content string, path string, source string, err error)
	WriteAll(content string) error
}

MemoryStore provides read/write access to memory.md.

type PlanData

type PlanData struct {
	Title string     `json:"title"`
	Steps []PlanStep `json:"steps"`
}

PlanData represents a task plan for the plan_update event.

type PlanStep

type PlanStep struct {
	Title  string `json:"title"`
	Status string `json:"status"`
}

PlanStep is a single step in a task plan.

type PlatformStatus

type PlatformStatus struct {
	Name        string   `json:"name"`
	Enabled     bool     `json:"enabled"`
	Connected   bool     `json:"connected"`
	WorkDir     string   `json:"work_dir,omitempty"`
	ActiveUsers []string `json:"active_users,omitempty"`
	LoginStatus string   `json:"login_status,omitempty"`
}

PlatformStatus represents a messaging platform's connection status.

type PlatformStatusProvider

type PlatformStatusProvider interface {
	GetPlatformStatuses() []PlatformStatus
}

PlatformStatusProvider supplies platform connection status.

type Runtime

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

Runtime is the WebSocket + HTTP runtime server.

func NewRuntime

func NewRuntime(listenAddr, authToken, version string) *Runtime

NewRuntime creates a new runtime server.

func (*Runtime) ConnectionCount

func (gw *Runtime) ConnectionCount() int

ConnectionCount returns the number of active WebSocket connections.

func (*Runtime) GetMux

func (gw *Runtime) GetMux() *http.ServeMux

GetMux returns the HTTP mux for registering additional routes.

func (*Runtime) RegisterHandler

func (gw *Runtime) RegisterHandler(pattern string, handler http.Handler)

RegisterHandler registers an additional HTTP handler on the runtime mux.

func (*Runtime) SetClientInfo

func (gw *Runtime) SetClientInfo(model, workDir string)

SetClientInfo sets metadata sent to WebSocket clients when they connect.

func (*Runtime) SetDispatcher

func (gw *Runtime) SetDispatcher(d Dispatcher)

SetDispatcher sets the message dispatcher.

func (*Runtime) SetMemoryStore

func (gw *Runtime) SetMemoryStore(s MemoryStore)

SetMemoryStore sets the memory store for the /api/memory endpoint.

func (*Runtime) SetPlatformStatusProvider

func (gw *Runtime) SetPlatformStatusProvider(p PlatformStatusProvider)

SetPlatformStatusProvider sets the platform status provider.

func (*Runtime) Start

func (gw *Runtime) Start() error

Start starts the HTTP server. Blocks until stopped.

func (*Runtime) Stop

func (gw *Runtime) Stop(timeout time.Duration) error

Stop gracefully shuts down the runtime.

func (*Runtime) WebSocketHandler

func (gw *Runtime) WebSocketHandler() http.Handler

WebSocketHandler returns the websocket endpoint handler without starting a server.

type SessionInfo

type SessionInfo struct {
	ID           string    `json:"id"`
	Platform     string    `json:"platform"`
	UserID       string    `json:"user_id"`
	WorkDir      string    `json:"work_dir"`
	Mode         string    `json:"mode,omitempty"`
	Model        string    `json:"model,omitempty"`
	MessageCount int       `json:"message_count"`
	LastActive   time.Time `json:"last_active"`
	Preview      string    `json:"preview,omitempty"`
}

SessionInfo is a simplified session view for API responses.

type WSConn

type WSConn struct {
	ID string
	// contains filtered or unexported fields
}

WSConn wraps a WebSocket connection with metadata.

func (*WSConn) Close

func (c *WSConn) Close()

Close closes the WebSocket connection.

func (*WSConn) Send

func (c *WSConn) Send(ev WSEvent) error

Send sends a WSEvent to the client.

type WSEvent

type WSEvent struct {
	Type    string `json:"type"`
	Content string `json:"content,omitempty"`

	// Connected event fields
	SessionID string `json:"session_id,omitempty"`
	Version   string `json:"version,omitempty"`
	Model     string `json:"model,omitempty"`
	WorkDir   string `json:"work_dir,omitempty"`

	// Tool event fields
	Tool   string         `json:"tool,omitempty"`
	CallID string         `json:"call_id,omitempty"`
	Args   map[string]any `json:"args,omitempty"`
	Result string         `json:"result,omitempty"`

	// Diff fields
	Path string `json:"path,omitempty"`
	Diff string `json:"diff,omitempty"`

	// Approval fields
	ApprovalID   string         `json:"approval_id,omitempty"`
	ApprovalTool string         `json:"approval_tool,omitempty"`
	ApprovalArgs map[string]any `json:"approval_args,omitempty"`
	RiskLevel    string         `json:"risk_level,omitempty"`
	Approved     bool           `json:"approved,omitempty"`

	// Question fields
	QuestionID      string   `json:"question_id,omitempty"`
	Question        string   `json:"question,omitempty"`
	QuestionOptions []string `json:"question_options,omitempty"`
	QuestionContext string   `json:"question_context,omitempty"`
	Answer          string   `json:"answer,omitempty"`

	// Compaction fields
	StatusMessage string `json:"status_message,omitempty"`

	// Plan fields
	Plan *PlanData `json:"plan,omitempty"`

	// Usage fields
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
	CacheReadTokens  int `json:"cache_read_tokens,omitempty"`
	CacheWriteTokens int `json:"cache_write_tokens,omitempty"`

	// Done/Error fields
	StopReason string `json:"stop_reason,omitempty"`
	Message    string `json:"message,omitempty"`
	Command    string `json:"command,omitempty"`
	Error      bool   `json:"error,omitempty"`
	Code       string `json:"code,omitempty"`
}

WSEvent is the event type sent over WebSocket. Mapped from agent.Event by the dispatcher.

Jump to

Keyboard shortcuts

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