22// ALERT - Simple Stupid flow - Using from a discardable VM is better
33// Helpers to handle tools/functions calling related to web access, pdf, etal
44// which work in sync with the bundled simpleproxy.py server logic.
5+ // Uses the js specific web worker path.
56// by Humans for All
67//
78
89import * as mChatMagic from './simplechat.js'
910
1011
11- let gToolsWorker = /** @type {Worker } */ ( /** @type {unknown } */ ( null ) ) ;
1212/**
1313 * @type {mChatMagic.Me }
1414 */
1515let gMe = /** @type {mChatMagic.Me } */ ( /** @type {unknown } */ ( null ) ) ;
1616
1717
18- /**
19- * Send a message to Tools WebWorker's monitor in main thread directly
20- * @param {MessageEvent<any> } mev
21- */
22- function message_toolsworker ( mev ) {
23- // @ts -ignore
24- gToolsWorker . onmessage ( mev )
25- }
26-
27-
2818/**
2919 * For now hash the shared secret with the year.
3020 */
@@ -51,7 +41,7 @@ async function bearer_transform() {
5141 * @param {any } objHeaders
5242 */
5343async function proxyserver_get_anyargs ( chatid , toolcallid , toolname , objSearchParams , path , objHeaders = { } ) {
54- if ( gToolsWorker . onmessage != null ) {
44+ if ( gMe . workers . js . onmessage != null ) {
5545 let params = new URLSearchParams ( objSearchParams )
5646 let newUrl = `${ gMe . tools . proxyUrl } /${ path } ?${ params } `
5747 let headers = new Headers ( objHeaders )
@@ -63,9 +53,9 @@ async function proxyserver_get_anyargs(chatid, toolcallid, toolname, objSearchPa
6353 }
6454 return resp . text ( )
6555 } ) . then ( data => {
66- message_toolsworker ( new MessageEvent ( 'message' , { data : { cid : chatid , tcid : toolcallid , name : toolname , data : data } } ) )
56+ gMe . workers_postmessage_for_main ( gMe . workers . js , chatid , toolcallid , toolname , data ) ;
6757 } ) . catch ( ( err ) => {
68- message_toolsworker ( new MessageEvent ( 'message' , { data : { cid : chatid , tcid : toolcallid , name : toolname , data : `Error:${ err } ` } } ) )
58+ gMe . workers_postmessage_for_main ( gMe . workers . js , chatid , toolcallid , toolname , `Error:${ err } ` ) ;
6959 } )
7060 }
7161}
@@ -343,15 +333,13 @@ async function fetchpdftext_setup(tcs) {
343333/**
344334 * Used to get hold of the web worker to use for running tool/function call related code
345335 * Also to setup tool calls, which need to cross check things at runtime
346- * @param {Worker } toolsWorker
347336 * @param {mChatMagic.Me } me
348337 */
349- export async function init ( toolsWorker , me ) {
338+ export async function init ( me ) {
350339 /**
351340 * @type {Object<string, Object<string, any>> } tcs
352341 */
353342 let tc_switch = { }
354- gToolsWorker = toolsWorker
355343 gMe = me
356344 await fetchweburlraw_setup ( tc_switch )
357345 await fetchweburltext_setup ( tc_switch )
0 commit comments