tensorlake 0.5.29 → 0.5.30
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/bin/darwin-arm64/tensorlake +0 -0
- package/dist/bin/darwin-arm64/tl +0 -0
- package/dist/bin/linux-x64/tensorlake +0 -0
- package/dist/bin/linux-x64/tl +0 -0
- package/dist/bin/win32-x64/tensorlake.exe +0 -0
- package/dist/bin/win32-x64/tl.exe +0 -0
- package/dist/index.cjs +137 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -6
- package/dist/index.d.ts +24 -6
- package/dist/index.js +135 -41
- package/dist/index.js.map +1 -1
- package/dist/native/darwin-arm64/tensorlake-node.node +0 -0
- package/dist/native/linux-x64/tensorlake-node.node +0 -0
- package/dist/native/win32-x64/tensorlake-node.node +0 -0
- package/package.json +1 -1
|
Binary file
|
package/dist/bin/darwin-arm64/tl
CHANGED
|
Binary file
|
|
Binary file
|
package/dist/bin/linux-x64/tl
CHANGED
|
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.
|
|
38
|
+
SDK_VERSION = "0.5.30";
|
|
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";
|
|
@@ -2969,6 +2969,14 @@ function resolveProxyTarget(proxyUrl, sandboxId) {
|
|
|
2969
2969
|
};
|
|
2970
2970
|
}
|
|
2971
2971
|
}
|
|
2972
|
+
function sandboxUrlFromIngressEndpoint(ingressEndpoint, sandboxId, port = 9501) {
|
|
2973
|
+
const parsed = new URL(ingressEndpoint);
|
|
2974
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
2975
|
+
throw new Error("ingressEndpoint must be an absolute http(s) URL");
|
|
2976
|
+
}
|
|
2977
|
+
const label = port === 9501 ? sandboxId : `${port}-${sandboxId}`;
|
|
2978
|
+
return `${parsed.protocol}//${label}.${parsed.host}`;
|
|
2979
|
+
}
|
|
2972
2980
|
function resolveSandboxLifecycleUrl(apiUrl) {
|
|
2973
2981
|
if (isLocalhost(apiUrl)) return apiUrl;
|
|
2974
2982
|
try {
|
|
@@ -3027,7 +3035,7 @@ function sendPtyFrame(socket, frame) {
|
|
|
3027
3035
|
socket.send(frame, (error) => error ? reject(error) : resolve());
|
|
3028
3036
|
});
|
|
3029
3037
|
}
|
|
3030
|
-
var import_ws2, DEFAULT_PROCESS_USER, PTY_OP_DATA, PTY_OP_RESIZE, PTY_OP_READY, PTY_OP_EXIT, Pty, Sandbox;
|
|
3038
|
+
var import_ws2, DEFAULT_PROCESS_USER, SandboxProxyConnection, PTY_OP_DATA, PTY_OP_RESIZE, PTY_OP_READY, PTY_OP_EXIT, Pty, Sandbox;
|
|
3031
3039
|
var init_sandbox = __esm({
|
|
3032
3040
|
"src/sandbox.ts"() {
|
|
3033
3041
|
"use strict";
|
|
@@ -3041,6 +3049,98 @@ var init_sandbox = __esm({
|
|
|
3041
3049
|
init_url();
|
|
3042
3050
|
import_ws2 = __toESM(require("ws"), 1);
|
|
3043
3051
|
DEFAULT_PROCESS_USER = "tl-user";
|
|
3052
|
+
SandboxProxyConnection = class {
|
|
3053
|
+
constructor(sandbox, options) {
|
|
3054
|
+
this.sandbox = sandbox;
|
|
3055
|
+
this.options = options;
|
|
3056
|
+
this.routingHint = options.routingHint;
|
|
3057
|
+
this.http = this.configureProxy(
|
|
3058
|
+
options.proxyUrl ?? SANDBOX_PROXY_URL,
|
|
3059
|
+
options.sandboxId,
|
|
3060
|
+
options.routingHint
|
|
3061
|
+
);
|
|
3062
|
+
this.resolveProxyInfo = options.resolveProxyInfo;
|
|
3063
|
+
}
|
|
3064
|
+
baseUrl = "";
|
|
3065
|
+
wsHeaders = {};
|
|
3066
|
+
http;
|
|
3067
|
+
resolveProxyInfo;
|
|
3068
|
+
resolvePromise = null;
|
|
3069
|
+
routingHint;
|
|
3070
|
+
async ensureResolved() {
|
|
3071
|
+
if (this.resolveProxyInfo == null) {
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3074
|
+
if (this.resolvePromise != null) {
|
|
3075
|
+
return this.resolvePromise;
|
|
3076
|
+
}
|
|
3077
|
+
this.resolvePromise = this.resolveProxyInfo(this.sandbox._getLifecycleIdentifier()).then((info) => {
|
|
3078
|
+
this.resolveProxyInfo = void 0;
|
|
3079
|
+
this.sandbox.traceId = info.traceId;
|
|
3080
|
+
this.sandbox._setLifecycleIdentifier(info.sandboxId);
|
|
3081
|
+
this.sandbox._setName(info.name ?? null);
|
|
3082
|
+
this.routingHint = this.routingHint ?? info.routingHint;
|
|
3083
|
+
const proxyUrl = info.ingressEndpoint ?? this.options.proxyUrl ?? SANDBOX_PROXY_URL;
|
|
3084
|
+
const nextHttp = this.configureProxy(proxyUrl, info.sandboxId, this.routingHint);
|
|
3085
|
+
this.http.close();
|
|
3086
|
+
this.http = nextHttp;
|
|
3087
|
+
}).finally(() => {
|
|
3088
|
+
this.resolvePromise = null;
|
|
3089
|
+
});
|
|
3090
|
+
return this.resolvePromise;
|
|
3091
|
+
}
|
|
3092
|
+
async requestJson(method, path2, options) {
|
|
3093
|
+
await this.ensureResolved();
|
|
3094
|
+
return this.http.requestJson(method, path2, options);
|
|
3095
|
+
}
|
|
3096
|
+
async requestBytes(method, path2, options) {
|
|
3097
|
+
await this.ensureResolved();
|
|
3098
|
+
return this.http.requestBytes(method, path2, options);
|
|
3099
|
+
}
|
|
3100
|
+
async requestStream(method, path2, options) {
|
|
3101
|
+
await this.ensureResolved();
|
|
3102
|
+
return this.http.requestStream(method, path2, options);
|
|
3103
|
+
}
|
|
3104
|
+
async requestResponse(method, path2, options) {
|
|
3105
|
+
await this.ensureResolved();
|
|
3106
|
+
return this.http.requestResponse(method, path2, options);
|
|
3107
|
+
}
|
|
3108
|
+
close() {
|
|
3109
|
+
this.http.close();
|
|
3110
|
+
}
|
|
3111
|
+
configureProxy(proxyUrl, sandboxId, routingHint) {
|
|
3112
|
+
const { baseUrl, hostHeader, sandboxIdHeader } = resolveProxyTarget(
|
|
3113
|
+
proxyUrl,
|
|
3114
|
+
sandboxId
|
|
3115
|
+
);
|
|
3116
|
+
this.baseUrl = baseUrl;
|
|
3117
|
+
this.wsHeaders = {};
|
|
3118
|
+
if (this.options.apiKey) {
|
|
3119
|
+
this.wsHeaders.Authorization = `Bearer ${this.options.apiKey}`;
|
|
3120
|
+
}
|
|
3121
|
+
if (this.options.organizationId) {
|
|
3122
|
+
this.wsHeaders["X-Forwarded-Organization-Id"] = this.options.organizationId;
|
|
3123
|
+
}
|
|
3124
|
+
if (this.options.projectId) {
|
|
3125
|
+
this.wsHeaders["X-Forwarded-Project-Id"] = this.options.projectId;
|
|
3126
|
+
}
|
|
3127
|
+
if (hostHeader) {
|
|
3128
|
+
this.wsHeaders.Host = hostHeader;
|
|
3129
|
+
}
|
|
3130
|
+
if (sandboxIdHeader) {
|
|
3131
|
+
this.wsHeaders["X-Tensorlake-Sandbox-Id"] = sandboxIdHeader;
|
|
3132
|
+
}
|
|
3133
|
+
return new HttpClient({
|
|
3134
|
+
baseUrl,
|
|
3135
|
+
apiKey: this.options.apiKey,
|
|
3136
|
+
organizationId: this.options.organizationId,
|
|
3137
|
+
projectId: this.options.projectId,
|
|
3138
|
+
hostHeader,
|
|
3139
|
+
sandboxIdHeader,
|
|
3140
|
+
routingHint
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
};
|
|
3044
3144
|
PTY_OP_DATA = 0;
|
|
3045
3145
|
PTY_OP_RESIZE = 1;
|
|
3046
3146
|
PTY_OP_READY = 2;
|
|
@@ -3206,9 +3306,8 @@ var init_sandbox = __esm({
|
|
|
3206
3306
|
Sandbox = class {
|
|
3207
3307
|
sandboxId;
|
|
3208
3308
|
traceId = null;
|
|
3309
|
+
proxy;
|
|
3209
3310
|
http;
|
|
3210
|
-
baseUrl;
|
|
3211
|
-
wsHeaders;
|
|
3212
3311
|
ownsSandbox = false;
|
|
3213
3312
|
lifecycleClient = null;
|
|
3214
3313
|
lifecycleIdentifier;
|
|
@@ -3216,34 +3315,14 @@ var init_sandbox = __esm({
|
|
|
3216
3315
|
constructor(options) {
|
|
3217
3316
|
this.sandboxId = options.sandboxId;
|
|
3218
3317
|
this.lifecycleIdentifier = options.sandboxId;
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
this.wsHeaders["X-Forwarded-Organization-Id"] = options.organizationId;
|
|
3228
|
-
}
|
|
3229
|
-
if (options.projectId) {
|
|
3230
|
-
this.wsHeaders["X-Forwarded-Project-Id"] = options.projectId;
|
|
3231
|
-
}
|
|
3232
|
-
if (hostHeader) {
|
|
3233
|
-
this.wsHeaders.Host = hostHeader;
|
|
3234
|
-
}
|
|
3235
|
-
if (sandboxIdHeader) {
|
|
3236
|
-
this.wsHeaders["X-Tensorlake-Sandbox-Id"] = sandboxIdHeader;
|
|
3237
|
-
}
|
|
3238
|
-
this.http = new HttpClient({
|
|
3239
|
-
baseUrl,
|
|
3240
|
-
apiKey: options.apiKey,
|
|
3241
|
-
organizationId: options.organizationId,
|
|
3242
|
-
projectId: options.projectId,
|
|
3243
|
-
hostHeader,
|
|
3244
|
-
sandboxIdHeader,
|
|
3245
|
-
routingHint: options.routingHint
|
|
3246
|
-
});
|
|
3318
|
+
this.proxy = new SandboxProxyConnection(this, options);
|
|
3319
|
+
this.http = this.proxy;
|
|
3320
|
+
}
|
|
3321
|
+
get baseUrl() {
|
|
3322
|
+
return this.proxy.baseUrl;
|
|
3323
|
+
}
|
|
3324
|
+
get wsHeaders() {
|
|
3325
|
+
return this.proxy.wsHeaders;
|
|
3247
3326
|
}
|
|
3248
3327
|
get name() {
|
|
3249
3328
|
return this.sandboxName;
|
|
@@ -3256,6 +3335,10 @@ var init_sandbox = __esm({
|
|
|
3256
3335
|
_setLifecycleIdentifier(identifier) {
|
|
3257
3336
|
this.lifecycleIdentifier = identifier;
|
|
3258
3337
|
}
|
|
3338
|
+
/** @internal Used by the lazy proxy resolver. */
|
|
3339
|
+
_getLifecycleIdentifier() {
|
|
3340
|
+
return this.lifecycleIdentifier;
|
|
3341
|
+
}
|
|
3259
3342
|
/** @internal Used by SandboxClient.createAndConnect to set ownership. */
|
|
3260
3343
|
_setOwner(client) {
|
|
3261
3344
|
this.ownsSandbox = true;
|
|
@@ -3282,9 +3365,9 @@ var init_sandbox = __esm({
|
|
|
3282
3365
|
/**
|
|
3283
3366
|
* Attach to an existing sandbox and return a connected handle.
|
|
3284
3367
|
*
|
|
3285
|
-
*
|
|
3286
|
-
*
|
|
3287
|
-
* sandbox — call `sandbox.resume()` explicitly.
|
|
3368
|
+
* When `proxyUrl` is omitted, resolves the sandbox first so the handle uses
|
|
3369
|
+
* the correct cloud/region ingress endpoint. Does **not** auto-resume a
|
|
3370
|
+
* suspended sandbox — call `sandbox.resume()` explicitly.
|
|
3288
3371
|
*/
|
|
3289
3372
|
static async connect(options) {
|
|
3290
3373
|
const { SandboxClient: SandboxClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
@@ -3698,6 +3781,7 @@ var init_sandbox = __esm({
|
|
|
3698
3781
|
}
|
|
3699
3782
|
/** Attach to an existing PTY session by ID and token and return a connected `Pty` handle. */
|
|
3700
3783
|
async connectPty(sessionId, token, options) {
|
|
3784
|
+
await this.proxy.ensureResolved();
|
|
3701
3785
|
const wsUrl = new URL(this.ptyWsUrl(sessionId, token));
|
|
3702
3786
|
const authToken = wsUrl.searchParams.get("token") ?? token;
|
|
3703
3787
|
const pty = new Pty({
|
|
@@ -3723,6 +3807,7 @@ var init_sandbox = __esm({
|
|
|
3723
3807
|
}
|
|
3724
3808
|
/** Open a TCP tunnel to a port inside the sandbox and return the local listener. */
|
|
3725
3809
|
async createTunnel(remotePort, options) {
|
|
3810
|
+
await this.proxy.ensureResolved();
|
|
3726
3811
|
return TcpTunnel.listen({
|
|
3727
3812
|
baseUrl: this.baseUrl,
|
|
3728
3813
|
wsHeaders: this.wsHeaders,
|
|
@@ -3734,6 +3819,7 @@ var init_sandbox = __esm({
|
|
|
3734
3819
|
}
|
|
3735
3820
|
/** Connect to a sandbox VNC session for programmatic desktop control. */
|
|
3736
3821
|
async connectDesktop(options) {
|
|
3822
|
+
await this.proxy.ensureResolved();
|
|
3737
3823
|
const port = options?.port ?? 5901;
|
|
3738
3824
|
const connectTimeout = options?.connectTimeout ?? 10;
|
|
3739
3825
|
const startMs = Date.now();
|
|
@@ -4053,6 +4139,7 @@ var init_client = __esm({
|
|
|
4053
4139
|
return {
|
|
4054
4140
|
allowUnauthenticatedAccess: info.allowUnauthenticatedAccess ?? false,
|
|
4055
4141
|
exposedPorts: dedupeAndSortPorts(info.exposedPorts ?? []),
|
|
4142
|
+
ingressEndpoint: info.ingressEndpoint,
|
|
4056
4143
|
sandboxUrl: info.sandboxUrl
|
|
4057
4144
|
};
|
|
4058
4145
|
}
|
|
@@ -4326,7 +4413,8 @@ var init_client = __esm({
|
|
|
4326
4413
|
apiKey: this.apiKey,
|
|
4327
4414
|
organizationId: this.organizationId,
|
|
4328
4415
|
projectId: this.projectId,
|
|
4329
|
-
routingHint
|
|
4416
|
+
routingHint,
|
|
4417
|
+
resolveProxyInfo: proxyUrl == null ? async (currentIdentifier) => this.get(currentIdentifier) : void 0
|
|
4330
4418
|
});
|
|
4331
4419
|
}
|
|
4332
4420
|
/**
|
|
@@ -4342,8 +4430,12 @@ var init_client = __esm({
|
|
|
4342
4430
|
const startupTimeout = options?.startupTimeout ?? 60;
|
|
4343
4431
|
const result = options?.poolId != null ? await this.claim(options.poolId) : await this.create(options);
|
|
4344
4432
|
const requestedName = options?.poolId != null ? null : options?.name ?? null;
|
|
4345
|
-
const finishConnect = (routingHint, name) => {
|
|
4346
|
-
const sandbox = this.connect(
|
|
4433
|
+
const finishConnect = (routingHint, name, ingressEndpoint) => {
|
|
4434
|
+
const sandbox = this.connect(
|
|
4435
|
+
result.sandboxId,
|
|
4436
|
+
options?.proxyUrl ?? ingressEndpoint,
|
|
4437
|
+
routingHint
|
|
4438
|
+
);
|
|
4347
4439
|
sandbox._setOwner(this);
|
|
4348
4440
|
sandbox.traceId = result.traceId;
|
|
4349
4441
|
sandbox._setLifecycleIdentifier(result.sandboxId);
|
|
@@ -4351,7 +4443,7 @@ var init_client = __esm({
|
|
|
4351
4443
|
return sandbox;
|
|
4352
4444
|
};
|
|
4353
4445
|
if (result.status === "running" /* RUNNING */) {
|
|
4354
|
-
return finishConnect(result.routingHint, result.name);
|
|
4446
|
+
return finishConnect(result.routingHint, result.name, result.ingressEndpoint);
|
|
4355
4447
|
}
|
|
4356
4448
|
if (result.status === "suspended" /* SUSPENDED */ || result.status === "terminated" /* TERMINATED */) {
|
|
4357
4449
|
throw new SandboxError(
|
|
@@ -4365,7 +4457,7 @@ var init_client = __esm({
|
|
|
4365
4457
|
while (Date.now() < deadline) {
|
|
4366
4458
|
const info = await this.get(result.sandboxId);
|
|
4367
4459
|
if (info.status === "running" /* RUNNING */) {
|
|
4368
|
-
return finishConnect(info.routingHint, info.name);
|
|
4460
|
+
return finishConnect(info.routingHint, info.name, info.ingressEndpoint);
|
|
4369
4461
|
}
|
|
4370
4462
|
if (info.status === "suspended" /* SUSPENDED */ || info.status === "terminated" /* TERMINATED */) {
|
|
4371
4463
|
throw new SandboxError(
|
|
@@ -4772,7 +4864,8 @@ __export(index_exports, {
|
|
|
4772
4864
|
StdinMode: () => StdinMode,
|
|
4773
4865
|
TcpTunnel: () => TcpTunnel,
|
|
4774
4866
|
createSandboxImage: () => createSandboxImage,
|
|
4775
|
-
dockerfileContent: () => dockerfileContent
|
|
4867
|
+
dockerfileContent: () => dockerfileContent,
|
|
4868
|
+
sandboxUrlFromIngressEndpoint: () => sandboxUrlFromIngressEndpoint
|
|
4776
4869
|
});
|
|
4777
4870
|
module.exports = __toCommonJS(index_exports);
|
|
4778
4871
|
init_client();
|
|
@@ -5165,6 +5258,7 @@ var APIClient = class {
|
|
|
5165
5258
|
// src/index.ts
|
|
5166
5259
|
init_sandbox_image();
|
|
5167
5260
|
init_image();
|
|
5261
|
+
init_url();
|
|
5168
5262
|
init_errors();
|
|
5169
5263
|
init_models();
|
|
5170
5264
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -5195,6 +5289,7 @@ init_models();
|
|
|
5195
5289
|
StdinMode,
|
|
5196
5290
|
TcpTunnel,
|
|
5197
5291
|
createSandboxImage,
|
|
5198
|
-
dockerfileContent
|
|
5292
|
+
dockerfileContent,
|
|
5293
|
+
sandboxUrlFromIngressEndpoint
|
|
5199
5294
|
});
|
|
5200
5295
|
//# sourceMappingURL=index.cjs.map
|