🤯 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(topic): add bot channel source filter to topics management page (#18788)
Arvin Xu9ae2f4f192dd
diff --git a/locales/en-US/topic.json b/locales/en-US/topic.jsonindex 8d7c7273808..2534f0cdf44 100644--- a/locales/en-US/topic.json+++ b/locales/en-US/topic.json@@ -175,6 +175,8 @@"management.empty.noTopics.action": "Start new chat","management.empty.noTopics.desc": "Start a conversation with this agent to create your first topic.","management.empty.noTopics.title": "No topics yet",+ "management.filters.botChannel.empty": "No channels",+ "management.filters.botChannel.label": "Channel","management.filters.project.empty": "No projects","management.filters.project.label": "Project","management.filters.status.active": "Active",@@ -189,6 +191,7 @@"management.filters.time.today": "Today","management.filters.time.week": "Past week","management.filters.trigger.api": "API",+ "management.filters.trigger.bot": "Channel","management.filters.trigger.chat": "Chat","management.filters.trigger.eval": "Eval","management.filters.trigger.label": "Trigger",diff --git a/locales/zh-CN/topic.json b/locales/zh-CN/topic.jsonindex ddfb4f6e6c4..5bcb32a506f 100644--- a/locales/zh-CN/topic.json+++ b/locales/zh-CN/topic.json@@ -175,6 +175,8 @@"management.empty.noTopics.action": "开始新对话","management.empty.noTopics.desc": "和这个助手聊聊,创建第一个话题。","management.empty.noTopics.title": "还没有话题",+ "management.filters.botChannel.empty": "暂无频道",+ "management.filters.botChannel.label": "频道","management.filters.project.empty": "暂无项目","management.filters.project.label": "项目","management.filters.status.active": "活跃",@@ -189,6 +191,7 @@"management.filters.time.today": "今天","management.filters.time.week": "最近一周","management.filters.trigger.api": "API",+ "management.filters.trigger.bot": "频道","management.filters.trigger.chat": "对话","management.filters.trigger.eval": "评测","management.filters.trigger.label": "来源",diff --git a/packages/locales/src/default/topic.ts b/packages/locales/src/default/topic.tsindex 5cdae9fff6d..30ba1900a70 100644--- a/packages/locales/src/default/topic.ts+++ b/packages/locales/src/default/topic.ts@@ -217,6 +217,8 @@ export default {'management.empty.noTopics.desc':'Start a conversation with this agent to create your first topic.','management.empty.noTopics.title': 'No topics yet',+ 'management.filters.botChannel.empty': 'No channels',+ 'management.filters.botChannel.label': 'Channel','management.filters.project.empty': 'No projects','management.filters.project.label': 'Project','management.filters.status.active': 'Active',@@ -231,6 +233,7 @@ export default {'management.filters.time.today': 'Today','management.filters.time.week': 'Past week','management.filters.trigger.api': 'API',+ 'management.filters.trigger.bot': 'Channel','management.filters.trigger.chat': 'Chat','management.filters.trigger.eval': 'Eval','management.filters.trigger.label': 'Trigger',diff --git a/src/features/AgentTopicManager/Toolbar.tsx b/src/features/AgentTopicManager/Toolbar.tsxindex 5ba379d08eb..2043c297986 100644--- a/src/features/AgentTopicManager/Toolbar.tsx+++ b/src/features/AgentTopicManager/Toolbar.tsx@@ -8,6 +8,7 @@ import {CalendarRange,ChevronDown,FolderClosed,+ Hash,LayoutGrid,List as ListIcon,ListFilter,@@ -23,11 +24,19 @@ import {import { memo, type ReactNode, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { getPlatformIcon } from '@/routes/(main)/agent/channel/const';import { useChatStore } from '@/store/chat';import { topicSelectors } from '@/store/chat/selectors';import { useTopicsViewStore } from './store';-import type { GroupBy, SortBy, StatusFilter, TimeRangeFilter, TriggerFilter } from './types';+import type {+ BotChannelOption,+ GroupBy,+ SortBy,+ StatusFilter,+ TimeRangeFilter,+ TriggerFilter,+} from './types';const CONTROL_HEIGHT = 32;const THREE_MONTHS_MS = 90 * 24 * 60 * 60 * 1000;@@ -144,10 +153,11 @@ const STATUS_OPTIONS: { key: StatusFilter; labelKey: string }[] = [{ key: 'completed', labelKey: 'management.filters.status.completed' },];-const TRIGGER_OPTIONS: TriggerFilter[] = ['chat', 'api', 'task', 'eval'];+const TRIGGER_OPTIONS: TriggerFilter[] = ['chat', 'bot', 'api', 'task', 'eval'];const TRIGGER_ICON: Record<TriggerFilter, LucideIcon> = {api: Webhook,+ bot: Hash,chat: MessageCircle,eval: TestTubeIcon,task: ListTodoIcon,@@ -160,6 +170,7 @@ const SORT_OPTIONS: SortBy[] = ['updatedAt', 'createdAt', 'title'];const GROUP_OPTIONS: GroupBy[] = ['byTime', 'byProject', 'none'];interface ToolbarProps {+ botChannelOptions: BotChannelOption[];projects: { label: string; value: string }[];statusCounts: Record<StatusFilter, number>;}@@ -170,18 +181,19 @@ const CheckMark = ({ visible }: { visible: boolean }) => (interface FilterChipProps {icon?: LucideIcon;+ iconNode?: ReactNode;items: DropdownItem[];label: string;onClear: () => void;value: ReactNode;}-const FilterChip = memo<FilterChipProps>(({ icon, label, value, items, onClear }) => {+const FilterChip = memo<FilterChipProps>(({ icon, iconNode, label, value, items, onClear }) => {return (<span className={styles.chip}><DropdownMenu items={items}><span className={styles.chipMain}>- {icon && <Icon icon={icon} size={12} />}+ {iconNode ?? (icon && <Icon icon={icon} size={12} />)}<Text style={{ color: cssVar.colorTextSecondary, fontSize: 12 }}>{label}:</Text><span className={styles.chipValue}>{value}</span><Icon icon={ChevronDown} size={10} />@@ -202,7 +214,7 @@ const FilterChip = memo<FilterChipProps>(({ icon, label, value, items, onClear });});-const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {+const Toolbar = memo<ToolbarProps>(({ projects, statusCounts, botChannelOptions }) => {const { t } = useTranslation('topic');const topics = useChatStore(topicSelectors.agentTopicsViewTopics);@@ -214,6 +226,10 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {const setGroupIds = useTopicsViewStore((s) => s.setGroupIds);const triggers = useTopicsViewStore((s) => s.triggers);const setTriggers = useTopicsViewStore((s) => s.setTriggers);+ const toggleTrigger = useTopicsViewStore((s) => s.toggleTrigger);+ const botChannels = useTopicsViewStore((s) => s.botChannels);+ const setBotChannels = useTopicsViewStore((s) => s.setBotChannels);+ const toggleBotChannel = useTopicsViewStore((s) => s.toggleBotChannel);const timeRange = useTopicsViewStore((s) => s.timeRange);const setTimeRange = useTopicsViewStore((s) => s.setTimeRange);const sortBy = useTopicsViewStore((s) => s.sortBy);@@ -230,10 +246,9 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {icon: <Icon icon={TRIGGER_ICON[tr]} size={14} />,key: tr,label: t(`management.filters.trigger.${tr}` as any) as string,- onClick: () =>- setTriggers(triggers.includes(tr) ? triggers.filter((x) => x !== tr) : [...triggers, tr]),+ onClick: () => toggleTrigger(tr),})),- [triggers, t, setTriggers],+ [triggers, t, toggleTrigger],);const projectItems: DropdownItem[] = useMemo(() => {@@ -253,6 +268,24 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {}));}, [projects, groupIds, t, setGroupIds]);+ // Flattened "send source" filter: one entry per bot platform (per review,+ // only distinguish tg/discord level — no per-channel submenu).+ const botChannelItems: DropdownItem[] = useMemo(() => {+ if (botChannelOptions.length === 0) {+ return [{ disabled: true, key: 'empty', label: t('management.filters.botChannel.empty') }];+ }+ return botChannelOptions.map((option) => {+ const PlatformIcon = getPlatformIcon(option.key);+ return {+ extra: <CheckMark visible={botChannels.includes(option.key)} />,+ icon: PlatformIcon ? <PlatformIcon size={14} /> : <Icon icon={Hash} size={14} />,+ key: option.key,+ label: option.label,+ onClick: () => toggleBotChannel(option.key),+ };+ });+ }, [botChannelOptions, botChannels, t, toggleBotChannel]);+const timeItems: DropdownItem[] = useMemo(() =>TIME_OPTIONS.map((r) => ({@@ -288,8 +321,9 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {const triggerApplied = triggers.length > 0;const projectApplied = groupIds.length > 0;+ const botChannelApplied = botChannels.length > 0;const timeApplied = timeRange !== 'all';- const anyFilterApplied = triggerApplied || projectApplied || timeApplied;+ const anyFilterApplied = triggerApplied || projectApplied || botChannelApplied || timeApplied;const addFilterItems: DropdownItem[] = useMemo(() => {const items: DropdownItem[] = [];@@ -311,6 +345,15 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {type: 'submenu',});}+ if (!botChannelApplied) {+ items.push({+ children: botChannelItems,+ icon: <Icon icon={Hash} size={14} />,+ key: 'botChannel',+ label: t('management.filters.botChannel.label'),+ type: 'submenu',+ });+ }if (!timeApplied) {items.push({children: timeItems,@@ -321,7 +364,17 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {});}return items;- }, [triggerApplied, projectApplied, timeApplied, triggerItems, projectItems, timeItems, t]);+ }, [+ triggerApplied,+ projectApplied,+ botChannelApplied,+ timeApplied,+ triggerItems,+ projectItems,+ botChannelItems,+ timeItems,+ t,+ ]);const projectChipValue = useMemo(() => {if (groupIds.length === 1) {@@ -335,6 +388,19 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {? (t(`management.filters.trigger.${triggers[0]}` as any) as string): `${triggers.length} selected`;+ // Single selection shows the channel (platform) name; multi shows a count.+ const botChannelChipValue = useMemo(() => {+ if (botChannels.length !== 1) return `${botChannels.length} selected`;+ const selected = botChannels[0];+ return botChannelOptions.find((o) => o.key === selected)?.label ?? selected;+ }, [botChannels, botChannelOptions]);++ const botChannelChipIcon = useMemo(() => {+ if (botChannels.length !== 1) return <Icon icon={Hash} size={12} />;+ const PlatformIcon = getPlatformIcon(botChannels[0]);+ return PlatformIcon ? <PlatformIcon size={12} /> : <Icon icon={Hash} size={12} />;+ }, [botChannels]);+const handleArchiveStale = useCallback(() => {const cutoff = Date.now() - THREE_MONTHS_MS;const stale = (topics ?? []).filter((tp) => {@@ -381,6 +447,7 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {onClick: () => {setTriggers([]);setGroupIds([]);+ setBotChannels([]);setTimeRange('all');},},@@ -403,6 +470,7 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {t,setTriggers,setGroupIds,+ setBotChannels,setTimeRange,handleArchiveStale,]);@@ -457,6 +525,15 @@ const Toolbar = memo<ToolbarProps>(({ projects, statusCounts }) => {onClear={() => setGroupIds([])}/>)}+ {botChannelApplied && (+ <FilterChip+ iconNode={botChannelChipIcon}+ items={botChannelItems}+ label={t('management.filters.botChannel.label')}+ value={botChannelChipValue}+ onClear={() => setBotChannels([])}+ />+ )}{timeApplied && (<FilterChipicon={CalendarRange}diff --git a/src/features/AgentTopicManager/TopicCard.tsx b/src/features/AgentTopicManager/TopicCard.tsxindex 3d92ca13edd..20f1b19d3d5 100644--- a/src/features/AgentTopicManager/TopicCard.tsx+++ b/src/features/AgentTopicManager/TopicCard.tsx@@ -11,6 +11,7 @@ import { useTranslation } from 'react-i18next';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { useActivityTime } from '@/hooks/useActivityTime';+import { getPlatformIcon } from '@/routes/(main)/agent/channel/const';import type { ChatTopic } from '@/types/topic';import StatusDot from './StatusDot';@@ -117,6 +118,9 @@ const TopicCard = memo<TopicCardProps>(({ topic, agentId }) => {const projectLabel = getProjectLabel(topic);const status = topic.status ?? 'active';+ // Bot source platform icon (same identity mark as the sidebar topic item).+ const botPlatform = topic.metadata?.bot?.platform;+ const BotPlatformIcon = botPlatform ? getPlatformIcon(botPlatform) : undefined;// Preview priority: user-written description → AI history summary → first user// message (sliced server-side when neither richer field exists).const preview =@@ -148,6 +152,13 @@ const TopicCard = memo<TopicCardProps>(({ topic, agentId }) => {{topic.favorite && (<Icon icon={Star} size={13} style={{ color: cssVar.colorWarning, flexShrink: 0 }} />)}+ {BotPlatformIcon && (+ <BotPlatformIcon+ color={cssVar.colorTextDescription}+ size={14}+ style={{ flexShrink: 0 }}+ />+ )}<Text className={styles.title} fontSize={14} weight={600}>{topic.title || t('defaultTitle')}</Text>diff --git a/src/features/AgentTopicManager/TopicListView.tsx b/src/features/AgentTopicManager/TopicListView.tsxindex 87d63c5d1a3..53c224b832e 100644--- a/src/features/AgentTopicManager/TopicListView.tsx+++ b/src/features/AgentTopicManager/TopicListView.tsx@@ -12,6 +12,7 @@ import { useTranslation } from 'react-i18next';import { useTopicItemDropdownMenu } from '@/features/AgentSidebar/Topic/List/Item/useDropdownMenu';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { useActivityTime } from '@/hooks/useActivityTime';+import { getPlatformIcon } from '@/routes/(main)/agent/channel/const';import type { ChatTopic } from '@/types/topic';import StatusDot from './StatusDot';@@ -178,6 +179,9 @@ const Row = memo<RowProps>(({ topic, agentId }) => {? (rawTrigger as TriggerFilter): 'chat';const triggerLabel = t(`management.filters.trigger.${triggerKey}` as any) as string;+ // Bot source platform icon (same identity mark as the sidebar topic item).+ const botPlatform = topic.metadata?.bot?.platform;+ const BotPlatformIcon = botPlatform ? getPlatformIcon(botPlatform) : undefined;return (<div@@ -197,6 +201,13 @@ const Row = memo<RowProps>(({ topic, agentId }) => {{topic.favorite && (<Icon icon={Star} size={12} style={{ color: cssVar.colorWarning, flexShrink: 0 }} />)}+ {BotPlatformIcon && (+ <BotPlatformIcon+ color={cssVar.colorTextDescription}+ size={13}+ style={{ flexShrink: 0 }}+ />+ )}<Text className={styles.title} fontSize={13} weight={500}>{topic.title || t('defaultTitle')}</Text>diff --git a/src/features/AgentTopicManager/index.tsx b/src/features/AgentTopicManager/index.tsxindex 51024fc55af..7ba1add250f 100644--- a/src/features/AgentTopicManager/index.tsx+++ b/src/features/AgentTopicManager/index.tsx@@ -24,7 +24,9 @@ import Toolbar from './Toolbar';import TopicGrid from './TopicGrid';import TopicListView from './TopicListView';import {+ buildBotChannelOptions,getProjectFilterLabel,+ matchesBotChannel,matchesGroup,matchesStatus,matchesTimeRange,@@ -59,6 +61,7 @@ const AgentTopicManager = memo(() => {const status = useTopicsViewStore((s) => s.status);const groupIds = useTopicsViewStore((s) => s.groupIds);const triggers = useTopicsViewStore((s) => s.triggers);+ const botChannels = useTopicsViewStore((s) => s.botChannels);const timeRange = useTopicsViewStore((s) => s.timeRange);const sortBy = useTopicsViewStore((s) => s.sortBy);const groupBy = useTopicsViewStore((s) => s.groupBy);@@ -66,6 +69,7 @@ const AgentTopicManager = memo(() => {const setStatus = useTopicsViewStore((s) => s.setStatus);const setGroupIds = useTopicsViewStore((s) => s.setGroupIds);const setTriggers = useTopicsViewStore((s) => s.setTriggers);+ const setBotChannels = useTopicsViewStore((s) => s.setBotChannels);const setTimeRange = useTopicsViewStore((s) => s.setTimeRange);const setSearch = useTopicsViewStore((s) => s.setSearch);@@ -108,9 +112,10 @@ const AgentTopicManager = memo(() => {(t) =>matchesGroup(t, groupIds) &&matchesTrigger(t, triggers) &&- matchesTimeRange(t, timeRange),+ matchesTimeRange(t, timeRange) &&+ matchesBotChannel(t, botChannels),),- [baseTopics, groupIds, triggers, timeRange],+ [baseTopics, groupIds, triggers, timeRange, botChannels],);const filtered = useMemo(() => {@@ -156,12 +161,15 @@ const AgentTopicManager = memo(() => {return Array.from(map, ([value, label]) => ({ label, value }));}, [baseTopics]);+ const botChannelOptions = useMemo(() => buildBotChannelOptions(baseTopics), [baseTopics]);+const totalAfterFilter = filtered.length;// 'active' is the default tab, so it doesn't count as a user-applied filterconst hasActiveFilters =(status !== 'active' && status !== 'all') ||groupIds.length > 0 ||triggers.length > 0 ||+ botChannels.length > 0 ||timeRange !== 'all' ||trimmedSearch.length > 0;@@ -172,6 +180,7 @@ const AgentTopicManager = memo(() => {setStatus('all');setGroupIds([]);setTriggers([]);+ setBotChannels([]);setTimeRange('all');setSearch('');};@@ -224,7 +233,11 @@ const AgentTopicManager = memo(() => {width: '100%',}}>- <Toolbar projects={projects} statusCounts={statusCounts} />+ <Toolbar+ botChannelOptions={botChannelOptions}+ projects={projects}+ statusCounts={statusCounts}+ /><BulkActionBar />{!isSearchMode && error && !isLoading && baseTopics.length === 0 ? (<AsyncErrordiff --git a/src/features/AgentTopicManager/store.test.ts b/src/features/AgentTopicManager/store.test.tsnew file mode 100644index 00000000000..fda1df13209--- /dev/null+++ b/src/features/AgentTopicManager/store.test.ts@@ -0,0 +1,29 @@+import { beforeEach, describe, expect, it } from 'vitest';++import { useTopicsViewStore } from './store';++describe('AgentTopicManager store', () => {+ beforeEach(() => {+ useTopicsViewStore.getState().reset();+ });++ it('switches the source to bot when selecting a channel', () => {+ useTopicsViewStore.getState().toggleBotChannel('discord');++ expect(useTopicsViewStore.getState()).toMatchObject({+ botChannels: ['discord'],+ triggers: ['bot'],+ });+ });++ it('clears selected channels when removing the bot source', () => {+ useTopicsViewStore.setState({ botChannels: ['discord'], triggers: ['bot'] });++ useTopicsViewStore.getState().toggleTrigger('bot');++ expect(useTopicsViewStore.getState()).toMatchObject({+ botChannels: [],+ triggers: [],+ });+ });+});diff --git a/src/features/AgentTopicManager/store.ts b/src/features/AgentTopicManager/store.tsindex 78cbd8d857a..22602a89ccb 100644--- a/src/features/AgentTopicManager/store.ts+++ b/src/features/AgentTopicManager/store.ts@@ -1,6 +1,7 @@import { create } from 'zustand';import type {+ BotChannelFilter,GroupBy,SortBy,StatusFilter,@@ -10,6 +11,7 @@ import type {} from './types';interface TopicsViewState {+ botChannels: BotChannelFilter[];groupBy: GroupBy;groupIds: string[];search: string;@@ -27,6 +29,7 @@ interface TopicsViewActions {exitSelectMode: () => void;reset: () => void;selectAll: (ids: string[]) => void;+ setBotChannels: (botChannels: BotChannelFilter[]) => void;setGroupBy: (groupBy: GroupBy) => void;setGroupIds: (groupIds: string[]) => void;setSearch: (search: string) => void;@@ -35,11 +38,14 @@ interface TopicsViewActions {setTimeRange: (range: TimeRangeFilter) => void;setTriggers: (triggers: TriggerFilter[]) => void;setViewMode: (mode: ViewMode) => void;+ toggleBotChannel: (botChannel: BotChannelFilter) => void;toggleSelected: (id: string) => void;toggleSelectMode: () => void;+ toggleTrigger: (trigger: TriggerFilter) => void;}const initialState: TopicsViewState = {+ botChannels: [],groupBy: 'byTime',groupIds: [],search: '',@@ -58,6 +64,7 @@ export const useTopicsViewStore = create<TopicsViewState & TopicsViewActions>((sexitSelectMode: () => set({ selectMode: false, selectedIds: [] }),reset: () => set(initialState),selectAll: (ids) => set({ selectedIds: ids }),+ setBotChannels: (botChannels) => set({ botChannels }),setGroupBy: (groupBy) => set({ groupBy }),setGroupIds: (groupIds) => set({ groupIds }),setSearch: (search) => set({ search }),@@ -66,6 +73,24 @@ export const useTopicsViewStore = create<TopicsViewState & TopicsViewActions>((ssetTimeRange: (timeRange) => set({ timeRange }),setTriggers: (triggers) => set({ triggers }),setViewMode: (viewMode) => set({ viewMode }),+ toggleBotChannel: (botChannel) =>+ set((state) => {+ if (state.botChannels.includes(botChannel)) {+ return { botChannels: state.botChannels.filter((item) => item !== botChannel) };+ }++ return { botChannels: [...state.botChannels, botChannel], triggers: ['bot'] };+ }),+ toggleTrigger: (trigger) =>+ set((state) => {+ const removing = state.triggers.includes(trigger);+ return {+ ...(removing && trigger === 'bot' ? { botChannels: [] } : {}),+ triggers: removing+ ? state.triggers.filter((item) => item !== trigger)+ : [...state.triggers, trigger],+ };+ }),toggleSelectMode: () =>set((s) => ({ selectMode: !s.selectMode, selectedIds: s.selectMode ? [] : s.selectedIds })),toggleSelected: (id) =>diff --git a/src/features/AgentTopicManager/types.ts b/src/features/AgentTopicManager/types.tsindex c7de4fa691b..cdf78e88b0e 100644--- a/src/features/AgentTopicManager/types.ts+++ b/src/features/AgentTopicManager/types.ts@@ -2,10 +2,25 @@ export type ViewMode = 'card' | 'list';export type StatusFilter = 'all' | 'active' | 'running' | 'completed' | 'archived';-export type TriggerFilter = 'chat' | 'api' | 'task' | 'eval';+export type TriggerFilter = 'chat' | 'api' | 'task' | 'eval' | 'bot';export type TimeRangeFilter = 'all' | 'today' | 'week' | 'month';export type SortBy = 'updatedAt' | 'createdAt' | 'title';export type GroupBy = 'byProject' | 'byTime' | 'none';++/**+ * A bot source platform, identified by `topic.metadata.bot.platform`+ * (e.g. `discord` / `telegram`). One value selects topics that arrived+ * through any channel of that platform's bot.+ */+export type BotChannelFilter = string;++/** One selectable bot source platform inside the flattened channel menu. */+export interface BotChannelOption {+ /** Platform id, e.g. `discord` — the filter value. */+ key: string;+ /** Display label, e.g. `Discord` / `Telegram`. */+ label: string;+}diff --git a/src/features/AgentTopicManager/utils.test.ts b/src/features/AgentTopicManager/utils.test.tsindex 3499e4084d1..ccd5f8397f9 100644--- a/src/features/AgentTopicManager/utils.test.ts+++ b/src/features/AgentTopicManager/utils.test.ts@@ -1,13 +1,25 @@import type { ChatTopic } from '@/types/topic';-import { getProjectFilterLabel, getProjectLabel, matchesGroup } from './utils';+import {+ buildBotChannelOptions,+ getBotPlatformName,+ getProjectFilterLabel,+ getProjectLabel,+ matchesBotChannel,+ matchesGroup,+ matchesTrigger,+} from './utils';-const createTopic = (metadata: ChatTopic['metadata']): ChatTopic => ({+const createTopic = (+ metadata: ChatTopic['metadata'],+ overrides: Partial<ChatTopic> = {},+): ChatTopic => ({createdAt: 1,id: 'topic-1',metadata,title: 'Topic',updatedAt: 1,+ ...overrides,});describe('AgentTopicManager utils', () => {@@ -26,4 +38,74 @@ describe('AgentTopicManager utils', () => {expect(getProjectFilterLabel(topic)).toBe('repo');expect(getProjectLabel(topic)).toBe('repo/repo-fix · fix');});++ it('matches bot channel filters by metadata.bot.platform', () => {+ const topic = createTopic(+ {+ bot: {+ applicationId: 'app-1',+ isOwner: true,+ platform: 'discord',+ platformThreadId: 'discord:guild:channel:thread',+ senderExternalUserId: 'user-1',+ },+ },+ { trigger: 'bot' },+ );++ expect(matchesBotChannel(topic, [])).toBe(true);+ expect(matchesBotChannel(topic, ['discord'])).toBe(true);+ expect(matchesBotChannel(topic, ['telegram'])).toBe(false);+ expect(matchesTrigger(topic, ['bot'])).toBe(true);+ });++ it('never matches a bot channel filter when the topic has no bot metadata', () => {+ const topic = createTopic({});+ expect(matchesBotChannel(topic, ['discord'])).toBe(false);+ });++ it('builds flattened platform options from topics, deduped and labeled', () => {+ const discordA = createTopic({+ bot: {+ applicationId: 'app-1',+ isOwner: true,+ platform: 'discord',+ platformThreadId: 'discord:guild:channel-a',+ senderExternalUserId: 'user-1',+ },+ });+ const discordB = createTopic({+ bot: {+ applicationId: 'app-1',+ isOwner: false,+ platform: 'discord',+ platformThreadId: 'discord:guild:channel-b',+ senderExternalUserId: 'user-2',+ },+ });+ const telegram = createTopic({+ bot: {+ applicationId: 'tg-app',+ isOwner: true,+ platform: 'telegram',+ platformThreadId: 'telegram:chat-456',+ senderExternalUserId: 'user-3',+ },+ });+ const plainTopic = createTopic({});++ const options = buildBotChannelOptions([plainTopic, discordA, discordB, telegram]);++ // Flattened to the platform level only — two discord topics collapse to one entry.+ expect(options).toEqual([+ { key: 'discord', label: 'Discord' },+ { key: 'telegram', label: 'Telegram' },+ ]);+ });++ it('exposes human-readable platform names', () => {+ expect(getBotPlatformName('discord')).toBe('Discord');+ expect(getBotPlatformName('feishu')).toBe('Feishu');+ expect(getBotPlatformName('unknown-platform')).toBe('unknown-platform');+ });});diff --git a/src/features/AgentTopicManager/utils.ts b/src/features/AgentTopicManager/utils.tsindex 8a9bfc677f8..51edfffbfb8 100644--- a/src/features/AgentTopicManager/utils.ts+++ b/src/features/AgentTopicManager/utils.ts@@ -6,7 +6,14 @@ import dayjs from 'dayjs';import type { ChatTopic } from '@/types/topic';-import type { SortBy, StatusFilter, TimeRangeFilter, TriggerFilter } from './types';+import type {+ BotChannelFilter,+ BotChannelOption,+ SortBy,+ StatusFilter,+ TimeRangeFilter,+ TriggerFilter,+} from './types';const DAY_MS = 24 * 60 * 60 * 1000;@@ -48,6 +55,12 @@ export const matchesTrigger = (topic: ChatTopic, triggers: TriggerFilter[]): booreturn triggers.includes(effective);};+export const matchesBotChannel = (topic: ChatTopic, botChannels: BotChannelFilter[]): boolean => {+ if (botChannels.length === 0) return true;+ const platform = topic.metadata?.bot?.platform;+ return !!platform && botChannels.includes(platform);+};+export const matchesTimeRange = (topic: ChatTopic, range: TimeRangeFilter): boolean => {if (range === 'all') return true;const updated = topic.updatedAt ? new Date(topic.updatedAt).getTime() : 0;@@ -114,6 +127,43 @@ export const getProjectLabel = (topic: ChatTopic): string | undefined => {return branch ? `${pathLabel} · ${branch}` : pathLabel;};+/** Client-side platform display names (server `PlatformDefinition.name`). */+const PLATFORM_DISPLAY_NAMES: Record<string, string> = {+ discord: 'Discord',+ feishu: 'Feishu',+ googlechat: 'Google Chat',+ imessage: 'iMessage',+ lark: 'Lark',+ line: 'Line',+ msteams: 'Microsoft Teams',+ qq: 'QQ',+ slack: 'Slack',+ telegram: 'Telegram',+ wechat: 'WeChat',+ whatsapp: 'WhatsApp',+};++/** Human-readable bot (platform) name, e.g. `discord` → `Discord`. */+export const getBotPlatformName = (platform: string): string =>+ PLATFORM_DISPLAY_NAMES[platform.toLowerCase()] ?? platform;++/**+ * Derive the flattened bot-source option list from a topic set — one entry+ * per platform that actually owns topics (per review: only distinguish+ * tg/discord level, no per-channel nesting).+ */+export const buildBotChannelOptions = (topics: ChatTopic[]): BotChannelOption[] => {+ const seen = new Set<string>();+ for (const topic of topics) {+ const platform = topic.metadata?.bot?.platform;+ if (platform) seen.add(platform);+ }+ return Array.from(seen).map((platform) => ({+ key: platform,+ label: getBotPlatformName(platform),+ }));+};+/*** Resolve the human-readable title for a time-bucket group ID produced by* `groupTopicsByUpdatedTime` (today / yesterday / week / month) or a dynamic