@ai-zen/agents-sdk 1.0.0-alpha.3 → 1.0.0-alpha.6
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 +44 -0
- package/README.md +10 -10
- package/README.zh.md +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/scope/plugins/builtin/BatchEditTool.js +1 -1
- package/dist/scope/plugins/builtin/DownloadFileTool.js +1 -1
- package/dist/scope/plugins/builtin/ExecTool.js +2 -2
- package/dist/scope/plugins/builtin/FindTextTool.js +6 -6
- package/dist/scope/plugins/builtin/GenerateImageTool.d.ts +1 -1
- package/dist/scope/plugins/builtin/GenerateImageTool.js +6 -6
- package/dist/scope/plugins/builtin/GlobTool.js +1 -1
- package/dist/scope/plugins/builtin/InspectFileTool.d.ts +2 -2
- package/dist/scope/plugins/builtin/InspectFileTool.js +5 -5
- package/dist/scope/plugins/builtin/LsTool.js +1 -1
- package/dist/scope/plugins/builtin/{ReadFileTool.d.ts → ReadTool.d.ts} +1 -1
- package/dist/scope/plugins/builtin/{ReadFileTool.js → ReadTool.js} +3 -3
- package/dist/scope/plugins/builtin/{ExecAsyncTool.d.ts → SpawnTool.d.ts} +1 -1
- package/dist/scope/plugins/builtin/{ExecAsyncTool.js → SpawnTool.js} +2 -2
- package/dist/scope/plugins/builtin/ViewImageTool.js +2 -2
- package/dist/scope/plugins/builtin/{WriteFileTool.d.ts → WriteTool.d.ts} +1 -1
- package/dist/scope/plugins/builtin/{WriteFileTool.js → WriteTool.js} +2 -2
- package/dist/scope/plugins/builtin/index.d.ts +4 -4
- package/dist/scope/plugins/builtin/index.js +7 -7
- package/dist/scope/plugins/builtin/outputGuard.d.ts +2 -2
- package/dist/scope/plugins/builtin/outputGuard.js +1 -1
- package/dist/types/index.d.ts +3 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.0-alpha.6] - 2026-10-13
|
|
4
|
+
|
|
5
|
+
### 💥 Breaking Changes
|
|
6
|
+
|
|
7
|
+
- **`exec_async` renamed to `spawn`** — the tool wraps `child_process.spawn` and returns `{ success, pid, message }`, so the new name matches both the implementation and the "start a process, get its pid" contract. It also pairs cleanly with `exec`: `exec` runs and **waits** (captures output, has a `timeout`), `spawn` starts and **returns immediately**. Permission lists, skill `allowed-tools` and any prompt naming `exec_async` must switch to `spawn`. The behaviour is otherwise unchanged — still shell-parsed, still does **not** capture output (redirect to a file if you need it).
|
|
8
|
+
- **Built-in tool classes renamed to match their new tool names** — `ReadFileTool` → `ReadTool`, `WriteFileTool` → `WriteTool`, `ExecAsyncTool` → `SpawnTool`, with the source files renamed to match. The classes re-exported from `@ai-zen/agents-sdk` change accordingly, so consumers importing them by name must update.
|
|
9
|
+
|
|
10
|
+
## [1.0.0-alpha.5] - 2026-10-13
|
|
11
|
+
|
|
12
|
+
### 💥 Breaking Changes
|
|
13
|
+
|
|
14
|
+
- **All built-in tool names unified on `snake_case`** — the multi-word tools that used camelCase were renamed. A tool name is the API contract the model sees and is matched **verbatim** by the permission system, so any `permissions.allow` / `deny` list, skill `allowed-tools` entry or prompt that names a tool must be updated:
|
|
15
|
+
|
|
16
|
+
| old | new |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `readFile` | `read` |
|
|
19
|
+
| `writeFile` | `write` |
|
|
20
|
+
| `inspectFile` | `inspect_file` |
|
|
21
|
+
| `findText` | `find_text` |
|
|
22
|
+
| `batchEdit` | `batch_edit` |
|
|
23
|
+
| `downloadFile` | `download_file` |
|
|
24
|
+
| `generateImage` | `generate_image` |
|
|
25
|
+
| `viewImage` | `view_image` |
|
|
26
|
+
|
|
27
|
+
Single-word tools (`cwd`, `edit`, `glob`, `ls`, `mkdir`, `rm`, `rename`, `copy`, `exec`, `exist`, `sleep`), the already-`snake_case` `exec_async`, the MCP / skill wrapper tools and core's `indexed_search` are unchanged. Tool descriptions and docs were updated in the same pass.
|
|
28
|
+
|
|
29
|
+
### 🔧 Changed
|
|
30
|
+
|
|
31
|
+
- **Dependency `@ai-zen/agents-core` bumped to `^4.3.2`** (carries the `indexedSearch` → `indexed_search` rename).
|
|
32
|
+
|
|
33
|
+
### 📄 Docs
|
|
34
|
+
|
|
35
|
+
- Current-version references in `docs/zh` and `docs/en` updated to `1.0.0-alpha.5`.
|
|
36
|
+
|
|
37
|
+
## [1.0.0-alpha.4] - 2026-10-13
|
|
38
|
+
|
|
39
|
+
### 🔧 Changed
|
|
40
|
+
|
|
41
|
+
- **Dependency `@ai-zen/agents-core` bumped to `^4.3.1`** (declared as `workspace:^`, expanded to `^4.3.1` at publish time). Pulls in core 4.3.1's fix for interrupted parallel tool rounds — the assistant message carrying `tool_calls` and its results now stay all-in or all-out, so an interrupted parallel tool call no longer leaves orphan `tool` results that the server rejects. `AgentContext` gains `abortedToolRoundStrategy` (default `"fill"`) and `abortedToolRoundReason`; set `agent.abortedToolRoundStrategy = "drop"` to drop the whole round instead
|
|
42
|
+
|
|
43
|
+
### 📄 Docs
|
|
44
|
+
|
|
45
|
+
- Current-version references in `docs/zh` and `docs/en` updated to `1.0.0-alpha.4`.
|
|
46
|
+
|
|
3
47
|
## [1.0.0-alpha.3] - 2026-10-03
|
|
4
48
|
|
|
5
49
|
### 🔧 Fixed
|
package/README.md
CHANGED
|
@@ -97,21 +97,21 @@ All built-in tools are classes (extending `SdkCallbackTool`), instantiated by th
|
|
|
97
97
|
| Tool | Description |
|
|
98
98
|
|------|-------------|
|
|
99
99
|
| `cwd` | Get the current working directory |
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
100
|
+
| `read` | Read a file (optional `range` for line/column slicing; oversized output warns and suggests batched reads) |
|
|
101
|
+
| `inspect_file` | Inspect a file's structural overview (line count, column distribution, etc.); streamed scan, not limited by the 300KB read threshold |
|
|
102
|
+
| `write` | Write a file |
|
|
103
103
|
| `exec` | Execute a command (supports `timeout`; oversized stdout+stderr is dumped to `stdout.log` / `stderr.log`) |
|
|
104
|
-
| `
|
|
104
|
+
| `spawn` | Execute a command asynchronously, returns immediately without waiting |
|
|
105
105
|
| `mkdir` | Create a directory |
|
|
106
106
|
| `rm` | Delete a file or directory |
|
|
107
107
|
| `glob` | Scan and find files using glob patterns (oversized output dumped to `result.json`) |
|
|
108
108
|
| `ls` | List directory contents (oversized output dumped to `result.json`) |
|
|
109
109
|
| `exist` | Check whether a file or directory exists |
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
110
|
+
| `find_text` | Search for text or regex in files (oversized output dumped to `result.json`) |
|
|
111
|
+
| `download_file` | Download a file from a URL and save it locally |
|
|
112
112
|
| `rename` | Rename or move a file/directory |
|
|
113
113
|
| `copy` | Copy a file or directory |
|
|
114
|
-
| `
|
|
114
|
+
| `batch_edit` | Batch-edit file text (only unmatched items are echoed back; successful ones are counted) |
|
|
115
115
|
| `edit` | Edit text in a file |
|
|
116
116
|
| `sleep` | Wait for a specified number of milliseconds |
|
|
117
117
|
|
|
@@ -119,10 +119,10 @@ Conditionally injected based on the active model / config:
|
|
|
119
119
|
|
|
120
120
|
| Tool | Injection Condition | Description |
|
|
121
121
|
|------|---------------------|-------------|
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
122
|
+
| `generate_image` | Only when `defaultImageModel` is configured | Generate an image from a text description |
|
|
123
|
+
| `view_image` | Only for vision models (the agent's `modelId` resolves to a model with `vision: true`) | View / analyze an image: local images are auto-uploaded via the Files API, network URLs are referenced directly |
|
|
124
124
|
|
|
125
|
-
Tool output protection: `AppConfig.maxToolOutput` (in characters, default 32768) is the unified ceiling for tool output. Each tool handles overflow itself — `exec` dumps `stdout.log` / `stderr.log` separately (returning head/tail previews per stream), `
|
|
125
|
+
Tool output protection: `AppConfig.maxToolOutput` (in characters, default 32768) is the unified ceiling for tool output. Each tool handles overflow itself — `exec` dumps `stdout.log` / `stderr.log` separately (returning head/tail previews per stream), `find_text` / `glob` / `ls` dump `result.json` (returning a head preview), and `read` only warns and suggests batched reads via `range`. Dumps go to `<tmpdir>/ai-zen/tool-output/<tool>-<timestamp>-<random>/`, one directory per call, with no self-cleanup. See [`docs/sdk-design-v1.md` §12](docs/sdk-design-v1.md).
|
|
126
126
|
|
|
127
127
|
## Built-in Plugins
|
|
128
128
|
|
package/README.zh.md
CHANGED
|
@@ -96,21 +96,21 @@ await scope.dispose(); // 断开 MCP、释放插件资源
|
|
|
96
96
|
| 工具 | 说明 |
|
|
97
97
|
|------|------|
|
|
98
98
|
| `cwd` | 获取当前工作目录 |
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
99
|
+
| `read` | 读取文件(可选 `range` 按行列范围读取;输出超限仅警告并提示用 `range` 分批) |
|
|
100
|
+
| `inspect_file` | 勘察文件结构概况(行数、列数分布等),流式扫描不受 300KB 限制 |
|
|
101
|
+
| `write` | 写入文件 |
|
|
102
102
|
| `exec` | 执行命令(支持 `timeout` 超时参数;stdout+stderr 超限时分文件落盘 `stdout.log` / `stderr.log`) |
|
|
103
|
-
| `
|
|
103
|
+
| `spawn` | 异步执行命令,启动后立即返回,不等待结果 |
|
|
104
104
|
| `mkdir` | 创建目录 |
|
|
105
105
|
| `rm` | 删除文件或目录 |
|
|
106
106
|
| `glob` | 使用 glob 模式扫描查找文件(输出超限落盘 `result.json`) |
|
|
107
107
|
| `ls` | 列出目录内容(输出超限落盘 `result.json`) |
|
|
108
108
|
| `exist` | 检查文件或目录是否存在 |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
109
|
+
| `find_text` | 在文件中搜索文本或正则(输出超限落盘 `result.json`) |
|
|
110
|
+
| `download_file` | 从 URL 下载文件并保存到本地 |
|
|
111
111
|
| `rename` | 重命名或移动文件/目录 |
|
|
112
112
|
| `copy` | 复制文件或目录 |
|
|
113
|
-
| `
|
|
113
|
+
| `batch_edit` | 批量编辑文件文本(仅回显未匹配项,成功项只计数) |
|
|
114
114
|
| `edit` | 编辑文件中的文本 |
|
|
115
115
|
| `sleep` | 等待指定毫秒数后继续 |
|
|
116
116
|
|
|
@@ -118,10 +118,10 @@ await scope.dispose(); // 断开 MCP、释放插件资源
|
|
|
118
118
|
|
|
119
119
|
| 工具 | 注入条件 | 说明 |
|
|
120
120
|
|------|----------|------|
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
121
|
+
| `generate_image` | 配置了 `defaultImageModel` 才注册 | 根据文字描述生成图片 |
|
|
122
|
+
| `view_image` | 仅视觉模型可用(Agent 的 `modelId` 解析为 `vision: true` 的模型) | 查看/分析图片:本地图片自动经 Files API 上传,网络 URL 直接引用 |
|
|
123
123
|
|
|
124
|
-
工具输出保护:`AppConfig.maxToolOutput`(字符数,缺省 32768)是工具输出的统一上限,超限时由各工具自行处置——`exec` 分文件落盘 `stdout.log` / `stderr.log`(返回各流头尾预览),`
|
|
124
|
+
工具输出保护:`AppConfig.maxToolOutput`(字符数,缺省 32768)是工具输出的统一上限,超限时由各工具自行处置——`exec` 分文件落盘 `stdout.log` / `stderr.log`(返回各流头尾预览),`find_text` / `glob` / `ls` 落盘 `result.json`(返回头部预览),`read` 仅警告并提示用 `range` 分批读取。落盘目录为 `<tmpdir>/ai-zen/tool-output/<工具名>-<时间戳>-<随机串>/`,每次调用独立、不自清理。详见 [`docs/sdk-design-v1.md` §12](docs/sdk-design-v1.md)。
|
|
125
125
|
|
|
126
126
|
## 内置插件
|
|
127
127
|
|
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
|
39
39
|
export type { ContextGuardOptions } from "./agent-plugins/ContextGuardPlugin.js";
|
|
40
40
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
41
41
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
42
|
-
export { CwdTool,
|
|
42
|
+
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, } from "./scope/plugins/builtin/index.js";
|
|
43
43
|
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
|
44
44
|
export { ViewImageTool } from "./scope/plugins/builtin/ViewImageTool.js";
|
|
45
45
|
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./scope/plugins/skills/skillTools.js";
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
|
34
34
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
35
35
|
// 工具 — 内置工具类 + 动态工具工厂
|
|
36
36
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
37
|
-
export { CwdTool,
|
|
37
|
+
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, } from "./scope/plugins/builtin/index.js";
|
|
38
38
|
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
|
39
39
|
export { ViewImageTool } from "./scope/plugins/builtin/ViewImageTool.js";
|
|
40
40
|
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./scope/plugins/skills/skillTools.js";
|
|
@@ -2,7 +2,7 @@ import * as fsp from "fs/promises";
|
|
|
2
2
|
import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
3
3
|
export class BatchEditTool extends SdkCallbackTool {
|
|
4
4
|
function = {
|
|
5
|
-
name: "
|
|
5
|
+
name: "batch_edit",
|
|
6
6
|
description: "批量编辑文件文本,可以优先使用这个工具对文件进行编辑",
|
|
7
7
|
parameters: {
|
|
8
8
|
type: "object",
|
|
@@ -3,7 +3,7 @@ import * as path from "path";
|
|
|
3
3
|
import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
4
4
|
export class DownloadFileTool extends SdkCallbackTool {
|
|
5
5
|
function = {
|
|
6
|
-
name: "
|
|
6
|
+
name: "download_file",
|
|
7
7
|
description: "从 URL 下载文件(图片、PDF 等二进制文件)并保存到本地磁盘。自动从 URL 推断文件名,也可指定保存路径。",
|
|
8
8
|
parameters: {
|
|
9
9
|
type: "object",
|
|
@@ -14,7 +14,7 @@ export class ExecTool extends SdkCallbackTool {
|
|
|
14
14
|
},
|
|
15
15
|
timeout: {
|
|
16
16
|
type: "number",
|
|
17
|
-
description: "超时时间(毫秒),必填。超时后会终止进程;超过该时长仍未完成即视为超时并终止。建议长时间运行的命令使用
|
|
17
|
+
description: "超时时间(毫秒),必填。超时后会终止进程;超过该时长仍未完成即视为超时并终止。建议长时间运行的命令使用 spawn 异步执行。",
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
required: ["command", "timeout"],
|
|
@@ -98,7 +98,7 @@ export class ExecTool extends SdkCallbackTool {
|
|
|
98
98
|
return JSON.stringify({
|
|
99
99
|
outputTooLarge: true,
|
|
100
100
|
warning: `输出过大:stdout + stderr 合计 ${result.stdout.length + result.stderr.length} 字符,` +
|
|
101
|
-
`超过上限 ${limit} 字符。完整内容已分文件落盘(stdout.log / stderr.log),可用
|
|
101
|
+
`超过上限 ${limit} 字符。完整内容已分文件落盘(stdout.log / stderr.log),可用 read 分批读取。`,
|
|
102
102
|
files: ctx.files,
|
|
103
103
|
stdout: { chars: result.stdout.length, lines: countLines(result.stdout), ...stdout },
|
|
104
104
|
stderr: { chars: result.stderr.length, lines: countLines(result.stderr), ...stderr },
|
|
@@ -4,13 +4,13 @@ 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;
|
|
7
|
-
/** 默认文件大小上限(字节,与
|
|
7
|
+
/** 默认文件大小上限(字节,与 ReadTool 的 300KB 口径一致) */
|
|
8
8
|
const DEFAULT_MAX_FILE_SIZE = 300 * 1024;
|
|
9
9
|
/** 默认行内容/匹配子串截断长度 */
|
|
10
10
|
const DEFAULT_MAX_LINE_LENGTH = 200;
|
|
11
11
|
export class FindTextTool extends SdkCallbackTool {
|
|
12
12
|
function = {
|
|
13
|
-
name: "
|
|
13
|
+
name: "find_text",
|
|
14
14
|
description: "查找文本出现的位置,支持普通文本或正则匹配,返回文件名及具体行号、行内容。为避免结果撑爆上下文,默认限制总匹配数、单文件大小与行内容长度,超限会截断并标记 truncated。",
|
|
15
15
|
parameters: {
|
|
16
16
|
type: "object",
|
|
@@ -89,12 +89,12 @@ export class FindTextTool extends SdkCallbackTool {
|
|
|
89
89
|
break; // 中断:stat 后再次检查
|
|
90
90
|
if (!stats.isFile())
|
|
91
91
|
continue;
|
|
92
|
-
// 文件过大则跳过(避免撑爆上下文;与
|
|
92
|
+
// 文件过大则跳过(避免撑爆上下文;与 ReadTool 300KB 口径一致,但此处为跳过而非报错)
|
|
93
93
|
if (stats.size > maxFileSize)
|
|
94
94
|
continue;
|
|
95
95
|
const content = await fsp.readFile(fullPath, "utf-8");
|
|
96
96
|
if (signal?.aborted)
|
|
97
|
-
break; // 中断:
|
|
97
|
+
break; // 中断:read 后再次检查
|
|
98
98
|
const lines = content.split("\n");
|
|
99
99
|
const matches = [];
|
|
100
100
|
for (let index = 0; index < lines.length; index++) {
|
|
@@ -145,7 +145,7 @@ export class FindTextTool extends SdkCallbackTool {
|
|
|
145
145
|
async protect(json) {
|
|
146
146
|
const limit = this.env.config.maxToolOutput ?? DEFAULT_MAX_TOOL_OUTPUT;
|
|
147
147
|
return await guardOutput({
|
|
148
|
-
tool: "
|
|
148
|
+
tool: "find_text",
|
|
149
149
|
content: json,
|
|
150
150
|
isOverLimit: (text) => text.length > limit,
|
|
151
151
|
dump: (_dir, text) => [{ name: "result.json", content: text }],
|
|
@@ -154,7 +154,7 @@ export class FindTextTool extends SdkCallbackTool {
|
|
|
154
154
|
return JSON.stringify({
|
|
155
155
|
outputTooLarge: true,
|
|
156
156
|
warning: `输出过大:结果共 ${json.length} 字符,超过上限 ${limit} 字符。` +
|
|
157
|
-
`完整结果已落盘(result.json),可用
|
|
157
|
+
`完整结果已落盘(result.json),可用 read 分批读取。`,
|
|
158
158
|
files: ctx.files,
|
|
159
159
|
chars: json.length,
|
|
160
160
|
...preview,
|
|
@@ -4,7 +4,7 @@ import type { AgentDefinition, AppConfig, ToolEnv } from "../../../types/index.j
|
|
|
4
4
|
/**
|
|
5
5
|
* 根据文字描述生成图片。**统一返回字符串**(JSON,含图片 URL 列表):
|
|
6
6
|
* 生成结果如何处理(查看/下载/转发)由模型与上层自由决定——
|
|
7
|
-
* 需要让模型看图时,模型可主动调用
|
|
7
|
+
* 需要让模型看图时,模型可主动调用 view_image(URL);需要保存时用 download_file。
|
|
8
8
|
*
|
|
9
9
|
* 依赖 AppConfig 中的 imageModels 和 defaultImageModel 配置(isAvailable 声明),
|
|
10
10
|
* 未配置时由 buildTools 过滤,不暴露给 Agent。
|
|
@@ -3,7 +3,7 @@ import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* 根据文字描述生成图片。**统一返回字符串**(JSON,含图片 URL 列表):
|
|
5
5
|
* 生成结果如何处理(查看/下载/转发)由模型与上层自由决定——
|
|
6
|
-
* 需要让模型看图时,模型可主动调用
|
|
6
|
+
* 需要让模型看图时,模型可主动调用 view_image(URL);需要保存时用 download_file。
|
|
7
7
|
*
|
|
8
8
|
* 依赖 AppConfig 中的 imageModels 和 defaultImageModel 配置(isAvailable 声明),
|
|
9
9
|
* 未配置时由 buildTools 过滤,不暴露给 Agent。
|
|
@@ -14,8 +14,8 @@ export class GenerateImageTool extends SdkCallbackTool {
|
|
|
14
14
|
return !!config.defaultImageModel;
|
|
15
15
|
}
|
|
16
16
|
function = {
|
|
17
|
-
name: "
|
|
18
|
-
description: "根据文字描述生成图片,返回图片 URL 列表(JSON)。如需查看图片内容,请用
|
|
17
|
+
name: "generate_image",
|
|
18
|
+
description: "根据文字描述生成图片,返回图片 URL 列表(JSON)。如需查看图片内容,请用 view_image 工具(传入图片 URL);如需保存到本地,用 download_file 下载。",
|
|
19
19
|
parameters: {
|
|
20
20
|
type: "object",
|
|
21
21
|
properties: {
|
|
@@ -99,15 +99,15 @@ export class GenerateImageTool extends SdkCallbackTool {
|
|
|
99
99
|
.map((img) => img.url)
|
|
100
100
|
.filter((url) => !!url);
|
|
101
101
|
// 统一返回字符串(JSON):生成结果如何处理(查看/下载/转发)由模型与上层自由决定,
|
|
102
|
-
// 不替模型做「看或不看」的假设。需要让模型看图 → 模型可主动调用
|
|
103
|
-
// 需要保存 →
|
|
102
|
+
// 不替模型做「看或不看」的假设。需要让模型看图 → 模型可主动调用 view_image(URL);
|
|
103
|
+
// 需要保存 → download_file 下载。
|
|
104
104
|
return JSON.stringify({
|
|
105
105
|
success: true,
|
|
106
106
|
model: imageModel.name,
|
|
107
107
|
modelId: imageModel.id,
|
|
108
108
|
created: result.created,
|
|
109
109
|
images: urls.map((url, i) => ({ index: i, url })),
|
|
110
|
-
note: "图片临时链接有效期为30天。如需查看图片内容,可用
|
|
110
|
+
note: "图片临时链接有效期为30天。如需查看图片内容,可用 view_image 工具(传入图片 URL);如需保存,可用 download_file 下载。",
|
|
111
111
|
}, null, 2);
|
|
112
112
|
}
|
|
113
113
|
catch (error) {
|
|
@@ -69,7 +69,7 @@ export class GlobTool extends SdkCallbackTool {
|
|
|
69
69
|
return JSON.stringify({
|
|
70
70
|
outputTooLarge: true,
|
|
71
71
|
warning: `输出过大:匹配结果共 ${json.length} 字符,超过上限 ${limit} 字符。` +
|
|
72
|
-
`完整结果已落盘(result.json),可用
|
|
72
|
+
`完整结果已落盘(result.json),可用 read 分批读取;` +
|
|
73
73
|
`也可用更精确的 pattern 或 exclude 缩小范围后重新查找。`,
|
|
74
74
|
files: ctx.files,
|
|
75
75
|
chars: json.length,
|
|
@@ -4,8 +4,8 @@ import type { AgentNS } from "@ai-zen/agents-core";
|
|
|
4
4
|
/**
|
|
5
5
|
* 勘察文件结构概况(行数、每行列数等),不做内容读取。
|
|
6
6
|
*
|
|
7
|
-
* 定位与
|
|
8
|
-
* 再决定
|
|
7
|
+
* 定位与 read 的 range 配套:大文件先看结构(有多少行、每行多长),
|
|
8
|
+
* 再决定 read 的读取范围。流式扫描,故不受 read 的 300KB 读取阈值限制。
|
|
9
9
|
*/
|
|
10
10
|
export declare class InspectFileTool extends SdkCallbackTool {
|
|
11
11
|
function: AgentNS.FunctionDefine;
|
|
@@ -6,13 +6,13 @@ import { DEFAULT_MAX_TOOL_OUTPUT } from "./outputGuard.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* 勘察文件结构概况(行数、每行列数等),不做内容读取。
|
|
8
8
|
*
|
|
9
|
-
* 定位与
|
|
10
|
-
* 再决定
|
|
9
|
+
* 定位与 read 的 range 配套:大文件先看结构(有多少行、每行多长),
|
|
10
|
+
* 再决定 read 的读取范围。流式扫描,故不受 read 的 300KB 读取阈值限制。
|
|
11
11
|
*/
|
|
12
12
|
export class InspectFileTool extends SdkCallbackTool {
|
|
13
13
|
function = {
|
|
14
|
-
name: "
|
|
15
|
-
description: "勘察文件的结构概况:总行数、总字符数、最长行的列数及其行索引、平均列数、行尾类型(LF/CRLF)。可选返回每行的列数映射。适用于在
|
|
14
|
+
name: "inspect_file",
|
|
15
|
+
description: "勘察文件的结构概况:总行数、总字符数、最长行的列数及其行索引、平均列数、行尾类型(LF/CRLF)。可选返回每行的列数映射。适用于在 read 之前先了解文件规模,再决定用 range 读取哪一段。仅做流式扫描,不受 read 的 300KB 读取阈值限制。",
|
|
16
16
|
parameters: {
|
|
17
17
|
type: "object",
|
|
18
18
|
properties: {
|
|
@@ -63,7 +63,7 @@ export class InspectFileTool extends SdkCallbackTool {
|
|
|
63
63
|
colCountMapOmitted: true,
|
|
64
64
|
warning: `行长度明细过大:概况与 colCountMap 合计 ${payload.length} 字符,` +
|
|
65
65
|
`超过上限 ${limit} 字符,未落盘返回。文件规模超出可处理范围,` +
|
|
66
|
-
`建议改用
|
|
66
|
+
`建议改用 find_text 定位后再按 range 分段读取。`,
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
return payload;
|
|
@@ -36,7 +36,7 @@ export class LsTool extends SdkCallbackTool {
|
|
|
36
36
|
return JSON.stringify({
|
|
37
37
|
outputTooLarge: true,
|
|
38
38
|
warning: `输出过大:目录条目共 ${entries.length} 项、${json.length} 字符,超过上限 ${limit} 字符。` +
|
|
39
|
-
`完整列表已落盘(result.json),可用
|
|
39
|
+
`完整列表已落盘(result.json),可用 read 分批读取;` +
|
|
40
40
|
`也可改用 glob 按模式筛选。`,
|
|
41
41
|
files: ctx.files,
|
|
42
42
|
chars: json.length,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
-
export declare class
|
|
4
|
+
export declare class ReadTool extends SdkCallbackTool {
|
|
5
5
|
function: AgentNS.FunctionDefine;
|
|
6
6
|
constructor(env: ToolEnv);
|
|
7
7
|
call(input: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as fsp from "fs/promises";
|
|
2
2
|
import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
3
3
|
import { DEFAULT_MAX_TOOL_OUTPUT, guardOutput } from "./outputGuard.js";
|
|
4
|
-
export class
|
|
4
|
+
export class ReadTool extends SdkCallbackTool {
|
|
5
5
|
function = {
|
|
6
|
-
name: "
|
|
6
|
+
name: "read",
|
|
7
7
|
description: "读取文件",
|
|
8
8
|
parameters: {
|
|
9
9
|
type: "object",
|
|
@@ -41,7 +41,7 @@ export class ReadFileTool extends SdkCallbackTool {
|
|
|
41
41
|
// 输出保护:本次返回内容超过上限时只警告、不落盘,并提示用 range 分批读取
|
|
42
42
|
const limit = this.env.config.maxToolOutput ?? DEFAULT_MAX_TOOL_OUTPUT;
|
|
43
43
|
return await guardOutput({
|
|
44
|
-
tool: "
|
|
44
|
+
tool: "read",
|
|
45
45
|
content: output,
|
|
46
46
|
isOverLimit: (text) => text.length > limit,
|
|
47
47
|
buildWarning: () => `读取内容过大:本次输出 ${output.length} 字符,超过上限 ${limit} 字符,未落盘。` +
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
-
export declare class
|
|
4
|
+
export declare class SpawnTool extends SdkCallbackTool {
|
|
5
5
|
function: AgentNS.FunctionDefine;
|
|
6
6
|
constructor(env: ToolEnv);
|
|
7
7
|
call(input: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
2
|
import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
3
|
-
export class
|
|
3
|
+
export class SpawnTool extends SdkCallbackTool {
|
|
4
4
|
function = {
|
|
5
|
-
name: "
|
|
5
|
+
name: "spawn",
|
|
6
6
|
description: "异步执行命令,启动程序后立即返回,不等待执行结果。适用于启动长期运行的进程(如服务器、监听程序、GUI应用等)或不需要等待结果的命令。注意:该工具本身不捕获命令的输出;若需获取/留存输出,可在命令中使用 shell 重定向写入文件(如 `> /path/file`,支持 `>>` 追加、`|` 管道)。命令经 shell 解析执行。",
|
|
7
7
|
parameters: {
|
|
8
8
|
type: "object",
|
|
@@ -33,7 +33,7 @@ export class ViewImageTool extends SdkCallbackTool {
|
|
|
33
33
|
return model?.vision === true;
|
|
34
34
|
}
|
|
35
35
|
function = {
|
|
36
|
-
name: "
|
|
36
|
+
name: "view_image",
|
|
37
37
|
description: "查看一张图片并分析其内容。传入本地图片路径或 http(s) 图片 URL。本地图片会自动上传(Files API)后引用,网络图片直接引用。不支持本地 URL(如 file:// 协议、指向本机 localhost/127.0.0.1 的 http(s) 地址),本地图片请使用文件路径。适合识别图片文字、描述图片内容、分析图表等。",
|
|
38
38
|
parameters: {
|
|
39
39
|
type: "object",
|
|
@@ -54,7 +54,7 @@ export class ViewImageTool extends SdkCallbackTool {
|
|
|
54
54
|
const signal = ctx?.signal;
|
|
55
55
|
const target = input?.path_or_url;
|
|
56
56
|
if (!target || !target.trim()) {
|
|
57
|
-
return "
|
|
57
|
+
return "view_image 需要提供 path_or_url 参数(本地图片路径或 http(s) URL)。";
|
|
58
58
|
}
|
|
59
59
|
const value = target.trim();
|
|
60
60
|
// 拒绝服务商无法访问的"本地 URL":file:// 等本地协议,或指向本机回环地址(localhost/127.0.0.1/[::1]/0.0.0.0)的 http(s) 地址
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
-
export declare class
|
|
4
|
+
export declare class WriteTool extends SdkCallbackTool {
|
|
5
5
|
function: AgentNS.FunctionDefine;
|
|
6
6
|
constructor(env: ToolEnv);
|
|
7
7
|
call(input: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as fsp from "fs/promises";
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
4
|
-
export class
|
|
4
|
+
export class WriteTool extends SdkCallbackTool {
|
|
5
5
|
function = {
|
|
6
|
-
name: "
|
|
6
|
+
name: "write",
|
|
7
7
|
description: "写入文件",
|
|
8
8
|
parameters: {
|
|
9
9
|
type: "object",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SdkCallbackTool } from "./SdkCallbackTool.js";
|
|
2
2
|
import type { ToolEnv } from "../../../types/index.js";
|
|
3
3
|
import { CwdTool } from "./CwdTool.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ReadTool } from "./ReadTool.js";
|
|
5
5
|
import { InspectFileTool } from "./InspectFileTool.js";
|
|
6
|
-
import {
|
|
6
|
+
import { WriteTool } from "./WriteTool.js";
|
|
7
7
|
import { ExecTool } from "./ExecTool.js";
|
|
8
8
|
import { MkdirTool } from "./MkdirTool.js";
|
|
9
9
|
import { RmTool } from "./RmTool.js";
|
|
@@ -16,7 +16,7 @@ import { RenameTool } from "./RenameTool.js";
|
|
|
16
16
|
import { CopyTool } from "./CopyTool.js";
|
|
17
17
|
import { BatchEditTool } from "./BatchEditTool.js";
|
|
18
18
|
import { EditTool } from "./EditTool.js";
|
|
19
|
-
import {
|
|
19
|
+
import { SpawnTool } from "./SpawnTool.js";
|
|
20
20
|
import { SleepTool } from "./SleepTool.js";
|
|
21
21
|
import { ViewImageTool } from "./ViewImageTool.js";
|
|
22
22
|
import { GenerateImageTool } from "./GenerateImageTool.js";
|
|
@@ -29,4 +29,4 @@ import { GenerateImageTool } from "./GenerateImageTool.js";
|
|
|
29
29
|
* 如 GenerateImageTool 依赖 defaultImageModel、ViewImageTool 仅视觉模型可用。
|
|
30
30
|
*/
|
|
31
31
|
export declare const BUILTIN_TOOL_CLASSES: Array<new (env: ToolEnv) => SdkCallbackTool>;
|
|
32
|
-
export { CwdTool,
|
|
32
|
+
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, ViewImageTool, GenerateImageTool, };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CwdTool } from "./CwdTool.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReadTool } from "./ReadTool.js";
|
|
3
3
|
import { InspectFileTool } from "./InspectFileTool.js";
|
|
4
|
-
import {
|
|
4
|
+
import { WriteTool } from "./WriteTool.js";
|
|
5
5
|
import { ExecTool } from "./ExecTool.js";
|
|
6
6
|
import { MkdirTool } from "./MkdirTool.js";
|
|
7
7
|
import { RmTool } from "./RmTool.js";
|
|
@@ -14,7 +14,7 @@ import { RenameTool } from "./RenameTool.js";
|
|
|
14
14
|
import { CopyTool } from "./CopyTool.js";
|
|
15
15
|
import { BatchEditTool } from "./BatchEditTool.js";
|
|
16
16
|
import { EditTool } from "./EditTool.js";
|
|
17
|
-
import {
|
|
17
|
+
import { SpawnTool } from "./SpawnTool.js";
|
|
18
18
|
import { SleepTool } from "./SleepTool.js";
|
|
19
19
|
import { ViewImageTool } from "./ViewImageTool.js";
|
|
20
20
|
import { GenerateImageTool } from "./GenerateImageTool.js";
|
|
@@ -28,9 +28,9 @@ import { GenerateImageTool } from "./GenerateImageTool.js";
|
|
|
28
28
|
*/
|
|
29
29
|
export const BUILTIN_TOOL_CLASSES = [
|
|
30
30
|
CwdTool,
|
|
31
|
-
|
|
31
|
+
ReadTool,
|
|
32
32
|
InspectFileTool,
|
|
33
|
-
|
|
33
|
+
WriteTool,
|
|
34
34
|
ExecTool,
|
|
35
35
|
MkdirTool,
|
|
36
36
|
RmTool,
|
|
@@ -43,9 +43,9 @@ export const BUILTIN_TOOL_CLASSES = [
|
|
|
43
43
|
CopyTool,
|
|
44
44
|
BatchEditTool,
|
|
45
45
|
EditTool,
|
|
46
|
-
|
|
46
|
+
SpawnTool,
|
|
47
47
|
SleepTool,
|
|
48
48
|
ViewImageTool,
|
|
49
49
|
GenerateImageTool,
|
|
50
50
|
];
|
|
51
|
-
export { CwdTool,
|
|
51
|
+
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, ViewImageTool, GenerateImageTool, };
|
|
@@ -28,7 +28,7 @@ export interface OutputGuardOptions<T> {
|
|
|
28
28
|
/** 超限判定:上限由工具自行从 config 读取,骨架不传参 */
|
|
29
29
|
isOverLimit: (content: T) => boolean;
|
|
30
30
|
/**
|
|
31
|
-
* 落盘内容组织(可选)。缺省表示"只警告、不落盘"(如
|
|
31
|
+
* 落盘内容组织(可选)。缺省表示"只警告、不落盘"(如 read)。
|
|
32
32
|
* 返回的文件按顺序写入本次调用专属的目录。
|
|
33
33
|
*/
|
|
34
34
|
dump?: (dir: string, content: T) => GuardDumpFile[] | Promise<GuardDumpFile[]>;
|
|
@@ -61,7 +61,7 @@ export interface HeadPreview {
|
|
|
61
61
|
/**
|
|
62
62
|
* 生成头部预览:最多 size 字符。
|
|
63
63
|
*
|
|
64
|
-
* 适用于结果按出现顺序排列、尾部参考价值低的工具(如
|
|
64
|
+
* 适用于结果按出现顺序排列、尾部参考价值低的工具(如 find_text)。
|
|
65
65
|
*/
|
|
66
66
|
export declare function headPreview(text: string, size?: number): HeadPreview;
|
|
67
67
|
/** 头尾预览 */
|
package/dist/types/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface Model {
|
|
|
36
36
|
/** 旧版字符数阈值(兼容迁移) */
|
|
37
37
|
maxContextChars?: number;
|
|
38
38
|
defaultParams?: Record<string, unknown>;
|
|
39
|
-
/** 是否支持图片输入(视觉模型)。看图工具(
|
|
39
|
+
/** 是否支持图片输入(视觉模型)。看图工具(view_image)仅对视觉模型启用;generate_image 是否返回图片内容块也据此判断 */
|
|
40
40
|
vision?: boolean;
|
|
41
41
|
description?: string;
|
|
42
42
|
version?: number;
|
|
@@ -104,7 +104,7 @@ export interface AppConfig {
|
|
|
104
104
|
*
|
|
105
105
|
* 工具本次输出超过该值时,由工具自身的保护策略处置(落盘或仅警告),
|
|
106
106
|
* 避免超长输出撑爆上下文。仅作用于"输出",与工具的读取阈值无关
|
|
107
|
-
* (如
|
|
107
|
+
* (如 read/find_text 对 300KB 文件的读取上限)。
|
|
108
108
|
*/
|
|
109
109
|
maxToolOutput?: number;
|
|
110
110
|
}
|
|
@@ -112,7 +112,7 @@ export interface AppConfig {
|
|
|
112
112
|
* 工具环境 — Scope 的能力插件在实例化内置工具时注入的环境信息。
|
|
113
113
|
*
|
|
114
114
|
* cwd 是相对路径解析的基准(每个 Scope 对应一个工作目录);
|
|
115
|
-
* config 供需要模型/端点配置的工具(如
|
|
115
|
+
* config 供需要模型/端点配置的工具(如 generate_image)使用。
|
|
116
116
|
*/
|
|
117
117
|
export interface ToolEnv {
|
|
118
118
|
/** 当前工作目录 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-zen/agents-sdk",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
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",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"author": "LZQCN",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@ai-zen/agents-core": "^4.3.2",
|
|
19
20
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
20
21
|
"dayjs": "^1.11.21",
|
|
21
|
-
"openai": "^7.5.0"
|
|
22
|
-
"@ai-zen/agents-core": "^4.3.0"
|
|
22
|
+
"openai": "^7.5.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^24.12.2",
|