@ai-zen/agents-sdk 1.0.0-alpha.0 → 1.0.0-alpha.10

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 +153 -0
  2. package/README.md +15 -14
  3. package/README.zh.md +15 -14
  4. package/dist/agent-plugins/AutoMigratePlugin.d.ts +33 -7
  5. package/dist/agent-plugins/AutoMigratePlugin.js +20 -6
  6. package/dist/agent-plugins/ContextGuardPlugin.d.ts +13 -3
  7. package/dist/agent-plugins/ContextGuardPlugin.js +9 -6
  8. package/dist/config/ConfigManager.d.ts +29 -1
  9. package/dist/config/ConfigManager.js +84 -2
  10. package/dist/config/constants.d.ts +3 -1
  11. package/dist/config/constants.js +77 -39
  12. package/dist/config/factory-skills.d.ts +33 -0
  13. package/dist/config/factory-skills.js +126 -0
  14. package/dist/index.d.ts +6 -4
  15. package/dist/index.js +5 -2
  16. package/dist/runtime/HandoffGuardPlugin.d.ts +35 -0
  17. package/dist/runtime/HandoffGuardPlugin.js +65 -0
  18. package/dist/runtime/HandoffService.d.ts +199 -0
  19. package/dist/runtime/HandoffService.js +372 -0
  20. package/dist/scope/plugins/builtin/BatchEditTool.js +1 -1
  21. package/dist/scope/plugins/builtin/DownloadFileTool.js +1 -1
  22. package/dist/scope/plugins/builtin/ExecTool.js +2 -2
  23. package/dist/scope/plugins/builtin/FindTextTool.js +6 -6
  24. package/dist/scope/plugins/builtin/GenerateImageTool.d.ts +1 -1
  25. package/dist/scope/plugins/builtin/GenerateImageTool.js +7 -7
  26. package/dist/scope/plugins/builtin/GlobTool.js +1 -1
  27. package/dist/scope/plugins/builtin/InspectFileTool.d.ts +2 -2
  28. package/dist/scope/plugins/builtin/InspectFileTool.js +5 -5
  29. package/dist/scope/plugins/builtin/LsTool.js +1 -1
  30. package/dist/scope/plugins/builtin/{ReadFileTool.d.ts → ReadTool.d.ts} +1 -1
  31. package/dist/scope/plugins/builtin/{ReadFileTool.js → ReadTool.js} +3 -3
  32. package/dist/scope/plugins/builtin/{ExecAsyncTool.d.ts → SpawnTool.d.ts} +1 -1
  33. package/dist/scope/plugins/builtin/{ExecAsyncTool.js → SpawnTool.js} +2 -2
  34. package/dist/scope/plugins/builtin/ViewImageTool.js +2 -2
  35. package/dist/scope/plugins/builtin/{WriteFileTool.d.ts → WriteTool.d.ts} +1 -1
  36. package/dist/scope/plugins/builtin/{WriteFileTool.js → WriteTool.js} +2 -2
  37. package/dist/scope/plugins/builtin/index.d.ts +4 -4
  38. package/dist/scope/plugins/builtin/index.js +7 -7
  39. package/dist/scope/plugins/builtin/outputGuard.d.ts +2 -2
  40. package/dist/scope/plugins/builtin/outputGuard.js +1 -1
  41. package/dist/types/index.d.ts +24 -3
  42. package/package.json +3 -3
  43. package/dist/runtime/TaskMigrationService.d.ts +0 -128
  44. package/dist/runtime/TaskMigrationService.js +0 -211
