@rivet-dev/agentos-runtime-core 0.0.0-agent-acp-codex-session-benchmark.62b1f46
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 +7 -0
- package/commands/[ +0 -0
- package/commands/_stubs +0 -0
- package/commands/arch +0 -0
- package/commands/awk +0 -0
- package/commands/b2sum +0 -0
- package/commands/base32 +0 -0
- package/commands/base64 +0 -0
- package/commands/basename +0 -0
- package/commands/basenc +0 -0
- package/commands/bash +0 -0
- package/commands/cat +0 -0
- package/commands/chcon +0 -0
- package/commands/chgrp +0 -0
- package/commands/chmod +0 -0
- package/commands/chown +0 -0
- package/commands/chroot +0 -0
- package/commands/cksum +0 -0
- package/commands/codex +0 -0
- package/commands/codex-exec +0 -0
- package/commands/column +0 -0
- package/commands/comm +0 -0
- package/commands/cp +0 -0
- package/commands/curl +0 -0
- package/commands/cut +0 -0
- package/commands/date +0 -0
- package/commands/dd +0 -0
- package/commands/df +0 -0
- package/commands/diff +0 -0
- package/commands/dir +0 -0
- package/commands/dircolors +0 -0
- package/commands/dirname +0 -0
- package/commands/du +0 -0
- package/commands/echo +0 -0
- package/commands/egrep +0 -0
- package/commands/env +0 -0
- package/commands/envsubst +0 -0
- package/commands/expand +0 -0
- package/commands/expr +0 -0
- package/commands/factor +0 -0
- package/commands/false +0 -0
- package/commands/fd +0 -0
- package/commands/fgrep +0 -0
- package/commands/file +0 -0
- package/commands/find +0 -0
- package/commands/fmt +0 -0
- package/commands/fold +0 -0
- package/commands/git +0 -0
- package/commands/git-remote-http +0 -0
- package/commands/git-remote-https +0 -0
- package/commands/grep +0 -0
- package/commands/groups +0 -0
- package/commands/gunzip +0 -0
- package/commands/gzip +0 -0
- package/commands/head +0 -0
- package/commands/hostid +0 -0
- package/commands/hostname +0 -0
- package/commands/http-test +0 -0
- package/commands/http_get +0 -0
- package/commands/id +0 -0
- package/commands/install +0 -0
- package/commands/join +0 -0
- package/commands/jq +0 -0
- package/commands/kill +0 -0
- package/commands/link +0 -0
- package/commands/ln +0 -0
- package/commands/logname +0 -0
- package/commands/ls +0 -0
- package/commands/md5sum +0 -0
- package/commands/mkdir +0 -0
- package/commands/mkfifo +0 -0
- package/commands/mknod +0 -0
- package/commands/mktemp +0 -0
- package/commands/more +0 -0
- package/commands/mv +0 -0
- package/commands/nice +0 -0
- package/commands/nl +0 -0
- package/commands/nohup +0 -0
- package/commands/nproc +0 -0
- package/commands/numfmt +0 -0
- package/commands/od +0 -0
- package/commands/paste +0 -0
- package/commands/pathchk +0 -0
- package/commands/pinky +0 -0
- package/commands/printenv +0 -0
- package/commands/printf +0 -0
- package/commands/ptx +0 -0
- package/commands/pwd +0 -0
- package/commands/readlink +0 -0
- package/commands/realpath +0 -0
- package/commands/rev +0 -0
- package/commands/rg +0 -0
- package/commands/rm +0 -0
- package/commands/rmdir +0 -0
- package/commands/runcon +0 -0
- package/commands/sed +0 -0
- package/commands/seq +0 -0
- package/commands/sh +0 -0
- package/commands/sha1sum +0 -0
- package/commands/sha224sum +0 -0
- package/commands/sha256sum +0 -0
- package/commands/sha384sum +0 -0
- package/commands/sha512sum +0 -0
- package/commands/shred +0 -0
- package/commands/shuf +0 -0
- package/commands/sleep +0 -0
- package/commands/sort +0 -0
- package/commands/spawn-test-host +0 -0
- package/commands/split +0 -0
- package/commands/sqlite3 +0 -0
- package/commands/stat +0 -0
- package/commands/stdbuf +0 -0
- package/commands/strings +0 -0
- package/commands/stty +0 -0
- package/commands/sum +0 -0
- package/commands/sync +0 -0
- package/commands/tac +0 -0
- package/commands/tail +0 -0
- package/commands/tar +0 -0
- package/commands/tee +0 -0
- package/commands/test +0 -0
- package/commands/timeout +0 -0
- package/commands/touch +0 -0
- package/commands/tr +0 -0
- package/commands/tree +0 -0
- package/commands/true +0 -0
- package/commands/truncate +0 -0
- package/commands/tsort +0 -0
- package/commands/tty +0 -0
- package/commands/uname +0 -0
- package/commands/unexpand +0 -0
- package/commands/uniq +0 -0
- package/commands/unlink +0 -0
- package/commands/unzip +0 -0
- package/commands/uptime +0 -0
- package/commands/users +0 -0
- package/commands/vdir +0 -0
- package/commands/wc +0 -0
- package/commands/which +0 -0
- package/commands/who +0 -0
- package/commands/whoami +0 -0
- package/commands/xargs +0 -0
- package/commands/xu +0 -0
- package/commands/yes +0 -0
- package/commands/yq +0 -0
- package/commands/zcat +0 -0
- package/commands/zip +0 -0
- package/dist/binary.d.ts +4 -0
- package/dist/binary.js +25 -0
- package/dist/bytes.d.ts +2 -0
- package/dist/bytes.js +6 -0
- package/dist/callbacks.d.ts +41 -0
- package/dist/callbacks.js +94 -0
- package/dist/correlation.d.ts +7 -0
- package/dist/correlation.js +52 -0
- package/dist/descriptors.d.ts +81 -0
- package/dist/descriptors.js +57 -0
- package/dist/event-buffer.d.ts +98 -0
- package/dist/event-buffer.js +333 -0
- package/dist/ext.d.ts +7 -0
- package/dist/ext.js +13 -0
- package/dist/filesystem.d.ts +33 -0
- package/dist/filesystem.js +52 -0
- package/dist/frame-payload-codec.d.ts +8 -0
- package/dist/frame-payload-codec.js +14 -0
- package/dist/frame-rpc.d.ts +45 -0
- package/dist/frame-rpc.js +98 -0
- package/dist/frame-stream.d.ts +34 -0
- package/dist/frame-stream.js +109 -0
- package/dist/framing.d.ts +8 -0
- package/dist/framing.js +23 -0
- package/dist/generated/AcpLimitsConfig.d.ts +4 -0
- package/dist/generated/AcpLimitsConfig.js +2 -0
- package/dist/generated/CreateVmConfig.d.ts +26 -0
- package/dist/generated/CreateVmConfig.js +1 -0
- package/dist/generated/FsPermissionRule.d.ts +6 -0
- package/dist/generated/FsPermissionRule.js +1 -0
- package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
- package/dist/generated/FsPermissionRuleSet.js +1 -0
- package/dist/generated/FsPermissionScope.d.ts +3 -0
- package/dist/generated/FsPermissionScope.js +1 -0
- package/dist/generated/HttpLimitsConfig.d.ts +3 -0
- package/dist/generated/HttpLimitsConfig.js +2 -0
- package/dist/generated/JsModuleResolution.d.ts +1 -0
- package/dist/generated/JsModuleResolution.js +2 -0
- package/dist/generated/JsRuntimeConfig.d.ts +31 -0
- package/dist/generated/JsRuntimeConfig.js +1 -0
- package/dist/generated/JsRuntimeLimitsConfig.d.ts +8 -0
- package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
- package/dist/generated/JsRuntimePlatform.d.ts +1 -0
- package/dist/generated/JsRuntimePlatform.js +2 -0
- package/dist/generated/MountPluginDescriptor.d.ts +4 -0
- package/dist/generated/MountPluginDescriptor.js +2 -0
- package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
- package/dist/generated/NativeRootFilesystemConfig.js +1 -0
- package/dist/generated/PatternPermissionRule.d.ts +6 -0
- package/dist/generated/PatternPermissionRule.js +1 -0
- package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
- package/dist/generated/PatternPermissionRuleSet.js +1 -0
- package/dist/generated/PatternPermissionScope.d.ts +3 -0
- package/dist/generated/PatternPermissionScope.js +1 -0
- package/dist/generated/PermissionMode.d.ts +1 -0
- package/dist/generated/PermissionMode.js +2 -0
- package/dist/generated/PermissionsPolicy.d.ts +10 -0
- package/dist/generated/PermissionsPolicy.js +1 -0
- package/dist/generated/PluginLimitsConfig.d.ts +4 -0
- package/dist/generated/PluginLimitsConfig.js +2 -0
- package/dist/generated/PythonLimitsConfig.d.ts +6 -0
- package/dist/generated/PythonLimitsConfig.js +2 -0
- package/dist/generated/ResourceLimitsConfig.d.ts +24 -0
- package/dist/generated/ResourceLimitsConfig.js +2 -0
- package/dist/generated/RootFilesystemConfig.d.ts +9 -0
- package/dist/generated/RootFilesystemConfig.js +1 -0
- package/dist/generated/RootFilesystemEntry.d.ts +13 -0
- package/dist/generated/RootFilesystemEntry.js +1 -0
- package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
- package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
- package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
- package/dist/generated/RootFilesystemEntryKind.js +2 -0
- package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
- package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
- package/dist/generated/RootFilesystemMode.d.ts +1 -0
- package/dist/generated/RootFilesystemMode.js +2 -0
- package/dist/generated/ToolLimitsConfig.d.ts +10 -0
- package/dist/generated/ToolLimitsConfig.js +2 -0
- package/dist/generated/VmDnsConfig.d.ts +6 -0
- package/dist/generated/VmDnsConfig.js +2 -0
- package/dist/generated/VmLimitsConfig.d.ts +18 -0
- package/dist/generated/VmLimitsConfig.js +1 -0
- package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
- package/dist/generated/VmListenPolicyConfig.js +2 -0
- package/dist/generated/WasmLimitsConfig.d.ts +7 -0
- package/dist/generated/WasmLimitsConfig.js +2 -0
- package/dist/generated-protocol.d.ts +1452 -0
- package/dist/generated-protocol.js +3936 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +20 -0
- package/dist/native-client.d.ts +47 -0
- package/dist/native-client.js +136 -0
- package/dist/numbers.d.ts +1 -0
- package/dist/numbers.js +8 -0
- package/dist/ownership.d.ts +18 -0
- package/dist/ownership.js +77 -0
- package/dist/permissions.d.ts +29 -0
- package/dist/permissions.js +68 -0
- package/dist/process.d.ts +22 -0
- package/dist/process.js +97 -0
- package/dist/protocol-client.d.ts +67 -0
- package/dist/protocol-client.js +270 -0
- package/dist/protocol-frames.d.ts +68 -0
- package/dist/protocol-frames.js +139 -0
- package/dist/protocol-maps.d.ts +31 -0
- package/dist/protocol-maps.js +273 -0
- package/dist/protocol-schema.d.ts +10 -0
- package/dist/protocol-schema.js +11 -0
- package/dist/request-payloads.d.ts +207 -0
- package/dist/request-payloads.js +357 -0
- package/dist/response-payloads.d.ts +268 -0
- package/dist/response-payloads.js +402 -0
- package/dist/sidecar-client.d.ts +19 -0
- package/dist/sidecar-client.js +1 -0
- package/dist/sidecar-errors.d.ts +44 -0
- package/dist/sidecar-errors.js +62 -0
- package/dist/sidecar-process.d.ts +434 -0
- package/dist/sidecar-process.js +1252 -0
- package/dist/state.d.ts +42 -0
- package/dist/state.js +45 -0
- package/dist/vm-config.d.ts +31 -0
- package/dist/vm-config.js +1 -0
- package/package.json +189 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { fromGeneratedRootFilesystemEntryEncoding, fromGeneratedRootFilesystemEntryKind, toGeneratedRootFilesystemEntryEncoding, toGeneratedRootFilesystemEntryKind, } from "./protocol-maps.js";
|
|
2
|
+
export function encodeGuestFilesystemContent(content) {
|
|
3
|
+
if (typeof content === "string") {
|
|
4
|
+
return { content };
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
content: Buffer.from(content).toString("base64"),
|
|
8
|
+
encoding: "base64",
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function decodeGuestFilesystemContent(response) {
|
|
12
|
+
if (response.content === undefined) {
|
|
13
|
+
throw new Error(`sidecar returned no file content for ${response.path}`);
|
|
14
|
+
}
|
|
15
|
+
if (response.encoding === undefined) {
|
|
16
|
+
throw new Error(`sidecar returned no file encoding for ${response.path}`);
|
|
17
|
+
}
|
|
18
|
+
if (response.encoding === "base64") {
|
|
19
|
+
return Buffer.from(response.content, "base64");
|
|
20
|
+
}
|
|
21
|
+
return Buffer.from(response.content, "utf8");
|
|
22
|
+
}
|
|
23
|
+
export function toGeneratedRootFilesystemEntry(entry) {
|
|
24
|
+
return {
|
|
25
|
+
path: entry.path,
|
|
26
|
+
kind: toGeneratedRootFilesystemEntryKind(entry.kind),
|
|
27
|
+
mode: entry.mode ?? null,
|
|
28
|
+
uid: entry.uid ?? null,
|
|
29
|
+
gid: entry.gid ?? null,
|
|
30
|
+
content: entry.content ?? null,
|
|
31
|
+
encoding: entry.encoding === undefined
|
|
32
|
+
? null
|
|
33
|
+
: toGeneratedRootFilesystemEntryEncoding(entry.encoding),
|
|
34
|
+
target: entry.target ?? null,
|
|
35
|
+
executable: entry.executable ?? false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function fromGeneratedRootFilesystemEntry(entry) {
|
|
39
|
+
return {
|
|
40
|
+
path: entry.path,
|
|
41
|
+
kind: fromGeneratedRootFilesystemEntryKind(entry.kind),
|
|
42
|
+
...(entry.mode !== null ? { mode: entry.mode } : {}),
|
|
43
|
+
...(entry.uid !== null ? { uid: entry.uid } : {}),
|
|
44
|
+
...(entry.gid !== null ? { gid: entry.gid } : {}),
|
|
45
|
+
...(entry.content !== null ? { content: entry.content } : {}),
|
|
46
|
+
...(entry.encoding !== null
|
|
47
|
+
? { encoding: fromGeneratedRootFilesystemEntryEncoding(entry.encoding) }
|
|
48
|
+
: {}),
|
|
49
|
+
...(entry.target !== null ? { target: entry.target } : {}),
|
|
50
|
+
executable: entry.executable,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type TransportPayloadCodec = "bare" | "json";
|
|
2
|
+
export declare function encodeJsonFramePayload(frame: unknown): Uint8Array;
|
|
3
|
+
export declare function decodeJsonFramePayload<TFrame extends {
|
|
4
|
+
payload?: {
|
|
5
|
+
type?: string;
|
|
6
|
+
chunk?: unknown;
|
|
7
|
+
};
|
|
8
|
+
}>(payload: Uint8Array): TFrame;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function encodeJsonFramePayload(frame) {
|
|
2
|
+
// BARE `data` fields are Uint8Array; JSON.stringify renders those as objects, so encode them
|
|
3
|
+
// as number arrays to match serde_json's Vec<u8> representation on the Rust side.
|
|
4
|
+
return new TextEncoder().encode(JSON.stringify(frame, (_key, value) => value instanceof Uint8Array ? Array.from(value) : value));
|
|
5
|
+
}
|
|
6
|
+
export function decodeJsonFramePayload(payload) {
|
|
7
|
+
const frame = JSON.parse(new TextDecoder().decode(payload));
|
|
8
|
+
const decodedPayload = frame.payload;
|
|
9
|
+
if (decodedPayload?.type === "process_output" &&
|
|
10
|
+
Array.isArray(decodedPayload.chunk)) {
|
|
11
|
+
decodedPayload.chunk = Uint8Array.from(decodedPayload.chunk);
|
|
12
|
+
}
|
|
13
|
+
return frame;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import { type FrameTransport } from "./frame-stream.js";
|
|
3
|
+
export type ClassifiedFrame<TResponseFrame, TEventFrame, TSidecarRequestFrame> = {
|
|
4
|
+
kind: "response";
|
|
5
|
+
requestId: number;
|
|
6
|
+
frame: TResponseFrame;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "event";
|
|
9
|
+
frame: TEventFrame;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "sidecarRequest";
|
|
12
|
+
frame: TSidecarRequestFrame;
|
|
13
|
+
};
|
|
14
|
+
export interface FrameRpcTransportOptions<TReadFrame, TWriteFrame, TResponseFrame, TEventFrame, TSidecarRequestFrame> {
|
|
15
|
+
frameTransport?: FrameTransport<TReadFrame, TWriteFrame>;
|
|
16
|
+
stdin?: Writable;
|
|
17
|
+
stdout?: Readable;
|
|
18
|
+
encodeFrame: (frame: TWriteFrame) => Uint8Array;
|
|
19
|
+
decodeFrame: (payload: Uint8Array) => TReadFrame;
|
|
20
|
+
classifyFrame: (frame: TReadFrame) => ClassifiedFrame<TResponseFrame, TEventFrame, TSidecarRequestFrame>;
|
|
21
|
+
}
|
|
22
|
+
export declare class FrameRpcTransport<TReadFrame, TWriteFrame, TResponseFrame, TEventFrame, TSidecarRequestFrame> {
|
|
23
|
+
private readonly frameTransport;
|
|
24
|
+
private readonly pendingResponses;
|
|
25
|
+
private readonly eventListeners;
|
|
26
|
+
private readonly sidecarRequestListeners;
|
|
27
|
+
private readonly frameActivityListeners;
|
|
28
|
+
constructor(options: FrameRpcTransportOptions<TReadFrame, TWriteFrame, TResponseFrame, TEventFrame, TSidecarRequestFrame>);
|
|
29
|
+
onEvent(handler: (event: TEventFrame) => void): () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Observe every classified inbound frame (response, event, or sidecar
|
|
32
|
+
* request) before it is routed. This is the transport's liveness signal:
|
|
33
|
+
* the silence watchdog resets on each invocation, so ANY inbound traffic —
|
|
34
|
+
* not just heartbeats — proves the sidecar is alive.
|
|
35
|
+
*/
|
|
36
|
+
onFrameActivity(handler: () => void): () => void;
|
|
37
|
+
onSidecarRequest(handler: (request: TSidecarRequestFrame) => void): () => void;
|
|
38
|
+
onError(handler: (error: Error) => void): () => void;
|
|
39
|
+
onEnd(handler: () => void): () => void;
|
|
40
|
+
sendFrame(requestId: number, frame: TWriteFrame, onResponse?: (response: TResponseFrame) => void): Promise<TResponseFrame>;
|
|
41
|
+
writeFrame(frame: TWriteFrame): Promise<void>;
|
|
42
|
+
rejectAll(error: Error): void;
|
|
43
|
+
dispose(): void;
|
|
44
|
+
private dispatchFrame;
|
|
45
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PendingResponseRegistry } from "./correlation.js";
|
|
2
|
+
import { StdioFrameTransport, } from "./frame-stream.js";
|
|
3
|
+
export class FrameRpcTransport {
|
|
4
|
+
frameTransport;
|
|
5
|
+
pendingResponses = new PendingResponseRegistry();
|
|
6
|
+
eventListeners = new Set();
|
|
7
|
+
sidecarRequestListeners = new Set();
|
|
8
|
+
frameActivityListeners = new Set();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
if (options.frameTransport) {
|
|
11
|
+
this.frameTransport = options.frameTransport;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (!options.stdin || !options.stdout) {
|
|
15
|
+
throw new Error("FrameRpcTransport requires either frameTransport or stdin/stdout streams");
|
|
16
|
+
}
|
|
17
|
+
this.frameTransport = new StdioFrameTransport({
|
|
18
|
+
stdin: options.stdin,
|
|
19
|
+
stdout: options.stdout,
|
|
20
|
+
encodeFrame: options.encodeFrame,
|
|
21
|
+
decodeFrame: options.decodeFrame,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
this.frameTransport.onFrame((frame) => {
|
|
25
|
+
this.dispatchFrame(options.classifyFrame(frame));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
onEvent(handler) {
|
|
29
|
+
this.eventListeners.add(handler);
|
|
30
|
+
return () => {
|
|
31
|
+
this.eventListeners.delete(handler);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Observe every classified inbound frame (response, event, or sidecar
|
|
36
|
+
* request) before it is routed. This is the transport's liveness signal:
|
|
37
|
+
* the silence watchdog resets on each invocation, so ANY inbound traffic —
|
|
38
|
+
* not just heartbeats — proves the sidecar is alive.
|
|
39
|
+
*/
|
|
40
|
+
onFrameActivity(handler) {
|
|
41
|
+
this.frameActivityListeners.add(handler);
|
|
42
|
+
return () => {
|
|
43
|
+
this.frameActivityListeners.delete(handler);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
onSidecarRequest(handler) {
|
|
47
|
+
this.sidecarRequestListeners.add(handler);
|
|
48
|
+
return () => {
|
|
49
|
+
this.sidecarRequestListeners.delete(handler);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
onError(handler) {
|
|
53
|
+
return this.frameTransport.onError(handler);
|
|
54
|
+
}
|
|
55
|
+
onEnd(handler) {
|
|
56
|
+
return this.frameTransport.onEnd(handler);
|
|
57
|
+
}
|
|
58
|
+
async sendFrame(requestId, frame, onResponse) {
|
|
59
|
+
const response = this.pendingResponses.waitForResponse(requestId, onResponse);
|
|
60
|
+
void this.writeFrame(frame).catch((error) => {
|
|
61
|
+
this.pendingResponses.reject(requestId, error instanceof Error ? error : new Error(String(error)));
|
|
62
|
+
});
|
|
63
|
+
return await response;
|
|
64
|
+
}
|
|
65
|
+
async writeFrame(frame) {
|
|
66
|
+
await this.frameTransport.writeFrame(frame);
|
|
67
|
+
}
|
|
68
|
+
rejectAll(error) {
|
|
69
|
+
this.pendingResponses.rejectAll(error);
|
|
70
|
+
}
|
|
71
|
+
dispose() {
|
|
72
|
+
this.frameTransport.dispose();
|
|
73
|
+
this.pendingResponses.rejectAll(new Error("frame rpc transport disposed"));
|
|
74
|
+
this.eventListeners.clear();
|
|
75
|
+
this.sidecarRequestListeners.clear();
|
|
76
|
+
this.frameActivityListeners.clear();
|
|
77
|
+
}
|
|
78
|
+
dispatchFrame(classified) {
|
|
79
|
+
for (const listener of this.frameActivityListeners) {
|
|
80
|
+
listener();
|
|
81
|
+
}
|
|
82
|
+
switch (classified.kind) {
|
|
83
|
+
case "response":
|
|
84
|
+
this.pendingResponses.resolve(classified.requestId, classified.frame);
|
|
85
|
+
return;
|
|
86
|
+
case "event":
|
|
87
|
+
for (const listener of this.eventListeners) {
|
|
88
|
+
listener(classified.frame);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
case "sidecarRequest":
|
|
92
|
+
for (const listener of this.sidecarRequestListeners) {
|
|
93
|
+
listener(classified.frame);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
export interface StdioFrameTransportOptions<TReadFrame, TWriteFrame> {
|
|
3
|
+
stdin: Writable;
|
|
4
|
+
stdout: Readable;
|
|
5
|
+
encodeFrame: (frame: TWriteFrame) => Uint8Array;
|
|
6
|
+
decodeFrame: (payload: Uint8Array) => TReadFrame;
|
|
7
|
+
}
|
|
8
|
+
export interface FrameTransport<TReadFrame, TWriteFrame = TReadFrame> {
|
|
9
|
+
onFrame(handler: (frame: TReadFrame) => void): () => void;
|
|
10
|
+
onError(handler: (error: Error) => void): () => void;
|
|
11
|
+
onEnd(handler: () => void): () => void;
|
|
12
|
+
writeFrame(frame: TWriteFrame): Promise<void>;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class StdioFrameTransport<TReadFrame, TWriteFrame = TReadFrame> implements FrameTransport<TReadFrame, TWriteFrame> {
|
|
16
|
+
private readonly stdin;
|
|
17
|
+
private readonly stdout;
|
|
18
|
+
private readonly encodeFrame;
|
|
19
|
+
private readonly decodeFrame;
|
|
20
|
+
private readonly frameListeners;
|
|
21
|
+
private readonly errorListeners;
|
|
22
|
+
private readonly endListeners;
|
|
23
|
+
private stdoutBuffer;
|
|
24
|
+
constructor(options: StdioFrameTransportOptions<TReadFrame, TWriteFrame>);
|
|
25
|
+
onFrame(handler: (frame: TReadFrame) => void): () => void;
|
|
26
|
+
onError(handler: (error: Error) => void): () => void;
|
|
27
|
+
onEnd(handler: () => void): () => void;
|
|
28
|
+
writeFrame(frame: TWriteFrame): Promise<void>;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
private readonly handleData;
|
|
31
|
+
private readonly handleEnd;
|
|
32
|
+
private readonly handleError;
|
|
33
|
+
private drainFrames;
|
|
34
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { encodeLengthPrefixedPayload, tryDecodeLengthPrefixedPayload, } from "./framing.js";
|
|
2
|
+
export class StdioFrameTransport {
|
|
3
|
+
stdin;
|
|
4
|
+
stdout;
|
|
5
|
+
encodeFrame;
|
|
6
|
+
decodeFrame;
|
|
7
|
+
frameListeners = new Set();
|
|
8
|
+
errorListeners = new Set();
|
|
9
|
+
endListeners = new Set();
|
|
10
|
+
stdoutBuffer = new Uint8Array(0);
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.stdin = options.stdin;
|
|
13
|
+
this.stdout = options.stdout;
|
|
14
|
+
this.encodeFrame = options.encodeFrame;
|
|
15
|
+
this.decodeFrame = options.decodeFrame;
|
|
16
|
+
this.stdout.on("data", this.handleData);
|
|
17
|
+
this.stdout.on("end", this.handleEnd);
|
|
18
|
+
this.stdout.on("error", this.handleError);
|
|
19
|
+
}
|
|
20
|
+
onFrame(handler) {
|
|
21
|
+
this.frameListeners.add(handler);
|
|
22
|
+
return () => {
|
|
23
|
+
this.frameListeners.delete(handler);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
onError(handler) {
|
|
27
|
+
this.errorListeners.add(handler);
|
|
28
|
+
return () => {
|
|
29
|
+
this.errorListeners.delete(handler);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
onEnd(handler) {
|
|
33
|
+
this.endListeners.add(handler);
|
|
34
|
+
return () => {
|
|
35
|
+
this.endListeners.delete(handler);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async writeFrame(frame) {
|
|
39
|
+
const payload = this.encodeFrame(frame);
|
|
40
|
+
const encoded = encodeLengthPrefixedPayload(payload);
|
|
41
|
+
await new Promise((resolve, reject) => {
|
|
42
|
+
this.stdin.write(encoded, (error) => {
|
|
43
|
+
if (error) {
|
|
44
|
+
reject(error);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
resolve();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
dispose() {
|
|
52
|
+
this.stdout.off("data", this.handleData);
|
|
53
|
+
this.stdout.off("end", this.handleEnd);
|
|
54
|
+
this.stdout.off("error", this.handleError);
|
|
55
|
+
this.frameListeners.clear();
|
|
56
|
+
this.errorListeners.clear();
|
|
57
|
+
this.endListeners.clear();
|
|
58
|
+
}
|
|
59
|
+
handleData = (chunk) => {
|
|
60
|
+
const bytes = typeof chunk === "string"
|
|
61
|
+
? new TextEncoder().encode(chunk)
|
|
62
|
+
: new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
63
|
+
this.stdoutBuffer = concatBytes(this.stdoutBuffer, bytes);
|
|
64
|
+
this.drainFrames();
|
|
65
|
+
};
|
|
66
|
+
handleEnd = () => {
|
|
67
|
+
for (const listener of this.endListeners) {
|
|
68
|
+
listener();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
handleError = (error) => {
|
|
72
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
73
|
+
for (const listener of this.errorListeners) {
|
|
74
|
+
listener(normalized);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
drainFrames() {
|
|
78
|
+
for (;;) {
|
|
79
|
+
const decoded = tryDecodeLengthPrefixedPayload(this.stdoutBuffer);
|
|
80
|
+
if (!decoded) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.stdoutBuffer = decoded.remaining;
|
|
84
|
+
let frame;
|
|
85
|
+
try {
|
|
86
|
+
frame = this.decodeFrame(decoded.payload);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
this.handleError(error);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
for (const listener of this.frameListeners) {
|
|
93
|
+
listener(frame);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function concatBytes(left, right) {
|
|
99
|
+
if (left.length === 0) {
|
|
100
|
+
return right;
|
|
101
|
+
}
|
|
102
|
+
if (right.length === 0) {
|
|
103
|
+
return left;
|
|
104
|
+
}
|
|
105
|
+
const combined = new Uint8Array(left.length + right.length);
|
|
106
|
+
combined.set(left);
|
|
107
|
+
combined.set(right, left.length);
|
|
108
|
+
return combined;
|
|
109
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const LENGTH_PREFIX_BYTES = 4;
|
|
2
|
+
export type ByteArray = Uint8Array<ArrayBufferLike>;
|
|
3
|
+
export interface LengthPrefixedPayload {
|
|
4
|
+
payload: ByteArray;
|
|
5
|
+
remaining: ByteArray;
|
|
6
|
+
}
|
|
7
|
+
export declare function encodeLengthPrefixedPayload(payload: Uint8Array): Uint8Array;
|
|
8
|
+
export declare function tryDecodeLengthPrefixedPayload(buffer: ByteArray): LengthPrefixedPayload | null;
|
package/dist/framing.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const LENGTH_PREFIX_BYTES = 4;
|
|
2
|
+
export function encodeLengthPrefixedPayload(payload) {
|
|
3
|
+
const encoded = new Uint8Array(LENGTH_PREFIX_BYTES + payload.length);
|
|
4
|
+
const view = new DataView(encoded.buffer, encoded.byteOffset, encoded.byteLength);
|
|
5
|
+
view.setUint32(0, payload.length, false);
|
|
6
|
+
encoded.set(payload, LENGTH_PREFIX_BYTES);
|
|
7
|
+
return encoded;
|
|
8
|
+
}
|
|
9
|
+
export function tryDecodeLengthPrefixedPayload(buffer) {
|
|
10
|
+
if (buffer.length < LENGTH_PREFIX_BYTES) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
14
|
+
const declaredLength = view.getUint32(0, false);
|
|
15
|
+
const frameEnd = LENGTH_PREFIX_BYTES + declaredLength;
|
|
16
|
+
if (buffer.length < frameEnd) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
payload: buffer.subarray(LENGTH_PREFIX_BYTES, frameEnd),
|
|
21
|
+
remaining: buffer.subarray(frameEnd),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { JsRuntimeConfig } from "./JsRuntimeConfig.js";
|
|
2
|
+
import type { NativeRootFilesystemConfig } from "./NativeRootFilesystemConfig.js";
|
|
3
|
+
import type { PermissionsPolicy } from "./PermissionsPolicy.js";
|
|
4
|
+
import type { RootFilesystemConfig } from "./RootFilesystemConfig.js";
|
|
5
|
+
import type { VmDnsConfig } from "./VmDnsConfig.js";
|
|
6
|
+
import type { VmLimitsConfig } from "./VmLimitsConfig.js";
|
|
7
|
+
import type { VmListenPolicyConfig } from "./VmListenPolicyConfig.js";
|
|
8
|
+
/**
|
|
9
|
+
* Canonical Rust-side VM config. Unknown fields must stay rejected here and in
|
|
10
|
+
* the TS preflight schema at
|
|
11
|
+
* the public thin-client VM options; update both when an explicit wire option
|
|
12
|
+
* changes the generated VM config.
|
|
13
|
+
*/
|
|
14
|
+
export type CreateVmConfig = {
|
|
15
|
+
cwd?: string;
|
|
16
|
+
env?: Record<string, string>;
|
|
17
|
+
rootFilesystem?: RootFilesystemConfig;
|
|
18
|
+
permissions?: PermissionsPolicy;
|
|
19
|
+
limits?: VmLimitsConfig;
|
|
20
|
+
dns?: VmDnsConfig;
|
|
21
|
+
nativeRoot?: NativeRootFilesystemConfig;
|
|
22
|
+
listen?: VmListenPolicyConfig;
|
|
23
|
+
loopbackExemptPorts?: Array<number>;
|
|
24
|
+
jsRuntime?: JsRuntimeConfig;
|
|
25
|
+
agentAdditionalInstructions?: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type JsModuleResolution = "node" | "relative" | "none";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { JsModuleResolution } from "./JsModuleResolution.js";
|
|
2
|
+
import type { JsRuntimePlatform } from "./JsRuntimePlatform.js";
|
|
3
|
+
/**
|
|
4
|
+
* Guest JavaScript host-environment configuration.
|
|
5
|
+
*
|
|
6
|
+
* Selects which globals/builtins/module-resolution surface guest JS sees,
|
|
7
|
+
* modeled on esbuild's `platform`. Omitting this preserves full Node.js
|
|
8
|
+
* emulation (`platform = node`).
|
|
9
|
+
*/
|
|
10
|
+
export type JsRuntimeConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* Which host environment to emulate for guest JS. Default `node`.
|
|
13
|
+
*/
|
|
14
|
+
platform?: JsRuntimePlatform;
|
|
15
|
+
/**
|
|
16
|
+
* How bare import specifiers resolve. Independent of `platform`.
|
|
17
|
+
* Default `node`.
|
|
18
|
+
*/
|
|
19
|
+
moduleResolution?: JsModuleResolution;
|
|
20
|
+
/**
|
|
21
|
+
* Node builtin-module allow-list. Only valid when `platform = node`.
|
|
22
|
+
* `None` => engine default allow-list. `Some([])` => deny all builtins.
|
|
23
|
+
* `Some([..])` => exactly those.
|
|
24
|
+
*/
|
|
25
|
+
allowedBuiltins?: Array<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Opt in to a high-resolution monotonic guest clock. Default false keeps
|
|
28
|
+
* the security-oriented 1ms timer resolution.
|
|
29
|
+
*/
|
|
30
|
+
highResolutionTime?: boolean;
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type JsRuntimePlatform = "node" | "browser" | "neutral" | "bare";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PermissionMode = "allow" | "ask" | "deny";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FsPermissionScope } from "./FsPermissionScope.js";
|
|
2
|
+
import type { PatternPermissionScope } from "./PatternPermissionScope.js";
|
|
3
|
+
export type PermissionsPolicy = {
|
|
4
|
+
fs?: FsPermissionScope;
|
|
5
|
+
network?: PatternPermissionScope;
|
|
6
|
+
childProcess?: PatternPermissionScope;
|
|
7
|
+
process?: PatternPermissionScope;
|
|
8
|
+
env?: PatternPermissionScope;
|
|
9
|
+
binding?: PatternPermissionScope;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|