Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 手机侧栏显示谁贴回了话题回复;待重试队列改为面板共同订阅
Dash1916d5111b44
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.tsindex 6190af1cd0..73b382c1ec 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts@@ -233,6 +233,14 @@ describe('bot group remote resources', () => {} });});+ it('names who shared a thread reply, never the card text, the way the desktop sidebar does', () => {+ const share = (extra: Record<string, unknown>) => botGroupRemotePreview(summary({ openPlan: null,+ lastMessage: { authorName: '小满', preview: '', createdAt: 50, threadShare: true, ...extra } as never }));+ expect(share({ authorKind: 'bot' })).toMatchObject({ fallback: '小满 shared a thread reply', translations: { 'zh-CN': '小满 贴回了一条话题回复' } });+ expect(share({ authorKind: 'user', isSelf: false })).toMatchObject({ translations: { 'zh-CN': '小满 贴回了一条话题回复' } });+ expect(share({ authorKind: 'user', isSelf: true })).toMatchObject({ fallback: 'You shared a thread reply', translations: { 'zh-CN': '你贴回了一条话题回复' } });+ });+it('sends the chat only to controllers that understand it, without host paths', async () => {const rich = await remoteResourceRegistry.get(context, { client: client([BOT_GROUP_CHAT_PRIMITIVE]), ref: ref('g1') });expect(rich.blocks?.[0]).toMatchObject({ primitive: BOT_GROUP_CHAT_PRIMITIVE });diff --git a/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts b/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.tsindex 3cb890dde1..0cbe92835c 100644--- a/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts+++ b/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts@@ -107,6 +107,20 @@ const COPY = {ja: '{name}さんがグループに参加しました',ko: '{name} 님이 그룹에 참여했습니다',},+ sharedReplyYou: {+ en: 'You shared a thread reply',+ 'zh-CN': '你贴回了一条话题回复',+ 'zh-TW': '你貼回了一則話題回覆',+ ja: 'スレッドの返信を共有しました',+ ko: '스레드 답글을 공유했습니다',+ },+ sharedReply: {+ en: '{name} shared a thread reply',+ 'zh-CN': '{name} 贴回了一条话题回复',+ 'zh-TW': '{name} 貼回了一則話題回覆',+ ja: '{name} がスレッドの返信を共有しました',+ ko: '{name} 님이 스레드 답글을 공유했습니다',+ },} satisfies Record<string, Copy>;function fill(template: string, vars: Record<string, string | number>): string {@@ -141,6 +155,11 @@ export function botGroupRemotePreview(group: BotGroupSummary): RemoteLocalizedTeif (!last) return undefined;if (last.authorKind === 'system' && last.noticeCode === 'member-joined')return localized(COPY.memberJoined, { name: last.authorName });+ // A share names who posted it; the card's own text is never quoted here.+ if (last.threadShare) {+ return last.authorKind === 'user' && last.isSelf !== false+ ? localized(COPY.sharedReplyYou) : localized(COPY.sharedReply, { name: last.authorName.trim() });+ }return last.authorKind === 'bot' && last.authorName? localized(COPY.lastMessage, { name: last.authorName, text: last.preview }): last.preview;diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsxindex 970039f032..b76d4418ca 100644--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx@@ -1,4 +1,4 @@-import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from 'react';+import { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore, type ReactNode } from 'react';import { Check, CornerDownRight, MessageSquareShare, X } from 'lucide-react';import { useTranslation } from 'react-i18next';import { Button } from '@/components/ui/button';@@ -32,15 +32,28 @@ export type BotGroupSharedReplies = ReadonlyMap<string, { messageId: string; byS/*** Replies that reached a thread while their main-chat copy did not, per group and thread.- * Kept outside the panel so switching threads and coming back still offers the retry.+ * Kept outside the panel, and the only copy: a copy may fail after its panel closed, or+ * while the same thread is open again, and either way that panel shows the retry.* Server groups keep their IDs across accounts, so the queue belongs to one data owner.*/-const unpostedStore = { owner: getDataOwnerGeneration(), replies: new Map<string, ReadonlySet<string>>() };+const unpostedStore = { owner: getDataOwnerGeneration(), replies: new Map<string, ReadonlySet<string>>(), listeners: new Set<() => void>() };+const NONE_UNPOSTED: ReadonlySet<string> = new Set();function unpostedReplies() {const owner = getDataOwnerGeneration();if (unpostedStore.owner !== owner) { unpostedStore.owner = owner; unpostedStore.replies.clear(); }return unpostedStore.replies;}+function updateUnposted(key: string, update: (previous: ReadonlySet<string>) => ReadonlySet<string>) {+ const queue = unpostedReplies();+ const next = update(queue.get(key) ?? NONE_UNPOSTED);+ if (next.size) queue.set(key, next); else queue.delete(key);+ for (const listener of unpostedStore.listeners) listener();+}+function useUnposted(key: string): ReadonlySet<string> {+ return useSyncExternalStore(+ useCallback(listener => { unpostedStore.listeners.add(listener); return () => { unpostedStore.listeners.delete(listener); }; }, []),+ () => unpostedReplies().get(key) ?? NONE_UNPOSTED);+}export function animateThreadPanelWidth(panel: HTMLElement, from: string, to: string): Animation | null {const style = getComputedStyle(panel);@@ -132,15 +145,8 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,// Off by default: a reply stays in the thread unless the user asks for both.const [alsoSend, setAlsoSend] = useState(false);const unpostedKey = `${group.id}:${rootId}`;- const [unposted, setUnpostedState] = useState<ReadonlySet<string>>(() => unpostedReplies().get(unpostedKey) ?? new Set());- // The queue is written first: a share may finish after this panel has closed, and the- // state below only mirrors it while the panel is open.- const setUnposted = (update: (previous: ReadonlySet<string>) => ReadonlySet<string>) => {- const queue = unpostedReplies();- const next = update(queue.get(unpostedKey) ?? new Set());- if (next.size) queue.set(unpostedKey, next); else queue.delete(unpostedKey);- setUnpostedState(next);- };+ const unposted = useUnposted(unpostedKey);+ const setUnposted = (update: (previous: ReadonlySet<string>) => ReadonlySet<string>) => updateUnposted(unpostedKey, update);const [posting, setPosting] = useState<ReadonlySet<string>>(new Set());const postingRef = useRef(new Set<string>());/** Shares confirmed in this panel (reply → main-chat message, null when unknown). */diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsxindex d28a52c31e..1586f021e0 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx@@ -2420,8 +2420,11 @@ describe('thread share follow-ups', () => {expect(mocks.reply).toHaveBeenCalledTimes(2);});- it('keeps a main-chat copy retryable when it fails after leaving the thread', async () => {- mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: 'u1', content: 'A' }), msg({ id: 'u2', sequence: 2, content: 'B' })] }) });+ // The copy fails while the reader is in another thread, or after they came back to this one.+ it.each(['away', 'back'] as const)('keeps a main-chat copy retryable when it fails after leaving the thread (reader %s)', async (where) => {+ // The queue outlives a panel by design, so each case uses threads of its own.+ const [rootA, rootB] = [`${where}-a`, `${where}-b`];+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: rootA, content: 'A' }), msg({ id: rootB, sequence: 2, content: 'B' })] }) });mocks.reply.mockResolvedValue({ ok: true, messageId: 'first' });let fail!: () => void;mocks.shareToMain.mockReturnValueOnce(new Promise(resolve => { fail = () => resolve({ ok: false, errorCode: 'SERVICE_ERROR' }); }));@@ -2435,10 +2438,16 @@ describe('thread share follow-ups', () => {await waitFor(() => expect(mocks.shareToMain).toHaveBeenCalledTimes(1));// The copy is still on its way when the reader moves to another thread.await user.click(second!);- await screen.findByText('Reply to u2');- await act(async () => fail());+ await screen.findByText(`Reply to ${rootB}`);+ if (where === 'away') await act(async () => fail());await user.click(first!);- expect(await within(await screen.findByRole('complementary')).findByRole('button', { name: t('retryPost') })).toBeTruthy();+ const reopened = await screen.findByRole('complementary');+ await within(reopened).findByText(`Reply to ${rootA}`);+ if (where === 'back') {+ expect(within(reopened).queryByRole('button', { name: t('retryPost') })).toBeNull();+ await act(async () => fail());+ }+ expect(await within(reopened).findByRole('button', { name: t('retryPost') })).toBeTruthy();});});