Path: blob/main/src/vs/workbench/contrib/chat/common/aiCustomizationWorkspaceService.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CancellationToken } from '../../../../base/common/cancellation.js';6import { IObservable } from '../../../../base/common/observable.js';7import { URI } from '../../../../base/common/uri.js';8import { isEqualOrParent } from '../../../../base/common/resources.js';9import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';10import { PromptsType } from './promptSyntax/promptTypes.js';11import { IChatPromptSlashCommand, PromptsStorage } from './promptSyntax/service/promptsService.js';1213export const IAICustomizationWorkspaceService = createDecorator<IAICustomizationWorkspaceService>('aiCustomizationWorkspaceService');1415/**16* Extended storage type for AI Customization that includes built-in prompts17* shipped with the application, alongside the core `PromptsStorage` values.18*/19export type AICustomizationPromptsStorage = PromptsStorage | 'builtin';2021/**22* Storage type discriminator for built-in customizations shipped with the application.23*/24export const BUILTIN_STORAGE: AICustomizationPromptsStorage = 'builtin';2526/**27* Possible section IDs for the AI Customization Management Editor sidebar.28*/29export const AICustomizationManagementSection = {30Agents: 'agents',31Skills: 'skills',32Instructions: 'instructions',33Prompts: 'prompts',34Hooks: 'hooks',35McpServers: 'mcpServers',36Plugins: 'plugins',37Models: 'models',38} as const;3940export type AICustomizationManagementSection = typeof AICustomizationManagementSection[keyof typeof AICustomizationManagementSection];4142/**43* Per-type filter policy controlling which storage sources and user file44* roots are visible for a given customization type.45*/46export interface IStorageSourceFilter {47/**48* Which storage groups to display (e.g. workspace, user, extension, builtin).49*/50readonly sources: readonly string[];5152/**53* If set, only user files under these roots are shown (allowlist).54* If `undefined`, all user file roots are included.55*/56readonly includedUserFileRoots?: readonly URI[];57}5859/**60* Controls which features are shown on the welcome page of the61* AI Customization Management Editor.62*/63export interface IWelcomePageFeatures {64/** Show the "Configure Your AI" getting-started banner. */65readonly showGettingStartedBanner: boolean;66}6768/**69* Applies a storage source filter to an array of items that have uri and storage.70* Removes items whose storage is not in the filter's source list,71* and for user-storage items, removes those not under an allowed root.72*/73export function applyStorageSourceFilter<T extends { readonly uri: URI; readonly storage: string }>(items: readonly T[], filter: IStorageSourceFilter): readonly T[] {74const sourceSet = new Set(filter.sources);75return items.filter(item => {76if (!sourceSet.has(item.storage)) {77return false;78}79if (item.storage === PromptsStorage.user && filter.includedUserFileRoots) {80return filter.includedUserFileRoots.some(root => isEqualOrParent(item.uri, root));81}82return true;83});84}8586/**87* Provides workspace context for AI Customization views.88*/89export interface IAICustomizationWorkspaceService {90readonly _serviceBrand: undefined;9192/**93* Observable that fires when the active project root changes.94*/95readonly activeProjectRoot: IObservable<URI | undefined>;9697/**98* Returns the current active project root, if any.99*/100getActiveProjectRoot(): URI | undefined;101102/**103* The sections to show in the AI Customization Management Editor sidebar.104*/105readonly managementSections: readonly AICustomizationManagementSection[];106107/**108* Returns the storage source filter for a given customization type.109* Controls which storage groups and user file roots are visible.110*/111getStorageSourceFilter(type: PromptsType): IStorageSourceFilter;112113/**114* Whether this is a sessions window (vs core VS Code).115*/116readonly isSessionsWindow: boolean;117118/**119* Controls which features are displayed on the welcome page.120*/121readonly welcomePageFeatures: IWelcomePageFeatures;122123/**124* Commits files in the active project.125*/126commitFiles(projectRoot: URI, fileUris: URI[]): Promise<void>;127128/**129* Commits the deletion of resources that have already been removed from disk.130* The URIs may point to individual files or to directories (for example, when131* deleting a skill, the entire customization folder is removed). Implementations132* should ensure that directory deletions are handled recursively as needed.133* In sessions this stages and commits the removal in the relevant repositories.134*/135deleteFiles(projectRoot: URI, fileUris: URI[]): Promise<void>;136137/**138* Launches the AI-guided creation flow for the given customization type.139*/140generateCustomization(type: PromptsType): Promise<void>;141142/**143* Whether a transient project root override is currently active.144*/145readonly hasOverrideProjectRoot: IObservable<boolean>;146147/**148* Sets a transient override for the active project root.149* While set, `activeProjectRoot` returns this value instead of the150* session- or workspace-derived root. Call `clearOverrideProjectRoot()` to revert.151*/152setOverrideProjectRoot(root: URI): void;153154/**155* Clears the transient project root override, reverting to the156* session-derived (or workspace-derived) root.157*/158clearOverrideProjectRoot(): void;159160/**161* Returns prompt/skill slash commands filtered through the workspace162* service's storage source policy, ensuring the results match the163* customizations visible in the AI Customization views.164*/165getFilteredPromptSlashCommands(token: CancellationToken): Promise<readonly IChatPromptSlashCommand[]>;166167/**168* Returns a map of built-in skill names that have direct UI integrations169* (toolbar buttons, menu items, etc.) to a tooltip describing the170* integration. Used to display a 'UI Integration' badge in the171* customizations editor, especially important when users override a172* built-in skill that drives a UI surface.173*/174getSkillUIIntegrations(): ReadonlyMap<string, string>;175}176177178