@enclave-vm/core 2.19.2 → 2.20.0-rc.1

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.
@@ -179,7 +179,7 @@ export declare class Interpreter {
179
179
  * For a host helper that is handed a callback (`parallel(items, fn)`): `fn` may be a function
180
180
  * of the script, or a built-in or host function the script passed along.
181
181
  */
182
- call(fn: unknown, args: unknown[]): unknown;
182
+ call(fn: unknown, args: unknown[]): Promise<unknown>;
183
183
  /** Number of AST nodes evaluated so far (for execution stats). */
184
184
  get stepCount(): number;
185
185
  run(program: ESTree.Program): Promise<unknown>;
@@ -244,9 +244,8 @@ export declare class Interpreter {
244
244
  private execSwitch;
245
245
  private execTry;
246
246
  /**
247
- * What a `catch` clause receives. A value the script threw is its own. A host Error (a refusal
248
- * by the interpreter, a failed tool call, a TypeError of a built-in) is replaced by a plain
249
- * copy with its name, message and code.
247
+ * What a `catch` clause receives. A value the script threw is its own. A host Error is copied
248
+ * with its name, message and code; every other host rejection reason becomes a generic error.
250
249
  */
251
250
  private toScriptValue;
252
251
  private evalExpr;
@@ -436,7 +435,7 @@ export declare function isScriptData(value: unknown): boolean;
436
435
  * number that is set) and the length the array has afterwards
437
436
  * @throws InterpreterError when the array would be longer than {@link MAX_ARRAY_LENGTH}
438
437
  */
439
- export declare function checkArrayWrite(array: unknown[], key: string, value: unknown): {
438
+ export declare function checkArrayWrite(array: unknown[], key: string, value: unknown, currentLength?: number): {
440
439
  value: unknown;
441
440
  length: number;
442
441
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enclave-vm/core",
3
- "version": "2.19.2",
3
+ "version": "2.20.0-rc.1",
4
4
  "description": "Sandbox runtime for secure JavaScript code execution",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "homepage": "https://github.com/agentfront/enclave",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/standalone": "^7.29.0",
47
- "@enclave-vm/ast": "2.19.2",
48
- "@enclave-vm/types": "2.19.2",
47
+ "@enclave-vm/ast": "2.20.0-rc.1",
48
+ "@enclave-vm/types": "2.20.0-rc.1",
49
49
  "@types/estree": "1.0.8",
50
50
  "acorn": "8.15.0",
51
51
  "acorn-walk": "8.3.4",
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Validated AgentScript execution for hosts without Node's VM modules.
3
+ * This entry point deliberately imports neither the Node VM nor its process hooks.
4
+ */
5
+ import { type InterpreterAdapterOptions } from './adapters/interpreter-adapter';
6
+ import type { CreateEnclaveOptions, ExecutionResult, ToolHandler } from './types';
7
+ export interface PortableEnclaveOptions extends CreateEnclaveOptions {
8
+ /** Interpreter work budgets; every value is finite and capped at construction. */
9
+ interpreter?: InterpreterAdapterOptions;
10
+ }
11
+ export interface PortableRunOptions {
12
+ maxToolResultBytes?: number;
13
+ onToolBridgeFailure?: () => void;
14
+ }
15
+ /**
16
+ * Runs the same raw-source pre-scan and AgentScript validation before handing code to the
17
+ * interpreter. Only the AgentScript preset and the string tool bridge are supported.
18
+ */
19
+ export declare class PortableEnclave {
20
+ private readonly options;
21
+ private readonly config;
22
+ private readonly preScanner;
23
+ private readonly validator;
24
+ private readonly adapter;
25
+ private readonly namespaces;
26
+ private readonly references?;
27
+ private readonly policyConfig;
28
+ private readonly customNames;
29
+ private disposed;
30
+ constructor(rawOptions?: PortableEnclaveOptions);
31
+ run<T = unknown>(code: string, toolHandler?: ToolHandler, runOptions?: PortableRunOptions): Promise<ExecutionResult<T>>;
32
+ dispose(): void;
33
+ }
34
+ /** The worker entry's CodeCall-facing contract for one validated AgentScript run. */
35
+ export interface AgentScriptRunnerOptions extends Omit<PortableEnclaveOptions, 'interpreter' | 'globals' | 'doubleVm' | 'maxGlobalFunctionCalls'> {
36
+ /** Each callback keeps its own parameter types; arguments are validated at the host boundary. */
37
+ hostFunctions: Readonly<Record<string, (...args: never[]) => unknown>>;
38
+ maxHostFunctionCalls: number;
39
+ maxSteps?: number;
40
+ maxCallDepth?: number;
41
+ maxPendingCalls?: number;
42
+ rapidEnumeration?: {
43
+ threshold?: number;
44
+ overrides?: Record<string, number>;
45
+ };
46
+ }
47
+ /** A narrow adapter for CodeCall's worker-safe runtime selection. */
48
+ export declare class AgentScriptRunner extends PortableEnclave {
49
+ static readonly capabilities: readonly string[];
50
+ constructor(options: AgentScriptRunnerOptions);
51
+ }
@@ -0,0 +1,2 @@
1
+ /** A bounded copy of host globals for the portable interpreter. */
2
+ export declare function copyPortableGlobals(globals: Record<string, unknown> | undefined, allowFunctions: boolean, maxBytes: number): Record<string, unknown>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The runtime half of "AgentScript has no regular expressions", shared by the VMs.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ /**
7
+ * Source of a statement evaluated in a sandbox realm (the inner realm of the double VM, the realm
8
+ * of the single VM) when a realm allowlist without `RegExp` is in force: it makes regular
9
+ * expressions unusable there.
10
+ *
11
+ * AgentScript has no regular expressions, and the validator refuses every way to write or run one.
12
+ * This is the runtime half of that rule: `String.prototype.match/matchAll/search` build a RegExp
13
+ * from a STRING argument inside the engine (no `RegExp` binding and no literal needed), and a
14
+ * backtracking pattern run that way is not interruptible work the iteration limit can see.
15
+ * Every regular expression of the realm reaches its matcher through `RegExp.prototype`, so the
16
+ * methods there are replaced by a function that throws, and the prototype is frozen.
17
+ */
18
+ export declare const REALM_REGEX_BACKSTOP_SOURCE: string;
@@ -20,6 +20,7 @@ export declare class ScoringGate {
20
20
  private scorer;
21
21
  private cache;
22
22
  private initialized;
23
+ private initializing;
23
24
  constructor(config: ScoringGateConfig);
24
25
  /**
25
26
  * Initialize the scoring gate
@@ -28,6 +29,7 @@ export declare class ScoringGate {
28
29
  * (e.g., local-llm needs to download the model)
29
30
  */
30
31
  initialize(): Promise<void>;
32
+ private setUpScorer;
31
33
  /**
32
34
  * Create the appropriate scorer based on configuration
33
35
  */
@@ -115,11 +115,16 @@ export declare class ReferenceResolver {
115
115
  /**
116
116
  * Check if a value contains any reference IDs
117
117
  *
118
+ * Every value is looked at, at any depth: a reference or composite past `maxResolutionDepth`
119
+ * cannot be resolved, and it must still be found, so that `resolve()` refuses the call rather
120
+ * than the handler receiving it unresolved. The value is walked with a list instead of by
121
+ * recursion, so a deep value cannot exhaust the stack, and an object is looked at once.
122
+ *
118
123
  * @param value - The value to check
119
- * @param depth - Current recursion depth (internal)
124
+ * @param _depth - Unused; kept for callers that pass a depth
120
125
  * @returns true if the value or any nested value is a reference
121
126
  */
122
- containsReferences(value: unknown, depth?: number): boolean;
127
+ containsReferences(value: unknown, _depth?: number): boolean;
123
128
  /**
124
129
  * Create a composite handle from multiple reference parts
125
130
  *
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enclave-vm/core",
3
- "version": "2.19.2",
3
+ "version": "2.20.0-rc.1",
4
4
  "description": "Sandbox runtime for secure JavaScript code execution",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "homepage": "https://github.com/agentfront/enclave",
@@ -46,8 +46,8 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@babel/standalone": "^7.29.0",
49
- "@enclave-vm/ast": "2.19.2",
50
- "@enclave-vm/types": "2.19.2",
49
+ "@enclave-vm/ast": "2.20.0-rc.1",
50
+ "@enclave-vm/types": "2.20.0-rc.1",
51
51
  "@types/estree": "1.0.8",
52
52
  "acorn": "8.15.0",
53
53
  "acorn-walk": "8.3.4",