loaner-sdk 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +33 -2
- package/dist/http.d.ts +23 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +40 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +176 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Escalay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# loaner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TypeScript client for [Loaner](https://github.com/escalay/loaner): disposable Linux machines for AI agents, on
|
|
4
|
+
your own server.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install loaner-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { loanerClient } from 'loaner-sdk'
|
|
12
|
+
|
|
13
|
+
const machines = loanerClient({ url: 'https://loaner.example.com', key: process.env.LOANER_KEY })
|
|
14
|
+
|
|
15
|
+
await machines.templates.create({ name: 'py', image: 'python:3.13-slim' }) // once: waits until it is built
|
|
16
|
+
const machine = await machines.create({ template: 'py', network: { mode: 'allowlist', allow: ['pypi.org'] } })
|
|
17
|
+
|
|
18
|
+
const { ok, output } = await machine.run('python3 -c "print(6 * 7)"', { onOutput: (text) => process.stdout.write(text) })
|
|
19
|
+
await machine.files.write('~/app/main.py', 'print("hi")')
|
|
20
|
+
await machine.start('python3 -m http.server 8000', { timeoutSeconds: 0 })
|
|
21
|
+
await machine.ports.wait(8000)
|
|
22
|
+
const url = await machine.ports.share(8000) // anyone with it reaches the server
|
|
23
|
+
|
|
24
|
+
const copies = await machine.fork({ commands: ['pytest -k fix_a', 'pytest -k fix_b'] })
|
|
25
|
+
await machine.delete()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `run` follows a command however long it takes (the API's 202s and waits are handled), and returns every byte it
|
|
29
|
+
printed with its `exitCode`. `start` answers at once for servers and watchers (`wait`, `kill`, `send`).
|
|
30
|
+
- A refused call throws `LoanerError` with the API's `status`, `code` and `detail` (which says what to change).
|
|
31
|
+
- `fetch` in the options takes any fetch: tests pass an app's own (`apps/api/test/sdk.test.ts`).
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
It needs only `fetch` (Node 20 or newer). MIT licensed.
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The SDK's one way to call the API: JSON in, JSON out, a problem answer thrown as a `LoanerError`. */
|
|
2
|
+
export interface ClientOptions {
|
|
3
|
+
/** The API's address, e.g. `http://localhost:4400` or `https://machines.example.com`. */
|
|
4
|
+
url: string;
|
|
5
|
+
/** A key (ADMIN_KEY, or one made with POST /api/keys); none for a server with auth open. */
|
|
6
|
+
key?: string;
|
|
7
|
+
/** A `fetch` to call it with (default the global one): tests pass the app's own. */
|
|
8
|
+
fetch?: (request: Request) => Promise<Response> | Response;
|
|
9
|
+
}
|
|
10
|
+
/** An answer the API refused: its status, its problem `code`, and the `detail` that says what to change. */
|
|
11
|
+
export declare class LoanerError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly code: string;
|
|
14
|
+
readonly detail: string;
|
|
15
|
+
constructor(status: number, code: string, detail: string);
|
|
16
|
+
}
|
|
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 }?: {
|
|
19
|
+
body?: unknown;
|
|
20
|
+
query?: Query;
|
|
21
|
+
}) => Promise<T>;
|
|
22
|
+
export type Http = ReturnType<typeof httpOf>;
|
|
23
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAExG,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,UAAU,MAAM,QAAQ,MAAM,oBAAmB;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,eAsBlG,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAA"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The SDK's one way to call the API: JSON in, JSON out, a problem answer thrown as a `LoanerError`. */
|
|
2
|
+
/** An answer the API refused: its status, its problem `code`, and the `detail` that says what to change. */
|
|
3
|
+
export class LoanerError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
code;
|
|
6
|
+
detail;
|
|
7
|
+
constructor(status, code, detail) {
|
|
8
|
+
super(`${status} ${code}: ${detail}`);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.detail = detail;
|
|
12
|
+
this.name = 'LoanerError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const httpOf = ({ url, key, fetch: send = (request) => fetch(request) }) => {
|
|
16
|
+
const base = url.replace(/\/$/, '');
|
|
17
|
+
return async (method, path, { body, query } = {}) => {
|
|
18
|
+
const address = new URL(`${base}${path}`);
|
|
19
|
+
for (const [name, value] of Object.entries(query ?? {}))
|
|
20
|
+
if (value !== undefined)
|
|
21
|
+
address.searchParams.set(name, String(value));
|
|
22
|
+
const response = await send(new Request(address, {
|
|
23
|
+
method,
|
|
24
|
+
headers: {
|
|
25
|
+
accept: 'application/hal+json, application/json',
|
|
26
|
+
...(body === undefined ? {} : { 'content-type': 'application/json' }),
|
|
27
|
+
...(key ? { authorization: `Bearer ${key}` } : {}),
|
|
28
|
+
},
|
|
29
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
30
|
+
}));
|
|
31
|
+
if (response.status === 204)
|
|
32
|
+
return undefined;
|
|
33
|
+
const text = await response.text();
|
|
34
|
+
const json = text ? JSON.parse(text) : {};
|
|
35
|
+
if (!response.ok)
|
|
36
|
+
throw new LoanerError(response.status, String(json.code ?? 'error'), String(json.detail ?? json.title ?? text));
|
|
37
|
+
return json;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAWxG,4GAA4G;AAC5G,MAAM,OAAO,WAAY,SAAQ,KAAK;IAEzB,MAAM;IACN,IAAI;IACJ,MAAM;IAHjB,YACW,MAAc,EACd,IAAY,EACZ,MAAc;QAEvB,KAAK,CAAC,GAAG,MAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC,CAAA;sBAJ5B,MAAM;oBACN,IAAI;sBACJ,MAAM;QAGf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF;AAID,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAiB,EAAE,EAAE;IAC/F,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACnC,OAAO,KAAK,EAAK,MAAc,EAAE,IAAY,EAAE,EAAE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M,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
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A client for the Loaner: disposable Linux machines, from code.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const machines = loanerClient({ url: 'https://machines.example.com', key: process.env.MACHINES_KEY })
|
|
6
|
+
* const machine = await machines.create({ template: 'py' })
|
|
7
|
+
* const { exitCode, output } = await machine.run('python3 -c "print(6 * 7)"')
|
|
8
|
+
* await machine.files.write('~/app/main.py', 'print("hi")')
|
|
9
|
+
* const url = await machine.ports.share(8000)
|
|
10
|
+
* await machine.delete()
|
|
11
|
+
*/
|
|
12
|
+
import { type ClientOptions, type Http } from './http.js';
|
|
13
|
+
export { LoanerError, type ClientOptions } from './http.js';
|
|
14
|
+
export interface NetworkPolicy {
|
|
15
|
+
mode: 'open' | 'allowlist' | 'off';
|
|
16
|
+
allow?: string[];
|
|
17
|
+
deny?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface MachineOptions {
|
|
20
|
+
name?: string;
|
|
21
|
+
labels?: Record<string, string>;
|
|
22
|
+
/** A template (`machines.templates.create`) to start from: its tools installed already. */
|
|
23
|
+
template?: string;
|
|
24
|
+
runtime?: 'container' | 'wasm';
|
|
25
|
+
distro?: 'debian' | 'alpine';
|
|
26
|
+
memoryMiB?: number;
|
|
27
|
+
cpus?: number;
|
|
28
|
+
diskMiB?: number;
|
|
29
|
+
/** Minutes it may sit unused before it stops (default 120). */
|
|
30
|
+
ttlMinutes?: number;
|
|
31
|
+
network?: NetworkPolicy;
|
|
32
|
+
/** A snapshot's id to start a copy of. */
|
|
33
|
+
fromSnapshot?: string;
|
|
34
|
+
}
|
|
35
|
+
/** A machine's card, as the API answers it. */
|
|
36
|
+
export interface MachineCard {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string | null;
|
|
39
|
+
status: 'booting' | 'running' | 'stopped' | 'lost';
|
|
40
|
+
runtime: string;
|
|
41
|
+
distro: string;
|
|
42
|
+
template: string | null;
|
|
43
|
+
labels: Record<string, string>;
|
|
44
|
+
stopReason: string | null;
|
|
45
|
+
endReason: string | null;
|
|
46
|
+
[field: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
export interface RunOptions {
|
|
49
|
+
cwd?: string;
|
|
50
|
+
env?: Record<string, string>;
|
|
51
|
+
/** Text for its stdin, which then closes. */
|
|
52
|
+
stdin?: string;
|
|
53
|
+
/** Stop it after this long (default 600; 0 never, for a server). */
|
|
54
|
+
timeoutSeconds?: number;
|
|
55
|
+
/** Hears its output as it comes (stdout and stderr together, in order). */
|
|
56
|
+
onOutput?: (text: string) => void;
|
|
57
|
+
}
|
|
58
|
+
/** How a command ended, and everything it printed. */
|
|
59
|
+
export interface CommandResult {
|
|
60
|
+
id: string;
|
|
61
|
+
/** `exited` (see `exitCode`), `timed_out`, `killed`, `lost` or `not_started`. */
|
|
62
|
+
state: string;
|
|
63
|
+
exitCode: number | null;
|
|
64
|
+
output: string;
|
|
65
|
+
/** `exitCode` 0. */
|
|
66
|
+
ok: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** A running command: its id, and ways to follow, answer and stop it. */
|
|
69
|
+
declare const commandOf: (http: Http, id: string) => {
|
|
70
|
+
id: string;
|
|
71
|
+
wait: (onOutput?: (text: string) => void) => Promise<CommandResult>;
|
|
72
|
+
/** Types into its stdin (a command started with `interactive`). */
|
|
73
|
+
send: (data: string, { eof }?: {
|
|
74
|
+
eof?: boolean | undefined;
|
|
75
|
+
}) => Promise<unknown>;
|
|
76
|
+
/** Stops it and everything it started (TERM, then KILL if it hangs on). */
|
|
77
|
+
kill: (signal?: 'TERM' | 'KILL' | 'INT' | 'HUP') => Promise<unknown>;
|
|
78
|
+
};
|
|
79
|
+
export type Command = ReturnType<typeof commandOf>;
|
|
80
|
+
/** A machine: its card, and everything to do with it. */
|
|
81
|
+
export interface Machine {
|
|
82
|
+
id: string;
|
|
83
|
+
card: MachineCard;
|
|
84
|
+
run(cmd: string, options?: RunOptions): Promise<CommandResult>;
|
|
85
|
+
start(cmd: string, options?: Omit<RunOptions, 'onOutput'> & {
|
|
86
|
+
interactive?: boolean;
|
|
87
|
+
}): Promise<Command>;
|
|
88
|
+
script(script: string, options?: RunOptions & {
|
|
89
|
+
language?: 'bash' | 'sh' | 'python3' | 'node';
|
|
90
|
+
args?: string[];
|
|
91
|
+
failFast?: boolean;
|
|
92
|
+
}): Promise<CommandResult>;
|
|
93
|
+
files: {
|
|
94
|
+
read(path: string): Promise<string>;
|
|
95
|
+
write(path: string, content: string): Promise<unknown>;
|
|
96
|
+
writeMany(files: Record<string, string>): Promise<unknown>;
|
|
97
|
+
edit(path: string, edits: {
|
|
98
|
+
oldText: string;
|
|
99
|
+
newText: string;
|
|
100
|
+
replaceAll?: boolean;
|
|
101
|
+
}[]): Promise<unknown>;
|
|
102
|
+
list(path?: string): Promise<{
|
|
103
|
+
name: string;
|
|
104
|
+
type: string;
|
|
105
|
+
bytes: number;
|
|
106
|
+
}[]>;
|
|
107
|
+
search(pattern: string, options?: {
|
|
108
|
+
path?: string;
|
|
109
|
+
glob?: string;
|
|
110
|
+
}): Promise<{
|
|
111
|
+
path: string;
|
|
112
|
+
line: number;
|
|
113
|
+
text: string;
|
|
114
|
+
}[]>;
|
|
115
|
+
};
|
|
116
|
+
ports: {
|
|
117
|
+
wait(port: number, options?: {
|
|
118
|
+
seconds?: number;
|
|
119
|
+
}): Promise<boolean>;
|
|
120
|
+
share(port: number): Promise<string>;
|
|
121
|
+
unshare(port: number): Promise<unknown>;
|
|
122
|
+
fetch(port: number, path?: string, init?: {
|
|
123
|
+
method?: string;
|
|
124
|
+
headers?: Record<string, string>;
|
|
125
|
+
body?: string;
|
|
126
|
+
}): Promise<{
|
|
127
|
+
status: number;
|
|
128
|
+
headers: Record<string, string>;
|
|
129
|
+
body: string;
|
|
130
|
+
}>;
|
|
131
|
+
};
|
|
132
|
+
fork(options: {
|
|
133
|
+
count?: number;
|
|
134
|
+
commands?: string[];
|
|
135
|
+
name?: string;
|
|
136
|
+
cwd?: string;
|
|
137
|
+
}): Promise<{
|
|
138
|
+
machine: Machine;
|
|
139
|
+
result: CommandResult | undefined;
|
|
140
|
+
}[]>;
|
|
141
|
+
snapshot(name: string): Promise<string>;
|
|
142
|
+
setNetwork(network: NetworkPolicy): Promise<unknown>;
|
|
143
|
+
keepAlive(ttlMinutes: number): Promise<unknown>;
|
|
144
|
+
refresh(): Promise<MachineCard>;
|
|
145
|
+
delete(): Promise<unknown>;
|
|
146
|
+
}
|
|
147
|
+
export interface TemplateCard {
|
|
148
|
+
name: string;
|
|
149
|
+
status: 'building' | 'ready' | 'failed';
|
|
150
|
+
distro: string | null;
|
|
151
|
+
error: string | null;
|
|
152
|
+
}
|
|
153
|
+
export declare const loanerClient: (options: ClientOptions) => {
|
|
154
|
+
/** A new machine, running and ready for commands. */
|
|
155
|
+
create: (machine?: MachineOptions) => Promise<Machine>;
|
|
156
|
+
/** A machine you made earlier. */
|
|
157
|
+
get: (id: string) => Promise<Machine>;
|
|
158
|
+
/** Your machines, the newest first (`labels`: `{ task: 'fix' }`). */
|
|
159
|
+
list: ({ status, labels, name }?: {
|
|
160
|
+
status?: string;
|
|
161
|
+
labels?: Record<string, string>;
|
|
162
|
+
name?: string;
|
|
163
|
+
}) => Promise<Machine[]>;
|
|
164
|
+
templates: {
|
|
165
|
+
/** Builds a template from an image or a Dockerfile, and waits until it is ready (or throws why it failed). */
|
|
166
|
+
create: (template: {
|
|
167
|
+
name: string;
|
|
168
|
+
image?: string;
|
|
169
|
+
dockerfile?: string;
|
|
170
|
+
}) => Promise<TemplateCard>;
|
|
171
|
+
list: () => Promise<TemplateCard[]>;
|
|
172
|
+
delete: (name: string) => Promise<unknown>;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
export type LoanerClient = ReturnType<typeof loanerClient>;
|
|
176
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAA;AAEjE,OAAO,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAE3D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,KAAK,CAAA;IAClC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;IAC9B,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,SAAS,GAA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,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A client for the Loaner: disposable Linux machines, from code.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const machines = loanerClient({ url: 'https://machines.example.com', key: process.env.MACHINES_KEY })
|
|
6
|
+
* const machine = await machines.create({ template: 'py' })
|
|
7
|
+
* const { exitCode, output } = await machine.run('python3 -c "print(6 * 7)"')
|
|
8
|
+
* await machine.files.write('~/app/main.py', 'print("hi")')
|
|
9
|
+
* const url = await machine.ports.share(8000)
|
|
10
|
+
* await machine.delete()
|
|
11
|
+
*/
|
|
12
|
+
import { httpOf } from './http.js';
|
|
13
|
+
export { LoanerError } from './http.js';
|
|
14
|
+
const MACHINES = '/api/v1/machines';
|
|
15
|
+
const COMMANDS = '/api/v1/commands';
|
|
16
|
+
const quote = (value) => encodeURIComponent(value);
|
|
17
|
+
/** A running command: its id, and ways to follow, answer and stop it. */
|
|
18
|
+
const commandOf = (http, id) => {
|
|
19
|
+
/** Reads its output from `offset` until it ends, telling `onOutput` each piece; then how it ended. */
|
|
20
|
+
const wait = async (onOutput) => {
|
|
21
|
+
let offset = 0;
|
|
22
|
+
let output = '';
|
|
23
|
+
for (;;) {
|
|
24
|
+
const slice = await http('GET', `${COMMANDS}/${id}/output`, {
|
|
25
|
+
query: { offset, wait: 25 },
|
|
26
|
+
});
|
|
27
|
+
if (slice.text) {
|
|
28
|
+
output += slice.text;
|
|
29
|
+
onOutput?.(slice.text);
|
|
30
|
+
}
|
|
31
|
+
offset = slice.nextOffset;
|
|
32
|
+
if (slice.eof)
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
let card = await http('GET', `${COMMANDS}/${id}`);
|
|
36
|
+
while (card.status === 'running')
|
|
37
|
+
card = await http('GET', `${COMMANDS}/${id}`, { query: { wait: 25 } });
|
|
38
|
+
return { id, state: card.state, exitCode: card.exitCode, output, ok: card.exitCode === 0 };
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
id,
|
|
42
|
+
wait,
|
|
43
|
+
/** Types into its stdin (a command started with `interactive`). */
|
|
44
|
+
send: (data, { eof = false } = {}) => http('POST', `${COMMANDS}/${id}/input`, { body: { data, eof } }),
|
|
45
|
+
/** Stops it and everything it started (TERM, then KILL if it hangs on). */
|
|
46
|
+
kill: (signal = 'TERM') => http('POST', `${COMMANDS}/${id}/signal`, { body: { signal } }),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const machineOf = (http, card) => {
|
|
50
|
+
const at = `${MACHINES}/${quote(card.id)}`;
|
|
51
|
+
const start = async (cmd, options = {}) => {
|
|
52
|
+
const { id } = await http('POST', `${at}/commands`, { body: { cmd, wait: 0, ...options } });
|
|
53
|
+
return commandOf(http, id);
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
id: card.id,
|
|
57
|
+
card,
|
|
58
|
+
/** Runs a shell command (sh -c, as "user" in the home folder) and waits for it however long it takes. */
|
|
59
|
+
run: async (cmd, { onOutput, ...options } = {}) => (await start(cmd, options)).wait(onOutput),
|
|
60
|
+
/** Starts a command and answers at once: a server, a watcher, anything you follow or stop later. */
|
|
61
|
+
start,
|
|
62
|
+
/** Runs a whole script as one command, stopping at its first failing line unless `failFast` is false. */
|
|
63
|
+
script: async (script, { language, args, failFast, onOutput, ...options } = {}) => {
|
|
64
|
+
const { id } = await http('POST', `${at}/scripts`, {
|
|
65
|
+
body: { script, wait: 0, ...(language ? { language } : {}), ...(args ? { args } : {}), ...(failFast === undefined ? {} : { failFast }), ...options },
|
|
66
|
+
});
|
|
67
|
+
return commandOf(http, id).wait(onOutput);
|
|
68
|
+
},
|
|
69
|
+
files: {
|
|
70
|
+
read: async (path) => (await http('GET', `${at}/files`, { query: { path } })).content,
|
|
71
|
+
write: (path, content) => http('PUT', `${at}/files`, { query: { path }, body: { content } }),
|
|
72
|
+
/** Writes many files in one call: `{ '~/app/a.py': '…' }`. */
|
|
73
|
+
writeMany: (files) => http('POST', `${at}/files/batch`, {
|
|
74
|
+
body: { files: Object.entries(files).map(([path, content]) => ({ path, content })) },
|
|
75
|
+
}),
|
|
76
|
+
/** Replaces exact text, all edits or none (each `oldText` must appear exactly once). */
|
|
77
|
+
edit: (path, edits) => http('PATCH', `${at}/files`, { query: { path }, body: { edits } }),
|
|
78
|
+
list: async (path = '~') => (await http('GET', `${at}/dir`, { query: { path } }))
|
|
79
|
+
.entries,
|
|
80
|
+
search: async (pattern, { path = '~', glob } = {}) => (await http('GET', `${at}/search`, {
|
|
81
|
+
query: { path, pattern, glob },
|
|
82
|
+
})).matches,
|
|
83
|
+
},
|
|
84
|
+
ports: {
|
|
85
|
+
/** Waits (up to `seconds`, at most 25 per try) until something listens on `port`. */
|
|
86
|
+
wait: async (port, { seconds = 60 } = {}) => {
|
|
87
|
+
for (const until = Date.now() + seconds * 1000;;) {
|
|
88
|
+
const answer = await http('GET', `${at}/ports/${port}`, {
|
|
89
|
+
query: { wait: Math.min(25, Math.max(1, Math.ceil((until - Date.now()) / 1000))) },
|
|
90
|
+
});
|
|
91
|
+
if (answer.listening)
|
|
92
|
+
return true;
|
|
93
|
+
if (Date.now() >= until)
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
/** A public URL anyone can open for `port` (treat it like a password). */
|
|
98
|
+
share: async (port) => (await http('POST', `${at}/ports/${port}/share`)).url,
|
|
99
|
+
unshare: (port) => http('DELETE', `${at}/ports/${port}/share`),
|
|
100
|
+
/** An HTTP request to a server inside: its status, headers and body. */
|
|
101
|
+
fetch: (port, path = '/', init = {}) => http('POST', `${at}/ports/${port}/fetch`, {
|
|
102
|
+
body: { path, ...init },
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Copies it, as it is now: `count` copies, or one per command in `commands`, each run on its copy right away.
|
|
107
|
+
* Answers the copies (with their command's result when there was one).
|
|
108
|
+
*/
|
|
109
|
+
fork: async (options) => {
|
|
110
|
+
const answer = await http('POST', `${at}/fork`, { body: { ...options, ...(options.commands ? { wait: 25 } : {}) } });
|
|
111
|
+
return Promise.all(answer.forks.map(async (slot) => {
|
|
112
|
+
if (!slot.machine)
|
|
113
|
+
throw new Error(`a copy did not start: ${slot.problem?.detail ?? 'unknown'}`);
|
|
114
|
+
const machine = machineOf(http, slot.machine);
|
|
115
|
+
// Finished or not, its result is the whole story: every byte it printed and how it ended
|
|
116
|
+
const result = slot.command ? await commandOf(http, slot.command.id).wait() : undefined;
|
|
117
|
+
return { machine, result };
|
|
118
|
+
}));
|
|
119
|
+
},
|
|
120
|
+
/** Saves it as a snapshot that `create({ fromSnapshot })` starts copies of. */
|
|
121
|
+
snapshot: async (name) => (await http('POST', `${at}/snapshots`, { body: { name } })).id,
|
|
122
|
+
/** Changes what it may reach, from its next connection. */
|
|
123
|
+
setNetwork: (network) => http('PATCH', at, { body: { network } }),
|
|
124
|
+
/** Keeps it from stopping idle for `ttlMinutes` from now. */
|
|
125
|
+
keepAlive: (ttlMinutes) => http('PATCH', at, { body: { ttlMinutes } }),
|
|
126
|
+
refresh: () => http('GET', at),
|
|
127
|
+
/** Powers it off for good, with its files. */
|
|
128
|
+
delete: () => http('DELETE', at),
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export const loanerClient = (options) => {
|
|
132
|
+
const http = httpOf(options);
|
|
133
|
+
return {
|
|
134
|
+
/** A new machine, running and ready for commands. */
|
|
135
|
+
create: async (machine = {}) => machineOf(http, await http('POST', MACHINES, { body: machine })),
|
|
136
|
+
/** A machine you made earlier. */
|
|
137
|
+
get: async (id) => machineOf(http, await http('GET', `${MACHINES}/${quote(id)}`)),
|
|
138
|
+
/** Your machines, the newest first (`labels`: `{ task: 'fix' }`). */
|
|
139
|
+
list: async ({ status, labels, name } = {}) => {
|
|
140
|
+
const page = await http('GET', MACHINES, {
|
|
141
|
+
query: {
|
|
142
|
+
status,
|
|
143
|
+
name,
|
|
144
|
+
labels: labels
|
|
145
|
+
? Object.entries(labels)
|
|
146
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
147
|
+
.join(',')
|
|
148
|
+
: undefined,
|
|
149
|
+
limit: 100,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
return page._embedded.machines.map((card) => machineOf(http, card));
|
|
153
|
+
},
|
|
154
|
+
templates: {
|
|
155
|
+
/** Builds a template from an image or a Dockerfile, and waits until it is ready (or throws why it failed). */
|
|
156
|
+
create: async (template) => {
|
|
157
|
+
let card = await http('POST', '/api/v1/templates', { body: template });
|
|
158
|
+
while (card.status === 'building')
|
|
159
|
+
card = await http('GET', `/api/v1/templates/${quote(template.name)}`, { query: { wait: 25 } });
|
|
160
|
+
if (card.status === 'failed')
|
|
161
|
+
throw new Error(`template ${template.name} failed to build: ${card.error ?? ''}`);
|
|
162
|
+
return card;
|
|
163
|
+
},
|
|
164
|
+
list: async () => (await http('GET', '/api/v1/templates'))._embedded.templates,
|
|
165
|
+
delete: (name) => http('DELETE', `/api/v1/templates/${quote(name)}`),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAiC,MAAM,WAAW,CAAA;AAEjE,OAAO,EAAE,WAAW,EAAsB,MAAM,WAAW,CAAA;AAoE3D,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AACnC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AACnC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;AAE1D,yEAAyE;AACzE,MAAM,SAAS,GAAG,CAAC,IAAU,EAAE,EAAU,EAAE,EAAE;IAC3C,sGAAsG;IACtG,MAAM,IAAI,GAAG,KAAK,EAAE,QAAiC,EAA0B,EAAE;QAC/E,IAAI,MAAM,GA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AG,MAAM,IAAI,CAAe,KAAK,EAAE,qBAAqB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;gBAC9G,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ;oBAAE,MAAM,IAAI,KAAK,CAAC,YAAY,QAAQ,CAAC,IAAI,qBAAqB,IAAI,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,CAAA;gBAC/G,OAAO,IAAI,CAAA;YACb,CAAC;YACD,IAAI,EAAE,KAAK,IAAI,EAAE,CACf,CAAC,MAAM,IAAI,CAA+C,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS;YAC5G,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;SAC7E;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loaner-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for Loaner: disposable Linux machines for AI agents, on your own server",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"sandbox",
|
|
9
|
+
"ai-agents",
|
|
10
|
+
"mcp",
|
|
11
|
+
"linux",
|
|
12
|
+
"containers",
|
|
13
|
+
"e2b",
|
|
14
|
+
"self-hosted",
|
|
15
|
+
"loaner"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/escalay/loaner/tree/main/packages/sdk#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/escalay/loaner.git",
|
|
21
|
+
"directory": "packages/sdk"
|
|
22
|
+
},
|
|
23
|
+
"bugs": "https://github.com/escalay/loaner/issues",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"typecheck": "tsc -p .",
|
|
45
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json"
|
|
46
|
+
},
|
|
47
|
+
"types": "./dist/index.d.ts"
|
|
6
48
|
}
|