gateway

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gateway provides the WebSocket control plane for omniagent.

Index

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) Close

func (c *Client) Close()

Close closes the client connection.

func (*Client) GetMetadata

func (c *Client) GetMetadata(key string) (interface{}, bool)

GetMetadata gets a metadata value.

func (*Client) Send

func (c *Client) Send(msg *Message)

Send queues a message to be sent to the client.

func (*Client) SetMetadata

func (c *Client) SetMetadata(key string, value interface{})

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.

func (*DefaultMessageHandler) Handle

func (h *DefaultMessageHandler) Handle(ctx context.Context, client *Client, msg *Message) (*Message, error)

Handle processes incoming messages.

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 New

func New(config Config) (*Gateway, error)

New creates a new Gateway.

func (*Gateway) Broadcast

func (g *Gateway) Broadcast(msg *Message)

Broadcast sends a message to all connected clients.

func (*Gateway) ClientCount

func (g *Gateway) ClientCount() int

ClientCount returns the number of connected clients.

func (*Gateway) GetClient

func (g *Gateway) GetClient(id string) *Client

GetClient returns a client by ID.

func (*Gateway) OnMessage

func (g *Gateway) OnMessage(handler MessageHandler)

OnMessage sets the message handler.

func (*Gateway) Run

func (g *Gateway) Run(ctx context.Context) error

Run starts the gateway server.

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

func NewChatResponse(id, content string) *Message

NewChatResponse creates a chat response message.

func NewErrorMessage

func NewErrorMessage(id, errMsg string) *Message

NewErrorMessage creates an error message.

func NewEventMessage

func NewEventMessage(event, channel string, data map[string]interface{}) *Message

NewEventMessage creates an event message.

type MessageHandler

type MessageHandler func(ctx context.Context, client *Client, msg *Message) (*Message, error)

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"
)

Jump to

Keyboard shortcuts

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