mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(headroom): translate openai-responses input through OpenAI for compression
Codex (openai-responses) body.input holds Responses items, not OpenAI messages. Translate input -> OpenAI -> compress -> back to input so the Responses contract is preserved. Fixes #1998 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
fb543a1f39
commit
d4d11357ab
@@ -1,5 +1,9 @@
|
||||
import { claudeToOpenAIRequest } from "../translator/request/claude-to-openai.js";
|
||||
import { openaiToClaudeRequest } from "../translator/request/openai-to-claude.js";
|
||||
import {
|
||||
openaiResponsesToOpenAIRequest,
|
||||
openaiToOpenAIResponsesRequest,
|
||||
} from "../translator/request/openai-responses.js";
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 3000;
|
||||
|
||||
@@ -135,6 +139,26 @@ export async function compressWithHeadroom(body, { enabled, url, model, format,
|
||||
return data;
|
||||
}
|
||||
|
||||
// OpenAI Responses shape (Codex): body.input holds Responses items, NOT OpenAI
|
||||
// messages. Translate input -> OpenAI -> compress -> translate back to input so
|
||||
// body.input keeps the Responses contract (the proxy only understands OpenAI). (#1998)
|
||||
if (format === "openai-responses") {
|
||||
const oai = openaiResponsesToOpenAIRequest(model, body, false);
|
||||
if (!Array.isArray(oai?.messages)) return null;
|
||||
const data = await callCompress(url, oai.messages, model, timeoutMs, compressUserMessages, diagnostics || {});
|
||||
if (!data) return null;
|
||||
// input: undefined so the translator rebuilds input from the compressed
|
||||
// messages instead of returning the original input unchanged.
|
||||
const responsesBody = openaiToOpenAIResponsesRequest(
|
||||
model,
|
||||
{ ...oai, input: undefined, messages: data.messages },
|
||||
false
|
||||
);
|
||||
if (Array.isArray(responsesBody?.input)) body.input = responsesBody.input;
|
||||
if (diagnostics) diagnostics.after = captureSizeSnapshot(body);
|
||||
return data;
|
||||
}
|
||||
|
||||
// OpenAI shape: messages/input go straight to the proxy.
|
||||
const key = Array.isArray(body.messages) ? "messages"
|
||||
: Array.isArray(body.input) ? "input"
|
||||
|
||||
Reference in New Issue
Block a user