config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package config holds graycode-router's provider configuration model and accessors for the active provider/model selection (ActiveProvider, ActiveModel, SetActiveProvider, SetProviderModel) used to route requests.

Index

Constants

View Source
const (
	OllamaDefaultBaseURL     = "http://localhost:11434/v1"
	OpenCodeGoDefaultBaseURL = opencodego.DefaultBaseURL
)
View Source
const (
	DefaultOpenAIBaseURL            = "https://api.openai.com/v1"
	DefaultOpenRouterOpenAIBaseURL  = "https://openrouter.ai/api/v1"
	DefaultConcentrateOpenAIBaseURL = "https://api.concentrate.ai/v1"
	DefaultOpenGatewayOpenAIBaseURL = "https://opengateway.gitlawb.com/v1"
	DefaultCanopyWaveOpenAIBaseURL  = "https://inference.canopywave.io/v1"
	DefaultZAIOpenAIBaseURL         = "https://api.z.ai/api/paas/v4"
	DefaultZAICodingOpenAIBaseURL   = "https://api.z.ai/api/coding/paas/v4"
	DefaultGeminiOpenAIBaseURL      = "https://generativelanguage.googleapis.com/v1beta/openai"
	DefaultAnthropicOpenAIBaseURL   = "https://api.anthropic.com/v1"
	DefaultGrokOpenAIBaseURL        = "https://api.x.ai/v1"
	DefaultOpenCodeGoBaseURL        = opencodego.DefaultBaseURL
	DefaultKimiOpenAIBaseURL        = "https://api.moonshot.ai/v1"
	DefaultXiaomiOpenAIBaseURL      = "https://api.xiaomimimo.com/v1"
	DefaultMiniMaxOpenAIBaseURL     = "https://api.minimax.io/v1"
	DefaultGroqOpenAIBaseURL        = "https://api.groq.com/openai/v1"
	DefaultPoolsideOpenAIBaseURL    = "https://inference.poolside.ai/v1"
	DefaultClinePassOpenAIBaseURL   = "https://api.cline.bot/api/v1" // #nosec G101 -- public API base URL, not a secret value
	DefaultStepFunOpenAIBaseURL     = "https://api.stepfun.ai/v1"
	DefaultAgnesOpenAIBaseURL       = "https://apihub.agnes-ai.com/v1"
	DefaultLongCatOpenAIBaseURL     = "https://api.longcat.chat/openai/v1"
	DefaultLongCatAnthropicBaseURL  = "https://api.longcat.chat/anthropic"
	DefaultFireworksOpenAIBaseURL   = "https://api.fireworks.ai/inference/v1"
)

Default base URLs for each provider.

View Source
const (
	EnvXiaomiPaygAPIKey       = "XIAOMI_MIMO_PAYG_API_KEY"       // #nosec G101 -- environment variable name string, not a secret value
	EnvXiaomiTokenPlanAPIKey  = "XIAOMI_MIMO_TOKEN_PLAN_API_KEY" // #nosec G101 -- environment variable name string, not a secret value
	EnvXiaomiPaygBaseURL      = "XIAOMI_MIMO_PAYG_BASE_URL"
	EnvXiaomiTokenPlanBaseURL = "XIAOMI_MIMO_TOKEN_PLAN_BASE_URL" // #nosec G101 -- environment variable name string, not a secret value
	EnvXiaomiTokenPlanRegion  = "XIAOMI_MIMO_TOKEN_PLAN_REGION"   // #nosec G101 -- environment variable name string, not a secret value
)

Variables

