tensorlake 0.5.13 → 0.5.17

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.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TI
35
35
  var init_defaults = __esm({
36
36
  "src/defaults.ts"() {
37
37
  "use strict";
38
- SDK_VERSION = "0.5.13";
38
+ SDK_VERSION = "0.5.17";
39
39
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
40
40
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
41
41
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -2995,6 +2995,15 @@ var init_url = __esm({
2995
2995
  });
2996
2996
 
2997
2997
  // src/sandbox.ts
2998
+ function processUserPayload(user) {
2999
+ if (user == null) {
3000
+ return DEFAULT_PROCESS_USER;
3001
+ }
3002
+ if (typeof user === "string" && user.trim() === "") {
3003
+ throw new SandboxError("process user must not be empty");
3004
+ }
3005
+ return user;
3006
+ }
2998
3007
  function normalizePtyMessage(message) {
2999
3008
  if (Buffer.isBuffer(message)) return message;
3000
3009
  if (Array.isArray(message)) {
@@ -3018,7 +3027,7 @@ function sendPtyFrame(socket, frame) {
3018
3027
  socket.send(frame, (error) => error ? reject(error) : resolve());
3019
3028
  });
3020
3029
  }
3021
- var import_ws2, PTY_OP_DATA, PTY_OP_RESIZE, PTY_OP_READY, PTY_OP_EXIT, Pty, Sandbox;
3030
+ var import_ws2, DEFAULT_PROCESS_USER, PTY_OP_DATA, PTY_OP_RESIZE, PTY_OP_READY, PTY_OP_EXIT, Pty, Sandbox;
3022
3031
  var init_sandbox = __esm({
3023
3032
  "src/sandbox.ts"() {
3024
3033
  "use strict";
@@ -3031,6 +3040,7 @@ var init_sandbox = __esm({
3031
3040
  init_sse();
3032
3041
  init_url();
3033
3042
  import_ws2 = __toESM(require("ws"), 1);
3043
+ DEFAULT_PROCESS_USER = "tl-user";
3034
3044
  PTY_OP_DATA = 0;
3035
3045
  PTY_OP_RESIZE = 1;
3036
3046
  PTY_OP_READY = 2;
@@ -3451,6 +3461,8 @@ var init_sandbox = __esm({
3451
3461
  if (options?.env) body.env = options.env;
3452
3462
  if (options?.workingDir) body.working_dir = options.workingDir;
3453
3463
  if (options?.timeout != null) body.timeout = options.timeout;
3464
+ const user = processUserPayload(options?.user);
3465
+ body.user = user;
3454
3466
  const sseStream = await this.http.requestStream(
3455
3467
  "POST",
3456
3468
  "/api/v1/processes/run",
@@ -3494,6 +3506,8 @@ var init_sandbox = __esm({
3494
3506
  if (options?.args != null) payload.args = options.args;
3495
3507
  if (options?.env != null) payload.env = options.env;
3496
3508
  if (options?.workingDir != null) payload.working_dir = options.workingDir;
3509
+ const user = processUserPayload(options?.user);
3510
+ payload.user = user;
3497
3511
  if (options?.stdinMode != null && options.stdinMode !== "closed" /* CLOSED */) {
3498
3512
  payload.stdin_mode = options.stdinMode;
3499
3513
  }
@@ -5077,12 +5091,16 @@ function optionalNumber(object, key) {
5077
5091
  }
5078
5092
  return value;
5079
5093
  }
5080
- async function runChecked(sandbox, command, args, env, workingDir) {
5081
- const result = await sandbox.run(command, {
5094
+ async function runChecked(sandbox, command, args, env, workingDir, user) {
5095
+ const options = {
5082
5096
  args,
5083
5097
  env,
5084
5098
  workingDir
5085
- });
5099
+ };
5100
+ if (user != null) {
5101
+ options.user = user;
5102
+ }
5103
+ const result = await sandbox.run(command, options);
5086
5104
  if (result.exitCode !== 0) {
5087
5105
  throw new Error(
5088
5106
  `Command '${command} ${args.join(" ")}' failed with exit code ${result.exitCode}`
@@ -5094,7 +5112,8 @@ async function runStreaming(sandbox, emit, sleep3, command, args = [], env, work
5094
5112
  const proc = await sandbox.startProcess(command, {
5095
5113
  args,
5096
5114
  env,
5097
- workingDir
5115
+ workingDir,
5116
+ user: ROOTFS_BUILDER_PROCESS_USER
5098
5117
  });
5099
5118
  let stdoutSeen = 0;
5100
5119
  let stderrSeen = 0;
@@ -5136,13 +5155,37 @@ function emitOutputLines(emit, stream, response, seen) {
5136
5155
  emit({ type: "build_log", stream, message: line });
5137
5156
  }
5138
5157
  }
5158
+ async function ensureRemoteBuildRoot(sandbox) {
5159
+ await runChecked(
5160
+ sandbox,
5161
+ "mkdir",
5162
+ ["-p", REMOTE_BUILD_DIR],
5163
+ void 0,
5164
+ void 0,
5165
+ ROOTFS_BUILDER_PROCESS_USER
5166
+ );
5167
+ await runChecked(
5168
+ sandbox,
5169
+ "chmod",
5170
+ ["0777", REMOTE_BUILD_DIR],
5171
+ void 0,
5172
+ void 0,
5173
+ ROOTFS_BUILDER_PROCESS_USER
5174
+ );
5175
+ }
5176
+ async function ensureRemoteDirectory(sandbox, remotePath) {
5177
+ await runChecked(sandbox, "mkdir", ["-p", remotePath]);
5178
+ }
5179
+ async function ensureRemoteParentDir(sandbox, remotePath) {
5180
+ await ensureRemoteDirectory(sandbox, import_node_path.default.posix.dirname(remotePath));
5181
+ }
5139
5182
  async function copyLocalPathToSandbox(sandbox, localPath, remotePath) {
5140
5183
  const fileStats = await (0, import_promises.stat)(localPath).catch(() => null);
5141
5184
  if (!fileStats) {
5142
5185
  throw new Error(`Local path not found: ${localPath}`);
5143
5186
  }
5144
5187
  if (fileStats.isFile()) {
5145
- await runChecked(sandbox, "mkdir", ["-p", import_node_path.default.posix.dirname(remotePath)]);
5188
+ await ensureRemoteParentDir(sandbox, remotePath);
5146
5189
  await sandbox.writeFile(remotePath, await (0, import_promises.readFile)(localPath));
5147
5190
  return;
5148
5191
  }
@@ -5154,14 +5197,10 @@ async function copyLocalPathToSandbox(sandbox, localPath, remotePath) {
5154
5197
  const sourcePath = import_node_path.default.join(localPath, entry.name);
5155
5198
  const destinationPath = import_node_path.default.posix.join(remotePath, entry.name);
5156
5199
  if (entry.isDirectory()) {
5157
- await runChecked(sandbox, "mkdir", ["-p", destinationPath]);
5200
+ await ensureRemoteDirectory(sandbox, destinationPath);
5158
5201
  await copyLocalPathToSandbox(sandbox, sourcePath, destinationPath);
5159
5202
  } else if (entry.isFile()) {
5160
- await runChecked(
5161
- sandbox,
5162
- "mkdir",
5163
- ["-p", import_node_path.default.posix.dirname(destinationPath)]
5164
- );
5203
+ await ensureRemoteParentDir(sandbox, destinationPath);
5165
5204
  await sandbox.writeFile(destinationPath, await (0, import_promises.readFile)(sourcePath));
5166
5205
  }
5167
5206
  }
@@ -5258,6 +5297,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
5258
5297
  message: `Rootfs builder sandbox ${sandbox.sandboxId} is running`
5259
5298
  });
5260
5299
  emit({ type: "status", message: "Uploading build context..." });
5300
+ await ensureRemoteBuildRoot(sandbox);
5261
5301
  await copyLocalPathToSandbox(sandbox, plan.contextDir, REMOTE_CONTEXT_DIR);
5262
5302
  const spec = await buildRootfsSpec(
5263
5303
  preparedSpec,
@@ -5265,7 +5305,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
5265
5305
  plan,
5266
5306
  options.diskMb
5267
5307
  );
5268
- await runChecked(sandbox, "mkdir", ["-p", import_node_path.default.posix.dirname(REMOTE_SPEC_PATH)]);
5308
+ await ensureRemoteParentDir(sandbox, REMOTE_SPEC_PATH);
5269
5309
  await sandbox.writeFile(
5270
5310
  REMOTE_SPEC_PATH,
5271
5311
  new TextEncoder().encode(JSON.stringify(spec, null, 2))
@@ -5348,7 +5388,7 @@ async function runCreateSandboxImageCli(argv = process.argv.slice(2)) {
5348
5388
  { emit: ndjsonStdoutEmit }
5349
5389
  );
5350
5390
  }
5351
- var import_promises, import_node_os, import_node_path, import_node_util, DEFAULT_ROOTFS_DISK_MB, REMOTE_BUILD_DIR, REMOTE_CONTEXT_DIR, REMOTE_SPEC_PATH, REMOTE_METADATA_PATH, ROOTFS_BUILDER_BIN_DIR, ROOTFS_BUILDER_PATH, ROOTFS_BUILDER_COMMAND, UNSUPPORTED_DOCKERFILE_INSTRUCTIONS;
5391
+ var import_promises, import_node_os, import_node_path, import_node_util, DEFAULT_ROOTFS_DISK_MB, REMOTE_BUILD_DIR, REMOTE_CONTEXT_DIR, REMOTE_SPEC_PATH, REMOTE_METADATA_PATH, ROOTFS_BUILDER_BIN_DIR, ROOTFS_BUILDER_PATH, ROOTFS_BUILDER_COMMAND, ROOTFS_BUILDER_PROCESS_USER, UNSUPPORTED_DOCKERFILE_INSTRUCTIONS;
5352
5392
  var init_sandbox_image = __esm({
5353
5393
  "src/sandbox-image.ts"() {
5354
5394
  "use strict";
@@ -5367,6 +5407,7 @@ var init_sandbox_image = __esm({
5367
5407
  ROOTFS_BUILDER_BIN_DIR = "/usr/local/bin";
5368
5408
  ROOTFS_BUILDER_PATH = "/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
5369
5409
  ROOTFS_BUILDER_COMMAND = "tl-rootfs-build";
5410
+ ROOTFS_BUILDER_PROCESS_USER = "root";
5370
5411
  UNSUPPORTED_DOCKERFILE_INSTRUCTIONS = /* @__PURE__ */ new Set([
5371
5412
  "ARG",
5372
5413
  "ONBUILD",