control

package
v0.7.44 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// AccountBundleFormat identifies a full console account migration file.
	AccountBundleFormat = "cli2api-accounts"
	// AccountBundleVersion is bumped when the JSON shape changes incompatibly.
	AccountBundleVersion = 1
)
View Source
const CatalogCacheTTL = 5 * time.Minute

Variables

This section is empty.

Functions

func AddModelRegion

func AddModelRegion(entry map[string]any, region string)

func CatalogCacheKey

func CatalogCacheKey(accountID string, mode CatalogMode) string

func CloneModelEntry added in v0.7.28

func CloneModelEntry(model map[string]any) map[string]any

CloneModelEntry copies a catalog entry so rewriting its id never mutates the shared catalog cache.

func CloneModelList

func CloneModelList(models []map[string]any) []map[string]any

func DecorateModelsWithContext

func DecorateModelsWithContext(ctx context.Context, settings *Settings, models []map[string]any) []map[string]any

func DefaultContextForModel

func DefaultContextForModel(model string) int

DefaultContextForModel is shared by catalog decoration and settings HTTP.

func EnsureCheckinDisabledAccounts added in v0.6.13

func EnsureCheckinDisabledAccounts(ctx context.Context, store SecretStore) (bool, error)

func EnsureCrossProviderModelPool

func EnsureCrossProviderModelPool(ctx context.Context, store SecretStore) (bool, error)

func EnsureProxyAPIKey

func EnsureProxyAPIKey(ctx context.Context, store SecretStore, bootstrap string) (string, bool, error)

func EnsureProxyURL

func EnsureProxyURL(ctx context.Context, store SecretStore, bootstrap string) (string, error)

func EnsureRoutingStrategy

func EnsureRoutingStrategy(ctx context.Context, store SecretStore) (string, error)

func EnsureWorkBuddyCheckinTime

func EnsureWorkBuddyCheckinTime(ctx context.Context, store SecretStore) (string, error)

func EntryModelRegions

func EntryModelRegions(entry map[string]any) []string

func FilterModelsByAccountAllow added in v0.7.34

func FilterModelsByAccountAllow(models []map[string]any, identity auth.Identity, pool []AccountModelAllow) []map[string]any

FilterModelsByAccountAllow drops catalog entries no granted account will serve. See ModelServedByAccounts for the empty-pool and mixed-account rules.

func FilterModelsForIdentity

func FilterModelsForIdentity(identity auth.Identity, models []map[string]any) []map[string]any

FilterModelsForIdentity applies grants after loading the shared catalog.

func GenerateAPIKey

func GenerateAPIKey() (string, error)

func MergeModelEntryCapabilities

func MergeModelEntryCapabilities(merged, incoming map[string]any)

MergeModelEntryCapabilities folds a later source entry into the merged one conservatively: numeric fields take the minimum and boolean fields are ANDed.

func MergeModelEntryPricing

func MergeModelEntryPricing(merged, incoming map[string]any)

MergeModelEntryPricing drops credits/free when source regions disagree.

func ModelCapabilitiesEntry

func ModelCapabilitiesEntry(model providers.ModelInfo) map[string]any

ModelCapabilitiesEntry is the merge-only capability view of one provider catalog entry. Unlike ProviderModelEntry it always states supports_images (true or false) so MergeModelEntryCapabilities can combine regions; the public entry only carries the field when the provider declares support.

func ModelContextKey

func ModelContextKey(model string) string

ModelContextKey normalizes a console setting key without treating an empty input as the routing model "auto".

func ModelServedByAccounts added in v0.7.34

func ModelServedByAccounts(entry map[string]any, identity auth.Identity, pool []AccountModelAllow) bool

ModelServedByAccounts reports whether at least one account the caller can reach will accept this catalog entry. Provider and region grants are applied here too, so a key scoped to one family never keeps another family's name just because that other account left its list unrestricted.

An empty account list keeps the catalog unchanged: tests and a pool that has not reported routing yet must not blank /v1/models. A model stays listed when any granted account can serve it — either because that account is unrestricted, or because the model (or an alias that rewrites to it) is in its enabled set. Region-qualified entries ("workbuddy-cn/…") only consult accounts of that region; a merged entry stays when any of its regions has a serving account.

