withruntime 1.0.0 → 1.1.1
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/CHANGELOG.md +76 -0
- package/README.md +145 -0
- package/dist/generated/agentSessions.d.ts +218 -0
- package/dist/generated/agentSessions.js +154 -0
- package/dist/generated/agents.d.ts +193 -0
- package/dist/generated/agents.js +166 -0
- package/dist/generated/apps.d.ts +87 -28
- package/dist/generated/apps.js +153 -41
- package/dist/generated/audit.d.ts +2 -2
- package/dist/generated/audit.js +3 -3
- package/dist/generated/browsers.d.ts +87 -28
- package/dist/generated/browsers.js +153 -41
- package/dist/generated/builds.d.ts +87 -28
- package/dist/generated/builds.js +153 -41
- package/dist/generated/ci.d.ts +87 -28
- package/dist/generated/ci.js +153 -41
- package/dist/generated/containers.d.ts +87 -28
- package/dist/generated/containers.js +153 -41
- package/dist/generated/desktops.d.ts +89 -30
- package/dist/generated/desktops.js +155 -43
- package/dist/generated/domains.d.ts +52 -15
- package/dist/generated/domains.js +74 -14
- package/dist/generated/egressIps.d.ts +6 -6
- package/dist/generated/egressIps.js +4 -4
- package/dist/generated/events.d.ts +4 -2
- package/dist/generated/events.js +3 -3
- package/dist/generated/feedback.d.ts +1 -1
- package/dist/generated/feedback.js +3 -3
- package/dist/generated/functions.d.ts +87 -28
- package/dist/generated/functions.js +153 -41
- package/dist/generated/identities.d.ts +2 -2
- package/dist/generated/identities.js +5 -5
- package/dist/generated/images.d.ts +68 -14
- package/dist/generated/images.js +96 -15
- package/dist/generated/index.d.ts +9 -0
- package/dist/generated/index.js +12 -0
- package/dist/generated/jobRuns.d.ts +11 -4
- package/dist/generated/jobRuns.js +6 -6
- package/dist/generated/jobs.d.ts +58 -9
- package/dist/generated/jobs.js +98 -14
- package/dist/generated/keys.d.ts +8 -6
- package/dist/generated/keys.js +6 -6
- package/dist/generated/me.d.ts +2 -2
- package/dist/generated/me.js +3 -3
- package/dist/generated/messages.d.ts +67 -0
- package/dist/generated/messages.js +17 -0
- package/dist/generated/networks.d.ts +4 -4
- package/dist/generated/networks.js +4 -4
- package/dist/generated/notebooks.d.ts +87 -28
- package/dist/generated/notebooks.js +153 -41
- package/dist/generated/otel.d.ts +2 -2
- package/dist/generated/otel.js +5 -5
- package/dist/generated/ports.d.ts +11 -11
- package/dist/generated/ports.js +8 -8
- package/dist/generated/previews.d.ts +50 -15
- package/dist/generated/previews.js +70 -18
- package/dist/generated/projects.d.ts +30 -6
- package/dist/generated/projects.js +13 -9
- package/dist/generated/roles.d.ts +11 -2
- package/dist/generated/roles.js +9 -5
- package/dist/generated/routes.js +1 -1
- package/dist/generated/runtime.d.ts +15 -3
- package/dist/generated/runtime.js +31 -18
- package/dist/generated/sandboxes.d.ts +213 -66
- package/dist/generated/sandboxes.js +171 -43
- package/dist/generated/secrets.d.ts +45 -6
- package/dist/generated/secrets.js +69 -9
- package/dist/generated/sessions.d.ts +1 -1
- package/dist/generated/sessions.js +4 -4
- package/dist/generated/signing.js +3 -1
- package/dist/generated/sites.d.ts +87 -28
- package/dist/generated/sites.js +153 -41
- package/dist/generated/snapshots.d.ts +70 -5
- package/dist/generated/snapshots.js +107 -7
- package/dist/generated/tunnels.d.ts +8 -8
- package/dist/generated/tunnels.js +4 -4
- package/dist/generated/usage.d.ts +57 -6
- package/dist/generated/usage.js +4 -4
- package/dist/generated/volumes.d.ts +72 -7
- package/dist/generated/volumes.js +114 -10
- package/dist/generated/webhooks.d.ts +2 -2
- package/dist/generated/webhooks.js +5 -5
- package/dist/generated/workspaces.d.ts +87 -28
- package/dist/generated/workspaces.js +153 -41
- package/dist/v2/bin.d.ts +2 -0
- package/dist/v2/bin.js +15 -0
- package/dist/v2/cli.d.ts +15 -2
- package/dist/v2/cli.js +158 -53
- package/dist/v2/json.d.ts +9 -0
- package/dist/v2/json.js +5 -0
- package/dist/v2/mcp.js +14 -1
- package/dist/v2/openapi.json +7695 -4382
- package/dist/v2/shims/fly.js +49 -13
- package/dist/v2/shims/morph.js +1 -1
- package/dist/v2/table.d.ts +7 -4
- package/dist/v2/table.js +97 -34
- package/package.json +7 -5
package/dist/v2/cli.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
/* `runtime`: every verb and shortcut the API serves, as commands read from
|
|
3
2
|
its own description (./table.ts). Nothing here names a product: parsing
|
|
4
3
|
argv into a verb's arguments, printing its answer, and the primitives a
|
|
@@ -9,6 +8,7 @@ import { readFileSync } from "node:fs";
|
|
|
9
8
|
import { Runtime } from "../generated/index.js";
|
|
10
9
|
import { Transport, callRoute, routesOf } from "../generated/runtime.js";
|
|
11
10
|
import { commandsOf, document, kebab } from "./table.js";
|
|
11
|
+
import { obj, str } from "./json.js";
|
|
12
12
|
import { serveMcp } from "./mcp.js";
|
|
13
13
|
import { login, logout, savedKey } from "./login.js";
|
|
14
14
|
import { serveMachinesApi } from "./shims/fly.js";
|
|
@@ -16,7 +16,9 @@ import { serveMachinesApi } from "./shims/fly.js";
|
|
|
16
16
|
function version() {
|
|
17
17
|
for (const p of ["../package.json", "../../package.json"]) {
|
|
18
18
|
try {
|
|
19
|
-
|
|
19
|
+
const v = str(obj(JSON.parse(readFileSync(new URL(p, import.meta.url), "utf8")))["version"]);
|
|
20
|
+
if (v !== undefined)
|
|
21
|
+
return v;
|
|
20
22
|
}
|
|
21
23
|
catch {
|
|
22
24
|
// the next place
|
|
@@ -28,7 +30,11 @@ function usage(commands, from) {
|
|
|
28
30
|
const products = new Map();
|
|
29
31
|
for (const c of commands)
|
|
30
32
|
products.set(c.product, [...(products.get(c.product) ?? []), c]);
|
|
31
|
-
const lines = [
|
|
33
|
+
const lines = [
|
|
34
|
+
"Usage: runtime <product> <verb> [arguments] [--flags]",
|
|
35
|
+
" runtime <shortcut> [--flags] [-- command...]",
|
|
36
|
+
"",
|
|
37
|
+
];
|
|
32
38
|
const shortcuts = commands.filter((c) => c.shortcut);
|
|
33
39
|
if (shortcuts.length) {
|
|
34
40
|
lines.push("Shortcuts:");
|
|
@@ -52,26 +58,69 @@ function usage(commands, from) {
|
|
|
52
58
|
return lines.join("\n");
|
|
53
59
|
}
|
|
54
60
|
function help(c) {
|
|
55
|
-
const head = c.shortcut
|
|
61
|
+
const head = c.shortcut
|
|
62
|
+
? `runtime ${c.name}`
|
|
63
|
+
: `runtime ${c.product} ${c.verb}${c.args.map((a) => ` <${a}>`).join("")}`;
|
|
56
64
|
const lines = [`Usage: ${head} [--flags]`, "", c.doc, ""];
|
|
57
|
-
for (const f of c.flags)
|
|
58
|
-
|
|
65
|
+
for (const f of c.flags) {
|
|
66
|
+
if (f.secret)
|
|
67
|
+
lines.push(` ${"--from-file <path>".padEnd(26)} Its ${f.field}, read from this file, or else from standard input; never a flag. ${f.doc}`);
|
|
68
|
+
else
|
|
69
|
+
lines.push(` --${f.flag.padEnd(24)} ${f.type}${f.list ? "[]" : ""}${f.choices ? ` (${f.choices.join(", ")})` : ""}${f.required ? ", required" : ""}. ${f.doc}`);
|
|
70
|
+
}
|
|
59
71
|
if (c.stdin)
|
|
60
72
|
lines.push("", "Its body is read from standard input.");
|
|
61
73
|
return lines.join("\n");
|
|
62
74
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
/** One flag's text as its field's type in the API's description, refused here, before anything is sent, when it is
|
|
76
|
+
* not one. 18 Nov 2026: a number went as its text (`--memory-gb 4` as "4"), and the API refused it. */
|
|
77
|
+
export function value(f, raw) {
|
|
78
|
+
switch (f.type) {
|
|
79
|
+
case "integer":
|
|
80
|
+
if (!/^-?\d+$/.test(raw) || !Number.isSafeInteger(Number(raw)))
|
|
81
|
+
throw new Error(`--${f.flag} takes a whole number, not ${JSON.stringify(raw)}.`);
|
|
82
|
+
return Number(raw);
|
|
83
|
+
case "number":
|
|
84
|
+
if (!/^-?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(raw) || !Number.isFinite(Number(raw)))
|
|
85
|
+
throw new Error(`--${f.flag} takes a number, not ${JSON.stringify(raw)}.`);
|
|
86
|
+
return Number(raw);
|
|
87
|
+
case "boolean":
|
|
88
|
+
if (raw !== "true" && raw !== "false")
|
|
89
|
+
throw new Error(`--${f.flag} takes true or false, not ${JSON.stringify(raw)}.`);
|
|
90
|
+
return raw === "true";
|
|
91
|
+
case "object":
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(raw);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new Error(`--${f.flag} takes JSON, as '{"key": "value"}'.`);
|
|
97
|
+
}
|
|
98
|
+
case "string":
|
|
99
|
+
if (f.choices && !f.choices.includes(raw))
|
|
100
|
+
throw new Error(`--${f.flag} takes one of ${f.choices.join(", ")}, not ${JSON.stringify(raw)}.`);
|
|
101
|
+
return raw;
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`--${f.flag} is of type ${f.type}, which this CLI does not read.`);
|
|
69
104
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
105
|
+
}
|
|
106
|
+
/** Where parse keeps --from-file's path until the secret is read. */
|
|
107
|
+
const FROM_FILE = "\u0000fromFile";
|
|
108
|
+
/** A command's secret field, from --from-file's file, or else standard input when it is piped in: one trailing
|
|
109
|
+
* newline dropped (what `echo` and editors add). Left out when neither gives one, as a set that keeps the value. */
|
|
110
|
+
export function readSecret(c, args, stdin) {
|
|
111
|
+
const f = c.flags.find((x) => x.secret);
|
|
112
|
+
const path = args[FROM_FILE];
|
|
113
|
+
delete args[FROM_FILE];
|
|
114
|
+
if (!f)
|
|
115
|
+
return;
|
|
116
|
+
const text = path !== undefined ? readFileSync(path, "utf8") : stdin();
|
|
117
|
+
const value = text?.replace(/\r?\n$/, "");
|
|
118
|
+
if (path !== undefined && !value)
|
|
119
|
+
throw new Error(`--from-file ${path} is empty.`);
|
|
120
|
+
if (value)
|
|
121
|
+
args[f.field] = value;
|
|
122
|
+
else if (f.required)
|
|
123
|
+
throw new Error(`${c.name} needs its ${f.field}: pipe it in, or name a file with --from-file.`);
|
|
75
124
|
}
|
|
76
125
|
/** argv after the command as its arguments by wire name: positionals its
|
|
77
126
|
* path's parts, flags its fields, and after `--`, its command (`cmd`) when
|
|
@@ -79,6 +128,11 @@ function value(f, raw) {
|
|
|
79
128
|
export function parse(c, argv) {
|
|
80
129
|
const args = {};
|
|
81
130
|
const positional = [];
|
|
131
|
+
// A command given by its flag (`--cmd 'npm test && npm run lint'`) is the API's text form, a shell command line
|
|
132
|
+
// (bash -lc); given more than once, a program and its arguments. After `--` it is always the program and its
|
|
133
|
+
// arguments. 18 Nov 2026: one --cmd went as a one-item list, so the text was looked for as a program
|
|
134
|
+
// (program_not_found).
|
|
135
|
+
const flagged = new Set();
|
|
82
136
|
for (let i = 0; i < argv.length; i++) {
|
|
83
137
|
const a = argv[i];
|
|
84
138
|
if (a === "--") {
|
|
@@ -94,10 +148,25 @@ export function parse(c, argv) {
|
|
|
94
148
|
continue;
|
|
95
149
|
}
|
|
96
150
|
const [name, inline] = a.slice(2).split(/=(.*)/s, 2);
|
|
151
|
+
const secret = c.flags.find((x) => x.secret);
|
|
152
|
+
if (secret && name === "from-file") {
|
|
153
|
+
const path = inline ?? argv[++i];
|
|
154
|
+
if (path === undefined)
|
|
155
|
+
throw new Error("--from-file needs a path.");
|
|
156
|
+
args[FROM_FILE] = path;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
97
159
|
const f = c.flags.find((x) => x.flag === name || x.flag === kebab(name));
|
|
160
|
+
if (f?.secret) {
|
|
161
|
+
throw new Error(`--${f.flag} would leave the ${f.field} in shell history and ps. Pipe it in (printf %s "$VALUE" | runtime ${c.product} ${c.verb} ...) or name a file with --from-file.`);
|
|
162
|
+
}
|
|
98
163
|
if (!f)
|
|
99
164
|
throw new Error(`${c.name} has no flag --${name}. runtime ${c.shortcut ? c.name : `${c.product} ${c.verb}`} --help lists them.`);
|
|
100
|
-
|
|
165
|
+
// A boolean flag alone is true; it takes the next argument only when that is true or false.
|
|
166
|
+
const raw = inline ??
|
|
167
|
+
(f.type === "boolean" && argv[i + 1] !== "true" && argv[i + 1] !== "false"
|
|
168
|
+
? "true"
|
|
169
|
+
: argv[++i]);
|
|
101
170
|
if (raw === undefined)
|
|
102
171
|
throw new Error(`--${f.flag} needs a value.`);
|
|
103
172
|
if (f.type === "map") {
|
|
@@ -105,12 +174,19 @@ export function parse(c, argv) {
|
|
|
105
174
|
args[f.field] = { ...args[f.field], [k]: v ?? "" };
|
|
106
175
|
}
|
|
107
176
|
else if (f.list) {
|
|
177
|
+
if (f.command)
|
|
178
|
+
flagged.add(f.field);
|
|
108
179
|
args[f.field] = [...(args[f.field] ?? []), value(f, raw)];
|
|
109
180
|
}
|
|
110
181
|
else {
|
|
111
182
|
args[f.field] = value(f, raw);
|
|
112
183
|
}
|
|
113
184
|
}
|
|
185
|
+
for (const field of flagged) {
|
|
186
|
+
const given = args[field];
|
|
187
|
+
if (given.length === 1)
|
|
188
|
+
args[field] = given[0];
|
|
189
|
+
}
|
|
114
190
|
if (positional.length > c.args.length) {
|
|
115
191
|
// A shortcut's command after its flags, without `--`.
|
|
116
192
|
const command = c.flags.find((f) => f.command);
|
|
@@ -131,7 +207,7 @@ export function parse(c, argv) {
|
|
|
131
207
|
if (args[n] === undefined)
|
|
132
208
|
throw new Error(`${c.name} needs <${n}>.`);
|
|
133
209
|
for (const f of c.flags)
|
|
134
|
-
if (f.required && args[f.field] === undefined)
|
|
210
|
+
if (f.required && !f.secret && args[f.field] === undefined)
|
|
135
211
|
throw new Error(`${c.name} needs --${f.flag}.`);
|
|
136
212
|
return args;
|
|
137
213
|
}
|
|
@@ -145,7 +221,9 @@ async function shortcut(t, routes, c, args) {
|
|
|
145
221
|
const a = {};
|
|
146
222
|
let ready = true;
|
|
147
223
|
for (const [name, from] of Object.entries(step.args)) {
|
|
148
|
-
const v = "arg" in from
|
|
224
|
+
const v = "arg" in from
|
|
225
|
+
? args[from.arg]
|
|
226
|
+
: answers[from.step]?.[from.field];
|
|
149
227
|
if ("step" in from && answers[from.step] === undefined)
|
|
150
228
|
ready = false;
|
|
151
229
|
if (v !== undefined && v !== null)
|
|
@@ -162,7 +240,7 @@ async function shortcut(t, routes, c, args) {
|
|
|
162
240
|
answers.push(await callRoute(t, route, a));
|
|
163
241
|
}
|
|
164
242
|
catch (e) {
|
|
165
|
-
failure ??= e;
|
|
243
|
+
failure ??= e instanceof Error ? e : new Error(String(e));
|
|
166
244
|
answers.push(undefined);
|
|
167
245
|
}
|
|
168
246
|
}
|
|
@@ -175,9 +253,14 @@ function print(answer) {
|
|
|
175
253
|
process.stdout.write(answer);
|
|
176
254
|
return 0;
|
|
177
255
|
}
|
|
178
|
-
// A command's result: its own output and exit code, as a shell's.
|
|
256
|
+
// A command's result (a process that ended, with its output): its own output and exit code, as a shell's. 18 Nov
|
|
257
|
+
// 2026: this read 1.0's `timedOut`, which v2's process has not, so `runtime sandboxes exec` printed the process's
|
|
258
|
+
// JSON instead.
|
|
179
259
|
const r = answer;
|
|
180
|
-
if (r &&
|
|
260
|
+
if (r &&
|
|
261
|
+
typeof r.stdout === "string" &&
|
|
262
|
+
typeof r.stderr === "string" &&
|
|
263
|
+
((r.object === "process" && r.state !== "running") || "timedOut" in r)) {
|
|
181
264
|
process.stdout.write(r.stdout);
|
|
182
265
|
process.stderr.write(r.stderr);
|
|
183
266
|
return typeof r.exitCode === "number" ? r.exitCode : 124;
|
|
@@ -196,7 +279,11 @@ async function ssh(baseUrl, id) {
|
|
|
196
279
|
}
|
|
197
280
|
const sbx = await new Runtime({ baseUrl }).sandboxes.get(id);
|
|
198
281
|
const tty = process.stdin.isTTY;
|
|
199
|
-
const run = sbx.execStream(["bash", "-l"], {
|
|
282
|
+
const run = sbx.execStream(["bash", "-l"], {
|
|
283
|
+
pty: { cols: process.stdout.columns ?? 80, rows: process.stdout.rows ?? 24 },
|
|
284
|
+
stdinOpen: true,
|
|
285
|
+
outputEncoding: "base64",
|
|
286
|
+
});
|
|
200
287
|
const shell = await run.started();
|
|
201
288
|
// Input in order: each write after the last, at the offset the shell has taken.
|
|
202
289
|
let offset = 0;
|
|
@@ -204,7 +291,9 @@ async function ssh(baseUrl, id) {
|
|
|
204
291
|
const send = (d) => {
|
|
205
292
|
const at = offset;
|
|
206
293
|
offset += d.length;
|
|
207
|
-
sent = sent
|
|
294
|
+
sent = sent
|
|
295
|
+
.then(() => sbx.processes.write(shell.id, { data: d.toString("base64"), offset: at }))
|
|
296
|
+
.catch(() => undefined);
|
|
208
297
|
};
|
|
209
298
|
if (tty)
|
|
210
299
|
process.stdin.setRawMode(true);
|
|
@@ -220,45 +309,61 @@ async function ssh(baseUrl, id) {
|
|
|
220
309
|
process.stdin.pause();
|
|
221
310
|
}
|
|
222
311
|
}
|
|
312
|
+
/** The commands this file serves itself, ahead of the API's: each by its name, given the API's URL and what follows. */
|
|
313
|
+
export const own = {
|
|
314
|
+
login: (baseUrl) => login(baseUrl),
|
|
315
|
+
logout: (baseUrl) => logout(baseUrl),
|
|
316
|
+
mcp: (baseUrl) => serveMcp(baseUrl),
|
|
317
|
+
ssh: (baseUrl, rest) => ssh(baseUrl, rest[0]),
|
|
318
|
+
"fly-api": (baseUrl, rest) => {
|
|
319
|
+
const i = rest.indexOf("--port");
|
|
320
|
+
return serveMachinesApi(i >= 0 ? Number(rest[i + 1]) : 4280, { baseUrl });
|
|
321
|
+
},
|
|
322
|
+
version: () => {
|
|
323
|
+
process.stdout.write(`runtime ${version()}\n`);
|
|
324
|
+
return 0;
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
own["--version"] = own["version"];
|
|
328
|
+
/** The API's command argv names (a shortcut by its name, a verb by its product and verb), and what follows it; an
|
|
329
|
+
* argv that names none is refused, with the verbs its product has. */
|
|
330
|
+
export function find(commands, argv) {
|
|
331
|
+
const [first, second] = argv;
|
|
332
|
+
const c = commands.find((x) => x.shortcut && x.name === first) ??
|
|
333
|
+
commands.find((x) => !x.shortcut && x.product === first && x.verb === second);
|
|
334
|
+
if (!c) {
|
|
335
|
+
const verbs = commands.filter((x) => x.product === first && !x.shortcut).map((x) => x.verb);
|
|
336
|
+
throw new Error(verbs.length ? `runtime ${first}: one of ${verbs.join(", ")}.` : `runtime: no command ${first}. runtime --help lists them.`);
|
|
337
|
+
}
|
|
338
|
+
return { c, rest: argv.slice(c.shortcut ? 1 : 2) };
|
|
339
|
+
}
|
|
223
340
|
export async function main(argv) {
|
|
224
341
|
const baseUrl = (process.env["RUNTIME_API_URL"] ?? "https://api.withruntime.com").replace(/\/$/, "");
|
|
225
|
-
if (argv[0] === "login")
|
|
226
|
-
return login(baseUrl);
|
|
227
|
-
if (argv[0] === "logout")
|
|
228
|
-
return logout(baseUrl);
|
|
229
342
|
// The key every command sends, the MCP bridge's and the shims' too: the environment's, else the one login saved.
|
|
230
|
-
if (!process.env["RUNTIME_API_KEY"]) {
|
|
343
|
+
if (argv[0] !== "login" && argv[0] !== "logout" && !process.env["RUNTIME_API_KEY"]) {
|
|
231
344
|
const key = savedKey(baseUrl);
|
|
232
345
|
if (key)
|
|
233
346
|
process.env["RUNTIME_API_KEY"] = key;
|
|
234
347
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return ssh(baseUrl, argv[1]);
|
|
239
|
-
if (argv[0] === "fly-api") {
|
|
240
|
-
const i = argv.indexOf("--port");
|
|
241
|
-
return serveMachinesApi(i >= 0 ? Number(argv[i + 1]) : 4280, { baseUrl });
|
|
242
|
-
}
|
|
243
|
-
if (argv[0] === "--version" || argv[0] === "version") {
|
|
244
|
-
process.stdout.write(`runtime ${version()}\n`);
|
|
245
|
-
return 0;
|
|
246
|
-
}
|
|
348
|
+
const mine = Object.hasOwn(own, argv[0] ?? "") ? own[argv[0]] : undefined;
|
|
349
|
+
if (mine)
|
|
350
|
+
return mine(baseUrl, argv.slice(1));
|
|
247
351
|
const { doc, from } = await document(baseUrl);
|
|
248
352
|
const commands = commandsOf(doc);
|
|
249
|
-
const
|
|
353
|
+
const first = argv[0];
|
|
250
354
|
if (!first || first === "--help" || first === "-h" || first === "help") {
|
|
251
355
|
process.stdout.write(`${usage(commands, from)}\n`);
|
|
252
356
|
return first ? 0 : 2;
|
|
253
357
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
358
|
+
let found;
|
|
359
|
+
try {
|
|
360
|
+
found = find(commands, argv);
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
process.stderr.write(`${e.message}\n`);
|
|
259
364
|
return 2;
|
|
260
365
|
}
|
|
261
|
-
const
|
|
366
|
+
const { c, rest } = found;
|
|
262
367
|
if (rest.includes("--help") || rest.includes("-h")) {
|
|
263
368
|
process.stdout.write(`${help(c)}\n`);
|
|
264
369
|
return 0;
|
|
@@ -269,7 +374,10 @@ export async function main(argv) {
|
|
|
269
374
|
const args = parse(c, rest);
|
|
270
375
|
if (c.stdin)
|
|
271
376
|
args["data"] = new Uint8Array(readFileSync(0));
|
|
272
|
-
|
|
377
|
+
readSecret(c, args, () => (process.stdin.isTTY ? undefined : readFileSync(0, "utf8")));
|
|
378
|
+
const answer = c.shortcut
|
|
379
|
+
? await shortcut(t, routes, c, args)
|
|
380
|
+
: await callRoute(t, routes[c.name], args);
|
|
273
381
|
return print(answer);
|
|
274
382
|
}
|
|
275
383
|
catch (e) {
|
|
@@ -278,6 +386,3 @@ export async function main(argv) {
|
|
|
278
386
|
return 1;
|
|
279
387
|
}
|
|
280
388
|
}
|
|
281
|
-
if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("/runtime") || process.argv[1]?.endsWith("/cli.js")) {
|
|
282
|
-
main(process.argv.slice(2)).then((code) => process.exit(code));
|
|
283
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Parsed JSON, read without trusting its shape: each read narrows, and a value of another shape reads as empty. */
|
|
2
|
+
export type Json = {
|
|
3
|
+
[k: string]: unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare const obj: (v: unknown) => Json;
|
|
6
|
+
export declare const arr: (v: unknown) => unknown[];
|
|
7
|
+
export declare const str: (v: unknown) => string | undefined;
|
|
8
|
+
export declare const num: (v: unknown) => number | undefined;
|
|
9
|
+
export declare const strs: (v: unknown) => string[];
|
package/dist/v2/json.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const obj = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
2
|
+
export const arr = (v) => (Array.isArray(v) ? v : []);
|
|
3
|
+
export const str = (v) => (typeof v === "string" ? v : undefined);
|
|
4
|
+
export const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
5
|
+
export const strs = (v) => arr(v).filter((x) => typeof x === "string");
|
package/dist/v2/mcp.js
CHANGED
|
@@ -34,12 +34,25 @@ export async function serveMcp(baseUrl, fetcher = fetch) {
|
|
|
34
34
|
if (res.status === 202)
|
|
35
35
|
continue;
|
|
36
36
|
const text = await res.text();
|
|
37
|
+
let body;
|
|
37
38
|
try {
|
|
38
|
-
|
|
39
|
+
body = JSON.parse(text);
|
|
39
40
|
}
|
|
40
41
|
catch {
|
|
41
42
|
write({ jsonrpc: "2.0", id, error: { code: -32603, message: `The API answered ${res.status}: ${text.slice(0, 200)}` } });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (res.ok) {
|
|
46
|
+
write(body);
|
|
47
|
+
continue;
|
|
42
48
|
}
|
|
49
|
+
// A refusal of the call itself (no key, a bad key, a limit) is the API's error body, not a JSON-RPC answer: the
|
|
50
|
+
// client is told it as this request's error, or it waits for an answer that never comes.
|
|
51
|
+
const api = body.error;
|
|
52
|
+
const message = !key && res.status === 401
|
|
53
|
+
? "No API key. Set RUNTIME_API_KEY, or run `npx withruntime login` once on this machine."
|
|
54
|
+
: `${api?.code ?? res.status}: ${api?.message ?? text.slice(0, 200)}${api?.hint ? ` ${api.hint}` : ""}`;
|
|
55
|
+
write({ jsonrpc: "2.0", id, error: { code: -32001, message, data: { status: res.status, ...api } } });
|
|
43
56
|
}
|
|
44
57
|
catch (e) {
|
|
45
58
|
write({ jsonrpc: "2.0", id, error: { code: -32603, message: `The API did not answer: ${e.message}` } });
|