import { Command, CommandFinished, Sandbox } from '@vercel/sandbox'; import type { VercelCredentials } from './auth.js'; import type { GitSource } from './source.js'; export type SandboxSessionStatus = 'pending' | 'running' | 'stopping' | 'stopped' | 'failed' | 'aborted' | 'snapshotting'; export type SandboxSnapshotStatus = 'failed' | 'created' | 'deleted'; export interface SandboxRoute { url: string; subdomain: string; port: number; } export interface SandboxSessionRecord { id: string; status: SandboxSessionStatus; activeCpuDurationMs?: number; networkTransfer?: { ingress: number; egress: number; }; [key: string]: unknown; } export interface SandboxSnapshotRecord { id: string; sourceSessionId: string; status: SandboxSnapshotStatus; [key: string]: unknown; } export interface SandboxListRecord { name: string; persistent: boolean; status: SandboxSessionStatus; image?: string; timeout?: number; tags?: Record; currentSnapshotId?: string; keepLastSnapshots?: { count: number; expiration?: number; deleteEvicted?: boolean; }; [key: string]: unknown; } export interface VercelStopResult { id: string; status: SandboxSessionStatus; activeCpuDurationMs?: number; networkTransfer?: { ingress: number; egress: number; }; snapshot?: { id: string; status: SandboxSnapshotStatus; [key: string]: unknown; }; [key: string]: unknown; } export type VercelCommandResult = Command | CommandFinished; export type VercelWriteFile = Parameters[0][number]; export type VercelRunCommandRequest = Parameters[0]; export interface VercelSandboxHandle { readonly id?: string; readonly name: string; readonly status: SandboxSessionStatus; readonly persistent?: boolean; readonly image?: string; readonly timeout?: number; readonly vcpus?: number; readonly createdAt?: Date; readonly expiresAt?: Date; readonly cwd?: string; readonly tags?: Record; readonly routes?: readonly SandboxRoute[]; readonly keepLastSnapshots?: { count: number; expiration?: number; deleteEvicted?: boolean; }; readonly currentSnapshotId?: string; readonly activeCpuUsageMs?: number; readonly networkTransfer?: { ingress: number; egress: number; }; readonly totalActiveCpuDurationMs?: number; readonly totalIngressBytes?: number; readonly totalEgressBytes?: number; openInteractive(options?: { signal?: AbortSignal; }): Promise<{ url: string; token: string; }>; extendTimeout(durationMs: number, options?: { signal?: AbortSignal; }): Promise; listSessions(params?: { signal?: AbortSignal; }): Promise; stop(params?: { signal?: AbortSignal; }): Promise; delete(params?: { signal?: AbortSignal; }): Promise; writeFiles(files: VercelWriteFile[], options?: { signal?: AbortSignal; }): Promise; runCommand(params: VercelRunCommandRequest): Promise; update(params: VercelSandboxUpdateRequest, options?: { signal?: AbortSignal; }): Promise; domain(port: number): string; } /** * The subset of `Sandbox.update` this client uses. * * `ports` is the complete desired list: the service deregisters any currently * exposed port that the array omits, so callers must always send the full set * rather than the delta they want to add. */ export type VercelSandboxUpdateRequest = Pick[0], 'ports'>; export interface VercelSnapshotHandle { readonly snapshotId: string; readonly status: SandboxSnapshotStatus; delete(params?: { signal?: AbortSignal; }): Promise; } export interface VercelSandboxCreateRequest { name: string; image: string; source: GitSource; timeout: number; ports?: number[]; env?: Record; persistent: true; keepLastSnapshots: { count: 1; }; tags: Record; resources?: { vcpus: number; }; signal?: AbortSignal; onCreate?: (sandbox: VercelSandboxHandle) => Promise; } export interface VercelSandboxGetRequest { credentials: VercelCredentials; name: string; resume?: boolean; signal?: AbortSignal; } export interface VercelSandboxDeleteByNameRequest { credentials: VercelCredentials; name: string; signal?: AbortSignal; } export interface VercelSandboxDeleteByNameResult { missing: boolean; } export interface VercelSandboxCreateInput { name: string; /** Fully-qualified digest reference resolved for this run. */ image: string; source: GitSource; timeoutMs: number; ports?: number[]; runtimeEnvironment?: Record; tags: Record; vcpus?: number; signal?: AbortSignal; onCreate?: (sandbox: VercelSandboxHandle) => Promise; } export declare function buildVercelSandboxCreateRequest(input: VercelSandboxCreateInput): VercelSandboxCreateRequest; export interface VercelSandboxClient { getOrCreate(request: VercelSandboxCreateRequest & { credentials: VercelCredentials; }): Promise; get(request: VercelSandboxGetRequest): Promise; deleteSandboxByName(request: VercelSandboxDeleteByNameRequest): Promise; listSandboxes(request: { credentials: VercelCredentials; tags?: Record; namePrefix?: string; signal?: AbortSignal; }): Promise; listSessions(sandbox: VercelSandboxHandle, options?: { signal?: AbortSignal; }): Promise; stopSandbox(sandbox: VercelSandboxHandle, options?: { signal?: AbortSignal; }): Promise; deleteSandbox(sandbox: VercelSandboxHandle, options?: { signal?: AbortSignal; }): Promise; writeFiles(sandbox: VercelSandboxHandle, files: VercelWriteFile[], options?: { signal?: AbortSignal; }): Promise; runCommand(sandbox: VercelSandboxHandle, params: VercelRunCommandRequest): Promise; /** * Replace the Sandbox's exposed ports with `ports` on the running Sandbox. * * This never recreates the Sandbox: it is the only supported way to add an * app route to a box that is already up. */ updatePorts(sandbox: VercelSandboxHandle, ports: readonly number[], options?: { signal?: AbortSignal; }): Promise; listSnapshots(request: { credentials: VercelCredentials; name: string; signal?: AbortSignal; }): Promise; getSnapshot(request: { credentials: VercelCredentials; snapshotId: string; signal?: AbortSignal; }): Promise; deleteSnapshot(snapshot: VercelSnapshotHandle, options?: { signal?: AbortSignal; }): Promise; } export interface VercelSandboxApi { getOrCreate(params: Record): Promise; get(params: Record): Promise; list(params: Record): Promise; } export interface VercelSnapshotApi { list(params: Record): Promise; get(params: Record): Promise; } export interface VercelSandboxClientOptions { sandbox?: VercelSandboxApi; snapshot?: VercelSnapshotApi; fetch?: typeof globalThis.fetch; } export declare class VercelSdkError extends Error { readonly operation: string; readonly status?: number; readonly notFound: boolean; constructor(operation: string, error: unknown, secrets: readonly string[]); } export declare function isVercelNotFound(error: unknown): boolean; export declare function isVercelStale(error: unknown): boolean; export declare function createVercelSandboxClient(options?: VercelSandboxClientOptions): VercelSandboxClient; export declare function collectPaginated(value: unknown, key: string): Promise;