Documentation
¶
Overview ¶
Package sqlite holds a complete Storage over SQLite (§3.2): every table the platform needs, created on construction. A working agent platform with no infrastructure to stand up first.
The package never imports a driver itself (§3.4). Hand it any *sql.DB opened with a SQLite driver, or call Open, which picks whichever database/sql driver the process has registered ("sqlite" from modernc.org/sqlite, or "sqlite3" from github.com/mattn/go-sqlite3).
The schema is the same one the TypeScript SqliteStorage creates, so both runtimes can read one file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var KvSchema = []string{
`CREATE TABLE IF NOT EXISTS kv (
key TEXT PRIMARY KEY, value TEXT NOT NULL, expiresAt INTEGER)`,
}
KvSchema is the DDL for the Kv table.
var Schema = []string{
`CREATE TABLE IF NOT EXISTS threads (
id TEXT PRIMARY KEY, title TEXT NOT NULL DEFAULT 'New Thread',
state TEXT NOT NULL DEFAULT 'IDLE', model TEXT NOT NULL DEFAULT 'gpt-4o',
createdAt INTEGER NOT NULL, updatedAt INTEGER NOT NULL)`,
`CREATE TABLE IF NOT EXISTS messages (
id TEXT PRIMARY KEY, threadId TEXT NOT NULL, agentId TEXT,
role TEXT NOT NULL, content TEXT NOT NULL, createdAt INTEGER NOT NULL,
seq INTEGER NOT NULL)`,
`CREATE INDEX IF NOT EXISTS messages_thread ON messages(threadId, seq)`,
`CREATE TABLE IF NOT EXISTS events (
id TEXT PRIMARY KEY, threadId TEXT NOT NULL, seq INTEGER NOT NULL,
type TEXT NOT NULL, payload TEXT, createdAt INTEGER NOT NULL)`,
`CREATE INDEX IF NOT EXISTS events_thread_seq ON events(threadId, seq)`,
`CREATE INDEX IF NOT EXISTS events_thread_type ON events(threadId, type, seq)`,
`CREATE TABLE IF NOT EXISTS usage (
id TEXT PRIMARY KEY, threadId TEXT NOT NULL, runId TEXT, agentId TEXT, agentName TEXT,
kind TEXT NOT NULL DEFAULT 'step', step INTEGER NOT NULL DEFAULT 0,
model TEXT, modelId TEXT,
inputTokens INTEGER NOT NULL, cachedInputTokens INTEGER NOT NULL,
cacheWriteInputTokens INTEGER NOT NULL DEFAULT 0,
outputTokens INTEGER NOT NULL, reasoningTokens INTEGER NOT NULL DEFAULT 0,
totalTokens INTEGER NOT NULL,
outcome TEXT NOT NULL DEFAULT 'finished', estimated INTEGER NOT NULL DEFAULT 0,
providerMetadata TEXT,
costMicros INTEGER, costCurrency TEXT, costSource TEXT,
createdAt INTEGER NOT NULL)`,
`CREATE INDEX IF NOT EXISTS usage_thread ON usage(threadId)`,
`CREATE INDEX IF NOT EXISTS usage_run ON usage(runId, createdAt)`,
}
Schema is the DDL, split per statement.
Functions ¶
Types ¶
type Kv ¶
type Kv struct {
// contains filtered or unexported fields
}
Kv is a Kv over SQLite, for a local setup whose storage is durable too.
The event sequence counter (§3.4) lives in the Kv. With an in-memory Kv beside a SQLite Storage, a restart resets the counter while the log keeps its numbers, so new events reuse old sequence numbers and every client's cursor drops them. Keeping the Kv in the same file as the log removes that failure entirely: one file, one lifetime.
Expiry is enforced on read. Incr and SET NX are single statements, so concurrent callers never collide on a counter or a lock.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is a Storage over SQLite.
func (*Storage) Events ¶
func (s *Storage) Events() ports.EventStore
func (*Storage) Messages ¶
func (s *Storage) Messages() ports.MessageStore
func (*Storage) Threads ¶
func (s *Storage) Threads() ports.ThreadStore
func (*Storage) Usage ¶
func (s *Storage) Usage() ports.UsageStore