@rome-os/node-core 0.1.8 → 0.1.10
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 +4 -5
- package/dist/actions.d.ts +2 -1
- package/dist/actions.js +3 -3
- package/dist/audit.d.ts +6 -0
- package/dist/audit.js +11 -0
- package/dist/cloud.js +1 -2
- package/dist/computer-use/audit-fields.d.ts +5 -0
- package/dist/computer-use/audit-fields.js +17 -0
- package/dist/computer-use/bridge.d.ts +53 -0
- package/dist/computer-use/bridge.js +361 -0
- package/dist/computer-use/discovery.d.ts +14 -0
- package/dist/computer-use/discovery.js +117 -0
- package/dist/computer-use/frames.d.ts +9 -0
- package/dist/computer-use/frames.js +100 -0
- package/dist/computer-use/host.d.ts +90 -0
- package/dist/computer-use/host.js +765 -0
- package/dist/computer-use/launch.d.ts +55 -0
- package/dist/computer-use/launch.js +375 -0
- package/dist/computer-use/protocol.d.ts +238 -0
- package/dist/computer-use/protocol.js +441 -0
- package/dist/connect.d.ts +7 -0
- package/dist/connect.js +6 -1
- package/dist/daemon-client.js +1 -1
- package/dist/daemon.js +15 -3
- package/dist/devices-status.d.ts +1 -1
- package/dist/devices-status.js +2 -5
- package/dist/executor.d.ts +2 -1
- package/dist/executor.js +124 -134
- package/dist/host-connection.js +3 -3
- package/dist/host.d.ts +4 -1
- package/dist/host.js +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type JsonObject } from "./protocol.js";
|
|
2
|
+
export declare function encodeFrame(message: JsonObject, binary?: Buffer): Buffer;
|
|
3
|
+
export declare class FrameDecoder {
|
|
4
|
+
#private;
|
|
5
|
+
private readonly receiveMetadata;
|
|
6
|
+
constructor(receiveMetadata: (message: JsonObject) => (binary: Buffer) => void);
|
|
7
|
+
push(chunk: Buffer): void;
|
|
8
|
+
finish(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { checkPng, ComputerUseError, isObject, JSON_LIMIT, PNG_LIMIT, screenshotFor, } from "./protocol.js";
|
|
2
|
+
const HEADER_BYTES = 8;
|
|
3
|
+
const EMPTY = Buffer.alloc(0);
|
|
4
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
5
|
+
function checkLengths(json, binary) {
|
|
6
|
+
if (json === 0 || json > JSON_LIMIT || binary > PNG_LIMIT) {
|
|
7
|
+
throw new ComputerUseError("frame_limit");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function encodeFrame(message, binary = EMPTY) {
|
|
11
|
+
if (!isObject(message))
|
|
12
|
+
throw new ComputerUseError("invalid_frame");
|
|
13
|
+
const json = Buffer.from(JSON.stringify(message));
|
|
14
|
+
checkLengths(json.length, binary.length);
|
|
15
|
+
const screenshot = screenshotFor(message, binary.length);
|
|
16
|
+
if (screenshot)
|
|
17
|
+
checkPng(binary, screenshot);
|
|
18
|
+
const header = Buffer.allocUnsafe(HEADER_BYTES);
|
|
19
|
+
header.writeUInt32BE(json.length, 0);
|
|
20
|
+
header.writeUInt32BE(binary.length, 4);
|
|
21
|
+
return Buffer.concat([header, json, binary]);
|
|
22
|
+
}
|
|
23
|
+
function decodeJson(bytes) {
|
|
24
|
+
let message;
|
|
25
|
+
try {
|
|
26
|
+
message = JSON.parse(utf8.decode(bytes));
|
|
27
|
+
}
|
|
28
|
+
catch (cause) {
|
|
29
|
+
throw new ComputerUseError("invalid_frame", { cause });
|
|
30
|
+
}
|
|
31
|
+
if (!isObject(message))
|
|
32
|
+
throw new ComputerUseError("invalid_frame");
|
|
33
|
+
return message;
|
|
34
|
+
}
|
|
35
|
+
export class FrameDecoder {
|
|
36
|
+
receiveMetadata;
|
|
37
|
+
#header = Buffer.allocUnsafe(HEADER_BYTES);
|
|
38
|
+
#part = this.#header;
|
|
39
|
+
#offset = 0;
|
|
40
|
+
#read = this.#readHeader;
|
|
41
|
+
#failure;
|
|
42
|
+
constructor(receiveMetadata) {
|
|
43
|
+
this.receiveMetadata = receiveMetadata;
|
|
44
|
+
}
|
|
45
|
+
push(chunk) {
|
|
46
|
+
if (this.#failure)
|
|
47
|
+
throw this.#failure;
|
|
48
|
+
try {
|
|
49
|
+
let offset = 0;
|
|
50
|
+
while (offset < chunk.length) {
|
|
51
|
+
const size = Math.min(this.#part.length - this.#offset, chunk.length - offset);
|
|
52
|
+
chunk.copy(this.#part, this.#offset, offset, offset + size);
|
|
53
|
+
offset += size;
|
|
54
|
+
this.#offset += size;
|
|
55
|
+
if (this.#offset === this.#part.length)
|
|
56
|
+
this.#read(this.#part);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (cause) {
|
|
60
|
+
this.#failure =
|
|
61
|
+
cause instanceof ComputerUseError
|
|
62
|
+
? cause
|
|
63
|
+
: new ComputerUseError("invalid_frame", { cause });
|
|
64
|
+
throw this.#failure;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
finish() {
|
|
68
|
+
if (this.#failure)
|
|
69
|
+
throw this.#failure;
|
|
70
|
+
if (this.#part !== this.#header || this.#offset !== 0) {
|
|
71
|
+
this.#failure = new ComputerUseError("invalid_frame");
|
|
72
|
+
throw this.#failure;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
#next(part, read) {
|
|
76
|
+
this.#part = part;
|
|
77
|
+
this.#offset = 0;
|
|
78
|
+
this.#read = read;
|
|
79
|
+
}
|
|
80
|
+
#readHeader(header) {
|
|
81
|
+
const jsonLength = header.readUInt32BE(0);
|
|
82
|
+
const binaryLength = header.readUInt32BE(4);
|
|
83
|
+
checkLengths(jsonLength, binaryLength);
|
|
84
|
+
this.#next(Buffer.allocUnsafe(jsonLength), (json) => {
|
|
85
|
+
const message = decodeJson(json);
|
|
86
|
+
const screenshot = screenshotFor(message, binaryLength);
|
|
87
|
+
const receive = this.receiveMetadata(message);
|
|
88
|
+
if (!screenshot) {
|
|
89
|
+
this.#next(this.#header, this.#readHeader);
|
|
90
|
+
receive(EMPTY);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.#next(Buffer.allocUnsafe(binaryLength), (binary) => {
|
|
94
|
+
checkPng(binary, screenshot);
|
|
95
|
+
this.#next(this.#header, this.#readHeader);
|
|
96
|
+
receive(binary);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type ActionResponse, type BinaryActionResult } from "../actions.js";
|
|
2
|
+
import { ComputerUseBridge } from "./bridge.js";
|
|
3
|
+
import { discoverHelper } from "./discovery.js";
|
|
4
|
+
import { type HelperPermissionCache, probeHelperPermissions } from "./launch.js";
|
|
5
|
+
type Bridge = Pick<ComputerUseBridge, "initialAccess" | "accessStatus" | "openPermissionGuide" | "instanceId" | "helperPid" | "closed" | "windows" | "bind" | "unbind" | "observe" | "act" | "cancel" | "status" | "close" | "onDisconnect" | "onCancelRequested">;
|
|
6
|
+
export type EnsureComputerUseHelper = (options?: {
|
|
7
|
+
force?: boolean;
|
|
8
|
+
}) => Promise<boolean>;
|
|
9
|
+
export interface HelperOptions {
|
|
10
|
+
computerUseLocale?: () => string | undefined;
|
|
11
|
+
ensureHelper?: EnsureComputerUseHelper;
|
|
12
|
+
strictBundledAppPath?: boolean;
|
|
13
|
+
permissionCache?: HelperPermissionCache;
|
|
14
|
+
}
|
|
15
|
+
interface HostDeps extends HelperOptions {
|
|
16
|
+
bundledAppPath?: string;
|
|
17
|
+
discover: typeof discoverHelper;
|
|
18
|
+
probePermissions: typeof probeHelperPermissions;
|
|
19
|
+
launch: (options: Parameters<typeof ComputerUseBridge.launch>[0]) => Promise<Bridge>;
|
|
20
|
+
consentTtlMs: number;
|
|
21
|
+
permissionTtlMs: number;
|
|
22
|
+
terminalTtlMs: number;
|
|
23
|
+
sessionTtlMs: number;
|
|
24
|
+
now: () => number;
|
|
25
|
+
isProcessAlive: (pid: number) => boolean;
|
|
26
|
+
stopPollMs: number;
|
|
27
|
+
}
|
|
28
|
+
interface PreparedOperation {
|
|
29
|
+
run(refusal?: ActionResponse): Promise<BinaryActionResult>;
|
|
30
|
+
release(): void;
|
|
31
|
+
}
|
|
32
|
+
export declare class ComputerUseHost {
|
|
33
|
+
private readonly sessions;
|
|
34
|
+
private readonly history;
|
|
35
|
+
private readonly windows;
|
|
36
|
+
private readonly deps;
|
|
37
|
+
private readonly permissionCache;
|
|
38
|
+
private discovering?;
|
|
39
|
+
private ensuring?;
|
|
40
|
+
constructor(deps?: Partial<HostDeps>);
|
|
41
|
+
private readonly operations;
|
|
42
|
+
info(peer: string): Promise<{
|
|
43
|
+
capability: {
|
|
44
|
+
id: string;
|
|
45
|
+
prefix: string;
|
|
46
|
+
title: string;
|
|
47
|
+
state: string;
|
|
48
|
+
personal: boolean;
|
|
49
|
+
actions: string[];
|
|
50
|
+
};
|
|
51
|
+
actions: string[];
|
|
52
|
+
usage: {
|
|
53
|
+
[k: string]: string;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
prepare(action: string, peer: string, args: unknown, body?: Uint8Array): PreparedOperation | undefined;
|
|
57
|
+
disconnect(): void;
|
|
58
|
+
private reserve;
|
|
59
|
+
private findHelper;
|
|
60
|
+
private ensureReady;
|
|
61
|
+
private resolveHelper;
|
|
62
|
+
private requireSession;
|
|
63
|
+
private check;
|
|
64
|
+
private work;
|
|
65
|
+
private snapshot;
|
|
66
|
+
private refusal;
|
|
67
|
+
private deadline;
|
|
68
|
+
private expiry;
|
|
69
|
+
private expire;
|
|
70
|
+
private start;
|
|
71
|
+
private current;
|
|
72
|
+
private updateAccess;
|
|
73
|
+
private failed;
|
|
74
|
+
private bind;
|
|
75
|
+
private bound;
|
|
76
|
+
private changeBinding;
|
|
77
|
+
private cancel;
|
|
78
|
+
private seal;
|
|
79
|
+
private scheduleStopCleanup;
|
|
80
|
+
private stopHelper;
|
|
81
|
+
private confirmStop;
|
|
82
|
+
private finishStop;
|
|
83
|
+
private watchHelperExit;
|
|
84
|
+
private releaseBinding;
|
|
85
|
+
private releaseWindows;
|
|
86
|
+
private outcome;
|
|
87
|
+
private record;
|
|
88
|
+
private remove;
|
|
89
|
+
}
|
|
90
|
+
export {};
|