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.
@@ -3611,15 +3611,53 @@ var init_sandbox = __esm({
3611
3611
  }
3612
3612
  /** Connect to a sandbox VNC session for programmatic desktop control. */
3613
3613
  async connectDesktop(options) {
3614
+ const port = options?.port ?? 5901;
3615
+ const connectTimeout = options?.connectTimeout ?? 10;
3616
+ const startMs = Date.now();
3617
+ const deadlineMs = startMs + connectTimeout * 1e3;
3618
+ await this.waitForPortReady(port, deadlineMs);
3619
+ const remainingSecs = Math.max(0.1, (deadlineMs - Date.now()) / 1e3);
3614
3620
  return Desktop.connect({
3615
3621
  baseUrl: this.baseUrl,
3616
3622
  wsHeaders: this.wsHeaders,
3617
- port: options?.port,
3623
+ port,
3618
3624
  password: options?.password,
3619
3625
  shared: options?.shared,
3620
- connectTimeout: options?.connectTimeout
3626
+ connectTimeout: remainingSecs
3621
3627
  });
3622
3628
  }
3629
+ /**
3630
+ * Poll the in-sandbox daemon until `127.0.0.1:port` accepts a TCP connection.
3631
+ * Uses `bash`'s `/dev/tcp` builtin via `processes/run` — no extra deps in
3632
+ * the sandbox image. `bash` is present on every image we ship.
3633
+ */
3634
+ async waitForPortReady(port, deadlineMs) {
3635
+ const probeIntervalMs = 250;
3636
+ const probeProcessTimeoutSecs = 2;
3637
+ let lastError;
3638
+ while (Date.now() < deadlineMs) {
3639
+ try {
3640
+ const result = await this.run("/bin/bash", {
3641
+ args: ["-c", `exec 3<>/dev/tcp/127.0.0.1/${port}`],
3642
+ timeout: probeProcessTimeoutSecs
3643
+ });
3644
+ if (result.exitCode === 0) {
3645
+ return;
3646
+ }
3647
+ } catch (error) {
3648
+ lastError = error;
3649
+ }
3650
+ const remainingMs = deadlineMs - Date.now();
3651
+ if (remainingMs <= 0) break;
3652
+ await new Promise(
3653
+ (resolve) => setTimeout(resolve, Math.min(probeIntervalMs, remainingMs))
3654
+ );
3655
+ }
3656
+ const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
3657
+ throw new SandboxError(
3658
+ `port ${port} did not become reachable inside sandbox within the connect timeout${detail}`
3659
+ );
3660
+ }
3623
3661
  ptyWsUrl(sessionId, token) {
3624
3662
  let wsBase;
3625
3663
  if (this.baseUrl.startsWith("https://")) {