Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 待贴回队列按数据所有者隔离
Dash5ac8866d9497
diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsxindex 8f713f4611..2a0f8e0e7f 100644--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx@@ -32,8 +32,14 @@ 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.+ * Server groups keep their IDs across accounts, so the queue belongs to one data owner.*/-const unpostedReplies = new Map<string, ReadonlySet<string>>();+const unpostedStore = { owner: getDataOwnerGeneration(), replies: new Map<string, ReadonlySet<string>>() };+function unpostedReplies() {+ const owner = getDataOwnerGeneration();+ if (unpostedStore.owner !== owner) { unpostedStore.owner = owner; unpostedStore.replies.clear(); }+ return unpostedStore.replies;+}export function animateThreadPanelWidth(panel: HTMLElement, from: string, to: string): Animation | null {const style = getComputedStyle(panel);@@ -118,10 +124,10 @@ export function ChatThreadPanel({ group, rootId, focus, sharedReplies, onRevealS// 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());+ const [unposted, setUnpostedState] = useState<ReadonlySet<string>>(() => unpostedReplies().get(unpostedKey) ?? new Set());const setUnposted = (update: (previous: ReadonlySet<string>) => ReadonlySet<string>) => setUnpostedState(previous => {const next = update(previous);- if (next.size) unpostedReplies.set(unpostedKey, next); else unpostedReplies.delete(unpostedKey);+ if (next.size) unpostedReplies().set(unpostedKey, next); else unpostedReplies().delete(unpostedKey);return next;});const [posting, setPosting] = useState<ReadonlySet<string>>(new Set());diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsxindex 375867ed16..679c9ce252 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx@@ -45,6 +45,7 @@ const mocks = vi.hoisted(() => ({getControlledState: vi.fn(),revoke: vi.fn(),thread: vi.fn(),+ ownerGeneration: 1,reply: vi.fn(),shareToMain: vi.fn(),toastInfo: vi.fn(),@@ -65,7 +66,7 @@ vi.mock('react-router-dom', () => ({useParams: () => ({ groupId: mocks.groupId }),}));vi.mock('@/contexts/dataOwnerGeneration', () => ({- getDataOwnerGeneration: () => 1,+ getDataOwnerGeneration: () => mocks.ownerGeneration,isDataOwnerGenerationCurrent: () => true,isDataOwnerPushCurrent: () => true,}));@@ -1994,3 +1995,29 @@ describe('more older shares than one refresh re-reads', () => {expect(screen.queryByText('↪ 卡片 0')).toBeNull();});});++describe('pending main-chat copies across accounts', () => {+ const t = (name: string) => `bots.groupChat.server.thread.${name}`;+ beforeEach(() => { vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} }); });+ afterEach(() => { mocks.ownerGeneration = 1; });++ it('does not offer one account\'s failed copy to the next account in the same group', async () => {+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: 'u1', content: 'A' })] }) });+ mocks.shareToMain.mockResolvedValue({ ok: false, errorCode: 'SERVICE_ERROR' });+ const user = userEvent.setup();+ const view = renderView();+ await user.click(await screen.findByRole('button', { name: 'bots.groupChat.server.reply' }));+ let panel = await screen.findByRole('complementary');+ await user.click(within(panel).getByRole('checkbox', { name: t('alsoSend') }));+ await user.type(within(panel).getByRole('textbox'), 'from account A{Enter}');+ await within(panel).findByRole('button', { name: t('retryPost') });+ view.unmount();+ // Another account opens the same server group and thread.+ mocks.ownerGeneration = 2;+ renderView();+ await user.click(await screen.findByRole('button', { name: 'bots.groupChat.server.reply' }));+ panel = await screen.findByRole('complementary');+ await within(panel).findByText('Reply to u1');+ expect(within(panel).queryByRole('button', { name: t('retryPost') })).toBeNull();+ });+});diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex eb2de6e0ee..d9528a5c80 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -467,7 +467,7 @@ Desktop 主聊天直接展示话题里的最新回复,并能把话题回复贴切换账号或退出时取消。- **同时发到主聊天**:话题输入框有「同时发到群聊」,默认不选、每次发送后恢复默认、切换话题不继承。先发话题回复,成功后再贴回主聊天;贴回失败时回复保留在话题里,显示「重新发到群聊」,重试只重做贴回这一步,不重发回复。多条失败一起列出,- 按群和话题保存在本次运行中,切换话题再回来仍可重试。回复失败时重试沿用原 `clientId`,回复送达前不会贴回。+ 按群和话题保存在本次运行中,切换话题再回来仍可重试;切换账号时清空,不把一个账号的待重试项交给另一个账号。回复失败时重试沿用原 `clientId`,回复送达前不会贴回。- **贴回已有回复**:话题里每条回复(包括别人和伙伴的)在「更多」菜单里有「贴回群聊」。已贴过的回复显示「已贴到群聊」,点了回到主聊天里那条;自己贴过的,菜单变为「在群聊中查看」。贴回接口返回的消息 ID 会保留下来;那条贴回在主群更早的记录里、还没加载时,会提示往上加载。主群未加载到的历史贴回,需要服务端提供按回复查询的索引才能显示状态;在此之前,重复贴回仍由服务端幂等去重。