Skip to content

Commit f8e8087

Browse files
committed
SimpleChatTC:WebFetch: Try confirm simpleproxy before enabling
1 parent d667e2d commit f8e8087

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

tools/server/public_simplechat/local.tools/simpleproxy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def do_GET(self):
4747
handle_urlraw(self, pr)
4848
case '/urltext':
4949
handle_urltext(self, pr)
50+
case '/aum':
51+
handle_aum(self, pr)
5052
case _:
5153
print(f"WARN:ProxyHandler:GET:UnknownPath{pr.path}")
5254
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
@@ -58,6 +60,12 @@ def do_OPTIONS(self):
5860
self.send_headers_common()
5961

6062

63+
def handle_aum(ph: ProxyHandler, pr: urllib.parse.ParseResult):
64+
ph.send_response_only(200, "bharatavarshe")
65+
ph.send_header('Access-Control-Allow-Origin', '*')
66+
ph.end_headers()
67+
68+
6169
@dataclass(frozen=True)
6270
class UrlReqResp:
6371
callOk: bool

tools/server/public_simplechat/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ browser js runtime environment. Depending on the path specified wrt the proxy se
351351
(and not urlraw), it additionally tries to convert html content into equivalent text to some extent
352352
in a simple minded manner by dropping head block as well as all scripts/styles/footers/headers/nav.
353353
May add support for white list of allowed sites to access or so.
354-
* the logic does a simple dumb check to see if there is something running at specified proxyUrl
354+
* the logic does a simple check to see if the bundled simpleproxy is running at specified proxyUrl
355355
before enabling fetch web related tool calls.
356356
* The bundled simple proxy can be found at
357357
* tools/server/public_simplechat/local.tools/simpleproxy.py

tools/server/public_simplechat/tooljs.mjs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,18 @@ function fetchweburlraw_run(toolcallid, toolname, obj) {
133133

134134
/**
135135
* Setup fetch_web_url_raw for tool calling
136-
* NOTE: Currently it just checks there is something at given proxyUrl
136+
* NOTE: Currently the logic is setup for the bundled simpleproxy.py
137137
* @param {Object<string, Object<string, any>>} tcs
138138
*/
139139
async function fetchweburlraw_setup(tcs) {
140140
// @ts-ignore
141-
let got = await fetch(`${document["gMe"].proxyUrl}/urlraw?url=jambudweepe.multiverse.987654321123456789`).then(resp=>{
141+
let got = await fetch(`${document["gMe"].proxyUrl}/aum?url=jambudweepe.multiverse.987654321123456789`).then(resp=>{
142+
if (resp.statusText != 'bharatavarshe') {
143+
console.log("WARN:ToolJS:FetchWebUrlRaw:Dont forget to run the bundled local.tools/simpleproxy.py to enable me")
144+
return
145+
} else {
146+
console.log("INFO:ToolJS:FetchWebUrlRaw:Enabling...")
147+
}
142148
tcs["fetch_web_url_raw"] = {
143149
"handler": fetchweburlraw_run,
144150
"meta": fetchweburlraw_meta,
@@ -201,12 +207,18 @@ function fetchweburltext_run(toolcallid, toolname, obj) {
201207

202208
/**
203209
* Setup fetch_web_url_text for tool calling
204-
* NOTE: Currently it just checks there is something at given proxyUrl
210+
* NOTE: Currently the logic is setup for the bundled simpleproxy.py
205211
* @param {Object<string, Object<string, any>>} tcs
206212
*/
207213
async function fetchweburltext_setup(tcs) {
208214
// @ts-ignore
209-
let got = await fetch(`${document["gMe"].proxyUrl}/urltext?url=jambudweepe.akashaganga.multiverse.987654321123456789`).then(resp=>{
215+
let got = await fetch(`${document["gMe"].proxyUrl}/aum?url=jambudweepe.akashaganga.multiverse.987654321123456789`).then(resp=>{
216+
if (resp.statusText != 'bharatavarshe') {
217+
console.log("WARN:ToolJS:FetchWebUrlText:Dont forget to run the bundled local.tools/simpleproxy.py to enable me")
218+
return
219+
} else {
220+
console.log("INFO:ToolJS:FetchWebUrlText:Enabling...")
221+
}
210222
tcs["fetch_web_url_text"] = {
211223
"handler": fetchweburltext_run,
212224
"meta": fetchweburltext_meta,

0 commit comments

Comments
 (0)