Documentation
¶
Overview ¶
Package model is the wire and screen model of agentscope: one Snapshot is everything the UI shows, and it carries METADATA only -- ids, working directories resolved to repositories, tool names, agent descriptions, lease notes, tell texts and timestamps. Nothing here ever holds a prompt or a response; the collector never reads those fields (see package collect).
Index ¶
- Constants
- Variables
- func ModelFamily(id string) string
- func ModelLabel(id string) string
- func ModelName(id string) (string, bool)
- func ShortID(id string) string
- func Truncate(s string, n int) string
- type AccountUsage
- type Agent
- type AllTokens
- type Anomaly
- type Capacity
- type CapacityItem
- type Counts
- type Lease
- type ModelCount
- type ModelSeen
- type QuotaPoint
- type QuotaWindow
- type RepoKind
- type Session
- type Snapshot
- type Stats
- type TargetKind
- type Tell
- type TokenSeries
- type Usage
- type WeekTotals
Constants ¶
const ( AnomalyUnresolvedKey = "unresolved key" AnomalyOrphanLease = "lease owner has no transcript" AnomalyUnknownSender = "tell from unknown session" AnomalyUnknownTarget = "tell to unknown session" AnomalyBadLine = "unparsable line" AnomalyOversizedLine = "oversized line skipped" AnomalyUnreadable = "unreadable file" AnomalyTranscriptStall = "transcript shrank" )
Anomaly kinds.
const UnattributedLayer = "unattributed"
UnattributedLayer is the name of the extra layer of the aggregated charts: tokens of an API call that no recorded account can be given.
const Version = 1
Version is the snapshot schema version; the browser refuses a newer one.
Variables ¶
var Families = []string{"Opus", "Sonnet", "Haiku", "Fable"}
Families are the model families the usage charts stack, bottom to top.
Functions ¶
func ModelFamily ¶ added in v0.5.0
ModelFamily is the family alone ("Opus"), or "?" for an unknown id.
func ModelLabel ¶ added in v0.5.0
ModelLabel is "Opus 5.5 (claude-opus-5-5)", or "? (<raw id>)" for an unknown id, or "? (none seen)" when there is none.
Types ¶
type AccountUsage ¶ added in v0.8.0
type AccountUsage struct {
// Key is the account's stable key: a short hash of its id; "" is the account
// of readings recorded before accounts were told apart (unknown, never
// guessed).
Key string `json:"key"`
Label string `json:"label"`
Plan string `json:"plan,omitempty"`
Active bool `json:"active,omitempty"`
// SessionEnd and WeekEnd are the reset instants (Unix seconds) closing the
// current 5 hour and 7 day windows; 0 when unknown. ResetSource says where
// WeekEnd came from: "aiquota", "recorded" (the last reading kept) or ""
// (unknown: the weeks end now).
SessionEnd int64 `json:"sessionEnd,omitempty"`
WeekEnd int64 `json:"weekEnd"`
ResetSource string `json:"resetSource,omitempty"`
RecordingSince int64 `json:"recordingSince,omitempty"`
Windows []QuotaWindow `json:"windows"`
Short TokenSeries `json:"short"` // the 5 hour window, 10 minute buckets
Week TokenSeries `json:"week"` // the 7 day window, hourly buckets
Weeks []WeekTotals `json:"weeks"` // four 7 day windows, oldest first
}
AccountUsage is one account's view.
type Agent ¶
type Agent struct {
Model string `json:"model,omitempty"`
Models []ModelSeen `json:"models,omitempty"`
ID string `json:"id"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
ToolUseID string `json:"toolUseId,omitempty"`
Depth int `json:"depth"`
LastActivity time.Time `json:"lastActivity"`
Active bool `json:"active"`
}
Agent is one sub-agent of a session.
type AllTokens ¶ added in v0.8.0
type AllTokens struct {
Layers []string `json:"layers"` // Families, then UnattributedLayer
Short TokenSeries `json:"short"`
Week TokenSeries `json:"week"`
// Days is 28 calendar days (local midnight to midnight), the last ending at
// the end of today.
Days TokenSeries `json:"days"`
// Unattributed is the tokens (output, cache read) that no account got.
UnattributedOut float64 `json:"unattributedOut"`
UnattributedCache float64 `json:"unattributedCache"`
}
AllTokens is the sum over accounts.
type Anomaly ¶
type Anomaly struct {
Kind string `json:"kind"`
Subject string `json:"subject"`
Detail string `json:"detail,omitempty"`
}
Anomaly is something odd the collector met and chose to show.
type Capacity ¶ added in v0.8.0
type Capacity struct {
// AccountWeeks is the sum of (100 - weekly %)/100 over the accounts whose
// weekly window is current; Counted is how many that is.
AccountWeeks float64 `json:"accountWeeks"`
Counted int `json:"counted"`
Items []CapacityItem `json:"items"`
}
Capacity is what is left of the weekly windows, summed over accounts.
type CapacityItem ¶ added in v0.8.0
type CapacityItem struct {
Key string `json:"key"`
Label string `json:"label"`
Active bool `json:"active,omitempty"`
SessionOK bool `json:"sessionOk,omitempty"`
Session float64 `json:"session,omitempty"`
WeeklyOK bool `json:"weeklyOk,omitempty"`
Weekly float64 `json:"weekly,omitempty"`
NextReset int64 `json:"nextReset,omitempty"`
SessionNext int64 `json:"sessionNext,omitempty"`
// Stale is a reading whose reset has passed: the account is listed, not
// counted.
Stale bool `json:"stale,omitempty"`
// Unknown is the account of readings recorded before accounts were told
// apart: it may be one of the others, so it is listed and never counted.
Unknown bool `json:"unknown,omitempty"`
}
CapacityItem is one account's row of the capacity table.
type Counts ¶
type Counts struct {
Sessions, Active, Agents, ActiveAgents, Repos, Held, Leases, Tells, Anomalies int
}
Counts is the header line of the UI.
type Lease ¶
type Lease struct {
Resource string `json:"resource"` // as written in the lease
Repo string `json:"repo"` // normalised key (org/repo when resolved)
Kind RepoKind `json:"kind"`
Path string `json:"path,omitempty"` // the clone, when there is one
Owner string `json:"owner"`
PID int `json:"pid"`
Note string `json:"note,omitempty"`
Acquired time.Time `json:"acquired"`
Expires time.Time `json:"expires"`
Expired bool `json:"expired"`
}
Lease is one advisory lease, expired ones included.
type ModelCount ¶ added in v0.5.0
ModelCount is how many sessions and sub-agents run one model family.
type QuotaPoint ¶ added in v0.7.0
QuotaPoint is one recorded reading of a window.
type QuotaWindow ¶ added in v0.7.0
type QuotaWindow struct {
Label string `json:"label"`
Available bool `json:"available"`
Percent float64 `json:"percent"`
ResetsAt int64 `json:"resetsAt,omitempty"`
// History is the recorded readings, oldest first: at most one point per
// bucket of the span it is drawn over.
History []QuotaPoint `json:"history,omitempty"`
}
QuotaWindow is one official window and its recorded history.
type RepoKind ¶
type RepoKind string
RepoKind says how a lease resource was understood.
const ( // KindRepo is an org/repo that matches a clone on this machine. KindRepo RepoKind = "repo" // KindRepoForm is an org/repo spelling with no clone here. KindRepoForm RepoKind = "repo-form" // KindOrg is an organisation that has clones here. KindOrg RepoKind = "org" // KindUnresolved is a key that is no repository: a note used as the key, // a bare name, a flag. It is shown, flagged, never hidden. KindUnresolved RepoKind = "unresolved" )
type Session ¶
type Session struct {
ID string `json:"id"`
Short string `json:"short"` // first 8 characters of ID
Title string `json:"title,omitempty"`
Slug string `json:"slug,omitempty"`
Cwd string `json:"cwd,omitempty"`
CwdRepo string `json:"cwdRepo,omitempty"` // Cwd resolved to org/repo, when it is one
Branch string `json:"branch,omitempty"`
PR string `json:"pr,omitempty"`
Project string `json:"project,omitempty"`
LastActivity time.Time `json:"lastActivity"`
Active bool `json:"active"`
HasTranscript bool `json:"hasTranscript"`
Sent int `json:"sent"` // SendMessage calls seen in the observed window
MemAdds int `json:"memAdds"` // entries in the agentsync session record
Agents []Agent `json:"agents,omitempty"`
// Model is the id of the latest assistant entry's model ("" when none was
// seen); Models is every model seen in the observed window, newest first.
Model string `json:"model,omitempty"`
Models []ModelSeen `json:"models,omitempty"`
}
Session is one Claude Code session, with its sub-agents.
type Snapshot ¶
type Snapshot struct {
Version int `json:"version"`
At time.Time `json:"at"`
ActiveFor string `json:"activeFor"` // the activity window, e.g. "10m0s"
Horizon string `json:"horizon"` // sessions older than this are not listed
Sessions []Session `json:"sessions"`
Leases []Lease `json:"leases"`
Tells []Tell `json:"tells"`
Anomalies []Anomaly `json:"anomalies"`
Stats Stats `json:"stats"`
// Usage is the Quota tab's data; nil until the first scan finished.
Usage *Usage `json:"usage,omitempty"`
}
Snapshot is the whole picture at one instant.
func (Snapshot) LeasesOf ¶
LeasesOf returns the leases a session holds or held, live first and then by most recent acquisition.
func (Snapshot) ModelCounts ¶ added in v0.5.0
func (s Snapshot) ModelCounts() []ModelCount
ModelCounts counts the listed sessions and sub-agents by model family, most first (ties by name). "?" counts those whose model is unknown or unseen.
func (Snapshot) SessionByShort ¶
SessionByShort finds a session by its short id.
type Stats ¶
type Stats struct {
TranscriptsSeen int `json:"transcriptsSeen"`
TranscriptsRead int `json:"transcriptsRead"`
BytesRead int64 `json:"bytesRead"`
LeasesRead int `json:"leasesRead"`
LeasesTorn int `json:"leasesTorn"`
TellsRead int `json:"tellsRead"`
TellsDropped int `json:"tellsDropped"`
SubAgentsRead int `json:"subAgentsRead"`
SessionRecords int `json:"sessionRecords"`
ElapsedMicros int64 `json:"elapsedMicros"`
LinesSkipped int `json:"linesSkipped"`
LinesUnparsable int `json:"linesUnparsable"`
ReadErrors int `json:"readErrors"`
ExpiredNotListed int `json:"expiredNotListed"`
}
Stats counts what the collector looked at, so a zero is distinguishable from "could not read".
type TargetKind ¶
type TargetKind string
TargetKind says what a tell was addressed to.
const ( TargetSession TargetKind = "session" TargetResource TargetKind = "resource" )
type Tell ¶
type Tell struct {
Target string `json:"target"` // the session short id or the repo key
TargetKind TargetKind `json:"targetKind"`
From string `json:"from"` // sender session id
Text string `json:"text"` // truncated
At time.Time `json:"at"`
}
Tell is one `agentsync tell` message.
type TokenSeries ¶ added in v0.7.0
type TokenSeries struct {
Start int64 `json:"start"`
Step int64 `json:"step"`
Out [][]float64 `json:"out"`
CacheRead [][]float64 `json:"cacheRead"`
}
TokenSeries is tokens per bucket per layer: Out[layer][bucket], and the same for cache reads. Bucket i covers [Start+i*Step, Start+(i+1)*Step).
type Usage ¶ added in v0.7.0
type Usage struct {
At int64 `json:"at"` // Unix seconds the view was built
Families []string `json:"families"`
// Active is the key of the account Claude Code is signed in to now, "" when
// it cannot be told.
Active string `json:"active,omitempty"`
// QuotaErr is why aiquota could not be read, "" when it could.
QuotaErr string `json:"quotaErr,omitempty"`
Accounts []AccountUsage `json:"accounts"`
Capacity Capacity `json:"capacity"`
// All is the tokens of every account summed, with an extra last layer for
// what could not be attributed (Layers names them).
All AllTokens `json:"all"`
}
Usage is the Quota tab's data: every account's official usage windows, what was recorded of them, and the tokens the local transcripts hold, per account and summed. It is computed on the server so the browser draws and never aggregates. An account is named by a short hash and a label, never by its e-mail or id.
type WeekTotals ¶ added in v0.7.0
type WeekTotals struct {
Start, End int64 // [Start, End)
InProgress bool
Out []float64 // per family
CacheRead []float64 // per family
// CumOut and CumCacheRead are the running totals over all families at
// 6 hour steps from Start; a window in progress stops at the present.
CumOut []float64
CumCacheRead []float64
// Percent is the last official weekly percentage recorded in the window;
// Recorded is false when none was.
Percent float64
Recorded bool
}
WeekTotals is one 7 day window aligned on the weekly reset.