Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 群聊发件箱按 main 返回的群 ID 读写,旧本地路由打开已迁移群也能乐观显示
Dashd1f11f2b720f
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsxindex 18a85e6540..404fcbbf92 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx@@ -235,6 +235,12 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {useEffect(() => {let cancelled = false;let requestVersion = 0;+ // The composer queues under the group's own id, which an older local route may not match.+ const discardOutbox = () => {+ const shown = stateRef.current;+ discardBotGroupOutbox(groupId);+ if (shown.kind === 'ready' && shown.group.id !== groupId) discardBotGroupOutbox(shown.group.id);+ };const load = async (additionalSources: string[] = []) => {const version = ++requestVersion;const owner = getDataOwnerGeneration();@@ -273,7 +279,7 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {}} else if (result.errorCode === 'NOT_FOUND') {// Gone for this account (deleted, archived or left): nothing of it is left to send.- discardBotGroupOutbox(groupId);+ discardOutbox();setState({ kind: 'missing' });} else {// Keep a timeline that is already on screen; only a first read fails loudly.@@ -331,7 +337,7 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {requestVersion += 1;// Unsent attachments go with the group (staged copies included).discardDraft(botGroupAttachmentScope(groupId));- discardBotGroupOutbox(groupId);+ discardOutbox();setState({ kind: 'missing' });return;}@@ -353,17 +359,19 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {() => (state.kind === 'ready' ? projectBotGroupExecutionFailures(mergeBotGroupMessages(state.older, state.group.messages), state.group.executionFailures) : []),[state],);- const outbox = useBotGroupOutbox(groupId);+ // The composer sends under the group's own id; an older local route can still lead here.+ const outboxGroupId = group?.id ?? groupId;+ const outbox = useBotGroupOutbox(outboxGroupId);// Settle receipts only once the read that shows them is on screen, so a pending bubble// never disappears a frame before its real message appears. Older pages count too: a// message pushed off the latest page settles its previews once 查看更早的消息 shows it.// A receipt for a message the timeline already shows settles when it comes back.useLayoutEffect(() => {- if (state.kind === 'ready') noteBotGroupTimeline(groupId, mergeBotGroupMessages(state.older, state.group.messages), state.readToken);- }, [groupId, state, outbox]);+ if (state.kind === 'ready') noteBotGroupTimeline(outboxGroupId, mergeBotGroupMessages(state.older, state.group.messages), state.readToken);+ }, [outboxGroupId, state, outbox]);const { pending: pendingSends, localAttachments } = useMemo(- () => projectBotGroupOutbox(outbox, messages, getBotGroupOutboxClaims(groupId), getBotGroupOutboxPreviews(groupId)),- [groupId, messages, outbox],+ () => projectBotGroupOutbox(outbox, messages, getBotGroupOutboxClaims(outboxGroupId), getBotGroupOutboxPreviews(outboxGroupId)),+ [outboxGroupId, messages, outbox],);// A receipt the timeline does not show yet: read again so the real message takes its place.const unreadReceipts = pendingSends.flatMap((entry) => (entry.status === 'sent' && entry.messageId ? [entry.messageId] : [])).join(',');diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsxindex 43cd5e8a11..9ad6fc140d 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx@@ -1220,6 +1220,27 @@ describe('BotGroupChatView', () => {const pushMessages = (groupId = 'g1') =>act(() => mocks.pushes.forEach((push) => push({ groupId, change: 'messages' })));+ it('shows and settles the message when an older local route opens a migrated group', async () => {+ // The route still carries the local id; main answers with the group's server room id.+ const send = pendingSend();+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ id: 'room-1' }) });+ renderView();+ const input = (await screen.findByRole('textbox')) as HTMLTextAreaElement;+ fireEvent.change(input, { target: { value: '迁移后的群' } });+ fireEvent.keyDown(input, { key: 'Enter' });+ expect(outboxItems()).toHaveLength(1);+ await waitFor(() => expect(mocks.sendBotGroupMessage).toHaveBeenCalledTimes(1));+ expect((mocks.sendBotGroupMessage.mock.calls[0]![0] as { groupId: string }).groupId).toBe('room-1');++ mocks.getBotGroup.mockResolvedValue({+ ok: true,+ group: detail({ id: 'room-1', messages: [...detail().messages, msg({ id: 'u2', sequence: 5, content: '迁移后的群' })] }),+ });+ await send.resolve({ ok: true, messageId: 'u2' });+ await waitFor(() => expect(getBotGroupOutbox('room-1')).toHaveLength(0));+ expect(screen.getAllByText('迁移后的群')).toHaveLength(1);+ });+it('shows the message as soon as it is sent and swaps in the real one without a duplicate', async () => {const send = pendingSend();renderView();diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex a99d418ca6..aa71d7bfee 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -363,7 +363,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授同一草稿的点名目标 ID、顺序或所有人标记变化,即使显示名字与正文没变,也必须使用新的 `clientId`。只有正文、点名目标、分工标记和附件均不变时,失败重试才复用原发送尝试。-Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时间线末尾,输入框与托盘马上空出,可以接着发下一条;同一个群的提交按发出顺序逐条交给 main,慢于 0.6 秒才在气泡下显示「发送中…」。回执的 `messageId` 是替换依据:时间线读到该消息即换成真实消息,回执之后开始的重读没读到也视为已进历史;推送重读先于回执到达时,只对正在提交的那一条按「基线之后、未被回执认领、正文与附件数一致的自己的消息」做显示去重,最终仍以 `messageId` 为准。附件按输入生成临时列表;带手绘标注的图片入队即烧录,完成后气泡改用烧录后的本地预览,提交与重试复用同一份烧录结果,放回输入框的仍是带笔迹的原件;入队烧录失败即这条消息失败,轮到它时不自动再烧,用户「重试」或编辑后重新发送才重新烧录。真实消息到达而服务器副本尚未可用(无 url / path,或旧版尚未列出)时,在同一 `messageId` 内配对:数量一致按发送顺序;副本按下载完成先后逐个列出、数量不一致时,只有名字(烧录后的名字)在这条消息里唯一的附件按名字配对,重名的附件分不出谁是谁,继续显示各自的本地预览、对应副本暂不单独显示,直到数量一致再按顺序替换;不退成缺失、不重复、同名文件不互换。离开输入框、尚未确认的图片(含标注原图与烧录副本)登记进存储清理的保护清单直到条目释放,已确认消息的本地预览不登记(发送时 main 已在群的 `bot-group-attachment` 引用下固定);本地预览按已加载的全部时间线(含更早的页)结算,不设条数上限,消息被删除(含在其他设备上删除)即撤下其本地预览;尚未进入消息的暂存文件按归属回收:还没开始提交的条目(排队中、已失败)归发件箱,群被删除(包括不在当前页、从列表消失且读取确认 `NOT_FOUND` 的群;读取不确定时在 5 秒、30 秒、2 分钟后各重试一次,群回到列表或读到仍存在即停止)时立即回收;已开始提交的条目归它的那次请求——烧录期间被丢弃的不再发出并回收,已交给 main 的等 main 答复,成功(已进入消息)不回收,失败或调用异常才回收(main 在答复前读完本地文件,失败时不留引用暂存路径的本地记录)。切换账号时发件箱同样发出回收,但 main 只删当前账号暂存目录里的副本,renderer 看到切换时 main 已在新账号(或边界)下,所以前一账号的暂存副本留在它自己的目录里,不在发件箱范围内。发送失败绝不自动重发:输入框为空(无文字、附件、分工标签)时把正文、点名、标签与附件原样放回并提示原因,再发沿用原 `clientId`;输入框已有新内容时消息留在时间线上显示「没发出去」(待发与失败的消息都排在按下发送时时间线已有的消息之后,之后到达的消息排在它下面,不会被挤到末尾;比它先发出、已出现在时间线上的自己的消息始终排在它上面),可「重试」(同一 `clientId`)或在输入框清空后「编辑」放回;main 拒绝的是消息内容本身时(引用原消息或点名对象已不可用、字段或附件无效:`QUOTE_UNAVAILABLE` / `MENTION_UNAVAILABLE` / `INVALID_PARAMS` / `INVALID_ATTACHMENT` / `ATTACHMENT_TOO_LARGE`),原样重发只会再次失败,只提供「编辑」;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。「引用回复」随消息进入发件箱:待发气泡上方显示同一个引用块,引用是发送输入的一部分(换引用即换 `clientId`);失败放回时引用只随它自己的正文放回(期间已另选引用的以新选为准),原消息不可用(`QUOTE_UNAVAILABLE`)时只放回正文。发件箱原样保存并发出完整发送输入(附件入队即开始烧录标注,提交时序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离,切换到另一个账号时清空(同账号的 generation 修复、认证边界短暂的 null 不清空)、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。+Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时间线末尾,输入框与托盘马上空出,可以接着发下一条;同一个群的提交按发出顺序逐条交给 main,慢于 0.6 秒才在气泡下显示「发送中…」。回执的 `messageId` 是替换依据:时间线读到该消息即换成真实消息,回执之后开始的重读没读到也视为已进历史;推送重读先于回执到达时,只对正在提交的那一条按「基线之后、未被回执认领、正文与附件数一致的自己的消息」做显示去重,最终仍以 `messageId` 为准。附件按输入生成临时列表;带手绘标注的图片入队即烧录,完成后气泡改用烧录后的本地预览,提交与重试复用同一份烧录结果,放回输入框的仍是带笔迹的原件;入队烧录失败即这条消息失败,轮到它时不自动再烧,用户「重试」或编辑后重新发送才重新烧录。真实消息到达而服务器副本尚未可用(无 url / path,或旧版尚未列出)时,在同一 `messageId` 内配对:数量一致按发送顺序;副本按下载完成先后逐个列出、数量不一致时,只有名字(烧录后的名字)在这条消息里唯一的附件按名字配对,重名的附件分不出谁是谁,继续显示各自的本地预览、对应副本暂不单独显示,直到数量一致再按顺序替换;不退成缺失、不重复、同名文件不互换。离开输入框、尚未确认的图片(含标注原图与烧录副本)登记进存储清理的保护清单直到条目释放,已确认消息的本地预览不登记(发送时 main 已在群的 `bot-group-attachment` 引用下固定);本地预览按已加载的全部时间线(含更早的页)结算,不设条数上限,消息被删除(含在其他设备上删除)即撤下其本地预览;尚未进入消息的暂存文件按归属回收:还没开始提交的条目(排队中、已失败)归发件箱,群被删除(包括不在当前页、从列表消失且读取确认 `NOT_FOUND` 的群;读取不确定时在 5 秒、30 秒、2 分钟后各重试一次,群回到列表或读到仍存在即停止)时立即回收;已开始提交的条目归它的那次请求——烧录期间被丢弃的不再发出并回收,已交给 main 的等 main 答复,成功(已进入消息)不回收,失败或调用异常才回收(main 在答复前读完本地文件,失败时不留引用暂存路径的本地记录)。切换账号时发件箱同样发出回收,但 main 只删当前账号暂存目录里的副本,renderer 看到切换时 main 已在新账号(或边界)下,所以前一账号的暂存副本留在它自己的目录里,不在发件箱范围内。发送失败绝不自动重发:输入框为空(无文字、附件、分工标签)时把正文、点名、标签与附件原样放回并提示原因,再发沿用原 `clientId`;输入框已有新内容时消息留在时间线上显示「没发出去」(待发与失败的消息都排在按下发送时时间线已有的消息之后,之后到达的消息排在它下面,不会被挤到末尾;比它先发出、已出现在时间线上的自己的消息始终排在它上面),可「重试」(同一 `clientId`)或在输入框清空后「编辑」放回;main 拒绝的是消息内容本身时(引用原消息或点名对象已不可用、字段或附件无效:`QUOTE_UNAVAILABLE` / `MENTION_UNAVAILABLE` / `INVALID_PARAMS` / `INVALID_ATTACHMENT` / `ATTACHMENT_TOO_LARGE`),原样重发只会再次失败,只提供「编辑」;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。「引用回复」随消息进入发件箱:待发气泡上方显示同一个引用块,引用是发送输入的一部分(换引用即换 `clientId`);失败放回时引用只随它自己的正文放回(期间已另选引用的以新选为准),原消息不可用(`QUOTE_UNAVAILABLE`)时只放回正文。发件箱原样保存并发出完整发送输入(附件入队即开始烧录标注,提交时序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离(以 main 返回的群 ID 为准,从旧的本地路由打开已迁移到 Chat Server 的群时同样),切换到另一个账号时清空(同账号的 generation 修复、认证边界短暂的 null 不清空)、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。完成全部显式目标校验后,最终点名列表继续沿用排除当前用户自己的既有规则;主群、Thread 与手机直连均一致,不因显式列表或所有人标记改变。