|
5 | 5 |
|
6 | 6 | import * as du from "./datautils.mjs"; |
7 | 7 | import * as ui from "./ui.mjs" |
8 | | -import * as tools from "./tools.mjs" |
| 8 | +import * as mTools from "./tools.mjs" |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class Roles { |
@@ -522,7 +522,7 @@ class SimpleChat { |
522 | 522 | obj["stream"] = true; |
523 | 523 | } |
524 | 524 | if (this.me.tools.enabled) { |
525 | | - obj["tools"] = tools.meta(); |
| 525 | + obj["tools"] = this.me.toolsMgr.meta(); |
526 | 526 | } |
527 | 527 | return JSON.stringify(obj); |
528 | 528 | } |
@@ -751,7 +751,7 @@ class SimpleChat { |
751 | 751 | return "Tool/Function call name not specified" |
752 | 752 | } |
753 | 753 | try { |
754 | | - return await tools.tool_call(this.chatId, toolcallid, toolname, toolargs) |
| 754 | + return await this.me.toolsMgr.tool_call(this.chatId, toolcallid, toolname, toolargs) |
755 | 755 | } catch (/** @type {any} */error) { |
756 | 756 | return `Tool/Function call raised an exception:${error.name}:${error.message}` |
757 | 757 | } |
@@ -1070,7 +1070,7 @@ class MultiChatUI { |
1070 | 1070 | }) |
1071 | 1071 |
|
1072 | 1072 | // Handle messages from tools web workers |
1073 | | - this.me.workers_cb((cid, tcid, name, data)=>{ |
| 1073 | + this.me.toolsMgr.workers_cb((cid, tcid, name, data)=>{ |
1074 | 1074 | clearTimeout(this.timers.toolcallResponseTimeout) |
1075 | 1075 | this.timers.toolcallResponseTimeout = undefined |
1076 | 1076 | let chat = this.simpleChats[cid]; |
@@ -1386,10 +1386,7 @@ export class Me { |
1386 | 1386 | //"frequency_penalty": 1.2, |
1387 | 1387 | //"presence_penalty": 1.2, |
1388 | 1388 | }; |
1389 | | - this.workers = { |
1390 | | - js: /** @type {Worker} */(/** @type {unknown} */(undefined)), |
1391 | | - db: /** @type {Worker} */(/** @type {unknown} */(undefined)), |
1392 | | - } |
| 1389 | + this.toolsMgr = new mTools.ToolsManager() |
1393 | 1390 | } |
1394 | 1391 |
|
1395 | 1392 | /** |
@@ -1473,35 +1470,4 @@ export class Me { |
1473 | 1470 | }) |
1474 | 1471 | } |
1475 | 1472 |
|
1476 | | - /** |
1477 | | - * Setup the callback that will be called when ever message |
1478 | | - * is recieved from the Tools Web Workers. |
1479 | | - * @param {(chatId: string, toolCallId: string, name: string, data: string) => void} cb |
1480 | | - */ |
1481 | | - workers_cb(cb) { |
1482 | | - this.workers.js.onmessage = function (ev) { |
1483 | | - cb(ev.data.cid, ev.data.tcid, ev.data.name, ev.data.data) |
1484 | | - } |
1485 | | - this.workers.db.onmessage = function (ev) { |
1486 | | - cb(ev.data.cid, ev.data.tcid, ev.data.name, JSON.stringify(ev.data.data, (k,v)=>{ |
1487 | | - return (v === undefined) ? '__UNDEFINED__' : v; |
1488 | | - })); |
1489 | | - } |
1490 | | - } |
1491 | | - |
1492 | | - /** |
1493 | | - * Send a message to specified tools web worker's monitor in main thread directly |
1494 | | - * @param {Worker} worker |
1495 | | - * @param {string} chatid |
1496 | | - * @param {string} toolcallid |
1497 | | - * @param {string} toolname |
1498 | | - * @param {string} data |
1499 | | - */ |
1500 | | - workers_postmessage_for_main(worker, chatid, toolcallid, toolname, data) { |
1501 | | - let mev = new MessageEvent('message', {data: {cid: chatid, tcid: toolcallid, name: toolname, data: data}}); |
1502 | | - if (worker.onmessage != null) { |
1503 | | - worker.onmessage(mev) |
1504 | | - } |
1505 | | - } |
1506 | | - |
1507 | 1473 | } |
0 commit comments