🤯 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(acceptance): open an acceptance link in the browser from beside it (#22128)
Rdmclin24eda0029805c
diff --git a/src/features/EntityLink/Render/InternalEntityLink.tsx b/src/features/EntityLink/Render/InternalEntityLink.tsxindex 710f4590d2f..eeda48fbe66 100644--- a/src/features/EntityLink/Render/InternalEntityLink.tsx+++ b/src/features/EntityLink/Render/InternalEntityLink.tsx@@ -2,12 +2,13 @@import { isDesktop } from '@lobechat/const';import { RENDERER_HANDLED_LINK_ATTR } from '@lobechat/desktop-bridge';-import { createStaticStyles, Icon } from '@lobehub/ui';+import { ActionIcon, createStaticStyles, Icon } from '@lobehub/ui';import {BadgeCheckIcon,BotIcon,CheckCircleIcon,CheckSquareIcon,+ ExternalLinkIcon,FileTextIcon,TargetIcon,} from 'lucide-react';@@ -27,6 +28,7 @@ import {useAgentDocumentStore,} from '@/store/agentDocument';import { useChatStore } from '@/store/chat';+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';import { useEntityLinkHostDismiss, useEntityLinkPortal } from '../host';import { type InternalLinkReference, isBareLinkLabel, isEntityIdLabel } from '../internalLink';@@ -35,8 +37,17 @@ import {InternalEntityPreview,internalEntityPreviewKey,} from './InternalEntityPreview';+import { useAcceptanceBrowserUrl } from './useAcceptanceBrowserUrl';const styles = createStaticStyles(({ css, cssVar }) => ({+ browser: css`+ color: ${cssVar.colorTextTertiary};+ transition: color 0.15s;++ &:hover {+ color: ${cssVar.colorText};+ }+ `,icon: css`margin-inline-end: 4px;color: ${cssVar.colorTextSecondary};@@ -71,6 +82,11 @@ const styles = createStaticStyles(({ css, cssVar }) => ({outline-offset: 2px;}`,+ wrapper: css`+ display: inline-flex;+ gap: 2px;+ align-items: center;+ `,}));const ENTITY_ICONS = {@@ -90,6 +106,7 @@ interface InternalEntityLinkProps {export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label, reference }) => {const { t } = useTranslation('chat');+ const { t: tVerify } = useTranslation('verify');const navigate = useWorkspaceAwareNavigate();const activeAgentId = useAgentStore((s) => s.activeAgentId);const portalAvailable = useEntityLinkPortal(reference.type);@@ -127,6 +144,14 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,{ revalidateOnFocus: false },);const displayLabel = (shouldResolveTitle && entity?.title) || label;+ // A click on the link opens the acceptance in the side panel, which another+ // surface (a session overlay) can cover; this one-click way out to the full+ // browser page needs no hover on the preview first. Mobile opens it in a+ // modal on top of everything, and a small icon right beside the link would+ // be a mis-tap target there, so the action stays off the mobile build.+ const isMobile = typeof __MOBILE__ !== 'undefined' && __MOBILE__;+ const acceptanceBrowserUrl = useAcceptanceBrowserUrl(reference);+ const browserUrl = isMobile ? undefined : acceptanceBrowserUrl;const linkedAgentId = reference.type === 'document' ? reference.agentId : undefined;const shouldResolveAgentDocument = !!linkedAgentId && linkedAgentId === activeAgentId;@@ -288,12 +313,32 @@ export const InternalEntityLink = memo<InternalEntityLinkProps>(({ href, label,</a>);- if (reference.type === 'route' || reference.workspaceSlug) return link;+ const preview =+ reference.type === 'route' || reference.workspaceSlug ? (+ link+ ) : (+ <InternalEntityPreview fallbackTitle={displayLabel} reference={reference}>+ {link}+ </InternalEntityPreview>+ );++ if (!browserUrl) return preview;return (- <InternalEntityPreview fallbackTitle={displayLabel} reference={reference}>- {link}- </InternalEntityPreview>+ <span className={styles.wrapper}>+ {preview}+ {/* Outside the anchor, like the side-browser action: the desktop preload+ claims clicks via `closest('a')`, so a nested button would never fire. */}+ <ActionIcon+ data-acceptance-browser+ aria-label={tVerify('report.actions.openInBrowser')}+ className={styles.browser}+ icon={ExternalLinkIcon}+ size={'small'}+ title={tVerify('report.actions.openInBrowser')}+ onClick={() => openTrustedExternalUrl(browserUrl)}+ />+ </span>);});diff --git a/src/features/EntityLink/Render/InternalEntityPreview.tsx b/src/features/EntityLink/Render/InternalEntityPreview.tsxindex 95747c96441..e22e3318e88 100644--- a/src/features/EntityLink/Render/InternalEntityPreview.tsx+++ b/src/features/EntityLink/Render/InternalEntityPreview.tsx@@ -24,11 +24,8 @@ import {import { memo, type PropsWithChildren, useState } from 'react';import { useTranslation } from 'react-i18next';-import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';import { ArticleSkeleton } from '@/components/Skeleton';-import { useAcceptanceOrigin } from '@/features/Acceptance/origin';import { goalStatusKey } from '@/features/AgentGoals/goalPresentation';-import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';import { useClientDataSWR } from '@/libs/swr';import { agentService } from '@/services/agent';import { documentService } from '@/services/document';@@ -38,6 +35,7 @@ import { verifyService } from '@/services/verify';import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';import type { InternalLinkReference } from '../internalLink';+import { useAcceptanceBrowserUrl } from './useAcceptanceBrowserUrl';const styles = createStaticStyles(({ css, cssVar }) => ({content: css`@@ -247,15 +245,9 @@ export const InternalEntityPreview = memo<InternalEntityPreviewProps>(const { t } = useTranslation('chat');const { t: tVerify } = useTranslation('verify');const [open, setOpen] = useState(false);- const appOrigin = useAcceptanceOrigin();- const activeWorkspaceSlug = useActiveWorkspaceSlug();// A click on the link opens the acceptance in the side panel; this is the- // explicit way out to a full browser page. Without an origin the URL would- // be relative, which the desktop system browser cannot resolve.- const browserUrl =- reference.type === 'acceptance' && appOrigin- ? `${appOrigin}${buildWorkspaceAwarePath(reference.pathname, activeWorkspaceSlug)}`- : undefined;+ // explicit way out to a full browser page.+ const browserUrl = useAcceptanceBrowserUrl(reference);const { data, isLoading } = useClientDataSWR(open ? internalEntityPreviewKey(reference) : null,() => getPreviewData(reference, t),diff --git a/src/features/EntityLink/Render/index.test.tsx b/src/features/EntityLink/Render/index.test.tsxindex 5b61d0f46aa..f34ed09abe2 100644--- a/src/features/EntityLink/Render/index.test.tsx+++ b/src/features/EntityLink/Render/index.test.tsx@@ -156,6 +156,14 @@ const renderLinkInHost = (properties: Record<string, unknown>, portal: EntityLin</EntityLinkHostProvider>,);+/** Hover the link's preview trigger (the Popover mock), not the outer action wrapper. */+const hoverPreview = (container: HTMLElement) =>+ fireEvent.mouseEnter(container.querySelector('a')!.parentElement!);++/** The open-in-browser action inside the hover preview card. */+const previewBrowserAction = (container: HTMLElement) =>+ container.querySelector<HTMLElement>('a ~ * button[aria-label="report.actions.openInBrowser"]');+afterEach(() => {mockShowIcon = true;mockConst.isDesktop = false;@@ -278,14 +286,14 @@ describe('Link Render — internal entities', () => {// full page as an explicit alternative, as an absolute URL so the desktop// system browser can resolve it.mockEntityPreview = { title: 'Workspace publishing' };- const { container, getByRole } = renderLink({+ const { container } = renderLink({linkHref: '/acceptance/acceptance-1',linkKind: 'generic',linkLabel: 'Acceptance',});- fireEvent.mouseEnter(container.firstElementChild!);+ hoverPreview(container);- fireEvent.click(getByRole('button', { name: 'report.actions.openInBrowser' }));+ fireEvent.click(previewBrowserAction(container)!);expect(mockOpenTrustedExternalUrl).toHaveBeenCalledWith('https://app.lobehub.com/acceptance/acceptance-1',@@ -298,14 +306,14 @@ describe('Link Render — internal entities', () => {// `/acceptance/<id>` is the marketing site's page rather than the report.mockAppOrigin = 'https://lobehub.com';mockEntityPreview = { title: 'Workspace publishing' };- const { container, getByRole } = renderLink({+ const { container } = renderLink({linkHref: '/acceptance/acceptance-1',linkKind: 'generic',linkLabel: 'Acceptance',});- fireEvent.mouseEnter(container.firstElementChild!);+ hoverPreview(container);- fireEvent.click(getByRole('button', { name: 'report.actions.openInBrowser' }));+ fireEvent.click(previewBrowserAction(container)!);expect(mockOpenTrustedExternalUrl).toHaveBeenCalledWith('https://app.lobehub.com/acceptance/acceptance-1',@@ -335,6 +343,73 @@ describe('Link Render — internal entities', () => {expect(queryByRole('button', { name: 'report.actions.openInBrowser' })).toBeNull();});+ it('opens an acceptance in the browser from beside the link, without hovering', () => {+ // The side panel a click opens can sit under another surface (a session+ // overlay), so the browser page is one click away right next to the link.+ const { container } = renderLink({+ linkHref: '/acceptance/acceptance-1',+ linkKind: 'generic',+ linkLabel: 'Acceptance',+ });++ const action = container.querySelector<HTMLElement>('[data-acceptance-browser]')!;+ expect(action).toHaveAttribute('aria-label', 'report.actions.openInBrowser');+ // Outside the anchor: the desktop preload claims clicks via closest('a').+ expect(action.closest('a')).toBeNull();++ fireEvent.click(action);++ expect(mockOpenTrustedExternalUrl).toHaveBeenCalledWith(+ 'https://app.lobehub.com/acceptance/acceptance-1',+ );+ expect(mockOpenAcceptance).not.toHaveBeenCalled();+ });++ it('keeps a workspace-qualified acceptance link scoped when opening it in the browser', () => {+ const { container } = renderLink({+ linkHref: '/lobe-team/acceptance/acceptance-1',+ linkKind: 'generic',+ linkLabel: 'Acceptance',+ });++ fireEvent.click(container.querySelector('[data-acceptance-browser]')!);++ expect(mockOpenTrustedExternalUrl).toHaveBeenCalledWith(+ 'https://app.lobehub.com/lobe-team/acceptance/acceptance-1',+ );+ });++ it('offers no inline browser action without an origin or on other entities', () => {+ for (const linkHref of ['/task/T-198', '/verify/run-1']) {+ const { container } = renderLink({ linkHref, linkKind: 'generic', linkLabel: 'Entity' });+ expect(container.querySelector('[data-acceptance-browser]')).toBeNull();+ }++ mockAppOrigin = '';+ const { container } = renderLink({+ linkHref: '/acceptance/acceptance-1',+ linkKind: 'generic',+ linkLabel: 'Acceptance',+ });+ expect(container.querySelector('[data-acceptance-browser]')).toBeNull();+ });++ it('keeps the inline browser action off mobile, where a tap beside the link would misfire', () => {+ vi.stubGlobal('__MOBILE__', true);++ try {+ const { container } = renderLink({+ linkHref: '/acceptance/acceptance-1',+ linkKind: 'generic',+ linkLabel: 'Acceptance',+ });++ expect(container.querySelector('[data-acceptance-browser]')).toBeNull();+ } finally {+ vi.unstubAllGlobals();+ }+ });+it('replaces a pasted URL label with the resolved entity title', () => {// A raw acceptance URL says nothing about what it points to; once the// entity resolves, the link reads as its title.diff --git a/src/features/EntityLink/Render/useAcceptanceBrowserUrl.ts b/src/features/EntityLink/Render/useAcceptanceBrowserUrl.tsnew file mode 100644index 00000000000..c4efb828082--- /dev/null+++ b/src/features/EntityLink/Render/useAcceptanceBrowserUrl.ts@@ -0,0 +1,25 @@+import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';+import { useAcceptanceOrigin } from '@/features/Acceptance/origin';+import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';++import type { InternalLinkReference } from '../internalLink';++/**+ * Absolute web URL of an acceptance link, for opening it in the browser+ * instead of the side panel. `undefined` for other entities, and without an+ * origin: a relative URL is something the desktop system browser cannot resolve.+ */+export const useAcceptanceBrowserUrl = (reference: InternalLinkReference): string | undefined => {+ const appOrigin = useAcceptanceOrigin();+ const activeWorkspaceSlug = useActiveWorkspaceSlug();++ if (reference.type !== 'acceptance' || !appOrigin) return;++ // A workspace-prefixed path is already scoped; an unprefixed one is scoped+ // to the active workspace, the same way a click on the link resolves it.+ const pathname = reference.workspaceSlug+ ? reference.pathname+ : buildWorkspaceAwarePath(reference.pathname, activeWorkspaceSlug);++ return `${appOrigin}${pathname}`;+};