Documentation
¶
Overview ¶
Package session provides the core session model: id, title, created_at, and conversation history. File-based persistence lives in internal/agentapp (SessionStore).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is returned when a session file does not exist.
Functions ¶
func CtxWithSessionID ¶
CtxWithSessionID returns a context that carries the given session ID.
func EnsureTitleFromFirstUserMessage ¶
EnsureTitleFromFirstUserMessage sets the session title from the first user message if the title is empty, truncated to maxLen runes. No-op otherwise.
Types ¶
type Session ¶
type Session struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
CreatedAt time.Time `json:"created_at"`
Messages []llm.Message `json:"messages,omitempty"`
PromptTokens int `json:"prompt_tokens,omitempty"`
CompletionTokens int `json:"completion_tokens,omitempty"`
// CompactionIdx is the index into Messages where the latest compaction boundary falls.
// Messages before this index have been summarized into CompactionSummary.
// Zero means no compaction has occurred.
CompactionIdx int `json:"compaction_idx,omitempty"`
CompactionSummary string `json:"compaction_summary,omitempty"`
}
Session holds conversation history (user, assistant, tool messages) and metadata. The system message is not stored; it is prepended at call time by the agent. JSON tags match the on-disk session file format (snake_case).
func NewSession ¶
NewSession creates a new session with a generated UUID, the given title, created_at set to the current time, and empty history. Title may be empty.
func NewSessionFromData ¶
func NewSessionFromData(id, title string, createdAt time.Time, messages []llm.Message, promptTokens, completionTokens int) *Session
NewSessionFromData constructs a Session from persisted data.
func (*Session) AddCompaction ¶
AddCompaction advances the compaction boundary by summarizedCount messages and stores the summary. Implements agent.CompactionHistory so RunLoop can persist the boundary across turns.
func (*Session) HistoryMessages ¶
HistoryMessages returns the LLM-facing message slice. When a compaction boundary exists, only messages from CompactionIdx onward are returned; earlier messages have been summarized.
type SessionItem ¶
type SessionItem struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
Workspace string `json:"workspace,omitempty"`
CreatedAt string `json:"created_at"` // RFC3339
Pinned bool `json:"pinned,omitempty"`
}
SessionItem is one session's metadata in the session index file (sessions.json).