🤯 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(share): open visitor conversations on their own page (#23741)
YuTengjing18ff6aead33b
diff --git a/locales/en-US/agent.json b/locales/en-US/agent.jsonindex ceaba0a7ca4..414eb48787e 100644--- a/locales/en-US/agent.json+++ b/locales/en-US/agent.json@@ -768,7 +768,7 @@"share.settings.pendingGrants.grantAll": "Open to visitors","share.settings.pendingGrants.title": "{{count}} tools or skills turned on in this Agent aren’t open to visitors yet","share.settings.permissions.allowCreatorViewSessions": "Let me read visitor conversations",- "share.settings.permissions.allowCreatorViewSessionsHint": "Off by default: visitor conversations stay private to the visitor. When on, they appear under Share on this agent's Topics page.",+ "share.settings.permissions.allowCreatorViewSessionsHint": "You can read visitors' conversations with the Agent.","share.settings.permissions.allowReadMemory": "Allow reading my memory","share.settings.permissions.allowReadMemoryHint": "The Agent may draw on your long-term memory while answering a visitor.","share.settings.permissions.desc": "What a visitor’s run may read, and whether you can read visitor conversations.",@@ -794,6 +794,11 @@"share.settings.permissions.deviceAllowPlaceholder": "Choose people from your contacts","share.settings.permissions.deviceAllowUnlisted": "No longer in contacts, so they can’t use it: {{names}}. They’re removed the next time you edit this list.","share.settings.permissions.title": "Permissions",+ "share.settings.permissions.visitorConversations.topics_one": "{{count}} conversation",+ "share.settings.permissions.visitorConversations.topics_other": "{{count}} conversations",+ "share.settings.permissions.visitorConversations.view": "View conversations",+ "share.settings.permissions.visitorConversations.visitors_one": "{{count}} visitor",+ "share.settings.permissions.visitorConversations.visitors_other": "{{count}} visitors","share.settings.profile.demoCases.add": "Add example","share.settings.profile.demoCases.desc": "Write examples for visitors to try. These are separate from the agent’s opening questions.","share.settings.profile.demoCases.description": "Description",diff --git a/locales/en-US/topic.json b/locales/en-US/topic.jsonindex 40f495d8e02..08915e11387 100644--- a/locales/en-US/topic.json+++ b/locales/en-US/topic.json@@ -302,12 +302,13 @@"scheduledStatusTip": "Scheduled to run at {{time}}.","searchPlaceholder": "Search Topics...","searchResultEmpty": "No search results found.",+ "shareVisitorTopics.backToShare": "Back to Share",+ "shareVisitorTopics.empty": "No visitor conversations yet","shareVisitorTopics.readOnly": "Read-only","shareVisitorTopics.readOnlyHint": "A visitor's conversation through your share link. You can read it, but not reply or change it.","shareVisitorTopics.title": "Visitors","shareVisitorTopics.unavailable": "This conversation is no longer available","shareVisitorTopics.untitled": "Untitled conversation",- "shareVisitorTopics.viewAll": "View all visitor conversations","sidebar.collapseAll": "Collapse all groups","sidebar.expandAll": "Expand all groups","sidebar.title": "Topics",diff --git a/locales/zh-CN/agent.json b/locales/zh-CN/agent.jsonindex 26de5ec9acd..9375d34b68c 100644--- a/locales/zh-CN/agent.json+++ b/locales/zh-CN/agent.json@@ -768,7 +768,7 @@"share.settings.pendingGrants.grantAll": "开放给访客","share.settings.pendingGrants.title": "助手里已开启的 {{count}} 个工具或技能还没开放给访客","share.settings.permissions.allowCreatorViewSessions": "允许我查看访客对话",- "share.settings.permissions.allowCreatorViewSessionsHint": "默认关闭:访客的对话只有访客自己能看到。开启后,可在该助手「话题」页的「分享」来源中查看。",+ "share.settings.permissions.allowCreatorViewSessionsHint": "你可以查看访客与助手的对话内容。","share.settings.permissions.allowReadMemory": "允许读取我的记忆","share.settings.permissions.allowReadMemoryHint": "助手在回答访客时可以参考你的长期记忆。","share.settings.permissions.desc": "访客的运行可以读取什么,以及你能否查看访客的对话。",@@ -794,6 +794,11 @@"share.settings.permissions.deviceAllowPlaceholder": "从通讯录选择","share.settings.permissions.deviceAllowUnlisted": "已不在通讯录,无法使用:{{names}}。下次修改名单时会被移除。","share.settings.permissions.title": "权限",+ "share.settings.permissions.visitorConversations.topics_one": "{{count}} 个对话",+ "share.settings.permissions.visitorConversations.topics_other": "{{count}} 个对话",+ "share.settings.permissions.visitorConversations.view": "查看访客对话",+ "share.settings.permissions.visitorConversations.visitors_one": "{{count}} 位访客",+ "share.settings.permissions.visitorConversations.visitors_other": "{{count}} 位访客","share.settings.profile.demoCases.add": "添加案例","share.settings.profile.demoCases.desc": "为访客编写可直接试用的案例,独立于助手的开场问题。","share.settings.profile.demoCases.description": "案例说明",diff --git a/locales/zh-CN/topic.json b/locales/zh-CN/topic.jsonindex 95d0c230daf..5ce5c301e7c 100644--- a/locales/zh-CN/topic.json+++ b/locales/zh-CN/topic.json@@ -302,12 +302,13 @@"scheduledStatusTip": "将于 {{time}} 运行","searchPlaceholder": "搜索话题…","searchResultEmpty": "暂无搜索结果",+ "shareVisitorTopics.backToShare": "返回分享",+ "shareVisitorTopics.empty": "还没有访客对话","shareVisitorTopics.readOnly": "只读","shareVisitorTopics.readOnlyHint": "访客通过你的分享链接发起的对话,只能查看,不能回复或修改。","shareVisitorTopics.title": "访客","shareVisitorTopics.unavailable": "该对话已无法查看","shareVisitorTopics.untitled": "未命名对话",- "shareVisitorTopics.viewAll": "查看全部访客对话","sidebar.collapseAll": "折叠所有分组","sidebar.expandAll": "展开所有分组","sidebar.title": "话题",diff --git a/packages/const/src/url.ts b/packages/const/src/url.tsindex 8ad41bcbf09..2fb3564061b 100644--- a/packages/const/src/url.ts+++ b/packages/const/src/url.ts@@ -78,6 +78,12 @@ export const AGENT_CHAT_TOPIC_PAGE_URL = (agentId: string, topicId: string, mobireturn urlJoin('/agent', agentId, topicId, 'page');};+/**+ * Visitors' conversations with the shared Agent, opened from its Share settings. Lands on the+ * newest visitor topic, with the visitors listed in the sidebar.+ */+export const AGENT_SHARE_VISITORS_URL = (agentId: string) => urlJoin('/agent', agentId, 'visitor');+/** A share visitor's run topic, opened read-only by the shared Agent's owner. */export const AGENT_SHARE_VISITOR_TOPIC_URL = (agentId: string, topicId: string) =>urlJoin('/agent', agentId, 'visitor', topicId);diff --git a/packages/locales/src/default/agent.ts b/packages/locales/src/default/agent.tsindex ff45d785e1d..89c466c0793 100644--- a/packages/locales/src/default/agent.ts+++ b/packages/locales/src/default/agent.ts@@ -1005,7 +1005,7 @@ export default {'{{count}} tools or skills turned on in this Agent aren’t open to visitors yet','share.settings.permissions.allowCreatorViewSessions': 'Let me read visitor conversations','share.settings.permissions.allowCreatorViewSessionsHint':- "Off by default: visitor conversations stay private to the visitor. When on, they appear under Share on this agent's Topics page.",+ "You can read visitors' conversations with the Agent.",'share.settings.permissions.allowReadMemory': 'Allow reading my memory','share.settings.permissions.allowReadMemoryHint':'The Agent may draw on your long-term memory while answering a visitor.',@@ -1048,6 +1048,11 @@ export default {'share.settings.permissions.desc':'What a visitor’s run may read, and whether you can read visitor conversations.','share.settings.permissions.title': 'Permissions',+ 'share.settings.permissions.visitorConversations.topics_one': '{{count}} conversation',+ 'share.settings.permissions.visitorConversations.topics_other': '{{count}} conversations',+ 'share.settings.permissions.visitorConversations.view': 'View conversations',+ 'share.settings.permissions.visitorConversations.visitors_one': '{{count}} visitor',+ 'share.settings.permissions.visitorConversations.visitors_other': '{{count}} visitors','share.settings.skills.autoGranted': 'Open automatically because this Agent can use it','share.settings.tabs.access': 'Access','share.settings.tabs.profile': 'Public profile',diff --git a/packages/locales/src/default/topic.ts b/packages/locales/src/default/topic.tsindex d28dea665e0..3216cb50955 100644--- a/packages/locales/src/default/topic.ts+++ b/packages/locales/src/default/topic.ts@@ -337,13 +337,14 @@ export default {'scheduledStatusTip': 'Scheduled to run at {{time}}.','searchPlaceholder': 'Search Topics...','searchResultEmpty': 'No search results found.',+ 'shareVisitorTopics.backToShare': 'Back to Share',+ 'shareVisitorTopics.empty': 'No visitor conversations yet','shareVisitorTopics.readOnly': 'Read-only','shareVisitorTopics.readOnlyHint':"A visitor's conversation through your share link. You can read it, but not reply or change it.",'shareVisitorTopics.title': 'Visitors','shareVisitorTopics.unavailable': 'This conversation is no longer available','shareVisitorTopics.untitled': 'Untitled conversation',- 'shareVisitorTopics.viewAll': 'View all visitor conversations','sidebar.collapseAll': 'Collapse all groups','sidebar.expandAll': 'Expand all groups','sidebar.title': 'Topics',diff --git a/src/features/AgentSidebar/Body.tsx b/src/features/AgentSidebar/Body.tsxindex c0c4bed5af5..8b1b8b43857 100644--- a/src/features/AgentSidebar/Body.tsx+++ b/src/features/AgentSidebar/Body.tsx@@ -1,7 +1,6 @@import { AccordionRoot, Flexbox } from '@lobehub/ui';import React, { memo, useCallback, useMemo } from 'react';-import ShareVisitorTopicsSection from '@/features/ShareVisitorTopics/SidebarSection';import { useAgentStore } from '@/store/agent';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';@@ -9,12 +8,10 @@ import { systemStatusSelectors } from '@/store/global/selectors';import Topic from './Topic';export enum ChatSidebarKey {- ShareVisitors = 'shareVisitors',Topic = 'topic',}const DEFAULT_EXPANDED: Record<string, boolean> = {- [ChatSidebarKey.ShareVisitors]: true,[ChatSidebarKey.Topic]: true,};@@ -36,7 +33,6 @@ const Body = memo(() => {updateSystemStatus({expandAgentSidebarSectionsByAgent: {[agentId]: {- [ChatSidebarKey.ShareVisitors]: keys.includes(ChatSidebarKey.ShareVisitors),[ChatSidebarKey.Topic]: keys.includes(ChatSidebarKey.Topic),},},@@ -57,9 +53,6 @@ const Body = memo(() => {expanded={expandedKeys.includes(ChatSidebarKey.Topic)}itemKey={ChatSidebarKey.Topic}/>- {agentId && (- <ShareVisitorTopicsSection agentId={agentId} itemKey={ChatSidebarKey.ShareVisitors} />- )}</AccordionRoot></Flexbox>);diff --git a/src/features/AgentSidebar/Content.test.tsx b/src/features/AgentSidebar/Content.test.tsxindex e3b384e18ae..39010bc50a6 100644--- a/src/features/AgentSidebar/Content.test.tsx+++ b/src/features/AgentSidebar/Content.test.tsx@@ -13,6 +13,9 @@ vi.mock('@/features/NavPanel/SideBarLayout', () => ({}));vi.mock('./Body', () => ({ default: () => <div>topics</div> }));vi.mock('./Header', () => ({ default: () => null }));+vi.mock('@/features/ShareVisitorTopics/SidebarNav', () => ({+ default: () => <div>visitor-nav</div>,+}));vi.mock('./ProfileNav', () => ({default: ({ active }: { active: string }) => <div>profile-nav:{active}</div>,}));@@ -37,6 +40,17 @@ describe('AgentSidebarContent', () => {expect(screen.queryByText('topics')).not.toBeInTheDocument();});+ it.each(['/agent/agt_1/visitor', '/agent/agt_1/visitor/tpc_1'])(+ 'lists visitors instead of the Agent topics on %s',+ (pathname) => {+ mocks.pathname = pathname;+ render(<AgentSidebarContent />);++ expect(screen.getByText('visitor-nav')).toBeInTheDocument();+ expect(screen.queryByText('topics')).not.toBeInTheDocument();+ },+ );+it('keeps the topic sidebar in the chat', () => {mocks.pathname = '/agent/agt_1';render(<AgentSidebarContent />);diff --git a/src/features/AgentSidebar/Content.tsx b/src/features/AgentSidebar/Content.tsxindex cf65897992e..97d212079e0 100644--- a/src/features/AgentSidebar/Content.tsx+++ b/src/features/AgentSidebar/Content.tsx@@ -1,5 +1,7 @@import { getAgentProfileTab } from '@/features/AgentProfileTabs/tabOptions';import SideBarLayout from '@/features/NavPanel/SideBarLayout';+import { isShareVisitorRoute } from '@/features/ShareVisitorTopics/latestVisitorTopic';+import ShareVisitorSidebarNav from '@/features/ShareVisitorTopics/SidebarNav';import { useActiveLocation } from '@/hooks/useActiveLocation';import { isMobileSurface } from '@/utils/mobileSurface';@@ -9,6 +11,10 @@ import ProfileNav from './ProfileNav';const AgentSidebarContent = () => {const { pathname } = useActiveLocation();+ // Visitors' conversations are someone else's topics, so they get their own sidebar instead of+ // mixing into the Agent's topic list.+ if (isShareVisitorRoute(pathname)) return <ShareVisitorSidebarNav />;+// Mobile keeps the header Segmented; this panel is only its chat drawer there.const profileTab = isMobileSurface() ? undefined : getAgentProfileTab(pathname);diff --git a/src/features/ShareVisitorTopics/Landing.tsx b/src/features/ShareVisitorTopics/Landing.tsxnew file mode 100644index 00000000000..1f5905655eb--- /dev/null+++ b/src/features/ShareVisitorTopics/Landing.tsx@@ -0,0 +1,43 @@+'use client';++import { AGENT_SHARE_VISITOR_TOPIC_URL } from '@lobechat/const';+import { Center, Text } from '@lobehub/ui';+import { useEffect } from 'react';+import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';++import AsyncError from '@/components/AsyncError';+import ReadOnlyConversationSkeleton from '@/components/Skeleton/Conversation/ReadOnly';+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';++import { getLatestVisitorTopicId } from './latestVisitorTopic';+import { useShareVisitorTopicGroups } from './useShareVisitorTopics';++/**+ * Where the Share settings' 「View visitor conversations」 lands: opens the most recently active+ * visitor topic, with every visitor listed in the sidebar beside it.+ */+const ShareVisitorsLanding = () => {+ const { t } = useTranslation('topic');+ const { aid } = useParams<{ aid: string }>();+ const navigate = useWorkspaceAwareNavigate();+ const { error, groups, isLoading, mutate } = useShareVisitorTopicGroups(aid);+ const latestTopicId = getLatestVisitorTopicId(groups);++ useEffect(() => {+ if (aid && latestTopicId)+ navigate(AGENT_SHARE_VISITOR_TOPIC_URL(aid, latestTopicId), { replace: true });+ }, [aid, latestTopicId, navigate]);++ if (isLoading || latestTopicId) return <ReadOnlyConversationSkeleton />;++ if (error) return <AsyncError error={error} variant={'page'} onRetry={() => void mutate()} />;++ return (+ <Center flex={1}>+ <Text type={'secondary'}>{t('shareVisitorTopics.empty')}</Text>+ </Center>+ );+};++export default ShareVisitorsLanding;diff --git a/src/features/ShareVisitorTopics/SidebarNav.tsx b/src/features/ShareVisitorTopics/SidebarNav.tsxnew file mode 100644index 00000000000..cb9e68b9561--- /dev/null+++ b/src/features/ShareVisitorTopics/SidebarNav.tsx@@ -0,0 +1,187 @@+'use client';++import { AGENT_SHARE_VISITOR_TOPIC_URL } from '@lobechat/const';+import type { ShareVisitorTopicGroup } from '@lobechat/types';+import {+ AccordionHeader,+ AccordionItem,+ AccordionPanel,+ AccordionRoot,+ AccordionTrigger,+ Flexbox,+ Text,+} from '@lobehub/ui';+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';+import { ChevronLeftIcon } from 'lucide-react';+import { useState } from 'react';+import { useTranslation } from 'react-i18next';++import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';+import AsyncError from '@/components/AsyncError';+import UserAvatar from '@/components/UserAvatar';+import { buildAgentProfileTabPath } from '@/features/AgentProfileTabs/tabOptions';+import Agent from '@/features/AgentSidebar/Header/Agent';+import NavItem from '@/features/NavPanel/components/NavItem';+import SectionTitle, { useSectionTriggerStyle } from '@/features/NavPanel/components/SectionTitle';+import SideBarLayout from '@/features/NavPanel/SideBarLayout';+import ToggleLeftPanelButton from '@/features/NavPanel/ToggleLeftPanelButton';+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';+import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';+import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';++import { useActiveVisitorTopic } from './useActiveVisitorTopic';+import { useShareVisitorTopicGroups } from './useShareVisitorTopics';++const COUNT_STYLE = { fontVariantNumeric: 'tabular-nums' } as const;++/** Lines topic titles up under the visitor's name, past the avatar slot. */+const ICON_PLACEHOLDER = <span aria-hidden style={{ flex: 'none', width: 16 }} />;++const VisitorGroup = ({+ activeTopicId,+ agentId,+ group,+}: {+ activeTopicId: string | undefined;+ agentId: string;+ group: ShareVisitorTopicGroup;+}) => {+ const { t } = useTranslation('topic');+ const sectionTriggerStyle = useSectionTriggerStyle();+ const navigate = useWorkspaceAwareNavigate();+ const workspaceSlug = useActiveWorkspaceSlug();+ const name = group.visitor.name || t('management.shareVisitors.unnamedVisitor');++ return (+ <AccordionItem value={group.visitor.id}>+ <AccordionHeader>+ <AccordionTrigger style={sectionTriggerStyle}>+ <Flexbox horizontal align={'center'} gap={6} height={24} style={{ minWidth: 0 }}>+ <UserAvatar+ avatar={group.visitor.avatar}+ name={name}+ shape={'circle'}+ size={16}+ style={{ flex: 'none' }}+ />+ <SectionTitle>{name}</SectionTitle>+ <Text fontSize={11} style={COUNT_STYLE} type={'secondary'}>+ {group.topics.length}+ </Text>+ </Flexbox>+ </AccordionTrigger>+ </AccordionHeader>+ <AccordionPanel contentStyle={{ padding: 0 }}>+ <Flexbox gap={1} paddingBlock={1}>+ {group.topics.map((topic) => {+ const path = AGENT_SHARE_VISITOR_TOPIC_URL(agentId, topic.id);+ return (+ <NavItem+ titleMarquee+ active={topic.id === activeTopicId}+ href={buildWorkspaceAwarePath(path, workspaceSlug)}+ icon={ICON_PLACEHOLDER}+ key={topic.id}+ title={topic.title || topic.preview || t('shareVisitorTopics.untitled')}+ titleColor={cssVar.colorText}+ onClick={() => navigate(path)}+ />+ );+ })}+ </Flexbox>+ </AccordionPanel>+ </AccordionItem>+ );+};++/**+ * Replaces the Agent's topic sidebar on the visitors page: the visitors' run topics through the+ * share link, grouped by visitor, with the way back to the Share settings they were opened from.+ * Every visitor starts expanded; collapsing one is remembered while the page stays open.+ */+const ShareVisitorSidebarNav = () => {+ const { t } = useTranslation('topic');+ const navigate = useWorkspaceAwareNavigate();+ const agentId = useActiveRouteParams().aid!;+ const { error, groups, isLoading, mutate } = useShareVisitorTopicGroups(agentId);+ const { activeTopicId, activeVisitorId } = useActiveVisitorTopic(groups);+ const [collapsed, setCollapsed] = useState<string[]>([]);+ const [revealedVisitorId, setRevealedVisitorId] = useState<string>();++ // Opening a topic reveals it inside its visitor group, once per visitor so the group can still be+ // collapsed afterwards.+ if (activeVisitorId && activeVisitorId !== revealedVisitorId) {+ setRevealedVisitorId(activeVisitorId);+ if (collapsed.includes(activeVisitorId))+ setCollapsed(collapsed.filter((id) => id !== activeVisitorId));+ }++ const expanded = groups.map((group) => group.visitor.id).filter((id) => !collapsed.includes(id));++ return (+ <SideBarLayout+ body={+ <Flexbox gap={4} paddingInline={4}>+ <Flexbox horizontal align={'center'} gap={4} paddingBlock={4} paddingInline={8}>+ <Text fontSize={12} type={'secondary'} weight={500}>+ {t('shareVisitorTopics.title')}+ </Text>+ {groups.length > 0 && (+ <Text fontSize={11} style={COUNT_STYLE} type={'secondary'}>+ {groups.length}+ </Text>+ )}+ </Flexbox>+ {error && groups.length === 0 ? (+ <AsyncError error={error} variant={'inline'} onRetry={() => void mutate()} />+ ) : !isLoading && groups.length === 0 ? (+ <Text fontSize={12} style={{ paddingInline: 8 }} type={'secondary'}>+ {t('shareVisitorTopics.empty')}+ </Text>+ ) : (+ <AccordionRoot+ indicatorPlacement="inline"+ style={{ gap: 2 }}+ value={expanded}+ onValueChange={(next) => {+ const open = next as string[];+ setCollapsed(+ groups.map((group) => group.visitor.id).filter((id) => !open.includes(id)),+ );+ }}+ >+ {groups.map((group) => (+ <VisitorGroup+ activeTopicId={activeTopicId}+ agentId={agentId}+ group={group}+ key={group.visitor.id}+ />+ ))}+ </AccordionRoot>+ )}+ </Flexbox>+ }+ header={+ <>+ <Flexbox horizontal align={'center'} paddingBlock={8} paddingInline={4}>+ <NavItem+ as={'button'}+ flex={1}+ icon={ChevronLeftIcon}+ style={{ textAlign: 'start' }}+ title={t('shareVisitorTopics.backToShare')}+ onClick={() => navigate(buildAgentProfileTabPath(agentId, 'share'))}+ />+ <ToggleLeftPanelButton />+ </Flexbox>+ <Flexbox paddingBlock={'0 8px'} paddingInline={6}>+ <Agent />+ </Flexbox>+ </>+ }+ />+ );+};++export default ShareVisitorSidebarNav;diff --git a/src/features/ShareVisitorTopics/SidebarSection.tsx b/src/features/ShareVisitorTopics/SidebarSection.tsxdeleted file mode 100644index 323cd1e8f0a..00000000000--- a/src/features/ShareVisitorTopics/SidebarSection.tsx+++ /dev/null@@ -1,176 +0,0 @@-'use client';--import { AGENT_SHARE_VISITOR_TOPIC_URL } from '@lobechat/const';-import type { ShareVisitorTopicGroup } from '@lobechat/types';-import {- AccordionHeader,- AccordionItem,- AccordionPanel,- AccordionRoot,- accordionStyles,- AccordionTrigger,- ActionIcon,- cx,- Flexbox,- Text,-} from '@lobehub/ui';-import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';-import { ArrowRight } from 'lucide-react';-import { type MouseEvent, useState } from 'react';-import { useTranslation } from 'react-i18next';--import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';-import UserAvatar from '@/components/UserAvatar';-import { useNavigateToAgentTopics } from '@/features/AgentSidebar/Topic/hooks/useTopicNavigation';-import NavItem from '@/features/NavPanel/components/NavItem';-import SectionTitle, { useSectionTriggerStyle } from '@/features/NavPanel/components/SectionTitle';-import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';-import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';-import { isMobileSurface } from '@/utils/mobileSurface';--import { useActiveVisitorTopic } from './useActiveVisitorTopic';-import { useShareVisitorTopics } from './useShareVisitorTopics';--const COUNT_STYLE = { fontVariantNumeric: 'tabular-nums' } as const;--/** Lines topic titles up with the Agent's own topic rows, which lead with a status icon slot. */-const ICON_PLACEHOLDER = <span aria-hidden style={{ flex: 'none', width: 16 }} />;--const VisitorGroup = ({- activeTopicId,- agentId,- group,-}: {- activeTopicId: string | undefined;- agentId: string;- group: ShareVisitorTopicGroup;-}) => {- const { t } = useTranslation('topic');- const sectionTriggerStyle = useSectionTriggerStyle();- const navigate = useWorkspaceAwareNavigate();- const workspaceSlug = useActiveWorkspaceSlug();- const name = group.visitor.name || t('management.shareVisitors.unnamedVisitor');-- return (- <AccordionItem value={group.visitor.id}>- <AccordionHeader>- <AccordionTrigger style={sectionTriggerStyle}>- <Flexbox horizontal align={'center'} gap={6} height={24} style={{ minWidth: 0 }}>- <UserAvatar- avatar={group.visitor.avatar}- name={name}- shape={'circle'}- size={16}- style={{ flex: 'none' }}- />- <SectionTitle>{name}</SectionTitle>- <Text fontSize={11} style={COUNT_STYLE} type={'secondary'}>- {group.topics.length}- </Text>- </Flexbox>- </AccordionTrigger>- </AccordionHeader>- <AccordionPanel contentStyle={{ padding: 0 }}>- <Flexbox gap={1} paddingBlock={1}>- {group.topics.map((topic) => {- const path = AGENT_SHARE_VISITOR_TOPIC_URL(agentId, topic.id);- return (- <NavItem- titleMarquee- active={topic.id === activeTopicId}- href={buildWorkspaceAwarePath(path, workspaceSlug)}- icon={ICON_PLACEHOLDER}- key={topic.id}- title={topic.title || topic.preview || t('shareVisitorTopics.untitled')}- titleColor={cssVar.colorText}- onClick={() => navigate(path)}- />- );- })}- </Flexbox>- </AccordionPanel>- </AccordionItem>- );-};--interface ShareVisitorTopicsSectionProps {- agentId: string;- itemKey: string;-}--/**- * Visitors' conversations with the Agent through its share link, as run topics grouped by visitor.- * Shown only while the share lets the owner read them; each topic opens read-only.- */-const ShareVisitorTopicsSection = ({ agentId, itemKey }: ShareVisitorTopicsSectionProps) => {- const { t } = useTranslation('topic');- const sectionTriggerStyle = useSectionTriggerStyle();- const groups = useShareVisitorTopics(agentId);- const navigateToAgentTopics = useNavigateToAgentTopics();- const { activeTopicId, activeVisitorId } = useActiveVisitorTopic(groups);- const [expanded, setExpanded] = useState<string[]>([]);- const [revealedVisitorId, setRevealedVisitorId] = useState<string>();-- // Opening a topic from elsewhere (the Topics page) reveals it in its visitor's group, once per- // visitor so the group can still be collapsed afterwards.- if (activeVisitorId && activeVisitorId !== revealedVisitorId) {- setRevealedVisitorId(activeVisitorId);- if (!expanded.includes(activeVisitorId)) setExpanded([...expanded, activeVisitorId]);- }-- if (groups.length === 0) return null;-- return (- <AccordionItem value={itemKey}>- <AccordionHeader>- <AccordionTrigger style={sectionTriggerStyle}>- <Flexbox horizontal align="center" gap={4}>- <SectionTitle>{t('shareVisitorTopics.title')}</SectionTitle>- <Text fontSize={11} style={COUNT_STYLE} type="secondary">- {groups.length}- </Text>- </Flexbox>- </AccordionTrigger>- {/* Same hover arrow as the Topics section, opening the Topics page on the Share source. */}- <div- className={cx(- 'accordion-action',- accordionStyles.action,- accordionStyles.actionBorderless,- isMobileSurface() && accordionStyles.actionAlwaysVisible,- )}- >- <ActionIcon- icon={ArrowRight}- size={'small'}- title={t('shareVisitorTopics.viewAll')}- onClick={(e: MouseEvent) => {- // Stop the click from toggling the accordion header.- e.stopPropagation();- navigateToAgentTopics(agentId, 'share');- }}- />- </div>- </AccordionHeader>- <AccordionPanel contentStyle={{ padding: 0 }}>- <AccordionRoot- indicatorPlacement="inline"- style={{ gap: 2 }}- value={expanded}- onValueChange={(next) => setExpanded(next as string[])}- >- {groups.map((group) => (- <VisitorGroup- activeTopicId={activeTopicId}- agentId={agentId}- group={group}- key={group.visitor.id}- />- ))}- </AccordionRoot>- </AccordionPanel>- </AccordionItem>- );-};--export default ShareVisitorTopicsSection;diff --git a/src/features/ShareVisitorTopics/latestVisitorTopic.test.ts b/src/features/ShareVisitorTopics/latestVisitorTopic.test.tsnew file mode 100644index 00000000000..d1f8493c816--- /dev/null+++ b/src/features/ShareVisitorTopics/latestVisitorTopic.test.ts@@ -0,0 +1,53 @@+import type { ShareVisitorTopic, ShareVisitorTopicGroup } from '@lobechat/types';+import { describe, expect, it } from 'vitest';++import { getLatestVisitorTopicId, isShareVisitorRoute } from './latestVisitorTopic';++const topic = (id: string, updatedAt: string): ShareVisitorTopic => ({+ createdAt: new Date(updatedAt),+ id,+ preview: null,+ title: null,+ totalCost: 0,+ totalTokens: 0,+ updatedAt: new Date(updatedAt),+});++const group = (visitorId: string, topics: ShareVisitorTopic[]): ShareVisitorTopicGroup => ({+ topics,+ visitor: { avatar: null, id: visitorId, name: null },+});++describe('getLatestVisitorTopicId', () => {+ it('picks the most recently updated topic across visitors', () => {+ expect(+ getLatestVisitorTopicId([+ group('v1', [topic('t1', '2026-11-20T00:00:00Z')]),+ group('v2', [topic('t2', '2026-11-22T00:00:00Z'), topic('t3', '2026-11-01T00:00:00Z')]),+ ]),+ ).toBe('t2');+ });++ it('returns undefined without visitor topics', () => {+ expect(getLatestVisitorTopicId([])).toBeUndefined();+ });+});++describe('isShareVisitorRoute', () => {+ it.each([+ '/agent/agt_1/visitor',+ '/agent/agt_1/visitor/',+ '/agent/agt_1/visitor/tpc_1',+ '/acme/agent/agt_1/visitor/tpc_1',+ '/_dangerous_local_dev_proxy/agent/agt_1/visitor',+ ])('matches %s', (pathname) => {+ expect(isShareVisitorRoute(pathname)).toBe(true);+ });++ it.each(['/agent/agt_1', '/agent/agt_1/share', '/agent/agt_1/tpc_1', '/agent/agt_1/visitor/a/b'])(+ 'does not match %s',+ (pathname) => {+ expect(isShareVisitorRoute(pathname)).toBe(false);+ },+ );+});diff --git a/src/features/ShareVisitorTopics/latestVisitorTopic.ts b/src/features/ShareVisitorTopics/latestVisitorTopic.tsnew file mode 100644index 00000000000..7d2733b804c--- /dev/null+++ b/src/features/ShareVisitorTopics/latestVisitorTopic.ts@@ -0,0 +1,22 @@+import type { ShareVisitorTopicGroup } from '@lobechat/types';++/** The most recently active visitor topic across all visitors, which the visitors page opens on. */+export const getLatestVisitorTopicId = (groups: ShareVisitorTopicGroup[]): string | undefined => {+ let latest: { id: string; updatedAt: number } | undefined;+ for (const group of groups) {+ for (const topic of group.topics) {+ const updatedAt = new Date(topic.updatedAt).getTime();+ if (!latest || updatedAt > latest.updatedAt) latest = { id: topic.id, updatedAt };+ }+ }+ return latest?.id;+};++const SHARE_VISITOR_ROUTE = /^(?:\/[^/]+)?\/agent\/[^/]+\/visitor(?:\/[^/]+)?\/?$/;++/**+ * Whether the URL is the visitors page or one of its topics, where the sidebar lists visitors+ * instead of the Agent's own topics. Anchored on the Agent subroute, with an optional workspace slug.+ */+export const isShareVisitorRoute = (pathname: string) =>+ SHARE_VISITOR_ROUTE.test(pathname.replace(/^\/_dangerous_local_dev_proxy(?=\/)/, ''));diff --git a/src/features/ShareVisitorTopics/useShareVisitorTopics.ts b/src/features/ShareVisitorTopics/useShareVisitorTopics.tsindex 0faef087004..f8fc04681c5 100644--- a/src/features/ShareVisitorTopics/useShareVisitorTopics.ts+++ b/src/features/ShareVisitorTopics/useShareVisitorTopics.ts@@ -8,22 +8,29 @@ import { CHANNEL_IDLE_REFRESH_MS } from '@/store/channel/action';const EMPTY: ShareVisitorTopicGroup[] = [];/**- * Visitors' run topics with the Agent's share, by visitor. Empty unless the share lets its owner- * read visitor conversations. Visitors keep talking without notifying the owner, so the list- * refreshes like the idle Channel list.+ * Visitors' run topics with the Agent's share, by visitor, with the first read's loading state.+ * Empty unless the share lets its owner read visitor conversations. Visitors keep talking without+ * notifying the owner, so the list refreshes like the idle Channel list. `mutate` re-reads it, e.g.+ * right after the owner allows reading visitor conversations. `enabled` is false while Channels are+ * off for the user (or their flags have not loaded): the list is then unknown, not empty. A failed+ * read keeps `groups` empty too, so check `error` before calling the list empty.*/-export const useShareVisitorTopics = (agentId: string | undefined) => {+export const useShareVisitorTopicGroups = (agentId: string | undefined) => {const enabled = useChannelsEnabled();- const { data } = useClientDataSWR(+ const { data, error, isLoading, mutate } = useClientDataSWR(enabled && agentId ? ['shareVisitorTopics', agentId] : null,() => channelService.shareVisitorTopics(agentId!),// Most Agents are never shared: read once on open, and keep polling only while there are// visitors to follow.{ refreshInterval: (latest) => (latest?.length ? CHANNEL_IDLE_REFRESH_MS : 0) },);- return data ?? EMPTY;+ return { enabled, error, groups: data ?? EMPTY, isLoading, mutate };};+/** Visitors' run topics with the Agent's share, by visitor. */+export const useShareVisitorTopics = (agentId: string | undefined) =>+ useShareVisitorTopicGroups(agentId).groups;+/** A visitor's run topic with its transcript. A visitor may still be talking, so it refreshes. */export const useShareVisitorTopic = (topicId: string | undefined) =>useClientDataSWR(diff --git a/src/routes/(main)/agent/visitor/index.tsx b/src/routes/(main)/agent/visitor/index.tsxnew file mode 100644index 00000000000..02539901d49--- /dev/null+++ b/src/routes/(main)/agent/visitor/index.tsx@@ -0,0 +1,7 @@+'use client';++import ShareVisitorsLanding from '@/features/ShareVisitorTopics/Landing';++const ShareVisitorsPage = () => <ShareVisitorsLanding />;++export default ShareVisitorsPage;diff --git a/src/spa/router/agentPageRoutes.tsx b/src/spa/router/agentPageRoutes.tsxindex 2e2393b6800..bd8b22952e1 100644--- a/src/spa/router/agentPageRoutes.tsx+++ b/src/spa/router/agentPageRoutes.tsx@@ -192,6 +192,14 @@ export const agentPageChildren: RouteObject[] = [loader: agentUsageLoader,path: 'statistics',},+ {+ element: dynamicElement(+ () => import('@/routes/(main)/agent/visitor'),+ 'Desktop > Chat > Share Visitors',+ ),+ handle: { meta: agentShareVisitorTopicRouteMeta },+ path: 'visitor',+ },{element: dynamicElement(() => import('@/routes/(main)/agent/visitor/[topicId]'),diff --git a/src/spa/router/mobileAgentRoutes.tsx b/src/spa/router/mobileAgentRoutes.tsxindex cb1f5f71e34..95b277f8faf 100644--- a/src/spa/router/mobileAgentRoutes.tsx+++ b/src/spa/router/mobileAgentRoutes.tsx@@ -45,6 +45,8 @@ const agentSubPages = overlayRoutes(agentPageChildren, {mobileShellHeader: true,},}),+ // With no visitor topic to open there is no page header; the shell adds back + the sidebar drawer.+ 'visitor': (route) => ({ ...route, handle: { ...route.handle, mobileShellHeader: true } }),// Served from the task workspace (`mobileWorkspaceRoutes.tsx`) on mobile.'task/:taskId/:slug?': dropRoute,});diff --git a/src/spa/router/mobileRouter.test.tsx b/src/spa/router/mobileRouter.test.tsxindex 0e8b85ef7c1..6612d3f4fe7 100644--- a/src/spa/router/mobileRouter.test.tsx+++ b/src/spa/router/mobileRouter.test.tsx@@ -123,6 +123,16 @@ describe('mobile community route layouts', () => {});});+describe('mobile share visitors page', () => {+ it('gives the empty visitors page the shell back header', () => {+ const route = matchRoutes(mobileRoutes, '/agent/agt_1/visitor')?.at(-1)?.route;++ expect(route?.path).toBe('visitor');+ expect((route?.handle as { mobileShellHeader?: boolean }).mobileShellHeader).toBe(true);+ expect(getRouteMetaFromHandle(route?.handle)?.titleKey).toBeDefined();+ });+});+describe('mobile Marketplace skill and connector pages', () => {it.each([['/marketplace/mcp/installed', 'mcp/installed'],