proxy

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 61 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxy carries a person's browser to the runtime of a machine, through the machine's agent link (docs/hub/architecture.md, "Reaching a runtime through the hub").

The page a person gets is the runtime's own. The hub checks who they are (the hub session in path mode, the machine origin's own cookie in subdomain mode) and that they belong to the machine's space, asks the agent for a runtime session for them, and forwards each request through a tunnel with the browser's cookies replaced by that session. The browser never holds a runtime token, and nothing of the hub's own session reaches the machine.

Index

Constants

View Source
const HubChatGuestPrefix = "/guest/chat/"

HubChatGuestPrefix names the read-only transcript route on the configured Hub hostname.

View Source
const InboxNoticesPerHour = 20

InboxNoticesPerHour bounds what Inbox may ring one person with; a burst beyond it is refused, not queued.

View Source
const (

	// OutboxEvery is how often the hub looks for messages whose machine is back.
	OutboxEvery = 5 * time.Second
)
View Source
const SettingsCopyHeader = "X-Harnessly-Copy-At"

SettingsCopyHeader marks an answer given from the hub's copy of a machine's settings: when the machine gave them, in Unix milliseconds.

View Source
const StaleHeader = "X-Harnessly-Stale"

StaleHeader marks an answer the hub gave from its copy; the value is the age of the copy in seconds.

Variables

This section is empty.

Functions

func ReloadAsked added in v0.16.154

func ReloadAsked(r *http.Request) bool

ReloadAsked: a frame navigating to a page of the hub from a cross-site context. Nothing of the hub or of a machine is framed by another site (frame-ancestors), so this is a previewed page by path that reloaded past its prefix.

func ServeReload added in v0.16.154

func ServeReload(w http.ResponseWriter, r *http.Request)

ServeReload asks the pane to open the path again in the frame's slot; the page holds nothing of the hub.

The hub's own frame ban (securityHeaders: X-Frame-Options DENY on every path outside /m/ and /agents/) is lifted: this page is for a frame and holds nothing, and with the ban the browser showed «hub refused to connect» in place of the board whose page navigated to the library's address (/a/<project>/p/<board>) past its slot.

Types

type Anchor

type Anchor interface {
	AnchorMachines(ctx context.Context, spaceIDs []string, rest string) []string
}

Anchor names the machines that hold a hub route's project, newest first, so the route needs no ?machine=.

type Bell

type Bell func(ctx context.Context, userID, email, key, title, text, link string) bool

Bell rings a hub notice in a person's bell (noticehub.RingAs); it reports whether a new notice was put.

type ClientChat

type ClientChat struct {
	ID          string  `json:"id"`
	MachineID   string  `json:"machineId"`
	MachineName string  `json:"machineName"`
	Online      bool    `json:"online"`
	Title       string  `json:"title"`
	Project     string  `json:"project"`
	ProjectID   *string `json:"projectId"`
	Cwd         string  `json:"cwd"`
	Provider    string  `json:"provider"`
	Model       string  `json:"model"`
	// State is the agent's state (working, waiting-question, waiting-permission, ready, idle, stopped, …).
	State string `json:"state"`
	// Attention is why the chat waits for the person: "question", "permission", "plan", "unread" or "".
	Attention    string  `json:"attention"`
	Unread       bool    `json:"unread"`
	Pinned       bool    `json:"pinned"`
	Recap        *string `json:"recap"`
	Snippet      *string `json:"snippet"`
	LastTurn     *string `json:"lastTurnStatus"`
	Queue        int     `json:"queue"`
	Background   int     `json:"background"`
	From         string  `json:"from,omitempty"`
	Delegated    bool    `json:"delegated"`
	CreatedAt    int64   `json:"createdAt"`
	LastPromptAt int64   `json:"lastPromptAt"`
	ActivityAt   int64   `json:"activityAt"`
	URL          string  `json:"url"`
}

ClientChat is a chat as the client API lists it.

type Deps

