every-plugin 2.10.1 → 3.0.0-rc.3

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 (462) hide show
  1. package/bin/every-plugin-serve.mjs +12 -0
  2. package/bin/every-plugin.mjs +59 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +1 -2
  4. package/dist/build/artifact-names.cjs +119 -0
  5. package/dist/build/artifact-names.cjs.map +1 -0
  6. package/dist/build/artifact-names.d.cts +68 -0
  7. package/dist/build/artifact-names.d.cts.map +1 -0
  8. package/dist/build/artifact-names.d.mts +68 -0
  9. package/dist/build/artifact-names.d.mts.map +1 -0
  10. package/dist/build/artifact-names.mjs +102 -0
  11. package/dist/build/artifact-names.mjs.map +1 -0
  12. package/dist/build/contract-types.cjs +89 -0
  13. package/dist/build/contract-types.cjs.map +1 -0
  14. package/dist/build/contract-types.mjs +81 -0
  15. package/dist/build/contract-types.mjs.map +1 -0
  16. package/dist/build/rspack/build-report-plugin.cjs +37 -0
  17. package/dist/build/rspack/build-report-plugin.cjs.map +1 -0
  18. package/dist/build/rspack/build-report-plugin.d.cts +18 -0
  19. package/dist/build/rspack/build-report-plugin.d.cts.map +1 -0
  20. package/dist/build/rspack/build-report-plugin.d.mts +18 -0
  21. package/dist/build/rspack/build-report-plugin.d.mts.map +1 -0
  22. package/dist/build/rspack/build-report-plugin.mjs +37 -0
  23. package/dist/build/rspack/build-report-plugin.mjs.map +1 -0
  24. package/dist/build/rspack/chunk-completeness-plugin.cjs +47 -0
  25. package/dist/build/rspack/chunk-completeness-plugin.cjs.map +1 -0
  26. package/dist/build/rspack/chunk-completeness-plugin.mjs +47 -0
  27. package/dist/build/rspack/chunk-completeness-plugin.mjs.map +1 -0
  28. package/dist/build/rspack/compose.cjs +69 -0
  29. package/dist/build/rspack/compose.cjs.map +1 -0
  30. package/dist/build/rspack/compose.d.cts +20 -0
  31. package/dist/build/rspack/compose.d.cts.map +1 -0
  32. package/dist/build/rspack/compose.d.mts +20 -0
  33. package/dist/build/rspack/compose.d.mts.map +1 -0
  34. package/dist/build/rspack/compose.mjs +65 -0
  35. package/dist/build/rspack/compose.mjs.map +1 -0
  36. package/dist/build/rspack/fix-mf-data-uri-plugin.cjs +11 -11
  37. package/dist/build/rspack/fix-mf-data-uri-plugin.cjs.map +1 -1
  38. package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts +2 -0
  39. package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts.map +1 -1
  40. package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts +2 -0
  41. package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts.map +1 -1
  42. package/dist/build/rspack/fix-mf-data-uri-plugin.mjs +11 -10
  43. package/dist/build/rspack/fix-mf-data-uri-plugin.mjs.map +1 -1
  44. package/dist/build/rspack/generated-config.cjs +35 -0
  45. package/dist/build/rspack/generated-config.cjs.map +1 -0
  46. package/dist/build/rspack/generated-config.mjs +32 -0
  47. package/dist/build/rspack/generated-config.mjs.map +1 -0
  48. package/dist/build/rspack/index.cjs +8 -5
  49. package/dist/build/rspack/index.d.cts +5 -3
  50. package/dist/build/rspack/index.d.mts +5 -3
  51. package/dist/build/rspack/index.mjs +5 -3
  52. package/dist/build/rspack/module-federation.cjs +2 -2
  53. package/dist/build/rspack/module-federation.cjs.map +1 -1
  54. package/dist/build/rspack/module-federation.mjs +1 -1
  55. package/dist/build/rspack/module-federation.mjs.map +1 -1
  56. package/dist/build/rspack/plugin.cjs +44 -69
  57. package/dist/build/rspack/plugin.cjs.map +1 -1
  58. package/dist/build/rspack/plugin.d.cts +4 -13
  59. package/dist/build/rspack/plugin.d.cts.map +1 -1
  60. package/dist/build/rspack/plugin.d.mts +4 -13
  61. package/dist/build/rspack/plugin.d.mts.map +1 -1
  62. package/dist/build/rspack/plugin.mjs +44 -69
  63. package/dist/build/rspack/plugin.mjs.map +1 -1
  64. package/dist/build/rspack/utils.cjs +7 -5
  65. package/dist/build/rspack/utils.cjs.map +1 -1
  66. package/dist/build/rspack/utils.mjs +7 -6
  67. package/dist/build/rspack/utils.mjs.map +1 -1
  68. package/dist/build/ui/factory.cjs +88 -0
  69. package/dist/build/ui/factory.cjs.map +1 -0
  70. package/dist/build/ui/factory.d.cts +11 -0
  71. package/dist/build/ui/factory.d.cts.map +1 -0
  72. package/dist/build/ui/factory.d.mts +11 -0
  73. package/dist/build/ui/factory.d.mts.map +1 -0
  74. package/dist/build/ui/factory.mjs +80 -0
  75. package/dist/build/ui/factory.mjs.map +1 -0
  76. package/dist/build/ui/generated-config.cjs +118 -0
  77. package/dist/build/ui/generated-config.cjs.map +1 -0
  78. package/dist/build/ui/generated-config.d.cts +33 -0
  79. package/dist/build/ui/generated-config.d.cts.map +1 -0
  80. package/dist/build/ui/generated-config.d.mts +33 -0
  81. package/dist/build/ui/generated-config.d.mts.map +1 -0
  82. package/dist/build/ui/generated-config.mjs +111 -0
  83. package/dist/build/ui/generated-config.mjs.map +1 -0
  84. package/dist/build/ui/hash-artifacts-plugin.cjs +61 -0
  85. package/dist/build/ui/hash-artifacts-plugin.cjs.map +1 -0
  86. package/dist/build/ui/hash-artifacts-plugin.d.cts +20 -0
  87. package/dist/build/ui/hash-artifacts-plugin.d.cts.map +1 -0
  88. package/dist/build/ui/hash-artifacts-plugin.d.mts +20 -0
  89. package/dist/build/ui/hash-artifacts-plugin.d.mts.map +1 -0
  90. package/dist/build/ui/hash-artifacts-plugin.mjs +58 -0
  91. package/dist/build/ui/hash-artifacts-plugin.mjs.map +1 -0
  92. package/dist/build/ui/index.cjs +90 -0
  93. package/dist/build/ui/index.cjs.map +1 -0
  94. package/dist/build/ui/index.d.cts +29 -0
  95. package/dist/build/ui/index.d.cts.map +1 -0
  96. package/dist/build/ui/index.d.mts +29 -0
  97. package/dist/build/ui/index.d.mts.map +1 -0
  98. package/dist/build/ui/index.mjs +68 -0
  99. package/dist/build/ui/index.mjs.map +1 -0
  100. package/dist/build/ui/manifest-plugin.cjs +37 -0
  101. package/dist/build/ui/manifest-plugin.cjs.map +1 -0
  102. package/dist/build/ui/manifest-plugin.d.cts +19 -0
  103. package/dist/build/ui/manifest-plugin.d.cts.map +1 -0
  104. package/dist/build/ui/manifest-plugin.d.mts +19 -0
  105. package/dist/build/ui/manifest-plugin.d.mts.map +1 -0
  106. package/dist/build/ui/manifest-plugin.mjs +37 -0
  107. package/dist/build/ui/manifest-plugin.mjs.map +1 -0
  108. package/dist/build/ui/rsbuild-config.cjs +203 -0
  109. package/dist/build/ui/rsbuild-config.cjs.map +1 -0
  110. package/dist/build/ui/rsbuild-config.d.cts +45 -0
  111. package/dist/build/ui/rsbuild-config.d.cts.map +1 -0
  112. package/dist/build/ui/rsbuild-config.d.mts +45 -0
  113. package/dist/build/ui/rsbuild-config.d.mts.map +1 -0
  114. package/dist/build/ui/rsbuild-config.mjs +200 -0
  115. package/dist/build/ui/rsbuild-config.mjs.map +1 -0
  116. package/dist/build/ui/stubs.cjs +107 -0
  117. package/dist/build/ui/stubs.cjs.map +1 -0
  118. package/dist/build/ui/stubs.d.cts +25 -0
  119. package/dist/build/ui/stubs.d.cts.map +1 -0
  120. package/dist/build/ui/stubs.d.mts +25 -0
  121. package/dist/build/ui/stubs.d.mts.map +1 -0
  122. package/dist/build/ui/stubs.mjs +106 -0
  123. package/dist/build/ui/stubs.mjs.map +1 -0
  124. package/dist/cli.cjs +83 -0
  125. package/dist/cli.cjs.map +1 -0
  126. package/dist/cli.d.cts +6 -0
  127. package/dist/cli.d.cts.map +1 -0
  128. package/dist/cli.d.mts +6 -0
  129. package/dist/cli.d.mts.map +1 -0
  130. package/dist/cli.mjs +82 -0
  131. package/dist/cli.mjs.map +1 -0
  132. package/dist/dev/serve.cjs +390 -0
  133. package/dist/dev/serve.cjs.map +1 -0
  134. package/dist/dev/serve.d.cts +23 -0
  135. package/dist/dev/serve.d.cts.map +1 -0
  136. package/dist/dev/serve.d.mts +23 -0
  137. package/dist/dev/serve.d.mts.map +1 -0
  138. package/dist/dev/serve.mjs +384 -0
  139. package/dist/dev/serve.mjs.map +1 -0
  140. package/dist/dev/watch-kill.cjs +39 -0
  141. package/dist/dev/watch-kill.cjs.map +1 -0
  142. package/dist/dev/watch-kill.mjs +38 -0
  143. package/dist/dev/watch-kill.mjs.map +1 -0
  144. package/dist/effect-helpers.cjs +23 -0
  145. package/dist/effect-helpers.cjs.map +1 -0
  146. package/dist/effect-helpers.d.cts +20 -0
  147. package/dist/effect-helpers.d.cts.map +1 -0
  148. package/dist/effect-helpers.d.mts +20 -0
  149. package/dist/effect-helpers.d.mts.map +1 -0
  150. package/dist/effect-helpers.mjs +22 -0
  151. package/dist/effect-helpers.mjs.map +1 -0
  152. package/dist/errors.cjs +50 -69
  153. package/dist/errors.cjs.map +1 -1
  154. package/dist/errors.d.cts +13 -96
  155. package/dist/errors.d.cts.map +1 -1
  156. package/dist/errors.d.mts +13 -96
  157. package/dist/errors.d.mts.map +1 -1
  158. package/dist/errors.mjs +16 -34
  159. package/dist/errors.mjs.map +1 -1
  160. package/dist/identity.cjs +19 -0
  161. package/dist/identity.cjs.map +1 -0
  162. package/dist/identity.d.cts +33 -0
  163. package/dist/identity.d.cts.map +1 -0
  164. package/dist/identity.d.mts +33 -0
  165. package/dist/identity.d.mts.map +1 -0
  166. package/dist/identity.mjs +16 -0
  167. package/dist/identity.mjs.map +1 -0
  168. package/dist/index.cjs +9 -5
  169. package/dist/index.d.cts +8 -6
  170. package/dist/index.d.mts +8 -6
  171. package/dist/index.mjs +6 -4
  172. package/dist/plugin.cjs +13 -26
  173. package/dist/plugin.cjs.map +1 -1
  174. package/dist/plugin.d.cts +57 -24
  175. package/dist/plugin.d.cts.map +1 -1
  176. package/dist/plugin.d.mts +58 -25
  177. package/dist/plugin.d.mts.map +1 -1
  178. package/dist/plugin.mjs +16 -29
  179. package/dist/plugin.mjs.map +1 -1
  180. package/dist/remote-entry.cjs +103 -0
  181. package/dist/remote-entry.cjs.map +1 -0
  182. package/dist/remote-entry.d.cts +53 -0
  183. package/dist/remote-entry.d.cts.map +1 -0
  184. package/dist/remote-entry.d.mts +53 -0
  185. package/dist/remote-entry.d.mts.map +1 -0
  186. package/dist/remote-entry.mjs +98 -0
  187. package/dist/remote-entry.mjs.map +1 -0
  188. package/dist/runtime/errors.cjs +159 -33
  189. package/dist/runtime/errors.cjs.map +1 -1
  190. package/dist/runtime/errors.d.cts +64 -7
  191. package/dist/runtime/errors.d.cts.map +1 -1
  192. package/dist/runtime/errors.d.mts +64 -7
  193. package/dist/runtime/errors.d.mts.map +1 -1
  194. package/dist/runtime/errors.mjs +154 -30
  195. package/dist/runtime/errors.mjs.map +1 -1
  196. package/dist/runtime/index.cjs +95 -23
  197. package/dist/runtime/index.cjs.map +1 -1
  198. package/dist/runtime/index.d.cts +16 -0
  199. package/dist/runtime/index.d.cts.map +1 -1
  200. package/dist/runtime/index.d.mts +16 -0
  201. package/dist/runtime/index.d.mts.map +1 -1
  202. package/dist/runtime/index.mjs +98 -26
  203. package/dist/runtime/index.mjs.map +1 -1
  204. package/dist/runtime/mf-config.cjs +3 -78
  205. package/dist/runtime/mf-config.cjs.map +1 -1
  206. package/dist/runtime/mf-config.d.cts +3 -49
  207. package/dist/runtime/mf-config.d.cts.map +1 -1
  208. package/dist/runtime/mf-config.d.mts +3 -49
  209. package/dist/runtime/mf-config.d.mts.map +1 -1
  210. package/dist/runtime/mf-config.mjs +5 -78
  211. package/dist/runtime/mf-config.mjs.map +1 -1
  212. package/dist/runtime/services/module-federation.service.cjs +57 -12
  213. package/dist/runtime/services/module-federation.service.cjs.map +1 -1
  214. package/dist/runtime/services/module-federation.service.d.cts +4 -13
  215. package/dist/runtime/services/module-federation.service.d.mts +4 -13
  216. package/dist/runtime/services/module-federation.service.mjs +57 -14
  217. package/dist/runtime/services/module-federation.service.mjs.map +1 -1
  218. package/dist/runtime/services/normalize.cjs +2 -22
  219. package/dist/runtime/services/normalize.d.cts +2 -21
  220. package/dist/runtime/services/normalize.d.mts +2 -21
  221. package/dist/runtime/services/normalize.mjs +2 -21
  222. package/dist/runtime/services/plugin-lifecycle.service.cjs +9 -11
  223. package/dist/runtime/services/plugin-lifecycle.service.cjs.map +1 -1
  224. package/dist/runtime/services/plugin-lifecycle.service.d.cts +3 -16
  225. package/dist/runtime/services/plugin-lifecycle.service.d.mts +3 -16
  226. package/dist/runtime/services/plugin-lifecycle.service.mjs +10 -13
  227. package/dist/runtime/services/plugin-lifecycle.service.mjs.map +1 -1
  228. package/dist/runtime/services/plugin-loader.service.cjs +56 -30
  229. package/dist/runtime/services/plugin-loader.service.cjs.map +1 -1
  230. package/dist/runtime/services/plugin-loader.service.d.cts +6 -53
  231. package/dist/runtime/services/plugin-loader.service.d.mts +6 -53
  232. package/dist/runtime/services/plugin-loader.service.mjs +55 -31
  233. package/dist/runtime/services/plugin-loader.service.mjs.map +1 -1
  234. package/dist/runtime/services/plugin.service.cjs +10 -12
  235. package/dist/runtime/services/plugin.service.cjs.map +1 -1
  236. package/dist/runtime/services/plugin.service.d.cts +14 -36
  237. package/dist/runtime/services/plugin.service.d.cts.map +1 -1
  238. package/dist/runtime/services/plugin.service.d.mts +14 -36
  239. package/dist/runtime/services/plugin.service.d.mts.map +1 -1
  240. package/dist/runtime/services/plugin.service.mjs +14 -18
  241. package/dist/runtime/services/plugin.service.mjs.map +1 -1
  242. package/dist/runtime/services/secrets.service.cjs +12 -12
  243. package/dist/runtime/services/secrets.service.cjs.map +1 -1
  244. package/dist/runtime/services/secrets.service.d.cts +3 -15
  245. package/dist/runtime/services/secrets.service.d.mts +3 -15
  246. package/dist/runtime/services/secrets.service.mjs +12 -13
  247. package/dist/runtime/services/secrets.service.mjs.map +1 -1
  248. package/dist/runtime/services/shared-identity.cjs +40 -0
  249. package/dist/runtime/services/shared-identity.cjs.map +1 -0
  250. package/dist/runtime/services/shared-identity.mjs +38 -0
  251. package/dist/runtime/services/shared-identity.mjs.map +1 -0
  252. package/dist/runtime/validation.cjs +2 -2
  253. package/dist/runtime/validation.cjs.map +1 -1
  254. package/dist/runtime/validation.mjs +2 -2
  255. package/dist/runtime/validation.mjs.map +1 -1
  256. package/dist/shared-deps-spec.cjs +384 -0
  257. package/dist/shared-deps-spec.cjs.map +1 -0
  258. package/dist/shared-deps-spec.d.cts +182 -0
  259. package/dist/shared-deps-spec.d.cts.map +1 -0
  260. package/dist/shared-deps-spec.d.mts +182 -0
  261. package/dist/shared-deps-spec.d.mts.map +1 -0
  262. package/dist/shared-deps-spec.mjs +368 -0
  263. package/dist/shared-deps-spec.mjs.map +1 -0
  264. package/dist/types.d.cts +25 -41
  265. package/dist/types.d.cts.map +1 -1
  266. package/dist/types.d.mts +25 -41
  267. package/dist/types.d.mts.map +1 -1
  268. package/dist/ui/manifest/construct.cjs +268 -0
  269. package/dist/ui/manifest/construct.cjs.map +1 -0
  270. package/dist/ui/manifest/construct.d.cts +48 -0
  271. package/dist/ui/manifest/construct.d.cts.map +1 -0
  272. package/dist/ui/manifest/construct.d.mts +48 -0
  273. package/dist/ui/manifest/construct.d.mts.map +1 -0
  274. package/dist/ui/manifest/construct.mjs +268 -0
  275. package/dist/ui/manifest/construct.mjs.map +1 -0
  276. package/dist/ui/manifest/contract.cjs +34 -0
  277. package/dist/ui/manifest/contract.cjs.map +1 -0
  278. package/dist/ui/manifest/contract.d.cts +26 -0
  279. package/dist/ui/manifest/contract.d.cts.map +1 -0
  280. package/dist/ui/manifest/contract.d.mts +26 -0
  281. package/dist/ui/manifest/contract.d.mts.map +1 -0
  282. package/dist/ui/manifest/contract.mjs +26 -0
  283. package/dist/ui/manifest/contract.mjs.map +1 -0
  284. package/dist/ui/manifest/descriptor.cjs +64 -0
  285. package/dist/ui/manifest/descriptor.cjs.map +1 -0
  286. package/dist/ui/manifest/descriptor.d.cts +60 -0
  287. package/dist/ui/manifest/descriptor.d.cts.map +1 -0
  288. package/dist/ui/manifest/descriptor.d.mts +60 -0
  289. package/dist/ui/manifest/descriptor.d.mts.map +1 -0
  290. package/dist/ui/manifest/descriptor.mjs +61 -0
  291. package/dist/ui/manifest/descriptor.mjs.map +1 -0
  292. package/dist/ui/manifest/generator.cjs +128 -0
  293. package/dist/ui/manifest/generator.cjs.map +1 -0
  294. package/dist/ui/manifest/generator.d.cts +41 -0
  295. package/dist/ui/manifest/generator.d.cts.map +1 -0
  296. package/dist/ui/manifest/generator.d.mts +41 -0
  297. package/dist/ui/manifest/generator.d.mts.map +1 -0
  298. package/dist/ui/manifest/generator.mjs +125 -0
  299. package/dist/ui/manifest/generator.mjs.map +1 -0
  300. package/dist/ui/manifest/index.cjs +35 -0
  301. package/dist/ui/manifest/index.d.cts +9 -0
  302. package/dist/ui/manifest/index.d.mts +9 -0
  303. package/dist/ui/manifest/index.mjs +9 -0
  304. package/dist/ui/manifest/manifest-schema.cjs +97 -0
  305. package/dist/ui/manifest/manifest-schema.cjs.map +1 -0
  306. package/dist/ui/manifest/manifest-schema.d.cts +132 -0
  307. package/dist/ui/manifest/manifest-schema.d.cts.map +1 -0
  308. package/dist/ui/manifest/manifest-schema.d.mts +132 -0
  309. package/dist/ui/manifest/manifest-schema.d.mts.map +1 -0
  310. package/dist/ui/manifest/manifest-schema.mjs +90 -0
  311. package/dist/ui/manifest/manifest-schema.mjs.map +1 -0
  312. package/dist/ui/manifest/mount-registry.cjs +52 -0
  313. package/dist/ui/manifest/mount-registry.cjs.map +1 -0
  314. package/dist/ui/manifest/mount-registry.d.cts +61 -0
  315. package/dist/ui/manifest/mount-registry.d.cts.map +1 -0
  316. package/dist/ui/manifest/mount-registry.d.mts +61 -0
  317. package/dist/ui/manifest/mount-registry.d.mts.map +1 -0
  318. package/dist/ui/manifest/mount-registry.mjs +48 -0
  319. package/dist/ui/manifest/mount-registry.mjs.map +1 -0
  320. package/dist/ui/manifest/nav.cjs +13 -0
  321. package/dist/ui/manifest/nav.cjs.map +1 -0
  322. package/dist/ui/manifest/nav.d.cts +34 -0
  323. package/dist/ui/manifest/nav.d.cts.map +1 -0
  324. package/dist/ui/manifest/nav.d.mts +34 -0
  325. package/dist/ui/manifest/nav.d.mts.map +1 -0
  326. package/dist/ui/manifest/nav.mjs +13 -0
  327. package/dist/ui/manifest/nav.mjs.map +1 -0
  328. package/dist/ui/manifest/route-config.cjs +33 -0
  329. package/dist/ui/manifest/route-config.cjs.map +1 -0
  330. package/dist/ui/manifest/route-config.d.cts +40 -0
  331. package/dist/ui/manifest/route-config.d.cts.map +1 -0
  332. package/dist/ui/manifest/route-config.d.mts +40 -0
  333. package/dist/ui/manifest/route-config.d.mts.map +1 -0
  334. package/dist/ui/manifest/route-config.mjs +33 -0
  335. package/dist/ui/manifest/route-config.mjs.map +1 -0
  336. package/dist/version-manifest.cjs +65 -0
  337. package/dist/version-manifest.cjs.map +1 -0
  338. package/dist/version-manifest.d.cts +52 -0
  339. package/dist/version-manifest.d.cts.map +1 -0
  340. package/dist/version-manifest.d.mts +52 -0
  341. package/dist/version-manifest.d.mts.map +1 -0
  342. package/dist/version-manifest.mjs +63 -0
  343. package/dist/version-manifest.mjs.map +1 -0
  344. package/package.json +165 -68
  345. package/skills/plugin-client/SKILL.md +24 -5
  346. package/skills/plugin-development/SKILL.md +79 -47
  347. package/skills/plugin-testing/SKILL.md +41 -12
  348. package/src/build/artifact-names.ts +117 -0
  349. package/src/build/contract-types.ts +101 -0
  350. package/src/build/rspack/build-report-plugin.ts +34 -0
  351. package/src/build/rspack/chunk-completeness-plugin.ts +57 -0
  352. package/src/build/rspack/compose.ts +87 -0
  353. package/src/build/rspack/fix-mf-data-uri-plugin.ts +23 -12
  354. package/src/build/rspack/generated-config.ts +35 -0
  355. package/src/build/rspack/index.ts +10 -5
  356. package/src/build/rspack/module-federation.ts +1 -1
  357. package/src/build/rspack/plugin.ts +103 -105
  358. package/src/build/rspack/utils.ts +8 -2
  359. package/src/build/ui/factory.ts +96 -0
  360. package/src/build/ui/generated-config.ts +133 -0
  361. package/src/build/ui/hash-artifacts-plugin.ts +79 -0
  362. package/src/build/ui/index.ts +98 -0
  363. package/src/build/ui/manifest-plugin.ts +54 -0
  364. package/src/build/ui/rsbuild-config.ts +256 -0
  365. package/src/build/ui/stubs.ts +103 -0
  366. package/src/cli.ts +100 -0
  367. package/src/dev/serve.ts +477 -0
  368. package/src/dev/watch-kill.ts +58 -0
  369. package/src/effect-helpers.ts +25 -0
  370. package/src/errors.ts +17 -18
  371. package/src/identity.ts +36 -0
  372. package/src/index.ts +4 -0
  373. package/src/plugin.ts +88 -91
  374. package/src/remote-entry.ts +171 -0
  375. package/src/runtime/errors.ts +229 -26
  376. package/src/runtime/index.ts +132 -43
  377. package/src/runtime/mf-config.ts +12 -107
  378. package/src/runtime/services/module-federation.service.ts +218 -117
  379. package/src/runtime/services/normalize.ts +1 -18
  380. package/src/runtime/services/plugin-lifecycle.service.ts +66 -75
  381. package/src/runtime/services/plugin-loader.service.ts +271 -212
  382. package/src/runtime/services/plugin.service.ts +61 -43
  383. package/src/runtime/services/secrets.service.ts +20 -15
  384. package/src/runtime/services/shared-identity.ts +68 -0
  385. package/src/runtime/validation.ts +5 -7
  386. package/src/shared-deps-spec.ts +478 -0
  387. package/src/types.ts +25 -48
  388. package/src/ui/manifest/construct.ts +403 -0
  389. package/src/ui/manifest/contract.ts +33 -0
  390. package/src/ui/manifest/descriptor.ts +96 -0
  391. package/src/ui/manifest/generator.ts +238 -0
  392. package/src/ui/manifest/index.ts +55 -0
  393. package/src/ui/manifest/manifest-schema.ts +107 -0
  394. package/src/ui/manifest/mount-registry.ts +50 -0
  395. package/src/ui/manifest/nav.ts +43 -0
  396. package/src/ui/manifest/route-config.ts +82 -0
  397. package/src/version-manifest.ts +88 -0
  398. package/dist/build/rspack/dev-server-middleware.cjs +0 -248
  399. package/dist/build/rspack/dev-server-middleware.cjs.map +0 -1
  400. package/dist/build/rspack/dev-server-middleware.mjs +0 -247
  401. package/dist/build/rspack/dev-server-middleware.mjs.map +0 -1
  402. package/dist/build/shared-deps.cjs +0 -83
  403. package/dist/build/shared-deps.cjs.map +0 -1
  404. package/dist/build/shared-deps.d.cts +0 -67
  405. package/dist/build/shared-deps.d.cts.map +0 -1
  406. package/dist/build/shared-deps.d.mts +0 -67
  407. package/dist/build/shared-deps.d.mts.map +0 -1
  408. package/dist/build/shared-deps.mjs +0 -79
  409. package/dist/build/shared-deps.mjs.map +0 -1
  410. package/dist/effect.cjs +0 -9
  411. package/dist/effect.d.cts +0 -1
  412. package/dist/effect.d.mts +0 -1
  413. package/dist/effect.mjs +0 -3
  414. package/dist/orpc-openapi.cjs +0 -17
  415. package/dist/orpc-openapi.d.cts +0 -2
  416. package/dist/orpc-openapi.d.mts +0 -2
  417. package/dist/orpc-openapi.mjs +0 -5
  418. package/dist/orpc.cjs +0 -46
  419. package/dist/orpc.d.cts +0 -7
  420. package/dist/orpc.d.mts +0 -7
  421. package/dist/orpc.mjs +0 -11
  422. package/dist/package.cjs +0 -23
  423. package/dist/package.cjs.map +0 -1
  424. package/dist/package.mjs +0 -17
  425. package/dist/package.mjs.map +0 -1
  426. package/dist/runtime/services/module-federation.service.d.cts.map +0 -1
  427. package/dist/runtime/services/module-federation.service.d.mts.map +0 -1
  428. package/dist/runtime/services/normalize.cjs.map +0 -1
  429. package/dist/runtime/services/normalize.d.cts.map +0 -1
  430. package/dist/runtime/services/normalize.d.mts.map +0 -1
  431. package/dist/runtime/services/normalize.mjs.map +0 -1
  432. package/dist/runtime/services/plugin-lifecycle.service.d.cts.map +0 -1
  433. package/dist/runtime/services/plugin-lifecycle.service.d.mts.map +0 -1
  434. package/dist/runtime/services/plugin-loader.service.d.cts.map +0 -1
  435. package/dist/runtime/services/plugin-loader.service.d.mts.map +0 -1
  436. package/dist/runtime/services/secrets.service.d.cts.map +0 -1
  437. package/dist/runtime/services/secrets.service.d.mts.map +0 -1
  438. package/dist/testing/index.cjs +0 -57
  439. package/dist/testing/index.cjs.map +0 -1
  440. package/dist/testing/index.d.cts +0 -54
  441. package/dist/testing/index.d.cts.map +0 -1
  442. package/dist/testing/index.d.mts +0 -54
  443. package/dist/testing/index.d.mts.map +0 -1
  444. package/dist/testing/index.mjs +0 -55
  445. package/dist/testing/index.mjs.map +0 -1
  446. package/dist/zod-core.cjs +0 -9
  447. package/dist/zod-core.d.cts +0 -1
  448. package/dist/zod-core.d.mts +0 -1
  449. package/dist/zod-core.mjs +0 -3
  450. package/dist/zod.cjs +0 -11
  451. package/dist/zod.d.cts +0 -2
  452. package/dist/zod.d.mts +0 -2
  453. package/dist/zod.mjs +0 -3
  454. package/src/build/rspack/dev-server-middleware.ts +0 -324
  455. package/src/build/shared-deps.ts +0 -102
  456. package/src/effect.ts +0 -1
  457. package/src/orpc-openapi.ts +0 -2
  458. package/src/orpc.ts +0 -9
  459. package/src/testing/index.ts +0 -87
  460. package/src/testing/mocks/module-federation.service.ts +0 -41
  461. package/src/zod-core.ts +0 -1
  462. package/src/zod.ts +0 -3
