@ai-zen/agents-sdk 1.0.0-alpha.8 → 1.0.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +661 -2
  2. package/README.md +22 -6
  3. package/README.zh.md +23 -7
  4. package/dist/agent-plugins/AutoMigratePlugin.d.ts +35 -9
  5. package/dist/agent-plugins/AutoMigratePlugin.js +21 -10
  6. package/dist/agent-plugins/AutoRefreshToolsPlugin.js +1 -3
  7. package/dist/agent-plugins/ContextGuardPlugin.d.ts +28 -16
  8. package/dist/agent-plugins/ContextGuardPlugin.js +23 -17
  9. package/dist/agent-plugins/UnknownToolHintPlugin.js +4 -4
  10. package/dist/config/ConfigManager.d.ts +57 -8
  11. package/dist/config/ConfigManager.js +167 -26
  12. package/dist/config/constants.d.ts +7 -0
  13. package/dist/config/constants.js +70 -43
  14. package/dist/config/factory-skills.d.ts +33 -0
  15. package/dist/config/factory-skills.js +126 -0
  16. package/dist/config/migrate.d.ts +106 -0
  17. package/dist/config/migrate.js +196 -0
  18. package/dist/config/reasoning-presets.d.ts +37 -0
  19. package/dist/config/reasoning-presets.js +64 -0
  20. package/dist/index.d.ts +13 -7
  21. package/dist/index.js +11 -3
  22. package/dist/runtime/HandoffGuardPlugin.d.ts +35 -0
  23. package/dist/runtime/HandoffGuardPlugin.js +65 -0
  24. package/dist/runtime/HandoffService.d.ts +246 -0
  25. package/dist/runtime/HandoffService.js +475 -0
  26. package/dist/runtime/SdkAgent.d.ts +7 -1
  27. package/dist/runtime/SdkAgent.js +3 -0
  28. package/dist/runtime/createAgent.d.ts +20 -1
  29. package/dist/runtime/createAgent.js +14 -9
  30. package/dist/runtime/createModel.d.ts +8 -4
  31. package/dist/runtime/createModel.js +22 -5
  32. package/dist/scope/PermissionEvaluator.js +1 -1
  33. package/dist/scope/Scope.d.ts +3 -1
  34. package/dist/scope/Scope.js +4 -2
  35. package/dist/scope/plugins/builtin/BatchEditTool.js +24 -14
  36. package/dist/scope/plugins/builtin/CopyTool.js +4 -4
  37. package/dist/scope/plugins/builtin/CwdTool.js +1 -1
  38. package/dist/scope/plugins/builtin/DownloadFileTool.d.ts +1 -0
  39. package/dist/scope/plugins/builtin/DownloadFileTool.js +58 -34
  40. package/dist/scope/plugins/builtin/EditTool.js +25 -25
  41. package/dist/scope/plugins/builtin/ExecTool.js +134 -25
  42. package/dist/scope/plugins/builtin/ExistTool.js +2 -2
  43. package/dist/scope/plugins/builtin/FindTextTool.js +15 -10
  44. package/dist/scope/plugins/builtin/GenerateImageTool.js +91 -25
  45. package/dist/scope/plugins/builtin/GlobTool.js +10 -5
  46. package/dist/scope/plugins/builtin/InspectFileTool.js +7 -7
  47. package/dist/scope/plugins/builtin/LsTool.js +5 -5
  48. package/dist/scope/plugins/builtin/MkdirTool.js +3 -3
  49. package/dist/scope/plugins/builtin/ReadTool.js +8 -8
  50. package/dist/scope/plugins/builtin/RenameTool.js +3 -3
  51. package/dist/scope/plugins/builtin/RmTool.js +3 -3
  52. package/dist/scope/plugins/builtin/SleepTool.js +6 -6
  53. package/dist/scope/plugins/builtin/SpawnTool.js +32 -49
  54. package/dist/scope/plugins/builtin/ViewImageTool.d.ts +6 -4
  55. package/dist/scope/plugins/builtin/ViewImageTool.js +50 -62
  56. package/dist/scope/plugins/builtin/WriteTool.js +3 -3
  57. package/dist/scope/plugins/builtin/searchBase.d.ts +9 -0
  58. package/dist/scope/plugins/builtin/searchBase.js +17 -0
  59. package/dist/scope/plugins/builtin/test-helpers.d.ts +3 -3
  60. package/dist/scope/plugins/builtin/test-helpers.js +3 -3
  61. package/dist/scope/plugins/builtin/textEdit.d.ts +17 -0
  62. package/dist/scope/plugins/builtin/textEdit.js +37 -0
  63. package/dist/scope/plugins/mcp/McpConnectionManager.d.ts +9 -1
  64. package/dist/scope/plugins/mcp/McpConnectionManager.js +95 -16
  65. package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +1 -1
  66. package/dist/scope/plugins/mcp/McpScopePlugin.js +8 -6
  67. package/dist/scope/plugins/mcp/discover.js +1 -1
  68. package/dist/scope/plugins/mcp/mcpTools.d.ts +9 -3
  69. package/dist/scope/plugins/mcp/mcpTools.js +247 -37
  70. package/dist/scope/plugins/skills/SkillsScopePlugin.js +2 -3
  71. package/dist/scope/plugins/skills/discover.js +28 -9
  72. package/dist/scope/plugins/skills/skillTools.js +30 -20
  73. package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +1 -3
  74. package/dist/scope/plugins/subagents/subAgentTools.js +4 -3
  75. package/dist/scope/plugins/usertools/discover.d.ts +8 -3
  76. package/dist/scope/plugins/usertools/discover.js +139 -12
  77. package/dist/shared/EntityRepository.d.ts +10 -1
  78. package/dist/shared/EntityRepository.js +18 -6
  79. package/dist/shared/content-blocks.d.ts +101 -0
  80. package/dist/shared/content-blocks.js +253 -0
  81. package/dist/shared/errors.d.ts +4 -8
  82. package/dist/shared/errors.js +8 -14
  83. package/dist/types/index.d.ts +170 -8
  84. package/package.json +16 -7
  85. package/dist/runtime/TaskMigrationService.d.ts +0 -128
  86. package/dist/runtime/TaskMigrationService.js +0 -211
