@@ -15,6 +15,7 @@ import { URI } from '../../../../base/common/uri.js';
15
15
import { IRange } from '../../../../editor/common/core/range.js' ;
16
16
import { SymbolKinds } from '../../../../editor/common/languages.js' ;
17
17
import { localize } from '../../../../nls.js' ;
18
+ import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js' ;
18
19
import { CodeDataTransfers , containsDragType , DocumentSymbolTransferData , extractEditorsDropData , extractSymbolDropData , IDraggedResourceEditorInput } from '../../../../platform/dnd/browser/dnd.js' ;
19
20
import { FileType , IFileService , IFileSystemProvider } from '../../../../platform/files/common/files.js' ;
20
21
import { IThemeService , Themable } from '../../../../platform/theme/common/themeService.js' ;
@@ -49,6 +50,7 @@ export class ChatDragAndDrop extends Themable {
49
50
@IExtensionService private readonly extensionService : IExtensionService ,
50
51
@IFileService protected readonly fileService : IFileService ,
51
52
@IEditorService protected readonly editorService : IEditorService ,
53
+ @IDialogService protected readonly dialogService : IDialogService
52
54
) {
53
55
super ( themeService ) ;
54
56
@@ -233,7 +235,7 @@ export class ChatDragAndDrop extends Themable {
233
235
234
236
private async resolveAttachContext ( editorInput : IDraggedResourceEditorInput ) : Promise < IChatRequestVariableEntry | undefined > {
235
237
// Image
236
- const imageContext = await getImageAttachContext ( editorInput , this . fileService ) ;
238
+ const imageContext = await getImageAttachContext ( editorInput , this . fileService , this . dialogService ) ;
237
239
if ( imageContext ) {
238
240
return this . extensionService . extensions . some ( ext => isProposedApiEnabled ( ext , 'chatReferenceBinaryData' ) ) ? imageContext : undefined ;
239
241
}
@@ -350,8 +352,9 @@ export class EditsDragAndDrop extends ChatDragAndDrop {
350
352
@IExtensionService extensionService : IExtensionService ,
351
353
@IFileService fileService : IFileService ,
352
354
@IEditorService editorService : IEditorService ,
355
+ @IDialogService dialogService : IDialogService
353
356
) {
354
- super ( attachmentModel , styles , themeService , extensionService , fileService , editorService ) ;
357
+ super ( attachmentModel , styles , themeService , extensionService , fileService , editorService , dialogService ) ;
355
358
}
356
359
357
360
protected override handleDrop ( context : IChatRequestVariableEntry [ ] ) : void {
@@ -424,14 +427,18 @@ function getResourceAttachContext(resource: URI, isDirectory: boolean): IChatReq
424
427
} ;
425
428
}
426
429
427
- async function getImageAttachContext ( editor : EditorInput | IDraggedResourceEditorInput , fileService : IFileService ) : Promise < IChatRequestVariableEntry | undefined > {
430
+ async function getImageAttachContext ( editor : EditorInput | IDraggedResourceEditorInput , fileService : IFileService , dialogService : IDialogService ) : Promise < IChatRequestVariableEntry | undefined > {
428
431
if ( ! editor . resource ) {
429
432
return undefined ;
430
433
}
431
434
432
435
if ( / \. ( p n g | j p g | j p e g | g i f | w e b p ) $ / i. test ( editor . resource . path ) ) {
433
436
const fileName = basename ( editor . resource ) ;
434
437
const readFile = await fileService . readFile ( editor . resource ) ;
438
+ if ( readFile . size > 30 * 1024 * 1024 ) { // 30 MB
439
+ dialogService . error ( localize ( 'imageTooLarge' , 'Image is too large' ) , localize ( 'imageTooLargeMessage' , 'The image {0} is too large to be attached.' , fileName ) ) ;
440
+ throw new Error ( 'Image is too large' ) ;
441
+ }
435
442
const resizedImage = await resizeImage ( readFile . value . buffer ) ;
436
443
return {
437
444
id : editor . resource . toString ( ) ,
0 commit comments