import { CancellationToken, CancellationTokenSource } from "../../../../../base/common/cancellation.js"; import { Disposable, DisposableStore, IDisposable } from "../../../../../base/common/lifecycle.js"; import { IObservable } from "../../../../../base/common/observable.js"; import { URI } from "../../../../../base/common/uri.js"; import { type ICloudSandboxConnectOptions, type ICloudSandboxCreatedSession, type ICloudSandboxCreateSessionRequest, type ICloudSandboxDiscoveryOptions } from "../../../../../platform/agentHost/common/cloudSandboxAgentHost.js"; import { ICloudSandboxAgentHostService } from "../../../../../platform/agentHost/common/cloudSandboxAgentHost.service.js"; import { ICloudSandboxApiService } from "../../../../../platform/agentHost/common/cloudSandboxAgentHost.service.js"; import { ICloudSandboxDraftPreparationService } from "../../../../../platform/agentHost/common/cloudSandboxAgentHost.service.js"; import { type IAgentSessionMetadata } from "../../../../../platform/agentHost/common/agent.js"; import { IAgentConnection } from "../../../../../platform/agentHost/common/agentService.js"; import { RemoteAgentHostConnectionStatus } from "../../../../../platform/agentHost/common/remoteAgentHostService.js"; import { IRemoteAgentHostService } from "../../../../../platform/agentHost/common/remoteAgentHostService.service.js"; import { IConfigurationService } from "../../../../../platform/configuration/common/configuration.service.js"; import { IInstantiationService } from "../../../../../platform/instantiation/common/instantiation.js"; import { ILogService } from "../../../../../platform/log/common/log.service.js"; import { IProgress } from "../../../../../platform/progress/common/progress.js"; import { IStorageService } from "../../../../../platform/storage/common/storage.service.js"; import { IWorkspaceTrustManagementService } from "../../../../../platform/workspace/common/workspaceTrust.service.js"; import { IWorkbenchContribution } from "../../../../common/contributions.js"; import { IChatSessionsService } from "../../common/chatSessionsService.service.js"; import { IChatEntitlementService } from "../../../../services/chat/common/chatEntitlementService.service.js"; import { IHostService } from "../../../../services/host/browser/host.service.js"; import { IRemoteAgentHostConnectionCustomizationService } from "./remoteAgentHostConnectionCustomization.service.js"; import { type CloudSandboxSessionFeedRefresh } from "./cloudSandboxSessionFeed.js"; interface ICloudSandboxDiscoveryRequest extends ICloudSandboxDiscoveryOptions { readonly retry?: boolean; } /** A discovered sandbox environment we can create a provider for. */ export interface ICloudSandboxSessionEnvironment { readonly environmentId: string; readonly eventType?: string; readonly application?: string; readonly sessionId?: string; /** * Mission Control task owning the session. Persisted AHP history is addressed per task, so this * is what makes the conversation readable once the environment is unreachable. */ readonly taskId?: string; readonly name: string; readonly repoName?: string; readonly hasRepository?: boolean; readonly updatedAt?: string; readonly isArchived?: boolean; } /** * The repository a discovered session belongs to, matching the shape the sandbox host reports once * connected so reconnecting does not visibly regroup the session. * * The `https` URI identifies the repository but is not backed by a file system provider, so a * session discovered this way cannot browse its files until it connects. The Agents window reads * a folder of this form, `https://github.com//`, as naming the session's repository * (see `getSessionFolderGitHubRepository`), so it groups with its repository before it connects. */ export declare function discoveredSessionProject(repoName: string | undefined): IAgentSessionMetadata["project"]; /** The window-specific list maintained by shared sandbox discovery and activation. */ export interface ICloudSandboxSessionList extends IDisposable { readonly connectionStatus: IObservable; seedSessions(sessions: readonly IAgentSessionMetadata[], options?: { readonly updateExisting?: boolean; readonly workspaceless?: boolean; }): void; /** Timestamp of a listed or provisional session, or undefined when it is absent. */ getSessionModifiedTime(sessionId: string): number | undefined; setLabel?(label: string): void; setConnection(connection: IAgentConnection, defaultDirectory: string | undefined): void; setConnectionStatus(status: RemoteAgentHostConnectionStatus): void; setSessionArchived(rawId: string, archived: boolean): void; removeDeletedSession?(rawId: string): void; removeTaskOwnership?(rawId: string): void; /** * Record a session this window just provisioned, before the host announces it. Implementations * may withhold it from listings until {@link publishWithheldSession} or the host lists it. */ seedProvisionalSession?(metadata: IAgentSessionMetadata): void; /** Reveal a session seeded by {@link seedProvisionalSession} whose first turn did not dispatch. */ publishWithheldSession?(rawId: string): void; /** Configuration recorded for a provisioned session whose draft had no backend to hold it. */ getProvisionalSessionConfig?(sessionResource: URI): Record | undefined; } /** A sandbox environment this window provisioned and connected to. */ export interface ICloudSandboxProvisionedEnvironment extends ICloudSandboxCreatedSession { readonly address: string; readonly name: string; /** How the session is listed until it is titled: the first line of its prompt. */ readonly title: string; readonly repoNwo: string | undefined; readonly provider: T; } export declare abstract class CloudSandboxSessionContribution extends Disposable implements IWorkbenchContribution { private readonly _cloudSandboxService; protected readonly _apiService: ICloudSandboxApiService; protected readonly _draftPreparationService: ICloudSandboxDraftPreparationService; private readonly _remoteAgentHostService; private readonly _connectionCustomizations; private readonly _configurationService; protected readonly _instantiationService: IInstantiationService; private readonly _chatSessionsService; private readonly _logService; private readonly _chatEntitlementService; private readonly _hostService; private readonly _storageService; private readonly _workspaceTrustManagementService; /** Provider instances keyed by connection address (`cloudsandbox:`). */ protected readonly _providerInstances: Map; private readonly _providerStores; private _persistedInventory; /** Environment metadata keyed by connection address, for on-demand reconnect. */ private readonly _environments; /** Tasks are session-owned: several discovered tasks can share one environment. */ private readonly _sessionEnvironments; /** In-flight connects keyed by address, so concurrent opens share one attempt. */ private readonly _pendingConnects; /** * Addresses being provisioned right now. A task we just created is not yet visible to a * discovery pass that started before it existed, so reconciliation would see a brand-new * environment as one that has vanished and tear it down mid-provision. */ protected readonly _provisioning: Set; /** History-backed providers retained through their first live connection. */ private readonly _historyHandlers; /** * Cancelled when the feature is disabled (or the contribution is disposed), so in-flight * discovery and connects abort instead of committing state after teardown has run. */ protected _enabledCts: CancellationTokenSource; /** Serializes discovery so overlapping triggers can't interleave reconciliation. */ private _discoveryInFlight; private _discoveryQueued; private _queuedDiscoveryRequest; private _taskRefreshInFlight; private _taskRefreshQueued; private readonly _pendingTaskIds; private _discoveryToken; private _discoveryIncremental; private _lastDiscoveryAttempt; private _lastFullDiscovery; private _discoveryRetryInterval; private _accountKey; private readonly _deletedTaskIds; private readonly _sessionFeed; private readonly _discoveryPoll; constructor(_cloudSandboxService: ICloudSandboxAgentHostService, _apiService: ICloudSandboxApiService, _draftPreparationService: ICloudSandboxDraftPreparationService, _remoteAgentHostService: IRemoteAgentHostService, _connectionCustomizations: IRemoteAgentHostConnectionCustomizationService, _configurationService: IConfigurationService, _instantiationService: IInstantiationService, _chatSessionsService: IChatSessionsService, _logService: ILogService, _chatEntitlementService: IChatEntitlementService, _hostService: IHostService, _storageService: IStorageService, _workspaceTrustManagementService: IWorkspaceTrustManagementService); protected _refreshIfStale(trigger?: "poll" | "focus" | "selection" | "automatic"): Promise; /** An account without any known sandbox only needs the periodic full reconciliation. */ private _pollInterval; /** Time until the current interval elapses since the latest inventory pass, spread so windows do not poll in lockstep. */ private _nextPollDelay; protected _pollJitter(): number; /** Inventory scans are serialized; feed task reads use an independent coalescing lane. */ protected _discoverAndSeed(request?: ICloudSandboxDiscoveryRequest): Promise; /** Reschedules an armed poll from the current interval, which a finished pass or a first sandbox may have changed. */ private _rearmDiscoveryPoll; protected _refreshFromFeed(refresh: CloudSandboxSessionFeedRefresh): Promise; private _refreshTasks; private _doDiscoverAndSeed; private _seedDiscoveredSession; protected _restoreAccount(accountKey: string | undefined): boolean; private _readInventory; protected _persistInventory(): void; protected _ownsSandboxSession(address: string, rawId: string): boolean; private _getTaskId; private _updateSandboxSession; protected _renameSandboxSession(address: string, rawId: string, title: string): Promise; protected _setSandboxSessionArchived(address: string, rawId: string, archived: boolean, token?: CancellationToken): Promise; protected _deleteSandboxSession(address: string, sessionIds: readonly string[], removeSession: (rawId: string) => void, token?: CancellationToken): Promise; /** * Cancel pending work and remove the connection while retaining the provider and its cached sessions. */ protected _disconnectEnvironment(address: string): Promise; private _cancelPendingConnect; /** * Fully tear down an environment: dispose its provider (unregistering it and its sessions) and * remove its connection + credential refresher. Used when an environment vanishes from discovery * or the feature is disabled. */ private _teardownEnvironment; /** Tear down every known sandbox environment (feature disabled). */ private _teardownAll; /** Map each known sandbox connection authority to its address (`cloudsandbox:`). */ private _authoritiesByAddress; /** Resolve the sandbox address owning a remote-agent-host session type, if any. */ private _findAddressForSessionType; /** Whether the chat surface can hand off persisted history and offline drafts to a live connection. */ protected get supportsBackgroundConnection(): boolean; /** Makes recorded history available independently of the surface's connection-on-open policy. */ protected _waitForActivation(sessionType: string): Promise; private _connectOnOpen; /** An unreadable record must not trigger an automatic resume in surfaces without background connection support. */ private _isEnvironmentOnline; /** Registers one provider that can promote its recorded conversations in place. */ private _activateHistory; private _registerLiveSessionProvider; private _clearSessionHandlers; /** Reconnect using a surviving session rather than the provider's original discovery seed. */ protected _connectEnvironment(environmentId: string): Promise; /** Establish or reuse the environment connection, returning its display address. */ connect(options: ICloudSandboxConnectOptions): Promise; /** * Return a provider to a state the user can act on after its connect failed. Defers to the * service when it has something live to report, so a failure that raced a successful dial does * not overwrite a good status, and leaves `incompatible` alone since redialing cannot fix it. */ private _settleFailedConnect; protected _isEnabled(): boolean; /** * Create a Mission Control task for a brand-new sandbox, seed its session on the provider and * connect to the environment. Provisioning runs the same `_ensureProvider → seed → connect` * path discovery does, so a later discovery pass reconciles the task rather than duplicating it. * * The seeded session stays withheld on providers that support it until the caller publishes * it (or this method fails, in which case the remote task is published so it is not lost). */ protected _provisionSandbox(request: ICloudSandboxCreateSessionRequest, token: CancellationToken, progress?: IProgress, draftResource?: URI): Promise>; private _createTaskForDraft; /** * Observe repository setup on a freshly provisioned environment. The returned store disposes * itself once the repository is ready or its clone failed. */ trackSessionCreationProgress(environmentId: string, repoNwo: string, progress: IProgress): IDisposable; private _updateEnablement; protected abstract _updateRegistration(): void; /** Create the sessions provider for an environment if it doesn't exist yet. */ protected _ensureProvider(env: ICloudSandboxSessionEnvironment): void; protected abstract _createProvider(env: ICloudSandboxSessionEnvironment, store: DisposableStore): T; /** Wire each live connection to its provider so session enumeration runs. */ private _wireConnections; /** Push the service's authoritative connection status onto each provider. */ private _updateConnectionStatuses; } export {};