func PrefixModelEntries added in v0.7.28

func PrefixModelEntries(models []map[string]any) []map[string]any

PrefixModelEntries rewrites bare model ids to provider-prefixed ids ("glm-5.2" -> "qoder/glm-5.2"). The gateway accepts bare ids only while the cross-provider pool is on; with it off, RejectsBareModel refuses them, so model lists must match what the gateway accepts or every client that picks a model from the list (console access page, /v1/models consumers) gets a 400. Entries already carrying a prefix, and the pooled qoder view (empty provider, owned_by=qoder), pass through unchanged. Region-qualified entries use the dash form so a specific region stays pinned ("workbuddy-cn/glm-5.3").

func ProviderModelEntry

func ProviderModelEntry(model providers.ModelInfo, provider string) map[string]any

Types

type AccountAdminAction

type AccountAdminAction struct {
	AccountID     string
	Action        string
	Method        string
	ContentType   string
	Body          []byte
	CallbackURL   string
	LoginMethod   string
	LoginStartURL string
}

type AccountAdminResult

type AccountAdminResult struct {
	Kind        string
	Session     providers.LoginSession
	LoginDone   bool
	LoginStatus string
	LoginMsg    string
	Worker      providers.AdminResponse
}

type AccountBundle added in v0.7.40

type AccountBundle struct {
	Format     string               `json:"format"`
	Version    int                  `json:"version"`
	ExportedAt string               `json:"exported_at"`
	Count      int                  `json:"count"`
	Accounts   []AccountBundleEntry `json:"accounts"`
}

AccountBundle is the full export/import file. Accounts without a stored credential are still exported so their routing settings survive migration.

type AccountBundleCredential added in v0.7.40

type AccountBundleCredential struct {
	Format     string          `json:"format"`
	Credential json.RawMessage `json:"credential,omitempty"`
	UserBlob   string          `json:"user_blob,omitempty"`
	MachineID  string          `json:"machine_id,omitempty"`
}

AccountBundleCredential is the portable credential material for one account. Native Qoder accounts carry user_blob/machine_id; all other providers carry an already-normalized credential payload.

type AccountBundleEntry added in v0.7.40

type AccountBundleEntry struct {
	Name                 string                   `json:"name"`
	Provider             string                   `json:"provider"`
	Region               string                   `json:"region"`
	AuthType             string                   `json:"auth_type,omitempty"`
	Enabled              bool                     `json:"enabled"`
	MaxInFlight          int                      `json:"max_inflight"`
	Priority             int                      `json:"priority"`
	DropSystemPrompt     *bool                    `json:"drop_system_prompt,omitempty"`
	ModelAliases         map[string]string        `json:"model_aliases,omitempty"`
	EnabledModels        []string                 `json:"enabled_models,omitempty"`
	ModelsRestricted     bool                     `json:"models_restricted,omitempty"`
	AutoCheckin          bool                     `json:"auto_checkin,omitempty"`
	CheckinTime          string                   `json:"checkin_time,omitempty"`
	WorkBuddyAutoCheckin bool                     `json:"workbuddy_auto_checkin,omitempty"`
	WorkBuddyCheckinTime string                   `json:"workbuddy_checkin_time,omitempty"`
	ProxyURL             string                   `json:"proxy_url,omitempty"`
	Credential           *AccountBundleCredential `json:"credential,omitempty"`
}

AccountBundleEntry is one account plus its settings and credential.

type AccountExport

type AccountExport struct {
	Format     string
	Name       string
	Provider   string
	Region     string
	Credential []byte
	UserBlob   string
	MachineID  string
}

type AccountImportInput

type AccountImportInput struct {
	Format               string          `json:"format"`
	Name                 string          `json:"name"`
	Provider             string          `json:"provider"`
	Region               string          `json:"region"`
	Enabled              bool            `json:"enabled"`
	MaxInFlight          int             `json:"max_inflight"`
	Priority             int             `json:"priority"`
	DropSystemPrompt     *bool           `json:"drop_system_prompt"`
	WorkBuddyAutoCheckin *bool           `json:"workbuddy_auto_checkin"`
	WorkBuddyCheckinTime string          `json:"workbuddy_checkin_time"`
	AutoCheckin          *bool           `json:"auto_checkin"`
	CheckinTime          string          `json:"checkin_time"`
	ProxyURL             string          `json:"proxy_url"`
	UserBlob             string          `json:"user_blob"`
	MachineID            string          `json:"machine_id"`
	Credential           json.RawMessage `json:"credential"`
}

