Documentation
¶
Index ¶
- func NormalizeCredentialScope(scope string) string
- type Credential
- func (c *Credential) APIKey() string
- func (c *Credential) BaseURL() string
- func (c *Credential) Clone() *Credential
- func (c *Credential) DisableCoolingOverride() (bool, bool)
- func (c *Credential) ExpirationTime() (time.Time, bool)
- func (c *Credential) Normalize() *Credential
- func (c *Credential) Priority() int
- func (c *Credential) RefreshExpiryDelta() (time.Duration, bool)
- func (c *Credential) RefreshName() string
- func (c *Credential) RequestRetryOverride() (int, bool)
- func (c *Credential) ScopeValue() string
- func (c *Credential) Validate() error
- type Error
- type ManagedCredential
- type ModelState
- type QuotaState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Credential ¶
type Credential struct {
// ID uniquely identifies the credential.
ID string `json:"id"`
// ProviderType is the upstream provider type/key (e.g. "openai", "anthropic").
ProviderType string `json:"provider_type"`
// ProviderID identifies the concrete provider instance this credential belongs to.
ProviderID string `json:"provider_id"`
// Type identifies the credential kind (e.g. api_key, cliauth_token).
Type string `json:"type"`
// Label is a human-readable label for logging and display.
Label string `json:"label,omitempty"`
// Scope controls scheduler matching for this credential.
Scope string `json:"scope,omitempty"`
// Attributes stores provider-specific configuration (e.g. api_key, base_url, priority).
Attributes map[string]string `json:"attributes,omitempty"`
// Metadata stores runtime mutable provider state (e.g. tokens, cookies).
Metadata map[string]any `json:"metadata,omitempty"`
// Disabled marks the credential as intentionally excluded from scheduling.
Disabled bool `json:"disabled,omitempty"`
// CreatedAt is the creation timestamp.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the last modification timestamp.
UpdatedAt time.Time `json:"updated_at"`
}
Credential holds the persisted definition for a single upstream credential.
func (*Credential) APIKey ¶
func (c *Credential) APIKey() string
APIKey returns the api_key attribute value, or empty string if not set.
func (*Credential) BaseURL ¶
func (c *Credential) BaseURL() string
BaseURL returns the base_url attribute value, or empty string if not set.
func (*Credential) Clone ¶
func (c *Credential) Clone() *Credential
Clone shallow copies the Credential, duplicating maps to avoid mutation.
func (*Credential) DisableCoolingOverride ¶
func (c *Credential) DisableCoolingOverride() (bool, bool)
DisableCoolingOverride returns the per-credential disable_cooling override when present.
func (*Credential) ExpirationTime ¶
func (c *Credential) ExpirationTime() (time.Time, bool)
ExpirationTime attempts to extract the credential expiration timestamp from metadata.
func (*Credential) Normalize ¶
func (c *Credential) Normalize() *Credential
Normalize canonicalizes stable credential identity fields in-place.
func (*Credential) Priority ¶
func (c *Credential) Priority() int
Priority returns the scheduling priority for this credential (higher = preferred).
func (*Credential) RefreshExpiryDelta ¶
func (c *Credential) RefreshExpiryDelta() (time.Duration, bool)
RefreshExpiryDelta returns the per-credential refresh lead time.
func (*Credential) RefreshName ¶
func (c *Credential) RefreshName() string
RefreshName returns the refresh handler name associated with this credential.
func (*Credential) RequestRetryOverride ¶
func (c *Credential) RequestRetryOverride() (int, bool)
RequestRetryOverride returns the per-credential request_retry override when present.
func (*Credential) ScopeValue ¶
func (c *Credential) ScopeValue() string
func (*Credential) Validate ¶
func (c *Credential) Validate() error
Validate checks the required stable identity fields for persisted credentials.
type Error ¶
type Error struct {
Code string `json:"code,omitempty"`
Message string `json:"message"`
Retryable bool `json:"retryable"`
HTTPStatus int `json:"http_status,omitempty"`
}
Error describes a credential-related failure in a provider-agnostic format.
func (*Error) StatusCode ¶
StatusCode implements optional status accessor for retry decision making.
type ManagedCredential ¶
type ManagedCredential struct {
Credential
Unavailable bool `json:"unavailable,omitempty"`
// NextRetryAfter is the earliest time a retry should be attempted.
NextRetryAfter time.Time `json:"next_retry_after,omitempty"`
// Quota captures recent quota information for load-balancing decisions.
Quota QuotaState `json:"quota"`
// LastError records the last failure encountered.
LastError *Error `json:"last_error,omitempty"`
// ModelStates tracks per-model runtime availability data.
ModelStates map[string]*ModelState `json:"model_states,omitempty"`
// AuthInvalid flags credentials rejected by upstream authentication (e.g. 401/403).
AuthInvalid bool `json:"auth_invalid,omitempty"`
// StateUpdatedAt is the last runtime-state update timestamp.
StateUpdatedAt time.Time `json:"state_updated_at,omitempty"`
}
ManagedCredential wraps a persisted credential with in-memory runtime state.
func (*ManagedCredential) Clone ¶
func (c *ManagedCredential) Clone() *ManagedCredential
Clone duplicates a ManagedCredential including runtime state.
type ModelState ¶
type ModelState struct {
Unavailable bool `json:"unavailable,omitempty"`
// NextRetryAfter is the earliest time this model may be retried.
NextRetryAfter time.Time `json:"next_retry_after,omitempty"`
// LastError records the latest error observed for this model.
LastError *Error `json:"last_error,omitempty"`
// Quota retains quota information if this model hit rate limits.
Quota QuotaState `json:"quota"`
// AuthInvalid flags model-specific authentication failure state.
AuthInvalid bool `json:"auth_invalid,omitempty"`
// UpdatedAt tracks the last update timestamp.
UpdatedAt time.Time `json:"updated_at"`
}
ModelState captures the execution state for a specific model under a credential.