Path: blob/main/src/vs/workbench/api/worker/extHostHooksWorker.ts
5232 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 type * as vscode from 'vscode';6import { CancellationToken } from '../../../base/common/cancellation.js';7import { ILogService } from '../../../platform/log/common/log.js';8import { HookTypeValue } from '../../contrib/chat/common/promptSyntax/hookSchema.js';9import { isToolInvocationContext, IToolInvocationContext } from '../../contrib/chat/common/tools/languageModelToolsService.js';10import { IHookCommandDto, MainContext, MainThreadHooksShape } from '../common/extHost.protocol.js';11import { IChatHookExecutionOptions, IExtHostHooks } from '../common/extHostHooks.js';12import { IExtHostRpcService } from '../common/extHostRpcService.js';13import * as typeConverters from '../common/extHostTypeConverters.js';14import { IHookResult } from '../../contrib/chat/common/hooks/hooksTypes.js';15import { HookCommandResultKind, IHookCommandResult } from '../../contrib/chat/common/hooks/hooksCommandTypes.js';1617export class WorkerExtHostHooks implements IExtHostHooks {1819private readonly _mainThreadProxy: MainThreadHooksShape;2021constructor(22@IExtHostRpcService extHostRpc: IExtHostRpcService,23@ILogService private readonly _logService: ILogService24) {25this._mainThreadProxy = extHostRpc.getProxy(MainContext.MainThreadHooks);26}2728async executeHook(hookType: HookTypeValue, options: IChatHookExecutionOptions, token?: CancellationToken): Promise<vscode.ChatHookResult[]> {29if (!options.toolInvocationToken || !isToolInvocationContext(options.toolInvocationToken)) {30throw new Error('Invalid or missing tool invocation token');31}3233const context = options.toolInvocationToken as IToolInvocationContext;3435const results = await this._mainThreadProxy.$executeHook(hookType, context.sessionResource, options.input, token ?? CancellationToken.None);36return results.map(r => typeConverters.ChatHookResult.to(r as IHookResult));37}3839async $runHookCommand(_hookCommand: IHookCommandDto, _input: unknown, _token: CancellationToken): Promise<IHookCommandResult> {40this._logService.debug('[WorkerExtHostHooks] Hook commands are not supported in web worker context');4142// Web worker cannot run shell commands - return an error43return {44kind: HookCommandResultKind.Error,45result: 'Hook commands are not supported in web worker context'46};47}48}495051