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 ¶
- type CallRequest
- type Capability
- type Error
- type Handler
- type Message
- type Provider
- type ProviderInfo
- type Registry
- func (r *Registry) Accounts() []string
- func (r *Registry) Add(p *Provider)
- func (r *Registry) ByAccount(account string) []ProviderInfo
- func (r *Registry) Call(ctx context.Context, req CallRequest) (json.RawMessage, error)
- func (r *Registry) Count() int
- func (r *Registry) List() []ProviderInfo
- func (r *Registry) RegisterCapabilities(providerID string, capabilities []Capability) error
- func (r *Registry) Remove(id string)
- func (r *Registry) ResolveResult(providerID string, msg Message) bool
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 Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the HTTP handler for platform provider WebSocket connections.
func NewHandler ¶
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.
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 ¶
NewRegistry creates a new provider registry.
func (*Registry) Accounts ¶
Accounts returns the names of all accounts that have at least one connected provider.
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) 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.