@ai-zen/agents-sdk 0.3.3 → 0.3.4
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
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.4] - 2026-07-27
|
|
4
|
+
|
|
5
|
+
### 🎯 优化
|
|
6
|
+
|
|
7
|
+
- **`AutoMigratePlugin` 钩子重命名** — `onHandoff` → `onMigrated`,语义更清晰:迁移前用 `onBeforeMigrate`(此时 `agent.messages` 仍是完整旧历史),迁移完成后用 `onMigrated`(交接文档已注入)
|
|
8
|
+
- **`conversation-runner.ts` 保存逻辑修正** — 将保存旧对话从 `onMigrated`(原 `onHandoff`)移至 `onBeforeMigrate`,确保保存的是完整的旧对话历史,而非迁移后的新消息
|
|
9
|
+
|
|
3
10
|
## [0.3.3] - 2026-07-27
|
|
4
11
|
|
|
5
12
|
### 🎯 优化
|
|
@@ -3,10 +3,10 @@ import { SdkAgent } from "../runtime/SdkAgent.js";
|
|
|
3
3
|
export interface AutoMigrateOptions {
|
|
4
4
|
maxTokens: number;
|
|
5
5
|
migrationAgent: SdkAgent;
|
|
6
|
-
/** 迁移开始前触发(promptTokens
|
|
6
|
+
/** 迁移开始前触发(promptTokens 刚超限时),此时 agent.messages 还是完整旧历史。适用于保存旧对话或向用户展示迁移提示。 */
|
|
7
7
|
onBeforeMigrate?: (promptTokens: number, maxTokens: number, agent: SdkAgent) => void;
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/** 迁移完成后触发,此时交接文档已注入 agent.messages。适用于 UI 更新等后处理。 */
|
|
9
|
+
onMigrated?: (handoffDoc: string, agent: SdkAgent) => void;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* 自动迁移插件。
|
|
@@ -18,7 +18,7 @@ export interface AutoMigrateOptions {
|
|
|
18
18
|
* agent.use(new AutoMigratePlugin({
|
|
19
19
|
* maxTokens: 250_000,
|
|
20
20
|
* migrationAgent: anotherAgent,
|
|
21
|
-
*
|
|
21
|
+
* onMigrated: (doc, agent) => { ... },
|
|
22
22
|
* }));
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
@@ -12,7 +12,7 @@ const log = createLogger();
|
|
|
12
12
|
* agent.use(new AutoMigratePlugin({
|
|
13
13
|
* maxTokens: 250_000,
|
|
14
14
|
* migrationAgent: anotherAgent,
|
|
15
|
-
*
|
|
15
|
+
* onMigrated: (doc, agent) => { ... },
|
|
16
16
|
* }));
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
@@ -23,7 +23,7 @@ export class AutoMigratePlugin {
|
|
|
23
23
|
}
|
|
24
24
|
async onAfterSend(ctx) {
|
|
25
25
|
const { agent } = ctx;
|
|
26
|
-
const { maxTokens, migrationAgent, onBeforeMigrate,
|
|
26
|
+
const { maxTokens, migrationAgent, onBeforeMigrate, onMigrated } = this.options;
|
|
27
27
|
const promptTokens = agent.lastUsage?.prompt_tokens;
|
|
28
28
|
if (promptTokens == null)
|
|
29
29
|
return;
|
|
@@ -47,12 +47,12 @@ export class AutoMigratePlugin {
|
|
|
47
47
|
// 仅替换消息列表,不重建 agent,保留所有引用和插件绑定
|
|
48
48
|
agent.messages.length = 0;
|
|
49
49
|
agent.messages.push(...agent.definition.messages, ...TaskMigrationService.createPostMessages(handoffDoc));
|
|
50
|
-
if (
|
|
50
|
+
if (onMigrated) {
|
|
51
51
|
try {
|
|
52
|
-
await
|
|
52
|
+
await onMigrated(handoffDoc, agent);
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
|
55
|
-
log.error(`[autoMigrate]
|
|
55
|
+
log.error(`[autoMigrate] onMigrated 回调失败: ${err?.message ?? err}`);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|