@graphrefly/graphrefly 0.45.0 → 0.46.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.
Files changed (714) hide show
  1. package/README.md +1 -2
  2. package/dist/_internal-B23BagFd.d.cts +33 -0
  3. package/dist/_internal-B23BagFd.d.ts +33 -0
  4. package/dist/adaptive-rate-limiter-Dch_xYIi.d.cts +111 -0
  5. package/dist/adaptive-rate-limiter-Dch_xYIi.d.ts +111 -0
  6. package/dist/agents-C0Ji9ldU.d.cts +629 -0
  7. package/dist/agents-C9zexT7I.d.ts +629 -0
  8. package/dist/audit-BAXb3VOg.d.ts +246 -0
  9. package/dist/audit-C_bPfkqS.d.cts +246 -0
  10. package/dist/backoff-7KIK3WQW.js +24 -0
  11. package/dist/backoff-7KIK3WQW.js.map +1 -0
  12. package/dist/backoff-Bnb9OoPh.d.cts +6 -0
  13. package/dist/backoff-Bnb9OoPh.d.ts +6 -0
  14. package/dist/base/composition/index.cjs +811 -0
  15. package/dist/base/composition/index.cjs.map +1 -0
  16. package/dist/base/composition/index.d.cts +469 -0
  17. package/dist/base/composition/index.d.ts +469 -0
  18. package/dist/base/composition/index.js +40 -0
  19. package/dist/base/composition/index.js.map +1 -0
  20. package/dist/base/index.cjs +6336 -0
  21. package/dist/base/index.cjs.map +1 -0
  22. package/dist/base/index.d.cts +22 -0
  23. package/dist/base/index.d.ts +22 -0
  24. package/dist/base/index.js +259 -0
  25. package/dist/base/index.js.map +1 -0
  26. package/dist/base/io/index.cjs +3270 -0
  27. package/dist/base/io/index.cjs.map +1 -0
  28. package/dist/base/io/index.d.cts +2245 -0
  29. package/dist/base/io/index.d.ts +2245 -0
  30. package/dist/base/io/index.js +117 -0
  31. package/dist/base/io/index.js.map +1 -0
  32. package/dist/base/meta/index.cjs +43 -0
  33. package/dist/base/meta/index.cjs.map +1 -0
  34. package/dist/base/meta/index.d.cts +45 -0
  35. package/dist/base/meta/index.d.ts +45 -0
  36. package/dist/base/meta/index.js +13 -0
  37. package/dist/base/meta/index.js.map +1 -0
  38. package/dist/base/mutation/index.cjs +200 -0
  39. package/dist/base/mutation/index.cjs.map +1 -0
  40. package/dist/base/mutation/index.d.cts +177 -0
  41. package/dist/base/mutation/index.d.ts +177 -0
  42. package/dist/base/mutation/index.js +22 -0
  43. package/dist/base/mutation/index.js.map +1 -0
  44. package/dist/base/render/index.cjs +1120 -0
  45. package/dist/base/render/index.cjs.map +1 -0
  46. package/dist/base/render/index.d.cts +227 -0
  47. package/dist/base/render/index.d.ts +227 -0
  48. package/dist/base/render/index.js +24 -0
  49. package/dist/base/render/index.js.map +1 -0
  50. package/dist/base/sources/browser/index.cjs +172 -0
  51. package/dist/base/sources/browser/index.cjs.map +1 -0
  52. package/dist/base/sources/browser/index.d.cts +84 -0
  53. package/dist/base/sources/browser/index.d.ts +84 -0
  54. package/dist/base/sources/browser/index.js +151 -0
  55. package/dist/base/sources/browser/index.js.map +1 -0
  56. package/dist/base/sources/event/index.cjs +98 -0
  57. package/dist/base/sources/event/index.cjs.map +1 -0
  58. package/dist/base/sources/event/index.d.cts +91 -0
  59. package/dist/base/sources/event/index.d.ts +91 -0
  60. package/dist/base/sources/event/index.js +13 -0
  61. package/dist/base/sources/event/index.js.map +1 -0
  62. package/dist/base/sources/index.cjs +755 -0
  63. package/dist/base/sources/index.cjs.map +1 -0
  64. package/dist/base/sources/index.d.cts +357 -0
  65. package/dist/base/sources/index.d.ts +357 -0
  66. package/dist/base/sources/index.js +42 -0
  67. package/dist/base/sources/index.js.map +1 -0
  68. package/dist/base/sources/node/index.cjs +320 -0
  69. package/dist/base/sources/node/index.cjs.map +1 -0
  70. package/dist/base/sources/node/index.d.cts +185 -0
  71. package/dist/base/sources/node/index.d.ts +185 -0
  72. package/dist/base/sources/node/index.js +306 -0
  73. package/dist/base/sources/node/index.js.map +1 -0
  74. package/dist/base/utils/index.cjs +37 -0
  75. package/dist/base/utils/index.cjs.map +1 -0
  76. package/dist/base/utils/index.d.cts +37 -0
  77. package/dist/base/utils/index.d.ts +37 -0
  78. package/dist/base/utils/index.js +11 -0
  79. package/dist/base/utils/index.js.map +1 -0
  80. package/dist/base/worker/index.cjs +548 -0
  81. package/dist/base/worker/index.cjs.map +1 -0
  82. package/dist/base/worker/index.d.cts +207 -0
  83. package/dist/base/worker/index.d.ts +207 -0
  84. package/dist/base/worker/index.js +20 -0
  85. package/dist/base/worker/index.js.map +1 -0
  86. package/dist/breaker-C9skL3d8.d.ts +175 -0
  87. package/dist/breaker-ugSdq54q.d.cts +175 -0
  88. package/dist/cascading-CSSbKGrJ.d.ts +199 -0
  89. package/dist/cascading-baGkiihI.d.cts +199 -0
  90. package/dist/chunk-255UCBG4.js +58 -0
  91. package/dist/chunk-255UCBG4.js.map +1 -0
  92. package/dist/chunk-2LO3EL4W.js +1 -0
  93. package/dist/chunk-2LO3EL4W.js.map +1 -0
  94. package/dist/chunk-2OB3CEJS.js +1065 -0
  95. package/dist/chunk-2OB3CEJS.js.map +1 -0
  96. package/dist/chunk-36NMM65U.js +144 -0
  97. package/dist/chunk-36NMM65U.js.map +1 -0
  98. package/dist/chunk-3CEXCBN6.js +1 -0
  99. package/dist/chunk-3CEXCBN6.js.map +1 -0
  100. package/dist/chunk-3MUSLI6E.js +105 -0
  101. package/dist/chunk-3MUSLI6E.js.map +1 -0
  102. package/dist/chunk-3PSLNJDU.js +884 -0
  103. package/dist/chunk-3PSLNJDU.js.map +1 -0
  104. package/dist/chunk-3QZY5BI7.js +92 -0
  105. package/dist/chunk-3QZY5BI7.js.map +1 -0
  106. package/dist/chunk-42FQ27MQ.js +594 -0
  107. package/dist/chunk-42FQ27MQ.js.map +1 -0
  108. package/dist/chunk-4GYMCUDZ.js +1085 -0
  109. package/dist/chunk-4GYMCUDZ.js.map +1 -0
  110. package/dist/chunk-4S53H2KR.js +382 -0
  111. package/dist/chunk-4S53H2KR.js.map +1 -0
  112. package/dist/chunk-4XCHZRUJ.js +128 -0
  113. package/dist/chunk-4XCHZRUJ.js.map +1 -0
  114. package/dist/chunk-5THCXDWY.js +725 -0
  115. package/dist/chunk-5THCXDWY.js.map +1 -0
  116. package/dist/chunk-6XZYT4SW.js +256 -0
  117. package/dist/chunk-6XZYT4SW.js.map +1 -0
  118. package/dist/chunk-7EGRP2VX.js +76 -0
  119. package/dist/chunk-7EGRP2VX.js.map +1 -0
  120. package/dist/chunk-A7KV5UK4.js +150 -0
  121. package/dist/chunk-A7KV5UK4.js.map +1 -0
  122. package/dist/chunk-APY2SS5X.js +156 -0
  123. package/dist/chunk-APY2SS5X.js.map +1 -0
  124. package/dist/chunk-AZDQPQ3V.js +66 -0
  125. package/dist/chunk-AZDQPQ3V.js.map +1 -0
  126. package/dist/chunk-BU3SEFA5.js +90 -0
  127. package/dist/chunk-BU3SEFA5.js.map +1 -0
  128. package/dist/chunk-BXGZFGZ4.js +189 -0
  129. package/dist/chunk-BXGZFGZ4.js.map +1 -0
  130. package/dist/chunk-CGHORL6G.js +579 -0
  131. package/dist/chunk-CGHORL6G.js.map +1 -0
  132. package/dist/chunk-CXANAIZU.js +530 -0
  133. package/dist/chunk-CXANAIZU.js.map +1 -0
  134. package/dist/chunk-CZQHCKKG.js +1 -0
  135. package/dist/chunk-CZQHCKKG.js.map +1 -0
  136. package/dist/chunk-DKNHAICT.js +133 -0
  137. package/dist/chunk-DKNHAICT.js.map +1 -0
  138. package/dist/chunk-DM4OMPWK.js +584 -0
  139. package/dist/chunk-DM4OMPWK.js.map +1 -0
  140. package/dist/chunk-DMSNO6ZB.js +452 -0
  141. package/dist/chunk-DMSNO6ZB.js.map +1 -0
  142. package/dist/chunk-E5OZPDIW.js +229 -0
  143. package/dist/chunk-E5OZPDIW.js.map +1 -0
  144. package/dist/chunk-EVYY4X5A.js +509 -0
  145. package/dist/chunk-EVYY4X5A.js.map +1 -0
  146. package/dist/chunk-FDFD67UO.js +1 -0
  147. package/dist/chunk-FDFD67UO.js.map +1 -0
  148. package/dist/chunk-FMPF42Q4.js +13 -0
  149. package/dist/chunk-FMPF42Q4.js.map +1 -0
  150. package/dist/chunk-FR6RGA3B.js +1277 -0
  151. package/dist/chunk-FR6RGA3B.js.map +1 -0
  152. package/dist/chunk-FW23JYNQ.js +454 -0
  153. package/dist/chunk-FW23JYNQ.js.map +1 -0
  154. package/dist/chunk-GBCENOLN.js +1575 -0
  155. package/dist/chunk-GBCENOLN.js.map +1 -0
  156. package/dist/chunk-HL7HUJIX.js +1 -0
  157. package/dist/chunk-HL7HUJIX.js.map +1 -0
  158. package/dist/chunk-HULCUY35.js +2508 -0
  159. package/dist/chunk-HULCUY35.js.map +1 -0
  160. package/dist/chunk-IHTWQEDR.js +169 -0
  161. package/dist/chunk-IHTWQEDR.js.map +1 -0
  162. package/dist/chunk-IJRR6YAI.js +128 -0
  163. package/dist/chunk-IJRR6YAI.js.map +1 -0
  164. package/dist/chunk-JGFRAFDL.js +221 -0
  165. package/dist/chunk-JGFRAFDL.js.map +1 -0
  166. package/dist/chunk-KIIXR252.js +211 -0
  167. package/dist/chunk-KIIXR252.js.map +1 -0
  168. package/dist/chunk-KN3H5CNT.js +11 -0
  169. package/dist/chunk-KN3H5CNT.js.map +1 -0
  170. package/dist/chunk-KPG3DGLA.js +1 -0
  171. package/dist/chunk-KPG3DGLA.js.map +1 -0
  172. package/dist/chunk-KRNQ6RGQ.js +1 -0
  173. package/dist/chunk-KRNQ6RGQ.js.map +1 -0
  174. package/dist/chunk-LBAJK24K.js +1071 -0
  175. package/dist/chunk-LBAJK24K.js.map +1 -0
  176. package/dist/chunk-MLTPJMH6.js +417 -0
  177. package/dist/chunk-MLTPJMH6.js.map +1 -0
  178. package/dist/chunk-N3SZ7BMH.js +95 -0
  179. package/dist/chunk-N3SZ7BMH.js.map +1 -0
  180. package/dist/chunk-NDUD3IMO.js +540 -0
  181. package/dist/chunk-NDUD3IMO.js.map +1 -0
  182. package/dist/chunk-NY2PYHNC.js +873 -0
  183. package/dist/chunk-NY2PYHNC.js.map +1 -0
  184. package/dist/chunk-O3MT7DYI.js +225 -0
  185. package/dist/chunk-O3MT7DYI.js.map +1 -0
  186. package/dist/chunk-OCUDSN63.js +2386 -0
  187. package/dist/chunk-OCUDSN63.js.map +1 -0
  188. package/dist/chunk-OIWU3NYV.js +199 -0
  189. package/dist/chunk-OIWU3NYV.js.map +1 -0
  190. package/dist/chunk-OO5BM6CJ.js +1153 -0
  191. package/dist/chunk-OO5BM6CJ.js.map +1 -0
  192. package/dist/chunk-OQUIJT7A.js +1 -0
  193. package/dist/chunk-OQUIJT7A.js.map +1 -0
  194. package/dist/chunk-P5LBT622.js +105 -0
  195. package/dist/chunk-P5LBT622.js.map +1 -0
  196. package/dist/chunk-PKGQG5QQ.js +519 -0
  197. package/dist/chunk-PKGQG5QQ.js.map +1 -0
  198. package/dist/chunk-PKPO3JTZ.js +561 -0
  199. package/dist/chunk-PKPO3JTZ.js.map +1 -0
  200. package/dist/chunk-PL5UDIQ5.js +118 -0
  201. package/dist/chunk-PL5UDIQ5.js.map +1 -0
  202. package/dist/chunk-PZWISPIQ.js +432 -0
  203. package/dist/chunk-PZWISPIQ.js.map +1 -0
  204. package/dist/chunk-Q3EYOCZB.js +510 -0
  205. package/dist/chunk-Q3EYOCZB.js.map +1 -0
  206. package/dist/chunk-QMBYUVRL.js +15 -0
  207. package/dist/chunk-QMBYUVRL.js.map +1 -0
  208. package/dist/chunk-RAGGHLCV.js +200 -0
  209. package/dist/chunk-RAGGHLCV.js.map +1 -0
  210. package/dist/chunk-RGL53X5G.js +574 -0
  211. package/dist/chunk-RGL53X5G.js.map +1 -0
  212. package/dist/chunk-RJOG4IJU.js +1039 -0
  213. package/dist/chunk-RJOG4IJU.js.map +1 -0
  214. package/dist/chunk-SOOKUYVM.js +403 -0
  215. package/dist/chunk-SOOKUYVM.js.map +1 -0
  216. package/dist/chunk-T5BN5KG7.js +1 -0
  217. package/dist/chunk-T5BN5KG7.js.map +1 -0
  218. package/dist/chunk-TP7244Y6.js +207 -0
  219. package/dist/chunk-TP7244Y6.js.map +1 -0
  220. package/dist/chunk-TSBFTJKM.js +57 -0
  221. package/dist/chunk-TSBFTJKM.js.map +1 -0
  222. package/dist/chunk-URQ2CBBF.js +143 -0
  223. package/dist/chunk-URQ2CBBF.js.map +1 -0
  224. package/dist/chunk-W2BOPXTI.js +1 -0
  225. package/dist/chunk-W2BOPXTI.js.map +1 -0
  226. package/dist/chunk-WKSWLSCX.js +207 -0
  227. package/dist/chunk-WKSWLSCX.js.map +1 -0
  228. package/dist/chunk-Y52CS6YA.js +88 -0
  229. package/dist/chunk-Y52CS6YA.js.map +1 -0
  230. package/dist/chunk-YCBUWK77.js +92 -0
  231. package/dist/chunk-YCBUWK77.js.map +1 -0
  232. package/dist/chunk-YJ4U2D2C.js +314 -0
  233. package/dist/chunk-YJ4U2D2C.js.map +1 -0
  234. package/dist/chunk-Z4YXAUDN.js +239 -0
  235. package/dist/chunk-Z4YXAUDN.js.map +1 -0
  236. package/dist/chunk-Z6EGP5D7.js +92 -0
  237. package/dist/chunk-Z6EGP5D7.js.map +1 -0
  238. package/dist/compat/index.cjs +3083 -2
  239. package/dist/compat/index.cjs.map +1 -1
  240. package/dist/compat/index.d.cts +116 -1
  241. package/dist/compat/index.d.ts +116 -1
  242. package/dist/compat/index.js +175 -2
  243. package/dist/compat/index.js.map +1 -1
  244. package/dist/compat/jotai/index.cjs +130 -2
  245. package/dist/compat/jotai/index.cjs.map +1 -1
  246. package/dist/compat/jotai/index.d.cts +2 -1
  247. package/dist/compat/jotai/index.d.ts +2 -1
  248. package/dist/compat/jotai/index.js +7 -2
  249. package/dist/compat/jotai/index.js.map +1 -1
  250. package/dist/compat/nanostores/index.cjs +186 -2
  251. package/dist/compat/nanostores/index.cjs.map +1 -1
  252. package/dist/compat/nanostores/index.d.cts +2 -1
  253. package/dist/compat/nanostores/index.d.ts +2 -1
  254. package/dist/compat/nanostores/index.js +21 -2
  255. package/dist/compat/nanostores/index.js.map +1 -1
  256. package/dist/compat/nestjs/index.cjs +2224 -2
  257. package/dist/compat/nestjs/index.cjs.map +1 -1
  258. package/dist/compat/nestjs/index.d.cts +10 -1
  259. package/dist/compat/nestjs/index.d.ts +10 -1
  260. package/dist/compat/nestjs/index.js +77 -2
  261. package/dist/compat/nestjs/index.js.map +1 -1
  262. package/dist/compat/react/index.cjs +95 -2
  263. package/dist/compat/react/index.cjs.map +1 -1
  264. package/dist/compat/react/index.d.cts +2 -1
  265. package/dist/compat/react/index.d.ts +2 -1
  266. package/dist/compat/react/index.js +11 -2
  267. package/dist/compat/react/index.js.map +1 -1
  268. package/dist/compat/solid/index.cjs +82 -2
  269. package/dist/compat/solid/index.cjs.map +1 -1
  270. package/dist/compat/solid/index.d.cts +2 -1
  271. package/dist/compat/solid/index.d.ts +2 -1
  272. package/dist/compat/solid/index.js +11 -2
  273. package/dist/compat/solid/index.js.map +1 -1
  274. package/dist/compat/svelte/index.cjs +85 -2
  275. package/dist/compat/svelte/index.cjs.map +1 -1
  276. package/dist/compat/svelte/index.d.cts +2 -1
  277. package/dist/compat/svelte/index.d.ts +2 -1
  278. package/dist/compat/svelte/index.js +11 -2
  279. package/dist/compat/svelte/index.js.map +1 -1
  280. package/dist/compat/vue/index.cjs +100 -2
  281. package/dist/compat/vue/index.cjs.map +1 -1
  282. package/dist/compat/vue/index.d.cts +3 -1
  283. package/dist/compat/vue/index.d.ts +3 -1
  284. package/dist/compat/vue/index.js +11 -2
  285. package/dist/compat/vue/index.js.map +1 -1
  286. package/dist/compat/zustand/index.cjs +50 -2
  287. package/dist/compat/zustand/index.cjs.map +1 -1
  288. package/dist/compat/zustand/index.d.cts +2 -1
  289. package/dist/compat/zustand/index.d.ts +2 -1
  290. package/dist/compat/zustand/index.js +7 -2
  291. package/dist/compat/zustand/index.js.map +1 -1
  292. package/dist/distill-De6Rnn15.d.cts +48 -0
  293. package/dist/distill-De6Rnn15.d.ts +48 -0
  294. package/dist/external-register-CWyroXb_.d.cts +138 -0
  295. package/dist/external-register-CWyroXb_.d.ts +138 -0
  296. package/dist/fallback-Bx46zqky.d.cts +243 -0
  297. package/dist/fallback-pIWW8A2d.d.ts +243 -0
  298. package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
  299. package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
  300. package/dist/index-5SU_O78r.d.cts +754 -0
  301. package/dist/index-B6pxYJzO.d.cts +36 -0
  302. package/dist/index-B6pxYJzO.d.ts +36 -0
  303. package/dist/index-BFsng6v1.d.cts +44 -0
  304. package/dist/index-BFsng6v1.d.ts +44 -0
  305. package/dist/index-Bg-LwEt-.d.cts +45 -0
  306. package/dist/index-Bg-LwEt-.d.ts +45 -0
  307. package/dist/index-Brp888t0.d.cts +127 -0
  308. package/dist/index-Brp888t0.d.ts +127 -0
  309. package/dist/index-CDfk6jHN.d.cts +37 -0
  310. package/dist/index-CDfk6jHN.d.ts +37 -0
  311. package/dist/index-CEXCtYYJ.d.ts +754 -0
  312. package/dist/index-DLAxYaN5.d.cts +169 -0
  313. package/dist/index-DLAxYaN5.d.ts +169 -0
  314. package/dist/index-DeWbQzMe.d.cts +34 -0
  315. package/dist/index-DeWbQzMe.d.ts +34 -0
  316. package/dist/index-dX9IzPqj.d.cts +86 -0
  317. package/dist/index-dX9IzPqj.d.ts +86 -0
  318. package/dist/index.cjs +25950 -0
  319. package/dist/index.cjs.map +1 -1
  320. package/dist/index.d.cts +56 -42
  321. package/dist/index.d.ts +56 -42
  322. package/dist/index.js +849 -0
  323. package/dist/index.js.map +1 -1
  324. package/dist/layout-types-B5aiHYgk.d.cts +72 -0
  325. package/dist/layout-types-B5aiHYgk.d.ts +72 -0
  326. package/dist/memory-composers-BryDrRBX.d.cts +529 -0
  327. package/dist/memory-composers-CVQqPYEV.d.ts +529 -0
  328. package/dist/observable-BXQoW1P-.d.cts +36 -0
  329. package/dist/observable-BXQoW1P-.d.ts +36 -0
  330. package/dist/pipeline-graph-Ce47CB6Y.d.cts +145 -0
  331. package/dist/pipeline-graph-DXCwY9vG.d.ts +145 -0
  332. package/dist/presets/ai/index.cjs +4377 -0
  333. package/dist/presets/ai/index.cjs.map +1 -0
  334. package/dist/presets/ai/index.d.cts +98 -0
  335. package/dist/presets/ai/index.d.ts +98 -0
  336. package/dist/presets/ai/index.js +54 -0
  337. package/dist/presets/ai/index.js.map +1 -0
  338. package/dist/presets/harness/index.cjs +5929 -0
  339. package/dist/presets/harness/index.cjs.map +1 -0
  340. package/dist/presets/harness/index.d.cts +566 -0
  341. package/dist/presets/harness/index.d.ts +566 -0
  342. package/dist/presets/harness/index.js +71 -0
  343. package/dist/presets/harness/index.js.map +1 -0
  344. package/dist/presets/index.cjs +9782 -0
  345. package/dist/presets/index.cjs.map +1 -0
  346. package/dist/presets/index.d.cts +28 -0
  347. package/dist/presets/index.d.ts +28 -0
  348. package/dist/presets/index.js +129 -0
  349. package/dist/presets/index.js.map +1 -0
  350. package/dist/presets/inspect/index.cjs +1087 -0
  351. package/dist/presets/inspect/index.cjs.map +1 -0
  352. package/dist/presets/inspect/index.d.cts +172 -0
  353. package/dist/presets/inspect/index.d.ts +172 -0
  354. package/dist/presets/inspect/index.js +21 -0
  355. package/dist/presets/inspect/index.js.map +1 -0
  356. package/dist/presets/resilience/index.cjs +1593 -0
  357. package/dist/presets/resilience/index.cjs.map +1 -0
  358. package/dist/presets/resilience/index.d.cts +205 -0
  359. package/dist/presets/resilience/index.d.ts +205 -0
  360. package/dist/presets/resilience/index.js +18 -0
  361. package/dist/presets/resilience/index.js.map +1 -0
  362. package/dist/rate-limiter-CEALq4N1.d.ts +559 -0
  363. package/dist/rate-limiter-DpVbSYdH.d.cts +559 -0
  364. package/dist/reactive-layout-fswlBUvX.d.cts +195 -0
  365. package/dist/reactive-layout-fswlBUvX.d.ts +195 -0
  366. package/dist/retry-BDbRZ_gx.d.ts +125 -0
  367. package/dist/retry-DWuhjvsA.d.cts +125 -0
  368. package/dist/solutions/index.cjs +8200 -0
  369. package/dist/solutions/index.cjs.map +1 -0
  370. package/dist/solutions/index.d.cts +23 -0
  371. package/dist/solutions/index.d.ts +23 -0
  372. package/dist/solutions/index.js +55 -0
  373. package/dist/solutions/index.js.map +1 -0
  374. package/dist/spawnable-5mDY501F.d.cts +746 -0
  375. package/dist/spawnable-D3lR0oQu.d.ts +746 -0
  376. package/dist/status-U-rUI79b.d.cts +84 -0
  377. package/dist/status-U-rUI79b.d.ts +84 -0
  378. package/dist/timeout-U5O4ESK3.js +12 -0
  379. package/dist/timeout-U5O4ESK3.js.map +1 -0
  380. package/dist/types-BB5Lw-pB.d.cts +442 -0
  381. package/dist/types-BB5Lw-pB.d.ts +442 -0
  382. package/dist/types-CJWIMJiZ.d.ts +548 -0
  383. package/dist/types-vCq7ShIm.d.cts +548 -0
  384. package/dist/utils/ai/browser.cjs +2169 -0
  385. package/dist/utils/ai/browser.cjs.map +1 -0
  386. package/dist/utils/ai/browser.d.cts +129 -0
  387. package/dist/utils/ai/browser.d.ts +129 -0
  388. package/dist/utils/ai/browser.js +255 -0
  389. package/dist/utils/ai/browser.js.map +1 -0
  390. package/dist/utils/ai/index.cjs +8468 -0
  391. package/dist/utils/ai/index.cjs.map +1 -0
  392. package/dist/utils/ai/index.d.cts +1777 -0
  393. package/dist/utils/ai/index.d.ts +1777 -0
  394. package/dist/utils/ai/index.js +173 -0
  395. package/dist/utils/ai/index.js.map +1 -0
  396. package/dist/utils/ai/node.cjs +648 -0
  397. package/dist/utils/ai/node.cjs.map +1 -0
  398. package/dist/utils/ai/node.d.cts +57 -0
  399. package/dist/utils/ai/node.d.ts +57 -0
  400. package/dist/utils/ai/node.js +84 -0
  401. package/dist/utils/ai/node.js.map +1 -0
  402. package/dist/utils/cqrs/index.cjs +1036 -0
  403. package/dist/utils/cqrs/index.cjs.map +1 -0
  404. package/dist/utils/cqrs/index.d.cts +438 -0
  405. package/dist/utils/cqrs/index.d.ts +438 -0
  406. package/dist/utils/cqrs/index.js +18 -0
  407. package/dist/utils/cqrs/index.js.map +1 -0
  408. package/dist/utils/demo-shell/index.cjs +865 -0
  409. package/dist/utils/demo-shell/index.cjs.map +1 -0
  410. package/dist/utils/demo-shell/index.d.cts +90 -0
  411. package/dist/utils/demo-shell/index.d.ts +90 -0
  412. package/dist/utils/demo-shell/index.js +13 -0
  413. package/dist/utils/demo-shell/index.js.map +1 -0
  414. package/dist/utils/domain-templates/index.cjs +732 -0
  415. package/dist/utils/domain-templates/index.cjs.map +1 -0
  416. package/dist/utils/domain-templates/index.d.cts +214 -0
  417. package/dist/utils/domain-templates/index.d.ts +214 -0
  418. package/dist/utils/domain-templates/index.js +17 -0
  419. package/dist/utils/domain-templates/index.js.map +1 -0
  420. package/dist/utils/graphspec/index.cjs +1174 -0
  421. package/dist/utils/graphspec/index.cjs.map +1 -0
  422. package/dist/utils/graphspec/index.d.cts +449 -0
  423. package/dist/utils/graphspec/index.d.ts +449 -0
  424. package/dist/utils/graphspec/index.js +35 -0
  425. package/dist/utils/graphspec/index.js.map +1 -0
  426. package/dist/utils/harness/index.cjs +656 -0
  427. package/dist/utils/harness/index.cjs.map +1 -0
  428. package/dist/utils/harness/index.d.cts +542 -0
  429. package/dist/utils/harness/index.d.ts +542 -0
  430. package/dist/utils/harness/index.js +56 -0
  431. package/dist/utils/harness/index.js.map +1 -0
  432. package/dist/utils/index.cjs +17609 -0
  433. package/dist/utils/index.cjs.map +1 -0
  434. package/dist/utils/index.d.cts +96 -0
  435. package/dist/utils/index.d.ts +96 -0
  436. package/dist/utils/index.js +514 -0
  437. package/dist/utils/index.js.map +1 -0
  438. package/dist/utils/inspect/index.cjs +807 -0
  439. package/dist/utils/inspect/index.cjs.map +1 -0
  440. package/dist/utils/inspect/index.d.cts +123 -0
  441. package/dist/utils/inspect/index.d.ts +123 -0
  442. package/dist/utils/inspect/index.js +30 -0
  443. package/dist/utils/inspect/index.js.map +1 -0
  444. package/dist/utils/job-queue/index.cjs +717 -0
  445. package/dist/utils/job-queue/index.cjs.map +1 -0
  446. package/dist/utils/job-queue/index.d.cts +200 -0
  447. package/dist/utils/job-queue/index.d.ts +200 -0
  448. package/dist/utils/job-queue/index.js +18 -0
  449. package/dist/utils/job-queue/index.js.map +1 -0
  450. package/dist/utils/memory/index.cjs +1451 -0
  451. package/dist/utils/memory/index.cjs.map +1 -0
  452. package/dist/utils/memory/index.d.cts +582 -0
  453. package/dist/utils/memory/index.d.ts +582 -0
  454. package/dist/utils/memory/index.js +19 -0
  455. package/dist/utils/memory/index.js.map +1 -0
  456. package/dist/utils/messaging/index.cjs +666 -0
  457. package/dist/utils/messaging/index.cjs.map +1 -0
  458. package/dist/utils/messaging/index.d.cts +562 -0
  459. package/dist/utils/messaging/index.d.ts +562 -0
  460. package/dist/utils/messaging/index.js +50 -0
  461. package/dist/utils/messaging/index.js.map +1 -0
  462. package/dist/utils/orchestration/index.cjs +876 -0
  463. package/dist/utils/orchestration/index.cjs.map +1 -0
  464. package/dist/utils/orchestration/index.d.cts +233 -0
  465. package/dist/utils/orchestration/index.d.ts +233 -0
  466. package/dist/utils/orchestration/index.js +19 -0
  467. package/dist/utils/orchestration/index.js.map +1 -0
  468. package/dist/utils/process/index.cjs +743 -0
  469. package/dist/utils/process/index.cjs.map +1 -0
  470. package/dist/utils/process/index.d.cts +411 -0
  471. package/dist/utils/process/index.d.ts +411 -0
  472. package/dist/utils/process/index.js +14 -0
  473. package/dist/utils/process/index.js.map +1 -0
  474. package/dist/utils/reactive-layout/index.cjs +1607 -0
  475. package/dist/utils/reactive-layout/index.cjs.map +1 -0
  476. package/dist/utils/reactive-layout/index.d.cts +492 -0
  477. package/dist/utils/reactive-layout/index.d.ts +492 -0
  478. package/dist/utils/reactive-layout/index.js +52 -0
  479. package/dist/utils/reactive-layout/index.js.map +1 -0
  480. package/dist/utils/reduction/index.cjs +203 -0
  481. package/dist/utils/reduction/index.cjs.map +1 -0
  482. package/dist/utils/reduction/index.d.cts +102 -0
  483. package/dist/utils/reduction/index.d.ts +102 -0
  484. package/dist/utils/reduction/index.js +14 -0
  485. package/dist/utils/reduction/index.js.map +1 -0
  486. package/dist/utils/resilience/index.cjs +1617 -0
  487. package/dist/utils/resilience/index.cjs.map +1 -0
  488. package/dist/utils/resilience/index.d.cts +9 -0
  489. package/dist/utils/resilience/index.d.ts +9 -0
  490. package/dist/utils/resilience/index.js +44 -0
  491. package/dist/utils/resilience/index.js.map +1 -0
  492. package/dist/utils/surface/index.cjs +1070 -0
  493. package/dist/utils/surface/index.cjs.map +1 -0
  494. package/dist/utils/surface/index.d.cts +240 -0
  495. package/dist/utils/surface/index.d.ts +240 -0
  496. package/dist/utils/surface/index.js +30 -0
  497. package/dist/utils/surface/index.js.map +1 -0
  498. package/dist/utils/topology-view/index.cjs +620 -0
  499. package/dist/utils/topology-view/index.cjs.map +1 -0
  500. package/dist/utils/topology-view/index.d.cts +68 -0
  501. package/dist/utils/topology-view/index.d.ts +68 -0
  502. package/dist/utils/topology-view/index.js +11 -0
  503. package/dist/utils/topology-view/index.js.map +1 -0
  504. package/package.json +293 -237
  505. package/dist/core/index.cjs +0 -21
  506. package/dist/core/index.cjs.map +0 -1
  507. package/dist/core/index.d.cts +0 -1
  508. package/dist/core/index.d.ts +0 -1
  509. package/dist/core/index.js +0 -3
  510. package/dist/core/index.js.map +0 -1
  511. package/dist/extra/browser.cjs +0 -21
  512. package/dist/extra/browser.cjs.map +0 -1
  513. package/dist/extra/browser.d.cts +0 -1
  514. package/dist/extra/browser.d.ts +0 -1
  515. package/dist/extra/browser.js +0 -3
  516. package/dist/extra/browser.js.map +0 -1
  517. package/dist/extra/index.cjs +0 -21
  518. package/dist/extra/index.cjs.map +0 -1
  519. package/dist/extra/index.d.cts +0 -1
  520. package/dist/extra/index.d.ts +0 -1
  521. package/dist/extra/index.js +0 -3
  522. package/dist/extra/index.js.map +0 -1
  523. package/dist/extra/node.cjs +0 -21
  524. package/dist/extra/node.cjs.map +0 -1
  525. package/dist/extra/node.d.cts +0 -1
  526. package/dist/extra/node.d.ts +0 -1
  527. package/dist/extra/node.js +0 -3
  528. package/dist/extra/node.js.map +0 -1
  529. package/dist/extra/operators.cjs +0 -21
  530. package/dist/extra/operators.cjs.map +0 -1
  531. package/dist/extra/operators.d.cts +0 -1
  532. package/dist/extra/operators.d.ts +0 -1
  533. package/dist/extra/operators.js +0 -3
  534. package/dist/extra/operators.js.map +0 -1
  535. package/dist/extra/reactive.cjs +0 -21
  536. package/dist/extra/reactive.cjs.map +0 -1
  537. package/dist/extra/reactive.d.cts +0 -1
  538. package/dist/extra/reactive.d.ts +0 -1
  539. package/dist/extra/reactive.js +0 -3
  540. package/dist/extra/reactive.js.map +0 -1
  541. package/dist/extra/render/index.cjs +0 -21
  542. package/dist/extra/render/index.cjs.map +0 -1
  543. package/dist/extra/render/index.d.cts +0 -1
  544. package/dist/extra/render/index.d.ts +0 -1
  545. package/dist/extra/render/index.js +0 -3
  546. package/dist/extra/render/index.js.map +0 -1
  547. package/dist/extra/sources.cjs +0 -21
  548. package/dist/extra/sources.cjs.map +0 -1
  549. package/dist/extra/sources.d.cts +0 -1
  550. package/dist/extra/sources.d.ts +0 -1
  551. package/dist/extra/sources.js +0 -3
  552. package/dist/extra/sources.js.map +0 -1
  553. package/dist/extra/storage-browser.cjs +0 -21
  554. package/dist/extra/storage-browser.cjs.map +0 -1
  555. package/dist/extra/storage-browser.d.cts +0 -1
  556. package/dist/extra/storage-browser.d.ts +0 -1
  557. package/dist/extra/storage-browser.js +0 -3
  558. package/dist/extra/storage-browser.js.map +0 -1
  559. package/dist/extra/storage-core.cjs +0 -21
  560. package/dist/extra/storage-core.cjs.map +0 -1
  561. package/dist/extra/storage-core.d.cts +0 -1
  562. package/dist/extra/storage-core.d.ts +0 -1
  563. package/dist/extra/storage-core.js +0 -3
  564. package/dist/extra/storage-core.js.map +0 -1
  565. package/dist/extra/storage-node.cjs +0 -21
  566. package/dist/extra/storage-node.cjs.map +0 -1
  567. package/dist/extra/storage-node.d.cts +0 -1
  568. package/dist/extra/storage-node.d.ts +0 -1
  569. package/dist/extra/storage-node.js +0 -3
  570. package/dist/extra/storage-node.js.map +0 -1
  571. package/dist/extra/storage-tiers-browser.cjs +0 -21
  572. package/dist/extra/storage-tiers-browser.cjs.map +0 -1
  573. package/dist/extra/storage-tiers-browser.d.cts +0 -1
  574. package/dist/extra/storage-tiers-browser.d.ts +0 -1
  575. package/dist/extra/storage-tiers-browser.js +0 -3
  576. package/dist/extra/storage-tiers-browser.js.map +0 -1
  577. package/dist/extra/storage-tiers-node.cjs +0 -21
  578. package/dist/extra/storage-tiers-node.cjs.map +0 -1
  579. package/dist/extra/storage-tiers-node.d.cts +0 -1
  580. package/dist/extra/storage-tiers-node.d.ts +0 -1
  581. package/dist/extra/storage-tiers-node.js +0 -3
  582. package/dist/extra/storage-tiers-node.js.map +0 -1
  583. package/dist/extra/storage-tiers.cjs +0 -21
  584. package/dist/extra/storage-tiers.cjs.map +0 -1
  585. package/dist/extra/storage-tiers.d.cts +0 -1
  586. package/dist/extra/storage-tiers.d.ts +0 -1
  587. package/dist/extra/storage-tiers.js +0 -3
  588. package/dist/extra/storage-tiers.js.map +0 -1
  589. package/dist/extra/storage-wal.cjs +0 -21
  590. package/dist/extra/storage-wal.cjs.map +0 -1
  591. package/dist/extra/storage-wal.d.cts +0 -1
  592. package/dist/extra/storage-wal.d.ts +0 -1
  593. package/dist/extra/storage-wal.js +0 -3
  594. package/dist/extra/storage-wal.js.map +0 -1
  595. package/dist/graph/index.cjs +0 -21
  596. package/dist/graph/index.cjs.map +0 -1
  597. package/dist/graph/index.d.cts +0 -1
  598. package/dist/graph/index.d.ts +0 -1
  599. package/dist/graph/index.js +0 -3
  600. package/dist/graph/index.js.map +0 -1
  601. package/dist/patterns/ai/browser.cjs +0 -21
  602. package/dist/patterns/ai/browser.cjs.map +0 -1
  603. package/dist/patterns/ai/browser.d.cts +0 -1
  604. package/dist/patterns/ai/browser.d.ts +0 -1
  605. package/dist/patterns/ai/browser.js +0 -3
  606. package/dist/patterns/ai/browser.js.map +0 -1
  607. package/dist/patterns/ai/index.cjs +0 -21
  608. package/dist/patterns/ai/index.cjs.map +0 -1
  609. package/dist/patterns/ai/index.d.cts +0 -1
  610. package/dist/patterns/ai/index.d.ts +0 -1
  611. package/dist/patterns/ai/index.js +0 -3
  612. package/dist/patterns/ai/index.js.map +0 -1
  613. package/dist/patterns/ai/node.cjs +0 -21
  614. package/dist/patterns/ai/node.cjs.map +0 -1
  615. package/dist/patterns/ai/node.d.cts +0 -1
  616. package/dist/patterns/ai/node.d.ts +0 -1
  617. package/dist/patterns/ai/node.js +0 -3
  618. package/dist/patterns/ai/node.js.map +0 -1
  619. package/dist/patterns/cqrs/index.cjs +0 -21
  620. package/dist/patterns/cqrs/index.cjs.map +0 -1
  621. package/dist/patterns/cqrs/index.d.cts +0 -1
  622. package/dist/patterns/cqrs/index.d.ts +0 -1
  623. package/dist/patterns/cqrs/index.js +0 -3
  624. package/dist/patterns/cqrs/index.js.map +0 -1
  625. package/dist/patterns/demo-shell/index.cjs +0 -21
  626. package/dist/patterns/demo-shell/index.cjs.map +0 -1
  627. package/dist/patterns/demo-shell/index.d.cts +0 -1
  628. package/dist/patterns/demo-shell/index.d.ts +0 -1
  629. package/dist/patterns/demo-shell/index.js +0 -3
  630. package/dist/patterns/demo-shell/index.js.map +0 -1
  631. package/dist/patterns/domain-templates/index.cjs +0 -21
  632. package/dist/patterns/domain-templates/index.cjs.map +0 -1
  633. package/dist/patterns/domain-templates/index.d.cts +0 -1
  634. package/dist/patterns/domain-templates/index.d.ts +0 -1
  635. package/dist/patterns/domain-templates/index.js +0 -3
  636. package/dist/patterns/domain-templates/index.js.map +0 -1
  637. package/dist/patterns/graphspec/index.cjs +0 -21
  638. package/dist/patterns/graphspec/index.cjs.map +0 -1
  639. package/dist/patterns/graphspec/index.d.cts +0 -1
  640. package/dist/patterns/graphspec/index.d.ts +0 -1
  641. package/dist/patterns/graphspec/index.js +0 -3
  642. package/dist/patterns/graphspec/index.js.map +0 -1
  643. package/dist/patterns/harness/index.cjs +0 -21
  644. package/dist/patterns/harness/index.cjs.map +0 -1
  645. package/dist/patterns/harness/index.d.cts +0 -1
  646. package/dist/patterns/harness/index.d.ts +0 -1
  647. package/dist/patterns/harness/index.js +0 -3
  648. package/dist/patterns/harness/index.js.map +0 -1
  649. package/dist/patterns/inspect/index.cjs +0 -21
  650. package/dist/patterns/inspect/index.cjs.map +0 -1
  651. package/dist/patterns/inspect/index.d.cts +0 -1
  652. package/dist/patterns/inspect/index.d.ts +0 -1
  653. package/dist/patterns/inspect/index.js +0 -3
  654. package/dist/patterns/inspect/index.js.map +0 -1
  655. package/dist/patterns/job-queue/index.cjs +0 -21
  656. package/dist/patterns/job-queue/index.cjs.map +0 -1
  657. package/dist/patterns/job-queue/index.d.cts +0 -1
  658. package/dist/patterns/job-queue/index.d.ts +0 -1
  659. package/dist/patterns/job-queue/index.js +0 -3
  660. package/dist/patterns/job-queue/index.js.map +0 -1
  661. package/dist/patterns/memory/index.cjs +0 -21
  662. package/dist/patterns/memory/index.cjs.map +0 -1
  663. package/dist/patterns/memory/index.d.cts +0 -1
  664. package/dist/patterns/memory/index.d.ts +0 -1
  665. package/dist/patterns/memory/index.js +0 -3
  666. package/dist/patterns/memory/index.js.map +0 -1
  667. package/dist/patterns/messaging/index.cjs +0 -21
  668. package/dist/patterns/messaging/index.cjs.map +0 -1
  669. package/dist/patterns/messaging/index.d.cts +0 -1
  670. package/dist/patterns/messaging/index.d.ts +0 -1
  671. package/dist/patterns/messaging/index.js +0 -3
  672. package/dist/patterns/messaging/index.js.map +0 -1
  673. package/dist/patterns/orchestration/index.cjs +0 -21
  674. package/dist/patterns/orchestration/index.cjs.map +0 -1
  675. package/dist/patterns/orchestration/index.d.cts +0 -1
  676. package/dist/patterns/orchestration/index.d.ts +0 -1
  677. package/dist/patterns/orchestration/index.js +0 -3
  678. package/dist/patterns/orchestration/index.js.map +0 -1
  679. package/dist/patterns/process/index.cjs +0 -21
  680. package/dist/patterns/process/index.cjs.map +0 -1
  681. package/dist/patterns/process/index.d.cts +0 -1
  682. package/dist/patterns/process/index.d.ts +0 -1
  683. package/dist/patterns/process/index.js +0 -3
  684. package/dist/patterns/process/index.js.map +0 -1
  685. package/dist/patterns/reactive-layout/index.cjs +0 -21
  686. package/dist/patterns/reactive-layout/index.cjs.map +0 -1
  687. package/dist/patterns/reactive-layout/index.d.cts +0 -1
  688. package/dist/patterns/reactive-layout/index.d.ts +0 -1
  689. package/dist/patterns/reactive-layout/index.js +0 -3
  690. package/dist/patterns/reactive-layout/index.js.map +0 -1
  691. package/dist/patterns/reduction/index.cjs +0 -21
  692. package/dist/patterns/reduction/index.cjs.map +0 -1
  693. package/dist/patterns/reduction/index.d.cts +0 -1
  694. package/dist/patterns/reduction/index.d.ts +0 -1
  695. package/dist/patterns/reduction/index.js +0 -3
  696. package/dist/patterns/reduction/index.js.map +0 -1
  697. package/dist/patterns/surface/index.cjs +0 -21
  698. package/dist/patterns/surface/index.cjs.map +0 -1
  699. package/dist/patterns/surface/index.d.cts +0 -1
  700. package/dist/patterns/surface/index.d.ts +0 -1
  701. package/dist/patterns/surface/index.js +0 -3
  702. package/dist/patterns/surface/index.js.map +0 -1
  703. package/dist/patterns/topology-view/index.cjs +0 -21
  704. package/dist/patterns/topology-view/index.cjs.map +0 -1
  705. package/dist/patterns/topology-view/index.d.cts +0 -1
  706. package/dist/patterns/topology-view/index.d.ts +0 -1
  707. package/dist/patterns/topology-view/index.js +0 -3
  708. package/dist/patterns/topology-view/index.js.map +0 -1
  709. package/dist/testing/index.cjs +0 -21
  710. package/dist/testing/index.cjs.map +0 -1
  711. package/dist/testing/index.d.cts +0 -1
  712. package/dist/testing/index.d.ts +0 -1
  713. package/dist/testing/index.js +0 -3
  714. package/dist/testing/index.js.map +0 -1
