Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/src/domains/chat/hooks/use-stream-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ export function useStreamEventHandler(
handleAssistantTextDelta(event, ctx);
break;
case "assistant_activity_state":
handleAssistantActivityState(event, epoch, ctx);
handleAssistantActivityState(event, ctx);
break;
case "message_complete":
handleMessageComplete(event, epoch, ctx);
handleMessageComplete(event, ctx);
break;
case "generation_handoff":
handleGenerationHandoff(event, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ describe("handleAssistantActivityState", () => {
reason: "thinking_delta",
conversationId: "conv-1",
},
1,
ctx,
);
expect(ctx.turnActions.onActivityThinking).not.toHaveBeenCalled();
expect(ctx.turnActions.completeTurn).not.toHaveBeenCalled();
});

it("updates version and handles idle phase", () => {
it("updates version and handles idle phase without starting reconcile", () => {
const ctx = makeCtx();
handleAssistantActivityState(
{
Expand All @@ -74,14 +73,13 @@ describe("handleAssistantActivityState", () => {
reason: "message_complete",
conversationId: "conv-1",
},
1,
ctx,
);
expect(ctx.lastActivityVersionRef.current.get("conv-1")).toBe(1);
expect(ctx.setMessages).toHaveBeenCalled();
expect(ctx.turnActions.completeTurn).toHaveBeenCalled();
expect(ctx.clearProcessingKey).toHaveBeenCalledWith("conv-1");
expect(ctx.startReconciliationLoop).toHaveBeenCalledWith(1);
expect(ctx.startReconciliationLoop).not.toHaveBeenCalled();
});

it("calls onActivityThinking for thinking phase", () => {
Expand All @@ -95,7 +93,6 @@ describe("handleAssistantActivityState", () => {
reason: "tool_result_received",
conversationId: "conv-1",
},
1,
ctx,
);
expect(ctx.lastActivityVersionRef.current.get("conv-1")).toBe(2);
Expand All @@ -116,7 +113,6 @@ describe("handleAssistantActivityState", () => {
statusText: "Processing bash results",
conversationId: "conv-1",
},
1,
ctx,
);
expect(ctx.turnActions.onActivityThinking).toHaveBeenCalledWith("Processing bash results");
Expand All @@ -132,7 +128,6 @@ describe("handleAssistantActivityState", () => {
anchor: "assistant_turn",
reason: "first_text_delta",
},
1,
ctx,
);
expect(ctx.lastActivityVersionRef.current.get(
Expand All @@ -144,17 +139,16 @@ describe("handleAssistantActivityState", () => {
});

describe("handleMessageComplete", () => {
it("finalizes message and starts reconciliation", () => {
it("finalizes message and completes turn without starting reconcile", () => {
const ctx = makeCtx();
handleMessageComplete(
{ type: "message_complete", messageId: "msg-1", content: "Done" },
1,
ctx,
);
expect(ctx.setMessages).toHaveBeenCalled();
expect(ctx.turnActions.completeTurn).toHaveBeenCalled();
expect(ctx.clearProcessingKey).toHaveBeenCalledWith("conv-1");
expect(ctx.startReconciliationLoop).toHaveBeenCalledWith(1);
expect(ctx.startReconciliationLoop).not.toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function handleAssistantTextDelta(

export function handleAssistantActivityState(
event: AssistantActivityStateEvent,
epoch: number,
ctx: StreamHandlerContext,
): void {
const convId =
Expand Down Expand Up @@ -82,12 +81,10 @@ export function handleAssistantActivityState(
activityVersion: event.activityVersion,
turnPhaseBefore,
});
ctx.startReconciliationLoop(epoch);
}

export function handleMessageComplete(
event: MessageCompleteEvent,
epoch: number,
ctx: StreamHandlerContext,
): void {
ctx.setMessages((prev) => finalizeMessageComplete(prev, event));
Expand All @@ -104,7 +101,6 @@ export function handleMessageComplete(
hasContent: !!event.content,
hasAttachments: !!event.attachments?.length,
});
ctx.startReconciliationLoop(epoch);
}

export function handleGenerationHandoff(
Expand Down