@@ -131,6 +131,23 @@ function fetchweburlraw_run(toolcallid, toolname, obj) {
131131}
132132
133133
134+ /**
135+ * Setup fetch_web_url_raw for tool calling
136+ * NOTE: Currently it just checks there is something at given proxyUrl
137+ * @param {Object<string, Object<string, any>> } tcs
138+ */
139+ async function fetchweburlraw_setup ( tcs ) {
140+ // @ts -ignore
141+ let got = await fetch ( document [ "gMe" ] . proxyUrl ) . then ( resp => {
142+ tcs [ "fetch_web_url_raw" ] = {
143+ "handler" : fetchweburlraw_run ,
144+ "meta" : fetchweburlraw_meta ,
145+ "result" : ""
146+ } ;
147+ } ) . catch ( err => console . log ( `WARN:ToolJS:FetchWebUrlRaw:ProxyServer missing?:${ err } \nDont forget to run the bundled local.tools/simpleproxy.py` ) )
148+ }
149+
150+
134151let fetchweburltext_meta = {
135152 "type" : "function" ,
136153 "function" : {
@@ -182,6 +199,23 @@ function fetchweburltext_run(toolcallid, toolname, obj) {
182199}
183200
184201
202+ /**
203+ * Setup fetch_web_url_text for tool calling
204+ * NOTE: Currently it just checks there is something at given proxyUrl
205+ * @param {Object<string, Object<string, any>> } tcs
206+ */
207+ async function fetchweburltext_setup ( tcs ) {
208+ // @ts -ignore
209+ let got = await fetch ( document [ "gMe" ] . proxyUrl ) . then ( resp => {
210+ tcs [ "fetch_web_url_text" ] = {
211+ "handler" : fetchweburltext_run ,
212+ "meta" : fetchweburltext_meta ,
213+ "result" : ""
214+ } ;
215+ } ) . catch ( err => console . log ( `WARN:ToolJS:FetchWebUrlText:ProxyServer missing?:${ err } \nDont forget to run the bundled local.tools/simpleproxy.py` ) )
216+ }
217+
218+
185219/**
186220 * @type {Object<string, Object<string, any>> }
187221 */
@@ -196,23 +230,16 @@ export let tc_switch = {
196230 "meta" : calc_meta ,
197231 "result" : ""
198232 } ,
199- "fetch_web_url_raw" : {
200- "handler" : fetchweburlraw_run ,
201- "meta" : fetchweburlraw_meta ,
202- "result" : ""
203- } ,
204- "fetch_web_url_text" : {
205- "handler" : fetchweburltext_run ,
206- "meta" : fetchweburltext_meta ,
207- "result" : ""
208- }
209233}
210234
211235
212236/**
213237 * Used to get hold of the web worker to use for running tool/function call related code
238+ * Also to setup tool calls, which need to cross check things at runtime
214239 * @param {Worker } toolsWorker
215240 */
216- export function init ( toolsWorker ) {
241+ export async function init ( toolsWorker ) {
217242 gToolsWorker = toolsWorker
243+ await fetchweburlraw_setup ( tc_switch )
244+ await fetchweburltext_setup ( tc_switch )
218245}
0 commit comments