import { IAction } from "../../../../../base/common/actions.js"; import { Disposable, DisposableStore, IDisposable } from "../../../../../base/common/lifecycle.js"; import { IObservable } from "../../../../../base/common/observable.js"; import { ThemeIcon } from "../../../../../base/common/themables.js"; import { IActionListItem } from "../../../../../platform/actionWidget/browser/actionList.js"; import { IActionWidgetService } from "../../../../../platform/actionWidget/browser/actionWidget.service.js"; import { IAgentHostEnablementService } from "../../../../../platform/agentHost/common/agentHostEnablementService.service.js"; import { IConfigurationService } from "../../../../../platform/configuration/common/configuration.service.js"; import { IDialogService } from "../../../../../platform/dialogs/common/dialogs.service.js"; import { IHoverService } from "../../../../../platform/hover/browser/hover.service.js"; import { IOpenerService } from "../../../../../platform/opener/common/opener.service.js"; import { IStorageService } from "../../../../../platform/storage/common/storage.service.js"; import { ITelemetryService } from "../../../../../platform/telemetry/common/telemetry.service.js"; import { ChatPermissionLevel } from "../../../../../workbench/contrib/chat/common/constants.js"; import { IModePickerPermissions, IPermissionLevelUnavailablePresentation, IUnavailablePermissionLevel } from "../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/agentHostModePickerPresentation.js"; /** * Strategy for the per-provider parts of {@link PermissionPicker}: how to read * back the current level (if at all), whether the picker should be visible * given the active session, and where to write the user's selection. * * Implementations live with the provider they back (e.g. * `AgentHostPermissionPickerDelegate` in the agent-host folder). */ export interface IPermissionPickerDelegate { readonly isPolicyRestricted?: () => boolean; /** * If provided, the picker's trigger label reactively tracks this. If * omitted, the picker manages its own internal state and starts at * {@link ChatPermissionLevel.Default}. */ readonly currentPermissionLevel?: IObservable; /** * If provided, the picker hides itself when this is `false`. Used by * delegates whose applicability depends on the active session. */ readonly isApplicable?: IObservable; /** Whether the picker is temporarily unavailable while its backing config resolves. */ readonly isResolving?: IObservable; /** * The ordered set of permission levels the picker should offer. When * omitted, the picker offers the default Copilot set * (`Default` / `Bypass` / `Autopilot`). Agent-host sessions offer the * supported subset of `Default` / `Assisted` / `Bypass`. */ readonly availableLevels?: readonly ChatPermissionLevel[]; /** Supported levels the session does not currently allow. They are shown disabled and are never selectable. */ readonly unavailableLevels?: IObservable; /** * The setting id the elevated-level warning dialog links to as "make this * the default". Defaults to `chat.permissions.default`; agent-host sessions * pass `chat.defaultConfiguration`. */ readonly defaultSettingKey?: string; getPermissionLevelMeta(level: ChatPermissionLevel, meta: IPermissionLevelMeta): IPermissionLevelMeta; /** * Called after the user selects a level (and any required confirmation * dialog has been accepted). */ setPermissionLevel(level: ChatPermissionLevel): void | Promise; /** * Optional hover content for delegates that need provider-specific copy. */ getPermissionLevelHover?(level: ChatPermissionLevel, meta: IPermissionLevelMeta): string | undefined; readonly isSandboxToggleApplicable?: () => boolean; readonly getSandboxToggleSettingId?: () => string | undefined; /** Tracks asynchronous setting ID changes, including agent host switches. */ readonly sandboxToggleSettingId?: IObservable; readonly getSandboxToggleProvider?: () => string | undefined; readonly sandboxEnabled?: IObservable; readonly sandboxConfirmedEnabled?: IObservable; readonly sandboxApplyFailed?: IObservable; readonly sandboxSelectionRejected?: IObservable; readonly sandboxDevContainer?: IObservable; readonly sandboxDevContainerSupported?: IObservable; setSandboxEnabled?(enabled: boolean): void; readonly managedSandboxEnforced?: IObservable; readonly managedSandboxAllowsBypass?: IObservable; readonly sandboxToggleConfigurationKeys?: readonly string[]; } export interface IPermissionLevelMeta { readonly label: string; readonly detail: string; readonly icon: ThemeIcon; readonly hover?: string; } /** Default level set offered when a delegate does not specify {@link IPermissionPickerDelegate.availableLevels}. */ export declare const DEFAULT_PERMISSION_LEVELS: readonly ChatPermissionLevel[]; export declare function getPermissionLevelMeta(level: ChatPermissionLevel): IPermissionLevelMeta; export declare class PermissionPicker extends Disposable { protected readonly _delegate: IPermissionPickerDelegate; protected readonly actionWidgetService: IActionWidgetService; protected readonly configurationService: IConfigurationService; protected readonly dialogService: IDialogService; protected readonly openerService: IOpenerService; protected readonly storageService: IStorageService; protected readonly telemetryService: ITelemetryService; protected readonly hoverService: IHoverService; private readonly agentHostEnablementService; protected _currentLevel: ChatPermissionLevel; protected _triggerElement: HTMLElement | undefined; protected readonly _renderDisposables: DisposableStore; private readonly _pickerDisposables; private readonly _sandboxDefaultChanged; constructor(_delegate: IPermissionPickerDelegate, actionWidgetService: IActionWidgetService, configurationService: IConfigurationService, dialogService: IDialogService, openerService: IOpenerService, storageService: IStorageService, telemetryService: ITelemetryService, hoverService: IHoverService, agentHostEnablementService: IAgentHostEnablementService); render(container: HTMLElement): HTMLElement; focus(): void; setFocusable(focusable: boolean): void; showPicker(): void; get presentation(): IModePickerPermissions; getActionListItems(isCurrentContext: () => boolean): readonly IActionListItem[]; private _getActionItems; private _selectItem; protected _showPicker(): void; /** Keeps open picker items current with sandbox changes and closes them when unavailable levels change. */ watchActionItems(items: readonly IActionListItem[]): IDisposable; watchSandboxToggle(items: readonly IActionListItem[]): IDisposable; protected _isResolving(): boolean; protected _isPolicyRestricted(): boolean; /** Selectable levels plus supported levels the session does not currently allow, in display order. */ protected _getOfferedLevels(): readonly ChatPermissionLevel[]; protected _isLevelUnavailable(level: ChatPermissionLevel): boolean; /** Default is never unavailable; elevated levels are disabled by the legacy auto-approval policy or withheld by the host. */ protected _getUnavailablePresentation(level: ChatPermissionLevel): IPermissionLevelUnavailablePresentation | undefined; protected _selectLevel(level: ChatPermissionLevel, isCurrentContext?: () => boolean): Promise; private _updateTriggerLabel; private _getSandboxStandaloneToggle; /** * Explains Dev Container sandboxing, which relaxes the container's isolation, and links to its * documentation from a footer action that keyboard users reach with Tab. */ private _getSandboxToggleHover; private _isSandboxToggleAvailable; private _isSandboxingEnabled; private _readSandboxToggleState; private _affectsSandboxToggle; private _getPermissionLevelHover; private _getTriggerHover; protected _getPermissionLevelMeta(level: ChatPermissionLevel): IPermissionLevelMeta; }