session

package
v0.260324.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MPL-2.0 Imports: 6 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 SessionStore) *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) CreateWith

func (m *Manager) CreateWith(chatID, agent, project string) *Session

CreateWith creates a new session with binding information

func (*Manager) Delete

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

Delete removes a session

func (*Manager) FindBy

func (m *Manager) FindBy(chatID, agent, project string) *Session

FindBy finds a session by (chatID, agent, project) tuple. Returns the session if found and not closed/expired, otherwise nil.

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

func (m *Manager) ListByChat(chatID string) []*Session

ListByChat lists all sessions for a given chat ID. Useful for debugging and management.

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 Session

type Session struct {
	ID             string                 // Unique session identifier
	ChatID         string                 // NEW: Bound chat ID
	Agent          string                 // NEW: Bound agent type ("claude", "tingly-box")
	Project        string                 // NEW: Bound project path
	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
	PermissionMode string                 // Permission mode: "auto" (yolo), "manual", "skip"
}

Session represents an execution session

type SessionStore

type SessionStore interface {
	// Get retrieves a session by ID
	Get(sessionID string) (*Session, error)

	// Set stores a session
	Set(sessionID string, sess *Session) error

	// Delete removes a session
	Delete(sessionID string) error

	// List returns all sessions
	List() []*Session

	// FindByChatAgentProject finds a session by (chatID, agent, project) tuple
	FindByChatAgentProject(chatID, agent, project string) (*Session, error)

	// ListByChat lists all sessions for a given chat ID
	ListByChat(chatID string) ([]*Session, error)

	// Close closes the store
	Close() error
}

SessionStore defines the interface for session persistence This allows both SQLite-based MessageStore and JSON-based SessionStoreJSON

type SessionStoreJSON

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

SessionStoreJSON handles session persistence using JSON file storage This provides a simpler, more portable alternative to SQLite MessageStore

func NewSessionStoreJSON

func NewSessionStoreJSON(filePath string) (*SessionStoreJSON, error)

NewSessionStoreJSON creates a new JSON-based session store

func (*SessionStoreJSON) CleanupOldSessions

func (s *SessionStoreJSON) CleanupOldSessions(olderThan time.Duration) int

CleanupOldSessions removes sessions older than the specified duration Only removes closed/completed/failed sessions, not running ones

func (*SessionStoreJSON) Close

func (s *SessionStoreJSON) Close() error

Close ensures data is persisted before closing

func (*SessionStoreJSON) Delete

func (s *SessionStoreJSON) Delete(sessionID string) error

Delete removes a session

func (*SessionStoreJSON) FindByChatAgentProject

func (s *SessionStoreJSON) FindByChatAgentProject(chatID, agent, project string) (*Session, error)

FindByChatAgentProject finds a session by (chatID, agent, project) tuple Returns the most recent session matching the criteria

func (*SessionStoreJSON) ForceSave

func (s *SessionStoreJSON) ForceSave() error

ForceSave ensures data is written to disk immediately

func (*SessionStoreJSON) Get

func (s *SessionStoreJSON) Get(sessionID string) (*Session, error)

Get retrieves a session by ID

func (*SessionStoreJSON) List

func (s *SessionStoreJSON) List() []*Session

List returns all sessions

func (*SessionStoreJSON) ListByChat

func (s *SessionStoreJSON) ListByChat(chatID string) ([]*Session, error)

ListByChat lists all sessions for a given chat ID

func (*SessionStoreJSON) Set

func (s *SessionStoreJSON) Set(sessionID string, sess *Session) error

Set stores a 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