Skip to content

Commit 0b024d8

Browse files
committed
SimpleChatTC:ChatSessionID: Get all handlers to account for chatid
This should ensure that tool call responses can be mapped back to the chat session for which it was triggered.
1 parent a74abce commit 0b024d8

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

tools/server/public_simplechat/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ Provide a handler which
458458

459459
Update the tc_switch to include a object entry for the tool, which inturn includes
460460
* the meta data wrt the tool call
461-
* a reference to the handler - the handler should take toolCallId, toolName and toolArgs.
461+
* a reference to the handler - handler should take chatSessionId, toolCallId, toolName and toolArgs.
462462
It should pass these along to the tools web worker, if used.
463463
* the result key (was used previously, may use in future, but for now left as is)
464464

tools/server/public_simplechat/tooljs.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ let js_meta = {
3232
/**
3333
* Implementation of the javascript interpretor logic. Minimal skeleton for now.
3434
* ALERT: Has access to the javascript web worker environment and can mess with it and beyond
35+
* @param {string} chatid
3536
* @param {string} toolcallid
3637
* @param {string} toolname
3738
* @param {any} obj
3839
*/
39-
function js_run(toolcallid, toolname, obj) {
40-
gToolsWorker.postMessage({ id: toolcallid, name: toolname, code: obj["code"]})
40+
function js_run(chatid, toolcallid, toolname, obj) {
41+
gToolsWorker.postMessage({ cid: chatid, tcid: toolcallid, name: toolname, code: obj["code"]})
4142
}
4243

4344

@@ -63,12 +64,13 @@ let calc_meta = {
6364
/**
6465
* Implementation of the simple calculator logic. Minimal skeleton for now.
6566
* ALERT: Has access to the javascript web worker environment and can mess with it and beyond
67+
* @param {string} chatid
6668
* @param {string} toolcallid
6769
* @param {string} toolname
6870
* @param {any} obj
6971
*/
70-
function calc_run(toolcallid, toolname, obj) {
71-
gToolsWorker.postMessage({ id: toolcallid, name: toolname, code: `console.log(${obj["arithexpr"]})`})
72+
function calc_run(chatid, toolcallid, toolname, obj) {
73+
gToolsWorker.postMessage({ cid: chatid, tcid: toolcallid, name: toolname, code: `console.log(${obj["arithexpr"]})`})
7274
}
7375

7476

tools/server/public_simplechat/toolsworker.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ self.onmessage = async function (ev) {
2323
console.log(`\n\nTool/Function call "${ev.data.name}" raised an exception:${error.name}:${error.message}\n\n`)
2424
}
2525
tconsole.console_revert()
26-
self.postMessage({ id: ev.data.id, name: ev.data.name, data: tconsole.gConsoleStr})
26+
self.postMessage({ cid: ev.data.cid, tcid: ev.data.tcid, name: ev.data.name, data: tconsole.gConsoleStr})
2727
console.info("DBUG:WW:OnMessage done")
2828
}

tools/server/public_simplechat/toolweb.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ function bearer_transform() {
4343
* * with a predefined query token and value wrt a predefined path
4444
* NOTE: Initial go, handles textual data type.
4545
* ALERT: Accesses a seperate/external web proxy/caching server, be aware and careful
46+
* @param {string} chatid
4647
* @param {string} toolcallid
4748
* @param {string} toolname
4849
* @param {any} obj
4950
* @param {string} path
5051
* @param {string} qkey
5152
* @param {string} qvalue
5253
*/
53-
async function proxyserver_get_1arg(toolcallid, toolname, obj, path, qkey, qvalue) {
54+
async function proxyserver_get_1arg(chatid, toolcallid, toolname, obj, path, qkey, qvalue) {
5455
if (gToolsWorker.onmessage != null) {
5556
let newUrl = `${get_gme().tools.proxyUrl}/${path}?${qkey}=${qvalue}`
5657
let btoken = await bearer_transform()
@@ -60,9 +61,9 @@ async function proxyserver_get_1arg(toolcallid, toolname, obj, path, qkey, qvalu
6061
}
6162
return resp.text()
6263
}).then(data => {
63-
message_toolsworker(new MessageEvent('message', {data: {id: toolcallid, name: toolname, data: data}}))
64+
message_toolsworker(new MessageEvent('message', {data: {cid: chatid, tcid: toolcallid, name: toolname, data: data}}))
6465
}).catch((err)=>{
65-
message_toolsworker(new MessageEvent('message', {data: {id: toolcallid, name: toolname, data: `Error:${err}`}}))
66+
message_toolsworker(new MessageEvent('message', {data: {cid: chatid, tcid: toolcallid, name: toolname, data: `Error:${err}`}}))
6667
})
6768
}
6869
}
@@ -122,12 +123,13 @@ let fetchweburlraw_meta = {
122123
* * with a query token named url wrt the path urlraw
123124
* which gives the actual url to fetch
124125
* ALERT: Accesses a seperate/external web proxy/caching server, be aware and careful
126+
* @param {string} chatid
125127
* @param {string} toolcallid
126128
* @param {string} toolname
127129
* @param {any} obj
128130
*/
129-
function fetchweburlraw_run(toolcallid, toolname, obj) {
130-
return proxyserver_get_1arg(toolcallid, toolname, obj, 'urlraw', 'url', encodeURIComponent(obj.url));
131+
function fetchweburlraw_run(chatid, toolcallid, toolname, obj) {
132+
return proxyserver_get_1arg(chatid, toolcallid, toolname, obj, 'urlraw', 'url', encodeURIComponent(obj.url));
131133
}
132134

133135

@@ -179,12 +181,13 @@ let fetchweburltext_meta = {
179181
* * strips out head as well as any script, style, header, footer, nav and so blocks in body
180182
* before returning remaining body contents.
181183
* ALERT: Accesses a seperate/external web proxy/caching server, be aware and careful
184+
* @param {string} chatid
182185
* @param {string} toolcallid
183186
* @param {string} toolname
184187
* @param {any} obj
185188
*/
186-
function fetchweburltext_run(toolcallid, toolname, obj) {
187-
return proxyserver_get_1arg(toolcallid, toolname, obj, 'urltext', 'url', encodeURIComponent(obj.url));
189+
function fetchweburltext_run(chatid, toolcallid, toolname, obj) {
190+
return proxyserver_get_1arg(chatid, toolcallid, toolname, obj, 'urltext', 'url', encodeURIComponent(obj.url));
188191
}
189192

190193

@@ -237,16 +240,17 @@ let searchwebtext_meta = {
237240
* * strips out head as well as any script, style, header, footer, nav and so blocks in body
238241
* before returning remaining body contents.
239242
* ALERT: Accesses a seperate/external web proxy/caching server, be aware and careful
243+
* @param {string} chatid
240244
* @param {string} toolcallid
241245
* @param {string} toolname
242246
* @param {any} obj
243247
*/
244-
function searchwebtext_run(toolcallid, toolname, obj) {
248+
function searchwebtext_run(chatid, toolcallid, toolname, obj) {
245249
if (gToolsWorker.onmessage != null) {
246250
/** @type {string} */
247251
let searchUrl = get_gme().tools.searchUrl;
248252
searchUrl = searchUrl.replace("SEARCHWORDS", encodeURIComponent(obj.words));
249-
return proxyserver_get_1arg(toolcallid, toolname, obj, 'urltext', 'url', encodeURIComponent(searchUrl));
253+
return proxyserver_get_1arg(chatid, toolcallid, toolname, obj, 'urltext', 'url', encodeURIComponent(searchUrl));
250254
}
251255
}
252256

0 commit comments

Comments
 (0)