View Source
var (
	AnthropicRuntimeProfile = RuntimeProviderProfile{
		Mode: "anthropic", DefaultBaseURL: DefaultAnthropicOpenAIBaseURL, DefaultModel: "claude-3-5-sonnet-latest",
		DetectionEnv: []string{"ANTHROPIC_API_KEY"},
		ModelEnv:     []string{"ANTHROPIC_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"ANTHROPIC_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "ANTHROPIC_API_KEY", Source: "anthropic"}, {Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	OpenAIRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultOpenAIBaseURL, DefaultModel: "gpt-4o",
		DetectionEnv: []string{"OPENAI_API_KEY"},
		ModelEnv:     []string{"OPENAI_MODEL"},
		BaseURLEnv:   []string{"OPENAI_BASE_URL", "OPENAI_API_BASE"},
		APIKeys:      []APIKeyDef{{Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	AgnesRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultAgnesOpenAIBaseURL,
		DetectionEnv: []string{"AGNES_API_KEY"},
		ModelEnv:     []string{"AGNES_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"AGNES_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "AGNES_API_KEY", Source: "agnes"}},
	}
	LongCatRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultLongCatOpenAIBaseURL,
		DetectionEnv: []string{"LONGCAT_API_KEY"},
		ModelEnv:     []string{"LONGCAT_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"LONGCAT_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "LONGCAT_API_KEY", Source: "longcat"}},
	}
	FireworksRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultFireworksOpenAIBaseURL,
		DetectionEnv: []string{"FIREWORKS_API_KEY"},
		ModelEnv:     []string{"FIREWORKS_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"FIREWORKS_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "FIREWORKS_API_KEY", Source: "fireworks"}},
	}
	GrokRuntimeProfile = RuntimeProviderProfile{
		Mode: "grok", DefaultBaseURL: DefaultGrokOpenAIBaseURL, DefaultModel: "grok-2",
		DetectionEnv: []string{"XAI_API_KEY"},
		ModelEnv:     []string{"XAI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"XAI_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "XAI_API_KEY", Source: "grok"}},
	}
	GeminiRuntimeProfile = RuntimeProviderProfile{
		Mode: "gemini", DefaultBaseURL: DefaultGeminiOpenAIBaseURL, DefaultModel: "gemini-2.0-flash",
		DetectionEnv: []string{"GEMINI_API_KEY"},
		ModelEnv:     []string{"GEMINI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"GEMINI_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "GEMINI_API_KEY", Source: "gemini"}, {Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	VertexRuntimeProfile = RuntimeProviderProfile{
		Mode: "gemini-vertex", DefaultBaseURL: "", DefaultModel: "gemini-2.0-flash",
		DetectionEnv: []string{"VERTEX_ACCESS_TOKEN", "GOOGLE_OAUTH_ACCESS_TOKEN"},
		ModelEnv:     []string{"VERTEX_MODEL", "GEMINI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"VERTEX_PROJECT_ID", "VERTEX_REGION"},
		APIKeys:      []APIKeyDef{{Env: "VERTEX_ACCESS_TOKEN", Source: "vertex"}, {Env: "GOOGLE_OAUTH_ACCESS_TOKEN", Source: "google"}},
	}
	AzureRuntimeProfile = RuntimeProviderProfile{
		Mode: "azure", DefaultBaseURL: "", DefaultModel: "",
		DetectionEnv: []string{"AZURE_OPENAI_API_KEY"},
		ModelEnv:     []string{"AZURE_OPENAI_DEPLOYMENT", "AZURE_OPENAI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"AZURE_OPENAI_ENDPOINT"},
		APIKeys:      []APIKeyDef{{Env: "AZURE_OPENAI_API_KEY", Source: "azure"}},
	}
	BedrockRuntimeProfile = RuntimeProviderProfile{
		Mode: "bedrock", DefaultBaseURL: "", DefaultModel: "",
		DetectionEnv: []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"},
		ModelEnv:     []string{"BEDROCK_MODEL", "ANTHROPIC_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"AWS_REGION", "AWS_DEFAULT_REGION"},
		APIKeys:      []APIKeyDef{{Env: "AWS_SECRET_ACCESS_KEY", Source: "bedrock"}, {Env: "AWS_ACCESS_KEY_ID", Source: "bedrock"}},
	}
	OpenRouterRuntimeProfile = RuntimeProviderProfile{
		Mode: "openrouter", DefaultBaseURL: DefaultOpenRouterOpenAIBaseURL,
		DetectionEnv: []string{"OPENROUTER_API_KEY"},
		ModelEnv:     []string{"OPENROUTER_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"OPENROUTER_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "OPENROUTER_API_KEY", Source: "openrouter"}, {Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	ConcentrateRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultConcentrateOpenAIBaseURL,
		DetectionEnv: []string{"CONCENTRATE_API_KEY"},
		ModelEnv:     []string{"CONCENTRATE_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"CONCENTRATE_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "CONCENTRATE_API_KEY", Source: "concentrate"}, {Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	OpenGatewayRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultOpenGatewayOpenAIBaseURL,
		DetectionEnv: []string{"OPENGATEWAY_API_KEY"},
		ModelEnv:     []string{"OPENGATEWAY_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"OPENGATEWAY_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "OPENGATEWAY_API_KEY", Source: "opengateway"}, {Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	ZAIPaygRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultZAIOpenAIBaseURL,
		DetectionEnv: []string{"ZAI_API_KEY"},
		ModelEnv:     []string{"ZAI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"ZAI_BASE_URL", "ZAI_API_BASE"},
		APIKeys:      []APIKeyDef{{Env: "ZAI_API_KEY", Source: "zai_payg"}},
	}
	ZAICodingRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultZAICodingOpenAIBaseURL,
		DetectionEnv: []string{"ZAI_CODING_API_KEY"},
		ModelEnv:     []string{"ZAI_CODING_MODEL", "ZAI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"ZAI_CODING_BASE_URL", "ZAI_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "ZAI_CODING_API_KEY", Source: "zai_coding"}},
	}
	CanopyWaveRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultCanopyWaveOpenAIBaseURL,
		DetectionEnv: []string{"CANOPYWAVE_API_KEY"},
		ModelEnv:     []string{"CANOPYWAVE_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"CANOPYWAVE_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "CANOPYWAVE_API_KEY", Source: "canopywave"}, {Env: "OPENAI_API_KEY", Source: "openai"}},
	}
	DeepSeekRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: "https://api.deepseek.com",
		DetectionEnv: []string{"DEEPSEEK_API_KEY"},
		ModelEnv:     []string{"DEEPSEEK_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"DEEPSEEK_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "DEEPSEEK_API_KEY", Source: "deepseek"}},
	}
	OpenCodeGoRuntimeProfile = RuntimeProviderProfile{
		Mode: "opencodego", DefaultBaseURL: DefaultOpenCodeGoBaseURL,
		DetectionEnv: []string{"OPENCODEGO_API_KEY"},
		ModelEnv:     []string{"OPENCODEGO_MODEL"},
		BaseURLEnv:   []string{"OPENCODEGO_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "OPENCODEGO_API_KEY", Source: "opencodego"}},
	}
	KimiRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultKimiOpenAIBaseURL,
		DetectionEnv: []string{"MOONSHOT_API_KEY"},
		ModelEnv:     []string{"MOONSHOT_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"MOONSHOT_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "MOONSHOT_API_KEY", Source: "kimi"}},
	}
	XiaomiPaygRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultXiaomiOpenAIBaseURL,
		DetectionEnv: []string{EnvXiaomiPaygAPIKey},
		ModelEnv:     []string{"XIAOMI_MIMO_PAYG_MODEL", "XIAOMI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{EnvXiaomiPaygBaseURL, "XIAOMI_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: EnvXiaomiPaygAPIKey, Source: "xiaomi_mimo_payg"}},
	}
	XiaomiTokenPlanRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: "",
		DetectionEnv: []string{EnvXiaomiTokenPlanAPIKey},
		ModelEnv:     []string{"XIAOMI_MIMO_TOKEN_PLAN_MODEL", "XIAOMI_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{EnvXiaomiTokenPlanBaseURL},
		APIKeys:      []APIKeyDef{{Env: EnvXiaomiTokenPlanAPIKey, Source: "xiaomi_mimo_token_plan"}},
	}
	MiniMaxTokenPlanRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultMiniMaxOpenAIBaseURL,
		DetectionEnv: []string{"MINIMAX_TOKEN_PLAN_API_KEY"},
		ModelEnv:     []string{"MINIMAX_TOKEN_PLAN_MODEL", "MINIMAX_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"MINIMAX_TOKEN_PLAN_BASE_URL", "MINIMAX_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "MINIMAX_TOKEN_PLAN_API_KEY", Source: "minimax_token_plan"}},
	}
	MiniMaxPaygRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultMiniMaxOpenAIBaseURL,
		DetectionEnv: []string{"MINIMAX_PAYG_API_KEY"},
		ModelEnv:     []string{"MINIMAX_PAYG_MODEL", "MINIMAX_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"MINIMAX_PAYG_BASE_URL", "MINIMAX_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "MINIMAX_PAYG_API_KEY", Source: "minimax_payg"}},
	}
	OllamaRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: OllamaDefaultBaseURL,
		DetectionEnv: []string{"OLLAMA_BASE_URL"},
		ModelEnv:     []string{"OLLAMA_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"OLLAMA_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "OLLAMA_API_KEY", Source: "ollama"}},
	}
	PoolsideRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultPoolsideOpenAIBaseURL,
		DetectionEnv: []string{"POOLSIDE_API_KEY"},
		ModelEnv:     []string{"POOLSIDE_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"POOLSIDE_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "POOLSIDE_API_KEY", Source: "poolside"}},
	}
	GroqRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: "https://api.groq.com/openai/v1",
		DetectionEnv: []string{"GROQ_API_KEY"},
		ModelEnv:     []string{"GROQ_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"GROQ_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "GROQ_API_KEY", Source: "groq"}},
	}
	ClinePassRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultClinePassOpenAIBaseURL,
		DetectionEnv: []string{"CLINE_API_KEY"},
		ModelEnv:     []string{"CLINE_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"CLINE_API_BASE"},
		APIKeys:      []APIKeyDef{{Env: "CLINE_API_KEY", Source: "clinepass"}},
	}
	StepFunRuntimeProfile = RuntimeProviderProfile{
		Mode: "openai", DefaultBaseURL: DefaultStepFunOpenAIBaseURL,
		DetectionEnv: []string{"STEP_API_KEY"},
		ModelEnv:     []string{"STEP_MODEL", "OPENAI_MODEL"},
		BaseURLEnv:   []string{"STEP_BASE_URL"},
		APIKeys:      []APIKeyDef{{Env: "STEP_API_KEY", Source: "stepfun"}},
	}
)

