Help us shape the future of Go! Take the 2026 Go Developer Survey

model

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeCredentialScope

func NormalizeCredentialScope(scope string) string

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, oauth_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) 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) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode implements optional status accessor for retry decision making.

type ManagedCredential

type ManagedCredential struct {
	Credential
	// Unavailable flags transient provider unavailability (e.g. quota exceeded).
	Unavailable bool `json:"unavailable,omitempty"`
	// CredentialWideUnavailable flags a transient block across every model.
	CredentialWideUnavailable bool `json:"credential_wide_unavailable,omitempty"`
	// CredentialWideNextRetryAfter bounds a credential-wide transient block.
	CredentialWideNextRetryAfter time.Time `json:"credential_wide_next_retry_after,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

Clone duplicates a ManagedCredential including runtime state.

type ModelState

type ModelState struct {
	// Unavailable flags transient unavailability for this model.
	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.

func (*ModelState) Clone

func (m *ModelState) Clone() *ModelState

Clone duplicates a ModelState.

type QuotaState

type QuotaState struct {
	Exceeded      bool      `json:"exceeded"`
	Reason        string    `json:"reason,omitempty"`
	NextRecoverAt time.Time `json:"next_recover_at,omitempty"`
	BackoffLevel  int       `json:"backoff_level,omitempty"`
}

QuotaState captures quota limiter tracking data for a credential.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL