storage

package
v0.99.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversationMetadata

type ConversationMetadata struct {
	ID                  string                   `json:"id"`
	Title               string                   `json:"title"`
	CreatedAt           time.Time                `json:"created_at"`
	UpdatedAt           time.Time                `json:"updated_at"`
	MessageCount        int                      `json:"message_count"`
	TokenStats          domain.SessionTokenStats `json:"token_stats"`
	CostStats           domain.SessionCostStats  `json:"cost_stats,omitempty"`
	Model               string                   `json:"model,omitempty"`
	Tags                []string                 `json:"tags,omitempty"`
	TitleGenerated      bool                     `json:"title_generated,omitempty"`
	TitleInvalidated    bool                     `json:"title_invalidated,omitempty"`
	TitleGenerationTime *time.Time               `json:"title_generation_time,omitempty"`
	ContextID           string                   `json:"context_id,omitempty"`
}

ConversationMetadata contains metadata about a conversation

type ConversationStorage

type ConversationStorage interface {
	// SaveConversation saves a conversation with a unique ID
	SaveConversation(ctx context.Context, conversationID string, entries []domain.ConversationEntry, metadata ConversationMetadata) error

	// LoadConversation loads a conversation by its ID
	LoadConversation(ctx context.Context, conversationID string) ([]domain.ConversationEntry, ConversationMetadata, error)

	// ListConversations returns a list of conversation summaries
	ListConversations(ctx context.Context, limit, offset int) ([]ConversationSummary, error)

	// DeleteConversation removes a conversation by its ID
	DeleteConversation(ctx context.Context, conversationID string) error

	// UpdateConversationMetadata updates metadata for a conversation
	UpdateConversationMetadata(ctx context.Context, conversationID string, metadata ConversationMetadata) error

	// ListConversationsNeedingTitles returns conversations that need title generation
	ListConversationsNeedingTitles(ctx context.Context, limit int) ([]ConversationSummary, error)

	// Close closes the storage connection
	Close() error

	// Health checks if the storage is healthy and reachable
	Health(ctx context.Context) error
}

ConversationStorage defines the interface for persistent conversation storage

func NewStorage

func NewStorage(config StorageConfig) (ConversationStorage, error)

NewStorage creates a new storage instance based on the provided configuration

type ConversationSummary

type ConversationSummary struct {
	ID                  string                   `json:"id"`
	Title               string                   `json:"title"`
	CreatedAt           time.Time                `json:"created_at"`
	UpdatedAt           time.Time                `json:"updated_at"`
	MessageCount        int                      `json:"message_count"`
	TokenStats          domain.SessionTokenStats `json:"token_stats"`
	CostStats           domain.SessionCostStats  `json:"cost_stats,omitempty"`
	Model               string                   `json:"model,omitempty"`
	Tags                []string                 `json:"tags,omitempty"`
	Summary             string                   `json:"summary,omitempty"`
	TitleGenerated      bool                     `json:"title_generated,omitempty"`
	TitleInvalidated    bool                     `json:"title_invalidated,omitempty"`
	TitleGenerationTime *time.Time               `json:"title_generation_time,omitempty"`
}

ConversationSummary contains summary information about a conversation

type JsonlStorage added in v0.92.6

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

JsonlStorage implements ConversationStorage using JSONL files

func NewJsonlStorage added in v0.92.6

func NewJsonlStorage(config JsonlStorageConfig) (*JsonlStorage, error)

NewJsonlStorage creates a new JSONL storage instance

func (*JsonlStorage) Close added in v0.92.6

func (s *JsonlStorage) Close() error

Close closes the storage (no-op for JSONL)

func (*JsonlStorage) DeleteConversation added in v0.92.6

func (s *JsonlStorage) DeleteConversation(ctx context.Context, conversationID string) error

DeleteConversation removes a conversation file

func (*JsonlStorage) Health added in v0.92.6

func (s *JsonlStorage) Health(ctx context.Context) error

Health checks if the storage is accessible

func (*JsonlStorage) ListConversations added in v0.92.6

func (s *JsonlStorage) ListConversations(ctx context.Context, limit, offset int) ([]ConversationSummary, error)

ListConversations returns a list of conversation summaries

func (*JsonlStorage) ListConversationsNeedingTitles added in v0.92.6

func (s *JsonlStorage) ListConversationsNeedingTitles(ctx context.Context, limit int) ([]ConversationSummary, error)

ListConversationsNeedingTitles returns conversations that need title generation

func (*JsonlStorage) LoadConversation added in v0.92.6

func (s *JsonlStorage) LoadConversation(ctx context.Context, conversationID string) ([]domain.ConversationEntry, ConversationMetadata, error)

LoadConversation loads a conversation from a JSONL file

func (*JsonlStorage) SaveConversation added in v0.92.6

func (s *JsonlStorage) SaveConversation(ctx context.Context, conversationID string, entries []domain.ConversationEntry, metadata ConversationMetadata) error

SaveConversation saves a conversation to a JSONL file

func (*JsonlStorage) UpdateConversationMetadata added in v0.92.6

