@@ -41,6 +41,18 @@ export function normalizeOpenAIResponsesResponse(response) {
4141 }
4242 if ( item . type === "custom_tool_call" ) {
4343 toolCalls . push ( { kind : "custom" , id : item . call_id , name : item . name , payload : item . input } ) ;
44+ continue ;
45+ }
46+ if ( item . type === "reasoning" ) {
47+ for ( const part of item . content ?? [ ] ) {
48+ parts . push ( { type : "thinking" , thinking : part . text } ) ;
49+ }
50+ for ( const part of item . summary ?? [ ] ) {
51+ parts . push ( { type : "thinking" , thinking : part . text } ) ;
52+ }
53+ if ( item . encrypted_content ) {
54+ parts . push ( { type : "redacted_thinking" , data : item . encrypted_content } ) ;
55+ }
4456 }
4557 }
4658 return {
@@ -64,6 +76,14 @@ export function normalizeAnthropicResponse(response) {
6476 parts . push ( text ( block . text ) ) ;
6577 continue ;
6678 }
79+ if ( block . type === "thinking" ) {
80+ parts . push ( { type : "thinking" , thinking : block . thinking , signature : block . signature } ) ;
81+ continue ;
82+ }
83+ if ( block . type === "redacted_thinking" ) {
84+ parts . push ( { type : "redacted_thinking" , data : block . data } ) ;
85+ continue ;
86+ }
6787 if ( block . type === "tool_use" || block . type === "server_tool_use" ) {
6888 toolCalls . push ( {
6989 kind : "function" ,
@@ -116,20 +136,38 @@ export function denormalizeToOpenAIResponsesResponse(response) {
116136 object : "response" ,
117137 created_at : response . createdAt ,
118138 model : response . model ,
119- output_text : collapseText ( response . message . parts ) ,
139+ output_text : collapseText ( response . message . parts . filter ( ( part ) => part . type === "text" || part . type === "refusal" ) ) ,
120140 error : null ,
121141 incomplete_details : null ,
122142 instructions : null ,
123143 metadata : null ,
124144 output : [
145+ ...response . message . parts
146+ . filter ( ( part ) => part . type === "thinking" || part . type === "redacted_thinking" )
147+ . map ( ( part , index ) => part . type === "thinking"
148+ ? {
149+ id : `reasoning_${ index } ` ,
150+ type : "reasoning" ,
151+ summary : [ { type : "summary_text" , text : part . thinking } ] ,
152+ content : [ { type : "reasoning_text" , text : part . thinking } ] ,
153+ encrypted_content : part . signature ?? null ,
154+ status : "completed" ,
155+ }
156+ : {
157+ id : `reasoning_${ index } ` ,
158+ type : "reasoning" ,
159+ summary : [ ] ,
160+ encrypted_content : part . data ,
161+ status : "completed" ,
162+ } ) ,
125163 ...( response . message . parts . length > 0
126164 ? [
127165 {
128166 id : "msg_1" ,
129167 type : "message" ,
130168 role : "assistant" ,
131169 status : "completed" ,
132- content : response . message . parts . map ( ( part ) => part . type === "text"
170+ content : response . message . parts . filter ( ( part ) => part . type !== "thinking" && part . type !== "redacted_thinking" ) . map ( ( part ) => part . type === "text"
133171 ? { type : "output_text" , text : part . text , annotations : [ ] }
134172 : { type : "refusal" , refusal : part . text } ) ,
135173 } ,
0 commit comments