@lute-lang/runtime 0.39.0 → 0.41.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.
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * `@lute-lang/runtime` — the Lute runtime for TypeScript hosts, in Effect
3
- * (spec 0.39.0). Platform layers live in `@lute-lang/runtime/bun` and
3
+ * (spec 0.40.0 §5–§6, 0.41.0 §6). Platform layers live in `@lute-lang/runtime/bun` and
4
4
  * `@lute-lang/runtime/browser`.
5
5
  */
6
6
  export * as Bundle from "./Bundle.js";
7
7
  export * as BundleSource from "./BundleSource.js";
8
8
  export * as Contract from "./generated/Contract.js";
9
+ export * as Ir from "./generated/Ir.js";
9
10
  export * as Errors from "./Errors.js";
10
11
  export * as InputLog from "./InputLog.js";
11
12
  export * as LuteRuntime from "./LuteRuntime.js";
package/dist/index.js CHANGED
@@ -1,40 +1,53 @@
1
1
  import {
2
- LogEntry,
3
2
  __export,
4
- exports_Bundle,
3
+ projectIndex,
4
+ exports_Ir,
5
+ exports_Errors,
5
6
  exports_BundleSource,
6
7
  exports_Contract,
7
- exports_Errors,
8
+ LogEntry,
8
9
  exports_InputLog,
9
- exports_LuteRuntime,
10
10
  exports_LuteWasm,
11
11
  exports_Program,
12
+ exports_LuteRuntime,
12
13
  exports_Session
13
- } from "./index-eqt12qy0.js";
14
+ } from "./index-tecmws3f.js";
15
+
16
+ // src/Bundle.ts
17
+ var exports_Bundle = {};
18
+ __export(exports_Bundle, {
19
+ Bundle: () => Bundle
20
+ });
21
+ import { Schema } from "effect";
22
+ var Bundle = Schema.Struct({
23
+ index: projectIndex,
24
+ artifacts: Schema.Record(Schema.String, Schema.Json)
25
+ });
14
26
  // src/Replay.ts
15
27
  var exports_Replay = {};
16
28
  __export(exports_Replay, {
17
- run: () => run,
18
- parseLog: () => parseLog
29
+ parseLog: () => parseLog,
30
+ run: () => run
19
31
  });
20
- import { Effect, Schema, Stream } from "effect";
21
- var decodeLine = Schema.decodeUnknownEffect(Schema.fromJsonString(LogEntry));
32
+ import { Effect, Schema as Schema2, Stream } from "effect";
33
+ var decodeLine = Schema2.decodeUnknownEffect(Schema2.fromJsonString(LogEntry));
22
34
  var parseLog = (text) => Effect.forEach(text.split(`
23
35
  `).filter((line) => line.trim().length > 0), (line) => decodeLine(line));
24
36
  var run = (program, entries) => {
25
37
  const [start, ...inputs] = entries;
26
38
  const begun = start === undefined || "input" in start ? Effect.die(new Error("an input log starts with a seed or a snapshot")) : ("seed" in start) ? Effect.map(program.begin(start.seed), ({ state, output }) => ({ state, outputs: [output] })) : Effect.map(program.restore(start.snapshot), (state) => ({ state, outputs: [] }));
27
- return Stream.unwrap(Effect.map(begun, ({ state, outputs }) => Stream.fromIterable(inputs).pipe(Stream.mapAccumEffect(() => state, (state2, entry) => ("input" in entry) ? Effect.map(program.step(state2, entry.input), (step) => [step.state, [step.output]]) : Effect.die(new Error("an input log has one seed or snapshot, at its start"))), Stream.prepend(outputs))));
39
+ return Stream.unwrap(Effect.map(begun, ({ state, outputs }) => Stream.fromIterable(inputs).pipe(Stream.mapAccumEffect(() => state, (state, entry) => ("input" in entry) ? Effect.map(program.step(state, entry.input), (step) => [step.state, [step.output]]) : Effect.die(new Error("an input log has one seed or snapshot, at its start"))), Stream.prepend(outputs))));
28
40
  };
