@ai-zen/agents-sdk 0.12.0 → 1.0.0-alpha.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 (111) hide show
  1. package/CHANGELOG.md +77 -36
  2. package/README.md +29 -21
  3. package/README.zh.md +29 -21
  4. package/dist/{plugin → agent-plugins}/AutoRefreshToolsPlugin.js +2 -2
  5. package/dist/{plugin → agent-plugins}/UnknownToolHintPlugin.d.ts +7 -5
  6. package/dist/{plugin → agent-plugins}/UnknownToolHintPlugin.js +9 -5
  7. package/dist/index.d.ts +37 -29
  8. package/dist/index.js +28 -21
  9. package/dist/runtime/SdkAgent.d.ts +5 -5
  10. package/dist/runtime/SdkAgent.js +4 -4
  11. package/dist/runtime/TaskMigrationService.d.ts +1 -1
  12. package/dist/runtime/TaskMigrationService.js +2 -2
  13. package/dist/runtime/createAgent.d.ts +4 -4
  14. package/dist/runtime/createAgent.js +8 -8
  15. package/dist/runtime/createModel.d.ts +3 -3
  16. package/dist/runtime/createModel.js +3 -3
  17. package/dist/scope/Scope.d.ts +111 -0
  18. package/dist/scope/Scope.js +165 -0
  19. package/dist/scope/ScopePlugin.d.ts +51 -0
  20. package/dist/scope/ScopePlugin.js +1 -0
  21. package/dist/scope/plugins/allInOne.d.ts +18 -0
  22. package/dist/scope/plugins/allInOne.js +23 -0
  23. package/dist/{capabilities/implements → scope/plugins}/builtin/BatchEditTool.d.ts +1 -1
  24. package/dist/{capabilities/implements → scope/plugins}/builtin/BatchEditTool.js +1 -1
  25. package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.d.ts +20 -0
  26. package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.js +30 -0
  27. package/dist/{capabilities/implements → scope/plugins}/builtin/CopyTool.d.ts +1 -1
  28. package/dist/{capabilities/implements → scope/plugins}/builtin/CopyTool.js +1 -1
  29. package/dist/{capabilities/implements → scope/plugins}/builtin/CwdTool.d.ts +1 -1
  30. package/dist/{capabilities/implements → scope/plugins}/builtin/CwdTool.js +1 -1
  31. package/dist/{capabilities/implements → scope/plugins}/builtin/DownloadFileTool.d.ts +1 -1
  32. package/dist/{capabilities/implements → scope/plugins}/builtin/DownloadFileTool.js +1 -1
  33. package/dist/{capabilities/implements → scope/plugins}/builtin/EditTool.d.ts +1 -1
  34. package/dist/{capabilities/implements → scope/plugins}/builtin/EditTool.js +1 -1
  35. package/dist/{capabilities/implements → scope/plugins}/builtin/ExecAsyncTool.d.ts +1 -1
  36. package/dist/{capabilities/implements → scope/plugins}/builtin/ExecAsyncTool.js +1 -1
  37. package/dist/{capabilities/implements → scope/plugins}/builtin/ExecTool.d.ts +1 -1
  38. package/dist/{capabilities/implements → scope/plugins}/builtin/ExecTool.js +1 -1
  39. package/dist/{capabilities/implements → scope/plugins}/builtin/ExistTool.d.ts +1 -1
  40. package/dist/{capabilities/implements → scope/plugins}/builtin/ExistTool.js +1 -1
  41. package/dist/{capabilities/implements → scope/plugins}/builtin/FindTextTool.d.ts +1 -1
  42. package/dist/{capabilities/implements → scope/plugins}/builtin/FindTextTool.js +1 -1
  43. package/dist/{capabilities/implements → scope/plugins}/builtin/GenerateImageTool.d.ts +1 -1
  44. package/dist/{capabilities/implements → scope/plugins}/builtin/GenerateImageTool.js +1 -1
  45. package/dist/{capabilities/implements → scope/plugins}/builtin/GlobTool.d.ts +1 -1
  46. package/dist/{capabilities/implements → scope/plugins}/builtin/GlobTool.js +1 -1
  47. package/dist/{capabilities/implements → scope/plugins}/builtin/InspectFileTool.d.ts +1 -1
  48. package/dist/{capabilities/implements → scope/plugins}/builtin/InspectFileTool.js +1 -1
  49. package/dist/{capabilities/implements → scope/plugins}/builtin/LsTool.d.ts +1 -1
  50. package/dist/{capabilities/implements → scope/plugins}/builtin/LsTool.js +1 -1
  51. package/dist/{capabilities/implements → scope/plugins}/builtin/MkdirTool.d.ts +1 -1
  52. package/dist/{capabilities/implements → scope/plugins}/builtin/MkdirTool.js +1 -1
  53. package/dist/{capabilities/implements → scope/plugins}/builtin/ReadFileTool.d.ts +1 -1
  54. package/dist/{capabilities/implements → scope/plugins}/builtin/ReadFileTool.js +1 -1
  55. package/dist/{capabilities/implements → scope/plugins}/builtin/RenameTool.d.ts +1 -1
  56. package/dist/{capabilities/implements → scope/plugins}/builtin/RenameTool.js +1 -1
  57. package/dist/{capabilities/implements → scope/plugins}/builtin/RmTool.d.ts +1 -1
  58. package/dist/{capabilities/implements → scope/plugins}/builtin/RmTool.js +1 -1
  59. package/dist/{runtime → scope/plugins/builtin}/SdkCallbackTool.d.ts +1 -1
  60. package/dist/{capabilities/implements → scope/plugins}/builtin/SleepTool.d.ts +1 -1
  61. package/dist/{capabilities/implements → scope/plugins}/builtin/SleepTool.js +1 -1
  62. package/dist/{capabilities/implements → scope/plugins}/builtin/ViewImageTool.d.ts +1 -1
  63. package/dist/{capabilities/implements → scope/plugins}/builtin/ViewImageTool.js +1 -1
  64. package/dist/{capabilities/implements → scope/plugins}/builtin/WriteFileTool.d.ts +1 -1
  65. package/dist/{capabilities/implements → scope/plugins}/builtin/WriteFileTool.js +1 -1
  66. package/dist/{capabilities/discovery/builtin.d.ts → scope/plugins/builtin/discover.d.ts} +1 -1
  67. package/dist/{capabilities/discovery/builtin.js → scope/plugins/builtin/discover.js} +1 -1
  68. package/dist/{capabilities/implements → scope/plugins}/builtin/index.d.ts +2 -2
  69. package/dist/{capabilities/implements → scope/plugins}/builtin/index.js +1 -1
  70. package/dist/{runtime → scope/plugins/mcp}/McpConnectionManager.d.ts +1 -1
  71. package/dist/{runtime → scope/plugins/mcp}/McpConnectionManager.js +1 -1
  72. package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +29 -0
  73. package/dist/scope/plugins/mcp/McpScopePlugin.js +60 -0
  74. package/dist/{capabilities/discovery/mcp.d.ts → scope/plugins/mcp/discover.d.ts} +1 -1
  75. package/dist/{capabilities/discovery/mcp.js → scope/plugins/mcp/discover.js} +1 -1
  76. package/dist/{capabilities/implements → scope/plugins/mcp}/mcpTools.d.ts +2 -2
  77. package/dist/{capabilities/implements → scope/plugins/mcp}/mcpTools.js +2 -2
  78. package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +28 -0
  79. package/dist/scope/plugins/skills/SkillsScopePlugin.js +48 -0
  80. package/dist/{capabilities/discovery/skills.js → scope/plugins/skills/discover.js} +1 -1
  81. package/dist/{capabilities/implements → scope/plugins/skills}/skillTools.d.ts +1 -1
  82. package/dist/{capabilities/implements → scope/plugins/skills}/skillTools.js +3 -3
  83. package/dist/scope/plugins/subagents/SubAgentsScopePlugin.d.ts +20 -0
  84. package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +34 -0
  85. package/dist/{capabilities/discovery/subagents.d.ts → scope/plugins/subagents/discover.d.ts} +1 -1
  86. package/dist/{capabilities/implements → scope/plugins/subagents}/subAgentTools.d.ts +3 -3
  87. package/dist/{capabilities/implements → scope/plugins/subagents}/subAgentTools.js +5 -5
  88. package/dist/scope/plugins/usertools/UserToolsScopePlugin.d.ts +24 -0
  89. package/dist/scope/plugins/usertools/UserToolsScopePlugin.js +28 -0
  90. package/dist/{capabilities/discovery/usertools.js → scope/plugins/usertools/discover.js} +1 -1
  91. package/dist/types/index.d.ts +2 -2
  92. package/package.json +3 -3
  93. package/dist/runtime/Provider.d.ts +0 -119
  94. package/dist/runtime/Provider.js +0 -218
  95. /package/dist/{plugin → agent-plugins}/AutoMigratePlugin.d.ts +0 -0
  96. /package/dist/{plugin → agent-plugins}/AutoMigratePlugin.js +0 -0
  97. /package/dist/{plugin → agent-plugins}/AutoRefreshToolsPlugin.d.ts +0 -0
  98. /package/dist/{plugin → agent-plugins}/ContextGuardPlugin.d.ts +0 -0
  99. /package/dist/{plugin → agent-plugins}/ContextGuardPlugin.js +0 -0
  100. /package/dist/{capabilities → scope}/PermissionEvaluator.d.ts +0 -0
  101. /package/dist/{capabilities → scope}/PermissionEvaluator.js +0 -0
  102. /package/dist/{capabilities → scope}/disclosure.d.ts +0 -0
  103. /package/dist/{capabilities → scope}/disclosure.js +0 -0
  104. /package/dist/{runtime → scope/plugins/builtin}/SdkCallbackTool.js +0 -0
  105. /package/dist/{capabilities/implements → scope/plugins}/builtin/outputGuard.d.ts +0 -0
  106. /package/dist/{capabilities/implements → scope/plugins}/builtin/outputGuard.js +0 -0
  107. /package/dist/{capabilities/implements → scope/plugins}/builtin/test-helpers.d.ts +0 -0
  108. /package/dist/{capabilities/implements → scope/plugins}/builtin/test-helpers.js +0 -0
  109. /package/dist/{capabilities/discovery/skills.d.ts → scope/plugins/skills/discover.d.ts} +0 -0
  110. /package/dist/{capabilities/discovery/subagents.js → scope/plugins/subagents/discover.js} +0 -0
  111. /package/dist/{capabilities/discovery/usertools.d.ts → scope/plugins/usertools/discover.d.ts} +0 -0
