mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: load AI providers from the database at startup (#25672)
Replace the env-based `BuildProviders` with a DB-backed loader. The database is now the single source of truth for runtime provider configuration; env config arrives via `SeedAIProvidersFromEnv` (run at boot) and `BuildProviders` reads it back as `aibridge.Provider` instances. `cli/server.go` and `enterprise/cli/server.go` both call the same path, so aibridged and aibridgeproxyd see the same provider set. Per-provider `DumpDir` is replaced by a top-level `CODER_AI_GATEWAY_DUMP_DIR` base; each provider's effective dump path is `<base>/<provider name>`.
This commit is contained in:
+15
-2
@@ -1863,6 +1863,16 @@ func (c *DeploymentValues) Options() serpent.OptionSet {
|
||||
Group: &deploymentGroupAIGateway,
|
||||
YAML: "structured_logging",
|
||||
}
|
||||
aiGatewayAPIDumpDir := serpent.Option{
|
||||
Name: "AI Gateway API Dump Directory",
|
||||
Description: "Base directory for dumping AI Bridge request/response pairs to disk for debugging. When set, each provider writes under a subdirectory named after the provider. Sensitive headers are redacted. Leave empty to disable.",
|
||||
Flag: "ai-gateway-dump-dir",
|
||||
Env: "CODER_AI_GATEWAY_DUMP_DIR",
|
||||
Value: &c.AI.BridgeConfig.APIDumpDir,
|
||||
Default: "",
|
||||
Group: &deploymentGroupAIGateway,
|
||||
YAML: "api_dump_dir",
|
||||
}
|
||||
aiGatewaySendActorHeaders := serpent.Option{
|
||||
Name: "AI Gateway Send Actor Headers",
|
||||
Description: "Once enabled, extra headers will be added to upstream requests to identify the user (actor) making requests to AI Gateway. " +
|
||||
@@ -4275,6 +4285,7 @@ Write out the current server config as YAML to stdout.`,
|
||||
UseInstead: serpent.OptionSet{aiGatewaySendActorHeaders},
|
||||
},
|
||||
aiGatewaySendActorHeaders,
|
||||
aiGatewayAPIDumpDir,
|
||||
{
|
||||
Name: "AI Bridge Allow BYOK",
|
||||
Description: "Deprecated: use --ai-gateway-allow-byok or CODER_AI_GATEWAY_ALLOW_BYOK instead. Allow users to provide their own LLM API keys or subscriptions. When disabled, only centralized key authentication is permitted.",
|
||||
@@ -4632,6 +4643,10 @@ type AIBridgeConfig struct {
|
||||
CircuitBreakerInterval serpent.Duration `json:"circuit_breaker_interval" typescript:",notnull"`
|
||||
CircuitBreakerTimeout serpent.Duration `json:"circuit_breaker_timeout" typescript:",notnull"`
|
||||
CircuitBreakerMaxRequests serpent.Int64 `json:"circuit_breaker_max_requests" typescript:",notnull"`
|
||||
// APIDumpDir is the base directory under which each provider's
|
||||
// request/response dumps are written, in a subdirectory named after
|
||||
// the provider. Empty disables dumping.
|
||||
APIDumpDir serpent.String `json:"api_dump_dir" typescript:",notnull"`
|
||||
}
|
||||
|
||||
type AIBridgeOpenAIConfig struct {
|
||||
@@ -4669,8 +4684,6 @@ type AIProviderConfig struct {
|
||||
Keys []string `json:"-"`
|
||||
// BaseURL is the base URL of the upstream provider API.
|
||||
BaseURL string `json:"base_url"`
|
||||
// DumpDir is the directory path for dumping API requests and responses.
|
||||
DumpDir string `json:"dump_dir,omitempty"`
|
||||
|
||||
// Bedrock fields (only applicable when Type == "anthropic").
|
||||
BedrockBaseURL string `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user