29
41
  export {
30
- exports_Session as Session,
31
- exports_Replay as Replay,
32
- exports_Program as Program,
33
- exports_LuteWasm as LuteWasm,
34
- exports_LuteRuntime as LuteRuntime,
35
- exports_InputLog as InputLog,
36
- exports_Errors as Errors,
37
- exports_Contract as Contract,
42
+ exports_Bundle as Bundle,
38
43
  exports_BundleSource as BundleSource,
39
- exports_Bundle as Bundle
44
+ exports_Contract as Contract,
45
+ exports_Errors as Errors,
46
+ exports_InputLog as InputLog,
47
+ exports_Ir as Ir,
48
+ exports_LuteRuntime as LuteRuntime,
49
+ exports_LuteWasm as LuteWasm,
50
+ exports_Program as Program,
51
+ exports_Replay as Replay,
52
+ exports_Session as Session
40
53
  };
@@ -33,10 +33,28 @@ export class Program {
33
33
  * The clock position, as `ClockAt` JSON or `null` without a clock.
34
34
  */
35
35
  clock(state: State): string;
36
+ /**
37
+ * Evaluate the bundle's def `name` over the state, its parameters bound
38
+ * to `args` (a JSON array of scalars, one per declared parameter;
39
+ * absent = `[]`), as `Evaluation` JSON; an unknown def, an argument
40
+ * fault or an evaluation error is rejected.
41
+ */
42
+ def(state: State, name: string, args?: string | null): QueryResult;
36
43
  /**
37
44
  * The verdict of `beat` (for `member`), as `Candidate` JSON or `null`.
38
45
  */
39
46
  eligibility(state: State, beat: string, member?: string | null): string;
47
+ /**
48
+ * Evaluate an IR `exprNode` (JSON) over the state, as `Evaluation`
49
+ * JSON; a malformed expression or an evaluation error is rejected.
50
+ */
51
+ evaluate(state: State, expr: string): QueryResult;
52
+ /**
53
+ * Whether a `raiseOccasion` of `occasion` (for `target`) with no writes
54
+ * would pass the seam now, as `Gate` JSON; an occasion the bundle does
55
+ * not declare is rejected.
56
+ */
57
+ gate(state: State, occasion: string, target?: string | null): QueryResult;
40
58
  /**
41
59
  * Load a `project.index.json` and an object mapping artifact paths to IR.
42
60
  *
@@ -53,6 +71,10 @@ export class Program {
53
71
  * contract's canonical form).
54
72
  */
55
73
  snapshot(state: State): string;
74
+ /**
75
+ * The persistent presentation stage as canonical JSON.
76
+ */
77
+ stage(state: State): string;
56
78
  /**
57
79
  * Apply a JSON input without invalidating the supplied state handle.
58
80
  */
@@ -68,6 +90,19 @@ export class Program {
68
90
  readonly fingerprint: string;
69
91
  }
70
92
 
93
+ /**
94
+ * The result of a query (`evaluate`, `def`, `gate`): its answer JSON
95
+ * (`Evaluation`, `Gate`) or a rejection.
96
+ */
97
+ export class QueryResult {
98
+ private constructor();
99
+ free(): void;
100
+ [Symbol.dispose](): void;
101
+ readonly ok: boolean;
102
+ readonly rejected: string | undefined;
103
+ readonly value: string | undefined;
104
+ }
105
+
71
106
  /**
72
107
  * The result of restoring a snapshot.
73
108
  */
@@ -108,6 +143,7 @@ export interface InitOutput {
108
143
  readonly memory: WebAssembly.Memory;
109
144
  readonly __wbg_loadresult_free: (a: number, b: number) => void;
110
145
  readonly __wbg_program_free: (a: number, b: number) => void;
146
+ readonly __wbg_queryresult_free: (a: number, b: number) => void;
111
147
  readonly __wbg_restoreresult_free: (a: number, b: number) => void;
112
148
  readonly __wbg_state_free: (a: number, b: number) => void;
113
149
  readonly __wbg_stepresult_free: (a: number, b: number) => void;
@@ -117,14 +153,21 @@ export interface InitOutput {
117
153
  readonly program_begin: (a: number, b: number, c: number) => number;
118
154
  readonly program_candidates: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
119
155
  readonly program_clock: (a: number, b: number) => [number, number];
156
+ readonly program_def: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
120
157
  readonly program_eligibility: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
158
+ readonly program_evaluate: (a: number, b: number, c: number, d: number) => number;
121
159
  readonly program_fingerprint: (a: number) => [number, number];
160
+ readonly program_gate: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
122
161
  readonly program_load: (a: number, b: number, c: number, d: number) => number;
123
162
  readonly program_restore: (a: number, b: number, c: number) => number;
124
163
  readonly program_snapshot: (a: number, b: number) => [number, number];
164
+ readonly program_stage: (a: number, b: number) => [number, number];
125
165
  readonly program_step: (a: number, b: number, c: number, d: number) => number;
126
166
  readonly program_terminal: (a: number, b: number) => number;
127
167
  readonly program_view: (a: number, b: number, c: number) => [number, number];
168
+ readonly queryresult_ok: (a: number) => number;
169
+ readonly queryresult_rejected: (a: number) => [number, number];
170
+ readonly queryresult_value: (a: number) => [number, number];
128
171
  readonly restoreresult_ok: (a: number) => number;
129
172
  readonly restoreresult_rejected: (a: number) => [number, number];
130
173
  readonly restoreresult_state: (a: number) => number;
@@ -123,6 +123,25 @@ export class Program {
123
123
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
124
124
  }
125
125
  }
126
+ /**
127
+ * Evaluate the bundle's def `name` over the state, its parameters bound
128
+ * to `args` (a JSON array of scalars, one per declared parameter;
129
+ * absent = `[]`), as `Evaluation` JSON; an unknown def, an argument
130
+ * fault or an evaluation error is rejected.
131
+ * @param {State} state
132
+ * @param {string} name
133
+ * @param {string | null} [args]
134
+ * @returns {QueryResult}
135
+ */
136
+ def(state, name, args) {
137
+ _assertClass(state, State);
138
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
139
+ const len0 = WASM_VECTOR_LEN;
140
+ var ptr1 = isLikeNone(args) ? 0 : passStringToWasm0(args, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
141
+ var len1 = WASM_VECTOR_LEN;
142
+ const ret = wasm.program_def(this.__wbg_ptr, state.__wbg_ptr, ptr0, len0, ptr1, len1);
143
+ return QueryResult.__wrap(ret);
144
+ }
126
145
  /**
127
146
  * The verdict of `beat` (for `member`), as `Candidate` JSON or `null`.
128
147
  * @param {State} state
@@ -147,6 +166,20 @@ export class Program {
147
166
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
148
167
  }
149
168
  }
169
+ /**
170
+ * Evaluate an IR `exprNode` (JSON) over the state, as `Evaluation`
171
+ * JSON; a malformed expression or an evaluation error is rejected.
172
+ * @param {State} state
173
+ * @param {string} expr
174
+ * @returns {QueryResult}
175
+ */
176
+ evaluate(state, expr) {
177
+ _assertClass(state, State);
178
+ const ptr0 = passStringToWasm0(expr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
179
+ const len0 = WASM_VECTOR_LEN;
180
+ const ret = wasm.program_evaluate(this.__wbg_ptr, state.__wbg_ptr, ptr0, len0);
181
+ return QueryResult.__wrap(ret);
182
+ }
150
183
  /**
151
184
  * @returns {string}
152
185
  */
@@ -162,6 +195,24 @@ export class Program {
162
195
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
163
196
  }
164
197
  }
198
+ /**
199
+ * Whether a `raiseOccasion` of `occasion` (for `target`) with no writes
200
+ * would pass the seam now, as `Gate` JSON; an occasion the bundle does
201
+ * not declare is rejected.
202
+ * @param {State} state
203
+ * @param {string} occasion
204
+ * @param {string | null} [target]
205
+ * @returns {QueryResult}
206
+ */
207
+ gate(state, occasion, target) {
208
+ _assertClass(state, State);
209
+ const ptr0 = passStringToWasm0(occasion, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
210
+ const len0 = WASM_VECTOR_LEN;
211
+ var ptr1 = isLikeNone(target) ? 0 : passStringToWasm0(target, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
212
+ var len1 = WASM_VECTOR_LEN;
213
+ const ret = wasm.program_gate(this.__wbg_ptr, state.__wbg_ptr, ptr0, len0, ptr1, len1);
214
+ return QueryResult.__wrap(ret);
215
+ }
165
216
  /**
166
217
  * Load a `project.index.json` and an object mapping artifact paths to IR.
167
218
  *
@@ -209,6 +260,24 @@ export class Program {
209
260
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
210
261
  }
211
262
  }
263
+ /**
264
+ * The persistent presentation stage as canonical JSON.
265
+ * @param {State} state
266
+ * @returns {string}
267
+ */
268
+ stage(state) {
269
+ let deferred1_0;
270
+ let deferred1_1;
271
+ try {
272
+ _assertClass(state, State);
273
+ const ret = wasm.program_stage(this.__wbg_ptr, state.__wbg_ptr);
274
+ deferred1_0 = ret[0];
275
+ deferred1_1 = ret[1];
276
+ return getStringFromWasm0(ret[0], ret[1]);
277
+ } finally {
278
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
279
+ }
280
+ }
212
281
  /**
213
282
  * Apply a JSON input without invalidating the supplied state handle.
214
283
  * @param {State} state
@@ -254,6 +323,61 @@ export class Program {
254
323
  }
255
324
  if (Symbol.dispose) Program.prototype[Symbol.dispose] = Program.prototype.free;
256
325
 
326
+ /**
327
+ * The result of a query (`evaluate`, `def`, `gate`): its answer JSON
328
+ * (`Evaluation`, `Gate`) or a rejection.
329
+ */
330
+ export class QueryResult {
331
+ static __wrap(ptr) {
332
+ const obj = Object.create(QueryResult.prototype);
333
+ obj.__wbg_ptr = ptr;
334
+ QueryResultFinalization.register(obj, obj.__wbg_ptr, obj);
335
+ return obj;
336
+ }
337
+ __destroy_into_raw() {
338
+ const ptr = this.__wbg_ptr;
339
+ this.__wbg_ptr = 0;
340
+ QueryResultFinalization.unregister(this);
341
+ return ptr;
342
+ }
343
+ free() {
344
+ const ptr = this.__destroy_into_raw();
345
+ wasm.__wbg_queryresult_free(ptr, 0);
346
+ }
347
+ /**
348
+ * @returns {boolean}
349
+ */
350
+ get ok() {
351
+ const ret = wasm.queryresult_ok(this.__wbg_ptr);
352
+ return ret !== 0;
353
+ }
354
+ /**
355
+ * @returns {string | undefined}
356
+ */
357
+ get rejected() {
358
+ const ret = wasm.queryresult_rejected(this.__wbg_ptr);
359
+ let v1;
360
+ if (ret[0] !== 0) {
361
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
362
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
363
+ }
364
+ return v1;
365
+ }
366
+ /**
367
+ * @returns {string | undefined}
368
+ */
369
+ get value() {
370
+ const ret = wasm.queryresult_value(this.__wbg_ptr);
371
+ let v1;
372
+ if (ret[0] !== 0) {
373
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
374
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
375
+ }
376
+ return v1;
377
+ }
378
+ }
379
+ if (Symbol.dispose) QueryResult.prototype[Symbol.dispose] = QueryResult.prototype.free;
380
+
257
381
  /**
258
382
  * The result of restoring a snapshot.
259
383
  */
@@ -414,6 +538,9 @@ const LoadResultFinalization = (typeof FinalizationRegistry === 'undefined')
414
538
  const ProgramFinalization = (typeof FinalizationRegistry === 'undefined')
415
539
  ? { register: () => {}, unregister: () => {} }
416
540
  : new FinalizationRegistry(ptr => wasm.__wbg_program_free(ptr, 1));
541
+ const QueryResultFinalization = (typeof FinalizationRegistry === 'undefined')
542
+ ? { register: () => {}, unregister: () => {} }
543
+ : new FinalizationRegistry(ptr => wasm.__wbg_queryresult_free(ptr, 1));
417
544
  const RestoreResultFinalization = (typeof FinalizationRegistry === 'undefined')
418
545
  ? { register: () => {}, unregister: () => {} }
419
546
  : new FinalizationRegistry(ptr => wasm.__wbg_restoreresult_free(ptr, 1));
Binary file
@@ -3,6 +3,7 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_loadresult_free: (a: number, b: number) => void;
5
5
  export const __wbg_program_free: (a: number, b: number) => void;
6
+ export const __wbg_queryresult_free: (a: number, b: number) => void;
6
7
  export const __wbg_restoreresult_free: (a: number, b: number) => void;
7
8
  export const __wbg_state_free: (a: number, b: number) => void;
8
9
  export const __wbg_stepresult_free: (a: number, b: number) => void;
@@ -12,14 +13,21 @@ export const loadresult_rejected: (a: number) => [number, number];
12
13
  export const program_begin: (a: number, b: number, c: number) => number;
13
14
  export const program_candidates: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
14
15
  export const program_clock: (a: number, b: number) => [number, number];
16
+ export const program_def: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
15
17
  export const program_eligibility: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
18
+ export const program_evaluate: (a: number, b: number, c: number, d: number) => number;
16
19
  export const program_fingerprint: (a: number) => [number, number];
20
+ export const program_gate: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
17
21
  export const program_load: (a: number, b: number, c: number, d: number) => number;
18
22
  export const program_restore: (a: number, b: number, c: number) => number;
19
23
  export const program_snapshot: (a: number, b: number) => [number, number];
24
+ export const program_stage: (a: number, b: number) => [number, number];
20
25
  export const program_step: (a: number, b: number, c: number, d: number) => number;
21
26
  export const program_terminal: (a: number, b: number) => number;
22
27
  export const program_view: (a: number, b: number, c: number) => [number, number];
28
+ export const queryresult_ok: (a: number) => number;
29
+ export const queryresult_rejected: (a: number) => [number, number];
30
+ export const queryresult_value: (a: number) => [number, number];
23
31
  export const restoreresult_ok: (a: number) => number;
24
32
  export const restoreresult_rejected: (a: number) => [number, number];
25
33
  export const restoreresult_state: (a: number) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lute-lang/runtime",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "The Lute runtime for TypeScript hosts, in Effect: load a compiled Lute bundle, drive the resumable step function, replay input logs (Bun and browsers).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "test": "bunx --bun vitest run",
36
36
  "test:browser": "bunx --bun vitest run --config vitest.browser.config.ts",
37
37
  "contract:gen": "bun scripts/contract-codegen.ts",
38
- "contract:check": "cargo run -q -p lute-runtime --features json-schema --bin lute-contract-schema && bun scripts/contract-codegen.ts && git diff --exit-code -- ../../schemas src/generated"
38
+ "contract:check": "cargo run -q -p lute-runtime --features json-schema --bin lute-contract-schema && bun scripts/contract-codegen.ts && git diff --exit-code -- ../../schemas src/generated ../player/src/bindings/schema.ts"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "effect": "4.0.2",