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
+4 -6
View File
@@ -6,22 +6,20 @@ import {
listProviderModels,
ModelListError,
} from "@/lib/provider-models"
import { PROVIDER_NAMES, PROVIDERS, type ProviderName } from "@/lib/providers"
import {
allowPrivateUrls,
isPrivateUrl,
RedirectRefusedError,
redirectGuardedFetch,
} from "@/lib/ssrf-protection"
import type { ProviderName } from "@/lib/types/model-config"
export const runtime = "nodejs"
// Public lists need no key
const NO_KEY_NEEDED = new Set<ProviderName>([
"ollama",
"openrouter",
"aihubmix",
])
const NO_KEY_NEEDED = new Set<ProviderName>(
PROVIDER_NAMES.filter((p) => PROVIDERS[p].listNeedsNoKey),
)
/**
* The models a provider offers, for the "Fetch models" button in model