@ai-zen/agents-sdk 1.0.0-alpha.24 → 1.0.0-alpha.25
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 +75 -0
- package/dist/config/migrate.d.ts +31 -0
- package/dist/config/migrate.js +51 -1
- package/dist/shared/EntityRepository.d.ts +10 -1
- package/dist/shared/EntityRepository.js +17 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
+
## [1.0.0-alpha.25] - 2026-11-02
|
|
2
|
+
|
|
3
|
+
> Endpoint capability bits are now backfilled on migration. Since alpha.12 the
|
|
4
|
+
> `capabilities.filesApi` bit decides whether local media is uploaded (Files API) or
|
|
5
|
+
> inlined as base64 — but endpoints are never factory-managed, and migration did not
|
|
6
|
+
> touch them either, so any config written before alpha.12 kept `deepseek` without the
|
|
7
|
+
> bit. For those users the promised "deepseek goes through the Files API" never took
|
|
8
|
+
> effect: images, `view_image` and MCP media silently degraded to base64 inline, and
|
|
9
|
+
> the request body grew with every turn of history.
|
|
10
|
+
>
|
|
11
|
+
> Alongside it, entity ids are now confined to their repository directory: a hostile id
|
|
12
|
+
> could previously make `AgentRepository` read / write / delete JSON files outside of
|
|
13
|
+
> `agents/`.
|
|
14
|
+
|
|
15
|
+
### 🛡️ Fixed — `Endpoint.capabilities` is backfilled when missing
|
|
16
|
+
|
|
17
|
+
- **`normalizeEndpointCapabilities()`** (in `config/migrate.ts`, wired into
|
|
18
|
+
`migrateConfig()`) fills in `capabilities` **only when the whole field is absent**,
|
|
19
|
+
taking the values from the factory endpoint with the same id. Nothing else is touched:
|
|
20
|
+
- an endpoint that already has `capabilities` — even `{}` or `{"filesApi": false}` — is
|
|
21
|
+
left byte-for-byte alone; an explicit `false` is a decision, not a gap;
|
|
22
|
+
- endpoints whose id is not in the factory list (user-built) are left alone, because
|
|
23
|
+
guessing would send uploads to a `/files` endpoint that may not exist.
|
|
24
|
+
- The migration lands on disk through the usual `ensureDefaultConfig()` path, so it runs
|
|
25
|
+
exactly once per config: a second start finds nothing to change.
|
|
26
|
+
- Verified end to end against a legacy-shaped config: `deepseek` gains
|
|
27
|
+
`{ filesApi: true }` in memory **and** on disk, a user-written `filesApi: false` on
|
|
28
|
+
`openai` survives, a self-built endpoint stays untouched, and the second start does not
|
|
29
|
+
rewrite the file.
|
|
30
|
+
|
|
31
|
+
### 🔒 Fixed — entity ids can no longer escape their repository directory
|
|
32
|
+
|
|
33
|
+
- **`EntityRepository.path()`** now validates the resolved target:
|
|
34
|
+
`resolve()` + a `root + sep` prefix check, instead of `join(dir, `${id}.json`)`.
|
|
35
|
+
- A bare `startsWith(root)` would not have been enough: `../agents-evil/x` normalizes to
|
|
36
|
+
`<root>-evil/x.json`, which still *starts with* `<root>`.
|
|
37
|
+
- `join` cannot normalize absolute paths, so `/etc/passwd` used to land in
|
|
38
|
+
`<dir>/etc/passwd.json`; `resolve` catches it.
|
|
39
|
+
- The check lives in `path()` rather than in `write()` / `delete()`: `read`, `write` and
|
|
40
|
+
`delete` all go through it, and `list()` only ever passes single-segment names coming
|
|
41
|
+
from `readdir`, so it cannot break listing — one gate, read/write/delete consistent.
|
|
42
|
+
- Affected callers that pass a user-supplied id straight through: `AgentRepository`
|
|
43
|
+
(agent / sub-agent definitions) and the CLI's conversation repository (`/save`, `/load`).
|
|
44
|
+
A hostile id now fails loudly (`Invalid entity id: …`) instead of writing outside the
|
|
45
|
+
directory.
|
|
46
|
+
- Known and accepted: `a/../b` normalizes back inside `<root>/b.json` and is therefore
|
|
47
|
+
still allowed — the only remaining effect is overwriting another definition, and
|
|
48
|
+
`config.json` is out of reach.
|
|
49
|
+
|
|
50
|
+
### ✅ Tests
|
|
51
|
+
|
|
52
|
+
- `AgentRepository.test.ts` +5: `../escaped` rejected *and* no file written outside,
|
|
53
|
+
`../agents-evil/x` rejected, `read` / `delete` share the same gate, absolute path
|
|
54
|
+
rejected, normal id unaffected. Uses a two-level temp directory so an escape would land
|
|
55
|
+
inside the test's own tmpdir instead of `/tmp`.
|
|
56
|
+
- `migrate.test.ts` +7: backfill on a legacy config, explicit `false` respected,
|
|
57
|
+
existing-but-empty `capabilities` untouched, user-built endpoint untouched, factory
|
|
58
|
+
endpoint without the bit untouched, idempotency, and "no side effects on the caller's
|
|
59
|
+
object".
|
|
60
|
+
- Full suite: **57 files / 629 tests passing** (6 skipped), `tsc --noEmit` clean.
|
|
61
|
+
|
|
62
|
+
### 🔧 Toolchain — TypeScript 5.9.3 → 7.0.2
|
|
63
|
+
|
|
64
|
+
- **`packages/sdk/tsconfig.json`**: added `"types": ["node"]`. TypeScript 7 no longer
|
|
65
|
+
picks global types up from `node_modules/@types` automatically (at least under this
|
|
66
|
+
repo's pnpm symlink layout), so `"node:fs"` / `process` / `Buffer` all turn into
|
|
67
|
+
`TS2591`. Naming the types explicitly is also what `@ai-zen/cli` already does.
|
|
68
|
+
- **`packages/core/tsconfig.json`**: `moduleResolution: "Node"` → `"Bundler"`. The
|
|
69
|
+
`node10` resolution mode was **removed** in TypeScript 7 (`TS5108`); `Bundler` is the
|
|
70
|
+
closest equivalent for a package compiled with `module: ESNext`.
|
|
71
|
+
- Verified after the upgrade: `tsc --noEmit` clean for both packages, both `build`
|
|
72
|
+
scripts succeed, core **150 passed / 17 skipped**, sdk **624 passed / 6 skipped**
|
|
73
|
+
at that point (629 after the entity-id hardening above), and `dist/index.js` still
|
|
74
|
+
loads at runtime (84 exports).
|
|
75
|
+
|
|
1
76
|
# Changelog
|
|
2
77
|
|
|
3
78
|
## [1.0.0-alpha.24] - 2026-10-29
|
package/dist/config/migrate.d.ts
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* `reasoningPreset` 而默默失去调档能力。这里删掉旧字段,并按**同 id 的出厂模型**
|
|
16
16
|
* 补上正确的策略名(同一 id 即同一厂商型号,协议能力不会因用户改过参数而变)。
|
|
17
17
|
*
|
|
18
|
+
* 另有一类「缺省值缺位」的迁移:`Endpoint.capabilities`(见 `normalizeEndpointCapabilities`)。
|
|
19
|
+
*
|
|
18
20
|
* 迁移时机:`ConfigManager.read()` 读出即迁(内存里永远是当前形状);
|
|
19
21
|
* 落盘由 `ensureDefaultConfig()` 负责 —— 它比较迁移结果与磁盘原文,不同才写回,
|
|
20
22
|
* 因此迁移只发生一次,且不会在每次启动时无谓地改写文件。
|
|
@@ -73,3 +75,32 @@ export declare const ABORTED_MESSAGE_STRATEGIES: readonly ["keep", "drop"];
|
|
|
73
75
|
export declare const ABORTED_TOOL_ROUND_STRATEGIES: readonly ["fill", "drop"];
|
|
74
76
|
/** 缺失 / 非法 → 出厂默认;返回是否有改动(直接改写传入对象) */
|
|
75
77
|
export declare function normalizeAbortStrategies(config: AppConfig): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
80
|
+
*
|
|
81
|
+
* ## 这个问题是怎么来的
|
|
82
|
+
*
|
|
83
|
+
* `capabilities.filesApi` 是 alpha.12 才引入的能力位 —— 同一版把 `view_image` 的判定
|
|
84
|
+
* 从「端点 id 是不是 `deepseek`」改成「看这一位」,并只给**出厂 deepseek** 打了 `true`。
|
|
85
|
+
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
86
|
+
* 迁移此前也完全不碰 `endpoints` —— 于是 alpha.12 之前就已写下的配置,其 deepseek
|
|
87
|
+
* 端点永远缺 `capabilities`,`supportsFilesApi()` 恒为 `false`:
|
|
88
|
+
*
|
|
89
|
+
* · 出厂承诺的「deepseek 走 Files API」对这些用户从未生效;
|
|
90
|
+
* · 而且**全程静默** —— 「未声明能力位」和「缺 apiKey」两个分支都不发 warning,
|
|
91
|
+
* 图片 / `view_image` / MCP 媒体就悄悄退化成 base64 内联,请求体随历史膨胀。
|
|
92
|
+
*
|
|
93
|
+
* 这是「默认值缺位」,不是「用户选择」,所以由迁移补 —— 与模型清单不同,端点本身仍然
|
|
94
|
+
* 归用户所有,我们只往**空位**里放出厂默认。
|
|
95
|
+
*
|
|
96
|
+
* ## 边界:只补整体缺失,绝不覆盖
|
|
97
|
+
*
|
|
98
|
+
* - `capabilities` **整体缺失** → 按**同 id 的出厂端点**补上整块;
|
|
99
|
+
* - `capabilities` 已存在(哪怕是 `{}`、哪怕写着 `filesApi: false`)→ 一个字段都不动:
|
|
100
|
+
* 用户已经表过态,`false` 就是「我不走 Files API」;
|
|
101
|
+
* - 端点 id 不在出厂清单(用户自建)→ 不动:我们不知道它是否真有 `/files`,
|
|
102
|
+
* 猜错会把上传请求打到不存在的接口上。
|
|
103
|
+
*
|
|
104
|
+
* @returns 是否有改动(直接改写传入对象)
|
|
105
|
+
*/
|
|
106
|
+
export declare function normalizeEndpointCapabilities(config: AppConfig): boolean;
|
package/dist/config/migrate.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* `reasoningPreset` 而默默失去调档能力。这里删掉旧字段,并按**同 id 的出厂模型**
|
|
16
16
|
* 补上正确的策略名(同一 id 即同一厂商型号,协议能力不会因用户改过参数而变)。
|
|
17
17
|
*
|
|
18
|
+
* 另有一类「缺省值缺位」的迁移:`Endpoint.capabilities`(见 `normalizeEndpointCapabilities`)。
|
|
19
|
+
*
|
|
18
20
|
* 迁移时机:`ConfigManager.read()` 读出即迁(内存里永远是当前形状);
|
|
19
21
|
* 落盘由 `ensureDefaultConfig()` 负责 —— 它比较迁移结果与磁盘原文,不同才写回,
|
|
20
22
|
* 因此迁移只发生一次,且不会在每次启动时无谓地改写文件。
|
|
@@ -118,7 +120,12 @@ export function migrateConfig(config) {
|
|
|
118
120
|
changed = true;
|
|
119
121
|
return reasoning.model;
|
|
120
122
|
});
|
|
121
|
-
const next = {
|
|
123
|
+
const next = {
|
|
124
|
+
...config,
|
|
125
|
+
models,
|
|
126
|
+
// 端点数组浅拷贝:能力位补齐会改元素,不把副作用浇到调用方手里的旧对象上
|
|
127
|
+
endpoints: (config.endpoints ?? []).map((endpoint) => ({ ...endpoint })),
|
|
128
|
+
};
|
|
122
129
|
// 已废弃字段:不参与运行,也不允许再写回磁盘
|
|
123
130
|
if ("defaultModel" in next) {
|
|
124
131
|
delete next.defaultModel;
|
|
@@ -126,6 +133,8 @@ export function migrateConfig(config) {
|
|
|
126
133
|
}
|
|
127
134
|
if (normalizeAbortStrategies(next))
|
|
128
135
|
changed = true;
|
|
136
|
+
if (normalizeEndpointCapabilities(next))
|
|
137
|
+
changed = true;
|
|
129
138
|
if (!changed)
|
|
130
139
|
return { config, changed };
|
|
131
140
|
return { config: next, changed };
|
|
@@ -146,3 +155,44 @@ export function normalizeAbortStrategies(config) {
|
|
|
146
155
|
}
|
|
147
156
|
return changed;
|
|
148
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
160
|
+
*
|
|
161
|
+
* ## 这个问题是怎么来的
|
|
162
|
+
*
|
|
163
|
+
* `capabilities.filesApi` 是 alpha.12 才引入的能力位 —— 同一版把 `view_image` 的判定
|
|
164
|
+
* 从「端点 id 是不是 `deepseek`」改成「看这一位」,并只给**出厂 deepseek** 打了 `true`。
|
|
165
|
+
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
166
|
+
* 迁移此前也完全不碰 `endpoints` —— 于是 alpha.12 之前就已写下的配置,其 deepseek
|
|
167
|
+
* 端点永远缺 `capabilities`,`supportsFilesApi()` 恒为 `false`:
|
|
168
|
+
*
|
|
169
|
+
* · 出厂承诺的「deepseek 走 Files API」对这些用户从未生效;
|
|
170
|
+
* · 而且**全程静默** —— 「未声明能力位」和「缺 apiKey」两个分支都不发 warning,
|
|
171
|
+
* 图片 / `view_image` / MCP 媒体就悄悄退化成 base64 内联,请求体随历史膨胀。
|
|
172
|
+
*
|
|
173
|
+
* 这是「默认值缺位」,不是「用户选择」,所以由迁移补 —— 与模型清单不同,端点本身仍然
|
|
174
|
+
* 归用户所有,我们只往**空位**里放出厂默认。
|
|
175
|
+
*
|
|
176
|
+
* ## 边界:只补整体缺失,绝不覆盖
|
|
177
|
+
*
|
|
178
|
+
* - `capabilities` **整体缺失** → 按**同 id 的出厂端点**补上整块;
|
|
179
|
+
* - `capabilities` 已存在(哪怕是 `{}`、哪怕写着 `filesApi: false`)→ 一个字段都不动:
|
|
180
|
+
* 用户已经表过态,`false` 就是「我不走 Files API」;
|
|
181
|
+
* - 端点 id 不在出厂清单(用户自建)→ 不动:我们不知道它是否真有 `/files`,
|
|
182
|
+
* 猜错会把上传请求打到不存在的接口上。
|
|
183
|
+
*
|
|
184
|
+
* @returns 是否有改动(直接改写传入对象)
|
|
185
|
+
*/
|
|
186
|
+
export function normalizeEndpointCapabilities(config) {
|
|
187
|
+
let changed = false;
|
|
188
|
+
for (const endpoint of config.endpoints ?? []) {
|
|
189
|
+
if (endpoint.capabilities != null)
|
|
190
|
+
continue;
|
|
191
|
+
const factory = (DEFAULT_APP_CONFIG.endpoints ?? []).find((item) => item.id === endpoint.id);
|
|
192
|
+
if (!factory?.capabilities)
|
|
193
|
+
continue;
|
|
194
|
+
endpoint.capabilities = { ...factory.capabilities };
|
|
195
|
+
changed = true;
|
|
196
|
+
}
|
|
197
|
+
return changed;
|
|
198
|
+
}
|
|
@@ -11,7 +11,16 @@ export declare class EntityRepository<T extends {
|
|
|
11
11
|
}> {
|
|
12
12
|
private dir;
|
|
13
13
|
constructor(dir: string);
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* 获取实体的文件路径;`id` 必须落在本仓储目录内,否则抛错。
|
|
16
|
+
*
|
|
17
|
+
* 这是**唯一**的落盘口(read / write / delete 全走这里,`list()` 的 id 来自
|
|
18
|
+
* `readdir` 的单层文件名、不可能逃逸),所以校验放这里读写删天然自洽。
|
|
19
|
+
*
|
|
20
|
+
* 两个细节都是必需的:
|
|
21
|
+
* - 用 `resolve` 而不是 `join`:只有 `resolve` 会把绝对路径(`/etc/passwd`)归一化拦下;
|
|
22
|
+
* - 比较 `root + sep` 而不是裸 `startsWith(root)`:`<root>-evil/x` 也以 `<root>` 开头。
|
|
23
|
+
*/
|
|
15
24
|
protected path(id: string): string;
|
|
16
25
|
/** 列出目录下所有实体(跳过解析失败的文件) */
|
|
17
26
|
list(): Promise<T[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { resolve, sep } from "node:path";
|
|
3
3
|
/**
|
|
4
4
|
* 通用实体仓储 — 对磁盘 JSON 文件的 CRUD 操作。
|
|
5
5
|
*
|
|
@@ -13,9 +13,23 @@ export class EntityRepository {
|
|
|
13
13
|
constructor(dir) {
|
|
14
14
|
this.dir = dir;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* 获取实体的文件路径;`id` 必须落在本仓储目录内,否则抛错。
|
|
18
|
+
*
|
|
19
|
+
* 这是**唯一**的落盘口(read / write / delete 全走这里,`list()` 的 id 来自
|
|
20
|
+
* `readdir` 的单层文件名、不可能逃逸),所以校验放这里读写删天然自洽。
|
|
21
|
+
*
|
|
22
|
+
* 两个细节都是必需的:
|
|
23
|
+
* - 用 `resolve` 而不是 `join`:只有 `resolve` 会把绝对路径(`/etc/passwd`)归一化拦下;
|
|
24
|
+
* - 比较 `root + sep` 而不是裸 `startsWith(root)`:`<root>-evil/x` 也以 `<root>` 开头。
|
|
25
|
+
*/
|
|
17
26
|
path(id) {
|
|
18
|
-
|
|
27
|
+
const root = resolve(this.dir);
|
|
28
|
+
const target = resolve(root, `${id}.json`);
|
|
29
|
+
if (!target.startsWith(root + sep)) {
|
|
30
|
+
throw new Error(`Invalid entity id: ${JSON.stringify(id)}`);
|
|
31
|
+
}
|
|
32
|
+
return target;
|
|
19
33
|
}
|
|
20
34
|
/** 列出目录下所有实体(跳过解析失败的文件) */
|
|
21
35
|
async list() {
|
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.25",
|
|
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",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dotenv": "^17.4.2",
|
|
36
36
|
"prettier": "^3.9.5",
|
|
37
37
|
"rimraf": "^6.0.0",
|
|
38
|
-
"typescript": "^
|
|
38
|
+
"typescript": "^7.0.2",
|
|
39
39
|
"vitest": "^4.1.9"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|