@@ -1,10 +1,27 @@
1
- import { ORPCError } from "@orpc/contract";
2
1
  import { Cause, Data } from "effect";
2
+ import { ORPCError } from "@orpc/server";
3
3
 
4
4
  //#region src/runtime/errors.ts
5
- var PluginRuntimeError = class extends Data.TaggedError("PluginRuntimeError") {};
5
+ var PluginRuntimeError = class extends Data.TaggedError("PluginRuntimeError") {
6
+ get message() {
7
+ return this.cause?.message ?? "Plugin operation failed";
8
+ }
9
+ };
6
10
  var ModuleFederationError = class extends Data.TaggedError("ModuleFederationError") {};
7
11
  var ValidationError = class extends Data.TaggedError("ValidationError") {};
12
+ const stringifyUnknown = (value) => {
13
+ if (value === null) return "null";
14
+ if (value === void 0) return "undefined";
15
+ if (value instanceof Error) return value.message;
16
+ if (typeof value === "string") return value;
17
+ if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
18
+ if (typeof value === "symbol") return value.description ?? "";
19
+ try {
20
+ return JSON.stringify(value) ?? "[Unserializable value]";
21
+ } catch {
22
+ return "[Unserializable value]";
23
+ }
24
+ };
8
25
  const extractErrorMessage = (error) => {
9
26
  if (!error) return "Unknown error";
10
27
  if (error instanceof Error) {
@@ -13,7 +30,25 @@ const extractErrorMessage = (error) => {
13
30
  }
14
31
  if (error instanceof AggregateError && error.errors?.length) return error.errors.map((e) => extractErrorMessage(e)).join("; ");
15
32
  if (typeof error === "object" && "message" in error) return String(error.message);
16
- return String(error);
33
+ return stringifyUnknown(error);
34
+ };
35
+ /**
36
+ * The deepest Error along the cause chain — the original throw site. Wrapper
37
+ * errors (PluginRuntimeError, ModuleFederationError) carry their own stacks
38
+ * (the wrapping frames); diagnosis needs the cause's stack (the actual
39
+ * failing module inside the evaluated remote entry).
40
+ */
41
+ const deepestErrorStack = (error) => {
42
+ let current = error;
43
+ let deepest;
44
+ let hops = 0;
45
+ while (current instanceof Error && hops < 8) {
46
+ if (current.stack) deepest = current.stack;
47
+ current = current.cause;
48
+ hops += 1;
49
+ }
50
+ if (current instanceof Error && current.stack) deepest = current.stack;
51
+ return deepest;
17
52
  };
18
53
  const formatValidationIssue = (issue, index, maxDisplay) => {
19
54
  if (index >= maxDisplay) return "";
@@ -33,7 +68,7 @@ const formatDataPreview = (data, maxLength = 100) => {
33
68
  }
34
69
  return `${str.slice(0, maxLength)}...`;
35
70
  } catch {
36
- return String(data).slice(0, maxLength);
71
+ return stringifyUnknown(data).slice(0, maxLength);
37
72
  }
38
73
  };