Provider runtime profiles.

APIProviderDetectionOrder is the priority order for provider detection.

View Source
var OpenAICompatibleRuntimeProfileOrder = []string{
	"concentrate", "agnes", "longcat", "fireworks", "openrouter", "grok", "gemini", "anthropic", "zai_coding", "zai_payg", "canopywave", "deepseek", "poolside", "groq", "clinepass", "openai", "opencodego", "kimi", "xiaomi_mimo_payg", "xiaomi_mimo_token_plan", "minimax_token_plan", "minimax_payg", "stepfun", "opengateway",
}

OpenAICompatibleRuntimeProfileOrder is the detection order for runtime profiles.

View Source
var OpenAICompatibleRuntimeProfiles = map[string]RuntimeProviderProfile{
	"concentrate":            ConcentrateRuntimeProfile,
	"agnes":                  AgnesRuntimeProfile,
	"longcat":                LongCatRuntimeProfile,
	"fireworks":              FireworksRuntimeProfile,
	"opengateway":            OpenGatewayRuntimeProfile,
	"anthropic":              AnthropicRuntimeProfile,
	"grok":                   GrokRuntimeProfile,
	"gemini":                 GeminiRuntimeProfile,
	"zai_payg":               ZAIPaygRuntimeProfile,
	"zai_coding":             ZAICodingRuntimeProfile,
	"canopywave":             CanopyWaveRuntimeProfile,
	"deepseek":               DeepSeekRuntimeProfile,
	"poolside":               PoolsideRuntimeProfile,
	"groq":                   GroqRuntimeProfile,
	"clinepass":              ClinePassRuntimeProfile,
	"openai":                 OpenAIRuntimeProfile,
	"openrouter":             OpenRouterRuntimeProfile,
	"opencodego":             OpenCodeGoRuntimeProfile,
	"kimi":                   KimiRuntimeProfile,
	"xiaomi_mimo_payg":       XiaomiPaygRuntimeProfile,
	"xiaomi_mimo_token_plan": XiaomiTokenPlanRuntimeProfile,
	"minimax_token_plan":     MiniMaxTokenPlanRuntimeProfile,
	"minimax_payg":           MiniMaxPaygRuntimeProfile,
	"stepfun":                StepFunRuntimeProfile,
}

OpenAICompatibleRuntimeProfiles maps profile key to its runtime profile.

View Source
var ProviderDetectionOrder = APIProviderDetectionOrder

ProviderDetectionOrder is the priority order for provider detection.

ProviderModelEnvKeys maps each provider to its model env var keys.

View Source
var RuntimeProviderProfiles = map[string]RuntimeProviderProfile{
	"anthropic":              AnthropicRuntimeProfile,
	"openai":                 OpenAIRuntimeProfile,
	"agnes":                  AgnesRuntimeProfile,
	"longcat":                LongCatRuntimeProfile,
	"fireworks":              FireworksRuntimeProfile,
	"grok":                   GrokRuntimeProfile,
	"gemini":                 GeminiRuntimeProfile,
	"vertex":                 VertexRuntimeProfile,
	"azure":                  AzureRuntimeProfile,
	"bedrock":                BedrockRuntimeProfile,
	"openrouter":             OpenRouterRuntimeProfile,
	"concentrate":            ConcentrateRuntimeProfile,
	"opengateway":            OpenGatewayRuntimeProfile,
	"zai_payg":               ZAIPaygRuntimeProfile,
	"zai_coding":             ZAICodingRuntimeProfile,
	"canopywave":             CanopyWaveRuntimeProfile,
	"deepseek":               DeepSeekRuntimeProfile,
	"poolside":               PoolsideRuntimeProfile,
	"groq":                   GroqRuntimeProfile,
	"clinepass":              ClinePassRuntimeProfile,
	"opencodego":             OpenCodeGoRuntimeProfile,
	"kimi":                   KimiRuntimeProfile,
	"xiaomi_mimo_payg":       XiaomiPaygRuntimeProfile,
	"xiaomi_mimo_token_plan": XiaomiTokenPlanRuntimeProfile,
	"minimax_token_plan":     MiniMaxTokenPlanRuntimeProfile,
	"minimax_payg":           MiniMaxPaygRuntimeProfile,
	"stepfun":                StepFunRuntimeProfile,
	"ollama":                 OllamaRuntimeProfile,
}

RuntimeProviderProfiles maps provider/profile keys to runtime detection profiles.

Functions

func ActiveModel

func ActiveModel(cfg *ProviderConfig) string

ActiveModel returns the user's selected model from provider.json (canonical when possible).

func ActiveProvider

func ActiveProvider(cfg *ProviderConfig) string

ActiveProvider returns the configured active provider id.

func AddProfile

func AddProfile(profile ProviderProfile) error

AddProfile adds or updates a profile.

func AgentRoutingPath

func AgentRoutingPath() string

AgentRoutingPath returns the path to the agent routing config.

