Path: blob/main/src/vs/workbench/api/browser/mainThreadHooks.ts
5222 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 { URI, UriComponents } from '../../../base/common/uri.js';6import { Disposable } from '../../../base/common/lifecycle.js';7import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';8import { ExtHostContext, MainContext, MainThreadHooksShape } from '../common/extHost.protocol.js';9import { HookCommandResultKind, IHookCommandResult } from '../../contrib/chat/common/hooks/hooksCommandTypes.js';10import { IHookResult } from '../../contrib/chat/common/hooks/hooksTypes.js';11import { IHooksExecutionProxy, IHooksExecutionService } from '../../contrib/chat/common/hooks/hooksExecutionService.js';12import { HookTypeValue, IHookCommand } from '../../contrib/chat/common/promptSyntax/hookSchema.js';13import { CancellationToken } from '../../../base/common/cancellation.js';1415@extHostNamedCustomer(MainContext.MainThreadHooks)16export class MainThreadHooks extends Disposable implements MainThreadHooksShape {1718constructor(19extHostContext: IExtHostContext,20@IHooksExecutionService private readonly _hooksExecutionService: IHooksExecutionService,21) {22super();23const extHostProxy = extHostContext.getProxy(ExtHostContext.ExtHostHooks);2425const proxy: IHooksExecutionProxy = {26runHookCommand: async (hookCommand: IHookCommand, input: unknown, token: CancellationToken): Promise<IHookCommandResult> => {27const result = await extHostProxy.$runHookCommand(hookCommand, input, token);28return {29kind: result.kind as HookCommandResultKind,30result: result.result31};32}33};3435this._hooksExecutionService.setProxy(proxy);36}3738async $executeHook(hookType: string, sessionResource: UriComponents, input: unknown, token: CancellationToken): Promise<IHookResult[]> {39const uri = URI.revive(sessionResource);40return this._hooksExecutionService.executeHook(hookType as HookTypeValue, uri, { input, token });41}42}434445