@ai-zen/agents-sdk 1.0.0-alpha.22 → 1.0.0-alpha.24

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 (44) hide show
  1. package/CHANGELOG.md +278 -184
  2. package/README.md +13 -0
  3. package/README.zh.md +13 -0
  4. package/dist/agent-plugins/AutoMigratePlugin.js +1 -1
  5. package/dist/agent-plugins/UnknownToolHintPlugin.js +4 -4
  6. package/dist/config/constants.js +24 -24
  7. package/dist/config/factory-skills.js +56 -56
  8. package/dist/runtime/HandoffGuardPlugin.js +2 -2
  9. package/dist/runtime/HandoffService.js +22 -22
  10. package/dist/runtime/createAgent.js +2 -2
  11. package/dist/runtime/createModel.js +3 -3
  12. package/dist/scope/PermissionEvaluator.js +1 -1
  13. package/dist/scope/Scope.js +1 -1
  14. package/dist/scope/plugins/builtin/BatchEditTool.js +8 -8
  15. package/dist/scope/plugins/builtin/CopyTool.js +4 -4
  16. package/dist/scope/plugins/builtin/CwdTool.js +1 -1
  17. package/dist/scope/plugins/builtin/DownloadFileTool.js +8 -8
  18. package/dist/scope/plugins/builtin/EditTool.js +9 -9
  19. package/dist/scope/plugins/builtin/ExecTool.js +8 -8
  20. package/dist/scope/plugins/builtin/ExistTool.js +2 -2
  21. package/dist/scope/plugins/builtin/FindTextTool.js +10 -10
  22. package/dist/scope/plugins/builtin/GenerateImageTool.js +13 -13
  23. package/dist/scope/plugins/builtin/GlobTool.js +4 -4
  24. package/dist/scope/plugins/builtin/InspectFileTool.js +7 -7
  25. package/dist/scope/plugins/builtin/LsTool.js +5 -5
  26. package/dist/scope/plugins/builtin/MkdirTool.js +3 -3
  27. package/dist/scope/plugins/builtin/ReadTool.js +8 -8
  28. package/dist/scope/plugins/builtin/RenameTool.js +3 -3
  29. package/dist/scope/plugins/builtin/RmTool.js +3 -3
  30. package/dist/scope/plugins/builtin/SleepTool.js +6 -6
  31. package/dist/scope/plugins/builtin/SpawnTool.js +9 -9
  32. package/dist/scope/plugins/builtin/ViewImageTool.js +12 -12
  33. package/dist/scope/plugins/builtin/WriteTool.js +3 -3
  34. package/dist/scope/plugins/mcp/McpConnectionManager.js +7 -7
  35. package/dist/scope/plugins/mcp/discover.js +1 -1
  36. package/dist/scope/plugins/mcp/mcpTools.js +29 -29
  37. package/dist/scope/plugins/skills/discover.js +7 -7
  38. package/dist/scope/plugins/skills/skillTools.js +17 -17
  39. package/dist/scope/plugins/subagents/subAgentTools.js +2 -2
  40. package/dist/scope/plugins/usertools/discover.d.ts +8 -3
  41. package/dist/scope/plugins/usertools/discover.js +131 -10
  42. package/dist/shared/content-blocks.js +9 -9
  43. package/dist/shared/errors.js +3 -3
  44. package/package.json +10 -1
@@ -2,23 +2,23 @@ import { CallbackTool, Agent, AgentToolLazy, Message } from "@ai-zen/agents-core
2
2
  import { createDisclosureParam } from "../../disclosure.js";
3
3
  import { readSkill } from "./discover.js";
4
4
  import { promises as fs } from "node:fs";
5
- const EMPTY_HINT = "(当前没有可用的 Skill,请联系用户添加)";
5
+ const EMPTY_HINT = "(No Skills are currently available, please ask the user to add one)";
6
6
  /**
7
7
  * 创建 load_skill 工具。
8
8
  * 枚举所有允许的 skill(不限是否支持子 Agent),由 filteredSkills 提供完整信息。
9
9
  */
