mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
- 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>
39 lines
1.8 KiB
JavaScript
39 lines
1.8 KiB
JavaScript
// Single source: build PROVIDERS + PROVIDER_MODELS from registry/{id}.js (transport + models co-located).
|
|
import REGISTRY from "./registry/index.js";
|
|
import { PROVIDER_DEFAULTS } from "./schema.js";
|
|
import { normalizeModel } from "./models/schema.js";
|
|
import { buildTtsProviderModels } from "../config/ttsModels.js";
|
|
|
|
// oauth block is canonical for these fields; inject into transport so executors reading
|
|
// this.config.{clientId,clientSecret,tokenUrl} keep working without duplicating in transport
|
|
const OAUTH_INJECT_FIELDS = ["clientId", "clientSecret", "tokenUrl"];
|
|
|
|
// transport: re-apply shared default (format:"openai") + inject oauth-canonical fields
|
|
function buildTransport(transport, oauth) {
|
|
const t = { ...transport };
|
|
if (!t.format) t.format = PROVIDER_DEFAULTS.format;
|
|
if (oauth) {
|
|
for (const f of OAUTH_INJECT_FIELDS) {
|
|
if (t[f] === undefined && oauth[f] !== undefined) t[f] = oauth[f];
|
|
}
|
|
}
|
|
return t;
|
|
}
|
|
|
|
export const PROVIDERS = {};
|
|
export const PROVIDER_MODELS = {};
|
|
export const PROVIDER_OAUTH = {};
|
|
export const PROVIDER_MEDIA = {};
|
|
for (const entry of REGISTRY) {
|
|
if (entry.transport) PROVIDERS[entry.id] = buildTransport(entry.transport, entry.oauth);
|
|
// models omitted (undefined) → provider has no model list key; [] is a valid explicit empty list
|
|
// normalizeModel: accept terse "id" strings + derive name via regex when omitted
|
|
// alias defaults to id (doc 01 §2); without fallback all alias-less providers collide on key `undefined`
|
|
if (entry.models !== undefined) PROVIDER_MODELS[entry.alias || entry.id] = entry.models.map(normalizeModel);
|
|
if (entry.oauth) PROVIDER_OAUTH[entry.id] = entry.oauth;
|
|
if (entry.media) PROVIDER_MEDIA[entry.id] = entry.media;
|
|
}
|
|
|
|
// TTS model/voice tables keyed by special names (openai-tts-models, ...), not provider ids
|
|
Object.assign(PROVIDER_MODELS, buildTtsProviderModels());
|