@lute-lang/runtime 0.0.0-stage → 0.40.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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Loads bundles into {@link Program}s (spec 0.40.0 §5.1). A program lives in
3
+ * the scope that loaded it and is freed when the scope closes.
4
+ */
5
+ import { Context, Effect, Layer, Scope } from "effect";
6
+ import type { Bundle } from "./Bundle.js";
7
+ import type * as Errors from "./Errors.js";
8
+ import { LuteWasm } from "./LuteWasm.js";
9
+ import * as Program from "./Program.js";
10
+ declare const LuteRuntime_base: Context.ServiceClass<LuteRuntime, "@lute-lang/runtime/LuteRuntime", {
11
+ /**
12
+ * Load a bundle. `IrVersionMismatch` when the runtime does not execute
13
+ * it (another IR line, an unknown command kind, not a bundle).
14
+ */
15
+ readonly load: (bundle: Bundle) => Effect.Effect<Program.Program, Errors.RuntimeRejection, Scope.Scope>;
16
+ }>;
17
+ export declare class LuteRuntime extends LuteRuntime_base {
18
+ }
19
+ export declare const layer: Layer.Layer<LuteRuntime, never, LuteWasm>;
20
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The instantiated wasm binding (`crates/lute-runtime-wasm`) as a service.
3
+ *
4
+ * Platform layers (`@lute-lang/runtime/bun`, `@lute-lang/runtime/browser`)
5
+ * obtain the module's bytes and instantiate it through {@link fromBytes};
6
+ * nothing else in the package touches the glue's module state.
7
+ */
8
+ import { Context, Effect, Layer } from "effect";
9
+ import { WasmLoadError } from "./Errors.js";
10
+ import * as Glue from "./wasm/lute_runtime_wasm.js";
11
+ /** The binding's entry point: `Program.load` and the result classes it returns. */
12
+ export interface LuteWasmShape {
13
+ readonly Program: typeof Glue.Program;
14
+ }
15
+ declare const LuteWasm_base: Context.ServiceClass<LuteWasm, "@lute-lang/runtime/LuteWasm", LuteWasmShape>;
16
+ export declare class LuteWasm extends LuteWasm_base {
17
+ }
18
+ /**
19
+ * Instantiate the binding from the `.wasm` bytes. Bytes backed by a
20
+ * `SharedArrayBuffer` are refused: WebAssembly compiles from an
21
+ * `ArrayBuffer`.
22
+ */
23
+ export declare const fromBytes: (bytes: Uint8Array | ArrayBuffer) => Effect.Effect<LuteWasmShape, WasmLoadError>;
24
+ /** The binding instantiated from bytes the host already holds. */
25
+ export declare const layerFromBytes: (bytes: Uint8Array | ArrayBuffer) => Layer.Layer<LuteWasm, WasmLoadError>;
26
+ export {};
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A loaded bundle and the runtime's step function over it (spec 0.40.0 §5.1).
3
+ *
4
+ * Every value crossing the binding is encoded and decoded with the contract
5
+ * schemas generated from the Rust types. JSON the binding returns that does
6
+ * not decode is contract drift — a defect.
7
+ */
8
+ import { Effect, Option } from "effect";
9
+ import * as Errors from "./Errors.js";
10
+ import * as Contract from "./generated/Contract.js";
11
+ import type * as Glue from "./wasm/lute_runtime_wasm.js";
12
+ declare const TypeId = "~@lute-lang/runtime/RuntimeState";
13
+ /**
14
+ * An opaque, immutable runtime state. Stepping from it never invalidates it,
15
+ * so a host may keep earlier states (undo, branching). Its serialized form
16
+ * is {@link Program.snapshot}.
17
+ */
18
+ export interface RuntimeState {
19
+ readonly [TypeId]: typeof TypeId;
20
+ }
21
+ /** One accepted input: the state it produced and the runtime's output. */
22
+ export interface Step {
23
+ readonly state: RuntimeState;
24
+ readonly output: Contract.Output;
25
+ }
26
+ export interface Program {
27
+ /** The bundle's identity, which snapshots carry. */
28
+ readonly fingerprint: string;
29
+ readonly begin: (seed: Contract.Seed) => Effect.Effect<Step, Errors.RuntimeRejection>;
30
+ readonly step: (state: RuntimeState, input: Contract.Input) => Effect.Effect<Step, Errors.RuntimeRejection>;
31
+ readonly snapshot: (state: RuntimeState) => Effect.Effect<Contract.Snapshot>;
32
+ readonly restore: (snapshot: Contract.Snapshot) => Effect.Effect<RuntimeState, Errors.RuntimeRejection>;
33
+ readonly candidates: (state: RuntimeState, occasion: string, target?: string) => Effect.Effect<ReadonlyArray<Contract.Candidate>>;
34
+ readonly eligibility: (state: RuntimeState, beat: string, member?: string) => Effect.Effect<Option.Option<Contract.Candidate>>;
35
+ readonly clock: (state: RuntimeState) => Effect.Effect<Option.Option<Contract.ClockAt>>;
36
+ readonly terminal: (state: RuntimeState) => Effect.Effect<boolean>;
37
+ readonly stage: (state: RuntimeState) => Effect.Effect<Contract.Stage>;
38
+ readonly view: (state: RuntimeState, options?: {
39
+ readonly facts?: boolean;
40
+ }) => Effect.Effect<Contract.WorldView>;
41
+ }
42
+ /** Fail with a rejection the binding returned as JSON. */
43
+ export declare const rejection: (json: string) => Effect.Effect<never, Errors.RuntimeRejection>;
44
+ /** Wrap a program the binding loaded. The caller owns its lifetime ({@link free}). */
45
+ export declare const make: (raw: Glue.Program) => Program & {
46
+ readonly free: Effect.Effect<void>;
47
+ };
48
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Replaying a recorded input log (spec 0.40.0 §5.4). Against the bundle
3
+ * that recorded it, a log reproduces every output.
4
+ */
5
+ import { Effect, Schema, Stream } from "effect";
6
+ import type { RuntimeRejection } from "./Errors.js";
7
+ import type { Output } from "./generated/Contract.js";
8
+ import { LogEntry } from "./InputLog.js";
9
+ import type { Program } from "./Program.js";
10
+ /** Parse an `inputs.jsonl` text: one log entry per non-empty line. */
11
+ export declare const parseLog: (text: string) => Effect.Effect<ReadonlyArray<LogEntry>, Schema.SchemaError>;
12
+ /**
13
+ * The outputs of a log: `begin` for a `seed` start (a `snapshot` start
14
+ * restores and emits nothing), then one output per `input`. A log that does
15
+ * not start with a seed or snapshot, or restarts midway, dies.
16
+ */
17
+ export declare const run: (program: Program, entries: ReadonlyArray<LogEntry>) => Stream.Stream<Output, RuntimeRejection>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * One running playthrough (spec 0.40.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.
5
+ */
6
+ import { Context, Effect, Layer, Scope, Stream, SubscriptionRef } from "effect";
7
+ import { BundleSource } from "./BundleSource.js";
8
+ import type { BundleError, InputLogError, RuntimeRejection } from "./Errors.js";
9
+ import type { Await, Event, Input, Output, Seed, Snapshot, Stage } from "./generated/Contract.js";
10
+ import { InputLog } from "./InputLog.js";
11
+ import { LuteRuntime } from "./LuteRuntime.js";
12
+ import type { RuntimeState } from "./Program.js";
13
+ /** Where the session stands: its state, stage, and what it waits for. */
14
+ export interface SessionState {
15
+ readonly state: RuntimeState;
16
+ readonly stage: Stage;
17
+ readonly await: Await;
18
+ }
19
+ declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Session", {
20
+ /** The program's fingerprint (what snapshots carry). */
21
+ readonly fingerprint: string;
22
+ /** The output of `begin`; for a restored session, no events and the snapshot's await. */
23
+ readonly started: Output;
24
+ /**
25
+ * Apply one input. Inputs run one at a time, in call order. An accepted
26
+ * input is logged before its events are published; a rejected one
27
+ * changes nothing.
28
+ */
29
+ readonly send: (input: Input) => Effect.Effect<Output, RuntimeRejection | InputLogError>;
30
+ readonly current: SubscriptionRef.SubscriptionRef<SessionState>;
31
+ /**
32
+ * Subscribe to the events of every later output, in order. The
33
+ * subscription exists once this effect completes, so nothing published
34
+ * afterwards is missed; it ends with its scope or the session's.
35
+ */
36
+ readonly events: Effect.Effect<Stream.Stream<Event>, never, Scope.Scope>;
37
+ /** Subscribe to the await of every later output, like `events`. */
38
+ readonly awaits: Effect.Effect<Stream.Stream<Await>, never, Scope.Scope>;
39
+ readonly save: Effect.Effect<Snapshot>;
40
+ /** Continue from a snapshot; the input log restarts from it. */
41
+ readonly restore: (snapshot: Snapshot) => Effect.Effect<void, RuntimeRejection | InputLogError>;
42
+ }>;
43
+ export declare class Session extends Session_base {
44
+ }
45
+ /** How a session starts: from a seed, or from a snapshot. */
46
+ export type SessionOptions = {
47
+ readonly seed: Seed;
48
+ } | {
49
+ readonly snapshot: Snapshot;
50
+ };
51
+ /**
52
+ * A session over the bundle of `BundleSource`. The program it loads lives
53
+ * as long as the layer's scope; closing it ends `events` and `awaits`.
54
+ */
55
+ export declare const layer: (options: SessionOptions) => Layer.Layer<Session, RuntimeRejection | BundleError | InputLogError, LuteRuntime | BundleSource | InputLog>;
56
+ export {};
@@ -0,0 +1,25 @@
1
+ import { Layer } from "effect";
2
+ import * as BundleSource from "./BundleSource.js";
3
+ import { WasmLoadError } from "./Errors.js";
4
+ import * as InputLog from "./InputLog.js";
5
+ import * as LuteRuntime from "./LuteRuntime.js";
6
+ import * as LuteWasm from "./LuteWasm.js";
7
+ import * as Session from "./Session.js";
8
+ /** The binding fetched from `url` (where the host serves `lute_runtime_wasm_bg.wasm`). */
9
+ export declare const wasm: (url: string) => Layer.Layer<LuteWasm.LuteWasm, WasmLoadError>;
10
+ /** `LuteRuntime` over the binding at `url`. */
11
+ export declare const runtime: (url: string) => Layer.Layer<LuteRuntime.LuteRuntime, WasmLoadError>;
12
+ /** The bundle served under `base` (a URL ending in `/`). */
13
+ export declare const bundle: (base: string) => Layer.Layer<BundleSource.BundleSource>;
14
+ /** An input log kept in `localStorage` under `key`. */
15
+ export declare const inputLog: (key: string) => Layer.Layer<InputLog.InputLog>;
16
+ /**
17
+ * A session over the bundle served under `bundle`, with the binding from
18
+ * `wasm`; inputs are logged in `localStorage` under `log` when given, in
19
+ * memory otherwise.
20
+ */
21
+ export declare const session: (options: Session.SessionOptions & {
22
+ readonly wasm: string;
23
+ readonly bundle: string;
24
+ readonly log?: string;
25
+ }) => Layer.Layer<Session.Session, import("./Errors.js").InputLogError | WasmLoadError | import("./Errors.js").BundleError | import("./Errors.js").RuntimeRejection, never>;
@@ -0,0 +1,28 @@
1
+ import {
2
+ WasmLoadError,
3
+ url,
4
+ memory,
5
+ keyValueStore,
6
+ LuteWasm2,
7
+ fromBytes,
8
+ layer,
9
+ layer2
10
+ } from "./index-wshk3yvw.js";
11
+
12
+ // src/browser.ts
13
+ import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
14
+ import { Effect, Layer } from "effect";
15
+ import * as FetchHttpClient from "effect/http/FetchHttpClient";
16
+ import * as HttpClient from "effect/http/HttpClient";
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
+ var bundle = (base) => url(base).pipe(Layer.provide(FetchHttpClient.layer));
20
+ var inputLog = (key) => keyValueStore(key).pipe(Layer.provide(BrowserKeyValueStore.layerLocalStorage));
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
+ export {
23
+ bundle,
24
+ inputLog,
25
+ runtime,
26
+ session,
27
+ wasm
28
+ };
package/dist/bun.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Layer } from "effect";
2
+ import * as BundleSource from "./BundleSource.js";
3
+ import { WasmLoadError } from "./Errors.js";
4
+ import * as InputLog from "./InputLog.js";
5
+ import * as LuteRuntime from "./LuteRuntime.js";
6
+ import * as LuteWasm from "./LuteWasm.js";
7
+ import * as Session from "./Session.js";
8
+ /** The binding shipped with this package, read from disk. */
9
+ export declare const wasm: Layer.Layer<LuteWasm.LuteWasm, WasmLoadError>;
10
+ /** `LuteRuntime` over the packaged binding. */
11
+ export declare const runtime: Layer.Layer<LuteRuntime.LuteRuntime, WasmLoadError>;
12
+ /** The bundle in a `lute compile --all` output directory. */
13
+ export declare const bundle: (directory: string) => Layer.Layer<BundleSource.BundleSource>;
14
+ /**
15
+ * A session over the bundle in `bundle` (a directory), logging inputs in
16
+ * memory unless `log` provides another `InputLog`.
17
+ */
18
+ export declare const session: (options: Session.SessionOptions & {
19
+ readonly bundle: string;
20
+ readonly log?: Layer.Layer<InputLog.InputLog>;
21
+ }) => Layer.Layer<Session.Session, import("./Errors.js").InputLogError | WasmLoadError | import("./Errors.js").BundleError | import("./Errors.js").RuntimeRejection, never>;
package/dist/bun.js ADDED
@@ -0,0 +1,28 @@
1
+ import {
2
+ WasmLoadError,
3
+ directory,
4
+ memory,
5
+ LuteWasm2,
6
+ fromBytes,
7
+ layer,
8
+ layer2
9
+ } from "./index-wshk3yvw.js";
10
+
11
+ // src/bun.ts
12
+ import * as BunServices from "@effect/platform-bun/BunServices";
13
+ import { Effect, FileSystem, Layer, Path } from "effect";
14
+ var wasm = Layer.effect(LuteWasm2, Effect.gen(function* () {
15
+ const fs = yield* FileSystem.FileSystem;
16
+ const path = yield* Path.Path;
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}` })));
18
+ return yield* fromBytes(bytes);
19
+ })).pipe(Layer.provide(BunServices.layer));
20
+ var runtime = layer.pipe(Layer.provide(wasm));
21
+ var bundle = (directory2) => directory(directory2).pipe(Layer.provide(BunServices.layer));
22
+ var session = (options) => layer2(options).pipe(Layer.provide(Layer.mergeAll(runtime, bundle(options.bundle), options.log ?? memory)));
23
+ export {
24
+ bundle,
25
+ runtime,
26
+ session,
27
+ wasm
28
+ };