type Deps struct {
	Config  *config.Config
	DB      *store.DB
	Auth    *auth.Service
	Spaces  *spaces.Service
	Reg     *link.Registry
	Tickets *ticket.Store
	Log     *slog.Logger
	// Now is the clock; nil means time.Now.
	Now func() time.Time
	// Design answers the design access API before a request would reach the machine; nil leaves it to the machine.
	Design Interceptor
	// Features says whether runtime.fleet is on for an organization (fleet.go); nil: off, the routes answer not found.
	Features FeatureGate
	// Workspace is the runtime's built page (web/dist): the hub serves it at /agents/ for the fleet (workspace.go). nil
	// leaves /agents/ to the hub's page.
	Workspace fs.FS
	// History: the workspace's chat history is read from the hub's copy (internal/hub/history, history.go); false leaves
	// it to the home machine.
	History bool
	// VoiceTakes: the person's dictation recordings are kept here (voicetakes.go); false answers 404.
	VoiceTakes bool
	// Fleet is the bus of the workspace page's live channel (fleet.go, GET /api/v2/machines/events); nil: there is none.
	Fleet *events.FleetBus
	// Switches are the rollout switches (stale.go, the «fleet-stale» switch); nil: all off. The owner\'s rule of opening a machine
	// (machaccess.FeatureOwnWork) is one of them.
	Switches switches.Gate
	// SlotKey signs the preview slot hosts' handles and cookies (slothost.go); with Config.PreviewSlotDomain it turns the
	// slot hosts on, still subject to the «preview-slot-host» rollout switch. nil: there are none.
	SlotKey []byte
	// Rollout answers GET /api/v2/rollout: whether a rollout is under way (internal/hub/rollout); nil answers «no».
	Rollout http.HandlerFunc
}

Deps are what the service is built from.

type FeatureGate added in v0.16.154

type FeatureGate interface {
	On(ctx context.Context, orgID, name string) bool
}

FeatureGate says whether an organization has a feature on (features.Gate).

type FleetMachine added in v0.16.154

type FleetMachine struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Host       string `json:"host"`
	Online     bool   `json:"online"`
	Status     string `json:"status"`
	LastSeenAt *int64 `json:"lastSeenAt"`
	OrgID      string `json:"orgId"`
	OrgName    string `json:"orgName"`
	TenantID   string `json:"tenantId"`
	Tenant     string `json:"tenant"`
	// Mine: the machine is the person's own (they added it, or it was assigned to them). The others are there because
	// the person administers their space or organization: they open them on purpose, their chats never join the
	// person's own list (docs/hub/machines.md, «Personal and administered machines»).
	Mine bool `json:"mine"`
}

FleetMachine is a machine of the person in any of their organizations.

type HomeServer

type HomeServer interface {
	ServeHome(w http.ResponseWriter, r *http.Request, u store.User, m store.Machine, ask func(ctx context.Context, w http.ResponseWriter)) bool
}

HomeServer answers Sinopia's home itself, asking the machine through ask and its store at once.

type Interceptor added in v0.16.154

type Interceptor interface {
	ServeMachine(w http.ResponseWriter, r *http.Request, u store.User, m store.Machine) bool
}

Interceptor answers some requests of a signed-in person to a machine itself; false lets them through to it.

type KeyedFiles

type KeyedFiles interface {
	KeyedFileUser(r *http.Request) string
}

KeyedFiles is the design service's side of a board's keyed address: whose live key a request for a file there carries, "" when it carries none.

type ProjectRow

type ProjectRow struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Directories []string `json:"directories"`
	MachineID   string   `json:"machineId"`
	MachineName string   `json:"machineName"`
	Mine        bool     `json:"mine"`
	// Asleep: the machine is not on; its projects are the registry's last word. Label says so in words.
	Asleep  bool   `json:"asleep"`
	Label   string `json:"label,omitempty"`
	OrgName string `json:"orgName,omitempty"`
}

ProjectRow is a project of a machine the person may open, as the sidebar «Проекты» shows it.

type Service

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

Service is the runtime proxy.

func New

func New(d Deps) *Service

