Documentation
¶
Overview ¶
Package ui is the agentscope screen: a ViewModel that holds ALL state as go-widgets/mvvm primitives and never references a widget, and a View (scene.go) that builds toolkit widgets and binds them to it. Both are tagless, so a native `go test` covers them; the browser host is cmd/agentscope-web.
Index ¶
- Constants
- Variables
- func AccountOptions(u *model.Usage) []string
- func Palette(dark bool) []toolkit.RGBA
- func RepoLabel(key string, max int) string
- func StackColors(dark bool) []toolkit.RGBA
- func Tokens(v float64) string
- type CapRow
- type Row
- type Scene
- func (s *Scene) Dirty() bool
- func (s *Scene) Draw(buf []byte)
- func (s *Scene) HandleChar(ch string) bool
- func (s *Scene) HandleClick(x, y int) bool
- func (s *Scene) HandleKeyDown(code string) bool
- func (s *Scene) HandleMove(x, y int) bool
- func (s *Scene) HandleRelease(x, y int) bool
- func (s *Scene) HandleScroll(x, y, delta int) bool
- func (s *Scene) PanelVisible() bool
- func (s *Scene) Resize(w, h int, scale float64)
- func (s *Scene) Size() (w, h int)
- func (s *Scene) VM() *ViewModel
- type ViewModel
Constants ¶
const ( // MaxGraphSessions is how many session clusters are drawn, newest first. MaxGraphSessions = 64 // MaxGraphAgents is how many sub-agent nodes a session cluster shows; the // rest are one "+N more" node. MaxGraphAgents = 6 // MaxGraphRepos is how many repositories the "other repositories" cluster // shows (held repositories are always drawn, inside their holder). MaxGraphRepos = 200 // NodeWidth is the width of a node box, and NodeChars the number of // characters a label is cut to so that it fits in it. NodeWidth = 170 NodeChars = 22 )
The GraphView sizes each cluster by its own members and scrolls when they overflow, so these are safety bounds on what is drawn, not a fit to the screen. They are the screen's, not the collector's: the table and the detail pane list everything.
const ( SpanShort = iota // the 5 hour window SpanWeek // the 7 day window SpanWeeks // four 7 day windows, aligned on the weekly reset )
The spans the Quota tab can show, in the order of the selector.
const ( KindOutput = iota KindCacheRead )
The token kinds the weeks view can show, in the order of the selector.
const ( DefaultW = 1280 DefaultH = 800 )
DefaultW and DefaultH are the size a Scene has before the host tells it the viewport's.
const ( TabGraph = iota TabQuota )
The tabs.
const AllAccounts = "All (aggregated)"
AllAccounts is the first option of the account selector: every account, aggregated.
const ModelChipSlots = 3
ModelChipSlots is how many model families the header shows chips for.
Variables ¶
var ( SpanNames = []string{"5 h", "7 days", "4 x 7 days"} KindNames = []string{"output", "cache read"} )
SpanNames and KindNames label the selectors.
var Brand = toolkit.RGB(0x00, 0x79, 0xA8)
Brand is agentscope's accent: the go-authn account page's brand colour.
Functions ¶
func AccountOptions ¶ added in v0.8.0
AccountOptions are the selector's options: All, then every account, the active one marked.
func Palette ¶ added in v0.6.0
Palette is the graph's category palette: the Okabe-Ito order, which is safe under the common colour-vision deficiencies, with its lightness tuned to the page: eased toward the Slate ground in light, lifted a little in dark so a pill keeps its contrast against the dark card. The order is what the legend and the colour assignment (by first appearance) rely on, so it is never reordered.
func RepoLabel ¶ added in v0.3.0
RepoLabel is org/repo cut to at most max characters. When it does not fit, the ORG is shortened (with an ellipsis) and the repo is kept whole; only a repo name longer than the room itself is cut.
func StackColors ¶ added in v0.7.0
StackColors are the families' colours, in the order of model.Usage.Families: four of the Okabe-Ito set, which stays apart under colour-vision deficiency.
Types ¶
type CapRow ¶ added in v0.8.0
type CapRow struct {
Account, Session, Weekly, Left, Resets, Active string
}
CapRow is one line of the capacity table.
type Row ¶
type Row struct {
ID string // session short id
State string
Repo string
Task string
Last string
Agent string // sub-agent count
Model string // short family name ("Opus 5.5"), or "?" when unknown or unseen
}
Row is one line of the sessions table.
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene is the View: the widgets, their layout, and the bindings to the ViewModel. It never assigns a widget's state field itself, and draws nothing by hand: every surface is a toolkit widget (Frame cards, Chips, the graph, the charts, the side panel in a toolkit Overlay).
func (*Scene) HandleChar ¶
HandleChar routes a printable character to the focused widget; "t" outside the search box toggles the side panel.
func (*Scene) HandleClick ¶
HandleClick dispatches a click at surface (x, y) to the widget under it. A click on the open panel never reaches the graph beneath it.
func (*Scene) HandleKeyDown ¶
HandleKeyDown routes a named key to the focused widget.
func (*Scene) HandleMove ¶
HandleMove routes pointer motion to the widget grabbed on press.
func (*Scene) HandleRelease ¶
HandleRelease routes a button release to the grabbed widget and drops it.
func (*Scene) HandleScroll ¶
HandleScroll routes a wheel scroll (Delta in rows, positive = down) to the scrollable under the pointer.
func (*Scene) PanelVisible ¶ added in v0.7.0
PanelVisible is whether the side panel is on screen: open, over the graph.
func (*Scene) Resize ¶ added in v0.7.0
Resize makes the scene w by h device pixels at the given device pixel ratio and lays it out again: the graph takes every pixel the header and the tabs do not, and its clusters flow into as many columns as the width holds. A resize may re-lay-out the graph; an edge update never does.
type ViewModel ¶
type ViewModel struct {
// Graph is what the GraphView shows; its Selected and Filter are the
// widget's own observables.
Graph *toolkit.GraphViewModel
// Query is the search entry's text. It dims the graph (Graph.Filter) and
// narrows the table.
Query *mvvm.Observable[string]
// Rows is the sessions table; TableSel is its selected row index.
Rows *mvvm.ObservableList[Row]
TableSel *mvvm.Observable[int]
// Detail is the detail pane: the selection's facts, or the anomalies when
// nothing is selected.
Detail *mvvm.ObservableList[string]
// Status is the one-line summary; Conn is the connection state.
Status *mvvm.Observable[string]
Conn *mvvm.Observable[string]
// ShowExpired draws the edges to a selected session's expired leases
// (hidden by default: the detail pane lists them). Expanded is the orgs of
// the "other repositories" cluster that are open.
ShowExpired *mvvm.Observable[bool]
Expanded *mvvm.ObservableList[string]
// Dark is the system's colour-scheme preference, set by the host (a
// browser's prefers-color-scheme) and followed when it changes.
Dark *mvvm.Observable[bool]
// ModelChips are the header's model-count chips: the three most used model
// families ("Sonnet 29"), "" for a slot with none.
ModelChips [ModelChipSlots]*mvvm.Observable[string]
// Tab is the shown tab: TabGraph or TabQuota.
Tab *mvvm.Observable[int]
// PanelOpen is whether the side panel (the sessions table and the details)
// is open over the graph; it starts closed, TogglePanel flips it, and
// selecting a node opens it.
PanelOpen *mvvm.Observable[bool]
TogglePanel *mvvm.Command
// Span is the Quota tab's span (SpanShort, SpanWeek, SpanWeeks) and Kind the
// token kind its 4 x 7 days charts show.
Span, Kind *mvvm.Observable[int]
// Usage is the Quota tab's data, from the last snapshot.
Usage *mvvm.Observable[*model.Usage]
// QuotaNotes is the line under the Quota charts: what is not available, what
// is not recorded, where the reset came from.
QuotaNotes *mvvm.Observable[string]
// Account is the account selector's choice: 0 is AllAccounts, i is the i-th
// account of the usage. AccountOptions are its options and Capacity the
// capacity table's rows, both rebuilt when the usage changes; the selection
// follows its account (by key) across a rebuild.
Account *mvvm.Observable[int]
AccountOptions *mvvm.ObservableList[string]
Capacity *mvvm.ObservableList[CapRow]
// contains filtered or unexported fields
}
ViewModel is the whole screen's state.
func NewViewModel ¶
func NewViewModel() *ViewModel
NewViewModel returns a ViewModel showing nothing yet.
func (*ViewModel) Apply ¶
Apply shows a snapshot. A list is replaced only when it differs, so a graph whose members did not change does not lay itself out again.
func (*ViewModel) CollapseAll ¶ added in v0.4.0
func (vm *ViewModel) CollapseAll()
CollapseAll folds every org again (Escape).