@ai-zen/agents-sdk 0.4.0 → 0.5.0

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 (91) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +19 -15
  3. package/dist/capabilities/discovery/builtin.d.ts +7 -6
  4. package/dist/capabilities/discovery/builtin.js +10 -9
  5. package/dist/capabilities/implements/builtin/BatchEditTool.d.ts +15 -0
  6. package/dist/capabilities/implements/builtin/BatchEditTool.js +82 -0
  7. package/dist/capabilities/implements/builtin/CopyTool.d.ts +10 -0
  8. package/dist/capabilities/implements/builtin/CopyTool.js +43 -0
  9. package/dist/capabilities/implements/builtin/CwdTool.d.ts +6 -0
  10. package/dist/capabilities/implements/builtin/CwdTool.js +20 -0
  11. package/dist/capabilities/implements/builtin/DownloadFileTool.d.ts +9 -0
  12. package/dist/capabilities/implements/builtin/{downloadFile.js → DownloadFileTool.js} +29 -24
  13. package/dist/capabilities/implements/builtin/EditTool.d.ts +11 -0
  14. package/dist/capabilities/implements/builtin/EditTool.js +84 -0
  15. package/dist/capabilities/implements/builtin/ExecAsyncTool.d.ts +10 -0
  16. package/dist/capabilities/implements/builtin/{execAsync.js → ExecAsyncTool.js} +32 -34
  17. package/dist/capabilities/implements/builtin/ExecTool.d.ts +9 -0
  18. package/dist/capabilities/implements/builtin/ExecTool.js +46 -0
  19. package/dist/capabilities/implements/builtin/ExistTool.d.ts +8 -0
  20. package/dist/capabilities/implements/builtin/ExistTool.js +30 -0
  21. package/dist/capabilities/implements/builtin/FindTextTool.d.ts +12 -0
  22. package/dist/capabilities/implements/builtin/{findText.js → FindTextTool.js} +43 -37
  23. package/dist/capabilities/implements/builtin/GenerateImageTool.d.ts +21 -0
  24. package/dist/capabilities/implements/builtin/GenerateImageTool.js +121 -0
  25. package/dist/capabilities/implements/builtin/GlobTool.d.ts +10 -0
  26. package/dist/capabilities/implements/builtin/GlobTool.js +51 -0
  27. package/dist/capabilities/implements/builtin/LsTool.d.ts +8 -0
  28. package/dist/capabilities/implements/builtin/LsTool.js +33 -0
  29. package/dist/capabilities/implements/builtin/MkdirTool.d.ts +9 -0
  30. package/dist/capabilities/implements/builtin/MkdirTool.js +39 -0
  31. package/dist/capabilities/implements/builtin/ReadFileTool.d.ts +8 -0
  32. package/dist/capabilities/implements/builtin/ReadFileTool.js +37 -0
  33. package/dist/capabilities/implements/builtin/RenameTool.d.ts +9 -0
  34. package/dist/capabilities/implements/builtin/RenameTool.js +37 -0
  35. package/dist/capabilities/implements/builtin/RmTool.d.ts +9 -0
  36. package/dist/capabilities/implements/builtin/RmTool.js +39 -0
  37. package/dist/capabilities/implements/builtin/SleepTool.d.ts +8 -0
  38. package/dist/capabilities/implements/builtin/SleepTool.js +46 -0
  39. package/dist/capabilities/implements/builtin/WriteFileTool.d.ts +9 -0
  40. package/dist/capabilities/implements/builtin/WriteFileTool.js +40 -0
  41. package/dist/capabilities/implements/builtin/index.d.ts +29 -21
  42. package/dist/capabilities/implements/builtin/index.js +44 -37
  43. package/dist/capabilities/implements/builtin/test-helpers.d.ts +3 -0
  44. package/dist/capabilities/implements/builtin/test-helpers.js +4 -0
  45. package/dist/index.d.ts +5 -9
  46. package/dist/index.js +6 -9
  47. package/dist/runtime/Provider.d.ts +9 -1
  48. package/dist/runtime/Provider.js +7 -1
  49. package/dist/runtime/SdkCallbackTool.d.ts +28 -0
  50. package/dist/runtime/SdkCallbackTool.js +33 -0
  51. package/dist/types/index.d.ts +12 -20
  52. package/package.json +1 -1
  53. package/dist/capabilities/implements/builtin/batchEdit.d.ts +0 -2
  54. package/dist/capabilities/implements/builtin/batchEdit.js +0 -76
  55. package/dist/capabilities/implements/builtin/copy.d.ts +0 -2
  56. package/dist/capabilities/implements/builtin/copy.js +0 -38
  57. package/dist/capabilities/implements/builtin/cwd.d.ts +0 -2
  58. package/dist/capabilities/implements/builtin/cwd.js +0 -15
  59. package/dist/capabilities/implements/builtin/downloadFile.d.ts +0 -2
  60. package/dist/capabilities/implements/builtin/edit.d.ts +0 -2
  61. package/dist/capabilities/implements/builtin/edit.js +0 -79
  62. package/dist/capabilities/implements/builtin/exec.d.ts +0 -2
  63. package/dist/capabilities/implements/builtin/exec.js +0 -38
  64. package/dist/capabilities/implements/builtin/execAsync.d.ts +0 -2
  65. package/dist/capabilities/implements/builtin/exist.d.ts +0 -2
  66. package/dist/capabilities/implements/builtin/exist.js +0 -25
  67. package/dist/capabilities/implements/builtin/findText.d.ts +0 -2
  68. package/dist/capabilities/implements/builtin/generateImage.d.ts +0 -9
  69. package/dist/capabilities/implements/builtin/generateImage.js +0 -112
  70. package/dist/capabilities/implements/builtin/glob.d.ts +0 -2
  71. package/dist/capabilities/implements/builtin/glob.js +0 -45
  72. package/dist/capabilities/implements/builtin/ls.d.ts +0 -2
  73. package/dist/capabilities/implements/builtin/ls.js +0 -28
  74. package/dist/capabilities/implements/builtin/mkdir.d.ts +0 -2
  75. package/dist/capabilities/implements/builtin/mkdir.js +0 -34
  76. package/dist/capabilities/implements/builtin/readFile.d.ts +0 -2
  77. package/dist/capabilities/implements/builtin/readFile.js +0 -31
  78. package/dist/capabilities/implements/builtin/rename.d.ts +0 -2
  79. package/dist/capabilities/implements/builtin/rename.js +0 -32
  80. package/dist/capabilities/implements/builtin/rm.d.ts +0 -2
  81. package/dist/capabilities/implements/builtin/rm.js +0 -34
  82. package/dist/capabilities/implements/builtin/sleep.d.ts +0 -2
  83. package/dist/capabilities/implements/builtin/sleep.js +0 -41
  84. package/dist/capabilities/implements/builtin/writeFile.d.ts +0 -2
  85. package/dist/capabilities/implements/builtin/writeFile.js +0 -34
  86. package/dist/crud/ConversationRepository.d.ts +0 -9
  87. package/dist/crud/ConversationRepository.js +0 -10
  88. package/dist/crud/DraftRepository.d.ts +0 -15
  89. package/dist/crud/DraftRepository.js +0 -52
  90. package/dist/plugin/AutoDraftPlugin.d.ts +0 -26
  91. package/dist/plugin/AutoDraftPlugin.js +0 -62
