first commit

This commit is contained in:
lingyuzeng
2026-03-22 13:16:22 +08:00
commit ba7d42da13
23 changed files with 3541 additions and 0 deletions

48
test/xml-toolcall.test.ts Executable file
View File

@@ -0,0 +1,48 @@
import { describe, it, expect } from 'vitest';
import { parseXmlToolCalls } from '../src/parsers/xml-toolcall';
describe('XML ToolCall Parser', () => {
it('parses basic XML tool call correctly', () => {
const content = `
<tool_call>
<function=read>
<parameter=path>
/tmp/test.txt
</parameter>
</function>
</tool_call>
`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(1);
expect(result[0].name).toBe('read');
expect(result[0].args).toEqual({ path: '/tmp/test.txt' });
});
it('parses multiple parameters correctly', () => {
const content = `
<function=write>
<parameter=path>
/tmp/a.txt
</parameter>
<parameter=content>
hello
</parameter>
</function>
`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(1);
expect(result[0].name).toBe('write');
expect(result[0].args).toEqual({
path: '/tmp/a.txt',
content: 'hello'
});
});
it('ignores normal text', () => {
const content = `I will read the file. Let me check the system.`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(0);
});
});