# v0.5.70 (2026-09-08)

## Features
- **Providers**: creating a compatible / custom-embedding node now registers the endpoint only — the API key is added afterwards from the node's page, like the built-in providers. The create dialogs drop the API Key / Model ID / Check fields, and `POST /api/provider-nodes` no longer accepts credentials at all, so a node can never be half-created
- **Providers**: compatible nodes now use the same model rows as built-in providers — capability badges, copy, per-model test, alias handling and the Add/Edit Model modal with vision + reasoning toggles, replacing the weaker read-only list
- **Providers**: compatible nodes get the built-in bulk toolbars: Test All / Disable / Active / Select All over connections, and Test All Models / Disable All / Active All over models, with per-row disable and a restore strip for disabled models
- **Providers**: wire the dead "Fetch Models" button on compatible nodes to the live upstream catalog, de-duplicating against already-added models

## Fixes
- **Models**: persist per-model capability assertions for custom and compatible providers and honor them everywhere — unsupported media is stripped on the chat path, `/v1/models` and `/api/models` report what the user asserted, and thinking translation follows it (asserting `reasoning:false` now actually strips thinking fields, `reasoning:true` emits them)
- **Models**: partial capability edits merge instead of overwriting, so toggling vision off no longer erases a stored reasoning assertion
- **Capabilities**: keep server-injected readers (synced catalog, user-asserted capabilities) in process-wide state — Next.js compiles startup and each API route into separate bundles with their own module instances, so a boot-time install was invisible to every request handler and the models.dev catalog contributed nothing to upstream requests since 0532f00d
- **Dashboard**: thinking-level picker and model-row suffix reflect user-asserted reasoning on compatible nodes
- **Providers**: `Default Model` is optional when adding an API key to a compatible node — the node's own model list (and the picker in the test modals) already determine what gets probed, and the built-in fallback still covers connection checks
- **Providers**: restore the `useCopyToClipboard` import dropped from the provider detail page, which crashed the route with `ReferenceError` for every provider
- **DB**: restore `getModelAliases` / `setModelAlias` / `deleteModelAlias` re-exports dropped from the `localDb` shim by 86112cee, which broke `GET /api/models` and `GET /v1/models` at import time
- **Providers**: remove dead `PassthroughModelsSection` (never passed props, superseded by the shared model rows)
- **Media Providers**: creating a custom embedding node reports that a key still has to be added, instead of claiming a key was saved; the edit dialog keeps its API Key + Check affordance since a stored key already exists there
- **Build**: self-host Inter instead of fetching it through `next/font/google` at build time — a Docker / mirrored builder with no route to `fonts.googleapis.com` failed the entire image build on `Failed to fetch 'Inter' from Google Fonts`. The seven `@font-face` rules and their `unicode-range`s copy what `next/font` emitted (a `latin`-only file would have dropped Vietnamese diacritics) and the latin subset is preloaded as before, so rendered metrics are unchanged
This commit is contained in:
2026-09-10 11:11:24 +07:00
parent 302795a613
commit a84ba559f3
40 changed files with 1562 additions and 802 deletions

View File

