LibreChat/client/test/harness.tsx
Marco Beretta b03c9432c5
🧭 refactor: Move the Chat Surface, Task Panel and Activity Group Into @librechat/chat (#17669)
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.
2026-10-31 22:09:52 +01:00

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>
);
}