nandi/oripublic Fork 0
35061753be581c0ba47a3189520d64e7788c183d
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

store.ts · 31 lines · 853 BTypeScript Blame HistoryRaw
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday1/**
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
10import { create } from "zustand";
11import {
12 initialState,
13 reduce,
14 type ChatEvent,
15 type ChatState,
16} from "./reducer";
17
18const store = create<ChatState>(() => initialState);
19
20/** React hook returning the current chat state (re-renders on change). */
21export const useChatState = store;
22
23/** dispatch applies an event to the store through the reducer. */
24export function dispatch(event: ChatEvent): void {
25 store.setState((state) => reduce(state, event));
26}
27
28/** resetStore restores the initial state; meant for tests. */
29export function resetStore(): void {
30 store.setState(initialState, true);
31}