registry

package
v6.8.53 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package registry provides model definitions and lookup helpers for various AI providers. Static model metadata is loaded from the embedded models.json file and can be refreshed from network.

Package registry provides centralized model management for all AI service providers. It implements a dynamic model registry with reference counting to track active clients and automatically hide models when no clients are available or when quota is exceeded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetModelRefreshCallback added in v6.8.52

func SetModelRefreshCallback(cb ModelRefreshCallback)

SetModelRefreshCallback registers a callback that is invoked when startup or periodic model refresh detects changes. Only one callback is supported; subsequent calls replace the previous callback.

func StartModelsUpdater added in v6.8.51

func StartModelsUpdater(ctx context.Context)

StartModelsUpdater starts a background updater that fetches models immediately on startup and then refreshes the model catalog every 3 hours. Safe to call multiple times; only one updater will run.

Types

type ModelInfo

type ModelInfo struct {
	// ID is the unique identifier for the model
	ID string `json:"id"`
	// Object type for the model (typically "model")
	Object string `json:"object"`
	// Created timestamp when the model was created
	Created int64 `json:"created"`
	// OwnedBy indicates the organization that owns the model
	OwnedBy string `json:"owned_by"`
	// Type indicates the model type (e.g., "claude", "gemini", "openai")
	Type string `json:"type"`
	// DisplayName is the human-readable name for the model
	DisplayName string `json:"display_name,omitempty"`
	// Name is used for Gemini-style model names
	Name string `json:"name,omitempty"`
	// Version is the model version
	Version string `json:"version,omitempty"`
	// Description provides detailed information about the model
	Description string `json:"description,omitempty"`
	// InputTokenLimit is the maximum input token limit
	InputTokenLimit int `json:"inputTokenLimit,omitempty"`
	// OutputTokenLimit is the maximum output token limit
	OutputTokenLimit int `json:"outputTokenLimit,omitempty"`
	// SupportedGenerationMethods lists supported generation methods
	SupportedGenerationMethods []string `json:"supportedGenerationMethods,omitempty"`
	// ContextLength is the context window size
	ContextLength int `json:"context_length,omitempty"`
	// MaxCompletionTokens is the maximum completion tokens
	MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
	// SupportedParameters lists supported parameters
	SupportedParameters []string `json:"supported_parameters,omitempty"`
	// SupportedInputModalities lists supported input modalities (e.g., TEXT, IMAGE, VIDEO, AUDIO)
	SupportedInputModalities []string `json:"supportedInputModalities,omitempty"`
	// SupportedOutputModalities lists supported output modalities (e.g., TEXT, IMAGE)
	SupportedOutputModalities []string `json:"supportedOutputModalities,omitempty"`

	// Thinking holds provider-specific reasoning/thinking budget capabilities.
	// This is optional and currently used for Gemini thinking budget normalization.
	Thinking *ThinkingSupport `json:"thinking,omitempty"`

	// UserDefined indicates this model was defined through config file's models[]
	// array (e.g., openai-compatibility.*.models[], *-api-key.models[]).
	// UserDefined models have thinking configuration passed through without validation.
	UserDefined bool `json:"-"`
}

ModelInfo represents information about an available model

func GetAIStudioModels added in v6.2.37

func GetAIStudioModels() []*ModelInfo

GetAIStudioModels returns model definitions for AI Studio.

func GetAntigravityModels added in v6.8.52

func GetAntigravityModels() []*ModelInfo

GetAntigravityModels returns the standard Antigravity model definitions.

func GetClaudeModels

func GetClaudeModels() []*ModelInfo

GetClaudeModels returns the standard Claude model definitions.

func GetCodexFreeModels added in v6.8.51

func GetCodexFreeModels() []*ModelInfo

GetCodexFreeModels returns model definitions for the Codex free plan tier.

func GetCodexPlusModels added in v6.8.51

func GetCodexPlusModels() []*ModelInfo

GetCodexPlusModels returns model definitions for the Codex plus plan tier.

func GetCodexProModels added in v6.8.51

func GetCodexProModels() []*ModelInfo

GetCodexProModels returns model definitions for the Codex pro plan tier.

func GetCodexTeamModels added in v6.8.51

func GetCodexTeamModels() []*ModelInfo

GetCodexTeamModels returns model definitions for the Codex team plan tier.

func GetGeminiCLIModels

func GetGeminiCLIModels() []*ModelInfo

GetGeminiCLIModels returns Gemini model definitions for the Gemini CLI.

