@@ -239,7 +239,10 @@ async function main() {
239239 async execute ( _input ) {
240240 spinner . stop ( ) ;
241241 console . log ( formatToolCall ( "time" , "" ) ) ;
242- return new Date ( ) . toLocaleTimeString ( ) ;
242+ return {
243+ type : "text" as const ,
244+ value : new Date ( ) . toLocaleTimeString ( ) ,
245+ } ;
243246 } ,
244247 } ) ,
245248 convert_to_celsius : tool ( {
@@ -267,7 +270,7 @@ async function main() {
267270 chalk . green ( `${ input . temperature } °F = ${ celsius } °C` )
268271 ) ;
269272
270- return `${ celsius } °C` ;
273+ return { type : "text" as const , value : `${ celsius } °C` } ;
271274 } ,
272275 } ) ,
273276
@@ -302,7 +305,11 @@ async function main() {
302305 locationSpinner . fail (
303306 chalk . red ( "Could not detect location" )
304307 ) ;
305- return "Unable to detect your location. Please specify a location for weather." ;
308+ return {
309+ type : "text" as const ,
310+ value :
311+ "Unable to detect your location. Please specify a location for weather." ,
312+ } ;
306313 }
307314
308315 locationSpinner . succeed (
@@ -311,7 +318,11 @@ async function main() {
311318 locationToUse = `${ autoLocation . city } , ${ autoLocation . region } ` ;
312319 } catch ( _error ) {
313320 locationSpinner . fail ( chalk . red ( "Location detection failed" ) ) ;
314- return "Failed to detect your location. Please specify a location for weather." ;
321+ return {
322+ type : "text" as const ,
323+ value :
324+ "Failed to detect your location. Please specify a location for weather." ,
325+ } ;
315326 }
316327 }
317328
@@ -331,7 +342,10 @@ async function main() {
331342 toolSpinner . fail (
332343 chalk . red ( `Location "${ locationToUse } " not found` )
333344 ) ;
334- return `Location "${ locationToUse } " not found` ;
345+ return {
346+ type : "text" as const ,
347+ value : `Location "${ locationToUse } " not found` ,
348+ } ;
335349 }
336350
337351 // Get weather data
@@ -364,10 +378,16 @@ async function main() {
364378 chalk . green ( `${ coordinates . name } , ${ coordinates . country } ` )
365379 ) ;
366380
367- return `${ coordinates . name } : ${ current . temperature_2m } °F, ${ weatherDescription } , ${ current . relative_humidity_2m } % humidity, ${ current . wind_speed_10m } mph wind` ;
381+ return {
382+ type : "text" as const ,
383+ value : `${ coordinates . name } : ${ current . temperature_2m } °F, ${ weatherDescription } , ${ current . relative_humidity_2m } % humidity, ${ current . wind_speed_10m } mph wind` ,
384+ } ;
368385 } catch ( _error ) {
369386 toolSpinner . fail ( chalk . red ( "Error getting weather" ) ) ;
370- return `Error getting weather for "${ locationToUse } "` ;
387+ return {
388+ type : "text" as const ,
389+ value : `Error getting weather for "${ locationToUse } "` ,
390+ } ;
371391 }
372392 } ,
373393 } ) ,
@@ -408,7 +428,8 @@ async function main() {
408428 // Count tokens (simple whitespace split)
409429 tokenCount += chunk . text . split ( / \s + / ) . filter ( Boolean ) . length ;
410430 } else if ( chunk . type === "tool-result" ) {
411- toolResponses . push ( chunk as any ) ;
431+ toolResponses . push ( chunk ) ;
432+ // Don't display tool results - let the AI incorporate them into its response
412433 } else if ( chunk . type === "tool-call" ) {
413434 toolCalls . push ( chunk satisfies ToolCallPart ) ;
414435 }
@@ -427,16 +448,21 @@ async function main() {
427448 console . log ( speedMsg ) ;
428449 }
429450
430- if ( toolResponses . length > 0 ) {
431- messages . push ( { role : "tool" , content : toolResponses } ) ;
432- }
433-
434- if ( assistantResponse . trim ( ) ) {
451+ if ( assistantResponse . trim ( ) || toolCalls . length > 0 ) {
435452 messages . push ( {
436453 role : "assistant" ,
437- content : [ { type : "text" , text : assistantResponse } , ...toolCalls ] ,
454+ content : [
455+ ...( assistantResponse . trim ( )
456+ ? [ { type : "text" as const , text : assistantResponse } ]
457+ : [ ] ) ,
458+ ...toolCalls ,
459+ ] ,
438460 } ) ;
439461 }
462+
463+ if ( toolResponses . length > 0 ) {
464+ messages . push ( { role : "tool" , content : toolResponses } ) ;
465+ }
440466 } catch ( _error ) {
441467 spinner . fail ( chalk . red ( "Error occurred" ) ) ;
442468 console . log ( "" ) ;
0 commit comments