feat(proxy): session-based prompt_cache_key routing for Codex Chat bridge

Codex always sends prompt_cache_key in its Responses requests, but the
Responses -> Chat Completions conversion dropped it, breaking session
cache affinity on upstreams that route by key (e.g. Kimi Coding).

- Re-inject prompt_cache_key after conversion in the forwarder: an
  explicit client key wins, otherwise a client-provided session ID;
  generated per-request UUIDs are never sent upstream.
- Provider-aware gating: "auto" enables only known-compatible upstreams
  (api.openai.com, api.kimi.com/coding) because strict gateways reject
  unknown fields with HTTP 400 (e.g. Fireworks); an advanced
  Auto/Enabled/Disabled override is available on the Codex form in all
  four locales.
- Kimi For Coding preset opts in explicitly.
This commit is contained in:
Jason
2026-07-11 21:42:43 +08:00
parent 0e563b50c5
commit a078b4b207
14 changed files with 295 additions and 4 deletions
@@ -129,6 +129,14 @@ const expectedChatPresets = new Map<
]);
describe("Codex Chat provider presets", () => {
it("enables session-based prompt cache routing for Kimi Coding", () => {
const preset = codexProviderPresets.find(
(item) => item.name === "Kimi For Coding",
);
expect(preset?.promptCacheRouting).toBe("enabled");
});
it("marks migrated Chat Completions presets for local routing", () => {
for (const [name, expected] of expectedChatPresets) {
const preset = codexProviderPresets.find((item) => item.name === name);