fix: stop Agents dead-ending on unsupported providers (#26841)

Configuring only a GitHub Copilot provider left the Agents page stuck on
"set up a provider then add a model", even with a provider and models
configured. The catalog dropped any provider type that NormalizeProvider
did not recognize, so a Copilot-only deployment looked identical to an
empty one and never unlocked the page.

The Agents harness cannot use Copilot: it needs a per-request token only
an official Copilot client can mint, and the harness is not one. Instead
of dropping such providers, the catalog now reports them as unsupported
so the UI can explain the dead end and point elsewhere, rather than ask
for setup that already happened. The providers stay usable through the
AI Gateway proxy.

Support is derived from the provider type, not stored, so there is no
migration. codersdk.IsAgentsUnsupportedProviderType is the single source
of truth, consulted by the chatd catalog and, through the generated
AgentsUnsupportedProviderTypes list, the frontend.

The diff also carries unrelated modernization of nearby db2sdk and
chatprovider helpers (slices.SortFunc, strings.Cut, range-over-int).

Closes CODAGT-627
Refs CODAGT-256
Refs CODAGT-682
This commit is contained in:
Mathias Fredriksson
2026-06-30 18:49:50 +03:00
committed by GitHub
parent a79fcd34af
commit 2fd5ae4323
30 changed files with 589 additions and 37 deletions
+52 -7
View File
@@ -5,7 +5,7 @@ import (
"mime"
"net/http"
neturl "net/url"
"sort"
"slices"
"strings"
"charm.land/fantasy"
@@ -46,17 +46,62 @@ var providerDisplayNameByName = map[string]string{
fantasyopenaicompat.Name: "OpenAI Compatible",
fantasyopenrouter.Name: "OpenRouter",
fantasyvercel.Name: "Vercel AI Gateway",
// Copilot is unsupported but still needs a display name for the
// unsupported list and AI Settings.
string(codersdk.AIProviderTypeCopilot): "GitHub Copilot",
}
// ProviderDisplayName returns a default display name for a provider.
func ProviderDisplayName(provider string) string {
normalized := NormalizeProvider(provider)
if normalized == "" {
// Fall back for providers the harness cannot normalize, like copilot.
normalized = strings.ToLower(strings.TrimSpace(provider))
}
if displayName, ok := providerDisplayNameByName[normalized]; ok {
return displayName
}
return normalized
}
// AgentsSupportsProvider reports whether the Agents harness can use the
// provider type.
func AgentsSupportsProvider(provider string) bool {
providerType := codersdk.AIProviderType(strings.ToLower(strings.TrimSpace(provider)))
if codersdk.IsAgentsUnsupportedProviderType(providerType) {
return false
}
return NormalizeProvider(provider) != ""
}
// UnsupportedProviders returns the configured providers the Agents harness
// cannot use, deduplicated by provider type.
func UnsupportedProviders(configured []ConfiguredProvider) []codersdk.ChatUnsupportedProvider {
seen := make(map[string]struct{}, len(configured))
unsupported := make([]codersdk.ChatUnsupportedProvider, 0)
for _, provider := range configured {
if AgentsSupportsProvider(provider.Provider) {
continue
}
key := strings.ToLower(strings.TrimSpace(provider.Provider))
if key == "" {
continue
}
if _, ok := seen[key]; ok {
continue
}
seen[key] = struct{}{}
unsupported = append(unsupported, codersdk.ChatUnsupportedProvider{
Provider: key,
DisplayName: ProviderDisplayName(provider.Provider),
})
}
slices.SortFunc(unsupported, func(a, b codersdk.ChatUnsupportedProvider) int {
return strings.Compare(a.Provider, b.Provider)
})
return unsupported
}
// ProviderAllowsAmbientCredentials reports whether provider can use
// ambient credentials from the Coder server instead of an explicit
// API key.
@@ -615,8 +660,8 @@ func newChatModel(provider, modelID, displayName string) codersdk.ChatModel {
}
func sortChatModels(models []codersdk.ChatModel) {
sort.Slice(models, func(i, j int) bool {
return models[i].Model < models[j].Model
slices.SortFunc(models, func(a, b codersdk.ChatModel) int {
return strings.Compare(a.Model, b.Model)
})
}
@@ -734,13 +779,13 @@ func parseCanonicalModelRef(modelRef string) (provider string, model string, ok
}
for _, separator := range []string{":", "/"} {
parts := strings.SplitN(modelRef, separator, 2)
if len(parts) != 2 {
before, after, found := strings.Cut(modelRef, separator)
if !found {
continue
}
provider := NormalizeProvider(parts[0])
modelID := strings.TrimSpace(parts[1])
provider := NormalizeProvider(before)
modelID := strings.TrimSpace(after)
if provider != "" && modelID != "" {
return provider, modelID, true
}
@@ -265,7 +265,6 @@ func TestResolveUserProviderKeys(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -416,7 +415,6 @@ func TestReasoningEffortFromChat(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -509,7 +507,6 @@ func TestResolveUserProviderKeys_UnavailableReason(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -658,7 +655,6 @@ func TestListConfiguredModels_PolicyAwareAvailability(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -742,7 +738,6 @@ func TestListConfiguredProviderAvailability_PolicyAwareFiltering(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -890,7 +885,6 @@ func TestPruneDisabledProviderKeys(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -1743,3 +1737,40 @@ func TestResolveModelWithProviderHint(t *testing.T) {
})
}
}
func TestUnsupportedProviders(t *testing.T) {
t.Parallel()
t.Run("copilot only", func(t *testing.T) {
t.Parallel()
got := chatprovider.UnsupportedProviders([]chatprovider.ConfiguredProvider{
{Provider: string(codersdk.AIProviderTypeCopilot)},
})
require.Equal(t, []codersdk.ChatUnsupportedProvider{
{
Provider: "copilot",
DisplayName: "GitHub Copilot",
},
}, got)
})
t.Run("supported provider omitted", func(t *testing.T) {
t.Parallel()
got := chatprovider.UnsupportedProviders([]chatprovider.ConfiguredProvider{
{Provider: fantasyanthropic.Name},
{Provider: fantasyopenai.Name},
})
require.Empty(t, got)
})
t.Run("dedup by type and skip supported", func(t *testing.T) {
t.Parallel()
got := chatprovider.UnsupportedProviders([]chatprovider.ConfiguredProvider{
{Provider: fantasyanthropic.Name},
{Provider: string(codersdk.AIProviderTypeCopilot)},
{Provider: "Copilot"},
})
require.Len(t, got, 1)
require.Equal(t, "copilot", got[0].Provider)
})
}