func (s *JsonlStorage) UpdateConversationMetadata(ctx context.Context, conversationID string, metadata ConversationMetadata) error

UpdateConversationMetadata updates only the metadata of a conversation

type JsonlStorageConfig added in v0.92.6

type JsonlStorageConfig struct {
	Path string `json:"path" yaml:"path"`
}

JsonlStorageConfig contains JSONL-specific configuration

type MemoryStorage added in v0.46.0

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

MemoryStorage implements ConversationStorage using in-memory storage This allows conversation history features to work without persistent storage

func NewMemoryStorage added in v0.46.0

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new in-memory storage instance

func (*MemoryStorage) Close added in v0.46.0

func (m *MemoryStorage) Close() error

Close closes the storage connection (no-op for memory storage)

func (*MemoryStorage) DeleteConversation added in v0.46.0

func (m *MemoryStorage) DeleteConversation(ctx context.Context, conversationID string) error

DeleteConversation removes a conversation by its ID

func (*MemoryStorage) Health added in v0.46.0

func (m *MemoryStorage) Health(ctx context.Context) error

Health checks if the storage is healthy and reachable

func (*MemoryStorage) ListConversations added in v0.46.0

func (m *MemoryStorage) ListConversations(ctx context.Context, limit, offset int) ([]ConversationSummary, error)

ListConversations returns a list of conversation summaries

func (*MemoryStorage) ListConversationsNeedingTitles added in v0.46.0

func (m *MemoryStorage) ListConversationsNeedingTitles(ctx context.Context, limit int) ([]ConversationSummary, error)

ListConversationsNeedingTitles returns conversations that need title generation

func (*MemoryStorage) LoadConversation added in v0.46.0

func (m *MemoryStorage) LoadConversation(ctx context.Context, conversationID string) ([]domain.ConversationEntry, ConversationMetadata, error)

LoadConversation loads a conversation by its ID

func (*MemoryStorage) SaveConversation added in v0.46.0

func (m *MemoryStorage) SaveConversation(ctx context.Context, conversationID string, entries []domain.ConversationEntry, metadata ConversationMetadata) error

SaveConversation saves a conversation with a unique ID

func (*MemoryStorage) UpdateConversationMetadata added in v0.46.0

func (m *MemoryStorage) UpdateConversationMetadata(ctx context.Context, conversationID string, metadata ConversationMetadata) error

UpdateConversationMetadata updates metadata for a conversation

type PostgresConfig

type PostgresConfig struct {
	Host     string `json:"host" yaml:"host"`
	Port     int    `json:"port" yaml:"port"`
	Database string `json:"database" yaml:"database"`
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
	SSLMode  string `json:"ssl_mode" yaml:"ssl_mode"`
}

PostgresConfig contains Postgres-specific configuration

type PostgresStorage

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

PostgresStorage implements ConversationStorage using PostgreSQL

func NewPostgresStorage

func NewPostgresStorage(config PostgresConfig) (*PostgresStorage, error)

NewPostgresStorage creates a new PostgreSQL storage instance

func (*PostgresStorage) Close

func (s *PostgresStorage) Close() error

Close closes the database connection

func (*PostgresStorage) DB added in v0.93.0

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

DB returns the underlying database connection

func (*PostgresStorage) DeleteConversation

func (s *PostgresStorage) DeleteConversation(ctx context.Context, conversationID string) error

DeleteConversation removes a conversation by its ID

func (*PostgresStorage) Health

func (s *PostgresStorage) Health(ctx context.Context) error

Health checks if the database is reachable and functional

func (*PostgresStorage) ListConversations

func (s *PostgresStorage) ListConversations(ctx context.Context, limit, offset int) ([]ConversationSummary, error)

ListConversations returns a list of conversation summaries

func (*PostgresStorage) ListConversationsNeedingTitles added in v0.46.0

func (s *PostgresStorage) ListConversationsNeedingTitles(ctx context.Context, limit int) ([]ConversationSummary, error)

ListConversationsNeedingTitles returns conversations that need title generation

func (*PostgresStorage) LoadConversation

func (s *PostgresStorage) LoadConversation(ctx context.Context, conversationID string) ([]domain.ConversationEntry, ConversationMetadata, error)

LoadConversation loads a conversation by its ID

func (*PostgresStorage) SaveConversation

func (s *PostgresStorage) SaveConversation(ctx context.Context, conversationID string, entries []domain.ConversationEntry, metadata ConversationMetadata) error

SaveConversation saves a conversation with its entries

func (*PostgresStorage) UpdateConversationMetadata

func (s *PostgresStorage) UpdateConversationMetadata(ctx context.Context, conversationID string, metadata ConversationMetadata) error

UpdateConversationMetadata updates metadata for a conversation

type RedisConfig

type RedisConfig struct {
	Host     string `json:"host" yaml:"host"`
	Port     int    `json:"port" yaml:"port"`
	Database int    `json:"database" yaml:"database"`
	Password string `json:"password,omitempty" yaml:"password,omitempty"`
	Username string `json:"username,omitempty" yaml:"username,omitempty"`
	TTL      int    `json:"ttl,omitempty" yaml:"ttl,omitempty"` // TTL in seconds, 0 means no expiration
}