func AgentRoutingSummary

func AgentRoutingSummary() string

AgentRoutingSummary returns a human-readable summary of routing config.

func ApplyOpenAICompatibleProvider

func ApplyOpenAICompatibleProvider(prefix, apiKey, model, baseURL string, overwrite bool)

ApplyOpenAICompatibleProvider sets env vars for an OpenAI-compatible provider.

func ApplyProviderConfigToEnv

func ApplyProviderConfigToEnv(config *ProviderConfig, overwrite bool, cat *catalog.ModelCatalog) string

ApplyProviderConfigToEnv applies the full provider config to env vars. Returns the detected provider or empty string.

func ApplyProviderEnv

func ApplyProviderEnv(provider string, config *ProviderConfig, activeModel string, overwrite bool, cat *catalog.ModelCatalog) map[string]string

ApplyProviderEnv computes the env vars for a specific provider and returns them as a map without modifying the process environment.

func ApplyProviderEnvToProcess

func ApplyProviderEnvToProcess(provider string, config *ProviderConfig, activeModel string, overwrite bool, cat *catalog.ModelCatalog)

ApplyProviderEnvToProcess applies the env vars for a specific provider directly to the process environment via os.Setenv.

func AsNonEmptyString

func AsNonEmptyString(v string) string

AsNonEmptyString returns trimmed string or empty.

func ClearActiveSelection

func ClearActiveSelection(cfg *ProviderConfig)

ClearActiveSelection clears active provider/model fields.

func ClearProviderRuntimeEnv

func ClearProviderRuntimeEnv()

ClearProviderRuntimeEnv clears all provider-related env vars.

func CommitCredential

func CommitCredential(ctx context.Context, inference CredentialInference, secret string) error

CommitCredential validates and probes a credential before persistence.

func CommitLocalCredential

func CommitLocalCredential(ctx context.Context, inference CredentialInference, value string) error

CommitLocalCredential validates and probes a no-key provider.

func DefaultCategories

func DefaultCategories() map[ModelCategory]CategoryConfig

DefaultCategories returns the built-in category-to-model mappings.

func DefaultProviderFromConfig

func DefaultProviderFromConfig(config *ProviderConfig) string

DefaultProviderFromConfig determines the default provider from config.

func DeleteProfile

func DeleteProfile(name string) error

DeleteProfile removes a profile by name.

func DeploymentConfigured

func DeploymentConfigured(deploymentID string, dep catalog.Deployment, dc DeploymentConfig) bool

DeploymentConfigured reports whether env supplies enough credentials for this deployment.

func DiscoveryCredentials

func DiscoveryCredentials(ctx context.Context) catalog.Credentials

DiscoveryCredentials loads API keys from the OS secret store (not process env or .env files), merged with non-secret routing from ~/.hawk/provider.json (e.g. MiMo Token Plan region/base URL).

func DiscoveryCredentialsFromState

func DiscoveryCredentialsFromState(apiKeys map[string]string, cfg *ProviderConfig) catalog.Credentials

DiscoveryCredentialsFromState combines injected credential values with non-secret provider routing state. It never reads process-global paths, environment variables, or the default credential store.

func DiscoveryEnvMap

func DiscoveryEnvMap(ctx context.Context) map[string]string

DiscoveryEnvMap returns merged credential env (keychain + provider.json routing) for status UI.

func FormatOllamaConnectError

func FormatOllamaConnectError(err error) error

FormatOllamaConnectError turns probe/network failures into actionable setup hints.

func GetProviderAPIKey

func GetProviderAPIKey(config *ProviderConfig, provider string) string

GetProviderAPIKey returns the configured API key for a provider. Credential env var names come from the provider registry, so new providers are covered by their registry entry alone.

func GetProviderActiveModel

func GetProviderActiveModel(config *ProviderConfig, provider string) string

GetProviderActiveModel gets the active model for a provider from config.

func GetProviderConfigDir

func GetProviderConfigDir() (string, error)

GetProviderConfigDir returns the config directory path. It returns an error when no configuration directory can be resolved (e.g. unset HOME in a container) so callers degrade gracefully instead of panicking.

func GetProviderConfigPath

func GetProviderConfigPath() (string, error)

GetProviderConfigPath returns the full path to provider.json. It returns an error when the configuration directory cannot be resolved.

func GetProviderModel

func GetProviderModel(config *ProviderConfig, provider string) string

GetProviderModel returns the configured model for a provider.

func HasAnyConfiguredDeployment

func HasAnyConfiguredDeployment(ctx context.Context) bool

HasAnyConfiguredDeployment reports whether catalog env + keychain satisfy any deployment.

func IsLocalProviderURL

func IsLocalProviderURL(baseURL string) bool

IsLocalProviderURL checks if a base URL points to localhost.

func IsOpenAICompatibleRuntimeEnabled

func IsOpenAICompatibleRuntimeEnabled() bool

IsOpenAICompatibleRuntimeEnabled checks if any provider API key is set.

func IsProviderConfigured

func IsProviderConfigured(config *ProviderConfig, provider string) bool

IsProviderConfigured checks if a provider has valid configuration.

func IsXiaomiMimoProvider

func IsXiaomiMimoProvider(providerID string) bool

IsXiaomiMimoProvider reports whether id is a MiMo setup gateway (payg or token plan).

func IsZAIProvider

func IsZAIProvider(providerID string) bool

IsZAIProvider reports whether id is a Z.AI setup gateway (payg or coding).

func ListProfiles

func ListProfiles() string

ListProfiles returns a human-readable list of profiles.

func LooksLikePlaceholderSecret

func LooksLikePlaceholderSecret(secret string) bool

LooksLikePlaceholderSecret detects obvious placeholder API keys.

func NormalizeOllamaOpenAIBaseURL

func NormalizeOllamaOpenAIBaseURL(baseURL string) string

NormalizeOllamaOpenAIBaseURL ensures the URL ends with /v1.

func ParseRoute

func ParseRoute(route string) (provider, model string)

ParseRoute splits a route string into provider and model. Format: "provider/model" or just "model".

func PrepareCredentialForSave

func PrepareCredentialForSave(inference CredentialInference, secret string) (string, error)

PrepareCredentialForSave validates and returns the normalized value to persist.

func ProbeCredential

func ProbeCredential(ctx context.Context, envKey, secret string) error

ProbeCredential verifies a key against the provider API when a probe is configured.

func ProbeCredentialWithProviderConfig

