Skip to content

Commit 842bdbb

Browse files
authored
Fix extHostHooks for web (#292968)
1 parent c35bf16 commit 842bdbb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/vs/workbench/api/worker/extHost.worker.services.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { InstantiationType, registerSingleton } from '../../../platform/instanti
88
import { ILogService } from '../../../platform/log/common/log.js';
99
import { ExtHostAuthentication, IExtHostAuthentication } from '../common/extHostAuthentication.js';
1010
import { IExtHostExtensionService } from '../common/extHostExtensionService.js';
11+
import { IExtHostHooks } from '../common/extHostHooks.js';
1112
import { ExtHostLogService } from '../common/extHostLogService.js';
1213
import { ExtensionStoragePaths, IExtensionStoragePaths } from '../common/extHostStoragePaths.js';
1314
import { ExtHostTelemetry, IExtHostTelemetry } from '../common/extHostTelemetry.js';
1415
import { ExtHostExtensionService } from './extHostExtensionService.js';
16+
import { WorkerExtHostHooks } from './extHostHooksWorker.js';
1517

1618
// #########################################################################
1719
// ### ###
@@ -24,3 +26,4 @@ registerSingleton(IExtHostAuthentication, ExtHostAuthentication, InstantiationTy
2426
registerSingleton(IExtHostExtensionService, ExtHostExtensionService, InstantiationType.Eager);
2527
registerSingleton(IExtensionStoragePaths, ExtensionStoragePaths, InstantiationType.Eager);
2628
registerSingleton(IExtHostTelemetry, new SyncDescriptor(ExtHostTelemetry, [true], true));
29+
registerSingleton(IExtHostHooks, WorkerExtHostHooks, InstantiationType.Eager);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 type * as vscode from 'vscode';
7+
import { CancellationToken } from '../../../base/common/cancellation.js';
8+
import { ILogService } from '../../../platform/log/common/log.js';
9+
import { HookTypeValue } from '../../contrib/chat/common/promptSyntax/hookSchema.js';
10+
import { isToolInvocationContext, IToolInvocationContext } from '../../contrib/chat/common/tools/languageModelToolsService.js';
11+
import { IHookCommandDto, MainContext, MainThreadHooksShape } from '../common/extHost.protocol.js';
12+
import { IChatHookExecutionOptions, IExtHostHooks } from '../common/extHostHooks.js';
13+
import { IExtHostRpcService } from '../common/extHostRpcService.js';
14+
import { HookCommandResultKind, IHookCommandResult, IHookResult } from '../../contrib/chat/common/hooksExecutionService.js';
15+
import * as typeConverters from '../common/extHostTypeConverters.js';
16+
17+
export class WorkerExtHostHooks implements IExtHostHooks {
18+
19+
private readonly _mainThreadProxy: MainThreadHooksShape;
20+
21+
constructor(
22+
@IExtHostRpcService extHostRpc: IExtHostRpcService,
23+
@ILogService private readonly _logService: ILogService
24+
) {
25+
this._mainThreadProxy = extHostRpc.getProxy(MainContext.MainThreadHooks);
26+
}
27+
28+
async executeHook(hookType: HookTypeValue, options: IChatHookExecutionOptions, token?: CancellationToken): Promise<vscode.ChatHookResult[]> {
29+
if (!options.toolInvocationToken || !isToolInvocationContext(options.toolInvocationToken)) {
30+
throw new Error('Invalid or missing tool invocation token');
31+
}
32+
33+
const context = options.toolInvocationToken as IToolInvocationContext;
34+
35+
const results = await this._mainThreadProxy.$executeHook(hookType, context.sessionResource, options.input, token ?? CancellationToken.None);
36+
return results.map(r => typeConverters.ChatHookResult.to(r as IHookResult));
37+
}
38+
39+
async $runHookCommand(_hookCommand: IHookCommandDto, _input: unknown, _token: CancellationToken): Promise<IHookCommandResult> {
40+
this._logService.debug('[WorkerExtHostHooks] Hook commands are not supported in web worker context');
41+
42+
// Web worker cannot run shell commands - return an error
43+
return {
44+
kind: HookCommandResultKind.Error,
45+
result: 'Hook commands are not supported in web worker context'
46+
};
47+
}
48+
}

0 commit comments

Comments
 (0)