mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-11 01:13:02 +03:00
Compare commits
1 Commits
fix/12251-
...
fix/12129-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1430ded910 |
@@ -0,0 +1 @@
|
||||
- fix(sse): require Responses-shaped body before native OpenAI-compatible passthrough (#12129)
|
||||
@@ -1 +0,0 @@
|
||||
- fix(dashboard): allow deleting the last extra-upstream-header row even when invalid (#12251)
|
||||
@@ -731,6 +731,7 @@ export async function handleChatCore({
|
||||
sourceFormat,
|
||||
endpointPath,
|
||||
providerSpecificData: credentials?.providerSpecificData,
|
||||
body,
|
||||
});
|
||||
const responsesInputItems = Array.isArray(body?.input) ? body.input : [];
|
||||
const customToolNames = collectCustomToolNamesForSourceFormat(
|
||||
|
||||
@@ -53,19 +53,35 @@ 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) {
|
||||
|
||||
@@ -707,10 +707,7 @@ export default function ModelCompatPopover({
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
disabled={
|
||||
disabled ||
|
||||
(headerRows.length <= 1 && !row.name.trim() && !row.value.trim())
|
||||
}
|
||||
disabled={disabled || headerRows.length <= 1}
|
||||
onClick={() => removeHeaderRow(row.id)}
|
||||
title={t("compatUpstreamRemoveRow")}
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-border/80 text-text-muted hover:bg-red-500/10 hover:text-red-600 dark:hover:text-red-400 disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-text-muted transition-colors"
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
// Repro for #12251
|
||||
import React, { act } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import ModelCompatPopover from "../ModelCompatPopover";
|
||||
|
||||
vi.mock("next-intl", () => ({
|
||||
useTranslations: () => (key: string) => key,
|
||||
}));
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let root: Root;
|
||||
|
||||
async function flushEffects() {
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
async function openPopover() {
|
||||
const trigger = container.querySelector("button") as HTMLButtonElement;
|
||||
await act(async () => trigger.click());
|
||||
await flushEffects();
|
||||
}
|
||||
|
||||
describe("ModelCompatPopover upstream headers — invalid single row cannot be deleted (#12251)", () => {
|
||||
beforeEach(() => {
|
||||
(
|
||||
globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
||||
).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
act(() => root.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("lets the user delete the invalid header via the delete icon when it is the ONLY row present", async () => {
|
||||
const onCompatPatch = vi.fn();
|
||||
|
||||
act(() => {
|
||||
root.render(
|
||||
<ModelCompatPopover
|
||||
t={(key) => key}
|
||||
providerId="openai"
|
||||
modelId="gpt-test"
|
||||
effectiveModelNormalize={() => false}
|
||||
effectiveModelPreserveDeveloper={() => true}
|
||||
getUpstreamHeadersRecord={() => ({
|
||||
"https://evil.example.com/callback": "some-secret-value",
|
||||
})}
|
||||
onCompatPatch={onCompatPatch}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
await openPopover();
|
||||
|
||||
const nameInput = document.querySelector(
|
||||
'input[placeholder="compatUpstreamHeaderNamePlaceholder"]'
|
||||
) as HTMLInputElement;
|
||||
expect(nameInput).toBeTruthy();
|
||||
expect(nameInput.value).toBe("https://evil.example.com/callback");
|
||||
|
||||
const rowButtons = document.querySelectorAll('button[title="compatUpstreamRemoveRow"]');
|
||||
expect(rowButtons.length).toBe(1);
|
||||
|
||||
const removeButton = rowButtons[0] as HTMLButtonElement;
|
||||
|
||||
// EXPECTED (fixed) behavior: a populated row should always be removable via
|
||||
// its own delete icon, even when it is the only row.
|
||||
expect(removeButton.disabled).toBe(false);
|
||||
|
||||
await act(async () => removeButton.click());
|
||||
await flushEffects();
|
||||
|
||||
expect(onCompatPatch).toHaveBeenCalledWith("openai", { upstreamHeaders: {} });
|
||||
});
|
||||
|
||||
it("keeps the delete button disabled when the sole row is genuinely blank", async () => {
|
||||
const onCompatPatch = vi.fn();
|
||||
|
||||
act(() => {
|
||||
root.render(
|
||||
<ModelCompatPopover
|
||||
t={(key) => key}
|
||||
providerId="openai"
|
||||
modelId="gpt-test"
|
||||
effectiveModelNormalize={() => false}
|
||||
effectiveModelPreserveDeveloper={() => true}
|
||||
getUpstreamHeadersRecord={() => ({})}
|
||||
onCompatPatch={onCompatPatch}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
await openPopover();
|
||||
|
||||
const rowButtons = document.querySelectorAll('button[title="compatUpstreamRemoveRow"]');
|
||||
expect(rowButtons.length).toBe(1);
|
||||
|
||||
const removeButton = rowButtons[0] as HTMLButtonElement;
|
||||
|
||||
// A blank sole row must stay non-deletable so the form always shows an
|
||||
// editable add-affordance.
|
||||
expect(removeButton.disabled).toBe(true);
|
||||
});
|
||||
});
|
||||
86
tests/unit/context-handoff-native-passthrough-bug.test.ts
Normal file
86
tests/unit/context-handoff-native-passthrough-bug.test.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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"
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user