UNPKG

@codesandbox/sdk

Version:
117 lines (116 loc) 3.96 kB
import { FileSystem } from "./filesystem"; import { Ports } from "./ports"; import { Setup } from "./setup"; import { Tasks } from "./tasks"; import { Interpreters } from "./interpreters"; import { Terminals } from "./terminals"; import { SandboxCommands } from "./commands"; import { HostToken } from "../HostTokens"; import { Hosts } from "./hosts"; import { type IAgentClient } from "../agent-client-interface"; import { setup, system } from "../pitcher-protocol"; import { SandboxSession } from "../types"; import { Tracer } from "@opentelemetry/api"; export * from "./filesystem"; export * from "./ports"; export * from "./setup"; export * from "./tasks"; export * from "./terminals"; export * from "./commands"; export * from "./interpreters"; export * from "./hosts"; type SandboxClientParams = { hostToken?: HostToken; username?: string; tracer?: Tracer; }; export declare class SandboxClient { protected agentClient: IAgentClient; private tracer?; static create(session: SandboxSession, getSession: (id: string) => Promise<SandboxSession>, initStatusCb?: (event: system.InitStatus) => void, tracer?: Tracer): Promise<SandboxClient>; private disposable; get workspacePath(): string; /** * Namespace for all filesystem operations on this Sandbox */ readonly fs: FileSystem; /** * Namespace for hosts */ readonly hosts: Hosts; /** * Namespace for creating and managing terminals this Sandbox */ readonly terminals: Terminals; /** * Namespace for running commands in the Sandbox */ readonly commands: SandboxCommands; /** * Namespace for running code interpreters in the Sandbox */ readonly interpreters: Interpreters; /** * Namespace for managing ports on this Sandbox */ readonly ports: Ports; /** * Namespace for the setup that runs when the Sandbox starts from scratch. */ readonly setup: Setup; /** * Namespace for tasks that are defined in the Sandbox. */ readonly tasks: Tasks; constructor(agentClient: IAgentClient, { hostToken, username, tracer }: SandboxClientParams, initialSetupProgress: setup.SetupProgress); private withSpan; /** * The current state of the Sandbox */ get state(): typeof this.agentClient.state; /** * An event that is emitted when the state of the Sandbox changes. */ get onStateChange(): import("../utils/event").Event<import("../agent-client-interface").IAgentClientState>; /** * Check if the Sandbox Agent process is up to date. To update a restart is required */ get isUpToDate(): boolean; /** * The ID of the sandbox. */ get id(): string; /** * Get the URL to the editor for this sandbox. Keep in mind that this URL is not * available if the sandbox is private, and the user opening this sandbox does not * have access to the sandbox. */ get editorUrl(): string; /** * Disconnect from the sandbox, this does not hibernate the sandbox (it will * automatically hibernate after hibernation timeout). Call "reconnect" to * reconnect to the sandbox. */ disconnect(): Promise<void>; /** * Explicitly reconnect to the sandbox. */ reconnect(): Promise<void>; /** * Attempt automatic reconnection with retry logic */ private attemptAutoReconnect; private keepAliveInterval; private shouldKeepAlive; private isExplicitlyDisconnected; private keepAliveFailures; private maxKeepAliveFailures; /** * If enabled, we will keep the sandbox from hibernating as long as the SDK is connected to it. */ keepActiveWhileConnected(enabled: boolean): void; /** * Dispose the session, this will disconnect from the sandbox and dispose all resources. If you want to do a clean disconnect, await "disconnect" method first. */ dispose(): void; }