Documentation
¶
Index ¶
- Constants
- func APIKeyHash(apiKey string) string
- func ApplyOriginalAuthFileName(auths []*coreauth.Auth, filename string)
- func AutoMigrate(db *gorm.DB) error
- func Bootstrap(ctx context.Context, opts BootstrapOptions) error
- func ClientAddr(ctx context.Context, db *gorm.DB) (string, error)
- func ConfigRootFromSnapshot(snapshot map[string]json.RawMessage) (map[string]any, error)
- func DeterministicAPIKeyUUID(provider, baseURL, apiKeyHash, compatName, providerKey string) string
- func DeterministicVirtualUUID(parentUUID, projectID string) string
- func EnsureOAuthPayloadUUID(raw []byte) ([]byte, string, bool, error)
- func ForwardRefreshToMaster(ctx context.Context, master *ClusterNodeRecord, authUUID string, secret string) ([]byte, error)
- func IsClientClusterCommand(args []string) bool
- func NormalizeClusterAuth(auth *coreauth.Auth, uuidValue string)
- func OAuthSessionData(record *OAuthSessionRecord) (map[string]any, error)
- func Open(ctx context.Context, cfg PGSQLConfig) (*gorm.DB, error)
- func RecordToAuth(record *AuthRecord) (*coreauth.Auth, error)
- func RuntimeConfigFromRoot(root map[string]any) (*appconfig.Config, []byte, error)
- type APIKeyRecord
- type AuthIndex
- type AuthRecord
- type BootstrapOptions
- type CertificateRecord
- type ClusterEventRecord
- type ClusterNodeRecord
- type Config
- type ConfigRecord
- type Coordinator
- func (c *Coordinator) CurrentMaster(ctx context.Context) (*ClusterNodeRecord, error)
- func (c *Coordinator) IsMaster() bool
- func (c *Coordinator) NodeSecret() string
- func (c *Coordinator) SetOnMasterChanged(callback func(bool))
- func (c *Coordinator) Start(ctx context.Context) error
- func (c *Coordinator) UpdateClientCount(ctx context.Context, clientCount int) error
- type CoordinatorOptions
- type CredentialConfigCounts
- type DisbandOptions
- type DisbandResult
- type EventWatcher
- type JSONB
- type NodeConfig
- type NodeIdentity
- type OAuthSessionRecord
- type PGSQLConfig
- type RESPHandler
- func (h *RESPHandler) Handle(ctx context.Context, args []string, remoteIP string) ([]byte, error)
- func (h *RESPHandler) RequestClientCertificate(ctx context.Context, certificateID string, csrPEM []byte) ([]byte, error)
- func (h *RESPHandler) UpdateClientCount(ctx context.Context, clientCount int) error
- type RefreshController
- type Repository
- func (r *Repository) AppendEvent(ctx context.Context, scope, op, entity string, version int64) error
- func (r *Repository) AppendUsage(ctx context.Context, payload string) (*UsageRecord, error)
- func (r *Repository) CompleteOAuthSession(ctx context.Context, state string) error
- func (r *Repository) CreateHomeJWT(ctx context.Context, certificateID string, ip string, port int) (string, error)
- func (r *Repository) CreatePendingClientCertificate(ctx context.Context) (string, error)
- func (r *Repository) CurrentMasterNode(ctx context.Context) (*ClusterNodeRecord, error)
- func (r *Repository) EnsureClusterCertificates(ctx context.Context, ip string) (*tls.Config, error)
- func (r *Repository) GetAuth(ctx context.Context, uuid string) (*coreauth.Auth, *AuthRecord, error)
- func (r *Repository) GetOAuthSession(ctx context.Context, state string) (*OAuthSessionRecord, error)
- func (r *Repository) ListAuthIndex(ctx context.Context) ([]AuthIndex, error)
- func (r *Repository) ListAuths(ctx context.Context) ([]*coreauth.Auth, error)
- func (r *Repository) ListLiveClusterNodes(ctx context.Context, cutoff time.Time) ([]ClusterNodeRecord, error)
- func (r *Repository) LiveClusterNodeByIPAndSecret(ctx context.Context, ip string, secret string, cutoff time.Time) (*ClusterNodeRecord, error)
- func (r *Repository) LoadConfigAsRuntimeConfig(ctx context.Context) (*appconfig.Config, []byte, error)
- func (r *Repository) LoadConfigSnapshot(ctx context.Context) (map[string]json.RawMessage, error)
- func (r *Repository) MaxEventID(ctx context.Context) (int64, error)
- func (r *Repository) MergeOAuthSessionData(ctx context.Context, state string, values map[string]any) error
- func (r *Repository) ReplaceConfigSnapshot(ctx context.Context, values map[string]any) error
- func (r *Repository) SetOAuthSessionError(ctx context.Context, state string, message string) error
- func (r *Repository) SignClientCertificateRequest(ctx context.Context, certificateID string, csrPEM []byte) ([]byte, []byte, error)
- func (r *Repository) SignClientCertificateRequestJSON(ctx context.Context, certificateID string, csrPEM []byte) ([]byte, error)
- func (r *Repository) SoftDeleteAuth(ctx context.Context, uuid string) error
- func (r *Repository) UpsertAuth(ctx context.Context, auth *coreauth.Auth, op string) (*AuthRecord, error)
- func (r *Repository) UpsertConfigValue(ctx context.Context, key string, value any) error
- func (r *Repository) UpsertOAuthSession(ctx context.Context, record *OAuthSessionRecord) error
- func (r *Repository) WithAuthRefreshLock(ctx context.Context, uuid string, ...) (*coreauth.Auth, error)
- type RuntimeAdapter
- func (a *RuntimeAdapter) ApplyEvent(ctx context.Context, event ClusterEventRecord) error
- func (a *RuntimeAdapter) Delete(ctx context.Context, id string) error
- func (a *RuntimeAdapter) Enabled() bool
- func (a *RuntimeAdapter) GetFullAuth(ctx context.Context, uuid string) (*coreauth.Auth, error)
- func (a *RuntimeAdapter) InvalidateFullAuth(uuid string)
- func (a *RuntimeAdapter) List(ctx context.Context) ([]*coreauth.Auth, error)
- func (a *RuntimeAdapter) ListMinimalAuths() []*coreauth.Auth
- func (a *RuntimeAdapter) LoadAuthIndex(ctx context.Context) error
- func (a *RuntimeAdapter) LoadConfigYAML(ctx context.Context) ([]byte, error)
- func (a *RuntimeAdapter) LoadIndex(ctx context.Context) error
- func (a *RuntimeAdapter) RefreshAuthIndex(ctx context.Context, uuid string) error
- func (a *RuntimeAdapter) RemoveAuthIndex(uuid string)
- func (a *RuntimeAdapter) Save(ctx context.Context, auth *coreauth.Auth) (string, error)
- func (a *RuntimeAdapter) StoreUsagePayload(ctx context.Context, payload string) error
- type UsageRecord
Constants ¶
const DefaultConfigPath = "cluster.yaml"
const OAuthSessionTTL = 20 * time.Minute
Variables ¶
This section is empty.
Functions ¶
func ApplyOriginalAuthFileName ¶
ApplyOriginalAuthFileName stores the source OAuth file name for management display.
func Bootstrap ¶
func Bootstrap(ctx context.Context, opts BootstrapOptions) error
Bootstrap imports local configuration into the cluster database.
func ClientAddr ¶
ClientAddr handles a client addr.
func ConfigRootFromSnapshot ¶
ConfigRootFromSnapshot derives config root from snapshot.
func DeterministicAPIKeyUUID ¶
DeterministicAPIKeyUUID handles a deterministic api key uuid.
func DeterministicVirtualUUID ¶
DeterministicVirtualUUID handles a deterministic virtual uuid.
func EnsureOAuthPayloadUUID ¶
EnsureOAuthPayloadUUID validates ensure o auth payload uuid.
func ForwardRefreshToMaster ¶
func ForwardRefreshToMaster(ctx context.Context, master *ClusterNodeRecord, authUUID string, secret string) ([]byte, error)
ForwardRefreshToMaster converts forward refresh to master.
func IsClientClusterCommand ¶ added in v1.0.5
IsClientClusterCommand reports whether a CLUSTER command is for authenticated CPA clients.
func NormalizeClusterAuth ¶
NormalizeClusterAuth normalizes a cluster auth.
func OAuthSessionData ¶ added in v1.0.3
func OAuthSessionData(record *OAuthSessionRecord) (map[string]any, error)
OAuthSessionData handles an o auth session data.
func RecordToAuth ¶
func RecordToAuth(record *AuthRecord) (*coreauth.Auth, error)
RecordToAuth records a to auth.
Types ¶
type APIKeyRecord ¶ added in v1.0.5
type APIKeyRecord struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement"`
APIKey string `gorm:"column:api_key;not null;uniqueIndex"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index"`
}
func (APIKeyRecord) TableName ¶ added in v1.0.5
func (APIKeyRecord) TableName() string
TableName returns the database table name.
type AuthRecord ¶
type AuthRecord struct {
UUID string `gorm:"column:uuid;primaryKey;type:uuid"`
AuthJSON JSONB `gorm:"column:auth_json;type:jsonb;not null"`
Version int64 `gorm:"column:version;not null;default:1"`
ID string `gorm:"column:id;index:idx_auth_active_order,priority:2"`
Index string `gorm:"column:index"`
Provider string `gorm:"column:provider"`
Label string `gorm:"column:label"`
Prefix string `gorm:"column:prefix"`
Status coreauth.Status `gorm:"column:status"`
Disabled bool `gorm:"column:disabled"`
BaseURL string `gorm:"column:base_url"`
APIKeyHash string `gorm:"column:api_key_hash"`
CompatName string `gorm:"column:compat_name"`
ProviderKey string `gorm:"column:provider_key"`
ModelsHash string `gorm:"column:models_hash"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
LastRefreshedAt *time.Time `gorm:"column:last_refreshed_at"`
NextRefreshAfter *time.Time `gorm:"column:next_refresh_after"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index;index:idx_auth_active_order,priority:1"`
}
func AuthToRecord ¶
func AuthToRecord(auth *coreauth.Auth) (*AuthRecord, error)
AuthToRecord converts auth to record.
func (AuthRecord) TableName ¶
func (AuthRecord) TableName() string
TableName returns the database table name.
type BootstrapOptions ¶
type CertificateRecord ¶ added in v1.0.14
type CertificateRecord struct {
ID string `gorm:"column:id;primaryKey"`
CertificatePEM string `gorm:"column:certificate_pem;type:text"`
PrivateKeyPEM string `gorm:"column:private_key_pem;type:text"`
CSRPEM string `gorm:"column:csr_pem;type:text"`
IP string `gorm:"column:ip;index:idx_certificate_server_ip,priority:2"`
IsCA bool `gorm:"column:is_ca;index"`
IsServer bool `gorm:"column:is_server;index:idx_certificate_server_ip,priority:1"`
IsClient bool `gorm:"column:is_client;index"`
SerialNumber string `gorm:"column:serial_number"`
NotBefore time.Time `gorm:"column:not_before"`
NotAfter time.Time `gorm:"column:not_after"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
func (CertificateRecord) TableName ¶ added in v1.0.14
func (CertificateRecord) TableName() string
TableName returns the database table name.
type ClusterEventRecord ¶
type ClusterEventRecord struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement"`
Scope string `gorm:"column:scope"`
Op string `gorm:"column:op"`
EntityUUID string `gorm:"column:entity_uuid"`
Version int64 `gorm:"column:version"`
CreatedAt time.Time `gorm:"column:created_at"`
}
func (ClusterEventRecord) TableName ¶
func (ClusterEventRecord) TableName() string
TableName returns the database table name.
type ClusterNodeRecord ¶
type ClusterNodeRecord struct {
IP string `` /* 150-byte string literal not displayed */
Port int `` /* 152-byte string literal not displayed */
SecretHash string `gorm:"column:secret_hash;index:idx_cluster_auth_lookup,priority:2"`
IsMaster bool `gorm:"column:is_master;index:idx_cluster_master_nodes,priority:1"`
ClientCount int `gorm:"column:client_count"`
StartedAt time.Time `` /* 147-byte string literal not displayed */
LastSeenAt time.Time `` /* 149-byte string literal not displayed */
}
func (ClusterNodeRecord) TableName ¶
func (ClusterNodeRecord) TableName() string
TableName returns the database table name.
type Config ¶
type Config struct {
PGSQL PGSQLConfig `yaml:"pgsql"`
Node NodeConfig `yaml:"node"`
}
func LoadConfigOptional ¶
LoadConfigOptional loads a config optional.
type ConfigRecord ¶
type ConfigRecord struct {
Key string `gorm:"column:key;primaryKey"`
Value JSONB `gorm:"column:value;type:jsonb;not null"`
Version int64 `gorm:"column:version;not null;default:1"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
func (ConfigRecord) TableName ¶
func (ConfigRecord) TableName() string
TableName returns the database table name.
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
func NewCoordinator ¶
func NewCoordinator(repo *Repository, node NodeIdentity, opts CoordinatorOptions) *Coordinator
NewCoordinator creates a new coordinator.
func (*Coordinator) CurrentMaster ¶
func (c *Coordinator) CurrentMaster(ctx context.Context) (*ClusterNodeRecord, error)
CurrentMaster returns a current master.
func (*Coordinator) IsMaster ¶
func (c *Coordinator) IsMaster() bool
IsMaster reports whether is master.
func (*Coordinator) NodeSecret ¶
func (c *Coordinator) NodeSecret() string
NodeSecret handles a node secret.
func (*Coordinator) SetOnMasterChanged ¶
func (c *Coordinator) SetOnMasterChanged(callback func(bool))
SetOnMasterChanged sets an on master changed.
func (*Coordinator) Start ¶
func (c *Coordinator) Start(ctx context.Context) error
Start starts the process.
func (*Coordinator) UpdateClientCount ¶ added in v1.0.5
func (c *Coordinator) UpdateClientCount(ctx context.Context, clientCount int) error
UpdateClientCount stores the current active CPA client count for this node.
type CoordinatorOptions ¶
type CredentialConfigCounts ¶ added in v1.0.3
type CredentialConfigCounts struct {
GeminiKeys int
VertexKeys int
CodexKeys int
ClaudeKeys int
OpenAICompatibility int
}
CredentialConfigCounts reports how many auth-backed config entries were restored.
func ApplyCredentialConfigToRoot ¶ added in v1.0.3
func ApplyCredentialConfigToRoot(root map[string]any, auths []*coreauth.Auth) CredentialConfigCounts
ApplyCredentialConfigToRoot restores auth-backed config keys into a config root.
type DisbandOptions ¶
type DisbandOptions struct {
ConfigPath string
AuthDir string
Repository *Repository
}
type DisbandResult ¶
type DisbandResult struct {
ConfigPath string
AuthDir string
ConfigBytes int
AuthFiles int
GeminiKeys int
VertexKeys int
CodexKeys int
ClaudeKeys int
OpenAICompatibility int
}
func Disband ¶
func Disband(ctx context.Context, opts DisbandOptions) (*DisbandResult, error)
Disband restores local files from the cluster database.
type EventWatcher ¶
type EventWatcher struct {
// contains filtered or unexported fields
}
func NewEventWatcher ¶
func NewEventWatcher(repo *Repository, pollInterval time.Duration, onEvent func(context.Context, ClusterEventRecord) error) *EventWatcher
NewEventWatcher creates a new event watcher.
func NewEventWatcherFrom ¶
func NewEventWatcherFrom(repo *Repository, pollInterval time.Duration, lastSeenID int64, onEvent func(context.Context, ClusterEventRecord) error) *EventWatcher
NewEventWatcherFrom creates a new event watcher from.
type JSONB ¶
type JSONB []byte
func (*JSONB) UnmarshalJSON ¶
UnmarshalJSON decodes a json.
type NodeConfig ¶
type NodeConfig struct {
ExternalIP string `yaml:"external-ip"`
ExternalPort int `yaml:"external-port"`
Port int `yaml:"port"`
HeartbeatInterval time.Duration `yaml:"heartbeat-interval"`
HeartbeatTimeout time.Duration `yaml:"heartbeat-timeout"`
EventPollInterval time.Duration `yaml:"event-poll-interval"`
}
type NodeIdentity ¶
type OAuthSessionRecord ¶ added in v1.0.3
type OAuthSessionRecord struct {
State string `gorm:"column:state;primaryKey"`
Provider string `gorm:"column:provider;index"`
Status string `gorm:"column:status"`
Error string `gorm:"column:error"`
Data JSONB `gorm:"column:data;type:jsonb"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
ExpiresAt time.Time `gorm:"column:expires_at;index"`
CompletedAt *time.Time `gorm:"column:completed_at"`
}
func NewOAuthSessionRecord ¶ added in v1.0.3
func NewOAuthSessionRecord(provider, state string, data map[string]any, now time.Time) (*OAuthSessionRecord, error)
NewOAuthSessionRecord creates a new o auth session record.
func (OAuthSessionRecord) TableName ¶ added in v1.0.3
func (OAuthSessionRecord) TableName() string
TableName returns the database table name.
type PGSQLConfig ¶
type PGSQLConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Passowrd string `yaml:"passowrd"`
Database string `yaml:"database"`
SSLMode string `yaml:"sslmode"`
}
func (PGSQLConfig) DSN ¶
func (c PGSQLConfig) DSN() (string, error)
DSN returns the PostgreSQL connection string.
type RESPHandler ¶
type RESPHandler struct {
// contains filtered or unexported fields
}
func NewRESPHandler ¶
func NewRESPHandler(coordinator *Coordinator, refresh *RefreshController, repo *Repository) *RESPHandler
NewRESPHandler creates a new resp handler.
func (*RESPHandler) RequestClientCertificate ¶ added in v1.0.14
func (h *RESPHandler) RequestClientCertificate(ctx context.Context, certificateID string, csrPEM []byte) ([]byte, error)
RequestClientCertificate signs a pending client certificate request.
func (*RESPHandler) UpdateClientCount ¶ added in v1.0.5
func (h *RESPHandler) UpdateClientCount(ctx context.Context, clientCount int) error
UpdateClientCount stores the current active CPA client count for this node.
type RefreshController ¶
type RefreshController struct {
// contains filtered or unexported fields
}
func NewRefreshController ¶
func NewRefreshController(coordinator *Coordinator, runtime *home.Runtime, repo *Repository) *RefreshController
NewRefreshController creates a new refresh controller.
func (*RefreshController) CanAutoRefresh ¶
func (c *RefreshController) CanAutoRefresh() bool
CanAutoRefresh reports whether can auto refresh.
func (*RefreshController) OnMasterChanged ¶
func (c *RefreshController) OnMasterChanged(isMaster bool)
OnMasterChanged handles an on master changed.
func (*RefreshController) RefreshNow ¶
RefreshNow refreshes refresh now.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(db *gorm.DB) *Repository
NewRepository creates a new repository.
func (*Repository) AppendEvent ¶
func (r *Repository) AppendEvent(ctx context.Context, scope, op, entity string, version int64) error
AppendEvent appends an event.
func (*Repository) AppendUsage ¶
func (r *Repository) AppendUsage(ctx context.Context, payload string) (*UsageRecord, error)
AppendUsage appends an usage.
func (*Repository) CompleteOAuthSession ¶ added in v1.0.3
func (r *Repository) CompleteOAuthSession(ctx context.Context, state string) error
CompleteOAuthSession handles a complete o auth session.
func (*Repository) CreateHomeJWT ¶ added in v1.0.14
func (r *Repository) CreateHomeJWT(ctx context.Context, certificateID string, ip string, port int) (string, error)
CreateHomeJWT creates a signed Home JWT with the client certificate id and target node.
func (*Repository) CreatePendingClientCertificate ¶ added in v1.0.14
func (r *Repository) CreatePendingClientCertificate(ctx context.Context) (string, error)
CreatePendingClientCertificate creates an empty client certificate slot.
func (*Repository) CurrentMasterNode ¶ added in v1.0.14
func (r *Repository) CurrentMasterNode(ctx context.Context) (*ClusterNodeRecord, error)
CurrentMasterNode returns the current master node if one is recorded.
func (*Repository) EnsureClusterCertificates ¶ added in v1.0.14
EnsureClusterCertificates makes sure the cluster CA and this node server certificate exist.
func (*Repository) GetAuth ¶
func (r *Repository) GetAuth(ctx context.Context, uuid string) (*coreauth.Auth, *AuthRecord, error)
GetAuth returns an auth.
func (*Repository) GetOAuthSession ¶ added in v1.0.3
func (r *Repository) GetOAuthSession(ctx context.Context, state string) (*OAuthSessionRecord, error)
GetOAuthSession returns an o auth session.
func (*Repository) ListAuthIndex ¶
func (r *Repository) ListAuthIndex(ctx context.Context) ([]AuthIndex, error)
ListAuthIndex returns an auth index.
func (*Repository) ListLiveClusterNodes ¶ added in v1.0.5
func (r *Repository) ListLiveClusterNodes(ctx context.Context, cutoff time.Time) ([]ClusterNodeRecord, error)
ListLiveClusterNodes returns live cluster nodes.
func (*Repository) LiveClusterNodeByIPAndSecret ¶
func (r *Repository) LiveClusterNodeByIPAndSecret(ctx context.Context, ip string, secret string, cutoff time.Time) (*ClusterNodeRecord, error)
LiveClusterNodeByIPAndSecret handles a live cluster node by ip and secret.
func (*Repository) LoadConfigAsRuntimeConfig ¶
func (r *Repository) LoadConfigAsRuntimeConfig(ctx context.Context) (*appconfig.Config, []byte, error)
LoadConfigAsRuntimeConfig loads a config as runtime config.
func (*Repository) LoadConfigSnapshot ¶
func (r *Repository) LoadConfigSnapshot(ctx context.Context) (map[string]json.RawMessage, error)
LoadConfigSnapshot loads a config snapshot.
func (*Repository) MaxEventID ¶
func (r *Repository) MaxEventID(ctx context.Context) (int64, error)
MaxEventID handles a max event id.
func (*Repository) MergeOAuthSessionData ¶ added in v1.0.3
func (r *Repository) MergeOAuthSessionData(ctx context.Context, state string, values map[string]any) error
MergeOAuthSessionData merges an o auth session data.
func (*Repository) ReplaceConfigSnapshot ¶
ReplaceConfigSnapshot handles a replace config snapshot.
func (*Repository) SetOAuthSessionError ¶ added in v1.0.3
SetOAuthSessionError sets an o auth session error.
func (*Repository) SignClientCertificateRequest ¶ added in v1.0.14
func (r *Repository) SignClientCertificateRequest(ctx context.Context, certificateID string, csrPEM []byte) ([]byte, []byte, error)
SignClientCertificateRequest signs a client CSR exactly once and returns the client certificate plus CA.
func (*Repository) SignClientCertificateRequestJSON ¶ added in v1.0.14
func (r *Repository) SignClientCertificateRequestJSON(ctx context.Context, certificateID string, csrPEM []byte) ([]byte, error)
SignClientCertificateRequestJSON signs a CSR and returns the RESP JSON payload.
func (*Repository) SoftDeleteAuth ¶
func (r *Repository) SoftDeleteAuth(ctx context.Context, uuid string) error
SoftDeleteAuth handles a soft delete auth.
func (*Repository) UpsertAuth ¶
func (r *Repository) UpsertAuth(ctx context.Context, auth *coreauth.Auth, op string) (*AuthRecord, error)
UpsertAuth inserts or updates an auth.
func (*Repository) UpsertConfigValue ¶
UpsertConfigValue inserts or updates a config value.
func (*Repository) UpsertOAuthSession ¶ added in v1.0.3
func (r *Repository) UpsertOAuthSession(ctx context.Context, record *OAuthSessionRecord) error
UpsertOAuthSession inserts or updates an o auth session.
func (*Repository) WithAuthRefreshLock ¶
func (r *Repository) WithAuthRefreshLock(ctx context.Context, uuid string, fn func(tx *Repository, auth *coreauth.Auth) (*coreauth.Auth, error)) (*coreauth.Auth, error)
WithAuthRefreshLock applies the auth refresh lock option.
type RuntimeAdapter ¶
type RuntimeAdapter struct {
// contains filtered or unexported fields
}
func NewRuntimeAdapter ¶
func NewRuntimeAdapter(repo *Repository) *RuntimeAdapter
NewRuntimeAdapter creates a new runtime adapter.
func (*RuntimeAdapter) ApplyEvent ¶
func (a *RuntimeAdapter) ApplyEvent(ctx context.Context, event ClusterEventRecord) error
ApplyEvent updates apply event.
func (*RuntimeAdapter) Delete ¶
func (a *RuntimeAdapter) Delete(ctx context.Context, id string) error
Delete handles delete.
func (*RuntimeAdapter) Enabled ¶
func (a *RuntimeAdapter) Enabled() bool
Enabled handles an enabled.
func (*RuntimeAdapter) GetFullAuth ¶
GetFullAuth returns a full auth.
func (*RuntimeAdapter) InvalidateFullAuth ¶
func (a *RuntimeAdapter) InvalidateFullAuth(uuid string)
InvalidateFullAuth invalidates a full auth.
func (*RuntimeAdapter) ListMinimalAuths ¶
func (a *RuntimeAdapter) ListMinimalAuths() []*coreauth.Auth
ListMinimalAuths returns a minimal auths.
func (*RuntimeAdapter) LoadAuthIndex ¶
func (a *RuntimeAdapter) LoadAuthIndex(ctx context.Context) error
LoadAuthIndex loads an auth index.
func (*RuntimeAdapter) LoadConfigYAML ¶
func (a *RuntimeAdapter) LoadConfigYAML(ctx context.Context) ([]byte, error)
LoadConfigYAML loads a config yaml.
func (*RuntimeAdapter) LoadIndex ¶
func (a *RuntimeAdapter) LoadIndex(ctx context.Context) error
LoadIndex loads an index.
func (*RuntimeAdapter) RefreshAuthIndex ¶
func (a *RuntimeAdapter) RefreshAuthIndex(ctx context.Context, uuid string) error
RefreshAuthIndex refreshes refresh auth index.
func (*RuntimeAdapter) RemoveAuthIndex ¶
func (a *RuntimeAdapter) RemoveAuthIndex(uuid string)
RemoveAuthIndex removes an auth index.
func (*RuntimeAdapter) StoreUsagePayload ¶
func (a *RuntimeAdapter) StoreUsagePayload(ctx context.Context, payload string) error
StoreUsagePayload stores an usage payload.
type UsageRecord ¶
type UsageRecord struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement"`
Timestamp time.Time `gorm:"column:timestamp;type:timestamptz;not null;index:idx_usage_timestamp"`
LatencyMS int64 `gorm:"column:latency_ms;not null;default:0"`
Source string `gorm:"column:source;index:idx_usage_source"`
AuthIndex string `gorm:"column:auth_index;index:idx_usage_auth_index"`
InputTokens int64 `gorm:"column:input_tokens;not null;default:0"`
OutputTokens int64 `gorm:"column:output_tokens;not null;default:0"`
ReasoningTokens int64 `gorm:"column:reasoning_tokens;not null;default:0"`
CachedTokens int64 `gorm:"column:cached_tokens;not null;default:0"`
CacheReadTokens int64 `gorm:"column:cache_read_tokens;not null;default:0"`
CacheCreationTokens int64 `gorm:"column:cache_creation_tokens;not null;default:0"`
TotalTokens int64 `gorm:"column:total_tokens;not null;default:0"`
Failed bool `gorm:"column:failed;not null;default:false;index:idx_usage_failed"`
FailStatusCode int `gorm:"column:fail_status_code;not null;default:0"`
FailBody string `gorm:"column:fail_body;type:text"`
Provider string `gorm:"column:provider;index:idx_usage_provider_model,priority:1"`
Model string `gorm:"column:model;index:idx_usage_provider_model,priority:2"`
Alias string `gorm:"column:alias"`
Endpoint string `gorm:"column:endpoint;index:idx_usage_endpoint"`
AuthType string `gorm:"column:auth_type"`
APIKey string `gorm:"column:api_key"`
RequestID string `gorm:"column:request_id;index:idx_usage_request_id"`
TokensJSON JSONB `gorm:"column:tokens;type:jsonb"`
FailJSON JSONB `gorm:"column:fail;type:jsonb"`
PayloadJSON JSONB `gorm:"column:payload;type:jsonb;not null"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;not null"`
}
func UsageRecordFromPayload ¶
func UsageRecordFromPayload(payload string) (*UsageRecord, error)
UsageRecordFromPayload derives usage record from payload.
func (UsageRecord) TableName ¶
func (UsageRecord) TableName() string
TableName returns the database table name.