tensorlake 0.4.45 → 0.4.47

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
@@ -1,5 +1,5 @@
1
- import { C as CreatePtySessionOptions, S as SandboxOptions, R as RunOptions, a as CommandResult, b as StartProcessOptions, P as ProcessInfo, c as SendSignalResponse, O as OutputResponse, d as OutputEvent, L as ListDirectoryResponse, e as PtySessionInfo, H as HealthResponse, D as DaemonInfo, f as SandboxClientOptions, g as CreateSandboxOptions, h as CreateSandboxResponse, i as SandboxInfo, U as UpdateSandboxOptions, j as SandboxPortAccess, k as SnapshotOptions, l as CreateSnapshotResponse, m as SnapshotInfo, n as SnapshotAndWaitOptions, o as CreatePoolOptions, p as CreateSandboxPoolResponse, q as SandboxPoolInfo, r as UpdatePoolOptions, s as CreateAndConnectOptions } from './sandbox-image-B5Fa0xqb.cjs';
2
- export { t as ContainerResourcesInfo, u as ContainerState, v as CreateSandboxImageOptions, w as DirectoryEntry, x as DockerfileBuildPlan, y as DockerfileInstruction, I as Image, z as ImageBuildOperation, A as ImageBuildOperationType, A as ImageBuildOperationTypeValue, B as ImageOptions, N as NetworkConfig, E as OutputMode, F as PoolContainerInfo, G as ProcessStatus, J as SandboxImageSource, K as SandboxStatus, M as SnapshotContentMode, Q as SnapshotStatus, T as StdinMode, V as createSandboxImage, W as dockerfileContent } from './sandbox-image-B5Fa0xqb.cjs';
1
+ import { C as CreatePtySessionOptions, S as SandboxOptions, R as RunOptions, a as CommandResult, b as StartProcessOptions, P as ProcessInfo, c as SendSignalResponse, O as OutputResponse, d as OutputEvent, L as ListDirectoryResponse, e as PtySessionInfo, H as HealthResponse, D as DaemonInfo, f as SandboxClientOptions, g as CreateSandboxOptions, h as CreateSandboxResponse, i as SandboxInfo, U as UpdateSandboxOptions, j as SandboxPortAccess, k as SnapshotOptions, l as CreateSnapshotResponse, m as SnapshotInfo, n as SnapshotAndWaitOptions, o as CreatePoolOptions, p as CreateSandboxPoolResponse, q as SandboxPoolInfo, r as UpdatePoolOptions, s as CreateAndConnectOptions } from './sandbox-image-B130uMYt.cjs';
2
+ export { t as ContainerResourcesInfo, u as ContainerState, v as CreateSandboxImageOptions, w as DirectoryEntry, x as DockerfileBuildPlan, y as DockerfileInstruction, I as Image, z as ImageBuildOperation, A as ImageBuildOperationType, A as ImageBuildOperationTypeValue, B as ImageOptions, N as NetworkConfig, E as OutputMode, F as PoolContainerInfo, G as ProcessStatus, J as SandboxImageSource, K as SandboxStatus, M as SnapshotContentMode, Q as SnapshotStatus, T as StdinMode, V as createSandboxImage, W as dockerfileContent } from './sandbox-image-B130uMYt.cjs';
3
3
 
4
4
  type MouseButton = "left" | "middle" | "right";
