tensorlake 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -310,6 +310,12 @@ declare class Sandbox {
310
310
  createTunnel(remotePort: number, options?: CreateTunnelOptions): Promise<TcpTunnel>;
311
311
  /** Connect to a sandbox VNC session for programmatic desktop control. */
312
312
  connectDesktop(options?: ConnectDesktopOptions): Promise<Desktop>;
313
+ /**
314
+ * Poll the in-sandbox daemon until `127.0.0.1:port` accepts a TCP connection.
315
+ * Uses `bash`'s `/dev/tcp` builtin via `processes/run` — no extra deps in
316
+ * the sandbox image. `bash` is present on every image we ship.
317
+ */
318
+ private waitForPortReady;
313
319
  ptyWsUrl(sessionId: string, token: string): string;
314
320
  /** Check the sandbox daemon health. */
315
321
  health(): Promise<HealthResponse>;
package/dist/index.d.ts CHANGED
@@ -310,6 +310,12 @@ declare class Sandbox {
310
310
  createTunnel(remotePort: number, options?: CreateTunnelOptions): Promise<TcpTunnel>;
311
311
  /** Connect to a sandbox VNC session for programmatic desktop control. */
312
312
  connectDesktop(options?: ConnectDesktopOptions): Promise<Desktop>;
313
+ /**
314
+ * Poll the in-sandbox daemon until `127.0.0.1:port` accepts a TCP connection.
315
+ * Uses `bash`'s `/dev/tcp` builtin via `processes/run` — no extra deps in
316
+ * the sandbox image. `bash` is present on every image we ship.
317
+ */
318
+ private waitForPortReady;
313
319
  ptyWsUrl(sessionId: string, token: string): string;
314
320
  /** Check the sandbox daemon health. */
315
321
  health(): Promise<HealthResponse>;
package/dist/index.js CHANGED
@@ -3654,15 +3654,53 @@ var init_sandbox = __esm({
3654
3654
  }
3655
3655
  /** Connect to a sandbox VNC session for programmatic desktop control. */
3656
3656
  async connectDesktop(options) {
3657
+ const port = options?.port ?? 5901;
3658
+ const connectTimeout = options?.connectTimeout ?? 10;
3659
+ const startMs = Date.now();
3660
+ const deadlineMs = startMs + connectTimeout * 1e3;
3661
+ await this.waitForPortReady(port, deadlineMs);
3662
+ const remainingSecs = Math.max(0.1, (deadlineMs - Date.now()) / 1e3);
3657
3663
  return Desktop.connect({
3658
3664
  baseUrl: this.baseUrl,
3659
3665
  wsHeaders: this.wsHeaders,
3660
- port: options?.port,
3666
+ port,
3661
3667
  password: options?.password,
3662
3668
  shared: options?.shared,
3663
- connectTimeout: options?.connectTimeout
3669
+ connectTimeout: remainingSecs
3664
3670
  });
3665
3671
  }
3672
+ /**
3673
+ * Poll the in-sandbox daemon until `127.0.0.1:port` accepts a TCP connection.
3674
+ * Uses `bash`'s `/dev/tcp` builtin via `processes/run` — no extra deps in
3675
+ * the sandbox image. `bash` is present on every image we ship.
3676
+ */
3677
+ async waitForPortReady(port, deadlineMs) {
3678
+ const probeIntervalMs = 250;
3679
+ const probeProcessTimeoutSecs = 2;
3680
+ let lastError;
3681
+ while (Date.now() < deadlineMs) {
3682
+ try {
3683
+ const result = await this.run("/bin/bash", {
3684
+ args: ["-c", `exec 3<>/dev/tcp/127.0.0.1/${port}`],
3685
+ timeout: probeProcessTimeoutSecs
3686
+ });
3687
+ if (result.exitCode === 0) {
3688
+ return;
3689
+ }
3690
+ } catch (error) {
3691
+ lastError = error;
3692
+ }
3693
+ const remainingMs = deadlineMs - Date.now();
3694
+ if (remainingMs <= 0) break;
3695
+ await new Promise(
3696
+ (resolve) => setTimeout(resolve, Math.min(probeIntervalMs, remainingMs))
3697
+ );
3698
+ }
3699
+ const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
3700
+ throw new SandboxError(
3701
+ `port ${port} did not become reachable inside sandbox within the connect timeout${detail}`
3702
+ );
3703
+ }
3666
3704
  ptyWsUrl(sessionId, token) {
3667
3705
  let wsBase;
3668
3706
  if (this.baseUrl.startsWith("https://")) {