@codingame/monaco-vscode-xterm-addons-common 36.2.7 → 37.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. package/package.json +10 -10
  2. package/vscode/src/vs/base/browser/htmlToMarkdown.js +24 -6
  3. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContext.d.ts +27 -0
  4. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContext.js +158 -24
  5. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/attachInstructionsAction.js +8 -16
  6. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/newPromptFileActions.js +15 -15
  7. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptName.js +9 -9
  8. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptSourceFolder.js +30 -29
  9. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/promptFilePickers.js +42 -38
  10. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/editor/chatPasteProviders.d.ts +22 -6
  11. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/editor/chatPasteProviders.js +254 -132
  12. package/vscode/src/vs/workbench/contrib/git/common/utils.d.ts +8 -0
  13. package/vscode/src/vs/workbench/contrib/git/common/utils.js +105 -0
  14. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.d.ts +1 -2
  15. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.js +27 -22
  16. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/markNavigationAddon.js +1 -11
  17. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.d.ts +16 -1
  18. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.js +75 -17
  19. package/vscode/src/vs/workbench/contrib/chat/browser/copilotCliEventsUri.d.ts +0 -82
  20. package/vscode/src/vs/workbench/contrib/chat/browser/copilotCliEventsUri.js +0 -114
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
- import { alert } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/aria/aria';
3
+ import { alert, status } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/aria/aria';
4
4
  import { Codicon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/codicons';
5
5
  import { VSDataTransfer, createStringDataTransferItem } from '@codingame/monaco-vscode-api/vscode/vs/base/common/dataTransfer';
6
6
  import { convertHtmlToMarkdown } from '../../../../../../../base/browser/htmlToMarkdown.js';
@@ -12,6 +12,7 @@ import { Schemas } from '@codingame/monaco-vscode-api/vscode/vs/base/common/netw
12
12
  import { joinPath, basename } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
13
13
  import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
14
14
  import { Position } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position';
15
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
15
16
  import { SymbolKinds, DocumentPasteTriggerKind } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages';
16
17
  import { ILanguageFeaturesService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/languageFeatures.service';
17
18
  import { IModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model.service';
@@ -21,27 +22,29 @@ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
21
22
  import { IEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/platform/environment/common/environment.service';
22
23
  import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
23
24
  import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
25
+ import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
24
26
  import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
25
27
  import { isProposedApiEnabled } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/extensions/common/extensions';
26
28
  import { IExtensionService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/extensions/common/extensions.service';
27
- import { isImageVariableEntry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/attachments/chatVariableEntries';
29
+ import { toPasteVariableEntry, ChatPasteAttachmentMetadata, isImageVariableEntry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/attachments/chatVariableEntries';
28
30
  import { chatVariableLeader } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/requestParser/chatParserTypes';
29
- import { IChatWidgetService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/chat.service';
30
- import { getDynamicVariablesForWidget } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/attachments/chatVariables';
31
- import { ChatDynamicVariableModel } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/attachments/chatDynamicVariables';
31
+ import { IChatPasteTargetService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/chat.service';
32
+ import { isChatInputModel, ChatConfiguration, chatInputSchemes } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/constants';
32
33
  import { cleanupOldImages, createFileForMedia, resizeImage, imageToHash } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/chatImageUtils';
33
34
 
34
- var CopyAttachmentsProvider_1;
35
35
  const COPY_MIME_TYPES = "application/vnd.code.additional-editor-data";
36
+ const pastedTextArtifactDefaultMinLength = 10000;
37
+ const CHAT_ATTACHMENT_MIME_TYPE = "application/vnd.chat.attachment+json";
38
+ const GITHUB_ISSUE_OR_PULL_REQUEST_URL_PATTERN = /\bhttps?:\/\/(?:www\.)?github\.com\/(?<owner>[\w.-]+)\/(?<repo>[\w.-]+)\/(?<kind>issues|pull)\/(?<number>\d+)(?![\w-])/gi;
36
39
  let PasteImageProvider = class PasteImageProvider {
37
40
  constructor(
38
- chatWidgetService,
41
+ pasteTargetService,
39
42
  extensionService,
40
43
  fileService,
41
44
  environmentService,
42
45
  logService
43
46
  ) {
44
- this.chatWidgetService = chatWidgetService;
47
+ this.pasteTargetService = pasteTargetService;
45
48
  this.extensionService = extensionService;
46
49
  this.fileService = fileService;
47
50
  this.environmentService = environmentService;
@@ -54,7 +57,7 @@ let PasteImageProvider = class PasteImageProvider {
54
57
  cleanupOldImages(this.fileService, this.logService, this.imagesFolder);
55
58
  }
56
59
  async provideDocumentPasteEdits(model, ranges, dataTransfer, context, token) {
57
- if (!( this.extensionService.extensions.some(ext => isProposedApiEnabled(ext)))) {
60
+ if (!( this.extensionService.extensions.some(ext => isProposedApiEnabled(ext, "chatReferenceBinaryData")))) {
58
61
  return;
59
62
  }
60
63
  const supportedMimeTypes = [
@@ -81,12 +84,12 @@ let PasteImageProvider = class PasteImageProvider {
81
84
  if (token.isCancellationRequested || !currClipboard) {
82
85
  return;
83
86
  }
84
- const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
85
- if (!widget) {
87
+ const target = this.pasteTargetService.getTarget(model.uri);
88
+ if (!target) {
86
89
  return;
87
90
  }
88
- const attachedVariables = widget.attachmentModel.attachments;
89
- const displayName = ( localize(8339, "Pasted Image"));
91
+ const attachedVariables = target.attachments;
92
+ const displayName = ( localize(10028, "Pasted Image"));
90
93
  let tempDisplayName = displayName;
91
94
  for (let appendValue = 2; ( attachedVariables.some(attachment => attachment.name === tempDisplayName)); appendValue++)
92
95
  {
@@ -104,11 +107,11 @@ let PasteImageProvider = class PasteImageProvider {
104
107
  if (token.isCancellationRequested || !scaledImageContext) {
105
108
  return;
106
109
  }
107
- const currentContextIds = widget.attachmentModel.getAttachmentIDs();
110
+ const currentContextIds = ( new Set(( target.attachments.map(attachment => attachment.id))));
108
111
  if (( currentContextIds.has(scaledImageContext.id))) {
109
112
  return;
110
113
  }
111
- const edit = createCustomPasteEdit(model, [scaledImageContext], mimeType, this.kind, ( localize(8340, "Pasted Image Attachment")), this.chatWidgetService);
114
+ const edit = createCustomPasteEdit(model, [scaledImageContext], mimeType, this.kind, ( localize(10029, "Pasted Image Attachment")), this.pasteTargetService);
112
115
  return createEditSession(edit);
113
116
  }
114
117
  };
@@ -155,7 +158,7 @@ let CopyTextProvider = class CopyTextProvider {
155
158
  this.pasteMimeTypes = [];
156
159
  }
157
160
  async prepareDocumentPaste(model, ranges, dataTransfer, token) {
158
- if (model.uri.scheme === Schemas.vscodeChatInput) {
161
+ if (isChatInputModel(model.uri)) {
159
162
  return;
160
163
  }
161
164
  const customDataTransfer = ( new VSDataTransfer());
@@ -191,50 +194,41 @@ let CopyTextProvider = class CopyTextProvider {
191
194
  };
192
195
  CopyTextProvider = ( __decorate([( __param(0, IModelService)), ( __param(1, ILanguageFeaturesService)), ( __param(2, IOutlineModelService))], CopyTextProvider));
193
196
  let CopyAttachmentsProvider = class CopyAttachmentsProvider {
194
- static {
195
- CopyAttachmentsProvider_1 = this;
196
- }
197
- static {
198
- this.ATTACHMENT_MIME_TYPE = "application/vnd.chat.attachment+json";
199
- }
200
- constructor(chatWidgetService) {
201
- this.chatWidgetService = chatWidgetService;
197
+ constructor(pasteTargetService) {
198
+ this.pasteTargetService = pasteTargetService;
202
199
  this.kind = ( new HierarchicalKind("chat.attach.attachments"));
203
200
  this.providedPasteEditKinds = [this.kind];
204
- this.copyMimeTypes = [CopyAttachmentsProvider_1.ATTACHMENT_MIME_TYPE];
205
- this.pasteMimeTypes = [CopyAttachmentsProvider_1.ATTACHMENT_MIME_TYPE];
201
+ this.copyMimeTypes = [CHAT_ATTACHMENT_MIME_TYPE];
202
+ this.pasteMimeTypes = [CHAT_ATTACHMENT_MIME_TYPE];
206
203
  }
207
204
  async prepareDocumentPaste(model, _ranges, _dataTransfer, _token) {
208
- const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
209
- if (!widget || !widget.viewModel) {
205
+ const target = this.pasteTargetService.getTarget(model.uri);
206
+ if (!target) {
210
207
  return undefined;
211
208
  }
212
- const attachments = widget.attachmentModel.attachments;
213
- const dynamicVariables = getDynamicVariablesForWidget(widget);
209
+ const dynamicVariables = target.inlineReferences;
210
+ const referencedIds = ( new Set(( dynamicVariables.map(variable => variable.id))));
211
+ const attachments = ( target.attachments.map(attachment => attachment.range && !( referencedIds.has(attachment.id)) ? {
212
+ ...attachment,
213
+ range: undefined
214
+ } : attachment));
214
215
  if (attachments.length === 0 && dynamicVariables.length === 0) {
215
216
  return undefined;
216
217
  }
217
218
  const result = ( new VSDataTransfer());
218
- result.append(
219
- CopyAttachmentsProvider_1.ATTACHMENT_MIME_TYPE,
220
- createStringDataTransferItem(JSON.stringify({
221
- attachments,
222
- dynamicVariables
223
- }))
224
- );
219
+ result.append(CHAT_ATTACHMENT_MIME_TYPE, createStringDataTransferItem(JSON.stringify({
220
+ attachments,
221
+ dynamicVariables
222
+ })));
225
223
  return result;
226
224
  }
227
225
  async provideDocumentPasteEdits(model, _ranges, dataTransfer, _context, token) {
228
- const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
229
- if (!widget || !widget.viewModel) {
230
- return undefined;
231
- }
232
- const chatDynamicVariable = widget.getContrib(ChatDynamicVariableModel.ID);
233
- if (!chatDynamicVariable) {
226
+ const target = this.pasteTargetService.getTarget(model.uri);
227
+ if (!target) {
234
228
  return undefined;
235
229
  }
236
230
  const text = dataTransfer.get(Mimes.text);
237
- const data = dataTransfer.get(CopyAttachmentsProvider_1.ATTACHMENT_MIME_TYPE);
231
+ const data = dataTransfer.get(CHAT_ATTACHMENT_MIME_TYPE);
238
232
  const rawData = await data?.asString();
239
233
  const textdata = await text?.asString();
240
234
  if (textdata === undefined || rawData === undefined) {
@@ -252,9 +246,9 @@ let CopyAttachmentsProvider = class CopyAttachmentsProvider {
252
246
  }
253
247
  const edit = {
254
248
  insertText: textdata,
255
- title: ( localize(8341, "Insert Prompt & Attachments")),
249
+ title: ( localize(10030, "Insert Prompt & Attachments")),
256
250
  kind: this.kind,
257
- handledMimeType: CopyAttachmentsProvider_1.ATTACHMENT_MIME_TYPE,
251
+ handledMimeType: CHAT_ATTACHMENT_MIME_TYPE,
258
252
  additionalEdit: {
259
253
  edits: []
260
254
  }
@@ -262,85 +256,205 @@ let CopyAttachmentsProvider = class CopyAttachmentsProvider {
262
256
  edit.additionalEdit?.edits.push({
263
257
  resource: model.uri,
264
258
  redo: () => {
265
- widget.attachmentModel.addContext(...pastedData.attachments);
259
+ target.addAttachments(pastedData.attachments);
266
260
  for (const dynamicVariable of pastedData.dynamicVariables) {
267
- chatDynamicVariable?.addReference(dynamicVariable);
261
+ target.addInlineReference(dynamicVariable);
268
262
  }
269
- widget.refreshParsedInput();
270
263
  },
271
264
  undo: () => {
272
- widget.attachmentModel.delete(...( pastedData.attachments.map(c => c.id)));
273
- widget.refreshParsedInput();
265
+ target.removeAttachments(( pastedData.attachments.map(c => c.id)));
274
266
  }
275
267
  });
276
268
  return createEditSession(edit);
277
269
  }
278
270
  };
279
- CopyAttachmentsProvider = CopyAttachmentsProvider_1 = ( __decorate([( __param(0, IChatWidgetService))], CopyAttachmentsProvider));
271
+ CopyAttachmentsProvider = ( __decorate([( __param(0, IChatPasteTargetService))], CopyAttachmentsProvider));
272
+ function getGitHubIssueOrPullRequestAttachments(input, metadata) {
273
+ const attachments = [];
274
+ const ids = ( new Set());
275
+ for (const match of input.matchAll(GITHUB_ISSUE_OR_PULL_REQUEST_URL_PATTERN)) {
276
+ const groups = match.groups;
277
+ const number = Number(groups?.["number"]);
278
+ if (!groups || !Number.isSafeInteger(number) || number <= 0) {
279
+ continue;
280
+ }
281
+ const owner = groups["owner"];
282
+ const repo = groups["repo"];
283
+ const kind = groups["kind"].toLowerCase();
284
+ const uri = `https://github.com/${owner}/${repo}/${kind}/${number}`;
285
+ const id = `github-context:${uri}`;
286
+ if (( ids.has(id))) {
287
+ continue;
288
+ }
289
+ ids.add(id);
290
+ attachments.push({
291
+ kind: "generic",
292
+ id,
293
+ icon: kind === "issues" ? Codicon.issues : Codicon.gitPullRequest,
294
+ name: `${owner}/${repo}#${number}`,
295
+ value: `GitHub context: ${uri}`,
296
+ _meta: metadata
297
+ });
298
+ }
299
+ return attachments;
300
+ }
280
301
  class PasteTextProvider {
281
- constructor(chatWidgetService, modelService) {
282
- this.chatWidgetService = chatWidgetService;
302
+ constructor(pasteTargetService, modelService, logService, configurationService) {
303
+ this.pasteTargetService = pasteTargetService;
283
304
  this.modelService = modelService;
305
+ this.logService = logService;
306
+ this.configurationService = configurationService;
284
307
  this.kind = ( new HierarchicalKind("chat.attach.text"));
285
308
  this.providedPasteEditKinds = [this.kind];
286
309
  this.copyMimeTypes = [];
287
- this.pasteMimeTypes = [COPY_MIME_TYPES];
310
+ this.pasteMimeTypes = [COPY_MIME_TYPES, Mimes.text];
288
311
  }
289
312
  async provideDocumentPasteEdits(model, ranges, dataTransfer, _context, token) {
290
- if (model.uri.scheme !== Schemas.vscodeChatInput) {
313
+ if (!isChatInputModel(model.uri)) {
291
314
  return;
292
315
  }
293
316
  const text = dataTransfer.get(Mimes.text);
294
317
  const editorData = dataTransfer.get("vscode-editor-data");
295
318
  const additionalEditorData = dataTransfer.get(COPY_MIME_TYPES);
296
- if (!editorData || !text || !additionalEditorData) {
319
+ if (!text) {
297
320
  return;
298
321
  }
299
322
  const textdata = await text.asString();
300
- const metadata = JSON.parse(await editorData.asString());
301
- const additionalData = JSON.parse(await additionalEditorData.asString());
302
- const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
303
- if (!widget) {
323
+ const target = this.pasteTargetService.getTarget(model.uri);
324
+ if (!target) {
304
325
  return;
305
326
  }
306
- const start = additionalData.range.startLineNumber;
307
- const end = additionalData.range.endLineNumber;
308
- if (start === end) {
309
- const textModel = this.modelService.getModel(URI.revive(additionalData.uri));
310
- if (!textModel) {
311
- return;
327
+ if (model.uri.scheme !== Schemas.sessionsChatInput) {
328
+ const currentContextIds = ( new Set(( target.attachments.map(attachment => attachment.id))));
329
+ const githubAttachments = getGitHubIssueOrPullRequestAttachments(textdata).filter(attachment => !( currentContextIds.has(attachment.id)));
330
+ if (githubAttachments.length) {
331
+ if (ranges.length !== 1) {
332
+ return;
333
+ }
334
+ const announcement = githubAttachments.length === 1 ? ( localize(10031, "Attached {0} as context", githubAttachments[0].name)) : ( localize(10032, "Attached {0} GitHub links as context", githubAttachments.length));
335
+ const edit = createCustomPasteEdit(model, githubAttachments, Mimes.text, this.kind, ( localize(10033, "Paste GitHub Context")), this.pasteTargetService, {
336
+ insertText: textdata,
337
+ statusAnnouncement: announcement
338
+ });
339
+ return createEditSession(edit);
312
340
  }
313
- const lineContent = textModel.getLineContent(start);
314
- if (lineContent !== textdata) {
315
- return;
341
+ }
342
+ let copiedContext;
343
+ if (editorData && additionalEditorData) {
344
+ try {
345
+ const metadata = JSON.parse(await editorData.asString());
346
+ const additionalData = JSON.parse(await additionalEditorData.asString());
347
+ const start = additionalData.range.startLineNumber;
348
+ const end = additionalData.range.endLineNumber;
349
+ let isWholeLine = true;
350
+ if (start === end) {
351
+ const textModel = this.modelService.getModel(URI.revive(additionalData.uri));
352
+ isWholeLine = !!textModel && start >= 1 && start <= textModel.getLineCount() && textModel.getLineContent(start) === textdata;
353
+ }
354
+ if (isWholeLine) {
355
+ copiedContext = getCopiedContext(
356
+ textdata,
357
+ URI.revive(additionalData.uri),
358
+ metadata.mode,
359
+ additionalData.range
360
+ );
361
+ }
362
+ } catch (error) {
363
+ this.logService.warn("Failed to read copied text metadata", error);
316
364
  }
317
365
  }
318
- const copiedContext = getCopiedContext(
319
- textdata,
320
- URI.revive(additionalData.uri),
321
- metadata.mode,
322
- additionalData.range
323
- );
324
- if (token.isCancellationRequested || !copiedContext) {
366
+ if (token.isCancellationRequested) {
367
+ return;
368
+ }
369
+ const hasRicherPaste = !!copiedContext || ( dataTransfer.has(CHAT_ATTACHMENT_MIME_TYPE)) || dataTransfer.matches("image/*");
370
+ const markdown = hasRicherPaste ? undefined : await getMeaningfulMarkdown(dataTransfer);
371
+ if (token.isCancellationRequested) {
372
+ return;
373
+ }
374
+ const artifact = hasRicherPaste ? undefined : createPastedTextArtifact(textdata, target.attachments, {
375
+ content: markdown,
376
+ minLength: this.configurationService.getValue(ChatConfiguration.PasteAsAttachmentThreshold, {
377
+ resource: model.uri
378
+ })
379
+ });
380
+ if (artifact) {
381
+ if (ranges.length !== 1 || target.isTerminalCommandPaste(textdata, ranges[0])) {
382
+ return;
383
+ }
384
+ const pasteRange = ranges[0];
385
+ const referenceRange = ( new Range(
386
+ pasteRange.startLineNumber,
387
+ pasteRange.startColumn,
388
+ pasteRange.startLineNumber,
389
+ pasteRange.startColumn + artifact.referenceText.length
390
+ ));
391
+ const referenceOffset = model.getOffsetAt(referenceRange.getStartPosition());
392
+ const edit = createCustomPasteEdit(model, [{
393
+ ...artifact.attachment,
394
+ range: {
395
+ start: referenceOffset,
396
+ endExclusive: referenceOffset + artifact.referenceText.length
397
+ }
398
+ }], Mimes.text, this.kind, ( localize(10034, "Pasted Text Attachment")), this.pasteTargetService, {
399
+ inlineReference: {
400
+ text: artifact.referenceText,
401
+ range: referenceRange
402
+ },
403
+ announcement: ( localize(10035, "Attached pasted text as {0}", artifact.attachment.name))
404
+ });
405
+ return createEditSession(edit);
406
+ }
407
+ if (!copiedContext) {
325
408
  return;
326
409
  }
327
- const currentContextIds = widget.attachmentModel.getAttachmentIDs();
410
+ const currentContextIds = ( new Set(( target.attachments.map(attachment => attachment.id))));
328
411
  if (( currentContextIds.has(copiedContext.id))) {
329
412
  return;
330
413
  }
331
- const edit = createCustomPasteEdit(model, [copiedContext], Mimes.text, this.kind, ( localize(8342, "Pasted Code Attachment")), this.chatWidgetService);
414
+ const edit = createCustomPasteEdit(model, [copiedContext], Mimes.text, this.kind, ( localize(10036, "Pasted Code Attachment")), this.pasteTargetService);
332
415
  edit.yieldTo = [{
333
416
  kind: HierarchicalKind.Empty.append("text", "plain")
334
417
  }];
335
418
  return createEditSession(edit);
336
419
  }
337
420
  }
421
+ function createPastedTextArtifact(text, existingAttachments, options) {
422
+ const trimmed = text.trim();
423
+ const minLength = options?.minLength ?? pastedTextArtifactDefaultMinLength;
424
+ if (!trimmed || trimmed.length < minLength) {
425
+ return undefined;
426
+ }
427
+ let index = 1;
428
+ let name;
429
+ do {
430
+ name = ( localize(10037, "Pasted text #{0}", index++));
431
+ } while (( existingAttachments.some(attachment => attachment.name === name)));
432
+ const content = options?.content;
433
+ const value = content ?? text;
434
+ const lineCount = countLines(value);
435
+ const pastedLines = lineCount === 1 ? ( localize(10038, "1 line")) : ( localize(10039, "{0} lines", lineCount));
436
+ const attachment = toPasteVariableEntry(name, value, {
437
+ language: content ? "markdown" : "plaintext",
438
+ fileName: name,
439
+ pastedLines,
440
+ _meta: {
441
+ [ChatPasteAttachmentMetadata.TextArtifact]: true
442
+ }
443
+ });
444
+ return {
445
+ attachment,
446
+ referenceText: `${chatVariableLeader}attachment:${name}`
447
+ };
448
+ }
449
+ function countLines(value) {
450
+ return value.split(/\r\n|\r|\n/).length;
451
+ }
338
452
  function getCopiedContext(code, file, language, range) {
339
453
  const fileName = basename(file);
340
454
  const start = range.startLineNumber;
341
455
  const end = range.endLineNumber;
342
456
  const resultText = `Copied Selection of Code: \n\n\n From the file: ${fileName} From lines ${start} to ${end} \n \`\`\`${code}\`\`\``;
343
- const pastedLines = start === end ? ( localize(8343, "1 line")) : ( localize(8344, "{0} lines", end + 1 - start));
457
+ const pastedLines = start === end ? ( localize(10040, "1 line")) : ( localize(10041, "{0} lines", end + 1 - start));
344
458
  return {
345
459
  kind: "paste",
346
460
  value: resultText,
@@ -361,27 +475,36 @@ function getCopiedContext(code, file, language, range) {
361
475
  }]
362
476
  };
363
477
  }
364
- function createCustomPasteEdit(model, context, handledMimeType, kind, title, chatWidgetService) {
365
- const label = context.length === 1 ? context[0].name : ( localize(8345, "{0} and {1} more", context[0].name, context.length - 1));
478
+ function createCustomPasteEdit(model, context, handledMimeType, kind, title, pasteTargetService, options) {
479
+ const label = context.length === 1 ? context[0].name : ( localize(10042, "{0} and {1} more", context[0].name, context.length - 1));
366
480
  const announceImageAttachment = context.length === 1 && isImageVariableEntry(context[0]);
481
+ const inlineReference = context.length === 1 ? options?.inlineReference : undefined;
482
+ const resolveTarget = operation => {
483
+ const target = pasteTargetService.getTarget(model.uri);
484
+ if (!target) {
485
+ throw ( new Error(`No chat paste target found for ${operation}`));
486
+ }
487
+ return target;
488
+ };
367
489
  const customEdit = {
368
490
  resource: model.uri,
369
491
  variable: context,
370
492
  undo: () => {
371
- const widget = chatWidgetService.getWidgetByInputUri(model.uri);
372
- if (!widget) {
373
- throw ( new Error("No widget found for undo"));
374
- }
375
- widget.attachmentModel.delete(...( context.map(c => c.id)));
493
+ resolveTarget("undo").removeAttachments(( context.map(c => c.id)));
376
494
  },
377
495
  redo: () => {
378
- const widget = chatWidgetService.getWidgetByInputUri(model.uri);
379
- if (!widget) {
380
- throw ( new Error("No widget found for redo"));
496
+ const target = resolveTarget("redo");
497
+ if (inlineReference) {
498
+ target.addInlineAttachment(context[0], inlineReference.text, inlineReference.range);
499
+ } else {
500
+ target.addAttachments(context);
381
501
  }
382
- widget.attachmentModel.addContext(...context);
383
- if (announceImageAttachment) {
384
- alert(( localize(8346, "Attached image")));
502
+ if (options?.announcement) {
503
+ alert(options.announcement);
504
+ } else if (options?.statusAnnouncement) {
505
+ status(options.statusAnnouncement);
506
+ } else if (announceImageAttachment) {
507
+ alert(( localize(10043, "Attached image")));
385
508
  }
386
509
  },
387
510
  metadata: {
@@ -390,7 +513,7 @@ function createCustomPasteEdit(model, context, handledMimeType, kind, title, cha
390
513
  }
391
514
  };
392
515
  return {
393
- insertText: "",
516
+ insertText: options?.inlineReference ? `${options.inlineReference.text} ` : options?.insertText ?? "",
394
517
  title,
395
518
  kind,
396
519
  handledMimeType,
@@ -489,12 +612,12 @@ async function resolveSymbolReference(
489
612
  }
490
613
  let PasteSymbolProvider = class PasteSymbolProvider {
491
614
  constructor(
492
- chatWidgetService,
615
+ pasteTargetService,
493
616
  modelService,
494
617
  languageFeaturesService,
495
618
  outlineModelService
496
619
  ) {
497
- this.chatWidgetService = chatWidgetService;
620
+ this.pasteTargetService = pasteTargetService;
498
621
  this.modelService = modelService;
499
622
  this.languageFeaturesService = languageFeaturesService;
500
623
  this.outlineModelService = outlineModelService;
@@ -504,7 +627,7 @@ let PasteSymbolProvider = class PasteSymbolProvider {
504
627
  this.pasteMimeTypes = [COPY_MIME_TYPES];
505
628
  }
506
629
  async provideDocumentPasteEdits(model, ranges, dataTransfer, _context, token) {
507
- if (model.uri.scheme !== Schemas.vscodeChatInput) {
630
+ if (!isChatInputModel(model.uri)) {
508
631
  return;
509
632
  }
510
633
  const text = dataTransfer.get(Mimes.text);
@@ -524,8 +647,7 @@ let PasteSymbolProvider = class PasteSymbolProvider {
524
647
  }
525
648
  const sourceUri = URI.revive(additionalData.uri);
526
649
  const sourceRange = additionalData.range;
527
- const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
528
- if (!widget) {
650
+ if (!this.pasteTargetService.getTarget(model.uri)) {
529
651
  return;
530
652
  }
531
653
  const cached = await getCachedSymbolReference(sourceUri, sourceRange, pastedText);
@@ -565,15 +687,14 @@ let PasteSymbolProvider = class PasteSymbolProvider {
565
687
  };
566
688
  const edit = {
567
689
  insertText,
568
- title: ( localize(8347, "Pasted Symbol Reference")),
690
+ title: ( localize(10044, "Pasted Symbol Reference")),
569
691
  kind: this.kind,
570
692
  handledMimeType: COPY_MIME_TYPES,
571
693
  additionalEdit: {
572
694
  edits: [{
573
695
  resource: model.uri,
574
696
  redo: () => {
575
- const w = this.chatWidgetService.getWidgetByInputUri(model.uri);
576
- w?.getContrib(ChatDynamicVariableModel.ID)?.addReference(dynamicRef);
697
+ this.pasteTargetService.getTarget(model.uri)?.addInlineReference(dynamicRef);
577
698
  },
578
699
  undo: () => {}
579
700
  }]
@@ -585,7 +706,7 @@ let PasteSymbolProvider = class PasteSymbolProvider {
585
706
  return createEditSession(edit);
586
707
  }
587
708
  };
588
- PasteSymbolProvider = ( __decorate([( __param(0, IChatWidgetService)), ( __param(1, IModelService)), ( __param(2, ILanguageFeaturesService)), ( __param(3, IOutlineModelService))], PasteSymbolProvider));
709
+ PasteSymbolProvider = ( __decorate([( __param(0, IChatPasteTargetService)), ( __param(1, IModelService)), ( __param(2, ILanguageFeaturesService)), ( __param(3, IOutlineModelService))], PasteSymbolProvider));
589
710
  class PasteHtmlProvider {
590
711
  constructor() {
591
712
  this.kind = ( new HierarchicalKind("chat.paste.html"));
@@ -594,7 +715,7 @@ class PasteHtmlProvider {
594
715
  this.pasteMimeTypes = [Mimes.html];
595
716
  }
596
717
  async provideDocumentPasteEdits(model, _ranges, dataTransfer, context, token) {
597
- if (model.uri.scheme !== Schemas.vscodeChatInput) {
718
+ if (!isChatInputModel(model.uri)) {
598
719
  return;
599
720
  }
600
721
  if (context.triggerKind !== DocumentPasteTriggerKind.Automatic) {
@@ -605,7 +726,7 @@ class PasteHtmlProvider {
605
726
  if (!htmlText || token.isCancellationRequested) {
606
727
  return;
607
728
  }
608
- if (!/<(a|strong|b|em|i|h[1-6]|code|pre|ul|ol|li|blockquote|del|s|strike|img|hr)\b/i.test(htmlText)) {
729
+ if (!isMeaningfulHtml(htmlText)) {
609
730
  return;
610
731
  }
611
732
  const markdown = convertHtmlToMarkdown(htmlText);
@@ -614,7 +735,7 @@ class PasteHtmlProvider {
614
735
  }
615
736
  return createEditSession({
616
737
  insertText: markdown,
617
- title: ( localize(8348, "Paste as Markdown")),
738
+ title: ( localize(10045, "Paste as Markdown")),
618
739
  kind: this.kind,
619
740
  handledMimeType: Mimes.html,
620
741
  yieldTo: [{
@@ -625,44 +746,45 @@ class PasteHtmlProvider {
625
746
  });
626
747
  }
627
748
  }
749
+ async function getMeaningfulMarkdown(dataTransfer) {
750
+ const htmlText = await dataTransfer.get(Mimes.html)?.asString();
751
+ if (!htmlText || !isMeaningfulHtml(htmlText)) {
752
+ return undefined;
753
+ }
754
+ return convertHtmlToMarkdown(htmlText) || undefined;
755
+ }
756
+ function isMeaningfulHtml(value) {
757
+ return /<(a|strong|b|em|i|h[1-6]|code|pre|ul|ol|li|blockquote|del|s|strike|img|hr)\b/i.test(value);
758
+ }
628
759
  let ChatPasteProvidersFeature = class ChatPasteProvidersFeature extends Disposable {
629
760
  constructor(
630
761
  instaService,
631
762
  languageFeaturesService,
632
- chatWidgetService,
763
+ pasteTargetService,
633
764
  extensionService,
634
765
  fileService,
635
766
  modelService,
636
767
  environmentService,
637
- logService
768
+ logService,
769
+ configurationService
638
770
  ) {
639
771
  super();
640
- this._register(languageFeaturesService.documentPasteEditProvider.register({
641
- scheme: Schemas.vscodeChatInput,
642
- pattern: "*",
643
- hasAccessToAllModels: true
644
- }, instaService.createInstance(CopyAttachmentsProvider)));
645
- this._register(languageFeaturesService.documentPasteEditProvider.register({
646
- scheme: Schemas.vscodeChatInput,
647
- pattern: "*",
648
- hasAccessToAllModels: true
649
- }, ( new PasteImageProvider(
650
- chatWidgetService,
772
+ const chatInputProviders = [instaService.createInstance(CopyAttachmentsProvider), ( new PasteImageProvider(
773
+ pasteTargetService,
651
774
  extensionService,
652
775
  fileService,
653
776
  environmentService,
654
777
  logService
655
- ))));
656
- this._register(languageFeaturesService.documentPasteEditProvider.register({
657
- scheme: Schemas.vscodeChatInput,
658
- pattern: "*",
659
- hasAccessToAllModels: true
660
- }, ( new PasteTextProvider(chatWidgetService, modelService))));
661
- this._register(languageFeaturesService.documentPasteEditProvider.register({
662
- scheme: Schemas.vscodeChatInput,
663
- pattern: "*",
664
- hasAccessToAllModels: true
665
- }, ( new PasteHtmlProvider())));
778
+ )), ( new PasteTextProvider(pasteTargetService, modelService, logService, configurationService)), ( new PasteHtmlProvider())];
779
+ for (const scheme of chatInputSchemes) {
780
+ for (const provider of chatInputProviders) {
781
+ this._register(languageFeaturesService.documentPasteEditProvider.register({
782
+ scheme,
783
+ pattern: "*",
784
+ hasAccessToAllModels: true
785
+ }, provider));
786
+ }
787
+ }
666
788
  this._register(languageFeaturesService.documentPasteEditProvider.register({
667
789
  scheme: Schemas.vscodeChatInput,
668
790
  pattern: "*",
@@ -673,6 +795,6 @@ let ChatPasteProvidersFeature = class ChatPasteProvidersFeature extends Disposab
673
795
  );
674
796
  }
675
797
  };
676
- ChatPasteProvidersFeature = ( __decorate([( __param(0, IInstantiationService)), ( __param(1, ILanguageFeaturesService)), ( __param(2, IChatWidgetService)), ( __param(3, IExtensionService)), ( __param(4, IFileService)), ( __param(5, IModelService)), ( __param(6, IEnvironmentService)), ( __param(7, ILogService))], ChatPasteProvidersFeature));
798
+ ChatPasteProvidersFeature = ( __decorate([( __param(0, IInstantiationService)), ( __param(1, ILanguageFeaturesService)), ( __param(2, IChatPasteTargetService)), ( __param(3, IExtensionService)), ( __param(4, IFileService)), ( __param(5, IModelService)), ( __param(6, IEnvironmentService)), ( __param(7, ILogService)), ( __param(8, IConfigurationService))], ChatPasteProvidersFeature));
677
799
 
678
- export { ChatPasteProvidersFeature, CopyTextProvider, PasteImageProvider, PasteTextProvider, isImage };
800
+ export { CHAT_ATTACHMENT_MIME_TYPE, ChatPasteProvidersFeature, CopyTextProvider, PasteImageProvider, PasteTextProvider, createPastedTextArtifact, getGitHubIssueOrPullRequestAttachments, isImage, pastedTextArtifactDefaultMinLength };
@@ -0,0 +1,8 @@
1
+ import { GitRepositoryState } from "@codingame/monaco-vscode-extensions-service-override/vscode/vs/workbench/contrib/git/common/gitService";
2
+ export interface IGitHubRemoteInfo {
3
+ readonly owner: string;
4
+ readonly repo: string;
5
+ }
6
+ export declare function hasGitHubRemotes(repositoryState: GitRepositoryState): boolean;
7
+ export declare function getGitHubRemoteInfo(repositoryState: GitRepositoryState, supportedHosts?: readonly string[]): IGitHubRemoteInfo | undefined;
8
+ export declare function getGitHubRepositoryFromRemoteUrl(remoteUrl: string, supportedHosts?: readonly string[]): IGitHubRemoteInfo | undefined;