loaner-sdk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/cli/bin.js +17 -0
- package/dist/cli/commands.json +2782 -0
- package/dist/cli/engine/args.js +175 -0
- package/dist/cli/engine/auth.js +243 -0
- package/dist/cli/engine/commands.js +266 -0
- package/dist/cli/engine/help.js +155 -0
- package/dist/cli/engine/index.js +879 -0
- package/dist/cli/engine/job.js +20 -0
- package/dist/cli/engine/mcp.js +125 -0
- package/dist/cli/jobs/deploy.js +136 -0
- package/dist/cli/jobs/index.js +4 -0
- package/dist/cli/jobs/logs.js +66 -0
- package/dist/cli/jobs/open.js +25 -0
- package/dist/http.d.ts +6 -2
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +8 -4
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +95 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -6
- package/dist/index.js.map +1 -1
- package/dist/pack.d.ts +7 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +120 -0
- package/dist/pack.js.map +1 -0
- package/dist/src/pack.js +119 -0
- package/package.json +15 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jobs: one task, one command (`postbox signup`). A job makes the few calls a playbook makes every time, through the
|
|
3
|
+
* same MCP tools an agent would call, and prints only the answer. Written by the app in `cli/jobs/`; this file is the
|
|
4
|
+
* kit's and imports nothing from Node, so scripts can load the jobs cheaply.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* export const signup = defineJob({
|
|
8
|
+
* name: 'signup', summary: 'Make an address and wait for its code',
|
|
9
|
+
* args: { label: { type: 'string', description: 'What the address is for.', default: 'signup' } },
|
|
10
|
+
* examples: [{ run: 'signup --label shop', about: 'An address for a shop, then its code' }],
|
|
11
|
+
* run: async (ctx, { label }) => {
|
|
12
|
+
* const made = await ctx.call('create_address', { label })
|
|
13
|
+
* if (made.isError) ctx.fail(made)
|
|
14
|
+
* ctx.progress(`Waiting for mail to ${made.json.address}`)
|
|
15
|
+
* ctx.print(made.text)
|
|
16
|
+
* },
|
|
17
|
+
* })
|
|
18
|
+
*/
|
|
19
|
+
/** Keeps a job's argument types for its `run`. */
|
|
20
|
+
export const defineJob = (job) => job;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export const PROTOCOL = '2026-07-28';
|
|
2
|
+
export const PROBLEM_META = 'api-kit/problem';
|
|
3
|
+
export const PENDING_META = 'api-kit/pending';
|
|
4
|
+
/** The MCP Tasks extension: declared on every request, so a server that offers it answers a slow call with a task. */
|
|
5
|
+
export const TASKS_EXTENSION = 'io.modelcontextprotocol/tasks';
|
|
6
|
+
/** The kit's hash of the server's tool list, on each listed tool and every call's result. */
|
|
7
|
+
export const TOOLS_HASH_META = 'api-kit/tools-hash';
|
|
8
|
+
/** The exit codes, stable for scripts and agents. */
|
|
9
|
+
export const EXIT = { ok: 0, usage: 1, signIn: 2, notFound: 3, refused: 4, server: 5, timeout: 6, interrupted: 130 };
|
|
10
|
+
/** The exit code an HTTP status stands for. */
|
|
11
|
+
export const exitFor = (status) => {
|
|
12
|
+
if (status === 400)
|
|
13
|
+
return EXIT.usage;
|
|
14
|
+
if (status === 401 || status === 403)
|
|
15
|
+
return EXIT.signIn;
|
|
16
|
+
if (status === 404 || status === 410)
|
|
17
|
+
return EXIT.notFound;
|
|
18
|
+
if (status === 408 || status === 504)
|
|
19
|
+
return EXIT.timeout;
|
|
20
|
+
if (status >= 500 || status === 0)
|
|
21
|
+
return EXIT.server;
|
|
22
|
+
return status >= 400 ? EXIT.refused : EXIT.ok;
|
|
23
|
+
};
|
|
24
|
+
/** A failure with its exit code, and the problem behind it when there is one. */
|
|
25
|
+
export class CliError extends Error {
|
|
26
|
+
exitCode;
|
|
27
|
+
problem;
|
|
28
|
+
/** The line after a usage error, when the usual `Run help <command>` would point somewhere that doesn't exist. */
|
|
29
|
+
hint;
|
|
30
|
+
constructor(message, exitCode, problem) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'CliError';
|
|
33
|
+
this.exitCode = exitCode;
|
|
34
|
+
this.problem = problem;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** A problem as one line: `404 not_found Not found: No such app.` (as the kit's tools write it). */
|
|
38
|
+
export const problemLine = (problem) => `${problem.status} ${problem.code ?? ''} ${problem.title}: ${problem.detail ?? ''}`.replace(/\s+/g, ' ').replace(/:\s*$/, '').trim();
|
|
39
|
+
/** The JSON-RPC answer in a body that is JSON or a server-sent event stream. */
|
|
40
|
+
const answerOf = (type, text) => {
|
|
41
|
+
if (!type.includes('event-stream'))
|
|
42
|
+
return JSON.parse(text);
|
|
43
|
+
const events = text.split(/\n\n/).map((event) => event.split('\n').filter((line) => line.startsWith('data:')).map((line) => line.slice(5).trim()).join('\n')).filter(Boolean);
|
|
44
|
+
const found = events.map((data) => JSON.parse(data)).find((message) => message.id !== undefined);
|
|
45
|
+
if (!found)
|
|
46
|
+
throw new CliError('The server sent no answer in its event stream.', EXIT.server);
|
|
47
|
+
return found;
|
|
48
|
+
};
|
|
49
|
+
export const mcpClient = ({ url, bearer, refresh, fetch: send, signIn }) => {
|
|
50
|
+
const endpoint = `${url.replace(/\/+$/, '')}/mcp`;
|
|
51
|
+
const post = async (method, params, signal, retried = false) => {
|
|
52
|
+
const token = await bearer();
|
|
53
|
+
let response;
|
|
54
|
+
try {
|
|
55
|
+
response = await send(endpoint, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
signal,
|
|
58
|
+
headers: {
|
|
59
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
60
|
+
'content-type': 'application/json',
|
|
61
|
+
accept: 'application/json, text/event-stream',
|
|
62
|
+
'mcp-protocol-version': PROTOCOL,
|
|
63
|
+
'mcp-method': method,
|
|
64
|
+
...(method === 'tools/call' ? { 'mcp-name': String(params.name) } : {}),
|
|
65
|
+
...(method === 'resources/read' ? { 'mcp-name': String(params.uri) } : {}),
|
|
66
|
+
...(method.startsWith('tasks/') ? { 'mcp-name': String(params.taskId) } : {}),
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params: { ...params, _meta: { 'io.modelcontextprotocol/protocolVersion': PROTOCOL, 'io.modelcontextprotocol/clientCapabilities': { extensions: { [TASKS_EXTENSION]: {} } } } } }),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (signal?.aborted)
|
|
73
|
+
throw signal.reason instanceof CliError ? signal.reason : new CliError('Stopped.', EXIT.interrupted);
|
|
74
|
+
throw new CliError(`Could not reach ${url}: ${error instanceof Error ? error.message : String(error)}`, EXIT.server);
|
|
75
|
+
}
|
|
76
|
+
if ((response.status === 401 || response.status === 403) && !retried && refresh && (await refresh()))
|
|
77
|
+
return post(method, params, signal, true);
|
|
78
|
+
const text = await response.text();
|
|
79
|
+
if (response.status === 401 || response.status === 403)
|
|
80
|
+
throw new CliError(`${response.status === 401 ? 'Not signed in' : 'Not allowed'} at ${url}: ${signIn}`, EXIT.signIn, { title: 'Not signed in', status: response.status });
|
|
81
|
+
if (response.status === 404)
|
|
82
|
+
throw new CliError(`No MCP server at ${endpoint} (404): check the address`, EXIT.server);
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
const problem = (() => {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
})();
|
|
92
|
+
throw new CliError(problem?.title ? problemLine({ ...problem, status: response.status }) : `${endpoint} answered ${response.status}`, exitFor(response.status), problem ? { ...problem, status: response.status } : undefined);
|
|
93
|
+
}
|
|
94
|
+
const answer = answerOf(response.headers.get('content-type') ?? '', text);
|
|
95
|
+
if (answer.error) {
|
|
96
|
+
// A route's failure inside a read comes back as `404 not_found …` in the message
|
|
97
|
+
const status = Number(answer.error.message.match(/^(\d{3}) /)?.[1] ?? 0);
|
|
98
|
+
if (status)
|
|
99
|
+
throw new CliError(answer.error.message, exitFor(status), { title: answer.error.message, status });
|
|
100
|
+
throw new CliError(answer.error.message, answer.error.code === -32602 ? EXIT.usage : EXIT.server);
|
|
101
|
+
}
|
|
102
|
+
return answer.result;
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
discover: (signal) => post('server/discover', {}, signal),
|
|
106
|
+
listTools: (signal) => post('tools/list', {}, signal),
|
|
107
|
+
listTemplates: (signal) => post('resources/templates/list', {}, signal),
|
|
108
|
+
/** A tool's result, or the task a server that offers tasks answers a slow call with. */
|
|
109
|
+
callTool: (name, args, signal) => post('tools/call', { name, arguments: args }, signal),
|
|
110
|
+
getTask: (taskId, signal) => post('tasks/get', { taskId }, signal),
|
|
111
|
+
readResource: (uri, signal) => post('resources/read', { uri }, signal),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
/** A failed tool result's problem: the kit's `_meta`, else read from its text (`404 not_found …`). */
|
|
115
|
+
export const problemOfResult = (result) => {
|
|
116
|
+
const meta = result._meta?.[PROBLEM_META];
|
|
117
|
+
if (meta)
|
|
118
|
+
return meta;
|
|
119
|
+
const text = (result.content ?? []).map((part) => part.text ?? '').join('\n');
|
|
120
|
+
const status = Number(text.match(/^(\d{3}) /)?.[1] ?? 0);
|
|
121
|
+
// The SDK's own refusal of bad arguments, before the tool runs
|
|
122
|
+
if (!status && /^Input validation error/i.test(text))
|
|
123
|
+
return { title: 'Invalid arguments', detail: text, status: 400 };
|
|
124
|
+
return { title: text || 'The tool failed', status: status || 500 };
|
|
125
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/** `loaner deploy [folder]`: a folder on this computer put online at a URL of its name, built and kept running. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { packFolder } from '../../src/pack.js';
|
|
5
|
+
import { defineJob } from '../engine/job.js';
|
|
6
|
+
const DEPLOYMENTS = '/api/v1/deployments';
|
|
7
|
+
/** A deployment name from the folder: its package.json name (`@shop/api` is `shop-api`), else the folder's own. */
|
|
8
|
+
export const nameOf = (folder) => {
|
|
9
|
+
let name = basename(resolve(folder));
|
|
10
|
+
try {
|
|
11
|
+
name = JSON.parse(readFileSync(join(folder, 'package.json'), 'utf8')).name ?? name;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// No package.json: the folder's name
|
|
15
|
+
}
|
|
16
|
+
return name
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/^@/, '')
|
|
19
|
+
.replace(/[^a-z0-9-]+/g, '-')
|
|
20
|
+
.replace(/^-+|-+$/g, '')
|
|
21
|
+
.slice(0, 40)
|
|
22
|
+
.replace(/-+$/, '');
|
|
23
|
+
};
|
|
24
|
+
/** `KEY=value` lines, as a .env file holds them: comments, blank lines and `export ` skipped, quotes taken off. */
|
|
25
|
+
export const envOf = (text) => Object.fromEntries(text
|
|
26
|
+
.split('\n')
|
|
27
|
+
.map((line) => line.trim().replace(/^export\s+/, ''))
|
|
28
|
+
.filter((line) => line && !line.startsWith('#') && line.includes('='))
|
|
29
|
+
.map((line) => {
|
|
30
|
+
const at = line.indexOf('=');
|
|
31
|
+
const value = line.slice(at + 1).trim();
|
|
32
|
+
return [line.slice(0, at).trim(), /^(['"]).*\1$/.test(value) ? value.slice(1, -1) : value];
|
|
33
|
+
}));
|
|
34
|
+
/** The JSON of an answer, or the job stops with its problem. */
|
|
35
|
+
const answerOf = async (ctx, response) => {
|
|
36
|
+
const json = (await response.json().catch(() => ({})));
|
|
37
|
+
if (!response.ok)
|
|
38
|
+
ctx.fail({ title: response.statusText || 'refused', ...json, status: response.status });
|
|
39
|
+
return json;
|
|
40
|
+
};
|
|
41
|
+
/** Follows a deploy until it is served (prints its URL) or failed (stops with its step and error). */
|
|
42
|
+
const followed = async (ctx, first, next, ready) => {
|
|
43
|
+
let card = first;
|
|
44
|
+
let said = '';
|
|
45
|
+
while (card.status === 'building' || card.status === 'waiting') {
|
|
46
|
+
if (card.step && card.step !== said)
|
|
47
|
+
ctx.progress(`Building: ${(said = card.step)}`);
|
|
48
|
+
if (ctx.signal.aborted)
|
|
49
|
+
ctx.fail({ title: `Stopped waiting; ${card.name} goes on building`, status: 408 });
|
|
50
|
+
card = await next();
|
|
51
|
+
}
|
|
52
|
+
if (card.status === 'failed')
|
|
53
|
+
ctx.fail({
|
|
54
|
+
title: `${card.name} failed at ${card.step}`,
|
|
55
|
+
status: 422,
|
|
56
|
+
detail: `${card.error ?? ''}\nloaner logs ${card.name} --of build shows each step.`,
|
|
57
|
+
});
|
|
58
|
+
ctx.progress(ready);
|
|
59
|
+
if (ctx.jsonMode)
|
|
60
|
+
ctx.json(card);
|
|
61
|
+
else
|
|
62
|
+
ctx.print(card.url ?? '');
|
|
63
|
+
};
|
|
64
|
+
/** Sends a folder to an upload link and follows the deploy, needing no sign-in: the link is the key. */
|
|
65
|
+
const toLink = async (ctx, folder, link) => {
|
|
66
|
+
const url = new URL(link);
|
|
67
|
+
if (!/^\/api\/v1\/uploads\/[^/]+$/.test(url.pathname))
|
|
68
|
+
ctx.fail({ title: `${link} is not an upload link (…/api/v1/uploads/<token>)`, status: 400 });
|
|
69
|
+
ctx.progress(`Packing ${resolve(folder)}`);
|
|
70
|
+
const archive = await packFolder(folder);
|
|
71
|
+
ctx.progress(`Uploading ${Math.ceil(archive.length / 1024)} KB`);
|
|
72
|
+
const read = async (response) => {
|
|
73
|
+
const json = (await response.json().catch(() => ({})));
|
|
74
|
+
if (!response.ok)
|
|
75
|
+
ctx.fail({ title: response.statusText || 'refused', ...json, status: response.status });
|
|
76
|
+
return json;
|
|
77
|
+
};
|
|
78
|
+
const sent = await read(await fetch(url, { method: 'PUT', body: archive, headers: { 'content-type': 'application/gzip' }, signal: ctx.signal }));
|
|
79
|
+
await followed(ctx, sent, async () => read(await fetch(`${url}?wait=25`, { headers: { accept: 'application/json' }, signal: ctx.signal })), `Ready: ${sent.name} is served`);
|
|
80
|
+
};
|
|
81
|
+
export const deploy = defineJob({
|
|
82
|
+
name: 'deploy',
|
|
83
|
+
summary: 'Put a folder online at a URL of its name, built and kept running',
|
|
84
|
+
description: 'Packs the folder (inside a git repository what git keeps; never node_modules, .git or .env files), uploads it, and waits while Loaner builds and starts it. Prints its URL, which stays the same when you deploy the same name again. Next.js, Astro, Vite and any app with a "start" script listening on $PORT need nothing else; a loaner.json says what to run otherwise. In a monorepo, give the app’s own folder: a lockfile at the top isn’t in it, so it installs with npm install.',
|
|
85
|
+
args: {
|
|
86
|
+
folder: { type: 'string', description: 'The app’s folder.', positional: true, default: '.' },
|
|
87
|
+
name: {
|
|
88
|
+
type: 'string',
|
|
89
|
+
description: 'Its name, also in its URL (default: package.json’s name, else the folder’s).',
|
|
90
|
+
},
|
|
91
|
+
preview: {
|
|
92
|
+
type: 'boolean',
|
|
93
|
+
description: 'A preview: stops after 2 idle hours, instead of running until deleted.',
|
|
94
|
+
default: false,
|
|
95
|
+
},
|
|
96
|
+
'env-file': { type: 'string', description: 'A .env file whose values its build and start get.' },
|
|
97
|
+
env: { type: 'string', description: 'KEY=value for its build and start; give it again for more.', multiple: true },
|
|
98
|
+
upload: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
description: 'An upload link from a deploy made elsewhere (deploy_app with upload, an agent): sends the folder there, with no sign-in.',
|
|
101
|
+
},
|
|
102
|
+
memory: {
|
|
103
|
+
type: 'number',
|
|
104
|
+
description: 'Its machine’s memory in MiB, when a build ran out (the failure says how much to ask for).',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
examples: [
|
|
108
|
+
{ run: 'deploy', about: 'This folder, named after its package.json' },
|
|
109
|
+
{ run: 'deploy ./site --name docs-site --env-file .env.production', about: 'A folder, a name, its secrets' },
|
|
110
|
+
{ run: 'deploy --preview', about: 'A preview that stops when idle' },
|
|
111
|
+
{ run: "deploy ./site --upload 'https://loaner.example.com/api/v1/uploads/…'", about: 'To a link, signed out' },
|
|
112
|
+
],
|
|
113
|
+
run: async (ctx, args) => {
|
|
114
|
+
if (args.upload)
|
|
115
|
+
return toLink(ctx, args.folder, args.upload);
|
|
116
|
+
const name = args.name ?? nameOf(args.folder);
|
|
117
|
+
if (name.length < 3)
|
|
118
|
+
ctx.fail({ title: `No name to deploy ${args.folder} as: give --name`, status: 400 });
|
|
119
|
+
const env = {
|
|
120
|
+
...(args['env-file'] ? envOf(readFileSync(args['env-file'], 'utf8')) : {}),
|
|
121
|
+
...envOf((args.env ?? []).join('\n')),
|
|
122
|
+
};
|
|
123
|
+
ctx.progress(`Packing ${resolve(args.folder)}`);
|
|
124
|
+
const archive = await packFolder(args.folder);
|
|
125
|
+
await answerOf(ctx, await ctx.api('POST', DEPLOYMENTS, {
|
|
126
|
+
name,
|
|
127
|
+
kind: args.preview ? 'preview' : 'app',
|
|
128
|
+
env,
|
|
129
|
+
upload: true,
|
|
130
|
+
...(args.memory ? { memoryMiB: args.memory } : {}),
|
|
131
|
+
}));
|
|
132
|
+
ctx.progress(`Uploading ${Math.ceil(archive.length / 1024)} KB as ${name}`);
|
|
133
|
+
const sent = await answerOf(ctx, await ctx.api('PUT', `${DEPLOYMENTS}/${name}/archive`, archive, { 'content-type': 'application/gzip' }));
|
|
134
|
+
await followed(ctx, sent, async () => answerOf(ctx, await ctx.api('GET', `${DEPLOYMENTS}/${name}?wait=25`)), `Ready: ${name} is served, and kept up${args.preview ? ' until it idles for 2 hours' : ' until deleted'}`);
|
|
135
|
+
},
|
|
136
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** `loaner logs <name>`: a deployment's build log and its app's log, or the app's followed as it prints. */
|
|
2
|
+
import { defineJob } from '../engine/job.js';
|
|
3
|
+
const headOf = (label, part) => `== ${label}: ${part.state}${part.exitCode !== null ? ` ${part.exitCode}` : ''} (${part.command})`;
|
|
4
|
+
export const logs = defineJob({
|
|
5
|
+
name: 'logs',
|
|
6
|
+
summary: 'Read a deployment’s build and app logs, or follow its app',
|
|
7
|
+
description: 'Shows the last lines of each build step and of the running app, apart. --follow prints the app’s output as it comes, until Ctrl-C or the app ends.',
|
|
8
|
+
args: {
|
|
9
|
+
name: { type: 'string', description: 'The deployment’s name.', positional: true, required: true },
|
|
10
|
+
of: { type: 'string', description: 'all, build or app.', default: 'all' },
|
|
11
|
+
lines: { type: 'number', description: 'How many last lines of each (at most 1000).', default: 40 },
|
|
12
|
+
follow: { type: 'boolean', description: 'Then print the app’s output as it comes.', default: false },
|
|
13
|
+
},
|
|
14
|
+
examples: [
|
|
15
|
+
{ run: 'logs docs-site', about: 'Its build and its app, the last 40 lines of each' },
|
|
16
|
+
{ run: 'logs docs-site --of build', about: 'Why a build failed' },
|
|
17
|
+
{ run: 'logs docs-site --follow', about: 'Watch the app, like tail -f' },
|
|
18
|
+
],
|
|
19
|
+
run: async (ctx, { name, of, lines, follow }) => {
|
|
20
|
+
const query = new URLSearchParams({ of: follow ? (of === 'build' ? 'all' : of) : of, lines: String(lines) });
|
|
21
|
+
const response = await ctx.api('GET', `/api/v1/deployments/${encodeURIComponent(name)}/logs?${query}`);
|
|
22
|
+
const json = (await response.json().catch(() => ({})));
|
|
23
|
+
if (!response.ok)
|
|
24
|
+
ctx.fail({ title: response.statusText || 'refused', ...json, status: response.status });
|
|
25
|
+
if (ctx.jsonMode && !follow)
|
|
26
|
+
return ctx.json(json);
|
|
27
|
+
for (const part of json.build ?? [])
|
|
28
|
+
ctx.print(`${headOf(part.step, part)}\n${part.lines}`);
|
|
29
|
+
if (json.app)
|
|
30
|
+
ctx.print(`${headOf('app', json.app)}\n${json.app.lines}`);
|
|
31
|
+
if (!follow)
|
|
32
|
+
return;
|
|
33
|
+
const from = json.app?._links.follow?.href;
|
|
34
|
+
if (!from)
|
|
35
|
+
ctx.fail({ title: `${name} has no running app to follow yet`, status: 404 });
|
|
36
|
+
const stream = await ctx.api('GET', from, undefined, { accept: 'text/event-stream' });
|
|
37
|
+
if (!stream.ok || !stream.body)
|
|
38
|
+
ctx.fail({ title: 'Following its app was refused', status: stream.status });
|
|
39
|
+
const decoder = new TextDecoder();
|
|
40
|
+
let events = '';
|
|
41
|
+
let line = '';
|
|
42
|
+
for await (const chunk of stream.body) {
|
|
43
|
+
events += decoder.decode(chunk, { stream: true });
|
|
44
|
+
for (let end = events.indexOf('\n\n'); end >= 0; end = events.indexOf('\n\n')) {
|
|
45
|
+
const event = events.slice(0, end);
|
|
46
|
+
events = events.slice(end + 2);
|
|
47
|
+
const kind = /^event: (\w+)/m.exec(event)?.[1];
|
|
48
|
+
const data = JSON.parse(/^data: (.*)$/m.exec(event)?.[1] ?? '{}');
|
|
49
|
+
if (kind === 'output' && data.text) {
|
|
50
|
+
// Whole lines only, so a line split across events prints once
|
|
51
|
+
const text = line + data.text;
|
|
52
|
+
const cut = text.lastIndexOf('\n');
|
|
53
|
+
if (cut >= 0)
|
|
54
|
+
ctx.print(text.slice(0, cut + 1));
|
|
55
|
+
line = text.slice(cut + 1);
|
|
56
|
+
}
|
|
57
|
+
if (kind === 'end') {
|
|
58
|
+
if (line)
|
|
59
|
+
ctx.print(line);
|
|
60
|
+
ctx.progress(`Its app ended: ${data.state}${data.exitCode != null ? ` ${data.exitCode}` : ''}`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** `loaner open <name>`: a deployment's URL, opened in the browser when a person is at the terminal. */
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { defineJob } from '../engine/job.js';
|
|
4
|
+
const OPENER = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'explorer' : 'xdg-open';
|
|
5
|
+
export const open = defineJob({
|
|
6
|
+
name: 'open',
|
|
7
|
+
summary: 'Open a deployment’s URL in the browser',
|
|
8
|
+
args: { name: { type: 'string', description: 'The deployment’s name.', positional: true, required: true } },
|
|
9
|
+
examples: [{ run: 'open docs-site', about: 'Its page, in your browser' }],
|
|
10
|
+
run: async (ctx, { name }) => {
|
|
11
|
+
const response = await ctx.api('GET', `/api/v1/deployments/${encodeURIComponent(name)}`);
|
|
12
|
+
const card = (await response.json().catch(() => ({})));
|
|
13
|
+
if (!response.ok)
|
|
14
|
+
ctx.fail({ title: response.statusText || 'refused', ...card, status: response.status });
|
|
15
|
+
if (!card.url)
|
|
16
|
+
ctx.fail({ title: `${name} has no URL yet: it is ${card.status}`, status: 409 });
|
|
17
|
+
if (ctx.jsonMode)
|
|
18
|
+
return ctx.json(card);
|
|
19
|
+
ctx.print(card.url);
|
|
20
|
+
if (ctx.interactive)
|
|
21
|
+
spawn(OPENER, [card.url], { detached: true, stdio: 'ignore' })
|
|
22
|
+
.on('error', () => { })
|
|
23
|
+
.unref();
|
|
24
|
+
},
|
|
25
|
+
});
|
package/dist/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The SDK's one way to call the API: JSON in, JSON out, a problem answer thrown as a `LoanerError`. */
|
|
1
|
+
/** The SDK's one way to call the API: JSON (or raw bytes) in, JSON out, a problem answer thrown as a `LoanerError`. */
|
|
2
2
|
export interface ClientOptions {
|
|
3
3
|
/** The API's address, e.g. `http://localhost:4400` or `https://machines.example.com`. */
|
|
4
4
|
url: string;
|
|
@@ -15,9 +15,13 @@ export declare class LoanerError extends Error {
|
|
|
15
15
|
constructor(status: number, code: string, detail: string);
|
|
16
16
|
}
|
|
17
17
|
export type Query = Record<string, string | number | boolean | undefined>;
|
|
18
|
-
export declare const httpOf: ({ url, key, fetch: send }: ClientOptions) => <T>(method: string, path: string, { body, query }?: {
|
|
18
|
+
export declare const httpOf: ({ url, key, fetch: send }: ClientOptions) => <T>(method: string, path: string, { body, query, bytes, }?: {
|
|
19
19
|
body?: unknown;
|
|
20
20
|
query?: Query;
|
|
21
|
+
bytes?: {
|
|
22
|
+
data: Uint8Array<ArrayBuffer>;
|
|
23
|
+
type: string;
|
|
24
|
+
};
|
|
21
25
|
}) => Promise<T>;
|
|
22
26
|
export type Http = ReturnType<typeof httpOf>;
|
|
23
27
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,uHAAuH;AAEvH,MAAM,WAAW,aAAa;IAC5B,yFAAyF;IACzF,GAAG,EAAE,MAAM,CAAA;IACX,4FAA4F;IAC5F,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,oFAAoF;IACpF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAA;CAC3D;AAED,4GAA4G;AAC5G,qBAAa,WAAY,SAAQ,KAAK;IAElC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM;IAHzB,YACW,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAIxB;CACF;AAED,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;AAEzE,eAAO,MAAM,MAAM,8BAA6D,aAAa,MAE7E,CAAC,UACL,MAAM,QACR,MAAM,4BAKT;IACD,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CACxD,eA2BJ,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAA"}
|
package/dist/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The SDK's one way to call the API: JSON in, JSON out, a problem answer thrown as a `LoanerError`. */
|
|
1
|
+
/** The SDK's one way to call the API: JSON (or raw bytes) in, JSON out, a problem answer thrown as a `LoanerError`. */
|
|
2
2
|
/** An answer the API refused: its status, its problem `code`, and the `detail` that says what to change. */
|
|
3
3
|
export class LoanerError extends Error {
|
|
4
4
|
status;
|
|
@@ -14,7 +14,7 @@ export class LoanerError extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
export const httpOf = ({ url, key, fetch: send = (request) => fetch(request) }) => {
|
|
16
16
|
const base = url.replace(/\/$/, '');
|
|
17
|
-
return async (method, path, { body, query } = {}) => {
|
|
17
|
+
return async (method, path, { body, query, bytes, } = {}) => {
|
|
18
18
|
const address = new URL(`${base}${path}`);
|
|
19
19
|
for (const [name, value] of Object.entries(query ?? {}))
|
|
20
20
|
if (value !== undefined)
|
|
@@ -23,10 +23,14 @@ export const httpOf = ({ url, key, fetch: send = (request) => fetch(request) })
|
|
|
23
23
|
method,
|
|
24
24
|
headers: {
|
|
25
25
|
accept: 'application/hal+json, application/json',
|
|
26
|
-
...(
|
|
26
|
+
...(bytes
|
|
27
|
+
? { 'content-type': bytes.type }
|
|
28
|
+
: body === undefined
|
|
29
|
+
? {}
|
|
30
|
+
: { 'content-type': 'application/json' }),
|
|
27
31
|
...(key ? { authorization: `Bearer ${key}` } : {}),
|
|
28
32
|
},
|
|
29
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
33
|
+
...(bytes ? { body: bytes.data } : body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
30
34
|
}));
|
|
31
35
|
if (response.status === 204)
|
|
32
36
|
return undefined;
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceR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G,CAAC,KAAK;oBACP,CAAC,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,IAAI,EAAE;oBAChC,CAAC,CAAC,IAAI,KAAK,SAAS;wBAClB,CAAC,CAAC,EAAE;wBACJ,CAAC,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;gBAC7C,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACnD;YACD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;SAC7F,CAAC,CACH,CAAA;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,SAAc,CAAA;QAClD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAA6B,CAAC,CAAC,CAAC,EAAE,CAAA;QACtE,IAAI,CAAC,QAAQ,CAAC,EAAE;YACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAA;QACjH,OAAO,IAAS,CAAA;IAClB,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -147,8 +147,59 @@ export interface Machine {
|
|
|
147
147
|
export interface TemplateCard {
|
|
148
148
|
name: string;
|
|
149
149
|
status: 'building' | 'ready' | 'failed';
|
|
150
|
+
image: string | null;
|
|
151
|
+
dockerfile: string | null;
|
|
150
152
|
distro: string | null;
|
|
153
|
+
/** The machines it starts: a template is built for one runtime. */
|
|
154
|
+
runtime: 'container' | 'wasm';
|
|
155
|
+
memoryMiB: number | null;
|
|
151
156
|
error: string | null;
|
|
157
|
+
/** One of Loaner's own (TEMPLATES_BUILTIN), such as `node`: every key can use it. */
|
|
158
|
+
builtin: boolean;
|
|
159
|
+
}
|
|
160
|
+
/** A deployment's card: where it is, and where it is up to. */
|
|
161
|
+
export interface DeploymentCard {
|
|
162
|
+
name: string;
|
|
163
|
+
kind: 'preview' | 'app';
|
|
164
|
+
/** `waiting` for its upload, `building`, `ready` (served at `url`), or `failed` (`step` and `error` say why). */
|
|
165
|
+
status: 'waiting' | 'building' | 'ready' | 'failed';
|
|
166
|
+
step: string | null;
|
|
167
|
+
error: string | null;
|
|
168
|
+
framework: string | null;
|
|
169
|
+
url: string | null;
|
|
170
|
+
machine: string | null;
|
|
171
|
+
port: number | null;
|
|
172
|
+
/** Its environment's names: the values are never shown. */
|
|
173
|
+
env: string[];
|
|
174
|
+
ttlMinutes: number | null;
|
|
175
|
+
/** The memory its machine has, for its build and its app. */
|
|
176
|
+
memoryMiB: number;
|
|
177
|
+
[field: string]: unknown;
|
|
178
|
+
}
|
|
179
|
+
export interface DeploymentOptions {
|
|
180
|
+
name: string;
|
|
181
|
+
/** `preview` (the default) stops after `ttlMinutes` idle; `app` keeps running until deleted. */
|
|
182
|
+
kind?: 'preview' | 'app';
|
|
183
|
+
/** Environment for its build and start; PORT and HOST are set for it. */
|
|
184
|
+
env?: Record<string, string>;
|
|
185
|
+
ttlMinutes?: number;
|
|
186
|
+
/** Its machine's memory, for a build that needs more than the server's default (2048). */
|
|
187
|
+
memoryMiB?: number;
|
|
188
|
+
}
|
|
189
|
+
/** A part of a deployment's log: the command that wrote it, how it is going, and its last lines. */
|
|
190
|
+
export interface LogPart {
|
|
191
|
+
command: string;
|
|
192
|
+
state: string;
|
|
193
|
+
exitCode: number | null;
|
|
194
|
+
endReason: string | null;
|
|
195
|
+
lines: string;
|
|
196
|
+
nextOffset: number;
|
|
197
|
+
[field: string]: unknown;
|
|
198
|
+
}
|
|
199
|
+
/** A deployment that ended `failed`: its card says at which step, and `error` why. */
|
|
200
|
+
export declare class DeploymentFailed extends Error {
|
|
201
|
+
readonly card: DeploymentCard;
|
|
202
|
+
constructor(card: DeploymentCard);
|
|
152
203
|
}
|
|
153
204
|
export declare const loanerClient: (options: ClientOptions) => {
|
|
154
205
|
/** A new machine, running and ready for commands. */
|
|
@@ -156,17 +207,60 @@ export declare const loanerClient: (options: ClientOptions) => {
|
|
|
156
207
|
/** A machine you made earlier. */
|
|
157
208
|
get: (id: string) => Promise<Machine>;
|
|
158
209
|
/** Your machines, the newest first (`labels`: `{ task: 'fix' }`). */
|
|
159
|
-
list: ({ status, labels, name }?: {
|
|
210
|
+
list: ({ status, labels, name, }?: {
|
|
160
211
|
status?: string;
|
|
161
212
|
labels?: Record<string, string>;
|
|
162
213
|
name?: string;
|
|
163
214
|
}) => Promise<Machine[]>;
|
|
215
|
+
/** Apps put online in one call: built, started and kept at a URL of their name. */
|
|
216
|
+
deployments: {
|
|
217
|
+
/** Deploys from git or a machine's folder, or (`upload: true`) waits for `upload`; answers at once. */
|
|
218
|
+
create: (deployment: DeploymentOptions & {
|
|
219
|
+
git?: {
|
|
220
|
+
url: string;
|
|
221
|
+
ref?: string;
|
|
222
|
+
path?: string;
|
|
223
|
+
token?: string;
|
|
224
|
+
};
|
|
225
|
+
machine?: {
|
|
226
|
+
id: string;
|
|
227
|
+
path?: string;
|
|
228
|
+
};
|
|
229
|
+
upload?: boolean;
|
|
230
|
+
}) => Promise<DeploymentCard>;
|
|
231
|
+
/** Sends a tar.gz of the app's folder (its files at the top) to a deployment made with `upload: true`. */
|
|
232
|
+
upload: (name: string, archive: Uint8Array<ArrayBuffer>) => Promise<DeploymentCard>;
|
|
233
|
+
get: (name: string) => Promise<DeploymentCard>;
|
|
234
|
+
wait: (name: string) => Promise<DeploymentCard>;
|
|
235
|
+
list: () => Promise<DeploymentCard[]>;
|
|
236
|
+
/** Its build log and its running app's log, apart (`of`), with the last `lines` of each. */
|
|
237
|
+
logs: (name: string, { of, lines }?: {
|
|
238
|
+
of?: 'all' | 'build' | 'app';
|
|
239
|
+
lines?: number;
|
|
240
|
+
}) => Promise<{
|
|
241
|
+
build: (LogPart & {
|
|
242
|
+
step: string;
|
|
243
|
+
})[];
|
|
244
|
+
app: LogPart | null;
|
|
245
|
+
}>;
|
|
246
|
+
/** Takes it down: its URL stops answering and its machine stops. */
|
|
247
|
+
delete: (name: string) => Promise<unknown>;
|
|
248
|
+
/**
|
|
249
|
+
* Deploys a folder on this computer (Node only): packs it (what git keeps, never `.env` files), uploads it, and
|
|
250
|
+
* waits until it is ready (its card, with `url`) or failed (throws `DeploymentFailed`).
|
|
251
|
+
*/
|
|
252
|
+
deploy: (folder: string, deployment: DeploymentOptions) => Promise<DeploymentCard>;
|
|
253
|
+
};
|
|
164
254
|
templates: {
|
|
165
255
|
/** Builds a template from an image or a Dockerfile, and waits until it is ready (or throws why it failed). */
|
|
166
256
|
create: (template: {
|
|
167
257
|
name: string;
|
|
168
258
|
image?: string;
|
|
169
259
|
dockerfile?: string;
|
|
260
|
+
/** `wasm` builds a Dockerfile FROM debian or alpine (RUN and ENV only) for wasm machines. */
|
|
261
|
+
runtime?: 'container' | 'wasm';
|
|
262
|
+
/** A wasm machine's disk lives in its memory: give a big install room. */
|
|
263
|
+
memoryMiB?: number;
|
|
170
264
|
}) => Promise<TemplateCard>;
|
|
171
265
|
list: () => Promise<TemplateCard[]>;
|
|
172
266
|
delete: (name: string) => Promise<unknown>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAU,KAAK,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