Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 群聊发件箱的重名附件在副本列全前保留本地预览
Dash404f197fc621
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.tsindex 7dd399e031..1976ef58bb 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts@@ -409,7 +409,7 @@ describe('botGroupOutbox', () => {usable('s1', 'a.png'),{ ...mine[1], id: 's2' },]);- // Older servers leave a copy out until it downloads: never show it missing or twice.+ // Main leaves a copy out until it downloads: never show it missing or twice.expect(mergeBotGroupLocalAttachments([usable('s2', 'b.png')], mine)).toEqual([mine[0], usable('s2', 'b.png')]);// A burned-in image may come back renamed; equal counts pair the rest in order.expect(mergeBotGroupLocalAttachments([usable('s1', 'a-annotated.png'), usable('s2', 'b.png')], mine)).toEqual([@@ -457,12 +457,27 @@ describe('botGroupOutbox', () => {expect(mergeBotGroupLocalAttachments([placeholder('s1', 'photo-annotated.png'), usable('s2', 'photo.png')], mine,)).toEqual([{ ...mine[0], id: 's1' }, usable('s2', 'photo.png')]);- // Copies listed one by one as they download (older servers).+ // Copies listed one by one as they download.expect(mergeBotGroupLocalAttachments([usable('s2', 'photo.png')], mine)).toEqual([mine[0], usable('s2', 'photo.png')]);expect(mergeBotGroupLocalAttachments([usable('s1', 'photo-annotated.png')], mine)).toEqual([usable('s1', 'photo-annotated.png'), mine[1],]);});++ it('keeps the local previews of files that share a name until every copy is listed', () => {+ // Two different photo.png and a.png; downloads finish in any order.+ const mine = [local('l1', 'photo.png'), local('l2', 'photo.png'), local('l3', 'a.png')];+ // Only the second photo.png is in: which one it is cannot be told, so neither is replaced.+ expect(mergeBotGroupLocalAttachments([usable('s2', 'photo.png')], mine)).toEqual(mine);+ // A unique name still pairs on its own.+ expect(mergeBotGroupLocalAttachments([usable('s2', 'photo.png'), usable('s3', 'a.png')], mine)).toEqual([+ mine[0], mine[1], usable('s3', 'a.png'),+ ]);+ // Every copy listed: the send order decides.+ expect(mergeBotGroupLocalAttachments([usable('s1', 'photo.png'), usable('s2', 'photo.png'), usable('s3', 'a.png')], mine)).toEqual([+ usable('s1', 'photo.png'), usable('s2', 'photo.png'), usable('s3', 'a.png'),+ ]);+ });});describe('drawn annotations', () => {diff --git a/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts b/apps/desktop/src/renderer/features/bots/botGroupOutbox.tsindex 8b0ccd26bc..09608b42d2 100644--- a/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts+++ b/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts@@ -15,7 +15,7 @@* 仍以 messageId 为准。* - 附件:临时消息从输入的附件生成列表;带手绘标注的图片烧录完成后改用烧录后的本地预览* (同一份烧录结果也用于提交与重试,不重复烧录;放回输入框的仍是带笔迹的原件)。真实消息到了- * 而服务器副本还没下载好(没有 url / path,或旧版干脆还没出现在列表里)时,按同一 messageId+ * 而服务器副本还没下载好(没有 url / path,或还没出现在列表里——main 只列已下载的副本)时,按同一 messageId* 把本地预览接到真实消息上,直到副本可用(见 `mergeBotGroupLocalAttachments`)。* - 离开输入框的附件不再受草稿保护:发件箱条目持有的图片地址(含标注原图与烧录副本)登记进* 存储清理的保护清单,条目移除时同步撤下;已确认消息的本地预览不登记——发送时 main 已在群的@@ -430,26 +430,21 @@ function isUsable(attachment: BotGroupAttachment): boolean {/*** Pair the server's attachments of a message with the local ones it was sent with. The server- * keeps the order they were sent in, so equal counts pair by position. An older server lists a- * copy only once it is downloaded; then pair by name in that same order, so two files with the- * same name never swap. Local names are the burned-in ones (see `prepared`), as on the server.- * Returns, for each local attachment, the server copy it matches (or undefined), plus the- * server attachments nothing local matched.+ * keeps the order they were sent in, so equal counts pair by position. Main lists a copy only+ * once it is downloaded, and downloads finish in any order: then a name that is unique among+ * the local files pairs by name, while files sharing a name cannot be told apart and keep their+ * local previews (their server copies wait unshown) until the counts match. Local names are the+ * burned-in ones (see `prepared`), as on the server. Returns, for each local attachment, the+ * server copy it matches (or undefined), plus the server attachments no local name accounts for.*/function pairLocalAttachments(server: readonly BotGroupAttachment[], local: readonly BotGroupAttachment[]) {if (server.length === local.length) return { pairs: [...server], extra: [] as BotGroupAttachment[] };- const used = new Set<number>();- let next = 0;- const pairs: Array<BotGroupAttachment | undefined> = local.map((file) => {- for (let at = next; at < server.length; at += 1) {- if (server[at]!.name !== file.name) continue;- used.add(at);- next = at + 1;- return server[at];- }- return undefined;- });- return { pairs, extra: server.filter((_, at) => !used.has(at)) };+ const counts = new Map<string, number>();+ for (const file of local) counts.set(file.name, (counts.get(file.name) ?? 0) + 1);+ const pairs = local.map((file) =>+ counts.get(file.name) === 1 ? server.find((copy) => copy.name === file.name) : undefined,+ );+ return { pairs, extra: server.filter((copy) => !counts.has(copy.name)) };}/**diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex 69b41ed5d0..44b253ccda 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -352,7 +352,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`)或在输入框清空后「编辑」放回;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。「引用回复」随消息进入发件箱:待发气泡上方显示同一个引用块,引用是发送输入的一部分(换引用即换 `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`)或在输入框清空后「编辑」放回;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。「引用回复」随消息进入发件箱:待发气泡上方显示同一个引用块,引用是发送输入的一部分(换引用即换 `clientId`);失败放回时引用只随它自己的正文放回(期间已另选引用的以新选为准),原消息不可用(`QUOTE_UNAVAILABLE`)时只放回正文。发件箱原样保存并发出完整发送输入(附件入队即开始烧录标注,提交时序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离,切换到另一个账号时清空(同账号的 generation 修复、认证边界短暂的 null 不清空)、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。完成全部显式目标校验后,最终点名列表继续沿用排除当前用户自己的既有规则;主群、Thread 与手机直连均一致,不因显式列表或所有人标记改变。