39
74
  const formatORPCValidationError = (error) => {
@@ -59,18 +94,31 @@ const formatORPCValidationError = (error) => {
59
94
  lines.push(`╰${"─".repeat(50)}\n`);
60
95
  return lines;
61
96
  };
97
+ const formatUnknownError = (error) => {
98
+ if (!error) return null;
99
+ const message = extractErrorMessage(error);
100
+ const lines = [];
101
+ lines.push(`\n╭─ Unhandled error ${"─".repeat(37)}`);
102
+ for (const line of message.split("\n")) lines.push(`│ ${line}`);
103
+ const stack = error instanceof Error ? error.stack?.split("\n").slice(1, 6) : void 0;
104
+ if (stack && stack.length > 0) {
105
+ lines.push(`│`);
106
+ for (const line of stack) lines.push(`│ ${line.trim()}`);
107
+ }
108
+ lines.push(`╰${"─".repeat(50)}\n`);
109
+ return lines.join("\n");
110
+ };
62
111
  const formatORPCError = (error) => {
63
- if (!(error instanceof ORPCError)) return null;
112
+ if (!(error instanceof ORPCError)) return formatUnknownError(error);
64
113
  const validationLines = formatORPCValidationError(error);
65
114
  if (validationLines) return validationLines.join("\n");
66
115
  const lines = [];
67
116
  const code = error.code || "UNKNOWN";
68
- const status = error.status || 500;
69
117
  const message = error.message || "An error occurred";
70
118
  lines.push(`\n╭─ oRPC Error ${"─".repeat(40)}`);
71
119
  const messageLines = message.split("\n");
72
120
  for (const line of messageLines) lines.push(`│ ${line}`);
73
- lines.push(`│ Code: ${code} (${status})`);
121
+ lines.push(`│ Code: ${code}`);
74
122
  lines.push(`│`);
75
123
  if (error.data) {
76
124
  if (typeof error.data === "object" && error.data !== null) {
@@ -95,38 +143,115 @@ const formatORPCError = (error) => {
95
143
  case "GATEWAY_TIMEOUT":
96
144
  lines.push(`│ → The service may be temporarily unavailable`);
97
145
  break;
98
- case "TIMEOUT":
99
- lines.push(`│ → The operation took too long`);
100
- break;
146
+ case "TIMEOUT": lines.push(`│ → The operation took too long`);
101
147
  }
102
148
  lines.push(`╰${"─".repeat(50)}\n`);
103
149
  return lines.join("\n");
104
150
  };
105
- const isRetryableError = (message) => {
106
- return [
107
- "ETIMEDOUT",
108
- "ECONNRESET",
109
- "timeout",
110
- "503",
111
- "429"
112
- ].some((p) => message.toLowerCase().includes(p.toLowerCase()));
151
+ /**
152
+ * The loader's default warning policy for declared-but-unset secrets: a
153
+ * successfully initialized plugin whose declared secret names resolved to
154
+ * nothing (missing or empty in the environment) gets one consolidated
155
+ * warning. `*_DATABASE_URL` keys are excluded — they have the shared-API-DB
156
+ * fallback, and a genuinely-missing DB URL fails initialization (a `failure`,
157
+ * not a warning). A plugin that declares its own `warnings` function opts out
158
+ * of this default.
159
+ */
160
+ const defaultMissingSecretWarnings = (pluginKey, declaredKeys, resolvedKeys) => {
161
+ const resolved = new Set(resolvedKeys);
162
+ const missing = declaredKeys.filter((key) => !resolved.has(key) && !key.endsWith("_DATABASE_URL"));
163
+ if (missing.length === 0) return [];
164
+ return [{
165
+ pluginKey,
166
+ message: missing.length === 1 ? `Declared secret ${missing[0]} is not set — features depending on it are disabled` : `${missing.length} declared secrets are not set: ${missing.join(", ")} — features depending on them are disabled`,
167
+ hint: "Set the secret(s) in your environment (.env in development); see the plugin's config schema for what each enables"
168
+ }];
113
169
  };
114
- const isRetryableORPCCode = (code) => {
115
- switch (code) {
116
- case "TOO_MANY_REQUESTS":
117
- case "SERVICE_UNAVAILABLE":
118
- case "BAD_GATEWAY":
119
- case "GATEWAY_TIMEOUT":
120
- case "TIMEOUT": return true;
121
- default: return false;
170
+ const NETWORK_RETRYABLE_PATTERNS = [
171
+ "ETIMEDOUT",
172
+ "ECONNRESET",
173
+ "timeout",
174
+ "503",
175
+ "429"
176
+ ];
177
+ const NETWORK_DEAD_PATTERNS = [
178
+ "ECONNREFUSED",
179
+ "ENOTFOUND",
180
+ "EHOSTUNREACH"
181
+ ];
182
+ const RETRYABLE_ORPC_CODES = /* @__PURE__ */ new Set([
183
+ "TOO_MANY_REQUESTS",
184
+ "SERVICE_UNAVAILABLE",
185
+ "BAD_GATEWAY",
186
+ "GATEWAY_TIMEOUT",
187
+ "TIMEOUT"
188
+ ]);
189
+ /**
190
+ * One classification for plugin lifecycle failures across MF / validation /
191
+ * network sources. This is the recovery policy — nothing in the runtime
192
+ * retries on it today by design (the host degrades and runs without a failed
193
+ * plugin); consumers (host bootstrap messages, the dev server retry loop)
194
+ * read kind / retryable / suggestion to decide what to tell the author.
195
+ */
196
+ const classifyPluginFailure = (error) => {
197
+ let current = extractFromFiberFailure(error);
198
+ let hops = 0;
199
+ while (current && typeof current === "object" && hops < 8) {
200
+ if (current instanceof ModuleFederationError) return {
201
+ kind: "mf",
202
+ retryable: false,
203
+ message: extractErrorMessage(current),
204
+ suggestion: "Run bos mf check — the deployed plugin bundle is likely stale (sharedDep / pluginVersion skew), then redeploy the plugin and bos publish --deploy --packages local"
205
+ };
206
+ if (current instanceof ValidationError) return {
207
+ kind: "validation",
208
+ retryable: false,
209
+ message: `${current.stage}: ${extractErrorMessage(current.zodError)}`,
210
+ suggestion: `Fix the plugin's ${current.stage} schema at plugins/${current.pluginId}`
211
+ };
212
+ if (current instanceof ORPCError) {
213
+ const retryableByCode = RETRYABLE_ORPC_CODES.has(current.code);
214
+ return {
215
+ kind: "network",
216
+ retryable: retryableByCode,
217
+ message: current.message,
218
+ suggestion: retryableByCode ? "The plugin procedure failed transiently — retry the call" : void 0
219
+ };
220
+ }
221
+ current = current.cause;
222
+ hops += 1;
122
223
  }
224
+ const message = extractErrorMessage(error);
225
+ const lower = message.toLowerCase();
226
+ if (NETWORK_RETRYABLE_PATTERNS.some((p) => lower.includes(p.toLowerCase()))) return {
227
+ kind: "network",
228
+ retryable: true,
229
+ message,
230
+ suggestion: "The remote may be temporarily unavailable — retry after redeploying the plugin"
231
+ };
232
+ if (NETWORK_DEAD_PATTERNS.some((p) => lower.includes(p.toLowerCase()))) return {
233
+ kind: "network",
234
+ retryable: false,
235
+ message,
236
+ suggestion: "The plugin host is unreachable — check plugins.<id> entry URLs in bos.config.json"
237
+ };
238
+ if (lower.includes("integrity") || lower.includes("sri")) return {
239
+ kind: "integrity",
240
+ retryable: true,
241
+ message,
242
+ suggestion: "The deployed bundle content does not match its recorded integrity — redeploy the plugin so bos.config.json is republished with a fresh hash"
243
+ };
244
+ return {
245
+ kind: "unknown",
246
+ retryable: false,
247
+ message
248
+ };
123
249
  };
124
250
  const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
125
251
  return new PluginRuntimeError({
126
252
  pluginId,
127
253
  operation,
128
254
  procedureName,
129
- retryable: isRetryableORPCCode(orpcError.code),
130
255
  cause: orpcError
131
256
  });
132
257
  };
@@ -148,18 +273,17 @@ const extractFromFiberFailure = (error) => {
148
273
  }
149
274
  return error;
150
275
  };
151
- const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
276
+ const toPluginRuntimeError = (error, pluginId, procedureName, operation) => {
152
277
  if (error instanceof ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
153
278
  if (error instanceof PluginRuntimeError) return error;
154
279
  return new PluginRuntimeError({
155
280
  pluginId,
156
281
  operation,
157
282
  procedureName,
158
- retryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),
159
283
  cause: error instanceof Error ? error : new Error(extractErrorMessage(error))
160
284
  });
161
285
  };
162
286
 
163
287
  //#endregion
164
- export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
288
+ export { ModuleFederationError, PluginRuntimeError, ValidationError, classifyPluginFailure, deepestErrorStack, defaultMissingSecretWarnings, extractFromFiberFailure, formatORPCError, toPluginRuntimeError, wrapORPCError };
165
289
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n readonly pluginId?: string;\n readonly operation?: string;\n readonly procedureName?: string;\n readonly cause?: Error;\n readonly retryable: boolean;\n}> {}\n\nexport class ModuleFederationError extends Data.TaggedError(\"ModuleFederationError\")<{\n readonly pluginId: string;\n readonly remoteUrl: string;\n readonly cause?: Error;\n}> {}\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n readonly pluginId: string;\n readonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n readonly zodError: z.ZodError;\n}> {}\n\nconst extractErrorMessage = (error: unknown): string => {\n if (!error) return \"Unknown error\";\n\n if (error instanceof Error) {\n if (error.message) return error.message;\n if ((error as any).cause instanceof Error) {\n return extractErrorMessage((error as any).cause);\n }\n }\n\n if (error instanceof AggregateError && error.errors?.length) {\n return error.errors.map((e) => extractErrorMessage(e)).join(\"; \");\n }\n\n if (typeof error === \"object\" && \"message\" in error) {\n return String((error as any).message);\n }\n\n return String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n if (index >= maxDisplay) return \"\";\n\n const path =\n Array.isArray(issue.path) && issue.path.length > 0\n ? issue.path.join(\".\")\n : issue.path || \"root\";\n\n const message = issue.message || \"Validation failed\";\n\n return `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n if (!data) return \"undefined\";\n\n try {\n const str = JSON.stringify(data);\n if (str.length <= maxLength) return str;\n\n if (typeof data === \"object\" && data !== null) {\n if (Array.isArray(data)) {\n return `Array(${data.length}) [...]`;\n }\n const keys = Object.keys(data);\n return `{ ${keys.slice(0, 3).join(\", \")}${keys.length > 3 ? \", ...\" : \"\"} }`;\n }\n\n return `${str.slice(0, maxLength)}...`;\n } catch {\n return String(data).slice(0, maxLength);\n }\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n const cause = error?.cause || error;\n\n if (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n return null;\n }\n\n const lines: string[] = [];\n const errorType = error?.message || cause?.message || \"Validation failed\";\n\n lines.push(`\\n╭─ oRPC Validation Error ${\"─\".repeat(30)}`);\n lines.push(`│ ${errorType}`);\n lines.push(`│`);\n\n const maxDisplay = 10;\n const totalIssues = cause.issues.length;\n\n lines.push(`│ Issues (${totalIssues}):`);\n\n const displayedIssues = cause.issues.slice(0, maxDisplay);\n displayedIssues.forEach((issue: any, idx: number) => {\n const formatted = formatValidationIssue(issue, idx, maxDisplay);\n if (formatted) lines.push(formatted);\n });\n\n if (totalIssues > maxDisplay) {\n lines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n }\n\n if (cause.data !== undefined) {\n lines.push(`│`);\n lines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n\n return lines;\n};\n\nexport const formatORPCError = (error: any): string | null => {\n if (!(error instanceof ORPCError)) {\n return null;\n }\n\n const validationLines = formatORPCValidationError(error);\n if (validationLines) {\n return validationLines.join(\"\\n\");\n }\n\n const lines: string[] = [];\n const code = error.code || \"UNKNOWN\";\n const status = error.status || 500;\n const message = error.message || \"An error occurred\";\n\n lines.push(`\\n╭─ oRPC Error ${\"─\".repeat(40)}`);\n const messageLines = message.split(\"\\n\");\n for (const line of messageLines) {\n lines.push(`│ ${line}`);\n }\n lines.push(`│ Code: ${code} (${status})`);\n lines.push(`│`);\n\n if (error.data) {\n const dataType = typeof error.data;\n if (dataType === \"object\" && error.data !== null) {\n if (\"retryAfter\" in error.data) {\n lines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n }\n if (\"remainingRequests\" in error.data) {\n lines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n }\n if (\"host\" in error.data) {\n lines.push(`│ Host: ${error.data.host}`);\n }\n if (\"port\" in error.data) {\n lines.push(`│ Port: ${error.data.port}`);\n }\n if (\"suggestion\" in error.data) {\n lines.push(`│ → ${error.data.suggestion}`);\n }\n if (\"resource\" in error.data) {\n lines.push(`│ Resource: ${error.data.resource}`);\n }\n if (\"resourceId\" in error.data) {\n lines.push(`│ ID: ${error.data.resourceId}`);\n }\n }\n }\n\n switch (code) {\n case \"UNAUTHORIZED\":\n lines.push(`│ → Check your API key or credentials`);\n break;\n case \"TOO_MANY_REQUESTS\":\n lines.push(`│ → Wait before retrying`);\n break;\n case \"SERVICE_UNAVAILABLE\":\n case \"BAD_GATEWAY\":\n case \"GATEWAY_TIMEOUT\":\n lines.push(`│ → The service may be temporarily unavailable`);\n break;\n case \"TIMEOUT\":\n lines.push(`│ → The operation took too long`);\n break;\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n return lines.join(\"\\n\");\n};\n\nconst isRetryableError = (message: string): boolean => {\n const retryablePatterns = [\"ETIMEDOUT\", \"ECONNRESET\", \"timeout\", \"503\", \"429\"];\n return retryablePatterns.some((p) => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n switch (code) {\n case \"TOO_MANY_REQUESTS\":\n case \"SERVICE_UNAVAILABLE\":\n case \"BAD_GATEWAY\":\n case \"GATEWAY_TIMEOUT\":\n case \"TIMEOUT\":\n return true;\n default:\n return false;\n }\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n orpcError: ORPCError<string, unknown>,\n pluginId?: string,\n procedureName?: string,\n operation?: string,\n): PluginRuntimeError => {\n return new PluginRuntimeError({\n pluginId,\n operation,\n procedureName,\n retryable: isRetryableORPCCode(orpcError.code),\n cause: orpcError as Error,\n });\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n if (!error || typeof error !== \"object\") return error;\n\n if (\"cause\" in error) {\n const cause = (error as { cause?: unknown }).cause;\n\n if (cause && typeof cause === \"object\" && \"_tag\" in cause) {\n try {\n const squashed = Cause.squash(cause as Cause.Cause<unknown>);\n if (squashed instanceof ORPCError) {\n return squashed;\n }\n return squashed;\n } catch {\n // Not a valid Cause\n }\n }\n\n if (cause instanceof ORPCError) {\n return cause;\n }\n }\n\n return error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n error: unknown,\n pluginId?: string,\n procedureName?: string,\n operation?: string,\n defaultRetryable = false,\n): PluginRuntimeError => {\n if (error instanceof ORPCError) {\n return wrapORPCError(error, pluginId, procedureName, operation);\n }\n\n if (error instanceof PluginRuntimeError) {\n return error;\n }\n\n return new PluginRuntimeError({\n pluginId,\n operation,\n procedureName,\n retryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n cause: error instanceof Error ? error : new Error(extractErrorMessage(error)),\n });\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAb,cAAwC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,CAAC,MAAM,MAAM,QAAQ,YAAY,CAAC,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACtF;AAGA,MAAa,uBAAuB,SAA0B;CAC5D,QAAQ,MAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAGA,MAAa,iBACX,WACA,UACA,eACA,cACuB;CACvB,OAAO,IAAI,mBAAmB;EAC5B;EACA;EACA;EACA,WAAW,oBAAoB,UAAU,IAAI;EAC7C,OAAO;CACT,CAAC;AACH;;;;;;AAOA,MAAa,2BAA2B,UAA4B;CAClE,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;CAEhD,IAAI,WAAW,OAAO;EACpB,MAAM,QAAS,MAA8B;EAE7C,IAAI,SAAS,OAAO,UAAU,YAAY,UAAU,OAClD,IAAI;GACF,MAAM,WAAW,MAAM,OAAO,KAA6B;GAC3D,IAAI,oBAAoB,WACtB,OAAO;GAET,OAAO;EACT,QAAQ,CAER;EAGF,IAAI,iBAAiB,WACnB,OAAO;CAEX;CAEA,OAAO;AACT;AAGA,MAAa,wBACX,OACA,UACA,eACA,WACA,mBAAmB,UACI;CACvB,IAAI,iBAAiB,WACnB,OAAO,cAAc,OAAO,UAAU,eAAe,SAAS;CAGhE,IAAI,iBAAiB,oBACnB,OAAO;CAGT,OAAO,IAAI,mBAAmB;EAC5B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,oBAAoB,KAAK,CAAC;EAC1E,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,KAAK,CAAC;CAC9E,CAAC;AACH"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/server\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n readonly pluginId?: string;\n readonly operation?: string;\n readonly procedureName?: string;\n readonly cause?: Error;\n}> {\n override get message() {\n return this.cause?.message ?? \"Plugin operation failed\";\n }\n}\n\nexport class ModuleFederationError extends Data.TaggedError(\"ModuleFederationError\")<{\n readonly pluginId: string;\n readonly remoteUrl: string;\n readonly cause?: Error;\n}> {}\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n readonly pluginId: string;\n readonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n readonly zodError: z.ZodError;\n}> {}\n\nconst stringifyUnknown = (value: unknown): string => {\n if (value === null) return \"null\";\n if (value === undefined) return \"undefined\";\n if (value instanceof Error) return value.message;\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"bigint\" || typeof value === \"boolean\") {\n return `${value}`;\n }\n if (typeof value === \"symbol\") return value.description ?? \"\";\n try {\n return JSON.stringify(value) ?? \"[Unserializable value]\";\n } catch {\n return \"[Unserializable value]\";\n }\n};\n\nconst extractErrorMessage = (error: unknown): string => {\n if (!error) return \"Unknown error\";\n\n if (error instanceof Error) {\n if (error.message) return error.message;\n if ((error as any).cause instanceof Error) {\n return extractErrorMessage((error as any).cause);\n }\n }\n\n if (error instanceof AggregateError && error.errors?.length) {\n return error.errors.map((e) => extractErrorMessage(e)).join(\"; \");\n }\n\n if (typeof error === \"object\" && \"message\" in error) {\n return String((error as any).message);\n }\n\n return stringifyUnknown(error);\n};\n\n/**\n * The deepest Error along the cause chain — the original throw site. Wrapper\n * errors (PluginRuntimeError, ModuleFederationError) carry their own stacks\n * (the wrapping frames); diagnosis needs the cause's stack (the actual\n * failing module inside the evaluated remote entry).\n */\nexport const deepestErrorStack = (error: unknown): string | undefined => {\n let current = error;\n let deepest: string | undefined;\n let hops = 0;\n while (current instanceof Error && hops < 8) {\n if (current.stack) deepest = current.stack;\n current = (current as { cause?: unknown }).cause as unknown;\n hops += 1;\n }\n if (current instanceof Error && current.stack) deepest = current.stack;\n return deepest;\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n if (index >= maxDisplay) return \"\";\n\n const path =\n Array.isArray(issue.path) && issue.path.length > 0\n ? issue.path.join(\".\")\n : issue.path || \"root\";\n\n const message = issue.message || \"Validation failed\";\n\n return `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n if (!data) return \"undefined\";\n\n try {\n const str = JSON.stringify(data);\n if (str.length <= maxLength) return str;\n\n if (typeof data === \"object\" && data !== null) {\n if (Array.isArray(data)) {\n return `Array(${data.length}) [...]`;\n }\n const keys = Object.keys(data);\n return `{ ${keys.slice(0, 3).join(\", \")}${keys.length > 3 ? \", ...\" : \"\"} }`;\n }\n\n return `${str.slice(0, maxLength)}...`;\n } catch {\n return stringifyUnknown(data).slice(0, maxLength);\n }\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n const cause = error?.cause || error;\n\n if (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n return null;\n }\n\n const lines: string[] = [];\n const errorType = error?.message || cause?.message || \"Validation failed\";\n\n lines.push(`\\n╭─ oRPC Validation Error ${\"─\".repeat(30)}`);\n lines.push(`│ ${errorType}`);\n lines.push(`│`);\n\n const maxDisplay = 10;\n const totalIssues = cause.issues.length;\n\n lines.push(`│ Issues (${totalIssues}):`);\n\n const displayedIssues = cause.issues.slice(0, maxDisplay);\n displayedIssues.forEach((issue: any, idx: number) => {\n const formatted = formatValidationIssue(issue, idx, maxDisplay);\n if (formatted) lines.push(formatted);\n });\n\n if (totalIssues > maxDisplay) {\n lines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n }\n\n if (cause.data !== undefined) {\n lines.push(`│`);\n lines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n\n return lines;\n};\n\nconst formatUnknownError = (error: any): string | null => {\n if (!error) return null;\n const message = extractErrorMessage(error);\n const lines: string[] = [];\n lines.push(`\\n╭─ Unhandled error ${\"─\".repeat(37)}`);\n for (const line of message.split(\"\\n\")) {\n lines.push(`│ ${line}`);\n }\n const stack = error instanceof Error ? error.stack?.split(\"\\n\").slice(1, 6) : undefined;\n if (stack && stack.length > 0) {\n lines.push(`│`);\n for (const line of stack) {\n lines.push(`│ ${line.trim()}`);\n }\n }\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n return lines.join(\"\\n\");\n};\n\nexport const formatORPCError = (error: any): string | null => {\n if (!(error instanceof ORPCError)) {\n // Unknown errors used to return null, leaving internal failures (e.g. a\n // storage backend throw) invisible in host logs while oRPC serialized\n // them client-side as a bare INTERNAL_SERVER_ERROR.\n return formatUnknownError(error);\n }\n\n const validationLines = formatORPCValidationError(error);\n if (validationLines) {\n return validationLines.join(\"\\n\");\n }\n\n const lines: string[] = [];\n const code = error.code || \"UNKNOWN\";\n const message = error.message || \"An error occurred\";\n\n lines.push(`\\n╭─ oRPC Error ${\"─\".repeat(40)}`);\n const messageLines = message.split(\"\\n\");\n for (const line of messageLines) {\n lines.push(`│ ${line}`);\n }\n lines.push(`│ Code: ${code}`);\n lines.push(`│`);\n\n if (error.data) {\n const dataType = typeof error.data;\n if (dataType === \"object\" && error.data !== null) {\n if (\"retryAfter\" in error.data) {\n lines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n }\n if (\"remainingRequests\" in error.data) {\n lines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n }\n if (\"host\" in error.data) {\n lines.push(`│ Host: ${error.data.host}`);\n }\n if (\"port\" in error.data) {\n lines.push(`│ Port: ${error.data.port}`);\n }\n if (\"suggestion\" in error.data) {\n lines.push(`│ → ${error.data.suggestion}`);\n }\n if (\"resource\" in error.data) {\n lines.push(`│ Resource: ${error.data.resource}`);\n }\n if (\"resourceId\" in error.data) {\n lines.push(`│ ID: ${error.data.resourceId}`);\n }\n }\n }\n\n switch (code) {\n case \"UNAUTHORIZED\":\n lines.push(`│ → Check your API key or credentials`);\n break;\n case \"TOO_MANY_REQUESTS\":\n lines.push(`│ → Wait before retrying`);\n break;\n case \"SERVICE_UNAVAILABLE\":\n case \"BAD_GATEWAY\":\n case \"GATEWAY_TIMEOUT\":\n lines.push(`│ → The service may be temporarily unavailable`);\n break;\n case \"TIMEOUT\":\n lines.push(`│ → The operation took too long`);\n break;\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n return lines.join(\"\\n\");\n};\n\nexport type PluginFailureKind =\n | \"mf\"\n | \"integrity\"\n | \"config\"\n | \"validation\"\n | \"network\"\n | \"unknown\";\n\nexport interface PluginFailureClassification {\n kind: PluginFailureKind;\n retryable: boolean;\n message: string;\n suggestion?: string;\n}\n\n/**\n * Structured report of one plugin-load failure, built by a loader (the host's\n * plugin boot, the dev server) from a `PluginFailureClassification` plus\n * loader context. This is the shape health endpoints and dashboards consume —\n * keep it serializable.\n */\nexport interface PluginLoadFailureInfo {\n /** loader-side key (host entry key, dev plugin id) */\n pluginKey: string;\n pluginUrl?: string;\n /** failing runtime stage when the cause is stage-attributed */\n operation?: string;\n kind: string;\n retryable: boolean;\n message: string;\n suggestion?: string;\n /** loader context: which env secret the plugin's DB binding expects */\n dbSecret?: string;\n dbUrlMasked?: string;\n}\n\n/**\n * Structured, serializable warning surfaced alongside plugin failures in\n * health endpoints and dashboards. Warnings are non-fatal: the plugin loaded\n * and initialized successfully, but runs with reduced functionality (e.g. an\n * optional secret was not set, so the feature depending on it is disabled).\n */\nexport interface PluginWarningInfo {\n /** loader-side key (host entry key, dev plugin id) */\n pluginKey: string;\n message: string;\n hint?: string;\n}\n\n/**\n * The loader's default warning policy for declared-but-unset secrets: a\n * successfully initialized plugin whose declared secret names resolved to\n * nothing (missing or empty in the environment) gets one consolidated\n * warning. `*_DATABASE_URL` keys are excluded — they have the shared-API-DB\n * fallback, and a genuinely-missing DB URL fails initialization (a `failure`,\n * not a warning). A plugin that declares its own `warnings` function opts out\n * of this default.\n */\nexport const defaultMissingSecretWarnings = (\n pluginKey: string,\n declaredKeys: readonly string[],\n resolvedKeys: readonly string[],\n): PluginWarningInfo[] => {\n const resolved = new Set(resolvedKeys);\n const missing = declaredKeys.filter(\n (key) => !resolved.has(key) && !key.endsWith(\"_DATABASE_URL\"),\n );\n if (missing.length === 0) return [];\n return [\n {\n pluginKey,\n message:\n missing.length === 1\n ? `Declared secret ${missing[0]} is not set — features depending on it are disabled`\n : `${missing.length} declared secrets are not set: ${missing.join(\", \")} — features depending on them are disabled`,\n hint: \"Set the secret(s) in your environment (.env in development); see the plugin's config schema for what each enables\",\n },\n ];\n};\n\nconst NETWORK_RETRYABLE_PATTERNS = [\"ETIMEDOUT\", \"ECONNRESET\", \"timeout\", \"503\", \"429\"] as const;\nconst NETWORK_DEAD_PATTERNS = [\"ECONNREFUSED\", \"ENOTFOUND\", \"EHOSTUNREACH\"] as const;\nconst RETRYABLE_ORPC_CODES = new Set([\n \"TOO_MANY_REQUESTS\",\n \"SERVICE_UNAVAILABLE\",\n \"BAD_GATEWAY\",\n \"GATEWAY_TIMEOUT\",\n \"TIMEOUT\",\n]);\n\n/**\n * One classification for plugin lifecycle failures across MF / validation /\n * network sources. This is the recovery policy — nothing in the runtime\n * retries on it today by design (the host degrades and runs without a failed\n * plugin); consumers (host bootstrap messages, the dev server retry loop)\n * read kind / retryable / suggestion to decide what to tell the author.\n */\nexport const classifyPluginFailure = (error: unknown): PluginFailureClassification => {\n let current: unknown = extractFromFiberFailure(error);\n let hops = 0;\n while (current && typeof current === \"object\" && hops < 8) {\n if (current instanceof ModuleFederationError) {\n return {\n kind: \"mf\",\n retryable: false,\n message: extractErrorMessage(current),\n suggestion:\n \"Run bos mf check — the deployed plugin bundle is likely stale (sharedDep / pluginVersion skew), then redeploy the plugin and bos publish --deploy --packages local\",\n };\n }\n if (current instanceof ValidationError) {\n return {\n kind: \"validation\",\n retryable: false,\n message: `${current.stage}: ${extractErrorMessage(current.zodError)}`,\n suggestion: `Fix the plugin's ${current.stage} schema at plugins/${current.pluginId}`,\n };\n }\n if (current instanceof ORPCError) {\n const retryableByCode = RETRYABLE_ORPC_CODES.has(current.code);\n return {\n kind: \"network\",\n retryable: retryableByCode,\n message: current.message,\n suggestion: retryableByCode\n ? \"The plugin procedure failed transiently — retry the call\"\n : undefined,\n };\n }\n current = (current as { cause?: unknown }).cause;\n hops += 1;\n }\n\n const message = extractErrorMessage(error);\n const lower = message.toLowerCase();\n\n if (NETWORK_RETRYABLE_PATTERNS.some((p) => lower.includes(p.toLowerCase()))) {\n return {\n kind: \"network\",\n retryable: true,\n message,\n suggestion: \"The remote may be temporarily unavailable — retry after redeploying the plugin\",\n };\n }\n if (NETWORK_DEAD_PATTERNS.some((p) => lower.includes(p.toLowerCase()))) {\n return {\n kind: \"network\",\n retryable: false,\n message,\n suggestion:\n \"The plugin host is unreachable — check plugins.<id> entry URLs in bos.config.json\",\n };\n }\n if (lower.includes(\"integrity\") || lower.includes(\"sri\")) {\n return {\n kind: \"integrity\",\n retryable: true,\n message,\n suggestion:\n \"The deployed bundle content does not match its recorded integrity — redeploy the plugin so bos.config.json is republished with a fresh hash\",\n };\n }\n\n return { kind: \"unknown\", retryable: false, message };\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n orpcError: ORPCError<string, unknown>,\n pluginId?: string,\n procedureName?: string,\n operation?: string,\n): PluginRuntimeError => {\n return new PluginRuntimeError({\n pluginId,\n operation,\n procedureName,\n cause: orpcError as Error,\n });\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n if (!error || typeof error !== \"object\") return error;\n\n if (\"cause\" in error) {\n const cause = (error as { cause?: unknown }).cause;\n\n if (cause && typeof cause === \"object\" && \"_tag\" in cause) {\n try {\n const squashed = Cause.squash(cause as unknown as Cause.Cause<unknown>);\n if (squashed instanceof ORPCError) {\n return squashed;\n }\n return squashed;\n } catch {\n // Not a valid Cause\n }\n }\n\n if (cause instanceof ORPCError) {\n return cause;\n }\n }\n\n return error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n error: unknown,\n pluginId?: string,\n procedureName?: string,\n operation?: string,\n): PluginRuntimeError => {\n if (error instanceof ORPCError) {\n return wrapORPCError(error, pluginId, procedureName, operation);\n }\n\n if (error instanceof PluginRuntimeError) {\n return error;\n }\n\n return new PluginRuntimeError({\n pluginId,\n operation,\n procedureName,\n cause: error instanceof Error ? error : new Error(extractErrorMessage(error)),\n });\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAb,cAAwC,KAAK,YAAY,oBAAoB,CAAC,CAK3E;CACD,IAAa,UAAU;EACrB,OAAO,KAAK,OAAO,WAAW;CAChC;AACF;AAEA,IAAa,wBAAb,cAA2C,KAAK,YAAY,uBAAuB,CAAC,CAIjF,CAAC;AAEJ,IAAa,kBAAb,cAAqC,KAAK,YAAY,iBAAiB,CAAC,CAIrE,CAAC;AAEJ,MAAM,oBAAoB,UAA2B;CACnD,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,UAAU,QAAW,OAAO;CAChC,IAAI,iBAAiB,OAAO,OAAO,MAAM;CACzC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,OAAO,GAAG;CAEZ,IAAI,OAAO,UAAU,UAAU,OAAO,MAAM,eAAe;CAC3D,IAAI;EACF,OAAO,KAAK,UAAU,KAAK,KAAK;CAClC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,uBAAuB,UAA2B;CACtD,IAAI,CAAC,OAAO,OAAO;CAEnB,IAAI,iBAAiB,OAAO;EAC1B,IAAI,MAAM,SAAS,OAAO,MAAM;EAChC,IAAK,MAAc,iBAAiB,OAClC,OAAO,oBAAqB,MAAc,KAAK;CAEnD;CAEA,IAAI,iBAAiB,kBAAkB,MAAM,QAAQ,QACnD,OAAO,MAA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,SAAS;CAGhE,IAAI,iBAAiB,oBACnB,OAAO;CAGT,OAAO,IAAI,mBAAmB;EAC5B;EACA;EACA;EACA,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,KAAK,CAAC;CAC9E,CAAC;AACH"}
@@ -1,35 +1,85 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_errors = require('./errors.cjs');
3
+ const require_build_artifact_names = require('../build/artifact-names.cjs');
3
4
  const require_plugin_service = require('./services/plugin.service.cjs');
5
+ require("@orpc/openapi/extensions/route");
4
6
  let effect = require("effect");
5
7
  let _orpc_server = require("@orpc/server");
8
+ require("@orpc/experimental-effect/extensions/effect");
6
9
 
7
10
  //#region src/runtime/index.ts
11
+ const MAX_CACHE_KEY_DEPTH = 32;
8
12
  var PluginRuntime = class {
9
13
  runtime;
10
14
  registry;
11
15
  __registryType;
12
16
  pluginCache = /* @__PURE__ */ new Map();
17
+ routerCache = /* @__PURE__ */ new Map();
18
+ cacheLeafIds = /* @__PURE__ */ new WeakMap();
19
+ nextCacheLeafId = 0;
13
20
  constructor(runtime, registry) {
14
21
  this.runtime = runtime;
15
22
  this.registry = registry;
16
23
  }
24
+ /**
25
+ * Cache key for plugin instances: JSON-equal configs share one plugin
26
+ * instance (variables and secrets originate from bos.config.json, so they
27
+ * are JSON values). Values outside the JSON domain follow Effect's Hash
28
+ * semantics — symbols key by description, functions and class instances by
29
+ * reference identity — and the host creates its pluginsClient map once per
30
+ * boot, making identity the correct equivalence for function-bearing
31
+ * configs.
32
+ */
17
33
  generateCacheKey(pluginId, config) {
18
- return `${pluginId}:${effect.Hash.structure(config).toString()}`;
34
+ return `${pluginId}:${this.canonicalizeConfig(config, 0, /* @__PURE__ */ new Set())}`;
35
+ }
36
+ canonicalizeConfig(value, depth, ancestors) {
37
+ switch (typeof value) {
38
+ case "undefined": return "undefined";
39
+ case "string": return `string:${JSON.stringify(value)}`;
40
+ case "number": return `number:${Object.is(value, -0) ? "-0" : String(value)}`;
41
+ case "bigint": return `bigint:${value.toString()}`;
42
+ case "boolean": return `boolean:${value}`;
43
+ case "symbol": return `symbol:${String(value)}`;
44
+ case "function": return `ref:${this.getCacheLeafId(value)}`;
45
+ case "object": {
46
+ if (value === null) return "null";
47
+ if (ancestors.has(value) || depth >= MAX_CACHE_KEY_DEPTH) return `ref:${this.getCacheLeafId(value)}`;
48
+ if (Array.isArray(value)) {
49
+ ancestors.add(value);
50
+ const serialized = `[${value.map((item) => this.canonicalizeConfig(item, depth + 1, ancestors)).join(",")}]`;
51
+ ancestors.delete(value);
52
+ return serialized;
53
+ }
54
+ const prototype = Object.getPrototypeOf(value);
55
+ if (prototype !== Object.prototype && prototype !== null) return `ref:${this.getCacheLeafId(value)}`;
56
+ const record = value;
57
+ ancestors.add(value);
58
+ const serialized = `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${this.canonicalizeConfig(record[key], depth + 1, ancestors)}`).join(",")}}`;
59
+ ancestors.delete(value);
60
+ return serialized;
61
+ }
62
+ }
63
+ }
64
+ getCacheLeafId(value) {
65
+ const existing = this.cacheLeafIds.get(value);
66
+ if (existing !== void 0) return existing;
67
+ const id = this.nextCacheLeafId++;
68
+ this.cacheLeafIds.set(value, id);
69
+ return id;
19
70
  }
20
71
  validatePluginId(pluginId) {
21
72
  if (!(pluginId in this.registry)) return effect.Effect.fail(new require_errors.PluginRuntimeError({
22
73
  pluginId: String(pluginId),
23
74
  operation: "validate-plugin-id",
24
- cause: /* @__PURE__ */ new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),
25
- retryable: false
75
+ cause: /* @__PURE__ */ new Error(`Plugin ID '${String(pluginId)}' not found in registry.`)
26
76
  }));
27
77
  return effect.Effect.succeed(String(pluginId));
28
78
  }
29
79
  async runPromise(effect$1) {
30
80
  const exit = await this.runtime.runPromiseExit(effect$1);
31
81
  if (effect.Exit.isFailure(exit)) {
32
- const error = effect.Cause.failureOption(exit.cause);
82
+ const error = effect.Cause.findErrorOption(exit.cause);
33
83
  if (effect.Option.isSome(error)) throw error.value;
34
84
  throw effect.Cause.squash(exit.cause);
35
85
  }
@@ -42,7 +92,7 @@ var PluginRuntime = class {
42
92
  });
43
93
  let cachedPlugin = this.pluginCache.get(cacheKey);
44
94
  if (!cachedPlugin) {
45
- const operation = effect.Effect.gen(this, function* () {
95
+ const operation = effect.Effect.gen({ self: this }, function* () {
46
96
  const pluginService = yield* require_plugin_service.PluginService;
47
97
  const validatedId = yield* this.validatePluginId(pluginId);
48
98
  const ctor = yield* pluginService.loadPlugin(validatedId);
@@ -50,19 +100,32 @@ var PluginRuntime = class {
50
100
  const initialized = yield* pluginService.initializePlugin(instance, config, plugins);
51
101
  yield* pluginService.registerPlugin(initialized);
52
102
  return initialized;
53
- }).pipe(effect.Effect.annotateLogs({ plugin: pluginId }), effect.Effect.provide(this.runtime));
54
- cachedPlugin = effect.Effect.cached(operation).pipe(effect.Effect.flatten);
103
+ });
104
+ cachedPlugin = this.runPromise(operation);
55
105
  this.pluginCache.set(cacheKey, cachedPlugin);
56
106
  }
57
107
  let initialized;
58
108
  try {
59
- initialized = await this.runPromise(cachedPlugin);
109
+ initialized = await cachedPlugin;
60
110
  } catch (error) {
61
- this.pluginCache.delete(cacheKey);
111
+ if (this.pluginCache.get(cacheKey) === cachedPlugin) {
112
+ this.pluginCache.delete(cacheKey);
113
+ this.routerCache.delete(cacheKey);
114
+ }
62
115
  throw error;
63
116
  }
64
- const router = initialized.plugin.createRouter(initialized.context);
65
- const createClient = (context) => (0, _orpc_server.createRouterClient)(router, { context: context ?? {} });
117
+ let router = this.routerCache.get(cacheKey);
118
+ if (!router) try {
119
+ router = initialized.plugin.createRouter(plugins ?? {});
120
+ this.routerCache.set(cacheKey, router);
121
+ } catch (error) {
122
+ await this.evictPlugin(pluginId, config, plugins);
123
+ throw error;
124
+ }
125
+ const createClient = (context) => (0, _orpc_server.createRouterClient)(router, { context: {
126
+ ...context,
127
+ "effect/context": initialized.effectContext
128
+ } });
66
129
  return {
67
130
  createClient,
68
131
  router,
@@ -73,13 +136,13 @@ var PluginRuntime = class {
73
136
  async loadPlugin(pluginId) {
74
137
  const effect$2 = effect.Effect.gen(function* () {
75
138
  return yield* (yield* require_plugin_service.PluginService).loadPlugin(pluginId);
76
- }).pipe(effect.Effect.annotateLogs({ plugin: pluginId }));
139
+ });
77
140
  return this.runPromise(effect$2);
78
141
  }
79
142
  async instantiatePlugin(pluginId, loadedPlugin) {
80
143
  const effect$3 = effect.Effect.gen(function* () {
81
144
  return yield* (yield* require_plugin_service.PluginService).instantiatePlugin(pluginId, loadedPlugin);
82
- }).pipe(effect.Effect.annotateLogs({ plugin: pluginId }));
145
+ });
83
146
  return this.runPromise(effect$3);
84
147
  }
85
148
  async initializePlugin(instance, config, plugins) {
@@ -88,30 +151,39 @@ var PluginRuntime = class {
88
151
  const initialized = yield* pluginService.initializePlugin(instance, config, plugins);
89
152
  yield* pluginService.registerPlugin(initialized);
90
153
  return initialized;
91
- }).pipe(effect.Effect.annotateLogs({ plugin: instance.plugin.id }));
154
+ });
92
155
  return this.runPromise(effect$4);
93
156
  }
94
157
  async shutdown() {
95
158
  const effect$5 = effect.Effect.gen(function* () {
96
- yield* (yield* require_plugin_service.PluginService).cleanup();
159
+ yield* (yield* require_plugin_service.PluginService).cleanup;
97
160
  });
98
- await this.runPromise(effect$5);
99
- await this.runtime.dispose();
161
+ try {
162
+ await this.runPromise(effect$5);
163
+ } finally {
164
+ this.pluginCache.clear();
165
+ this.routerCache.clear();
166
+ await this.runtime.dispose();
167
+ }
100
168
  }
101
169
  async evictPlugin(pluginId, config, plugins) {
102
170
  const cacheKey = this.generateCacheKey(pluginId, {
103
171
  ...config,
104
172
  __plugins: plugins ?? {}
105
173
  });
106
- const effect$6 = effect.Effect.gen(this, function* () {
174
+ const effect$6 = effect.Effect.gen({ self: this }, function* () {
107
175
  const pluginService = yield* require_plugin_service.PluginService;
108
176
  const cachedPlugin = this.pluginCache.get(cacheKey);
109
177
  if (cachedPlugin) {
110
178
  this.pluginCache.delete(cacheKey);
111
- const pluginResult = yield* cachedPlugin.pipe(effect.Effect.catchAll(() => effect.Effect.succeed(null)));
112
- if (pluginResult) yield* pluginService.shutdownPlugin(pluginResult).pipe(effect.Effect.catchAll((error) => effect.Effect.logWarning(`Failed to shutdown evicted plugin ${pluginId}`, error)));
179
+ this.routerCache.delete(cacheKey);
180
+ const pluginResult = yield* effect.Effect.tryPromise({
181
+ try: () => cachedPlugin,
182
+ catch: (error) => require_errors.toPluginRuntimeError(error, pluginId, void 0, "evict-plugin")
183
+ }).pipe(effect.Effect.orElseSucceed(() => null));
184
+ if (pluginResult) yield* pluginService.shutdownPlugin(pluginResult);
113
185
  }
114
- }).pipe(effect.Effect.catchAll((error) => effect.Effect.logWarning(`Plugin eviction failed for ${pluginId}`, error)));
186
+ });
115
187
  return this.runPromise(effect$6);
116
188
  }
117
189
  };
@@ -122,7 +194,7 @@ var PluginRuntime = class {
122
194
  function normalizeRemoteUrl(url) {
123
195
  if (!url) return url;
124
196
  if (url.endsWith(".js") || url.endsWith(".json")) return url;
125
- return `${url.endsWith("/") ? url.slice(0, -1) : url}/remoteEntry.js`;
197
+ return `${url.endsWith("/") ? url.slice(0, -1) : url}/${require_build_artifact_names.DEV_ENTRY_FILENAME}`;
126
198
  }
127
199
  /**
128
200
  * Extract plugin map (module constructors) from registry entries
@@ -169,7 +241,7 @@ function createPluginRuntime(config) {
169
241
  const secrets = config.secrets || {};
170
242
  const normalizedRegistry = normalizeRegistry(config.registry);
171
243
  const pluginMap = extractPluginMap(config.registry);
172
- const layer = require_plugin_service.PluginService.Live(normalizedRegistry, secrets, pluginMap);
244
+ const layer = require_plugin_service.PluginServiceLive(normalizedRegistry, secrets, pluginMap);
173
245
  const runtime = effect.ManagedRuntime.make(layer);
174
246
  return new PluginRuntime(runtime, normalizedRegistry);
175
247
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Hash","Effect","PluginRuntimeError","effect","Exit","Cause","Option","PluginService","ManagedRuntime"],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import { createRouterClient } from \"@orpc/server\";\nimport { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from \"effect\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InferRegistryFromEntries,\n InitializedPlugin,\n LoadedPlugin,\n PluginConfigInput,\n PluginInstance,\n PluginRegistry,\n PluginRegistryEntry,\n PluginRouterType,\n PluginRuntimeConfig,\n RegisteredPlugin,\n RegisteredPlugins,\n UsePluginResult,\n} from \"../types\";\nimport { PluginRuntimeError } from \"./errors\";\nimport { PluginService } from \"./services/plugin.service\";\n\nexport class PluginRuntime<R = RegisteredPlugins> {\n readonly __registryType?: R;\n\n private pluginCache = new Map<\n string,\n Effect.Effect<InitializedPlugin<AnyPlugin>, PluginRuntimeError>\n >();\n\n constructor(\n private runtime: ManagedRuntime.ManagedRuntime<PluginService, never>,\n private registry: PluginRegistry,\n ) {}\n\n private generateCacheKey(pluginId: string, config: unknown): string {\n const configHash = Hash.structure(config as object).toString();\n return `${pluginId}:${configHash}`;\n }\n\n private validatePluginId(pluginId: string): Effect.Effect<string, PluginRuntimeError> {\n if (!(pluginId in this.registry)) {\n return Effect.fail(\n new PluginRuntimeError({\n pluginId: String(pluginId),\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),\n retryable: false,\n }),\n );\n }\n return Effect.succeed(String(pluginId));\n }\n\n private async runPromise<A, E>(effect: Effect.Effect<A, E, PluginService>): Promise<A> {\n const exit = await this.runtime.runPromiseExit(effect);\n\n if (Exit.isFailure(exit)) {\n const error = Cause.failureOption(exit.cause);\n if (Option.isSome(error)) {\n throw error.value;\n }\n throw Cause.squash(exit.cause);\n }\n\n return exit.value;\n }\n\n async usePlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n plugins?: Record<string, unknown>,\n ): Promise<UsePluginResult<K, R>> {\n const cacheKey = this.generateCacheKey(pluginId, { ...config, __plugins: plugins ?? {} });\n\n let cachedPlugin = this.pluginCache.get(cacheKey);\n if (!cachedPlugin) {\n const operation = Effect.gen(this, function* () {\n const pluginService = yield* PluginService;\n const validatedId = yield* this.validatePluginId(pluginId);\n\n // Load → Instantiate → Initialize → Register\n const ctor = yield* pluginService.loadPlugin(validatedId);\n const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);\n const initialized = yield* pluginService.initializePlugin(instance, config, plugins);\n yield* pluginService.registerPlugin(initialized);\n\n return initialized;\n }).pipe(Effect.annotateLogs({ plugin: pluginId }), Effect.provide(this.runtime));\n\n cachedPlugin = Effect.cached(operation).pipe(Effect.flatten);\n this.pluginCache.set(cacheKey, cachedPlugin);\n }\n\n let initialized: InitializedPlugin<AnyPlugin>;\n try {\n initialized = await this.runPromise(cachedPlugin);\n } catch (error) {\n // Evict failed initializations so the next call retries instead\n // of returning the permanently-cached failure from Effect.cached.\n this.pluginCache.delete(cacheKey);\n throw error;\n }\n\n // Construct the router once per plugin instance, not per client/request.\n const router = initialized.plugin.createRouter(initialized.context) as PluginRouterType<R[K]>;\n\n // Create client factory that accepts request context\n const createClient = (context?: any) => createRouterClient(router, { context: context ?? {} });\n\n return {\n createClient: createClient as any,\n router,\n metadata: initialized.metadata,\n initialized: initialized as InitializedPlugin<RegisteredPlugin<K, R>>,\n } as UsePluginResult<K, R>;\n }\n\n async loadPlugin<K extends keyof R & string>(\n pluginId: K,\n ): Promise<LoadedPlugin<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.loadPlugin(pluginId);\n }).pipe(Effect.annotateLogs({ plugin: pluginId }));\n return this.runPromise(effect) as Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;\n }\n\n async instantiatePlugin<K extends keyof R & string>(\n pluginId: K,\n loadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>,\n ): Promise<PluginInstance<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);\n }).pipe(Effect.annotateLogs({ plugin: pluginId }));\n return this.runPromise(effect) as Promise<PluginInstance<RegisteredPlugin<K, R>>>;\n }\n\n async initializePlugin<T extends AnyPlugin>(\n instance: PluginInstance<T>,\n config: any,\n plugins?: Record<string, unknown>,\n ): Promise<InitializedPlugin<T>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n const initialized = yield* pluginService.initializePlugin(instance, config, plugins);\n yield* pluginService.registerPlugin(initialized);\n return initialized;\n }).pipe(Effect.annotateLogs({ plugin: instance.plugin.id }));\n return this.runPromise(effect);\n }\n\n async shutdown(): Promise<void> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n yield* pluginService.cleanup();\n });\n await this.runPromise(effect);\n await this.runtime.dispose();\n }\n\n async evictPlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n plugins?: Record<string, unknown>,\n ): Promise<void> {\n const cacheKey = this.generateCacheKey(pluginId, { ...config, __plugins: plugins ?? {} });\n\n const effect = Effect.gen(this, function* () {\n const pluginService = yield* PluginService;\n const cachedPlugin = this.pluginCache.get(cacheKey);\n\n if (cachedPlugin) {\n this.pluginCache.delete(cacheKey);\n\n const pluginResult = yield* cachedPlugin.pipe(Effect.catchAll(() => Effect.succeed(null)));\n\n if (pluginResult) {\n yield* pluginService\n .shutdownPlugin(pluginResult)\n .pipe(\n Effect.catchAll((error) =>\n Effect.logWarning(`Failed to shutdown evicted plugin ${pluginId}`, error),\n ),\n );\n }\n }\n }).pipe(\n Effect.catchAll((error) =>\n Effect.logWarning(`Plugin eviction failed for ${pluginId}`, error),\n ),\n );\n\n return this.runPromise(effect);\n }\n}\n\n/**\n * Normalizes a remote URL to ensure it points to remoteEntry.js\n * If the URL doesn't end with a file extension, appends /remoteEntry.js\n */\nfunction normalizeRemoteUrl(url: string): string {\n if (!url) return url;\n if (url.endsWith(\".js\") || url.endsWith(\".json\")) return url;\n return `${url.endsWith(\"/\") ? url.slice(0, -1) : url}/remoteEntry.js`;\n}\n\n/**\n * Extract plugin map (module constructors) from registry entries\n */\nfunction extractPluginMap(\n registry: Record<string, PluginRegistryEntry>,\n): Record<string, AnyPluginConstructor> {\n const pluginMap: Record<string, AnyPluginConstructor> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry && entry.module) {\n pluginMap[pluginId] = entry.module;\n }\n }\n\n return pluginMap;\n}\n\n/**\n * Normalize registry entries - ensure remote URLs are properly formatted\n */\nfunction normalizeRegistry(registry: Record<string, PluginRegistryEntry>): PluginRegistry {\n const normalized: Record<string, PluginRegistryEntry> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry) {\n normalized[pluginId] = {\n ...entry,\n remote: entry.remote ? normalizeRemoteUrl(entry.remote) : undefined,\n };\n } else {\n normalized[pluginId] = {\n ...entry,\n remote: normalizeRemoteUrl(entry.remote),\n };\n }\n }\n\n return normalized as PluginRegistry;\n}\n\n/**\n * Creates a plugin runtime with support for both module and remote plugin entries.\n *\n * @example\n * ```typescript\n * // With module entries (types inferred automatically)\n * const runtime = createPluginRuntime({\n * registry: {\n * telegram: { module: TelegramPlugin },\n * gopher: { remote: \"https://cdn.example.com/gopher/remoteEntry.js\" }\n * },\n * secrets: { API_KEY: \"...\" }\n * });\n *\n * // Types are automatically inferred from module entries!\n * const { router } = await runtime.usePlugin(\"telegram\", config);\n * ```\n */\nexport function createPluginRuntime<TRegistry extends Record<string, PluginRegistryEntry>>(\n config: PluginRuntimeConfig<TRegistry>,\n): PluginRuntime<InferRegistryFromEntries<TRegistry>> {\n const secrets = config.secrets || {};\n const normalizedRegistry = normalizeRegistry(config.registry);\n const pluginMap = extractPluginMap(config.registry);\n\n const layer = PluginService.Live(normalizedRegistry, secrets, pluginMap);\n const runtime = ManagedRuntime.make(layer);\n\n return new PluginRuntime(runtime, normalizedRegistry) as PluginR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,SAAS,iBACP,UACsC;CACtC,MAAM,YAAkD,CAAC;CAEzD,KAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,QAAQ,GACrD,IAAI,YAAY,SAAS,MAAM,QAC7B,UAAU,YAAY,MAAM;CAIhC,OAAO;AACT;;;;AAKA,SAAS,kBAAkB,UAA+D;CACxF,MAAM,aAAkD,CAAC;CAEzD,KAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,QAAQ,GACrD,IAAI,YAAY,OACd,WAAW,YAAY;EACrB,GAAG;EACH,QAAQ,MAAM,SAAS,mBAAmB,MAAM,MAAM,IAAI;CAC5D;MAEA,WAAW,YAAY;EACrB,GAAG;EACH,QAAQ,mBAAmB,MAAM,MAAM;CACzC;CAIJ,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,oBACd,QACoD;CACpD,MAAM,UAAU,OAAO,WAAW,CAAC;CACnC,MAAM,qBAAqB,kBAAkB,OAAO,QAAQ;CAC5D,MAAM,YAAY,iBAAiB,OAAO,QAAQ;CAElD,MAAM,QAAQI,qCAAc,KAAK,oBAAoB,SAAS,SAAS;CACvE,MAAM,UAAUC,sBAAe,KAAK,KAAK;CAEzC,OAAO,IAAI,cAAc,SAAS,kBAAkB;AAGtD"}
1
+ {"version":3,"file":"index.cjs","names":["Effect","PluginRuntimeError","effect","Exit","Cause","Option","PluginService","createRouterClient","toPluginRuntimeError","DEV_ENTRY_FILENAME","PluginServiceLive","ManagedRuntime"],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import \"@orpc/experimental-effect/extensions/effect\";\nimport \"@orpc/openapi/extensions/route\";\n\nimport { createRouterClient } from \"@orpc/server\";\nimport { Cause, Effect, Exit, ManagedRuntime, Option } from \"effect\";\nimport { DEV_ENTRY_FILENAME } from \"../build/artifact-names\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InferRegistryFromEntries,\n InitializedPlugin,\n LoadedPlugin,\n PluginConfigInput,\n PluginInstance,\n PluginRegistry,\n PluginRegistryEntry,\n PluginRouterType,\n PluginRuntimeConfig,\n RegisteredPlugin,\n RegisteredPlugins,\n UsePluginResult,\n} from \"../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"./errors\";\nimport { PluginService, PluginServiceLive } from \"./services/plugin.service\";\n\nconst MAX_CACHE_KEY_DEPTH = 32;\n\nexport class PluginRuntime<R = RegisteredPlugins> {\n readonly __registryType?: R;\n\n private pluginCache = new Map<string, Promise<InitializedPlugin<AnyPlugin>>>();\n private routerCache = new Map<string, PluginRouterType<any>>();\n private cacheLeafIds = new WeakMap<object, number>();\n private nextCacheLeafId = 0;\n\n constructor(\n private runtime: ManagedRuntime.ManagedRuntime<PluginService, never>,\n private registry: PluginRegistry,\n ) {}\n\n /**\n * Cache key for plugin instances: JSON-equal configs share one plugin\n * instance (variables and secrets originate from bos.config.json, so they\n * are JSON values). Values outside the JSON domain follow Effect's Hash\n * semantics — symbols key by description, functions and class instances by\n * reference identity — and the host creates its pluginsClient map once per\n * boot, making identity the correct equivalence for function-bearing\n * configs.\n */\n private generateCacheKey(pluginId: string, config: unknown): string {\n return `${pluginId}:${this.canonicalizeConfig(config, 0, new Set())}`;\n }\n\n private canonicalizeConfig(value: unknown, depth: number, ancestors: Set<object>): string {\n switch (typeof value) {\n case \"undefined\":\n return \"undefined\";\n case \"string\":\n return `string:${JSON.stringify(value)}`;\n case \"number\":\n return `number:${Object.is(value, -0) ? \"-0\" : String(value)}`;\n case \"bigint\":\n return `bigint:${value.toString()}`;\n case \"boolean\":\n return `boolean:${value}`;\n case \"symbol\":\n return `symbol:${String(value)}`;\n case \"function\":\n return `ref:${this.getCacheLeafId(value)}`;\n case \"object\": {\n if (value === null) return \"null\";\n if (ancestors.has(value) || depth >= MAX_CACHE_KEY_DEPTH) {\n return `ref:${this.getCacheLeafId(value)}`;\n }\n\n if (Array.isArray(value)) {\n ancestors.add(value);\n const serialized = `[${value\n .map((item) => this.canonicalizeConfig(item, depth + 1, ancestors))\n .join(\",\")}]`;\n ancestors.delete(value);\n return serialized;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return `ref:${this.getCacheLeafId(value)}`;\n }\n\n const record = value as Record<string, unknown>;\n ancestors.add(value);\n const serialized = `{${Object.keys(record)\n .sort()\n .map(\n (key) =>\n `${JSON.stringify(key)}:${this.canonicalizeConfig(record[key], depth + 1, ancestors)}`,\n )\n .join(\",\")}}`;\n ancestors.delete(value);\n return serialized;\n }\n }\n }\n\n private getCacheLeafId(value: object): number {\n const existing = this.cacheLeafIds.get(value);\n if (existing !== undefined) return existing;\n const id = this.nextCacheLeafId++;\n this.cacheLeafIds.set(value, id);\n return id;\n }\n\n private validatePluginId(pluginId: string): Effect.Effect<string, PluginRuntimeError> {\n if (!(pluginId in this.registry)) {\n return Effect.fail(\n new PluginRuntimeError({\n pluginId: String(pluginId),\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),\n }),\n );\n }\n return Effect.succeed(String(pluginId));\n }\n\n private async runPromise<A, E>(effect: Effect.Effect<A, E, PluginService>): Promise<A> {\n const exit = await this.runtime.runPromiseExit(effect);\n\n if (Exit.isFailure(exit)) {\n const error = Cause.findErrorOption(exit.cause);\n if (Option.isSome(error)) {\n throw error.value;\n }\n throw Cause.squash(exit.cause);\n }\n\n return exit.value;\n }\n\n async usePlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n plugins?: Record<string, unknown>,\n ): Promise<UsePluginResult<K, R>> {\n const cacheKey = this.generateCacheKey(pluginId, { ...config, __plugins: plugins ?? {} });\n\n let cachedPlugin = this.pluginCache.get(cacheKey);\n if (!cachedPlugin) {\n const operation = Effect.gen({ self: this }, function* () {\n const pluginService = yield* PluginService;\n const validatedId = yield* this.validatePluginId(pluginId);\n\n // Load → Instantiate → Initialize → Register\n const ctor = yield* pluginService.loadPlugin(validatedId);\n const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);\n const initialized = yield* pluginService.initializePlugin(instance, config, plugins);\n yield* pluginService.registerPlugin(initialized);\n\n return initialized;\n });\n\n cachedPlugin = this.runPromise(operation);\n this.pluginCache.set(cacheKey, cachedPlugin);\n }\n\n let initialized: InitializedPlugin<AnyPlugin>;\n try {\n initialized = await cachedPlugin;\n } catch (error) {\n if (this.pluginCache.get(cacheKey) === cachedPlugin) {\n this.pluginCache.delete(cacheKey);\n this.routerCache.delete(cacheKey);\n }\n throw error;\n }\n\n // Construct the router once per plugin instance, not per client/request.\n let router = this.routerCache.get(cacheKey);\n if (!router) {\n try {\n router = initialized.plugin.createRouter(plugins ?? {}) as PluginRouterType<R[K]>;\n this.routerCache.set(cacheKey, router);\n } catch (error) {\n await this.evictPlugin(pluginId, config, plugins);\n throw error;\n }\n }\n\n // Create client factory that accepts request context. The plugin's\n // Effect context is injected so `.effect()` handlers resolve services\n // on in-process (server-side / SSR) calls.\n const createClient = (context?: any) =>\n createRouterClient(router, {\n context: {\n ...context,\n \"effect/context\": initialized.effectContext,\n },\n });\n\n return {\n createClient: createClient as any,\n router,\n metadata: initialized.metadata,\n initialized: initialized as InitializedPlugin<RegisteredPlugin<K, R>>,\n } as UsePluginResult<K, R>;\n }\n\n async loadPlugin<K extends keyof R & string>(\n pluginId: K,\n ): Promise<LoadedPlugin<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.loadPlugin(pluginId);\n });\n return this.runPromise(effect) as Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;\n }\n\n async instantiatePlugin<K extends keyof R & string>(\n pluginId: K,\n loadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>,\n ): Promise<PluginInstance<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);\n });\n return this.runPromise(effect) as Promise<PluginInstance<RegisteredPlugin<K, R>>>;\n }\n\n async initializePlugin<T extends AnyPlugin>(\n instance: PluginInstance<T>,\n config: any,\n plugins?: Record<string, unknown>,\n ): Promise<InitializedPlugin<T>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n const initialized = yield* pluginService.initializePlugin(instance, config, plugins);\n yield* pluginService.registerPlugin(initialized);\n return initialized;\n });\n return this.runPromise(effect);\n }\n\n async shutdown(): Promise<void> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n yield* pluginService.cleanup;\n });\n try {\n await this.runPromise(effect);\n } finally {\n this.pluginCache.clear();\n this.routerCache.clear();\n await this.runtime.dispose();\n }\n }\n\n async evictPlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n plugins?: Record<string, unknown>,\n ): Promise<void> {\n const cacheKey = this.generateCacheKey(pluginId, { ...config, __plugins: plugins ?? {} });\n\n const effect = Effect.gen({ self: this }, function* () {\n const pluginService = yield* PluginService;\n const cachedPlugin = this.pluginCache.get(cacheKey);\n\n if (cachedPlugin) {\n this.pluginCache.delete(cacheKey);\n this.routerCache.delete(cacheKey);\n\n const pluginResult = yield* Effect.tryPromise({\n try: () => cachedPlugin,\n catch: (error) => toPluginRuntimeError(error, pluginId, undefined, \"evict-plugin\"),\n }).pipe(Effect.orElseSucceed(() => null));\n\n if (pluginResult) {\n yield* pluginService.shutdownPlugin(pluginResult);\n }\n }\n });\n\n return this.runPromise(effect);\n }\n}\n\n/**\n * Normalizes a remote URL to ensure it points to remoteEntry.js\n * If the URL doesn't end with a file extension, appends /remoteEntry.js\n */\nfunction normalizeRemoteUrl(url: string): string {\n if (!url) return url;\n if (url.endsWith(\".js\") || url.endsWith(\".json\")) return url;\n return `${url.endsWith(\"/\") ? url.slice(0, -1) : url}/${DEV_ENTRY_FILENAME}`;\n}\n\n/**\n * Extract plugin map (module constructors) from registry entries\n */\nfunction extractPluginMap(\n registry: Record<string, PluginRegistryEntry>,\n): Record<string, AnyPluginConstructor> {\n const pluginMap: Record<string, AnyPluginConstructor> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry && entry.module) {\n pluginMap[pluginId] = entry.module;\n }\n }\n\n return pluginMap;\n}\n\n/**\n * Normalize registry entries - ensure remote URLs are properly formatted\n */\nfunction normalizeRegistry(registry: Record<string, PluginRegistryEntry>): PluginRegistry {\n const normalized: Record<string, PluginRegistryEntry> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry) {\n normalized[pluginId] = {\n ...entry,\n remote: entry.remote ? normalizeRemoteUrl(entry.remote) : undefined,\n };\n } else {\n normalized[pluginId] = {\n ...entry,\n remote: normalizeRemoteUrl(entry.remote),\n };\n }\n }\n\n return normalized as PluginRegistry;\n}\n\n/**\n * Creates a plugin runtime with support for both module and remote plugin entries.\n *\n * @example\n * ```typescript\n * // With module entries (types inferred automatically)\n * const runtime = createPluginRuntime({\n * registry: {\n * telegram: { module: TelegramPlugin },\n * gopher: { remote: \"https://cdn.example.com/gopher/remoteEntry.js\" }\n * },\n * secrets: { API_KEY: \"...\" }\n * });\n *\n * // Types are automatically inferred from module entries!\n * const { router } = await runtime.usePlugin(\"telegram\", config);\n * ```\n */\nexport function createPluginRuntime<TRegistry extends Record<string, PluginRegistryEntry>>(\n config: PluginRuntimeConfig<TRegistry>,\n): PluginRuntime<InferRegistryFromEntries<TRegistry>> {\n const secrets = config.secrets || {};\n const normalizedRegistry = normalizeRegistry(config.registry);\n const pluginMap = extractPluginMap(config.registry);\n\n const layer = PluginServiceLive(normalizedRegistry, secrets, pluginMap);\n const runtime = ManagedRuntime.make(layer);\n\n return new PluginRuntime(runtime, normalizedRegistry) as PluginRuntime<\n InferRegistryFromEntries<TRegistry>\n >;\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,sBAAsB;AAE5B,IAAa,gBAAb,MAAkD;CAStC;CACA;CATV,AAAS;CAET,AAAQ,8BAAc,IAAI,IAAmD;CAC7E,AAAQ,8BAAc,IAAI,IAAmC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