Documentation
¶
Overview ¶
Package ws implements the serve WebSocket channel runtime.
Index ¶
- type ClientMessage
- type Dispatcher
- type MemoryStore
- type PlanData
- type PlanStep
- type PlatformStatus
- type PlatformStatusProvider
- type Runtime
- func (gw *Runtime) ConnectionCount() int
- func (gw *Runtime) GetMux() *http.ServeMux
- func (gw *Runtime) RegisterHandler(pattern string, handler http.Handler)
- func (gw *Runtime) SetClientInfo(model, workDir string)
- func (gw *Runtime) SetDispatcher(d Dispatcher)
- func (gw *Runtime) SetMemoryStore(s MemoryStore)
- func (gw *Runtime) SetPlatformStatusProvider(p PlatformStatusProvider)
- func (gw *Runtime) Start() error
- func (gw *Runtime) Stop(timeout time.Duration) error
- func (gw *Runtime) WebSocketHandler() http.Handler
- type SessionInfo
- type WSConn
- type WSEvent
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 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 ¶
NewRuntime creates a new runtime server.
func (*Runtime) ConnectionCount ¶
ConnectionCount returns the number of active WebSocket connections.
func (*Runtime) RegisterHandler ¶
RegisterHandler registers an additional HTTP handler on the runtime mux.
func (*Runtime) SetClientInfo ¶
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) WebSocketHandler ¶
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.
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.