55
66import { URI } from '../../../../../base/common/uri.js' ;
77import { Emitter } from '../../../../../base/common/event.js' ;
8+ import { basename } from '../../../../../base/common/resources.js' ;
89import { IChatRequestVariableEntry } from '../../common/chatModel.js' ;
910import { ChatPromptAttachmentModel } from './chatPromptAttachmentModel.js' ;
1011import { PromptsConfig } from '../../../../../platform/prompts/common/config.js' ;
@@ -13,6 +14,30 @@ import { Disposable, DisposableMap } from '../../../../../base/common/lifecycle.
1314import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js' ;
1415import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
1516
17+ /**
18+ * Prompt IDs start with a well-defined prefix that is used by
19+ * the copilot extension to identify prompt references.
20+ *
21+ * @param uri The URI of the prompt file.
22+ * @param isRoot Whether the prompt file is the root file, or a
23+ * child reference that is nested inside the root file.
24+ */
25+ export const createPromptVariableId = (
26+ uri : URI ,
27+ isRoot : boolean ,
28+ ) : string => {
29+ // the default prefix that is used for all prompt files
30+ let prefix = 'vscode.prompt.instructions' ;
31+ // if the reference is the root object, add the `.root` suffix
32+ if ( isRoot ) {
33+ prefix += '.root' ;
34+ }
35+
36+ // final `id` for all `prompt files` starts with the well-defined
37+ // part that the copilot extension(or other chatbot) can rely on
38+ return `${ prefix } __${ uri } ` ;
39+ } ;
40+
1641/**
1742 * Utility to convert a {@link reference} to a chat variable entry.
1843 * The `id` of the chat variable can be one of the following:
@@ -34,23 +59,14 @@ export const toChatVariable = (
3459 // default `id` is the stringified `URI`
3560 let id = `${ uri } ` ;
3661
37- // for prompt files, we add a prefix to the `id`
62+ // prompts have special `id`s that are used by the copilot extension
3863 if ( isPromptFile ) {
39- // the default prefix that is used for all prompt files
40- let prefix = 'vscode.prompt.instructions' ;
41- // if the reference is the root object, add the `.root` suffix
42- if ( isRoot ) {
43- prefix += '.root' ;
44- }
45-
46- // final `id` for all `prompt files` starts with the well-defined
47- // part that the copilot extension(or other chatbot) can rely on
48- id = `${ prefix } __${ id } ` ;
64+ id = createPromptVariableId ( uri , isRoot ) ;
4965 }
5066
5167 return {
5268 id,
53- name : uri . fsPath ,
69+ name : `file: ${ basename ( uri ) } ` ,
5470 value : uri ,
5571 kind : 'file' ,
5672 } ;
0 commit comments