feat(agent): 完善分析编排与结果传输
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
|
||||
import { createActivityTracker } from "../../src/routes/chatActivityTracker.js";
|
||||
|
||||
describe("createActivityTracker", () => {
|
||||
it("groups actions and closes running children with their activity", () => {
|
||||
const events: Array<{ event: string; data: Record<string, unknown> }> = [];
|
||||
const tracker = createActivityTracker({
|
||||
clientSessionId: "client-session-1",
|
||||
write: (event, data) => events.push({ event, data }),
|
||||
});
|
||||
|
||||
tracker.start("activity-1", "准备分析数据", "需要先获取分析输入。");
|
||||
tracker.upsertAction(
|
||||
{
|
||||
id: "tool-1",
|
||||
tool: "tjwater_cli",
|
||||
state: {
|
||||
status: "running",
|
||||
input: { command: "data list" },
|
||||
},
|
||||
} as never,
|
||||
{ command: "data list" },
|
||||
);
|
||||
tracker.finalize("cancelled");
|
||||
|
||||
expect(tracker.getCurrentContext()).toEqual({
|
||||
id: "activity-1",
|
||||
title: "准备分析数据",
|
||||
reason: "需要先获取分析输入。",
|
||||
});
|
||||
expect(events.at(-1)).toMatchObject({
|
||||
event: "activity_update",
|
||||
data: {
|
||||
session_id: "client-session-1",
|
||||
activity: {
|
||||
id: "activity-1",
|
||||
status: "cancelled",
|
||||
actions: [
|
||||
expect.objectContaining({
|
||||
id: "tool-1",
|
||||
status: "completed",
|
||||
target: "data list",
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user