@@ -0,0 +1,76 @@
import { afterEach, describe, expect, it, vi } from "vitest";
/**
* Next.js compiles `instrumentation.js` and every API route into SEPARATE server
* bundles, so one source file gets a distinct module instance per bundle. A
* reader installed into a plain module-local variable therefore lands in the
* startup copy while the chat route reads its own still-empty copy: the setter
* appears to succeed and the feature is silently dead.
*
* Distinct `?bundle=` suffixes give this file two instances of the same module in
* one process — it models "two bundles" without a real build.
*/
const boot = await import("../../open-sse/providers/capabilities.js?bundle=boot");
const route = await import("../../open-sse/providers/capabilities.js?bundle=route");
afterEach(() => {
boot.setUserCapsSource(null);
boot.setCatalogSource(null);
});
describe("capability sources across server bundles", () => {
it("keeps distinct module instances per bundle", () => {
// If these ever collapse into one instance the tests below prove nothing.
expect(route).not.toBe(boot);
});
it("honours a user-asserted caps source installed at startup", () => {
boot.setUserCapsSource(() => ({ vision: false }));
// qwen3-vl-plus is vision by name heuristic; the assertion must win in the
// bundle that actually serves the request.
expect(route.getCapabilitiesForModel("custom-node", "qwen3-vl-plus").vision).toBe(false);
boot.setUserCapsSource(() => ({ reasoning: true }));
expect(route.getCapabilitiesForModel("custom-node", "my-private-chatml-9").reasoning).toBe(true);
});
it("honours a catalog source installed at startup", () => {
boot.setCatalogSource({
getModalities: (model) => (model === "hand-rolled-7b" ? { vision: true } : null),
getLimits: (provider, model) => (model === "hand-rolled-7b" ? { contextWindow: 400000 } : null),
});
const caps = route.getCapabilitiesForModel("custom-node", "hand-rolled-7b");
expect(caps.vision).toBe(true);
expect(caps.contextWindow).toBe(400000);
});
it("detaches the catalog everywhere when one bundle detaches it", () => {
// modelCatalog/sync.js nulls the reader while computing a delta against the
// hand-written tables, then reinstalls it; both bundles must agree.
boot.setCatalogSource({ getModalities: () => ({ vision: true }), getLimits: () => null });
expect(route.getCapabilitiesForModel("custom-node", "hand-rolled-7b").vision).toBe(true);
boot.setCatalogSource(null);
expect(route.getCapabilitiesForModel("custom-node", "hand-rolled-7b").vision).toBe(false);
});
});
describe("user-caps snapshot across server bundles", () => {
const rows = [{ providerAlias: "node-abc", id: "chat-9", type: "llm", caps: { reasoning: true } }];
it("makes a rebuild started by the write route visible to the request route", async () => {
vi.doMock("@/lib/db/index.js", () => ({ getCustomModels: async () => rows }));
try {
const write = await import("../../src/lib/modelCaps/userCaps.js?bundle=write");
const request = await import("../../src/lib/modelCaps/userCaps.js?bundle=request");
write.invalidateUserCaps();
await vi.waitFor(() => {
expect(request.getUserCapsFor("node-abc", "chat-9")).toEqual({ reasoning: true });
});
} finally {
vi.doUnmock("@/lib/db/index.js");
vi.resetModules();
}
});
});

View File

