mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix(codex): apply global service tiers to combo request bodies
This commit is contained in:
@@ -130,8 +130,8 @@ export interface ApplyCodexGlobalFastServiceTierOptions {
|
||||
*/
|
||||
model?: string | null;
|
||||
/**
|
||||
* Outbound request body. Per-request body.service_tier is left untouched if
|
||||
* already set.
|
||||
* Outbound request body. A valid per-request body.service_tier is left untouched
|
||||
* when already set.
|
||||
*/
|
||||
body?: Record<string, unknown> | null;
|
||||
}
|
||||
@@ -188,12 +188,11 @@ export function applyCodexGlobalFastServiceTier<T extends JsonRecord | null | un
|
||||
} as T;
|
||||
}
|
||||
|
||||
if (resolved.tier === "flex") {
|
||||
// Write the wire value directly to the outbound body when possible. The executor
|
||||
// also accepts requestDefaults.serviceTier = "flex" for downstream accounting.
|
||||
if (body && typeof body === "object" && !Array.isArray(body)) {
|
||||
(body as JsonRecord).service_tier = "flex";
|
||||
}
|
||||
if (body && typeof body === "object" && !Array.isArray(body)) {
|
||||
// Write the wire value directly to the outbound body when possible, so combo
|
||||
// request previews and logs show the same effective tier that the executor sends.
|
||||
// The executor also accepts requestDefaults.serviceTier for downstream accounting.
|
||||
(body as JsonRecord).service_tier = resolved.tier;
|
||||
}
|
||||
|
||||
// Intentional precedence: body service_tier > global mode > connection defaults.
|
||||
|
||||
@@ -606,6 +606,47 @@ test("chat pipeline persists Codex responses cache and reasoning tokens to call
|
||||
assert.equal(callLog.tokens.reasoning, 13);
|
||||
});
|
||||
|
||||
test("chat pipeline applies global Codex priority service tier inside combos", async () => {
|
||||
await seedConnection("codex", { apiKey: "sk-codex-combo-priority" });
|
||||
await settingsDb.updateSettings({
|
||||
codexServiceTier: { enabled: true, tier: "priority" },
|
||||
});
|
||||
await combosDb.createCombo({
|
||||
name: "codex-priority-combo",
|
||||
strategy: "priority",
|
||||
config: { maxRetries: 0, retryDelayMs: 0 },
|
||||
models: ["codex/gpt-5.5"],
|
||||
});
|
||||
const fetchCalls = [];
|
||||
|
||||
globalThis.fetch = async (url, init: RequestInit = {}) => {
|
||||
fetchCalls.push({
|
||||
url: String(url),
|
||||
headers: toPlainHeaders(init.headers),
|
||||
body: init.body ? JSON.parse(String(init.body)) : null,
|
||||
});
|
||||
return buildOpenAIResponsesSSE({ text: "combo priority ok", model: "gpt-5.5" });
|
||||
};
|
||||
|
||||
const response = await handleChat(
|
||||
buildRequest({
|
||||
body: {
|
||||
model: "codex-priority-combo",
|
||||
stream: false,
|
||||
messages: [{ role: "user", content: "Use Codex combo priority" }],
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const json = (await response.json()) as any;
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(fetchCalls.length, 1);
|
||||
assert.match(fetchCalls[0].url, /\/responses$/);
|
||||
assert.equal(fetchCalls[0].headers.Authorization, "Bearer sk-codex-combo-priority");
|
||||
assert.equal(fetchCalls[0].body.service_tier, "priority");
|
||||
assert.equal(json.choices[0].message.content, "combo priority ok");
|
||||
});
|
||||
|
||||
test("chat pipeline applies Codex CLI fingerprint to OAuth responses requests", async () => {
|
||||
setCliCompatProviders(["codex"]);
|
||||
await seedConnection("codex", {
|
||||
@@ -950,12 +991,7 @@ test("chat pipeline sends Gemini CLI OAuth requests with native Cloud Code trans
|
||||
assert.equal(generateCall.body.requestId, undefined);
|
||||
assert.equal(generateCall.body.user_prompt_id, generateCall.body.request.session_id);
|
||||
const keys = Object.keys(generateCall.body).slice(0, 4);
|
||||
assert.deepEqual(keys.sort(), [
|
||||
"model",
|
||||
"project",
|
||||
"request",
|
||||
"user_prompt_id",
|
||||
]);
|
||||
assert.deepEqual(keys.sort(), ["model", "project", "request", "user_prompt_id"]);
|
||||
assert.equal(generateCall.body.request.sessionId, undefined);
|
||||
assert.match(generateCall.body.request.session_id, /^[0-9a-f-]{36}$/i);
|
||||
assert.equal(generateCall.body.request.contents.at(-1).parts[0].text, "Hello Gemini CLI");
|
||||
|
||||
@@ -106,15 +106,17 @@ test("Codex global service tier injects selected mode and can override connectio
|
||||
});
|
||||
|
||||
test("Codex global service tier matches provider-prefixed combo model ids", () => {
|
||||
const body: Record<string, unknown> = {};
|
||||
assert.deepEqual(
|
||||
applyCodexGlobalFastServiceTier(
|
||||
"codex",
|
||||
{ providerSpecificData: {} },
|
||||
{ codexServiceTier: { enabled: true, tier: "priority" } },
|
||||
{ model: "codex/gpt-5.5" }
|
||||
{ model: "codex/gpt-5.5", body }
|
||||
),
|
||||
{ providerSpecificData: { requestDefaults: { serviceTier: "priority" } } }
|
||||
);
|
||||
assert.equal(body.service_tier, "priority");
|
||||
|
||||
const unsupported = { providerSpecificData: {} };
|
||||
assert.equal(
|
||||
@@ -155,7 +157,7 @@ test("Codex global service tier only short-circuits on valid body service_tier",
|
||||
assert.deepEqual(injected, {
|
||||
providerSpecificData: { requestDefaults: { serviceTier: "priority" } },
|
||||
});
|
||||
assert.equal(invalidBody.service_tier, "invalid");
|
||||
assert.equal(invalidBody.service_tier, "priority");
|
||||
|
||||
const validBody: Record<string, unknown> = { service_tier: " Flex " };
|
||||
const unchanged = { providerSpecificData: {} };
|
||||
|
||||
Reference in New Issue
Block a user