@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/README.md +64 -0
- package/dist/Bundle.d.ts +221 -8
- package/dist/BundleSource.d.ts +2 -2
- package/dist/Errors.d.ts +44 -3
- package/dist/InputLog.d.ts +123 -4
- package/dist/LuteRuntime.d.ts +1 -1
- package/dist/Program.d.ts +31 -2
- package/dist/Replay.d.ts +1 -1
- package/dist/Session.d.ts +18 -8
- package/dist/browser.js +12 -12
- package/dist/bun.js +8 -8
- package/dist/generated/Contract.d.ts +409 -15
- package/dist/generated/Ir.d.ts +2882 -0
- package/dist/index-tecmws3f.js +2168 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +32 -19
- package/dist/wasm/lute_runtime_wasm.d.ts +43 -0
- package/dist/wasm/lute_runtime_wasm.js +127 -0
- package/dist/wasm/lute_runtime_wasm_bg.wasm +0 -0
- package/dist/wasm/lute_runtime_wasm_bg.wasm.d.ts +8 -0
- package/package.json +2 -2
- package/dist/index-eqt12qy0.js +0 -857
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.
|
|
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
package/dist/Session.d.ts
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One running playthrough (spec 0.
|
|
3
|
-
* the state,
|
|
4
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
3
|
+
url,
|
|
4
|
+
memory,
|
|
5
5
|
keyValueStore,
|
|
6
|
+
LuteWasm2,
|
|
7
|
+
fromBytes,
|
|
6
8
|
layer,
|
|
7
|
-
|
|
8
|
-
|
|
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 = (
|
|
18
|
-
var runtime = (
|
|
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
|
-
|
|
24
|
-
session,
|
|
25
|
-
runtime,
|
|
23
|
+
bundle,
|
|
26
24
|
inputLog,
|
|
27
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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(
|
|
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
|
-
|
|
25
|
-
session,
|
|
24
|
+
bundle,
|
|
26
25
|
runtime,
|
|
27
|
-
|
|
26
|
+
session,
|
|
27
|
+
wasm
|
|
28
28
|
};
|