Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
chore(desktop): 删除无生产调用的 materializeQueuedOssAttachments 同步包装 (#5473)
lengjingxu8eb5952becd5
diff --git a/apps/desktop/src/main/__tests__/deviceLinkAutoTitleWiring.test.ts b/apps/desktop/src/main/__tests__/deviceLinkAutoTitleWiring.test.tsindex e8dd80e076..3ca270774d 100644--- a/apps/desktop/src/main/__tests__/deviceLinkAutoTitleWiring.test.ts+++ b/apps/desktop/src/main/__tests__/deviceLinkAutoTitleWiring.test.ts@@ -90,7 +90,7 @@ describe('device-link auto-title wiring', () => {);const stages = [/(?:await\s+)?inputCoordinator\.ensureQueueRestored\(sid\)/,- /await materializeQueuedOssAttachments/,+ /await materializeQueuedOssAttachmentsDeferred/,/await hydrateQueuedAgentReferences/,/await prepareDeviceLinkAutoTitle\(sid, queued\)/,];@@ -160,7 +160,7 @@ describe('device-link auto-title wiring', () => {'if (!isCurrentInputGeneration())',earlySessionGuardAt,);- const materializeAt = body.indexOf('await materializeQueuedOssAttachments');+ const materializeAt = body.indexOf('await materializeQueuedOssAttachmentsDeferred');const materializeGuardAt = body.indexOf('assertCurrentInputGeneration();', materializeAt);const hydrateAt = body.indexOf('await hydrateQueuedAgentReferences', materializeAt);const hydrateGuardAt = body.indexOf('assertCurrentInputGeneration();', hydrateAt);diff --git a/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.ts b/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.tsindex 004ef90e0c..566e179ba4 100644--- a/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.ts+++ b/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.ts@@ -80,7 +80,7 @@ vi.mock('../logger.js', () => ({import {materializeDirectSendOssAttachments,normalizeUserMessage,- materializeQueuedOssAttachments,+ materializeQueuedOssAttachmentsDeferred,} from '../maker-ipc/normalizeAttachments';import { buildAttachmentOssRef } from '../../shared/attachmentOssRef';import { buildPeerAttachmentRef } from '@cindy/device-link';@@ -91,10 +91,11 @@ describe('peer attachment materialization', () => {it('ingests a staged image through existing media ownership without touching OSS', async () => {const metadata = { ticket: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', size: 11, sha256: ATTACHMENT_SHA256, mimeType: 'image/png' };const ref = buildPeerAttachmentRef(metadata);- const result = await materializeQueuedOssAttachments('sess-1', {+ const materialized = await materializeQueuedOssAttachmentsDeferred('sess-1', {files: [{ path: ref, url: ref, mimeType: 'image/png', category: 'image', ext: '.png' }],persistedContent: JSON.stringify({ images: [{ url: ref }] }),- }) as { files: Array<{ url: string }>; persistedContent: string };+ });+ const result = materialized.item as { files: Array<{ url: string }>; persistedContent: string };expect(copyPeerAttachment).toHaveBeenCalledWith(metadata, expect.any(String));expect(copyPeerAttachment).toHaveBeenCalledTimes(1);expect(result.files[0].url).toBe(BLOB_URL);@@ -106,7 +107,7 @@ describe('peer attachment materialization', () => {});describe('queued attachment cleanup regression', () => {- it('cleans earlier materialized OSS objects when a later integrity ref rejects the queue', async () => {+ it('keeps earlier OSS objects retryable when a later integrity ref rejects the queue', async () => {const first = buildAttachmentOssRef({ ossKey: 'oss/first.png', mimeType: 'image/png' });const second = buildAttachmentOssRef({ossKey: 'oss/second.pdf',@@ -115,18 +116,23 @@ describe('queued attachment cleanup regression', () => {sha256: ATTACHMENT_SHA256,});downloadToFile.mockImplementation(async (...args: unknown[]) => {- if (args[0] === 'oss/second.pdf') throw new Error('integrity mismatch');+ if (args[0] === 'oss/second.pdf') {+ throw Object.assign(new Error('integrity mismatch'), { name: 'AttachmentIntegrityError' });+ }});await expect(- materializeQueuedOssAttachments('sess-1', {+ materializeQueuedOssAttachmentsDeferred('sess-1', {files: [{ path: first, mimeType: 'image/png' },{ path: second, mimeType: 'application/pdf' },],}),).rejects.toThrow();- expect(removeRemote).toHaveBeenCalledWith('oss/first.png');+ // 拒绝路径清掉本地物化(cindy-media 引用),已成功的 OSS 保持可重试;坏对象本身立即删。+ expect(removeRefById).toHaveBeenCalledWith('ref-1');+ expect(removeRemote).toHaveBeenCalledWith('oss/second.pdf');+ expect(removeRemote).not.toHaveBeenCalledWith('oss/first.png');});});@@ -226,7 +232,7 @@ describe('normalizeUserMessage — device-link 出方向 OSS 引用物化', () =});});-describe('materializeQueuedOssAttachments — 出方向 files[] + persistedContent 一次性物化', () => {+describe('materializeQueuedOssAttachmentsDeferred — 出方向 files[] + persistedContent 一次性物化', () => {it('files[] 与 persistedContent 共用同一 OSS 引用 → 只下载/入库一次,删 OSS 一次;图片入总仓、非媒体走老缓存', async () => {// 同一张图,控制端给 files[].url/path 与 persistedContent.images[].url 用了同一个 OSS 引用串。const imgRef = buildAttachmentOssRef({@@ -261,11 +267,15 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedConte}),};- const out = (await materializeQueuedOssAttachments('sess-1', item)) as typeof item;+ const materialized = await materializeQueuedOssAttachmentsDeferred('sess-1', item);+ const out = materialized.item as typeof item;// 每个 OSS 对象只下载一次(2 个),即使 files[] 与 persistedContent 各引用一次。expect(downloadToFile).toHaveBeenCalledTimes(2);- // 用后删:每个 ossKey 删一次。+ // 真实入口接受前不删 OSS:删除延迟到 cleanupAfterAcceptance。+ expect(removeRemote).not.toHaveBeenCalled();+ expect(typeof materialized.cleanupAfterAcceptance).toBe('function');+ materialized.cleanupAfterAcceptance?.();expect(removeRemote).toHaveBeenCalledTimes(2);expect(removeRemote).toHaveBeenCalledWith('oss/img.png');expect(removeRemote).toHaveBeenCalledWith('oss/doc.pdf');@@ -304,7 +314,7 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedContefiles: [],}),};- const out = await materializeQueuedOssAttachments('sess-1', item);+ const { item: out } = await materializeQueuedOssAttachmentsDeferred('sess-1', item);expect(out).toBe(item); // 引用相等:零改动expect(downloadToFile).not.toHaveBeenCalled();expect(copyFromPath).not.toHaveBeenCalled();@@ -326,7 +336,8 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedConte}),};- const out = (await materializeQueuedOssAttachments('sess-1', item)) as typeof item;+ const materialized = await materializeQueuedOssAttachmentsDeferred('sess-1', item);+ const out = materialized.item as typeof item;// 读源文件字节 → 总仓 ingest(带 session-attachment 引用);老缓存零参与。expect(readFile).toHaveBeenCalledWith('/workdir/assets/photo.png');@@ -360,9 +371,8 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedContefiles: [],}),};- const out = (await materializeQueuedOssAttachments('sess-1', item)) as {- persistedContent: string;- };+ const materialized = await materializeQueuedOssAttachmentsDeferred('sess-1', item);+ const out = materialized.item as { persistedContent: string };const pc = JSON.parse(out.persistedContent) as { images: Array<{ url: string }> };expect(pc.images[0].url).toBe('/gone/missing.png');});@@ -378,7 +388,7 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedContefiles: [{ name: 'notes.txt', path: '/workdir/notes.txt' }],}),};- const out = await materializeQueuedOssAttachments('sess-1', item);+ const { item: out } = await materializeQueuedOssAttachmentsDeferred('sess-1', item);expect(out).toBe(item); // 无需物化:引用相等原样返回expect(copyFromPath).not.toHaveBeenCalled();});@@ -391,7 +401,8 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedContefiles: [{ url: imgRef, path: imgRef, mimeType: 'image/png' }],persistedContent: '{"text":"hi"}',};- const out = (await materializeQueuedOssAttachments('sess-1', item)) as typeof item;+ const materialized = await materializeQueuedOssAttachmentsDeferred('sess-1', item);+ const out = materialized.item as typeof item;const f = out.files as Array<{ url: string }>;expect(f[0].url).toBe(imgRef); // 原引用保留expect(removeRemote).not.toHaveBeenCalled();@@ -408,7 +419,7 @@ describe('materializeQueuedOssAttachments — 出方向 files[] + persistedContedownloadToFile.mockRejectedValue(new Error('附件完整性校验失败'));await expect(- materializeQueuedOssAttachments('sess-1', {+ materializeQueuedOssAttachmentsDeferred('sess-1', {clientId: 'c1',files: [{ path: ref, mimeType: 'application/pdf' }],persistedContent: JSON.stringify({diff --git a/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts b/apps/desktop/src/main/maker-ipc/normalizeAttachments.tsindex ae81923394..bc23200ab1 100644--- a/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts+++ b/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts@@ -590,7 +590,6 @@ async function materializePersistedContent(async function materializeQueuedOssAttachmentsInternal(sessionId: string,item: unknown,- deferCleanup: boolean,): Promise<{item: unknown;cleanupAfterAcceptance?: () => void;@@ -789,7 +788,7 @@ async function materializeQueuedOssAttachmentsInternal(};return {item: materializedItem,- ...(deferCleanup && (ossKeys.size > 0 || localCleanupCallbacks.length > 0)+ ...(ossKeys.size > 0 || localCleanupCallbacks.length > 0? {cleanupAfterAcceptance: cleanupOss,cleanupBeforeAcceptance,@@ -802,18 +801,9 @@ async function materializeQueuedOssAttachmentsInternal(} catch (err) {await cleanupBeforeAcceptance();throw err;- } finally {- if (!deferCleanup) cleanupOss();}}-export async function materializeQueuedOssAttachments(- sessionId: string,- item: unknown,-): Promise<unknown> {- return (await materializeQueuedOssAttachmentsInternal(sessionId, item, false)).item;-}-/*** Deferred variant for content-bearing input handlers.*@@ -832,7 +822,7 @@ export async function materializeQueuedOssAttachmentsDeferred(cleanupBeforeAcceptance?: () => Promise<void>;cleanupLocalMaterialization?: () => Promise<void>;}> {- return materializeQueuedOssAttachmentsInternal(sessionId, item, true);+ return materializeQueuedOssAttachmentsInternal(sessionId, item);}/**@@ -906,7 +896,6 @@ export async function materializeDirectSendOssAttachments(files: projectedFiles,...(typeof persistedContent === 'string' ? { persistedContent } : {}),},- true,);const projected = materialized.item as { files?: unknown; persistedContent?: unknown };const materializedFiles = Array.isArray(projected.files) ? projected.files : projectedFiles;diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 26d736f622..30c71339da 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -16751,7 +16751,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)// device-link 出方向:远程入队消息的 OSS 引用(files[] + persistedContent)在入队前一次性物化成本地// 临时文件(共用下载、用后删 OSS),保证喂 agent 的 files[] 与落库的 persistedContent 都是本地路径。- // 本机会话无 OSS 引用 → materializeQueuedOssAttachments 原样返回,零开销。+ // 本机会话无 OSS 引用 → materializeQueuedOssAttachmentsDeferred 原样返回,零开销。ipcMain.handle(MAKER_INVOKE.INPUT_ENQUEUE,async (event, sessionId: unknown, item: unknown, opts?: unknown) => {diff --git a/apps/mobile/docs/remote-control-plan.md b/apps/mobile/docs/remote-control-plan.mdindex 79ac7fdb81..f62e9c2fc6 100644--- a/apps/mobile/docs/remote-control-plan.md+++ b/apps/mobile/docs/remote-control-plan.md@@ -1298,7 +1298,7 @@ apps/mobile/src/- media lightbox。已完成首版:HTTP/data image 可全屏预览,`xdt-*://` 打开详情后自动取件,失败显示可重试占位和原始 URL。- tool payload full-screen。已完成首版:tool_result、媒体 URL、文件路径/文本预览、diff 全量内容统一走 `MessagePayloadModal`。- diff viewer。已完成移动端结构化版:全屏分段展示完整 Edit / Write / MultiEdit payload,每段保留旧内容 / 新内容两栏横向对照;后续再补桌面同级 line-level context folding 和更细的语法增强。-- 附件上传:已完成真实发送链路——手机端输入被控电脑上的文件路径,通过被控端 `fs:stat-path` 校验为文件后,构造桌面兼容队列项并随消息发送。手机本机文件已接 `expo-document-picker` + presign-put / OSS PUT / `cindy-oss-attach://` 链路;图片附件现在会写入 `persistedContent.images[]` / `chatMessage.images`,非图片文件写入 `persistedContent.files[]` / `chatMessage.files`,顶层 `files[]` 仍保留全部附件供被控端 `materializeQueuedOssAttachments` 一次性物化和去重。photo/library/share sheet 作为更好的原生入口仍留后续。+- 附件上传:已完成真实发送链路——手机端输入被控电脑上的文件路径,通过被控端 `fs:stat-path` 校验为文件后,构造桌面兼容队列项并随消息发送。手机本机文件已接 `expo-document-picker` + presign-put / OSS PUT / `cindy-oss-attach://` 链路;图片附件现在会写入 `persistedContent.images[]` / `chatMessage.images`,非图片文件写入 `persistedContent.files[]` / `chatMessage.files`,顶层 `files[]` 仍保留全部附件供被控端 `materializeQueuedOssAttachmentsDeferred` 一次性物化和去重。photo/library/share sheet 作为更好的原生入口仍留后续。验收:diff --git a/apps/mobile/src/session/types.ts b/apps/mobile/src/session/types.tsindex 8017735d59..aeab5b959e 100644--- a/apps/mobile/src/session/types.ts+++ b/apps/mobile/src/session/types.ts@@ -176,7 +176,7 @@ export interface RemoteSerializedAttachment {truncated?: boolean;/*** 图片带用户手绘圈点标注(lightbox 标注模式的烧录产物)。字段随 wire 契约- * 原样透传到被控端(materializeQueuedOssAttachments 只改写 url/path),桌面+ * 原样透传到被控端(materializeQueuedOssAttachmentsDeferred 只改写 url/path),桌面* 端 buildMakerUserMessage 据此给模型注入「红色笔迹是用户标注」的固定说明,* 与桌面 AgentInputSerializedFile.annotated 同一契约。*/