@dxos/app-framework 0.8.4-main.ead640a → 0.8.4-main.effb148878

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 (572) hide show
  1. package/.storybook/main.mts +2 -4
  2. package/.storybook/preview.mts +2 -2
  3. package/LICENSE +102 -5
  4. package/README.md +1 -1
  5. package/dist/lib/browser/capability-C4WE22TJ.mjs +35 -0
  6. package/dist/lib/browser/capability-C4WE22TJ.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-2ZIYRDAF.mjs +95 -0
  8. package/dist/lib/browser/chunk-2ZIYRDAF.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-5GY3YOEL.mjs +28 -0
  10. package/dist/lib/browser/chunk-5GY3YOEL.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-66IXTIVK.mjs +48 -0
  12. package/dist/lib/browser/chunk-66IXTIVK.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-67GCXX5I.mjs +581 -0
  14. package/dist/lib/browser/chunk-67GCXX5I.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-FJ4765WW.mjs +8 -0
  16. package/dist/lib/browser/chunk-FJ4765WW.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-FO3IYSLV.mjs +68 -0
  18. package/dist/lib/browser/chunk-FO3IYSLV.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-IW44C7UL.mjs +83 -0
  20. package/dist/lib/browser/chunk-IW44C7UL.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  22. package/dist/lib/browser/chunk-KLHQNYJ2.mjs +422 -0
  23. package/dist/lib/browser/chunk-KLHQNYJ2.mjs.map +7 -0
  24. package/dist/lib/browser/chunk-LPWOVOOB.mjs +142 -0
  25. package/dist/lib/browser/chunk-LPWOVOOB.mjs.map +7 -0
  26. package/dist/lib/browser/chunk-LUQOVTWB.mjs +43 -0
  27. package/dist/lib/browser/chunk-LUQOVTWB.mjs.map +7 -0
  28. package/dist/lib/browser/chunk-SLX73WRZ.mjs +218 -0
  29. package/dist/lib/browser/chunk-SLX73WRZ.mjs.map +7 -0
  30. package/dist/lib/browser/chunk-SZMB3K2N.mjs +517 -0
  31. package/dist/lib/browser/chunk-SZMB3K2N.mjs.map +7 -0
  32. package/dist/lib/browser/chunk-VJ5PFAWC.mjs +1446 -0
  33. package/dist/lib/browser/chunk-VJ5PFAWC.mjs.map +7 -0
  34. package/dist/lib/browser/cli/index.mjs +74 -0
  35. package/dist/lib/browser/cli/index.mjs.map +7 -0
  36. package/dist/lib/browser/common/activation-events.mjs +20 -0
  37. package/dist/lib/browser/common/capabilities.mjs +56 -0
  38. package/dist/lib/browser/core/activation-event.mjs +20 -0
  39. package/dist/lib/browser/core/capability.mjs +32 -0
  40. package/dist/lib/browser/core/capability.mjs.map +7 -0
  41. package/dist/lib/browser/core/plugin-manager.mjs +19 -0
  42. package/dist/lib/browser/core/plugin-manager.mjs.map +7 -0
  43. package/dist/lib/browser/core/plugin.mjs +39 -0
  44. package/dist/lib/browser/core/plugin.mjs.map +7 -0
  45. package/dist/lib/browser/core/url-loader.mjs +24 -0
  46. package/dist/lib/browser/core/url-loader.mjs.map +7 -0
  47. package/dist/lib/browser/index.mjs +85 -148
  48. package/dist/lib/browser/index.mjs.map +4 -4
  49. package/dist/lib/browser/meta.json +1 -1
  50. package/dist/lib/browser/process-manager-capability-3Q4TA73T.mjs +89 -0
  51. package/dist/lib/browser/process-manager-capability-3Q4TA73T.mjs.map +7 -0
  52. package/dist/lib/browser/testing/index.mjs +245 -47
  53. package/dist/lib/browser/testing/index.mjs.map +4 -4
  54. package/dist/lib/browser/testing/react.mjs +78 -0
  55. package/dist/lib/browser/testing/react.mjs.map +7 -0
  56. package/dist/lib/browser/ui/index.mjs +54 -0
  57. package/dist/lib/browser/ui/index.mjs.map +7 -0
  58. package/dist/lib/node-esm/capability-GPN6OS6M.mjs +36 -0
  59. package/dist/lib/node-esm/capability-GPN6OS6M.mjs.map +7 -0
  60. package/dist/lib/node-esm/chunk-37Z53PXZ.mjs +10 -0
  61. package/dist/lib/node-esm/chunk-37Z53PXZ.mjs.map +7 -0
  62. package/dist/lib/node-esm/chunk-42UNAKYO.mjs +423 -0
  63. package/dist/lib/node-esm/chunk-42UNAKYO.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-6S45OMUP.mjs +219 -0
  65. package/dist/lib/node-esm/chunk-6S45OMUP.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-CTKEZHKF.mjs +84 -0
  67. package/dist/lib/node-esm/chunk-CTKEZHKF.mjs.map +7 -0
  68. package/dist/lib/node-esm/chunk-FEVJEUD7.mjs +143 -0
  69. package/dist/lib/node-esm/chunk-FEVJEUD7.mjs.map +7 -0
  70. package/dist/lib/node-esm/chunk-GBHZF46K.mjs +518 -0
  71. package/dist/lib/node-esm/chunk-GBHZF46K.mjs.map +7 -0
  72. package/dist/lib/node-esm/chunk-GUE5V5CG.mjs +582 -0
  73. package/dist/lib/node-esm/chunk-GUE5V5CG.mjs.map +7 -0
  74. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  75. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  76. package/dist/lib/node-esm/chunk-KFZEB6BV.mjs +29 -0
  77. package/dist/lib/node-esm/chunk-KFZEB6BV.mjs.map +7 -0
  78. package/dist/lib/node-esm/chunk-MXWDXYV2.mjs +44 -0
  79. package/dist/lib/node-esm/chunk-MXWDXYV2.mjs.map +7 -0
  80. package/dist/lib/node-esm/chunk-QBUGLR4H.mjs +96 -0
  81. package/dist/lib/node-esm/chunk-QBUGLR4H.mjs.map +7 -0
  82. package/dist/lib/node-esm/chunk-SFYCO3PT.mjs +1447 -0
  83. package/dist/lib/node-esm/chunk-SFYCO3PT.mjs.map +7 -0
  84. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs +70 -0
  85. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs.map +7 -0
  86. package/dist/lib/node-esm/chunk-XOCUANHO.mjs +49 -0
  87. package/dist/lib/node-esm/chunk-XOCUANHO.mjs.map +7 -0
  88. package/dist/lib/node-esm/cli/index.mjs +75 -0
  89. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  90. package/dist/lib/node-esm/common/activation-events.mjs +21 -0
  91. package/dist/lib/node-esm/common/activation-events.mjs.map +7 -0
  92. package/dist/lib/node-esm/common/capabilities.mjs +57 -0
  93. package/dist/lib/node-esm/common/capabilities.mjs.map +7 -0
  94. package/dist/lib/node-esm/core/activation-event.mjs +21 -0
  95. package/dist/lib/node-esm/core/activation-event.mjs.map +7 -0
  96. package/dist/lib/node-esm/core/capability.mjs +33 -0
  97. package/dist/lib/node-esm/core/capability.mjs.map +7 -0
  98. package/dist/lib/node-esm/core/plugin-manager.mjs +20 -0
  99. package/dist/lib/node-esm/core/plugin-manager.mjs.map +7 -0
  100. package/dist/lib/node-esm/core/plugin.mjs +40 -0
  101. package/dist/lib/node-esm/core/plugin.mjs.map +7 -0
  102. package/dist/lib/node-esm/core/url-loader.mjs +25 -0
  103. package/dist/lib/node-esm/core/url-loader.mjs.map +7 -0
  104. package/dist/lib/node-esm/index.mjs +85 -148
  105. package/dist/lib/node-esm/index.mjs.map +4 -4
  106. package/dist/lib/node-esm/meta.json +1 -1
  107. package/dist/lib/node-esm/process-manager-capability-5KCLSNQM.mjs +90 -0
  108. package/dist/lib/node-esm/process-manager-capability-5KCLSNQM.mjs.map +7 -0
  109. package/dist/lib/node-esm/testing/index.mjs +245 -47
  110. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  111. package/dist/lib/node-esm/testing/react.mjs +79 -0
  112. package/dist/lib/node-esm/testing/react.mjs.map +7 -0
  113. package/dist/lib/node-esm/ui/index.mjs +55 -0
  114. package/dist/lib/node-esm/ui/index.mjs.map +7 -0
  115. package/dist/plugin/node-esm/index.mjs +893 -0
  116. package/dist/plugin/node-esm/index.mjs.map +7 -0
  117. package/dist/plugin/node-esm/meta.json +1 -0
  118. package/dist/types/src/cli/cli.d.ts +37 -0
  119. package/dist/types/src/cli/cli.d.ts.map +1 -0
  120. package/dist/types/src/cli/index.d.ts +2 -0
  121. package/dist/types/src/cli/index.d.ts.map +1 -0
  122. package/dist/types/src/common/activation-events.d.ts +24 -0
  123. package/dist/types/src/common/activation-events.d.ts.map +1 -0
  124. package/dist/types/src/common/annotations.d.ts +1 -0
  125. package/dist/types/src/common/annotations.d.ts.map +1 -0
  126. package/dist/types/src/common/capabilities.d.ts +214 -199
  127. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  128. package/dist/types/src/common/index.d.ts +4 -8
  129. package/dist/types/src/common/index.d.ts.map +1 -1
  130. package/dist/types/src/common/operations.d.ts +19 -0
  131. package/dist/types/src/common/operations.d.ts.map +1 -0
  132. package/dist/types/src/common/translations.d.ts +7 -7
  133. package/dist/types/src/common/translations.d.ts.map +1 -1
  134. package/dist/types/src/context.d.ts +5 -0
  135. package/dist/types/src/context.d.ts.map +1 -0
  136. package/dist/types/src/core/{events.d.ts → activation-event.d.ts} +11 -11
  137. package/dist/types/src/core/activation-event.d.ts.map +1 -0
  138. package/dist/types/src/core/capability-manager.d.ts +48 -0
  139. package/dist/types/src/core/capability-manager.d.ts.map +1 -0
  140. package/dist/types/src/core/capability-manager.test.d.ts +2 -0
  141. package/dist/types/src/core/capability-manager.test.d.ts.map +1 -0
  142. package/dist/types/src/core/capability.d.ts +161 -0
  143. package/dist/types/src/core/capability.d.ts.map +1 -0
  144. package/dist/types/src/core/edge-registry-plugin-provider.d.ts +30 -0
  145. package/dist/types/src/core/edge-registry-plugin-provider.d.ts.map +1 -0
  146. package/dist/types/src/core/index.d.ts +11 -4
  147. package/dist/types/src/core/index.d.ts.map +1 -1
  148. package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
  149. package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
  150. package/dist/types/src/core/plugin-manager.d.ts +297 -0
  151. package/dist/types/src/core/plugin-manager.d.ts.map +1 -0
  152. package/dist/types/src/core/plugin-manager.test.d.ts +2 -0
  153. package/dist/types/src/core/plugin-manager.test.d.ts.map +1 -0
  154. package/dist/types/src/core/plugin-manifest.d.ts +101 -0
  155. package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
  156. package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
  157. package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
  158. package/dist/types/src/core/plugin.d.ts +276 -39
  159. package/dist/types/src/core/plugin.d.ts.map +1 -1
  160. package/dist/types/src/core/registry.d.ts +107 -0
  161. package/dist/types/src/core/registry.d.ts.map +1 -0
  162. package/dist/types/src/core/url-loader.d.ts +127 -0
  163. package/dist/types/src/core/url-loader.d.ts.map +1 -0
  164. package/dist/types/src/core/url-loader.test.d.ts +2 -0
  165. package/dist/types/src/core/url-loader.test.d.ts.map +1 -0
  166. package/dist/types/src/helpers.d.ts.map +1 -1
  167. package/dist/types/src/index.d.ts +2 -4
  168. package/dist/types/src/index.d.ts.map +1 -1
  169. package/dist/types/src/plugin-process-manager/ProcessManagerPlugin.d.ts +3 -0
  170. package/dist/types/src/plugin-process-manager/ProcessManagerPlugin.d.ts.map +1 -0
  171. package/dist/types/src/plugin-process-manager/history/capability.d.ts +7 -0
  172. package/dist/types/src/plugin-process-manager/history/capability.d.ts.map +1 -0
  173. package/dist/types/src/plugin-process-manager/history/errors.d.ts +32 -0
  174. package/dist/types/src/plugin-process-manager/history/errors.d.ts.map +1 -0
  175. package/dist/types/src/plugin-process-manager/history/history-tracker.d.ts +18 -0
  176. package/dist/types/src/plugin-process-manager/history/history-tracker.d.ts.map +1 -0
  177. package/dist/types/src/plugin-process-manager/history/history-tracker.test.d.ts +2 -0
  178. package/dist/types/src/plugin-process-manager/history/history-tracker.test.d.ts.map +1 -0
  179. package/dist/types/src/plugin-process-manager/history/index.d.ts +6 -0
  180. package/dist/types/src/plugin-process-manager/history/index.d.ts.map +1 -0
  181. package/dist/types/src/plugin-process-manager/history/types.d.ts +13 -0
  182. package/dist/types/src/plugin-process-manager/history/types.d.ts.map +1 -0
  183. package/dist/types/src/plugin-process-manager/history/undo-mapping.d.ts +101 -0
  184. package/dist/types/src/plugin-process-manager/history/undo-mapping.d.ts.map +1 -0
  185. package/dist/types/src/plugin-process-manager/history/undo-registry.d.ts +23 -0
  186. package/dist/types/src/plugin-process-manager/history/undo-registry.d.ts.map +1 -0
  187. package/dist/types/src/plugin-process-manager/history/undo-registry.test.d.ts +2 -0
  188. package/dist/types/src/plugin-process-manager/history/undo-registry.test.d.ts.map +1 -0
  189. package/dist/types/src/plugin-process-manager/index.d.ts +3 -0
  190. package/dist/types/src/plugin-process-manager/index.d.ts.map +1 -0
  191. package/dist/types/src/plugin-process-manager/meta.d.ts +3 -0
  192. package/dist/types/src/plugin-process-manager/meta.d.ts.map +1 -0
  193. package/dist/types/src/plugin-process-manager/process-manager-capability.d.ts +8 -0
  194. package/dist/types/src/plugin-process-manager/process-manager-capability.d.ts.map +1 -0
  195. package/dist/types/src/plugin-process-manager/testing.d.ts +59 -0
  196. package/dist/types/src/plugin-process-manager/testing.d.ts.map +1 -0
  197. package/dist/types/src/testing/harness.d.ts +79 -0
  198. package/dist/types/src/testing/harness.d.ts.map +1 -0
  199. package/dist/types/src/testing/index.d.ts +2 -0
  200. package/dist/types/src/testing/index.d.ts.map +1 -1
  201. package/dist/types/src/testing/react.d.ts +27 -0
  202. package/dist/types/src/testing/react.d.ts.map +1 -0
  203. package/dist/types/src/testing/react.test.d.ts +2 -0
  204. package/dist/types/src/testing/react.test.d.ts.map +1 -0
  205. package/dist/types/src/testing/service.d.ts +8 -0
  206. package/dist/types/src/testing/service.d.ts.map +1 -0
  207. package/dist/types/src/testing/withPluginManager.d.ts +7 -6
  208. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  209. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  210. package/dist/types/src/ui/components/App/App.d.ts +9 -0
  211. package/dist/types/src/ui/components/App/App.d.ts.map +1 -0
  212. package/dist/types/src/ui/components/App/App.stories.d.ts +19 -0
  213. package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -0
  214. package/dist/types/src/ui/components/App/index.d.ts +2 -0
  215. package/dist/types/src/ui/components/App/index.d.ts.map +1 -0
  216. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
  217. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
  218. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
  219. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
  220. package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
  221. package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
  222. package/dist/types/src/{playground/playground.stories.d.ts → ui/components/PluginManager/PluginManagerContext.stories.d.ts} +5 -3
  223. package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -0
  224. package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts +10 -0
  225. package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts.map +1 -0
  226. package/dist/types/src/ui/components/PluginManager/index.d.ts +2 -0
  227. package/dist/types/src/ui/components/PluginManager/index.d.ts.map +1 -0
  228. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts +24 -0
  229. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts.map +1 -0
  230. package/dist/types/src/{components/App.stories.d.ts → ui/components/Surface/SurfaceComponent.stories.d.ts} +1 -1
  231. package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -0
  232. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts +11 -0
  233. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts.map +1 -0
  234. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts +48 -0
  235. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -0
  236. package/dist/types/src/ui/components/Surface/context.d.ts +5 -0
  237. package/dist/types/src/ui/components/Surface/context.d.ts.map +1 -0
  238. package/dist/types/src/ui/components/Surface/index.d.ts +36 -0
  239. package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -0
  240. package/dist/types/src/ui/components/Surface/types.d.ts +197 -0
  241. package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -0
  242. package/dist/types/src/ui/components/Surface/types.test.d.ts +2 -0
  243. package/dist/types/src/ui/components/Surface/types.test.d.ts.map +1 -0
  244. package/dist/types/src/ui/components/index.d.ts +5 -0
  245. package/dist/types/src/ui/components/index.d.ts.map +1 -0
  246. package/dist/types/src/ui/hooks/index.d.ts +7 -0
  247. package/dist/types/src/ui/hooks/index.d.ts.map +1 -0
  248. package/dist/types/src/ui/hooks/useApp.d.ts +86 -0
  249. package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -0
  250. package/dist/types/src/ui/hooks/useApp.test.d.ts +2 -0
  251. package/dist/types/src/ui/hooks/useApp.test.d.ts.map +1 -0
  252. package/dist/types/src/ui/hooks/useCapabilities.d.ts +31 -0
  253. package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -0
  254. package/dist/types/src/{components → ui/hooks}/useLoading.d.ts +1 -2
  255. package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -0
  256. package/dist/types/src/ui/hooks/useProcessManagerRuntime.d.ts +30 -0
  257. package/dist/types/src/ui/hooks/useProcessManagerRuntime.d.ts.map +1 -0
  258. package/dist/types/src/ui/hooks/useSettingsState.d.ts +10 -0
  259. package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -0
  260. package/dist/types/src/ui/hooks/useSurface.d.ts +3 -0
  261. package/dist/types/src/ui/hooks/useSurface.d.ts.map +1 -0
  262. package/dist/types/src/ui/index.d.ts +3 -0
  263. package/dist/types/src/ui/index.d.ts.map +1 -0
  264. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +34 -0
  265. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -0
  266. package/dist/types/src/vite-plugin/boot-loader/index.d.ts +2 -0
  267. package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -0
  268. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts +51 -0
  269. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts.map +1 -0
  270. package/dist/types/src/vite-plugin/composer/index.d.ts +34 -0
  271. package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -0
  272. package/dist/types/src/vite-plugin/import-map/index.d.ts +28 -0
  273. package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -0
  274. package/dist/types/src/vite-plugin/index.d.ts +5 -0
  275. package/dist/types/src/vite-plugin/index.d.ts.map +1 -0
  276. package/dist/types/src/vite-plugin/manifest.d.ts +41 -0
  277. package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -0
  278. package/dist/types/src/vite-plugin/manifest.test.d.ts +2 -0
  279. package/dist/types/src/vite-plugin/manifest.test.d.ts.map +1 -0
  280. package/dist/types/src/vite-plugin/packages.d.ts +13 -0
  281. package/dist/types/src/vite-plugin/packages.d.ts.map +1 -0
  282. package/dist/types/tsconfig.tsbuildinfo +1 -1
  283. package/moon.yml +25 -6
  284. package/package.json +119 -56
  285. package/src/cli/cli.ts +102 -0
  286. package/src/{components → cli}/index.ts +1 -1
  287. package/src/common/activation-events.ts +39 -0
  288. package/src/{playground/layout/index.ts → common/annotations.ts} +0 -2
  289. package/src/common/capabilities.ts +287 -195
  290. package/src/common/index.ts +4 -8
  291. package/src/common/operations.ts +36 -0
  292. package/src/common/translations.ts +17 -9
  293. package/src/context.ts +9 -0
  294. package/src/core/{events.ts → activation-event.ts} +10 -7
  295. package/src/core/capability-manager.test.ts +151 -0
  296. package/src/core/capability-manager.ts +192 -0
  297. package/src/core/capability.ts +254 -0
  298. package/src/core/edge-registry-plugin-provider.ts +92 -0
  299. package/src/core/index.ts +11 -4
  300. package/src/core/plugin-asset-cache.ts +60 -0
  301. package/src/core/plugin-manager.test.ts +1899 -0
  302. package/src/core/plugin-manager.ts +1687 -0
  303. package/src/core/plugin-manifest.test.ts +75 -0
  304. package/src/core/plugin-manifest.ts +134 -0
  305. package/src/core/plugin.ts +415 -45
  306. package/src/core/registry.ts +163 -0
  307. package/src/core/url-loader.test.ts +221 -0
  308. package/src/core/url-loader.ts +388 -0
  309. package/src/index.ts +2 -4
  310. package/src/plugin-process-manager/ProcessManagerPlugin.ts +24 -0
  311. package/src/plugin-process-manager/history/capability.ts +36 -0
  312. package/src/plugin-process-manager/history/errors.ts +7 -0
  313. package/src/plugin-process-manager/history/history-tracker.test.ts +374 -0
  314. package/src/plugin-process-manager/history/history-tracker.ts +128 -0
  315. package/src/plugin-process-manager/history/index.ts +9 -0
  316. package/src/plugin-process-manager/history/types.ts +17 -0
  317. package/src/plugin-process-manager/history/undo-mapping.ts +135 -0
  318. package/src/plugin-process-manager/history/undo-registry.test.ts +72 -0
  319. package/src/plugin-process-manager/history/undo-registry.ts +54 -0
  320. package/src/plugin-process-manager/index.ts +6 -0
  321. package/src/plugin-process-manager/meta.ts +14 -0
  322. package/src/plugin-process-manager/process-manager-capability.ts +178 -0
  323. package/src/plugin-process-manager/testing.ts +155 -0
  324. package/src/testing/harness.ts +247 -0
  325. package/src/testing/index.ts +2 -0
  326. package/src/testing/react.test.tsx +48 -0
  327. package/src/testing/react.tsx +113 -0
  328. package/src/testing/service.ts +52 -0
  329. package/src/testing/withPluginManager.stories.tsx +8 -9
  330. package/src/testing/withPluginManager.tsx +73 -42
  331. package/src/ui/components/App/App.stories.tsx +86 -0
  332. package/src/ui/components/App/App.tsx +81 -0
  333. package/src/{playground/debug → ui/components/App}/index.ts +1 -1
  334. package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
  335. package/src/ui/components/Placeholder/Placeholder.tsx +156 -0
  336. package/src/{playground/logger → ui/components/Placeholder}/index.ts +1 -1
  337. package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +184 -0
  338. package/src/{react → ui/components/PluginManager}/PluginManagerProvider.ts +3 -3
  339. package/src/ui/components/PluginManager/index.ts +5 -0
  340. package/src/ui/components/Surface/SurfaceComponent.stories.tsx +144 -0
  341. package/src/ui/components/Surface/SurfaceComponent.tsx +303 -0
  342. package/src/ui/components/Surface/SurfaceInfo.tsx +106 -0
  343. package/src/ui/components/Surface/SurfaceProfilerContext.tsx +207 -0
  344. package/src/ui/components/Surface/context.ts +12 -0
  345. package/src/ui/components/Surface/index.ts +54 -0
  346. package/src/ui/components/Surface/types.test.ts +126 -0
  347. package/src/ui/components/Surface/types.ts +269 -0
  348. package/src/ui/components/index.ts +8 -0
  349. package/src/ui/hooks/index.ts +10 -0
  350. package/src/ui/hooks/useApp.test.tsx +159 -0
  351. package/src/ui/hooks/useApp.tsx +418 -0
  352. package/src/ui/hooks/useCapabilities.ts +68 -0
  353. package/src/{components → ui/hooks}/useLoading.tsx +16 -10
  354. package/src/ui/hooks/useProcessManagerRuntime.ts +78 -0
  355. package/src/ui/hooks/useSettingsState.ts +26 -0
  356. package/src/ui/hooks/useSurface.ts +13 -0
  357. package/src/ui/index.ts +6 -0
  358. package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +270 -0
  359. package/src/vite-plugin/boot-loader/boot-loader.css +320 -0
  360. package/src/vite-plugin/boot-loader/boot-loader.js +325 -0
  361. package/src/vite-plugin/boot-loader/index.ts +5 -0
  362. package/src/vite-plugin/boot-loader/loader.ts +123 -0
  363. package/src/vite-plugin/composer/index.ts +306 -0
  364. package/src/vite-plugin/import-map/index.ts +527 -0
  365. package/src/vite-plugin/index.ts +10 -0
  366. package/src/vite-plugin/manifest.test.ts +46 -0
  367. package/src/vite-plugin/manifest.ts +57 -0
  368. package/src/vite-plugin/packages.ts +187 -0
  369. package/tsconfig.json +30 -15
  370. package/tsconfig.node.json +2 -4
  371. package/typedoc.json +2 -4
  372. package/vitest.config.ts +1 -1
  373. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  374. package/.swc/plugins/linux_x86_64_19.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429.wasmer-v7 +0 -0
  375. package/dist/lib/browser/app-graph-builder-LG4RG2LM.mjs +0 -138
  376. package/dist/lib/browser/app-graph-builder-LG4RG2LM.mjs.map +0 -7
  377. package/dist/lib/browser/chunk-2GRQ4QXA.mjs +0 -1646
  378. package/dist/lib/browser/chunk-2GRQ4QXA.mjs.map +0 -7
  379. package/dist/lib/browser/chunk-FRUTKCPG.mjs +0 -467
  380. package/dist/lib/browser/chunk-FRUTKCPG.mjs.map +0 -7
  381. package/dist/lib/browser/chunk-SCPE4ZO2.mjs +0 -35
  382. package/dist/lib/browser/chunk-SCPE4ZO2.mjs.map +0 -7
  383. package/dist/lib/browser/intent-dispatcher-6SHA5B3N.mjs +0 -11
  384. package/dist/lib/browser/intent-resolver-UZZ4OANZ.mjs +0 -39
  385. package/dist/lib/browser/intent-resolver-UZZ4OANZ.mjs.map +0 -7
  386. package/dist/lib/browser/store-ACBEYK4B.mjs +0 -30
  387. package/dist/lib/browser/store-ACBEYK4B.mjs.map +0 -7
  388. package/dist/lib/browser/worker.mjs +0 -77
  389. package/dist/lib/node-esm/app-graph-builder-FMHVHPWA.mjs +0 -139
  390. package/dist/lib/node-esm/app-graph-builder-FMHVHPWA.mjs.map +0 -7
  391. package/dist/lib/node-esm/chunk-CXT6CYPE.mjs +0 -468
  392. package/dist/lib/node-esm/chunk-CXT6CYPE.mjs.map +0 -7
  393. package/dist/lib/node-esm/chunk-KSPOOYT3.mjs +0 -1648
  394. package/dist/lib/node-esm/chunk-KSPOOYT3.mjs.map +0 -7
  395. package/dist/lib/node-esm/chunk-ZX63QUGE.mjs +0 -37
  396. package/dist/lib/node-esm/chunk-ZX63QUGE.mjs.map +0 -7
  397. package/dist/lib/node-esm/intent-dispatcher-SIYQ5ZIU.mjs +0 -12
  398. package/dist/lib/node-esm/intent-resolver-7FYJMXAG.mjs +0 -40
  399. package/dist/lib/node-esm/intent-resolver-7FYJMXAG.mjs.map +0 -7
  400. package/dist/lib/node-esm/store-6OBLTVXC.mjs +0 -31
  401. package/dist/lib/node-esm/store-6OBLTVXC.mjs.map +0 -7
  402. package/dist/lib/node-esm/worker.mjs +0 -78
  403. package/dist/types/src/common/collaboration.d.ts +0 -20
  404. package/dist/types/src/common/collaboration.d.ts.map +0 -1
  405. package/dist/types/src/common/events.d.ts +0 -52
  406. package/dist/types/src/common/events.d.ts.map +0 -1
  407. package/dist/types/src/common/file.d.ts +0 -14
  408. package/dist/types/src/common/file.d.ts.map +0 -1
  409. package/dist/types/src/common/graph.d.ts +0 -21
  410. package/dist/types/src/common/graph.d.ts.map +0 -1
  411. package/dist/types/src/common/layout.d.ts +0 -279
  412. package/dist/types/src/common/layout.d.ts.map +0 -1
  413. package/dist/types/src/common/surface.d.ts +0 -59
  414. package/dist/types/src/common/surface.d.ts.map +0 -1
  415. package/dist/types/src/components/App.d.ts +0 -10
  416. package/dist/types/src/components/App.d.ts.map +0 -1
  417. package/dist/types/src/components/App.stories.d.ts.map +0 -1
  418. package/dist/types/src/components/DefaultFallback.d.ts +0 -8
  419. package/dist/types/src/components/DefaultFallback.d.ts.map +0 -1
  420. package/dist/types/src/components/index.d.ts +0 -2
  421. package/dist/types/src/components/index.d.ts.map +0 -1
  422. package/dist/types/src/components/useApp.d.ts +0 -44
  423. package/dist/types/src/components/useApp.d.ts.map +0 -1
  424. package/dist/types/src/components/useLoading.d.ts.map +0 -1
  425. package/dist/types/src/core/capabilities.d.ts +0 -117
  426. package/dist/types/src/core/capabilities.d.ts.map +0 -1
  427. package/dist/types/src/core/capabilities.test.d.ts +0 -2
  428. package/dist/types/src/core/capabilities.test.d.ts.map +0 -1
  429. package/dist/types/src/core/events.d.ts.map +0 -1
  430. package/dist/types/src/core/manager.d.ts +0 -126
  431. package/dist/types/src/core/manager.d.ts.map +0 -1
  432. package/dist/types/src/core/manager.test.d.ts +0 -2
  433. package/dist/types/src/core/manager.test.d.ts.map +0 -1
  434. package/dist/types/src/playground/debug/Debug.d.ts +0 -6
  435. package/dist/types/src/playground/debug/Debug.d.ts.map +0 -1
  436. package/dist/types/src/playground/debug/index.d.ts +0 -2
  437. package/dist/types/src/playground/debug/index.d.ts.map +0 -1
  438. package/dist/types/src/playground/debug/plugin.d.ts +0 -2
  439. package/dist/types/src/playground/debug/plugin.d.ts.map +0 -1
  440. package/dist/types/src/playground/generator/Main.d.ts +0 -6
  441. package/dist/types/src/playground/generator/Main.d.ts.map +0 -1
  442. package/dist/types/src/playground/generator/Toolbar.d.ts +0 -6
  443. package/dist/types/src/playground/generator/Toolbar.d.ts.map +0 -1
  444. package/dist/types/src/playground/generator/generator.d.ts +0 -7
  445. package/dist/types/src/playground/generator/generator.d.ts.map +0 -1
  446. package/dist/types/src/playground/generator/index.d.ts +0 -3
  447. package/dist/types/src/playground/generator/index.d.ts.map +0 -1
  448. package/dist/types/src/playground/generator/plugin.d.ts +0 -2
  449. package/dist/types/src/playground/generator/plugin.d.ts.map +0 -1
  450. package/dist/types/src/playground/layout/Layout.d.ts +0 -8
  451. package/dist/types/src/playground/layout/Layout.d.ts.map +0 -1
  452. package/dist/types/src/playground/layout/index.d.ts +0 -2
  453. package/dist/types/src/playground/layout/index.d.ts.map +0 -1
  454. package/dist/types/src/playground/layout/plugin.d.ts +0 -2
  455. package/dist/types/src/playground/layout/plugin.d.ts.map +0 -1
  456. package/dist/types/src/playground/logger/Toolbar.d.ts +0 -6
  457. package/dist/types/src/playground/logger/Toolbar.d.ts.map +0 -1
  458. package/dist/types/src/playground/logger/index.d.ts +0 -2
  459. package/dist/types/src/playground/logger/index.d.ts.map +0 -1
  460. package/dist/types/src/playground/logger/plugin.d.ts +0 -2
  461. package/dist/types/src/playground/logger/plugin.d.ts.map +0 -1
  462. package/dist/types/src/playground/logger/schema.d.ts +0 -13
  463. package/dist/types/src/playground/logger/schema.d.ts.map +0 -1
  464. package/dist/types/src/playground/playground.stories.d.ts.map +0 -1
  465. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +0 -2
  466. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +0 -1
  467. package/dist/types/src/plugin-intent/actions.d.ts +0 -36
  468. package/dist/types/src/plugin-intent/actions.d.ts.map +0 -1
  469. package/dist/types/src/plugin-intent/errors.d.ts +0 -16
  470. package/dist/types/src/plugin-intent/errors.d.ts.map +0 -1
  471. package/dist/types/src/plugin-intent/index.d.ts +0 -6
  472. package/dist/types/src/plugin-intent/index.d.ts.map +0 -1
  473. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +0 -139
  474. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +0 -1
  475. package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts +0 -2
  476. package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +0 -1
  477. package/dist/types/src/plugin-intent/intent.d.ts +0 -63
  478. package/dist/types/src/plugin-intent/intent.d.ts.map +0 -1
  479. package/dist/types/src/plugin-intent/meta.d.ts +0 -3
  480. package/dist/types/src/plugin-intent/meta.d.ts.map +0 -1
  481. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +0 -2
  482. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +0 -1
  483. package/dist/types/src/plugin-settings/actions.d.ts +0 -25
  484. package/dist/types/src/plugin-settings/actions.d.ts.map +0 -1
  485. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +0 -4
  486. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +0 -1
  487. package/dist/types/src/plugin-settings/index.d.ts +0 -3
  488. package/dist/types/src/plugin-settings/index.d.ts.map +0 -1
  489. package/dist/types/src/plugin-settings/intent-resolver.d.ts +0 -4
  490. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +0 -1
  491. package/dist/types/src/plugin-settings/meta.d.ts +0 -3
  492. package/dist/types/src/plugin-settings/meta.d.ts.map +0 -1
  493. package/dist/types/src/plugin-settings/store.d.ts +0 -5
  494. package/dist/types/src/plugin-settings/store.d.ts.map +0 -1
  495. package/dist/types/src/plugin-settings/translations.d.ts +0 -11
  496. package/dist/types/src/plugin-settings/translations.d.ts.map +0 -1
  497. package/dist/types/src/react/ErrorBoundary.d.ts +0 -30
  498. package/dist/types/src/react/ErrorBoundary.d.ts.map +0 -1
  499. package/dist/types/src/react/IntentContext.d.ts +0 -8
  500. package/dist/types/src/react/IntentContext.d.ts.map +0 -1
  501. package/dist/types/src/react/PluginManagerProvider.d.ts +0 -10
  502. package/dist/types/src/react/PluginManagerProvider.d.ts.map +0 -1
  503. package/dist/types/src/react/Surface.d.ts +0 -12
  504. package/dist/types/src/react/Surface.d.ts.map +0 -1
  505. package/dist/types/src/react/Surface.stories.d.ts +0 -17
  506. package/dist/types/src/react/Surface.stories.d.ts.map +0 -1
  507. package/dist/types/src/react/common.d.ts +0 -13
  508. package/dist/types/src/react/common.d.ts.map +0 -1
  509. package/dist/types/src/react/index.d.ts +0 -7
  510. package/dist/types/src/react/index.d.ts.map +0 -1
  511. package/dist/types/src/react/useCapabilities.d.ts +0 -13
  512. package/dist/types/src/react/useCapabilities.d.ts.map +0 -1
  513. package/dist/types/src/react/useIntentResolver.d.ts +0 -3
  514. package/dist/types/src/react/useIntentResolver.d.ts.map +0 -1
  515. package/dist/types/src/worker.d.ts +0 -4
  516. package/dist/types/src/worker.d.ts.map +0 -1
  517. package/src/common/collaboration.ts +0 -18
  518. package/src/common/events.ts +0 -79
  519. package/src/common/file.ts +0 -22
  520. package/src/common/graph.ts +0 -30
  521. package/src/common/layout.ts +0 -277
  522. package/src/common/surface.ts +0 -83
  523. package/src/components/App.stories.tsx +0 -33
  524. package/src/components/App.tsx +0 -59
  525. package/src/components/DefaultFallback.tsx +0 -26
  526. package/src/components/useApp.tsx +0 -164
  527. package/src/core/capabilities.test.ts +0 -136
  528. package/src/core/capabilities.ts +0 -259
  529. package/src/core/manager.test.ts +0 -516
  530. package/src/core/manager.ts +0 -604
  531. package/src/playground/debug/Debug.tsx +0 -39
  532. package/src/playground/debug/plugin.ts +0 -16
  533. package/src/playground/generator/Main.tsx +0 -71
  534. package/src/playground/generator/Toolbar.tsx +0 -47
  535. package/src/playground/generator/generator.ts +0 -48
  536. package/src/playground/generator/index.ts +0 -6
  537. package/src/playground/generator/plugin.ts +0 -22
  538. package/src/playground/layout/Layout.tsx +0 -33
  539. package/src/playground/layout/plugin.ts +0 -18
  540. package/src/playground/logger/Toolbar.tsx +0 -30
  541. package/src/playground/logger/plugin.ts +0 -41
  542. package/src/playground/logger/schema.ts +0 -12
  543. package/src/playground/playground.stories.tsx +0 -46
  544. package/src/plugin-intent/IntentPlugin.ts +0 -20
  545. package/src/plugin-intent/actions.ts +0 -31
  546. package/src/plugin-intent/errors.ts +0 -40
  547. package/src/plugin-intent/index.ts +0 -9
  548. package/src/plugin-intent/intent-dispatcher.test.ts +0 -286
  549. package/src/plugin-intent/intent-dispatcher.ts +0 -337
  550. package/src/plugin-intent/intent.ts +0 -154
  551. package/src/plugin-intent/meta.ts +0 -10
  552. package/src/plugin-settings/SettingsPlugin.ts +0 -34
  553. package/src/plugin-settings/actions.ts +0 -25
  554. package/src/plugin-settings/app-graph-builder.ts +0 -160
  555. package/src/plugin-settings/index.ts +0 -6
  556. package/src/plugin-settings/intent-resolver.ts +0 -35
  557. package/src/plugin-settings/meta.ts +0 -10
  558. package/src/plugin-settings/store.ts +0 -33
  559. package/src/plugin-settings/translations.ts +0 -19
  560. package/src/react/ErrorBoundary.tsx +0 -56
  561. package/src/react/IntentContext.tsx +0 -35
  562. package/src/react/Surface.stories.tsx +0 -101
  563. package/src/react/Surface.tsx +0 -86
  564. package/src/react/common.ts +0 -13
  565. package/src/react/index.ts +0 -10
  566. package/src/react/useCapabilities.ts +0 -31
  567. package/src/react/useIntentResolver.ts +0 -22
  568. package/src/worker.ts +0 -11
  569. /package/dist/lib/browser/{intent-dispatcher-6SHA5B3N.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
  570. /package/dist/lib/browser/{worker.mjs.map → common/activation-events.mjs.map} +0 -0
  571. /package/dist/lib/{node-esm/intent-dispatcher-SIYQ5ZIU.mjs.map → browser/common/capabilities.mjs.map} +0 -0
  572. /package/dist/lib/{node-esm/worker.mjs.map → browser/core/activation-event.mjs.map} +0 -0
@@ -0,0 +1,1446 @@
1
+ import {
2
+ eventKey,
3
+ getEvents,
4
+ isAllOf
5
+ } from "./chunk-66IXTIVK.mjs";
6
+ import {
7
+ LazyPluginError,
8
+ PluginDependencyError,
9
+ Service as Service2,
10
+ isLazy,
11
+ resolveLazy
12
+ } from "./chunk-SLX73WRZ.mjs";
13
+ import {
14
+ Service
15
+ } from "./chunk-IW44C7UL.mjs";
16
+ import {
17
+ __export
18
+ } from "./chunk-J5LGTIGS.mjs";
19
+
20
+ // src/core/plugin-manager.ts
21
+ var plugin_manager_exports = {};
22
+ __export(plugin_manager_exports, {
23
+ ManagerTypeId: () => ManagerTypeId,
24
+ PluginInitializationError: () => PluginInitializationError,
25
+ PluginTimeoutError: () => PluginTimeoutError,
26
+ isManager: () => isManager,
27
+ make: () => make5
28
+ });
29
+ import { Atom as Atom3, Registry } from "@effect-atom/atom-react";
30
+ import * as Array from "effect/Array";
31
+ import * as Cause from "effect/Cause";
32
+ import * as Deferred2 from "effect/Deferred";
33
+ import * as Duration from "effect/Duration";
34
+ import * as Effect3 from "effect/Effect";
35
+ import * as Fiber from "effect/Fiber";
36
+ import * as Function from "effect/Function";
37
+ import * as HashSet from "effect/HashSet";
38
+ import * as PubSub from "effect/PubSub";
39
+ import * as Ref from "effect/Ref";
40
+ import { runAndForwardErrors as runAndForwardErrors2 } from "@dxos/effect";
41
+ import { Performance } from "@dxos/effect";
42
+ import { BaseError } from "@dxos/errors";
43
+ import { log as log3 } from "@dxos/log";
44
+
45
+ // src/core/capability-manager.ts
46
+ var capability_manager_exports = {};
47
+ __export(capability_manager_exports, {
48
+ make: () => make2
49
+ });
50
+ import { Atom } from "@effect-atom/atom-react";
51
+ import * as Deferred from "effect/Deferred";
52
+ import * as Effect from "effect/Effect";
53
+ import { invariant } from "@dxos/invariant";
54
+ import { log } from "@dxos/log";
55
+ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/capability-manager.ts";
56
+ var CapabilityManagerImpl = class {
57
+ _registry;
58
+ _capabilityEntries = Atom.family(() => {
59
+ return Atom.make([]).pipe(Atom.keepAlive);
60
+ });
61
+ _capabilities = Atom.family((id) => {
62
+ return Atom.make((get2) => {
63
+ const current = get2(this._capabilityEntries(id));
64
+ return current.map((c) => c.implementation);
65
+ }).pipe(Atom.keepAlive);
66
+ });
67
+ _capabilitiesByModule = Atom.family((id) => {
68
+ return Atom.make((get2) => {
69
+ const entries = get2(this._capabilityEntries(id));
70
+ const result = {};
71
+ for (const entry of entries) {
72
+ (result[entry.moduleId] ??= []).push(entry.implementation);
73
+ }
74
+ return result;
75
+ }).pipe(Atom.keepAlive);
76
+ });
77
+ _capability = Atom.family((id) => {
78
+ return Atom.make((get2) => {
79
+ const current = get2(this._capabilities(id));
80
+ invariant(current.length > 0, `No capability found for ${id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 35, S: this, A: ["current.length > 0", "`No capability found for ${id}`"] });
81
+ return current[0];
82
+ });
83
+ });
84
+ constructor({ registry }) {
85
+ this._registry = registry;
86
+ }
87
+ contribute({ module: moduleId, interface: interfaceDef, implementation }) {
88
+ const current = this._registry.get(this._capabilityEntries(interfaceDef.identifier));
89
+ const isDuplicate = current.some((c) => c.moduleId === moduleId && c.implementation === implementation);
90
+ if (isDuplicate) {
91
+ log("capability already contributed, skipping", {
92
+ id: interfaceDef.identifier,
93
+ moduleId
94
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 46, S: this });
95
+ return;
96
+ }
97
+ const entry = {
98
+ moduleId,
99
+ implementation
100
+ };
101
+ this._registry.set(this._capabilityEntries(interfaceDef.identifier), [
102
+ ...current,
103
+ entry
104
+ ]);
105
+ log("capability contributed", {
106
+ id: interfaceDef.identifier,
107
+ moduleId,
108
+ count: current.length
109
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 60, S: this });
110
+ }
111
+ remove(interfaceDef, implementation) {
112
+ const current = this._registry.get(this._capabilityEntries(interfaceDef.identifier));
113
+ if (current.length === 0) {
114
+ return;
115
+ }
116
+ const next = current.filter((c) => c.implementation !== implementation);
117
+ if (next.length !== current.length) {
118
+ this._registry.set(this._capabilityEntries(interfaceDef.identifier), next);
119
+ log("capability removed", {
120
+ id: interfaceDef.identifier,
121
+ count: current.length
122
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 74, S: this });
123
+ } else {
124
+ log.warn("capability not removed", {
125
+ id: interfaceDef.identifier
126
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 79, S: this });
127
+ }
128
+ }
129
+ atom(interfaceDef) {
130
+ return this._capabilities(interfaceDef.identifier);
131
+ }
132
+ getAll(interfaceDef) {
133
+ return this._registry.get(this.atom(interfaceDef));
134
+ }
135
+ get(interfaceDef) {
136
+ const capabilities = this.getAll(interfaceDef);
137
+ invariant(capabilities.length > 0, `No capability found for ${interfaceDef.identifier}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 93, S: this, A: ["capabilities.length > 0", "`No capability found for ${interfaceDef.identifier}`"] });
138
+ return capabilities[0];
139
+ }
140
+ waitFor(interfaceDef) {
141
+ return Effect.gen(this, function* () {
142
+ const [capability] = this.getAll(interfaceDef);
143
+ if (capability) {
144
+ return capability;
145
+ }
146
+ const deferred = yield* Deferred.make();
147
+ const cancel = this._registry.subscribe(this.atom(interfaceDef), (capabilities) => {
148
+ if (capabilities.length > 0) {
149
+ Effect.runSync(Deferred.succeed(deferred, capabilities[0]));
150
+ }
151
+ });
152
+ const result = yield* Deferred.await(deferred);
153
+ cancel();
154
+ return result;
155
+ });
156
+ }
157
+ atomByModule(interfaceDef) {
158
+ return this._capabilitiesByModule(interfaceDef.identifier);
159
+ }
160
+ };
161
+ var make2 = (options) => new CapabilityManagerImpl(options);
162
+
163
+ // src/core/registry.ts
164
+ var registry_exports = {};
165
+ __export(registry_exports, {
166
+ Manager: () => Manager
167
+ });
168
+ import { Atom as Atom2 } from "@effect-atom/atom-react";
169
+ import * as Effect2 from "effect/Effect";
170
+ import { runAndForwardErrors } from "@dxos/effect";
171
+ import { log as log2 } from "@dxos/log";
172
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/registry.ts";
173
+ var NULL_PROVIDER = {
174
+ listPlugins: () => Effect2.succeed([]),
175
+ listVersions: () => Effect2.fail(new Error("No plugin registry provider configured")),
176
+ getPlugin: () => Effect2.fail(new Error("No plugin registry provider configured"))
177
+ };
178
+ var Manager = class {
179
+ plugins;
180
+ #provider;
181
+ constructor(provider, atomRegistry) {
182
+ this.#provider = provider ?? NULL_PROVIDER;
183
+ const initialLoading = provider !== void 0;
184
+ this.plugins = Atom2.make({
185
+ entries: [],
186
+ loading: initialLoading,
187
+ error: null
188
+ }).pipe(Atom2.keepAlive);
189
+ if (provider !== void 0) {
190
+ void runAndForwardErrors(provider.listPlugins().pipe(Effect2.match({
191
+ onSuccess: (entries) => atomRegistry.set(this.plugins, {
192
+ entries,
193
+ loading: false,
194
+ error: null
195
+ }),
196
+ onFailure: (error) => {
197
+ log2.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 49, S: this });
198
+ atomRegistry.set(this.plugins, {
199
+ entries: [],
200
+ loading: false,
201
+ error
202
+ });
203
+ }
204
+ })));
205
+ }
206
+ }
207
+ /** Forwards to the underlying provider. */
208
+ listPlugins() {
209
+ return this.#provider.listPlugins();
210
+ }
211
+ /** Forwards to the underlying provider. */
212
+ listVersions(repo) {
213
+ return this.#provider.listVersions(repo);
214
+ }
215
+ /** Forwards to the underlying provider. */
216
+ getPlugin(repo, version) {
217
+ return this.#provider.getPlugin(repo, version);
218
+ }
219
+ };
220
+
221
+ // src/core/plugin-manager.ts
222
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/plugin-manager.ts";
223
+ var PluginInitializationError = class extends BaseError.extend("PluginInitializationError", "Plugin manager initialization failed") {
224
+ };
225
+ var PluginTimeoutError = class extends BaseError.extend("PluginTimeoutError", "Plugin operation timed out") {
226
+ };
227
+ var DEFAULT_LOAD_TIMEOUT = Duration.seconds(30);
228
+ var DEFAULT_ACTIVATION_TIMEOUT = Duration.seconds(30);
229
+ var ManagerTypeId = /* @__PURE__ */ Symbol.for("@dxos/app-framework/Manager");
230
+ var isManager = (value) => {
231
+ return typeof value === "object" && value !== null && ManagerTypeId in value;
232
+ };
233
+ var ManagerImpl = class {
234
+ [ManagerTypeId] = ManagerTypeId;
235
+ activation = Effect3.runSync(PubSub.unbounded());
236
+ capabilities;
237
+ registry;
238
+ pluginRegistry;
239
+ _pluginsAtom;
240
+ _coreAtom;
241
+ _enabledAtom;
242
+ _modulesAtom;
243
+ _activeAtom;
244
+ _eventsFiredAtom;
245
+ _pendingResetAtom;
246
+ _failedAtom;
247
+ _pluginLoader;
248
+ _onRemove;
249
+ _loadTimeout;
250
+ _activationTimeout;
251
+ _capabilities = /* @__PURE__ */ new Map();
252
+ _moduleMemoMap = /* @__PURE__ */ new Map();
253
+ _moduleSemaphores = /* @__PURE__ */ new Map();
254
+ // Coalesces concurrent `_resolveLazyPlugin` calls per plugin id. Without
255
+ // this, two callers entering `enable(id)` before the swap completes would
256
+ // each invoke `mod.default(options)` and produce distinct module objects,
257
+ // defeating `_addModule`'s reference-equality dedupe and racing the
258
+ // `_pluginsAtom` swap.
259
+ _resolvingPlugins = /* @__PURE__ */ new Map();
260
+ // Tracks dev-source plugins (loaded via a Vite dev server) keyed by id.
261
+ // When `shadow` is present, the entry has displaced an existing plugin —
262
+ // `remove` reinstates it and re-enables iff `wasEnabled`. Entries without a
263
+ // shadow are dev plugins with no underlying registry/builtin to restore.
264
+ // The atom mirrors the map's keys for UI subscribers (they don't need the
265
+ // shadow internals); the two stay in sync via {@link _markDev}/{@link _unmarkDev}.
266
+ _devPlugins = /* @__PURE__ */ new Map();
267
+ _devPluginIdsAtom;
268
+ _activatingEvents = Effect3.runSync(Ref.make([]));
269
+ _activatingModules = Effect3.runSync(Ref.make([]));
270
+ _inFlightFibers = Effect3.runSync(Ref.make([]));
271
+ _shutdownSemaphore = Effect3.runSync(Effect3.makeSemaphore(1));
272
+ _shuttingDown = Effect3.runSync(Ref.make(false));
273
+ // Tracks the constructor-launched core/enabled `enable()` calls so that
274
+ // `activate` can wait for module registration before dispatching events.
275
+ // Lazy plugins make `enable` asynchronous (a dynamic `import()` happens
276
+ // inside it), so without this synchronization an `activate` triggered
277
+ // immediately after `make` could fire on an empty module set. Failures
278
+ // are wrapped in `PluginInitializationError` so awaiters get a tagged
279
+ // error rather than the wide `Error` produced by the underlying chain.
280
+ _initialization = Effect3.runSync(Deferred2.make());
281
+ constructor({ pluginLoader, plugins = [], enabled = [], registry, pluginRegistryProvider, onRemove, loadTimeout = DEFAULT_LOAD_TIMEOUT, activationTimeout = DEFAULT_ACTIVATION_TIMEOUT }) {
282
+ const core = plugins.filter(({ meta }) => meta.tags?.includes("system")).map(({ meta }) => meta.id);
283
+ this.registry = registry ?? Registry.make();
284
+ this.capabilities = make2({
285
+ registry: this.registry
286
+ });
287
+ this.pluginRegistry = new Manager(pluginRegistryProvider, this.registry);
288
+ this._pluginLoader = pluginLoader;
289
+ this._onRemove = onRemove;
290
+ this._loadTimeout = loadTimeout;
291
+ this._activationTimeout = activationTimeout;
292
+ this._pluginsAtom = Atom3.make(plugins).pipe(Atom3.keepAlive);
293
+ this._coreAtom = Atom3.make(core).pipe(Atom3.keepAlive);
294
+ this._enabledAtom = Atom3.make(enabled).pipe(Atom3.keepAlive);
295
+ this._modulesAtom = Atom3.make([]).pipe(Atom3.keepAlive);
296
+ this._activeAtom = Atom3.make([]).pipe(Atom3.keepAlive);
297
+ this._eventsFiredAtom = Atom3.make([]).pipe(Atom3.keepAlive);
298
+ this._pendingResetAtom = Atom3.make([]).pipe(Atom3.keepAlive);
299
+ this._failedAtom = Atom3.make([]).pipe(Atom3.keepAlive);
300
+ this._devPluginIdsAtom = Atom3.make([]).pipe(Atom3.keepAlive);
301
+ plugins.forEach((plugin) => this._addPlugin(plugin));
302
+ const initialIds = [
303
+ .../* @__PURE__ */ new Set([
304
+ ...core,
305
+ ...enabled
306
+ ])
307
+ ];
308
+ void Effect3.all(initialIds.map((id) => this.enable(id))).pipe(Effect3.mapError((cause) => new PluginInitializationError({
309
+ cause
310
+ })), Effect3.tap(() => Deferred2.succeed(this._initialization, void 0)), Effect3.tapErrorCause((cause) => Deferred2.failCause(this._initialization, cause))).pipe(runAndForwardErrors2);
311
+ }
312
+ get plugins() {
313
+ return this._pluginsAtom;
314
+ }
315
+ get core() {
316
+ return this._coreAtom;
317
+ }
318
+ /**
319
+ * Ids of plugins that are currently enabled.
320
+ */
321
+ get enabled() {
322
+ return this._enabledAtom;
323
+ }
324
+ /**
325
+ * Modules of plugins which are currently enabled.
326
+ */
327
+ get modules() {
328
+ return this._modulesAtom;
329
+ }
330
+ /**
331
+ * Ids of modules which are currently active.
332
+ */
333
+ get active() {
334
+ return this._activeAtom;
335
+ }
336
+ /**
337
+ * Ids of events which have been fired.
338
+ */
339
+ get eventsFired() {
340
+ return this._eventsFiredAtom;
341
+ }
342
+ /**
343
+ * Ids of modules which are pending reset.
344
+ */
345
+ get pendingReset() {
346
+ return this._pendingResetAtom;
347
+ }
348
+ /**
349
+ * Plugins that failed to load or activate.
350
+ */
351
+ get failed() {
352
+ return this._failedAtom;
353
+ }
354
+ /**
355
+ * Ids of currently-registered plugins that came from a dev source.
356
+ */
357
+ get devPluginIds() {
358
+ return this._devPluginIdsAtom;
359
+ }
360
+ getPlugins() {
361
+ return this._get(this._pluginsAtom);
362
+ }
363
+ getCore() {
364
+ return this._get(this._coreAtom);
365
+ }
366
+ getEnabled() {
367
+ return this._get(this._enabledAtom);
368
+ }
369
+ getModules() {
370
+ return this._get(this._modulesAtom);
371
+ }
372
+ getActive() {
373
+ return this._get(this._activeAtom);
374
+ }
375
+ getEventsFired() {
376
+ return this._get(this._eventsFiredAtom);
377
+ }
378
+ getPendingReset() {
379
+ return this._get(this._pendingResetAtom);
380
+ }
381
+ getFailed() {
382
+ return this._get(this._failedAtom);
383
+ }
384
+ getDevPluginIds() {
385
+ return this._get(this._devPluginIdsAtom);
386
+ }
387
+ /**
388
+ * Marks `id` as dev-sourced. If the plugin displaced an existing one, pass
389
+ * the shadow snapshot so `remove` can restore it. Repeat calls (e.g. a dev
390
+ * plugin reload) preserve the original shadow target — restoration always
391
+ * unwinds back to the real underlying plugin, never an intermediate dev build.
392
+ */
393
+ _markDev(id, shadow) {
394
+ if (this._devPlugins.has(id)) {
395
+ return;
396
+ }
397
+ this._devPlugins.set(id, {
398
+ shadow
399
+ });
400
+ this._update(this._devPluginIdsAtom, (ids) => ids.includes(id) ? ids : [
401
+ ...ids,
402
+ id
403
+ ]);
404
+ }
405
+ /** Drops the dev-plugin entry and returns its shadow data (if any) for restoration. */
406
+ _unmarkDev(id) {
407
+ const entry = this._devPlugins.get(id);
408
+ this._devPlugins.delete(id);
409
+ this._update(this._devPluginIdsAtom, (ids) => ids.filter((existing) => existing !== id));
410
+ return entry?.shadow;
411
+ }
412
+ getDependencies(id, opts) {
413
+ const transitive = opts?.transitive !== false;
414
+ if (!transitive) {
415
+ return this._directDependencies(id);
416
+ }
417
+ const walk = this._computeDependencyClosure(id);
418
+ return walk.order.filter((depId) => depId !== id);
419
+ }
420
+ getDependents(id, opts) {
421
+ return this._collectDependents(id, {
422
+ transitive: opts?.transitive !== false,
423
+ enabledOnly: opts?.enabledOnly === true
424
+ });
425
+ }
426
+ clearFailure(id) {
427
+ const current = this._get(this._failedAtom);
428
+ if (!current.some((failure) => failure.id === id)) {
429
+ return false;
430
+ }
431
+ this._set(this._failedAtom, current.filter((failure) => failure.id !== id));
432
+ return true;
433
+ }
434
+ /**
435
+ * Adds a plugin to the manager via the plugin loader.
436
+ * The plugin is registered but not enabled; call `enable` separately to activate it.
437
+ * @param id The id of the plugin.
438
+ */
439
+ add(id) {
440
+ return Effect3.gen(this, function* () {
441
+ log3("add plugin", {
442
+ id
443
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 262, S: this });
444
+ const { plugin, dev = false } = yield* this._pluginLoader(id);
445
+ const pluginId = plugin.meta.id;
446
+ const existing = this._getPlugin(pluginId);
447
+ if (dev && existing && existing !== plugin) {
448
+ const wasEnabled = this._get(this._enabledAtom).includes(pluginId);
449
+ if (wasEnabled) {
450
+ yield* this.disable(pluginId);
451
+ }
452
+ this._markDev(pluginId, {
453
+ plugin: existing,
454
+ wasEnabled
455
+ });
456
+ this._update(this._pluginsAtom, (plugins) => plugins.map((p) => p.meta.id === pluginId ? plugin : p));
457
+ } else {
458
+ this._addPlugin(plugin);
459
+ if (dev) {
460
+ this._markDev(pluginId);
461
+ }
462
+ }
463
+ return plugin;
464
+ });
465
+ }
466
+ /**
467
+ * Enables a plugin.
468
+ * @param id The id of the plugin.
469
+ * @param opts See {@link PluginManager.enable}.
470
+ */
471
+ enable(id, opts) {
472
+ const resolveDependencies = opts?.resolveDependencies !== false;
473
+ return Effect3.gen(this, function* () {
474
+ log3("enable plugin", {
475
+ id,
476
+ resolveDependencies
477
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 301, S: this });
478
+ if (!resolveDependencies) {
479
+ return yield* this._enableOne(id);
480
+ }
481
+ if (!this._getPlugin(id) && !this._getCatalogEntry(id)) {
482
+ return yield* this._enableOne(id);
483
+ }
484
+ const walk = this._computeDependencyClosure(id);
485
+ if (walk.cycle) {
486
+ this._recordFailure(id, "load", new PluginDependencyError({
487
+ context: {
488
+ id,
489
+ reason: "cycle",
490
+ path: walk.cycle
491
+ }
492
+ }));
493
+ return false;
494
+ }
495
+ if (walk.missing.length > 0) {
496
+ this._recordFailure(id, "load", new PluginDependencyError({
497
+ context: {
498
+ id,
499
+ reason: "missing",
500
+ missing: walk.missing
501
+ }
502
+ }));
503
+ return false;
504
+ }
505
+ let queue = walk.toInstall.slice();
506
+ const installed = /* @__PURE__ */ new Set();
507
+ while (queue.length > 0) {
508
+ const next = queue.shift();
509
+ if (installed.has(next) || this._getPlugin(next)) {
510
+ continue;
511
+ }
512
+ const installResult = yield* this.add(next).pipe(Effect3.either);
513
+ if (installResult._tag === "Left") {
514
+ this._recordFailure(id, "load", new PluginDependencyError({
515
+ context: {
516
+ id,
517
+ reason: "install-failed",
518
+ dependency: next
519
+ },
520
+ cause: installResult.left
521
+ }));
522
+ return false;
523
+ }
524
+ installed.add(next);
525
+ const rewalk = this._computeDependencyClosure(id);
526
+ if (rewalk.cycle) {
527
+ this._recordFailure(id, "load", new PluginDependencyError({
528
+ context: {
529
+ id,
530
+ reason: "cycle",
531
+ path: rewalk.cycle
532
+ }
533
+ }));
534
+ return false;
535
+ }
536
+ if (rewalk.missing.length > 0) {
537
+ this._recordFailure(id, "load", new PluginDependencyError({
538
+ context: {
539
+ id,
540
+ reason: "missing",
541
+ missing: rewalk.missing
542
+ }
543
+ }));
544
+ return false;
545
+ }
546
+ queue = rewalk.toInstall.filter((depId) => !installed.has(depId));
547
+ }
548
+ const order = this._computeDependencyClosure(id).order;
549
+ let succeeded = false;
550
+ for (const depId of order) {
551
+ const ok = yield* this._enableOne(depId);
552
+ if (depId === id) {
553
+ succeeded = ok;
554
+ }
555
+ }
556
+ return succeeded;
557
+ });
558
+ }
559
+ /**
560
+ * Enables a single plugin without consulting its declared dependencies.
561
+ * Used by {@link enable} as the leaf step after closure resolution, and
562
+ * directly when callers pass `{ resolveDependencies: false }`.
563
+ *
564
+ * The underlying operations (`_addModule`, `_setPendingResetByModule`,
565
+ * `activate`) are all idempotent, so this method is safe to call multiple
566
+ * times for the same id. The constructor's bootstrap path relies on this:
567
+ * the persisted `enabled` ids are written into `_enabledAtom` up front, so
568
+ * the very first `enable(id)` for those plugins sees `alreadyEnabled`-style
569
+ * state but still needs to perform the module registration and activation.
570
+ */
571
+ _enableOne(id) {
572
+ return Effect3.gen(this, function* () {
573
+ const stub = this._getPlugin(id);
574
+ if (!stub) {
575
+ return false;
576
+ }
577
+ this.clearFailure(id);
578
+ const plugin = yield* this._resolveLazyPlugin(stub);
579
+ this._update(this._enabledAtom, (enabled) => enabled.includes(id) ? enabled : [
580
+ ...enabled,
581
+ id
582
+ ]);
583
+ plugin.modules.forEach((module) => {
584
+ this._addModule(module);
585
+ this._setPendingResetByModule(module);
586
+ });
587
+ log3("pending reset", {
588
+ events: [
589
+ ...this.getPendingReset()
590
+ ]
591
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 428, S: this });
592
+ yield* Effect3.all(this.getPendingReset().map((event) => this.activate(event)), {
593
+ concurrency: "unbounded"
594
+ });
595
+ return true;
596
+ });
597
+ }
598
+ /**
599
+ * Resolves a lazy plugin stub (returned by {@link Plugin.lazy}) to its
600
+ * loaded form and swaps it into `_pluginsAtom`. Returns the input unchanged
601
+ * when the plugin is already resolved, so callers can `yield*` this
602
+ * unconditionally. The lazy stub carries `meta` synchronously but its
603
+ * `modules` list is empty until the loader resolves; the swap ensures
604
+ * subsequent enable/disable operations see the resolved plugin.
605
+ *
606
+ * Concurrent calls for the same id are coalesced via `_resolvingPlugins`:
607
+ * the first caller starts the resolution, every subsequent caller awaits
608
+ * the same `Deferred`. On failure we publish a `lazy:<id>` error message
609
+ * and skip the atom swap so the failure is observable to the activation
610
+ * subscriber and a retry can be attempted.
611
+ */
612
+ _resolveLazyPlugin(plugin) {
613
+ return Effect3.gen(this, function* () {
614
+ if (!isLazy(plugin)) {
615
+ return plugin;
616
+ }
617
+ const id = plugin.meta.id;
618
+ const existing = this._resolvingPlugins.get(id);
619
+ if (existing) {
620
+ return yield* Deferred2.await(existing);
621
+ }
622
+ const deferred = yield* Deferred2.make();
623
+ this._resolvingPlugins.set(id, deferred);
624
+ return yield* Effect3.gen(this, function* () {
625
+ log3("resolving lazy plugin", {
626
+ id
627
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 465, S: this });
628
+ yield* PubSub.publish(this.activation, {
629
+ event: "",
630
+ state: "activating",
631
+ module: `lazy:${id}`
632
+ });
633
+ const resolvedPlugin = yield* resolveLazy(plugin).pipe(
634
+ // Cap how long a remote import can hang. Without this the host can
635
+ // sit on a pending dynamic `import()` indefinitely if the plugin's
636
+ // server is unreachable, which stalls every caller awaiting
637
+ // `enable(id)` and (transitively) the manager's initialization.
638
+ Effect3.timeoutFail({
639
+ duration: this._loadTimeout,
640
+ onTimeout: () => new LazyPluginError({
641
+ context: {
642
+ id,
643
+ reason: "load-failed"
644
+ },
645
+ cause: new PluginTimeoutError({
646
+ context: {
647
+ id,
648
+ phase: "load"
649
+ }
650
+ })
651
+ })
652
+ })
653
+ );
654
+ this._update(this._pluginsAtom, (plugins) => plugins.map((p) => p.meta.id === id ? resolvedPlugin : p));
655
+ yield* PubSub.publish(this.activation, {
656
+ event: "",
657
+ state: "activated",
658
+ module: `lazy:${id}`
659
+ });
660
+ return resolvedPlugin;
661
+ }).pipe(Effect3.tapError((error) => Effect3.gen(this, function* () {
662
+ yield* PubSub.publish(this.activation, {
663
+ event: "",
664
+ state: "error",
665
+ module: `lazy:${id}`,
666
+ error
667
+ });
668
+ this._recordFailure(id, "load", error);
669
+ this._scheduleAutoDisable(id);
670
+ })), Effect3.tap((value) => Deferred2.succeed(deferred, value)), Effect3.tapErrorCause((cause) => Deferred2.failCause(deferred, cause)), Effect3.ensuring(Effect3.sync(() => this._resolvingPlugins.delete(id))));
671
+ });
672
+ }
673
+ /**
674
+ * Removes a plugin from the manager.
675
+ * @param id The id of the plugin.
676
+ * @param opts See {@link PluginManager.remove}.
677
+ */
678
+ remove(id, opts) {
679
+ return Effect3.gen(this, function* () {
680
+ log3("remove plugin", {
681
+ id
682
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 517, S: this });
683
+ const wasDev = this._devPlugins.has(id);
684
+ const disabled = yield* this.disable(id, opts);
685
+ if (!disabled) {
686
+ return false;
687
+ }
688
+ this._removePlugin(id);
689
+ if (this._onRemove) {
690
+ this._runForkedFiber(this._onRemove(id).pipe(Effect3.tapError((error) => Effect3.sync(() => log3.warn("plugin remove hook failed", {
691
+ id,
692
+ error
693
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 527, S: this }))), Effect3.ignore));
694
+ }
695
+ if (wasDev) {
696
+ const shadow = this._unmarkDev(id);
697
+ if (shadow) {
698
+ this._addPlugin(shadow.plugin);
699
+ if (shadow.wasEnabled) {
700
+ yield* this.enable(id);
701
+ }
702
+ }
703
+ }
704
+ return true;
705
+ });
706
+ }
707
+ /**
708
+ * Disables a plugin.
709
+ * @param id The id of the plugin.
710
+ * @param opts See {@link PluginManager.disable}.
711
+ */
712
+ disable(id, { cascade = true } = {}) {
713
+ return Effect3.gen(this, function* () {
714
+ log3("disable plugin", {
715
+ id,
716
+ cascade
717
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 555, S: this });
718
+ if (this._get(this._coreAtom).includes(id)) {
719
+ return false;
720
+ }
721
+ const plugin = this._getPlugin(id);
722
+ if (!plugin) {
723
+ return false;
724
+ }
725
+ if (cascade) {
726
+ const enabledDependents = this._collectDependents(id, {
727
+ transitive: true,
728
+ enabledOnly: true
729
+ });
730
+ if (enabledDependents.length > 0) {
731
+ const coreDependent = enabledDependents.find((dependentId) => this._get(this._coreAtom).includes(dependentId));
732
+ if (coreDependent) {
733
+ return yield* Effect3.fail(new PluginDependencyError({
734
+ context: {
735
+ id,
736
+ reason: "core-dependent",
737
+ coreDependent
738
+ }
739
+ }));
740
+ }
741
+ for (const dependentId of enabledDependents) {
742
+ yield* this._disableOne(dependentId);
743
+ }
744
+ }
745
+ }
746
+ yield* this._disableOne(id);
747
+ return true;
748
+ });
749
+ }
750
+ /**
751
+ * Disables a single plugin without consulting its dependents. Used by
752
+ * {@link disable} after the dependents pass has run (or been skipped via
753
+ * `cascade: false`).
754
+ */
755
+ _disableOne(id) {
756
+ return Effect3.gen(this, function* () {
757
+ if (this._get(this._coreAtom).includes(id)) {
758
+ return false;
759
+ }
760
+ const plugin = this._getPlugin(id);
761
+ if (!plugin) {
762
+ return false;
763
+ }
764
+ const enabledIndex = this._get(this._enabledAtom).findIndex((enabled) => enabled === id);
765
+ if (enabledIndex !== -1) {
766
+ this._update(this._enabledAtom, (enabled) => enabled.filter((item) => item !== id));
767
+ yield* this.deactivate(id);
768
+ plugin.modules.forEach((module) => {
769
+ this._removeModule(module.id);
770
+ });
771
+ }
772
+ return true;
773
+ });
774
+ }
775
+ /**
776
+ * Activates plugins based on the activation event.
777
+ * @param event The activation event.
778
+ * @returns Whether the activation was successful.
779
+ */
780
+ activate(event, params) {
781
+ const key = typeof event === "string" ? event : eventKey(event);
782
+ return Effect3.gen(this, function* () {
783
+ if (yield* this._isShuttingDown()) {
784
+ log3("skipping activation during shutdown", {
785
+ key,
786
+ ...params
787
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 626, S: this });
788
+ return false;
789
+ }
790
+ yield* Deferred2.await(this._initialization);
791
+ return yield* Effect3.withFiberRuntime((fiber) => this._activateEvent(key, params, fiber).pipe(together(Effect3.sleep(Duration.seconds(15)).pipe(Effect3.andThen(Effect3.sync(() => log3.warn("event activation is taking a long time", {
792
+ event: key
793
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 637, S: this }))))), Performance.addTrackEntry({
794
+ name: typeof event === "string" ? event : eventKey(event),
795
+ devtools: {
796
+ dataType: "track-entry",
797
+ track: "Event Activation",
798
+ trackGroup: "Composer",
799
+ color: "primary"
800
+ }
801
+ })));
802
+ });
803
+ }
804
+ /**
805
+ * Deactivates all of the modules for a plugin.
806
+ * @param id The id of the plugin.
807
+ * @returns Whether the deactivation was successful.
808
+ */
809
+ deactivate(id) {
810
+ return Effect3.gen(this, function* () {
811
+ const plugin = this._getPlugin(id);
812
+ if (!plugin) {
813
+ return false;
814
+ }
815
+ const modules = plugin.modules;
816
+ const results = yield* Effect3.all(modules.map((module) => this._deactivateModule(module)), {
817
+ concurrency: "unbounded"
818
+ });
819
+ return results.every((result) => result);
820
+ });
821
+ }
822
+ /**
823
+ * Re-activates the modules that were activated by the event.
824
+ * @param event The activation event.
825
+ * @returns Whether the reset was successful.
826
+ */
827
+ reset(event) {
828
+ return Effect3.gen(this, function* () {
829
+ const key = typeof event === "string" ? event : eventKey(event);
830
+ log3("reset", {
831
+ key
832
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 674, S: this });
833
+ const modules = this._getActiveModulesByEvent(key);
834
+ const results = yield* Effect3.all(modules.map((module) => this._deactivateModule(module)), {
835
+ concurrency: "unbounded"
836
+ });
837
+ if (results.every((result) => result)) {
838
+ return yield* this.activate(key);
839
+ } else {
840
+ return false;
841
+ }
842
+ });
843
+ }
844
+ shutdown() {
845
+ return this._shutdownSemaphore.withPermits(1)(Effect3.gen(this, function* () {
846
+ yield* Ref.set(this._shuttingDown, true);
847
+ log3("shutdown", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 691, S: this });
848
+ yield* this._interruptInFlightActivations();
849
+ const activeIds = [
850
+ ...this._get(this._activeAtom)
851
+ ].reverse();
852
+ const allModules = this._get(this._modulesAtom);
853
+ const modulesToDeactivate = activeIds.map((id) => allModules.find((module) => module.id === id)).filter((module) => module != null);
854
+ for (const module of modulesToDeactivate) {
855
+ yield* this._deactivateModule(module);
856
+ }
857
+ this._set(this._eventsFiredAtom, []);
858
+ this._set(this._pendingResetAtom, []);
859
+ this._moduleMemoMap.clear();
860
+ yield* Ref.set(this._activatingEvents, []);
861
+ yield* Ref.set(this._activatingModules, []);
862
+ log3("shutdown complete", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 706, S: this });
863
+ return true;
864
+ }).pipe(Effect3.ensuring(Ref.set(this._shuttingDown, false))));
865
+ }
866
+ //
867
+ // State helpers
868
+ //
869
+ _get(atom) {
870
+ return this.registry.get(atom);
871
+ }
872
+ _set(atom, value) {
873
+ this.registry.set(atom, value);
874
+ }
875
+ _update(atom, updater) {
876
+ this._set(atom, updater(this._get(atom)));
877
+ }
878
+ _isShuttingDown() {
879
+ return Ref.get(this._shuttingDown);
880
+ }
881
+ _getPlugin(id) {
882
+ return this._get(this._pluginsAtom).find((plugin) => plugin.meta.id === id);
883
+ }
884
+ _getPluginIdForModule(moduleId) {
885
+ return this._get(this._pluginsAtom).find((plugin) => plugin.modules.some((module) => module.id === moduleId))?.meta.id;
886
+ }
887
+ /** Looks up an id in the cached registry catalog, returning the entry or `undefined`. */
888
+ _getCatalogEntry(id) {
889
+ return this._get(this.pluginRegistry.plugins).entries.find((entry) => entry.id === id);
890
+ }
891
+ /**
892
+ * Returns the direct `dependsOn` declarations for an id, drawing from the
893
+ * registered plugin's meta when available and falling back to the registry
894
+ * catalog entry. Unknown ids return an empty list (callers detect "missing"
895
+ * separately).
896
+ */
897
+ _directDependencies(id) {
898
+ const plugin = this._getPlugin(id);
899
+ if (plugin) {
900
+ return [
901
+ ...plugin.meta.dependsOn ?? []
902
+ ];
903
+ }
904
+ const catalog = this._getCatalogEntry(id);
905
+ return catalog?.dependsOn ? [
906
+ ...catalog.dependsOn
907
+ ] : [];
908
+ }
909
+ /**
910
+ * Computes the transitive dependency closure for an id.
911
+ *
912
+ * Walks {@link _directDependencies} (registered plugins ∪ catalog entries).
913
+ * Returns:
914
+ * - `order`: closure including the root in dependency-first topological order.
915
+ * - `missing`: ids in the closure that are neither registered nor in the catalog.
916
+ * - `toInstall`: ids in the closure that are in the catalog but not yet registered.
917
+ * - `cycle`: when a cycle is detected, the cycle path; otherwise `undefined`.
918
+ */
919
+ _computeDependencyClosure(id) {
920
+ const order = [];
921
+ const visited = /* @__PURE__ */ new Set();
922
+ const onStack = /* @__PURE__ */ new Set();
923
+ const stackPath = [];
924
+ const missing = [];
925
+ const toInstall = [];
926
+ let cycle;
927
+ const knownIds = /* @__PURE__ */ new Set([
928
+ ...this._get(this._pluginsAtom).map((plugin) => plugin.meta.id),
929
+ ...this._get(this.pluginRegistry.plugins).entries.map((entry) => entry.id)
930
+ ]);
931
+ const visit = (currentId) => {
932
+ if (cycle) {
933
+ return;
934
+ }
935
+ if (visited.has(currentId)) {
936
+ return;
937
+ }
938
+ if (onStack.has(currentId)) {
939
+ const cycleStart = stackPath.indexOf(currentId);
940
+ cycle = [
941
+ ...stackPath.slice(cycleStart),
942
+ currentId
943
+ ];
944
+ return;
945
+ }
946
+ onStack.add(currentId);
947
+ stackPath.push(currentId);
948
+ if (!knownIds.has(currentId)) {
949
+ missing.push(currentId);
950
+ } else if (!this._getPlugin(currentId)) {
951
+ toInstall.push(currentId);
952
+ }
953
+ for (const depId of this._directDependencies(currentId)) {
954
+ visit(depId);
955
+ if (cycle) {
956
+ break;
957
+ }
958
+ }
959
+ onStack.delete(currentId);
960
+ stackPath.pop();
961
+ if (!cycle) {
962
+ visited.add(currentId);
963
+ order.push(currentId);
964
+ }
965
+ };
966
+ visit(id);
967
+ return {
968
+ order,
969
+ missing,
970
+ toInstall,
971
+ cycle
972
+ };
973
+ }
974
+ /**
975
+ * Walks the reverse `dependsOn` edges across registered plugins. With
976
+ * `enabledOnly`, filters the result to currently-enabled ids. Returns
977
+ * dependents in dependents-before-deps order so callers (cascade-disable)
978
+ * can iterate and tear down leaves first.
979
+ */
980
+ _collectDependents(id, opts) {
981
+ const direct = this._get(this._pluginsAtom).filter((plugin) => plugin.meta.dependsOn?.includes(id)).map((plugin) => plugin.meta.id);
982
+ if (!opts.transitive) {
983
+ return opts.enabledOnly ? direct.filter((dependentId) => this._get(this._enabledAtom).includes(dependentId)) : direct;
984
+ }
985
+ const result = [];
986
+ const visited = /* @__PURE__ */ new Set();
987
+ const visit = (currentId) => {
988
+ if (visited.has(currentId)) {
989
+ return;
990
+ }
991
+ visited.add(currentId);
992
+ const parents = this._get(this._pluginsAtom).filter((plugin) => plugin.meta.dependsOn?.includes(currentId)).map((plugin) => plugin.meta.id);
993
+ for (const parentId of parents) {
994
+ visit(parentId);
995
+ if (parentId !== id && !result.includes(parentId)) {
996
+ result.push(parentId);
997
+ }
998
+ }
999
+ };
1000
+ visit(id);
1001
+ return opts.enabledOnly ? result.filter((dependentId) => this._get(this._enabledAtom).includes(dependentId)) : result;
1002
+ }
1003
+ /**
1004
+ * Records a failure for a plugin. Latest failure wins so the registry UI
1005
+ * always sees the most recent reason. Walks the `cause` chain when checking
1006
+ * for timeouts: lazy-load timeouts arrive wrapped in `LazyPluginError` (the
1007
+ * timeout is the cause), but the operator-visible reason should still be
1008
+ * `'timeout'`.
1009
+ */
1010
+ _recordFailure(id, phase, error) {
1011
+ const reason = isTimeoutCause(error) ? "timeout" : "error";
1012
+ const failure = {
1013
+ id,
1014
+ phase,
1015
+ reason,
1016
+ error,
1017
+ timestamp: Date.now()
1018
+ };
1019
+ log3.warn("plugin failed", {
1020
+ id,
1021
+ phase,
1022
+ reason,
1023
+ error: error.message
1024
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 858, S: this });
1025
+ this._update(this._failedAtom, (current) => [
1026
+ ...current.filter((entry) => entry.id !== id),
1027
+ failure
1028
+ ]);
1029
+ }
1030
+ /**
1031
+ * Fire-and-forget disable of a failed plugin. Forked because a failure can
1032
+ * happen mid-activation chain — yielding a `disable` inline would deadlock
1033
+ * on the shared semaphores. Core plugins are skipped (the host opted into
1034
+ * them being non-removable; the failure record is enough signal).
1035
+ */
1036
+ _scheduleAutoDisable(id) {
1037
+ if (this._get(this._coreAtom).includes(id)) {
1038
+ return;
1039
+ }
1040
+ if (!this._get(this._enabledAtom).includes(id)) {
1041
+ return;
1042
+ }
1043
+ this._runForkedFiber(this.disable(id).pipe(Effect3.tapError((error) => Effect3.sync(() => log3.warn("auto-disable failed", {
1044
+ id,
1045
+ error
1046
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 881, S: this }))), Effect3.ignore));
1047
+ }
1048
+ _getActiveModules() {
1049
+ const active = this._get(this._activeAtom);
1050
+ return this._get(this._modulesAtom).filter((module) => active.includes(module.id));
1051
+ }
1052
+ _getInactiveModules() {
1053
+ const active = this._get(this._activeAtom);
1054
+ return this._get(this._modulesAtom).filter((module) => !active.includes(module.id));
1055
+ }
1056
+ _getActiveModulesByEvent(key) {
1057
+ return this._getActiveModules().filter((module) => getEvents(module.activatesOn).map(eventKey).includes(key));
1058
+ }
1059
+ _getInactiveModulesByEvent(key) {
1060
+ return this._getInactiveModules().filter((module) => getEvents(module.activatesOn).map(eventKey).includes(key));
1061
+ }
1062
+ _setPendingResetByModule(module) {
1063
+ const activationEvents = getEvents(module.activatesOn).map(eventKey).filter((key) => this._get(this._eventsFiredAtom).includes(key));
1064
+ const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => {
1065
+ const pending = this._get(this._pendingResetAtom);
1066
+ return !pending.includes(event);
1067
+ });
1068
+ if (pendingReset.length > 0) {
1069
+ log3("pending reset", {
1070
+ events: pendingReset
1071
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 907, S: this });
1072
+ this._update(this._pendingResetAtom, (current) => [
1073
+ ...current,
1074
+ ...pendingReset
1075
+ ]);
1076
+ }
1077
+ }
1078
+ _clearPendingReset(key) {
1079
+ const pendingIndex = this._get(this._pendingResetAtom).findIndex((event) => event === key);
1080
+ if (pendingIndex !== -1) {
1081
+ this._update(this._pendingResetAtom, (pending) => pending.filter((event) => event !== key));
1082
+ }
1083
+ }
1084
+ //
1085
+ // Fiber helpers
1086
+ //
1087
+ _interruptInFlightActivations() {
1088
+ return Effect3.gen(this, function* () {
1089
+ const inFlightFibers = yield* Ref.get(this._inFlightFibers);
1090
+ yield* Effect3.forEach(inFlightFibers, (fiber) => Fiber.interrupt(fiber), {
1091
+ concurrency: "unbounded"
1092
+ });
1093
+ });
1094
+ }
1095
+ _trackFiber(ref, fiber) {
1096
+ return Ref.update(ref, (fibers) => [
1097
+ ...fibers,
1098
+ fiber
1099
+ ]);
1100
+ }
1101
+ _untrackFiber(ref, fiber) {
1102
+ return Ref.update(ref, (fibers) => fibers.filter((trackedFiber) => trackedFiber !== fiber));
1103
+ }
1104
+ /**
1105
+ * Spawns an effect on the default runtime and registers the resulting fiber in
1106
+ * `_inFlightFibers` so {@link shutdown} can interrupt it. Used from sync entry
1107
+ * points like {@link remove} where there is no enclosing Effect to fork from;
1108
+ * inside an Effect chain prefer the existing track/await/untrack pattern.
1109
+ */
1110
+ _runForkedFiber(effect) {
1111
+ const fiber = Effect3.runFork(effect);
1112
+ Effect3.runSync(this._trackFiber(this._inFlightFibers, fiber));
1113
+ Effect3.runFork(Fiber.await(fiber).pipe(Effect3.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))));
1114
+ }
1115
+ //
1116
+ // Registration helpers
1117
+ //
1118
+ _addPlugin(plugin) {
1119
+ log3("add plugin", {
1120
+ id: plugin.meta.id
1121
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 956, S: this });
1122
+ this._update(this._pluginsAtom, (plugins) => plugins.includes(plugin) ? plugins : [
1123
+ ...plugins,
1124
+ plugin
1125
+ ]);
1126
+ }
1127
+ _removePlugin(id) {
1128
+ log3("remove plugin", {
1129
+ id
1130
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 966, S: this });
1131
+ this._update(this._pluginsAtom, (plugins) => plugins.filter((plugin) => plugin.meta.id !== id));
1132
+ }
1133
+ _addModule(module) {
1134
+ log3("add module", {
1135
+ id: module.id
1136
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 972, S: this });
1137
+ this._update(this._modulesAtom, (modules) => modules.includes(module) ? modules : [
1138
+ ...modules,
1139
+ module
1140
+ ]);
1141
+ }
1142
+ _removeModule(id) {
1143
+ log3("remove module", {
1144
+ id
1145
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 982, S: this });
1146
+ this._update(this._modulesAtom, (modules) => modules.filter((module) => module.id !== id));
1147
+ }
1148
+ //
1149
+ // Activation helpers
1150
+ //
1151
+ _activateEvent(key, params, fiber) {
1152
+ return Effect3.gen(this, function* () {
1153
+ yield* this._trackFiber(this._inFlightFibers, fiber);
1154
+ log3("activating", {
1155
+ key,
1156
+ ...params
1157
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 993, S: this });
1158
+ yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));
1159
+ this._clearPendingReset(key);
1160
+ const activatingEvents = yield* this._activatingEvents;
1161
+ const activatingModules = yield* this._activatingModules;
1162
+ const modules = this._getModulesForActivation(key, activatingEvents, activatingModules);
1163
+ if (modules.length === 0) {
1164
+ log3("no modules to activate", {
1165
+ key
1166
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1003, S: this });
1167
+ if (!this._get(this._eventsFiredAtom).includes(key)) {
1168
+ this._update(this._eventsFiredAtom, (events) => [
1169
+ ...events,
1170
+ key
1171
+ ]);
1172
+ }
1173
+ return false;
1174
+ }
1175
+ return yield* this._activateModulesForEvent(key, modules, activatingEvents);
1176
+ }).pipe(Effect3.ensuring(Effect3.all([
1177
+ this._untrackFiber(this._inFlightFibers, fiber),
1178
+ Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event) => event !== key))
1179
+ ])));
1180
+ }
1181
+ _activateModulesForEvent(key, modules, activatingEvents) {
1182
+ const activatingModuleIds = modules.map((module) => module.id);
1183
+ return Effect3.gen(this, function* () {
1184
+ yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, activatingModuleIds));
1185
+ log3("activating modules", {
1186
+ key,
1187
+ modules: activatingModuleIds
1188
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1024, S: this });
1189
+ performance.mark(`event:${key}:start`);
1190
+ yield* PubSub.publish(this.activation, {
1191
+ event: key,
1192
+ state: "activating"
1193
+ });
1194
+ yield* this._activateRelatedEvents(key, this._getBeforeEvents(modules, activatingEvents), "before");
1195
+ const capabilities = yield* this._loadCapabilitiesForModules(key, modules);
1196
+ yield* this._contributeCapabilitiesForModules(modules, capabilities);
1197
+ yield* this._activateRelatedEvents(key, this._getAfterEvents(modules, activatingEvents), "after");
1198
+ if (!this._get(this._eventsFiredAtom).includes(key)) {
1199
+ this._update(this._eventsFiredAtom, (events) => [
1200
+ ...events,
1201
+ key
1202
+ ]);
1203
+ }
1204
+ performance.mark(`event:${key}:end`);
1205
+ performance.measure(`event:${key}`, `event:${key}:start`, `event:${key}:end`);
1206
+ yield* PubSub.publish(this.activation, {
1207
+ event: key,
1208
+ state: "activated"
1209
+ });
1210
+ log3("activated", {
1211
+ key
1212
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1049, S: this });
1213
+ return true;
1214
+ }).pipe(Effect3.ensuring(Ref.update(this._activatingModules, (activating) => Array.filter(activating, (module) => !activatingModuleIds.includes(module)))));
1215
+ }
1216
+ _getModulesForActivation(key, activatingEvents, activatingModules) {
1217
+ return this._getInactiveModulesByEvent(key).filter((module) => {
1218
+ const allOf = isAllOf(module.activatesOn);
1219
+ if (!allOf) {
1220
+ return true;
1221
+ }
1222
+ const events = getEvents(module.activatesOn).filter((event) => eventKey(event) !== key);
1223
+ return events.every((event) => this._get(this._eventsFiredAtom).includes(eventKey(event)) || activatingEvents.includes(eventKey(event))) && !activatingModules.includes(module.id);
1224
+ });
1225
+ }
1226
+ _getBeforeEvents(modules, activatingEvents) {
1227
+ return Function.pipe(modules, Array.flatMap((module) => module.firesBeforeActivation ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event) => !activatingEvents.includes(eventKey(event))));
1228
+ }
1229
+ _getAfterEvents(modules, activatingEvents) {
1230
+ return Function.pipe(modules, Array.flatMap((module) => module.firesAfterActivation ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event) => !activatingEvents.includes(eventKey(event))));
1231
+ }
1232
+ _activateRelatedEvents(key, events, phase) {
1233
+ const logLabel = phase === "before" ? "firesBeforeActivation" : "firesAfterActivation";
1234
+ const eventKey2 = phase === "before" ? "beforeEvents" : "afterEvents";
1235
+ return Function.pipe(events, Array.map((event) => this.activate(event, phase === "before" ? {
1236
+ before: key
1237
+ } : {
1238
+ after: key
1239
+ })), Effect3.allWith({
1240
+ concurrency: "unbounded"
1241
+ }), together(Effect3.sleep(Duration.seconds(10)).pipe(Effect3.andThen(Effect3.sync(() => log3.warn(`${logLabel} is taking a long time`, {
1242
+ event: key,
1243
+ [eventKey2]: events.map(eventKey)
1244
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1082, S: this }))))), Effect3.asVoid);
1245
+ }
1246
+ //
1247
+ // Module lifecycle helpers
1248
+ //
1249
+ _loadCapabilitiesForModules(key, modules) {
1250
+ return Function.pipe(modules, Array.map((mod) => this._loadModule(mod, key)), Effect3.allWith({
1251
+ concurrency: "unbounded"
1252
+ }), Effect3.catchAll((error) => {
1253
+ return Effect3.gen(this, function* () {
1254
+ yield* PubSub.publish(this.activation, {
1255
+ event: key,
1256
+ state: "error",
1257
+ error
1258
+ });
1259
+ return yield* Effect3.fail(error);
1260
+ });
1261
+ }));
1262
+ }
1263
+ _contributeCapabilitiesForModules(modules, capabilities) {
1264
+ return Function.pipe(
1265
+ modules,
1266
+ Array.zip(capabilities),
1267
+ Array.map(([module, capabilitySet]) => this._contributeCapabilities(module, capabilitySet)),
1268
+ Effect3.all,
1269
+ Effect3.asVoid
1270
+ );
1271
+ }
1272
+ _getModuleSemaphore(moduleId) {
1273
+ let semaphore = this._moduleSemaphores.get(moduleId);
1274
+ if (!semaphore) {
1275
+ semaphore = Effect3.runSync(Effect3.makeSemaphore(1));
1276
+ this._moduleSemaphores.set(moduleId, semaphore);
1277
+ }
1278
+ return semaphore;
1279
+ }
1280
+ // `parentEvent` is the activation event that first triggered this module
1281
+ // load — included in `activating`/`activated` PubSub messages so subscribers
1282
+ // (e.g. the boot loader's status listener) can associate a module with its
1283
+ // triggering event in the trace. The same module may be referenced by
1284
+ // multiple events, but module loads are memoized via `_moduleMemoMap`, so
1285
+ // only the first event to need it will appear here; later events await the
1286
+ // cached deferred without re-publishing.
1287
+ _loadModule = (module, parentEvent) => Effect3.gen(this, function* () {
1288
+ const semaphore = this._getModuleSemaphore(module.id);
1289
+ const deferredToAwait = yield* Effect3.gen(this, function* () {
1290
+ const existing = this._moduleMemoMap.get(module.id);
1291
+ if (existing) {
1292
+ return existing;
1293
+ }
1294
+ const deferred = yield* Deferred2.make();
1295
+ this._moduleMemoMap.set(module.id, deferred);
1296
+ const loadEffect = Effect3.gen(this, function* () {
1297
+ log3("loading module", {
1298
+ module: module.id,
1299
+ parentEvent
1300
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1140, S: this });
1301
+ performance.mark(`module:${module.id}:start`);
1302
+ yield* PubSub.publish(this.activation, {
1303
+ event: parentEvent,
1304
+ state: "activating",
1305
+ module: module.id
1306
+ });
1307
+ const pluginId = this._getPluginIdForModule(module.id);
1308
+ const [duration, capabilities] = yield* module.activate().pipe(
1309
+ Effect3.provideService(Service, this.capabilities),
1310
+ Effect3.provideService(Service2, this),
1311
+ // Cap activation so a single misbehaving module can't hold the
1312
+ // event chain open. On timeout the failure is recorded against
1313
+ // the plugin and surfaced as `PluginTimeoutError`.
1314
+ Effect3.timeoutFail({
1315
+ duration: this._activationTimeout,
1316
+ onTimeout: () => new PluginTimeoutError({
1317
+ context: {
1318
+ id: pluginId ?? module.id,
1319
+ module: module.id,
1320
+ phase: "activation"
1321
+ }
1322
+ })
1323
+ }),
1324
+ Effect3.timed
1325
+ );
1326
+ const normalized = capabilities == null ? [] : Array.isArray(capabilities) ? capabilities : [
1327
+ capabilities
1328
+ ];
1329
+ const elapsed = Duration.toMillis(duration);
1330
+ performance.mark(`module:${module.id}:end`);
1331
+ performance.measure(`module:${module.id}`, `module:${module.id}:start`, `module:${module.id}:end`);
1332
+ yield* PubSub.publish(this.activation, {
1333
+ event: parentEvent,
1334
+ state: "activated",
1335
+ module: module.id
1336
+ });
1337
+ log3("loaded module", {
1338
+ module: module.id,
1339
+ parentEvent,
1340
+ elapsed,
1341
+ failed: false
1342
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1175, S: this });
1343
+ return normalized;
1344
+ }).pipe(Effect3.withSpan("PluginManager._loadModule"), together(Effect3.sleep(Duration.seconds(10)).pipe(Effect3.andThen(Effect3.sync(() => log3.warn(`module is taking a long time to activate`, {
1345
+ module: module.id
1346
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1182, S: this }))))), Performance.addTrackEntry({
1347
+ name: module.id,
1348
+ devtools: {
1349
+ dataType: "track-entry",
1350
+ track: "Module Activation",
1351
+ trackGroup: "Composer",
1352
+ color: "primary"
1353
+ }
1354
+ }));
1355
+ const fiber = yield* Effect3.forkDaemon(loadEffect.pipe(Effect3.tap((result) => Deferred2.succeed(deferred, result)), Effect3.catchAllCause((cause) => {
1356
+ const error = Cause.squash(cause);
1357
+ log3.error("module failed to activate", {
1358
+ module: module.id,
1359
+ error: error instanceof Error ? error.message : String(error),
1360
+ stack: error instanceof Error ? error.stack : void 0,
1361
+ isDefect: !Cause.isFailure(cause)
1362
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1196, S: this });
1363
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
1364
+ const pluginId = this._getPluginIdForModule(module.id);
1365
+ if (pluginId !== void 0) {
1366
+ this._recordFailure(pluginId, "activation", normalizedError);
1367
+ this._scheduleAutoDisable(pluginId);
1368
+ }
1369
+ return Deferred2.fail(deferred, normalizedError);
1370
+ })));
1371
+ yield* this._trackFiber(this._inFlightFibers, fiber);
1372
+ yield* Effect3.forkDaemon(Fiber.await(fiber).pipe(Effect3.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))));
1373
+ return deferred;
1374
+ }).pipe(semaphore.withPermits(1));
1375
+ return yield* Deferred2.await(deferredToAwait);
1376
+ });
1377
+ _contributeCapabilities(module, capabilities) {
1378
+ return Effect3.gen(this, function* () {
1379
+ capabilities.forEach((capability) => {
1380
+ this.capabilities.contribute({
1381
+ module: module.id,
1382
+ ...capability
1383
+ });
1384
+ });
1385
+ this._update(this._activeAtom, (active) => [
1386
+ ...active,
1387
+ module.id
1388
+ ]);
1389
+ this._capabilities.set(module.id, capabilities);
1390
+ });
1391
+ }
1392
+ _deactivateModule(module) {
1393
+ return Effect3.gen(this, function* () {
1394
+ const id = module.id;
1395
+ log3("deactivating", {
1396
+ id
1397
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1235, S: this });
1398
+ this._moduleMemoMap.delete(id);
1399
+ const capabilities = this._capabilities.get(id);
1400
+ if (capabilities) {
1401
+ for (const capability of capabilities) {
1402
+ this.capabilities.remove(capability.interface, capability.implementation);
1403
+ const program = capability.deactivate?.() ?? Effect3.succeed(void 0);
1404
+ yield* program;
1405
+ }
1406
+ this._capabilities.delete(id);
1407
+ }
1408
+ const activeIndex = this._get(this._activeAtom).findIndex((event) => event === id);
1409
+ if (activeIndex !== -1) {
1410
+ this._update(this._activeAtom, (active) => active.filter((event) => event !== id));
1411
+ }
1412
+ log3("deactivated", {
1413
+ id
1414
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 1252, S: this });
1415
+ return true;
1416
+ });
1417
+ }
1418
+ };
1419
+ var make5 = (options) => new ManagerImpl(options);
1420
+ var isTimeoutCause = (error, depth = 0) => {
1421
+ if (depth > 5 || !(error instanceof Error)) {
1422
+ return false;
1423
+ }
1424
+ if (PluginTimeoutError.is(error)) {
1425
+ return true;
1426
+ }
1427
+ return isTimeoutCause(error.cause, depth + 1);
1428
+ };
1429
+ var together = (togetherEffect) => (effect) => Effect3.gen(function* () {
1430
+ const togetherFiber = yield* Effect3.fork(togetherEffect);
1431
+ const result = yield* effect;
1432
+ yield* Fiber.interrupt(togetherFiber);
1433
+ return result;
1434
+ });
1435
+
1436
+ export {
1437
+ capability_manager_exports,
1438
+ registry_exports,
1439
+ PluginInitializationError,
1440
+ PluginTimeoutError,
1441
+ ManagerTypeId,
1442
+ isManager,
1443
+ make5 as make,
1444
+ plugin_manager_exports
1445
+ };
1446
+ //# sourceMappingURL=chunk-VJ5PFAWC.mjs.map