import { CancellationToken } from "../../../../../base/common/cancellation.js"; import { Disposable } from "../../../../../base/common/lifecycle.js"; import { CloudSandboxConnectResult, ICloudSandboxConnectionRequest, ICloudSandboxCreatedSession, ICloudSandboxCreateSessionRequest, ICloudSandboxReservedSession, ICloudSandboxReserveSessionRequest, ICloudSandboxDiscoveryResult, ICloudSandboxDiscoveryOptions, ICloudSandboxEnvironment, ICloudSandboxAuthenticationTarget, ICloudSandboxIdentityToken, ICloudSandboxPreparedAuthentication, ICloudSandboxSealedToken, ICloudSandboxSealTokenRequest, IMissionControlEnvironment, ICloudSandboxModelCatalog, ICloudSandboxSessionFeedConnection } from "../../../../../platform/agentHost/common/cloudSandboxAgentHost.js"; import { ICloudSandboxApiService } from "../../../../../platform/agentHost/common/cloudSandboxAgentHost.service.js"; import { IReplayedTaskHistory } from "../../../../../platform/agentHost/common/taskEventReplay.js"; import { ILogService } from "../../../../../platform/log/common/log.service.js"; import { IProductService } from "../../../../../platform/product/common/productService.service.js"; import { IRequestService } from "../../../../../platform/request/common/request.service.js"; import { IAuthenticationService } from "../../../../services/authentication/common/authentication.service.js"; import { ICloudSandboxTelemetryService } from "./cloudSandboxTelemetry.service.js"; import { IWorkbenchGitHubService } from "../../../../services/github/common/githubService.service.js"; /** * Mission Control client for cloud sandbox sessions: mints (`connect`) and refreshes (`reconnect`) * Web PubSub credentials, reads environment and task records, discovers sandbox-backed sessions, * and replays a task's persisted AHP history. * * Runs in the renderer so the sandbox path works in VS Code Web, where no Copilot extension host is * available. */ export declare class CloudSandboxApiService extends Disposable implements ICloudSandboxApiService { private readonly _requestService; private readonly _authenticationService; private readonly _productService; private readonly _logService; private readonly _telemetry; private readonly _githubService; readonly _serviceBrand: undefined; private readonly _identityTokenProvider; private readonly _lifetimeToken; /** Resolved (or in-flight) repository names, keyed by numeric repository id. */ private readonly _repositoryNames; private readonly _discoveredTasks; private readonly _activeDiscoveryReads; private _discoverySince; private _discoveryGeneration; private _accountGeneration; private _historyRequestId; private readonly _historyCache; private _environments; private readonly _onDidChangeAccount; readonly onDidChangeAccount: import("../../../../../base/common/event.js").Event; constructor(_requestService: IRequestService, _authenticationService: IAuthenticationService, _productService: IProductService, _logService: ILogService, _telemetry: ICloudSandboxTelemetryService, _githubService: IWorkbenchGitHubService); private get _authenticationProviderId(); getAccountKey(): Promise; private _accountKeyForSession; getIdentityToken(accountKey: string, token: CancellationToken, forceRefresh?: boolean): Promise; prepareSandboxAuthentication(accountKey: string, target: Promise, token: CancellationToken, forceRefresh?: boolean): Promise; sealToken(request: ICloudSandboxSealTokenRequest, token: CancellationToken): Promise; private _sealToken; private _requestIdentityToken; private _requestCredential; connectSessionFeed(token: CancellationToken): Promise; private _onAuthenticationChanged; connect(request: ICloudSandboxConnectionRequest, token: CancellationToken): Promise; reconnect(request: ICloudSandboxConnectionRequest, clientId: string, token: CancellationToken): Promise; getEnvironment(environmentId: string, token: CancellationToken): Promise; getCachedEnvironments(): readonly IMissionControlEnvironment[] | undefined; listEnvironments(token: CancellationToken, options?: { readonly refresh?: boolean; }): Promise; deleteEnvironment(environmentId: string, token: CancellationToken, expectedAccountKey: string): Promise; /** Incremental scans preserve absent tasks; full scans also find tasks without environment-kind metadata. */ listSessions(token: CancellationToken, options?: ICloudSandboxDiscoveryOptions): Promise; private _listSessions; reserveSession(request: ICloudSandboxReserveSessionRequest, token: CancellationToken): Promise; private _reserveSession; /** * Provision a sandbox task and environment without starting an agent turn. * The caller sends the first turn over the relay. */ createSession(request: ICloudSandboxCreateSessionRequest, token: CancellationToken, onRequest?: () => void): Promise; private _createSession; private _requestTaskCreation; deleteTask(taskId: string, token: CancellationToken, expectedAccountKey?: string): Promise; private _deleteTask; renameTask(taskId: string, title: string, token: CancellationToken): Promise; setTaskArchived(taskId: string, archived: boolean, token: CancellationToken): Promise; /** * Delete a task we created but cannot use. Best-effort: the caller is already failing, and a * failed cleanup must not replace the error that explains why. * * Only covers tasks whose id we learned. Mission Control writes the task record before it * provisions compute, so any failure after that point (an authorization rejection, or a * provisioning error such as HTTP 500 `failed to create agent compute`) leaves a task behind. * When the failure response omits the id, that orphan can only be cleaned up server-side. */ private _deleteTaskBestEffort; /** * Read a task's persisted AHP history and fold it into session/chat state. * * The only history path that survives the sandbox: `/events` is served by Mission Control's * mirror, not the environment. The `vnd.github.ahp+json` media type selects the raw relayed * frames rather than the cloud-task event summaries the endpoint serves by default. */ getSessionHistory(taskId: string, token: CancellationToken, diagnosticId?: string, onCachedHistory?: (history: IReplayedTaskHistory) => void, canCacheHistory?: (history: IReplayedTaskHistory | undefined) => boolean): Promise; invalidateSessionHistory(taskId: string, preserveCached?: boolean): void; clearSessionHistory(taskId?: string): void; private _fetchSessionHistory; /** * Resolve a numeric repository id to its `owner/name`, memoized for the life of the service. * A task names its repository nowhere — `repository` carries an id, and the session's * `event_url` / `base_ref` are empty for tasks created through the tasks API. * * The cached promise must never reject: every task in a pass shares it, and a rejection would * count each one as unresolved (forcing the scan `partial`) and drop those sessions from the * listing entirely. A miss is evicted so the next pass retries. */ private _resolveRepositoryName; /** Shared handler for the `connect`/`reconnect` endpoints (200 token or 202 waking). */ private _connectRequest; /** * Issue an agent-environment request and return the raw response. The caller owns status * handling, since the meaning of a status is endpoint-specific (notably HTTP 202 = "waking", * which is neither an error nor a result). */ private _sendEnvironment; /** Issue a task API request, throwing on a non-success status. */ private _sendTask; /** * Re-issue a discovery read that came back rate-limited, waiting for `Retry-After` when the * response names one and backing off exponentially when it does not. * * Discovery reads the API far harder than any other sandbox call, so it is the one path that * routinely trips the limit. Reporting a 429 rather than retrying it loses the session being * resolved for the rest of the window, because nothing re-runs a pass that otherwise succeeded. */ private _retryWhileRateLimited; private _request; /** * Mission Control task API base. Uses the Copilot API host: `api.github.com/agents/*` omits * CORS headers on authenticated responses, so a renderer `fetch` receives the reply and discards it. */ private _tasksBaseUrl; listModels(token: CancellationToken): Promise; private _readJson; /** * Throw a diagnosable error for a non-success response. Pass `prereadBody` when the caller has * already consumed the stream, since reading it twice yields nothing. */ private _throwForStatus; /** The task id from a failed create, when the response names the task it already recorded. */ private _taskIdFromFailure; /** A GitHub session carrying at least the configured chat provider scopes. */ private _resolveGitHubSession; }