@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/Program.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * A loaded bundle and the runtime's step function over it (spec 0.39.0 §5.1).
2
+ * A loaded bundle and the runtime's step function over it (spec 0.40.0 §5.1,
3
+ * 0.41.0 §6).
3
4
  *
4
5
  * Every value crossing the binding is encoded and decoded with the contract
5
6
  * schemas generated from the Rust types. JSON the binding returns that does
6
7
  * not decode is contract drift — a defect.
7
8
  */
8
- import { Effect, Option } from "effect";
9
+ import { Effect, Option, Schema } from "effect";
9
10
  import * as Errors from "./Errors.js";
10
11
  import * as Contract from "./generated/Contract.js";
11
12
  import type * as Glue from "./wasm/lute_runtime_wasm.js";
@@ -14,6 +15,11 @@ declare const TypeId = "~@lute-lang/runtime/RuntimeState";
14
15
  * An opaque, immutable runtime state. Stepping from it never invalidates it,
15
16
  * so a host may keep earlier states (undo, branching). Its serialized form
16
17
  * is {@link Program.snapshot}.
18
+ *
19
+ * A state is valid for every `Program` loaded from a bundle with the
20
+ * fingerprint of the program that created it (spec 0.41.0 §6.2): a host may
21
+ * query the state of a session it does not drive with its own program of
22
+ * that bundle. Handing it to a program of another fingerprint is a defect.
17
23
  */
18
24
  export interface RuntimeState {
19
25
  readonly [TypeId]: typeof TypeId;
@@ -34,9 +40,32 @@ export interface Program {
34
40
  readonly eligibility: (state: RuntimeState, beat: string, member?: string) => Effect.Effect<Option.Option<Contract.Candidate>>;
35
41
  readonly clock: (state: RuntimeState) => Effect.Effect<Option.Option<Contract.ClockAt>>;
36
42
  readonly terminal: (state: RuntimeState) => Effect.Effect<boolean>;
43
+ readonly stage: (state: RuntimeState) => Effect.Effect<Contract.Stage>;
37
44
  readonly view: (state: RuntimeState, options?: {
38
45
  readonly facts?: boolean;
39
46
  }) => Effect.Effect<Contract.WorldView>;
47
+ /**
48
+ * Evaluate an IR `exprNode` — the `expr` of any `{cel, expr}` pair the IR
49
+ * carries, such as an objective's `visibleWhen.expr`, or the output of
50
+ * `lute expr` — over the state, as the runtime's walk reads a guard (spec
51
+ * 0.41.0 §5.1). A `param` node is not admitted: it is `InvalidInput`.
52
+ */
53
+ readonly evaluate: (state: RuntimeState, expr: Schema.Json) => Effect.Effect<Contract.Evaluation, Errors.QueryRejection>;
54
+ /**
55
+ * Evaluate the bundle's index def `name` over the state, binding its
56
+ * parameters to `args` in declaration order — one JSON scalar each, absent
57
+ * for a parameterless def (spec 0.41.0 §5.1). A wrong arity or an argument
58
+ * that does not fit its parameter type is `InvalidInput`.
59
+ */
60
+ readonly def: (state: RuntimeState, name: string, args?: ReadonlyArray<string | number | boolean>) => Effect.Effect<Contract.Evaluation, Errors.QueryRejection>;
61
+ /**
62
+ * Whether a `raiseOccasion` of `occasion` (for `target`) with no writes
63
+ * would pass the seam now (spec 0.41.0 §5.2): `open: false` without
64
+ * `unresolved` is decided closed (its `raisedWhen` is false, or the game
65
+ * is over and the occasion is not `outsideRun`); with `unresolved`, it is
66
+ * undecided. An occasion the bundle does not declare is `InvalidInput`.
67
+ */
68
+ readonly gate: (state: RuntimeState, occasion: string, target?: string) => Effect.Effect<Contract.Gate, Errors.InvalidInput>;
40
69
  }
41
70
  /** Fail with a rejection the binding returned as JSON. */
42
71
  export declare const rejection: (json: string) => Effect.Effect<never, Errors.RuntimeRejection>;
package/dist/Replay.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Replaying a recorded input log (spec 0.39.0 §5.4). Against the bundle
2
+ * Replaying a recorded input log (spec 0.40.0 §5.4). Against the bundle
3
3
  * that recorded it, a log reproduces every output.
4
4
  */
5
5
  import { Effect, Schema, Stream } from "effect";
package/dist/Session.d.ts CHANGED
@@ -1,23 +1,32 @@
1
1
  /**
2
- * One running playthrough (spec 0.39.0 §5.2): the host sends inputs, watches
3
- * the state, and subscribes to events and awaits. The session adds no game
4
- * policy — it answers nothing and paces nothing.
2
+ * One running playthrough (spec 0.40.0 §5.2, 0.41.0 §6.2): the host sends
3
+ * inputs, watches the state, subscribes to events and awaits, and queries the
4
+ * state through the session's program. The session adds no game policy — it
5
+ * answers nothing and paces nothing.
5
6
  */
6
7
  import { Context, Effect, Layer, Scope, Stream, SubscriptionRef } from "effect";
7
8
  import { BundleSource } from "./BundleSource.js";
8
9
  import type { BundleError, InputLogError, RuntimeRejection } from "./Errors.js";
9
- import type { Await, Event, Input, Output, Seed, Snapshot } from "./generated/Contract.js";
10
+ import type { Await, Event, Input, Output, Seed, Snapshot, Stage } from "./generated/Contract.js";
10
11
  import { InputLog } from "./InputLog.js";
11
12
  import { LuteRuntime } from "./LuteRuntime.js";
12
- import type { RuntimeState } from "./Program.js";
13
- /** Where the session stands: its state and what it waits for. */
13
+ import type { Program, RuntimeState } from "./Program.js";
14
+ /** Where the session stands: its state, stage, and what it waits for. */
14
15
  export interface SessionState {
15
16
  readonly state: RuntimeState;
17
+ readonly stage: Stage;
16
18
  readonly await: Await;
17
19
  }
18
- declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Session", {
20
+ /** The session service. */
21
+ export interface SessionShape {
19
22
  /** The program's fingerprint (what snapshots carry). */
20
23
  readonly fingerprint: string;
24
+ /**
25
+ * The program the layer loaded, valid for the session's scope: run
26
+ * `view`, `evaluate`, `def`, `gate`, `candidates` … over `current`'s state
27
+ * without loading the bundle a second time.
28
+ */
29
+ readonly program: Program;
21
30
  /** The output of `begin`; for a restored session, no events and the snapshot's await. */
22
31
  readonly started: Output;
23
32
  /**
@@ -38,7 +47,8 @@ declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Se
38
47
  readonly save: Effect.Effect<Snapshot>;
39
48
  /** Continue from a snapshot; the input log restarts from it. */
40
49
  readonly restore: (snapshot: Snapshot) => Effect.Effect<void, RuntimeRejection | InputLogError>;
41
- }>;
50
+ }
51
+ declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Session", SessionShape>;
42
52
  export declare class Session extends Session_base {
43
53
  }
