@relayflows/sdk 2.0.28 → 2.0.30

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.
Files changed (120) hide show
  1. package/dist/authored-flow-executor.d.ts.map +1 -1
  2. package/dist/authored-flow-executor.js +10 -1
  3. package/dist/authored-flow-executor.js.map +1 -1
  4. package/dist/authored-step-index.d.ts +6 -0
  5. package/dist/authored-step-index.d.ts.map +1 -1
  6. package/dist/authored-step-index.js +42 -14
  7. package/dist/authored-step-index.js.map +1 -1
  8. package/dist/bundle-extensions.d.ts.map +1 -1
  9. package/dist/bundle-extensions.js +4 -7
  10. package/dist/bundle-extensions.js.map +1 -1
  11. package/dist/bundle.d.ts.map +1 -1
  12. package/dist/bundle.js +41 -7
  13. package/dist/bundle.js.map +1 -1
  14. package/dist/canonical.d.ts.map +1 -1
  15. package/dist/canonical.js +18 -6
  16. package/dist/canonical.js.map +1 -1
  17. package/dist/cli/status.d.ts +12 -0
  18. package/dist/cli/status.d.ts.map +1 -1
  19. package/dist/cli/status.js +39 -1
  20. package/dist/cli/status.js.map +1 -1
  21. package/dist/flow-extension-compat.d.ts.map +1 -1
  22. package/dist/flow-extension-compat.js +26 -8
  23. package/dist/flow-extension-compat.js.map +1 -1
  24. package/dist/flow-extension-loader.d.ts +7 -0
  25. package/dist/flow-extension-loader.d.ts.map +1 -1
  26. package/dist/flow-extension-loader.js +48 -22
  27. package/dist/flow-extension-loader.js.map +1 -1
  28. package/dist/fs-descriptor.d.ts +17 -0
  29. package/dist/fs-descriptor.d.ts.map +1 -0
  30. package/dist/fs-descriptor.js +96 -0
  31. package/dist/fs-descriptor.js.map +1 -0
  32. package/dist/hosted-base-snapshot.d.ts +25 -0
  33. package/dist/hosted-base-snapshot.d.ts.map +1 -0
  34. package/dist/hosted-base-snapshot.js +278 -0
  35. package/dist/hosted-base-snapshot.js.map +1 -0
  36. package/dist/hosted-extension-declarations.d.ts +10 -0
  37. package/dist/hosted-extension-declarations.d.ts.map +1 -0
  38. package/dist/hosted-extension-declarations.js +272 -0
  39. package/dist/hosted-extension-declarations.js.map +1 -0
  40. package/dist/hosted-extension-isolation.d.ts +82 -0
  41. package/dist/hosted-extension-isolation.d.ts.map +1 -0
  42. package/dist/hosted-extension-isolation.js +322 -0
  43. package/dist/hosted-extension-isolation.js.map +1 -0
  44. package/dist/hosted-extension-manifest.d.ts +9 -0
  45. package/dist/hosted-extension-manifest.d.ts.map +1 -0
  46. package/dist/hosted-extension-manifest.js +235 -0
  47. package/dist/hosted-extension-manifest.js.map +1 -0
  48. package/dist/hosted-extension-protocol.d.ts +16 -0
  49. package/dist/hosted-extension-protocol.d.ts.map +1 -0
  50. package/dist/hosted-extension-protocol.js +224 -0
  51. package/dist/hosted-extension-protocol.js.map +1 -0
  52. package/dist/hosted-extension-runtime.d.ts +30 -0
  53. package/dist/hosted-extension-runtime.d.ts.map +1 -0
  54. package/dist/hosted-extension-runtime.js +167 -0
  55. package/dist/hosted-extension-runtime.js.map +1 -0
  56. package/dist/hosted-extension-sandbox-source.d.ts +9 -0
  57. package/dist/hosted-extension-sandbox-source.d.ts.map +1 -0
  58. package/dist/hosted-extension-sandbox-source.js +95 -0
  59. package/dist/hosted-extension-sandbox-source.js.map +1 -0
  60. package/dist/hosted-extension-sandbox.d.ts +39 -0
  61. package/dist/hosted-extension-sandbox.d.ts.map +1 -0
  62. package/dist/hosted-extension-sandbox.js +418 -0
  63. package/dist/hosted-extension-sandbox.js.map +1 -0
  64. package/dist/hosted-project.d.ts +3 -0
  65. package/dist/hosted-project.d.ts.map +1 -0
  66. package/dist/hosted-project.js +19 -0
  67. package/dist/hosted-project.js.map +1 -0
  68. package/dist/hosted-promise-safety.d.ts +12 -0
  69. package/dist/hosted-promise-safety.d.ts.map +1 -0
  70. package/dist/hosted-promise-safety.js +63 -0
  71. package/dist/hosted-promise-safety.js.map +1 -0
  72. package/dist/index.d.ts +2 -0
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +2 -0
  75. package/dist/index.js.map +1 -1
  76. package/dist/intrinsic-array.d.ts +3 -0
  77. package/dist/intrinsic-array.d.ts.map +1 -0
  78. package/dist/intrinsic-array.js +14 -0
  79. package/dist/intrinsic-array.js.map +1 -0
  80. package/dist/json-value.d.ts +6 -1
  81. package/dist/json-value.d.ts.map +1 -1
  82. package/dist/json-value.js +155 -36
  83. package/dist/json-value.js.map +1 -1
  84. package/dist/llm-worker.d.ts +9 -0
  85. package/dist/llm-worker.d.ts.map +1 -1
  86. package/dist/llm-worker.js +15 -1
  87. package/dist/llm-worker.js.map +1 -1
  88. package/dist/plugin-store.d.ts +8 -2
  89. package/dist/plugin-store.d.ts.map +1 -1
  90. package/dist/plugin-store.js +233 -56
  91. package/dist/plugin-store.js.map +1 -1
  92. package/dist/semver-range.d.ts.map +1 -1
  93. package/dist/semver-range.js +27 -15
  94. package/dist/semver-range.js.map +1 -1
  95. package/package.json +2 -2
  96. package/src/authored-flow-executor.ts +10 -1
  97. package/src/authored-step-index.ts +46 -12
  98. package/src/bundle-extensions.ts +6 -5
  99. package/src/bundle.ts +52 -7
  100. package/src/canonical.ts +20 -6
  101. package/src/cli/status.ts +50 -1
  102. package/src/flow-extension-compat.ts +32 -7
  103. package/src/flow-extension-loader.ts +56 -21
  104. package/src/fs-descriptor.ts +127 -0
  105. package/src/hosted-base-snapshot.ts +351 -0
  106. package/src/hosted-extension-declarations.ts +387 -0
  107. package/src/hosted-extension-isolation.ts +457 -0
  108. package/src/hosted-extension-manifest.ts +249 -0
  109. package/src/hosted-extension-protocol.ts +262 -0
  110. package/src/hosted-extension-runtime.ts +266 -0
  111. package/src/hosted-extension-sandbox-source.ts +94 -0
  112. package/src/hosted-extension-sandbox.ts +489 -0
  113. package/src/hosted-project.ts +18 -0
  114. package/src/hosted-promise-safety.ts +68 -0
  115. package/src/index.ts +18 -0
  116. package/src/intrinsic-array.ts +14 -0
  117. package/src/json-value.ts +184 -32
  118. package/src/llm-worker.ts +15 -1
  119. package/src/plugin-store.ts +323 -56
  120. package/src/semver-range.ts +39 -14
