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:
parent
510c65c721
commit
14d67f6c3c
|
|
@ -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})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue