@secure-exec/core 0.0.0-agentos-dylib-base.edaa4a4
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/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/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/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/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/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/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/cargo.d.ts +2 -0
- package/dist/cargo.js +142 -0
- package/dist/correlation.d.ts +10 -0
- package/dist/correlation.js +49 -0
- package/dist/descriptors.d.ts +80 -0
- package/dist/descriptors.js +55 -0
- package/dist/event-buffer.d.ts +90 -0
- package/dist/event-buffer.js +313 -0
- package/dist/ext.d.ts +7 -0
- package/dist/ext.js +13 -0
- package/dist/filesystem.d.ts +41 -0
- package/dist/filesystem.js +70 -0
- package/dist/frame-payload-codec.d.ts +8 -0
- package/dist/frame-payload-codec.js +14 -0
- package/dist/frame-rpc.d.ts +40 -0
- package/dist/frame-rpc.js +81 -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 +19 -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 +26 -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 +22 -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 +5 -0
- package/dist/generated/WasmLimitsConfig.js +2 -0
- package/dist/generated-protocol.d.ts +1055 -0
- package/dist/generated-protocol.js +2921 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +28 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +20 -0
- package/dist/kernel-proxy.d.ts +165 -0
- package/dist/kernel-proxy.js +1760 -0
- package/dist/message-frame-transport.d.ts +29 -0
- package/dist/message-frame-transport.js +81 -0
- package/dist/native-client.d.ts +42 -0
- package/dist/native-client.js +126 -0
- package/dist/node-runtime.d.ts +516 -0
- package/dist/node-runtime.js +823 -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 +48 -0
- package/dist/protocol-client.js +181 -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 +253 -0
- package/dist/protocol-schema.d.ts +10 -0
- package/dist/protocol-schema.js +11 -0
- package/dist/request-payloads.d.ts +154 -0
- package/dist/request-payloads.js +241 -0
- package/dist/response-payloads.d.ts +124 -0
- package/dist/response-payloads.js +180 -0
- package/dist/sidecar-client.d.ts +17 -0
- package/dist/sidecar-client.js +1 -0
- package/dist/sidecar-errors.d.ts +15 -0
- package/dist/sidecar-errors.js +30 -0
- package/dist/sidecar-process.d.ts +281 -0
- package/dist/sidecar-process.js +839 -0
- package/dist/state.d.ts +40 -0
- package/dist/state.js +44 -0
- package/dist/test-runtime.d.ts +536 -0
- package/dist/test-runtime.js +2153 -0
- package/dist/vm-config.d.ts +31 -0
- package/dist/vm-config.js +1 -0
- package/fixtures/alpine-defaults.json +520 -0
- package/fixtures/base-filesystem.json +528 -0
- package/package.json +212 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FrameTransport } from "./frame-stream.js";
|
|
2
|
+
export interface MessageFrameEndpoint {
|
|
3
|
+
postMessage(message: unknown, transfer?: readonly unknown[]): void;
|
|
4
|
+
}
|
|
5
|
+
export interface MessageFrameTransportOptions<TReadFrame, TWriteFrame> {
|
|
6
|
+
endpoint: MessageFrameEndpoint;
|
|
7
|
+
listen(handler: (message: unknown) => void): () => void;
|
|
8
|
+
encodeFrame: (frame: TWriteFrame) => Uint8Array;
|
|
9
|
+
decodeFrame: (payload: Uint8Array) => TReadFrame;
|
|
10
|
+
transfer?: (payload: Uint8Array) => readonly unknown[];
|
|
11
|
+
}
|
|
12
|
+
export declare class MessageFrameTransport<TReadFrame, TWriteFrame = TReadFrame> implements FrameTransport<TReadFrame, TWriteFrame> {
|
|
13
|
+
private readonly endpoint;
|
|
14
|
+
private readonly encodeFrame;
|
|
15
|
+
private readonly decodeFrame;
|
|
16
|
+
private readonly transfer?;
|
|
17
|
+
private readonly frameListeners;
|
|
18
|
+
private readonly errorListeners;
|
|
19
|
+
private readonly endListeners;
|
|
20
|
+
private readonly stopListening;
|
|
21
|
+
constructor(options: MessageFrameTransportOptions<TReadFrame, TWriteFrame>);
|
|
22
|
+
onFrame(handler: (frame: TReadFrame) => void): () => void;
|
|
23
|
+
onError(handler: (error: Error) => void): () => void;
|
|
24
|
+
onEnd(handler: () => void): () => void;
|
|
25
|
+
writeFrame(frame: TWriteFrame): Promise<void>;
|
|
26
|
+
dispose(): void;
|
|
27
|
+
private readonly handleMessage;
|
|
28
|
+
private handleError;
|
|
29
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export class MessageFrameTransport {
|
|
2
|
+
endpoint;
|
|
3
|
+
encodeFrame;
|
|
4
|
+
decodeFrame;
|
|
5
|
+
transfer;
|
|
6
|
+
frameListeners = new Set();
|
|
7
|
+
errorListeners = new Set();
|
|
8
|
+
endListeners = new Set();
|
|
9
|
+
stopListening;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.endpoint = options.endpoint;
|
|
12
|
+
this.encodeFrame = options.encodeFrame;
|
|
13
|
+
this.decodeFrame = options.decodeFrame;
|
|
14
|
+
this.transfer = options.transfer;
|
|
15
|
+
this.stopListening = options.listen(this.handleMessage);
|
|
16
|
+
}
|
|
17
|
+
onFrame(handler) {
|
|
18
|
+
this.frameListeners.add(handler);
|
|
19
|
+
return () => {
|
|
20
|
+
this.frameListeners.delete(handler);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
onError(handler) {
|
|
24
|
+
this.errorListeners.add(handler);
|
|
25
|
+
return () => {
|
|
26
|
+
this.errorListeners.delete(handler);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
onEnd(handler) {
|
|
30
|
+
this.endListeners.add(handler);
|
|
31
|
+
return () => {
|
|
32
|
+
this.endListeners.delete(handler);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async writeFrame(frame) {
|
|
36
|
+
const payload = this.encodeFrame(frame);
|
|
37
|
+
this.endpoint.postMessage(payload, this.transfer?.(payload));
|
|
38
|
+
}
|
|
39
|
+
dispose() {
|
|
40
|
+
this.stopListening();
|
|
41
|
+
this.frameListeners.clear();
|
|
42
|
+
this.errorListeners.clear();
|
|
43
|
+
this.endListeners.clear();
|
|
44
|
+
}
|
|
45
|
+
handleMessage = (message) => {
|
|
46
|
+
const payload = toByteArray(message);
|
|
47
|
+
if (!payload) {
|
|
48
|
+
this.handleError(new Error("message frame transport received non-byte message"));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let frame;
|
|
52
|
+
try {
|
|
53
|
+
frame = this.decodeFrame(payload);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.handleError(error);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const listener of this.frameListeners) {
|
|
60
|
+
listener(frame);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
handleError(error) {
|
|
64
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
65
|
+
for (const listener of this.errorListeners) {
|
|
66
|
+
listener(normalized);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function toByteArray(message) {
|
|
71
|
+
if (message instanceof Uint8Array) {
|
|
72
|
+
return new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
|
73
|
+
}
|
|
74
|
+
if (message instanceof ArrayBuffer) {
|
|
75
|
+
return new Uint8Array(message);
|
|
76
|
+
}
|
|
77
|
+
if (ArrayBuffer.isView(message)) {
|
|
78
|
+
return new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { StdioSidecarProcess } from "./process.js";
|
|
2
|
+
import type { SidecarProcessTransport } from "./sidecar-client.js";
|
|
3
|
+
import type { LiveEventFrame, LiveResponseFrame, LiveSidecarRequestHandler, ProtocolFramePayloadCodec } from "./protocol-frames.js";
|
|
4
|
+
import type { LiveOwnershipScope } from "./ownership.js";
|
|
5
|
+
import type { LiveRequestPayload } from "./request-payloads.js";
|
|
6
|
+
import type { LiveSidecarEventSelector } from "./event-buffer.js";
|
|
7
|
+
export declare const DEFAULT_SIDECAR_FRAME_TIMEOUT_MS = 120000;
|
|
8
|
+
export declare const DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY = 4096;
|
|
9
|
+
export declare const DEFAULT_SIDECAR_GRACEFUL_EXIT_MS = 5000;
|
|
10
|
+
export declare const DEFAULT_SIDECAR_FORCE_EXIT_MS = 2000;
|
|
11
|
+
export interface StdioSidecarProtocolClientSpawnOptions {
|
|
12
|
+
cwd?: string;
|
|
13
|
+
command?: string;
|
|
14
|
+
args?: string[];
|
|
15
|
+
frameTimeoutMs?: number;
|
|
16
|
+
eventBufferCapacity?: number;
|
|
17
|
+
gracefulExitMs?: number;
|
|
18
|
+
forceExitMs?: number;
|
|
19
|
+
disposedErrorMessage?: string;
|
|
20
|
+
payloadCodec?: ProtocolFramePayloadCodec;
|
|
21
|
+
}
|
|
22
|
+
export declare class StdioSidecarProtocolClient implements SidecarProcessTransport {
|
|
23
|
+
readonly child: StdioSidecarProcess["child"];
|
|
24
|
+
private readonly sidecarProcess;
|
|
25
|
+
private readonly protocolClient;
|
|
26
|
+
private readonly gracefulExitMs;
|
|
27
|
+
private readonly forceExitMs;
|
|
28
|
+
private readonly disposedErrorMessage;
|
|
29
|
+
private constructor();
|
|
30
|
+
static spawn(options?: StdioSidecarProtocolClientSpawnOptions): StdioSidecarProtocolClient;
|
|
31
|
+
setSidecarRequestHandler(handler: LiveSidecarRequestHandler | null): void;
|
|
32
|
+
onEvent(handler: (event: LiveEventFrame) => void): () => void;
|
|
33
|
+
sendRequest(input: {
|
|
34
|
+
ownership: LiveOwnershipScope;
|
|
35
|
+
payload: LiveRequestPayload;
|
|
36
|
+
}): Promise<LiveResponseFrame>;
|
|
37
|
+
waitForEvent(matcher: LiveSidecarEventSelector | ((event: LiveEventFrame) => boolean), timeoutMs?: number, options?: {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<LiveEventFrame>;
|
|
40
|
+
dispose(): Promise<void>;
|
|
41
|
+
failPermanently(error: Error): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { resolvePublishedSidecarBinary } from "./binary.js";
|
|
2
|
+
import { SidecarProcessExited, StdioSidecarProcess, } from "./process.js";
|
|
3
|
+
import { SidecarProtocolClient } from "./protocol-client.js";
|
|
4
|
+
import { registerSidecarProcessSpawnFactory } from "./sidecar-process.js";
|
|
5
|
+
export const DEFAULT_SIDECAR_FRAME_TIMEOUT_MS = 120_000;
|
|
6
|
+
export const DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY = 4_096;
|
|
7
|
+
export const DEFAULT_SIDECAR_GRACEFUL_EXIT_MS = 5_000;
|
|
8
|
+
export const DEFAULT_SIDECAR_FORCE_EXIT_MS = 2_000;
|
|
9
|
+
export class StdioSidecarProtocolClient {
|
|
10
|
+
child;
|
|
11
|
+
sidecarProcess;
|
|
12
|
+
protocolClient;
|
|
13
|
+
gracefulExitMs;
|
|
14
|
+
forceExitMs;
|
|
15
|
+
disposedErrorMessage;
|
|
16
|
+
constructor(sidecarProcess, options) {
|
|
17
|
+
this.sidecarProcess = sidecarProcess;
|
|
18
|
+
this.child = sidecarProcess.child;
|
|
19
|
+
this.gracefulExitMs = options.gracefulExitMs;
|
|
20
|
+
this.forceExitMs = options.forceExitMs;
|
|
21
|
+
this.disposedErrorMessage = options.disposedErrorMessage;
|
|
22
|
+
this.protocolClient = new SidecarProtocolClient({
|
|
23
|
+
stdin: this.child.stdin,
|
|
24
|
+
stdout: this.child.stdout,
|
|
25
|
+
frameTimeoutMs: options.frameTimeoutMs,
|
|
26
|
+
eventBufferCapacity: options.eventBufferCapacity,
|
|
27
|
+
payloadCodec: options.payloadCodec,
|
|
28
|
+
stderrText: () => this.sidecarProcess.stderrText(),
|
|
29
|
+
streamEndedError: () => this.sidecarProcess.currentExitError() ??
|
|
30
|
+
new SidecarProcessExited({
|
|
31
|
+
exitCode: this.child.exitCode,
|
|
32
|
+
signal: this.child.signalCode,
|
|
33
|
+
stderr: this.sidecarProcess.stderrText(),
|
|
34
|
+
}),
|
|
35
|
+
frameError: (error) => this.sidecarProcess.currentExitError() ?? error,
|
|
36
|
+
});
|
|
37
|
+
this.sidecarProcess.onExit((error) => {
|
|
38
|
+
this.failPermanently(error);
|
|
39
|
+
});
|
|
40
|
+
this.sidecarProcess.onError((error) => {
|
|
41
|
+
this.failPermanently(error);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
static spawn(options = {}) {
|
|
45
|
+
return new StdioSidecarProtocolClient(StdioSidecarProcess.spawn({
|
|
46
|
+
command: options.command ?? resolvePublishedSidecarBinary(),
|
|
47
|
+
args: options.args ?? [],
|
|
48
|
+
cwd: options.cwd,
|
|
49
|
+
}), {
|
|
50
|
+
frameTimeoutMs: options.frameTimeoutMs ?? DEFAULT_SIDECAR_FRAME_TIMEOUT_MS,
|
|
51
|
+
eventBufferCapacity: options.eventBufferCapacity ??
|
|
52
|
+
DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY,
|
|
53
|
+
gracefulExitMs: options.gracefulExitMs ?? DEFAULT_SIDECAR_GRACEFUL_EXIT_MS,
|
|
54
|
+
forceExitMs: options.forceExitMs ?? DEFAULT_SIDECAR_FORCE_EXIT_MS,
|
|
55
|
+
disposedErrorMessage: options.disposedErrorMessage ?? "sidecar client disposed",
|
|
56
|
+
payloadCodec: options.payloadCodec ?? "bare",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
setSidecarRequestHandler(handler) {
|
|
60
|
+
this.protocolClient.setSidecarRequestHandler(handler);
|
|
61
|
+
}
|
|
62
|
+
onEvent(handler) {
|
|
63
|
+
return this.protocolClient.onEvent(handler);
|
|
64
|
+
}
|
|
65
|
+
async sendRequest(input) {
|
|
66
|
+
return await this.protocolClient.sendRequest(input);
|
|
67
|
+
}
|
|
68
|
+
async waitForEvent(matcher, timeoutMs, options) {
|
|
69
|
+
return await this.protocolClient.waitForEvent(matcher, timeoutMs, options);
|
|
70
|
+
}
|
|
71
|
+
async dispose() {
|
|
72
|
+
this.protocolClient.failPermanently(new Error(this.disposedErrorMessage));
|
|
73
|
+
if (!this.child.stdin.destroyed) {
|
|
74
|
+
try {
|
|
75
|
+
this.child.stdin.end();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Stdin may already be closing. The child exit watcher will catch up.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const exitCode = await this.sidecarProcess.waitForExit(this.gracefulExitMs);
|
|
82
|
+
if (exitCode === null) {
|
|
83
|
+
try {
|
|
84
|
+
this.child.kill("SIGKILL");
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// The child may have exited between the timeout and the kill attempt.
|
|
88
|
+
}
|
|
89
|
+
await this.sidecarProcess.waitForExit(this.forceExitMs);
|
|
90
|
+
}
|
|
91
|
+
this.protocolClient.dispose();
|
|
92
|
+
try {
|
|
93
|
+
this.child.stdin.destroy();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Best effort. The child is gone so the descriptor will close on its own.
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
this.child.stdout.destroy();
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Best effort. The child is gone so the descriptor will close on its own.
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
this.child.stderr.destroy();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Best effort. The child is gone so the descriptor will close on its own.
|
|
109
|
+
}
|
|
110
|
+
if (exitCode !== null &&
|
|
111
|
+
exitCode !== 0 &&
|
|
112
|
+
this.child.signalCode === null) {
|
|
113
|
+
throw new Error(`sidecar exited with code ${exitCode}\nstderr:\n${this.sidecarProcess.stderrText()}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
failPermanently(error) {
|
|
117
|
+
this.protocolClient.failPermanently(error, {
|
|
118
|
+
replaceExisting: (current, next) => current instanceof SidecarProcessExited &&
|
|
119
|
+
current.exitCode === null &&
|
|
120
|
+
current.signal === null &&
|
|
121
|
+
next instanceof SidecarProcessExited &&
|
|
122
|
+
(next.exitCode !== null || next.signal !== null),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
registerSidecarProcessSpawnFactory((options) => StdioSidecarProtocolClient.spawn(options));
|