Documentation
¶
Overview ¶
Package station is the model Vibium Station's packages share: rigs, devices, holds, principals and scopes, and the five interfaces an embedding application implements. Station's code never names a kind of device; what a rig offers is data.
Index ¶
- Constants
- Variables
- func DeviceID(rigID, name string) string
- func HasScope(scopes []Scope, s Scope) bool
- func NewID(prefix string) string
- func ScopeStrings(scopes []Scope) []string
- func SplitDeviceID(id string) (rigID, name string, ok bool)
- type Access
- type Action
- type AuditEntry
- type AuditSink
- type Authenticator
- type Authorizer
- type Blob
- type BlobIndex
- type BlobQuery
- type Device
- type DeviceStore
- type EventStore
- type Hold
- type HoldStore
- type Invite
- type Jam
- type JamEvent
- type Level
- type Principal
- type Rig
- type Scope
- type Shortcut
- type TagCount
- type Team
- type TokenLevel
- type User
- type UserStore
Constants ¶
const ( CapVideo = "video" CapAudio = "audio" CapHID = "hid" CapBidi = "bidi" CapMJPEG = "mjpeg" )
Capabilities a device can announce.
const OwnerLogin = "owner"
OwnerLogin is the login of the first admin, whose password `station passwd` sets.
Variables ¶
var ( ErrUnauthenticated = errors.New("not signed in") ErrForbidden = errors.New("not allowed") ErrNotFound = errors.New("not found") ErrNoHold = errors.New("no hold") )
Errors the interfaces return.
var AllScopes = []Scope{ScopeView, ScopeInput, ScopeBidi, ScopeAdmin}
AllScopes lists the scopes in their canonical order.
Functions ¶
func ScopeStrings ¶
ScopeStrings is the list as strings, for tags and JSON.
func SplitDeviceID ¶
SplitDeviceID takes a device id apart.
Types ¶
type Access ¶
type Access struct {
DeviceID string `json:"device"`
TeamID string `json:"team"`
Level Level `json:"level"`
}
Access is one team's level on one device.
type Action ¶
type Action string
Action is what a principal wants to do, for the Authorizer.
const ( ActionView Action = "view" // open the viewer, screenshots, status ActionControl Action = "control" // take a hold with input ActionBidi Action = "bidi" // drive the device with an agent ActionAdmin Action = "admin" // the device's admin endpoints ActionManage Action = "manage" // enroll and remove rigs, codes, tokens )
type AuditEntry ¶
type AuditEntry struct {
At time.Time
Subject string
Action string
DeviceID string
HoldID string
Detail string
}
AuditEntry is one thing that happened.
type AuditSink ¶
type AuditSink interface {
Audit(ctx context.Context, e AuditEntry)
}
AuditSink receives audit entries.
type Authenticator ¶
Authenticator says who a request comes from.
type Authorizer ¶
type Authorizer interface {
Authorize(ctx context.Context, p Principal, action Action, deviceID string) error
}
Authorizer says whether a principal may do an action to a device (deviceID is empty for ActionManage).
type Blob ¶
type Blob struct {
SHA256 string
Size int64
Type string // the media type
Name string // a file name hint, such as record.zip
Uploader string // "owner", "token:<name>", a login, or "rig:<rig id>"
User string // the id of the user behind the uploader, when a person or their token uploaded it
PubKey string // hex: the key that signed the upload
HoldID string
DeviceID string
RigID string
EventID string // the file event (kind 1063) the station signed for it
Public bool // readable without any authorization
CreatedAt time.Time
// What a recording holds, read once when it is unpacked: its steps,
// its frames, how long it ran, and the file of its last frame.
Steps int
Frames int
Duration time.Duration
Thumb string
// Golden marks a record worth keeping in view, the station's word
// for a pin or a bookmark; Tags are the words people filed it under.
Golden bool
Tags []string
}
Blob is a file in the Record Store, named by its SHA-256: a session recording, a screenshot, a log. The bytes live in a blob store; this is what the station knows about them.
type BlobIndex ¶
type BlobIndex interface {
PutBlob(ctx context.Context, b Blob) error
Blob(ctx context.Context, sha256 string) (Blob, error)
Blobs(ctx context.Context, q BlobQuery) ([]Blob, error)
DeleteBlob(ctx context.Context, sha256 string) error
SetBlobPublic(ctx context.Context, sha256 string, public bool) error
SetBlobGolden(ctx context.Context, sha256 string, golden bool) error
// SetBlobTags replaces a blob's tags.
SetBlobTags(ctx context.Context, sha256 string, tags []string) error
// BlobTagCounts lists the tags in use, most used first.
BlobTagCounts(ctx context.Context) ([]TagCount, error)
// BlobTotal is how many blobs the index holds and their size in bytes.
BlobTotal(ctx context.Context) (count int, size int64, err error)
}
BlobIndex is the Record Store's index of what the blob store holds.
type BlobQuery ¶
type BlobQuery struct {
DeviceID string
HoldID string
PubKey string
Before time.Time // only blobs stored before this time
OldestFirst bool
Limit int
// Text keeps the blobs whose name, type, uploader, hold, device,
// rig, hash or tags contain every word of it; Tags those carrying
// every tag named; Golden the golden ones.
Text string
Tags []string
Golden bool
}
BlobQuery narrows a listing of blobs; the zero value lists them all, newest first.
type Device ¶
type Device struct {
ID string `json:"id"` // "<rig id>/<name>"
Kind string `json:"kind"` // "phone", "browser", ...
Caps []string `json:"caps"` // see the Cap constants
Key string `json:"key,omitempty"` // hex public key, when the device has its own
Shortcuts []Shortcut `json:"shortcuts,omitempty"`
// Input is how the device is best driven, "touch" or "mouse": the
// viewer's pointer mode until the person picks one. Empty leaves it
// to the viewer.
Input string `json:"input,omitempty"`
// Extras is the path on the rig of a script that adds the device's
// own buttons and panels to the shared viewer; empty when none.
Extras string `json:"extras,omitempty"`
// Label is the device's name for people, such as "Dev iPhone 15",
// when the id's name ("phone") is not one. Empty shows the name.
Label string `json:"label,omitempty"`
// Platform is what the device runs: "ios", "android", "macos",
// "windows", "linux", or empty when the kind says enough.
Platform string `json:"platform,omitempty"`
// Model is the device's model name, such as "iPhone 15 Pro Max",
// and OSVersion the version of what it runs, such as "26.6", both
// as the rig was told; empty when it was not.
Model string `json:"model,omitempty"`
OSVersion string `json:"os_version,omitempty"`
}
Device is one thing a rig offers.
type DeviceStore ¶
type DeviceStore interface {
Rigs(ctx context.Context) ([]Rig, error)
Rig(ctx context.Context, id string) (Rig, error)
RigByKey(ctx context.Context, pk nostr.PubKey) (Rig, error)
PutRig(ctx context.Context, rig Rig) error
RemoveRig(ctx context.Context, id string) error
// SetDevices replaces a rig's devices with what it last announced.
SetDevices(ctx context.Context, rigID string, devices []Device) error
Device(ctx context.Context, id string) (Device, error)
}
DeviceStore holds rigs and their devices.
type EventStore ¶
type EventStore = eventstore.Store
EventStore keeps every event the station signs or accepts, verbatim. It is khatru's event-store interface, so the same store can back a relay later without a migration.
type Hold ¶
type Hold struct {
ID string
DeviceID string
RigID string
Seq uint64
Subject string
Scopes []Scope
CreatedAt time.Time
ActiveAt time.Time // the last refresh or input
ExpiresAt time.Time // the hard end
ReleasedAt time.Time // zero while held
}
Hold is control of one device by one subject, numbered per device so a newer hold always wins on the rig.
type HoldStore ¶
type HoldStore interface {
// Current is the hold held on a device, or ErrNoHold.
Current(ctx context.Context, deviceID string) (Hold, error)
// Create stores a new hold with the device's next sequence number and
// returns it with Seq set.
Create(ctx context.Context, hold Hold) (Hold, error)
Hold(ctx context.Context, id string) (Hold, error)
Touch(ctx context.Context, id string, at time.Time) error
Release(ctx context.Context, id string, at time.Time) error
// Held lists every hold still held.
Held(ctx context.Context) ([]Hold, error)
}
HoldStore holds holds and each device's sequence counter.
type Invite ¶
Invite is a setup link: one user's single-use way to choose a password and set up an authenticator, good until it expires.
type Jam ¶
type Jam struct {
ID string `json:"id"`
Subject string `json:"subject"` // who started it
DeviceID string `json:"device"` // "<rig id>/<name>"
Model string `json:"model"` // the agent model's name on Settings
Prompt string `json:"prompt"` // the first prompt
Title string `json:"title,omitempty"` // a few words for the prompt, from the model; empty until it answers
Mode string `json:"mode"` // "check", "run", or "" when the model picks
Status string `json:"status"` // running, done, stopped, failed
Took string `json:"took"` // "check" or "run", once the model has chosen
Result string `json:"result"` // passed, failed, inconclusive, completed, not_completed
Summary string `json:"summary"` // the model's explanation of the result
HoldID string `json:"hold"` // the hold the jam drove the device on
Actions int `json:"actions"` // tool calls made
TokensIn int `json:"tokens_in"`
TokensOut int `json:"tokens_out"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"created"`
EndedAt time.Time `json:"ended,omitempty"`
}
Jam is one jam session: a prompt a person typed on the station, driven on a device by a model through the station's own loop. See docs/specs/jams.md.
type JamEvent ¶
type JamEvent struct {
JamID string `json:"-"`
Seq int `json:"seq"`
At time.Time `json:"at"`
Kind string `json:"kind"`
Data json.RawMessage `json:"data"`
}
JamEvent is one step of a jam as the page shows it and the transcript keeps it: a prompt, the model's text, a tool call and its result, a screenshot, the verdict, an error, the end.
type Level ¶
type Level string
Level is what a team may do with a device: watch it, drive it, or also start jams and agents on it. Each level includes the ones before; the empty level is no access.
func ParseLevel ¶
ParseLevel reads a level's name; "" and "none" are no access.
type Principal ¶
type Principal struct {
Subject string // "owner", "token:<name>", or a login such as you@example.com
ReadOnly bool // may view, never control
Admin bool // sees and manages everything; a regular user sees what their teams are given
// Token is the token's level when the principal is one, "" for a
// person: watch (read only), drive (everything on devices, jams and
// agents included), or admin (the station's management too).
Token TokenLevel
// Device, when set, is the one device the principal may act on: a
// token minted for a jam carries the jam's device.
Device string
// User is the id of the user behind the principal, a person signed
// in or the owner of a token, and Teams the ids of the teams they
// are in, which decide what a regular user may see and do.
User string
Teams []string
// Expires is when that user's account expires, zero for never: no
// hold taken for them lasts past it.
Expires time.Time
}
Principal is who a request comes from, as the Authenticator saw it.
type Scope ¶
type Scope string
Scope is what a hold grant allows on a device.
func ParseScopes ¶
ParseScopes parses a list, refusing unknown and repeated scopes.
type Shortcut ¶
Shortcut is a toolbar button the device's provider asks the shared viewer to show: a label and the key chord to send, in the viewer's key syntax ("GUI+h").
type Team ¶
type Team struct {
ID string `json:"id"`
Name string `json:"name"`
Members []string `json:"members,omitempty"` // user ids
CreatedAt time.Time `json:"created"`
}
Team groups users; devices are shared with teams.
type TokenLevel ¶
type TokenLevel string
TokenLevel is what an API token may do, within what its user may: watch (read only), drive (hold and drive devices, start jams and run agents, as the user's teams allow), or admin (manage the station as well, for an admin's token). Most tokens are drive.
const ( TokenWatch TokenLevel = "watch" TokenDrive TokenLevel = "drive" TokenAdmin TokenLevel = "admin" )
func ParseTokenLevel ¶
func ParseTokenLevel(s string) (TokenLevel, error)
ParseTokenLevel reads a token level's name; "" is drive.
type User ¶
type User struct {
ID string `json:"id"`
Login string `json:"login"` // lowercased; an email address as a rule
Name string `json:"name,omitempty"`
Admin bool `json:"admin"`
Locked bool `json:"locked,omitempty"` // cannot sign in; sessions and tokens stop
CreatedAt time.Time `json:"created"`
LastLogin time.Time `json:"last_login,omitempty"`
Teams []string `json:"teams,omitempty"` // team ids
// How they sign in by password: whether one is set, and whether an
// authenticator confirmed since.
HasPassword bool `json:"has_password"`
TwoFactor bool `json:"two_factor"`
TwoFactorAt time.Time `json:"two_factor_at,omitempty"`
// ExpiresAt, when set, is when the account stops working on its own,
// as if locked then: for a trial or a demo. An admin can move it.
ExpiresAt time.Time `json:"expires,omitzero"`
}
User is someone who signs in: an admin, who sees and manages everything, or a regular user, who sees what their teams are given.
type UserStore ¶
type UserStore interface {
Users(ctx context.Context) ([]User, error)
User(ctx context.Context, id string) (User, error)
UserByLogin(ctx context.Context, login string) (User, error)
// PutUser creates a user, or updates everything but the password,
// the second factor and the teams of one that exists.
PutUser(ctx context.Context, u User) error
RemoveUser(ctx context.Context, id string) error
SetPassword(ctx context.Context, id, hash string) error
PasswordHash(ctx context.Context, id string) (string, error)
TouchUser(ctx context.Context, id string, at time.Time) error
// The second factor: an authenticator secret once a code confirmed
// it, the last time step a code was accepted for, and backup codes
// kept as hashes, each good once.
SetSecondFactor(ctx context.Context, id, secret string, at time.Time) error
SecondFactor(ctx context.Context, id string) (secret string, lastStep int64, err error)
// AcceptStep remembers a step a code was accepted for, and says no
// when one at or after it was already used.
AcceptStep(ctx context.Context, id string, step int64) (bool, error)
SetBackupCodes(ctx context.Context, id string, hashes []string) error
UseBackupCode(ctx context.Context, id, hash string) (left int, ok bool, err error)
BackupCodesLeft(ctx context.Context, id string) (int, error)
// ResetSignIn forgets a user's password, authenticator and backup codes.
ResetSignIn(ctx context.Context, id string) error
// Setup links, kept as hashes; a user has at most one open.
PutInvite(ctx context.Context, hash string, inv Invite) error
Invite(ctx context.Context, hash string, now time.Time) (Invite, error)
UseInvite(ctx context.Context, hash string) error
OpenInvites(ctx context.Context, now time.Time) (map[string]time.Time, error)
Teams(ctx context.Context) ([]Team, error)
PutTeam(ctx context.Context, t Team) error
RemoveTeam(ctx context.Context, id string) error
SetMember(ctx context.Context, teamID, userID string, in bool) error
Accesses(ctx context.Context) ([]Access, error)
// SetAccess sets a team's level on a device; LevelNone takes it away.
SetAccess(ctx context.Context, a Access) error
// LevelFor is the highest level any of the teams has on the device.
LevelFor(ctx context.Context, teams []string, deviceID string) (Level, error)
// BestLevel is the highest level any of the teams has on any device.
BestLevel(ctx context.Context, teams []string) (Level, error)
}
UserStore keeps users, teams, and what teams may do with devices.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package blob keeps files by their SHA-256, the way Blossom addresses them: a file is stored once under its hash, and the hash is checked as the bytes come in, so a store never holds a file under a name that does not match it.
|
Package blob keeps files by their SHA-256, the way Blossom addresses them: a file is stored once under its hash, and the hash is checked as the bytes come in, so a store never holds a file under a name that does not match it. |
|
cmd
|
|
|
station
command
Command station is Vibium Station for one owner: enroll your rigs, sign in with a password or your tailnet identity, and open any device's viewer.
|
Command station is Vibium Station for one owner: enroll your rigs, sign in with a password or your tailnet identity, and open any device's viewer. |
|
station-linecheck
command
Command station-linecheck checks a station from outside, the way a browser would: it signs in with an API token, holds a device, connects over WebRTC through TURN only (unless told otherwise), measures what arrives, taps the screen and confirms the screenshot changed, and releases the hold.
|
Command station-linecheck checks a station from outside, the way a browser would: it signs in with an API token, holds a device, connects over WebRTC through TURN only (unless told otherwise), measures what arrives, taps the screen and confirms the screenshot changed, and releases the hold. |
|
Package enroll is the station's side of a rig joining it: one-time codes that carry the station key's fingerprint, the /v1/station profile the rig checks that fingerprint against, the /v1/enroll endpoint, and mDNS so a rig on the LAN finds the station without a URL.
|
Package enroll is the station's side of a rig joining it: one-time codes that carry the station key's fingerprint, the /v1/station profile the rig checks that fingerprint against, the /v1/enroll endpoint, and mDNS so a rig on the LAN finds the station without a URL. |
|
Package hold hands out control of devices: one hold per device, numbered so the rig can always tell the newer one, with takeover by input scope, observers on the holder's hold, and release after idle or maximum time.
|
Package hold hands out control of devices: one hold per device, numbered so the rig can always tell the newer one, with takeover by input scope, observers on the holder's hold, and release after idle or maximum time. |
|
Package jam is the station's own agent: a loop that drives a device through Vibium's tools for a prompt typed on the station, with a model the owner set up.
|
Package jam is the station's own agent: a loop that drives a device through Vibium's tools for a prompt typed on the station, with a model the owner set up. |
|
Package records is the Record Store: session recordings, screenshots and logs kept as Blossom blobs, each named by its SHA-256, uploaded with a signed authorization and listed per device and hold.
|
Package records is the Record Store: session recordings, screenshots and logs kept as Blossom blobs, each named by its SHA-256, uploaded with a signed authorization and listed per device and hold. |
|
Package relay forwards HTTP to a rig over its tunnel: the station's reverse proxy for signaling now, and for REST, BiDi, MJPEG and the fallback WebSockets later.
|
Package relay forwards HTTP to a rig over its tunnel: the station's reverse proxy for signaling now, and for REST, BiDi, MJPEG and the fallback WebSockets later. |
|
Package rig is what a machine needs to be a rig: its key, the policy file naming the stations it accepts, enrollment, the tunnel to each station, and the gate every relayed request passes: the grant check with the hold state, and the endpoint allowlist.
|
Package rig is what a machine needs to be a rig: its key, the policy file naming the stations it accepts, enrollment, the tunnel to each station, and the gate every relayed request passes: the grant check with the hold state, and the endpoint allowlist. |
|
Package sdnotify tells systemd how a service is doing, over the socket systemd names in NOTIFY_SOCKET: that it is ready, that it is still alive (the watchdog) and that it is stopping.
|
Package sdnotify tells systemd how a service is doing, over the socket systemd names in NOTIFY_SOCKET: that it is ready, that it is still alive (the watchdog) and that it is stopping. |
|
Package signal is the viewer's signaling endpoint on the station, /v1/devices/{id}/signal: a WebSocket relayed over the rig's tunnel to the rig's own signaling handler.
|
Package signal is the viewer's signaling endpoint on the station, /v1/devices/{id}/signal: a WebSocket relayed over the rig's tunnel to the rig's own signaling handler. |
|
Package sqlite is Station's storage: one SQLite file holding the event store, rigs and devices, holds, the Record Store's index, API tokens, enrollment codes and the audit log.
|
Package sqlite is Station's storage: one SQLite file holding the event store, rigs and devices, holds, the Record Store's index, API tokens, enrollment codes and the audit log. |
|
Package token builds and checks Station's signed events: hold grants, revocations and the handshake events, in the Nostr event format with the kinds in docs/kinds.md.
|
Package token builds and checks Station's signed events: hold grants, revocations and the handshake events, in the Nostr event format with the kinds in docs/kinds.md. |
|
Package tunnel is the rig's one outbound connection to its station: a WebSocket at /v1/tunnel, opened by the rig, authenticated by signing the station's challenge, then multiplexed with yamux.
|
Package tunnel is the rig's one outbound connection to its station: a WebSocket at /v1/tunnel, opened by the rig, authenticated by signing the station's challenge, then multiplexed with yamux. |
|
Package turn is the station's embedded TURN server: pion/turn with one job, carrying a session's media when the browser and the rig cannot reach each other directly.
|
Package turn is the station's embedded TURN server: pion/turn with one job, carrying a session's media when the browser and the rig cannot reach each other directly. |
|
Package viewer is the browser side shared by a station and a Roadie host: one shell, with Roadie's look and all of its viewer's features, served by both, with the WebRTC transport module and the audio worklets.
|
Package viewer is the browser side shared by a station and a Roadie host: one shell, with Roadie's look and all of its viewer's features, served by both, with the WebRTC transport module and the audio worklets. |