SimpleChatTC:WebFetch: Enable only if something at proxyUrl

NOTE: not a robust check, just tries to establish a http connection
for now and doesnt really check if it is the specific proxy srvr
of interest or not.
This commit is contained in:
hanishkvc 2025-10-20 18:59:18 +05:30
parent fa0a6919cb
commit 80dbbb89a5
3 changed files with 48 additions and 17 deletions

View File

@ -350,8 +350,11 @@ server logic, this helps bypass the CORS restrictions applied if trying to direc
browser js runtime environment. Depending on the path specified wrt the proxy server, if urltext
(and not urlraw), it additionally tries to convert html content into equivalent text to some extent
in a simple minded manner by dropping head block as well as all scripts/styles/footers/headers/nav.
May add support for white list of allowed sites to access or so. The simple proxy can be found at
* tools/server/public_simplechat/local.tools/simpleproxy.py
May add support for white list of allowed sites to access or so.
* the logic does a simple dumb check to see if there is something running at specified proxyUrl
before enabling fetch web related tool calls.
* The bundled simple proxy can be found at
* tools/server/public_simplechat/local.tools/simpleproxy.py
#### Extending with new tools

View File

@ -131,6 +131,23 @@ function fetchweburlraw_run(toolcallid, toolname, obj) {
}
/**
* Setup fetch_web_url_raw for tool calling
* NOTE: Currently it just checks there is something at given proxyUrl
* @param {Object<string, Object<string, any>>} tcs
*/
async function fetchweburlraw_setup(tcs) {
// @ts-ignore
let got = await fetch(document["gMe"].proxyUrl).then(resp=>{
tcs["fetch_web_url_raw"] = {
"handler": fetchweburlraw_run,
"meta": fetchweburlraw_meta,
"result": ""
};
}).catch(err=>console.log(`WARN:ToolJS:FetchWebUrlRaw:ProxyServer missing?:${err}\nDont forget to run the bundled local.tools/simpleproxy.py`))
}
let fetchweburltext_meta = {
"type": "function",
"function": {
@ -182,6 +199,23 @@ function fetchweburltext_run(toolcallid, toolname, obj) {
}
/**
* Setup fetch_web_url_text for tool calling
* NOTE: Currently it just checks there is something at given proxyUrl
* @param {Object<string, Object<string, any>>} tcs
*/
async function fetchweburltext_setup(tcs) {
// @ts-ignore
let got = await fetch(document["gMe"].proxyUrl).then(resp=>{
tcs["fetch_web_url_text"] = {
"handler": fetchweburltext_run,
"meta": fetchweburltext_meta,
"result": ""
};
}).catch(err=>console.log(`WARN:ToolJS:FetchWebUrlText:ProxyServer missing?:${err}\nDont forget to run the bundled local.tools/simpleproxy.py`))
}
/**
* @type {Object<string, Object<string, any>>}
*/
@ -196,23 +230,16 @@ export let tc_switch = {
"meta": calc_meta,
"result": ""
},
"fetch_web_url_raw": {
"handler": fetchweburlraw_run,
"meta": fetchweburlraw_meta,
"result": ""
},
"fetch_web_url_text": {
"handler": fetchweburltext_run,
"meta": fetchweburltext_meta,
"result": ""
}
}
/**
* Used to get hold of the web worker to use for running tool/function call related code
* Also to setup tool calls, which need to cross check things at runtime
* @param {Worker} toolsWorker
*/
export function init(toolsWorker) {
export async function init(toolsWorker) {
gToolsWorker = toolsWorker
await fetchweburlraw_setup(tc_switch)
await fetchweburltext_setup(tc_switch)
}

View File

@ -15,10 +15,11 @@ let gToolsWorker = new Worker('./toolsworker.mjs', { type: 'module' });
export let tc_switch = {}
export function init() {
tjs.init(gToolsWorker)
for (const key in tjs.tc_switch) {
tc_switch[key] = tjs.tc_switch[key]
}
tjs.init(gToolsWorker).then(()=>{
for (const key in tjs.tc_switch) {
tc_switch[key] = tjs.tc_switch[key]
}
})
}
export function meta() {