@opencode/codemode 2.2.7 → 2.3.0

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 (197) hide show
  1. package/README.md +11 -13
  2. package/dist/{vm/async.d.ts → async.d.ts} +1 -1
  3. package/dist/codemode.d.ts +8 -22
  4. package/dist/codemode.js +17 -38
  5. package/dist/data.d.ts +4 -19
  6. package/dist/data.js +1 -82
  7. package/dist/extension.d.ts +8 -2
  8. package/dist/extension.js +9 -0
  9. package/dist/{vm/host.d.ts → host.d.ts} +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/{vm/opcodes.d.ts → opcodes.d.ts} +1 -1
  12. package/dist/{vm/prelude → prelude}/helpers.js +1 -1
  13. package/dist/{vm/runtime → runtime}/driver.d.ts +1 -1
  14. package/dist/{vm/runtime → runtime}/driver.js +1 -1
  15. package/dist/{vm/runtime → runtime}/errors.js +2 -2
  16. package/dist/{vm/runtime → runtime}/execute.d.ts +17 -8
  17. package/dist/{vm/runtime → runtime}/execute.js +11 -9
  18. package/dist/{vm/runtime → runtime}/extensions.d.ts +1 -1
  19. package/dist/{vm/runtime → runtime}/extensions.js +39 -4
  20. package/dist/{vm/runtime → runtime}/globals.js +1 -1
  21. package/dist/{vm/runtime → runtime}/interpreter.d.ts +1 -1
  22. package/dist/{vm/runtime → runtime}/model.d.ts +1 -1
  23. package/dist/{vm/runtime → runtime}/objects.d.ts +1 -1
  24. package/dist/{vm/runtime → runtime}/objects.js +1 -1
  25. package/dist/{vm/runtime → runtime}/operations.d.ts +1 -1
  26. package/dist/{vm/runtime → runtime}/operations.js +1 -1
  27. package/dist/scan.js +2 -2
  28. package/dist/{vm/scheduler.d.ts → scheduler.d.ts} +1 -1
  29. package/dist/{vm/snapshot → snapshot}/codec.d.ts +6 -5
  30. package/dist/{vm/snapshot → snapshot}/codec.js +12 -5
  31. package/dist/{vm/snapshot → snapshot}/snapshot.d.ts +8 -5
  32. package/dist/{vm/snapshot → snapshot}/snapshot.js +14 -3
  33. package/dist/{vm/snapshot.js → snapshot.js} +1 -1
  34. package/dist/stdlib/array.d.ts +14 -9
  35. package/dist/stdlib/array.js +89 -276
  36. package/dist/stdlib/bytes.d.ts +11 -7
  37. package/dist/stdlib/bytes.js +112 -79
  38. package/dist/stdlib/collections.d.ts +7 -7
  39. package/dist/stdlib/collections.js +30 -339
  40. package/dist/stdlib/console.d.ts +2 -2
  41. package/dist/stdlib/console.js +3 -3
  42. package/dist/stdlib/date.d.ts +2 -2
  43. package/dist/stdlib/date.js +21 -30
  44. package/dist/stdlib/headers.d.ts +2 -2
  45. package/dist/stdlib/headers.js +15 -33
  46. package/dist/stdlib/iterator.d.ts +2 -2
  47. package/dist/stdlib/iterator.js +10 -302
  48. package/dist/stdlib/json.d.ts +2 -2
  49. package/dist/stdlib/json.js +15 -31
  50. package/dist/stdlib/math.d.ts +2 -7
  51. package/dist/stdlib/math.js +6 -30
  52. package/dist/stdlib/number.d.ts +3 -3
  53. package/dist/stdlib/number.js +8 -8
  54. package/dist/stdlib/object.d.ts +4 -4
  55. package/dist/stdlib/object.js +12 -30
  56. package/dist/stdlib/regexp.d.ts +6 -5
  57. package/dist/stdlib/regexp.js +18 -13
  58. package/dist/stdlib/string.d.ts +2 -2
  59. package/dist/stdlib/string.js +53 -53
  60. package/dist/stdlib/url.d.ts +21 -9
  61. package/dist/stdlib/url.js +55 -55
  62. package/dist/stdlib/value.d.ts +3 -4
  63. package/dist/stdlib/value.js +5 -6
  64. package/dist/stdlib/web.d.ts +4 -4
  65. package/dist/stdlib/web.js +7 -7
  66. package/dist/tool-runtime.d.ts +14 -13
  67. package/dist/tool-runtime.js +245 -53
  68. package/dist/tool-schema.d.ts +5 -0
  69. package/dist/tool-schema.js +36 -16
  70. package/dist/tool.d.ts +24 -9
  71. package/dist/tool.js +15 -22
  72. package/dist/{vm/vm.d.ts → vm.d.ts} +3 -3
  73. package/dist/{vm/vm.js → vm.js} +1 -1
  74. package/package.json +3 -5
  75. package/dist/interpreter/callback.d.ts +0 -35
  76. package/dist/interpreter/callback.js +0 -98
  77. package/dist/interpreter/errors.js +0 -173
  78. package/dist/interpreter/execute.d.ts +0 -14
  79. package/dist/interpreter/execute.js +0 -207
  80. package/dist/interpreter/extensions.d.ts +0 -9
  81. package/dist/interpreter/extensions.js +0 -248
  82. package/dist/interpreter/generators.d.ts +0 -3
  83. package/dist/interpreter/generators.js +0 -168
  84. package/dist/interpreter/globals.js +0 -144
  85. package/dist/interpreter/interpreter.d.ts +0 -48
  86. package/dist/interpreter/interpreter.js +0 -2253
  87. package/dist/interpreter/intrinsics.d.ts +0 -15
  88. package/dist/interpreter/intrinsics.js +0 -105
  89. package/dist/interpreter/model.d.ts +0 -68
  90. package/dist/interpreter/model.js +0 -54
  91. package/dist/interpreter/native.d.ts +0 -17
  92. package/dist/interpreter/native.js +0 -35
  93. package/dist/interpreter/objects.d.ts +0 -301
  94. package/dist/interpreter/objects.js +0 -592
  95. package/dist/interpreter/promises.d.ts +0 -18
  96. package/dist/interpreter/promises.js +0 -292
  97. package/dist/interpreter/runner.d.ts +0 -178
  98. package/dist/interpreter/runner.js +0 -480
  99. package/dist/interpreter/scope.d.ts +0 -16
  100. package/dist/interpreter/scope.js +0 -79
  101. package/dist/suspend-error.d.ts +0 -24
  102. package/dist/suspend-error.js +0 -25
  103. package/dist/vm/data.d.ts +0 -7
  104. package/dist/vm/data.js +0 -13
  105. package/dist/vm/index.d.ts +0 -6
  106. package/dist/vm/index.js +0 -6
  107. package/dist/vm/runtime/errors.d.ts +0 -23
  108. package/dist/vm/runtime/globals.d.ts +0 -6
  109. package/dist/vm/runtime/limits.d.ts +0 -10
  110. package/dist/vm/runtime/limits.js +0 -19
  111. package/dist/vm/runtime/modules.d.ts +0 -4
  112. package/dist/vm/runtime/modules.js +0 -33
  113. package/dist/vm/runtime/references.d.ts +0 -8
  114. package/dist/vm/runtime/references.js +0 -51
  115. package/dist/vm/stdlib/array.d.ts +0 -16
  116. package/dist/vm/stdlib/array.js +0 -311
  117. package/dist/vm/stdlib/bytes.d.ts +0 -11
  118. package/dist/vm/stdlib/bytes.js +0 -222
  119. package/dist/vm/stdlib/collections.d.ts +0 -7
  120. package/dist/vm/stdlib/collections.js +0 -188
  121. package/dist/vm/stdlib/console.d.ts +0 -6
  122. package/dist/vm/stdlib/console.js +0 -93
  123. package/dist/vm/stdlib/date.d.ts +0 -2
  124. package/dist/vm/stdlib/date.js +0 -123
  125. package/dist/vm/stdlib/headers.d.ts +0 -2
  126. package/dist/vm/stdlib/headers.js +0 -92
  127. package/dist/vm/stdlib/iterator.d.ts +0 -2
  128. package/dist/vm/stdlib/iterator.js +0 -30
  129. package/dist/vm/stdlib/json.d.ts +0 -3
  130. package/dist/vm/stdlib/json.js +0 -42
  131. package/dist/vm/stdlib/math.d.ts +0 -3
  132. package/dist/vm/stdlib/math.js +0 -73
  133. package/dist/vm/stdlib/number.d.ts +0 -3
  134. package/dist/vm/stdlib/number.js +0 -72
  135. package/dist/vm/stdlib/object.d.ts +0 -6
  136. package/dist/vm/stdlib/object.js +0 -201
  137. package/dist/vm/stdlib/regexp.d.ts +0 -8
  138. package/dist/vm/stdlib/regexp.js +0 -119
  139. package/dist/vm/stdlib/string.d.ts +0 -2
  140. package/dist/vm/stdlib/string.js +0 -272
  141. package/dist/vm/stdlib/url.d.ts +0 -25
  142. package/dist/vm/stdlib/url.js +0 -255
  143. package/dist/vm/stdlib/value.d.ts +0 -6
  144. package/dist/vm/stdlib/value.js +0 -32
  145. package/dist/vm/stdlib/web.d.ts +0 -5
  146. package/dist/vm/stdlib/web.js +0 -97
  147. /package/dist/{vm/async.js → async.js} +0 -0
  148. /package/dist/{vm/code.d.ts → code.d.ts} +0 -0
  149. /package/dist/{vm/code.js → code.js} +0 -0
  150. /package/dist/{vm/compiler → compiler}/compile.d.ts +0 -0
  151. /package/dist/{vm/compiler → compiler}/compile.js +0 -0
  152. /package/dist/{vm/compiler → compiler}/scope.d.ts +0 -0
  153. /package/dist/{vm/compiler → compiler}/scope.js +0 -0
  154. /package/dist/{vm/generators.d.ts → generators.d.ts} +0 -0
  155. /package/dist/{vm/generators.js → generators.js} +0 -0
  156. /package/dist/{vm/host.js → host.js} +0 -0
  157. /package/dist/{vm/internal-prelude.d.ts → internal-prelude.d.ts} +0 -0
  158. /package/dist/{vm/internal-prelude.js → internal-prelude.js} +0 -0
  159. /package/dist/{vm/opcodes.js → opcodes.js} +0 -0
  160. /package/dist/{vm/prelude → prelude}/bytecode.d.ts +0 -0
  161. /package/dist/{vm/prelude → prelude}/bytecode.js +0 -0
  162. /package/dist/{vm/prelude → prelude}/bytecode.json +0 -0
  163. /package/dist/{vm/prelude → prelude}/helpers.d.ts +0 -0
  164. /package/dist/{vm/prelude → prelude}/prelude.d.ts +0 -0
  165. /package/dist/{vm/prelude → prelude}/prelude.js +0 -0
  166. /package/dist/{vm/prelude → prelude}/source.d.ts +0 -0
  167. /package/dist/{vm/prelude → prelude}/source.js +0 -0
  168. /package/dist/{vm/runtime → runtime}/callback.d.ts +0 -0
  169. /package/dist/{vm/runtime → runtime}/callback.js +0 -0
  170. /package/dist/{interpreter → runtime}/errors.d.ts +0 -0
  171. /package/dist/{vm/runtime → runtime}/generators.d.ts +0 -0
  172. /package/dist/{vm/runtime → runtime}/generators.js +0 -0
  173. /package/dist/{interpreter → runtime}/globals.d.ts +0 -0
  174. /package/dist/{vm/runtime → runtime}/interpreter.js +0 -0
  175. /package/dist/{vm/runtime → runtime}/intrinsic-names.d.ts +0 -0
  176. /package/dist/{vm/runtime → runtime}/intrinsic-names.js +0 -0
  177. /package/dist/{vm/runtime → runtime}/intrinsics.d.ts +0 -0
  178. /package/dist/{vm/runtime → runtime}/intrinsics.js +0 -0
  179. /package/dist/{interpreter → runtime}/limits.d.ts +0 -0
  180. /package/dist/{interpreter → runtime}/limits.js +0 -0
  181. /package/dist/{vm/runtime → runtime}/model.js +0 -0
  182. /package/dist/{interpreter → runtime}/modules.d.ts +0 -0
  183. /package/dist/{interpreter → runtime}/modules.js +0 -0
  184. /package/dist/{vm/runtime → runtime}/native.d.ts +0 -0
  185. /package/dist/{vm/runtime → runtime}/native.js +0 -0
  186. /package/dist/{vm/runtime → runtime}/promises.d.ts +0 -0
  187. /package/dist/{vm/runtime → runtime}/promises.js +0 -0
  188. /package/dist/{interpreter → runtime}/references.d.ts +0 -0
  189. /package/dist/{interpreter → runtime}/references.js +0 -0
  190. /package/dist/{vm/runtime → runtime}/signals.d.ts +0 -0
  191. /package/dist/{vm/runtime → runtime}/signals.js +0 -0
  192. /package/dist/{vm/runtime → runtime}/source.d.ts +0 -0
  193. /package/dist/{vm/runtime → runtime}/source.js +0 -0
  194. /package/dist/{vm/runtime → runtime}/table.d.ts +0 -0
  195. /package/dist/{vm/runtime → runtime}/table.js +0 -0
  196. /package/dist/{vm/scheduler.js → scheduler.js} +0 -0
  197. /package/dist/{vm/snapshot.d.ts → snapshot.d.ts} +0 -0
