tensorlake 0.5.126 → 0.5.128

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.
@@ -49,7 +49,7 @@ var init_defaults = __esm({
49
49
  "src/defaults.ts"() {
50
50
  "use strict";
51
51
  init_cjs_shims();
52
- SDK_VERSION = "0.5.126";
52
+ SDK_VERSION = "0.5.128";
53
53
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
54
54
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
55
55
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -84,6 +84,27 @@ function describeError(err) {
84
84
  if (parts.length > 0) return parts.join(": ");
85
85
  return err instanceof Error ? err.message : String(err);
86
86
  }
87
+ function formatErrorDetails(errorDetails) {
88
+ if (errorDetails == null) return void 0;
89
+ if (typeof errorDetails === "string") {
90
+ const detail = errorDetails.trim();
91
+ return detail || void 0;
92
+ }
93
+ if (Array.isArray(errorDetails)) {
94
+ const parts = errorDetails.map((item) => formatErrorDetails(item)).filter((item) => Boolean(item));
95
+ return parts.length > 0 ? parts.join("; ") : JSON.stringify(errorDetails);
96
+ }
97
+ if (typeof errorDetails === "object") {
98
+ for (const key of ["message", "detail", "error", "reason"]) {
99
+ const value = errorDetails[key];
100
+ if (typeof value === "string" && value.trim()) {
101
+ return value.trim();
102
+ }
103
+ }
104
+ return JSON.stringify(errorDetails);
105
+ }
106
+ return String(errorDetails);
107
+ }
87
108
  var SandboxException, SandboxError, SandboxConnectionError, SandboxNotFoundError, PoolNotFoundError, PoolInUseError, RemoteAPIError, RequestNotFinishedError, RequestFailedError, RequestExecutionError;
88
109
  var init_errors = __esm({
89
110
  "src/errors.ts"() {
@@ -135,9 +156,39 @@ var init_errors = __esm({
135
156
  };
136
157
  RemoteAPIError = class extends SandboxError {
137
158
  statusCode;
159
+ /** Original response body, retained for compatibility and diagnostics. */
138
160
  responseMessage;
161
+ sandboxId;
162
+ /** Server reason, including unknown future reasons. */
163
+ reason;
164
+ errorDetails;
139
165
  constructor(statusCode, message) {
140
- super(`API error (status ${statusCode}): ${message}`);
166
+ let failure;
167
+ try {
168
+ const payload = JSON.parse(message);
169
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
170
+ const record = payload;
171
+ if (typeof record.sandbox_id === "string" && record.sandbox_id.trim() && (record.status === "failed" || record.status === "terminated"))
172
+ failure = record;
173
+ }
174
+ } catch {
175
+ }
176
+ const sandboxId = failure?.sandbox_id;
177
+ const rawReason = failure?.reason ?? failure?.termination_reason;
178
+ const reason = typeof rawReason === "string" ? rawReason : void 0;
179
+ const errorDetails = failure?.error_details;
180
+ let displayMessage = message;
181
+ if (failure) {
182
+ displayMessage = `Sandbox ${sandboxId} ${failure.status}`;
183
+ if (reason) displayMessage += ` (${reason})`;
184
+ const detail = formatErrorDetails(errorDetails);
185
+ if (detail) displayMessage += `: ${detail}`;
186
+ if (!reason && !detail) displayMessage = message;
187
+ }
188
+ super(`API error (status ${statusCode}): ${displayMessage}`);
189
+ this.sandboxId = sandboxId;
190
+ this.reason = reason;
191
+ this.errorDetails = errorDetails;
141
192
  this.name = "RemoteAPIError";
142
193
  this.statusCode = statusCode;
143
194
  this.responseMessage = message;
@@ -3664,13 +3715,15 @@ init_cloud_client();
3664
3715
 
3665
3716
  // src/filesystem.ts
3666
3717
  init_cjs_shims();
3667
- var import_node_child_process = require("child_process");
3668
3718
  var import_node_crypto5 = require("crypto");
3719
+
3720
+ // src/mount-cli.ts
3721
+ init_cjs_shims();
3722
+ var import_node_child_process = require("child_process");
3669
3723
  var import_node_fs2 = require("fs");
3670
3724
  var import_node_os2 = require("os");
3671
3725
  var import_node_path3 = require("path");
3672
3726
  var import_node_util2 = require("util");
3673
- init_defaults();
3674
3727
 
3675
3728
  // src/filesystem-models.ts
3676
3729
  init_cjs_shims();
@@ -3750,14 +3803,71 @@ var ReadOnlyMountNotSupportedError = class extends MountError {
3750
3803
  }
3751
3804
  };
3752
3805
  var CliNotFoundError = class extends MountError {
3753
- constructor(detail) {
3806
+ constructor(detail, command = "fs") {
3754
3807
  super(
3755
- `Mount operations require the Tensorlake CLI (\`tl\`) with \`tl fs\` support: ${detail}. Install or upgrade it with: curl -fsSL https://tensorlake.ai/install.sh | sh`
3808
+ `Mount operations require the Tensorlake CLI (\`tl\`) with \`tl ${command}\` support: ${detail}. Install or upgrade it with: curl -fsSL https://tensorlake.ai/install.sh | sh`
3756
3809
  );
3757
3810
  this.name = "CliNotFoundError";
3758
3811
  }
3759
3812
  };
3760
3813
 
3814
+ // src/mount-cli.ts
3815
+ var execFileAsync = (0, import_node_util2.promisify)(import_node_child_process.execFile);
3816
+ var MountCli = class {
3817
+ constructor(command, envOverrides) {
3818
+ this.command = command;
3819
+ this.envOverrides = envOverrides;
3820
+ }
3821
+ binary = null;
3822
+ async findCli() {
3823
+ const candidates = [];
3824
+ if (process.env.TENSORLAKE_CLI) candidates.push(process.env.TENSORLAKE_CLI);
3825
+ candidates.push("tl");
3826
+ const installed = (0, import_node_path3.join)((0, import_node_os2.homedir)(), ".tensorlake", "bin", "tl");
3827
+ try {
3828
+ (0, import_node_fs2.accessSync)(installed, import_node_fs2.constants.F_OK);
3829
+ candidates.push(installed);
3830
+ } catch {
3831
+ }
3832
+ const support = this.command === "git" ? "git mount" : "fs";
3833
+ const probe = this.command === "git" ? ["git", "mount", "--help"] : ["fs", "--help"];
3834
+ let unsupported = null;
3835
+ for (const candidate of candidates) {
3836
+ try {
3837
+ await execFileAsync(candidate, probe, { timeout: 15e3 });
3838
+ return candidate;
3839
+ } catch (error) {
3840
+ if (error.code !== "ENOENT") unsupported = candidate;
3841
+ }
3842
+ }
3843
+ throw new CliNotFoundError(
3844
+ unsupported ? `\`tl\` at ${unsupported} does not support \`tl ${support}\` (upgrade required)` : "`tl` was not found on PATH",
3845
+ support
3846
+ );
3847
+ }
3848
+ async run(args, timeoutMs = 3e5) {
3849
+ if (this.binary === null) this.binary = await this.findCli();
3850
+ try {
3851
+ const { stdout } = await execFileAsync(this.binary, [this.command, ...args], {
3852
+ timeout: timeoutMs,
3853
+ env: { ...process.env, ...this.envOverrides },
3854
+ maxBuffer: 16 * 1024 * 1024
3855
+ });
3856
+ return stdout;
3857
+ } catch (error) {
3858
+ const failure = error;
3859
+ if (failure.killed) {
3860
+ throw new MountError(`\`tl ${this.command} ${args[0]}\` timed out after ${timeoutMs}ms`);
3861
+ }
3862
+ const detail = (failure.stderr || failure.stdout || String(error)).trim();
3863
+ throw new MountError(`\`tl ${this.command} ${args.join(" ")}\` failed: ${detail}`);
3864
+ }
3865
+ }
3866
+ };
3867
+
3868
+ // src/filesystem.ts
3869
+ init_defaults();
3870
+
3761
3871
  // src/native-sandbox.ts
3762
3872
  init_cjs_shims();
3763
3873
  init_errors();
@@ -3981,7 +4091,7 @@ function createWorkerBinding(runtime) {
3981
4091
  };
3982
4092
  }
3983
4093
  var runtimeKey = /* @__PURE__ */ Symbol.for(
3984
- `tensorlake.native.worker.${false ? "source" : "0.5.126"}.v1`
4094
+ `tensorlake.native.worker.${false ? "source" : "0.5.128"}.v1`
3985
4095
  );
3986
4096
  var runtimes = globalThis;
3987
4097
  function workerBinding() {
@@ -3998,7 +4108,6 @@ function loadNativeSandboxBinding() {
3998
4108
 
3999
4109
  // src/filesystem.ts
4000
4110
  init_sandbox_image();
4001
- var execFileAsync = (0, import_node_util2.promisify)(import_node_child_process.execFile);
4002
4111
  var FILESYSTEM_REPO_KIND = "filesystem";
4003
4112
  function translateNativeError(error, notFound) {
4004
4113
  const message = error instanceof Error ? error.message : String(error);
@@ -4030,58 +4139,9 @@ async function callNative(fn, notFound) {
4030
4139
  throw translateNativeError(error, notFound);
4031
4140
  }
4032
4141
  }
4033
- var FsCli = class {
4034
- binary = null;
4035
- envOverrides;
4142
+ var FsCli = class extends MountCli {
4036
4143
  constructor(envOverrides) {
4037
- this.envOverrides = envOverrides;
4038
- }
4039
- async findCli() {
4040
- const candidates = [];
4041
- if (process.env.TENSORLAKE_CLI) {
4042
- candidates.push(process.env.TENSORLAKE_CLI);
4043
- }
4044
- candidates.push("tl");
4045
- const installed = (0, import_node_path3.join)((0, import_node_os2.homedir)(), ".tensorlake", "bin", "tl");
4046
- try {
4047
- (0, import_node_fs2.accessSync)(installed, import_node_fs2.constants.F_OK);
4048
- candidates.push(installed);
4049
- } catch {
4050
- }
4051
- let unsupported = null;
4052
- for (const candidate of candidates) {
4053
- try {
4054
- await execFileAsync(candidate, ["fs", "--help"], { timeout: 15e3 });
4055
- return candidate;
4056
- } catch (error) {
4057
- if (error.code !== "ENOENT") {
4058
- unsupported = candidate;
4059
- }
4060
- }
4061
- }
4062
- throw new CliNotFoundError(
4063
- unsupported ? `\`tl\` at ${unsupported} does not support \`tl fs\` (upgrade required)` : "`tl` was not found on PATH"
4064
- );
4065
- }
4066
- async run(args, timeoutMs = 3e5) {
4067
- if (this.binary === null) {
4068
- this.binary = await this.findCli();
4069
- }
4070
- try {
4071
- const { stdout } = await execFileAsync(this.binary, ["fs", ...args], {
4072
- timeout: timeoutMs,
4073
- env: { ...process.env, ...this.envOverrides },
4074
- maxBuffer: 16 * 1024 * 1024
4075
- });
4076
- return stdout;
4077
- } catch (error) {
4078
- const failure = error;
4079
- if (failure.killed) {
4080
- throw new MountError(`\`tl fs ${args[0]}\` timed out after ${timeoutMs}ms`);
4081
- }
4082
- const detail = (failure.stderr || failure.stdout || String(error)).trim();
4083
- throw new MountError(`\`tl fs ${args.join(" ")}\` failed: ${detail}`);
4084
- }
4144
+ super("fs", envOverrides);
4085
4145
  }
4086
4146
  // Flags always precede a `--` end-of-options separator so caller-supplied
4087
4147
  // names/paths can never be parsed as CLI flags (e.g. a path literally