refactor(open-sse): registry consolidation + DRY media/oauth/adhoc cleanup

- Single-source registry: oauth clientId/tokenUrl, usage URLs, image/embed
  configs, search defaultModel, codex fixedPort, google token url derive.
- Remove 29 unused OmniRoute providers (registry 100→71); media intact.
- De-adhoc: codex literals → registry format/oauth flags; reasoningInject,
  image/embed openrouter headers + xai bodyFields config-driven.
- Add REGISTRY_TEMPLATE.js + expand PROVIDER_DEFAULTS/schema JSDoc.
- Baselines updated; PROVIDERS 62 + alias 90 byte-for-byte, golden snapshots.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-14 13:15:48 +07:00
parent 9105dd0e25
commit bb9e9aa91f
166 changed files with 3089 additions and 3067 deletions

View File

@@ -5,7 +5,11 @@
import { CLIENT_METADATA, getPlatformUserAgent } from "../config/appConstants.js";
import { proxyAwareFetch } from "../utils/proxyFetch.js";
import { resolveDefaultProfileArn } from "../config/kiroConstants.js";
import { ANTIGRAVITY_OAUTH_CLIENT } from "../providers/shared.js";
import { ANTIGRAVITY_OAUTH_CLIENT, ANTHROPIC_API_VERSION } from "../providers/shared.js";
import { PROVIDERS } from "../providers/index.js";
// usage endpoints: single source from registry transport.usage
const U = (id) => PROVIDERS[id]?.usage || {};
// GitHub API config
const GITHUB_CONFIG = {
@@ -13,49 +17,40 @@ const GITHUB_CONFIG = {
userAgent: "GitHubCopilotChat/0.26.7",
};
// GLM quota endpoints (region-aware)
// GLM quota endpoints (region-aware) — url from registry transport.usage
const GLM_QUOTA_URLS = {
international: "https://api.z.ai/api/monitor/usage/quota/limit",
china: "https://open.bigmodel.cn/api/monitor/usage/quota/limit",
international: U("glm").url,
china: U("glm-cn").url,
};
// MiniMax usage endpoints (try in order, fallback on transient errors)
const MINIMAX_USAGE_URLS = {
minimax: [
"https://www.minimax.io/v1/token_plan/remains",
"https://api.minimax.io/v1/api/openplatform/coding_plan/remains",
],
"minimax-cn": [
"https://www.minimaxi.com/v1/api/openplatform/coding_plan/remains",
"https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains",
],
minimax: U("minimax").urls,
"minimax-cn": U("minimax-cn").urls,
};
// Vercel AI Gateway credits endpoint
// Returns { balance: "95.50", total_used: "4.50" } (USD as decimal strings).
// Docs: https://vercel.com/docs/ai-gateway/usage
const VERCEL_AI_GATEWAY_CREDITS_URL = "https://ai-gateway.vercel.sh/v1/credits";
const VERCEL_AI_GATEWAY_CREDITS_URL = U("vercel-ai-gateway").url;
// Antigravity API config (from Quotio)
// Antigravity API config (from Quotio) — urls from registry, oauth client + dynamic UA kept here
const ANTIGRAVITY_CONFIG = {
quotaApiUrl: "https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
loadProjectApiUrl: "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist",
tokenUrl: "https://oauth2.googleapis.com/token",
...U("antigravity"),
...ANTIGRAVITY_OAUTH_CLIENT,
userAgent: getPlatformUserAgent(),
};
// Codex (OpenAI) API config
const CODEX_CONFIG = {
usageUrl: "https://chatgpt.com/backend-api/wham/usage",
usageUrl: U("codex").url,
};
// Claude API config
// Claude API config (urls from registry, apiVersion is header logic kept here)
const CLAUDE_CONFIG = {
oauthUsageUrl: "https://api.anthropic.com/api/oauth/usage",
usageUrl: "https://api.anthropic.com/v1/organizations/{org_id}/usage",
settingsUrl: "https://api.anthropic.com/v1/settings",
apiVersion: "2023-06-01",
oauthUsageUrl: U("claude").oauthUrl,
usageUrl: U("claude").orgUrl,
settingsUrl: U("claude").settingsUrl,
apiVersion: ANTHROPIC_API_VERSION,
};
/**
@@ -139,7 +134,7 @@ async function getGitHubUsage(accessToken, providerSpecificData, proxyOptions =
}
// copilot_internal/user API requires GitHub OAuth token, not copilotToken
const response = await proxyAwareFetch("https://api.github.com/copilot_internal/user", {
const response = await proxyAwareFetch(U("github").url, {
headers: {
"Authorization": `token ${accessToken}`,
"Accept": "application/json",
@@ -249,7 +244,7 @@ async function getGeminiUsage(accessToken, providerSpecificData, proxyOptions =
let response;
try {
response = await proxyAwareFetch(
"https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota",
U("gemini-cli").quotaUrl,
{
method: "POST",
headers: {
@@ -313,7 +308,7 @@ async function getGeminiSubscriptionInfo(accessToken, proxyOptions = null) {
const timeoutId = setTimeout(() => controller.abort(), 10000);
try {
const response = await proxyAwareFetch(
"https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist",
U("gemini-cli").loadCodeAssistUrl,
{
method: "POST",
headers: {
@@ -765,7 +760,7 @@ async function getKiroUsage(accessToken, providerSpecificData, proxyOptions = nu
{
name: "codewhisperer-get",
run: async () => proxyAwareFetch(
`https://codewhisperer.us-east-1.amazonaws.com/getUsageLimits?${getUsageParams.toString()}`,
`${U("kiro").cwHost}${U("kiro").limitsPath}?${getUsageParams.toString()}`,
{
method: "GET",
headers: {
@@ -780,7 +775,7 @@ async function getKiroUsage(accessToken, providerSpecificData, proxyOptions = nu
},
{
name: "codewhisperer-post",
run: async () => proxyAwareFetch("https://codewhisperer.us-east-1.amazonaws.com", {
run: async () => proxyAwareFetch(U("kiro").cwHost, {
method: "POST",
headers: {
"Authorization": `Bearer ${accessToken}`,
@@ -803,7 +798,7 @@ async function getKiroUsage(accessToken, providerSpecificData, proxyOptions = nu
profileArn,
resourceType: "AGENTIC_REQUEST",
});
return proxyAwareFetch(`https://q.us-east-1.amazonaws.com/getUsageLimits?${params}`, {
return proxyAwareFetch(`${U("kiro").qHost}${U("kiro").limitsPath}?${params}`, {
method: "GET",
headers: {
"Authorization": `Bearer ${accessToken}`,
@@ -1289,7 +1284,7 @@ async function getQoderUsage(accessToken, proxyOptions = null) {
}
try {
const response = await proxyAwareFetch(
"https://openapi.qoder.sh/api/v2/quota/usage",
U("qoder").url,
{
method: "GET",
headers: {