@@ -1,15 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export const cwdTool = new CallbackTool({
3
- function: {
4
- name: "cwd",
5
- description: "获取当前工作目录 cwd",
6
- parameters: {
7
- type: "object",
8
- properties: {},
9
- required: [],
10
- },
11
- },
12
- async callback() {
13
- return process.cwd();
14
- },
15
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const downloadFileTool: CallbackTool;
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const editTool: CallbackTool;
@@ -1,79 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- import * as fsp from "fs/promises";
3
- function countOccurrences(content, text) {
4
- let count = 0;
5
- let pos = 0;
6
- while (true) {
7
- pos = content.indexOf(text, pos);
8
- if (pos === -1)
9
- break;
10
- count++;
11
- pos += text.length;
12
- }
13
- return count;
14
- }
15
- export const editTool = new CallbackTool({
16
- function: {
17
- name: "edit",
18
- description: "编辑文件中的文本,支持精确替换或替换所有匹配项",
19
- parameters: {
20
- type: "object",
21
- properties: {
22
- path: {
23
- type: "string",
24
- description: "文件路径",
25
- },
26
- oldText: {
27
- type: "string",
28
- description: "要替换的文本",
29
- },
30
- newText: {
31
- type: "string",
32
- description: "替换后的文本",
33
- },
34
- isReplaceAll: {
35
- type: "boolean",
36
- description: "是否替换所有匹配的文本(默认 false,仅替换首次匹配)。使用此功能前应确保你提供的 oldText 足够精确,避免误替换",
37
- default: false,
38
- },
39
- },
40
- required: ["path", "oldText", "newText"],
41
- additionalProperties: false,
42
- },
43
- },
44
- async callback(input) {
45
- try {
46
- const path = input.path;
47
- const oldText = input.oldText;
48
- const newText = input.newText;
49
- const isReplaceAll = input.isReplaceAll;
50
- const content = await fsp.readFile(path, "utf-8");
51
- const count = countOccurrences(content, oldText);
52
- if (count === 0) {
53
- return JSON.stringify({
54
- result: "文件中未精确匹配到要替换的文本",
55
- matchCount: 0,
56
- });
57
- }
58
- const newContent = isReplaceAll
59
- ? content.replaceAll(oldText, newText)
60
- : content.replace(oldText, newText);
61
- await fsp.writeFile(path, newContent);
62
- if (!isReplaceAll && count > 1) {
63
- return JSON.stringify({
64
- result: `警告:未开启替换所有(isReplaceAll=false),但文本 "${oldText}" 在文件中出现了 ${count} 次,仅替换了首次匹配。如果希望替换所有匹配,请将 isReplaceAll 设为 true`,
65
- matchCount: count,
66
- replacedCount: 1,
67
- });
68
- }
69
- return JSON.stringify({
70
- result: "success",
71
- matchCount: count,
72
- replacedCount: isReplaceAll ? count : 1,
73
- });
74
- }
75
- catch (error) {
76
- return error?.message;
77
- }
78
- },
79
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const execTool: CallbackTool;
@@ -1,38 +0,0 @@
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
- timeout: {
15
- type: "number",
16
- description: "超时时间(毫秒),超时后会终止进程。默认无超时。建议长时间运行的命令使用 exec_async 异步执行。",
17
- },
18
- },
19
- required: ["command"],
20
- additionalProperties: false,
21
- },
22
- },
23
- async callback(input) {
24
- const command = input.command;
25
- const timeout = input.timeout;
26
- const result = await new Promise((resolve) => {
27
- const child = exec(command, { timeout: timeout && timeout > 0 ? timeout : undefined }, (error, stdout, stderr) => {
28
- resolve({
29
- stdout,
30
- stderr,
31
- exitCode: error?.code ?? (error ? 1 : null),
32
- killed: error?.killed ?? false,
33
- });
34
- });
35
- });
36
- return JSON.stringify(result);
37
- },
38
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const execAsyncTool: CallbackTool;
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const existTool: CallbackTool;
@@ -1,25 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const findTextTool: CallbackTool;
@@ -1,9 +0,0 @@
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;
@@ -1,112 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const globTool: CallbackTool;
@@ -1,45 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const lsTool: CallbackTool;
@@ -1,28 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const mkdirTool: CallbackTool;
@@ -1,34 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const readFileTool: CallbackTool;
@@ -1,31 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const renameTool: CallbackTool;
@@ -1,32 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const rmTool: CallbackTool;
@@ -1,34 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const sleepTool: CallbackTool;
@@ -1,41 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export const sleepTool = new CallbackTool({
3
- function: {
4
- name: "sleep",
5
- description: "等待指定的时间(毫秒)。用于需要延迟执行的场景,例如等待其他操作完成、操作间隔控制等。注意:过长的等待时间会影响响应速度,建议不超过 30000 毫秒(30 秒)。",
6
- parameters: {
7
- type: "object",
8
- properties: {
9
- ms: {
10
- type: "number",
11
- description: "等待的毫秒数(1 秒 = 1000 毫秒)。建议不超过 30000(30 秒)。",
12
- },
13
- },
14
- required: ["ms"],
15
- additionalProperties: false,
16
- },
17
- },
18
- async callback(input) {
19
- const ms = input.ms;
20
- if (typeof ms !== "number" || !Number.isFinite(ms) || ms < 0) {
21
- return JSON.stringify({
22
- success: false,
23
- error: "ms 必须是正整数",
24
- });
25
- }
26
- if (ms > 300_000) {
27
- // 超过 5 分钟给出警告
28
- return JSON.stringify({
29
- success: false,
30
- error: `等待时间 ${ms}ms 过长,建议不超过 300000ms(5 分钟)。如需长时间等待请分段执行。`,
31
- });
32
- }
33
- await new Promise((resolve) => setTimeout(resolve, ms));
34
- return JSON.stringify({
35
- success: true,
36
- waitedMs: ms,
37
- waitedSeconds: (ms / 1000).toFixed(1),
38
- message: `已等待 ${ms}ms(${(ms / 1000).toFixed(1)} 秒)`,
39
- });
40
- },
41
- });
@@ -1,2 +0,0 @@
1
- import { CallbackTool } from "@ai-zen/agents-core";
2
- export declare const writeFileTool: CallbackTool;
@@ -1,34 +0,0 @@
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
- });
@@ -1,9 +0,0 @@
1
- import type { Conversation } from "../types/index.js";
2
- import { EntityRepository } from "../shared/EntityRepository.js";
3
- /**
4
- * Conversation 仓储。
5
- * 每个 Conversation 一个 JSON 文件存储在 ${conversationsDir}/${id}.json。
6
- */
7
- export declare class ConversationRepository extends EntityRepository<Conversation> {
8
- constructor(conversationsDir: string);
9
- }
@@ -1,10 +0,0 @@
1
- import { EntityRepository } from "../shared/EntityRepository.js";
2
- /**
3
- * Conversation 仓储。
4
- * 每个 Conversation 一个 JSON 文件存储在 ${conversationsDir}/${id}.json。
5
- */
6
- export class ConversationRepository extends EntityRepository {
7
- constructor(conversationsDir) {
8
- super(conversationsDir);
9
- }
10
- }