Skip to content

Commit 45ef5fd

Browse files
fix(desktop): allow larger binary attachments
Allows image/binary attachments to use the binary size budget while keeping text-like attachments on the text limit.
1 parent 398cbc6 commit 45ef5fd

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

apps/desktop/src/main/prompt-context.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ describe('preparePromptContext', () => {
3232
});
3333

3434
it('allows binary attachments (png) up to 10MB - 500KB png passes', async () => {
35+
// Binary attachments (images) can be up to 10MB - allowed larger than text
3536
await expect(
3637
preparePromptContext({
3738
attachments: [{ path: 'C:/repo/image.png', name: 'image.png', size: 543_034 }],
3839
}),
3940
).rejects.toMatchObject({
4041
code: 'ATTACHMENT_READ_FAILED',
4142
});
43+
// It fails because the file doesn't exist, but importantly - NOT ATTACHMENT_TOO_LARGE
4244
});
4345

4446
it('encodes supported image attachments as data URLs', async () => {

apps/desktop/src/main/prompt-context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const IMAGE_MIME_TYPES: Record<string, string> = {
4040

4141
const MAX_ATTACHMENT_CHARS = 6_000;
4242
const MAX_TEXT_ATTACHMENT_BYTES = 256_000;
43-
const MAX_BINARY_ATTACHMENT_BYTES = 10_000_000;
43+
const MAX_BINARY_ATTACHMENT_BYTES = 10_000_000; // 10MB - images get full read for data URL, non-image binary only needs filename
4444
const MAX_URL_EXCERPT_CHARS = 1_200;
4545
const MAX_URL_RESPONSE_BYTES = 256_000;
4646
const REFERENCE_CONTENT_TYPES = ['text/html', 'application/xhtml+xml'];
@@ -72,6 +72,8 @@ async function readAttachment(file: LocalInputFile): Promise<AttachmentContext>
7272
const extension = extname(file.name).toLowerCase();
7373
const imageMimeType = IMAGE_MIME_TYPES[extension];
7474

75+
// Binary attachments (images, etc) - images need full content for data URL
76+
// So allow larger size limit than text
7577
const isKnownTextExtension = TEXT_EXTS.has(extension);
7678
const maxFileBytes = isKnownTextExtension
7779
? MAX_TEXT_ATTACHMENT_BYTES

0 commit comments

Comments
 (0)