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
- func ReloadAsked(r *http.Request) bool
- func ServeReload(w http.ResponseWriter, r *http.Request)
- type Anchor
- type Bell
- type ClientChat
- type Deps
- type FeatureGate
- type FleetMachine
- type HomeServer
- type Interceptor
- type KeyedFiles
- type ProjectRow
- type Service
- func (s *Service) DeliverOutbox(ctx context.Context) int
- func (s *Service) DeliverOutboxChats(ctx context.Context) int
- func (s *Service) Forget(id string)
- func (s *Service) ForwardAs(w http.ResponseWriter, r *http.Request, u store.User, m store.Machine)
- func (s *Service) IsSlotHost(host string) bool
- func (s *Service) Kick(spaceID, userID string)
- func (s *Service) Mount(mux *http.ServeMux)
- func (s *Service) RunOutbox(ctx context.Context)
- func (s *Service) RunOutboxChats(ctx context.Context)
- func (s *Service) ServeGuestChatSnapshot(w http.ResponseWriter, r *http.Request)
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) ServeSlotHost(w http.ResponseWriter, r *http.Request)
- func (s *Service) Transport(id string) http.RoundTripper
- func (s *Service) UseBell(b Bell)
- func (s *Service) UseDocs(h http.Handler, prefix string)
- func (s *Service) UseUploads(u Uploads)
- func (s *Service) UseVault(v *vaultsvc.Service)
- func (s *Service) Workspace() bool
- type Uploads
Constants ¶
const HubChatGuestPrefix = "/guest/chat/"
HubChatGuestPrefix names the read-only transcript route on the configured Hub hostname.
const InboxNoticesPerHour = 20
InboxNoticesPerHour bounds what Inbox may ring one person with; a burst beyond it is refused, not queued.
const ( // OutboxEvery is how often the hub looks for messages whose machine is back. OutboxEvery = 5 * time.Second )
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.
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
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 ¶
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
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 ¶
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 (*Service) DeliverOutbox ¶
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 ¶
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 ¶
Forget drops what the proxy holds for a machine: its idle tunnels and the sessions it asked for.
func (*Service) ForwardAs ¶
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 ¶
IsSlotHost says whether host is a preview slot host of this hub.
func (*Service) Kick ¶
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 ¶
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 ¶
RunOutbox hands the waiting messages to machines that are back, every OutboxEvery, until ctx ends.
func (*Service) RunOutboxChats ¶
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) 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 ¶
UseBell gives the proxy the person's bell for Inbox notices; without it the bell part is skipped.
func (*Service) UseDocs ¶
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 ¶
UseUploads lets the workspace keep uploads in the hub's store; nil (no store) leaves them to the machines.
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).
Source Files
¶
- cards.go
- chatguest.go
- chatguest_render.go
- chatshares.go
- client_api.go
- deadline.go
- design_invite.go
- docs.go
- fleet.go
- history.go
- inbox_notice.go
- inbox_triage.go
- launch.go
- machinesettings.go
- move.go
- outbox.go
- outbox_chats.go
- personsettings.go
- preview.go
- projects.go
- proxy.go
- review_notes.go
- slothost.go
- stale.go
- uploads.go
- vault.go
- viewonly.go
- voicetakes.go
- workspace.go