@@ -50,6 +50,22 @@ describe("prepareApiConversationMessage", () => {
5050 ] )
5151 } )
5252
53+ it ( "falls back to generic reasoning blocks for Anthropic messages without thought signatures" , ( ) => {
54+ const result = prepareApiConversationMessage ( {
55+ message : { role : "assistant" , content : "answer" } ,
56+ reasoning : "private reasoning" ,
57+ api : { } as any ,
58+ apiConfiguration : { apiProvider : "anthropic" , apiModelId : "claude-3-5-sonnet" } as any ,
59+ apiConversationHistory : [ ] ,
60+ } ) as any
61+
62+ expect ( result . content ) . toEqual ( [
63+ { type : "reasoning" , text : "private reasoning" , summary : [ ] } ,
64+ { type : "text" , text : "answer" } ,
65+ ] )
66+ expect ( result . ts ) . toBe ( Date . now ( ) )
67+ } )
68+
5369 it ( "preserves encrypted reasoning content" , ( ) => {
5470 const result = prepareApiConversationMessage ( {
5571 message : { role : "assistant" , content : [ { type : "text" , text : "answer" } ] } ,
@@ -103,4 +119,25 @@ describe("prepareApiConversationMessage", () => {
103119 expect ( result . content ) . toEqual ( [ { type : "tool_result" , tool_use_id : "tool-1" , content : "done" } ] )
104120 expect ( result . ts ) . toBe ( Date . now ( ) )
105121 } )
122+
123+ it ( "converts user tool_result blocks to text when the last effective message is not assistant" , ( ) => {
124+ const result = prepareApiConversationMessage ( {
125+ message : {
126+ role : "user" ,
127+ content : [
128+ { type : "tool_result" , tool_use_id : "tool-1" , content : "done" } ,
129+ { type : "text" , text : "next step" } ,
130+ ] ,
131+ } ,
132+ api : { } as any ,
133+ apiConfiguration : { apiProvider : "openrouter" , openRouterModelId : "openai/gpt-4" } as any ,
134+ apiConversationHistory : [ { role : "user" , content : "previous user message" } as any ] ,
135+ } ) as any
136+
137+ expect ( result . content ) . toEqual ( [
138+ { type : "text" , text : "Tool result:\ndone" } ,
139+ { type : "text" , text : "next step" } ,
140+ ] )
141+ expect ( result . ts ) . toBe ( Date . now ( ) )
142+ } )
106143} )
0 commit comments