session

package
v0.260213.1830-hotfix Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout          time.Duration // Session timeout duration
	MessageRetention time.Duration // Message retention window
}

Config holds session manager configuration

type Manager

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

Manager handles session lifecycle

func NewManager

func NewManager(cfg Config, store *MessageStore) *Manager

NewManager creates a new session manager

func (*Manager) AppendMessage

func (m *Manager) AppendMessage(id string, msg Message) bool

AppendMessage adds a message to a session

func (*Manager) Clear

func (m *Manager) Clear() int

Clear removes all sessions

func (*Manager) Close

func (m *Manager) Close(id string) bool

Close terminates a session gracefully

func (*Manager) Create

func (m *Manager) Create() *Session

Create creates a new session and returns it

func (*Manager) Delete

func (m *Manager) Delete(id string) bool

Delete removes a session

func (*Manager) Get

func (m *Manager) Get(id string) (*Session, bool)

Get retrieves a session by ID

func (*Manager) GetContext

func (m *Manager) GetContext(id string, key string) (interface{}, bool)

GetContext retrieves context data for a session

func (*Manager) GetMessages

func (m *Manager) GetMessages(id string) ([]Message, bool)

GetMessages retrieves messages for a session

func (*Manager) GetOrLoad

func (m *Manager) GetOrLoad(id string) (*Session, bool)

GetOrLoad retrieves a session by ID, falling back to the store if needed

func (*Manager) GetRequest

func (m *Manager) GetRequest(id string) (string, bool)

GetRequest retrieves the request for a session

func (*Manager) GetStats

func (m *Manager) GetStats() map[string]interface{}

GetStats returns comprehensive session statistics

func (*Manager) List

func (m *Manager) List() []*Session

List returns all sessions

func (*Manager) SetCompleted

func (m *Manager) SetCompleted(id string, response string) bool

SetCompleted marks a session as completed with response

func (*Manager) SetContext

func (m *Manager) SetContext(id string, key string, value interface{}) bool

SetContext stores context data for a session

func (*Manager) SetFailed

func (m *Manager) SetFailed(id string, err string) bool

SetFailed marks a session as failed with error

func (*Manager) SetRequest

func (m *Manager) SetRequest(id string, request string) bool

SetRequest stores the request for a session

func (*Manager) SetRunning

func (m *Manager) SetRunning(id string) bool

SetRunning marks a session as running

func (*Manager) Stats

func (m *Manager) Stats() map[string]int

Stats returns session statistics by status

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the cleanup goroutine

func (*Manager) Update

func (m *Manager) Update(id string, fn func(*Session)) bool

Update updates a session

type Message

type Message struct {
	Role      string    // "user" or "assistant"
	Content   string    // Full content
	Summary   string    // Optional summary for assistant responses
	Timestamp time.Time // When the message was created
}

Message represents a chat message within a session

type MessageStore

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

MessageStore persists session messages to SQLite

func NewMessageStore

func NewMessageStore(dbPath string) (*MessageStore, error)

NewMessageStore creates a SQLite-backed message store

func (*MessageStore) ClearAllMessages

func (s *MessageStore) ClearAllMessages() error

ClearAllMessages removes all messages

func (*MessageStore) ClearAllSessions

func (s *MessageStore) ClearAllSessions() error

ClearAllSessions removes all sessions from storage

func (*MessageStore) Close

func (s *MessageStore) Close() error

Close closes the underlying DB

func (*MessageStore) DeleteMessagesForSession

func (s *MessageStore) DeleteMessagesForSession(sessionID string) error

DeleteMessagesForSession removes all messages for a session

func (*MessageStore) DeleteSession

func (s *MessageStore) DeleteSession(sessionID string) error

DeleteSession removes a session from storage

func (*MessageStore) GetMessages

func (s *MessageStore) GetMessages(sessionID string) ([]Message, error)

GetMessages returns messages for a session in chronological order

func (*MessageStore) GetSession

func (s *MessageStore) GetSession(sessionID string) (*Session, error)

GetSession retrieves a single session from storage

func (*MessageStore) InsertMessage

func (s *MessageStore) InsertMessage(sessionID string, msg Message) error

InsertMessage writes a message to storage

func (*MessageStore) LoadSessions

func (s *MessageStore) LoadSessions() ([]*Session, error)

LoadSessions loads all sessions from storage

func (*MessageStore) PurgeOlderThan

func (s *MessageStore) PurgeOlderThan(cutoff time.Time) error

PurgeOlderThan deletes messages older than a cutoff

func (*MessageStore) PurgeSessionsOlderThan

func (s *MessageStore) PurgeSessionsOlderThan(cutoff time.Time) error

PurgeSessionsOlderThan deletes sessions older than a cutoff

func (*MessageStore) UpsertSession

func (s *MessageStore) UpsertSession(sess *Session) error

UpsertSession writes session metadata to storage

type Session

type Session struct {
	ID           string                 // Unique session identifier
	Status       Status                 // Current session status
	Request      string                 // User's request payload
	Response     string                 // Claude Code response summary
	Error        string                 // Error message if failed
	CreatedAt    time.Time              // Session creation timestamp
	LastActivity time.Time              // Last activity timestamp
	ExpiresAt    time.Time              // Session expiration timestamp
	Context      map[string]interface{} // Request context for continued communication
	Messages     []Message              // Chat message history
}

Session represents an execution session

type Status

type Status string

Status represents the current state of a session

const (
	StatusPending   Status = "pending"
	StatusRunning   Status = "running"
	StatusCompleted Status = "completed"
	StatusFailed    Status = "failed"
	StatusExpired   Status = "expired"
	StatusClosed    Status = "closed"
)

Jump to

Keyboard shortcuts

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