@ai-zen/agents-sdk 1.0.0-alpha.12 → 1.0.0-alpha.14
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 +74 -0
- package/dist/agent-plugins/AutoMigratePlugin.d.ts +7 -7
- package/dist/agent-plugins/AutoMigratePlugin.js +8 -8
- package/dist/agent-plugins/ContextGuardPlugin.d.ts +13 -25
- package/dist/agent-plugins/ContextGuardPlugin.js +13 -20
- package/dist/config/ConfigManager.d.ts +28 -1
- package/dist/config/ConfigManager.js +84 -9
- package/dist/config/constants.js +24 -11
- package/dist/config/migrate.d.ts +47 -0
- package/dist/config/migrate.js +89 -0
- package/dist/config/reasoning-presets.d.ts +29 -0
- package/dist/config/reasoning-presets.js +56 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/runtime/HandoffService.d.ts +2 -2
- package/dist/runtime/HandoffService.js +3 -3
- package/dist/runtime/createAgent.js +4 -1
- package/dist/runtime/createModel.d.ts +7 -1
- package/dist/runtime/createModel.js +9 -2
- package/dist/scope/Scope.d.ts +9 -1
- package/dist/scope/Scope.js +8 -0
- package/dist/shared/errors.d.ts +4 -8
- package/dist/shared/errors.js +8 -14
- package/dist/shared/reasoning.d.ts +62 -0
- package/dist/shared/reasoning.js +159 -0
- package/dist/types/index.d.ts +69 -6
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -25,6 +25,35 @@ export interface EndpointCapabilities {
|
|
|
25
25
|
*/
|
|
26
26
|
filesApi?: boolean;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* 单个档位的请求参数补丁 —— 原样合并进模型请求参数。
|
|
30
|
+
*
|
|
31
|
+
* 各家协议差异全部关在补丁里,SDK 不解释、不硬编码任何键名:
|
|
32
|
+
* OpenAI → `{ reasoning_effort: "high" }`(没有 `thinking` 参数)
|
|
33
|
+
* DeepSeek → `{ thinking: { type: "enabled" }, reasoning_effort: "high" }`
|
|
34
|
+
* 关闭 → `{ reasoning_effort: "none" }` 或 `{ thinking: { type: "disabled" } }`
|
|
35
|
+
*/
|
|
36
|
+
export type ReasoningPatch = Record<string, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* 一个具名思考策略:档位名 → 参数补丁。
|
|
39
|
+
*
|
|
40
|
+
* `levels` 的键集合**就是**该策略的全部可选档位 —— 没有单独的「能否关闭思考」字段:
|
|
41
|
+
* 表里有 `off` 键就能关,没有就不能(如智谱 GLM-5.3 系,官方原文「其余输入将报错」)。
|
|
42
|
+
*/
|
|
43
|
+
export interface ReasoningPreset {
|
|
44
|
+
/** 用户改过 → SDK 初始化不再覆盖该策略(与 `Model.custom` 同构) */
|
|
45
|
+
custom?: boolean;
|
|
46
|
+
/** 档位名 → 参数补丁 */
|
|
47
|
+
levels: Record<string, ReasoningPatch>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 思考策略表 —— `<basePath>/reasoning-presets.json` 的结构,出厂内容见
|
|
51
|
+
* `config/reasoning-presets.ts`。
|
|
52
|
+
*
|
|
53
|
+
* 键是策略名,由 `Model.reasoningPreset` 引用。**策略名一旦发布即视为稳定标识**
|
|
54
|
+
* (用户配置文件里写着它),改名等同破坏性变更。
|
|
55
|
+
*/
|
|
56
|
+
export type ReasoningPresets = Record<string, ReasoningPreset>;
|
|
28
57
|
/** API 端点 */
|
|
29
58
|
export interface Endpoint {
|
|
30
59
|
id: string;
|
|
@@ -34,6 +63,24 @@ export interface Endpoint {
|
|
|
34
63
|
description?: string;
|
|
35
64
|
capabilities?: EndpointCapabilities;
|
|
36
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* 上下文用量阈值 —— 与模型的真实窗口无关,只描述「用量到了这条线该怎么办」。
|
|
68
|
+
*
|
|
69
|
+
* 两个阈值语义不同,消费方也不同:
|
|
70
|
+
* - `handoff`:软线。`AutoMigratePlugin` 在响应返回后拿 `usage.prompt_tokens` 比它,
|
|
71
|
+
* 超过即触发任务交接(交接本身还要再发 1~2 次请求,所以这条线必须留足余量)。
|
|
72
|
+
* - `guard`:硬线。`ContextGuardPlugin` 在**每次请求前**比它,超过即抛
|
|
73
|
+
* `ContextOverflowError` 中断本轮——这是最后一道保护,宁可报错也不要发出必然失败的请求。
|
|
74
|
+
*
|
|
75
|
+
* 建议 `guard ≈ handoff × 1.5`,给交接留出缓冲;两者都是绝对值,配置里写多少就是多少,
|
|
76
|
+
* 不做任何倍数换算(阈值就该是能直接读懂的数字)。
|
|
77
|
+
*/
|
|
78
|
+
export interface TokenThresholds {
|
|
79
|
+
/** 交接阈值(软线):prompt_tokens 超过它 → 触发任务交接 */
|
|
80
|
+
handoff: number;
|
|
81
|
+
/** 强行阻断阈值(硬线):请求前用量超过它 → 中断本轮并报错 */
|
|
82
|
+
guard: number;
|
|
83
|
+
}
|
|
37
84
|
/** 模型配置,绑定一个 Endpoint */
|
|
38
85
|
export interface Model {
|
|
39
86
|
id: string;
|
|
@@ -41,15 +88,21 @@ export interface Model {
|
|
|
41
88
|
endpointId: string;
|
|
42
89
|
modelName?: string;
|
|
43
90
|
/**
|
|
44
|
-
*
|
|
91
|
+
* 上下文用量阈值(交接软线 + 阻断硬线)。**不是**模型的真实上下文窗口。
|
|
45
92
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
93
|
+
* 历史字段 `maxContextTokens` / `maxContextChars` 已由 `config/migrate.ts`
|
|
94
|
+
* 迁移成这个结构体并删除。
|
|
48
95
|
*/
|
|
49
|
-
|
|
50
|
-
/** 旧版字符数阈值(兼容迁移) */
|
|
51
|
-
maxContextChars?: number;
|
|
96
|
+
tokenThresholds: TokenThresholds;
|
|
52
97
|
defaultParams?: Record<string, unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* 思考策略名,引用 `reasoning-presets.json` 里的键。缺省视为不可调档。
|
|
100
|
+
*
|
|
101
|
+
* 为什么只存名字不存整张表:档位细节属于**厂商协议知识**,跟 SDK 版本一起演进;
|
|
102
|
+
* 配置只需要记录「这个型号套用哪套协议」。名字指向同目录下的策略表文件,
|
|
103
|
+
* 用户看得见、改得动,不必等 SDK 发版。
|
|
104
|
+
*/
|
|
105
|
+
reasoningPreset?: string;
|
|
53
106
|
/** 是否支持图片输入(视觉模型)。看图工具(view_image)仅对视觉模型启用;generate_image 是否返回图片内容块也据此判断 */
|
|
54
107
|
vision?: boolean;
|
|
55
108
|
description?: string;
|
|
@@ -69,6 +122,16 @@ export interface AgentDefinition {
|
|
|
69
122
|
description?: string;
|
|
70
123
|
messages: AgentNS.Message[];
|
|
71
124
|
modelId?: string;
|
|
125
|
+
/**
|
|
126
|
+
* 该 Agent 的思考档位(可选),必须是该模型策略表 `levels` 里的键。
|
|
127
|
+
*
|
|
128
|
+
* 有了它,同一个模型可以给不同 Agent 配不同强度(编程 Agent `max`、闲聊 Agent `low`),
|
|
129
|
+
* 而模型本身的默认参数保持不变。未声明时沿用模型默认。
|
|
130
|
+
*
|
|
131
|
+
* 类型是 `string` 而非联合类型:档位名由策略表定义,各家本就不同名,
|
|
132
|
+
* 用一个全局枚举假装统一只会把厂商差异藏进字段里。合法性在运行时按表校验。
|
|
133
|
+
*/
|
|
134
|
+
reasoningEffort?: string;
|
|
72
135
|
permissions?: AgentPermissions;
|
|
73
136
|
function?: AgentNS.FunctionDefine;
|
|
74
137
|
createdAt: string;
|