@ai-zen/agents-sdk 0.9.0 → 0.9.2
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
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.2] - 2026-08-31
|
|
4
|
+
|
|
5
|
+
### 🎯 Optimized
|
|
6
|
+
|
|
7
|
+
- **默认 Agent 提示词重构(`DEFAULT_AGENT_DEFINITION`)** — 精简并统一风格:
|
|
8
|
+
- 人格设定调整为"幽默风趣、严谨可靠"
|
|
9
|
+
- 原有 8 条原则压缩为一条核心规则:遇到任何不明确、不确定、有矛盾或可能影响结果的状况,立即停下并直接询问用户,而不是自行脑补、猜测或硬干
|
|
10
|
+
- 新增"惜字如金"原则:只交代结果与必要说明,执行过程(工具调用、读写、搜索等)用户均已可见,不必再复述,以节省 token
|
|
11
|
+
- 保留护栏:主动调用工具、如实汇报、并只在你被指定的工作范围内行事
|
|
12
|
+
- 注入"当前操作系统"信息,动态使用 `process.platform`,适配不同平台
|
|
13
|
+
- **`ViewImageTool` 增加本地 URL 校验** — 新增 `isLocalUrl()`,拒绝 `file://` 协议及指向本机回环地址(`localhost`/`127.0.0.1`/`[::1]`/`0.0.0.0`)的 http(s) URL(API 服务商无法下载访问),在调用早期直接报错;`function.description` 与 `path_or_url` 参数说明同步补充"不支持本地 URL,本地图片请使用文件路径"
|
|
14
|
+
|
|
15
|
+
## [0.9.1] - 2026-08-28
|
|
16
|
+
|
|
17
|
+
### 🔧 Fixed
|
|
18
|
+
|
|
19
|
+
- **SDK-produced messages now always carry an `id`, aligned with core 4.1.0's required `Message.id`** — `TaskMigrationService.createPostMessages()` returns a `Message.User`, and the default agent / sub-agent definitions (`DEFAULT_AGENT_DEFINITION` / `DEFAULT_SUBAGENT_DEFINITION`) build their messages via `Message.System` / `Message.User`. This removes the last places where a bare object literal `{ role, content }` was assigned to `AgentNS.Message`, which would now fail to compile under core 4.1.0 (where `Message.id` is non-optional). Consumers no longer need to patch a missing `id` on SDK-generated messages (e.g. a desktop-side `ensureId` bridge)
|
|
20
|
+
- **No breaking change to public API** — only internal message construction was switched to the `Message` factory methods; exported types and method signatures are unchanged
|
|
21
|
+
|
|
22
|
+
### ✅ Tests
|
|
23
|
+
|
|
24
|
+
- SDK suite re-checked green against core 4.1.0 (`Message.id` required)
|
|
25
|
+
|
|
3
26
|
## [0.9.0] - 2026-08-28
|
|
4
27
|
|
|
5
28
|
### 🎯 Optimized
|
|
@@ -3,6 +3,16 @@ import { promises as fs } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { SdkCallbackTool } from "../../../runtime/SdkCallbackTool.js";
|
|
5
5
|
const SUPPORTED_EXT = [".jpg", ".jpeg", ".png", ".gif", ".webp"];
|
|
6
|
+
/**
|
|
7
|
+
* 是否为"本地 URL"——指向本地/回环地址,API 服务商无法下载访问。
|
|
8
|
+
* 覆盖 file:// 等本地协议,以及指向本机的 http(s) 地址(localhost、127.0.0.1、[::1]、0.0.0.0)。
|
|
9
|
+
*/
|
|
10
|
+
function isLocalUrl(value) {
|
|
11
|
+
if (/^file:\/\//i.test(value))
|
|
12
|
+
return true;
|
|
13
|
+
const m = value.match(/^https?:\/\/([^/?#]+)/i);
|
|
14
|
+
return !!m && /^(localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0)$/i.test(m[1]);
|
|
15
|
+
}
|
|
6
16
|
/**
|
|
7
17
|
* 查看图片工具 — 让 Agent 主动查看/分析一张图片。**仅对视觉模型可用**:
|
|
8
18
|
* 由 `isAvailable(config, definition)` 声明(从 definition.modelId 解析模型,检查 Model.vision),
|
|
@@ -24,13 +34,13 @@ export class ViewImageTool extends SdkCallbackTool {
|
|
|
24
34
|
}
|
|
25
35
|
function = {
|
|
26
36
|
name: "viewImage",
|
|
27
|
-
description: "查看一张图片并分析其内容。传入本地图片路径或 http(s) 图片 URL。本地图片会自动上传(Files API
|
|
37
|
+
description: "查看一张图片并分析其内容。传入本地图片路径或 http(s) 图片 URL。本地图片会自动上传(Files API)后引用,网络图片直接引用。不支持本地 URL(如 file:// 协议、指向本机 localhost/127.0.0.1 的 http(s) 地址),本地图片请使用文件路径。适合识别图片文字、描述图片内容、分析图表等。",
|
|
28
38
|
parameters: {
|
|
29
39
|
type: "object",
|
|
30
40
|
properties: {
|
|
31
41
|
path_or_url: {
|
|
32
42
|
type: "string",
|
|
33
|
-
description: "本地图片路径(相对/绝对)或 http(s) 图片 URL。支持的格式:JPEG、PNG、GIF、WebP
|
|
43
|
+
description: "本地图片路径(相对/绝对)或 http(s) 图片 URL。支持的格式:JPEG、PNG、GIF、WebP。不支持本地 URL(如 file:// 协议、指向本机 localhost/127.0.0.1 的 http(s) 地址),本地图片请使用文件路径。",
|
|
34
44
|
},
|
|
35
45
|
},
|
|
36
46
|
required: ["path_or_url"],
|
|
@@ -47,6 +57,10 @@ export class ViewImageTool extends SdkCallbackTool {
|
|
|
47
57
|
return "viewImage 需要提供 path_or_url 参数(本地图片路径或 http(s) URL)。";
|
|
48
58
|
}
|
|
49
59
|
const value = target.trim();
|
|
60
|
+
// 拒绝服务商无法访问的"本地 URL":file:// 等本地协议,或指向本机回环地址(localhost/127.0.0.1/[::1]/0.0.0.0)的 http(s) 地址
|
|
61
|
+
if (isLocalUrl(value)) {
|
|
62
|
+
return "不支持本地 URL(API 服务商无法下载访问)。本地图片请使用文件路径,而不是本地链接。";
|
|
63
|
+
}
|
|
50
64
|
try {
|
|
51
65
|
// 网络图片:直接返回 image_url 内容块(无需上传)
|
|
52
66
|
if (/^https?:\/\//i.test(value)) {
|
package/dist/config/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Message } from "@ai-zen/agents-core";
|
|
2
2
|
// ---------------------------------------------------------------------------
|
|
3
3
|
// 默认 Agent
|
|
4
4
|
// ---------------------------------------------------------------------------
|
|
@@ -10,17 +10,9 @@ export const DEFAULT_AGENT_DEFINITION = {
|
|
|
10
10
|
name: "默认助手",
|
|
11
11
|
description: "默认的 AI 助手,适用于日常问答和任务执行。",
|
|
12
12
|
messages: [
|
|
13
|
-
{
|
|
14
|
-
role: AgentNS.Role.System,
|
|
15
|
-
content: `你是一个严谨可靠的智能助手。请用中文回复,说话风格参照官方文件。
|
|
13
|
+
Message.System(`你是一个幽默风趣、严谨可靠的智能助手,请用中文回复。当前操作系统:${process.platform}。
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
- 实事求是 — 知之为知之,不知为不知,而不是凭空编造;如果用户意图不明确,应先提问澄清,而不是自行脑补
|
|
19
|
-
- 一切行动听指挥 — 严格遵循用户指令,而不是自作主张
|
|
20
|
-
- 安全第一 — 风险操作先告知确认,而不是盲目执行
|
|
21
|
-
- 能打胜仗 — 写优秀的代码,而不是只限于能用的代码
|
|
22
|
-
- 有矛盾就问 — 如果用户指令中存在自相矛盾之处,应指出矛盾并请求澄清,而不是自行取舍`,
|
|
23
|
-
},
|
|
15
|
+
惜字如金:只交代结果和必要说明,执行过程(工具调用、读写、搜索等)用户均已可见,不必再复述。遇到任何不明确、不确定、有矛盾或可能影响结果的状况,立即停下并直接询问用户,而不是自行脑补、猜测或硬干。除此之外,主动调用工具、如实汇报,并只在你被指定的工作范围内行事。`),
|
|
24
16
|
],
|
|
25
17
|
permissions: {
|
|
26
18
|
tools: { allow: ["*"] },
|
|
@@ -40,11 +32,8 @@ export const DEFAULT_SUBAGENT_DEFINITION = {
|
|
|
40
32
|
name: "通用助手",
|
|
41
33
|
description: "一个通用的子 Agent,擅长独立完成各类任务。",
|
|
42
34
|
messages: [
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
content: "你是一个通用助手子 Agent,被父 Agent 委派来独立完成具体任务。请根据给定的任务描述,主动调用你的工具(文件读写、执行命令、搜索等)来分析和完成任务。完成任务后直接返回结果,不需要解释你的思考过程。\n\n⚠️ 强制性要求:\n1. 如果任务描述中存在任何不明确、模糊或缺失的信息(包括但不限于具体目标、文件路径、约束条件、预期产出等),你必须直接拒绝执行,并明确列出哪些信息不明确或缺失,要求父 Agent 提供更完整的任务上下文。不得自行假设、猜测或脑补任何信息。\n2. 如果任务描述中存在自相矛盾的信息(如相互冲突的要求、不一致的文件路径、矛盾的约束条件等),你必须及时指出矛盾之处,并要求父 Agent 澄清后再执行。",
|
|
46
|
-
},
|
|
47
|
-
{ role: AgentNS.Role.User, content: "{{task}}" },
|
|
35
|
+
Message.System("你是一个通用助手子 Agent,被父 Agent 委派来独立完成具体任务。请根据给定的任务描述,主动调用你的工具(文件读写、执行命令、搜索等)来分析和完成任务。完成任务后直接返回结果,不需要解释你的思考过程。\n\n⚠️ 强制性要求:\n1. 如果任务描述中存在任何不明确、模糊或缺失的信息(包括但不限于具体目标、文件路径、约束条件、预期产出等),你必须直接拒绝执行,并明确列出哪些信息不明确或缺失,要求父 Agent 提供更完整的任务上下文。不得自行假设、猜测或脑补任何信息。\n2. 如果任务描述中存在自相矛盾的信息(如相互冲突的要求、不一致的文件路径、矛盾的约束条件等),你必须及时指出矛盾之处,并要求父 Agent 澄清后再执行。"),
|
|
36
|
+
Message.User("{{task}}"),
|
|
48
37
|
],
|
|
49
38
|
permissions: {
|
|
50
39
|
tools: { allow: ["*"] },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Message } from "@ai-zen/agents-core";
|
|
2
2
|
import { getLogger } from "../shared/logger.js";
|
|
3
3
|
/**
|
|
4
4
|
* 任务迁移服务。
|
|
@@ -83,7 +83,7 @@ export class TaskMigrationService {
|
|
|
83
83
|
"",
|
|
84
84
|
"请确认你已理解以上内容,然后询问用户接下来需要什么帮助。",
|
|
85
85
|
].join("\n");
|
|
86
|
-
return [
|
|
86
|
+
return [Message.User(content)];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* 序列化消息为 `[role]: content` 文本,供模型理解完整对话历史。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-zen/agents-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "AI-Zen Agents SDK — shared business logic for CLI and Desktop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
20
20
|
"dayjs": "^1.11.21",
|
|
21
21
|
"openai": "^7.5.0",
|
|
22
|
-
"@ai-zen/agents-core": "^4.
|
|
22
|
+
"@ai-zen/agents-core": "^4.1.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^24.12.2",
|