fix: preserve pathless browser-uploaded file attachments on retry/edit

This commit is contained in:
Taylor Ho
2026-04-15 06:25:38 -10:00
parent 143ab86766
commit cbf6732ee0
2 changed files with 28 additions and 2 deletions
@@ -121,4 +121,30 @@ describe("rebuildAttachmentDrafts", () => {
expect(drafts[0].kind).toBe("file");
expect(drafts[0].name).toBe("photo.jpg");
});
it("preserves pathless browser-uploaded file attachments", () => {
const msg: Message = {
id: "m4",
role: "user",
created: Date.now(),
content: [{ type: "text", text: "see attached" }],
metadata: {
userVisible: true,
agentVisible: true,
attachments: [
{
type: "file",
name: "report.pdf",
mimeType: "application/pdf",
},
],
},
};
const drafts = rebuildAttachmentDrafts(msg);
expect(drafts).toHaveLength(1);
expect(drafts[0].kind).toBe("file");
expect(drafts[0].name).toBe("report.pdf");
});
});
@@ -112,14 +112,14 @@ export function rebuildAttachmentDrafts(
name: att.name,
path: att.path,
});
} else if (att.type === "file" && att.path) {
} else if (att.type === "file") {
// Skip image file entries when content blocks already provide the base64
if (hasImageDrafts && att.mimeType?.startsWith("image/")) continue;
drafts.push({
id: crypto.randomUUID(),
kind: "file",
name: att.name,
path: att.path,
...(att.path ? { path: att.path } : {}),
mimeType: att.mimeType,
});
}