package/README.md CHANGED
@@ -61,6 +61,10 @@ only shape the model-visible signature. Without `output`, the signature uses `Pr
61
61
 
62
62
  Descriptions and schemas are model-visible contracts. Authorization belongs in `execute`.
63
63
 
64
+ Set `freeform: true` on a tool whose input is one required string field to let programs pass that string directly. For
65
+ `{ patchText: string }`, the catalog shows `tools.patch(patchText: string)`, and `tools.patch("*** Begin Patch...")`
66
+ delivers `{ patchText: "*** Begin Patch..." }` to validation, hooks and the executor. The object form still works.
67
+
64
68
  Nested records are the shorthand for ordinary namespaces. Use `Namespace.make` when a namespace needs a description:
65
69
 
66
70
  ```ts
@@ -97,13 +101,9 @@ runs before the call reaches the host, and a failing one denies it: the host fun
97
101
  catches the failure as a thrown error. A denied call fails the way the call itself would: a tool call or asynchronous
98
102
  global rejects its promise, and a synchronous global throws.
99
103
 
100
- ### Bytecode VM and suspending/resuming a run (experimental, `engine: "vm"`)
101
-
102
- Pass `engine: "vm"` to `CodeMode.make` or `CodeMode.execute` to run programs on the bytecode VM instead of the default
103
- `"legacy"` AST interpreter. `runtime.execute(code, bindings?)` keeps the same `Effect<CodeMode.Result>` signature on
104
- both engines.
104
+ ### Suspending and resuming a run
105
105
 
