@dxos/app-framework 0.8.4-main.b97322e → 0.8.4-main.bc2380dfbc

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