* Translates a complete Anthropic API request body to Codex format. * @param anthropicBody - The Anthropic request body to translate * @returns Object containing the translated Codex body and model
(anthropicBody: Record<string, unknown>)
| 220 | * @returns Object containing the translated Codex body and model |
| 221 | */ |
| 222 | function translateToCodexBody(anthropicBody: Record<string, unknown>): { |
| 223 | codexBody: Record<string, unknown> |
| 224 | codexModel: string |
| 225 | } { |
| 226 | const anthropicMessages = (anthropicBody.messages || []) as AnthropicMessage[] |
| 227 | const systemPrompt = anthropicBody.system as |
| 228 | | string |
| 229 | | Array<{ type: string; text?: string; cache_control?: unknown }> |
| 230 | | undefined |
| 231 | const claudeModel = anthropicBody.model as string |
| 232 | const anthropicTools = (anthropicBody.tools || []) as AnthropicTool[] |
| 233 | |
| 234 | const codexModel = mapClaudeModelToCodex(claudeModel) |
| 235 | |
| 236 | // Build system instructions |
| 237 | let instructions = '' |
| 238 | if (systemPrompt) { |
| 239 | instructions = |
| 240 | typeof systemPrompt === 'string' |
| 241 | ? systemPrompt |
| 242 | : Array.isArray(systemPrompt) |
| 243 | ? systemPrompt |
| 244 | .filter(b => b.type === 'text' && typeof b.text === 'string') |
| 245 | .map(b => b.text!) |
| 246 | .join('\n') |
| 247 | : '' |
| 248 | } |
| 249 | |
| 250 | // Convert messages |
| 251 | const input = translateMessages(anthropicMessages) |
| 252 | |
| 253 | const codexBody: Record<string, unknown> = { |
| 254 | model: codexModel, |
| 255 | store: false, |
| 256 | stream: true, |
| 257 | instructions, |
| 258 | input, |
| 259 | tool_choice: 'auto', |
| 260 | parallel_tool_calls: true, |
| 261 | } |
| 262 | |
| 263 | // Add tools if present |
| 264 | if (anthropicTools.length > 0) { |
| 265 | codexBody.tools = translateTools(anthropicTools) |
| 266 | } |
| 267 | |
| 268 | return { codexBody, codexModel } |
| 269 | } |
| 270 | |
| 271 | // ── Response translation: Codex SSE → Anthropic SSE ───────────────── |
| 272 |
no test coverage detected