mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-12 18:02:11 +03:00
Compare commits
1 Commits
fix/12129-
...
fix/12681-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b6c652b48 |
@@ -1 +0,0 @@
|
||||
- fix(sse): require Responses-shaped body before native OpenAI-compatible passthrough (#12129)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ────────────────────────────────────────────────
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
@@ -731,7 +731,6 @@ export async function handleChatCore({
|
||||
sourceFormat,
|
||||
endpointPath,
|
||||
providerSpecificData: credentials?.providerSpecificData,
|
||||
body,
|
||||
});
|
||||
const responsesInputItems = Array.isArray(body?.input) ? body.input : [];
|
||||
const customToolNames = collectCustomToolNamesForSourceFormat(
|
||||
|
||||
@@ -53,35 +53,19 @@ export function stampNativeResponsesPassthroughBody(
|
||||
return { ...body, _nativeOpenAICompatibleResponsesPassthrough: true };
|
||||
}
|
||||
|
||||
// A body only qualifies for the native-Responses passthrough fast path when it is
|
||||
// actually shaped like a Responses API request (`input`, no `messages`). Endpoint
|
||||
// path alone is not sufficient: an internally-synthesized Chat Completions-shaped
|
||||
// body (e.g. the context-handoff summary request) can be dispatched through a
|
||||
// closure that still carries the original client request's `/responses` endpoint,
|
||||
// which otherwise makes `sourceFormat` resolve to "openai-responses" even though
|
||||
// the body itself was never translated. See issue #12129.
|
||||
function isResponsesShapedBody(body: unknown): boolean {
|
||||
if (!body || typeof body !== "object") return false;
|
||||
const candidate = body as Record<string, unknown>;
|
||||
return candidate.input !== undefined && candidate.messages === undefined;
|
||||
}
|
||||
|
||||
export function shouldUseNativeOpenAICompatibleResponsesPassthrough({
|
||||
provider,
|
||||
sourceFormat,
|
||||
endpointPath,
|
||||
providerSpecificData,
|
||||
body,
|
||||
}: {
|
||||
provider?: string | null;
|
||||
sourceFormat?: string | null;
|
||||
endpointPath?: string | null;
|
||||
providerSpecificData?: unknown;
|
||||
body?: unknown;
|
||||
}): boolean {
|
||||
if (!provider?.startsWith("openai-compatible-")) return false;
|
||||
if (sourceFormat !== FORMATS.OPENAI_RESPONSES) return false;
|
||||
if (body !== undefined && !isResponsesShapedBody(body)) return false;
|
||||
if (providerSpecificData && typeof providerSpecificData === "object") {
|
||||
const psd = providerSpecificData as Record<string, unknown>;
|
||||
if (psd.apiType === "responses" || psd._omnirouteForceResponsesUpstream === true) {
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
// Regression test for issue #12129: an internal context-handoff summary request (built in
|
||||
// Chat Completions shape -- `messages`, no `input`) is dispatched through the SAME
|
||||
// handleSingleModel closure that carries the ORIGINAL client request's endpoint.
|
||||
// When that original endpoint matched `/responses` and the resolved handoff-model
|
||||
// provider is an openai-compatible-* connection configured with apiType "responses",
|
||||
// the pipeline used to decide the body was already native-Responses-shaped and skip
|
||||
// chat->responses translation entirely (`_nativeOpenAICompatibleResponsesPassthrough`),
|
||||
// so the upstream received `messages` on `/v1/responses` and rejected it with zero input.
|
||||
//
|
||||
// Fix: `shouldUseNativeOpenAICompatibleResponsesPassthrough` now requires the body to
|
||||
// actually look Responses-shaped (`input` present, `messages` absent) before allowing
|
||||
// the passthrough fast path, so an internally-synthesized chat-shaped body is routed
|
||||
// through the normal chat->responses translation layer instead.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
import { resolveChatCoreRequestFormat } from "../../open-sse/handlers/chatCore/requestFormat.ts";
|
||||
import { shouldUseNativeOpenAICompatibleResponsesPassthrough } from "../../open-sse/handlers/chatCore/passthroughHelpers.ts";
|
||||
|
||||
test("internal chat-shaped handoff body is no longer treated as native Responses passthrough", () => {
|
||||
const clientRawRequest = {
|
||||
endpoint: "/v1/responses",
|
||||
headers: new Headers(),
|
||||
};
|
||||
|
||||
const summaryBody = {
|
||||
model: "some-handoff-model",
|
||||
messages: [{ role: "user", content: "Summarize this conversation." }],
|
||||
stream: false,
|
||||
max_tokens: 800,
|
||||
temperature: 0.1,
|
||||
_omnirouteSkipContextRelay: true,
|
||||
_omnirouteInternalRequest: "context-handoff",
|
||||
};
|
||||
|
||||
const { sourceFormat, endpointPath } = resolveChatCoreRequestFormat({
|
||||
clientRawRequest,
|
||||
body: summaryBody,
|
||||
provider: "openai-compatible-responses-cliproxy",
|
||||
userAgent: null,
|
||||
});
|
||||
|
||||
assert.equal(sourceFormat, "openai-responses");
|
||||
assert.equal(endpointPath, "/v1/responses");
|
||||
|
||||
const providerSpecificData = { apiType: "responses" };
|
||||
|
||||
const nativePassthrough = shouldUseNativeOpenAICompatibleResponsesPassthrough({
|
||||
provider: "openai-compatible-responses-cliproxy",
|
||||
sourceFormat,
|
||||
endpointPath,
|
||||
providerSpecificData,
|
||||
body: summaryBody,
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
nativePassthrough,
|
||||
false,
|
||||
"fixed: chat-shaped internal body must not take the native-Responses passthrough shortcut"
|
||||
);
|
||||
|
||||
assert.equal((summaryBody as Record<string, unknown>).input, undefined);
|
||||
assert.ok(Array.isArray(summaryBody.messages) && summaryBody.messages.length > 0);
|
||||
});
|
||||
|
||||
test("genuine Responses-shaped body still takes the native passthrough fast path", () => {
|
||||
const genuineResponsesBody = {
|
||||
model: "gpt-5.6-sol",
|
||||
input: [{ role: "user", content: [{ type: "input_text", text: "Hello" }] }],
|
||||
stream: false,
|
||||
};
|
||||
|
||||
const nativePassthrough = shouldUseNativeOpenAICompatibleResponsesPassthrough({
|
||||
provider: "openai-compatible-responses-cliproxy",
|
||||
sourceFormat: "openai-responses",
|
||||
endpointPath: "/v1/responses",
|
||||
providerSpecificData: { apiType: "responses" },
|
||||
body: genuineResponsesBody,
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
nativePassthrough,
|
||||
true,
|
||||
"a genuine Responses-shaped client body must keep the zero-translation fast path"
|
||||
);
|
||||
});
|
||||
54
tests/unit/issue-12633-opencode-zen-responses-auth.test.ts
Normal file
54
tests/unit/issue-12633-opencode-zen-responses-auth.test.ts
Normal 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);
|
||||
});
|
||||
33
tests/unit/issue-12681-opencode-muse-spark-context.test.ts
Normal file
33
tests/unit/issue-12681-opencode-muse-spark-context.test.ts
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user