session

package
v0.5.0-beta Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package session manages ACP session lifecycle, wrapping kodelet threads with ACP session semantics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages ACP sessions

func NewManager

func NewManager(cfg ManagerConfig) *Manager

NewManager creates a new session manager

func (*Manager) Cancel

func (m *Manager) Cancel(id acptypes.SessionID) error

Cancel cancels a session by ID

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

Close releases session-scoped resources and conversation storage.

func (*Manager) GetSession

func (m *Manager) GetSession(id acptypes.SessionID) (*Session, error)

GetSession returns a session by ID

func (*Manager) LoadSession

func (m *Manager) LoadSession(ctx context.Context, req acptypes.LoadSessionRequest) (*Session, error)

LoadSession loads an existing session

func (*Manager) NewSession

func (m *Manager) NewSession(ctx context.Context, req acptypes.NewSessionRequest) (*Session, error)

NewSession creates a new session

type ManagerConfig

type ManagerConfig struct {
	Provider            string
	Model               string
	MaxTokens           int
	NoSkills            bool
	NoExtensions        bool
	EnableFSSearchTools bool
	MaxTurns            int
	CompactRatio        float64
}

ManagerConfig holds configuration for the session Manager.

type Session

type Session struct {
	ID         acptypes.SessionID
	Thread     llmtypes.Thread
	State      *tools.BasicState
	Extensions *extensions.Runtime
	CWD        string
	// contains filtered or unexported fields
}

Session represents an ACP session wrapping a kodelet thread

func (*Session) Cancel

func (s *Session) Cancel()

Cancel cancels the current prompt execution

func (*Session) Close

func (s *Session) Close(ctx context.Context) error

Close releases session-scoped resources.

func (*Session) HandlePrompt

func (s *Session) HandlePrompt(ctx context.Context, prompt []acptypes.ContentBlock, sender UpdateSender) (acptypes.StopReason, error)

HandlePrompt processes a prompt and returns the stop reason

func (*Session) IsCancelled

func (s *Session) IsCancelled() bool

IsCancelled returns whether the session has been cancelled

type SessionStorage

type SessionStorage interface {
	AppendUpdate(sessionID acptypes.SessionID, update any) error
	ReadUpdates(sessionID acptypes.SessionID) ([]StoredUpdate, error)
	Flush(sessionID acptypes.SessionID) error
	Delete(sessionID acptypes.SessionID) error
	CloseSession(sessionID acptypes.SessionID) error
	Exists(sessionID acptypes.SessionID) bool
	Close() error
}

SessionStorage defines the interface for ACP session update storage.

func GetDefaultStorage

func GetDefaultStorage(ctx context.Context) (SessionStorage, error)

GetDefaultStorage returns the default storage implementation (SQLite).

type Storage

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

Storage handles persistence of ACP session updates using SQLite.

func NewStorage

func NewStorage(ctx context.Context, opts ...StorageOption) (*Storage, error)

NewStorage creates a new SQLite-based session storage. Note: Migrations should be run via db.RunMigrations() at CLI startup before calling this.

func (*Storage) AppendUpdate

func (s *Storage) AppendUpdate(sessionID acptypes.SessionID, update any) error

AppendUpdate appends a session update, merging consecutive text chunks.

func (*Storage) Close

func (s *Storage) Close() error

Close flushes all pending updates and closes the database connection.

func (*Storage) CloseSession

func (s *Storage) CloseSession(sessionID acptypes.SessionID) error

CloseSession flushes pending updates and removes the session from memory.

func (*Storage) Delete

func (s *Storage) Delete(sessionID acptypes.SessionID) error

Delete removes all session updates from storage.

func (*Storage) Exists

func (s *Storage) Exists(sessionID acptypes.SessionID) bool

Exists checks if a session has any stored updates.

func (*Storage) Flush

func (s *Storage) Flush(sessionID acptypes.SessionID) error

Flush writes any pending update for a session to disk.

func (*Storage) ReadUpdates

func (s *Storage) ReadUpdates(sessionID acptypes.SessionID) ([]StoredUpdate, error)

ReadUpdates reads all updates for a session for replay.

type StorageOption

type StorageOption func(*Storage)

StorageOption configures a Storage instance.

func WithDBPath

func WithDBPath(path string) StorageOption

WithDBPath sets a custom database path for session storage.

type StoredUpdate

type StoredUpdate struct {
	SessionID acptypes.SessionID `json:"sessionId"`
	Update    json.RawMessage    `json:"update"`
}

StoredUpdate represents a stored session update for replay

type UpdateSender

type UpdateSender interface {
	SendUpdate(sessionID acptypes.SessionID, update any) error
}

UpdateSender interface for sending session updates

Jump to

Keyboard shortcuts

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