Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 原图就绪后立即更新上传中预览
Dash81de6007bdc6
diff --git a/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx b/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsxindex 2057eeca45..f77b9bf1c9 100644--- a/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx+++ b/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx@@ -214,15 +214,19 @@ describe("composer attachment tray overlay foreground", () => {uploading,delivered,showTray,+ pendingUri,}: {uploading: boolean;delivered: boolean;showTray: boolean;+ pendingUri: string;}) {const props = {attachments: delivered ? [attachment("done")] : [],previews: { done: "file:///durable.jpg" },- pendingUploads: uploading ? [pending("uploading")] : [],+ pendingUploads: uploading+ ? [{ ...pending("uploading"), previewUri: pendingUri }]+ : [],getUploadedAttachmentId: (id: string) =>delivered && id === "uploading" ? "done" : undefined,};@@ -242,13 +246,19 @@ describe("composer attachment tray overlay foreground", () => {</>);}- const render = (uploading: boolean, delivered = false, showTray = true) =>+ const render = (+ uploading: boolean,+ delivered = false,+ showTray = true,+ pendingUri = "file:///uploading.jpg",+ ) =>act(() =>root.render(<Composeruploading={uploading}delivered={delivered}showTray={showTray}+ pendingUri={pendingUri}/>,),);@@ -265,6 +275,14 @@ describe("composer attachment tray overlay foreground", () => {expect(host.querySelector('[data-testid="lightbox"]')?.textContent).toBe("file:///uploading.jpg",);+ // The same open viewer upgrades from the picker thumbnail before PUT finishes.+ theme.files.add("file:///original.jpg");+ render(true, false, false, "file:///original.jpg");+ expect(host.querySelector('[data-testid="lightbox"]')?.textContent).toBe(+ "file:///original.jpg",+ );+ expect(theme.mounts).toBe(1);+ theme.files.delete("file:///original.jpg");theme.files.delete("file:///uploading.jpg");theme.files.add("file:///durable.jpg");// onUploaded publishes the delivered attachment before the controller removes pending.diff --git a/apps/mobile/src/__tests__/mobileLocalAttachmentUpload.test.ts b/apps/mobile/src/__tests__/mobileLocalAttachmentUpload.test.tsindex 42cc053890..7b1baeaead 100644--- a/apps/mobile/src/__tests__/mobileLocalAttachmentUpload.test.ts+++ b/apps/mobile/src/__tests__/mobileLocalAttachmentUpload.test.ts@@ -270,6 +270,59 @@ describe('createMobileLocalAttachmentUploadController', () => {expect(uploaded[0]?.uploadedUri).toBe('file:///tmp/downsampled.jpg');});+ // Regression: the picker returns a tiny thumbnail before resolving the original.+ // Existing tests only checked onUploaded; unit coverage must observe the preview+ // while preprocessing/PUT are still pending, and after failure recycles that file.+ it('upgrades the pending preview before upload and drops recycled originals on retry', async () => {+ const gate = gatedUpload();+ let finishResolve!: (value: { uri: string }) => void;+ let finishPreprocess!: (value: { uri: string; name: string; size: number }) => void;+ const cleaned: string[] = [];+ const { deps, pendingSnapshots } = makeDeps({+ upload: gate.upload,+ preprocess: () => new Promise((resolve) => { finishPreprocess = resolve; }),+ });+ const controller = createMobileLocalAttachmentUploadController(deps);+ const latest = () => pendingSnapshots.at(-1)![0]!;+ controller.enqueue([{+ ...candidate('photo.jpg'),+ uri: 'data:image/jpeg;base64,tiny-thumbnail',+ resolve: () => new Promise((resolve) => { finishResolve = resolve; }),+ cleanupLocalUris: async (uris) => { cleaned.push(...uris); },+ }], { token: 't' });+ const initial = latest();+ try {+ await flush();+ expect(latest().previewUri).toBe(initial.previewUri);+ finishResolve({ uri: 'file:///original.jpg' });+ await flush();+ expect(latest().previewUri).toBe('file:///original.jpg');+ expect(latest().localId).toBe(initial.localId);+ expect(gate.inFlight()).toEqual([]);+ finishPreprocess({ uri: 'file:///encoded.jpg', name: 'photo.jpg', size: 500_000 });+ await flush();+ expect(gate.inFlight()).toEqual(['photo.jpg']);+ expect(latest().previewUri).toBe('file:///original.jpg');+ gate.fail('photo.jpg');+ await controller.waitForIdle();+ expect(cleaned).toContain('file:///original.jpg');+ expect(latest()).toMatchObject({ previewUri: initial.previewUri, failed: true });+ controller.retry(initial.localId, { token: 't2' });+ await flush();+ expect(latest().previewUri).toBe(initial.previewUri);+ finishResolve({ uri: 'file:///retry-original.jpg' });+ await flush();+ expect(latest().previewUri).toBe('file:///retry-original.jpg');+ finishPreprocess({ uri: 'file:///retry-encoded.jpg', name: 'photo.jpg', size: 500_000 });+ await flush();+ gate.release('photo.jpg');+ expect(await controller.waitForIdle()).toEqual({ failedCount: 0 });+ } finally {+ controller.dispose();+ finishPreprocess?.({ uri: 'file:///cleanup.jpg', name: 'photo.jpg', size: 500_000 });+ }+ });+it('resolve 型任务:onUploaded 回传就位后的 candidate,保留来源与 composer 代际', async () => {const { deps, uploaded } = makeDeps();const controller = createMobileLocalAttachmentUploadController(deps);diff --git a/apps/mobile/src/session/mobileImageAttachment.ts b/apps/mobile/src/session/mobileImageAttachment.tsindex d818947e53..1a8f76dc4d 100644--- a/apps/mobile/src/session/mobileImageAttachment.ts+++ b/apps/mobile/src/session/mobileImageAttachment.ts@@ -17,7 +17,7 @@ export type MobileImageAttachmentCandidate = MobileAttachmentUploadCandidate & {height?: number | null;/*** 仅 HEIC / HEIF 等非白名单格式带此钩子:任务开跑时就地转 JPEG(#3889)。- * 托盘预览仍用原始 uri;返回字段由上传管线覆盖到 candidate 上。+ * 返回字段由上传管线覆盖到 candidate 上,并更新上传中预览。*/resolve?: () => Promise<{ uri: string; name: string; mimeType: string; size: number }>;};diff --git a/apps/mobile/src/session/mobileLocalAttachmentUpload.ts b/apps/mobile/src/session/mobileLocalAttachmentUpload.tsindex 59a00cf44d..50638a462a 100644--- a/apps/mobile/src/session/mobileLocalAttachmentUpload.ts+++ b/apps/mobile/src/session/mobileLocalAttachmentUpload.ts@@ -43,8 +43,8 @@ export interface MobileLocalAttachmentUploadCandidate {height?: number | null;/*** 任务真正开跑时的异步就位钩子(相册 ph:// → file:// 换址、HEIC 转码缩边等重活)。- * 返回的字段覆盖到 candidate 上再进后续管线;托盘预览始终用原始 uri,所以入队- * 当帧就有缩略图,重活全在后台。+ * 返回的字段覆盖到 candidate 上再进后续管线;入队时先显示缩略图,就位后+ * 立即切换预览地址,无需等待压缩和上传结束。重活全在后台。*/resolve?: (signal?: AbortSignal) => Promise<Partial<Pick<MobileLocalAttachmentUploadCandidate,@@ -282,7 +282,7 @@ export function createMobileLocalAttachmentUploadController(pending.push({localId: task.localId,kind: task.candidate.kind,- previewUri: task.candidate.uri,+ previewUri: task.resolvedSource?.uri || task.candidate.uri,name: task.candidate.name,size: task.candidate.size,sourceId: task.candidate.sourceId,@@ -324,6 +324,8 @@ export function createMobileLocalAttachmentUploadController(if (keepOriginal) task.prepared = undefined;const cleanup = task.candidate.cleanupLocalUris;if (!cleanup) return;+ // Failed uploads retain the picker thumbnail, but recycle resolved originals.+ task.resolvedSource = undefined;const originalUri = task.candidate.uri;const uris = [...task.localUris].filter((uri) => !keepOriginal || uri !== originalUri);task.localUris = keepOriginal ? new Set([originalUri]) : new Set();@@ -361,6 +363,7 @@ export function createMobileLocalAttachmentUploadController(}task.resolvedSource = source;task.localUris.add(source.uri);+ if (!disposed && !task.discarded && source.uri !== task.candidate.uri) notifyPending();// 只有图片需要降采样;文件(pdf / office / 文本)与已优化产物原样直传。const prepared = source.kind === 'image' && !source.skipPreprocess? await step(deps.preprocess({diff --git a/docs/dev-rules/mobile-development.md b/docs/dev-rules/mobile-development.mdindex 6be6d7376c..214c7b71fa 100644--- a/docs/dev-rules/mobile-development.md+++ b/docs/dev-rules/mobile-development.md@@ -83,10 +83,12 @@ pnpm --filter mobile test:smoke### 相册选图与 iCloud 原图-iOS 的系统选图器在确认后立即把选中项交给现有附件队列。预览只读取本机小缩略图,+iOS 的系统选图器在确认后立即把选中项交给现有附件队列。首帧预览只读取本机小缩略图,不等待 iCloud 原图;受限照片权限下拿不到缩略图时保留附件占位,不扩大照片库权限。原图由选图器授予的 `NSItemProvider` 在队列的 `resolve` 阶段读取,随后沿用格式转换、压缩、上传和持久发件箱交接。发送自动等待原图就绪,不要求用户另行下载或再次发送。+原图就绪后立即更新上传中预览,已打开的查看器同步换成清晰图片,不等待压缩或上传结束。+失败回收原图临时文件时,预览回到仍有效的选图缩略图;重试就绪后再次更新。失败保留选中项供重试,移除/换任务/成功交付后释放原生句柄;取消后的迟到文件只清理不回填。临时副本使用 App 私有 `Caches/ImagePicker`,由现有附件生命周期回收。