@@ -721,7 +721,7 @@ class SimpleChat {
721721 return "Tool/Function call name not specified"
722722 }
723723 try {
724- return await tools . tool_call ( toolcallid , toolname , toolargs )
724+ return await tools . tool_call ( this . chatId , toolcallid , toolname , toolargs )
725725 } catch ( /** @type {any } */ error ) {
726726 return `Tool/Function call raised an exception:${ error . name } :${ error . message } `
727727 }
@@ -847,10 +847,11 @@ class MultiChatUI {
847847 */
848848 chat_show ( chatId , bClear = true , bShowInfoAll = false ) {
849849 if ( chatId != this . curChatId ) {
850- return
850+ return false
851851 }
852852 let chat = this . simpleChats [ this . curChatId ] ;
853853 chat . show ( this . elDivChat , this . elInUser , bClear , bShowInfoAll )
854+ return true
854855 }
855856
856857 /**
@@ -897,21 +898,19 @@ class MultiChatUI {
897898 } )
898899
899900 // Handle messages from Tools web worker
900- tools . setup ( ( id , name , data ) => {
901+ tools . setup ( ( cid , tcid , name , data ) => {
901902 clearTimeout ( this . timers . toolcallResponseTimeout )
902903 this . timers . toolcallResponseTimeout = undefined
903- // TODO: Check for chat id in future so as to
904- // identify the right chat session to add the tc response to
905- // as well as to decide whether to show this chat currently or not and same with auto submit
906- let chat = this . simpleChats [ this . curChatId ] ; // rather we should pick chat based on tool response's chatId
907- chat . add ( new ChatMessageEx ( Roles . ToolTemp , ChatMessageEx . createToolCallResultAllInOne ( id , name , data ) ) )
908- this . chat_show ( chat . chatId ) // one needs to use tool response's chatId
909- this . ui_reset_userinput ( false )
910- if ( gMe . tools . auto > 0 ) {
911- this . timers . toolcallResponseSubmitClick = setTimeout ( ( ) => {
912- this . elBtnUser . click ( )
913- } , gMe . tools . auto * this . TimePeriods . ToolCallAutoTimeUnit )
904+ let chat = this . simpleChats [ cid ] ;
905+ chat . add ( new ChatMessageEx ( Roles . ToolTemp , ChatMessageEx . createToolCallResultAllInOne ( tcid , name , data ) ) )
906+ if ( this . chat_show ( cid ) ) {
907+ if ( gMe . tools . auto > 0 ) {
908+ this . timers . toolcallResponseSubmitClick = setTimeout ( ( ) => {
909+ this . elBtnUser . click ( )
910+ } , gMe . tools . auto * this . TimePeriods . ToolCallAutoTimeUnit )
911+ }
914912 }
913+ this . ui_reset_userinput ( false )
915914 } )
916915
917916 this . elInUser . addEventListener ( "keyup" , ( ev ) => {
0 commit comments