refactor(providers): one record per provider, ten name-keyed tables derived from it

Step 2 of the provider refactor plan. lib/providers.ts holds one record per
provider (SDK kind, credential kind, env prefix, default URL, picker group,
notes and base URL hints in four languages, and the short model list of the
six providers that cannot list models). ProviderName is now the record's
key set and lib/types/model-config.ts re-exports the record as PROVIDER_INFO,
so the twelve importers are unchanged.

Derived from the record, under their old names and in their old files:
FIXED_CRED_PROVIDERS, PROVIDER_LOGO_MAP and chatRequestUrl's own-path list
(model-config.ts), SINGLE_SYSTEM_PROVIDERS, PROVIDER_ENV_VARS and
SDK_KNOWS_ENDPOINT (ai-providers.ts), PROVIDER_GROUPS and OPTIONS_OPEN
(provider-setup.ts), NO_KEY_NEEDED (provider-models route).
tests/unit/providers.test.ts freezes the old tables' values and checks the
derived ones against them. The record is written in the picker's order, so
the provider lists in two 'No AI provider configured' messages change order;
those two snapshot rows are the only snapshot change.
This commit is contained in:
dayuan.jiang
2026-10-12 21:17:51 +09:00
parent 31f4641178
commit b0e95a5ef4
7 changed files with 1113 additions and 323 deletions
+16 -41
View File
@@ -1,50 +1,29 @@
// What the model settings show about providers: the groups of the provider
// picker, and how far a provider's setup has come
import {
PROVIDER_NAMES,
PROVIDERS,
type ProviderGroup as ProviderGroupId,
} from "@/lib/providers"
import {
PROVIDER_INFO,
type ProviderConfig,
type ProviderName,
} from "@/lib/types/model-config"
export type ProviderGroupId = "vendors" | "aggregators" | "cloud" | "selfHosted"
export type { ProviderGroupId }
/** The provider picker's groups, each provider in exactly one */
/** The provider picker's groups, each provider in exactly one, in record order */
export const PROVIDER_GROUPS: {
id: ProviderGroupId
providers: ProviderName[]
}[] = [
{
id: "vendors",
providers: [
"openai",
"anthropic",
"google",
"deepseek",
"qwen",
"doubao",
"glm",
"kimi",
"minimax",
"mimo",
],
},
{
id: "aggregators",
providers: [
"openrouter",
"aihubmix",
"siliconflow",
"modelscope",
"novita",
"atlascloud",
"qiniu",
"gateway",
],
},
{ id: "cloud", providers: ["bedrock", "vertexai", "azure", "edgeone"] },
{ id: "selfHosted", providers: ["ollama", "sglang"] },
]
}[] = (["vendors", "aggregators", "cloud", "selfHosted"] as const).map(
(id) => ({
id,
providers: PROVIDER_NAMES.filter((p) => PROVIDERS[p].group === id),
}),
)
/** Shown when the user has no provider yet */
export const POPULAR_PROVIDERS: ProviderName[] = [
@@ -71,13 +50,9 @@ export const PROVIDER_NOTE_KEYS: Partial<Record<ProviderName, string>> = {
* an example; Ollama's is its cloud, SGLang's a local server) or comes with
* a hint (MiniMax, MiMo): their folded options start open
*/
export const OPTIONS_OPEN: ProviderName[] = [
"azure",
"ollama",
"sglang",
"minimax",
"mimo",
]
export const OPTIONS_OPEN: ProviderName[] = PROVIDER_NAMES.filter(
(p) => PROVIDERS[p].optionsOpen,
)
/** The groups with only the providers whose name matches the search */
export function filterProviderGroups(query: string) {