Documentation
¶
Overview ¶
Package store owns Codex Switch's shared domain types and one SQLite database.
It persists routing facts and the responses the relay completed: no credentials, allowance snapshots, rates, provider abstraction, migrations, retries, or response content. It imports no other Codex Switch package; the usage package keeps its own tables in the same database. SQLite is provided by modernc.org/sqlite so the proxy stays a single CGO-free binary.
Index ¶
- type AccountAllowanceWindowIdentity
- type AccountIdentity
- type AccountName
- type CompletedResponseID
- type CompletedResponseRecord
- type ModelRequestCounts
- type ModelRequestOutcome
- type ProviderAccountID
- type StoreDatabase
- func (database *StoreDatabase) ClearAccountExhaustionBefore(accountName AccountName, observedAt time.Time) (bool, error)
- func (database *StoreDatabase) CloseStoreDatabase() error
- func (database *StoreDatabase) CompareAndSwapTaskAccountPin(taskID TaskID, servedAccountName AccountName, nextAccountName AccountName, ...) (bool, error)
- func (database *StoreDatabase) FindAccountForAllowanceWindow(durationSeconds int64, resetsAt, eventAt time.Time) (ProviderAccountID, bool, error)
- func (database *StoreDatabase) NextAccountNumber() (int, error)
- func (database *StoreDatabase) PinTaskAccountIfAbsent(candidate TaskAccountPin) (TaskAccountPin, error)
- func (database *StoreDatabase) ReadAccountIdentities() ([]AccountIdentity, error)
- func (database *StoreDatabase) ReadAccountReportedReset(accountName AccountName) (time.Time, bool, error)
- func (database *StoreDatabase) ReadCompletedResponsesSince(since time.Time) ([]CompletedResponseRecord, error)
- func (database *StoreDatabase) ReadModelRequestCounts() (time.Time, []ModelRequestCounts, error)
- func (database *StoreDatabase) ReadPromptCacheParent(taskID TaskID, prefixes []string) (TaskID, error)
- func (database *StoreDatabase) ReadTaskAccountPin(taskID TaskID) (TaskAccountPin, bool, error)
- func (database *StoreDatabase) RecordAccountAllowanceWindowIdentity(identity AccountAllowanceWindowIdentity) error
- func (database *StoreDatabase) RecordAccountReportedReset(accountName AccountName, resetsAt, observedAt time.Time) error
- func (database *StoreDatabase) RecordCompletedResponse(record CompletedResponseRecord) error
- func (database *StoreDatabase) RecordModelRequestOutcome(account AccountName, admittedAt time.Time, outcome ModelRequestOutcome) error
- func (database *StoreDatabase) RememberAccountIdentity(identity AccountIdentity) error
- func (database *StoreDatabase) RememberPromptCachePrefix(taskID TaskID, prefix string) error
- func (database *StoreDatabase) RemoveAccountRoutingState(accountName AccountName) (int64, error)
- func (database *StoreDatabase) SQLDatabase() *sql.DB
- func (database *StoreDatabase) StartModelRequestObservation(now time.Time) error
- type TaskAccountPin
- type TaskID
- type WorkKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountAllowanceWindowIdentity ¶
type AccountAllowanceWindowIdentity struct {
ProviderAccountID ProviderAccountID
DurationSeconds int64
ResetsAt time.Time
ObservedAt time.Time
UsedPercent float64
}
AccountAllowanceWindowIdentity records an explicit provider reset from an authenticated allowance read after the account has used that window.
type AccountIdentity ¶
type AccountIdentity struct {
AccountName AccountName
ProviderAccountID string
Email string
}
AccountIdentity keeps historical usage attached to its account after removal from the pool.
type AccountName ¶
type AccountName string
AccountName keeps durable local identity separate from provider account IDs and emails.
type CompletedResponseID ¶
type CompletedResponseID string
CompletedResponseID is the provider identity used to record one completion exactly once.
type CompletedResponseRecord ¶
type CompletedResponseRecord struct {
CompletedResponseID CompletedResponseID
TaskID TaskID
AccountName AccountName
ModelSlug string
HarnessMode string
InputTokens int64
CachedInputTokens int64
CacheWriteInputTokens *int64
CostNanoUSD *int64
OutputTokens int64
ReasoningTokens int64
CompletedAt time.Time
}
CompletedResponseRecord excludes response content because accounting needs token facts only.
type ModelRequestCounts ¶
type ModelRequestCounts struct {
AccountName AccountName
Requests int64
Successful int64
Failed int64
Interrupted int64
}
type ModelRequestOutcome ¶
type ModelRequestOutcome int
const ( ModelRequestStarted ModelRequestOutcome = iota ModelRequestSuccessful ModelRequestFailed ModelRequestInterrupted )
type ProviderAccountID ¶
type ProviderAccountID string
type StoreDatabase ¶
type StoreDatabase struct {
// contains filtered or unexported fields
}
StoreDatabase is shared by old and new proxy generations during a live drain.
func OpenStoreDatabase ¶
func OpenStoreDatabase(databasePath string) (*StoreDatabase, error)
OpenStoreDatabase enables WAL before exposing the database to concurrent proxy generations.
func (*StoreDatabase) ClearAccountExhaustionBefore ¶
func (database *StoreDatabase) ClearAccountExhaustionBefore(accountName AccountName, observedAt time.Time) (bool, error)
ClearAccountExhaustionBefore lets a successful later provider read restore capacity. It reports whether it cleared a recorded exhaustion.
func (*StoreDatabase) CloseStoreDatabase ¶
func (database *StoreDatabase) CloseStoreDatabase() error
CloseStoreDatabase releases only this process's connection and never affects another generation.
func (*StoreDatabase) CompareAndSwapTaskAccountPin ¶
func (database *StoreDatabase) CompareAndSwapTaskAccountPin(taskID TaskID, servedAccountName AccountName, nextAccountName AccountName, movedAt time.Time) (bool, error)
CompareAndSwapTaskAccountPin makes a concurrent exhaustion report a no-op after another process moves the pin.
func (*StoreDatabase) FindAccountForAllowanceWindow ¶
func (database *StoreDatabase) FindAccountForAllowanceWindow(durationSeconds int64, resetsAt, eventAt time.Time) (ProviderAccountID, bool, error)
FindAccountForAllowanceWindow identifies only events within a window that has exactly one authenticated owner. Colliding resets do not establish ownership.
func (*StoreDatabase) NextAccountNumber ¶
func (database *StoreDatabase) NextAccountNumber() (int, error)
NextAccountNumber is called under the pool mutation lock, after remembering existing accounts.
func (*StoreDatabase) PinTaskAccountIfAbsent ¶
func (database *StoreDatabase) PinTaskAccountIfAbsent(candidate TaskAccountPin) (TaskAccountPin, error)
PinTaskAccountIfAbsent returns the winner when two proxy generations first see the same task.
func (*StoreDatabase) ReadAccountIdentities ¶
func (database *StoreDatabase) ReadAccountIdentities() ([]AccountIdentity, error)
func (*StoreDatabase) ReadAccountReportedReset ¶
func (database *StoreDatabase) ReadAccountReportedReset(accountName AccountName) (time.Time, bool, error)
ReadAccountReportedReset adjusts provider snapshots with later exhaustion evidence.
func (*StoreDatabase) ReadCompletedResponsesSince ¶
func (database *StoreDatabase) ReadCompletedResponsesSince(since time.Time) ([]CompletedResponseRecord, error)
func (*StoreDatabase) ReadModelRequestCounts ¶
func (database *StoreDatabase) ReadModelRequestCounts() (time.Time, []ModelRequestCounts, error)
func (*StoreDatabase) ReadPromptCacheParent ¶
func (database *StoreDatabase) ReadPromptCacheParent(taskID TaskID, prefixes []string) (TaskID, error)
ReadPromptCacheParent looks up a matching reusable prefix only for an unpinned session. The index expires with Anthropic's longest cache lifetime.
func (*StoreDatabase) ReadTaskAccountPin ¶
func (database *StoreDatabase) ReadTaskAccountPin(taskID TaskID) (TaskAccountPin, bool, error)
ReadTaskAccountPin reads current state on every turn so repairs take effect without restart.
func (*StoreDatabase) RecordAccountAllowanceWindowIdentity ¶
func (database *StoreDatabase) RecordAccountAllowanceWindowIdentity(identity AccountAllowanceWindowIdentity) error
func (*StoreDatabase) RecordAccountReportedReset ¶
func (database *StoreDatabase) RecordAccountReportedReset(accountName AccountName, resetsAt, observedAt time.Time) error
RecordAccountReportedReset preserves account-wide provider exhaustion independently of any task pin.
func (*StoreDatabase) RecordCompletedResponse ¶
func (database *StoreDatabase) RecordCompletedResponse(record CompletedResponseRecord) error
RecordCompletedResponse preserves directly observed inference usage once per response.
func (*StoreDatabase) RecordModelRequestOutcome ¶
func (database *StoreDatabase) RecordModelRequestOutcome(account AccountName, admittedAt time.Time, outcome ModelRequestOutcome) error
func (*StoreDatabase) RememberAccountIdentity ¶
func (database *StoreDatabase) RememberAccountIdentity(identity AccountIdentity) error
func (*StoreDatabase) RememberPromptCachePrefix ¶
func (database *StoreDatabase) RememberPromptCachePrefix(taskID TaskID, prefix string) error
func (*StoreDatabase) RemoveAccountRoutingState ¶
func (database *StoreDatabase) RemoveAccountRoutingState(accountName AccountName) (int64, error)
RemoveAccountRoutingState retires routing state while preserving account identity and completed usage.
func (*StoreDatabase) SQLDatabase ¶
func (database *StoreDatabase) SQLDatabase() *sql.DB
SQLDatabase shares this process's one connection with a module that owns its own tables, so its writes queue behind the same connection as routing writes.
func (*StoreDatabase) StartModelRequestObservation ¶
func (database *StoreDatabase) StartModelRequestObservation(now time.Time) error
type TaskAccountPin ¶
type TaskAccountPin struct {
TaskID TaskID
AccountName AccountName
PinnedAt time.Time
}
TaskAccountPin is durable so draining proxy generations agree on the next account.