storage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package storage provides a storage interface for omniagent.

Storage backends are used by the agent and skills for:

  • Caching expensive operations (API responses, generated reports)
  • Persisting conversation state
  • Storing user preferences

Available Backends

  • memory: In-memory storage (default, no persistence)
  • sqlite: SQLite database (recommended for Lightsail)
  • dynamodb: AWS DynamoDB (for serverless deployments)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("key not found")
	ErrClosed   = errors.New("storage is closed")
)

Common errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Type is the storage backend type: "memory", "sqlite", "dynamodb".
	Type string `yaml:"type" json:"type"`

	// Path is the database path (for sqlite).
	Path string `yaml:"path,omitempty" json:"path,omitempty"`

	// TableName is the table name (for dynamodb).
	TableName string `yaml:"table_name,omitempty" json:"table_name,omitempty"`

	// Region is the AWS region (for dynamodb).
	Region string `yaml:"region,omitempty" json:"region,omitempty"`
}

Config configures storage creation.

type Document

type Document struct {
	// ID is the document identifier.
	ID string

	// Data contains the document fields.
	Data map[string]any

	// Metadata contains system metadata.
	Metadata map[string]string

	// CreatedAt is when the document was created.
	CreatedAt time.Time

	// UpdatedAt is when the document was last modified.
	UpdatedAt time.Time
}

Document represents a stored document.

type DocumentStorage

type DocumentStorage interface {
	Storage

	// Put stores a document in a collection.
	Put(ctx context.Context, collection string, doc Document) error

	// Query retrieves documents matching a filter.
	Query(ctx context.Context, collection string, filter map[string]any) ([]Document, error)

	// DeleteDoc removes a document by ID.
	DeleteDoc(ctx context.Context, collection, id string) error
}

DocumentStorage extends Storage with document operations.

type Storage

type Storage interface {
	// Get retrieves a value by key.
	// Returns ErrNotFound if the key doesn't exist or has expired.
	Get(ctx context.Context, key string) ([]byte, error)

	// Set stores a value with an optional TTL.
	// If ttl is 0, the value never expires.
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

	// Delete removes a key.
	// Returns nil if the key doesn't exist.
	Delete(ctx context.Context, key string) error

	// Close releases storage resources.
	Close() error
}

Storage is the primary storage interface.

Directories

Path Synopsis
Package memory provides an in-memory storage backend.
Package memory provides an in-memory storage backend.
Package sqlite provides a SQLite storage backend.
Package sqlite provides a SQLite storage backend.

Jump to

Keyboard shortcuts

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