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/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kyora
|
|
4
|
+
Copyright (c) 2026 Tembo
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# starfold (TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A client for agents and scripts driving a starfold desktop: screenshots, waiting for the
|
|
4
|
+
screen, mouse and keyboard, recordings and files. Node 20+, Bun and Deno; no dependencies.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install starfold # or: bun add starfold, pnpm add starfold, deno add npm:starfold
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { Starfold, act } from 'starfold';
|
|
12
|
+
|
|
13
|
+
// password defaults to $STARFOLD_PASSWORD
|
|
14
|
+
const sf = new Starfold('http://localhost:6901', { password: '...' });
|
|
15
|
+
|
|
16
|
+
const shot = await sf.screenshot(); // shot.png (Uint8Array), shot.seq, shot.size
|
|
17
|
+
await shot.save('before.png');
|
|
18
|
+
|
|
19
|
+
await sf.click(400, 300);
|
|
20
|
+
const r = await sf.typeText('hello\n');
|
|
21
|
+
await sf.wait({ change: true, since: r.seq }); // resolves once the typing changed the screen
|
|
22
|
+
await sf.wait({ idleMs: 300 }); // and once it settled
|
|
23
|
+
|
|
24
|
+
await sf.key('ctrl+shift+t');
|
|
25
|
+
await sf.scroll(0, 3, 400, 300);
|
|
26
|
+
await sf.drag(100, 100, 400, 100);
|
|
27
|
+
await sf.actions([
|
|
28
|
+
act.key('ctrl+l'),
|
|
29
|
+
act.typeText('example.com'),
|
|
30
|
+
act.key('Enter'),
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
const clips = await sf.record(5); // MP4s: one, or more if the encoder changed mid-recording
|
|
34
|
+
await sf.filesUpload('data.csv', 'local/data.csv');
|
|
35
|
+
console.log((await sf.filesList()).entries.map((e) => e.name));
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The calls are the Python SDK's in camelCase, each returning a Promise; `wait()` takes its
|
|
39
|
+
options as an object (`idleMs`, `timeoutMs`, `change`, `region`, `since`). `timeoutMs` in the
|
|
40
|
+
constructor (default 30000) applies per request; waits and recordings get their own length on
|
|
41
|
+
top. `filesUpload()` takes bytes, a Blob or a local file's path.
|
|
42
|
+
|
|
43
|
+
Errors: `AuthError` (wrong or missing password), `ReadOnlyError` (the server runs with
|
|
44
|
+
`--read-only`), `RecordingOffError` (without `--enable-recording`), `ForbiddenError`,
|
|
45
|
+
`NotFoundError`, `StarfoldTimeoutError`, `StarfoldConnectionError`, all `StarfoldError`, with
|
|
46
|
+
`message` and `status`. `wait()` reports a timeout in its result (`timedOut`) rather than
|
|
47
|
+
throwing.
|
|
48
|
+
|
|
49
|
+
Keys for `key()` are a single character or a name (Enter, Tab, Escape, BackSpace, Delete,
|
|
50
|
+
Home, End, PageUp, PageDown, Up, Down, Left, Right, F1-F24, ...), joined with `+` after
|
|
51
|
+
modifiers (ctrl, shift, alt, altgr, super). With shift, a letter or a US-layout digit or
|
|
52
|
+
punctuation key means the shifted key: `ctrl+shift+t`, `cmd+shift+4`.
|
|
53
|
+
|
|
54
|
+
## The server, from the same install
|
|
55
|
+
|
|
56
|
+
On Linux x64 and arm64 (glibc), macOS arm64 and Windows x64, `npm install starfold` also
|
|
57
|
+
installs the starfold server binary, from the optional dependency
|
|
58
|
+
`@starfold/server-<platform>` that matches the machine. On other platforms it installs the
|
|
59
|
+
client alone, which works against a server running elsewhere.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { startServer } from 'starfold';
|
|
63
|
+
|
|
64
|
+
await using server = await startServer(); // loopback, a free port, a generated password
|
|
65
|
+
const sf = server.client(); // signed in already
|
|
66
|
+
await (await sf.screenshot()).save('desktop.png');
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`startServer()` listens on 127.0.0.1 unless you pass `addr`; `port` (default: a free one,
|
|
70
|
+
tried again if another process takes it first), `password` (default, and when empty: a
|
|
71
|
+
generated one), `args` (more server flags, `starfold --help`; with `--base-path` the `url`
|
|
72
|
+
includes it), `env` (added to this process's environment), `binary` and `timeoutMs` (until it
|
|
73
|
+
answers, default 30000) are optional. It resolves to a `LocalServer` with `url`, `password`,
|
|
74
|
+
`process`, `client()`, `output()` (the last of what the server printed) and `close()`; the
|
|
75
|
+
server stops on `close()`, at the end of an `await using` block, when your process exits, and
|
|
76
|
+
on Linux and macOS also when your process is killed. If the server exits, doesn't answer in
|
|
77
|
+
time or finds its port taken, `startServer()` throws a `ServerStartError` whose `output` is
|
|
78
|
+
what the server printed. On Linux it needs a display (`DISPLAY`, e.g. from Xvfb); it doesn't
|
|
79
|
+
start one.
|
|
80
|
+
|
|
81
|
+
`binaryPath()` is the binary: `$STARFOLD_BIN` if set, else the platform package's; without
|
|
82
|
+
one it throws a `BinaryNotFoundError`. The `starfold` command runs it (`npx starfold --help`).
|
|
83
|
+
These errors, and `MissingLibrariesError` below, are `StarfoldError`s too.
|
|
84
|
+
|
|
85
|
+
On Linux the server uses the system's libyuv, Opus and PulseAudio libraries and needs glibc
|
|
86
|
+
2.39 or newer (Ubuntu 24.04 or newer):
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
sudo apt install libyuv0 libopus0 libpulse0
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Without them, or on an older glibc, `startServer()` (a `MissingLibrariesError`) and
|
|
93
|
+
`starfold` name what is missing, the libraries or the glibc version (`GLIBC_2.39`), with
|
|
94
|
+
that line.
|
|
95
|
+
|
|
96
|
+
## Tests
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
bun run test # unit tests, no server
|
|
100
|
+
bun run build && STARFOLD_BIN=../../target/release/starfold node test/integration.mjs # Linux, Xvfb + xterm
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The integration test also runs under `bun` and `deno run -A`.
|
package/bin/starfold.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs the starfold server binary with this command's arguments and passes its exit code through.
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { binaryPath, checkLibraries } from '../dist/native.js';
|
|
5
|
+
|
|
6
|
+
let bin;
|
|
7
|
+
try {
|
|
8
|
+
bin = binaryPath();
|
|
9
|
+
checkLibraries(bin);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
console.error(`starfold: ${e instanceof Error ? e.message : e}`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
16
|
+
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
17
|
+
// Each is passed on. A terminal's Ctrl-C reaches the server twice (the process group, and this);
|
|
18
|
+
// the server shuts down on the first and ignores the second.
|
|
19
|
+
const forward = (signal) => {
|
|
20
|
+
child.kill(signal);
|
|
21
|
+
};
|
|
22
|
+
if (process.platform !== 'win32') {
|
|
23
|
+
for (const s of signals) process.on(s, forward);
|
|
24
|
+
}
|
|
25
|
+
child.on('error', (e) => {
|
|
26
|
+
console.error(`starfold: ${bin}: ${e.message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
});
|
|
29
|
+
child.on('exit', (code, signal) => {
|
|
30
|
+
for (const s of signals) process.off(s, forward);
|
|
31
|
+
if (signal) {
|
|
32
|
+
process.kill(process.pid, signal);
|
|
33
|
+
} else {
|
|
34
|
+
process.exit(code ?? 1);
|
|
35
|
+
}
|
|
36
|
+
});
|
package/dist/act.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Builders for `Starfold.actions()`: each returns one action of `POST /input`. */
|
|
2
|
+
export type Button = 'left' | 'middle' | 'right' | (string & {}) | number;
|
|
3
|
+
export type Action = {
|
|
4
|
+
type: 'move';
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'click';
|
|
9
|
+
button: Button;
|
|
10
|
+
count: number;
|
|
11
|
+
x?: number;
|
|
12
|
+
y?: number;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'down' | 'up';
|
|
15
|
+
button: Button;
|
|
16
|
+
x?: number;
|
|
17
|
+
y?: number;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'scroll';
|
|
20
|
+
dx: number;
|
|
21
|
+
dy: number;
|
|
22
|
+
x?: number;
|
|
23
|
+
y?: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'key' | 'key_down' | 'key_up';
|
|
26
|
+
key: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'type';
|
|
29
|
+
text: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'pause';
|
|
32
|
+
ms: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function move(x: number, y: number): Action;
|
|
35
|
+
export declare function click(x?: number, y?: number, button?: Button, count?: number): Action;
|
|
36
|
+
export declare function down(x?: number, y?: number, button?: Button): Action;
|
|
37
|
+
export declare function up(x?: number, y?: number, button?: Button): Action;
|
|
38
|
+
/** Wheel notches: positive `dy` scrolls down, positive `dx` right. */
|
|
39
|
+
export declare function scroll(dx?: number, dy?: number, x?: number, y?: number): Action;
|
|
40
|
+
/** Press and release keys together: "Enter", "ctrl+c", "ctrl+shift+t", "alt+F4". */
|
|
41
|
+
export declare function key(combo: string): Action;
|
|
42
|
+
export declare function keyDown(combo: string): Action;
|
|
43
|
+
export declare function keyUp(combo: string): Action;
|
|
44
|
+
export declare function typeText(text: string): Action;
|
|
45
|
+
export declare function pause(ms: number): Action;
|
|
46
|
+
/** Press at (x1, y1), move to (x2, y2) in `steps` moves `stepMs` apart, release. */
|
|
47
|
+
export declare function drag(x1: number, y1: number, x2: number, y2: number, button?: Button, steps?: number, stepMs?: number): Action[];
|
package/dist/act.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Builders for `Starfold.actions()`: each returns one action of `POST /input`. */
|
|
2
|
+
function at(action, x, y) {
|
|
3
|
+
if ((x === undefined) !== (y === undefined)) {
|
|
4
|
+
throw new RangeError('give both x and y, or neither');
|
|
5
|
+
}
|
|
6
|
+
return x === undefined ? action : { ...action, x, y };
|
|
7
|
+
}
|
|
8
|
+
export function move(x, y) {
|
|
9
|
+
return { type: 'move', x, y };
|
|
10
|
+
}
|
|
11
|
+
export function click(x, y, button = 'left', count = 1) {
|
|
12
|
+
return at({ type: 'click', button, count }, x, y);
|
|
13
|
+
}
|
|
14
|
+
export function down(x, y, button = 'left') {
|
|
15
|
+
return at({ type: 'down', button }, x, y);
|
|
16
|
+
}
|
|
17
|
+
export function up(x, y, button = 'left') {
|
|
18
|
+
return at({ type: 'up', button }, x, y);
|
|
19
|
+
}
|
|
20
|
+
/** Wheel notches: positive `dy` scrolls down, positive `dx` right. */
|
|
21
|
+
export function scroll(dx = 0, dy = 0, x, y) {
|
|
22
|
+
return at({ type: 'scroll', dx, dy }, x, y);
|
|
23
|
+
}
|
|
24
|
+
/** Press and release keys together: "Enter", "ctrl+c", "ctrl+shift+t", "alt+F4". */
|
|
25
|
+
export function key(combo) {
|
|
26
|
+
return { type: 'key', key: combo };
|
|
27
|
+
}
|
|
28
|
+
export function keyDown(combo) {
|
|
29
|
+
return { type: 'key_down', key: combo };
|
|
30
|
+
}
|
|
31
|
+
export function keyUp(combo) {
|
|
32
|
+
return { type: 'key_up', key: combo };
|
|
33
|
+
}
|
|
34
|
+
export function typeText(text) {
|
|
35
|
+
return { type: 'type', text };
|
|
36
|
+
}
|
|
37
|
+
export function pause(ms) {
|
|
38
|
+
return { type: 'pause', ms };
|
|
39
|
+
}
|
|
40
|
+
/** Press at (x1, y1), move to (x2, y2) in `steps` moves `stepMs` apart, release. */
|
|
41
|
+
export function drag(x1, y1, x2, y2, button = 'left', steps = 10, stepMs = 10) {
|
|
42
|
+
const n = Math.max(1, steps);
|
|
43
|
+
const path = [down(x1, y1, button)];
|
|
44
|
+
for (let i = 1; i <= n; i++) {
|
|
45
|
+
path.push(pause(stepMs), move(x1 + Math.floor(((x2 - x1) * i) / n), y1 + Math.floor(((y2 - y1) * i) / n)));
|
|
46
|
+
}
|
|
47
|
+
path.push(up(undefined, undefined, button));
|
|
48
|
+
return path;
|
|
49
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Action, Button } from './act.js';
|
|
2
|
+
import { Screenshot } from './types.js';
|
|
3
|
+
import type { FileList, InputResult, Recording, Segments, Upload, WaitResult } from './types.js';
|
|
4
|
+
export declare const DEFAULT_URL = "http://localhost:6901";
|
|
5
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
6
|
+
export interface StarfoldOptions {
|
|
7
|
+
/** Defaults to $STARFOLD_PASSWORD. */
|
|
8
|
+
password?: string;
|
|
9
|
+
/** Per request; waits and recordings get their own length on top. */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
/** The fetch to use (default: the global one). */
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
}
|
|
14
|
+
export interface WaitOptions {
|
|
15
|
+
/** How long the screen has to stay still (the server's default: 300). */
|
|
16
|
+
idleMs?: number;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
/** Wait until the screen changes instead. */
|
|
19
|
+
change?: boolean;
|
|
20
|
+
/** [x, y, width, height] to watch instead of the whole screen. */
|
|
21
|
+
region?: [number, number, number, number];
|
|
22
|
+
/** A `seq` from a screenshot or an input: a change after it counts. */
|
|
23
|
+
since?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A starfold desktop, for agents: screenshots, waiting for the screen, mouse and keyboard.
|
|
27
|
+
*
|
|
28
|
+
* `password` defaults to $STARFOLD_PASSWORD. `timeoutMs` applies per request; waits and
|
|
29
|
+
* recordings get their own length on top.
|
|
30
|
+
*/
|
|
31
|
+
export declare class Starfold {
|
|
32
|
+
#private;
|
|
33
|
+
readonly url: string;
|
|
34
|
+
readonly timeoutMs: number;
|
|
35
|
+
constructor(url?: string, options?: StarfoldOptions);
|
|
36
|
+
/** Nothing to release (each request is its own); here so the client can be closed like the Python one. */
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
39
|
+
screenshot(): Promise<Screenshot>;
|
|
40
|
+
/** Until the screen stays still for `idleMs` (default 300), or with `change` until it changes. */
|
|
41
|
+
wait(options?: WaitOptions): Promise<WaitResult>;
|
|
42
|
+
/** Sends `act` actions in one request, applied in order. */
|
|
43
|
+
actions(actions: Iterable<Action | Action[]>): Promise<InputResult>;
|
|
44
|
+
move(x: number, y: number): Promise<InputResult>;
|
|
45
|
+
click(x?: number, y?: number, button?: Button, count?: number): Promise<InputResult>;
|
|
46
|
+
doubleClick(x?: number, y?: number, button?: Button): Promise<InputResult>;
|
|
47
|
+
mouseDown(x?: number, y?: number, button?: Button): Promise<InputResult>;
|
|
48
|
+
mouseUp(x?: number, y?: number, button?: Button): Promise<InputResult>;
|
|
49
|
+
drag(x1: number, y1: number, x2: number, y2: number, button?: Button, steps?: number, stepMs?: number): Promise<InputResult>;
|
|
50
|
+
scroll(dx?: number, dy?: number, x?: number, y?: number): Promise<InputResult>;
|
|
51
|
+
key(combo: string): Promise<InputResult>;
|
|
52
|
+
typeText(text: string): Promise<InputResult>;
|
|
53
|
+
/** An MP4 of the next `seconds`. */
|
|
54
|
+
record(seconds: number): Promise<Segments>;
|
|
55
|
+
recordStart(): Promise<Recording>;
|
|
56
|
+
recordStop(recording: Recording | string): Promise<Segments>;
|
|
57
|
+
filesList(path?: string): Promise<FileList>;
|
|
58
|
+
/** A file's bytes, or a folder as a zip. */
|
|
59
|
+
filesDownload(path: string): Promise<Uint8Array>;
|
|
60
|
+
/** Uploads `data` (bytes, a Blob, or a local file's path) as `name` into `path` (default: the upload folder). */
|
|
61
|
+
filesUpload(name: string, data: Uint8Array | ArrayBuffer | Blob | string | URL, path?: string, sub?: string): Promise<Upload>;
|
|
62
|
+
}
|