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:
@@ -1,9 +1,9 @@
|
||||
import { platform, arch } from "os";
|
||||
import { PROVIDERS } from "./providers.js";
|
||||
import { PROVIDERS, PROVIDER_OAUTH } from "./providers.js";
|
||||
|
||||
// === Gemini CLI ===
|
||||
export const GEMINI_CLI_VERSION = "0.34.0";
|
||||
export const GEMINI_CLI_API_CLIENT = "google-genai-sdk/1.41.0 gl-node/v22.19.0";
|
||||
// === Gemini CLI === derive từ registry gemini-cli.transport
|
||||
export const GEMINI_CLI_VERSION = PROVIDERS["gemini-cli"]?.cliVersion;
|
||||
export const GEMINI_CLI_API_CLIENT = PROVIDERS["gemini-cli"]?.apiClient;
|
||||
|
||||
// Map Node arch to Gemini CLI arch string (x64/x86/arm64/...)
|
||||
function geminiCLIArch() {
|
||||
@@ -17,11 +17,13 @@ export function geminiCLIUserAgent(model = "unknown") {
|
||||
}
|
||||
|
||||
// === GitHub Copilot ===
|
||||
// Derive từ registry github.transport.copilot
|
||||
const _ghCopilot = PROVIDERS.github?.copilot || {};
|
||||
export const GITHUB_COPILOT = {
|
||||
VSCODE_VERSION: "1.110.0",
|
||||
COPILOT_CHAT_VERSION: "0.38.0",
|
||||
USER_AGENT: "GitHubCopilotChat/0.38.0",
|
||||
API_VERSION: "2025-04-01",
|
||||
VSCODE_VERSION: _ghCopilot.vscodeVersion,
|
||||
COPILOT_CHAT_VERSION: _ghCopilot.chatVersion,
|
||||
USER_AGENT: _ghCopilot.userAgent,
|
||||
API_VERSION: _ghCopilot.apiVersion,
|
||||
};
|
||||
|
||||
// === Antigravity enums ===
|
||||
@@ -153,43 +155,19 @@ export const LOAD_CODE_ASSIST_METADATA = {
|
||||
export const CLAUDE_SYSTEM_PROMPT = "You are Claude Code, Anthropic's official CLI for Claude.";
|
||||
export const ANTIGRAVITY_DEFAULT_SYSTEM = "You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.**Absolute paths only****Proactiveness**";
|
||||
|
||||
// Proactive token refresh lead times per provider (ms)
|
||||
export const REFRESH_LEAD_MS = {
|
||||
codex: 5 * 24 * 60 * 60 * 1000, // 5 days
|
||||
claude: 4 * 60 * 60 * 1000, // 4 hours
|
||||
iflow: 24 * 60 * 60 * 1000, // 24 hours
|
||||
qwen: 20 * 60 * 1000, // 20 minutes
|
||||
"kimi-coding": 5 * 60 * 1000, // 5 minutes
|
||||
antigravity: 5 * 60 * 1000, // 5 minutes
|
||||
};
|
||||
// Derive từ registry oauth.refreshLeadMs
|
||||
export const REFRESH_LEAD_MS = Object.fromEntries(
|
||||
Object.entries(PROVIDER_OAUTH).filter(([, o]) => o.refreshLeadMs).map(([id, o]) => [id, o.refreshLeadMs])
|
||||
);
|
||||
|
||||
// OAuth endpoints
|
||||
export const OAUTH_ENDPOINTS = {
|
||||
google: {
|
||||
token: "https://oauth2.googleapis.com/token",
|
||||
auth: "https://accounts.google.com/o/oauth2/auth"
|
||||
},
|
||||
openai: {
|
||||
token: PROVIDERS.codex.tokenUrl,
|
||||
auth: "https://auth.openai.com/oauth/authorize"
|
||||
},
|
||||
anthropic: {
|
||||
token: PROVIDERS.claude.tokenUrl,
|
||||
auth: "https://api.anthropic.com/v1/oauth/authorize"
|
||||
},
|
||||
qwen: {
|
||||
token: "https://qwen.ai/api/v1/oauth2/token",
|
||||
auth: "https://qwen.ai/api/v1/oauth2/device/code"
|
||||
},
|
||||
iflow: {
|
||||
token: PROVIDERS.iflow.tokenUrl,
|
||||
auth: "https://iflow.cn/oauth"
|
||||
},
|
||||
github: {
|
||||
token: "https://github.com/login/oauth/access_token",
|
||||
auth: "https://github.com/login/oauth/authorize",
|
||||
deviceCode: "https://github.com/login/device/code"
|
||||
}
|
||||
google: { token: "https://oauth2.googleapis.com/token", auth: "https://accounts.google.com/o/oauth2/auth" },
|
||||
openai: { token: PROVIDER_OAUTH["codex"]?.tokenUrl, auth: PROVIDER_OAUTH["codex"]?.authorizeUrl },
|
||||
anthropic: { token: PROVIDER_OAUTH["claude"]?.tokenUrl, auth: "https://api.anthropic.com/v1/oauth/authorize" }, // ≠ claude.authorizeUrl (claude.ai login) — keep
|
||||
qwen: { token: PROVIDER_OAUTH["qwen"]?.tokenUrl, auth: PROVIDER_OAUTH["qwen"]?.deviceCodeUrl },
|
||||
iflow: { token: PROVIDER_OAUTH["iflow"]?.tokenUrl, auth: PROVIDER_OAUTH["iflow"]?.authorizeUrl },
|
||||
github: { token: PROVIDER_OAUTH["github"]?.tokenUrl, auth: PROVIDER_OAUTH["github"]?.authorizeUrl, deviceCode: PROVIDER_OAUTH["github"]?.deviceCodeUrl },
|
||||
};
|
||||
|
||||
// Generate Kimi OAuth custom headers
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { PROVIDERS } from "./providers.js";
|
||||
import REGISTRY from "../providers/registry/index.js";
|
||||
// PROVIDER_MODELS now built from providers/registry (transport + models co-located)
|
||||
import { PROVIDER_MODELS } from "../providers/index.js";
|
||||
import { modelQuotaFamily, modelStrip, modelTargetFormat } from "../providers/models/schema.js";
|
||||
import { CODEX_REVIEW_SUFFIX } from "../providers/models/helpers.js";
|
||||
|
||||
export { PROVIDER_MODELS };
|
||||
|
||||
const CODEX_REVIEW_SUFFIX = "-review";
|
||||
|
||||
|
||||
// Helper functions
|
||||
export function getProviderModels(aliasOrId) {
|
||||
@@ -60,27 +60,11 @@ export function getModelQuotaFamily(aliasOrId, modelId) {
|
||||
return modelQuotaFamily(models?.find(m => m.id === modelId));
|
||||
}
|
||||
|
||||
// OAuth providers that use short aliases (everything else: alias = id)
|
||||
// Single source of canonical id→alias; services/model.js derives the reverse.
|
||||
export const OAUTH_ALIASES = {
|
||||
claude: "cc",
|
||||
codex: "cx",
|
||||
"gemini-cli": "gc",
|
||||
qwen: "qw",
|
||||
iflow: "if",
|
||||
antigravity: "ag",
|
||||
github: "gh",
|
||||
kiro: "kr",
|
||||
cursor: "cu",
|
||||
"kimi-coding": "kmc",
|
||||
kilocode: "kc",
|
||||
cline: "cl",
|
||||
opencode: "oc",
|
||||
qoder: "qd",
|
||||
"mimo-free": "mmf",
|
||||
vertex: "vertex",
|
||||
"vertex-partner": "vertex-partner",
|
||||
};
|
||||
// OAuth short aliases — derived from registry `alias` (single source). everything else: alias = id.
|
||||
// vertex/vertex-partner keep alias=id (kept via the `|| id` fallback in consumers).
|
||||
export const OAUTH_ALIASES = Object.fromEntries(
|
||||
REGISTRY.filter(r => r.alias && r.alias !== r.id).map(r => [r.id, r.alias])
|
||||
);
|
||||
|
||||
// Derived from PROVIDERS — no need to maintain manually
|
||||
export const PROVIDER_ID_TO_ALIAS = Object.fromEntries(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Barrel: PROVIDERS now built from providers/registry (transport co-located with models)
|
||||
export { PROVIDERS } from "../providers/index.js";
|
||||
import { PROVIDERS } from "../providers/index.js";
|
||||
export { PROVIDERS, PROVIDER_OAUTH } from "../providers/index.js";
|
||||
|
||||
export const OLLAMA_LOCAL_DEFAULT_HOST = "http://localhost:11434";
|
||||
|
||||
@@ -8,12 +9,9 @@ export function resolveOllamaLocalHost(credentials) {
|
||||
return (raw || OLLAMA_LOCAL_DEFAULT_HOST).replace(/\/$/, "");
|
||||
}
|
||||
|
||||
export const XIAOMI_TOKENPLAN_REGIONS = {
|
||||
sgp: "https://token-plan-sgp.xiaomimimo.com/v1",
|
||||
cn: "https://token-plan-cn.xiaomimimo.com/v1",
|
||||
ams: "https://token-plan-ams.xiaomimimo.com/v1"
|
||||
};
|
||||
export const XIAOMI_TOKENPLAN_DEFAULT_REGION = "sgp";
|
||||
// Region URLs single-source from registry xiaomi-tokenplan.transport
|
||||
export const XIAOMI_TOKENPLAN_REGIONS = PROVIDERS["xiaomi-tokenplan"]?.regions || {};
|
||||
export const XIAOMI_TOKENPLAN_DEFAULT_REGION = PROVIDERS["xiaomi-tokenplan"]?.defaultRegion;
|
||||
|
||||
export function resolveXiaomiTokenplanBaseUrl(credentials) {
|
||||
const region = credentials?.providerSpecificData?.region;
|
||||
|
||||
Reference in New Issue
Block a user