@@ -3,7 +3,7 @@ import { SdkCallbackTool } from "./SdkCallbackTool.js";
3
3
  /**
4
4
  * 根据文字描述生成图片。**统一返回字符串**(JSON,含图片 URL 列表):
5
5
  * 生成结果如何处理(查看/下载/转发)由模型与上层自由决定——
6
- * 需要让模型看图时,模型可主动调用 viewImage(URL);需要保存时用 downloadFile。
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: "generateImage",
18
- description: "根据文字描述生成图片,返回图片 URL 列表(JSON)。如需查看图片内容,请用 viewImage 工具(传入图片 URL);如需保存到本地,用 downloadFile 下载。",
17
+ name: "generate_image",
18
+ description: "根据文字描述生成图片,返回图片 URL 列表(JSON)。如需查看图片内容,请用 view_image 工具(传入图片 URL);如需保存到本地,用 download_file 下载。",
19
19
  parameters: {
20
20
  type: "object",
21
21
  properties: {
@@ -25,7 +25,7 @@ export class GenerateImageTool extends SdkCallbackTool {
25
25
  },
26
26
  model: {
27
27
  type: "string",
28
- description: "图片模型 ID,不指定则使用配置中的默认图片模型。配置中的图片模型可通过 'aiz config show' 查看。",
28
+ description: "图片模型 ID,不指定则使用配置中的默认图片模型;若指定的模型不存在,本工具会返回当前可用的模型列表。",
29
29
  },
30
30
  size: {
31
31
  type: "string",
@@ -99,15 +99,15 @@ export class GenerateImageTool extends SdkCallbackTool {
99
99
  .map((img) => img.url)
100
100
  .filter((url) => !!url);
101
101
  // 统一返回字符串(JSON):生成结果如何处理(查看/下载/转发)由模型与上层自由决定,
102
- // 不替模型做「看或不看」的假设。需要让模型看图 → 模型可主动调用 viewImage(URL);
103
- // 需要保存 → downloadFile 下载。
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天。如需查看图片内容,可用 viewImage 工具(传入图片 URL);如需保存,可用 downloadFile 下载。",
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),可用 readFile 分批读取;` +
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
- * 定位与 readFile 的 range 配套:大文件先看结构(有多少行、每行多长),
8
- * 再决定 readFile 的读取范围。流式扫描,故不受 readFile 的 300KB 读取阈值限制。
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
- * 定位与 readFile 的 range 配套:大文件先看结构(有多少行、每行多长),
10
- * 再决定 readFile 的读取范围。流式扫描,故不受 readFile 的 300KB 读取阈值限制。
9
+ * 定位与 read 的 range 配套:大文件先看结构(有多少行、每行多长),
10
+ * 再决定 read 的读取范围。流式扫描,故不受 read 的 300KB 读取阈值限制。
11
11
  */
