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