SimpleChatTC: Web worker flow initial go cleanup

Had forgotten to specify type as module wrt web worker, in order
to allow it to import the toolsconsole module.

Had forgotten to maintain the id of the timeout handler, which is
needed to clear/stop the timeout handler from triggering, if tool
call response is got well in time.

As I am currently reverting the console redirection at end of
handling a tool call code in the web worker message handler, I
need to setup the redirection each time. Also I had forgotten
to clear the console.log capture data space, before a new tool
call code is executed, this is also fixed by this change.

TODO: Need to abort the tool call code execution in the web worker
if possible in future, if the client / browser side times out
waiting for tool call response, ie if the tool call code is taking
up too much time.
This commit is contained in:
hanishkvc 2025-10-14 01:34:22 +05:30
parent 148ec1c41a
commit a0f6762fda
3 changed files with 4 additions and 4 deletions

View File

@ -678,6 +678,7 @@ class MultiChatUI {
}) })
tools.setup((name, data)=>{ tools.setup((name, data)=>{
clearTimeout(this.idTimeOut)
this.elInUser.value = `<tool_response>${data}</tool_response>` this.elInUser.value = `<tool_response>${data}</tool_response>`
this.ui_reset_userinput(false) this.ui_reset_userinput(false)
}) })
@ -791,7 +792,7 @@ class MultiChatUI {
this.elInUser.value = `<tool_response>${toolResult}</tool_response>` this.elInUser.value = `<tool_response>${toolResult}</tool_response>`
this.ui_reset_userinput(false) this.ui_reset_userinput(false)
} else { } else {
setTimeout(() => { this.idTimeOut = setTimeout(() => {
this.elInUser.value = `<tool_response>Tool/Function call ${toolname} taking too much time, aborting...</tool_response>` this.elInUser.value = `<tool_response>Tool/Function call ${toolname} taking too much time, aborting...</tool_response>`
this.ui_reset_userinput(false) this.ui_reset_userinput(false)
}, 10000) }, 10000)

View File

@ -8,7 +8,7 @@
import * as tjs from './tooljs.mjs' import * as tjs from './tooljs.mjs'
let gToolsWorker = new Worker('./toolsworker.mjs'); let gToolsWorker = new Worker('./toolsworker.mjs', { type: 'module' });
/** /**
* @type {Object<string,Object<string,any>>} * @type {Object<string,Object<string,any>>}
*/ */

View File

@ -13,9 +13,8 @@
import * as tconsole from "./toolsconsole.mjs" import * as tconsole from "./toolsconsole.mjs"
tconsole.console_redir()
self.onmessage = function (ev) { self.onmessage = function (ev) {
tconsole.console_redir()
try { try {
eval(ev.data.code) eval(ev.data.code)
} catch (/** @type {any} */error) { } catch (/** @type {any} */error) {