@ai-zen/agents-sdk 1.0.0 → 1.2.0-alpha.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.
- package/CHANGELOG.md +40 -0
- package/README.md +5 -17
- package/README.zh.md +5 -17
- package/dist/agent-plugins/AutoMigratePlugin.js +5 -0
- package/dist/agent-plugins/AutoRefreshToolsPlugin.d.ts +28 -1
- package/dist/agent-plugins/AutoRefreshToolsPlugin.js +29 -8
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.d.ts +64 -0
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.js +68 -0
- package/dist/agent-plugins/UnknownToolHintPlugin.d.ts +0 -1
- package/dist/agent-plugins/UnknownToolHintPlugin.js +0 -1
- package/dist/config/ConfigManager.d.ts +11 -7
- package/dist/config/ConfigManager.js +15 -13
- package/dist/config/constants.d.ts +5 -3
- package/dist/config/constants.js +10 -4
- package/dist/config/migrate.d.ts +15 -6
- package/dist/config/migrate.js +16 -12
- package/dist/index.d.ts +12 -4
- package/dist/index.js +9 -4
- package/dist/runtime/HandoffService.d.ts +51 -9
- package/dist/runtime/HandoffService.js +158 -97
- package/dist/runtime/SdkAgent.d.ts +11 -4
- package/dist/runtime/SdkAgent.js +10 -4
- package/dist/runtime/completeOnce.d.ts +43 -0
- package/dist/runtime/completeOnce.js +38 -0
- package/dist/runtime/createAgent.d.ts +27 -1
- package/dist/runtime/createAgent.js +37 -7
- package/dist/runtime/createModel.d.ts +13 -1
- package/dist/runtime/createModel.js +14 -1
- package/dist/runtime/resolveModel.d.ts +93 -0
- package/dist/runtime/resolveModel.js +78 -0
- package/dist/scope/Scope.d.ts +1 -2
- package/dist/scope/Scope.js +1 -1
- package/dist/scope/ScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/allInOne.d.ts +1 -1
- package/dist/scope/plugins/allInOne.js +1 -1
- package/dist/scope/plugins/builtin/ExecTool.js +4 -0
- package/dist/scope/plugins/builtin/SdkCallbackTool.d.ts +1 -2
- package/dist/scope/plugins/builtin/SdkCallbackTool.js +0 -1
- package/dist/scope/plugins/builtin/SpawnTool.js +2 -2
- package/dist/scope/plugins/builtin/ViewImageTool.d.ts +1 -1
- package/dist/scope/plugins/builtin/ViewImageTool.js +1 -1
- package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/mcp/McpScopePlugin.js +1 -1
- package/dist/scope/plugins/mcp/mcpTools.d.ts +1 -1
- package/dist/scope/plugins/mcp/mcpTools.js +4 -4
- package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +1 -1
- package/dist/scope/plugins/skills/discover.js +1 -1
- package/dist/scope/plugins/usertools/discover.d.ts +24 -0
- package/dist/scope/plugins/usertools/discover.js +17 -5
- package/dist/shared/content-blocks.d.ts +6 -9
- package/dist/shared/content-blocks.js +38 -58
- package/dist/types/index.d.ts +76 -30
- package/dist/types/index.js +0 -4
- package/package.json +5 -5
package/dist/config/migrate.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `maxContextChars` 是 token 口径之前的历史遗留,按 `floor(chars / 4)` 折成 tokens
|
|
10
10
|
* (与旧代码的回退算法一致)后并入 `handoff`。
|
|
11
11
|
* 2. **`Model.reasoning` → `Model.reasoningPreset`**
|
|
12
|
-
*
|
|
12
|
+
* 老配置用 `reasoning: { efforts, disable? }` 在模型上声明思考能力,现在是
|
|
13
13
|
* 「引用策略表里的名字」。未标 `custom` 的模型会被出厂定义整块覆盖,但**标了 `custom`
|
|
14
14
|
* 的模型会原地保留**,于是留下一个无人认识的 `reasoning` 死字段,同时因为缺
|
|
15
15
|
* `reasoningPreset` 而默默失去调档能力。这里删掉旧字段,并按**同 id 的出厂模型**
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
*
|
|
18
18
|
* 另有一类「缺省值缺位」的迁移:`Endpoint.capabilities`(见 `normalizeEndpointCapabilities`)。
|
|
19
19
|
*
|
|
20
|
+
* ## `defaultModel` 是**反例**:它不需要迁移,也绝不能清
|
|
21
|
+
*
|
|
22
|
+
* 模型解析是三级(`会话级覆盖 > Agent 定义 > 本字段`,唯一实现在
|
|
23
|
+
* `runtime/resolveModel.ts`),`defaultModel` 就是**全局兜底层**。字段名从未变过,
|
|
24
|
+
* 所以这里**什么都不用搬**:老配置里写着的原样保留、继续生效。绝对不能再清 ——
|
|
25
|
+
* 清掉等于用户升级一次就静默丢一次自己配的兜底模型,而这属于「默认值缺位」里最坏的
|
|
26
|
+
* 一种:丢的是用户明确填过的值。
|
|
27
|
+
*
|
|
20
28
|
* 迁移时机:`ConfigManager.read()` 读出即迁(内存里永远是当前形状);
|
|
21
29
|
* 落盘由 `ensureDefaultConfig()` 负责 —— 它比较迁移结果与磁盘原文,不同才写回,
|
|
22
30
|
* 因此迁移只发生一次,且不会在每次启动时无谓地改写文件。
|
|
@@ -61,7 +69,8 @@ export declare function migrateModelReasoning(model: Model): {
|
|
|
61
69
|
* 图片模型(`imageModels`)既没有上下文阈值、也没有思考概念。
|
|
62
70
|
*
|
|
63
71
|
* 同时做两件字段级收敛:
|
|
64
|
-
* -
|
|
72
|
+
* - **保留** `defaultModel`(三级解析的全局兜底层,见文件头):它不在这里被删、
|
|
73
|
+
* 也不在这里被补 —— 用户没配就没有兜底层,`createAgent` 会给出明确报错;
|
|
65
74
|
* - 补齐中断策略(`abortedMessageStrategy` / `abortedToolRoundStrategy`):把缺失或
|
|
66
75
|
* 非法值写成出厂默认。这样「配置即事实」——文件里写着的就是运行时用的,不再需要
|
|
67
76
|
* 使用方各自 `?? "keep"` 地兵分两路兜底。
|
|
@@ -78,12 +87,12 @@ export declare function normalizeAbortStrategies(config: AppConfig): boolean;
|
|
|
78
87
|
/**
|
|
79
88
|
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
80
89
|
*
|
|
81
|
-
* ##
|
|
90
|
+
* ## 为什么要补
|
|
82
91
|
*
|
|
83
|
-
* `capabilities.filesApi`
|
|
84
|
-
*
|
|
92
|
+
* `capabilities.filesApi` 是后来才引入的能力位 —— 它把 `view_image` 的判定从「端点 id
|
|
93
|
+
* 是不是 `deepseek`」改成「看这一位」,而出厂只有 deepseek 打了 `true`。
|
|
85
94
|
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
86
|
-
* 迁移此前也完全不碰 `endpoints` ——
|
|
95
|
+
* 迁移此前也完全不碰 `endpoints` —— 于是在这之前就已写下的配置,其 deepseek
|
|
87
96
|
* 端点永远缺 `capabilities`,`supportsFilesApi()` 恒为 `false`:
|
|
88
97
|
*
|
|
89
98
|
* · 出厂承诺的「deepseek 走 Files API」对这些用户从未生效;
|
package/dist/config/migrate.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `maxContextChars` 是 token 口径之前的历史遗留,按 `floor(chars / 4)` 折成 tokens
|
|
10
10
|
* (与旧代码的回退算法一致)后并入 `handoff`。
|
|
11
11
|
* 2. **`Model.reasoning` → `Model.reasoningPreset`**
|
|
12
|
-
*
|
|
12
|
+
* 老配置用 `reasoning: { efforts, disable? }` 在模型上声明思考能力,现在是
|
|
13
13
|
* 「引用策略表里的名字」。未标 `custom` 的模型会被出厂定义整块覆盖,但**标了 `custom`
|
|
14
14
|
* 的模型会原地保留**,于是留下一个无人认识的 `reasoning` 死字段,同时因为缺
|
|
15
15
|
* `reasoningPreset` 而默默失去调档能力。这里删掉旧字段,并按**同 id 的出厂模型**
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
*
|
|
18
18
|
* 另有一类「缺省值缺位」的迁移:`Endpoint.capabilities`(见 `normalizeEndpointCapabilities`)。
|
|
19
19
|
*
|
|
20
|
+
* ## `defaultModel` 是**反例**:它不需要迁移,也绝不能清
|
|
21
|
+
*
|
|
22
|
+
* 模型解析是三级(`会话级覆盖 > Agent 定义 > 本字段`,唯一实现在
|
|
23
|
+
* `runtime/resolveModel.ts`),`defaultModel` 就是**全局兜底层**。字段名从未变过,
|
|
24
|
+
* 所以这里**什么都不用搬**:老配置里写着的原样保留、继续生效。绝对不能再清 ——
|
|
25
|
+
* 清掉等于用户升级一次就静默丢一次自己配的兜底模型,而这属于「默认值缺位」里最坏的
|
|
26
|
+
* 一种:丢的是用户明确填过的值。
|
|
27
|
+
*
|
|
20
28
|
* 迁移时机:`ConfigManager.read()` 读出即迁(内存里永远是当前形状);
|
|
21
29
|
* 落盘由 `ensureDefaultConfig()` 负责 —— 它比较迁移结果与磁盘原文,不同才写回,
|
|
22
30
|
* 因此迁移只发生一次,且不会在每次启动时无谓地改写文件。
|
|
@@ -68,7 +76,7 @@ export function migrateModelThresholds(model) {
|
|
|
68
76
|
return { model, changed: false };
|
|
69
77
|
const fromChars = legacyChars !== undefined ? Math.max(1, Math.floor(legacyChars / 4)) : undefined;
|
|
70
78
|
const handoff = current.handoff ?? legacyTokens ?? fromChars ?? legacySingle ?? DEFAULT_HANDOFF_THRESHOLD;
|
|
71
|
-
// 旧数据里没有 guard
|
|
79
|
+
// 旧数据里没有 guard 这一项:按 1.5 倍(历史上护栏用的默认倍数)折算一次,
|
|
72
80
|
// 让迁移后的实际行为与迁移前一致。这是**一次性**换算,落盘后两个值都是整数,
|
|
73
81
|
// 运行时不再有任何倍数关系(想调硬线就直接改 guard 的数字)。
|
|
74
82
|
const guard = current.guard ?? Math.round(handoff * 1.5);
|
|
@@ -104,7 +112,8 @@ export function migrateModelReasoning(model) {
|
|
|
104
112
|
* 图片模型(`imageModels`)既没有上下文阈值、也没有思考概念。
|
|
105
113
|
*
|
|
106
114
|
* 同时做两件字段级收敛:
|
|
107
|
-
* -
|
|
115
|
+
* - **保留** `defaultModel`(三级解析的全局兜底层,见文件头):它不在这里被删、
|
|
116
|
+
* 也不在这里被补 —— 用户没配就没有兜底层,`createAgent` 会给出明确报错;
|
|
108
117
|
* - 补齐中断策略(`abortedMessageStrategy` / `abortedToolRoundStrategy`):把缺失或
|
|
109
118
|
* 非法值写成出厂默认。这样「配置即事实」——文件里写着的就是运行时用的,不再需要
|
|
110
119
|
* 使用方各自 `?? "keep"` 地兵分两路兜底。
|
|
@@ -124,11 +133,6 @@ export function migrateConfig(config) {
|
|
|
124
133
|
// 端点数组浅拷贝:能力位补齐会改元素,不把副作用浇到调用方手里的旧对象上
|
|
125
134
|
endpoints: (config.endpoints ?? []).map((endpoint) => ({ ...endpoint })),
|
|
126
135
|
};
|
|
127
|
-
// 已废弃字段:不参与运行,也不允许再写回磁盘
|
|
128
|
-
if ("defaultModel" in next) {
|
|
129
|
-
delete next.defaultModel;
|
|
130
|
-
changed = true;
|
|
131
|
-
}
|
|
132
136
|
if (normalizeAbortStrategies(next))
|
|
133
137
|
changed = true;
|
|
134
138
|
if (normalizeEndpointCapabilities(next))
|
|
@@ -156,12 +160,12 @@ export function normalizeAbortStrategies(config) {
|
|
|
156
160
|
/**
|
|
157
161
|
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
158
162
|
*
|
|
159
|
-
* ##
|
|
163
|
+
* ## 为什么要补
|
|
160
164
|
*
|
|
161
|
-
* `capabilities.filesApi`
|
|
162
|
-
*
|
|
165
|
+
* `capabilities.filesApi` 是后来才引入的能力位 —— 它把 `view_image` 的判定从「端点 id
|
|
166
|
+
* 是不是 `deepseek`」改成「看这一位」,而出厂只有 deepseek 打了 `true`。
|
|
163
167
|
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
164
|
-
* 迁移此前也完全不碰 `endpoints` ——
|
|
168
|
+
* 迁移此前也完全不碰 `endpoints` —— 于是在这之前就已写下的配置,其 deepseek
|
|
165
169
|
* 端点永远缺 `capabilities`,`supportsFilesApi()` 恒为 `false`:
|
|
166
170
|
*
|
|
167
171
|
* · 出厂承诺的「deepseek 走 Files API」对这些用户从未生效;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
|
8
8
|
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
9
9
|
export type { SkillInfo, Frontmatter } from "./scope/plugins/skills/discover.js";
|
|
10
10
|
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
11
|
-
export { discoverUserTools } from "./scope/plugins/usertools/discover.js";
|
|
11
|
+
export { discoverUserTools, discoverUserToolFiles } from "./scope/plugins/usertools/discover.js";
|
|
12
|
+
export type { UserToolFile } from "./scope/plugins/usertools/discover.js";
|
|
12
13
|
export { Scope } from "./scope/Scope.js";
|
|
13
14
|
export type { FilterOutput, ExcludeOptions, FilterOptions } from "./scope/Scope.js";
|
|
14
15
|
export type { ScopePlugin, ScopeCandidates } from "./scope/ScopePlugin.js";
|
|
@@ -24,13 +25,18 @@ export { FACTORY_SKILLS, HANDOFF_SKILL_ID, FALLBACK_HANDOFF_TEMPLATE, isCustomSk
|
|
|
24
25
|
export { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./config/reasoning-presets.js";
|
|
25
26
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
26
27
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
27
|
-
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash,
|
|
28
|
+
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash, MIME_BY_EXT, DEFAULT_MAX_INLINE_BYTES, } from "./shared/content-blocks.js";
|
|
28
29
|
export type { FileSource, FileToSectionInput, FileToSectionResult, ContentTransport, UploadFn, } from "./shared/content-blocks.js";
|
|
29
|
-
export { createModel } from "./runtime/createModel.js";
|
|
30
|
+
export { createModel, createModelFromConfig } from "./runtime/createModel.js";
|
|
31
|
+
export type { AgentModel } from "./runtime/createModel.js";
|
|
32
|
+
export { completeOnce } from "./runtime/completeOnce.js";
|
|
33
|
+
export type { CompleteOnceInput } from "./runtime/completeOnce.js";
|
|
30
34
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
31
35
|
export type { AgentPlugin, SendContext } from "./runtime/SdkAgent.js";
|
|
32
36
|
export { createAgent } from "./runtime/createAgent.js";
|
|
33
37
|
export type { CreateAgentOptions } from "./runtime/createAgent.js";
|
|
38
|
+
export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
|
|
39
|
+
export type { ModelLevel, ModelResolutionInput, ModelParamsResolutionInput, ResolvedModel, } from "./runtime/resolveModel.js";
|
|
34
40
|
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
35
41
|
export type { McpConnectOptions } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
36
42
|
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
@@ -40,10 +46,12 @@ export type { HandoffContext, HandoffMode, HandoffParams, HandoffServiceOptions,
|
|
|
40
46
|
export { HandoffGuardPlugin } from "./runtime/HandoffGuardPlugin.js";
|
|
41
47
|
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
42
48
|
export type { AutoMigrateOptions, AutoMigrateTriggerInfo, AutoMigrateModeResolver, } from "./agent-plugins/AutoMigratePlugin.js";
|
|
43
|
-
export { AutoRefreshToolsPlugin } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
49
|
+
export { AutoRefreshToolsPlugin, type AutoRefreshWhen, } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
44
50
|
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
45
51
|
export type { ContextGuardOptions } from "./agent-plugins/ContextGuardPlugin.js";
|
|
46
52
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
53
|
+
export { SubAgentGuardInstallerPlugin } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
54
|
+
export type { SubAgentGuardOptions } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
47
55
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
48
56
|
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";
|
|
49
57
|
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { discoverBuiltinTools } from "./scope/plugins/builtin/discover.js";
|
|
|
6
6
|
export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
7
7
|
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
8
8
|
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
9
|
-
export { discoverUserTools } from "./scope/plugins/usertools/discover.js";
|
|
9
|
+
export { discoverUserTools, discoverUserToolFiles } from "./scope/plugins/usertools/discover.js";
|
|
10
10
|
// Scope — 全局上下文 + 能力装配编排容器
|
|
11
11
|
export { Scope } from "./scope/Scope.js";
|
|
12
12
|
export { BuiltinToolsScopePlugin } from "./scope/plugins/builtin/BuiltinToolsScopePlugin.js";
|
|
@@ -26,20 +26,25 @@ export { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./config/reas
|
|
|
26
26
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
27
27
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
28
28
|
// 文件 → 内容块(统一入口)— 上层应用构造媒体消息时请走这里,不要自己判断上传还是内联
|
|
29
|
-
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash,
|
|
29
|
+
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash, MIME_BY_EXT, DEFAULT_MAX_INLINE_BYTES, } from "./shared/content-blocks.js";
|
|
30
30
|
// 运行时
|
|
31
|
-
export { createModel } from "./runtime/createModel.js";
|
|
31
|
+
export { createModel, createModelFromConfig } from "./runtime/createModel.js";
|
|
32
|
+
// 一次性模型调用(不流式 / 不带工具):交接摘要、会话自动标题共用这一份请求体形状
|
|
33
|
+
export { completeOnce } from "./runtime/completeOnce.js";
|
|
32
34
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
33
35
|
export { createAgent } from "./runtime/createAgent.js";
|
|
36
|
+
// 模型三级解析(唯一实现):档位类型也导出,服务端与客户端要按它渲染「当前生效档」
|
|
37
|
+
export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
|
|
34
38
|
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
35
39
|
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
36
40
|
export { HandoffAbortedError, HandoffService } from "./runtime/HandoffService.js";
|
|
37
41
|
export { HandoffGuardPlugin } from "./runtime/HandoffGuardPlugin.js";
|
|
38
42
|
// 插件
|
|
39
43
|
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
40
|
-
export { AutoRefreshToolsPlugin } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
44
|
+
export { AutoRefreshToolsPlugin, } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
41
45
|
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
42
46
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
47
|
+
export { SubAgentGuardInstallerPlugin } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
43
48
|
// 工具 — 内置工具类 + 动态工具工厂
|
|
44
49
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
45
50
|
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";
|
|
@@ -116,7 +116,7 @@ export interface MigrateParams extends HandoffParams {
|
|
|
116
116
|
*
|
|
117
117
|
* 职责分层(这是本模块唯一的设计主线):
|
|
118
118
|
* - `handoff()`:**只产出交接文档**(停工 → 写文档 → 校验 → 失败降级),不动会话;
|
|
119
|
-
* - `migrate()`:`handoff()`
|
|
119
|
+
* - `migrate()`:`handoff()` 之后清历史并开新会话。
|
|
120
120
|
*
|
|
121
121
|
* 模板的唯一真相源是 `handoff` Skill(`SKILL.md`);代码只负责
|
|
122
122
|
* 「读正文 → 注入 → 校验文件 → 读不到时用兜底模板」,不持有第二份章节清单。
|
|
@@ -124,6 +124,11 @@ export interface MigrateParams extends HandoffParams {
|
|
|
124
124
|
* 重入:`handoff()` 与 `migrate()` 共用 `busy` 标志。交接回合本身也是一次 `send()`,
|
|
125
125
|
* 若不在 busy 期间让 `AutoMigratePlugin` / `ContextGuardPlugin` 让行,就会「交接触发迁移、
|
|
126
126
|
* 迁移再触发交接」无限递归,或在最满的时刻被护栏直接击杀。
|
|
127
|
+
*
|
|
128
|
+
* 取消:取消句柄由服务自己持有({@link HandoffService.abort}),而不是只认调用方传进来的
|
|
129
|
+
* `signal` —— 自动迁移由 `AutoMigratePlugin` 直接驱动,调用方根本没有机会把 signal 递进来,
|
|
130
|
+
* 只认外部 signal 的后果是「自动迁移期间按 Ctrl+C 会被当成『文档没写出来』,于是重试一轮、
|
|
131
|
+
* 再降级 summary 一轮,最后照样迁移」。取消后一律回到交接前的状态(见 {@link HandoffService.restoreBeforeHandoff})。
|
|
127
132
|
*/
|
|
128
133
|
export declare class HandoffService {
|
|
129
134
|
/** 交接文档兜底模板(仅在读不到 Skill 时使用) */
|
|
@@ -142,6 +147,13 @@ export declare class HandoffService {
|
|
|
142
147
|
private readonly logger;
|
|
143
148
|
/** 交接/迁移进行中标志(插件据此让行) */
|
|
144
149
|
private _busy;
|
|
150
|
+
/**
|
|
151
|
+
* 当前这次交接/迁移的取消句柄(`null` = 没有进行中的交接)。
|
|
152
|
+
*
|
|
153
|
+
* 三条链路(`/handoff`、`/migrate`、自动迁移)共用同一个开关:前两条还有调用方能
|
|
154
|
+
* 传 `signal`,自动迁移没有 —— 句柄放在服务里,三者的取消语义才不会各不相同。
|
|
155
|
+
*/
|
|
156
|
+
private abortController;
|
|
145
157
|
/** 交接回合的工具守卫(同一实例复用 + arm/disarm,避免插件数组无限增长) */
|
|
146
158
|
private guard?;
|
|
147
159
|
/** 已注册过守卫的 agent(每个 agent 只 use 一次) */
|
|
@@ -179,11 +191,21 @@ export declare class HandoffService {
|
|
|
179
191
|
static createPostMessages(handoffPath: string): AgentNS.Message[];
|
|
180
192
|
/** 序列化消息为 `[role]: content` 文本(仅 `summary` 模式使用) */
|
|
181
193
|
static serializeMessages(messages: AgentNS.Message[]): string;
|
|
194
|
+
/**
|
|
195
|
+
* 取消进行中的交接/迁移(用户按 Ctrl+C)。没有进行中的交接时是 no-op。
|
|
196
|
+
*
|
|
197
|
+
* 边界:本方法只保证「停下 + 回退」——不再重试、不降级 summary、不迁移,并把会话
|
|
198
|
+
* 退回交接前。**它不负责立刻掐断正在跑的模型请求**:`self` 模式的回合是
|
|
199
|
+
* `agent.send()`,调用方通常要同时 `agent.abort()`(TUI 就是这么做的);`summary`
|
|
200
|
+
* 模式的那次请求拿的是本服务合并出的 signal,会被真正中断。
|
|
201
|
+
*/
|
|
202
|
+
abort(): void;
|
|
182
203
|
/**
|
|
183
204
|
* 只产出交接文档,**不改动会话**(`/handoff`)。
|
|
184
205
|
*
|
|
185
206
|
* 不清理历史:交接回合(指令 + 工具调用 + 回执)会留在 `agent.messages` 里,
|
|
186
|
-
* 用户可继续让 agent
|
|
207
|
+
* 用户可继续让 agent 打磨这份文档(重写同一路径即可)。被取消时相反:整个交接
|
|
208
|
+
* 回合从 `agent.messages` 里截掉,本次新建的文档也不留。
|
|
187
209
|
*/
|
|
188
210
|
handoff(params: HandoffParams): Promise<HandoffContext>;
|
|
189
211
|
/**
|
|
@@ -194,16 +216,13 @@ export declare class HandoffService {
|
|
|
194
216
|
* - `prune`:物理剔除历史,只留 `definition.messages` + 交接断点。
|
|
195
217
|
*/
|
|
196
218
|
migrate(params: MigrateParams): Promise<HandoffContext>;
|
|
197
|
-
/** 串行化 + 防重入:交接与迁移共用同一把锁 */
|
|
198
|
-
private withBusy;
|
|
199
219
|
/**
|
|
200
|
-
*
|
|
220
|
+
* 串行化 + 防重入:交接与迁移共用同一把锁,也共用同一个取消句柄。
|
|
201
221
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* `readSkillContent` 这类前置 await 期间被取消。调用方只需要认一个类型。
|
|
222
|
+
* 句柄与 `busy` 同寿命:`finally` 里清掉,否则下一次 `abort()` 会往一个已结束的
|
|
223
|
+
* controller 上发出无意义的 abort(看起来「取消成功」,实际什么都没发生)。
|
|
205
224
|
*/
|
|
206
|
-
private
|
|
225
|
+
private withBusy;
|
|
207
226
|
/** 取消点检查:每跨过一个阶段就确认一次,避免取消后继续往下一步冲 */
|
|
208
227
|
private throwIfAborted;
|
|
209
228
|
private fileExists;
|
|
@@ -215,7 +234,27 @@ export declare class HandoffService {
|
|
|
215
234
|
* 留着半成品更糟 —— 下一轮接手方会把不完整的内容当成真实交接读进去。
|
|
216
235
|
*/
|
|
217
236
|
private discardPartialFile;
|
|
237
|
+
/**
|
|
238
|
+
* 跑完一次交接("/handoff" 与 "/migrate" 共用),取消时**由本方法统一回退**。
|
|
239
|
+
*
|
|
240
|
+
* 为什么回退只写在这一处:取消可能从任何一个阶段冒出来(`self` 回合后的主动检查、
|
|
241
|
+
* `summary` 请求被 abort、前置的 `readSkillContent`),分散到各自的 catch 里就会
|
|
242
|
+
* 漏掉「文档已落盘但还没校验通过」这种半成品状态。这里一次拿全三件事:
|
|
243
|
+
* 交接前的消息条数、文档路径、以及「文档本就不存在」这个事实。
|
|
244
|
+
*
|
|
245
|
+
* 取消形态有两类,都要认:{@link HandoffAbortedError}(主动检查)与底层 abort 错误
|
|
246
|
+
* (OpenAI 的 `APIUserAbortError`)。调用方只需要认前者。
|
|
247
|
+
*/
|
|
218
248
|
private runHandoff;
|
|
249
|
+
/**
|
|
250
|
+
* 取消后回到交接前的状态:把交接回合追加的消息全部截掉,并删掉本次新建的文档。
|
|
251
|
+
*
|
|
252
|
+
* 为什么必须截消息:`self` 模式的交接回合是「一条几 KB 的 Skill 指令 user 消息 +
|
|
253
|
+
* 工具结果 + 回执」,留在 `agent.messages` 里既让用户看到半段无关对话,也让下一次
|
|
254
|
+
* 请求把它当历史再发一遍(`↑` 翻历史还会把它翻出来)。`agent.messages` 是唯一真相源,
|
|
255
|
+
* 截回原长度之后,转录、历史、用量全都自动复位,不需要第二处补偿。
|
|
256
|
+
*/
|
|
257
|
+
private restoreBeforeHandoff;
|
|
219
258
|
/** 自交接是否可用:需要 `write` 工具 + `send` 能力 */
|
|
220
259
|
private supportsSelfHandoff;
|
|
221
260
|
/**
|
|
@@ -230,6 +269,9 @@ export declare class HandoffService {
|
|
|
230
269
|
* `agent.abort()` 不抛错(core 把消息标记为 Aborted 后正常返回),否则「用户
|
|
231
270
|
* 按了 Ctrl+C」会被下面的文件校验误判成「模型没写出文档」,于是重试一轮、再降级
|
|
232
271
|
* 一轮 —— 用户以为取消了,实际多烧了两轮全量输入。
|
|
272
|
+
*
|
|
273
|
+
* 取消的善后(删文档、截消息)不在这里做:交给 {@link runHandoff} 的 catch 一处处理,
|
|
274
|
+
* 因为「文档已写出但还没校验」的取消根本进不到本方法的 catch。
|
|
233
275
|
*/
|
|
234
276
|
private runSelfHandoff;
|
|
235
277
|
/** 独立摘要:一次模型调用,用同一份 Skill 正文作为规范 */
|