session

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package session defines the durable, harness-neutral session model.

Index

Constants

View Source
const (
	NamespaceMaxBytes        = 128
	ExternalKeyMaxBytes      = 512
	InputFingerprintMaxBytes = 256
)

Variables

This section is empty.

Functions

func ValidText

func ValidText(value string) bool

ValidText is shared by prompts and opaque identifiers.

func ValidateExternal

func ValidateExternal(value *string, maxBytes int, path ...any) error

ValidateExternal applies byte limits after transport type validation.

Types

type APIError

type APIError struct {
	Status  int
	Problem Error
}

func Problem

func Problem(status int, code, message string) *APIError

func (*APIError) Error

func (e *APIError) Error() string

type Acceptance

type Acceptance struct {
	SessionID uuid.UUID `json:"session_id"`
	RunID     uuid.UUID `json:"run_id"`
	MessageID uuid.UUID `json:"message_id"`
}

type AgentConfiguration

type AgentConfiguration struct {
	Profile      string             `json:"profile"`
	Model        string             `json:"model"`
	Codex        CodexConfiguration `json:"codex,omitzero"`
	Instructions string             `json:"instructions"`
}

type AgentInput

type AgentInput struct {
	Profile      string  `json:"profile"`
	Model        *string `json:"model,omitzero"`
	Instructions *string `json:"instructions,omitzero"`
}

type Cancellation

type Cancellation struct {
	RunID  uuid.UUID `json:"run_id"`
	Status Status    `json:"status"`
}

type CodexConfiguration added in v0.1.5

type CodexConfiguration struct {
	Effort      string `json:"effort,omitzero"`
	Summary     string `json:"summary,omitzero"`
	Personality string `json:"personality,omitzero"`
	ServiceTier string `json:"service_tier,omitzero"`
}

type Configuration

type Configuration struct {
	Agent   AgentConfiguration   `json:"agent"`
	Sandbox SandboxConfiguration `json:"sandbox"`
	Limits  Limits               `json:"limits"`
	Hooks   HooksConfiguration   `json:"hooks"`
}

type ConfigurationInput

type ConfigurationInput struct {
	Agent   AgentInput   `json:"agent"`
	Sandbox SandboxInput `json:"sandbox"`
	Limits  Limits       `json:"limits"`
	Hooks   *HooksInput  `json:"hooks,omitzero"`
}

type CreateSession

type CreateSession struct {
	Services          []string           `json:"services,omitzero"`
	AllowMultipleRuns bool               `json:"allow_multiple_runs,omitzero"`
	Namespace         *string            `json:"namespace,omitzero"`
	ExternalKey       *string            `json:"external_key,omitzero"`
	InputFingerprint  *string            `json:"input_fingerprint,omitzero"`
	Configuration     ConfigurationInput `json:"configuration"`
	Messages          []TextMessage      `json:"messages"`
	Env               map[string]string  `json:"env,omitzero"`
	EnvFrom           []string           `json:"env_from,omitzero"`
}

type CredentialStore

type CredentialStore struct {
	Type        string  `json:"type" toml:"type"`
	Bucket      string  `json:"bucket" toml:"bucket"`
	Region      string  `json:"region" toml:"region"`
	EndpointURL *string `json:"endpoint_url" toml:"endpoint_url"`
}

type Credentials

type Credentials struct {
	Mode      string           `json:"mode" toml:"mode"`
	AccountID string           `json:"account_id,omitzero" toml:"account_id"`
	APIKeyEnv string           `json:"api_key_env" toml:"api_key_env"`
	Store     *CredentialStore `json:"store" toml:"-"`
	Key       string           `json:"key" toml:"key"`
}

type Detail

type Detail struct {
	Path []any  `json:"path"`
	Code string `json:"code"`
}

type Error

type Error struct {
	Code    string   `json:"code"`
	Message string   `json:"message"`
	Phase   *string  `json:"phase"`
	Details []Detail `json:"details"`
}

type Event

