Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): keep message bubbles off the chat store for topic actions
zqchrisea17f445d39a
diff --git a/apps/desktop/src/renderer/components/chat/AssistantMessage.tsx b/apps/desktop/src/renderer/components/chat/AssistantMessage.tsxindex 971d06821f..e422fc5fff 100644--- a/apps/desktop/src/renderer/components/chat/AssistantMessage.tsx+++ b/apps/desktop/src/renderer/components/chat/AssistantMessage.tsx@@ -4,7 +4,7 @@ import { BotStarterOptions } from '@/features/bots/BotStarterOptions';import { stripStarterOptionList } from '../../../shared/botStarterOptions';import { BotSessionTaskResultCard } from '@/features/bots/BotSessionTaskResultCard';import { BotDmThreadPreview } from '@/features/bots/BotDmThreadPreview';-import { useBotDmThreadForMessage } from '@/features/bots/botDmThreads';+import { useBotDmThreadForMessage } from '@/features/bots/botDmThreadsContext';import { botTaskResultKey, type BotCollaborationMeta } from '@cindy/maker-shared/botCollaboration';/*** AssistantMessagediff --git a/apps/desktop/src/renderer/components/chat/UserMessage.tsx b/apps/desktop/src/renderer/components/chat/UserMessage.tsxindex ced1d12619..e049efe705 100644--- a/apps/desktop/src/renderer/components/chat/UserMessage.tsx+++ b/apps/desktop/src/renderer/components/chat/UserMessage.tsx@@ -1,5 +1,5 @@import { BotDmThreadPreview } from '@/features/bots/BotDmThreadPreview';-import { useBotDmThreadForMessage } from '@/features/bots/botDmThreads';+import { useBotDmThreadForMessage } from '@/features/bots/botDmThreadsContext';import { FileTypeIcon } from '@/components/ui/file-type-icon';import type { ImMessageSource } from '../../../shared/imMessageSource';import { isSharedTaskPeer } from '@cindy/device-link';diff --git a/apps/desktop/src/renderer/features/bots/BotDmThreadHost.tsx b/apps/desktop/src/renderer/features/bots/BotDmThreadHost.tsxindex 029b136268..2e0e2c696e 100644--- a/apps/desktop/src/renderer/features/bots/BotDmThreadHost.tsx+++ b/apps/desktop/src/renderer/features/bots/BotDmThreadHost.tsx@@ -13,7 +13,8 @@ import { makerChatStore } from '@/lib/makerChatStore';import type { ComposerBotMention } from '@/lib/fileTypes';import type { BotChatIdentity } from './BotSessionContentHeader';import { BotDmThreadPanel, type BotDmThreadPanelState } from './BotDmThreadViews';-import { BotDmThreadsProvider, isBotDmThreadUnread, useBotDmThreadList, type BotDmThreadsValue } from './botDmThreads';+import { isBotDmThreadUnread, useBotDmThreadList } from './botDmThreads';+import { BotDmThreadsProvider, type BotDmThreadsValue } from './botDmThreadsContext';import { useBotProfiles } from './botStore';import { BOT_DM_THREAD_PARAM } from './botDmThreadRoute';diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsxindex 77d0500f3f..24c833547d 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsx@@ -17,6 +17,8 @@ vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (s: string) => s }vi.mock('@/hooks/useAgentIslandSettings', () => ({isAgentIslandSupported: () => mocks.supported,}));+// The private-chat topic host belongs to the chat surface these tests isolate.+vi.mock('../BotDmThreadHost', () => ({ BotDmThreadHost: ({ children }: { children: import('react').ReactNode }) => <>{children}</> }));vi.mock('@/features/cc-agent/CCAgentSessionView', () => ({CCAgentSessionView: () => <div data-testid="chat" />,}));diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsxindex 7df0542c77..ccc75c96af 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx@@ -29,6 +29,8 @@ vi.mock('react-router-dom', () => ({}));vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));vi.mock('../useBotIslandVisibleSession', () => ({ useBotIslandVisibleSession: () => {} }));+// The private-chat topic host belongs to the chat surface these tests isolate.+vi.mock('../BotDmThreadHost', () => ({ BotDmThreadHost: ({ children }: { children: import('react').ReactNode }) => <>{children}</> }));vi.mock('@/features/cc-agent/CCAgentSessionView', () => ({CCAgentSessionView: ({ botIdentity, botInvitationStage, readOnly }: { botIdentity?: BotChatBinding; botInvitationStage?: string; readOnly?: boolean }) => {const sessions = useRemoteProjectSessions();diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botSessionRead.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botSessionRead.test.tsxindex fec3f2de04..07e610ebb8 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botSessionRead.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botSessionRead.test.tsx@@ -22,6 +22,8 @@ vi.mock('react-router-dom', () => ({useNavigate: () => mocks.navigate,useParams: () => mocks.params,}));+// The private-chat topic host belongs to the chat surface these tests isolate.+vi.mock('../BotDmThreadHost', () => ({ BotDmThreadHost: ({ children }: { children: import('react').ReactNode }) => <>{children}</> }));vi.mock('@/features/cc-agent/CCAgentSessionView', () => ({CCAgentSessionView: ({ botUnreadBoundaryAt, onBotReadThrough, readOnly, botIdentity }: { botUnreadBoundaryAt?: number | null; onBotReadThrough?: (at: number) => void; readOnly?: boolean; botIdentity?: { canonicalChat?: boolean } }) => {mocks.read = onBotReadThrough;diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botWorkbenchLifecycle.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botWorkbenchLifecycle.test.tsxindex fcbade92f5..84e54df935 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botWorkbenchLifecycle.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botWorkbenchLifecycle.test.tsx@@ -20,6 +20,8 @@ vi.mock('react-router-dom', () => ({vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));vi.mock('../useBotIslandVisibleSession', () => ({ useBotIslandVisibleSession: () => {} }));vi.mock('../botStore', () => ({ useBotProfiles: () => [] }));+// The private-chat topic host belongs to the chat surface these tests isolate.+vi.mock('../BotDmThreadHost', () => ({ BotDmThreadHost: ({ children }: { children: import('react').ReactNode }) => <>{children}</> }));vi.mock('@/features/cc-agent/CCAgentSessionView', () => ({ CCAgentSessionView: () => <div>chat</div> }));vi.mock('@/features/right-sidebar/lib/detachedSidebarRouting', () => ({ routeSidebarCommand: async () => 'attached' }));diff --git a/apps/desktop/src/renderer/features/bots/botDmThreads.tsx b/apps/desktop/src/renderer/features/bots/botDmThreads.tsxindex 480ef48ea7..74352e9c21 100644--- a/apps/desktop/src/renderer/features/bots/botDmThreads.tsx+++ b/apps/desktop/src/renderer/features/bots/botDmThreads.tsx@@ -2,44 +2,16 @@* 私聊话题(docs/product-rules/cindy-bots-runtime.md「私聊话题」)。** 主人对私聊里的某条消息开话题:话题是这位伙伴的一条隐藏 Session,开在主对话的这条消息上。- * 这里负责私聊时间线这一侧:读出本私聊的话题入口,提供给消息气泡(悬停「话题」按钮、- * 根消息下的话题入口行),以及打开话题。话题面板本身见 BotDmThreadPanel。+ * 这里读出本私聊的话题入口并保持更新;气泡侧的上下文见 botDmThreadsContext.tsx,+ * 面板见 BotDmThreadViews。*/-import { createContext, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from 'react';-import type { ReactNode } from 'react';+import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';import { getDataOwnerGeneration, isDataOwnerGenerationCurrent, isDataOwnerPushCurrent } from '@/contexts/dataOwnerGeneration';import { makerChatStore } from '@/lib/makerChatStore';import type { BotDmThreadSummary } from '../../../shared/botDmThread';-import type { BotChatIdentity } from './BotSessionContentHeader';import { isBotDmThreadUnread, subscribeBotReadState } from './botReadState';-export interface BotDmThreadsValue {- /** The private chat's companion. */- botId: string;- botName: string;- bot: BotChatIdentity;- /** The main Chat whose messages carry topics; bubbles of any other Session show none. */- rootSessionId: string;- /** Topics by the clientId of the main-chat message they were opened on. */- threads: ReadonlyMap<string, BotDmThreadSummary>;- /** The root whose topic panel is open, if any. */- openRootClientId: string | null;- isUnread: (thread: BotDmThreadSummary) => boolean;- openThread: (rootClientId: string) => void;-}--const BotDmThreadsContext = createContext<BotDmThreadsValue | null>(null);--export function BotDmThreadsProvider({ value, children }: { value: BotDmThreadsValue | null; children: ReactNode }) {- return <BotDmThreadsContext.Provider value={value}>{children}</BotDmThreadsContext.Provider>;-}--/** The private-chat topics around one message bubble; null outside a local companion chat. */-export function useBotDmThreads(): BotDmThreadsValue | null {- return useContext(BotDmThreadsContext);-}-/*** Load the topics opened on messages of `rootSessionId` (the companion's main Chat) and keep* them current: a topic message, a companion reply finishing, window focus or a read change.@@ -89,17 +61,3 @@ export function useBotDmThreadList(botId: string | null, rootSessionId: string |}export { isBotDmThreadUnread };--/** Topic actions for one bubble: only messages of the main Chat itself, never inside a topic. */-export function useBotDmThreadForMessage(sessionId: string | undefined, clientId: string | undefined) {- const value = useBotDmThreads();- if (!value || !sessionId || !clientId || sessionId !== value.rootSessionId) return null;- const thread = value.threads.get(clientId) ?? null;- return {- bot: value.bot,- thread,- unread: thread ? value.isUnread(thread) : false,- isOpen: value.openRootClientId === clientId,- open: () => value.openThread(clientId),- };-}diff --git a/apps/desktop/src/renderer/features/bots/botDmThreadsContext.tsx b/apps/desktop/src/renderer/features/bots/botDmThreadsContext.tsxnew file mode 100644index 0000000000..786f5a8742--- /dev/null+++ b/apps/desktop/src/renderer/features/bots/botDmThreadsContext.tsx@@ -0,0 +1,50 @@+/**+ * 私聊话题在消息气泡这一侧的上下文(docs/product-rules/cindy-bots-runtime.md「私聊话题」):+ * 气泡据此显示「话题」按钮与根消息下的入口行。只依赖 React,气泡引用它不会顺带引入聊天 store;+ * 话题列表的读取见 botDmThreads.tsx,面板见 BotDmThreadViews。+ */+import { createContext, useContext } from 'react';+import type { ReactNode } from 'react';++import type { BotDmThreadSummary } from '../../../shared/botDmThread';+import type { BotChatIdentity } from './BotSessionContentHeader';++export interface BotDmThreadsValue {+ /** The private chat's companion. */+ botId: string;+ botName: string;+ bot: BotChatIdentity;+ /** The main Chat whose messages carry topics; bubbles of any other Session show none. */+ rootSessionId: string;+ /** Topics by the clientId of the main-chat message they were opened on. */+ threads: ReadonlyMap<string, BotDmThreadSummary>;+ /** The root whose topic panel is open, if any. */+ openRootClientId: string | null;+ isUnread: (thread: BotDmThreadSummary) => boolean;+ openThread: (rootClientId: string) => void;+}++const BotDmThreadsContext = createContext<BotDmThreadsValue | null>(null);++export function BotDmThreadsProvider({ value, children }: { value: BotDmThreadsValue | null; children: ReactNode }) {+ return <BotDmThreadsContext.Provider value={value}>{children}</BotDmThreadsContext.Provider>;+}++/** The private-chat topics around one message bubble; null outside a local companion chat. */+export function useBotDmThreads(): BotDmThreadsValue | null {+ return useContext(BotDmThreadsContext);+}++/** Topic actions for one bubble: only messages of the main Chat itself, never inside a topic. */+export function useBotDmThreadForMessage(sessionId: string | undefined, clientId: string | undefined) {+ const value = useBotDmThreads();+ if (!value || !sessionId || !clientId || sessionId !== value.rootSessionId) return null;+ const thread = value.threads.get(clientId) ?? null;+ return {+ bot: value.bot,+ thread,+ unread: thread ? value.isUnread(thread) : false,+ isOpen: value.openRootClientId === clientId,+ open: () => value.openThread(clientId),+ };+}