@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,918 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+
16
+ // src/Bundle.ts
17
+ var exports_Bundle = {};
18
+ __export(exports_Bundle, {
19
+ Bundle: () => Bundle,
20
+ IndexDocuments: () => IndexDocuments
21
+ });
22
+ import { Schema } from "effect";
23
+ var Bundle = Schema.Struct({
24
+ index: Schema.Json,
25
+ artifacts: Schema.Record(Schema.String, Schema.Json)
26
+ });
27
+ var IndexDocuments = Schema.Struct({
28
+ documents: Schema.Array(Schema.Struct({ artifact: Schema.String }))
29
+ });
30
+
31
+ // src/Errors.ts
32
+ var exports_Errors = {};
33
+ __export(exports_Errors, {
34
+ BridgeShapeMismatch: () => BridgeShapeMismatch,
35
+ BundleMalformed: () => BundleMalformed,
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
50
+ });
51
+ import { Effect, Schema as Schema2 } from "effect";
52
+
53
+ class RuntimeBusy extends Schema2.TaggedError()("RuntimeBusy", {
54
+ code: Schema2.Literal("E-RUNTIME-BUSY"),
55
+ message: Schema2.String
56
+ }) {
57
+ }
58
+
59
+ class TimeoutUnavailable extends Schema2.TaggedError()("TimeoutUnavailable", {
60
+ code: Schema2.Literal("E-RUNTIME-TIMEOUT"),
61
+ message: Schema2.String
62
+ }) {
63
+ }
64
+
65
+ class RequestMismatch extends Schema2.TaggedError()("RequestMismatch", {
66
+ code: Schema2.Literal("E-RUNTIME-REQUEST"),
67
+ message: Schema2.String
68
+ }) {
69
+ }
70
+
71
+ class OptionUnavailable extends Schema2.TaggedError()("OptionUnavailable", {
72
+ code: Schema2.Literal("E-RUNTIME-OPTION"),
73
+ message: Schema2.String
74
+ }) {
75
+ }
76
+
77
+ class BridgeShapeMismatch extends Schema2.TaggedError()("BridgeShapeMismatch", {
78
+ code: Schema2.Literal("E-RUNTIME-BRIDGE-SHAPE"),
79
+ message: Schema2.String
80
+ }) {
81
+ }
82
+
83
+ class InvalidInput extends Schema2.TaggedError()("InvalidInput", {
84
+ code: Schema2.Literal("E-RUNTIME-INPUT"),
85
+ message: Schema2.String
86
+ }) {
87
+ }
88
+
89
+ class RuntimeHalted extends Schema2.TaggedError()("RuntimeHalted", {
90
+ code: Schema2.Literal("E-RUNTIME-HALTED"),
91
+ message: Schema2.String
92
+ }) {
93
+ }
94
+
95
+ class IrVersionMismatch extends Schema2.TaggedError()("IrVersionMismatch", {
96
+ code: Schema2.Literal("E-RUNTIME-IR-VERSION"),
97
+ message: Schema2.String
98
+ }) {
99
+ }
100
+
101
+ class SnapshotProjectMismatch extends Schema2.TaggedError()("SnapshotProjectMismatch", { code: Schema2.Literal("E-RUNTIME-SNAPSHOT-PROJECT"), message: Schema2.String }) {
102
+ }
103
+
104
+ class SnapshotVersionMismatch extends Schema2.TaggedError()("SnapshotVersionMismatch", { code: Schema2.Literal("E-RUNTIME-SNAPSHOT-VERSION"), message: Schema2.String }) {
105
+ }
106
+ var byCode = {
107
+ "E-RUNTIME-BUSY": (message) => new RuntimeBusy({ code: "E-RUNTIME-BUSY", message }),
108
+ "E-RUNTIME-REQUEST": (message) => new RequestMismatch({ code: "E-RUNTIME-REQUEST", message }),
109
+ "E-RUNTIME-OPTION": (message) => new OptionUnavailable({ code: "E-RUNTIME-OPTION", message }),
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 }),
112
+ "E-RUNTIME-INPUT": (message) => new InvalidInput({ code: "E-RUNTIME-INPUT", message }),
113
+ "E-RUNTIME-HALTED": (message) => new RuntimeHalted({ code: "E-RUNTIME-HALTED", message }),
114
+ "E-RUNTIME-IR-VERSION": (message) => new IrVersionMismatch({ code: "E-RUNTIME-IR-VERSION", message }),
115
+ "E-RUNTIME-SNAPSHOT-PROJECT": (message) => new SnapshotProjectMismatch({ code: "E-RUNTIME-SNAPSHOT-PROJECT", message }),
116
+ "E-RUNTIME-SNAPSHOT-VERSION": (message) => new SnapshotVersionMismatch({ code: "E-RUNTIME-SNAPSHOT-VERSION", message })
117
+ };
118
+ var fromRejected = (rejected) => {
119
+ const make = byCode[rejected.code];
120
+ return make === undefined ? Effect.die(new Error(`unknown runtime rejection ${rejected.code}: ${rejected.message}`)) : Effect.fail(make(rejected.message));
121
+ };
122
+
123
+ class BundleNotFound extends Schema2.TaggedError()("BundleNotFound", {
124
+ path: Schema2.String,
125
+ message: Schema2.String
126
+ }) {
127
+ }
128
+
129
+ class BundleUnreadable extends Schema2.TaggedError()("BundleUnreadable", {
130
+ path: Schema2.String,
131
+ message: Schema2.String
132
+ }) {
133
+ }
134
+
135
+ class BundleMalformed extends Schema2.TaggedError()("BundleMalformed", {
136
+ path: Schema2.String,
137
+ message: Schema2.String
138
+ }) {
139
+ }
140
+
141
+ class WasmLoadError extends Schema2.TaggedError()("WasmLoadError", {
142
+ message: Schema2.String
143
+ }) {
144
+ }
145
+
146
+ class InputLogError extends Schema2.TaggedError()("InputLogError", {
147
+ message: Schema2.String
148
+ }) {
149
+ }
150
+
151
+ // src/BundleSource.ts
152
+ var exports_BundleSource = {};
153
+ __export(exports_BundleSource, {
154
+ BundleSource: () => BundleSource,
155
+ directory: () => directory,
156
+ url: () => url,
157
+ value: () => value
158
+ });
159
+ import { Context, Effect as Effect2, FileSystem, Layer, Path, Schema as Schema3 } from "effect";
160
+ import * as HttpClient from "effect/http/HttpClient";
161
+ class BundleSource extends Context.Service()("@lute-lang/runtime/BundleSource") {
162
+ }
163
+ var INDEX = "project.index.json";
164
+ var decodeJson = Schema3.decodeUnknownEffect(Schema3.fromJsonString(Schema3.Json));
165
+ var decodeDocuments = Schema3.decodeUnknownEffect(IndexDocuments);
166
+ var assemble = (read) => Effect2.gen(function* () {
167
+ const readJson = (path) => Effect2.flatMap(read(path), (text) => Effect2.mapError(decodeJson(text), (error) => new BundleMalformed({ path, message: error.message })));
168
+ const index = yield* readJson(INDEX);
169
+ const { documents } = yield* Effect2.mapError(decodeDocuments(index), (error) => new BundleMalformed({ path: INDEX, message: error.message }));
170
+ const artifacts = yield* Effect2.forEach(documents, ({ artifact }) => Effect2.map(readJson(artifact), (json) => [artifact, json]));
171
+ return { index, artifacts: Object.fromEntries(artifacts) };
172
+ });
173
+ var value = (bundle) => Layer.succeed(BundleSource, { load: Effect2.succeed(bundle) });
174
+ var directory = (root) => Layer.effect(BundleSource, Effect2.gen(function* () {
175
+ const fs = yield* FileSystem.FileSystem;
176
+ const path = yield* Path.Path;
177
+ const read = (file) => {
178
+ const full = path.join(root, file);
179
+ return Effect2.mapError(fs.readFileString(full), (error) => error.reason._tag === "NotFound" ? new BundleNotFound({ path: full, message: error.message }) : new BundleUnreadable({ path: full, message: error.message }));
180
+ };
181
+ return { load: Effect2.withSpan(assemble(read), "Lute.BundleSource.directory", { attributes: { root } }) };
182
+ }));
183
+ var url = (base) => Layer.effect(BundleSource, Effect2.gen(function* () {
184
+ const client = HttpClient.filterStatusOk(yield* HttpClient.HttpClient);
185
+ const read = (file) => {
186
+ const href = new URL(file, base).href;
187
+ return client.get(href).pipe(Effect2.flatMap((response) => response.text), Effect2.mapError((error) => error.reason._tag === "StatusCodeError" && error.reason.response.status === 404 ? new BundleNotFound({ path: href, message: error.message }) : new BundleUnreadable({ path: href, message: error.message })));
188
+ };
189
+ return { load: Effect2.withSpan(assemble(read), "Lute.BundleSource.url", { attributes: { base } }) };
190
+ }));
191
+
192
+ // src/generated/Contract.ts
193
+ var exports_Contract = {};
194
+ __export(exports_Contract, {
195
+ AdvanceBy: () => AdvanceBy,
196
+ Answer: () => Answer,
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
233
+ });
234
+ import * as Schema4 from "effect/Schema";
235
+ var parseOptions = { onExcessProperty: "error" };
236
+ var AdvanceBy = Schema4.Union([
237
+ Schema4.String,
238
+ Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
239
+ Schema4.Struct({
240
+ to: Schema4.String
241
+ }),
242
+ Schema4.Struct({
243
+ to: Schema4.suspend(() => ClockPosition)
244
+ })
245
+ ]);
246
+ var Atom = Schema4.Union([
247
+ Schema4.Struct({
248
+ visited: Schema4.String
249
+ }),
250
+ Schema4.Struct({
251
+ completed: Schema4.String
252
+ }),
253
+ Schema4.Struct({
254
+ active: Schema4.String
255
+ })
256
+ ]);
257
+ var Await = Schema4.Union([
258
+ Schema4.Struct({
259
+ menu: Schema4.suspend(() => MenuAwait),
260
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
261
+ type: Schema4.Literal("awaitChoice")
262
+ }),
263
+ Schema4.Struct({
264
+ document: Schema4.String,
265
+ fields: Schema4.Record(Schema4.String, Schema4.String),
266
+ position: Schema4.String,
267
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
268
+ tag: Schema4.String,
269
+ type: Schema4.Literal("awaitBridge")
270
+ }),
271
+ Schema4.Struct({
272
+ type: Schema4.Literal("idle")
273
+ }),
274
+ Schema4.Struct({
275
+ reason: Schema4.String,
276
+ type: Schema4.Literal("ended")
277
+ }),
278
+ Schema4.Struct({
279
+ kind: Schema4.String,
280
+ message: Schema4.String,
281
+ site: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
282
+ type: Schema4.Literal("halted")
283
+ })
284
+ ]).pipe(Schema4.toTaggedUnion("type"));
285
+ var BeatKind = Schema4.Literals([
286
+ "scene",
287
+ "entry",
288
+ "bundle"
289
+ ]);
290
+ var BeatOnce = Schema4.String.pipe(Schema4.check(Schema4.isPattern(new RegExp("^(run|user|none|day|slot|week|season:.+)$"))));
291
+ var Candidate = Schema4.Struct({
292
+ also: Schema4.Boolean,
293
+ document: Schema4.String,
294
+ forMember: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
295
+ id: Schema4.String,
296
+ kind: Schema4.suspend(() => BeatKind),
297
+ priority: Schema4.Int,
298
+ read: Schema4.Boolean,
299
+ rejudged: Schema4.Boolean,
300
+ verdict: Schema4.suspend(() => Verdict)
301
+ });
302
+ var ClockAt = Schema4.Struct({
303
+ day: Schema4.Int,
304
+ slot: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0)))
305
+ });
306
+ var ClockPosition = Schema4.Struct({
307
+ slot: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
308
+ weekday: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
309
+ });
310
+ var ClockView = Schema4.Struct({
311
+ day: Schema4.Int,
312
+ ended: Schema4.optionalKey(Schema4.NullOr(Schema4.Boolean)),
313
+ last: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
314
+ slot: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
315
+ weekday: Schema4.optionalKey(Schema4.NullOr(Schema4.Int)),
316
+ weekdayLabel: Schema4.optionalKey(Schema4.NullOr(Schema4.String))
317
+ });
318
+ var Event = Schema4.Union([
319
+ Schema4.Struct({
320
+ document: Schema4.String,
321
+ record: Schema4.Json,
322
+ type: Schema4.Literal("record")
323
+ }),
324
+ Schema4.Struct({
325
+ beat: Schema4.String,
326
+ document: Schema4.String,
327
+ kind: Schema4.String,
328
+ occasion: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
329
+ target: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
330
+ type: Schema4.Literal("presentation")
331
+ }),
332
+ Schema4.Struct({
333
+ beat: Schema4.String,
334
+ document: Schema4.String,
335
+ reason: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
336
+ type: Schema4.Literal("presentationEnd")
337
+ }),
338
+ Schema4.Struct({
339
+ commands: Schema4.Array(Schema4.Json),
340
+ document: Schema4.String,
341
+ type: Schema4.Literal("quest")
342
+ }),
343
+ Schema4.Struct({
344
+ from: Schema4.Json,
345
+ passed: Schema4.optionalKey(Schema4.Json),
346
+ to: Schema4.Json,
347
+ type: Schema4.Literal("clock")
348
+ })
349
+ ]).pipe(Schema4.toTaggedUnion("type"));
350
+ var GuardRead = Schema4.Union([
351
+ Schema4.Struct({
352
+ kind: Schema4.Literal("path"),
353
+ value: Schema4.Tuple([
354
+ Schema4.String,
355
+ Schema4.suspend(() => Value)
356
+ ])
357
+ }),
358
+ Schema4.Struct({
359
+ kind: Schema4.Literal("fact"),
360
+ value: Schema4.String
361
+ }),
362
+ Schema4.Struct({
363
+ kind: Schema4.Literal("derived"),
364
+ value: Schema4.Struct({
365
+ base: Schema4.Array(Schema4.String),
366
+ fact: Schema4.String,
367
+ rules: Schema4.Array(Schema4.Tuple([
368
+ Schema4.String,
369
+ Schema4.Array(Schema4.String)
370
+ ]))
371
+ })
372
+ }),
373
+ Schema4.Struct({
374
+ kind: Schema4.Literal("visited"),
375
+ value: Schema4.String
376
+ }),
377
+ Schema4.Struct({
378
+ kind: Schema4.Literal("holds"),
379
+ value: Schema4.String
380
+ }),
381
+ Schema4.Struct({
382
+ kind: Schema4.Literal("seen"),
383
+ value: Schema4.String
384
+ })
385
+ ]).pipe(Schema4.toTaggedUnion("kind"));
386
+ var Input = Schema4.Union([
387
+ Schema4.Struct({
388
+ occasion: Schema4.String,
389
+ payload: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.Json)),
390
+ pick: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => PickInput))),
391
+ target: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
392
+ type: Schema4.Literal("raiseOccasion"),
393
+ writes: Schema4.optionalKey(Schema4.suspend(() => WritesInput))
394
+ }),
395
+ Schema4.Struct({
396
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
397
+ type: Schema4.Literal("timeout")
398
+ }),
399
+ Schema4.Struct({
400
+ option: Schema4.String,
401
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
402
+ type: Schema4.Literal("choose")
403
+ }),
404
+ Schema4.Struct({
405
+ fields: Schema4.Record(Schema4.String, Schema4.Json),
406
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
407
+ type: Schema4.Literal("bridgeResult")
408
+ }),
409
+ Schema4.Struct({
410
+ by: Schema4.suspend(() => AdvanceBy),
411
+ pick: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => PickInput))),
412
+ type: Schema4.Literal("advanceClock"),
413
+ writes: Schema4.optionalKey(Schema4.suspend(() => WritesInput))
414
+ }),
415
+ Schema4.Struct({
416
+ type: Schema4.Literal("hostWrite"),
417
+ writes: Schema4.suspend(() => WritesInput)
418
+ }),
419
+ Schema4.Struct({
420
+ name: Schema4.String,
421
+ type: Schema4.Literal("worldEvent")
422
+ }),
423
+ Schema4.Struct({
424
+ type: Schema4.Literal("newRun"),
425
+ writes: Schema4.optionalKey(Schema4.suspend(() => WritesInput))
426
+ })
427
+ ]).pipe(Schema4.toTaggedUnion("type"));
428
+ var MenuAwait = Schema4.Struct({
429
+ construct: Schema4.String,
430
+ default: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
431
+ document: Schema4.String,
432
+ id: Schema4.String,
433
+ options: Schema4.Array(Schema4.suspend(() => MenuOptionAwait)),
434
+ position: Schema4.String,
435
+ presentation: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
436
+ prompt: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
437
+ timeout: Schema4.optionalKey(Schema4.NullOr(Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0)))))
438
+ });
439
+ var MenuOptionAwait = Schema4.Struct({
440
+ exit: Schema4.Boolean,
441
+ id: Schema4.String,
442
+ once: Schema4.Boolean,
443
+ verdict: Schema4.String
444
+ });
445
+ var Output = Schema4.Struct({
446
+ await: Schema4.suspend(() => Await),
447
+ eventVersion: Schema4.String,
448
+ events: Schema4.Array(Schema4.suspend(() => Event))
449
+ });
450
+ var PickInput = Schema4.Union([
451
+ Schema4.String,
452
+ Schema4.Struct({
453
+ beat: Schema4.String
454
+ })
455
+ ]);
456
+ var Premise = Schema4.Union([
457
+ Schema4.Struct({
458
+ once: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => BeatOnce))),
459
+ premise: Schema4.Literal("spent"),
460
+ reason: Schema4.String
461
+ }),
462
+ Schema4.Struct({
463
+ chapters: Schema4.Boolean,
464
+ premise: Schema4.Literal("after"),
465
+ raw: Schema4.String,
466
+ unmet: Schema4.Array(Schema4.suspend(() => Atom))
467
+ }),
468
+ Schema4.Struct({
469
+ premise: Schema4.Literal("spentBy"),
470
+ raw: Schema4.String
471
+ }),
472
+ Schema4.Struct({
473
+ premise: Schema4.Literal("when"),
474
+ raw: Schema4.String
475
+ }),
476
+ Schema4.Struct({
477
+ occasion: Schema4.String,
478
+ premise: Schema4.Literal("gate"),
479
+ raw: Schema4.String,
480
+ reads: Schema4.Array(Schema4.suspend(() => GuardRead))
481
+ }),
482
+ Schema4.Struct({
483
+ occasion: Schema4.String,
484
+ premise: Schema4.Literal("terminal"),
485
+ raw: Schema4.String
486
+ })
487
+ ]).pipe(Schema4.toTaggedUnion("premise"));
488
+ var Rejected = Schema4.Struct({
489
+ code: Schema4.String,
490
+ message: Schema4.String
491
+ });
492
+ var SaveInput = Schema4.Struct({
493
+ entriesRead: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.Array(Schema4.String))),
494
+ presented: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.Array(Schema4.String))),
495
+ questInstances: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))))),
496
+ quests: Schema4.optionalKey(Schema4.Record(Schema4.String, Schema4.String)),
497
+ visited: Schema4.optionalKey(Schema4.Array(Schema4.String))
498
+ });
499
+ var Seed = Schema4.Struct({
500
+ derive: Schema4.optionalKey(Schema4.Boolean),
501
+ facts: Schema4.optionalKey(Schema4.Array(Schema4.String)),
502
+ save: Schema4.optionalKey(Schema4.suspend(() => SaveInput)),
503
+ state: Schema4.optionalKey(Schema4.Array(Schema4.suspend(() => StateWrite)))
504
+ });
505
+ var StateWrite = Schema4.Struct({
506
+ add: Schema4.optionalKey(Schema4.NullOr(Schema4.Number)),
507
+ path: Schema4.String,
508
+ value: Schema4.optionalKey(Schema4.Json)
509
+ });
510
+ var StreamLine = Schema4.Union([
511
+ Schema4.Struct({
512
+ output: Schema4.suspend(() => Output),
513
+ seed: Schema4.suspend(() => Seed)
514
+ }),
515
+ Schema4.Struct({
516
+ input: Schema4.suspend(() => Input),
517
+ output: Schema4.suspend(() => Output)
518
+ }),
519
+ Schema4.Struct({
520
+ input: Schema4.suspend(() => Input),
521
+ rejected: Schema4.suspend(() => Rejected)
522
+ }),
523
+ Schema4.Struct({
524
+ rejected: Schema4.suspend(() => Rejected),
525
+ seed: Schema4.suspend(() => Seed)
526
+ })
527
+ ]);
528
+ var Value = Schema4.Union([
529
+ Schema4.Struct({
530
+ kind: Schema4.Literal("bool"),
531
+ value: Schema4.Boolean
532
+ }),
533
+ Schema4.Struct({
534
+ kind: Schema4.Literal("int"),
535
+ value: Schema4.Int
536
+ }),
537
+ Schema4.Struct({
538
+ kind: Schema4.Literal("double"),
539
+ value: Schema4.Number
540
+ }),
541
+ Schema4.Struct({
542
+ kind: Schema4.Literal("str"),
543
+ value: Schema4.String
544
+ }),
545
+ Schema4.Struct({
546
+ kind: Schema4.Literal("unknown")
547
+ }),
548
+ Schema4.Struct({
549
+ kind: Schema4.Literal("error"),
550
+ value: Schema4.String
551
+ })
552
+ ]).pipe(Schema4.toTaggedUnion("kind"));
553
+ var Verdict = Schema4.Union([
554
+ Schema4.Struct({
555
+ verdict: Schema4.Literal("eligible")
556
+ }),
557
+ Schema4.Struct({
558
+ premise: Schema4.suspend(() => Premise),
559
+ verdict: Schema4.Literal("ineligible")
560
+ }),
561
+ Schema4.Struct({
562
+ verdict: Schema4.Literal("unknown"),
563
+ why: Schema4.String
564
+ })
565
+ ]).pipe(Schema4.toTaggedUnion("verdict"));
566
+ var WorldView = Schema4.Struct({
567
+ clock: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => ClockView))),
568
+ facts: Schema4.optionalKey(Schema4.UniqueArray(Schema4.String)),
569
+ quests: Schema4.Record(Schema4.String, Schema4.String),
570
+ state: Schema4.Record(Schema4.String, Schema4.suspend(() => Value))
571
+ });
572
+ var WritesInput = Schema4.Struct({
573
+ accept: Schema4.optionalKey(Schema4.Array(Schema4.String)),
574
+ facts: Schema4.optionalKey(Schema4.Array(Schema4.String)),
575
+ retract: Schema4.optionalKey(Schema4.Array(Schema4.String)),
576
+ state: Schema4.optionalKey(Schema4.Array(Schema4.suspend(() => StateWrite)))
577
+ });
578
+ var Answer = Schema4.Union([
579
+ Schema4.Struct({
580
+ choice: Schema4.Struct({
581
+ id: Schema4.String,
582
+ option: Schema4.String
583
+ })
584
+ }),
585
+ Schema4.Struct({
586
+ bridge: Schema4.Struct({
587
+ fields: Schema4.Record(Schema4.String, Schema4.Json),
588
+ tag: Schema4.String
589
+ })
590
+ })
591
+ ]);
592
+ var Cadence = Schema4.Struct({
593
+ latched: Schema4.Record(Schema4.String, Schema4.NullOr(Schema4.suspend(() => ClockAt))),
594
+ live: Schema4.Record(Schema4.String, Schema4.Boolean),
595
+ rearm: Schema4.Record(Schema4.String, Schema4.Boolean),
596
+ spentSeason: Schema4.UniqueArray(Schema4.String),
597
+ windows: Schema4.UniqueArray(Schema4.String)
598
+ });
599
+ var Continuation = Schema4.Struct({
600
+ answers: Schema4.Array(Schema4.suspend(() => Answer)),
601
+ before: Schema4.suspend(() => World),
602
+ delivered: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
603
+ input: Schema4.suspend(() => Input),
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
637
+ });
638
+ var World = Schema4.Struct({
639
+ accepts: Schema4.Array(Schema4.String),
640
+ advanceCascadeDepth: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
641
+ cadence: Schema4.suspend(() => Cadence),
642
+ clockAdvancedByBeat: Schema4.Boolean,
643
+ deferBy: Schema4.optionalKey(Schema4.NullOr(Schema4.String)),
644
+ deferHandlers: Schema4.Boolean,
645
+ deferredHandlers: Schema4.Array(Schema4.Tuple([
646
+ Schema4.String,
647
+ Schema4.String
648
+ ])),
649
+ derive: Schema4.optionalKey(Schema4.NullOr(Schema4.Boolean)),
650
+ facts: Schema4.UniqueArray(Schema4.Tuple([
651
+ Schema4.String,
652
+ Schema4.Array(Schema4.String)
653
+ ])),
654
+ failedObjectives: Schema4.UniqueArray(Schema4.String),
655
+ nextRunAccepts: Schema4.Array(Schema4.String),
656
+ questInstances: Schema4.Record(Schema4.String, Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0)))),
657
+ quests: Schema4.Record(Schema4.String, Schema4.String),
658
+ shareSpentBy: Schema4.Record(Schema4.String, Schema4.String),
659
+ spentAt: Schema4.Record(Schema4.String, Schema4.suspend(() => ClockAt)),
660
+ spentRun: Schema4.UniqueArray(Schema4.String),
661
+ spentUser: Schema4.UniqueArray(Schema4.String),
662
+ stage: Schema4.suspend(() => Stage),
663
+ state: Schema4.Record(Schema4.String, Schema4.suspend(() => Value)),
664
+ visited: Schema4.UniqueArray(Schema4.String)
665
+ });
666
+ var Snapshot = Schema4.Struct({
667
+ await: Schema4.suspend(() => Await),
668
+ continuation: Schema4.optionalKey(Schema4.NullOr(Schema4.suspend(() => Continuation))),
669
+ project: Schema4.String,
670
+ request: Schema4.Int.pipe(Schema4.check(Schema4.isGreaterThanOrEqualTo(0))),
671
+ snapshotVersion: Schema4.String,
672
+ world: Schema4.suspend(() => World)
673
+ });
674
+
675
+ // src/InputLog.ts
676
+ var exports_InputLog = {};
677
+ __export(exports_InputLog, {
678
+ InputLog: () => InputLog,
679
+ LogEntry: () => LogEntry,
680
+ keyValueStore: () => keyValueStore,
681
+ memory: () => memory
682
+ });
683
+ import { Context as Context2, Effect as Effect3, Layer as Layer2, Option, Ref, Schema as Schema5 } from "effect";
684
+ import * as KeyValueStore from "effect/persistence/KeyValueStore";
685
+ var LogEntry = Schema5.Union([
686
+ Schema5.Struct({ seed: Seed }),
687
+ Schema5.Struct({ snapshot: Snapshot }),
688
+ Schema5.Struct({ input: Input })
689
+ ]);
690
+
691
+ class InputLog extends Context2.Service()("@lute-lang/runtime/InputLog") {
692
+ }
693
+ var memory = Layer2.effect(InputLog, Effect3.map(Ref.make([]), (log) => ({
694
+ reset: (start) => Ref.set(log, [start]),
695
+ append: (entry) => Ref.update(log, (entries) => [...entries, entry]),
696
+ entries: Ref.get(log)
697
+ })));
698
+ var keyValueStore = (key) => Layer2.effect(InputLog, Effect3.gen(function* () {
699
+ const store = KeyValueStore.toSchemaStore(yield* KeyValueStore.KeyValueStore, Schema5.Array(LogEntry));
700
+ const entries = store.get(key).pipe(Effect3.map(Option.getOrElse(() => [])), Effect3.mapError((error) => new InputLogError({ message: error.message })));
701
+ return {
702
+ reset: (start) => Effect3.mapError(store.set(key, [start]), (error) => new InputLogError({ message: error.message })),
703
+ append: (entry) => entries.pipe(Effect3.flatMap((logged) => store.set(key, [...logged, entry])), Effect3.mapError((error) => new InputLogError({ message: error.message }))),
704
+ entries
705
+ };
706
+ }));
707
+
708
+ // src/LuteWasm.ts
709
+ var exports_LuteWasm = {};
710
+ __export(exports_LuteWasm, {
711
+ LuteWasm: () => LuteWasm2,
712
+ fromBytes: () => fromBytes,
713
+ layerFromBytes: () => layerFromBytes
714
+ });
715
+ import { Context as Context3, Effect as Effect4, Layer as Layer3 } from "effect";
716
+ import * as Glue from "./wasm/lute_runtime_wasm.js";
717
+
718
+ class LuteWasm2 extends Context3.Service()("@lute-lang/runtime/LuteWasm") {
719
+ }
720
+ var fromBytes = (bytes) => Effect4.try({
721
+ try: () => {
722
+ const { buffer, byteOffset, byteLength } = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
723
+ if (!(buffer instanceof ArrayBuffer))
724
+ throw new TypeError("the bytes live in a SharedArrayBuffer");
725
+ Glue.initSync({ module: new Uint8Array(buffer, byteOffset, byteLength) });
726
+ return { Program: Glue.Program };
727
+ },
728
+ catch: (cause) => new WasmLoadError({ message: `cannot instantiate the runtime binding: ${String(cause)}` })
729
+ });
730
+ var layerFromBytes = (bytes) => Layer3.effect(LuteWasm2, fromBytes(bytes));
731
+
732
+ // src/Program.ts
733
+ var exports_Program = {};
734
+ __export(exports_Program, {
735
+ make: () => make,
736
+ rejection: () => rejection
737
+ });
738
+ import { Effect as Effect5, Option as Option2, Schema as Schema6 } from "effect";
739
+ var TypeId = "~@lute-lang/runtime/RuntimeState";
740
+ var handles = new WeakMap;
741
+ var wrap = (handle) => {
742
+ const state = { [TypeId]: TypeId };
743
+ handles.set(state, handle);
744
+ return state;
745
+ };
746
+ var handleOf = (state) => {
747
+ const handle = handles.get(state);
748
+ return handle === undefined ? Effect5.die(new Error("a RuntimeState must come from a Program of this package")) : Effect5.succeed(handle);
749
+ };
750
+ var fromBinding = (schema) => {
751
+ const decode = Schema6.decodeUnknownEffect(Schema6.fromJsonString(schema), parseOptions);
752
+ return (json) => Effect5.orDie(decode(json));
753
+ };
754
+ var toBinding = (schema) => {
755
+ const encode = Schema6.encodeEffect(Schema6.fromJsonString(schema), parseOptions);
756
+ return (value) => Effect5.orDie(encode(value));
757
+ };
758
+ var decodeOutput = fromBinding(Output);
759
+ var decodeRejected = fromBinding(Rejected);
760
+ var decodeSnapshot = fromBinding(Snapshot);
761
+ var decodeCandidates = fromBinding(Schema6.Array(Candidate));
762
+ var decodeCandidate = fromBinding(Schema6.NullOr(Candidate));
763
+ var decodeStage = fromBinding(Stage);
764
+ var decodeClock = fromBinding(Schema6.NullOr(ClockAt));
765
+ var decodeView = fromBinding(WorldView);
766
+ var encodeSeed = toBinding(Seed);
767
+ var encodeInput = toBinding(Input);
768
+ var encodeSnapshot = toBinding(Snapshot);
769
+ var rejection = (json) => Effect5.flatMap(decodeRejected(json), fromRejected);
770
+ var settle = (result, success) => Effect5.suspend(() => {
771
+ const { ok, rejected } = result;
772
+ if (ok)
773
+ return success();
774
+ if (rejected !== undefined)
775
+ return rejection(rejected);
776
+ return Effect5.die(new Error("the runtime binding returned neither a value nor a rejection"));
777
+ }).pipe(Effect5.ensuring(Effect5.sync(() => result.free())));
778
+ var stepOf = (result) => settle(result, () => {
779
+ const { state, output } = result;
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 }));
781
+ });
782
+ var make = (raw) => ({
783
+ fingerprint: raw.fingerprint,
784
+ begin: Effect5.fn("Lute.Program.begin")(function* (seed) {
785
+ const json = yield* encodeSeed(seed);
786
+ return yield* stepOf(raw.begin(json));
787
+ }),
788
+ step: Effect5.fn("Lute.Program.step")(function* (state, input) {
789
+ const handle = yield* handleOf(state);
790
+ const json = yield* encodeInput(input);
791
+ return yield* stepOf(raw.step(handle, json));
792
+ }),
793
+ snapshot: Effect5.fn("Lute.Program.snapshot")(function* (state) {
794
+ const handle = yield* handleOf(state);
795
+ return yield* decodeSnapshot(raw.snapshot(handle));
796
+ }),
797
+ restore: Effect5.fn("Lute.Program.restore")(function* (snapshot) {
798
+ const json = yield* encodeSnapshot(snapshot);
799
+ const result = raw.restore(json);
800
+ return yield* settle(result, () => {
801
+ const { state } = result;
802
+ return state === undefined ? Effect5.die(new Error("the runtime binding restored a snapshot without a state")) : Effect5.succeed(wrap(state));
803
+ });
804
+ }),
805
+ candidates: Effect5.fn("Lute.Program.candidates")(function* (state, occasion, target) {
806
+ const handle = yield* handleOf(state);
807
+ return yield* decodeCandidates(raw.candidates(handle, occasion, target));
808
+ }),
809
+ eligibility: Effect5.fn("Lute.Program.eligibility")(function* (state, beat, member) {
810
+ const handle = yield* handleOf(state);
811
+ const candidate = yield* decodeCandidate(raw.eligibility(handle, beat, member));
812
+ return Option2.fromNullOr(candidate);
813
+ }),
814
+ clock: Effect5.fn("Lute.Program.clock")(function* (state) {
815
+ const handle = yield* handleOf(state);
816
+ const clock = yield* decodeClock(raw.clock(handle));
817
+ return Option2.fromNullOr(clock);
818
+ }),
819
+ terminal: Effect5.fn("Lute.Program.terminal")(function* (state) {
820
+ const handle = yield* handleOf(state);
821
+ return raw.terminal(handle);
822
+ }),
823
+ stage: Effect5.fn("Lute.Program.stage")(function* (state) {
824
+ const handle = yield* handleOf(state);
825
+ return yield* decodeStage(raw.stage(handle));
826
+ }),
827
+ view: Effect5.fn("Lute.Program.view")(function* (state, options) {
828
+ const handle = yield* handleOf(state);
829
+ return yield* decodeView(raw.view(handle, options?.facts === true));
830
+ }),
831
+ free: Effect5.sync(() => raw.free())
832
+ });
833
+
834
+ // src/LuteRuntime.ts
835
+ var exports_LuteRuntime = {};
836
+ __export(exports_LuteRuntime, {
837
+ LuteRuntime: () => LuteRuntime,
838
+ layer: () => layer
839
+ });
840
+ import { Context as Context4, Effect as Effect6, Layer as Layer4 } from "effect";
841
+ class LuteRuntime extends Context4.Service()("@lute-lang/runtime/LuteRuntime") {
842
+ }
843
+ var layer = Layer4.effect(LuteRuntime, Effect6.gen(function* () {
844
+ const wasm = yield* LuteWasm2;
845
+ const acquire = Effect6.fn("Lute.LuteRuntime.load")(function* (bundle) {
846
+ const result = wasm.Program.load(JSON.stringify(bundle.index), JSON.stringify(bundle.artifacts));
847
+ const { ok, program, rejected } = result;
848
+ result.free();
849
+ if (ok && program !== undefined)
850
+ return make(program);
851
+ if (rejected !== undefined)
852
+ return yield* rejection(rejected);
853
+ return yield* Effect6.die(new Error("the runtime binding returned neither a program nor a rejection"));
854
+ });
855
+ return {
856
+ load: (bundle) => Effect6.acquireRelease(acquire(bundle), (program) => program.free)
857
+ };
858
+ }));
859
+
860
+ // src/Session.ts
861
+ var exports_Session = {};
862
+ __export(exports_Session, {
863
+ Session: () => Session,
864
+ layer: () => layer2
865
+ });
866
+ import { Context as Context5, Effect as Effect7, Layer as Layer5, PubSub, Semaphore, Stream, SubscriptionRef } from "effect";
867
+ class Session extends Context5.Service()("@lute-lang/runtime/Session") {
868
+ }
869
+ var layer2 = (options) => Layer5.effect(Session, Effect7.gen(function* () {
870
+ const runtime = yield* LuteRuntime;
871
+ const log = yield* InputLog;
872
+ const bundle = yield* (yield* BundleSource).load;
873
+ const program = yield* runtime.load(bundle);
874
+ const started = "seed" in options ? yield* program.begin(options.seed) : {
875
+ state: yield* program.restore(options.snapshot),
876
+ output: { eventVersion: options.snapshot.snapshotVersion, events: [], await: options.snapshot.await }
877
+ };
878
+ const stage = yield* program.stage(started.state);
879
+ yield* log.reset(options);
880
+ const current = yield* SubscriptionRef.make({
881
+ state: started.state,
882
+ stage,
883
+ await: started.output.await
884
+ });
885
+ const events = yield* PubSub.unbounded();
886
+ const awaits = yield* PubSub.unbounded();
887
+ yield* Effect7.addFinalizer(() => Effect7.andThen(PubSub.shutdown(events), PubSub.shutdown(awaits)));
888
+ const lock = yield* Semaphore.make(1);
889
+ const send = Effect7.fn("Lute.Session.send")(function* (input) {
890
+ const { state } = yield* SubscriptionRef.get(current);
891
+ const step = yield* program.step(state, input);
892
+ yield* log.append({ input });
893
+ const stage = yield* program.stage(step.state);
894
+ yield* SubscriptionRef.set(current, { state: step.state, stage, await: step.output.await });
895
+ yield* PubSub.publishAll(events, step.output.events);
896
+ yield* PubSub.publish(awaits, step.output.await);
897
+ return step.output;
898
+ });
899
+ const restore = Effect7.fn("Lute.Session.restore")(function* (snapshot) {
900
+ const state = yield* program.restore(snapshot);
901
+ const stage = yield* program.stage(state);
902
+ yield* log.reset({ snapshot });
903
+ yield* SubscriptionRef.set(current, { state, stage, await: snapshot.await });
904
+ yield* PubSub.publish(awaits, snapshot.await);
905
+ });
906
+ return {
907
+ fingerprint: program.fingerprint,
908
+ started: started.output,
909
+ send: (input) => lock.withPermits(1)(send(input)),
910
+ current,
911
+ events: Effect7.map(PubSub.subscribe(events), Stream.fromSubscription),
912
+ awaits: Effect7.map(PubSub.subscribe(awaits), Stream.fromSubscription),
913
+ save: SubscriptionRef.get(current).pipe(Effect7.flatMap(({ state }) => program.snapshot(state)), Effect7.withSpan("Lute.Session.save")),
914
+ restore: (snapshot) => lock.withPermits(1)(restore(snapshot))
915
+ };
916
+ }));
917
+
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 };