@@ -0,0 +1,20 @@
1
+ import type { Tool } from "@ai-zen/agents-core";
2
+ import type { AgentDefinition } from "../../../types/index.js";
3
+ import type { Scope, FilterOutput } from "../../Scope.js";
4
+ import type { ScopeCandidates, ScopePlugin } from "../../ScopePlugin.js";
5
+ /**
6
+ * 内置工具插件 —— 20 个内置工具类(BUILTIN_TOOL_CLASSES)。
7
+ *
8
+ * 发现层零过滤;可用性由各工具 `isAvailable(config, definition)` 自陈,
9
+ * 在本插件 `candidates()` 阶段按声明剔除(如 GenerateImageTool 依赖 defaultImageModel、
10
+ * ViewImageTool 仅视觉模型可用)。
11
+ */
12
+ export declare class BuiltinToolsScopePlugin implements ScopePlugin {
13
+ static readonly ID = "builtin";
14
+ readonly id = "builtin";
15
+ /** 发现结果自持(每次 discover 重新实例化) */
16
+ private tools;
17
+ discover(scope: Scope): void;
18
+ candidates(scope: Scope, definition: AgentDefinition): ScopeCandidates;
19
+ instantiate(_scope: Scope, filtered: FilterOutput): Tool[];
20
+ }
@@ -0,0 +1,30 @@
1
+ import { discoverBuiltinTools } from "./discover.js";
2
+ /**
3
+ * 内置工具插件 —— 20 个内置工具类(BUILTIN_TOOL_CLASSES)。
4
+ *
5
+ * 发现层零过滤;可用性由各工具 `isAvailable(config, definition)` 自陈,
6
+ * 在本插件 `candidates()` 阶段按声明剔除(如 GenerateImageTool 依赖 defaultImageModel、
7
+ * ViewImageTool 仅视觉模型可用)。
8
+ */
9
+ export class BuiltinToolsScopePlugin {
10
+ static ID = "builtin";
11
+ id = BuiltinToolsScopePlugin.ID;
12
+ /** 发现结果自持(每次 discover 重新实例化) */
13
+ tools = [];
14
+ discover(scope) {
15
+ this.tools = discoverBuiltinTools(scope.env);
16
+ }
17
+ candidates(scope, definition) {
18
+ const tools = this.tools
19
+ .filter((t) => {
20
+ const isAvailable = t?.isAvailable;
21
+ return isAvailable ? isAvailable(scope.config, definition) : true;
22
+ })
23
+ .map((t) => t.function.name);
24
+ return { tools };
25
+ }
26
+ instantiate(_scope, filtered) {
27
+ const allow = new Set(filtered.tools);
28
+ return this.tools.filter((t) => allow.has(t.function.name));
29
+ }
30
+ }
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class CopyTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  export class CopyTool extends SdkCallbackTool {
4
4
  function = {
5
5
  name: "copy",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class CwdTool extends SdkCallbackTool {
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  export class CwdTool extends SdkCallbackTool {
3
3
  function = {
4
4
  name: "cwd",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
4
4
  export declare class DownloadFileTool extends SdkCallbackTool {
@@ -1,6 +1,6 @@
1
1
  import * as fsp from "fs/promises";
2
2
  import * as path from "path";
3
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
3
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
4
4
  export class DownloadFileTool extends SdkCallbackTool {
5
5
  function = {
6
6
  name: "downloadFile",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class EditTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  function countOccurrences(content, text) {
4
4
  let count = 0;
5
5
  let pos = 0;
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class ExecAsyncTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import { spawn } from "child_process";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  export class ExecAsyncTool extends SdkCallbackTool {
4
4
  function = {
5
5
  name: "exec_async",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
4
4
  export declare class ExecTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import { exec } from "child_process";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  import { DEFAULT_MAX_TOOL_OUTPUT, guardOutput, headTailPreview } from "./outputGuard.js";
4
4
  export class ExecTool extends SdkCallbackTool {
5
5
  function = {
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class ExistTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  export class ExistTool extends SdkCallbackTool {
4
4
  function = {
5
5
  name: "exist",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
4
4
  export declare class FindTextTool extends SdkCallbackTool {
@@ -1,6 +1,6 @@
1
1
  import * as fsp from "fs/promises";
2
2
  import * as path from "path";
3
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
3
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
4
4
  import { DEFAULT_MAX_TOOL_OUTPUT, guardOutput, headPreview } from "./outputGuard.js";
5
5
  /** 默认总匹配数上限 */
6
6
  const DEFAULT_MAX_MATCHES = 200;
@@ -1,5 +1,5 @@
1
1
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  import type { AgentDefinition, AppConfig, ToolEnv } from "../../../types/index.js";
4
4
  /**
5
5
  * 根据文字描述生成图片。**统一返回字符串**(JSON,含图片 URL 列表):
@@ -1,5 +1,5 @@
1
1
  import OpenAI from "openai";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  /**
4
4
  * 根据文字描述生成图片。**统一返回字符串**(JSON,含图片 URL 列表):
5
5
  * 生成结果如何处理(查看/下载/转发)由模型与上层自由决定——
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
4
4
  export declare class GlobTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  import { DEFAULT_MAX_TOOL_OUTPUT, guardOutput, headPreview } from "./outputGuard.js";
4
4
  export class GlobTool extends SdkCallbackTool {
5
5
  function = {
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  import * as fsp from "fs/promises";
2
2
  import { createReadStream } from "fs";
3
3
  import { StringDecoder } from "string_decoder";
4
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
4
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
5
5
  import { DEFAULT_MAX_TOOL_OUTPUT } from "./outputGuard.js";
6
6
  /**
7
7
  * 勘察文件结构概况(行数、每行列数等),不做内容读取。
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class LsTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  import { DEFAULT_MAX_TOOL_OUTPUT, guardOutput, headPreview } from "./outputGuard.js";
4
4
  export class LsTool extends SdkCallbackTool {
5
5
  function = {
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class MkdirTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  export class MkdirTool extends SdkCallbackTool {
4
4
  function = {
5
5
  name: "mkdir",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class ReadFileTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  import { DEFAULT_MAX_TOOL_OUTPUT, guardOutput } from "./outputGuard.js";
4
4
  export class ReadFileTool extends SdkCallbackTool {
5
5
  function = {
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class RenameTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  export class RenameTool extends SdkCallbackTool {
4
4
  function = {
5
5
  name: "rename",
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class RmTool extends SdkCallbackTool {
@@ -1,5 +1,5 @@
1
1
  import * as fsp from "fs/promises";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  export class RmTool extends SdkCallbackTool {
4
4
  function = {
5
5
  name: "rm",
@@ -1,6 +1,6 @@
1
1
  import { Tool, ToolCallContext } from "@ai-zen/agents-core";
2
2
  import type { AgentNS } from "@ai-zen/agents-core";
3
- import type { AgentDefinition, AppConfig, ToolEnv } from "../types/index.js";
3
+ import type { AgentDefinition, AppConfig, ToolEnv } from "../../../types/index.js";
4
4
  /** SdkCallbackTool 构造选项。env 为核心字段,未来可在此扩展可选项。 */
5
5
  export interface SdkCallbackToolOptions {
6
6
  /** 注入的工具环境 */
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
4
4
  export declare class SleepTool extends SdkCallbackTool {
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  export class SleepTool extends SdkCallbackTool {
3
3
  function = {
4
4
  name: "sleep",
@@ -1,5 +1,5 @@
1
1
  import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
2
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
2
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  import type { AgentDefinition, AppConfig, ToolEnv } from "../../../types/index.js";
4
4
  /**
5
5
  * 查看图片工具 — 让 Agent 主动查看/分析一张图片。**仅对视觉模型可用**:
@@ -1,7 +1,7 @@
1
1
  import OpenAI, { toFile } from "openai";
2
2
  import { promises as fs } from "node:fs";
3
3
  import path from "node:path";
4
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
4
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
5
5
  const SUPPORTED_EXT = [".jpg", ".jpeg", ".png", ".gif", ".webp"];
6
6
  /**
7
7
  * 是否为"本地 URL"——指向本地/回环地址,API 服务商无法下载访问。
@@ -1,4 +1,4 @@
1
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import type { AgentNS } from "@ai-zen/agents-core";
4
4
  export declare class WriteFileTool extends SdkCallbackTool {
@@ -1,6 +1,6 @@
1
1
  import * as fsp from "fs/promises";
2
2
  import * as path from "path";
3
- import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
3
+ import { SdkCallbackTool } from "./SdkCallbackTool.js";
4
4
  export class WriteFileTool extends SdkCallbackTool {
5
5
  function = {
6
6
  name: "writeFile",
@@ -1,5 +1,5 @@
1
1
  import type { Tool } from "@ai-zen/agents-core";
2
- import type { ToolEnv } from "../../types/index.js";
2
+ import type { ToolEnv } from "../../../types/index.js";
3
3
  /**
4
4
  * 发现内置工具:按静态注册表实例化全部内置工具(无任何过滤)。
5
5
  *
@@ -1,4 +1,4 @@
1
- import { BUILTIN_TOOL_CLASSES } from "../implements/builtin/index.js";
1
+ import { BUILTIN_TOOL_CLASSES } from "./index.js";
2
2
  /**
3
3
  * 发现内置工具:按静态注册表实例化全部内置工具(无任何过滤)。
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
1
+ import type { SdkCallbackTool } from "./SdkCallbackTool.js";
2
2
  import type { ToolEnv } from "../../../types/index.js";
3
3
  import { CwdTool } from "./CwdTool.js";
4
4
  import { ReadFileTool } from "./ReadFileTool.js";
@@ -22,7 +22,7 @@ import { ViewImageTool } from "./ViewImageTool.js";
22
22
  import { GenerateImageTool } from "./GenerateImageTool.js";
23
23
  /**
24
24
  * 全部内置工具类(20 个)。
25
- * 工具类由 Provider 用 ToolEnv 实例化(每个 Provider 一套实例,注入其 cwd)。
25
+ * 工具类由 Scope 的内置工具插件(BuiltinToolsScopePlugin)用 ToolEnv 实例化(每个 Scope 一套实例,注入其 cwd)。
26
26
  *
27
27
  * 发现层不做任何过滤——工具的可用性由各工具自行声明(SdkCallbackTool.isAvailable,
28
28
  * 入参含完整 config + 模型信息),在 buildTools/filter 阶段按声明过滤。
@@ -20,7 +20,7 @@ import { ViewImageTool } from "./ViewImageTool.js";
20
20
  import { GenerateImageTool } from "./GenerateImageTool.js";
21
21
  /**
22
22
  * 全部内置工具类(20 个)。
23
- * 工具类由 Provider 用 ToolEnv 实例化(每个 Provider 一套实例,注入其 cwd)。
23
+ * 工具类由 Scope 的内置工具插件(BuiltinToolsScopePlugin)用 ToolEnv 实例化(每个 Scope 一套实例,注入其 cwd)。
24
24
  *
25
25
  * 发现层不做任何过滤——工具的可用性由各工具自行声明(SdkCallbackTool.isAvailable,
26
26
  * 入参含完整 config + 模型信息),在 buildTools/filter 阶段按声明过滤。
@@ -1,6 +1,6 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
3
- import type { McpServerConfig, McpServerManifest, McpConnectionState } from "../types/index.js";
3
+ import type { McpServerConfig, McpServerManifest, McpConnectionState } from "../../../types/index.js";
4
4
  export interface McpConnectOptions {
5
5
  /** 空闲超时(毫秒),默认 stdio: 30min, http: 5min */
6
6
  idleTimeoutMs?: number;
@@ -2,7 +2,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
3
3
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
4
4
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
5
- import { getLogger } from "../shared/logger.js";
5
+ import { getLogger } from "../../../shared/logger.js";
6
6
  const DEFAULT_IDLE_TIMEOUT = {
7
7
  stdio: 30 * 60 * 1000,
8
8
  http: 5 * 60 * 1000,
@@ -0,0 +1,29 @@
1
+ import type { Tool } from "@ai-zen/agents-core";
2
+ import type { Scope, FilterOutput } from "../../Scope.js";
3
+ import type { ScopeCandidates, ScopePlugin } from "../../ScopePlugin.js";
4
+ /**
5
+ * MCP 插件 —— 发现 mcp.json + 自持连接管理器 + 装配渐进式披露元工具。
6
+ *
7
+ * 渐进式披露设计原样保留:
8
+ * - `load_mcp` 枚举所有允许的 server(含 include_manifest 开关)
9
+ * - `call_mcp_tool` 调用已连接 server 的工具
10
+ * - `read_mcp_resource` 读取已连接 server 的资源
11
+ * 三个元工具名恒上报 `tools` 维度;`mcpManager` 由本插件私有持有,
12
+ * 有配置路径时在构造时创建,`dispose()` 时统一断开。
13
+ */
14
+ export declare class McpScopePlugin implements ScopePlugin {
15
+ static readonly ID = "mcp";
16
+ readonly id = "mcp";
17
+ private readonly paths;
18
+ private readonly mcpManager;
19
+ private servers;
20
+ constructor(options?: {
21
+ paths?: string[];
22
+ });
23
+ discover(scope: Scope): Promise<void>;
24
+ /** 是否配置了 MCP(供外部代码判定,如 UnknownToolHintPlugin) */
25
+ hasConfig(): boolean;
26
+ candidates(): ScopeCandidates;
27
+ instantiate(_scope: Scope, filtered: FilterOutput): Tool[];
28
+ dispose(): Promise<void>;
29
+ }
@@ -0,0 +1,60 @@
1
+ import { isAbsolute, join } from "node:path";
2
+ import { discoverMcpServers } from "./discover.js";
3
+ import { createCallMcpTool, createLoadMcpTool, createReadMcpResourceTool, } from "./mcpTools.js";
4
+ import { McpConnectionManager } from "./McpConnectionManager.js";
5
+ /**
6
+ * MCP 插件 —— 发现 mcp.json + 自持连接管理器 + 装配渐进式披露元工具。
7
+ *
8
+ * 渐进式披露设计原样保留:
9
+ * - `load_mcp` 枚举所有允许的 server(含 include_manifest 开关)
10
+ * - `call_mcp_tool` 调用已连接 server 的工具
11
+ * - `read_mcp_resource` 读取已连接 server 的资源
12
+ * 三个元工具名恒上报 `tools` 维度;`mcpManager` 由本插件私有持有,
13
+ * 有配置路径时在构造时创建,`dispose()` 时统一断开。
14
+ */
15
+ export class McpScopePlugin {
16
+ static ID = "mcp";
17
+ id = McpScopePlugin.ID;
18
+ paths;
19
+ mcpManager;
20
+ servers = [];
21
+ constructor(options) {
22
+ this.paths = options?.paths ?? [];
23
+ this.mcpManager =
24
+ this.paths.length > 0 ? new McpConnectionManager() : undefined;
25
+ }
26
+ async discover(scope) {
27
+ const files = this.paths.map((p) => (isAbsolute(p) ? p : join(scope.cwd, p)));
28
+ this.servers = await discoverMcpServers(files);
29
+ }
30
+ /** 是否配置了 MCP(供外部代码判定,如 UnknownToolHintPlugin) */
31
+ hasConfig() {
32
+ return this.paths.length > 0;
33
+ }
34
+ candidates() {
35
+ return {
36
+ mcps: this.servers.map((s) => s.id),
37
+ tools: ["load_mcp", "call_mcp_tool", "read_mcp_resource"],
38
+ };
39
+ }
40
+ instantiate(_scope, filtered) {
41
+ const allow = new Set(filtered.tools);
42
+ const allowedMcps = new Set(filtered.mcps);
43
+ const filteredMcps = this.servers.filter((s) => allowedMcps.has(s.id));
44
+ const m = this.mcpManager;
45
+ const result = [];
46
+ if (allow.has("load_mcp") && m && filteredMcps.length > 0) {
47
+ result.push(createLoadMcpTool(m, filteredMcps));
48
+ }
49
+ if (allow.has("call_mcp_tool") && m) {
50
+ result.push(createCallMcpTool(m));
51
+ }
52
+ if (allow.has("read_mcp_resource") && m) {
53
+ result.push(createReadMcpResourceTool(m));
54
+ }
55
+ return result;
56
+ }
57
+ async dispose() {
58
+ await this.mcpManager?.disconnectAll();
59
+ }
60
+ }
@@ -1,4 +1,4 @@
1
- import type { McpServerConfig } from "../../types/index.js";
1
+ import type { McpServerConfig } from "../../../types/index.js";
2
2
  /**
3
3
  * 从 mcp.json 文件列表中发现所有 MCP server 配置。
4
4
  *
@@ -1,5 +1,5 @@
1
1
  import { promises as fs } from "node:fs";
2
- import { getLogger } from "../../shared/logger.js";
2
+ import { getLogger } from "../../../shared/logger.js";
3
3
  /**
4
4
  * 归一化原始 MCP server 配置为内部 McpServerConfig。
5
5
  * 处理业界标准中的字段别名差异。
@@ -1,6 +1,6 @@
1
1
  import { CallbackTool } from "@ai-zen/agents-core";
2
- import type { McpConnectionManager } from "../../runtime/McpConnectionManager.js";
3
- import type { McpServerConfig } from "../../types/index.js";
2
+ import type { McpConnectionManager } from "./McpConnectionManager.js";
3
+ import type { McpServerConfig } from "../../../types/index.js";
4
4
  /**
5
5
  * 创建 load_mcp 工具。
6
6
  * server 枚举由 filteredMcps (完整 McpServerConfig[])自动推导,
@@ -1,6 +1,6 @@
1
1
  import { CallbackTool } from "@ai-zen/agents-core";
2
- import { createDisclosureParam } from "../disclosure.js";
3
- import { getLogger } from "../../shared/logger.js";
2
+ import { createDisclosureParam } from "../../disclosure.js";
3
+ import { getLogger } from "../../../shared/logger.js";
4
4
  const EMPTY_HINT = "(当前没有可用的 MCP 服务器,请联系用户添加)";
5
5
  const log = getLogger();
6
6
  /**
@@ -0,0 +1,28 @@
1
+ import type { Tool } from "@ai-zen/agents-core";
2
+ import type { Scope, FilterOutput } from "../../Scope.js";
3
+ import type { ScopeCandidates, ScopePlugin } from "../../ScopePlugin.js";
4
+ /**
5
+ * Skill 插件 —— 发现 SKILL.md + 装配渐进式披露元工具。
6
+ *
7
+ * 渐进式披露设计原样保留:
8
+ * - `load_skill` 枚举所有允许的 skill
9
+ * - `call_skill_sub_agent` 枚举 subAgent: true 的 skill(AgentToolLazy)
10
+ * 两个元工具名恒上报 `tools` 维度(供权限允许/拒绝 → 拒绝即切断披露通道);
11
+ * 是否真正注册由 `instantiate()` 按允许名 + 候选条件决定。
12
+ */
13
+ export declare class SkillsScopePlugin implements ScopePlugin {
14
+ static readonly ID = "skills";
15
+ readonly id = "skills";
16
+ private readonly paths;
17
+ private skills;
18
+ /** 解析后的 skill 目录(供 instantiate 时传给工具读取正文) */
19
+ private dirs;
20
+ constructor(options?: {
21
+ paths?: string[];
22
+ });
23
+ discover(scope: Scope, options?: {
24
+ silent?: boolean;
25
+ }): Promise<void>;
26
+ candidates(): ScopeCandidates;
27
+ instantiate(_scope: Scope, filtered: FilterOutput): Tool[];
28
+ }