@@ -0,0 +1,167 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { canonicalize } from './canonical.js';
4
+ import { createHostedBaseSnapshot, hostedBaseSourceDigest, removeHostedBaseSnapshot, } from './hosted-base-snapshot.js';
5
+ import { appendIntrinsicArray } from './intrinsic-array.js';
6
+ import { declarationSignature, hostedDeclaredExtensions, } from './hosted-extension-declarations.js';
7
+ import { findHostedProject } from './hosted-project.js';
8
+ import { assertHostedPromiseSafety, frozenHostedPromiseValue, } from './hosted-promise-safety.js';
9
+ import { PluginError } from './plugin-manifest.js';
10
+ import { pluginStoreDirectory, verifyStoredPlugin } from './plugin-store.js';
11
+ const INSTALLATION_AUTHORITY = new WeakSet();
12
+ const BASE_AUTHORITY = new WeakSet();
13
+ const REALPATH = realpath;
14
+ const PATH_DIRNAME = dirname;
15
+ const PATH_JOIN = join;
16
+ const PATH_RESOLVE = resolve;
17
+ const SOFTWARE_FACTORY_SHA256 = '49c993220b9c34fab2d4b0e51911656f62b8b657f534d988691960d45bb9d9b6';
18
+ const ARRAY_IS_ARRAY = Array.isArray;
19
+ const OBJECT_FREEZE = Object.freeze;
20
+ const WEAK_MAP_GET = Function.prototype.call.bind(WeakMap.prototype.get);
21
+ const WEAK_MAP_SET = Function.prototype.call.bind(WeakMap.prototype.set);
22
+ const WEAK_SET_ADD = Function.prototype.call.bind(WeakSet.prototype.add);
23
+ const WEAK_SET_HAS = Function.prototype.call.bind(WeakSet.prototype.has);
24
+ const INSTALLATION_GENERATION = new WeakMap();
25
+ const BASE_GENERATION = new WeakMap();
26
+ /** Load one base/installation generation that cannot be paired across redeploys. */
27
+ export async function loadHostedExtensionRuntime(flowPath) {
28
+ assertHostedPromiseSafety('plugin_source_invalid');
29
+ const origin = await REALPATH(PATH_RESOLVE(flowPath));
30
+ const generation = newGeneration(origin);
31
+ const loaded = await installationAt(origin, generation);
32
+ generation.declarations = loaded.declarations;
33
+ const base = await baseAt(origin, generation);
34
+ if (loaded.declarations !== declaredExtensions(generation).signature) {
35
+ throw new PluginError('plugin_source_drift', 'Hosted extension declarations changed while their runtime generation was loaded.');
36
+ }
37
+ await assertCurrentGeneration(generation);
38
+ OBJECT_FREEZE(generation);
39
+ return frozenHostedPromiseValue({ installation: loaded.installation, base });
40
+ }
41
+ /** @internal Metadata-only test seam; public hosted callers use the combined loader. */
42
+ export async function loadHostedExtensionArtifacts(flowPath) {
43
+ assertHostedPromiseSafety('plugin_source_invalid');
44
+ const origin = await REALPATH(PATH_RESOLVE(flowPath));
45
+ const generation = newGeneration(origin);
46
+ const loaded = await installationAt(origin, generation);
47
+ generation.declarations = loaded.declarations;
48
+ return loaded.installation;
49
+ }
50
+ /** @internal Base-only test seam; public hosted callers use the combined loader. */
51
+ export async function loadHostedExtensionBase(flowPath) {
52
+ assertHostedPromiseSafety('plugin_source_invalid');
53
+ const origin = await REALPATH(PATH_RESOLVE(flowPath));
54
+ const generation = newGeneration(origin);
55
+ generation.declarations = declaredExtensions(generation).signature;
56
+ return await baseAt(origin, generation);
57
+ }
58
+ /** Validate both opaque values and refuse a cached generation after redeploy. */
59
+ export async function assertHostedRuntimeAuthority(installation, base) {
60
+ if (typeof base !== 'object' || base === null || !WEAK_SET_HAS(BASE_AUTHORITY, base)) {
61
+ throw new PluginError('plugin_incompatible', 'Hosted extension base authority is malformed; use loadHostedExtensionRuntime.');
62
+ }
63
+ if (typeof installation !== 'object' ||
64
+ installation === null ||
65
+ !WEAK_SET_HAS(INSTALLATION_AUTHORITY, installation)) {
66
+ throw new PluginError('plugin_source_invalid', 'Hosted extension installation authority is malformed; use loadHostedExtensionRuntime.');
67
+ }
68
+ const generation = WEAK_MAP_GET(BASE_GENERATION, base);
69
+ if (generation === undefined || generation !== WEAK_MAP_GET(INSTALLATION_GENERATION, installation)) {
70
+ throw new PluginError('plugin_source_invalid', 'Hosted extension base and installation must originate from the same runtime generation.');
71
+ }
72
+ await assertCurrentGeneration(generation);
73
+ }
74
+ /** @internal Validate a metadata-only installation used by selection tests. */
75
+ export function assertHostedInstallationAuthority(value) {
76
+ if (typeof value !== 'object' ||
77
+ value === null ||
78
+ !WEAK_SET_HAS(INSTALLATION_AUTHORITY, value) ||
79
+ !ARRAY_IS_ARRAY(value.artifacts)) {
80
+ throw new PluginError('plugin_source_invalid', 'Hosted extension installation authority is malformed.');
81
+ }
82
+ }
83
+ async function installationAt(origin, generation) {
84
+ const root = generation.projectRoot;
85
+ if (root === undefined)
86
+ return frozenHostedPromiseValue({
87
+ installation: installation([], generation),
88
+ declarations: canonicalize([]),
89
+ });
90
+ const artifacts = [];
91
+ const declared = hostedDeclaredExtensions(root);
92
+ for (let index = 0; index < declared.length; index += 1) {
93
+ const { ref, entry } = declared[index];
94
+ const directory = pluginStoreDirectory(root, entry.name, entry.digest);
95
+ await verifyStoredPlugin(directory, entry.digest);
96
+ appendIntrinsicArray(artifacts, OBJECT_FREEZE({
97
+ ref,
98
+ name: entry.name,
99
+ version: entry.version,
100
+ directory,
101
+ digest: entry.digest,
102
+ manifestSha256: entry.manifestSha256,
103
+ }));
104
+ }
105
+ return frozenHostedPromiseValue({
106
+ installation: installation(artifacts, generation),
107
+ declarations: declarationSignature(declared),
108
+ });
109
+ }
110
+ function declaredExtensions(generation) {
111
+ const root = generation.projectRoot;
112
+ return {
113
+ signature: root === undefined ? canonicalize([]) : declarationSignature(hostedDeclaredExtensions(root)),
114
+ };
115
+ }
116
+ function newGeneration(origin) {
117
+ return {
118
+ origin,
119
+ projectRoot: findHostedProject(PATH_DIRNAME(origin)),
120
+ declarations: canonicalize([]),
121
+ sourceRoots: OBJECT_FREEZE([]),
122
+ sourceSha256: '',
123
+ };
124
+ }
125
+ async function assertCurrentGeneration(generation) {
126
+ let currentSource;
127
+ try {
128
+ currentSource = await hostedBaseSourceDigest(generation.sourceRoots);
129
+ }
130
+ catch {
131
+ throw new PluginError('plugin_source_invalid', 'Hosted extension runtime generation is no longer readable.');
132
+ }
133
+ if (declaredExtensions(generation).signature !== generation.declarations ||
134
+ currentSource !== generation.sourceSha256) {
135
+ throw new PluginError('plugin_source_invalid', 'Hosted extension runtime generation is stale; reload the base and installation together.');
136
+ }
137
+ }
138
+ async function baseAt(origin, generation) {
139
+ const snapshot = await createHostedBaseSnapshot(origin, generation.projectRoot ?? PATH_DIRNAME(origin));
140
+ generation.sourceRoots = snapshot.liveSources;
141
+ generation.sourceSha256 = snapshot.liveDigest;
142
+ try {
143
+ if (snapshot.snapshotFlowSha256 !== SOFTWARE_FACTORY_SHA256) {
144
+ throw new PluginError('plugin_source_invalid', 'Hosted capability isolation accepts only the reviewed Software Factory base source.');
145
+ }
146
+ const value = frozenHostedPromiseValue({
147
+ name: 'software-factory',
148
+ version: '2.0.22',
149
+ });
150
+ WEAK_SET_ADD(BASE_AUTHORITY, value);
151
+ WEAK_MAP_SET(BASE_GENERATION, value, generation);
152
+ return value;
153
+ }
154
+ finally {
155
+ await removeHostedBaseSnapshot(snapshot);
156
+ }
157
+ }
158
+ function installation(artifacts, generation) {
159
+ const artifactCopy = [];
160
+ for (let index = 0; index < artifacts.length; index += 1)
161
+ appendIntrinsicArray(artifactCopy, artifacts[index]);
162
+ const value = frozenHostedPromiseValue({ artifacts: frozenHostedPromiseValue(artifactCopy) });
163
+ WEAK_SET_ADD(INSTALLATION_AUTHORITY, value);
164
+ WEAK_MAP_SET(INSTALLATION_GENERATION, value, generation);
165
+ return value;
166
+ }
167
+ //# sourceMappingURL=hosted-extension-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-extension-runtime.js","sourceRoot":"","sources":["../src/hosted-extension-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C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EAAE,UAAU,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Source for the process that imports one hosted extension inside the Linux
3
+ * namespace assembled by hosted-extension-isolation.ts.
4
+ *
5
+ * Keep this dependency-free. The parent writes it to a private file and
6
+ * mounts that file read-only; the extension is not imported by the host.
7
+ */
8
+ export declare const HOSTED_EXTENSION_SANDBOX_SOURCE: string;
9
+ //# sourceMappingURL=hosted-extension-sandbox-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-extension-sandbox-source.d.ts","sourceRoot":"","sources":["../src/hosted-extension-sandbox-source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,QAsF3C,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Source for the process that imports one hosted extension inside the Linux
3
+ * namespace assembled by hosted-extension-isolation.ts.
4
+ *
5
+ * Keep this dependency-free. The parent writes it to a private file and
6
+ * mounts that file read-only; the extension is not imported by the host.
7
+ */
8
+ export const HOSTED_EXTENSION_SANDBOX_SOURCE = String.raw `
9
+ import { createReadStream, writeSync } from 'node:fs';
10
+ import { createInterface } from 'node:readline';
11
+ import { pathToFileURL } from 'node:url';
12
+
13
+ const lines = createInterface({ input: createReadStream(null, { fd: 0 }), crlfDelay: Infinity });
14
+ const iterator = lines[Symbol.asyncIterator]();
15
+ const send = value => writeSync(3, JSON.stringify(value) + '\n');
16
+ const receive = async () => {
17
+ const next = await iterator.next();
18
+ if (next.done) throw new Error('hosted capability channel closed');
19
+ return JSON.parse(next.value);
20
+ };
21
+ const subscriptionOf = handler => {
22
+ const trigger = handler?.trigger;
23
+ const filter = trigger?.filter;
24
+ if (trigger?.kind !== 'webhook' || filter === undefined
25
+ || typeof filter.provider !== 'string' || filter.provider !== trigger.name
26
+ || typeof filter.type !== 'string') return undefined;
27
+ const action = typeof filter.payload === 'object' && filter.payload !== null && !Array.isArray(filter.payload)
28
+ ? filter.payload.action : undefined;
29
+ if (action !== undefined && typeof action !== 'string') return undefined;
30
+ return action === undefined
31
+ ? { provider: filter.provider, event: filter.type }
32
+ : { provider: filter.provider, event: filter.type, action };
33
+ };
34
+ const matches = (subscription, identity) => subscription !== undefined
35
+ && subscription.provider === identity.provider
36
+ && subscription.event === identity.event
37
+ && (subscription.action === undefined || subscription.action === identity.action);
38
+
39
+ try {
40
+ const request = await receive();
41
+ if (request?.type !== 'execute' || typeof request.entry !== 'string'
42
+ || typeof request.surfaceRuntime !== 'string' || typeof request.capability !== 'string') {
43
+ throw new Error('malformed hosted extension execution request');
44
+ }
45
+ const runtime = await import(pathToFileURL(request.surfaceRuntime).href);
46
+ const authored = await import(pathToFileURL(request.entry).href);
47
+ const definition = runtime.getFlowDefinition(authored.default);
48
+ const selected = definition.handlers.filter(handler => matches(subscriptionOf(handler), request.identity));
49
+ if (selected.length !== 1) throw new Error('hosted event must match exactly one isolated extension handler');
50
+
51
+ let nextCall = 1;
52
+ let capabilityCalls = 0;
53
+ let completion;
54
+ const invoke = async value => {
55
+ capabilityCalls += 1;
56
+ if (capabilityCalls !== 1) throw new Error('hosted extension may invoke its capability once');
57
+ const id = nextCall++;
58
+ send({ type: 'capability', id, name: request.capability, request: value });
59
+ const response = await receive();
60
+ if (response?.type !== 'capability-result' || response.id !== id || typeof response.ok !== 'boolean') {
61
+ throw new Error('malformed hosted capability response');
62
+ }
63
+ if (!response.ok) throw new Error(typeof response.error === 'string' ? response.error : 'hosted capability refused');
64
+ return response.value;
65
+ };
66
+ const capabilities = Object.freeze({
67
+ cloud: Object.freeze({ babysitterTurn: Object.freeze({ queue: invoke }) }),
68
+ });
69
+ const available = Object.freeze({
70
+ capabilities,
71
+ done(reason) {
72
+ if (completion !== undefined) throw new Error('hosted extension completed more than once');
73
+ completion = reason;
74
+ },
75
+ });
76
+ const context = new Proxy(available, {
77
+ get(target, property, receiver) {
78
+ if (property !== 'capabilities' && property !== 'done') {
79
+ throw new Error('hosted extension context denies ' + String(property));
80
+ }
81
+ return Reflect.get(target, property, receiver);
82
+ },
83
+ has(_target, property) { return property === 'capabilities' || property === 'done'; },
84
+ ownKeys() { return ['capabilities', 'done']; },
85
+ });
86
+ await selected[0].body(context, request.input);
87
+ if (capabilityCalls !== 1) throw new Error('hosted extension did not invoke its capability exactly once');
88
+ if (completion !== 'success') throw new Error('hosted extension did not complete with success');
89
+ send({ type: 'result', completionReason: completion, capabilityCalls });
90
+ } catch (error) {
91
+ send({ type: 'error', message: error instanceof Error ? (error.stack ?? error.message) : String(error) });
92
+ process.exitCode = 1;
93
+ }
94
+ `;
95
+ //# sourceMappingURL=hosted-extension-sandbox-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-extension-sandbox-source.js","sourceRoot":"","sources":["../src/hosted-extension-sandbox-source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFxD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type BigIntStats } from 'node:fs';
2
+ import { type HostedExtensionProtocolResult } from './hosted-extension-protocol.js';
3
+ export interface CapturedExecutable {
4
+ readonly descriptor: number;
5
+ readonly sha256: string;
6
+ readonly stat: BigIntStats;
7
+ }
8
+ export interface RunHostedExtensionSandboxOptions {
9
+ readonly artifactDirectory: string;
10
+ readonly artifactDigest: string;
11
+ readonly entry: string;
12
+ readonly surfaceVersion: string;
13
+ readonly identity: {
14
+ readonly provider: string;
15
+ readonly event: string;
16
+ readonly action?: string;
17
+ };
18
+ readonly input: unknown;
19
+ readonly invoke: (request: unknown) => Promise<unknown>;
20
+ readonly timeoutMs?: number;
21
+ readonly bubblewrapPath?: string;
22
+ readonly nodePath?: string;
23
+ readonly prlimitPath?: string;
24
+ /** @internal Test seam for a package root with the exact pinned runtime bytes. */
25
+ readonly surfaceRoot?: string;
26
+ /** @internal Last parent-side authority check after private snapshots exist. */
27
+ readonly beforeLaunch?: () => Promise<void>;
28
+ }
29
+ export declare function runHostedExtensionSandbox(options: RunHostedExtensionSandboxOptions): Promise<HostedExtensionProtocolResult>;
30
+ /** @internal Pure construction seam for hostile-intrinsic regressions. */
31
+ export declare function sandboxArguments(input: {
32
+ dataDestinations: readonly string[];
33
+ }): string[];
34
+ /** @internal Descriptor-pinning seam for the executable replacement regression. */
35
+ export declare function captureExecutable(path: string, name: string): CapturedExecutable;
36
+ /** @internal Reads the inode captured before authored code could replace its path. */
37
+ export declare function readCapturedExecutable(capture: CapturedExecutable, name: string): Buffer;
38
+ export declare function supportsHostedSandboxFlags(version: string): boolean;
39
+ //# sourceMappingURL=hosted-extension-sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-extension-sandbox.d.ts","sourceRoot":"","sources":["../src/hosted-extension-sandbox.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAsBjB,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,gCAAgC,CAAC;AA0FxC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B;AAED,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAA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