@ai-zen/agents-sdk 2.0.0-alpha.0 → 2.0.0-alpha.1
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 +73 -16
- package/README.md +397 -113
- package/README.zh.md +314 -112
- package/dist/agent-plugins/AssetTransportPlugin.d.ts +51 -0
- package/dist/agent-plugins/AssetTransportPlugin.js +145 -0
- package/dist/agent-plugins/AutoMigratePlugin.d.ts +35 -14
- package/dist/agent-plugins/AutoMigratePlugin.js +36 -36
- package/dist/agent-plugins/AutoRefreshToolsPlugin.d.ts +6 -6
- package/dist/agent-plugins/AutoRefreshToolsPlugin.js +2 -2
- package/dist/agent-plugins/ContextGuardPlugin.d.ts +20 -24
- package/dist/agent-plugins/ContextGuardPlugin.js +25 -24
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.d.ts +25 -35
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.js +26 -41
- package/dist/agent-plugins/UnknownToolHintPlugin.d.ts +14 -9
- package/dist/agent-plugins/UnknownToolHintPlugin.js +15 -13
- package/dist/config/ConfigManager.d.ts +13 -5
- package/dist/config/ConfigManager.js +58 -39
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/constants.js +2 -2
- package/dist/config/factory-skills.js +2 -2
- package/dist/config/normalize.d.ts +93 -0
- package/dist/config/normalize.js +158 -0
- package/dist/crud/AgentRepository.d.ts +3 -1
- package/dist/crud/AgentRepository.js +4 -2
- package/dist/index.d.ts +19 -9
- package/dist/index.js +14 -7
- package/dist/runtime/AgentRuntime.d.ts +293 -0
- package/dist/runtime/AgentRuntime.js +457 -0
- package/dist/runtime/HandoffGuardPlugin.d.ts +82 -15
- package/dist/runtime/HandoffGuardPlugin.js +136 -17
- package/dist/runtime/HandoffService.d.ts +244 -119
- package/dist/runtime/HandoffService.js +373 -251
- package/dist/runtime/RuntimePeerSessions.d.ts +34 -0
- package/dist/runtime/RuntimePeerSessions.js +50 -0
- package/dist/runtime/Scopes.d.ts +123 -0
- package/dist/runtime/Scopes.js +169 -0
- package/dist/runtime/SdkAgent.d.ts +19 -8
- package/dist/runtime/SdkAgent.js +23 -6
- package/dist/runtime/completeOnce.d.ts +3 -3
- package/dist/runtime/completeOnce.js +3 -3
- package/dist/runtime/createAgent.d.ts +29 -7
- package/dist/runtime/createAgent.js +57 -12
- package/dist/runtime/createModel.d.ts +4 -4
- package/dist/runtime/createModel.js +6 -6
- package/dist/runtime/lastPromptTokens.d.ts +18 -0
- package/dist/runtime/lastPromptTokens.js +26 -0
- package/dist/runtime/resolveModel.d.ts +9 -9
- package/dist/runtime/resolveModel.js +8 -8
- package/dist/scope/Scope.d.ts +10 -9
- package/dist/scope/Scope.js +6 -6
- package/dist/scope/ScopePlugin.d.ts +2 -8
- package/dist/scope/disclosure.d.ts +1 -1
- package/dist/scope/disclosure.js +1 -1
- package/dist/scope/plugins/allInOne.d.ts +13 -1
- package/dist/scope/plugins/allInOne.js +9 -5
- package/dist/scope/plugins/builtin/AsyncExecTool.d.ts +12 -0
- package/dist/scope/plugins/builtin/AsyncExecTool.js +103 -0
- package/dist/scope/plugins/builtin/AsyncTimeoutTool.d.ts +10 -0
- package/dist/scope/plugins/builtin/AsyncTimeoutTool.js +90 -0
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.js +1 -1
- package/dist/scope/plugins/builtin/DownloadFileTool.js +1 -1
- package/dist/scope/plugins/builtin/ExecTool.js +10 -199
- package/dist/scope/plugins/builtin/FindTextTool.d.ts +1 -1
- package/dist/scope/plugins/builtin/FindTextTool.js +1 -1
- package/dist/scope/plugins/builtin/GenerateImageTool.d.ts +1 -4
- package/dist/scope/plugins/builtin/GenerateImageTool.js +2 -8
- package/dist/scope/plugins/builtin/InspectFileTool.js +1 -1
- package/dist/scope/plugins/builtin/SdkCallbackTool.d.ts +4 -4
- package/dist/scope/plugins/builtin/SdkCallbackTool.js +3 -3
- package/dist/scope/plugins/builtin/SleepTool.js +2 -3
- package/dist/scope/plugins/builtin/ViewImageTool.d.ts +2 -4
- package/dist/scope/plugins/builtin/ViewImageTool.js +4 -6
- package/dist/scope/plugins/builtin/WriteTool.d.ts +7 -0
- package/dist/scope/plugins/builtin/WriteTool.js +8 -1
- package/dist/scope/plugins/builtin/asyncTasks.d.ts +41 -0
- package/dist/scope/plugins/builtin/asyncTasks.js +97 -0
- package/dist/scope/plugins/builtin/commandOutput.d.ts +22 -0
- package/dist/scope/plugins/builtin/commandOutput.js +55 -0
- package/dist/scope/plugins/builtin/commandRun.d.ts +48 -0
- package/dist/scope/plugins/builtin/commandRun.js +169 -0
- package/dist/scope/plugins/builtin/discover.d.ts +1 -3
- package/dist/scope/plugins/builtin/discover.js +1 -3
- package/dist/scope/plugins/builtin/index.d.ts +5 -7
- package/dist/scope/plugins/builtin/index.js +7 -7
- package/dist/scope/plugins/builtin/outputGuard.d.ts +1 -5
- package/dist/scope/plugins/builtin/outputGuard.js +1 -5
- package/dist/scope/plugins/mcp/McpConnectionManager.d.ts +56 -11
- package/dist/scope/plugins/mcp/McpConnectionManager.js +169 -74
- package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +17 -7
- package/dist/scope/plugins/mcp/McpScopePlugin.js +36 -12
- package/dist/scope/plugins/mcp/discover.d.ts +9 -2
- package/dist/scope/plugins/mcp/discover.js +12 -14
- package/dist/scope/plugins/mcp/mcpTaskNotice.d.ts +52 -0
- package/dist/scope/plugins/mcp/mcpTaskNotice.js +8 -0
- package/dist/scope/plugins/mcp/mcpTools.d.ts +20 -2
- package/dist/scope/plugins/mcp/mcpTools.js +220 -39
- package/dist/scope/plugins/peers/PeerSessionsScopePlugin.d.ts +4 -7
- package/dist/scope/plugins/peers/PeerSessionsScopePlugin.js +4 -7
- package/dist/scope/plugins/peers/peerSessionTools.d.ts +97 -46
- package/dist/scope/plugins/peers/peerSessionTools.js +147 -121
- package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +4 -0
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +10 -4
- package/dist/scope/plugins/skills/discover.d.ts +15 -8
- package/dist/scope/plugins/skills/discover.js +15 -26
- package/dist/scope/plugins/skills/skillTools.d.ts +8 -7
- package/dist/scope/plugins/skills/skillTools.js +18 -14
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.d.ts +4 -0
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +4 -1
- package/dist/scope/plugins/subagents/discover.d.ts +7 -1
- package/dist/scope/plugins/subagents/discover.js +7 -3
- package/dist/scope/plugins/subagents/subAgentTools.d.ts +0 -1
- package/dist/scope/plugins/subagents/subAgentTools.js +11 -1
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.d.ts +4 -0
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.js +4 -1
- package/dist/scope/plugins/usertools/discover.d.ts +7 -8
- package/dist/scope/plugins/usertools/discover.js +17 -27
- package/dist/shared/EntityRepository.d.ts +22 -5
- package/dist/shared/EntityRepository.js +45 -29
- package/dist/shared/content-blocks.d.ts +9 -3
- package/dist/shared/content-blocks.js +12 -19
- package/dist/shared/errors.d.ts +5 -7
- package/dist/shared/errors.js +6 -8
- package/dist/shared/logger.d.ts +21 -10
- package/dist/shared/logger.js +9 -15
- package/dist/types/index.d.ts +36 -13
- package/package.json +2 -2
- package/dist/config/migrate.d.ts +0 -115
- package/dist/config/migrate.js +0 -200
- package/dist/scope/plugins/builtin/test-helpers.d.ts +0 -3
- package/dist/scope/plugins/builtin/test-helpers.js +0 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置补位 —— 缺字段 / 非法值在启动时补成出厂值
|
|
3
|
+
*
|
|
4
|
+
* 依据 PRD 3.4:配置里少了字段、或值不合法,启动时补成出厂值。补完之后「配置即事实」——
|
|
5
|
+
* 文件里写着的就是运行时用的,使用方不必各自 `?? 出厂值` 地兵分两路兜底。
|
|
6
|
+
*
|
|
7
|
+
* 这里**不是**迁移:本仓没有发过旧版本(PRD 1.9「不做…迁移或识别旧数据」),所以文件里
|
|
8
|
+
* 没有一行「读旧形状」的代码。补位只往**空位**里放出厂值,用户写下的值一个都不改:
|
|
9
|
+
*
|
|
10
|
+
* - `Model.tokenThresholds`:`handoff`(交接线,软)与 `guard`(阻断线,硬)两条整数阈值,
|
|
11
|
+
* 缺哪条补哪条(见 `normalizeModelThresholds`);
|
|
12
|
+
* - `AppConfig.abortedMessageStrategy` / `abortedToolRoundStrategy`:缺失或非法 → 出厂默认
|
|
13
|
+
* (见 `normalizeAbortStrategies`);
|
|
14
|
+
* - `Endpoint.capabilities`:整块缺失 → 同 id 出厂端点的能力位
|
|
15
|
+
* (见 `normalizeEndpointCapabilities`)。
|
|
16
|
+
*
|
|
17
|
+
* ## `defaultModel` 在这里不出现,是有意的
|
|
18
|
+
*
|
|
19
|
+
* 模型解析是三级(`会话级覆盖 > Agent 定义 > 本字段`,唯一实现在 `runtime/resolveModel.ts`),
|
|
20
|
+
* `defaultModel` 就是**全局兜底层**。用户没配就没有兜底层,`createAgent` 会给出明确报错 ——
|
|
21
|
+
* 那不是「缺省值缺位」,而是「用户没表态」。所以这里既不补也不清:清掉等于用户升级一次
|
|
22
|
+
* 就静默丢一次自己配的兜底模型。
|
|
23
|
+
*
|
|
24
|
+
* 时机:`ConfigManager.read()` 读出即补位(内存里永远是当前形状);落盘由
|
|
25
|
+
* `ensureDefaultConfig()` 负责 —— 它比较补位结果与磁盘原文,不同才写回,因此补位只发生
|
|
26
|
+
* 一次,且不会在每次启动时无谓地改写文件。
|
|
27
|
+
*/
|
|
28
|
+
import type { AppConfig, Model } from "../types/index.js";
|
|
29
|
+
/**
|
|
30
|
+
* `handoff` 缺失时的兜底。
|
|
31
|
+
*
|
|
32
|
+
* 与 CLI 新建模型的默认值一致;宁可给一个保守值,也不要让模型缺阈值 ——
|
|
33
|
+
* 缺阈值意味着既没有交接触发、也没有阻断保护。
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_HANDOFF_THRESHOLD = 128000;
|
|
36
|
+
/**
|
|
37
|
+
* 补齐单个模型缺失的阈值。
|
|
38
|
+
*
|
|
39
|
+
* - 两条都在(都是合法正整数)→ 原样返回,`changed: false` 且连对象引用都不换;
|
|
40
|
+
* - 只有 `handoff` → `guard` 按 1.5 倍补;
|
|
41
|
+
* - 只有 `guard` → `handoff` 补 `DEFAULT_HANDOFF_THRESHOLD`(硬线是用户自己的选择,不动);
|
|
42
|
+
* - 两条都缺,或值不合法 → 两条都补出厂值。
|
|
43
|
+
*
|
|
44
|
+
* `changed` 就是「要不要写盘」的判据;入参对象不被就地修改(调用方手里的旧对象保持原样)。
|
|
45
|
+
*/
|
|
46
|
+
export declare function normalizeModelThresholds(model: Model): {
|
|
47
|
+
model: Model;
|
|
48
|
+
changed: boolean;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 收敛整个配置:模型阈值 + 中断策略 + 端点能力位。
|
|
52
|
+
*
|
|
53
|
+
* 只处理会话模型(`models`)—— 图片模型(`imageModels`)既没有上下文阈值、也没有思考概念。
|
|
54
|
+
* 无改动时返回**原对象**(调用方靠 `changed` / 引用相等判断「不用写盘」)。
|
|
55
|
+
*/
|
|
56
|
+
export declare function normalizeConfig(config: AppConfig): {
|
|
57
|
+
config: AppConfig;
|
|
58
|
+
changed: boolean;
|
|
59
|
+
};
|
|
60
|
+
/** 合法的中断策略取值(与 core 的枚举一致) */
|
|
61
|
+
export declare const ABORTED_MESSAGE_STRATEGIES: readonly ["keep", "drop"];
|
|
62
|
+
export declare const ABORTED_TOOL_ROUND_STRATEGIES: readonly ["fill", "drop"];
|
|
63
|
+
/** 缺失 / 非法 → 出厂默认;返回是否有改动(直接改写传入对象) */
|
|
64
|
+
export declare function normalizeAbortStrategies(config: AppConfig): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
67
|
+
*
|
|
68
|
+
* ## 为什么要补
|
|
69
|
+
*
|
|
70
|
+
* `capabilities.filesApi` 是能力位里的一项 —— 它把 `view_image` 的判定从「端点 id
|
|
71
|
+
* 是不是 `deepseek`」改成「看这一位」,而出厂只有 deepseek 打了 `true`。
|
|
72
|
+
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
73
|
+
* 这一格也就没有别的路径会补 —— 只要配置里它是空的,这个 deepseek 端点的
|
|
74
|
+
* `supportsFilesApi()` 就恒为 `false`:
|
|
75
|
+
*
|
|
76
|
+
* · 出厂承诺的「deepseek 走 Files API」对这些配置从未生效;
|
|
77
|
+
* · 而且**全程静默** —— 「未声明能力位」和「缺 apiKey」两个分支都不发 warning,
|
|
78
|
+
* 图片 / `view_image` / MCP 媒体就悄悄退化成 base64 内联,请求体随历史膨胀。
|
|
79
|
+
*
|
|
80
|
+
* 这是「默认值缺位」,不是「用户选择」,所以由这里补 —— 与模型清单不同,端点本身仍然
|
|
81
|
+
* 归用户所有,我们只往**空位**里放出厂默认。
|
|
82
|
+
*
|
|
83
|
+
* ## 边界:只补整体缺失,绝不覆盖
|
|
84
|
+
*
|
|
85
|
+
* - `capabilities` **整体缺失** → 按**同 id 的出厂端点**补上整块;
|
|
86
|
+
* - `capabilities` 已存在(哪怕是 `{}`、哪怕写着 `filesApi: false`)→ 一个字段都不动:
|
|
87
|
+
* 用户已经表过态,`false` 就是「我不走 Files API」;
|
|
88
|
+
* - 端点 id 不在出厂清单(用户自建)→ 不动:我们不知道它是否真有 `/files`,
|
|
89
|
+
* 猜错会把上传请求打到不存在的接口上。
|
|
90
|
+
*
|
|
91
|
+
* @returns 是否有改动(直接改写传入对象)
|
|
92
|
+
*/
|
|
93
|
+
export declare function normalizeEndpointCapabilities(config: AppConfig): boolean;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置补位 —— 缺字段 / 非法值在启动时补成出厂值
|
|
3
|
+
*
|
|
4
|
+
* 依据 PRD 3.4:配置里少了字段、或值不合法,启动时补成出厂值。补完之后「配置即事实」——
|
|
5
|
+
* 文件里写着的就是运行时用的,使用方不必各自 `?? 出厂值` 地兵分两路兜底。
|
|
6
|
+
*
|
|
7
|
+
* 这里**不是**迁移:本仓没有发过旧版本(PRD 1.9「不做…迁移或识别旧数据」),所以文件里
|
|
8
|
+
* 没有一行「读旧形状」的代码。补位只往**空位**里放出厂值,用户写下的值一个都不改:
|
|
9
|
+
*
|
|
10
|
+
* - `Model.tokenThresholds`:`handoff`(交接线,软)与 `guard`(阻断线,硬)两条整数阈值,
|
|
11
|
+
* 缺哪条补哪条(见 `normalizeModelThresholds`);
|
|
12
|
+
* - `AppConfig.abortedMessageStrategy` / `abortedToolRoundStrategy`:缺失或非法 → 出厂默认
|
|
13
|
+
* (见 `normalizeAbortStrategies`);
|
|
14
|
+
* - `Endpoint.capabilities`:整块缺失 → 同 id 出厂端点的能力位
|
|
15
|
+
* (见 `normalizeEndpointCapabilities`)。
|
|
16
|
+
*
|
|
17
|
+
* ## `defaultModel` 在这里不出现,是有意的
|
|
18
|
+
*
|
|
19
|
+
* 模型解析是三级(`会话级覆盖 > Agent 定义 > 本字段`,唯一实现在 `runtime/resolveModel.ts`),
|
|
20
|
+
* `defaultModel` 就是**全局兜底层**。用户没配就没有兜底层,`createAgent` 会给出明确报错 ——
|
|
21
|
+
* 那不是「缺省值缺位」,而是「用户没表态」。所以这里既不补也不清:清掉等于用户升级一次
|
|
22
|
+
* 就静默丢一次自己配的兜底模型。
|
|
23
|
+
*
|
|
24
|
+
* 时机:`ConfigManager.read()` 读出即补位(内存里永远是当前形状);落盘由
|
|
25
|
+
* `ensureDefaultConfig()` 负责 —— 它比较补位结果与磁盘原文,不同才写回,因此补位只发生
|
|
26
|
+
* 一次,且不会在每次启动时无谓地改写文件。
|
|
27
|
+
*/
|
|
28
|
+
import { DEFAULT_APP_CONFIG } from "./constants.js";
|
|
29
|
+
/** `Model` 上两条阈值的字段名(当前唯一的形状) */
|
|
30
|
+
const TOKEN_THRESHOLDS_KEY = "tokenThresholds";
|
|
31
|
+
/**
|
|
32
|
+
* `handoff` 缺失时的兜底。
|
|
33
|
+
*
|
|
34
|
+
* 与 CLI 新建模型的默认值一致;宁可给一个保守值,也不要让模型缺阈值 ——
|
|
35
|
+
* 缺阈值意味着既没有交接触发、也没有阻断保护。
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_HANDOFF_THRESHOLD = 128_000;
|
|
38
|
+
/** 缺 `guard` 时按 `handoff` 的这个倍数补:硬线在软线的 1.5 倍处(护栏的出厂口径) */
|
|
39
|
+
const GUARD_RATIO = 1.5;
|
|
40
|
+
/** 阈值只认正整数:0、负数、小数、非数字一律视为「这一格没填」 */
|
|
41
|
+
function toPositiveInt(value) {
|
|
42
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
43
|
+
return undefined;
|
|
44
|
+
return Math.floor(value);
|
|
45
|
+
}
|
|
46
|
+
function readThresholds(value) {
|
|
47
|
+
if (typeof value !== "object" || value === null)
|
|
48
|
+
return {};
|
|
49
|
+
const raw = value;
|
|
50
|
+
return {
|
|
51
|
+
handoff: toPositiveInt(raw.handoff),
|
|
52
|
+
guard: toPositiveInt(raw.guard),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 补齐单个模型缺失的阈值。
|
|
57
|
+
*
|
|
58
|
+
* - 两条都在(都是合法正整数)→ 原样返回,`changed: false` 且连对象引用都不换;
|
|
59
|
+
* - 只有 `handoff` → `guard` 按 1.5 倍补;
|
|
60
|
+
* - 只有 `guard` → `handoff` 补 `DEFAULT_HANDOFF_THRESHOLD`(硬线是用户自己的选择,不动);
|
|
61
|
+
* - 两条都缺,或值不合法 → 两条都补出厂值。
|
|
62
|
+
*
|
|
63
|
+
* `changed` 就是「要不要写盘」的判据;入参对象不被就地修改(调用方手里的旧对象保持原样)。
|
|
64
|
+
*/
|
|
65
|
+
export function normalizeModelThresholds(model) {
|
|
66
|
+
const current = readThresholds(model[TOKEN_THRESHOLDS_KEY]);
|
|
67
|
+
if (current.handoff !== undefined && current.guard !== undefined) {
|
|
68
|
+
return { model, changed: false };
|
|
69
|
+
}
|
|
70
|
+
const handoff = current.handoff ?? DEFAULT_HANDOFF_THRESHOLD;
|
|
71
|
+
const guard = current.guard ?? Math.round(handoff * GUARD_RATIO);
|
|
72
|
+
return { model: { ...model, tokenThresholds: { handoff, guard } }, changed: true };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 收敛整个配置:模型阈值 + 中断策略 + 端点能力位。
|
|
76
|
+
*
|
|
77
|
+
* 只处理会话模型(`models`)—— 图片模型(`imageModels`)既没有上下文阈值、也没有思考概念。
|
|
78
|
+
* 无改动时返回**原对象**(调用方靠 `changed` / 引用相等判断「不用写盘」)。
|
|
79
|
+
*/
|
|
80
|
+
export function normalizeConfig(config) {
|
|
81
|
+
let changed = false;
|
|
82
|
+
const models = (config.models ?? []).map((model) => {
|
|
83
|
+
const thresholds = normalizeModelThresholds(model);
|
|
84
|
+
if (thresholds.changed)
|
|
85
|
+
changed = true;
|
|
86
|
+
return thresholds.model;
|
|
87
|
+
});
|
|
88
|
+
const next = {
|
|
89
|
+
...config,
|
|
90
|
+
models,
|
|
91
|
+
// 端点数组浅拷贝:能力位补齐会改元素,不把副作用浇到调用方手里的旧对象上
|
|
92
|
+
endpoints: (config.endpoints ?? []).map((endpoint) => ({ ...endpoint })),
|
|
93
|
+
};
|
|
94
|
+
if (normalizeAbortStrategies(next))
|
|
95
|
+
changed = true;
|
|
96
|
+
if (normalizeEndpointCapabilities(next))
|
|
97
|
+
changed = true;
|
|
98
|
+
if (!changed)
|
|
99
|
+
return { config, changed };
|
|
100
|
+
return { config: next, changed };
|
|
101
|
+
}
|
|
102
|
+
/** 合法的中断策略取值(与 core 的枚举一致) */
|
|
103
|
+
export const ABORTED_MESSAGE_STRATEGIES = ["keep", "drop"];
|
|
104
|
+
export const ABORTED_TOOL_ROUND_STRATEGIES = ["fill", "drop"];
|
|
105
|
+
/** 缺失 / 非法 → 出厂默认;返回是否有改动(直接改写传入对象) */
|
|
106
|
+
export function normalizeAbortStrategies(config) {
|
|
107
|
+
let changed = false;
|
|
108
|
+
if (!ABORTED_MESSAGE_STRATEGIES.includes(config.abortedMessageStrategy)) {
|
|
109
|
+
config.abortedMessageStrategy = DEFAULT_APP_CONFIG.abortedMessageStrategy;
|
|
110
|
+
changed = true;
|
|
111
|
+
}
|
|
112
|
+
if (!ABORTED_TOOL_ROUND_STRATEGIES.includes(config.abortedToolRoundStrategy)) {
|
|
113
|
+
config.abortedToolRoundStrategy = DEFAULT_APP_CONFIG.abortedToolRoundStrategy;
|
|
114
|
+
changed = true;
|
|
115
|
+
}
|
|
116
|
+
return changed;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 补齐端点**缺失**的能力位声明(`Endpoint.capabilities`)。
|
|
120
|
+
*
|
|
121
|
+
* ## 为什么要补
|
|
122
|
+
*
|
|
123
|
+
* `capabilities.filesApi` 是能力位里的一项 —— 它把 `view_image` 的判定从「端点 id
|
|
124
|
+
* 是不是 `deepseek`」改成「看这一位」,而出厂只有 deepseek 打了 `true`。
|
|
125
|
+
* 但端点**不参与出厂托管**(`ConfigManager.syncManagedModels` 明写「保持用户配置」),
|
|
126
|
+
* 这一格也就没有别的路径会补 —— 只要配置里它是空的,这个 deepseek 端点的
|
|
127
|
+
* `supportsFilesApi()` 就恒为 `false`:
|
|
128
|
+
*
|
|
129
|
+
* · 出厂承诺的「deepseek 走 Files API」对这些配置从未生效;
|
|
130
|
+
* · 而且**全程静默** —— 「未声明能力位」和「缺 apiKey」两个分支都不发 warning,
|
|
131
|
+
* 图片 / `view_image` / MCP 媒体就悄悄退化成 base64 内联,请求体随历史膨胀。
|
|
132
|
+
*
|
|
133
|
+
* 这是「默认值缺位」,不是「用户选择」,所以由这里补 —— 与模型清单不同,端点本身仍然
|
|
134
|
+
* 归用户所有,我们只往**空位**里放出厂默认。
|
|
135
|
+
*
|
|
136
|
+
* ## 边界:只补整体缺失,绝不覆盖
|
|
137
|
+
*
|
|
138
|
+
* - `capabilities` **整体缺失** → 按**同 id 的出厂端点**补上整块;
|
|
139
|
+
* - `capabilities` 已存在(哪怕是 `{}`、哪怕写着 `filesApi: false`)→ 一个字段都不动:
|
|
140
|
+
* 用户已经表过态,`false` 就是「我不走 Files API」;
|
|
141
|
+
* - 端点 id 不在出厂清单(用户自建)→ 不动:我们不知道它是否真有 `/files`,
|
|
142
|
+
* 猜错会把上传请求打到不存在的接口上。
|
|
143
|
+
*
|
|
144
|
+
* @returns 是否有改动(直接改写传入对象)
|
|
145
|
+
*/
|
|
146
|
+
export function normalizeEndpointCapabilities(config) {
|
|
147
|
+
let changed = false;
|
|
148
|
+
for (const endpoint of config.endpoints ?? []) {
|
|
149
|
+
if (endpoint.capabilities != null)
|
|
150
|
+
continue;
|
|
151
|
+
const factory = (DEFAULT_APP_CONFIG.endpoints ?? []).find((item) => item.id === endpoint.id);
|
|
152
|
+
if (!factory?.capabilities)
|
|
153
|
+
continue;
|
|
154
|
+
endpoint.capabilities = { ...factory.capabilities };
|
|
155
|
+
changed = true;
|
|
156
|
+
}
|
|
157
|
+
return changed;
|
|
158
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../types/index.js";
|
|
2
|
+
import { type LogSink } from "../shared/logger.js";
|
|
2
3
|
import { EntityRepository } from "../shared/EntityRepository.js";
|
|
3
4
|
/**
|
|
4
5
|
* Agent 仓储。
|
|
5
6
|
* 每个 Agent 一个 JSON 文件存储在 ${agentsDir}/${id}.json。
|
|
6
7
|
*/
|
|
7
8
|
export declare class AgentRepository extends EntityRepository<AgentDefinition> {
|
|
8
|
-
|
|
9
|
+
/** @param logger 日志口(可选):`list()` 跳过读不出来的那一条时从它报一句,缺省不记 */
|
|
10
|
+
constructor(agentsDir: string, logger?: LogSink);
|
|
9
11
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { SILENT_LOG } from "../shared/logger.js";
|
|
1
2
|
import { EntityRepository } from "../shared/EntityRepository.js";
|
|
2
3
|
/**
|
|
3
4
|
* Agent 仓储。
|
|
4
5
|
* 每个 Agent 一个 JSON 文件存储在 ${agentsDir}/${id}.json。
|
|
5
6
|
*/
|
|
6
7
|
export class AgentRepository extends EntityRepository {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/** @param logger 日志口(可选):`list()` 跳过读不出来的那一条时从它报一句,缺省不记 */
|
|
9
|
+
constructor(agentsDir, logger = SILENT_LOG) {
|
|
10
|
+
super(agentsDir, logger);
|
|
9
11
|
}
|
|
10
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ export { createDisclosureParam } from "./scope/disclosure.js";
|
|
|
5
5
|
export type { DisclosureParam } from "./scope/disclosure.js";
|
|
6
6
|
export { discoverBuiltinTools } from "./scope/plugins/builtin/discover.js";
|
|
7
7
|
export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
8
|
+
export type { DiscoverSubAgentsOptions } from "./scope/plugins/subagents/discover.js";
|
|
8
9
|
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
9
|
-
export type { SkillInfo, Frontmatter } from "./scope/plugins/skills/discover.js";
|
|
10
|
+
export type { SkillInfo, Frontmatter, DiscoverSkillsOptions, } from "./scope/plugins/skills/discover.js";
|
|
10
11
|
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
12
|
+
export type { DiscoverMcpServersOptions } from "./scope/plugins/mcp/discover.js";
|
|
11
13
|
export { discoverUserTools, discoverUserToolFiles } from "./scope/plugins/usertools/discover.js";
|
|
12
|
-
export type { UserToolFile } from "./scope/plugins/usertools/discover.js";
|
|
14
|
+
export type { UserToolFile, DiscoverUserToolsOptions } from "./scope/plugins/usertools/discover.js";
|
|
13
15
|
export { Scope } from "./scope/Scope.js";
|
|
14
16
|
export type { FilterOutput, ExcludeOptions, FilterOptions, ScopeConfigSource, } from "./scope/Scope.js";
|
|
15
17
|
export type { ScopePlugin, ScopeCandidates } from "./scope/ScopePlugin.js";
|
|
@@ -19,8 +21,8 @@ export { SkillsScopePlugin } from "./scope/plugins/skills/SkillsScopePlugin.js";
|
|
|
19
21
|
export { McpScopePlugin } from "./scope/plugins/mcp/McpScopePlugin.js";
|
|
20
22
|
export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePlugin.js";
|
|
21
23
|
export { PeerSessionsScopePlugin } from "./scope/plugins/peers/PeerSessionsScopePlugin.js";
|
|
22
|
-
export { PEER_SESSION_TOOL_NAMES, CREATE_SESSION_TOOL, READ_SESSION_STATUS_TOOL,
|
|
23
|
-
export type { PeerSessionPort, PeerSessionCreated, PeerSessionStatus,
|
|
24
|
+
export { PEER_SESSION_TOOL_NAMES, CREATE_SESSION_TOOL, READ_SESSION_STATUS_TOOL, POST_MESSAGE_TOOL, } from "./scope/plugins/peers/peerSessionTools.js";
|
|
25
|
+
export type { PeerSessionPort, PeerSessionCreated, PeerSessionStatus, PeerSessionActivity, PeerSessionRejectReason, PeerSessionCreateInput, PeerSessionSent, PeerSessionSendInput, PeerSessionSendRejectReason, } from "./scope/plugins/peers/peerSessionTools.js";
|
|
24
26
|
export { allInOne } from "./scope/plugins/allInOne.js";
|
|
25
27
|
export type { AllInOneOptions } from "./scope/plugins/allInOne.js";
|
|
26
28
|
export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
|
|
@@ -39,6 +41,10 @@ export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
|
39
41
|
export type { AgentPlugin, InnerLoopContext, OuterLoopContext, SubAgentHookContext, ToolHookContext, } from "./runtime/SdkAgent.js";
|
|
40
42
|
export { createAgent } from "./runtime/createAgent.js";
|
|
41
43
|
export type { CreateAgentOptions } from "./runtime/createAgent.js";
|
|
44
|
+
export { AgentRuntime } from "./runtime/AgentRuntime.js";
|
|
45
|
+
export type { WakeMaterials, NewPeerSession, OpenPeerSession, RuntimePorts, RuntimeFact, PostResult, } from "./runtime/AgentRuntime.js";
|
|
46
|
+
export { Scopes } from "./runtime/Scopes.js";
|
|
47
|
+
export type { ScopesDeps, ScopeCapabilities, ScopeEvent, ScopeRefreshFailure, ScopeRefreshReport, } from "./runtime/Scopes.js";
|
|
42
48
|
export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
|
|
43
49
|
export type { ModelLevel, ModelResolutionInput, ModelParamsResolutionInput, ResolvedModel, } from "./runtime/resolveModel.js";
|
|
44
50
|
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
@@ -46,7 +52,7 @@ export type { McpConnectOptions } from "./scope/plugins/mcp/McpConnectionManager
|
|
|
46
52
|
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
47
53
|
export type { SdkCallbackToolOptions } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
48
54
|
export { HandoffAbortedError, HandoffService } from "./runtime/HandoffService.js";
|
|
49
|
-
export type { HandoffContext, HandoffMode, HandoffParams, HandoffServiceOptions, MigrateParams, MigrationStrategy, } from "./runtime/HandoffService.js";
|
|
55
|
+
export type { HandoffContext, HandoffFact, HandoffMode, HandoffParams, HandoffServiceOptions, MemoryCommit, MigrateParams, MigrationStrategy, } from "./runtime/HandoffService.js";
|
|
50
56
|
export { HandoffGuardPlugin } from "./runtime/HandoffGuardPlugin.js";
|
|
51
57
|
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
52
58
|
export type { AutoMigrateOptions, AutoMigrateTriggerInfo, AutoMigrateModeResolver, } from "./agent-plugins/AutoMigratePlugin.js";
|
|
@@ -54,15 +60,19 @@ export { AutoRefreshToolsPlugin, type AutoRefreshWhen, } from "./agent-plugins/A
|
|
|
54
60
|
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
55
61
|
export type { ContextGuardOptions } from "./agent-plugins/ContextGuardPlugin.js";
|
|
56
62
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
63
|
+
export { AssetTransportPlugin } from "./agent-plugins/AssetTransportPlugin.js";
|
|
64
|
+
export type { AssetTransportOptions } from "./agent-plugins/AssetTransportPlugin.js";
|
|
57
65
|
export { SubAgentGuardInstallerPlugin } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
58
66
|
export type { SubAgentGuardOptions } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
59
67
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
60
|
-
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";
|
|
68
|
+
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, AsyncExecTool, AsyncTimeoutTool, } from "./scope/plugins/builtin/index.js";
|
|
69
|
+
export { ASYNC_TASK_TOOL_NAMES, ASYNC_EXEC_TOOL, ASYNC_TIMEOUT_TOOL, } from "./scope/plugins/builtin/asyncTasks.js";
|
|
61
70
|
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
|
62
71
|
export { ViewImageTool } from "./scope/plugins/builtin/ViewImageTool.js";
|
|
63
72
|
export { createLoadSkillTool, createCallSkillSubAgentTool, } from "./scope/plugins/skills/skillTools.js";
|
|
64
|
-
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool, } from "./scope/plugins/mcp/mcpTools.js";
|
|
73
|
+
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool, createGetMcpTaskResultTool, createCancelMcpTaskTool, } from "./scope/plugins/mcp/mcpTools.js";
|
|
74
|
+
export { GET_MCP_TASK_RESULT_TOOL, CANCEL_MCP_TASK_TOOL, isTerminalTaskStatus, } from "./scope/plugins/mcp/mcpTaskNotice.js";
|
|
75
|
+
export type { McpTaskNotice, McpTaskNoticePort, McpTaskTerminalStatus, } from "./scope/plugins/mcp/mcpTaskNotice.js";
|
|
65
76
|
export { createSubAgentTool } from "./scope/plugins/subagents/subAgentTools.js";
|
|
66
|
-
export {
|
|
67
|
-
export type { Logger, LogFunctions } from "./shared/logger.js";
|
|
77
|
+
export type { LogSink } from "./shared/logger.js";
|
|
68
78
|
export { SdkError, ContextOverflowError } from "./shared/errors.js";
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { McpScopePlugin } from "./scope/plugins/mcp/McpScopePlugin.js";
|
|
|
16
16
|
export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePlugin.js";
|
|
17
17
|
// 平级会话:能力来自宿主注入的端口,不给端口就不产出任何工具
|
|
18
18
|
export { PeerSessionsScopePlugin } from "./scope/plugins/peers/PeerSessionsScopePlugin.js";
|
|
19
|
-
export { PEER_SESSION_TOOL_NAMES, CREATE_SESSION_TOOL, READ_SESSION_STATUS_TOOL,
|
|
19
|
+
export { PEER_SESSION_TOOL_NAMES, CREATE_SESSION_TOOL, READ_SESSION_STATUS_TOOL, POST_MESSAGE_TOOL, } from "./scope/plugins/peers/peerSessionTools.js";
|
|
20
20
|
export { allInOne } from "./scope/plugins/allInOne.js";
|
|
21
21
|
// 配置 — ConfigManager
|
|
22
22
|
export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
|
|
@@ -28,7 +28,7 @@ export { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./config/reas
|
|
|
28
28
|
// CRUD — 实体仓储(仅 Agent 定义等能力实体)
|
|
29
29
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
30
30
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
31
|
-
// 文件 →
|
|
31
|
+
// 文件 → 内容块(统一入口):走上传、内联还是直接引用 URL,由它判断
|
|
32
32
|
export { fileToContentSection, resolveModelAndEndpoint, supportsFilesApi, mimeOf, toDataUrl, base64ByteLength, contentHash, MIME_BY_EXT, DEFAULT_MAX_INLINE_BYTES, } from "./shared/content-blocks.js";
|
|
33
33
|
// 运行时
|
|
34
34
|
export { createModel, createModelFromConfig } from "./runtime/createModel.js";
|
|
@@ -36,7 +36,11 @@ export { createModel, createModelFromConfig } from "./runtime/createModel.js";
|
|
|
36
36
|
export { completeOnce } from "./runtime/completeOnce.js";
|
|
37
37
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
38
38
|
export { createAgent } from "./runtime/createAgent.js";
|
|
39
|
-
//
|
|
39
|
+
// 运行时:让执行体活着、让它们互相说话(登记、唤醒、发话)
|
|
40
|
+
export { AgentRuntime } from "./runtime/AgentRuntime.js";
|
|
41
|
+
// 能力容器按目录存活:什么时候造、什么时候拆
|
|
42
|
+
export { Scopes } from "./runtime/Scopes.js";
|
|
43
|
+
// 模型三级解析(唯一实现):档位类型也导出,宿主与客户端按它渲染「当前生效档」
|
|
40
44
|
export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
|
|
41
45
|
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
42
46
|
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
@@ -47,15 +51,18 @@ export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
|
47
51
|
export { AutoRefreshToolsPlugin, } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
48
52
|
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
49
53
|
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
54
|
+
export { AssetTransportPlugin } from "./agent-plugins/AssetTransportPlugin.js";
|
|
50
55
|
export { SubAgentGuardInstallerPlugin } from "./agent-plugins/SubAgentGuardInstallerPlugin.js";
|
|
51
56
|
// 工具 — 内置工具类 + 动态工具工厂
|
|
52
57
|
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
53
|
-
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";
|
|
58
|
+
export { CwdTool, ReadTool, InspectFileTool, WriteTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, SpawnTool, SleepTool, AsyncExecTool, AsyncTimeoutTool, } from "./scope/plugins/builtin/index.js";
|
|
59
|
+
// 两个后台工具的名字:一次性执行体手上没有它们(装配期按这份名单剔除)
|
|
60
|
+
export { ASYNC_TASK_TOOL_NAMES, ASYNC_EXEC_TOOL, ASYNC_TIMEOUT_TOOL, } from "./scope/plugins/builtin/asyncTasks.js";
|
|
54
61
|
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
|
55
62
|
export { ViewImageTool } from "./scope/plugins/builtin/ViewImageTool.js";
|
|
56
63
|
export { createLoadSkillTool, createCallSkillSubAgentTool, } from "./scope/plugins/skills/skillTools.js";
|
|
57
|
-
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool, } from "./scope/plugins/mcp/mcpTools.js";
|
|
64
|
+
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool, createGetMcpTaskResultTool, createCancelMcpTaskTool, } from "./scope/plugins/mcp/mcpTools.js";
|
|
65
|
+
// MCP 任务:两条工具的名字、终态判定与通知投递口(口由宿主实现)
|
|
66
|
+
export { GET_MCP_TASK_RESULT_TOOL, CANCEL_MCP_TASK_TOOL, isTerminalTaskStatus, } from "./scope/plugins/mcp/mcpTaskNotice.js";
|
|
58
67
|
export { createSubAgentTool } from "./scope/plugins/subagents/subAgentTools.js";
|
|
59
|
-
// 共享
|
|
60
|
-
export { getLogger, setLogger } from "./shared/logger.js";
|
|
61
68
|
export { SdkError, ContextOverflowError } from "./shared/errors.js";
|