Compare commits

..

1 Commits

Author SHA1 Message Date
diegosouzapw
4b6c652b48 fix(providers): correct opencode-zen muse-spark context length and Responses auth header (#12681, #12633)
- Declare the real ~1M contextLength/maxOutputTokens on the muse-spark-1.2 /
  muse-spark-1.2-contributor-free registry entries (opencode + opencode-zen)
  instead of silently falling back to the 200000 provider default (#12681).
- Send x-api-key instead of Authorization: Bearer for the openai-responses
  format on the main OpenCode Zen host, fixing a 401 on Muse Spark
  Contributor's /v1/responses route; scoped by baseUrl so opencode-go (a
  different upstream) keeps Bearer (#12633).
2026-09-10 14:16:31 -03:00
10 changed files with 127 additions and 138 deletions

View File

@@ -1 +0,0 @@
- fix(dashboard): refresh the providers list after deleting a compatible provider node (#12298)

View File

@@ -0,0 +1 @@
- fix(providers): send `x-api-key` instead of `Authorization: Bearer` for OpenCode Zen's `/v1/responses` endpoint (Muse Spark Contributor models), fixing a 401 on OmniRoute's auth header (#12633)

View File

@@ -0,0 +1 @@
- fix(models): declare the real ~1M contextLength for OpenCode Zen's Muse Spark 1.2 models instead of falling back to the 200000 provider default (#12681)

View File

@@ -30,17 +30,25 @@ export const opencodeProvider: RegistryEntry = {
// content (see issue #10867). The opencode provider is passthrough, so
// declaring them here only sets the wire format / capability flags — the
// live upstream model list already advertises both ids.
// #12681: real window confirmed against the opencode-go registry's own
// muse-spark-1.2-contributor entries (contextLength: 1048576, maxOutputTokens:
// 131072) — without an explicit value here resolution fell back to the
// provider-wide defaultContextLength (200000), understating the real window.
{
id: "muse-spark-1.2",
name: "Muse Spark 1.2",
supportsReasoning: true,
targetFormat: "openai-responses",
contextLength: 1048576,
maxOutputTokens: 131072,
},
{
id: "muse-spark-1.2-contributor-free",
name: "Muse Spark 1.2 Contributor Free",
supportsReasoning: true,
targetFormat: "openai-responses",
contextLength: 1048576,
maxOutputTokens: 131072,
},
{ id: "deepseek-v4-flash-free", name: "DeepSeek V4 Flash Free", supportsReasoning: true },
// #6998: 2026-07-14 refresh — the upstream free tier rotated its lineup;

View File

@@ -63,11 +63,17 @@ export const opencode_zenProvider: RegistryEntry = {
// targetFormat declaration, so requests routed here still hit
// /chat/completions with a mismatched or unanswerable body and the
// upstream returns an empty message.
// #12681: real window confirmed against the opencode-go registry's own
// muse-spark-1.2-contributor entries (contextLength: 1048576, maxOutputTokens:
// 131072) — without an explicit value here resolution fell back to the
// provider-wide defaultContextLength (200000), understating the real window.
{
id: "muse-spark-1.2",
name: "Muse Spark 1.2",
supportsReasoning: true,
targetFormat: "openai-responses",
contextLength: 1048576,
maxOutputTokens: 131072,
},
// Explicit wire-format overlay of the base opencode provider's muse-spark entry
// (targetFormat: openai-responses). Keep in sync with base on catalog syncs.
@@ -76,6 +82,8 @@ export const opencode_zenProvider: RegistryEntry = {
name: "Muse Spark 1.2 Contributor Free",
supportsReasoning: true,
targetFormat: "openai-responses",
contextLength: 1048576,
maxOutputTokens: 131072,
},
// ── DeepSeek ────────────────────────────────────────────────

View File

@@ -31,6 +31,13 @@ import {
import { isOpencodeGeoBlocked, proxyKeyOf } from "./opencodeGeoBlock.ts";
import { isNetworkRotationSharedEgressGuardEnabled } from "@/shared/utils/featureFlags";
/**
* The main OpenCode Zen host, shared by the `opencode` and `opencode-zen`
* registry entries. Used to scope the `x-api-key` auth override (#12633) away
* from `opencode-go`, which serves a different upstream (`.../zen/go/v1`).
*/
const ZEN_BASE_URL = "https://opencode.ai/zen/v1";
/**
* Per-account proxy configuration, persisted by NoAuthAccountCard under
* `providerSpecificData.accountProxies` (keyed by the account id, which the UI
@@ -776,6 +783,20 @@ export class OpencodeExecutor extends BaseExecutor {
}
}
/**
* #12633: OpenCode Zen's `/v1/responses` endpoint (reached when
* `_requestFormat === "openai-responses"`, e.g. Muse Spark Contributor
* models) requires `x-api-key`, not `Authorization: Bearer` — unlike the
* default `/chat/completions` endpoint on the same host, which accepts
* Bearer. Scoped by baseUrl (not provider id/alias) so this only applies to
* the main Zen host (`opencode` / `opencode-zen`, both `https://opencode.ai/zen/v1`)
* and never to opencode-go, which serves Responses-format models from a
* different upstream (`https://opencode.ai/zen/go/v1`) that expects Bearer.
*/
private usesZenApiKeyAuth(): boolean {
return this._requestFormat === "openai-responses" && this.config?.baseUrl === ZEN_BASE_URL;
}
buildHeaders(
credentials: ProviderCredentials | null,
stream = true,
@@ -792,7 +813,7 @@ export class OpencodeExecutor extends BaseExecutor {
: undefined;
if (key) {
if (this._requestFormat === "claude") {
if (this._requestFormat === "claude" || this.usesZenApiKeyAuth()) {
headers["x-api-key"] = key;
} else {
headers["Authorization"] = `Bearer ${key}`;

View File

@@ -110,7 +110,6 @@ export default function CompatibleNodeCard({
});
if (res.ok) {
router.push("/dashboard/providers");
router.refresh();
}
} catch (error) {
console.error("Error deleting provider node:", error);

View File

@@ -0,0 +1,54 @@
import test from "node:test";
import assert from "node:assert/strict";
import { OpencodeExecutor } from "../../open-sse/executors/opencode.ts";
test("#12633: openai-responses format on opencode-zen sends x-api-key, not Authorization Bearer", () => {
const executor = new OpencodeExecutor("opencode-zen");
executor._requestFormat = "openai-responses";
const headers = executor.buildHeaders(
{ apiKey: "sk-zen-test" },
true,
null,
"muse-spark-1.2-contributor-free"
);
assert.equal(headers["x-api-key"], "sk-zen-test");
assert.equal(headers["Authorization"], undefined);
});
test("#12633: openai-responses format on the base opencode (oc) provider also sends x-api-key", () => {
const executor = new OpencodeExecutor("opencode");
executor._requestFormat = "openai-responses";
const headers = executor.buildHeaders(
{ apiKey: "sk-oc-test" },
true,
null,
"muse-spark-1.2-contributor-free"
);
assert.equal(headers["x-api-key"], "sk-oc-test");
assert.equal(headers["Authorization"], undefined);
});
test("#12633: openai-responses format on opencode-go (different upstream endpoint) keeps Authorization Bearer", () => {
const executor = new OpencodeExecutor("opencode-go");
executor._requestFormat = "openai-responses";
const headers = executor.buildHeaders(
{ apiKey: "sk-go-test" },
true,
null,
"muse-spark-1.2-contributor"
);
assert.equal(headers["Authorization"], "Bearer sk-go-test");
assert.equal(headers["x-api-key"], undefined);
});
test("#12633: claude format keeps sending x-api-key (unchanged behavior)", () => {
const executor = new OpencodeExecutor("opencode-zen");
executor._requestFormat = "claude";
const headers = executor.buildHeaders({ apiKey: "sk-claude-test" }, true, null, "some-model");
assert.equal(headers["x-api-key"], "sk-claude-test");
assert.equal(headers["Authorization"], undefined);
});

View File

@@ -0,0 +1,33 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { REGISTRY } from "../../open-sse/config/providerRegistry.ts";
import { getTokenLimit } from "../../open-sse/services/contextManager.ts";
test("#12681: opencode registry declares an explicit real contextLength for muse-spark-1.2 models", () => {
const opencode = REGISTRY["opencode"];
const museSpark = opencode.models.find((m) => m.id === "muse-spark-1.2");
const museSparkFree = opencode.models.find((m) => m.id === "muse-spark-1.2-contributor-free");
assert.notEqual(
museSpark?.contextLength,
undefined,
"muse-spark-1.2 should declare its own real contextLength instead of relying on the 200000 provider default"
);
assert.notEqual(
museSparkFree?.contextLength,
undefined,
"muse-spark-1.2-contributor-free should declare its own real contextLength instead of relying on the 200000 provider default"
);
});
test("#12681: opencode-zen registry declares an explicit real contextLength for muse-spark-1.2 models", () => {
const zen = REGISTRY["opencode-zen"];
const museSpark = zen.models.find((m) => m.id === "muse-spark-1.2");
const museSparkFree = zen.models.find((m) => m.id === "muse-spark-1.2-contributor-free");
assert.notEqual(museSpark?.contextLength, undefined);
assert.notEqual(museSparkFree?.contextLength, undefined);
});
test("#12681: contextManager.getTokenLimit resolves muse-spark-1.2-contributor-free to its real 1M+ window, not the 200000 provider default", () => {
assert.equal(getTokenLimit("opencode", "muse-spark-1.2-contributor-free"), 1048576);
assert.equal(getTokenLimit("opencode-zen", "muse-spark-1.2-contributor-free"), 1048576);
});

View File

@@ -1,135 +0,0 @@
// @vitest-environment jsdom
import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import CompatibleNodeCard from "../../../src/app/(dashboard)/dashboard/providers/[id]/components/CompatibleNodeCard";
const router = vi.hoisted(() => ({
push: vi.fn(),
refresh: vi.fn(),
}));
vi.mock("next/navigation", () => ({
useRouter: () => router,
}));
vi.mock("@/shared/components", () => ({
Card: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Button: ({
children,
onClick,
}: {
children: React.ReactNode;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
}) => <button onClick={onClick}>{children}</button>,
}));
vi.mock("@/shared/components/ProviderIcon", () => ({
default: () => null,
}));
function renderCard(container: HTMLDivElement) {
const root = createRoot(container);
return root;
}
describe("CompatibleNodeCard provider deletion (#12298)", () => {
let container: HTMLDivElement;
let root: ReturnType<typeof createRoot>;
beforeEach(() => {
(
globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
router.push.mockClear();
router.refresh.mockClear();
vi.stubGlobal("confirm", vi.fn(() => true));
container = document.createElement("div");
document.body.appendChild(container);
root = renderCard(container);
});
afterEach(() => {
act(() => root.unmount());
container.remove();
vi.unstubAllGlobals();
});
async function clickDelete() {
await act(async () => {
root.render(
<CompatibleNodeCard
providerId="custom-node"
providerNode={{ baseUrl: "https://example.test/v1", apiType: "openai" }}
isCcCompatible={false}
isAnthropicCompatible={false}
isAnthropicProtocolCompatible={false}
gateConnectionFlow={(callback) => callback()}
openApiKeyAddFlow={vi.fn()}
onOpenEditNodeModal={vi.fn()}
t={(key) => key}
/>
);
});
const deleteButton = Array.from(container.querySelectorAll("button")).find(
(button) => button.textContent === "delete"
);
expect(deleteButton).toBeDefined();
await act(async () => {
deleteButton?.click();
await Promise.resolve();
await Promise.resolve();
});
return deleteButton;
}
it("invalidates the cached providers page after a successful delete and navigation", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true } as Response));
await clickDelete();
expect(fetch).toHaveBeenCalledWith("/api/provider-nodes/custom-node", {
method: "DELETE",
});
expect(router.push).toHaveBeenCalledWith("/dashboard/providers");
expect(router.refresh).toHaveBeenCalledTimes(1);
expect(router.push.mock.invocationCallOrder[0]).toBeLessThan(
router.refresh.mock.invocationCallOrder[0]
);
});
it("does not navigate or refresh when the user cancels the confirm dialog", async () => {
vi.stubGlobal("confirm", vi.fn(() => false));
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true } as Response));
await clickDelete();
expect(fetch).not.toHaveBeenCalled();
expect(router.push).not.toHaveBeenCalled();
expect(router.refresh).not.toHaveBeenCalled();
});
it("does not navigate or refresh when the DELETE response is not ok", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false } as Response));
await clickDelete();
expect(router.push).not.toHaveBeenCalled();
expect(router.refresh).not.toHaveBeenCalled();
});
it("does not navigate or refresh when the DELETE request throws", async () => {
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("network down")));
vi.spyOn(console, "error").mockImplementation(() => {});
await clickDelete();
expect(router.push).not.toHaveBeenCalled();
expect(router.refresh).not.toHaveBeenCalled();
});
});