type AccountImportItemError added in v0.7.10

type AccountImportItemError struct {
	Index   int    `json:"index"`
	Name    string `json:"name,omitempty"`
	Message string `json:"message"`
}

AccountImportItemError records one failed entry inside a multi-account package.

type AccountImportResult added in v0.7.10

type AccountImportResult struct {
	Object    string                   `json:"object"`
	Succeeded int                      `json:"succeeded"`
	Failed    int                      `json:"failed"`
	Data      []accounts.Account       `json:"data"`
	Errors    []AccountImportItemError `json:"errors,omitempty"`
}

AccountImportResult is the import outcome. Single-credential imports still populate Data with one account; packages may partially succeed.

type AccountModelAllow added in v0.7.34

type AccountModelAllow struct {
	Provider         string
	Region           string
	ModelsRestricted bool
	EnabledModels    []string
	// Aliases maps a client-facing canonical name onto the canonical catalog
	// model this account rewrites it to. The public list keeps an alias only
	// when some granted account both defines it and may serve its target.
	Aliases map[string]string
}

AccountModelAllow is one account's contribution to the public model list. A restricted account contributes only EnabledModels; an unrestricted one contributes every model of its provider and region. Enabled IDs are the canonical form stored by NormalizeAccountRouting.

type Accounts

type Accounts struct {
	Providers *providers.Registry
	// contains filtered or unexported fields
}

Accounts orchestrates console account operations through Store + Runtime. HTTP handlers keep decoding and error-code mapping.

func NewAccounts

func NewAccounts(runtime Runtime) *Accounts

func (*Accounts) Admin

func (*Accounts) Checkin

func (a *Accounts) Checkin(ctx context.Context, id string) (accounts.Account, error)

func (*Accounts) CheckinAll added in v0.7.40

func (a *Accounts) CheckinAll(ctx context.Context, force, includeDisabled bool) ([]accounts.CheckinAllResult, error)

func (*Accounts) CompleteLogin

func (a *Accounts) CompleteLogin(ctx context.Context, id, callback string) error

func (*Accounts) Create

func (*Accounts) Delete

func (a *Accounts) Delete(ctx context.Context, id string) error

func (*Accounts) Export

func (a *Accounts) Export(ctx context.Context, id string) (AccountExport, error)

func (*Accounts) ExportBundle added in v0.7.40

func (a *Accounts) ExportBundle(ctx context.Context) (AccountBundle, error)

ExportBundle builds a portable migration file from every stored account.

func (*Accounts) Get

func (*Accounts) GetStored

func (a *Accounts) GetStored(ctx context.Context, id string) (accounts.Account, error)

func (*Accounts) Import

func (a *Accounts) Import(ctx context.Context, input AccountImportInput, raw []byte) (accounts.Account, error)

func (*Accounts) ImportAll added in v0.7.10

func (a *Accounts) ImportAll(ctx context.Context, input AccountImportInput, raw []byte) (AccountImportResult, error)

ImportAll imports one credential or every entry in a multi-account package. Failure policy is partial success: valid entries are kept, failures are summarized in Errors instead of rolling back successes.

func (*Accounts) ImportBundle added in v0.7.40

func (a *Accounts) ImportBundle(ctx context.Context, bundle AccountBundle) (AccountImportResult, error)

ImportBundle restores every account in a migration file. Import is additive: existing accounts and IDs are never touched; new accounts get fresh IDs. Failure policy matches ImportAll: valid entries are kept, failures reported.

func (*Accounts) ImportCredentialPayload

func (a *Accounts) ImportCredentialPayload(ctx context.Context, input accounts.CreateAccount, format string, payload []byte, enable bool) (accounts.Account, error)

ImportCredentialPayload creates a disabled in-process account, writes the provider credential blob, then optionally enables it. Credential write failure deletes the account, matching the previous HTTP handler. A Get after a successful write is best-effort, also matching that handler.

