Documentation
¶
Index ¶
- Variables
- type APIKey
- type DBTX
- type Execution
- type File
- type FileFilter
- type Session
- type SkillRecord
- type Store
- func (s *Store) Close() error
- func (s *Store) CreateExecution(ctx context.Context, e *Execution) (*Execution, error)
- func (s *Store) CreateFile(ctx context.Context, f *File) (*File, error)
- func (s *Store) CreateKey(ctx context.Context, tenantID, name, keyHash string) (*APIKey, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) DeleteFile(ctx context.Context, id, tenantID string) error
- func (s *Store) DeleteSession(ctx context.Context, tenantID, externalID string) error
- func (s *Store) DeleteSkill(ctx context.Context, tenantID, name, version string) error
- func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (*APIKey, error)
- func (s *Store) GetExecution(ctx context.Context, id, tenantID string) (*Execution, error)
- func (s *Store) GetFile(ctx context.Context, id, tenantID string) (*File, error)
- func (s *Store) GetOrCreateSession(ctx context.Context, tenantID, externalID string) (*Session, error)
- func (s *Store) GetSession(ctx context.Context, tenantID, sessionID string) (*Session, error)
- func (s *Store) GetSessionByExternalID(ctx context.Context, tenantID, externalID string) (*Session, error)
- func (s *Store) GetSkill(ctx context.Context, tenantID, name, version string) (*SkillRecord, error)
- func (s *Store) InsertExecution(ctx context.Context, e *Execution) error
- func (s *Store) ListExecutions(ctx context.Context, tenantID string, limit, offset int) ([]Execution, error)
- func (s *Store) ListFileVersions(ctx context.Context, fileID, tenantID string) ([]*File, error)
- func (s *Store) ListFiles(ctx context.Context, filter FileFilter) ([]*File, error)
- func (s *Store) ListKeys(ctx context.Context, tenantID string) ([]APIKey, error)
- func (s *Store) ListSessionFiles(ctx context.Context, tenantID, sessionID string) ([]*File, error)
- func (s *Store) ListSkills(ctx context.Context, tenantID string) ([]SkillRecord, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) ResolveLatestVersion(ctx context.Context, tenantID, name string) (string, error)
- func (s *Store) RevokeKey(ctx context.Context, keyID string) error
- func (s *Store) RunInTx(ctx context.Context, fn func(tx *Store) error) error
- func (s *Store) TouchSession(ctx context.Context, sessionID string) error
- func (s *Store) UpdateExecution(ctx context.Context, e *Execution) error
- func (s *Store) UpdateFile(ctx context.Context, f *File) error
- func (s *Store) UpsertSkill(ctx context.Context, rec *SkillRecord) error
- func (s *Store) ValidateKey(ctx context.Context, keyHash string) (*APIKey, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested record does not exist.
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey struct {
ID string
KeyHash string
TenantID string
Name string
CreatedAt time.Time
RevokedAt *time.Time
}
APIKey represents a row in the sandbox.api_keys table.
type DBTX ¶ added in v0.3.0
type DBTX interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
DBTX is the common interface satisfied by both *sql.DB and *sql.Tx. Store methods use this internally so they work inside transactions without code changes.
type Execution ¶
type Execution struct {
ID string `json:"execution_id"`
SkillName string `json:"skill_name"`
SkillVersion string `json:"skill_version"`
TenantID string `json:"tenant_id"`
Status string `json:"status"`
Input json.RawMessage `json:"input,omitempty"`
Output json.RawMessage `json:"output,omitempty"`
Logs string `json:"logs,omitempty"`
FilesURL string `json:"files_url,omitempty"`
FilesList []string `json:"files_list,omitempty"`
DurationMs int64 `json:"duration_ms"`
Error *string `json:"error"`
CreatedAt time.Time `json:"created_at"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
}
Execution represents a row in the sandbox.executions table.
type File ¶ added in v0.2.0
type File struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
SessionID string `json:"session_id,omitempty"`
ExecutionID string `json:"execution_id,omitempty"`
Name string `json:"name"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
S3Key string `json:"s3_key"`
Version int `json:"version"`
ParentID *string `json:"parent_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
File represents a row in the sandbox.files table.
type FileFilter ¶ added in v0.2.0
FileFilter describes the filter and pagination parameters for listing files.
type Session ¶ added in v0.8.0
type Session struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
ExternalID string `json:"external_id"`
CreatedAt time.Time `json:"created_at"`
LastAccessedAt time.Time `json:"last_accessed_at"`
}
Session represents a row in the sandbox.sessions table.
type SkillRecord ¶
type SkillRecord struct {
TenantID string `json:"tenant_id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Lang string `json:"lang"`
UploadedAt time.Time `json:"uploaded_at"`
}
SkillRecord represents a row in the sandbox.skills metadata table.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps a PostgreSQL connection pool and provides data-access methods for the Skillbox runtime. When tx is set (via RunInTx), all queries go through the transaction instead of the pool.
func New ¶
New opens a connection pool to PostgreSQL using the provided DSN, verifies connectivity, and runs all embedded migrations. It returns a ready-to-use Store or an error if any step fails.
func NewWithDB ¶
NewWithDB creates a Store that wraps the given *sql.DB without running migrations. This is intended for use in tests that provide a mock or in-memory database.
func (*Store) CreateExecution ¶
CreateExecution inserts a new execution record with status "running". The Execution is mutated in place with the server-generated ID and timestamp.
func (*Store) CreateFile ¶ added in v0.2.0
CreateFile inserts a new file record. The File is mutated in place with the server-generated ID and timestamps.
func (*Store) CreateKey ¶
CreateKey inserts a new API key record and returns the populated APIKey (including the server-generated UUID and timestamp).
func (*Store) DeleteFile ¶ added in v0.2.0
DeleteFile removes a file record by its UUID, scoped to a tenant.
func (*Store) DeleteSession ¶ added in v0.8.0
DeleteSession removes a session record. This does NOT delete associated files — callers must clean those up separately.
func (*Store) DeleteSkill ¶
DeleteSkill removes a skill metadata record.
func (*Store) GetAPIKeyByHash ¶
GetAPIKeyByHash looks up an API key by its SHA-256 hex hash. It returns ErrNotFound if no matching key exists.
func (*Store) GetExecution ¶
GetExecution retrieves a single execution by its UUID, scoped to a tenant. Returns ErrNotFound if the execution does not exist or belongs to another tenant.
func (*Store) GetFile ¶ added in v0.2.0
GetFile retrieves a single file record by its UUID, scoped to a tenant. Returns ErrNotFound if the file does not exist or belongs to another tenant.
func (*Store) GetOrCreateSession ¶ added in v0.8.0
func (s *Store) GetOrCreateSession(ctx context.Context, tenantID, externalID string) (*Session, error)
GetOrCreateSession finds an existing session by tenant and external ID, or creates a new one if none exists. The returned session always has its LastAccessedAt updated to now.
func (*Store) GetSession ¶ added in v0.8.0
GetSession retrieves a session by its internal UUID, scoped to a tenant.
func (*Store) GetSessionByExternalID ¶ added in v0.8.0
func (s *Store) GetSessionByExternalID(ctx context.Context, tenantID, externalID string) (*Session, error)
GetSessionByExternalID retrieves a session by its external ID (VectorChat session UUID).
func (*Store) GetSkill ¶
GetSkill retrieves a single skill metadata record by tenant, name, and version.
func (*Store) InsertExecution ¶
InsertExecution creates a new execution record. This is an alias kept for compatibility with callers that set status before calling.
func (*Store) ListExecutions ¶
func (s *Store) ListExecutions(ctx context.Context, tenantID string, limit, offset int) ([]Execution, error)
ListExecutions returns executions for a tenant ordered by creation time (newest first), with pagination via limit and offset.
func (*Store) ListFileVersions ¶ added in v0.2.0
ListFileVersions returns all versions of a file, following the parent_id chain. It finds all files where id = fileID or parent_id = fileID, ordered by version descending. Scoped to tenant_id for isolation.
func (*Store) ListFiles ¶ added in v0.2.0
ListFiles returns files matching the given filter, ordered by creation time (newest first), with pagination via limit and offset.
func (*Store) ListKeys ¶
ListKeys returns all API keys belonging to the given tenant, ordered by creation time (newest first). Revoked keys are included so the caller can display their status.
func (*Store) ListSessionFiles ¶ added in v0.8.0
ListSessionFiles returns files linked to a session via the session_id column on sandbox.files.
func (*Store) ListSkills ¶
ListSkills returns all skill metadata for a tenant, ordered by name then version.
func (*Store) ResolveLatestVersion ¶ added in v0.2.0
ResolveLatestVersion returns the version string of the most recently uploaded skill for a given tenant and name. If no versions exist, it returns ErrNotFound.
func (*Store) RevokeKey ¶
RevokeKey soft-deletes an API key by setting its revoked_at timestamp. It returns an error if the key does not exist or is already revoked.
func (*Store) RunInTx ¶ added in v0.3.0
RunInTx executes fn inside a database transaction. If fn returns a non-nil error the transaction is rolled back; otherwise it is committed. The Store passed to fn shares the same transaction so all its methods operate atomically.
func (*Store) TouchSession ¶ added in v0.8.0
TouchSession updates the last_accessed_at timestamp for a session.
func (*Store) UpdateExecution ¶
UpdateExecution writes back mutable fields for an existing execution. Typically called once the execution has completed (or timed out).
func (*Store) UpdateFile ¶ added in v0.2.0
UpdateFile updates a file record's mutable fields: name, content_type, size_bytes, s3_key, and version. It also sets updated_at to now().
func (*Store) UpsertSkill ¶
func (s *Store) UpsertSkill(ctx context.Context, rec *SkillRecord) error
UpsertSkill inserts or updates a skill metadata record. On conflict (same tenant, name, version) it updates the description and lang.
func (*Store) ValidateKey ¶
ValidateKey looks up an API key by its SHA-256 hash. It returns the matching APIKey if the hash exists and the key has not been revoked. A nil APIKey (with nil error) is returned when the key is not found or has been revoked.