storage

package
v0.48.13 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 16 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"`
	Model               string                     `json:"model,omitempty"`
	Tags                []string                   `json:"tags,omitempty"`
	Summary             string                     `json:"summary,omitempty"`
	OptimizedMessages   []domain.ConversationEntry `json:"optimized_messages,omitempty"`
	TitleGenerated      bool                       `json:"title_generated,omitempty"`
	TitleInvalidated    bool                       `json:"title_invalidated,omitempty"`
	TitleGenerationTime *time.Time                 `json:"title_generation_time,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"`
	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 MemoryStorage added in v0.46.1

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.1

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new in-memory storage instance

func (*MemoryStorage) Close added in v0.46.1

func (m *MemoryStorage) Close() error

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

func (*MemoryStorage) DeleteConversation added in v0.46.1

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

DeleteConversation removes a conversation by its ID

func (*MemoryStorage) Health added in v0.46.1

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

Health checks if the storage is healthy and reachable

func (*MemoryStorage) ListConversations added in v0.46.1

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.1

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.1

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.1

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.1

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) 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.1

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.1

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) 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.1

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)
	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"`
}

StorageConfig contains configuration for storage backends

func NewStorageFromConfig added in v0.46.1

func NewStorageFromConfig(cfg *config.Config) StorageConfig

NewStorageFromConfig creates a storage configuration from app config

Jump to

Keyboard shortcuts

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