func ProbeCredentialWithProviderConfig(ctx context.Context, envKey, secret string, cfg *ProviderConfig) error

ProbeCredentialWithProviderConfig verifies a credential using only the supplied provider state for region/base routing. Host-facing callers should prefer this over ProbeCredential so an Engine never consults the process-default provider.json path while probing a scoped credential.

func ProbeLocalCredential

func ProbeLocalCredential(ctx context.Context, envKey, value string) error

ProbeLocalCredential verifies a local provider endpoint when configured.

func ProfilesPath

func ProfilesPath() string

ProfilesPath returns the path to the profiles file.

func ProviderConfigContainsSecrets

func ProviderConfigContainsSecrets(cfg ProviderConfig) bool

ProviderConfigContainsSecrets reports whether provider state contains credential material, including unrepresentable fields on unregistered deployments. It never returns or formats credential values.

func ProviderConfigSecrets

func ProviderConfigSecrets(cfg ProviderConfig) (map[string]string, error)

ProviderConfigSecrets maps every credential stored in provider state to its canonical secret-store environment variable. Placeholder values are omitted. Deployment credentials take precedence over older top-level fields. It returns an error naming fields that cannot be represented by the canonical secret store; callers must not sanitize provider state on error.

func ProviderIDForEnv

func ProviderIDForEnv(envKey string) string

ProviderIDForEnv maps an env var to registry provider id.

func ResetCategoryRegistry

func ResetCategoryRegistry()

ResetCategoryRegistry clears the global registry (for testing).

func ResolveXiaomiOpenAIBase

func ResolveXiaomiOpenAIBase(providerID string, cfg *ProviderConfig) (string, error)

ResolveXiaomiOpenAIBase resolves the OpenAI-compat base for a MiMo gateway id.

func ResolveZAIAnthropicBase

func ResolveZAIAnthropicBase(cfg *ProviderConfig) string

ResolveZAIAnthropicBase resolves the Anthropic-compat base for a Z.AI gateway config.

func ResolveZAIOpenAIBase

func ResolveZAIOpenAIBase(providerID string, cfg *ProviderConfig) (string, error)

ResolveZAIOpenAIBase resolves the OpenAI-compat base for a Z.AI gateway id.

func SaveAgentRouting

func SaveAgentRouting(cfg *AgentRoutingConfig) error

SaveAgentRouting persists the agent routing config.

func SaveProfiles

func SaveProfiles(profiles []ProviderProfile) error

SaveProfiles persists provider profiles.

func SaveProviderConfig

func SaveProviderConfig(config *ProviderConfig, path string) (err error)

SaveProviderConfig atomically persists non-secret provider state. Credential material belongs in the credential store; refusing it here makes plaintext provider.json writes impossible through the public config API.

func SetActiveProvider

func SetActiveProvider(cfg *ProviderConfig, provider string)

SetActiveProvider updates active_provider in provider config.

func SetEnvValue

func SetEnvValue(key, value string, overwrite bool)

SetEnvValue sets an env var if value is non-empty and overwrite is allowed.

func SetProviderModel

func SetProviderModel(cfg *ProviderConfig, provider, model string)

SetProviderModel sets active_model and the provider-scoped model field.

func ValidateAPIKey

func ValidateAPIKey(apiKey, providerName string) string

ValidateAPIKey validates an API key.

func ValidateCredentialBeforeSave

func ValidateCredentialBeforeSave(inference CredentialInference, secret string) error

ValidateCredentialBeforeSave checks format without a live API probe.

func ValidateCredentialSecret

func ValidateCredentialSecret(envKey, secret string) error

ValidateCredentialSecret validates env-specific secret shape.

func ValidateKeyFormat

func ValidateKeyFormat(secret string) error

ValidateKeyFormat checks a pasted secret before any provider is chosen.

func VertexGeminiBaseURL

func VertexGeminiBaseURL(projectID, region string) string

VertexGeminiBaseURL returns the Google Vertex AI publisher endpoint for Gemini.

func XiaomiTokenPlanRegionFromConfig

func XiaomiTokenPlanRegionFromConfig(cfg *ProviderConfig) xiaomi.Region

XiaomiTokenPlanRegionFromConfig reads persisted Token Plan cluster from provider.json.

Types

type APIKeyDef

type APIKeyDef struct {
	Env    string `json:"env"`
	Source string `json:"source"`
}

APIKeyDef maps an env var to a key source name.

type APIProvider

type APIProvider = string

APIProvider is the type for supported LLM providers.

const (
	ProviderAnthropic           APIProvider = "anthropic"
	ProviderOpenAI              APIProvider = "openai"
	ProviderAzure               APIProvider = "azure"
	ProviderCanopyWave          APIProvider = "canopywave"
	ProviderDeepSeek            APIProvider = "deepseek"
	ProviderZAICoding           APIProvider = "zai_coding"
	ProviderZAIPayg             APIProvider = "zai_payg"
	ProviderOpenRouter          APIProvider = "openrouter"
	ProviderConcentrate         APIProvider = "concentrate"
	ProviderOpenGateway         APIProvider = "opengateway"
	ProviderAgnes               APIProvider = "agnes"
	ProviderLongCat             APIProvider = "longcat"
	ProviderFireworks           APIProvider = "fireworks"
	ProviderGrok                APIProvider = "grok"
	ProviderGemini              APIProvider = "gemini"
	ProviderBedrock             APIProvider = "bedrock"
	ProviderVertex              APIProvider = "vertex"
	ProviderOllama              APIProvider = "ollama"
	ProviderOpenCodeGo          APIProvider = "opencodego"
	ProviderKimi                APIProvider = "kimi"
	ProviderXiaomiMimoPayg      APIProvider = "xiaomi_mimo_payg"
	ProviderXiaomiMimoTokenPlan APIProvider = "xiaomi_mimo_token_plan" // #nosec G101 -- provider id string, not a secret value
	ProviderMiniMaxTokenPlan    APIProvider = "minimax_token_plan"
	ProviderMiniMaxPayg         APIProvider = "minimax_payg"
	ProviderPoolside            APIProvider = "poolside"
	ProviderGroq                APIProvider = "groq"
	ProviderClinePass           APIProvider = "clinepass"
	ProviderStepFun             APIProvider = "stepfun"
)

type AgentRoutingConfig

type AgentRoutingConfig struct {
	// Routes maps agent type to model identifier (provider/model).
	// Special keys: "default" for fallback, "general-purpose" for main chat.
	Routes map[string]string `json:"routes"`
}

