fix(dashboard): make 'Import from /models' work for no-auth providers (#3047) (#3099)

No-auth providers (OpenCode Free) have no connection row, so handleImportModels returned early and /api/providers/[id]/models 404'd — the import button silently no-op'd. The route now serves the provider's registry/static model catalog when called with a no-auth provider id, and handleImportModels falls back to the provider id when there is no connection. Test: route returns the opencode catalog (source local_catalog) and still 404s for unknown ids.
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-06-03 07:48:19 -03:00
committed by GitHub
parent 365c29a115
commit 8a25d9e229
4 changed files with 73 additions and 2 deletions

View File

@@ -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)

View File

@@ -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) => ({

View File

@@ -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<string, { noAuth?: boolean }>)[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 });
}

View File

@@ -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);
});