import { URI } from "../../../../../../base/common/uri.js"; import { CancellationToken } from "../../../../../../base/common/cancellation.js"; import { Event } from "../../../../../../base/common/event.js"; import { Disposable } from "../../../../../../base/common/lifecycle.js"; import { IAgentHostResourceUriMapper } from "../../../../../../platform/agentHost/common/agentHostUri.js"; import { IAgentHostConnectionsService } from "../../../../../../platform/agentHost/common/agentHostConnectionsService.service.js"; import { CustomizationEnablementKind, McpServerCustomization, type Customization, type CustomizationEnablement, type PluginCustomization, type RootConfigState } from "../../../../../../platform/agentHost/common/state/protocol/state.js"; import { AgentCustomization, type ISessionFolderPickerDecision } from "../../../../../../platform/agentHost/common/state/sessionState.js"; import { IInstantiationService } from "../../../../../../platform/instantiation/common/instantiation.js"; import { IMcpServerConfiguration } from "../../../../../../platform/mcp/common/mcpPlatformTypes.js"; import { IConfigurationService } from "../../../../../../platform/configuration/common/configuration.service.js"; import { ILogService } from "../../../../../../platform/log/common/log.service.js"; import { INotificationService } from "../../../../../../platform/notification/common/notification.service.js"; import { IChatService } from "../../../common/chatService/chatService.service.js"; import type { IAgentFileToolInventoryEntry } from "../../../common/customizationHarnessService.js"; import { IAgentHostUntitledProvisionalSessionService } from "./agentHostUntitledProvisionalSessionService.service.js"; import { IAgentHostActiveClientService } from "./agentHostActiveClientService.service.js"; import { IAgentHostMcpServer } from "../../../../../../platform/agentHost/common/agentHostMcpServer.js"; import { type IAgentHostAuthenticateRequest } from "./agentHostAuth.js"; import { IMcpService } from "../../../../mcp/common/mcpTypes.service.js"; import { IAgentHostCustomizationService } from "./agentHostCustomizationService.service.js"; export declare function getMcpServerDisplayLabel(server: Pick): string; export declare class NullAgentHostCustomizationService implements IAgentHostCustomizationService { readonly _serviceBrand: undefined; readonly onDidChangeCustomAgents: Event; readonly onDidChangeCustomizations: Event; getAgentFileToolInventory(_sessionResource: URI): readonly IAgentFileToolInventoryEntry[] | undefined; getCustomAgents(_sessionResource: URI): readonly AgentCustomization[]; getClientPluginUri(_sessionResource: URI, _plugin: Pick): URI | undefined; getCustomizations(_sessionResource: URI): readonly Customization[]; whenCustomizationsReady(_sessionResource: URI, _token?: CancellationToken): Promise; getFolderPickerDecision(_sessionResource: URI): ISessionFolderPickerDecision | undefined; getWorkingDirectory(sessionResource: URI): string | undefined; getWorkingDirectories(_sessionResource: URI): readonly string[]; getClientWorkingDirectoryUris(_sessionResource: URI): readonly URI[]; getMcpServers(_sessionResource: URI): readonly IAgentHostMcpServer[]; addMcpServer(_sessionResource: URI, _name: string, _config: IMcpServerConfiguration): void; authenticateMcpServer(_sessionResource: URI, _serverId: string): Promise; setCustomizationEnablement(_sessionResource: URI, _customizationId: string, _currentEnablement: readonly CustomizationEnablement[] | undefined, _kind: CustomizationEnablementKind, _enabled: boolean): void; showMcpServerLog(_sessionResource: URI, _serverId: string, beforeShow?: () => Promise): Promise; } export interface IAgentHostCustomizationTarget { readonly backendSession: URI; readonly clientId?: string; readonly customizations: readonly Customization[]; readonly resourceUris: IAgentHostResourceUriMapper; readonly folderPickerDecision?: ISessionFolderPickerDecision; readonly workingDirectory?: string; /** Host-space session roots used in protocol enablement decisions. */ readonly workingDirectories?: readonly string[]; /** Client-space roots, including provisional roots. */ readonly clientWorkingDirectories?: readonly URI[]; readonly rootConfig?: RootConfigState; isBundledMcpServer(pluginUri: string, serverName: string): boolean; authenticate(request: IAgentHostAuthenticateRequest): Promise; handleMcpRequest?(channel: string, method: string, params: Record | undefined): Promise; setCustomizationEnablement(rawId: string, enablement: readonly CustomizationEnablement[]): void; startMcpServer(rawId: string): Promise; stopMcpServer(rawId: string): Promise; backgroundMcpServer(rawId: string): Promise; setRootConfigValue(property: string, value: unknown): void; } export declare abstract class AbstractAgentHostCustomizationService extends Disposable implements IAgentHostCustomizationService { protected readonly _instantiationService: IInstantiationService; protected readonly _logService: ILogService; private readonly _notificationService; readonly _serviceBrand: undefined; private readonly _onDidChangeCustomAgents; private readonly _onDidChangeCustomizations; readonly onDidChangeCustomAgents: Event; readonly onDidChangeCustomizations: Event; private readonly _mcpLogRegistry; /** * Sessions whose MCP diagnostics we mirror into per-server Output channels. * A session is tracked once the user reveals a server's output; from then * on every state change is recorded via {@link onDidChangeCustomizations}, * so subsequent failures and recoveries land in the channel history. */ private readonly _mcpDiagnosticSessions; private readonly _mcpAutoAuthentication; private _copilotConnectorAuthorizationInstance; private readonly _mcpAuthenticationVerifications; /** Bounds how long Sign In waits for a server to leave the authentication-required state. */ protected _mcpAuthenticationVerificationTimeoutMs: number; protected constructor(_instantiationService: IInstantiationService, _logService: ILogService, _notificationService: INotificationService); protected abstract _resolveTarget(sessionResource: URI): IAgentHostCustomizationTarget | undefined; getCustomAgents(sessionResource: URI): readonly AgentCustomization[]; getCustomizations(sessionResource: URI): readonly Customization[]; /** * Targets resolved by this base are backed by already-materialized provider * state, so a snapshot is available as soon as the target resolves. */ whenCustomizationsReady(_sessionResource: URI, _token?: CancellationToken): Promise; getFolderPickerDecision(sessionResource: URI): ISessionFolderPickerDecision | undefined; getWorkingDirectory(sessionResource: URI): string | undefined; getWorkingDirectories(sessionResource: URI): readonly string[]; getClientWorkingDirectoryUris(sessionResource: URI): readonly URI[]; getClientPluginUri(sessionResource: URI, plugin: Pick): URI | undefined; getMcpServers(sessionResource: URI): readonly IAgentHostMcpServer[]; private _isAutoAuthenticatingMcpServer; private _reconcileMcpAutoAuthenticationAttempts; private _updateMcpAutoAuthenticationAttempt; private _mcpAuthenticationChallenge; showMcpServerLog(sessionResource: URI, serverId: string, beforeShow?: () => Promise): Promise; /** * Registers `sessionResource` for MCP diagnostics mirroring and records the * currently-observed state of each of its servers. Idempotent: registering * an already-tracked session simply re-records (dedup'd by state signature). */ private _trackMcpDiagnostics; /** Re-records every tracked session's MCP server states (on any customizations change). */ private _recordMcpDiagnostics; /** Stops mirroring and disposes all MCP diagnostics channels for a session that is going away. */ protected _disposeMcpDiagnostics(sessionResource: URI): void; addMcpServer(sessionResource: URI, name: string, config: IMcpServerConfiguration): void; authenticateMcpServer(sessionResource: URI, serverId: string): Promise; /** * Authorizes Copilot Connectors for the session account, rebinds the session credential that Connector-owned * servers use, and restarts the Connector. Never creates a narrow session or forwards an MCP token. */ private _authorizeCopilotConnectorMcpServer; /** Created on first use, so hosts without Copilot Connectors never resolve its services. */ private get _copilotConnectorAuthorization(); private _reportMcpAuthenticationOutcome; /** * Observes a server until it settles after authentication. Until {@link IMcpAuthenticationVerification.settle} * the host may still be applying the authentication, so only readiness is conclusive. Afterwards a server that * restarted and asks for the same authentication again rejected it; an unchanged challenge without a restart * keeps waiting, because the host can defer applying it. Connector-owned servers can restart and fail again * with the same credential, so they report success only once ready. */ private _verifyMcpAuthentication; setCustomizationEnablement(sessionResource: URI, customizationId: string, currentEnablement: readonly CustomizationEnablement[] | undefined, kind: CustomizationEnablementKind, enabled: boolean): void; private _workspaceEnablementEntry; protected _fireCustomAgentsChanged(): void; protected _fireCustomizationsChanged(): void; private _findMcpServer; private _findCustomization; protected _scopedMcpServerId(sessionResource: URI, rawId: string): string; private _isScopedMcpServerIdForRawId; } /** One MCP server customization, with the position it was published at. */ export interface IMcpServerCustomizationEntry { readonly server: McpServerCustomization; /** * The plugin that declares this server. Absent both for a server published at the top level * and for one declared by a {@link CustomizationType.Directory} container, so it says nothing * about where in the tree the server sits -- use {@link isTopLevel} for that. */ readonly plugin?: PluginCustomization; /** Whether the agent host published this server as a customization of the session itself. */ readonly isTopLevel: boolean; } /** Every MCP server customization in a session, including duplicates of the same server. */ export declare function flattenMcpServerCustomizations(customizations: readonly Customization[]): readonly IMcpServerCustomizationEntry[]; /** * The MCP servers to *show* for a session: one entry per server. * * A session can carry two customizations for one server: the declaration, published as a child of * whatever declared it, and a top-level entry the agent host mints for a server the SDK reports * before that child resolves by name. A child is dropped when a top-level customization already * speaks for its name, because the top-level copy is the one the host keeps live and resolves for * lifecycle and enablement. * * Tree position is the signal, not the shape of the minted id and not the absence of an owning * plugin -- a directory-declared child has none either. Only presentation dedupes; lookups * elsewhere walk every customization, so an id from either copy still resolves. Servers of the * same name from different containers are left alone, because they are different servers. */ export declare function getPresentableMcpServerCustomizations(customizations: readonly Customization[]): readonly IMcpServerCustomizationEntry[]; export declare class WorkbenchAgentHostCustomizationService extends AbstractAgentHostCustomizationService { private readonly _connectionsService; private readonly _provisionalSessionService; private readonly _chatService; private readonly _activeClientService; private readonly _mcpService; private readonly _configurationService; private readonly _sessionStateSubscriptions; constructor(_connectionsService: IAgentHostConnectionsService, _provisionalSessionService: IAgentHostUntitledProvisionalSessionService, instantiationService: IInstantiationService, logService: ILogService, _chatService: IChatService, _activeClientService: IAgentHostActiveClientService, _mcpService: IMcpService, _configurationService: IConfigurationService, notificationService: INotificationService); private _syncClientMcpEnablement; protected _resolveTarget(sessionResource: URI): IAgentHostCustomizationTarget | undefined; /** * Session state arrives asynchronously over the protocol, so a freshly * created subscription reports `undefined` until its first snapshot lands. * * The wait is memoized per subscription so that callers can apply their own * cancellation or timeout policy without affecting other consumers. */ whenCustomizationsReady(sessionResource: URI, token?: CancellationToken): Promise; getAgentFileToolInventory(sessionResource: URI): readonly IAgentFileToolInventoryEntry[] | undefined; getBackendChatResource(sessionResource: URI): URI | undefined; private _awaitFirstSnapshot; private _ensureSessionStateSubscription; /** * Resolves a chat session resource to the backend agent-session URI plus * the {@link IAgentConnection} (local or remote) that owns it. Returns * `undefined` for sessions not backed by an agent host. */ private _resolveSessionTarget; private _isDisabledByPolicy; }