func GetGeminiModels

func GetGeminiModels() []*ModelInfo

GetGeminiModels returns the standard Gemini model definitions.

func GetGeminiVertexModels added in v6.3.58

func GetGeminiVertexModels() []*ModelInfo

GetGeminiVertexModels returns Gemini model definitions for Vertex AI.

func GetIFlowModels added in v6.1.0

func GetIFlowModels() []*ModelInfo

GetIFlowModels returns the standard iFlow model definitions.

func GetKimiModels added in v6.8.0

func GetKimiModels() []*ModelInfo

GetKimiModels returns the standard Kimi (Moonshot AI) model definitions.

func GetQwenModels

func GetQwenModels() []*ModelInfo

GetQwenModels returns the standard Qwen model definitions.

func GetStaticModelDefinitionsByChannel added in v6.7.26

func GetStaticModelDefinitionsByChannel(channel string) []*ModelInfo

GetStaticModelDefinitionsByChannel returns static model definitions for a given channel/provider. It returns nil when the channel is unknown.

Supported channels:

  • claude
  • gemini
  • vertex
  • gemini-cli
  • aistudio
  • codex
  • qwen
  • iflow
  • kimi
  • antigravity

func LookupModelInfo added in v6.7.0

func LookupModelInfo(modelID string, provider ...string) *ModelInfo

LookupModelInfo searches dynamic registry (provider-specific > global) then static definitions.

func LookupStaticModelInfo added in v6.6.70

func LookupStaticModelInfo(modelID string) *ModelInfo

LookupStaticModelInfo searches all static model definitions for a model by ID. Returns nil if no matching model is found.

type ModelRefreshCallback added in v6.8.52

type ModelRefreshCallback func(changedProviders []string)

ModelRefreshCallback is invoked when startup or periodic model refresh detects changes. changedProviders contains the provider names whose model definitions changed.

type ModelRegistration

type ModelRegistration struct {
	// Info contains the model metadata
	Info *ModelInfo
	// InfoByProvider maps provider identifiers to specific ModelInfo to support differing capabilities.
	InfoByProvider map[string]*ModelInfo
	// Count is the number of active clients that can provide this model
	Count int
	// LastUpdated tracks when this registration was last modified
	LastUpdated time.Time
	// QuotaExceededClients tracks which clients have exceeded quota for this model
	QuotaExceededClients map[string]*time.Time
	// Providers tracks available clients grouped by provider identifier
	Providers map[string]int
	// SuspendedClients tracks temporarily disabled clients keyed by client ID
	SuspendedClients map[string]string
}

ModelRegistration tracks a model's availability

type ModelRegistry

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

ModelRegistry manages the global registry of available models

func GetGlobalRegistry

func GetGlobalRegistry() *ModelRegistry

GetGlobalRegistry returns the global model registry instance

func (*ModelRegistry) CleanupExpiredQuotas

func (r *ModelRegistry) CleanupExpiredQuotas()

CleanupExpiredQuotas removes expired quota tracking entries

func (*ModelRegistry) ClearModelQuotaExceeded

func (r *ModelRegistry) ClearModelQuotaExceeded(clientID, modelID string)

ClearModelQuotaExceeded removes quota exceeded status for a model and client Parameters:

  • clientID: The client to clear quota status for
  • modelID: The model to clear quota status for

func (*ModelRegistry) ClientSupportsModel added in v6.3.2

func (r *ModelRegistry) ClientSupportsModel(clientID, modelID string) bool

ClientSupportsModel reports whether the client registered support for modelID.

func (*ModelRegistry) GetAvailableModels

func (r *ModelRegistry) GetAvailableModels(handlerType string) []map[string]any

GetAvailableModels returns all models that have at least one available client Parameters:

  • handlerType: The handler type to filter models for (e.g., "openai", "claude", "gemini")

Returns:

  • []map[string]any: List of available models in the requested format

func (*ModelRegistry) GetAvailableModelsByProvider added in v6.6.75

func (r *ModelRegistry) GetAvailableModelsByProvider(provider string) []*ModelInfo

GetAvailableModelsByProvider returns models available for the given provider identifier. Parameters:

  • provider: Provider identifier (e.g., "codex", "gemini", "antigravity")

Returns:

  • []*ModelInfo: List of available models for the provider

func (*ModelRegistry) GetFirstAvailableModel added in v6.3.35

func (r *ModelRegistry) GetFirstAvailableModel(handlerType string) (string, error)

