3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { DataTransfers } from '../../../../../base/browser/dnd.js' ;
7
6
import * as dom from '../../../../../base/browser/dom.js' ;
8
7
import { ButtonWithIcon } from '../../../../../base/browser/ui/button/button.js' ;
9
- import { applyDragImage } from '../../../../../base/browser/ui/dnd/dnd.js' ;
10
- import { assertNever } from '../../../../../base/common/assert.js' ;
11
8
import { VSBuffer } from '../../../../../base/common/buffer.js' ;
12
9
import { Codicon } from '../../../../../base/common/codicons.js' ;
13
10
import { Emitter } from '../../../../../base/common/event.js' ;
14
11
import { IMarkdownString } from '../../../../../base/common/htmlContent.js' ;
15
12
import { Disposable } from '../../../../../base/common/lifecycle.js' ;
16
- import { getExtensionForMimeType } from '../../../../../base/common/mime.js' ;
17
13
import { autorun , ISettableObservable , observableValue } from '../../../../../base/common/observable.js' ;
18
14
import { basename , joinPath } from '../../../../../base/common/resources.js' ;
19
15
import { ThemeIcon } from '../../../../../base/common/themables.js' ;
@@ -34,9 +30,8 @@ import { ILabelService } from '../../../../../platform/label/common/label.js';
34
30
import { INotificationService } from '../../../../../platform/notification/common/notification.js' ;
35
31
import { IProgressService , ProgressLocation } from '../../../../../platform/progress/common/progress.js' ;
36
32
import { IWorkspaceContextService } from '../../../../../platform/workspace/common/workspace.js' ;
37
- import { fillEditorsDragData } from '../../../../browser/dnd.js' ;
38
33
import { REVEAL_IN_EXPLORER_COMMAND_ID } from '../../../files/browser/fileConstants.js' ;
39
- import { getAttachableImageExtension , IChatRequestVariableEntry , OmittedState } from '../../common/chatModel.js' ;
34
+ import { getAttachableImageExtension , IChatRequestVariableEntry } from '../../common/chatModel.js' ;
40
35
import { IChatRendererContent } from '../../common/chatViewModel.js' ;
41
36
import { ChatTreeItem , IChatCodeBlockInfo } from '../chat.js' ;
42
37
import { CodeBlockPart , ICodeBlockData , ICodeBlockRenderOptions } from '../codeBlockPart.js' ;
@@ -57,16 +52,11 @@ export interface IChatCollapsibleIOCodePart {
57
52
export interface IChatCollapsibleIODataPart {
58
53
kind : 'data' ;
59
54
value : Uint8Array ;
60
- mimeType : string ;
61
- uri ?: URI ;
62
- }
63
-
64
- export interface IChatCollapsibleIOResourcePart {
65
- kind : 'resource' ;
55
+ mimeType : string | undefined ;
66
56
uri : URI ;
67
57
}
68
58
69
- export type ChatCollapsibleIOPart = IChatCollapsibleIOCodePart | IChatCollapsibleIODataPart | IChatCollapsibleIOResourcePart ;
59
+ export type ChatCollapsibleIOPart = IChatCollapsibleIOCodePart | IChatCollapsibleIODataPart ;
70
60
71
61
export interface IChatCollapsibleInputData extends IChatCollapsibleIOCodePart { }
72
62
export interface IChatCollapsibleOutputData {
@@ -192,11 +182,11 @@ export class ChatCollapsibleInputOutputContentPart extends Disposable {
192
182
continue ;
193
183
}
194
184
195
- const group : ( IChatCollapsibleIODataPart | IChatCollapsibleIOResourcePart ) [ ] = [ ] ;
185
+ const group : IChatCollapsibleIODataPart [ ] = [ ] ;
196
186
for ( let k = i ; k < output . parts . length ; k ++ ) {
197
187
const part = output . parts [ k ] ;
198
- if ( ! ( part . kind === 'data' || part . kind === 'resource' ) ) {
199
- continue ;
188
+ if ( part . kind !== 'data' ) {
189
+ break ;
200
190
}
201
191
group . push ( part ) ;
202
192
}
@@ -209,21 +199,17 @@ export class ChatCollapsibleInputOutputContentPart extends Disposable {
209
199
return contents . root ;
210
200
}
211
201
212
- private addResourceGroup ( parts : ( IChatCollapsibleIODataPart | IChatCollapsibleIOResourcePart ) [ ] , container : HTMLElement ) {
202
+ private addResourceGroup ( parts : IChatCollapsibleIODataPart [ ] , container : HTMLElement ) {
213
203
const el = dom . h ( '.chat-collapsible-io-resource-group' , [
214
204
dom . h ( '.chat-collapsible-io-resource-items@items' ) ,
215
205
dom . h ( '.chat-collapsible-io-resource-actions@actions' ) ,
216
206
] ) ;
217
207
218
208
const entries = parts . map ( ( part ) : IChatRequestVariableEntry => {
219
- if ( part . kind === 'data' && getAttachableImageExtension ( part . mimeType ) ) {
220
- return { kind : 'image' , id : generateUuid ( ) , name : part . uri ? basename ( part . uri ) : `image.${ getAttachableImageExtension ( part . mimeType ) } ` , value : part . value , mimeType : part . mimeType , isURL : false } ;
221
- } else if ( part . kind === 'resource' ) {
222
- return { kind : 'file' , id : generateUuid ( ) , name : basename ( part . uri ) , fullName : part . uri . path , value : part . uri } ;
223
- } else if ( part . kind === 'data' ) {
224
- return { kind : 'generic' , id : generateUuid ( ) , name : localize ( 'chat.unknownData' , "Unknown Data" ) , value : part . value , fullName : localize ( 'chat.unknownData.full' , "Unknown Data with MIME type {0}" , part . mimeType ) , omittedState : OmittedState . Full } ;
209
+ if ( part . mimeType && getAttachableImageExtension ( part . mimeType ) ) {
210
+ return { kind : 'image' , id : generateUuid ( ) , name : basename ( part . uri ) , value : part . value , mimeType : part . mimeType , isURL : false , references : [ { kind : 'reference' , reference : part . uri } ] } ;
225
211
} else {
226
- assertNever ( part ) ;
212
+ return { kind : 'file' , id : generateUuid ( ) , name : basename ( part . uri ) , fullName : part . uri . path , value : part . uri } ;
227
213
}
228
214
} ) ;
229
215
@@ -250,23 +236,6 @@ export class ChatCollapsibleInputOutputContentPart extends Disposable {
250
236
}
251
237
} ;
252
238
253
- attachments . dragStartHandler = ( attachment , event , element ) => {
254
- if ( ! event . dataTransfer ) {
255
- return ;
256
- }
257
-
258
- const index = entries . indexOf ( attachment ) ;
259
- const part = parts [ index ] ;
260
- if ( ! part . uri ) {
261
- return ;
262
- }
263
-
264
- applyDragImage ( event , element , attachment . name ) ;
265
- event . dataTransfer . effectAllowed = 'copy' ;
266
- event . dataTransfer . setData ( DataTransfers . TEXT , part . uri . toString ( ) ) ;
267
- this . _instantiationService . invokeFunction ( accessor => fillEditorsDragData ( accessor , [ part . uri ! ] , event ) ) ;
268
- } ;
269
-
270
239
el . items . appendChild ( attachments . domNode ! ) ;
271
240
272
241
const toolbar = this . _register ( this . _instantiationService . createInstance ( MenuWorkbenchToolBar , el . actions , MenuId . ChatToolOutputResourceToolbar , {
@@ -309,7 +278,7 @@ export class ChatCollapsibleInputOutputContentPart extends Disposable {
309
278
}
310
279
311
280
interface IChatToolOutputResourceToolbarContext {
312
- parts : ( IChatCollapsibleIODataPart | IChatCollapsibleIOResourcePart ) [ ] ;
281
+ parts : IChatCollapsibleIODataPart [ ] ;
313
282
}
314
283
315
284
class SaveResourcesAction extends Action2 {
@@ -339,11 +308,8 @@ class SaveResourcesAction extends Action2 {
339
308
const labelService = accessor . get ( ILabelService ) ;
340
309
const defaultFilepath = await fileDialog . defaultFilePath ( ) ;
341
310
342
- const partBasename = ( part : IChatCollapsibleIODataPart | IChatCollapsibleIOResourcePart ) =>
343
- ( part . kind === 'resource' || part . uri ) ? basename ( part . uri ! ) : ( 'file' + ( getExtensionForMimeType ( part . mimeType ) || '' ) ) ;
344
-
345
- const savePart = async ( part : IChatCollapsibleIODataPart | IChatCollapsibleIOResourcePart , isFolder : boolean , uri : URI ) => {
346
- const target = isFolder ? joinPath ( uri , partBasename ( part ) ) : uri ;
311
+ const savePart = async ( part : IChatCollapsibleIODataPart , isFolder : boolean , uri : URI ) => {
312
+ const target = isFolder ? joinPath ( uri , basename ( part . uri ) ) : uri ;
347
313
try {
348
314
if ( part . kind === 'data' ) {
349
315
await fileService . writeFile ( target , VSBuffer . wrap ( part . value ) ) ;
@@ -353,7 +319,7 @@ class SaveResourcesAction extends Action2 {
353
319
await fileService . writeFile ( target , contents . value ) ;
354
320
}
355
321
} catch ( e ) {
356
- notificationService . error ( localize ( 'chat.saveResources.error' , "Failed to save {0}: {1}" , partBasename ( part ) , e ) ) ;
322
+ notificationService . error ( localize ( 'chat.saveResources.error' , "Failed to save {0}: {1}" , basename ( part . uri ) , e ) ) ;
357
323
}
358
324
} ;
359
325
@@ -378,7 +344,7 @@ class SaveResourcesAction extends Action2 {
378
344
379
345
if ( context . parts . length === 1 ) {
380
346
const part = context . parts [ 0 ] ;
381
- const uri = await fileDialog . pickFileToSave ( joinPath ( defaultFilepath , partBasename ( part ) ) ) ;
347
+ const uri = await fileDialog . pickFileToSave ( joinPath ( defaultFilepath , basename ( part . uri ) ) ) ;
382
348
if ( ! uri ) {
383
349
return ;
384
350
}
0 commit comments