@@ -1,12 +1,17 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./constants.js";
4
+ import { FACTORY_SKILLS, isCustomSkill } from "./factory-skills.js";
5
+ import { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./reasoning-presets.js";
6
+ import { migrateConfig } from "./migrate.js";
4
7
  /**
5
8
  * 配置管理器 — 负责配置文件的读写、目录初始化、默认实体创建。
6
9
  */
7
10
  export class ConfigManager {
8
11
  configPath;
9
12
  basePath;
13
+ /** 当前配置里的模型 id 集合(bootstrap 时填充,供默认 Agent 校验 modelId) */
14
+ knownModelIds = new Set();
10
15
  constructor(configPath) {
11
16
  this.configPath = configPath;
12
17
  this.basePath = dirname(configPath);
@@ -16,13 +21,22 @@ export class ConfigManager {
16
21
  // -----------------------------------------------------------------------
17
22
  /**
18
23
  * 读取配置。文件不存在时返回出厂默认配置。
24
+ *
25
+ * 读到即**迁移**(`config/migrate.ts`):上层拿到的永远是当前字段形状,
26
+ * 旧字段(`maxContextTokens` / `maxContextChars`)不会漏到调用方。
27
+ * 迁移结果不在这里落盘——落盘只在 `ensureDefaultConfig()` 做一次。
19
28
  */
20
29
  async read() {
30
+ const raw = await this.readRaw();
31
+ return raw ? migrateConfig(raw).config : { ...DEFAULT_APP_CONFIG };
32
+ }
33
+ /** 读磁盘原文(不做任何迁移/同步),供 `ensureDefaultConfig()` 对比写盘用 */
34
+ async readRaw() {
21
35
  try {
22
36
  await fs.access(this.configPath);
23
37
  }
24
38
  catch {
25
- return { ...DEFAULT_APP_CONFIG };
39
+ return null;
26
40
  }
27
41
  const raw = await fs.readFile(this.configPath, "utf-8");
28
42
  return JSON.parse(raw);
@@ -61,18 +75,16 @@ export class ConfigManager {
61
75
  * 条目视为用户自有,原样保留。同步结果与磁盘内容一致时不写盘。
62
76
  */
63
77
  async ensureDefaultConfig() {
64
- let existing;
65
- try {
66
- await fs.access(this.configPath);
67
- existing = await this.read();
68
- }
69
- catch {
78
+ const onDisk = await this.readRaw();
79
+ if (!onDisk) {
70
80
  await this.ensureDirs();
71
81
  await this.write(DEFAULT_APP_CONFIG);
72
82
  return { ...DEFAULT_APP_CONFIG };
73
83
  }
74
- const synced = syncManagedModels(existing);
75
- if (JSON.stringify(synced) !== JSON.stringify(existing)) {
84
+ // 先迁移历史字段,再同步出厂模型清单;两者结果与磁盘原文不同才写盘
85
+ const migrated = migrateConfig(onDisk).config;
86
+ const synced = syncManagedModels(migrated);
87
+ if (JSON.stringify(synced) !== JSON.stringify(onDisk)) {
76
88
  await this.write(synced);
77
89
  }
78
90
  return synced;
@@ -80,28 +92,48 @@ export class ConfigManager {
80
92
  /**
81
93
  * 确保 basePath/agents/default.json 存在。
82
94
  *
83
- * - default.json 已存在且 custom === true → 用户声明为自定义,原样返回,不做任何改动
84
- * - default.json 已存在且 custom !== true → 仅同步出厂提示词(messages),
85
- * 其余字段(name/permissions/modelId 等)保留;提示词一致时不写盘
86
- * - agents/ 为空 → 写入默认 Agent
95
+ * - default.json 已存在且 custom === true → 用户声明为自定义,不替换提示词(缺 modelId 仍补)
96
+ * - default.json 已存在且 custom !== true → 同步出厂提示词(messages),
97
+ * 其余字段(name/permissions 等)保留;提示词与 modelId 都一致时不写盘
98
+ * - agents/ 为空 → 写入默认 Agent(含 modelId)
87
99
  * - 已有其他 Agent → 返回 null
100
+ *
101
+ * 模型真相源只有 `AgentDefinition.modelId`:这里保证默认 Agent **一定有** modelId,
102
+ * 运行期不再有任何 `config.defaultModel` 兜底。
103
+ *
104
+ * @param legacyDefaultModel 老配置里的 `config.defaultModel`。仅在 Agent **既无 modelId**
105
+ * 且该模型仍在模型清单里时用它补齐,让升级不改变用户实际在用的模型;之后
106
+ * 这个字段就彻底不存在了。
88
107
  */
89
- async ensureDefaultAgent() {
108
+ async ensureDefaultAgent(legacyDefaultModel) {
90
109
  const agentsDir = join(this.basePath, "agents");
91
110
  const defaultPath = join(agentsDir, `${DEFAULT_AGENT_ID}.json`);
111
+ const fallbackModelId = legacyDefaultModel && this.knownModelIds.has(legacyDefaultModel)
112
+ ? legacyDefaultModel
113
+ : DEFAULT_AGENT_DEFINITION.modelId;
92
114
  try {
93
115
  const existing = JSON.parse(await fs.readFile(defaultPath, "utf-8"));
94
- // 用户声明为自定义 → 完全跳过替换
95
- if (existing.custom === true)
96
- return existing;
116
+ // 缺 modelId → 补上(历史配置升级路径)
117
+ const withModel = existing.modelId
118
+ ? existing
119
+ : { ...existing, modelId: fallbackModelId };
120
+ const modelPatched = !existing.modelId;
121
+ // 用户声明为自定义 → 不替换提示词,但补上的 modelId 要落盘
122
+ if (withModel.custom === true) {
123
+ if (modelPatched) {
124
+ await fs.writeFile(defaultPath, JSON.stringify(withModel, null, 2), "utf-8");
125
+ }
126
+ return withModel;
127
+ }
97
128
  // 仅同步提示词;内容一致则不写盘、不动时间戳
98
129
  const messages = DEFAULT_AGENT_DEFINITION.messages;
99
- if (sameMessages(existing.messages ?? [], messages))
100
- return existing;
130
+ const sameMsgs = sameMessages(withModel.messages ?? [], messages);
131
+ if (sameMsgs && !modelPatched)
132
+ return withModel;
101
133
  const updated = {
102
- ...existing,
134
+ ...withModel,
103
135
  messages,
104
- updatedAt: new Date().toISOString(),
136
+ updatedAt: sameMsgs ? withModel.updatedAt : new Date().toISOString(),
105
137
  };
106
138
  await fs.writeFile(defaultPath, JSON.stringify(updated, null, 2), "utf-8");
107
139
  return updated;
@@ -174,13 +206,121 @@ export class ConfigManager {
174
206
  */
175
207
  async bootstrap() {
176
208
  await this.ensureDirs();
209
+ // 迁移前读一次磁盘原文:只为了拿旧的 `defaultModel`(字段已从类型里移除),
210
+ // 让升级不改变用户原本在用的模型
211
+ const raw = (await this.readRaw());
177
212
  const config = await this.ensureDefaultConfig();
178
- const agent = await this.ensureDefaultAgent();
213
+ this.knownModelIds = new Set((config.models ?? []).map((m) => m.id));
214
+ const agent = await this.ensureDefaultAgent(raw?.defaultModel);
179
215
  const subAgent = await this.ensureDefaultSubAgent();
180
216
  await this.ensureDefaultMcpConfig();
217
+ await this.ensureFactorySkills();
218
+ await this.ensureReasoningPresets();
181
219
  return { config, agent, subAgent };
182
220
  }
183
221
  // -----------------------------------------------------------------------
222
+ // 思考策略表({basePath}/reasoning-presets.json)
223
+ // -----------------------------------------------------------------------
224
+ /** 策略表文件路径(与 config.json 同级) */
225
+ get reasoningPresetsPath() {
226
+ return join(this.basePath, REASONING_PRESETS_FILE);
227
+ }
228
+ /**
229
+ * 读取思考策略表。
230
+ *
231
+ * 文件缺失或无法解析时返回出厂种子(内存值,不写盘)——保证调用方永远拿到可用的表:
232
+ * 用户误删文件后客户端仍能正常选档位,下次 `ensureReasoningPresets()` 会重新释放。
233
+ */
234
+ async readReasoningPresets() {
235
+ try {
236
+ const raw = await fs.readFile(this.reasoningPresetsPath, "utf-8");
237
+ const parsed = JSON.parse(raw);
238
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
239
+ return parsed;
240
+ }
241
+ catch {
242
+ // 缺失或损坏 → 回落出厂种子
243
+ }
244
+ return { ...FACTORY_REASONING_PRESETS };
245
+ }
246
+ /**
247
+ * 释放 / 同步出厂思考策略。
248
+ *
249
+ * 覆盖策略与 `syncManagedModels` 同构,**按策略逐个判断**(粒度到单个策略):
250
+ * - 文件不存在 → 写入出厂种子;
251
+ * - 某策略标了 `custom: true` → 用户自有,原样保留;
252
+ * - 某策略未标 → 用出厂版覆盖该策略(内容相同则不写盘);
253
+ * - 用户自建的非出厂策略 → 始终保留。
254
+ *
255
+ * @returns 实际写入的策略名列表(未变化 / 用户自有 均不计入)
256
+ */
257
+ async ensureReasoningPresets() {
258
+ let onDisk = null;
259
+ try {
260
+ onDisk = JSON.parse(await fs.readFile(this.reasoningPresetsPath, "utf-8"));
261
+ }
262
+ catch {
263
+ onDisk = null;
264
+ }
265
+ if (!onDisk || typeof onDisk !== "object" || Array.isArray(onDisk)) {
266
+ await fs.mkdir(this.basePath, { recursive: true });
267
+ await fs.writeFile(this.reasoningPresetsPath, JSON.stringify(FACTORY_REASONING_PRESETS, null, 2), "utf-8");
268
+ return Object.keys(FACTORY_REASONING_PRESETS);
269
+ }
270
+ const next = { ...onDisk };
271
+ const written = [];
272
+ for (const [name, preset] of Object.entries(FACTORY_REASONING_PRESETS)) {
273
+ const existing = onDisk[name];
274
+ if (existing?.custom === true)
275
+ continue; // 用户改过 → 冻结
276
+ if (JSON.stringify(existing) === JSON.stringify(preset))
277
+ continue; // 已是最新
278
+ next[name] = preset;
279
+ written.push(name);
280
+ }
281
+ if (written.length > 0) {
282
+ await fs.writeFile(this.reasoningPresetsPath, JSON.stringify(next, null, 2), "utf-8");
283
+ }
284
+ return written;
285
+ }
286
+ // -----------------------------------------------------------------------
287
+ // 出厂 Skill({basePath}/skills/<id>/SKILL.md)
288
+ // -----------------------------------------------------------------------
289
+ /**
290
+ * 释放 / 同步出厂 Skill。
291
+ *
292
+ * 覆盖策略与 `syncManagedModels` 同构:
293
+ * - 磁盘上不存在 → 写入出厂内容;
294
+ * - 存在且 frontmatter 标了 `custom: "true"` → 用户自有,原样保留;
295
+ * - 存在但未标 → 视为出厂托管,同步为当前版本内容(内容相同则不写盘)。
296
+ *
297
+ * @returns 实际写入的 Skill id 列表(内容未变化 / 用户自有 均不计入)
298
+ */
299
+ async ensureFactorySkills() {
300
+ const written = [];
301
+ for (const skill of FACTORY_SKILLS) {
302
+ const dir = join(this.basePath, "skills", skill.id);
303
+ const file = join(dir, "SKILL.md");
304
+ let existing = null;
305
+ try {
306
+ existing = await fs.readFile(file, "utf-8");
307
+ }
308
+ catch {
309
+ existing = null;
310
+ }
311
+ // 用户声明自有 → 永不覆盖
312
+ if (existing != null && isCustomSkill(existing))
313
+ continue;
314
+ // 内容已一致 → 不重复写盘
315
+ if (existing === skill.content)
316
+ continue;
317
+ await fs.mkdir(dir, { recursive: true });
318
+ await fs.writeFile(file, skill.content, "utf-8");
319
+ written.push(skill.id);
320
+ }
321
+ return written;
322
+ }
323
+ // -----------------------------------------------------------------------
184
324
  // MCP 配置(~/.ai-zen/mcp.json)
185
325
  // -----------------------------------------------------------------------
186
326
  /** mcp.json 路径:{basePath}/mcp.json */
@@ -251,9 +391,11 @@ export class ConfigManager {
251
391
  * 规则:
252
392
  * - 未标 `custom: true` 的条目 → 由 SDK 托管,从结果中移除,改用 defaults 中的最新定义;
253
393
  * - 标了 `custom: true` 的条目 → 用户自有,原样保留;与出厂定义同 id 时用户版本优先;
254
- * - 默认模型 ID(defaultModel / defaultImageModel / defaultMigrationModel)
394
+ * - 默认模型 ID(defaultImageModel / defaultMigrationModel)
255
395
  * 在合并后若已不存在 → 回退到出厂默认,避免悬空引用。
256
396
  *
397
+ * 注意 `defaultModel` 已不再存在:模型真相源是 `AgentDefinition.modelId`。
398
+ *
257
399
  * 端点(endpoints)不参与托管,始终保持用户配置。
258
400
  */
259
401
  export function syncManagedModels(config) {
@@ -267,12 +409,11 @@ export function syncManagedModels(config) {
267
409
  const imageModels = pick(config.imageModels, DEFAULT_APP_CONFIG.imageModels ?? []);
268
410
  const modelIds = new Set(models.map((m) => m.id));
269
411
  const imageIds = new Set(imageModels.map((m) => m.id));
270
- const resolve = (id, ids, fallback) => id && ids.has(id) ? id : fallback;
412
+ const resolve = (id, ids, fallback) => (id && ids.has(id) ? id : fallback);
271
413
  return {
272
414
  ...config,
273
415
  models,
274
416
  imageModels,
275
- defaultModel: resolve(config.defaultModel, modelIds, DEFAULT_APP_CONFIG.defaultModel),
276
417
  defaultImageModel: resolve(config.defaultImageModel, imageIds, DEFAULT_APP_CONFIG.defaultImageModel),
277
418
  defaultMigrationModel: resolve(config.defaultMigrationModel, modelIds, DEFAULT_APP_CONFIG.defaultMigrationModel),
278
419
  };
@@ -289,4 +430,4 @@ function sameMessages(a, b) {
289
430
  return a.every((message, index) => message.role === b[index].role &&
290
431
  JSON.stringify(message.content) === JSON.stringify(b[index].content));
291
432
  }
292
- export { DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./constants.js";
433
+ export { DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_MODEL_ID, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./constants.js";
@@ -1,6 +1,13 @@
1
1
  import type { AgentDefinition, AppConfig } from "../types/index.js";
2
2
  /** 默认 Agent ID */
3
3
  export declare const DEFAULT_AGENT_ID = "default";
4
+ /**
5
+ * 出厂默认模型 id。
6
+ *
7
+ * 模型的**唯一真相源是 `AgentDefinition.modelId`**:配置里不再有 `defaultModel`,
8
+ * 会话存档里也不记模型。这个常量只用于给出厂默认 Agent 填一个初始值。
9
+ */
10
+ export declare const DEFAULT_MODEL_ID = "deepseek-flash";
4
11
  /** 默认 Agent 定义(不含时间戳) */
5
12
  export declare const DEFAULT_AGENT_DEFINITION: Omit<AgentDefinition, "createdAt" | "updatedAt">;
6
13
  /** 默认 SubAgent ID */
@@ -4,16 +4,25 @@ import { Message } from "@ai-zen/agents-core";
4
4
  // ---------------------------------------------------------------------------
5
5
  /** 默认 Agent ID */
6
6
  export const DEFAULT_AGENT_ID = "default";
7
+ /**
8
+ * 出厂默认模型 id。
9
+ *
10
+ * 模型的**唯一真相源是 `AgentDefinition.modelId`**:配置里不再有 `defaultModel`,
11
+ * 会话存档里也不记模型。这个常量只用于给出厂默认 Agent 填一个初始值。
12
+ */
13
+ export const DEFAULT_MODEL_ID = "deepseek-flash";
7
14
  /** 默认 Agent 定义(不含时间戳) */
8
15
  export const DEFAULT_AGENT_DEFINITION = {
9
16
  id: DEFAULT_AGENT_ID,
10
- name: "默认助手",
11
- description: "默认的 AI 助手,适用于日常问答和任务执行。",
17
+ name: "Default Assistant",
18
+ description: "The default AI assistant, suited for everyday Q&A and task execution.",
19
+ // 模型写在 Agent 定义上,是运行期唯一真相源(无 config.defaultModel 兜底)
20
+ modelId: DEFAULT_MODEL_ID,
12
21
  messages: [
13
- Message.System(`你是一个幽默风趣、严谨可靠的智能助手,请用中文回复。当前操作系统:${process.platform}。
22
+ Message.System(`You are a witty, rigorous and reliable assistant. Always reply in the same language the user writes in. Current operating system: ${process.platform}.
14
23
 
15
- 一、需要用户决策时,一次只问一个问题。
16
- 二、当前对话基于 Node.js 驱动,你可以编写 Node.js 脚本执行复杂任务,并通过 exec 工具运行。`),
24
+ 1. When user input is needed for a decision, ask only one question at a time.
25
+ 2. This session runs on Node.js — you can write Node.js scripts to carry out complex tasks and run them via the exec tool.`),
17
26
  ],
18
27
  // 出厂默认 Agent:custom 为 false,SDK 初始化时会同步出厂提示词(用户设为 true 则跳过)
19
28
  custom: false,
@@ -32,10 +41,10 @@ export const DEFAULT_SUBAGENT_ID = "sub-agent-default";
32
41
  /** 默认 SubAgent 定义(不含时间戳) */
33
42
  export const DEFAULT_SUBAGENT_DEFINITION = {
34
43
  id: DEFAULT_SUBAGENT_ID,
35
- name: "通用助手",
36
- description: "一个通用的子 Agent,擅长独立完成各类任务。",
44
+ name: "General Assistant",
45
+ description: "A general-purpose sub-agent that is good at completing all kinds of tasks independently.",
37
46
  messages: [
38
- Message.System("你是一个通用助手子 Agent,被父 Agent 委派来独立完成具体任务。请根据给定的任务描述,主动调用你的工具(文件读写、执行命令、搜索等)来分析和完成任务。完成任务后直接返回结果,不需要解释你的思考过程。\n\n⚠️ 强制性要求:\n1. 如果任务描述中存在任何不明确、模糊或缺失的信息(包括但不限于具体目标、文件路径、约束条件、预期产出等),你必须直接拒绝执行,并明确列出哪些信息不明确或缺失,要求父 Agent 提供更完整的任务上下文。不得自行假设、猜测或脑补任何信息。\n2. 如果任务描述中存在自相矛盾的信息(如相互冲突的要求、不一致的文件路径、矛盾的约束条件等),你必须及时指出矛盾之处,并要求父 Agent 澄清后再执行。"),
47
+ Message.System("You are a general-purpose assistant sub-agent, delegated by a parent agent to independently complete a specific task. Based on the given task description, proactively call your tools (file read/write, command execution, search, etc.) to analyze and complete the task. When the task is done, return the result directly; there is no need to explain your thinking process.\n\n⚠️ Mandatory requirements:\n1. If anything in the task description is unclear, vague or missing (including but not limited to the specific goal, file paths, constraints, expected deliverables, etc.), you MUST refuse to execute immediately and explicitly list what is unclear or missing, asking the parent agent to provide more complete task context. Do not assume, guess or make up any information on your own.\n2. If the task description contains contradictory information (such as mutually conflicting requirements, inconsistent file paths, contradictory constraints, etc.), you MUST point out the contradiction promptly and require the parent agent to clarify before executing."),
39
48
  Message.User("{{task}}"),
40
49
  ],
41
50
  permissions: {
@@ -46,11 +55,14 @@ export const DEFAULT_SUBAGENT_DEFINITION = {
46
55
  },
47
56
  function: {
48
57
  name: "sub_agent_default",
49
- description: "通用子 Agent,可独立完成各类任务。⚠️ 委派任务时必须提供完整的任务上下文,包括所有必要的背景信息、文件路径、具体要求和约束条件,任何信息不明确将导致子 Agent 拒绝执行并要求补充信息。",
58
+ description: "General-purpose sub-agent that can independently complete all kinds of tasks. ⚠️ When delegating a task you must provide complete task context, including all necessary background information, file paths, specific requirements and constraints; any unclear information will cause the sub-agent to refuse execution and ask for more information.",
50
59
  parameters: {
51
60
  type: "object",
52
61
  properties: {
53
- task: { type: "string", description: "完整的任务描述,必须包含所有必要的背景、目标、约束条件和上下文信息。任何不明确的信息将导致子 Agent 拒绝执行。" },
62
+ task: {
63
+ type: "string",
64
+ description: "Complete task description; must include all necessary background, goals, constraints and context. Any unclear information will cause the sub-agent to refuse execution.",
65
+ },
54
66
  },
55
67
  required: ["task"],
56
68
  additionalProperties: false,
@@ -68,21 +80,24 @@ export const DEFAULT_APP_CONFIG = {
68
80
  name: "OpenAI",
69
81
  apiKey: "",
70
82
  baseUrl: "https://api.openai.com/v1",
71
- description: "OpenAI API 端点",
83
+ description: "OpenAI API endpoint",
72
84
  },
73
85
  {
74
86
  id: "bigmodelcn",
75
- name: "BigModelCN (智谱AI)",
87
+ name: "BigModelCN (Zhipu AI)",
76
88
  apiKey: "",
77
89
  baseUrl: "https://open.bigmodel.cn/api/paas/v4",
78
- description: "智谱AI大模型端点",
90
+ description: "Zhipu AI large-model endpoint",
79
91
  },
80
92
  {
81
93
  id: "deepseek",
82
94
  name: "DeepSeek",
83
95
  apiKey: "",
84
96
  baseUrl: "https://api.deepseek.com/v1",
85
- description: "DeepSeek API 端点",
97
+ description: "DeepSeek API endpoint (supports the Files API: local files are uploaded and then referenced by file_id)",
98
+ // 唯一声明了 Files API 能力的出厂端点;其余端点本地文件走 base64 内联。
99
+ // 判断依据是能力位而非端点 id,用户自建端点只要声明即可享受上传。
100
+ capabilities: { filesApi: true },
86
101
  },
87
102
  ],
88
103
  // 模型清单(2026-10-03 依据各厂商官方来源核对):
@@ -95,9 +110,16 @@ export const DEFAULT_APP_CONFIG = {
95
110
  // 标了 `custom: true` 的条目视为用户自有,原样保留。实现见
96
111
  // ConfigManager.syncManagedModels。
97
112
  //
98
- // maxContextTokens 是「任务迁移(交接)触发阈值」,不是模型的真实上下文窗口:
99
- // 迁移判断只看 API 响应返回的 usage.prompt_tokens。窗口 ≥1M 的模型统一取 250K
100
- // (约 25%),glm-4.7-flash 窗口仅 200K,取 100K。
113
+ // tokenThresholds 的两条线都与模型的真实上下文窗口无关:
114
+ // handoff(软线,交接触发)与 guard(硬线,请求前强行阻断)。
115
+ // 出厂取值:窗口 ≥1M 的模型统一 handoff=250K / guard=375K(约窗口的 25% / 37.5%),
116
+ // glm-4.7-flash 窗口仅 200K,取 handoff=100K / guard=150K。
117
+ //
118
+ // reasoningPreset:应用层元数据,**SDK 不解释**(既不参与请求参数生成,也不影响运行行为)。
119
+ // 它由客户端(如 CLI)自己定义含义:指向哪张思考档位表、`/think` 能选哪几档。
120
+ // 之所以留在出厂定义里:字段声明与行为消费是两件事,出厂模型需要把它带上,
121
+ // 否则 `syncManagedModels` 会用出厂定义整块覆盖并抹掉应用声明的值。
122
+ // 不写这个字段 = 应用层视作「不可调档」(如 GLM-4.7 强制思考且无 reasoning_effort 参数)。
101
123
  models: [
102
124
  // ---------- OpenAI ----------
103
125
  {
@@ -105,30 +127,33 @@ export const DEFAULT_APP_CONFIG = {
105
127
  name: "GPT-6 Astra",
106
128
  endpointId: "openai",
107
129
  modelName: "gpt-6-astra",
108
- maxContextTokens: 250_000,
130
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
109
131
  defaultParams: {},
110
132
  vision: true,
111
- description: "OpenAI 最强旗舰(2026-09):高级分析、软件工程、深度研究与科学工作",
133
+ reasoningPreset: "openai",
134
+ description: "OpenAI flagship (2026-09): advanced analysis, software engineering, deep research and scientific work",
112
135
  },
113
136
  {
114
137
  id: "gpt-6.1-sol",
115
138
  name: "GPT-6.1 Sol",
116
139
  endpointId: "openai",
117
140
  modelName: "gpt-6.1-sol",
118
- maxContextTokens: 250_000,
141
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
119
142
  defaultParams: {},
120
143
  vision: true,
121
- description: "OpenAI 最新旗舰(2026-09-29):Agentic Coding、计算机操作与文档密集型专业任务",
144
+ reasoningPreset: "openai",
145
+ description: "OpenAI latest flagship (2026-09-29): agentic coding, computer operation and document-intensive professional tasks",
122
146
  },
123
147
  {
124
148
  id: "gpt-6-luna",
125
149
  name: "GPT-6 Luna",
126
150
  endpointId: "openai",
127
151
  modelName: "gpt-6-luna",
128
- maxContextTokens: 250_000,
152
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
129
153
  defaultParams: {},
130
154
  vision: true,
131
- description: "OpenAI GPT-6 系列快速低成本模型:适合高吞吐、低延迟场景",
155
+ reasoningPreset: "openai",
156
+ description: "OpenAI GPT-6 series fast, low-cost model: suited for high-throughput, low-latency scenarios",
132
157
  },
133
158
  // ---------- 智谱 BigModel ----------
134
159
  {
@@ -136,29 +161,32 @@ export const DEFAULT_APP_CONFIG = {
136
161
  name: "GLM-5.3",
137
162
  endpointId: "bigmodelcn",
138
163
  modelName: "glm-5.3",
139
- maxContextTokens: 250_000,
164
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
140
165
  defaultParams: { thinking: { type: "enabled" }, reasoning_effort: "max" },
141
- description: "智谱最新旗舰:复杂软件工程与长程 Agent 任务(强制开启思考,1M 上下文)",
166
+ reasoningPreset: "zhipu-5.3",
167
+ description: "Zhipu latest flagship: complex software engineering and long-horizon agent tasks (thinking always on, 1M context)",
142
168
  },
143
169
  {
144
170
  id: "glm-5.3-flash",
145
171
  name: "GLM-5.3-Flash",
146
172
  endpointId: "bigmodelcn",
147
173
  modelName: "glm-5.3-flash",
148
- maxContextTokens: 250_000,
174
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
149
175
  defaultParams: { thinking: { type: "enabled" }, reasoning_effort: "max" },
150
176
  vision: true,
151
- description: "智谱原生多模态模型(图片/视频/文件):视觉 Coding,1M 上下文",
177
+ reasoningPreset: "zhipu-5.3",
178
+ description: "Zhipu native multimodal model (image/video/file): visual coding, 1M context",
152
179
  },
153
180
  {
154
181
  id: "glm-5.3-flashx",
155
182
  name: "GLM-5.3-FlashX",
156
183
  endpointId: "bigmodelcn",
157
184
  modelName: "glm-5.3-flashx",
158
- maxContextTokens: 250_000,
185
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
159
186
  defaultParams: { thinking: { type: "enabled" }, reasoning_effort: "max" },
160
187
  vision: true,
161
- description: "GLM-5.3-Flash 高速版(200 tokens/s),原生多模态",
188
+ reasoningPreset: "zhipu-5.3",
189
+ description: "GLM-5.3-Flash high-speed edition (200 tokens/s), native multimodal",
162
190
  },
163
191
  {
164
192
  id: "glm-4.7-flash",
@@ -166,9 +194,9 @@ export const DEFAULT_APP_CONFIG = {
166
194
  endpointId: "bigmodelcn",
167
195
  modelName: "glm-4.7-flash",
168
196
  // 该模型真实窗口仅 200K,阈值下调至 100K(约窗口的 50%),留足 response 空间
169
- maxContextTokens: 100_000,
197
+ tokenThresholds: { handoff: 100_000, guard: 150_000 },
170
198
  defaultParams: {},
171
- description: "智谱免费文本模型:200K 上下文,适合轻量任务",
199
+ description: "Zhipu free text model: 200K context, suited for lightweight tasks",
172
200
  },
173
201
  // ---------- DeepSeek ----------
174
202
  {
@@ -176,10 +204,11 @@ export const DEFAULT_APP_CONFIG = {
176
204
  name: "DeepSeek-V4.1-Flash",
177
205
  endpointId: "deepseek",
178
206
  modelName: "deepseek-flash",
179
- maxContextTokens: 250_000,
207
+ tokenThresholds: { handoff: 250_000, guard: 375_000 },
180
208
  defaultParams: { thinking: { type: "enabled" } },
181
209
  vision: true,
182
- description: "DeepSeek 旗舰(2026-09-10):552B MoE 非对称架构,原生多模态,1M 上下文",
210
+ reasoningPreset: "deepseek",
211
+ description: "DeepSeek flagship (2026-09-10): 552B MoE asymmetric architecture, native multimodal, 1M context",
183
212
  },
184
213
  ],
185
214
  imageModels: [
@@ -206,12 +235,16 @@ export const DEFAULT_APP_CONFIG = {
206
235
  defaultSize: "1024x1024",
207
236
  },
208
237
  ],
209
- defaultModel: "deepseek-flash",
210
238
  defaultImageModel: "cogview-4",
211
239
  defaultAgent: "default",
212
240
  defaultMigrationModel: "deepseek-flash",
213
241
  // 工具输出上限(字符数),与 DEFAULT_MAX_TOOL_OUTPUT 保持一致
214
242
  maxToolOutput: 32_768,
243
+ // 中断策略:出厂取「保留已输出的内容」—— 中断后模型能接着半截往下说,
244
+ // 而不是「失忆重来」(core 的库级默认是 drop,产品层认为那是坑);
245
+ // 工具轮次保持整轮进出(fill),服务端要求 tool_calls 与结果一一配对。
246
+ abortedMessageStrategy: "keep",
247
+ abortedToolRoundStrategy: "fill",
215
248
  };
216
249
  // ---------------------------------------------------------------------------
217
250
  // 默认 MCP 配置(socket-pty 终端 MCP + chrome-devtools 浏览器调试 MCP)
@@ -230,13 +263,13 @@ export const DEFAULT_MCP_CONFIG = {
230
263
  type: "stdio",
231
264
  command: "npx",
232
265
  args: ["-y", "@ai-zen/socket-pty", "mcp"],
233
- description: "可托管的伪终端(pty):spawn/read/wait/write/resize/status/kill",
266
+ description: "Manageable pseudo-terminal (pty): spawn/read/wait/write/resize/status/kill",
234
267
  },
235
268
  "chrome-devtools": {
236
269
  type: "stdio",
237
270
  command: "npx",
238
271
  args: ["-y", "chrome-devtools-mcp@latest"],
239
- description: "Chrome DevTools 浏览器调试与自动化(Google chrome-devtools-mcp):页面导航、性能追踪、网络与控制台检查、截图等",
272
+ description: "Chrome DevTools browser debugging and automation (Google chrome-devtools-mcp): page navigation, performance tracing, network and console inspection, screenshots, etc.",
240
273
  },
241
274
  },
242
275
  };
@@ -251,10 +284,4 @@ export const DEFAULT_MCP_CONFIG = {
251
284
  * ~/.ai-zen/cli/ ← CLI 运行时
252
285
  * ~/.ai-zen/desktop/ ← Desktop 运行时(未来)
253
286
  */
254
- export const CONFIG_SUB_DIRS = [
255
- "agents",
256
- "sub-agents",
257
- "skills",
258
- "tools",
259
- "mcp-oauth",
260
- ];
287
+ export const CONFIG_SUB_DIRS = ["agents", "sub-agents", "skills", "tools", "mcp-oauth"];
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 出厂 Skill 资产 —— 随 SDK 版本释放到 `<basePath>/skills/<id>/SKILL.md`。
3
+ *
4
+ * 为什么以 TS 字符串常量内联、而不是独立 .md 文件:
5
+ * SDK 用 `tsc` 直接编译,不拷贝非 TS 资源;内容内联后 `dist/` 天然携带,
6
+ * 无需额外打包步骤,也不依赖包内相对资源路径。
7
+ *
8
+ * 覆盖策略(与 `syncManagedModels` 同构):
9
+ * - 磁盘上的 SKILL.md frontmatter 里写了 `custom: "true"` → 视为用户自有,永不被覆盖;
10
+ * - 否则每次 `ConfigManager.bootstrap()` 同步为当前版本内容(模板属于产品行为,
11
+ * 改进了就要让老用户吃到)。
12
+ */
13
+ /** 交接 Skill 的 id(目录名 = frontmatter name) */
14
+ export declare const HANDOFF_SKILL_ID = "handoff";
15
+ /**
16
+ * 交接文档兜底模板。
17
+ *
18
+ * 仅在磁盘上读不到 `handoff` Skill 时使用(用户删除 / 目录不可读)。
19
+ * 它是**保险丝**,不是第二真相源:正常路径下模板一律来自 SKILL.md。
20
+ */
21
+ export declare const FALLBACK_HANDOFF_TEMPLATE: string;
22
+ /** 全部出厂 Skill(顺序无意义,按 id 去重) */
23
+ export declare const FACTORY_SKILLS: readonly {
24
+ id: string;
25
+ content: string;
26
+ }[];
27
+ /**
28
+ * 判断一份 SKILL.md 是否被用户声明为自有。
29
+ *
30
+ * 只检查 frontmatter 区块内的 `custom: true`(允许带引号),
31
+ * 正文里出现同样的字样不生效——避免误判导致模板停止更新。
32
+ */
33
+ export declare function isCustomSkill(content: string): boolean;