brass-runtime 1.17.0 → 1.18.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 (120) hide show
  1. package/README.md +36 -3
  2. package/dist/agent/cli/main.cjs +31 -32
  3. package/dist/agent/cli/main.js +3 -4
  4. package/dist/agent/cli/main.mjs +3 -4
  5. package/dist/agent/index.cjs +4 -5
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -4
  8. package/dist/agent/index.mjs +3 -4
  9. package/dist/{chunk-7X3K5RMS.js → chunk-22HZQG5F.js} +9 -11
  10. package/dist/{chunk-GLE2WY7Z.cjs → chunk-2JHJ4YHS.cjs} +417 -124
  11. package/dist/{chunk-Q2I37RP3.cjs → chunk-2OW6IFY2.cjs} +44 -323
  12. package/dist/{chunk-7ZPEZ57L.cjs → chunk-5LC7V2OZ.cjs} +18 -20
  13. package/dist/{chunk-AGR5B2BC.cjs → chunk-5RZ7YITF.cjs} +564 -12
  14. package/dist/{chunk-DNFJLJMW.mjs → chunk-6MLAZPBL.mjs} +48 -24
  15. package/dist/{chunk-EJ6BPYVR.mjs → chunk-6V2AWT4R.mjs} +1 -1
  16. package/dist/{chunk-3AYM6WPJ.js → chunk-7DU7IQHK.js} +20 -299
  17. package/dist/{chunk-SK7UZRNI.mjs → chunk-7GBJYOX7.mjs} +528 -23
  18. package/dist/chunk-7TKI527D.cjs +123 -0
  19. package/dist/{chunk-52OB2ROS.js → chunk-7VQLEN37.js} +2 -4
  20. package/dist/{chunk-KH4SYAOS.mjs → chunk-B5FKOLTB.mjs} +20 -299
  21. package/dist/{chunk-FHQGHPMO.mjs → chunk-BC6Q6BCO.mjs} +2 -4
  22. package/dist/{chunk-4P2HHGAX.mjs → chunk-COOW7BJX.mjs} +32 -11
  23. package/dist/{chunk-2HQTDLHF.mjs → chunk-EEN5OTCR.mjs} +555 -3
  24. package/dist/{chunk-KZJQ723N.cjs → chunk-EICAJDNX.cjs} +13 -15
  25. package/dist/chunk-ELIECDYN.cjs +33 -0
  26. package/dist/{chunk-GYM3LLGS.mjs → chunk-H626ZTDZ.mjs} +399 -106
  27. package/dist/{chunk-C3MDXTRZ.js → chunk-HCJ4S3YB.js} +48 -24
  28. package/dist/{chunk-7JIJOVCT.js → chunk-IPSMXUWA.js} +2 -4
  29. package/dist/{chunk-4ROBZFL6.cjs → chunk-J6DUHITE.cjs} +6 -8
  30. package/dist/{chunk-6RY2FFN4.mjs → chunk-JWIEMBE6.mjs} +9 -11
  31. package/dist/{chunk-PD4EJTQC.cjs → chunk-KNTJ7FQB.cjs} +5 -5
  32. package/dist/chunk-KTGDLBLD.mjs +123 -0
  33. package/dist/chunk-LSYQ3C2M.js +33 -0
  34. package/dist/{chunk-RKGKFN2A.js → chunk-OW5VHAOE.js} +1 -1
  35. package/dist/{chunk-EOC4UHBS.mjs → chunk-RBHNOKH4.mjs} +2 -2
  36. package/dist/{chunk-6IXXWIUM.js → chunk-S4HXADU4.js} +555 -3
  37. package/dist/{chunk-FH2X7BVP.js → chunk-TTSPIU3U.js} +399 -106
  38. package/dist/{chunk-5QC7LRZ3.js → chunk-UAKAF32U.js} +2 -2
  39. package/dist/{chunk-CZIVE6NT.cjs → chunk-UUMKZJRJ.cjs} +48 -24
  40. package/dist/{chunk-MBEJI5HF.mjs → chunk-WCBNXPN6.mjs} +2 -4
  41. package/dist/{chunk-52PPNNI4.cjs → chunk-WGE2FEZE.cjs} +2 -2
  42. package/dist/{chunk-WBGRHGBP.cjs → chunk-WI7GZF3B.cjs} +114 -93
  43. package/dist/chunk-WUDHOZIH.js +6234 -0
  44. package/dist/{chunk-F6XWZQY4.cjs → chunk-WVSZOPGQ.cjs} +583 -78
  45. package/dist/chunk-XPIMJQYS.cjs +6234 -0
  46. package/dist/{chunk-VWIPB6I5.js → chunk-YGR2IN4R.js} +528 -23
  47. package/dist/chunk-YM3EDNYD.js +123 -0
  48. package/dist/chunk-YWLLH27R.mjs +33 -0
  49. package/dist/{chunk-BKK77SBA.js → chunk-YZ5LQ32F.js} +32 -11
  50. package/dist/chunk-Z3ZZMQUZ.mjs +6234 -0
  51. package/dist/core/index.cjs +37 -9
  52. package/dist/core/index.d.ts +19 -152
  53. package/dist/core/index.js +86 -58
  54. package/dist/core/index.mjs +86 -58
  55. package/dist/defaultClient-Cid0JoUR.d.ts +1648 -0
  56. package/dist/{effect-DIUHZ9IN.d.ts → effect-DnGUuhw6.d.ts} +22 -1
  57. package/dist/http/index.cjs +206 -59
  58. package/dist/http/index.d.ts +55 -819
  59. package/dist/http/index.js +220 -73
  60. package/dist/http/index.mjs +220 -73
  61. package/dist/http/testing.cjs +31 -10
  62. package/dist/http/testing.d.ts +16 -5
  63. package/dist/http/testing.js +29 -8
  64. package/dist/http/testing.mjs +29 -8
  65. package/dist/index.cjs +116 -88
  66. package/dist/index.d.ts +9 -8
  67. package/dist/index.js +87 -59
  68. package/dist/index.mjs +87 -59
  69. package/dist/{schedule-CK3Ml_7p.d.ts → layer-D2LFcBVx.d.ts} +176 -2
  70. package/dist/observability/index.cjs +20 -7
  71. package/dist/observability/index.d.ts +32 -8
  72. package/dist/observability/index.js +19 -6
  73. package/dist/observability/index.mjs +19 -6
  74. package/dist/perf/cli.cjs +26 -28
  75. package/dist/perf/cli.js +11 -13
  76. package/dist/perf/cli.mjs +11 -13
  77. package/dist/perf/index.cjs +13 -15
  78. package/dist/perf/index.js +11 -13
  79. package/dist/perf/index.mjs +11 -13
  80. package/dist/schema/index.cjs +2 -2
  81. package/dist/schema/index.js +1 -1
  82. package/dist/schema/index.mjs +1 -1
  83. package/dist/{server-D6JZ15_e.d.ts → server-Bf1zNYZk.d.ts} +5 -5
  84. package/dist/{stream-B4oK9JFP.d.ts → stream-I7bkvF7a.d.ts} +1 -1
  85. package/dist/{tracer-Hwt1cl7h.d.ts → tracer-DF83nLn6.d.ts} +2 -2
  86. package/dist/{tracing-DqbTKGcf.d.ts → tracing-CWV4gT0u.d.ts} +1 -1
  87. package/docs/README.md +2 -0
  88. package/docs/ai/PUBLIC_API.md +28 -7
  89. package/docs/articles/brass-runtime-http-observability.md +467 -0
  90. package/docs/frameworks/angular.md +51 -0
  91. package/docs/frameworks/express.md +58 -0
  92. package/docs/frameworks/fastify.md +49 -0
  93. package/docs/frameworks/nestjs.md +53 -0
  94. package/docs/frameworks/nextjs.md +55 -0
  95. package/docs/frameworks/react.md +44 -0
  96. package/docs/frameworks/vanilla.md +56 -0
  97. package/docs/guides/layers.md +130 -0
  98. package/docs/http-recipes.md +31 -1
  99. package/docs/http.md +50 -1
  100. package/docs/observability.md +132 -0
  101. package/docs/performance-profiler.md +6 -2
  102. package/docs/recipes/layers.md +46 -2
  103. package/docs/recipes/testing.md +25 -0
  104. package/package.json +6 -2
  105. package/dist/chunk-3LOYJFRR.cjs +0 -300
  106. package/dist/chunk-3Y2RIUMM.js +0 -300
  107. package/dist/chunk-5EC274J5.cjs +0 -2874
  108. package/dist/chunk-5VRJNBLZ.mjs +0 -2874
  109. package/dist/chunk-62AZW6UT.cjs +0 -313
  110. package/dist/chunk-74ZTY6CP.js +0 -2871
  111. package/dist/chunk-7CMJS3QE.mjs +0 -2871
  112. package/dist/chunk-A2OM6NEH.mjs +0 -194
  113. package/dist/chunk-B33ICAKP.js +0 -313
  114. package/dist/chunk-JF5WGYJJ.cjs +0 -194
  115. package/dist/chunk-KN32XNTH.mjs +0 -313
  116. package/dist/chunk-KQLYONSE.cjs +0 -2871
  117. package/dist/chunk-L2SYFEBS.js +0 -194
  118. package/dist/chunk-MIIYDLGM.js +0 -2874
  119. package/dist/chunk-PWC3RBQE.mjs +0 -300
  120. package/dist/client-CZHU674n.d.ts +0 -820