AgentRoutingConfig holds per-agent model routing rules.

func DefaultAgentRouting

func DefaultAgentRouting() *AgentRoutingConfig

DefaultAgentRouting returns the default routing config.

func LoadAgentRouting

func LoadAgentRouting() (*AgentRoutingConfig, error)

LoadAgentRouting reads the agent routing config.

func (*AgentRoutingConfig) ResolveModel

func (c *AgentRoutingConfig) ResolveModel(agentType, fallback string) string

ResolveModel returns the model for the given agent type. Falls back to "default" route, then to the provided fallback.

func (*AgentRoutingConfig) SetRoute

func (c *AgentRoutingConfig) SetRoute(agentType, model string)

SetRoute sets the model for an agent type.

type CategoryConfig

type CategoryConfig struct {
	Model       string  `json:"model"`
	Provider    string  `json:"provider,omitempty"`
	Temperature float64 `json:"temperature,omitempty"`
	MaxTokens   int     `json:"max_tokens,omitempty"`
	Description string  `json:"description,omitempty"`
}

CategoryConfig maps a category to a specific model configuration.

func ResolveCategory

func ResolveCategory(cat ModelCategory) CategoryConfig

ResolveCategory is a convenience function that resolves a category using the global registry.

type CategoryRegistry

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

CategoryRegistry holds the mapping from categories to model configs.

func GetCategoryRegistry

func GetCategoryRegistry() *CategoryRegistry

GetCategoryRegistry returns the global category registry. It loads overrides from Hawk user config if present.

func (*CategoryRegistry) AllCategories

func (r *CategoryRegistry) AllCategories() map[ModelCategory]CategoryConfig

AllCategories returns all registered categories.

func (*CategoryRegistry) Resolve

Resolve returns the CategoryConfig for the given category. Falls back to CategoryUnspecifiedHigh if the category is unknown.

func (*CategoryRegistry) ResolveWithDefaults

func (r *CategoryRegistry) ResolveWithDefaults(cat ModelCategory, defaultModel string) CategoryConfig

ResolveWithDefaults returns the config for a category, falling back to the provided defaults if the category-specific field is empty.

func (*CategoryRegistry) SetCategory

func (r *CategoryRegistry) SetCategory(cat ModelCategory, cfg CategoryConfig)

SetCategory overrides a category configuration at runtime.

type CredentialInference

type CredentialInference = credential.CredentialInference

func InferCredentialsFromAPIKey

func InferCredentialsFromAPIKey(ctx context.Context, secret string) []CredentialInference

InferCredentialsFromAPIKey is deprecated; use InferenceForProvider after gateway selection.

func InferenceForProvider

func InferenceForProvider(providerID string) (CredentialInference, error)

InferenceForProvider returns save metadata for a gateway selected in setup UI.

func InferenceFromOption

func InferenceFromOption(opt CredentialProviderOption) CredentialInference

InferenceFromOption converts a provider picker row to persistence metadata.

func LocalCredentialInference

func LocalCredentialInference(providerID string) (CredentialInference, error)

LocalCredentialInference returns setup metadata for no-key providers.

type CredentialProviderOption

type CredentialProviderOption = credential.CredentialProviderOption

func ListCredentialProviders

func ListCredentialProviders() []CredentialProviderOption

ListCredentialProviders returns all registry providers for setup UIs.

type CredentialResolveResult

type CredentialResolveResult = credential.CredentialResolveResult

func ResolveCredential

func ResolveCredential(ctx context.Context, secret string) CredentialResolveResult

ResolveCredential validates format and lists registered providers (gateway must be chosen first).

type DeploymentChoice

type DeploymentChoice struct {
	DeploymentID string `json:"deployment_id"`
	Weight       int    `json:"weight"`
}

type DeploymentConfig

type DeploymentConfig struct {
	APIKey          string            `json:"api_key,omitempty"`
	BaseURL         string            `json:"base_url,omitempty"`
	Endpoint        string            `json:"endpoint,omitempty"`
	APIVersion      string            `json:"api_version,omitempty"`
	ProjectID       string            `json:"project_id,omitempty"`
	Region          string            `json:"region,omitempty"`
	Token           string            `json:"token,omitempty"`
	AccessKeyID     string            `json:"access_key_id,omitempty"`
	SecretAccessKey string            `json:"secret_access_key,omitempty"`
	SessionToken    string            `json:"session_token,omitempty"`
	ModelMappings   map[string]string `json:"model_mappings,omitempty"`

	// OIDC keyless auth (opt-in). When RoleARN (Bedrock) or WIFAudience (Vertex)
	// is set — or GRAYCODE_ROUTER_OIDC=1 — and the process runs in GitHub Actions, the
	// deployment obtains short-lived credentials via OIDC instead of stored
	// secrets. Empty by default; the non-OIDC path is unchanged.
	RoleARN             string `json:"role_arn,omitempty"`
	WIFAudience         string `json:"wif_audience,omitempty"`
	ServiceAccountEmail string `json:"service_account_email,omitempty"`
}

func DeploymentConfigFromEnv

func DeploymentConfigFromEnv(dep catalog.Deployment, env map[string]string) DeploymentConfig

DeploymentConfigFromEnv builds deployment credentials from catalog env_fallbacks and env values.

func DeploymentConfigFromProviderState

func DeploymentConfigFromProviderState(cfg *ProviderConfig, provider string) DeploymentConfig

DeploymentConfigFromProviderState builds a deployment for provider from flat provider.json fields, resolving canonical credential and base-url env var names from the provider registry. Providers without flat fields return an empty deployment.

func SanitizeDeploymentConfigForDisk

func SanitizeDeploymentConfigForDisk(dc DeploymentConfig) DeploymentConfig

SanitizeDeploymentConfigForDisk removes secret fields before writing provider.json. Runtime clients resolve API keys from the process environment or credential store.

type ModelCategory

type ModelCategory string

ModelCategory identifies a semantic task category for model routing. Instead of selecting specific models, agents delegate by category (e.g., "deep" for reasoning-heavy tasks, "quick" for fast responses).

const (
	CategoryDeep              ModelCategory = "deep"
	CategoryQuick             ModelCategory = "quick"
	CategoryUltraBrain        ModelCategory = "ultrabrain"
	CategoryVisualEngineering ModelCategory = "visual-engineering"
	CategoryArtistry          ModelCategory = "artistry"
	CategoryWriting           ModelCategory = "writing"
	CategoryUnspecifiedLow    ModelCategory = "unspecified-low"
	CategoryUnspecifiedHigh   ModelCategory = "unspecified-high"
)

