brass-runtime 1.16.0 → 1.16.1

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.
Files changed (210) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +283 -18
  3. package/dist/agent/cli/main.cjs +38 -38
  4. package/dist/agent/cli/main.js +6 -6
  5. package/dist/agent/cli/main.mjs +6 -6
  6. package/dist/agent/index.cjs +7 -7
  7. package/dist/agent/index.d.ts +1 -1
  8. package/dist/agent/index.js +6 -6
  9. package/dist/agent/index.mjs +6 -6
  10. package/dist/chunk-2HQTDLHF.mjs +683 -0
  11. package/dist/chunk-36I3M4UC.mjs +370 -0
  12. package/dist/{chunk-QY5FKYEQ.js → chunk-3AYM6WPJ.js} +570 -51
  13. package/dist/chunk-3LOYJFRR.cjs +300 -0
  14. package/dist/chunk-3Y2RIUMM.js +300 -0
  15. package/dist/{chunk-N6VHMOWB.cjs → chunk-4ROBZFL6.cjs} +128 -128
  16. package/dist/{chunk-NC5SDRYE.js → chunk-52OB2ROS.js} +4 -4
  17. package/dist/{chunk-JX3LZQJH.cjs → chunk-52PPNNI4.cjs} +82 -20
  18. package/dist/{chunk-5YOQOXEQ.cjs → chunk-5EC274J5.cjs} +676 -293
  19. package/dist/chunk-5QC7LRZ3.js +229 -0
  20. package/dist/{chunk-7TL2LHQJ.js → chunk-5VRJNBLZ.mjs} +524 -141
  21. package/dist/chunk-62AZW6UT.cjs +313 -0
  22. package/dist/chunk-6IXXWIUM.js +683 -0
  23. package/dist/chunk-74ZTY6CP.js +2871 -0
  24. package/dist/chunk-76YMRMH2.cjs +777 -0
  25. package/dist/chunk-7CMJS3QE.mjs +2871 -0
  26. package/dist/{chunk-2WC63LJK.mjs → chunk-7JIJOVCT.js} +20 -10
  27. package/dist/{chunk-FM4W4QPL.js → chunk-A2OM6NEH.mjs} +5 -4
  28. package/dist/chunk-AGR5B2BC.cjs +683 -0
  29. package/dist/chunk-AVNQLJ5V.js +777 -0
  30. package/dist/chunk-B33ICAKP.js +313 -0
  31. package/dist/{chunk-J3H54ZRV.mjs → chunk-B5JD23U7.mjs} +1 -1
  32. package/dist/chunk-BABBZK4Y.js +2024 -0
  33. package/dist/{chunk-U5KWK3PX.mjs → chunk-C3MDXTRZ.js} +11 -0
  34. package/dist/{chunk-F5EUMJL7.mjs → chunk-CIZFIMK5.js} +55 -5
  35. package/dist/{chunk-SPUEME2B.cjs → chunk-CZIVE6NT.cjs} +12 -1
  36. package/dist/{chunk-TDVMADDN.js → chunk-DNFJLJMW.mjs} +11 -0
  37. package/dist/chunk-DNFO2EIZ.mjs +777 -0
  38. package/dist/{chunk-XDZOO4L5.js → chunk-EJ6BPYVR.mjs} +79 -17
  39. package/dist/{chunk-JNFRRJYH.cjs → chunk-ENKODRU3.cjs} +242 -192
  40. package/dist/chunk-EOC4UHBS.mjs +229 -0
  41. package/dist/{chunk-7LVI2GIN.js → chunk-FH2X7BVP.js} +507 -72
  42. package/dist/{chunk-OOGJ73B6.js → chunk-FHQGHPMO.mjs} +20 -10
  43. package/dist/{chunk-WQ5QNU5R.cjs → chunk-GLE2WY7Z.cjs} +652 -217
  44. package/dist/{chunk-G6IQOE4P.mjs → chunk-GYM3LLGS.mjs} +507 -72
  45. package/dist/chunk-HLWLMW2F.mjs +2024 -0
  46. package/dist/{chunk-TVN5I4U6.cjs → chunk-JF5WGYJJ.cjs} +25 -24
  47. package/dist/{chunk-CY33PGEX.mjs → chunk-KH4SYAOS.mjs} +570 -51
  48. package/dist/chunk-KN32XNTH.mjs +313 -0
  49. package/dist/chunk-KQLYONSE.cjs +2871 -0
  50. package/dist/{chunk-7HUOJA4W.cjs → chunk-KZJQ723N.cjs} +90 -80
  51. package/dist/{chunk-CCKHV5BT.mjs → chunk-L2SYFEBS.js} +5 -4
  52. package/dist/{chunk-IJT6RRQ5.cjs → chunk-L6VB5N7Q.cjs} +20 -9
  53. package/dist/{chunk-ZGLD4TVZ.mjs → chunk-MBEJI5HF.mjs} +4 -4
  54. package/dist/{chunk-PRWCB3QL.mjs → chunk-MIIYDLGM.js} +524 -141
  55. package/dist/{chunk-H55LI6WY.js → chunk-MOO4L7F4.mjs} +15 -4
  56. package/dist/{chunk-7XOPAB5Q.js → chunk-MT3OWDPC.mjs} +55 -5
  57. package/dist/chunk-MVGUEJ5Z.cjs +370 -0
  58. package/dist/chunk-PD4EJTQC.cjs +229 -0
  59. package/dist/chunk-PWC3RBQE.mjs +300 -0
  60. package/dist/{chunk-MWXMNYJS.cjs → chunk-Q2I37RP3.cjs} +643 -124
  61. package/dist/{chunk-VFIUZG7J.mjs → chunk-RKGKFN2A.js} +79 -17
  62. package/dist/{chunk-NYL4D7SK.cjs → chunk-SA6HUJVI.cjs} +5 -5
  63. package/dist/{chunk-K2T3DV26.mjs → chunk-TRM4JUZQ.js} +15 -4
  64. package/dist/chunk-UB4B6OFY.js +370 -0
  65. package/dist/{chunk-G3XGCZDQ.js → chunk-UCUBNWM2.js} +1 -1
  66. package/dist/chunk-VN44DYYT.cjs +2024 -0
  67. package/dist/{client-CtFmoDvM.d.ts → client-CZHU674n.d.ts} +211 -36
  68. package/dist/core/index.cjs +135 -9
  69. package/dist/core/index.d.ts +238 -33
  70. package/dist/core/index.js +155 -29
  71. package/dist/core/index.mjs +155 -29
  72. package/dist/{effect-CGNl5Rqp.d.ts → effect-DIUHZ9IN.d.ts} +89 -1
  73. package/dist/effectRunner-CFLC32IK.cjs +8 -0
  74. package/dist/{effectRunner-A4CHJXJI.js → effectRunner-L4S7IPT3.js} +2 -2
  75. package/dist/{effectRunner-OPUF6QRN.mjs → effectRunner-NNGG75QA.mjs} +2 -2
  76. package/dist/http/index.cjs +324 -2986
  77. package/dist/http/index.d.ts +54 -68
  78. package/dist/http/index.js +238 -2900
  79. package/dist/http/index.mjs +238 -2900
  80. package/dist/http/testing.cjs +14 -12
  81. package/dist/http/testing.d.ts +5 -4
  82. package/dist/http/testing.js +10 -8
  83. package/dist/http/testing.mjs +10 -8
  84. package/dist/index.cjs +423 -255
  85. package/dist/index.d.ts +87 -69
  86. package/dist/index.js +301 -133
  87. package/dist/index.mjs +301 -133
  88. package/dist/observability/index.cjs +16 -531
  89. package/dist/observability/index.d.ts +81 -8
  90. package/dist/observability/index.js +23 -538
  91. package/dist/observability/index.mjs +23 -538
  92. package/dist/perf/cli.cjs +401 -0
  93. package/dist/perf/cli.d.ts +1 -0
  94. package/dist/perf/cli.js +401 -0
  95. package/dist/perf/cli.mjs +401 -0
  96. package/dist/perf/index.cjs +141 -0
  97. package/dist/perf/index.d.ts +483 -0
  98. package/dist/perf/index.js +141 -0
  99. package/dist/perf/index.mjs +141 -0
  100. package/dist/schedule-CK3Ml_7p.d.ts +259 -0
  101. package/dist/schema/index.cjs +6 -2
  102. package/dist/schema/index.d.ts +3 -1
  103. package/dist/schema/index.js +5 -1
  104. package/dist/schema/index.mjs +5 -1
  105. package/dist/{server-C8hDXA74.d.ts → server-GJPg8ZSG.d.ts} +4 -3
  106. package/dist/{stream-dvSs0QS5.d.ts → stream-B4oK9JFP.d.ts} +1 -1
  107. package/dist/{tracer-B5tRH9H7.d.ts → tracer-Hwt1cl7h.d.ts} +13 -54
  108. package/dist/{tracing-Dt9S_6V8.d.ts → tracing-DqbTKGcf.d.ts} +1 -1
  109. package/docs/ARCHITECTURE.md +292 -0
  110. package/docs/README.md +63 -0
  111. package/docs/adr/0001-ai-context-pack.md +32 -0
  112. package/docs/agent-apply-mode.md +104 -0
  113. package/docs/agent-approvals.md +110 -0
  114. package/docs/agent-batch.md +185 -0
  115. package/docs/agent-boundaries.md +112 -0
  116. package/docs/agent-chat-sessions.md +160 -0
  117. package/docs/agent-ci.md +17 -0
  118. package/docs/agent-cli.md +405 -0
  119. package/docs/agent-config.md +480 -0
  120. package/docs/agent-context-discovery.md +159 -0
  121. package/docs/agent-copilot-like-dx.md +126 -0
  122. package/docs/agent-declarative-optimized-planning.md +138 -0
  123. package/docs/agent-dx.md +224 -0
  124. package/docs/agent-env-files.md +126 -0
  125. package/docs/agent-follow-up-context.md +43 -0
  126. package/docs/agent-global-usage.md +180 -0
  127. package/docs/agent-init.md +109 -0
  128. package/docs/agent-install-and-configure.md +516 -0
  129. package/docs/agent-language-workspace-ux.md +99 -0
  130. package/docs/agent-llm-adapters.md +123 -0
  131. package/docs/agent-local-install.md +190 -0
  132. package/docs/agent-local-tests.md +51 -0
  133. package/docs/agent-observability.md +155 -0
  134. package/docs/agent-patch-quality-loop.md +162 -0
  135. package/docs/agent-presets.md +22 -0
  136. package/docs/agent-project-commands.md +237 -0
  137. package/docs/agent-project-intelligence.md +156 -0
  138. package/docs/agent-redaction.md +18 -0
  139. package/docs/agent-release-readiness.md +76 -0
  140. package/docs/agent-rollback-safety.md +162 -0
  141. package/docs/agent-rollback.md +23 -0
  142. package/docs/agent-run-artifacts.md +16 -0
  143. package/docs/agent-vscode-auto-discovery.md +137 -0
  144. package/docs/agent-vscode-batch-runner.md +100 -0
  145. package/docs/agent-vscode-chat-layout.md +90 -0
  146. package/docs/agent-vscode-clean-install.md +147 -0
  147. package/docs/agent-vscode-code-actions.md +70 -0
  148. package/docs/agent-vscode-diff-preview.md +45 -0
  149. package/docs/agent-vscode-inline-assist.md +56 -0
  150. package/docs/agent-vscode-install.md +186 -0
  151. package/docs/agent-vscode-model-setup.md +97 -0
  152. package/docs/agent-vscode-patch-preview.md +92 -0
  153. package/docs/agent-vscode-problems.md +79 -0
  154. package/docs/agent-vscode-project-dashboard.md +106 -0
  155. package/docs/agent-vscode-run-history.md +92 -0
  156. package/docs/agent-vscode-ux.md +73 -0
  157. package/docs/ai/INVARIANTS.md +84 -0
  158. package/docs/ai/PROJECT_MAP.md +338 -0
  159. package/docs/ai/PUBLIC_API.md +336 -0
  160. package/docs/ai/VALIDATION_MATRIX.md +67 -0
  161. package/docs/api-polish.md +37 -0
  162. package/docs/cancellation.md +162 -0
  163. package/docs/coverage.md +46 -0
  164. package/docs/getting-started.md +159 -0
  165. package/docs/guides/README.md +40 -0
  166. package/docs/guides/circuit-breaker.md +89 -0
  167. package/docs/guides/error-handling.md +91 -0
  168. package/docs/guides/getting-started.md +107 -0
  169. package/docs/guides/layers.md +189 -0
  170. package/docs/guides/metrics.md +101 -0
  171. package/docs/guides/resource-management.md +141 -0
  172. package/docs/guides/retry.md +215 -0
  173. package/docs/guides/semaphore.md +66 -0
  174. package/docs/guides/streams.md +117 -0
  175. package/docs/guides/supervisors.md +98 -0
  176. package/docs/guides/testing.md +162 -0
  177. package/docs/guides/tracing.md +71 -0
  178. package/docs/http-recipes.md +399 -0
  179. package/docs/http.md +749 -0
  180. package/docs/modules.md +285 -0
  181. package/docs/observability-collector-smoke.md +31 -0
  182. package/docs/observability-framework-examples.md +98 -0
  183. package/docs/observability.md +542 -0
  184. package/docs/otel-collector-smoke.yaml +27 -0
  185. package/docs/performance-profiler.md +199 -0
  186. package/docs/production-readiness.md +73 -0
  187. package/docs/recipes/README.md +12 -0
  188. package/docs/recipes/http-server.md +45 -0
  189. package/docs/recipes/layers.md +44 -0
  190. package/docs/recipes/performance.md +47 -0
  191. package/docs/recipes/runtime.md +41 -0
  192. package/docs/recipes/testing.md +41 -0
  193. package/docs/release.md +53 -0
  194. package/docs/wasm-bounded-queues.md +44 -0
  195. package/docs/wasm-engine-observability-benchmarks.md +85 -0
  196. package/docs/wasm-fiber-engine.md +117 -0
  197. package/docs/wasm-scheduler-state-machine.md +122 -0
  198. package/docs/wasm-stream-chunks.md +54 -0
  199. package/package.json +22 -2
  200. package/dist/chunk-45F7OKGT.cjs +0 -104
  201. package/dist/chunk-7V4KY4RL.mjs +0 -104
  202. package/dist/chunk-DJQ7OMMB.cjs +0 -144
  203. package/dist/chunk-GOV47PPB.mjs +0 -552
  204. package/dist/chunk-JF4XXPZ5.cjs +0 -552
  205. package/dist/chunk-KCPT2D6G.js +0 -552
  206. package/dist/chunk-NOYZIMUJ.mjs +0 -144
  207. package/dist/chunk-PNVFW245.js +0 -144
  208. package/dist/chunk-ROJC3NBJ.js +0 -104
  209. package/dist/effectRunner-3ZHAD3LE.cjs +0 -8
  210. package/dist/schedule-Fque9Abz.d.ts +0 -70
