@ai-zen/agents-sdk 0.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -0
  3. package/dist/capabilities/Capabilities.d.ts +71 -0
  4. package/dist/capabilities/Capabilities.js +161 -0
  5. package/dist/capabilities/PermissionEvaluator.d.ts +19 -0
  6. package/dist/capabilities/PermissionEvaluator.js +50 -0
  7. package/dist/capabilities/disclosure.d.ts +10 -0
  8. package/dist/capabilities/disclosure.js +17 -0
  9. package/dist/capabilities/discovery/builtin.d.ts +8 -0
  10. package/dist/capabilities/discovery/builtin.js +17 -0
  11. package/dist/capabilities/discovery/mcp.d.ts +7 -0
  12. package/dist/capabilities/discovery/mcp.js +29 -0
  13. package/dist/capabilities/discovery/skills.d.ts +43 -0
  14. package/dist/capabilities/discovery/skills.js +175 -0
  15. package/dist/capabilities/discovery/subagents.d.ts +7 -0
  16. package/dist/capabilities/discovery/subagents.js +39 -0
  17. package/dist/capabilities/discovery/usertools.d.ts +13 -0
  18. package/dist/capabilities/discovery/usertools.js +136 -0
  19. package/dist/capabilities/implements/builtin/batchEdit.d.ts +2 -0
  20. package/dist/capabilities/implements/builtin/batchEdit.js +76 -0
  21. package/dist/capabilities/implements/builtin/copy.d.ts +2 -0
  22. package/dist/capabilities/implements/builtin/copy.js +38 -0
  23. package/dist/capabilities/implements/builtin/cwd.d.ts +2 -0
  24. package/dist/capabilities/implements/builtin/cwd.js +15 -0
  25. package/dist/capabilities/implements/builtin/downloadFile.d.ts +2 -0
  26. package/dist/capabilities/implements/builtin/downloadFile.js +70 -0
  27. package/dist/capabilities/implements/builtin/edit.d.ts +2 -0
  28. package/dist/capabilities/implements/builtin/edit.js +79 -0
  29. package/dist/capabilities/implements/builtin/exec.d.ts +2 -0
  30. package/dist/capabilities/implements/builtin/exec.js +31 -0
  31. package/dist/capabilities/implements/builtin/exist.d.ts +2 -0
  32. package/dist/capabilities/implements/builtin/exist.js +25 -0
  33. package/dist/capabilities/implements/builtin/findText.d.ts +2 -0
  34. package/dist/capabilities/implements/builtin/findText.js +86 -0
  35. package/dist/capabilities/implements/builtin/generateImage.d.ts +9 -0
  36. package/dist/capabilities/implements/builtin/generateImage.js +112 -0
  37. package/dist/capabilities/implements/builtin/glob.d.ts +2 -0
  38. package/dist/capabilities/implements/builtin/glob.js +45 -0
  39. package/dist/capabilities/implements/builtin/index.d.ts +19 -0
  40. package/dist/capabilities/implements/builtin/index.js +34 -0
  41. package/dist/capabilities/implements/builtin/ls.d.ts +2 -0
  42. package/dist/capabilities/implements/builtin/ls.js +28 -0
  43. package/dist/capabilities/implements/builtin/mkdir.d.ts +2 -0
  44. package/dist/capabilities/implements/builtin/mkdir.js +34 -0
  45. package/dist/capabilities/implements/builtin/readFile.d.ts +2 -0
  46. package/dist/capabilities/implements/builtin/readFile.js +31 -0
  47. package/dist/capabilities/implements/builtin/rename.d.ts +2 -0
  48. package/dist/capabilities/implements/builtin/rename.js +32 -0
  49. package/dist/capabilities/implements/builtin/rm.d.ts +2 -0
  50. package/dist/capabilities/implements/builtin/rm.js +34 -0
  51. package/dist/capabilities/implements/builtin/writeFile.d.ts +2 -0
  52. package/dist/capabilities/implements/builtin/writeFile.js +34 -0
  53. package/dist/capabilities/implements/mcpTools.d.ts +20 -0
  54. package/dist/capabilities/implements/mcpTools.js +147 -0
  55. package/dist/capabilities/implements/skillTools.d.ts +15 -0
  56. package/dist/capabilities/implements/skillTools.js +113 -0
  57. package/dist/capabilities/implements/subAgentTools.d.ts +11 -0
  58. package/dist/capabilities/implements/subAgentTools.js +53 -0
  59. package/dist/config/ConfigManager.d.ts +49 -0
  60. package/dist/config/ConfigManager.js +126 -0
  61. package/dist/config/constants.d.ts +20 -0
  62. package/dist/config/constants.js +185 -0
  63. package/dist/crud/AgentRepository.d.ts +9 -0
  64. package/dist/crud/AgentRepository.js +10 -0
  65. package/dist/crud/ConversationRepository.d.ts +9 -0
  66. package/dist/crud/ConversationRepository.js +10 -0
  67. package/dist/crud/DraftRepository.d.ts +15 -0
  68. package/dist/crud/DraftRepository.js +41 -0
  69. package/dist/index.d.ts +40 -0
  70. package/dist/index.js +37 -0
  71. package/dist/plugin/AutoDraftPlugin.d.ts +26 -0
  72. package/dist/plugin/AutoDraftPlugin.js +58 -0
  73. package/dist/plugin/AutoMigratePlugin.d.ts +25 -0
  74. package/dist/plugin/AutoMigratePlugin.js +74 -0
  75. package/dist/plugin/AutoRefreshToolsPlugin.d.ts +12 -0
  76. package/dist/plugin/AutoRefreshToolsPlugin.js +23 -0
  77. package/dist/runtime/McpConnectionManager.d.ts +42 -0
  78. package/dist/runtime/McpConnectionManager.js +238 -0
  79. package/dist/runtime/Provider.d.ts +44 -0
  80. package/dist/runtime/Provider.js +38 -0
  81. package/dist/runtime/SdkAgent.d.ts +100 -0
  82. package/dist/runtime/SdkAgent.js +103 -0
  83. package/dist/runtime/TaskMigrationService.d.ts +24 -0
  84. package/dist/runtime/TaskMigrationService.js +71 -0
  85. package/dist/runtime/createAgent.d.ts +14 -0
  86. package/dist/runtime/createAgent.js +41 -0
  87. package/dist/runtime/createModel.d.ts +11 -0
  88. package/dist/runtime/createModel.js +28 -0
  89. package/dist/shared/EntityRepository.d.ts +24 -0
  90. package/dist/shared/EntityRepository.js +62 -0
  91. package/dist/shared/errors.d.ts +8 -0
  92. package/dist/shared/errors.js +15 -0
  93. package/dist/shared/logger.d.ts +10 -0
  94. package/dist/shared/logger.js +10 -0
  95. package/dist/types/index.d.ts +178 -0
  96. package/dist/types/index.js +5 -0
  97. package/package.json +47 -0
