fix(api): accept the current compatible-provider connection id scheme in the models test route (#8326) (#8359)

This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-07-24 11:44:46 -03:00
committed by GitHub
parent 493708f575
commit fa46d93941
7 changed files with 207 additions and 14 deletions

View File

@@ -0,0 +1,36 @@
/**
* Single source of truth for recognizing a "compatible provider" connection
* ID — the dynamic IDs generated for openai-compatible / anthropic-compatible
* custom nodes (src/app/api/provider-nodes/route.ts).
*
* Generated shapes (all four must match):
* - openai-compatible-chat-<uuid>
* - openai-compatible-responses-<uuid>
* - anthropic-compatible-<uuid>
* - anthropic-compatible-cc-<uuid>
*
* Built from the same prefix constants used at ID-generation time
* (src/shared/constants/providers.ts) so the generator and the validator can
* never drift apart again. See #8326: the previous inline regex required a
* literal "-chat-" segment, rejecting 3 of the 4 shapes the system actually
* generates.
*
* @module shared/utils/compatibleProviderId
*/
import { OPENAI_COMPATIBLE_PREFIX, ANTHROPIC_COMPATIBLE_PREFIX } from "@/shared/constants/providers";
const COMPATIBLE_PROVIDER_ID_PATTERN = new RegExp(
`^(?:${OPENAI_COMPATIBLE_PREFIX}(?:chat|responses)-|${ANTHROPIC_COMPATIBLE_PREFIX}(?:cc-)?)[0-9a-f-]+$`,
"i"
);
/**
* True when `providerId` matches one of the four generated compatible-
* provider connection ID shapes. Rejects plain built-in provider IDs (e.g.
* "openai", "anthropic") and unrelated look-alikes (e.g.
* "custom-compatible-chat-...").
*/
export function isCompatibleProviderConnectionId(providerId: string | null | undefined): boolean {
return typeof providerId === "string" && COMPATIBLE_PROVIDER_ID_PATTERN.test(providerId);
}