refactor(providers): the UI, the connection test and the routes read the record's fields

Step 5 of the provider refactor plan. Provider names gave way to the
record's credential and sdk fields in: hasCredentials (one rule per
credential kind), the connection test (an Object.hasOwn check first, then a
credential switch; EdgeOne's site endpoint and cookie forwarding follow
credential none), the chat route (the on-site function and the single-system
rule for the OpenAI SDK), the credentials form (which fields to show, the
optional-key label, the base URL hint from the record), the picker (the note
from the record), the logo (icon and logo fields), the settings dialog (test
blocker, error hints, EdgeOne origin), the admin panel (fixedCredentials),
chatRequestUrl (sdk), the model list (sdk aihubmix) and the zod schema
(Object.hasOwn instead of 'in'). The eight provider-specific dictionary
entries moved into the record as four-language objects; needAzure became a
generic needUrl.

Two intended behavior changes: the connection test answers 400 'Invalid
provider' for an unknown name whether or not a key is sent (before: 400
'API key is required' without a key, 200 with an error text with one); and
Azure has no placeholder default URL any more, so a new Azure entry starts
with an empty URL and the generic 'needs a URL' rule applies. The e2e
Azure test seeds no URL and expects the new wording. Out-of-layer
provider-name checks: 44 before, 6 after (the admin panel's fixed-variable
branches for Bedrock, Vertex AI and Ollama, kept on purpose). Behavior
snapshot unchanged.
This commit is contained in:
dayuan.jiang
2026-10-12 21:17:51 +09:00
parent e0a196dded
commit f811242568
22 changed files with 303 additions and 266 deletions
+7 -12
View File
@@ -33,14 +33,9 @@ import {
import { Switch } from "@/components/ui/switch"
import { useDictionary } from "@/hooks/use-dictionary"
import { formatMessage } from "@/lib/i18n/utils"
import { PROVIDERS, type ProviderName } from "@/lib/providers"
import { STORAGE_KEYS } from "@/lib/storage"
import {
FIXED_CRED_PROVIDERS,
generateId,
PROVIDER_INFO,
type ProviderName,
SUGGESTED_MODELS,
} from "@/lib/types/model-config"
import { generateId, SUGGESTED_MODELS } from "@/lib/types/model-config"
import { cn } from "@/lib/utils"
import {
type AdminProvider,
@@ -72,7 +67,7 @@ function ProviderDetail({
Record<string, { ok: boolean; message: string }>
>({})
const info = PROVIDER_INFO[provider.provider]
const info = PROVIDERS[provider.provider]
const suggestions = (SUGGESTED_MODELS[provider.provider] || []).filter(
(m) => !provider.models.includes(m),
)
@@ -500,7 +495,7 @@ export function ModelsSection({
>
<ProviderLogo provider={p.provider} />
<span className="min-w-0 flex-1 truncate">
{p.name || PROVIDER_INFO[p.provider].label}
{p.name || PROVIDERS[p.provider].label}
</span>
{p.isDefault && (
<Star
@@ -526,13 +521,13 @@ export function ModelsSection({
{dict.modelConfig.addProvider}
</SelectTrigger>
<SelectContent className="max-h-72">
{(Object.keys(PROVIDER_INFO) as ProviderName[]).map(
{(Object.keys(PROVIDERS) as ProviderName[]).map(
(p) => {
// Global-credential providers already in
// the env config can't be added here —
// panel credentials would override theirs
const envBlocked =
FIXED_CRED_PROVIDERS.includes(p) &&
!!PROVIDERS[p].fixedCredentials &&
envProviders.some(
(e) => e.provider === p,
)
@@ -544,7 +539,7 @@ export function ModelsSection({
>
<div className="flex items-center gap-2">
<ProviderLogo provider={p} />
{PROVIDER_INFO[p].label}
{PROVIDERS[p].label}
{envBlocked && (
<span className="text-xs text-muted-foreground">
{
+18 -13
View File
@@ -47,6 +47,7 @@ import {
resolveMaxOutputTokens,
withOutputTokenLimitFallback,
} from "@/lib/output-token-limit"
import { PROVIDERS, type ProviderName } from "@/lib/providers"
import {
type FlattenedServerModel,
findServerModelById,
@@ -173,14 +174,17 @@ async function handleChatRequest(req: Request): Promise<Response> {
// A server model's provider comes from its config: for one set up in
// the admin panel the header holds the provider name's slug. Without
// either, the server's own AI_PROVIDER.
const isEdgeOne =
(serverModelConfig.provider || provider || getServerProvider()) ===
"edgeone"
// EdgeOne is this deployment's own function, whatever URL the request
// names: another host would get the user's EdgeOne cookies, and the
// quota counts it. Absolute, as the SDK needs.
if (isEdgeOne) baseUrl = edgeOneEndpoint(req)
const requestedProvider =
serverModelConfig.provider || provider || getServerProvider()
// A provider without credentials (EdgeOne) is this deployment's own
// function, whatever URL the request names: another host would get the
// user's EdgeOne cookies, and the quota counts it. Absolute, as the SDK
// needs.
const onSiteFunction =
!!requestedProvider &&
Object.hasOwn(PROVIDERS, requestedProvider) &&
PROVIDERS[requestedProvider as ProviderName].credential === "none"
if (onSiteFunction) baseUrl = edgeOneEndpoint(req)
// Same rule as validate-model: with ALLOW_PRIVATE_URLS=false a request may
// not point the server at a private or internal address
@@ -195,12 +199,13 @@ async function handleChatRequest(req: Request): Promise<Response> {
const cookieHeader = req.headers.get("cookie")
const clientOverrides = {
// Server model provider takes precedence over client header; EdgeOne
// named only in AI_PROVIDER is named here, for its own base URL
// Server model provider takes precedence over client header; the
// site's function named only in AI_PROVIDER is named here, for its
// own base URL
provider:
serverModelConfig.provider ||
provider ||
(isEdgeOne ? "edgeone" : null),
(onSiteFunction ? requestedProvider : null),
baseUrl,
apiKey: req.headers.get("x-ai-api-key"),
// A server model runs the model it was configured with, whatever the header says
@@ -216,7 +221,7 @@ async function handleChatRequest(req: Request): Promise<Response> {
vertexApiKey: req.headers.get("x-vertex-api-key"),
// Pass cookies for EdgeOne Pages authentication, and the access code,
// which the EdgeOne function checks too
...(isEdgeOne && {
...(onSiteFunction && {
headers: {
...(cookieHeader && { cookie: cookieHeader }),
"x-access-code": req.headers.get("x-access-code") || "",
@@ -420,7 +425,7 @@ ${userInputText}
// Also merge for OpenAI-compatible providers with custom base URLs (e.g. vLLM, LMStudio)
// because open-source model chat templates (Qwen, Llama, etc.) typically reject multiple system messages
const isCustomOpenAIEndpoint =
resolvedProvider === "openai" &&
PROVIDERS[resolvedProvider].sdk === "openai" &&
!!(
baseUrl ||
process.env.OPENAI_BASE_URL ||