refactor: enhance XML tool call parsing to support nested structures, CDATA, and repeated tags

This commit is contained in:
CJACK
2026-04-19 19:58:45 +08:00
parent 26d195f2a6
commit 0f2b5fee23
16 changed files with 550 additions and 140 deletions

View File

@@ -30,6 +30,20 @@ line 2 with <tags> and & symbols]]></content></parameters></tool_call>`,
Input: map[string]any{"content": "line 1\nline 2 with <tags> and & symbols"},
}},
},
{
name: "Nested XML with repeated parameters (New Feature)",
text: `<tool_call><tool_name>write_file</tool_name><parameters><path>script.sh</path><content><![CDATA[#!/bin/bash
echo "hello"
]]></content><item>first</item><item>second</item></parameters></tool_call>`,
expected: []ParsedToolCall{{
Name: "write_file",
Input: map[string]any{
"path": "script.sh",
"content": "#!/bin/bash\necho \"hello\"\n",
"item": []any{"first", "second"},
},
}},
},
{
name: "Dirty XML with unescaped symbols (Robustness Improvement)",
text: `<tool_call><tool_name>bash</tool_name><parameters><command>echo "hello" > out.txt && cat out.txt</command></parameters></tool_call>`,