forked from bots-garden/ori
| ✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS | 1 | /** |
| 2 | * The application store: a zustand wrapper around the pure reducer. | |
| 3 | * | |
| 4 | * @example | |
| 5 | * import { useChatState, dispatch } from "./store"; | |
| 6 | * dispatch({ type: "connection", status: "online" }); | |
| 7 | * const state = useChatState(); // inside a component | |
| 8 | */ | |
| 9 | ||
| 10 | import { create } from "zustand"; | |
| 11 | import { | |
| 12 | initialState, | |
| 13 | reduce, | |
| 14 | type ChatEvent, | |
| 15 | type ChatState, | |
| 16 | } from "./reducer"; | |
| 17 | ||
| 18 | const store = create<ChatState>(() => initialState); | |
| 19 | ||
| 20 | /** React hook returning the current chat state (re-renders on change). */ | |
| 21 | export const useChatState = store; | |
| 22 | ||
| 23 | /** dispatch applies an event to the store through the reducer. */ | |
| 24 | export function dispatch(event: ChatEvent): void { | |
| 25 | store.setState((state) => reduce(state, event)); | |
| 26 | } | |
| 27 | ||
| 28 | /** resetStore restores the initial state; meant for tests. */ | |
| 29 | export function resetStore(): void { | |
| 30 | store.setState(initialState, true); | |
| 31 | } |