@insforge/instabox-sdk 0.8.0 → 0.9.0
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/README.md +11 -8
- package/dist/index.cjs +27 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/instabox/SKILL.md +10 -8
package/README.md
CHANGED
|
@@ -32,14 +32,14 @@ The key is sent as the `X-API-Key` header.
|
|
|
32
32
|
|
|
33
33
|
### Scopes
|
|
34
34
|
|
|
35
|
-
| Scope | Allows
|
|
36
|
-
| ----------------- |
|
|
37
|
-
| `machines:read` | `Sandbox.list`, `getInfo`, `isRunning`, `vault`, `ports.list`
|
|
38
|
-
| `machines:write` | `create`, `connect` (resume), `pause`, `resume`, `stop`, `setAutoSuspend`, `setMetadata`, `disableVault`, `pushVault`, `commands`, `files`, `sshCredentials`, `ports.publish`, `ports.unpublish` |
|
|
39
|
-
| `machines:delete` | `kill`
|
|
40
|
-
| `images:read` | Resolve private snapshot names, `listSnapshots`, `getSnapshot`
|
|
41
|
-
| `images:write` | `createSnapshot`
|
|
42
|
-
| `images:delete` | `deleteSnapshot`
|
|
35
|
+
| Scope | Allows |
|
|
36
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `machines:read` | `Sandbox.list`, `getInfo`, `isRunning`, `vault`, `ports.list` |
|
|
38
|
+
| `machines:write` | `create`, `connect` (resume), `pause`, `resume`, `stop`, `setAutoSuspend`, `setMetadata`, `resize`, `disableVault`, `pushVault`, `commands`, `files`, `sshCredentials`, `ports.publish`, `ports.unpublish` |
|
|
39
|
+
| `machines:delete` | `kill` |
|
|
40
|
+
| `images:read` | Resolve private snapshot names, `listSnapshots`, `getSnapshot` |
|
|
41
|
+
| `images:write` | `createSnapshot` |
|
|
42
|
+
| `images:delete` | `deleteSnapshot` |
|
|
43
43
|
|
|
44
44
|
`:write` and `:delete` imply `:read`. Creating from a template or a snapshot ID needs only machine scopes. Creating from a snapshot name also needs `images:read`. Snapshot permissions are named `images:*` by the current API. Add `images:write` and `images:delete` if your code saves and deletes snapshots. A call outside the key's scopes throws `InstaboxAuthError` (`403 insufficient_scope`).
|
|
45
45
|
|
|
@@ -191,6 +191,7 @@ const mine = await Sandbox.list({ metadata: { userId: 'u_42' } }) // all pairs m
|
|
|
191
191
|
|
|
192
192
|
await sandbox.setAutoSuspend(10 * 60_000) // paid plan: pause after 10 idle minutes; 0 keeps it on (free plan: 403)
|
|
193
193
|
await sandbox.setMetadata({ userId: 'u_42', stage: 'review' }) // replaces it; {} clears
|
|
194
|
+
await sandbox.resize({ vcpus: 8, memMiB: 16384 }) // paid plan: another of its sizes, restarting it if it runs
|
|
194
195
|
|
|
195
196
|
await sandbox.kill() // delete the machine and its disks (sends X-Confirm-Delete); false if already gone
|
|
196
197
|
await Sandbox.kill(id)
|
|
@@ -198,6 +199,8 @@ await Sandbox.kill(id)
|
|
|
198
199
|
|
|
199
200
|
Every lifecycle call waits for its operation to finish (default limit 10 minutes, `operationTimeoutMs` to change it).
|
|
200
201
|
|
|
202
|
+
Resize: `resize({ vcpus, memMiB })` gives the sandbox another of its plan's sizes, on a paid plan (`instabox whoami --json` lists them as `allowedSpecs`). A stopped sandbox takes the new size at its next start. A running or paused one is stopped, resized and started again by one server operation, so its files stay but its running processes and paused memory do not. If it cannot start at the new size, the server starts it again at the old one and `resize` throws the operation's error. A size the plan does not offer throws `InstaboxQuotaError` (`spec_not_allowed`). A server that cannot restart a sandbox for a resize throws `resize_restart_off`: stop the sandbox first.
|
|
203
|
+
|
|
201
204
|
Idle pause: a new sandbox pauses after 30 idle minutes (no agent working, no terminal use, little CPU) and resumes on the next `commands.run`, file read or SSH sign-in, processes and memory intact. On a paid plan, `autoSuspendMs` sets another idle time (5 to 30 minutes, in whole minutes) or 0 (never) and `setAutoSuspend(ms)` changes it later; the free plan keeps 30 minutes and refuses any other value with a 403, so leave both out there. The dashboard always uses 30 minutes. `getInfo().autoSuspendMs` shows what applies. The setting stays across pause and resume.
|
|
202
205
|
|
|
203
206
|
No lifetime timeout: since 0.6.0 (server change of 2026-10-20) a sandbox has no timeout that pauses or deletes it a fixed time after creation. Passing the 0.5 options `timeoutMs` or `onTimeout`, or calling `setTimeout()`, throws `InstaboxError` with code `retired_option` before any request, so code written for 0.5 fails instead of leaving sandboxes running. Use `autoSuspendMs` / `setAutoSuspend(ms)` (paid plan) for the idle pause, `archiveMs` to stop and archive a sandbox a set time after creation, and `kill()` in a `finally` block to delete it when you are done.
|
package/dist/index.cjs
CHANGED
|
@@ -2603,6 +2603,12 @@ function toSeconds(ms, field) {
|
|
|
2603
2603
|
}
|
|
2604
2604
|
return s;
|
|
2605
2605
|
}
|
|
2606
|
+
function wholeCount(field, n) {
|
|
2607
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
2608
|
+
throw new InstaboxError(`${field} must be a whole number from 1; got ${n}`, { code: "bad_request" });
|
|
2609
|
+
}
|
|
2610
|
+
return n;
|
|
2611
|
+
}
|
|
2606
2612
|
var METADATA_KEY = /^[A-Za-z0-9_.-]{1,64}$/;
|
|
2607
2613
|
var enc4 = encodeURIComponent;
|
|
2608
2614
|
var Sandbox = class _Sandbox {
|
|
@@ -2758,6 +2764,27 @@ var Sandbox = class _Sandbox {
|
|
|
2758
2764
|
async setTimeout(..._args) {
|
|
2759
2765
|
throw timeoutRemoved("setTimeout()", "Use setAutoSuspend(ms) to pause the sandbox once it has been idle that long");
|
|
2760
2766
|
}
|
|
2767
|
+
/**
|
|
2768
|
+
* Gives the sandbox another of its plan's sizes (paid plans). A stopped sandbox takes it at its next
|
|
2769
|
+
* start. A running or paused one is stopped, resized and started again by one server operation: files
|
|
2770
|
+
* stay, running processes and paused memory do not. If it cannot start at the new size, the server
|
|
2771
|
+
* starts it again at the old one and this throws. A size the plan does not offer throws
|
|
2772
|
+
* `InstaboxQuotaError` (`spec_not_allowed`). Requires machines:write.
|
|
2773
|
+
*/
|
|
2774
|
+
async resize(opts) {
|
|
2775
|
+
const vcpus = wholeCount("vcpus", opts.vcpus);
|
|
2776
|
+
const memMiB = wholeCount("memMiB", opts.memMiB);
|
|
2777
|
+
await this.settle();
|
|
2778
|
+
if (this.machine.spec.vcpus === vcpus && this.machine.spec.memMiB === memMiB) return;
|
|
2779
|
+
const body = { vcpus, memMiB };
|
|
2780
|
+
if (this.machine.state !== "stopped") body.apply = "restart";
|
|
2781
|
+
const r = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, { body });
|
|
2782
|
+
try {
|
|
2783
|
+
if ("machineId" in r) await this.http.waitForOperation(r);
|
|
2784
|
+
} finally {
|
|
2785
|
+
this.machine = await getMachine(this.http, this.sandboxId).catch(() => this.machine);
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2761
2788
|
/** Replaces the sandbox's metadata (`{}` clears it). */
|
|
2762
2789
|
async setMetadata(metadata) {
|
|
2763
2790
|
this.machine = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, {
|