Documentation
¶
Overview ¶
Package session persists gateway-owned session metadata and coordinates active runs. Native transcripts remain owned by the native CLI and are never copied or deleted here.
Index ¶
- Constants
- Variables
- type Info
- type LastRun
- type Lineage
- type NativeTranscript
- type Registry
- func (r *Registry) Acquire(workspaceID, sessionID, runID, mode, forkFrom string, settings *agent.Settings, ...) (release func(), err error)
- func (r *Registry) Bind(workspaceID, sessionID, nativeSessionID string) error
- func (r *Registry) Complete(workspaceID, sessionID, runID, status string, usage agent.UsageTotal) error
- func (r *Registry) Create(workspaceID, sessionID string) (Info, error)
- func (r *Registry) Delete(sessionID string) error
- func (r *Registry) Fork(parentID, sessionID string) (Info, error)
- func (r *Registry) Get(sessionID string) (Info, error)
- func (r *Registry) Health() error
- func (r *Registry) LastUsed() map[string]time.Time
- func (r *Registry) List(workspaceID string) []Info
- func (r *Registry) RemoveIfIdle(workspaceID string, remove func() error) error
- type Run
- type RunCount
- type Times
- type View
Constants ¶
const ( StateIdle = "idle" StateActive = "active" StateCompleted = "completed" StateOrphaned = "orphaned" )
const ( OriginNew = "new" OriginFork = "fork" )
Session origins.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct {
WorkspaceID string `json:"workspace_id"`
SessionID string `json:"session_id" format:"uuid"`
State string `json:"state" enum:"idle,active,completed,orphaned,unavailable"`
SessionMode string `json:"session_mode,omitempty" enum:"new,resume,fork"`
ForkFrom string `json:"fork_from,omitempty" format:"uuid"`
LastRunID string `json:"last_run_id,omitempty" format:"uuid"`
LastRunStatus string `json:"last_run_status,omitempty" enum:"succeeded,failed,cancelled"`
LastRunMode string `json:"last_run_mode,omitempty" enum:"new,resume,fork"`
ActiveRunID string `json:"active_run_id,omitempty" format:"uuid"`
NativeSessionID string `json:"native_session_id,omitempty"`
GatewayRuns int `json:"gateway_runs"`
RunsWithoutUsage int `json:"runs_without_usage"`
ObservedUsage *storedUsage `json:"observed_usage,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
NativeTranscript NativeTranscript `json:"native_transcript"`
// Settings are the run settings of the last run; continuing the session reuses them.
Settings *agent.Settings `json:"settings,omitempty"`
}
Info is the minimal gateway-owned session metadata persisted across restarts. Its JSON form is the metadata file format; the API shows View.
type Lineage ¶
type Lineage struct {
Origin string `` /* 133-byte string literal not displayed */
ForkFrom string `json:"fork_from,omitempty" format:"uuid" doc:"Session this one was forked from."`
}
Lineage is how the session's conversation started. It does not change afterwards.
type NativeTranscript ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry owns session metadata and active-run locks.
func NewRegistry ¶
NewRegistry loads and validates persisted metadata. Active records left by a previous process are atomically rewritten as orphaned because their native process cannot be proven alive.
func (*Registry) Acquire ¶
func (r *Registry) Acquire(workspaceID, sessionID, runID, mode, forkFrom string, settings *agent.Settings, check func() error) (release func(), err error)
Acquire marks a session active. Unknown native session IDs are registered so resume/fork can address transcripts created outside this gateway without claiming ownership of them.
func (*Registry) Bind ¶
Bind records the provider-owned session identifier while the gateway session is active.
func (*Registry) Complete ¶
func (r *Registry) Complete(workspaceID, sessionID, runID, status string, usage agent.UsageTotal) error
Complete records the terminal gateway run without claiming that the native transcript exists or that the native CLI considers the conversation closed.
func (*Registry) Delete ¶
Delete removes gateway metadata only; the native CLI transcript is never touched.
func (*Registry) Fork ¶
Fork registers an idle session that will fork parentID on its first run. It inherits the parent's workspace and settings.
func (*Registry) LastUsed ¶
LastUsed returns the latest session update of every workspace that has sessions.
type Run ¶
type Run struct {
RunID string `json:"run_id" format:"uuid"`
Mode string `` /* 130-byte string literal not displayed */
}
Run is a run of a session and how it opened the native conversation.
type RunCount ¶
type RunCount struct {
Count int `json:"count"`
WithoutTurns int `json:"without_turns" doc:"Runs that ended before any turn finished, for example cancelled before the agent answered."`
}
RunCount counts a session's finished runs.
type Times ¶
type Times struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Times are a session's timestamps.
type View ¶
type View struct {
SessionID string `json:"session_id" format:"uuid"`
WorkspaceID string `json:"workspace_id"`
// NativeSessionID is the agent's own identifier of the conversation, once it started.
NativeSessionID string `json:"native_session_id,omitempty"`
State string `json:"state" enum:"idle,active,completed,orphaned,unavailable"`
Lineage Lineage `json:"lineage"`
// ActiveRun is the run working in the session while its state is active.
ActiveRun *Run `json:"active_run,omitempty"`
// LastRun is the latest finished run.
LastRun *LastRun `json:"last_run,omitempty"`
Runs RunCount `json:"runs"`
// Usage sums the token counts of the session's runs.
Usage agent.UsageTotal `json:"usage"`
// Settings are the run settings of the last run; continuing the session reuses them.
Settings *agent.Settings `json:"settings,omitempty"`
Times Times `json:"times"`
}
View is a session as the API shows it.