diff --git a/CHANGELOG.md b/CHANGELOG.md index badab26d76..ae1d0f2ce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ _Development cycle in progress — entries are added as work merges into `releas ### 🔧 Bug Fixes +- **dashboard:** "Import from /models" now works for no-auth providers (e.g. OpenCode Free) — the button used to silently no-op because no-auth providers have no connection row, so `handleImportModels` returned early and the models route 404'd. The route now serves the provider's model catalog when called with a no-auth provider id, and the dashboard falls back to the provider id when there is no connection. ([#3047](https://github.com/diegosouzapw/OmniRoute/issues/3047)) - **providers:** forward Grok's paired `sso-rw` cookie for grok-web — both the executor and the connection validator now send `sso=…; sso-rw=…` (via the new `buildGrokCookieHeader` helper) when the pasted blob carries `sso-rw`, fixing the `403` _"Request rejected by anti-bot rules"_ that Grok returns for `sso` alone. The add-account hint now asks for the full cookie line. ([#3063](https://github.com/diegosouzapw/OmniRoute/issues/3063)) - **providers:** fix claude-web persistent 403 — `execute()` was calling the synchronous `normalizeClaudeSessionCookie()` which never injects `cf_clearance`; changed to async `normalizeClaudeSessionCookieWithAutoRefresh()` with `allowAutoSolve:true`. Also removes dead executor `claude-web-auto-refresh.ts` and correctly reclassifies `duckduckgo-web` and `veoaifree-web` as `NOAUTH_PROVIDERS`. (#3090 — thanks @oyi77) - **autoCombo:** rotate across all provider connections, never waste capacity — `buildAutoCandidates` now expands each provider into one candidate per active connection (e.g. 43 Cerebras keys → 43 candidates). Adds `ScoreTierRotator` with per-combo round-robin state, combo-name-aware tier preferences (smart/fast/cheap/coding), `connectionDensity` factor (weight 0.05), and budget-cap degradation using the rotator. (#3078 — thanks @oyi77) diff --git a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx index 6ecd6f130e..be36ab75fc 100644 --- a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx +++ b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx @@ -3006,7 +3006,11 @@ export default function ProviderDetailPage() { const handleImportModels = async () => { if (importingModels) return; const activeConnection = connections.find((conn) => conn.isActive !== false); - if (!activeConnection) return; + // #3047 — no-auth providers (e.g. OpenCode Free) have no connection rows; + // fall back to the provider id so the models route can serve the public + // catalog instead of the button silently doing nothing. + if (!activeConnection && !isFreeNoAuth) return; + const importTargetId = activeConnection?.id ?? providerId; setImportingModels(true); setShowImportModal(true); @@ -3021,7 +3025,7 @@ export default function ProviderDetailPage() { }); try { - const res = await fetch(`/api/providers/${activeConnection.id}/models?refresh=true`); + const res = await fetch(`/api/providers/${importTargetId}/models?refresh=true`); const data = await res.json(); if (!res.ok) { setImportProgress((prev) => ({ diff --git a/src/app/api/providers/[id]/models/route.ts b/src/app/api/providers/[id]/models/route.ts index 15f3845885..37e73375c3 100755 --- a/src/app/api/providers/[id]/models/route.ts +++ b/src/app/api/providers/[id]/models/route.ts @@ -4,6 +4,7 @@ import { isAnthropicCompatibleProvider, isOpenAICompatibleProvider, isSelfHostedChatProvider, + NOAUTH_PROVIDERS, } from "@/shared/constants/providers"; import { getRegistryEntry } from "@omniroute/open-sse/config/providerRegistry.ts"; import { getModelsByProviderId } from "@/shared/constants/models"; @@ -745,6 +746,28 @@ export async function GET( const connection = await getProviderConnectionById(id); if (!connection) { + // #3047 — no-auth providers (e.g. OpenCode Free) have no connection rows, + // so the "Import from /models" button had no connection id to fetch from + // and silently no-op'd. When the route is called with a no-auth provider + // id, serve that provider's registry/static model catalog so the import + // flow can populate the custom model list. + const isNoAuthProvider = + (NOAUTH_PROVIDERS as Record)[id]?.noAuth === true; + if (isNoAuthProvider) { + const catalog = mergeLocalCatalogModels( + getModelsByProviderId(id) || [], + getStaticModelsForProvider(id) || [] + ).map((model) => ({ id: model.id, name: model.name || model.id })); + const visible = excludeHidden + ? catalog.filter((m) => !getModelIsHidden(id, m.id)) + : catalog; + return NextResponse.json({ + provider: id, + connectionId: id, + models: visible, + source: "local_catalog", + }); + } return NextResponse.json({ error: "Connection not found" }, { status: 404 }); } diff --git a/tests/unit/opencode-noauth-models-route.test.ts b/tests/unit/opencode-noauth-models-route.test.ts new file mode 100644 index 0000000000..685b9d8ed5 --- /dev/null +++ b/tests/unit/opencode-noauth-models-route.test.ts @@ -0,0 +1,43 @@ +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-opencode-models-")); +process.env.DATA_DIR = TEST_DATA_DIR; + +const core = await import("../../src/lib/db/core.ts"); +const modelsRoute = await import("../../src/app/api/providers/[id]/models/route.ts"); + +test.after(() => { + core.resetDbInstance(); + fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true }); +}); + +// #3047 — OpenCode Free (no-auth) has no connection row, so the +// "Import from /models" button used to hit a 404 and silently no-op. The models +// route must serve the provider's catalog when called with a no-auth provider id. +test("models route serves the catalog for a no-auth provider id (#3047)", async () => { + const response = await modelsRoute.GET( + new Request("http://localhost/api/providers/opencode/models?refresh=true"), + { params: { id: "opencode" } } + ); + assert.equal(response.status, 200); + const body = await response.json(); + assert.equal(body.provider, "opencode"); + assert.equal(body.source, "local_catalog"); + assert.ok(Array.isArray(body.models) && body.models.length > 0, "should return catalog models"); + assert.ok( + body.models.every((m: { id?: unknown }) => typeof m.id === "string" && m.id.length > 0), + "every model must have a non-empty id" + ); +}); + +test("models route still 404s for an unknown provider/connection id", async () => { + const response = await modelsRoute.GET( + new Request("http://localhost/api/providers/does-not-exist-xyz/models"), + { params: { id: "does-not-exist-xyz" } } + ); + assert.equal(response.status, 404); +});