type Event struct {
	ID        string          `json:"id"`
	SessionID uuid.UUID       `json:"session_id"`
	Type      string          `json:"type"`
	CreatedAt time.Time       `json:"created_at"`
	Data      json.RawMessage `json:"data"`
}

type EventPage

type EventPage struct {
	Items      []Event `json:"items"`
	NextCursor string  `json:"next_cursor"`
	HasMore    bool    `json:"has_more"`
}

type HistoryItem

type HistoryItem struct {
	Type     string    `json:"type"`
	Message  *Message  `json:"message,omitzero"`
	ToolCall *ToolCall `json:"tool_call,omitzero"`
}

type HistoryPage

type HistoryPage struct {
	Page[HistoryItem]
	EventCursor string `json:"event_cursor"`
}

type HookResult

type HookResult struct {
	ID                 uuid.UUID       `json:"id"`
	Name               string          `json:"name"`
	Status             string          `json:"status"`
	StartedAt          *time.Time      `json:"started_at"`
	DeadlineAt         *time.Time      `json:"deadline_at"`
	FinishedAt         *time.Time      `json:"finished_at"`
	ExitCode           *int            `json:"exit_code"`
	Signal             *int            `json:"signal"`
	Output             json.RawMessage `json:"output"`
	OutputCompleteness string          `json:"output_completeness"`
	TruncationReason   *string         `json:"truncation_reason"`
	Error              *Error          `json:"error"`
}

type HooksConfiguration

type HooksConfiguration struct {
	AfterCreate    *string `json:"after_create,omitzero"`
	BeforeRun      *string `json:"before_run,omitzero"`
	AfterRun       *string `json:"after_run,omitzero"`
	BeforeRemove   *string `json:"before_remove,omitzero"`
	TimeoutSeconds int     `json:"timeout_seconds"`
}

type HooksInput

type HooksInput struct {
	AfterCreate    *string `json:"after_create,omitzero"`
	BeforeRun      *string `json:"before_run,omitzero"`
	AfterRun       *string `json:"after_run,omitzero"`
	BeforeRemove   *string `json:"before_remove,omitzero"`
	TimeoutSeconds *int    `json:"timeout_seconds,omitzero"`
}

type Limits

type Limits struct {
	RunTimeoutSeconds int   `json:"run_timeout_seconds"`
	MaxSessionTokens  int64 `json:"max_session_tokens,omitzero"`
}

type Message

type Message struct {
	ExternalKey        *string         `json:"external_key"`
	Metadata           json.RawMessage `json:"metadata"`
	ID                 uuid.UUID       `json:"id"`
	SessionID          uuid.UUID       `json:"session_id"`
	RunID              uuid.UUID       `json:"run_id"`
	Role               string          `json:"role"`
	Kind               *string         `json:"kind"`
	Text               string          `json:"text"`
	DeliveryStatus     *string         `json:"delivery_status"`
	Error              *Error          `json:"error"`
	RegisteredSequence string          `json:"registered_sequence"`
	Position           *Position       `json:"position"`
	CreatedAt          time.Time       `json:"created_at"`
}

type Page

type Page[T any] struct {
	Items      []T     `json:"items"`
	NextCursor *string `json:"next_cursor"`
}

type Position

type Position struct {
	RunNumber int `json:"run_number"`
	ItemIndex int `json:"item_index"`
}

type ResolvedConfiguration

type ResolvedConfiguration struct {
	Version     int           `json:"version"`
	Harness     string        `json:"harness"`
	Public      Configuration `json:"public"`
	Credentials Credentials   `json:"credentials"`
}

type Run

