gateway

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCompanion     = errors.New("no companion connected")
	ErrApprovalTimeout = errors.New("approval timeout")
	ErrAgentNotReady   = errors.New("agent not ready")
)

Functions

func SessionFromContext

func SessionFromContext(ctx context.Context) string

SessionFromContext extracts the authenticated session key from the request context. Returns empty string if no session is present.

Types

type AuthManager

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

AuthManager manages authentication providers

func NewAuthManager

func NewAuthManager(cfg config.AuthConfig, store session.Store) (*AuthManager, error)

NewAuthManager creates a new AuthManager

func (*AuthManager) RegisterRoutes

func (am *AuthManager) RegisterRoutes(r chi.Router)

RegisterRoutes registers auth routes on the router

type Client

type Client struct {
	ID         string
	Type       string // "ui" or "companion"
	Conn       *websocket.Conn
	Server     *Server
	Send       chan []byte
	SessionKey string
	// contains filtered or unexported fields
}

Client represents a connected WebSocket client

func (*Client) Close

func (c *Client) Close()

Close closes the client connection

type Config

type Config struct {
	Host             string
	Port             int
	HTTPEnabled      bool
	WebSocketEnabled bool
	AllowedOrigins   []string
	ApprovalTimeout  time.Duration
	RequestTimeout   time.Duration
}

Config holds gateway server configuration

type OIDCProvider

type OIDCProvider struct {
	Name         string
	Config       config.OIDCProviderConfig
	OAuthConfig  *oauth2.Config
	OIDCProvider *oidc.Provider
	Verifier     *oidc.IDTokenVerifier
}

OIDCProvider handles OIDC authentication for a specific provider

func NewOIDCProvider

func NewOIDCProvider(name string, cfg config.OIDCProviderConfig) (*OIDCProvider, error)

NewOIDCProvider creates a new OIDCProvider

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError represents an RPC error

func (RPCError) Error

func (e RPCError) Error() string

Error implements the error interface for RPCError.

type RPCHandler

type RPCHandler func(client *Client, params json.RawMessage) (interface{}, error)

RPCHandler is a function that handles an RPC method. The client parameter provides the calling client's context (session, type, etc).

type RPCRequest

type RPCRequest struct {
	ID     string          `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

RPCRequest represents an incoming RPC request

type RPCResponse

type RPCResponse struct {
	ID     string      `json:"id"`
	Result interface{} `json:"result,omitempty"`
	Error  *RPCError   `json:"error,omitempty"`
}

RPCResponse represents an RPC response

type Server

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

Server represents the gateway server

func New

func New(cfg Config, agent *adk.Agent, provider *security.RPCProvider, store session.Store, auth *AuthManager) *Server

New creates a new gateway server

func (*Server) Broadcast

func (s *Server) Broadcast(event string, payload interface{})

Broadcast sends a message to all connected clients (defaulting to UI)

func (*Server) BroadcastToCompanions

func (s *Server) BroadcastToCompanions(event string, payload interface{})

BroadcastToCompanions sends a message to all connected companions

func (*Server) BroadcastToSession

func (s *Server) BroadcastToSession(sessionKey, event string, payload interface{})

BroadcastToSession sends an event to all UI clients belonging to a specific session. When the session key is empty (no auth), it broadcasts to all UI clients.

func (*Server) HasCompanions

func (s *Server) HasCompanions() bool

HasCompanions returns true if at least one companion client is connected.

func (*Server) OnTurnComplete

func (s *Server) OnTurnComplete(cb TurnCallback)

OnTurnComplete registers a callback that fires after each agent turn.

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(method string, handler RPCHandler)

RegisterHandler registers an RPC method handler

func (*Server) RequestApproval

func (s *Server) RequestApproval(ctx context.Context, message string) (approval.ApprovalResponse, error)

RequestApproval broadcasts an approval request to companions and waits for response.

func (*Server) Router

func (s *Server) Router() chi.Router

Router returns the underlying chi.Router for mounting additional routes.

func (*Server) SetAgent

func (s *Server) SetAgent(agent *adk.Agent)

SetAgent sets the agent on the server (used for deferred wiring).

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server

func (*Server) Start

func (s *Server) Start() error

Start starts the gateway server

type TurnCallback

type TurnCallback func(sessionKey string)

TurnCallback is called after each agent turn completes (for buffer triggers, etc).

Jump to

Keyboard shortcuts

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