Documentation
¶
Index ¶
- Variables
- func AutomationJobRowToStrings(jsonStr string) []string
- func AutomationStringsToJSON(ss []string) string
- func GenerateAutomationAPIKey() (rawKey, hash, prefix string, err error)
- func HashAutomationAPIKey(rawKey string) string
- func IsAutomationAPIKey(s string) bool
- func MaskAutomationAPIKey(rawKey string) string
- func TimePtrToUnix(t *time.Time) *int64
- func UnixNow() int64
- func UnixPtrToTime(u *int64) *time.Time
- type AutomationAPIKeyRow
- type AutomationJobRow
- type AutomationRunRow
- type Config
- type DB
- func (db *DB) Close() error
- func (db *DB) CountUnreadByAgents(ctx context.Context, agentIDs []string) (map[string]int, error)
- func (db *DB) CreateAutomationAPIKey(ctx context.Context, row AutomationAPIKeyRow) error
- func (db *DB) CreateAutomationJob(ctx context.Context, row AutomationJobRow) error
- func (db *DB) CreateAutomationRun(ctx context.Context, row AutomationRunRow) error
- func (db *DB) CreateSessionTask(ctx context.Context, task SessionTask) error
- func (db *DB) DSN() string
- func (db *DB) DeleteAutomationAPIKey(ctx context.Context, id string) error
- func (db *DB) DeleteAutomationJob(ctx context.Context, id, ownerID string) error
- func (db *DB) DeleteCredential(ctx context.Context, key string) error
- func (db *DB) DeleteMessage(ctx context.Context, msgID string) error
- func (db *DB) DeleteProfile(ctx context.Context, id string) error
- func (db *DB) DeleteSessionTask(ctx context.Context, sessionID, taskID string) error
- func (db *DB) DeleteTeam(ctx context.Context, id string) error
- func (db *DB) Driver() Driver
- func (db *DB) FindProfilesByRole(ctx context.Context, role string) ([]GAgentProfile, error)
- func (db *DB) FindProfilesByTeam(ctx context.Context, teamID string) ([]GAgentProfile, error)
- func (db *DB) GetAutomationAPIKeyByHash(ctx context.Context, hash string) (*AutomationAPIKeyRow, error)
- func (db *DB) GetAutomationJob(ctx context.Context, id string) (*AutomationJobRow, error)
- func (db *DB) GetAutomationRun(ctx context.Context, id string) (*AutomationRunRow, error)
- func (db *DB) GetCredential(ctx context.Context, key string) (string, bool, error)
- func (db *DB) GetFileSessions(ctx context.Context, filePath string) ([]SessionFile, error)
- func (db *DB) GetMessage(ctx context.Context, msgID string) (GMailboxMessage, error)
- func (db *DB) GetMessageHistory(ctx context.Context, toAgent string, limit int) ([]GMailboxMessage, error)
- func (db *DB) GetMessageThread(ctx context.Context, rootID string) ([]GMailboxMessage, error)
- func (db *DB) GetProfile(ctx context.Context, id string) (GAgentProfile, error)
- func (db *DB) GetSessionFiles(ctx context.Context, sessionID string) ([]SessionFile, error)
- func (db *DB) GetSessionTask(ctx context.Context, sessionID, taskID string) (SessionTask, error)
- func (db *DB) GetTeam(ctx context.Context, id string) (GTeam, error)
- func (db *DB) GetTeamAgents(ctx context.Context, teamID string) ([]string, error)
- func (db *DB) GetTeamByName(ctx context.Context, name string) (GTeam, error)
- func (db *DB) GetUnreadMessages(ctx context.Context, toAgent string) ([]GMailboxMessage, error)
- func (db *DB) GormDB() *gorm.DB
- func (db *DB) HasSessionFileEntry(ctx context.Context, sessionID string) (bool, error)
- func (db *DB) Initialize(ctx context.Context) error
- func (db *DB) InitializeAutomationDaemon(ctx context.Context) error
- func (db *DB) InsertMessage(ctx context.Context, row GMailboxMessage) error
- func (db *DB) ListAutomationAPIKeys(ctx context.Context) ([]*AutomationAPIKeyRow, error)
- func (db *DB) ListAutomationJobs(ctx context.Context, ownerID string) ([]*AutomationJobRow, error)
- func (db *DB) ListAutomationRuns(ctx context.Context, jobID string, limit int) ([]*AutomationRunRow, error)
- func (db *DB) ListCredentialKeys(ctx context.Context) ([]string, error)
- func (db *DB) ListProfiles(ctx context.Context) ([]GAgentProfile, error)
- func (db *DB) ListSessionTasks(ctx context.Context, sessionID string) ([]SessionTask, error)
- func (db *DB) ListTeams(ctx context.Context) ([]GTeam, error)
- func (db *DB) MarkAllMessagesRead(ctx context.Context, toAgent string) error
- func (db *DB) MarkMessageRead(ctx context.Context, msgID string) error
- func (db *DB) NextSessionTaskPosition(ctx context.Context, sessionID string) (int, error)
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) RevokeAutomationAPIKey(ctx context.Context, id string) error
- func (db *DB) SQL() *sql.DB
- func (db *DB) SetProfileTeam(ctx context.Context, agentID, teamID string) error
- func (db *DB) UpdateAutomationJob(ctx context.Context, row AutomationJobRow) error
- func (db *DB) UpdateAutomationRun(ctx context.Context, row AutomationRunRow) error
- func (db *DB) UpdateSessionTask(ctx context.Context, task SessionTask) error
- func (db *DB) UpsertCredential(ctx context.Context, key, plaintext string) error
- func (db *DB) UpsertProfile(ctx context.Context, row GAgentProfile) error
- func (db *DB) UpsertProfileIfAbsent(ctx context.Context, row GAgentProfile) error
- func (db *DB) UpsertSessionFile(ctx context.Context, sf SessionFile) error
- func (db *DB) UpsertTeam(ctx context.Context, row GTeam) error
- type Driver
- type GAgentProfile
- type GMailboxMessage
- type GTeam
- type SessionFile
- type SessionTask
Constants ¶
This section is empty.
Variables ¶
var ErrMessageNotFound = errors.New("mailbox message not found")
ErrMessageNotFound is returned when a requested mailbox message does not exist.
var ErrProfileNotFound = errors.New("agent profile not found")
ErrProfileNotFound is returned when a requested agent profile does not exist.
var ErrTeamNotFound = errors.New("team not found")
ErrTeamNotFound is returned when a requested team does not exist.
Functions ¶
func AutomationStringsToJSON ¶
func GenerateAutomationAPIKey ¶
GenerateAutomationAPIKey creates a new random key with the sats_ prefix. Returns the raw key (shown once) and its SHA-256 hash.
func HashAutomationAPIKey ¶
HashAutomationAPIKey returns the SHA-256 hex hash of a raw key.
func IsAutomationAPIKey ¶
IsAutomationAPIKey reports whether s looks like a sats_ prefixed key.
func MaskAutomationAPIKey ¶
MaskAutomationAPIKey returns a display-safe version: "sats_****<last4>".
func TimePtrToUnix ¶
func UnixPtrToTime ¶
Types ¶
type AutomationAPIKeyRow ¶
type AutomationAPIKeyRow struct {
ID string
KeyHash string // SHA-256 hex of the raw key
KeyPrefix string // first 12 chars of raw key for display ("sats_a1b2c3")
Label string
OwnerID string
Enabled bool
CreatedAt int64
// ExpiresAt is a Unix timestamp; 0 means no expiry.
ExpiresAt int64
}
AutomationAPIKeyRow is the DB row for a daemon API key.
type AutomationJobRow ¶
type AutomationJobRow struct {
ID string
OwnerID string // user ID from the calling app; "" = system/unowned
Name string
Description string
TriggerType string
TriggerCron string
TriggerInterval int64 // nanoseconds
TriggerRunAt *int64
AgentSlug string // optional: slug of a named agent in seshat-ai
AgentBaseType string
AgentToolsJSON string
AgentSkillsJSON string
AgentModel string
AgentMaxTurns int
AgentSysPrompt string
Task string
Status string
LastRunAt *int64
NextRunAt *int64
LastRunStatus string
CreatedAt int64
UpdatedAt int64
}
AutomationJobRow is the DB representation of a persisted automation job.
type AutomationRunRow ¶
type AutomationRunRow struct {
ID string
JobID string
StartedAt int64
EndedAt *int64
Status string
Output string
Error string
CreatedAt int64
}
AutomationRunRow is the DB representation of a single job execution.
type Config ¶
type Config struct {
Driver Driver
DSN string
AutoMigrate bool // when true, runs versioned schema migrations on Open
BusyTimeoutMS int // SQLite only
}
Config describes how to open and initialize an application database.
func DefaultMySQLConfig ¶
DefaultMySQLConfig returns a default MySQL configuration.
func DefaultPostgresConfig ¶
DefaultPostgresConfig returns a default PostgreSQL configuration.
func DefaultSQLiteConfig ¶
DefaultSQLiteConfig returns a pragmatic default SQLite configuration for local Seshat persistence.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the shared low-level application database handle. Runtime subsystems such as session storage can depend on it now, and future app domains like users/roles can reuse the same connection and migration layer later.
func Open ¶
Open creates a database handle and initializes the shared schema when AutoMigrate is enabled.
func (*DB) Close ¶
Close closes the underlying database handle. For SQLite, PRAGMA optimize is run first to update the query planner statistics.
func (*DB) CountUnreadByAgents ¶
CountUnreadByAgents returns a map of agentID → unread message count for each ID in the given slice. Agents with zero unread messages are absent from the result map (treat missing keys as 0). A single GROUP BY query is used regardless of how many agent IDs are provided.
func (*DB) CreateAutomationAPIKey ¶
func (db *DB) CreateAutomationAPIKey(ctx context.Context, row AutomationAPIKeyRow) error
func (*DB) CreateAutomationJob ¶
func (db *DB) CreateAutomationJob(ctx context.Context, row AutomationJobRow) error
func (*DB) CreateAutomationRun ¶
func (db *DB) CreateAutomationRun(ctx context.Context, row AutomationRunRow) error
func (*DB) CreateSessionTask ¶
func (db *DB) CreateSessionTask(ctx context.Context, task SessionTask) error
func (*DB) DeleteAutomationAPIKey ¶
func (*DB) DeleteAutomationJob ¶
func (*DB) DeleteCredential ¶
DeleteCredential removes the credential for key. No-op if it does not exist.
func (*DB) DeleteMessage ¶
DeleteMessage removes a message record permanently.
func (*DB) DeleteProfile ¶
DeleteProfile removes the profile with the given ID. No-op if absent.
func (*DB) DeleteSessionTask ¶
func (*DB) DeleteTeam ¶
DeleteTeam removes the team with the given ID. No-op if absent.
func (*DB) FindProfilesByRole ¶
FindProfilesByRole returns all profiles whose role equals the given value.
func (*DB) FindProfilesByTeam ¶
FindProfilesByTeam returns all profiles belonging to the given team.
func (*DB) GetAutomationAPIKeyByHash ¶
func (db *DB) GetAutomationAPIKeyByHash(ctx context.Context, hash string) (*AutomationAPIKeyRow, error)
GetAutomationAPIKeyByHash looks up an active, non-expired key by its SHA-256 hash. Returns nil, nil when the key does not exist, is disabled, or is expired.
func (*DB) GetAutomationJob ¶
func (*DB) GetAutomationRun ¶
func (*DB) GetCredential ¶
GetCredential retrieves and decrypts the value stored under key. Returns ("", false, nil) when the key does not exist.
func (*DB) GetFileSessions ¶
GetFileSessions returns all sessions that touched a given file path, ordered by most recent first.
func (*DB) GetMessage ¶
GetMessage returns a single message by ID.
func (*DB) GetMessageHistory ¶
func (db *DB) GetMessageHistory(ctx context.Context, toAgent string, limit int) ([]GMailboxMessage, error)
GetMessageHistory returns up to limit messages for toAgent, newest first.
func (*DB) GetMessageThread ¶
GetMessageThread returns all messages in a thread rooted at rootID, including the root itself, ordered oldest first.
func (*DB) GetProfile ¶
GetProfile returns the profile with the given ID. Returns ErrProfileNotFound when no record matches.
func (*DB) GetSessionFiles ¶
GetSessionFiles returns all file operations recorded for a session, ordered by timestamp ascending.
func (*DB) GetSessionTask ¶
func (*DB) GetTeam ¶
GetTeam returns the team with the given ID. Returns ErrTeamNotFound when no record matches.
func (*DB) GetTeamAgents ¶
GetTeamAgents returns the distinct to_agent values that have received messages tagged with teamID. Used for broadcast expansion.
func (*DB) GetTeamByName ¶
GetTeamByName returns the team with the given name. Returns ErrTeamNotFound when no record matches.
func (*DB) GetUnreadMessages ¶
GetUnreadMessages returns all unread messages for toAgent, oldest first.
func (*DB) HasSessionFileEntry ¶
HasSessionFileEntry returns true if session_files already has at least one row for the given session. Used to detect whether backfill is needed.
func (*DB) Initialize ¶
Initialize applies only the public engine's core persistence migrations. Product/backend schema lives in the private product repository.
func (*DB) InitializeAutomationDaemon ¶
InitializeAutomationDaemon applies daemon-specific migrations on top of the core migrations. Call this in the seshat-automation binary after Initialize.
func (*DB) InsertMessage ¶
func (db *DB) InsertMessage(ctx context.Context, row GMailboxMessage) error
InsertMessage writes a new message record.
func (*DB) ListAutomationAPIKeys ¶
func (db *DB) ListAutomationAPIKeys(ctx context.Context) ([]*AutomationAPIKeyRow, error)
func (*DB) ListAutomationJobs ¶
ListAutomationJobs returns all jobs, optionally filtered by owner. Pass ownerID = "" to list all jobs (system/admin use).
func (*DB) ListAutomationRuns ¶
func (*DB) ListCredentialKeys ¶
ListCredentialKeys returns the stored keys without their values.
func (*DB) ListProfiles ¶
func (db *DB) ListProfiles(ctx context.Context) ([]GAgentProfile, error)
ListProfiles returns all profiles ordered by nickname.
func (*DB) ListSessionTasks ¶
func (*DB) MarkAllMessagesRead ¶
MarkAllMessagesRead sets read_at to now for all unread messages of toAgent.
func (*DB) MarkMessageRead ¶
MarkMessageRead sets read_at to now for the given message ID.
func (*DB) NextSessionTaskPosition ¶
func (*DB) RevokeAutomationAPIKey ¶
func (*DB) SQL ¶
SQL exposes the underlying sql.DB for backend implementations that need transactions or driver-specific operations (e.g. sqlite_backend.go).
func (*DB) SetProfileTeam ¶
SetProfileTeam updates team_id on a single agent profile. Pass an empty teamID to remove the agent from its team.
func (*DB) UpdateAutomationJob ¶
func (db *DB) UpdateAutomationJob(ctx context.Context, row AutomationJobRow) error
func (*DB) UpdateAutomationRun ¶
func (db *DB) UpdateAutomationRun(ctx context.Context, row AutomationRunRow) error
func (*DB) UpdateSessionTask ¶
func (db *DB) UpdateSessionTask(ctx context.Context, task SessionTask) error
func (*DB) UpsertCredential ¶
UpsertCredential encrypts plaintext and stores it under key.
func (*DB) UpsertProfile ¶
func (db *DB) UpsertProfile(ctx context.Context, row GAgentProfile) error
UpsertProfile inserts or fully replaces a profile record.
func (*DB) UpsertProfileIfAbsent ¶
func (db *DB) UpsertProfileIfAbsent(ctx context.Context, row GAgentProfile) error
UpsertProfileIfAbsent inserts the profile only when no record with the same ID exists. Used for seeding built-in profiles without overwriting user edits.
func (*DB) UpsertSessionFile ¶
func (db *DB) UpsertSessionFile(ctx context.Context, sf SessionFile) error
UpsertSessionFile records a file operation for a session. When tool_use_id is non-empty, INSERT OR IGNORE silently skips duplicates (the unique index on tool_use_id WHERE tool_use_id != ” enforces this).
type Driver ¶
type Driver string
Driver identifies a database driver supported by the shared DB module.
type GAgentProfile ¶
type GAgentProfile struct {
// ID is a UUID string — globally unique, generated once at creation.
ID string `gorm:"primaryKey;size:36"`
Nickname string `gorm:"not null"`
Role string `gorm:"not null;index"`
TeamID string `gorm:"column:team_id;index"`
// SystemPromptTemplate is the raw template; {{.Nickname}} is resolved at runtime.
SystemPromptTemplate string `gorm:"column:system_prompt_template;type:text;not null"`
Model string `gorm:"column:model"`
SkillsJSON string `gorm:"column:skills_json;type:text;not null;default:'[]'"`
MetadataJSON string `gorm:"column:metadata_json;type:text;not null;default:'{}'"`
CreatedAtUnix int64 `gorm:"column:created_at_unix;autoCreateTime:unix"`
UpdatedAtUnix int64 `gorm:"column:updated_at_unix;autoUpdateTime:unix"`
}
GAgentProfile is the GORM model for the agent_profiles table.
func (GAgentProfile) TableName ¶
func (GAgentProfile) TableName() string
type GMailboxMessage ¶
type GMailboxMessage struct {
ID string `gorm:"primaryKey;size:36"`
Kind string `gorm:"not null;index"`
FromAgent string `gorm:"column:from_agent;not null;index"`
ToAgent string `gorm:"column:to_agent;not null;index"`
Subject string `gorm:"not null"`
Body string `gorm:"type:text;not null"`
ReplyTo string `gorm:"column:reply_to;index"`
TeamID string `gorm:"column:team_id;index"`
ReadAt *int64 `gorm:"column:read_at"`
CreatedAt int64 `gorm:"column:created_at;not null;index"`
}
GMailboxMessage is the GORM model for the mailbox_messages table.
func (GMailboxMessage) TableName ¶
func (GMailboxMessage) TableName() string
type GTeam ¶
type GTeam struct {
ID string `gorm:"primaryKey;size:36"`
Name string `gorm:"not null;uniqueIndex"`
Description string `gorm:"column:description;type:text;not null;default:''"`
MetadataJSON string `gorm:"column:metadata_json;type:text;not null;default:'{}'"`
CreatedAtUnix int64 `gorm:"column:created_at_unix;autoCreateTime:unix"`
UpdatedAtUnix int64 `gorm:"column:updated_at_unix;autoUpdateTime:unix"`
}
GTeam is the GORM model for the teams table.
type SessionFile ¶
type SessionFile struct {
ID int64
SessionID string
ToolUseID string // foreign key into session_transcript_entries JSON
FilePath string
Operation string // "create" | "update" | "edit" | "patch"
TimestampUnix int64
LinesAdded int
LinesRemoved int
}
SessionFile represents one file operation recorded against a session. ToolUseID is the tool_use_id from the transcript — use it to look up the full ToolResultContent.Metadata (structured_patch, git_diff, content, …) in session_transcript_entries without scanning the whole transcript.