@@ -49,6 +49,7 @@ import { resolveHttpProxyUrlForTarget } from "../utils/node-http-proxy.ts";
4949import { extractOpenAiCodexAccountId } from "../utils/openai-codex-auth.ts" ;
5050import { uuidv7 } from "../utils/uuid.ts" ;
5151import { createGrammarToolInputProperties } from "./constrained-sampling.ts" ;
52+ import { buildCodexReasoning , type CodexReasoningSummaryInput } from "./openai-codex-responses/reasoning.ts" ;
5253import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.ts" ;
5354import { convertResponsesMessages , convertResponsesTools , processResponsesStream } from "./openai-responses-shared.ts" ;
5455import {
@@ -91,7 +92,7 @@ const CODEX_RESPONSE_STATUSES = new Set<CodexResponseStatus>([
9192
9293export interface OpenAICodexResponsesOptions extends StreamOptions {
9394 reasoningEffort ?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" ;
94- reasoningSummary ?: "auto" | "concise" | "detailed" | "off" | "on" | null ;
95+ reasoningSummary ?: CodexReasoningSummaryInput ;
9596 serviceTier ?: ResponseCreateParamsStreaming [ "service_tier" ] ;
9697 textVerbosity ?: "low" | "medium" | "high" ;
9798 toolChoice ?: "auto" | "none" | "required" ;
@@ -110,7 +111,7 @@ interface RequestBody {
110111 tool_choice ?: OpenAICodexResponsesOptions [ "toolChoice" ] ;
111112 parallel_tool_calls ?: boolean ;
112113 temperature ?: number ;
113- reasoning ?: { effort ?: string ; summary ?: string } ;
114+ reasoning ?: ReturnType < typeof buildCodexReasoning > ;
114115 service_tier ?: ResponseCreateParamsStreaming [ "service_tier" ] ;
115116 text ?: { verbosity ?: string } ;
116117 include ?: string [ ] ;
@@ -595,17 +596,13 @@ function buildRequestBody(
595596 } ) ;
596597 }
597598
598- if ( reasoningEffort !== undefined && reasoningEffort !== null ) {
599- body . reasoning = {
600- effort : reasoningEffort ,
601- summary : options ?. reasoningSummary === null ? "off" : ( options ?. reasoningSummary ?? "auto" ) ,
602- } ;
603- } else if ( reasoningEffort === undefined && model . reasoning && model . thinkingLevelMap ?. off !== null ) {
604- body . reasoning = {
605- effort : model . thinkingLevelMap ?. off ?? "none" ,
606- summary : options ?. reasoningSummary === null ? "off" : ( options ?. reasoningSummary ?? "auto" ) ,
607- } ;
608- }
599+ const reasoning = buildCodexReasoning (
600+ reasoningEffort ,
601+ options ?. reasoningSummary ,
602+ model . reasoning ,
603+ model . thinkingLevelMap ?. off ,
604+ ) ;
605+ if ( reasoning ) body . reasoning = reasoning ;
609606
610607 applyExtraBody ( body , options ?. extraBody , OPENAI_RESPONSES_RESERVED_BODY_KEYS ) ;
611608
0 commit comments