import { URI } from "../../../base/common/uri.js"; import { IConfigurationService } from "../../configuration/common/configuration.service.js"; import { SessionStatus } from "./state/sessionState.js"; import { SessionModelInfo } from "./state/protocol/state.js"; import { MissionControlErrorMetadata } from "../../github/common/missionControl/missionControlError.js"; /** Configuration key gating the cloud-sandbox connection path. Disabled by default. */ export declare const CloudSandboxEnabledSettingId = "chat.agentHost.cloudSandbox.enabled"; export declare const CloudSandboxAutoConnectOnOpenSettingId = "chat.agentHost.cloudSandbox.autoConnectOnOpen"; export declare const CloudSandboxEarlyPreparationSettingId = "chat.agentHost.cloudSandbox.earlyPreparation"; export declare const CloudSandboxSessionFeedEnabledSettingId = "chat.agentHost.cloudSandbox.sessionFeed.enabled"; /** * Whether cloud sandbox sessions can be created or connected to. A sandbox is reached over the * remote-agent-host relay, so it needs that setting too. */ export declare function isCloudSandboxEnabled(configurationService: IConfigurationService): boolean; /** Prefix for the synthesized display address of a cloud sandbox connection. */ export declare const CLOUD_SANDBOX_ADDRESS_PREFIX = "cloudsandbox:"; /** * Session URI scheme the Copilot host uses when it creates and lists sessions * (`ahp-session:/`). Differs from its agent provider ({@link CLOUD_SANDBOX_AGENT_PROVIDER}): * the UI routes by provider, but backend calls must address sessions under this scheme because the * host's session registry is keyed by the exact URI. */ export declare const CLOUD_SANDBOX_SESSION_SCHEME = "ahp-session"; /** The agent provider advertised by the Copilot host inside the sandbox. */ export declare const CLOUD_SANDBOX_AGENT_PROVIDER = "copilot"; /** * Whether a title the sandbox host reports is its stand-in for an untitled session. AHP gives * `title` no "untitled" meaning, and this host fills it with the session id until the agent names * the session; the local agent host publishes an empty title instead. Remove once the sandbox host * does the same or the protocol defines the untitled case. */ export declare function isCloudSandboxPlaceholderTitle(title: string | undefined, session: URI | string): title is string; /** Prefix of a sealed token envelope (`copilot-sealed.v1..`). */ export declare const CLOUD_SANDBOX_SEALED_TOKEN_PREFIX = "copilot-sealed.v1."; /** Whether {@link token} is a sealed envelope, and so safe to forward over the relay. */ export declare function isCloudSandboxSealedToken(token: string | undefined): boolean; /** The Mission Control environment id encoded in a cloud sandbox connection address, if any. */ export declare function cloudSandboxEnvironmentId(address: string): string | undefined; /** * Historical sandbox agent slug, retained for discovery diagnostics rather than filtering. * Keep sandbox discovery opt-in until overlap with the Copilot extension's cloud provider is resolved. */ export declare const CLOUD_SANDBOX_AGENT_SLUG = "copilot-developer-cli"; /** * Sentinel environment id asking Mission Control to provision a fresh sandbox VM. Never a real * environment: the concrete id comes back on the created session and everything must address that * one — see {@link ICloudSandboxCreatedSession.environmentId}. */ export declare const CLOUD_SANDBOX_ON_DEMAND_ENVIRONMENT_ID = "github-sandbox"; /** What to provision a sandbox session for. */ export interface ICloudSandboxCreateSessionRequest { /** Repository to bind the sandbox to, as `owner/name`. Omitted for a repo-less sandbox. */ readonly repoNwo?: string; /** Existing online environment to reuse. Omit to provision a new environment. */ readonly environmentId?: string; /** Reservation to consume on submission; requires expectedAccountKey and excludes environmentId. */ readonly reservedTaskId?: string; /** Expected account identity, checked locally before sending the request. */ readonly expectedAccountKey?: string; /** First user turn. Mission Control starts no run, so the client sends it over the relay. */ readonly prompt: string; } /** A sandbox task/session pair, bound to a concrete environment. */ export interface ICloudSandboxCreatedSession { /** Mission Control task id owning the session; the key its persisted AHP history is under. */ readonly taskId: string; /** Session id, issued as `ahp-session:/` and listed back by the host under that id. */ readonly sessionId: string; /** The sandbox VM Mission Control bound, never {@link CLOUD_SANDBOX_ON_DEMAND_ENVIRONMENT_ID}. */ readonly environmentId: string; /** Present for reservation submissions: true when reused, false when the server created a fresh task. */ readonly claimed?: boolean; } /** Client task-creation provenance, not a claim about environment readiness. */ export declare const cloudSandboxTaskCreationPaths: readonly [ "newEnvironment", "existingEnvironment", "reservationClaimed", "reservationFallback", "reservationUnconfirmed", "unknown" ]; export type CloudSandboxTaskCreationPath = typeof cloudSandboxTaskCreationPaths[number]; /** The draft configuration to reserve without submitting a user turn. */ export interface ICloudSandboxReserveSessionRequest { readonly repoNwo?: string; /** Renew this reservation when compatible, or accept its replacement. */ readonly reservedTaskId?: string; readonly expectedAccountKey: string; } /** A hidden task reservation; its environment is not necessarily ready. */ export interface ICloudSandboxReservedSession extends ICloudSandboxCreatedSession { /** Server lease expiry in milliseconds since the Unix epoch. */ readonly reservationExpiresAt: number; } export interface ICloudSandboxPreparedReservation extends ICloudSandboxReservedSession { readonly expectedAccountKey: string; } /** A confirmed reservation submission retained until its logical draft is disposed. */ export interface ICloudSandboxSubmittedDraft { readonly reservation: ICloudSandboxPreparedReservation; readonly created: ICloudSandboxCreatedSession; readonly repoNwo: string | undefined; } /** A sandbox session discovered from the Copilot task list, enough to seed a session entry. */ export interface ICloudSandboxDiscoveredSession { readonly eventType?: string; /** The creating application's slug from the owning task, not a participating session client. */ readonly application?: string; /** Mission Control environment id the session's sandbox is bound to. */ readonly environmentId: string; /** * Session id, used as the native session's raw id. Mission Control creates the session as * `ahp-session:/` and the host lists it back under the same id, so seeded entries * reconcile with the host's `listSessions()` on connect. */ readonly sessionId: string; /** * Mission Control task id owning the session. Persisted AHP history is addressed per task, so * this is what makes a session's conversation readable after its sandbox is gone. */ readonly taskId: string; /** Display name for the session/host. */ readonly name: string; /** Owning repository as `owner/name`, when known. */ readonly repoName?: string; /** Whether discovery identified a repository association, independent of name resolution. */ readonly hasRepository?: boolean; /** Last-updated timestamp (ISO 8601), when known, for ordering. */ readonly updatedAt?: string; /** Last reported activity; this does not establish environment availability or session flags. */ readonly status?: SessionStatus; /** Mission Control's archive state, independent of the sandbox's AHP session flags. */ readonly isArchived?: boolean; } /** Build the synthesized remote-agent-host address for a sandbox environment. */ export declare function cloudSandboxAddress(environmentId: string): string; /** Build the Web PubSub URL for a client token. The scheme is forced to `wss://`. */ export declare function buildWpsUrl(token: ICloudSandboxClientToken): string; /** * The three per-client Web PubSub group "lanes". The client joins {@link broadcast} and * {@link to_client} (inbound) and publishes to {@link to_host} (outbound). */ export interface IWebPubSubClientGroups { /** Host → this-client broadcast lane the client subscribes to. */ readonly broadcast: string; /** Host → this-client lane the client subscribes to. */ readonly to_client: string; /** This-client → host lane the client publishes to. */ readonly to_host: string; } /** A public sealing key advertised by the sandbox host. */ export interface IHostEncryptionKey { /** Stateless key fingerprint; names the key in a sealed value's envelope. */ readonly key_id: string; /** Trust domain the key serves (e.g. `auth-token`). */ readonly use: string; /** Sealing scheme, such as `x25519-sealedbox` or `hpke-x25519-hkdf-sha256-aes256gcm`. */ readonly algorithm: string; /** Recipient public key in standard (padded) base64. */ readonly public_key: string; } /** A credential to seal for an environment; resource binding is optional and connection binding is not supported. */ export interface ICloudSandboxSealTokenRequest { readonly environmentId: string; readonly token: string; readonly resource?: string; } /** The server-sealed credential and the recipient key returned over authenticated HTTPS. */ export interface ICloudSandboxSealedToken { readonly encrypted_github_token: string; readonly host_encryption_key: IHostEncryptionKey; } /** * A client Web PubSub connection token (`/connect` and `/reconnect`, HTTP 200). Field names mirror * the wire shape so the extension can pass them through the bridge without remapping. */ export interface ICloudSandboxClientToken { /** Short-lived Web PubSub JWT. Never persisted. */ readonly access_token: string; /** ISO-8601 expiry of {@link access_token}. */ readonly expires_at: string; /** Web PubSub endpoint URL (without the access-token query param). */ readonly wps_endpoint: string; /** Web PubSub hub name. */ readonly hub: string; /** WebSocket subprotocol to negotiate (e.g. the reliable JSON subprotocol). */ readonly subprotocol: string; /** MC-issued stable client identity used for group lanes, `initialize`, and reconnect. */ readonly client_id: string; /** The per-client group lanes. */ readonly groups: IWebPubSubClientGroups; /** Opaque `copilot-sealed.v1..` envelope, when MC sealed a token. */ readonly encrypted_github_token?: string; /** The host key the {@link encrypted_github_token} was sealed to, when present. */ readonly host_encryption_key?: IHostEncryptionKey; } /** * Mission Control signalled that the environment is waking (HTTP 202). The * client must retry `/connect` after {@link retryAfterSeconds} until it gets a * token (HTTP 200). */ export interface ICloudSandboxWaking { /** Seconds to wait before retrying, from the `Retry-After` header. */ readonly retryAfterSeconds: number; } /** Result of a credentials mint: either a usable token or a "waking" retry signal. */ export type CloudSandboxConnectResult = { readonly kind: "token"; readonly token: ICloudSandboxClientToken; } | { readonly kind: "waking"; readonly waking: ICloudSandboxWaking; }; /** * Operational state of a sandbox environment. Only `online` has a daemon listening on the relay; * connecting to any other state leaves the AHP `initialize` unanswered. */ export type CloudSandboxEnvironmentStatus = "online" | "offline" | "degraded" | "waking" | "draining"; /** A sandbox environment's current record, as reported by Mission Control. */ export interface ICloudSandboxEnvironment { readonly id: string; readonly status: CloudSandboxEnvironmentStatus; readonly capabilities?: { /** The copilotd **host** version (e.g. `0.6.3`), not the AHP wire protocol version. */ readonly ahp_version?: string; }; /** Public recipient keys obtained through authenticated MC HTTPS, not through the relay. */ readonly encryption_keys?: readonly IHostEncryptionKey[]; } /** Credential-free discovery metadata for a Mission Control environment. */ export interface IMissionControlEnvironment { readonly id: string; /** Open vocabulary; only online permits attachment without a warning. */ readonly status: string; readonly kind: string; readonly name: string; } /** Identifies which sandbox environment/session credentials are being minted for. */ export interface ICloudSandboxConnectionRequest { /** Local reporting scope; user-local hosts must not emit cloud sandbox lifecycle events. Never sent to the server. */ readonly environmentKind?: "user-local"; /** Stable environment identifier (`env_`) of the sandbox. */ readonly environmentId: string; /** * The cloud session/task id the client is connecting to. Mission Control * uses it to resolve the repository when minting the token. */ readonly sessionId?: string; /** Reports credential HTTP dispatch or a pending response locally; never sent to the server. */ readonly onRequest?: (event: "issued" | "waking") => void; } export interface ICloudSandboxModelCatalog { readonly models: readonly SessionModelInfo[]; readonly defaultModel?: string; } /** An identity-only credential for sandbox host authentication; never persist it or send it unsealed over the relay. */ export interface ICloudSandboxIdentityToken { readonly token: string; /** Expiry in Unix milliseconds, absent when the issuer supplies no lifetime. */ readonly expiresAt?: number; } /** A sandbox whose recipient key is ready for the server-side sealing operation. */ export interface ICloudSandboxAuthenticationTarget { readonly environmentId: string; readonly resource: string; } /** A sealed identity credential; its original expiry must still be checked before authentication. */ export interface ICloudSandboxPreparedAuthentication extends ICloudSandboxSealedToken, ICloudSandboxAuthenticationTarget { readonly expiresAt?: number; } /** Receive-only discovery credentials. The URL contains a bearer token and must not be logged. */ export interface ICloudSandboxSessionFeedConnection { readonly url: string; readonly subprotocol: "json.webpubsub.azure.v1"; readonly group: string; readonly expires_at: string; readonly reconnect_after: string; /** Server-relative milliseconds; omitted together by older servers. */ readonly expires_in?: number; readonly reconnect_in?: number; readonly frame_schema_version: 1; } export declare const cloudSandboxDiscoveryTriggers: readonly [ "startup", "automatic", "poll", "focus", "selection", "accountChange", "configurationChange", "manual", "feedChange", "feedRenewal", "feedReconnect" ]; export type CloudSandboxDiscoveryTrigger = typeof cloudSandboxDiscoveryTriggers[number]; export interface ICloudSandboxDiscoveryOptions { readonly incremental?: boolean; readonly taskIds?: readonly string[]; readonly trigger?: CloudSandboxDiscoveryTrigger; } /** Only a complete scan permits removing absent sessions; other results may name explicit removals. */ export type ICloudSandboxDiscoveryResult = /** Every task was scanned and resolved; absent sessions really are gone. */ { readonly kind: "complete"; readonly sessions: readonly ICloudSandboxDiscoveredSession[]; } /** Changes only; sessions absent from this result must be retained. */ | { readonly kind: "incremental"; readonly sessions: readonly ICloudSandboxDiscoveredSession[]; readonly removedTaskIds: readonly string[]; } /** Some tasks could not be resolved; only explicitly removed tasks may be dropped. */ | { readonly kind: "partial"; readonly sessions: readonly ICloudSandboxDiscoveredSession[]; readonly removedTaskIds?: readonly string[]; readonly failedTaskIds?: readonly string[]; } /** Discovery could not run (auth not ready, request failed). Existing state must be left alone. */ | { readonly kind: "failed"; readonly reason: string; }; /** Thrown when no GitHub session with the required scopes is available. */ export declare class CloudSandboxAuthenticationRequiredError extends Error { constructor(); } /** A connection request failed without receiving an HTTP response. */ export declare class CloudSandboxNetworkError extends Error { constructor(message: string, options?: ErrorOptions); } /** * A Mission Control request failure or local request validation failure. * Carries the {@link statusCode} when a response was received and available error metadata. */ export declare class CloudSandboxRequestError extends Error { readonly statusCode: number | undefined; readonly retryAfterSeconds?: number | undefined; readonly code: string | undefined; readonly limitedResource: string | undefined; readonly requestId: string | undefined; constructor(statusCode: number | undefined, message: string, retryAfterSeconds?: number | undefined, metadata?: MissionControlErrorMetadata); } /** Whether credential recovery can succeed without changing its inputs. Semantic codes override HTTP status. */ export declare function isRetryableCloudSandboxError(error: unknown): boolean; /** Options for establishing a live AHP relay to a cloud sandbox environment. */ export interface ICloudSandboxConnectOptions { /** Selects the generic native-host path rather than sandbox checkout preparation. */ readonly environmentKind?: "user-local"; /** Stable Mission Control environment identifier (`env_`). */ readonly environmentId: string; /** The cloud session/task id this connection is for, used for token minting. */ readonly sessionId?: string; /** Human-readable display name for the connection. */ readonly name: string; /** Local identity that owns this staged user-local connection; never sent to MC. */ readonly accountKey?: string; /** Recipient keys from this account's environment descriptor, fetched over authenticated HTTPS. */ readonly trustedEncryptionKeys?: readonly IHostEncryptionKey[]; /** Caller provenance, not a claim about warm or cold compute. */ readonly connectionSource?: "created" | "existing"; /** Local task-creation start time for end-to-end provisioning telemetry; never persisted or sent to MC. */ readonly provisioningStartedAt?: number; /** Local startup provenance for timing telemetry; never persisted or sent to MC. */ readonly taskCreationPath?: CloudSandboxTaskCreationPath; /** Time spent awaiting the draft reservation during submission; a subset of provisioning time, not an additional stage. */ readonly reservationWaitMs?: number; }