@ai-zen/agents-sdk 0.3.4 → 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.
- package/CHANGELOG.md +35 -0
- package/README.md +19 -15
- package/dist/capabilities/discovery/builtin.d.ts +7 -6
- package/dist/capabilities/discovery/builtin.js +10 -9
- package/dist/capabilities/discovery/mcp.js +2 -1
- package/dist/capabilities/discovery/skills.js +2 -2
- package/dist/capabilities/discovery/usertools.js +3 -2
- package/dist/capabilities/implements/builtin/BatchEditTool.d.ts +15 -0
- package/dist/capabilities/implements/builtin/BatchEditTool.js +82 -0
- package/dist/capabilities/implements/builtin/CopyTool.d.ts +10 -0
- package/dist/capabilities/implements/builtin/CopyTool.js +43 -0
- package/dist/capabilities/implements/builtin/CwdTool.d.ts +6 -0
- package/dist/capabilities/implements/builtin/CwdTool.js +20 -0
- package/dist/capabilities/implements/builtin/DownloadFileTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/{downloadFile.js → DownloadFileTool.js} +29 -24
- package/dist/capabilities/implements/builtin/EditTool.d.ts +11 -0
- package/dist/capabilities/implements/builtin/EditTool.js +84 -0
- package/dist/capabilities/implements/builtin/ExecAsyncTool.d.ts +10 -0
- package/dist/capabilities/implements/builtin/{execAsync.js → ExecAsyncTool.js} +32 -34
- package/dist/capabilities/implements/builtin/ExecTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/ExecTool.js +46 -0
- package/dist/capabilities/implements/builtin/ExistTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/ExistTool.js +30 -0
- package/dist/capabilities/implements/builtin/FindTextTool.d.ts +12 -0
- package/dist/capabilities/implements/builtin/{findText.js → FindTextTool.js} +43 -37
- package/dist/capabilities/implements/builtin/GenerateImageTool.d.ts +21 -0
- package/dist/capabilities/implements/builtin/GenerateImageTool.js +121 -0
- package/dist/capabilities/implements/builtin/GlobTool.d.ts +10 -0
- package/dist/capabilities/implements/builtin/GlobTool.js +51 -0
- package/dist/capabilities/implements/builtin/LsTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/LsTool.js +33 -0
- package/dist/capabilities/implements/builtin/MkdirTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/MkdirTool.js +39 -0
- package/dist/capabilities/implements/builtin/ReadFileTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/ReadFileTool.js +37 -0
- package/dist/capabilities/implements/builtin/RenameTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/RenameTool.js +37 -0
- package/dist/capabilities/implements/builtin/RmTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/RmTool.js +39 -0
- package/dist/capabilities/implements/builtin/SleepTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/SleepTool.js +46 -0
- package/dist/capabilities/implements/builtin/WriteFileTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/WriteFileTool.js +40 -0
- package/dist/capabilities/implements/builtin/index.d.ts +29 -21
- package/dist/capabilities/implements/builtin/index.js +44 -37
- package/dist/capabilities/implements/builtin/test-helpers.d.ts +3 -0
- package/dist/capabilities/implements/builtin/test-helpers.js +4 -0
- package/dist/capabilities/implements/mcpTools.js +6 -4
- package/dist/capabilities/implements/skillTools.js +2 -2
- package/dist/index.d.ts +6 -10
- package/dist/index.js +7 -10
- package/dist/plugin/AutoMigratePlugin.js +2 -2
- package/dist/runtime/McpConnectionManager.js +4 -3
- package/dist/runtime/Provider.d.ts +9 -1
- package/dist/runtime/Provider.js +7 -1
- package/dist/runtime/SdkCallbackTool.d.ts +28 -0
- package/dist/runtime/SdkCallbackTool.js +33 -0
- package/dist/shared/logger.d.ts +6 -2
- package/dist/shared/logger.js +14 -7
- package/dist/types/index.d.ts +12 -20
- package/package.json +1 -1
- package/dist/capabilities/implements/builtin/batchEdit.d.ts +0 -2
- package/dist/capabilities/implements/builtin/batchEdit.js +0 -76
- package/dist/capabilities/implements/builtin/copy.d.ts +0 -2
- package/dist/capabilities/implements/builtin/copy.js +0 -38
- package/dist/capabilities/implements/builtin/cwd.d.ts +0 -2
- package/dist/capabilities/implements/builtin/cwd.js +0 -15
- package/dist/capabilities/implements/builtin/downloadFile.d.ts +0 -2
- package/dist/capabilities/implements/builtin/edit.d.ts +0 -2
- package/dist/capabilities/implements/builtin/edit.js +0 -79
- package/dist/capabilities/implements/builtin/exec.d.ts +0 -2
- package/dist/capabilities/implements/builtin/exec.js +0 -38
- package/dist/capabilities/implements/builtin/execAsync.d.ts +0 -2
- package/dist/capabilities/implements/builtin/exist.d.ts +0 -2
- package/dist/capabilities/implements/builtin/exist.js +0 -25
- package/dist/capabilities/implements/builtin/findText.d.ts +0 -2
- package/dist/capabilities/implements/builtin/generateImage.d.ts +0 -9
- package/dist/capabilities/implements/builtin/generateImage.js +0 -112
- package/dist/capabilities/implements/builtin/glob.d.ts +0 -2
- package/dist/capabilities/implements/builtin/glob.js +0 -45
- package/dist/capabilities/implements/builtin/ls.d.ts +0 -2
- package/dist/capabilities/implements/builtin/ls.js +0 -28
- package/dist/capabilities/implements/builtin/mkdir.d.ts +0 -2
- package/dist/capabilities/implements/builtin/mkdir.js +0 -34
- package/dist/capabilities/implements/builtin/readFile.d.ts +0 -2
- package/dist/capabilities/implements/builtin/readFile.js +0 -31
- package/dist/capabilities/implements/builtin/rename.d.ts +0 -2
- package/dist/capabilities/implements/builtin/rename.js +0 -32
- package/dist/capabilities/implements/builtin/rm.d.ts +0 -2
- package/dist/capabilities/implements/builtin/rm.js +0 -34
- package/dist/capabilities/implements/builtin/sleep.d.ts +0 -2
- package/dist/capabilities/implements/builtin/sleep.js +0 -41
- package/dist/capabilities/implements/builtin/writeFile.d.ts +0 -2
- package/dist/capabilities/implements/builtin/writeFile.js +0 -34
- package/dist/crud/ConversationRepository.d.ts +0 -9
- package/dist/crud/ConversationRepository.js +0 -10
- package/dist/crud/DraftRepository.d.ts +0 -15
- package/dist/crud/DraftRepository.js +0 -52
- package/dist/plugin/AutoDraftPlugin.d.ts +0 -26
- 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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 {
|
|
45
|
+
export { CwdTool, ReadFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, GenerateImageTool, };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CallbackTool } from "@ai-zen/agents-core";
|
|
2
2
|
import { createDisclosureParam } from "../disclosure.js";
|
|
3
|
+
import { getLogger } from "../../shared/logger.js";
|
|
3
4
|
const EMPTY_HINT = "(当前没有可用的 MCP 服务器,请联系用户添加)";
|
|
5
|
+
const log = getLogger();
|
|
4
6
|
/**
|
|
5
7
|
* 创建 load_mcp 工具。
|
|
6
8
|
* server 枚举由 filteredMcps (完整 McpServerConfig[])自动推导,
|
|
@@ -40,13 +42,13 @@ export function createLoadMcpTool(mcpManager, filteredMcps) {
|
|
|
40
42
|
const existingManifest = mcpManager.getManifest(serverName);
|
|
41
43
|
if (existingManifest && mcpManager.getState(serverName) === "connected") {
|
|
42
44
|
mcpManager.touch(serverName);
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
+
log.info(`[load_mcp] ${serverName}:\n${JSON.stringify(existingManifest, null, 2)}`);
|
|
46
|
+
return JSON.stringify({ tools: existingManifest.tools, resources: existingManifest.resources });
|
|
45
47
|
}
|
|
46
48
|
try {
|
|
47
49
|
const manifest = await mcpManager.connect(serverName, config);
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
+
log.info(`[load_mcp] ${serverName}:\n${JSON.stringify(manifest, null, 2)}`);
|
|
51
|
+
return JSON.stringify({ tools: manifest.tools, resources: manifest.resources });
|
|
50
52
|
}
|
|
51
53
|
catch (error) {
|
|
52
54
|
return `无法连接到 "${serverName}": ${error?.message ?? error}`;
|
|
@@ -2,9 +2,9 @@ import { CallbackTool, Agent, Message } from "@ai-zen/agents-core";
|
|
|
2
2
|
import { SdkAgent } from "../../runtime/SdkAgent.js";
|
|
3
3
|
import { createDisclosureParam } from "../disclosure.js";
|
|
4
4
|
import { readSkill } from "../discovery/skills.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getLogger } from "../../shared/logger.js";
|
|
6
6
|
import { promises as fs } from "node:fs";
|
|
7
|
-
const log =
|
|
7
|
+
const log = getLogger();
|
|
8
8
|
const EMPTY_HINT = "(当前没有可用的 Skill,请联系用户添加)";
|
|
9
9
|
/**
|
|
10
10
|
* 创建 load_skill 工具。
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { PermissionPolicy, AgentPermissions, Endpoint, Model, ImageModel, AgentDefinition,
|
|
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,20 +20,18 @@ 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 {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
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";
|
|
39
|
-
export {
|
|
35
|
+
export { getLogger, setLogger } from "./shared/logger.js";
|
|
40
36
|
export type { Logger, LogFunctions } from "./shared/logger.js";
|
|
41
37
|
export { SdkError } from "./shared/errors.js";
|
package/dist/index.js
CHANGED
|
@@ -9,30 +9,27 @@ 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 —
|
|
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 {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
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";
|
|
36
33
|
// 共享
|
|
37
|
-
export {
|
|
34
|
+
export { getLogger, setLogger } from "./shared/logger.js";
|
|
38
35
|
export { SdkError } from "./shared/errors.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentNS } from "@ai-zen/agents-core";
|
|
2
2
|
import { TaskMigrationService } from "../runtime/TaskMigrationService.js";
|
|
3
|
-
import {
|
|
4
|
-
const log =
|
|
3
|
+
import { getLogger } from "../shared/logger.js";
|
|
4
|
+
const log = getLogger();
|
|
5
5
|
/**
|
|
6
6
|
* 自动迁移插件。
|
|
7
7
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
3
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
+
import { getLogger } from "../shared/logger.js";
|
|
4
5
|
const DEFAULT_IDLE_TIMEOUT = {
|
|
5
6
|
stdio: 30 * 60 * 1000,
|
|
6
7
|
http: 5 * 60 * 1000,
|
|
@@ -139,7 +140,7 @@ export class McpConnectionManager {
|
|
|
139
140
|
}));
|
|
140
141
|
}
|
|
141
142
|
catch (err) {
|
|
142
|
-
|
|
143
|
+
getLogger().error(`[McpConnectionManager] 获取 "${name}" 工具列表失败: ${err?.message ?? err}`);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
if (serverCaps?.resources) {
|
|
@@ -153,7 +154,7 @@ export class McpConnectionManager {
|
|
|
153
154
|
}));
|
|
154
155
|
}
|
|
155
156
|
catch (err) {
|
|
156
|
-
|
|
157
|
+
getLogger().error(`[McpConnectionManager] 获取 "${name}" 资源列表失败: ${err?.message ?? err}`);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
if (serverCaps?.prompts) {
|
|
@@ -165,7 +166,7 @@ export class McpConnectionManager {
|
|
|
165
166
|
}));
|
|
166
167
|
}
|
|
167
168
|
catch (err) {
|
|
168
|
-
|
|
169
|
+
getLogger().error(`[McpConnectionManager] 获取 "${name}" 提示列表失败: ${err?.message ?? err}`);
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
const entry = this.servers.get(name) ?? { state: "connecting" };
|
|
@@ -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
|
* 初始化:执行全局能力发现。
|
package/dist/runtime/Provider.js
CHANGED
|
@@ -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.
|
|
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 });
|