mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 05:42:19 +03:00
Rebased onto the current release/v3.8.51 tip as part of a combined provider-retirement/provenance merge batch (Designer Web, Felo Web, Runtime, GPL-derived removal, Qwen Web already landed). Large conflict set (this is the biggest PR in the batch — the common ChatGPT Web provider touches chat, images, count-tokens, session leases, and combos). Conflicts resolved: - `open-sse/config/providers/registry/chatgpt-web/*`, `open-sse/executors/chatgpt-web*`, `open-sse/handlers/imageGeneration/providers/chatgptWeb.ts`, and their tests: kept deleted, matching the PR's stated scope. - `open-sse/config/providers/registry/minimax/web/index.ts`, `open-sse/handlers/imageGeneration/providers/geminiWeb.ts`, `open-sse/executors/gemini-web.ts`'s stale image-mode branch: base-drift collisions against already-merged sibling retirements (#11691, #11708) — kept deleted / dropped the dead code, since this PR's own branch forked before those merged. - `src/shared/constants/reservedProviderPrefixes.ts`, `open-sse/executors/index.ts`, `executorProxy.ts`, `virtualFactory.ts`, `autoStrategy.ts`, `src/lib/db/providers.ts`, `src/sse/handlers/chat.ts`: combined the Designer + Runtime (Felo/Qwen) + common-ChatGPT-Web retirement guard calls at each shared chokepoint — compute-once-then-OR pattern, consistent with prior combinations in this batch. - `src/sse/services/model.ts` / `src/sse/handlers/chatHelpers.ts`: adopted this PR's new `getModelInfoOrRetirementResponse()` central wrapper (a real improvement over ad-hoc try/catch), and extended it to also catch the Designer + Runtime retirement errors it didn't originally cover, so the consolidation doesn't regress the other two mechanisms. - `src/app/api/v1/images/edits/route.ts`: this PR moved the retirement check earlier (before `enforceApiKeyPolicy`) but left the old later call+catch block in place from base drift — removed the now-redundant duplicate `resolveImageRouteModel()` call and merged the Designer catch into the earlier one. - `open-sse/config/imageRegistry.ts`, `tests/snapshots/executors/executor-map.json` (`keyCount` recomputed to 133), `tests/snapshots/provider/translate-path.json`: same "both sides inserted a different retired provider at the same slot" pattern — resolved by dropping both. - `tests/unit/chatcore-executor-proxy.test.ts`, `provider-node-reserved-prefix.test.ts`, `combo-auto-candidate-expansion.test.ts`, `messages-count-tokens-route.test.ts`, `virtual-auto-combo.test.ts`: split into independent per-mechanism test blocks (established pattern); `virtual-auto-combo.test.ts`'s old "includes cookie web-session providers" positive-inclusion test (which used chatgpt-web as its example) was retired along with the provider and replaced by this PR's negative-exclusion test for the same slot. - `docs/architecture/ARCHITECTURE.md`, `CODEBASE_DOCUMENTATION.md` (+ 4 i18n mirrors), `README.md`, `FREE-TIERS-GUIDE.md`, `docs/diagrams/free-tier-budget.svg`, `docs/screenshots/free-tier-budget-card.svg`, `docs/reference/PROVIDER_REFERENCE.md`: recomputed every stale count from the real merged state — 104 executors (`countFiles` gate logic), 351 providers (regenerated via `gen:provider-reference`), 152/351 `hasFree` entries, 445/438/7 free-tier catalog rows, 13 ToS-avoid providers, budget-card regenerated via its real generator script. One doc conflict (`oauth/` module list) needed picking HEAD's side specifically — theirs still listed the already-removed `raycast` module instead of the real `openference`. - `config/quality/test-masking-allowlist.json`: additive merge of the PR's 17 `_deletedWithReplacement` entries alongside the batch's existing ones (one real duplicate-key mistake in my first pass, caught and fixed via a `object_pairs_hook` duplicate-key check before finalizing). Also fixed two real, unrelated-to-my-merge issues surfaced by the focused suite: - `tests/unit/resolve-web-provider-host.test.ts`: the PR's own test had a typo — it asserted `perplexity-web`'s resolved host as `"perplexity.ai"`, but the provider's registered `website` is `"https://www.perplexity.ai"` and the resolver returns the URL's `host` verbatim (no www-stripping), so the correct value is `"www.perplexity.ai"` (consistent with the same test's own `url` assertion). - `tests/unit/hard-session-lease-bypass-inventory.test.ts`: this golden call-site inventory was already stale on the pristine post-#11713 tip (confirmed via a throwaway probe worktree) — `src/lib/db/providers.ts`'s 3 connection-fallback sites and a third `src/app/api/providers/route.ts` site were never added to the golden list by the earlier-merged #11698/#11720 PRs. Updated it to the real current inventory (dated inline comments explain each delta and which PR introduced it), plus this PR's own legitimate deltas (image-edits duplicate-call removal, `ChatGptWebExecutor.execute()` site removed). Focused suite green (433/433 across executor-proxy, reserved-prefix, hard-session-lease-bypass-inventory, resolve-web-provider-host, retirement/runtime-block/source-retirement/management-retirement/image-handler-retirement, migration-168, combo-auto-candidate-expansion, virtual-auto-combo, executor-map-golden and siblings), plus `typecheck:core`, `check-file-size`, and `check-changelog-integrity` clean. Thanks for the thorough provenance-hold retirement work — appreciated.
93 lines
4.0 KiB
TypeScript
93 lines
4.0 KiB
TypeScript
// Reserved provider prefixes — single source of truth shared by:
|
|
//
|
|
// 1. The runtime model resolver guard (src/sse/services/model.ts): user-defined
|
|
// compatible-node prefixes must not be allowed to shadow built-in provider
|
|
// ids/aliases, otherwise a node with prefix="cf" would hijack cloudflare-ai
|
|
// requests (ported from upstream 9router 047fdc89).
|
|
// 2. The write-path validation schemas (createProviderNodeSchema /
|
|
// updateProviderNodeSchema in src/shared/validation/schemas/provider.ts):
|
|
// a prefix that the runtime will never honor must be rejected at creation
|
|
// time with a clear message instead of silently routing to the built-in
|
|
// provider (tokenrouter bug: "No active credentials for provider:
|
|
// tokenrouter" despite a fully configured compatible node).
|
|
//
|
|
// Semantics:
|
|
// - Live REGISTRY entry ids + aliases, plus exact retired provider ids that
|
|
// must remain unavailable after their registry entries are removed. Manual
|
|
// aliases outside REGISTRY (xiaomi/llamacpp/aq) do NOT intercept nodes at
|
|
// runtime and are therefore deliberately NOT reserved — including them would
|
|
// cause false-positive rejections.
|
|
// - Live REGISTRY entries remain case-sensitive. Retired ids use their retirement
|
|
// normalizer (trim + lowercase), so casing cannot revive a removed provider.
|
|
import { REGISTRY } from "@omniroute/open-sse/config/providerRegistry.ts";
|
|
|
|
import {
|
|
isMicrosoftDesignerWebRetiredProviderId,
|
|
RETIRED_MICROSOFT_DESIGNER_WEB_PROVIDER_IDS,
|
|
} from "@/shared/constants/designerWebRetirement";
|
|
import { isRuntimeRetiredProviderId, RUNTIME_RETIRED_PROVIDER_IDS } from "./providerRetirement";
|
|
import {
|
|
isCommonChatGptWebRetiredProviderId,
|
|
RETIRED_COMMON_CHATGPT_WEB_PROVIDER_IDS,
|
|
} from "@/shared/constants/chatgptWebRetirement";
|
|
|
|
let _reserved: Set<string> | null = null;
|
|
|
|
function buildReservedProviderPrefixes(): Set<string> {
|
|
if (_reserved) return _reserved;
|
|
const reserved = new Set<string>();
|
|
for (const entry of Object.values(REGISTRY)) {
|
|
if (entry?.id) reserved.add(entry.id);
|
|
if (entry?.alias) reserved.add(entry.alias);
|
|
}
|
|
for (const providerId of RETIRED_MICROSOFT_DESIGNER_WEB_PROVIDER_IDS) {
|
|
reserved.add(providerId);
|
|
}
|
|
for (const providerId of RUNTIME_RETIRED_PROVIDER_IDS) reserved.add(providerId);
|
|
for (const retiredId of RETIRED_COMMON_CHATGPT_WEB_PROVIDER_IDS) reserved.add(retiredId);
|
|
_reserved = reserved;
|
|
return reserved;
|
|
}
|
|
|
|
/**
|
|
* All canonical reserved provider prefixes (REGISTRY ids + aliases + retired
|
|
* provider tombstones). Built lazily so the registry is only walked once per
|
|
* process.
|
|
*/
|
|
export function getReservedProviderPrefixes(): ReadonlySet<string> {
|
|
return buildReservedProviderPrefixes();
|
|
}
|
|
|
|
/**
|
|
* Number of unique reserved prefixes (ids + aliases deduplicated). Exposed for
|
|
* tests/docs so counts are measured, not memorized.
|
|
*/
|
|
export const RESERVED_PREFIX_COUNT = buildReservedProviderPrefixes().size;
|
|
|
|
/**
|
|
* Frozen snapshot of the reserved set (test/documentation convenience). Prefer
|
|
* `isReservedProviderPrefix` / `getReservedProviderPrefixes` on hot paths.
|
|
*/
|
|
export const RESERVED_PROVIDER_PREFIXES: ReadonlySet<string> = getReservedProviderPrefixes();
|
|
|
|
/**
|
|
* True when `value` is a reserved provider prefix. Non-strings are never
|
|
* reserved (mirrors the runtime guard's typeof check).
|
|
*/
|
|
export function isReservedProviderPrefix(value: unknown): boolean {
|
|
return (
|
|
(typeof value === "string" && buildReservedProviderPrefixes().has(value)) ||
|
|
isMicrosoftDesignerWebRetiredProviderId(value) ||
|
|
isRuntimeRetiredProviderId(value) ||
|
|
isCommonChatGptWebRetiredProviderId(value)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Zod-friendly rejection message for a reserved prefix. Names the colliding
|
|
* prefix and tells the operator what to pick instead.
|
|
*/
|
|
export function reservedProviderPrefixMessage(value: string): string {
|
|
return `"${value}" is a reserved provider prefix — choose a different prefix (reserved ids/aliases cannot be used for custom nodes because requests like <prefix>/model route to a built-in provider or fail closed when retired)`;
|
|
}
|