Path: blob/main/src/vs/workbench/contrib/chat/common/promptSyntax/hookCopilotCliCompat.ts
5243 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 { HookType } from './hookSchema.js';67/**8* Maps Copilot CLI hook type names to our abstract HookType.9* Copilot CLI uses camelCase names.10*/11export const COPILOT_CLI_HOOK_TYPE_MAP: Record<string, HookType> = {12'sessionStart': HookType.SessionStart,13'userPromptSubmitted': HookType.UserPromptSubmit,14'preToolUse': HookType.PreToolUse,15'postToolUse': HookType.PostToolUse,16};1718/**19* Cached inverse mapping from HookType to Copilot CLI hook type name.20* Lazily computed on first access.21*/22let _hookTypeToCopilotCliName: Map<HookType, string> | undefined;2324function getHookTypeToCopilotCliNameMap(): Map<HookType, string> {25if (!_hookTypeToCopilotCliName) {26_hookTypeToCopilotCliName = new Map();27for (const [copilotCliName, hookType] of Object.entries(COPILOT_CLI_HOOK_TYPE_MAP)) {28_hookTypeToCopilotCliName.set(hookType, copilotCliName);29}30}31return _hookTypeToCopilotCliName;32}3334/**35* Resolves a Copilot CLI hook type name to our abstract HookType.36*/37export function resolveCopilotCliHookType(name: string): HookType | undefined {38return COPILOT_CLI_HOOK_TYPE_MAP[name];39}4041/**42* Gets the Copilot CLI hook type name for a given abstract HookType.43* Returns undefined if the hook type is not supported in Copilot CLI.44*/45export function getCopilotCliHookTypeName(hookType: HookType): string | undefined {46return getHookTypeToCopilotCliNameMap().get(hookType);47}484950