Skip to content

Commit 3fc723c

Browse files
committed
fix: preserve pathless browser-uploaded file attachments on retry/edit
1 parent 65e225d commit 3fc723c

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

ui/goose2/src/features/chat/lib/__tests__/attachments.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,30 @@ describe("rebuildAttachmentDrafts", () => {
121121
expect(drafts[0].kind).toBe("file");
122122
expect(drafts[0].name).toBe("photo.jpg");
123123
});
124+
125+
it("preserves pathless browser-uploaded file attachments", () => {
126+
const msg: Message = {
127+
id: "m4",
128+
role: "user",
129+
created: Date.now(),
130+
content: [{ type: "text", text: "see attached" }],
131+
metadata: {
132+
userVisible: true,
133+
agentVisible: true,
134+
attachments: [
135+
{
136+
type: "file",
137+
name: "report.pdf",
138+
mimeType: "application/pdf",
139+
},
140+
],
141+
},
142+
};
143+
144+
const drafts = rebuildAttachmentDrafts(msg);
145+
146+
expect(drafts).toHaveLength(1);
147+
expect(drafts[0].kind).toBe("file");
148+
expect(drafts[0].name).toBe("report.pdf");
149+
});
124150
});

ui/goose2/src/features/chat/lib/attachments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ export function rebuildAttachmentDrafts(
112112
name: att.name,
113113
path: att.path,
114114
});
115-
} else if (att.type === "file" && att.path) {
115+
} else if (att.type === "file") {
116116
// Skip image file entries when content blocks already provide the base64
117117
if (hasImageDrafts && att.mimeType?.startsWith("image/")) continue;
118118
drafts.push({
119119
id: crypto.randomUUID(),
120120
kind: "file",
121121
name: att.name,
122-
path: att.path,
122+
...(att.path ? { path: att.path } : {}),
123123
mimeType: att.mimeType,
124124
});
125125
}

0 commit comments

Comments
 (0)