feat(chat): 优化分析过程与结果展示
This commit is contained in:
@@ -132,6 +132,80 @@ describe("useAgentChatSession actions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("applies an activity phase and todo snapshot atomically before revealing the final answer", async () => {
|
||||
listChatSessions.mockResolvedValue([]);
|
||||
jest.mocked(streamAgentChat).mockImplementationOnce(async ({ onEvent }) => {
|
||||
onEvent({
|
||||
type: "activity_update",
|
||||
sessionId: "session-1",
|
||||
activity: {
|
||||
id: "activity-analyze",
|
||||
title: "分析管网数据",
|
||||
reason: "需要识别影响供水能力的关键管段。",
|
||||
status: "running",
|
||||
actions: [],
|
||||
startedAt: 1000,
|
||||
},
|
||||
todos: [
|
||||
{
|
||||
id: "todo-data",
|
||||
content: "准备管网数据",
|
||||
status: "completed",
|
||||
priority: "high",
|
||||
},
|
||||
{
|
||||
id: "todo-analysis",
|
||||
content: "识别瓶颈管段",
|
||||
status: "in_progress",
|
||||
priority: "high",
|
||||
},
|
||||
],
|
||||
todosCreatedAt: 1001,
|
||||
});
|
||||
onEvent({
|
||||
type: "final_answer",
|
||||
sessionId: "session-1",
|
||||
content: "已识别关键瓶颈管段。",
|
||||
});
|
||||
onEvent({ type: "done", sessionId: "session-1" });
|
||||
});
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useAgentChatSession({
|
||||
projectId: "project-1",
|
||||
onToolCall: jest.fn(),
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(() => expect(result.current.isHydrating).toBe(false));
|
||||
|
||||
await act(async () => {
|
||||
await result.current.sendPrompt("分析管网瓶颈");
|
||||
});
|
||||
|
||||
const assistantMessage = result.current.messages.at(-1);
|
||||
expect(assistantMessage).toMatchObject({
|
||||
role: "assistant",
|
||||
content: "已识别关键瓶颈管段。",
|
||||
todos: {
|
||||
sessionId: "session-1",
|
||||
createdAt: 1001,
|
||||
todos: [
|
||||
expect.objectContaining({ id: "todo-data", status: "completed" }),
|
||||
expect.objectContaining({ id: "todo-analysis", status: "completed" }),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(
|
||||
assistantMessage?.activities?.find(
|
||||
(activity) => activity.id === "activity-analyze",
|
||||
),
|
||||
).toMatchObject({
|
||||
title: "分析管网数据",
|
||||
status: "completed",
|
||||
});
|
||||
});
|
||||
|
||||
it("finalizes running progress when aborting an active prompt", async () => {
|
||||
listChatSessions.mockResolvedValue([]);
|
||||
jest.mocked(streamAgentChat).mockImplementationOnce(
|
||||
|
||||
Reference in New Issue
Block a user