LibreChat/packages/chat/src/react/subagents/runtime.ts
Marco Beretta ce35dc25e1
🚚 refactor: Move the Subagent Thread Panel Into @librechat/chat (#17781)
* refactor: Read the Thread Panel's Jotai State Through the Chat Surface

* refactor: Move the Subagent Thread Panel Into @librechat/chat

* test: Spec the Subagent Thread Panel Against Fake Hosts

* test: Cover the App Subagents Host Adapters the Panel Move Relies On

* fix: Style the Moved Subagent Panel With Shared Variants

* test: Pin the Shared Variants the Panel Draws Its Picker and Inline Actions With

* perf: Keep the Subagent Thread Panel Out of the Boot Bundle
2026-11-08 00:29:26 +01:00

28 lines
1 KiB
TypeScript

import { useCallback } from 'react';
import { useAtom, useAtomValue, useStore } from 'jotai';
import type { SubagentControlUiState } from './state';
import type { SubagentPanelState } from './context';
import {
subagentControlStateByTask,
subagentPanelFocusRequest,
useSubagentProgress,
} from './state';
import { useSubagentActivityStream } from './stream';
function useControlStateWriter(): (identity: string, state: SubagentControlUiState | null) => void {
const store = useStore();
return useCallback(
(identity: string, state: SubagentControlUiState | null) =>
store.set(subagentControlStateByTask(identity), state),
[store],
);
}
/** The panel state `ChatSurfaceProvider` supplies: the atoms behind `SubagentPanelState`. */
export const subagentPanelState: SubagentPanelState = {
useFocusRequest: () => useAtomValue(subagentPanelFocusRequest),
useProgress: useSubagentProgress,
useControlState: (identity) => useAtom(subagentControlStateByTask(identity)),
useControlStateWriter,
useActivityStream: useSubagentActivityStream,
};