mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00: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:
@@ -292,6 +292,11 @@ func providersFromEnv(ctx context.Context, cfg codersdk.AIBridgeConfig, logger s
|
||||
Type: database.AiProviderTypeAnthropic,
|
||||
}
|
||||
if hasLegacyBedrock {
|
||||
if hasAnthropicKey {
|
||||
logger.Warn(ctx, "ignoring legacy Anthropic API key because Bedrock credentials are configured; Bedrock authenticates via access keys or credential chain",
|
||||
slog.F("provider", aibridge.ProviderAnthropic),
|
||||
)
|
||||
}
|
||||
// Bedrock-only deployments use CODER_AIBRIDGE_BEDROCK_BASE_URL
|
||||
// for custom VPC, FIPS, or proxy endpoints.
|
||||
dp.BaseURL = cfg.LegacyBedrock.BaseURL.String()
|
||||
|
||||
Generated
+4
-4
@@ -14450,6 +14450,10 @@ const docTemplate = `{
|
||||
}
|
||||
]
|
||||
},
|
||||
"api_dump_dir": {
|
||||
"description": "APIDumpDir is the base directory under which each provider's\nrequest/response dumps are written, in a subdirectory named after\nthe provider. Empty disables dumping.",
|
||||
"type": "string"
|
||||
},
|
||||
"bedrock": {
|
||||
"description": "Deprecated: Use Providers with indexed CODER_AI_GATEWAY_PROVIDER_\u003cN\u003e_* env vars instead.",
|
||||
"allOf": [
|
||||
@@ -15062,10 +15066,6 @@ const docTemplate = `{
|
||||
"bedrock_small_fast_model": {
|
||||
"type": "string"
|
||||
},
|
||||
"dump_dir": {
|
||||
"description": "DumpDir is the directory path for dumping API requests and responses.",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "Name is the unique instance identifier used for routing.\nDefaults to Type if not provided.",
|
||||
"type": "string"
|
||||
|
||||
Generated
+4
-4
@@ -12854,6 +12854,10 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"api_dump_dir": {
|
||||
"description": "APIDumpDir is the base directory under which each provider's\nrequest/response dumps are written, in a subdirectory named after\nthe provider. Empty disables dumping.",
|
||||
"type": "string"
|
||||
},
|
||||
"bedrock": {
|
||||
"description": "Deprecated: Use Providers with indexed CODER_AI_GATEWAY_PROVIDER_\u003cN\u003e_* env vars instead.",
|
||||
"allOf": [
|
||||
@@ -13466,10 +13470,6 @@
|
||||
"bedrock_small_fast_model": {
|
||||
"type": "string"
|
||||
},
|
||||
"dump_dir": {
|
||||
"description": "DumpDir is the directory path for dumping API requests and responses.",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "Name is the unique instance identifier used for routing.\nDefaults to Type if not provided.",
|
||||
"type": "string"
|
||||
|
||||
@@ -627,6 +627,7 @@ var (
|
||||
rbac.ResourceAibridgeInterception.Type: {policy.ActionCreate, policy.ActionRead, policy.ActionUpdate, policy.ActionDelete},
|
||||
rbac.ResourceAiModelPrice.Type: {policy.ActionUpdate}, // Required for the startup price seeder.
|
||||
rbac.ResourceAiSeat.Type: {policy.ActionCreate}, // Required for UpsertAISeatState.
|
||||
rbac.ResourceAIProvider.Type: {policy.ActionRead}, // Required to load the provider snapshot (and per-provider keys) at startup.
|
||||
}),
|
||||
User: []rbac.Permission{},
|
||||
ByOrgID: map[string]rbac.OrgPermissions{},
|
||||
|
||||
Reference in New Issue
Block a user