@@ -0,0 +1,683 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkGLE2WY7Zcjs = require('./chunk-GLE2WY7Z.cjs');
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+ var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
14
+
15
+ // src/core/runtime/combinators.ts
16
+ function sleep(ms) {
17
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
18
+ const clock = _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env);
19
+ const id = clock.setTimeout(() => cb({ _tag: "Success", value: void 0 }), ms);
20
+ return () => clock.clearTimeout(id);
21
+ });
22
+ }
23
+ function timeout(effect, ms) {
24
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
25
+ const clock = _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env);
26
+ let done = false;
27
+ let timerId;
28
+ let fiber;
29
+ timerId = clock.setTimeout(() => {
30
+ if (done) return;
31
+ done = true;
32
+ _optionalChain([fiber, 'optionalAccess', _ => _.interrupt, 'call', _2 => _2()]);
33
+ cb({
34
+ _tag: "Failure",
35
+ cause: { _tag: "Fail", error: { _tag: "TimeoutError", ms } }
36
+ });
37
+ }, ms);
38
+ const runtime = _chunkGLE2WY7Zcjs.unsafeGetCurrentRuntime.call(void 0, );
39
+ fiber = runtime.fork(effect);
40
+ fiber.join((exit) => {
41
+ if (done) return;
42
+ done = true;
43
+ clock.clearTimeout(timerId);
44
+ cb(exit);
45
+ });
46
+ return () => {
47
+ if (done) return;
48
+ done = true;
49
+ clock.clearTimeout(timerId);
50
+ fiber.interrupt();
51
+ };
52
+ });
53
+ }
54
+ function retry(effect, policy) {
55
+ const shouldRetry = _nullishCoalesce(policy.shouldRetry, () => ( (() => true)));
56
+ const jitter2 = _nullishCoalesce(policy.jitter, () => ( "full"));
57
+ const maxElapsedMs = policy.maxElapsedMs;
58
+ const computeDelay = (attempt) => {
59
+ const exp = policy.baseDelayMs * Math.pow(2, attempt);
60
+ const capped = Math.min(exp, policy.maxDelayMs);
61
+ if (jitter2 === "none") return capped;
62
+ return Math.floor(Math.random() * capped);
63
+ };
64
+ const loop = (attempt, startedAt, clock) => _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
65
+ effect,
66
+ (error) => {
67
+ if (attempt >= policy.maxRetries) return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
68
+ if (!shouldRetry(error, attempt)) return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
69
+ if (maxElapsedMs !== void 0) {
70
+ const elapsed2 = clock.now() - startedAt;
71
+ if (elapsed2 >= maxElapsedMs) return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
72
+ }
73
+ const delay = computeDelay(attempt);
74
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, sleep(delay), () => loop(attempt + 1, startedAt, clock));
75
+ },
76
+ (value) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, value)
77
+ );
78
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
79
+ { _tag: "Sync", thunk: (env) => {
80
+ const clock = _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env);
81
+ return { clock, startedAt: clock.now() };
82
+ } },
83
+ ({ clock, startedAt }) => loop(0, startedAt, clock)
84
+ );
85
+ }
86
+ function retryN(effect, n) {
87
+ return retry(effect, {
88
+ maxRetries: n,
89
+ baseDelayMs: 0,
90
+ maxDelayMs: 0,
91
+ jitter: "none"
92
+ });
93
+ }
94
+ function retryWithBackoff(effect, opts = {}) {
95
+ return retry(effect, {
96
+ maxRetries: _nullishCoalesce(opts.maxRetries, () => ( 3)),
97
+ baseDelayMs: _nullishCoalesce(opts.baseDelayMs, () => ( 100)),
98
+ maxDelayMs: _nullishCoalesce(opts.maxDelayMs, () => ( 1e4)),
99
+ maxElapsedMs: opts.maxElapsedMs,
100
+ shouldRetry: opts.shouldRetry,
101
+ jitter: "full"
102
+ });
103
+ }
104
+
105
+ // src/core/runtime/schedule.ts
106
+ function recurs(n) {
107
+ return {
108
+ _tag: "Schedule",
109
+ initial: () => 0,
110
+ step: (count, _input) => {
111
+ const next = count + 1;
112
+ return [{ continue: next < n, delayMs: 0 }, next, next];
113
+ }
114
+ };
115
+ }
116
+ function forever() {
117
+ return {
118
+ _tag: "Schedule",
119
+ initial: () => 0,
120
+ step: (count) => {
121
+ const next = count + 1;
122
+ return [{ continue: true, delayMs: 0 }, next, next];
123
+ }
124
+ };
125
+ }
126
+ function never() {
127
+ return {
128
+ _tag: "Schedule",
129
+ initial: () => 0,
130
+ step: (count) => {
131
+ const next = count + 1;
132
+ return [{ continue: false, delayMs: 0 }, next, next];
133
+ }
134
+ };
135
+ }
136
+ function once() {
137
+ return {
138
+ _tag: "Schedule",
139
+ initial: () => 0,
140
+ step: (count) => {
141
+ const next = count + 1;
142
+ return [{ continue: count === 0, delayMs: 0 }, next, next];
143
+ }
144
+ };
145
+ }
146
+ function fixed(delayMs) {
147
+ const delay = normalizeDelay(delayMs);
148
+ return {
149
+ _tag: "Schedule",
150
+ initial: () => 0,
151
+ step: (count, _input) => {
152
+ return [{ continue: true, delayMs: delay }, count + 1, count + 1];
153
+ }
154
+ };
155
+ }
156
+ var spaced = fixed;
157
+ function exponential(baseMs, maxMs = Infinity) {
158
+ const base = Math.max(0, baseMs);
159
+ const cap = normalizeCap(maxMs);
160
+ return {
161
+ _tag: "Schedule",
162
+ initial: () => 0,
163
+ step: (count, _input) => {
164
+ const delay = Math.min(base * Math.pow(2, count), cap);
165
+ return [{ continue: true, delayMs: delay }, count + 1, count + 1];
166
+ }
167
+ };
168
+ }
169
+ function linear(baseMs, maxMs = Infinity) {
170
+ const base = Math.max(0, baseMs);
171
+ const cap = normalizeCap(maxMs);
172
+ return {
173
+ _tag: "Schedule",
174
+ initial: () => 0,
175
+ step: (count, _input) => {
176
+ const next = count + 1;
177
+ return [{ continue: true, delayMs: Math.min(base * next, cap) }, next, next];
178
+ }
179
+ };
180
+ }
181
+ function fibonacci(baseMs, maxMs = Infinity) {
182
+ const base = Math.max(0, baseMs);
183
+ const cap = normalizeCap(maxMs);
184
+ return {
185
+ _tag: "Schedule",
186
+ initial: () => ({ prev: 0, curr: 1, count: 0 }),
187
+ step: (state, _input) => {
188
+ const delay = Math.min(base * state.curr, cap);
189
+ const next = {
190
+ prev: state.curr,
191
+ curr: state.prev + state.curr,
192
+ count: state.count + 1
193
+ };
194
+ return [{ continue: true, delayMs: delay }, next, state.count + 1];
195
+ }
196
+ };
197
+ }
198
+ function jittered(baseMs, maxMs = Infinity) {
199
+ return jitteredSchedule(exponential(baseMs, maxMs), { factor: 1 });
200
+ }
201
+ function elapsed(maxMs) {
202
+ const max = Math.max(0, maxMs);
203
+ return {
204
+ _tag: "Schedule",
205
+ initial: (context) => nowFromContext(context),
206
+ step: (startedAt, _input, context) => {
207
+ const el = nowFromContext(context) - startedAt;
208
+ return [{ continue: el < max, delayMs: 0 }, startedAt, el];
209
+ }
210
+ };
211
+ }
212
+ function whileInput(pred) {
213
+ return {
214
+ _tag: "Schedule",
215
+ initial: () => void 0,
216
+ step: (_state, input) => {
217
+ return [{ continue: pred(input), delayMs: 0 }, void 0, input];
218
+ }
219
+ };
220
+ }
221
+ function untilInput(pred) {
222
+ return {
223
+ _tag: "Schedule",
224
+ initial: () => void 0,
225
+ step: (_state, input) => {
226
+ return [{ continue: !pred(input), delayMs: 0 }, void 0, input];
227
+ }
228
+ };
229
+ }
230
+ function take(schedule, n) {
231
+ const limit = Math.max(0, Math.floor(n));
232
+ return {
233
+ _tag: "Schedule",
234
+ name: schedule.name,
235
+ initial: (context) => ({ inner: schedule.initial(context), count: 0 }),
236
+ step: (state, input, context) => {
237
+ if (state.count >= limit) return [{ continue: false, delayMs: 0 }, state, void 0];
238
+ const [decision, nextInner, output] = schedule.step(state.inner, input, context);
239
+ const nextState = { inner: nextInner, count: state.count + 1 };
240
+ return [{ continue: decision.continue && state.count + 1 < limit, delayMs: decision.delayMs }, nextState, output];
241
+ }
242
+ };
243
+ }
244
+ function map(schedule, f) {
245
+ return {
246
+ _tag: "Schedule",
247
+ name: schedule.name,
248
+ initial: schedule.initial,
249
+ step: (state, input, context) => {
250
+ const [decision, nextState, output] = schedule.step(state, input, context);
251
+ return [decision, nextState, f(output)];
252
+ }
253
+ };
254
+ }
255
+ function contramap(schedule, f) {
256
+ return {
257
+ _tag: "Schedule",
258
+ name: schedule.name,
259
+ initial: schedule.initial,
260
+ step: (state, input, context) => schedule.step(state, f(input), context)
261
+ };
262
+ }
263
+ function jitteredSchedule(schedule, options = {}) {
264
+ const factor = typeof options === "number" ? options : _nullishCoalesce(options.factor, () => ( 1));
265
+ const random = typeof options === "number" ? Math.random : _nullishCoalesce(options.random, () => ( Math.random));
266
+ const spread = Math.max(0, factor);
267
+ return {
268
+ _tag: "Schedule",
269
+ name: schedule.name,
270
+ initial: schedule.initial,
271
+ step: (state, input, context) => {
272
+ const [decision, nextState, output] = schedule.step(state, input, context);
273
+ if (!decision.continue || decision.delayMs <= 0 || spread === 0) {
274
+ return [decision, nextState, output];
275
+ }
276
+ const delay = spread >= 1 ? Math.floor(random() * decision.delayMs) : Math.floor(decision.delayMs * (1 - spread + random() * spread * 2));
277
+ return [{ ...decision, delayMs: Math.max(0, delay) }, nextState, output];
278
+ }
279
+ };
280
+ }
281
+ var jitter = jitteredSchedule;
282
+ function windowed(schedule, windowMs, clock) {
283
+ const window = Math.max(0, windowMs);
284
+ return {
285
+ _tag: "Schedule",
286
+ name: schedule.name,
287
+ initial: (context) => ({ inner: schedule.initial(context), windowStartedAt: clockNow(clock, context) }),
288
+ step: (state, input, context) => {
289
+ const now = clockNow(clock, context);
290
+ const shouldReset = window > 0 && now - state.windowStartedAt > window;
291
+ const inner = shouldReset ? schedule.initial(context) : state.inner;
292
+ const windowStartedAt = shouldReset ? now : state.windowStartedAt;
293
+ const [decision, nextInner, output] = schedule.step(inner, input, context);
294
+ return [decision, { inner: nextInner, windowStartedAt }, output];
295
+ }
296
+ };
297
+ }
298
+ function maxDelay(schedule, maxMs) {
299
+ const cap = Math.max(0, maxMs);
300
+ return {
301
+ _tag: "Schedule",
302
+ name: schedule.name,
303
+ initial: schedule.initial,
304
+ step: (state, input, context) => {
305
+ const [decision, nextState, output] = schedule.step(state, input, context);
306
+ return [{ ...decision, delayMs: Math.min(decision.delayMs, cap) }, nextState, output];
307
+ }
308
+ };
309
+ }
310
+ function maxElapsed(schedule, maxMs) {
311
+ const max = Math.max(0, maxMs);
312
+ return {
313
+ _tag: "Schedule",
314
+ name: schedule.name,
315
+ initial: (context) => ({ inner: schedule.initial(context), startedAt: nowFromContext(context) }),
316
+ step: (state, input, context) => {
317
+ const now = nowFromContext(context);
318
+ const elapsedMs = Math.max(0, now - state.startedAt);
319
+ if (elapsedMs >= max) return [{ continue: false, delayMs: 0 }, state, void 0];
320
+ const [decision, nextInner, output] = schedule.step(state.inner, input, context);
321
+ const remaining = Math.max(0, max - elapsedMs);
322
+ return [
323
+ { ...decision, continue: decision.continue && remaining > 0, delayMs: Math.min(decision.delayMs, remaining) },
324
+ { inner: nextInner, startedAt: state.startedAt },
325
+ output
326
+ ];
327
+ }
328
+ };
329
+ }
330
+ var upTo = maxElapsed;
331
+ function whileOutput(schedule, pred) {
332
+ return {
333
+ _tag: "Schedule",
334
+ name: schedule.name,
335
+ initial: schedule.initial,
336
+ step: (state, input, context) => {
337
+ const [decision, nextState, output] = schedule.step(state, input, context);
338
+ return [{ ...decision, continue: decision.continue && pred(output) }, nextState, output];
339
+ }
340
+ };
341
+ }
342
+ function untilOutput(schedule, pred) {
343
+ return whileOutput(schedule, (output) => !pred(output));
344
+ }
345
+ function named(name, schedule) {
346
+ return {
347
+ _tag: "Schedule",
348
+ name,
349
+ initial: schedule.initial,
350
+ step: schedule.step
351
+ };
352
+ }
353
+ function tapDecision(schedule, tap) {
354
+ return {
355
+ _tag: "Schedule",
356
+ name: schedule.name,
357
+ initial: schedule.initial,
358
+ step: (state, input, context) => {
359
+ const [decision, nextState, output] = schedule.step(state, input, context);
360
+ const enriched = enrichDecision(decision, context, schedule.name);
361
+ safeObserve(tap, {
362
+ name: enriched.name,
363
+ input,
364
+ output,
365
+ decision: enriched,
366
+ attempt: _nullishCoalesce(_nullishCoalesce(enriched.attempt, () => ( _optionalChain([context, 'optionalAccess', _3 => _3.attempt]))), () => ( 0)),
367
+ elapsedMs: _nullishCoalesce(enriched.elapsedMs, () => ( elapsedFromContext(context))),
368
+ state,
369
+ nextState,
370
+ timestamp: wallClockNow()
371
+ });
372
+ return [decision, nextState, output];
373
+ }
374
+ };
375
+ }
376
+ function andThen(first, second) {
377
+ return {
378
+ _tag: "Schedule",
379
+ name: _nullishCoalesce(first.name, () => ( second.name)),
380
+ initial: (context) => ({ phase: "first", inner: first.initial(context) }),
381
+ step: (state, input, context) => {
382
+ if (state.phase === "first") {
383
+ const [decision2, nextInner2, output2] = first.step(state.inner, input, context);
384
+ if (decision2.continue) {
385
+ return [decision2, { phase: "first", inner: nextInner2 }, output2];
386
+ }
387
+ return [{ continue: true, delayMs: decision2.delayMs }, { phase: "second", inner: second.initial(context) }, output2];
388
+ }
389
+ const [decision, nextInner, output] = second.step(state.inner, input, context);
390
+ return [decision, { phase: "second", inner: nextInner }, output];
391
+ }
392
+ };
393
+ }
394
+ function intersect(left, right) {
395
+ return {
396
+ _tag: "Schedule",
397
+ name: _nullishCoalesce(left.name, () => ( right.name)),
398
+ initial: (context) => ({ left: left.initial(context), right: right.initial(context) }),
399
+ step: (state, input, context) => {
400
+ const [ld, ls, lo] = left.step(state.left, input, context);
401
+ const [rd, rs, ro] = right.step(state.right, input, context);
402
+ const cont = ld.continue && rd.continue;
403
+ const delay = Math.max(ld.delayMs, rd.delayMs);
404
+ return [{ continue: cont, delayMs: delay }, { left: ls, right: rs }, [lo, ro]];
405
+ }
406
+ };
407
+ }
408
+ function union(left, right) {
409
+ return {
410
+ _tag: "Schedule",
411
+ name: _nullishCoalesce(left.name, () => ( right.name)),
412
+ initial: (context) => ({ left: left.initial(context), right: right.initial(context) }),
413
+ step: (state, input, context) => {
414
+ const [ld, ls, lo] = left.step(state.left, input, context);
415
+ const [rd, rs, ro] = right.step(state.right, input, context);
416
+ const cont = ld.continue || rd.continue;
417
+ const delay = Math.min(ld.delayMs, rd.delayMs);
418
+ return [{ continue: cont, delayMs: delay }, { left: ls, right: rs }, [lo, ro]];
419
+ }
420
+ };
421
+ }
422
+ function makeScheduleDriver(schedule, options = {}) {
423
+ const clock = _nullishCoalesce(options.clock, () => ( _chunkGLE2WY7Zcjs.liveClock));
424
+ let startedAtMs = _nullishCoalesce(options.startedAtMs, () => ( clock.now()));
425
+ let attempt = 0;
426
+ let lastDecision;
427
+ let state = schedule.initial(makeContext(clock, startedAtMs, attempt, _nullishCoalesce(options.name, () => ( schedule.name))));
428
+ return {
429
+ next: (input) => {
430
+ const currentState = state;
431
+ const context = makeContext(clock, startedAtMs, attempt, _nullishCoalesce(options.name, () => ( schedule.name)));
432
+ const [decision, nextState, output] = schedule.step(currentState, input, context);
433
+ const enriched = enrichDecision(decision, context, schedule.name);
434
+ state = nextState;
435
+ const result = {
436
+ continue: enriched.continue,
437
+ delayMs: enriched.delayMs,
438
+ output,
439
+ decision: enriched,
440
+ attempt: _nullishCoalesce(enriched.attempt, () => ( attempt)),
441
+ elapsedMs: _nullishCoalesce(enriched.elapsedMs, () => ( elapsedFromContext(context))),
442
+ state: nextState
443
+ };
444
+ lastDecision = result;
445
+ const event = {
446
+ name: enriched.name,
447
+ input,
448
+ output,
449
+ decision: enriched,
450
+ attempt: result.attempt,
451
+ elapsedMs: result.elapsedMs,
452
+ state: currentState,
453
+ nextState,
454
+ timestamp: wallClockNow()
455
+ };
456
+ observeDriverDecision(event, options);
457
+ attempt++;
458
+ return result;
459
+ },
460
+ reset: () => {
461
+ startedAtMs = clock.now();
462
+ attempt = 0;
463
+ lastDecision = void 0;
464
+ state = schedule.initial(makeContext(clock, startedAtMs, attempt, _nullishCoalesce(options.name, () => ( schedule.name))));
465
+ },
466
+ snapshot: () => ({
467
+ name: _nullishCoalesce(options.name, () => ( schedule.name)),
468
+ attempt,
469
+ elapsedMs: Math.max(0, clock.now() - startedAtMs),
470
+ state,
471
+ last: lastDecision
472
+ }),
473
+ state: () => state,
474
+ last: () => lastDecision
475
+ };
476
+ }
477
+ var scheduleDriver = makeScheduleDriver;
478
+ function runSchedule(schedule, inputs, options = {}) {
479
+ const driver = makeScheduleDriver(schedule, options);
480
+ const decisions = [];
481
+ for (const input of inputs) {
482
+ const next = driver.next(input);
483
+ decisions.push(next);
484
+ if (!next.continue) break;
485
+ }
486
+ return decisions;
487
+ }
488
+ function driverFromRuntime(schedule, options = {}) {
489
+ return _chunkMVGUEJ5Zcjs.Async.sync((env) => makeScheduleDriver(schedule, {
490
+ ...options,
491
+ clock: _nullishCoalesce(options.clock, () => ( _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env)))
492
+ }));
493
+ }
494
+ function retryWithSchedule(effect, schedule, options = {}) {
495
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, driverFromRuntime(schedule, options), (driver) => {
496
+ const loop = () => _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
497
+ effect,
498
+ (error) => {
499
+ const next = driver.next(error);
500
+ if (!next.continue) return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
501
+ if (next.delayMs <= 0) return loop();
502
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, sleep(next.delayMs), () => loop());
503
+ },
504
+ (value) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, value)
505
+ );
506
+ return loop();
507
+ });
508
+ }
509
+ var retry2 = retryWithSchedule;
510
+ function repeatWithSchedule(effect, schedule, options = {}) {
511
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, driverFromRuntime(schedule, options), (driver) => {
512
+ const loop = (lastValue) => {
513
+ const next = driver.next(lastValue);
514
+ if (!next.continue) return _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, lastValue);
515
+ if (next.delayMs <= 0) {
516
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
517
+ effect,
518
+ (error) => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error),
519
+ (value) => loop(value)
520
+ );
521
+ }
522
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
523
+ sleep(next.delayMs),
524
+ () => _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
525
+ effect,
526
+ (error) => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error),
527
+ (value) => loop(value)
528
+ )
529
+ );
530
+ };
531
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
532
+ effect,
533
+ (error) => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error),
534
+ (value) => loop(value)
535
+ );
536
+ });
537
+ }
538
+ var repeat = repeatWithSchedule;
539
+ var poll = repeatWithSchedule;
540
+ function normalizeDelay(ms) {
541
+ if (!Number.isFinite(ms)) return 0;
542
+ return Math.max(0, Math.floor(ms));
543
+ }
544
+ function normalizeCap(ms) {
545
+ if (ms === Infinity) return Infinity;
546
+ return normalizeDelay(ms);
547
+ }
548
+ function defaultClock() {
549
+ return _chunkGLE2WY7Zcjs.liveClock.now();
550
+ }
551
+ function nowFromContext(context) {
552
+ return _nullishCoalesce(_optionalChain([context, 'optionalAccess', _4 => _4.clock, 'access', _5 => _5.now, 'call', _6 => _6()]), () => ( defaultClock()));
553
+ }
554
+ function clockNow(clock, context) {
555
+ return clock ? clock() : nowFromContext(context);
556
+ }
557
+ function elapsedFromContext(context) {
558
+ if (!context) return 0;
559
+ return Math.max(0, context.clock.now() - context.startedAtMs);
560
+ }
561
+ function makeContext(clock, startedAtMs, attempt, name) {
562
+ return { clock, startedAtMs, attempt, name };
563
+ }
564
+ function enrichDecision(decision, context, fallbackName) {
565
+ const delayMs = normalizeDelay(decision.delayMs);
566
+ return {
567
+ ...decision,
568
+ continue: decision.continue,
569
+ delayMs,
570
+ attempt: _nullishCoalesce(decision.attempt, () => ( _optionalChain([context, 'optionalAccess', _7 => _7.attempt]))),
571
+ elapsedMs: _nullishCoalesce(decision.elapsedMs, () => ( elapsedFromContext(context))),
572
+ name: _nullishCoalesce(_nullishCoalesce(decision.name, () => ( _optionalChain([context, 'optionalAccess', _8 => _8.name]))), () => ( fallbackName))
573
+ };
574
+ }
575
+ function wallClockNow() {
576
+ return Date.now();
577
+ }
578
+ function safeObserve(observer, event) {
579
+ try {
580
+ observer(event);
581
+ } catch (e) {
582
+ }
583
+ }
584
+ function observeDriverDecision(event, options) {
585
+ if (options.onDecision) safeObserve(options.onDecision, event);
586
+ if (!options.hooks) return;
587
+ try {
588
+ options.hooks.emit({
589
+ type: "schedule.decision",
590
+ name: event.name,
591
+ attempt: event.attempt,
592
+ elapsedMs: event.elapsedMs,
593
+ delayMs: event.decision.delayMs,
594
+ continue: event.decision.continue,
595
+ reason: event.decision.reason,
596
+ ...options.captureInput ? { input: event.input } : {},
597
+ ...options.captureOutput ? { output: event.output } : {}
598
+ }, _nullishCoalesce(options.emitContext, () => ( {})));
599
+ } catch (e2) {
600
+ }
601
+ }
602
+ var Schedule = Object.freeze({
603
+ driver: makeScheduleDriver,
604
+ run: runSchedule,
605
+ recurs,
606
+ forever,
607
+ never,
608
+ once,
609
+ fixed,
610
+ spaced,
611
+ linear,
612
+ exponential,
613
+ fibonacci,
614
+ jittered,
615
+ jitteredSchedule,
616
+ jitter,
617
+ elapsed,
618
+ whileInput,
619
+ untilInput,
620
+ whileOutput,
621
+ untilOutput,
622
+ take,
623
+ map,
624
+ contramap,
625
+ maxDelay,
626
+ maxElapsed,
627
+ upTo,
628
+ windowed,
629
+ named,
630
+ tapDecision,
631
+ andThen,
632
+ intersect,
633
+ union,
634
+ retry: retryWithSchedule,
635
+ repeat: repeatWithSchedule,
636
+ poll: repeatWithSchedule
637
+ });
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+ exports.sleep = sleep; exports.timeout = timeout; exports.retry = retry; exports.retryN = retryN; exports.retryWithBackoff = retryWithBackoff; exports.recurs = recurs; exports.forever = forever; exports.never = never; exports.once = once; exports.fixed = fixed; exports.spaced = spaced; exports.exponential = exponential; exports.linear = linear; exports.fibonacci = fibonacci; exports.jittered = jittered; exports.elapsed = elapsed; exports.whileInput = whileInput; exports.untilInput = untilInput; exports.take = take; exports.map = map; exports.contramap = contramap; exports.jitteredSchedule = jitteredSchedule; exports.jitter = jitter; exports.windowed = windowed; exports.maxDelay = maxDelay; exports.maxElapsed = maxElapsed; exports.upTo = upTo; exports.whileOutput = whileOutput; exports.untilOutput = untilOutput; exports.named = named; exports.tapDecision = tapDecision; exports.andThen = andThen; exports.intersect = intersect; exports.union = union; exports.makeScheduleDriver = makeScheduleDriver; exports.scheduleDriver = scheduleDriver; exports.runSchedule = runSchedule; exports.retryWithSchedule = retryWithSchedule; exports.retry2 = retry2; exports.repeatWithSchedule = repeatWithSchedule; exports.repeat = repeat; exports.poll = poll; exports.Schedule = Schedule;