@@ -29,6 +29,7 @@ function formatConfigError(error) {
29
29
  }
30
30
  var ok = (data) => ({ success: true, data });
31
31
  var fail = (issues) => ({ success: false, issues });
32
+ var EMPTY_PATH = Object.freeze([]);
32
33
  var receivedKind = (value) => {
33
34
  if (value === null) return "null";
34
35
  if (value === void 0) return "undefined";
@@ -37,12 +38,16 @@ var receivedKind = (value) => {
37
38
  return typeof value;
38
39
  };
39
40
  var pathLabel = (path) => path.length === 0 ? "$" : path.reduce((acc, part) => typeof part === "number" ? `${acc}[${part}]` : `${acc}.${part}`, "$");
40
- var makeSchemaIssue = (path, expected, received, message) => ({
41
- path,
42
- expected,
43
- received: receivedKind(received),
44
- message: message ?? `Expected ${expected} at ${pathLabel(path)}, received ${receivedKind(received)}`
45
- });
41
+ var makeSchemaIssue = (path, expected, received, message) => {
42
+ const issuePath = path.length === 0 ? EMPTY_PATH : [...path];
43
+ const receivedLabel = receivedKind(received);
44
+ return {
45
+ path: issuePath,
46
+ expected,
47
+ received: receivedLabel,
48
+ message: message ?? `Expected ${expected} at ${pathLabel(issuePath)}, received ${receivedLabel}`
49
+ };
50
+ };
46
51
  function formatIssues(issues) {
47
52
  if (issues.length === 0) return "Validation failed";
48
53
  const preview = issues.slice(0, 3).map((issue) => `${pathLabel(issue.path)}: ${issue.message}`).join("; ");
@@ -55,9 +60,9 @@ function makeSchema(kind, isOptional, parser, name) {
55
60
  name,
56
61
  isOptional,
57
62
  _parse: parser,
58
- safeParse: (input) => parser(input, []),
63
+ safeParse: (input) => parser(input, EMPTY_PATH),
59
64
  parse: (input) => {
60
- const result = parser(input, []);
65
+ const result = parser(input, EMPTY_PATH);
61
66
  if (result.success) return result.data;
62
67
  throw new SchemaValidationException(result.issues);
63
68
  },
@@ -212,50 +217,65 @@ function arraySchema(item) {
212
217
  return makeSchema("array", false, (input, path) => {
213
218
  if (!Array.isArray(input)) return fail([makeSchemaIssue(path, "array", input)]);
214
219
  const out = [];
215
- const issues = [];
216
- input.forEach((value, index) => {
217
- const result = item._parse(value, [...path, index]);
220
+ const childPath = path.length === 0 ? [] : [...path];
221
+ let issues;
222
+ for (let index = 0; index < input.length; index += 1) {
223
+ if (!(index in input)) continue;
224
+ childPath.push(index);
225
+ const result = item._parse(input[index], childPath);
226
+ childPath.pop();
218
227
  if (result.success) {
219
228
  out.push(result.data);
220
229
  } else {
230
+ issues ??= [];
221
231
  issues.push(...result.issues);
222
232
  }
223
- });
224
- return issues.length > 0 ? fail(issues) : ok(out);
233
+ }
234
+ return issues ? fail(issues) : ok(out);
225
235
  });
226
236
  }
227
237
  function objectSchema(shape, options = {}) {
228
238
  const unknownKeys = options.unknownKeys ?? "strip";
239
+ const shapeEntries = Object.entries(shape);
240
+ const knownKeys = unknownKeys === "strict" ? new Set(shapeEntries.map(([key]) => key)) : void 0;
229
241
  return makeSchema("object", false, (input, path) => {
230
242
  if (typeof input !== "object" || input === null || Array.isArray(input)) {
231
243
  return fail([makeSchemaIssue(path, options.name ?? "object", input)]);
232
244
  }
233
245
  const source = input;
234
246
  const out = unknownKeys === "passthrough" ? { ...source } : {};
235
- const issues = [];
236
- const knownKeys = new Set(Object.keys(shape));
237
- for (const [key, fieldSchema] of Object.entries(shape)) {
247
+ const childPath = path.length === 0 ? [] : [...path];
248
+ let issues;
249
+ for (const [key, fieldSchema] of shapeEntries) {
250
+ childPath.push(key);
238
251
  if (!(key in source)) {
239
252
  if (!fieldSchema.isOptional) {
240
- issues.push(makeSchemaIssue([...path, key], fieldSchema.name ?? fieldSchema.kind, void 0, "Required field is missing"));
253
+ issues ??= [];
254
+ issues.push(makeSchemaIssue(childPath, fieldSchema.name ?? fieldSchema.kind, void 0, "Required field is missing"));
241
255
  }
256
+ childPath.pop();
242
257
  continue;
243
258
  }
244
- const result = fieldSchema._parse(source[key], [...path, key]);
259
+ const result = fieldSchema._parse(source[key], childPath);
260
+ childPath.pop();
245
261
  if (result.success) {
246
262
  out[key] = result.data;
247
263
  } else {
264
+ issues ??= [];
248
265
  issues.push(...result.issues);
249
266
  }
250
267
  }
251
- if (unknownKeys === "strict") {
268
+ if (knownKeys) {
252
269
  for (const key of Object.keys(source)) {
253
270
  if (!knownKeys.has(key)) {
254
- issues.push(makeSchemaIssue([...path, key], "known key", source[key], "Unknown key is not allowed"));
271
+ childPath.push(key);
272
+ issues ??= [];
273
+ issues.push(makeSchemaIssue(childPath, "known key", source[key], "Unknown key is not allowed"));
274
+ childPath.pop();
255
275
  }
256
276
  }
257
277
  }
258
- return issues.length > 0 ? fail(issues) : ok(out);
278
+ return issues ? fail(issues) : ok(out);
259
279
  }, options.name);
260
280
  }
261
281
  function recordSchema(valueSchema) {
@@ -264,16 +284,20 @@ function recordSchema(valueSchema) {
264
284
  return fail([makeSchemaIssue(path, "record", input)]);
265
285
  }
266
286
  const out = {};
267
- const issues = [];
287
+ const childPath = path.length === 0 ? [] : [...path];
288
+ let issues;
268
289
  for (const [key, value] of Object.entries(input)) {
269
- const result = valueSchema._parse(value, [...path, key]);
290
+ childPath.push(key);
291
+ const result = valueSchema._parse(value, childPath);
292
+ childPath.pop();
270
293
  if (result.success) {
271
294
  out[key] = result.data;
272
295
  } else {
296
+ issues ??= [];
273
297
  issues.push(...result.issues);
274
298
  }
275
299
  }
276
- return issues.length > 0 ? fail(issues) : ok(out);
300
+ return issues ? fail(issues) : ok(out);
277
301
  });
278
302
  }
279
303
  function unionSchema(members) {
@@ -2,13 +2,11 @@ import {
2
2
  raceWith
3
3
  } from "./chunk-UCUBNWM2.js";
4
4
  import {
5
- Scope
6
- } from "./chunk-L2SYFEBS.js";
7
- import {
5
+ Scope,
8
6
  getCurrentFiber,
9
7
  unsafeGetCurrentRuntime,
10
8
  unsafeRunFoldWithEnv
11
- } from "./chunk-FH2X7BVP.js";
9
+ } from "./chunk-TTSPIU3U.js";
12
10
  import {
13
11
  Cause,
14
12
  Exit,
@@ -3,10 +3,8 @@
3
3
  var _chunkSA6HUJVIcjs = require('./chunk-SA6HUJVI.cjs');
4
4
 
5
5
 
6
- var _chunkJF5WGYJJcjs = require('./chunk-JF5WGYJJ.cjs');
7
6
 
8
-
9
- var _chunkGLE2WY7Zcjs = require('./chunk-GLE2WY7Z.cjs');
7
+ var _chunk2JHJ4YHScjs = require('./chunk-2JHJ4YHS.cjs');
10
8
 
11
9
 
12
10
 
@@ -1916,7 +1914,7 @@ var runLoop = (state, scope, runStartedAt) => {
1916
1914
  })
1917
1915
  );
1918
1916
  };
1919
- var runAgent = (runtime, goal) => _chunkJF5WGYJJcjs.withScopeAsync.call(void 0,
1917
+ var runAgent = (runtime, goal) => _chunk2JHJ4YHScjs.withScopeAsync.call(void 0,
1920
1918
  runtime,
1921
1919
  (scope) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1922
1920
  nowMillis(),
@@ -2221,14 +2219,14 @@ var parseRipgrep = (stdout) => stdout.split("\n").filter(Boolean).map((line) =>
2221
2219
  return { path, line: Number(lineNo), text: rest.join(":") };
2222
2220
  });
2223
2221
  var makeNodeFileSystem = (shell) => ({
2224
- readFile: (path) => _chunkGLE2WY7Zcjs.fromPromiseAbortable.call(void 0,
2222
+ readFile: (path) => _chunk2JHJ4YHScjs.fromPromiseAbortable.call(void 0,
2225
2223
  async (signal) => {
2226
2224
  const { readFile } = await dynamicImport2("node:fs/promises");
2227
2225
  return readFile(path, { encoding: "utf8", signal });
2228
2226
  },
2229
2227
  (cause) => ({ _tag: "FsError", operation: "readFile", cause })
2230
2228
  ),
2231
- exists: (path) => _chunkGLE2WY7Zcjs.fromPromiseAbortable.call(void 0,
2229
+ exists: (path) => _chunk2JHJ4YHScjs.fromPromiseAbortable.call(void 0,
2232
2230
  async (signal) => {
2233
2231
  if (signal.aborted) return false;
2234
2232
  const { stat } = await dynamicImport2("node:fs/promises");
@@ -2609,7 +2607,7 @@ var loadNodeAgentConfig = async (options) => {
2609
2607
  // src/agent/llm/openAICompatible.ts
2610
2608
  var extractText = (json) => _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([json, 'optionalAccess', _150 => _150.choices, 'optionalAccess', _151 => _151[0], 'optionalAccess', _152 => _152.message, 'optionalAccess', _153 => _153.content]), () => ( _optionalChain([json, 'optionalAccess', _154 => _154.output_text]))), () => ( _optionalChain([json, 'optionalAccess', _155 => _155.content, 'optionalAccess', _156 => _156[0], 'optionalAccess', _157 => _157.text]))), () => ( JSON.stringify(json)));
2611
2609
  var makeOpenAICompatibleLLM = (config) => ({
2612
- complete: (request) => _chunkGLE2WY7Zcjs.fromPromiseAbortable.call(void 0,
2610
+ complete: (request) => _chunk2JHJ4YHScjs.fromPromiseAbortable.call(void 0,
2613
2611
  async (signal) => {
2614
2612
  const res = await fetch(config.endpoint, {
2615
2613
  method: "POST",
@@ -2701,7 +2699,7 @@ var responseErrorMessage = async (res) => {
2701
2699
  }
2702
2700
  };
2703
2701
  var makeGoogleGenerativeAILLM = (config) => ({
2704
- complete: (request) => _chunkGLE2WY7Zcjs.fromPromiseAbortable.call(void 0,
2702
+ complete: (request) => _chunk2JHJ4YHScjs.fromPromiseAbortable.call(void 0,
2705
2703
  async (signal) => {
2706
2704
  const res = await fetch(makeGenerateContentEndpoint(config), {
2707
2705
  method: "POST",
@@ -1,26 +1,24 @@
1
1
  import {
2
2
  makeFiberRef,
3
3
  makeRuntimeRecorder
4
- } from "./chunk-EOC4UHBS.mjs";
5
- import {
6
- makeDefaultHttpClient
7
- } from "./chunk-7CMJS3QE.mjs";
8
- import {
9
- makeHttp
10
- } from "./chunk-5VRJNBLZ.mjs";
4
+ } from "./chunk-RBHNOKH4.mjs";
11
5
  import {
12
6
  withHttpObservability
13
- } from "./chunk-SK7UZRNI.mjs";
7
+ } from "./chunk-7GBJYOX7.mjs";
14
8
  import {
15
9
  makeObservability
16
- } from "./chunk-4P2HHGAX.mjs";
10
+ } from "./chunk-COOW7BJX.mjs";
17
11
  import {
18
12
  EventBus
19
- } from "./chunk-EJ6BPYVR.mjs";
13
+ } from "./chunk-6V2AWT4R.mjs";
14
+ import {
15
+ makeDefaultHttpClient,
16
+ makeHttp
17
+ } from "./chunk-Z3ZZMQUZ.mjs";
20
18
  import {
21
19
  Runtime,
22
20
  Scheduler
23
- } from "./chunk-GYM3LLGS.mjs";
21
+ } from "./chunk-H626ZTDZ.mjs";
24
22
  import {
25
23
  asyncFlatMap,
26
24
  asyncSucceed,
@@ -1,10 +1,10 @@
1
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
2
 
3
- var _chunk52PPNNI4cjs = require('./chunk-52PPNNI4.cjs');
3
+ var _chunkWGE2FEZEcjs = require('./chunk-WGE2FEZE.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunkGLE2WY7Zcjs = require('./chunk-GLE2WY7Z.cjs');
7
+ var _chunk2JHJ4YHScjs = require('./chunk-2JHJ4YHS.cjs');
8
8
 
9
9
 
10
10
 
@@ -73,9 +73,9 @@ function fiberRefSnapshot() {
73
73
  return new Map(currentFiberRefs(false));
74
74
  }
75
75
  function currentFiberRefs(create) {
76
- const fiber = _chunkGLE2WY7Zcjs.getCurrentFiber.call(void 0, );
76
+ const fiber = _chunk2JHJ4YHScjs.getCurrentFiber.call(void 0, );
77
77
  if (!fiber) return void 0;
78
- fiber.fiberContext ??= { log: _chunkGLE2WY7Zcjs.emptyContext, trace: null };
78
+ fiber.fiberContext ??= { log: _chunk2JHJ4YHScjs.emptyContext, trace: null };
79
79
  if (!fiber.fiberContext.fiberRefs && create) fiber.fiberContext.fiberRefs = /* @__PURE__ */ new Map();
80
80
  return fiber.fiberContext.fiberRefs;
81
81
  }
@@ -98,7 +98,7 @@ function makeRuntimeRecorder(options = {}) {
98
98
  return out;
99
99
  };
100
100
  const emit = (ev, ctx) => {
101
- records[next] = _chunk52PPNNI4cjs.makeRuntimeEventRecord.call(void 0, ev, ctx, seq++);
101
+ records[next] = _chunkWGE2FEZEcjs.makeRuntimeEventRecord.call(void 0, ev, ctx, seq++);
102
102
  next = (next + 1) % capacity;
103
103
  if (size < capacity) size++;
104
104
  else dropped++;
@@ -0,0 +1,123 @@
1
+ import {
2
+ asyncFail,
3
+ asyncFold,
4
+ asyncSucceed
5
+ } from "./chunk-36I3M4UC.mjs";
6
+
7
+ // src/core/runtime/circuitBreaker.ts
8
+ function makeCircuitBreaker(config = {}) {
9
+ const failureThreshold = config.failureThreshold ?? 5;
10
+ const resetTimeoutMs = config.resetTimeoutMs ?? 3e4;
11
+ const successThreshold = config.successThreshold ?? 1;
12
+ const isFailure = config.isFailure ?? (() => true);
13
+ const onStateChange = config.onStateChange;
14
+ let currentState = "closed";
15
+ let consecutiveFailures = 0;
16
+ let consecutiveSuccesses = 0;
17
+ let openedAt = 0;
18
+ let totalRequests = 0;
19
+ let totalFailures = 0;
20
+ let totalSuccesses = 0;
21
+ let totalRejected = 0;
22
+ let lastFailureTime = null;
23
+ let lastSuccessTime = null;
24
+ const transition = (to) => {
25
+ if (currentState === to) return;
26
+ const from = currentState;
27
+ currentState = to;
28
+ onStateChange?.(from, to);
29
+ };
30
+ const onSuccess = () => {
31
+ totalSuccesses++;
32
+ lastSuccessTime = Date.now();
33
+ consecutiveFailures = 0;
34
+ if (currentState === "half-open") {
35
+ consecutiveSuccesses++;
36
+ if (consecutiveSuccesses >= successThreshold) {
37
+ consecutiveSuccesses = 0;
38
+ transition("closed");
39
+ }
40
+ }
41
+ };
42
+ const onFailure = (error) => {
43
+ if (!isFailure(error)) {
44
+ onSuccess();
45
+ return;
46
+ }
47
+ totalFailures++;
48
+ lastFailureTime = Date.now();
49
+ consecutiveSuccesses = 0;
50
+ consecutiveFailures++;
51
+ if (currentState === "half-open") {
52
+ openedAt = Date.now();
53
+ transition("open");
54
+ } else if (currentState === "closed" && consecutiveFailures >= failureThreshold) {
55
+ openedAt = Date.now();
56
+ transition("open");
57
+ }
58
+ };
59
+ const shouldAllow = () => {
60
+ switch (currentState) {
61
+ case "closed":
62
+ return true;
63
+ case "open": {
64
+ const elapsed = Date.now() - openedAt;
65
+ if (elapsed >= resetTimeoutMs) {
66
+ transition("half-open");
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+ case "half-open":
72
+ return true;
73
+ }
74
+ };
75
+ const protect = (effect) => {
76
+ totalRequests++;
77
+ if (!shouldAllow()) {
78
+ totalRejected++;
79
+ return asyncFail({
80
+ _tag: "CircuitBreakerOpen",
81
+ openSince: openedAt,
82
+ failures: consecutiveFailures
83
+ });
84
+ }
85
+ return asyncFold(
86
+ effect,
87
+ (error) => {
88
+ onFailure(error);
89
+ return asyncFail(error);
90
+ },
91
+ (value) => {
92
+ onSuccess();
93
+ return asyncSucceed(value);
94
+ }
95
+ );
96
+ };
97
+ const stats = () => ({
98
+ state: currentState,
99
+ failures: consecutiveFailures,
100
+ successes: consecutiveSuccesses,
101
+ totalRequests,
102
+ totalFailures,
103
+ totalSuccesses,
104
+ totalRejected,
105
+ lastFailureTime,
106
+ lastSuccessTime
107
+ });
108
+ const reset = () => {
109
+ consecutiveFailures = 0;
110
+ consecutiveSuccesses = 0;
111
+ transition("closed");
112
+ };
113
+ return {
114
+ state: () => currentState,
115
+ protect,
116
+ stats,
117
+ reset
118
+ };
119
+ }
120
+
121
+ export {
122
+ makeCircuitBreaker
123
+ };
@@ -0,0 +1,33 @@
1
+ import {
2
+ layerEffect,
3
+ makeServiceTag
4
+ } from "./chunk-S4HXADU4.js";
5
+ import {
6
+ Runtime
7
+ } from "./chunk-TTSPIU3U.js";
8
+ import {
9
+ asyncSync
10
+ } from "./chunk-UB4B6OFY.js";
11
+
12
+ // src/core/runtime/runtimeLayer.ts
13
+ var RuntimeService = makeServiceTag("Runtime");
14
+ function makeRuntimeLayer(env = {}, options = {}) {
15
+ const { tag = RuntimeService, ...runtimeOptions } = options;
16
+ return layerEffect(
17
+ tag,
18
+ (context) => asyncSync(
19
+ () => new Runtime({
20
+ ...runtimeOptions,
21
+ env: resolveRuntimeLayerEnv(env, context)
22
+ })
23
+ )
24
+ );
25
+ }
26
+ function resolveRuntimeLayerEnv(env, context) {
27
+ return typeof env === "function" ? env(context) : env;
28
+ }
29
+
30
+ export {
31
+ RuntimeService,
32
+ makeRuntimeLayer
33
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeBoundedRingBuffer
3
- } from "./chunk-FH2X7BVP.js";
3
+ } from "./chunk-TTSPIU3U.js";
4
4
  import {
5
5
  Cause
6
6
  } from "./chunk-UB4B6OFY.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  makeRuntimeEventRecord
3
- } from "./chunk-EJ6BPYVR.mjs";
3
+ } from "./chunk-6V2AWT4R.mjs";
4
4
  import {
5
5
  emptyContext,
6
6
  getCurrentFiber
7
- } from "./chunk-GYM3LLGS.mjs";
7
+ } from "./chunk-H626ZTDZ.mjs";
8
8
  import {
9
9
  Cause,
10
10
  asyncFlatMap,