@@ -0,0 +1,31 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import { exec } from "child_process";
3
+ export const execTool = new CallbackTool({
4
+ function: {
5
+ name: "exec",
6
+ description: "执行命令",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ command: {
11
+ type: "string",
12
+ description: "要执行的命令",
13
+ },
14
+ },
15
+ required: ["command"],
16
+ additionalProperties: false,
17
+ },
18
+ },
19
+ async callback(input) {
20
+ const result = await new Promise((resolve) => {
21
+ exec(input.command, (error, stdout, stderr) => {
22
+ resolve({
23
+ stdout,
24
+ stderr,
25
+ exitCode: error?.code ?? (error ? 1 : null),
26
+ });
27
+ });
28
+ });
29
+ return JSON.stringify(result);
30
+ },
31
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const existTool: CallbackTool;
@@ -0,0 +1,25 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const existTool = new CallbackTool({
4
+ function: {
5
+ name: "exist",
6
+ description: "检查文件或目录是否存在",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ path: {
11
+ type: "string",
12
+ description: "文件或目录路径",
13
+ },
14
+ },
15
+ required: ["path"],
16
+ additionalProperties: false,
17
+ },
18
+ },
19
+ async callback(input) {
20
+ return await fsp
21
+ .access(input.path)
22
+ .then(() => "true")
23
+ .catch(() => "false");
24
+ },
25
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const findTextTool: CallbackTool;
@@ -0,0 +1,86 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ import * as path from "path";
4
+ export const findTextTool = new CallbackTool({
5
+ function: {
6
+ name: "findText",
7
+ description: "查找文本出现的位置,支持普通文本或正则匹配,返回文件名及具体行号、行内容",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ path: {
12
+ type: "string",
13
+ description: "glob cwd",
14
+ },
15
+ pattern: {
16
+ type: "string",
17
+ description: "glob pattern",
18
+ },
19
+ text: {
20
+ type: "string",
21
+ description: "要查找的文本(与 regex 二选一)",
22
+ },
23
+ regex: {
24
+ type: "string",
25
+ description: "正则表达式(与 text 二选一,例如 \\bconst\\s+\\w+)",
26
+ },
27
+ exclude: {
28
+ type: "array",
29
+ description: "要排除的 glob 模式数组",
30
+ items: {
31
+ type: "string",
32
+ },
33
+ },
34
+ },
35
+ required: ["path", "pattern"],
36
+ },
37
+ },
38
+ async callback(input) {
39
+ try {
40
+ const result = [];
41
+ const text = input.text;
42
+ const regexStr = input.regex;
43
+ if (!text && !regexStr) {
44
+ return "请提供 text 或 regex 参数";
45
+ }
46
+ const regex = regexStr ? new RegExp(regexStr) : null;
47
+ for await (const file of fsp.glob(input.pattern, {
48
+ cwd: input.path,
49
+ exclude: input.exclude || ["**/node_modules/**"],
50
+ })) {
51
+ const fullPath = path.join(input.path, file);
52
+ const stats = await fsp.stat(fullPath);
53
+ if (stats.isFile()) {
54
+ const content = await fsp.readFile(fullPath, "utf-8");
55
+ const lines = content.split("\n");
56
+ const matches = [];
57
+ lines.forEach((lineContent, index) => {
58
+ if (regex) {
59
+ const matchResult = lineContent.match(regex);
60
+ if (matchResult) {
61
+ matches.push({
62
+ line: index + 1,
63
+ content: lineContent,
64
+ match: matchResult[0],
65
+ });
66
+ }
67
+ }
68
+ else if (lineContent.includes(text)) {
69
+ matches.push({
70
+ line: index + 1,
71
+ content: lineContent,
72
+ });
73
+ }
74
+ });
75
+ if (matches.length > 0) {
76
+ result.push({ file, matches });
77
+ }
78
+ }
79
+ }
80
+ return JSON.stringify(result);
81
+ }
82
+ catch (error) {
83
+ return error?.message;
84
+ }
85
+ },
86
+ });
@@ -0,0 +1,9 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import type { AppConfig } from "../../../types/index.js";
3
+ /**
4
+ * 根据文字描述生成图片。返回图片 URL,可通过 downloadFile 工具保存到本地。
5
+ *
6
+ * 依赖 AppConfig 中的 imageModels 和 defaultImageModel 配置。
7
+ * 如果未配置图片模型,工具会返回错误提示。
8
+ */
9
+ export declare function createGenerateImageTool(config: AppConfig): CallbackTool;
@@ -0,0 +1,112 @@
1
+ import { CallbackTool, OpenAI, ZhipuImage } from "@ai-zen/agents-core";
2
+ /**
3
+ * 根据文字描述生成图片。返回图片 URL,可通过 downloadFile 工具保存到本地。
4
+ *
5
+ * 依赖 AppConfig 中的 imageModels 和 defaultImageModel 配置。
6
+ * 如果未配置图片模型,工具会返回错误提示。
7
+ */
8
+ export function createGenerateImageTool(config) {
9
+ return new CallbackTool({
10
+ function: {
11
+ name: "generateImage",
12
+ description: "根据文字描述生成图片。返回图片 URL,可通过 downloadFile 工具保存到本地。",
13
+ parameters: {
14
+ type: "object",
15
+ properties: {
16
+ prompt: {
17
+ type: "string",
18
+ description: "所需图像的文本描述,应详细描述画面内容、风格、构图等",
19
+ },
20
+ model: {
21
+ type: "string",
22
+ description: "图片模型 ID,不指定则使用配置中的默认图片模型。配置中的图片模型可通过 'aiz config show' 查看。",
23
+ },
24
+ size: {
25
+ type: "string",
26
+ description: '图片尺寸。不指定则使用模型的默认尺寸。cogview系列: 1024x1024, 768x1344, 864x1152, 1344x768, 1152x864, 1440x720, 720x1440。glm-image: 1280x1280, 1568x1056, 1056x1568, 1472x1088, 1088x1472, 1728x960, 960x1728。',
27
+ },
28
+ quality: {
29
+ type: "string",
30
+ description: "图像质量。hd: 精细(约20秒), standard: 快速(约5-10秒)",
31
+ enum: ["hd", "standard"],
32
+ },
33
+ },
34
+ required: ["prompt"],
35
+ additionalProperties: false,
36
+ },
37
+ },
38
+ async callback(input) {
39
+ try {
40
+ const prompt = input.prompt;
41
+ if (!prompt || !prompt.trim()) {
42
+ return JSON.stringify({ success: false, error: "prompt 不能为空" });
43
+ }
44
+ const imageModels = config.imageModels;
45
+ const defaultImageModel = config.defaultImageModel;
46
+ if (!imageModels || imageModels.length === 0) {
47
+ return JSON.stringify({
48
+ success: false,
49
+ error: "未配置图片生成模型。请在配置中添加 imageModels。",
50
+ });
51
+ }
52
+ const modelId = input.model || defaultImageModel;
53
+ const imageModel = modelId
54
+ ? imageModels.find((m) => m.id === modelId)
55
+ : imageModels[0];
56
+ if (!imageModel) {
57
+ return JSON.stringify({
58
+ success: false,
59
+ error: `图片模型 "${modelId}" 不存在。可用的图片模型: ${imageModels.map((m) => m.id).join(", ")}`,
60
+ });
61
+ }
62
+ const endpoint = config.endpoints.find((e) => e.id === imageModel.endpointId);
63
+ if (!endpoint) {
64
+ return JSON.stringify({
65
+ success: false,
66
+ error: `图片模型 "${imageModel.name}" 对应的端点 "${imageModel.endpointId}" 未配置`,
67
+ });
68
+ }
69
+ if (!endpoint.apiKey) {
70
+ return JSON.stringify({
71
+ success: false,
72
+ error: `端点 "${endpoint.name}" 的 API Key 未设置`,
73
+ });
74
+ }
75
+ const ep = new OpenAI({
76
+ openai_endpoint: endpoint.baseUrl,
77
+ api_key: endpoint.apiKey,
78
+ });
79
+ const modelName = input.model || imageModel.modelName;
80
+ const model = new ZhipuImage({
81
+ request_config: await ep.imageGeneration(modelName),
82
+ });
83
+ const result = await model.generate({
84
+ prompt: prompt.trim(),
85
+ model: modelName,
86
+ size: input.size || imageModel.defaultSize || undefined,
87
+ quality: input.quality || imageModel.defaultQuality || undefined,
88
+ });
89
+ const images = result.data.map((img, i) => ({
90
+ index: i,
91
+ url: img.url,
92
+ description: `图片 ${i + 1}`,
93
+ }));
94
+ return JSON.stringify({
95
+ success: true,
96
+ model: imageModel.name,
97
+ modelId: imageModel.id,
98
+ created: result.created,
99
+ images,
100
+ content_filter: result.content_filter || [],
101
+ note: "图片临时链接有效期为30天,请及时转存图片。",
102
+ }, null, 2);
103
+ }
104
+ catch (error) {
105
+ return JSON.stringify({
106
+ success: false,
107
+ error: error instanceof Error ? error.message : "图片生成失败",
108
+ });
109
+ }
110
+ },
111
+ });
112
+ }
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const globTool: CallbackTool;
@@ -0,0 +1,45 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const globTool = new CallbackTool({
4
+ function: {
5
+ name: "glob",
6
+ description: "使用 glob 模式递归扫描和查找文件。这是进行文件系统搜索的首选工具,功能远优于简单的 'ls' 列表命令。当你需要查找特定类型的文件、遍历目录树或需要排除特定文件时,请优先使用此函数。",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ path: {
11
+ type: "string",
12
+ description: "glob cwd",
13
+ },
14
+ pattern: {
15
+ type: "string",
16
+ description: "glob pattern",
17
+ },
18
+ exclude: {
19
+ type: "array",
20
+ description: "glob pattern to exclude",
21
+ items: {
22
+ type: "string",
23
+ },
24
+ },
25
+ },
26
+ required: ["pattern"],
27
+ additionalProperties: false,
28
+ },
29
+ },
30
+ async callback(input) {
31
+ try {
32
+ const result = [];
33
+ for await (const file of fsp.glob(input.pattern, {
34
+ exclude: input.exclude || ["**/node_modules/**"],
35
+ cwd: input.path,
36
+ })) {
37
+ result.push(file);
38
+ }
39
+ return JSON.stringify(result);
40
+ }
41
+ catch (error) {
42
+ return error?.message;
43
+ }
44
+ },
45
+ });
@@ -0,0 +1,19 @@
1
+ import type { Tool } from "@ai-zen/agents-core";
2
+ import { cwdTool } from "./cwd.js";
3
+ import { readFileTool } from "./readFile.js";
4
+ import { writeFileTool } from "./writeFile.js";
5
+ import { execTool } from "./exec.js";
6
+ import { mkdirTool } from "./mkdir.js";
7
+ import { rmTool } from "./rm.js";
8
+ import { globTool } from "./glob.js";
9
+ import { lsTool } from "./ls.js";
10
+ import { existTool } from "./exist.js";
11
+ import { findTextTool } from "./findText.js";
12
+ import { downloadFileTool } from "./downloadFile.js";
13
+ import { renameTool } from "./rename.js";
14
+ import { copyTool } from "./copy.js";
15
+ import { batchEditTool } from "./batchEdit.js";
16
+ import { editTool } from "./edit.js";
17
+ /** 15 个内置工具实例,注册与实现一体。 */
18
+ export declare const BUILTIN_TOOLS: Tool[];
19
+ export { cwdTool, readFileTool, writeFileTool, execTool, mkdirTool, rmTool, globTool, lsTool, existTool, findTextTool, downloadFileTool, renameTool, copyTool, batchEditTool, editTool };
@@ -0,0 +1,34 @@
1
+ import { cwdTool } from "./cwd.js";
2
+ import { readFileTool } from "./readFile.js";
3
+ import { writeFileTool } from "./writeFile.js";
4
+ import { execTool } from "./exec.js";
5
+ import { mkdirTool } from "./mkdir.js";
6
+ import { rmTool } from "./rm.js";
7
+ import { globTool } from "./glob.js";
8
+ import { lsTool } from "./ls.js";
9
+ import { existTool } from "./exist.js";
10
+ import { findTextTool } from "./findText.js";
11
+ import { downloadFileTool } from "./downloadFile.js";
12
+ import { renameTool } from "./rename.js";
13
+ import { copyTool } from "./copy.js";
14
+ import { batchEditTool } from "./batchEdit.js";
15
+ import { editTool } from "./edit.js";
16
+ /** 15 个内置工具实例,注册与实现一体。 */
17
+ export const BUILTIN_TOOLS = [
18
+ cwdTool,
19
+ readFileTool,
20
+ writeFileTool,
21
+ execTool,
22
+ mkdirTool,
23
+ rmTool,
24
+ globTool,
25
+ lsTool,
26
+ existTool,
27
+ findTextTool,
28
+ downloadFileTool,
29
+ renameTool,
30
+ copyTool,
31
+ batchEditTool,
32
+ editTool,
33
+ ];
34
+ export { cwdTool, readFileTool, writeFileTool, execTool, mkdirTool, rmTool, globTool, lsTool, existTool, findTextTool, downloadFileTool, renameTool, copyTool, batchEditTool, editTool };
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const lsTool: CallbackTool;
@@ -0,0 +1,28 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const lsTool = new CallbackTool({
4
+ function: {
5
+ name: "ls",
6
+ description: "列出目录",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ path: {
11
+ type: "string",
12
+ description: "目录路径",
13
+ },
14
+ },
15
+ required: ["path"],
16
+ additionalProperties: false,
17
+ },
18
+ },
19
+ async callback(input) {
20
+ try {
21
+ const result = await fsp.readdir(input.path);
22
+ return JSON.stringify(result);
23
+ }
24
+ catch (error) {
25
+ return error?.message;
26
+ }
27
+ },
28
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const mkdirTool: CallbackTool;
@@ -0,0 +1,34 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const mkdirTool = new CallbackTool({
4
+ function: {
5
+ name: "mkdir",
6
+ description: "创建目录",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ path: {
11
+ type: "string",
12
+ description: "目录路径",
13
+ },
14
+ recursive: {
15
+ type: "boolean",
16
+ description: "是否递归创建子目录",
17
+ },
18
+ },
19
+ required: ["path"],
20
+ additionalProperties: false,
21
+ },
22
+ },
23
+ async callback(input) {
24
+ try {
25
+ await fsp.mkdir(input.path, {
26
+ recursive: input.recursive,
27
+ });
28
+ return "success";
29
+ }
30
+ catch (error) {
31
+ return error?.message;
32
+ }
33
+ },
34
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const readFileTool: CallbackTool;
@@ -0,0 +1,31 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const readFileTool = new CallbackTool({
4
+ function: {
5
+ name: "readFile",
6
+ description: "读取文件",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ path: {
11
+ type: "string",
12
+ description: "文件路径",
13
+ },
14
+ },
15
+ required: ["path"],
16
+ additionalProperties: false,
17
+ },
18
+ },
19
+ async callback(input) {
20
+ try {
21
+ const stats = await fsp.stat(input.path);
22
+ if (stats.size > 300 * 1024) {
23
+ throw new Error(`文件过大,无法读取,当前文件大小 ${stats.size} 字节`);
24
+ }
25
+ return await fsp.readFile(input.path, "utf-8");
26
+ }
27
+ catch (error) {
28
+ return error?.message;
29
+ }
30
+ },
31
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const renameTool: CallbackTool;
@@ -0,0 +1,32 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const renameTool = new CallbackTool({
4
+ function: {
5
+ name: "rename",
6
+ description: "重命名或移动文件/目录(相当于 mv 命令)",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ oldPath: {
11
+ type: "string",
12
+ description: "原路径",
13
+ },
14
+ newPath: {
15
+ type: "string",
16
+ description: "新路径",
17
+ },
18
+ },
19
+ required: ["oldPath", "newPath"],
20
+ additionalProperties: false,
21
+ },
22
+ },
23
+ async callback(input) {
24
+ try {
25
+ await fsp.rename(input.oldPath, input.newPath);
26
+ return "success";
27
+ }
28
+ catch (error) {
29
+ return error?.message;
30
+ }
31
+ },
32
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const rmTool: CallbackTool;
@@ -0,0 +1,34 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ export const rmTool = new CallbackTool({
4
+ function: {
5
+ name: "rm",
6
+ description: "删除文件或目录",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ path: {
11
+ type: "string",
12
+ description: "文件或目录路径",
13
+ },
14
+ recursive: {
15
+ type: "boolean",
16
+ description: "是否递归删除子目录",
17
+ },
18
+ },
19
+ required: ["path"],
20
+ additionalProperties: false,
21
+ },
22
+ },
23
+ async callback(input) {
24
+ try {
25
+ await fsp.rm(input.path, {
26
+ recursive: input.recursive ?? false,
27
+ });
28
+ return "success";
29
+ }
30
+ catch (error) {
31
+ return error?.message;
32
+ }
33
+ },
34
+ });
@@ -0,0 +1,2 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ export declare const writeFileTool: CallbackTool;
@@ -0,0 +1,34 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import * as fsp from "fs/promises";
3
+ import * as path from "path";
4
+ export const writeFileTool = new CallbackTool({
5
+ function: {
6
+ name: "writeFile",
7
+ description: "写入文件",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ path: {
12
+ type: "string",
13
+ description: "文件路径",
14
+ },
15
+ content: {
16
+ type: "string",
17
+ description: "文件内容",
18
+ },
19
+ },
20
+ required: ["path", "content"],
21
+ additionalProperties: false,
22
+ },
23
+ },
24
+ async callback(input) {
25
+ try {
26
+ await fsp.mkdir(path.dirname(input.path), { recursive: true });
27
+ await fsp.writeFile(input.path, input.content);
28
+ return "success";
29
+ }
30
+ catch (error) {
31
+ return error?.message;
32
+ }
33
+ },
34
+ });
@@ -0,0 +1,20 @@
1
+ import { CallbackTool } from "@ai-zen/agents-core";
2
+ import type { McpConnectionManager } from "../../runtime/McpConnectionManager.js";
3
+ import type { McpServerConfig } from "../../types/index.js";
4
+ /**
5
+ * 创建 load_mcp 工具。
6
+ * server 枚举由 filteredMcps (完整 McpServerConfig[])自动推导。
7
+ */
8
+ export declare function createLoadMcpTool(mcpManager: McpConnectionManager, mcpConfigs: Map<string, {
9
+ name: string;
10
+ config: McpServerConfig;
11
+ }>, filteredMcps: McpServerConfig[]): CallbackTool;
12
+ /**
13
+ * 创建 call_mcp_tool 工具。
14
+ * 通过官方 Client.callTool() API 调用 MCP 服务器上的工具。
15
+ */
16
+ export declare function createCallMcpTool(mcpManager: McpConnectionManager): CallbackTool;
17
+ /**
18
+ * 创建 read_mcp_resource 工具。
19
+ */
20
+ export declare function createReadMcpResourceTool(mcpManager: McpConnectionManager): CallbackTool;