Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/browser/mainThreadHooks.ts
5222 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 { URI, UriComponents } from '../../../base/common/uri.js';
7
import { Disposable } from '../../../base/common/lifecycle.js';
8
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
9
import { ExtHostContext, MainContext, MainThreadHooksShape } from '../common/extHost.protocol.js';
10
import { HookCommandResultKind, IHookCommandResult } from '../../contrib/chat/common/hooks/hooksCommandTypes.js';
11
import { IHookResult } from '../../contrib/chat/common/hooks/hooksTypes.js';
12
import { IHooksExecutionProxy, IHooksExecutionService } from '../../contrib/chat/common/hooks/hooksExecutionService.js';
13
import { HookTypeValue, IHookCommand } from '../../contrib/chat/common/promptSyntax/hookSchema.js';
14
import { CancellationToken } from '../../../base/common/cancellation.js';
15
16
@extHostNamedCustomer(MainContext.MainThreadHooks)
17
export class MainThreadHooks extends Disposable implements MainThreadHooksShape {
18
19
constructor(
20
extHostContext: IExtHostContext,
21
@IHooksExecutionService private readonly _hooksExecutionService: IHooksExecutionService,
22
) {
23
super();
24
const extHostProxy = extHostContext.getProxy(ExtHostContext.ExtHostHooks);
25
26
const proxy: IHooksExecutionProxy = {
27
runHookCommand: async (hookCommand: IHookCommand, input: unknown, token: CancellationToken): Promise<IHookCommandResult> => {
28
const result = await extHostProxy.$runHookCommand(hookCommand, input, token);
29
return {
30
kind: result.kind as HookCommandResultKind,
31
result: result.result
32
};
33
}
34
};
35
36
this._hooksExecutionService.setProxy(proxy);
37
}
38
39
async $executeHook(hookType: string, sessionResource: UriComponents, input: unknown, token: CancellationToken): Promise<IHookResult[]> {
40
const uri = URI.revive(sessionResource);
41
return this._hooksExecutionService.executeHook(hookType as HookTypeValue, uri, { input, token });
42
}
43
}
44
45