Spaces:
Paused
Paused
Download console/src/plugins/registry/useChatExtensions.ts from mysticaldragon/HF: direct link, hf CLI and curl.
- Browser
- Download file 905 Bytes
-
https://huggingface.co/spaces/mysticaldragon/HF/resolve/main/console/src/plugins/registry/useChatExtensions.ts
- Command line
-
hf download hf://spaces/mysticaldragon/HF/console/src/plugins/registry/useChatExtensions.ts
-
curl -L -o useChatExtensions.ts https://huggingface.co/spaces/mysticaldragon/HF/resolve/main/console/src/plugins/registry/useChatExtensions.ts
905 Bytes
| /** | |
| * registry/useChatExtensions.ts — React subscriptions for the chat extension registry. | |
| * | |
| * Wraps `useSyncExternalStore` so ChatPage re-renders whenever a plugin | |
| * registers/disposes. Snapshots are stable refs between mutations | |
| * (the registry replaces them only on change), so the useMemo | |
| * dep chain in ChatPage doesn't fire spuriously. | |
| */ | |
| import { useSyncExternalStore } from "react"; | |
| import { | |
| chatExtensions, | |
| type ChatListSnapshot, | |
| type ChatScalarSnapshot, | |
| } from "./chatExtensions"; | |
| function subscribe(cb: () => void): () => void { | |
| return chatExtensions.subscribe(cb); | |
| } | |
| export function useChatScalarSnapshot(): ChatScalarSnapshot { | |
| return useSyncExternalStore(subscribe, () => | |
| chatExtensions.getScalarSnapshot(), | |
| ); | |
| } | |
| export function useChatListSnapshot(): ChatListSnapshot { | |
| return useSyncExternalStore(subscribe, () => | |
| chatExtensions.getListSnapshot(), | |
| ); | |
| } | |