type Run struct {
	Services           []Service    `json:"services"`
	Usage              Usage        `json:"usage"`
	InputFingerprint   *string      `json:"input_fingerprint"`
	EnvNames           []string     `json:"env_names"`
	EnvFrom            []string     `json:"env_from"`
	ID                 uuid.UUID    `json:"id"`
	SessionID          uuid.UUID    `json:"session_id"`
	Number             int          `json:"number"`
	Status             Status       `json:"status"`
	Phase              *string      `json:"phase"`
	AgentStatus        *Status      `json:"agent_status"`
	AgentError         *Error       `json:"agent_error"`
	Hooks              []HookResult `json:"hooks"`
	Observation        *string      `json:"observation"`
	CreatedAt          time.Time    `json:"created_at"`
	ExecutionStartedAt *time.Time   `json:"execution_started_at"`
	DeadlineAt         *time.Time   `json:"deadline_at"`
	FinishedAt         *time.Time   `json:"finished_at"`
	CancelRequestedAt  *time.Time   `json:"cancel_requested_at"`
	StopReason         *string      `json:"stop_reason"`
	StopMethod         *string      `json:"stop_method"`
	FinalMessage       *Message     `json:"final_message"`
	Error              *Error       `json:"error"`
}

type SandboxConfiguration

type SandboxConfiguration struct {
	Services []Service `json:"services"`
	Template string    `json:"template"`
	EnvNames []string  `json:"env_names"`
	EnvFrom  []string  `json:"env_from"`
}

type SandboxInput

type SandboxInput struct {
	Services []string          `json:"services,omitzero"`
	Template string            `json:"template"`
	Env      map[string]string `json:"env"`
	EnvFrom  []string          `json:"env_from"`
}

type SandboxState

type SandboxState struct {
	State          string  `json:"state"`
	LastKnownState *string `json:"last_known_state"`
	Error          *Error  `json:"error"`
	ID             *string `json:"id"`
	Workspace      *string `json:"workspace"`
}

type Service added in v0.6.0

type Service struct {
	Code        string   `json:"code"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	EnvFrom     []string `json:"env_from"`
}

type Session

type Session struct {
	AllowMultipleRuns bool          `json:"allow_multiple_runs"`
	Usage             Usage         `json:"usage"`
	Namespace         *string       `json:"namespace"`
	ExternalKey       *string       `json:"external_key"`
	ID                uuid.UUID     `json:"id"`
	CreatedAt         time.Time     `json:"created_at"`
	Configuration     Configuration `json:"configuration"`
	Sandbox           SandboxState  `json:"sandbox"`
	ActiveRunID       *uuid.UUID    `json:"active_run_id"`
	LastRunID         uuid.UUID     `json:"last_run_id"`
	LastRunCreatedAt  time.Time     `json:"last_run_created_at"`
	Status            Status        `json:"status"`
	Phase             *string       `json:"phase"`
	FinalMessage      *Message      `json:"final_message"`
	Error             *Error        `json:"error"`
}

type Status

type Status string
const (
	Accepted   Status = "accepted"
	Starting   Status = "starting"
	Running    Status = "running"
	Cancelling Status = "cancelling"
	Finalizing Status = "finalizing"
	Completed  Status = "completed"
	Failed     Status = "failed"
	Cancelled  Status = "cancelled"
)

func (Status) Terminal

func (s Status) Terminal() bool

func (Status) Valid

func (s Status) Valid() bool

type TextMessage

type TextMessage struct {
	ExternalKey *string         `json:"external_key,omitzero"`
	Text        string          `json:"text"`
	Metadata    json.RawMessage `json:"metadata,omitzero"`
}

type ToolCall

type ToolCall struct {
	ID                 uuid.UUID       `json:"id"`
	SessionID          uuid.UUID       `json:"session_id"`
	RunID              uuid.UUID       `json:"run_id"`
	Name               string          `json:"name"`
	Input              json.RawMessage `json:"input"`
	Status             string          `json:"status"`
	Result             json.RawMessage `json:"result"`
	OutputCompleteness string          `json:"output_completeness"`
	TruncationReason   *string         `json:"truncation_reason"`
	RegisteredSequence string          `json:"registered_sequence"`
	Position           *Position       `json:"position"`
	CreatedAt          time.Time       `json:"created_at"`
}

type Usage

type Usage struct {
	InputTokens           int64 `json:"input_tokens"`
	CachedInputTokens     int64 `json:"cached_input_tokens"`
	OutputTokens          int64 `json:"output_tokens"`
	ReasoningOutputTokens int64 `json:"reasoning_output_tokens"`
	TotalTokens           int64 `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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