starfold 0.0.0-stage → 0.3.2
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 +22 -0
- package/README.md +102 -2
- package/bin/starfold.js +36 -0
- package/dist/act.d.ts +47 -0
- package/dist/act.js +49 -0
- package/dist/client.d.ts +62 -0
- package/dist/client.js +379 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/native.d.ts +76 -0
- package/dist/native.js +419 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.js +53 -0
- package/dist/zip.d.ts +2 -0
- package/dist/zip.js +53 -0
- package/package.json +42 -4
package/dist/client.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import * as act from './act.js';
|
|
2
|
+
import { AuthError, ForbiddenError, NotFoundError, ReadOnlyError, RecordingOffError, Screenshot, StarfoldConnectionError, StarfoldError, StarfoldTimeoutError, segments, } from './types.js';
|
|
3
|
+
import { unzip } from './zip.js';
|
|
4
|
+
Symbol.asyncDispose ??= Symbol.for('Symbol.asyncDispose');
|
|
5
|
+
export const DEFAULT_URL = 'http://localhost:6901';
|
|
6
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
|
+
function environment() {
|
|
8
|
+
const p = globalThis.process;
|
|
9
|
+
try {
|
|
10
|
+
return p?.env ?? {};
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function warn(message) {
|
|
17
|
+
const p = globalThis.process;
|
|
18
|
+
if (typeof p?.emitWarning === 'function') {
|
|
19
|
+
p.emitWarning(message, 'DeprecationWarning');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.warn(`DeprecationWarning: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function envPassword() {
|
|
26
|
+
const env = environment();
|
|
27
|
+
const fresh = env.STARFOLD_PASSWORD;
|
|
28
|
+
const old = env.VOXL_PASSWORD;
|
|
29
|
+
if (old !== undefined) {
|
|
30
|
+
warn(fresh !== undefined
|
|
31
|
+
? 'VOXL_PASSWORD is ignored: STARFOLD_PASSWORD is set'
|
|
32
|
+
: 'VOXL_PASSWORD is deprecated: use STARFOLD_PASSWORD');
|
|
33
|
+
}
|
|
34
|
+
return fresh ?? old;
|
|
35
|
+
}
|
|
36
|
+
async function errorFor(resp) {
|
|
37
|
+
const text = await resp.text();
|
|
38
|
+
let body = null;
|
|
39
|
+
let message;
|
|
40
|
+
try {
|
|
41
|
+
body = JSON.parse(text);
|
|
42
|
+
const e = body.error;
|
|
43
|
+
if (e === undefined) {
|
|
44
|
+
throw new Error('no error field');
|
|
45
|
+
}
|
|
46
|
+
message = String(e);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
body = null;
|
|
50
|
+
message = text.trim() || resp.statusText;
|
|
51
|
+
}
|
|
52
|
+
const code = resp.status;
|
|
53
|
+
const fields = body !== null && typeof body === 'object'
|
|
54
|
+
? body
|
|
55
|
+
: {};
|
|
56
|
+
if (code === 401) {
|
|
57
|
+
return new AuthError(message, code);
|
|
58
|
+
}
|
|
59
|
+
if (code === 403) {
|
|
60
|
+
if (fields.read_only === true) {
|
|
61
|
+
return new ReadOnlyError(message, code);
|
|
62
|
+
}
|
|
63
|
+
if (fields.recording === false) {
|
|
64
|
+
return new RecordingOffError(message, code);
|
|
65
|
+
}
|
|
66
|
+
return new ForbiddenError(message, code);
|
|
67
|
+
}
|
|
68
|
+
if (code === 404) {
|
|
69
|
+
return new NotFoundError(message, code);
|
|
70
|
+
}
|
|
71
|
+
return new StarfoldError(`${code}: ${message}`, code);
|
|
72
|
+
}
|
|
73
|
+
async function bytes(r) {
|
|
74
|
+
return new Uint8Array(await r.arrayBuffer());
|
|
75
|
+
}
|
|
76
|
+
async function json(r) {
|
|
77
|
+
return (await r.json());
|
|
78
|
+
}
|
|
79
|
+
function seqHeader(headers) {
|
|
80
|
+
const v = headers.get('x-starfold-seq') ?? headers.get('x-voxl-seq');
|
|
81
|
+
if (v === null) {
|
|
82
|
+
throw new StarfoldError('the screenshot came without its sequence number');
|
|
83
|
+
}
|
|
84
|
+
return Number.parseInt(v, 10);
|
|
85
|
+
}
|
|
86
|
+
async function parseSegments(r) {
|
|
87
|
+
const type = (r.headers.get('content-type') ?? '')
|
|
88
|
+
.split(';')[0]
|
|
89
|
+
.trim()
|
|
90
|
+
.toLowerCase();
|
|
91
|
+
const data = await bytes(r);
|
|
92
|
+
if (type !== 'application/zip') {
|
|
93
|
+
return segments([data]);
|
|
94
|
+
}
|
|
95
|
+
const members = await unzip(data);
|
|
96
|
+
const member = (name) => {
|
|
97
|
+
const m = members.get(name);
|
|
98
|
+
if (m === undefined) {
|
|
99
|
+
throw new StarfoldError(`the recording's zip lacks ${name}`);
|
|
100
|
+
}
|
|
101
|
+
return m;
|
|
102
|
+
};
|
|
103
|
+
const manifest = JSON.parse(new TextDecoder().decode(member('manifest.json')));
|
|
104
|
+
return segments(manifest.segments.map((s) => member(s.file)), manifest.end_reason);
|
|
105
|
+
}
|
|
106
|
+
function flatten(actions) {
|
|
107
|
+
const flat = [];
|
|
108
|
+
for (const a of actions) {
|
|
109
|
+
if (Array.isArray(a)) {
|
|
110
|
+
flat.push(...a);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
flat.push(a);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return flat;
|
|
117
|
+
}
|
|
118
|
+
function recordingId(recording) {
|
|
119
|
+
const id = typeof recording === 'object' && recording !== null
|
|
120
|
+
? recording.id
|
|
121
|
+
: recording;
|
|
122
|
+
if (typeof id !== 'string') {
|
|
123
|
+
const kind = id === null ? 'null' : typeof id;
|
|
124
|
+
throw new TypeError(`a recording id is a string (the Recording recordStart returned, or its .id), not ${kind}`);
|
|
125
|
+
}
|
|
126
|
+
return id;
|
|
127
|
+
}
|
|
128
|
+
async function readData(data) {
|
|
129
|
+
if (typeof data === 'string' || data instanceof URL) {
|
|
130
|
+
const { readFile } = await import('node:fs/promises');
|
|
131
|
+
return new Uint8Array(await readFile(data));
|
|
132
|
+
}
|
|
133
|
+
if (data instanceof ArrayBuffer) {
|
|
134
|
+
return new Uint8Array(data);
|
|
135
|
+
}
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A starfold desktop, for agents: screenshots, waiting for the screen, mouse and keyboard.
|
|
140
|
+
*
|
|
141
|
+
* `password` defaults to $STARFOLD_PASSWORD. `timeoutMs` applies per request; waits and
|
|
142
|
+
* recordings get their own length on top.
|
|
143
|
+
*/
|
|
144
|
+
export class Starfold {
|
|
145
|
+
url;
|
|
146
|
+
timeoutMs;
|
|
147
|
+
#headers;
|
|
148
|
+
#fetch;
|
|
149
|
+
constructor(url = DEFAULT_URL, options = {}) {
|
|
150
|
+
this.url = url.replace(/\/+$/, '');
|
|
151
|
+
const password = options.password !== undefined ? options.password : envPassword();
|
|
152
|
+
this.#headers = password ? { Authorization: `Bearer ${password}` } : {};
|
|
153
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
154
|
+
this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
155
|
+
}
|
|
156
|
+
/** Nothing to release (each request is its own); here so the client can be closed like the Python one. */
|
|
157
|
+
async close() { }
|
|
158
|
+
async [Symbol.asyncDispose]() {
|
|
159
|
+
await this.close();
|
|
160
|
+
}
|
|
161
|
+
async #do(req) {
|
|
162
|
+
const query = req.params
|
|
163
|
+
? `?${new URLSearchParams(Object.entries(req.params).map(([k, v]) => [k, String(v)]))}`
|
|
164
|
+
: '';
|
|
165
|
+
const headers = {
|
|
166
|
+
...this.#headers,
|
|
167
|
+
...req.headers,
|
|
168
|
+
};
|
|
169
|
+
let body = req.body;
|
|
170
|
+
if (req.json !== undefined) {
|
|
171
|
+
body = JSON.stringify(req.json);
|
|
172
|
+
headers['Content-Type'] = 'application/json';
|
|
173
|
+
}
|
|
174
|
+
const ms = this.timeoutMs + (req.extraMs ?? 0);
|
|
175
|
+
const abort = new AbortController();
|
|
176
|
+
const timer = setTimeout(() => abort.abort(), ms);
|
|
177
|
+
const late = () => new StarfoldTimeoutError(`no answer in time: ${ms} ms`);
|
|
178
|
+
try {
|
|
179
|
+
let resp;
|
|
180
|
+
try {
|
|
181
|
+
resp = await this.#fetch(`${this.url}${req.path}${query}`, {
|
|
182
|
+
method: req.method,
|
|
183
|
+
headers,
|
|
184
|
+
body: body,
|
|
185
|
+
signal: abort.signal,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
throw abort.signal.aborted
|
|
190
|
+
? late()
|
|
191
|
+
: new StarfoldConnectionError(`cannot reach the server: ${describe(e)}`);
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
if (!resp.ok) {
|
|
195
|
+
throw await errorFor(resp);
|
|
196
|
+
}
|
|
197
|
+
return await req.parse(resp);
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
throw abort.signal.aborted && !(e instanceof StarfoldError)
|
|
201
|
+
? late()
|
|
202
|
+
: e;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
clearTimeout(timer);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
screenshot() {
|
|
210
|
+
return this.#do({
|
|
211
|
+
method: 'GET',
|
|
212
|
+
path: '/screenshot',
|
|
213
|
+
parse: async (r) => new Screenshot(await bytes(r), seqHeader(r.headers)),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/** Until the screen stays still for `idleMs` (default 300), or with `change` until it changes. */
|
|
217
|
+
wait(options = {}) {
|
|
218
|
+
const params = {};
|
|
219
|
+
if (options.idleMs !== undefined)
|
|
220
|
+
params.idle = options.idleMs;
|
|
221
|
+
if (options.timeoutMs !== undefined)
|
|
222
|
+
params.timeout = options.timeoutMs;
|
|
223
|
+
if (options.change)
|
|
224
|
+
params.change = 1;
|
|
225
|
+
if (options.region !== undefined)
|
|
226
|
+
params.region = options.region.map((v) => Math.trunc(v)).join(',');
|
|
227
|
+
if (options.since !== undefined)
|
|
228
|
+
params.since = options.since;
|
|
229
|
+
return this.#do({
|
|
230
|
+
method: 'GET',
|
|
231
|
+
path: '/wait',
|
|
232
|
+
params,
|
|
233
|
+
extraMs: options.timeoutMs ?? 10_000,
|
|
234
|
+
parse: async (r) => {
|
|
235
|
+
const d = await json(r);
|
|
236
|
+
return {
|
|
237
|
+
changed: Boolean(d.changed),
|
|
238
|
+
timedOut: Boolean(d.timed_out),
|
|
239
|
+
seq: Number(d.seq),
|
|
240
|
+
waitedMs: Number(d.waited_ms),
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** Sends `act` actions in one request, applied in order. */
|
|
246
|
+
actions(actions) {
|
|
247
|
+
const flat = flatten(actions);
|
|
248
|
+
let extraMs = 0;
|
|
249
|
+
for (const a of flat) {
|
|
250
|
+
if (a.type === 'pause')
|
|
251
|
+
extraMs += a.ms;
|
|
252
|
+
// The answer comes once the input is done; a character the keymap lacks takes ~10 ms.
|
|
253
|
+
if (a.type === 'type')
|
|
254
|
+
extraMs += a.text.length * 10;
|
|
255
|
+
}
|
|
256
|
+
return this.#do({
|
|
257
|
+
method: 'POST',
|
|
258
|
+
path: '/input',
|
|
259
|
+
json: flat,
|
|
260
|
+
extraMs,
|
|
261
|
+
parse: async (r) => {
|
|
262
|
+
const d = await json(r);
|
|
263
|
+
return { seq: Number(d.seq), events: Number(d.events) };
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
move(x, y) {
|
|
268
|
+
return this.actions([act.move(x, y)]);
|
|
269
|
+
}
|
|
270
|
+
click(x, y, button = 'left', count = 1) {
|
|
271
|
+
return this.actions([act.click(x, y, button, count)]);
|
|
272
|
+
}
|
|
273
|
+
doubleClick(x, y, button = 'left') {
|
|
274
|
+
return this.actions([act.click(x, y, button, 2)]);
|
|
275
|
+
}
|
|
276
|
+
mouseDown(x, y, button = 'left') {
|
|
277
|
+
return this.actions([act.down(x, y, button)]);
|
|
278
|
+
}
|
|
279
|
+
mouseUp(x, y, button = 'left') {
|
|
280
|
+
return this.actions([act.up(x, y, button)]);
|
|
281
|
+
}
|
|
282
|
+
drag(x1, y1, x2, y2, button = 'left', steps = 10, stepMs = 10) {
|
|
283
|
+
return this.actions(act.drag(x1, y1, x2, y2, button, steps, stepMs));
|
|
284
|
+
}
|
|
285
|
+
scroll(dx = 0, dy = 0, x, y) {
|
|
286
|
+
return this.actions([act.scroll(dx, dy, x, y)]);
|
|
287
|
+
}
|
|
288
|
+
key(combo) {
|
|
289
|
+
return this.actions([act.key(combo)]);
|
|
290
|
+
}
|
|
291
|
+
typeText(text) {
|
|
292
|
+
return this.actions([act.typeText(text)]);
|
|
293
|
+
}
|
|
294
|
+
/** An MP4 of the next `seconds`. */
|
|
295
|
+
record(seconds) {
|
|
296
|
+
return this.#do({
|
|
297
|
+
method: 'GET',
|
|
298
|
+
path: '/record',
|
|
299
|
+
params: { seconds, format: 'zip' },
|
|
300
|
+
extraMs: seconds * 1000,
|
|
301
|
+
parse: parseSegments,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
recordStart() {
|
|
305
|
+
return this.#do({
|
|
306
|
+
method: 'POST',
|
|
307
|
+
path: '/record/start',
|
|
308
|
+
parse: async (r) => {
|
|
309
|
+
const d = await json(r);
|
|
310
|
+
return { id: String(d.id), maxSeconds: Number(d.max_seconds) };
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async recordStop(recording) {
|
|
315
|
+
const id = recordingId(recording);
|
|
316
|
+
return this.#do({
|
|
317
|
+
method: 'POST',
|
|
318
|
+
path: '/record/stop',
|
|
319
|
+
params: { id, format: 'zip' },
|
|
320
|
+
parse: parseSegments,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
filesList(path = '') {
|
|
324
|
+
return this.#do({
|
|
325
|
+
method: 'GET',
|
|
326
|
+
path: '/files/list',
|
|
327
|
+
params: { path },
|
|
328
|
+
parse: async (r) => {
|
|
329
|
+
const d = (await r.json());
|
|
330
|
+
return {
|
|
331
|
+
path: d.path,
|
|
332
|
+
entries: d.entries.map((e) => ({
|
|
333
|
+
name: e.name,
|
|
334
|
+
dir: Boolean(e.dir),
|
|
335
|
+
size: Number(e.size),
|
|
336
|
+
mtimeMs: Number(e.mtime),
|
|
337
|
+
})),
|
|
338
|
+
};
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/** A file's bytes, or a folder as a zip. */
|
|
343
|
+
filesDownload(path) {
|
|
344
|
+
return this.#do({
|
|
345
|
+
method: 'GET',
|
|
346
|
+
path: '/files/download',
|
|
347
|
+
params: { path },
|
|
348
|
+
parse: bytes,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/** Uploads `data` (bytes, a Blob, or a local file's path) as `name` into `path` (default: the upload folder). */
|
|
352
|
+
async filesUpload(name, data, path, sub) {
|
|
353
|
+
const params = { name };
|
|
354
|
+
if (path !== undefined)
|
|
355
|
+
params.path = path;
|
|
356
|
+
if (sub !== undefined)
|
|
357
|
+
params.sub = sub;
|
|
358
|
+
return this.#do({
|
|
359
|
+
method: 'PUT',
|
|
360
|
+
path: '/files/upload',
|
|
361
|
+
params,
|
|
362
|
+
body: await readData(data),
|
|
363
|
+
headers: { 'X-Starfold-Upload': '1', 'X-Voxl-Upload': '1' },
|
|
364
|
+
parse: async (r) => {
|
|
365
|
+
const d = await json(r);
|
|
366
|
+
return { path: String(d.path), size: Number(d.size) };
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function describe(e) {
|
|
372
|
+
if (e instanceof Error) {
|
|
373
|
+
const cause = e.cause;
|
|
374
|
+
return cause instanceof Error
|
|
375
|
+
? `${e.message} (${cause.message})`
|
|
376
|
+
: e.message;
|
|
377
|
+
}
|
|
378
|
+
return String(e);
|
|
379
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Drive a starfold desktop: screenshots, waiting for the screen, mouse and keyboard. */
|
|
2
|
+
export * as act from './act.js';
|
|
3
|
+
export type { Action, Button } from './act.js';
|
|
4
|
+
export { DEFAULT_TIMEOUT_MS, DEFAULT_URL, Starfold } from './client.js';
|
|
5
|
+
export type { StarfoldOptions, WaitOptions } from './client.js';
|
|
6
|
+
export { AuthError, ForbiddenError, NotFoundError, ReadOnlyError, RecordingOffError, Screenshot, StarfoldConnectionError, StarfoldError, StarfoldTimeoutError, } from './types.js';
|
|
7
|
+
export type { FileEntry, FileList, InputResult, Recording, Segments, Upload, WaitResult, } from './types.js';
|
|
8
|
+
export { BinaryNotFoundError, LINUX_LIBRARIES_HINT, LocalServer, MissingLibrariesError, ServerStartError, binaryPath, checkLibraries, missingLibraries, platformKey, serverPackage, startServer, } from './native.js';
|
|
9
|
+
export type { StartServerOptions } from './native.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Drive a starfold desktop: screenshots, waiting for the screen, mouse and keyboard. */
|
|
2
|
+
export * as act from './act.js';
|
|
3
|
+
export { DEFAULT_TIMEOUT_MS, DEFAULT_URL, Starfold } from './client.js';
|
|
4
|
+
export { AuthError, ForbiddenError, NotFoundError, ReadOnlyError, RecordingOffError, Screenshot, StarfoldConnectionError, StarfoldError, StarfoldTimeoutError, } from './types.js';
|
|
5
|
+
export { BinaryNotFoundError, LINUX_LIBRARIES_HINT, LocalServer, MissingLibrariesError, ServerStartError, binaryPath, checkLibraries, missingLibraries, platformKey, serverPackage, startServer, } from './native.js';
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ChildProcess } from 'node:child_process';
|
|
2
|
+
import { Starfold } from './client.js';
|
|
3
|
+
import type { StarfoldOptions } from './client.js';
|
|
4
|
+
import { StarfoldError } from './types.js';
|
|
5
|
+
/** The apt line for the shared libraries the Linux binary links. */
|
|
6
|
+
export declare const LINUX_LIBRARIES_HINT = "sudo apt install libyuv0 libopus0 libpulse0 (glibc 2.39+, Ubuntu 24.04 or newer)";
|
|
7
|
+
/** No server binary: $STARFOLD_BIN isn't set (or isn't a file) and no platform package has one. */
|
|
8
|
+
export declare class BinaryNotFoundError extends StarfoldError {
|
|
9
|
+
}
|
|
10
|
+
/** The shared libraries the server binary needs don't all resolve on this Linux system. */
|
|
11
|
+
export declare class MissingLibrariesError extends StarfoldError {
|
|
12
|
+
readonly missing: string[];
|
|
13
|
+
constructor(missing: string[]);
|
|
14
|
+
}
|
|
15
|
+
/** startServer failed: the server exited, didn't answer in time, or its port was taken. */
|
|
16
|
+
export declare class ServerStartError extends StarfoldError {
|
|
17
|
+
/** The last of what the server printed. */
|
|
18
|
+
readonly output: string;
|
|
19
|
+
constructor(message: string, output: string);
|
|
20
|
+
}
|
|
21
|
+
/** The platform's key in the server packages' names, such as linux-x64-gnu. */
|
|
22
|
+
export declare function platformKey(): string;
|
|
23
|
+
/** The server package for this platform, or null if there is none. */
|
|
24
|
+
export declare function serverPackage(key?: string): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The server binary: $STARFOLD_BIN if set, else the one in this platform's
|
|
27
|
+
* @starfold/server-* package. Throws a BinaryNotFoundError if neither is there; the client
|
|
28
|
+
* still works against a remote server without it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function binaryPath(): string;
|
|
31
|
+
/**
|
|
32
|
+
* On Linux, what `binary` needs and the system lacks, by ldd: the shared libraries that don't
|
|
33
|
+
* resolve and the glibc versions that are too new (GLIBC_2.39, say); elsewhere nothing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function missingLibraries(binary: string): string[];
|
|
36
|
+
/** Throws a MissingLibrariesError naming what `binary` lacks (Linux only). */
|
|
37
|
+
export declare function checkLibraries(binary: string): void;
|
|
38
|
+
export interface StartServerOptions {
|
|
39
|
+
/** The address to bind (default 127.0.0.1, loopback only). */
|
|
40
|
+
addr?: string;
|
|
41
|
+
/** The port (default: a free one, tried again if another process takes it first). */
|
|
42
|
+
port?: number;
|
|
43
|
+
/** The password (default, and when empty: a generated one, which `client()` holds). */
|
|
44
|
+
password?: string;
|
|
45
|
+
/** More server flags, such as --enable-recording or --base-path. */
|
|
46
|
+
args?: string[];
|
|
47
|
+
/** Environment for the server, on top of this process's (DISPLAY, for one). */
|
|
48
|
+
env?: Record<string, string>;
|
|
49
|
+
/** The binary (default: binaryPath()). */
|
|
50
|
+
binary?: string;
|
|
51
|
+
/** How long to wait for the server to answer (default 30000). */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
}
|
|
54
|
+
/** A server this process started: `client()` is signed in; `close()` stops it. */
|
|
55
|
+
export declare class LocalServer {
|
|
56
|
+
#private;
|
|
57
|
+
readonly url: string;
|
|
58
|
+
readonly password: string;
|
|
59
|
+
/** The child process (on Linux and macOS a small sh guard whose child is the server). */
|
|
60
|
+
readonly process: ChildProcess;
|
|
61
|
+
constructor(url: string, password: string, child: ChildProcess, exited: Promise<void>, output: () => string);
|
|
62
|
+
/** A client for this server, already holding its password. */
|
|
63
|
+
client(options?: Omit<StarfoldOptions, 'password'>): Starfold;
|
|
64
|
+
/** The last of what the server printed. */
|
|
65
|
+
output(): string;
|
|
66
|
+
/** Stops the server and waits for it to exit. */
|
|
67
|
+
close(): Promise<void>;
|
|
68
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Starts the server and resolves once it answers. It binds to loopback with a generated
|
|
72
|
+
* password unless told otherwise, and stops when this process exits. On Linux it needs an
|
|
73
|
+
* X display ($DISPLAY, Xvfb for one); it does not start one. Every failure to start is a
|
|
74
|
+
* ServerStartError carrying what the server printed.
|
|
75
|
+
*/
|
|
76
|
+
export declare function startServer(options?: StartServerOptions): Promise<LocalServer>;
|