Documentation
¶
Index ¶
- type Config
- type Manager
- func (m *Manager) AppendMessage(id string, msg Message) bool
- func (m *Manager) Clear() int
- func (m *Manager) Close(id string) bool
- func (m *Manager) Create() *Session
- func (m *Manager) CreateWith(chatID, agent, project string) *Session
- func (m *Manager) Delete(id string) bool
- func (m *Manager) FindBy(chatID, agent, project string) *Session
- func (m *Manager) Get(id string) (*Session, bool)
- func (m *Manager) GetContext(id string, key string) (interface{}, bool)
- func (m *Manager) GetMessages(id string) ([]Message, bool)
- func (m *Manager) GetOrLoad(id string) (*Session, bool)
- func (m *Manager) GetRequest(id string) (string, bool)
- func (m *Manager) GetStats() map[string]interface{}
- func (m *Manager) List() []*Session
- func (m *Manager) ListByChat(chatID string) []*Session
- func (m *Manager) SetCompleted(id string, response string) bool
- func (m *Manager) SetContext(id string, key string, value interface{}) bool
- func (m *Manager) SetFailed(id string, err string) bool
- func (m *Manager) SetRequest(id string, request string) bool
- func (m *Manager) SetRunning(id string) bool
- func (m *Manager) Stats() map[string]int
- func (m *Manager) Stop()
- func (m *Manager) Update(id string, fn func(*Session)) bool
- type Message
- type Session
- type SessionStore
- type SessionStoreJSON
- func (s *SessionStoreJSON) CleanupOldSessions(olderThan time.Duration) int
- func (s *SessionStoreJSON) Close() error
- func (s *SessionStoreJSON) Delete(sessionID string) error
- func (s *SessionStoreJSON) FindByChatAgentProject(chatID, agent, project string) (*Session, error)
- func (s *SessionStoreJSON) ForceSave() error
- func (s *SessionStoreJSON) Get(sessionID string) (*Session, error)
- func (s *SessionStoreJSON) List() []*Session
- func (s *SessionStoreJSON) ListByChat(chatID string) ([]*Session, error)
- func (s *SessionStoreJSON) Set(sessionID string, sess *Session) error
- type Status
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 ¶
AppendMessage adds a message to a session
func (*Manager) CreateWith ¶
CreateWith creates a new session with binding information
func (*Manager) FindBy ¶
FindBy finds a session by (chatID, agent, project) tuple. Returns the session if found and not closed/expired, otherwise nil.
func (*Manager) GetContext ¶
GetContext retrieves context data for a session
func (*Manager) GetMessages ¶
GetMessages retrieves messages for a session
func (*Manager) GetOrLoad ¶
GetOrLoad retrieves a session by ID, falling back to the store if needed
func (*Manager) GetRequest ¶
GetRequest retrieves the request for a session
func (*Manager) ListByChat ¶
ListByChat lists all sessions for a given chat ID. Useful for debugging and management.
func (*Manager) SetCompleted ¶
SetCompleted marks a session as completed with response
func (*Manager) SetContext ¶
SetContext stores context data for a session
func (*Manager) SetRequest ¶
SetRequest stores the request for a session
func (*Manager) SetRunning ¶
SetRunning marks a session as running
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 // Claude CLI permission mode: "default", "plan", "auto", "acceptEdits", "dontAsk", "bypassPermissions"
}
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