π€― 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
β¨ feat(daily brief): add action link component (#18249)
Arvin Xu2eb2c0880668
diff --git a/src/features/DailyBrief/BriefActionLink.tsx b/src/features/DailyBrief/BriefActionLink.tsxnew file mode 100644index 00000000000..3eaf43d0823--- /dev/null+++ b/src/features/DailyBrief/BriefActionLink.tsx@@ -0,0 +1,115 @@+'use client';++import { isDesktop } from '@lobechat/const';+import { RENDERER_HANDLED_LINK_ATTR } from '@lobechat/desktop-bridge';+import { Button } from '@lobehub/ui/base-ui';+import type { MouseEvent, ReactNode } from 'react';+import { memo, useCallback } from 'react';++import { useWorkspaces } from '@/business/client/hooks/useWorkspaces';+import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';+import { parseInternalLink } from '@/features/Conversation/Markdown/plugins/Link/internalLink';+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';+import { useChatStore } from '@/store/chat';+import { useGlobalStore } from '@/store/global';++interface BriefActionLinkProps {+ /** Agent owning the brief's task β keeps the task detail path agent-scoped. */+ agentId?: string | null;+ children: ReactNode;+ className?: string;+ /** Renders the filled primary variant used for a card's leading action. */+ primary?: boolean;+ taskId?: string | null;+ url?: string;+}++/**+ * A `type: 'link'` brief action.+ *+ * A bare `<a href>` is a document navigation: on the web it throws away the+ * whole SPA, and in Electron it hands `app://renderer/<path>` to a router that+ * never registered the target (acceptance is web-only β see+ * `desktopRouter.config.tsx`), so the button reads as dead. Internal+ * destinations therefore route through React Router instead, and acceptance β+ * which has no standalone desktop route at all β opens in the task-agent panel+ * beside its task, the same surface `TaskAcceptance` / `RunVerifyTag` use.+ *+ * The `href` stays on the anchor so middle-click / copy-link still work, and+ * `RENDERER_HANDLED_LINK_ATTR` tells the desktop preload interceptor this+ * click is already claimed.+ */+export const BriefActionLink = memo<BriefActionLinkProps>(+ ({ agentId, children, className, primary, taskId, url }) => {+ const navigate = useWorkspaceAwareNavigate();+ const workspaces = useWorkspaces();+ const openAcceptance = useChatStore((s) => s.openAcceptance);+ const toggleTaskAgentPanel = useGlobalStore((s) => s.toggleTaskAgentPanel);++ const reference = parseInternalLink(+ url,+ typeof window === 'undefined' ? undefined : window.location.origin,+ workspaces.map((workspace) => workspace.slug),+ );+ const isTasklessDesktopAcceptance = isDesktop && reference?.type === 'acceptance' && !taskId;+ const isRendererHandled = !!reference && !isTasklessDesktopAcceptance;++ const handleClick = useCallback(+ (event: MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => {+ // External destinations (billing, docs) stay plain anchors.+ if (!reference) return;+ // Electron has no standalone acceptance route. Without a task there is+ // no panel destination either, so leave the link to the preload layer.+ if (isTasklessDesktopAcceptance) return;+ if (event.button !== 0) return;++ // On the web a modifier-click means "open in a new tab", so let the+ // browser handle it. Desktop has no tabs for it to open.+ const modifierClick = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;+ if (!isDesktop && modifierClick) return;++ event.preventDefault();++ if (reference.type === 'acceptance' && taskId) {+ // Arm the panel before navigating, the same handoff+ // `Home/InputArea/useSend` performs β the panel mounts with the task+ // page and reads this state on its first render.+ toggleTaskAgentPanel(true);+ openAcceptance(reference.acceptanceId);+ navigate(taskDetailPath(taskId, agentId ?? undefined));+ return;+ }++ // A path that already carries its workspace slug must not be prefixed twice.+ navigate(+ reference.pathname,+ 'workspaceSlug' in reference && reference.workspaceSlug ? { escape: true } : undefined,+ );+ },+ [+ agentId,+ isTasklessDesktopAcceptance,+ navigate,+ openAcceptance,+ reference,+ taskId,+ toggleTaskAgentPanel,+ ],+ );++ return (+ <Button+ {...(isRendererHandled ? { [RENDERER_HANDLED_LINK_ATTR]: 'true' } : {})}+ className={className}+ href={url}+ shape={'round'}+ type={primary ? 'primary' : 'default'}+ onClick={handleClick}+ >+ {children}+ </Button>+ );+ },+);++BriefActionLink.displayName = 'BriefActionLink';diff --git a/src/features/DailyBrief/BriefCardActions.tsx b/src/features/DailyBrief/BriefCardActions.tsxindex f683cdd2704..13489e48e5a 100644--- a/src/features/DailyBrief/BriefCardActions.tsx+++ b/src/features/DailyBrief/BriefCardActions.tsx@@ -10,6 +10,7 @@ import { shallow } from 'zustand/shallow';import { useBriefStore } from '@/store/brief';import { useTaskStore } from '@/store/task';+import { BriefActionLink } from './BriefActionLink';import CommentInput from './CommentInput';import { styles } from './style';@@ -262,14 +263,15 @@ const BriefCardActions = memo<BriefCardActionsProps>({otherActions.map((action) => {if (action.type === 'link') {return (- <Button+ <BriefActionLink+ agentId={agentId}className={styles.actionBtn}- href={action.url}key={action.key}- shape={'round'}+ taskId={taskId}+ url={action.url}>{getActionLabel(action)}- </Button>+ </BriefActionLink>);}@@ -300,14 +302,15 @@ const BriefCardActions = memo<BriefCardActionsProps>(// A link primary (e.g. the budget-error "Upgrade" remedy) navigates// to its url instead of resolving the brief; render it as a filled// primary so the fix is the clear call to action.- <Button+ <BriefActionLink+ primary+ agentId={agentId}className={styles.actionBtnPrimary}- href={primaryActions.url}- shape={'round'}- type={'primary'}+ taskId={taskId}+ url={primaryActions.url}>{getActionLabel(primaryActions)}- </Button>+ </BriefActionLink>) : (<ButtonclassName={styles.actionBtnPrimary}diff --git a/src/features/DailyBrief/__tests__/BriefCardActions.test.tsx b/src/features/DailyBrief/__tests__/BriefCardActions.test.tsxindex 26e67b80c8b..616e6f8b3a6 100644--- a/src/features/DailyBrief/__tests__/BriefCardActions.test.tsx+++ b/src/features/DailyBrief/__tests__/BriefCardActions.test.tsx@@ -1,3 +1,5 @@+import type * as LobechatConst from '@lobechat/const';+import { RENDERER_HANDLED_LINK_ATTR } from '@lobechat/desktop-bridge';import type { BriefAction } from '@lobechat/types';import { toast } from '@lobehub/ui/base-ui';import { fireEvent, render, screen, waitFor } from '@testing-library/react';@@ -12,6 +14,11 @@ import BriefCardActions from '../BriefCardActions';const renderWithRouter = (ui: ReactElement) => render(<MemoryRouter>{ui}</MemoryRouter>);+vi.mock('@lobechat/const', async (importOriginal) => ({+ ...(await importOriginal<typeof LobechatConst>()),+ isDesktop: true,+}));+// Mock i18nvi.mock('react-i18next', () => ({useTranslation: () => ({@@ -78,6 +85,53 @@ beforeEach(() => {});describe('BriefCardActions', () => {+ it('should route primary and secondary link actions through BriefActionLink', () => {+ const actions: BriefAction[] = [+ { key: 'primary', label: 'Primary link', type: 'link', url: '/settings/profile' },+ { key: 'secondary', label: 'Secondary link', type: 'link', url: '/settings/common' },+ ];++ renderWithRouter(+ <BriefCardActions+ actions={actions}+ agentId="agent-1"+ briefId="brief-links"+ briefType="decision"+ taskId="task-1"+ />,+ );++ expect(screen.getByRole('button', { name: 'Primary link' })).toHaveAttribute(+ RENDERER_HANDLED_LINK_ATTR,+ 'true',+ );+ expect(screen.getByRole('button', { name: 'Secondary link' })).toHaveAttribute(+ RENDERER_HANDLED_LINK_ATTR,+ 'true',+ );+ });++ it('should leave a taskless acceptance link to the desktop preload interceptor', () => {+ renderWithRouter(+ <BriefCardActions+ briefId="brief-acceptance"+ briefType="decision"+ actions={[+ {+ key: 'review',+ label: 'Review acceptance',+ type: 'link',+ url: '/acceptance/acceptance-1',+ },+ ]}+ />,+ );++ const link = screen.getByRole('button', { name: 'Review acceptance' });+ expect(link).not.toHaveAttribute(RENDERER_HANDLED_LINK_ATTR);+ expect(fireEvent.click(link)).toBe(true);+ });+it('should render resolve action buttons from actions prop', () => {renderWithRouter(<BriefCardActions actions={sampleActions} briefId="brief-1" briefType="decision" />,