🤯 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): hide community publish for heterogeneous agents (#15166)
AmAzing-5f6f0530391a
diff --git a/src/routes/(main)/agent/profile/features/Header/AgentPublishButton/index.tsx b/src/routes/(main)/agent/profile/features/Header/AgentPublishButton/index.tsxdeleted file mode 100644index 1926ddbc4e2..00000000000--- a/src/routes/(main)/agent/profile/features/Header/AgentPublishButton/index.tsx+++ /dev/null@@ -1,45 +0,0 @@-import isEqual from 'fast-deep-equal';-import { memo, useCallback, useState } from 'react';--import { useAgentStore } from '@/store/agent';-import { agentSelectors } from '@/store/agent/selectors';--import PublishButton from './PublishButton';-import PublishResultModal from './PublishResultModal';--/**- * Agent Publish Button Component- *- * Simplified version - backend now handles ownership check automatically.- * The action type (submit vs upload) is determined by backend based on:- * 1. Whether the identifier exists- * 2. Whether the current user is the owner- */-const AgentPublishButton = memo(() => {- const meta = useAgentStore(agentSelectors.currentAgentMeta, isEqual);-- const [showResultModal, setShowResultModal] = useState(false);- const [publishedIdentifier, setPublishedIdentifier] = useState<string>();-- const handlePublishSuccess = useCallback((identifier: string) => {- setPublishedIdentifier(identifier);- setShowResultModal(true);- }, []);-- // Determine action based on whether we have an existing marketIdentifier- // Backend will verify ownership and decide to create new or update- const action = meta?.marketIdentifier ? 'upload' : 'submit';-- return (- <>- <PublishButton action={action} onPublishSuccess={handlePublishSuccess} />- <PublishResultModal- identifier={publishedIdentifier}- open={showResultModal}- onCancel={() => setShowResultModal(false)}- />- </>- );-});--export default AgentPublishButton;diff --git a/src/routes/(main)/agent/profile/features/Header/index.test.tsx b/src/routes/(main)/agent/profile/features/Header/index.test.tsxnew file mode 100644index 00000000000..7f5f144d820--- /dev/null+++ b/src/routes/(main)/agent/profile/features/Header/index.test.tsx@@ -0,0 +1,214 @@+import { render, screen } from '@testing-library/react';+import type { PropsWithChildren, ReactNode } from 'react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import Header from './index';++const mocks = vi.hoisted(() => ({+ agentState: {+ activeAgentId: 'agent-1',+ canCurrentAgentPublishToCommunity: true,+ isCurrentAgentHeterogeneous: false,+ meta: {+ title: 'Test Agent',+ },+ systemRole: 'You are helpful.',+ },+ globalState: {+ isStatusInit: true,+ showAgentBuilderPanel: false,+ toggleAgentBuilderPanel: vi.fn(),+ },+ homeState: {+ removeAgent: vi.fn(),+ },+ marketAuth: {+ isAuthenticated: true,+ isLoading: false,+ signIn: vi.fn(),+ },+ marketPublish: {+ checkOwnership: vi.fn(),+ isPublishing: false,+ publish: vi.fn(),+ },+ navigate: vi.fn(),+ versionReviewStatus: {+ isUnderReview: false,+ },+}));++vi.mock('@lobehub/ui', () => ({+ ActionIcon: () => <button aria-label="more" type="button" />,+ DropdownMenu: ({+ children,+ items = [],+ }: PropsWithChildren<{+ items?: Array<{ key?: string; label?: ReactNode; type?: string }>;+ }>) => (+ <div>+ {children}+ <div data-testid="agent-profile-menu">+ {items+ .filter((item) => item.type !== 'divider')+ .map((item) => (+ <button key={item.key} type="button">+ {item.label}+ </button>+ ))}+ </div>+ </div>+ ),+ Flexbox: ({ children }: PropsWithChildren) => <div>{children}</div>,+ Icon: () => <span />,+}));++vi.mock('@lobehub/ui/icons', () => ({+ ShapesUploadIcon: () => null,+}));++vi.mock('antd', () => ({+ App: {+ useApp: () => ({+ modal: {+ confirm: vi.fn(),+ },+ }),+ },+ Modal: {+ confirm: vi.fn(),+ },+}));++vi.mock('lucide-react', () => ({+ BotMessageSquareIcon: () => null,+ MoreHorizontal: () => null,+ Settings2Icon: () => null,+ Trash: () => null,+}));++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string) => key,+ }),+}));++vi.mock('react-router-dom', () => ({+ useNavigate: () => mocks.navigate,+}));++vi.mock('@/components/AntdStaticMethods', () => ({+ message: {+ error: vi.fn(),+ success: vi.fn(),+ warning: vi.fn(),+ },+}));++vi.mock('@/const/layoutTokens', () => ({+ DESKTOP_HEADER_ICON_SMALL_SIZE: 24,+}));++vi.mock('@/features/NavHeader', () => ({+ default: ({ left, right }: { left?: ReactNode; right?: ReactNode }) => (+ <header>+ {left}+ {right}+ </header>+ ),+}));++vi.mock('@/features/RightPanel/ToggleRightPanelButton', () => ({+ default: () => <button type="button">agentBuilder</button>,+}));++vi.mock('@/layout/AuthProvider/MarketAuth', () => ({+ useMarketAuth: () => mocks.marketAuth,+}));++vi.mock('@/layout/AuthProvider/MarketAuth/errors', () => ({+ resolveMarketAuthError: () => ({ code: 'unknown' }),+}));++vi.mock('@/store/agent', () => ({+ useAgentStore: (selector: (state: typeof mocks.agentState) => unknown) =>+ selector(mocks.agentState),+}));++vi.mock('@/store/agent/selectors', () => ({+ agentSelectors: {+ canCurrentAgentPublishToCommunity: (state: typeof mocks.agentState) =>+ state.canCurrentAgentPublishToCommunity,+ currentAgentMeta: (state: typeof mocks.agentState) => state.meta,+ currentAgentSystemRole: (state: typeof mocks.agentState) => state.systemRole,+ isCurrentAgentHeterogeneous: (state: typeof mocks.agentState) =>+ state.isCurrentAgentHeterogeneous,+ },+}));++vi.mock('@/store/global', () => ({+ useGlobalStore: (selector: (state: typeof mocks.globalState) => unknown) =>+ selector(mocks.globalState),+}));++vi.mock('@/store/global/selectors', () => ({+ systemStatusSelectors: {+ isStatusInit: (state: typeof mocks.globalState) => state.isStatusInit,+ showAgentBuilderPanel: (state: typeof mocks.globalState) => state.showAgentBuilderPanel,+ },+}));++vi.mock('@/store/home', () => ({+ useHomeStore: (selector: (state: typeof mocks.homeState) => unknown) => selector(mocks.homeState),+}));++vi.mock('./AgentForkTag', () => ({+ default: () => null,+}));++vi.mock('./AgentPublishButton/ForkConfirmModal', () => ({+ default: () => null,+}));++vi.mock('./AgentPublishButton/PublishResultModal', () => ({+ default: () => null,+}));++vi.mock('./AgentPublishButton/useMarketPublish', () => ({+ useMarketPublish: () => mocks.marketPublish,+}));++vi.mock('./AgentStatusTag', () => ({+ default: () => null,+}));++vi.mock('./AutoSaveHint', () => ({+ default: () => null,+}));++vi.mock('./AgentVersionReviewTag', () => ({+ default: () => null,+ useVersionReviewStatus: () => mocks.versionReviewStatus,+}));++describe('Agent profile Header', () => {+ beforeEach(() => {+ mocks.agentState.canCurrentAgentPublishToCommunity = true;+ mocks.agentState.isCurrentAgentHeterogeneous = false;+ });++ it('should show the community publish action for normal agents', () => {+ render(<Header />);++ expect(screen.getByRole('button', { name: 'publishToCommunity' })).toBeInTheDocument();+ });++ it('should hide the community publish action for heterogeneous and platform agents', () => {+ mocks.agentState.canCurrentAgentPublishToCommunity = false;+ mocks.agentState.isCurrentAgentHeterogeneous = true;++ render(<Header />);++ expect(screen.queryByRole('button', { name: 'publishToCommunity' })).not.toBeInTheDocument();+ });+});diff --git a/src/routes/(main)/agent/profile/features/Header/index.tsx b/src/routes/(main)/agent/profile/features/Header/index.tsxindex e4a032779a4..416d226494a 100644--- a/src/routes/(main)/agent/profile/features/Header/index.tsx+++ b/src/routes/(main)/agent/profile/features/Header/index.tsx@@ -36,6 +36,7 @@ const Header = memo(() => {const systemRole = useAgentStore(agentSelectors.currentAgentSystemRole);const activeAgentId = useAgentStore((s) => s.activeAgentId);const isHeterogeneous = useAgentStore(agentSelectors.isCurrentAgentHeterogeneous);+ const canPublishToCommunity = useAgentStore(agentSelectors.canCurrentAgentPublishToCommunity);const [showAgentBuilderPanel, toggleAgentBuilderPanel, isStatusInit] = useGlobalStore((s) => [systemStatusSelectors.showAgentBuilderPanel(s),s.toggleAgentBuilderPanel,@@ -148,13 +149,17 @@ const Header = memo(() => {onClick: () => useAgentStore.setState({ showAgentSetting: true }),},{ type: 'divider' as const },- {- icon: <Icon icon={ShapesUploadIcon} />,- key: 'publish',- label: t('publishToCommunity', { ns: 'setting' }),- onClick: handlePublishClick,- },- { type: 'divider' as const },+ ...(canPublishToCommunity+ ? [+ {+ icon: <Icon icon={ShapesUploadIcon} />,+ key: 'publish',+ label: t('publishToCommunity', { ns: 'setting' }),+ onClick: handlePublishClick,+ },+ { type: 'divider' as const },+ ]+ : []),{danger: true,icon: <Icon icon={Trash} />,@@ -163,7 +168,7 @@ const Header = memo(() => {onClick: handleDelete,},],- [handlePublishClick, handleDelete, t],+ [canPublishToCommunity, handlePublishClick, handleDelete, t],);return (@@ -182,7 +187,7 @@ const Header = memo(() => {<DropdownMenu items={menuItems}><ActionIconicon={MoreHorizontal}- loading={isPublishing || isAuthLoading}+ loading={canPublishToCommunity && (isPublishing || isAuthLoading)}size={DESKTOP_HEADER_ICON_SMALL_SIZE}/></DropdownMenu>diff --git a/src/store/agent/selectors/selectors.test.ts b/src/store/agent/selectors/selectors.test.tsindex 20aacdd999f..40239b26adf 100644--- a/src/store/agent/selectors/selectors.test.ts+++ b/src/store/agent/selectors/selectors.test.ts@@ -360,6 +360,50 @@ describe('agentSelectors', () => {});});+ describe('canCurrentAgentPublishToCommunity', () => {+ it('should allow publishing normal agents', () => {+ const state = createState({+ activeAgentId: 'agent-1',+ agentMap: { 'agent-1': { id: 'agent-1' } },+ });++ expect(agentSelectors.canCurrentAgentPublishToCommunity(state)).toBe(true);+ });++ it('should prevent publishing local heterogeneous agents', () => {+ const state = createState({+ activeAgentId: 'agent-1',+ agentMap: {+ 'agent-1': {+ agencyConfig: {+ heterogeneousProvider: { command: 'codex', type: 'codex' },+ },+ id: 'agent-1',+ },+ },+ });++ expect(agentSelectors.canCurrentAgentPublishToCommunity(state)).toBe(false);+ });++ it('should prevent publishing platform agents', () => {+ const state = createState({+ activeAgentId: 'agent-1',+ agentMap: {+ 'agent-1': {+ agencyConfig: {+ boundDeviceId: 'device-1',+ heterogeneousProvider: { type: 'openclaw' },+ },+ id: 'agent-1',+ },+ },+ });++ expect(agentSelectors.canCurrentAgentPublishToCommunity(state)).toBe(false);+ });+ });+describe('currentKnowledgeIds', () => {it('should return enabled file and knowledge base IDs', () => {const state = createState({diff --git a/src/store/agent/selectors/selectors.ts b/src/store/agent/selectors/selectors.tsindex 8a98286da6d..45f2eaab0ab 100644--- a/src/store/agent/selectors/selectors.ts+++ b/src/store/agent/selectors/selectors.ts@@ -286,6 +286,9 @@ const isCurrentAgentExternal = (s: AgentStoreState): boolean => !currentAgentDatconst isCurrentAgentHeterogeneous = (s: AgentStoreState): boolean =>!!currentAgentConfig(s)?.agencyConfig?.heterogeneousProvider;+const canCurrentAgentPublishToCommunity = (s: AgentStoreState): boolean =>+ !!currentAgentData(s) && !isCurrentAgentHeterogeneous(s);+const currentAgentHeterogeneousProviderType = (s: AgentStoreState) =>currentAgentConfig(s)?.agencyConfig?.heterogeneousProvider?.type;@@ -293,6 +296,7 @@ const getAgentDocumentsById = (agentId: string) => (s: AgentStoreState) =>s.agentDocumentsMap[agentId];export const agentSelectors = {+ canCurrentAgentPublishToCommunity,currentAgentHeterogeneousProviderType,currentAgentAvatar,currentAgentBackgroundColor,