@effect-ak/tg-bot 1.0.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/dist/index.js ADDED
@@ -0,0 +1,3865 @@
1
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Function.js
2
+ var isFunction = (input) => typeof input === "function";
3
+ var dual = function(arity, body) {
4
+ if (typeof arity === "function") {
5
+ return function() {
6
+ if (arity(arguments)) {
7
+ return body.apply(this, arguments);
8
+ }
9
+ return (self) => body(self, ...arguments);
10
+ };
11
+ }
12
+ switch (arity) {
13
+ case 0:
14
+ case 1:
15
+ throw new RangeError(`Invalid arity ${arity}`);
16
+ case 2:
17
+ return function(a, b) {
18
+ if (arguments.length >= 2) {
19
+ return body(a, b);
20
+ }
21
+ return function(self) {
22
+ return body(self, a);
23
+ };
24
+ };
25
+ case 3:
26
+ return function(a, b, c) {
27
+ if (arguments.length >= 3) {
28
+ return body(a, b, c);
29
+ }
30
+ return function(self) {
31
+ return body(self, a, b);
32
+ };
33
+ };
34
+ case 4:
35
+ return function(a, b, c, d) {
36
+ if (arguments.length >= 4) {
37
+ return body(a, b, c, d);
38
+ }
39
+ return function(self) {
40
+ return body(self, a, b, c);
41
+ };
42
+ };
43
+ case 5:
44
+ return function(a, b, c, d, e) {
45
+ if (arguments.length >= 5) {
46
+ return body(a, b, c, d, e);
47
+ }
48
+ return function(self) {
49
+ return body(self, a, b, c, d);
50
+ };
51
+ };
52
+ default:
53
+ return function() {
54
+ if (arguments.length >= arity) {
55
+ return body.apply(this, arguments);
56
+ }
57
+ const args2 = arguments;
58
+ return function(self) {
59
+ return body(self, ...args2);
60
+ };
61
+ };
62
+ }
63
+ };
64
+ var identity = (a) => a;
65
+ var constant = (value) => () => value;
66
+ var constTrue = /* @__PURE__ */ constant(true);
67
+ var constFalse = /* @__PURE__ */ constant(false);
68
+ var constUndefined = /* @__PURE__ */ constant(void 0);
69
+ var constVoid = constUndefined;
70
+ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
71
+ switch (arguments.length) {
72
+ case 1:
73
+ return a;
74
+ case 2:
75
+ return ab(a);
76
+ case 3:
77
+ return bc(ab(a));
78
+ case 4:
79
+ return cd(bc(ab(a)));
80
+ case 5:
81
+ return de(cd(bc(ab(a))));
82
+ case 6:
83
+ return ef(de(cd(bc(ab(a)))));
84
+ case 7:
85
+ return fg(ef(de(cd(bc(ab(a))))));
86
+ case 8:
87
+ return gh(fg(ef(de(cd(bc(ab(a)))))));
88
+ case 9:
89
+ return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
90
+ default: {
91
+ let ret = arguments[0];
92
+ for (let i = 1; i < arguments.length; i++) {
93
+ ret = arguments[i](ret);
94
+ }
95
+ return ret;
96
+ }
97
+ }
98
+ }
99
+
100
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Equivalence.js
101
+ var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
102
+
103
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/version.js
104
+ var moduleVersion = "3.12.0";
105
+ var getCurrentVersion = () => moduleVersion;
106
+
107
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/GlobalValue.js
108
+ var globalStoreId = /* @__PURE__ */ Symbol.for(`effect/GlobalValue/globalStoreId/${/* @__PURE__ */ getCurrentVersion()}`);
109
+ if (!(globalStoreId in globalThis)) {
110
+ ;
111
+ globalThis[globalStoreId] = /* @__PURE__ */ new Map();
112
+ }
113
+ var globalStore = globalThis[globalStoreId];
114
+ var globalValue = (id, compute) => {
115
+ if (!globalStore.has(id)) {
116
+ globalStore.set(id, compute());
117
+ }
118
+ return globalStore.get(id);
119
+ };
120
+
121
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Predicate.js
122
+ var isFunction2 = isFunction;
123
+ var isRecordOrArray = (input) => typeof input === "object" && input !== null;
124
+ var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
125
+ var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
126
+ var isTagged = /* @__PURE__ */ dual(2, (self, tag) => hasProperty(self, "_tag") && self["_tag"] === tag);
127
+
128
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/errors.js
129
+ var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
130
+
131
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Utils.js
132
+ var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
133
+ var GenKindImpl = class {
134
+ value;
135
+ constructor(value) {
136
+ this.value = value;
137
+ }
138
+ /**
139
+ * @since 2.0.0
140
+ */
141
+ get _F() {
142
+ return identity;
143
+ }
144
+ /**
145
+ * @since 2.0.0
146
+ */
147
+ get _R() {
148
+ return (_) => _;
149
+ }
150
+ /**
151
+ * @since 2.0.0
152
+ */
153
+ get _O() {
154
+ return (_) => _;
155
+ }
156
+ /**
157
+ * @since 2.0.0
158
+ */
159
+ get _E() {
160
+ return (_) => _;
161
+ }
162
+ /**
163
+ * @since 2.0.0
164
+ */
165
+ [GenKindTypeId] = GenKindTypeId;
166
+ /**
167
+ * @since 2.0.0
168
+ */
169
+ [Symbol.iterator]() {
170
+ return new SingleShotGen(this);
171
+ }
172
+ };
173
+ var SingleShotGen = class _SingleShotGen {
174
+ self;
175
+ called = false;
176
+ constructor(self) {
177
+ this.self = self;
178
+ }
179
+ /**
180
+ * @since 2.0.0
181
+ */
182
+ next(a) {
183
+ return this.called ? {
184
+ value: a,
185
+ done: true
186
+ } : (this.called = true, {
187
+ value: this.self,
188
+ done: false
189
+ });
190
+ }
191
+ /**
192
+ * @since 2.0.0
193
+ */
194
+ return(a) {
195
+ return {
196
+ value: a,
197
+ done: true
198
+ };
199
+ }
200
+ /**
201
+ * @since 2.0.0
202
+ */
203
+ throw(e) {
204
+ throw e;
205
+ }
206
+ /**
207
+ * @since 2.0.0
208
+ */
209
+ [Symbol.iterator]() {
210
+ return new _SingleShotGen(this.self);
211
+ }
212
+ };
213
+ var MUL_HI = 1481765933 >>> 0;
214
+ var MUL_LO = 1284865837 >>> 0;
215
+ var YieldWrapTypeId = /* @__PURE__ */ Symbol.for("effect/Utils/YieldWrap");
216
+ var YieldWrap = class {
217
+ /**
218
+ * @since 3.0.6
219
+ */
220
+ #value;
221
+ constructor(value) {
222
+ this.#value = value;
223
+ }
224
+ /**
225
+ * @since 3.0.6
226
+ */
227
+ [YieldWrapTypeId]() {
228
+ return this.#value;
229
+ }
230
+ };
231
+ function yieldWrapGet(self) {
232
+ if (typeof self === "object" && self !== null && YieldWrapTypeId in self) {
233
+ return self[YieldWrapTypeId]();
234
+ }
235
+ throw new Error(getBugErrorMessage("yieldWrapGet"));
236
+ }
237
+ var structuralRegionState = /* @__PURE__ */ globalValue("effect/Utils/isStructuralRegion", () => ({
238
+ enabled: false,
239
+ tester: void 0
240
+ }));
241
+ var genConstructor = function* () {
242
+ }.constructor;
243
+
244
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Hash.js
245
+ var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
246
+ var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
247
+ var hash = (self) => {
248
+ if (structuralRegionState.enabled === true) {
249
+ return 0;
250
+ }
251
+ switch (typeof self) {
252
+ case "number":
253
+ return number(self);
254
+ case "bigint":
255
+ return string(self.toString(10));
256
+ case "boolean":
257
+ return string(String(self));
258
+ case "symbol":
259
+ return string(String(self));
260
+ case "string":
261
+ return string(self);
262
+ case "undefined":
263
+ return string("undefined");
264
+ case "function":
265
+ case "object": {
266
+ if (self === null) {
267
+ return string("null");
268
+ } else if (self instanceof Date) {
269
+ return hash(self.toISOString());
270
+ } else if (isHash(self)) {
271
+ return self[symbol]();
272
+ } else {
273
+ return random(self);
274
+ }
275
+ }
276
+ default:
277
+ throw new Error(`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`);
278
+ }
279
+ };
280
+ var random = (self) => {
281
+ if (!randomHashCache.has(self)) {
282
+ randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)));
283
+ }
284
+ return randomHashCache.get(self);
285
+ };
286
+ var combine = (b) => (self) => self * 53 ^ b;
287
+ var optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
288
+ var isHash = (u) => hasProperty(u, symbol);
289
+ var number = (n) => {
290
+ if (n !== n || n === Infinity) {
291
+ return 0;
292
+ }
293
+ let h = n | 0;
294
+ if (h !== n) {
295
+ h ^= n * 4294967295;
296
+ }
297
+ while (n > 4294967295) {
298
+ h ^= n /= 4294967295;
299
+ }
300
+ return optimize(h);
301
+ };
302
+ var string = (str) => {
303
+ let h = 5381, i = str.length;
304
+ while (i) {
305
+ h = h * 33 ^ str.charCodeAt(--i);
306
+ }
307
+ return optimize(h);
308
+ };
309
+ var structureKeys = (o, keys2) => {
310
+ let h = 12289;
311
+ for (let i = 0; i < keys2.length; i++) {
312
+ h ^= pipe(string(keys2[i]), combine(hash(o[keys2[i]])));
313
+ }
314
+ return optimize(h);
315
+ };
316
+ var structure = (o) => structureKeys(o, Object.keys(o));
317
+ var array = (arr) => {
318
+ let h = 6151;
319
+ for (let i = 0; i < arr.length; i++) {
320
+ h = pipe(h, combine(hash(arr[i])));
321
+ }
322
+ return optimize(h);
323
+ };
324
+ var cached = function() {
325
+ if (arguments.length === 1) {
326
+ const self2 = arguments[0];
327
+ return function(hash3) {
328
+ Object.defineProperty(self2, symbol, {
329
+ value() {
330
+ return hash3;
331
+ },
332
+ enumerable: false
333
+ });
334
+ return hash3;
335
+ };
336
+ }
337
+ const self = arguments[0];
338
+ const hash2 = arguments[1];
339
+ Object.defineProperty(self, symbol, {
340
+ value() {
341
+ return hash2;
342
+ },
343
+ enumerable: false
344
+ });
345
+ return hash2;
346
+ };
347
+
348
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Equal.js
349
+ var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
350
+ function equals() {
351
+ if (arguments.length === 1) {
352
+ return (self) => compareBoth(self, arguments[0]);
353
+ }
354
+ return compareBoth(arguments[0], arguments[1]);
355
+ }
356
+ function compareBoth(self, that) {
357
+ if (self === that) {
358
+ return true;
359
+ }
360
+ const selfType = typeof self;
361
+ if (selfType !== typeof that) {
362
+ return false;
363
+ }
364
+ if (selfType === "object" || selfType === "function") {
365
+ if (self !== null && that !== null) {
366
+ if (isEqual(self) && isEqual(that)) {
367
+ if (hash(self) === hash(that) && self[symbol2](that)) {
368
+ return true;
369
+ } else {
370
+ return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
371
+ }
372
+ } else if (self instanceof Date && that instanceof Date) {
373
+ return self.toISOString() === that.toISOString();
374
+ }
375
+ }
376
+ if (structuralRegionState.enabled) {
377
+ if (Array.isArray(self) && Array.isArray(that)) {
378
+ return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]));
379
+ }
380
+ if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
381
+ const keysSelf = Object.keys(self);
382
+ const keysThat = Object.keys(that);
383
+ if (keysSelf.length === keysThat.length) {
384
+ for (const key of keysSelf) {
385
+ if (!(key in that && compareBoth(self[key], that[key]))) {
386
+ return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
387
+ }
388
+ }
389
+ return true;
390
+ }
391
+ }
392
+ return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
393
+ }
394
+ }
395
+ return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
396
+ }
397
+ var isEqual = (u) => hasProperty(u, symbol2);
398
+
399
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Inspectable.js
400
+ var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
401
+ var toJSON = (x) => {
402
+ try {
403
+ if (hasProperty(x, "toJSON") && isFunction2(x["toJSON"]) && x["toJSON"].length === 0) {
404
+ return x.toJSON();
405
+ } else if (Array.isArray(x)) {
406
+ return x.map(toJSON);
407
+ }
408
+ } catch (_) {
409
+ return {};
410
+ }
411
+ return redact(x);
412
+ };
413
+ var format = (x) => JSON.stringify(x, null, 2);
414
+ var BaseProto = {
415
+ toJSON() {
416
+ return toJSON(this);
417
+ },
418
+ [NodeInspectSymbol]() {
419
+ return this.toJSON();
420
+ },
421
+ toString() {
422
+ return format(this.toJSON());
423
+ }
424
+ };
425
+ var Class = class {
426
+ /**
427
+ * @since 2.0.0
428
+ */
429
+ [NodeInspectSymbol]() {
430
+ return this.toJSON();
431
+ }
432
+ /**
433
+ * @since 2.0.0
434
+ */
435
+ toString() {
436
+ return format(this.toJSON());
437
+ }
438
+ };
439
+ var toStringUnknown = (u, whitespace = 2) => {
440
+ if (typeof u === "string") {
441
+ return u;
442
+ }
443
+ try {
444
+ return typeof u === "object" ? stringifyCircular(u, whitespace) : String(u);
445
+ } catch (_) {
446
+ return String(u);
447
+ }
448
+ };
449
+ var stringifyCircular = (obj, whitespace) => {
450
+ let cache = [];
451
+ const retVal = JSON.stringify(obj, (_key, value) => typeof value === "object" && value !== null ? cache.includes(value) ? void 0 : cache.push(value) && (redactableState.fiberRefs !== void 0 && isRedactable(value) ? value[symbolRedactable](redactableState.fiberRefs) : value) : value, whitespace);
452
+ cache = void 0;
453
+ return retVal;
454
+ };
455
+ var symbolRedactable = /* @__PURE__ */ Symbol.for("effect/Inspectable/Redactable");
456
+ var isRedactable = (u) => typeof u === "object" && u !== null && symbolRedactable in u;
457
+ var redactableState = /* @__PURE__ */ globalValue("effect/Inspectable/redactableState", () => ({
458
+ fiberRefs: void 0
459
+ }));
460
+ var redact = (u) => {
461
+ if (isRedactable(u) && redactableState.fiberRefs !== void 0) {
462
+ return u[symbolRedactable](redactableState.fiberRefs);
463
+ }
464
+ return u;
465
+ };
466
+
467
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Pipeable.js
468
+ var pipeArguments = (self, args2) => {
469
+ switch (args2.length) {
470
+ case 0:
471
+ return self;
472
+ case 1:
473
+ return args2[0](self);
474
+ case 2:
475
+ return args2[1](args2[0](self));
476
+ case 3:
477
+ return args2[2](args2[1](args2[0](self)));
478
+ case 4:
479
+ return args2[3](args2[2](args2[1](args2[0](self))));
480
+ case 5:
481
+ return args2[4](args2[3](args2[2](args2[1](args2[0](self)))));
482
+ case 6:
483
+ return args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self))))));
484
+ case 7:
485
+ return args2[6](args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self)))))));
486
+ case 8:
487
+ return args2[7](args2[6](args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self))))))));
488
+ case 9:
489
+ return args2[8](args2[7](args2[6](args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self)))))))));
490
+ default: {
491
+ let ret = self;
492
+ for (let i = 0, len = args2.length; i < len; i++) {
493
+ ret = args2[i](ret);
494
+ }
495
+ return ret;
496
+ }
497
+ }
498
+ };
499
+
500
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/opCodes/effect.js
501
+ var OP_COMMIT = "Commit";
502
+ var OP_FAILURE = "Failure";
503
+ var OP_WITH_RUNTIME = "WithRuntime";
504
+
505
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/effectable.js
506
+ var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
507
+ var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
508
+ var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
509
+ var ChannelTypeId = /* @__PURE__ */ Symbol.for("effect/Channel");
510
+ var effectVariance = {
511
+ /* c8 ignore next */
512
+ _R: (_) => _,
513
+ /* c8 ignore next */
514
+ _E: (_) => _,
515
+ /* c8 ignore next */
516
+ _A: (_) => _,
517
+ _V: /* @__PURE__ */ getCurrentVersion()
518
+ };
519
+ var sinkVariance = {
520
+ /* c8 ignore next */
521
+ _A: (_) => _,
522
+ /* c8 ignore next */
523
+ _In: (_) => _,
524
+ /* c8 ignore next */
525
+ _L: (_) => _,
526
+ /* c8 ignore next */
527
+ _E: (_) => _,
528
+ /* c8 ignore next */
529
+ _R: (_) => _
530
+ };
531
+ var channelVariance = {
532
+ /* c8 ignore next */
533
+ _Env: (_) => _,
534
+ /* c8 ignore next */
535
+ _InErr: (_) => _,
536
+ /* c8 ignore next */
537
+ _InElem: (_) => _,
538
+ /* c8 ignore next */
539
+ _InDone: (_) => _,
540
+ /* c8 ignore next */
541
+ _OutErr: (_) => _,
542
+ /* c8 ignore next */
543
+ _OutElem: (_) => _,
544
+ /* c8 ignore next */
545
+ _OutDone: (_) => _
546
+ };
547
+ var EffectPrototype = {
548
+ [EffectTypeId]: effectVariance,
549
+ [StreamTypeId]: effectVariance,
550
+ [SinkTypeId]: sinkVariance,
551
+ [ChannelTypeId]: channelVariance,
552
+ [symbol2](that) {
553
+ return this === that;
554
+ },
555
+ [symbol]() {
556
+ return cached(this, random(this));
557
+ },
558
+ [Symbol.iterator]() {
559
+ return new SingleShotGen(new YieldWrap(this));
560
+ },
561
+ pipe() {
562
+ return pipeArguments(this, arguments);
563
+ }
564
+ };
565
+ var StructuralPrototype = {
566
+ [symbol]() {
567
+ return cached(this, structure(this));
568
+ },
569
+ [symbol2](that) {
570
+ const selfKeys = Object.keys(this);
571
+ const thatKeys = Object.keys(that);
572
+ if (selfKeys.length !== thatKeys.length) {
573
+ return false;
574
+ }
575
+ for (const key of selfKeys) {
576
+ if (!(key in that && equals(this[key], that[key]))) {
577
+ return false;
578
+ }
579
+ }
580
+ return true;
581
+ }
582
+ };
583
+ var CommitPrototype = {
584
+ ...EffectPrototype,
585
+ _op: OP_COMMIT
586
+ };
587
+ var StructuralCommitPrototype = {
588
+ ...CommitPrototype,
589
+ ...StructuralPrototype
590
+ };
591
+
592
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/option.js
593
+ var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
594
+ var CommonProto = {
595
+ ...EffectPrototype,
596
+ [TypeId]: {
597
+ _A: (_) => _
598
+ },
599
+ [NodeInspectSymbol]() {
600
+ return this.toJSON();
601
+ },
602
+ toString() {
603
+ return format(this.toJSON());
604
+ }
605
+ };
606
+ var SomeProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
607
+ _tag: "Some",
608
+ _op: "Some",
609
+ [symbol2](that) {
610
+ return isOption(that) && isSome(that) && equals(this.value, that.value);
611
+ },
612
+ [symbol]() {
613
+ return cached(this, combine(hash(this._tag))(hash(this.value)));
614
+ },
615
+ toJSON() {
616
+ return {
617
+ _id: "Option",
618
+ _tag: this._tag,
619
+ value: toJSON(this.value)
620
+ };
621
+ }
622
+ });
623
+ var NoneHash = /* @__PURE__ */ hash("None");
624
+ var NoneProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
625
+ _tag: "None",
626
+ _op: "None",
627
+ [symbol2](that) {
628
+ return isOption(that) && isNone(that);
629
+ },
630
+ [symbol]() {
631
+ return NoneHash;
632
+ },
633
+ toJSON() {
634
+ return {
635
+ _id: "Option",
636
+ _tag: this._tag
637
+ };
638
+ }
639
+ });
640
+ var isOption = (input) => hasProperty(input, TypeId);
641
+ var isNone = (fa) => fa._tag === "None";
642
+ var isSome = (fa) => fa._tag === "Some";
643
+ var none = /* @__PURE__ */ Object.create(NoneProto);
644
+ var some = (value) => {
645
+ const a = Object.create(SomeProto);
646
+ a.value = value;
647
+ return a;
648
+ };
649
+
650
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/either.js
651
+ var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
652
+ var CommonProto2 = {
653
+ ...EffectPrototype,
654
+ [TypeId2]: {
655
+ _R: (_) => _
656
+ },
657
+ [NodeInspectSymbol]() {
658
+ return this.toJSON();
659
+ },
660
+ toString() {
661
+ return format(this.toJSON());
662
+ }
663
+ };
664
+ var RightProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
665
+ _tag: "Right",
666
+ _op: "Right",
667
+ [symbol2](that) {
668
+ return isEither(that) && isRight(that) && equals(this.right, that.right);
669
+ },
670
+ [symbol]() {
671
+ return combine(hash(this._tag))(hash(this.right));
672
+ },
673
+ toJSON() {
674
+ return {
675
+ _id: "Either",
676
+ _tag: this._tag,
677
+ right: toJSON(this.right)
678
+ };
679
+ }
680
+ });
681
+ var LeftProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
682
+ _tag: "Left",
683
+ _op: "Left",
684
+ [symbol2](that) {
685
+ return isEither(that) && isLeft(that) && equals(this.left, that.left);
686
+ },
687
+ [symbol]() {
688
+ return combine(hash(this._tag))(hash(this.left));
689
+ },
690
+ toJSON() {
691
+ return {
692
+ _id: "Either",
693
+ _tag: this._tag,
694
+ left: toJSON(this.left)
695
+ };
696
+ }
697
+ });
698
+ var isEither = (input) => hasProperty(input, TypeId2);
699
+ var isLeft = (ma) => ma._tag === "Left";
700
+ var isRight = (ma) => ma._tag === "Right";
701
+ var left = (left3) => {
702
+ const a = Object.create(LeftProto);
703
+ a.left = left3;
704
+ return a;
705
+ };
706
+ var right = (right3) => {
707
+ const a = Object.create(RightProto);
708
+ a.right = right3;
709
+ return a;
710
+ };
711
+
712
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Either.js
713
+ var right2 = right;
714
+ var left2 = left;
715
+
716
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Option.js
717
+ var none2 = () => none;
718
+ var some2 = some;
719
+ var isNone2 = isNone;
720
+ var isSome2 = isSome;
721
+ var getOrElse = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
722
+ var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
723
+
724
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Array.js
725
+ var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
726
+ var isArray = Array.isArray;
727
+ var reverse = (self) => Array.from(self).reverse();
728
+ var reduce = /* @__PURE__ */ dual(3, (self, b, f) => fromIterable(self).reduce((b2, a, i) => f(b2, a, i), b));
729
+
730
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Chunk.js
731
+ var TypeId3 = /* @__PURE__ */ Symbol.for("effect/Chunk");
732
+ function copy(src, srcPos, dest, destPos, len) {
733
+ for (let i = srcPos; i < Math.min(src.length, srcPos + len); i++) {
734
+ dest[destPos + i - srcPos] = src[i];
735
+ }
736
+ return dest;
737
+ }
738
+ var emptyArray = [];
739
+ var getEquivalence = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet(that, i))));
740
+ var _equivalence = /* @__PURE__ */ getEquivalence(equals);
741
+ var ChunkProto = {
742
+ [TypeId3]: {
743
+ _A: (_) => _
744
+ },
745
+ toString() {
746
+ return format(this.toJSON());
747
+ },
748
+ toJSON() {
749
+ return {
750
+ _id: "Chunk",
751
+ values: toReadonlyArray(this).map(toJSON)
752
+ };
753
+ },
754
+ [NodeInspectSymbol]() {
755
+ return this.toJSON();
756
+ },
757
+ [symbol2](that) {
758
+ return isChunk(that) && _equivalence(this, that);
759
+ },
760
+ [symbol]() {
761
+ return cached(this, array(toReadonlyArray(this)));
762
+ },
763
+ [Symbol.iterator]() {
764
+ switch (this.backing._tag) {
765
+ case "IArray": {
766
+ return this.backing.array[Symbol.iterator]();
767
+ }
768
+ case "IEmpty": {
769
+ return emptyArray[Symbol.iterator]();
770
+ }
771
+ default: {
772
+ return toReadonlyArray(this)[Symbol.iterator]();
773
+ }
774
+ }
775
+ },
776
+ pipe() {
777
+ return pipeArguments(this, arguments);
778
+ }
779
+ };
780
+ var makeChunk = (backing) => {
781
+ const chunk = Object.create(ChunkProto);
782
+ chunk.backing = backing;
783
+ switch (backing._tag) {
784
+ case "IEmpty": {
785
+ chunk.length = 0;
786
+ chunk.depth = 0;
787
+ chunk.left = chunk;
788
+ chunk.right = chunk;
789
+ break;
790
+ }
791
+ case "IConcat": {
792
+ chunk.length = backing.left.length + backing.right.length;
793
+ chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth);
794
+ chunk.left = backing.left;
795
+ chunk.right = backing.right;
796
+ break;
797
+ }
798
+ case "IArray": {
799
+ chunk.length = backing.array.length;
800
+ chunk.depth = 0;
801
+ chunk.left = _empty;
802
+ chunk.right = _empty;
803
+ break;
804
+ }
805
+ case "ISingleton": {
806
+ chunk.length = 1;
807
+ chunk.depth = 0;
808
+ chunk.left = _empty;
809
+ chunk.right = _empty;
810
+ break;
811
+ }
812
+ case "ISlice": {
813
+ chunk.length = backing.length;
814
+ chunk.depth = backing.chunk.depth + 1;
815
+ chunk.left = _empty;
816
+ chunk.right = _empty;
817
+ break;
818
+ }
819
+ }
820
+ return chunk;
821
+ };
822
+ var isChunk = (u) => hasProperty(u, TypeId3);
823
+ var _empty = /* @__PURE__ */ makeChunk({
824
+ _tag: "IEmpty"
825
+ });
826
+ var empty = () => _empty;
827
+ var make2 = (...as2) => as2.length === 1 ? of(as2[0]) : unsafeFromNonEmptyArray(as2);
828
+ var of = (a) => makeChunk({
829
+ _tag: "ISingleton",
830
+ a
831
+ });
832
+ var fromIterable2 = (self) => isChunk(self) ? self : makeChunk({
833
+ _tag: "IArray",
834
+ array: fromIterable(self)
835
+ });
836
+ var copyToArray = (self, array2, initial) => {
837
+ switch (self.backing._tag) {
838
+ case "IArray": {
839
+ copy(self.backing.array, 0, array2, initial, self.length);
840
+ break;
841
+ }
842
+ case "IConcat": {
843
+ copyToArray(self.left, array2, initial);
844
+ copyToArray(self.right, array2, initial + self.left.length);
845
+ break;
846
+ }
847
+ case "ISingleton": {
848
+ array2[initial] = self.backing.a;
849
+ break;
850
+ }
851
+ case "ISlice": {
852
+ let i = 0;
853
+ let j = initial;
854
+ while (i < self.length) {
855
+ array2[j] = unsafeGet(self, i);
856
+ i += 1;
857
+ j += 1;
858
+ }
859
+ break;
860
+ }
861
+ }
862
+ };
863
+ var toReadonlyArray_ = (self) => {
864
+ switch (self.backing._tag) {
865
+ case "IEmpty": {
866
+ return emptyArray;
867
+ }
868
+ case "IArray": {
869
+ return self.backing.array;
870
+ }
871
+ default: {
872
+ const arr = new Array(self.length);
873
+ copyToArray(self, arr, 0);
874
+ self.backing = {
875
+ _tag: "IArray",
876
+ array: arr
877
+ };
878
+ self.left = _empty;
879
+ self.right = _empty;
880
+ self.depth = 0;
881
+ return arr;
882
+ }
883
+ }
884
+ };
885
+ var toReadonlyArray = toReadonlyArray_;
886
+ var reverseChunk = (self) => {
887
+ switch (self.backing._tag) {
888
+ case "IEmpty":
889
+ case "ISingleton":
890
+ return self;
891
+ case "IArray": {
892
+ return makeChunk({
893
+ _tag: "IArray",
894
+ array: reverse(self.backing.array)
895
+ });
896
+ }
897
+ case "IConcat": {
898
+ return makeChunk({
899
+ _tag: "IConcat",
900
+ left: reverse2(self.backing.right),
901
+ right: reverse2(self.backing.left)
902
+ });
903
+ }
904
+ case "ISlice":
905
+ return unsafeFromArray(reverse(toReadonlyArray(self)));
906
+ }
907
+ };
908
+ var reverse2 = reverseChunk;
909
+ var unsafeFromArray = (self) => makeChunk({
910
+ _tag: "IArray",
911
+ array: self
912
+ });
913
+ var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self);
914
+ var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
915
+ switch (self.backing._tag) {
916
+ case "IEmpty": {
917
+ throw new Error(`Index out of bounds`);
918
+ }
919
+ case "ISingleton": {
920
+ if (index !== 0) {
921
+ throw new Error(`Index out of bounds`);
922
+ }
923
+ return self.backing.a;
924
+ }
925
+ case "IArray": {
926
+ if (index >= self.length || index < 0) {
927
+ throw new Error(`Index out of bounds`);
928
+ }
929
+ return self.backing.array[index];
930
+ }
931
+ case "IConcat": {
932
+ return index < self.left.length ? unsafeGet(self.left, index) : unsafeGet(self.right, index - self.left.length);
933
+ }
934
+ case "ISlice": {
935
+ return unsafeGet(self.backing.chunk, index + self.backing.offset);
936
+ }
937
+ }
938
+ });
939
+ var prepend = /* @__PURE__ */ dual(2, (self, elem) => appendAll(of(elem), self));
940
+ var appendAll = /* @__PURE__ */ dual(2, (self, that) => {
941
+ if (self.backing._tag === "IEmpty") {
942
+ return that;
943
+ }
944
+ if (that.backing._tag === "IEmpty") {
945
+ return self;
946
+ }
947
+ const diff = that.depth - self.depth;
948
+ if (Math.abs(diff) <= 1) {
949
+ return makeChunk({
950
+ _tag: "IConcat",
951
+ left: self,
952
+ right: that
953
+ });
954
+ } else if (diff < -1) {
955
+ if (self.left.depth >= self.right.depth) {
956
+ const nr = appendAll(self.right, that);
957
+ return makeChunk({
958
+ _tag: "IConcat",
959
+ left: self.left,
960
+ right: nr
961
+ });
962
+ } else {
963
+ const nrr = appendAll(self.right.right, that);
964
+ if (nrr.depth === self.depth - 3) {
965
+ const nr = makeChunk({
966
+ _tag: "IConcat",
967
+ left: self.right.left,
968
+ right: nrr
969
+ });
970
+ return makeChunk({
971
+ _tag: "IConcat",
972
+ left: self.left,
973
+ right: nr
974
+ });
975
+ } else {
976
+ const nl = makeChunk({
977
+ _tag: "IConcat",
978
+ left: self.left,
979
+ right: self.right.left
980
+ });
981
+ return makeChunk({
982
+ _tag: "IConcat",
983
+ left: nl,
984
+ right: nrr
985
+ });
986
+ }
987
+ }
988
+ } else {
989
+ if (that.right.depth >= that.left.depth) {
990
+ const nl = appendAll(self, that.left);
991
+ return makeChunk({
992
+ _tag: "IConcat",
993
+ left: nl,
994
+ right: that.right
995
+ });
996
+ } else {
997
+ const nll = appendAll(self, that.left.left);
998
+ if (nll.depth === that.depth - 3) {
999
+ const nl = makeChunk({
1000
+ _tag: "IConcat",
1001
+ left: nll,
1002
+ right: that.left.right
1003
+ });
1004
+ return makeChunk({
1005
+ _tag: "IConcat",
1006
+ left: nl,
1007
+ right: that.right
1008
+ });
1009
+ } else {
1010
+ const nr = makeChunk({
1011
+ _tag: "IConcat",
1012
+ left: that.left.right,
1013
+ right: that.right
1014
+ });
1015
+ return makeChunk({
1016
+ _tag: "IConcat",
1017
+ left: nll,
1018
+ right: nr
1019
+ });
1020
+ }
1021
+ }
1022
+ }
1023
+ });
1024
+ var isEmpty = (self) => self.length === 0;
1025
+ var isNonEmpty = (self) => self.length > 0;
1026
+ var unsafeHead = (self) => unsafeGet(self, 0);
1027
+ var headNonEmpty = unsafeHead;
1028
+
1029
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/context.js
1030
+ var TagTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Tag");
1031
+ var ReferenceTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Reference");
1032
+ var STMSymbolKey = "effect/STM";
1033
+ var STMTypeId = /* @__PURE__ */ Symbol.for(STMSymbolKey);
1034
+ var TagProto = {
1035
+ ...EffectPrototype,
1036
+ _op: "Tag",
1037
+ [STMTypeId]: effectVariance,
1038
+ [TagTypeId]: {
1039
+ _Service: (_) => _,
1040
+ _Identifier: (_) => _
1041
+ },
1042
+ toString() {
1043
+ return format(this.toJSON());
1044
+ },
1045
+ toJSON() {
1046
+ return {
1047
+ _id: "Tag",
1048
+ key: this.key,
1049
+ stack: this.stack
1050
+ };
1051
+ },
1052
+ [NodeInspectSymbol]() {
1053
+ return this.toJSON();
1054
+ },
1055
+ of(self) {
1056
+ return self;
1057
+ },
1058
+ context(self) {
1059
+ return make3(this, self);
1060
+ }
1061
+ };
1062
+ var ReferenceProto = {
1063
+ ...TagProto,
1064
+ [ReferenceTypeId]: ReferenceTypeId
1065
+ };
1066
+ var Tag = (id) => () => {
1067
+ const limit = Error.stackTraceLimit;
1068
+ Error.stackTraceLimit = 2;
1069
+ const creationError = new Error();
1070
+ Error.stackTraceLimit = limit;
1071
+ function TagClass() {
1072
+ }
1073
+ Object.setPrototypeOf(TagClass, TagProto);
1074
+ TagClass.key = id;
1075
+ Object.defineProperty(TagClass, "stack", {
1076
+ get() {
1077
+ return creationError.stack;
1078
+ }
1079
+ });
1080
+ return TagClass;
1081
+ };
1082
+ var Reference = () => (id, options) => {
1083
+ const limit = Error.stackTraceLimit;
1084
+ Error.stackTraceLimit = 2;
1085
+ const creationError = new Error();
1086
+ Error.stackTraceLimit = limit;
1087
+ function ReferenceClass() {
1088
+ }
1089
+ Object.setPrototypeOf(ReferenceClass, ReferenceProto);
1090
+ ReferenceClass.key = id;
1091
+ ReferenceClass.defaultValue = options.defaultValue;
1092
+ Object.defineProperty(ReferenceClass, "stack", {
1093
+ get() {
1094
+ return creationError.stack;
1095
+ }
1096
+ });
1097
+ return ReferenceClass;
1098
+ };
1099
+ var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Context");
1100
+ var ContextProto = {
1101
+ [TypeId4]: {
1102
+ _Services: (_) => _
1103
+ },
1104
+ [symbol2](that) {
1105
+ if (isContext(that)) {
1106
+ if (this.unsafeMap.size === that.unsafeMap.size) {
1107
+ for (const k of this.unsafeMap.keys()) {
1108
+ if (!that.unsafeMap.has(k) || !equals(this.unsafeMap.get(k), that.unsafeMap.get(k))) {
1109
+ return false;
1110
+ }
1111
+ }
1112
+ return true;
1113
+ }
1114
+ }
1115
+ return false;
1116
+ },
1117
+ [symbol]() {
1118
+ return cached(this, number(this.unsafeMap.size));
1119
+ },
1120
+ pipe() {
1121
+ return pipeArguments(this, arguments);
1122
+ },
1123
+ toString() {
1124
+ return format(this.toJSON());
1125
+ },
1126
+ toJSON() {
1127
+ return {
1128
+ _id: "Context",
1129
+ services: Array.from(this.unsafeMap).map(toJSON)
1130
+ };
1131
+ },
1132
+ [NodeInspectSymbol]() {
1133
+ return this.toJSON();
1134
+ }
1135
+ };
1136
+ var makeContext = (unsafeMap) => {
1137
+ const context = Object.create(ContextProto);
1138
+ context.unsafeMap = unsafeMap;
1139
+ return context;
1140
+ };
1141
+ var serviceNotFoundError = (tag) => {
1142
+ const error = new Error(`Service not found${tag.key ? `: ${String(tag.key)}` : ""}`);
1143
+ if (tag.stack) {
1144
+ const lines = tag.stack.split("\n");
1145
+ if (lines.length > 2) {
1146
+ const afterAt = lines[2].match(/at (.*)/);
1147
+ if (afterAt) {
1148
+ error.message = error.message + ` (defined at ${afterAt[1]})`;
1149
+ }
1150
+ }
1151
+ }
1152
+ if (error.stack) {
1153
+ const lines = error.stack.split("\n");
1154
+ lines.splice(1, 3);
1155
+ error.stack = lines.join("\n");
1156
+ }
1157
+ return error;
1158
+ };
1159
+ var isContext = (u) => hasProperty(u, TypeId4);
1160
+ var make3 = (tag, service2) => makeContext(/* @__PURE__ */ new Map([[tag.key, service2]]));
1161
+ var add = /* @__PURE__ */ dual(3, (self, tag, service2) => {
1162
+ const map7 = new Map(self.unsafeMap);
1163
+ map7.set(tag.key, service2);
1164
+ return makeContext(map7);
1165
+ });
1166
+ var defaultValueCache = /* @__PURE__ */ globalValue("effect/Context/defaultValueCache", () => /* @__PURE__ */ new Map());
1167
+ var getDefaultValue = (tag) => {
1168
+ if (defaultValueCache.has(tag.key)) {
1169
+ return defaultValueCache.get(tag.key);
1170
+ }
1171
+ const value = tag.defaultValue();
1172
+ defaultValueCache.set(tag.key, value);
1173
+ return value;
1174
+ };
1175
+ var unsafeGetReference = (self, tag) => {
1176
+ return self.unsafeMap.has(tag.key) ? self.unsafeMap.get(tag.key) : getDefaultValue(tag);
1177
+ };
1178
+ var unsafeGet2 = /* @__PURE__ */ dual(2, (self, tag) => {
1179
+ if (!self.unsafeMap.has(tag.key)) {
1180
+ if (ReferenceTypeId in tag) return getDefaultValue(tag);
1181
+ throw serviceNotFoundError(tag);
1182
+ }
1183
+ return self.unsafeMap.get(tag.key);
1184
+ });
1185
+ var merge = /* @__PURE__ */ dual(2, (self, that) => {
1186
+ const map7 = new Map(self.unsafeMap);
1187
+ for (const [tag, s] of that.unsafeMap) {
1188
+ map7.set(tag, s);
1189
+ }
1190
+ return makeContext(map7);
1191
+ });
1192
+
1193
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Context.js
1194
+ var make4 = make3;
1195
+ var add2 = add;
1196
+ var unsafeGet3 = unsafeGet2;
1197
+ var merge2 = merge;
1198
+ var Tag2 = Tag;
1199
+ var Reference2 = Reference;
1200
+
1201
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/hashMap/config.js
1202
+ var SIZE = 5;
1203
+ var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE);
1204
+ var MASK = BUCKET_SIZE - 1;
1205
+ var MAX_INDEX_NODE = BUCKET_SIZE / 2;
1206
+ var MIN_ARRAY_NODE = BUCKET_SIZE / 4;
1207
+
1208
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/hashMap/bitwise.js
1209
+ function popcount(x) {
1210
+ x -= x >> 1 & 1431655765;
1211
+ x = (x & 858993459) + (x >> 2 & 858993459);
1212
+ x = x + (x >> 4) & 252645135;
1213
+ x += x >> 8;
1214
+ x += x >> 16;
1215
+ return x & 127;
1216
+ }
1217
+ function hashFragment(shift, h) {
1218
+ return h >>> shift & MASK;
1219
+ }
1220
+ function toBitmap(x) {
1221
+ return 1 << x;
1222
+ }
1223
+ function fromBitmap(bitmap, bit) {
1224
+ return popcount(bitmap & bit - 1);
1225
+ }
1226
+
1227
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/stack.js
1228
+ var make5 = (value, previous) => ({
1229
+ value,
1230
+ previous
1231
+ });
1232
+
1233
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/hashMap/array.js
1234
+ function arrayUpdate(mutate2, at, v, arr) {
1235
+ let out = arr;
1236
+ if (!mutate2) {
1237
+ const len = arr.length;
1238
+ out = new Array(len);
1239
+ for (let i = 0; i < len; ++i) out[i] = arr[i];
1240
+ }
1241
+ out[at] = v;
1242
+ return out;
1243
+ }
1244
+ function arraySpliceOut(mutate2, at, arr) {
1245
+ const newLen = arr.length - 1;
1246
+ let i = 0;
1247
+ let g = 0;
1248
+ let out = arr;
1249
+ if (mutate2) {
1250
+ i = g = at;
1251
+ } else {
1252
+ out = new Array(newLen);
1253
+ while (i < at) out[g++] = arr[i++];
1254
+ }
1255
+ ;
1256
+ ++i;
1257
+ while (i <= newLen) out[g++] = arr[i++];
1258
+ if (mutate2) {
1259
+ out.length = newLen;
1260
+ }
1261
+ return out;
1262
+ }
1263
+ function arraySpliceIn(mutate2, at, v, arr) {
1264
+ const len = arr.length;
1265
+ if (mutate2) {
1266
+ let i2 = len;
1267
+ while (i2 >= at) arr[i2--] = arr[i2];
1268
+ arr[at] = v;
1269
+ return arr;
1270
+ }
1271
+ let i = 0, g = 0;
1272
+ const out = new Array(len + 1);
1273
+ while (i < at) out[g++] = arr[i++];
1274
+ out[at] = v;
1275
+ while (i < len) out[++g] = arr[i++];
1276
+ return out;
1277
+ }
1278
+
1279
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/hashMap/node.js
1280
+ var EmptyNode = class _EmptyNode {
1281
+ _tag = "EmptyNode";
1282
+ modify(edit, _shift, f, hash2, key, size4) {
1283
+ const v = f(none2());
1284
+ if (isNone2(v)) return new _EmptyNode();
1285
+ ++size4.value;
1286
+ return new LeafNode(edit, hash2, key, v);
1287
+ }
1288
+ };
1289
+ function isEmptyNode(a) {
1290
+ return isTagged(a, "EmptyNode");
1291
+ }
1292
+ function isLeafNode(node) {
1293
+ return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode";
1294
+ }
1295
+ function canEditNode(node, edit) {
1296
+ return isEmptyNode(node) ? false : edit === node.edit;
1297
+ }
1298
+ var LeafNode = class _LeafNode {
1299
+ edit;
1300
+ hash;
1301
+ key;
1302
+ value;
1303
+ _tag = "LeafNode";
1304
+ constructor(edit, hash2, key, value) {
1305
+ this.edit = edit;
1306
+ this.hash = hash2;
1307
+ this.key = key;
1308
+ this.value = value;
1309
+ }
1310
+ modify(edit, shift, f, hash2, key, size4) {
1311
+ if (equals(key, this.key)) {
1312
+ const v2 = f(this.value);
1313
+ if (v2 === this.value) return this;
1314
+ else if (isNone2(v2)) {
1315
+ ;
1316
+ --size4.value;
1317
+ return new EmptyNode();
1318
+ }
1319
+ if (canEditNode(this, edit)) {
1320
+ this.value = v2;
1321
+ return this;
1322
+ }
1323
+ return new _LeafNode(edit, hash2, key, v2);
1324
+ }
1325
+ const v = f(none2());
1326
+ if (isNone2(v)) return this;
1327
+ ++size4.value;
1328
+ return mergeLeaves(edit, shift, this.hash, this, hash2, new _LeafNode(edit, hash2, key, v));
1329
+ }
1330
+ };
1331
+ var CollisionNode = class _CollisionNode {
1332
+ edit;
1333
+ hash;
1334
+ children;
1335
+ _tag = "CollisionNode";
1336
+ constructor(edit, hash2, children) {
1337
+ this.edit = edit;
1338
+ this.hash = hash2;
1339
+ this.children = children;
1340
+ }
1341
+ modify(edit, shift, f, hash2, key, size4) {
1342
+ if (hash2 === this.hash) {
1343
+ const canEdit = canEditNode(this, edit);
1344
+ const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size4);
1345
+ if (list === this.children) return this;
1346
+ return list.length > 1 ? new _CollisionNode(edit, this.hash, list) : list[0];
1347
+ }
1348
+ const v = f(none2());
1349
+ if (isNone2(v)) return this;
1350
+ ++size4.value;
1351
+ return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v));
1352
+ }
1353
+ updateCollisionList(mutate2, edit, hash2, list, f, key, size4) {
1354
+ const len = list.length;
1355
+ for (let i = 0; i < len; ++i) {
1356
+ const child = list[i];
1357
+ if ("key" in child && equals(key, child.key)) {
1358
+ const value = child.value;
1359
+ const newValue2 = f(value);
1360
+ if (newValue2 === value) return list;
1361
+ if (isNone2(newValue2)) {
1362
+ ;
1363
+ --size4.value;
1364
+ return arraySpliceOut(mutate2, i, list);
1365
+ }
1366
+ return arrayUpdate(mutate2, i, new LeafNode(edit, hash2, key, newValue2), list);
1367
+ }
1368
+ }
1369
+ const newValue = f(none2());
1370
+ if (isNone2(newValue)) return list;
1371
+ ++size4.value;
1372
+ return arrayUpdate(mutate2, len, new LeafNode(edit, hash2, key, newValue), list);
1373
+ }
1374
+ };
1375
+ var IndexedNode = class _IndexedNode {
1376
+ edit;
1377
+ mask;
1378
+ children;
1379
+ _tag = "IndexedNode";
1380
+ constructor(edit, mask, children) {
1381
+ this.edit = edit;
1382
+ this.mask = mask;
1383
+ this.children = children;
1384
+ }
1385
+ modify(edit, shift, f, hash2, key, size4) {
1386
+ const mask = this.mask;
1387
+ const children = this.children;
1388
+ const frag = hashFragment(shift, hash2);
1389
+ const bit = toBitmap(frag);
1390
+ const indx = fromBitmap(mask, bit);
1391
+ const exists = mask & bit;
1392
+ const canEdit = canEditNode(this, edit);
1393
+ if (!exists) {
1394
+ const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size4);
1395
+ if (!_newChild) return this;
1396
+ return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new _IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children));
1397
+ }
1398
+ const current = children[indx];
1399
+ const child = current.modify(edit, shift + SIZE, f, hash2, key, size4);
1400
+ if (current === child) return this;
1401
+ let bitmap = mask;
1402
+ let newChildren;
1403
+ if (isEmptyNode(child)) {
1404
+ bitmap &= ~bit;
1405
+ if (!bitmap) return new EmptyNode();
1406
+ if (children.length <= 2 && isLeafNode(children[indx ^ 1])) {
1407
+ return children[indx ^ 1];
1408
+ }
1409
+ newChildren = arraySpliceOut(canEdit, indx, children);
1410
+ } else {
1411
+ newChildren = arrayUpdate(canEdit, indx, child, children);
1412
+ }
1413
+ if (canEdit) {
1414
+ this.mask = bitmap;
1415
+ this.children = newChildren;
1416
+ return this;
1417
+ }
1418
+ return new _IndexedNode(edit, bitmap, newChildren);
1419
+ }
1420
+ };
1421
+ var ArrayNode = class _ArrayNode {
1422
+ edit;
1423
+ size;
1424
+ children;
1425
+ _tag = "ArrayNode";
1426
+ constructor(edit, size4, children) {
1427
+ this.edit = edit;
1428
+ this.size = size4;
1429
+ this.children = children;
1430
+ }
1431
+ modify(edit, shift, f, hash2, key, size4) {
1432
+ let count = this.size;
1433
+ const children = this.children;
1434
+ const frag = hashFragment(shift, hash2);
1435
+ const child = children[frag];
1436
+ const newChild = (child || new EmptyNode()).modify(edit, shift + SIZE, f, hash2, key, size4);
1437
+ if (child === newChild) return this;
1438
+ const canEdit = canEditNode(this, edit);
1439
+ let newChildren;
1440
+ if (isEmptyNode(child) && !isEmptyNode(newChild)) {
1441
+ ;
1442
+ ++count;
1443
+ newChildren = arrayUpdate(canEdit, frag, newChild, children);
1444
+ } else if (!isEmptyNode(child) && isEmptyNode(newChild)) {
1445
+ ;
1446
+ --count;
1447
+ if (count <= MIN_ARRAY_NODE) {
1448
+ return pack(edit, count, frag, children);
1449
+ }
1450
+ newChildren = arrayUpdate(canEdit, frag, new EmptyNode(), children);
1451
+ } else {
1452
+ newChildren = arrayUpdate(canEdit, frag, newChild, children);
1453
+ }
1454
+ if (canEdit) {
1455
+ this.size = count;
1456
+ this.children = newChildren;
1457
+ return this;
1458
+ }
1459
+ return new _ArrayNode(edit, count, newChildren);
1460
+ }
1461
+ };
1462
+ function pack(edit, count, removed, elements) {
1463
+ const children = new Array(count - 1);
1464
+ let g = 0;
1465
+ let bitmap = 0;
1466
+ for (let i = 0, len = elements.length; i < len; ++i) {
1467
+ if (i !== removed) {
1468
+ const elem = elements[i];
1469
+ if (elem && !isEmptyNode(elem)) {
1470
+ children[g++] = elem;
1471
+ bitmap |= 1 << i;
1472
+ }
1473
+ }
1474
+ }
1475
+ return new IndexedNode(edit, bitmap, children);
1476
+ }
1477
+ function expand(edit, frag, child, bitmap, subNodes) {
1478
+ const arr = [];
1479
+ let bit = bitmap;
1480
+ let count = 0;
1481
+ for (let i = 0; bit; ++i) {
1482
+ if (bit & 1) arr[i] = subNodes[count++];
1483
+ bit >>>= 1;
1484
+ }
1485
+ arr[frag] = child;
1486
+ return new ArrayNode(edit, count + 1, arr);
1487
+ }
1488
+ function mergeLeavesInner(edit, shift, h1, n1, h2, n2) {
1489
+ if (h1 === h2) return new CollisionNode(edit, h1, [n2, n1]);
1490
+ const subH1 = hashFragment(shift, h1);
1491
+ const subH2 = hashFragment(shift, h2);
1492
+ if (subH1 === subH2) {
1493
+ return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]);
1494
+ } else {
1495
+ const children = subH1 < subH2 ? [n1, n2] : [n2, n1];
1496
+ return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children);
1497
+ }
1498
+ }
1499
+ function mergeLeaves(edit, shift, h1, n1, h2, n2) {
1500
+ let stack = void 0;
1501
+ let currentShift = shift;
1502
+ while (true) {
1503
+ const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2);
1504
+ if (typeof res === "function") {
1505
+ stack = make5(res, stack);
1506
+ currentShift = currentShift + SIZE;
1507
+ } else {
1508
+ let final = res;
1509
+ while (stack != null) {
1510
+ final = stack.value(final);
1511
+ stack = stack.previous;
1512
+ }
1513
+ return final;
1514
+ }
1515
+ }
1516
+ }
1517
+
1518
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/hashMap.js
1519
+ var HashMapSymbolKey = "effect/HashMap";
1520
+ var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey);
1521
+ var HashMapProto = {
1522
+ [HashMapTypeId]: HashMapTypeId,
1523
+ [Symbol.iterator]() {
1524
+ return new HashMapIterator(this, (k, v) => [k, v]);
1525
+ },
1526
+ [symbol]() {
1527
+ let hash2 = hash(HashMapSymbolKey);
1528
+ for (const item of this) {
1529
+ hash2 ^= pipe(hash(item[0]), combine(hash(item[1])));
1530
+ }
1531
+ return cached(this, hash2);
1532
+ },
1533
+ [symbol2](that) {
1534
+ if (isHashMap(that)) {
1535
+ if (that._size !== this._size) {
1536
+ return false;
1537
+ }
1538
+ for (const item of this) {
1539
+ const elem = pipe(that, getHash(item[0], hash(item[0])));
1540
+ if (isNone2(elem)) {
1541
+ return false;
1542
+ } else {
1543
+ if (!equals(item[1], elem.value)) {
1544
+ return false;
1545
+ }
1546
+ }
1547
+ }
1548
+ return true;
1549
+ }
1550
+ return false;
1551
+ },
1552
+ toString() {
1553
+ return format(this.toJSON());
1554
+ },
1555
+ toJSON() {
1556
+ return {
1557
+ _id: "HashMap",
1558
+ values: Array.from(this).map(toJSON)
1559
+ };
1560
+ },
1561
+ [NodeInspectSymbol]() {
1562
+ return this.toJSON();
1563
+ },
1564
+ pipe() {
1565
+ return pipeArguments(this, arguments);
1566
+ }
1567
+ };
1568
+ var makeImpl = (editable, edit, root, size4) => {
1569
+ const map7 = Object.create(HashMapProto);
1570
+ map7._editable = editable;
1571
+ map7._edit = edit;
1572
+ map7._root = root;
1573
+ map7._size = size4;
1574
+ return map7;
1575
+ };
1576
+ var HashMapIterator = class _HashMapIterator {
1577
+ map;
1578
+ f;
1579
+ v;
1580
+ constructor(map7, f) {
1581
+ this.map = map7;
1582
+ this.f = f;
1583
+ this.v = visitLazy(this.map._root, this.f, void 0);
1584
+ }
1585
+ next() {
1586
+ if (isNone2(this.v)) {
1587
+ return {
1588
+ done: true,
1589
+ value: void 0
1590
+ };
1591
+ }
1592
+ const v0 = this.v.value;
1593
+ this.v = applyCont(v0.cont);
1594
+ return {
1595
+ done: false,
1596
+ value: v0.value
1597
+ };
1598
+ }
1599
+ [Symbol.iterator]() {
1600
+ return new _HashMapIterator(this.map, this.f);
1601
+ }
1602
+ };
1603
+ var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2();
1604
+ var visitLazy = (node, f, cont = void 0) => {
1605
+ switch (node._tag) {
1606
+ case "LeafNode": {
1607
+ if (isSome2(node.value)) {
1608
+ return some2({
1609
+ value: f(node.key, node.value.value),
1610
+ cont
1611
+ });
1612
+ }
1613
+ return applyCont(cont);
1614
+ }
1615
+ case "CollisionNode":
1616
+ case "ArrayNode":
1617
+ case "IndexedNode": {
1618
+ const children = node.children;
1619
+ return visitLazyChildren(children.length, children, 0, f, cont);
1620
+ }
1621
+ default: {
1622
+ return applyCont(cont);
1623
+ }
1624
+ }
1625
+ };
1626
+ var visitLazyChildren = (len, children, i, f, cont) => {
1627
+ while (i < len) {
1628
+ const child = children[i++];
1629
+ if (child && !isEmptyNode(child)) {
1630
+ return visitLazy(child, f, [len, children, i, f, cont]);
1631
+ }
1632
+ }
1633
+ return applyCont(cont);
1634
+ };
1635
+ var _empty2 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode(), 0);
1636
+ var empty3 = () => _empty2;
1637
+ var isHashMap = (u) => hasProperty(u, HashMapTypeId);
1638
+ var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => {
1639
+ let node = self._root;
1640
+ let shift = 0;
1641
+ while (true) {
1642
+ switch (node._tag) {
1643
+ case "LeafNode": {
1644
+ return equals(key, node.key) ? node.value : none2();
1645
+ }
1646
+ case "CollisionNode": {
1647
+ if (hash2 === node.hash) {
1648
+ const children = node.children;
1649
+ for (let i = 0, len = children.length; i < len; ++i) {
1650
+ const child = children[i];
1651
+ if ("key" in child && equals(key, child.key)) {
1652
+ return child.value;
1653
+ }
1654
+ }
1655
+ }
1656
+ return none2();
1657
+ }
1658
+ case "IndexedNode": {
1659
+ const frag = hashFragment(shift, hash2);
1660
+ const bit = toBitmap(frag);
1661
+ if (node.mask & bit) {
1662
+ node = node.children[fromBitmap(node.mask, bit)];
1663
+ shift += SIZE;
1664
+ break;
1665
+ }
1666
+ return none2();
1667
+ }
1668
+ case "ArrayNode": {
1669
+ node = node.children[hashFragment(shift, hash2)];
1670
+ if (node) {
1671
+ shift += SIZE;
1672
+ break;
1673
+ }
1674
+ return none2();
1675
+ }
1676
+ default:
1677
+ return none2();
1678
+ }
1679
+ }
1680
+ });
1681
+ var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value)));
1682
+ var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => {
1683
+ if (self._editable) {
1684
+ ;
1685
+ self._root = newRoot;
1686
+ self._size = newSize;
1687
+ return self;
1688
+ }
1689
+ return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize);
1690
+ });
1691
+ var keys = (self) => new HashMapIterator(self, (key) => key);
1692
+ var size = (self) => self._size;
1693
+ var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size);
1694
+ var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f));
1695
+ var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => {
1696
+ const size4 = {
1697
+ value: self._size
1698
+ };
1699
+ const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size4);
1700
+ return pipe(self, setTree(newRoot, size4.value));
1701
+ });
1702
+ var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, void 0, (_, value, key) => f(value, key)));
1703
+ var reduce2 = /* @__PURE__ */ dual(3, (self, zero, f) => {
1704
+ const root = self._root;
1705
+ if (root._tag === "LeafNode") {
1706
+ return isSome2(root.value) ? f(zero, root.value.value, root.key) : zero;
1707
+ }
1708
+ if (root._tag === "EmptyNode") {
1709
+ return zero;
1710
+ }
1711
+ const toVisit = [root.children];
1712
+ let children;
1713
+ while (children = toVisit.pop()) {
1714
+ for (let i = 0, len = children.length; i < len; ) {
1715
+ const child = children[i++];
1716
+ if (child && !isEmptyNode(child)) {
1717
+ if (child._tag === "LeafNode") {
1718
+ if (isSome2(child.value)) {
1719
+ zero = f(zero, child.value.value, child.key);
1720
+ }
1721
+ } else {
1722
+ toVisit.push(child.children);
1723
+ }
1724
+ }
1725
+ }
1726
+ }
1727
+ return zero;
1728
+ });
1729
+
1730
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/hashSet.js
1731
+ var HashSetSymbolKey = "effect/HashSet";
1732
+ var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey);
1733
+ var HashSetProto = {
1734
+ [HashSetTypeId]: HashSetTypeId,
1735
+ [Symbol.iterator]() {
1736
+ return keys(this._keyMap);
1737
+ },
1738
+ [symbol]() {
1739
+ return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey)));
1740
+ },
1741
+ [symbol2](that) {
1742
+ if (isHashSet(that)) {
1743
+ return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap);
1744
+ }
1745
+ return false;
1746
+ },
1747
+ toString() {
1748
+ return format(this.toJSON());
1749
+ },
1750
+ toJSON() {
1751
+ return {
1752
+ _id: "HashSet",
1753
+ values: Array.from(this).map(toJSON)
1754
+ };
1755
+ },
1756
+ [NodeInspectSymbol]() {
1757
+ return this.toJSON();
1758
+ },
1759
+ pipe() {
1760
+ return pipeArguments(this, arguments);
1761
+ }
1762
+ };
1763
+ var makeImpl2 = (keyMap) => {
1764
+ const set2 = Object.create(HashSetProto);
1765
+ set2._keyMap = keyMap;
1766
+ return set2;
1767
+ };
1768
+ var isHashSet = (u) => hasProperty(u, HashSetTypeId);
1769
+ var _empty3 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty3());
1770
+ var empty4 = () => _empty3;
1771
+ var size2 = (self) => size(self._keyMap);
1772
+ var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap));
1773
+ var endMutation = (self) => {
1774
+ ;
1775
+ self._keyMap._editable = false;
1776
+ return self;
1777
+ };
1778
+ var mutate = /* @__PURE__ */ dual(2, (self, f) => {
1779
+ const transient = beginMutation2(self);
1780
+ f(transient);
1781
+ return endMutation(transient);
1782
+ });
1783
+ var add3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap)));
1784
+ var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate(empty4(), (set2) => {
1785
+ forEach2(self, (value) => add3(set2, value));
1786
+ for (const value of that) {
1787
+ add3(set2, value);
1788
+ }
1789
+ }));
1790
+ var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k)));
1791
+
1792
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/HashSet.js
1793
+ var empty5 = empty4;
1794
+ var size3 = size2;
1795
+ var add4 = add3;
1796
+ var union3 = union2;
1797
+
1798
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/data.js
1799
+ var ArrayProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(Array.prototype), {
1800
+ [symbol]() {
1801
+ return cached(this, array(this));
1802
+ },
1803
+ [symbol2](that) {
1804
+ if (Array.isArray(that) && this.length === that.length) {
1805
+ return this.every((v, i) => equals(v, that[i]));
1806
+ } else {
1807
+ return false;
1808
+ }
1809
+ }
1810
+ });
1811
+ var Structural = /* @__PURE__ */ function() {
1812
+ function Structural2(args2) {
1813
+ if (args2) {
1814
+ Object.assign(this, args2);
1815
+ }
1816
+ }
1817
+ Structural2.prototype = StructuralPrototype;
1818
+ return Structural2;
1819
+ }();
1820
+
1821
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/opCodes/cause.js
1822
+ var OP_DIE = "Die";
1823
+ var OP_EMPTY = "Empty";
1824
+ var OP_FAIL = "Fail";
1825
+ var OP_INTERRUPT = "Interrupt";
1826
+ var OP_PARALLEL = "Parallel";
1827
+ var OP_SEQUENTIAL = "Sequential";
1828
+
1829
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/cause.js
1830
+ var CauseSymbolKey = "effect/Cause";
1831
+ var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey);
1832
+ var variance = {
1833
+ /* c8 ignore next */
1834
+ _E: (_) => _
1835
+ };
1836
+ var proto = {
1837
+ [CauseTypeId]: variance,
1838
+ [symbol]() {
1839
+ return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this));
1840
+ },
1841
+ [symbol2](that) {
1842
+ return isCause(that) && causeEquals(this, that);
1843
+ },
1844
+ pipe() {
1845
+ return pipeArguments(this, arguments);
1846
+ },
1847
+ toJSON() {
1848
+ switch (this._tag) {
1849
+ case "Empty":
1850
+ return {
1851
+ _id: "Cause",
1852
+ _tag: this._tag
1853
+ };
1854
+ case "Die":
1855
+ return {
1856
+ _id: "Cause",
1857
+ _tag: this._tag,
1858
+ defect: toJSON(this.defect)
1859
+ };
1860
+ case "Interrupt":
1861
+ return {
1862
+ _id: "Cause",
1863
+ _tag: this._tag,
1864
+ fiberId: this.fiberId.toJSON()
1865
+ };
1866
+ case "Fail":
1867
+ return {
1868
+ _id: "Cause",
1869
+ _tag: this._tag,
1870
+ failure: toJSON(this.error)
1871
+ };
1872
+ case "Sequential":
1873
+ case "Parallel":
1874
+ return {
1875
+ _id: "Cause",
1876
+ _tag: this._tag,
1877
+ left: toJSON(this.left),
1878
+ right: toJSON(this.right)
1879
+ };
1880
+ }
1881
+ },
1882
+ toString() {
1883
+ return pretty(this);
1884
+ },
1885
+ [NodeInspectSymbol]() {
1886
+ return this.toJSON();
1887
+ }
1888
+ };
1889
+ var fail = (error) => {
1890
+ const o = Object.create(proto);
1891
+ o._tag = OP_FAIL;
1892
+ o.error = error;
1893
+ return o;
1894
+ };
1895
+ var parallel = (left3, right3) => {
1896
+ const o = Object.create(proto);
1897
+ o._tag = OP_PARALLEL;
1898
+ o.left = left3;
1899
+ o.right = right3;
1900
+ return o;
1901
+ };
1902
+ var sequential = (left3, right3) => {
1903
+ const o = Object.create(proto);
1904
+ o._tag = OP_SEQUENTIAL;
1905
+ o.left = left3;
1906
+ o.right = right3;
1907
+ return o;
1908
+ };
1909
+ var isCause = (u) => hasProperty(u, CauseTypeId);
1910
+ var isInterruptedOnly = (self) => reduceWithContext(void 0, IsInterruptedOnlyCauseReducer)(self);
1911
+ var causeEquals = (left3, right3) => {
1912
+ let leftStack = of(left3);
1913
+ let rightStack = of(right3);
1914
+ while (isNonEmpty(leftStack) && isNonEmpty(rightStack)) {
1915
+ const [leftParallel, leftSequential] = pipe(headNonEmpty(leftStack), reduce4([empty5(), empty()], ([parallel2, sequential2], cause) => {
1916
+ const [par, seq] = evaluateCause(cause);
1917
+ return some2([pipe(parallel2, union3(par)), pipe(sequential2, appendAll(seq))]);
1918
+ }));
1919
+ const [rightParallel, rightSequential] = pipe(headNonEmpty(rightStack), reduce4([empty5(), empty()], ([parallel2, sequential2], cause) => {
1920
+ const [par, seq] = evaluateCause(cause);
1921
+ return some2([pipe(parallel2, union3(par)), pipe(sequential2, appendAll(seq))]);
1922
+ }));
1923
+ if (!equals(leftParallel, rightParallel)) {
1924
+ return false;
1925
+ }
1926
+ leftStack = leftSequential;
1927
+ rightStack = rightSequential;
1928
+ }
1929
+ return true;
1930
+ };
1931
+ var flattenCause = (cause) => {
1932
+ return flattenCauseLoop(of(cause), empty());
1933
+ };
1934
+ var flattenCauseLoop = (causes, flattened) => {
1935
+ while (1) {
1936
+ const [parallel2, sequential2] = pipe(causes, reduce([empty5(), empty()], ([parallel3, sequential3], cause) => {
1937
+ const [par, seq] = evaluateCause(cause);
1938
+ return [pipe(parallel3, union3(par)), pipe(sequential3, appendAll(seq))];
1939
+ }));
1940
+ const updated = size3(parallel2) > 0 ? pipe(flattened, prepend(parallel2)) : flattened;
1941
+ if (isEmpty(sequential2)) {
1942
+ return reverse2(updated);
1943
+ }
1944
+ causes = sequential2;
1945
+ flattened = updated;
1946
+ }
1947
+ throw new Error(getBugErrorMessage("Cause.flattenCauseLoop"));
1948
+ };
1949
+ var evaluateCause = (self) => {
1950
+ let cause = self;
1951
+ const stack = [];
1952
+ let _parallel = empty5();
1953
+ let _sequential = empty();
1954
+ while (cause !== void 0) {
1955
+ switch (cause._tag) {
1956
+ case OP_EMPTY: {
1957
+ if (stack.length === 0) {
1958
+ return [_parallel, _sequential];
1959
+ }
1960
+ cause = stack.pop();
1961
+ break;
1962
+ }
1963
+ case OP_FAIL: {
1964
+ _parallel = add4(_parallel, make2(cause._tag, cause.error));
1965
+ if (stack.length === 0) {
1966
+ return [_parallel, _sequential];
1967
+ }
1968
+ cause = stack.pop();
1969
+ break;
1970
+ }
1971
+ case OP_DIE: {
1972
+ _parallel = add4(_parallel, make2(cause._tag, cause.defect));
1973
+ if (stack.length === 0) {
1974
+ return [_parallel, _sequential];
1975
+ }
1976
+ cause = stack.pop();
1977
+ break;
1978
+ }
1979
+ case OP_INTERRUPT: {
1980
+ _parallel = add4(_parallel, make2(cause._tag, cause.fiberId));
1981
+ if (stack.length === 0) {
1982
+ return [_parallel, _sequential];
1983
+ }
1984
+ cause = stack.pop();
1985
+ break;
1986
+ }
1987
+ case OP_SEQUENTIAL: {
1988
+ switch (cause.left._tag) {
1989
+ case OP_EMPTY: {
1990
+ cause = cause.right;
1991
+ break;
1992
+ }
1993
+ case OP_SEQUENTIAL: {
1994
+ cause = sequential(cause.left.left, sequential(cause.left.right, cause.right));
1995
+ break;
1996
+ }
1997
+ case OP_PARALLEL: {
1998
+ cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right));
1999
+ break;
2000
+ }
2001
+ default: {
2002
+ _sequential = prepend(_sequential, cause.right);
2003
+ cause = cause.left;
2004
+ break;
2005
+ }
2006
+ }
2007
+ break;
2008
+ }
2009
+ case OP_PARALLEL: {
2010
+ stack.push(cause.right);
2011
+ cause = cause.left;
2012
+ break;
2013
+ }
2014
+ }
2015
+ }
2016
+ throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop"));
2017
+ };
2018
+ var IsInterruptedOnlyCauseReducer = {
2019
+ emptyCase: constTrue,
2020
+ failCase: constFalse,
2021
+ dieCase: constFalse,
2022
+ interruptCase: constTrue,
2023
+ sequentialCase: (_, left3, right3) => left3 && right3,
2024
+ parallelCase: (_, left3, right3) => left3 && right3
2025
+ };
2026
+ var OP_SEQUENTIAL_CASE = "SequentialCase";
2027
+ var OP_PARALLEL_CASE = "ParallelCase";
2028
+ var reduce4 = /* @__PURE__ */ dual(3, (self, zero, pf) => {
2029
+ let accumulator = zero;
2030
+ let cause = self;
2031
+ const causes = [];
2032
+ while (cause !== void 0) {
2033
+ const option = pf(accumulator, cause);
2034
+ accumulator = isSome2(option) ? option.value : accumulator;
2035
+ switch (cause._tag) {
2036
+ case OP_SEQUENTIAL: {
2037
+ causes.push(cause.right);
2038
+ cause = cause.left;
2039
+ break;
2040
+ }
2041
+ case OP_PARALLEL: {
2042
+ causes.push(cause.right);
2043
+ cause = cause.left;
2044
+ break;
2045
+ }
2046
+ default: {
2047
+ cause = void 0;
2048
+ break;
2049
+ }
2050
+ }
2051
+ if (cause === void 0 && causes.length > 0) {
2052
+ cause = causes.pop();
2053
+ }
2054
+ }
2055
+ return accumulator;
2056
+ });
2057
+ var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => {
2058
+ const input = [self];
2059
+ const output = [];
2060
+ while (input.length > 0) {
2061
+ const cause = input.pop();
2062
+ switch (cause._tag) {
2063
+ case OP_EMPTY: {
2064
+ output.push(right2(reducer.emptyCase(context)));
2065
+ break;
2066
+ }
2067
+ case OP_FAIL: {
2068
+ output.push(right2(reducer.failCase(context, cause.error)));
2069
+ break;
2070
+ }
2071
+ case OP_DIE: {
2072
+ output.push(right2(reducer.dieCase(context, cause.defect)));
2073
+ break;
2074
+ }
2075
+ case OP_INTERRUPT: {
2076
+ output.push(right2(reducer.interruptCase(context, cause.fiberId)));
2077
+ break;
2078
+ }
2079
+ case OP_SEQUENTIAL: {
2080
+ input.push(cause.right);
2081
+ input.push(cause.left);
2082
+ output.push(left2({
2083
+ _tag: OP_SEQUENTIAL_CASE
2084
+ }));
2085
+ break;
2086
+ }
2087
+ case OP_PARALLEL: {
2088
+ input.push(cause.right);
2089
+ input.push(cause.left);
2090
+ output.push(left2({
2091
+ _tag: OP_PARALLEL_CASE
2092
+ }));
2093
+ break;
2094
+ }
2095
+ }
2096
+ }
2097
+ const accumulator = [];
2098
+ while (output.length > 0) {
2099
+ const either = output.pop();
2100
+ switch (either._tag) {
2101
+ case "Left": {
2102
+ switch (either.left._tag) {
2103
+ case OP_SEQUENTIAL_CASE: {
2104
+ const left3 = accumulator.pop();
2105
+ const right3 = accumulator.pop();
2106
+ const value = reducer.sequentialCase(context, left3, right3);
2107
+ accumulator.push(value);
2108
+ break;
2109
+ }
2110
+ case OP_PARALLEL_CASE: {
2111
+ const left3 = accumulator.pop();
2112
+ const right3 = accumulator.pop();
2113
+ const value = reducer.parallelCase(context, left3, right3);
2114
+ accumulator.push(value);
2115
+ break;
2116
+ }
2117
+ }
2118
+ break;
2119
+ }
2120
+ case "Right": {
2121
+ accumulator.push(either.right);
2122
+ break;
2123
+ }
2124
+ }
2125
+ }
2126
+ if (accumulator.length === 0) {
2127
+ throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");
2128
+ }
2129
+ return accumulator.pop();
2130
+ });
2131
+ var pretty = (cause, options) => {
2132
+ if (isInterruptedOnly(cause)) {
2133
+ return "All fibers interrupted without errors.";
2134
+ }
2135
+ return prettyErrors(cause).map(function(e) {
2136
+ if (options?.renderErrorCause !== true || e.cause === void 0) {
2137
+ return e.stack;
2138
+ }
2139
+ return `${e.stack} {
2140
+ ${renderErrorCause(e.cause, " ")}
2141
+ }`;
2142
+ }).join("\n");
2143
+ };
2144
+ var renderErrorCause = (cause, prefix) => {
2145
+ const lines = cause.stack.split("\n");
2146
+ let stack = `${prefix}[cause]: ${lines[0]}`;
2147
+ for (let i = 1, len = lines.length; i < len; i++) {
2148
+ stack += `
2149
+ ${prefix}${lines[i]}`;
2150
+ }
2151
+ if (cause.cause) {
2152
+ stack += ` {
2153
+ ${renderErrorCause(cause.cause, `${prefix} `)}
2154
+ ${prefix}}`;
2155
+ }
2156
+ return stack;
2157
+ };
2158
+ var PrettyError = class _PrettyError extends globalThis.Error {
2159
+ span = void 0;
2160
+ constructor(originalError) {
2161
+ const originalErrorIsObject = typeof originalError === "object" && originalError !== null;
2162
+ const prevLimit = Error.stackTraceLimit;
2163
+ Error.stackTraceLimit = 1;
2164
+ super(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? {
2165
+ cause: new _PrettyError(originalError.cause)
2166
+ } : void 0);
2167
+ if (this.message === "") {
2168
+ this.message = "An error has occurred";
2169
+ }
2170
+ Error.stackTraceLimit = prevLimit;
2171
+ this.name = originalError instanceof Error ? originalError.name : "Error";
2172
+ if (originalErrorIsObject) {
2173
+ if (spanSymbol in originalError) {
2174
+ this.span = originalError[spanSymbol];
2175
+ }
2176
+ Object.keys(originalError).forEach((key) => {
2177
+ if (!(key in this)) {
2178
+ this[key] = originalError[key];
2179
+ }
2180
+ });
2181
+ }
2182
+ this.stack = prettyErrorStack(`${this.name}: ${this.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", this.span);
2183
+ }
2184
+ };
2185
+ var prettyErrorMessage = (u) => {
2186
+ if (typeof u === "string") {
2187
+ return u;
2188
+ }
2189
+ if (typeof u === "object" && u !== null && u instanceof Error) {
2190
+ return u.message;
2191
+ }
2192
+ try {
2193
+ if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) {
2194
+ return u["toString"]();
2195
+ }
2196
+ } catch {
2197
+ }
2198
+ return stringifyCircular(u);
2199
+ };
2200
+ var locationRegex = /\((.*)\)/g;
2201
+ var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
2202
+ var prettyErrorStack = (message, stack, span) => {
2203
+ const out = [message];
2204
+ const lines = stack.startsWith(message) ? stack.slice(message.length).split("\n") : stack.split("\n");
2205
+ for (let i = 1; i < lines.length; i++) {
2206
+ if (lines[i].includes("Generator.next")) {
2207
+ break;
2208
+ }
2209
+ if (lines[i].includes("effect_internal_function")) {
2210
+ out.pop();
2211
+ break;
2212
+ }
2213
+ out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>"));
2214
+ }
2215
+ if (span) {
2216
+ let current = span;
2217
+ let i = 0;
2218
+ while (current && current._tag === "Span" && i < 10) {
2219
+ const stackFn = spanToTrace.get(current);
2220
+ if (typeof stackFn === "function") {
2221
+ const stack2 = stackFn();
2222
+ if (typeof stack2 === "string") {
2223
+ const locationMatchAll = stack2.matchAll(locationRegex);
2224
+ let match2 = false;
2225
+ for (const [, location] of locationMatchAll) {
2226
+ match2 = true;
2227
+ out.push(` at ${current.name} (${location})`);
2228
+ }
2229
+ if (!match2) {
2230
+ out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`);
2231
+ }
2232
+ } else {
2233
+ out.push(` at ${current.name}`);
2234
+ }
2235
+ } else {
2236
+ out.push(` at ${current.name}`);
2237
+ }
2238
+ current = getOrUndefined(current.parent);
2239
+ i++;
2240
+ }
2241
+ }
2242
+ return out.join("\n");
2243
+ };
2244
+ var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
2245
+ var prettyErrors = (cause) => reduceWithContext(cause, void 0, {
2246
+ emptyCase: () => [],
2247
+ dieCase: (_, unknownError) => {
2248
+ return [new PrettyError(unknownError)];
2249
+ },
2250
+ failCase: (_, error) => {
2251
+ return [new PrettyError(error)];
2252
+ },
2253
+ interruptCase: () => [],
2254
+ parallelCase: (_, l, r) => [...l, ...r],
2255
+ sequentialCase: (_, l, r) => [...l, ...r]
2256
+ });
2257
+
2258
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/singleShotGen.js
2259
+ var SingleShotGen2 = class _SingleShotGen {
2260
+ self;
2261
+ called = false;
2262
+ constructor(self) {
2263
+ this.self = self;
2264
+ }
2265
+ next(a) {
2266
+ return this.called ? {
2267
+ value: a,
2268
+ done: true
2269
+ } : (this.called = true, {
2270
+ value: this.self,
2271
+ done: false
2272
+ });
2273
+ }
2274
+ return(a) {
2275
+ return {
2276
+ value: a,
2277
+ done: true
2278
+ };
2279
+ }
2280
+ throw(e) {
2281
+ throw e;
2282
+ }
2283
+ [Symbol.iterator]() {
2284
+ return new _SingleShotGen(this.self);
2285
+ }
2286
+ };
2287
+
2288
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/internal/core.js
2289
+ var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect");
2290
+ var EffectPrimitive = class {
2291
+ _op;
2292
+ effect_instruction_i0 = void 0;
2293
+ effect_instruction_i1 = void 0;
2294
+ effect_instruction_i2 = void 0;
2295
+ trace = void 0;
2296
+ [EffectTypeId2] = effectVariance;
2297
+ constructor(_op) {
2298
+ this._op = _op;
2299
+ }
2300
+ [symbol2](that) {
2301
+ return this === that;
2302
+ }
2303
+ [symbol]() {
2304
+ return cached(this, random(this));
2305
+ }
2306
+ pipe() {
2307
+ return pipeArguments(this, arguments);
2308
+ }
2309
+ toJSON() {
2310
+ return {
2311
+ _id: "Effect",
2312
+ _op: this._op,
2313
+ effect_instruction_i0: toJSON(this.effect_instruction_i0),
2314
+ effect_instruction_i1: toJSON(this.effect_instruction_i1),
2315
+ effect_instruction_i2: toJSON(this.effect_instruction_i2)
2316
+ };
2317
+ }
2318
+ toString() {
2319
+ return format(this.toJSON());
2320
+ }
2321
+ [NodeInspectSymbol]() {
2322
+ return this.toJSON();
2323
+ }
2324
+ [Symbol.iterator]() {
2325
+ return new SingleShotGen2(new YieldWrap(this));
2326
+ }
2327
+ };
2328
+ var EffectPrimitiveFailure = class {
2329
+ _op;
2330
+ effect_instruction_i0 = void 0;
2331
+ effect_instruction_i1 = void 0;
2332
+ effect_instruction_i2 = void 0;
2333
+ trace = void 0;
2334
+ [EffectTypeId2] = effectVariance;
2335
+ constructor(_op) {
2336
+ this._op = _op;
2337
+ this._tag = _op;
2338
+ }
2339
+ [symbol2](that) {
2340
+ return exitIsExit(that) && that._op === "Failure" && // @ts-expect-error
2341
+ equals(this.effect_instruction_i0, that.effect_instruction_i0);
2342
+ }
2343
+ [symbol]() {
2344
+ return pipe(
2345
+ // @ts-expect-error
2346
+ string(this._tag),
2347
+ // @ts-expect-error
2348
+ combine(hash(this.effect_instruction_i0)),
2349
+ cached(this)
2350
+ );
2351
+ }
2352
+ get cause() {
2353
+ return this.effect_instruction_i0;
2354
+ }
2355
+ pipe() {
2356
+ return pipeArguments(this, arguments);
2357
+ }
2358
+ toJSON() {
2359
+ return {
2360
+ _id: "Exit",
2361
+ _tag: this._op,
2362
+ cause: this.cause.toJSON()
2363
+ };
2364
+ }
2365
+ toString() {
2366
+ return format(this.toJSON());
2367
+ }
2368
+ [NodeInspectSymbol]() {
2369
+ return this.toJSON();
2370
+ }
2371
+ [Symbol.iterator]() {
2372
+ return new SingleShotGen2(new YieldWrap(this));
2373
+ }
2374
+ };
2375
+ var EffectPrimitiveSuccess = class {
2376
+ _op;
2377
+ effect_instruction_i0 = void 0;
2378
+ effect_instruction_i1 = void 0;
2379
+ effect_instruction_i2 = void 0;
2380
+ trace = void 0;
2381
+ [EffectTypeId2] = effectVariance;
2382
+ constructor(_op) {
2383
+ this._op = _op;
2384
+ this._tag = _op;
2385
+ }
2386
+ [symbol2](that) {
2387
+ return exitIsExit(that) && that._op === "Success" && // @ts-expect-error
2388
+ equals(this.effect_instruction_i0, that.effect_instruction_i0);
2389
+ }
2390
+ [symbol]() {
2391
+ return pipe(
2392
+ // @ts-expect-error
2393
+ string(this._tag),
2394
+ // @ts-expect-error
2395
+ combine(hash(this.effect_instruction_i0)),
2396
+ cached(this)
2397
+ );
2398
+ }
2399
+ get value() {
2400
+ return this.effect_instruction_i0;
2401
+ }
2402
+ pipe() {
2403
+ return pipeArguments(this, arguments);
2404
+ }
2405
+ toJSON() {
2406
+ return {
2407
+ _id: "Exit",
2408
+ _tag: this._op,
2409
+ value: toJSON(this.value)
2410
+ };
2411
+ }
2412
+ toString() {
2413
+ return format(this.toJSON());
2414
+ }
2415
+ [NodeInspectSymbol]() {
2416
+ return this.toJSON();
2417
+ }
2418
+ [Symbol.iterator]() {
2419
+ return new SingleShotGen2(new YieldWrap(this));
2420
+ }
2421
+ };
2422
+ var isEffect = (u) => hasProperty(u, EffectTypeId2);
2423
+ var withFiberRuntime = (withRuntime) => {
2424
+ const effect = new EffectPrimitive(OP_WITH_RUNTIME);
2425
+ effect.effect_instruction_i0 = withRuntime;
2426
+ return effect;
2427
+ };
2428
+ var spanSymbol2 = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
2429
+ var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation");
2430
+ var capture = (obj, span) => {
2431
+ if (isSome2(span)) {
2432
+ return new Proxy(obj, {
2433
+ has(target, p) {
2434
+ return p === spanSymbol2 || p === originalSymbol || p in target;
2435
+ },
2436
+ get(target, p) {
2437
+ if (p === spanSymbol2) {
2438
+ return span.value;
2439
+ }
2440
+ if (p === originalSymbol) {
2441
+ return obj;
2442
+ }
2443
+ return target[p];
2444
+ }
2445
+ });
2446
+ }
2447
+ return obj;
2448
+ };
2449
+ var fail2 = (error) => isObject(error) && !(spanSymbol2 in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error));
2450
+ var failCause = (cause) => {
2451
+ const effect = new EffectPrimitiveFailure(OP_FAILURE);
2452
+ effect.effect_instruction_i0 = cause;
2453
+ return effect;
2454
+ };
2455
+ var logLevelAll = {
2456
+ _tag: "All",
2457
+ syslog: 0,
2458
+ label: "ALL",
2459
+ ordinal: Number.MIN_SAFE_INTEGER,
2460
+ pipe() {
2461
+ return pipeArguments(this, arguments);
2462
+ }
2463
+ };
2464
+ var logLevelNone = {
2465
+ _tag: "None",
2466
+ syslog: 7,
2467
+ label: "OFF",
2468
+ ordinal: Number.MAX_SAFE_INTEGER,
2469
+ pipe() {
2470
+ return pipeArguments(this, arguments);
2471
+ }
2472
+ };
2473
+ var RequestResolverSymbolKey = "effect/RequestResolver";
2474
+ var RequestResolverTypeId = /* @__PURE__ */ Symbol.for(RequestResolverSymbolKey);
2475
+ var requestResolverVariance = {
2476
+ /* c8 ignore next */
2477
+ _A: (_) => _,
2478
+ /* c8 ignore next */
2479
+ _R: (_) => _
2480
+ };
2481
+ var RequestResolverImpl = class _RequestResolverImpl {
2482
+ runAll;
2483
+ target;
2484
+ [RequestResolverTypeId] = requestResolverVariance;
2485
+ constructor(runAll, target) {
2486
+ this.runAll = runAll;
2487
+ this.target = target;
2488
+ }
2489
+ [symbol]() {
2490
+ return cached(this, this.target ? hash(this.target) : random(this));
2491
+ }
2492
+ [symbol2](that) {
2493
+ return this.target ? isRequestResolver(that) && equals(this.target, that.target) : this === that;
2494
+ }
2495
+ identified(...ids) {
2496
+ return new _RequestResolverImpl(this.runAll, fromIterable2(ids));
2497
+ }
2498
+ pipe() {
2499
+ return pipeArguments(this, arguments);
2500
+ }
2501
+ };
2502
+ var isRequestResolver = (u) => hasProperty(u, RequestResolverTypeId);
2503
+ var YieldableError = /* @__PURE__ */ function() {
2504
+ class YieldableError2 extends globalThis.Error {
2505
+ commit() {
2506
+ return fail2(this);
2507
+ }
2508
+ toJSON() {
2509
+ return {
2510
+ ...this
2511
+ };
2512
+ }
2513
+ [NodeInspectSymbol]() {
2514
+ if (this.toString !== globalThis.Error.prototype.toString) {
2515
+ return this.stack ? `${this.toString()}
2516
+ ${this.stack.split("\n").slice(1).join("\n")}` : this.toString();
2517
+ } else if ("Bun" in globalThis) {
2518
+ return pretty(fail(this), {
2519
+ renderErrorCause: true
2520
+ });
2521
+ }
2522
+ return this;
2523
+ }
2524
+ }
2525
+ Object.assign(YieldableError2.prototype, StructuralCommitPrototype);
2526
+ return YieldableError2;
2527
+ }();
2528
+ var makeException = (proto2, tag) => {
2529
+ class Base2 extends YieldableError {
2530
+ _tag = tag;
2531
+ }
2532
+ Object.assign(Base2.prototype, proto2);
2533
+ Base2.prototype.name = tag;
2534
+ return Base2;
2535
+ };
2536
+ var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException");
2537
+ var RuntimeException = /* @__PURE__ */ makeException({
2538
+ [RuntimeExceptionTypeId]: RuntimeExceptionTypeId
2539
+ }, "RuntimeException");
2540
+ var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException");
2541
+ var InterruptedException = /* @__PURE__ */ makeException({
2542
+ [InterruptedExceptionTypeId]: InterruptedExceptionTypeId
2543
+ }, "InterruptedException");
2544
+ var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument");
2545
+ var IllegalArgumentException = /* @__PURE__ */ makeException({
2546
+ [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId
2547
+ }, "IllegalArgumentException");
2548
+ var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement");
2549
+ var NoSuchElementException = /* @__PURE__ */ makeException({
2550
+ [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId
2551
+ }, "NoSuchElementException");
2552
+ var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException");
2553
+ var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({
2554
+ [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
2555
+ }, "InvalidPubSubCapacityException");
2556
+ var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException");
2557
+ var ExceededCapacityException = /* @__PURE__ */ makeException({
2558
+ [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
2559
+ }, "ExceededCapacityException");
2560
+ var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout");
2561
+ var TimeoutException = /* @__PURE__ */ makeException({
2562
+ [TimeoutExceptionTypeId]: TimeoutExceptionTypeId
2563
+ }, "TimeoutException");
2564
+ var exitIsExit = (u) => isEffect(u) && "_tag" in u && (u._tag === "Success" || u._tag === "Failure");
2565
+ var currentSpanFromFiber = (fiber) => {
2566
+ const span = fiber.currentSpan;
2567
+ return span !== void 0 && span._tag === "Span" ? some2(span) : none2();
2568
+ };
2569
+
2570
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Data.js
2571
+ var Class2 = Structural;
2572
+ var TaggedClass = (tag) => {
2573
+ class Base2 extends Class2 {
2574
+ _tag = tag;
2575
+ }
2576
+ return Base2;
2577
+ };
2578
+ var Error2 = /* @__PURE__ */ function() {
2579
+ const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs");
2580
+ return class Base extends YieldableError {
2581
+ constructor(args2) {
2582
+ super(args2?.message, args2?.cause ? {
2583
+ cause: args2.cause
2584
+ } : void 0);
2585
+ if (args2) {
2586
+ Object.assign(this, args2);
2587
+ Object.defineProperty(this, plainArgsSymbol, {
2588
+ value: args2,
2589
+ enumerable: false
2590
+ });
2591
+ }
2592
+ }
2593
+ toJSON() {
2594
+ return {
2595
+ ...this[plainArgsSymbol],
2596
+ ...this
2597
+ };
2598
+ }
2599
+ };
2600
+ }();
2601
+ var TaggedError = (tag) => {
2602
+ class Base2 extends Error2 {
2603
+ _tag = tag;
2604
+ }
2605
+ ;
2606
+ Base2.prototype.name = tag;
2607
+ return Base2;
2608
+ };
2609
+
2610
+ // src/internal/bot-response.ts
2611
+ var BotResponse = class _BotResponse extends TaggedClass("BotResponse") {
2612
+ static make(result) {
2613
+ return new _BotResponse({ response: result });
2614
+ }
2615
+ static ignore = new _BotResponse({});
2616
+ };
2617
+
2618
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Effectable.js
2619
+ var EffectPrototype2 = EffectPrototype;
2620
+
2621
+ // ../../node_modules/.pnpm/effect@3.12.0/node_modules/effect/dist/esm/Micro.js
2622
+ var TypeId5 = /* @__PURE__ */ Symbol.for("effect/Micro");
2623
+ var MicroExitTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroExit");
2624
+ var isMicro = (u) => typeof u === "object" && u !== null && TypeId5 in u;
2625
+ var MicroCauseTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroCause");
2626
+ var microCauseVariance = {
2627
+ _E: identity
2628
+ };
2629
+ var MicroCauseImpl = class extends globalThis.Error {
2630
+ _tag;
2631
+ traces;
2632
+ [MicroCauseTypeId];
2633
+ constructor(_tag, originalError, traces) {
2634
+ const causeName = `MicroCause.${_tag}`;
2635
+ let name;
2636
+ let message;
2637
+ let stack;
2638
+ if (originalError instanceof globalThis.Error) {
2639
+ name = `(${causeName}) ${originalError.name}`;
2640
+ message = originalError.message;
2641
+ const messageLines = message.split("\n").length;
2642
+ stack = originalError.stack ? `(${causeName}) ${originalError.stack.split("\n").slice(0, messageLines + 3).join("\n")}` : `${name}: ${message}`;
2643
+ } else {
2644
+ name = causeName;
2645
+ message = toStringUnknown(originalError, 0);
2646
+ stack = `${name}: ${message}`;
2647
+ }
2648
+ if (traces.length > 0) {
2649
+ stack += `
2650
+ ${traces.join("\n ")}`;
2651
+ }
2652
+ super(message);
2653
+ this._tag = _tag;
2654
+ this.traces = traces;
2655
+ this[MicroCauseTypeId] = microCauseVariance;
2656
+ this.name = name;
2657
+ this.stack = stack;
2658
+ }
2659
+ pipe() {
2660
+ return pipeArguments(this, arguments);
2661
+ }
2662
+ toString() {
2663
+ return this.stack;
2664
+ }
2665
+ [NodeInspectSymbol]() {
2666
+ return this.stack;
2667
+ }
2668
+ };
2669
+ var Fail = class extends MicroCauseImpl {
2670
+ error;
2671
+ constructor(error, traces = []) {
2672
+ super("Fail", error, traces);
2673
+ this.error = error;
2674
+ }
2675
+ };
2676
+ var causeFail = (error, traces = []) => new Fail(error, traces);
2677
+ var Die = class extends MicroCauseImpl {
2678
+ defect;
2679
+ constructor(defect, traces = []) {
2680
+ super("Die", defect, traces);
2681
+ this.defect = defect;
2682
+ }
2683
+ };
2684
+ var causeDie = (defect, traces = []) => new Die(defect, traces);
2685
+ var Interrupt = class extends MicroCauseImpl {
2686
+ constructor(traces = []) {
2687
+ super("Interrupt", "interrupted", traces);
2688
+ }
2689
+ };
2690
+ var causeInterrupt = (traces = []) => new Interrupt(traces);
2691
+ var causeIsFail = (self) => self._tag === "Fail";
2692
+ var causeIsInterrupt = (self) => self._tag === "Interrupt";
2693
+ var MicroFiberTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroFiber");
2694
+ var fiberVariance = {
2695
+ _A: identity,
2696
+ _E: identity
2697
+ };
2698
+ var MicroFiberImpl = class {
2699
+ context;
2700
+ interruptible;
2701
+ [MicroFiberTypeId];
2702
+ _stack = [];
2703
+ _observers = [];
2704
+ _exit;
2705
+ _children;
2706
+ currentOpCount = 0;
2707
+ constructor(context, interruptible2 = true) {
2708
+ this.context = context;
2709
+ this.interruptible = interruptible2;
2710
+ this[MicroFiberTypeId] = fiberVariance;
2711
+ }
2712
+ getRef(ref) {
2713
+ return unsafeGetReference(this.context, ref);
2714
+ }
2715
+ addObserver(cb) {
2716
+ if (this._exit) {
2717
+ cb(this._exit);
2718
+ return constVoid;
2719
+ }
2720
+ this._observers.push(cb);
2721
+ return () => {
2722
+ const index = this._observers.indexOf(cb);
2723
+ if (index >= 0) {
2724
+ this._observers.splice(index, 1);
2725
+ }
2726
+ };
2727
+ }
2728
+ _interrupted = false;
2729
+ unsafeInterrupt() {
2730
+ if (this._exit) {
2731
+ return;
2732
+ }
2733
+ this._interrupted = true;
2734
+ if (this.interruptible) {
2735
+ this.evaluate(exitInterrupt);
2736
+ }
2737
+ }
2738
+ unsafePoll() {
2739
+ return this._exit;
2740
+ }
2741
+ evaluate(effect) {
2742
+ if (this._exit) {
2743
+ return;
2744
+ } else if (this._yielded !== void 0) {
2745
+ const yielded = this._yielded;
2746
+ this._yielded = void 0;
2747
+ yielded();
2748
+ }
2749
+ const exit2 = this.runLoop(effect);
2750
+ if (exit2 === Yield) {
2751
+ return;
2752
+ }
2753
+ const interruptChildren = fiberMiddleware.interruptChildren && fiberMiddleware.interruptChildren(this);
2754
+ if (interruptChildren !== void 0) {
2755
+ return this.evaluate(flatMap3(interruptChildren, () => exit2));
2756
+ }
2757
+ this._exit = exit2;
2758
+ for (let i = 0; i < this._observers.length; i++) {
2759
+ this._observers[i](exit2);
2760
+ }
2761
+ this._observers.length = 0;
2762
+ }
2763
+ runLoop(effect) {
2764
+ let yielding = false;
2765
+ let current = effect;
2766
+ this.currentOpCount = 0;
2767
+ try {
2768
+ while (true) {
2769
+ this.currentOpCount++;
2770
+ if (!yielding && this.getRef(CurrentScheduler).shouldYield(this)) {
2771
+ yielding = true;
2772
+ const prev = current;
2773
+ current = flatMap3(yieldNow, () => prev);
2774
+ }
2775
+ current = current[evaluate](this);
2776
+ if (current === Yield) {
2777
+ const yielded = this._yielded;
2778
+ if (MicroExitTypeId in yielded) {
2779
+ this._yielded = void 0;
2780
+ return yielded;
2781
+ }
2782
+ return Yield;
2783
+ }
2784
+ }
2785
+ } catch (error) {
2786
+ if (!hasProperty(current, evaluate)) {
2787
+ return exitDie(`MicroFiber.runLoop: Not a valid effect: ${String(current)}`);
2788
+ }
2789
+ return exitDie(error);
2790
+ }
2791
+ }
2792
+ getCont(symbol3) {
2793
+ while (true) {
2794
+ const op = this._stack.pop();
2795
+ if (!op) return void 0;
2796
+ const cont = op[ensureCont] && op[ensureCont](this);
2797
+ if (cont) return {
2798
+ [symbol3]: cont
2799
+ };
2800
+ if (op[symbol3]) return op;
2801
+ }
2802
+ }
2803
+ // cancel the yielded operation, or for the yielded exit value
2804
+ _yielded = void 0;
2805
+ yieldWith(value) {
2806
+ this._yielded = value;
2807
+ return Yield;
2808
+ }
2809
+ children() {
2810
+ return this._children ??= /* @__PURE__ */ new Set();
2811
+ }
2812
+ };
2813
+ var fiberMiddleware = /* @__PURE__ */ globalValue("effect/Micro/fiberMiddleware", () => ({
2814
+ interruptChildren: void 0
2815
+ }));
2816
+ var fiberAwait = (self) => async((resume) => sync(self.addObserver((exit2) => resume(succeed(exit2)))));
2817
+ var fiberInterrupt = (self) => suspend(() => {
2818
+ self.unsafeInterrupt();
2819
+ return asVoid(fiberAwait(self));
2820
+ });
2821
+ var fiberInterruptAll = (fibers) => suspend(() => {
2822
+ for (const fiber of fibers) fiber.unsafeInterrupt();
2823
+ const iter = fibers[Symbol.iterator]();
2824
+ const wait = suspend(() => {
2825
+ let result = iter.next();
2826
+ while (!result.done) {
2827
+ if (result.value.unsafePoll()) {
2828
+ result = iter.next();
2829
+ continue;
2830
+ }
2831
+ const fiber = result.value;
2832
+ return async((resume) => {
2833
+ fiber.addObserver((_) => {
2834
+ resume(wait);
2835
+ });
2836
+ });
2837
+ }
2838
+ return exitVoid;
2839
+ });
2840
+ return wait;
2841
+ });
2842
+ var identifier = /* @__PURE__ */ Symbol.for("effect/Micro/identifier");
2843
+ var args = /* @__PURE__ */ Symbol.for("effect/Micro/args");
2844
+ var evaluate = /* @__PURE__ */ Symbol.for("effect/Micro/evaluate");
2845
+ var successCont = /* @__PURE__ */ Symbol.for("effect/Micro/successCont");
2846
+ var failureCont = /* @__PURE__ */ Symbol.for("effect/Micro/failureCont");
2847
+ var ensureCont = /* @__PURE__ */ Symbol.for("effect/Micro/ensureCont");
2848
+ var Yield = /* @__PURE__ */ Symbol.for("effect/Micro/Yield");
2849
+ var microVariance = {
2850
+ _A: identity,
2851
+ _E: identity,
2852
+ _R: identity
2853
+ };
2854
+ var MicroProto = {
2855
+ ...EffectPrototype2,
2856
+ _op: "Micro",
2857
+ [TypeId5]: microVariance,
2858
+ pipe() {
2859
+ return pipeArguments(this, arguments);
2860
+ },
2861
+ [Symbol.iterator]() {
2862
+ return new SingleShotGen(new YieldWrap(this));
2863
+ },
2864
+ toJSON() {
2865
+ return {
2866
+ _id: "Micro",
2867
+ op: this[identifier],
2868
+ ...args in this ? {
2869
+ args: this[args]
2870
+ } : void 0
2871
+ };
2872
+ },
2873
+ toString() {
2874
+ return format(this);
2875
+ },
2876
+ [NodeInspectSymbol]() {
2877
+ return format(this);
2878
+ }
2879
+ };
2880
+ function defaultEvaluate(_fiber) {
2881
+ return exitDie(`Micro.evaluate: Not implemented`);
2882
+ }
2883
+ var makePrimitiveProto = (options) => ({
2884
+ ...MicroProto,
2885
+ [identifier]: options.op,
2886
+ [evaluate]: options.eval ?? defaultEvaluate,
2887
+ [successCont]: options.contA,
2888
+ [failureCont]: options.contE,
2889
+ [ensureCont]: options.ensure
2890
+ });
2891
+ var makePrimitive = (options) => {
2892
+ const Proto = makePrimitiveProto(options);
2893
+ return function() {
2894
+ const self = Object.create(Proto);
2895
+ self[args] = options.single === false ? arguments : arguments[0];
2896
+ return self;
2897
+ };
2898
+ };
2899
+ var makeExit = (options) => {
2900
+ const Proto = {
2901
+ ...makePrimitiveProto(options),
2902
+ [MicroExitTypeId]: MicroExitTypeId,
2903
+ _tag: options.op,
2904
+ get [options.prop]() {
2905
+ return this[args];
2906
+ },
2907
+ toJSON() {
2908
+ return {
2909
+ _id: "MicroExit",
2910
+ _tag: options.op,
2911
+ [options.prop]: this[args]
2912
+ };
2913
+ },
2914
+ [symbol2](that) {
2915
+ return isMicroExit(that) && that._tag === options.op && equals(this[args], that[args]);
2916
+ },
2917
+ [symbol]() {
2918
+ return cached(this, combine(string(options.op))(hash(this[args])));
2919
+ }
2920
+ };
2921
+ return function(value) {
2922
+ const self = Object.create(Proto);
2923
+ self[args] = value;
2924
+ self[successCont] = void 0;
2925
+ self[failureCont] = void 0;
2926
+ self[ensureCont] = void 0;
2927
+ return self;
2928
+ };
2929
+ };
2930
+ var succeed = /* @__PURE__ */ makeExit({
2931
+ op: "Success",
2932
+ prop: "value",
2933
+ eval(fiber) {
2934
+ const cont = fiber.getCont(successCont);
2935
+ return cont ? cont[successCont](this[args], fiber) : fiber.yieldWith(this);
2936
+ }
2937
+ });
2938
+ var failCause2 = /* @__PURE__ */ makeExit({
2939
+ op: "Failure",
2940
+ prop: "cause",
2941
+ eval(fiber) {
2942
+ let cont = fiber.getCont(failureCont);
2943
+ while (causeIsInterrupt(this[args]) && cont && fiber.interruptible) {
2944
+ cont = fiber.getCont(failureCont);
2945
+ }
2946
+ return cont ? cont[failureCont](this[args], fiber) : fiber.yieldWith(this);
2947
+ }
2948
+ });
2949
+ var fail3 = (error) => failCause2(causeFail(error));
2950
+ var sync = /* @__PURE__ */ makePrimitive({
2951
+ op: "Sync",
2952
+ eval(fiber) {
2953
+ const value = this[args]();
2954
+ const cont = fiber.getCont(successCont);
2955
+ return cont ? cont[successCont](value, fiber) : fiber.yieldWith(exitSucceed(value));
2956
+ }
2957
+ });
2958
+ var suspend = /* @__PURE__ */ makePrimitive({
2959
+ op: "Suspend",
2960
+ eval(_fiber) {
2961
+ return this[args]();
2962
+ }
2963
+ });
2964
+ var yieldNowWith = /* @__PURE__ */ makePrimitive({
2965
+ op: "Yield",
2966
+ eval(fiber) {
2967
+ let resumed = false;
2968
+ fiber.getRef(CurrentScheduler).scheduleTask(() => {
2969
+ if (resumed) return;
2970
+ fiber.evaluate(exitVoid);
2971
+ }, this[args] ?? 0);
2972
+ return fiber.yieldWith(() => {
2973
+ resumed = true;
2974
+ });
2975
+ }
2976
+ });
2977
+ var yieldNow = /* @__PURE__ */ yieldNowWith(0);
2978
+ var void_ = /* @__PURE__ */ succeed(void 0);
2979
+ var try_ = (options) => suspend(() => {
2980
+ try {
2981
+ return succeed(options.try());
2982
+ } catch (err) {
2983
+ return fail3(options.catch(err));
2984
+ }
2985
+ });
2986
+ var tryPromise = (options) => asyncOptions(function(resume, signal) {
2987
+ try {
2988
+ options.try(signal).then((a) => resume(succeed(a)), (e) => resume(fail3(options.catch(e))));
2989
+ } catch (err) {
2990
+ resume(fail3(options.catch(err)));
2991
+ }
2992
+ }, options.try.length !== 0);
2993
+ var withMicroFiber = /* @__PURE__ */ makePrimitive({
2994
+ op: "WithMicroFiber",
2995
+ eval(fiber) {
2996
+ return this[args](fiber);
2997
+ }
2998
+ });
2999
+ var asyncOptions = /* @__PURE__ */ makePrimitive({
3000
+ op: "Async",
3001
+ single: false,
3002
+ eval(fiber) {
3003
+ const register = this[args][0];
3004
+ let resumed = false;
3005
+ let yielded = false;
3006
+ const controller = this[args][1] ? new AbortController() : void 0;
3007
+ const onCancel = register((effect) => {
3008
+ if (resumed) return;
3009
+ resumed = true;
3010
+ if (yielded) {
3011
+ fiber.evaluate(effect);
3012
+ } else {
3013
+ yielded = effect;
3014
+ }
3015
+ }, controller?.signal);
3016
+ if (yielded !== false) return yielded;
3017
+ yielded = true;
3018
+ fiber._yielded = () => {
3019
+ resumed = true;
3020
+ };
3021
+ if (controller === void 0 && onCancel === void 0) {
3022
+ return Yield;
3023
+ }
3024
+ fiber._stack.push(asyncFinalizer(() => {
3025
+ resumed = true;
3026
+ controller?.abort();
3027
+ return onCancel ?? exitVoid;
3028
+ }));
3029
+ return Yield;
3030
+ }
3031
+ });
3032
+ var asyncFinalizer = /* @__PURE__ */ makePrimitive({
3033
+ op: "AsyncFinalizer",
3034
+ ensure(fiber) {
3035
+ if (fiber.interruptible) {
3036
+ fiber.interruptible = false;
3037
+ fiber._stack.push(setInterruptible(true));
3038
+ }
3039
+ },
3040
+ contE(cause, _fiber) {
3041
+ return causeIsInterrupt(cause) ? flatMap3(this[args](), () => failCause2(cause)) : failCause2(cause);
3042
+ }
3043
+ });
3044
+ var async = (register) => asyncOptions(register, register.length >= 2);
3045
+ var gen = (...args2) => suspend(() => fromIterator(args2.length === 1 ? args2[0]() : args2[1].call(args2[0])));
3046
+ var fromIterator = /* @__PURE__ */ makePrimitive({
3047
+ op: "Iterator",
3048
+ contA(value, fiber) {
3049
+ const state = this[args].next(value);
3050
+ if (state.done) return succeed(state.value);
3051
+ fiber._stack.push(this);
3052
+ return yieldWrapGet(state.value);
3053
+ },
3054
+ eval(fiber) {
3055
+ return this[successCont](void 0, fiber);
3056
+ }
3057
+ });
3058
+ var as = /* @__PURE__ */ dual(2, (self, value) => map6(self, (_) => value));
3059
+ var andThen = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => {
3060
+ const value = isMicro(f) ? f : typeof f === "function" ? f(a) : f;
3061
+ return isMicro(value) ? value : succeed(value);
3062
+ }));
3063
+ var tap = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => {
3064
+ const value = isMicro(f) ? f : typeof f === "function" ? f(a) : f;
3065
+ return isMicro(value) ? as(value, a) : succeed(a);
3066
+ }));
3067
+ var asVoid = (self) => flatMap3(self, (_) => exitVoid);
3068
+ var exit = (self) => matchCause(self, {
3069
+ onFailure: exitFailCause,
3070
+ onSuccess: exitSucceed
3071
+ });
3072
+ var flatMap3 = /* @__PURE__ */ dual(2, (self, f) => {
3073
+ const onSuccess = Object.create(OnSuccessProto);
3074
+ onSuccess[args] = self;
3075
+ onSuccess[successCont] = f;
3076
+ return onSuccess;
3077
+ });
3078
+ var OnSuccessProto = /* @__PURE__ */ makePrimitiveProto({
3079
+ op: "OnSuccess",
3080
+ eval(fiber) {
3081
+ fiber._stack.push(this);
3082
+ return this[args];
3083
+ }
3084
+ });
3085
+ var map6 = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => succeed(f(a))));
3086
+ var isMicroExit = (u) => hasProperty(u, MicroExitTypeId);
3087
+ var exitSucceed = succeed;
3088
+ var exitFailCause = failCause2;
3089
+ var exitInterrupt = /* @__PURE__ */ exitFailCause(/* @__PURE__ */ causeInterrupt());
3090
+ var exitDie = (defect) => exitFailCause(causeDie(defect));
3091
+ var exitVoid = /* @__PURE__ */ exitSucceed(void 0);
3092
+ var exitVoidAll = (exits) => {
3093
+ for (const exit2 of exits) {
3094
+ if (exit2._tag === "Failure") {
3095
+ return exit2;
3096
+ }
3097
+ }
3098
+ return exitVoid;
3099
+ };
3100
+ var setImmediate = "setImmediate" in globalThis ? globalThis.setImmediate : (f) => setTimeout(f, 0);
3101
+ var MicroSchedulerDefault = class {
3102
+ tasks = [];
3103
+ running = false;
3104
+ /**
3105
+ * @since 3.5.9
3106
+ */
3107
+ scheduleTask(task, _priority) {
3108
+ this.tasks.push(task);
3109
+ if (!this.running) {
3110
+ this.running = true;
3111
+ setImmediate(this.afterScheduled);
3112
+ }
3113
+ }
3114
+ /**
3115
+ * @since 3.5.9
3116
+ */
3117
+ afterScheduled = () => {
3118
+ this.running = false;
3119
+ this.runTasks();
3120
+ };
3121
+ /**
3122
+ * @since 3.5.9
3123
+ */
3124
+ runTasks() {
3125
+ const tasks = this.tasks;
3126
+ this.tasks = [];
3127
+ for (let i = 0, len = tasks.length; i < len; i++) {
3128
+ tasks[i]();
3129
+ }
3130
+ }
3131
+ /**
3132
+ * @since 3.5.9
3133
+ */
3134
+ shouldYield(fiber) {
3135
+ return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield);
3136
+ }
3137
+ /**
3138
+ * @since 3.5.9
3139
+ */
3140
+ flush() {
3141
+ while (this.tasks.length > 0) {
3142
+ this.runTasks();
3143
+ }
3144
+ }
3145
+ };
3146
+ var service = (tag) => withMicroFiber((fiber) => succeed(unsafeGet3(fiber.context, tag)));
3147
+ var updateContext = /* @__PURE__ */ dual(2, (self, f) => withMicroFiber((fiber) => {
3148
+ const prev = fiber.context;
3149
+ fiber.context = f(prev);
3150
+ return onExit(self, () => {
3151
+ fiber.context = prev;
3152
+ return void_;
3153
+ });
3154
+ }));
3155
+ var provideContext = /* @__PURE__ */ dual(2, (self, provided) => updateContext(self, merge2(provided)));
3156
+ var provideService = /* @__PURE__ */ dual(3, (self, tag, service2) => updateContext(self, add2(tag, service2)));
3157
+ var MaxOpsBeforeYield = class extends (/* @__PURE__ */ Reference2()("effect/Micro/currentMaxOpsBeforeYield", {
3158
+ defaultValue: () => 2048
3159
+ })) {
3160
+ };
3161
+ var CurrentConcurrency = class extends (/* @__PURE__ */ Reference2()("effect/Micro/currentConcurrency", {
3162
+ defaultValue: () => "unbounded"
3163
+ })) {
3164
+ };
3165
+ var CurrentScheduler = class extends (/* @__PURE__ */ Reference2()("effect/Micro/currentScheduler", {
3166
+ defaultValue: () => new MicroSchedulerDefault()
3167
+ })) {
3168
+ };
3169
+ var repeatExit = /* @__PURE__ */ dual(2, (self, options) => suspend(() => {
3170
+ const startedAt = options.schedule ? Date.now() : 0;
3171
+ let attempt = 0;
3172
+ const loop = flatMap3(exit(self), (exit2) => {
3173
+ if (options.while !== void 0 && !options.while(exit2)) {
3174
+ return exit2;
3175
+ } else if (options.times !== void 0 && attempt >= options.times) {
3176
+ return exit2;
3177
+ }
3178
+ attempt++;
3179
+ let delayEffect = yieldNow;
3180
+ if (options.schedule !== void 0) {
3181
+ const elapsed = Date.now() - startedAt;
3182
+ const duration = options.schedule(attempt, elapsed);
3183
+ if (isNone2(duration)) {
3184
+ return exit2;
3185
+ }
3186
+ delayEffect = sleep(duration.value);
3187
+ }
3188
+ return flatMap3(delayEffect, () => loop);
3189
+ });
3190
+ return loop;
3191
+ }));
3192
+ var repeat = /* @__PURE__ */ dual((args2) => isMicro(args2[0]), (self, options) => repeatExit(self, {
3193
+ ...options,
3194
+ while: (exit2) => exit2._tag === "Success" && (options?.while === void 0 || options.while(exit2.value))
3195
+ }));
3196
+ var catchAllCause = /* @__PURE__ */ dual(2, (self, f) => {
3197
+ const onFailure = Object.create(OnFailureProto);
3198
+ onFailure[args] = self;
3199
+ onFailure[failureCont] = f;
3200
+ return onFailure;
3201
+ });
3202
+ var OnFailureProto = /* @__PURE__ */ makePrimitiveProto({
3203
+ op: "OnFailure",
3204
+ eval(fiber) {
3205
+ fiber._stack.push(this);
3206
+ return this[args];
3207
+ }
3208
+ });
3209
+ var catchCauseIf = /* @__PURE__ */ dual(3, (self, predicate, f) => catchAllCause(self, (cause) => predicate(cause) ? f(cause) : failCause2(cause)));
3210
+ var catchAll = /* @__PURE__ */ dual(2, (self, f) => catchCauseIf(self, causeIsFail, (cause) => f(cause.error)));
3211
+ var matchCauseEffect = /* @__PURE__ */ dual(2, (self, options) => {
3212
+ const primitive = Object.create(OnSuccessAndFailureProto);
3213
+ primitive[args] = self;
3214
+ primitive[successCont] = options.onSuccess;
3215
+ primitive[failureCont] = options.onFailure;
3216
+ return primitive;
3217
+ });
3218
+ var OnSuccessAndFailureProto = /* @__PURE__ */ makePrimitiveProto({
3219
+ op: "OnSuccessAndFailure",
3220
+ eval(fiber) {
3221
+ fiber._stack.push(this);
3222
+ return this[args];
3223
+ }
3224
+ });
3225
+ var matchCause = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, {
3226
+ onFailure: (cause) => sync(() => options.onFailure(cause)),
3227
+ onSuccess: (value) => sync(() => options.onSuccess(value))
3228
+ }));
3229
+ var sleep = (millis) => async((resume) => {
3230
+ const timeout = setTimeout(() => {
3231
+ resume(void_);
3232
+ }, millis);
3233
+ return sync(() => {
3234
+ clearTimeout(timeout);
3235
+ });
3236
+ });
3237
+ var delay = /* @__PURE__ */ dual(2, (self, millis) => andThen(sleep(millis), self));
3238
+ var MicroScopeTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroScope");
3239
+ var MicroScopeImpl = class _MicroScopeImpl {
3240
+ [MicroScopeTypeId];
3241
+ state = {
3242
+ _tag: "Open",
3243
+ finalizers: /* @__PURE__ */ new Set()
3244
+ };
3245
+ constructor() {
3246
+ this[MicroScopeTypeId] = MicroScopeTypeId;
3247
+ }
3248
+ unsafeAddFinalizer(finalizer) {
3249
+ if (this.state._tag === "Open") {
3250
+ this.state.finalizers.add(finalizer);
3251
+ }
3252
+ }
3253
+ addFinalizer(finalizer) {
3254
+ return suspend(() => {
3255
+ if (this.state._tag === "Open") {
3256
+ this.state.finalizers.add(finalizer);
3257
+ return void_;
3258
+ }
3259
+ return finalizer(this.state.exit);
3260
+ });
3261
+ }
3262
+ unsafeRemoveFinalizer(finalizer) {
3263
+ if (this.state._tag === "Open") {
3264
+ this.state.finalizers.delete(finalizer);
3265
+ }
3266
+ }
3267
+ close(microExit) {
3268
+ return suspend(() => {
3269
+ if (this.state._tag === "Open") {
3270
+ const finalizers = Array.from(this.state.finalizers).reverse();
3271
+ this.state = {
3272
+ _tag: "Closed",
3273
+ exit: microExit
3274
+ };
3275
+ return flatMap3(forEach3(finalizers, (finalizer) => exit(finalizer(microExit))), exitVoidAll);
3276
+ }
3277
+ return void_;
3278
+ });
3279
+ }
3280
+ get fork() {
3281
+ return sync(() => {
3282
+ const newScope = new _MicroScopeImpl();
3283
+ if (this.state._tag === "Closed") {
3284
+ newScope.state = this.state;
3285
+ return newScope;
3286
+ }
3287
+ function fin(exit2) {
3288
+ return newScope.close(exit2);
3289
+ }
3290
+ this.state.finalizers.add(fin);
3291
+ newScope.unsafeAddFinalizer((_) => sync(() => this.unsafeRemoveFinalizer(fin)));
3292
+ return newScope;
3293
+ });
3294
+ }
3295
+ };
3296
+ var onExit = /* @__PURE__ */ dual(2, (self, f) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), {
3297
+ onFailure: (cause) => flatMap3(f(exitFailCause(cause)), () => failCause2(cause)),
3298
+ onSuccess: (a) => flatMap3(f(exitSucceed(a)), () => succeed(a))
3299
+ })));
3300
+ var setInterruptible = /* @__PURE__ */ makePrimitive({
3301
+ op: "SetInterruptible",
3302
+ ensure(fiber) {
3303
+ fiber.interruptible = this[args];
3304
+ if (fiber._interrupted && fiber.interruptible) {
3305
+ return () => exitInterrupt;
3306
+ }
3307
+ }
3308
+ });
3309
+ var interruptible = (self) => withMicroFiber((fiber) => {
3310
+ if (fiber.interruptible) return self;
3311
+ fiber.interruptible = true;
3312
+ fiber._stack.push(setInterruptible(false));
3313
+ if (fiber._interrupted) return exitInterrupt;
3314
+ return self;
3315
+ });
3316
+ var uninterruptibleMask = (f) => withMicroFiber((fiber) => {
3317
+ if (!fiber.interruptible) return f(identity);
3318
+ fiber.interruptible = false;
3319
+ fiber._stack.push(setInterruptible(true));
3320
+ return f(interruptible);
3321
+ });
3322
+ var whileLoop = /* @__PURE__ */ makePrimitive({
3323
+ op: "While",
3324
+ contA(value, fiber) {
3325
+ this[args].step(value);
3326
+ if (this[args].while()) {
3327
+ fiber._stack.push(this);
3328
+ return this[args].body();
3329
+ }
3330
+ return exitVoid;
3331
+ },
3332
+ eval(fiber) {
3333
+ if (this[args].while()) {
3334
+ fiber._stack.push(this);
3335
+ return this[args].body();
3336
+ }
3337
+ return exitVoid;
3338
+ }
3339
+ });
3340
+ var forEach3 = (iterable, f, options) => withMicroFiber((parent) => {
3341
+ const concurrencyOption = options?.concurrency === "inherit" ? parent.getRef(CurrentConcurrency) : options?.concurrency ?? 1;
3342
+ const concurrency = concurrencyOption === "unbounded" ? Number.POSITIVE_INFINITY : Math.max(1, concurrencyOption);
3343
+ const items = fromIterable(iterable);
3344
+ let length = items.length;
3345
+ if (length === 0) {
3346
+ return options?.discard ? void_ : succeed([]);
3347
+ }
3348
+ const out = options?.discard ? void 0 : new Array(length);
3349
+ let index = 0;
3350
+ if (concurrency === 1) {
3351
+ return as(whileLoop({
3352
+ while: () => index < items.length,
3353
+ body: () => f(items[index], index),
3354
+ step: out ? (b) => out[index++] = b : (_) => index++
3355
+ }), out);
3356
+ }
3357
+ return async((resume) => {
3358
+ const fibers = /* @__PURE__ */ new Set();
3359
+ let result = void 0;
3360
+ let inProgress = 0;
3361
+ let doneCount = 0;
3362
+ let pumping = false;
3363
+ let interrupted = false;
3364
+ function pump() {
3365
+ pumping = true;
3366
+ while (inProgress < concurrency && index < length) {
3367
+ const currentIndex = index;
3368
+ const item = items[currentIndex];
3369
+ index++;
3370
+ inProgress++;
3371
+ try {
3372
+ const child = unsafeFork(parent, f(item, currentIndex), true, true);
3373
+ fibers.add(child);
3374
+ child.addObserver((exit2) => {
3375
+ fibers.delete(child);
3376
+ if (interrupted) {
3377
+ return;
3378
+ } else if (exit2._tag === "Failure") {
3379
+ if (result === void 0) {
3380
+ result = exit2;
3381
+ length = index;
3382
+ fibers.forEach((fiber) => fiber.unsafeInterrupt());
3383
+ }
3384
+ } else if (out !== void 0) {
3385
+ out[currentIndex] = exit2.value;
3386
+ }
3387
+ doneCount++;
3388
+ inProgress--;
3389
+ if (doneCount === length) {
3390
+ resume(result ?? succeed(out));
3391
+ } else if (!pumping && inProgress < concurrency) {
3392
+ pump();
3393
+ }
3394
+ });
3395
+ } catch (err) {
3396
+ result = exitDie(err);
3397
+ length = index;
3398
+ fibers.forEach((fiber) => fiber.unsafeInterrupt());
3399
+ }
3400
+ }
3401
+ pumping = false;
3402
+ }
3403
+ pump();
3404
+ return suspend(() => {
3405
+ interrupted = true;
3406
+ index = length;
3407
+ return fiberInterruptAll(fibers);
3408
+ });
3409
+ });
3410
+ });
3411
+ var unsafeFork = (parent, effect, immediate = false, daemon = false) => {
3412
+ const child = new MicroFiberImpl(parent.context, parent.interruptible);
3413
+ if (!daemon) {
3414
+ parent.children().add(child);
3415
+ child.addObserver(() => parent.children().delete(child));
3416
+ }
3417
+ if (immediate) {
3418
+ child.evaluate(effect);
3419
+ } else {
3420
+ parent.getRef(CurrentScheduler).scheduleTask(() => child.evaluate(effect), 0);
3421
+ }
3422
+ return child;
3423
+ };
3424
+ var forkDaemon = (self) => withMicroFiber((fiber) => succeed(unsafeFork(fiber, self, false, true)));
3425
+ var runFork = (effect, options) => {
3426
+ const fiber = new MicroFiberImpl(CurrentScheduler.context(options?.scheduler ?? new MicroSchedulerDefault()));
3427
+ fiber.evaluate(effect);
3428
+ if (options?.signal) {
3429
+ if (options.signal.aborted) {
3430
+ fiber.unsafeInterrupt();
3431
+ } else {
3432
+ const abort = () => fiber.unsafeInterrupt();
3433
+ options.signal.addEventListener("abort", abort, {
3434
+ once: true
3435
+ });
3436
+ fiber.addObserver(() => options.signal.removeEventListener("abort", abort));
3437
+ }
3438
+ }
3439
+ return fiber;
3440
+ };
3441
+ var runPromiseExit = (effect, options) => new Promise((resolve, _reject) => {
3442
+ const handle = runFork(effect, options);
3443
+ handle.addObserver(resolve);
3444
+ });
3445
+ var runPromise = (effect, options) => runPromiseExit(effect, options).then((exit2) => {
3446
+ if (exit2._tag === "Failure") {
3447
+ throw exit2.cause;
3448
+ }
3449
+ return exit2.value;
3450
+ });
3451
+
3452
+ // src/internal/handle-update.ts
3453
+ import { executeTgBotMethod } from "@effect-ak/tg-bot-client";
3454
+ import { MESSAGE_EFFECTS } from "@effect-ak/tg-bot-client";
3455
+
3456
+ // src/internal/poll-settings.ts
3457
+ var BotUpdateHandlersTag = class extends Tag2("BotUpdateHandlers")() {
3458
+ };
3459
+ var BotPollSettings = class _BotPollSettings extends Class2 {
3460
+ static make(input) {
3461
+ let batch_size = input.batch_size ?? 10;
3462
+ let poll_timeout = input.poll_timeout ?? 10;
3463
+ let max_empty_responses = input.max_empty_responses;
3464
+ let log_level = input.log_level ?? "info";
3465
+ let on_error = input.on_error;
3466
+ if (batch_size < 10 || batch_size > 100) {
3467
+ console.warn("Wrong batch_size, must be in [10..100], using 10 instead");
3468
+ batch_size = 10;
3469
+ }
3470
+ if (poll_timeout < 2 || poll_timeout > 120) {
3471
+ console.warn("Wrong poll_timeout, must be in [2..120], using 20 instead");
3472
+ poll_timeout = 20;
3473
+ }
3474
+ if (max_empty_responses && max_empty_responses < 2) {
3475
+ console.warn(
3476
+ "Wrong max_empty_responses, must be in [2..infinity], using infinity"
3477
+ );
3478
+ max_empty_responses = void 0;
3479
+ }
3480
+ if (!log_level) {
3481
+ log_level = "info";
3482
+ }
3483
+ if (!on_error) {
3484
+ on_error = "stop";
3485
+ }
3486
+ const config = new _BotPollSettings({
3487
+ batch_size,
3488
+ poll_timeout,
3489
+ max_empty_responses,
3490
+ log_level,
3491
+ on_error
3492
+ });
3493
+ console.log("bot poll settings", config);
3494
+ return config;
3495
+ }
3496
+ };
3497
+ var BotPollSettingsTag = class extends Reference2()(
3498
+ "BotSettings",
3499
+ {
3500
+ defaultValue() {
3501
+ return BotPollSettings.make({});
3502
+ }
3503
+ }
3504
+ ) {
3505
+ };
3506
+
3507
+ // src/internal/handle-update.ts
3508
+ var extractUpdate = (input) => {
3509
+ for (const [field, value] of Object.entries(input)) {
3510
+ if (field == "update_id") {
3511
+ continue;
3512
+ }
3513
+ return {
3514
+ type: field,
3515
+ ...value
3516
+ };
3517
+ }
3518
+ return;
3519
+ };
3520
+ var BatchUpdateResult = class extends Class2 {
3521
+ };
3522
+ var handleUpdates = (updates) => gen(function* () {
3523
+ const pollSettings = yield* service(BotPollSettingsTag);
3524
+ const updateHandler = yield* service(BotUpdateHandlersTag);
3525
+ if (updateHandler.type == "single") {
3526
+ return yield* handleOneByOne(updates, updateHandler, pollSettings);
3527
+ } else {
3528
+ return yield* handleEntireBatch(updates, updateHandler);
3529
+ }
3530
+ });
3531
+ var handleEntireBatch = (updates, handlers) => try_({
3532
+ try: () => handlers.on_batch(updates),
3533
+ catch: identity
3534
+ }).pipe(
3535
+ andThen((result) => {
3536
+ if (result instanceof Promise) {
3537
+ return tryPromise({
3538
+ try: () => result,
3539
+ catch: identity
3540
+ });
3541
+ } else {
3542
+ return succeed(result);
3543
+ }
3544
+ }),
3545
+ andThen(
3546
+ (doNext) => new BatchUpdateResult({
3547
+ hasErrors: !doNext,
3548
+ updates
3549
+ })
3550
+ ),
3551
+ catchAll((error) => {
3552
+ console.warn("handle batch error", {
3553
+ errorMessage: error instanceof Error ? error.message : void 0,
3554
+ updates: updates.map((_) => Object.keys(_).at(1)),
3555
+ error
3556
+ });
3557
+ return succeed(
3558
+ new BatchUpdateResult({
3559
+ hasErrors: true,
3560
+ updates
3561
+ })
3562
+ );
3563
+ })
3564
+ );
3565
+ var HandleUpdateError = class extends TaggedError("HandleUpdateError") {
3566
+ };
3567
+ var handleOneByOne = (updates, handlers, pollSettings) => forEach3(
3568
+ updates,
3569
+ (update) => handleOneUpdate(update, handlers).pipe(
3570
+ catchAll((error) => {
3571
+ console.log("update handle error", {
3572
+ updateId: update.update_id,
3573
+ updateKey: Object.keys(update).at(1),
3574
+ name: error._tag,
3575
+ ...error.cause instanceof Error ? { error: error.cause.message } : void 0
3576
+ });
3577
+ return succeed(error);
3578
+ })
3579
+ ),
3580
+ {
3581
+ concurrency: 10
3582
+ }
3583
+ ).pipe(
3584
+ andThen((batchResult) => {
3585
+ if (pollSettings.log_level == "debug") {
3586
+ console.debug("handle batch result", batchResult);
3587
+ }
3588
+ return new BatchUpdateResult({
3589
+ hasErrors: !batchResult.every((error) => error == null),
3590
+ updates
3591
+ });
3592
+ })
3593
+ );
3594
+ var handleOneUpdate = (updateObject, handlers) => gen(function* () {
3595
+ const update = extractUpdate(updateObject);
3596
+ if (!update) {
3597
+ return yield* fail3(
3598
+ new HandleUpdateError({
3599
+ name: "UnknownUpdate",
3600
+ update: updateObject
3601
+ })
3602
+ );
3603
+ }
3604
+ const updateHandler = handlers[`on_${update.type}`];
3605
+ if (!updateHandler) {
3606
+ return yield* fail3(
3607
+ new HandleUpdateError({
3608
+ name: "HandlerNotDefined",
3609
+ update: updateObject
3610
+ })
3611
+ );
3612
+ }
3613
+ if (update.type == "message" && "text" in update) {
3614
+ console.info("Got a new text message", {
3615
+ chatId: update.chat.id,
3616
+ chatType: update.chat.type,
3617
+ message: `${update.text.slice(0, 5)}...`
3618
+ });
3619
+ }
3620
+ let handleUpdateError;
3621
+ const handleResult = yield* try_({
3622
+ try: () => updateHandler(update),
3623
+ catch: (error) => new HandleUpdateError({
3624
+ name: "BotHandlerError",
3625
+ update: updateObject,
3626
+ cause: error
3627
+ })
3628
+ }).pipe(
3629
+ andThen((handleResult2) => {
3630
+ if (handleResult2 instanceof Promise) {
3631
+ return tryPromise({
3632
+ try: () => handleResult2,
3633
+ catch: (error) => new HandleUpdateError({
3634
+ name: "BotHandlerError",
3635
+ update: updateObject,
3636
+ cause: error
3637
+ })
3638
+ });
3639
+ }
3640
+ return succeed(handleResult2);
3641
+ }),
3642
+ catchAll((error) => {
3643
+ handleUpdateError = error;
3644
+ console.log("error", {
3645
+ updateId: updateObject.update_id,
3646
+ updateKey: Object.keys(updateObject).at(1),
3647
+ name: error._tag,
3648
+ ...error.cause instanceof Error ? { error: error.cause.message } : void 0
3649
+ });
3650
+ return succeed(
3651
+ BotResponse.make({
3652
+ type: "message",
3653
+ text: `Some internal error has happend(${error.name}) while handling this message`,
3654
+ message_effect_id: MESSAGE_EFFECTS["\u{1F4A9}"],
3655
+ ...updateObject.message?.message_id ? {
3656
+ reply_parameters: {
3657
+ message_id: updateObject.message?.message_id
3658
+ }
3659
+ } : void 0
3660
+ })
3661
+ );
3662
+ })
3663
+ );
3664
+ const pollSettings = yield* service(BotPollSettingsTag);
3665
+ if (!handleResult && pollSettings.log_level == "debug") {
3666
+ console.log(
3667
+ `Bot response is undefined for update with ID #${updateObject.update_id}.`
3668
+ );
3669
+ return;
3670
+ }
3671
+ if ("chat" in update && handleResult.response) {
3672
+ const response = yield* executeTgBotMethod(
3673
+ `send_${handleResult.response.type}`,
3674
+ {
3675
+ ...handleResult.response,
3676
+ chat_id: update.chat.id
3677
+ }
3678
+ );
3679
+ if (pollSettings.log_level == "debug" && "text") {
3680
+ console.debug("bot response", response);
3681
+ }
3682
+ }
3683
+ return handleUpdateError;
3684
+ });
3685
+
3686
+ // src/service/fetch-updates.ts
3687
+ import { executeTgBotMethod as executeTgBotMethod2 } from "@effect-ak/tg-bot-client";
3688
+ var BotFetchUpdatesService = class extends Reference2()(
3689
+ "BotFetchUpdatesService",
3690
+ {
3691
+ defaultValue: () => {
3692
+ const state = {
3693
+ lastUpdateId: void 0,
3694
+ emptyResponses: 0
3695
+ };
3696
+ const fetchUpdates = _fetchUpdates(state).pipe(
3697
+ tap((updates) => {
3698
+ const id = updates.map((_) => _.update_id).sort().at(-1);
3699
+ console.log("updating last update id", id);
3700
+ state.lastUpdateId = id ? id + 1 : void 0;
3701
+ console.log(state);
3702
+ })
3703
+ );
3704
+ const commit = _commitLastBatch(state);
3705
+ return {
3706
+ state,
3707
+ fetchUpdates,
3708
+ commit
3709
+ };
3710
+ }
3711
+ }
3712
+ ) {
3713
+ };
3714
+ var FetchUpdatesError = class extends TaggedError("FetchUpdatesError") {
3715
+ };
3716
+ var _fetchUpdates = (pollState) => gen(function* () {
3717
+ const pollSettings = yield* service(BotPollSettingsTag);
3718
+ if (pollSettings.max_empty_responses && pollState.emptyResponses == pollSettings.max_empty_responses) {
3719
+ return yield* fail3(
3720
+ new FetchUpdatesError({ name: "TooManyEmptyResponses" })
3721
+ );
3722
+ }
3723
+ const updateId = pollState.lastUpdateId;
3724
+ if (pollSettings.log_level == "debug") {
3725
+ console.debug("getting updates", pollState);
3726
+ }
3727
+ const updates = yield* executeTgBotMethod2("get_updates", {
3728
+ timeout: pollSettings.poll_timeout,
3729
+ ...updateId ? { offset: updateId } : void 0
3730
+ }).pipe(andThen((_) => _.sort((_2) => _2.update_id)));
3731
+ if (updates.length) {
3732
+ console.debug(`got a batch of updates (${updates.length})`);
3733
+ pollState.emptyResponses = 0;
3734
+ return updates;
3735
+ } else {
3736
+ pollState.emptyResponses += 1;
3737
+ return [];
3738
+ }
3739
+ });
3740
+ var _commitLastBatch = (pollState) => gen(function* () {
3741
+ console.log("commit", { pollState });
3742
+ if (pollState.lastUpdateId) {
3743
+ return yield* executeTgBotMethod2("get_updates", {
3744
+ offset: pollState.lastUpdateId,
3745
+ limit: 0
3746
+ }).pipe(
3747
+ andThen(
3748
+ andThen(service(BotPollSettingsTag), (pollSettings) => {
3749
+ if (pollSettings.log_level == "debug") {
3750
+ console.debug("committed offset", pollState);
3751
+ }
3752
+ })
3753
+ )
3754
+ );
3755
+ } else {
3756
+ return yield* fail3(
3757
+ new FetchUpdatesError({
3758
+ name: "NoUpdatesToCommit"
3759
+ })
3760
+ );
3761
+ }
3762
+ });
3763
+
3764
+ // src/service/run.ts
3765
+ var BotRunService = class extends Reference2()(
3766
+ "BotRunService",
3767
+ {
3768
+ defaultValue: () => {
3769
+ console.log("Initiating BotRunService");
3770
+ const state = {
3771
+ fiber: void 0
3772
+ };
3773
+ const runBotInBackground = _runBotDaemon(state);
3774
+ const getFiber = () => state.fiber;
3775
+ return {
3776
+ runBotInBackground,
3777
+ getFiber
3778
+ };
3779
+ }
3780
+ }
3781
+ ) {
3782
+ };
3783
+ var _runBotDaemon = (state) => gen(function* () {
3784
+ console.log("running telegram chat bot");
3785
+ const fetchService = yield* service(BotFetchUpdatesService);
3786
+ const settings = yield* service(BotPollSettingsTag);
3787
+ const continueOnError = (hasError) => {
3788
+ if (settings.on_error == "continue") return true;
3789
+ return !hasError;
3790
+ };
3791
+ const startFiber = delay(1e3)(
3792
+ fetchService.fetchUpdates.pipe(
3793
+ andThen(handleUpdates),
3794
+ tap((result) => {
3795
+ const hasUpdates = result.updates.length > 0;
3796
+ return hasUpdates && continueOnError(result.hasErrors) ? fetchService.commit : void_;
3797
+ })
3798
+ )
3799
+ ).pipe(
3800
+ repeat({
3801
+ while: (_) => continueOnError(_.hasErrors)
3802
+ }),
3803
+ forkDaemon,
3804
+ tap(
3805
+ (fiber) => fiber.addObserver((exit2) => {
3806
+ console.log("bot's fiber has been closed", exit2);
3807
+ })
3808
+ )
3809
+ );
3810
+ if (state.fiber) {
3811
+ console.log("killing previous bot's fiber");
3812
+ yield* fiberInterrupt(state.fiber);
3813
+ }
3814
+ state.fiber = yield* startFiber;
3815
+ console.log("Fetching bot updates via long polling...");
3816
+ });
3817
+
3818
+ // src/internal/launch.ts
3819
+ import { TgBotApiToken } from "@effect-ak/tg-bot-client";
3820
+ var launchBot = (input) => gen(function* () {
3821
+ const service2 = yield* service(BotRunService);
3822
+ const contextWithToken = make4(TgBotApiToken, input.bot_token);
3823
+ yield* service2.runBotInBackground.pipe(
3824
+ provideService(BotUpdateHandlersTag, input.mode),
3825
+ provideService(
3826
+ BotPollSettingsTag,
3827
+ BotPollSettings.make(input.poll ?? {})
3828
+ ),
3829
+ provideContext(contextWithToken)
3830
+ );
3831
+ const reload = (mode) => service2.runBotInBackground.pipe(
3832
+ provideService(BotUpdateHandlersTag, mode),
3833
+ provideContext(contextWithToken),
3834
+ runPromise
3835
+ );
3836
+ return {
3837
+ reload,
3838
+ fiber: service2.getFiber
3839
+ };
3840
+ });
3841
+
3842
+ // src/run.ts
3843
+ var runTgChatBot = (input) => launchBot(input).pipe(runPromise);
3844
+ var defineBot = (input) => {
3845
+ if (Object.keys(input).length == 0)
3846
+ console.warn("No handlers are defined for bot");
3847
+ return input;
3848
+ };
3849
+ export {
3850
+ BatchUpdateResult,
3851
+ BotPollSettings,
3852
+ BotPollSettingsTag,
3853
+ BotResponse,
3854
+ BotRunService,
3855
+ BotUpdateHandlersTag,
3856
+ HandleUpdateError,
3857
+ defineBot,
3858
+ extractUpdate,
3859
+ handleEntireBatch,
3860
+ handleOneByOne,
3861
+ handleOneUpdate,
3862
+ handleUpdates,
3863
+ launchBot,
3864
+ runTgChatBot
3865
+ };