fix(codex): use user-agent detection for Droid CLI compatibility

The previous merge used sourceFormat check which broke Cursor when it
sends openai-responses format requests. Now uses user-agent detection:
- Droid CLI (user-agent contains 'droid' or 'codex-cli') → passthrough
- Other clients (Cursor, etc.) → translate to Chat Completions format

This fixes the API translation for both clients.

Co-authored-by: Hellodebasishsahu <itsyourboydevil@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Hellodebasishsahu
2026-02-06 15:02:56 +07:00
committed by decolua
parent fafa77316b
commit 8c6e3b8b62

View File

@@ -469,10 +469,11 @@ export async function handleChatCore({ body, modelInfo, credentials, log, onCred
// Create transform stream with logger for streaming response
let transformStream;
// For Codex provider, translate response from openai-responses to openai (Chat Completions) format
// UNLESS client originally sent in openai-responses format (like Droid CLI) - they expect same format back
const needsCodexTranslation = provider === 'codex'
&& targetFormat === 'openai-responses'
&& sourceFormat !== 'openai-responses';
// UNLESS client is Droid CLI which expects openai-responses format back
const isDroidCLI = userAgent?.toLowerCase().includes('droid') || userAgent?.toLowerCase().includes('codex-cli');
const needsCodexTranslation = provider === 'codex'
&& targetFormat === 'openai-responses'
&& !isDroidCLI;
if (needsCodexTranslation) {
// Codex returns openai-responses, translate to openai (Chat Completions) that clients expect