chatVariableEntries.ts ×54

Frontier kind: Code frontier

unlabeled · c_fcaf1c32be28

583 tests · 10704 LOC · 43 files · introduces 0 tests · 506 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
54 ranges506 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1074 ranges10704 lines · 43 files · Browse complete extent
All tests (intent)
583 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 506 introduced LOC across 54 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/attachments/chatVariableEntries.ts 506 introduced LOC · 54 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- chatVariableEntries.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { Codicon } from '../../../../../base/common/codicons.js';
7 > import { IMarkdownString } from '../../../../../base/common/htmlContent.js';
8 > import { basename } from '../../../../../base/common/resources.js';
9 > import { ThemeIcon } from '../../../../../base/common/themables.js';
10 > import { URI } from '../../../../../base/common/uri.js';
11 > import { generateUuid } from '../../../../../base/common/uuid.js';
12 > import { IRange } from '../../../../../editor/common/core/range.js';
13 > import { IOffsetRange } from '../../../../../editor/common/core/ranges/offsetRange.js';
14 > import { isLocation, Location, SymbolKind } from '../../../../../editor/common/languages.js';
15 > import { localize } from '../../../../../nls.js';
16 > import { MarkerSeverity, IMarker } from '../../../../../platform/markers/common/markers.js';
17 > import { ISCMHistoryItem } from '../../../scm/common/history.js';
18 > import { IChatContentReference } from '../chatService/chatService.js';
19 > import { IChatRequestVariableValue } from './chatVariables.js';
20 > import { IToolData, IToolSet } from '../tools/languageModelToolsService.js';
21 > import type { ILanguageModelChatMetadata } from '../languageModels.js';
22 > import { decodeBase64, encodeBase64, VSBuffer } from '../../../../../base/common/buffer.js';
23 > import { Mutable } from '../../../../../base/common/types.js';
24 >
25 >
26 > /**
27 > * An icon for a chat context item. Mirrors the `IconPath` type from the extension API:
28 > * either a {@link ThemeIcon theme icon}, a single {@link URI} or separate light/dark {@link URI uris}.
29 > */
30 > export type ChatContextIconPath = ThemeIcon | URI | { light: URI; dark: URI };
31 >
32 > /**
33 > * Type guard for {@link ChatContextIconPath}. Accepts a {@link ThemeIcon theme icon}, a single
34 > * {@link URI} or an object with both `light` and `dark` {@link URI uris}. Rejects `null`, `undefined`
35 > * and partially-specified light/dark objects.
36 > */
37 > export function isChatContextIconPath(value: unknown): value is ChatContextIconPath {
38 if (!value || typeof value !== 'object') {
39 return false;
45 return URI.isUri(asDualPath.light) && URI.isUri(asDualPath.dark);
46 }
48 > /**
49 > * Resolve a {@link ChatContextIconPath} into a value that can be passed to the `iconPath`
50 > * option of an icon label, picking the light or dark uri based on the current theme.
51 > *
52 > * @param iconPath The icon path to resolve.
53 > * @param useDark Whether the current theme is a dark theme.
54 > */
55 > export function resolveChatContextIcon(iconPath: ChatContextIconPath, useDark: boolean): ThemeIcon | URI {
56 if (ThemeIcon.isThemeIcon(iconPath) || URI.isUri(iconPath)) {
57 return iconPath;
59 return useDark ? iconPath.dark : iconPath.light;
60 }
62 > interface IBaseChatRequestVariableEntry {
63 > readonly id: string;
64 > readonly fullName?: string;
65 > readonly icon?: ThemeIcon;
66 > readonly name: string;
67 > readonly modelDescription?: string;
68 >
69 > /**
70 > * The offset-range in the prompt. This means this entry has been explicitly typed out
71 > * by the user.
72 > */
73 > readonly range?: IOffsetRange;
74 > readonly value: IChatRequestVariableValue;
75 > readonly references?: IChatContentReference[];
76 >
77 > /**
78 > * Implementation-defined metadata that providers attach to a variable
79 > * entry. Used to round-trip provider-specific data (e.g. agent-host
80 > * `_meta`) when an entry is sent back to the provider as part of a
81 > * request attachment.
82 > */
83 > readonly _meta?: Record<string, unknown>;
84 >
85 > omittedState?: OmittedState;
86 > }
87 >
88 > export interface IGenericChatRequestVariableEntry extends IBaseChatRequestVariableEntry {
89 > kind: 'generic';
90 > tooltip?: IMarkdownString;
91 > /**
92 > * A provider-supplied icon that may be a {@link ThemeIcon theme icon}, a single uri or light/dark uris.
93 > * Takes precedence over the {@link IBaseChatRequestVariableEntry.icon base theme icon} when rendering.
94 > */
95 > iconPath?: ChatContextIconPath;
96 > }
97 >
98 > export const ChatPasteAttachmentMetadata = {
99 > Kind: 'vscode.chat.attachment.kind',
100 > Language: 'vscode.chat.attachment.language',
101 > FileName: 'vscode.chat.attachment.fileName',
102 > PastedLines: 'vscode.chat.attachment.pastedLines',
103 > } as const;
104 >
105 > export interface IRestorablePasteAttachment {
106 > readonly label: string;
107 > readonly displayKind?: string;
108 > readonly modelRepresentation?: string;
109 > readonly _meta?: Record<string, unknown>;
110 > }
111 >
112 > export const enum AgentHostCompletionReferenceKind {
113 > Skill = 'skill',
114 > Command = 'command',
115 > }
116 >
117 > export interface IAgentHostCompletionVariableValue {
118 > readonly $mid: 'agentHostCompletion';
119 > readonly kind: AgentHostCompletionReferenceKind;
120 > }
121 >
122 function agentHostCompletionVariableValue(kind: AgentHostCompletionReferenceKind): IAgentHostCompletionVariableValue {
123 return { $mid: 'agentHostCompletion', kind };
124 }
126 function agentHostCompletionVariableId(kind: AgentHostCompletionReferenceKind, reference: URI | string): string {
127 switch (kind) {
132 }
133 }
135 > export function toAgentHostCompletionVariableEntry(kind: AgentHostCompletionReferenceKind, name: string, reference: URI | string | undefined, _meta: Record<string, unknown> | undefined): IGenericChatRequestVariableEntry & { value: IAgentHostCompletionVariableValue } {
136 return {
137 kind: 'generic',
142 };
143 }
145 > export function toAgentHostCompletionVariableEntryFromMetadata(kind: AgentHostCompletionReferenceKind, name: string, _meta: Record<string, unknown> | undefined): IGenericChatRequestVariableEntry & { value: IAgentHostCompletionVariableValue } {
146 switch (kind) {
147 case AgentHostCompletionReferenceKind.Skill:
151 }
152 }
154 > export function getAgentHostCompletionReferenceKind(entry: IChatRequestVariableEntry): AgentHostCompletionReferenceKind | undefined {
155 if (entry.kind !== 'generic') {
156 return undefined;
158 return getAgentHostCompletionReferenceKindFromValue(entry.value);
159 }
161 > export function getAgentHostCompletionReferenceKindFromValue(value: IChatRequestVariableValue): AgentHostCompletionReferenceKind | undefined {
162 if (typeof value !== 'object' || value === null) {
163 return undefined;
176 return undefined;
177 }
179 > export function isAgentHostCompletionVariableEntry(entry: IChatRequestVariableEntry): entry is IGenericChatRequestVariableEntry & { value: IAgentHostCompletionVariableValue } {
180 return getAgentHostCompletionReferenceKind(entry) !== undefined;
181 }
183 >
184 > export interface IChatRequestDirectoryEntry extends IBaseChatRequestVariableEntry {
185 > kind: 'directory';
186 > imageCount?: number;
187 > }
188 >
189 > export interface IChatRequestFileEntry extends IBaseChatRequestVariableEntry {
190 > kind: 'file';
191 > }
192 >
193 > export const enum OmittedState {
194 > NotOmitted,
195 > Partial,
196 > Full,
197 > ImageLimitExceeded,
198 > }
199 >
200 > const CLAUDE_MESSAGES_MAX_IMAGES_PER_REQUEST = 20;
201 > const GEMINI_MAX_IMAGES_PER_REQUEST = 10;
202 >
203 > /**
204 > * Returns the image-attachment limit for the selected model.
205 > *
206 > * Claude-family models use a max of 20 (Messages API), Gemini-family models use
207 > * a max of 10. Other models do not have a UI-enforced image count limit.
208 > */
209 > export function getImageAttachmentLimit(model: Pick<ILanguageModelChatMetadata, 'family'> | undefined): number | undefined {
210 if (!model) {
211 return undefined;
223 return undefined;
224 }
226 > export interface IChatRequestToolEntry extends IBaseChatRequestVariableEntry {
227 > readonly kind: 'tool';
228 > }
229 >
230 > export interface IChatRequestToolSetEntry extends IBaseChatRequestVariableEntry {
231 > readonly kind: 'toolset';
232 > readonly value: IChatRequestToolEntry[];
233 > }
234 >
235 > export type ChatRequestToolReferenceEntry = IChatRequestToolEntry | IChatRequestToolSetEntry;
236 >
237 > export interface StringChatContextValue {
238 > value?: string;
239 > name?: string;
240 > modelDescription?: string;
241 > iconPath?: ChatContextIconPath;
242 > uri: URI;
243 > resourceUri?: URI;
244 > tooltip?: IMarkdownString;
245 > /**
246 > * Command ID to execute when this context item is clicked.
247 > */
248 > readonly commandId?: string;
249 > readonly handle: number;
250 > }
251 >
252 > export interface IChatRequestImplicitVariableEntry extends IBaseChatRequestVariableEntry {
253 > readonly kind: 'implicit';
254 > readonly isFile: true;
255 > readonly value: URI | Location | StringChatContextValue | undefined;
256 > readonly uri: URI | undefined;
257 > readonly isSelection: boolean;
258 > enabled: boolean;
259 > }
260 >
261 > export interface IChatRequestStringVariableEntry extends IBaseChatRequestVariableEntry {
262 > readonly kind: 'string';
263 > readonly value: string | undefined;
264 > readonly modelDescription?: string;
265 > readonly iconPath?: ChatContextIconPath;
266 > readonly uri: URI;
267 > readonly resourceUri?: URI;
268 > readonly tooltip?: IMarkdownString;
269 > /**
270 > * Command ID to execute when this context item is clicked.
271 > */
272 > readonly commandId?: string;
273 > readonly handle: number;
274 > }
275 >
276 > export interface IChatRequestWorkspaceVariableEntry extends IBaseChatRequestVariableEntry {
277 > readonly kind: 'workspace';
278 > readonly value: string;
279 > readonly modelDescription?: string;
280 > }
281 >
282 >
283 > export interface IChatRequestPasteVariableEntry extends IBaseChatRequestVariableEntry {
284 > readonly kind: 'paste';
285 > readonly code: string;
286 > readonly language: string;
287 > readonly pastedLines: string;
288 >
289 > // This is only used for old serialized data and should be removed once we no longer support it
290 > readonly fileName: string;
291 >
292 > // This is only undefined on old serialized data
293 > readonly copiedFrom: {
294 > readonly uri: URI;
295 > readonly range: IRange;
296 > } | undefined;
297 > }
298 >
299 > export function toPasteVariableEntry(
300 name: string,
301 code: string,
332 };
333 }
335 > export function restorePasteVariableEntryFromAttachment(attachment: IRestorablePasteAttachment): IChatRequestPasteVariableEntry | undefined {
336 const modelRepresentation = attachment.modelRepresentation;
337 if (typeof modelRepresentation !== 'string' || attachment._meta?.[ChatPasteAttachmentMetadata.Kind] !== 'paste') {
350 });
351 }
353 > export interface ISymbolVariableEntry extends IBaseChatRequestVariableEntry {
354 > readonly kind: 'symbol';
355 > readonly value: Location;
356 > readonly symbolKind: SymbolKind;
357 > }
358 >
359 > export interface ICommandResultVariableEntry extends IBaseChatRequestVariableEntry {
360 > readonly kind: 'command';
361 > }
362 >
363 > export interface IImageVariableEntry extends IBaseChatRequestVariableEntry {
364 > readonly kind: 'image';
365 > readonly isPasted?: boolean;
366 > readonly isURL?: boolean;
367 > readonly mimeType?: string;
368 > }
369 >
370 > export interface INotebookOutputVariableEntry extends IBaseChatRequestVariableEntry {
371 > readonly kind: 'notebookOutput';
372 > readonly outputIndex?: number;
373 > readonly mimeType?: string;
374 > }
375 >
376 > export interface IDiagnosticVariableEntryFilterData {
377 > readonly owner?: string;
378 > readonly problemMessage?: string;
379 > readonly filterUri?: URI;
380 > readonly filterSeverity?: MarkerSeverity;
381 > readonly filterRange?: IRange;
382 > }
383 >
384 >
385 >
386 > export namespace IDiagnosticVariableEntryFilterData {
387 > export const icon = Codicon.error;
388 >
389 > export function fromMarker(marker: IMarker): IDiagnosticVariableEntryFilterData {
390 return {
391 filterUri: marker.resource,
395 };
396 }
398 > export function toEntry(data: IDiagnosticVariableEntryFilterData): IDiagnosticVariableEntry {
399 return {
400 id: id(data),
406 };
407 }
409 > export function id(data: IDiagnosticVariableEntryFilterData) {
410 return [data.filterUri, data.owner, data.filterSeverity, data.filterRange?.startLineNumber, data.filterRange?.startColumn].join(':');
411 }
413 > export function label(data: IDiagnosticVariableEntryFilterData) {
414 const enum TrimThreshold {
415 MaxChars = 30,
436 return labelStr;
437 }
439 >
440 > export interface IDiagnosticVariableEntry extends IBaseChatRequestVariableEntry, IDiagnosticVariableEntryFilterData {
441 > readonly kind: 'diagnostic';
442 > }
443 >
444 > export interface IElementAncestorData {
445 > readonly tagName: string;
446 > readonly id?: string;
447 > readonly classNames?: string[];
448 > }
449 >
450 > export interface IElementVariableEntry extends IBaseChatRequestVariableEntry {
451 > readonly kind: 'element';
452 > readonly value: string;
453 > readonly ancestors?: IElementAncestorData[];
454 > readonly attributes?: Record<string, string>;
455 > readonly computedStyles?: Record<string, string>;
456 > readonly dimensions?: { readonly top: number; readonly left: number; readonly width: number; readonly height: number };
457 > readonly innerText?: string;
458 > }
459 >
460 > export interface IPromptFileVariableEntry extends IBaseChatRequestVariableEntry {
461 > readonly kind: 'promptFile';
462 > readonly value: URI;
463 > readonly isRoot: boolean;
464 > readonly originLabel?: string;
465 > readonly modelDescription: string;
466 > readonly automaticallyAdded: boolean;
467 > readonly toolReferences?: readonly ChatRequestToolReferenceEntry[];
468 > }
469 >
470 > export interface IPromptTextVariableEntry extends IBaseChatRequestVariableEntry {
471 > readonly kind: 'promptText';
472 > readonly value: string;
473 > readonly settingId?: string;
474 > readonly modelDescription: string;
475 > readonly automaticallyAdded: boolean;
476 > readonly toolReferences?: readonly ChatRequestToolReferenceEntry[];
477 > }
478 >
479 > export interface ISCMHistoryItemVariableEntry extends IBaseChatRequestVariableEntry {
480 > readonly kind: 'scmHistoryItem';
481 > readonly value: URI;
482 > readonly historyItem: ISCMHistoryItem;
483 > }
484 >
485 > export interface ISCMHistoryItemChangeVariableEntry extends IBaseChatRequestVariableEntry {
486 > readonly kind: 'scmHistoryItemChange';
487 > readonly value: URI;
488 > readonly historyItem: ISCMHistoryItem;
489 > }
490 >
491 > export interface ISCMHistoryItemChangeRangeVariableEntry extends IBaseChatRequestVariableEntry {
492 > readonly kind: 'scmHistoryItemChangeRange';
493 > readonly value: URI;
494 > readonly historyItemChangeStart: {
495 > readonly uri: URI;
496 > readonly historyItem: ISCMHistoryItem;
497 > };
498 > readonly historyItemChangeEnd: {
499 > readonly uri: URI;
500 > readonly historyItem: ISCMHistoryItem;
501 > };
502 > }
503 >
504 > export interface ITerminalVariableEntry extends IBaseChatRequestVariableEntry {
505 > readonly kind: 'terminalCommand';
506 > readonly value: string;
507 > readonly resource: URI;
508 > readonly command: string;
509 > readonly output?: string;
510 > readonly exitCode?: number;
511 > }
512 >
513 > export interface IDebugVariableEntry extends IBaseChatRequestVariableEntry {
514 > readonly kind: 'debugVariable';
515 > readonly value: string;
516 > readonly expression: string;
517 > readonly type?: string;
518 > }
519 >
520 > export interface IAgentFeedbackVariableEntry extends IBaseChatRequestVariableEntry {
521 > readonly kind: 'agentFeedback';
522 > readonly sessionResource: URI;
523 > /**
524 > * The agent-host annotations channel URI that backs these feedback items
525 > * (each item id is an annotation id on this channel). Set only for
526 > * agent-host sessions; used to emit {@link MessageAnnotationsAttachment}s
527 > * referencing the specific comments on the wire.
528 > */
529 > readonly annotationsResource?: URI;
530 > readonly feedbackItems: ReadonlyArray<{
531 > readonly id: string;
532 > readonly text: string;
533 > readonly resourceUri: URI;
534 > readonly range: IRange;
535 > readonly codeSelection?: string;
536 > readonly diffHunks?: string;
537 > /** When this item was converted from a PR review comment, the original thread ID. */
538 > readonly sourcePRReviewCommentId?: string;
539 > /** Additional replies that belong to the same comment thread as {@link text}. */
540 > readonly replies?: readonly string[];
541 > }>;
542 > }
543 >
544 > export interface IChatRequestDebugEventsVariableEntry extends IBaseChatRequestVariableEntry {
545 > readonly kind: 'debugEvents';
546 > /** Timestamp when the debug events were snapshotted. */
547 > readonly snapshotTime: number;
548 > /** The session resource these debug events belong to. */
549 > readonly sessionResource: URI;
550 > }
551 >
552 > export interface IChatRequestSessionReferenceVariableEntry extends IBaseChatRequestVariableEntry {
553 > readonly kind: 'sessionReference';
554 > readonly value: URI;
555 > }
556 >
557 > export interface IBrowserViewVariableEntry extends IBaseChatRequestVariableEntry {
558 > readonly kind: 'browserView';
559 > readonly value: URI;
560 > readonly browserId: string;
561 > }
562 >
563 > export function isBrowserViewVariableEntry(entry: IChatRequestVariableEntry): entry is IBrowserViewVariableEntry {
564 return entry.kind === 'browserView';
565 }
567 > export type IChatRequestVariableEntry = IGenericChatRequestVariableEntry | IChatRequestImplicitVariableEntry | IChatRequestPasteVariableEntry
568 > | ISymbolVariableEntry | ICommandResultVariableEntry | IDiagnosticVariableEntry | IImageVariableEntry
569 > | IChatRequestToolEntry | IChatRequestToolSetEntry
570 > | IChatRequestDirectoryEntry | IChatRequestFileEntry | INotebookOutputVariableEntry | IElementVariableEntry
571 > | IPromptFileVariableEntry | IPromptTextVariableEntry
572 > | ISCMHistoryItemVariableEntry | ISCMHistoryItemChangeVariableEntry | ISCMHistoryItemChangeRangeVariableEntry | ITerminalVariableEntry
573 > | IChatRequestStringVariableEntry | IChatRequestWorkspaceVariableEntry | IDebugVariableEntry | IAgentFeedbackVariableEntry
574 > | IChatRequestDebugEventsVariableEntry | IChatRequestSessionReferenceVariableEntry | IBrowserViewVariableEntry;
575 >
576 > export namespace IChatRequestVariableEntry {
577 >
578 > /**
579 > * Returns URI of the passed variant entry. Return undefined if not found.
580 > */
581 > export function toUri(entry: IChatRequestVariableEntry): URI | undefined {
582 return URI.isUri(entry.value)
583 ? entry.value
586 : undefined;
587 }
589 > export function toExport(v: IChatRequestVariableEntry): IChatRequestVariableEntry {
590 if (v.value instanceof Uint8Array) {
591 // 'dup' here is needed otherwise TS complains about the narrowed `value` in a spread operation
597 return v;
598 }
600 > export function fromExport(v: IChatRequestVariableEntry): IChatRequestVariableEntry {
601 // Old variables format
602 // eslint-disable-next-line local/code-no-in-operator
623 }
624 }
626 >
627 > export function isImplicitVariableEntry(obj: IChatRequestVariableEntry): obj is IChatRequestImplicitVariableEntry {
628 return obj.kind === 'implicit';
629 }
631 > export function isStringVariableEntry(obj: IChatRequestVariableEntry): obj is IChatRequestStringVariableEntry {
632 return obj.kind === 'string';
633 }
635 > export function isTerminalVariableEntry(obj: IChatRequestVariableEntry): obj is ITerminalVariableEntry {
636 return obj.kind === 'terminalCommand';
637 }
639 > export function isDebugVariableEntry(obj: IChatRequestVariableEntry): obj is IDebugVariableEntry {
640 return obj.kind === 'debugVariable';
641 }
643 > export function isAgentFeedbackVariableEntry(obj: IChatRequestVariableEntry): obj is IAgentFeedbackVariableEntry {
644 return obj.kind === 'agentFeedback';
645 }
647 > export function isPasteVariableEntry(obj: IChatRequestVariableEntry): obj is IChatRequestPasteVariableEntry {
648 return obj.kind === 'paste';
649 }
651 > export function isWorkspaceVariableEntry(obj: IChatRequestVariableEntry): obj is IChatRequestWorkspaceVariableEntry {
652 return obj.kind === 'workspace';
653 }
655 > export function isImageVariableEntry(obj: IChatRequestVariableEntry): obj is IImageVariableEntry {
656 return obj.kind === 'image';
657 }
659 > export function isExplicitFileOrImageVariableEntry(obj: IChatRequestVariableEntry): obj is IChatRequestFileEntry | IChatRequestDirectoryEntry | IImageVariableEntry {
660 return obj.kind === 'file' || obj.kind === 'directory' || obj.kind === 'image';
661 }
663 > export function getExplicitFileOrImageAttachmentSummary(entries: readonly IChatRequestVariableEntry[]): string | undefined {
664 const fileOrImageEntries = entries.filter(isExplicitFileOrImageVariableEntry);
665 if (!fileOrImageEntries.length) {
677 : localize('chat.attachmentSummary.file.many', "Attached {0} files", fileOrImageEntries.length);
678 }
680 > export function isNotebookOutputVariableEntry(obj: IChatRequestVariableEntry): obj is INotebookOutputVariableEntry {
681 return obj.kind === 'notebookOutput';
682 }
684 > export function isElementVariableEntry(obj: IChatRequestVariableEntry): obj is IElementVariableEntry {
685 return obj.kind === 'element';
686 }
688 > export function isDiagnosticsVariableEntry(obj: IChatRequestVariableEntry): obj is IDiagnosticVariableEntry {
689 return obj.kind === 'diagnostic';
690 }
692 > export function isChatRequestFileEntry(obj: IChatRequestVariableEntry): obj is IChatRequestFileEntry {
693 return obj.kind === 'file';
694 }
696 > export function isPromptFileVariableEntry(obj: IChatRequestVariableEntry): obj is IPromptFileVariableEntry {
697 return obj.kind === 'promptFile';
698 }
700 > export function isPromptTextVariableEntry(obj: IChatRequestVariableEntry): obj is IPromptTextVariableEntry {
701 return obj.kind === 'promptText';
702 }
704 > export function isChatRequestVariableEntry(obj: unknown): obj is IChatRequestVariableEntry {
705 const entry = obj as IChatRequestVariableEntry;
706 return typeof entry === 'object' &&
709 typeof entry.name === 'string';
710 }
712 > export function isSCMHistoryItemVariableEntry(obj: IChatRequestVariableEntry): obj is ISCMHistoryItemVariableEntry {
713 return obj.kind === 'scmHistoryItem';
714 }
716 > export function isSCMHistoryItemChangeVariableEntry(obj: IChatRequestVariableEntry): obj is ISCMHistoryItemChangeVariableEntry {
717 return obj.kind === 'scmHistoryItemChange';
718 }
720 > export function isSCMHistoryItemChangeRangeVariableEntry(obj: IChatRequestVariableEntry): obj is ISCMHistoryItemChangeRangeVariableEntry {
721 return obj.kind === 'scmHistoryItemChangeRange';
722 }
724 > export function isStringImplicitContextValue(value: unknown): value is StringChatContextValue {
725 const asStringImplicitContextValue = value as Partial<StringChatContextValue>;
726 return (
736 );
737 }
739 > export enum PromptFileVariableKind {
740 > Instruction = 'vscode.instructions.file.root',
741 > InstructionReference = `vscode.instructions.file.reference`,
742 > PromptFile = 'vscode.prompt.file',
743 > }
744 >
745 > /**
746 > * Utility to convert a {@link uri} to a chat variable entry.
747 > * The `id` of the chat variable can be one of the following:
748 > *
749 > * - `vscode.instructions.file.reference__<URI>`: for all non-root prompt instructions references
750 > * - `vscode.instructions.file.root__<URI>`: for *root* prompt instructions references
751 > * - `vscode.prompt.file__<URI>`: for prompt file references
752 > *
753 > * @param uri A resource URI that points to a prompt instructions file.
754 > * @param kind The kind of the prompt file variable entry.
755 > */
756 > export function toPromptFileVariableEntry(uri: URI, kind: PromptFileVariableKind, originLabel?: string, automaticallyAdded = false, toolReferences?: ChatRequestToolReferenceEntry[]): IPromptFileVariableEntry {
757 // `id` for all `prompt files` starts with the well-defined part that the copilot extension(or other chatbot) can rely on
758 return {
768 };
769 }
771 > enum PromptTextVariableKind {
772 > CustomizationsIndex = 'vscode.customizations.index',
773 > }
774 >
775 > export function toPromptTextVariableEntry(content: string, automaticallyAdded = false, toolReferences?: ChatRequestToolReferenceEntry[]): IPromptTextVariableEntry {
776 return {
777 id: PromptTextVariableKind.CustomizationsIndex,
784 };
785 }
787 > export function toFileVariableEntry(uri: URI, range?: IRange): IChatRequestFileEntry {
788 return {
789 kind: 'file',
793 };
794 }
796 > export function toToolVariableEntry(entry: IToolData, range?: IOffsetRange): IChatRequestToolEntry {
797 return {
798 kind: 'tool',
804 };
805 }
807 > export function toToolSetVariableEntry(entry: IToolSet, range?: IOffsetRange): IChatRequestToolSetEntry {
808 return {
809 kind: 'toolset',
815 };
816 }
818 > export class ChatRequestVariableSet {
819 > private _ids = new Set<string>();
820 > private _entries: IChatRequestVariableEntry[] = [];
821 >
822 > constructor(entries?: IChatRequestVariableEntry[]) {
823 if (entries) {
824 this.add(...entries);
825 }
826 }
828 > public add(...entry: IChatRequestVariableEntry[]): void {
829 for (const e of entry) {
830 if (!this._ids.has(e.id)) {
834 }
835 }
837 > public insertFirst(entry: IChatRequestVariableEntry): void {
838 if (!this._ids.has(entry.id)) {
839 this._ids.add(entry.id);
841 }
842 }
844 > public remove(entry: IChatRequestVariableEntry): void {
845 this._ids.delete(entry.id);
846 this._entries = this._entries.filter(e => e.id !== entry.id);
847 }
849 > public has(entry: IChatRequestVariableEntry): boolean {
850 return this._ids.has(entry.id);
851 }
853 > public asArray(): IChatRequestVariableEntry[] {
854 return this._entries.slice(0); // return a copy
855 }
857 > public get length(): number {
858 return this._entries.length;
859 }