ppio-sandbox 2.1.2 → 2.1.4-a1
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/{chunk-3L3K3WO3.mjs → chunk-PPBSBQ3N.mjs} +2 -2
- package/dist/{chunk-3OWF5GCM.mjs → chunk-Q4BOWZMT.mjs} +2 -2
- package/dist/{chunk-PQGBLWKQ.mjs → chunk-RWHOETVW.mjs} +107 -49
- package/dist/chunk-RWHOETVW.mjs.map +1 -0
- package/dist/code-interpreter.d.mts +2 -2
- package/dist/code-interpreter.d.ts +2 -2
- package/dist/code-interpreter.js +105 -47
- package/dist/code-interpreter.js.map +1 -1
- package/dist/code-interpreter.mjs +2 -2
- package/dist/desktop.d.mts +1 -1
- package/dist/desktop.d.ts +1 -1
- package/dist/desktop.js +105 -47
- package/dist/desktop.js.map +1 -1
- package/dist/desktop.mjs +2 -2
- package/dist/{index-CAD08VLb.d.mts → index-DIHU8MXT.d.mts} +164 -4
- package/dist/{index-CAD08VLb.d.ts → index-DIHU8MXT.d.ts} +164 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +105 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/sandbox-6EPWOUGN.mjs +8 -0
- package/dist/sandbox-OKITI7WW.mjs +8 -0
- package/package.json +1 -1
- package/dist/chunk-PQGBLWKQ.mjs.map +0 -1
- package/dist/sandbox-DMY2YDSO.mjs +0 -8
- package/dist/sandbox-TS3DDCSN.mjs +0 -8
- /package/dist/{chunk-3L3K3WO3.mjs.map → chunk-PPBSBQ3N.mjs.map} +0 -0
- /package/dist/{chunk-3OWF5GCM.mjs.map → chunk-Q4BOWZMT.mjs.map} +0 -0
- /package/dist/{sandbox-DMY2YDSO.mjs.map → sandbox-6EPWOUGN.mjs.map} +0 -0
- /package/dist/{sandbox-TS3DDCSN.mjs.map → sandbox-OKITI7WW.mjs.map} +0 -0
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
__forAwait,
|
|
10
10
|
__spreadProps,
|
|
11
11
|
__spreadValues
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-RWHOETVW.mjs";
|
|
13
13
|
|
|
14
14
|
// src/code-interpreter/messaging.ts
|
|
15
15
|
async function extractError(res) {
|
|
@@ -465,4 +465,4 @@ Sandbox2.defaultTemplate = "code-interpreter-v1";
|
|
|
465
465
|
export {
|
|
466
466
|
Sandbox2 as Sandbox
|
|
467
467
|
};
|
|
468
|
-
//# sourceMappingURL=chunk-
|
|
468
|
+
//# sourceMappingURL=chunk-PPBSBQ3N.mjs.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
TimeoutError,
|
|
6
6
|
__spreadProps,
|
|
7
7
|
__spreadValues
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-RWHOETVW.mjs";
|
|
9
9
|
|
|
10
10
|
// src/desktop/utils.ts
|
|
11
11
|
import { randomBytes } from "crypto";
|
|
@@ -530,4 +530,4 @@ var VNCServer = class {
|
|
|
530
530
|
export {
|
|
531
531
|
Sandbox2 as Sandbox
|
|
532
532
|
};
|
|
533
|
-
//# sourceMappingURL=chunk-
|
|
533
|
+
//# sourceMappingURL=chunk-Q4BOWZMT.mjs.map
|
|
@@ -60,7 +60,7 @@ import createClient from "openapi-fetch";
|
|
|
60
60
|
import platform2 from "platform";
|
|
61
61
|
|
|
62
62
|
// package.json
|
|
63
|
-
var version = "2.1.
|
|
63
|
+
var version = "2.1.4-a1";
|
|
64
64
|
|
|
65
65
|
// src/core/utils.ts
|
|
66
66
|
import platform from "platform";
|
|
@@ -2998,11 +2998,14 @@ function bindingFromJson(data) {
|
|
|
2998
2998
|
|
|
2999
2999
|
// src/core/sandbox/sandboxApi.ts
|
|
3000
3000
|
async function createRawApiError(response) {
|
|
3001
|
-
var _a3;
|
|
3001
|
+
var _a3, _b, _c;
|
|
3002
3002
|
let message = response.statusText;
|
|
3003
3003
|
try {
|
|
3004
3004
|
const body = await response.json();
|
|
3005
3005
|
message = (_a3 = body == null ? void 0 : body.message) != null ? _a3 : JSON.stringify(body);
|
|
3006
|
+
if ((body == null ? void 0 : body.item) || (body == null ? void 0 : body.reason)) {
|
|
3007
|
+
message = `${(_b = body.item) != null ? _b : "request"}: ${(_c = body.reason) != null ? _c : "error"}: ${message}`;
|
|
3008
|
+
}
|
|
3006
3009
|
} catch (e) {
|
|
3007
3010
|
try {
|
|
3008
3011
|
message = await response.text();
|
|
@@ -3024,6 +3027,51 @@ async function createRawApiError(response) {
|
|
|
3024
3027
|
function getRawApiHeaders(config, headers) {
|
|
3025
3028
|
return __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, defaultHeaders), config.apiKey ? { "X-API-KEY": config.apiKey } : {}), config.accessToken ? { Authorization: `Bearer ${config.accessToken}` } : {}), config.headers), headers != null ? headers : {});
|
|
3026
3029
|
}
|
|
3030
|
+
var MIB_PER_GIB = 1024;
|
|
3031
|
+
function gibToMib(value, name) {
|
|
3032
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
3033
|
+
throw new SandboxError(`resource target ${name} must be a positive number`);
|
|
3034
|
+
}
|
|
3035
|
+
const mib = value * MIB_PER_GIB;
|
|
3036
|
+
if (!Number.isSafeInteger(mib)) {
|
|
3037
|
+
throw new SandboxError(`resource target ${name} must be an exact number of MiB`);
|
|
3038
|
+
}
|
|
3039
|
+
return mib;
|
|
3040
|
+
}
|
|
3041
|
+
function resourceTargetsToApi(resources) {
|
|
3042
|
+
const unknown = Object.keys(resources != null ? resources : {}).filter(
|
|
3043
|
+
(key) => !["cpu", "memoryGiB", "diskGiB"].includes(key)
|
|
3044
|
+
);
|
|
3045
|
+
if (unknown.length) throw new SandboxError(`unsupported resource field: ${unknown.join(", ")}`);
|
|
3046
|
+
const body = {};
|
|
3047
|
+
const { cpu, memoryGiB, diskGiB } = resources != null ? resources : {};
|
|
3048
|
+
if (cpu !== void 0) {
|
|
3049
|
+
if (!Number.isSafeInteger(cpu) || cpu <= 0) {
|
|
3050
|
+
throw new SandboxError("resource target cpu must be a positive whole number");
|
|
3051
|
+
}
|
|
3052
|
+
body.vcpu = cpu;
|
|
3053
|
+
}
|
|
3054
|
+
if (memoryGiB !== void 0) body.memory_mb = gibToMib(memoryGiB, "memoryGiB");
|
|
3055
|
+
if (diskGiB !== void 0) body.disk_size_mb = gibToMib(diskGiB, "diskGiB");
|
|
3056
|
+
if (!Object.keys(body).length) throw new SandboxError("at least one resource target is required");
|
|
3057
|
+
return body;
|
|
3058
|
+
}
|
|
3059
|
+
function resizeResultFromApi(data) {
|
|
3060
|
+
var _a3, _b, _c;
|
|
3061
|
+
const result = {};
|
|
3062
|
+
for (const key of ["cpu", "memory", "disk"]) {
|
|
3063
|
+
const item = data == null ? void 0 : data[key];
|
|
3064
|
+
if (!item) continue;
|
|
3065
|
+
const divisor = key === "cpu" ? 1 : 1024;
|
|
3066
|
+
result[key] = __spreadProps(__spreadValues({}, item), {
|
|
3067
|
+
requested: ((_a3 = item.requested) != null ? _a3 : 0) / divisor,
|
|
3068
|
+
previous: ((_b = item.previous) != null ? _b : 0) / divisor,
|
|
3069
|
+
current: ((_c = item.current) != null ? _c : 0) / divisor,
|
|
3070
|
+
unit: key === "cpu" ? "cores" : "GiB"
|
|
3071
|
+
});
|
|
3072
|
+
}
|
|
3073
|
+
return result;
|
|
3074
|
+
}
|
|
3027
3075
|
function getLifecycle(opts) {
|
|
3028
3076
|
if (opts == null ? void 0 : opts.lifecycle) {
|
|
3029
3077
|
return opts.lifecycle;
|
|
@@ -3221,28 +3269,24 @@ var SandboxApi = class {
|
|
|
3221
3269
|
templateType: "snapshot_template"
|
|
3222
3270
|
};
|
|
3223
3271
|
}
|
|
3224
|
-
static async
|
|
3272
|
+
static async resize(sandboxId, resources, opts) {
|
|
3273
|
+
const body = resourceTargetsToApi(resources);
|
|
3225
3274
|
const config = new ConnectionConfig(opts);
|
|
3226
|
-
raiseIfLegacy(config, "Sandbox.
|
|
3275
|
+
raiseIfLegacy(config, "Sandbox.resize", SandboxError);
|
|
3227
3276
|
const response = await fetch(
|
|
3228
|
-
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/
|
|
3277
|
+
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/resize`,
|
|
3229
3278
|
{
|
|
3230
3279
|
method: "POST",
|
|
3231
|
-
headers: getRawApiHeaders(config, {
|
|
3232
|
-
|
|
3233
|
-
}),
|
|
3234
|
-
body: JSON.stringify({
|
|
3235
|
-
requested_size_mib: requestedSizeMib
|
|
3236
|
-
}),
|
|
3280
|
+
headers: getRawApiHeaders(config, { "Content-Type": "application/json" }),
|
|
3281
|
+
body: JSON.stringify(body),
|
|
3237
3282
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3238
3283
|
}
|
|
3239
3284
|
);
|
|
3240
3285
|
if (response.status === 404) {
|
|
3241
3286
|
throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`);
|
|
3242
3287
|
}
|
|
3243
|
-
if (!response.ok)
|
|
3244
|
-
|
|
3245
|
-
}
|
|
3288
|
+
if (!response.ok) throw await createRawApiError(response);
|
|
3289
|
+
return resizeResultFromApi(await response.json());
|
|
3246
3290
|
}
|
|
3247
3291
|
static async reset(sandboxId, opts) {
|
|
3248
3292
|
var _a3;
|
|
@@ -3340,7 +3384,7 @@ var SandboxApi = class {
|
|
|
3340
3384
|
throw await createRawApiError(response);
|
|
3341
3385
|
}
|
|
3342
3386
|
const data = await response.json();
|
|
3343
|
-
return {
|
|
3387
|
+
return __spreadProps(__spreadValues({
|
|
3344
3388
|
sandboxId: data.sandboxID,
|
|
3345
3389
|
templateId: data.templateID,
|
|
3346
3390
|
name: data.name,
|
|
@@ -3349,10 +3393,11 @@ var SandboxApi = class {
|
|
|
3349
3393
|
endAt: new Date(data.endAt),
|
|
3350
3394
|
state: data.state,
|
|
3351
3395
|
cpuCount: data.cpuCount,
|
|
3352
|
-
memoryMB: data.memoryMB
|
|
3396
|
+
memoryMB: data.memoryMB
|
|
3397
|
+
}, data.diskSizeMB !== void 0 ? { diskSizeMB: data.diskSizeMB } : {}), {
|
|
3353
3398
|
envdVersion: data.envdVersion,
|
|
3354
3399
|
volumeMounts: (_b = data.volumeMounts) != null ? _b : []
|
|
3355
|
-
};
|
|
3400
|
+
});
|
|
3356
3401
|
}
|
|
3357
3402
|
static async setNetwork(sandboxId, opts) {
|
|
3358
3403
|
const config = new ConnectionConfig(opts);
|
|
@@ -3466,6 +3511,7 @@ var SandboxApi = class {
|
|
|
3466
3511
|
state: res.data.state,
|
|
3467
3512
|
cpuCount: res.data.cpuCount,
|
|
3468
3513
|
memoryMB: res.data.memoryMB,
|
|
3514
|
+
diskSizeMB: res.data.diskSizeMB,
|
|
3469
3515
|
network: res.data.network ? {
|
|
3470
3516
|
allowOut: res.data.network.allowOut,
|
|
3471
3517
|
denyOut: res.data.network.denyOut,
|
|
@@ -3618,7 +3664,7 @@ var SandboxApi = class {
|
|
|
3618
3664
|
return true;
|
|
3619
3665
|
}
|
|
3620
3666
|
static async createSandbox(template, timeoutMs, opts) {
|
|
3621
|
-
var _a3, _b, _c, _d, _e, _f, _g;
|
|
3667
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h;
|
|
3622
3668
|
const config = new ConnectionConfig(opts);
|
|
3623
3669
|
const longRunning = ((_a3 = opts == null ? void 0 : opts.metadata) == null ? void 0 : _a3.long_running) === "true";
|
|
3624
3670
|
const metadata = longRunning ? __spreadValues({}, opts == null ? void 0 : opts.metadata) : opts == null ? void 0 : opts.metadata;
|
|
@@ -3644,6 +3690,9 @@ var SandboxApi = class {
|
|
|
3644
3690
|
if (opts == null ? void 0 : opts.secretEnvs) {
|
|
3645
3691
|
raiseIfLegacy(config, "Sandbox.create secretEnvs", SandboxError);
|
|
3646
3692
|
}
|
|
3693
|
+
if (opts == null ? void 0 : opts.resources) {
|
|
3694
|
+
raiseIfLegacy(config, "Sandbox.create resources", SandboxError);
|
|
3695
|
+
}
|
|
3647
3696
|
const body2 = __spreadValues(__spreadValues({
|
|
3648
3697
|
templateID: template,
|
|
3649
3698
|
timeout,
|
|
@@ -3705,6 +3754,30 @@ var SandboxApi = class {
|
|
|
3705
3754
|
;
|
|
3706
3755
|
body.secrets = validatedSecretEnvs;
|
|
3707
3756
|
}
|
|
3757
|
+
if (opts == null ? void 0 : opts.resources) {
|
|
3758
|
+
const targets = resourceTargetsToApi(opts.resources);
|
|
3759
|
+
const response = await fetch(`${config.apiUrl}/sandboxes/custom`, {
|
|
3760
|
+
method: "POST",
|
|
3761
|
+
headers: getRawApiHeaders(config, { "Content-Type": "application/json" }),
|
|
3762
|
+
body: JSON.stringify(__spreadProps(__spreadValues({}, body), { resources: targets })),
|
|
3763
|
+
signal: config.getSignal((_h = opts == null ? void 0 : opts.requestTimeoutMs) != null ? _h : 36e4)
|
|
3764
|
+
});
|
|
3765
|
+
if (!response.ok) throw await createRawApiError(response);
|
|
3766
|
+
const data = await response.json();
|
|
3767
|
+
if (compareVersions4(data.envdVersion, "0.1.0") < 0) {
|
|
3768
|
+
await this.kill(data.sandboxID, opts);
|
|
3769
|
+
throw new TemplateError(
|
|
3770
|
+
"You need to update the template to use the new SDK. You can do this by running `ppio template build` in the directory with the template."
|
|
3771
|
+
);
|
|
3772
|
+
}
|
|
3773
|
+
return {
|
|
3774
|
+
sandboxId: data.sandboxID,
|
|
3775
|
+
sandboxDomain: data.domain || void 0,
|
|
3776
|
+
envdVersion: data.envdVersion,
|
|
3777
|
+
envdAccessToken: data.envdAccessToken,
|
|
3778
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3779
|
+
};
|
|
3780
|
+
}
|
|
3708
3781
|
const res = await client.api.POST("/sandboxes", {
|
|
3709
3782
|
body,
|
|
3710
3783
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -4194,19 +4267,6 @@ var Sandbox = class extends SandboxApi {
|
|
|
4194
4267
|
snapshotTemplateId: cloneResult.snapshotTemplateId
|
|
4195
4268
|
};
|
|
4196
4269
|
}
|
|
4197
|
-
/**
|
|
4198
|
-
* Dynamically adjust the hotplugged memory on a running sandbox.
|
|
4199
|
-
*
|
|
4200
|
-
* The value represents the new *total* plugged size in MiB, not a delta.
|
|
4201
|
-
* Use `0` to unplug all hotplugged memory.
|
|
4202
|
-
*/
|
|
4203
|
-
static async hotplugMemory(sandboxId, requestedSizeMib, opts) {
|
|
4204
|
-
return await SandboxApi.hotplugMemory(
|
|
4205
|
-
sandboxId,
|
|
4206
|
-
requestedSizeMib,
|
|
4207
|
-
opts
|
|
4208
|
-
);
|
|
4209
|
-
}
|
|
4210
4270
|
/**
|
|
4211
4271
|
* Mount a volume to a sandbox.
|
|
4212
4272
|
*
|
|
@@ -4217,6 +4277,10 @@ var Sandbox = class extends SandboxApi {
|
|
|
4217
4277
|
*
|
|
4218
4278
|
* @returns updated sandbox information.
|
|
4219
4279
|
*/
|
|
4280
|
+
/** Increase running sandbox resources to absolute CPU and GiB targets. */
|
|
4281
|
+
static async resize(sandboxId, resources, opts) {
|
|
4282
|
+
return await SandboxApi.resize(sandboxId, resources, opts);
|
|
4283
|
+
}
|
|
4220
4284
|
static async mountVolume(sandboxId, name, path3, opts) {
|
|
4221
4285
|
return await SandboxApi.mountVolume(sandboxId, name, path3, opts);
|
|
4222
4286
|
}
|
|
@@ -4501,21 +4565,9 @@ var Sandbox = class extends SandboxApi {
|
|
|
4501
4565
|
}
|
|
4502
4566
|
await SandboxApi.kill(this.sandboxId, this.resolveApiOpts(opts));
|
|
4503
4567
|
}
|
|
4504
|
-
/**
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
* The value represents the new *total* plugged size in MiB, not a delta.
|
|
4508
|
-
* Use `0` to unplug all hotplugged memory.
|
|
4509
|
-
*
|
|
4510
|
-
* @param requestedSizeMib new total plugged memory size in MiB.
|
|
4511
|
-
* @param opts connection options.
|
|
4512
|
-
*/
|
|
4513
|
-
async hotplugMemory(requestedSizeMib, opts) {
|
|
4514
|
-
await SandboxApi.hotplugMemory(
|
|
4515
|
-
this.sandboxId,
|
|
4516
|
-
requestedSizeMib,
|
|
4517
|
-
this.resolveApiOpts(opts)
|
|
4518
|
-
);
|
|
4568
|
+
/** Increase this sandbox's resources to absolute CPU and GiB targets. */
|
|
4569
|
+
async resize(resources, opts) {
|
|
4570
|
+
return await SandboxApi.resize(this.sandboxId, resources, this.resolveApiOpts(opts));
|
|
4519
4571
|
}
|
|
4520
4572
|
/**
|
|
4521
4573
|
* Pause a sandbox by its ID.
|
|
@@ -7765,6 +7817,9 @@ var RuntimeSandboxNamespace = class {
|
|
|
7765
7817
|
getQuota(opts) {
|
|
7766
7818
|
return Sandbox.getQuota(mergeConnectionOpts(this.opts, opts));
|
|
7767
7819
|
}
|
|
7820
|
+
resize(sandboxId, resources, opts) {
|
|
7821
|
+
return Sandbox.resize(sandboxId, resources, mergeConnectionOpts(this.opts, opts));
|
|
7822
|
+
}
|
|
7768
7823
|
getEvents(opts) {
|
|
7769
7824
|
return Sandbox.getEvents(mergeConnectionOpts(this.opts, opts));
|
|
7770
7825
|
}
|
|
@@ -7852,6 +7907,9 @@ var SandboxNamespace = class {
|
|
|
7852
7907
|
getQuota(opts) {
|
|
7853
7908
|
return Sandbox.getQuota(mergeConnectionOpts(this.opts, opts));
|
|
7854
7909
|
}
|
|
7910
|
+
resize(sandboxId, resources, opts) {
|
|
7911
|
+
return Sandbox.resize(sandboxId, resources, mergeConnectionOpts(this.opts, opts));
|
|
7912
|
+
}
|
|
7855
7913
|
getEvents(opts) {
|
|
7856
7914
|
return Sandbox.getEvents(mergeConnectionOpts(this.opts, opts));
|
|
7857
7915
|
}
|
|
@@ -8003,12 +8061,12 @@ var PPIO = class {
|
|
|
8003
8061
|
this.secret = new SecretNamespace(opts);
|
|
8004
8062
|
this.codeInterpreter = new RuntimeSandboxNamespace(
|
|
8005
8063
|
opts,
|
|
8006
|
-
() => import("./sandbox-
|
|
8064
|
+
() => import("./sandbox-OKITI7WW.mjs")
|
|
8007
8065
|
);
|
|
8008
8066
|
this.code_interpreter = this.codeInterpreter;
|
|
8009
8067
|
this.desktop = new RuntimeSandboxNamespace(
|
|
8010
8068
|
opts,
|
|
8011
|
-
() => import("./sandbox-
|
|
8069
|
+
() => import("./sandbox-6EPWOUGN.mjs")
|
|
8012
8070
|
);
|
|
8013
8071
|
}
|
|
8014
8072
|
async create(templateOrOpts, opts) {
|
|
@@ -8087,4 +8145,4 @@ export {
|
|
|
8087
8145
|
ALL_TRAFFIC,
|
|
8088
8146
|
core_default
|
|
8089
8147
|
};
|
|
8090
|
-
//# sourceMappingURL=chunk-
|
|
8148
|
+
//# sourceMappingURL=chunk-RWHOETVW.mjs.map
|