3c922fe16c
- 新增 web_search 工具,使用 Tavily SDK 进行网络搜索 - 支持搜索深度(basic/advanced)和主题(general/news/finance)配置 - 新增 WebPermissionChecker 权限检查器 - 搜索操作默认需要用户确认,支持会话级权限记忆 - 配置文件支持 tavilyApiKey 存储
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import type { ToolResult } from '../types/index.js';
|
|
import type { ToolWithMetadata } from './types.js';
|
|
import { toolRegistry } from './registry.js';
|
|
|
|
/**
|
|
* tool_search 工具
|
|
* 用于搜索可用的工具,实现动态工具发现
|
|
*/
|
|
export const toolSearchTool: ToolWithMetadata = {
|
|
name: 'tool_search',
|
|
description: `搜索可用的工具。当你需要执行某项任务但当前没有合适的工具时,使用此工具搜索。
|
|
|
|
可搜索的能力类别:
|
|
- 文件操作: 读取、写入、编辑、复制、移动、删除文件
|
|
- 目录操作: 列出目录、创建目录、搜索文件
|
|
- 内容搜索: 在文件中搜索文本、grep
|
|
- Shell: 执行命令行命令
|
|
- Git: 版本控制操作 (即将支持)
|
|
- 网络: HTTP请求、网页抓取 (即将支持)
|
|
|
|
搜索后返回的工具将可以直接使用。`,
|
|
|
|
parameters: {
|
|
query: {
|
|
type: 'string',
|
|
description: '描述你需要的功能,如 "读取文件内容"、"搜索代码"、"移动文件"、"执行命令"',
|
|
required: true,
|
|
},
|
|
},
|
|
|
|
metadata: {
|
|
name: 'tool_search',
|
|
category: 'core',
|
|
description: '搜索可用工具',
|
|
keywords: ['search', 'find', 'tool', 'discover', '搜索', '查找', '工具', '发现'],
|
|
deferLoading: false, // 核心工具,始终加载
|
|
},
|
|
|
|
execute: async (params: Record<string, unknown>): Promise<ToolResult> => {
|
|
const query = params.query as string;
|
|
|
|
if (!query || query.trim().length === 0) {
|
|
return {
|
|
success: false,
|
|
output: '',
|
|
error: '请提供搜索关键词',
|
|
};
|
|
}
|
|
|
|
const results = toolRegistry.search(query, 5);
|
|
|
|
if (results.length === 0) {
|
|
return {
|
|
success: true,
|
|
output: `没有找到与 "${query}" 匹配的工具。请尝试其他关键词,或使用更通用的描述。`,
|
|
};
|
|
}
|
|
|
|
const toolList = results
|
|
.map((t) => `- ${t.name}: ${t.description} [${t.category}]`)
|
|
.join('\n');
|
|
|
|
return {
|
|
success: true,
|
|
output: `找到 ${results.length} 个相关工具:\n\n${toolList}\n\n重要:这些工具现在已经可以直接调用了。请立即使用合适的工具(如 web_search)来完成任务,不要使用 bash 命令代替。`,
|
|
};
|
|
},
|
|
};
|