@@ -31,6 +31,7 @@ type ConvertCodexResponseToClaudeParams struct {
3131 ThinkingBlockOpen bool
3232 ThinkingStopPending bool
3333 ThinkingSignature string
34+ ThinkingSummarySeen bool
3435}
3536
3637// ConvertCodexResponseToClaude performs sophisticated streaming response format conversion.
@@ -86,12 +87,8 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
8687 if params .ThinkingBlockOpen && params .ThinkingStopPending {
8788 output = append (output , finalizeCodexThinkingBlock (params )... )
8889 }
89- template = []byte (`{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":""}}` )
90- template , _ = sjson .SetBytes (template , "index" , params .BlockIndex )
91- params .ThinkingBlockOpen = true
92- params .ThinkingStopPending = false
93-
94- output = translatorcommon .AppendSSEEventBytes (output , "content_block_start" , template , 2 )
90+ params .ThinkingSummarySeen = true
91+ output = append (output , startCodexThinkingBlock (params )... )
9592 } else if typeStr == "response.reasoning_summary_text.delta" {
9693 template = []byte (`{"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":""}}` )
9794 template , _ = sjson .SetBytes (template , "index" , params .BlockIndex )
@@ -100,9 +97,6 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
10097 output = translatorcommon .AppendSSEEventBytes (output , "content_block_delta" , template , 2 )
10198 } else if typeStr == "response.reasoning_summary_part.done" {
10299 params .ThinkingStopPending = true
103- if params .ThinkingSignature != "" {
104- output = append (output , finalizeCodexThinkingBlock (params )... )
105- }
106100 } else if typeStr == "response.content_part.added" {
107101 template = []byte (`{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}` )
108102 template , _ = sjson .SetBytes (template , "index" , params .BlockIndex )
@@ -169,10 +163,8 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
169163
170164 output = translatorcommon .AppendSSEEventBytes (output , "content_block_delta" , template , 2 )
171165 } else if itemType == "reasoning" {
166+ params .ThinkingSummarySeen = false
172167 params .ThinkingSignature = itemResult .Get ("encrypted_content" ).String ()
173- if params .ThinkingStopPending {
174- output = append (output , finalizeCodexThinkingBlock (params )... )
175- }
176168 }
177169 } else if typeStr == "response.output_item.done" {
178170 itemResult := rootResult .Get ("item" )
@@ -229,8 +221,13 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
229221 if signature := itemResult .Get ("encrypted_content" ).String (); signature != "" {
230222 params .ThinkingSignature = signature
231223 }
232- output = append (output , finalizeCodexThinkingBlock (params )... )
224+ if params .ThinkingSummarySeen {
225+ output = append (output , finalizeCodexThinkingBlock (params )... )
226+ } else {
227+ output = append (output , finalizeCodexSignatureOnlyThinkingBlock (params )... )
228+ }
233229 params .ThinkingSignature = ""
230+ params .ThinkingSummarySeen = false
234231 }
235232 } else if typeStr == "response.function_call_arguments.delta" {
236233 params .HasReceivedArgumentsDelta = true
@@ -437,6 +434,29 @@ func ClaudeTokenCount(_ context.Context, count int64) []byte {
437434 return translatorcommon .ClaudeInputTokensJSON (count )
438435}
439436
437+ func startCodexThinkingBlock (params * ConvertCodexResponseToClaudeParams ) []byte {
438+ if params .ThinkingBlockOpen {
439+ return nil
440+ }
441+
442+ template := []byte (`{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":""}}` )
443+ template , _ = sjson .SetBytes (template , "index" , params .BlockIndex )
444+ params .ThinkingBlockOpen = true
445+ params .ThinkingStopPending = false
446+
447+ return translatorcommon .AppendSSEEventBytes (nil , "content_block_start" , template , 2 )
448+ }
449+
450+ func finalizeCodexSignatureOnlyThinkingBlock (params * ConvertCodexResponseToClaudeParams ) []byte {
451+ if params .ThinkingSignature == "" {
452+ return nil
453+ }
454+
455+ output := startCodexThinkingBlock (params )
456+ output = append (output , finalizeCodexThinkingBlock (params )... )
457+ return output
458+ }
459+
440460func finalizeCodexThinkingBlock (params * ConvertCodexResponseToClaudeParams ) []byte {
441461 if ! params .ThinkingBlockOpen {
442462 return nil
0 commit comments