44
54
  /** How a session starts: from a seed, or from a snapshot. */
package/dist/browser.js CHANGED
@@ -1,28 +1,28 @@
1
1
  import {
2
- LuteWasm,
3
2
  WasmLoadError,
4
- fromBytes,
3
+ url,
4
+ memory,
5
5
  keyValueStore,
6
+ LuteWasm2,
7
+ fromBytes,
6
8
  layer,
7
- layer1 as layer2,
8
- memory,
9
- url
10
- } from "./index-eqt12qy0.js";
9
+ layer2
10
+ } from "./index-tecmws3f.js";
11
11
 
12
12
  // src/browser.ts
13
13
  import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
14
14
  import { Effect, Layer } from "effect";
15
15
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
16
16
  import * as HttpClient from "effect/http/HttpClient";
17
- var wasm = (url2) => Layer.effect(LuteWasm, HttpClient.get(url2).pipe(Effect.flatMap((response) => response.arrayBuffer), Effect.mapError((error) => new WasmLoadError({ message: `cannot fetch the runtime binding: ${error.message}` })), Effect.flatMap(fromBytes))).pipe(Layer.provide(FetchHttpClient.layer));
18
- var runtime = (url2) => layer.pipe(Layer.provide(wasm(url2)));
17
+ var wasm = (url) => Layer.effect(LuteWasm2, HttpClient.get(url).pipe(Effect.flatMap((response) => response.arrayBuffer), Effect.mapError((error) => new WasmLoadError({ message: `cannot fetch the runtime binding: ${error.message}` })), Effect.flatMap(fromBytes))).pipe(Layer.provide(FetchHttpClient.layer));
18
+ var runtime = (url) => layer.pipe(Layer.provide(wasm(url)));
19
19
  var bundle = (base) => url(base).pipe(Layer.provide(FetchHttpClient.layer));
20
20
  var inputLog = (key) => keyValueStore(key).pipe(Layer.provide(BrowserKeyValueStore.layerLocalStorage));
21
21
  var session = (options) => layer2(options).pipe(Layer.provide(Layer.mergeAll(runtime(options.wasm), bundle(options.bundle), options.log === undefined ? memory : inputLog(options.log))));
22
22
  export {
23
- wasm,
24
- session,
25
- runtime,
23
+ bundle,
26
24
  inputLog,
27
- bundle
25
+ runtime,
26
+ session,
27
+ wasm
28
28
  };
package/dist/bun.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import {
2
- LuteWasm,
3
2
  WasmLoadError,
4
3
  directory,
4
+ memory,
5
+ LuteWasm2,
5
6
  fromBytes,
6
7
  layer,
7
- layer1 as layer2,
8
- memory
9
- } from "./index-eqt12qy0.js";
8
+ layer2
9
+ } from "./index-tecmws3f.js";
10
10
 
11
11
  // src/bun.ts
12
12
  import * as BunServices from "@effect/platform-bun/BunServices";
13
13
  import { Effect, FileSystem, Layer, Path } from "effect";
14
- var wasm = Layer.effect(LuteWasm, Effect.gen(function* () {
14
+ var wasm = Layer.effect(LuteWasm2, Effect.gen(function* () {
15
15
  const fs = yield* FileSystem.FileSystem;
16
16
  const path = yield* Path.Path;
17
17
  const bytes = yield* path.fromFileUrl(new URL("./wasm/lute_runtime_wasm_bg.wasm", import.meta.url)).pipe(Effect.flatMap(fs.readFile), Effect.mapError((error) => new WasmLoadError({ message: `cannot read the runtime binding: ${error.message}` })));
@@ -21,8 +21,8 @@ var runtime = layer.pipe(Layer.provide(wasm));
21
21
  var bundle = (directory2) => directory(directory2).pipe(Layer.provide(BunServices.layer));
22
22
  var session = (options) => layer2(options).pipe(Layer.provide(Layer.mergeAll(runtime, bundle(options.bundle), options.log ?? memory)));
23
23
  export {
24
- wasm,
25
- session,
24
+ bundle,
26
25
  runtime,
27
- bundle
26
+ session,
27
+ wasm
28
28
  };