@@ -0,0 +1,81 @@
import { describe, it, expect, vi, afterEach } from "vitest";
// /v1/models is what external CLIs (Codex, Claude Code, aider) read. A capability
// the user asserted on the dashboard must show up there, and it must win over the
// name heuristic / live-catalog guess.
const NODE_ID = "openai-compatible-chat-abc123";
vi.mock("@/lib/localDb", () => ({
getProviderConnections: vi.fn(async () => [
{
provider: NODE_ID,
isActive: true,
providerSpecificData: { prefix: "relay", apiType: "chat", baseUrl: "https://relay.example.com/v1" },
},
]),
getCombos: vi.fn(async () => []),
getCustomModels: vi.fn(async () => []),
getModelAliases: vi.fn(async () => ({})),
}));
vi.mock("@/lib/disabledModelsDb", () => ({
getDisabledModels: vi.fn(async () => ({})),
}));
vi.mock("@/sse/services/auth.js", () => ({
getApiKeyRecord: vi.fn(async () => null),
extractApiKey: vi.fn(() => null),
}));
vi.mock("@/sse/services/tokenRefresh", () => ({
updateProviderCredentials: vi.fn(async () => {}),
}));
afterEach(() => vi.clearAllMocks());
async function buildWithCustomModels(customModels) {
const localDb = await import("@/lib/localDb");
localDb.getCustomModels.mockResolvedValue(customModels);
const { buildModelsList } = await import("@/app/api/v1/models/route.js");
// skipDynamicFetch: a real GET /models against the node URL would be network I/O.
return buildModelsList(["llm"], { skipDynamicFetch: true });
}
describe("/v1/models honors stored per-model capabilities", () => {
it("reports asserted vision:false over the name heuristic", async () => {
const models = await buildWithCustomModels([
{ providerAlias: NODE_ID, id: "qwen3-vl-plus", type: "llm", caps: { vision: false } },
]);
const entry = models.find((m) => m.id === "relay/qwen3-vl-plus");
expect(entry).toBeTruthy();
expect(entry.capabilities.vision).toBe(false);
});
it("reports asserted reasoning:true and token limits", async () => {
const models = await buildWithCustomModels([
{
providerAlias: NODE_ID,
id: "my-private-model",
type: "llm",
caps: { reasoning: true, contextWindow: 32000, maxOutput: 4096 },
},
]);
const entry = models.find((m) => m.id === "relay/my-private-model");
expect(entry.capabilities.reasoning).toBe(true);
// Snake_case names are what clients actually read for compaction.
expect(entry.context_length).toBe(32000);
expect(entry.max_completion_tokens).toBe(4096);
});
it("leaves models with no assertions to the heuristics", async () => {
const models = await buildWithCustomModels([
{ providerAlias: NODE_ID, id: "qwen3-vl-plus", type: "llm" },
]);
const entry = models.find((m) => m.id === "relay/qwen3-vl-plus");
expect(entry.capabilities.vision).toBe(true);
});
});

View File

@@ -0,0 +1,114 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, it, expect, afterEach, vi } from "vitest";
// The dashboard's Add/Edit Model modal stores only the toggles the user touched.
// That is only safe if the storage layer merges per key: a second POST carrying
// { vision:false } must not erase an earlier { reasoning:true } assertion.
const originalDataDir = process.env.DATA_DIR;
let tempDir = null;
function setup() {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "9router-caps-roundtrip-"));
process.env.DATA_DIR = tempDir;
global._dbAdapter = { instance: null, initPromise: null, logged: false };
vi.resetModules();
vi.doMock("next/server", () => ({
NextResponse: {
json(body, init = {}) {
return new Response(JSON.stringify(body), {
status: init.status || 200,
headers: { "Content-Type": "application/json" },
});
},
},
}));
}
afterEach(() => {
// driver.js caches the open handle on `global`; release it before unlinking.
global._dbAdapter = { instance: null, initPromise: null, logged: false };
if (tempDir) fs.rmSync(tempDir, { recursive: true, force: true });
tempDir = null;
if (originalDataDir === undefined) delete process.env.DATA_DIR;
else process.env.DATA_DIR = originalDataDir;
});
function request(method, url, body) {
return new Request(url, {
method,
headers: { "Content-Type": "application/json" },
body: body === undefined ? undefined : JSON.stringify(body),
});
}
describe("POST /api/models/custom caps round-trip", () => {
it("stores whitelisted booleans and merges later partial edits", async () => {
setup();
const { POST, GET } = await import("@/app/api/models/custom/route.js");
const { getCustomModels } = await import("@/models/index.js");
const NODE = "openai-compatible-chat-abc123";
const first = await POST(request("POST", "https://9router.local/api/models/custom", {
providerAlias: NODE,
id: "my-model",
type: "llm",
// junk keys / non-booleans must be dropped by sanitizeCaps
caps: { vision: true, reasoning: true, bogus: "yes", contextWindow: "128k" },
}));
expect(first.status).toBe(200);
expect(await first.json()).toEqual({ success: true, added: true });
const [row] = await getCustomModels();
expect(row.caps).toEqual({ vision: true, reasoning: true });
// Edit mode sends only the changed toggle.
await POST(request("POST", "https://9router.local/api/models/custom", {
providerAlias: NODE,
id: "my-model",
type: "llm",
caps: { vision: false },
}));
// GET /api/models/custom returns the raw stored rows.
const listed = await (await GET()).json();
const raw = listed.models.find((m) => m.providerAlias === NODE && m.id === "my-model");
expect(raw).toBeTruthy();
expect(raw.caps).toEqual({ vision: false, reasoning: true });
// GET /api/models is what the dashboard badges read; stored caps must win there too.
const { GET: getList } = await import("@/app/api/models/route.js");
const view = (await (await getList()).json()).models.find(
(m) => m.provider === NODE && m.model === "my-model",
);
expect(view).toBeTruthy();
expect(view.caps.vision).toBe(false);
expect(view.caps.reasoning).toBe(true);
});
it("keeps an edit with no changed toggles from clearing stored caps", async () => {
setup();
const { POST } = await import("@/app/api/models/custom/route.js");
const { getCustomModels } = await import("@/models/index.js");
await POST(request("POST", "https://9router.local/api/models/custom", {
providerAlias: "openai-compatible-chat-abc123",
id: "stable-model",
type: "llm",
caps: { vision: false },
}));
await POST(request("POST", "https://9router.local/api/models/custom", {
providerAlias: "openai-compatible-chat-abc123",
id: "stable-model",
type: "llm",
name: "Renamed",
// no caps at all: sanitizeCaps -> null, so the assertion must survive
}));
const [row] = await getCustomModels();
expect(row.name).toBe("Renamed");
expect(row.caps).toEqual({ vision: false });
});
});

