File size: 1,222 Bytes
5f40163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { create } from "zustand";
import { ExecutionStatus } from "#/types/agent-server/core/base/common";

interface ConversationStateStore {
  /**
   * Latest execution status per conversation, fed by the main and planning
   * WebSocket handlers. Scoped by conversation id so the planning helper
   * conversation's own run/idle transitions can never overwrite the main
   * conversation's status (or vice versa) — see conversation-websocket-context.tsx.
   */
  executionStatusByConversation: Record<string, ExecutionStatus>;

  /**
   * Set the agent status for a specific conversation.
   */
  setExecutionStatus: (
    conversationId: string,
    execution_status: ExecutionStatus,
  ) => void;

  /**
   * Reset the store to initial state
   */
  reset: () => void;
}

export const useConversationStateStore = create<ConversationStateStore>(
  (set) => ({
    executionStatusByConversation: {},

    setExecutionStatus: (conversationId, execution_status) =>
      set((state) => ({
        executionStatusByConversation: {
          ...state.executionStatusByConversation,
          [conversationId]: execution_status,
        },
      })),

    reset: () => set({ executionStatusByConversation: {} }),
  }),
);