type OpenAICompatibleApiKeySource

type OpenAICompatibleApiKeySource = string

OpenAICompatibleApiKeySource identifies where the API key came from.

type OpenAICompatibleRuntimeMode

type OpenAICompatibleRuntimeMode = string

OpenAICompatibleRuntimeMode identifies the runtime mode.

type ProviderConfig

type ProviderConfig struct {
	ConfigVersion              int                         `json:"config_version,omitempty"`
	Version                    string                      `json:"_version,omitempty"`
	ActiveProvider             string                      `json:"active_provider,omitempty"`
	AnthropicAPIKey            string                      `json:"anthropic_api_key,omitempty"`
	GrokAPIKey                 string                      `json:"grok_api_key,omitempty"`
	XAIAPIKey                  string                      `json:"xai_api_key,omitempty"`
	OpenAIAPIKey               string                      `json:"openai_api_key,omitempty"`
	CanopyWaveAPIKey           string                      `json:"canopywave_api_key,omitempty"`
	DeepSeekAPIKey             string                      `json:"deepseek_api_key,omitempty"`
	ZAIAPIKey                  string                      `json:"zai_api_key,omitempty"`
	ZAICodingAPIKey            string                      `json:"zai_coding_api_key,omitempty"`
	OpenRouterAPIKey           string                      `json:"openrouter_api_key,omitempty"`
	GeminiAPIKey               string                      `json:"gemini_api_key,omitempty"`
	OllamaBaseURL              string                      `json:"ollama_base_url,omitempty"`
	OpenCodeGoAPIKey           string                      `json:"opencodego_api_key,omitempty"`
	MoonshotAPIKey             string                      `json:"moonshot_api_key,omitempty"`
	XiaomiMimoPaygAPIKey       string                      `json:"xiaomi_mimo_payg_api_key,omitempty"`
	XiaomiMimoTokenPlanAPIKey  string                      `json:"xiaomi_mimo_token_plan_api_key,omitempty"`
	MiniMaxTokenPlanAPIKey     string                      `json:"minimax_token_plan_api_key,omitempty"`
	MiniMaxPaygAPIKey          string                      `json:"minimax_payg_api_key,omitempty"`
	AnthropicBaseURL           string                      `json:"anthropic_base_url,omitempty"`
	CanopyWaveBaseURL          string                      `json:"canopywave_base_url,omitempty"`
	DeepSeekBaseURL            string                      `json:"deepseek_base_url,omitempty"`
	ZAIBaseURL                 string                      `json:"zai_base_url,omitempty"`
	ZAICodingBaseURL           string                      `json:"zai_coding_base_url,omitempty"`
	ZAIRegion                  string                      `json:"zai_region,omitempty"`
	ZAICodingRegion            string                      `json:"zai_coding_region,omitempty"`
	GrokBaseURL                string                      `json:"grok_base_url,omitempty"`
	XAIBaseURL                 string                      `json:"xai_base_url,omitempty"`
	OpenAIBaseURL              string                      `json:"openai_base_url,omitempty"`
	OpenRouterBaseURL          string                      `json:"openrouter_base_url,omitempty"`
	GeminiBaseURL              string                      `json:"gemini_base_url,omitempty"`
	OpenCodeGoBaseURL          string                      `json:"opencodego_base_url,omitempty"`
	MoonshotBaseURL            string                      `json:"moonshot_base_url,omitempty"`
	XiaomiBaseURL              string                      `json:"xiaomi_mimo_base_url,omitempty"`
	XiaomiMimoPaygBaseURL      string                      `json:"xiaomi_mimo_payg_base_url,omitempty"`
	XiaomiMimoTokenPlanBaseURL string                      `json:"xiaomi_mimo_token_plan_base_url,omitempty"`
	XiaomiMimoTokenPlanRegion  string                      `json:"xiaomi_mimo_token_plan_region,omitempty"`
	MiniMaxTokenPlanBaseURL    string                      `json:"minimax_token_plan_base_url,omitempty"`
	MiniMaxPaygBaseURL         string                      `json:"minimax_payg_base_url,omitempty"`
	PoolsideAPIKey             string                      `json:"poolside_api_key,omitempty"`
	PoolsideBaseURL            string                      `json:"poolside_base_url,omitempty"`
	PoolsideModel              string                      `json:"poolside_model,omitempty"`
	GroqAPIKey                 string                      `json:"groq_api_key,omitempty"`
	GroqBaseURL                string                      `json:"groq_base_url,omitempty"`
	GroqModel                  string                      `json:"groq_model,omitempty"`
	ClinePassAPIKey            string                      `json:"clinepass_api_key,omitempty"`
	ClinePassBaseURL           string                      `json:"clinepass_base_url,omitempty"`
	ClinePassModel             string                      `json:"clinepass_model,omitempty"`
	StepFunAPIKey              string                      `json:"stepfun_api_key,omitempty"`
	StepFunBaseURL             string                      `json:"stepfun_base_url,omitempty"`
	StepFunModel               string                      `json:"stepfun_model,omitempty"`
	MiniMaxModel               string                      `json:"minimax_model,omitempty"`
	AnthropicModel             string                      `json:"anthropic_model,omitempty"`
	OpenAIModel                string                      `json:"openai_model,omitempty"`
	CanopyWaveModel            string                      `json:"canopywave_model,omitempty"`
	ConcentrateAPIKey          string                      `json:"concentrate_api_key,omitempty"`
	ConcentrateBaseURL         string                      `json:"concentrate_base_url,omitempty"`
	ConcentrateModel           string                      `json:"concentrate_model,omitempty"`
	OpenGatewayAPIKey          string                      `json:"opengateway_api_key,omitempty"`
	OpenGatewayBaseURL         string                      `json:"opengateway_base_url,omitempty"`
	OpenGatewayModel           string                      `json:"opengateway_model,omitempty"`
	AgnesAPIKey                string                      `json:"agnes_api_key,omitempty"`
	AgnesBaseURL               string                      `json:"agnes_base_url,omitempty"`
	AgnesModel                 string                      `json:"agnes_model,omitempty"`
	FireworksAPIKey            string                      `json:"fireworks_api_key,omitempty"`
	FireworksBaseURL           string                      `json:"fireworks_base_url,omitempty"`
	FireworksModel             string                      `json:"fireworks_model,omitempty"`
	DeepSeekModel              string                      `json:"deepseek_model,omitempty"`
	ZAIModel                   string                      `json:"zai_model,omitempty"`
	GrokModel                  string                      `json:"grok_model,omitempty"`
	XAIModel                   string                      `json:"xai_model,omitempty"`
	OpenRouterModel            string                      `json:"openrouter_model,omitempty"`
	GeminiModel                string                      `json:"gemini_model,omitempty"`
	OllamaModel                string                      `json:"ollama_model,omitempty"`
	OpenCodeGoModel            string                      `json:"opencodego_model,omitempty"`
	MoonshotModel              string                      `json:"moonshot_model,omitempty"`
	XiaomiModel                string                      `json:"xiaomi_mimo_model,omitempty"`
	ActiveModel                string                      `json:"active_model,omitempty"`
	ExplorationModel           string                      `json:"exploration_model,omitempty"`
	AnthropicVersion           string                      `json:"anthropic_version,omitempty"`
	Deployments                map[string]DeploymentConfig `json:"deployments,omitempty"`
	Routing                    *RoutingPolicy              `json:"routing,omitempty"`
}