View File

@@ -0,0 +1,205 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, it, expect, afterEach, vi } from "vitest";
// POST /api/provider-nodes registers a node only — API keys are added later
// from the node page through POST /api/providers. The node row it creates MUST
// carry the same providerSpecificData the connection created later will copy,
// otherwise a key added after the fact routes differently from the old
// one-call flow.
const originalDataDir = process.env.DATA_DIR;
let tempDir = null;
function resetDataDir(prefix) {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
process.env.DATA_DIR = tempDir;
// src/lib/db/driver.js caches the opened adapter on `global` to survive Next
// hot-reload; without this every test would share the first temp DB.
global._dbAdapter = { instance: null, initPromise: null, logged: false };
vi.resetModules();
vi.doMock("next/server", () => ({
NextResponse: {
json(body, init = {}) {
return new Response(JSON.stringify(body), {
status: init.status || 200,
headers: { "Content-Type": "application/json" },
});
},
},
}));
}
afterEach(() => {
// Drop the cached adapter BEFORE deleting its file: driver.js keeps the
// opened handle on `global`, so any later file in this worker would otherwise
// write into a removed database.
global._dbAdapter = { instance: null, initPromise: null, logged: false };
if (tempDir) fs.rmSync(tempDir, { recursive: true, force: true });
tempDir = null;
if (originalDataDir === undefined) delete process.env.DATA_DIR;
else process.env.DATA_DIR = originalDataDir;
});
function post(url, body) {
return new Request(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
}
async function loadRoutes() {
const nodes = await import("@/app/api/provider-nodes/route.js");
const providers = await import("@/app/api/providers/route.js");
const models = await import("@/models/index.js");
return { nodes, providers, models };
}
describe("provider-nodes POST creates a node without a key", () => {
it("creates an openai-compatible node and stores no connection", async () => {
resetDataDir("9router-node-create-");
const { nodes, models } = await loadRoutes();
const res = await nodes.POST(post("https://9router.local/api/provider-nodes", {
type: "openai-compatible",
apiType: "responses",
name: "My Relay",
prefix: "relay",
baseUrl: "https://relay.example.com/v1",
}));
expect(res.status).toBe(201);
const created = await res.json();
expect(created.node?.id).toContain("openai-compatible-");
expect(created.node.name).toBe("My Relay");
expect(created.node.baseUrl).toBe("https://relay.example.com/v1");
expect(created.node.prefix).toBe("relay");
expect(created.node.apiType).toBe("responses");
// Creating a node must never fabricate a connection.
expect(created.connection).toBeUndefined();
expect(created.connectionError).toBeUndefined();
expect(await models.getProviderConnections()).toEqual([]);
});
it("ignores a stray apiKey instead of opening a connection", async () => {
resetDataDir("9router-node-create-stray-key-");
const { nodes, models } = await loadRoutes();
const res = await nodes.POST(post("https://9router.local/api/provider-nodes", {
type: "openai-compatible",
apiType: "chat",
name: "Legacy Client",
prefix: "lc",
baseUrl: "https://lc.example.com/v1",
apiKey: "sk-should-be-dropped",
defaultModel: "gpt-5.1",
testStatus: "active",
}));
expect(res.status).toBe(201);
const body = await res.json();
expect(body.connection).toBeUndefined();
expect(JSON.stringify(body)).not.toContain("sk-should-be-dropped");
expect(await models.getProviderConnections()).toEqual([]);
});
it("strips /messages for anthropic-compatible and omits apiType", async () => {
resetDataDir("9router-node-create-anthropic-");
const { nodes } = await loadRoutes();
const body = await (
await nodes.POST(post("https://9router.local/api/provider-nodes", {
type: "anthropic-compatible",
name: "Claude Proxy",
prefix: "cpx",
baseUrl: "https://proxy.example.com/v1/messages",
}))
).json();
expect(body.node.baseUrl).toBe("https://proxy.example.com/v1");
expect(body.node.providerSpecificData).toBeUndefined();
expect(body.node).toMatchObject({
type: "anthropic-compatible",
prefix: "cpx",
baseUrl: "https://proxy.example.com/v1",
name: "Claude Proxy",
});
});
it("creates a custom-embedding node", async () => {
resetDataDir("9router-node-create-embedding-");
const { nodes, models } = await loadRoutes();
const res = await nodes.POST(post("https://9router.local/api/provider-nodes", {
type: "custom-embedding",
name: "Voyage",
prefix: "voyage",
baseUrl: "https://api.voyageai.com/v1",
}));
expect(res.status).toBe(201);
const body = await res.json();
expect(body.node.id).toContain("custom-embedding-");
expect(await models.getProviderConnections()).toEqual([]);
});
it("rejects a bad proxy before creating anything", async () => {
resetDataDir("9router-node-proxy-guard-");
const { nodes, models } = await loadRoutes();
const res = await nodes.POST(post("https://9router.local/api/provider-nodes", {
type: "openai-compatible",
apiType: "chat",
name: "Nope",
prefix: "np",
baseUrl: "https://np.example.com/v1",
connectionProxyEnabled: true,
}));
expect(res.status).toBe(400);
expect((await res.json()).error).toContain("proxy URL is required");
expect(await models.getProviderNodes()).toEqual([]);
expect(await models.getProviderConnections()).toEqual([]);
});
it("keys added afterwards land on the node with the node's own data", async () => {
resetDataDir("9router-node-later-key-");
const { nodes, providers, models } = await loadRoutes();
const node = (
await (
await nodes.POST(post("https://9router.local/api/provider-nodes", {
type: "openai-compatible",
apiType: "responses",
name: "Relay",
prefix: "relay",
baseUrl: "https://relay.example.com/v1",
}))
).json()
).node;
const added = await (
await providers.POST(post("https://9router.local/api/providers", {
provider: node.id,
name: "First Key",
apiKey: "sk-later",
}))
).json();
expect(added.connection).toBeTruthy();
expect(added.connection.provider).toBe(node.id);
expect(added.connection.authType).toBe("apikey");
expect(added.connection.isActive).toBe(true);
expect(added.connection.apiKey).toBeUndefined();
// Connection copies the node row, so the prefix/apiType survive.
expect(added.connection.providerSpecificData.prefix).toBe("relay");
expect(added.connection.providerSpecificData.apiType).toBe("responses");
const stored = (await models.getProviderConnections())
.filter((c) => c.provider === node.id)
.map((c) => c.apiKey);
expect(stored).toEqual(["sk-later"]);
});
});

View File

@@ -0,0 +1,92 @@
import { afterEach, describe, expect, it } from "vitest";
import {
DEFAULT_CAPABILITIES,
getCapabilitiesForModel,
setUserCapsSource,
} from "../../open-sse/providers/capabilities.js";
import { applyThinking } from "../../open-sse/translator/concerns/thinkingUnified.js";
import { looksLikeVisionModel } from "../../open-sse/providers/visionPatterns.js";
// Dashboard capability toggles are the user's own assertion about a model the
// heuristics cannot know. They are final: false must beat a name heuristic,
// true must beat the safe floor, and applying them must never leak a mutation
// back into DEFAULT_CAPABILITIES.
afterEach(() => setUserCapsSource(null));
function assertSource(caps) {
setUserCapsSource(() => caps);
}
describe("user-asserted model capabilities", () => {
it("turns a heuristic-detected vision model back off", () => {
const model = "qwen3-vl-plus";
expect(looksLikeVisionModel(model)).toBe(true);
expect(getCapabilitiesForModel("custom-node", model).vision).toBe(true);
assertSource({ vision: false });
expect(getCapabilitiesForModel("custom-node", model).vision).toBe(false);
});
it("turns reasoning on for a model the tables consider text-only", () => {
const model = "my-private-chatml-9";
expect(getCapabilitiesForModel("custom-node", model).reasoning).toBe(false);
assertSource({ reasoning: true });
expect(getCapabilitiesForModel("custom-node", model).reasoning).toBe(true);
});
it("ignores keys outside the capability set and non-objects", () => {
const before = getCapabilitiesForModel("custom-node", "gpt-5.1");
assertSource({ vision: true, nonsense: true });
const after = getCapabilitiesForModel("custom-node", "gpt-5.1");
expect(after.vision).toBe(true);
expect("nonsense" in after).toBe(false);
for (const junk of [null, undefined, "nope", 42]) {
assertSource(junk);
expect(getCapabilitiesForModel("custom-node", "gpt-5.1")).toEqual(before);
}
});
it("only applies asserted keys, leaving the rest resolved normally", () => {
assertSource({ vision: false });
const caps = getCapabilitiesForModel("custom-node", "my-private-chatml-9");
expect(caps.vision).toBe(false);
expect(caps.tools).toBe(true);
expect(caps.contextWindow).toBe(DEFAULT_CAPABILITIES.contextWindow);
});
it("never mutates DEFAULT_CAPABILITIES", () => {
const floor = { ...DEFAULT_CAPABILITIES };
assertSource({ vision: true, reasoning: true, tools: false, contextWindow: 1234 });
getCapabilitiesForModel("custom-node", "anything");
expect(DEFAULT_CAPABILITIES).toEqual(floor);
});
it("keeps heuristics when no source is installed", () => {
assertSource({ vision: false });
expect(getCapabilitiesForModel("custom-node", "qwen3-vl-plus").vision).toBe(false);
setUserCapsSource(null);
expect(getCapabilitiesForModel("custom-node", "qwen3-vl-plus").vision).toBe(true);
});
});
describe("thinking follows the assertion", () => {
it("strips thinking fields when reasoning is asserted off", () => {
assertSource({ reasoning: false });
const body = { reasoning_effort: "high", messages: [{ role: "user", content: "hi" }] };
applyThinking("openai", "my-private-chatml-9", body, "custom-node");
expect(body.reasoning_effort).toBeUndefined();
expect(body.reasoning).toBeUndefined();
expect(body.thinking).toBeUndefined();
});
it("emits thinking fields when reasoning is asserted on", () => {
assertSource({ reasoning: true, thinkingFormat: "openai" });
const body = { reasoning_effort: "high", messages: [{ role: "user", content: "hi" }] };
applyThinking("openai", "my-private-chatml-9", body, "custom-node");
expect(body.reasoning_effort).toBe("high");
});
});