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
package/dist/index.js
CHANGED
|
@@ -80,7 +80,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
80
80
|
var version;
|
|
81
81
|
var init_package = __esm({
|
|
82
82
|
"package.json"() {
|
|
83
|
-
version = "2.1.
|
|
83
|
+
version = "2.1.4-a1";
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
|
|
@@ -3142,11 +3142,14 @@ var init_secret = __esm({
|
|
|
3142
3142
|
|
|
3143
3143
|
// src/core/sandbox/sandboxApi.ts
|
|
3144
3144
|
async function createRawApiError(response) {
|
|
3145
|
-
var _a3;
|
|
3145
|
+
var _a3, _b, _c;
|
|
3146
3146
|
let message = response.statusText;
|
|
3147
3147
|
try {
|
|
3148
3148
|
const body = await response.json();
|
|
3149
3149
|
message = (_a3 = body == null ? void 0 : body.message) != null ? _a3 : JSON.stringify(body);
|
|
3150
|
+
if ((body == null ? void 0 : body.item) || (body == null ? void 0 : body.reason)) {
|
|
3151
|
+
message = `${(_b = body.item) != null ? _b : "request"}: ${(_c = body.reason) != null ? _c : "error"}: ${message}`;
|
|
3152
|
+
}
|
|
3150
3153
|
} catch (e) {
|
|
3151
3154
|
try {
|
|
3152
3155
|
message = await response.text();
|
|
@@ -3168,6 +3171,50 @@ async function createRawApiError(response) {
|
|
|
3168
3171
|
function getRawApiHeaders(config, headers) {
|
|
3169
3172
|
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 : {});
|
|
3170
3173
|
}
|
|
3174
|
+
function gibToMib(value, name) {
|
|
3175
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
3176
|
+
throw new SandboxError(`resource target ${name} must be a positive number`);
|
|
3177
|
+
}
|
|
3178
|
+
const mib = value * MIB_PER_GIB;
|
|
3179
|
+
if (!Number.isSafeInteger(mib)) {
|
|
3180
|
+
throw new SandboxError(`resource target ${name} must be an exact number of MiB`);
|
|
3181
|
+
}
|
|
3182
|
+
return mib;
|
|
3183
|
+
}
|
|
3184
|
+
function resourceTargetsToApi(resources) {
|
|
3185
|
+
const unknown = Object.keys(resources != null ? resources : {}).filter(
|
|
3186
|
+
(key) => !["cpu", "memoryGiB", "diskGiB"].includes(key)
|
|
3187
|
+
);
|
|
3188
|
+
if (unknown.length) throw new SandboxError(`unsupported resource field: ${unknown.join(", ")}`);
|
|
3189
|
+
const body = {};
|
|
3190
|
+
const { cpu, memoryGiB, diskGiB } = resources != null ? resources : {};
|
|
3191
|
+
if (cpu !== void 0) {
|
|
3192
|
+
if (!Number.isSafeInteger(cpu) || cpu <= 0) {
|
|
3193
|
+
throw new SandboxError("resource target cpu must be a positive whole number");
|
|
3194
|
+
}
|
|
3195
|
+
body.vcpu = cpu;
|
|
3196
|
+
}
|
|
3197
|
+
if (memoryGiB !== void 0) body.memory_mb = gibToMib(memoryGiB, "memoryGiB");
|
|
3198
|
+
if (diskGiB !== void 0) body.disk_size_mb = gibToMib(diskGiB, "diskGiB");
|
|
3199
|
+
if (!Object.keys(body).length) throw new SandboxError("at least one resource target is required");
|
|
3200
|
+
return body;
|
|
3201
|
+
}
|
|
3202
|
+
function resizeResultFromApi(data) {
|
|
3203
|
+
var _a3, _b, _c;
|
|
3204
|
+
const result = {};
|
|
3205
|
+
for (const key of ["cpu", "memory", "disk"]) {
|
|
3206
|
+
const item = data == null ? void 0 : data[key];
|
|
3207
|
+
if (!item) continue;
|
|
3208
|
+
const divisor = key === "cpu" ? 1 : 1024;
|
|
3209
|
+
result[key] = __spreadProps(__spreadValues({}, item), {
|
|
3210
|
+
requested: ((_a3 = item.requested) != null ? _a3 : 0) / divisor,
|
|
3211
|
+
previous: ((_b = item.previous) != null ? _b : 0) / divisor,
|
|
3212
|
+
current: ((_c = item.current) != null ? _c : 0) / divisor,
|
|
3213
|
+
unit: key === "cpu" ? "cores" : "GiB"
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
return result;
|
|
3217
|
+
}
|
|
3171
3218
|
function getLifecycle(opts) {
|
|
3172
3219
|
if (opts == null ? void 0 : opts.lifecycle) {
|
|
3173
3220
|
return opts.lifecycle;
|
|
@@ -3183,7 +3230,7 @@ function getLifecycle(opts) {
|
|
|
3183
3230
|
autoResume: false
|
|
3184
3231
|
};
|
|
3185
3232
|
}
|
|
3186
|
-
var import_compare_versions4, SandboxApi, BasePaginator, SandboxPaginator, SnapshotPaginator;
|
|
3233
|
+
var import_compare_versions4, MIB_PER_GIB, SandboxApi, BasePaginator, SandboxPaginator, SnapshotPaginator;
|
|
3187
3234
|
var init_sandboxApi = __esm({
|
|
3188
3235
|
"src/core/sandbox/sandboxApi.ts"() {
|
|
3189
3236
|
"use strict";
|
|
@@ -3194,6 +3241,7 @@ var init_sandboxApi = __esm({
|
|
|
3194
3241
|
init_utils();
|
|
3195
3242
|
init_metadata();
|
|
3196
3243
|
init_secret();
|
|
3244
|
+
MIB_PER_GIB = 1024;
|
|
3197
3245
|
SandboxApi = class {
|
|
3198
3246
|
constructor() {
|
|
3199
3247
|
}
|
|
@@ -3376,28 +3424,24 @@ var init_sandboxApi = __esm({
|
|
|
3376
3424
|
templateType: "snapshot_template"
|
|
3377
3425
|
};
|
|
3378
3426
|
}
|
|
3379
|
-
static async
|
|
3427
|
+
static async resize(sandboxId, resources, opts) {
|
|
3428
|
+
const body = resourceTargetsToApi(resources);
|
|
3380
3429
|
const config = new ConnectionConfig(opts);
|
|
3381
|
-
raiseIfLegacy(config, "Sandbox.
|
|
3430
|
+
raiseIfLegacy(config, "Sandbox.resize", SandboxError);
|
|
3382
3431
|
const response = await fetch(
|
|
3383
|
-
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/
|
|
3432
|
+
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/resize`,
|
|
3384
3433
|
{
|
|
3385
3434
|
method: "POST",
|
|
3386
|
-
headers: getRawApiHeaders(config, {
|
|
3387
|
-
|
|
3388
|
-
}),
|
|
3389
|
-
body: JSON.stringify({
|
|
3390
|
-
requested_size_mib: requestedSizeMib
|
|
3391
|
-
}),
|
|
3435
|
+
headers: getRawApiHeaders(config, { "Content-Type": "application/json" }),
|
|
3436
|
+
body: JSON.stringify(body),
|
|
3392
3437
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3393
3438
|
}
|
|
3394
3439
|
);
|
|
3395
3440
|
if (response.status === 404) {
|
|
3396
3441
|
throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`);
|
|
3397
3442
|
}
|
|
3398
|
-
if (!response.ok)
|
|
3399
|
-
|
|
3400
|
-
}
|
|
3443
|
+
if (!response.ok) throw await createRawApiError(response);
|
|
3444
|
+
return resizeResultFromApi(await response.json());
|
|
3401
3445
|
}
|
|
3402
3446
|
static async reset(sandboxId, opts) {
|
|
3403
3447
|
var _a3;
|
|
@@ -3495,7 +3539,7 @@ var init_sandboxApi = __esm({
|
|
|
3495
3539
|
throw await createRawApiError(response);
|
|
3496
3540
|
}
|
|
3497
3541
|
const data = await response.json();
|
|
3498
|
-
return {
|
|
3542
|
+
return __spreadProps(__spreadValues({
|
|
3499
3543
|
sandboxId: data.sandboxID,
|
|
3500
3544
|
templateId: data.templateID,
|
|
3501
3545
|
name: data.name,
|
|
@@ -3504,10 +3548,11 @@ var init_sandboxApi = __esm({
|
|
|
3504
3548
|
endAt: new Date(data.endAt),
|
|
3505
3549
|
state: data.state,
|
|
3506
3550
|
cpuCount: data.cpuCount,
|
|
3507
|
-
memoryMB: data.memoryMB
|
|
3551
|
+
memoryMB: data.memoryMB
|
|
3552
|
+
}, data.diskSizeMB !== void 0 ? { diskSizeMB: data.diskSizeMB } : {}), {
|
|
3508
3553
|
envdVersion: data.envdVersion,
|
|
3509
3554
|
volumeMounts: (_b = data.volumeMounts) != null ? _b : []
|
|
3510
|
-
};
|
|
3555
|
+
});
|
|
3511
3556
|
}
|
|
3512
3557
|
static async setNetwork(sandboxId, opts) {
|
|
3513
3558
|
const config = new ConnectionConfig(opts);
|
|
@@ -3621,6 +3666,7 @@ var init_sandboxApi = __esm({
|
|
|
3621
3666
|
state: res.data.state,
|
|
3622
3667
|
cpuCount: res.data.cpuCount,
|
|
3623
3668
|
memoryMB: res.data.memoryMB,
|
|
3669
|
+
diskSizeMB: res.data.diskSizeMB,
|
|
3624
3670
|
network: res.data.network ? {
|
|
3625
3671
|
allowOut: res.data.network.allowOut,
|
|
3626
3672
|
denyOut: res.data.network.denyOut,
|
|
@@ -3773,7 +3819,7 @@ var init_sandboxApi = __esm({
|
|
|
3773
3819
|
return true;
|
|
3774
3820
|
}
|
|
3775
3821
|
static async createSandbox(template, timeoutMs, opts) {
|
|
3776
|
-
var _a3, _b, _c, _d, _e, _f, _g;
|
|
3822
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h;
|
|
3777
3823
|
const config = new ConnectionConfig(opts);
|
|
3778
3824
|
const longRunning = ((_a3 = opts == null ? void 0 : opts.metadata) == null ? void 0 : _a3.long_running) === "true";
|
|
3779
3825
|
const metadata = longRunning ? __spreadValues({}, opts == null ? void 0 : opts.metadata) : opts == null ? void 0 : opts.metadata;
|
|
@@ -3799,6 +3845,9 @@ var init_sandboxApi = __esm({
|
|
|
3799
3845
|
if (opts == null ? void 0 : opts.secretEnvs) {
|
|
3800
3846
|
raiseIfLegacy(config, "Sandbox.create secretEnvs", SandboxError);
|
|
3801
3847
|
}
|
|
3848
|
+
if (opts == null ? void 0 : opts.resources) {
|
|
3849
|
+
raiseIfLegacy(config, "Sandbox.create resources", SandboxError);
|
|
3850
|
+
}
|
|
3802
3851
|
const body2 = __spreadValues(__spreadValues({
|
|
3803
3852
|
templateID: template,
|
|
3804
3853
|
timeout,
|
|
@@ -3860,6 +3909,30 @@ var init_sandboxApi = __esm({
|
|
|
3860
3909
|
;
|
|
3861
3910
|
body.secrets = validatedSecretEnvs;
|
|
3862
3911
|
}
|
|
3912
|
+
if (opts == null ? void 0 : opts.resources) {
|
|
3913
|
+
const targets = resourceTargetsToApi(opts.resources);
|
|
3914
|
+
const response = await fetch(`${config.apiUrl}/sandboxes/custom`, {
|
|
3915
|
+
method: "POST",
|
|
3916
|
+
headers: getRawApiHeaders(config, { "Content-Type": "application/json" }),
|
|
3917
|
+
body: JSON.stringify(__spreadProps(__spreadValues({}, body), { resources: targets })),
|
|
3918
|
+
signal: config.getSignal((_h = opts == null ? void 0 : opts.requestTimeoutMs) != null ? _h : 36e4)
|
|
3919
|
+
});
|
|
3920
|
+
if (!response.ok) throw await createRawApiError(response);
|
|
3921
|
+
const data = await response.json();
|
|
3922
|
+
if ((0, import_compare_versions4.compareVersions)(data.envdVersion, "0.1.0") < 0) {
|
|
3923
|
+
await this.kill(data.sandboxID, opts);
|
|
3924
|
+
throw new TemplateError(
|
|
3925
|
+
"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."
|
|
3926
|
+
);
|
|
3927
|
+
}
|
|
3928
|
+
return {
|
|
3929
|
+
sandboxId: data.sandboxID,
|
|
3930
|
+
sandboxDomain: data.domain || void 0,
|
|
3931
|
+
envdVersion: data.envdVersion,
|
|
3932
|
+
envdAccessToken: data.envdAccessToken,
|
|
3933
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3934
|
+
};
|
|
3935
|
+
}
|
|
3863
3936
|
const res = await client.api.POST("/sandboxes", {
|
|
3864
3937
|
body,
|
|
3865
3938
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -4373,19 +4446,6 @@ var init_sandbox = __esm({
|
|
|
4373
4446
|
snapshotTemplateId: cloneResult.snapshotTemplateId
|
|
4374
4447
|
};
|
|
4375
4448
|
}
|
|
4376
|
-
/**
|
|
4377
|
-
* Dynamically adjust the hotplugged memory on a running sandbox.
|
|
4378
|
-
*
|
|
4379
|
-
* The value represents the new *total* plugged size in MiB, not a delta.
|
|
4380
|
-
* Use `0` to unplug all hotplugged memory.
|
|
4381
|
-
*/
|
|
4382
|
-
static async hotplugMemory(sandboxId, requestedSizeMib, opts) {
|
|
4383
|
-
return await SandboxApi.hotplugMemory(
|
|
4384
|
-
sandboxId,
|
|
4385
|
-
requestedSizeMib,
|
|
4386
|
-
opts
|
|
4387
|
-
);
|
|
4388
|
-
}
|
|
4389
4449
|
/**
|
|
4390
4450
|
* Mount a volume to a sandbox.
|
|
4391
4451
|
*
|
|
@@ -4396,6 +4456,10 @@ var init_sandbox = __esm({
|
|
|
4396
4456
|
*
|
|
4397
4457
|
* @returns updated sandbox information.
|
|
4398
4458
|
*/
|
|
4459
|
+
/** Increase running sandbox resources to absolute CPU and GiB targets. */
|
|
4460
|
+
static async resize(sandboxId, resources, opts) {
|
|
4461
|
+
return await SandboxApi.resize(sandboxId, resources, opts);
|
|
4462
|
+
}
|
|
4399
4463
|
static async mountVolume(sandboxId, name, path3, opts) {
|
|
4400
4464
|
return await SandboxApi.mountVolume(sandboxId, name, path3, opts);
|
|
4401
4465
|
}
|
|
@@ -4680,21 +4744,9 @@ var init_sandbox = __esm({
|
|
|
4680
4744
|
}
|
|
4681
4745
|
await SandboxApi.kill(this.sandboxId, this.resolveApiOpts(opts));
|
|
4682
4746
|
}
|
|
4683
|
-
/**
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
* The value represents the new *total* plugged size in MiB, not a delta.
|
|
4687
|
-
* Use `0` to unplug all hotplugged memory.
|
|
4688
|
-
*
|
|
4689
|
-
* @param requestedSizeMib new total plugged memory size in MiB.
|
|
4690
|
-
* @param opts connection options.
|
|
4691
|
-
*/
|
|
4692
|
-
async hotplugMemory(requestedSizeMib, opts) {
|
|
4693
|
-
await SandboxApi.hotplugMemory(
|
|
4694
|
-
this.sandboxId,
|
|
4695
|
-
requestedSizeMib,
|
|
4696
|
-
this.resolveApiOpts(opts)
|
|
4697
|
-
);
|
|
4747
|
+
/** Increase this sandbox's resources to absolute CPU and GiB targets. */
|
|
4748
|
+
async resize(resources, opts) {
|
|
4749
|
+
return await SandboxApi.resize(this.sandboxId, resources, this.resolveApiOpts(opts));
|
|
4698
4750
|
}
|
|
4699
4751
|
/**
|
|
4700
4752
|
* Pause a sandbox by its ID.
|
|
@@ -9062,6 +9114,9 @@ var init_client = __esm({
|
|
|
9062
9114
|
getQuota(opts) {
|
|
9063
9115
|
return Sandbox.getQuota(mergeConnectionOpts(this.opts, opts));
|
|
9064
9116
|
}
|
|
9117
|
+
resize(sandboxId, resources, opts) {
|
|
9118
|
+
return Sandbox.resize(sandboxId, resources, mergeConnectionOpts(this.opts, opts));
|
|
9119
|
+
}
|
|
9065
9120
|
getEvents(opts) {
|
|
9066
9121
|
return Sandbox.getEvents(mergeConnectionOpts(this.opts, opts));
|
|
9067
9122
|
}
|
|
@@ -9149,6 +9204,9 @@ var init_client = __esm({
|
|
|
9149
9204
|
getQuota(opts) {
|
|
9150
9205
|
return Sandbox.getQuota(mergeConnectionOpts(this.opts, opts));
|
|
9151
9206
|
}
|
|
9207
|
+
resize(sandboxId, resources, opts) {
|
|
9208
|
+
return Sandbox.resize(sandboxId, resources, mergeConnectionOpts(this.opts, opts));
|
|
9209
|
+
}
|
|
9152
9210
|
getEvents(opts) {
|
|
9153
9211
|
return Sandbox.getEvents(mergeConnectionOpts(this.opts, opts));
|
|
9154
9212
|
}
|