remote

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 18 Imported by: 0

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

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.

func WithAssetCache

func WithAssetCache(next http.Handler) http.Handler

WithAssetCache wraps the shared asset handler with remote-only caching and conditional gzip (see assetCache doc for the invariants).

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 New

func New(opts Options) *Server

New creates a remote server. It does not listen until Start.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the listen address, or "" when not running.

func (*Server) GeneratePairingCode

func (s *Server) GeneratePairingCode() (code string, sid string, expires time.Time)

GeneratePairingCode replaces any active attempt with a fresh {sid, code} pair. Called from the settings UI binding only.

func (*Server) ListSessions

func (s *Server) ListSessions() []Session

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

func (s *Server) RevokeSession(id string) bool

RevokeSession kicks one device by session id.

func (*Server) Running

func (s *Server) Running() (bool, int)

Running reports whether the listener is up, plus its port.

func (*Server) Start

func (s *Server) Start(port int) error

Start begins listening on 0.0.0.0:port. Restarting while running is an error (stop first). Event bridge subscriptions are registered here and removed on Stop.

func (*Server) Stop

func (s *Server) Stop()

Stop shuts the listener and the hub down. Idempotent.

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

type SessionStore interface {
	LoadSessions() string
	SaveSessions(blob string)
}

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

Jump to

Keyboard shortcuts

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