agental 0.49.0 → 0.50.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/dist/cli.js +565 -140
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3037,18 +3037,18 @@ var require_set = __commonJS({
|
|
|
3037
3037
|
}
|
|
3038
3038
|
static from(schema, iterable, ctx) {
|
|
3039
3039
|
const { replacer } = ctx;
|
|
3040
|
-
const
|
|
3040
|
+
const set3 = new this(schema);
|
|
3041
3041
|
if (iterable && Symbol.iterator in Object(iterable))
|
|
3042
3042
|
for (let value of iterable) {
|
|
3043
3043
|
if (typeof replacer === "function")
|
|
3044
3044
|
value = replacer.call(iterable, value, value);
|
|
3045
|
-
|
|
3045
|
+
set3.items.push(Pair.createPair(value, null, ctx));
|
|
3046
3046
|
}
|
|
3047
|
-
return
|
|
3047
|
+
return set3;
|
|
3048
3048
|
}
|
|
3049
3049
|
};
|
|
3050
3050
|
YAMLSet.tag = "tag:yaml.org,2002:set";
|
|
3051
|
-
var
|
|
3051
|
+
var set2 = {
|
|
3052
3052
|
collection: "map",
|
|
3053
3053
|
identify: (value) => value instanceof Set,
|
|
3054
3054
|
nodeClass: YAMLSet,
|
|
@@ -3067,7 +3067,7 @@ var require_set = __commonJS({
|
|
|
3067
3067
|
}
|
|
3068
3068
|
};
|
|
3069
3069
|
exports.YAMLSet = YAMLSet;
|
|
3070
|
-
exports.set =
|
|
3070
|
+
exports.set = set2;
|
|
3071
3071
|
}
|
|
3072
3072
|
});
|
|
3073
3073
|
|
|
@@ -3174,7 +3174,7 @@ var require_schema3 = __commonJS({
|
|
|
3174
3174
|
var merge = require_merge();
|
|
3175
3175
|
var omap = require_omap();
|
|
3176
3176
|
var pairs = require_pairs();
|
|
3177
|
-
var
|
|
3177
|
+
var set2 = require_set();
|
|
3178
3178
|
var timestamp = require_timestamp();
|
|
3179
3179
|
var schema = [
|
|
3180
3180
|
map.map,
|
|
@@ -3194,7 +3194,7 @@ var require_schema3 = __commonJS({
|
|
|
3194
3194
|
merge.merge,
|
|
3195
3195
|
omap.omap,
|
|
3196
3196
|
pairs.pairs,
|
|
3197
|
-
|
|
3197
|
+
set2.set,
|
|
3198
3198
|
timestamp.intTime,
|
|
3199
3199
|
timestamp.floatTime,
|
|
3200
3200
|
timestamp.timestamp
|
|
@@ -3221,7 +3221,7 @@ var require_tags = __commonJS({
|
|
|
3221
3221
|
var omap = require_omap();
|
|
3222
3222
|
var pairs = require_pairs();
|
|
3223
3223
|
var schema$2 = require_schema3();
|
|
3224
|
-
var
|
|
3224
|
+
var set2 = require_set();
|
|
3225
3225
|
var timestamp = require_timestamp();
|
|
3226
3226
|
var schemas = /* @__PURE__ */ new Map([
|
|
3227
3227
|
["core", schema.schema],
|
|
@@ -3247,7 +3247,7 @@ var require_tags = __commonJS({
|
|
|
3247
3247
|
omap: omap.omap,
|
|
3248
3248
|
pairs: pairs.pairs,
|
|
3249
3249
|
seq: seq.seq,
|
|
3250
|
-
set:
|
|
3250
|
+
set: set2.set,
|
|
3251
3251
|
timestamp: timestamp.timestamp
|
|
3252
3252
|
};
|
|
3253
3253
|
var coreKnownTags = {
|
|
@@ -3255,7 +3255,7 @@ var require_tags = __commonJS({
|
|
|
3255
3255
|
"tag:yaml.org,2002:merge": merge.merge,
|
|
3256
3256
|
"tag:yaml.org,2002:omap": omap.omap,
|
|
3257
3257
|
"tag:yaml.org,2002:pairs": pairs.pairs,
|
|
3258
|
-
"tag:yaml.org,2002:set":
|
|
3258
|
+
"tag:yaml.org,2002:set": set2.set,
|
|
3259
3259
|
"tag:yaml.org,2002:timestamp": timestamp.timestamp
|
|
3260
3260
|
};
|
|
3261
3261
|
function getTags(customTags, schemaName, addMergeTag) {
|
|
@@ -6363,15 +6363,15 @@ var require_parser = __commonJS({
|
|
|
6363
6363
|
var node_process = __require("process");
|
|
6364
6364
|
var cst = require_cst();
|
|
6365
6365
|
var lexer = require_lexer();
|
|
6366
|
-
function includesToken(
|
|
6367
|
-
for (let i = 0; i <
|
|
6368
|
-
if (
|
|
6366
|
+
function includesToken(list5, type) {
|
|
6367
|
+
for (let i = 0; i < list5.length; ++i)
|
|
6368
|
+
if (list5[i].type === type)
|
|
6369
6369
|
return true;
|
|
6370
6370
|
return false;
|
|
6371
6371
|
}
|
|
6372
|
-
function findNonEmptyIndex(
|
|
6373
|
-
for (let i = 0; i <
|
|
6374
|
-
switch (
|
|
6372
|
+
function findNonEmptyIndex(list5) {
|
|
6373
|
+
for (let i = 0; i < list5.length; ++i) {
|
|
6374
|
+
switch (list5[i].type) {
|
|
6375
6375
|
case "space":
|
|
6376
6376
|
case "comment":
|
|
6377
6377
|
case "newline":
|
|
@@ -7411,7 +7411,7 @@ import { parseArgs } from "node:util";
|
|
|
7411
7411
|
|
|
7412
7412
|
// ../src/cli-build.ts
|
|
7413
7413
|
var PUBLISHED = true;
|
|
7414
|
-
var CLI_VERSION = true ? "0.
|
|
7414
|
+
var CLI_VERSION = true ? "0.50.0" : "dev";
|
|
7415
7415
|
var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
|
|
7416
7416
|
var PACKAGE_NAME = "agental";
|
|
7417
7417
|
var USER_AGENT = `agental-cli/${CLI_VERSION}`;
|
|
@@ -7969,8 +7969,8 @@ function keyOf(body) {
|
|
|
7969
7969
|
throw new Error("The answer was not an API key.");
|
|
7970
7970
|
}
|
|
7971
7971
|
const key2 = body;
|
|
7972
|
-
const
|
|
7973
|
-
return { ...key2, actions:
|
|
7972
|
+
const list5 = (value) => Array.isArray(value) ? value.map(String) : [];
|
|
7973
|
+
return { ...key2, actions: list5(key2.actions), sandboxIds: list5(key2.sandboxIds), templateIds: list5(key2.templateIds), allowFrom: list5(key2.allowFrom) };
|
|
7974
7974
|
}
|
|
7975
7975
|
function keysOf(body) {
|
|
7976
7976
|
const listed2 = body?.apiKeys;
|
|
@@ -8303,7 +8303,7 @@ async function pushRequest(base, ask13) {
|
|
|
8303
8303
|
async function listen() {
|
|
8304
8304
|
let arrived = () => {
|
|
8305
8305
|
};
|
|
8306
|
-
let
|
|
8306
|
+
let answer4 = () => {
|
|
8307
8307
|
};
|
|
8308
8308
|
const next = new Promise((resolve) => arrived = resolve);
|
|
8309
8309
|
let taken = false;
|
|
@@ -8318,7 +8318,7 @@ async function listen() {
|
|
|
8318
8318
|
return;
|
|
8319
8319
|
}
|
|
8320
8320
|
taken = true;
|
|
8321
|
-
|
|
8321
|
+
answer4 = (to) => response.writeHead(302, { location: to, "cache-control": "no-store" }).end();
|
|
8322
8322
|
arrived(url);
|
|
8323
8323
|
});
|
|
8324
8324
|
await new Promise((resolve, reject) => {
|
|
@@ -8326,7 +8326,7 @@ async function listen() {
|
|
|
8326
8326
|
server2.listen(0, "127.0.0.1", resolve);
|
|
8327
8327
|
});
|
|
8328
8328
|
const { port } = server2.address();
|
|
8329
|
-
return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) =>
|
|
8329
|
+
return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) => answer4(to) };
|
|
8330
8330
|
}
|
|
8331
8331
|
async function browserSignIn(base, term, organizationId) {
|
|
8332
8332
|
const verifier = randomBytes2(32).toString("base64url");
|
|
@@ -8691,8 +8691,8 @@ function claudeDesktopHere(places, platform = process.platform, env = process.en
|
|
|
8691
8691
|
function addToClaudeLink(url) {
|
|
8692
8692
|
return `https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=${CONNECTOR_NAME}&connectorUrl=${encodeURIComponent(url)}`;
|
|
8693
8693
|
}
|
|
8694
|
-
function names(
|
|
8695
|
-
return
|
|
8694
|
+
function names(list5) {
|
|
8695
|
+
return list5.length < 2 ? list5[0] ?? "" : `${list5.slice(0, -1).join(", ")} and ${list5.at(-1)}`;
|
|
8696
8696
|
}
|
|
8697
8697
|
async function ensureConnector(site2, places = placesFrom()) {
|
|
8698
8698
|
const url = `${site2}/v1/mcp`;
|
|
@@ -8994,9 +8994,9 @@ async function api(base, key2, method, pathname, body, headers = {}) {
|
|
|
8994
8994
|
}
|
|
8995
8995
|
return { status: response.status, body: parsed && typeof parsed === "object" ? parsed : {} };
|
|
8996
8996
|
}
|
|
8997
|
-
function errorOf(
|
|
8998
|
-
const error =
|
|
8999
|
-
return { code: String(error["code"] ?? `http_${
|
|
8997
|
+
function errorOf(answer4) {
|
|
8998
|
+
const error = answer4.body["error"] && typeof answer4.body["error"] === "object" ? answer4.body["error"] : {};
|
|
8999
|
+
return { code: String(error["code"] ?? `http_${answer4.status}`), message: String(error["message"] ?? `HTTP ${answer4.status}`) };
|
|
9000
9000
|
}
|
|
9001
9001
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9002
9002
|
function real(file) {
|
|
@@ -9613,6 +9613,18 @@ var COMMANDS = [
|
|
|
9613
9613
|
["--json", "print as JSON"]
|
|
9614
9614
|
]
|
|
9615
9615
|
},
|
|
9616
|
+
{
|
|
9617
|
+
name: "secret",
|
|
9618
|
+
summary: "Keep your organization's secrets, sealed on this machine before they are sent, and give them to templates and sandboxes.",
|
|
9619
|
+
examples: ["agental secret set GITHUB_TOKEN --host api.github.com,github.com", "agental secret use GITHUB_TOKEN --template default", "agental secret list"],
|
|
9620
|
+
flags: [
|
|
9621
|
+
["--host <host>[,<host>...]", "set, seal: the hosts its value may go to, and no other"],
|
|
9622
|
+
["--template <template>", "use, unuse: the template whose sandboxes see it"],
|
|
9623
|
+
["--sandbox <sandbox-id>", "use, unuse: the one sandbox that sees it"],
|
|
9624
|
+
["--yes", "delete: go on without asking"],
|
|
9625
|
+
["--json", "print as JSON"]
|
|
9626
|
+
]
|
|
9627
|
+
},
|
|
9616
9628
|
{ name: "jobs", summary: "List your jobs, or one sandbox's, or one template's." },
|
|
9617
9629
|
{
|
|
9618
9630
|
name: "job",
|
|
@@ -10473,12 +10485,12 @@ async function organizations(client) {
|
|
|
10473
10485
|
const me = await ask5(client, "GET", "/v1/me");
|
|
10474
10486
|
return { organizations: Array.isArray(listed2) ? listed2 : [], acting: String(me["activeOrganizationId"] ?? "") };
|
|
10475
10487
|
}
|
|
10476
|
-
function organizationNamed(
|
|
10477
|
-
const byId =
|
|
10488
|
+
function organizationNamed(list5, given) {
|
|
10489
|
+
const byId = list5.find((organization) => organization.id === given);
|
|
10478
10490
|
if (byId) {
|
|
10479
10491
|
return byId;
|
|
10480
10492
|
}
|
|
10481
|
-
const byName =
|
|
10493
|
+
const byName = list5.filter((organization) => organization.name.toLowerCase() === given.toLowerCase());
|
|
10482
10494
|
if (byName.length === 1 && byName[0]) {
|
|
10483
10495
|
return byName[0];
|
|
10484
10496
|
}
|
|
@@ -10491,14 +10503,14 @@ async function org(client, positionals, options, signInTo) {
|
|
|
10491
10503
|
const [verb = "list", ...rest] = positionals;
|
|
10492
10504
|
switch (verb) {
|
|
10493
10505
|
case "list": {
|
|
10494
|
-
const { organizations:
|
|
10506
|
+
const { organizations: list5, acting } = await organizations(client);
|
|
10495
10507
|
if (options.json) {
|
|
10496
|
-
print2(true, { organizations:
|
|
10508
|
+
print2(true, { organizations: list5.map((organization) => ({ ...organization, acting: organization.id === acting })) }, "");
|
|
10497
10509
|
return;
|
|
10498
10510
|
}
|
|
10499
10511
|
process.stdout.write(` ${[pad("ID", 22), pad("NAME", 24), "ROLE"].join(" ")}
|
|
10500
10512
|
`);
|
|
10501
|
-
for (const organization of
|
|
10513
|
+
for (const organization of list5) {
|
|
10502
10514
|
const role = organization.personal ? "your own" : organization.role ?? "";
|
|
10503
10515
|
process.stdout.write(`${organization.id === acting ? "*" : " "} ${[pad(organization.id, 22), pad(organization.name, 24), role].join(" ")}
|
|
10504
10516
|
`);
|
|
@@ -10511,8 +10523,8 @@ async function org(client, positionals, options, signInTo) {
|
|
|
10511
10523
|
if (!given) {
|
|
10512
10524
|
throw new Error("org use takes the organization's id or name: agental org use Acme.");
|
|
10513
10525
|
}
|
|
10514
|
-
const { organizations:
|
|
10515
|
-
const chosen = organizationNamed(
|
|
10526
|
+
const { organizations: list5, acting } = await organizations(client);
|
|
10527
|
+
const chosen = organizationNamed(list5, given);
|
|
10516
10528
|
if (chosen.id === acting) {
|
|
10517
10529
|
process.stdout.write(`This command's key acts in ${chosen.name} already.
|
|
10518
10530
|
`);
|
|
@@ -10542,15 +10554,15 @@ agental org use ${organization.id} signs this command in to it.
|
|
|
10542
10554
|
}
|
|
10543
10555
|
}
|
|
10544
10556
|
async function actingTeam(client) {
|
|
10545
|
-
const { organizations:
|
|
10546
|
-
const team =
|
|
10557
|
+
const { organizations: list5, acting } = await organizations(client);
|
|
10558
|
+
const team = list5.find((organization) => organization.id === acting);
|
|
10547
10559
|
if (!team) {
|
|
10548
10560
|
throw new Error("This command's key acts in no organization you are in. agental org use <organization> signs it in to one.");
|
|
10549
10561
|
}
|
|
10550
10562
|
return team;
|
|
10551
10563
|
}
|
|
10552
|
-
function memberNamed(
|
|
10553
|
-
const found =
|
|
10564
|
+
function memberNamed(list5, given) {
|
|
10565
|
+
const found = list5.find((member) => member.userId === given || member.email?.toLowerCase() === given.toLowerCase());
|
|
10554
10566
|
if (!found) {
|
|
10555
10567
|
throw new Error(`No member ${given} in this team. agental members lists them.`);
|
|
10556
10568
|
}
|
|
@@ -10560,7 +10572,7 @@ async function members(client, positionals, options) {
|
|
|
10560
10572
|
const [verb = "list", target] = positionals;
|
|
10561
10573
|
const team = await actingTeam(client);
|
|
10562
10574
|
const listed2 = await ask5(client, "GET", `/v1/organizations/${encodeURIComponent(team.id)}/members`);
|
|
10563
|
-
const
|
|
10575
|
+
const list5 = Array.isArray(listed2["members"]) ? listed2["members"] : [];
|
|
10564
10576
|
switch (verb) {
|
|
10565
10577
|
case "list": {
|
|
10566
10578
|
if (options.json) {
|
|
@@ -10572,7 +10584,7 @@ async function members(client, positionals, options) {
|
|
|
10572
10584
|
`);
|
|
10573
10585
|
process.stdout.write(`${[pad("ID", 34), pad("EMAIL", 30), pad("ROLE", 8), "ADDED"].join(" ")}
|
|
10574
10586
|
`);
|
|
10575
|
-
for (const member of
|
|
10587
|
+
for (const member of list5) {
|
|
10576
10588
|
process.stdout.write(`${[pad(member.userId, 34), pad(member.email ?? member.name ?? "", 30), pad(member.role, 8), member.addedAt.slice(0, 10)].join(" ")}
|
|
10577
10589
|
`);
|
|
10578
10590
|
}
|
|
@@ -10582,7 +10594,7 @@ async function members(client, positionals, options) {
|
|
|
10582
10594
|
if (!target) {
|
|
10583
10595
|
throw new Error("members remove takes the member's id or email: agental members remove cy@example.com.");
|
|
10584
10596
|
}
|
|
10585
|
-
const member = memberNamed(
|
|
10597
|
+
const member = memberNamed(list5, target);
|
|
10586
10598
|
const query = options.revokeKeys ? "?revokeKeys=true" : "";
|
|
10587
10599
|
const removed = await ask5(client, "DELETE", `/v1/organizations/${encodeURIComponent(team.id)}/members/${encodeURIComponent(member.userId)}${query}`);
|
|
10588
10600
|
const revoked = Number(removed["revokedKeys"] ?? 0);
|
|
@@ -10864,15 +10876,15 @@ function jobInputsOf(options) {
|
|
|
10864
10876
|
return void 0;
|
|
10865
10877
|
}
|
|
10866
10878
|
const inputs = {};
|
|
10867
|
-
const add = (given,
|
|
10879
|
+
const add = (given, secret2) => {
|
|
10868
10880
|
const [name, value] = pairOf(given);
|
|
10869
10881
|
if (name === "") {
|
|
10870
|
-
throw new Error(`${
|
|
10882
|
+
throw new Error(`${secret2 ? "--secret-input" : "--input"} is NAME=DEFAULT, or NAME for one a run must be given: ${given} has no name.`);
|
|
10871
10883
|
}
|
|
10872
10884
|
if (Object.hasOwn(inputs, name)) {
|
|
10873
10885
|
throw new Error(`The input ${name} is given twice.`);
|
|
10874
10886
|
}
|
|
10875
|
-
inputs[name] =
|
|
10887
|
+
inputs[name] = secret2 ? { default: value, secret: true } : value;
|
|
10876
10888
|
};
|
|
10877
10889
|
for (const given of options.input ?? []) {
|
|
10878
10890
|
add(given, false);
|
|
@@ -11323,11 +11335,11 @@ function signatureOf(trigger2) {
|
|
|
11323
11335
|
}
|
|
11324
11336
|
}
|
|
11325
11337
|
var addressOf = (trigger2) => trigger2.url ?? "none: this API serves no addresses";
|
|
11326
|
-
function printTrigger(trigger2,
|
|
11338
|
+
function printTrigger(trigger2, secret2) {
|
|
11327
11339
|
const rows = [
|
|
11328
11340
|
["id", trigger2.id],
|
|
11329
11341
|
["address", addressOf(trigger2)],
|
|
11330
|
-
...
|
|
11342
|
+
...secret2 === void 0 ? [] : [["secret", `${secret2} (shown this once: keep it now)`]],
|
|
11331
11343
|
["signature", signatureOf(trigger2)],
|
|
11332
11344
|
["respond", trigger2.respond === "wait" ? "wait: a call is held until the run ends, up to 60 s" : "accepted: a call is answered at once with its run's id"],
|
|
11333
11345
|
["rate", `${trigger2.ratePerMinute} calls a minute`],
|
|
@@ -12431,11 +12443,11 @@ async function offload(client, words2, options) {
|
|
|
12431
12443
|
return;
|
|
12432
12444
|
}
|
|
12433
12445
|
const enabled = turn === void 0 ? (await ask8(client, "GET", "/v1/offload")).enabled : turn === "on";
|
|
12434
|
-
const
|
|
12446
|
+
const set2 = await ask8(client, "PUT", "/v1/offload", { enabled, ...overPercent === void 0 ? {} : { overPercent } });
|
|
12435
12447
|
if (options.json) {
|
|
12436
|
-
printJson2(
|
|
12448
|
+
printJson2(set2);
|
|
12437
12449
|
} else {
|
|
12438
|
-
sayOffload(
|
|
12450
|
+
sayOffload(set2);
|
|
12439
12451
|
}
|
|
12440
12452
|
}
|
|
12441
12453
|
async function coreDays(client, options) {
|
|
@@ -12793,9 +12805,9 @@ function describe4(webhook2) {
|
|
|
12793
12805
|
""
|
|
12794
12806
|
].join("\n");
|
|
12795
12807
|
}
|
|
12796
|
-
function saySecret(
|
|
12797
|
-
if (
|
|
12798
|
-
process.stdout.write(`secret: ${
|
|
12808
|
+
function saySecret(secret2) {
|
|
12809
|
+
if (secret2) {
|
|
12810
|
+
process.stdout.write(`secret: ${secret2}
|
|
12799
12811
|
`);
|
|
12800
12812
|
process.stderr.write("The signing secret is shown this once. Keep it where your receiver checks the X-Agental-Signature of each post.\n");
|
|
12801
12813
|
}
|
|
@@ -13222,16 +13234,16 @@ async function snapshot(client, positionals, options) {
|
|
|
13222
13234
|
if (found.kept === STORAGE_ONLY) {
|
|
13223
13235
|
process.stderr.write("Its server no longer holds it: it is fetched from storage first, which takes a few minutes.\n");
|
|
13224
13236
|
}
|
|
13225
|
-
const
|
|
13237
|
+
const answer4 = await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
|
|
13226
13238
|
headers: { "Idempotency-Key": options.idempotencyKey ?? `cli-${randomUUID2()}` },
|
|
13227
13239
|
body: { snapshotId: found.id }
|
|
13228
13240
|
});
|
|
13229
13241
|
if (options.json) {
|
|
13230
|
-
process.stdout.write(`${JSON.stringify(
|
|
13242
|
+
process.stdout.write(`${JSON.stringify(answer4, null, 2)}
|
|
13231
13243
|
`);
|
|
13232
13244
|
return;
|
|
13233
13245
|
}
|
|
13234
|
-
const read2 =
|
|
13246
|
+
const read2 = answer4;
|
|
13235
13247
|
const discarded = Array.isArray(read2?.discarded) ? read2.discarded.map(String) : [];
|
|
13236
13248
|
const status = typeof read2?.sandbox?.status === "string" ? `, and ${read2.sandbox.status}` : "";
|
|
13237
13249
|
process.stdout.write(`${sandbox} is as it was at ${found.name}${status}.
|
|
@@ -13260,8 +13272,368 @@ async function snapshot(client, positionals, options) {
|
|
|
13260
13272
|
}
|
|
13261
13273
|
}
|
|
13262
13274
|
|
|
13275
|
+
// ../sdk/typescript/src/sealed.ts
|
|
13276
|
+
var SEALED_SUITE = "x25519-hkdf-sha256-aes256gcm";
|
|
13277
|
+
var ROOT_PUBLIC_KEYS = [];
|
|
13278
|
+
var KEM_ID = 32;
|
|
13279
|
+
var KDF_ID = 1;
|
|
13280
|
+
var AEAD_ID = 2;
|
|
13281
|
+
var INFO = "agental sealed secret v1";
|
|
13282
|
+
var AAD_LABEL = "agental sealed secret aad v1";
|
|
13283
|
+
var KEY_MESSAGE_LABEL = "agental sealing key v1";
|
|
13284
|
+
var SealingError = class extends Error {
|
|
13285
|
+
name = "SealingError";
|
|
13286
|
+
};
|
|
13287
|
+
async function seal(key2, secret2, roots = ROOT_PUBLIC_KEYS) {
|
|
13288
|
+
await verifySealingKey(key2, roots);
|
|
13289
|
+
const ephemeral = await subtle().generateKey({ name: "X25519" }, true, ["deriveBits"]);
|
|
13290
|
+
return sealWith(key2, secret2, ephemeral);
|
|
13291
|
+
}
|
|
13292
|
+
async function verifySealingKey(key2, roots = ROOT_PUBLIC_KEYS) {
|
|
13293
|
+
if (key2.suite !== SEALED_SUITE) throw new SealingError(`sealing key ${key2.kid} is for suite ${key2.suite}, not ${SEALED_SUITE}`);
|
|
13294
|
+
if ([key2.kid, key2.owner, key2.publicKey, key2.signature].some((field) => !field || /[\n\u0000]/.test(field))) {
|
|
13295
|
+
throw new SealingError(`sealing key ${key2.kid} has an empty field or one holding a newline`);
|
|
13296
|
+
}
|
|
13297
|
+
const publicKey2 = fromBase64url(key2.publicKey);
|
|
13298
|
+
if (publicKey2.length !== 32) throw new SealingError(`sealing key ${key2.kid} is not a 32-byte X25519 key`);
|
|
13299
|
+
if (key2.kid !== await sealingKeyId(publicKey2)) throw new SealingError(`sealing key ${key2.kid} does not have the id its public key gives`);
|
|
13300
|
+
if (roots.length === 0) throw new SealingError("no root key is known yet, so no sealing key can be trusted");
|
|
13301
|
+
const message = utf8(sealingKeyMessage(key2));
|
|
13302
|
+
const signature = fromBase64url(key2.signature);
|
|
13303
|
+
for (const root of roots) {
|
|
13304
|
+
let rootKey;
|
|
13305
|
+
try {
|
|
13306
|
+
rootKey = await subtle().importKey("raw", fromBase64url(root), { name: "Ed25519" }, false, ["verify"]);
|
|
13307
|
+
} catch {
|
|
13308
|
+
continue;
|
|
13309
|
+
}
|
|
13310
|
+
if (await subtle().verify({ name: "Ed25519" }, rootKey, signature, message)) return;
|
|
13311
|
+
}
|
|
13312
|
+
throw new SealingError(`sealing key ${key2.kid} is not signed by agental's root key`);
|
|
13313
|
+
}
|
|
13314
|
+
function sealingKeyMessage(key2) {
|
|
13315
|
+
return [KEY_MESSAGE_LABEL, key2.kid, key2.suite, key2.owner, key2.publicKey].join("\n");
|
|
13316
|
+
}
|
|
13317
|
+
async function sealingKeyId(publicKey2) {
|
|
13318
|
+
const digest = new Uint8Array(await subtle().digest("SHA-256", publicKey2));
|
|
13319
|
+
return `sk_${[...digest.subarray(0, 12)].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
13320
|
+
}
|
|
13321
|
+
function sealedAad(org2, name) {
|
|
13322
|
+
return utf8(`${AAD_LABEL}\0${org2}\0${name}`);
|
|
13323
|
+
}
|
|
13324
|
+
async function sealWith(key2, secret2, ephemeral) {
|
|
13325
|
+
checkSecret(key2, secret2);
|
|
13326
|
+
const recipient = await subtle().importKey("raw", fromBase64url(key2.publicKey), { name: "X25519" }, false, []);
|
|
13327
|
+
const dh = new Uint8Array(await subtle().deriveBits({ name: "X25519", public: recipient }, ephemeral.privateKey, 256));
|
|
13328
|
+
const enc = new Uint8Array(await subtle().exportKey("raw", ephemeral.publicKey));
|
|
13329
|
+
const sharedSecret = await kemSharedSecret(dh, enc, fromBase64url(key2.publicKey));
|
|
13330
|
+
const { aeadKey, baseNonce } = await keySchedule(sharedSecret, utf8(INFO));
|
|
13331
|
+
const plaintext = utf8(
|
|
13332
|
+
JSON.stringify({ value: secret2.value, hosts: secret2.hosts, org: secret2.org, name: secret2.name, sealedAt: secret2.sealedAt ?? (/* @__PURE__ */ new Date()).toISOString() })
|
|
13333
|
+
);
|
|
13334
|
+
const aes = await subtle().importKey("raw", aeadKey, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
13335
|
+
const ct = new Uint8Array(
|
|
13336
|
+
await subtle().encrypt({ name: "AES-GCM", iv: baseNonce, additionalData: sealedAad(secret2.org, secret2.name) }, aes, plaintext)
|
|
13337
|
+
);
|
|
13338
|
+
return { v: 1, kid: key2.kid, suite: SEALED_SUITE, enc: toBase64url(enc), ct: toBase64url(ct) };
|
|
13339
|
+
}
|
|
13340
|
+
function checkSecret(key2, secret2) {
|
|
13341
|
+
if (key2.owner !== "agental" && key2.owner !== secret2.org) {
|
|
13342
|
+
throw new SealingError(`sealing key ${key2.kid} holds ${key2.owner}'s secrets, not ${secret2.org}'s`);
|
|
13343
|
+
}
|
|
13344
|
+
if (!secret2.org || !secret2.name) throw new SealingError("a secret needs its organization and its name");
|
|
13345
|
+
if (secret2.org.includes("\0") || secret2.name.includes("\0")) throw new SealingError("an organization or a name cannot hold a NUL");
|
|
13346
|
+
if (!Array.isArray(secret2.hosts) || secret2.hosts.length === 0) throw new SealingError("a secret needs at least one host it may be sent to");
|
|
13347
|
+
if (secret2.hosts.some((host) => typeof host !== "string" || host === "")) throw new SealingError("a host cannot be empty");
|
|
13348
|
+
if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(secret2.value)) {
|
|
13349
|
+
throw new SealingError("the value holds a broken character (a lone surrogate)");
|
|
13350
|
+
}
|
|
13351
|
+
}
|
|
13352
|
+
async function kemSharedSecret(dh, enc, recipientPublic) {
|
|
13353
|
+
const kemSuite = concat(utf8("KEM"), i2osp(KEM_ID, 2));
|
|
13354
|
+
const eaePrk = await labeledExtract(kemSuite, new Uint8Array(), "eae_prk", dh);
|
|
13355
|
+
return labeledExpand(kemSuite, eaePrk, "shared_secret", concat(enc, recipientPublic), 32);
|
|
13356
|
+
}
|
|
13357
|
+
async function keySchedule(sharedSecret, info) {
|
|
13358
|
+
const suite = concat(utf8("HPKE"), i2osp(KEM_ID, 2), i2osp(KDF_ID, 2), i2osp(AEAD_ID, 2));
|
|
13359
|
+
const pskIdHash = await labeledExtract(suite, new Uint8Array(), "psk_id_hash", new Uint8Array());
|
|
13360
|
+
const infoHash = await labeledExtract(suite, new Uint8Array(), "info_hash", info);
|
|
13361
|
+
const context = concat(new Uint8Array([0]), pskIdHash, infoHash);
|
|
13362
|
+
const secret2 = await labeledExtract(suite, sharedSecret, "secret", new Uint8Array());
|
|
13363
|
+
return {
|
|
13364
|
+
aeadKey: await labeledExpand(suite, secret2, "key", context, 32),
|
|
13365
|
+
baseNonce: await labeledExpand(suite, secret2, "base_nonce", context, 12)
|
|
13366
|
+
};
|
|
13367
|
+
}
|
|
13368
|
+
function labeledExtract(suite, salt, label, ikm) {
|
|
13369
|
+
return hkdfExtract(salt, concat(utf8("HPKE-v1"), suite, utf8(label), ikm));
|
|
13370
|
+
}
|
|
13371
|
+
function labeledExpand(suite, prk, label, info, length) {
|
|
13372
|
+
return hkdfExpand(prk, concat(i2osp(length, 2), utf8("HPKE-v1"), suite, utf8(label), info), length);
|
|
13373
|
+
}
|
|
13374
|
+
async function hkdfExtract(salt, ikm) {
|
|
13375
|
+
return hmac(salt.length > 0 ? salt : new Uint8Array(32), ikm);
|
|
13376
|
+
}
|
|
13377
|
+
async function hkdfExpand(prk, info, length) {
|
|
13378
|
+
const out = new Uint8Array(length);
|
|
13379
|
+
let block = new Uint8Array();
|
|
13380
|
+
for (let counter = 1, filled = 0; filled < length; counter++) {
|
|
13381
|
+
block = await hmac(prk, concat(block, info, new Uint8Array([counter])));
|
|
13382
|
+
out.set(block.subarray(0, Math.min(block.length, length - filled)), filled);
|
|
13383
|
+
filled += block.length;
|
|
13384
|
+
}
|
|
13385
|
+
return out;
|
|
13386
|
+
}
|
|
13387
|
+
async function hmac(key2, data) {
|
|
13388
|
+
const hmacKey = await subtle().importKey("raw", key2, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
13389
|
+
return new Uint8Array(await subtle().sign("HMAC", hmacKey, data));
|
|
13390
|
+
}
|
|
13391
|
+
function subtle() {
|
|
13392
|
+
const webCrypto = globalThis.crypto?.subtle;
|
|
13393
|
+
if (!webCrypto) throw new SealingError("this runtime has no WebCrypto, so it cannot seal");
|
|
13394
|
+
return webCrypto;
|
|
13395
|
+
}
|
|
13396
|
+
function i2osp(value, length) {
|
|
13397
|
+
const out = new Uint8Array(length);
|
|
13398
|
+
for (let i = length - 1, v = value; i >= 0; i--, v >>>= 8) out[i] = v & 255;
|
|
13399
|
+
return out;
|
|
13400
|
+
}
|
|
13401
|
+
function concat(...parts) {
|
|
13402
|
+
const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
13403
|
+
let offset = 0;
|
|
13404
|
+
for (const part of parts) {
|
|
13405
|
+
out.set(part, offset);
|
|
13406
|
+
offset += part.length;
|
|
13407
|
+
}
|
|
13408
|
+
return out;
|
|
13409
|
+
}
|
|
13410
|
+
function utf8(text) {
|
|
13411
|
+
return new Uint8Array(new TextEncoder().encode(text));
|
|
13412
|
+
}
|
|
13413
|
+
function toBase64url(bytes4) {
|
|
13414
|
+
let binary = "";
|
|
13415
|
+
for (const byte of bytes4) binary += String.fromCharCode(byte);
|
|
13416
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
13417
|
+
}
|
|
13418
|
+
function fromBase64url(text) {
|
|
13419
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text) || text.length % 4 === 1) throw new SealingError("not base64url");
|
|
13420
|
+
const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - text.length % 4) % 4));
|
|
13421
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
13422
|
+
}
|
|
13423
|
+
|
|
13424
|
+
// ../src/cli-secret.ts
|
|
13425
|
+
var ROOT_KEYS = ["jNdFf3FKdbFQ5J-1e_NE7ZzuaNPRdci-mzlGj384Rmw"];
|
|
13426
|
+
var USAGE8 = "secret takes list, get, set, seal, delete, use or unuse. agental secret --help shows each.";
|
|
13427
|
+
var NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
13428
|
+
var HOST = /^(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
13429
|
+
var SHORTEST_VALUE = 8;
|
|
13430
|
+
var MOST_HOSTS = 10;
|
|
13431
|
+
async function secret(client, positionals, options) {
|
|
13432
|
+
const [verb, ...args] = positionals;
|
|
13433
|
+
switch (verb) {
|
|
13434
|
+
case void 0:
|
|
13435
|
+
case "list":
|
|
13436
|
+
return list3(client, options);
|
|
13437
|
+
case "get":
|
|
13438
|
+
return get(client, nameOf2(args[0], "get"), options);
|
|
13439
|
+
case "set":
|
|
13440
|
+
return set(client, args[0], options);
|
|
13441
|
+
case "seal":
|
|
13442
|
+
return printSealed(client, args[0], options);
|
|
13443
|
+
case "delete":
|
|
13444
|
+
return remove2(client, nameOf2(args[0], "delete"), options);
|
|
13445
|
+
case "use":
|
|
13446
|
+
case "unuse":
|
|
13447
|
+
return use(client, verb === "use", nameOf2(args[0], verb), options);
|
|
13448
|
+
default:
|
|
13449
|
+
throw new Error(`agental secret ${verb} is not a command. ${USAGE8}`);
|
|
13450
|
+
}
|
|
13451
|
+
}
|
|
13452
|
+
async function list3(client, options) {
|
|
13453
|
+
const { secrets: secrets2 } = await answer2(client, "/v1/secrets", { method: "GET" });
|
|
13454
|
+
if (options.json) {
|
|
13455
|
+
process.stdout.write(`${JSON.stringify({ secrets: secrets2 }, null, 2)}
|
|
13456
|
+
`);
|
|
13457
|
+
return;
|
|
13458
|
+
}
|
|
13459
|
+
if (secrets2.length === 0) {
|
|
13460
|
+
process.stdout.write("No secrets. agental secret set <NAME> --host <host> keeps one.\n");
|
|
13461
|
+
return;
|
|
13462
|
+
}
|
|
13463
|
+
for (const s of secrets2) {
|
|
13464
|
+
process.stdout.write(`${s.name} ${s.hosts.join(",")} ${usedWords(s)}
|
|
13465
|
+
`);
|
|
13466
|
+
}
|
|
13467
|
+
}
|
|
13468
|
+
async function get(client, name, options) {
|
|
13469
|
+
const view = await answer2(client, `/v1/secrets/${encodeURIComponent(name)}`, { method: "GET" });
|
|
13470
|
+
if (options.json) {
|
|
13471
|
+
process.stdout.write(`${JSON.stringify(view, null, 2)}
|
|
13472
|
+
`);
|
|
13473
|
+
return;
|
|
13474
|
+
}
|
|
13475
|
+
process.stdout.write(
|
|
13476
|
+
`${view.name}
|
|
13477
|
+
goes to ${view.hosts.join(", ")}
|
|
13478
|
+
sealed to ${view.sealedTo.join(", ")}
|
|
13479
|
+
used by ${usedWords(view)}
|
|
13480
|
+
changed ${view.updatedAt}
|
|
13481
|
+
Its value is sealed, and nothing shows it: not the API, the console or this command.
|
|
13482
|
+
`
|
|
13483
|
+
);
|
|
13484
|
+
}
|
|
13485
|
+
async function set(client, given, options) {
|
|
13486
|
+
const { name, value, hosts } = await toSeal(client, given, options, "set");
|
|
13487
|
+
const { sealed, org: org2 } = await sealFor(client, name, value, hosts);
|
|
13488
|
+
const made = await client.request("/v1/secrets", { method: "POST", headers: JSON_HEADERS, body: JSON.stringify({ name, hosts, sealed }) });
|
|
13489
|
+
let view;
|
|
13490
|
+
if (made.ok) {
|
|
13491
|
+
view = await made.json();
|
|
13492
|
+
} else {
|
|
13493
|
+
const body = await made.json().catch(() => null);
|
|
13494
|
+
if (made.status !== 409 || codeOf(body) !== "secret_exists") {
|
|
13495
|
+
refused(client, made.status, body);
|
|
13496
|
+
}
|
|
13497
|
+
view = await answer2(client, `/v1/secrets/${encodeURIComponent(name)}`, { method: "PUT", headers: JSON_HEADERS, body: JSON.stringify({ hosts, sealed }) });
|
|
13498
|
+
}
|
|
13499
|
+
if (options.json) {
|
|
13500
|
+
process.stdout.write(`${JSON.stringify(view, null, 2)}
|
|
13501
|
+
`);
|
|
13502
|
+
return;
|
|
13503
|
+
}
|
|
13504
|
+
process.stdout.write(
|
|
13505
|
+
`Kept ${view.name} for the organization ${org2}, sealed here before it was sent; it goes only to ${view.hosts.join(", ")}. ${usedWords(view) === "nothing" ? `agental secret use ${view.name} --template <template> gives it to a template's sandboxes.` : `Used by ${usedWords(view)}.`}
|
|
13506
|
+
`
|
|
13507
|
+
);
|
|
13508
|
+
}
|
|
13509
|
+
async function printSealed(client, given, options) {
|
|
13510
|
+
const { name, value, hosts } = await toSeal(client, given, options, "seal");
|
|
13511
|
+
const { sealed, org: org2 } = await sealFor(client, name, value, hosts);
|
|
13512
|
+
process.stderr.write(`Sealed ${name} for the organization ${org2}.
|
|
13513
|
+
`);
|
|
13514
|
+
process.stdout.write(`${JSON.stringify(options.json ? { name, hosts, sealed } : sealed)}
|
|
13515
|
+
`);
|
|
13516
|
+
}
|
|
13517
|
+
async function remove2(client, name, options) {
|
|
13518
|
+
if (!options.yes && !await client.confirmed(`Delete the secret ${name}, and take it from every template and sandbox that uses it?`)) {
|
|
13519
|
+
throw new Error("Nothing was deleted. Give --yes to delete without asking.");
|
|
13520
|
+
}
|
|
13521
|
+
const { usedBy } = await answer2(client, `/v1/secrets/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
13522
|
+
if (options.json) {
|
|
13523
|
+
process.stdout.write(`${JSON.stringify({ deleted: name, usedBy }, null, 2)}
|
|
13524
|
+
`);
|
|
13525
|
+
return;
|
|
13526
|
+
}
|
|
13527
|
+
const from = usedBy.templates.length + usedBy.sandboxes.length;
|
|
13528
|
+
process.stdout.write(`Deleted ${name}${from > 0 ? `, and took it from ${usedWords({ usedBy })}` : ""}.
|
|
13529
|
+
`);
|
|
13530
|
+
}
|
|
13531
|
+
async function use(client, on, name, options) {
|
|
13532
|
+
if (options.template === void 0 === (options.sandbox === void 0)) {
|
|
13533
|
+
throw new Error(`secret ${on ? "use" : "unuse"} takes --template <template> or --sandbox <sandbox-id>, one of them.`);
|
|
13534
|
+
}
|
|
13535
|
+
const where = options.template !== void 0 ? { path: `/v1/templates/${encodeURIComponent(await client.templateId(options.template))}`, words: `the template ${options.template}` } : { path: `/v1/sandboxes/${encodeURIComponent(options.sandbox ?? "")}`, words: `the sandbox ${options.sandbox}` };
|
|
13536
|
+
const path6 = `${where.path}/secrets/${encodeURIComponent(name)}`;
|
|
13537
|
+
if (on) {
|
|
13538
|
+
const view = await answer2(client, path6, { method: "PUT" });
|
|
13539
|
+
process.stdout.write(options.json ? `${JSON.stringify(view, null, 2)}
|
|
13540
|
+
` : `${where.words} uses ${name}: its commands see the variable, and its value goes only to ${view.hosts.join(", ")}.
|
|
13541
|
+
`);
|
|
13542
|
+
return;
|
|
13543
|
+
}
|
|
13544
|
+
const res = await client.request(path6, { method: "DELETE" });
|
|
13545
|
+
if (!res.ok) {
|
|
13546
|
+
refused(client, res.status, await res.json().catch(() => null));
|
|
13547
|
+
}
|
|
13548
|
+
process.stdout.write(options.json ? `${JSON.stringify({ unused: name }, null, 2)}
|
|
13549
|
+
` : `${where.words} no longer uses ${name}.
|
|
13550
|
+
`);
|
|
13551
|
+
}
|
|
13552
|
+
async function toSeal(client, given, options, verb) {
|
|
13553
|
+
if (!given) {
|
|
13554
|
+
throw new Error(`secret ${verb} requires <NAME>, and --host: agental secret ${verb} GITHUB_TOKEN --host api.github.com`);
|
|
13555
|
+
}
|
|
13556
|
+
const at4 = given.indexOf("=");
|
|
13557
|
+
const name = nameOf2(at4 < 0 ? given : given.slice(0, at4), verb);
|
|
13558
|
+
const hosts = hostsOf(options.host, verb);
|
|
13559
|
+
const value = at4 < 0 ? await client.readValue(`${name}'s value (not shown): `) : given.slice(at4 + 1);
|
|
13560
|
+
if (value.length < SHORTEST_VALUE) {
|
|
13561
|
+
throw new Error(`${name}'s value is ${value.length} characters: a secret is at least ${SHORTEST_VALUE}, and the API cannot check a sealed one, so it is refused here.`);
|
|
13562
|
+
}
|
|
13563
|
+
return { name, value, hosts };
|
|
13564
|
+
}
|
|
13565
|
+
async function sealFor(client, name, value, hosts) {
|
|
13566
|
+
const { keys } = await answer2(client, "/v1/secrets/key", { method: "GET" });
|
|
13567
|
+
const org2 = String((await answer2(client, "/v1/me", { method: "GET" })).activeOrganizationId ?? "");
|
|
13568
|
+
if (!org2) {
|
|
13569
|
+
throw new Error("The API did not say which organization this key acts in, so nothing could be sealed for it.");
|
|
13570
|
+
}
|
|
13571
|
+
const mine = keys.filter((key2) => key2.owner === "agental");
|
|
13572
|
+
if (mine.length === 0) {
|
|
13573
|
+
throw new Error("The API publishes no key of agental's boxes, so nothing was sealed or sent.");
|
|
13574
|
+
}
|
|
13575
|
+
for (const key2 of mine) {
|
|
13576
|
+
await verifySealingKey(key2, client.roots ?? ROOT_KEYS);
|
|
13577
|
+
}
|
|
13578
|
+
const sealed = await Promise.all(mine.map((key2) => seal(key2, { value, hosts, org: org2, name }, client.roots ?? ROOT_KEYS)));
|
|
13579
|
+
return { sealed, org: org2 };
|
|
13580
|
+
}
|
|
13581
|
+
function nameOf2(given, verb) {
|
|
13582
|
+
if (!given) {
|
|
13583
|
+
throw new Error(`secret ${verb} requires <NAME>`);
|
|
13584
|
+
}
|
|
13585
|
+
if (!NAME.test(given)) {
|
|
13586
|
+
throw new Error(`${given} is not a secret's name: letters, digits and _, not starting with a digit, up to 128.`);
|
|
13587
|
+
}
|
|
13588
|
+
return given;
|
|
13589
|
+
}
|
|
13590
|
+
function hostsOf(given, verb) {
|
|
13591
|
+
const hosts = (given ?? []).flatMap((h) => h.split(",")).map((h) => h.trim().toLowerCase()).filter((h) => h.length > 0);
|
|
13592
|
+
if (hosts.length === 0) {
|
|
13593
|
+
throw new Error(`secret ${verb} requires --host: the hosts its value may go to, as --host api.github.com`);
|
|
13594
|
+
}
|
|
13595
|
+
if (hosts.length > MOST_HOSTS) {
|
|
13596
|
+
throw new Error(`A secret goes to at most ${MOST_HOSTS} hosts, not ${hosts.length}.`);
|
|
13597
|
+
}
|
|
13598
|
+
for (const h of hosts) {
|
|
13599
|
+
if (!HOST.test(h)) {
|
|
13600
|
+
throw new Error(`${h} is not a host: a name such as api.github.com, or *.example.com.`);
|
|
13601
|
+
}
|
|
13602
|
+
}
|
|
13603
|
+
return [...new Set(hosts)];
|
|
13604
|
+
}
|
|
13605
|
+
function usedWords(view) {
|
|
13606
|
+
const t = view.usedBy.templates.length;
|
|
13607
|
+
const s = view.usedBy.sandboxes.length;
|
|
13608
|
+
if (t + s === 0) {
|
|
13609
|
+
return "nothing";
|
|
13610
|
+
}
|
|
13611
|
+
return [t > 0 ? `${t} template${t === 1 ? "" : "s"}` : "", s > 0 ? `${s} sandbox${s === 1 ? "" : "es"}` : ""].filter(Boolean).join(" and ");
|
|
13612
|
+
}
|
|
13613
|
+
function codeOf(body) {
|
|
13614
|
+
const error = body?.error;
|
|
13615
|
+
return typeof error?.code === "string" ? error.code : void 0;
|
|
13616
|
+
}
|
|
13617
|
+
var JSON_HEADERS = { "content-type": "application/json" };
|
|
13618
|
+
async function answer2(client, path6, init) {
|
|
13619
|
+
const res = await client.request(path6, init);
|
|
13620
|
+
const body = await res.json().catch(() => null);
|
|
13621
|
+
if (!res.ok) {
|
|
13622
|
+
refused(client, res.status, body);
|
|
13623
|
+
}
|
|
13624
|
+
return body;
|
|
13625
|
+
}
|
|
13626
|
+
function refused(client, status, body) {
|
|
13627
|
+
if (status === 403 && codeOf(body) === "key_reach_limited") {
|
|
13628
|
+
throw new Error(
|
|
13629
|
+
"This API key is held to some sandboxes or templates, and the account's secrets are the whole organization's: it cannot list, keep, change or give them. Use a key that reaches everything, or sign in with agental login."
|
|
13630
|
+
);
|
|
13631
|
+
}
|
|
13632
|
+
client.fail(status, body);
|
|
13633
|
+
}
|
|
13634
|
+
|
|
13263
13635
|
// ../src/cli-sites.ts
|
|
13264
|
-
var
|
|
13636
|
+
var USAGE9 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
|
|
13265
13637
|
var ANALYTICS_USAGE = "site analytics takes on or off, then the sandbox and the site's id, or org, with on or off to change it.";
|
|
13266
13638
|
var REPORT_ROWS = 5;
|
|
13267
13639
|
async function bodyOf2(response) {
|
|
@@ -13408,9 +13780,9 @@ async function organizationSwitch(client, words2, options) {
|
|
|
13408
13780
|
const put2 = (body) => client.request("/v1/site-analytics", { method: "PUT", body: JSON.stringify(body) });
|
|
13409
13781
|
let response = await put2({ enabled: turn === "on" });
|
|
13410
13782
|
let answered = await bodyOf2(response);
|
|
13411
|
-
const
|
|
13412
|
-
if (response.status === 409 &&
|
|
13413
|
-
process.stderr.write(`${
|
|
13783
|
+
const refused2 = answered?.error;
|
|
13784
|
+
if (response.status === 409 && refused2?.code === "notice_required") {
|
|
13785
|
+
process.stderr.write(`${refused2.message ?? ""}
|
|
13414
13786
|
`);
|
|
13415
13787
|
if (!options.informed) {
|
|
13416
13788
|
process.stderr.write("Nothing was changed. If your organization accepts this: agental site analytics org on --informed\n");
|
|
@@ -13450,13 +13822,13 @@ async function site(client, positionals, options) {
|
|
|
13450
13822
|
const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
|
|
13451
13823
|
const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
|
|
13452
13824
|
if (sandbox === void 0) {
|
|
13453
|
-
throw new Error(
|
|
13825
|
+
throw new Error(USAGE9);
|
|
13454
13826
|
}
|
|
13455
13827
|
switch (verb) {
|
|
13456
13828
|
case null:
|
|
13457
13829
|
case "list": {
|
|
13458
13830
|
if (target !== void 0) {
|
|
13459
|
-
throw new Error(
|
|
13831
|
+
throw new Error(USAGE9);
|
|
13460
13832
|
}
|
|
13461
13833
|
const sites = await sitesOf(client, sandbox);
|
|
13462
13834
|
if (options.json) {
|
|
@@ -13476,7 +13848,7 @@ async function site(client, positionals, options) {
|
|
|
13476
13848
|
}
|
|
13477
13849
|
case "add": {
|
|
13478
13850
|
if (rest.length > 0) {
|
|
13479
|
-
throw new Error(
|
|
13851
|
+
throw new Error(USAGE9);
|
|
13480
13852
|
}
|
|
13481
13853
|
const port = portFrom(target);
|
|
13482
13854
|
const made = routeOf(await ask11(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
|
|
@@ -13527,7 +13899,7 @@ async function site(client, positionals, options) {
|
|
|
13527
13899
|
}
|
|
13528
13900
|
|
|
13529
13901
|
// ../src/cli-claude.ts
|
|
13530
|
-
var
|
|
13902
|
+
var USAGE10 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
|
|
13531
13903
|
var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
|
|
13532
13904
|
var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
|
|
13533
13905
|
async function ask12(client, method, pathname, body) {
|
|
@@ -13612,10 +13984,10 @@ async function hidden(question) {
|
|
|
13612
13984
|
const muted = lines;
|
|
13613
13985
|
process.stderr.write(question);
|
|
13614
13986
|
muted._writeToOutput = () => void 0;
|
|
13615
|
-
lines.question("", (
|
|
13987
|
+
lines.question("", (answer4) => {
|
|
13616
13988
|
lines.close();
|
|
13617
13989
|
process.stderr.write("\n");
|
|
13618
|
-
resolve(
|
|
13990
|
+
resolve(answer4.trim());
|
|
13619
13991
|
});
|
|
13620
13992
|
});
|
|
13621
13993
|
}
|
|
@@ -13642,7 +14014,7 @@ async function listClaude(client, asJson) {
|
|
|
13642
14014
|
async function claude(client, positionals, options) {
|
|
13643
14015
|
const [what, target, ...rest] = positionals;
|
|
13644
14016
|
if (rest.length > 0) {
|
|
13645
|
-
throw new Error(
|
|
14017
|
+
throw new Error(USAGE10);
|
|
13646
14018
|
}
|
|
13647
14019
|
switch (what) {
|
|
13648
14020
|
case "connect": {
|
|
@@ -13710,7 +14082,7 @@ async function claude(client, positionals, options) {
|
|
|
13710
14082
|
return;
|
|
13711
14083
|
}
|
|
13712
14084
|
default:
|
|
13713
|
-
throw new Error(
|
|
14085
|
+
throw new Error(USAGE10);
|
|
13714
14086
|
}
|
|
13715
14087
|
}
|
|
13716
14088
|
function needId2(id, what) {
|
|
@@ -13761,7 +14133,7 @@ function whyClosed(code, reason2, error) {
|
|
|
13761
14133
|
return `The terminal was closed (${code})${said ? `: ${said}` : ""}.`;
|
|
13762
14134
|
}
|
|
13763
14135
|
}
|
|
13764
|
-
async function
|
|
14136
|
+
async function answer3(response) {
|
|
13765
14137
|
const body = await response.json().catch(() => null);
|
|
13766
14138
|
if (!response.ok) {
|
|
13767
14139
|
const error = body?.error;
|
|
@@ -13770,7 +14142,7 @@ async function answer2(response) {
|
|
|
13770
14142
|
return body;
|
|
13771
14143
|
}
|
|
13772
14144
|
async function keptShells2(client, id) {
|
|
13773
|
-
const body = await
|
|
14145
|
+
const body = await answer3(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals`, { method: "GET" }));
|
|
13774
14146
|
if (!body || !Array.isArray(body.terminals)) {
|
|
13775
14147
|
throw new Error("The list of kept shells was missing terminals.");
|
|
13776
14148
|
}
|
|
@@ -13824,7 +14196,7 @@ async function listShells(client, id, json3, stdout) {
|
|
|
13824
14196
|
}
|
|
13825
14197
|
async function closeShell(client, id, given, stdout) {
|
|
13826
14198
|
const found = await shellNamed(client, id, given, "--close");
|
|
13827
|
-
await
|
|
14199
|
+
await answer3(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals/${encodeURIComponent(found.id)}`, { method: "DELETE" }));
|
|
13828
14200
|
stdout.write(`Closed ${found.n === null ? "shell" : `shell ${found.n}`} (${found.id}).
|
|
13829
14201
|
`);
|
|
13830
14202
|
}
|
|
@@ -14534,7 +14906,7 @@ async function main() {
|
|
|
14534
14906
|
await create({ ...values, template: once(values.template, "--template") });
|
|
14535
14907
|
return;
|
|
14536
14908
|
case "list":
|
|
14537
|
-
await
|
|
14909
|
+
await list4(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
|
|
14538
14910
|
return;
|
|
14539
14911
|
case "bulk-actions":
|
|
14540
14912
|
await bulkActionsCommand(positionals.slice(1), values.json);
|
|
@@ -14570,7 +14942,7 @@ async function main() {
|
|
|
14570
14942
|
await bulk("delete", whereQuery(values.where, labelsFilter(values)), {}, values.yes === true, values.json, values.confirm);
|
|
14571
14943
|
return;
|
|
14572
14944
|
}
|
|
14573
|
-
await
|
|
14945
|
+
await remove3(positionals[1], values["pause-jobs"] === true);
|
|
14574
14946
|
return;
|
|
14575
14947
|
case "start":
|
|
14576
14948
|
if (values.where !== void 0) {
|
|
@@ -14617,31 +14989,31 @@ async function main() {
|
|
|
14617
14989
|
await files({ request, fail }, positionals.slice(1), { json: values.json, recursive: values.recursive === true });
|
|
14618
14990
|
return;
|
|
14619
14991
|
case "desktop": {
|
|
14620
|
-
const
|
|
14992
|
+
const use2 = DESKTOP_USES.filter((name) => values[name] !== void 0);
|
|
14621
14993
|
const shotOptions = { crop: values.crop, scale: values.scale, quality: values.quality, cursor: values["no-cursor"] === true ? false : void 0 };
|
|
14622
14994
|
const linkOptions = { expires: values.expires, keepStreams: values["keep-streams"] === true };
|
|
14623
14995
|
const treeOptions = { window: values.window, query: values.query, limit: values.limit };
|
|
14624
14996
|
const shaping = Object.values(shotOptions).some((value) => value !== void 0);
|
|
14625
14997
|
const linking = linkOptions.expires !== void 0 || linkOptions.keepStreams;
|
|
14626
14998
|
const narrowing = Object.values(treeOptions).some((value) => value !== void 0);
|
|
14627
|
-
if (
|
|
14999
|
+
if (use2.length === 0 && !shaping && !linking && !narrowing) {
|
|
14628
15000
|
await desktop(positionals[1], values.screen, values.off, values.status);
|
|
14629
|
-
} else if (
|
|
15001
|
+
} else if (use2.length !== 1 || values.screen !== void 0 || values.off || values.status) {
|
|
14630
15002
|
throw new Error(
|
|
14631
|
-
|
|
15003
|
+
use2.length === 0 ? "desktop takes --crop, --scale, --quality and --no-cursor with --screenshot, --window, --query and --limit with --tree, and --expires and --keep-streams with --link" : `desktop does one thing at a time: --${use2[0]} goes with no other of its options`
|
|
14632
15004
|
);
|
|
14633
|
-
} else if (shaping &&
|
|
15005
|
+
} else if (shaping && use2[0] !== "screenshot" || linking && use2[0] !== "link" || narrowing && use2[0] !== "tree") {
|
|
14634
15006
|
throw new Error(shaping ? "--crop, --scale, --quality and --no-cursor go with --screenshot" : linking ? "--expires and --keep-streams go with --link" : "--window, --query and --limit go with --tree");
|
|
14635
|
-
} else if (
|
|
15007
|
+
} else if (use2[0] === "tree") {
|
|
14636
15008
|
await desktopTree(positionals[1], treeOptions, values.json);
|
|
14637
|
-
} else if (
|
|
15009
|
+
} else if (use2[0] === "screenshot") {
|
|
14638
15010
|
await screenshot(positionals[1], values.screenshot, shotOptions);
|
|
14639
|
-
} else if (
|
|
15011
|
+
} else if (use2[0] === "clipboard" || use2[0] === "set-clipboard") {
|
|
14640
15012
|
await clipboard(positionals[1], values["set-clipboard"]);
|
|
14641
|
-
} else if (
|
|
14642
|
-
await desktopLinks(positionals[1],
|
|
15013
|
+
} else if (use2[0] === "link" || use2[0] === "links" || use2[0] === "unlink") {
|
|
15014
|
+
await desktopLinks(positionals[1], use2[0], values[use2[0]], linkOptions);
|
|
14643
15015
|
} else {
|
|
14644
|
-
await useDesktop(positionals[1],
|
|
15016
|
+
await useDesktop(positionals[1], use2[0], String(values[use2[0]]));
|
|
14645
15017
|
}
|
|
14646
15018
|
return;
|
|
14647
15019
|
}
|
|
@@ -14669,6 +15041,13 @@ async function main() {
|
|
|
14669
15041
|
case "secrets":
|
|
14670
15042
|
await secrets(positionals.slice(1), { ...values, template: once(values.template, "--template") });
|
|
14671
15043
|
return;
|
|
15044
|
+
case "secret":
|
|
15045
|
+
await secret(
|
|
15046
|
+
{ request, fail, confirmed, templateId: async (given) => (await templateNamed(given)).id, readValue: hiddenValue },
|
|
15047
|
+
positionals.slice(1),
|
|
15048
|
+
{ json: values.json, ...values.host === void 0 ? {} : { host: values.host }, template: once(values.template, "--template"), sandbox: once(values.sandbox, "--sandbox"), yes: values.yes === true }
|
|
15049
|
+
);
|
|
15050
|
+
return;
|
|
14672
15051
|
case "metrics":
|
|
14673
15052
|
await metrics(positionals[1], values);
|
|
14674
15053
|
return;
|
|
@@ -14868,12 +15247,12 @@ function regionsOption(given) {
|
|
|
14868
15247
|
const named = listedIn([given]);
|
|
14869
15248
|
return named.length === 1 ? { region: named[0] } : { regions: named };
|
|
14870
15249
|
}
|
|
14871
|
-
async function sshKeys(id, keyId,
|
|
15250
|
+
async function sshKeys(id, keyId, remove4, json3) {
|
|
14872
15251
|
if (!id) {
|
|
14873
15252
|
throw new Error("ssh-keys requires <sandbox-id>");
|
|
14874
15253
|
}
|
|
14875
15254
|
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/ssh/keys`;
|
|
14876
|
-
if (
|
|
15255
|
+
if (remove4) {
|
|
14877
15256
|
if (!keyId) {
|
|
14878
15257
|
throw new Error("ssh-keys --remove requires <key-id>, as ssh-keys lists it");
|
|
14879
15258
|
}
|
|
@@ -14950,7 +15329,7 @@ async function regions(asJson) {
|
|
|
14950
15329
|
}
|
|
14951
15330
|
process.stdout.write("* where a sandbox is made when no region is named\n");
|
|
14952
15331
|
}
|
|
14953
|
-
async function
|
|
15332
|
+
async function list4(asJson, filter, sort, limit, wide = false) {
|
|
14954
15333
|
const sandboxes2 = [];
|
|
14955
15334
|
let cursor = null;
|
|
14956
15335
|
do {
|
|
@@ -15076,6 +15455,52 @@ async function typedCount(count) {
|
|
|
15076
15455
|
lines.close();
|
|
15077
15456
|
}
|
|
15078
15457
|
}
|
|
15458
|
+
async function hiddenValue(prompt) {
|
|
15459
|
+
if (!process.stdin.isTTY) {
|
|
15460
|
+
process.stderr.write(`${prompt.replace(/: $/, "")}: read from stdin
|
|
15461
|
+
`);
|
|
15462
|
+
const chunks = [];
|
|
15463
|
+
for await (const chunk of process.stdin) {
|
|
15464
|
+
chunks.push(chunk);
|
|
15465
|
+
}
|
|
15466
|
+
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
15467
|
+
}
|
|
15468
|
+
process.stderr.write(prompt);
|
|
15469
|
+
process.stdin.setEncoding("utf8");
|
|
15470
|
+
process.stdin.setRawMode(true);
|
|
15471
|
+
process.stdin.resume();
|
|
15472
|
+
try {
|
|
15473
|
+
let value = "";
|
|
15474
|
+
for await (const chunk of process.stdin) {
|
|
15475
|
+
const text = chunk;
|
|
15476
|
+
for (let i = 0; i < text.length; i++) {
|
|
15477
|
+
const ch = text[i] ?? "";
|
|
15478
|
+
if (ch === "\r" || ch === "\n") {
|
|
15479
|
+
if (text.slice(i + 1).replace(/^\n/, "").length > 0) {
|
|
15480
|
+
throw new Error("A value of more than one line was pasted: nothing was sealed or sent. Give such a value on stdin: agental secret set NAME --host \u2026 < file");
|
|
15481
|
+
}
|
|
15482
|
+
return value;
|
|
15483
|
+
}
|
|
15484
|
+
if (ch === "") {
|
|
15485
|
+
throw new Error("Nothing was sealed or sent.");
|
|
15486
|
+
}
|
|
15487
|
+
if (ch === "\x7F" || ch === "\b") {
|
|
15488
|
+
value = [...value].slice(0, -1).join("");
|
|
15489
|
+
continue;
|
|
15490
|
+
}
|
|
15491
|
+
if (ch < " " && ch !== " ") {
|
|
15492
|
+
throw new Error("A control or arrow key was typed in the value: nothing was sealed or sent.");
|
|
15493
|
+
}
|
|
15494
|
+
value += ch;
|
|
15495
|
+
}
|
|
15496
|
+
}
|
|
15497
|
+
return value;
|
|
15498
|
+
} finally {
|
|
15499
|
+
process.stdin.setRawMode(false);
|
|
15500
|
+
process.stdin.pause();
|
|
15501
|
+
process.stderr.write("\n");
|
|
15502
|
+
}
|
|
15503
|
+
}
|
|
15079
15504
|
async function confirmed(question) {
|
|
15080
15505
|
if (!process.stdin.isTTY) {
|
|
15081
15506
|
return false;
|
|
@@ -15204,7 +15629,7 @@ async function exec(positionals) {
|
|
|
15204
15629
|
}
|
|
15205
15630
|
process.exitCode = typeof record["exitCode"] === "number" ? record["exitCode"] : 1;
|
|
15206
15631
|
}
|
|
15207
|
-
async function
|
|
15632
|
+
async function remove3(id, pauseJobs) {
|
|
15208
15633
|
if (!id) {
|
|
15209
15634
|
throw new Error("delete requires <sandbox-id>");
|
|
15210
15635
|
}
|
|
@@ -15593,12 +16018,12 @@ async function desktopTree(id, options, json3) {
|
|
|
15593
16018
|
` : `${treeText(body)}
|
|
15594
16019
|
`);
|
|
15595
16020
|
}
|
|
15596
|
-
async function desktopLinks(id,
|
|
16021
|
+
async function desktopLinks(id, use2, given, options) {
|
|
15597
16022
|
if (!id) {
|
|
15598
16023
|
throw new Error("desktop requires <sandbox-id>");
|
|
15599
16024
|
}
|
|
15600
16025
|
const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/links`;
|
|
15601
|
-
if (
|
|
16026
|
+
if (use2 === "unlink") {
|
|
15602
16027
|
const response2 = await request(`${at4}/${encodeURIComponent(String(given))}`, { method: "DELETE" });
|
|
15603
16028
|
if (!response2.ok) {
|
|
15604
16029
|
fail(response2.status, await readBody(response2));
|
|
@@ -15607,7 +16032,7 @@ async function desktopLinks(id, use, given, options) {
|
|
|
15607
16032
|
`);
|
|
15608
16033
|
return;
|
|
15609
16034
|
}
|
|
15610
|
-
if (
|
|
16035
|
+
if (use2 === "links") {
|
|
15611
16036
|
const response2 = await request(at4, { method: "GET" });
|
|
15612
16037
|
const body2 = await readBody(response2);
|
|
15613
16038
|
if (!response2.ok) {
|
|
@@ -15645,38 +16070,38 @@ function numbers(text, least, most, signedFrom = most) {
|
|
|
15645
16070
|
const whole = parts.every((part, index) => (index >= signedFrom ? /^-?\d+$/ : /^\d+$/).test(part));
|
|
15646
16071
|
return whole && parts.length >= least && parts.length <= most ? parts.map(Number) : null;
|
|
15647
16072
|
}
|
|
15648
|
-
async function useDesktop(id,
|
|
16073
|
+
async function useDesktop(id, use2, given) {
|
|
15649
16074
|
if (!id) {
|
|
15650
16075
|
throw new Error("desktop requires <sandbox-id>");
|
|
15651
16076
|
}
|
|
15652
|
-
const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/${
|
|
16077
|
+
const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/${use2}`;
|
|
15653
16078
|
let body;
|
|
15654
|
-
if (
|
|
16079
|
+
if (use2 === "click") {
|
|
15655
16080
|
const [x, y, button, count, ...more] = given.split(",");
|
|
15656
16081
|
const point = numbers(`${x ?? ""},${y ?? ""}`, 2, 2);
|
|
15657
16082
|
if (!point || more.length > 0 || button !== void 0 && !["left", "middle", "right"].includes(button) || count !== void 0 && !/^[123]$/.test(count)) {
|
|
15658
16083
|
throw new Error("--click is where to click, as x,y, with the button and how many times after it when they are not left and once: 640,400 or 640,400,right or 640,400,left,2");
|
|
15659
16084
|
}
|
|
15660
16085
|
body = { x: point[0], y: point[1], ...button ? { button } : {}, ...count ? { count: Number(count) } : {} };
|
|
15661
|
-
} else if (
|
|
16086
|
+
} else if (use2 === "move") {
|
|
15662
16087
|
const point = numbers(given, 2, 2);
|
|
15663
16088
|
if (!point) {
|
|
15664
16089
|
throw new Error("--move is where the pointer goes, as x,y: 640,400");
|
|
15665
16090
|
}
|
|
15666
16091
|
body = { x: point[0], y: point[1] };
|
|
15667
|
-
} else if (
|
|
16092
|
+
} else if (use2 === "drag") {
|
|
15668
16093
|
const points = numbers(given, 4, 4);
|
|
15669
16094
|
if (!points) {
|
|
15670
16095
|
throw new Error("--drag is where the button goes down and where it comes up, as x,y,x,y: 10,20,300,400");
|
|
15671
16096
|
}
|
|
15672
16097
|
body = { from: { x: points[0], y: points[1] }, to: { x: points[2], y: points[3] } };
|
|
15673
|
-
} else if (
|
|
16098
|
+
} else if (use2 === "scroll") {
|
|
15674
16099
|
const turn = numbers(given, 3, 4, 2);
|
|
15675
16100
|
if (!turn) {
|
|
15676
16101
|
throw new Error("--scroll is where the pointer is and how many notches the wheel turns, down or with a minus up, as x,y,notches: 640,400,3. A fourth number turns it to the right, or with a minus to the left.");
|
|
15677
16102
|
}
|
|
15678
16103
|
body = { x: turn[0], y: turn[1], dy: turn[2], ...turn[3] !== void 0 ? { dx: turn[3] } : {} };
|
|
15679
|
-
} else if (
|
|
16104
|
+
} else if (use2 === "type") {
|
|
15680
16105
|
body = { text: given };
|
|
15681
16106
|
} else {
|
|
15682
16107
|
body = { keys: given };
|
|
@@ -15864,9 +16289,9 @@ async function egress(positionals, values) {
|
|
|
15864
16289
|
card: "a card saved: agental billing card save",
|
|
15865
16290
|
use_case: 'what your sandboxes will use it for: agental egress use-case "<what for>"'
|
|
15866
16291
|
};
|
|
15867
|
-
const
|
|
16292
|
+
const refused2 = account3["refused"];
|
|
15868
16293
|
const lines = !account3["offered"] ? ["Residential egress is not offered here."] : [
|
|
15869
|
-
`residential: ${account3["enabled"] ? "on for this account" :
|
|
16294
|
+
`residential: ${account3["enabled"] ? "on for this account" : refused2 ? `refused: ${String(refused2.reason ?? "")}` : "not yet"}`,
|
|
15870
16295
|
...missing.map((need) => ` needs ${needs[need] ?? need}`),
|
|
15871
16296
|
`price: ${money(number("microsPerGb"))} a GB, both directions counted`,
|
|
15872
16297
|
`this month: ${money(number("spentMicros"))} of a ${money(number("budgetMicros"))} budget${account3["budgetSet"] ? "" : " (the default)"}`,
|
|
@@ -15998,15 +16423,15 @@ ${faint("The default is used when a sandbox is made without naming one. agental
|
|
|
15998
16423
|
process.stdout.write("* used when a sandbox is made without naming one\n");
|
|
15999
16424
|
}
|
|
16000
16425
|
function showTemplate(each) {
|
|
16001
|
-
const
|
|
16426
|
+
const list5 = (items) => items && items.length > 0 ? items.join(", ") : "none";
|
|
16002
16427
|
return [
|
|
16003
16428
|
`id: ${each.id}`,
|
|
16004
16429
|
`name: ${each.name}${each.default ? " (default: used when a sandbox is made without naming one)" : ""}`,
|
|
16005
16430
|
`start: ${startInWords(each.start)}`,
|
|
16006
|
-
`variables: ${
|
|
16431
|
+
`variables: ${list5(each.variables)}`,
|
|
16007
16432
|
// Said only where some are. An API from before variables could be kept out of the sandbox says nothing of them.
|
|
16008
|
-
...each.hidden && each.hidden.length > 0 ? [`kept out: ${
|
|
16009
|
-
`files: ${
|
|
16433
|
+
...each.hidden && each.hidden.length > 0 ? [`kept out: ${list5(each.hidden)}`] : [],
|
|
16434
|
+
`files: ${list5(each.files)}`,
|
|
16010
16435
|
// An API from before templates held rules says nothing of one.
|
|
16011
16436
|
...each.network ? [`network: ${ruleInWords(each.network)}`] : [],
|
|
16012
16437
|
// An API from before templates gave SSH says nothing of it.
|
|
@@ -16143,8 +16568,8 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
|
|
|
16143
16568
|
const found = await templateNamed(need(first, "<template>"));
|
|
16144
16569
|
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/egress`;
|
|
16145
16570
|
const how = `template egress takes <template>, and then nothing, box, or residential <country> [sticky|rotating], as agental template egress ${first ?? ""} residential de.`;
|
|
16146
|
-
const
|
|
16147
|
-
print4(
|
|
16571
|
+
const set2 = await call2(path6, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
|
|
16572
|
+
print4(set2, `${found.name}: ${egressInWords(set2)}${rest.length === 0 ? "" : ", for sandboxes made from it from now on"}
|
|
16148
16573
|
`);
|
|
16149
16574
|
return;
|
|
16150
16575
|
}
|
|
@@ -16426,8 +16851,8 @@ async function metrics(id, asked2) {
|
|
|
16426
16851
|
if (!response.ok) {
|
|
16427
16852
|
fail(response.status, body);
|
|
16428
16853
|
}
|
|
16429
|
-
const
|
|
16430
|
-
const fromTo = typeof
|
|
16854
|
+
const answer4 = body && typeof body === "object" ? body : {};
|
|
16855
|
+
const fromTo = typeof answer4["since"] === "string" && typeof answer4["until"] === "string" ? ` from ${answer4["since"]} to ${answer4["until"]}` : "";
|
|
16431
16856
|
if (asked2.json) {
|
|
16432
16857
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
16433
16858
|
`);
|
|
@@ -16452,7 +16877,7 @@ async function metrics(id, asked2) {
|
|
|
16452
16877
|
])
|
|
16453
16878
|
);
|
|
16454
16879
|
}
|
|
16455
|
-
if (
|
|
16880
|
+
if (answer4["complete"] === false) {
|
|
16456
16881
|
process.stderr.write(
|
|
16457
16882
|
id === void 0 ? "A server did not answer, so a sandbox on it has no reading here though it may have been running. Ask again in a minute.\n" : `A server did not answer, so readings may be missing: those from any time ${id} was on that server. Ask again in a minute.
|
|
16458
16883
|
`
|
|
@@ -16495,8 +16920,8 @@ async function dataRetention(positionals, asJson) {
|
|
|
16495
16920
|
`);
|
|
16496
16921
|
return;
|
|
16497
16922
|
}
|
|
16498
|
-
const
|
|
16499
|
-
const days =
|
|
16923
|
+
const answer4 = body ?? {};
|
|
16924
|
+
const days = answer4.keepDays ?? null;
|
|
16500
16925
|
const kept2 = days === null ? "until their sandbox is deleted" : days === 1 ? "1 day" : `${days} days`;
|
|
16501
16926
|
process.stdout.write(`${period === void 0 ? "" : "Saved. "}Command output, agent conversations and events are kept ${kept2}.
|
|
16502
16927
|
`);
|
|
@@ -16504,7 +16929,7 @@ async function dataRetention(positionals, asJson) {
|
|
|
16504
16929
|
process.stdout.write(`What is older is deleted within the hour, and cannot be brought back.
|
|
16505
16930
|
`);
|
|
16506
16931
|
}
|
|
16507
|
-
const last =
|
|
16932
|
+
const last = answer4.lastCleared;
|
|
16508
16933
|
if (period === void 0) {
|
|
16509
16934
|
process.stdout.write(
|
|
16510
16935
|
last ? `Last clean-up ${last.at}: ${last.commands} commands' output, ${last.conversations} conversations and ${last.events} events deleted.
|
|
@@ -16650,8 +17075,8 @@ async function telemetry(positionals, given, asJson) {
|
|
|
16650
17075
|
`);
|
|
16651
17076
|
return;
|
|
16652
17077
|
}
|
|
16653
|
-
const
|
|
16654
|
-
process.stdout.write(
|
|
17078
|
+
const set2 = settingsIn(body);
|
|
17079
|
+
process.stdout.write(set2 === null ? "No collector is set. agental telemetry set <endpoint> sets one.\n" : describeSettings(set2));
|
|
16655
17080
|
return;
|
|
16656
17081
|
}
|
|
16657
17082
|
case "set": {
|
|
@@ -16672,8 +17097,8 @@ async function telemetry(positionals, given, asJson) {
|
|
|
16672
17097
|
process.stdout.write(`${JSON.stringify({ ...saved, test: tested }, null, 2)}
|
|
16673
17098
|
`);
|
|
16674
17099
|
} else {
|
|
16675
|
-
const
|
|
16676
|
-
process.stdout.write(
|
|
17100
|
+
const set2 = settingsIn(saved);
|
|
17101
|
+
process.stdout.write(set2 === null ? "" : describeSettings(set2));
|
|
16677
17102
|
}
|
|
16678
17103
|
sayTest(tested, "Saved. ");
|
|
16679
17104
|
return;
|
|
@@ -17187,10 +17612,10 @@ async function showLimits(positionals, options) {
|
|
|
17187
17612
|
`);
|
|
17188
17613
|
return;
|
|
17189
17614
|
}
|
|
17190
|
-
const
|
|
17191
|
-
const spent = typeof
|
|
17192
|
-
const budget = typeof
|
|
17193
|
-
process.stdout.write(`Budget for burst fees: ${money(budget)} a month${
|
|
17615
|
+
const answer4 = body2 && typeof body2 === "object" ? body2 : {};
|
|
17616
|
+
const spent = typeof answer4["spentMicros"] === "number" ? answer4["spentMicros"] : 0;
|
|
17617
|
+
const budget = typeof answer4["budgetMicros"] === "number" ? answer4["budgetMicros"] : 0;
|
|
17618
|
+
process.stdout.write(`Budget for burst fees: ${money(budget)} a month${answer4["budgetSet"] === true ? "" : " (the default)"}; ${money(spent)} spent this month.
|
|
17194
17619
|
`);
|
|
17195
17620
|
return;
|
|
17196
17621
|
}
|
|
@@ -17220,8 +17645,8 @@ async function showLimits(positionals, options) {
|
|
|
17220
17645
|
process.stdout.write(describeLimits(body, options.from === void 0 && options.to === void 0, options.to === void 0));
|
|
17221
17646
|
}
|
|
17222
17647
|
function describeLimits(body, today, endsNow) {
|
|
17223
|
-
const
|
|
17224
|
-
const now =
|
|
17648
|
+
const answer4 = body && typeof body === "object" ? body : {};
|
|
17649
|
+
const now = answer4["now"] && typeof answer4["now"] === "object" ? answer4["now"] : {};
|
|
17225
17650
|
const number = (from, name) => typeof from[name] === "number" ? from[name] : 0;
|
|
17226
17651
|
const units = (mb) => {
|
|
17227
17652
|
const value = mb / 2048;
|
|
@@ -17231,11 +17656,11 @@ function describeLimits(body, today, endsNow) {
|
|
|
17231
17656
|
const at4 = new Date(iso).toISOString();
|
|
17232
17657
|
return at4.slice(0, 10) === (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) ? `${at4.slice(11, 16)} UTC` : `${at4.slice(0, 10)} ${at4.slice(11, 16)} UTC`;
|
|
17233
17658
|
};
|
|
17234
|
-
const range = today ? "today (UTC)" : `from ${String(
|
|
17659
|
+
const range = today ? "today (UTC)" : `from ${String(answer4["from"] ?? "")} to ${String(answer4["to"] ?? "")}`;
|
|
17235
17660
|
const lines = [
|
|
17236
|
-
`running: ${units(number(now, "runningMb"))} of ${number(now, "runningUnits").toLocaleString("en-US")} units (a tiny is 1, a small 2, a medium 4, a large 8); at the running count ${duration(number(
|
|
17661
|
+
`running: ${units(number(now, "runningMb"))} of ${number(now, "runningUnits").toLocaleString("en-US")} units (a tiny is 1, a small 2, a medium 4, a large 8); at the running count ${duration(number(answer4, "atRunningCountMs"))} ${range}`
|
|
17237
17662
|
];
|
|
17238
|
-
const bursts = Array.isArray(
|
|
17663
|
+
const bursts = Array.isArray(answer4["bursts"]) ? answer4["bursts"] : [];
|
|
17239
17664
|
const open = endsNow ? bursts.find((one) => one["endedAt"] === null && typeof one["startedAt"] === "string") : void 0;
|
|
17240
17665
|
const over = number(now, "overMb") > 0;
|
|
17241
17666
|
const nextStart = Array.isArray(now["nextStart"]) ? now["nextStart"] : [];
|
|
@@ -17251,9 +17676,9 @@ function describeLimits(body, today, endsNow) {
|
|
|
17251
17676
|
const budgetMonth = now["budgetMonth"] && typeof now["budgetMonth"] === "object" ? now["budgetMonth"] : null;
|
|
17252
17677
|
const since = typeof budgetMonth?.start === "string" && budgetMonth.start.slice(8, 10) !== "01" ? ` (since ${shortDayOf(budgetMonth.start)})` : "";
|
|
17253
17678
|
lines.push(`fees: ${money(number(now, "spentMicros"))} this month${since} of a ${money(number(now, "budgetMicros"))} budget`);
|
|
17254
|
-
const
|
|
17255
|
-
const total = number(
|
|
17256
|
-
const byReason = Array.isArray(
|
|
17679
|
+
const refused2 = answer4["refused"] && typeof answer4["refused"] === "object" ? answer4["refused"] : {};
|
|
17680
|
+
const total = number(refused2, "total");
|
|
17681
|
+
const byReason = Array.isArray(refused2["byReason"]) ? refused2["byReason"] : [];
|
|
17257
17682
|
lines.push(
|
|
17258
17683
|
`did not start: ${total.toLocaleString("en-US")} ${range}${byReason.length > 0 ? `: ${byReason.map((one) => `${one.count.toLocaleString("en-US")} ${REASON_WORDS[one.reason] ?? one.reason} (${one.code})`).join(", ")}` : ""}`
|
|
17259
17684
|
);
|
|
@@ -17280,22 +17705,22 @@ async function asked(path6, init) {
|
|
|
17280
17705
|
return body;
|
|
17281
17706
|
}
|
|
17282
17707
|
function settingsIn(body) {
|
|
17283
|
-
const
|
|
17284
|
-
if (
|
|
17708
|
+
const set2 = body && typeof body === "object" ? body["telemetry"] : void 0;
|
|
17709
|
+
if (set2 === null) {
|
|
17285
17710
|
return null;
|
|
17286
17711
|
}
|
|
17287
|
-
if (!
|
|
17712
|
+
if (!set2 || typeof set2 !== "object") {
|
|
17288
17713
|
throw new Error("Telemetry response was missing telemetry");
|
|
17289
17714
|
}
|
|
17290
|
-
return
|
|
17715
|
+
return set2;
|
|
17291
17716
|
}
|
|
17292
|
-
function describeSettings(
|
|
17293
|
-
const headers = Array.isArray(
|
|
17294
|
-
const error =
|
|
17717
|
+
function describeSettings(set2) {
|
|
17718
|
+
const headers = Array.isArray(set2["headers"]) ? set2["headers"].map(String) : [];
|
|
17719
|
+
const error = set2["lastError"] && typeof set2["lastError"] === "object" ? set2["lastError"] : null;
|
|
17295
17720
|
return [
|
|
17296
|
-
String(
|
|
17721
|
+
String(set2["endpoint"] ?? ""),
|
|
17297
17722
|
` headers ${headers.length === 0 ? NO_FIGURE : headers.join(", ")}`,
|
|
17298
|
-
` last export ${typeof
|
|
17723
|
+
` last export ${typeof set2["lastExportAt"] === "string" ? set2["lastExportAt"] : NO_FIGURE}`,
|
|
17299
17724
|
` last error ${error === null ? NO_FIGURE : `${String(error["message"] ?? "")}, at ${String(error["at"] ?? "")}`}`,
|
|
17300
17725
|
""
|
|
17301
17726
|
].join("\n");
|
|
@@ -17501,11 +17926,11 @@ function readSandboxes(body) {
|
|
|
17501
17926
|
return body.sandboxes.filter((item) => Boolean(item) && typeof item === "object");
|
|
17502
17927
|
}
|
|
17503
17928
|
function readList(body, name) {
|
|
17504
|
-
const
|
|
17505
|
-
if (!Array.isArray(
|
|
17929
|
+
const list5 = body && typeof body === "object" ? body[name] : void 0;
|
|
17930
|
+
if (!Array.isArray(list5)) {
|
|
17506
17931
|
throw new Error(`Metrics response was missing ${name}`);
|
|
17507
17932
|
}
|
|
17508
|
-
return
|
|
17933
|
+
return list5.filter((item) => Boolean(item) && typeof item === "object");
|
|
17509
17934
|
}
|
|
17510
17935
|
function teamOptions(values) {
|
|
17511
17936
|
return { json: values.json, revokeKeys: values["revoke-keys"], ...values.role === void 0 ? {} : { role: values.role } };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agental",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "The agental command: Linux sandboxes for your agents, from the terminal. npx agental@latest signs you in and installs the agent skills.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "VERTIXER LTD",
|