SimpleChatTC: Pass around structured objects wrt tool worker

The request for code to run as well as the resultant response data
both need to follow a structured object convention, so that it is
easy to map a request and the corresponding response to some extent.
This commit is contained in:
hanishkvc 2025-10-14 00:54:21 +05:30
parent 510c65c721
commit 14d67f6c3c
1 changed files with 11 additions and 4 deletions

View File

@ -4,16 +4,23 @@
// by Humans for All // by Humans for All
// //
/**
* Expects to get a message with identifier name and code to run
* Posts message with identifier name and data captured from console.log outputs
*/
import * as tconsole from "./toolsconsole.mjs" import * as tconsole from "./toolsconsole.mjs"
tconsole.console_redir() tconsole.console_redir()
onmessage = async (ev) => { self.onmessage = function (ev) {
try { try {
eval(ev.data) eval(ev.data.code)
} catch (/** @type {any} */error) { } catch (/** @type {any} */error) {
console.log(`\n\nTool/Function call raised an exception:${error.name}:${error.message}\n\n`) console.log(`\n\nTool/Function call "${ev.data.name}" raised an exception:${error.name}:${error.message}\n\n`)
} }
tconsole.console_revert() tconsole.console_revert()
postMessage(tconsole.gConsoleStr) self.postMessage({ name: ev.data.name, data: tconsole.gConsoleStr})
} }