Documentation
¶
Overview ¶
Package gateway provides the WebSocket control plane for omniagent.
Index ¶
- type AgentProcessor
- type AuthMessage
- type ChatMessage
- type Client
- type Config
- type DefaultMessageHandler
- type EventMessage
- type Gateway
- type Message
- type MessageHandler
- type MessageType
- type Observability
- func (o *Observability) CompleteWorkflow(ctx context.Context, workflowID string, output map[string]any) error
- func (o *Observability) EndTrace(tc *TraceContext, err error)
- func (o *Observability) FailWorkflow(ctx context.Context, workflowID string, err error) error
- func (o *Observability) ForceFlush(ctx context.Context) error
- func (o *Observability) Provider() observops.Provider
- func (o *Observability) RecordClientConnect(ctx context.Context, clientID string)
- func (o *Observability) RecordClientDisconnect(ctx context.Context, clientID string)
- func (o *Observability) RecordEvent(ctx context.Context, eventType, category string, data map[string]any) error
- func (o *Observability) RecordMessage(ctx context.Context, clientID string, msgType MessageType, err error)
- func (o *Observability) RecordToolInvocation(ctx context.Context, toolName string, duration time.Duration, err error)
- func (o *Observability) Shutdown(ctx context.Context) error
- func (o *Observability) StartTrace(ctx context.Context, operationName string, attrs ...observops.KeyValue) *TraceContext
- func (o *Observability) StartWorkflow(ctx context.Context, name string, input map[string]any) (*agentops.Workflow, error)
- func (o *Observability) Store() agentops.Store
- type ObservabilityConfig
- type ToolInfo
- type ToolInvokeRequest
- type ToolInvokeResponse
- type ToolsListHandler
- type ToolsListResponse
- type ToolsRPCConfig
- type ToolsRPCHandler
- type TraceContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentProcessor ¶
type AgentProcessor interface {
Process(ctx context.Context, sessionID, content string) (string, error)
}
AgentProcessor processes messages through an AI agent.
type AuthMessage ¶
type AuthMessage struct {
Token string `json:"token,omitempty"`
DeviceID string `json:"device_id,omitempty"`
}
AuthMessage represents an authentication message.
type ChatMessage ¶
type ChatMessage struct {
SessionID string `json:"session_id,omitempty"`
Content string `json:"content"`
Channel string `json:"channel,omitempty"`
ReplyTo string `json:"reply_to,omitempty"`
}
ChatMessage represents a chat message.
type Client ¶
type Client struct {
ID string
// contains filtered or unexported fields
}
Client represents a connected WebSocket client.
func (*Client) GetMetadata ¶
GetMetadata gets a metadata value.
func (*Client) SetMetadata ¶
SetMetadata sets a metadata value.
type Config ¶
type Config struct {
Address string
ReadTimeout time.Duration
WriteTimeout time.Duration
PingInterval time.Duration
Logger *slog.Logger
Agent AgentProcessor
WebhookHandlers map[string]http.Handler // Path -> Handler for webhook endpoints
}
Config configures the gateway server.
type DefaultMessageHandler ¶
type DefaultMessageHandler struct {
// contains filtered or unexported fields
}
DefaultMessageHandler provides a basic message handler implementation.
func NewDefaultMessageHandler ¶
func NewDefaultMessageHandler(gw *Gateway) *DefaultMessageHandler
NewDefaultMessageHandler creates a new default message handler.
type EventMessage ¶
type EventMessage struct {
Event string `json:"event"`
Channel string `json:"channel,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
}
EventMessage represents an event notification.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is the WebSocket control plane server.
func (*Gateway) ClientCount ¶
ClientCount returns the number of connected clients.
func (*Gateway) OnMessage ¶
func (g *Gateway) OnMessage(handler MessageHandler)
OnMessage sets the message handler.
type Message ¶
type Message struct {
ID string `json:"id,omitempty"`
Type MessageType `json:"type"`
Channel string `json:"channel,omitempty"`
Content string `json:"content,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
Error string `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
Message is the base message structure for gateway communication.
func NewChatResponse ¶
NewChatResponse creates a chat response message.
func NewErrorMessage ¶
NewErrorMessage creates an error message.
func NewEventMessage ¶
NewEventMessage creates an event message.
type MessageHandler ¶
MessageHandler handles incoming messages from clients.
type MessageType ¶
type MessageType string
MessageType represents the type of gateway message.
const ( // Client -> Gateway MessageTypeChat MessageType = "chat" MessageTypePing MessageType = "ping" MessageTypeAuth MessageType = "auth" MessageTypeSubscribe MessageType = "subscribe" // Gateway -> Client MessageTypeResponse MessageType = "response" MessageTypePong MessageType = "pong" MessageTypeError MessageType = "error" MessageTypeEvent MessageType = "event" )
type Observability ¶ added in v0.9.0
type Observability struct {
// contains filtered or unexported fields
}
Observability provides gateway instrumentation.
func NewObservability ¶ added in v0.9.0
func NewObservability(config ObservabilityConfig) (*Observability, error)
NewObservability creates a new observability instance.
func (*Observability) CompleteWorkflow ¶ added in v0.9.0
func (o *Observability) CompleteWorkflow(ctx context.Context, workflowID string, output map[string]any) error
CompleteWorkflow completes an agentops workflow.
func (*Observability) EndTrace ¶ added in v0.9.0
func (o *Observability) EndTrace(tc *TraceContext, err error)
EndTrace ends a trace with optional error.
func (*Observability) FailWorkflow ¶ added in v0.9.0
FailWorkflow marks an agentops workflow as failed.
func (*Observability) ForceFlush ¶ added in v0.9.0
func (o *Observability) ForceFlush(ctx context.Context) error
ForceFlush forces any buffered telemetry to be exported.
func (*Observability) Provider ¶ added in v0.9.0
func (o *Observability) Provider() observops.Provider
Provider returns the observops provider.
func (*Observability) RecordClientConnect ¶ added in v0.9.0
func (o *Observability) RecordClientConnect(ctx context.Context, clientID string)
RecordClientConnect records a client connection event.
func (*Observability) RecordClientDisconnect ¶ added in v0.9.0
func (o *Observability) RecordClientDisconnect(ctx context.Context, clientID string)
RecordClientDisconnect records a client disconnection event.
func (*Observability) RecordEvent ¶ added in v0.9.0
func (o *Observability) RecordEvent(ctx context.Context, eventType, category string, data map[string]any) error
RecordEvent records a generic event.
func (*Observability) RecordMessage ¶ added in v0.9.0
func (o *Observability) RecordMessage(ctx context.Context, clientID string, msgType MessageType, err error)
RecordMessage records a message processing event.
func (*Observability) RecordToolInvocation ¶ added in v0.9.0
func (o *Observability) RecordToolInvocation(ctx context.Context, toolName string, duration time.Duration, err error)
RecordToolInvocation records a tool invocation event.
func (*Observability) Shutdown ¶ added in v0.9.0
func (o *Observability) Shutdown(ctx context.Context) error
Shutdown shuts down observability, flushing any buffered data.
func (*Observability) StartTrace ¶ added in v0.9.0
func (o *Observability) StartTrace(ctx context.Context, operationName string, attrs ...observops.KeyValue) *TraceContext
StartTrace starts a new trace for a gateway operation.
func (*Observability) StartWorkflow ¶ added in v0.9.0
func (o *Observability) StartWorkflow(ctx context.Context, name string, input map[string]any) (*agentops.Workflow, error)
StartWorkflow starts a new agentops workflow for tracking.
func (*Observability) Store ¶ added in v0.9.0
func (o *Observability) Store() agentops.Store
Store returns the agentops store.
type ObservabilityConfig ¶ added in v0.9.0
type ObservabilityConfig struct {
// ServiceName is the name of this gateway service.
ServiceName string
// ServiceVersion is the version of this gateway service.
ServiceVersion string
// ObservopsProvider is the observops provider for metrics/traces.
ObservopsProvider observops.Provider
// AgentopsStore is the agentops store for workflow/task tracking.
AgentopsStore agentops.Store
// Logger is the logger for observability events.
Logger *slog.Logger
}
ObservabilityConfig configures gateway observability.
type ToolInfo ¶ added in v0.9.0
type ToolInfo struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters any `json:"parameters,omitempty"`
}
ToolInfo describes a tool for listing.
type ToolInvokeRequest ¶ added in v0.9.0
type ToolInvokeRequest struct {
// Tool is the name of the tool to invoke.
Tool string `json:"tool"`
// Arguments are the tool arguments as JSON.
Arguments json.RawMessage `json:"arguments"`
// WorkflowID is the optional workflow ID for tracking.
WorkflowID string `json:"workflow_id,omitempty"`
// TaskID is the optional task ID for tracking.
TaskID string `json:"task_id,omitempty"`
// AgentID is the agent invoking the tool.
AgentID string `json:"agent_id,omitempty"`
// TraceID is the optional trace ID for correlation.
TraceID string `json:"trace_id,omitempty"`
// Metadata contains optional request metadata.
Metadata map[string]any `json:"metadata,omitempty"`
}
ToolInvokeRequest is the request format for tools.invoke RPC.
type ToolInvokeResponse ¶ added in v0.9.0
type ToolInvokeResponse struct {
// Result is the tool execution result.
Result string `json:"result,omitempty"`
// Error is the error message if execution failed.
Error string `json:"error,omitempty"`
// ToolName is the name of the tool that was invoked.
ToolName string `json:"tool_name"`
// DurationMs is the execution duration in milliseconds.
DurationMs int64 `json:"duration_ms"`
// InvocationID is the unique ID for this invocation.
InvocationID string `json:"invocation_id,omitempty"`
// TraceID is the trace ID for correlation.
TraceID string `json:"trace_id,omitempty"`
}
ToolInvokeResponse is the response format for tools.invoke RPC.
type ToolsListHandler ¶ added in v0.9.0
type ToolsListHandler struct {
// contains filtered or unexported fields
}
ToolsListHandler handles listing available tools.
func NewToolsListHandler ¶ added in v0.9.0
func NewToolsListHandler(registry *agent.ToolRegistry, logger *slog.Logger) *ToolsListHandler
NewToolsListHandler creates a new tools list handler.
func (*ToolsListHandler) ServeHTTP ¶ added in v0.9.0
func (h *ToolsListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles the HTTP request.
type ToolsListResponse ¶ added in v0.9.0
type ToolsListResponse struct {
Tools []ToolInfo `json:"tools"`
}
ToolsListResponse is the response format for tools.list RPC.
type ToolsRPCConfig ¶ added in v0.9.0
type ToolsRPCConfig struct {
// ToolRegistry is the registry of available tools.
ToolRegistry *agent.ToolRegistry
// Observability provides tracing and metrics.
Observability *Observability
// Logger is the logger for RPC events.
Logger *slog.Logger
// MaxRequestSize is the maximum request body size in bytes.
// Default is 1MB.
MaxRequestSize int64
// Timeout is the maximum time for a tool invocation.
// Default is 30 seconds.
Timeout time.Duration
}
ToolsRPCConfig configures the tools RPC handler.
type ToolsRPCHandler ¶ added in v0.9.0
type ToolsRPCHandler struct {
// contains filtered or unexported fields
}
ToolsRPCHandler handles SDK-facing tools.invoke RPC requests.
func NewToolsRPCHandler ¶ added in v0.9.0
func NewToolsRPCHandler(config ToolsRPCConfig) *ToolsRPCHandler
NewToolsRPCHandler creates a new tools RPC handler.
func (*ToolsRPCHandler) ServeHTTP ¶ added in v0.9.0
func (h *ToolsRPCHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles the HTTP request.
type TraceContext ¶ added in v0.9.0
type TraceContext struct {
// contains filtered or unexported fields
}
TraceContext holds trace context for a request.