@ai-zen/agents-sdk 0.3.4 → 0.4.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 +14 -0
- 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/mcpTools.js +6 -4
- package/dist/capabilities/implements/skillTools.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/AutoDraftPlugin.js +2 -2
- package/dist/plugin/AutoMigratePlugin.js +2 -2
- package/dist/runtime/McpConnectionManager.js +4 -3
- package/dist/shared/logger.d.ts +6 -2
- package/dist/shared/logger.js +14 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2026-07-29
|
|
4
|
+
|
|
5
|
+
### 💥 破坏性变更
|
|
6
|
+
|
|
7
|
+
- **`load_mcp` 返回值从纯文本改为结构化 JSON** — 现在返回 `{ tools, resources }`,其中 tools 包含完整的 `inputSchema`(参数 JSON Schema),resources 包含 `uri`、`name`、`description`、`mimeType`。LLM 可获得精确的参数结构信息,不再需要靠描述文字猜测参数格式
|
|
8
|
+
- **`load_mcp` 不再返回 `prompts` 字段** — prompts 属于 UI 层用途,不对 Agent 暴露
|
|
9
|
+
- **`createLogger()` 替换为全局单例 `getLogger()` / `setLogger()`** — 日志不再支持多例,SDK 内部所有模块统一通过 `getLogger()` 获取同一实例
|
|
10
|
+
- **`index.ts` 导出变更** — `createLogger` → `getLogger` / `setLogger`
|
|
11
|
+
|
|
12
|
+
### 🎯 优化
|
|
13
|
+
|
|
14
|
+
- **`load_mcp` 连接成功后在日志中打印完整 manifest** — 包含 tools、resources、prompts 的完整 JSON,便于调试排查
|
|
15
|
+
- **SDK 内部日志统一** — `mcps.ts`、`skills.ts`、`usertools.ts`、`McpConnectionManager.ts` 中的 `console.warn`/`console.error` 全部改为 `getLogger().warn`/`getLogger().error`
|
|
16
|
+
|
|
3
17
|
## [0.3.4] - 2026-07-27
|
|
4
18
|
|
|
5
19
|
### 🎯 优化
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
|
+
import { getLogger } from "../../shared/logger.js";
|
|
2
3
|
/**
|
|
3
4
|
* 归一化原始 MCP server 配置为内部 McpServerConfig。
|
|
4
5
|
* 处理业界标准中的字段别名差异。
|
|
@@ -80,7 +81,7 @@ export async function discoverMcpServers(paths) {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
catch (err) {
|
|
83
|
-
|
|
84
|
+
getLogger().warn(`[sdk] 解析 MCP 配置失败: ${path} — ${err?.message ?? err}`);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
return items;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
const log =
|
|
3
|
+
import { getLogger } from "../../shared/logger.js";
|
|
4
|
+
const log = getLogger();
|
|
5
5
|
// ---- 发现(返回完整 SkillInfo,不再丢失 subAgent 等信息)----
|
|
6
6
|
/**
|
|
7
7
|
* 扫描多个目录中发现的所有 Skill(含 SKILL.md 的子目录)。
|
|
@@ -2,6 +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 "../../shared/logger.js";
|
|
5
6
|
/**
|
|
6
7
|
* 扫描多个 tools/ 目录,发现所有 .js / .mjs 文件,动态加载为 Tool 实例。
|
|
7
8
|
* 使用原生 dynamic import() 加载(在 "type": "module" 下 .js 也是 ESM),
|
|
@@ -73,7 +74,7 @@ async function loadToolFile(filepath, silent) {
|
|
|
73
74
|
}
|
|
74
75
|
catch (err) {
|
|
75
76
|
if (!silent) {
|
|
76
|
-
|
|
77
|
+
getLogger().error(`[usertools] 加载工具文件失败: ${filepath} — ${err?.message ?? err}`);
|
|
77
78
|
}
|
|
78
79
|
return null;
|
|
79
80
|
}
|
|
@@ -109,7 +110,7 @@ function normalizeToolExport(exported, filepath, silent) {
|
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
if (!silent) {
|
|
112
|
-
|
|
113
|
+
getLogger().error(`[usertools] 无法识别的工具格式: ${filepath}`);
|
|
113
114
|
}
|
|
114
115
|
return null;
|
|
115
116
|
}
|
|
@@ -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
|
@@ -36,6 +36,6 @@ export { sleepTool } from "./capabilities/implements/builtin/sleep.js";
|
|
|
36
36
|
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./capabilities/implements/skillTools.js";
|
|
37
37
|
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./capabilities/implements/mcpTools.js";
|
|
38
38
|
export { createSubAgentTool } from "./capabilities/implements/subAgentTools.js";
|
|
39
|
-
export {
|
|
39
|
+
export { getLogger, setLogger } from "./shared/logger.js";
|
|
40
40
|
export type { Logger, LogFunctions } from "./shared/logger.js";
|
|
41
41
|
export { SdkError } from "./shared/errors.js";
|
package/dist/index.js
CHANGED
|
@@ -34,5 +34,5 @@ export { createLoadSkillTool, createCallSkillSubAgentTool } from "./capabilities
|
|
|
34
34
|
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./capabilities/implements/mcpTools.js";
|
|
35
35
|
export { createSubAgentTool } from "./capabilities/implements/subAgentTools.js";
|
|
36
36
|
// 共享
|
|
37
|
-
export {
|
|
37
|
+
export { getLogger, setLogger } from "./shared/logger.js";
|
|
38
38
|
export { SdkError } from "./shared/errors.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DraftRepository } from "../crud/DraftRepository.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getLogger } from "../shared/logger.js";
|
|
3
3
|
import { promises as fs } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import dayjs from "dayjs";
|
|
6
|
-
const log =
|
|
6
|
+
const log = getLogger();
|
|
7
7
|
const CURRENT_DRAFT = "_current.json";
|
|
8
8
|
const EXPIRE_DAYS = 7;
|
|
9
9
|
/**
|
|
@@ -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" };
|
package/dist/shared/logger.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export interface LogFunctions {
|
|
|
5
5
|
}
|
|
6
6
|
export type Logger = LogFunctions;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* 获取全局 Logger 实例。
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function getLogger(): Logger;
|
|
11
|
+
/**
|
|
12
|
+
* 设置全局 Logger 实例,替换默认的 console 输出。
|
|
13
|
+
*/
|
|
14
|
+
export declare function setLogger(log: Logger): void;
|
package/dist/shared/logger.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
let currentLogger = {
|
|
2
|
+
info: console.log,
|
|
3
|
+
warn: console.warn,
|
|
4
|
+
error: console.error,
|
|
5
|
+
};
|
|
1
6
|
/**
|
|
2
|
-
*
|
|
7
|
+
* 获取全局 Logger 实例。
|
|
3
8
|
*/
|
|
4
|
-
export function
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
export function getLogger() {
|
|
10
|
+
return currentLogger;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 设置全局 Logger 实例,替换默认的 console 输出。
|
|
14
|
+
*/
|
|
15
|
+
export function setLogger(log) {
|
|
16
|
+
currentLogger = log;
|
|
10
17
|
}
|