@dxos/app-framework 0.8.4-main.fffef41 → 0.9.0

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