session

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package session stores bounded conversation history in SQLite.

Index

Constants

View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
)

Role values persisted for conversation turns (system/persona is not stored).

Variables

This section is empty.

Functions

func EstTokens

func EstTokens(msgs []Message) int

EstTokens returns the chars/4 token estimate for messages.

Types

type LLMSummarizer

type LLMSummarizer struct {
	Completer provider.Completer
}

LLMSummarizer uses the chat completer for a cheap compression pass.

func (*LLMSummarizer) Fold

func (s *LLMSummarizer) Fold(ctx context.Context, prior string, dropped []Message) (string, error)

Fold returns an updated summary paragraph.

type Message

type Message struct {
	Role    string
	Content string
}

Message is one persisted conversation turn.

type Store

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

Store is a SQLite-backed session history.

func Open

func Open(dataDir string, maxMessages, maxEstTokens int) (*Store, error)

Open opens (or creates) gantry.db under dataDir and runs migrations.

func (*Store) Append

func (s *Store) Append(ctx context.Context, sessionID string, msgs ...Message) error

Append writes turns and trims the session to configured bounds.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying database handle (shared by memory when builtin).

func (*Store) Messages

func (s *Store) Messages(ctx context.Context, sessionID string) ([]Message, error)

Messages returns the bounded history for sessionID (oldest first).

func (*Store) Reset

func (s *Store) Reset(ctx context.Context, sessionID string) error

Reset deletes all history for sessionID (memory untouched — different store).

func (*Store) Stats

func (s *Store) Stats(ctx context.Context, sessionID string) (messages int, estTokens int, err error)

Stats returns message count and estimated tokens (chars/4) for a session.

func (*Store) Summary

func (s *Store) Summary(ctx context.Context, sessionID string) (string, error)

Summary returns the rolling summary for sessionID (empty if none).

func (*Store) WithSummarizer

func (s *Store) WithSummarizer(sum Summarizer) *Store

WithSummarizer enables rolling summary when history is trimmed.

type Summarizer

type Summarizer interface {
	Fold(ctx context.Context, prior string, dropped []Message) (string, error)
}

Summarizer folds dropped history turns into a durable session summary.

Jump to

Keyboard shortcuts

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