storage

package
v0.0.0-...-b272ff4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SettingKeyShowStatusBar  = "ui.showStatusBar"
	SettingKeyShowTimestamps = "ui.showTimestamps"
	SettingKeyDefaultModel   = "ui.defaultModel"
	SettingKeyDefaultAgent   = "ui.defaultAgent"
)

Preference keys used throughout the UI layer.

View Source
const DefaultProjectName = "General"

DefaultProjectName is used when no project exists yet.

Variables

This section is empty.

Functions

func BoolSettingValue

func BoolSettingValue(value bool) string

BoolSettingValue encodes a bool for storage.

func ParseBoolSetting

func ParseBoolSetting(value string, defaultValue bool) bool

ParseBoolSetting converts a stored string into a bool with a fallback.

Types

type MessageRecord

type MessageRecord struct {
	Role      string
	Content   string
	Display   string
	Model     string
	CreatedAt time.Time
}

MessageRecord captures a single message for persistence.

type Project

type Project struct {
	ID          int64
	Name        string
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Project represents a logical grouping of conversations.

type ProjectStats

type ProjectStats struct {
	Project
	ConversationCount int
	LastConversation  time.Time
}

ProjectStats provides aggregate info for menu listings.

type Session

type Session struct {
	ID          int64
	ProjectID   int64
	Title       string
	LastSummary string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Session represents a single saved conversation.

type SettingScope

type SettingScope string

SettingScope identifies whether a preference targets the whole user or a specific project.

const (
	// SettingScopeUser stores preferences that apply globally for the current user.
	SettingScopeUser SettingScope = "user"
	// SettingScopeProject stores preferences scoped to a single project.
	SettingScopeProject SettingScope = "project"
)

type Store

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

Store wraps a SQLite database for conversation persistence.

func Open

func Open(path string) (*Store, error)

Open opens (and creates if needed) the SQLite database at the given path.

func OpenDefault

func OpenDefault() (*Store, error)

OpenDefault tries a series of writable locations and returns the first successful store handle.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database handle.

func (*Store) ConversationsByProject

func (s *Store) ConversationsByProject(projectID int64, limit int) ([]Session, error)

ConversationsByProject returns the conversations for a given project.

func (*Store) CreateProject

func (s *Store) CreateProject(name, description string) (Project, error)

CreateProject inserts a new project row.

func (*Store) CreateSession

func (s *Store) CreateSession(projectID int64, label string) (Session, error)

CreateSession creates a new empty conversation row for a project.

func (*Store) DeleteProject

func (s *Store) DeleteProject(id int64) error

DeleteProject removes a project and all of its conversations.

func (*Store) DeleteSession

func (s *Store) DeleteSession(sessionID int64) error

DeleteSession removes a single conversation and its messages.

func (*Store) EnsureProject

func (s *Store) EnsureProject(name string) (Project, error)

EnsureProject finds or creates a project with the given name.

func (*Store) GetProject

func (s *Store) GetProject(id int64) (Project, error)

GetProject fetches a project by id.

func (*Store) GetProjectByName

func (s *Store) GetProjectByName(name string) (Project, error)

GetProjectByName fetches a project with an exact name match.

func (*Store) GetSession

func (s *Store) GetSession(id int64) (Session, error)

GetSession returns metadata for a single session.

func (*Store) ListProjectsWithStats

func (s *Store) ListProjectsWithStats(limit int) ([]ProjectStats, error)

ListProjectsWithStats returns projects ordered by recent activity.

func (*Store) LoadSessionMessages

func (s *Store) LoadSessionMessages(sessionID int64) ([]MessageRecord, error)

LoadSessionMessages returns all messages for a session ordered by creation time.

func (*Store) LoadSetting

func (s *Store) LoadSetting(scope SettingScope, targetID int64, key string) (string, bool, error)

LoadSetting fetches a single key/value pair for the provided scope + target.

func (*Store) LoadSettings

func (s *Store) LoadSettings(scope SettingScope, targetID int64) (map[string]string, error)

LoadSettings returns all key/value pairs for the provided scope + target.

func (*Store) RecentSessions

func (s *Store) RecentSessions(limit int) ([]Session, error)

RecentSessions returns the most recently updated sessions.

func (*Store) RenameProject

func (s *Store) RenameProject(id int64, name string) (Project, error)

RenameProject updates a project's name and returns the updated record.

func (*Store) SaveMessage

func (s *Store) SaveMessage(sessionID int64, rec MessageRecord) error

SaveMessage persists a message to the session and updates metadata.

func (*Store) SaveSetting

func (s *Store) SaveSetting(scope SettingScope, targetID int64, key, value string) error

SaveSetting upserts a key/value pair for the provided scope + target.

func (*Store) UpdateSessionTitle

func (s *Store) UpdateSessionTitle(sessionID int64, title string) error

UpdateSessionTitle renames a conversation.

Jump to

Keyboard shortcuts

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