func (*Accounts) ImportNative

func (a *Accounts) ImportNative(ctx context.Context, input accounts.ImportAccount) (accounts.Account, error)

func (*Accounts) List

func (a *Accounts) List(ctx context.Context, refresh bool) ([]accounts.AccountView, error)

func (*Accounts) ListCheckins

func (a *Accounts) ListCheckins(ctx context.Context, id string, limit int) ([]accounts.CheckinRecord, error)

func (*Accounts) LoadCredentialPayload

func (a *Accounts) LoadCredentialPayload(ctx context.Context, id string) (string, []byte, error)

func (*Accounts) LoadNativeCredential

func (a *Accounts) LoadNativeCredential(ctx context.Context, id string) (accounts.NativeCredential, error)

func (*Accounts) LoginPAT added in v0.6.7

func (a *Accounts) LoginPAT(ctx context.Context, id, token string) error

LoginPAT stores a pasted provider-native token for an in-process account whose adapter exposes a PAT credential (for example Command Code's user_… key). The Qoder child runtime keeps its worker login path; only adapters that implement CredentialImporter accept this. The token is wrapped as {"api_key": …} for the importer, then persisted in the provider's own credential format and the account is enabled and started.

func (*Accounts) PollLogin

func (a *Accounts) PollLogin(ctx context.Context, id string) (bool, string, error)

func (*Accounts) RefreshAccount

func (a *Accounts) RefreshAccount(ctx context.Context, id string, forceQuota bool) error

func (*Accounts) RefreshAll

func (a *Accounts) RefreshAll(ctx context.Context, forceQuota bool) error

func (*Accounts) ReloadProxyURL

func (a *Accounts) ReloadProxyURL(ctx context.Context, value string) error

func (*Accounts) ReplaceProxyAPIKey

func (a *Accounts) ReplaceProxyAPIKey(ctx context.Context, key string) error

func (*Accounts) StartLogin

func (a *Accounts) StartLogin(ctx context.Context, id string) (providers.LoginSession, error)

func (*Accounts) Update

func (a *Accounts) Update(ctx context.Context, id string, input accounts.UpdateAccount) (accounts.Account, error)

type Backup

type Backup struct {
	// contains filtered or unexported fields
}

func NewBackup

func NewBackup(store accounts.AccountStore) *Backup

func (*Backup) Snapshot

func (b *Backup) Snapshot(ctx context.Context, directory string, keep int) (accounts.Backup, error)

type Catalog

type Catalog struct {
	TTL      time.Duration
	Interval time.Duration
	Fetch    CatalogFetcher
	Store    CatalogStore
	Health   *CatalogHealth
	// contains filtered or unexported fields
}

Catalog is the shared /v1/models and /api/models display cache. It does not own runtime catalogs or proven-model membership.

func NewCatalog

func NewCatalog(fetch CatalogFetcher) *Catalog

func (*Catalog) CachedCount

func (c *Catalog) CachedCount(accountID string, mode CatalogMode) int

func (*Catalog) Get

func (c *Catalog) Get(refresh bool, accountID string, mode CatalogMode) ([]map[string]any, error)

Get returns the display catalog for one view. A failed fetch never discards a catalog that already served: the last successful list is returned and the failure is reported through Status instead.

func (*Catalog) ModelContextLength added in v0.6.7

func (c *Catalog) ModelContextLength(modelID string) (int, bool)

ModelContextLength resolves a model's default context window from the cached (or freshly fetched) merged catalog. It returns ok=false when the model or its window is unknown, so callers fall back to the static default.

func (*Catalog) ModelContextWindows added in v0.6.7

func (c *Catalog) ModelContextWindows(modelID string) (dev, max int, ok bool)

ModelContextWindows returns a model's default window and its largest selectable window. max is 0 when the model has no larger tier. ok=false when the model or its window is unknown, so callers fall back to the static default.

func (*Catalog) Refresh added in v0.7.13

func (c *Catalog) Refresh() (CatalogStatus, error)

Refresh forces one full reload and reports the resulting status. The returned error is the fetch error for this attempt; a served catalog is still intact when it is non-nil.

func (*Catalog) Restore added in v0.7.13

func (c *Catalog) Restore(ctx context.Context)

Restore loads the persisted snapshot into the cache without treating it as fresh: the entry keeps its original timestamp, so the next read refreshes it in the background while still serving the last known models.

func (*Catalog) RunRefresher added in v0.7.13

func (c *Catalog) RunRefresher(stop <-chan struct{})

RunRefresher keeps the merged catalog warm: it refreshes once at start and then every Interval, so a newly announced upstream model reaches clients without waiting for someone to open the model list. A zero or negative interval disables the loop (manual refresh only).

func (*Catalog) Status added in v0.7.13

func (c *Catalog) Status() CatalogStatus

Status reports the shared catalog's sync state plus each provider's own.

type CatalogAccount

type CatalogAccount struct {
	ID, Provider, Region string
	Worker               bool
}

CatalogAccount is a display source snapshot, not a scheduler item.

type CatalogCacheEntry

type CatalogCacheEntry struct {
	Models []map[string]any
	At     time.Time
}

type CatalogFetcher

type CatalogFetcher func(refresh bool, accountID string, mode CatalogMode) ([]map[string]any, error)

CatalogFetcher loads the raw display catalog. Runtime pool membership and SQLite settings stay outside this cache.

type CatalogHealth added in v0.7.13

type CatalogHealth struct {
	// contains filtered or unexported fields
}

CatalogHealth records per-provider catalog outcomes. Providers discover their own model list, so the merged catalog can be half fresh: recording per provider is what lets the console and /v1/models say which upstream is behind instead of only that "the catalog" failed.

func NewCatalogHealth added in v0.7.13

func NewCatalogHealth() *CatalogHealth

func (*CatalogHealth) Attempt added in v0.7.13

func (h *CatalogHealth) Attempt(provider string)

Attempt marks the start of one upstream catalog request.

func (*CatalogHealth) Failure added in v0.7.13

func (h *CatalogHealth) Failure(provider string, err error)

Failure records a failed catalog request. The previous model count and last success time stay in place so a failure never looks like an empty catalog.

func (*CatalogHealth) Restore added in v0.7.13

func (h *CatalogHealth) Restore(entries []CatalogProviderHealth)

Restore seeds health from a persisted snapshot. Timestamps are kept verbatim; a provider whose last attempt failed stays stale until the next success.

func (*CatalogHealth) Snapshot added in v0.7.13

func (h *CatalogHealth) Snapshot() []CatalogProviderHealth

Snapshot returns a stable, provider-sorted copy for display.

func (*CatalogHealth) Success added in v0.7.13

func (h *CatalogHealth) Success(provider string, models int)

Success records a served catalog and clears the provider's failure state.

type CatalogMode

type CatalogMode int
const (
	CatalogModeMerge CatalogMode = iota
	CatalogModeExpand
)

type CatalogProviderHealth added in v0.7.13

type CatalogProviderHealth struct {
	Provider      string `json:"provider"`
	Models        int    `json:"models"`
	LastAttemptAt string `json:"last_attempt_at,omitempty"`
	LastSuccessAt string `json:"last_success_at,omitempty"`
	LastError     string `json:"last_error,omitempty"`
	// Stale is true while the last attempt failed and the model list below
	// still describes the last successful sync.
	Stale bool `json:"stale"`
}

CatalogProviderHealth is one provider's upstream model-catalog sync state. It is display-only: a failure never removes models from the shared catalog.

type CatalogSource

type CatalogSource struct {
	Accounts     func() []CatalogAccount
	Providers    *providers.Registry
	WorkerModels func(context.Context, string, bool) ([]map[string]any, error)
	Health       *CatalogHealth
}

CatalogSource aggregates provider catalogs through injected data sources. Health is optional and records one outcome per provider request.

func (*CatalogSource) Fetch

func (a *CatalogSource) Fetch(refresh bool, accountID string, mode CatalogMode) ([]map[string]any, error)

type CatalogStatus added in v0.7.13

type CatalogStatus struct {
	SyncedAt        string                  `json:"synced_at,omitempty"`
	Stale           bool                    `json:"stale"`
	Refreshing      bool                    `json:"refreshing"`
	LastError       string                  `json:"last_error,omitempty"`
	IntervalSeconds int                     `json:"interval_seconds"`
	Providers       []CatalogProviderHealth `json:"providers"`
}

CatalogStatus is the whole display catalog's sync state. SyncedAt is the last successful full refresh of the merged view that backs /v1/models.

type CatalogStore added in v0.7.13

type CatalogStore interface {
	GetSecret(ctx context.Context, name string) (string, bool, error)
	SetSecret(ctx context.Context, name, value string) error
}

CatalogStore persists the last successful catalog snapshot. internal/store satisfies it; the narrow surface keeps control free of the store package.

type KeyRotation

type KeyRotation struct {
	Keys     *Keys
	Accounts *Accounts
	Mu       *sync.Mutex
	Generate func() (string, error)
	Publish  func(string)
}

KeyRotation serializes persistence, live authentication publication and worker reload.

func (*KeyRotation) Rotate

func (s *KeyRotation) Rotate(ctx context.Context) (string, error)

type Keys

type Keys struct {
	// contains filtered or unexported fields
}

func NewKeys

func NewKeys(store accounts.AccountStore) *Keys

func (*Keys) Create

func (k *Keys) Create(ctx context.Context, input accounts.CreateAPIKey) (accounts.APIKey, error)

func (*Keys) Delete

func (k *Keys) Delete(ctx context.Context, id string) error

func (*Keys) Get

func (k *Keys) Get(ctx context.Context, id string) (accounts.APIKey, error)

func (*Keys) List

func (k *Keys) List(ctx context.Context) ([]accounts.APIKey, error)

func (*Keys) SetConsoleSecret

func (k *Keys) SetConsoleSecret(ctx context.Context, secretName, secret string) error

func (*Keys) Touch

func (k *Keys) Touch(ctx context.Context, id string) error

func (*Keys) Update

func (k *Keys) Update(ctx context.Context, id string, input accounts.UpdateAPIKey) (accounts.APIKey, error)

type ModelSetting

type ModelSetting struct {
	Provider             string
	Model                string
	ContextLength        int
	DefaultContextLength int
	ContextCustom        bool
	MaxMode              bool
	ReasoningEffort      string
}

type OperationError

type OperationError struct {
	Code string
	Err  error
}

func (*OperationError) Error

func (e *OperationError) Error() string

func (*OperationError) Unwrap

func (e *OperationError) Unwrap() error

type ProviderModelSettingPatch

type ProviderModelSettingPatch struct {
	MaxMode         *bool
	ReasoningEffort *string
}

type Runtime

type Runtime interface {
	StartAccount(ctx context.Context, account accounts.Account) error
	StopAccount(id string) error
	RemoveAccount(id string) error
	SyncAccount(ctx context.Context, before, after accounts.Account) error
	AccountView(ctx context.Context, id string) (accounts.AccountView, error)
	Accounts(ctx context.Context) ([]accounts.AccountView, error)
	RefreshAccount(ctx context.Context, id string, forceQuota bool) error
	RefreshAll(ctx context.Context, forceQuota bool) error
	CheckinAccount(ctx context.Context, accountID string) (accounts.Account, error)
	CheckinAll(ctx context.Context, force, includeDisabled bool) ([]accounts.CheckinAllResult, error)
	ReloadProxyURL(ctx context.Context, value string) error
	ReplaceProxyAPIKey(ctx context.Context, key string) error
	WorkerAdmin(ctx context.Context, input providers.AdminRequest) (providers.AdminResponse, error)
	Store() accounts.AccountStore
}

Runtime is the process lifecycle surface control calls. Persistence and enable/import order live here; Manager only starts, stops, and syncs the pool.

type SecretStore

type SecretStore interface {
	GetSecret(ctx context.Context, name string) (string, bool, error)
	SetSecret(ctx context.Context, name, value string) error
}

type Services

type Services struct {
	Accounts *Accounts
	Keys     *Keys
	Settings *Settings
	Backup   *Backup
	Catalog  *Catalog
}

Services is the console application surface assembled by app.New.

func New

func New(runtime Runtime) *Services

type Settings

type Settings struct {
	// contains filtered or unexported fields
}

func NewSettings

func NewSettings(store accounts.AccountStore) *Settings

func (*Settings) BindCatalog added in v0.6.7

func (s *Settings) BindCatalog(catalog *Catalog)

BindCatalog lets settings resolve per-model context defaults from the display catalog. It is called during process assembly, before the server serves.

func (*Settings) DefaultContextLength added in v0.6.7

func (s *Settings) DefaultContextLength(modelID string) int

DefaultContextLength is the model's default context window: the upstream value the catalog reported when available, otherwise the static fallback.

func (*Settings) GetModelContext

func (s *Settings) GetModelContext(ctx context.Context, modelID string) (int, bool, error)

func (*Settings) GetProviderModelSetting

func (s *Settings) GetProviderModelSetting(ctx context.Context, provider, modelID string) (accounts.ProviderModelSetting, error)

func (*Settings) GetSecret

func (s *Settings) GetSecret(ctx context.Context, name string) (string, bool, error)

func (*Settings) ListModelContexts

func (s *Settings) ListModelContexts(ctx context.Context) (map[string]int, error)

func (*Settings) MaxContextLength added in v0.6.7

func (s *Settings) MaxContextLength(modelID string) int

MaxContextLength is the model's larger selectable window, or 0 when the catalog advertises no larger tier.

func (*Settings) ReadModelSetting

func (s *Settings) ReadModelSetting(ctx context.Context, provider, modelID string) (ModelSetting, error)

func (*Settings) SetModelContext

func (s *Settings) SetModelContext(ctx context.Context, modelID string, contextLength int) error

func (*Settings) SetProviderModelSetting

func (s *Settings) SetProviderModelSetting(ctx context.Context, provider, modelID string, setting accounts.ProviderModelSetting) error

func (*Settings) SetSecret

func (s *Settings) SetSecret(ctx context.Context, name, value string) error

func (*Settings) SetSecretOrEmpty

func (s *Settings) SetSecretOrEmpty(ctx context.Context, name, value string) error

func (*Settings) UpdateModelSetting

func (s *Settings) UpdateModelSetting(ctx context.Context, provider, modelID string, contextLength *int, patch ProviderModelSettingPatch) (ModelSetting, error)

func (*Settings) UpdateProviderModelSetting

func (s *Settings) UpdateProviderModelSetting(ctx context.Context, provider, modelID string, patch ProviderModelSettingPatch) (accounts.ProviderModelSetting, error)

func (*Settings) WorkBuddyCheckinTimeDefault

func (s *Settings) WorkBuddyCheckinTimeDefault(ctx context.Context) string

type System

type System struct {
	Settings          *Settings
	Accounts          *Accounts
	Pool              *executor.Pool
	Executor          *executor.ChatExecutor
	CrossProviderPool *atomic.Bool
	Mu                *sync.Mutex
}

func (*System) Current

func (h *System) Current(ctx context.Context) SystemSettings

func (*System) Patch

func (h *System) Patch(ctx context.Context, input SystemSettingsPatch) error

type SystemSettings

type SystemSettings struct {
	CrossProviderModelPool  bool                          `json:"cross_provider_model_pool"`
	CheckinDisabledAccounts bool                          `json:"checkin_disabled_accounts"`
	RoutingStrategy         string                        `json:"routing_strategy"`
	ProxyURL                string                        `json:"proxy_url"`
	WorkBuddyCheckinTime    string                        `json:"workbuddy_checkin_time"`
	CheckinTimes            map[string]string             `json:"checkin_times"`
	Timezone                string                        `json:"timezone"`
	SessionAffinity         executor.SessionAffinityStats `json:"session_affinity"`
}

type SystemSettingsPatch

type SystemSettingsPatch struct {
	CrossProviderModelPool  *bool             `json:"cross_provider_model_pool"`
	CheckinDisabledAccounts *bool             `json:"checkin_disabled_accounts"`
	RoutingStrategy         *string           `json:"routing_strategy"`
	ProxyURL                *string           `json:"proxy_url"`
	WorkBuddyCheckinTime    *string           `json:"workbuddy_checkin_time"`
	CheckinTimes            map[string]string `json:"checkin_times"`
}

Jump to

Keyboard shortcuts

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