Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(sidebar): rename an agent in the shared dialog, writing its name (#20668)

Arvin Xu19478f199bbd
diff --git a/e2e/src/steps/home/sidebarAgent.steps.ts b/e2e/src/steps/home/sidebarAgent.steps.ts
index e3c525f8f55..95952d6ef35 100644
--- a/e2e/src/steps/home/sidebarAgent.steps.ts
+++ b/e2e/src/steps/home/sidebarAgent.steps.ts
@@ -25,10 +25,9 @@ async function inputNewName(
): Promise<void> {
await this.page.waitForTimeout(300);
- // Primary: find input inside EditingPopover (data-testid) or antd Popover
- const renameInput = this.page
- .locator('[data-testid="editing-popover"] input, .ant-popover input')
- .first();
+ // Rename opens the shared rename dialog, not an inline popover input.
+ const dialog = this.page.getByRole('dialog').first();
+ const renameInput = dialog.locator('input').first();
await renameInput.waitFor({ state: 'visible', timeout: 5000 });
await renameInput.click();
@@ -38,10 +37,7 @@ async function inputNewName(
if (pressEnter) {
await renameInput.press('Enter');
} else {
- // Click the save button (ActionIcon with Check icon) next to the input
- const saveButton = this.page
- .locator('[data-testid="editing-popover"] svg.lucide-check, .ant-popover svg.lucide-check')
- .first();
+ const saveButton = dialog.getByRole('button', { name: /^(save|保存)$/i });
try {
await saveButton.waitFor({ state: 'visible', timeout: 2000 });
await saveButton.click();
diff --git a/packages/types/src/agent/displayName.test.ts b/packages/types/src/agent/displayName.test.ts
index 9d69d646311..9e908c628a9 100644
--- a/packages/types/src/agent/displayName.test.ts
+++ b/packages/types/src/agent/displayName.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { agentDisplayName, agentSecondaryDisplayName } from './displayName';
+import { agentDisplayName, agentRenameField, agentSecondaryDisplayName } from './displayName';
describe('agentDisplayName', () => {
it('prefers the personal name over the role', () => {
@@ -76,3 +76,18 @@ describe('agentSecondaryDisplayName', () => {
expect(agentSecondaryDisplayName(null)).toBeUndefined();
});
});
+
+describe('agentRenameField', () => {
+ it('renames the personal name when the agent has one β€” that is what the label shows', () => {
+ expect(agentRenameField({ name: 'Alice', title: 'Health Assistant' })).toBe('name');
+ });
+
+ it('renames the title when there is no name to show', () => {
+ expect(agentRenameField({ name: null, title: 'Health Assistant' })).toBe('title');
+ expect(agentRenameField({ title: 'Health Assistant' })).toBe('title');
+ });
+
+ it('treats a blank name as absent, like the label does', () => {
+ expect(agentRenameField({ name: ' ', title: 'Health Assistant' })).toBe('title');
+ });
+});
diff --git a/packages/types/src/agent/displayName.ts b/packages/types/src/agent/displayName.ts
index b47f6d520f5..339cd400cbc 100644
--- a/packages/types/src/agent/displayName.ts
+++ b/packages/types/src/agent/displayName.ts
@@ -44,6 +44,17 @@ export function agentDisplayName(
return firstNonBlank(agent?.name, agent?.title, fallback);
}
+/**
+ * The field a rename writes: whichever one the resolved label is showing.
+ *
+ * A rename surface binds to {@link agentDisplayName}, so it must write back to
+ * the field that label came from β€” writing `title` under a named agent would
+ * silently rewrite its role and leave the visible name untouched. `name` wins
+ * whenever it is set, exactly like the label does; a blank name is absent.
+ */
+export const agentRenameField = (agent: AgentNameFields): 'name' | 'title' =>
+ firstNonBlank(agent?.name) ? 'name' : 'title';
+
/**
* Resolve the supporting label shown beside an agent's primary name: its role.
*
diff --git a/src/features/AgentViewAll/ItemActions.tsx b/src/features/AgentViewAll/ItemActions.tsx
index f51a03c0cbd..a1082ac9e3a 100644
--- a/src/features/AgentViewAll/ItemActions.tsx
+++ b/src/features/AgentViewAll/ItemActions.tsx
@@ -146,13 +146,13 @@ const AgentItemActions = memo<ItemActionsProps>(({ anchor, item, ...rest }) => {
}, [id, openCreateGroupModal, visibility]);
const getAgentMenu = useAgentDropdownMenu({
- anchor,
avatar: customAvatar,
backgroundColor: backgroundColor || undefined,
group: undefined,
id,
labels: item.labels,
labelsEnabled: true,
+ name: item.name,
openCreateGroupModal: handleOpenCreateGroupModal,
pinned: pinned ?? false,
slug,
diff --git a/src/features/EditingPopover/AgentContent.tsx b/src/features/EditingPopover/AgentContent.tsx
deleted file mode 100644
index b7e13e0321d..00000000000
--- a/src/features/EditingPopover/AgentContent.tsx
+++ /dev/null
@@ -1,178 +0,0 @@
-import { DEFAULT_AVATAR } from '@lobechat/const';
-import { Block, Flexbox, Icon, stopPropagation, Tooltip } from '@lobehub/ui';
-import { ActionIcon, Avatar, Input, toast } from '@lobehub/ui/base-ui';
-import { Check, PaletteIcon } from 'lucide-react';
-import { memo, useCallback, useEffect, useRef, useState } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import EmojiPicker from '@/components/EmojiPicker';
-import BackgroundSwatches from '@/features/AgentSetting/AgentMeta/BackgroundSwatches';
-import { useIsDark } from '@/hooks/useIsDark';
-import { useAgentStore } from '@/store/agent';
-import { agentSelectors } from '@/store/agent/selectors';
-import { useFileStore } from '@/store/file';
-import { useGlobalStore } from '@/store/global';
-import { globalGeneralSelectors } from '@/store/global/selectors';
-import { useHomeStore } from '@/store/home';
-
-const MAX_AVATAR_SIZE = 1024 * 1024;
-
-interface AgentContentProps {
- avatar?: string;
- id: string;
- onClose: () => void;
- title: string;
-}
-
-const AgentContent = memo<AgentContentProps>(({ id, title, avatar, onClose }) => {
- const { t } = useTranslation('setting');
- const locale = useGlobalStore(globalGeneralSelectors.currentLanguage);
- const isDarkMode = useIsDark();
- const uploadWithProgress = useFileStore((s) => s.uploadWithProgress);
-
- const meta = useAgentStore(agentSelectors.getAgentMetaById(id));
-
- const [newTitle, setNewTitle] = useState(title);
- const [newAvatar, setNewAvatar] = useState<string | null | undefined>(avatar);
- const [newBackgroundColor, setNewBackgroundColor] = useState(meta.backgroundColor);
- const [uploading, setUploading] = useState(false);
-
- const handleUpdate = useCallback(async () => {
- const titleChanged = newTitle && title !== newTitle;
- const avatarChanged = newAvatar !== (avatar || undefined);
- const backgroundColorChanged = newBackgroundColor !== meta.backgroundColor;
-
- if (titleChanged || avatarChanged || backgroundColorChanged) {
- const updates: { avatar?: string; backgroundColor?: string; title?: string } = {};
- if (titleChanged) updates.title = newTitle;
- if (avatarChanged) updates.avatar = newAvatar || undefined;
- if (backgroundColorChanged) updates.backgroundColor = newBackgroundColor;
-
- void useHomeStore
- .getState()
- .updateAgentMeta(id, updates)
- .catch(() => toast.error(t('operationFailed', { ns: 'common' })));
- }
- onClose();
- }, [
- newTitle,
- newAvatar,
- newBackgroundColor,
- title,
- avatar,
- meta.backgroundColor,
- id,
- onClose,
- t,
- ]);
-
- const handleAvatarUpload = useCallback(
- async (file: File) => {
- if (file.size > MAX_AVATAR_SIZE) {
- toast.error(t('settingAgent.avatar.sizeExceeded'));
- return;
- }
-
- setUploading(true);
- try {
- const result = await uploadWithProgress({ file });
- if (result?.url) {
- setNewAvatar(result.url);
- }
- } finally {
- setUploading(false);
- }
- },
- [uploadWithProgress, t],
- );
-
- const handleAvatarDelete = useCallback(() => {
- setNewAvatar(null);
- }, []);
-
- const inputRef = useRef<HTMLInputElement>(null);
- useEffect(() => {
- requestAnimationFrame(() => {
- requestAnimationFrame(() => {
- if (inputRef.current) {
- inputRef.current.focus();
- }
- });
- });
- }, []);
-
- return (
- <Flexbox horizontal align={'center'} gap={4} style={{ width: 320 }} onClick={stopPropagation}>
- <EmojiPicker
- allowUpload
- allowDelete={!!newAvatar}
- loading={uploading}
- locale={locale}
- shape={'square'}
- value={newAvatar ?? undefined}
- background={
- newBackgroundColor && newBackgroundColor !== 'rgba(0,0,0,0)'
- ? newBackgroundColor
- : undefined
- }
- customRender={(avatarValue) => (
- <Block
- clickable
- align={'center'}
- height={36}
- justify={'center'}
- variant={isDarkMode ? 'filled' : 'outlined'}
- width={36}
- onClick={stopPropagation}
- >
- <Avatar
- emojiScaleWithBackground
- avatar={avatarValue || DEFAULT_AVATAR}
- shape={'square'}
- size={32}
- background={
- newBackgroundColor && newBackgroundColor !== 'rgba(0,0,0,0)'
- ? newBackgroundColor
- : undefined
- }
- />
- </Block>
- )}
- customTabs={[
- {
- label: (
- <Tooltip title={t('settingAgent.backgroundColor.title')}>
- <Icon icon={PaletteIcon} size={{ size: 20, strokeWidth: 2.5 }} />
- </Tooltip>
- ),
- render: () => (
- <Flexbox padding={8} width={332}>
- <BackgroundSwatches
- gap={8}
- shape={'square'}
- size={38}
- value={newBackgroundColor}
- onChange={setNewBackgroundColor}
- />
- </Flexbox>
- ),
- value: 'background',
- },
- ]}
- onChange={setNewAvatar}
- onDelete={handleAvatarDelete}
- onUpload={handleAvatarUpload}
- />
- <Input
- defaultValue={title}
- ref={inputRef}
- style={{ flex: 1 }}
- onChange={(e) => setNewTitle(e.target.value)}
- onPressEnter={handleUpdate}
- />
- <ActionIcon icon={Check} size={'small'} onClick={handleUpdate} />
- </Flexbox>
- );
-});
-
-export default AgentContent;
diff --git a/src/features/EditingPopover/index.tsx b/src/features/EditingPopover/index.tsx
index b00c2b52afa..762a1ecfdda 100644
--- a/src/features/EditingPopover/index.tsx
+++ b/src/features/EditingPopover/index.tsx
@@ -2,7 +2,6 @@
import { PopoverPopup, PopoverPortal, PopoverPositioner, PopoverRoot } from '@lobehub/ui';
-import AgentContent from './AgentContent';
import GroupContent from './GroupContent';
import { useEditingPopoverStore } from './store';
@@ -20,14 +19,7 @@ const EditingPopover = () => {
<PopoverPortal>
<PopoverPositioner anchor={target?.anchor ?? document.body} placement="bottomLeft">
<PopoverPopup data-testid="editing-popover" style={{ padding: 4 }}>
- {target?.type === 'agent' ? (
- <AgentContent
- avatar={target.avatar}
- id={target.id}
- title={target.title}
- onClose={close}
- />
- ) : target ? (
+ {target ? (
<GroupContent
avatar={target.avatar}
backgroundColor={target.backgroundColor}
diff --git a/src/features/EditingPopover/store.ts b/src/features/EditingPopover/store.ts
index 5a8a6fc3796..47f140baf80 100644
--- a/src/features/EditingPopover/store.ts
+++ b/src/features/EditingPopover/store.ts
@@ -7,7 +7,7 @@ export interface EditingTarget {
id: string;
memberAvatars?: { avatar?: string; background?: string }[];
title: string;
- type: 'agent' | 'group' | 'agentGroup';
+ type: 'group' | 'agentGroup';
}
interface EditingPopoverState {
diff --git a/src/features/HomeSidebar/Body/Agent/List/AgentItem/index.tsx b/src/features/HomeSidebar/Body/Agent/List/AgentItem/index.tsx
index cd8d7a6ed61..7bca8b95322 100644
--- a/src/features/HomeSidebar/Body/Agent/List/AgentItem/index.tsx
+++ b/src/features/HomeSidebar/Body/Agent/List/AgentItem/index.tsx
@@ -4,7 +4,7 @@ import { ActionIcon, Spin } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar } from 'antd-style';
import { PinIcon } from 'lucide-react';
import { type CSSProperties, type DragEvent } from 'react';
-import { memo, useCallback, useMemo, useState } from 'react';
+import { memo, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import NavItem from '@/features/NavPanel/components/NavItem';
@@ -88,7 +88,6 @@ const AgentItem = memo<AgentItemProps>(({ item, style, className, onNavigate, se
const unreadCount = item.unreadCount ?? 0;
const { t } = useTranslation('chat');
const { openCreateGroupModal } = useAgentModal();
- const [anchor, setAnchor] = useState<HTMLElement | null>(null);
const openAgentInNewWindow = useGlobalStore((s) => s.openAgentInNewWindow);
const prefetchAgent = usePrefetchAgent();
@@ -181,11 +180,11 @@ const AgentItem = memo<AgentItemProps>(({ item, style, className, onNavigate, se
}, [isUpdating, isLoading, avatar, backgroundColor, displayTitle, unreadCount]);
const dropdownMenu = useAgentDropdownMenu({
- anchor,
avatar: typeof avatar === 'string' ? avatar : undefined,
backgroundColor: backgroundColor || undefined,
group: undefined, // TODO: pass group from parent if needed
id,
+ name: item.name,
openCreateGroupModal: handleOpenCreateGroupModal,
pinned: pinned ?? false,
slug,
@@ -197,7 +196,6 @@ const AgentItem = memo<AgentItemProps>(({ item, style, className, onNavigate, se
return (
<WorkspaceLink
aria-label={displayTitle}
- ref={setAnchor}
to={agentUrl}
onClick={onNavigate}
onMouseEnter={handleMouseEnter}
diff --git a/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.test.tsx b/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.test.tsx
index 89de4f494b6..b6eea19fcff 100644
--- a/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.test.tsx
+++ b/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.test.tsx
@@ -21,9 +21,11 @@ const mocks = vi.hoisted(() => ({
removeAgent: vi.fn(),
toggleAgentLabel: vi.fn(),
updateAgentGroup: vi.fn(),
+ updateAgentMeta: vi.fn(),
},
navigate: vi.fn(),
openAgentInNewWindow: vi.fn(),
+ openRenameModal: vi.fn(),
setSidebarItemVisible: vi.fn(),
transferMenuItems: null as null | { key: string; label: string }[],
}));
@@ -55,7 +57,7 @@ vi.mock('@/business/client/hooks/useAgentTransferMenuItem', () => ({
useAgentTransferMenuItem: () => mocks.transferMenuItems,
}));
-vi.mock('@/features/EditingPopover/store', () => ({ openEditingPopover: vi.fn() }));
+vi.mock('@/components/RenameModal', () => ({ openRenameModal: mocks.openRenameModal }));
vi.mock('@/features/ResourcePermission/useResourceAccess', () => ({
useResourceAccess: () => ({
@@ -138,6 +140,17 @@ const getMenuLayout = (items: ReturnType<ReturnType<typeof useAgentDropdownMenu>
return [];
});
+const getMenuItem = (
+ items: ReturnType<ReturnType<typeof useAgentDropdownMenu>>,
+ key: string,
+): { onClick: (info: { domEvent: { stopPropagation: () => void } }) => void } => {
+ const found = (items ?? []).find(
+ (item) => item && typeof item === 'object' && 'key' in item && item.key === key,
+ ) as { onClick: (info: { domEvent: { stopPropagation: () => void } }) => void } | undefined;
+ if (!found) throw new Error(`Expected ${key} menu item`);
+ return found;
+};
+
describe('useAgentDropdownMenu', () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -153,7 +166,6 @@ describe('useAgentDropdownMenu', () => {
it('keeps non-config actions available to a use-only Workspace member', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -176,7 +188,6 @@ describe('useAgentDropdownMenu', () => {
it('shows the Labels submenu only where it is enabled (the agents list page)', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
labelsEnabled: true,
@@ -199,7 +210,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
labelsEnabled: true,
@@ -221,7 +231,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
labelsEnabled: true,
@@ -242,7 +251,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -259,7 +267,6 @@ describe('useAgentDropdownMenu', () => {
it('hides an Agent through the caller sidebar preference', async () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -296,7 +303,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -324,7 +330,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -346,7 +351,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -379,7 +383,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -399,7 +402,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -427,7 +429,6 @@ describe('useAgentDropdownMenu', () => {
const { result } = renderHook(() =>
useAgentDropdownMenu({
- anchor: null,
group: undefined,
id: 'agent-1',
openCreateGroupModal: vi.fn(),
@@ -440,4 +441,62 @@ describe('useAgentDropdownMenu', () => {
expect(getMenuKeys(result.current())).not.toContain('permission');
});
+ it('renames through the shared modal, writing the field the row label came from', async () => {
+ mocks.canEditResource = true;
+
+ const { result } = renderHook(() =>
+ useAgentDropdownMenu({
+ group: undefined,
+ id: 'agent-1',
+ name: 'Claude Code',
+ openCreateGroupModal: vi.fn(),
+ pinned: false,
+ title: 'Claude Code',
+ userId: 'member-1',
+ visibility: 'public',
+ }),
+ );
+
+ getMenuItem(result.current(), 'rename').onClick({ domEvent: { stopPropagation: vi.fn() } });
+
+ expect(mocks.openRenameModal).toHaveBeenCalledOnce();
+ const { defaultValue, onSave } = mocks.openRenameModal.mock.calls[0][0] as {
+ defaultValue: string;
+ onSave: (next: string) => Promise<void>;
+ };
+ expect(defaultValue).toBe('Claude Code');
+
+ await onSave('Claude Code 2');
+
+ // The row shows `name`, so that is what a rename writes β€” never the role.
+ expect(mocks.home.updateAgentMeta).toHaveBeenCalledWith('agent-1', { name: 'Claude Code 2' });
+ });
+
+ it('renames the role only when there is no name to show', async () => {
+ mocks.canEditResource = true;
+
+ const { result } = renderHook(() =>
+ useAgentDropdownMenu({
+ group: undefined,
+ id: 'agent-1',
+ name: null,
+ openCreateGroupModal: vi.fn(),
+ pinned: false,
+ title: 'Health Assistant',
+ userId: 'member-1',
+ visibility: 'public',
+ }),
+ );
+
+ getMenuItem(result.current(), 'rename').onClick({ domEvent: { stopPropagation: vi.fn() } });
+
+ const { onSave } = mocks.openRenameModal.mock.calls[0][0] as {
+ onSave: (next: string) => Promise<void>;
+ };
+ await onSave('Care Assistant');
+
+ expect(mocks.home.updateAgentMeta).toHaveBeenCalledWith('agent-1', {
+ title: 'Care Assistant',
+ });
+ });
});
diff --git a/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.tsx b/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.tsx
index 64e5d947bc3..7154422d030 100644
--- a/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.tsx
+++ b/src/features/HomeSidebar/Body/Agent/List/AgentItem/useDropdownMenu.tsx
@@ -1,5 +1,6 @@
import { BUILTIN_AGENT_SLUGS } from '@lobechat/builtin-agents';
import {
+ agentRenameField,
SessionDefaultGroup,
type SidebarAgentLabel,
type SidebarVisibility,
@@ -30,7 +31,7 @@ import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
import { useAgentTransferMenuItem } from '@/business/client/hooks/useAgentTransferMenuItem';
import { useAgentTransferToMemberMenuItem } from '@/business/client/hooks/useAgentTransferToMemberMenuItem';
-import { openEditingPopover } from '@/features/EditingPopover/store';
+import { openRenameModal } from '@/components/RenameModal';
import { useOptionalAgentModal } from '@/features/HomeSidebar/Body/Agent/ModalProvider';
import { useResourceAccess } from '@/features/ResourcePermission/useResourceAccess';
import VisibilityConfirmContent from '@/features/VisibilityConfirmContent';
@@ -52,7 +53,6 @@ import { getAgentPublishErrorKey } from './agentMenuVisibility';
const BUILTIN_SLUGS = new Set<string>(Object.values(BUILTIN_AGENT_SLUGS));
interface UseAgentDropdownMenuParams {
- anchor: HTMLElement | null;
avatar?: string;
backgroundColor?: string;
group: string | undefined;
@@ -65,6 +65,8 @@ interface UseAgentDropdownMenuParams {
* surfaces on the agents list page (ItemActions), where labels render.
*/
labelsEnabled?: boolean;
+ /** The agent's personal name β€” the row label is this when set, the role otherwise. */
+ name?: string | null;
openCreateGroupModal: () => void;
pinned: boolean;
slug?: string | null;
@@ -74,13 +76,13 @@ interface UseAgentDropdownMenuParams {
}
export const useAgentDropdownMenu = ({
- anchor,
avatar,
backgroundColor,
group,
id,
labels,
labelsEnabled,
+ name,
openCreateGroupModal,
pinned,
slug,
@@ -103,9 +105,21 @@ export const useAgentDropdownMenu = ({
isEqual,
);
const refreshAgentList = useHomeStore((s) => s.refreshAgentList);
- const [pinAgent, duplicateAgent, updateAgentGroup, removeAgent, toggleAgentLabel] = useHomeStore(
- (s) => [s.pinAgent, s.duplicateAgent, s.updateAgentGroup, s.removeAgent, s.toggleAgentLabel],
- );
+ const [
+ pinAgent,
+ duplicateAgent,
+ updateAgentGroup,
+ removeAgent,
+ toggleAgentLabel,
+ updateAgentMeta,
+ ] = useHomeStore((s) => [
+ s.pinAgent,
+ s.duplicateAgent,
+ s.updateAgentGroup,
+ s.removeAgent,
+ s.toggleAgentLabel,
+ s.updateAgentMeta,
+ ]);
// Label picker: the shared registry (archived labels only stay listed while
// still applied to this agent, so they can be unchecked but not re-added).
@@ -237,9 +251,22 @@ export const useAgentDropdownMenu = ({
label: t('rename', { ns: 'common' }),
onClick: (info: any) => {
info.domEvent?.stopPropagation();
- if (anchor) {
- openEditingPopover({ anchor, avatar, id, title, type: 'agent' });
- }
+ openRenameModal({
+ defaultValue: title,
+ onSave: async (newName) => {
+ try {
+ // The row shows `name` when the agent has one and the role
+ // otherwise; the rename writes back to that same field.
+ await updateAgentMeta(id, { [agentRenameField({ name })]: newName });
+ } catch (error) {
+ console.error('[agent:rename]', error);
+ toast.error(t('operationFailed', { ns: 'common' }));
+ // The shared modal closes on a resolved save; re-throw so the
+ // typed name survives for a retry.
+ throw error;
+ }
+ },
+ });
},
sfSymbol: 'pencil',
},
@@ -560,7 +587,6 @@ export const useAgentDropdownMenu = ({
] as MenuProps['items'],
[
activeWorkspaceId,
- anchor,
canCreate,
canConfigure,
canEdit,
@@ -571,11 +597,13 @@ export const useAgentDropdownMenu = ({
id,
avatar,
title,
+ name,
pinAgent,
duplicateAgent,
updateAgentGroup,
removeAgent,
toggleAgentLabel,
+ updateAgentMeta,
pickerLabels,
assignedLabelIds,
canCreateLabel,
diff --git a/src/features/Portal/AgentDetail/useMoreMenu.test.ts b/src/features/Portal/AgentDetail/useMoreMenu.test.ts
deleted file mode 100644
index 7c2ef0e6dcc..00000000000
--- a/src/features/Portal/AgentDetail/useMoreMenu.test.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { describe, expect, it, vi } from 'vitest';
-
-import { agentRenameField } from './useMoreMenu';
-
-vi.mock('@/components/RenameModal', () => ({ openRenameModal: vi.fn() }));
-
-describe('agentRenameField', () => {
- it('renames the personal name when the agent has one β€” that is what the header shows', () => {
- expect(agentRenameField({ name: 'Alice', title: 'Health Assistant' })).toBe('name');
- });
-
- it('renames the title when there is no name to show', () => {
- expect(agentRenameField({ name: null, title: 'Health Assistant' })).toBe('title');
- expect(agentRenameField({ title: 'Health Assistant' })).toBe('title');
- });
-
- it('treats a blank name as absent, like the label does', () => {
- expect(agentRenameField({ name: ' ', title: 'Health Assistant' })).toBe('title');
- });
-});
diff --git a/src/features/Portal/AgentDetail/useMoreMenu.ts b/src/features/Portal/AgentDetail/useMoreMenu.ts
index a8b0bb1e057..604aad64a3b 100644
--- a/src/features/Portal/AgentDetail/useMoreMenu.ts
+++ b/src/features/Portal/AgentDetail/useMoreMenu.ts
@@ -1,5 +1,5 @@
import { AGENT_CHAT_URL } from '@lobechat/const';
-import { agentDisplayName, type AgentNameFields } from '@lobechat/types';
+import { agentDisplayName, agentRenameField } from '@lobechat/types';
import { openRenameModal } from '@/components/RenameModal';
import { type PortalMoreMenuConfig } from '@/features/Portal/components/PortalMoreMenu/types';
@@ -11,14 +11,6 @@ import { chatPortalSelectors } from '@/store/chat/selectors';
import { usePortalShareUrl } from '../components/PortalMoreMenu/shareUrl';
-/**
- * The field a rename writes: whichever one the header is showing. `name` wins
- * the label whenever it is set, so renaming `title` under a named agent would
- * save without visibly changing anything.
- */
-export const agentRenameField = (meta: AgentNameFields): 'name' | 'title' =>
- meta.name?.trim() ? 'name' : 'title';
-
export const useAgentDetailMoreMenu = (): PortalMoreMenuConfig | undefined => {
const agentId = useChatStore(chatPortalSelectors.agentDetailId);
const meta = useAgentStore(agentSelectors.getAgentMetaById(agentId || ''));