Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 新建任务恢复发件箱时保留标注标与标注区域
Dashedb44a7b2b36
diff --git a/apps/mobile/src/__tests__/durableOutboxFiles.test.ts b/apps/mobile/src/__tests__/durableOutboxFiles.test.tsindex 6b2def75cf..31efb0a278 100644--- a/apps/mobile/src/__tests__/durableOutboxFiles.test.ts+++ b/apps/mobile/src/__tests__/durableOutboxFiles.test.ts@@ -180,6 +180,25 @@ describe("outbox-owned attachment bytes", () => {expect(reburned.annotated).toBe(true);expect(reburned.annotationRegions).toBeUndefined();});+ it("keeps the annotated flag and regions when an already-retained upload is retained again (new-task recovery)", async () => {+ const first = await retainOutboxFile(record, 0, {+ ...source,+ annotation: {+ strokes: [{ points: [{ x: 0.1, y: 0.2 }, { x: 0.3, y: 0.4 }] }],+ sourceUri: "file:///cache/src.jpg",+ sourceMimeType: "image/jpeg",+ },+ });+ // new.tsx 恢复时:{ ...oldUpload, uri },没有 candidate.annotation。+ const again = await retainOutboxFile(record, 1, {+ ...first,+ uri: durableOutboxUploadUri(record, first),+ });+ expect(again.annotated).toBe(true);+ expect(again.annotationRegions).toEqual([{ x0: 0.1, y0: 0.2, x1: 0.3, y1: 0.4 }]);+ const plain = await retainOutboxFile(record, 2, { ...source, annotated: false });+ expect(plain.annotated).toBeUndefined();+ });it("rejects a partial copy rather than accepting a message with missing bytes", async () => {fs.getInfoAsync.mockResolvedValue({exists: true,diff --git a/apps/mobile/src/session/durableOutboxFiles.ts b/apps/mobile/src/session/durableOutboxFiles.tsindex e413494c88..0794f10e9c 100644--- a/apps/mobile/src/session/durableOutboxFiles.ts+++ b/apps/mobile/src/session/durableOutboxFiles.ts@@ -5,7 +5,7 @@ import { DURABLE_OUTBOX_PREFIX, type DurableOutboxRecord, type DurableUpload } fimport type { MobileLocalAttachmentUploadCandidate } from "./mobileLocalAttachmentUpload";import { isAttachmentOssRef } from './attachmentOssRef';import { isPeerAttachmentRef } from '@cindy/device-link';-import { summarizeAnnotationRegions } from '@cindy/maker-shared/image-annotation';+import { sanitizeAnnotationRegions, summarizeAnnotationRegions } from '@cindy/maker-shared/image-annotation';/** Desktop path references already have their source on the controlled device. */export function outboxAttachmentNeedsLocalBytes(attachment: { path: string }): boolean {@@ -30,20 +30,33 @@ export function durableOutboxUploadUri(throw new Error("OUTBOX_FILE_INVALID");return durableOutboxDirectory(record) + upload.fileName;}-/** 标注区域随发件箱落盘(与乐观上传路径同一归纳算法),重投时照样带给被控端。 */-function annotationRegionsFor(- source: MobileLocalAttachmentUploadCandidate,-): Pick<DurableUpload, "annotationRegions"> {- // 底图已是烧录图(旧红线位置不可知)时不带区域,见 annotationRegionsForUpload。- if (!source.annotation || source.annotation.baseAnnotated) return {};- const regions = summarizeAnnotationRegions(source.annotation.strokes);- return regions.length > 0 ? { annotationRegions: regions } : {};+/**+ * 重新留存时可以传入已落盘的 DurableUpload(恢复新建任务时 new.tsx 以+ * `{ ...oldUpload, uri }` 再次留存),它没有 candidate.annotation,但带着上一次落盘的+ * 标注字段——这些字段必须原样沿用,否则恢复后的同一条消息会丢掉 annotated 标与区域。+ */+type RetainSource = MobileLocalAttachmentUploadCandidate &+ Partial<Pick<DurableUpload, "annotated" | "annotationRegions">>;++/** 标注字段随发件箱落盘(区域与乐观上传路径同一归纳算法),重投时照样带给被控端。 */+function annotationFieldsFor(+ source: RetainSource,+): Pick<DurableUpload, "annotated" | "annotationRegions"> {+ if (source.annotation) {+ // 底图已是烧录图(旧红线位置不可知)时不带区域,见 annotationRegionsForUpload。+ if (source.annotation.baseAnnotated) return { annotated: true };+ const regions = summarizeAnnotationRegions(source.annotation.strokes);+ return { annotated: true, ...(regions.length > 0 ? { annotationRegions: regions } : {}) };+ }+ if (source.annotated !== true) return {};+ const regions = sanitizeAnnotationRegions(source.annotationRegions);+ return { annotated: true, ...(regions ? { annotationRegions: regions } : {}) };}export async function retainOutboxFile(record: DurableOutboxRecord,slot: number,- source: MobileLocalAttachmentUploadCandidate,+ source: RetainSource,): Promise<DurableUpload> {await initializeOutboxFiles();const extension =@@ -55,8 +68,7 @@ export async function retainOutboxFile(mimeType: source.mimeType,kind: source.kind,size: source.size,- ...(source.annotation ? { annotated: true } : {}),- ...annotationRegionsFor(source),+ ...annotationFieldsFor(source),};await FileSystem.makeDirectoryAsync(durableOutboxDirectory(record), {intermediates: true,