instabox 0.8.41 → 0.8.43
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/bin/instabox.mjs +18 -7
- package/cli/SHA256SUMS +6 -6
- package/cli/instabox-darwin-amd64 +0 -0
- package/cli/instabox-darwin-arm64 +0 -0
- package/cli/instabox-linux-amd64 +0 -0
- package/cli/instabox-linux-arm64 +0 -0
- package/cli/instabox-windows-amd64.exe +0 -0
- package/cli/instabox-windows-arm64.exe +0 -0
- package/lib/image.mjs +32 -0
- package/package.json +1 -1
package/bin/instabox.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
20
20
|
import { createClient } from '../lib/api.mjs';
|
|
21
21
|
import { orderBoxes } from '../lib/boxes.mjs';
|
|
22
22
|
import { guestUserNote, localGuestUser } from '../lib/guestuser.mjs';
|
|
23
|
+
import { resolveImage } from '../lib/image.mjs';
|
|
23
24
|
import {
|
|
24
25
|
bundledCli,
|
|
25
26
|
checkCli,
|
|
@@ -45,7 +46,8 @@ const API = (
|
|
|
45
46
|
process.env.INSTABOX_API ||
|
|
46
47
|
'https://api.instabox.sh'
|
|
47
48
|
).replace(/\/$/, '');
|
|
48
|
-
// The template a new box starts from: the CLI's and dashboard's default (shown as standard).
|
|
49
|
+
// The template a new box starts from: the CLI's and dashboard's default (shown as standard). An
|
|
50
|
+
// official template wins over a snapshot of the same name; snapshot:<name> picks the snapshot.
|
|
49
51
|
const IMAGE = process.env.INSTABOX_IMAGE || 'agent-browser';
|
|
50
52
|
// SSH certificate lifetime for a box with no timeout of its own.
|
|
51
53
|
const CERT_MIN = 120;
|
|
@@ -77,6 +79,9 @@ function usage() {
|
|
|
77
79
|
--no-skills do not install the instabox agent skills
|
|
78
80
|
npx instabox@latest <command> run an instabox CLI command (instabox help lists them)
|
|
79
81
|
|
|
82
|
+
INSTABOX_IMAGE=<template> picks the template sh starts from (default agent-browser);
|
|
83
|
+
INSTABOX_IMAGE=snapshot:<name> starts from a snapshot of yours instead.
|
|
84
|
+
|
|
80
85
|
Usage data (steps and outcomes, never names or arguments) goes to the instabox team;
|
|
81
86
|
INSTABOX_NO_TELEMETRY=1 or DO_NOT_TRACK=1 turns it off.
|
|
82
87
|
`);
|
|
@@ -190,19 +195,25 @@ async function quotaFull(err) {
|
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
async function newBox() {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
const src = await resolveImage(IMAGE, {
|
|
199
|
+
// Unreadable: null, and the name goes to the server as a template.
|
|
200
|
+
templates: () =>
|
|
201
|
+
client.call('GET', '/v1/templates').then(
|
|
202
|
+
(r) => r?.templates ?? null,
|
|
203
|
+
() => null,
|
|
204
|
+
),
|
|
205
|
+
snapshots: () => client.call('GET', '/v1/images').then((r) => r?.images ?? []),
|
|
206
|
+
});
|
|
207
|
+
if (src.missing) throw new Error(`no snapshot named ${src.missing} (instabox snapshot ls lists yours)`);
|
|
196
208
|
const body = {
|
|
197
209
|
name: `box-${randomBytes(3).toString('hex')}`,
|
|
198
210
|
desiredState: 'running',
|
|
211
|
+
...src,
|
|
199
212
|
};
|
|
200
|
-
if (img) body.imageId = img.id;
|
|
201
|
-
else body.templateId = IMAGE;
|
|
202
213
|
// The box's Linux user is named after yours, so `ssh <box>` over your own network works. A
|
|
203
214
|
// box from one of your own snapshots keeps the snapshot's user.
|
|
204
215
|
const user = localGuestUser();
|
|
205
|
-
if (user.name &&
|
|
216
|
+
if (user.name && src.templateId) body.guestUser = user.name;
|
|
206
217
|
const op = await waitOp(await client.call('POST', '/v1/machines', body));
|
|
207
218
|
return { id: op.machineId, name: body.name, user };
|
|
208
219
|
}
|
package/cli/SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
5f289a8732580c39dada8a34beaffd3a9ce875791425baf6e2da5f08a3b9c2e0 instabox-darwin-amd64
|
|
2
|
+
083ceebe0939785fe56a214c93d73cc0df79eedc0b9aa01c1105661db0b36222 instabox-darwin-arm64
|
|
3
|
+
5083d4af6088cf8e9a3418faebd62162cec097fea9c267121afad2eb43cd315d instabox-linux-amd64
|
|
4
|
+
0793c3aae88c57afdc1a5b96da2e89426a45c892ded9a10e18072f5242765939 instabox-linux-arm64
|
|
5
|
+
c618076b713a5fac84f6dfa48369246c72def71f5f246a4cbcd30e87cf572a0e instabox-windows-amd64.exe
|
|
6
|
+
3a18e15376d0e8fa59f535158b81903ae052e4f5aa1f1ea3d99de2574161c421 instabox-windows-arm64.exe
|
|
Binary file
|
|
Binary file
|
package/cli/instabox-linux-amd64
CHANGED
|
Binary file
|
package/cli/instabox-linux-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/image.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// What INSTABOX_IMAGE names: an official template (GET /v1/templates), as `id` or `id@version`.
|
|
2
|
+
// A snapshot of yours is named with `snapshot:<name or id>`, so one that shares a template's name
|
|
3
|
+
// never stands in for it. A bare name that is no template still finds a snapshot of that name.
|
|
4
|
+
|
|
5
|
+
export const SNAPSHOT_PREFIX = 'snapshot:';
|
|
6
|
+
|
|
7
|
+
// The snapshot named want: by id first, else by name.
|
|
8
|
+
function findSnapshot(snapshots, want) {
|
|
9
|
+
const list = Array.isArray(snapshots) ? snapshots.filter((s) => s && typeof s.id === 'string') : [];
|
|
10
|
+
return list.find((s) => s.id === want) || list.find((s) => s.name === want) || null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// isTemplate: whether image (id or id@version) is one of templates. templates null (the list
|
|
14
|
+
// could not be read): treated as a template, so the server decides and a snapshot never wins.
|
|
15
|
+
export function isTemplate(image, templates) {
|
|
16
|
+
if (!Array.isArray(templates)) return true;
|
|
17
|
+
const id = image.split('@')[0];
|
|
18
|
+
return templates.some((t) => t && t.id === id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// resolveImage turns image into the create request's source: { templateId } or { imageId }, or
|
|
22
|
+
// { missing } for a snapshot: name that matches none. snapshots is read only when needed.
|
|
23
|
+
export async function resolveImage(image, { templates, snapshots }) {
|
|
24
|
+
if (image.startsWith(SNAPSHOT_PREFIX)) {
|
|
25
|
+
const want = image.slice(SNAPSHOT_PREFIX.length);
|
|
26
|
+
const s = findSnapshot(await snapshots(), want);
|
|
27
|
+
return s ? { imageId: s.id } : { missing: want };
|
|
28
|
+
}
|
|
29
|
+
if (isTemplate(image, await templates())) return { templateId: image };
|
|
30
|
+
const s = findSnapshot(await snapshots(), image);
|
|
31
|
+
return s ? { imageId: s.id } : { templateId: image };
|
|
32
|
+
}
|