Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/common/aiCustomizationWorkspaceService.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
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 { CancellationToken } from '../../../../base/common/cancellation.js';
7
import { IObservable } from '../../../../base/common/observable.js';
8
import { URI } from '../../../../base/common/uri.js';
9
import { isEqualOrParent } from '../../../../base/common/resources.js';
10
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
11
import { PromptsType } from './promptSyntax/promptTypes.js';
12
import { IChatPromptSlashCommand, PromptsStorage } from './promptSyntax/service/promptsService.js';
13
14
export const IAICustomizationWorkspaceService = createDecorator<IAICustomizationWorkspaceService>('aiCustomizationWorkspaceService');
15
16
/**
17
* Extended storage type for AI Customization that includes built-in prompts
18
* shipped with the application, alongside the core `PromptsStorage` values.
19
*/
20
export type AICustomizationPromptsStorage = PromptsStorage | 'builtin';
21
22
/**
23
* Storage type discriminator for built-in customizations shipped with the application.
24
*/
25
export const BUILTIN_STORAGE: AICustomizationPromptsStorage = 'builtin';
26
27
/**
28
* Possible section IDs for the AI Customization Management Editor sidebar.
29
*/
30
export const AICustomizationManagementSection = {
31
Agents: 'agents',
32
Skills: 'skills',
33
Instructions: 'instructions',
34
Prompts: 'prompts',
35
Hooks: 'hooks',
36
McpServers: 'mcpServers',
37
Plugins: 'plugins',
38
Models: 'models',
39
} as const;
40
41
export type AICustomizationManagementSection = typeof AICustomizationManagementSection[keyof typeof AICustomizationManagementSection];
42
43
/**
44
* Per-type filter policy controlling which storage sources and user file
45
* roots are visible for a given customization type.
46
*/
47
export interface IStorageSourceFilter {
48
/**
49
* Which storage groups to display (e.g. workspace, user, extension, builtin).
50
*/
51
readonly sources: readonly string[];
52
53
/**
54
* If set, only user files under these roots are shown (allowlist).
55
* If `undefined`, all user file roots are included.
56
*/
57
readonly includedUserFileRoots?: readonly URI[];
58
}
59
60
/**
61
* Controls which features are shown on the welcome page of the
62
* AI Customization Management Editor.
63
*/
64
export interface IWelcomePageFeatures {
65
/** Show the "Configure Your AI" getting-started banner. */
66
readonly showGettingStartedBanner: boolean;
67
}
68
69
/**
70
* Applies a storage source filter to an array of items that have uri and storage.
71
* Removes items whose storage is not in the filter's source list,
72
* and for user-storage items, removes those not under an allowed root.
73
*/
74
export function applyStorageSourceFilter<T extends { readonly uri: URI; readonly storage: string }>(items: readonly T[], filter: IStorageSourceFilter): readonly T[] {
75
const sourceSet = new Set(filter.sources);
76
return items.filter(item => {
77
if (!sourceSet.has(item.storage)) {
78
return false;
79
}
80
if (item.storage === PromptsStorage.user && filter.includedUserFileRoots) {
81
return filter.includedUserFileRoots.some(root => isEqualOrParent(item.uri, root));
82
}
83
return true;
84
});
85
}
86
87
/**
88
* Provides workspace context for AI Customization views.
89
*/
90
export interface IAICustomizationWorkspaceService {
91
readonly _serviceBrand: undefined;
92
93
/**
94
* Observable that fires when the active project root changes.
95
*/
96
readonly activeProjectRoot: IObservable<URI | undefined>;
97
98
/**
99
* Returns the current active project root, if any.
100
*/
101
getActiveProjectRoot(): URI | undefined;
102
103
/**
104
* The sections to show in the AI Customization Management Editor sidebar.
105
*/
106
readonly managementSections: readonly AICustomizationManagementSection[];
107
108
/**
109
* Returns the storage source filter for a given customization type.
110
* Controls which storage groups and user file roots are visible.
111
*/
112
getStorageSourceFilter(type: PromptsType): IStorageSourceFilter;
113
114
/**
115
* Whether this is a sessions window (vs core VS Code).
116
*/
117
readonly isSessionsWindow: boolean;
118
119
/**
120
* Controls which features are displayed on the welcome page.
121
*/
122
readonly welcomePageFeatures: IWelcomePageFeatures;
123
124
/**
125
* Commits files in the active project.
126
*/
127
commitFiles(projectRoot: URI, fileUris: URI[]): Promise<void>;
128
129
/**
130
* Commits the deletion of resources that have already been removed from disk.
131
* The URIs may point to individual files or to directories (for example, when
132
* deleting a skill, the entire customization folder is removed). Implementations
133
* should ensure that directory deletions are handled recursively as needed.
134
* In sessions this stages and commits the removal in the relevant repositories.
135
*/
136
deleteFiles(projectRoot: URI, fileUris: URI[]): Promise<void>;
137
138
/**
139
* Launches the AI-guided creation flow for the given customization type.
140
*/
141
generateCustomization(type: PromptsType): Promise<void>;
142
143
/**
144
* Whether a transient project root override is currently active.
145
*/
146
readonly hasOverrideProjectRoot: IObservable<boolean>;
147
148
/**
149
* Sets a transient override for the active project root.
150
* While set, `activeProjectRoot` returns this value instead of the
151
* session- or workspace-derived root. Call `clearOverrideProjectRoot()` to revert.
152
*/
153
setOverrideProjectRoot(root: URI): void;
154
155
/**
156
* Clears the transient project root override, reverting to the
157
* session-derived (or workspace-derived) root.
158
*/
159
clearOverrideProjectRoot(): void;
160
161
/**
162
* Returns prompt/skill slash commands filtered through the workspace
163
* service's storage source policy, ensuring the results match the
164
* customizations visible in the AI Customization views.
165
*/
166
getFilteredPromptSlashCommands(token: CancellationToken): Promise<readonly IChatPromptSlashCommand[]>;
167
168
/**
169
* Returns a map of built-in skill names that have direct UI integrations
170
* (toolbar buttons, menu items, etc.) to a tooltip describing the
171
* integration. Used to display a 'UI Integration' badge in the
172
* customizations editor, especially important when users override a
173
* built-in skill that drives a UI surface.
174
*/
175
getSkillUIIntegrations(): ReadonlyMap<string, string>;
176
}
177
178