Files
multica/packages/core/chat/index.ts
Naiyuan Qing 01855f6b09 revert(chat): Chat V2 — restore right-bottom floating drawer (#1580) (#1792)
* Revert "fix(chat): prevent UI flicker when streaming response finalizes (#1583)"

This reverts commit 71cc646951.

* Revert "fix(chat): prevent chatbox jump when sending first message (#1582)"

This reverts commit bb767e0ea6.

* Revert "feat(chat): Chat V2 — sidebar entry + main-area page (#1580)"

This reverts commit 35aca57939.
2026-04-28 18:31:33 +08:00

39 lines
1.3 KiB
TypeScript

export { createChatStore, CHAT_MIN_W, CHAT_MIN_H, CHAT_DEFAULT_W, CHAT_DEFAULT_H, DRAFT_NEW_SESSION } from "./store";
export type { ChatStoreOptions, ChatState, ChatTimelineItem, ContextAnchor } from "./store";
import type { createChatStore as CreateChatStoreFn } from "./store";
type ChatStoreInstance = ReturnType<typeof CreateChatStoreFn>;
/** Module-level singleton — set once at app boot via `registerChatStore()`. */
let _store: ChatStoreInstance | null = null;
/**
* Register the chat store instance created by the app.
* Must be called at boot before any component renders.
*/
export function registerChatStore(store: ChatStoreInstance) {
_store = store;
}
/**
* Singleton accessor — a Zustand hook backed by the registered instance.
* Supports `useChatStore(selector)` and `useChatStore.getState()`.
*/
export const useChatStore: ChatStoreInstance = new Proxy(
(() => {}) as unknown as ChatStoreInstance,
{
apply(_target, _thisArg, args) {
if (!_store)
throw new Error(
"Chat store not initialised — call registerChatStore() first",
);
return (_store as unknown as (...a: unknown[]) => unknown)(...args);
},
get(_target, prop) {
if (!_store) return undefined;
return Reflect.get(_store, prop);
},
},
);