Skip to content

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

🧳 refactor: Move Ask State, Approval and File Previews, and Diff View Into the Chat Package (#17657)

Marco Beretta36b9cf36a177
diff --git a/client/src/components/Chat/ChatView.tsx b/client/src/components/Chat/ChatView.tsx
index 6eaf14bdff..e1504af643 100644
--- a/client/src/components/Chat/ChatView.tsx
+++ b/client/src/components/Chat/ChatView.tsx
@@ -9,7 +9,9 @@ import {
submissionByIndex,
ChatSessionProvider,
useScrollbarGutterSeed,
+ AskAnswerHostProvider,
ComposerRestoreProvider,
+ pendingApprovalActionFamily,
} from '@librechat/chat/react';
import type { TChatProject, TMessage } from 'librechat-data-provider';
import type { ChatFormValues } from '~/common';
@@ -18,11 +20,9 @@ import Footer, { useLandingFooter, useConfiguredFooter } from './Footer';
import { useChatSettings } from '~/Providers/ChatSettingsContext';
import ApprovalProvider from './Messages/Content/ApprovalContext';
import ConversationStarters from './Input/ConversationStarters';
-import { pendingApprovalActionFamily } from './approval/state';
import ProjectBadge from '~/components/Projects/ProjectBadge';
import { OwnerTextProvider } from './Messages/PrivateText';
import { useAddedResponse, useLocalize } from '~/hooks';
-import { AskAnswerHostProvider } from './ask/state';
import MessagesView from './Messages/MessagesView';
import Presentation from './Presentation';
import ChatForm from './Input/ChatForm';
diff --git a/client/src/components/Chat/Input/AskUserQuestionPopover.tsx b/client/src/components/Chat/Input/AskUserQuestionPopover.tsx
index c33294361a..b11c89c97b 100644
--- a/client/src/components/Chat/Input/AskUserQuestionPopover.tsx
+++ b/client/src/components/Chat/Input/AskUserQuestionPopover.tsx
@@ -1,12 +1,12 @@
import { memo, useCallback, useEffect, useRef } from 'react';
import { useWatch } from 'react-hook-form';
import { isCancelKey } from '@librechat/chat';
+import { AskOptions } from '@librechat/chat/components';
import { Button, TooltipAnchor } from '@librechat/client';
import { useComposerOverlay } from '@librechat/chat/react';
import { ChevronDown, CornerDownLeft, TriangleAlert } from 'lucide-react';
import AskUserQuestions from '~/components/Chat/Messages/Content/AskUserQuestions';
import useAskAnswerMode from '~/hooks/Input/useAskAnswerMode';
-import AskOptions from '~/components/Chat/ask/options';
import { useChatFormContext } from '~/Providers';
import { useLocalize } from '~/hooks';
diff --git a/client/src/components/Chat/Input/Composer/Files.tsx b/client/src/components/Chat/Input/Composer/Files.tsx
index 59ebc74ab3..d2eb3d8a15 100644
--- a/client/src/components/Chat/Input/Composer/Files.tsx
+++ b/client/src/components/Chat/Input/Composer/Files.tsx
@@ -1,5 +1,6 @@
import { memo, useRef, useMemo, useState, useEffect } from 'react';
import { Eye, Search } from 'lucide-react';
+import { getPreviewKind } from '@librechat/chat';
import { apiBaseUrl } from 'librechat-data-provider';
import { FilePreview, getFileType } from '@librechat/chat/components';
import { Button, IconButton, Spinner, useToastContext } from '@librechat/client';
@@ -9,7 +10,6 @@ import FilePreviewDialog, {
formatBytes,
getDisplayType,
} from '~/components/Chat/Messages/Content/FilePreviewDialog';
-import { getPreviewKind } from '~/components/Chat/Messages/Content/preview';
import DialogImage from '~/components/Chat/Messages/Content/DialogImage';
import { useGetFiles, useFilePreviewBlob } from '~/data-provider';
import { toAbsoluteFilePath, triggerDownload } from '~/utils';
diff --git a/client/src/components/Chat/Messages/Content/ApprovalContext.tsx b/client/src/components/Chat/Messages/Content/ApprovalContext.tsx
index d5956cd84d..36d433df70 100644
--- a/client/src/components/Chat/Messages/Content/ApprovalContext.tsx
+++ b/client/src/components/Chat/Messages/Content/ApprovalContext.tsx
@@ -9,16 +9,18 @@ import {
} from 'react';
import { Constants } from 'librechat-data-provider';
import { useAtom, useStore, useAtomValue } from 'jotai';
-import { activeGenerationCreatedAtByConvoId } from '@librechat/chat/react';
+import {
+ askSubmitStatusAtom,
+ pendingApprovalActionFamily,
+ activeGenerationCreatedAtByConvoId,
+} from '@librechat/chat/react';
+import type { AskAnswerStatus } from '@librechat/chat/react';
import type { Agents } from 'librechat-data-provider';
-import type { AskAnswerStatus } from '~/components/Chat/ask/state';
import {
useSubmitToolApprovalMutation,
useSubmitAskAnswerMutation,
type ResumeAgentFields,
} from '~/data-provider';
-import { pendingApprovalActionFamily } from '~/components/Chat/approval/state';
-import { askSubmitStatusAtom } from '~/components/Chat/ask/state';
import { useChatSettings } from '~/Providers/ChatSettingsContext';
import { resolveAskUserQuestionPart } from '~/utils/approval';
import { ChatContext } from '~/Providers/ChatContext';
diff --git a/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx b/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx
index f016b9f094..7e2315f517 100644
--- a/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx
+++ b/client/src/components/Chat/Messages/Content/AskUserQuestion.tsx
@@ -1,4 +1,5 @@
import { useContext, useMemo, useState } from 'react';
+import { AskOptions } from '@librechat/chat/components';
import { Button, TextareaAutosize, TooltipAnchor } from '@librechat/client';
import { ChevronDown, MessageCircleQuestion, TriangleAlert } from 'lucide-react';
import { isCancelKey, isReboundSubmitChord, resolveComposerKeyDown } from '@librechat/chat';
@@ -10,7 +11,6 @@ import { useOptionalChatSurface } from '~/components/Chat/Subagents/surface';
import { NO_HOST_BINDINGS } from '~/hooks/Input/useComposerBindings';
import { cn, forceResize, insertTextAtCursor } from '~/utils';
import useAskAnswerMode from '~/hooks/Input/useAskAnswerMode';
-import AskOptions from '~/components/Chat/ask/options';
import { ChatContext } from '~/Providers/ChatContext';
import AskUserQuestions from './AskUserQuestions';
import { useLocalize } from '~/hooks';
diff --git a/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx b/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx
index f036a44669..f65e5bce13 100644
--- a/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx
+++ b/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx
@@ -1,12 +1,12 @@
import { useCallback, useEffect, useId, useMemo, useRef } from 'react';
import { TriangleAlert } from 'lucide-react';
import { Input, Button } from '@librechat/client';
+import { AskOptions } from '@librechat/chat/components';
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 useAskQuestionsForm from '~/hooks/Input/useAskQuestionsForm';
-import AskOptions from '~/components/Chat/ask/options';
import { splitOtherOption } from '~/utils/approval';
import { AutoHeight } from '~/components/ui';
import { mainTextareaId } from '~/common';
diff --git a/client/src/components/Chat/Messages/Content/Container.tsx b/client/src/components/Chat/Messages/Content/Container.tsx
index db97b17e17..9c32425fb9 100644
--- a/client/src/components/Chat/Messages/Content/Container.tsx
+++ b/client/src/components/Chat/Messages/Content/Container.tsx
@@ -1,6 +1,5 @@
+import { MessageQuotes, SkillPills } from '@librechat/chat/components';
import type { TMessage } from 'librechat-data-provider';
-import MessageQuotes from './MessageQuotes';
-import SkillPills from './SkillPills';
const Container = ({ children, message }: { children: React.ReactNode; message?: TMessage }) => (
<div
diff --git a/client/src/components/Chat/Messages/Content/FilePreviewDialog.tsx b/client/src/components/Chat/Messages/Content/FilePreviewDialog.tsx
index 28d2431136..5c353a9ce0 100644
--- a/client/src/components/Chat/Messages/Content/FilePreviewDialog.tsx
+++ b/client/src/components/Chat/Messages/Content/FilePreviewDialog.tsx
@@ -8,14 +8,14 @@ import {
OGDialogTitle,
OGDialogDescription,
} from '@librechat/client';
-import type { TFile } from 'librechat-data-provider';
import {
getFileExtension,
getPreviewKind,
isExtractedTextPreviewLoading,
shouldUseExtractedTextPreview,
shouldUseSharedFileDownload,
-} from './preview';
+} from '@librechat/chat';
+import type { TFile } from 'librechat-data-provider';
import {
useFilePreview,
useFilePreviewBlob,
diff --git a/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx b/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx
index def2b9e0d3..98e7762df8 100644
--- a/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx
@@ -1,19 +1,21 @@
import { useMemo } from 'react';
import { FilePenLine, FilePlus2 } from 'lucide-react';
-import { TOOL_ROW_CLASSES, BareStatus } from '@librechat/chat/components';
import { parseJsonField, parseJsonFieldOccurrences } from '@librechat/chat';
import {
toolPanelSpacingClassName,
useFollowScroll,
useToolCallIntent,
} from '@librechat/chat/react';
-import type { TAttachment, PartMetadata } from 'librechat-data-provider';
-import DiffView, {
+import {
+ DiffView,
+ BareStatus,
+ diffPreviewText,
+ TOOL_ROW_CLASSES,
parseUnifiedDiff,
buildEditPreviewDiff,
- diffPreviewText,
- type TextEditPreview,
-} from './DiffView';
+} from '@librechat/chat/components';
+import type { TAttachment, PartMetadata } from 'librechat-data-provider';
+import type { TextEditPreview } from '@librechat/chat/components';
import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
import useToolCallState from './useToolCallState';
import useLazyHighlight from './useLazyHighlight';
diff --git a/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx b/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx
index ccb24ff3cd..5e3480028f 100644
--- a/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx
@@ -2,13 +2,13 @@ import { memo, useMemo, useState, useEffect, useCallback } from 'react';
import {
SteerReceipt,
FileContainer,
+ MessageQuotes,
CollapsibleText,
MessageTimestamp,
} from '@librechat/chat/components';
import type { SteerReceiptState } from '@librechat/chat/components';
import type { TFile, TMessage } from 'librechat-data-provider';
import FilePreviewDialog from '~/components/Chat/Messages/Content/FilePreviewDialog';
-import MessageQuotes from '~/components/Chat/Messages/Content/MessageQuotes';
import { cn, hydrateFileDeliveryMetadata, usesImagePreview } from '~/utils';
import MarkdownLite from '~/components/Chat/Messages/Content/MarkdownLite';
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
diff --git a/client/src/components/Chat/Messages/Content/ToolApproval.tsx b/client/src/components/Chat/Messages/Content/ToolApproval.tsx
index d9113555ff..b3c5e832ce 100644
--- a/client/src/components/Chat/Messages/Content/ToolApproval.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolApproval.tsx
@@ -1,5 +1,6 @@
import { useId, useContext, useEffect, useMemo } from 'react';
import { Button, TextareaAutosize } from '@librechat/client';
+import { useComposerPresentsApproval } from '@librechat/chat/react';
import {
X,
Check,
@@ -15,13 +16,12 @@ import {
bindingFromEvent,
bindingsMatch,
bindingHash,
+ boundApprovalLabel,
} 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';
import { useApprovalContext, useResumeSubmit } from './ApprovalContext';
import { cn, forceResize, insertTextAtCursor, logger } from '~/utils';
import { NO_HOST_BINDINGS } from '~/hooks/Input/useComposerBindings';
diff --git a/client/src/components/Chat/Messages/Content/__tests__/FilePreviewDialog.test.ts b/client/src/components/Chat/Messages/Content/__tests__/FilePreviewDialog.test.ts
index c8c0c9edb2..d2e3c9b8db 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/FilePreviewDialog.test.ts
+++ b/client/src/components/Chat/Messages/Content/__tests__/FilePreviewDialog.test.ts
@@ -4,7 +4,7 @@ import {
isExtractedTextPreviewLoading,
shouldUseExtractedTextPreview,
shouldUseSharedFileDownload,
-} from '../preview';
+} from '@librechat/chat';
import { getDownloadFilename } from '~/utils/downloadFile';
describe('FilePreviewDialog text-source behavior', () => {
diff --git a/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx
index 40f5aa93cb..d1af10018c 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/ToolApproval.test.tsx
@@ -1,14 +1,14 @@
import React from 'react';
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 {
approvalPanelOpenFamily,
pendingApprovalActionFamily,
-} from '~/components/Chat/approval/state';
+ activeGenerationCreatedAtByConvoId,
+} from '@librechat/chat/react';
+import type { ShortcutBinding } from '@librechat/chat';
+import type { Agents } from 'librechat-data-provider';
import { ChatSurfaceProvider } from '~/components/Chat/Subagents/surface';
import ApprovalProvider, { useApprovalContext } from '../ApprovalContext';
import { ChatContext } from '~/Providers/ChatContext';
diff --git a/client/src/components/Chat/__tests__/ChatView.spec.tsx b/client/src/components/Chat/__tests__/ChatView.spec.tsx
index 8b2d2f9fc2..a2bac59ab6 100644
--- a/client/src/components/Chat/__tests__/ChatView.spec.tsx
+++ b/client/src/components/Chat/__tests__/ChatView.spec.tsx
@@ -72,7 +72,7 @@ jest.mock('../Input/ChatForm', () => ({
__esModule: true,
default: (props: Record<string, unknown>) => {
mockChatFormProps(props);
- mockAskHostSaveDrafts(jest.requireActual('../ask/state').useAskAnswerHost());
+ mockAskHostSaveDrafts(jest.requireActual('@librechat/chat/react').useAskAnswerHost());
return <div />;
},
}));
diff --git a/client/src/components/Chat/approval/Review.tsx b/client/src/components/Chat/approval/Review.tsx
index 0f74f5289e..9ea0a7f0a9 100644
--- a/client/src/components/Chat/approval/Review.tsx
+++ b/client/src/components/Chat/approval/Review.tsx
@@ -2,8 +2,13 @@ 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 { buildApprovalPreview, buildApprovalPreviews } from '@librechat/chat';
import { ChevronDown, ChevronUp, ShieldQuestion, TriangleAlert } from 'lucide-react';
+import {
+ useComposerOverlay,
+ approvalPanelOpenFamily,
+ pendingApprovalActionFamily,
+} from '@librechat/chat/react';
import type { Agents } from 'librechat-data-provider';
import type { KeyboardEvent, RefObject } from 'react';
import type { TranslationKeys } from '~/hooks';
@@ -11,11 +16,6 @@ import {
useApprovalContext,
useResumeSubmit,
} from '~/components/Chat/Messages/Content/ApprovalContext';
-import {
- approvalPanelOpenFamily,
- pendingApprovalActionFamily,
-} from '~/components/Chat/approval/state';
-import { buildApprovalPreview, buildApprovalPreviews } from '~/components/Chat/approval/preview';
import ToolApproval from '~/components/Chat/Messages/Content/ToolApproval';
import { useLocalize } from '~/hooks';
diff --git a/client/src/components/Chat/approval/__tests__/Review.test.tsx b/client/src/components/Chat/approval/__tests__/Review.test.tsx
index 57007ebfbf..fb844f2b8a 100644
--- a/client/src/components/Chat/approval/__tests__/Review.test.tsx
+++ b/client/src/components/Chat/approval/__tests__/Review.test.tsx
@@ -2,11 +2,10 @@ import React from 'react';
import { RecoilRoot } from 'recoil';
import { Provider as JotaiProvider, createStore } from 'jotai';
import { fireEvent, render, screen } from '@testing-library/react';
-import { composerOverlayCountFamily } from '@librechat/chat/react';
+import { composerOverlayCountFamily, pendingApprovalActionFamily } from '@librechat/chat/react';
import type { Agents } from 'librechat-data-provider';
import { PendingToolApprovalButton, PendingToolApprovalPanel } from '../Review';
import ApprovalProvider from '../../Messages/Content/ApprovalContext';
-import { pendingApprovalActionFamily } from '../state';
jest.mock('@librechat/client', () => ({
Button: jest
diff --git a/client/src/components/Chat/approval/state.ts b/client/src/components/Chat/approval/state.ts
deleted file mode 100644
index 2205e31ed8..0000000000
--- a/client/src/components/Chat/approval/state.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export {
- approvalPanelOpenFamily,
- pendingApprovalActionFamily,
- useComposerPresentsApproval,
-} from '@librechat/chat/react';
diff --git a/client/src/hooks/Input/useAskAnswerMode.spec.ts b/client/src/hooks/Input/useAskAnswerMode.spec.ts
index 56b8b7f565..583f5fbb3b 100644
--- a/client/src/hooks/Input/useAskAnswerMode.spec.ts
+++ b/client/src/hooks/Input/useAskAnswerMode.spec.ts
@@ -8,7 +8,7 @@ import {
askAnswerCheckedAtom,
askAnswerTextAtom,
releasedComposerTextAtom,
-} from '~/components/Chat/ask/state';
+} from '@librechat/chat/react';
const mockSubmitAskAnswer = jest.fn();
const mockResetComposer = jest.fn();
diff --git a/client/src/hooks/Input/useAskAnswerMode.ts b/client/src/hooks/Input/useAskAnswerMode.ts
index a01cb9c33f..66f2711186 100644
--- a/client/src/hooks/Input/useAskAnswerMode.ts
+++ b/client/src/hooks/Input/useAskAnswerMode.ts
@@ -7,7 +7,7 @@ import {
askAnswerTextAtom,
releasedComposerTextAtom,
useAskAnswerHost,
-} from '~/components/Chat/ask/state';
+} from '@librechat/chat/react';
import {
useAskSubmitStatus,
useResumeSubmit,
diff --git a/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts b/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
index c2892519cf..c4065aa88e 100644
--- a/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
+++ b/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
@@ -23,7 +23,6 @@ import {
removeUsageAtoms,
} from '~/components/Chat/Input/TokenUsage/store';
import { registerComposerDraft, captureComposerDraft, bindComposerLaunch } from '~/utils/drafts';
-import { pendingApprovalActionFamily } from '~/components/Chat/approval/state';
type SSEEventListener = (e: Partial<MessageEvent> & { responseCode?: number }) => void;
@@ -327,6 +326,7 @@ import {
stopRequestedByConvoId,
detachedRunByConvoId,
resetQueueFamilies,
+ pendingApprovalActionFamily,
} from '@librechat/chat/react';
/** Every hook here renders under the app's stream host, as `Root` mounts it. */
diff --git a/client/src/hooks/SSE/__tests__/useResumeOnLoad.spec.tsx b/client/src/hooks/SSE/__tests__/useResumeOnLoad.spec.tsx
index 5caabf3f71..02a9dc8c5a 100644
--- a/client/src/hooks/SSE/__tests__/useResumeOnLoad.spec.tsx
+++ b/client/src/hooks/SSE/__tests__/useResumeOnLoad.spec.tsx
@@ -1,7 +1,7 @@
import { RecoilRoot } from 'recoil';
-import { useResumeOnLoad } from '@librechat/chat/react';
import { renderHook, act, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+import { useResumeOnLoad, pendingApprovalActionFamily } from '@librechat/chat/react';
import { Constants, ContentTypes, QueryKeys, RetentionMode } from 'librechat-data-provider';
import { isSubmittingFamily, resetSubmitting, submissionByIndex } from '@librechat/chat/react';
import {
@@ -31,7 +31,6 @@ import type { MutableSnapshot } from 'recoil';
import type { ReactNode } from 'react';
import { ChatSettingsContext, defaultChatSettings } from '~/Providers/ChatSettingsContext';
import { siblingIdxFamily, siblingKey } from '~/components/Chat/Messages/Thread/state';
-import { pendingApprovalActionFamily } from '~/components/Chat/approval/state';
import { agentQueuedTurnsQueryKey } from '~/data-provider/SSE/queuedTurns';
import { usePaneConversation } from '~/routes/ChatSettings';
import { StreamHostTestProvider } from 'test/streamHost';
diff --git a/client/src/hooks/SSE/pane.ts b/client/src/hooks/SSE/pane.ts
index 70b52a474e..63b9a6f1ac 100644
--- a/client/src/hooks/SSE/pane.ts
+++ b/client/src/hooks/SSE/pane.ts
@@ -12,6 +12,7 @@ import {
detachedRunByConvoId,
drainAfterAbortByIndex,
stopRequestedByConvoId,
+ pendingApprovalActionFamily,
} from '@librechat/chat/react';
import type {
ResumableRun,
@@ -21,7 +22,6 @@ import type {
RunEnd,
} from '@librechat/chat';
import type { EventHandlerParams } from './useEventHandlers';
-import { pendingApprovalActionFamily } from '~/components/Chat/approval/state';
import { clearComposerDrafts, resolveRunEndTarget } from '~/utils';
import { activeRunFamily } from './atoms';
diff --git a/client/src/hooks/SSE/useSSE.ts b/client/src/hooks/SSE/useSSE.ts
index 192bb11bc1..0d551076df 100644
--- a/client/src/hooks/SSE/useSSE.ts
+++ b/client/src/hooks/SSE/useSSE.ts
@@ -4,7 +4,12 @@ import { useStore, useSetAtom } from 'jotai';
import { useQueryClient } from '@tanstack/react-query';
import { startedAsNewConversation, buildCreatedInitialResponse } from '@librechat/chat';
import { StepEvents, createPayload, removeNullishValues } from 'librechat-data-provider';
-import { useUsageHandler, abortScrollFamily, showStopButtonByIndex } from '@librechat/chat/react';
+import {
+ useUsageHandler,
+ abortScrollFamily,
+ showStopButtonByIndex,
+ pendingApprovalActionFamily,
+} from '@librechat/chat/react';
import type {
Agents,
TMessage,
@@ -19,7 +24,6 @@ import type {
import type { EventHandlerParams } from './useEventHandlers';
import type { TResData, TFinalResData } from '~/common';
import { clearComposerDrafts, applyPendingAction, findPendingActionMessageIndex } from '~/utils';
-import { pendingApprovalActionFamily } from '~/components/Chat/approval/state';
import { useChatTransport } from '~/Providers/ChatTransportContext';
import { useChatSettings } from '~/Providers/ChatSettingsContext';
import { reopenTermsOnRefusal } from '~/utils/terms';
diff --git a/packages/api/src/agents/hitl/edits.spec.ts b/packages/api/src/agents/hitl/edits.spec.ts
index 592b9f28e7..4f3014d74a 100644
--- a/packages/api/src/agents/hitl/edits.spec.ts
+++ b/packages/api/src/agents/hitl/edits.spec.ts
@@ -13,7 +13,7 @@ import {
import type { ToolExecuteBatchRequest } from '@librechat/agents';
import type { Agents } from 'librechat-data-provider';
import type { ToolApprovalHook } from './hooks';
-import { buildApprovalPreview } from '../../../../../client/src/components/Chat/approval/preview';
+import { buildApprovalPreview } from '../../../../chat/src/core/parts/approval';
import { collectNativeEditFileAgentIds } from './byom';
import { buildHITLRunWiring } from './runtime';
import { normalizeEditArgs } from '../edits';
diff --git a/packages/chat/src/components.ts b/packages/chat/src/components.ts
index 7939ae0b98..3f5077d42d 100644
--- a/packages/chat/src/components.ts
+++ b/packages/chat/src/components.ts
@@ -96,6 +96,18 @@ export {
FOLD_GLYPH_SELECTOR,
ARTIFACT_ROW_NAV_SPACING,
} from './components/parts/rows';
+export { default as AskOptions } from './components/parts/AskOptions';
+export type { AskOption } from './components/parts/AskOptions';
+export { default as SkillPills } from './components/parts/SkillPills';
+export type { SkillPillsSource } from './components/parts/SkillPills';
+export { default as MessageQuotes } from './components/parts/MessageQuotes';
+export {
+ default as DiffView,
+ diffPreviewText,
+ parseUnifiedDiff,
+ buildEditPreviewDiff,
+} from './components/parts/DiffView';
+export type { DiffLine, ParsedDiff, TextEditPreview } from './components/parts/DiffView';
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';
diff --git a/client/src/components/Chat/ask/options.tsx b/packages/chat/src/components/parts/AskOptions.tsx
similarity index 96%
rename from client/src/components/Chat/ask/options.tsx
rename to packages/chat/src/components/parts/AskOptions.tsx
index 1e7d0180c6..37f673f7da 100644
--- a/client/src/components/Chat/ask/options.tsx
+++ b/packages/chat/src/components/parts/AskOptions.tsx
@@ -1,6 +1,6 @@
import { Check } from 'lucide-react';
-import { Button } from '@librechat/client';
-import { cn } from '~/utils';
+import { cn, Button } from '@librechat/client';
+import type { ReactNode } from 'react';
export interface AskOption {
label: string;
@@ -42,7 +42,7 @@ export default function AskOptions({
optionRefs?: React.MutableRefObject<(HTMLButtonElement | null)[]>;
listRef?: React.RefObject<HTMLDivElement>;
className?: string;
-}) {
+}): ReactNode {
return (
<div ref={listRef} className={className}>
{options.map((option, index) => {
diff --git a/client/src/components/Chat/Messages/Content/Parts/DiffView.tsx b/packages/chat/src/components/parts/DiffView.tsx
similarity index 98%
rename from client/src/components/Chat/Messages/Content/Parts/DiffView.tsx
rename to packages/chat/src/components/parts/DiffView.tsx
index e7b6afc162..8e1c3ca821 100644
--- a/client/src/components/Chat/Messages/Content/Parts/DiffView.tsx
+++ b/packages/chat/src/components/parts/DiffView.tsx
@@ -1,5 +1,6 @@
import { memo } from 'react';
-import { cn } from '~/utils';
+import { cn } from '@librechat/client';
+import type { ReactNode } from 'react';
const HUNK_HEADER = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
@@ -209,7 +210,7 @@ const DiffRow = memo(function DiffRow({ type, text, num, hasLineNumbers }: DiffR
/** Index keys are safe: the parser walks the text top to bottom and the stream
* only appends, so a row's index, type and line numbers are stable once
* emitted. Only the trailing, still-growing line changes, and its props do too. */
-export default function DiffView({ parsed }: { parsed: ParsedDiff }) {
+export default function DiffView({ parsed }: { parsed: ParsedDiff }): ReactNode {
const { lines, hasLineNumbers } = parsed;
const firstContentIndex = lines.findIndex((line) => line.type !== 'hunk');
diff --git a/client/src/components/Chat/Messages/Content/MessageQuotes.tsx b/packages/chat/src/components/parts/MessageQuotes.tsx
similarity index 81%
rename from client/src/components/Chat/Messages/Content/MessageQuotes.tsx
rename to packages/chat/src/components/parts/MessageQuotes.tsx
index c5f209994a..eee19be74f 100644
--- a/client/src/components/Chat/Messages/Content/MessageQuotes.tsx
+++ b/packages/chat/src/components/parts/MessageQuotes.tsx
@@ -1,6 +1,7 @@
import { memo } from 'react';
import { TextQuote } from 'lucide-react';
-import { useLocalize } from '~/hooks';
+import { useLocalize } from '@librechat/client';
+import type { ReactNode, NamedExoticComponent } from 'react';
/**
* Renders the verbatim excerpts a user quoted on a submitted message as
@@ -12,7 +13,7 @@ import { useLocalize } from '~/hooks';
* `quotes={message.quotes}` and the references survive reload and history
* renders, mirroring how `SkillPills` reads `message.manualSkills`.
*/
-function MessageQuotes({ quotes }: { quotes?: string[] }) {
+function MessageQuotes({ quotes }: { quotes?: string[] }): ReactNode {
const localize = useLocalize();
if (!quotes || quotes.length === 0) {
@@ -43,4 +44,6 @@ function MessageQuotes({ quotes }: { quotes?: string[] }) {
);
}
-export default memo(MessageQuotes);
+const MemoizedMessageQuotes: NamedExoticComponent<{ quotes?: string[] }> = memo(MessageQuotes);
+
+export default MemoizedMessageQuotes;
diff --git a/client/src/components/Chat/Messages/Content/SkillPills.tsx b/packages/chat/src/components/parts/SkillPills.tsx
similarity index 86%
rename from client/src/components/Chat/Messages/Content/SkillPills.tsx
rename to packages/chat/src/components/parts/SkillPills.tsx
index 1af9c52150..c7c3ae3381 100644
--- a/client/src/components/Chat/Messages/Content/SkillPills.tsx
+++ b/packages/chat/src/components/parts/SkillPills.tsx
@@ -1,6 +1,7 @@
import { memo } from 'react';
import { Pin, ScrollText } from 'lucide-react';
-import { useLocalize } from '~/hooks';
+import { useLocalize } from '@librechat/client';
+import type { ReactNode, NamedExoticComponent } from 'react';
/**
* Origin tag driving the pill variant:
@@ -25,13 +26,12 @@ export type SkillPillsSource = 'manual' | 'always-apply';
* and pills survive page reloads / history renders. The `source` prop picks
* the icon variant so both flavors render from the same component.
*/
-function SkillPills({
- skills,
- source = 'manual',
-}: {
+interface SkillPillsProps {
skills?: string[];
source?: SkillPillsSource;
-}) {
+}
+
+function SkillPills({ skills, source = 'manual' }: SkillPillsProps): ReactNode {
const localize = useLocalize();
if (!skills || skills.length === 0) {
@@ -64,4 +64,6 @@ function SkillPills({
);
}
-export default memo(SkillPills);
+const MemoizedSkillPills: NamedExoticComponent<SkillPillsProps> = memo(SkillPills);
+
+export default MemoizedSkillPills;
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/DiffView.test.ts b/packages/chat/src/components/parts/__tests__/DiffView.spec.ts
similarity index 100%
rename from client/src/components/Chat/Messages/Content/Parts/__tests__/DiffView.test.ts
rename to packages/chat/src/components/parts/__tests__/DiffView.spec.ts
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/DiffViewRows.test.tsx b/packages/chat/src/components/parts/__tests__/DiffViewRows.spec.tsx
similarity index 91%
rename from client/src/components/Chat/Messages/Content/Parts/__tests__/DiffViewRows.test.tsx
rename to packages/chat/src/components/parts/__tests__/DiffViewRows.spec.tsx
index 27b185965e..2a30b946f4 100644
--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/DiffViewRows.test.tsx
+++ b/packages/chat/src/components/parts/__tests__/DiffViewRows.spec.tsx
@@ -1,9 +1,12 @@
+/**
+ * @jest-environment jsdom
+ */
+import { cn } from '@librechat/client';
import { render } from '@testing-library/react';
import DiffView, { parseUnifiedDiff } from '../DiffView';
-import { cn } from '~/utils';
-jest.mock('~/utils', () => {
- const actual = jest.requireActual('~/utils');
+jest.mock('@librechat/client', () => {
+ const actual = jest.requireActual('@librechat/client');
return { ...actual, cn: jest.fn(actual.cn) };
});
diff --git a/client/src/components/Chat/Messages/Content/__tests__/MessageQuotes.test.tsx b/packages/chat/src/components/parts/__tests__/MessageQuotes.spec.tsx
similarity index 91%
rename from client/src/components/Chat/Messages/Content/__tests__/MessageQuotes.test.tsx
rename to packages/chat/src/components/parts/__tests__/MessageQuotes.spec.tsx
index 7cb2e753cb..9aaae84dbc 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/MessageQuotes.test.tsx
+++ b/packages/chat/src/components/parts/__tests__/MessageQuotes.spec.tsx
@@ -1,7 +1,11 @@
+/**
+ * @jest-environment jsdom
+ */
import React from 'react';
import { render, screen } from '@testing-library/react';
-jest.mock('~/hooks', () => ({
+jest.mock('@librechat/client', () => ({
+ ...jest.requireActual('@librechat/client'),
useLocalize: () => (key: string) => key,
}));
diff --git a/client/src/components/Chat/Messages/Content/__tests__/SkillPills.test.tsx b/packages/chat/src/components/parts/__tests__/SkillPills.spec.tsx
similarity index 95%
rename from client/src/components/Chat/Messages/Content/__tests__/SkillPills.test.tsx
rename to packages/chat/src/components/parts/__tests__/SkillPills.spec.tsx
index 134cc0224b..e3e71a0787 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/SkillPills.test.tsx
+++ b/packages/chat/src/components/parts/__tests__/SkillPills.spec.tsx
@@ -1,7 +1,11 @@
+/**
+ * @jest-environment jsdom
+ */
import React from 'react';
import { render, screen } from '@testing-library/react';
-jest.mock('~/hooks', () => ({
+jest.mock('@librechat/client', () => ({
+ ...jest.requireActual('@librechat/client'),
useLocalize: () => (key: string, params?: Record<string, unknown>) =>
`${key}:${params?.[0] ?? ''}`,
}));
diff --git a/client/src/components/Chat/approval/__tests__/preview.test.ts b/packages/chat/src/core/parts/__tests__/approval.spec.ts
similarity index 98%
rename from client/src/components/Chat/approval/__tests__/preview.test.ts
rename to packages/chat/src/core/parts/__tests__/approval.spec.ts
index a20c8b1c26..7e15c87f60 100644
--- a/client/src/components/Chat/approval/__tests__/preview.test.ts
+++ b/packages/chat/src/core/parts/__tests__/approval.spec.ts
@@ -1,4 +1,4 @@
-import { buildApprovalPreview, buildApprovalPreviews } from '../preview';
+import { buildApprovalPreview, buildApprovalPreviews } from '../approval';
describe('buildApprovalPreview', () => {
test('shows named action arguments instead of an empty command', () => {
@@ -106,7 +106,7 @@ describe('buildApprovalPreview', () => {
0,
),
).toBeLessThanOrEqual(64 * 1024);
- expect(previews.at(-1)).toMatchObject({ body: '', truncated: true });
+ expect(previews[previews.length - 1]).toMatchObject({ body: '', truncated: true });
});
test('applies the visible cap after expanding hidden control characters', () => {
diff --git a/client/src/components/Chat/approval/preview.ts b/packages/chat/src/core/parts/approval.ts
similarity index 99%
rename from client/src/components/Chat/approval/preview.ts
rename to packages/chat/src/core/parts/approval.ts
index f5008a23ee..61f6fe192e 100644
--- a/client/src/components/Chat/approval/preview.ts
+++ b/packages/chat/src/core/parts/approval.ts
@@ -109,7 +109,7 @@ function stringifyArguments(args: unknown): string {
/** Build a bounded, inert preview from the exact effective arguments in the interrupt. */
export function buildApprovalPreview(
request: Agents.ToolApprovalRequest,
- maxChars = MAX_PREVIEW_CHARS,
+ maxChars: number = MAX_PREVIEW_CHARS,
): ApprovalPreview {
const parsed = parseArguments(request.arguments);
let kind: ApprovalPreview['kind'] = 'generic';
diff --git a/packages/chat/src/core/parts/index.ts b/packages/chat/src/core/parts/index.ts
index 17d3c881c5..e6e83d5657 100644
--- a/packages/chat/src/core/parts/index.ts
+++ b/packages/chat/src/core/parts/index.ts
@@ -8,3 +8,5 @@ export * from './params';
export * from './rerunParent';
export * from './splitMarkdown';
export * from './editableParts';
+export * from './approval';
+export * from './preview';
diff --git a/client/src/components/Chat/Messages/Content/preview.ts b/packages/chat/src/core/parts/preview.ts
similarity index 100%
rename from client/src/components/Chat/Messages/Content/preview.ts
rename to packages/chat/src/core/parts/preview.ts
diff --git a/packages/chat/src/react.ts b/packages/chat/src/react.ts
index 65086119ab..2d0d51e367 100644
--- a/packages/chat/src/react.ts
+++ b/packages/chat/src/react.ts
@@ -162,6 +162,17 @@ export type {
export { boundIntentLabel, getToolCallIntent, useToolCallIntent } from './react/parts/intent';
export { default as useFollowScroll } from './react/parts/useFollowScroll';
export { default as useRowHandoff } from './react/parts/handoff';
+export {
+ askAnswerTextAtom,
+ useAskAnswerHost,
+ askSubmitStatusAtom,
+ askAnswerCheckedAtom,
+ AskAnswerHostProvider,
+ askAnswerSelectionAtom,
+ collapsedAskActionsAtom,
+ releasedComposerTextAtom,
+} from './react/parts/ask';
+export type { AskAnswerStatus, ReleasedComposerStash } from './react/parts/ask';
export { useFilesHost, FilesHostProvider } from './react/files';
export type { FilesHost } from './react/files';
export { default as useReducedMotion } from './react/motion';
diff --git a/client/src/components/Chat/ask/state.tsx b/packages/chat/src/react/parts/ask.tsx
similarity index 67%
rename from client/src/components/Chat/ask/state.tsx
rename to packages/chat/src/react/parts/ask.tsx
index 65a69eaa98..85d6439d63 100644
--- a/client/src/components/Chat/ask/state.tsx
+++ b/packages/chat/src/react/parts/ask.tsx
@@ -1,21 +1,24 @@
import { createContext, useContext } from 'react';
import { atom } from 'jotai';
+import type { PrimitiveAtom } from 'jotai';
import type { ReactNode } from 'react';
/**
* Action ids the user moved into the chat: the popover is hidden and the
* composer is released, so the chat card is the question's only surface.
*/
-export const collapsedAskActionsAtom = atom<string[]>([]);
+export const collapsedAskActionsAtom: PrimitiveAtom<string[]> = atom<string[]>([]);
/** Currently highlighted option row (keyboard cursor), or nothing. */
-export const askAnswerSelectionAtom = atom<number | null>(null);
+export const askAnswerSelectionAtom: PrimitiveAtom<number | null> = atom<number | null>(null);
/** Checked option rows for a multi-select question. */
-export const askAnswerCheckedAtom = atom<number[]>([]);
+export const askAnswerCheckedAtom: PrimitiveAtom<number[]> = atom<number[]>([]);
/** Free-form answers keyed by pending action id. */
-export const askAnswerTextAtom = atom<Record<string, string>>({});
+export const askAnswerTextAtom: PrimitiveAtom<Record<string, string>> = atom<
+ Record<string, string>
+>({});
/**
* Ordinary composer text stashed while the card owns the composer, keyed by
@@ -25,11 +28,15 @@ export const askAnswerTextAtom = atom<Record<string, string>>({});
* remaining chance to give the message back.
*/
export type ReleasedComposerStash = { conversationId: string | null; text: string };
-export const releasedComposerTextAtom = atom<Record<string, ReleasedComposerStash>>({});
+export const releasedComposerTextAtom: PrimitiveAtom<Record<string, ReleasedComposerStash>> = atom<
+ Record<string, ReleasedComposerStash>
+>({});
/** Submission lifecycle shared by composer and message-content surfaces. */
export type AskAnswerStatus = 'idle' | 'submitting' | 'submitted' | 'expired' | 'error';
-export const askSubmitStatusAtom = atom<Record<string, AskAnswerStatus>>({});
+export const askSubmitStatusAtom: PrimitiveAtom<Record<string, AskAnswerStatus>> = atom<
+ Record<string, AskAnswerStatus>
+>({});
const AskAnswerHostContext = createContext(false);
@@ -39,7 +46,7 @@ export function AskAnswerHostProvider({
}: {
saveDrafts: boolean;
children?: ReactNode;
-}) {
+}): ReactNode {
return (
<AskAnswerHostContext.Provider value={saveDrafts}>{children}</AskAnswerHostContext.Provider>
);