@ai-zen/agents-sdk 0.4.0 → 0.5.1

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 +27 -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 +2 -2
  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
@@ -0,0 +1,37 @@
1
+ import * as fsp from "fs/promises";
2
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
3
+ export class ReadFileTool extends SdkCallbackTool {
4
+ constructor(env) {
5
+ super({
6
+ function: {
7
+ name: "readFile",
8
+ description: "读取文件",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ path: {
13
+ type: "string",
14
+ description: "文件路径",
15
+ },
16
+ },
17
+ required: ["path"],
18
+ additionalProperties: false,
19
+ },
20
+ },
21
+ env,
22
+ });
23
+ }
24
+ async call(input) {
25
+ try {
26
+ const filePath = this.resolve(input.path);
27
+ const stats = await fsp.stat(filePath);
28
+ if (stats.size > 300 * 1024) {
29
+ throw new Error(`文件过大,无法读取,当前文件大小 ${stats.size} 字节`);
30
+ }
31
+ return await fsp.readFile(filePath, "utf-8");
32
+ }
33
+ catch (error) {
34
+ return error?.message;
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,9 @@
1
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import type { ToolEnv } from "../../../types/index.js";
3
+ export declare class RenameTool extends SdkCallbackTool {
4
+ constructor(env: ToolEnv);
5
+ call(input: {
6
+ oldPath: string;
7
+ newPath: string;
8
+ }): Promise<string>;
9
+ }
@@ -0,0 +1,37 @@
1
+ import * as fsp from "fs/promises";
2
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
3
+ export class RenameTool extends SdkCallbackTool {
4
+ constructor(env) {
5
+ super({
6
+ function: {
7
+ name: "rename",
8
+ description: "重命名或移动文件/目录(相当于 mv 命令)",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ oldPath: {
13
+ type: "string",
14
+ description: "原路径",
15
+ },
16
+ newPath: {
17
+ type: "string",
18
+ description: "新路径",
19
+ },
20
+ },
21
+ required: ["oldPath", "newPath"],
22
+ additionalProperties: false,
23
+ },
24
+ },
25
+ env,
26
+ });
27
+ }
28
+ async call(input) {
29
+ try {
30
+ await fsp.rename(this.resolve(input.oldPath), this.resolve(input.newPath));
31
+ return "success";
32
+ }
33
+ catch (error) {
34
+ return error?.message;
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,9 @@
1
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import type { ToolEnv } from "../../../types/index.js";
3
+ export declare class RmTool extends SdkCallbackTool {
4
+ constructor(env: ToolEnv);
5
+ call(input: {
6
+ path: string;
7
+ recursive?: boolean;
8
+ }): Promise<string>;
9
+ }
@@ -0,0 +1,39 @@
1
+ import * as fsp from "fs/promises";
2
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
3
+ export class RmTool extends SdkCallbackTool {
4
+ constructor(env) {
5
+ super({
6
+ function: {
7
+ name: "rm",
8
+ description: "删除文件或目录",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ path: {
13
+ type: "string",
14
+ description: "文件或目录路径",
15
+ },
16
+ recursive: {
17
+ type: "boolean",
18
+ description: "是否递归删除子目录",
19
+ },
20
+ },
21
+ required: ["path"],
22
+ additionalProperties: false,
23
+ },
24
+ },
25
+ env,
26
+ });
27
+ }
28
+ async call(input) {
29
+ try {
30
+ await fsp.rm(this.resolve(input.path), {
31
+ recursive: input.recursive ?? false,
32
+ });
33
+ return "success";
34
+ }
35
+ catch (error) {
36
+ return error?.message;
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,8 @@
1
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import type { ToolEnv } from "../../../types/index.js";
3
+ export declare class SleepTool extends SdkCallbackTool {
4
+ constructor(env: ToolEnv);
5
+ call(input: {
6
+ ms: number;
7
+ }): Promise<string>;
8
+ }
@@ -0,0 +1,46 @@
1
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ export class SleepTool extends SdkCallbackTool {
3
+ constructor(env) {
4
+ super({
5
+ function: {
6
+ name: "sleep",
7
+ description: "等待指定的时间(毫秒)。用于需要延迟执行的场景,例如等待其他操作完成、操作间隔控制等。注意:过长的等待时间会影响响应速度,建议不超过 30000 毫秒(30 秒)。",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ ms: {
12
+ type: "number",
13
+ description: "等待的毫秒数(1 秒 = 1000 毫秒)。建议不超过 30000(30 秒)。",
14
+ },
15
+ },
16
+ required: ["ms"],
17
+ additionalProperties: false,
18
+ },
19
+ },
20
+ env,
21
+ });
22
+ }
23
+ async call(input) {
24
+ const ms = input.ms;
25
+ if (typeof ms !== "number" || !Number.isFinite(ms) || ms < 0) {
26
+ return JSON.stringify({
27
+ success: false,
28
+ error: "ms 必须是正整数",
29
+ });
30
+ }
31
+ if (ms > 300_000) {
32
+ // 超过 5 分钟给出警告
33
+ return JSON.stringify({
34
+ success: false,
35
+ error: `等待时间 ${ms}ms 过长,建议不超过 300000ms(5 分钟)。如需长时间等待请分段执行。`,
36
+ });
37
+ }
38
+ await new Promise((resolve) => setTimeout(resolve, ms));
39
+ return JSON.stringify({
40
+ success: true,
41
+ waitedMs: ms,
42
+ waitedSeconds: (ms / 1000).toFixed(1),
43
+ message: `已等待 ${ms}ms(${(ms / 1000).toFixed(1)} 秒)`,
44
+ });
45
+ }
46
+ }
@@ -0,0 +1,9 @@
1
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import type { ToolEnv } from "../../../types/index.js";
3
+ export declare class WriteFileTool extends SdkCallbackTool {
4
+ constructor(env: ToolEnv);
5
+ call(input: {
6
+ path: string;
7
+ content: string;
8
+ }): Promise<string>;
9
+ }
@@ -0,0 +1,40 @@
1
+ import * as fsp from "fs/promises";
2
+ import * as path from "path";
3
+ import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
4
+ export class WriteFileTool extends SdkCallbackTool {
5
+ constructor(env) {
6
+ super({
7
+ function: {
8
+ name: "writeFile",
9
+ description: "写入文件",
10
+ parameters: {
11
+ type: "object",
12
+ properties: {
13
+ path: {
14
+ type: "string",
15
+ description: "文件路径",
16
+ },
17
+ content: {
18
+ type: "string",
19
+ description: "文件内容",
20
+ },
21
+ },
22
+ required: ["path", "content"],
23
+ additionalProperties: false,
24
+ },
25
+ },
26
+ env,
27
+ });
28
+ }
29
+ async call(input) {
30
+ try {
31
+ const filePath = this.resolve(input.path);
32
+ await fsp.mkdir(path.dirname(filePath), { recursive: true });
33
+ await fsp.writeFile(filePath, input.content);
34
+ return "success";
35
+ }
36
+ catch (error) {
37
+ return error?.message;
38
+ }
39
+ }
40
+ }
@@ -1,21 +1,29 @@
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
- import { execAsyncTool } from "./execAsync.js";
18
- import { sleepTool } from "./sleep.js";
19
- /** 17 个内置工具实例,注册与实现一体。 */
20
- export declare const BUILTIN_TOOLS: Tool[];
21
- export { cwdTool, readFileTool, writeFileTool, execTool, mkdirTool, rmTool, globTool, lsTool, existTool, findTextTool, downloadFileTool, renameTool, copyTool, batchEditTool, editTool, execAsyncTool, sleepTool };
1
+ import type { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import type { ToolEnv } from "../../../types/index.js";
3
+ import { CwdTool } from "./CwdTool.js";
4
+ import { ReadFileTool } from "./ReadFileTool.js";
5
+ import { WriteFileTool } from "./WriteFileTool.js";
6
+ import { ExecTool } from "./ExecTool.js";
7
+ import { MkdirTool } from "./MkdirTool.js";
8
+ import { RmTool } from "./RmTool.js";
9
+ import { GlobTool } from "./GlobTool.js";
10
+ import { LsTool } from "./LsTool.js";
11
+ import { ExistTool } from "./ExistTool.js";
12
+ import { FindTextTool } from "./FindTextTool.js";
13
+ import { DownloadFileTool } from "./DownloadFileTool.js";
14
+ import { RenameTool } from "./RenameTool.js";
15
+ import { CopyTool } from "./CopyTool.js";
16
+ import { BatchEditTool } from "./BatchEditTool.js";
17
+ import { EditTool } from "./EditTool.js";
18
+ import { ExecAsyncTool } from "./ExecAsyncTool.js";
19
+ import { SleepTool } from "./SleepTool.js";
20
+ import { GenerateImageTool } from "./GenerateImageTool.js";
21
+ /**
22
+ * 17 个无条件注册的内置工具类。
23
+ * 工具类由 Provider 用 ToolEnv 实例化(每个 Provider 一套实例,注入其 cwd)。
24
+ *
25
+ * 注意:GenerateImageTool 依赖图片模型配置(defaultImageModel),
26
+ * 由 discoverBuiltinTools 按条件实例化,不在此静态注册表中。
27
+ */
28
+ export declare const BUILTIN_TOOL_CLASSES: Array<new (env: ToolEnv) => SdkCallbackTool>;
29
+ export { CwdTool, ReadFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, GenerateImageTool, };
@@ -1,38 +1,45 @@
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
- import { execAsyncTool } from "./execAsync.js";
17
- import { sleepTool } from "./sleep.js";
18
- /** 17 个内置工具实例,注册与实现一体。 */
19
- export const BUILTIN_TOOLS = [
20
- cwdTool,
21
- readFileTool,
22
- writeFileTool,
23
- execTool,
24
- mkdirTool,
25
- rmTool,
26
- globTool,
27
- lsTool,
28
- existTool,
29
- findTextTool,
30
- downloadFileTool,
31
- renameTool,
32
- copyTool,
33
- batchEditTool,
34
- editTool,
35
- execAsyncTool,
36
- sleepTool,
1
+ import { CwdTool } from "./CwdTool.js";
2
+ import { ReadFileTool } from "./ReadFileTool.js";
3
+ import { WriteFileTool } from "./WriteFileTool.js";
4
+ import { ExecTool } from "./ExecTool.js";
5
+ import { MkdirTool } from "./MkdirTool.js";
6
+ import { RmTool } from "./RmTool.js";
7
+ import { GlobTool } from "./GlobTool.js";
8
+ import { LsTool } from "./LsTool.js";
9
+ import { ExistTool } from "./ExistTool.js";
10
+ import { FindTextTool } from "./FindTextTool.js";
11
+ import { DownloadFileTool } from "./DownloadFileTool.js";
12
+ import { RenameTool } from "./RenameTool.js";
13
+ import { CopyTool } from "./CopyTool.js";
14
+ import { BatchEditTool } from "./BatchEditTool.js";
15
+ import { EditTool } from "./EditTool.js";
16
+ import { ExecAsyncTool } from "./ExecAsyncTool.js";
17
+ import { SleepTool } from "./SleepTool.js";
18
+ import { GenerateImageTool } from "./GenerateImageTool.js";
19
+ /**
20
+ * 17 个无条件注册的内置工具类。
21
+ * 工具类由 Provider 用 ToolEnv 实例化(每个 Provider 一套实例,注入其 cwd)。
22
+ *
23
+ * 注意:GenerateImageTool 依赖图片模型配置(defaultImageModel),
24
+ * 由 discoverBuiltinTools 按条件实例化,不在此静态注册表中。
25
+ */
26
+ export const BUILTIN_TOOL_CLASSES = [
27
+ CwdTool,
28
+ ReadFileTool,
29
+ WriteFileTool,
30
+ ExecTool,
31
+ MkdirTool,
32
+ RmTool,
33
+ GlobTool,
34
+ LsTool,
35
+ ExistTool,
36
+ FindTextTool,
37
+ DownloadFileTool,
38
+ RenameTool,
39
+ CopyTool,
40
+ BatchEditTool,
41
+ EditTool,
42
+ ExecAsyncTool,
43
+ SleepTool,
37
44
  ];
38
- export { cwdTool, readFileTool, writeFileTool, execTool, mkdirTool, rmTool, globTool, lsTool, existTool, findTextTool, downloadFileTool, renameTool, copyTool, batchEditTool, editTool, execAsyncTool, sleepTool };
45
+ export { CwdTool, ReadFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, GenerateImageTool, };
@@ -0,0 +1,3 @@
1
+ import type { AppConfig, ToolEnv } from "../../../types/index.js";
2
+ /** 构造测试用 ToolEnv */
3
+ export declare function makeEnv(cwd?: string, config?: AppConfig): ToolEnv;
@@ -0,0 +1,4 @@
1
+ /** 构造测试用 ToolEnv */
2
+ export function makeEnv(cwd = process.cwd(), config = {}) {
3
+ return { cwd, config };
4
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { PermissionPolicy, AgentPermissions, Endpoint, Model, ImageModel, AgentDefinition, Conversation, Draft, AppConfig, McpIcon, McpAnnotations, McpToolDef, McpResourceDef, McpPromptDef, McpServerManifest, McpServerConfig, McpConnectionState, } from "./types/index.js";
1
+ export type { PermissionPolicy, AgentPermissions, Endpoint, Model, ImageModel, AgentDefinition, AppConfig, ToolEnv, McpIcon, McpAnnotations, McpToolDef, McpResourceDef, McpPromptDef, McpServerManifest, McpServerConfig, McpConnectionState, } from "./types/index.js";
2
2
  export { PermissionEvaluator } from "./capabilities/PermissionEvaluator.js";
3
3
  export type { CandidateSets } from "./capabilities/PermissionEvaluator.js";
4
4
  export { createDisclosureParam } from "./capabilities/disclosure.js";
@@ -12,8 +12,6 @@ export { discoverUserTools } from "./capabilities/discovery/usertools.js";
12
12
  export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
13
13
  export { EntityRepository } from "./shared/EntityRepository.js";
14
14
  export { AgentRepository } from "./crud/AgentRepository.js";
15
- export { ConversationRepository } from "./crud/ConversationRepository.js";
16
- export { DraftRepository } from "./crud/DraftRepository.js";
17
15
  export { Provider } from "./runtime/Provider.js";
18
16
  export type { FilterOutput, ExcludeOptions } from "./runtime/Provider.js";
19
17
  export { createModel } from "./runtime/createModel.js";
@@ -22,17 +20,15 @@ export type { AgentPlugin, SendContext } from "./runtime/SdkAgent.js";
22
20
  export { createAgent } from "./runtime/createAgent.js";
23
21
  export { McpConnectionManager } from "./runtime/McpConnectionManager.js";
24
22
  export type { McpConnectOptions } from "./runtime/McpConnectionManager.js";
23
+ export { SdkCallbackTool } from "./runtime/SdkCallbackTool.js";
25
24
  export { TaskMigrationService } from "./runtime/TaskMigrationService.js";
26
25
  export type { BuildMigrationAgentOptions } from "./runtime/TaskMigrationService.js";
27
26
  export { AutoMigratePlugin } from "./plugin/AutoMigratePlugin.js";
28
27
  export type { AutoMigrateOptions } from "./plugin/AutoMigratePlugin.js";
29
- export { AutoDraftPlugin } from "./plugin/AutoDraftPlugin.js";
30
- export type { AutoDraftOptions } from "./plugin/AutoDraftPlugin.js";
31
28
  export { AutoRefreshToolsPlugin } from "./plugin/AutoRefreshToolsPlugin.js";
32
- export { BUILTIN_TOOLS } from "./capabilities/implements/builtin/index.js";
33
- export { createGenerateImageTool } from "./capabilities/implements/builtin/generateImage.js";
34
- export { execAsyncTool } from "./capabilities/implements/builtin/execAsync.js";
35
- export { sleepTool } from "./capabilities/implements/builtin/sleep.js";
29
+ export { BUILTIN_TOOL_CLASSES } from "./capabilities/implements/builtin/index.js";
30
+ export { CwdTool, ReadFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, } from "./capabilities/implements/builtin/index.js";
31
+ export { GenerateImageTool } from "./capabilities/implements/builtin/GenerateImageTool.js";
36
32
  export { createLoadSkillTool, createCallSkillSubAgentTool } from "./capabilities/implements/skillTools.js";
37
33
  export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./capabilities/implements/mcpTools.js";
38
34
  export { createSubAgentTool } from "./capabilities/implements/subAgentTools.js";
package/dist/index.js CHANGED
@@ -9,27 +9,24 @@ export { discoverMcpServers } from "./capabilities/discovery/mcp.js";
9
9
  export { discoverUserTools } from "./capabilities/discovery/usertools.js";
10
10
  // 配置 — ConfigManager
11
11
  export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
12
- // CRUD — EntityRepository + 实体仓储
12
+ // CRUD — 实体仓储(仅 Agent 定义等能力实体)
13
13
  export { EntityRepository } from "./shared/EntityRepository.js";
14
14
  export { AgentRepository } from "./crud/AgentRepository.js";
15
- export { ConversationRepository } from "./crud/ConversationRepository.js";
16
- export { DraftRepository } from "./crud/DraftRepository.js";
17
15
  // 运行时
18
16
  export { Provider } from "./runtime/Provider.js";
19
17
  export { createModel } from "./runtime/createModel.js";
20
18
  export { SdkAgent } from "./runtime/SdkAgent.js";
21
19
  export { createAgent } from "./runtime/createAgent.js";
22
20
  export { McpConnectionManager } from "./runtime/McpConnectionManager.js";
21
+ export { SdkCallbackTool } from "./runtime/SdkCallbackTool.js";
23
22
  export { TaskMigrationService } from "./runtime/TaskMigrationService.js";
24
23
  // 插件
25
24
  export { AutoMigratePlugin } from "./plugin/AutoMigratePlugin.js";
26
- export { AutoDraftPlugin } from "./plugin/AutoDraftPlugin.js";
27
25
  export { AutoRefreshToolsPlugin } from "./plugin/AutoRefreshToolsPlugin.js";
28
- // 工具
29
- export { BUILTIN_TOOLS } from "./capabilities/implements/builtin/index.js";
30
- export { createGenerateImageTool } from "./capabilities/implements/builtin/generateImage.js";
31
- export { execAsyncTool } from "./capabilities/implements/builtin/execAsync.js";
32
- export { sleepTool } from "./capabilities/implements/builtin/sleep.js";
26
+ // 工具 — 内置工具类 + 动态工具工厂
27
+ export { BUILTIN_TOOL_CLASSES } from "./capabilities/implements/builtin/index.js";
28
+ export { CwdTool, ReadFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, } from "./capabilities/implements/builtin/index.js";
29
+ export { GenerateImageTool } from "./capabilities/implements/builtin/GenerateImageTool.js";
33
30
  export { createLoadSkillTool, createCallSkillSubAgentTool } from "./capabilities/implements/skillTools.js";
34
31
  export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./capabilities/implements/mcpTools.js";
35
32
  export { createSubAgentTool } from "./capabilities/implements/subAgentTools.js";
@@ -1,5 +1,5 @@
1
1
  import type { Tool } from "@ai-zen/agents-core";
2
- import type { AppConfig, AgentDefinition, AgentPermissions, McpServerConfig } from "../types/index.js";
2
+ import type { AppConfig, AgentDefinition, AgentPermissions, McpServerConfig, ToolEnv } from "../types/index.js";
3
3
  import type { SkillInfo } from "../capabilities/discovery/skills.js";
4
4
  import { McpConnectionManager } from "./McpConnectionManager.js";
5
5
  /**
@@ -48,6 +48,10 @@ export interface ExcludeOptions {
48
48
  export declare class Provider {
49
49
  /** 应用配置(端点、模型等) */
50
50
  readonly config: AppConfig;
51
+ /** 当前工作目录 — 相对路径解析基准,也是 ToolEnv.cwd 的来源 */
52
+ readonly cwd: string;
53
+ /** 工具环境 — 实例化内置工具时注入 */
54
+ readonly env: ToolEnv;
51
55
  readonly agentsDir: string;
52
56
  readonly subAgentsPaths: string[];
53
57
  readonly skillsPaths: string[];
@@ -68,6 +72,8 @@ export declare class Provider {
68
72
  skillsPaths?: string[];
69
73
  toolsPaths?: string[];
70
74
  mcpPaths?: string[];
75
+ /** 当前工作目录,默认 process.cwd() */
76
+ cwd?: string;
71
77
  });
72
78
  /**
73
79
  * 异步创建 Provider,一步完成构造 + 全局能力发现。
@@ -79,6 +85,8 @@ export declare class Provider {
79
85
  skillsPaths?: string[];
80
86
  toolsPaths?: string[];
81
87
  mcpPaths?: string[];
88
+ /** 当前工作目录,默认 process.cwd() */
89
+ cwd?: string;
82
90
  }): Promise<Provider>;
83
91
  /**
84
92
  * 初始化:执行全局能力发现。
@@ -34,6 +34,10 @@ import { discoverUserTools } from "../capabilities/discovery/usertools.js";
34
34
  export class Provider {
35
35
  /** 应用配置(端点、模型等) */
36
36
  config;
37
+ /** 当前工作目录 — 相对路径解析基准,也是 ToolEnv.cwd 的来源 */
38
+ cwd;
39
+ /** 工具环境 — 实例化内置工具时注入 */
40
+ env;
37
41
  // ---- 路径 ----
38
42
  agentsDir;
39
43
  subAgentsPaths;
@@ -52,6 +56,8 @@ export class Provider {
52
56
  mcpManager;
53
57
  constructor(options) {
54
58
  this.config = options.config;
59
+ this.cwd = options.cwd ?? process.cwd();
60
+ this.env = { cwd: this.cwd, config: this.config };
55
61
  this.agentsDir = options.agentsDir;
56
62
  this.subAgentsPaths = options.subAgentsPaths ?? [];
57
63
  this.skillsPaths = options.skillsPaths ?? [];
@@ -181,7 +187,7 @@ export class Provider {
181
187
  */
182
188
  async refresh(options) {
183
189
  const silent = options?.silent ?? false;
184
- this.builtinTools = discoverBuiltinTools(this.config);
190
+ this.builtinTools = discoverBuiltinTools(this.env);
185
191
  this.userTools = await discoverUserTools(this.toolsPaths, { silent });
186
192
  this.subagents = await discoverSubAgents(this.subAgentsPaths);
187
193
  this.skills = await discoverSkills(this.skillsPaths, { silent });
@@ -0,0 +1,28 @@
1
+ import { Tool, FunctionCallContext } from "@ai-zen/agents-core";
2
+ import type { AgentNS } from "@ai-zen/agents-core";
3
+ import type { ToolEnv } from "../types/index.js";
4
+ /**
5
+ * SdkCallbackTool — SDK 内置工具基类。
6
+ *
7
+ * 环境(ToolEnv)在构造时注入,工具逻辑在子类的 call() 中实现,
8
+ * 不再依赖全局 process.cwd(),也不需要在运行时反查 Agent 上下文。
9
+ *
10
+ * 设计原则:
11
+ * - 一个工具一个类,文件名 = 类名(PascalCase)
12
+ * - 依赖环境(cwd、config)通过构造参数显式注入
13
+ * - 相对路径统一用 resolve() 解析到 env.cwd
14
+ */
15
+ export declare abstract class SdkCallbackTool extends Tool {
16
+ /** 注入的工具环境 */
17
+ readonly env: ToolEnv;
18
+ constructor(options: {
19
+ function: AgentNS.FunctionDefine;
20
+ env: ToolEnv;
21
+ });
22
+ /** 工具核心逻辑(由子类实现,参数为 parsed_args) */
23
+ abstract call(input: unknown): unknown | Promise<unknown>;
24
+ /** 桥接 core 的 Tool.exec:解析参数 → call → 序列化 */
25
+ exec(ctx: FunctionCallContext): Promise<string>;
26
+ /** 将相对路径解析到 env.cwd,绝对路径原样返回 */
27
+ resolve(p: string): string;
28
+ }
@@ -0,0 +1,33 @@
1
+ import path from "node:path";
2
+ import { Tool } from "@ai-zen/agents-core";
3
+ /**
4
+ * SdkCallbackTool — SDK 内置工具基类。
5
+ *
6
+ * 环境(ToolEnv)在构造时注入,工具逻辑在子类的 call() 中实现,
7
+ * 不再依赖全局 process.cwd(),也不需要在运行时反查 Agent 上下文。
8
+ *
9
+ * 设计原则:
10
+ * - 一个工具一个类,文件名 = 类名(PascalCase)
11
+ * - 依赖环境(cwd、config)通过构造参数显式注入
12
+ * - 相对路径统一用 resolve() 解析到 env.cwd
13
+ */
14
+ export class SdkCallbackTool extends Tool {
15
+ /** 注入的工具环境 */
16
+ env;
17
+ constructor(options) {
18
+ super({ function: options.function });
19
+ this.env = options.env;
20
+ }
21
+ /** 桥接 core 的 Tool.exec:解析参数 → call → 序列化 */
22
+ async exec(ctx) {
23
+ const result = await this.call(ctx.parsed_args);
24
+ if (typeof result === "string")
25
+ return result;
26
+ // JSON.stringify(undefined) 返回 undefined(非字符串),会破坏 Promise<string> 契约
27
+ return JSON.stringify(result) ?? "";
28
+ }
29
+ /** 将相对路径解析到 env.cwd,绝对路径原样返回 */
30
+ resolve(p) {
31
+ return path.isAbsolute(p) ? p : path.join(this.env.cwd, p);
32
+ }
33
+ }
@@ -45,26 +45,6 @@ export interface AgentDefinition {
45
45
  updatedAt: string;
46
46
  version?: number;
47
47
  }
48
- /** 对话记录 */
49
- export interface Conversation {
50
- id: string;
51
- agentId: string;
52
- modelId: string;
53
- messages: AgentNS.Message[];
54
- lastPromptTokens?: number;
55
- cwd?: string;
56
- createdAt: string;
57
- updatedAt: string;
58
- }
59
- /** 当前会话草稿 */
60
- export interface Draft {
61
- conversationId?: string;
62
- agentId: string;
63
- modelId: string;
64
- messages: AgentNS.Message[];
65
- cwd?: string;
66
- updatedAt: string;
67
- }
68
48
  /** 图片生成模型配置 */
69
49
  export interface ImageModel {
70
50
  id: string;
@@ -90,6 +70,18 @@ export interface AppConfig {
90
70
  /** 默认迁移模型 ID */
91
71
  defaultMigrationModel?: string;
92
72
  }
73
+ /**
74
+ * 工具环境 — Provider 在实例化内置工具时注入的环境信息。
75
+ *
76
+ * cwd 是相对路径解析的基准(每个 Provider 对应一个工作目录);
77
+ * config 供需要模型/端点配置的工具(如 generateImage)使用。
78
+ */
79
+ export interface ToolEnv {
80
+ /** 当前工作目录 */
81
+ cwd: string;
82
+ /** 应用配置 */
83
+ config: AppConfig;
84
+ }
93
85
  /** MCP 连接状态 */
94
86
  export type McpConnectionState = "disconnected" | "connecting" | "connected" | "error";
95
87
  /** MCP 服务器配置 */