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

⚙️ feat: Move Chat Actions Into a Header Options Menu (#16775)

Marco Berettab56de235f912
diff --git a/client/src/common/menus.ts b/client/src/common/menus.ts
index ee7d7292c9..1aeb70d644 100644
--- a/client/src/common/menus.ts
+++ b/client/src/common/menus.ts
@@ -15,6 +15,8 @@ export interface MenuItemProps {
separate?: boolean;
hideOnClick?: boolean;
dialog?: React.ReactElement;
+ ariaHasPopup?: React.AriaAttributes['aria-haspopup'];
+ ariaControls?: string;
ariaLabel?: string;
ariaChecked?: boolean;
ref?: React.Ref<any>;
diff --git a/client/src/components/Chat/ExportAndShareMenu.tsx b/client/src/components/Chat/ExportAndShareMenu.tsx
index c91d30543f..dc1789a18d 100644
--- a/client/src/components/Chat/ExportAndShareMenu.tsx
+++ b/client/src/components/Chat/ExportAndShareMenu.tsx
@@ -1,27 +1,33 @@
import { useState, useId } from 'react';
-import { Share2 } from 'lucide-react';
+import { Ellipsis } from 'lucide-react';
import * as Ariakit from '@ariakit/react';
import { DropdownPopup, TooltipAnchor, useMediaQuery } from '@librechat/client';
-import useExportShare from '~/hooks/Chat/useExportShare';
+import useChatOptions from '~/hooks/Chat/useChatOptions';
import { useLocalize } from '~/hooks';
export default function ExportAndShareMenu({
isSharedButtonEnabled,
+ readOnly = false,
}: {
isSharedButtonEnabled: boolean;
+ readOnly?: boolean;
}) {
const localize = useLocalize();
const menuId = useId();
const [isPopoverActive, setIsPopoverActive] = useState(false);
const isSmallScreen = useMediaQuery('(max-width: 768px)');
- const { show, items, hasSharedLink, dialogs } = useExportShare({ isSharedButtonEnabled });
+ const { show, items, hasSharedLink, dialogs } = useChatOptions({
+ isSharedButtonEnabled,
+ readOnly,
+ closeMenu: () => setIsPopoverActive(false),
+ });
if (!show) {
return null;
}
const description = localize(
- hasSharedLink ? 'com_ui_export_share_link_active' : 'com_endpoint_export_share',
+ hasSharedLink ? 'com_ui_chat_options_link_active' : 'com_ui_chat_options',
);
return (
@@ -42,7 +48,7 @@ export default function ExportAndShareMenu({
aria-label={description}
className="border-border-light bg-presentation text-text-primary hover:bg-surface-tertiary aria-expanded:bg-surface-tertiary relative inline-flex size-9 shrink-0 items-center justify-center rounded-xl border transition-all ease-in-out disabled:pointer-events-none disabled:opacity-50"
>
- <Share2
+ <Ellipsis
className="icon-md text-text-primary"
aria-hidden="true"
focusable="false"
diff --git a/client/src/components/Chat/Header.tsx b/client/src/components/Chat/Header.tsx
index ac8e0cfddf..45fd682b1a 100644
--- a/client/src/components/Chat/Header.tsx
+++ b/client/src/components/Chat/Header.tsx
@@ -127,11 +127,15 @@ function Header({
<HeaderMenu
startupConfig={startupConfig}
trace={trace}
+ readOnly={readOnly}
className={isSmallScreen ? undefined : 'hidden'}
/>
<div className={cn('items-center gap-2', isSmallScreen ? 'hidden' : 'flex')}>
{trace.show && <TraceButton onClick={trace.open} />}
- <ExportAndShareMenu isSharedButtonEnabled={startupConfig?.sharedLinksEnabled ?? false} />
+ <ExportAndShareMenu
+ isSharedButtonEnabled={startupConfig?.sharedLinksEnabled ?? false}
+ readOnly={readOnly}
+ />
{showTemporaryChat && <TemporaryChat />}
</div>
</div>
diff --git a/client/src/components/Chat/Menus/HeaderMenu.tsx b/client/src/components/Chat/Menus/HeaderMenu.tsx
index ca6229fd9c..1a7b37d0a8 100644
--- a/client/src/components/Chat/Menus/HeaderMenu.tsx
+++ b/client/src/components/Chat/Menus/HeaderMenu.tsx
@@ -10,7 +10,7 @@ import type * as t from '~/common';
import { BookmarkContext } from '~/Providers/BookmarkContext';
import useBookmarkItems from '~/hooks/Chat/useBookmarkItems';
import useTemporaryChat from '~/hooks/Chat/useTemporaryChat';
-import useExportShare from '~/hooks/Chat/useExportShare';
+import useChatOptions from '~/hooks/Chat/useChatOptions';
import useMultiConvo from '~/hooks/Chat/useMultiConvo';
import { useHasAccess, useLocalize } from '~/hooks';
import { cn } from '~/utils';
@@ -25,8 +25,11 @@ export default function HeaderMenu({
startupConfig,
trace,
className,
+ readOnly = false,
}: {
startupConfig?: TStartupConfig;
+ /** A read-only subagent thread offers share and export but no edits to the chat. */
+ readOnly?: boolean;
/** Owned by the header, which also renders the desktop trace button from it. */
trace?: TraceControl;
className?: string;
@@ -51,8 +54,10 @@ export default function HeaderMenu({
const multiConvo = useMultiConvo();
const temporary = useTemporaryChat();
const bookmarks = useBookmarkItems({ enabled: hasAccessToBookmarks === true });
- const exportShare = useExportShare({
+ const exportShare = useChatOptions({
isSharedButtonEnabled: startupConfig?.sharedLinksEnabled ?? false,
+ readOnly,
+ closeMenu: () => setIsOpen(false),
});
const showBookmarks = hasAccessToBookmarks === true && bookmarks.show;
@@ -129,7 +134,7 @@ export default function HeaderMenu({
/** Mirrors the desktop share button, which surfaces an active link in its tooltip. */
const triggerDescription = exportShare.hasSharedLink
- ? localize('com_ui_export_share_link_active')
+ ? localize('com_ui_chat_options_link_active')
: localize('com_ui_more_options');
return (
diff --git a/client/src/components/Chat/Menus/__tests__/HeaderMenu.spec.tsx b/client/src/components/Chat/Menus/__tests__/HeaderMenu.spec.tsx
index 30541a517c..52b2326ca6 100644
--- a/client/src/components/Chat/Menus/__tests__/HeaderMenu.spec.tsx
+++ b/client/src/components/Chat/Menus/__tests__/HeaderMenu.spec.tsx
@@ -44,7 +44,7 @@ jest.mock('~/hooks/Chat/useBookmarkItems', () => ({
return mockHookState.bookmarks;
},
}));
-jest.mock('~/hooks/Chat/useExportShare', () => ({
+jest.mock('~/hooks/Chat/useChatOptions', () => ({
__esModule: true,
default: () => mockHookState.exportShare,
}));
@@ -186,7 +186,7 @@ describe('HeaderMenu', () => {
expect(screen.getByTestId('header-menu-shared-link-indicator')).toBeInTheDocument();
expect(screen.getByTestId('header-overflow-menu')).toHaveAttribute(
'aria-label',
- 'com_ui_export_share_link_active',
+ 'com_ui_chat_options_link_active',
);
});
diff --git a/client/src/components/Chat/Rename.tsx b/client/src/components/Chat/Rename.tsx
new file mode 100644
index 0000000000..367c3ae469
--- /dev/null
+++ b/client/src/components/Chat/Rename.tsx
@@ -0,0 +1,140 @@
+import { useState, useEffect, useRef } from 'react';
+import {
+ Label,
+ Input,
+ Button,
+ Spinner,
+ OGDialog,
+ OGDialogClose,
+ OGDialogTitle,
+ OGDialogHeader,
+ OGDialogContent,
+ useToastContext,
+} from '@librechat/client';
+import type { FormEvent, RefObject } from 'react';
+import { useUpdateConversationMutation } from '~/data-provider';
+import { NotificationSeverity } from '~/common';
+import { useLocalize } from '~/hooks';
+import { logger } from '~/utils';
+
+const TITLE_MAX_LENGTH = 100;
+const INPUT_ID = 'chat-rename-input';
+
+type RenameProps = {
+ conversationId: string;
+ title: string;
+ /** Saving an unchanged title is how a user claims an automatic one, so only an owned title short-circuits. */
+ titleSetByUser: boolean;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ triggerRef?: RefObject<HTMLButtonElement>;
+};
+
+function RenameContent({
+ conversationId,
+ title,
+ titleSetByUser,
+ onClose,
+}: Pick<RenameProps, 'conversationId' | 'title' | 'titleSetByUser'> & { onClose: () => void }) {
+ const localize = useLocalize();
+ const { showToast } = useToastContext();
+ const [value, setValue] = useState(title);
+ const inputRef = useRef<HTMLInputElement>(null);
+ const updateMutation = useUpdateConversationMutation(conversationId);
+
+ const mountedRef = useRef(true);
+
+ useEffect(() => {
+ mountedRef.current = true;
+ inputRef.current?.focus();
+ inputRef.current?.select();
+ return () => {
+ mountedRef.current = false;
+ };
+ }, []);
+
+ const handleSubmit = async (event: FormEvent) => {
+ event.preventDefault();
+ const next = value.trim() || localize('com_ui_untitled');
+ if (next === title && titleSetByUser) {
+ onClose();
+ return;
+ }
+ try {
+ await updateMutation.mutateAsync({ conversationId, title: next });
+ /** A rename that settles after the dialog went away has no dialog left to close or focus. */
+ if (mountedRef.current) {
+ onClose();
+ }
+ } catch (error) {
+ logger.error('Error renaming conversation', error);
+ showToast({
+ message: localize('com_ui_rename_failed'),
+ severity: NotificationSeverity.ERROR,
+ showIcon: true,
+ });
+ }
+ };
+
+ return (
+ <OGDialogContent
+ id="rename-conversation-dialog"
+ className="w-11/12 max-w-md"
+ showCloseButton={false}
+ >
+ <OGDialogHeader>
+ <OGDialogTitle>{localize('com_ui_rename_conversation')}</OGDialogTitle>
+ </OGDialogHeader>
+ <form onSubmit={handleSubmit} className="flex flex-col gap-4">
+ <div className="flex flex-col gap-2">
+ <Label htmlFor={INPUT_ID}>{localize('com_ui_new_conversation_title')}</Label>
+ <Input
+ id={INPUT_ID}
+ ref={inputRef}
+ value={value}
+ maxLength={TITLE_MAX_LENGTH}
+ onChange={(event) => setValue(event.target.value)}
+ />
+ </div>
+ <div className="flex justify-end gap-4">
+ <OGDialogClose asChild>
+ <Button type="button" variant="outline">
+ {localize('com_ui_cancel')}
+ </Button>
+ </OGDialogClose>
+ <Button type="submit" variant="submit" disabled={updateMutation.isLoading}>
+ {updateMutation.isLoading ? <Spinner /> : localize('com_ui_save')}
+ </Button>
+ </div>
+ </form>
+ </OGDialogContent>
+ );
+}
+
+/** Rename for the open chat. The sidebar renames inline in its row, which the header has no row for. */
+export default function Rename({
+ conversationId,
+ title,
+ titleSetByUser,
+ open,
+ onOpenChange,
+ triggerRef,
+}: RenameProps) {
+ /** Closing from a save bypasses the dialog's own handler, which is what returns focus to the
+ * menu item that opened it, so the same return is done here. */
+ const close = () => {
+ setTimeout(() => triggerRef?.current?.focus(), 0);
+ onOpenChange(false);
+ };
+
+ return (
+ <OGDialog open={open} onOpenChange={onOpenChange} triggerRef={triggerRef}>
+ <RenameContent
+ conversationId={conversationId}
+ title={title}
+ titleSetByUser={titleSetByUser}
+ onClose={close}
+ />
+ </OGDialog>
+ );
+}
diff --git a/client/src/components/Chat/__tests__/ExportAndShareMenu.test.tsx b/client/src/components/Chat/__tests__/ExportAndShareMenu.test.tsx
index 225a989af3..fb40c0aae0 100644
--- a/client/src/components/Chat/__tests__/ExportAndShareMenu.test.tsx
+++ b/client/src/components/Chat/__tests__/ExportAndShareMenu.test.tsx
@@ -3,15 +3,7 @@ import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import ExportAndShareMenu from '../ExportAndShareMenu';
-let mockShareId: string | null = null;
-
-jest.mock('recoil', () => ({
- useRecoilValue: () => ({ conversationId: 'conversation-1' }),
-}));
-
-jest.mock('librechat-data-provider/react-query', () => ({
- useGetSharedLinkQuery: () => ({ data: { shareId: mockShareId } }),
-}));
+const mockOptions = { show: true, hasSharedLink: false };
jest.mock('@ariakit/react', () => ({
MenuButton: ({ children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) => (
@@ -26,31 +18,22 @@ jest.mock('@librechat/client', () => ({
}));
jest.mock('~/hooks', () => ({
- useHasAccess: () => true,
useLocalize: () => (key: string) => key,
}));
-jest.mock('~/components/Nav/ExportConversation/ExportModal', () => ({
+jest.mock('~/hooks/Chat/useChatOptions', () => ({
__esModule: true,
- default: () => null,
-}));
-
-jest.mock('~/components/Conversations/ConvoOptions', () => ({
- ShareButton: () => null,
-}));
-
-jest.mock('~/store', () => ({
- __esModule: true,
- default: { conversationByIndex: () => ({}) },
+ default: () => ({ ...mockOptions, items: [], dialogs: null }),
}));
describe('ExportAndShareMenu link status', () => {
beforeEach(() => {
- mockShareId = null;
+ mockOptions.show = true;
+ mockOptions.hasSharedLink = false;
});
it('shows a blue circular indicator when the conversation has a link', () => {
- mockShareId = 'share-1';
+ mockOptions.hasSharedLink = true;
render(<ExportAndShareMenu isSharedButtonEnabled={true} />);
@@ -63,14 +46,22 @@ describe('ExportAndShareMenu link status', () => {
);
expect(screen.getByRole('button')).toHaveAttribute(
'aria-label',
- 'com_ui_export_share_link_active',
+ 'com_ui_chat_options_link_active',
);
});
- it('uses the default share control when the conversation has no link', () => {
+ it('uses the default options label when the conversation has no link', () => {
render(<ExportAndShareMenu isSharedButtonEnabled={true} />);
expect(screen.queryByTestId('header-shared-link-indicator')).not.toBeInTheDocument();
- expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'com_endpoint_export_share');
+ expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'com_ui_chat_options');
+ });
+
+ it('renders nothing for a conversation that has not been saved', () => {
+ mockOptions.show = false;
+
+ const { container } = render(<ExportAndShareMenu isSharedButtonEnabled={true} />);
+
+ expect(container).toBeEmptyDOMElement();
});
});
diff --git a/client/src/components/Chat/__tests__/Rename.spec.tsx b/client/src/components/Chat/__tests__/Rename.spec.tsx
new file mode 100644
index 0000000000..f35a61c02b
--- /dev/null
+++ b/client/src/components/Chat/__tests__/Rename.spec.tsx
@@ -0,0 +1,153 @@
+import React from 'react';
+import { act, render, screen, fireEvent, waitFor } from '@testing-library/react';
+import '@testing-library/jest-dom';
+import Rename from '../Rename';
+
+const mockMutateAsync = jest.fn();
+const mockShowToast = jest.fn();
+
+jest.mock('@librechat/client', () => ({
+ Label: (props: React.LabelHTMLAttributes<HTMLLabelElement>) => <label {...props} />,
+ Input: jest
+ .requireActual('react')
+ .forwardRef(
+ (
+ props: React.InputHTMLAttributes<HTMLInputElement>,
+ ref: React.ForwardedRef<HTMLInputElement>,
+ ) => <input ref={ref} {...props} />,
+ ),
+ Button: ({
+ variant: _variant,
+ ...props
+ }: React.ButtonHTMLAttributes<HTMLButtonElement> & { variant?: string }) => <button {...props} />,
+ Spinner: () => <span role="status" />,
+ OGDialog: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
+ OGDialogClose: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+ OGDialogTitle: ({ children }: { children: React.ReactNode }) => <h2>{children}</h2>,
+ OGDialogHeader: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
+ OGDialogContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
+ useToastContext: () => ({ showToast: mockShowToast }),
+}));
+jest.mock('~/data-provider', () => ({
+ useUpdateConversationMutation: () => ({ mutateAsync: mockMutateAsync, isLoading: false }),
+}));
+jest.mock('~/common', () => ({ NotificationSeverity: { ERROR: 'error' } }));
+jest.mock('~/hooks', () => ({ useLocalize: () => (key: string) => key }));
+jest.mock('~/utils', () => ({ logger: { error: jest.fn() } }));
+
+const setup = (titleSetByUser = true, title = 'Old title') => {
+ const onOpenChange = jest.fn();
+ const trigger = document.createElement('button');
+ document.body.appendChild(trigger);
+ const { unmount } = render(
+ <Rename
+ conversationId="convo-1"
+ title={title}
+ titleSetByUser={titleSetByUser}
+ open={true}
+ onOpenChange={onOpenChange}
+ triggerRef={{ current: trigger }}
+ />,
+ );
+ return {
+ onOpenChange,
+ trigger,
+ unmount,
+ input: screen.getByLabelText('com_ui_new_conversation_title'),
+ };
+};
+
+describe('Rename', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ mockMutateAsync.mockResolvedValue({});
+ });
+
+ it('starts with the current title selected', () => {
+ const { input } = setup();
+
+ expect(input).toHaveValue('Old title');
+ expect(input).toHaveFocus();
+ });
+
+ it('saves the trimmed title and closes', async () => {
+ const { input, onOpenChange } = setup();
+
+ fireEvent.change(input, { target: { value: ' New title ' } });
+ fireEvent.click(screen.getByText('com_ui_save'));
+
+ await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
+ expect(mockMutateAsync).toHaveBeenCalledWith({
+ conversationId: 'convo-1',
+ title: 'New title',
+ });
+ });
+
+ it('saves an unchanged title to claim ownership while it is still automatic', async () => {
+ const { onOpenChange } = setup(false);
+
+ fireEvent.click(screen.getByText('com_ui_save'));
+
+ await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
+ expect(mockMutateAsync).toHaveBeenCalledWith({
+ conversationId: 'convo-1',
+ title: 'Old title',
+ });
+ });
+
+ it('closes without a request when the title did not change', () => {
+ const { onOpenChange } = setup();
+
+ fireEvent.click(screen.getByText('com_ui_save'));
+
+ expect(onOpenChange).toHaveBeenCalledWith(false);
+ expect(mockMutateAsync).not.toHaveBeenCalled();
+ });
+ it('returns focus to the menu item after a successful save', async () => {
+ const { input, trigger } = setup();
+
+ fireEvent.change(input, { target: { value: 'New title' } });
+ fireEvent.click(screen.getByText('com_ui_save'));
+
+ await waitFor(() => expect(trigger).toHaveFocus());
+ });
+
+ it('returns focus to the menu item when an unchanged title closes the dialog', async () => {
+ const { trigger } = setup();
+
+ fireEvent.click(screen.getByText('com_ui_save'));
+
+ await waitFor(() => expect(trigger).toHaveFocus());
+ });
+ it('does not steal focus when a rename settles after the dialog was unmounted', async () => {
+ let settle: (value: unknown) => void = () => {};
+ mockMutateAsync.mockReturnValue(new Promise((resolve) => (settle = resolve)));
+ const { input, trigger, unmount, onOpenChange } = setup();
+
+ fireEvent.change(input, { target: { value: 'New title' } });
+ fireEvent.click(screen.getByText('com_ui_save'));
+ unmount();
+ await act(async () => {
+ settle({});
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ });
+
+ expect(trigger).not.toHaveFocus();
+ expect(onOpenChange).not.toHaveBeenCalled();
+ });
+
+ it('stays open and reports a failed rename', async () => {
+ mockMutateAsync.mockRejectedValue(new Error('nope'));
+ const { input, onOpenChange } = setup();
+
+ fireEvent.change(input, { target: { value: 'Other' } });
+ fireEvent.click(screen.getByText('com_ui_save'));
+
+ await waitFor(() =>
+ expect(mockShowToast).toHaveBeenCalledWith(
+ expect.objectContaining({ message: 'com_ui_rename_failed' }),
+ ),
+ );
+ expect(onOpenChange).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/components/Conversations/Convo.tsx b/client/src/components/Conversations/Convo.tsx
index d7f88b23c8..be05477697 100644
--- a/client/src/components/Conversations/Convo.tsx
+++ b/client/src/components/Conversations/Convo.tsx
@@ -286,7 +286,6 @@ function Conversation({
isActiveConvo,
isUnseen,
conversationId,
- chatProjectId: conversation.chatProjectId,
isPopoverActive,
isGenerating,
contextMenuPosition,
diff --git a/client/src/components/Conversations/ConvoActions.tsx b/client/src/components/Conversations/ConvoActions.tsx
index a65a68b640..9909cb0a21 100644
--- a/client/src/components/Conversations/ConvoActions.tsx
+++ b/client/src/components/Conversations/ConvoActions.tsx
@@ -8,7 +8,6 @@ import { useLocalize } from '~/hooks';
export type ConvoActionsProps = {
conversationId: string | null;
- chatProjectId?: string | null;
title: string | null;
canRename?: boolean;
isPinned?: boolean;
diff --git a/client/src/components/Conversations/ConvoOptions/ConvoOptions.tsx b/client/src/components/Conversations/ConvoOptions/ConvoOptions.tsx
index 09692f8529..2e47df9bf7 100644
--- a/client/src/components/Conversations/ConvoOptions/ConvoOptions.tsx
+++ b/client/src/components/Conversations/ConvoOptions/ConvoOptions.tsx
@@ -1,41 +1,24 @@
import { useState, useId, useRef, memo, useCallback, useMemo } from 'react';
import * as Ariakit from '@ariakit/react';
+import { QueryKeys } from 'librechat-data-provider';
import { useQueryClient } from '@tanstack/react-query';
import { useParams, useNavigate } from 'react-router-dom';
import { DropdownPopup, Spinner, useToastContext } from '@librechat/client';
-import { QueryKeys, PermissionTypes, Permissions } from 'librechat-data-provider';
-import {
- Ellipsis,
- Share2,
- CopyPlus,
- Archive,
- ArchiveRestore,
- FolderInput,
- FolderX,
- Mail,
- Pen,
- Pin,
- Trash,
-} from 'lucide-react';
+import { Ellipsis, Archive, ArchiveRestore, Mail, Pen, Pin, Trash } from 'lucide-react';
import type { TMessage } from 'librechat-data-provider';
import type { MouseEvent } from 'react';
import {
- useDuplicateConversationMutation,
- useAssignConversationToProjectMutation,
useDeleteConversationMutation,
- useGetStartupConfig,
useArchiveConvoMutation,
usePinConversationMutation,
useMarkConversationUnreadMutation,
} from '~/data-provider';
-import { useHasAccess, useLocalize, useNavigateToConvo, useNewConvo } from '~/hooks';
import { useChatContext, useLiveAnnouncer } from '~/Providers';
import useDrawerViewport from '~/hooks/Nav/useDrawerViewport';
+import { useLocalize, useNewConvo } from '~/hooks';
import { NotificationSeverity } from '~/common';
import { cn, rowActionClasses } from '~/utils';
-import ProjectButton from './ProjectButton';
import DeleteButton from './DeleteButton';
-import ShareButton from './ShareButton';
/** The overflow menu and the shift-held quick action show the same archive control in two
* sizes, and must never disagree about which direction it moves the conversation. */
function renderArchiveIcon(isLoading: boolean, isArchived: boolean, className: string) {
@@ -50,7 +33,6 @@ function renderArchiveIcon(isLoading: boolean, isArchived: boolean, className: s
function ConvoOptions({
conversationId,
- chatProjectId,
title,
isPinned = false,
isArchived = false,
@@ -66,7 +48,6 @@ function ConvoOptions({
contextMenuPosition,
}: {
conversationId: string | null;
- chatProjectId?: string | null;
title: string | null;
isPinned?: boolean;
/** This row's own archive state, which the sidebar filter does not stand in for. */
@@ -85,9 +66,7 @@ function ConvoOptions({
const localize = useLocalize();
const queryClient = useQueryClient();
const isSmallScreen = useDrawerViewport();
- const { index, setConversation } = useChatContext();
- const { data: startupConfig } = useGetStartupConfig();
- const { navigateToConvo } = useNavigateToConvo(index);
+ const { setConversation } = useChatContext();
const { showToast } = useToastContext();
/* Archiving or restoring removes the row from the list that held it, unmounting this
menu: the announcement has to come from a live region that outlives the row. */
@@ -104,20 +83,10 @@ function ConvoOptions({
const menuId = useId();
const menuButtonRef = useRef<HTMLButtonElement>(null);
- const shareButtonRef = useRef<HTMLButtonElement>(null);
const deleteButtonRef = useRef<HTMLButtonElement>(null);
- const projectButtonRef = useRef<HTMLButtonElement>(null);
- const [showShareDialog, setShowShareDialog] = useState(false);
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
- const [showProjectDialog, setShowProjectDialog] = useState(false);
-
- const canCreateSharedLinks = useHasAccess({
- permissionType: PermissionTypes.SHARED_LINKS,
- permission: Permissions.CREATE,
- });
const archiveConvoMutation = useArchiveConvoMutation();
- const assignConversationToProject = useAssignConversationToProjectMutation();
const pinConvoMutation = usePinConversationMutation();
const markUnreadMutation = useMarkConversationUnreadMutation();
@@ -143,73 +112,14 @@ function ConvoOptions({
},
});
- const duplicateConversation = useDuplicateConversationMutation({
- onSuccess: (data) => {
- navigateToConvo(data.conversation);
- showToast({
- message: localize('com_ui_duplication_success'),
- status: 'success',
- });
- setIsPopoverActive(false);
- },
- onMutate: () => {
- showToast({
- message: localize('com_ui_duplication_processing'),
- status: 'info',
- });
- },
- onError: () => {
- showToast({
- message: localize('com_ui_duplication_error'),
- status: 'error',
- });
- },
- });
-
- const isDuplicateLoading = duplicateConversation.isLoading;
const isArchiveLoading = archiveConvoMutation.isLoading;
const isPinLoading = pinConvoMutation.isLoading;
const isDeleteLoading = deleteMutation.isLoading;
- const shareHandler = useCallback(() => {
- setShowShareDialog(true);
- }, []);
-
const deleteHandler = useCallback(() => {
setShowDeleteDialog(true);
}, []);
- const projectHandler = useCallback(() => {
- setShowProjectDialog(true);
- }, []);
-
- const removeProjectHandler = useCallback(() => {
- const convoId = conversationId ?? '';
- if (!convoId) {
- return;
- }
- assignConversationToProject.mutate(
- { conversationId: convoId, projectId: null },
- {
- onSuccess: () => {
- setIsPopoverActive(false);
- showToast({
- message: localize('com_ui_project_updated'),
- severity: NotificationSeverity.SUCCESS,
- showIcon: true,
- });
- },
- onError: () => {
- showToast({
- message: localize('com_ui_project_update_error'),
- severity: NotificationSeverity.ERROR,
- showIcon: true,
- });
- },
- },
- );
- }, [assignConversationToProject, conversationId, localize, setIsPopoverActive, showToast]);
-
const handleInstantDelete = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
@@ -320,26 +230,8 @@ function ConvoOptions({
);
}, [conversationId, markUnreadMutation, setIsPopoverActive, showToast, localize]);
- const handleDuplicateClick = useCallback(() => {
- duplicateConversation.mutate({
- conversationId: conversationId ?? '',
- });
- }, [conversationId, duplicateConversation]);
-
const dropdownItems = useMemo(
() => [
- {
- label: localize('com_ui_share'),
- onClick: shareHandler,
- icon: <Share2 className="icon-sm text-text-primary mr-2" aria-hidden="true" />,
- show: startupConfig && startupConfig.sharedLinksEnabled && canCreateSharedLinks,
- ariaHasPopup: 'dialog' as const,
- ariaControls: 'share-conversation-dialog',
- /** NOTE: THE FOLLOWING PROPS ARE REQUIRED FOR MENU ITEMS THAT OPEN DIALOGS */
- hideOnClick: false,
- ref: shareButtonRef,
- render: (props) => <button {...props} />,
- },
{
label: localize(isPinned ? 'com_ui_unpin' : 'com_ui_pin'),
onClick: handlePinClick,
@@ -364,37 +256,6 @@ function ConvoOptions({
disabled: !canRename,
icon: <Pen className="icon-sm text-text-primary mr-2" aria-hidden="true" />,
},
- {
- label: localize('com_ui_duplicate'),
- onClick: handleDuplicateClick,
- hideOnClick: false,
- icon: isDuplicateLoading ? (
- <Spinner className="size-4" />
- ) : (
- <CopyPlus className="icon-sm text-text-primary mr-2" aria-hidden="true" />
- ),
- },
- {
- label: localize('com_ui_change_project'),
- onClick: projectHandler,
- icon: <FolderInput className="icon-sm text-text-primary mr-2" aria-hidden="true" />,
- ariaHasPopup: 'dialog' as const,
- ariaControls: 'project-conversation-dialog',
- hideOnClick: false,
- ref: projectButtonRef,
- render: (props) => <button {...props} />,
- },
- {
- label: localize('com_ui_remove_from_project'),
- onClick: removeProjectHandler,
- show: Boolean(chatProjectId),
- hideOnClick: false,
- icon: assignConversationToProject.isLoading ? (
- <Spinner className="size-4" />
- ) : (
- <FolderX className="icon-sm text-text-primary mr-2" aria-hidden="true" />
- ),
- },
{
label: localize(isArchived ? 'com_ui_unarchive' : 'com_ui_archive'),
onClick: handleArchiveClick,
@@ -419,23 +280,14 @@ function ConvoOptions({
isUnseen,
isActiveConvo,
isPinLoading,
- shareHandler,
- startupConfig,
renameHandler,
canRename,
deleteHandler,
isArchiveLoading,
isArchived,
- isDuplicateLoading,
handlePinClick,
handleMarkUnreadClick,
handleArchiveClick,
- canCreateSharedLinks,
- handleDuplicateClick,
- projectHandler,
- removeProjectHandler,
- chatProjectId,
- assignConversationToProject.isLoading,
],
);
@@ -443,7 +295,7 @@ function ConvoOptions({
visible: isActiveConvo === true || isPopoverActive || isSmallScreen || isGenerating,
});
- if (isShiftHeld && isActiveConvo && !isPopoverActive && !showShareDialog && !showDeleteDialog) {
+ if (isShiftHeld && isActiveConvo && !isPopoverActive && !showDeleteDialog) {
return (
<div className="flex items-center gap-0.5">
<button
@@ -521,14 +373,6 @@ function ConvoOptions({
}
items={dropdownItems}
/>
- {showShareDialog && (
- <ShareButton
- conversationId={conversationId ?? ''}
- open={showShareDialog}
- onOpenChange={setShowShareDialog}
- triggerRef={shareButtonRef}
- />
- )}
{showDeleteDialog && (
<DeleteButton
title={title ?? ''}
@@ -540,16 +384,6 @@ function ConvoOptions({
setShowDeleteDialog={setShowDeleteDialog}
/>
)}
- {showProjectDialog && (
- <ProjectButton
- conversationId={conversationId ?? ''}
- chatProjectId={chatProjectId}
- setMenuOpen={setIsPopoverActive}
- triggerRef={menuButtonRef}
- showProjectDialog={showProjectDialog}
- setShowProjectDialog={setShowProjectDialog}
- />
- )}
</>
);
}
@@ -559,7 +393,6 @@ export default memo(ConvoOptions, (prevProps, nextProps) => {
prevProps.conversationId === nextProps.conversationId &&
prevProps.title === nextProps.title &&
prevProps.canRename === nextProps.canRename &&
- prevProps.chatProjectId === nextProps.chatProjectId &&
prevProps.isPinned === nextProps.isPinned &&
prevProps.isArchived === nextProps.isArchived &&
prevProps.isUnseen === nextProps.isUnseen &&
diff --git a/client/src/components/Conversations/ConvoOptions/DeleteButton.tsx b/client/src/components/Conversations/ConvoOptions/DeleteButton.tsx
index b49cff6e2e..f3510827d8 100644
--- a/client/src/components/Conversations/ConvoOptions/DeleteButton.tsx
+++ b/client/src/components/Conversations/ConvoOptions/DeleteButton.tsx
@@ -27,12 +27,15 @@ type DeleteButtonProps = {
triggerRef?: React.RefObject<HTMLButtonElement>;
setMenuOpen?: (open: boolean) => void;
currentConversationId?: string;
+ /** Read when the delete settles, for callers whose dialog outlives the route it was opened on. */
+ getCurrentConversationId?: () => string | undefined;
};
export function DeleteConversationDialog({
setShowDeleteDialog,
conversationId,
currentConversationId,
+ getCurrentConversationId,
setMenuOpen,
retainView,
title,
@@ -41,6 +44,7 @@ export function DeleteConversationDialog({
setShowDeleteDialog: (value: boolean) => void;
conversationId: string;
currentConversationId?: string;
+ getCurrentConversationId?: () => string | undefined;
retainView: () => void;
title: string;
}) {
@@ -55,7 +59,8 @@ export function DeleteConversationDialog({
const deleteMutation = useDeleteConversationMutation({
onSuccess: () => {
setShowDeleteDialog(false);
- if (currentConvoId === conversationId || currentConvoId === 'new') {
+ const openConvoId = getCurrentConversationId ? getCurrentConversationId() : currentConvoId;
+ if (openConvoId === conversationId || openConvoId === 'new') {
newConversation();
navigate('/c/new', { replace: true });
}
@@ -86,6 +91,7 @@ export function DeleteConversationDialog({
return (
<OGDialogContent
+ id="delete-conversation-dialog"
className="w-11/12 max-w-md"
showCloseButton={false}
aria-describedby="delete-conversation-description"
@@ -117,6 +123,7 @@ export function DeleteConversationDialog({
export default function DeleteButton({
conversationId,
currentConversationId,
+ getCurrentConversationId,
retainView,
title,
setMenuOpen,
@@ -138,6 +145,7 @@ export default function DeleteButton({
setShowDeleteDialog={setShowDeleteDialog}
conversationId={conversationId}
currentConversationId={currentConversationId}
+ getCurrentConversationId={getCurrentConversationId}
setMenuOpen={setMenuOpen}
retainView={retainView}
title={title}
diff --git a/client/src/components/Conversations/ConvoOptions/ProjectButton.tsx b/client/src/components/Conversations/ConvoOptions/ProjectButton.tsx
index 1cf44a19e0..96b118a0a8 100644
--- a/client/src/components/Conversations/ConvoOptions/ProjectButton.tsx
+++ b/client/src/components/Conversations/ConvoOptions/ProjectButton.tsx
@@ -25,6 +25,8 @@ type ProjectButtonProps = {
setShowProjectDialog?: (value: boolean) => void;
triggerRef?: RefObject<HTMLButtonElement>;
setMenuOpen?: (open: boolean) => void;
+ /** Called with the new project once the assignment has landed. */
+ onAssigned?: (projectId: string) => void;
};
function ProjectConversationDialog({
@@ -32,11 +34,13 @@ function ProjectConversationDialog({
chatProjectId,
setMenuOpen,
setShowProjectDialog,
+ onAssigned,
}: {
conversationId: string;
chatProjectId?: string | null;
setMenuOpen?: (open: boolean) => void;
setShowProjectDialog: (value: boolean) => void;
+ onAssigned?: (projectId: string) => void;
}) {
const localize = useLocalize();
const { showToast } = useToastContext();
@@ -59,7 +63,7 @@ function ProjectConversationDialog({
projects.map((project) => ({
label: project.name,
value: project._id,
- icon: <Folder className="h-4 w-4 text-text-secondary" aria-hidden="true" />,
+ icon: <Folder className="text-text-secondary h-4 w-4" aria-hidden="true" />,
})),
[projects],
);
@@ -79,6 +83,7 @@ function ProjectConversationDialog({
},
{
onSuccess: () => {
+ onAssigned?.(selectedProjectId);
setShowProjectDialog(false);
setMenuOpen?.(false);
showToast({
@@ -108,7 +113,7 @@ function ProjectConversationDialog({
<OGDialogTitle>{localize('com_ui_change_project')}</OGDialogTitle>
</OGDialogHeader>
<div className="flex flex-col gap-2">
- <Label htmlFor="change-project-select" className="text-sm font-medium text-text-primary">
+ <Label htmlFor="change-project-select" className="text-text-primary text-sm font-medium">
{localize('com_ui_select_project')}
</Label>
<ControlCombobox
@@ -117,7 +122,7 @@ function ProjectConversationDialog({
displayValue={selectedProject?.name}
items={projectItems}
setValue={setSelectedProjectId}
- SelectIcon={<Folder className="h-4 w-4 text-text-secondary" aria-hidden="true" />}
+ SelectIcon={<Folder className="text-text-secondary h-4 w-4" aria-hidden="true" />}
ariaLabel={localize('com_ui_select_project')}
searchPlaceholder={localize('com_ui_search_projects')}
selectPlaceholder={localize('com_ui_select_project')}
@@ -127,7 +132,7 @@ function ProjectConversationDialog({
portal={false}
matchTriggerWidth={true}
containerClassName="w-full px-0"
- className="h-10 w-full justify-start gap-2 rounded-xl border border-border-light bg-surface-tertiary px-3 text-sm text-text-primary hover:bg-surface-hover"
+ className="border-border-light bg-surface-tertiary text-text-primary hover:bg-surface-hover h-10 w-full justify-start gap-2 rounded-xl border px-3 text-sm"
/>
{hasNextPage ? (
<Button
@@ -162,6 +167,7 @@ export default function ProjectButton({
showProjectDialog,
setShowProjectDialog,
triggerRef,
+ onAssigned,
}: ProjectButtonProps) {
if (showProjectDialog === undefined || setShowProjectDialog === undefined) {
return null;
@@ -178,6 +184,7 @@ export default function ProjectButton({
chatProjectId={chatProjectId}
setMenuOpen={setMenuOpen}
setShowProjectDialog={setShowProjectDialog}
+ onAssigned={onAssigned}
/>
</OGDialog>
);
diff --git a/client/src/components/Conversations/ConvoOptions/__tests__/DeleteButton.test.tsx b/client/src/components/Conversations/ConvoOptions/__tests__/DeleteButton.test.tsx
new file mode 100644
index 0000000000..4bb43fef27
--- /dev/null
+++ b/client/src/components/Conversations/ConvoOptions/__tests__/DeleteButton.test.tsx
@@ -0,0 +1,89 @@
+import React from 'react';
+import { render } from '@testing-library/react';
+import '@testing-library/jest-dom';
+import { DeleteConversationDialog } from '../DeleteButton';
+
+const mockNavigate = jest.fn();
+const mockNewConversation = jest.fn();
+const mockRoute = { current: 'convo-1' as string | undefined };
+const mockDeleteOptions: { current?: { onSuccess?: () => void } } = {};
+
+jest.mock('react-i18next', () => ({
+ Trans: ({ i18nKey }: { i18nKey: string }) => <span>{i18nKey}</span>,
+}));
+jest.mock('react-router-dom', () => ({
+ useNavigate: () => mockNavigate,
+ useParams: () => ({ conversationId: mockRoute.current }),
+}));
+jest.mock('@tanstack/react-query', () => ({
+ useQueryClient: () => ({ getQueryData: jest.fn() }),
+}));
+jest.mock('librechat-data-provider', () => ({ QueryKeys: { messages: 'messages' } }));
+jest.mock('@librechat/client', () => {
+ const Box = ({ children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
+ <div {...props}>{children}</div>
+ );
+ return {
+ Button: ({ children }: { children: React.ReactNode }) => <button>{children}</button>,
+ Spinner: () => <span role="status" />,
+ OGDialog: Box,
+ OGDialogClose: Box,
+ OGDialogTitle: Box,
+ OGDialogHeader: Box,
+ OGDialogContent: Box,
+ useToastContext: () => ({ showToast: jest.fn() }),
+ };
+});
+jest.mock('~/data-provider', () => ({
+ useDeleteConversationMutation: (options: { onSuccess?: () => void }) => {
+ mockDeleteOptions.current = options;
+ return { mutate: jest.fn(), isLoading: false };
+ },
+}));
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useNewConvo: () => ({ newConversation: mockNewConversation }),
+}));
+jest.mock('~/common', () => ({ NotificationSeverity: { SUCCESS: 'success', ERROR: 'error' } }));
+
+const renderDialog = (getCurrentConversationId?: () => string | undefined) =>
+ render(
+ <DeleteConversationDialog
+ conversationId="convo-1"
+ title="Hello"
+ retainView={jest.fn()}
+ setShowDeleteDialog={jest.fn()}
+ getCurrentConversationId={getCurrentConversationId}
+ />,
+ );
+
+describe('DeleteConversationDialog', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ mockRoute.current = 'convo-1';
+ });
+
+ it('carries the id its menu item points aria-controls at', () => {
+ const { container } = renderDialog();
+
+ expect(container.querySelector('#delete-conversation-dialog')).not.toBeNull();
+ });
+
+ it('leaves a chat opened after the delete was confirmed', () => {
+ renderDialog(() => 'convo-2');
+
+ mockDeleteOptions.current?.onSuccess?.();
+
+ expect(mockNewConversation).not.toHaveBeenCalled();
+ expect(mockNavigate).not.toHaveBeenCalled();
+ });
+
+ it('replaces the chat when the deleted one is still the open one', () => {
+ renderDialog(() => 'convo-1');
+
+ mockDeleteOptions.current?.onSuccess?.();
+
+ expect(mockNewConversation).toHaveBeenCalledTimes(1);
+ expect(mockNavigate).toHaveBeenCalledWith('/c/new', { replace: true });
+ });
+});
diff --git a/client/src/data-provider/__tests__/pinPointCache.spec.tsx b/client/src/data-provider/__tests__/pinPointCache.spec.tsx
new file mode 100644
index 0000000000..0551f24662
--- /dev/null
+++ b/client/src/data-provider/__tests__/pinPointCache.spec.tsx
@@ -0,0 +1,39 @@
+import { createElement } from 'react';
+import { dataService, QueryKeys } from 'librechat-data-provider';
+import { act, renderHook, waitFor } from '@testing-library/react';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+import type { TConversation } from 'librechat-data-provider';
+import type { ReactNode } from 'react';
+import { usePinConversationMutation } from '../mutations';
+
+jest.mock('librechat-data-provider', () => {
+ const actual = jest.requireActual('librechat-data-provider');
+ return { ...actual, dataService: { ...actual.dataService, pinConversation: jest.fn() } };
+});
+
+const pinConversation = dataService.pinConversation as jest.MockedFunction<
+ typeof dataService.pinConversation
+>;
+
+describe('pin mutation and the open chat point cache', () => {
+ it('writes the new pin state into an existing conversation point entry', async () => {
+ const convo = {
+ conversationId: 'convo-1',
+ title: 'Hello',
+ endpoint: 'openAI',
+ } as TConversation;
+ pinConversation.mockResolvedValue({ ...convo, pinned: true } as never);
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ queryClient.setQueryData([QueryKeys.conversation, 'convo-1'], { ...convo, pinned: false });
+ const wrapper = ({ children }: { children: ReactNode }) =>
+ createElement(QueryClientProvider, { client: queryClient }, children);
+ const { result } = renderHook(() => usePinConversationMutation(), { wrapper });
+
+ act(() => result.current.mutate({ conversationId: 'convo-1', pinned: true }));
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
+
+ expect(
+ queryClient.getQueryData<TConversation>([QueryKeys.conversation, 'convo-1'])?.pinned,
+ ).toBe(true);
+ });
+});
diff --git a/client/src/hooks/Chat/__tests__/useChatOptions.spec.tsx b/client/src/hooks/Chat/__tests__/useChatOptions.spec.tsx
new file mode 100644
index 0000000000..fbb918e55b
--- /dev/null
+++ b/client/src/hooks/Chat/__tests__/useChatOptions.spec.tsx
@@ -0,0 +1,449 @@
+import '@testing-library/jest-dom';
+import { QueryKeys } from 'librechat-data-provider';
+import { render, screen, renderHook, act } from '@testing-library/react';
+import type { QueryClient } from '@tanstack/react-query';
+import type { MenuItemProps } from '~/common';
+import useChatOptions from '../useChatOptions';
+
+const mockState = {
+ conversation: { conversationId: 'convo-1', title: 'Hello', pinned: false } as Record<
+ string,
+ unknown
+ >,
+ cached: undefined as Record<string, unknown> | undefined,
+ route: 'convo-1' as string | undefined,
+ activeJobs: [] as string[],
+ startupConfig: undefined as Record<string, unknown> | undefined,
+};
+const mockClient: { current: QueryClient | null } = { current: null };
+const mockCloseMenu = jest.fn();
+const mockPin = jest.fn();
+const mockArchive = jest.fn();
+const mockAssign = jest.fn();
+const mockDuplicate = jest.fn();
+const mockNavigate = jest.fn();
+const mockNewConversation = jest.fn();
+const mockSetConversation = jest.fn();
+const mockAnnounce = jest.fn();
+
+jest.mock('recoil', () => ({ useRecoilValue: () => mockState.conversation }));
+jest.mock('@tanstack/react-query', () => ({ useQueryClient: () => mockClient.current }));
+jest.mock('react-router-dom', () => ({
+ useNavigate: () => mockNavigate,
+ useParams: () => ({ conversationId: mockState.route }),
+}));
+jest.mock('@librechat/client', () => ({ useToastContext: () => ({ showToast: jest.fn() }) }));
+jest.mock('~/store', () => ({ __esModule: true, default: { conversationByIndex: () => ({}) } }));
+jest.mock('~/common', () => ({ NotificationSeverity: { SUCCESS: 'success', ERROR: 'error' } }));
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useNewConvo: () => ({ newConversation: mockNewConversation }),
+ useNavigateToConvo: () => ({ navigateToConvo: jest.fn() }),
+}));
+jest.mock('~/Providers', () => ({
+ useChatContext: () => ({ setConversation: mockSetConversation }),
+ useLiveAnnouncer: () => ({ announcePolite: mockAnnounce }),
+}));
+jest.mock('~/data-provider', () => ({
+ useGetConvoIdQuery: () => ({ data: mockState.cached }),
+ useGetStartupConfig: () => ({ data: mockState.startupConfig }),
+ useActiveJobs: () => ({ data: { activeJobIds: mockState.activeJobs } }),
+ usePinConversationMutation: () => ({ mutate: mockPin }),
+ useArchiveConvoMutation: () => ({ mutate: mockArchive }),
+ useAssignConversationToProjectMutation: () => ({ mutate: mockAssign }),
+ useDuplicateConversationMutation: () => ({ mutate: mockDuplicate }),
+}));
+jest.mock('~/components/Conversations/ConvoOptions', () => ({
+ ProjectButton: () => <div data-testid="project-dialog" />,
+}));
+const mockDeleteProps: {
+ current?: {
+ setShowDeleteDialog: (open: boolean) => void;
+ setMenuOpen: (open: boolean) => void;
+ getCurrentConversationId: () => string | undefined;
+ };
+} = {};
+jest.mock('~/components/Conversations/ConvoOptions/DeleteButton', () => ({
+ __esModule: true,
+ default: (props: NonNullable<typeof mockDeleteProps.current>) => {
+ mockDeleteProps.current = props;
+ return <div data-testid="delete-dialog" />;
+ },
+}));
+jest.mock('~/components/Chat/Rename', () => ({
+ __esModule: true,
+ default: () => <div data-testid="rename-dialog" />,
+}));
+jest.mock('../useExportShare', () => ({
+ __esModule: true,
+ default: () => ({
+ show: true,
+ hasSharedLink: false,
+ items: [{ label: 'share' }, { label: 'export' }],
+ dialogs: null,
+ }),
+}));
+
+const setup = (readOnly = false) =>
+ renderHook(() =>
+ useChatOptions({ isSharedButtonEnabled: true, closeMenu: mockCloseMenu, readOnly }),
+ );
+const labels = (items: MenuItemProps[]) =>
+ items.filter((item) => item.show !== false && item.separate !== true).map((item) => item.label);
+const find = (items: MenuItemProps[], label: string) => {
+ const item = items.find((entry) => entry.label === label);
+ if (item == null) {
+ throw new Error(`no ${label} item`);
+ }
+ return item;
+};
+
+describe('useChatOptions', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ mockState.conversation = { conversationId: 'convo-1', title: 'Hello', pinned: false };
+ mockState.cached = undefined;
+ mockClient.current = new (jest.requireActual('@tanstack/react-query').QueryClient)();
+ mockState.route = 'convo-1';
+ mockState.activeJobs = [];
+ mockState.startupConfig = undefined;
+ });
+
+ it('lists share and export first, then the sidebar actions for the open chat', () => {
+ const { result } = setup();
+
+ expect(labels(result.current.items)).toEqual([
+ 'share',
+ 'export',
+ 'com_ui_rename',
+ 'com_ui_pin',
+ 'com_ui_change_project',
+ 'com_ui_duplicate',
+ 'com_ui_archive',
+ 'com_ui_delete',
+ ]);
+ });
+
+ it('leaves out mark unread, which the open chat can never need', () => {
+ const { result } = setup();
+
+ expect(labels(result.current.items)).not.toContain('com_ui_mark_unread');
+ });
+
+ it('keeps the dialog-opening items open and anchored so their dialogs can restore focus', () => {
+ const { result } = setup();
+
+ for (const label of ['com_ui_rename', 'com_ui_change_project', 'com_ui_delete']) {
+ const item = find(result.current.items, label);
+ expect(item.hideOnClick).toBe(false);
+ expect(item.ref).toBeDefined();
+ }
+ });
+
+ it('reads pin and archive state from the cached conversation over the chat state', () => {
+ mockState.cached = { conversationId: 'convo-1', pinned: true, isArchived: true };
+ const { result } = setup();
+
+ expect(labels(result.current.items)).toEqual(
+ expect.arrayContaining(['com_ui_unpin', 'com_ui_unarchive']),
+ );
+ });
+
+ it('offers removal from a project only when the chat is in one', () => {
+ const { result, rerender } = setup();
+ expect(labels(result.current.items)).not.toContain('com_ui_remove_from_project');
+
+ mockState.cached = { conversationId: 'convo-1', chatProjectId: 'project-1' };
+ rerender();
+ expect(labels(result.current.items)).toContain('com_ui_remove_from_project');
+ });
+
+ it('pins an unpinned chat', () => {
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_pin').onClick?.({} as never));
+
+ expect(mockPin).toHaveBeenCalledWith(
+ { conversationId: 'convo-1', pinned: true },
+ expect.any(Object),
+ );
+ });
+
+ it('mirrors a landed pin into the open chat when no cached conversation carries it', () => {
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_pin').onClick?.({} as never));
+ act(() => mockPin.mock.calls[0][1].onSuccess());
+
+ expect(mockSetConversation).toHaveBeenCalledTimes(1);
+ const [updater] = mockSetConversation.mock.calls[0];
+ expect(updater({ conversationId: 'convo-1', pinned: false })).toEqual({
+ conversationId: 'convo-1',
+ pinned: true,
+ });
+ });
+
+ it('does not touch another chat opened while the pin was in flight', () => {
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_pin').onClick?.({} as never));
+ act(() => mockPin.mock.calls[0][1].onSuccess());
+
+ const [updater] = mockSetConversation.mock.calls[0];
+ const other = { conversationId: 'convo-2', pinned: false };
+ expect(updater(other)).toBe(other);
+ });
+
+ it('mirrors a landed project removal into the open chat', () => {
+ mockState.cached = { conversationId: 'convo-1', chatProjectId: 'project-1' };
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_remove_from_project').onClick?.({} as never));
+ act(() => mockAssign.mock.calls[0][1].onSuccess());
+
+ expect(mockAssign.mock.calls[0][0]).toEqual({ conversationId: 'convo-1', projectId: null });
+ const [updater] = mockSetConversation.mock.calls[0];
+ expect(updater({ conversationId: 'convo-1', chatProjectId: 'project-1' })).toEqual({
+ conversationId: 'convo-1',
+ chatProjectId: null,
+ });
+ });
+
+ it('offers only share and export on a read-only subagent thread', () => {
+ const { result } = setup(true);
+
+ expect(labels(result.current.items)).toEqual(['share', 'export']);
+ });
+
+ it('disables rename while the chat is generating without title ownership support', () => {
+ mockState.activeJobs = ['convo-1'];
+ const { result } = setup();
+
+ expect(find(result.current.items, 'com_ui_rename').disabled).toBe(true);
+ });
+
+ it('keeps rename enabled while generating when the deployment supports title ownership', () => {
+ mockState.activeJobs = ['convo-1'];
+ mockState.startupConfig = {
+ conversationTitleOwnershipVersion: 1,
+ interface: { runningChatRename: true },
+ };
+ const { result } = setup();
+
+ expect(find(result.current.items, 'com_ui_rename').disabled).toBe(false);
+ });
+
+ it('keeps rename enabled for a chat that is not generating', () => {
+ const { result } = setup();
+
+ expect(find(result.current.items, 'com_ui_rename').disabled).toBe(false);
+ });
+
+ it('stays on a chat opened while the archive request was in flight', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_archive').onClick?.({} as never));
+ mockState.route = 'convo-2';
+ rerender();
+ act(() => mockArchive.mock.calls[0][1].onSuccess());
+
+ expect(mockNewConversation).not.toHaveBeenCalled();
+ expect(mockNavigate).not.toHaveBeenCalled();
+ });
+
+ it('hides history-only actions for a temporary chat', () => {
+ mockState.conversation = {
+ conversationId: 'convo-1',
+ title: 'Hello',
+ isTemporary: true,
+ chatProjectId: 'project-1',
+ };
+ const { result } = setup();
+
+ expect(labels(result.current.items)).toEqual([
+ 'share',
+ 'export',
+ 'com_ui_rename',
+ 'com_ui_duplicate',
+ 'com_ui_delete',
+ ]);
+ });
+
+ it('tells assistive technology which items open a dialog', () => {
+ const { result } = setup();
+
+ expect(find(result.current.items, 'com_ui_rename')).toMatchObject({
+ ariaHasPopup: 'dialog',
+ ariaControls: 'rename-conversation-dialog',
+ });
+ expect(find(result.current.items, 'com_ui_change_project')).toMatchObject({
+ ariaHasPopup: 'dialog',
+ ariaControls: 'project-conversation-dialog',
+ });
+ expect(find(result.current.items, 'com_ui_delete')).toMatchObject({
+ ariaHasPopup: 'dialog',
+ ariaControls: 'delete-conversation-dialog',
+ });
+ });
+
+ it('closes an open dialog when another chat becomes the open one', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_rename').onClick?.({} as never));
+ const { rerender: rerenderDialogs } = render(<>{result.current.dialogs}</>);
+ expect(screen.getByTestId('rename-dialog')).toBeInTheDocument();
+
+ mockState.conversation = { conversationId: 'convo-2', title: 'Other' };
+ rerender();
+ rerenderDialogs(<>{result.current.dialogs}</>);
+
+ expect(screen.queryByTestId('rename-dialog')).not.toBeInTheDocument();
+ });
+
+ it('does not reopen a dialog when the first chat comes back', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_delete').onClick?.({} as never));
+ mockState.conversation = { conversationId: 'convo-2', title: 'Other' };
+ rerender();
+ mockState.conversation = { conversationId: 'convo-1', title: 'Hello' };
+ rerender();
+ render(<>{result.current.dialogs}</>);
+
+ expect(screen.queryByTestId('delete-dialog')).not.toBeInTheDocument();
+ });
+
+ it('renders no mutating dialog once the thread turns read-only', () => {
+ let readOnly = false;
+ const { result, rerender } = renderHook(() =>
+ useChatOptions({ isSharedButtonEnabled: true, closeMenu: mockCloseMenu, readOnly }),
+ );
+
+ act(() => find(result.current.items, 'com_ui_change_project').onClick?.({} as never));
+ readOnly = true;
+ rerender();
+ render(<>{result.current.dialogs}</>);
+
+ expect(screen.queryByTestId('project-dialog')).not.toBeInTheDocument();
+ });
+
+ it('tells the delete dialog which chat is open when the request settles', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_delete').onClick?.({} as never));
+ render(<>{result.current.dialogs}</>);
+ const props = mockDeleteProps.current;
+ mockState.route = 'convo-2';
+ rerender();
+
+ expect(props?.getCurrentConversationId()).toBe('convo-2');
+ });
+
+ it('keeps a newer chat dialog open when an earlier delete settles', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_delete').onClick?.({} as never));
+ const first = render(<>{result.current.dialogs}</>);
+ const settleEarlierDelete = mockDeleteProps.current?.setShowDeleteDialog;
+ first.unmount();
+ mockState.route = 'convo-2';
+ mockState.conversation = { conversationId: 'convo-2', title: 'Other' };
+ rerender();
+ act(() => find(result.current.items, 'com_ui_rename').onClick?.({} as never));
+ act(() => settleEarlierDelete?.(false));
+ render(<>{result.current.dialogs}</>);
+
+ expect(screen.getByTestId('rename-dialog')).toBeInTheDocument();
+ });
+
+ it('dismisses the menu and dialogs when the route moves before the chat state does', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_rename').onClick?.({} as never));
+ mockCloseMenu.mockClear();
+ mockState.route = 'convo-2';
+ rerender();
+ render(<>{result.current.dialogs}</>);
+
+ expect(mockCloseMenu).toHaveBeenCalled();
+ expect(screen.queryByTestId('rename-dialog')).not.toBeInTheDocument();
+ });
+
+ it('does not let a delete that settles later close the menu of the chat opened since', () => {
+ const { result, rerender } = setup();
+
+ act(() => find(result.current.items, 'com_ui_delete').onClick?.({} as never));
+ render(<>{result.current.dialogs}</>);
+ const settleEarlierDelete = mockDeleteProps.current?.setMenuOpen;
+ mockState.route = 'convo-2';
+ mockState.conversation = { conversationId: 'convo-2', title: 'Other' };
+ rerender();
+ mockCloseMenu.mockClear();
+ act(() => settleEarlierDelete?.(false));
+
+ expect(mockCloseMenu).not.toHaveBeenCalled();
+ });
+
+ it('closes the menu when the delete of the open chat settles', () => {
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_delete').onClick?.({} as never));
+ render(<>{result.current.dialogs}</>);
+ mockCloseMenu.mockClear();
+ act(() => mockDeleteProps.current?.setMenuOpen(false));
+
+ expect(mockCloseMenu).toHaveBeenCalledTimes(1);
+ });
+
+ it('prefers the newest cached copy over an older point entry', () => {
+ const client = mockClient.current as QueryClient;
+ client.setQueryData(
+ [QueryKeys.conversation, 'convo-1'],
+ { conversationId: 'convo-1', pinned: false },
+ { updatedAt: Date.now() - 1000 },
+ );
+ client.setQueryData(
+ [QueryKeys.allConversations],
+ {
+ pages: [{ conversations: [{ conversationId: 'convo-1', pinned: true }], nextCursor: null }],
+ pageParams: [undefined],
+ },
+ { updatedAt: Date.now() },
+ );
+ mockState.cached = { conversationId: 'convo-1', pinned: false };
+ const { result } = setup();
+
+ expect(labels(result.current.items)).toContain('com_ui_unpin');
+ });
+
+ it('leaves an archived chat for a new one once the archive lands', () => {
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_archive').onClick?.({} as never));
+ expect(mockArchive.mock.calls[0][0]).toEqual({ conversationId: 'convo-1', isArchived: true });
+ act(() => mockArchive.mock.calls[0][1].onSuccess());
+
+ expect(mockNewConversation).toHaveBeenCalledTimes(1);
+ expect(mockNavigate).toHaveBeenCalledWith('/c/new', { replace: true });
+ });
+
+ it('stays on a chat it just restored from the archive', () => {
+ mockState.cached = { conversationId: 'convo-1', isArchived: true };
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_unarchive').onClick?.({} as never));
+ act(() => mockArchive.mock.calls[0][1].onSuccess());
+
+ expect(mockArchive.mock.calls[0][0]).toEqual({ conversationId: 'convo-1', isArchived: false });
+ expect(mockNavigate).not.toHaveBeenCalled();
+ expect(mockNewConversation).not.toHaveBeenCalled();
+ });
+
+ it('duplicates the open chat', () => {
+ const { result } = setup();
+
+ act(() => find(result.current.items, 'com_ui_duplicate').onClick?.({} as never));
+
+ expect(mockDuplicate).toHaveBeenCalledWith({ conversationId: 'convo-1' });
+ });
+});
diff --git a/client/src/hooks/Chat/useChatOptions.tsx b/client/src/hooks/Chat/useChatOptions.tsx
new file mode 100644
index 0000000000..6d053bc2ce
--- /dev/null
+++ b/client/src/hooks/Chat/useChatOptions.tsx
@@ -0,0 +1,344 @@
+import { useState, useRef, useEffect, useCallback } from 'react';
+import { useRecoilValue } from 'recoil';
+import { useToastContext } from '@librechat/client';
+import { useQueryClient } from '@tanstack/react-query';
+import { useNavigate, useParams } from 'react-router-dom';
+import { supportsConversationTitleOwnership } from 'librechat-data-provider';
+import {
+ Pen,
+ Pin,
+ Trash,
+ Archive,
+ FolderX,
+ CopyPlus,
+ FolderInput,
+ ArchiveRestore,
+} from 'lucide-react';
+import type { TConversation } from 'librechat-data-provider';
+import type { ReactNode } from 'react';
+import type * as t from '~/common';
+import {
+ useActiveJobs,
+ useGetConvoIdQuery,
+ useGetStartupConfig,
+ useArchiveConvoMutation,
+ usePinConversationMutation,
+ useDuplicateConversationMutation,
+ useAssignConversationToProjectMutation,
+} from '~/data-provider';
+import { findConvoInAllQueries, isTemporaryConversation, hasRealTitle } from '~/utils';
+import DeleteButton from '~/components/Conversations/ConvoOptions/DeleteButton';
+import { ProjectButton } from '~/components/Conversations/ConvoOptions';
+import { useLocalize, useNavigateToConvo, useNewConvo } from '~/hooks';
+import { useChatContext, useLiveAnnouncer } from '~/Providers';
+import { NotificationSeverity } from '~/common';
+import useExportShare from './useExportShare';
+import Rename from '~/components/Chat/Rename';
+import store from '~/store';
+
+export type UseChatOptionsResult = {
+ show: boolean;
+ items: t.MenuItemProps[];
+ hasSharedLink: boolean;
+ /** Rendered by the surface that owns the menu, next to its trigger. */
+ dialogs: ReactNode;
+};
+
+type DialogKind = 'rename' | 'project' | 'delete';
+
+const iconClass = 'size-4 text-text-secondary';
+const noop = () => {};
+
+/**
+ * Everything the sidebar row's overflow menu does to a chat, for the chat that is open,
+ * grouped for the header: share and export first, then organizing, then the two actions
+ * that remove it from view. Mark unread is left out because the open chat is read by definition.
+ */
+export default function useChatOptions({
+ isSharedButtonEnabled,
+ closeMenu,
+ readOnly = false,
+}: {
+ isSharedButtonEnabled: boolean;
+ closeMenu: () => void;
+ /** A durable subagent thread is a canonical record of its parent's run: only share and export apply. */
+ readOnly?: boolean;
+}): UseChatOptionsResult {
+ const localize = useLocalize();
+ const navigate = useNavigate();
+ const { showToast } = useToastContext();
+ const { announcePolite } = useLiveAnnouncer();
+ const { newConversation } = useNewConvo();
+ const { setConversation } = useChatContext();
+ const { navigateToConvo } = useNavigateToConvo(0);
+ const { data: startupConfig } = useGetStartupConfig();
+ const { data: activeJobs } = useActiveJobs();
+ const { conversationId: routeConversationId } = useParams();
+ /** A request outlives the click: the route that matters is the one open when it resolves. */
+ const openConvoIdRef = useRef(routeConversationId);
+ openConvoIdRef.current = routeConversationId;
+ const exportShare = useExportShare({ isSharedButtonEnabled });
+ const conversation = useRecoilValue(store.conversationByIndex(0));
+
+ const conversationId = conversation?.conversationId ?? '';
+ const queryClient = useQueryClient();
+ /** Pin and project changes land in the query cache, not in the chat's own state. The observer
+ * re-renders on a change to the point entry; the freshest copy across it and the lists is read
+ * here, because a revisited chat's point entry can predate an edit the lists already hold. */
+ const { data: cached } = useGetConvoIdQuery(conversationId, { enabled: false });
+ const freshest = conversationId ? findConvoInAllQueries(queryClient, conversationId) : undefined;
+ const base = cached ?? conversation;
+ const current = freshest ? { ...base, ...freshest } : base;
+ const isPinned = current?.pinned === true;
+ const isArchived = current?.isArchived === true;
+ const chatProjectId = current?.chatProjectId ?? null;
+ const title = current?.title ?? '';
+ const isTemporary = isTemporaryConversation(current);
+ const isGenerating = activeJobs?.activeJobIds?.includes(conversationId) === true;
+ /** The sidebar's rule: a running chat can only be renamed where the deployment can protect
+ * the manual title from the pending generated one. */
+ const canRename =
+ supportsConversationTitleOwnership(startupConfig) ||
+ (!isGenerating && (current?.titleSetByUser === true || hasRealTitle(title)));
+
+ const renameRef = useRef<HTMLButtonElement>(null);
+ const projectRef = useRef<HTMLButtonElement>(null);
+ const deleteRef = useRef<HTMLButtonElement>(null);
+ /** ChatView stays mounted across a route change, so a dialog is tied to the chat it was opened
+ * for rather than to whichever chat is open when it renders. */
+ const [openDialog, setOpenDialog] = useState<{ kind: DialogKind; id: string } | null>(null);
+ /** The route moves before the chat state does, and the menu and dialogs are portaled outside the
+ * hidden pane, so they are dismissed on either change rather than left aimed at the old chat. */
+ const closeMenuRef = useRef(closeMenu);
+ closeMenuRef.current = closeMenu;
+ const scopeRef = useRef(`${conversationId}|${routeConversationId}|${readOnly}`);
+ useEffect(() => {
+ const scope = `${conversationId}|${routeConversationId}|${readOnly}`;
+ if (scopeRef.current === scope) {
+ return;
+ }
+ scopeRef.current = scope;
+ setOpenDialog(null);
+ closeMenuRef.current();
+ }, [conversationId, routeConversationId, readOnly]);
+ const isDialogOpen = (kind: DialogKind) =>
+ !readOnly &&
+ openDialog?.kind === kind &&
+ openDialog.id === conversationId &&
+ (routeConversationId == null || routeConversationId === conversationId);
+ const showRename = isDialogOpen('rename');
+ const showProject = isDialogOpen('project');
+ const showDelete = isDialogOpen('delete');
+ /** A close only clears the dialog it belongs to: a delete that settles after another chat
+ * opened its own dialog must not take that one down. */
+ const toggleDialog = (kind: DialogKind) => (open: boolean) =>
+ setOpenDialog((prev) => {
+ if (open) {
+ return { kind, id: conversationId };
+ }
+ return prev?.kind === kind && prev.id === conversationId ? null : prev;
+ });
+ const setShowRename = toggleDialog('rename');
+ const setShowProject = toggleDialog('project');
+ const setShowDelete = toggleDialog('delete');
+
+ const pinMutation = usePinConversationMutation();
+ const archiveMutation = useArchiveConvoMutation();
+ const assignMutation = useAssignConversationToProjectMutation();
+ const duplicateMutation = useDuplicateConversationMutation({
+ onSuccess: (data) => {
+ navigateToConvo(data.conversation);
+ showToast({ message: localize('com_ui_duplication_success'), status: 'success' });
+ },
+ onMutate: () => {
+ showToast({ message: localize('com_ui_duplication_processing'), status: 'info' });
+ },
+ onError: () => {
+ showToast({ message: localize('com_ui_duplication_error'), status: 'error' });
+ },
+ });
+
+ const showError = useCallback(
+ (key: Parameters<typeof localize>[0]) =>
+ showToast({ message: localize(key), severity: NotificationSeverity.ERROR, showIcon: true }),
+ [localize, showToast],
+ );
+
+ /** The request outlives the click, so the open chat is matched at commit time. The query cache
+ * only carries the change when its entry exists, and this state is what the menu falls back to. */
+ const mirrorToOpenChat = (patch: Partial<TConversation>) =>
+ setConversation((prev) =>
+ prev?.conversationId === conversationId ? { ...prev, ...patch } : prev,
+ );
+
+ const togglePin = () => {
+ pinMutation.mutate(
+ { conversationId, pinned: !isPinned },
+ {
+ onSuccess: () => mirrorToOpenChat({ pinned: !isPinned }),
+ onError: () => showError(isPinned ? 'com_ui_unpin_error' : 'com_ui_pin_error'),
+ },
+ );
+ };
+
+ const removeFromProject = () => {
+ assignMutation.mutate(
+ { conversationId, projectId: null },
+ {
+ onSuccess: () => {
+ mirrorToOpenChat({ chatProjectId: null });
+ showToast({
+ message: localize('com_ui_project_updated'),
+ severity: NotificationSeverity.SUCCESS,
+ showIcon: true,
+ });
+ },
+ onError: () => showError('com_ui_project_update_error'),
+ },
+ );
+ };
+
+ const toggleArchive = () => {
+ archiveMutation.mutate(
+ { conversationId, isArchived: !isArchived },
+ {
+ onSuccess: () => {
+ mirrorToOpenChat({ isArchived: !isArchived });
+ announcePolite({
+ message: localize(isArchived ? 'com_ui_convo_unarchived' : 'com_ui_convo_archived'),
+ isStatus: true,
+ });
+ /** An archived chat leaves the list, so the open one is replaced; a restored one stays.
+ * Another chat opened since the click is left alone. */
+ const openConvoId = openConvoIdRef.current;
+ if (!isArchived && (openConvoId === conversationId || openConvoId === 'new')) {
+ newConversation();
+ navigate('/c/new', { replace: true });
+ }
+ },
+ onError: () => showError(isArchived ? 'com_ui_unarchive_error' : 'com_ui_archive_error'),
+ },
+ );
+ };
+
+ /** A temporary chat is excluded from the history, pinned, archived and project lists, so
+ * organizing it would report success and show nowhere. */
+ const canOrganize = !isTemporary;
+
+ const items: t.MenuItemProps[] = [
+ ...exportShare.items,
+ { separate: true },
+ {
+ label: localize('com_ui_rename'),
+ onClick: () => setShowRename(true),
+ icon: <Pen className={iconClass} aria-hidden="true" />,
+ disabled: !canRename,
+ ariaHasPopup: 'dialog',
+ ariaControls: 'rename-conversation-dialog',
+ /** NOTE: THE FOLLOWING PROPS ARE REQUIRED FOR MENU ITEMS THAT OPEN DIALOGS */
+ hideOnClick: false,
+ ref: renameRef,
+ render: (props) => <button {...props} />,
+ },
+ {
+ label: localize(isPinned ? 'com_ui_unpin' : 'com_ui_pin'),
+ onClick: togglePin,
+ show: canOrganize,
+ icon: <Pin className={iconClass} aria-hidden="true" />,
+ },
+ {
+ label: localize('com_ui_change_project'),
+ onClick: () => setShowProject(true),
+ show: canOrganize,
+ icon: <FolderInput className={iconClass} aria-hidden="true" />,
+ ariaHasPopup: 'dialog',
+ ariaControls: 'project-conversation-dialog',
+ /** NOTE: THE FOLLOWING PROPS ARE REQUIRED FOR MENU ITEMS THAT OPEN DIALOGS */
+ hideOnClick: false,
+ ref: projectRef,
+ render: (props) => <button {...props} />,
+ },
+ {
+ label: localize('com_ui_remove_from_project'),
+ onClick: removeFromProject,
+ show: canOrganize && chatProjectId != null,
+ icon: <FolderX className={iconClass} aria-hidden="true" />,
+ },
+ {
+ label: localize('com_ui_duplicate'),
+ onClick: () => duplicateMutation.mutate({ conversationId }),
+ icon: <CopyPlus className={iconClass} aria-hidden="true" />,
+ },
+ { separate: true },
+ {
+ label: localize(isArchived ? 'com_ui_unarchive' : 'com_ui_archive'),
+ onClick: toggleArchive,
+ show: canOrganize,
+ icon: isArchived ? (
+ <ArchiveRestore className={iconClass} aria-hidden="true" />
+ ) : (
+ <Archive className={iconClass} aria-hidden="true" />
+ ),
+ },
+ {
+ label: localize('com_ui_delete'),
+ onClick: () => setShowDelete(true),
+ icon: <Trash className={iconClass} aria-hidden="true" />,
+ ariaHasPopup: 'dialog',
+ ariaControls: 'delete-conversation-dialog',
+ /** NOTE: THE FOLLOWING PROPS ARE REQUIRED FOR MENU ITEMS THAT OPEN DIALOGS */
+ hideOnClick: false,
+ ref: deleteRef,
+ render: (props) => <button {...props} />,
+ },
+ ];
+
+ return {
+ show: exportShare.show,
+ items: readOnly ? exportShare.items : items,
+ hasSharedLink: exportShare.hasSharedLink,
+ dialogs: exportShare.show ? (
+ <>
+ {exportShare.dialogs}
+ {showRename && (
+ <Rename
+ open={showRename}
+ onOpenChange={setShowRename}
+ conversationId={conversationId}
+ title={title}
+ titleSetByUser={current?.titleSetByUser === true}
+ triggerRef={renameRef}
+ />
+ )}
+ {showProject && (
+ <ProjectButton
+ conversationId={conversationId}
+ chatProjectId={chatProjectId}
+ setMenuOpen={closeMenu}
+ triggerRef={projectRef}
+ onAssigned={(projectId) => mirrorToOpenChat({ chatProjectId: projectId })}
+ showProjectDialog={showProject}
+ setShowProjectDialog={setShowProject}
+ />
+ )}
+ {showDelete && (
+ <DeleteButton
+ title={title}
+ retainView={noop}
+ triggerRef={deleteRef}
+ getCurrentConversationId={() => openConvoIdRef.current}
+ setMenuOpen={() => {
+ /** A delete that settles after another chat opened must not close that chat's menu. */
+ if (openConvoIdRef.current === conversationId) {
+ closeMenu();
+ }
+ }}
+ conversationId={conversationId}
+ showDeleteDialog={showDelete}
+ setShowDeleteDialog={setShowDelete}
+ />
+ )}
+ </>
+ ) : null,
+ };
+}
diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json
index d58e3780d1..170e595199 100644
--- a/client/src/locales/en/translation.json
+++ b/client/src/locales/en/translation.json
@@ -501,7 +501,6 @@
"com_endpoint_effort": "Effort",
"com_endpoint_examples": "Presets",
"com_endpoint_export": "Export",
- "com_endpoint_export_share": "Export/Share",
"com_endpoint_frequency_penalty": "Frequency Penalty",
"com_endpoint_google_maxoutputtokens": "Maximum number of tokens that can be generated in the response. Specify a lower value for shorter responses and a higher value for longer responses. Note: models may stop before reaching this maximum.",
"com_endpoint_google_temp": "Higher values = more random, while lower values = more focused and deterministic. We recommend altering this or Top P but not both.",
@@ -1350,6 +1349,8 @@
"com_ui_change_version": "Change Version",
"com_ui_chat": "Chat",
"com_ui_chat_history": "Chat History",
+ "com_ui_chat_options": "Chat options",
+ "com_ui_chat_options_link_active": "Chat options, link active",
"com_ui_chat_list": "Chat list",
"com_ui_chats_load_error": "Couldn't load your chats",
"com_ui_chats": "Chats",
@@ -1699,7 +1700,6 @@
"com_ui_export_mermaid_source": "Download source",
"com_ui_export_png": "Export as PNG",
"com_ui_export_retrieval": "Retrieval",
- "com_ui_export_share_link_active": "Export/Share, link active",
"com_ui_export_steer": "You (steered)",
"com_ui_export_summary": "Summary",
"com_ui_export_svg": "Export as SVG",
diff --git a/e2e/specs/mock/conversation-management.spec.ts b/e2e/specs/mock/conversation-management.spec.ts
index d410ff067e..0687f98d2f 100644
--- a/e2e/specs/mock/conversation-management.spec.ts
+++ b/e2e/specs/mock/conversation-management.spec.ts
@@ -123,9 +123,9 @@ test.describe('conversation management', () => {
await expect(menu).toBeFocused();
await page.keyboard.press('ArrowDown');
await expect(menu.getByRole('menuitem').first()).toBeFocused();
- const expectedOptions = ['Share', 'Pin'];
+ const expectedOptions = ['Pin'];
if (background) expectedOptions.push('Mark as unread');
- expectedOptions.push('Rename', 'Duplicate', 'Change project', 'Archive', 'Delete');
+ expectedOptions.push('Rename', 'Archive', 'Delete');
await expect(menu.getByRole('menuitem')).toHaveText(expectedOptions);
await test.info().attach('running-chat-menu', {
body: await page.screenshot(),
@@ -244,8 +244,8 @@ test.describe('conversation management', () => {
}) => {
await openMockChat(page);
await sendAndExpectReply(page, uniqueLabel('portal-context'));
- await conversationRow(page).click({ button: 'right' });
- await page.getByRole('menuitem', { name: 'Share', exact: true }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
+ await page.getByTestId('share-conversation-menu-item').click();
const dialog = page.getByRole('dialog', { name: 'Share link to chat' });
await expect(dialog).toBeVisible();
await dialog.getByRole('button', { name: 'Create a shared link' }).click();
diff --git a/e2e/specs/mock/export.spec.ts b/e2e/specs/mock/export.spec.ts
index bb6482fa48..10fe1f778a 100644
--- a/e2e/specs/mock/export.spec.ts
+++ b/e2e/specs/mock/export.spec.ts
@@ -51,7 +51,7 @@ async function startMockConversation(page: Page): Promise<string> {
}
async function openExportModal(page: Page): Promise<Locator> {
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByRole('menuitem', { name: 'Export' }).click();
const dialog = page.getByRole('dialog', { name: 'Export conversation' });
await expect(dialog).toBeVisible();
diff --git a/e2e/specs/mock/mcp-apps.spec.ts b/e2e/specs/mock/mcp-apps.spec.ts
index cffe051db5..c7e6768073 100644
--- a/e2e/specs/mock/mcp-apps.spec.ts
+++ b/e2e/specs/mock/mcp-apps.spec.ts
@@ -381,7 +381,7 @@ async function readEvents(page: Page): Promise<DebugEvent[]> {
}
async function createShare(page: Page, conversationId: string): Promise<SharePayload> {
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByTestId('share-conversation-menu-item').click();
const dialog = page.getByRole('dialog', { name: 'Share link to chat' });
await expect(dialog).toBeVisible();
diff --git a/e2e/specs/mock/private-text.spec.ts b/e2e/specs/mock/private-text.spec.ts
index 93ebe49382..bd4ca29003 100644
--- a/e2e/specs/mock/private-text.spec.ts
+++ b/e2e/specs/mock/private-text.spec.ts
@@ -112,7 +112,7 @@ test('owner sees original after reload while provider, sharing, and canonical re
expect(shared.text).toContain('EMAIL_1_');
const openExport = async () => {
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByRole('menuitem', { name: 'Export' }).click();
return page.getByRole('dialog', { name: 'Export conversation' });
};
@@ -283,7 +283,7 @@ test('an unchanged unprotected transcript still downloads a PNG screenshot', asy
'data-conversation-id',
conversationId!,
);
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByRole('menuitem', { name: 'Export' }).click();
const dialog = page.getByRole('dialog', { name: 'Export conversation' });
await dialog.getByTestId('dropdown-menu').click();
diff --git a/e2e/specs/mock/scenarios/shared-undocked-artifacts.spec.ts b/e2e/specs/mock/scenarios/shared-undocked-artifacts.spec.ts
index 5574977bc8..9b537737c1 100644
--- a/e2e/specs/mock/scenarios/shared-undocked-artifacts.spec.ts
+++ b/e2e/specs/mock/scenarios/shared-undocked-artifacts.spec.ts
@@ -49,7 +49,7 @@ test('a shared link can undock its artifacts pane @scenario:a-shared-link-can-un
throw new Error(`Could not parse conversation id from ${page.url()}`);
}
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByTestId('share-conversation-menu-item').click();
const shareDialog = page.getByRole('dialog', { name: 'Share link to chat' });
await expect(shareDialog).toBeVisible();
diff --git a/e2e/specs/mock/shared-links.spec.ts b/e2e/specs/mock/shared-links.spec.ts
index dea7695841..0a040fc103 100644
--- a/e2e/specs/mock/shared-links.spec.ts
+++ b/e2e/specs/mock/shared-links.spec.ts
@@ -168,7 +168,7 @@ test.describe('shared links', () => {
throw new Error(`Could not parse conversation id from ${conversationUrl.href}`);
}
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByTestId('share-conversation-menu-item').click();
const shareDialog = page.getByRole('dialog', { name: 'Share link to chat' });
await expect(shareDialog).toBeVisible();
@@ -239,7 +239,7 @@ test.describe('shared links', () => {
await expect(mockReply(page)).toHaveCount(1);
await page.goto(conversationUrl.pathname, { timeout: 10000 });
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByTestId('share-conversation-menu-item').click();
await expect(shareDialog).toBeVisible();
await expect(shareFilesSwitch).not.toBeChecked();
@@ -351,7 +351,7 @@ test.describe('shared links', () => {
}
await page.goto(conversationUrl.pathname, { timeout: 10000 });
- await page.getByRole('button', { name: 'Export/Share' }).click();
+ await page.getByRole('button', { name: 'Chat options' }).click();
await page.getByTestId('share-conversation-menu-item').click();
await expect(shareDialog).toBeVisible();
await shareDialog.getByRole('button', { name: 'Delete Link' }).click();