GetFirstAvailableModel returns the first available model for the given handler type. It prioritizes models by their creation timestamp (newest first) and checks if they have available clients that are not suspended or over quota.

Parameters:

  • handlerType: The API handler type (e.g., "openai", "claude", "gemini")

Returns:

  • string: The model ID of the first available model, or empty string if none available
  • error: An error if no models are available

func (*ModelRegistry) GetModelCount

func (r *ModelRegistry) GetModelCount(modelID string) int

GetModelCount returns the number of available clients for a specific model Parameters:

  • modelID: The model ID to check

Returns:

  • int: Number of available clients for the model

func (*ModelRegistry) GetModelInfo added in v6.3.0

func (r *ModelRegistry) GetModelInfo(modelID, provider string) *ModelInfo

GetModelInfo returns ModelInfo, prioritizing provider-specific definition if available.

func (*ModelRegistry) GetModelProviders

func (r *ModelRegistry) GetModelProviders(modelID string) []string

GetModelProviders returns provider identifiers that currently supply the given model Parameters:

  • modelID: The model ID to check

Returns:

  • []string: Provider identifiers ordered by availability count (descending)

func (*ModelRegistry) GetModelsForClient added in v6.6.11

func (r *ModelRegistry) GetModelsForClient(clientID string) []*ModelInfo

GetModelsForClient returns the models registered for a specific client. Parameters:

  • clientID: The client identifier (typically auth file name or auth ID)

Returns:

  • []*ModelInfo: List of models registered for this client, nil if client not found

func (*ModelRegistry) RegisterClient

func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models []*ModelInfo)

RegisterClient registers a client and its supported models Parameters:

  • clientID: Unique identifier for the client
  • clientProvider: Provider name (e.g., "gemini", "claude", "openai")
  • models: List of models that this client can provide

func (*ModelRegistry) ResumeClientModel

func (r *ModelRegistry) ResumeClientModel(clientID, modelID string)

ResumeClientModel clears a previous suspension so the client counts toward availability again. Parameters:

  • clientID: The client to resume
  • modelID: The model being resumed

func (*ModelRegistry) SetHook added in v6.6.79

func (r *ModelRegistry) SetHook(hook ModelRegistryHook)

SetHook sets an optional hook for observing model registration changes.

func (*ModelRegistry) SetModelQuotaExceeded

func (r *ModelRegistry) SetModelQuotaExceeded(clientID, modelID string)

SetModelQuotaExceeded marks a model as quota exceeded for a specific client Parameters:

  • clientID: The client that exceeded quota
  • modelID: The model that exceeded quota

func (*ModelRegistry) SuspendClientModel

func (r *ModelRegistry) SuspendClientModel(clientID, modelID, reason string)

SuspendClientModel marks a client's model as temporarily unavailable until explicitly resumed. Parameters:

  • clientID: The client to suspend
  • modelID: The model affected by the suspension
  • reason: Optional description for observability

func (*ModelRegistry) UnregisterClient

func (r *ModelRegistry) UnregisterClient(clientID string)

UnregisterClient removes a client and decrements counts for its models Parameters:

  • clientID: Unique identifier for the client to remove

type ModelRegistryHook added in v6.6.79

type ModelRegistryHook interface {
	OnModelsRegistered(ctx context.Context, provider, clientID string, models []*ModelInfo)
	OnModelsUnregistered(ctx context.Context, provider, clientID string)
}

ModelRegistryHook provides optional callbacks for external integrations to track model list changes. Hook implementations must be non-blocking and resilient; calls are executed asynchronously and panics are recovered.

type ThinkingSupport added in v6.3.0

type ThinkingSupport struct {
	// Min is the minimum allowed thinking budget (inclusive).
	Min int `json:"min,omitempty"`
	// Max is the maximum allowed thinking budget (inclusive).
	Max int `json:"max,omitempty"`
	// ZeroAllowed indicates whether 0 is a valid value (to disable thinking).
	ZeroAllowed bool `json:"zero_allowed,omitempty"`
	// DynamicAllowed indicates whether -1 is a valid value (dynamic thinking budget).
	DynamicAllowed bool `json:"dynamic_allowed,omitempty"`
	// Levels defines discrete reasoning effort levels (e.g., "low", "medium", "high").
	// When set, the model uses level-based reasoning instead of token budgets.
	Levels []string `json:"levels,omitempty"`
}

ThinkingSupport describes a model family's supported internal reasoning budget range. Values are interpreted in provider-native token units.

Jump to

Keyboard shortcuts

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