mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* fix(gemini): preserve structured tool calls for antigravity * fix(gemini): parse prefixed textual tool calls * fix(antigravity): preserve textual SSE tool calls * fix(stream): normalize textual passthrough tool calls * fix(stream): normalize split textual tool calls * fix(stream): suppress malformed textual tool calls * fix(stream): suppress compact malformed tool calls * fix(stream): emit structured textual tool calls * fix(stream): suppress unknown textual tool calls * fix(stream): normalize responses textual tool calls * chore: ignore .claude/settings.local.json (per-user Claude Code permissions) * fix(opencode-go): route qwen3.x via claude messages + repair fixMissingToolResponses for Claude-shape upstreams (#2791) Integrated into release/v3.8.6 * fix: resolve npm install warnings — remove dead deps, relax engine constraint (#2792) Integrated into release/v3.8.6 * fix: register missing web-cookie validators (claude-web, gemini-web, copilot-web, t3-web) (#2793) Integrated into release/v3.8.6 * fix: Error: Unable to inspect existing database #2771 (#2795) Integrated into release/v3.8.6 * fix(oauth): repair Google loopback callback flow (#2796) Integrated into release/v3.8.6 * feat(logs): add clean history button (#2799) Integrated into release/v3.8.6 * [codex] home: restore settings-driven home layout and quota auto-refresh (#2800) Integrated into release/v3.8.6 * fix(gemini): emit signaturelessToolCallMode:text for GEMINI format models (#2801) Integrated into release/v3.8.6 * feat(modelSpecs): align opencode-go family with upstream provider limits (#2802) Integrated into release/v3.8.6 * chore: apply unit test fixes, polyfills, and environment precedence fixes * docs(agents): atualiza fluxos de release e triagem Expande os workflows de release para incluir auditoria de segurança, CHANGELOG completo por commits, quality gate obrigatório, homologação em VPS local, publicação oficial, deploy em Akamai e validação de artefatos. Reorganiza a triagem de features com arquivos permanentes por bucket, suporte a itens em andamento, regra de reclaim após 15 dias e novo tratamento para ideias viáveis catalogadas. Corrige a orientação de revisão de discussões para usar a ordem cronológica real dos comentários e respostas ao identificar a última atividade. * fix(lockout): classify Gemini Antigravity resource exhaustion as quota_exhausted * fix(reasoning): gate replay by interleaved field * docs(rule-16): permit human Co-authored-by, restrict only AI/bot trailers Rule #16 previously banned all `Co-Authored-By` trailers absolutely. That blocked the upstream-port workflows (`/port-upstream-features` and `/port-upstream-issues`), which must credit human upstream PR authors and issue reporters in OmniRoute commits. Refine the rule to ban only AI/bot-attributed trailers (Claude, GPT, Copilot, Bot; anthropic.com / openai.com / bot-owned noreply.github.com emails) while allowing standard human `Co-authored-by: Name <email>` attribution. Sync the rule across the source CLAUDE.md, the E2E shakedown doc note, and 41 i18n translations. * fix(gitlawb): add specialty validators for connection test — bypass /models probe GitLawB OpenGateway API (xiaomi-mimo compatible) does not expose a /models endpoint, causing validateOpenAILikeProvider to 404 on the initial probe and report 'Provider validation endpoint not supported'. Add specialty validators for both gitlawb and gitlawb-gmi that follow the same pattern as the existing xiaomi-mimo validator: skip GET /models, validate directly via POST /chat/completions with a minimal test message. Any 401/403 response means an invalid key; all other responses mean auth is OK. Fixes test-connection returning 404 for GitLawB providers. * test(gitlawb): add 12 unit tests for gitlawb and gitlawb-gmi specialty validators Covers success, auth failure (401/403), non-auth acceptance (400/422/429), network errors, and custom baseUrl overrides for both providers. * feat(gitlawb): serve models from static registry without API-unavailable warning GitLawB's OpenGateway API does not expose a /models endpoint per provider-path. Previously the models route fell through to the generic fallback which returned static catalog models with the misleading 'API unavailable — using local catalog' warning. Now gitlawb and gitlawb-gmi are handled as static model providers (same pattern as reka and qwen OAuth) — models are served from the provider registry without any warning, since all registered models are functional via POST /chat/completions. * refactor(gitlawb): extract shared opengateway validator factory, fix docs path in test - Extract gitlawb/gitlawb-gmi validators into buildOpengatewayValidator factory - Fix dockerignore-docs-coverage test: update stale docs/AUTO-COMBO.md -> docs/routing/AUTO-COMBO.md * fix(reasoning): guard interleaved capability lookup * feat(gitlawb): dynamic model fetch with gmi-cloud fallback Hybrid approach: - gitlawb (xiaomi-mimo): dynamic /models endpoint → 356 models - gitlawb-gmi (gmi-cloud): 404 fallback → local catalog gracefully Mimics Gitlawb/openclaude's model-routing pattern * i18n(pt-BR): complete missing translations and sync with en.json * feat(build): nix multi-OS package manager install (#2806) Integrated into release/v3.8.6 * fix(i18n): translate 144 new __MISSING__ pt-BR strings (#2816) Integrated into release/v3.8.6 * chore(docs): set coverage gate to 40/40/40/40 in CLAUDE.md Aligns the documented coverage gate with the v3.8.6 release decision (lowered from 75/75/75/70). Matches the threshold already set in package.json by the large feature PRs (planos 11-22). * fix(cli): respect PORT env var in serve command (#2845) Integrated into release/v3.8.6. * fix(deepseek-web): return 400 when client sends tools[] - chat.deepseek.com has no tool support (#2854) Integrated into release/v3.8.6. * fix(qoder): reject invalid/expired PATs returning Cosy 500 error (#2860) Integrated into release/v3.8.6. * fix(cli): register openclaw in tool-detector (#2833) (#2850) Integrated into release/v3.8.6. * fix(api): include noAuth providers in /v1/models catalog (#2798) (#2814) Integrated into release/v3.8.6. * fix(combo): resolve custom provider targets via combo name (#2778) (#2812) Integrated into release/v3.8.6. * fix(translator): strip safety_identifier in openai-responses cleanup (#2770) (#2809) Integrated into release/v3.8.6. * fix(quota): honor explicit per-connection preflight opt-out (#2831) (#2844) Integrated into release/v3.8.6. * fix(usage): un-invert GitHub Copilot Free/limited quota — limited_user_quotas is remaining (#2876) (#2881) Integrated into release/v3.8.6. * fix(nous-research): correct baseUrl to include /chat/completions (#2826) (#2835) Integrated into release/v3.8.6. * fix(opencode): qwen3.x max/plus models lack vision support (#2822) (#2836) Integrated into release/v3.8.6. * fix(translator): pass-through tool_search built-in tool type (#2766) (#2811) Integrated into release/v3.8.6. * fix(github): route claude-opus-4.6 via chat completions (#2821) Integrated into release/v3.8.6. * docs(oauth): add Windsurf login fix design (Phase 1 hotfix + Phase 2 Firebase OAuth) Two-phase plan to fix the broken Windsurf OAuth flow: - Phase 1: drop the dead app.devin.ai/editor/signin PKCE path, promote import-token from windsurf.com/show-auth-token as the primary path - Phase 2: port Firebase OAuth + RegisterUser flow from fendoushaonian/WindSurf-gRPC-API for full browser-based automation Spec only - no code changes yet. * docs(plan): Phase 1 windsurf login hotfix implementation plan 10 tasks covering: - TDD assertions for flowType + 410 Gone responses - Provider switch to import_token - Route handler retiring authorize/start-callback-server/poll-callback - OAuthModal UI override - i18n sync - Verification + PR steps * fix(cli): replace cli-table3 with hand-rolled formatter (#2752) (#2813) Integrated into release/v3.8.6. * fix(skills): skip interception for unregistered client-native tools (#2815) (#2817) Integrated into release/v3.8.6. * feat(sse): add RTK filters for kubectl, docker-build, composer, gh (#2824) Integrated into release/v3.8.6. * fix(geminiHelper): support rec.image content shape + warn on dropped remote URLs (refs #2807) (#2855) Integrated into release/v3.8.6. * fix(cli): allow nullable/optional apiKey in cliMitmStartSchema (#2857) Integrated into release/v3.8.6. * fix(combo): preserve system messages during context handoff summary generation (#2865) Integrated into release/v3.8.6. * fix: wire CLIProxyAPI fallback settings into chatCore routing engine (#2866) Integrated into release/v3.8.6. * fix(usage): add opencode quota fetcher (#2852) (#2867) Integrated into release/v3.8.6. * feat(claude): default xhigh support for newer Opus models (#2874) Integrated into release/v3.8.6. * fix(cli): restore omniroute logs command stream (#2756) (#2810) Integrated into release/v3.8.6. * fix(combo): normalize upstream Headers for Node 24 undici interop (#2751) (#2823) Integrated into release/v3.8.6. * Rename proxy log Public IP to Client IP (#2880) Integrated into release/v3.8.6. * fix(claude): preserve max effort for supported models (#2875) Integrated into release/v3.8.6. * fix(oauth): switch windsurf provider to import_token flow The PKCE auth URL targeting app.devin.ai/editor/signin returns 404 post-rebrand. Until Phase 2 ports Firebase OAuth + RegisterUser, the only supported path is import-token via windsurf.com/show-auth-token. - windsurf.ts: drop buildAuthUrl, set flowType=import_token - generateAuthData returns supported:false + helpful error for windsurf/devin-cli - tests: assert flowType + disabled stub * fix(oauth): return 410 Gone for retired windsurf/devin-cli PKCE actions start-callback-server, authorize, and poll-callback (GET + POST) now return 410 Gone with a pointer to /import-token. The 410 short-circuit runs before auth so the response is honest about the action being permanently gone, not gated. Codex PKCE flow unchanged. Tests: 5 new assertions cover GET + POST 410 paths and a Codex regression check. * refactor(oauth): annotate retired PKCE fields in WINDSURF_CONFIG No behaviour change - comment-only update documenting that authorizeUrl, codeChallengeMethod, callbackPort, callbackPath, apiServerUrl, and exchangePath are no longer consumed. Active fields (inferenceUrl, showAuthTokenUrl, firebaseApiKey, ideName) called out separately. * fix(cli,docs): use requireCliToolsAuth in logs route + document OPENCODE quota env Post-merge contract fixes for v3.8.6: - src/app/api/cli-tools/logs/route.ts (#2810) now uses the shared requireCliToolsAuth guard (param renamed req->request) to satisfy the cli-tools-auth-hardening contract test. - Document OMNIROUTE_OPENCODE_QUOTA_URL (#2867) in docs/reference/ENVIRONMENT.md to satisfy the env/docs sync contract. * fix(dashboard): force import-token panel for windsurf/devin-cli Phase 1 hotfix: hide the 'Browser Login' tab and start in Paste API Key mode. Removes windsurf/devin-cli from PKCE_CALLBACK_SERVER_PROVIDERS so no callback server is started for them. Codex still uses the PKCE flow. The 'Get token' link continues to point at windsurf.com/show-auth-token via the existing supportsTokenPaste form copy. * fix(oauth): windsurf import-token mapTokens signature mismatch The route at `src/app/api/oauth/[provider]/[action]/route.ts` invokes `providerData.mapTokens({ accessToken: token })` (object), matching the cursor/kiro signature. The windsurf provider was declared with `mapTokens(token: string)` instead, so the entire object was stored as `accessToken`. When the connection record reached the SQLite layer it crashed with: SQLite3 can only bind numbers, strings, bigints, buffers, and null Fix by aligning windsurf's `mapTokens` signature with the route caller and the cursor/kiro convention. Also dedupe a copy-pasted second `if (action === "import-token")` block in the route handler — the second block was unreachable but identical to the first. Adds two regression tests asserting that `provider.mapTokens({ accessToken })` returns a string `accessToken` for both windsurf and devin-cli, so a future signature drift trips the gate instead of the SQLite bind error in production. * feat(compression): expand pt-BR pack with troglodita rules (15 → 49) (#2818) Integrated into release/v3.8.6 * fix(sse): repair RTK engine defaults so dedup and direct calls work (#2825) Integrated into release/v3.8.6 * fix(mcp): redirect console.log/warn to stderr in --mcp stdio mode (#2840) Integrated into release/v3.8.6 * fix(gemini-cli): prefer real project IDs over default-project (#2841) Integrated into release/v3.8.6 * fix(opencode-go): add provider limits quota fetcher (#2861) Integrated into release/v3.8.6 * Audit & add web cookie providers: fix 4 missing registry entries + DuckDuckGo (#2862) Integrated into release/v3.8.6 * fix(antigravity): harden signatureless tool history (#2878) Integrated into release/v3.8.6 * fix: provider model sync pruning and dynamic antigravity MITM proxy mappings (#2886) Integrated into release/v3.8.6 * feat(usage): per-API-key token limits scoped to model/provider/global (#2888) Integrated into release/v3.8.6 * fix(audio): build multipart body manually to preserve Content-Type (#2842) Integrated into release/v3.8.6 * refactor: remove agent skill documentation files and streamline maintenance workflows * test(stabilization): resolve unit test failures in blackbox-web, schema-coercion, translator-helper-branches, usage-service-hardening, and audio-transcription * fix(security): mitigate Socket.dev supply-chain findings + secrets opt-in + minimal build profile (#2863) (#2871) Two real security gaps closed and four cosmetic Socket.dev fingerprints removed. See docs/security/SOCKET_DEV_FINDINGS.md for the per-finding maintainer attestation. Real bugs fixed: - cloudSync: HMAC verification of `X-Cloud-Sig` + opt-in `OMNIROUTE_CLOUD_SYNC_SECRETS=true` before overwriting `accessToken` / `refreshToken` / `providerSpecificData` from a remote response. Closes the silent-credential-swap surface (a misconfigured or hostile CLOUD_URL could previously replace local tokens unverified). - Zed import: split into 2-step `/discover` + `/import` flow. `/import` now requires `confirmedAccounts: [{ service, account, fingerprint }]` and re-reads the keychain server-side to filter by fingerprint, so a tampered discover response cannot trick the endpoint into saving an unrelated token. Cosmetic Socket.dev mitigations: - runElevatedPowerShell writes the elevated payload to a per-call temp `.ps1` file (mode 0o600) and references it via `-File`. Removes the textbook `-EncodedCommand <base64utf16le>` pattern flagged as malware by Socket's AI classifier. - Maintainer attestation `SECURITY-AUDITOR-NOTE:` blocks added at every flagged call site pointing to `docs/security/SOCKET_DEV_FINDINGS.md`. Build-time hardening: - `OMNIROUTE_BUILD_PROFILE=minimal` (`npm run build:secure`) physically removes the four sensitive modules from the standalone bundle via webpack `NormalModuleReplacementPlugin`. Stubs throw `FeatureDisabledError` at runtime. Intended for the `omniroute-secure` artifact. Tests: - 24 new unit tests in `tests/unit/security/` covering the wrapper builder, HMAC verification (4 cases), credential fingerprint determinism (5 cases), confirmedAccounts validation + fingerprint filtering (6 cases), and the minimal-build stubs (5 cases). Docs: - New `docs/security/SOCKET_DEV_FINDINGS.md` — per-finding attestation. - New `socket.yml` — Socket.dev v2 config pointing at the attestation. - Updated `SECURITY.md` — supply-chain scanner section. - Updated `.env.example` — three new env vars documented. Backwards compatibility: - Cloud sync token overwrite is OFF by default. Users who relied on it must set `OMNIROUTE_CLOUD_SYNC_SECRETS=true`. Breaking change documented in CHANGELOG. - Zed import 2-step is the new default; legacy 1-step preserved behind `OMNIROUTE_ZED_IMPORT_LEGACY_ONE_STEP=true` and will be removed in v3.9. Closes #2863 * fix(security): redact public Firebase Web key from windsurf spec; doc SHA-256 cache-key rationale (#2894) Two security-scanning findings on release/v3.8.6: - Secret-scanning alert 7 (google_api_key): the windsurf login-fix design spec embedded the literal public Firebase Web API key on two lines. Firebase Web API keys are non-sensitive by design (they identify the project; access is gated by Firebase Security Rules + key restrictions), but the literal trips secret scanning. Redacted to a placeholder; the embedded default still goes through resolvePublicCred per rule #11. - Code-scanning alert 261 (js/insufficient-password-hash): tokenCacheKey() uses SHA-256 to derive an in-memory cache key from the session token, not for password-at-rest storage. Added a comment documenting why CWE-916 KDFs do not apply (false positive). * fix(ci): resolve release/v3.8.6 gate failures (docs-sync, any-budget, pack-artifact) (#2895) * fix(ci): resolve release/v3.8.6 gate failures (docs-sync, any-budget, pack-artifact) Three CI gates failed on release/v3.8.6 (run 26630300877): - docs-sync: CHANGELOG had a spurious "## [3.8.6-patch]" section above "## [3.8.6]", so the latest release no longer matched package.json (3.8.6) and the 41 i18n CHANGELOG mirrors were flagged as missing that section. Fold the lone #2752 entry into [3.8.6] and drop the patch heading. - any-budget:t11: open-sse/handlers/chatCore.ts regressed to 1 explicit `any` (budget 0). Type the persist callback arg as Record<string, unknown>, which matches runWithOnPersist's RefreshPersistFn contract exactly. - pack-artifact: open-sse/utils/setupPolyfill.ts ships via package.json "files" (bin/omniroute.mjs imports it at startup) but was missing from the pack policy allowlist. Allow it and add a regression test. * fix(security): redact public Firebase Web key from windsurf spec Redact the literal public Firebase Web API key (secret-scanning #7) to a placeholder, mirroring the redaction on release/v3.8.6 (PR #2894) and the windsurf fix branch. Non-sensitive public Web key; trips secret scanning. * feat(combo): Zero-Latency Combos (Hedging, Proactive Compression, Predictive TTFT) (#2868) * feat(combo): implement zero-latency combo optimizations (hedging, proactive compression, predictive TTFT) * fix(combo): fix predictive TTFT skip logic and unhandled promise rejections --------- Co-authored-by: Automation <automation@omniroute> * feat: implement automated skill workflows and update system configuration and validation schemas * test: eliminate dynamic cast warnings in cloud-sync unit test * test: isolate services-branch-hardening database directory to avoid concurrency issues * feat(providers): add 7 new web-cookie providers + research catalog + discovery tool New providers: - huggingchat: free LLM chat via huggingface.co/chat (no subscription) - phind: free dev-focused AI chat via phind.com/api/agent - poe-web: multi-model chat via poe.com GraphQL (p-b cookie) - venice-web: privacy-focused AI chat via venice.ai (session cookie) - v0-vercel-web: Vercel v0 code gen via v0.dev (session cookie) - kimi-web: Moonshot Kimi chat via kimi.moonshot.cn (session cookie) - doubao-web: ByteDance Doubao chat via doubao.com (session cookie) Additional: - Research catalog: docs/research/UNLIMITED_LLM_ACCESS.md - Discovery tool design + stub: src/lib/discovery/ + migration 073 - Unit tests: 33 tests for all 7 providers - Shared helpers consolidated in error.ts (slop cleanup) - All registered in WEB_COOKIE_PROVIDERS + providerRegistry + webSessionCredentials Closes #2885 * fix(typecheck): resolve typecheck errors in combo spec and compression modules * feat(api,oauth): add `agy` (Antigravity CLI) standalone provider with CLI token import (#2899) Add a standalone OAuth provider `agy` (Antigravity CLI) next to gemini-cli/antigravity. It reuses the antigravity inference backend (identical Google client_id + daily-cloudcode-pa.googleapis.com endpoint, executor and token-refresh) but ships its own model catalog — including the Claude models the backend exposes (claude-opus-4-6-thinking, claude-sonnet-4-6) — its own account pool, and four ways to connect: - token-file import (paste/upload the agy oauth token JSON) - auto-detect a local CLI login (~/.gemini/antigravity-cli/antigravity-oauth-token) - browser OAuth (via the shared OAuthModal Google loopback flow) - bulk / ZIP import New routes: POST /api/providers/agy-auth/{import,import-bulk,zip-extract,apply-local}. Catalog pinned from the live :fetchAvailableModels endpoint. Docs (openapi.yaml, ENVIRONMENT.md, .env.example, CHANGELOG) updated; new unit tests for registration, the token parser, and route auth-hardening. * fix(security): redact public Firebase Web key from windsurf spec (#2896) Redact the literal public Firebase Web API key (secret-scanning #7) to a placeholder. Firebase Web API keys are non-sensitive by design but the literal trips GitHub secret scanning. Mirrors the redaction landed on release/v3.8.6 (PR #2894). Embedded default still flows through resolvePublicCred (rule #11). * Pr 2871 (#2897) * fix(security): mitigate Socket.dev supply-chain findings + secrets opt-in + minimal build profile (#2863) Two real security gaps closed and four cosmetic Socket.dev fingerprints removed. See docs/security/SOCKET_DEV_FINDINGS.md for the per-finding maintainer attestation. Real bugs fixed: - cloudSync: HMAC verification of `X-Cloud-Sig` + opt-in `OMNIROUTE_CLOUD_SYNC_SECRETS=true` before overwriting `accessToken` / `refreshToken` / `providerSpecificData` from a remote response. Closes the silent-credential-swap surface (a misconfigured or hostile CLOUD_URL could previously replace local tokens unverified). - Zed import: split into 2-step `/discover` + `/import` flow. `/import` now requires `confirmedAccounts: [{ service, account, fingerprint }]` and re-reads the keychain server-side to filter by fingerprint, so a tampered discover response cannot trick the endpoint into saving an unrelated token. Cosmetic Socket.dev mitigations: - runElevatedPowerShell writes the elevated payload to a per-call temp `.ps1` file (mode 0o600) and references it via `-File`. Removes the textbook `-EncodedCommand <base64utf16le>` pattern flagged as malware by Socket's AI classifier. - Maintainer attestation `SECURITY-AUDITOR-NOTE:` blocks added at every flagged call site pointing to `docs/security/SOCKET_DEV_FINDINGS.md`. Build-time hardening: - `OMNIROUTE_BUILD_PROFILE=minimal` (`npm run build:secure`) physically removes the four sensitive modules from the standalone bundle via webpack `NormalModuleReplacementPlugin`. Stubs throw `FeatureDisabledError` at runtime. Intended for the `omniroute-secure` artifact. Tests: - 24 new unit tests in `tests/unit/security/` covering the wrapper builder, HMAC verification (4 cases), credential fingerprint determinism (5 cases), confirmedAccounts validation + fingerprint filtering (6 cases), and the minimal-build stubs (5 cases). Docs: - New `docs/security/SOCKET_DEV_FINDINGS.md` — per-finding attestation. - New `socket.yml` — Socket.dev v2 config pointing at the attestation. - Updated `SECURITY.md` — supply-chain scanner section. - Updated `.env.example` — three new env vars documented. Backwards compatibility: - Cloud sync token overwrite is OFF by default. Users who relied on it must set `OMNIROUTE_CLOUD_SYNC_SECRETS=true`. Breaking change documented in CHANGELOG. - Zed import 2-step is the new default; legacy 1-step preserved behind `OMNIROUTE_ZED_IMPORT_LEGACY_ONE_STEP=true` and will be removed in v3.9. Closes #2863 * feat: implement automated skill workflows and update system configuration and validation schemas * test: eliminate dynamic cast warnings in cloud-sync unit test * test: isolate services-branch-hardening database directory to avoid concurrency issues * chore(docs): refresh generated docs collection index Update the generated Fumadocs browser collection mapping to keep documentation imports in sync with the current docs structure. * docs: update generated browser docs collection manifest Refresh the generated Fumadocs browser collection mapping so the docs site can resolve the current documentation files correctly. --------- Co-authored-by: OpenClaw <openclaw@kuzhomesrv.local> Co-authored-by: Dmitry Kuznetsov <139351986+dmitry@users.noreply.local> Co-authored-by: KuzyaBot <kuzya@local> Co-authored-by: JeferssonLemes <jeferssondev@gmail.com> Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com> Co-authored-by: Markus Hartung <mail@hartmark.se> Co-authored-by: akarray <akarray@users.noreply.github.com> Co-authored-by: Apostol Apostolov <theapoapostolov@gmail.com> Co-authored-by: Hernan Javier Ardila Sanchez <hjasgr@gmail.com> Co-authored-by: Dmitry Kuznetsov <dmitry@kuznetsov.me> Co-authored-by: Nikolay Alafuzov <alafuzov_nn@rusklimat.ru> Co-authored-by: oyi77 <oyi77@users.noreply.github.com> Co-authored-by: Ronaldo Davi <alltomatos@users.noreply.github.com> Co-authored-by: levonk <277861+levonk@users.noreply.github.com> Co-authored-by: Lenine Júnior <lenine@engrene.com.br> Co-authored-by: Annas Alghoffar <aag.annas@gmail.com> Co-authored-by: Tushar Agarwal <76201310+Tushar49@users.noreply.github.com> Co-authored-by: GreatLiu <eurasiaxz@qq.com> Co-authored-by: yuna amelia <230527278+yunaamelia@users.noreply.github.com> Co-authored-by: Randi <55005611+rdself@users.noreply.github.com> Co-authored-by: Container <78986709+disonjer@users.noreply.github.com> Co-authored-by: nickwizard <35692452+nickwizard@users.noreply.github.com> Co-authored-by: Rajvardhan Patil <rajvardhanpatil7890@gmail.com> Co-authored-by: Raxxoor <manker_lol@hotmail.com> Co-authored-by: Muhammad Mugni Hadi <mugnimaestra3@gmail.com> Co-authored-by: mi <123757457+soyelmismo@users.noreply.github.com> Co-authored-by: Automation <automation@omniroute>
1361 lines
46 KiB
TypeScript
1361 lines
46 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-model-catalog-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "catalog-test-secret";
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const modelsDb = await import("../../src/lib/db/models.ts");
|
|
const combosDb = await import("../../src/lib/db/combos.ts");
|
|
const settingsDb = await import("../../src/lib/db/settings.ts");
|
|
const apiKeysDb = await import("../../src/lib/db/apiKeys.ts");
|
|
const modelsDevSync = await import("../../src/lib/modelsDevSync.ts");
|
|
const v1ModelsCatalog = await import("../../src/app/api/v1/models/catalog.ts");
|
|
|
|
async function resetStorage() {
|
|
core.resetDbInstance();
|
|
apiKeysDb.resetApiKeyState();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
async function seedConnection(provider: string, overrides: Record<string, unknown> = {}) {
|
|
return providersDb.createProviderConnection({
|
|
provider,
|
|
authType: (overrides.authType as string) || "apikey",
|
|
name: (overrides.name as string) || `${provider}-${Math.random().toString(16).slice(2, 8)}`,
|
|
apiKey: (overrides.apiKey as string) || "sk-test",
|
|
accessToken: overrides.accessToken as string | undefined,
|
|
isActive: (overrides.isActive as boolean) ?? true,
|
|
testStatus: (overrides.testStatus as string) || "active",
|
|
providerSpecificData: (overrides.providerSpecificData as Record<string, unknown>) || {},
|
|
});
|
|
}
|
|
|
|
function capability(overrides = {}) {
|
|
return {
|
|
tool_call: null,
|
|
reasoning: null,
|
|
attachment: null,
|
|
structured_output: null,
|
|
temperature: null,
|
|
modalities_input: JSON.stringify([]),
|
|
modalities_output: JSON.stringify([]),
|
|
knowledge_cutoff: null,
|
|
release_date: null,
|
|
last_updated: null,
|
|
status: null,
|
|
family: null,
|
|
open_weights: null,
|
|
limit_context: null,
|
|
limit_input: null,
|
|
limit_output: null,
|
|
interleaved_field: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test.beforeEach(async () => {
|
|
await resetStorage();
|
|
});
|
|
|
|
test.after(async () => {
|
|
core.resetDbInstance();
|
|
apiKeysDb.resetApiKeyState();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
});
|
|
|
|
test("v1 models catalog requires auth when the route is protected and login is enabled", async () => {
|
|
await settingsDb.updateSettings({
|
|
requireLogin: true,
|
|
password: "hashed-password",
|
|
requireAuthForModels: true,
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
|
|
assert.equal(response.status, 401);
|
|
assert.equal(body.error.code, "invalid_api_key");
|
|
assert.match(body.error.message, /Authentication required/i);
|
|
});
|
|
|
|
test("v1 models catalog accepts bearer API keys and filters the list by allowed model patterns", async () => {
|
|
await settingsDb.updateSettings({
|
|
requireLogin: true,
|
|
password: "hashed-password",
|
|
requireAuthForModels: true,
|
|
});
|
|
await seedConnection("openai", { name: "openai-main" });
|
|
await seedConnection("claude", {
|
|
authType: "oauth",
|
|
name: "claude-main",
|
|
apiKey: null,
|
|
accessToken: "claude-access",
|
|
});
|
|
|
|
const key = await apiKeysDb.createApiKey("catalog-filter", "machine-catalog");
|
|
await apiKeysDb.updateApiKeyPermissions(key.id, {
|
|
allowedModels: ["openai/*"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models", {
|
|
headers: { Authorization: `Bearer ${key.key}` },
|
|
})
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids = body.data.map((item) => item.id);
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(ids.some((id) => id.startsWith("openai/")));
|
|
assert.equal(
|
|
ids.some((id) => id.startsWith("claude/") || id.startsWith("cc/")),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog hides models excluded by every active connection while keeping models served by at least one account", async () => {
|
|
const first = await seedConnection("openai", {
|
|
name: "openai-first",
|
|
providerSpecificData: {
|
|
excludedModels: ["gpt-5.4*"],
|
|
},
|
|
});
|
|
const second = await seedConnection("openai", {
|
|
name: "openai-second",
|
|
providerSpecificData: {
|
|
excludedModels: ["gpt-4.1*"],
|
|
},
|
|
});
|
|
|
|
let response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
let body = (await response.json()) as any;
|
|
let ids = new Set(body.data.map((item) => item.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(ids.has("openai/gpt-5.4-mini"), true);
|
|
|
|
await providersDb.updateProviderConnection((second as any).id, {
|
|
providerSpecificData: {
|
|
excludedModels: ["gpt-5.4*"],
|
|
},
|
|
});
|
|
|
|
response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
body = (await response.json()) as any;
|
|
ids = new Set(body.data.map((item) => item.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(ids.has("openai/gpt-5.4-mini"), false);
|
|
|
|
await providersDb.updateProviderConnection((first as any).id, {
|
|
providerSpecificData: {
|
|
excludedModels: [],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("v1 models catalog includes combos and custom models while excluding hidden models and blocked providers", async () => {
|
|
await settingsDb.updateSettings({
|
|
blockedProviders: ["claude"],
|
|
});
|
|
await seedConnection("openai", { name: "openai-visible" });
|
|
await seedConnection("claude", {
|
|
authType: "oauth",
|
|
name: "claude-blocked",
|
|
apiKey: null,
|
|
accessToken: "claude-access",
|
|
});
|
|
await seedConnection("kiro", {
|
|
authType: "oauth",
|
|
name: "kiro-custom",
|
|
apiKey: null,
|
|
accessToken: "kiro-access",
|
|
});
|
|
|
|
modelsDb.mergeModelCompatOverride("openai", "gpt-4o-mini", { isHidden: true });
|
|
await modelsDb.addCustomModel("kiro", "custom-kiro", "Custom Kiro");
|
|
await combosDb.createCombo({
|
|
name: "team-router",
|
|
strategy: "priority",
|
|
models: ["openai/gpt-4o"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids = new Set(body.data.map((item) => item.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(ids.has("team-router"));
|
|
assert.ok(ids.has("kr/custom-kiro"));
|
|
assert.ok(ids.has("kiro/custom-kiro"));
|
|
assert.equal(ids.has("openai/gpt-4o-mini"), false);
|
|
assert.equal(
|
|
[...ids].some((id) => (id as any).startsWith("claude/") || (id as any).startsWith("cc/")),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog keeps only visible combos when no providers are active", async () => {
|
|
const visible = await combosDb.createCombo({
|
|
name: "visible-combo",
|
|
strategy: "priority",
|
|
models: ["openai/gpt-4o"],
|
|
});
|
|
await combosDb.updateCombo((visible as any).id, { context_length: 32000 });
|
|
const hidden = await combosDb.createCombo({
|
|
name: "hidden-combo",
|
|
strategy: "priority",
|
|
models: ["openai/gpt-4o"],
|
|
isHidden: true,
|
|
});
|
|
const inactive = await combosDb.createCombo({
|
|
name: "inactive-combo",
|
|
strategy: "priority",
|
|
models: ["openai/gpt-4o"],
|
|
});
|
|
await combosDb.updateCombo((inactive as any).id, { isActive: false });
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
|
|
assert.equal(response.status, 200);
|
|
// The visible combo must be present (noAuth provider models may also appear — that is correct
|
|
// behavior after the fix for Issue #2798, so we check membership rather than exact equality).
|
|
const ids = body.data.map((item) => item.id);
|
|
assert.ok(ids.includes(visible.name), "visible combo must appear");
|
|
const visibleCombo = body.data.find((item) => item.id === visible.name);
|
|
assert.ok(visibleCombo, "visible combo entry must exist");
|
|
assert.equal(visibleCombo.context_length, 32000);
|
|
assert.equal(
|
|
body.data.some((item) => item.id === hidden.name),
|
|
false
|
|
);
|
|
assert.equal(
|
|
body.data.some((item) => item.id === inactive.name),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog derives combo metadata from known targets conservatively", async () => {
|
|
try {
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
openai: {
|
|
"combo-alpha": capability({
|
|
tool_call: true,
|
|
reasoning: true,
|
|
attachment: true,
|
|
structured_output: true,
|
|
temperature: false,
|
|
modalities_input: JSON.stringify(["text", "image"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 1000,
|
|
limit_input: 900,
|
|
limit_output: 120,
|
|
}),
|
|
},
|
|
gemini: {
|
|
"combo-beta": capability({
|
|
tool_call: true,
|
|
reasoning: true,
|
|
attachment: false,
|
|
structured_output: true,
|
|
temperature: false,
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 800,
|
|
limit_input: 700,
|
|
limit_output: 90,
|
|
}),
|
|
},
|
|
});
|
|
|
|
await combosDb.createCombo({
|
|
name: "metadata-router",
|
|
strategy: "priority",
|
|
models: ["openai/combo-alpha", "gemini/combo-beta"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const combo = body.data.find((item) => item.id === "metadata-router");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(combo);
|
|
assert.equal(combo.context_length, 800);
|
|
assert.equal(combo.max_input_tokens, 700);
|
|
assert.equal(combo.max_output_tokens, 90);
|
|
assert.deepEqual(combo.input_modalities, ["text"]);
|
|
assert.deepEqual(combo.output_modalities, ["text"]);
|
|
assert.equal(combo.capabilities.structured_output, true);
|
|
assert.equal(combo.capabilities.temperature, false);
|
|
assert.equal(combo.capabilities.tool_calling, true);
|
|
assert.equal(combo.capabilities.reasoning, true);
|
|
assert.equal(combo.capabilities.thinking, true);
|
|
assert.equal("vision" in combo.capabilities, false);
|
|
assert.equal("attachment" in combo.capabilities, false);
|
|
assert.equal("architecture" in combo, false);
|
|
assert.equal("top_provider" in combo, false);
|
|
assert.equal("supported_parameters" in combo, false);
|
|
} finally {
|
|
modelsDevSync.saveModelsDevCapabilities({});
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog lets explicit combo context override derived context", async () => {
|
|
try {
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
openai: {
|
|
"context-alpha": capability({
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 1000,
|
|
limit_input: 900,
|
|
limit_output: 120,
|
|
}),
|
|
},
|
|
gemini: {
|
|
"context-beta": capability({
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 800,
|
|
limit_input: 700,
|
|
limit_output: 90,
|
|
}),
|
|
},
|
|
});
|
|
|
|
const combo = await combosDb.createCombo({
|
|
name: "context-router",
|
|
strategy: "priority",
|
|
models: ["openai/context-alpha", "gemini/context-beta"],
|
|
});
|
|
await combosDb.updateCombo((combo as any).id, { context_length: 12345 });
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const listed = body.data.find((item) => item.id === "context-router");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(listed.context_length, 12345);
|
|
assert.equal(listed.max_input_tokens, 700);
|
|
assert.equal(listed.max_output_tokens, 90);
|
|
} finally {
|
|
modelsDevSync.saveModelsDevCapabilities({});
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog keeps unknown combo targets visible without guessed metadata", async () => {
|
|
await combosDb.createCombo({
|
|
name: "unknown-router",
|
|
strategy: "priority",
|
|
models: ["openai/no-known-metadata"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const combo = body.data.find((item) => item.id === "unknown-router");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(combo);
|
|
assert.equal("context_length" in combo, false);
|
|
assert.equal("max_input_tokens" in combo, false);
|
|
assert.equal("max_output_tokens" in combo, false);
|
|
assert.equal("input_modalities" in combo, false);
|
|
assert.equal("output_modalities" in combo, false);
|
|
assert.equal("capabilities" in combo, false);
|
|
});
|
|
|
|
test("v1 models catalog aggregates nested combos and keeps hidden child combos unlisted", async () => {
|
|
try {
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
openai: {
|
|
"nested-alpha": capability({
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 1000,
|
|
limit_input: 900,
|
|
limit_output: 120,
|
|
}),
|
|
},
|
|
gemini: {
|
|
"nested-beta": capability({
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 800,
|
|
limit_input: 700,
|
|
limit_output: 90,
|
|
}),
|
|
},
|
|
});
|
|
|
|
await combosDb.createCombo({
|
|
name: "hidden-child-router",
|
|
strategy: "priority",
|
|
models: ["openai/nested-alpha", "gemini/nested-beta"],
|
|
isHidden: true,
|
|
});
|
|
await combosDb.createCombo({
|
|
name: "parent-router",
|
|
strategy: "priority",
|
|
models: ["hidden-child-router"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const parent = body.data.find((item) => item.id === "parent-router");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(parent);
|
|
assert.equal(parent.context_length, 800);
|
|
assert.equal(parent.max_output_tokens, 90);
|
|
assert.equal(
|
|
body.data.some((item) => item.id === "hidden-child-router"),
|
|
false
|
|
);
|
|
} finally {
|
|
modelsDevSync.saveModelsDevCapabilities({});
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog resolves provider aliases without corrupting slashful model ids", async () => {
|
|
try {
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
claude: {
|
|
"alias-model": capability({
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 2000,
|
|
limit_input: 1900,
|
|
limit_output: 200,
|
|
}),
|
|
},
|
|
openrouter: {
|
|
"Qwen/Qwen3-Coder": capability({
|
|
modalities_input: JSON.stringify(["text"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
limit_context: 1600,
|
|
limit_input: 1500,
|
|
limit_output: 150,
|
|
}),
|
|
},
|
|
});
|
|
|
|
await combosDb.createCombo({
|
|
name: "alias-and-slash-router",
|
|
strategy: "priority",
|
|
models: [
|
|
{ kind: "model", providerId: "claude", model: "cc/alias-model" },
|
|
{ kind: "model", providerId: "openrouter", model: "Qwen/Qwen3-Coder" },
|
|
],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const combo = body.data.find((item) => item.id === "alias-and-slash-router");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(combo);
|
|
assert.equal(combo.context_length, 1600);
|
|
assert.equal(combo.max_input_tokens, 1500);
|
|
assert.equal(combo.max_output_tokens, 150);
|
|
} finally {
|
|
modelsDevSync.saveModelsDevCapabilities({});
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog does not final-enrich combo names as real models", async () => {
|
|
await combosDb.createCombo({
|
|
name: "gpt-5.5",
|
|
strategy: "priority",
|
|
models: ["openai/no-known-metadata"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const combo = body.data.find((item) => item.id === "gpt-5.5");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(combo);
|
|
assert.equal(combo.owned_by, "combo");
|
|
assert.equal("max_output_tokens" in combo, false);
|
|
assert.equal("capabilities" in combo, false);
|
|
});
|
|
|
|
test("v1 models catalog exposes claude alias and provider-prefixed built-in models with vision metadata", async () => {
|
|
await seedConnection("claude", {
|
|
authType: "oauth",
|
|
name: "claude-vision",
|
|
apiKey: null,
|
|
accessToken: "claude-access",
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const aliasModel = body.data.find((item) => item.id === "cc/claude-sonnet-4-6");
|
|
const providerModel = body.data.find((item) => item.id === "claude/claude-sonnet-4-6");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(aliasModel);
|
|
assert.ok(providerModel);
|
|
assert.equal(providerModel.parent, aliasModel.id);
|
|
assert.equal(aliasModel.capabilities?.vision, true);
|
|
assert.deepEqual(aliasModel.input_modalities, ["text", "image"]);
|
|
assert.deepEqual(aliasModel.output_modalities, ["text"]);
|
|
});
|
|
|
|
test("v1 models catalog exposes refreshed GitHub Copilot aliases and drops retired models", async () => {
|
|
await seedConnection("github", {
|
|
authType: "oauth",
|
|
name: "github-current",
|
|
apiKey: null,
|
|
accessToken: "github-access",
|
|
providerSpecificData: {
|
|
copilotToken: "copilot-token",
|
|
},
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const aliasModel = body.data.find((item) => item.id === "gh/gpt-5.4");
|
|
const providerModel = body.data.find((item) => item.id === "github/gpt-5.4");
|
|
const codexModel = body.data.find((item) => item.id === "gh/gpt-5.3-codex");
|
|
const opusModel = body.data.find((item) => item.id === "github/claude-opus-4.7");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(aliasModel);
|
|
assert.ok(providerModel);
|
|
assert.ok(codexModel);
|
|
assert.ok(opusModel);
|
|
assert.equal(providerModel.parent, aliasModel.id);
|
|
assert.equal(
|
|
body.data.some((item) => item.id === "gh/gpt-5.1"),
|
|
false
|
|
);
|
|
assert.equal(
|
|
body.data.some((item) => item.id === "gh/claude-opus-4.1"),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog exposes bare Codex-preferred IDs for native Codex clients", async () => {
|
|
await seedConnection("codex", {
|
|
authType: "oauth",
|
|
name: "codex-native",
|
|
apiKey: null,
|
|
accessToken: "codex-access",
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const getModel = (id: string) => body.data.find((item) => item.id === id);
|
|
|
|
assert.equal(response.status, 200);
|
|
const modelId = "codex-auto-review";
|
|
const bareModel = getModel(modelId);
|
|
const providerModel = getModel(`codex/${modelId}`);
|
|
const aliasModel = getModel(`cx/${modelId}`);
|
|
const openAiModel = getModel(`openai/${modelId}`);
|
|
|
|
assert.ok(bareModel, `expected bare ${modelId} model`);
|
|
assert.ok(providerModel, `expected codex/${modelId} model`);
|
|
assert.ok(aliasModel, `expected cx/${modelId} model`);
|
|
assert.equal(openAiModel, undefined);
|
|
assert.equal(bareModel.owned_by, "codex");
|
|
assert.equal(bareModel.parent, providerModel.id);
|
|
assert.equal(providerModel.parent, aliasModel.id);
|
|
});
|
|
|
|
test("v1 models catalog exposes Antigravity client-visible preview aliases instead of upstream internal IDs", async () => {
|
|
await seedConnection("antigravity", {
|
|
authType: "oauth",
|
|
name: "antigravity-preview",
|
|
apiKey: null,
|
|
accessToken: "antigravity-access",
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids = new Set(body.data.map((item) => item.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(ids.has("antigravity/gemini-3-pro-preview"));
|
|
assert.ok(ids.has("antigravity/gemini-3-flash-preview"));
|
|
assert.equal(ids.has("antigravity/gemini-3.1-pro-high"), false);
|
|
assert.equal(ids.has("antigravity/gemini-claude-sonnet-4-5"), false);
|
|
assert.equal(ids.has("antigravity/gemini-claude-sonnet-4-5-thinking"), false);
|
|
assert.equal(ids.has("antigravity/gemini-claude-opus-4-5-thinking"), false);
|
|
});
|
|
|
|
test("v1 models catalog uses provider-node prefixes for compatible provider custom models", async () => {
|
|
await providersDb.createProviderNode({
|
|
id: "anthropic-compatible-demo",
|
|
type: "anthropic-compatible",
|
|
name: "Anthropic Demo",
|
|
prefix: "cm",
|
|
baseUrl: "https://proxy.example.com",
|
|
chatPath: "/v1/messages",
|
|
modelsPath: "/v1/models",
|
|
});
|
|
await seedConnection("anthropic-compatible-demo", {
|
|
name: "anthropic-node",
|
|
providerSpecificData: {
|
|
baseUrl: "https://proxy.example.com",
|
|
chatPath: "/v1/messages",
|
|
modelsPath: "/v1/models",
|
|
},
|
|
});
|
|
await modelsDb.addCustomModel("anthropic-compatible-demo", "claude-edge", "Claude Edge");
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids = new Set(body.data.map((item) => item.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(ids.has("cm/claude-edge"));
|
|
assert.equal(ids.has("anthropic-compatible-demo/claude-edge"), false);
|
|
});
|
|
|
|
test("v1 models catalog includes synced Gemini models and duplicates audio models for speech", async () => {
|
|
const connection = await seedConnection("gemini", {
|
|
name: "gemini-synced",
|
|
apiKey: "gm-key",
|
|
});
|
|
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection(
|
|
"gemini" as any,
|
|
(connection as any).id,
|
|
[
|
|
{
|
|
id: "gemini-audio-live",
|
|
name: "Gemini Audio Live",
|
|
source: "imported",
|
|
supportedEndpoints: ["audio"],
|
|
inputTokenLimit: 4096,
|
|
},
|
|
{
|
|
id: "text-embedding-004",
|
|
name: "Text Embedding 004",
|
|
source: "imported",
|
|
supportedEndpoints: ["embeddings"],
|
|
inputTokenLimit: 2048,
|
|
},
|
|
{
|
|
id: "gemini-hidden",
|
|
name: "Gemini Hidden",
|
|
source: "imported",
|
|
supportedEndpoints: ["chat"],
|
|
},
|
|
]
|
|
);
|
|
modelsDb.mergeModelCompatOverride("gemini", "gemini-hidden", { isHidden: true });
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const audioVariants = body.data.filter((item) => item.id === "gemini/gemini-audio-live");
|
|
const embedding = body.data.find((item) => item.id === "gemini/text-embedding-004");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(audioVariants.length, 2);
|
|
assert.deepEqual(audioVariants.map((item) => item.subtype).sort(), ["speech", "transcription"]);
|
|
assert.equal(embedding.type, "embedding");
|
|
assert.equal(
|
|
body.data.some((item) => item.id === "gemini/gemini-hidden"),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog keeps Gemini chat models untyped when synced endpoints are omitted", async () => {
|
|
const connection = await seedConnection("gemini", {
|
|
name: "gemini-chat-default",
|
|
apiKey: "gm-chat-key",
|
|
});
|
|
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection("gemini", (connection as any).id, [
|
|
{
|
|
id: "gemini-2.5-pro-live",
|
|
name: "Gemini 2.5 Pro Live",
|
|
source: "imported",
|
|
inputTokenLimit: 8192,
|
|
},
|
|
]);
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const chatModel = body.data.find((item) => item.id === "gemini/gemini-2.5-pro-live");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(chatModel);
|
|
assert.equal("type" in chatModel, false);
|
|
assert.equal("supported_endpoints" in chatModel, false);
|
|
assert.equal(chatModel.context_length, 8192);
|
|
});
|
|
|
|
test("v1 models catalog includes synced non-Gemini provider models from discovery cache", async () => {
|
|
const connection = await seedConnection("opencode-go", {
|
|
name: "opencode-go-synced",
|
|
apiKey: "go-key",
|
|
});
|
|
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection("opencode-go", (connection as any).id, [
|
|
{
|
|
id: "glm-5.1",
|
|
name: "GLM 5.1",
|
|
source: "imported",
|
|
supportedEndpoints: ["chat"],
|
|
inputTokenLimit: 262144,
|
|
},
|
|
]);
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const syncedModel = body.data.find((item) => item.id === "opencode-go/glm-5.1");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(syncedModel);
|
|
assert.equal(syncedModel.owned_by, "opencode-go");
|
|
assert.equal(syncedModel.context_length, 262144);
|
|
});
|
|
|
|
test("v1 models catalog includes media, moderation, rerank, video, and music models for active providers", async () => {
|
|
await seedConnection("openai", { name: "openai-media" });
|
|
await seedConnection("cohere", { name: "cohere-rerank" });
|
|
await seedConnection("comfyui", {
|
|
name: "comfy-media",
|
|
apiKey: null,
|
|
accessToken: null,
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const byId = new Map(body.data.map((item) => [item.id, item]));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal((byId.get("openai/gpt-image-2") as any).type, "image");
|
|
assert.equal((byId.get("openai/whisper-1") as any).type, "audio");
|
|
assert.equal((byId.get("openai/whisper-1") as any).subtype, "transcription");
|
|
assert.equal((byId.get("openai/omni-moderation-latest") as any).type, "moderation");
|
|
assert.equal((byId.get("cohere/rerank-v3.5") as any).type, "rerank");
|
|
assert.equal((byId.get("comfyui/animatediff") as any).type, "video");
|
|
assert.equal((byId.get("comfyui/stable-audio-open") as any).type, "music");
|
|
});
|
|
|
|
test("v1 models catalog does not duplicate imported Jina specialty models", async () => {
|
|
const connection = await seedConnection("jina-ai", {
|
|
name: "jina-synced",
|
|
apiKey: "jina-key",
|
|
});
|
|
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection("jina-ai", (connection as any).id, [
|
|
{
|
|
id: "jina-embeddings-v5-text-small",
|
|
name: "Jina Embeddings v5 Text Small",
|
|
source: "imported",
|
|
apiFormat: "embeddings",
|
|
supportedEndpoints: ["embeddings"],
|
|
},
|
|
{
|
|
id: "jina-reranker-v3",
|
|
name: "Jina Reranker v3",
|
|
source: "imported",
|
|
apiFormat: "rerank",
|
|
supportedEndpoints: ["rerank"],
|
|
},
|
|
]);
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const visibleJinaEmbeddingRows = body.data.filter(
|
|
(item) =>
|
|
item.owned_by === "jina-ai" &&
|
|
item.root === "jina-embeddings-v5-text-small" &&
|
|
item.type === "embedding" &&
|
|
!item.parent
|
|
);
|
|
const visibleJinaRerankRows = body.data.filter(
|
|
(item) =>
|
|
item.owned_by === "jina-ai" &&
|
|
item.root === "jina-reranker-v3" &&
|
|
item.type === "rerank" &&
|
|
!item.parent
|
|
);
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(visibleJinaEmbeddingRows.length, 1);
|
|
assert.equal(visibleJinaEmbeddingRows[0].id, "jina/jina-embeddings-v5-text-small");
|
|
assert.equal(visibleJinaRerankRows.length, 1);
|
|
assert.equal(visibleJinaRerankRows[0].id, "jina/jina-reranker-v3");
|
|
});
|
|
|
|
test("v1 models catalog does not duplicate custom Jina specialty models", async () => {
|
|
await seedConnection("jina-ai", {
|
|
name: "jina-custom",
|
|
apiKey: "jina-key",
|
|
});
|
|
await modelsDb.addCustomModel(
|
|
"jina-ai",
|
|
"jina-embeddings-v5-text-small",
|
|
"Jina Embeddings v5 Text Small",
|
|
"imported",
|
|
"embeddings",
|
|
["embeddings"]
|
|
);
|
|
await modelsDb.addCustomModel(
|
|
"jina-ai",
|
|
"jina-reranker-v3",
|
|
"Jina Reranker v3",
|
|
"imported",
|
|
"rerank",
|
|
["rerank"]
|
|
);
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const visibleJinaEmbeddingRows = body.data.filter(
|
|
(item) =>
|
|
item.owned_by === "jina-ai" &&
|
|
item.root === "jina-embeddings-v5-text-small" &&
|
|
item.type === "embedding" &&
|
|
!item.parent
|
|
);
|
|
const visibleJinaRerankRows = body.data.filter(
|
|
(item) =>
|
|
item.owned_by === "jina-ai" &&
|
|
item.root === "jina-reranker-v3" &&
|
|
item.type === "rerank" &&
|
|
!item.parent
|
|
);
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(visibleJinaEmbeddingRows.length, 1);
|
|
assert.equal(visibleJinaEmbeddingRows[0].id, "jina-ai/jina-embeddings-v5-text-small");
|
|
assert.equal(visibleJinaRerankRows.length, 1);
|
|
assert.equal(visibleJinaRerankRows[0].id, "jina-ai/jina-reranker-v3");
|
|
});
|
|
|
|
test("v1 models catalog exposes image model input and output modalities for advanced image providers", async () => {
|
|
await seedConnection("together", { name: "together-images" });
|
|
await seedConnection("topaz", { name: "topaz-images" });
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const byId = new Map(body.data.map((item) => [item.id, item]));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.deepEqual((byId as any).get("flux-2-dev")?.input_modalities, ["text", "image"]);
|
|
(assert as any).deepEqual((byId.get("flux-2-dev") as any).output_modalities, ["image"]);
|
|
(assert as any).equal((byId.get("flux-2-dev") as any).type, "image");
|
|
assert.ok((byId.get("flux-2-dev") as any).supported_sizes?.includes("1024x1024"));
|
|
(assert as any).deepEqual((byId.get("topaz/topaz-enhance") as any).input_modalities, ["image"]);
|
|
assert.deepEqual((byId.get("topaz/topaz-enhance") as any).output_modalities, ["image"]);
|
|
});
|
|
|
|
test("v1 models catalog tolerates custom model lookup failures and keeps builtin models available", async () => {
|
|
await seedConnection("openai", { name: "openai-custom-failure" });
|
|
|
|
const db = core.getDbInstance();
|
|
const originalPrepare = db.prepare.bind(db);
|
|
const originalLog = console.log;
|
|
const logs = [];
|
|
|
|
db.prepare = (sql) => {
|
|
if (String(sql) === "SELECT key, value FROM key_value WHERE namespace = 'customModels'") {
|
|
throw new Error("custom models offline");
|
|
}
|
|
return originalPrepare(sql);
|
|
};
|
|
console.log = (...args) => {
|
|
logs.push(args.map((arg) => String(arg)).join(" "));
|
|
};
|
|
|
|
try {
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(body.data.some((item) => item.id === "openai/gpt-4o-2024-11-20"));
|
|
assert.ok(logs.some((entry) => entry.includes("Could not fetch custom models")));
|
|
} finally {
|
|
db.prepare = originalPrepare;
|
|
console.log = originalLog;
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog exposes provider-prefixed custom models, filters by raw model permissions, and skips hidden or Gemini custom rows", async () => {
|
|
await seedConnection("cline", {
|
|
authType: "oauth",
|
|
name: "cline-custom",
|
|
apiKey: null,
|
|
accessToken: "cline-access",
|
|
});
|
|
await seedConnection("gemini", { name: "gemini-custom" });
|
|
|
|
await modelsDb.addCustomModel("cline", "demo-custom", "Demo Custom", "manual", "responses", [
|
|
"images",
|
|
]);
|
|
await modelsDb.updateCustomModel("cline", "demo-custom", {
|
|
inputTokenLimit: 1234,
|
|
});
|
|
await modelsDb.addCustomModel("gemini", "gemini-custom-only", "Gemini Custom");
|
|
|
|
const db = core.getDbInstance();
|
|
db.prepare("UPDATE key_value SET value = ? WHERE namespace = 'customModels' AND key = ?").run(
|
|
JSON.stringify([
|
|
{
|
|
id: "demo-custom",
|
|
name: "Demo Custom",
|
|
apiFormat: "responses",
|
|
supportedEndpoints: ["images"],
|
|
inputTokenLimit: 1234,
|
|
},
|
|
{
|
|
id: "hidden-custom",
|
|
name: "Hidden Custom",
|
|
isHidden: true,
|
|
},
|
|
{
|
|
name: "Missing Id",
|
|
},
|
|
null,
|
|
]),
|
|
"cline"
|
|
);
|
|
|
|
const key = await apiKeysDb.createApiKey("catalog-root-filter", "machine-root-filter");
|
|
await apiKeysDb.updateApiKeyPermissions(key.id, {
|
|
allowedModels: ["demo-custom"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models", {
|
|
headers: { Authorization: `Bearer ${key.key}` },
|
|
})
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids = new Set(body.data.map((item) => item.id));
|
|
const shortAlias = body.data.find((item) => item.id === "cl/demo-custom");
|
|
const providerAlias = body.data.find((item) => item.id === "cline/demo-custom");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(ids.has("cl/demo-custom"));
|
|
assert.ok(ids.has("cline/demo-custom"));
|
|
assert.equal(ids.has("cl/hidden-custom"), false);
|
|
assert.equal(ids.has("gemini/gemini-custom-only"), false);
|
|
assert.equal(shortAlias.type, "image");
|
|
assert.equal(shortAlias.api_format, "responses");
|
|
assert.deepEqual(shortAlias.supported_endpoints, ["images"]);
|
|
assert.equal(shortAlias.context_length, 1234);
|
|
assert.equal(providerAlias.parent, "cl/demo-custom");
|
|
});
|
|
|
|
test("v1 models catalog uses synced models.dev limits instead of provider defaults", async () => {
|
|
await seedConnection("openai", { name: "openai-models-dev" });
|
|
|
|
try {
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
openai: {
|
|
"gpt-5.5": {
|
|
tool_call: true,
|
|
reasoning: true,
|
|
attachment: true,
|
|
structured_output: true,
|
|
temperature: true,
|
|
modalities_input: JSON.stringify(["text", "image"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
knowledge_cutoff: null,
|
|
release_date: null,
|
|
last_updated: null,
|
|
status: null,
|
|
family: "gpt-5",
|
|
open_weights: false,
|
|
limit_context: 1050000,
|
|
limit_input: 1050000,
|
|
limit_output: 128000,
|
|
interleaved_field: null,
|
|
},
|
|
},
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const model = body.data.find((item) => item.id === "openai/gpt-5.5");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(model);
|
|
assert.equal(model.context_length, 1050000);
|
|
assert.equal(model.max_input_tokens, 1050000);
|
|
assert.equal(model.max_output_tokens, 128000);
|
|
} finally {
|
|
modelsDevSync.saveModelsDevCapabilities({});
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog exposes Bedrock Claude token limits from static metadata", async () => {
|
|
await seedConnection("bedrock", { name: "bedrock-limits" });
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const sonnet46 = body.data.find((item) => item.id === "bedrock/anthropic.claude-sonnet-4-6");
|
|
const sonnet45 = body.data.find((item) => item.id === "bedrock/anthropic.claude-sonnet-4-5");
|
|
const opus46 = body.data.find((item) => item.id === "bedrock/anthropic.claude-opus-4-6");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(sonnet46);
|
|
assert.equal(sonnet46.context_length, 1000000);
|
|
assert.equal(sonnet46.max_input_tokens, 1000000);
|
|
assert.equal(sonnet46.max_output_tokens, 64000);
|
|
assert.ok(sonnet45);
|
|
assert.equal(sonnet45.context_length, 200000);
|
|
assert.equal(sonnet45.max_output_tokens, 64000);
|
|
assert.ok(opus46);
|
|
assert.equal(opus46.context_length, 1000000);
|
|
assert.equal(opus46.max_output_tokens, 128000);
|
|
});
|
|
|
|
test("v1 models catalog lets provider-specific synced limits beat global static specs", async () => {
|
|
await seedConnection("github", {
|
|
authType: "oauth",
|
|
name: "github-copilot-models-dev",
|
|
apiKey: null,
|
|
accessToken: "github-access",
|
|
});
|
|
|
|
try {
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
github: {
|
|
"gpt-5.5": {
|
|
tool_call: true,
|
|
reasoning: true,
|
|
attachment: true,
|
|
structured_output: true,
|
|
temperature: true,
|
|
modalities_input: JSON.stringify(["text", "image"]),
|
|
modalities_output: JSON.stringify(["text"]),
|
|
knowledge_cutoff: null,
|
|
release_date: null,
|
|
last_updated: null,
|
|
status: null,
|
|
family: "gpt-5",
|
|
open_weights: false,
|
|
limit_context: 400000,
|
|
limit_input: 272000,
|
|
limit_output: 128000,
|
|
interleaved_field: null,
|
|
},
|
|
},
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const model = body.data.find((item) => item.id === "gh/gpt-5.5");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(model);
|
|
assert.equal(model.context_length, 400000);
|
|
assert.equal(model.max_input_tokens, 272000);
|
|
assert.equal(model.max_output_tokens, 128000);
|
|
} finally {
|
|
modelsDevSync.saveModelsDevCapabilities({});
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog returns 500 when model compatibility lookup crashes", async () => {
|
|
await seedConnection("openai", { name: "openai-compat-crash" });
|
|
|
|
const db = core.getDbInstance();
|
|
const originalPrepare = db.prepare.bind(db);
|
|
const originalLog = console.log;
|
|
const logs = [];
|
|
|
|
db.prepare = (sql) => {
|
|
const statement = originalPrepare(sql);
|
|
if (String(sql) !== "SELECT value FROM key_value WHERE namespace = ? AND key = ?") {
|
|
return statement;
|
|
}
|
|
|
|
return new Proxy(statement, {
|
|
get(target, prop, receiver) {
|
|
if (prop === "get") {
|
|
return (...args) => {
|
|
if (args[0] === "modelCompatOverrides") {
|
|
throw new Error("compat lookup boom");
|
|
}
|
|
return target.get(...args);
|
|
};
|
|
}
|
|
return Reflect.get(target, prop, receiver);
|
|
},
|
|
});
|
|
};
|
|
console.log = (...args) => {
|
|
logs.push(args.map((arg) => String(arg)).join(" "));
|
|
};
|
|
|
|
try {
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
|
|
assert.equal(response.status, 500);
|
|
assert.equal(body.error.type, "server_error");
|
|
assert.match(body.error.message, /compat lookup boom/i);
|
|
assert.ok(logs.some((entry) => entry.includes("Error fetching models:")));
|
|
} finally {
|
|
db.prepare = originalPrepare;
|
|
console.log = originalLog;
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog skips duplicate built-ins and custom models from inactive providers", async () => {
|
|
await seedConnection("openai", { name: "openai-duplicate" });
|
|
await seedConnection("cline", {
|
|
authType: "oauth",
|
|
name: "cline-inactive-custom",
|
|
apiKey: null,
|
|
accessToken: "cline-access",
|
|
isActive: false,
|
|
});
|
|
|
|
await modelsDb.addCustomModel("openai", "gpt-4o-2024-11-20", "Duplicate Builtin");
|
|
await modelsDb.addCustomModel("cline", "inactive-only", "Inactive Only");
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const duplicateBuiltins = body.data.filter((item) => item.id === "openai/gpt-4o-2024-11-20");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(duplicateBuiltins.length, 1);
|
|
assert.equal(duplicateBuiltins[0].custom === true, false);
|
|
assert.equal(
|
|
body.data.some((item) => item.id === "cl/inactive-only" || item.id === "cline/inactive-only"),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog adds managed fallback models for Claude-compatible providers", async () => {
|
|
await providersDb.createProviderNode({
|
|
id: "anthropic-compatible-cc-demo",
|
|
type: "anthropic-compatible",
|
|
name: "Claude Compatible Demo",
|
|
prefix: "ccdemo",
|
|
baseUrl: "https://proxy.example.com",
|
|
chatPath: "/v1/messages",
|
|
modelsPath: "/v1/models",
|
|
});
|
|
await seedConnection("anthropic-compatible-cc-demo", {
|
|
name: "claude-compatible-node",
|
|
providerSpecificData: {
|
|
baseUrl: "https://proxy.example.com",
|
|
chatPath: "/v1/messages",
|
|
modelsPath: "/v1/models",
|
|
},
|
|
});
|
|
modelsDb.mergeModelCompatOverride("anthropic-compatible-cc-demo", "claude-sonnet-4-6", {
|
|
isHidden: true,
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids = new Set(body.data.map((item) => item.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(ids.has("ccdemo/claude-opus-4-7"));
|
|
assert.ok(ids.has("ccdemo/claude-opus-4-6"));
|
|
assert.equal(ids.has("ccdemo/claude-sonnet-4-6"), false);
|
|
});
|
|
|
|
test("v1 models catalog auto-calculates combo context_length from targets when not set manually", async () => {
|
|
await seedConnection("openai", { name: "openai-auto-context" });
|
|
await seedConnection("claude", {
|
|
authType: "oauth",
|
|
name: "claude-auto-context",
|
|
apiKey: null,
|
|
accessToken: "claude-access",
|
|
});
|
|
|
|
// Create a combo with targets having different context limits.
|
|
// openai/gpt-4o context = 128000, claude/claude-sonnet-4-6 = 200000.
|
|
// The combo should expose context_length = min = 128000.
|
|
const combo = await combosDb.createCombo({
|
|
name: "auto-context-combo",
|
|
strategy: "priority",
|
|
models: ["openai/gpt-4o", "claude/claude-sonnet-4-6"],
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const comboModel = body.data.find((item) => item.id === "auto-context-combo");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(comboModel);
|
|
assert.equal(
|
|
comboModel.context_length,
|
|
128000,
|
|
"combo context_length should be the MIN of all target model limits"
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog includes context_length for individual chat models", async () => {
|
|
await seedConnection("openai", { name: "openai-context" });
|
|
await seedConnection("claude", {
|
|
authType: "oauth",
|
|
name: "claude-context",
|
|
apiKey: null,
|
|
accessToken: "claude-access",
|
|
});
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const chatModels = body.data.filter((item) => !item.type || item.type === "chat");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(chatModels.length > 0, "should have at least one chat model");
|
|
|
|
for (const model of chatModels) {
|
|
assert.ok(
|
|
typeof model.context_length === "number" && model.context_length > 0,
|
|
`chat model ${model.id} should have a positive context_length, got ${model.context_length}`
|
|
);
|
|
}
|
|
});
|
|
|
|
test("v1 models catalog falls back to getTokenLimit for models without registry defaultContextLength", async () => {
|
|
// opencode-go has defaultContextLength in REGISTRY, but we test the fallback
|
|
// path by verifying models from the synced path still get context_length
|
|
const connection = await seedConnection("opencode-go", {
|
|
name: "opencode-go-context-fallback",
|
|
apiKey: "go-key",
|
|
});
|
|
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection("opencode-go", (connection as any).id, [
|
|
{
|
|
id: "test-model-no-context",
|
|
name: "Test Model No Context",
|
|
source: "imported",
|
|
supportedEndpoints: ["chat"],
|
|
},
|
|
]);
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const model = body.data.find((item) => item.id === "opencode-go/test-model-no-context");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(model, "synced model should appear");
|
|
assert.ok(
|
|
typeof model.context_length === "number" && model.context_length > 0,
|
|
`synced model without inputTokenLimit should get context_length via getTokenLimit fallback, got ${model.context_length}`
|
|
);
|
|
});
|
|
|
|
test("v1 models catalog prefers manual combo context_length over auto-calculated", async () => {
|
|
await seedConnection("openai", { name: "openai-manual-context" });
|
|
|
|
const combo = await combosDb.createCombo({
|
|
name: "manual-context-combo",
|
|
strategy: "priority",
|
|
models: ["openai/gpt-4o"],
|
|
});
|
|
await combosDb.updateCombo((combo as any).id, { context_length: 64000 });
|
|
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const comboModel = body.data.find((item) => item.id === "manual-context-combo");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.ok(comboModel);
|
|
assert.equal(comboModel.context_length, 64000, "manual context_length should override auto-calc");
|
|
});
|
|
|
|
// Regression test for Issue #2798: noAuth providers (opencode/oc) have no DB connection rows
|
|
// but their models must still appear in /v1/models.
|
|
test("v1 models catalog includes noAuth provider models when no DB connections exist (#2798)", async () => {
|
|
// No connections seeded — empty DB, simulating a fresh install with no credentials added.
|
|
const response = await v1ModelsCatalog.getUnifiedModelsResponse(
|
|
new Request("http://localhost/api/v1/models")
|
|
);
|
|
const body = (await response.json()) as any;
|
|
const ids: string[] = body.data.map((item: any) => item.id);
|
|
|
|
assert.equal(response.status, 200);
|
|
// opencode (noAuth) models must surface even with zero connection rows.
|
|
// The registry defines models under alias "oc" (e.g. "oc/big-pickle").
|
|
assert.ok(
|
|
ids.some((id) => id.startsWith("oc/") || id.startsWith("opencode/")),
|
|
`Expected at least one oc/* or opencode/* model in /v1/models but got none. IDs sample: ${ids.slice(0, 10).join(", ")}`
|
|
);
|
|
});
|