@@ -207,6 +207,58 @@ describe("claude outbound SSE", () => {
207207 expect ( startIndexes ) . toEqual ( [ 0 , 1 , 2 ] ) ;
208208 } ) ;
209209
210+ test ( "multi-part reasoning summaries keep the JSON path's part separator" , async ( ) => {
211+ const upstream = [
212+ sse ( "response.created" , { response : { id : "resp_1" , status : "in_progress" } } ) ,
213+ sse ( "response.output_item.added" , { output_index : 0 , item : { type : "reasoning" , id : "rs_1" } } ) ,
214+ sse ( "response.reasoning_summary_part.added" , { item_id : "rs_1" , output_index : 0 , summary_index : 0 , part : { type : "summary_text" , text : "" } } ) ,
215+ sse ( "response.reasoning_summary_text.delta" , { item_id : "rs_1" , output_index : 0 , summary_index : 0 , delta : "**A**\n\nOne." } ) ,
216+ sse ( "response.reasoning_summary_part.added" , { item_id : "rs_1" , output_index : 0 , summary_index : 1 , part : { type : "summary_text" , text : "" } } ) ,
217+ sse ( "response.reasoning_summary_text.delta" , { item_id : "rs_1" , output_index : 0 , summary_index : 1 , delta : "**B**\n\nTwo." } ) ,
218+ sse ( "response.output_item.done" , { output_index : 0 , item : { type : "reasoning" , id : "rs_1" } } ) ,
219+ sse ( "response.output_item.added" , { output_index : 1 , item : { type : "reasoning" , id : "rs_2" } } ) ,
220+ sse ( "response.reasoning_summary_text.delta" , { item_id : "rs_2" , output_index : 1 , summary_index : 0 , delta : "Three." } ) ,
221+ sse ( "response.completed" , { response : { status : "completed" , usage : { input_tokens : 1 , output_tokens : 1 } } } ) ,
222+ ] . join ( "" ) ;
223+ const msg = await collectAnthropicMessage ( responsesSseToAnthropicSse ( streamFrom ( upstream ) , "m" ) , "m" ) as Record < string , any > ;
224+ // Parts within an item are separated; a new reasoning item opens its own block.
225+ const thinkingBlocks = msg . content . filter ( ( b : Record < string , unknown > ) => b . type === "thinking" ) ;
226+ expect ( thinkingBlocks . map ( ( b : Record < string , unknown > ) => b . thinking ) ) . toEqual ( [
227+ "**A**\n\nOne.\n\n**B**\n\nTwo." ,
228+ "Three." ,
229+ ] ) ;
230+
231+ // Parity: the non-streaming translator joins the same summary parts identically.
232+ const json = responsesJsonToAnthropicMessage ( {
233+ id : "resp_1" ,
234+ status : "completed" ,
235+ output : [ { type : "reasoning" , id : "rs_1" , summary : [ { type : "summary_text" , text : "**A**\n\nOne." } , { type : "summary_text" , text : "**B**\n\nTwo." } ] } ] ,
236+ usage : { input_tokens : 1 , output_tokens : 1 } ,
237+ } , "m" ) as Record < string , any > ;
238+ const jsonThinking = json . content . find ( ( b : Record < string , unknown > ) => b . type === "thinking" ) ;
239+ expect ( jsonThinking . thinking ) . toBe ( "**A**\n\nOne.\n\n**B**\n\nTwo." ) ;
240+ } ) ;
241+
242+ test ( "same-part deltas and index-free reasoning frames never get a separator" , async ( ) => {
243+ const samePart = [
244+ sse ( "response.created" , { response : { id : "resp_1" , status : "in_progress" } } ) ,
245+ sse ( "response.reasoning_summary_text.delta" , { item_id : "rs_1" , output_index : 0 , summary_index : 0 , delta : "Hel" } ) ,
246+ sse ( "response.reasoning_summary_text.delta" , { item_id : "rs_1" , output_index : 0 , summary_index : 0 , delta : "lo" } ) ,
247+ sse ( "response.completed" , { response : { status : "completed" , usage : { input_tokens : 1 , output_tokens : 1 } } } ) ,
248+ ] . join ( "" ) ;
249+ const msg1 = await collectAnthropicMessage ( responsesSseToAnthropicSse ( streamFrom ( samePart ) , "m" ) , "m" ) as Record < string , any > ;
250+ expect ( msg1 . content . find ( ( b : Record < string , unknown > ) => b . type === "thinking" ) . thinking ) . toBe ( "Hello" ) ;
251+
252+ const indexFree = [
253+ sse ( "response.created" , { response : { id : "resp_1" , status : "in_progress" } } ) ,
254+ sse ( "response.reasoning_text.delta" , { delta : "A" } ) ,
255+ sse ( "response.reasoning_text.delta" , { delta : "B" } ) ,
256+ sse ( "response.completed" , { response : { status : "completed" , usage : { input_tokens : 1 , output_tokens : 1 } } } ) ,
257+ ] . join ( "" ) ;
258+ const msg2 = await collectAnthropicMessage ( responsesSseToAnthropicSse ( streamFrom ( indexFree ) , "m" ) , "m" ) as Record < string , any > ;
259+ expect ( msg2 . content . find ( ( b : Record < string , unknown > ) => b . type === "thinking" ) . thinking ) . toBe ( "AB" ) ;
260+ } ) ;
261+
210262 test ( "data-only Responses frames infer event names from payload types" , async ( ) => {
211263 const upstream = [
212264 dataOnlySse ( { type : "response.created" , response : { id : "resp_data_only" , status : "in_progress" } } ) ,
0 commit comments