session

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArtifactSummary

type ArtifactSummary struct {
	Kind      string `json:"kind,omitempty"`
	Name      string `json:"name,omitempty"`
	MIME      string `json:"mime,omitempty"`
	Source    string `json:"source,omitempty"`
	SourceTyp string `json:"source_type,omitempty"`
	Width     int64  `json:"width,omitempty"`
	Height    int64  `json:"height,omitempty"`
}

type AssistantProvider

type AssistantProvider interface {
	Assist(AssistantRequest) (AssistantResponse, error)
}

type AssistantRequest

type AssistantRequest struct {
	Kind    string
	Prompt  string
	Context SessionInspect
}

type AssistantResponse

type AssistantResponse struct {
	Text string
}

type CheckpointID

type CheckpointID string

type DebugStep

type DebugStep struct {
	Index      int               `json:"index"`
	Statement  string            `json:"statement"`
	OK         bool              `json:"ok"`
	Result     string            `json:"result,omitempty"`
	Error      string            `json:"error,omitempty"`
	Variables  map[string]string `json:"variables,omitempty"`
	DurationMS int64             `json:"duration_ms"`
}

type DebugTrace

type DebugTrace struct {
	SessionID   SessionID   `json:"session_id"`
	ExecutionID ExecutionID `json:"execution_id"`
	OK          bool        `json:"ok"`
	Steps       []DebugStep `json:"steps"`
	Error       string      `json:"error,omitempty"`
}

type ErrorKind

type ErrorKind string

ErrorKind classifies execution errors reported via ExecutionMetrics. Its values intentionally match the string values of the root package's ExecErrorKind (interpreter.go) so hosts comparing across both APIs see consistent classifications; pkg/session cannot import the root package (which imports pkg/session), so the values are duplicated here rather than shared via a type alias.

const (
	ErrorKindNone          ErrorKind = ""
	ErrorKindRuntime       ErrorKind = "runtime"
	ErrorKindPolicyDenied  ErrorKind = "policy_denied"
	ErrorKindResourceLimit ErrorKind = "resource_limit"
	ErrorKindTimeout       ErrorKind = "timeout"
	ErrorKindCancelled     ErrorKind = "cancelled"
)

type EventKind

type EventKind string
const (
	EventExecutionStart  EventKind = "execution.start"
	EventExecutionFinish EventKind = "execution.finish"
	EventOutput          EventKind = "output"
	EventDiagnostic      EventKind = "diagnostic"
	EventMetric          EventKind = "metric"
	EventTrace           EventKind = "trace"
	EventRenderArtifact  EventKind = "render_artifact"
	EventError           EventKind = "error"
	EventDebug           EventKind = "debug"
	EventCheckpoint      EventKind = "checkpoint"
	EventRestore         EventKind = "restore"
	EventReplay          EventKind = "replay"
)

type ExecutionEvent

type ExecutionEvent struct {
	ID          string         `json:"id"`
	SessionID   SessionID      `json:"session_id"`
	ExecutionID ExecutionID    `json:"execution_id,omitempty"`
	Kind        EventKind      `json:"kind"`
	Time        time.Time      `json:"time"`
	Message     string         `json:"message,omitempty"`
	Data        map[string]any `json:"data,omitempty"`
}

type ExecutionID

type ExecutionID string

type ExecutionMetrics

type ExecutionMetrics struct {
	Duration    time.Duration `json:"duration"`
	Steps       int64         `json:"steps"`
	OutputBytes int64         `json:"output_bytes"`
	ResultType  string        `json:"result_type,omitempty"`
	Error       string        `json:"error,omitempty"`
	ErrorKind   ErrorKind     `json:"error_kind,omitempty"`
}

type ExecutionRequest

type ExecutionRequest struct {
	Source     string
	Path       string
	Data       map[string]interface{}
	Print      bool
	Replay     bool
	Record     bool
	Checkpoint CheckpointID
}

type ExecutionResult

