Path: blob/main/extensions/copilot/src/extension/commands/node/commandService.ts
13399 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 { ChatLocation } from '../../../platform/chat/common/commonTypes';6import { createServiceIdentifier } from '../../../util/common/services';7import { IIntentService } from '../../intents/node/intentService';8import { CommandDetails } from '../../prompt/node/intentRegistry';910export const ICommandService = createServiceIdentifier<ICommandService>('ICommandService');1112export interface ICommandService {13readonly _serviceBrand: undefined;14getCommands(location: ChatLocation): CommandDetails[];15getCommand(commandId: string, location: ChatLocation): CommandDetails | undefined;16}1718export class CommandServiceImpl implements ICommandService {1920declare _serviceBrand: undefined;212223constructor(24@IIntentService private readonly intentService: IIntentService25) { }2627public getCommands(location: ChatLocation): CommandDetails[] {28return this.intentService.getIntents(location)29.filter(candidate => !candidate.commandInfo || !candidate.commandInfo.hiddenFromUser)30.map(intent => ({ commandId: intent.id, intent, details: intent.description, locations: intent.locations, toolEquivalent: intent.commandInfo?.toolEquivalent } satisfies CommandDetails));31}3233public getCommand(id: string, location: ChatLocation): CommandDetails | undefined {34return this.getCommands(location).find(c => c.commandId === id);35}36}373839