ProviderConfig mirrors the Hawk provider.json file.

func LoadProviderConfig

func LoadProviderConfig(path string) *ProviderConfig

LoadProviderConfig loads provider config from disk. Returns nil if file doesn't exist or the config dir cannot be resolved. Returns nil for corrupt JSON or permission issues (callers wanting detail should use LoadProviderConfigWithError).

func LoadProviderConfigWithError

func LoadProviderConfigWithError(path string) (*ProviderConfig, error)

LoadProviderConfigWithError loads provider config from disk with detailed error reporting. Returns (nil, nil) if file doesn't exist. Returns (nil, error) for corrupt JSON, missing config dir, or permission issues.

func SanitizeProviderConfigForDisk

func SanitizeProviderConfigForDisk(cfg ProviderConfig) ProviderConfig

SanitizeProviderConfigForDisk removes every credential field while preserving provider selection, routing, endpoints, and model metadata.

func SyncProviderConfigFromCatalog

func SyncProviderConfigFromCatalog(compiled *catalog.CompiledCatalog, env map[string]string) *ProviderConfig

SyncProviderConfigFromCatalog merges catalog + env into provider.json deployments and routing.

type ProviderProfile

type ProviderProfile struct {
	Name        string    `json:"name"`
	Provider    string    `json:"provider"`
	Model       string    `json:"model"`
	BaseURL     string    `json:"base_url,omitempty"`
	APIKeyEnv   string    `json:"api_key_env,omitempty"` // env var to read key from
	Temperature float64   `json:"temperature,omitempty"`
	MaxTokens   int       `json:"max_tokens,omitempty"`
	Description string    `json:"description,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
}

ProviderProfile is a saved provider configuration.

func FindProfile

func FindProfile(name string) (*ProviderProfile, error)

FindProfile returns a profile by name (case-insensitive).

func LoadProfiles

func LoadProfiles() ([]ProviderProfile, error)

LoadProfiles reads saved provider profiles.

func RecommendedProfile

func RecommendedProfile(goal string) ProviderProfile

RecommendedProfile returns a profile based on the user's goal.

type ProviderTransport

type ProviderTransport string

ProviderTransport is the transport type for provider requests.

const TransportChatCompletions ProviderTransport = "chat_completions"

type ReasoningEffort

type ReasoningEffort string

ReasoningEffort levels.

const (
	ReasoningLow    ReasoningEffort = "low"
	ReasoningMedium ReasoningEffort = "medium"
	ReasoningHigh   ReasoningEffort = "high"
)

type ResolvedOpenAICompatibleRuntime

type ResolvedOpenAICompatibleRuntime struct {
	Mode         string                  `json:"mode"`
	Request      ResolvedProviderRequest `json:"request"`
	APIKey       string                  `json:"-"`
	APIKeySource string                  `json:"api_key_source"`
}

ResolvedOpenAICompatibleRuntime holds the resolved runtime config.

func ResolveOpenAICompatibleRuntime

func ResolveOpenAICompatibleRuntime(model, baseURL, fallbackModel string) ResolvedOpenAICompatibleRuntime

ResolveOpenAICompatibleRuntime resolves the full OpenAI-compatible runtime config.

type ResolvedProviderRequest

type ResolvedProviderRequest struct {
	Transport      ProviderTransport `json:"transport"`
	RequestedModel string            `json:"requested_model"`
	ResolvedModel  string            `json:"resolved_model"`
	BaseURL        string            `json:"base_url"`
	Reasoning      *struct {
		Effort ReasoningEffort `json:"effort"`
	} `json:"reasoning,omitempty"`
}

ResolvedProviderRequest holds the resolved provider request details.

func ResolveProviderRequest

func ResolveProviderRequest(model, baseURL, fallbackModel string) ResolvedProviderRequest

ResolveProviderRequest resolves model/baseUrl/transport from options and env.

type RoutingPolicy

type RoutingPolicy struct {
	Default   []RoutingStage            `json:"default,omitempty"`
	Providers map[string][]RoutingStage `json:"providers,omitempty"`
	Models    map[string][]RoutingStage `json:"models,omitempty"`
}

func BuildRoutingPolicyFromDeployments

func BuildRoutingPolicyFromDeployments(deployments map[string]DeploymentConfig) *RoutingPolicy

BuildRoutingPolicyFromDeployments builds deployment routing from configured deployments. Hawk should not author routing rules — consume this JSON from graycode-router only.

type RoutingStage

type RoutingStage struct {
	Deployments []DeploymentChoice `json:"deployments"`
	Retries     int                `json:"retries,omitempty"`
}

type RuntimeProviderProfile

type RuntimeProviderProfile struct {
	Mode           string      `json:"mode"`
	DefaultBaseURL string      `json:"default_base_url"`
	DefaultModel   string      `json:"default_model"`
	DetectionEnv   []string    `json:"detection_env"`
	ModelEnv       []string    `json:"model_env"`
	BaseURLEnv     []string    `json:"base_url_env"`
	APIKeys        []APIKeyDef `json:"api_keys"`
}

RuntimeProviderProfile defines how a provider is detected and configured at runtime.

func RuntimeProfileByKey

func RuntimeProfileByKey(key string) (RuntimeProviderProfile, bool)

RuntimeProfileByKey returns the provider runtime profile registered for key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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