type ExecutionResult struct {
	ID          ExecutionID       `json:"id"`
	SessionID   SessionID         `json:"session_id"`
	Source      string            `json:"source,omitempty"`
	Path        string            `json:"path,omitempty"`
	OK          bool              `json:"ok"`
	Result      object.Object     `json:"-"`
	ResultText  string            `json:"result,omitempty"`
	Output      string            `json:"output,omitempty"`
	Error       string            `json:"error,omitempty"`
	Diagnostics []string          `json:"diagnostics,omitempty"`
	Artifacts   []ArtifactSummary `json:"artifacts,omitempty"`
	Metrics     ExecutionMetrics  `json:"metrics"`
	StartedAt   time.Time         `json:"started_at"`
	FinishedAt  time.Time         `json:"finished_at"`
}

type RuntimeInspector

type RuntimeInspector interface {
	Inspect() SessionInspect
}

type Session

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

func New

func New(opts SessionOptions) (*Session, error)

func NewWithEnvironment

func NewWithEnvironment(env *object.Environment, opts SessionOptions) (*Session, error)

func (*Session) Ask

func (s *Session) Ask(kind, prompt string) (AssistantResponse, error)

func (*Session) Cancel

func (s *Session) Cancel() error

Cancel cancels the currently-running (or next-to-start) Execute call on this session by invoking the cancel function of the context it derives its deadline/cancellation from. If no execution is currently in flight, Cancel is a safe no-op. Cancel does not stop any execution already completed, and it only affects a single in-flight (or immediately upcoming, in a narrow race window) Execute call — it is not a queue/registry of executions.

func (*Session) Checkpoint

func (s *Session) Checkpoint(name string) (SessionSnapshot, error)

func (*Session) Close

func (s *Session) Close()

func (*Session) Debug

func (s *Session) Debug(src string, path string) DebugTrace

func (*Session) Environment

func (s *Session) Environment() *object.Environment

func (*Session) Events

func (s *Session) Events() []ExecutionEvent

func (*Session) Execute

func (s *Session) Execute(req ExecutionRequest) ExecutionResult

func (*Session) ID

func (s *Session) ID() SessionID

func (*Session) Inspect

func (s *Session) Inspect() SessionInspect

func (*Session) Replay

func (s *Session) Replay() ([]ExecutionResult, error)

func (*Session) Restore

func (s *Session) Restore(name string) error

func (*Session) SetOutput

func (s *Session) SetOutput(output io.Writer)

type SessionID

type SessionID string

type SessionInspect

type SessionInspect struct {
	ID             SessionID         `json:"id"`
	Profile        string            `json:"profile"`
	ModuleDir      string            `json:"module_dir,omitempty"`
	SourcePath     string            `json:"source_path,omitempty"`
	Variables      map[string]string `json:"variables"`
	History        []ExecutionResult `json:"history"`
	Checkpoints    []SessionSnapshot `json:"checkpoints"`
	Events         []ExecutionEvent  `json:"events"`
	RuntimeLimits  map[string]any    `json:"runtime_limits,omitempty"`
	RenderArtifact int               `json:"render_artifacts,omitempty"`
}

type SessionOptions

type SessionOptions struct {
	ID             SessionID
	Profile        string
	Args           []string
	ModuleDir      string
	SourcePath     string
	Output         io.Writer
	Security       *object.SecurityPolicy
	Sandbox        *sandbox.SandboxConfig
	MaxDepth       int
	MaxSteps       int64
	MaxHeapMB      int64
	MaxOutputBytes int64
	Timeout        time.Duration
	Persist        bool
	PersistenceDir string
	Assistant      AssistantProvider
	EventLimit     int
}

type SessionSnapshot

type SessionSnapshot struct {
	ID          CheckpointID      `json:"id"`
	SessionID   SessionID         `json:"session_id"`
	CreatedAt   time.Time         `json:"created_at"`
	Description string            `json:"description,omitempty"`
	Variables   map[string]string `json:"variables"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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