session

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDir

func DefaultDir() (string, error)

DefaultDir returns the default session directory.

func ExportSessionMarkdown

func ExportSessionMarkdown(ses *Session) string

ExportSessionMarkdown renders a Session to markdown.

Types

type JSONLStore

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

JSONLStore implements Store using JSONL files.

func NewDefaultStore

func NewDefaultStore() (*JSONLStore, error)

NewDefaultStore creates a store in the default directory.

func NewJSONLStore

func NewJSONLStore(dir string) (*JSONLStore, error)

NewJSONLStore creates a store rooted at dir (creates dir if needed).

func (*JSONLStore) AppendMessage

func (s *JSONLStore) AppendMessage(ses *Session, msg provider.Message) error

AppendMessage atomically appends a single message to the session's JSONL file. This is more efficient than Save() for incremental updates.

func (*JSONLStore) CleanupOlderThan

func (s *JSONLStore) CleanupOlderThan(before time.Time) (int, error)

CleanupOlderThan removes sessions older than the given time. Returns count removed.

func (*JSONLStore) Delete

func (s *JSONLStore) Delete(id string) error

Delete removes a session file and its index entry.

func (*JSONLStore) Dir

func (s *JSONLStore) Dir() string

Dir returns the store's directory path.

func (*JSONLStore) EnsureMeta

func (s *JSONLStore) EnsureMeta(ses *Session) error

EnsureMeta writes the meta record if the session file doesn't exist yet.

func (*JSONLStore) ExportMarkdown

func (s *JSONLStore) ExportMarkdown(id string) (string, error)

ExportMarkdown renders a session as a markdown document.

func (*JSONLStore) List

func (s *JSONLStore) List() ([]*Session, error)

List returns all sessions sorted by UpdatedAt descending (uses index for speed).

func (*JSONLStore) Load

func (s *JSONLStore) Load(id string) (*Session, error)

Load reads a session from its JSONL file.

func (*JSONLStore) Save

func (s *JSONLStore) Save(ses *Session) error

Save writes the full session as a JSONL file (atomic).

type Session

type Session struct {
	ID        string             `json:"id"`
	CreatedAt time.Time          `json:"created_at"`
	UpdatedAt time.Time          `json:"updated_at"`
	Title     string             `json:"title"`
	Vendor    string             `json:"vendor"`
	Endpoint  string             `json:"endpoint"`
	Model     string             `json:"model"`
	Messages  []provider.Message `json:"messages,omitempty"`
	// Cost data stored as opaque JSON to avoid circular dependency with cost package.
	CostJSON []byte `json:"cost,omitempty"`
}

Session represents a single conversation session.

func NewSession

func NewSession(vendor, endpoint, model string) *Session

NewSession creates a new Session with a generated ID.

type Store

type Store interface {
	// Save persists the current state of a session (atomic write).
	Save(s *Session) error

	// Load retrieves a session by ID.
	Load(id string) (*Session, error)

	// List returns all sessions, sorted by UpdatedAt descending.
	List() ([]*Session, error)

	// Delete removes a session by ID.
	Delete(id string) error

	// ExportMarkdown renders a session as a markdown document.
	ExportMarkdown(id string) (string, error)

	// CleanupOlderThan removes sessions whose UpdatedAt is before the given time.
	CleanupOlderThan(before time.Time) (int, error)
}

Store is the interface for session persistence.

Jump to

Keyboard shortcuts

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