storage

package
v0.0.1-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindExecutable

func BindExecutable(s *Storage, dbPath string) error

BindExecutable is a no-op when built without the binddb tag.

Types

type Config

type Config struct {
	ID        int64     `json:"id"`
	Section   string    `json:"section"` // e.g., "llm", "gateway", "storage"
	Key       string    `json:"key"`     // e.g., "apiKey", "baseUrl", "model"
	Value     string    `json:"value"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Event

type Event struct {
	ID          int64         `json:"id"`
	Title       string        `json:"title"`
	Content     string        `json:"content"`
	Priority    EventPriority `json:"priority"` // 0-3
	Status      string        `json:"status"`   // pending, processing, completed, dismissed
	Channel     string        `json:"channel"`  // telegram, discord, etc (empty = all)
	CreatedAt   time.Time     `json:"created_at"`
	ProcessedAt *time.Time    `json:"processed_at,omitempty"`
}

type EventPriority

type EventPriority int

EventPriority levels (lower = higher priority) 0 = Critical (broadcast to all channels immediately) 1 = Important (channel broadcast) 2 = Normal (process when idle) 3 = Low (process when available)

const (
	PriorityCritical EventPriority = 0 // Broadcast to all channels
	PriorityHigh     EventPriority = 1 // Broadcast to configured channels
	PriorityNormal   EventPriority = 2 // Process when idle
	PriorityLow      EventPriority = 3 // Process when available
)

type FileRecord

type FileRecord struct {
	ID        int64     `json:"id"`
	Path      string    `json:"path"`
	Content   string    `json:"content"`
	MimeType  string    `json:"mime_type"`
	CreatedAt time.Time `json:"created_at"`
}

type Memory

type Memory struct {
	ID         int64     `json:"id"`
	Key        string    `json:"key"`
	Text       string    `json:"text"`     // memory content
	Category   string    `json:"category"` // preference, decision, fact, entity, other
	Importance float64   `json:"importance"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

type Message

type Message struct {
	ID         int64     `json:"id"`
	SessionKey string    `json:"session_key"`
	Role       string    `json:"role"` // user, assistant, system
	Content    string    `json:"content"`
	CreatedAt  time.Time `json:"created_at"`
}

type SessionMeta

type SessionMeta struct {
	SessionKey               string    `json:"session_key"`
	TotalTokens              int       `json:"total_tokens"`
	CompactionCount          int       `json:"compaction_count"`
	LastSummary              string    `json:"last_summary"`
	MemoryFlushAt            time.Time `json:"memory_flush_at"`
	MemoryFlushCompactionCnt int       `json:"memory_flush_compaction_count"`
	UpdatedAt                time.Time `json:"updated_at"`
}

type Storage

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

func New

func New(dbPath string) (*Storage, error)

func (*Storage) AddEvent

func (s *Storage) AddEvent(title, content string, priority EventPriority, channel string) (int64, error)

AddEvent adds a new event to the database

func (*Storage) AddFile

func (s *Storage) AddFile(path, content, mimeType string) error

func (*Storage) AddMemory

func (s *Storage) AddMemory(text, category string, importance float64) (int64, error)

func (*Storage) AddMessage

func (s *Storage) AddMessage(sessionKey, role, content string) error

func (*Storage) ArchiveMessages

func (s *Storage) ArchiveMessages(sessionKey string, beforeID int64) error

func (*Storage) ClearConfigSection

func (s *Storage) ClearConfigSection(section string) error

ClearConfigSection clears a section

func (*Storage) ClearMessages

func (s *Storage) ClearMessages(sessionKey string) error

func (*Storage) ClearOldEvents

func (s *Storage) ClearOldEvents(olderThanHours int) error

ClearOldEvents removes completed/dismissed events older than specified hours

func (*Storage) Close

func (s *Storage) Close() error

func (*Storage) ConfigExists

func (s *Storage) ConfigExists(section string) (bool, error)

ConfigExists checks whether a section exists

func (*Storage) DeleteConfig

func (s *Storage) DeleteConfig(section, key string) error

DeleteConfig deletes a config entry

func (*Storage) DeleteMemory

func (s *Storage) DeleteMemory(key string) error

func (*Storage) DeleteMemoryByID

func (s *Storage) DeleteMemoryByID(id int64) error

func (*Storage) Exec

func (s *Storage) Exec(query string, args ...interface{}) (interface{}, error)

Exec executes a raw SQL query

func (*Storage) ExportConfig

func (s *Storage) ExportConfig() ([]byte, error)

ExportConfig exports all configs as JSON

func (*Storage) ExportMemories

func (s *Storage) ExportMemories() ([]byte, error)

Export memories to JSON

func (*Storage) GetAllMemories

func (s *Storage) GetAllMemories(limit int) ([]Memory, error)

func (*Storage) GetConfig

func (s *Storage) GetConfig(section, key string) (string, error)

GetConfig reads a config value

func (*Storage) GetConfigSection

func (s *Storage) GetConfigSection(section string) (map[string]string, error)

GetConfigSection reads all config values in a section

func (*Storage) GetEventCount

func (s *Storage) GetEventCount() (map[string]int, error)

GetEventCount returns counts by status

func (*Storage) GetFile

func (s *Storage) GetFile(path string) (*FileRecord, error)

func (*Storage) GetMemoriesByCategory

func (s *Storage) GetMemoriesByCategory(category string) ([]Memory, error)

func (*Storage) GetMemory

func (s *Storage) GetMemory(idOrKey string) (Memory, error)

func (*Storage) GetMessages

func (s *Storage) GetMessages(sessionKey string, limit int) ([]Message, error)

func (*Storage) GetNextEvent

func (s *Storage) GetNextEvent() (*Event, error)

GetNextEvent returns the highest priority pending event

func (*Storage) GetPendingEvents

func (s *Storage) GetPendingEvents(limit int) ([]Event, error)

GetPendingEvents returns pending events ordered by priority (0 first)

func (*Storage) GetSessionMeta

func (s *Storage) GetSessionMeta(sessionKey string) (SessionMeta, error)

func (*Storage) ImportMemory

func (s *Storage) ImportMemory(key, value, category string) error

Import from MD-style data (simplified)

func (*Storage) ListFiles

func (s *Storage) ListFiles() ([]FileRecord, error)

func (*Storage) Query

func (s *Storage) Query(query string, args ...interface{}) (interface{}, error)

Query executes a raw SQL query and returns rows

func (*Storage) SearchMemories

func (s *Storage) SearchMemories(keyword string) ([]Memory, error)

func (*Storage) SetConfig

func (s *Storage) SetConfig(section, key, value string) error

SetConfig writes a config entry to the database

func (*Storage) SetMemory

func (s *Storage) SetMemory(key, text, category string) error

func (*Storage) Stats

func (s *Storage) Stats() (map[string]int, error)

func (*Storage) UpdateEventStatus

func (s *Storage) UpdateEventStatus(id int64, status string) error

UpdateEventStatus updates an event's status

func (*Storage) UpsertSessionMeta

func (s *Storage) UpsertSessionMeta(meta SessionMeta) error

Jump to

Keyboard shortcuts

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