🤯 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(desktop): show running, awaiting-input and recent topics in the Dock menu (#20635)
Inneid98cee826c27
diff --git a/apps/desktop/resources/locales/en/menu.json b/apps/desktop/resources/locales/en/menu.jsonindex fcfbfcf2d92..97f1779a02b 100644--- a/apps/desktop/resources/locales/en/menu.json+++ b/apps/desktop/resources/locales/en/menu.json@@ -80,8 +80,10 @@"tray.quit": "Quit","tray.recent": "Recent","tray.recentAgents": "Recent Agents",+ "tray.running": "Running","tray.settings": "Settings","tray.show": "Show {{appName}}",+ "tray.waitingForHuman": "Awaiting Input","view.forceReload": "Force Reload","view.reload": "Reload","view.resetZoom": "Reset Zoom",diff --git a/apps/desktop/resources/locales/zh-CN/menu.json b/apps/desktop/resources/locales/zh-CN/menu.jsonindex 18f8c8608e1..8f17ce5d805 100644--- a/apps/desktop/resources/locales/zh-CN/menu.json+++ b/apps/desktop/resources/locales/zh-CN/menu.json@@ -85,8 +85,10 @@"tray.quit": "退出","tray.recent": "最近访问","tray.recentAgents": "最近使用的智能体",+ "tray.running": "运行中","tray.settings": "设置","tray.show": "显示 {{appName}}",+ "tray.waitingForHuman": "等待处理","view.forceReload": "强制重新加载","view.reload": "重新加载","view.resetZoom": "重置缩放",diff --git a/apps/desktop/src/main/core/ui/MenuManager.ts b/apps/desktop/src/main/core/ui/MenuManager.tsindex 1c59308fcd5..a27b74e8e84 100644--- a/apps/desktop/src/main/core/ui/MenuManager.ts+++ b/apps/desktop/src/main/core/ui/MenuManager.ts@@ -86,6 +86,10 @@ export class MenuManager {return this.platformImpl.buildTrayMenu(snapshot);}+ updateDockMenu(snapshot: TrayNavigationSnapshot) {+ this.platformImpl.updateDockMenu?.(snapshot);+ }+/*** Refresh menus*/diff --git a/apps/desktop/src/main/core/ui/TrayManager.ts b/apps/desktop/src/main/core/ui/TrayManager.tsindex 93b5b119fc5..0e504aba9f0 100644--- a/apps/desktop/src/main/core/ui/TrayManager.ts+++ b/apps/desktop/src/main/core/ui/TrayManager.ts@@ -84,6 +84,7 @@ export class TrayManager {updateNavigationSnapshot(snapshot: TrayNavigationSnapshot) {this.navigationSnapshot = snapshot;+ this.app.menuManager.updateDockMenu(snapshot);const mainTray = this.getMainTray();if (mainTray) mainTray.setMenu(this.app.menuManager.buildTrayMenu(snapshot));}diff --git a/apps/desktop/src/main/core/ui/__tests__/TrayManager.test.ts b/apps/desktop/src/main/core/ui/__tests__/TrayManager.test.tsindex 70aabc78e6f..9be510b71e6 100644--- a/apps/desktop/src/main/core/ui/__tests__/TrayManager.test.ts+++ b/apps/desktop/src/main/core/ui/__tests__/TrayManager.test.ts@@ -44,6 +44,7 @@ describe('TrayManager', () => {mockApp = {menuManager: {buildTrayMenu: vi.fn(() => ({ _mockMenu: true }) as any),+ updateDockMenu: vi.fn(),},storeManager: {get: vi.fn(() => true),@@ -89,6 +90,14 @@ describe('TrayManager', () => {expect(mockTray.setMenu).toHaveBeenCalledWith({ _mockMenu: true });});+ it('should forward navigation snapshots to the dock menu even without a tray', () => {+ const snapshot = { agents: [], pinned: [], recent: [] };++ trayManager.updateNavigationSnapshot(snapshot);++ expect(mockApp.menuManager.updateDockMenu).toHaveBeenCalledWith(snapshot);+ });+it('should skip tray initialization when app tray is disabled', () => {vi.mocked(mockApp.storeManager.get).mockReturnValue(false);diff --git a/apps/desktop/src/main/locales/default/menu.ts b/apps/desktop/src/main/locales/default/menu.tsindex fc38231024e..1095b258038 100644--- a/apps/desktop/src/main/locales/default/menu.ts+++ b/apps/desktop/src/main/locales/default/menu.ts@@ -85,8 +85,10 @@ const menu = {'tray.quit': 'Quit','tray.recent': 'Recent','tray.recentAgents': 'Recent Agents',+ 'tray.running': 'Running','tray.settings': 'Settings','tray.show': 'Show {{appName}}',+ 'tray.waitingForHuman': 'Awaiting Input','view.forceReload': 'Force Reload','view.reload': 'Reload','view.resetZoom': 'Reset Zoom',diff --git a/apps/desktop/src/main/menus/impls/macOS.test.ts b/apps/desktop/src/main/menus/impls/macOS.test.tsindex 49c292f88b8..067b7a045f8 100644--- a/apps/desktop/src/main/menus/impls/macOS.test.ts+++ b/apps/desktop/src/main/menus/impls/macOS.test.ts@@ -193,6 +193,25 @@ describe('MacOSMenu', () => {const dockMenu = (app.dock.setMenu as any).mock.calls[0][0];expect(dockMenu.template.some((item: any) => item.label === 'Quick Composer')).toBe(true);});++ it('should rebuild the dock menu with active topics and leave out system-provided items', () => {+ macOSMenu.updateDockMenu({+ activeTopics: [+ { status: 'running', subtitle: 'Researcher', title: 'Refactor auth', url: '/agent/a/t1' },+ ],+ agents: [{ id: 'a', title: 'Researcher', url: '/agent/a' }],+ pinned: [],+ recent: [],+ });++ const labels = (app.dock.setMenu as any).mock.calls[0][0].template.map(+ (item: any) => item.label,+ );+ expect(labels.slice(0, 2)).toEqual(['Running', 'Refactor auth']);+ expect(labels).not.toContain('Recent Agents');+ expect(labels).not.toContain('Quit');+ expect(labels).not.toContain('Settings');+ });});describe('refresh', () => {diff --git a/apps/desktop/src/main/menus/impls/macOS.ts b/apps/desktop/src/main/menus/impls/macOS.tsindex 8c8bbb71c89..1d4c017b378 100644--- a/apps/desktop/src/main/menus/impls/macOS.ts+++ b/apps/desktop/src/main/menus/impls/macOS.ts@@ -10,7 +10,7 @@ import { HETERO_AGENT_DIR } from '@/const/heteroAgent';import NotificationCtr from '@/controllers/NotificationCtr';import SystemController from '@/controllers/SystemCtr';-import { buildTrayMenuTemplate } from '../trayMenu';+import { buildDockMenuTemplate, buildTrayMenuTemplate } from '../trayMenu';import type { ContextMenuData, IMenuPlatform, MenuOptions } from '../types';import { BaseMenuPlatform } from './BaseMenuPlatform';@@ -18,6 +18,7 @@ export class MacOSMenu extends BaseMenuPlatform implements IMenuPlatform {private appMenu: Menu | null = null;private dockMenu: Menu | null = null;private trayMenu: Menu | null = null;+ private navigationSnapshot: TrayNavigationSnapshot = { agents: [], pinned: [], recent: [] };buildAndSetAppMenu(options?: MenuOptions): Menu {const template = this.getAppMenuTemplate(options);@@ -54,6 +55,11 @@ export class MacOSMenu extends BaseMenuPlatform implements IMenuPlatform {return this.trayMenu;}+ updateDockMenu(snapshot: TrayNavigationSnapshot): void {+ this.navigationSnapshot = snapshot;+ this.buildAndSetDockMenu();+ }+refresh(options?: MenuOptions): void {// Rebuild Application menuthis.buildAndSetAppMenu(options);@@ -739,23 +745,9 @@ export class MacOSMenu extends BaseMenuPlatform implements IMenuPlatform {private buildAndSetDockMenu() {if (!app.dock?.setMenu) return;- this.dockMenu = Menu.buildFromTemplate(this.getDockMenuTemplate());+ this.dockMenu = Menu.buildFromTemplate(+ buildDockMenuTemplate(this.app, this.navigationSnapshot),+ );app.dock.setMenu(this.dockMenu);}-- private getDockMenuTemplate(): MenuItemConstructorOptions[] {- const t = this.app.i18n.ns('menu');- const appName = app.getName();-- return [- {- click: () => this.app.browserManager.showMainWindow(),- label: t('tray.show', { appName }),- },- {- click: () => this.app.screenCaptureManager.startSession(),- label: t('tray.openMiniToolbar'),- },- ];- }}diff --git a/apps/desktop/src/main/menus/trayMenu.test.ts b/apps/desktop/src/main/menus/trayMenu.test.tsindex 537010b044d..bd03502b6f1 100644--- a/apps/desktop/src/main/menus/trayMenu.test.ts+++ b/apps/desktop/src/main/menus/trayMenu.test.ts@@ -42,7 +42,7 @@ describe('buildTrayMenuTemplate', () => {expect(labels).not.toContain('tray.recent');});- it('limits dynamic sections and exposes More actions only on overflow', () => {+ it('limits dynamic sections and offers More only for agents', () => {const { app } = createApp();const template = buildTrayMenuTemplate(app, {agents: Array.from({ length: 4 }, (_, index) => ({@@ -65,7 +65,32 @@ describe('buildTrayMenuTemplate', () => {expect(labels.filter((label) => String(label).startsWith('Agent '))).toHaveLength(3);expect(labels.filter((label) => String(label).startsWith('Recent '))).toHaveLength(5);expect(labels).toContain('tray.moreAgents');- expect(labels).toContain('tray.more');+ expect(labels).not.toContain('tray.more');+ });++ it('lists topics awaiting input before running ones, each capped', () => {+ const { app } = createApp();+ const template = buildTrayMenuTemplate(app, {+ activeTopics: [+ ...Array.from({ length: 6 }, (_, index) => ({+ status: 'running' as const,+ title: `Running ${index}`,+ url: `/agent/a/running-${index}`,+ })),+ { status: 'waitingForHuman', subtitle: 'Researcher', title: 'Deploy', url: '/agent/a/t' },+ ],+ agents: [],+ pinned: [],+ recent: [],+ });+ const labels = template.map((item) => item.label);++ expect(labels.slice(0, 3)).toEqual(['tray.waitingForHuman', 'Deploy', undefined]);+ expect(labels[3]).toBe('tray.running');+ expect(labels.filter((label) => String(label).startsWith('Running '))).toHaveLength(5);+ expect(template.find(({ label }) => label === 'Deploy')).toMatchObject({+ sublabel: 'Researcher',+ });});it('opens dynamic routes in the main window', () => {diff --git a/apps/desktop/src/main/menus/trayMenu.ts b/apps/desktop/src/main/menus/trayMenu.tsindex 6605b956d32..f217b5109cc 100644--- a/apps/desktop/src/main/menus/trayMenu.ts+++ b/apps/desktop/src/main/menus/trayMenu.ts@@ -1,9 +1,10 @@-import type { TrayNavigationSnapshot } from '@lobechat/electron-client-ipc';+import type { TrayActiveTopicItem, TrayNavigationSnapshot } from '@lobechat/electron-client-ipc';import type { MenuItemConstructorOptions } from 'electron';import { app as electronApp } from 'electron';import type { App } from '@/core/App';+const ACTIVE_LIMIT = 5;const PINNED_LIMIT = 3;const RECENT_AGENT_LIMIT = 3;const RECENT_LIMIT = 5;@@ -20,12 +21,21 @@ const createSection = (): MenuItemConstructorOptions[] =>items.length > 0 ? [{ enabled: false, label }, ...items, { type: 'separator' }] : [];-export const buildTrayMenuTemplate = (+export const buildDockMenuTemplate = (app: App,snapshot: TrayNavigationSnapshot,+ { includeAgents = false }: { includeAgents?: boolean } = {},): MenuItemConstructorOptions[] => {const t = app.i18n.ns('menu');- const appName = electronApp.getName();+ const activeItems = (status: TrayActiveTopicItem['status']) =>+ (snapshot.activeTopics ?? [])+ .filter((topic) => topic.status === status)+ .slice(0, ACTIVE_LIMIT)+ .map(({ subtitle, title, url }) => ({+ click: () => openRoute(app, url),+ label: title,+ sublabel: subtitle,+ }));const pinnedItems = snapshot.pinned.slice(0, PINNED_LIMIT).map(({ title, url }) => ({click: () => openRoute(app, url),label: title,@@ -51,19 +61,11 @@ export const buildTrayMenuTemplate = (});}- if (snapshot.recent.length > RECENT_LIMIT) {- recentItems.push({- click: () => {- app.browserManager.showMainWindow();- app.browserManager.getMainWindow().broadcast('openRecentlyViewed');- },- label: t('tray.more'),- });- }-return [+ ...createSection(t('tray.waitingForHuman'), activeItems('waitingForHuman')),+ ...createSection(t('tray.running'), activeItems('running')),...createSection(t('tray.pinned'), pinnedItems),- ...createSection(t('tray.recentAgents'), agentItems),+ ...(includeAgents ? createSection(t('tray.recentAgents'), agentItems) : []),...createSection(t('tray.recent'), recentItems),{accelerator: 'Alt+Shift+Space',@@ -82,6 +84,18 @@ export const buildTrayMenuTemplate = (},label: t('tray.newChat'),},+ ];+};++export const buildTrayMenuTemplate = (+ app: App,+ snapshot: TrayNavigationSnapshot,+): MenuItemConstructorOptions[] => {+ const t = app.i18n.ns('menu');+ const appName = electronApp.getName();++ return [+ ...buildDockMenuTemplate(app, snapshot, { includeAgents: true }),{ type: 'separator' },{click: () => app.browserManager.showMainWindow(),diff --git a/apps/desktop/src/main/menus/types.ts b/apps/desktop/src/main/menus/types.tsindex 9a44c504df3..6e0c34c243b 100644--- a/apps/desktop/src/main/menus/types.ts+++ b/apps/desktop/src/main/menus/types.ts@@ -47,4 +47,6 @@ export interface IMenuPlatform {* Refresh menu*/refresh: (options?: MenuOptions) => void;++ updateDockMenu?: (snapshot: TrayNavigationSnapshot) => void;}diff --git a/packages/electron-client-ipc/src/types/tray.ts b/packages/electron-client-ipc/src/types/tray.tsindex 7eac44e54a2..4eaef90e047 100644--- a/packages/electron-client-ipc/src/types/tray.ts+++ b/packages/electron-client-ipc/src/types/tray.ts@@ -10,7 +10,13 @@ export interface TrayNavigationItem {url: string;}+export interface TrayActiveTopicItem extends TrayNavigationItem {+ status: 'running' | 'waitingForHuman';+}+export interface TrayNavigationSnapshot {+ // Optional: an OTA-updated renderer and the main process can ship different versions.+ activeTopics?: TrayActiveTopicItem[];agents: TrayAgentItem[];pinned: TrayNavigationItem[];recent: TrayNavigationItem[];diff --git a/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.test.ts b/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.test.tsindex d77db245ea9..186209795ab 100644--- a/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.test.ts+++ b/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.test.ts@@ -1,3 +1,4 @@+import type { RecentItem } from '@lobechat/types';import { describe, expect, it } from 'vitest';import type { SidebarAgentItem } from '@/database/repositories/home';@@ -8,7 +9,18 @@ import { resolveTrayNavigationSnapshot } from './resolveSnapshot';const page = (title: string, url: string, lastVisited: number): ResolvedTab => ({isActive: false,meta: { title },- tab: { id: url, lastVisited, url },+ tab: { cached: { title }, id: url, lastVisited, url },+});++const recent = (item: Partial<RecentItem>): RecentItem => ({+ icon: item.type ?? 'document',+ id: 'id',+ routePath: '/',+ status: null,+ title: '',+ type: 'document',+ updatedAt: new Date(0),+ ...item,});const agent = (id: string, title: string, updatedAt: string): SidebarAgentItem =>@@ -40,24 +52,40 @@ describe('resolveTrayNavigationSnapshot', () => {expect(snapshot.agents).toHaveLength(4);});- it('keeps only concrete topics and pages with a descriptive second line', () => {+ it('builds recent entries from the sidebar recents with workspace-aware links', () => {const snapshot = resolveTrayNavigationSnapshot({agents: [agent('agent-1', 'Researcher', '2026-07-11T00:00:00.000Z')],pinnedPages: [],- recentPages: [- page('Topic title · Researcher', '/agent/agent-1/topic-1', 5),- page('Page title', '/page/page-1', 4),- page('Agent root', '/agent/agent-1', 3),- page('Agent task', '/agent/agent-1/task/task-1', 3),- page('Page list', '/page', 2),- page('Settings', '/settings', 1),+ recentPages: [],+ recents: [+ recent({+ agentId: 'agent-1',+ id: 'topic-1',+ routePath: '/agent/agent-1/topic-1',+ title: 'Topic title',+ type: 'topic',+ }),+ recent({ id: 'doc-1', routePath: '/page/doc-1', title: '', type: 'document' }),+ recent({+ agentId: 'agent-1',+ id: 'task-1',+ routePath: '/agent/agent-1/task/task-1',+ slugTitle: 'Ship it',+ title: 'Ship it',+ type: 'task',+ }),],- scope: { type: 'personal' },+ scope: { slug: 'acme', type: 'workspace' },});expect(snapshot.recent).toEqual([- { subtitle: 'Researcher', title: 'Topic title', url: '/agent/agent-1/topic-1' },- { subtitle: 'Page', title: 'Page title', url: '/page/page-1' },+ { subtitle: 'Researcher', title: 'Topic title', url: '/acme/agent/agent-1/topic-1' },+ { subtitle: undefined, title: 'Untitled', url: '/acme/page/doc-1' },+ {+ subtitle: 'Researcher',+ title: 'Ship it',+ url: '/acme/agent/agent-1/task/task-1/ship-it',+ },]);});@@ -67,8 +95,9 @@ describe('resolveTrayNavigationSnapshot', () => {pinnedPages: Array.from({ length: 4 }, (_, index) =>page(`Pinned ${index}`, `/page/pinned-${index}`, index),),- recentPages: Array.from({ length: 6 }, (_, index) =>- page(`Recent ${index}`, `/page/recent-${index}`, index),+ recentPages: [],+ recents: Array.from({ length: 6 }, (_, index) =>+ recent({ id: `doc-${index}`, routePath: `/page/doc-${index}`, title: `Recent ${index}` }),),scope: { type: 'personal' },});@@ -81,4 +110,47 @@ describe('resolveTrayNavigationSnapshot', () => {expect(snapshot.pinned).toHaveLength(4);expect(snapshot.recent).toHaveLength(6);});++ it('routes active topics by owner, lists awaiting input first, and drops them from recent', () => {+ const snapshot = resolveTrayNavigationSnapshot({+ activeTopics: [+ { agentId: 'agent-1', status: 'running', title: 'Refactor', topicId: 'topic-1' },+ { groupId: 'group-1', status: 'waitingForHuman', title: '', topicId: 'topic-2' },+ ],+ agents: [agent('agent-1', 'Researcher', '2026-07-11T00:00:00.000Z')],+ pinnedPages: [],+ recentPages: [],+ recents: [+ recent({+ id: 'topic-1',+ routePath: '/agent/agent-1/topic-1',+ title: 'Refactor',+ type: 'topic',+ }),+ recent({+ id: 'topic-3',+ routePath: '/agent/agent-1/topic-3',+ title: 'Other',+ type: 'topic',+ }),+ ],+ scope: { slug: 'acme', type: 'workspace' },+ });++ expect(snapshot.activeTopics).toEqual([+ {+ status: 'waitingForHuman',+ subtitle: undefined,+ title: 'Untitled',+ url: '/acme/group/group-1/topic-2',+ },+ {+ status: 'running',+ subtitle: 'Researcher',+ title: 'Refactor',+ url: '/acme/agent/agent-1/topic-1',+ },+ ]);+ expect(snapshot.recent.map(({ url }) => url)).toEqual(['/acme/agent/agent-1/topic-3']);+ });});diff --git a/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.ts b/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.tsindex 43646f483fd..ee041d67451 100644--- a/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.ts+++ b/src/features/Electron/titlebar/TrayMenu/resolveSnapshot.ts@@ -1,15 +1,21 @@+import { AGENT_CHAT_TOPIC_URL, GROUP_CHAT_TOPIC_URL } from '@lobechat/const';import type { TrayNavigationSnapshot } from '@lobechat/electron-client-ipc';-import { agentDisplayName } from '@lobechat/types';+import { agentDisplayName, type RecentItem } from '@lobechat/types';import type { SidebarAgentItem } from '@/database/repositories/home';+import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';+import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';import type { ResolvedTab } from '../TabBar/hooks/useResolvedTabs';import type { TabScope } from '../TabBar/scope';+import type { ActiveTopic } from './selectActiveTopics';interface ResolveTrayNavigationSnapshotParams {+ activeTopics?: ActiveTopic[];agents: SidebarAgentItem[];pinnedPages: ResolvedTab[];recentPages: ResolvedTab[];+ recents?: RecentItem[];scope: TabScope;}@@ -25,44 +31,31 @@ const getAgentIdFromUrl = (url: string): string | undefined => {return encodedId ? decodeURIComponent(encodedId) : undefined;};-const fallbackAgentUrl = (scope: TabScope, agentId: string) => {- const prefix = scope.type === 'workspace' ? `/${encodeURIComponent(scope.slug)}` : '';- return `${prefix}/agent/${encodeURIComponent(agentId)}`;-};+const scopedPath = (scope: TabScope, path: string) =>+ scope.type === 'workspace' ? `/${encodeURIComponent(scope.slug)}${path}` : path;-const resolveRecentItem = (page: ResolvedTab, agentNames: ReadonlyMap<string, string>) => {- const pathname = new URL(page.tab.url, 'https://lobehub.local').pathname;- const segments = pathname.split('/').filter(Boolean);- const agentIndex = segments.indexOf('agent');- if (- agentIndex >= 0 &&- segments.length === agentIndex + 3 &&- segments[agentIndex + 1] &&- segments[agentIndex + 2]- ) {- const agentId = decodeURIComponent(segments[agentIndex + 1]);- const agentName = agentNames.get(agentId) || 'Untitled';- const agentSuffix = ` · ${agentName}`;- const title = page.meta.title.endsWith(agentSuffix)- ? page.meta.title.slice(0, -agentSuffix.length)- : page.meta.title;- return {- subtitle: agentName,- title,- url: page.tab.url,- };- }+const fallbackAgentUrl = (scope: TabScope, agentId: string) =>+ scopedPath(scope, `/agent/${encodeURIComponent(agentId)}`);- const pageIndex = segments.indexOf('page');- if (pageIndex >= 0 && segments.length === pageIndex + 2 && segments[pageIndex + 1]) {- return { subtitle: 'Page', title: page.meta.title, url: page.tab.url };- }-};+const activeTopicUrl = (scope: TabScope, { agentId, groupId, topicId }: ActiveTopic) =>+ scopedPath(+ scope,+ groupId+ ? GROUP_CHAT_TOPIC_URL(encodeURIComponent(groupId), encodeURIComponent(topicId))+ : AGENT_CHAT_TOPIC_URL(encodeURIComponent(agentId ?? ''), encodeURIComponent(topicId)),+ );++const recentRoute = (item: RecentItem) =>+ item.type === 'task'+ ? taskDetailPath(item.id, item.agentId ?? undefined, item.slugTitle)+ : item.routePath;export const resolveTrayNavigationSnapshot = ({+ activeTopics = [],agents,pinnedPages,recentPages,+ recents = [],scope,}: ResolveTrayNavigationSnapshotParams): TrayNavigationSnapshot => {const uniqueAgents = new Map<string, SidebarAgentItem>();@@ -78,7 +71,21 @@ export const resolveTrayNavigationSnapshot = ({(a, b) => b.tab.lastVisited - a.tab.lastVisited,);+ const active = activeTopics+ .toSorted(+ (a, b) => Number(b.status === 'waitingForHuman') - Number(a.status === 'waitingForHuman'),+ )+ .map((topic) => ({+ status: topic.status,+ subtitle: agentNames.get(topic.groupId ?? topic.agentId ?? ''),+ title: topic.title || 'Untitled',+ url: activeTopicUrl(scope, topic),+ }));+ const activeTopicIds = new Set(activeTopics.map(({ topicId }) => topicId));+ const workspaceSlug = scope.type === 'workspace' ? scope.slug : undefined;+return {+ activeTopics: active,agents: [...uniqueAgents.values()].map((agent) => ({id: agent.id,title: agentDisplayName(agent, 'Untitled'),@@ -87,8 +94,12 @@ export const resolveTrayNavigationSnapshot = ({fallbackAgentUrl(scope, agent.id),})),pinned: pinnedPages.map(({ meta, tab }) => ({ title: meta.title, url: tab.url })),- recent: recentPages- .map((page) => resolveRecentItem(page, agentNames))- .filter((item) => item !== undefined),+ recent: recents+ .filter((item) => !(item.type === 'topic' && activeTopicIds.has(item.id)))+ .map((item) => ({+ subtitle: item.agentId ? agentNames.get(item.agentId) : undefined,+ title: item.title || 'Untitled',+ url: buildWorkspaceAwarePath(recentRoute(item), workspaceSlug),+ })),};};diff --git a/src/features/Electron/titlebar/TrayMenu/selectActiveTopics.test.ts b/src/features/Electron/titlebar/TrayMenu/selectActiveTopics.test.tsnew file mode 100644index 00000000000..6efa3502b78--- /dev/null+++ b/src/features/Electron/titlebar/TrayMenu/selectActiveTopics.test.ts@@ -0,0 +1,57 @@+import { describe, expect, it } from 'vitest';++import type { ChatStoreState } from '@/store/chat/initialState';++import { selectActiveTopics } from './selectActiveTopics';++const topic = (id: string, status?: string) => ({ id, status, title: `Title ${id}` });++const state = (overrides: Partial<Record<string, unknown>>) =>+ ({+ operations: {},+ operationsByType: {},+ topicDataMap: {},+ topicDetailMap: {},+ ...overrides,+ }) as unknown as ChatStoreState;++describe('selectActiveTopics', () => {+ it('collects running and awaiting-input topics with owners parsed from bucket keys', () => {+ const result = selectActiveTopics(+ state({+ topicDataMap: {+ agent_agt_1: { items: [topic('t1', 'running'), topic('t2', 'active')] },+ group_grp_1: { items: [topic('t3', 'waitingForHuman')] },+ },+ }),+ );++ expect(result).toEqual([+ { agentId: 'agt_1', status: 'running', title: 'Title t1', topicId: 't1' },+ { groupId: 'grp_1', status: 'waitingForHuman', title: 'Title t3', topicId: 't3' },+ ]);+ });++ it('marks topics with a local running operation and resolves ambiguous buckets from it', () => {+ const result = selectActiveTopics(+ state({+ operations: {+ op1: {+ context: { agentId: 'agt_1', groupId: 'grp_1', topicId: 't1' },+ metadata: {},+ status: 'running',+ },+ },+ operationsByType: { execAgentRuntime: ['op1'] },+ topicDataMap: {+ group_agent_grp_1_agt_1: { items: [topic('t1', 'active')] },+ group_agent_grp_2_agt_2: { items: [topic('t2', 'running')] },+ },+ }),+ );++ expect(result).toEqual([+ { agentId: 'agt_1', groupId: 'grp_1', status: 'running', title: 'Title t1', topicId: 't1' },+ ]);+ });+});diff --git a/src/features/Electron/titlebar/TrayMenu/selectActiveTopics.ts b/src/features/Electron/titlebar/TrayMenu/selectActiveTopics.tsnew file mode 100644index 00000000000..250ce90fa79--- /dev/null+++ b/src/features/Electron/titlebar/TrayMenu/selectActiveTopics.ts@@ -0,0 +1,71 @@+import type { TrayActiveTopicItem } from '@lobechat/electron-client-ipc';++import type { ChatStoreState } from '@/store/chat/initialState';+import { operationSelectors } from '@/store/chat/slices/operation/selectors';+import type { ChatTopic } from '@/types/topic';++interface TopicOwner {+ agentId?: string;+ groupId?: string;+}++export interface ActiveTopic extends TopicOwner {+ status: TrayActiveTopicItem['status'];+ title: string;+ topicId: string;+}++// `group_agent_{groupId}_{agentId}` cannot be split because ids contain underscores.+const ownerFromBucketKey = (key: string): TopicOwner | undefined => {+ if (key.startsWith('group_agent_')) return;+ if (key.startsWith('group_')) return { groupId: key.slice('group_'.length) };+ if (key.startsWith('agent_')) {+ const agentId = key.slice('agent_'.length);+ if (agentId && agentId !== 'undefined') return { agentId };+ }+};++export const selectActiveTopics = (s: ChatStoreState): ActiveTopic[] => {+ const runningIds = operationSelectors.visiblyRunningTopicIds(s);+ const candidates = new Map<string, { owner?: TopicOwner; topic: ChatTopic }>();++ for (const [key, data] of Object.entries(s.topicDataMap)) {+ for (const topic of data.items ?? []) {+ if (candidates.has(topic.id)) continue;+ if (+ topic.status === 'running' ||+ topic.status === 'waitingForHuman' ||+ runningIds.has(topic.id)+ ) {+ candidates.set(topic.id, { owner: ownerFromBucketKey(key), topic });+ }+ }+ }+ for (const topicId of runningIds) {+ const topic = s.topicDetailMap[topicId];+ if (topic && !candidates.has(topicId)) candidates.set(topicId, { topic });+ }+ if (candidates.size === 0) return [];++ const opOwners = new Map<string, TopicOwner>();+ for (const op of Object.values(s.operations)) {+ const { agentId, groupId, topicId } = op.context;+ if (topicId && candidates.has(topicId) && (agentId || groupId)) {+ opOwners.set(topicId, { agentId, groupId });+ }+ }++ const result: ActiveTopic[] = [];+ for (const [topicId, { owner, topic }] of candidates) {+ const resolvedOwner = opOwners.get(topicId) ?? owner;+ if (!resolvedOwner) continue;+ result.push({+ ...resolvedOwner,+ status: topic.status === 'waitingForHuman' ? 'waitingForHuman' : 'running',+ title: topic.title,+ topicId,+ });+ }++ return result;+};diff --git a/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.test.tsx b/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.test.tsxindex e140b1be49c..d09fd675a6f 100644--- a/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.test.tsx+++ b/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.test.tsx@@ -6,6 +6,8 @@ import { useTrayMenuSync } from './useTrayMenuSync';const mocks = vi.hoisted(() => ({agents: [{ id: 'agent-1', title: 'Researcher', updatedAt: '2026-07-11T00:00:00.000Z' }],useFetchAgentList: vi.fn(),+ refreshRecents: vi.fn(),+ swrKey: vi.fn(),updateNavigationSnapshot: vi.fn(),}));@@ -15,10 +17,41 @@ vi.mock('@/services/electron/tray', () => ({desktopTrayService: { updateNavigationSnapshot: mocks.updateNavigationSnapshot },}));+vi.mock('@/store/chat', () => ({+ useChatStore: vi.fn(() => []),+}));+vi.mock('@/store/home', () => ({useHomeStore: vi.fn(() => mocks.agents),}));+vi.mock('@/store/user', () => ({+ useUserStore: vi.fn(() => true),+}));++vi.mock('@/libs/swr/useCacheScope', () => ({ useCacheScope: () => 'personal' }));++vi.mock('@/libs/swr', () => ({+ useClientDataSWR: vi.fn((key) => {+ mocks.swrKey(key);+ return {+ data: [+ {+ agentId: 'agent-1',+ icon: 'topic',+ id: 'topic-1',+ routePath: '/agent/agent-1/topic-1',+ status: null,+ title: 'Research',+ type: 'topic',+ updatedAt: new Date(0),+ },+ ],+ mutate: mocks.refreshRecents,+ };+ }),+}));+vi.mock('@/store/home/slices/agentList/selectors', () => ({homeAgentListSelectors: { allAgents: vi.fn() },}));@@ -55,7 +88,10 @@ describe('useTrayMenuSync', () => {await waitFor(() => expect(mocks.updateNavigationSnapshot).toHaveBeenCalledTimes(1));expect(mocks.useFetchAgentList).toHaveBeenCalled();+ expect(mocks.swrKey).toHaveBeenCalledWith(['recent:trayList', 10, 'personal']);+ expect(mocks.refreshRecents).not.toHaveBeenCalled();expect(mocks.updateNavigationSnapshot).toHaveBeenCalledWith({+ activeTopics: [],agents: [{ id: 'agent-1', title: 'Researcher', url: '/agent/agent-1/topic-1' }],pinned: [],recent: [{ subtitle: 'Researcher', title: 'Research', url: '/agent/agent-1/topic-1' }],diff --git a/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.ts b/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.tsindex 19d4f7428b7..b382a6a1757 100644--- a/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.ts+++ b/src/features/Electron/titlebar/TrayMenu/useTrayMenuSync.ts@@ -1,28 +1,62 @@'use client';+import isEqual from 'fast-deep-equal';import { useEffect, useMemo, useRef } from 'react';import { useFetchAgentList } from '@/hooks/useFetchAgentList';+import { useClientDataSWR } from '@/libs/swr';+import { recentKeys } from '@/libs/swr/keys';+import { useCacheScope } from '@/libs/swr/useCacheScope';import { desktopTrayService } from '@/services/electron/tray';+import { recentService } from '@/services/recent';+import { useChatStore } from '@/store/chat';import { useElectronStore } from '@/store/electron';import { useHomeStore } from '@/store/home';import { homeAgentListSelectors } from '@/store/home/slices/agentList/selectors';+import { useUserStore } from '@/store/user';+import { authSelectors } from '@/store/user/slices/auth/selectors';import { useResolvedPages } from '../RecentlyViewed/hooks/useResolvedPages';import { resolveTrayNavigationSnapshot } from './resolveSnapshot';+import { selectActiveTopics } from './selectActiveTopics';++const TRAY_RECENT_FETCH_LIMIT = 10;export const useTrayMenuSync = () => {useFetchAgentList();const agents = useHomeStore(homeAgentListSelectors.allAgents);const scope = useElectronStore((state) => state.activeRecentScope);const { pinnedPages, recentPages } = useResolvedPages();+ const activeTopics = useChatStore(selectActiveTopics, isEqual);+ const isLogin = useUserStore(authSelectors.isLogin);+ const cacheScope = useCacheScope();+ const { data: recents, mutate: refreshRecents } = useClientDataSWR(+ isLogin ? recentKeys.trayList(TRAY_RECENT_FETCH_LIMIT, cacheScope) : null,+ () => recentService.getAll(TRAY_RECENT_FETCH_LIMIT, undefined, false, true),+ );+ const activeSignature = activeTopics.map(({ status, topicId }) => topicId + status).join();const lastSnapshotRef = useRef<string | undefined>(undefined);const snapshot = useMemo(- () => resolveTrayNavigationSnapshot({ agents, pinnedPages, recentPages, scope }),- [agents, pinnedPages, recentPages, scope],+ () =>+ resolveTrayNavigationSnapshot({+ activeTopics,+ agents,+ pinnedPages,+ recentPages,+ recents,+ scope,+ }),+ [activeTopics, agents, pinnedPages, recentPages, recents, scope],);+ const lastActiveSignatureRef = useRef(activeSignature);+ useEffect(() => {+ if (lastActiveSignatureRef.current === activeSignature) return;+ lastActiveSignatureRef.current = activeSignature;+ void refreshRecents();+ }, [activeSignature, refreshRecents]);+useEffect(() => {const signature = JSON.stringify(snapshot);if (signature === lastSnapshotRef.current) return;diff --git a/src/libs/swr/keys.ts b/src/libs/swr/keys.tsindex 59442efb324..239583360d7 100644--- a/src/libs/swr/keys.ts+++ b/src/libs/swr/keys.ts@@ -294,6 +294,11 @@ export const recentKeys = {scope,view,]),+ trayList: def('recent:trayList', (limit: number, scope: string) => [+ 'recent:trayList',+ limit,+ scope,+ ]),};// ---- task ---------------------------------------------------------------