@@ -0,0 +1,1617 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/resilience/index.ts
21
+ var resilience_exports = {};
22
+ __export(resilience_exports, {
23
+ CircuitOpenError: () => CircuitOpenError,
24
+ NS_PER_SEC: () => NS_PER_SEC,
25
+ RateLimiterOverflowError: () => RateLimiterOverflowError,
26
+ TimeoutError: () => TimeoutError,
27
+ adaptiveRateLimiter: () => adaptiveRateLimiter,
28
+ budgetGate: () => budgetGate,
29
+ circuitBreaker: () => circuitBreaker,
30
+ fallback: () => fallback,
31
+ rateLimiter: () => rateLimiter,
32
+ retry: () => retry,
33
+ tokenBucket: () => tokenBucket,
34
+ withBreaker: () => withBreaker,
35
+ withStatus: () => withStatus,
36
+ withTimeout: () => withTimeout
37
+ });
38
+ module.exports = __toCommonJS(resilience_exports);
39
+
40
+ // src/base/resilience/retry.ts
41
+ var import_core2 = require("@graphrefly/pure-ts/core");
42
+
43
+ // src/base/resilience/_internal.ts
44
+ var import_core = require("@graphrefly/pure-ts/core");
45
+ function operatorOpts(opts) {
46
+ return { describeKind: "derived", ...opts };
47
+ }
48
+ function clampNonNegative(value) {
49
+ return value < 0 ? 0 : value;
50
+ }
51
+ function msgVal(m) {
52
+ return m[1];
53
+ }
54
+ function coerceDelayNs(raw) {
55
+ if (typeof raw !== "number" || !Number.isFinite(raw)) {
56
+ throw new TypeError("backoff strategy must return a finite number");
57
+ }
58
+ return raw < 0 ? 0 : raw;
59
+ }
60
+ function isNode(x) {
61
+ return x != null && typeof x === "object" && "cache" in x && typeof x.subscribe === "function";
62
+ }
63
+ function resolveReactiveOption(arg, onChange) {
64
+ if (!isNode(arg)) {
65
+ return { current: () => arg, unsub: () => void 0 };
66
+ }
67
+ const node9 = arg;
68
+ let latest = node9.cache;
69
+ const unsub = node9.subscribe((msgs) => {
70
+ for (const m of msgs) {
71
+ if (m[0] === import_core.DATA) {
72
+ latest = m[1];
73
+ if (onChange) onChange(latest);
74
+ }
75
+ }
76
+ });
77
+ return {
78
+ current: () => latest,
79
+ unsub
80
+ };
81
+ }
82
+ function isThenable(x) {
83
+ return x != null && typeof x.then === "function";
84
+ }
85
+ function isAsyncIterable(x) {
86
+ return x != null && typeof x === "object" && typeof x[Symbol.asyncIterator] === "function";
87
+ }
88
+
89
+ // src/base/resilience/backoff.ts
90
+ var NS_PER_MS = 1e6;
91
+ var NS_PER_SEC = 1e9;
92
+ function clampNonNegative2(value) {
93
+ return value < 0 ? 0 : value;
94
+ }
95
+ function applyJitter(delay, jitter) {
96
+ if (jitter === "none") return delay;
97
+ if (jitter === "full") return Math.random() * delay;
98
+ return delay / 2 + Math.random() * (delay / 2);
99
+ }
100
+ function randomBetween(min, max) {
101
+ return min + Math.random() * (max - min);
102
+ }
103
+ function constant(delayNs) {
104
+ const safe = clampNonNegative2(delayNs);
105
+ return () => safe;
106
+ }
107
+ function linear(baseNs, stepNs) {
108
+ const safeBase = clampNonNegative2(baseNs);
109
+ const safeStep = stepNs === void 0 ? safeBase : clampNonNegative2(stepNs);
110
+ return (attempt) => safeBase + safeStep * Math.max(0, attempt);
111
+ }
112
+ function exponential(options) {
113
+ const baseNs = clampNonNegative2(options?.baseNs ?? 100 * NS_PER_MS);
114
+ const factor = options?.factor !== void 0 && options.factor < 1 ? 1 : options?.factor ?? 2;
115
+ const maxDelayNs = clampNonNegative2(options?.maxDelayNs ?? 30 * NS_PER_SEC);
116
+ const jitter = options?.jitter ?? "none";
117
+ return (attempt) => {
118
+ let delay;
119
+ if (baseNs === 0) {
120
+ delay = 0;
121
+ } else if (factor === 1) {
122
+ delay = baseNs;
123
+ } else {
124
+ const capRatio = maxDelayNs / baseNs;
125
+ let growth = 1;
126
+ for (let i = 0; i < Math.max(0, attempt); i++) {
127
+ if (growth >= capRatio) {
128
+ growth = capRatio;
129
+ break;
130
+ }
131
+ growth *= factor;
132
+ }
133
+ delay = baseNs * growth;
134
+ if (delay > maxDelayNs) delay = maxDelayNs;
135
+ }
136
+ return applyJitter(delay, jitter);
137
+ };
138
+ }
139
+ function fibonacci(baseNs = 100 * NS_PER_MS, maxDelayNs = 30 * NS_PER_SEC) {
140
+ const safeBase = clampNonNegative2(baseNs);
141
+ const safeMax = clampNonNegative2(maxDelayNs);
142
+ function fibUnit(attempt) {
143
+ if (attempt <= 0) return 1;
144
+ let prev = 1;
145
+ let cur = 2;
146
+ for (let i = 1; i < attempt; i++) {
147
+ const next = prev + cur;
148
+ prev = cur;
149
+ cur = next;
150
+ }
151
+ return cur;
152
+ }
153
+ return (attempt) => {
154
+ const raw = fibUnit(attempt) * safeBase;
155
+ return raw <= safeMax ? raw : safeMax;
156
+ };
157
+ }
158
+ function decorrelatedJitter(baseNs = 100 * NS_PER_MS, maxNs = 30 * NS_PER_SEC) {
159
+ return (_attempt, _error, prevDelayNs) => {
160
+ const last = prevDelayNs ?? baseNs;
161
+ const ceiling = Math.min(maxNs, last * 3);
162
+ return randomBetween(baseNs, ceiling);
163
+ };
164
+ }
165
+ function resolveBackoffPreset(name) {
166
+ if (name === "constant") return constant(1 * NS_PER_SEC);
167
+ if (name === "linear") return linear(1 * NS_PER_SEC);
168
+ if (name === "exponential") return exponential();
169
+ if (name === "fibonacci") return fibonacci();
170
+ if (name === "decorrelatedJitter") return decorrelatedJitter();
171
+ throw new Error(
172
+ `Unknown backoff preset: "${String(name)}". Use one of: constant, linear, exponential, fibonacci, decorrelatedJitter`
173
+ );
174
+ }
175
+
176
+ // src/base/resilience/retry.ts
177
+ function resolveRetryConfig(opts) {
178
+ const count = opts?.count;
179
+ const backoffOpt = opts?.backoff;
180
+ if (backoffOpt !== void 0 && count === void 0) {
181
+ throw new RangeError(
182
+ "retry({ backoff }) requires explicit count to prevent unbounded retries; pass { count: <n>, backoff: ... }"
183
+ );
184
+ }
185
+ const maxRetries = count !== void 0 ? count : 0;
186
+ if (maxRetries < 0) throw new RangeError("retry count must be >= 0");
187
+ const strategy = backoffOpt === void 0 ? null : typeof backoffOpt === "string" ? resolveBackoffPreset(backoffOpt) : backoffOpt;
188
+ return { maxRetries, strategy };
189
+ }
190
+ function retryFactoryArgs(opts) {
191
+ const args = {};
192
+ if (opts?.count !== void 0) args.count = opts.count;
193
+ if (typeof opts?.backoff === "string") args.backoff = opts.backoff;
194
+ return Object.keys(args).length > 0 ? args : void 0;
195
+ }
196
+ function _runRetryStateMachine(getCfg, acquireSource, a, emitState) {
197
+ let attempt = 0;
198
+ let stopped = false;
199
+ let prevDelay = null;
200
+ let unsub;
201
+ const timer = new import_core2.ResettableTimer();
202
+ const publish = (status) => {
203
+ emitState?.({ status, attempt, lastDelay_ns: prevDelay });
204
+ };
205
+ publish("pending");
206
+ function disconnectUpstream() {
207
+ unsub?.();
208
+ unsub = void 0;
209
+ }
210
+ function scheduleRetryOrFinish(err) {
211
+ if (stopped) return;
212
+ const cfg = getCfg();
213
+ if (attempt >= cfg.maxRetries) {
214
+ disconnectUpstream();
215
+ publish("errored");
216
+ a.down([[import_core2.ERROR, err]]);
217
+ return;
218
+ }
219
+ const raw = cfg.strategy === null ? 0 : cfg.strategy(attempt, err, prevDelay);
220
+ if (raw === null || raw === void 0) {
221
+ disconnectUpstream();
222
+ publish("errored");
223
+ a.down([[import_core2.ERROR, err]]);
224
+ return;
225
+ }
226
+ let delayNs;
227
+ try {
228
+ delayNs = coerceDelayNs(raw);
229
+ } catch {
230
+ disconnectUpstream();
231
+ publish("errored");
232
+ a.down([[import_core2.ERROR, err]]);
233
+ return;
234
+ }
235
+ prevDelay = delayNs;
236
+ attempt += 1;
237
+ disconnectUpstream();
238
+ publish("paused");
239
+ const delayMs = delayNs > 0 ? delayNs / NS_PER_MS : 1;
240
+ timer.start(delayMs, () => {
241
+ if (stopped) return;
242
+ connect();
243
+ });
244
+ }
245
+ function connect() {
246
+ timer.cancel();
247
+ disconnectUpstream();
248
+ let src;
249
+ try {
250
+ src = acquireSource();
251
+ } catch (err) {
252
+ scheduleRetryOrFinish(err);
253
+ return;
254
+ }
255
+ publish("running");
256
+ unsub = src.subscribe((msgs) => {
257
+ if (stopped) return;
258
+ for (const m of msgs) {
259
+ const t = m[0];
260
+ if (t === import_core2.DIRTY) a.down([[import_core2.DIRTY]]);
261
+ else if (t === import_core2.DATA) {
262
+ attempt = 0;
263
+ prevDelay = null;
264
+ a.emit(m[1]);
265
+ publish("running");
266
+ } else if (t === import_core2.RESOLVED) a.down([[import_core2.RESOLVED]]);
267
+ else if (t === import_core2.COMPLETE) {
268
+ stopped = true;
269
+ disconnectUpstream();
270
+ publish("completed");
271
+ a.down([[import_core2.COMPLETE]]);
272
+ } else if (t === import_core2.ERROR) {
273
+ scheduleRetryOrFinish(msgVal(m));
274
+ return;
275
+ } else a.down([m]);
276
+ }
277
+ });
278
+ }
279
+ connect();
280
+ return () => {
281
+ const wasStopped = stopped;
282
+ stopped = true;
283
+ timer.cancel();
284
+ disconnectUpstream();
285
+ if (!wasStopped) publish("cancelled");
286
+ };
287
+ }
288
+ function retry(input, opts) {
289
+ const retryState = (0, import_core2.node)([], {
290
+ name: "retryState",
291
+ describeKind: "state",
292
+ initial: { status: "pending", attempt: 0, lastDelay_ns: null },
293
+ equals: (a, b) => a === b || a != null && b != null && typeof a === "object" && typeof b === "object" && JSON.stringify(a) === JSON.stringify(b)
294
+ });
295
+ const emit = (s) => {
296
+ retryState.down([[import_core2.DIRTY], [import_core2.DATA, s]]);
297
+ };
298
+ if (typeof input === "function") {
299
+ return {
300
+ node: _retryFactory(input, opts, emit),
301
+ retryState
302
+ };
303
+ }
304
+ return {
305
+ node: _retrySource(input, opts, emit),
306
+ retryState
307
+ };
308
+ }
309
+ function makeMergedOptsMirror(arg) {
310
+ if (arg === void 0) {
311
+ return { current: () => void 0, unsub: () => void 0 };
312
+ }
313
+ if (!isNode(arg)) {
314
+ return { current: () => arg, unsub: () => void 0 };
315
+ }
316
+ const optsNode = arg;
317
+ let merged = optsNode.cache ?? void 0;
318
+ const unsub = optsNode.subscribe((msgs) => {
319
+ for (const m of msgs) {
320
+ if (m[0] !== import_core2.DATA) continue;
321
+ const next = m[1];
322
+ if (next == null || typeof next !== "object") continue;
323
+ if (Object.keys(next).length === 0) continue;
324
+ merged = { ...merged ?? {}, ...next };
325
+ }
326
+ });
327
+ return { current: () => merged, unsub };
328
+ }
329
+ var _retrySourceNonResubscribableWarned = /* @__PURE__ */ new WeakSet();
330
+ function _retrySource(source, opts, emitState) {
331
+ const sourceWithFlag = source;
332
+ if (sourceWithFlag._resubscribable === false && !_retrySourceNonResubscribableWarned.has(source)) {
333
+ _retrySourceNonResubscribableWarned.add(source);
334
+ console.warn(
335
+ "retry(source, opts): source-mode requires `resubscribable: true` on the upstream node. Retries will be silent no-ops after the first ERROR. Either pass `resubscribable: true` to the source factory, OR use factory-mode retry `retry(() => buildSource(), opts)` so each attempt builds a fresh node."
336
+ );
337
+ }
338
+ const staticOpts = isNode(opts) ? void 0 : opts;
339
+ if (!isNode(opts)) resolveRetryConfig(staticOpts);
340
+ return (0, import_core2.node)(
341
+ (_data, a) => {
342
+ const merged = makeMergedOptsMirror(opts);
343
+ const getCfg = () => resolveRetryConfig(merged.current());
344
+ const inner = _runRetryStateMachine(getCfg, () => source, a, emitState);
345
+ return () => {
346
+ inner();
347
+ merged.unsub();
348
+ };
349
+ },
350
+ {
351
+ ...operatorOpts(),
352
+ initial: source.cache,
353
+ meta: {
354
+ ...staticOpts?.meta ?? {},
355
+ ...(0, import_core2.factoryTag)(
356
+ "retry",
357
+ isNode(opts) ? { reactiveOpts: true } : retryFactoryArgs(staticOpts)
358
+ )
359
+ }
360
+ }
361
+ );
362
+ }
363
+ function _retryFactory(factory, opts, emitState) {
364
+ const staticOpts = isNode(opts) ? void 0 : opts;
365
+ if (!isNode(opts)) resolveRetryConfig(staticOpts);
366
+ return (0, import_core2.node)(
367
+ (_data, a) => {
368
+ const merged = makeMergedOptsMirror(opts);
369
+ const getCfg = () => resolveRetryConfig(merged.current());
370
+ const inner = _runRetryStateMachine(getCfg, factory, a, emitState);
371
+ return () => {
372
+ inner();
373
+ merged.unsub();
374
+ };
375
+ },
376
+ {
377
+ ...operatorOpts(),
378
+ initial: staticOpts?.initial,
379
+ meta: {
380
+ ...staticOpts?.meta ?? {},
381
+ ...(0, import_core2.factoryTag)(
382
+ "retry",
383
+ isNode(opts) ? { reactiveOpts: true } : retryFactoryArgs(staticOpts)
384
+ )
385
+ }
386
+ }
387
+ );
388
+ }
389
+
390
+ // src/base/resilience/status.ts
391
+ var import_core3 = require("@graphrefly/pure-ts/core");
392
+ function withStatus(src, options) {
393
+ const initialStatus = options?.initialStatus ?? "pending";
394
+ const callerMeta = options?.meta;
395
+ const out = (0, import_core3.node)(
396
+ [],
397
+ (_deps, a) => {
398
+ let currentStatus = initialStatus;
399
+ out.meta.status.down([[import_core3.DATA, initialStatus]]);
400
+ out.meta.error.down([[import_core3.DATA, null]]);
401
+ const unsub = src.subscribe((msgs) => {
402
+ for (const m of msgs) {
403
+ const t = m[0];
404
+ if (t === import_core3.DIRTY) a.down([[import_core3.DIRTY]]);
405
+ else if (t === import_core3.DATA) {
406
+ if (currentStatus === "errored") {
407
+ (0, import_core3.batch)(() => {
408
+ out.meta.error.down([[import_core3.DATA, null]]);
409
+ out.meta.status.down([[import_core3.DATA, "running"]]);
410
+ a.emit(m[1]);
411
+ });
412
+ currentStatus = "running";
413
+ } else if (currentStatus !== "running") {
414
+ (0, import_core3.batch)(() => {
415
+ out.meta.status.down([[import_core3.DATA, "running"]]);
416
+ a.emit(m[1]);
417
+ });
418
+ currentStatus = "running";
419
+ } else {
420
+ a.emit(m[1]);
421
+ }
422
+ } else if (t === import_core3.RESOLVED) a.down([[import_core3.RESOLVED]]);
423
+ else if (t === import_core3.COMPLETE) {
424
+ out.meta.status.down([[import_core3.DATA, "completed"]]);
425
+ currentStatus = "completed";
426
+ a.down([[import_core3.COMPLETE]]);
427
+ } else if (t === import_core3.ERROR) {
428
+ const err = msgVal(m);
429
+ (0, import_core3.batch)(() => {
430
+ out.meta.error.down([[import_core3.DATA, err]]);
431
+ out.meta.status.down([[import_core3.DATA, "errored"]]);
432
+ });
433
+ currentStatus = "errored";
434
+ a.down([m]);
435
+ } else a.down([m]);
436
+ }
437
+ });
438
+ return unsub;
439
+ },
440
+ {
441
+ ...operatorOpts(),
442
+ meta: {
443
+ ...callerMeta ?? {},
444
+ status: initialStatus,
445
+ error: null,
446
+ ...(0, import_core3.factoryTag)("withStatus", { initialStatus })
447
+ },
448
+ completeWhenDepsComplete: false,
449
+ resubscribable: true,
450
+ initial: src.cache
451
+ }
452
+ );
453
+ return {
454
+ node: out,
455
+ status: out.meta.status,
456
+ error: out.meta.error
457
+ };
458
+ }
459
+
460
+ // src/base/resilience/timeout.ts
461
+ var import_core4 = require("@graphrefly/pure-ts/core");
462
+ var TimeoutError = class extends Error {
463
+ name = "TimeoutError";
464
+ constructor(ns) {
465
+ super(`Timed out after ${ns / NS_PER_MS}ms`);
466
+ }
467
+ };
468
+ function withTimeout(source, opts, extraOpts) {
469
+ const isReactive = isNode(opts);
470
+ let latestOpts = null;
471
+ if (!isReactive) {
472
+ const staticOpts = opts;
473
+ if (staticOpts.ns === void 0 || typeof staticOpts.ns !== "number" || !Number.isFinite(staticOpts.ns) || staticOpts.ns <= 0) {
474
+ throw new RangeError("withTimeout: opts.ns must be a positive finite number");
475
+ }
476
+ latestOpts = {
477
+ ns: staticOpts.ns,
478
+ ...staticOpts.meta != null ? { meta: staticOpts.meta } : {}
479
+ };
480
+ } else {
481
+ const cached = opts.cache;
482
+ if (cached !== void 0) {
483
+ if (cached.ns === void 0 || typeof cached.ns !== "number" || !Number.isFinite(cached.ns) || cached.ns <= 0) {
484
+ throw new RangeError(
485
+ "withTimeout: opts.ns must be a positive finite number on first settle"
486
+ );
487
+ }
488
+ latestOpts = {
489
+ ns: cached.ns,
490
+ ...cached.meta != null ? { meta: cached.meta } : {}
491
+ };
492
+ }
493
+ }
494
+ const callerMeta = extraOpts?.meta;
495
+ const factoryArgs = isReactive ? { ns: "Node<Partial<TimeoutOptions>>" } : { ns: latestOpts.ns };
496
+ const timeoutState = (0, import_core4.node)([], {
497
+ name: "timeoutState",
498
+ describeKind: "state",
499
+ initial: { status: "pending" },
500
+ equals: (a, b) => a === b || a != null && b != null && typeof a === "object" && typeof b === "object" && a.status === b.status && JSON.stringify(a) === JSON.stringify(b)
501
+ });
502
+ const out = (0, import_core4.node)(
503
+ (_data, a) => {
504
+ let stopped = false;
505
+ let lastDeadlineNs = 0;
506
+ const timer = new import_core4.ResettableTimer();
507
+ let optsUnsub = null;
508
+ let srcUnsub = null;
509
+ function emitState(next) {
510
+ timeoutState.down([[import_core4.DIRTY], [import_core4.DATA, next]]);
511
+ }
512
+ function startTimer() {
513
+ if (stopped) return;
514
+ if (latestOpts == null || typeof latestOpts.ns !== "number" || !Number.isFinite(latestOpts.ns) || latestOpts.ns <= 0) {
515
+ return;
516
+ }
517
+ const ns = latestOpts.ns;
518
+ lastDeadlineNs = ns;
519
+ const startedAt = (0, import_core4.monotonicNs)();
520
+ const delayMs = ns / NS_PER_MS;
521
+ emitState({
522
+ status: "running",
523
+ startedAt_ns: startedAt,
524
+ deadline_ns: ns
525
+ });
526
+ timer.start(delayMs, () => {
527
+ if (stopped) return;
528
+ stopped = true;
529
+ srcUnsub?.();
530
+ emitState({
531
+ status: "errored",
532
+ firedAt_ns: (0, import_core4.monotonicNs)(),
533
+ deadline_ns: ns
534
+ });
535
+ a.down([[import_core4.ERROR, new TimeoutError(ns)]]);
536
+ });
537
+ }
538
+ function attachSource() {
539
+ if (srcUnsub != null || stopped) return;
540
+ srcUnsub = source.subscribe((msgs) => {
541
+ for (const m of msgs) {
542
+ if (stopped) return;
543
+ const t = m[0];
544
+ if (t === import_core4.DIRTY) a.down([[import_core4.DIRTY]]);
545
+ else if (t === import_core4.DATA) {
546
+ startTimer();
547
+ a.emit(m[1]);
548
+ } else if (t === import_core4.RESOLVED) a.down([[import_core4.RESOLVED]]);
549
+ else if (t === import_core4.COMPLETE) {
550
+ timer.cancel();
551
+ stopped = true;
552
+ emitState({
553
+ status: "completed",
554
+ settledAt_ns: (0, import_core4.monotonicNs)()
555
+ });
556
+ a.down([[import_core4.COMPLETE]]);
557
+ return;
558
+ } else if (t === import_core4.ERROR) {
559
+ timer.cancel();
560
+ stopped = true;
561
+ emitState({
562
+ status: "errored",
563
+ firedAt_ns: (0, import_core4.monotonicNs)(),
564
+ deadline_ns: lastDeadlineNs
565
+ });
566
+ a.down([m]);
567
+ return;
568
+ } else if (t === import_core4.TEARDOWN) {
569
+ timer.cancel();
570
+ stopped = true;
571
+ a.down([m]);
572
+ return;
573
+ } else a.down([m]);
574
+ }
575
+ });
576
+ if (latestOpts != null && latestOpts.ns > 0) {
577
+ startTimer();
578
+ }
579
+ }
580
+ if (isReactive) {
581
+ const optsNode = opts;
582
+ optsUnsub = optsNode.subscribe((msgs) => {
583
+ for (const m of msgs) {
584
+ if (m[0] !== import_core4.DATA) continue;
585
+ const next = m[1];
586
+ if (next == null || typeof next !== "object") continue;
587
+ const keys = Object.keys(next);
588
+ if (keys.length === 0) continue;
589
+ if ("ns" in next) {
590
+ if (typeof next.ns !== "number" || !Number.isFinite(next.ns) || next.ns <= 0) {
591
+ if (latestOpts == null) {
592
+ stopped = true;
593
+ a.down([
594
+ [
595
+ import_core4.ERROR,
596
+ new RangeError(
597
+ "withTimeout: opts.ns must be a positive finite number on first settle"
598
+ )
599
+ ]
600
+ ]);
601
+ return;
602
+ }
603
+ continue;
604
+ }
605
+ }
606
+ const wasNull = latestOpts == null;
607
+ latestOpts = {
608
+ ...latestOpts ?? { ns: 0 },
609
+ ...next
610
+ };
611
+ if (wasNull && latestOpts.ns > 0) {
612
+ attachSource();
613
+ }
614
+ }
615
+ });
616
+ }
617
+ if (latestOpts != null) {
618
+ attachSource();
619
+ }
620
+ return () => {
621
+ stopped = true;
622
+ timer.cancel();
623
+ if (srcUnsub) srcUnsub();
624
+ if (optsUnsub) optsUnsub();
625
+ };
626
+ },
627
+ {
628
+ ...operatorOpts(),
629
+ initial: source.cache,
630
+ meta: { ...callerMeta ?? {}, ...(0, import_core4.factoryTag)("withTimeout", factoryArgs) }
631
+ }
632
+ );
633
+ return { node: out, timeoutState };
634
+ }
635
+
636
+ // src/utils/resilience/breaker.ts
637
+ var import_core5 = require("@graphrefly/pure-ts/core");
638
+ var CircuitOpenError = class extends Error {
639
+ name = "CircuitOpenError";
640
+ constructor() {
641
+ super("Circuit breaker is open");
642
+ }
643
+ };
644
+ function circuitBreaker(options) {
645
+ let threshold = 5;
646
+ let baseCooldownNs = 30 * NS_PER_SEC;
647
+ let cooldownStrategy = null;
648
+ let halfOpenMax = 1;
649
+ let now = import_core5.monotonicNs;
650
+ function applyOptions(o) {
651
+ threshold = Math.max(1, o?.failureThreshold ?? 5);
652
+ baseCooldownNs = clampNonNegative(o?.cooldownNs ?? 30 * NS_PER_SEC);
653
+ cooldownStrategy = o?.cooldown ?? null;
654
+ halfOpenMax = Math.max(1, o?.halfOpenMax ?? 1);
655
+ now = o?.now ?? import_core5.monotonicNs;
656
+ }
657
+ let _state = "closed";
658
+ let _failureCount = 0;
659
+ let _openCycle = 0;
660
+ let _lastOpenedAt = 0;
661
+ let _lastCooldownNs = baseCooldownNs;
662
+ let _halfOpenAttempts = 0;
663
+ let initialOpts;
664
+ let optsUnsub;
665
+ if (isNode(options)) {
666
+ const optsNode = options;
667
+ initialOpts = optsNode.cache;
668
+ applyOptions(initialOpts);
669
+ const lockedNow = initialOpts?.now;
670
+ const hadInitialCache = initialOpts !== void 0;
671
+ let firstEmit = hadInitialCache;
672
+ optsUnsub = optsNode.subscribe((msgs) => {
673
+ for (const m of msgs) {
674
+ if (m[0] !== import_core5.DATA) continue;
675
+ if (firstEmit) {
676
+ firstEmit = false;
677
+ continue;
678
+ }
679
+ const next = m[1];
680
+ if (next == null || typeof next !== "object") continue;
681
+ if (Object.keys(next).length === 0) continue;
682
+ if ("now" in next && next.now !== lockedNow) {
683
+ console.error(
684
+ "circuitBreaker: ignoring mid-flight `now` change \u2014 clock override is mode-locked at construction. Prior `now` preserved."
685
+ );
686
+ continue;
687
+ }
688
+ const merged = {
689
+ ...initialOpts ?? {},
690
+ ...next,
691
+ ...lockedNow !== void 0 ? { now: lockedNow } : {}
692
+ };
693
+ applyOptions(merged);
694
+ initialOpts = merged;
695
+ }
696
+ });
697
+ } else {
698
+ applyOptions(options);
699
+ }
700
+ _lastCooldownNs = baseCooldownNs;
701
+ function getCooldownNs() {
702
+ if (!cooldownStrategy) return baseCooldownNs;
703
+ const delayNs = cooldownStrategy(_openCycle);
704
+ return delayNs !== null ? delayNs : baseCooldownNs;
705
+ }
706
+ function transitionToOpen() {
707
+ _state = "open";
708
+ _lastCooldownNs = getCooldownNs();
709
+ _lastOpenedAt = now();
710
+ _halfOpenAttempts = 0;
711
+ }
712
+ const breaker = {
713
+ canExecute() {
714
+ if (_state === "closed") return true;
715
+ if (_state === "open") {
716
+ const elapsed = now() - _lastOpenedAt;
717
+ if (elapsed >= _lastCooldownNs) {
718
+ _state = "half-open";
719
+ _halfOpenAttempts = 1;
720
+ return true;
721
+ }
722
+ return false;
723
+ }
724
+ if (_halfOpenAttempts < halfOpenMax) {
725
+ _halfOpenAttempts++;
726
+ return true;
727
+ }
728
+ return false;
729
+ },
730
+ recordSuccess() {
731
+ if (_state === "half-open") {
732
+ _state = "closed";
733
+ _failureCount = 0;
734
+ _openCycle = 0;
735
+ } else if (_state === "closed") {
736
+ _failureCount = 0;
737
+ }
738
+ },
739
+ recordFailure(_error) {
740
+ if (_state === "half-open") {
741
+ _openCycle++;
742
+ transitionToOpen();
743
+ return;
744
+ }
745
+ if (_state === "closed") {
746
+ _failureCount++;
747
+ if (_failureCount >= threshold) {
748
+ transitionToOpen();
749
+ }
750
+ }
751
+ },
752
+ get state() {
753
+ return _state;
754
+ },
755
+ get failureCount() {
756
+ return _failureCount;
757
+ },
758
+ reset() {
759
+ _state = "closed";
760
+ _failureCount = 0;
761
+ _openCycle = 0;
762
+ _halfOpenAttempts = 0;
763
+ },
764
+ dispose() {
765
+ optsUnsub?.();
766
+ }
767
+ // Internal accessors used by withBreaker for the BreakerState
768
+ // companion (DS-13.5.B). Not part of the public CircuitBreaker
769
+ // interface but exposed for the bundle wiring.
770
+ };
771
+ breaker._stateSnapshot = () => ({
772
+ status: _state,
773
+ failureCount: _failureCount,
774
+ openCycle: _openCycle,
775
+ lastOpenedAtNs: _lastOpenedAt,
776
+ halfOpenAttempts: _halfOpenAttempts,
777
+ lastCooldownNs: _lastCooldownNs
778
+ });
779
+ return breaker;
780
+ }
781
+ function withBreaker(breaker, options) {
782
+ const onOpen = options?.onOpen ?? "skip";
783
+ const callerMeta = options?.meta;
784
+ return (source) => {
785
+ const snapshot = breaker._stateSnapshot;
786
+ const initialSnapshot = snapshot ? snapshot() : {
787
+ status: breaker.state,
788
+ failureCount: breaker.failureCount,
789
+ openCycle: 0,
790
+ lastOpenedAtNs: 0,
791
+ halfOpenAttempts: 0,
792
+ lastCooldownNs: 0
793
+ };
794
+ const wrapped = (0, import_core5.node)(
795
+ [],
796
+ (_deps, a) => {
797
+ function syncState() {
798
+ const s = snapshot ? snapshot() : {
799
+ status: breaker.state,
800
+ failureCount: breaker.failureCount,
801
+ openCycle: 0,
802
+ lastOpenedAtNs: 0,
803
+ halfOpenAttempts: 0,
804
+ lastCooldownNs: 0
805
+ };
806
+ wrapped.meta.breakerState.down([[import_core5.DIRTY], [import_core5.DATA, s]]);
807
+ }
808
+ const unsub = source.subscribe((msgs) => {
809
+ for (const m of msgs) {
810
+ const t = m[0];
811
+ if (t === import_core5.DIRTY) a.down([[import_core5.DIRTY]]);
812
+ else if (t === import_core5.DATA) {
813
+ if (breaker.canExecute()) {
814
+ syncState();
815
+ a.emit(m[1]);
816
+ } else {
817
+ syncState();
818
+ if (onOpen === "error") a.down([[import_core5.ERROR, new CircuitOpenError()]]);
819
+ else a.down([[import_core5.RESOLVED]]);
820
+ }
821
+ } else if (t === import_core5.RESOLVED) a.down([[import_core5.RESOLVED]]);
822
+ else if (t === import_core5.COMPLETE) {
823
+ breaker.recordSuccess();
824
+ syncState();
825
+ a.down([[import_core5.COMPLETE]]);
826
+ } else if (t === import_core5.ERROR) {
827
+ breaker.recordFailure(msgVal(m));
828
+ syncState();
829
+ a.down([m]);
830
+ } else a.down([m]);
831
+ }
832
+ });
833
+ syncState();
834
+ return unsub;
835
+ },
836
+ {
837
+ ...operatorOpts(),
838
+ meta: {
839
+ ...callerMeta ?? {},
840
+ breakerState: initialSnapshot,
841
+ ...(0, import_core5.factoryTag)("withBreaker", { onOpen })
842
+ },
843
+ completeWhenDepsComplete: false,
844
+ initial: source.cache
845
+ }
846
+ );
847
+ return { node: wrapped, breakerState: wrapped.meta.breakerState };
848
+ };
849
+ }
850
+
851
+ // src/utils/resilience/budget-gate.ts
852
+ var import_core6 = require("@graphrefly/pure-ts/core");
853
+
854
+ // src/base/meta/domain-meta.ts
855
+ function domainMeta(domain, kind, extra) {
856
+ return {
857
+ [domain]: true,
858
+ [`${domain}_type`]: kind,
859
+ ...extra ?? {}
860
+ };
861
+ }
862
+
863
+ // src/utils/resilience/budget-gate.ts
864
+ var HeadIndexQueue = class {
865
+ buf = [];
866
+ head = 0;
867
+ get size() {
868
+ return this.buf.length - this.head;
869
+ }
870
+ push(item) {
871
+ this.buf.push(item);
872
+ }
873
+ /** O(1) — removes and returns the oldest item, or `undefined` when empty. */
874
+ shift() {
875
+ if (this.head >= this.buf.length) return void 0;
876
+ const item = this.buf[this.head];
877
+ this.buf[this.head] = void 0;
878
+ this.head++;
879
+ if (this.head > 32 && this.head * 2 > this.buf.length) {
880
+ this.buf = this.buf.slice(this.head);
881
+ this.head = 0;
882
+ }
883
+ return item;
884
+ }
885
+ clear() {
886
+ this.buf = [];
887
+ this.head = 0;
888
+ }
889
+ };
890
+ function budgetGate(source, constraints, opts) {
891
+ if (constraints.length === 0) throw new RangeError("budgetGate requires at least one constraint");
892
+ const constraintNodes = constraints.map((c) => c.node);
893
+ const allDeps = [source, ...constraintNodes];
894
+ const buffer = new HeadIndexQueue();
895
+ let paused = false;
896
+ let pendingResolved = false;
897
+ const lockId = /* @__PURE__ */ Symbol("budget-gate");
898
+ const latestValues = new Array(constraints.length);
899
+ function checkBudget() {
900
+ return constraints.every((c, i) => c.check(latestValues[i]));
901
+ }
902
+ function budgetGateStateEqual(a, b) {
903
+ if (a === b) return true;
904
+ if (a.status !== b.status) return false;
905
+ const sa = a.constraintsSnapshot;
906
+ const sb = b.constraintsSnapshot;
907
+ if (sa.length !== sb.length) return false;
908
+ for (let i = 0; i < sa.length; i++) {
909
+ const ai = sa[i];
910
+ const bi = sb[i];
911
+ if (ai === void 0 || bi === void 0) return false;
912
+ if (ai.name !== bi.name) return false;
913
+ if (ai.satisfied !== bi.satisfied) return false;
914
+ if (!Object.is(ai.value, bi.value)) return false;
915
+ }
916
+ return true;
917
+ }
918
+ const budgetGateState = (0, import_core6.node)([], {
919
+ name: "budgetGateState",
920
+ describeKind: "state",
921
+ initial: {
922
+ status: "closed",
923
+ constraintsSnapshot: constraints.map((c) => ({
924
+ name: c.name ?? c.node.name ?? "",
925
+ satisfied: false,
926
+ value: void 0
927
+ }))
928
+ },
929
+ equals: budgetGateStateEqual
930
+ });
931
+ let lastEmittedState = null;
932
+ function publishState() {
933
+ const snapshot = constraints.map((c, i) => {
934
+ const v = latestValues[i];
935
+ let satisfied = false;
936
+ try {
937
+ satisfied = c.check(v);
938
+ } catch (err) {
939
+ console.error(
940
+ `budgetGate: constraint "${c.name ?? c.node.name ?? `[${i}]`}" check threw; treating as not satisfied.`,
941
+ err
942
+ );
943
+ satisfied = false;
944
+ }
945
+ return {
946
+ name: c.name ?? c.node.name ?? "",
947
+ satisfied,
948
+ value: v
949
+ };
950
+ });
951
+ const status = snapshot.every((s) => s.satisfied) ? "open" : "closed";
952
+ const next = { status, constraintsSnapshot: snapshot };
953
+ if (lastEmittedState != null && budgetGateStateEqual(lastEmittedState, next)) {
954
+ return;
955
+ }
956
+ lastEmittedState = next;
957
+ budgetGateState.down([[import_core6.DIRTY], [import_core6.DATA, next]]);
958
+ }
959
+ function flushBuffer(actions) {
960
+ while (buffer.size > 0 && checkBudget()) {
961
+ const item = buffer.shift();
962
+ actions.emit(item);
963
+ }
964
+ if (buffer.size === 0 && pendingResolved) {
965
+ pendingResolved = false;
966
+ actions.down([[import_core6.RESOLVED]]);
967
+ }
968
+ }
969
+ const out = (0, import_core6.node)(
970
+ [],
971
+ (_data, gateActions) => {
972
+ for (let i = 0; i < constraints.length; i++) {
973
+ latestValues[i] = constraints[i].node.cache;
974
+ }
975
+ publishState();
976
+ const unsubs = [];
977
+ for (let depIdx = 0; depIdx < allDeps.length; depIdx++) {
978
+ const dep = allDeps[depIdx];
979
+ unsubs.push(
980
+ dep.subscribe((msgs) => {
981
+ for (const msg of msgs) {
982
+ _handleBudgetMessage(msg, depIdx, gateActions);
983
+ }
984
+ })
985
+ );
986
+ }
987
+ return () => {
988
+ for (const u of unsubs) u();
989
+ };
990
+ },
991
+ {
992
+ ...opts,
993
+ describeKind: "derived",
994
+ meta: domainMeta("resilience", "budget_gate", opts?.meta)
995
+ }
996
+ );
997
+ return { node: out, budgetGateState };
998
+ function _handleBudgetMessage(msg, depIndex, actions) {
999
+ const t = msg[0];
1000
+ if (depIndex === 0) {
1001
+ if (t === import_core6.DATA) {
1002
+ if (checkBudget() && buffer.size === 0) {
1003
+ actions.emit(msg[1]);
1004
+ } else {
1005
+ buffer.push(msg[1]);
1006
+ if (!paused) {
1007
+ paused = true;
1008
+ actions.up([[import_core6.PAUSE, lockId]]);
1009
+ }
1010
+ }
1011
+ return true;
1012
+ }
1013
+ if (t === import_core6.DIRTY) {
1014
+ actions.down([[import_core6.DIRTY]]);
1015
+ return true;
1016
+ }
1017
+ if (t === import_core6.RESOLVED) {
1018
+ if (buffer.size === 0) {
1019
+ actions.down([[import_core6.RESOLVED]]);
1020
+ } else {
1021
+ pendingResolved = true;
1022
+ }
1023
+ return true;
1024
+ }
1025
+ if (t === import_core6.COMPLETE || t === import_core6.ERROR) {
1026
+ while (buffer.size > 0) {
1027
+ actions.emit(buffer.shift());
1028
+ }
1029
+ pendingResolved = false;
1030
+ if (paused) {
1031
+ paused = false;
1032
+ actions.up([[import_core6.RESUME, lockId]]);
1033
+ }
1034
+ actions.down([msg]);
1035
+ return true;
1036
+ }
1037
+ return false;
1038
+ }
1039
+ if (t === import_core6.DATA) {
1040
+ latestValues[depIndex - 1] = msg[1];
1041
+ }
1042
+ if (t === import_core6.DATA || t === import_core6.RESOLVED) {
1043
+ const ok = checkBudget();
1044
+ if (ok && buffer.size > 0) {
1045
+ flushBuffer(actions);
1046
+ if (buffer.size === 0 && paused) {
1047
+ paused = false;
1048
+ actions.up([[import_core6.RESUME, lockId]]);
1049
+ }
1050
+ } else if (!ok && !paused && buffer.size > 0) {
1051
+ paused = true;
1052
+ actions.up([[import_core6.PAUSE, lockId]]);
1053
+ }
1054
+ if (t === import_core6.DATA) publishState();
1055
+ return true;
1056
+ }
1057
+ if (t === import_core6.DIRTY) {
1058
+ return true;
1059
+ }
1060
+ if (t === import_core6.ERROR) {
1061
+ actions.down([msg]);
1062
+ return true;
1063
+ }
1064
+ if (t === import_core6.COMPLETE) {
1065
+ return true;
1066
+ }
1067
+ return false;
1068
+ }
1069
+ }
1070
+
1071
+ // src/utils/resilience/fallback.ts
1072
+ var import_core7 = require("@graphrefly/pure-ts/core");
1073
+ var import_extra = require("@graphrefly/pure-ts/extra");
1074
+ function fallback(source, fb, options) {
1075
+ const callerMeta = options?.meta;
1076
+ return (0, import_core7.node)(
1077
+ (_data, a) => {
1078
+ let fallbackUnsub;
1079
+ let sourceUnsub;
1080
+ function switchToFallback() {
1081
+ sourceUnsub?.();
1082
+ sourceUnsub = void 0;
1083
+ if (isNode(fb) || isThenable(fb) || isAsyncIterable(fb)) {
1084
+ const fbNode = (0, import_extra.fromAny)(fb);
1085
+ fallbackUnsub = fbNode.subscribe((fMsgs) => {
1086
+ a.down(fMsgs);
1087
+ for (const fm of fMsgs) {
1088
+ const ft = fm[0];
1089
+ if (ft === import_core7.COMPLETE || ft === import_core7.ERROR || ft === import_core7.TEARDOWN) {
1090
+ fallbackUnsub = void 0;
1091
+ return;
1092
+ }
1093
+ }
1094
+ });
1095
+ } else {
1096
+ a.emit(fb);
1097
+ a.down([[import_core7.COMPLETE]]);
1098
+ }
1099
+ }
1100
+ sourceUnsub = source.subscribe((msgs) => {
1101
+ for (const m of msgs) {
1102
+ const t = m[0];
1103
+ if (t === import_core7.DIRTY) a.down([[import_core7.DIRTY]]);
1104
+ else if (t === import_core7.DATA) a.emit(m[1]);
1105
+ else if (t === import_core7.RESOLVED) a.down([[import_core7.RESOLVED]]);
1106
+ else if (t === import_core7.COMPLETE) a.down([[import_core7.COMPLETE]]);
1107
+ else if (t === import_core7.ERROR) {
1108
+ switchToFallback();
1109
+ return;
1110
+ } else if (t === import_core7.TEARDOWN) {
1111
+ fallbackUnsub?.();
1112
+ a.down([m]);
1113
+ return;
1114
+ } else a.down([m]);
1115
+ }
1116
+ });
1117
+ return () => {
1118
+ sourceUnsub?.();
1119
+ fallbackUnsub?.();
1120
+ };
1121
+ },
1122
+ {
1123
+ ...operatorOpts(),
1124
+ initial: source.cache,
1125
+ meta: { ...callerMeta ?? {}, ...(0, import_core7.factoryTag)("fallback") }
1126
+ }
1127
+ );
1128
+ }
1129
+
1130
+ // src/utils/resilience/rate-limiter.ts
1131
+ var import_core9 = require("@graphrefly/pure-ts/core");
1132
+
1133
+ // src/utils/resilience/adaptive-rate-limiter.ts
1134
+ var import_core8 = require("@graphrefly/pure-ts/core");
1135
+ var import_extra2 = require("@graphrefly/pure-ts/extra");
1136
+ function makeAbortError(reason) {
1137
+ const err = new Error(reason);
1138
+ err.name = "AbortError";
1139
+ return err;
1140
+ }
1141
+ function adaptiveRateLimiter(opts = {}) {
1142
+ const burst = Math.max(1, opts.burstMultiplier ?? 1);
1143
+ const clampCooldownMs = opts.clampCooldownMs ?? 6e4;
1144
+ const rpmInputNode = opts.rpm != null ? (0, import_extra2.fromAny)(opts.rpm) : (0, import_core8.node)([], { initial: Number.POSITIVE_INFINITY });
1145
+ const tpmInputNode = opts.tpm != null ? (0, import_extra2.fromAny)(opts.tpm) : (0, import_core8.node)([], { initial: Number.POSITIVE_INFINITY });
1146
+ const signalRpmCap = (0, import_core8.node)([], {
1147
+ initial: Number.POSITIVE_INFINITY,
1148
+ name: "adaptiveRateLimiter/signalRpmCap"
1149
+ });
1150
+ const signalTpmCap = (0, import_core8.node)([], {
1151
+ initial: Number.POSITIVE_INFINITY,
1152
+ name: "adaptiveRateLimiter/signalTpmCap"
1153
+ });
1154
+ const lastSignal = (0, import_core8.node)([], {
1155
+ initial: {},
1156
+ name: "adaptiveRateLimiter/lastSignal"
1157
+ });
1158
+ const effectiveRpm = (0, import_core8.node)(
1159
+ [rpmInputNode, signalRpmCap],
1160
+ (batchData, actions, ctx) => {
1161
+ const data = batchData.map(
1162
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1163
+ );
1164
+ actions.emit(Math.min(Number(data[0] ?? Infinity), Number(data[1] ?? Infinity)));
1165
+ },
1166
+ { name: "adaptiveRateLimiter/effectiveRpm", describeKind: "derived" }
1167
+ );
1168
+ const effectiveTpm = (0, import_core8.node)(
1169
+ [tpmInputNode, signalTpmCap],
1170
+ (batchData, actions, ctx) => {
1171
+ const data = batchData.map(
1172
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1173
+ );
1174
+ actions.emit(Math.min(Number(data[0] ?? Infinity), Number(data[1] ?? Infinity)));
1175
+ },
1176
+ { name: "adaptiveRateLimiter/effectiveTpm", describeKind: "derived" }
1177
+ );
1178
+ let rpmBucket = makeBucket(
1179
+ Number(rpmInputNode.cache ?? Number.POSITIVE_INFINITY),
1180
+ burst
1181
+ );
1182
+ let tpmBucket = makeBucket(
1183
+ Number(tpmInputNode.cache ?? Number.POSITIVE_INFINITY),
1184
+ burst
1185
+ );
1186
+ let rpmHardStop = false;
1187
+ let tpmHardStop = false;
1188
+ const unsubRpm = effectiveRpm.subscribe((msgs) => {
1189
+ for (const msg of msgs) {
1190
+ if (msg[0] === import_core8.DATA) {
1191
+ const v = Number(msg[1]);
1192
+ if (Number.isFinite(v) && v > 0) {
1193
+ rpmBucket = makeBucket(v, burst);
1194
+ rpmHardStop = false;
1195
+ } else if (v === Infinity) {
1196
+ rpmBucket = makeBucket(Infinity, burst);
1197
+ rpmHardStop = false;
1198
+ } else if (v <= 0) {
1199
+ rpmHardStop = true;
1200
+ }
1201
+ }
1202
+ }
1203
+ });
1204
+ const unsubTpm = effectiveTpm.subscribe((msgs) => {
1205
+ for (const msg of msgs) {
1206
+ if (msg[0] === import_core8.DATA) {
1207
+ const v = Number(msg[1]);
1208
+ if (Number.isFinite(v) && v > 0) {
1209
+ tpmBucket = makeBucket(v, burst);
1210
+ tpmHardStop = false;
1211
+ } else if (v === Infinity) {
1212
+ tpmBucket = makeBucket(Infinity, burst);
1213
+ tpmHardStop = false;
1214
+ } else if (v <= 0) {
1215
+ tpmHardStop = true;
1216
+ }
1217
+ }
1218
+ }
1219
+ });
1220
+ let throttleUntilNs = 0;
1221
+ const rpmDecayTimer = new import_core8.ResettableTimer();
1222
+ const tpmDecayTimer = new import_core8.ResettableTimer();
1223
+ let unsubAdapt;
1224
+ if (opts.adaptation != null) {
1225
+ const adaptNode = (0, import_extra2.fromAny)(opts.adaptation);
1226
+ unsubAdapt = adaptNode.subscribe((msgs) => {
1227
+ for (const msg of msgs) {
1228
+ if (msg[0] === import_core8.DATA) applySignal(msg[1]);
1229
+ }
1230
+ });
1231
+ }
1232
+ function applySignal(sig) {
1233
+ lastSignal.emit(sig);
1234
+ if (sig.rpmCap != null && Number.isFinite(sig.rpmCap) && sig.rpmCap >= 0) {
1235
+ signalRpmCap.emit(sig.rpmCap);
1236
+ if (Number.isFinite(clampCooldownMs) && clampCooldownMs > 0) {
1237
+ rpmDecayTimer.start(clampCooldownMs, () => signalRpmCap.emit(Number.POSITIVE_INFINITY));
1238
+ }
1239
+ }
1240
+ if (sig.tpmCap != null && Number.isFinite(sig.tpmCap) && sig.tpmCap >= 0) {
1241
+ signalTpmCap.emit(sig.tpmCap);
1242
+ if (Number.isFinite(clampCooldownMs) && clampCooldownMs > 0) {
1243
+ tpmDecayTimer.start(clampCooldownMs, () => signalTpmCap.emit(Number.POSITIVE_INFINITY));
1244
+ }
1245
+ }
1246
+ if (sig.retryAfterMs != null && sig.retryAfterMs > 0) {
1247
+ const resumeAt = (0, import_core8.monotonicNs)() + sig.retryAfterMs * 1e6;
1248
+ if (resumeAt > throttleUntilNs) throttleUntilNs = resumeAt;
1249
+ }
1250
+ }
1251
+ const pending = (0, import_core8.node)([], { initial: 0, name: "adaptiveRateLimiter/pending" });
1252
+ const rpmAvailableNode = (0, import_core8.node)([], {
1253
+ initial: Number.POSITIVE_INFINITY,
1254
+ name: "adaptiveRateLimiter/rpmAvailable"
1255
+ });
1256
+ const tpmAvailableNode = (0, import_core8.node)([], {
1257
+ initial: Number.POSITIVE_INFINITY,
1258
+ name: "adaptiveRateLimiter/tpmAvailable"
1259
+ });
1260
+ const bumpPending = (delta) => {
1261
+ pending.emit((pending.cache ?? 0) + delta);
1262
+ };
1263
+ const refreshAvailable = () => {
1264
+ rpmAvailableNode.emit(rpmBucket.available());
1265
+ tpmAvailableNode.emit(tpmBucket.available());
1266
+ };
1267
+ async function acquire(acquireOpts = {}) {
1268
+ const requestCost = acquireOpts.requestCost ?? 1;
1269
+ const tokenCost = acquireOpts.tokenCost ?? 0;
1270
+ const abortSignal = acquireOpts.signal;
1271
+ bumpPending(1);
1272
+ try {
1273
+ while (true) {
1274
+ if (abortSignal?.aborted) throw makeAbortError("AdaptiveRateLimiter.acquire aborted");
1275
+ const now = (0, import_core8.monotonicNs)();
1276
+ if (throttleUntilNs > now) {
1277
+ const waitMs = Math.ceil((throttleUntilNs - now) / 1e6);
1278
+ await sleepReactive(waitMs, abortSignal);
1279
+ continue;
1280
+ }
1281
+ if (requestCost > 0 && rpmHardStop || tokenCost > 0 && tpmHardStop) {
1282
+ await sleepReactive(250, abortSignal);
1283
+ continue;
1284
+ }
1285
+ const rpmAtAcquire = rpmBucket;
1286
+ const tpmAtAcquire = tpmBucket;
1287
+ const gotRpm = rpmAtAcquire.tryConsume(requestCost);
1288
+ if (!gotRpm) {
1289
+ await sleepReactive(estimateWaitMs(rpmAtAcquire, requestCost), abortSignal);
1290
+ continue;
1291
+ }
1292
+ const gotTpm = tokenCost > 0 ? tpmAtAcquire.tryConsume(tokenCost) : true;
1293
+ if (!gotTpm) {
1294
+ rpmAtAcquire.putBack(requestCost);
1295
+ await sleepReactive(estimateWaitMs(tpmAtAcquire, tokenCost), abortSignal);
1296
+ continue;
1297
+ }
1298
+ refreshAvailable();
1299
+ return;
1300
+ }
1301
+ } finally {
1302
+ bumpPending(-1);
1303
+ }
1304
+ }
1305
+ function recordUsage(delta) {
1306
+ if (delta > 0) {
1307
+ tpmBucket.tryConsume(delta);
1308
+ } else if (delta < 0) {
1309
+ tpmBucket.putBack(-delta);
1310
+ }
1311
+ refreshAvailable();
1312
+ }
1313
+ function dispose() {
1314
+ unsubRpm();
1315
+ unsubTpm();
1316
+ unsubAdapt?.();
1317
+ rpmDecayTimer.cancel();
1318
+ tpmDecayTimer.cancel();
1319
+ }
1320
+ return {
1321
+ effectiveRpm,
1322
+ effectiveTpm,
1323
+ lastSignal,
1324
+ pending,
1325
+ rpmAvailable: rpmAvailableNode,
1326
+ tpmAvailable: tpmAvailableNode,
1327
+ acquire,
1328
+ recordUsage,
1329
+ recordSignal: applySignal,
1330
+ dispose
1331
+ };
1332
+ }
1333
+ function makeBucket(perMinute, burst) {
1334
+ if (!Number.isFinite(perMinute) || perMinute === Infinity) {
1335
+ return tokenBucket(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
1336
+ }
1337
+ const capacity = Math.max(1, perMinute * burst);
1338
+ const refillPerSecond = perMinute / 60;
1339
+ return tokenBucket(capacity, refillPerSecond);
1340
+ }
1341
+ function estimateWaitMs(bucket, needed) {
1342
+ const have = bucket.available();
1343
+ const deficit = Math.max(0, needed - have);
1344
+ if (deficit <= 0) return 25;
1345
+ return Math.min(5e3, Math.max(50, deficit * 100));
1346
+ }
1347
+ function sleepReactive(ms, signal) {
1348
+ if (ms <= 0) return Promise.resolve();
1349
+ if (signal?.aborted) return Promise.reject(makeAbortError("AdaptiveRateLimiter.acquire aborted"));
1350
+ return new Promise((resolve, reject) => {
1351
+ const timer = new import_core8.ResettableTimer();
1352
+ let onAbort;
1353
+ const cleanup = () => {
1354
+ timer.cancel();
1355
+ if (signal && onAbort) signal.removeEventListener("abort", onAbort);
1356
+ };
1357
+ timer.start(ms, () => {
1358
+ cleanup();
1359
+ resolve();
1360
+ });
1361
+ if (signal) {
1362
+ onAbort = () => {
1363
+ cleanup();
1364
+ reject(makeAbortError("AdaptiveRateLimiter.acquire aborted"));
1365
+ };
1366
+ signal.addEventListener("abort", onAbort, { once: true });
1367
+ }
1368
+ });
1369
+ }
1370
+
1371
+ // src/utils/resilience/rate-limiter.ts
1372
+ function tokenBucket(capacity, refillPerSecond, opts) {
1373
+ if (capacity <= 0) throw new RangeError("capacity must be > 0");
1374
+ if (refillPerSecond < 0) throw new RangeError("refillPerSecond must be >= 0");
1375
+ const clock = opts?.clock ?? import_core9.monotonicNs;
1376
+ let tokens = capacity;
1377
+ let updatedAt = clock();
1378
+ function refill(now) {
1379
+ if (refillPerSecond > 0) {
1380
+ const elapsedNs = now - updatedAt;
1381
+ tokens = Math.min(capacity, tokens + elapsedNs / NS_PER_SEC * refillPerSecond);
1382
+ }
1383
+ updatedAt = now;
1384
+ }
1385
+ return {
1386
+ available() {
1387
+ refill(clock());
1388
+ return tokens;
1389
+ },
1390
+ tryConsume(cost = 1) {
1391
+ if (cost <= 0) return true;
1392
+ const now = clock();
1393
+ refill(now);
1394
+ if (tokens >= cost) {
1395
+ tokens -= cost;
1396
+ return true;
1397
+ }
1398
+ return false;
1399
+ },
1400
+ putBack(cost = 1) {
1401
+ if (cost <= 0) return;
1402
+ refill(clock());
1403
+ tokens = Math.min(capacity, tokens + cost);
1404
+ }
1405
+ };
1406
+ }
1407
+ var RateLimiterOverflowError = class extends Error {
1408
+ name = "RateLimiterOverflowError";
1409
+ constructor(maxBuffer) {
1410
+ super(`rateLimiter buffer overflow (maxBuffer=${maxBuffer})`);
1411
+ }
1412
+ };
1413
+ function rateLimiterStateEqual(a, b) {
1414
+ return a.status === b.status && a.droppedCount === b.droppedCount && a.pendingCount === b.pendingCount && a.paused === b.paused;
1415
+ }
1416
+ var RATE_LIMITER_INITIAL_STATE = Object.freeze({
1417
+ status: "open",
1418
+ droppedCount: 0,
1419
+ pendingCount: 0,
1420
+ paused: false
1421
+ });
1422
+ function rateLimiter(source, opts) {
1423
+ const isReactive = isNode(opts);
1424
+ if (!isReactive) {
1425
+ const o = opts;
1426
+ if (o.maxEvents <= 0) throw new RangeError("maxEvents must be > 0");
1427
+ if (o.windowNs <= 0) throw new RangeError("windowNs must be > 0");
1428
+ if (o.maxBuffer === void 0) {
1429
+ throw new RangeError(
1430
+ "rateLimiter requires explicit maxBuffer (use Infinity to opt in to unbounded)"
1431
+ );
1432
+ }
1433
+ const isUnbounded0 = o.maxBuffer === Infinity;
1434
+ if (!isUnbounded0 && (!Number.isInteger(o.maxBuffer) || o.maxBuffer < 1)) {
1435
+ throw new RangeError("maxBuffer must be a positive integer (or Infinity for unbounded)");
1436
+ }
1437
+ }
1438
+ const initialOpts = isReactive ? opts.cache : opts;
1439
+ const initialMaxBuffer = initialOpts?.maxBuffer;
1440
+ const isUnbounded = initialMaxBuffer === Infinity;
1441
+ const out = (0, import_core9.node)(
1442
+ (_data, a) => {
1443
+ let maxEvents = initialOpts?.maxEvents ?? 1;
1444
+ let windowNs = initialOpts?.windowNs ?? NS_PER_SEC;
1445
+ let maxBuffer = initialMaxBuffer ?? 1;
1446
+ let onOverflow = initialOpts?.onOverflow ?? "drop-newest";
1447
+ let refillPerSec = maxEvents * NS_PER_SEC / windowNs;
1448
+ let tokenTimeNs = NS_PER_SEC / refillPerSec;
1449
+ let bucket = tokenBucket(maxEvents, refillPerSec);
1450
+ const pending = isUnbounded ? makeArrayQueue() : ringBufferQueue(Math.max(1, maxBuffer));
1451
+ const timer = new import_core9.ResettableTimer();
1452
+ let terminated = false;
1453
+ let dropped = 0;
1454
+ const droppedNode = out.meta.droppedCount;
1455
+ const stateNode = out.meta.rateLimitState;
1456
+ let lastState = RATE_LIMITER_INITIAL_STATE;
1457
+ function syncState() {
1458
+ droppedNode.emit(dropped);
1459
+ const isPaused = pending.size > 0;
1460
+ const next = {
1461
+ status: isPaused ? "throttled" : "open",
1462
+ droppedCount: dropped,
1463
+ pendingCount: pending.size,
1464
+ paused: isPaused
1465
+ };
1466
+ if (!rateLimiterStateEqual(lastState, next)) {
1467
+ lastState = next;
1468
+ stateNode.emit(next);
1469
+ }
1470
+ }
1471
+ lastState = RATE_LIMITER_INITIAL_STATE;
1472
+ droppedNode.emit(0);
1473
+ stateNode.emit(RATE_LIMITER_INITIAL_STATE);
1474
+ const optMirror = resolveReactiveOption(
1475
+ opts,
1476
+ (next) => {
1477
+ if (terminated) return;
1478
+ if (next == null) return;
1479
+ if (typeof next === "object" && Object.keys(next).length === 0) return;
1480
+ if (!(next.maxEvents > 0) || !(next.windowNs > 0)) return;
1481
+ const nextBuf = next.maxBuffer;
1482
+ if (nextBuf === void 0) return;
1483
+ const nextUnbounded = nextBuf === Infinity;
1484
+ if (nextUnbounded !== isUnbounded) {
1485
+ return;
1486
+ }
1487
+ if (!nextUnbounded && (!Number.isInteger(nextBuf) || nextBuf < 1)) return;
1488
+ if (!nextUnbounded && nextBuf > maxBuffer) {
1489
+ console.warn(
1490
+ `rateLimiter: reactive maxBuffer grow (${maxBuffer} \u2192 ${nextBuf}) rejected. The pending ring buffer is allocated at construction; reactive maxBuffer is monotonically non-increasing. Recreate the rateLimiter with the larger cap if growth is required.`
1491
+ );
1492
+ return;
1493
+ }
1494
+ maxEvents = next.maxEvents;
1495
+ windowNs = next.windowNs;
1496
+ maxBuffer = nextBuf;
1497
+ onOverflow = next.onOverflow ?? "drop-newest";
1498
+ refillPerSec = maxEvents * NS_PER_SEC / windowNs;
1499
+ tokenTimeNs = NS_PER_SEC / refillPerSec;
1500
+ bucket = tokenBucket(maxEvents, refillPerSec);
1501
+ if (!nextUnbounded) {
1502
+ while (pending.size > maxBuffer) {
1503
+ pending.shift();
1504
+ dropped += 1;
1505
+ }
1506
+ }
1507
+ syncState();
1508
+ }
1509
+ );
1510
+ function tryEmit() {
1511
+ while (pending.size > 0) {
1512
+ if (bucket.tryConsume(1)) {
1513
+ a.emit(pending.shift());
1514
+ syncState();
1515
+ } else {
1516
+ timer.start(Math.max(1, tokenTimeNs / NS_PER_MS), tryEmit);
1517
+ return;
1518
+ }
1519
+ }
1520
+ }
1521
+ function recordDrop() {
1522
+ dropped += 1;
1523
+ syncState();
1524
+ }
1525
+ function resetForTerminal() {
1526
+ terminated = true;
1527
+ timer.cancel();
1528
+ while (pending.size > 0) pending.shift();
1529
+ dropped = 0;
1530
+ }
1531
+ const unsub = source.subscribe((msgs) => {
1532
+ for (const m of msgs) {
1533
+ if (terminated) return;
1534
+ const t = m[0];
1535
+ if (t === import_core9.DIRTY) a.down([[import_core9.DIRTY]]);
1536
+ else if (t === import_core9.DATA) {
1537
+ if (!isUnbounded && pending.size >= maxBuffer) {
1538
+ if (onOverflow === "drop-newest") {
1539
+ recordDrop();
1540
+ } else if (onOverflow === "drop-oldest") {
1541
+ pending.shift();
1542
+ pending.push(m[1]);
1543
+ recordDrop();
1544
+ } else {
1545
+ recordDrop();
1546
+ resetForTerminal();
1547
+ a.down([[import_core9.ERROR, new RateLimiterOverflowError(maxBuffer)]]);
1548
+ return;
1549
+ }
1550
+ } else {
1551
+ pending.push(m[1]);
1552
+ syncState();
1553
+ }
1554
+ tryEmit();
1555
+ } else if (t === import_core9.RESOLVED) a.down([[import_core9.RESOLVED]]);
1556
+ else if (t === import_core9.COMPLETE) {
1557
+ resetForTerminal();
1558
+ a.down([[import_core9.COMPLETE]]);
1559
+ } else if (t === import_core9.ERROR) {
1560
+ resetForTerminal();
1561
+ a.down([m]);
1562
+ } else if (t === import_core9.TEARDOWN) {
1563
+ resetForTerminal();
1564
+ a.down([m]);
1565
+ return;
1566
+ } else a.down([m]);
1567
+ }
1568
+ });
1569
+ return () => {
1570
+ terminated = true;
1571
+ timer.cancel();
1572
+ unsub();
1573
+ optMirror.unsub();
1574
+ };
1575
+ },
1576
+ {
1577
+ ...operatorOpts(),
1578
+ initial: source.cache,
1579
+ meta: {
1580
+ // Caller-supplied meta first; companion seeds + factoryTag
1581
+ // override below so they always win.
1582
+ ...isReactive ? {} : opts.meta ?? {},
1583
+ droppedCount: 0,
1584
+ rateLimitState: RATE_LIMITER_INITIAL_STATE,
1585
+ ...(0, import_core9.factoryTag)("rateLimiter", isReactive ? { reactiveOpts: true } : opts)
1586
+ }
1587
+ }
1588
+ );
1589
+ return {
1590
+ node: out,
1591
+ droppedCount: out.meta.droppedCount,
1592
+ rateLimitState: out.meta.rateLimitState
1593
+ };
1594
+ }
1595
+ function ringBufferQueue(capacity) {
1596
+ const buf = new import_core9.RingBuffer(capacity);
1597
+ return {
1598
+ push: (v) => buf.push(v),
1599
+ shift: () => buf.shift(),
1600
+ get size() {
1601
+ return buf.size;
1602
+ }
1603
+ };
1604
+ }
1605
+ function makeArrayQueue() {
1606
+ const arr = [];
1607
+ return {
1608
+ push: (v) => {
1609
+ arr.push(v);
1610
+ },
1611
+ shift: () => arr.shift(),
1612
+ get size() {
1613
+ return arr.length;
1614
+ }
1615
+ };
1616
+ }
1617
+ //# sourceMappingURL=index.cjs.map