Documentation
¶
Overview ¶
Package store persists Antares state behind a driver-agnostic interface so the same code runs on SQLite (single node) or Postgres (shared/multi node).
Index ¶
- Constants
- Variables
- func HashDeviceToken(token string) string
- func LooksLikeDeviceToken(s string) bool
- func NormalizeDeviceName(n string) (string, error)
- func NormalizeDevicePlatform(p string) string
- type Chunk
- type CronJob
- type CronRun
- type Device
- type Memory
- type Message
- type Meta
- type ModelUsage
- type Pairing
- type SearchHit
- type Session
- type SessionFilter
- type SocialAccount
- type Stats
- type Store
- type Usage
- type UsagePoint
- type VPSHost
Constants ¶
const ( // DeviceTokenPrefix starts every device token: "atd_" + 48 hex chars. DeviceTokenPrefix = "atd_" // DeviceTokenLen is the full length of a device token. DeviceTokenLen = len(DeviceTokenPrefix) + 2*deviceTokenBytes // DeviceNameMax is the longest accepted device name, in characters. DeviceNameMax = 64 )
const ( RoleSystem = "system" RoleUser = "user" RoleAssistant = "assistant" RoleTool = "tool" )
Role values for Message.
Variables ¶
var DevicePlatforms = []string{"desktop-macos", "desktop-windows", "desktop-linux", "cli", "other"}
DevicePlatforms are the accepted platform values; anything else is "other".
var ErrEmbeddingShape = errors.New("store: invalid embedding shape")
ErrEmbeddingShape is returned when a caller supplies a vector that cannot be indexed: empty, NaN/Inf, all-zero, or (for an existing collection) the wrong dimensionality.
var ErrInvalidDeviceName = errors.New("device name must be 1-64 characters")
ErrInvalidDeviceName is returned for an empty or over-long device name.
var ErrLegacyBadVector = errors.New("store: rag_chunks row has an unindexable embedding")
ErrLegacyBadVector wraps a persisted embedding that cannot be indexed (empty, all-zero, non-finite, or the wrong shape). Returned by ensureWarm so a corrupted row surfaces at the caller instead of silently dropping out of every search result — the "invisible omit" that hides real bugs.
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a lookup by id yields nothing.
Functions ¶
func HashDeviceToken ¶ added in v0.6.0
HashDeviceToken is the stored form of a device token: SHA-256, lowercase hex.
func LooksLikeDeviceToken ¶ added in v0.6.0
LooksLikeDeviceToken reports whether s has the device token shape, so callers skip a database lookup for anything else.
func NormalizeDeviceName ¶ added in v0.6.0
NormalizeDeviceName trims a name and checks its length (1-64 characters).
func NormalizeDevicePlatform ¶ added in v0.6.0
NormalizeDevicePlatform maps an unknown platform to "other".
Types ¶
type Chunk ¶
type Chunk struct {
ID string `json:"id"`
Collection string `json:"collection"`
DocID string `json:"doc_id"`
Path string `json:"path"`
Index int `json:"index"`
Content string `json:"content"`
Embedding []float32 `json:"-"`
Meta Meta `json:"meta"`
CreatedAt time.Time `json:"created_at"`
}
Chunk is one embedded text span in the builtin RAG index.
type CronJob ¶
type CronJob struct {
ID string `json:"id"`
Name string `json:"name"`
Schedule string `json:"schedule"`
Prompt string `json:"prompt"`
Enabled bool `json:"enabled"`
Target string `json:"target"`
Timezone string `json:"timezone"`
LastRun *time.Time `json:"last_run"`
NextRun *time.Time `json:"next_run"`
LastState string `json:"last_state"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Meta Meta `json:"meta"`
}
CronJob is a scheduled natural-language task.
type CronRun ¶
type CronRun struct {
ID string `json:"id"`
JobID string `json:"job_id"`
Status string `json:"status"` // running|ok|error|skipped
Output string `json:"output"`
Error string `json:"error"`
SessionID string `json:"session_id"`
StartedAt time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
}
CronRun records one execution of a CronJob.
type Device ¶ added in v0.6.0
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
Platform string `json:"platform"`
TokenHash string `json:"-"`
CreatedAt time.Time `json:"created_at"`
LastSeenAt *time.Time `json:"last_seen_at"`
RevokedAt *time.Time `json:"revoked_at"`
}
Device is a paired client (a desktop app, the CLI, later a phone) holding a long-lived device token. Only the token's SHA-256 is stored.
func PairDevice ¶ added in v0.6.0
PairDevice creates a device and returns it with its plain token. The token exists only in the return value; the store keeps its hash.
type Memory ¶
type Memory struct {
ID string `json:"id"`
Scope string `json:"scope"` // global|user|session|project
ScopeKey string `json:"scope_key"`
Key string `json:"key"`
Content string `json:"content"`
Tags string `json:"tags"` // JSON array
Source string `json:"source"`
Pinned bool `json:"pinned"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Memory is one agent-curated long-term fact.
type Message ¶
type Message struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Seq int64 `json:"seq"`
Role string `json:"role"`
Content string `json:"content"`
Reasoning string `json:"reasoning,omitempty"`
ToolCalls string `json:"tool_calls,omitempty"` // JSON array
ToolCallID string `json:"tool_call_id,omitempty"`
ToolName string `json:"tool_name,omitempty"`
Attachments string `json:"attachments,omitempty"` // JSON array
Model string `json:"model,omitempty"`
TokensIn int `json:"tokens_in"`
TokensOut int `json:"tokens_out"`
Hidden bool `json:"hidden"`
Compacted bool `json:"compacted"`
CreatedAt time.Time `json:"created_at"`
Meta Meta `json:"meta"`
}
Message is one turn element inside a session.
type ModelUsage ¶
type ModelUsage struct {
Model string `json:"model"`
Provider string `json:"provider"`
Calls int64 `json:"calls"`
TokensIn int64 `json:"tokens_in"`
TokensOut int64 `json:"tokens_out"`
Cost float64 `json:"cost"`
}
ModelUsage aggregates spend per model.
type Pairing ¶
type Pairing struct {
ID string `json:"id"`
Platform string `json:"platform"`
ExternalID string `json:"external_id"`
DisplayName string `json:"display_name"`
Status string `json:"status"` // pending|approved|revoked
Code string `json:"code"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Pairing is an approved external identity (Telegram/Discord user).
type SearchHit ¶
type SearchHit struct {
SessionID string `json:"session_id"`
SessionTitle string `json:"session_title"`
MessageID string `json:"message_id"`
Role string `json:"role"`
Snippet string `json:"snippet"`
CreatedAt time.Time `json:"created_at"`
Score float64 `json:"score"`
}
SearchHit is a full-text match inside a session.
type Session ¶
type Session struct {
ID string `json:"id"`
Title string `json:"title"`
Platform string `json:"platform"`
ChannelID string `json:"channel_id"`
UserID string `json:"user_id"`
Model string `json:"model"`
Provider string `json:"provider"`
Workspace string `json:"workspace"`
MessageCount int `json:"message_count"`
TokensIn int64 `json:"tokens_in"`
TokensOut int64 `json:"tokens_out"`
Cost float64 `json:"cost"`
Archived bool `json:"archived"`
Pinned bool `json:"pinned"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Meta Meta `json:"meta"`
}
Session is one conversation thread.
type SessionFilter ¶
type SessionFilter struct {
Platform string
// ExcludePlatforms hides sessions from these platforms — used to keep
// sub-agent sessions ("subagent", "background") out of the human's list.
ExcludePlatforms []string
UserID string
Query string
Archived *bool
Limit int
Offset int
OrderBy string // updated_at|created_at|message_count
}
SessionFilter narrows a session listing.
type SocialAccount ¶ added in v0.4.0
type SocialAccount struct {
ID string `json:"id"`
Platform string `json:"platform"`
DisplayName string `json:"display_name"`
Username string `json:"username"`
Password string `json:"-"` // plaintext only at the boundary; encrypted in DB
RecoveryCodes string `json:"-"` // plaintext only at the boundary; encrypted in DB
ProfileURL string `json:"profile_url"`
Status string `json:"status"` // not_created|pending|verification_required|connected|suspended|error
RAGNamespace string `json:"rag_namespace"`
SkillName string `json:"skill_name"`
LastCheckedAt *time.Time `json:"last_checked_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SocialAccount is one social media platform account. Password and recovery codes are encrypted at rest; plaintext lives only at the Store boundary.
type Stats ¶
type Stats struct {
Sessions int64 `json:"sessions"`
Messages int64 `json:"messages"`
Memories int64 `json:"memories"`
CronJobs int64 `json:"cron_jobs"`
TokensIn int64 `json:"tokens_in"`
TokensOut int64 `json:"tokens_out"`
Cost float64 `json:"cost"`
EmptySessions int64 `json:"empty_sessions"`
SizeBytes int64 `json:"size_bytes"`
}
Stats summarises the database for the dashboard header.
type Store ¶
type Store interface {
Driver() string
Close() error
Ping(ctx context.Context) error
Stats(ctx context.Context) (Stats, error)
CreateSession(ctx context.Context, s *Session) error
GetSession(ctx context.Context, id string) (*Session, error)
UpdateSession(ctx context.Context, s *Session) error
// SetSessionTitle updates only the title (and updated_at), leaving meta and
// the message counters untouched — so a title save from a stale in-memory
// struct cannot clobber a tool's concurrent meta write.
SetSessionTitle(ctx context.Context, id, title string) error
// TouchSession bumps only updated_at.
TouchSession(ctx context.Context, id string) error
ListSessions(ctx context.Context, f SessionFilter) ([]Session, int64, error)
DeleteSession(ctx context.Context, id string) error
DeleteSessions(ctx context.Context, ids []string) (int64, error)
DeleteEmptySessions(ctx context.Context) (int64, error)
CountEmptySessions(ctx context.Context) (int64, error)
PruneSessions(ctx context.Context, olderThan time.Time) (int64, error)
AppendMessage(ctx context.Context, m *Message) error
ListMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)
DeleteMessage(ctx context.Context, id string) error
// DeleteMessagesFrom removes a message and everything after it in its session,
// then recomputes the session tallies. Powers "edit message".
DeleteMessagesFrom(ctx context.Context, sessionID, fromID string) error
SearchMessages(ctx context.Context, query string, limit int) ([]SearchHit, error)
PutMemory(ctx context.Context, m *Memory) error
ListMemories(ctx context.Context, scope, scopeKey string, limit int) ([]Memory, error)
SearchMemories(ctx context.Context, query string, limit int) ([]Memory, error)
DeleteMemory(ctx context.Context, id string) error
ClearMemories(ctx context.Context, scope, scopeKey string) (int64, error)
PutChunks(ctx context.Context, chunks []Chunk) error
// ReplaceDocuments upserts chunks and, for each represented doc_id,
// deletes any surviving chunk_index strictly greater than the highest
// index in the batch. This is how a shrunken re-embed prunes its own
// tail without leaving unreachable rows in the collection.
ReplaceDocuments(ctx context.Context, collection string, chunks []Chunk) error
// DeleteDocuments removes every chunk belonging to the listed docIDs
// inside collection. Empty docIDs is a no-op; missing docs are ignored.
DeleteDocuments(ctx context.Context, collection string, docIDs []string) (int64, error)
SearchChunks(ctx context.Context, collection string, embedding []float32, text string, topK int, hybrid bool) ([]Chunk, []float64, error)
DeleteCollection(ctx context.Context, collection string) (int64, error)
ListCollections(ctx context.Context) ([]string, error)
PutVPSHost(ctx context.Context, v *VPSHost) error
GetVPSHost(ctx context.Context, id string) (*VPSHost, error)
ListVPSHosts(ctx context.Context) ([]VPSHost, error)
DeleteVPSHost(ctx context.Context, id string) error
SetVPSHostKey(ctx context.Context, id, hostKey string) error
PutCronJob(ctx context.Context, j *CronJob) error
GetCronJob(ctx context.Context, id string) (*CronJob, error)
ListCronJobs(ctx context.Context) ([]CronJob, error)
DeleteCronJob(ctx context.Context, id string) error
PutCronRun(ctx context.Context, r *CronRun) error
ListCronRuns(ctx context.Context, jobID string, limit int) ([]CronRun, error)
RecordUsage(ctx context.Context, u *Usage) error
UsageSeries(ctx context.Context, since time.Time, bucket string) ([]UsagePoint, error)
UsageByModel(ctx context.Context, since time.Time) ([]ModelUsage, error)
PutPairing(ctx context.Context, p *Pairing) error
GetPairing(ctx context.Context, platform, externalID string) (*Pairing, error)
ListPairings(ctx context.Context) ([]Pairing, error)
DeletePairing(ctx context.Context, id string) error
GetKV(ctx context.Context, key string) (string, error)
SetKV(ctx context.Context, key, value string) error
DeleteKV(ctx context.Context, key string) error
ListKV(ctx context.Context, prefix string) (map[string]string, error)
PutSocialAccount(ctx context.Context, a *SocialAccount) error
GetSocialAccount(ctx context.Context, id string) (*SocialAccount, error)
ListSocialAccounts(ctx context.Context) ([]SocialAccount, error)
DeleteSocialAccount(ctx context.Context, id string) error
CreateDevice(ctx context.Context, d *Device) error
GetDevice(ctx context.Context, id string) (*Device, error)
DeviceByTokenHash(ctx context.Context, tokenHash string) (*Device, error)
ListDevices(ctx context.Context) ([]Device, error)
RevokeDevice(ctx context.Context, id string) error
TouchDevice(ctx context.Context, id string, at time.Time) error
}
Store is the persistence contract every driver implements.
type Usage ¶
type Usage struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Provider string `json:"provider"`
Model string `json:"model"`
TokensIn int `json:"tokens_in"`
TokensOut int `json:"tokens_out"`
CacheRead int `json:"cache_read"`
Cost float64 `json:"cost"`
Source string `json:"source"`
CreatedAt time.Time `json:"created_at"`
}
Usage is a per-call accounting record powering the analytics page.
type UsagePoint ¶
type UsagePoint struct {
Bucket string `json:"bucket"`
TokensIn int64 `json:"tokens_in"`
TokensOut int64 `json:"tokens_out"`
Cost float64 `json:"cost"`
Calls int64 `json:"calls"`
}
UsagePoint is one bucket in the analytics timeseries.
type VPSHost ¶
type VPSHost struct {
ID string `json:"id"`
Label string `json:"label"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
AuthMethod string `json:"auth_method"` // password|key
Password string `json:"password,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
// HostKey is the server's SSH public key, pinned on first connect (TOFU).
// A later connection presenting a different key is refused. Not secret.
HostKey string `json:"host_key,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
VPSHost is a saved server the user can monitor and manage over SSH. The secret fields (Password, PrivateKey, Passphrase) are stored encrypted at rest; the store encrypts on Put and decrypts on read, so callers see plain values but the DB never holds them in the clear.