@lute-lang/runtime 0.39.0 → 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.
@@ -16,8 +16,8 @@ var __export = (target, all) => {
16
16
  // src/Bundle.ts
17
17
  var exports_Bundle = {};
18
18
  __export(exports_Bundle, {
19
- IndexDocuments: () => IndexDocuments,
20
- Bundle: () => Bundle
19
+ Bundle: () => Bundle,
20
+ IndexDocuments: () => IndexDocuments
21
21
  });
22
22
  import { Schema } from "effect";
23
23
  var Bundle = Schema.Struct({
@@ -31,21 +31,22 @@ var IndexDocuments = Schema.Struct({
31
31
  // src/Errors.ts
32
32
  var exports_Errors = {};
33
33
  __export(exports_Errors, {
34
- fromRejected: () => fromRejected,
35
- WasmLoadError: () => WasmLoadError,
36
- SnapshotVersionMismatch: () => SnapshotVersionMismatch,
37
- SnapshotProjectMismatch: () => SnapshotProjectMismatch,
38
- RuntimeHalted: () => RuntimeHalted,
39
- RuntimeBusy: () => RuntimeBusy,
40
- RequestMismatch: () => RequestMismatch,
41
- OptionUnavailable: () => OptionUnavailable,
42
- IrVersionMismatch: () => IrVersionMismatch,
43
- InvalidInput: () => InvalidInput,
44
- InputLogError: () => InputLogError,
45
- BundleUnreadable: () => BundleUnreadable,
46
- BundleNotFound: () => BundleNotFound,
34
+ BridgeShapeMismatch: () => BridgeShapeMismatch,
47
35
  BundleMalformed: () => BundleMalformed,
48
- BridgeShapeMismatch: () => BridgeShapeMismatch
36
+ BundleNotFound: () => BundleNotFound,
37
+ BundleUnreadable: () => BundleUnreadable,
38
+ InputLogError: () => InputLogError,
39
+ InvalidInput: () => InvalidInput,
40
+ IrVersionMismatch: () => IrVersionMismatch,
41
+ OptionUnavailable: () => OptionUnavailable,
42
+ RequestMismatch: () => RequestMismatch,
43
+ RuntimeBusy: () => RuntimeBusy,
44
+ RuntimeHalted: () => RuntimeHalted,
45
+ SnapshotProjectMismatch: () => SnapshotProjectMismatch,
46
+ SnapshotVersionMismatch: () => SnapshotVersionMismatch,
47
+ TimeoutUnavailable: () => TimeoutUnavailable,
48
+ WasmLoadError: () => WasmLoadError,
49
+ fromRejected: () => fromRejected
49
50
  });
50
51
  import { Effect, Schema as Schema2 } from "effect";
51
52
 
@@ -55,6 +56,12 @@ class RuntimeBusy extends Schema2.TaggedError()("RuntimeBusy", {
55
56
  }) {
56
57
  }
57
58
 
59
+ class TimeoutUnavailable extends Schema2.TaggedError()("TimeoutUnavailable", {
60
+ code: Schema2.Literal("E-RUNTIME-TIMEOUT"),
61
+ message: Schema2.String
62
+ }) {
63
+ }
64
+
58
65
  class RequestMismatch extends Schema2.TaggedError()("RequestMismatch", {
59
66
  code: Schema2.Literal("E-RUNTIME-REQUEST"),
60
67
  message: Schema2.String
@@ -101,6 +108,7 @@ var byCode = {
101
108
  "E-RUNTIME-REQUEST": (message) => new RequestMismatch({ code: "E-RUNTIME-REQUEST", message }),
102
109
  "E-RUNTIME-OPTION": (message) => new OptionUnavailable({ code: "E-RUNTIME-OPTION", message }),
103
110
  "E-RUNTIME-BRIDGE-SHAPE": (message) => new BridgeShapeMismatch({ code: "E-RUNTIME-BRIDGE-SHAPE", message }),
111
+ "E-RUNTIME-TIMEOUT": (message) => new TimeoutUnavailable({ code: "E-RUNTIME-TIMEOUT", message }),
104
112
  "E-RUNTIME-INPUT": (message) => new InvalidInput({ code: "E-RUNTIME-INPUT", message }),
105
113
  "E-RUNTIME-HALTED": (message) => new RuntimeHalted({ code: "E-RUNTIME-HALTED", message }),
106
114
  "E-RUNTIME-IR-VERSION": (message) => new IrVersionMismatch({ code: "E-RUNTIME-IR-VERSION", message }),
@@ -143,10 +151,10 @@ class InputLogError extends Schema2.TaggedError()("InputLogError", {
143
151
  // src/BundleSource.ts
144
152
  var exports_BundleSource = {};
145
153
  __export(exports_BundleSource, {
146
- value: () => value,
147
- url: () => url,
154
+ BundleSource: () => BundleSource,
148
155
  directory: () => directory,
149
- BundleSource: () => BundleSource
156
+ url: () => url,
157
+ value: () => value
150
158
  });
151
159
  import { Context, Effect as Effect2, FileSystem, Layer, Path, Schema as Schema3 } from "effect";
152
160
  import * as HttpClient from "effect/http/HttpClient";
@@ -184,38 +192,44 @@ var url = (base) => Layer.effect(BundleSource, Effect2.gen(function* () {
184
192
  // src/generated/Contract.ts
185
193
  var exports_Contract = {};
186
194
  __export(exports_Contract, {
187
- parseOptions: () => parseOptions,
188
- WritesInput: () => WritesInput,
189
- WorldView: () => WorldView,
190
- World: () => World,
191
- Verdict: () => Verdict,
192
- Value: () => Value,
193
- StreamLine: () => StreamLine,
194
- StateWrite: () => StateWrite,
195
- Snapshot: () => Snapshot,
196
- Seed: () => Seed,
197
- SaveInput: () => SaveInput,
198
- Rejected: () => Rejected,
199
- Premise: () => Premise,
200
- PickInput: () => PickInput,
201
- Output: () => Output,
202
- MenuOptionAwait: () => MenuOptionAwait,
203
- MenuAwait: () => MenuAwait,
204
- Input: () => Input,
205
- GuardRead: () => GuardRead,
206
- Event: () => Event,
207
- Continuation: () => Continuation,
208
- ClockView: () => ClockView,
209
- ClockPosition: () => ClockPosition,
210
- ClockAt: () => ClockAt,
211
- Candidate: () => Candidate,
212
- Cadence: () => Cadence,
213
- BeatOnce: () => BeatOnce,
214
- BeatKind: () => BeatKind,
215
- Await: () => Await,
216
- Atom: () => Atom,
195
+ AdvanceBy: () => AdvanceBy,
217
196
  Answer: () => Answer,
218
- AdvanceBy: () => AdvanceBy
197
+ Atom: () => Atom,
198
+ Await: () => Await,
199
+ BeatKind: () => BeatKind,
200
+ BeatOnce: () => BeatOnce,
201
+ Cadence: () => Cadence,
202
+ Candidate: () => Candidate,
203
+ ClockAt: () => ClockAt,
204
+ ClockPosition: () => ClockPosition,
205
+ ClockView: () => ClockView,
206
+ Continuation: () => Continuation,
207
+ Event: () => Event,
208
+ GuardRead: () => GuardRead,
209
+ Input: () => Input,
210
+ MenuAwait: () => MenuAwait,
211
+ MenuOptionAwait: () => MenuOptionAwait,
212
+ Output: () => Output,
213
+ PickInput: () => PickInput,
214
+ Premise: () => Premise,
215
+ Rejected: () => Rejected,
216
+ SaveInput: () => SaveInput,
217
+ Seed: () => Seed,
218
+ Snapshot: () => Snapshot,
219
+ Stage: () => Stage,
220
+ StageActor: () => StageActor,
221
+ StageBackground: () => StageBackground,
222
+ StageCg: () => StageCg,
223
+ StageMusic: () => StageMusic,
224
+ StageVideo: () => StageVideo,
225
+ StateWrite: () => StateWrite,
226
+ StreamLine: () => StreamLine,
227
+ Value: () => Value,
228
+ Verdict: () => Verdict,
229
+ World: () => World,
230
+ WorldView: () => WorldView,
231
+ WritesInput: () => WritesInput,
232
+ parseOptions: () => parseOptions
219
233
  });
220
234
  import * as Schema4 from "effect/Schema";
221
235
  var parseOptions = { onExcessProperty: "error" };
@@ -378,6 +392,10 @@ var Input = Schema4.Union([
378
392
  type: Schema4.Literal("raiseOccasion"),
379
393
  writes: Schema4.optionalKey(Schema4.suspend(() => WritesInput))
380
394
  }),
395
+ Schema4.Struct({
396
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
397
+ type: Schema4.Literal("timeout")
398
+ }),
381
399
  Schema4.Struct({
382
400
  option: Schema4.String,
383
401
  request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
@@ -409,13 +427,14 @@ var Input = Schema4.Union([
409
427
  ]).pipe(Schema4.toTaggedUnion("type"));
410
428
  var MenuAwait = Schema4.Struct({
411
429
  construct: Schema4.String,
430
+ default: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
412
431
  document: Schema4.String,
413
432
  id: Schema4.String,
414
433
  options: Schema4.Array(Schema4.suspend(() => MenuOptionAwait)),
415
434
  position: Schema4.String,
416
435
  presentation: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
417
436
  prompt: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
418
- timeout: Schema4.optionalKey(Schema4.NullOr(Schema4.Number))
437
+ timeout: Schema4.optionalKey(Schema4.NullOr(Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0)))))
419
438
  });
420
439
  var MenuOptionAwait = Schema4.Struct({
421
440
  exit: Schema4.Boolean,
@@ -582,7 +601,39 @@ var Continuation = Schema4.Struct({
582
601
  before: Schema4.suspend(() => World),
583
602
  delivered: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
584
603
  input: Schema4.suspend(() => Input),
585
- pending: Schema4.suspend(() => Await)
604
+ pending: Schema4.suspend(() => Await),
605
+ stage: Schema4.suspend(() => Stage)
606
+ });
607
+ var Stage = Schema4.Struct({
608
+ actors: Schema4.Array(Schema4.suspend(() => StageActor)),
609
+ bg: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => StageBackground))),
610
+ cg: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => StageCg))),
611
+ music: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => StageMusic))),
612
+ video: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => StageVideo)))
613
+ });
614
+ var StageActor = Schema4.Struct({
615
+ anchor: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
616
+ character: Schema4.String,
617
+ costume: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
618
+ emotion: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
619
+ });
620
+ var StageBackground = Schema4.Struct({
621
+ assetId: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
622
+ location: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
623
+ time: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
624
+ });
625
+ var StageCg = Schema4.Struct({
626
+ assetId: Schema4.String,
627
+ layout: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
628
+ });
629
+ var StageMusic = Schema4.Struct({
630
+ assetId: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
631
+ mood: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
632
+ playback: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
633
+ volume: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
634
+ });
635
+ var StageVideo = Schema4.Struct({
636
+ assetId: Schema4.String
586
637
  });
587
638
  var World = Schema4.Struct({
588
639
  accepts: Schema4.Array(Schema4.String),
@@ -608,6 +659,7 @@ var World = Schema4.Struct({
608
659
  spentAt: Schema4.Record(Schema4.String, Schema4.suspend(() => ClockAt)),
609
660
  spentRun: Schema4.UniqueArray(Schema4.String),
610
661
  spentUser: Schema4.UniqueArray(Schema4.String),
662
+ stage: Schema4.suspend(() => Stage),
611
663
  state: Schema4.Record(Schema4.String, Schema4.suspend(() => Value)),
612
664
  visited: Schema4.UniqueArray(Schema4.String)
613
665
  });
@@ -623,10 +675,10 @@ var Snapshot = Schema4.Struct({
623
675
  // src/InputLog.ts
624
676
  var exports_InputLog = {};
625
677
  __export(exports_InputLog, {
626
- memory: () => memory,
627
- keyValueStore: () => keyValueStore,
678
+ InputLog: () => InputLog,
628
679
  LogEntry: () => LogEntry,
629
- InputLog: () => InputLog
680
+ keyValueStore: () => keyValueStore,
681
+ memory: () => memory
630
682
  });
631
683
  import { Context as Context2, Effect as Effect3, Layer as Layer2, Option, Ref, Schema as Schema5 } from "effect";
632
684
  import * as KeyValueStore from "effect/persistence/KeyValueStore";
@@ -656,14 +708,14 @@ var keyValueStore = (key) => Layer2.effect(InputLog, Effect3.gen(function* () {
656
708
  // src/LuteWasm.ts
657
709
  var exports_LuteWasm = {};
658
710
  __export(exports_LuteWasm, {
659
- layerFromBytes: () => layerFromBytes,
711
+ LuteWasm: () => LuteWasm2,
660
712
  fromBytes: () => fromBytes,
661
- LuteWasm: () => LuteWasm
713
+ layerFromBytes: () => layerFromBytes
662
714
  });
663
715
  import { Context as Context3, Effect as Effect4, Layer as Layer3 } from "effect";
664
716
  import * as Glue from "./wasm/lute_runtime_wasm.js";
665
717
 
666
- class LuteWasm extends Context3.Service()("@lute-lang/runtime/LuteWasm") {
718
+ class LuteWasm2 extends Context3.Service()("@lute-lang/runtime/LuteWasm") {
667
719
  }
668
720
  var fromBytes = (bytes) => Effect4.try({
669
721
  try: () => {
@@ -675,13 +727,13 @@ var fromBytes = (bytes) => Effect4.try({
675
727
  },
676
728
  catch: (cause) => new WasmLoadError({ message: `cannot instantiate the runtime binding: ${String(cause)}` })
677
729
  });
678
- var layerFromBytes = (bytes) => Layer3.effect(LuteWasm, fromBytes(bytes));
730
+ var layerFromBytes = (bytes) => Layer3.effect(LuteWasm2, fromBytes(bytes));
679
731
 
680
732
  // src/Program.ts
681
733
  var exports_Program = {};
682
734
  __export(exports_Program, {
683
- rejection: () => rejection,
684
- make: () => make
735
+ make: () => make,
736
+ rejection: () => rejection
685
737
  });
686
738
  import { Effect as Effect5, Option as Option2, Schema as Schema6 } from "effect";
687
739
  var TypeId = "~@lute-lang/runtime/RuntimeState";
@@ -701,13 +753,14 @@ var fromBinding = (schema) => {
701
753
  };
702
754
  var toBinding = (schema) => {
703
755
  const encode = Schema6.encodeEffect(Schema6.fromJsonString(schema), parseOptions);
704
- return (value2) => Effect5.orDie(encode(value2));
756
+ return (value) => Effect5.orDie(encode(value));
705
757
  };
706
758
  var decodeOutput = fromBinding(Output);
707
759
  var decodeRejected = fromBinding(Rejected);
708
760
  var decodeSnapshot = fromBinding(Snapshot);
709
761
  var decodeCandidates = fromBinding(Schema6.Array(Candidate));
710
762
  var decodeCandidate = fromBinding(Schema6.NullOr(Candidate));
763
+ var decodeStage = fromBinding(Stage);
711
764
  var decodeClock = fromBinding(Schema6.NullOr(ClockAt));
712
765
  var decodeView = fromBinding(WorldView);
713
766
  var encodeSeed = toBinding(Seed);
@@ -724,7 +777,7 @@ var settle = (result, success) => Effect5.suspend(() => {
724
777
  }).pipe(Effect5.ensuring(Effect5.sync(() => result.free())));
725
778
  var stepOf = (result) => settle(result, () => {
726
779
  const { state, output } = result;
727
- return state === undefined || output === undefined ? Effect5.die(new Error("the runtime binding accepted an input without a state and output")) : Effect5.map(decodeOutput(output), (output2) => ({ state: wrap(state), output: output2 }));
780
+ return state === undefined || output === undefined ? Effect5.die(new Error("the runtime binding accepted an input without a state and output")) : Effect5.map(decodeOutput(output), (output) => ({ state: wrap(state), output }));
728
781
  });
729
782
  var make = (raw) => ({
730
783
  fingerprint: raw.fingerprint,
@@ -767,6 +820,10 @@ var make = (raw) => ({
767
820
  const handle = yield* handleOf(state);
768
821
  return raw.terminal(handle);
769
822
  }),
823
+ stage: Effect5.fn("Lute.Program.stage")(function* (state) {
824
+ const handle = yield* handleOf(state);
825
+ return yield* decodeStage(raw.stage(handle));
826
+ }),
770
827
  view: Effect5.fn("Lute.Program.view")(function* (state, options) {
771
828
  const handle = yield* handleOf(state);
772
829
  return yield* decodeView(raw.view(handle, options?.facts === true));
@@ -777,14 +834,14 @@ var make = (raw) => ({
777
834
  // src/LuteRuntime.ts
778
835
  var exports_LuteRuntime = {};
779
836
  __export(exports_LuteRuntime, {
780
- layer: () => layer,
781
- LuteRuntime: () => LuteRuntime
837
+ LuteRuntime: () => LuteRuntime,
838
+ layer: () => layer
782
839
  });
783
840
  import { Context as Context4, Effect as Effect6, Layer as Layer4 } from "effect";
784
841
  class LuteRuntime extends Context4.Service()("@lute-lang/runtime/LuteRuntime") {
785
842
  }
786
843
  var layer = Layer4.effect(LuteRuntime, Effect6.gen(function* () {
787
- const wasm = yield* LuteWasm;
844
+ const wasm = yield* LuteWasm2;
788
845
  const acquire = Effect6.fn("Lute.LuteRuntime.load")(function* (bundle) {
789
846
  const result = wasm.Program.load(JSON.stringify(bundle.index), JSON.stringify(bundle.artifacts));
790
847
  const { ok, program, rejected } = result;
@@ -803,8 +860,8 @@ var layer = Layer4.effect(LuteRuntime, Effect6.gen(function* () {
803
860
  // src/Session.ts
804
861
  var exports_Session = {};
805
862
  __export(exports_Session, {
806
- layer: () => layer2,
807
- Session: () => Session
863
+ Session: () => Session,
864
+ layer: () => layer2
808
865
  });
809
866
  import { Context as Context5, Effect as Effect7, Layer as Layer5, PubSub, Semaphore, Stream, SubscriptionRef } from "effect";
810
867
  class Session extends Context5.Service()("@lute-lang/runtime/Session") {
@@ -818,9 +875,11 @@ var layer2 = (options) => Layer5.effect(Session, Effect7.gen(function* () {
818
875
  state: yield* program.restore(options.snapshot),
819
876
  output: { eventVersion: options.snapshot.snapshotVersion, events: [], await: options.snapshot.await }
820
877
  };
878
+ const stage = yield* program.stage(started.state);
821
879
  yield* log.reset(options);
822
880
  const current = yield* SubscriptionRef.make({
823
881
  state: started.state,
882
+ stage,
824
883
  await: started.output.await
825
884
  });
826
885
  const events = yield* PubSub.unbounded();
@@ -831,15 +890,17 @@ var layer2 = (options) => Layer5.effect(Session, Effect7.gen(function* () {
831
890
  const { state } = yield* SubscriptionRef.get(current);
832
891
  const step = yield* program.step(state, input);
833
892
  yield* log.append({ input });
834
- yield* SubscriptionRef.set(current, { state: step.state, await: step.output.await });
893
+ const stage = yield* program.stage(step.state);
894
+ yield* SubscriptionRef.set(current, { state: step.state, stage, await: step.output.await });
835
895
  yield* PubSub.publishAll(events, step.output.events);
836
896
  yield* PubSub.publish(awaits, step.output.await);
837
897
  return step.output;
838
898
  });
839
899
  const restore = Effect7.fn("Lute.Session.restore")(function* (snapshot) {
840
900
  const state = yield* program.restore(snapshot);
901
+ const stage = yield* program.stage(state);
841
902
  yield* log.reset({ snapshot });
842
- yield* SubscriptionRef.set(current, { state, await: snapshot.await });
903
+ yield* SubscriptionRef.set(current, { state, stage, await: snapshot.await });
843
904
  yield* PubSub.publish(awaits, snapshot.await);
844
905
  });
845
906
  return {
@@ -854,4 +915,4 @@ var layer2 = (options) => Layer5.effect(Session, Effect7.gen(function* () {
854
915
  };
855
916
  }));
856
917
 
857
- export { __export, exports_Bundle, WasmLoadError, exports_Errors, directory, url, exports_BundleSource, exports_Contract, LogEntry, memory, keyValueStore, exports_InputLog, LuteWasm, fromBytes, exports_LuteWasm, exports_Program, layer, exports_LuteRuntime, layer2 as layer1, exports_Session };
918
+ export { __export, exports_Bundle, WasmLoadError, exports_Errors, directory, url, exports_BundleSource, exports_Contract, LogEntry, memory, keyValueStore, exports_InputLog, LuteWasm2, fromBytes, exports_LuteWasm, exports_Program, layer, exports_LuteRuntime, layer2, exports_Session };
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). 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";