Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
⌨️ refactor: Move Composer Input Controls Into the Chat Package (#17551)
Marco Beretta19ab2b51f5ee
diff --git a/bun.lock b/bun.lockindex 9d808a8752..5f34879fe3 100644--- a/bun.lock+++ b/bun.lock@@ -444,6 +444,7 @@"sse.js": "^2.8.0",},"devDependencies": {+ "@ariakit/react": "^0.4.29","@babel/preset-env": "^7.29.5","@babel/preset-react": "^7.22.15","@babel/preset-typescript": "^7.21.0",@@ -477,6 +478,7 @@"uuid": "^11.1.1",},"peerDependencies": {+ "@ariakit/react": "^0.4.29","@librechat/client": "*","@radix-ui/react-dialog": "^1.1.23","jotai": "^2.12.5",@@ -491,6 +493,7 @@"micromark-extension-gfm": "^3.0.0","micromark-extension-math": "^3.1.0","react": "^18.2.0 || ^19.1.0",+ "react-dom": "^18.2.0 || ^19.1.0","uuid": "^11.1.1",},},diff --git a/client/src/Providers/ComposerHostContext.tsx b/client/src/Providers/ComposerHostContext.tsxnew file mode 100644index 0000000000..9c0ec8aa1d--- /dev/null+++ b/client/src/Providers/ComposerHostContext.tsx@@ -0,0 +1,12 @@+import type { ComposerHost } from '@librechat/chat/react';+import { useShortcutAriaKey, useShortcutDisplay } from '~/hooks/useKeyboardShortcuts';+import useComposerBindings from '~/hooks/Input/useComposerBindings';++/** The app's capabilities for the composer controls in `@librechat/chat`. */+export const appComposerHost: ComposerHost = {+ useComposerBindings,+ useShortcutDisplay,+ useShortcutAriaKey,+};++export { ComposerHostProvider, useComposerHost } from '@librechat/chat/react';diff --git a/client/src/common/types.ts b/client/src/common/types.tsindex b50ccc7b96..e699daf10f 100644--- a/client/src/common/types.ts+++ b/client/src/common/types.ts@@ -68,7 +68,7 @@ export type LocalizeFunction = (export type ChatFormValues = { text: string };-export const mainTextareaId = 'prompt-textarea';+export { mainTextareaId } from '@librechat/chat';export const globalAudioId = 'global-audio';export type NavLink = {diff --git a/client/src/components/Chat/Input/AskUserQuestionPopover.tsx b/client/src/components/Chat/Input/AskUserQuestionPopover.tsxindex 2285020b82..c33294361a 100644--- a/client/src/components/Chat/Input/AskUserQuestionPopover.tsx+++ b/client/src/components/Chat/Input/AskUserQuestionPopover.tsx@@ -1,5 +1,6 @@import { memo, useCallback, useEffect, useRef } from 'react';import { useWatch } from 'react-hook-form';+import { isCancelKey } from '@librechat/chat';import { Button, TooltipAnchor } from '@librechat/client';import { useComposerOverlay } from '@librechat/chat/react';import { ChevronDown, CornerDownLeft, TriangleAlert } from 'lucide-react';@@ -7,7 +8,6 @@ import AskUserQuestions from '~/components/Chat/Messages/Content/AskUserQuestionimport useAskAnswerMode from '~/hooks/Input/useAskAnswerMode';import AskOptions from '~/components/Chat/ask/options';import { useChatFormContext } from '~/Providers';-import { isCancelKey } from '~/utils/shortcuts';import { useLocalize } from '~/hooks';/**diff --git a/client/src/components/Chat/Input/ChatForm.tsx b/client/src/components/Chat/Input/ChatForm.tsxindex f845f3d7a4..898ac949a6 100644--- a/client/src/components/Chat/Input/ChatForm.tsx+++ b/client/src/components/Chat/Input/ChatForm.tsx@@ -4,7 +4,6 @@ import { useWatch } from 'react-hook-form';import { useAtom, useAtomValue } from 'jotai';import { useNavigate } from 'react-router-dom';import { useDirection } from '@radix-ui/react-direction';-import { PastedTextDialog } from '@librechat/chat/components';import { useSteering, showStopButtonByIndex, useComposerRestoreHost } from '@librechat/chat/react';import {submitFromComposer,@@ -25,6 +24,13 @@ import {isAgentsEndpoint,isAssistantsEndpoint,} from 'librechat-data-provider';+import {+ PastedTextDialog,+ QuoteButton,+ composerHintId,+ ComposerHints as Hints,+ ComposerWaveform as Waveform,+} from '@librechat/chat/components';import type { TChatProject, TMessage, TConversation } from 'librechat-data-provider';import type { QueuedMessageContext } from '@librechat/chat';import type { SetterOrUpdater } from 'recoil';@@ -62,6 +68,7 @@ import {PendingToolApprovalButton,PendingToolApprovalPanel,} from '~/components/Chat/approval/Review';+import { WatchedSendButton, WatchedDuringRunSendButton } from './watched';import useComposerRestore from '~/hooks/Input/useComposerRestore';import { useChatSettings } from '~/Providers/ChatSettingsContext';import usePastedTextEdit from '~/hooks/Files/usePastedTextEdit';@@ -70,8 +77,6 @@ import AskUserQuestionPopover from './AskUserQuestionPopover';import useComposerItems from '~/hooks/Input/useComposerItems';import useAttachTarget from '~/hooks/Input/useAttachTarget';import { chatDirectionAtom } from '~/store/chatDirection';-import Hints, { composerHintId } from './Composer/Hints';-import DuringRunSendButton from './DuringRunSendButton';import ProjectLandingChip from '../ProjectLandingChip';import useHasAccess from '~/hooks/Roles/useHasAccess';import useDictation from '~/hooks/Input/useDictation';@@ -82,11 +87,8 @@ import TextareaHeader from './TextareaHeader';import PromptsCommand from './PromptsCommand';import SkillsCommand from './SkillsCommand';import AutoPlayAudio from './AutoPlayAudio';-import Waveform from './Composer/Waveform';import { mainTextareaId } from '~/common';-import QuoteButton from './QuoteButton';import ToolDialogs from './ToolDialogs';-import SendButton from './SendButton';import Queue from './Composer/Queue';import Tray from './Composer/Tray';import Bar from './Composer/Bar';@@ -616,7 +618,7 @@ const ChatForm = memo(function ChatForm({if (sendOwnsSlot) {return (<>- <DuringRunSendButton+ <WatchedDuringRunSendButtonref={submitButtonRef}control={methods.control}steering={steering}@@ -659,7 +661,7 @@ const ChatForm = memo(function ChatForm({isSubmitting && !answerMode.composerAnswers && duringRunSlot != null? duringRunSlot: endpoint && (- <SendButton+ <WatchedSendButtonref={submitButtonRef}control={methods.control}fileCount={submittableFileCount}diff --git a/client/src/components/Chat/Input/Composer/Bar.tsx b/client/src/components/Chat/Input/Composer/Bar.tsxindex 705527b2a1..ea3f8a6ed8 100644--- a/client/src/components/Chat/Input/Composer/Bar.tsx+++ b/client/src/components/Chat/Input/Composer/Bar.tsx@@ -1,5 +1,6 @@import React, { memo, useMemo, useState, useCallback } from 'react';import * as Ariakit from '@ariakit/react';+import { useElementSize } from '@librechat/chat/react';import { ComposerChip as Chip } from '@librechat/chat/components';import { Mic, Plus, Check, Square, ChevronDown } from 'lucide-react';import { IconButton, TooltipAnchor, SendIcon } from '@librechat/client';@@ -10,7 +11,6 @@ import type { ExtendedFile, FileSetter } from '~/common';import usePaletteEntries from '~/hooks/Input/usePaletteEntries';import MCPConfigDialog from '~/components/MCP/MCPConfigDialog';import useToolFavorites from '~/hooks/Input/useToolFavorites';-import useElementSize from '~/hooks/Generic/useElementSize';import useChipPacking from '~/hooks/Input/useChipPacking';import { useBadgeRowContext } from '~/Providers';import TokenUsage from '../TokenUsage';diff --git a/client/src/components/Chat/Input/Composer/Effort.tsx b/client/src/components/Chat/Input/Composer/Effort.tsxindex 3d9cc98b7f..bf057e5ce2 100644--- a/client/src/components/Chat/Input/Composer/Effort.tsx+++ b/client/src/components/Chat/Input/Composer/Effort.tsx@@ -1,5 +1,6 @@import { memo, useRef, useMemo, useState, useEffect, useCallback } from 'react';import { CircleHelp } from 'lucide-react';+import { useReducedMotion } from '@librechat/chat/react';import { Constants, reasoningOverrideSchema } from 'librechat-data-provider';import {Button,@@ -13,7 +14,6 @@ import type { SettingDefinition, TConversation, TReasoningOverride } from 'libreimport type { CSSProperties } from 'react';import type { LocalizeFunction } from '~/common';import type { TranslationKeys } from '~/hooks';-import useReducedMotion from '~/hooks/Generic/useReducedMotion';import { useLocalize } from '~/hooks';import { cn } from '~/utils';diff --git a/client/src/components/Chat/Input/Composer/Palette.tsx b/client/src/components/Chat/Input/Composer/Palette.tsxindex ea3792d262..018b8d1090 100644--- a/client/src/components/Chat/Input/Composer/Palette.tsx+++ b/client/src/components/Chat/Input/Composer/Palette.tsx@@ -9,10 +9,11 @@ import React, {} from 'react';import { useSetAtom } from 'jotai';import * as Ariakit from '@ariakit/react';+import { isMacPlatform } from '@librechat/chat';import { AutoSizer, List } from 'react-virtualized';-import { composerLiftFamily } from '@librechat/chat/react';import { Star, Plus, Search, ChevronDown } from 'lucide-react';import { FilePreview, getFileType } from '@librechat/chat/components';+import { composerLiftFamily, useReducedMotion, useElementSize } from '@librechat/chat/react';import { Button, FileUpload, IconButton, TooltipAnchor, useMediaQuery } from '@librechat/client';import type {TFile,@@ -26,14 +27,11 @@ import type { ExtendedFile, FileSetter } from '~/common';import type { CatalogSection } from './Catalog';import type { TranslationKeys } from '~/hooks';import { SharePointPickerDialog } from '~/components/SharePoint';-import useReducedMotion from '~/hooks/Generic/useReducedMotion';import useToolFavorites from '~/hooks/Input/useToolFavorites';-import useElementSize from '~/hooks/Generic/useElementSize';import useRecentFiles from '~/hooks/Input/useRecentFiles';import useAttachItems from '~/hooks/Input/useAttachItems';import { useMCPRefresh } from '~/hooks/MCP/useMCPRefresh';import { isUnifiedUploadMode, cn } from '~/utils';-import { isMacPlatform } from '~/utils/shortcuts';import { useBadgeRowContext } from '~/Providers';import { useLocalize } from '~/hooks';import Catalog from './Catalog';diff --git a/client/src/components/Chat/Input/Composer/Queue.tsx b/client/src/components/Chat/Input/Composer/Queue.tsxindex 4eb1be24c3..143164a80f 100644--- a/client/src/components/Chat/Input/Composer/Queue.tsx+++ b/client/src/components/Chat/Input/Composer/Queue.tsx@@ -4,8 +4,8 @@ import { createPortal } from 'react-dom';import * as Ariakit from '@ariakit/react';import { useDrag, useDrop } from 'react-dnd';import { queuedMessagesByConvoId } from '@librechat/chat/react';-import { useQueuedTurnPortal } from '@librechat/chat/components';import { AnimatePresence, motion, useReducedMotion } from 'framer-motion';+import { useQueuedTurnPortal, EscalateNowButton } from '@librechat/chat/components';import { claimQueuedIntent, releaseQueuedIntent, hasQueuedIntent } from '@librechat/chat';import {escalatingSteerFamily,@@ -36,7 +36,6 @@ import type { RestoreToComposer } from '@librechat/chat/react';import type { SteeringControls } from '@librechat/chat/react';import type { MenuItemProps } from '@librechat/client';import type { QueuedMessage } from '@librechat/chat';-import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';import { useLocalize } from '~/hooks';import { cn } from '~/utils';diff --git a/client/src/components/Chat/Input/Composer/__tests__/Palette.spec.tsx b/client/src/components/Chat/Input/Composer/__tests__/Palette.spec.tsxindex 2e3c2e84ad..8a4b430ed7 100644--- a/client/src/components/Chat/Input/Composer/__tests__/Palette.spec.tsx+++ b/client/src/components/Chat/Input/Composer/__tests__/Palette.spec.tsx@@ -26,9 +26,9 @@ jest.mock('react-virtualized', () => {};});-jest.mock('~/hooks/Generic/useElementSize', () => ({- __esModule: true,- default: () => ({ ref: { current: null }, height: mockPopupHeight, width: 0 }),+jest.mock('@librechat/chat/react', () => ({+ ...jest.requireActual('@librechat/chat/react'),+ useElementSize: () => ({ ref: { current: null }, height: mockPopupHeight, width: 0 }),}));jest.mock('~/components/SharePoint', () => ({ SharePointPickerDialog: () => null }));diff --git a/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx b/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsxindex 65d39eb117..bf1fcfd6e7 100644--- a/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx+++ b/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx@@ -43,6 +43,7 @@ jest.mock('@librechat/client', () => {);IconButton.displayName = 'IconButton';return {+ ...jest.requireActual('@librechat/client'),Button: ({ children, ...props }: { children?: React.ReactNode } & Record<string, unknown>) =>ReactActual.createElement('button', { type: 'button', ...props }, children),IconButton,@@ -93,6 +94,8 @@ jest.mock('@librechat/client', () => {? ReactActual.cloneElement(render, props): ReactActual.createElement('span', props, children),useMediaQuery: () => true,+ useLocalize: () => (key: string, options?: Record<string, string | number>) =>+ options ? `${key}:${options.count ?? options['0']}` : key,useToastContext: () => ({ showToast: mockShowToast }),};});diff --git a/client/src/components/Chat/Input/Composer/__tests__/Thinking.spec.tsx b/client/src/components/Chat/Input/Composer/__tests__/Thinking.spec.tsxindex 992553e21b..d16edf986e 100644--- a/client/src/components/Chat/Input/Composer/__tests__/Thinking.spec.tsx+++ b/client/src/components/Chat/Input/Composer/__tests__/Thinking.spec.tsx@@ -40,9 +40,9 @@ jest.mock('../../Reasoning', () => ({}),}));-jest.mock('~/hooks/Generic/useReducedMotion', () => ({- __esModule: true,- default: () => true,+jest.mock('@librechat/chat/react', () => ({+ ...jest.requireActual('@librechat/chat/react'),+ useReducedMotion: () => true,}));jest.mock('~/hooks', () => ({diff --git a/client/src/components/Chat/Input/Composer/__tests__/semanticTokens.spec.ts b/client/src/components/Chat/Input/Composer/__tests__/semanticTokens.spec.tsindex f55c880bdb..d18fb3fbb6 100644--- a/client/src/components/Chat/Input/Composer/__tests__/semanticTokens.spec.ts+++ b/client/src/components/Chat/Input/Composer/__tests__/semanticTokens.spec.ts@@ -24,7 +24,10 @@ const composerModules = [const protectedModules = [...composerModules,join(__dirname, '..', '..', 'Reasoning.tsx'),- join(__dirname, '..', '..', 'EscalateNowButton.tsx'),+ join(+ __dirname,+ '../../../../../../../packages/chat/src/components/composer/EscalateNowButton.tsx',+ ),join(__dirname, '..', '..', '..', 'Messages', 'Content', 'Parts', 'PendingSteers.tsx'),join(__dirname, '..', '..', '..', '..', '..', 'hooks', 'Input', 'usePaletteEntries.tsx'),];diff --git a/client/src/components/Chat/Input/Mention.tsx b/client/src/components/Chat/Input/Mention.tsxindex 2eac03af60..25c4b81326 100644--- a/client/src/components/Chat/Input/Mention.tsx+++ b/client/src/components/Chat/Input/Mention.tsx@@ -3,11 +3,11 @@ import { AutoSizer, List } from 'react-virtualized';import { EModelEndpoint } from 'librechat-data-provider';import { MentionItem } from '@librechat/chat/components';import { useRecoilValue, useSetRecoilState } from 'recoil';+import { useInitPopoverInput } from '@librechat/chat/react';import { Input, Spinner, useCombobox, useRemScale } from '@librechat/client';import type { RecoilState } from 'recoil';import type { MentionOption, ConvoGenerator } from '~/common';import { useGetConversation, useLocalize, TranslationKeys } from '~/hooks';-import useInitPopoverInput from '~/hooks/Input/useInitPopoverInput';import useSelectMention from '~/hooks/Input/useSelectMention';import { useAssistantsMapContext } from '~/Providers';import useMentions from '~/hooks/Input/useMentions';diff --git a/client/src/components/Chat/Input/PromptsCommand.tsx b/client/src/components/Chat/Input/PromptsCommand.tsxindex da1e7e82ea..887666eabf 100644--- a/client/src/components/Chat/Input/PromptsCommand.tsx+++ b/client/src/components/Chat/Input/PromptsCommand.tsx@@ -2,6 +2,7 @@ import { useState, useRef, useEffect, useMemo, memo, useCallback } from 'react';import { AutoSizer, List } from 'react-virtualized';import { MentionItem } from '@librechat/chat/components';import { useSetRecoilState, useRecoilValue } from 'recoil';+import { useInitPopoverInput } from '@librechat/chat/react';import { Input, Spinner, useCombobox, useRemScale, useToastContext } from '@librechat/client';import type { TPromptGroup } from 'librechat-data-provider';import type { PromptOption } from '~/common';@@ -13,7 +14,6 @@ import {} from '~/utils';import { activateCatalog, useLocalize, usePromptContentResolver } from '~/hooks';import useChatScopedRequest from '~/hooks/Prompts/useChatScopedRequest';-import useInitPopoverInput from '~/hooks/Input/useInitPopoverInput';import { useRecordPromptUsage } from '~/data-provider';import { VariableDialog } from '~/components/Prompts';import { usePromptGroupsContext } from '~/Providers';diff --git a/client/src/components/Chat/Input/SkillsCommand.tsx b/client/src/components/Chat/Input/SkillsCommand.tsxindex aa7197a9d4..4bab5bd81b 100644--- a/client/src/components/Chat/Input/SkillsCommand.tsx+++ b/client/src/components/Chat/Input/SkillsCommand.tsx@@ -6,10 +6,13 @@ import { AutoSizer, List } from 'react-virtualized';import { MentionItem } from '@librechat/chat/components';import { Input, Spinner, useCombobox, useRemScale } from '@librechat/client';import { SkillsScope, resolveAgentSkillsScope } from 'librechat-data-provider';-import { pendingManualSkillsByConvoId, showSkillsPopoverFamily } from '@librechat/chat/react';+import {+ pendingManualSkillsByConvoId,+ showSkillsPopoverFamily,+ useInitPopoverInput,+} from '@librechat/chat/react';import type { TSkillSummary } from 'librechat-data-provider';import type { MentionOption } from '~/common';-import useInitPopoverInput from '~/hooks/Input/useInitPopoverInput';import { useLocalize, useSkillActiveState } from '~/hooks';import { useSkillsInfiniteQuery } from '~/data-provider';import { useAgentsMapContext } from '~/Providers';diff --git a/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx b/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsxindex 3787c43989..e1aaa8a44e 100644--- a/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx+++ b/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx@@ -4,10 +4,12 @@ import { useForm } from 'react-hook-form';import { render, screen, fireEvent } from '@testing-library/react';import type { SteeringControls } from '@librechat/chat/react';import type { ShortcutOverride } from '~/store/misc';-import DuringRunSendButton from '../DuringRunSendButton';+import { ComposerHostTestProvider } from 'test/composerHost';+import { WatchedDuringRunSendButton } from '../watched';import store from '~/store';-jest.mock('~/hooks', () => ({+jest.mock('@librechat/client', () => ({+ ...jest.requireActual('@librechat/client'),useLocalize: () => (key: string) => key,}));@@ -68,15 +70,17 @@ function Harness({}) {const methods = useForm<{ text: string }>({ defaultValues: { text: TEXT } });return (- <DuringRunSendButton- control={methods.control}- steering={steering}- isNewConversation={isNewConversation}- getText={() => TEXT}- onConsumed={mockOnConsumed}- enterToSend={enterToSend}- disabled={disabled}- />+ <ComposerHostTestProvider>+ <WatchedDuringRunSendButton+ control={methods.control}+ steering={steering}+ isNewConversation={isNewConversation}+ getText={() => TEXT}+ onConsumed={mockOnConsumed}+ enterToSend={enterToSend}+ disabled={disabled}+ />+ </ComposerHostTestProvider>);}diff --git a/client/src/components/Chat/Input/watched.tsx b/client/src/components/Chat/Input/watched.tsxnew file mode 100644index 0000000000..9cd17c8154--- /dev/null+++ b/client/src/components/Chat/Input/watched.tsx@@ -0,0 +1,26 @@+import { forwardRef } from 'react';+import { useWatch } from 'react-hook-form';+import { SendButton, DuringRunSendButton } from '@librechat/chat/components';+import type { Control } from 'react-hook-form';+import type { ComponentProps } from 'react';+import type { ChatFormValues } from '~/common';++type Watched<P> = Omit<P, 'text'> & { control: Control<ChatFormValues> };++/** The package buttons take the text as a value; watching it here keeps a keystroke from+ * re-rendering more than the button, as it did when the buttons subscribed themselves. */+export const WatchedSendButton = forwardRef<+ HTMLButtonElement,+ Watched<ComponentProps<typeof SendButton>>+>(function WatchedSendButton({ control, ...props }, ref) {+ const text = useWatch({ control, name: 'text' });+ return <SendButton ref={ref} text={text ?? ''} {...props} />;+});++export const WatchedDuringRunSendButton = forwardRef<+ HTMLButtonElement,+ Watched<ComponentProps<typeof DuringRunSendButton>>+>(function WatchedDuringRunSendButton({ control, ...props }, ref) {+ const text = useWatch({ control, name: 'text' });+ return <DuringRunSendButton ref={ref} text={text ?? ''} {...props} />;+});diff --git a/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx b/client/src/components/Chat/Messages/Content/AskUserQuestion.tsxindex d4d12044ec..f016b9f094 100644--- a/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx+++ b/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx@@ -1,9 +1,9 @@import { useContext, useMemo, useState } from 'react';import { Button, TextareaAutosize, TooltipAnchor } from '@librechat/client';import { ChevronDown, MessageCircleQuestion, TriangleAlert } from 'lucide-react';+import { isCancelKey, isReboundSubmitChord, resolveComposerKeyDown } from '@librechat/chat';import type { Agents } from 'librechat-data-provider';import type { KeyboardEvent } from 'react';-import { isCancelKey, isReboundSubmitChord, resolveComposerKeyDown } from '~/utils/shortcuts';import { useApprovalContext, useAskSubmitStatus, useResumeSubmit } from './ApprovalContext';import { splitOtherOption, ASK_USER_DECLINED_ANSWER } from '~/utils/approval';import { useOptionalChatSurface } from '~/components/Chat/Subagents/surface';diff --git a/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx b/client/src/components/Chat/Messages/Content/AskUserQuestions.tsxindex 3a542d754c..f036a44669 100644--- a/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx+++ b/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx@@ -1,10 +1,10 @@import { useCallback, useEffect, useId, useMemo, useRef } from 'react';import { TriangleAlert } from 'lucide-react';import { Input, Button } from '@librechat/client';+import { isCancelKey, isReboundSubmitChord } from '@librechat/chat';import type { Agents } from 'librechat-data-provider';import type { KeyboardEvent, ReactNode } from 'react';import { useOptionalChatSurface } from '~/components/Chat/Subagents/surface';-import { isCancelKey, isReboundSubmitChord } from '~/utils/shortcuts';import useAskQuestionsForm from '~/hooks/Input/useAskQuestionsForm';import AskOptions from '~/components/Chat/ask/options';import { splitOtherOption } from '~/utils/approval';diff --git a/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx b/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsxindex d054ef0891..d061ed6041 100644--- a/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx+++ b/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx@@ -4,7 +4,7 @@ import { Clock, TextQuote, X } from 'lucide-react';import { useQueryClient } from '@tanstack/react-query';import { Button, TooltipAnchor } from '@librechat/client';import { QueryKeys, type TMessage } from 'librechat-data-provider';-import { getMessageRowWidthClass } from '@librechat/chat/components';+import { EscalateNowButton, getMessageRowWidthClass } from '@librechat/chat/components';import {useSteerCancel,useSteerMoveToQueue,@@ -13,7 +13,6 @@ import {useSteerRecovery,} from '@librechat/chat/react';import type { SteerReceiptState } from '@librechat/chat/components';-import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';import { useGetMessagesByConvoId } from '~/data-provider';import { cn, isLegacyDeliveryUncertain } from '~/utils';diff --git a/client/src/components/Chat/Messages/Content/ToolApproval.tsx b/client/src/components/Chat/Messages/Content/ToolApproval.tsxindex 1903c4d77f..d9113555ff 100644--- a/client/src/components/Chat/Messages/Content/ToolApproval.tsx+++ b/client/src/components/Chat/Messages/Content/ToolApproval.tsx@@ -9,16 +9,16 @@ import {ShieldQuestion,TriangleAlert,} from 'lucide-react';-import type { Agents } from 'librechat-data-provider';-import type { KeyboardEvent } from 'react';-import type { TranslationKeys } from '~/hooks';import {isReboundSubmitChord,resolveComposerKeyDown,bindingFromEvent,bindingsMatch,bindingHash,-} from '~/utils/shortcuts';+} from '@librechat/chat';+import type { Agents } from 'librechat-data-provider';+import type { KeyboardEvent } from 'react';+import type { TranslationKeys } from '~/hooks';import { useComposerPresentsApproval } from '~/components/Chat/approval/state';import { useOptionalChatSurface } from '~/components/Chat/Subagents/surface';import { boundApprovalLabel } from '~/components/Chat/approval/preview';diff --git a/client/src/components/Chat/Messages/Content/__tests__/AskUserQuestion.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/AskUserQuestion.test.tsxindex 19f10beea2..55538f2f72 100644--- a/client/src/components/Chat/Messages/Content/__tests__/AskUserQuestion.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/AskUserQuestion.test.tsx@@ -1,8 +1,8 @@import React from 'react';import { RecoilRoot } from 'recoil';import { fireEvent, render, screen } from '@testing-library/react';+import type { ShortcutBinding } from '@librechat/chat';import type { Agents } from 'librechat-data-provider';-import type { ShortcutBinding } from '~/utils/shortcuts';import { ChatSurfaceProvider } from '~/components/Chat/Subagents/surface';import { ASK_USER_DECLINED_ANSWER } from '~/utils/approval';import ApprovalProvider from '../ApprovalContext';diff --git a/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsxindex 8ea5e191ae..40f5aa93cb 100644--- a/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx@@ -3,8 +3,8 @@ import { RecoilRoot } from 'recoil';import { Provider, createStore } from 'jotai';import { activeGenerationCreatedAtByConvoId } from '@librechat/chat/react';import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';+import type { ShortcutBinding } from '@librechat/chat';import type { Agents } from 'librechat-data-provider';-import type { ShortcutBinding } from '~/utils/shortcuts';import {approvalPanelOpenFamily,pendingApprovalActionFamily,diff --git a/client/src/components/Chat/Messages/Content/verticals.tsx b/client/src/components/Chat/Messages/Content/verticals.tsxindex f4c0f4e7a8..2da928863e 100644--- a/client/src/components/Chat/Messages/Content/verticals.tsx+++ b/client/src/components/Chat/Messages/Content/verticals.tsx@@ -1,12 +1,12 @@import { Star, MapPin } from 'lucide-react';import { Tools } from 'librechat-data-provider';+import { isMacPlatform } from '@librechat/chat';import type {TAttachment,ImageResult,PlaceResult,ShoppingResult,} from 'librechat-data-provider';-import { isMacPlatform } from '~/utils/shortcuts';import { isSafeUrl } from '~/utils/markdown';import { useLocalize } from '~/hooks';import { cn } from '~/utils';diff --git a/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx b/client/src/components/Chat/Subagents/SubagentThreadPanel.tsxindex 40e70b2a3b..148b1e8a7d 100644--- a/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx+++ b/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx@@ -3,6 +3,7 @@ import { v4 } from 'uuid';import { useNavigate } from 'react-router-dom';import { dataService, ForkOptions } from 'librechat-data-provider';import { useAtom, useAtomValue, useSetAtom, useStore } from 'jotai';+import { isMacPlatform, resolveComposerKeyDown } from '@librechat/chat';import { ArrowUpRight, Clock, OctagonPause, X, Zap } from 'lucide-react';import {Alert,@@ -30,7 +31,7 @@ import type {import type { ComposerKeyVerdict, ComposerStopProps, SendAction } from '@librechat/client';import type { ActiveSubagentPanel, SubagentControlUiState } from '@librechat/chat/react';import type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';-import type { ComposerKeyAction } from '~/utils/shortcuts';+import type { ComposerKeyAction } from '@librechat/chat';import type { OptionWithIcon } from '~/common';import {ACTIVE_THREAD_REFRESH_MS,@@ -58,7 +59,6 @@ import {import SubagentActivity, { SubagentActivityScrollSurface } from './SubagentActivity';import ApprovalProvider from '~/components/Chat/Messages/Content/ApprovalContext';import { TaskContentScopeContext } from '~/data-provider/Subagents/content';-import { isMacPlatform, resolveComposerKeyDown } from '~/utils/shortcuts';import { useFocusTrap, useLocalize, useNavigateToConvo } from '~/hooks';import { ARTIFACTS_SHEET_MAX_WIDTH } from '~/utils/breakpoints';import { useConfiguredFooter } from '~/components/Chat/Footer';diff --git a/client/src/components/Chat/approval/Review.tsx b/client/src/components/Chat/approval/Review.tsxindex 730c71b00b..0f74f5289e 100644--- a/client/src/components/Chat/approval/Review.tsx+++ b/client/src/components/Chat/approval/Review.tsx@@ -1,5 +1,6 @@import { memo, useEffect, useMemo } from 'react';import { useAtom, useAtomValue } from 'jotai';+import { isCancelKey } from '@librechat/chat';import { Button, TooltipAnchor } from '@librechat/client';import { useComposerOverlay } from '@librechat/chat/react';import { ChevronDown, ChevronUp, ShieldQuestion, TriangleAlert } from 'lucide-react';@@ -16,7 +17,6 @@ import {} from '~/components/Chat/approval/state';import { buildApprovalPreview, buildApprovalPreviews } from '~/components/Chat/approval/preview';import ToolApproval from '~/components/Chat/Messages/Content/ToolApproval';-import { isCancelKey } from '~/utils/shortcuts';import { useLocalize } from '~/hooks';function usePendingToolApproval(conversationId: string) {diff --git a/client/src/components/Nav/KeyboardShortcutsDialog.tsx b/client/src/components/Nav/KeyboardShortcutsDialog.tsxindex 0224b74d79..fe2226ca3e 100644--- a/client/src/components/Nav/KeyboardShortcutsDialog.tsx+++ b/client/src/components/Nav/KeyboardShortcutsDialog.tsx@@ -1,5 +1,6 @@import { memo, useCallback, useId, useMemo, useState } from 'react';import { Plus, X } from 'lucide-react';+import { bindingDisplayKeys } from '@librechat/chat';import { useRecoilState, useRecoilValue } from 'recoil';import {Label,@@ -9,12 +10,11 @@ import {OGDialogTitle,OGDialogContent,} from '@librechat/client';+import type { ShortcutBinding } from '@librechat/chat';import type { ShortcutActionId, ShortcutBindingInfo } from '~/hooks/useKeyboardShortcuts';import type { TranslationKeys } from '~/hooks/useLocalize';-import type { ShortcutBinding } from '~/utils/shortcuts';import { RecorderInfo, RecorderPill, useShortcutRecorder } from './ShortcutRecorder';import { isMac, useShortcutBindings } from '~/hooks/useKeyboardShortcuts';-import { bindingDisplayKeys } from '~/utils/shortcuts';import ShortcutKeyCombo from './ShortcutKeyCombo';import { useLocalize } from '~/hooks';import { cn } from '~/utils';diff --git a/client/src/components/Nav/ShortcutRecorder.tsx b/client/src/components/Nav/ShortcutRecorder.tsxindex 682fdfa225..f4a829e8ce 100644--- a/client/src/components/Nav/ShortcutRecorder.tsx+++ b/client/src/components/Nav/ShortcutRecorder.tsx@@ -1,7 +1,5 @@import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { X } from 'lucide-react';-import type { RefObject } from 'react';-import type { ShortcutBinding } from '~/utils/shortcuts';import {bindingDisplayKeys,bindingHash,@@ -9,7 +7,9 @@ import {isModifierKey,isValidBinding,normalizeKey,-} from '~/utils/shortcuts';+} from '@librechat/chat';+import type { ShortcutBinding } from '@librechat/chat';+import type { RefObject } from 'react';import { isMac } from '~/hooks/useKeyboardShortcuts';import ShortcutKeyCombo from './ShortcutKeyCombo';import { useLocalize } from '~/hooks';diff --git a/client/src/components/Nav/__tests__/ShortcutRecorder.spec.tsx b/client/src/components/Nav/__tests__/ShortcutRecorder.spec.tsxindex 6d5ebb8d0c..978bdba523 100644--- a/client/src/components/Nav/__tests__/ShortcutRecorder.spec.tsx+++ b/client/src/components/Nav/__tests__/ShortcutRecorder.spec.tsx@@ -1,6 +1,6 @@+import { bindingHash } from '@librechat/chat';import { fireEvent, render, screen } from '@testing-library/react';import { RecorderInfo, RecorderPill, useShortcutRecorder } from '../ShortcutRecorder';-import { bindingHash } from '~/utils/shortcuts';jest.mock('~/hooks', () => ({useLocalize: () => (key: string) => key,diff --git a/client/src/hooks/Generic/index.ts b/client/src/hooks/Generic/index.tsindex 34134a06d4..d9c64d965f 100644--- a/client/src/hooks/Generic/index.ts+++ b/client/src/hooks/Generic/index.ts@@ -1,5 +1,4 @@export * from './useLazyEffect';export { default as useShiftKey } from './useShiftKey';-export { default as useElementSize } from './useElementSize';export { default as useOuterScrollWindow } from './useOuterScrollWindow';-export { default as useReducedMotion } from './useReducedMotion';+export { useElementSize, useReducedMotion } from '@librechat/chat/react';diff --git a/client/src/hooks/Input/useComposerBindings.spec.tsx b/client/src/hooks/Input/useComposerBindings.spec.tsxindex 3c735f65c1..1c498bb59e 100644--- a/client/src/hooks/Input/useComposerBindings.spec.tsx+++ b/client/src/hooks/Input/useComposerBindings.spec.tsx@@ -1,9 +1,9 @@import React from 'react';import { RecoilRoot } from 'recoil';import { renderHook } from '@testing-library/react';+import { resolveComposerKeyDown } from '@librechat/chat';import type { MutableSnapshot } from 'recoil';import type { ReactNode } from 'react';-import { resolveComposerKeyDown } from '~/utils/shortcuts';import useComposerBindings from './useComposerBindings';import store from '~/store';diff --git a/client/src/hooks/Input/useComposerBindings.ts b/client/src/hooks/Input/useComposerBindings.tsindex 39a5c356fa..9fa80f7d1b 100644--- a/client/src/hooks/Input/useComposerBindings.ts+++ b/client/src/hooks/Input/useComposerBindings.ts@@ -1,40 +1,13 @@import { useMemo } from 'react';import { useRecoilValue } from 'recoil';+import { bindingHash } from '@librechat/chat';+import type { ComposerBindings } from '@librechat/chat';import type { ShortcutActionId } from '~/hooks/useKeyboardShortcuts';-import type { ShortcutBinding } from '~/utils/shortcuts';import { EDITING_ALLOWED_SHORTCUTS, resolveShortcutBindings } from '~/hooks/useKeyboardShortcuts';-import { bindingHash } from '~/utils/shortcuts';import store from '~/store';-export type ComposerBindings = {- /** Whether user-configurable keyboard shortcuts are globally enabled. */- shortcutsEnabled: boolean;- /**- * Effective `submitMessage` override: `undefined` when unset (default Ctrl/Cmd+Enter applies),- * `null` when explicitly unbound, otherwise the rebound chord.- */- submitOverride: ShortcutBinding | null | undefined;- /**- * Chords the user has bound to global shortcuts that still run while typing- * (`EDITING_ALLOWED_SHORTCUTS`). The window-level handler in- * `useKeyboardShortcuts` runs AFTER the composer's and yields any keypress- * a closer handler claimed via `preventDefault`, so the composer must leave- * these chords entirely untouched — acting on them would claim the event- * and silently swallow the global action. `submitMessage` is excluded: its- * rebinding is resolved through `submitOverride` instead. No default binding- * uses an Enter chord besides submit, so this only ever yields to a- * deliberate rebinding.- */- yieldedChords: ReadonlySet<string>;-};--/** Default bindings for a card rendered without a chat surface host- * (Share, search), where the user's custom shortcuts are not in scope. */-export const NO_HOST_BINDINGS: ComposerBindings = {- shortcutsEnabled: true,- submitOverride: undefined,- yieldedChords: new Set(),-};+export { NO_HOST_BINDINGS } from '@librechat/chat';+export type { ComposerBindings } from '@librechat/chat';/** The user's effective composer-relevant shortcut bindings, shared by the* composer keydown handler and the during-run hovercard hints. */diff --git a/client/src/hooks/Input/useDictation.ts b/client/src/hooks/Input/useDictation.tsindex 0be89d0326..d166b90e17 100644--- a/client/src/hooks/Input/useDictation.ts+++ b/client/src/hooks/Input/useDictation.ts@@ -1,9 +1,9 @@import { useRef, useMemo, useState, useEffect, useCallback } from 'react';import { useToastContext } from '@librechat/client';+import { isFocusedChatPane } from '@librechat/chat';import type { TAskFunction } from '~/common';import useGetAudioSettings from './useGetAudioSettings';import { useChatFormContext } from '~/Providers';-import { isFocusedChatPane } from '~/utils/pane';import useSpeechToText from './useSpeechToText';import { globalAudioId } from '~/common';import useLocalize from '../useLocalize';diff --git a/client/src/hooks/Input/useTextarea.spec.tsx b/client/src/hooks/Input/useTextarea.spec.tsxindex fdd17dffe8..c82eaed768 100644--- a/client/src/hooks/Input/useTextarea.spec.tsx+++ b/client/src/hooks/Input/useTextarea.spec.tsx@@ -126,7 +126,8 @@ jest.mock('~/Providers', () => ({useUploadModalContext: jest.fn(() => ({ openModal: mockOpenModal })),}));-jest.mock('~/utils/shortcuts', () => ({+jest.mock('@librechat/chat', () => ({+ ...jest.requireActual('@librechat/chat'),resolveComposerKeyDown: jest.fn(),}));diff --git a/client/src/hooks/Input/useTextarea.ts b/client/src/hooks/Input/useTextarea.tsindex b46717df53..944a91ff83 100644--- a/client/src/hooks/Input/useTextarea.ts+++ b/client/src/hooks/Input/useTextarea.ts@@ -3,6 +3,7 @@ import { v4 } from 'uuid';import debounce from 'lodash/debounce';import { useToastContext } from '@librechat/client';import { useRecoilValue, useRecoilState } from 'recoil';+import { resolveComposerKeyDown } from '@librechat/chat';import { Constants, EToolResources, isAssistantsEndpoint } from 'librechat-data-provider';import type { TEndpointOption } from 'librechat-data-provider';import type { KeyboardEvent } from 'react';@@ -35,7 +36,6 @@ import { useChatSettings } from '~/Providers/ChatSettingsContext';import useGetSender from '~/hooks/Conversations/useGetSender';import useUploadOptions from '~/hooks/Files/useUploadOptions';import { useInteractionHealthCheck } from '~/data-provider';-import { resolveComposerKeyDown } from '~/utils/shortcuts';import { useChatContext } from '~/Providers/ChatContext';import { globalAudioId } from '~/common';import { useLocalize } from '~/hooks';diff --git a/client/src/hooks/useKeyboardShortcuts.spec.tsx b/client/src/hooks/useKeyboardShortcuts.spec.tsxindex 7a87e30a71..d8e6ce3493 100644--- a/client/src/hooks/useKeyboardShortcuts.spec.tsx+++ b/client/src/hooks/useKeyboardShortcuts.spec.tsx@@ -1,5 +1,6 @@import { MemoryRouter } from 'react-router-dom';import { RecoilRoot, useRecoilValue } from 'recoil';+import { bindingDisplayString, bindingToString } from '@librechat/chat';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { render, act, cleanup, renderHook, fireEvent, screen } from '@testing-library/react';import type { SettingDefinition, TConversation } from 'librechat-data-provider';@@ -17,7 +18,6 @@ import useKeyboardShortcuts, {useShortcutDisplay,useShortcutAriaKey,} from './useKeyboardShortcuts';-import { bindingDisplayString, bindingToString } from '~/utils/shortcuts';import { ReasoningControl } from '~/components/Chat/Input/Reasoning';import Thinking from '~/components/Chat/Input/Composer/Thinking';import store from '~/store';@@ -54,9 +54,9 @@ jest.mock('~/Providers', () => ({}),}));-jest.mock('~/hooks/Generic/useReducedMotion', () => ({- __esModule: true,- default: () => true,+jest.mock('@librechat/chat/react', () => ({+ ...jest.requireActual('@librechat/chat/react'),+ useReducedMotion: () => true,}));jest.mock('copy-to-clipboard', () => ({diff --git a/client/src/hooks/useKeyboardShortcuts.ts b/client/src/hooks/useKeyboardShortcuts.tsindex f4487b2e05..233a489bea 100644--- a/client/src/hooks/useKeyboardShortcuts.ts+++ b/client/src/hooks/useKeyboardShortcuts.ts@@ -6,8 +6,6 @@ import { useIsSubmitting } from '@librechat/chat/react';import { useMatch, useNavigate } from 'react-router-dom';import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';import { PermissionTypes, Permissions, isForcedTemporaryRetention } from 'librechat-data-provider';-import type { ShortcutBinding } from '~/utils/shortcuts';-import type { ShortcutOverride } from '~/store/misc';import {bindingDisplayString,bindingFromEvent,@@ -15,14 +13,16 @@ import {bindingToString,isMacPlatform,parseBinding,-} from '~/utils/shortcuts';+ getFocusedChatPane,+} from '@librechat/chat';+import type { ShortcutBinding } from '@librechat/chat';+import type { ShortcutOverride } from '~/store/misc';import { useArchiveConvoMutation, useGetStartupConfig } from '~/data-provider';import { mainTextareaId, NotificationSeverity } from '~/common';import useSidebarToggle from '~/hooks/Nav/useSidebarToggle';import { showFilesDialogAtom } from '~/store/filesDialog';import useNewChat from '~/hooks/Conversations/useNewChat';import { useHasAccess, useLocalize } from '~/hooks';-import { getFocusedChatPane } from '~/utils/pane';import store from '~/store';const isMac = isMacPlatform;diff --git a/client/src/routes/Root.tsx b/client/src/routes/Root.tsxindex 05247a3387..6bb7687e13 100644--- a/client/src/routes/Root.tsx+++ b/client/src/routes/Root.tsx@@ -33,6 +33,7 @@ import {CodeHighlightThrottleContext,normalizeCodeHighlightThrottleMs,} from '~/components/Chat/Messages/Content/Parts/useLazyHighlight';+import { ComposerHostProvider, appComposerHost } from '~/Providers/ComposerHostContext';import { StreamHostProvider, appStreamHost } from '~/Providers/StreamHostContext';import KeyboardShortcutsDialog from '~/components/Nav/KeyboardShortcutsDialog';import { SteerHostProvider, appSteerHost } from '~/Providers/SteerHostContext';@@ -276,7 +277,9 @@ export default function Root() {<SteerHostProvider host={appSteerHost}><ChatHostProvider host={appChatHost}><StreamHostProvider host={appStreamHost}>- <RootLayout />+ <ComposerHostProvider host={appComposerHost}>+ <RootLayout />+ </ComposerHostProvider></StreamHostProvider></ChatHostProvider></SteerHostProvider>diff --git a/client/src/utils/index.ts b/client/src/utils/index.tsindex 7151bb078f..019abef530 100644--- a/client/src/utils/index.ts+++ b/client/src/utils/index.ts@@ -71,7 +71,7 @@ export {collectQuotelessAppliedSteerIds,} from '@librechat/chat';export type { SteerCarriedContext } from '@librechat/chat';-export * from './pane';+export { getChatPane, getFocusedChatPane, isFocusedChatPane } from '@librechat/chat';export * from './activityLabels';export * from './agentModelSelection';export * from './runStepDuration';diff --git a/client/test/composerHost.tsx b/client/test/composerHost.tsxnew file mode 100644index 0000000000..c7dcd8ac26--- /dev/null+++ b/client/test/composerHost.tsx@@ -0,0 +1,10 @@+import React from 'react';+import { ComposerHostProvider } from '@librechat/chat/react';+import { appComposerHost } from '~/Providers/ComposerHostContext';++/** Mounts the app's composer host the way `routes/Root.tsx` does, for specs that render the+ * composer controls outside the app shell. Import it after the spec's module mocks so the host+ * uses them. */+export function ComposerHostTestProvider({ children }: { children?: React.ReactNode }) {+ return <ComposerHostProvider host={appComposerHost}>{children}</ComposerHostProvider>;+}diff --git a/e2e/byom/browser.test.mjs b/e2e/byom/browser.test.mjsindex 6f493a6bf4..c974b30b85 100644--- a/e2e/byom/browser.test.mjs+++ b/e2e/byom/browser.test.mjs@@ -2,7 +2,7 @@ import test from 'node:test';import { runInNewContext } from 'node:vm';import assert from 'node:assert/strict';import { initializeBrowser } from './browser.mjs';-import { resolveComposerKeyDown } from '../../client/src/utils/shortcuts.ts';+import { resolveComposerKeyDown } from '../../packages/chat/src/core/shortcuts.ts';const enter = { key: 'Enter', ctrlKey: false, metaKey: false, altKey: false, shiftKey: false };const context = {diff --git a/e2e/specs/mock/scenarios/composer-queue.spec.ts b/e2e/specs/mock/scenarios/composer-queue.spec.tsindex e52878a519..33c6ef31ec 100644--- a/e2e/specs/mock/scenarios/composer-queue.spec.ts+++ b/e2e/specs/mock/scenarios/composer-queue.spec.ts@@ -89,6 +89,31 @@ test.describe('composer queue rail', () => {await expect(messageTurns(page).nth(5).locator('.agent-turn')).toBeVisible();});+ test('Interrupt now on a queued row preempts the run and sends that message @scenario:interrupt-now-on-a-queued-row-sends-it-into-the-run', async ({+ page,+ }) => {+ test.setTimeout(120000);+ const label = uniqueLabel('queue-interrupt');+ const queueText = `Interrupt with this ${label}`;++ await page.goto(NEW_CHAT_PATH, { timeout: 10000 });+ await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);+ await establishConversation(page, `queue-interrupt-setup-${label}`);++ await startSlowRun(page, label);+ await typeDuringRun(page, queueText);+ await messageInput(page).press('Enter');++ const row = queuedRows(page).filter({ hasText: queueText });+ await expect(row).toBeVisible({ timeout: 10000 });+ const interruptNow = row.getByRole('button', { name: `Interrupt now: ${queueText}` });+ await expect(interruptNow).toBeEnabled({ timeout: 10000 });+ await interruptNow.click();++ await expect(row).toHaveCount(0, { timeout: 30000 });+ await expect(messagesView(page).getByText(queueText)).toBeVisible({ timeout: 30000 });+ });+test('Queued rows reorder with the keyboard @scenario:queued-rows-reorder-with-the-keyboard', async ({page,}) => {diff --git a/eslint-suppressions.json b/eslint-suppressions.jsonindex 7bc6d95c9d..0b377579d8 100644--- a/eslint-suppressions.json+++ b/eslint-suppressions.json@@ -104,11 +104,6 @@"count": 2}},- "client/src/components/Chat/Input/EscalateNowButton.tsx": {- "design/disabled-recipe": {- "count": 1- }- },"client/src/components/Chat/Input/Files/MyFilesModal.tsx": {"shadcn/no-restyle": {"count": 2@@ -150,11 +145,6 @@"count": 3}},- "client/src/components/Chat/Input/QuoteButton.tsx": {- "shadcn/no-inline-styles": {- "count": 1- }- },"client/src/components/Chat/Input/TokenUsage/Breakdown.tsx": {"shadcn/no-restyle": {"count": 10@@ -1378,6 +1368,16 @@"count": 1}},+ "packages/chat/src/components/composer/EscalateNowButton.tsx": {+ "design/disabled-recipe": {+ "count": 1+ }+ },+ "packages/chat/src/components/composer/QuoteButton.tsx": {+ "shadcn/no-inline-styles": {+ "count": 1+ }+ },"packages/chat/src/components/composer/files/DragDropOverlay.tsx": {"shadcn/no-inline-styles": {"count": 3diff --git a/package-lock.json b/package-lock.jsonindex 923d3f2250..1e157140ba 100644--- a/package-lock.json+++ b/package-lock.json@@ -41448,6 +41448,7 @@"sse.js": "^2.8.0"},"devDependencies": {+ "@ariakit/react": "^0.4.29","@babel/preset-env": "^7.29.5","@babel/preset-react": "^7.22.15","@babel/preset-typescript": "^7.21.0",@@ -41482,6 +41483,7 @@"uuid": "^11.1.1"},"peerDependencies": {+ "@ariakit/react": "^0.4.29","@librechat/client": "*","@radix-ui/react-dialog": "^1.1.23","@tanstack/react-query": "^4.28.0",@@ -41497,6 +41499,7 @@"micromark-extension-gfm": "^3.0.0","micromark-extension-math": "^3.1.0","react": "^18.2.0 || ^19.1.0",+ "react-dom": "^18.2.0 || ^19.1.0","uuid": "^11.1.1"}},diff --git a/packages/chat/package.json b/packages/chat/package.jsonindex a6c43ce49f..b3b51af9f7 100644--- a/packages/chat/package.json+++ b/packages/chat/package.json@@ -58,6 +58,7 @@"test:ci": "jest --ci"},"peerDependencies": {+ "@ariakit/react": "^0.4.29","@librechat/client": "*","@radix-ui/react-dialog": "^1.1.23","@tanstack/react-query": "^4.28.0",@@ -73,12 +74,14 @@"micromark-extension-gfm": "^3.0.0","micromark-extension-math": "^3.1.0","react": "^18.2.0 || ^19.1.0",+ "react-dom": "^18.2.0 || ^19.1.0","uuid": "^11.1.1"},"dependencies": {"sse.js": "^2.8.0"},"devDependencies": {+ "@ariakit/react": "^0.4.29","@babel/preset-env": "^7.29.5","@babel/preset-react": "^7.22.15","@babel/preset-typescript": "^7.21.0",diff --git a/packages/chat/src/components.ts b/packages/chat/src/components.tsindex 309e1dc183..89c9b17c46 100644--- a/packages/chat/src/components.ts+++ b/packages/chat/src/components.ts@@ -88,3 +88,15 @@ export {} from './components/parts/rows';export { default as AttachmentImage } from './components/composer/files/Image';export { default as ImagePreview } from './components/composer/files/ImagePreview';+export { default as SendButton } from './components/composer/SendButton';+export { default as QuoteButton } from './components/composer/QuoteButton';+export { default as ComposerHints } from './components/composer/bar/Hints';+export { default as ComposerWaveform } from './components/composer/bar/Waveform';+export { default as EscalateNowButton } from './components/composer/EscalateNowButton';+export { default as DuringRunSendButton } from './components/composer/DuringRunSendButton';+export { composerHintId } from './components/composer/bar/Hints';+export type {+ ComposerHint,+ ComposerHintKind,+ ComposerHintState,+} from './components/composer/bar/hint';diff --git a/client/src/components/Chat/Input/DuringRunSendButton.tsx b/packages/chat/src/components/composer/DuringRunSendButton.tsxsimilarity index 88%rename from client/src/components/Chat/Input/DuringRunSendButton.tsxrename to packages/chat/src/components/composer/DuringRunSendButton.tsxindex 609144f0e3..452a528040 100644--- a/client/src/components/Chat/Input/DuringRunSendButton.tsx+++ b/packages/chat/src/components/composer/DuringRunSendButton.tsx@@ -1,14 +1,12 @@import React, { forwardRef, useMemo, useRef } from 'react';-import { useWatch } from 'react-hook-form';import { Zap, Clock, ZapOff } from 'lucide-react';-import { composerSubmitClasses, SendActions, SendIcon } from '@librechat/client';-import type { SteeringControls } from '@librechat/chat/react';+import { SendIcon, SendActions, useLocalize, composerSubmitClasses } from '@librechat/client';+import type { ForwardRefExoticComponent, RefAttributes } from 'react';import type { SendAction } from '@librechat/client';-import type { Control } from 'react-hook-form';-import type { ComposerKeyContext, KeyChordSource } from '~/utils/shortcuts';-import { isMacPlatform, resolveComposerKeyDown } from '~/utils/shortcuts';-import useComposerBindings from '~/hooks/Input/useComposerBindings';-import { useLocalize } from '~/hooks';+import type { ComposerKeyContext, KeyChordSource } from '../../core/shortcuts';+import type { SteeringControls } from '../../react/steering/useSteering';+import { isMacPlatform, resolveComposerKeyDown } from '../../core/shortcuts';+import { useComposerHost } from '../../react/input';/** The rows, the popover and the chord chips are shared with every other chat* surface that can submit more than one way — see `SendActions`. */@@ -21,7 +19,8 @@ const ACTION_LABELS = {} as const;type DuringRunSendButtonProps = {- control: Control<{ text: string }>;+ /** The composer's current text; the host owns the input state. */+ text: string;steering: SteeringControls;isNewConversation: boolean;getText: () => string;@@ -33,15 +32,17 @@ type DuringRunSendButtonProps = {};/** The active mode owns submission; the menu overrides it for one message. */-const DuringRunSendButton = React.memo(+const DuringRunSendButton: React.MemoExoticComponent<+ ForwardRefExoticComponent<DuringRunSendButtonProps & RefAttributes<HTMLButtonElement>>+> = React.memo(forwardRef((props: DuringRunSendButtonProps, ref: React.ForwardedRef<HTMLButtonElement>) => {const localize = useLocalize();+ const { useComposerBindings } = useComposerHost();const { shortcutsEnabled, submitOverride, yieldedChords } = useComposerBindings();const { steering, enterToSend } = props;const disabledRef = useRef(props.disabled);disabledRef.current = props.disabled;- const data = useWatch({ control: props.control });- const content = data?.text?.trim();+ const content = props.text.trim();const primary = steering.effectiveAction;const modEnter = isMacPlatform ? '⌘⏎' : 'Ctrl ⏎';const altEnter = isMacPlatform ? '⌥⏎' : 'Alt ⏎';diff --git a/client/src/components/Chat/Input/EscalateNowButton.tsx b/packages/chat/src/components/composer/EscalateNowButton.tsxsimilarity index 95%rename from client/src/components/Chat/Input/EscalateNowButton.tsxrename to packages/chat/src/components/composer/EscalateNowButton.tsxindex 2cec54d664..9211867447 100644--- a/client/src/components/Chat/Input/EscalateNowButton.tsx+++ b/packages/chat/src/components/composer/EscalateNowButton.tsx@@ -1,11 +1,9 @@import { useEffect, useId, useSyncExternalStore } from 'react';import { ArrowUp } from 'lucide-react';import * as Ariakit from '@ariakit/react';-import { Button, IconButton } from '@librechat/client';-import { useShortcutAriaKey, useShortcutDisplay } from '~/hooks/useKeyboardShortcuts';-import { getChatPane, getFocusedChatPane } from '~/utils/pane';-import { useLocalize } from '~/hooks';-import { cn } from '~/utils';+import { cn, Button, IconButton, useLocalize } from '@librechat/client';+import { getChatPane, getFocusedChatPane } from '../../core/pane';+import { useComposerHost } from '../../react/input';/** Longest message excerpt spoken as part of the button's accessible name;* past this the row is identified by its opening words rather than read out. */@@ -115,8 +113,9 @@ export default function EscalateNowButton({size = 'xs',shape,onClick,-}: EscalateNowButtonProps) {+}: EscalateNowButtonProps): React.JSX.Element {const localize = useLocalize();+ const { useShortcutDisplay, useShortcutAriaKey } = useComposerHost();const chord = useShortcutDisplay('escalateSteer');const ariaKey = useShortcutAriaKey('escalateSteer');const targetId = useId();diff --git a/client/src/components/Chat/Input/QuoteButton.tsx b/packages/chat/src/components/composer/QuoteButton.tsxsimilarity index 97%rename from client/src/components/Chat/Input/QuoteButton.tsxrename to packages/chat/src/components/composer/QuoteButton.tsxindex 9d7eda9d90..b47ac43872 100644--- a/client/src/components/Chat/Input/QuoteButton.tsx+++ b/packages/chat/src/components/composer/QuoteButton.tsx@@ -2,10 +2,11 @@ import { memo, useRef, useEffect, useCallback, useLayoutEffect } from 'react';import { useSetAtom } from 'jotai';import { createPortal } from 'react-dom';import { TextQuote } from 'lucide-react';-import { pendingQuotesByConvoId } from '@librechat/chat/react';-import { cn, MAX_QUOTE_COUNT } from '~/utils';-import { mainTextareaId } from '~/common';-import { useLocalize } from '~/hooks';+import { cn, useLocalize } from '@librechat/client';+import type { NamedExoticComponent } from 'react';+import { pendingQuotesByConvoId } from '../../react/composer';+import { MAX_QUOTE_COUNT } from '../../core/steer/steer';+import { mainTextareaId } from '../../core/composer';/** Only selections fully inside a rendered chat message get the popup. */const MESSAGE_SELECTOR = '.message-render';@@ -318,7 +319,9 @@ const resolveTop = (anchor: Anchor, height: number, preferBelow: boolean): numbe* is clamped accurately to the viewport, and it tracks the selection while the* page scrolls rather than dismissing on the first scroll event.*/-function QuoteButton({ conversationId }: { conversationId: string }) {+type QuoteButtonProps = { conversationId: string };++function QuoteButton({ conversationId }: QuoteButtonProps): React.ReactPortal | null {const localize = useLocalize();const selectionRef = useRef<SelectionState | null>(null);const buttonRef = useRef<HTMLButtonElement>(null);@@ -644,4 +647,6 @@ function QuoteButton({ conversationId }: { conversationId: string }) {);}-export default memo(QuoteButton);+const MemoQuoteButton: NamedExoticComponent<QuoteButtonProps> = memo(QuoteButton);++export default MemoQuoteButton;diff --git a/client/src/components/Chat/Input/SendButton.tsx b/packages/chat/src/components/composer/SendButton.tsxsimilarity index 69%rename from client/src/components/Chat/Input/SendButton.tsxrename to packages/chat/src/components/composer/SendButton.tsxindex 0a32dbecf8..37515a023d 100644--- a/client/src/components/Chat/Input/SendButton.tsx+++ b/packages/chat/src/components/composer/SendButton.tsx@@ -1,13 +1,12 @@import React, { forwardRef } from 'react';-import { useWatch } from 'react-hook-form';-import { SendIcon, IconButton, TooltipAnchor } from '@librechat/client';-import type { Control } from 'react-hook-form';-import { isSubmittableMessage } from '~/utils';-import { useLocalize } from '~/hooks';+import { SendIcon, IconButton, useLocalize, TooltipAnchor } from '@librechat/client';+import type { ForwardRefExoticComponent, RefAttributes } from 'react';+import { isSubmittableMessage } from '../../core/turns/draft';type SendButtonProps = {disabled: boolean;- control: Control<{ text: string }>;+ /** The composer's current text; the host owns the input state. */+ text: string;/** Number of attached files; attachments allow sending without text */fileCount?: number;};@@ -38,10 +37,11 @@ const SubmitButton = React.memo();}),);-const SendButton = React.memo(+const SendButton: React.MemoExoticComponent<+ ForwardRefExoticComponent<SendButtonProps & RefAttributes<HTMLButtonElement>>+> = React.memo(forwardRef((props: SendButtonProps, ref: React.ForwardedRef<HTMLButtonElement>) => {- const data = useWatch({ control: props.control });- const canSubmit = isSubmittableMessage(data?.text, props.fileCount);+ const canSubmit = isSubmittableMessage(props.text, props.fileCount);return <SubmitButton ref={ref} disabled={props.disabled || !canSubmit} />;}),);diff --git a/packages/chat/src/components/composer/__tests__/DuringRunSendButton.spec.tsx b/packages/chat/src/components/composer/__tests__/DuringRunSendButton.spec.tsxnew file mode 100644index 0000000000..b35b31a5f7--- /dev/null+++ b/packages/chat/src/components/composer/__tests__/DuringRunSendButton.spec.tsx@@ -0,0 +1,135 @@+/**+ * @jest-environment jsdom+ */+import React from 'react';+import { fireEvent, render, screen } from '@testing-library/react';+import type { SteeringControls } from '../../../react/steering/useSteering';+import type { ComposerBindings } from '../../../core/shortcuts';+import type { ComposerHost } from '../../../react/input';+import { ComposerHostProvider } from '../../../react/input';+import { NO_HOST_BINDINGS } from '../../../core/shortcuts';+import DuringRunSendButton from '../DuringRunSendButton';++jest.mock('@librechat/client', () => ({+ ...jest.requireActual('@librechat/client'),+ useLocalize: () => (key: string) => key,+}));++/** Renders the hovercard eagerly; jsdom reports zero pointer geometry to Ariakit's show path. */+jest.mock('@ariakit/react', () => ({+ HovercardProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,+ HovercardAnchor: ({ render }: { render: React.ReactElement }) => render,+ Hovercard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,+}));++const TEXT = 'stop, do not run that command';+const steerFromComposer = jest.fn(() => true);+const queueFromComposer = jest.fn(() => true);+const interruptSteer = jest.fn(() => true);+const onConsumed = jest.fn();++const steering = (overrides: Partial<SteeringControls> = {}): SteeringControls =>+ ({+ effectiveAction: 'steer',+ canSteer: true,+ canControlGeneration: true,+ pausedOnApproval: false,+ steerFromComposer,+ queueFromComposer,+ interruptSteer,+ ...overrides,+ }) as SteeringControls;++const hostWith = (bindings: ComposerBindings): ComposerHost => ({+ useComposerBindings: () => bindings,+ useShortcutDisplay: () => '',+ useShortcutAriaKey: () => undefined,+});++function renderButton({+ text = TEXT,+ disabled = false,+ controls = steering(),+ bindings = NO_HOST_BINDINGS,+ enterToSend = true,+}: {+ text?: string;+ disabled?: boolean;+ controls?: SteeringControls;+ bindings?: ComposerBindings;+ enterToSend?: boolean;+} = {}) {+ return render(+ <ComposerHostProvider host={hostWith(bindings)}>+ <DuringRunSendButton+ text={text}+ steering={controls}+ isNewConversation={false}+ getText={() => text}+ onConsumed={onConsumed}+ enterToSend={enterToSend}+ disabled={disabled}+ />+ </ComposerHostProvider>,+ );+}++const row = (label: string) => screen.getByText(label).closest('button') as HTMLButtonElement;++beforeEach(() => {+ jest.clearAllMocks();+});++describe('DuringRunSendButton', () => {+ it('labels the submit slot with the effective action and disables it without text', () => {+ const { rerender } = renderButton();+ const button = screen.getByTestId('during-run-send-button');+ expect(button).toHaveAttribute('aria-label', 'com_ui_steer_send');+ expect(button).toBeEnabled();++ rerender(+ <DuringRunSendButton+ text=" "+ steering={steering()}+ isNewConversation={false}+ getText={() => ' '}+ onConsumed={onConsumed}+ enterToSend+ />,+ );+ expect(screen.getByTestId('during-run-send-button')).toBeDisabled();+ });++ it('runs the chosen row with the trimmed text and consumes the composer', () => {+ renderButton();++ fireEvent.click(row('com_ui_queue'));+ expect(queueFromComposer).toHaveBeenCalledWith(TEXT);+ fireEvent.click(row('com_ui_steer'));+ expect(steerFromComposer).toHaveBeenCalledWith(TEXT);+ expect(onConsumed).toHaveBeenCalledTimes(2);+ });++ it('holds every row while the host disables sending', () => {+ renderButton({ disabled: true });++ for (const label of ['com_ui_steer', 'com_ui_queue', 'com_ui_interrupt_steer']) {+ expect(row(label)).toHaveAttribute('aria-disabled', 'true');+ fireEvent.click(row(label));+ }+ expect(steerFromComposer).not.toHaveBeenCalled();+ expect(queueFromComposer).not.toHaveBeenCalled();+ expect(interruptSteer).not.toHaveBeenCalled();+ expect(onConsumed).not.toHaveBeenCalled();+ });++ it('moves the default row hint to the modifier chord when Enter does not send', () => {+ const { unmount } = renderButton();+ expect(row('com_ui_steer')).toHaveTextContent('⏎');+ expect(row('com_ui_steer')).not.toHaveTextContent('Ctrl');+ unmount();++ renderButton({ enterToSend: false });+ expect(row('com_ui_steer')).toHaveTextContent('Ctrl ⏎');+ });+});diff --git a/client/src/components/Chat/Input/__tests__/EscalateNowButton.spec.tsx b/packages/chat/src/components/composer/__tests__/EscalateNowButton.spec.tsxsimilarity index 68%rename from client/src/components/Chat/Input/__tests__/EscalateNowButton.spec.tsxrename to packages/chat/src/components/composer/__tests__/EscalateNowButton.spec.tsxindex 6f7b380d62..0c4259630a 100644--- a/client/src/components/Chat/Input/__tests__/EscalateNowButton.spec.tsx+++ b/packages/chat/src/components/composer/__tests__/EscalateNowButton.spec.tsx@@ -1,26 +1,36 @@+/**+ * @jest-environment jsdom+ */import { render, screen, fireEvent, act } from '@testing-library/react';+import type { ComposerHost } from '../../../react/input';+import { ComposerHostProvider } from '../../../react/input';+import { NO_HOST_BINDINGS } from '../../../core/shortcuts';import EscalateNowButton from '../EscalateNowButton';-jest.mock('~/hooks', () => ({+jest.mock('@librechat/client', () => ({+ ...jest.requireActual('@librechat/client'),useLocalize: () => (key: string) => key,}));-jest.mock('~/hooks/useKeyboardShortcuts', () => ({+const host: ComposerHost = {+ useComposerBindings: () => NO_HOST_BINDINGS,useShortcutDisplay: () => 'Ctrl+Shift+.',useShortcutAriaKey: () => 'Control+Shift+.',-}));+};function Pane({ index }: { index: number }) {return (- <section data-chat-pane={index}>- <textarea aria-label={`composer ${index}`} />- <EscalateNowButton- surface="bubble"- disabled={false}- messageText={`waiting ${index}`}- onClick={jest.fn()}- />- </section>+ <ComposerHostProvider host={host}>+ <section data-chat-pane={index}>+ <textarea aria-label={`composer ${index}`} />+ <EscalateNowButton+ surface="bubble"+ disabled={false}+ messageText={`waiting ${index}`}+ onClick={jest.fn()}+ />+ </section>+ </ComposerHostProvider>);}diff --git a/client/src/components/Chat/Input/__tests__/QuoteButton.test.tsx b/packages/chat/src/components/composer/__tests__/QuoteButton.spec.tsxsimilarity index 98%rename from client/src/components/Chat/Input/__tests__/QuoteButton.test.tsxrename to packages/chat/src/components/composer/__tests__/QuoteButton.spec.tsxindex 203c185d1d..a2196dea36 100644--- a/client/src/components/Chat/Input/__tests__/QuoteButton.test.tsx+++ b/packages/chat/src/components/composer/__tests__/QuoteButton.spec.tsx@@ -1,14 +1,18 @@+/**+ * @jest-environment jsdom+ */import React, { Profiler, useState } from 'react';import { act, render, screen, fireEvent } from '@testing-library/react';import { Provider as JotaiProvider, createStore, useAtomValue } from 'jotai';-jest.mock('~/hooks', () => ({+jest.mock('@librechat/client', () => ({+ ...jest.requireActual('@librechat/client'),useLocalize: () => (key: string) => key,}));import QuoteButton from '../QuoteButton';-import { mainTextareaId } from '~/common';-import { pendingQuotesByConvoId } from '@librechat/chat/react';+import { mainTextareaId } from '../../../core/composer';+import { pendingQuotesByConvoId } from '../../../react/composer';const CONVO_ID = 'convo-1';const SELECTED_TEXT = 'Selected assistant text';diff --git a/packages/chat/src/components/composer/__tests__/SendButton.spec.tsx b/packages/chat/src/components/composer/__tests__/SendButton.spec.tsxnew file mode 100644index 0000000000..6db273a279--- /dev/null+++ b/packages/chat/src/components/composer/__tests__/SendButton.spec.tsx@@ -0,0 +1,32 @@+/**+ * @jest-environment jsdom+ */+import React from 'react';+import { render, screen } from '@testing-library/react';+import SendButton from '../SendButton';++jest.mock('@librechat/client', () => ({+ ...jest.requireActual('@librechat/client'),+ useLocalize: () => (key: string) => key,+}));++const send = () => screen.getByTestId('send-button');++describe('SendButton', () => {+ it('sends text, or attachments alone, and refuses whitespace', () => {+ const { rerender } = render(<SendButton text="hello" disabled={false} />);+ expect(send()).toBeEnabled();+ expect(send()).toHaveAttribute('type', 'submit');++ rerender(<SendButton text=" " disabled={false} />);+ expect(send()).toBeDisabled();++ rerender(<SendButton text="" fileCount={1} disabled={false} />);+ expect(send()).toBeEnabled();+ });++ it('stays disabled while the host holds sending', () => {+ render(<SendButton text="hello" disabled />);+ expect(send()).toBeDisabled();+ });+});diff --git a/client/src/components/Chat/Input/Composer/Hints.tsx b/packages/chat/src/components/composer/bar/Hints.tsxsimilarity index 63%rename from client/src/components/Chat/Input/Composer/Hints.tsxrename to packages/chat/src/components/composer/bar/Hints.tsxindex 45fd4cef42..fb0c6d6e76 100644--- a/client/src/components/Chat/Input/Composer/Hints.tsx+++ b/packages/chat/src/components/composer/bar/Hints.tsx@@ -1,10 +1,11 @@import { memo } from 'react';-import type { ComposerHintState } from '~/hooks/Input/useComposerHint';-import useComposerHint from '~/hooks/Input/useComposerHint';+import type { NamedExoticComponent } from 'react';+import type { ComposerHintState } from './hint';+import useComposerHint from './hint';/** Scoped per pane: split view mounts one composer per index, and a shared id* would point every textarea's `aria-describedby` at the first pane's hint. */-export const composerHintId = (index: number) => `composer-hint-${index}`;+export const composerHintId = (index: number): string => `composer-hint-${index}`;/*** The composer's accessible description: whatever the current state affords@@ -14,7 +15,9 @@ export const composerHintId = (index: number) => `composer-hint-${index}`;* every keystroke as the hint flips between idle and typing, so the description* channel carries it instead.*/-function Hints({ index, enterToSend, ...state }: ComposerHintState & { index: number }) {+type HintsProps = ComposerHintState & { index: number };++function Hints({ index, enterToSend, ...state }: HintsProps): React.JSX.Element {const hint = useComposerHint({ ...state, enterToSend });return (@@ -24,4 +27,6 @@ function Hints({ index, enterToSend, ...state }: ComposerHintState & { index: nu);}-export default memo(Hints);+const MemoHints: NamedExoticComponent<HintsProps> = memo(Hints);++export default MemoHints;diff --git a/client/src/components/Chat/Input/Composer/Waveform.tsx b/packages/chat/src/components/composer/bar/Waveform.tsxsimilarity index 88%rename from client/src/components/Chat/Input/Composer/Waveform.tsxrename to packages/chat/src/components/composer/bar/Waveform.tsxindex 7c117c60f3..6b70d1e291 100644--- a/client/src/components/Chat/Input/Composer/Waveform.tsx+++ b/packages/chat/src/components/composer/bar/Waveform.tsx@@ -1,8 +1,9 @@import { memo, useRef, useEffect } from 'react';-import useReducedMotion from '~/hooks/Generic/useReducedMotion';-import useElementSize from '~/hooks/Generic/useElementSize';-import useAudioLevels from '~/hooks/Input/useAudioLevels';-import { cn } from '~/utils';+import { cn } from '@librechat/client';+import type { NamedExoticComponent } from 'react';+import useReducedMotion from '../../../react/motion';+import useAudioLevels from '../../../react/levels';+import useElementSize from '../../../react/size';/** One loudness sample per this many ms; each becomes a bar. */const SAMPLE_MS = 55;@@ -31,7 +32,7 @@ interface WaveformProps {* The bar color is the element's own `text-text-primary`, read from the* canvas every frame, so it follows the theme like any other text.*/-function Waveform({ active, className }: WaveformProps) {+function Waveform({ active, className }: WaveformProps): React.JSX.Element {const read = useAudioLevels(active);const reducedMotion = useReducedMotion();const canvasRef = useRef<HTMLCanvasElement>(null);@@ -99,4 +100,6 @@ function Waveform({ active, className }: WaveformProps) {);}-export default memo(Waveform);+const MemoWaveform: NamedExoticComponent<WaveformProps> = memo(Waveform);++export default MemoWaveform;diff --git a/client/src/components/Chat/Input/Composer/__tests__/Hints.spec.tsx b/packages/chat/src/components/composer/bar/__tests__/Hints.spec.tsxsimilarity index 74%rename from client/src/components/Chat/Input/Composer/__tests__/Hints.spec.tsxrename to packages/chat/src/components/composer/bar/__tests__/Hints.spec.tsxindex 36441bf255..09f4aef769 100644--- a/client/src/components/Chat/Input/Composer/__tests__/Hints.spec.tsx+++ b/packages/chat/src/components/composer/bar/__tests__/Hints.spec.tsx@@ -1,16 +1,26 @@+/**+ * @jest-environment jsdom+ */import React from 'react';import { render, screen } from '@testing-library/react';-import type { ComposerHintState } from '~/hooks/Input/useComposerHint';+import type { ComposerHintState } from '../hint';import Hints, { composerHintId } from '../Hints';-jest.mock('~/hooks/Input/useComposerBindings', () => ({- __esModule: true,- default: () => ({- shortcutsEnabled: true,- submitOverride: undefined,- yieldedChords: new Set<string>(),- }),-}));+/** The hint copy is the app's English, interpolated the way i18next does for these keys. */+jest.mock('@librechat/client', () => {+ const english: Record<string, string> = jest.requireActual(+ '../../../../../../../client/src/locales/en/translation.json',+ );+ return {+ ...jest.requireActual('@librechat/client'),+ useLocalize: () => (key: string, options?: Record<string, string | number>) => {+ const count = options?.count;+ const plural = count == null ? undefined : english[`${key}_${count === 1 ? 'one' : 'other'}`];+ const template = english[key] ?? plural ?? key;+ return template.replace(/\{\{(\w+)\}\}/g, (_, name: string) => String(options?.[name] ?? ''));+ },+ };+});const baseState: ComposerHintState = {hasText: true,diff --git a/client/src/hooks/Input/__tests__/useComposerHint.spec.ts b/packages/chat/src/components/composer/bar/__tests__/hint.spec.tssimilarity index 98%rename from client/src/hooks/Input/__tests__/useComposerHint.spec.tsrename to packages/chat/src/components/composer/bar/__tests__/hint.spec.tsindex 5f2de52bc1..1835521f75 100644--- a/client/src/hooks/Input/__tests__/useComposerHint.spec.ts+++ b/packages/chat/src/components/composer/bar/__tests__/hint.spec.ts@@ -1,5 +1,5 @@-import type { ComposerHintState } from '../useComposerHint';-import { composeHint } from '../useComposerHint';+import type { ComposerHintState } from '../hint';+import { composeHint } from '../hint';/** Echoes the key so assertions read against the key, not English copy. */const localize = ((key: string, options?: Record<string, string | number>) =>diff --git a/client/src/hooks/Input/useComposerHint.ts b/packages/chat/src/components/composer/bar/hint.tssimilarity index 96%rename from client/src/hooks/Input/useComposerHint.tsrename to packages/chat/src/components/composer/bar/hint.tsindex 067313ffc7..f94f916b20 100644--- a/client/src/hooks/Input/useComposerHint.ts+++ b/packages/chat/src/components/composer/bar/hint.ts@@ -1,8 +1,13 @@import { useMemo } from 'react';-import type { LocalizeFunction } from '~/common';-import { isMacPlatform, bindingDisplayString, resolveComposerKeyDown } from '~/utils/shortcuts';-import useComposerBindings from '~/hooks/Input/useComposerBindings';-import useLocalize from '~/hooks/useLocalize';+import { useLocalize } from '@librechat/client';+import {+ isMacPlatform,+ bindingDisplayString,+ resolveComposerKeyDown,+} from '../../../core/shortcuts';+import { useComposerHost } from '../../../react/input';++type LocalizeFunction = ReturnType<typeof useLocalize>;/** The effective `submitMessage` binding, reduced to what the hints need.* `customized` false means the stock modifier chord applies; a customized@@ -194,6 +199,7 @@ export function composeHint(export default function useComposerHint(state: ComposerHintState): ComposerHint {const localize = useLocalize();+ const { useComposerBindings } = useComposerHost();const { shortcutsEnabled, submitOverride, yieldedChords } = useComposerBindings();const sendBinding = useMemo<SendBinding>(() => ({diff --git a/client/src/utils/shortcuts.spec.ts b/packages/chat/src/core/__tests__/shortcuts.spec.tssimilarity index 99%rename from client/src/utils/shortcuts.spec.tsrename to packages/chat/src/core/__tests__/shortcuts.spec.tsindex 3cfc880901..91ee9db56f 100644--- a/client/src/utils/shortcuts.spec.ts+++ b/packages/chat/src/core/__tests__/shortcuts.spec.ts@@ -1,4 +1,7 @@-import type { ShortcutBinding, ComposerKeyContext } from './shortcuts';+/**+ * @jest-environment jsdom+ */+import type { ShortcutBinding, ComposerKeyContext } from '../shortcuts';import {hasModifier,isCancelKey,@@ -16,7 +19,7 @@ import {bindingFromEvent,bindingDisplayKeys,bindingDisplayString,-} from './shortcuts';+} from '../shortcuts';function makeBinding(overrides: Partial<ShortcutBinding> = {}): ShortcutBinding {return { meta: false, ctrl: false, alt: false, shift: false, key: '', ...overrides };diff --git a/packages/chat/src/core/composer.ts b/packages/chat/src/core/composer.tsindex 87f7867cc8..2074827869 100644--- a/packages/chat/src/core/composer.ts+++ b/packages/chat/src/core/composer.ts@@ -51,3 +51,6 @@ export function isComposerFileTaken(id: string): boolean {export function releaseComposerFile(id: string): void {takenFileIds.delete(id);}++/** The DOM id of a pane's main composer textarea; selection and quote features locate it by id. */+export const mainTextareaId = 'prompt-textarea';diff --git a/packages/chat/src/core/index.ts b/packages/chat/src/core/index.tsindex c447311cee..80ae190147 100644--- a/packages/chat/src/core/index.ts+++ b/packages/chat/src/core/index.ts@@ -22,3 +22,5 @@ export * from './ptc';export * from './branch';export * from './subagents';export { strongDirection } from './direction';+export * from './shortcuts';+export * from './pane';diff --git a/client/src/utils/pane.ts b/packages/chat/src/core/pane.tssimilarity index 100%rename from client/src/utils/pane.tsrename to packages/chat/src/core/pane.tsdiff --git a/client/src/utils/shortcuts.ts b/packages/chat/src/core/shortcuts.tssimilarity index 89%rename from client/src/utils/shortcuts.tsrename to packages/chat/src/core/shortcuts.tsindex effebb71c0..7acd31fee1 100644--- a/client/src/utils/shortcuts.ts+++ b/packages/chat/src/core/shortcuts.ts@@ -6,7 +6,7 @@ export type ShortcutBinding = {key: string;};-export const isMacPlatform =+export const isMacPlatform: boolean =typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent);const MODIFIER_KEYS = new Set(['Meta', 'Control', 'Alt', 'Shift']);@@ -402,3 +402,33 @@ export function bindingDisplayString(binding: ShortcutBinding | null, mac: booleconst keys = bindingDisplayKeys(binding, mac);return mac ? keys.join(' ') : keys.join('+');}++export type ComposerBindings = {+ /** Whether user-configurable keyboard shortcuts are globally enabled. */+ shortcutsEnabled: boolean;+ /**+ * Effective `submitMessage` override: `undefined` when unset (default Ctrl/Cmd+Enter applies),+ * `null` when explicitly unbound, otherwise the rebound chord.+ */+ submitOverride: ShortcutBinding | null | undefined;+ /**+ * Chords the user has bound to global shortcuts that still run while typing+ * (`EDITING_ALLOWED_SHORTCUTS`). The window-level handler in+ * `useKeyboardShortcuts` runs AFTER the composer's and yields any keypress+ * a closer handler claimed via `preventDefault`, so the composer must leave+ * these chords entirely untouched: acting on them would claim the event+ * and silently swallow the global action. `submitMessage` is excluded: its+ * rebinding is resolved through `submitOverride` instead. No default binding+ * uses an Enter chord besides submit, so this only ever yields to a+ * deliberate rebinding.+ */+ yieldedChords: ReadonlySet<string>;+};++/** Default bindings for a card rendered without a chat surface host+ * (Share, search), where the user's custom shortcuts are not in scope. */+export const NO_HOST_BINDINGS: ComposerBindings = {+ shortcutsEnabled: true,+ submitOverride: undefined,+ yieldedChords: new Set(),+};diff --git a/packages/chat/src/react.ts b/packages/chat/src/react.tsindex dc2bf64158..c0d75780d8 100644--- a/packages/chat/src/react.ts+++ b/packages/chat/src/react.ts@@ -157,3 +157,9 @@ export { default as useFollowScroll } from './react/parts/useFollowScroll';export { default as useRowHandoff } from './react/parts/handoff';export { useFilesHost, FilesHostProvider } from './react/files';export type { FilesHost } from './react/files';+export { default as useReducedMotion } from './react/motion';+export { default as useElementSize } from './react/size';+export { default as useAudioLevels, frameLevel } from './react/levels';+export { default as useInitPopoverInput } from './react/popover';+export { useComposerHost, ComposerHostProvider } from './react/input';+export type { ComposerHost, ComposerShortcutAction } from './react/input';diff --git a/client/src/hooks/Input/__tests__/useAudioLevels.spec.ts b/packages/chat/src/react/__tests__/levels.spec.tssimilarity index 94%rename from client/src/hooks/Input/__tests__/useAudioLevels.spec.tsrename to packages/chat/src/react/__tests__/levels.spec.tsindex a98bca0dc2..aa94bb78f7 100644--- a/client/src/hooks/Input/__tests__/useAudioLevels.spec.ts+++ b/packages/chat/src/react/__tests__/levels.spec.ts@@ -1,4 +1,4 @@-import { frameLevel } from '../useAudioLevels';+import { frameLevel } from '../levels';/** A time-domain frame of a sine at the given peak amplitude (0-1). */const sine = (amplitude: number, length = 1024) =>diff --git a/client/src/hooks/Generic/__tests__/useElementSize.spec.tsx b/packages/chat/src/react/__tests__/size.spec.tsxsimilarity index 98%rename from client/src/hooks/Generic/__tests__/useElementSize.spec.tsxrename to packages/chat/src/react/__tests__/size.spec.tsxindex 57a08edc02..37a85f98dd 100644--- a/client/src/hooks/Generic/__tests__/useElementSize.spec.tsx+++ b/packages/chat/src/react/__tests__/size.spec.tsx@@ -1,5 +1,8 @@+/**+ * @jest-environment jsdom+ */import { renderHook, act } from '@testing-library/react';-import useElementSize from '../useElementSize';+import useElementSize from '../size';class MockResizeObserver {static instances: MockResizeObserver[] = [];diff --git a/packages/chat/src/react/input.tsx b/packages/chat/src/react/input.tsxnew file mode 100644index 0000000000..372e188349--- /dev/null+++ b/packages/chat/src/react/input.tsx@@ -0,0 +1,42 @@+import { createContext, useContext } from 'react';+import type { ReactNode } from 'react';+import type { ComposerBindings } from '../core/shortcuts';+import { NO_HOST_BINDINGS } from '../core/shortcuts';++/** Composer actions whose chord the user can rebind and the composer advertises. */+export type ComposerShortcutAction = 'escalateSteer';++/** App capabilities the composer controls read. */+export interface ComposerHost {+ /** The user's effective composer-relevant shortcut bindings. */+ useComposerBindings: () => ComposerBindings;+ /** The chord bound to an action, formatted for display; empty when unbound or shortcuts are off. */+ useShortcutDisplay: (action: ComposerShortcutAction) => string;+ /** The chord bound to an action, in `aria-keyshortcuts` form; undefined when unbound. */+ useShortcutAriaKey: (action: ComposerShortcutAction) => string | undefined;+}++/** Without a host the composer keeps the stock chords and advertises no rebound ones. */+const fallbackHost: ComposerHost = {+ useComposerBindings: () => NO_HOST_BINDINGS,+ useShortcutDisplay: () => '',+ useShortcutAriaKey: () => undefined,+};++const ComposerHostContext = createContext<ComposerHost>(fallbackHost);++/** Supplies the host the composer controls read from. */+export function ComposerHostProvider({+ host,+ children,+}: {+ host: ComposerHost;+ children: ReactNode;+}): ReactNode {+ return <ComposerHostContext.Provider value={host}>{children}</ComposerHostContext.Provider>;+}++/** The host of the nearest provider, or one with the stock chords. */+export function useComposerHost(): ComposerHost {+ return useContext(ComposerHostContext);+}diff --git a/client/src/hooks/Input/useAudioLevels.ts b/packages/chat/src/react/levels.tssimilarity index 100%rename from client/src/hooks/Input/useAudioLevels.tsrename to packages/chat/src/react/levels.tsdiff --git a/client/src/hooks/Generic/useReducedMotion.ts b/packages/chat/src/react/motion.tssimilarity index 100%rename from client/src/hooks/Generic/useReducedMotion.tsrename to packages/chat/src/react/motion.tsdiff --git a/client/src/hooks/Input/useInitPopoverInput.ts b/packages/chat/src/react/popover.tssimilarity index 97%rename from client/src/hooks/Input/useInitPopoverInput.tsrename to packages/chat/src/react/popover.tsindex a3a28a2633..97cb3125f9 100644--- a/client/src/hooks/Input/useInitPopoverInput.ts+++ b/packages/chat/src/react/popover.ts@@ -15,7 +15,7 @@ const useInitPopoverInput = ({preserveTextAfterCursor?: boolean;setSearchValue: (value: string) => void;setOpen: (value: boolean) => void;-}) =>+}): ((node: HTMLInputElement | null) => void) =>useCallback((node: HTMLInputElement | null) => {inputRef.current = node;diff --git a/client/src/hooks/Generic/useElementSize.ts b/packages/chat/src/react/size.tssimilarity index 100%rename from client/src/hooks/Generic/useElementSize.tsrename to packages/chat/src/react/size.ts