Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/chat/browser/agentHost/agentHostPermissionPickerActionItem.ts
13405 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 { autorun } from '../../../../../base/common/observable.js';
7
import { MenuItemAction } from '../../../../../platform/actions/common/actions.js';
8
import { IActionWidgetService } from '../../../../../platform/actionWidget/browser/actionWidget.js';
9
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
10
import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';
11
import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js';
12
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
13
import { IKeybindingService } from '../../../../../platform/keybinding/common/keybinding.js';
14
import { IOpenerService } from '../../../../../platform/opener/common/opener.js';
15
import { IStorageService } from '../../../../../platform/storage/common/storage.js';
16
import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js';
17
import { IChatInputPickerOptions } from '../../../../../workbench/contrib/chat/browser/widget/input/chatInputPickerActionItem.js';
18
import { PermissionPickerActionItem } from '../../../../../workbench/contrib/chat/browser/widget/input/permissionPickerActionItem.js';
19
import { AgentHostPermissionPickerDelegate } from './agentHostPermissionPickerDelegate.js';
20
21
/**
22
* Agent host wrapper around the workbench {@link PermissionPickerActionItem}
23
* for use in the running chat widget's secondary toolbar
24
* (`MenuId.ChatInputSecondary`). Owns its
25
* {@link AgentHostPermissionPickerDelegate} and reactively hides itself when
26
* the active session's `autoApprove` schema doesn't match the well-known
27
* shape.
28
*/
29
export class AgentHostPermissionPickerActionItem extends PermissionPickerActionItem {
30
31
private readonly _delegate: AgentHostPermissionPickerDelegate;
32
33
constructor(
34
action: MenuItemAction,
35
pickerOptions: IChatInputPickerOptions,
36
@IInstantiationService instantiationService: IInstantiationService,
37
@IActionWidgetService actionWidgetService: IActionWidgetService,
38
@IKeybindingService keybindingService: IKeybindingService,
39
@IContextKeyService contextKeyService: IContextKeyService,
40
@ITelemetryService telemetryService: ITelemetryService,
41
@IConfigurationService configurationService: IConfigurationService,
42
@IDialogService dialogService: IDialogService,
43
@IOpenerService openerService: IOpenerService,
44
@IStorageService storageService: IStorageService,
45
) {
46
const delegate = instantiationService.createInstance(AgentHostPermissionPickerDelegate);
47
super(
48
action,
49
delegate,
50
pickerOptions,
51
actionWidgetService,
52
keybindingService,
53
contextKeyService,
54
telemetryService,
55
configurationService,
56
dialogService,
57
openerService,
58
storageService,
59
);
60
this._delegate = this._register(delegate);
61
62
// The base widget's label is rendered on demand via `refresh()`. Keep it
63
// in sync with the delegate's level observable.
64
this._register(autorun(reader => {
65
delegate.currentPermissionLevel.read(reader);
66
this.refresh();
67
}));
68
}
69
70
override render(container: HTMLElement): void {
71
super.render(container);
72
// The active session can change while this view item is alive (the
73
// `IActionViewItemService` factory only runs once per render), so gate
74
// visibility reactively rather than at construction time.
75
this._register(autorun(reader => {
76
const visible = this._delegate.isApplicable.read(reader);
77
if (this.element) {
78
this.element.style.display = visible ? '' : 'none';
79
}
80
}));
81
}
82
}
83
84