@@ -81,6 +81,54 @@ describe("NativeOllamaHandler", () => {
8181 expect ( results [ 2 ] ) . toEqual ( { type : "usage" , inputTokens : 10 , outputTokens : 2 } )
8282 } )
8383
84+ it ( "should map tool_result array content to a concatenated string (text kept, others dropped)" , async ( ) => {
85+ mockChat . mockImplementation ( async function * ( ) {
86+ yield { message : { content : "ok" } }
87+ } )
88+
89+ const messages = [
90+ {
91+ role : "user" as const ,
92+ content : [
93+ {
94+ type : "tool_result" as const ,
95+ tool_use_id : "tool-1" ,
96+ content : [
97+ { type : "text" as const , text : "line one" } ,
98+ // Non-text block (document) should be dropped to ""
99+ {
100+ type : "document" as const ,
101+ source : {
102+ type : "base64" as const ,
103+ media_type : "application/pdf" ,
104+ data : "abc" ,
105+ } as const ,
106+ } ,
107+ { type : "text" as const , text : "line two" } ,
108+ ] ,
109+ } ,
110+ ] ,
111+ } ,
112+ ]
113+
114+ const stream = handler . createMessage ( "System" , messages )
115+ for await ( const _ of stream ) {
116+ // consume stream
117+ }
118+
119+ // Text blocks are joined with "\n"; the non-text block contributes ""
120+ expect ( mockChat ) . toHaveBeenCalledWith (
121+ expect . objectContaining ( {
122+ messages : expect . arrayContaining ( [
123+ expect . objectContaining ( {
124+ role : "user" ,
125+ content : "line one\n\nline two" ,
126+ } ) ,
127+ ] ) ,
128+ } ) ,
129+ )
130+ } )
131+
84132 it ( "should not include num_ctx by default" , async ( ) => {
85133 // Mock the chat response
86134 mockChat . mockImplementation ( async function * ( ) {
0 commit comments