-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Expand file tree
/
Copy pathpromptsService.ts
More file actions
336 lines (278 loc) · 9.47 KB
/
promptsService.ts
File metadata and controls
336 lines (278 loc) · 9.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
import { Event } from '../../../../../../base/common/event.js';
import { IDisposable } from '../../../../../../base/common/lifecycle.js';
import { URI } from '../../../../../../base/common/uri.js';
import { ITextModel } from '../../../../../../editor/common/model.js';
import { ExtensionIdentifier, IExtensionDescription } from '../../../../../../platform/extensions/common/extensions.js';
import { createDecorator } from '../../../../../../platform/instantiation/common/instantiation.js';
import { IChatModeInstructions, IVariableReference } from '../../chatModes.js';
import { PromptsType } from '../promptTypes.js';
import { IHandOff, ParsedPromptFile } from '../promptFileParser.js';
import { ResourceSet } from '../../../../../../base/common/map.js';
/**
* Activation events for prompt file providers.
*/
export const CUSTOM_AGENT_PROVIDER_ACTIVATION_EVENT = 'onCustomAgentProvider';
export const INSTRUCTIONS_PROVIDER_ACTIVATION_EVENT = 'onInstructionsProvider';
export const PROMPT_FILE_PROVIDER_ACTIVATION_EVENT = 'onPromptFileProvider';
/**
* Options for querying prompt files.
*/
export interface IPromptFileQueryOptions { }
/**
* Represents a prompt file resource from an external provider.
*/
export interface IPromptFileResource {
/**
* The unique identifier/name of the custom agent resource.
*/
readonly name: string;
/**
* A description of what the custom agent resource does.
*/
readonly description: string;
/**
* The URI to the agent or prompt resource file.
*/
readonly uri: URI;
/**
* Indicates whether the custom agent resource is editable. Defaults to false.
*/
readonly isEditable?: boolean;
}
/**
* Provides prompt services.
*/
export const IPromptsService = createDecorator<IPromptsService>('IPromptsService');
/**
* Where the prompt is stored.
*/
export enum PromptsStorage {
local = 'local',
user = 'user',
extension = 'extension'
}
/**
* The type of source for extension agents.
*/
export enum ExtensionAgentSourceType {
contribution = 'contribution',
provider = 'provider',
}
/**
* Represents a prompt path with its type.
* This is used for both prompt files and prompt source folders.
*/
export type IPromptPath = IExtensionPromptPath | ILocalPromptPath | IUserPromptPath;
export interface IPromptPathBase {
/**
* URI of the prompt.
*/
readonly uri: URI;
/**
* Storage of the prompt.
*/
readonly storage: PromptsStorage;
/**
* Type of the prompt (e.g. 'prompt' or 'instructions').
*/
readonly type: PromptsType;
/**
* Identifier of the contributing extension (only when storage === PromptsStorage.extension).
*/
readonly extension?: IExtensionDescription;
readonly name?: string;
readonly description?: string;
}
export interface IExtensionPromptPath extends IPromptPathBase {
readonly storage: PromptsStorage.extension;
readonly extension: IExtensionDescription;
readonly source: ExtensionAgentSourceType;
readonly name?: string;
readonly description?: string;
}
export interface ILocalPromptPath extends IPromptPathBase {
readonly storage: PromptsStorage.local;
}
export interface IUserPromptPath extends IPromptPathBase {
readonly storage: PromptsStorage.user;
}
export type IAgentSource = {
readonly storage: PromptsStorage.extension;
readonly extensionId: ExtensionIdentifier;
readonly type: ExtensionAgentSourceType;
} | {
readonly storage: PromptsStorage.local | PromptsStorage.user;
};
export interface ICustomAgent {
/**
* URI of a custom agent file.
*/
readonly uri: URI;
/**
* Name of the custom agent as used in prompt files or contexts
*/
readonly name: string;
/**
* Description of the agent
*/
readonly description?: string;
/**
* Tools metadata in the prompt header.
*/
readonly tools?: readonly string[];
/**
* Model metadata in the prompt header.
*/
readonly model?: string;
/**
* Argument hint metadata in the prompt header that describes what inputs the agent expects or supports.
*/
readonly argumentHint?: string;
/**
* Target metadata in the prompt header.
*/
readonly target?: string;
/**
* Infer metadata in the prompt header.
*/
readonly infer?: boolean;
/**
* Contents of the custom agent file body and other agent instructions.
*/
readonly agentInstructions: IChatModeInstructions;
/**
* Hand-offs defined in the custom agent file.
*/
readonly handOffs?: readonly IHandOff[];
/**
* Where the agent was loaded from.
*/
readonly source: IAgentSource;
}
export interface IAgentInstructions {
readonly content: string;
readonly toolReferences: readonly IVariableReference[];
readonly metadata?: Record<string, boolean | string | number>;
}
export interface IChatPromptSlashCommand {
readonly name: string;
readonly description: string | undefined;
readonly argumentHint: string | undefined;
readonly promptPath: IPromptPath;
readonly parsedPromptFile: ParsedPromptFile;
}
export interface IAgentSkill {
readonly uri: URI;
readonly type: 'personal' | 'project';
readonly name: string;
readonly description: string | undefined;
}
/**
* Provides prompt services.
*/
export interface IPromptsService extends IDisposable {
readonly _serviceBrand: undefined;
/**
* The parsed prompt file for the provided text model.
* @param textModel Returns the parsed prompt file.
*/
getParsedPromptFile(textModel: ITextModel): ParsedPromptFile;
/**
* List all available prompt files.
*/
listPromptFiles(type: PromptsType, token: CancellationToken): Promise<readonly IPromptPath[]>;
/**
* List all available prompt files.
*/
listPromptFilesForStorage(type: PromptsType, storage: PromptsStorage, token: CancellationToken): Promise<readonly IPromptPath[]>;
/**
* Get a list of prompt source folders based on the provided prompt type.
*/
getSourceFolders(type: PromptsType): readonly IPromptPath[];
/**
* Validates if the provided command name is a valid prompt slash command.
*/
isValidSlashCommandName(name: string): boolean;
/**
* Gets the prompt file for a slash command.
*/
resolvePromptSlashCommand(command: string, token: CancellationToken): Promise<IChatPromptSlashCommand | undefined>;
/**
* Event that is triggered when the slash command to ParsedPromptFile cache is updated.
* Event handlers can use {@link resolvePromptSlashCommand} to retrieve the latest data.
*/
readonly onDidChangeSlashCommands: Event<void>;
/**
* Returns a prompt command if the command name is valid.
*/
getPromptSlashCommands(token: CancellationToken): Promise<readonly IChatPromptSlashCommand[]>;
/**
* Returns the prompt command name for the given URI.
*/
getPromptSlashCommandName(uri: URI, token: CancellationToken): Promise<string>;
/**
* Event that is triggered when the list of custom agents changes.
*/
readonly onDidChangeCustomAgents: Event<void>;
/**
* Finds all available custom agents
*/
getCustomAgents(token: CancellationToken): Promise<readonly ICustomAgent[]>;
/**
* Parses the provided URI
* @param uris
*/
parseNew(uri: URI, token: CancellationToken): Promise<ParsedPromptFile>;
/**
* Internal: register a contributed file. Returns a disposable that removes the contribution.
* Not intended for extension authors; used by contribution point handler.
*/
registerContributedFile(type: PromptsType, uri: URI, extension: IExtensionDescription, name: string | undefined, description: string | undefined): IDisposable;
getPromptLocationLabel(promptPath: IPromptPath): string;
/**
* Gets list of all AGENTS.md files in the workspace.
*/
findAgentMDsInWorkspace(token: CancellationToken): Promise<URI[]>;
/**
* Gets list of AGENTS.md files.
* @param includeNested Whether to include AGENTS.md files from subfolders, or only from the root.
*/
listAgentMDs(token: CancellationToken, includeNested: boolean): Promise<URI[]>;
/**
* Gets list of .github/copilot-instructions.md files.
*/
listCopilotInstructionsMDs(token: CancellationToken): Promise<URI[]>;
/**
* For a chat mode file URI, return the name of the agent file that it should use.
* @param oldURI
*/
getAgentFileURIFromModeFile(oldURI: URI): URI | undefined;
/**
* Returns the list of disabled prompt file URIs for a given type. By default no prompt files are disabled.
*/
getDisabledPromptFiles(type: PromptsType): ResourceSet;
/**
* Persists the set of disabled prompt file URIs for the given type.
*/
setDisabledPromptFiles(type: PromptsType, uris: ResourceSet): void;
/**
* Registers a prompt file provider that can provide prompt files for repositories.
* @param extension The extension registering the provider.
* @param type The type of contribution.
* @param provider The provider implementation with optional change event.
* @returns A disposable that unregisters the provider when disposed.
*/
registerPromptFileProvider(extension: IExtensionDescription, type: PromptsType, provider: {
onDidChangePromptFiles?: Event<void>;
providePromptFiles: (options: IPromptFileQueryOptions, token: CancellationToken) => Promise<IPromptFileResource[] | undefined>;
}): IDisposable;
/**
* Gets list of agent skills files.
*/
findAgentSkills(token: CancellationToken): Promise<IAgentSkill[] | undefined>;
}