session

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	StateIdle        = "idle"
	StateActive      = "active"
	StateCompleted   = "completed"
	StateOrphaned    = "orphaned"
	StateUnavailable = "unavailable"
)
View Source
const (
	OriginNew  = "new"
	OriginFork = "fork"
)

Session origins.

Variables

View Source
var (
	ErrBusy       = errors.New("session is busy")
	ErrNotFound   = errors.New("session not found")
	ErrExists     = errors.New("session already exists")
	ErrInvalid    = errors.New("session metadata is invalid")
	ErrNotStarted = errors.New("session has no native conversation yet")
)

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.

func (Info) View

func (i Info) View() View

View returns the API form of the metadata.

type LastRun

type LastRun struct {
	Run

	Status string `json:"status" enum:"succeeded,failed,cancelled"`
}

LastRun is the latest finished run of a session.

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 NativeTranscript struct {
	Owner string `json:"owner" enum:"native_cli"`
	State string `json:"state" enum:"unverified"`
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry owns session metadata and active-run locks.

func NewRegistry

func NewRegistry(root string, available func(workspaceID string) bool) (*Registry, error)

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

func (r *Registry) Bind(workspaceID, sessionID, nativeSessionID string) error

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) Create

func (r *Registry) Create(workspaceID, sessionID string) (Info, error)

Create registers an idle session ID issued by the gateway.

func (*Registry) Delete

func (r *Registry) Delete(sessionID string) error

Delete removes gateway metadata only; the native CLI transcript is never touched.

func (*Registry) Fork

func (r *Registry) Fork(parentID, sessionID string) (Info, error)

Fork registers an idle session that will fork parentID on its first run. It inherits the parent's workspace and settings.

func (*Registry) Get

func (r *Registry) Get(sessionID string) (Info, error)

func (*Registry) Health

func (r *Registry) Health() error

Health verifies that the persistent metadata root is still accessible.

func (*Registry) LastUsed

func (r *Registry) LastUsed() map[string]time.Time

LastUsed returns the latest session update of every workspace that has sessions.

func (*Registry) List

func (r *Registry) List(workspaceID string) []Info

List returns sessions newest first, optionally filtered to one workspace.

func (*Registry) RemoveIfIdle

func (r *Registry) RemoveIfIdle(workspaceID string, remove func() error) error

RemoveIfIdle runs remove only when no session of the workspace is active.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL