tensorlake 0.5.5 → 0.5.7
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 +120 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -22
- package/dist/index.d.ts +34 -22
- package/dist/index.js +120 -35
- package/dist/index.js.map +1 -1
- package/dist/{sandbox-image-BmhjX2bC.d.cts → sandbox-image-BMDaNpZ2.d.cts} +1 -1
- package/dist/{sandbox-image-BmhjX2bC.d.ts → sandbox-image-BMDaNpZ2.d.ts} +1 -1
- package/dist/sandbox-image.cjs +120 -35
- package/dist/sandbox-image.cjs.map +1 -1
- package/dist/sandbox-image.d.cts +1 -1
- package/dist/sandbox-image.d.ts +1 -1
- package/dist/sandbox-image.js +120 -35
- package/dist/sandbox-image.js.map +1 -1
- package/package.json +1 -1
|
@@ -443,4 +443,4 @@ declare function loadImagePlan(image: Image, options?: Pick<CreateSandboxImageOp
|
|
|
443
443
|
declare function createSandboxImage(source: SandboxImageSource, options?: CreateSandboxImageOptions, deps?: CreateSandboxImageDeps): Promise<Record<string, unknown>>;
|
|
444
444
|
declare function runCreateSandboxImageCli(argv?: string[]): Promise<void>;
|
|
445
445
|
|
|
446
|
-
export { defaultRegisteredName as $, type CreateSandboxImageOptions as A, type DirectoryEntry as B, type CreatePtySessionOptions as C, type DaemonInfo as D, type DockerfileBuildPlan as E, type DockerfileInstruction as F, type ImageBuildOperation as G, type HealthResponse as H, Image as I, ImageBuildOperationType as J, type ImageOptions as K, type ListDirectoryResponse as L, OutputMode as M, type NetworkConfig as N, type OutputResponse as O, type ProcessInfo as P, type PoolContainerInfo as Q, type RunOptions as R, type SandboxOptions as S, ProcessStatus as T, type UpdateSandboxOptions as U, type SandboxImageSource as V, SnapshotStatus as W, type SnapshotType as X, StdinMode as Y, createSandboxImage as Z, dockerfileContent as _, type CreateAndConnectOptions as a, loadDockerfilePlan as a0, loadImagePlan as a1, logicalDockerfileLines as a2, runCreateSandboxImageCli as a3, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d,
|
|
446
|
+
export { defaultRegisteredName as $, type CreateSandboxImageOptions as A, type DirectoryEntry as B, type CreatePtySessionOptions as C, type DaemonInfo as D, type DockerfileBuildPlan as E, type DockerfileInstruction as F, type ImageBuildOperation as G, type HealthResponse as H, Image as I, ImageBuildOperationType as J, type ImageOptions as K, type ListDirectoryResponse as L, OutputMode as M, type NetworkConfig as N, type OutputResponse as O, type ProcessInfo as P, type PoolContainerInfo as Q, type RunOptions as R, type SandboxOptions as S, ProcessStatus as T, type UpdateSandboxOptions as U, type SandboxImageSource as V, SnapshotStatus as W, type SnapshotType as X, StdinMode as Y, createSandboxImage as Z, dockerfileContent as _, type CreateAndConnectOptions as a, loadDockerfilePlan as a0, loadImagePlan as a1, logicalDockerfileLines as a2, runCreateSandboxImageCli as a3, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d, type SandboxInfo as e, SandboxStatus as f, type SuspendResumeOptions as g, type CheckpointOptions as h, type CommandResult as i, type StartProcessOptions as j, type SendSignalResponse as k, type OutputEvent as l, type PtySessionInfo as m, type CreateSandboxOptions as n, type CreateSandboxResponse as o, type SandboxPortAccess as p, type SnapshotOptions as q, type CreateSnapshotResponse as r, type SnapshotAndWaitOptions as s, type CreatePoolOptions as t, type CreateSandboxPoolResponse as u, type SandboxPoolInfo as v, type UpdatePoolOptions as w, type CheckpointType as x, type ContainerResourcesInfo as y, ContainerState as z };
|
|
@@ -443,4 +443,4 @@ declare function loadImagePlan(image: Image, options?: Pick<CreateSandboxImageOp
|
|
|
443
443
|
declare function createSandboxImage(source: SandboxImageSource, options?: CreateSandboxImageOptions, deps?: CreateSandboxImageDeps): Promise<Record<string, unknown>>;
|
|
444
444
|
declare function runCreateSandboxImageCli(argv?: string[]): Promise<void>;
|
|
445
445
|
|
|
446
|
-
export { defaultRegisteredName as $, type CreateSandboxImageOptions as A, type DirectoryEntry as B, type CreatePtySessionOptions as C, type DaemonInfo as D, type DockerfileBuildPlan as E, type DockerfileInstruction as F, type ImageBuildOperation as G, type HealthResponse as H, Image as I, ImageBuildOperationType as J, type ImageOptions as K, type ListDirectoryResponse as L, OutputMode as M, type NetworkConfig as N, type OutputResponse as O, type ProcessInfo as P, type PoolContainerInfo as Q, type RunOptions as R, type SandboxOptions as S, ProcessStatus as T, type UpdateSandboxOptions as U, type SandboxImageSource as V, SnapshotStatus as W, type SnapshotType as X, StdinMode as Y, createSandboxImage as Z, dockerfileContent as _, type CreateAndConnectOptions as a, loadDockerfilePlan as a0, loadImagePlan as a1, logicalDockerfileLines as a2, runCreateSandboxImageCli as a3, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d,
|
|
446
|
+
export { defaultRegisteredName as $, type CreateSandboxImageOptions as A, type DirectoryEntry as B, type CreatePtySessionOptions as C, type DaemonInfo as D, type DockerfileBuildPlan as E, type DockerfileInstruction as F, type ImageBuildOperation as G, type HealthResponse as H, Image as I, ImageBuildOperationType as J, type ImageOptions as K, type ListDirectoryResponse as L, OutputMode as M, type NetworkConfig as N, type OutputResponse as O, type ProcessInfo as P, type PoolContainerInfo as Q, type RunOptions as R, type SandboxOptions as S, ProcessStatus as T, type UpdateSandboxOptions as U, type SandboxImageSource as V, SnapshotStatus as W, type SnapshotType as X, StdinMode as Y, createSandboxImage as Z, dockerfileContent as _, type CreateAndConnectOptions as a, loadDockerfilePlan as a0, loadImagePlan as a1, logicalDockerfileLines as a2, runCreateSandboxImageCli as a3, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d, type SandboxInfo as e, SandboxStatus as f, type SuspendResumeOptions as g, type CheckpointOptions as h, type CommandResult as i, type StartProcessOptions as j, type SendSignalResponse as k, type OutputEvent as l, type PtySessionInfo as m, type CreateSandboxOptions as n, type CreateSandboxResponse as o, type SandboxPortAccess as p, type SnapshotOptions as q, type CreateSnapshotResponse as r, type SnapshotAndWaitOptions as s, type CreatePoolOptions as t, type CreateSandboxPoolResponse as u, type SandboxPoolInfo as v, type UpdatePoolOptions as w, type CheckpointType as x, type ContainerResourcesInfo as y, ContainerState as z };
|
package/dist/sandbox-image.cjs
CHANGED
|
@@ -83,7 +83,7 @@ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TI
|
|
|
83
83
|
var init_defaults = __esm({
|
|
84
84
|
"src/defaults.ts"() {
|
|
85
85
|
"use strict";
|
|
86
|
-
SDK_VERSION = "0.
|
|
86
|
+
SDK_VERSION = "0.5.7";
|
|
87
87
|
API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
|
|
88
88
|
API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
|
|
89
89
|
NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
|
|
@@ -260,6 +260,9 @@ var init_http = __esm({
|
|
|
260
260
|
if (options.hostHeader) {
|
|
261
261
|
this.headers["Host"] = options.hostHeader;
|
|
262
262
|
}
|
|
263
|
+
if (options.sandboxIdHeader) {
|
|
264
|
+
this.headers["X-Tensorlake-Sandbox-Id"] = options.sandboxIdHeader;
|
|
265
|
+
}
|
|
263
266
|
if (options.routingHint) {
|
|
264
267
|
this.headers["X-Tensorlake-Route-Hint"] = options.routingHint;
|
|
265
268
|
}
|
|
@@ -2886,21 +2889,36 @@ function resolveProxyTarget(proxyUrl, sandboxId) {
|
|
|
2886
2889
|
if (host === "localhost" || host === "127.0.0.1") {
|
|
2887
2890
|
return {
|
|
2888
2891
|
baseUrl: trimTrailingSlashes(proxyUrl),
|
|
2889
|
-
hostHeader: `${sandboxId}.local
|
|
2892
|
+
hostHeader: `${sandboxId}.local`,
|
|
2893
|
+
sandboxIdHeader: void 0
|
|
2890
2894
|
};
|
|
2891
2895
|
}
|
|
2892
2896
|
const port = parsed.port ? `:${parsed.port}` : "";
|
|
2893
2897
|
return {
|
|
2894
|
-
baseUrl: `${parsed.protocol}//${
|
|
2895
|
-
hostHeader: void 0
|
|
2898
|
+
baseUrl: `${parsed.protocol}//${host}${port}`,
|
|
2899
|
+
hostHeader: void 0,
|
|
2900
|
+
sandboxIdHeader: sandboxId
|
|
2896
2901
|
};
|
|
2897
2902
|
} catch {
|
|
2898
2903
|
return {
|
|
2899
2904
|
baseUrl: `${trimTrailingSlashes(proxyUrl)}/${sandboxId}`,
|
|
2900
|
-
hostHeader: void 0
|
|
2905
|
+
hostHeader: void 0,
|
|
2906
|
+
sandboxIdHeader: void 0
|
|
2901
2907
|
};
|
|
2902
2908
|
}
|
|
2903
2909
|
}
|
|
2910
|
+
function resolveSandboxLifecycleUrl(apiUrl) {
|
|
2911
|
+
if (isLocalhost(apiUrl)) return apiUrl;
|
|
2912
|
+
try {
|
|
2913
|
+
const parsed = new URL(apiUrl);
|
|
2914
|
+
if (parsed.hostname.startsWith("api.")) {
|
|
2915
|
+
parsed.hostname = "sandbox." + parsed.hostname.slice(4);
|
|
2916
|
+
return parsed.toString().replace(/\/$/, "");
|
|
2917
|
+
}
|
|
2918
|
+
} catch {
|
|
2919
|
+
}
|
|
2920
|
+
return apiUrl;
|
|
2921
|
+
}
|
|
2904
2922
|
function lifecyclePath(path2, isLocal, namespace) {
|
|
2905
2923
|
if (isLocal) {
|
|
2906
2924
|
return `/v1/namespaces/${namespace}/${path2}`;
|
|
@@ -3127,7 +3145,7 @@ var init_sandbox = __esm({
|
|
|
3127
3145
|
this.sandboxId = options.sandboxId;
|
|
3128
3146
|
this.lifecycleIdentifier = options.sandboxId;
|
|
3129
3147
|
const proxyUrl = options.proxyUrl ?? SANDBOX_PROXY_URL;
|
|
3130
|
-
const { baseUrl, hostHeader } = resolveProxyTarget(proxyUrl, options.sandboxId);
|
|
3148
|
+
const { baseUrl, hostHeader, sandboxIdHeader } = resolveProxyTarget(proxyUrl, options.sandboxId);
|
|
3131
3149
|
this.baseUrl = baseUrl;
|
|
3132
3150
|
this.wsHeaders = {};
|
|
3133
3151
|
if (options.apiKey) {
|
|
@@ -3142,12 +3160,16 @@ var init_sandbox = __esm({
|
|
|
3142
3160
|
if (hostHeader) {
|
|
3143
3161
|
this.wsHeaders.Host = hostHeader;
|
|
3144
3162
|
}
|
|
3163
|
+
if (sandboxIdHeader) {
|
|
3164
|
+
this.wsHeaders["X-Tensorlake-Sandbox-Id"] = sandboxIdHeader;
|
|
3165
|
+
}
|
|
3145
3166
|
this.http = new HttpClient({
|
|
3146
3167
|
baseUrl,
|
|
3147
3168
|
apiKey: options.apiKey,
|
|
3148
3169
|
organizationId: options.organizationId,
|
|
3149
3170
|
projectId: options.projectId,
|
|
3150
3171
|
hostHeader,
|
|
3172
|
+
sandboxIdHeader,
|
|
3151
3173
|
routingHint: options.routingHint
|
|
3152
3174
|
});
|
|
3153
3175
|
}
|
|
@@ -3188,8 +3210,8 @@ var init_sandbox = __esm({
|
|
|
3188
3210
|
/**
|
|
3189
3211
|
* Attach to an existing sandbox and return a connected handle.
|
|
3190
3212
|
*
|
|
3191
|
-
*
|
|
3192
|
-
*
|
|
3213
|
+
* Returns immediately without contacting the server. Call `sandbox.info()`
|
|
3214
|
+
* to fetch the current state on demand. Does **not** auto-resume a suspended
|
|
3193
3215
|
* sandbox — call `sandbox.resume()` explicitly.
|
|
3194
3216
|
*/
|
|
3195
3217
|
static async connect(options) {
|
|
@@ -3199,15 +3221,12 @@ var init_sandbox = __esm({
|
|
|
3199
3221
|
/* _internal */
|
|
3200
3222
|
true
|
|
3201
3223
|
);
|
|
3202
|
-
const info = await client.get(options.sandboxId);
|
|
3203
3224
|
const sandbox = client.connect(
|
|
3204
|
-
|
|
3225
|
+
options.sandboxId,
|
|
3205
3226
|
options.proxyUrl,
|
|
3206
|
-
options.routingHint
|
|
3227
|
+
options.routingHint
|
|
3207
3228
|
);
|
|
3208
3229
|
sandbox.lifecycleClient = client;
|
|
3209
|
-
sandbox._setLifecycleIdentifier(info.sandboxId);
|
|
3210
|
-
sandbox._setName(info.name ?? null);
|
|
3211
3230
|
return sandbox;
|
|
3212
3231
|
}
|
|
3213
3232
|
// --- Static snapshot management ---
|
|
@@ -3231,6 +3250,26 @@ var init_sandbox = __esm({
|
|
|
3231
3250
|
);
|
|
3232
3251
|
await client.deleteSnapshot(snapshotId);
|
|
3233
3252
|
}
|
|
3253
|
+
/** List all sandboxes. No sandbox handle needed. */
|
|
3254
|
+
static async list(options) {
|
|
3255
|
+
const { SandboxClient: SandboxClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
3256
|
+
const client = new SandboxClient2(
|
|
3257
|
+
options,
|
|
3258
|
+
/* _internal */
|
|
3259
|
+
true
|
|
3260
|
+
);
|
|
3261
|
+
return client.list();
|
|
3262
|
+
}
|
|
3263
|
+
/** List all snapshots in the project. No sandbox handle needed. */
|
|
3264
|
+
static async listSnapshots(options) {
|
|
3265
|
+
const { SandboxClient: SandboxClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
3266
|
+
const client = new SandboxClient2(
|
|
3267
|
+
options,
|
|
3268
|
+
/* _internal */
|
|
3269
|
+
true
|
|
3270
|
+
);
|
|
3271
|
+
return client.listSnapshots();
|
|
3272
|
+
}
|
|
3234
3273
|
// --- Instance lifecycle methods ---
|
|
3235
3274
|
requireLifecycleClient(operation) {
|
|
3236
3275
|
if (!this.lifecycleClient) {
|
|
@@ -3240,6 +3279,14 @@ var init_sandbox = __esm({
|
|
|
3240
3279
|
}
|
|
3241
3280
|
return this.lifecycleClient;
|
|
3242
3281
|
}
|
|
3282
|
+
/** Fetch the current sandbox information from the server on demand. */
|
|
3283
|
+
async info() {
|
|
3284
|
+
const client = this.requireLifecycleClient("info");
|
|
3285
|
+
const info = await client.get(this.lifecycleIdentifier);
|
|
3286
|
+
this._setLifecycleIdentifier(info.sandboxId);
|
|
3287
|
+
this._setName(info.name ?? null);
|
|
3288
|
+
return info;
|
|
3289
|
+
}
|
|
3243
3290
|
/**
|
|
3244
3291
|
* Fetch the current sandbox status from the server.
|
|
3245
3292
|
*
|
|
@@ -3347,6 +3394,7 @@ var init_sandbox = __esm({
|
|
|
3347
3394
|
"/api/v1/processes/run",
|
|
3348
3395
|
{ json: body }
|
|
3349
3396
|
);
|
|
3397
|
+
const traceId = sseStream.traceId;
|
|
3350
3398
|
const stdoutLines = [];
|
|
3351
3399
|
const stderrLines = [];
|
|
3352
3400
|
let exitCode = -1;
|
|
@@ -3365,11 +3413,10 @@ var init_sandbox = __esm({
|
|
|
3365
3413
|
}
|
|
3366
3414
|
}
|
|
3367
3415
|
}
|
|
3368
|
-
return
|
|
3369
|
-
exitCode,
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
};
|
|
3416
|
+
return Object.assign(
|
|
3417
|
+
{ exitCode, stdout: stdoutLines.join("\n"), stderr: stderrLines.join("\n") },
|
|
3418
|
+
{ traceId }
|
|
3419
|
+
);
|
|
3373
3420
|
}
|
|
3374
3421
|
// --- Process management ---
|
|
3375
3422
|
/**
|
|
@@ -3399,7 +3446,7 @@ var init_sandbox = __esm({
|
|
|
3399
3446
|
"/api/v1/processes",
|
|
3400
3447
|
{ body: payload }
|
|
3401
3448
|
);
|
|
3402
|
-
return fromSnakeKeys(raw);
|
|
3449
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3403
3450
|
}
|
|
3404
3451
|
/** List all processes (running and exited) tracked by the sandbox daemon. */
|
|
3405
3452
|
async listProcesses() {
|
|
@@ -3416,7 +3463,7 @@ var init_sandbox = __esm({
|
|
|
3416
3463
|
"GET",
|
|
3417
3464
|
`/api/v1/processes/${pid}`
|
|
3418
3465
|
);
|
|
3419
|
-
return fromSnakeKeys(raw);
|
|
3466
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3420
3467
|
}
|
|
3421
3468
|
/** Send SIGKILL to a process. */
|
|
3422
3469
|
async killProcess(pid) {
|
|
@@ -3429,7 +3476,7 @@ var init_sandbox = __esm({
|
|
|
3429
3476
|
`/api/v1/processes/${pid}/signal`,
|
|
3430
3477
|
{ body: { signal } }
|
|
3431
3478
|
);
|
|
3432
|
-
return fromSnakeKeys(raw);
|
|
3479
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3433
3480
|
}
|
|
3434
3481
|
// --- Process I/O ---
|
|
3435
3482
|
/** Write bytes to a process's stdin. The process must have been started with `stdinMode: StdinMode.PIPE`. */
|
|
@@ -3449,7 +3496,7 @@ var init_sandbox = __esm({
|
|
|
3449
3496
|
"GET",
|
|
3450
3497
|
`/api/v1/processes/${pid}/stdout`
|
|
3451
3498
|
);
|
|
3452
|
-
return fromSnakeKeys(raw);
|
|
3499
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3453
3500
|
}
|
|
3454
3501
|
/** Return all captured stderr lines produced so far by a process. */
|
|
3455
3502
|
async getStderr(pid) {
|
|
@@ -3457,7 +3504,7 @@ var init_sandbox = __esm({
|
|
|
3457
3504
|
"GET",
|
|
3458
3505
|
`/api/v1/processes/${pid}/stderr`
|
|
3459
3506
|
);
|
|
3460
|
-
return fromSnakeKeys(raw);
|
|
3507
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3461
3508
|
}
|
|
3462
3509
|
/** Return all captured stdout+stderr lines produced so far by a process. */
|
|
3463
3510
|
async getOutput(pid) {
|
|
@@ -3465,7 +3512,7 @@ var init_sandbox = __esm({
|
|
|
3465
3512
|
"GET",
|
|
3466
3513
|
`/api/v1/processes/${pid}/output`
|
|
3467
3514
|
);
|
|
3468
|
-
return fromSnakeKeys(raw);
|
|
3515
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3469
3516
|
}
|
|
3470
3517
|
// --- Streaming (SSE) ---
|
|
3471
3518
|
/** Stream stdout events from a process until it exits. Yields one `OutputEvent` per line. */
|
|
@@ -3539,7 +3586,7 @@ var init_sandbox = __esm({
|
|
|
3539
3586
|
"GET",
|
|
3540
3587
|
`/api/v1/files/list?path=${encodeURIComponent(path2)}`
|
|
3541
3588
|
);
|
|
3542
|
-
return fromSnakeKeys(raw);
|
|
3589
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3543
3590
|
}
|
|
3544
3591
|
// --- PTY ---
|
|
3545
3592
|
/** Create an interactive PTY session. Returns a `sessionId` and `token` for WebSocket connection via `connectPty()`. */
|
|
@@ -3557,7 +3604,7 @@ var init_sandbox = __esm({
|
|
|
3557
3604
|
"/api/v1/pty",
|
|
3558
3605
|
{ body: payload }
|
|
3559
3606
|
);
|
|
3560
|
-
return fromSnakeKeys(raw);
|
|
3607
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3561
3608
|
}
|
|
3562
3609
|
/** Create a PTY session and connect to it immediately. Cleans up the session if the WebSocket connection fails. */
|
|
3563
3610
|
async createPty(options) {
|
|
@@ -3611,15 +3658,53 @@ var init_sandbox = __esm({
|
|
|
3611
3658
|
}
|
|
3612
3659
|
/** Connect to a sandbox VNC session for programmatic desktop control. */
|
|
3613
3660
|
async connectDesktop(options) {
|
|
3661
|
+
const port = options?.port ?? 5901;
|
|
3662
|
+
const connectTimeout = options?.connectTimeout ?? 10;
|
|
3663
|
+
const startMs = Date.now();
|
|
3664
|
+
const deadlineMs = startMs + connectTimeout * 1e3;
|
|
3665
|
+
await this.waitForPortReady(port, deadlineMs);
|
|
3666
|
+
const remainingSecs = Math.max(0.1, (deadlineMs - Date.now()) / 1e3);
|
|
3614
3667
|
return Desktop.connect({
|
|
3615
3668
|
baseUrl: this.baseUrl,
|
|
3616
3669
|
wsHeaders: this.wsHeaders,
|
|
3617
|
-
port
|
|
3670
|
+
port,
|
|
3618
3671
|
password: options?.password,
|
|
3619
3672
|
shared: options?.shared,
|
|
3620
|
-
connectTimeout:
|
|
3673
|
+
connectTimeout: remainingSecs
|
|
3621
3674
|
});
|
|
3622
3675
|
}
|
|
3676
|
+
/**
|
|
3677
|
+
* Poll the in-sandbox daemon until `127.0.0.1:port` accepts a TCP connection.
|
|
3678
|
+
* Uses `bash`'s `/dev/tcp` builtin via `processes/run` — no extra deps in
|
|
3679
|
+
* the sandbox image. `bash` is present on every image we ship.
|
|
3680
|
+
*/
|
|
3681
|
+
async waitForPortReady(port, deadlineMs) {
|
|
3682
|
+
const probeIntervalMs = 250;
|
|
3683
|
+
const probeProcessTimeoutSecs = 2;
|
|
3684
|
+
let lastError;
|
|
3685
|
+
while (Date.now() < deadlineMs) {
|
|
3686
|
+
try {
|
|
3687
|
+
const result = await this.run("/bin/bash", {
|
|
3688
|
+
args: ["-c", `exec 3<>/dev/tcp/127.0.0.1/${port}`],
|
|
3689
|
+
timeout: probeProcessTimeoutSecs
|
|
3690
|
+
});
|
|
3691
|
+
if (result.exitCode === 0) {
|
|
3692
|
+
return;
|
|
3693
|
+
}
|
|
3694
|
+
} catch (error) {
|
|
3695
|
+
lastError = error;
|
|
3696
|
+
}
|
|
3697
|
+
const remainingMs = deadlineMs - Date.now();
|
|
3698
|
+
if (remainingMs <= 0) break;
|
|
3699
|
+
await new Promise(
|
|
3700
|
+
(resolve) => setTimeout(resolve, Math.min(probeIntervalMs, remainingMs))
|
|
3701
|
+
);
|
|
3702
|
+
}
|
|
3703
|
+
const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
|
|
3704
|
+
throw new SandboxError(
|
|
3705
|
+
`port ${port} did not become reachable inside sandbox within the connect timeout${detail}`
|
|
3706
|
+
);
|
|
3707
|
+
}
|
|
3623
3708
|
ptyWsUrl(sessionId, token) {
|
|
3624
3709
|
let wsBase;
|
|
3625
3710
|
if (this.baseUrl.startsWith("https://")) {
|
|
@@ -3638,15 +3723,15 @@ var init_sandbox = __esm({
|
|
|
3638
3723
|
"GET",
|
|
3639
3724
|
"/api/v1/health"
|
|
3640
3725
|
);
|
|
3641
|
-
return fromSnakeKeys(raw);
|
|
3726
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3642
3727
|
}
|
|
3643
3728
|
/** Get sandbox daemon info (version, uptime, process counts). */
|
|
3644
|
-
async
|
|
3729
|
+
async daemonInfo() {
|
|
3645
3730
|
const raw = await this.http.requestJson(
|
|
3646
3731
|
"GET",
|
|
3647
3732
|
"/api/v1/info"
|
|
3648
3733
|
);
|
|
3649
|
-
return fromSnakeKeys(raw);
|
|
3734
|
+
return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
|
|
3650
3735
|
}
|
|
3651
3736
|
};
|
|
3652
3737
|
}
|
|
@@ -3739,7 +3824,7 @@ var init_client = __esm({
|
|
|
3739
3824
|
this.namespace = options?.namespace ?? NAMESPACE;
|
|
3740
3825
|
this.local = isLocalhost(this.apiUrl);
|
|
3741
3826
|
this.http = new HttpClient({
|
|
3742
|
-
baseUrl: this.apiUrl,
|
|
3827
|
+
baseUrl: resolveSandboxLifecycleUrl(this.apiUrl),
|
|
3743
3828
|
apiKey: this.apiKey,
|
|
3744
3829
|
organizationId: this.organizationId,
|
|
3745
3830
|
projectId: this.projectId,
|
|
@@ -3807,7 +3892,7 @@ var init_client = __esm({
|
|
|
3807
3892
|
"GET",
|
|
3808
3893
|
this.path(`sandboxes/${sandboxId}`)
|
|
3809
3894
|
);
|
|
3810
|
-
return fromSnakeKeys(raw, "sandboxId");
|
|
3895
|
+
return Object.assign(fromSnakeKeys(raw, "sandboxId"), { traceId: raw.traceId });
|
|
3811
3896
|
}
|
|
3812
3897
|
/** List all sandboxes in the namespace. */
|
|
3813
3898
|
async list() {
|
|
@@ -3838,7 +3923,7 @@ var init_client = __esm({
|
|
|
3838
3923
|
this.path(`sandboxes/${sandboxId}`),
|
|
3839
3924
|
{ body }
|
|
3840
3925
|
);
|
|
3841
|
-
return fromSnakeKeys(raw, "sandboxId");
|
|
3926
|
+
return Object.assign(fromSnakeKeys(raw, "sandboxId"), { traceId: raw.traceId });
|
|
3842
3927
|
}
|
|
3843
3928
|
/** Get the current proxy port settings for a sandbox. */
|
|
3844
3929
|
async getPortAccess(sandboxId) {
|
|
@@ -3980,7 +4065,7 @@ var init_client = __esm({
|
|
|
3980
4065
|
"GET",
|
|
3981
4066
|
this.path(`snapshots/${snapshotId}`)
|
|
3982
4067
|
);
|
|
3983
|
-
return fromSnakeKeys(raw, "snapshotId");
|
|
4068
|
+
return Object.assign(fromSnakeKeys(raw, "snapshotId"), { traceId: raw.traceId });
|
|
3984
4069
|
}
|
|
3985
4070
|
/** List all snapshots in the namespace. */
|
|
3986
4071
|
async listSnapshots() {
|