platform

package
v0.9.0-rc Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package platform implements the WebSocket endpoint for native platform provider connections (e.g. macOS app). Providers connect inward and register capabilities that the server can invoke via platform requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallRequest

type CallRequest struct {
	Account    string
	ClientID   string
	Capability string
	Method     string
	Params     json.RawMessage
}

CallRequest describes a routed request to a connected platform provider.

type Capability

type Capability struct {
	Name    string   `json:"name"`
	Version string   `json:"version,omitempty"`
	Methods []string `json:"methods,omitempty"`
}

Capability describes a platform capability exposed by a connected provider, along with the methods it supports.

type Error

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

Error carries structured error information in message responses.

type Handler

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

Handler is the HTTP handler for platform provider WebSocket connections.

func NewHandler

func NewHandler(tokenIndex map[string]string, registry *Registry, logger *slog.Logger) *Handler

NewHandler creates a new platform WebSocket handler. The tokenIndex maps authentication tokens to account names (built by config.PlatformConfig.TokenIndex). If registry is nil, a default Registry is created.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades the connection to WebSocket, performs the auth handshake, and runs the heartbeat and read loops for the provider.

type Message

type Message struct {
	ID      int64           `json:"id,omitempty"`
	Type    string          `json:"type"`
	Success bool            `json:"success,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Message is the generic WebSocket message envelope used for post-auth communication (pong, future request/response). The auth handshake uses dedicated structs (authRequired, authMessage, authOK, authFailed, ping).

type Provider

type Provider struct {
	ID          string
	Account     string
	ClientName  string
	ClientID    string
	Conn        *websocket.Conn
	ConnectedAt time.Time
	// contains filtered or unexported fields
}

Provider represents a connected platform provider (e.g. a macOS app instance). Account is the server-assigned identity resolved from the token at auth time.

type ProviderInfo

type ProviderInfo struct {
	ID           string       `json:"id"`
	Account      string       `json:"account"`
	ClientName   string       `json:"client_name"`
	ClientID     string       `json:"client_id"`
	ConnectedAt  time.Time    `json:"connected_at"`
	Capabilities []Capability `json:"capabilities,omitempty"`
}

ProviderInfo is a safe-to-export snapshot of a connected provider, without the WebSocket connection pointer.

type Registry

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

Registry tracks connected platform providers. It maintains a primary index by provider ID and a secondary index by account name for dispatching requests to the right identity.

func NewRegistry

func NewRegistry(logger *slog.Logger) *Registry

NewRegistry creates a new provider registry.

func (*Registry) Accounts

func (r *Registry) Accounts() []string

Accounts returns the names of all accounts that have at least one connected provider.

func (*Registry) Add

func (r *Registry) Add(p *Provider)

Add registers a provider in the registry.

func (*Registry) ByAccount

func (r *Registry) ByAccount(account string) []ProviderInfo

ByAccount returns snapshots of all providers connected under the given account name. Returns nil if no providers are connected for that account.

func (*Registry) Call

func (r *Registry) Call(ctx context.Context, req CallRequest) (json.RawMessage, error)

Call dispatches a request to a connected provider and waits for the corresponding result or context cancellation.

Call relies on the caller to provide a bounded context; it does not impose an additional timeout beyond ctx.Done() and provider disconnects.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of connected providers.

func (*Registry) List

func (r *Registry) List() []ProviderInfo

List returns a snapshot of all connected providers.

func (*Registry) RegisterCapabilities

func (r *Registry) RegisterCapabilities(providerID string, capabilities []Capability) error

RegisterCapabilities replaces the capability set registered for a provider.

func (*Registry) Remove

func (r *Registry) Remove(id string)

Remove unregisters a provider from the registry.

func (*Registry) ResolveResult

func (r *Registry) ResolveResult(providerID string, msg Message) bool

ResolveResult completes a pending call for the given provider.

Jump to

Keyboard shortcuts

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