RedisConfig contains Redis-specific configuration

type RedisStorage

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

RedisStorage implements ConversationStorage using Redis

func NewRedisStorage

func NewRedisStorage(config RedisConfig) (*RedisStorage, error)

NewRedisStorage creates a new Redis storage instance

func (*RedisStorage) Close

func (s *RedisStorage) Close() error

Close closes the Redis connection

func (*RedisStorage) DeleteConversation

func (s *RedisStorage) DeleteConversation(ctx context.Context, conversationID string) error

DeleteConversation removes a conversation by its ID

func (*RedisStorage) Health

func (s *RedisStorage) Health(ctx context.Context) error

Health checks if Redis is reachable and functional

func (*RedisStorage) ListConversations

func (s *RedisStorage) ListConversations(ctx context.Context, limit, offset int) ([]ConversationSummary, error)

ListConversations returns a list of conversation summaries

func (*RedisStorage) ListConversationsNeedingTitles added in v0.46.0

func (s *RedisStorage) ListConversationsNeedingTitles(ctx context.Context, limit int) ([]ConversationSummary, error)

ListConversationsNeedingTitles returns conversations that need title generation

func (*RedisStorage) LoadConversation

func (s *RedisStorage) LoadConversation(ctx context.Context, conversationID string) ([]domain.ConversationEntry, ConversationMetadata, error)

LoadConversation loads a conversation by its ID

func (*RedisStorage) SaveConversation

func (s *RedisStorage) SaveConversation(ctx context.Context, conversationID string, entries []domain.ConversationEntry, metadata ConversationMetadata) error

SaveConversation saves a conversation with its entries

func (*RedisStorage) UpdateConversationMetadata

func (s *RedisStorage) UpdateConversationMetadata(ctx context.Context, conversationID string, metadata ConversationMetadata) error

UpdateConversationMetadata updates metadata for a conversation

type SQLiteConfig

type SQLiteConfig struct {
	Path string `json:"path" yaml:"path"`
}

SQLiteConfig contains SQLite-specific configuration

type SQLiteStorage

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

SQLiteStorage implements ConversationStorage using SQLite

func NewSQLiteStorage

func NewSQLiteStorage(config SQLiteConfig) (*SQLiteStorage, error)

NewSQLiteStorage creates a new SQLite storage instance

func (*SQLiteStorage) Close

func (s *SQLiteStorage) Close() error

Close closes the database connection

func (*SQLiteStorage) DB added in v0.93.0

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

DB returns the underlying database connection

func (*SQLiteStorage) DeleteConversation

func (s *SQLiteStorage) DeleteConversation(ctx context.Context, conversationID string) error

DeleteConversation removes a conversation by its ID

func (*SQLiteStorage) Health

func (s *SQLiteStorage) Health(ctx context.Context) error

Health checks if the database is reachable and functional

func (*SQLiteStorage) ListConversations

func (s *SQLiteStorage) ListConversations(ctx context.Context, limit, offset int) ([]ConversationSummary, error)

ListConversations returns a list of conversation summaries

func (*SQLiteStorage) ListConversationsNeedingTitles added in v0.46.0

func (s *SQLiteStorage) ListConversationsNeedingTitles(ctx context.Context, limit int) ([]ConversationSummary, error)

ListConversationsNeedingTitles returns conversations that need title generation

func (*SQLiteStorage) LoadConversation

func (s *SQLiteStorage) LoadConversation(ctx context.Context, conversationID string) ([]domain.ConversationEntry, ConversationMetadata, error)

LoadConversation loads a conversation by its ID using simplified schema

func (*SQLiteStorage) SaveConversation

func (s *SQLiteStorage) SaveConversation(ctx context.Context, conversationID string, entries []domain.ConversationEntry, metadata ConversationMetadata) error

SaveConversation saves a conversation with its entries using simplified schema

func (*SQLiteStorage) UpdateConversationMetadata

func (s *SQLiteStorage) UpdateConversationMetadata(ctx context.Context, conversationID string, metadata ConversationMetadata) error

UpdateConversationMetadata updates metadata for a conversation

type StorageConfig

type StorageConfig struct {
	// Type specifies the storage backend type (sqlite, postgres, redis, jsonl)
	Type string `json:"type" yaml:"type"`

	// SQLite specific configuration
	SQLite SQLiteConfig `json:"sqlite,omitempty" yaml:"sqlite,omitempty"`

	// Postgres specific configuration
	Postgres PostgresConfig `json:"postgres,omitempty" yaml:"postgres,omitempty"`

	// Redis specific configuration
	Redis RedisConfig `json:"redis,omitempty" yaml:"redis,omitempty"`

	// JSONL specific configuration
	Jsonl JsonlStorageConfig `json:"jsonl,omitempty" yaml:"jsonl,omitempty"`
}

StorageConfig contains configuration for storage backends

func NewStorageFromConfig added in v0.46.0

func NewStorageFromConfig(cfg *config.Config) StorageConfig

NewStorageFromConfig creates a storage configuration from app config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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