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