diff --git a/tools/server/public_simplechat/local.tools/simpleproxy.py b/tools/server/public_simplechat/local.tools/simpleproxy.py index ce638dfa15..8185382297 100644 --- a/tools/server/public_simplechat/local.tools/simpleproxy.py +++ b/tools/server/public_simplechat/local.tools/simpleproxy.py @@ -47,6 +47,8 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler): handle_urlraw(self, pr) case '/urltext': handle_urltext(self, pr) + case '/aum': + handle_aum(self, pr) case _: print(f"WARN:ProxyHandler:GET:UnknownPath{pr.path}") self.send_error(400, f"WARN:UnknownPath:{pr.path}") @@ -58,6 +60,12 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler): self.send_headers_common() +def handle_aum(ph: ProxyHandler, pr: urllib.parse.ParseResult): + ph.send_response_only(200, "bharatavarshe") + ph.send_header('Access-Control-Allow-Origin', '*') + ph.end_headers() + + @dataclass(frozen=True) class UrlReqResp: callOk: bool diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index 3a1b5e104c..63b9a43ead 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -351,7 +351,7 @@ browser js runtime environment. Depending on the path specified wrt the proxy se (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 logic does a simple dumb check to see if there is something running at specified proxyUrl +* the logic does a simple check to see if the bundled simpleproxy is 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 diff --git a/tools/server/public_simplechat/tooljs.mjs b/tools/server/public_simplechat/tooljs.mjs index b195288aa6..755d9eae75 100644 --- a/tools/server/public_simplechat/tooljs.mjs +++ b/tools/server/public_simplechat/tooljs.mjs @@ -133,12 +133,18 @@ 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 + * NOTE: Currently the logic is setup for the bundled simpleproxy.py * @param {Object>} tcs */ async function fetchweburlraw_setup(tcs) { // @ts-ignore - let got = await fetch(`${document["gMe"].proxyUrl}/urlraw?url=jambudweepe.multiverse.987654321123456789`).then(resp=>{ + let got = await fetch(`${document["gMe"].proxyUrl}/aum?url=jambudweepe.multiverse.987654321123456789`).then(resp=>{ + if (resp.statusText != 'bharatavarshe') { + console.log("WARN:ToolJS:FetchWebUrlRaw:Dont forget to run the bundled local.tools/simpleproxy.py to enable me") + return + } else { + console.log("INFO:ToolJS:FetchWebUrlRaw:Enabling...") + } tcs["fetch_web_url_raw"] = { "handler": fetchweburlraw_run, "meta": fetchweburlraw_meta, @@ -201,12 +207,18 @@ 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 + * NOTE: Currently the logic is setup for the bundled simpleproxy.py * @param {Object>} tcs */ async function fetchweburltext_setup(tcs) { // @ts-ignore - let got = await fetch(`${document["gMe"].proxyUrl}/urltext?url=jambudweepe.akashaganga.multiverse.987654321123456789`).then(resp=>{ + let got = await fetch(`${document["gMe"].proxyUrl}/aum?url=jambudweepe.akashaganga.multiverse.987654321123456789`).then(resp=>{ + if (resp.statusText != 'bharatavarshe') { + console.log("WARN:ToolJS:FetchWebUrlText:Dont forget to run the bundled local.tools/simpleproxy.py to enable me") + return + } else { + console.log("INFO:ToolJS:FetchWebUrlText:Enabling...") + } tcs["fetch_web_url_text"] = { "handler": fetchweburltext_run, "meta": fetchweburltext_meta,