SimpleChatTC: Pass toolname to the tool handler

So that when tool handler writes the result to the tc_switch, it
can make use of the same, to write to the right location.

NOTE: This also fixes the issue with I forgetting to rename the
key in js_run wrt writing of result.
This commit is contained in:
hanishkvc 2025-10-12 17:19:51 +05:30
parent f7284a8b89
commit a80da9a652
2 changed files with 7 additions and 5 deletions

View File

@ -63,14 +63,15 @@ let js_meta = {
/** /**
* Implementation of the javascript interpretor logic. Minimal skeleton for now. * Implementation of the javascript interpretor logic. Minimal skeleton for now.
* ALERT: Has access to the javascript environment and can mess with it and beyond * ALERT: Has access to the javascript environment and can mess with it and beyond
* @param {string} toolname
* @param {any} obj * @param {any} obj
*/ */
function js_run(obj) { function js_run(toolname, obj) {
console_redir() console_redir()
let func = new Function(obj["code"]) let func = new Function(obj["code"])
func() func()
console_revert() console_revert()
tc_switch["javascript"]["result"] = gConsoleStr tc_switch[toolname]["result"] = gConsoleStr
} }
@ -96,14 +97,15 @@ let calc_meta = {
/** /**
* Implementation of the simple calculator logic. Minimal skeleton for now. * Implementation of the simple calculator logic. Minimal skeleton for now.
* ALERT: Has access to the javascript environment and can mess with it and beyond * ALERT: Has access to the javascript environment and can mess with it and beyond
* @param {string} toolname
* @param {any} obj * @param {any} obj
*/ */
function calc_run(obj) { function calc_run(toolname, obj) {
console_redir() console_redir()
let func = new Function(`console.log(${obj["arithexpr"]})`) let func = new Function(`console.log(${obj["arithexpr"]})`)
func() func()
console_revert() console_revert()
tc_switch["simple_calculator"]["result"] = gConsoleStr tc_switch[toolname]["result"] = gConsoleStr
} }

View File

@ -37,7 +37,7 @@ export async function tool_call(toolname, toolargs) {
for (const fn in tc_switch) { for (const fn in tc_switch) {
if (fn == toolname) { if (fn == toolname) {
try { try {
tc_switch[fn]["handler"](JSON.parse(toolargs)) tc_switch[fn]["handler"](fn, JSON.parse(toolargs))
return tc_switch[fn]["result"] return tc_switch[fn]["result"]
} catch (/** @type {any} */error) { } catch (/** @type {any} */error) {
return `Tool/Function call raised an exception:${error.name}:${error.message}` return `Tool/Function call raised an exception:${error.name}:${error.message}`