mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
The chat surface context, the durable task panel hook and the event subagent activity group move into the package. The surface context and read hooks live apart from the provider that binds the panel atoms, so the components entry loads no module-scope atom. Share state and the inline agent avatar reach the package through two new MessagePartsHost members, useShare and renderAgentAvatar, which the app fills from ShareContext and renderAgentAvatar with the same options as before.
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { useState } from 'react';
|
|
import { RecoilRoot } from 'recoil';
|
|
import { createStore, Provider as JotaiProvider } from 'jotai';
|
|
import type { ChatSurface } from '@librechat/chat/react';
|
|
import type { ReactNode } from 'react';
|
|
import { ChatSurfaceProvider } from '@librechat/chat/react';
|
|
|
|
export type JotaiStore = ReturnType<typeof createStore>;
|
|
|
|
/** The app's Recoil root, for renders that use the app's default hosts, which read it. */
|
|
export function AppStores({ children }: { children: ReactNode }) {
|
|
return <RecoilRoot>{children}</RecoilRoot>;
|
|
}
|
|
|
|
/** The application's own defaults, so a test that does not care about a
|
|
* preference reads what a reader who never changed one would see. */
|
|
export const testChatSurface = (overrides: Partial<ChatSurface> = {}): ChatSurface => ({
|
|
enterToSend: true,
|
|
maximizeChatSpace: false,
|
|
showScrollButton: true,
|
|
composerBindings: {
|
|
shortcutsEnabled: true,
|
|
submitOverride: undefined,
|
|
yieldedChords: new Set<string>(),
|
|
},
|
|
claimForeground: () => undefined,
|
|
handOffComposerText: () => undefined,
|
|
...overrides,
|
|
});
|
|
|
|
/**
|
|
* One test's own atom store. Jotai's default store is module-global, so
|
|
* without a provider one test's selection is still there for the next.
|
|
*/
|
|
export function IsolatedAtomStore({
|
|
seed,
|
|
children,
|
|
}: {
|
|
seed?: (store: JotaiStore) => void;
|
|
children: ReactNode;
|
|
}) {
|
|
const [store] = useState(() => {
|
|
const created = createStore();
|
|
seed?.(created);
|
|
return created;
|
|
});
|
|
return <JotaiProvider store={store}>{children}</JotaiProvider>;
|
|
}
|
|
|
|
/** An isolated store plus the host half of the seam the feature reads through. */
|
|
export function ChatSurfaceHarness({
|
|
surface,
|
|
seed,
|
|
children,
|
|
}: {
|
|
surface?: ChatSurface;
|
|
seed?: (store: JotaiStore) => void;
|
|
children: ReactNode;
|
|
}) {
|
|
return (
|
|
<IsolatedAtomStore seed={seed}>
|
|
<ChatSurfaceProvider value={surface ?? testChatSurface()}>{children}</ChatSurfaceProvider>
|
|
</IsolatedAtomStore>
|
|
);
|
|
}
|