Documentation
¶
Overview ¶
Package remote embeds an optional, token-authenticated HTTP server into the desktop process so that browsers / mobile clients can connect to the very same app instance while the GUI keeps running (AGENTS.md §1.8).
It deliberately exposes only the existing Wails3 protocol surface:
- "/" → frontend assets, wrapped by the SAME HTTPTransport binding middleware the webview uses (/wails/runtime dispatch). No second API is invented (§5.3 KISS).
- "/wails/events"→ WebSocket hub bridging app.Event.On subscriptions.
- "/wails/custom.js" → browser-side WS bootstrap (the desktop webview gets a 404 for this path and the bundled runtime skips it silently, so the webview never opens a second event channel).
Auth: cookie (browsers: fetch + WS upgrade carry same-origin cookies) or "Authorization: Bearer <token>" (native clients). Only /health and /auth are exempt. The binding surface equals full agent control (bash execution), so unauthenticated exposure is never acceptable.
Index ¶
- func LanAddresses() []string
- func WithAssetCache(next http.Handler) http.Handler
- type Options
- type Server
- func (s *Server) Addr() string
- func (s *Server) GeneratePairingCode() (code string, sid string, expires time.Time)
- func (s *Server) ListSessions() []Session
- func (s *Server) RevokeAllSessions()
- func (s *Server) RevokeSession(id string) bool
- func (s *Server) Running() (bool, int)
- func (s *Server) Start(port int) error
- func (s *Server) Stop()
- type Session
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LanAddresses ¶
func LanAddresses() []string
LanAddresses lists non-loopback IPv4 addresses of this machine, used to render connect URLs in the settings UI.
Types ¶
type Options ¶
type Options struct {
Transport transportHandler
Assets http.Handler
Token func() string // current token, read per request (regeneration applies live)
EventNames []string // closed set of events bridged to remote clients
Sessions SessionStore // per-device session persistence (nil = memory only)
Logger *slog.Logger
}
Options wires the remote server to the live app. Transport and Assets must be the very instances used for the webview path (single dispatch chain).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server owns the embedded HTTP listener. Zero value is not usable; use New.
func (*Server) GeneratePairingCode ¶
GeneratePairingCode replaces any active attempt with a fresh {sid, code} pair. Called from the settings UI binding only.
func (*Server) ListSessions ¶
ListSessions snapshots the paired-device sessions (newest first).
func (*Server) RevokeAllSessions ¶
func (s *Server) RevokeAllSessions()
RevokeAllSessions is the token-regeneration kill switch: every paired device dies with the old token.
func (*Server) RevokeSession ¶
RevokeSession kicks one device by session id.
type Session ¶
type Session struct {
ID string `json:"id"`
Label string `json:"label"` // UA-derived, e.g. "iPhone · Safari"
CreatedAt time.Time `json:"createdAt"` // pairing time
LastSeen time.Time `json:"lastSeen"` // throttled request touch
}
Session is one paired device.
type SessionStore ¶
SessionStore persists the session list (JSON blob) — implemented by the chat service over the settings KV table; nil disables persistence (sessions then live only for the process lifetime).