mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
refactor(open-sse): translator DRY + schema enums, bug fixes, dead code cleanup
- Bug B1-B7: media UI m.kind||m.type, serviceKinds, gemini mediaPriority, schema kind, models/info lookup by kind - Dead code D1-D6: safeParseJSON, drop PROVIDER_ENDPOINTS, orphan fetcher, GITHUB_CONFIG derive, getProviderConfig internal, legacy kiro file - Translator concerns: toOpenAIUsage, toOpenAIFinish (gemini/kiro/ollama + fix kiro tool finish), thinking effort maps - Reorg helpers/ → concerns/ (logic) + formats/ (per-format) + schema/ (pure enums: roles/blocks/finishReasons/defaults) - Wire ~280 hardcoded role/block/finish/default literals to schema enums across 20+ files - collapseTextParts + extractTextContent dedup - Normalize translator fn names to openaiToXRequest / xToOpenAIResponse - Golden tests lock behavior; 0 regression (byte-for-byte providers/alias, 26=26 known fails) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -134,7 +134,7 @@ const KIND_EXAMPLE_CONFIG = {
|
||||
function EmbeddingExampleCard({ providerId, customAlias }) {
|
||||
const isCustom = isCustomEmbeddingProvider(providerId);
|
||||
const providerAlias = isCustom ? (customAlias || providerId) : getProviderAlias(providerId);
|
||||
const embeddingModels = isCustom ? [] : getModelsByProviderId(providerId).filter((m) => m.type === "embedding");
|
||||
const embeddingModels = isCustom ? [] : getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "embedding");
|
||||
|
||||
const [selectedModel, setSelectedModel] = useState(embeddingModels[0]?.id ?? "");
|
||||
const [input, setInput] = useState("The quick brown fox jumps over the lazy dog");
|
||||
@@ -431,7 +431,7 @@ function TtsExampleCard({ providerId }) {
|
||||
// Use per-model voices if available, else flat list
|
||||
const voices = (config.voicesPerModel && defaultModel)
|
||||
? (getTtsVoicesForModel(providerId, defaultModel) || [])
|
||||
: getModelsByProviderId(config.voiceKey || providerId).filter((m) => m.type === "tts");
|
||||
: getModelsByProviderId(config.voiceKey || providerId).filter((m) => (m.kind || m.type) === "tts");
|
||||
if (voices.length) {
|
||||
if (config.hasBrowseButton) {
|
||||
// Google TTS: pre-select "en" (English) as default, show as single voice chip
|
||||
@@ -475,7 +475,7 @@ function TtsExampleCard({ providerId }) {
|
||||
if (config.voiceSource === "hardcoded") {
|
||||
// Build languages/byLang from static providerModels data
|
||||
const voiceKey = config.voiceKey || providerId;
|
||||
const voices = getModelsByProviderId(voiceKey).filter((m) => m.type === "tts");
|
||||
const voices = getModelsByProviderId(voiceKey).filter((m) => (m.kind || m.type) === "tts");
|
||||
const byLangMap = {};
|
||||
for (const v of voices) {
|
||||
if (!byLangMap[v.id]) byLangMap[v.id] = { code: v.id, name: v.name, voices: [{ id: v.id, name: v.name }] };
|
||||
@@ -735,13 +735,13 @@ function TtsExampleCard({ providerId }) {
|
||||
<select
|
||||
value={selectedVoice}
|
||||
onChange={(e) => {
|
||||
const m = getModelsByProviderId(providerId).filter((m) => m.type === "tts").find((m) => m.id === e.target.value);
|
||||
const m = getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "tts").find((m) => m.id === e.target.value);
|
||||
setSelectedVoice(e.target.value);
|
||||
setSelectedVoiceName(m?.name || e.target.value);
|
||||
}}
|
||||
className="w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"
|
||||
>
|
||||
{getModelsByProviderId(providerId).filter((m) => m.type === "tts").map((m) => (
|
||||
{getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "tts").map((m) => (
|
||||
<option key={m.id} value={m.id}>{m.name || m.id}</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -925,7 +925,7 @@ function GenericExampleCard({ providerId, kind }) {
|
||||
const safeExConfig = exConfig || {};
|
||||
|
||||
// Get models for this kind (e.g., type="image")
|
||||
const kindModels = getModelsByProviderId(providerId).filter((m) => m.type === kind);
|
||||
const kindModels = getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === kind);
|
||||
// Kinds that need a model identifier in the request (image/video/music)
|
||||
const KIND_NEEDS_MODEL = new Set(["image", "video", "music", "imageToText"]);
|
||||
const needsModel = KIND_NEEDS_MODEL.has(kind);
|
||||
@@ -1429,7 +1429,7 @@ function GenericExampleCard({ providerId, kind }) {
|
||||
// ─── STT Example Card ────────────────────────────────────────────────────────
|
||||
function SttExampleCard({ providerId }) {
|
||||
const providerAlias = getProviderAlias(providerId);
|
||||
const builtinSttModels = getModelsByProviderId(providerId).filter((m) => m.type === "stt");
|
||||
const builtinSttModels = getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "stt");
|
||||
const [customSttModels, setCustomSttModels] = useState([]);
|
||||
const sttModels = [...builtinSttModels, ...customSttModels];
|
||||
|
||||
@@ -1467,7 +1467,7 @@ function SttExampleCard({ providerId }) {
|
||||
fetch("/api/models/custom", { cache: "no-store" })
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
const list = (d.models || []).filter((m) => m.type === "stt" && m.providerAlias === providerAlias);
|
||||
const list = (d.models || []).filter((m) => (m.kind || m.type) === "stt" && m.providerAlias === providerAlias);
|
||||
setCustomSttModels(list);
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
@@ -206,14 +206,14 @@ export default function ModelsCard({ providerId, kindFilter, providerAliasOverri
|
||||
const builtInModels = kindFilter
|
||||
? allBuiltIn.filter((m) => {
|
||||
if (m.kinds) return m.kinds.includes(kindFilter);
|
||||
return (m.type || "llm") === kindFilter;
|
||||
return (m.kind || m.type || "llm") === kindFilter;
|
||||
})
|
||||
: allBuiltIn;
|
||||
|
||||
// Custom models for this provider + kind, dedupe vs built-in
|
||||
const myCustomModels = customModels.filter(
|
||||
(m) => m.providerAlias === providerAlias
|
||||
&& (m.type || "llm") === effectiveType
|
||||
&& (m.kind || m.type || "llm") === effectiveType
|
||||
&& !builtInModels.some((b) => b.id === m.id)
|
||||
);
|
||||
|
||||
|
||||
@@ -122,6 +122,9 @@ export default function ProvidersPage() {
|
||||
|
||||
const sortByPriority = (entries, authType) =>
|
||||
[...entries].sort(([ka, a], [kb, b]) => {
|
||||
const pa = a.priority ?? 999;
|
||||
const pb = b.priority ?? 999;
|
||||
if (pa !== pb) return pa - pb;
|
||||
const sa = getProviderStats(ka, authType);
|
||||
const sb = getProviderStats(kb, authType);
|
||||
const ca = sa.connected > 0 ? 1 : 0;
|
||||
@@ -132,6 +135,9 @@ export default function ProvidersPage() {
|
||||
|
||||
const sortItemsByPriority = (items, authType) =>
|
||||
[...items].sort((a, b) => {
|
||||
const pa = a.priority ?? 999;
|
||||
const pb = b.priority ?? 999;
|
||||
if (pa !== pb) return pa - pb;
|
||||
const sa = getProviderStats(a.id, authType);
|
||||
const sb = getProviderStats(b.id, authType);
|
||||
const ca = sa.connected > 0 ? 1 : 0;
|
||||
@@ -273,15 +279,22 @@ export default function ProvidersPage() {
|
||||
}))
|
||||
.filter((p) => matchSearch(p.name));
|
||||
|
||||
const oauthEntries = Object.entries(OAUTH_PROVIDERS).filter(
|
||||
([, info]) => !info.hidden && matchSearch(info.name),
|
||||
const oauthEntries = sortByPriority(
|
||||
Object.entries(OAUTH_PROVIDERS).filter(([, info]) => !info.hidden && matchSearch(info.name)),
|
||||
"oauth",
|
||||
);
|
||||
const freeEntries = Object.entries(FREE_PROVIDERS).filter(
|
||||
([, info]) => !info.hidden && matchSearch(info.name),
|
||||
);
|
||||
const freeTierEntries = Object.entries(FREE_TIER_PROVIDERS).filter(
|
||||
([, info]) => !info.hidden && matchSearch(info.name),
|
||||
);
|
||||
const freeTierEntries = Object.entries(FREE_TIER_PROVIDERS)
|
||||
.filter(([, info]) => !info.hidden && matchSearch(info.name))
|
||||
.sort(([, a], [, b]) => {
|
||||
// hasFree providers first, then by priority
|
||||
const fa = a.hasFree ? 0 : 1;
|
||||
const fb = b.hasFree ? 0 : 1;
|
||||
if (fa !== fb) return fa - fb;
|
||||
return (a.priority ?? 999) - (b.priority ?? 999);
|
||||
});
|
||||
const apikeyEntries = sortByPriority(
|
||||
Object.entries(APIKEY_PROVIDERS).filter(
|
||||
([, info]) =>
|
||||
|
||||
@@ -2,9 +2,8 @@ import { getProviderConnectionById, updateProviderConnection } from "@/lib/local
|
||||
import { resolveConnectionProxyConfig } from "@/lib/network/connectionProxy";
|
||||
import { testProxyUrl } from "@/lib/network/proxyTest";
|
||||
import { isOpenAICompatibleProvider, isAnthropicCompatibleProvider } from "@/shared/constants/providers";
|
||||
import { PROVIDER_ENDPOINTS } from "@/shared/constants/config";
|
||||
import { getDefaultModel } from "open-sse/config/providerModels.js";
|
||||
import { resolveOllamaLocalHost } from "open-sse/config/providers.js";
|
||||
import { resolveOllamaLocalHost, PROVIDERS } from "open-sse/config/providers.js";
|
||||
import {
|
||||
refreshProviderCredentials,
|
||||
shouldRefreshCredentials,
|
||||
@@ -474,7 +473,7 @@ async function testApiKeyConnection(connection, effectiveProxy = null) {
|
||||
}
|
||||
case "volcengine-ark":
|
||||
case "byteplus": {
|
||||
const res = await fetchWithConnectionProxy(PROVIDER_ENDPOINTS[connection.provider], {
|
||||
const res = await fetchWithConnectionProxy(PROVIDERS[connection.provider]?.baseUrl, {
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${connection.apiKey}`, "content-type": "application/json" },
|
||||
body: JSON.stringify({ model: getDefaultModel(connection.provider), max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
||||
|
||||
@@ -3,8 +3,7 @@ import { getProviderNodeById } from "@/models";
|
||||
import { isOpenAICompatibleProvider, isAnthropicCompatibleProvider, isCustomEmbeddingProvider, AI_PROVIDERS } from "@/shared/constants/providers";
|
||||
import { getDefaultModel } from "open-sse/config/providerModels.js";
|
||||
import { resolveOllamaLocalHost, resolveXiaomiTokenplanBaseUrl, PROVIDERS } from "open-sse/config/providers.js";
|
||||
import { openaiToCommandCode } from "open-sse/translator/request/openai-to-commandcode.js";
|
||||
import { PROVIDER_ENDPOINTS } from "@/shared/constants/config";
|
||||
import { openaiToCommandCodeRequest } from "open-sse/translator/request/openai-to-commandcode.js";
|
||||
import { normalizeProviderId } from "@/lib/providerNormalization";
|
||||
|
||||
// Probe a webSearch/webFetch provider using its searchConfig/fetchConfig.
|
||||
@@ -326,7 +325,7 @@ export async function POST(request) {
|
||||
}
|
||||
case "volcengine-ark":
|
||||
case "byteplus": {
|
||||
const res = await fetch(PROVIDER_ENDPOINTS[provider], {
|
||||
const res = await fetch(PROVIDERS[provider]?.baseUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${apiKey}`,
|
||||
@@ -400,7 +399,7 @@ export async function POST(request) {
|
||||
case "commandcode": {
|
||||
const cfg = PROVIDERS.commandcode;
|
||||
const model = getDefaultModel("commandcode");
|
||||
const payload = openaiToCommandCode(model, {
|
||||
const payload = openaiToCommandCodeRequest(model, {
|
||||
messages: [{ role: "user", content: "ping" }],
|
||||
max_tokens: 1,
|
||||
stream: false,
|
||||
|
||||
@@ -40,7 +40,8 @@ function buildInfo({ alias, providerId, model, kind, providerInfo }) {
|
||||
}
|
||||
|
||||
// id format: "{alias}/{modelId}" - alias may also be providerId
|
||||
function lookup(fullId) {
|
||||
// requestedKind: optional, disambiguates duplicate ids across kinds (e.g. gemini-2.5-pro llm vs stt)
|
||||
function lookup(fullId, requestedKind) {
|
||||
if (!fullId || !fullId.includes("/")) return null;
|
||||
const slash = fullId.indexOf("/");
|
||||
const alias = fullId.slice(0, slash);
|
||||
@@ -50,7 +51,9 @@ function lookup(fullId) {
|
||||
|
||||
// PROVIDER_MODELS lookup (by alias key, fallback to providerId)
|
||||
const list = PROVIDER_MODELS[alias] || PROVIDER_MODELS[providerId] || [];
|
||||
const m = list.find((x) => x.id === modelId);
|
||||
const m = requestedKind
|
||||
? list.find((x) => x.id === modelId && (x.kind || x.type || "llm") === requestedKind)
|
||||
: list.find((x) => x.id === modelId);
|
||||
if (m) {
|
||||
const kind = m.kind || m.type || "llm";
|
||||
return buildInfo({ alias, providerId, model: m, kind, providerInfo });
|
||||
@@ -82,13 +85,14 @@ export async function OPTIONS() {
|
||||
export async function GET(request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
const kind = searchParams.get("kind");
|
||||
if (!id) {
|
||||
return Response.json(
|
||||
{ error: { message: "Missing required query param: id (e.g. ?id=openai/dall-e-3)", type: "invalid_request_error" } },
|
||||
{ status: 400, headers: { "Access-Control-Allow-Origin": "*" } },
|
||||
);
|
||||
}
|
||||
const info = lookup(id);
|
||||
const info = lookup(id, kind);
|
||||
if (!info) {
|
||||
return Response.json(
|
||||
{ error: { message: `Model not found: ${id}`, type: "not_found" } },
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
/**
|
||||
* Usage Fetcher - Get usage data from provider APIs
|
||||
*/
|
||||
|
||||
import { GITHUB_CONFIG, GEMINI_CONFIG, ANTIGRAVITY_CONFIG } from "@/lib/oauth/constants/oauth";
|
||||
|
||||
/**
|
||||
* Get usage data for a provider connection
|
||||
* @param {Object} connection - Provider connection with accessToken
|
||||
* @returns {Object} Usage data with quotas
|
||||
*/
|
||||
export async function getUsageForProvider(connection) {
|
||||
const { provider, accessToken, providerSpecificData } = connection;
|
||||
|
||||
switch (provider) {
|
||||
case "github":
|
||||
return await getGitHubUsage(accessToken, providerSpecificData);
|
||||
case "gemini-cli":
|
||||
return await getGeminiUsage(accessToken);
|
||||
case "antigravity":
|
||||
return await getAntigravityUsage(accessToken);
|
||||
case "claude":
|
||||
return await getClaudeUsage(accessToken);
|
||||
case "codex":
|
||||
return await getCodexUsage(accessToken);
|
||||
case "qwen":
|
||||
return await getQwenUsage(accessToken, providerSpecificData);
|
||||
case "iflow":
|
||||
return await getIflowUsage(accessToken);
|
||||
default:
|
||||
return { message: `Usage API not implemented for ${provider}` };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GitHub Copilot Usage
|
||||
*/
|
||||
async function getGitHubUsage(accessToken, providerSpecificData) {
|
||||
try {
|
||||
// Use copilotToken for copilot_internal API, not GitHub OAuth accessToken
|
||||
const copilotToken = providerSpecificData?.copilotToken;
|
||||
if (!copilotToken) {
|
||||
throw new Error("Copilot token not found. Please refresh token first.");
|
||||
}
|
||||
|
||||
const response = await fetch("https://api.github.com/copilot_internal/user", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${copilotToken}`,
|
||||
Accept: "application/json",
|
||||
"X-GitHub-Api-Version": GITHUB_CONFIG.apiVersion,
|
||||
"User-Agent": GITHUB_CONFIG.userAgent,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
throw new Error(`GitHub API error: ${error}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Handle different response formats (paid vs free)
|
||||
if (data.quota_snapshots) {
|
||||
// Paid plan format
|
||||
const snapshots = data.quota_snapshots;
|
||||
return {
|
||||
plan: data.copilot_plan,
|
||||
resetDate: data.quota_reset_date,
|
||||
quotas: {
|
||||
chat: formatGitHubQuotaSnapshot(snapshots.chat),
|
||||
completions: formatGitHubQuotaSnapshot(snapshots.completions),
|
||||
premium_interactions: formatGitHubQuotaSnapshot(snapshots.premium_interactions),
|
||||
},
|
||||
};
|
||||
} else if (data.monthly_quotas || data.limited_user_quotas) {
|
||||
// Free/limited plan format
|
||||
const monthlyQuotas = data.monthly_quotas || {};
|
||||
const usedQuotas = data.limited_user_quotas || {};
|
||||
|
||||
return {
|
||||
plan: data.copilot_plan || data.access_type_sku,
|
||||
resetDate: data.limited_user_reset_date,
|
||||
quotas: {
|
||||
chat: {
|
||||
used: usedQuotas.chat || 0,
|
||||
total: monthlyQuotas.chat || 0,
|
||||
unlimited: false,
|
||||
},
|
||||
completions: {
|
||||
used: usedQuotas.completions || 0,
|
||||
total: monthlyQuotas.completions || 0,
|
||||
unlimited: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return { message: "GitHub Copilot connected. Unable to parse quota data." };
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to fetch GitHub usage: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function formatGitHubQuotaSnapshot(quota) {
|
||||
if (!quota) return { used: 0, total: 0, unlimited: true };
|
||||
|
||||
return {
|
||||
used: quota.entitlement - quota.remaining,
|
||||
total: quota.entitlement,
|
||||
remaining: quota.remaining,
|
||||
unlimited: quota.unlimited || false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gemini CLI Usage (Google Cloud)
|
||||
*/
|
||||
async function getGeminiUsage(accessToken) {
|
||||
try {
|
||||
// Gemini CLI uses Google Cloud quotas
|
||||
// Try to get quota info from Cloud Resource Manager
|
||||
const response = await fetch(
|
||||
"https://cloudresourcemanager.googleapis.com/v1/projects?filter=lifecycleState:ACTIVE",
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
// Quota API may not be accessible, return generic message
|
||||
return { message: "Gemini CLI uses Google Cloud quotas. Check Google Cloud Console for details." };
|
||||
}
|
||||
|
||||
return { message: "Gemini CLI connected. Usage tracked via Google Cloud Console." };
|
||||
} catch (error) {
|
||||
return { message: "Unable to fetch Gemini usage. Check Google Cloud Console." };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Antigravity Usage
|
||||
*/
|
||||
async function getAntigravityUsage(accessToken) {
|
||||
try {
|
||||
// Similar to Gemini, uses Google Cloud
|
||||
return { message: "Antigravity connected. Usage tracked via Google Cloud Console." };
|
||||
} catch (error) {
|
||||
return { message: "Unable to fetch Antigravity usage." };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Claude Usage
|
||||
*/
|
||||
async function getClaudeUsage(accessToken) {
|
||||
try {
|
||||
// Claude OAuth doesn't expose usage API directly
|
||||
// Could potentially check via inference endpoint
|
||||
return { message: "Claude connected. Usage tracked per request." };
|
||||
} catch (error) {
|
||||
return { message: "Unable to fetch Claude usage." };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Codex (OpenAI) Usage
|
||||
*/
|
||||
async function getCodexUsage(accessToken) {
|
||||
try {
|
||||
// OpenAI usage requires organization API access
|
||||
return { message: "Codex connected. Check OpenAI dashboard for usage." };
|
||||
} catch (error) {
|
||||
return { message: "Unable to fetch Codex usage." };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Qwen Usage
|
||||
*/
|
||||
async function getQwenUsage(accessToken, providerSpecificData) {
|
||||
try {
|
||||
const resourceUrl = providerSpecificData?.resourceUrl;
|
||||
if (!resourceUrl) {
|
||||
return { message: "Qwen connected. No resource URL available." };
|
||||
}
|
||||
|
||||
// Qwen may have usage endpoint at resource URL
|
||||
return { message: "Qwen connected. Usage tracked per request." };
|
||||
} catch (error) {
|
||||
return { message: "Unable to fetch Qwen usage." };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* iFlow Usage
|
||||
*/
|
||||
async function getIflowUsage(accessToken) {
|
||||
try {
|
||||
// iFlow may have usage endpoint
|
||||
return { message: "iFlow connected. Usage tracked per request." };
|
||||
} catch (error) {
|
||||
return { message: "Unable to fetch iFlow usage." };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,26 +62,6 @@ export const CONSOLE_LOG_CONFIG = {
|
||||
// Client-side store TTL: how long fetched data stays fresh before re-fetching
|
||||
export const CLIENT_STORE_TTL_MS = 60000;
|
||||
|
||||
// Provider API endpoints (for display only)
|
||||
export const PROVIDER_ENDPOINTS = {
|
||||
openrouter: "https://openrouter.ai/api/v1/chat/completions",
|
||||
glm: "https://api.z.ai/api/anthropic/v1/messages",
|
||||
"glm-cn": "https://open.bigmodel.cn/api/coding/paas/v4/chat/completions",
|
||||
kimi: "https://api.kimi.com/coding/v1/messages",
|
||||
minimax: "https://api.minimax.io/anthropic/v1/messages",
|
||||
"minimax-cn": "https://api.minimaxi.com/anthropic/v1/messages",
|
||||
alicode: "https://coding.dashscope.aliyuncs.com/v1/chat/completions",
|
||||
"alicode-intl": "https://coding-intl.dashscope.aliyuncs.com/v1/chat/completions",
|
||||
"volcengine-ark": "https://ark.cn-beijing.volces.com/api/coding/v3/chat/completions",
|
||||
byteplus: "https://ark.ap-southeast.bytepluses.com/api/coding/v3/chat/completions",
|
||||
openai: "https://api.openai.com/v1/chat/completions",
|
||||
"vercel-ai-gateway": "https://ai-gateway.vercel.sh/v1/chat/completions",
|
||||
anthropic: "https://api.anthropic.com/v1/messages",
|
||||
gemini: "https://generativelanguage.googleapis.com/v1beta/models",
|
||||
ollama: "https://ollama.com/api/chat",
|
||||
"ollama-local": "http://localhost:11434/api/chat",
|
||||
};
|
||||
|
||||
// Re-export from providers.js for backward compatibility
|
||||
export {
|
||||
FREE_PROVIDERS,
|
||||
|
||||
@@ -11,7 +11,6 @@ const MEDIA_ENTRY_KEYS = [
|
||||
// Build provider UI object from registry entry
|
||||
function buildProviderEntry(r) {
|
||||
const mediaFields = {};
|
||||
// Support both legacy r.media wrapper and new flat top-level fields (post-migration)
|
||||
if (r.media) Object.assign(mediaFields, r.media);
|
||||
for (const k of MEDIA_ENTRY_KEYS) {
|
||||
if (r[k] !== undefined) mediaFields[k] = r[k];
|
||||
@@ -21,6 +20,8 @@ function buildProviderEntry(r) {
|
||||
id: r.id,
|
||||
alias: r.uiAlias || r.alias,
|
||||
...mediaFields,
|
||||
...(r.priority !== undefined ? { priority: r.priority } : {}),
|
||||
...(r.hasFree ? { hasFree: true } : {}),
|
||||
...(r.thinkingConfig ? { thinkingConfig: r.thinkingConfig } : {}),
|
||||
...(r.regions ? { regions: r.regions, defaultRegion: r.defaultRegion } : {}),
|
||||
...(r.hasProviderSpecificData ? { hasProviderSpecificData: true } : {}),
|
||||
@@ -147,7 +148,7 @@ export function getProvidersByKind(kind) {
|
||||
if (p.hiddenKinds?.includes(kind)) return false;
|
||||
return true;
|
||||
})
|
||||
.sort((a, b) => (a.mediaPriority ?? 100) - (b.mediaPriority ?? 100));
|
||||
.sort((a, b) => (a.priority ?? a.mediaPriority ?? 999) - (b.priority ?? b.mediaPriority ?? 999));
|
||||
}
|
||||
|
||||
// Derive từ registry features flags
|
||||
|
||||
Reference in New Issue
Block a user