SimpleChatTC:ToolCall response relaxed handling

Use DOMParser parseFromString in text/html mode rather than text/xml
as it makes it more relaxed without worrying about special chars
of xml like & etal
This commit is contained in:
hanishkvc 2025-10-24 01:11:22 +05:30
parent c109da870f
commit 74226a0992
1 changed files with 8 additions and 2 deletions

View File

@ -107,12 +107,18 @@ class ChatMessageEx {
/**
* Extract the elements of the all in one tool call result string
* This should potentially account for content tag having xml content within to an extent.
* This should potentially account for content tag having xml/html content within to an extent.
*
* NOTE: Rather text/html is a more relaxed/tolarent mode for parseFromString than text/xml.
* NOTE: Maybe better to switch to a json string format or use a more intelligent xml encoder
* in createToolCallResultAllInOne so that extractor like this dont have to worry about special
* xml chars like & as is, in the AllInOne content. For now text/html tolarence seems ok enough.
*
* @param {string} allInOne
*/
static extractToolCallResultAllInOne(allInOne) {
const dParser = new DOMParser();
const got = dParser.parseFromString(allInOne, 'text/xml');
const got = dParser.parseFromString(allInOne, 'text/html');
const parseErrors = got.querySelector('parseerror')
if (parseErrors) {
console.debug("WARN:ChatMessageEx:ExtractToolCallResultAllInOne:", parseErrors.textContent.trim())