Refresh thread recency after turn start

This commit is contained in:
murashit 2026-06-23 12:44:44 +09:00
parent e74b118d04
commit a24a56fabf
2 changed files with 14 additions and 8 deletions

View file

@ -214,13 +214,17 @@ const STREAM_UPDATE_PLANNERS = {
} satisfies ServerNotificationStatePlannerMap<StreamUpdateNotificationMethod>;
const TURN_LIFECYCLE_PLANNERS = {
"turn/started": (state, notification) =>
actionPlan({
type: "turn/started",
threadId: notification.params.threadId,
turnId: notification.params.turn.id,
items: messageStreamItemsWithPendingPromptSubmitHooks(state, notification.params.turn.id),
}),
"turn/started": (state, notification) => ({
actions: [
{
type: "turn/started",
threadId: notification.params.threadId,
turnId: notification.params.turn.id,
items: messageStreamItemsWithPendingPromptSubmitHooks(state, notification.params.turn.id),
},
],
effects: [{ type: "refresh-threads" }],
}),
"turn/completed": (state, notification) => {
if (activeTurnId(state) !== notification.params.turn.id) return EMPTY_PLAN;
return {

View file

@ -466,7 +466,8 @@ describe("ChatInboundHandler", () => {
status: "completed",
},
]);
const handler = handlerForState(state);
const refreshActiveThreads = vi.fn();
const handler = handlerForState(state, { refreshActiveThreads });
handler.handleNotification({
method: "turn/started",
@ -488,6 +489,7 @@ describe("ChatInboundHandler", () => {
expect(chatStateMessageStreamItems(handler.currentState()).map((item) => item.id)).toEqual(["local-user-1", "hook-hook-1-1"]);
expect(chatStateMessageStreamItems(handler.currentState())[1]).toMatchObject({ id: "hook-hook-1-1", turnId: "turn-active" });
expect(pendingTurnStart(handler.currentState())).toBeNull();
expect(refreshActiveThreads).toHaveBeenCalledOnce();
});
it("moves pre-turn hook runs after the optimistic user message when a turn id is assigned", () => {