import { CancellationToken } from "../../base/common/cancellation.js"; import { Event } from "../../base/common/event.js"; import { IObservable, IReader } from "../../base/common/observable.js"; import { ThemeIcon } from "../../base/common/themables.js"; import { URI } from "../../base/common/uri.js"; import { IAgentHostMcpServer } from "../../platform/agentHost/common/agentHostMcpServer.js"; import type { AgentMergeSessionOverrides, AgentMergeSessionState } from "../../platform/agentHost/common/agentMerge.js"; import { AuthenticateParams, AuthenticateResult, IAgentConnection } from "../../platform/agentHost/common/agentService.js"; import { RemoteAgentHostConnectionStatus } from "../../platform/agentHost/common/remoteAgentHostService.js"; import { ResolveSessionConfigResult, SessionConfigValueItem } from "../../platform/agentHost/common/state/protocol/commands.js"; import { AgentCustomization, Customization, RootConfigState, type CustomizationEnablement, type RootState } from "../../platform/agentHost/common/state/protocol/state.js"; import { ISessionConfigProvider, ISessionsProvider } from "../services/sessions/common/sessionsProvider.js"; import { ISessionAgentRef } from "../services/sessions/common/session.js"; import type { ISessionSandboxPolicy } from "../../platform/agentHost/common/meta/agentSandboxPolicyMeta.js"; export { IAgentHostMcpServer }; /** * Progress emitted while an agent-host provider is establishing a connection. */ export interface IAgentHostConnectProgress { readonly connectionKey: string; readonly message: string; } /** Agent Merge state that affects client-side presentation. */ export interface IAgentMergeClientState { readonly enabled: boolean; readonly overrides?: AgentMergeSessionOverrides; } /** * Opt-in policy offered on a remote host's recovery surface: when enabled, * opening a chat whose host is not running starts the host instead of * waiting for the user to click. Scoped to the host *kind* rather than an * individual host, so the label names the kind ("WSL", not "Ubuntu-24.04") * and toggling it from any one host applies to all hosts of that kind. * Providers choose how the value is backed. */ export interface IAgentHostAutoConnect { /** Checkbox label, e.g. "Automatically Start WSL When Opening Chats". */ readonly label: string; readonly enabled: IObservable; setEnabled(enabled: boolean): void; } /** Localized labels shared by connection banners and recovery screens. */ export interface IAgentHostConnectionLabels { readonly unavailableTitle: string; readonly unavailableDescription?: string; readonly unavailable: string; readonly connectingTitle: string; readonly connectingDescription?: string; readonly connecting: string; readonly reconnecting: string; reconnectingIn(seconds: number): string; readonly incompatibleTitle: string; readonly incompatible: string; } export declare function getAgentHostConnectionStatusLabel(status: RemoteAgentHostConnectionStatus): string; /** * Declares that a provider is one of many interchangeable members of a single * user-facing host. Members collapse into one `IAgentHostFilterEntry` that * scopes the sessions list to all of them; hosts that are a place of their own * (a tunnel machine, a WSL distro, an SSH target) leave this undefined. */ export interface IAgentHostGroup { /** Stable id shared by every member, and the filter key of the collapsed entry. */ readonly id: string; /** Display name of the collapsed entry (e.g. "Cloud"). */ readonly label: string; /** Icon for the collapsed entry. Falls back to the generic remote icon. */ readonly icon?: ThemeIcon; /** * Sort rank of the collapsed entry among host filter entries; lower comes * first. Ungrouped hosts rank `0`. Defaults to `0`. */ readonly order?: number; /** * Whether the collapsed entry offers a manual connect/disconnect toggle. * `false` for groups whose members connect implicitly. Defaults to `true`. */ readonly connectable?: boolean; /** Provider that creates new environments for this group, without requiring an existing connection. */ readonly sessionCreationProviderId?: string; } /** A tool reported by an agent-host MCP server's `tools/list`. */ export type AgentHostMcpTool = { readonly name: string; readonly title?: string; readonly description?: string; }; /** * Extended sessions provider for agent host providers (local and remote). * Adds remote connection properties and dynamic session configuration. */ export interface IAgentHostSessionsProvider extends ISessionsProvider { /** Connection status observable, present on remote providers. */ readonly connectionStatus?: IObservable; /** Progress messages during on-demand connect. */ readonly onDidReportConnectProgress?: Event; /** Opens this host's connection log, including while connecting. */ readonly showConnectionLog?: () => Promise; /** Remote address string, present on remote providers. */ readonly remoteAddress?: string; /** * Set when this provider is one member of a larger user-facing host (see * {@link IAgentHostGroup}). Members share one host filter entry instead of * getting one each. */ readonly hostGroup?: IAgentHostGroup; /** * Stable preference key used to persist/read a * {@link IRemoteAgentHostLocationPreferenceService} choice for this * host, present on remote providers. Distinct from {@link remoteAddress} * for SSH hosts, whose live address is a forwarded local endpoint (e.g. * `localhost:4321`) rather than the stable `ssh:` (or * `user@host:port`) key `computeSSHConnectionKey()` and * `SSHRemoteAgentHostService` key preferences by. Providers with no * separate stable identity (tunnels, WSL, cloud sandbox) may omit this; * consumers should fall back to {@link remoteAddress}. */ readonly remoteLocationPreferenceKey?: string; /** * Establish (or re-establish) the connection for this host on demand. * Tears down any existing connection first. Present on remote providers * that manage their own transport (e.g. tunnel relay); providers that * use the generic {@link IRemoteAgentHostService} reconnect flow may * leave this undefined. */ connect?(): Promise; /** * Tear down the active connection for this host without forgetting the * entry. A subsequent {@link connect} call should be able to re-establish * it. Present on remote providers that manage their own transport. */ disconnect?(): Promise; /** Permanently remove this host from the user-visible host inventory. */ remove?(): Promise; /** False when the host inventory is owned externally and cannot be removed locally. */ readonly canRemove?: boolean; /** Inventory-owned local labels may reject a rename after this provider's lifetime ends. */ setDisplayName?(name: string | undefined): void; /** * Skips a pending reconnect backoff and retries at once. Present on remote * providers whose transport is restored by a protocol client. */ reconnectNow?(): void; /** * Kind-scoped auto-start policy surfaced on the recovery screen. Present * on remote providers whose host can be started locally; omitted where * starting is not something VS Code can do. */ readonly autoConnect?: IAgentHostAutoConnect; /** Optional labels for providers whose display name does not name the host. */ readonly connectionLabels?: IAgentHostConnectionLabels; readonly hostDescription?: IObservable; /** Availability before applying a user's hidden preference. Defaults to available. */ readonly isAvailableInEnvironmentPicker?: IObservable; /** Controls environment and workspace picker visibility without withdrawing existing sessions. Defaults to visible. */ readonly isVisibleInEnvironmentPicker?: IObservable; /** Reveals this host after an explicit picker selection without changing its availability. */ showInEnvironmentPicker?(): void; readonly removeLabel?: string; readonly disconnectLabel?: string; /** * When `true`, the workspace picker keeps this provider's browse * action(s) enabled even while {@link connectionStatus} reports * `disconnected` — the assumption being that clicking the action * itself triggers a connect attempt (e.g. booting a stopped WSL * distro). The `incompatible` state is still treated as unavailable * because the user can't recover from it via a click. */ readonly canConnectOnDemand?: boolean; /** Source workspace for a container-backed provider, retained while disconnected or restored. */ readonly devContainerSourceWorkspace?: URI; /** Fires when Dev Container workspace availability should be checked again. */ readonly onDidChangeDevContainerAvailability?: Event; /** Whether this workspace supports Dev Container execution. */ isDevContainerWorkspaceAvailable?(workspaceUri: URI): Promise; /** Whether this draft's workspace supports Dev Container execution. */ isDevContainerAvailable?(sessionId: string): boolean; /** Whether this draft should be prepared on a Dev Container Agent Host. */ isDevContainerEnabled?(sessionId: string): boolean; /** Whether this draft has selected Dev Container execution, including pending availability. */ isDevContainerRequested?(sessionId: string): boolean; /** Set whether this draft should run on a Dev Container Agent Host. */ setDevContainerEnabled?(sessionId: string, enabled: boolean): void; /** Enable Dev Container execution once availability resolves. Required selections fail rather than falling back to the host. */ preferDevContainer?(sessionId: string, options?: { readonly required?: boolean; }): void; /** Fires when dynamic configuration for a session changes. */ readonly onDidChangeSessionConfig: Event; /** Returns the last resolved dynamic configuration of a session's chat: the session's, with the chat's own values applied. */ getSessionConfig(sessionId: string, chat: URI): ResolveSessionConfigResult | undefined; /** Returns the session's own configuration, which {@link replaceSessionConfig} edits: the values of its chats that set none of their own. */ getSessionOwnConfig(sessionId: string): ResolveSessionConfigResult | undefined; /** Waits for a draft's authentication and configuration resolution, rejecting if configuration is unavailable. */ whenSessionConfigResolved(sessionId: string, token: CancellationToken): Promise; /** Canceled when the draft is disposed, including when its provider disconnects. */ getNewSessionCancellationToken(sessionId: string): CancellationToken; /** Effective runtime sandbox policy, refreshed with session configuration notifications. */ getSessionSandboxPolicy?(sessionId: string): ISessionSandboxPolicy | undefined; /** Last sandbox enablement successfully applied by the host for a session's chat. */ getSessionSandboxEnabled?(sessionId: string, chat: URI): boolean | undefined; /** Whether the latest sandbox configuration change for a session's chat failed to apply. */ hasSessionSandboxChangeError?(sessionId: string, chat: URI): boolean; /** Whether a rejected sandbox selection of a session's chat should remain visible during rollback synchronization. */ hasSessionSandboxRejectedSelection?(sessionId: string, chat: URI): boolean; /** Docker prerequisites for sandboxing, undefined when the session does not target a known container. */ getDevContainerSandboxSupported?(sessionId: string): boolean | undefined; /** * Observable: `true` while a `resolveSessionConfig` round-trip is in * flight. Pickers gate on this rather than `session.loading` so they * stay interactive in the required-values-missing state. */ isSessionConfigResolving(sessionId: string, chat: URI): IObservable; /** Sets one dynamic configuration property, for the chat when the chat may set it for itself, and re-resolves the schema. */ setSessionConfigValue(sessionId: string, chat: URI, property: string, value: unknown): Promise; /** Tracks a draft configuration side effect that must finish before the first request. */ trackSessionConfigOperation(sessionId: string, operation: Promise): void; /** * Replaces the full set of running-session config values atomically. * * Dispatches a single `session/configChanged` action with replace * semantics. Only user-editable properties (`sessionMutable: true` and * not `readOnly`) are actually replaced from the caller-supplied values — * for every other property the current value is carried through, so * non-mutable / read-only properties (e.g. `isolation`, `branch`) can * never be altered through this API even if included in the input. * Unknown keys (no schema entry) are ignored. * * No-op for pre-creation (new) sessions — use {@link setSessionConfigValue} * there since the schema is still being resolved. */ replaceSessionConfig(sessionId: string, values: Record): Promise; /** Returns dynamic completions; new-session branch lists reuse the request started when their workspace was selected. */ getSessionConfigCompletions(sessionId: string, property: string, query?: string): Promise; /** Returns the resolved config that should be sent to createSession. */ getCreateSessionConfig(sessionId: string): Record | undefined; /** Clears dynamic configuration state for an abandoned new session. */ clearSessionConfig(sessionId: string): void; /** * Returns the persisted Agent Merge state of a running session's folder. * Each folder a chat works in has its own Agent Merge; pass `chat` for the * folder it works in, or omit it for the session folder (the main chat's). */ getAgentMergeSessionState(sessionId: string, chat?: URI): AgentMergeSessionState | undefined; /** Returns observable Agent Merge client state of a folder (see {@link getAgentMergeSessionState}) while retaining the required session subscription. */ getAgentMergeClientStateObservable(sessionId: string, chat?: URI): IObservable; /** Enables or disables Agent Merge for a folder (see {@link getAgentMergeSessionState}) while preserving its action overrides. */ setAgentMergeEnabled(sessionId: string, enabled: boolean, chat?: URI): Promise; /** Replaces a folder's Agent Merge action overrides (see {@link getAgentMergeSessionState}); `undefined` follows global defaults. */ setAgentMergeOverrides(sessionId: string, overrides: AgentMergeSessionOverrides | undefined, chat?: URI): Promise; /** Fires when the root (agent host) configuration schema or values change. */ readonly onDidChangeRootConfig: Event; /** Returns the last-known root (agent host) configuration, or `undefined` if the host has not published any. */ getRootConfig(): RootConfigState | undefined; getRootState(): RootState | undefined; mapAgentHostResource(uri: URI): URI; /** This window's client identity on the provider's connection. */ getClientId?(): string | undefined; /** * Sets one root configuration property. * * Optimistically updates local state and dispatches a * `root/configChanged` action (non-replace) to the agent host. */ setRootConfigValue(property: string, value: unknown): Promise; /** * Replaces the full set of root configuration values atomically. * * Dispatches a single `root/configChanged` action with replace semantics. * Unknown keys (no schema entry) are ignored. */ replaceRootConfig(values: Record): Promise; /** Authenticate against the backing agent-host connection. */ authenticate(params: AuthenticateParams): Promise; /** * Fires when the effective custom-agent set for any session may have * changed (root state customizations or per-session customizations * updated). The event has no payload — consumers re-read via * {@link getCustomAgents}. */ readonly onDidChangeCustomAgents: Event; /** * Returns the merged, de-duped custom-agent list a session should see, * computed from root, active-client, and session customizations. Returns * an empty array when the session is unknown or no agents have been * advertised. */ getCustomAgents(sessionId: string): readonly AgentCustomization[]; /** Resolves a draft source or advertised URI to its current published agent, when known. */ resolveCustomAgent?(sessionId: string, uri: string): AgentCustomization | undefined; readonly onDidChangeCustomizations: Event; /** * Returns the full set of customizations. */ getCustomizations(sessionId: string): readonly Customization[]; /** * Returns the host-provided working directory, tracking updates when a reader is supplied. */ getWorkingDirectory(sessionId: string, reader?: IReader): string | undefined; /** * Returns the full ordered set of working-directory roots for the session * (index 0 = primary), or an empty array when none are known. */ getWorkingDirectories(sessionId: string): readonly string[]; /** * Returns the MCP servers exposed by the session as rich objects whose * methods dispatch protocol-level toggle and lifecycle actions. * Returns an empty array when the session is unknown or exposes no MCP * servers. */ getMcpServers(sessionId: string): readonly IAgentHostMcpServer[]; /** Replaces an agent-host customization's explicit enablement decisions. */ setCustomizationEnablement(sessionId: string, customizationId: string, enablement: readonly CustomizationEnablement[]): void; /** * Set (or clear) the selected custom agent for a session. Optional so * providers that don't expose custom agents can omit it. * @param sessionId The ID of the session. * @param agent The agent to select, or `undefined` to clear the selection * and use the provider's default behavior. */ setAgent?(sessionId: string, agent: ISessionAgentRef | undefined): void; /** * Returns the agent-host annotations channel for a session so that * sessions-layer features (e.g. agent feedback) can subscribe to and * dispatch annotation actions against the session's * `/annotations` channel. Returns `undefined` when the * session is unknown or the host connection is unavailable. */ getFeedbackAnnotationsChannel(sessionId: string): { readonly connection: IAgentConnection; readonly annotationsUri: URI; } | undefined; /** Sends a request on an `mcp://` AHP side channel of this host's connection. */ handleMcpRequest?(channel: string, method: string, params: Record | undefined): Promise; /** * Resolves the sessions-window client chat resource ({@link IChat.resource}) * to the opaque **backend** chat URI the host uses on the wire (the value * carried on `MessageChatAttachment.resource`). Used to fill the chat-reference * drag payload with the backend URI a `#chat:` reference must carry. * * This is a pure **lookup** of host-supplied data (the authoritative * `ChatSummary.resource` / `SessionState.defaultChat` the provider already * receives), not a construction, so callers never derive an AHP chat URI. * Returns `undefined` when the session's state has not been hydrated (e.g. the * chat is not currently backed by known state), in which case the caller omits * the chat-reference payload. */ getBackendChatResource(chatResource: URI): URI | undefined; /** Returns the host-advertised session URI owning this session's customizations. */ getBackendSessionResource(sessionId: string): URI | undefined; } export declare const LOCAL_AGENT_HOST_PROVIDER_ID = "local-agent-host"; export declare const REMOTE_AGENT_HOST_PROVIDER_PREFIX = "agenthost-"; export declare const REMOTE_AGENT_HOST_PROVIDER_RE: RegExp; export declare const ANY_AGENT_HOST_PROVIDER_RE: RegExp; /** * Checks whether a provider is an agent host provider based on its * reserved provider ID (`local-agent-host` or `agenthost-*` prefix). */ export declare function isAgentHostProvider(provider: ISessionsProvider): provider is IAgentHostSessionsProvider; /** Whether this provider can appear as an individual remote environment, independent of visibility. */ export declare function isRemoteSessionCreationEnvironment(provider: ISessionsProvider): provider is IAgentHostSessionsProvider & { readonly connectionStatus: IObservable; }; /** Legacy providers may express availability through their visibility signal alone. */ export declare function isAgentHostEnvironmentAvailable(provider: IAgentHostSessionsProvider, reader?: IReader): boolean; export declare function getSessionConfigProvider(provider: ISessionsProvider): ISessionConfigProvider | undefined; /** * Checks whether a provider ID is for an agent host provider * (`local-agent-host` or any `agenthost-*` provider). */ export declare function isAgentHostProviderId(providerId: string): boolean; /** * Structural equality for resolved session configs. Returns true when both * inputs have the same value-key set with deep-equal values and the same set * of schema property keys with identical (by-identity) property objects. * Schema property objects are compared by identity since they originate from * the same protocol snapshot in the providers that use this helper. Values * are deep-compared via {@link equals} so non-string entries (e.g. permission * objects) compare correctly. */ export declare function resolvedConfigsEqual(a: ResolveSessionConfigResult, b: ResolveSessionConfigResult): boolean; type MutableConfigSchemaItem = { type: "string"; title: string; sessionMutable: true; enum: string[]; } | { type: "number"; title: string; sessionMutable: true; } | { type: "boolean"; title: string; sessionMutable: true; } | { type: "array"; title: string; sessionMutable: true; } | { type: "object"; title: string; sessionMutable: true; }; /** * Builds a minimal session-mutable config schema from changed values. * Used when a restored session receives a ConfigChanged action before * the full schema has been hydrated. Properties whose value type isn't * representable in the config schema (e.g. `null`, `undefined`) are * omitted. */ export declare function buildMutableConfigSchema(config: Record): Record;