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 { type AgentHostUriMapper } from "../../../../../platform/agentHost/common/agentHostUri.js"; import { type IAgentSessionMetadata } from "../../../../../platform/agentHost/common/agent.js"; import { type IAgentConnection } from "../../../../../platform/agentHost/common/agentService.js"; import { IAgentHostService } from "../../../../../platform/agentHost/common/agentService.service.js"; import { type IAgentHostSessionSchemeAlias } from "../../../../../platform/agentHost/common/agentHostConnectionsService.js"; import { IAgentHostConnectionsService } from "../../../../../platform/agentHost/common/agentHostConnectionsService.service.js"; import { ChangesetKind } from "../../../../../platform/agentHost/common/changesetUri.js"; import { RemoteAgentHostConnectionStatus } from "../../../../../platform/agentHost/common/remoteAgentHostService.js"; import { IRemoteAgentHostService } from "../../../../../platform/agentHost/common/remoteAgentHostService.service.js"; import { type ISessionGitState } from "../../../../../platform/agentHost/common/state/sessionState.js"; import { IConfigurationService } from "../../../../../platform/configuration/common/configuration.service.js"; import { IFileDialogService } from "../../../../../platform/dialogs/common/dialogs.service.js"; import { IDialogService } from "../../../../../platform/dialogs/common/dialogs.service.js"; import { IWorkspaceTrustManagementService } from "../../../../../platform/workspace/common/workspaceTrust.service.js"; import { IInstantiationService } from "../../../../../platform/instantiation/common/instantiation.js"; import { ILabelService } from "../../../../../platform/label/common/label.service.js"; import { ILogService } from "../../../../../platform/log/common/log.service.js"; import { INotificationService } from "../../../../../platform/notification/common/notification.service.js"; import { IStorageService } from "../../../../../platform/storage/common/storage.service.js"; import { ITelemetryService } from "../../../../../platform/telemetry/common/telemetry.service.js"; import { IUriIdentityService } from "../../../../../platform/uriIdentity/common/uriIdentity.service.js"; import { IAgentHostActiveClientService } from "../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/agentHostActiveClientService.service.js"; import { IAgentHostMcpAppToolsService } from "../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/agentHostMcpAppToolsService.service.js"; import { IAgentHostSessionWorkingDirectoryResolver } from "../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionWorkingDirectoryResolver.service.js"; import { IRemoteAgentHostAuthenticationService } from "../../../../../workbench/contrib/chat/browser/remoteAgentHost/remoteAgentHostAuthentication.service.js"; import { IChatWidgetService } from "../../../../../workbench/contrib/chat/browser/chat.service.js"; import { IChatService } from "../../../../../workbench/contrib/chat/common/chatService/chatService.service.js"; import { IChatSessionsService } from "../../../../../workbench/contrib/chat/common/chatSessionsService.service.js"; import { ILanguageModelsService } from "../../../../../workbench/contrib/chat/common/languageModels.service.js"; import { IAgentHostAutoConnect, IAgentHostConnectProgress, IAgentHostConnectionLabels, IAgentHostGroup } from "../../../../common/agentHostSessionsProvider.js"; import { IGitHubInfo, IChat, ISession, ISessionEnvironment, ISessionType, ISessionWorkspace, ISessionWorkspaceBrowseAction } from "../../../../services/sessions/common/session.js"; import { ISessionsService } from "../../../../services/sessions/browser/sessionsService.service.js"; import { ISessionsRecentWorkspacesService } from "../../../../services/sessions/browser/sessionsRecentWorkspacesService.service.js"; import { IGitHubService } from "../../../github/browser/githubService.service.js"; import { DevContainerAgentHostSessionsProvider } from "../../agentHost/browser/devContainerAgentHostSessionsProvider.js"; import type { AgentHostSessionAdapter } from "../../agentHost/browser/baseAgentHostSessionsProvider.js"; import type { INestedChatFolderInfo, INestedChatWorkspace, ISendRequestOptions, ISessionsProviderAutomations, SessionResourceResolveReason, ICreateNewChatOptions } from "../../../../services/sessions/common/sessionsProvider.js"; import { INewSessionComposerService } from "../../../chat/browser/newSessionComposerService.service.js"; export interface IRemoteAgentHostSessionsProviderConfig { readonly address: string; readonly name: string; /** * Stable preference key for this host (see * {@link IAgentHostSessionsProvider.remoteLocationPreferenceKey}), when * it differs from {@link address} — e.g. an SSH host's * `computeSSHConnectionKey()` result versus its live forwarded address. * Defaults to {@link address} when omitted. */ readonly preferenceKey?: string; /** Optional hook to establish a connection on demand (e.g. tunnel relay). */ readonly connectOnDemand?: () => Promise; /** Optional hook to tear down the active connection on demand (e.g. tunnel relay). */ readonly disconnectOnDemand?: () => Promise; /** Optional hook to permanently remove the host from its provider inventory. */ readonly removeOnDemand?: () => Promise; readonly canRemove?: boolean; readonly setDisplayName?: (name: string | undefined) => void; /** Account-scoped inventory owners isolate cached summaries without changing routing identity. */ readonly sessionCacheKey?: string; readonly retainSessionsOnDisconnect?: boolean; /** Optional owner-managed deletion for exact backend resources, working without a host connection. */ readonly deleteSessionsOnDemand?: { ownsSession(session: URI): boolean; deleteSessions(sessions: readonly URI[]): Promise; }; /** Optional progress messages during on-demand connect. */ readonly onDidReportConnectProgress?: Event; readonly showConnectionLog?: () => Promise; /** Optional kind-scoped policy for automatically starting the host. */ readonly autoConnect?: IAgentHostAutoConnect; readonly connectionLabels?: IAgentHostConnectionLabels; readonly hostDescription?: IObservable; readonly isVisibleInEnvironmentPicker?: IObservable; /** Overrides the stable host key for account-scoped picker preferences. */ readonly pickerVisibilityKey?: string; readonly removeLabel?: string; readonly disconnectLabel?: string; /** * Set when the host addresses sessions under a scheme that differs from its agent provider, as * the cloud sandbox host does (sessions are `ahp-session:/` while the agent is `copilot`). * The provider derives both directions from this pair, so they cannot drift apart. */ readonly sessionSchemeAlias?: IAgentHostSessionSchemeAlias; /** * Suppresses the `[host]` suffix that otherwise disambiguates this host's workspaces from * identically-named ones on other hosts. Set by hosts whose label names a task rather than a * location, where the suffix would put every session in a workspace group of one. */ readonly omitHostFromWorkspaceLabel?: boolean; /** Type icon for this host's workspaces. See {@link ISessionWorkspace.typeIcon}. */ readonly workspaceTypeIcon?: ThemeIcon; /** Keeps unavailable and initially connecting sessions read-only, but permits self-healing reconnects. */ readonly readOnlyWhenDisconnected?: boolean; /** See {@link IAgentHostAdapterOptions.defaultChangesetKind}. */ readonly defaultChangesetKind?: ChangesetKind.Branch | ChangesetKind.Uncommitted | ChangesetKind.Session; /** * Marks this connection as one member of a larger user-facing host, so the host filter shows * one entry for the whole group instead of one per connection. See {@link IAgentHostGroup}. */ readonly hostGroup?: IAgentHostGroup; /** Source workspace represented by this Dev Container provider. */ readonly devContainerSourceWorkspaceUri?: URI; readonly devContainerWorktreeScope?: string; /** Controls the stopped/removed container while this runtime provider remains registered. */ readonly devContainerLifecycle?: { connect(): Promise; stop(): Promise; remove(): Promise; }; /** Resolves the source host that owns this container's detached worktree handles. Defaults to the local host. */ readonly resolveDevContainerWorktreeConnection?: () => Promise; } /** * The two names a session goes by when the host's session scheme differs from its agent provider. * The raw session id is shared, so only the scheme is translated. */ /** * Sessions provider for a remote agent host connection. A thin subclass of * {@link DevContainerAgentHostSessionsProvider} that adds the connection-lifecycle * surface (`setConnection`/`clearConnection`), sticky authentication-pending * tracking, the well-known session-type mapping, and a remote folder picker. * * **URI/ID scheme:** * - **rawId** - unique session identifier (e.g. `abc123`), used as the cache key. * - **resource** - `{resourceScheme}:///{rawId}`. The scheme is the unique * per-connection id and routes the chat service to the correct * {@link AgentHostSessionHandler}. * - **sessionType** - the logical session type (e.g. `copilotcli` for copilot * agents, or the per-connection id for other agents). Distinct from the * resource scheme. * - **sessionId** - `{providerId}:{resource}` - the provider-scoped ID used by * {@link ISessionsProvider} methods. * - Protocol operations (e.g. `disposeSession`) use the canonical agent * session URI (`copilot:///abc123`), reconstructed via `AgentSession.uri`. */ export declare class RemoteAgentHostSessionsProvider extends DevContainerAgentHostSessionsProvider { private readonly _fileDialogService; private readonly _notificationService; private readonly _localAgentHostService; private readonly agentHostConnectionsService; private readonly _remoteAgentHostService; private readonly _labelService; private readonly _configurationService; private readonly _newSessionComposerService; private readonly _telemetryService; readonly id: string; private _defaultLabel; /** Configured or discovered name, without the client-local override. */ get defaultLabel(): string; private _label; get label(): string; get environment(): ISessionEnvironment; readonly icon: ThemeIcon; readonly remoteAddress: string; get devContainerSourceWorkspace(): URI | undefined; readonly remoteLocationPreferenceKey: string; readonly hostGroup: IAgentHostGroup | undefined; private _browseActions; get browseActions(): readonly ISessionWorkspaceBrowseAction[]; readonly canConnectOnDemand: boolean; readonly onDidReportConnectProgress: Event | undefined; readonly showConnectionLog?: () => Promise; readonly autoConnect?: IAgentHostAutoConnect; readonly connectionLabels?: IAgentHostConnectionLabels; readonly hostDescription?: IObservable; readonly isAvailableInEnvironmentPicker?: IObservable; readonly isVisibleInEnvironmentPicker?: IObservable; readonly showInEnvironmentPicker: () => void; readonly removeLabel?: string; readonly canRemove?: boolean; readonly disconnectLabel?: string; get automations(): ISessionsProviderAutomations | undefined; readonly setDisplayName?: (name: string | undefined) => void; readonly supportsQuickChats = true; private readonly _automationStore; private readonly _activitySources; private readonly _connectionStatus; private readonly _readOnly; readonly connectionStatus: IObservable; private readonly _environmentIsConnected; protected get remoteConnectionStatus(): IObservable; /** * `true` while we are still resolving and pushing tokens for the host's * `protectedResources`. Defaults to `true` so that sessions surface as * loading until the first authentication pass settles. */ private readonly _authenticationPending; private readonly _effectiveAuthenticationPending; private _authenticationSettled; private readonly _onDidDisconnect; protected get onConnectionLost(): Event; /** * Overridable seam so tests can exercise both the web and non-web * branches of the label/description gating without depending on the * ambient {@link isWeb} constant (the browser test runner always * reports `isWeb === true`). */ protected get isWebPlatform(): boolean; private _connection; private readonly _passiveRelay; private readonly _allowOfflineDrafts; private _defaultDirectory; private readonly _connectionListeners; private readonly _onDidChangeResourceLabelHomes; private readonly _connectionAuthority; private readonly _connectOnDemand; private readonly _disconnectOnDemand; private readonly _removeOnDemand; private readonly _retainSessionsOnDisconnect; protected readonly _deleteSessionsOnDemand: IRemoteAgentHostSessionsProviderConfig["deleteSessionsOnDemand"]; private readonly _sessionSchemeAlias; private readonly _omitHostFromWorkspaceLabel; private readonly _workspaceTypeIcon; private readonly _defaultChangesetKind; private readonly _devContainerSourceWorkspaceUri; private readonly _devContainerWorktreeScope; private readonly _devContainerLifecycle; private _devContainerIdleSince; private _devContainerIdleCheckRunning; private _devContainerArchiveOperations; private readonly _devContainerIdleScheduler; private readonly _resolveDevContainerWorktreeConnection; /** Storage key used for persisting {@link _sessionCache} snapshots. */ private readonly _storageKey; /** * When `true`, the provider has been marked unreachable and sessions are * hidden from {@link getSessions}, even though {@link _sessionCache} and * persistent storage are retained. Cleared when a new connection is wired * up in {@link setConnection}, at which point the cached entries are * re-announced so the UI can repopulate. */ private _unpublished; private readonly _detachedWorktreeDeletionTasks; private _detachedWorktreeReconciliation; constructor(config: IRemoteAgentHostSessionsProviderConfig, _fileDialogService: IFileDialogService, _notificationService: INotificationService, storageService: IStorageService, _localAgentHostService: IAgentHostService, agentHostConnectionsService: IAgentHostConnectionsService, chatSessionsService: IChatSessionsService, chatService: IChatService, chatWidgetService: IChatWidgetService, languageModelsService: ILanguageModelsService, _remoteAgentHostService: IRemoteAgentHostService, _labelService: ILabelService, _configurationService: IConfigurationService, logService: ILogService, gitHubService: IGitHubService, instantiationService: IInstantiationService, sessionsService: ISessionsService, activeClientService: IAgentHostActiveClientService, mcpAppToolsService: IAgentHostMcpAppToolsService, dialogService: IDialogService, workspaceTrustManagementService: IWorkspaceTrustManagementService, recentWorkspacesService: ISessionsRecentWorkspacesService, uriIdentityService: IUriIdentityService, workingDirectoryResolver: IAgentHostSessionWorkingDirectoryResolver, remoteAuthenticationService: IRemoteAgentHostAuthenticationService, _newSessionComposerService: INewSessionComposerService, _telemetryService: ITelemetryService); archiveSession(sessionId: string): Promise; unarchiveSession(sessionId: string): Promise; createNewChat(chatId: string, prompt?: string, options?: ICreateNewChatOptions): Promise; resolveNestedChatFolder(sessionId: string, chat: URI, folder: URI, token: CancellationToken): Promise; getNestedChatBranches(sessionId: string, chat: URI, folder: URI, query: string, token: CancellationToken): Promise; applyNestedChatWorkspace(sessionId: string, chat: URI, workspace: INestedChatWorkspace, prompt: string): Promise; sendRequest(chatId: string, chatResource: URI, options: ISendRequestOptions): Promise; private _ensureDevContainerConnection; private _setDevContainerSessionArchived; private _scheduleDevContainerStopIfIdle; private _isDevContainerIdle; private _hasUnarchivedDevContainerSession; private _isEmptyDevContainerDraft; private _stopDevContainerIfIdle; deleteSessions(sessionIds: readonly string[]): Promise; protected _onNewSessionAbandoned(sessionId: string, reason: "discarded" | "sendFailed" | "providerDisposed"): void; protected _onBackendSessionRemoved(rawId: string): void; protected _onHostReconciledSessions(rawIds: ReadonlySet): void; private _getDetachedWorktreeHandle; private _setDetachedWorktreeArchived; private _deleteDetachedWorktree; protected get connection(): IAgentConnection | undefined; protected supportsDevContainerWorkspace(workspaceUri: URI): boolean; protected get authenticationPending(): IObservable; protected get passiveRelay(): IObservable; protected get supportsOfflineDrafts(): boolean; /** * Suspend cache-change tracking while sessions are unpublished (offline) so * the on-disk snapshot survives an unreachable host. See * {@link unpublishCachedSessions}. */ protected _shouldTrackSessionCacheChanges(): boolean; protected _adapterOptions(agentProvider: string): { readOnly: IObservable; allowOfflineDrafts: import("../../../../../base/common/observable.js").IObservableWithChange; supportsCanvasPresentation: (agentProvider: string, connection: IAgentConnection | undefined, reader: IReader) => boolean; defaultChangesetKind: ChangesetKind.Branch | ChangesetKind.Uncommitted | ChangesetKind.Session | undefined; useSessionTitleForDefaultChat: boolean; buildWorkspace: (project: IAgentSessionMetadata["project"], workingDirectories: readonly URI[] | undefined, gitHubInfo: IObservable, gitState: ISessionGitState | undefined) => ISessionWorkspace | undefined; }; protected resourceSchemeForProvider(provider: string): string; getSessions(): ISession[]; resolveSessionResource(resource: URI, reason?: SessionResourceResolveReason): Promise; prepareSessionForOpen(_session: ISession, _reason: SessionResourceResolveReason): Promise; protected mapWorkingDirectoryUri(uri: URI): URI; protected mapProjectUri(uri: URI): URI; protected _diffUriMapper(): AgentHostUriMapper; protected _validateBeforeCreate(_sessionType: ISessionType): void; protected _noAgentsErrorMessage(): string; protected _notConnectedSendErrorMessage(): string; /** * Establish (or re-establish) the connection for this host on demand. * Tunnel-backed providers use their relay hook; other providers fall * back to the generic remote agent host reconnect path. */ connect(): Promise; reconnectNow(): void; /** * Tear down the active connection for this host. Tunnel-backed providers * use their relay hook; other providers fall back to the generic remote * agent host disconnect path. Cached sessions are hidden from the UI so * the sessions list reflects the disconnected state; the persisted cache * is retained so sessions can be restored on reconnect. */ disconnect(): Promise; remove(): Promise; /** Update the connection status for this provider. */ setConnectionStatus(status: RemoteAgentHostConnectionStatus): void; /** Refresh the provider's display name and notify picker consumers. */ setLabel(name: string): void; private _updateLabel; /** Seed offline rows, optionally refreshing discovery-owned display metadata and workspace-less intent. */ seedSessions(metas: readonly IAgentSessionMetadata[], options?: { readonly updateExisting?: boolean; readonly workspaceless?: boolean; }): void; protected createAdapter(meta: IAgentSessionMetadata): AgentHostSessionAdapter; protected batchBackendRegistrations(fn: () => T): T; protected registerBackendSession(backendSession: URI, provider: string): void; protected updateAdapter(adapter: AgentHostSessionAdapter, meta: IAgentSessionMetadata): boolean; /** * Reads older sandbox cache rows without dropping their exact backend identity. */ protected _adoptSessionMeta(meta: IAgentSessionMetadata): IAgentSessionMetadata; /** * Sandbox creation retains its host-specific addressing contract. */ protected _backendSessionScheme(agentProvider: string): string; protected _logicalSessionTypeForBackendScheme(backendScheme: string): string; setAuthenticationPending(pending: boolean): void; /** * Wire a live connection to this provider, enabling session operations and folder browsing. */ setConnection(connection: IAgentConnection, defaultDirectory?: string): void; /** * Clear the connection, e.g. when the remote host disconnects. * Retains the provider registration so it remains visible in the UI, * and **preserves** the cached session list so previously loaded * sessions stay visible while we're offline. Callers that know the * host is unreachable should follow up with {@link unpublishCachedSessions}. */ clearConnection(): void; private updateResourceLabelHomes; /** * Hide cached sessions from the UI without discarding them. Called by the * host-tracking contributions when they determine the remote host is * unreachable (tunnel offline or SSH reconnect failed). The in-memory * cache and persisted storage are left intact so the sessions can be * restored if the host comes back online in this session, or on the next * launch. The next {@link setConnection} call re-announces the cached * entries. */ unpublishCachedSessions(): void; protected _formatSessionTypeLabel(agentLabel: string): string; /** * The host name appended to this host's workspace labels, or `undefined` when it would add * nothing — in web the workbench is already scoped to a single host by the host picker. */ private get _workspaceHostLabel(); static buildWorkspace(project: IAgentSessionMetadata["project"], workingDirectories: readonly URI[] | undefined, providerLabel: string | undefined, gitHubInfo: IObservable, gitState: ISessionGitState | undefined, description?: string, branchProtectionPatterns?: readonly string[], typeIcon?: ThemeIcon): ISessionWorkspace | undefined; private _buildWorkspaceFromUri; resolveWorkspace(repositoryUri: URI): ISessionWorkspace | undefined; cloneRepository(repository: URI, token: CancellationToken): Promise; canonicalizeWorkspaceUri(workspaceUri: URI): URI; private _folderBrowseUri; private _browseForFolder; /** * Enumerate subdirectories below {@link _defaultDirectory}, filtered * by a case-insensitive substring query. Backs the inline folder * list rendered by the mobile workspace picker sheet so users can * pick a folder without opening a separate file-dialog. * * The query supports light path navigation: a `/` in the query is * treated as a path delimiter, listing children of `/` * and matching the part after the last slash. So typing `projects/` * drills into the `projects` directory, and `projects/foo` lists * children of `projects` whose name contains `foo`. * * Hidden directories (those starting with `.`) are omitted, results * are sorted by name, and the cancellation token is honored before * and after the network round-trip so stale queries don't surface * after the user has typed more characters. */ private _listRemoteFolders; }