12
12
  export class InspectFileTool extends SdkCallbackTool {
13
13
  function = {
14
- name: "inspectFile",
15
- description: "勘察文件的结构概况:总行数、总字符数、最长行的列数及其行索引、平均列数、行尾类型(LF/CRLF)。可选返回每行的列数映射。适用于在 readFile 之前先了解文件规模,再决定用 range 读取哪一段。仅做流式扫描,不受 readFile 的 300KB 读取阈值限制。",
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
- `建议改用 findText 定位后再按 range 分段读取。`,
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),可用 readFile 分批读取;` +
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 ReadFileTool extends SdkCallbackTool {
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 ReadFileTool extends SdkCallbackTool {
4
+ export class ReadTool extends SdkCallbackTool {
5
5
  function = {
6
- name: "readFile",
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: "readFile",
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 ExecAsyncTool extends SdkCallbackTool {
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 ExecAsyncTool extends SdkCallbackTool {
3
+ export class SpawnTool extends SdkCallbackTool {
4
4
  function = {
5
- name: "exec_async",
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: "viewImage",
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 "viewImage 需要提供 path_or_url 参数(本地图片路径或 http(s) URL)。";
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 WriteFileTool extends SdkCallbackTool {
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 WriteFileTool extends SdkCallbackTool {
4
+ export class WriteTool extends SdkCallbackTool {
5
5
  function = {
6
- name: "writeFile",
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 { ReadFileTool } from "./ReadFileTool.js";
4
+ import { ReadTool } from "./ReadTool.js";
5
5
  import { InspectFileTool } from "./InspectFileTool.js";
6
- import { WriteFileTool } from "./WriteFileTool.js";
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 { ExecAsyncTool } from "./ExecAsyncTool.js";
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, ReadFileTool, InspectFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, ViewImageTool, GenerateImageTool, };
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 { ReadFileTool } from "./ReadFileTool.js";
2
+ import { ReadTool } from "./ReadTool.js";
3
3
  import { InspectFileTool } from "./InspectFileTool.js";
4
- import { WriteFileTool } from "./WriteFileTool.js";
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 { ExecAsyncTool } from "./ExecAsyncTool.js";
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
- ReadFileTool,
31
+ ReadTool,
32
32
  InspectFileTool,
33
- WriteFileTool,
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
- ExecAsyncTool,
46
+ SpawnTool,
47
47
  SleepTool,
48
48
  ViewImageTool,
49
49
  GenerateImageTool,
50
50
  ];
51
- export { CwdTool, ReadFileTool, InspectFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, ViewImageTool, GenerateImageTool, };
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
- * 落盘内容组织(可选)。缺省表示"只警告、不落盘"(如 readFile)。
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
- * 适用于结果按出现顺序排列、尾部参考价值低的工具(如 findText)。
64
+ * 适用于结果按出现顺序排列、尾部参考价值低的工具(如 find_text)。
65
65
  */
66
66
  export declare function headPreview(text: string, size?: number): HeadPreview;
67
67
  /** 头尾预览 */
@@ -42,7 +42,7 @@ export async function guardOutput(options) {
42
42
  /**
43
43
  * 生成头部预览:最多 size 字符。
44
44
  *
45
- * 适用于结果按出现顺序排列、尾部参考价值低的工具(如 findText)。
45
+ * 适用于结果按出现顺序排列、尾部参考价值低的工具(如 find_text)。
46
46
  */
47
47
  export function headPreview(text, size = 1000) {
48
48
  if (text.length <= size)
@@ -26,13 +26,27 @@ export interface Model {
26
26
  name: string;
27
27
  endpointId: string;
28
28
  modelName?: string;
29
+ /**
30
+ * 任务迁移(交接)触发阈值 —— **不是**模型的真实上下文窗口。
31
+ *
32
+ * AutoMigratePlugin 不估算、不学习:只在 API 响应返回后,用 `usage.prompt_tokens`
33
+ * 与该值比较,超过即触发交接迁移。建议取模型真实窗口的约 25%,为 response 留出空间。
34
+ */
29
35
  maxContextTokens: number;
36
+ /** 旧版字符数阈值(兼容迁移) */
30
37
  maxContextChars?: number;
31
38
  defaultParams?: Record<string, unknown>;
32
- /** 是否支持图片输入(视觉模型)。看图工具(viewImage)仅对视觉模型启用;generateImage 是否返回图片内容块也据此判断 */
39
+ /** 是否支持图片输入(视觉模型)。看图工具(view_image)仅对视觉模型启用;generate_image 是否返回图片内容块也据此判断 */
33
40
  vision?: boolean;
34
41
  description?: string;
35
42
  version?: number;
43
+ /**
44
+ * 是否用户自定义。
45
+ *
46
+ * 为 true 时 SDK 初始化不会用出厂定义替换该模型;缺省(或 false)视为出厂托管,
47
+ * 初始化时会与 DEFAULT_APP_CONFIG.models 同步(出厂清单为准)。
48
+ */
49
+ custom?: boolean;
36
50
  }
37
51
  /** Agent 定义,有 function 字段时为 SubAgent */
38
52
  export interface AgentDefinition {
@@ -64,6 +78,13 @@ export interface ImageModel {
64
78
  defaultSize?: string;
65
79
  defaultQuality?: string;
66
80
  version?: number;
81
+ /**
82
+ * 是否用户自定义。
83
+ *
84
+ * 为 true 时 SDK 初始化不会用出厂定义替换该模型;缺省(或 false)视为出厂托管,
85
+ * 初始化时会与 DEFAULT_APP_CONFIG.imageModels 同步(出厂清单为准)。
86
+ */
87
+ custom?: boolean;
67
88
  }
68
89
  /** config.json 结构 */
69
90
  export interface AppConfig {
@@ -83,7 +104,7 @@ export interface AppConfig {
83
104
  *
84
105
  * 工具本次输出超过该值时,由工具自身的保护策略处置(落盘或仅警告),
85
106
  * 避免超长输出撑爆上下文。仅作用于"输出",与工具的读取阈值无关
86
- * (如 readFile/findText 对 300KB 文件的读取上限)。
107
+ * (如 read/find_text 对 300KB 文件的读取上限)。
87
108
  */
88
109
  maxToolOutput?: number;
89
110
  }
@@ -91,7 +112,7 @@ export interface AppConfig {
91
112
  * 工具环境 — Scope 的能力插件在实例化内置工具时注入的环境信息。
92
113
  *
93
114
  * cwd 是相对路径解析的基准(每个 Scope 对应一个工作目录);
94
- * config 供需要模型/端点配置的工具(如 generateImage)使用。
115
+ * config 供需要模型/端点配置的工具(如 generate_image)使用。
95
116
  */
96
117
  export interface ToolEnv {
97
118
  /** 当前工作目录 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-zen/agents-sdk",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.10",
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.5.1",
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",
@@ -1,128 +0,0 @@
1
- import { AgentNS } from "@ai-zen/agents-core";
2
- import type OpenAI from "openai";
3
- import { type Logger } from "../shared/logger.js";
4
- import type { SdkAgent } from "./SdkAgent.js";
5
- /**
6
- * 迁移上下文 — 贯穿「迁移前 → 生成交接文档 → 迁移后」的结构化数据。
7
- *
8
- * 供 `TaskMigrationService.migrate` 与钩子(`onBeforeMigrate` / `onMigrated`)使用。
9
- * 手动迁移与自动迁移共用同一上下文结构,保证上层(CLI)行为一致。
10
- */
11
- export interface MigrationContext {
12
- /** 当前对话 Agent(引用不变,仅替换消息列表) */
13
- agent: SdkAgent;
14
- /** 生成交接文档所用模型名 */
15
- model: string;
16
- /** 当前 prompt token 用量(自动迁移时由 AutoMigratePlugin 提供;手动迁移可省略) */
17
- promptTokens?: number;
18
- /** 上下文阈值(自动迁移时由 AutoMigratePlugin 提供;手动迁移可省略) */
19
- maxTokens?: number;
20
- /** 序列化后的完整对话历史(迁移输入) */
21
- historyText: string;
22
- /** 迁移前消息总数 */
23
- messageCountBefore: number;
24
- /** 生成的交接文档(迁移完成后填充) */
25
- handoffDoc?: string;
26
- }
27
- /**
28
- * 迁移后的历史处理策略。
29
- *
30
- * - `omit`(默认):将历史消息标记 `omit: true`,仍保留在 `agent.messages` 可审计/回放,但不再发送给模型;
31
- * - `prune`:物理剔除历史,只保留 `definition.messages`(系统提示等模板)+ 追加的对话断点。
32
- */
33
- export type MigrationStrategy = "omit" | "prune";
34
- /**
35
- * 任务迁移服务构造参数。
36
- */
37
- export interface TaskMigrationServiceOptions {
38
- /** 生成交接文档所用客户端(可选;未传则 migrate 时回退到 agent.client) */
39
- client?: OpenAI;
40
- /** 生成交接文档所用模型名(可选;未传则 migrate 时回退到 agent.model) */
41
- model?: string;
42
- /** 生成交接文档所用模型参数(可选;未传则 migrate 时回退到 agent.modelConfig) */
43
- modelConfig?: Record<string, unknown>;
44
- /** 迁移后历史处理策略,默认 `omit`(标记历史保留可审计)。可选 `prune`(物理剔除)。 */
45
- strategy?: MigrationStrategy;
46
- /** 迁移前钩子(服务持有)。迁移开始前触发,此时 agent.messages 仍为完整旧历史 */
47
- onBeforeMigrate?: (ctx: MigrationContext) => void | Promise<void>;
48
- /** 迁移后钩子(服务持有)。迁移完成后触发,交接文档已注入 agent.messages */
49
- onMigrated?: (ctx: MigrationContext) => void | Promise<void>;
50
- /** 可注入日志(可选,默认使用全局单例) */
51
- logger?: Logger;
52
- }
53
- /**
54
- * 任务迁移服务。
55
- *
56
- * 一个服务实例对应一次迁移上下文。它**不持有**任何模型调用——生成交接文档时
57
- * 默认复用传入 `agent`(`SdkAgent`)自身的 `client` / `model` / `modelConfig`,
58
- * 因此无需 Scope、无需独立「迁移 Agent」对象,也无需自建 OpenAI 客户端。
59
- * 如需用不同模型生成交接文档,可在构造时显式传入 `client` / `model` / `modelConfig`,
60
- * 未传则 migrate 时回退到 agent 自带的配置。
61
- *
62
- * 职责:
63
- * 1. 生成交接文档的提示词 / 注入格式(静态纯工具,供上层使用)
64
- * 2. 执行完整迁移(串行化 → 模型生成 → 按策略处理历史 + 追加对话断点),并暴露迁移前后钩子(实例方法)
65
- *
66
- * 设计上,`AutoMigratePlugin` 只负责「何时触发」(检测 token 超限),
67
- * 实际迁移逻辑统一收敛到本服务,从而让手动迁移与自动迁移复用同一条链路。
68
- */
69
- export declare class TaskMigrationService {
70
- static readonly HANDOFF_SECTIONS: {
71
- readonly breakpoint: "## 💬 对话断点";
72
- readonly completed: "## ✅ 已完成的任务";
73
- readonly pending: "## 📋 未完成的任务";
74
- readonly memory: "## 🧠 重要记忆";
75
- readonly files: "## 📁 文件索引";
76
- readonly instructions: "## 🔔 接手指令";
77
- };
78
- private onBeforeMigrate?;
79
- private onMigrated?;
80
- private client?;
81
- private model?;
82
- private modelConfig?;
83
- private strategy;
84
- private logger;
85
- constructor(options?: TaskMigrationServiceOptions);
86
- static createPrompt(): string;
87
- /**
88
- * 生成迁移后追加的「对话断点」消息(role=user):交接文档 + 接手指令。
89
- * 该消息是 omit 迁移方案中新上下文的起点,模型看到的序列为
90
- * `[definition.messages, 断点消息]`(历史消息已被标记 omit,不再发送)。
91
- */
92
- static createPostMessages(handoffDoc: string): AgentNS.Message[];
93
- /**
94
- * 序列化消息为 `[role]: content` 文本,供模型理解完整对话历史。
95
- */
96
- static serializeMessages(messages: AgentNS.Message[]): string;
97
- /**
98
- * 生成交接文档:使用指定的 client / model / modelConfig 带交接 prompt 生成结构化文档。
99
- */
100
- private generateHandoff;
101
- /**
102
- * 执行完整迁移:序列化历史 → 模型生成交接文档 → 按策略处理历史并追加对话断点 → 触发钩子。
103
- *
104
- * 策略(`strategy`,构造函数默认 / 本参数可覆盖):
105
- * - `omit`(默认):`agent.definition.messages`(模板)保留,其余既有历史标记 `omit: true`(仍存于
106
- * `agent.messages` 可审计/回放但不再发送给模型),末尾追加「对话断点」消息。因此 `formatHistory()`
107
- * 发送给模型的是 `[definition.messages, 断点消息]` —— 历史被压缩但并不删除。
108
- * - `prune`:物理剔除历史,只保留 `definition.messages` + 断点消息(即原先的替换行为)。
109
- *
110
- * 设计约束:
111
- * - 不重建 Agent,保留所有引用与插件绑定(仅重建消息列表)
112
- * - 钩子(onBeforeMigrate / onMigrated)抛错会被捕获并记录,**不中断**迁移流程
113
- * - 生成失败 / 未取到交接文档时抛错,此时 `agent.messages` 保持原样(不会被部分修改)
114
- *
115
- * @param params.agent 当前对话 Agent
116
- * @param params.promptTokens 当前 prompt token 用量(可选)
117
- * @param params.maxTokens 上下文阈值(可选)
118
- * @param params.strategy 本次迁移的历史处理策略(可选,覆盖构造时的默认值)
119
- * @returns 完整的迁移上下文(含生成的交接文档)
120
- */
121
- migrate(params: {
122
- agent: SdkAgent;
123
- promptTokens?: number;
124
- maxTokens?: number;
125
- /** 本次迁移的历史处理策略(可选,覆盖构造时的默认值) */
126
- strategy?: MigrationStrategy;
127
- }): Promise<MigrationContext>;
128
- }