Fix draft agent handoff continuity

Move optimistic user message reconciliation into the stream reducers and keep draft-created agents in a handoff lifecycle until authoritative history lands.
This commit is contained in:
Mohamed Boudra
2026-05-25 20:53:49 +07:00
parent e5658654c0
commit 53faba64ca
21 changed files with 677 additions and 458 deletions
@@ -71,4 +71,21 @@ describe("create-flow-store", () => {
useCreateFlowStore.getState().clear({ draftId: "draft-1" });
expect(useCreateFlowStore.getState().pendingByDraftId["draft-1"]).toBeUndefined();
});
it("clears pending handoff state by agent", () => {
useCreateFlowStore.getState().setPending({
draftId: "draft-1",
serverId: "server-1",
agentId: null,
clientMessageId: "msg-1",
text: "hello",
timestamp: Date.now(),
});
useCreateFlowStore.getState().updateAgentId({ draftId: "draft-1", agentId: "agent-1" });
useCreateFlowStore.getState().markLifecycle({ draftId: "draft-1", lifecycle: "sent" });
useCreateFlowStore.getState().clearByAgent({ serverId: "server-1", agentId: "agent-1" });
expect(useCreateFlowStore.getState().pendingByDraftId["draft-1"]).toBeUndefined();
});
});