106
- On `engine: "vm"`, `CodeMode.make` returns a `CodeMode.VmRuntime`, which can also run a program step by step:
106
+ `CodeMode.make` returns a `CodeMode.Runtime`, which can also run a program step by step:
107
107
  `runtime.program(code, bindings?, { runId }?)` makes a `CodeMode.Program`, and nothing runs until `program.run()`. Every
108
108
  host call gets a stable key `<runId>:<callId>` (using a generated UUID when `runId` is omitted), saved in the snapshot
109
109
  and passed to tools as `execute(input, { key })` and to hooks as `call.key`. `run()` runs the program in the current
@@ -115,7 +115,7 @@ type Suspended = {
115
115
  state: CodeMode.Snapshot // JSON; CodeMode.toBytes / CodeMode.fromBytes convert it
116
116
  }
117
117
 
118
- const runtime = CodeMode.make({ tools, engine: "vm" })
118
+ const runtime = CodeMode.make({ tools })
119
119
 
120
120
  // inline
121
121
  const outcome = yield* runtime.program(code).run()
@@ -130,8 +130,7 @@ const outcome = yield* Fiber.join(fiber)
130
130
  yield* runtime.resume(CodeMode.toBytes(suspended.state)).run()
131
131
  ```
132
132
 
133
- The default runtime has no `program` or `resume`, and ignores `Tool.idempotent`, `Tool.durable`, and extension
134
- `snapshot` hooks. A program runs once: running it again is a defect, so make another with `runtime.program` or
133
+ A program runs once: running it again is a defect, so make another with `runtime.program` or
135
134
  `runtime.resume`. `run()` owns the run's host calls: interrupting it interrupts the program and every call in progress
136
135
  (and cancels any started durable tool work).
137
136
 
@@ -173,8 +172,7 @@ Tool.make({
173
172
  - **`Tool.idempotent(execute)`:** idempotent/read-only work safe to run again. If a suspend lands while the call is
174
173
  running, the VM detaches and interrupts it without firing `tool.after`, saves the call in the snapshot as queued, and
175
174
  re-runs it on resume with the same `key` without double-counting it against `maxToolCalls`.
176
- - **`Tool.durable({ start, wait, cancel })`:** work that outlives a suspended run (when run without a suspend or on the
177
- legacy engine, it runs `start` then `wait`):
175
+ - **`Tool.durable({ start, wait, cancel })`:** work that outlives a suspended run:
178
176
  - `start(input, { key }) => Effect<Data /* Json */>` begins the work and returns JSON `data` (inferred into `wait`
179
177
  and `cancel`);
180
178
  - `wait(data, { key }) => Effect<Output>` connects to the running work and waits for its result;
@@ -205,7 +203,7 @@ extensions (and the same extension `snapshot` hooks). The state is checked when
205
203
  fails with a `CodeMode.SnapshotError` when it can't be resumed here or is malformed. Built-ins are saved by name and
206
204
  only their changes are copied.
207
205
 
208
- Set `CODEMODE_ROUNDTRIP=1` (`bun run test:roundtrip`) to run the tests on the VM with every run saved to bytes and
206
+ Set `CODEMODE_ROUNDTRIP=1` (`bun run test:roundtrip`) to run the tests with every run saved to bytes and
209
207
  restored into a brand-new runtime at every host call and every few steps.
210
208
 
211
209
  ### `Extension.make`
@@ -248,7 +246,7 @@ Every value crossing in either direction is converted, never shared: arguments c
248
246
  copies, and a function inside a result is callable the same way. A global that shadows a built-in or another
249
247
  extension throws at `CodeMode.make`.
250
248
 
251
- Functions inside a result have no data form, so a suspended VM run loses them by default: after a resume, calling one
249
+ Functions inside a result have no data form, so a suspended run loses them by default: after a resume, calling one
252
250
  throws a `TypeError`. An extension can preserve them across suspend and resume with `snapshot` hooks. `encode` receives
253
251
  a value one of the extension's functions returned, as the host function returned it, and returns plain data (JSON
254
252
  values and `Uint8Array`s); on resume, `decode` receives that data once per value and returns a host value of the same
@@ -1,4 +1,4 @@
1
- import type { Diagnostic } from "../codemode.js";
1
+ import type { Diagnostic } from "./codemode.js";
2
2
  import { type AstNode } from "./runtime/model.js";
3
3
  import { type Callable, PromiseObj, type Value } from "./runtime/objects.js";
4
4
  import { type Completion } from "./runtime/signals.js";
@@ -1,13 +1,12 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import type { Extension } from "./extension.js";
3
3
  import { scanTools } from "./scan.js";
4
- import { fromBytes, SnapshotError, SuspendError, toBytes } from "./suspend-error.js";
5
4
  import { type Services, type ToolDescription, ToolRuntime } from "./tool-runtime.js";
6
5
  import type { Tools } from "./tools.js";
7
- import type { VmEngine } from "./vm/index.js";
6
+ import { SuspendError } from "./runtime/execute.js";
7
+ import { fromBytes, type Snapshot, SnapshotError, type SnapshotHeader, toBytes } from "./snapshot/snapshot.js";
8
8
  export { fromBytes, scanTools, SnapshotError, SuspendError, toBytes };
9
- export type SnapshotHeader = VmEngine.SnapshotHeader;
10
- export type Snapshot = VmEngine.Snapshot;
9
+ export type { Snapshot, SnapshotHeader };
11
10
  /** A tool call admitted during an execution. */
12
11
  export type { CallResult, ExtensionInvocation, Hooks, ToolCall, ToolDescription, ToolInvocation, } from "./tool-runtime.js";
13
12
  /** Signature-construction helpers for host-owned catalog instructions. */
@@ -32,14 +31,12 @@ export type ResolvedExecutionLimits = {
32
31
  readonly maxToolCalls: number | undefined;
33
32
  readonly maxOutputBytes: number | undefined;
34
33
  };
35
- /** Execution engine: the default AST generator interpreter (`"legacy"`) or the experimental bytecode VM (`"vm"`). */
36
- export type Engine = "legacy" | "vm";
37
- /** Options for `VmRuntime.program`. */
34
+ /** Options for `Runtime.program`. */
38
35
  export type ProgramOptions = {
39
36
  /** Names this run's host calls (`<runId>:<callId>`); a random UUID by default. */
40
37
  readonly runId?: string;
41
38
  };
42
- /** How `program.suspend` saves a run's state (`engine: "vm"` only). */
39
+ /** How `program.suspend` saves a run's state. */
43
40
  export type SuspendOptions = {
44
41
  /** The most bytes a saved state may take; a larger one fails the suspend, and the run goes on. */
45
42
  readonly maxBytes?: number;
@@ -54,11 +51,6 @@ export type Options<Provided extends Record<string, unknown> = {}, Extensions ex
54
51
  extensions?: Extensions;
55
52
  /** Resource limits enforced on each execution. Time counts active time only, across every resume of a run. */
56
53
  limits?: ExecutionLimits;
57
- /**
58
- * Interpreter that runs programs. `"vm"` is the experimental bytecode VM, whose runtime (`VmRuntime`) can also
59
- * suspend and resume runs; the default is `"legacy"`.
60
- */
61
- engine?: Engine;
62
54
  };
63
55
  /** The Effect environment an execution needs: what the tools and the extensions' Effect globals require. */
64
56
  export type Environment<Provided extends Record<string, unknown>, Extensions extends ReadonlyArray<Extension>> = Services<Provided> | Extension.Services<Extensions[number]>;
@@ -166,20 +158,17 @@ export declare const Result: Schema.Union<readonly [Schema.Struct<{
166
158
  }>]>;
167
159
  /** Result of executing a CodeMode program. Program failures are data, not Effect failures. */
168
160
  export type Result = typeof Result.Type;
169
- /** A run stopped by `program.suspend`: its whole state, to resume with `VmRuntime.resume`. */
161
+ /** A run stopped by `program.suspend`: its whole state, to resume with `Runtime.resume`. */
170
162
  export type Suspended = {
171
163
  readonly ok: "suspended";
172
164
  readonly state: Snapshot;
173
165
  };
174
166
  /** How a run of a program ended: its result, or its saved state once suspended. */
175
167
  export type Outcome = Result | Suspended;
176
- /** Reusable confined runtime over explicit tools. */
168
+ /** Reusable confined runtime over explicit tools and extensions. */
177
169
  export type Runtime<R = never> = {
178
170
  readonly catalog: ReadonlyArray<ToolDescription>;
179
171
  readonly execute: (code: string, bindings?: Readonly<Record<string, DataValue>>) => Effect.Effect<Result, never, R>;
180
- };
181
- /** A runtime on the bytecode VM (`engine: "vm"`, experimental): it can also suspend runs and resume them. */
182
- export type VmRuntime<R = never> = Runtime<R> & {
183
172
  /** A program ready to run once; nothing runs until `program.run()`. */
184
173
  readonly program: (code: string, bindings?: Readonly<Record<string, DataValue>>, options?: ProgramOptions) => Program<R>;
185
174
  /**
@@ -190,7 +179,7 @@ export type VmRuntime<R = never> = Runtime<R> & {
190
179
  readonly resume: (state: Snapshot | Uint8Array) => Program<R, SnapshotError>;
191
180
  };
192
181
  /**
193
- * One run of a program on the VM. `run()` runs it in the current fiber until it ends or is suspended, and owns its host
182
+ * One run of a program. `run()` runs it in the current fiber until it ends or is suspended, and owns its host
194
183
  * calls: interrupting `run()` interrupts them. A program runs once: running it again is a defect.
195
184
  */
196
185
  export type Program<R = never, E = never> = {
@@ -206,7 +195,4 @@ export type Program<R = never, E = never> = {
206
195
  /** Executes one Effect-native CodeMode program without constructing a reusable runtime. */
207
196
  export declare const execute: <const Provided extends Record<string, unknown>, const Extensions extends ReadonlyArray<Extension> = []>(options: ExecuteOptions<Provided, Extensions>) => Effect.Effect<Result, never, Environment<Provided, Extensions>>;
208
197
  /** Creates an Effect-native runtime over explicit, schema-described tools and extensions. */
209
- export declare function make<const Provided extends Record<string, unknown> = {}, const Extensions extends ReadonlyArray<Extension> = []>(options: Options<Provided, Extensions> & {
210
- engine: "vm";
211
- }): VmRuntime<Environment<Provided, Extensions>>;
212
198
  export declare function make<const Provided extends Record<string, unknown> = {}, const Extensions extends ReadonlyArray<Extension> = []>(options?: Options<Provided, Extensions>): Runtime<Environment<Provided, Extensions>>;
package/dist/codemode.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Deferred, Effect, Exit, Schema } from "effect";
2
- import { fromJson } from "./data.js";
3
- import { executeProgram } from "./interpreter/execute.js";
4
- import { extensionGlobals } from "./interpreter/extensions.js";
5
- import { globalNames } from "./interpreter/globals.js";
6
2
  import { scanTools } from "./scan.js";
7
- import { fromBytes, SnapshotError, SuspendError, toBytes } from "./suspend-error.js";
8
3
  import { ToolRuntime } from "./tool-runtime.js";
4
+ import { fromJson } from "./data.js";
5
+ import { finishExecution, resumeProgram, startProgram, SuspendError } from "./runtime/execute.js";
6
+ import { extensionGlobals } from "./runtime/extensions.js";
7
+ import { globalNames } from "./runtime/globals.js";
8
+ import { fromBytes, SnapshotError, toBytes } from "./snapshot/snapshot.js";
9
9
  export { fromBytes, scanTools, SnapshotError, SuspendError, toBytes };
10
10
  /** Signature-construction helpers for host-owned catalog instructions. */
11
11
  export { searchSignature, toolExpression } from "./tool-runtime.js";
@@ -61,11 +61,11 @@ const resolveExecutionLimits = (limits) => ({
61
61
  });
62
62
  /** Executes one Effect-native CodeMode program without constructing a reusable runtime. */
63
63
  export const execute = (options) => make(options).execute(options.code, options.bindings);
64
+ /** Creates an Effect-native runtime over explicit, schema-described tools and extensions. */
64
65
  export function make(options = {}) {
65
66
  const prepared = ToolRuntime.prepare((options.tools ?? {}));
66
67
  const limits = resolveExecutionLimits(options.limits);
67
68
  const extensions = options.extensions ?? [];
68
- // Both engines bind the same global names; test/engines.test.ts keeps them in step.
69
69
  const bound = new Set(globalNames);
70
70
  for (const extension of extensions) {
71
71
  for (const name of Object.keys(extension.globals)) {
@@ -74,40 +74,28 @@ export function make(options = {}) {
74
74
  bound.add(name);
75
75
  }
76
76
  }
77
- if (options.engine !== "vm") {
78
- return {
79
- get catalog() {
80
- return prepared.catalog;
81
- },
82
- execute: (code, bindings) => executeProgram(code, prepared, limits, options.hooks ?? {}, (ctx) => [
83
- ...Object.entries(bindings ?? {}).map(([name, value]) => [name, fromJson(ctx, value)]),
84
- ...extensionGlobals(ctx, extensions),
85
- ]),
86
- };
87
- }
88
- let setup;
89
- const getSetup = (vm) => (setup ??= {
77
+ const setup = {
90
78
  prepared,
91
79
  limits,
92
80
  hooks: options.hooks ?? {},
93
- globals: extensions.length === 0 ? undefined : (ctx) => vm.extensionGlobals(ctx, extensions),
81
+ globals: extensions.length === 0 ? undefined : (ctx) => extensionGlobals(ctx, extensions),
94
82
  lossy: extensions.some((extension) => extension.snapshot === undefined),
95
- });
96
- const data = (vm, bindings) => bindings === undefined
83
+ };
84
+ const data = (bindings) => bindings === undefined
97
85
  ? undefined
98
- : (ctx) => Object.entries(bindings).map(([name, value]) => [name, vm.fromJson(ctx, value)]);
99
- const program = (code, bindings, programOptions) => vmProgram((vm) => Effect.succeed(vm.startProgram(getSetup(vm), code, data(vm, bindings), programOptions?.runId)));
86
+ : (ctx) => Object.entries(bindings).map(([name, value]) => [name, fromJson(ctx, value)]);
87
+ const program = (code, bindings, programOptions) => makeProgram(() => Effect.succeed(startProgram(setup, code, data(bindings), programOptions?.runId)));
100
88
  return {
101
89
  get catalog() {
102
90
  return prepared.catalog;
103
91
  },
104
- execute: (code, bindings) => Effect.flatMap(loadVm(), (vm) => vm.finishExecution(program(code, bindings).run())),
92
+ execute: (code, bindings) => Effect.suspend(() => finishExecution(program(code, bindings).run())),
105
93
  program,
106
- resume: (state) => vmProgram((vm) => vm.resumeProgram(getSetup(vm), state)),
94
+ resume: (state) => makeProgram(() => resumeProgram(setup, state)),
107
95
  };
108
96
  }
109
- // A program's one run: `start` makes it once the VM is loaded, and a suspend waits for it.
110
- const vmProgram = (start) => {
97
+ // A program's one run: `start` makes it when `run()` is called, and a suspend waits for it.
98
+ const makeProgram = (start) => {
111
99
  let claimed = false;
112
100
  const started = Deferred.makeUnsafe();
113
101
  return {
@@ -116,7 +104,7 @@ const vmProgram = (start) => {
116
104
  return Effect.die(new Error("A CodeMode program runs once; make another with runtime.program or runtime.resume."));
117
105
  }
118
106
  claimed = true;
119
- return loadVm().pipe(Effect.flatMap(start), Effect.onExit((exit) => Exit.isSuccess(exit)
107
+ return start().pipe(Effect.onExit((exit) => Exit.isSuccess(exit)
120
108
  ? Deferred.succeed(started, exit.value)
121
109
  : Deferred.fail(started, new SuspendError({ message: "The program didn't start.", running: [] }))), Effect.flatMap((running) => running.run()));
122
110
  }),
@@ -129,12 +117,3 @@ const vmProgram = (start) => {
129
117
  },
130
118
  };
131
119
  };
132
- // The VM is loaded on first use so the default engine pulls in none of its code.
133
- let vmLoaded;
134
- let vmEngine;
135
- const loadVm = () => vmLoaded !== undefined
136
- ? Effect.succeed(vmLoaded)
137
- : Effect.promise(() => (vmEngine ??= import("./vm/index.js").then((mod) => {
138
- vmLoaded = mod;
139
- return mod;
140
- })));
package/dist/data.d.ts CHANGED
@@ -1,21 +1,6 @@
1
- export * as Data from "./data.js";
2
- import type { Schema } from "effect";
3
- import type { Interpreter } from "./interpreter/interpreter.js";
4
- import { Obj, type Value } from "./interpreter/objects.js";
5
- import { type Eval } from "./interpreter/runner.js";
6
- export type Json = Schema.Json;
7
- type Replacer = (args: Array<Value>, holder: Obj) => Eval<Value>;
8
- /**
9
- * What `JSON.stringify` would serialize for a program value, as host JSON: `toJSON` is honored, functions and
10
- * `undefined` vanish, non-finite numbers become null, and everything else is copied. Two departures from JS
11
- * so a mistake is not a silent `{}`: an Error serializes as `{ name, message, ...own }`, and a promise throws.
12
- */
13
- export declare const toJson: <R>(ctx: Interpreter<R>, value: Value, replacer?: Replacer) => Eval<Schema.Json | undefined>;
14
- /**
15
- * The host boundary: `toJson`, plus what a program most likely meant when a value cannot be JSON. A promise is
16
- * awaited, a Set crosses as an array, a URLSearchParams as its query string, a Uint8Array asks to be encoded as
17
- * text first, and a `__proto__` key is dropped so host code can never receive one.
18
- */
19
- export declare const toBoundary: <R>(ctx: Interpreter<R>, value: Value) => Eval<Schema.Json | undefined>;
1
+ import type { Json } from "./snapshot/codec.js";
2
+ import type { Interpreter } from "./runtime/interpreter.js";
3
+ import { type Value } from "./runtime/objects.js";
4
+ export type { Json };
20
5
  /** Host JSON as program values: objects and arrays are copied, primitives pass through. */
21
6
  export declare const fromJson: <R>(ctx: Interpreter<R>, value: Json | undefined) => Value;
package/dist/data.js CHANGED
@@ -1,85 +1,4 @@
1
- export * as Data from "./data.js";
2
- import { MAX_VALUE_DEPTH } from "./interpreter/limits.js";
3
- import { invalidData, rangeError, typeError } from "./interpreter/model.js";
4
- import { Arr, Bytes, Callable, define, ErrorObj, get, keys, Obj, PromiseObj, record, SetObj, URLSearchParamsObj, HeadersObj, } from "./interpreter/objects.js";
5
- import { typeofValue } from "./interpreter/references.js";
6
- import { Slice } from "./interpreter/runner.js";
7
- /**
8
- * What `JSON.stringify` would serialize for a program value, as host JSON: `toJSON` is honored, functions and
9
- * `undefined` vanish, non-finite numbers become null, and everything else is copied. Two departures from JS
10
- * so a mistake is not a silent `{}`: an Error serializes as `{ name, message, ...own }`, and a promise throws.
11
- */
12
- export const toJson = (ctx, value, replacer) => walk(ctx, value, replacer, false);
13
- /**
14
- * The host boundary: `toJson`, plus what a program most likely meant when a value cannot be JSON. A promise is
15
- * awaited, a Set crosses as an array, a URLSearchParams as its query string, a Uint8Array asks to be encoded as
16
- * text first, and a `__proto__` key is dropped so host code can never receive one.
17
- */
18
- export const toBoundary = (ctx, value) => walk(ctx, value, undefined, true);
19
- const walk = (ctx, value, replacer, boundary) => {
20
- const stack = new Set();
21
- const visit = function* (holder, key, depth) {
22
- // Shared references expand into a tree, so the work is not bounded by the value's size or depth.
23
- if (ctx.runner.tick())
24
- yield Slice;
25
- if (depth > MAX_VALUE_DEPTH)
26
- throw rangeError(`Value exceeds the maximum depth of ${MAX_VALUE_DEPTH}.`);
27
- const raw = get(holder, key);
28
- if (raw instanceof PromiseObj && !boundary) {
29
- throw invalidData("JSON.stringify received an un-awaited Promise; await it first - e.g. `const result = await tools.ns.tool(...)`.");
30
- }
31
- const settled = raw instanceof PromiseObj ? yield* ctx.awaitValue(raw) : raw;
32
- const toJSON = settled instanceof Obj ? get(settled, "toJSON") : undefined;
33
- const own = toJSON instanceof Callable ? yield* ctx.call(toJSON, settled, [key]) : settled;
34
- const value = replacer === undefined ? own : yield* replacer([key, own], holder);
35
- if (value === undefined || typeofValue(value) === "function")
36
- return undefined;
37
- if (typeof value === "number")
38
- return Number.isFinite(value) ? value : null;
39
- if (value === null || typeof value === "string" || typeof value === "boolean")
40
- return value;
41
- if (!(value instanceof Obj))
42
- return {};
43
- if (boundary && value instanceof Bytes) {
44
- throw invalidData("A Uint8Array cannot cross to the host; pass text instead, e.g. `new TextDecoder().decode(bytes)` or `bytes.toBase64()`.");
45
- }
46
- if (boundary && value instanceof URLSearchParamsObj)
47
- return value.params.toString();
48
- if (value instanceof HeadersObj)
49
- return Object.fromEntries(value.headers);
50
- const target = boundary && value instanceof SetObj ? new Arr(ctx.builtins.Array, [...value.set]) : value;
51
- if (stack.has(target))
52
- throw typeError("Converting circular structure to JSON.");
53
- stack.add(target);
54
- if (target instanceof Arr) {
55
- const items = [];
56
- for (let index = 0; index < target.items.length; index += 1) {
57
- items.push((yield* visit(target, String(index), depth + 1)) ?? null);
58
- }
59
- stack.delete(target);
60
- return items;
61
- }
62
- const copied = {};
63
- // Own data property regardless of the key, so "__proto__" never reaches the Object.prototype setter.
64
- const put = (name, item) => {
65
- if (item !== undefined)
66
- Object.defineProperty(copied, name, { value: item, enumerable: true, writable: true, configurable: true });
67
- };
68
- // Errors serialize as { name, message, ...own }: both may be inherited, and neither is enumerable in JS.
69
- if (target instanceof ErrorObj) {
70
- put("name", yield* visit(target, "name", depth + 1));
71
- put("message", yield* visit(target, "message", depth + 1));
72
- }
73
- for (const name of keys(target)) {
74
- if (boundary && name === "__proto__")
75
- continue;
76
- put(name, yield* visit(target, name, depth + 1));
77
- }
78
- stack.delete(target);
79
- return copied;
80
- };
81
- return visit(record(ctx.builtins.Object, { "": value }), "", 0);
82
- };
1
+ import { Arr, define, Obj } from "./runtime/objects.js";
83
2
  /** Host JSON as program values: objects and arrays are copied, primitives pass through. */
84
3
  export const fromJson = (ctx, value) => {
85
4
  if (value === null || typeof value !== "object")
@@ -11,12 +11,12 @@ import type { Effect } from "effect";
11
11
  * promise of an asynchronous global and by throwing from a synchronous one. Functions inside a global object are
12
12
  * called the same way, named by their path (`fs.readFile`).
13
13
  *
14
- * Programs can also `import` or `require` a global by its Node module name; see `interpreter/modules.ts`.
14
+ * Programs can also `import` or `require` a global by its Node module name; see `runtime/modules.ts`.
15
15
  */
16
16
  export type Extension<Globals extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>> = {
17
17
  readonly name: string;
18
18
  readonly globals: Globals;
19
- /** How a suspended run saves the values this extension's functions returned (`engine: "vm"` only); see `Snapshot`. */
19
+ /** How a suspended run saves the values this extension's functions returned; see `Snapshot`. */
20
20
  readonly snapshot?: Snapshot | undefined;
21
21
  };
22
22
  /**
@@ -37,6 +37,12 @@ export type Services<E> = E extends {
37
37
  type GlobalServices<Global> = Global extends (...args: never) => unknown ? Requirements<Global> : Global extends object ? Requirements<Global[keyof Global]> : never;
38
38
  type Requirements<F> = F extends (...args: never) => infer Result ? Effect.Services<Result> : never;
39
39
  export declare const make: <const Globals extends Readonly<Record<string, unknown>>>(options: Extension<Globals>) => Extension<Globals>;
40
+ /** A live fetch response whose I/O is owned by the host for the lifetime of the program. */
41
+ export declare class StreamingResponse {
42
+ readonly response: Response;
43
+ readonly redirected: boolean;
44
+ constructor(response: Response, redirected?: boolean);
45
+ }
40
46
  /** Marks a global that returns a Promise or an Effect, so a denied call rejects its promise instead of throwing. */
41
47
  export declare const async: <F extends Function>(global: F) => F;
42
48
  export declare const isAsync: (global: Function) => boolean;
package/dist/extension.js CHANGED
@@ -12,6 +12,15 @@ export const make = (options) => {
12
12
  };
13
13
  };
14
14
  const asyncGlobals = new WeakSet();
15
+ /** A live fetch response whose I/O is owned by the host for the lifetime of the program. */
16
+ export class StreamingResponse {
17
+ response;
18
+ redirected;
19
+ constructor(response, redirected = response.redirected) {
20
+ this.response = response;
21
+ this.redirected = redirected;
22
+ }
23
+ }
15
24
  const AsyncFunction = (async () => { }).constructor;
16
25
  /** Marks a global that returns a Promise or an Effect, so a denied call rejects its promise instead of throwing. */
17
26
  export const async = (global) => {
@@ -1,4 +1,4 @@
1
- import type { Diagnostic } from "../codemode.js";
1
+ import type { Diagnostic } from "./codemode.js";
2
2
  import { type Json } from "./data.js";
3
3
  import type { Interpreter } from "./runtime/interpreter.js";
4
4
  import { type AstNode } from "./runtime/model.js";
package/dist/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export * as Extension from "./extension.js";
3
3
  export * as Namespace from "./namespace.js";
4
4
  export * as Tool from "./tool.js";
5
5
  export * as OpenAPI from "./openapi/index.js";
6
- export { fromBytes, searchSignature, SnapshotError, SuspendError, toBytes, toolExpression, type Outcome, type Program, type ProgramOptions, type Snapshot, type SnapshotHeader, type Suspended, type SuspendOptions, type VmRuntime, } from "./codemode.js";
6
+ export { fromBytes, searchSignature, SnapshotError, SuspendError, toBytes, toolExpression, type Outcome, type Program, type ProgramOptions, type Runtime, type Snapshot, type SnapshotHeader, type Suspended, type SuspendOptions, } from "./codemode.js";
7
7
  export { ToolError, toolError } from "./tool-error.js";
@@ -1,4 +1,4 @@
1
- import type { DiagnosticKind } from "../codemode.js";
1
+ import type { DiagnosticKind } from "./codemode.js";
2
2
  import type { ErrorType } from "./runtime/intrinsics.js";
3
3
  /** Uninitialized lexical binding sentinel (temporal dead zone). */
4
4
  export declare const HOLE: unique symbol;
@@ -9,7 +9,7 @@ import { native, receiver } from "../runtime/native.js";
9
9
  import { Arr, Bytes, coerceToString, data, define, hidden, hasPrototype, keys, getOwn, IteratorObj, positionIterator, coerceToNumber, get, MapObj, Obj, PromiseObj, SetObj, WeakMapObj, WeakSetObj, } from "../runtime/objects.js";
10
10
  import { builtinCursor, requireIteratorObject } from "../runtime/operations.js";
11
11
  import { containsOpaqueReference, describeValue, isOpaque } from "../runtime/references.js";
12
- import { compareText } from "../../tool-runtime.js";
12
+ import { compareText } from "../tool-runtime.js";
13
13
  import { Invoke } from "../runtime/signals.js";
14
14
  const classes = { Array: Arr, Uint8Array: Bytes, Map: MapObj, Set: SetObj };
15
15
  export const helpers = (ctx) => {
@@ -1,6 +1,6 @@
1
1
  import { type Context, Effect } from "effect";
2
2
  import type { HostCall } from "../scheduler.js";
3
- import { type ToolRuntime } from "../../tool-runtime.js";
3
+ import { type ToolRuntime } from "../tool-runtime.js";
4
4
  import type { Vm } from "../vm.js";
5
5
  import { type Completion } from "./signals.js";
6
6
  /** What `Driver.run` returns once the run was suspended: its state is saved, and the VM stopped. */
@@ -1,5 +1,5 @@
1
1
  import { Cause, Effect, Exit, Fiber } from "effect";
2
- import { toolExpression } from "../../tool-runtime.js";
2
+ import { toolExpression } from "../tool-runtime.js";
3
3
  import { locate } from "./errors.js";
4
4
  import { PendingThrow } from "./model.js";
5
5
  import { abrupt, Interruption, normal } from "./signals.js";
@@ -1,5 +1,5 @@
1
- import { ToolError } from "../../tool-error.js";
2
- import { ToolRuntimeError } from "../../tool-runtime.js";
1
+ import { ToolError } from "../tool-error.js";
2
+ import { ToolRuntimeError } from "../tool-runtime.js";
3
3
  import { formatLocation, PendingThrow, Throw, sourceLocation } from "./model.js";
4
4
  import { containsRuntimeReference } from "./references.js";
5
5
  import { createErrorValue, isErrorType } from "./intrinsics.js";
@@ -1,13 +1,25 @@
1
1
  import { type Program } from "acorn";
2
- import { Effect } from "effect";
3
- import type { DataValue, Diagnostic, Outcome, ResolvedExecutionLimits, Result } from "../../codemode.js";
4
- import type { Extension } from "../../extension.js";
2
+ import { Cause, Effect, Schema } from "effect";
3
+ import type { Diagnostic, Outcome, ResolvedExecutionLimits, Result } from "../codemode.js";
5
4
  import { type Snapshot, SnapshotError } from "../snapshot/snapshot.js";
6
- import { ToolRuntime } from "../../tool-runtime.js";
7
- import { SuspendError } from "../../suspend-error.js";
5
+ import { ToolRuntime } from "../tool-runtime.js";
8
6
  import { Interpreter } from "./interpreter.js";
9
7
  import type { Value } from "./objects.js";
10
8
  import { Source } from "./source.js";
9
+ declare const SuspendError_base: Schema.Class<SuspendError, Schema.TaggedStruct<"SuspendError", {
10
+ readonly message: Schema.String;
11
+ readonly running: Schema.$Array<Schema.Struct<{
12
+ readonly key: Schema.String;
13
+ readonly path: Schema.String;
14
+ }>>;
15
+ }>, Cause.YieldableError>;
16
+ /**
17
+ * A suspend that failed, leaving the run running: `running` names each host call that blocked it by its key and its
18
+ * path (`tools.x.y`, `search`, or an extension function's path such as `fetch`). Empty when the state couldn't be
19
+ * saved or was too large.
20
+ */
21
+ export declare class SuspendError extends SuspendError_base {
22
+ }
11
23
  type Globals<R> = (ctx: Interpreter<R>) => ReadonlyArray<readonly [string, Value]>;
12
24
  /** How a runtime runs programs: its tools, limits, hooks, and host globals, shared by every run it starts. */
13
25
  export type Setup<R> = {
@@ -21,9 +33,6 @@ export type Setup<R> = {
21
33
  };
22
34
  /** Turns a suspended outcome into a failure, for callers that only run programs to their end. */
23
35
  export declare const finishExecution: <E, R>(outcome: Effect.Effect<Outcome, E, R>) => Effect.Effect<Result, E, R>;
24
- /** Runs a program on the VM with `CodeMode.make`'s extensions and JSON bindings. */
25
- export declare const execute: <R>(code: string, prepared: ToolRuntime.Prepared<R>, limits: ResolvedExecutionLimits, hooks: ToolRuntime.Hooks<R>, extensions: ReadonlyArray<Extension>, bindings: Readonly<Record<string, DataValue>> | undefined) => Effect.Effect<Result, never, R>;
26
- export declare const executeProgram: <R>(code: string, prepared: ToolRuntime.Prepared<R>, limits: ResolvedExecutionLimits, hooks: ToolRuntime.Hooks<R>, globals?: Globals<R>, bindings?: Globals<R>, lossy?: boolean) => Effect.Effect<Result, never, R>;
27
36
  /** A program ready to run on the VM: nothing runs until `run`. */
28
37
  export declare const startProgram: <R>(setup: Setup<R>, code: string, bindings?: Globals<R>, runId?: string) => Running<R>;
29
38
  /**
@@ -1,17 +1,24 @@
1
1
  import { parse } from "acorn";
2
2
  import { Cause, Deferred, Effect, Option, Schema } from "effect";
3
- import { fromJson } from "../data.js";
4
3
  import { fromBytes, header, SnapshotError, toBytes } from "../snapshot/snapshot.js";
5
- import { ToolRuntime } from "../../tool-runtime.js";
6
- import { SuspendError } from "../../suspend-error.js";
4
+ import { ToolRuntime } from "../tool-runtime.js";
7
5
  import { normalizeError } from "./errors.js";
8
- import { extensionGlobals } from "./extensions.js";
9
6
  import { createBuiltins } from "./intrinsics.js";
10
7
  import { Interpreter } from "./interpreter.js";
11
8
  import { formatLocation, sourceLocation } from "./model.js";
12
9
  import { callPath, Driver, SUSPENDED } from "./driver.js";
13
10
  import { Interruption } from "./signals.js";
14
11
  import { Source } from "./source.js";
12
+ /**
13
+ * A suspend that failed, leaving the run running: `running` names each host call that blocked it by its key and its
14
+ * path (`tools.x.y`, `search`, or an extension function's path such as `fetch`). Empty when the state couldn't be
15
+ * saved or was too large.
16
+ */
17
+ export class SuspendError extends Schema.TaggedError()("SuspendError", {
18
+ message: Schema.String,
19
+ running: Schema.Array(Schema.Struct({ key: Schema.String, path: Schema.String })),
20
+ }) {
21
+ }
15
22
  /** Turns a suspended outcome into a failure, for callers that only run programs to their end. */
16
23
  export const finishExecution = (outcome) => Effect.map(outcome, (outcome) => {
17
24
  if (outcome.ok !== "suspended")
@@ -22,11 +29,6 @@ export const finishExecution = (outcome) => Effect.map(outcome, (outcome) => {
22
29
  toolCalls: outcome.state.header.toolCalls,
23
30
  };
24
31
  });
25
- /** Runs a program on the VM with `CodeMode.make`'s extensions and JSON bindings. */
26
- export const execute = (code, prepared, limits, hooks, extensions, bindings) => executeProgram(code, prepared, limits, hooks, extensions.length === 0 ? undefined : (ctx) => extensionGlobals(ctx, extensions), bindings === undefined
27
- ? undefined
28
- : (ctx) => Object.entries(bindings).map(([name, value]) => [name, fromJson(ctx, value)]), extensions.some((extension) => extension.snapshot === undefined));
29
- export const executeProgram = (code, prepared, limits, hooks, globals, bindings, lossy = false) => finishExecution(startProgram({ prepared, limits, hooks, globals, lossy }, code, bindings).run());
30
32
  /** A program ready to run on the VM: nothing runs until `run`. */
31
33
  export const startProgram = (setup, code, bindings, runId = crypto.randomUUID()) => new Running(setup, 0, () => {
32
34
  if (code.trim().length === 0) {
@@ -1,4 +1,4 @@
1
- import { type Extension } from "../../extension.js";
1
+ import { type Extension } from "../extension.js";
2
2
  import type { Interpreter } from "./interpreter.js";
3
3
  import { type AstNode } from "./model.js";
4
4
  import { PromiseObj, type Value } from "./objects.js";