mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 06:42:12 +03:00
fix(api): accept the current compatible-provider connection id scheme in the models test route (#8326) (#8359)
This commit is contained in:
committed by
GitHub
parent
493708f575
commit
fa46d93941
@@ -3,6 +3,7 @@ import { getServiceModels } from "@/lib/db/serviceModels";
|
||||
import { isServiceBackendPluginId } from "@/lib/services/serviceBackends";
|
||||
import { getRegistryEntry } from "@omniroute/open-sse/config/providerRegistry.ts";
|
||||
import { getProviderById, getProviderByAlias } from "@/shared/constants/providers";
|
||||
import { isCompatibleProviderConnectionId } from "@/shared/utils/compatibleProviderId";
|
||||
|
||||
/**
|
||||
* Handle CORS preflight
|
||||
@@ -51,9 +52,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ prov
|
||||
providerAlias = catalogEntry.alias || providerId;
|
||||
} else {
|
||||
// Allow fetching models by connection ID for compatible providers
|
||||
const isCompatibleConnectionId = /^(openai|anthropic)-compatible-chat-[a-f0-9-]+$/.test(
|
||||
rawProvider
|
||||
);
|
||||
const isCompatibleConnectionId = isCompatibleProviderConnectionId(rawProvider);
|
||||
if (!isCompatibleConnectionId) {
|
||||
return Response.json(
|
||||
{
|
||||
|
||||
@@ -12,6 +12,13 @@
|
||||
* @module lib/display/names
|
||||
*/
|
||||
|
||||
import { isCompatibleProviderConnectionId } from "@/shared/utils/compatibleProviderId";
|
||||
import {
|
||||
isClaudeCodeCompatibleProvider,
|
||||
isOpenAICompatibleProvider,
|
||||
isAnthropicCompatibleProvider,
|
||||
} from "@/shared/constants/providers";
|
||||
|
||||
export interface ConnectionLike {
|
||||
id?: string | null;
|
||||
name?: string | null;
|
||||
@@ -59,14 +66,11 @@ export function getProviderDisplayName(
|
||||
if (providerNode?.prefix?.trim()) return providerNode.prefix.trim();
|
||||
if (!providerId) return "Unknown Provider";
|
||||
|
||||
// Simplify dynamic compatible provider IDs
|
||||
const match = providerId.match(
|
||||
/^(openai|anthropic)-compatible-(?:chat|responses)-[0-9a-f-]{10,}$/i
|
||||
);
|
||||
if (match) return `Compatible (${match[1]})`;
|
||||
|
||||
if (/^anthropic-compatible-cc-[0-9a-f-]{10,}$/i.test(providerId)) {
|
||||
return "CC Compatible";
|
||||
// Simplify dynamic compatible provider IDs (all 4 generated shapes — #8326)
|
||||
if (isCompatibleProviderConnectionId(providerId)) {
|
||||
if (isClaudeCodeCompatibleProvider(providerId)) return "CC Compatible";
|
||||
if (isOpenAICompatibleProvider(providerId)) return "Compatible (openai)";
|
||||
if (isAnthropicCompatibleProvider(providerId)) return "Compatible (anthropic)";
|
||||
}
|
||||
|
||||
return providerId;
|
||||
|
||||
36
src/shared/utils/compatibleProviderId.ts
Normal file
36
src/shared/utils/compatibleProviderId.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user