5
5
  interface ConnectDesktopOptions {
@@ -157,6 +157,12 @@ declare class Sandbox {
157
157
  _setOwner(client: SandboxClient): void;
158
158
  close(): void;
159
159
  terminate(): Promise<void>;
160
+ /**
161
+ * Run a command to completion and return its output.
162
+ *
163
+ * Uses a single streaming `POST /api/v1/processes/run` request that starts
164
+ * the process, streams output, and delivers the exit code over one connection.
165
+ */
160
166
  run(command: string, options?: RunOptions): Promise<CommandResult>;
161
167
  startProcess(command: string, options?: StartProcessOptions): Promise<ProcessInfo>;
162
168
  listProcesses(): Promise<ProcessInfo[]>;
@@ -243,7 +249,7 @@ declare class SandboxClient {
243
249
  listPools(): Promise<SandboxPoolInfo[]>;
244
250
  updatePool(poolId: string, options: UpdatePoolOptions): Promise<SandboxPoolInfo>;
245
251
  deletePool(poolId: string): Promise<void>;
246
- connect(identifier: string, proxyUrl?: string): Sandbox;
252
+ connect(identifier: string, proxyUrl?: string, routingHint?: string): Sandbox;
247
253
  createAndConnect(options?: CreateAndConnectOptions): Promise<Sandbox>;
248
254
  }
249
255
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CreatePtySessionOptions, S as SandboxOptions, R as RunOptions, a as CommandResult, b as StartProcessOptions, P as ProcessInfo, c as SendSignalResponse, O as OutputResponse, d as OutputEvent, L as ListDirectoryResponse, e as PtySessionInfo, H as HealthResponse, D as DaemonInfo, f as SandboxClientOptions, g as CreateSandboxOptions, h as CreateSandboxResponse, i as SandboxInfo, U as UpdateSandboxOptions, j as SandboxPortAccess, k as SnapshotOptions, l as CreateSnapshotResponse, m as SnapshotInfo, n as SnapshotAndWaitOptions, o as CreatePoolOptions, p as CreateSandboxPoolResponse, q as SandboxPoolInfo, r as UpdatePoolOptions, s as CreateAndConnectOptions } from './sandbox-image-B5Fa0xqb.js';
2
- export { t as ContainerResourcesInfo, u as ContainerState, v as CreateSandboxImageOptions, w as DirectoryEntry, x as DockerfileBuildPlan, y as DockerfileInstruction, I as Image, z as ImageBuildOperation, A as ImageBuildOperationType, A as ImageBuildOperationTypeValue, B as ImageOptions, N as NetworkConfig, E as OutputMode, F as PoolContainerInfo, G as ProcessStatus, J as SandboxImageSource, K as SandboxStatus, M as SnapshotContentMode, Q as SnapshotStatus, T as StdinMode, V as createSandboxImage, W as dockerfileContent } from './sandbox-image-B5Fa0xqb.js';
1
+ import { C as CreatePtySessionOptions, S as SandboxOptions, R as RunOptions, a as CommandResult, b as StartProcessOptions, P as ProcessInfo, c as SendSignalResponse, O as OutputResponse, d as OutputEvent, L as ListDirectoryResponse, e as PtySessionInfo, H as HealthResponse, D as DaemonInfo, f as SandboxClientOptions, g as CreateSandboxOptions, h as CreateSandboxResponse, i as SandboxInfo, U as UpdateSandboxOptions, j as SandboxPortAccess, k as SnapshotOptions, l as CreateSnapshotResponse, m as SnapshotInfo, n as SnapshotAndWaitOptions, o as CreatePoolOptions, p as CreateSandboxPoolResponse, q as SandboxPoolInfo, r as UpdatePoolOptions, s as CreateAndConnectOptions } from './sandbox-image-B130uMYt.js';
2
+ export { t as ContainerResourcesInfo, u as ContainerState, v as CreateSandboxImageOptions, w as DirectoryEntry, x as DockerfileBuildPlan, y as DockerfileInstruction, I as Image, z as ImageBuildOperation, A as ImageBuildOperationType, A as ImageBuildOperationTypeValue, B as ImageOptions, N as NetworkConfig, E as OutputMode, F as PoolContainerInfo, G as ProcessStatus, J as SandboxImageSource, K as SandboxStatus, M as SnapshotContentMode, Q as SnapshotStatus, T as StdinMode, V as createSandboxImage, W as dockerfileContent } from './sandbox-image-B130uMYt.js';
3
3
 
4
4
  type MouseButton = "left" | "middle" | "right";
5
5
  interface ConnectDesktopOptions {
@@ -157,6 +157,12 @@ declare class Sandbox {
157
157
  _setOwner(client: SandboxClient): void;
158
158
  close(): void;
159
159
  terminate(): Promise<void>;
160
+ /**
161
+ * Run a command to completion and return its output.
162
+ *
163
+ * Uses a single streaming `POST /api/v1/processes/run` request that starts
164
+ * the process, streams output, and delivers the exit code over one connection.
165
+ */
160
166
  run(command: string, options?: RunOptions): Promise<CommandResult>;
161
167
  startProcess(command: string, options?: StartProcessOptions): Promise<ProcessInfo>;
162
168
  listProcesses(): Promise<ProcessInfo[]>;
@@ -243,7 +249,7 @@ declare class SandboxClient {
243
249
  listPools(): Promise<SandboxPoolInfo[]>;
244
250
  updatePool(poolId: string, options: UpdatePoolOptions): Promise<SandboxPoolInfo>;
245
251
  deletePool(poolId: string): Promise<void>;
246
- connect(identifier: string, proxyUrl?: string): Sandbox;
252
+ connect(identifier: string, proxyUrl?: string, routingHint?: string): Sandbox;
247
253
  createAndConnect(options?: CreateAndConnectOptions): Promise<Sandbox>;
248
254
  }
249
255
 
package/dist/index.js CHANGED
@@ -114,6 +114,9 @@ var HttpClient = class {
114
114
  if (options.hostHeader) {
115
115
  this.headers["Host"] = options.hostHeader;
116
116
  }
117
+ if (options.routingHint) {
118
+ this.headers["X-Tensorlake-Route-Hint"] = options.routingHint;
119
+ }
117
120
  }
118
121
  close() {
119
122
  this.abortController?.abort();
@@ -148,12 +151,13 @@ var HttpClient = class {
148
151
  const buffer = await response.arrayBuffer();
149
152
  return new Uint8Array(buffer);
150
153
  }
151
- /** Make a request and return the raw Response (for SSE streaming). */
154
+ /** Make a request and return the response body as an SSE stream. */
152
155
  async requestStream(method, path2, options) {
153
156
  const response = await this.requestResponse(
154
157
  method,
155
158
  path2,
156
159
  {
160
+ json: options?.json,
157
161
  headers: { Accept: "text/event-stream" },
158
162
  signal: options?.signal
159
163
  }
@@ -3086,7 +3090,8 @@ var Sandbox = class {
3086
3090
  apiKey: options.apiKey,
3087
3091
  organizationId: options.organizationId,
3088
3092
  projectId: options.projectId,
3089
- hostHeader
3093
+ hostHeader,
3094
+ routingHint: options.routingHint
3090
3095
  });
3091
3096
  }
3092
3097
  /** @internal Used by SandboxClient.createAndConnect to set ownership. */
@@ -3107,37 +3112,45 @@ var Sandbox = class {
3107
3112
  }
3108
3113
  }
3109
3114
  // --- High-level convenience ---
3115
+ /**
3116
+ * Run a command to completion and return its output.
3117
+ *
3118
+ * Uses a single streaming `POST /api/v1/processes/run` request that starts
3119
+ * the process, streams output, and delivers the exit code over one connection.
3120
+ */
3110
3121
  async run(command, options) {
3111
- const proc = await this.startProcess(command, {
3112
- args: options?.args,
3113
- env: options?.env,
3114
- workingDir: options?.workingDir
3115
- });
3116
- const deadline = options?.timeout ? Date.now() + options.timeout * 1e3 : null;
3117
- let info;
3118
- while (true) {
3119
- info = await this.getProcess(proc.pid);
3120
- if (info.status !== "running" /* RUNNING */) break;
3121
- if (deadline && Date.now() > deadline) {
3122
- await this.killProcess(proc.pid);
3123
- throw new SandboxError(`Command timed out after ${options.timeout}s`);
3122
+ const body = { command };
3123
+ if (options?.args) body.args = options.args;
3124
+ if (options?.env) body.env = options.env;
3125
+ if (options?.workingDir) body.working_dir = options.workingDir;
3126
+ if (options?.timeout != null) body.timeout = options.timeout;
3127
+ const sseStream = await this.http.requestStream(
3128
+ "POST",
3129
+ "/api/v1/processes/run",
3130
+ { json: body }
3131
+ );
3132
+ const stdoutLines = [];
3133
+ const stderrLines = [];
3134
+ let exitCode = -1;
3135
+ for await (const raw of parseSSEStream(sseStream)) {
3136
+ if (typeof raw.line === "string") {
3137
+ if (raw.stream === "stderr") {
3138
+ stderrLines.push(raw.line);
3139
+ } else {
3140
+ stdoutLines.push(raw.line);
3141
+ }
3142
+ } else if ("exit_code" in raw || "signal" in raw) {
3143
+ if (typeof raw.exit_code === "number") {
3144
+ exitCode = raw.exit_code;
3145
+ } else if (typeof raw.signal === "number") {
3146
+ exitCode = -raw.signal;
3147
+ }
3124
3148
  }
3125
- await sleep2(100);
3126
- }
3127
- const stdoutResp = await this.getStdout(proc.pid);
3128
- const stderrResp = await this.getStderr(proc.pid);
3129
- let exitCode;
3130
- if (info.exitCode != null) {
3131
- exitCode = info.exitCode;
3132
- } else if (info.signal != null) {
3133
- exitCode = -info.signal;
3134
- } else {
3135
- exitCode = -1;
3136
3149
  }
3137
3150
  return {
3138
3151
  exitCode,
3139
- stdout: stdoutResp.lines.join("\n"),
3140
- stderr: stderrResp.lines.join("\n")
3152
+ stdout: stdoutLines.join("\n"),
3153
+ stderr: stderrLines.join("\n")
3141
3154
  };
3142
3155
  }
3143
3156
  // --- Process management ---
@@ -3386,9 +3399,6 @@ var Sandbox = class {
3386
3399
  return fromSnakeKeys(raw);
3387
3400
  }
3388
3401
  };
3389
- function sleep2(ms) {
3390
- return new Promise((resolve) => setTimeout(resolve, ms));
3391
- }
3392
3402
 
3393
3403
  // src/client.ts
3394
3404
  var SandboxClient = class _SandboxClient {
@@ -3604,7 +3614,7 @@ var SandboxClient = class _SandboxClient {
3604
3614
  `Snapshot ${result.snapshotId} failed: ${info.error}`
3605
3615
  );
3606
3616
  }
3607
- await sleep3(pollInterval * 1e3);
3617
+ await sleep2(pollInterval * 1e3);
3608
3618
  }
3609
3619
  throw new SandboxError(
3610
3620
  `Snapshot ${result.snapshotId} did not complete within ${timeout}s`
@@ -3676,14 +3686,15 @@ var SandboxClient = class _SandboxClient {
3676
3686
  );
3677
3687
  }
3678
3688
  // --- Connect ---
3679
- connect(identifier, proxyUrl) {
3689
+ connect(identifier, proxyUrl, routingHint) {
3680
3690
  const resolvedProxy = proxyUrl ?? resolveProxyUrl(this.apiUrl);
3681
3691
  return new Sandbox({
3682
3692
  sandboxId: identifier,
3683
3693
  proxyUrl: resolvedProxy,
3684
3694
  apiKey: this.apiKey,
3685
3695
  organizationId: this.organizationId,
3686
- projectId: this.projectId
3696
+ projectId: this.projectId,
3697
+ routingHint
3687
3698
  });
3688
3699
  }
3689
3700
  async createAndConnect(options) {
@@ -3694,6 +3705,11 @@ var SandboxClient = class _SandboxClient {
3694
3705
  } else {
3695
3706
  result = await this.create(options);
3696
3707
  }
3708
+ if (result.status === "running" /* RUNNING */) {
3709
+ const sandbox = this.connect(result.sandboxId, options?.proxyUrl, result.routingHint);
3710
+ sandbox._setOwner(this);
3711
+ return sandbox;
3712
+ }
3697
3713
  const deadline = Date.now() + startupTimeout * 1e3;
3698
3714
  while (Date.now() < deadline) {
3699
3715
  const info = await this.get(result.sandboxId);
@@ -3707,7 +3723,7 @@ var SandboxClient = class _SandboxClient {
3707
3723
  `Sandbox ${result.sandboxId} terminated during startup`
3708
3724
  );
3709
3725
  }
3710
- await sleep3(500);
3726
+ await sleep2(500);
3711
3727
  }
3712
3728
  try {
3713
3729
  await this.delete(result.sandboxId);
@@ -3718,7 +3734,7 @@ var SandboxClient = class _SandboxClient {
3718
3734
  );
3719
3735
  }
3720
3736
  };
3721
- function sleep3(ms) {
3737
+ function sleep2(ms) {
3722
3738
  return new Promise((resolve) => setTimeout(resolve, ms));
3723
3739
  }
3724
3740
  var RESERVED_SANDBOX_MANAGEMENT_PORT = 9501;
@@ -4600,7 +4616,7 @@ async function runChecked(sandbox, command, args, env, workingDir) {
4600
4616
  }
4601
4617
  return result;
4602
4618
  }
4603
- async function runStreaming(sandbox, emit, sleep4, command, args = [], env, workingDir) {
4619
+ async function runStreaming(sandbox, emit, sleep3, command, args = [], env, workingDir) {
4604
4620
  const proc = await sandbox.startProcess(command, {
4605
4621
  args,
4606
4622
  env,
@@ -4625,13 +4641,13 @@ async function runStreaming(sandbox, emit, sleep4, command, args = [], env, work
4625
4641
  emitOutputLines(emit, "stderr", finalStderr, stderrSeen);
4626
4642
  break;
4627
4643
  }
4628
- await sleep4(300);
4644
+ await sleep3(300);
4629
4645
  }
4630
4646
  for (let i = 0; i < 10; i++) {
4631
4647
  if (info.exitCode != null || info.signal != null) {
4632
4648
  break;
4633
4649
  }
4634
- await sleep4(200);
4650
+ await sleep3(200);
4635
4651
  info = await sandbox.getProcess(proc.pid);
4636
4652
  }
4637
4653
  const exitCode = info.exitCode != null ? info.exitCode : info.signal != null ? -info.signal : 0;
@@ -4729,7 +4745,7 @@ async function copyFromContext(sandbox, emit, contextDir, sources, destination,
4729
4745
  await copyLocalPathToSandbox(sandbox, localSource, remoteDestination);
4730
4746
  }
4731
4747
  }
4732
- async function addUrlToSandbox(sandbox, emit, url, destination, workingDir, processEnv, sleep4) {
4748
+ async function addUrlToSandbox(sandbox, emit, url, destination, workingDir, processEnv, sleep3) {
4733
4749
  let destinationPath = resolveContainerPath(destination, workingDir);
4734
4750
  const parsedUrl = new URL(url);
4735
4751
  const fileName = path.posix.basename(parsedUrl.pathname.replace(/\/$/, "")) || "downloaded";
@@ -4745,7 +4761,7 @@ async function addUrlToSandbox(sandbox, emit, url, destination, workingDir, proc
4745
4761
  await runStreaming(
4746
4762
  sandbox,
4747
4763
  emit,
4748
- sleep4,
4764
+ sleep3,
4749
4765
  "sh",
4750
4766
  [
4751
4767
  "-c",
@@ -4755,7 +4771,7 @@ async function addUrlToSandbox(sandbox, emit, url, destination, workingDir, proc
4755
4771
  workingDir
4756
4772
  );
4757
4773
  }
4758
- async function executeDockerfilePlan(sandbox, plan, emit, sleep4) {
4774
+ async function executeDockerfilePlan(sandbox, plan, emit, sleep3) {
4759
4775
  const processEnv = { ...BUILD_SANDBOX_PIP_ENV };
4760
4776
  let workingDir = "/";
4761
4777
  for (const instruction of plan.instructions) {
@@ -4765,7 +4781,7 @@ async function executeDockerfilePlan(sandbox, plan, emit, sleep4) {
4765
4781
  await runStreaming(
4766
4782
  sandbox,
4767
4783
  emit,
4768
- sleep4,
4784
+ sleep3,
4769
4785
  "sh",
4770
4786
  ["-c", value],
4771
4787
  processEnv,
@@ -4822,7 +4838,7 @@ async function executeDockerfilePlan(sandbox, plan, emit, sleep4) {
4822
4838
  destination,
4823
4839
  workingDir,
4824
4840
  processEnv,
4825
- sleep4
4841
+ sleep3
4826
4842
  );
4827
4843
  } else {
4828
4844
  await copyFromContext(
@@ -4890,7 +4906,7 @@ async function registerImage(context, name, dockerfile, snapshotId, snapshotUri,
4890
4906
  }
4891
4907
  async function createSandboxImage(source, options = {}, deps = {}) {
4892
4908
  const emit = deps.emit ?? defaultEmit;
4893
- const sleep4 = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
4909
+ const sleep3 = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
4894
4910
  const context = buildContextFromEnv();
4895
4911
  const clientFactory = deps.createClient ?? createDefaultClient;
4896
4912
  const register = deps.registerImage ?? ((...args) => registerImage(...args));
@@ -4913,7 +4929,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
4913
4929
  type: "status",
4914
4930
  message: `Materializing image in sandbox ${sandbox.sandboxId}...`
4915
4931
  });
4916
- await executeDockerfilePlan(sandbox, plan, emit, sleep4);
4932
+ await executeDockerfilePlan(sandbox, plan, emit, sleep3);
4917
4933
  emit({ type: "status", message: "Creating snapshot..." });
4918
4934
  const snapshot = await client.snapshotAndWait(sandbox.sandboxId, {
4919
4935
  contentMode: "filesystem_only"