10
10
  export function createLoadSkillTool(skillDirs, filteredSkills) {
11
11
  const ids = filteredSkills.map((s) => s.id);
12
- const param = createDisclosureParam(ids, "选择一个 Skill", EMPTY_HINT);
12
+ const param = createDisclosureParam(ids, "Select a Skill", EMPTY_HINT);
13
13
  // 拼接各 skill 的描述供 LLM 参考
14
14
  const skillDescriptions = filteredSkills
15
- .map((s) => ` - ${s.id}: ${s.description || "无描述"}`)
15
+ .map((s) => ` - ${s.id}: ${s.description || "No description"}`)
16
16
  .join("\n");
17
- const skillIdDescription = `${param.description}\n\n各 Skill 说明:\n${skillDescriptions || " 无可用 Skill"}`;
17
+ const skillIdDescription = `${param.description}\n\nSkill descriptions:\n${skillDescriptions || " No Skills available"}`;
18
18
  return new CallbackTool({
19
19
  function: {
20
20
  name: "load_skill",
21
- description: "加载指定 Skill 的完整指导文档。Skill 是预制的专业指导,加载后展开到上下文中。",
21
+ description: "Load the full guidance document of a Skill. A Skill is pre-authored expert guidance that is expanded into the context once loaded.",
22
22
  parameters: {
23
23
  type: "object",
24
24
  properties: {
@@ -36,7 +36,7 @@ export function createLoadSkillTool(skillDirs, filteredSkills) {
36
36
  const skillId = input.skill_id;
37
37
  const skill = await readSkill(skillDirs, skillId);
38
38
  if (!skill) {
39
- return `❌ Skill "${skillId}" 不存在,请确认名称是否正确`;
39
+ return `❌ Skill "${skillId}" not found, please verify the name`;
40
40
  }
41
41
  // 扫描 skill 目录下的文件列表
42
42
  let fileList = "";
@@ -46,18 +46,18 @@ export function createLoadSkillTool(skillDirs, filteredSkills) {
46
46
  const suffix = e.isDirectory() ? "/" : "";
47
47
  return ` - ${e.name}${suffix}`;
48
48
  });
49
- fileList = `\n\nSkill 目录文件列表:\n${files.join("\n")}`;
49
+ fileList = `\n\nSkill directory files:\n${files.join("\n")}`;
50
50
  }
51
51
  catch {
52
52
  fileList = "";
53
53
  }
54
54
  return [
55
- `Skill "${skillId}" 已加载:`,
55
+ `Skill "${skillId}" loaded:`,
56
56
  ``,
57
- `Skill 目录路径: ${skill.dirPath}`,
57
+ `Skill directory path: ${skill.dirPath}`,
58
58
  fileList,
59
59
  ``,
60
- `--- Skill 内容开始 ---`,
60
+ `--- Skill content starts ---`,
61
61
  skill.content,
62
62
  ].join("\n");
63
63
  },
@@ -76,16 +76,16 @@ export function createCallSkillSubAgentTool(skillDirs, filteredSkills) {
76
76
  // 只保留支持子 Agent 模式的 skill
77
77
  const subAgentSkills = filteredSkills.filter((s) => s.subAgent);
78
78
  const ids = subAgentSkills.map((s) => s.id);
79
- const param = createDisclosureParam(ids, "选择一个 Skill(支持子 Agent)", EMPTY_HINT);
79
+ const param = createDisclosureParam(ids, "Select a Skill that supports SubAgent mode", EMPTY_HINT);
80
80
  // 拼接各 skill 的描述供 LLM 参考
81
81
  const skillDescriptions = subAgentSkills
82
- .map((s) => ` - ${s.id}: ${s.description || "无描述"}`)
82
+ .map((s) => ` - ${s.id}: ${s.description || "No description"}`)
83
83
  .join("\n");
84
- const skillIdDescription = `${param.description}\n\n各 Skill 说明:\n${skillDescriptions || " 无可用 Skill"}`;
84
+ const skillIdDescription = `${param.description}\n\nSkill descriptions:\n${skillDescriptions || " No Skills available"}`;
85
85
  return new AgentToolLazy({
86
86
  function: {
87
87
  name: "call_skill_sub_agent",
88
- description: "将任务委派给指定的 Skill 子 Agent,由其独立完成并返回结果。",
88
+ description: "Delegate a task to the specified Skill SubAgent, which completes it independently and returns the result.",
89
89
  parameters: {
90
90
  type: "object",
91
91
  properties: {
@@ -96,7 +96,7 @@ export function createCallSkillSubAgentTool(skillDirs, filteredSkills) {
96
96
  },
97
97
  task: {
98
98
  type: "string",
99
- description: "要委派给子 Agent 完成的任务描述",
99
+ description: "Task description to delegate to the SubAgent",
100
100
  },
101
101
  },
102
102
  required: ["skill_id", "task"],
@@ -110,10 +110,10 @@ export function createCallSkillSubAgentTool(skillDirs, filteredSkills) {
110
110
  const task = parsedArgs.task;
111
111
  const skill = await readSkill(skillDirs, skillId);
112
112
  if (!skill) {
113
- throw new Error(`❌ Skill "${skillId}" 不存在,请确认名称是否正确`);
113
+ throw new Error(`❌ Skill "${skillId}" not found, please verify the name`);
114
114
  }
115
115
  if (!skill.subAgent) {
116
- throw new Error(`Skill "${skillId}" 不支持子 Agent 模式,请使用 load_skill 加载指导后自行处理`);
116
+ throw new Error(`Skill "${skillId}" does not support SubAgent mode, use load_skill to load its guidance and handle the task yourself`);
117
117
  }
118
118
  // 沿用父 Agent 的工具能力(不做权限过滤),剔除自身以防自递归
119
119
  const parentAgent = ctx.agent;
@@ -8,7 +8,7 @@ import { createModel } from "../../../runtime/createModel.js";
8
8
  */
9
9
  export function createSubAgentTool(def, scope) {
10
10
  if (!def.function) {
11
- throw new Error(`Agent "${def.id}" 没有 function 字段,不能作为 SubAgent 工具`);
11
+ throw new Error(`Agent "${def.id}" has no function field, so it cannot be used as a SubAgent tool`);
12
12
  }
13
13
  const selfName = def.function.name;
14
14
  const lazy = new AgentToolLazy({
@@ -33,7 +33,7 @@ export function createSubAgentTool(def, scope) {
33
33
  else {
34
34
  const parent = ctx.agent;
35
35
  if (!parent) {
36
- throw new Error(`SubAgent "${selfName}" 未指定 modelId,且父 Agent 没有可复用的模型`);
36
+ throw new Error(`SubAgent "${selfName}" does not specify a modelId, and the parent Agent has no reusable model`);
37
37
  }
38
38
  client = parent.client;
39
39
  model = parent.model;
@@ -1,4 +1,11 @@
1
1
  import { Tool } from "@ai-zen/agents-core";
2
+ /** 单个用户工具文件的加载参数 */
3
+ export interface DiscoverUserToolsOptions {
4
+ /** 静默:不写日志(测试 / 批量探测用) */
5
+ silent?: boolean;
6
+ /** 单文件 import 的超时(毫秒),默认 {@link DEFAULT_IMPORT_TIMEOUT_MS};`0` 表示不限 */
7
+ importTimeoutMs?: number;
8
+ }
2
9
  /**
3
10
  * 扫描多个 tools/ 目录,发现所有 .js / .mjs 文件,动态加载为 Tool 实例。
4
11
  * 使用原生 dynamic import() 加载(在 "type": "module" 下 .js 也是 ESM),
@@ -7,6 +14,4 @@ import { Tool } from "@ai-zen/agents-core";
7
14
  * 按优先级从高到低传入路径列表,同名工具靠前的路径优先(先到先得)。
8
15
  * 按文件名排序以保证确定性。
9
16
  */
10
- export declare function discoverUserTools(paths: string[], options?: {
11
- silent?: boolean;
12
- }): Promise<Tool[]>;
17
+ export declare function discoverUserTools(paths: string[], options?: DiscoverUserToolsOptions): Promise<Tool[]>;
@@ -3,6 +3,114 @@ import { join } from "node:path";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { Tool, CallbackTool } from "@ai-zen/agents-core";
5
5
  import { getLogger } from "../../../shared/logger.js";
6
+ /** 默认的单文件 import 超时:工具目录里不该有需要长过它的模块求值 */
7
+ const DEFAULT_IMPORT_TIMEOUT_MS = 5000;
8
+ // ==================================================================
9
+ // 宿主护栏
10
+ // ==================================================================
11
+ //
12
+ // `import()` 是把文件当模块**求值**,不是把文件当配置读——顶层代码因此拥有宿主进程
13
+ // 的全部权限。这里是有过真实事故的:用户把一个一次性开发脚本(无参数时
14
+ // `process.exit(2)`)放进了 tools 目录,于是**每次启动都在初始化途中被这个脚本杀掉**,
15
+ // 界面上只剩最后一帧,看着像「卡住不启动」;另有脚本在顶层直接 `writeFileSync`,
16
+ // 每次启动都在静默重写项目资产。
17
+ //
18
+ // 能挡住的:
19
+ // · `process.exit` / `process.abort` → 换成抛异常,落进 `loadToolFile` 的 try/catch;
20
+ // · `console.log / info / debug` → 改指 stderr,不撕宿主的 stdout(TUI 画面);
21
+ // · 顶层 await 永不 settle(异步挂死)→ 超时放弃该文件。
22
+ //
23
+ // **挡不住**的(只有进程隔离能解,而那正是 MCP 的职责):
24
+ // · 顶层同步死循环——事件循环被占,连超时定时器都不会跑;
25
+ // · `process.kill(process.pid)` 这类原生自杀。
26
+ //
27
+ // 所以 tools/ 的定位是**可信的本地扩展**;不可信的代码请写成 MCP 服务器。
28
+ /** 正在被 import 的文件(护栏回报错误时用它定位) */
29
+ let importingFile = null;
30
+ /** 用户文件里调 `process.exit()` / `process.abort()` 时抛这个 —— 落进 loadToolFile 的 catch */
31
+ class UserToolExitError extends Error {
32
+ constructor(code) {
33
+ super(`process.exit(${code ?? "?"}) was called while evaluating a user tool file` +
34
+ (importingFile ? `: ${importingFile}` : "") +
35
+ " — the call was suppressed to keep the host process alive");
36
+ this.name = "UserToolExitError";
37
+ }
38
+ }
39
+ /**
40
+ * 工具模块的静态判据:ESM 里没有 `export` 就**不可能**导出 Tool。
41
+ *
42
+ * 这个预检能把「放错目录的普通脚本」挡在求值之前——没有 export 的模块本来也会被
43
+ * `normalizeToolExport` 判成 null,区别只在于:那时它已经被求值、副作用已经发生了。
44
+ * 实测那 4 个一次性脚本的 export 计数全为 0。
45
+ *
46
+ * 读不出来(权限 / 编码 / 不是普通文件)时放行:预检只为省掉明显的白跑,
47
+ * 不该因为读不了文件就把正常工具挡住。
48
+ */
49
+ const TOOL_MODULE_HINT = /\bexport\b/;
50
+ async function mayExportTool(filepath) {
51
+ try {
52
+ return TOOL_MODULE_HINT.test(await fs.readFile(filepath, "utf-8"));
53
+ }
54
+ catch {
55
+ return true;
56
+ }
57
+ }
58
+ /**
59
+ * 装上宿主护栏,返回还原函数。
60
+ *
61
+ * 保存的是**当前**值而非模块加载时的值,且由调用方在 finally 里还原——
62
+ * 不能常驻,否则宿主自己也永远退不出去。
63
+ */
64
+ function installHostGuards() {
65
+ const realExit = process.exit;
66
+ const realAbort = process.abort;
67
+ const realLog = console.log;
68
+ const realInfo = console.info;
69
+ const realDebug = console.debug;
70
+ process.exit = ((code) => {
71
+ throw new UserToolExitError(code);
72
+ });
73
+ process.abort = (() => {
74
+ throw new UserToolExitError();
75
+ });
76
+ // 用户脚本的输出一律走 stderr:stdout 属于宿主的界面(Ink 的帧),不能让扩展写
77
+ console.log = (...args) => console.error(...args);
78
+ console.info = console.log;
79
+ console.debug = console.log;
80
+ return () => {
81
+ process.exit = realExit;
82
+ process.abort = realAbort;
83
+ console.log = realLog;
84
+ console.info = realInfo;
85
+ console.debug = realDebug;
86
+ };
87
+ }
88
+ /**
89
+ * `import()` + 超时。
90
+ *
91
+ * 超时只是「不再等它」:ESM 求值**不可取消**,该模块随后仍可能被求值完并产生副作用,
92
+ * 因此超时只记告警、不声称已终止。真正的隔离需要独立进程(即 MCP)。
93
+ */
94
+ async function importWithTimeout(url, timeoutMs) {
95
+ if (timeoutMs <= 0)
96
+ return import(url);
97
+ let timer;
98
+ const timeout = new Promise((_, reject) => {
99
+ timer = setTimeout(() => reject(new Error(`import timed out after ${timeoutMs}ms`)), timeoutMs);
100
+ });
101
+ try {
102
+ return await Promise.race([import(url), timeout]);
103
+ }
104
+ finally {
105
+ if (timer)
106
+ clearTimeout(timer);
107
+ }
108
+ }
109
+ /** 「这个文件被拒了」的出口:只走 logger,怎么展示是宿主的事 */
110
+ function reportReject(file, reason, opts, level = "warn") {
111
+ if (!opts.silent)
112
+ getLogger()[level](`[usertools] ${file} — ${reason}`);
113
+ }
6
114
  /**
7
115
  * 扫描多个 tools/ 目录,发现所有 .js / .mjs 文件,动态加载为 Tool 实例。
8
116
  * 使用原生 dynamic import() 加载(在 "type": "module" 下 .js 也是 ESM),
@@ -11,8 +119,7 @@ import { getLogger } from "../../../shared/logger.js";
11
119
  * 按优先级从高到低传入路径列表,同名工具靠前的路径优先(先到先得)。
12
120
  * 按文件名排序以保证确定性。
13
121
  */
14
- export async function discoverUserTools(paths, options) {
15
- const silent = options?.silent ?? false;
122
+ export async function discoverUserTools(paths, options = {}) {
16
123
  const seen = new Set();
17
124
  const tools = [];
18
125
  for (const dir of paths) {
@@ -35,7 +142,7 @@ export async function discoverUserTools(paths, options) {
35
142
  if (!seen.has(name)) {
36
143
  seen.add(name);
37
144
  try {
38
- const tool = await loadToolFile(join(dir, name + ext), silent);
145
+ const tool = await loadToolFile(join(dir, name + ext), options);
39
146
  if (tool) {
40
147
  tools.push(tool);
41
148
  }
@@ -60,24 +167,38 @@ export async function discoverUserTools(paths, options) {
60
167
  *
61
168
  * 使用原生 dynamic import() 加载 ESM 模块。每次调用添加时间戳 querystring
62
169
  * 防止模块缓存,确保 refresh() 能重新加载。
170
+ *
171
+ * 三道护栏(顺序有意义):
172
+ * 1. **先做静态预检**:没有 `export` 的文件根本不 import(连求值的机会都不给);
173
+ * 2. **再装宿主护栏**:import 期间 `process.exit` / console 输出被接管;
174
+ * 3. **超时**:异步挂死的文件不再拖住启动。
63
175
  */
64
- async function loadToolFile(filepath, silent) {
176
+ async function loadToolFile(filepath, opts) {
177
+ if (!(await mayExportTool(filepath))) {
178
+ reportReject(filepath, "no `export` in source — not a tool module, skipped without evaluating", opts);
179
+ return null;
180
+ }
181
+ const restore = installHostGuards();
182
+ const outerImporting = importingFile;
183
+ importingFile = filepath;
65
184
  try {
66
185
  const url = `${pathToFileURL(filepath).href}?t=${Date.now()}`;
67
- const mod = await import(url);
186
+ const mod = (await importWithTimeout(url, opts.importTimeoutMs ?? DEFAULT_IMPORT_TIMEOUT_MS));
68
187
  // import() 返回模块命名空间对象,取其 default 导出
69
188
  const exported = mod.default ?? mod;
70
189
  if (!exported || (typeof exported === "object" && Object.keys(exported).length === 0)) {
71
190
  return null;
72
191
  }
73
- return normalizeToolExport({ default: exported }, filepath, silent);
192
+ return normalizeToolExport({ default: exported }, filepath, opts.silent);
74
193
  }
75
194
  catch (err) {
76
- if (!silent) {
77
- getLogger().error(`[usertools] 加载工具文件失败: ${filepath} — ${err?.message ?? err}`);
78
- }
195
+ reportReject(filepath, `failed to load — ${err?.message ?? err}`, opts, "error");
79
196
  return null;
80
197
  }
198
+ finally {
199
+ importingFile = outerImporting;
200
+ restore();
201
+ }
81
202
  }
82
203
  // ==================================================================
83
204
  // 导出格式归一化
@@ -110,7 +231,7 @@ function normalizeToolExport(exported, filepath, silent) {
110
231
  });
111
232
  }
112
233
  if (!silent) {
113
- getLogger().error(`[usertools] 无法识别的工具格式: ${filepath}`);
234
+ getLogger().error(`[usertools] Unrecognized tool format: ${filepath}`);
114
235
  }
115
236
  return null;
116
237
  }
@@ -139,7 +139,7 @@ export async function fileToContentSection(input) {
139
139
  // ---- 1. 网络 URL:直接引用,不经上传/内联 ----
140
140
  if ("url" in source) {
141
141
  if (!isRemoteUrl(source.url)) {
142
- throw new Error(`不支持本地 URL(${source.url}):API 服务商无法访问。本地文件请传文件路径,而不是本地链接。`);
142
+ throw new Error(`Unsupported local URL (${source.url}): the API provider cannot access it. For local files pass a file path, not a local link`);
143
143
  }
144
144
  return {
145
145
  section: { type: "image_url", image_url: { url: source.url } },
@@ -160,10 +160,10 @@ export async function fileToContentSection(input) {
160
160
  absPath = path.isAbsolute(source.path) ? source.path : path.resolve(source.path);
161
161
  const st = await fs.stat(absPath);
162
162
  if (!st.isFile())
163
- throw new Error(`"${absPath}" 不是文件。`);
163
+ throw new Error(`"${absPath}" is not a file`);
164
164
  const inferred = mimeOf(absPath);
165
165
  if (!inferred) {
166
- throw new Error(`不支持的文件类型:"${absPath}"(已知类型:${Object.keys(MIME_BY_EXT).join(" ")})`);
166
+ throw new Error(`Unsupported file type: "${absPath}" (known types: ${Object.keys(MIME_BY_EXT).join(" ")})`);
167
167
  }
168
168
  mime = inferred;
169
169
  stat = { mtimeMs: st.mtimeMs, size: st.size };
@@ -198,10 +198,10 @@ export async function fileToContentSection(input) {
198
198
  if (isImage && model && model.vision !== true) {
199
199
  const label = absPath ?? filename;
200
200
  return {
201
- section: textSection(`[图片] ${label}(当前模型不支持图片输入,如需查看请改用视觉模型)`),
201
+ section: textSection(`[Image] ${label} (the current model does not support image input; use a vision-capable model to view it)`),
202
202
  transport: "text",
203
203
  bytes: byteLength,
204
- warning: "当前模型不支持图片输入,已退化为文本提示",
204
+ warning: "The current model does not support image input; degraded to a text hint",
205
205
  };
206
206
  }
207
207
  // ---- 4. 端点支持 Files API:上传(带缓存),失败降级内联 ----
@@ -231,14 +231,14 @@ export async function fileToContentSection(input) {
231
231
  catch (error) {
232
232
  if (signal?.aborted)
233
233
  throw error;
234
- warning = `上传 Files API 失败,已改为 base64 内联:${error?.message ?? error}`;
234
+ warning = `Files API upload failed, falling back to base64 inline: ${error?.message ?? error}`;
235
235
  }
236
236
  }
237
237
  // ---- 5. 内联(base64 data URL)----
238
238
  if (byteLength > maxInline) {
239
- throw new Error(`文件体积 ${(byteLength / 1024 / 1024).toFixed(1)} MiB 超过内联上限 ` +
240
- `${(maxInline / 1024 / 1024).toFixed(1)} MiB,且端点未声明 Files API 能力` +
241
- `(capabilities.filesApi),无法发送。`);
239
+ throw new Error(`File size ${(byteLength / 1024 / 1024).toFixed(1)} MiB exceeds the inline limit of ` +
240
+ `${(maxInline / 1024 / 1024).toFixed(1)} MiB and the endpoint does not declare the Files API capability ` +
241
+ `(capabilities.filesApi), so it cannot be sent`);
242
242
  }
243
243
  // base64 来源直接透传,不重新编码(保证字节级一致,也省一次编解码)
244
244
  const dataUrl = toDataUrl(base64 ?? Buffer.from(ensureBytes()).toString("base64"), mime);
@@ -24,9 +24,9 @@ export class ContextOverflowError extends Error {
24
24
  /** 被越过的强行阻断阈值(`tokenThresholds.guard`,绝对值) */
25
25
  guardTokens;
26
26
  constructor(promptTokens, guardTokens) {
27
- super(`🛑 上下文严重超限:已用 ${promptTokens} token,超过阻断阈值 ${guardTokens}。` +
28
- `当前对话可能因读入超大文件而失控,已中断,请检查并重新开始。` +
29
- `(如确需更长上下文,请调高 config.json 中该模型的 tokenThresholds.guard。)`);
27
+ super(`🛑 Context critically over the limit: ${promptTokens} tokens used, above the blocking threshold of ${guardTokens}.` +
28
+ ` The conversation may have run away after reading an oversized file, so it has been interrupted — please inspect and start over.` +
29
+ ` (If you really need a longer context, raise tokenThresholds.guard for this model in config.json.)`);
30
30
  this.name = "ContextOverflowError";
31
31
  this.promptTokens = promptTokens;
32
32
  this.guardTokens = guardTokens;
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "@ai-zen/agents-sdk",
3
- "version": "1.0.0-alpha.22",
3
+ "version": "1.0.0-alpha.24",
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",
7
7
  "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ai-zen/agents.git",
11
+ "directory": "packages/sdk"
12
+ },
13
+ "homepage": "https://github.com/ai-zen/agents/tree/main/packages/sdk#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/ai-zen/agents/issues"
16
+ },
8
17
  "keywords": [
9
18
  "ai",
10
19
  "agent",