@secure-exec/core 0.0.0-nathan-docs-sdk-expansion.c9c2e4e
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/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 +34 -0
- package/dist/descriptors.js +37 -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 +38 -0
- package/dist/frame-rpc.js +73 -0
- package/dist/frame-stream.d.ts +27 -0
- package/dist/frame-stream.js +99 -0
- package/dist/framing.d.ts +7 -0
- package/dist/framing.js +22 -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 +7 -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 +5 -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 +1037 -0
- package/dist/generated-protocol.js +2887 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +20 -0
- package/dist/kernel-proxy.d.ts +149 -0
- package/dist/kernel-proxy.js +1733 -0
- package/dist/native-client.d.ts +41 -0
- package/dist/native-client.js +124 -0
- package/dist/node-runtime.d.ts +443 -0
- package/dist/node-runtime.js +569 -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 +35 -0
- package/dist/process.js +125 -0
- package/dist/protocol-client.d.ts +46 -0
- package/dist/protocol-client.js +180 -0
- package/dist/protocol-frames.d.ts +68 -0
- package/dist/protocol-frames.js +139 -0
- package/dist/protocol-maps.d.ts +28 -0
- package/dist/protocol-maps.js +217 -0
- package/dist/protocol-schema.d.ts +10 -0
- package/dist/protocol-schema.js +11 -0
- package/dist/request-payloads.d.ts +137 -0
- package/dist/request-payloads.js +210 -0
- package/dist/response-payloads.d.ts +107 -0
- package/dist/response-payloads.js +161 -0
- package/dist/sidecar-client.d.ts +242 -0
- package/dist/sidecar-client.js +797 -0
- package/dist/state.d.ts +40 -0
- package/dist/state.js +44 -0
- package/dist/test-runtime.d.ts +526 -0
- package/dist/test-runtime.js +2119 -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 +194 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @secure-exec/core
|
|
2
|
+
|
|
3
|
+
Raw Secure Exec protocol types and codecs.
|
|
4
|
+
|
|
5
|
+
- `@secure-exec/core/protocol` exports the generated sidecar protocol.
|
|
6
|
+
- `@secure-exec/core/binary` resolves the published `secure-exec-sidecar` binary and honors `SECURE_EXEC_SIDECAR_BIN`.
|
|
7
|
+
- `@secure-exec/core/framing`, `@secure-exec/core/frame-stream`, `@secure-exec/core/frame-rpc`, `@secure-exec/core/frame-payload-codec`, `@secure-exec/core/correlation`, `@secure-exec/core/event-buffer`, `@secure-exec/core/ownership`, `@secure-exec/core/permissions`, `@secure-exec/core/state`, `@secure-exec/core/request-payloads`, `@secure-exec/core/response-payloads`, `@secure-exec/core/protocol-frames`, `@secure-exec/core/protocol-client`, `@secure-exec/core/native-client`, `@secure-exec/core/descriptors`, `@secure-exec/core/process`, `@secure-exec/core/protocol-schema`, `@secure-exec/core/protocol-maps`, `@secure-exec/core/callbacks`, `@secure-exec/core/filesystem`, `@secure-exec/core/json`, `@secure-exec/core/numbers`, `@secure-exec/core/bytes`, and `@secure-exec/core/ext` expose generic Node transport primitives.
|
package/dist/binary.d.ts
ADDED
package/dist/binary.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the published secure-exec sidecar binary for Node.js clients.
|
|
5
|
+
*/
|
|
6
|
+
export function resolvePublishedSidecarBinary() {
|
|
7
|
+
const override = process.env.SECURE_EXEC_SIDECAR_BIN;
|
|
8
|
+
if (override) {
|
|
9
|
+
if (!existsSync(override)) {
|
|
10
|
+
throw new Error(`SECURE_EXEC_SIDECAR_BIN is set to ${override} but the file does not exist`);
|
|
11
|
+
}
|
|
12
|
+
return override;
|
|
13
|
+
}
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
let mod;
|
|
16
|
+
try {
|
|
17
|
+
mod = require("@secure-exec/sidecar");
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error("failed to resolve the secure-exec sidecar binary: the @secure-exec/sidecar " +
|
|
21
|
+
"package is not installed. Install it, or set SECURE_EXEC_SIDECAR_BIN to a local " +
|
|
22
|
+
`secure-exec-sidecar binary. (${error.message})`);
|
|
23
|
+
}
|
|
24
|
+
return mod.getSidecarPath();
|
|
25
|
+
}
|
package/dist/bytes.d.ts
ADDED
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type * as protocol from "./generated-protocol.js";
|
|
2
|
+
export interface CallbackExtEnvelope {
|
|
3
|
+
namespace: string;
|
|
4
|
+
payload: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export type CallbackSidecarRequestPayload = {
|
|
7
|
+
type: "host_callback";
|
|
8
|
+
invocation_id: string;
|
|
9
|
+
callback_key: string;
|
|
10
|
+
input: unknown;
|
|
11
|
+
timeout_ms: number;
|
|
12
|
+
} | {
|
|
13
|
+
type: "js_bridge_call";
|
|
14
|
+
call_id: string;
|
|
15
|
+
mount_id: string;
|
|
16
|
+
operation: string;
|
|
17
|
+
args: unknown;
|
|
18
|
+
} | {
|
|
19
|
+
type: "ext";
|
|
20
|
+
envelope: CallbackExtEnvelope;
|
|
21
|
+
};
|
|
22
|
+
export type CallbackSidecarResponsePayload = {
|
|
23
|
+
type: "host_callback_result";
|
|
24
|
+
invocation_id: string;
|
|
25
|
+
result?: unknown;
|
|
26
|
+
error?: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "js_bridge_result";
|
|
29
|
+
call_id: string;
|
|
30
|
+
result?: unknown;
|
|
31
|
+
error?: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "ext_result";
|
|
34
|
+
envelope: CallbackExtEnvelope;
|
|
35
|
+
};
|
|
36
|
+
export type LiveSidecarRequestPayload = CallbackSidecarRequestPayload;
|
|
37
|
+
export type LiveSidecarResponsePayload = CallbackSidecarResponsePayload;
|
|
38
|
+
export declare function isMatchingSidecarResponsePayload(request: CallbackSidecarRequestPayload, response: CallbackSidecarResponsePayload): boolean;
|
|
39
|
+
export declare function errorSidecarResponsePayload(request: CallbackSidecarRequestPayload, error: unknown): CallbackSidecarResponsePayload;
|
|
40
|
+
export declare function fromGeneratedSidecarRequestPayload(payload: protocol.SidecarRequestPayload): LiveSidecarRequestPayload;
|
|
41
|
+
export declare function toGeneratedSidecarResponsePayload(payload: LiveSidecarResponsePayload): protocol.SidecarResponsePayload;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { fromGeneratedExtEnvelope, toGeneratedExtEnvelope, } from "./ext.js";
|
|
2
|
+
import { parseJsonUtf8, stringifyJsonUtf8 } from "./json.js";
|
|
3
|
+
import { bigIntToSafeNumber } from "./numbers.js";
|
|
4
|
+
export function isMatchingSidecarResponsePayload(request, response) {
|
|
5
|
+
switch (request.type) {
|
|
6
|
+
case "host_callback":
|
|
7
|
+
return response.type === "host_callback_result";
|
|
8
|
+
case "js_bridge_call":
|
|
9
|
+
return response.type === "js_bridge_result";
|
|
10
|
+
case "ext":
|
|
11
|
+
return response.type === "ext_result";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function errorSidecarResponsePayload(request, error) {
|
|
15
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16
|
+
switch (request.type) {
|
|
17
|
+
case "host_callback":
|
|
18
|
+
return {
|
|
19
|
+
type: "host_callback_result",
|
|
20
|
+
invocation_id: request.invocation_id,
|
|
21
|
+
error: message,
|
|
22
|
+
};
|
|
23
|
+
case "js_bridge_call":
|
|
24
|
+
return {
|
|
25
|
+
type: "js_bridge_result",
|
|
26
|
+
call_id: request.call_id,
|
|
27
|
+
error: message,
|
|
28
|
+
};
|
|
29
|
+
case "ext":
|
|
30
|
+
return {
|
|
31
|
+
type: "ext_result",
|
|
32
|
+
envelope: {
|
|
33
|
+
namespace: request.envelope.namespace,
|
|
34
|
+
payload: Buffer.from(message, "utf8"),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function fromGeneratedSidecarRequestPayload(payload) {
|
|
40
|
+
switch (payload.tag) {
|
|
41
|
+
case "HostCallbackRequest":
|
|
42
|
+
return {
|
|
43
|
+
type: "host_callback",
|
|
44
|
+
invocation_id: payload.val.invocationId,
|
|
45
|
+
callback_key: payload.val.callbackKey,
|
|
46
|
+
input: parseJsonUtf8(payload.val.input, "host callback input"),
|
|
47
|
+
timeout_ms: bigIntToSafeNumber(payload.val.timeoutMs, "host callback timeout"),
|
|
48
|
+
};
|
|
49
|
+
case "JsBridgeCallRequest":
|
|
50
|
+
return {
|
|
51
|
+
type: "js_bridge_call",
|
|
52
|
+
call_id: payload.val.callId,
|
|
53
|
+
mount_id: payload.val.mountId,
|
|
54
|
+
operation: payload.val.operation,
|
|
55
|
+
args: parseJsonUtf8(payload.val.args, "js bridge call args"),
|
|
56
|
+
};
|
|
57
|
+
case "ExtEnvelope":
|
|
58
|
+
return {
|
|
59
|
+
type: "ext",
|
|
60
|
+
envelope: fromGeneratedExtEnvelope(payload.val),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function toGeneratedSidecarResponsePayload(payload) {
|
|
65
|
+
switch (payload.type) {
|
|
66
|
+
case "host_callback_result":
|
|
67
|
+
return {
|
|
68
|
+
tag: "HostCallbackResultResponse",
|
|
69
|
+
val: {
|
|
70
|
+
invocationId: payload.invocation_id,
|
|
71
|
+
result: payload.result === undefined
|
|
72
|
+
? null
|
|
73
|
+
: stringifyJsonUtf8(payload.result, "host_callback_result.result"),
|
|
74
|
+
error: payload.error ?? null,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
case "js_bridge_result":
|
|
78
|
+
return {
|
|
79
|
+
tag: "JsBridgeResultResponse",
|
|
80
|
+
val: {
|
|
81
|
+
callId: payload.call_id,
|
|
82
|
+
result: payload.result === undefined
|
|
83
|
+
? null
|
|
84
|
+
: stringifyJsonUtf8(payload.result, "js_bridge_result.result"),
|
|
85
|
+
error: payload.error ?? null,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
case "ext_result":
|
|
89
|
+
return {
|
|
90
|
+
tag: "ExtEnvelope",
|
|
91
|
+
val: toGeneratedExtEnvelope(payload.envelope),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
package/dist/cargo.d.ts
ADDED
package/dist/cargo.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { accessSync, constants as fsConstants, existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const CARGO_BINARY_NAME = process.platform === "win32" ? "cargo.exe" : "cargo";
|
|
5
|
+
function hasPathSeparator(candidate) {
|
|
6
|
+
return candidate.includes("/") || candidate.includes("\\");
|
|
7
|
+
}
|
|
8
|
+
function isExecutableFile(candidate) {
|
|
9
|
+
try {
|
|
10
|
+
if (!statSync(candidate).isFile()) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
accessSync(candidate, fsConstants.X_OK);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function resolveExecutableOnPath(binaryName) {
|
|
21
|
+
const pathEntries = (process.env.PATH ?? "")
|
|
22
|
+
.split(path.delimiter)
|
|
23
|
+
.map((entry) => entry.trim())
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
for (const entry of pathEntries) {
|
|
26
|
+
const candidate = path.join(entry, binaryName);
|
|
27
|
+
if (isExecutableFile(candidate)) {
|
|
28
|
+
return candidate;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function resolveExecutableCandidate(candidate) {
|
|
34
|
+
if (hasPathSeparator(candidate)) {
|
|
35
|
+
return isExecutableFile(candidate) ? candidate : null;
|
|
36
|
+
}
|
|
37
|
+
return resolveExecutableOnPath(candidate);
|
|
38
|
+
}
|
|
39
|
+
function getToolchainCargoFromRustupHome(rustupHome) {
|
|
40
|
+
const toolchainsDir = path.join(rustupHome, "toolchains");
|
|
41
|
+
if (!existsSync(toolchainsDir)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const settingsPath = path.join(rustupHome, "settings.toml");
|
|
45
|
+
const orderedToolchains = [];
|
|
46
|
+
if (existsSync(settingsPath)) {
|
|
47
|
+
const defaultToolchain = readFileSync(settingsPath, "utf8")
|
|
48
|
+
.match(/^default_toolchain\s*=\s*"([^"]+)"/m)?.[1]
|
|
49
|
+
?.trim();
|
|
50
|
+
if (defaultToolchain) {
|
|
51
|
+
orderedToolchains.push(defaultToolchain);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const entry of readdirSync(toolchainsDir)) {
|
|
55
|
+
if (!orderedToolchains.includes(entry)) {
|
|
56
|
+
orderedToolchains.push(entry);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const toolchain of orderedToolchains) {
|
|
60
|
+
const cargoPath = path.join(toolchainsDir, toolchain, "bin", CARGO_BINARY_NAME);
|
|
61
|
+
if (existsSync(cargoPath)) {
|
|
62
|
+
return { cargoPath, rustupHome };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function inferRustupHomesFromPath() {
|
|
68
|
+
const rustupHomes = new Set();
|
|
69
|
+
const pathEntries = (process.env.PATH ?? "")
|
|
70
|
+
.split(path.delimiter)
|
|
71
|
+
.map((entry) => entry.trim())
|
|
72
|
+
.filter(Boolean);
|
|
73
|
+
for (const entry of pathEntries) {
|
|
74
|
+
if (path.basename(entry) !== "bin") {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const parentDir = path.dirname(entry);
|
|
78
|
+
if (existsSync(path.join(parentDir, "toolchains"))) {
|
|
79
|
+
rustupHomes.add(parentDir);
|
|
80
|
+
}
|
|
81
|
+
const siblingRoot = path.dirname(parentDir);
|
|
82
|
+
try {
|
|
83
|
+
for (const sibling of readdirSync(siblingRoot, { withFileTypes: true })) {
|
|
84
|
+
if (!sibling.isDirectory()) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const siblingPath = path.join(siblingRoot, sibling.name);
|
|
88
|
+
if (existsSync(path.join(siblingPath, "toolchains"))) {
|
|
89
|
+
rustupHomes.add(siblingPath);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
}
|
|
95
|
+
return [...rustupHomes];
|
|
96
|
+
}
|
|
97
|
+
function ensureToolchainEnvironment(toolchainCargo) {
|
|
98
|
+
const toolchainBin = path.dirname(toolchainCargo.cargoPath);
|
|
99
|
+
const currentPathEntries = (process.env.PATH ?? "")
|
|
100
|
+
.split(path.delimiter)
|
|
101
|
+
.filter(Boolean);
|
|
102
|
+
if (!currentPathEntries.includes(toolchainBin)) {
|
|
103
|
+
process.env.PATH = [toolchainBin, ...currentPathEntries].join(path.delimiter);
|
|
104
|
+
}
|
|
105
|
+
if (!process.env.RUSTUP_HOME) {
|
|
106
|
+
process.env.RUSTUP_HOME = toolchainCargo.rustupHome;
|
|
107
|
+
}
|
|
108
|
+
const toolchainName = path.basename(path.dirname(toolchainBin));
|
|
109
|
+
if (!process.env.RUSTUP_TOOLCHAIN) {
|
|
110
|
+
process.env.RUSTUP_TOOLCHAIN = toolchainName;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function findCargoBinary() {
|
|
114
|
+
const explicitCargo = process.env.CARGO?.trim();
|
|
115
|
+
const rustupHomes = [
|
|
116
|
+
process.env.RUSTUP_HOME?.trim(),
|
|
117
|
+
path.join(homedir(), ".rustup"),
|
|
118
|
+
...inferRustupHomesFromPath(),
|
|
119
|
+
].filter((candidate) => Boolean(candidate));
|
|
120
|
+
const toolchainCargoCandidates = rustupHomes
|
|
121
|
+
.map((rustupHome) => getToolchainCargoFromRustupHome(rustupHome))
|
|
122
|
+
.filter((candidate) => Boolean(candidate));
|
|
123
|
+
if (toolchainCargoCandidates.length > 0) {
|
|
124
|
+
ensureToolchainEnvironment(toolchainCargoCandidates[0]);
|
|
125
|
+
}
|
|
126
|
+
const candidates = [
|
|
127
|
+
explicitCargo,
|
|
128
|
+
...toolchainCargoCandidates.map((candidate) => candidate.cargoPath),
|
|
129
|
+
path.join(homedir(), ".cargo", "bin", CARGO_BINARY_NAME),
|
|
130
|
+
CARGO_BINARY_NAME,
|
|
131
|
+
].filter((candidate) => Boolean(candidate));
|
|
132
|
+
for (const candidate of candidates) {
|
|
133
|
+
const resolved = resolveExecutableCandidate(candidate);
|
|
134
|
+
if (resolved) {
|
|
135
|
+
return resolved;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
export function resolveCargoBinary() {
|
|
141
|
+
return findCargoBinary() ?? CARGO_BINARY_NAME;
|
|
142
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class PendingResponseRegistry<TResponse> {
|
|
2
|
+
private readonly pending;
|
|
3
|
+
waitForResponse(requestId: number, options: {
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
timeoutMessage: () => string;
|
|
6
|
+
}): Promise<TResponse>;
|
|
7
|
+
resolve(requestId: number, frame: TResponse): boolean;
|
|
8
|
+
reject(requestId: number, error: Error): boolean;
|
|
9
|
+
rejectAll(error: Error): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class PendingResponseRegistry {
|
|
2
|
+
pending = new Map();
|
|
3
|
+
waitForResponse(requestId, options) {
|
|
4
|
+
if (this.pending.has(requestId)) {
|
|
5
|
+
throw new Error(`response waiter already registered for request ${requestId}`);
|
|
6
|
+
}
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const entry = {
|
|
9
|
+
resolve: (frame) => {
|
|
10
|
+
clearTimeout(entry.timer);
|
|
11
|
+
this.pending.delete(requestId);
|
|
12
|
+
resolve(frame);
|
|
13
|
+
},
|
|
14
|
+
reject: (error) => {
|
|
15
|
+
clearTimeout(entry.timer);
|
|
16
|
+
this.pending.delete(requestId);
|
|
17
|
+
reject(error);
|
|
18
|
+
},
|
|
19
|
+
timer: setTimeout(() => {
|
|
20
|
+
this.pending.delete(requestId);
|
|
21
|
+
reject(new Error(options.timeoutMessage()));
|
|
22
|
+
}, options.timeoutMs),
|
|
23
|
+
};
|
|
24
|
+
this.pending.set(requestId, entry);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
resolve(requestId, frame) {
|
|
28
|
+
const pending = this.pending.get(requestId);
|
|
29
|
+
if (!pending) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
pending.resolve(frame);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
reject(requestId, error) {
|
|
36
|
+
const pending = this.pending.get(requestId);
|
|
37
|
+
if (!pending) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
pending.reject(error);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
rejectAll(error) {
|
|
44
|
+
for (const pending of this.pending.values()) {
|
|
45
|
+
pending.reject(error);
|
|
46
|
+
}
|
|
47
|
+
this.pending.clear();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type * as protocol from "./generated-protocol.js";
|
|
2
|
+
export type LiveSidecarPlacement = {
|
|
3
|
+
kind: "shared";
|
|
4
|
+
pool?: string | null;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "explicit";
|
|
7
|
+
sidecar_id: string;
|
|
8
|
+
};
|
|
9
|
+
export type MountConfigJsonPrimitive = string | number | boolean | null;
|
|
10
|
+
export type MountConfigJsonValue = MountConfigJsonPrimitive | MountConfigJsonObject | MountConfigJsonValue[];
|
|
11
|
+
export interface MountConfigJsonObject {
|
|
12
|
+
[key: string]: MountConfigJsonValue;
|
|
13
|
+
}
|
|
14
|
+
export interface NativeMountPluginDescriptor<TConfig extends MountConfigJsonObject = MountConfigJsonObject> {
|
|
15
|
+
id: string;
|
|
16
|
+
config?: TConfig;
|
|
17
|
+
}
|
|
18
|
+
export interface LiveMountDescriptor {
|
|
19
|
+
guest_path: string;
|
|
20
|
+
read_only: boolean;
|
|
21
|
+
plugin: NativeMountPluginDescriptor;
|
|
22
|
+
}
|
|
23
|
+
export interface LiveSoftwareDescriptor {
|
|
24
|
+
package_name: string;
|
|
25
|
+
root: string;
|
|
26
|
+
}
|
|
27
|
+
export interface LiveProjectedModuleDescriptor {
|
|
28
|
+
package_name: string;
|
|
29
|
+
entrypoint: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function toGeneratedSidecarPlacement(placement: LiveSidecarPlacement): protocol.SidecarPlacement;
|
|
32
|
+
export declare function toGeneratedMountDescriptor(descriptor: LiveMountDescriptor): protocol.MountDescriptor;
|
|
33
|
+
export declare function toGeneratedSoftwareDescriptor(descriptor: LiveSoftwareDescriptor): protocol.SoftwareDescriptor;
|
|
34
|
+
export declare function toGeneratedProjectedModuleDescriptor(descriptor: LiveProjectedModuleDescriptor): protocol.ProjectedModuleDescriptor;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { stringifyJsonUtf8 } from "./json.js";
|
|
2
|
+
export function toGeneratedSidecarPlacement(placement) {
|
|
3
|
+
switch (placement.kind) {
|
|
4
|
+
case "shared":
|
|
5
|
+
return {
|
|
6
|
+
tag: "SidecarPlacementShared",
|
|
7
|
+
val: { pool: placement.pool ?? null },
|
|
8
|
+
};
|
|
9
|
+
case "explicit":
|
|
10
|
+
return {
|
|
11
|
+
tag: "SidecarPlacementExplicit",
|
|
12
|
+
val: { sidecarId: placement.sidecar_id },
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function toGeneratedMountDescriptor(descriptor) {
|
|
17
|
+
return {
|
|
18
|
+
guestPath: descriptor.guest_path,
|
|
19
|
+
readOnly: descriptor.read_only,
|
|
20
|
+
plugin: {
|
|
21
|
+
id: descriptor.plugin.id,
|
|
22
|
+
config: stringifyJsonUtf8(descriptor.plugin.config ?? {}, "mount plugin config"),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function toGeneratedSoftwareDescriptor(descriptor) {
|
|
27
|
+
return {
|
|
28
|
+
packageName: descriptor.package_name,
|
|
29
|
+
root: descriptor.root,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function toGeneratedProjectedModuleDescriptor(descriptor) {
|
|
33
|
+
return {
|
|
34
|
+
packageName: descriptor.package_name,
|
|
35
|
+
entrypoint: descriptor.entrypoint,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type LiveExtEnvelope } from "./ext.js";
|
|
2
|
+
import type * as protocol from "./generated-protocol.js";
|
|
3
|
+
import { type LiveOwnershipScope } from "./ownership.js";
|
|
4
|
+
export declare const ANY_BUFFERED_EVENT_KEY = "*";
|
|
5
|
+
export type { LiveOwnershipScope } from "./ownership.js";
|
|
6
|
+
export type LiveSidecarEventPayload = {
|
|
7
|
+
type: "vm_lifecycle";
|
|
8
|
+
state: "creating" | "ready" | "disposing" | "disposed" | "failed";
|
|
9
|
+
} | {
|
|
10
|
+
type: "process_output";
|
|
11
|
+
process_id: string;
|
|
12
|
+
channel: "stdout" | "stderr";
|
|
13
|
+
chunk: Uint8Array;
|
|
14
|
+
} | {
|
|
15
|
+
type: "process_exited";
|
|
16
|
+
process_id: string;
|
|
17
|
+
exit_code: number;
|
|
18
|
+
} | {
|
|
19
|
+
type: "structured";
|
|
20
|
+
name: string;
|
|
21
|
+
detail: Record<string, string>;
|
|
22
|
+
} | {
|
|
23
|
+
type: "ext";
|
|
24
|
+
envelope: LiveExtEnvelope;
|
|
25
|
+
};
|
|
26
|
+
export interface LiveSidecarEventFrame {
|
|
27
|
+
ownership: LiveOwnershipScope;
|
|
28
|
+
payload: LiveSidecarEventPayload;
|
|
29
|
+
}
|
|
30
|
+
export type LiveSidecarEventSelector = {
|
|
31
|
+
any: true;
|
|
32
|
+
} | {
|
|
33
|
+
type: "vm_lifecycle";
|
|
34
|
+
ownership?: LiveOwnershipScope;
|
|
35
|
+
state?: Extract<LiveSidecarEventPayload, {
|
|
36
|
+
type: "vm_lifecycle";
|
|
37
|
+
}>["state"];
|
|
38
|
+
} | {
|
|
39
|
+
type: "process_output";
|
|
40
|
+
ownership?: LiveOwnershipScope;
|
|
41
|
+
processId?: string;
|
|
42
|
+
channel?: Extract<LiveSidecarEventPayload, {
|
|
43
|
+
type: "process_output";
|
|
44
|
+
}>["channel"];
|
|
45
|
+
} | {
|
|
46
|
+
type: "process_exited";
|
|
47
|
+
ownership?: LiveOwnershipScope;
|
|
48
|
+
processId?: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "structured";
|
|
51
|
+
ownership?: LiveOwnershipScope;
|
|
52
|
+
name?: string;
|
|
53
|
+
detail?: Record<string, string>;
|
|
54
|
+
};
|
|
55
|
+
export type LiveSidecarBufferedEventRecord<TEvent extends LiveSidecarEventFrame> = {
|
|
56
|
+
event: TEvent;
|
|
57
|
+
keys: readonly string[];
|
|
58
|
+
};
|
|
59
|
+
export type LiveSidecarEventWaitMatcher<TEvent extends LiveSidecarEventFrame> = {
|
|
60
|
+
matches: (event: TEvent) => boolean;
|
|
61
|
+
bufferKey: string | null;
|
|
62
|
+
};
|
|
63
|
+
export declare class SidecarEventBufferOverflow extends Error {
|
|
64
|
+
readonly capacity: number;
|
|
65
|
+
readonly bufferedEvents: number;
|
|
66
|
+
readonly eventType: LiveSidecarEventPayload["type"];
|
|
67
|
+
constructor(options: {
|
|
68
|
+
capacity: number;
|
|
69
|
+
bufferedEvents: number;
|
|
70
|
+
eventType: LiveSidecarEventPayload["type"];
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export declare class SidecarEventBuffer<TEvent extends LiveSidecarEventFrame> {
|
|
74
|
+
private readonly capacity;
|
|
75
|
+
private readonly bufferedEvents;
|
|
76
|
+
private readonly bufferedEventQueues;
|
|
77
|
+
private nextBufferedEventId;
|
|
78
|
+
constructor(capacity: number);
|
|
79
|
+
get size(): number;
|
|
80
|
+
buffer(event: TEvent): SidecarEventBufferOverflow | null;
|
|
81
|
+
take(matcher: LiveSidecarEventWaitMatcher<TEvent>): TEvent | null;
|
|
82
|
+
private takeFromKey;
|
|
83
|
+
private remove;
|
|
84
|
+
}
|
|
85
|
+
export declare function sidecarSelectorMatchesEvent<TEvent extends LiveSidecarEventFrame>(selector: LiveSidecarEventSelector, event: TEvent): boolean;
|
|
86
|
+
export declare function sidecarSelectorBufferKey(selector: LiveSidecarEventSelector): string | null;
|
|
87
|
+
export declare function normalizeSidecarEventMatcher<TEvent extends LiveSidecarEventFrame>(selector: LiveSidecarEventSelector | ((event: TEvent) => boolean)): LiveSidecarEventWaitMatcher<TEvent>;
|
|
88
|
+
export declare function fromGeneratedEventPayload(payload: protocol.EventPayload): LiveSidecarEventPayload;
|
|
89
|
+
export declare function sidecarEventWaitAbortError(reason: unknown): Error;
|
|
90
|
+
export declare function sidecarEventBufferKeys<TEvent extends LiveSidecarEventFrame>(event: TEvent): string[];
|