feat: add 'copilot' to ai_provider_type (#25616)

This commit is contained in:
Danny Kopping
2026-05-22 16:10:37 +02:00
committed by GitHub
parent de6d62815e
commit 0d9718e217
12 changed files with 61 additions and 21 deletions
+22 -6
View File
@@ -327,9 +327,9 @@ func providersFromEnv(ctx context.Context, cfg codersdk.AIBridgeConfig, logger s
dp.Type = database.AiProviderTypeOpenai
case aibridge.ProviderAnthropic:
dp.Type = database.AiProviderTypeAnthropic
case aibridge.ProviderCopilot:
dp.Type = database.AiProviderTypeCopilot
default:
// Skip other types (e.g. copilot) until they are added
// to the database enum.
logger.Warn(ctx, "skipping indexed AI provider with unsupported type",
slog.F("name", name),
slog.F("type", p.Type),
@@ -367,11 +367,27 @@ func providersFromEnv(ctx context.Context, cfg codersdk.AIBridgeConfig, logger s
dp.BaseURL = p.BedrockBaseURL
}
}
// Non-Bedrock providers carry their bearer keys in
// Non-Bedrock, non-Copilot providers carry their bearer keys in
// ai_provider_keys. Bedrock providers authenticate via the
// settings blob and have no keys; cli/server.go rejects
// configs that set both before we get here.
if !isBedrock {
// settings blob; Copilot providers use request-time GitHub
// OAuth tokens. cli/server.go rejects configs that set Bedrock
// alongside bearer keys before we get here.
switch {
case isBedrock:
if len(p.Keys) > 0 {
logger.Warn(ctx, "ignoring bearer keys configured on Bedrock AI provider; Bedrock authenticates via access keys or credential chain",
slog.F("name", name),
slog.F("ignored_key_count", len(p.Keys)),
)
}
case dp.Type == database.AiProviderTypeCopilot:
if len(p.Keys) > 0 {
logger.Warn(ctx, "ignoring bearer keys configured on Copilot AI provider; Copilot authenticates via request-time GitHub OAuth tokens",
slog.F("name", name),
slog.F("ignored_key_count", len(p.Keys)),
)
}
default:
dp.Keys = append(dp.Keys, p.Keys...)
}
+6 -3
View File
@@ -371,12 +371,15 @@ func TestSeedAIProvidersFromEnv(t *testing.T) {
db, _ := dbtestutil.NewDB(t)
ctx := testutil.Context(t, testutil.WaitShort)
// vercel is a valid ai_provider_type DB value but the aibridge
// runtime has no constructor for it, so the seed switch falls
// into the default branch and skips the row.
cfg := codersdk.AIBridgeConfig{
Providers: []codersdk.AIProviderConfig{
{
Type: "copilot",
Name: "gh-copilot",
BaseURL: "https://api.githubcopilot.com/",
Type: "vercel",
Name: "vercel-instance",
BaseURL: "https://example.com",
},
{
Type: "openai",
+4 -2
View File
@@ -15117,7 +15117,8 @@ const docTemplate = `{
"openai-compat",
"openrouter",
"vercel",
"bedrock"
"bedrock",
"copilot"
],
"x-enum-varnames": [
"AIProviderTypeOpenAI",
@@ -15127,7 +15128,8 @@ const docTemplate = `{
"AIProviderTypeOpenAICompat",
"AIProviderTypeOpenrouter",
"AIProviderTypeVercel",
"AIProviderTypeBedrock"
"AIProviderTypeBedrock",
"AIProviderTypeCopilot"
]
},
"codersdk.APIAllowListTarget": {
+4 -2
View File
@@ -13521,7 +13521,8 @@
"openai-compat",
"openrouter",
"vercel",
"bedrock"
"bedrock",
"copilot"
],
"x-enum-varnames": [
"AIProviderTypeOpenAI",
@@ -13531,7 +13532,8 @@
"AIProviderTypeOpenAICompat",
"AIProviderTypeOpenrouter",
"AIProviderTypeVercel",
"AIProviderTypeBedrock"
"AIProviderTypeBedrock",
"AIProviderTypeCopilot"
]
},
"codersdk.APIAllowListTarget": {
+2 -1
View File
@@ -18,7 +18,8 @@ CREATE TYPE ai_provider_type AS ENUM (
'google',
'openai-compat',
'openrouter',
'vercel'
'vercel',
'copilot'
);
CREATE TYPE ai_seat_usage_reason AS ENUM (
@@ -0,0 +1,2 @@
-- No-op: Postgres does not allow removing enum values safely.
-- Matches the precedent in 000499_ai_provider_type_chatd_values.down.sql.
@@ -0,0 +1,5 @@
-- Add 'copilot' to ai_provider_type. The aibridge runtime already supports
-- Copilot via aibridge.NewCopilotProvider; the enum just needs the
-- discriminator so DB-driven providers can carry it. Mirrors the precedent
-- in 000499_ai_provider_type_chatd_values.up.sql.
ALTER TYPE ai_provider_type ADD VALUE IF NOT EXISTS 'copilot';
+4 -1
View File
@@ -27,6 +27,7 @@ const (
AiProviderTypeOpenaiCompat AIProviderType = "openai-compat"
AiProviderTypeOpenrouter AIProviderType = "openrouter"
AiProviderTypeVercel AIProviderType = "vercel"
AiProviderTypeCopilot AIProviderType = "copilot"
)
func (e *AIProviderType) Scan(src interface{}) error {
@@ -73,7 +74,8 @@ func (e AIProviderType) Valid() bool {
AiProviderTypeGoogle,
AiProviderTypeOpenaiCompat,
AiProviderTypeOpenrouter,
AiProviderTypeVercel:
AiProviderTypeVercel,
AiProviderTypeCopilot:
return true
}
return false
@@ -89,6 +91,7 @@ func AllAIProviderTypeValues() []AIProviderType {
AiProviderTypeOpenaiCompat,
AiProviderTypeOpenrouter,
AiProviderTypeVercel,
AiProviderTypeCopilot,
}
}