File size: 933 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
import { create } from "zustand";
import { devtools } from "zustand/middleware";
import { GoalStatus } from "#/types/agent-server/core/events/conversation-state-event";

interface GoalState {
  /** Latest goal status per conversation, fed by goal state-update events. */
  statusByConversation: Record<string, GoalStatus>;
}

interface GoalActions {
  /** Replace the latest goal status for a conversation. */
  setStatus: (conversationId: string, status: GoalStatus) => void;
}

type GoalStore = GoalState & GoalActions;

const initialState: GoalState = { statusByConversation: {} };

export const useGoalStore = create<GoalStore>()(
  devtools(
    (set) => ({
      ...initialState,
      setStatus: (conversationId, status) =>
        set((s) => ({
          statusByConversation: {
            ...s.statusByConversation,
            [conversationId]: status,
          },
        })),
    }),
    { name: "GoalStore" },
  ),
);