New makes the proxy.

func (*Service) DeliverOutbox

func (s *Service) DeliverOutbox(ctx context.Context) int

DeliverOutbox is one pass: the messages of connected machines, every machine's own oldest first and one at a time, the machines side by side. It returns how many were delivered.

func (*Service) DeliverOutboxChats

func (s *Service) DeliverOutboxChats(ctx context.Context) int

DeliverOutboxChats is one pass: the waiting chats of connected machines, oldest first, one at a time, a machine that did not take one left for the next pass. It returns how many chats were made.

func (*Service) Forget

func (s *Service) Forget(id string)

Forget drops what the proxy holds for a machine: its idle tunnels and the sessions it asked for.

func (*Service) ForwardAs

func (s *Service) ForwardAs(w http.ResponseWriter, r *http.Request, u store.User, m store.Machine)

ForwardAs sends a request the hub made itself to the machine as the person u, the way their own would go (HRN-1799: a comment to the agent kept while the machine was off). path is the runtime's, without /m/<id>.

func (*Service) IsSlotHost

func (s *Service) IsSlotHost(host string) bool

IsSlotHost says whether host is a preview slot host of this hub.

func (*Service) Kick

func (s *Service) Kick(spaceID, userID string)

Kick ends what a person has open on the machines of a space (they were removed, or lost the right): requests in flight, sockets and terminals included, and the belief that they may come in.

func (*Service) Mount

func (s *Service) Mount(mux *http.ServeMux)

Mount registers the hub-origin side: /m/<id>/… (path mode runs it, subdomain mode sends people to the machine's own origin), plus the fullscreen browser's socket, which always stays on the hub's origin.

func (*Service) RunOutbox

func (s *Service) RunOutbox(ctx context.Context)

RunOutbox hands the waiting messages to machines that are back, every OutboxEvery, until ctx ends.

func (*Service) RunOutboxChats

func (s *Service) RunOutboxChats(ctx context.Context)

RunOutboxChats makes the waiting chats on machines that are back, every OutboxEvery, until ctx ends.

func (*Service) ServeGuestChatSnapshot

func (s *Service) ServeGuestChatSnapshot(w http.ResponseWriter, r *http.Request)

ServeGuestChatSnapshot serves the configured guest path without using browser credentials.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Service) ServeSlotHost

func (s *Service) ServeSlotHost(w http.ResponseWriter, r *http.Request)

ServeSlotHost answers a request to a preview slot host.

func (*Service) Transport added in v0.16.154

func (s *Service) Transport(id string) http.RoundTripper

Transport is the machine's HTTP client over its tunnels, for the hub's own requests to it.

func (*Service) UseBell

func (s *Service) UseBell(b Bell)

UseBell gives the proxy the person's bell for Inbox notices; without it the bell part is skipped.

func (*Service) UseDocs

func (s *Service) UseDocs(h http.Handler, prefix string)

UseDocs turns the hub's documents on for the workspace: h answers them under prefix (the documents' own platform API prefix). nil leaves /docs to the machines, as before.

func (*Service) UseUploads

func (s *Service) UseUploads(u Uploads)

UseUploads lets the workspace keep uploads in the hub's store; nil (no store) leaves them to the machines.

func (*Service) UseVault

func (s *Service) UseVault(v *vaultsvc.Service)

UseVault turns the hub's safe on; nil leaves /vault to the machines, as before.

func (*Service) Workspace

func (s *Service) Workspace() bool

Workspace: whether this hub serves the fleet's workspace at /agents/ (it was built with the runtime's page). Whether a person gets it is still the runtime.fleet flag of their spaces.

type Uploads

type Uploads interface {
	HasBlob(ctx context.Context, spaceID, kind, sha string) (bool, error)
	OpenBlob(ctx context.Context, spaceID, kind, sha string) (io.ReadCloser, error)
	PutBlob(ctx context.Context, spaceID, kind, sha string, r io.Reader) error
}

Uploads is the store's side the workspace needs (storehub.Store).

Jump to

Keyboard shortcuts

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