From fbe9b2369fb78425100f4db3ce59c119dabc14db Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Fri, 7 Nov 2025 01:31:29 +0530 Subject: [PATCH] SimpleChatTC:XmlText: Add plumbing on web client ui ie js side Add the meta data for the fetch xml as text tool call Implement the handler and the setup tool call plumbing logic --- tools/server/public_simplechat/toolweb.mjs | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/server/public_simplechat/toolweb.mjs b/tools/server/public_simplechat/toolweb.mjs index 7ca4205ea3..266e564dc4 100644 --- a/tools/server/public_simplechat/toolweb.mjs +++ b/tools/server/public_simplechat/toolweb.mjs @@ -329,6 +329,67 @@ async function fetchpdftext_setup(tcs) { } +// +// Fetch XML Text +// + + +let fetchxmltext_meta = { + "type": "function", + "function": { + "name": "fetch_xml_as_text", + "description": "Fetch the requested xml url through a proxy server and return its text content after stripping away the xml tags, in few seconds", + "parameters": { + "type": "object", + "properties": { + "url":{ + "type":"string", + "description":"url of the xml file that will be fetched" + }, + "tagDrops":{ + "type":"string", + "description":"specify a json stringified form of list of xml tags to drop" + } + }, + "required": ["url"] + } + } + } + + +/** + * Implementation of the fetch xml as text logic. + * Expects simpleproxy to be running at specified url and providing xmltext service + * ALERT: Accesses a seperate/external web proxy/caching server, be aware and careful + * @param {string} chatid + * @param {string} toolcallid + * @param {string} toolname + * @param {any} obj + */ +function fetchxmltext_run(chatid, toolcallid, toolname, obj) { + let headers = { 'xmltext-tag-drops': obj.tagDrops } + return proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, 'xmltext', headers); +} + + +/** + * Setup fetch_xml_as_text for tool calling + * NOTE: Currently the logic is setup for the bundled simpleproxy.py + * @param {Object>} tcs + */ +async function fetchxmltext_setup(tcs) { + return proxyserver_tc_setup('FetchXmlAsText', 'xmltext', 'fetch_xml_as_text', { + "handler": fetchxmltext_run, + "meta": fetchxmltext_meta, + "result": "" + }, tcs); +} + + +// +// Entry point +// + /** * Used to get hold of the web worker to use for running tool/function call related code @@ -345,5 +406,6 @@ export async function init(me) { await fetchweburltext_setup(tc_switch) await searchwebtext_setup(tc_switch) await fetchpdftext_setup(tc_switch) + await fetchxmltext_setup(tc_switch) return tc_switch }