🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(agent): scope heterogeneous default names to shared workspaces (#18770)
AmAzing-fe493ef8e6b5
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 8f84a9264a1..4bdd8bb4c97 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -673,7 +673,6 @@"heteroAgent.codexQuota.tooltip": "View Codex quota","heteroAgent.codexQuota.totalEarned_one": "{{count}} earned in total","heteroAgent.codexQuota.totalEarned_other": "{{count}} earned in total",- "heteroAgent.defaultName": "{{owner}}'s {{product}}","heteroAgent.executionTarget.auto": "Auto","heteroAgent.executionTarget.autoDesc": "Use an online device automatically, picking one when several are available","heteroAgent.executionTarget.downloadDesktop": "Get Desktop App",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex dd43bacd399..9f0b64222f4 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -673,7 +673,6 @@"heteroAgent.codexQuota.tooltip": "查看 Codex 额度","heteroAgent.codexQuota.totalEarned_one": "累计获得 {{count}} 次","heteroAgent.codexQuota.totalEarned_other": "累计获得 {{count}} 次",- "heteroAgent.defaultName": "{{owner}} 的 {{product}}","heteroAgent.executionTarget.auto": "自动","heteroAgent.executionTarget.autoDesc": "自动使用在线设备,有多台时择一使用","heteroAgent.executionTarget.downloadDesktop": "下载桌面端",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 7a787522c0b..0c342301ab0 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -329,7 +329,6 @@ export default {'groupWizard.searchTemplates': 'Search templates...','groupWizard.title': 'Create Group','groupWizard.useTemplate': 'Use Template',- 'heteroAgent.defaultName': "{{owner}}'s {{product}}",'heteroAgent.fullAccess.label': 'Full access','heteroAgent.fullAccess.tooltip':'The local coding agent runs with full read/write access to the working directory. Switching permission modes is not available yet.',diff --git a/src/features/ConnectAgent/index.tsx b/src/features/ConnectAgent/index.tsxindex 7f65d9740d9..5a02d414d94 100644--- a/src/features/ConnectAgent/index.tsx+++ b/src/features/ConnectAgent/index.tsx@@ -502,12 +502,13 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(if (!single) return;const profile = isRemoteHeterogeneousType(single.type) ? profiles[single.type] : undefined;const productTitle = profile?.title ?? single.title;- // Prefill with the same "{owner}'s {product}" default that createAgent- // seeds, so the input shows the name the agent would actually get.- setName(heteroAgentDefaultName(productTitle) ?? productTitle);+ setName(+ heteroAgentDefaultName({ productTitle, visibility, workspaceId: activeWorkspaceId }) ??+ productTitle,+ );setDescription(profile?.description ?? '');setStep(2);- }, [profiles, single]);+ }, [activeWorkspaceId, profiles, single, visibility]);const buildCreateParams = useCallback((provider: ConnectableProvider, overrides?: { description?: string; name?: string }) => {@@ -549,7 +550,11 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(// screen shows the same label the sidebar will.title:params.config.name?.trim() ||- heteroAgentDefaultName(params.config.title) ||+ heteroAgentDefaultName({+ productTitle: params.config.title,+ visibility,+ workspaceId: activeWorkspaceId,+ }) ||agentDisplayName(params.config, provider.title),version: scanState.agents?.[provider.type]?.version,} satisfies CreatedAgent;@@ -569,6 +574,7 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(}},[+ activeWorkspaceId,buildCreateParams,onTitleChange,refreshAgentList,@@ -579,6 +585,7 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(t,target,targetLabel,+ visibility,],);diff --git a/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.test.tsx b/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.test.tsxindex 8b3453389e7..17614010304 100644--- a/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.test.tsx+++ b/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.test.tsx@@ -14,6 +14,7 @@ const mocks = vi.hoisted(() => {agentMap: {} as Record<string,{+ agencyConfig?: { heterogeneousProvider?: { type: string } };avatar?: string | null;backgroundColor?: string;name?: string;@@ -267,6 +268,79 @@ describe('AgentHeader', () => {expect(view.container.textContent?.match(/Lobe AI/g)).toHaveLength(1);});+ it('shows an identical heterogeneous product name and role only once', () => {+ mocks.permissionState.allowed = true;+ mocks.agentStoreState.agentMap = {+ 'agent-a': {+ agencyConfig: { heterogeneousProvider: { type: 'grok-build' } },+ name: 'Grok Build',+ slug: 'why-hard-industry',+ title: 'Grok Build',+ },+ };+ const view = render(<AgentHeader />);++ expect(view.container.textContent?.match(/Grok Build/g)).toHaveLength(1);+ expect(view.container.textContent).toContain('@why-hard-industry');+ expect(view.container.textContent).not.toContain('settingAgent.personalName.unnamed');+ expect(view.container.textContent).toContain('settingAgent.identity.edit');+ });++ it('leaves an ordinary identical name and role in both slots', () => {+ mocks.agentStoreState.agentMap = {+ 'agent-a': { name: 'Grok Build', title: 'Grok Build' },+ };+ const view = render(<AgentHeader />);++ expect(view.container.textContent?.match(/Grok Build/g)).toHaveLength(2);+ });++ it('suppresses the role included in an owner-qualified shared heterogeneous name', () => {+ mocks.agentStoreState.agentMap = {+ 'agent-a': {+ agencyConfig: { heterogeneousProvider: { type: 'grok-build' } },+ name: 'Max’s Grok Build',+ slug: 'shared-builder',+ title: 'Grok Build',+ },+ };+ const view = render(<AgentHeader />);++ expect(view.container.textContent).toContain('Max’s Grok Build');+ expect(view.container.textContent?.match(/Grok Build/g)).toHaveLength(1);+ expect(view.container.textContent).toContain('@shared-builder');+ expect(view.container.textContent).not.toContain('·');+ });++ it('retains the role for a custom-named heterogeneous agent', () => {+ mocks.agentStoreState.agentMap = {+ 'agent-a': {+ agencyConfig: { heterogeneousProvider: { type: 'grok-build' } },+ name: 'Release Builder',+ title: 'Grok Build',+ },+ };+ const view = render(<AgentHeader />);++ expect(view.container.textContent).toContain('Release Builder');+ expect(view.container.textContent).toContain('Grok Build');+ });++ it('retains the unset role slot for a heterogeneous agent without a role', () => {+ mocks.agentStoreState.agentMap = {+ 'agent-a': {+ agencyConfig: { heterogeneousProvider: { type: 'grok-build' } },+ name: 'Release Builder',+ slug: 'release-builder',+ },+ };+ const view = render(<AgentHeader />);++ expect(view.container.textContent).toContain('settingAgent.role.unset');+ expect(view.container.textContent).toContain('·');+ expect(view.container.textContent).toContain('@release-builder');+ });+// With no name there is nothing to headline, so the slot carries the prompt// that fixes it — not a placeholder dressed up as a name.it('gives the headline slot to the naming prompt while unnamed', () => {diff --git a/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsx b/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsxindex 1f1008fe6aa..008c3276f09 100644--- a/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsx+++ b/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsx@@ -1,5 +1,6 @@'use client';+import { agentSecondaryDisplayName } from '@lobechat/types';import { Flexbox, Tooltip } from '@lobehub/ui';import { ActionIcon, Button, Text } from '@lobehub/ui/base-ui';import { cssVar } from 'antd-style';@@ -29,9 +30,16 @@ const AgentHeader = memo(() => {const slug = useAgentStore(agentSelectors.getAgentSlugById(agentId));const updateMetaById = useAgentStore((s) => s.updateAgentMetaById);const { autoName, naming } = useAutoName(agentId);+ const personalName = meta.name?.trim();+ const role = meta.title?.trim();+ const suppressDuplicateRole =+ !!config?.agencyConfig?.heterogeneousProvider &&+ !!personalName &&+ !!role &&+ agentSecondaryDisplayName({ name: personalName, title: role }) === undefined;// Without edit rights there is nothing to prompt for, so a nameless agent// falls back to the plain label rather than showing an action nobody can take.- const showNamePrompt = !meta.name?.trim() && canEdit;+ const showNamePrompt = !personalName && canEdit;return (<Flexbox@@ -68,14 +76,10 @@ const AgentHeader = memo(() => {form modal; inline inputs crowded the header and left no room for aper-field label or error. */}<Flexbox flex={1} gap={8} paddingInline={24} style={{ minWidth: 0 }}>- {/* The headline is the NAME slot. It does not borrow the role the way- list surfaces do — the role has its own line right below, and falling- back would print it twice (an agent titled "Lobe AI" read- "Lobe AI / Lobe AI · @inbox").-- With no name there is nothing to headline, so the slot carries the- one thing that can fix it instead of a placeholder pretending to be a- name. The edit affordance stays hidden until then: naming it IS the+ {/* The headline is the NAME slot. With no name there is nothing to+ headline, so it carries the action that can fix this instead of a+ placeholder pretending to be a name. The edit affordance stays hidden+ until then: naming it IS thenext step, and offering the full identity form alongside would splitattention between two ways to do the same thing. */}{showNamePrompt ? (@@ -98,7 +102,7 @@ const AgentHeader = memo(() => {) : (<Flexbox horizontal align={'center'} gap={8} style={{ minWidth: 0 }}><Text ellipsis style={{ fontSize: 36, fontWeight: 600 }}>- {meta.name?.trim() || t('settingAgent.identity.untitled', { ns: 'setting' })}+ {personalName || t('settingAgent.identity.untitled', { ns: 'setting' })}</Text>{canEdit ? (<ActionIcon@@ -115,19 +119,21 @@ const AgentHeader = memo(() => {maps to the TERTIARY step — too faint for the line that carries theagent's role. Set the secondary colour explicitly, and leave onlythe decorative `@` and the separator at tertiary. */}- {/* The role always occupies its slot. An agent with no role gets a- stated placeholder rather than a gap — otherwise the line silently- collapses to a bare slug and the missing role is indistinguishable- from a role that was never meant to be there. */}- <Text- ellipsis- style={{- color: meta.title?.trim() ? cssVar.colorTextSecondary : cssVar.colorTextTertiary,- }}- >- {meta.title?.trim() || t('settingAgent.role.unset', { ns: 'setting' })}- </Text>- {slug ? <Text style={{ color: cssVar.colorTextTertiary }}>·</Text> : null}+ {/* A heterogeneous product name that already includes its role is+ shown once. Genuinely custom names retain the role underneath. */}+ {!suppressDuplicateRole ? (+ <Text+ ellipsis+ style={{+ color: role ? cssVar.colorTextSecondary : cssVar.colorTextTertiary,+ }}+ >+ {role || t('settingAgent.role.unset', { ns: 'setting' })}+ </Text>+ ) : null}+ {slug && !suppressDuplicateRole ? (+ <Text style={{ color: cssVar.colorTextTertiary }}>·</Text>+ ) : null}{/* The tooltip only renders when a slug exists, so it can always namethe real url rather than a `<slug>` the reader has to substitute. */}{slug ? (diff --git a/src/store/agent/slices/agent/action.test.ts b/src/store/agent/slices/agent/action.test.tsindex 6545ef2a2b5..4e2b5ab385c 100644--- a/src/store/agent/slices/agent/action.test.ts+++ b/src/store/agent/slices/agent/action.test.ts@@ -3,6 +3,7 @@ import { toast } from '@lobehub/ui/base-ui';import { act, renderHook, waitFor } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import * as activeWorkspaceModule from '@/business/client/hooks/useActiveWorkspaceId';import { setScopedMutate } from '@/libs/swr';import { agentConfigKeys } from '@/libs/swr/keys';import { agentService } from '@/services/agent';@@ -211,7 +212,7 @@ describe('AgentSlice Actions', () => {}});- it('names a heterogeneous agent after its owner instead of a personal name', async () => {+ it('uses the product title as a personal heterogeneous agent name', async () => {vi.mocked(agentService.createAgent).mockResolvedValue({ agentId: 'agent-2' });const userState = useUserStore.getState();useUserStore.setState({@@ -230,16 +231,64 @@ describe('AgentSlice Actions', () => {});});- // Test i18n serves the default (English) chat resources.expect(vi.mocked(agentService.createAgent).mock.calls[0][0].config?.name).toBe(- "Max's Claude Code",+ 'Claude Code',);} finally {useUserStore.setState({ isSignedIn: userState.isSignedIn, user: userState.user });}});- it('leaves a heterogeneous agent unnamed for an anonymous owner', async () => {+ it('uses a stable English owner-qualified name for a shared workspace agent', async () => {+ vi.mocked(agentService.createAgent).mockResolvedValue({ agentId: 'agent-2' });+ vi.spyOn(activeWorkspaceModule, 'getActiveWorkspaceId').mockReturnValue('workspace-1');+ const userState = useUserStore.getState();+ const status = useGlobalStore.getState().status;+ useUserStore.setState({+ isSignedIn: true,+ user: { fullName: 'Max', id: 'user-1' } as any,+ });+ useGlobalStore.setState({ status: { ...status, language: 'zh-CN' } });+ const { result } = renderHook(() => useAgentStore());++ try {+ await act(async () => {+ await result.current.createAgent({+ config: {+ agencyConfig: { heterogeneousProvider: { command: 'claude', type: 'claude-code' } },+ title: 'Claude Code',+ },+ });+ });++ expect(vi.mocked(agentService.createAgent).mock.calls[0][0].config?.name).toBe(+ 'Max’s Claude Code',+ );+ } finally {+ useUserStore.setState({ isSignedIn: userState.isSignedIn, user: userState.user });+ useGlobalStore.setState({ status });+ }+ });++ it('uses the product title as a workspace-private heterogeneous agent name', async () => {+ vi.mocked(agentService.createAgent).mockResolvedValue({ agentId: 'agent-2' });+ vi.spyOn(activeWorkspaceModule, 'getActiveWorkspaceId').mockReturnValue('workspace-1');+ const { result } = renderHook(() => useAgentStore());++ await act(async () => {+ await result.current.createAgent({+ config: {+ agencyConfig: { heterogeneousProvider: { command: 'claude', type: 'claude-code' } },+ title: 'Claude Code',+ },+ visibility: 'private',+ });+ });++ expect(vi.mocked(agentService.createAgent).mock.calls[0][0].config?.name).toBe('Claude Code');+ });++ it('uses the product title as a personal heterogeneous agent name for an anonymous owner', async () => {vi.mocked(agentService.createAgent).mockResolvedValue({ agentId: 'agent-2' });const userState = useUserStore.getState();useUserStore.setState({ isSignedIn: false, user: undefined });@@ -255,7 +304,9 @@ describe('AgentSlice Actions', () => {});});- expect(vi.mocked(agentService.createAgent).mock.calls[0][0].config?.name).toBeUndefined();+ expect(vi.mocked(agentService.createAgent).mock.calls[0][0].config?.name).toBe(+ 'Claude Code',+ );} finally {useUserStore.setState({ isSignedIn: userState.isSignedIn, user: userState.user });}diff --git a/src/store/agent/slices/agent/action.ts b/src/store/agent/slices/agent/action.tsindex 494ceb02e83..0d576aca6a7 100644--- a/src/store/agent/slices/agent/action.ts+++ b/src/store/agent/slices/agent/action.ts@@ -14,6 +14,7 @@ import { produce } from 'immer';import type { SWRResponse } from 'swr';import type { PartialDeep } from 'type-fest';+import { getActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';import { MESSAGE_CANCEL_FLAT } from '@/const/message';import { mutate, useClientDataSWR, useClientDataSWRWithSync } from '@/libs/swr';import { agentConfigKeys } from '@/libs/swr/keys';@@ -160,9 +161,9 @@ export class AgentSliceActionImpl {// resolves on the client (`auto` follows the browser). A caller that already// carries a name — e.g. a market agent — keeps it.//- // A heterogeneous agent never draws a personal name: it is the user's- // external tool, not one of our own agents, so its default reads as whose- // tool it is — "{owner}'s {product}" (e.g. "Max 的 Claude Code").+ // A heterogeneous agent never draws a random personal name. In personal or+ // workspace-private scope its name is the product title; a shared workspace+ // agent adds the creator so members can distinguish identical tools.const heteroProvider = params.config?.agencyConfig?.heterogeneousProvider;const locale = globalGeneralSelectors.currentLanguage(useGlobalStore.getState());const config = {@@ -170,9 +171,11 @@ export class AgentSliceActionImpl {name:params.config?.name ||(heteroProvider- ? heteroAgentDefaultName(- params.config?.title || getHeterogeneousTypeLabel(heteroProvider.type),- )+ ? heteroAgentDefaultName({+ productTitle: params.config?.title || getHeterogeneousTypeLabel(heteroProvider.type),+ visibility: params.visibility,+ workspaceId: getActiveWorkspaceId(),+ }): randomAgentName(locale)),};diff --git a/src/store/agent/utils/heteroAgentDefaultName.ts b/src/store/agent/utils/heteroAgentDefaultName.tsindex 6b866debcc2..8e7008bd75b 100644--- a/src/store/agent/utils/heteroAgentDefaultName.ts+++ b/src/store/agent/utils/heteroAgentDefaultName.ts@@ -1,25 +1,34 @@-import { t } from 'i18next';-import { getUserStoreState } from '@/store/user';import { authSelectors, userProfileSelectors } from '@/store/user/selectors';+interface HeteroAgentDefaultNameOptions {+ productTitle?: string | null;+ visibility?: 'private' | 'public';+ workspaceId?: string | null;+}+/**- * Default display name for a heterogeneous (external CLI / platform) agent:- * "{owner}'s {product}" (e.g. "Max 的 Claude Code"). Such an agent is the- * user's external tool rather than one of our own agents, so its default label- * says whose tool it is instead of drawing a personal name.+ * Default display name for a heterogeneous agent. Personal and+ * workspace-private agents use their product title. Shared agents include the+ * creator to distinguish otherwise identical tools in a multilingual workspace.*- * Returns undefined when the owner has no usable name (anonymous session), so- * the product title stays the primary label.+ * The possessive is deliberately stable English rather than creation-locale+ * copy because the persisted name is shown to every workspace member.*/-export const heteroAgentDefaultName = (productTitle?: string | null): string | undefined => {+export const heteroAgentDefaultName = ({+ productTitle,+ visibility,+ workspaceId,+}: HeteroAgentDefaultNameOptions): string | undefined => {+ const product = productTitle?.trim();+ if (!product) return undefined;++ if (!workspaceId || visibility === 'private') return product;+const userStore = getUserStoreState();const owner = authSelectors.isLogin(userStore)? userProfileSelectors.nickName(userStore)?.trim(): undefined;- const product = productTitle?.trim();-- if (!owner || !product) return undefined;- return t('heteroAgent.defaultName', { ns: 'chat', owner, product });+ return owner ? `${owner}’s ${product}` : product;};