@ai-zen/agents-sdk 0.12.0 → 1.0.0-alpha.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.
- package/CHANGELOG.md +103 -36
- package/README.md +29 -21
- package/README.zh.md +29 -21
- package/dist/{plugin → agent-plugins}/AutoRefreshToolsPlugin.js +2 -2
- package/dist/{plugin → agent-plugins}/UnknownToolHintPlugin.d.ts +7 -5
- package/dist/{plugin → agent-plugins}/UnknownToolHintPlugin.js +9 -5
- package/dist/config/ConfigManager.d.ts +17 -0
- package/dist/config/ConfigManager.js +44 -1
- package/dist/config/constants.js +67 -37
- package/dist/index.d.ts +37 -29
- package/dist/index.js +28 -21
- package/dist/runtime/SdkAgent.d.ts +5 -5
- package/dist/runtime/SdkAgent.js +4 -4
- package/dist/runtime/TaskMigrationService.d.ts +1 -1
- package/dist/runtime/TaskMigrationService.js +2 -2
- package/dist/runtime/createAgent.d.ts +4 -4
- package/dist/runtime/createAgent.js +8 -8
- package/dist/runtime/createModel.d.ts +3 -3
- package/dist/runtime/createModel.js +3 -3
- package/dist/scope/Scope.d.ts +111 -0
- package/dist/scope/Scope.js +165 -0
- package/dist/scope/ScopePlugin.d.ts +51 -0
- package/dist/scope/ScopePlugin.js +1 -0
- package/dist/scope/plugins/allInOne.d.ts +18 -0
- package/dist/scope/plugins/allInOne.js +23 -0
- package/dist/{capabilities/implements → scope/plugins}/builtin/BatchEditTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/BatchEditTool.js +1 -1
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.d.ts +20 -0
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.js +30 -0
- package/dist/{capabilities/implements → scope/plugins}/builtin/CopyTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/CopyTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/CwdTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/CwdTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/DownloadFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/DownloadFileTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/EditTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/EditTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecAsyncTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecAsyncTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExistTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExistTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/FindTextTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/FindTextTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GenerateImageTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GenerateImageTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GlobTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GlobTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/InspectFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/InspectFileTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/LsTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/LsTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/MkdirTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/MkdirTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ReadFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ReadFileTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RenameTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RenameTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RmTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RmTool.js +1 -1
- package/dist/{runtime → scope/plugins/builtin}/SdkCallbackTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/SleepTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/SleepTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ViewImageTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ViewImageTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/WriteFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/WriteFileTool.js +1 -1
- package/dist/{capabilities/discovery/builtin.d.ts → scope/plugins/builtin/discover.d.ts} +1 -1
- package/dist/{capabilities/discovery/builtin.js → scope/plugins/builtin/discover.js} +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/index.d.ts +2 -2
- package/dist/{capabilities/implements → scope/plugins}/builtin/index.js +1 -1
- package/dist/{runtime → scope/plugins/mcp}/McpConnectionManager.d.ts +1 -1
- package/dist/{runtime → scope/plugins/mcp}/McpConnectionManager.js +1 -1
- package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +29 -0
- package/dist/scope/plugins/mcp/McpScopePlugin.js +60 -0
- package/dist/{capabilities/discovery/mcp.d.ts → scope/plugins/mcp/discover.d.ts} +1 -1
- package/dist/{capabilities/discovery/mcp.js → scope/plugins/mcp/discover.js} +1 -1
- package/dist/{capabilities/implements → scope/plugins/mcp}/mcpTools.d.ts +2 -2
- package/dist/{capabilities/implements → scope/plugins/mcp}/mcpTools.js +2 -2
- package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +28 -0
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +48 -0
- package/dist/{capabilities/discovery/skills.js → scope/plugins/skills/discover.js} +1 -1
- package/dist/{capabilities/implements → scope/plugins/skills}/skillTools.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins/skills}/skillTools.js +3 -3
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.d.ts +20 -0
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +34 -0
- package/dist/{capabilities/discovery/subagents.d.ts → scope/plugins/subagents/discover.d.ts} +1 -1
- package/dist/{capabilities/implements → scope/plugins/subagents}/subAgentTools.d.ts +3 -3
- package/dist/{capabilities/implements → scope/plugins/subagents}/subAgentTools.js +5 -5
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.d.ts +24 -0
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.js +28 -0
- package/dist/{capabilities/discovery/usertools.js → scope/plugins/usertools/discover.js} +1 -1
- package/dist/types/index.d.ts +23 -2
- package/package.json +3 -3
- package/dist/runtime/Provider.d.ts +0 -119
- package/dist/runtime/Provider.js +0 -218
- /package/dist/{plugin → agent-plugins}/AutoMigratePlugin.d.ts +0 -0
- /package/dist/{plugin → agent-plugins}/AutoMigratePlugin.js +0 -0
- /package/dist/{plugin → agent-plugins}/AutoRefreshToolsPlugin.d.ts +0 -0
- /package/dist/{plugin → agent-plugins}/ContextGuardPlugin.d.ts +0 -0
- /package/dist/{plugin → agent-plugins}/ContextGuardPlugin.js +0 -0
- /package/dist/{capabilities → scope}/PermissionEvaluator.d.ts +0 -0
- /package/dist/{capabilities → scope}/PermissionEvaluator.js +0 -0
- /package/dist/{capabilities → scope}/disclosure.d.ts +0 -0
- /package/dist/{capabilities → scope}/disclosure.js +0 -0
- /package/dist/{runtime → scope/plugins/builtin}/SdkCallbackTool.js +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/outputGuard.d.ts +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/outputGuard.js +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/test-helpers.d.ts +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/test-helpers.js +0 -0
- /package/dist/{capabilities/discovery/skills.d.ts → scope/plugins/skills/discover.d.ts} +0 -0
- /package/dist/{capabilities/discovery/subagents.js → scope/plugins/subagents/discover.js} +0 -0
- /package/dist/{capabilities/discovery/usertools.d.ts → scope/plugins/usertools/discover.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SdkCallbackTool } from "
|
|
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 "
|
|
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 "
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { SdkCallbackTool } from "
|
|
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,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 "
|
|
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 "
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import type { AgentNS, ToolCallContext } from "@ai-zen/agents-core";
|
|
2
|
-
import { SdkCallbackTool } from "
|
|
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 "
|
|
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 "
|
|
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 "
|
|
3
|
+
import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
4
4
|
export class WriteFileTool extends SdkCallbackTool {
|
|
5
5
|
function = {
|
|
6
6
|
name: "writeFile",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SdkCallbackTool } from "
|
|
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
|
-
* 工具类由
|
|
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
|
-
* 工具类由
|
|
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 "
|
|
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 "
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { CallbackTool } from "@ai-zen/agents-core";
|
|
2
|
-
import type { McpConnectionManager } from "
|
|
3
|
-
import type { McpServerConfig } from "
|
|
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 "
|
|
3
|
-
import { getLogger } from "
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
2
|
+
import { discoverSkills } from "./discover.js";
|
|
3
|
+
import { createCallSkillSubAgentTool, createLoadSkillTool, } from "./skillTools.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 class SkillsScopePlugin {
|
|
14
|
+
static ID = "skills";
|
|
15
|
+
id = SkillsScopePlugin.ID;
|
|
16
|
+
paths;
|
|
17
|
+
skills = [];
|
|
18
|
+
/** 解析后的 skill 目录(供 instantiate 时传给工具读取正文) */
|
|
19
|
+
dirs = [];
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.paths = options?.paths ?? [];
|
|
22
|
+
}
|
|
23
|
+
async discover(scope, options) {
|
|
24
|
+
this.dirs = this.paths.map((p) => (isAbsolute(p) ? p : join(scope.cwd, p)));
|
|
25
|
+
this.skills = await discoverSkills(this.dirs, options);
|
|
26
|
+
}
|
|
27
|
+
candidates() {
|
|
28
|
+
return {
|
|
29
|
+
skills: this.skills.map((s) => s.id),
|
|
30
|
+
tools: ["load_skill", "call_skill_sub_agent"],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
instantiate(_scope, filtered) {
|
|
34
|
+
const allow = new Set(filtered.tools);
|
|
35
|
+
const allowedSkills = new Set(filtered.skills);
|
|
36
|
+
const filteredSkills = this.skills.filter((s) => allowedSkills.has(s.id));
|
|
37
|
+
const result = [];
|
|
38
|
+
if (allow.has("load_skill") && filteredSkills.length > 0) {
|
|
39
|
+
result.push(createLoadSkillTool(this.dirs, filteredSkills));
|
|
40
|
+
}
|
|
41
|
+
// call_skill_sub_agent:只要有支持子 Agent 的 skill 就注册
|
|
42
|
+
if (allow.has("call_skill_sub_agent") &&
|
|
43
|
+
filteredSkills.some((s) => s.subAgent)) {
|
|
44
|
+
result.push(createCallSkillSubAgentTool(this.dirs, filteredSkills));
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { getLogger } from "
|
|
3
|
+
import { getLogger } from "../../../shared/logger.js";
|
|
4
4
|
const log = getLogger();
|
|
5
5
|
// ---- 发现(返回完整 SkillInfo,不再丢失 subAgent 等信息)----
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CallbackTool, Agent, AgentToolLazy, Message } from "@ai-zen/agents-core";
|
|
2
|
-
import { createDisclosureParam } from "
|
|
3
|
-
import { readSkill } from "
|
|
4
|
-
import { getLogger } from "
|
|
2
|
+
import { createDisclosureParam } from "../../disclosure.js";
|
|
3
|
+
import { readSkill } from "./discover.js";
|
|
4
|
+
import { getLogger } from "../../../shared/logger.js";
|
|
5
5
|
import { promises as fs } from "node:fs";
|
|
6
6
|
const log = getLogger();
|
|
7
7
|
const EMPTY_HINT = "(当前没有可用的 Skill,请联系用户添加)";
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
* SubAgent 插件 —— 发现 `sub-agents/*.json`,将含 function 的定义注册为工具。
|
|
6
|
+
*
|
|
7
|
+
* 产物为 `AgentToolLazy`(延迟构建,避免工具列表构建阶段的递归创建)。
|
|
8
|
+
*/
|
|
9
|
+
export declare class SubAgentsScopePlugin implements ScopePlugin {
|
|
10
|
+
static readonly ID = "subagents";
|
|
11
|
+
readonly id = "subagents";
|
|
12
|
+
private readonly paths;
|
|
13
|
+
private subagents;
|
|
14
|
+
constructor(options?: {
|
|
15
|
+
paths?: string[];
|
|
16
|
+
});
|
|
17
|
+
discover(scope: Scope): Promise<void>;
|
|
18
|
+
candidates(): ScopeCandidates;
|
|
19
|
+
instantiate(scope: Scope, filtered: FilterOutput): Tool[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
2
|
+
import { discoverSubAgents } from "./discover.js";
|
|
3
|
+
import { createSubAgentTool } from "./subAgentTools.js";
|
|
4
|
+
/**
|
|
5
|
+
* SubAgent 插件 —— 发现 `sub-agents/*.json`,将含 function 的定义注册为工具。
|
|
6
|
+
*
|
|
7
|
+
* 产物为 `AgentToolLazy`(延迟构建,避免工具列表构建阶段的递归创建)。
|
|
8
|
+
*/
|
|
9
|
+
export class SubAgentsScopePlugin {
|
|
10
|
+
static ID = "subagents";
|
|
11
|
+
id = SubAgentsScopePlugin.ID;
|
|
12
|
+
paths;
|
|
13
|
+
subagents = [];
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.paths = options?.paths ?? [];
|
|
16
|
+
}
|
|
17
|
+
async discover(scope) {
|
|
18
|
+
const dirs = this.paths.map((p) => (isAbsolute(p) ? p : join(scope.cwd, p)));
|
|
19
|
+
this.subagents = await discoverSubAgents(dirs);
|
|
20
|
+
}
|
|
21
|
+
candidates() {
|
|
22
|
+
return {
|
|
23
|
+
subagents: this.subagents
|
|
24
|
+
.filter((d) => d.function)
|
|
25
|
+
.map((d) => d.function.name),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
instantiate(scope, filtered) {
|
|
29
|
+
const allow = new Set(filtered.subagents);
|
|
30
|
+
return this.subagents
|
|
31
|
+
.filter((d) => d.function && allow.has(d.function.name))
|
|
32
|
+
.map((d) => createSubAgentTool(d, scope));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Tool } from "@ai-zen/agents-core";
|
|
2
|
-
import type { AgentDefinition } from "
|
|
3
|
-
import type {
|
|
2
|
+
import type { AgentDefinition } from "../../../types/index.js";
|
|
3
|
+
import type { Scope } from "../../Scope.js";
|
|
4
4
|
/**
|
|
5
5
|
* 创建 SubAgent 工具(AgentToolLazy)。
|
|
6
6
|
*
|
|
7
7
|
* SubAgent 是有 `function` 字段的 Agent,可被其他 Agent 作为工具调用。
|
|
8
8
|
* 使用延迟构建(AgentToolLazy)避免工具列表构建阶段的递归创建问题。
|
|
9
9
|
*/
|
|
10
|
-
export declare function createSubAgentTool(def: AgentDefinition,
|
|
10
|
+
export declare function createSubAgentTool(def: AgentDefinition, scope: Scope): Tool;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Agent, AgentToolLazy } from "@ai-zen/agents-core";
|
|
2
|
-
import { createModel } from "
|
|
2
|
+
import { createModel } from "../../../runtime/createModel.js";
|
|
3
3
|
/**
|
|
4
4
|
* 创建 SubAgent 工具(AgentToolLazy)。
|
|
5
5
|
*
|
|
6
6
|
* SubAgent 是有 `function` 字段的 Agent,可被其他 Agent 作为工具调用。
|
|
7
7
|
* 使用延迟构建(AgentToolLazy)避免工具列表构建阶段的递归创建问题。
|
|
8
8
|
*/
|
|
9
|
-
export function createSubAgentTool(def,
|
|
9
|
+
export function createSubAgentTool(def, scope) {
|
|
10
10
|
if (!def.function) {
|
|
11
11
|
throw new Error(`Agent "${def.id}" 没有 function 字段,不能作为 SubAgent 工具`);
|
|
12
12
|
}
|
|
@@ -24,7 +24,7 @@ export function createSubAgentTool(def, provider) {
|
|
|
24
24
|
let model;
|
|
25
25
|
let modelConfig;
|
|
26
26
|
if (def.modelId) {
|
|
27
|
-
const m = createModel(
|
|
27
|
+
const m = createModel(scope, def.modelId);
|
|
28
28
|
client = m.client;
|
|
29
29
|
model = m.model;
|
|
30
30
|
modelConfig = m.modelConfig;
|
|
@@ -39,12 +39,12 @@ export function createSubAgentTool(def, provider) {
|
|
|
39
39
|
modelConfig = parent.modelConfig;
|
|
40
40
|
}
|
|
41
41
|
// SubAgent 独立解析自己的工具(排除自身,防止递归)
|
|
42
|
-
const subFiltered =
|
|
42
|
+
const subFiltered = scope.filter(def, {
|
|
43
43
|
exclude: {
|
|
44
44
|
subagents: def.function?.name ? [def.function.name] : undefined,
|
|
45
45
|
},
|
|
46
46
|
});
|
|
47
|
-
const tools =
|
|
47
|
+
const tools = scope.instantiate(subFiltered);
|
|
48
48
|
const subAgent = new Agent({
|
|
49
49
|
client,
|
|
50
50
|
model,
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* 用户工具插件 —— 扫描 `tools/*.js` / `*.mjs` 动态加载。
|
|
7
|
+
*
|
|
8
|
+
* 与内置工具插件分开,以便单独替换/停用其中一类。
|
|
9
|
+
* 路径可为绝对路径或相对路径(相对则按 scope.cwd join)。
|
|
10
|
+
*/
|
|
11
|
+
export declare class UserToolsScopePlugin implements ScopePlugin {
|
|
12
|
+
static readonly ID = "user-tools";
|
|
13
|
+
readonly id = "user-tools";
|
|
14
|
+
private readonly paths;
|
|
15
|
+
private tools;
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
paths?: string[];
|
|
18
|
+
});
|
|
19
|
+
discover(scope: Scope, options?: {
|
|
20
|
+
silent?: boolean;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
candidates(_scope: Scope, _definition: AgentDefinition): ScopeCandidates;
|
|
23
|
+
instantiate(_scope: Scope, filtered: FilterOutput): Tool[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
2
|
+
import { discoverUserTools } from "./discover.js";
|
|
3
|
+
/**
|
|
4
|
+
* 用户工具插件 —— 扫描 `tools/*.js` / `*.mjs` 动态加载。
|
|
5
|
+
*
|
|
6
|
+
* 与内置工具插件分开,以便单独替换/停用其中一类。
|
|
7
|
+
* 路径可为绝对路径或相对路径(相对则按 scope.cwd join)。
|
|
8
|
+
*/
|
|
9
|
+
export class UserToolsScopePlugin {
|
|
10
|
+
static ID = "user-tools";
|
|
11
|
+
id = UserToolsScopePlugin.ID;
|
|
12
|
+
paths;
|
|
13
|
+
tools = [];
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.paths = options?.paths ?? [];
|
|
16
|
+
}
|
|
17
|
+
async discover(scope, options) {
|
|
18
|
+
const dirs = this.paths.map((p) => (isAbsolute(p) ? p : join(scope.cwd, p)));
|
|
19
|
+
this.tools = await discoverUserTools(dirs, options);
|
|
20
|
+
}
|
|
21
|
+
candidates(_scope, _definition) {
|
|
22
|
+
return { tools: this.tools.map((t) => t.function.name) };
|
|
23
|
+
}
|
|
24
|
+
instantiate(_scope, filtered) {
|
|
25
|
+
const allow = new Set(filtered.tools);
|
|
26
|
+
return this.tools.filter((t) => allow.has(t.function.name));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -2,7 +2,7 @@ import { promises as fs } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { Tool, CallbackTool } from "@ai-zen/agents-core";
|
|
5
|
-
import { getLogger } from "
|
|
5
|
+
import { getLogger } from "../../../shared/logger.js";
|
|
6
6
|
/**
|
|
7
7
|
* 扫描多个 tools/ 目录,发现所有 .js / .mjs 文件,动态加载为 Tool 实例。
|
|
8
8
|
* 使用原生 dynamic import() 加载(在 "type": "module" 下 .js 也是 ESM),
|