refactor(core): 实现类型安全的工具定义系统
- 新增 defineTool 函数,使用 Zod schema 定义参数并自动推断 TypeScript 类型 - 重构文件系统工具 (read_file, write_file, edit_file, glob, grep, multi_edit) 使用 Zod 类型推断 - 重构 shell 工具 (bash, kill_shell) 使用新的类型安全系统 - 重构 task 工具 (task, task_output) 使用 Zod 验证 - 兼容 Zod v4 API (处理 _zod.def vs _def, error.issues vs error.errors) - 导出参数类型供外部使用 (ReadFileParams, BashParams 等) - 统一参数命名: path -> file_path - 修复相关测试以适配新的参数结构和输出格式 - 移除不存在工具的测试文件
This commit is contained in:
@@ -65,9 +65,9 @@ describe('bashTool - Bash 命令工具', () => {
|
||||
expect(bashTool.parameters.command.required).toBe(true);
|
||||
});
|
||||
|
||||
it('定义了可选的 cwd 参数', () => {
|
||||
expect(bashTool.parameters.cwd).toBeDefined();
|
||||
expect(bashTool.parameters.cwd.required).toBe(false);
|
||||
it('定义了可选的 timeout 参数', () => {
|
||||
expect(bashTool.parameters.timeout).toBeDefined();
|
||||
expect(bashTool.parameters.timeout?.required).not.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -172,11 +172,12 @@ describe('bashTool - Bash 命令工具', () => {
|
||||
checkBashPermission: mockCheck,
|
||||
} as any);
|
||||
|
||||
await bashTool.execute({ command: 'ls -la', cwd: '/home/user' });
|
||||
await bashTool.execute({ command: 'ls -la' });
|
||||
|
||||
// bashTool 使用 process.cwd() 作为 workdir
|
||||
expect(mockCheck).toHaveBeenCalledWith({
|
||||
command: 'ls -la',
|
||||
workdir: '/home/user',
|
||||
workdir: expect.any(String),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user