@lute-lang/runtime 0.0.0-stage → 0.39.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,17 @@
1
+ /**
2
+ * Replaying a recorded input log (spec 0.39.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,55 @@
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.
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 } 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 and what it waits for. */
14
+ export interface SessionState {
15
+ readonly state: RuntimeState;
16
+ readonly await: Await;
17
+ }
18
+ declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Session", {
19
+ /** The program's fingerprint (what snapshots carry). */
20
+ readonly fingerprint: string;
21
+ /** The output of `begin`; for a restored session, no events and the snapshot's await. */
22
+ readonly started: Output;
23
+ /**
24
+ * Apply one input. Inputs run one at a time, in call order. An accepted
25
+ * input is logged before its events are published; a rejected one
26
+ * changes nothing.
27
+ */
28
+ readonly send: (input: Input) => Effect.Effect<Output, RuntimeRejection | InputLogError>;
29
+ readonly current: SubscriptionRef.SubscriptionRef<SessionState>;
30
+ /**
31
+ * Subscribe to the events of every later output, in order. The
32
+ * subscription exists once this effect completes, so nothing published
33
+ * afterwards is missed; it ends with its scope or the session's.
34
+ */
35
+ readonly events: Effect.Effect<Stream.Stream<Event>, never, Scope.Scope>;
36
+ /** Subscribe to the await of every later output, like `events`. */
37
+ readonly awaits: Effect.Effect<Stream.Stream<Await>, never, Scope.Scope>;
38
+ readonly save: Effect.Effect<Snapshot>;
39
+ /** Continue from a snapshot; the input log restarts from it. */
40
+ readonly restore: (snapshot: Snapshot) => Effect.Effect<void, RuntimeRejection | InputLogError>;
41
+ }>;
42
+ export declare class Session extends Session_base {
43
+ }
44
+ /** How a session starts: from a seed, or from a snapshot. */
45
+ export type SessionOptions = {
46
+ readonly seed: Seed;
47
+ } | {
48
+ readonly snapshot: Snapshot;
49
+ };
50
+ /**
51
+ * A session over the bundle of `BundleSource`. The program it loads lives
52
+ * as long as the layer's scope; closing it ends `events` and `awaits`.
53
+ */
54
+ export declare const layer: (options: SessionOptions) => Layer.Layer<Session, RuntimeRejection | BundleError | InputLogError, LuteRuntime | BundleSource | InputLog>;
55
+ 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
+ LuteWasm,
3
+ WasmLoadError,
4
+ fromBytes,
5
+ keyValueStore,
6
+ layer,
7
+ layer1 as layer2,
8
+ memory,
9
+ url
10
+ } from "./index-eqt12qy0.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 = (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)));
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
+ wasm,
24
+ session,
25
+ runtime,
26
+ inputLog,
27
+ bundle
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
+ LuteWasm,
3
+ WasmLoadError,
4
+ directory,
5
+ fromBytes,
6
+ layer,
7
+ layer1 as layer2,
8
+ memory
9
+ } from "./index-eqt12qy0.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(LuteWasm, 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
+ wasm,
25
+ session,
26
+ runtime,
27
+ bundle
28
+ };