@@ -15,6 +15,7 @@ import { URI } from '../../../../base/common/uri.js';
1515import { IRange } from '../../../../editor/common/core/range.js' ;
1616import { SymbolKinds } from '../../../../editor/common/languages.js' ;
1717import { localize } from '../../../../nls.js' ;
18+ import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js' ;
1819import { CodeDataTransfers , containsDragType , DocumentSymbolTransferData , extractEditorsDropData , extractSymbolDropData , IDraggedResourceEditorInput } from '../../../../platform/dnd/browser/dnd.js' ;
1920import { FileType , IFileService , IFileSystemProvider } from '../../../../platform/files/common/files.js' ;
2021import { IThemeService , Themable } from '../../../../platform/theme/common/themeService.js' ;
@@ -49,6 +50,7 @@ export class ChatDragAndDrop extends Themable {
4950 @IExtensionService private readonly extensionService : IExtensionService ,
5051 @IFileService protected readonly fileService : IFileService ,
5152 @IEditorService protected readonly editorService : IEditorService ,
53+ @IDialogService protected readonly dialogService : IDialogService
5254 ) {
5355 super ( themeService ) ;
5456
@@ -233,7 +235,7 @@ export class ChatDragAndDrop extends Themable {
233235
234236 private async resolveAttachContext ( editorInput : IDraggedResourceEditorInput ) : Promise < IChatRequestVariableEntry | undefined > {
235237 // Image
236- const imageContext = await getImageAttachContext ( editorInput , this . fileService ) ;
238+ const imageContext = await getImageAttachContext ( editorInput , this . fileService , this . dialogService ) ;
237239 if ( imageContext ) {
238240 return this . extensionService . extensions . some ( ext => isProposedApiEnabled ( ext , 'chatReferenceBinaryData' ) ) ? imageContext : undefined ;
239241 }
@@ -350,8 +352,9 @@ export class EditsDragAndDrop extends ChatDragAndDrop {
350352 @IExtensionService extensionService : IExtensionService ,
351353 @IFileService fileService : IFileService ,
352354 @IEditorService editorService : IEditorService ,
355+ @IDialogService dialogService : IDialogService
353356 ) {
354- super ( attachmentModel , styles , themeService , extensionService , fileService , editorService ) ;
357+ super ( attachmentModel , styles , themeService , extensionService , fileService , editorService , dialogService ) ;
355358 }
356359
357360 protected override handleDrop ( context : IChatRequestVariableEntry [ ] ) : void {
@@ -424,14 +427,18 @@ function getResourceAttachContext(resource: URI, isDirectory: boolean): IChatReq
424427 } ;
425428}
426429
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 > {
428431 if ( ! editor . resource ) {
429432 return undefined ;
430433 }
431434
432435 if ( / \. ( p n g | j p g | j p e g | g i f | w e b p ) $ / i. test ( editor . resource . path ) ) {
433436 const fileName = basename ( editor . resource ) ;
434437 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+ }
435442 const resizedImage = await resizeImage ( readFile . value . buffer ) ;
436443 return {
437444 id : editor . resource . toString ( ) ,
0 commit comments