@dxos/app-framework 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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 (577) hide show
  1. package/.storybook/main.mts +9 -0
  2. package/.storybook/preview.mts +8 -0
  3. package/dist/lib/browser/capability-5RRH3WIB.mjs +35 -0
  4. package/dist/lib/browser/capability-5RRH3WIB.mjs.map +7 -0
  5. package/dist/lib/browser/capability-LUKGKUQH.mjs +38 -0
  6. package/dist/lib/browser/capability-LUKGKUQH.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-23D4SJUE.mjs +42 -0
  8. package/dist/lib/browser/chunk-23D4SJUE.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-3JWJXGLK.mjs +79 -0
  10. package/dist/lib/browser/chunk-3JWJXGLK.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-45CHLTBV.mjs +34 -0
  12. package/dist/lib/browser/chunk-45CHLTBV.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-66IXTIVK.mjs +48 -0
  14. package/dist/lib/browser/chunk-66IXTIVK.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-7VZJR2OA.mjs +581 -0
  16. package/dist/lib/browser/chunk-7VZJR2OA.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-CZ4BIAHH.mjs +422 -0
  18. package/dist/lib/browser/chunk-CZ4BIAHH.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-FJ4765WW.mjs +8 -0
  20. package/dist/lib/browser/chunk-FJ4765WW.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-FO3IYSLV.mjs +68 -0
  22. package/dist/lib/browser/chunk-FO3IYSLV.mjs.map +7 -0
  23. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  24. package/dist/lib/browser/chunk-JD3Z5NEF.mjs +469 -0
  25. package/dist/lib/browser/chunk-JD3Z5NEF.mjs.map +7 -0
  26. package/dist/lib/browser/chunk-NBXPP7JR.mjs +1174 -0
  27. package/dist/lib/browser/chunk-NBXPP7JR.mjs.map +7 -0
  28. package/dist/lib/browser/chunk-WBHCSOBW.mjs +80 -0
  29. package/dist/lib/browser/chunk-WBHCSOBW.mjs.map +7 -0
  30. package/dist/lib/browser/chunk-Z55LVAGN.mjs +213 -0
  31. package/dist/lib/browser/chunk-Z55LVAGN.mjs.map +7 -0
  32. package/dist/lib/browser/chunk-ZGJAZSNE.mjs +142 -0
  33. package/dist/lib/browser/chunk-ZGJAZSNE.mjs.map +7 -0
  34. package/dist/lib/browser/cli/index.mjs +76 -0
  35. package/dist/lib/browser/cli/index.mjs.map +7 -0
  36. package/dist/lib/browser/common/activation-events.mjs +24 -0
  37. package/dist/lib/browser/common/capabilities.mjs +46 -0
  38. package/dist/lib/browser/core/activation-event.mjs +20 -0
  39. package/dist/lib/browser/core/capability.mjs +30 -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 +37 -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 +108 -162
  48. package/dist/lib/browser/index.mjs.map +4 -4
  49. package/dist/lib/browser/invoker-capability-K4GHUFXF.mjs +44 -0
  50. package/dist/lib/browser/invoker-capability-K4GHUFXF.mjs.map +7 -0
  51. package/dist/lib/browser/meta.json +1 -1
  52. package/dist/lib/browser/testing/index.mjs +235 -48
  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 +48 -0
  57. package/dist/lib/browser/ui/index.mjs.map +7 -0
  58. package/dist/lib/node-esm/capability-FCGZVIEG.mjs +39 -0
  59. package/dist/lib/node-esm/capability-FCGZVIEG.mjs.map +7 -0
  60. package/dist/lib/node-esm/capability-JOIQ2MQE.mjs +36 -0
  61. package/dist/lib/node-esm/capability-JOIQ2MQE.mjs.map +7 -0
  62. package/dist/lib/node-esm/chunk-37Z53PXZ.mjs +10 -0
  63. package/dist/lib/node-esm/chunk-37Z53PXZ.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-6XW6LET6.mjs +35 -0
  65. package/dist/lib/node-esm/chunk-6XW6LET6.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-D347W3KO.mjs +143 -0
  67. package/dist/lib/node-esm/chunk-D347W3KO.mjs.map +7 -0
  68. package/dist/lib/node-esm/chunk-DRZKO5UZ.mjs +470 -0
  69. package/dist/lib/node-esm/chunk-DRZKO5UZ.mjs.map +7 -0
  70. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  71. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  72. package/dist/lib/node-esm/chunk-HTBJU5FX.mjs +214 -0
  73. package/dist/lib/node-esm/chunk-HTBJU5FX.mjs.map +7 -0
  74. package/dist/lib/node-esm/chunk-M3HKPRPO.mjs +423 -0
  75. package/dist/lib/node-esm/chunk-M3HKPRPO.mjs.map +7 -0
  76. package/dist/lib/node-esm/chunk-MUVUQC3G.mjs +1175 -0
  77. package/dist/lib/node-esm/chunk-MUVUQC3G.mjs.map +7 -0
  78. package/dist/lib/node-esm/chunk-SBS2YMPT.mjs +43 -0
  79. package/dist/lib/node-esm/chunk-SBS2YMPT.mjs.map +7 -0
  80. package/dist/lib/node-esm/chunk-SDJ4B2LU.mjs +80 -0
  81. package/dist/lib/node-esm/chunk-SDJ4B2LU.mjs.map +7 -0
  82. package/dist/lib/node-esm/chunk-V24UWT36.mjs +582 -0
  83. package/dist/lib/node-esm/chunk-V24UWT36.mjs.map +7 -0
  84. package/dist/lib/node-esm/chunk-WFSRZKBP.mjs +81 -0
  85. package/dist/lib/node-esm/chunk-WFSRZKBP.mjs.map +7 -0
  86. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs +70 -0
  87. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs.map +7 -0
  88. package/dist/lib/node-esm/chunk-XOCUANHO.mjs +49 -0
  89. package/dist/lib/node-esm/chunk-XOCUANHO.mjs.map +7 -0
  90. package/dist/lib/node-esm/cli/index.mjs +77 -0
  91. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  92. package/dist/lib/node-esm/common/activation-events.mjs +25 -0
  93. package/dist/lib/node-esm/common/activation-events.mjs.map +7 -0
  94. package/dist/lib/node-esm/common/capabilities.mjs +47 -0
  95. package/dist/lib/node-esm/common/capabilities.mjs.map +7 -0
  96. package/dist/lib/node-esm/core/activation-event.mjs +21 -0
  97. package/dist/lib/node-esm/core/activation-event.mjs.map +7 -0
  98. package/dist/lib/node-esm/core/capability.mjs +31 -0
  99. package/dist/lib/node-esm/core/capability.mjs.map +7 -0
  100. package/dist/lib/node-esm/core/plugin-manager.mjs +20 -0
  101. package/dist/lib/node-esm/core/plugin-manager.mjs.map +7 -0
  102. package/dist/lib/node-esm/core/plugin.mjs +38 -0
  103. package/dist/lib/node-esm/core/plugin.mjs.map +7 -0
  104. package/dist/lib/node-esm/core/url-loader.mjs +25 -0
  105. package/dist/lib/node-esm/core/url-loader.mjs.map +7 -0
  106. package/dist/lib/node-esm/index.mjs +108 -162
  107. package/dist/lib/node-esm/index.mjs.map +4 -4
  108. package/dist/lib/node-esm/invoker-capability-XEPW5LMJ.mjs +45 -0
  109. package/dist/lib/node-esm/invoker-capability-XEPW5LMJ.mjs.map +7 -0
  110. package/dist/lib/node-esm/meta.json +1 -1
  111. package/dist/lib/node-esm/testing/index.mjs +235 -48
  112. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  113. package/dist/lib/node-esm/testing/react.mjs +79 -0
  114. package/dist/lib/node-esm/testing/react.mjs.map +7 -0
  115. package/dist/lib/node-esm/ui/index.mjs +49 -0
  116. package/dist/lib/node-esm/ui/index.mjs.map +7 -0
  117. package/dist/plugin/node-esm/index.mjs +893 -0
  118. package/dist/plugin/node-esm/index.mjs.map +7 -0
  119. package/dist/plugin/node-esm/meta.json +1 -0
  120. package/dist/types/src/cli/cli.d.ts +39 -0
  121. package/dist/types/src/cli/cli.d.ts.map +1 -0
  122. package/dist/types/src/cli/index.d.ts +2 -0
  123. package/dist/types/src/cli/index.d.ts.map +1 -0
  124. package/dist/types/src/common/activation-events.d.ts +27 -0
  125. package/dist/types/src/common/activation-events.d.ts.map +1 -0
  126. package/dist/types/src/common/annotations.d.ts +1 -0
  127. package/dist/types/src/common/annotations.d.ts.map +1 -0
  128. package/dist/types/src/common/capabilities.d.ts +110 -190
  129. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  130. package/dist/types/src/common/index.d.ts +4 -8
  131. package/dist/types/src/common/index.d.ts.map +1 -1
  132. package/dist/types/src/common/operations.d.ts +19 -0
  133. package/dist/types/src/common/operations.d.ts.map +1 -0
  134. package/dist/types/src/common/translations.d.ts +8 -8
  135. package/dist/types/src/common/translations.d.ts.map +1 -1
  136. package/dist/types/src/context.d.ts +5 -0
  137. package/dist/types/src/context.d.ts.map +1 -0
  138. package/dist/types/src/core/{events.d.ts → activation-event.d.ts} +11 -11
  139. package/dist/types/src/core/activation-event.d.ts.map +1 -0
  140. package/dist/types/src/core/capability-manager.d.ts +48 -0
  141. package/dist/types/src/core/capability-manager.d.ts.map +1 -0
  142. package/dist/types/src/core/capability-manager.test.d.ts +2 -0
  143. package/dist/types/src/core/capability-manager.test.d.ts.map +1 -0
  144. package/dist/types/src/core/capability.d.ts +156 -0
  145. package/dist/types/src/core/capability.d.ts.map +1 -0
  146. package/dist/types/src/core/edge-registry-plugin-provider.d.ts +30 -0
  147. package/dist/types/src/core/edge-registry-plugin-provider.d.ts.map +1 -0
  148. package/dist/types/src/core/index.d.ts +11 -4
  149. package/dist/types/src/core/index.d.ts.map +1 -1
  150. package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
  151. package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
  152. package/dist/types/src/core/plugin-manager.d.ts +239 -0
  153. package/dist/types/src/core/plugin-manager.d.ts.map +1 -0
  154. package/dist/types/src/core/plugin-manager.test.d.ts +2 -0
  155. package/dist/types/src/core/plugin-manager.test.d.ts.map +1 -0
  156. package/dist/types/src/core/plugin-manifest.d.ts +101 -0
  157. package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
  158. package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
  159. package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
  160. package/dist/types/src/core/plugin.d.ts +208 -37
  161. package/dist/types/src/core/plugin.d.ts.map +1 -1
  162. package/dist/types/src/core/registry.d.ts +101 -0
  163. package/dist/types/src/core/registry.d.ts.map +1 -0
  164. package/dist/types/src/core/url-loader.d.ts +127 -0
  165. package/dist/types/src/core/url-loader.d.ts.map +1 -0
  166. package/dist/types/src/core/url-loader.test.d.ts +2 -0
  167. package/dist/types/src/core/url-loader.test.d.ts.map +1 -0
  168. package/dist/types/src/helpers.d.ts.map +1 -1
  169. package/dist/types/src/index.d.ts +3 -4
  170. package/dist/types/src/index.d.ts.map +1 -1
  171. package/dist/types/src/plugin-operation/OperationPlugin.d.ts +3 -0
  172. package/dist/types/src/plugin-operation/OperationPlugin.d.ts.map +1 -0
  173. package/dist/types/src/plugin-operation/history/capability.d.ts +7 -0
  174. package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -0
  175. package/dist/types/src/plugin-operation/history/errors.d.ts +32 -0
  176. package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -0
  177. package/dist/types/src/plugin-operation/history/history-tracker.d.ts +18 -0
  178. package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -0
  179. package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts +2 -0
  180. package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts.map +1 -0
  181. package/dist/types/src/plugin-operation/history/index.d.ts +6 -0
  182. package/dist/types/src/plugin-operation/history/index.d.ts.map +1 -0
  183. package/dist/types/src/plugin-operation/history/types.d.ts +13 -0
  184. package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -0
  185. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +101 -0
  186. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -0
  187. package/dist/types/src/plugin-operation/history/undo-registry.d.ts +23 -0
  188. package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -0
  189. package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts +2 -0
  190. package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts.map +1 -0
  191. package/dist/types/src/plugin-operation/index.d.ts +3 -0
  192. package/dist/types/src/plugin-operation/index.d.ts.map +1 -0
  193. package/dist/types/src/plugin-operation/invoker-capability.d.ts +6 -0
  194. package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -0
  195. package/dist/types/src/plugin-operation/meta.d.ts +3 -0
  196. package/dist/types/src/plugin-operation/meta.d.ts.map +1 -0
  197. package/dist/types/src/plugin-operation/testing.d.ts +59 -0
  198. package/dist/types/src/plugin-operation/testing.d.ts.map +1 -0
  199. package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts +3 -0
  200. package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts.map +1 -0
  201. package/dist/types/src/plugin-runtime/capability.d.ts +6 -0
  202. package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -0
  203. package/dist/types/src/plugin-runtime/index.d.ts +2 -0
  204. package/dist/types/src/plugin-runtime/index.d.ts.map +1 -0
  205. package/dist/types/src/plugin-runtime/meta.d.ts +3 -0
  206. package/dist/types/src/plugin-runtime/meta.d.ts.map +1 -0
  207. package/dist/types/src/testing/harness.d.ts +67 -0
  208. package/dist/types/src/testing/harness.d.ts.map +1 -0
  209. package/dist/types/src/testing/index.d.ts +2 -0
  210. package/dist/types/src/testing/index.d.ts.map +1 -1
  211. package/dist/types/src/testing/react.d.ts +27 -0
  212. package/dist/types/src/testing/react.d.ts.map +1 -0
  213. package/dist/types/src/testing/react.test.d.ts +2 -0
  214. package/dist/types/src/testing/react.test.d.ts.map +1 -0
  215. package/dist/types/src/testing/service.d.ts +8 -0
  216. package/dist/types/src/testing/service.d.ts.map +1 -0
  217. package/dist/types/src/testing/withPluginManager.d.ts +8 -9
  218. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  219. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  220. package/dist/types/src/ui/components/App/App.d.ts +9 -0
  221. package/dist/types/src/ui/components/App/App.d.ts.map +1 -0
  222. package/dist/types/src/ui/components/App/App.stories.d.ts +19 -0
  223. package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -0
  224. package/dist/types/src/ui/components/App/index.d.ts +2 -0
  225. package/dist/types/src/ui/components/App/index.d.ts.map +1 -0
  226. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
  227. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
  228. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
  229. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
  230. package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
  231. package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
  232. package/dist/types/src/{playground/playground.stories.d.ts → ui/components/PluginManager/PluginManagerContext.stories.d.ts} +5 -4
  233. package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -0
  234. package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts +10 -0
  235. package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts.map +1 -0
  236. package/dist/types/src/ui/components/PluginManager/index.d.ts +2 -0
  237. package/dist/types/src/ui/components/PluginManager/index.d.ts.map +1 -0
  238. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts +24 -0
  239. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts.map +1 -0
  240. package/dist/types/src/{components/App.stories.d.ts → ui/components/Surface/SurfaceComponent.stories.d.ts} +1 -2
  241. package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -0
  242. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts +11 -0
  243. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts.map +1 -0
  244. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts +48 -0
  245. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -0
  246. package/dist/types/src/ui/components/Surface/context.d.ts +5 -0
  247. package/dist/types/src/ui/components/Surface/context.d.ts.map +1 -0
  248. package/dist/types/src/ui/components/Surface/index.d.ts +36 -0
  249. package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -0
  250. package/dist/types/src/ui/components/Surface/types.d.ts +197 -0
  251. package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -0
  252. package/dist/types/src/ui/components/Surface/types.test.d.ts +2 -0
  253. package/dist/types/src/ui/components/Surface/types.test.d.ts.map +1 -0
  254. package/dist/types/src/ui/components/index.d.ts +5 -0
  255. package/dist/types/src/ui/components/index.d.ts.map +1 -0
  256. package/dist/types/src/ui/hooks/index.d.ts +6 -0
  257. package/dist/types/src/ui/hooks/index.d.ts.map +1 -0
  258. package/dist/types/src/ui/hooks/useApp.d.ts +89 -0
  259. package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -0
  260. package/dist/types/src/ui/hooks/useApp.test.d.ts +2 -0
  261. package/dist/types/src/ui/hooks/useApp.test.d.ts.map +1 -0
  262. package/dist/types/src/ui/hooks/useCapabilities.d.ts +31 -0
  263. package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -0
  264. package/dist/types/src/{components → ui/hooks}/useLoading.d.ts +1 -2
  265. package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -0
  266. package/dist/types/src/ui/hooks/useSettingsState.d.ts +10 -0
  267. package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -0
  268. package/dist/types/src/ui/hooks/useSurface.d.ts +3 -0
  269. package/dist/types/src/ui/hooks/useSurface.d.ts.map +1 -0
  270. package/dist/types/src/ui/index.d.ts +3 -0
  271. package/dist/types/src/ui/index.d.ts.map +1 -0
  272. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +34 -0
  273. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -0
  274. package/dist/types/src/vite-plugin/boot-loader/index.d.ts +2 -0
  275. package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -0
  276. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts +51 -0
  277. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts.map +1 -0
  278. package/dist/types/src/vite-plugin/composer/index.d.ts +34 -0
  279. package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -0
  280. package/dist/types/src/vite-plugin/import-map/index.d.ts +28 -0
  281. package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -0
  282. package/dist/types/src/vite-plugin/index.d.ts +5 -0
  283. package/dist/types/src/vite-plugin/index.d.ts.map +1 -0
  284. package/dist/types/src/vite-plugin/manifest.d.ts +41 -0
  285. package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -0
  286. package/dist/types/src/vite-plugin/manifest.test.d.ts +2 -0
  287. package/dist/types/src/vite-plugin/manifest.test.d.ts.map +1 -0
  288. package/dist/types/src/vite-plugin/packages.d.ts +13 -0
  289. package/dist/types/src/vite-plugin/packages.d.ts.map +1 -0
  290. package/dist/types/tsconfig.tsbuildinfo +1 -1
  291. package/moon.yml +26 -3
  292. package/package.json +114 -54
  293. package/src/cli/cli.ts +107 -0
  294. package/src/{playground/logger → cli}/index.ts +1 -1
  295. package/src/common/activation-events.ts +44 -0
  296. package/src/{components/index.ts → common/annotations.ts} +0 -2
  297. package/src/common/capabilities.ts +169 -195
  298. package/src/common/index.ts +4 -8
  299. package/src/common/operations.ts +35 -0
  300. package/src/common/translations.ts +18 -10
  301. package/src/context.ts +9 -0
  302. package/src/core/{events.ts → activation-event.ts} +10 -7
  303. package/src/core/capability-manager.test.ts +151 -0
  304. package/src/core/capability-manager.ts +192 -0
  305. package/src/core/capability.ts +247 -0
  306. package/src/core/edge-registry-plugin-provider.ts +92 -0
  307. package/src/core/index.ts +11 -4
  308. package/src/core/plugin-asset-cache.ts +60 -0
  309. package/src/core/plugin-manager.test.ts +1671 -0
  310. package/src/core/plugin-manager.ts +1335 -0
  311. package/src/core/plugin-manifest.test.ts +75 -0
  312. package/src/core/plugin-manifest.ts +134 -0
  313. package/src/core/plugin.ts +369 -43
  314. package/src/core/registry.ts +157 -0
  315. package/src/core/url-loader.test.ts +221 -0
  316. package/src/core/url-loader.ts +388 -0
  317. package/src/index.ts +3 -4
  318. package/src/plugin-operation/OperationPlugin.ts +24 -0
  319. package/src/plugin-operation/history/capability.ts +36 -0
  320. package/src/plugin-operation/history/errors.ts +7 -0
  321. package/src/plugin-operation/history/history-tracker.test.ts +374 -0
  322. package/src/plugin-operation/history/history-tracker.ts +128 -0
  323. package/src/plugin-operation/history/index.ts +9 -0
  324. package/src/plugin-operation/history/types.ts +17 -0
  325. package/src/plugin-operation/history/undo-mapping.ts +135 -0
  326. package/src/plugin-operation/history/undo-registry.test.ts +72 -0
  327. package/src/plugin-operation/history/undo-registry.ts +54 -0
  328. package/src/plugin-operation/index.ts +6 -0
  329. package/src/plugin-operation/invoker-capability.ts +55 -0
  330. package/src/plugin-operation/meta.ts +12 -0
  331. package/src/plugin-operation/testing.ts +155 -0
  332. package/src/plugin-runtime/RuntimePlugin.ts +19 -0
  333. package/src/plugin-runtime/capability.ts +53 -0
  334. package/src/plugin-runtime/index.ts +5 -0
  335. package/src/plugin-runtime/meta.ts +12 -0
  336. package/src/testing/harness.ts +229 -0
  337. package/src/testing/index.ts +2 -0
  338. package/src/testing/react.test.tsx +48 -0
  339. package/src/testing/react.tsx +113 -0
  340. package/src/testing/service.ts +52 -0
  341. package/src/testing/withPluginManager.stories.tsx +9 -10
  342. package/src/testing/withPluginManager.tsx +74 -50
  343. package/src/ui/components/App/App.stories.tsx +88 -0
  344. package/src/ui/components/App/App.tsx +81 -0
  345. package/src/{playground/layout → ui/components/App}/index.ts +1 -1
  346. package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
  347. package/src/ui/components/Placeholder/Placeholder.tsx +155 -0
  348. package/src/{playground/debug → ui/components/Placeholder}/index.ts +1 -1
  349. package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +185 -0
  350. package/src/{react → ui/components/PluginManager}/PluginManagerProvider.ts +3 -3
  351. package/src/ui/components/PluginManager/index.ts +5 -0
  352. package/src/ui/components/Surface/SurfaceComponent.stories.tsx +144 -0
  353. package/src/ui/components/Surface/SurfaceComponent.tsx +303 -0
  354. package/src/ui/components/Surface/SurfaceInfo.tsx +106 -0
  355. package/src/ui/components/Surface/SurfaceProfilerContext.tsx +207 -0
  356. package/src/ui/components/Surface/context.ts +12 -0
  357. package/src/ui/components/Surface/index.ts +54 -0
  358. package/src/ui/components/Surface/types.test.ts +126 -0
  359. package/src/ui/components/Surface/types.ts +269 -0
  360. package/src/ui/components/index.ts +8 -0
  361. package/src/ui/hooks/index.ts +9 -0
  362. package/src/ui/hooks/useApp.test.tsx +159 -0
  363. package/src/ui/hooks/useApp.tsx +424 -0
  364. package/src/ui/hooks/useCapabilities.ts +67 -0
  365. package/src/{components → ui/hooks}/useLoading.tsx +16 -10
  366. package/src/ui/hooks/useSettingsState.ts +26 -0
  367. package/src/ui/hooks/useSurface.ts +13 -0
  368. package/src/ui/index.ts +6 -0
  369. package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +270 -0
  370. package/src/vite-plugin/boot-loader/boot-loader.css +320 -0
  371. package/src/vite-plugin/boot-loader/boot-loader.js +325 -0
  372. package/src/vite-plugin/boot-loader/index.ts +5 -0
  373. package/src/vite-plugin/boot-loader/loader.ts +123 -0
  374. package/src/vite-plugin/composer/index.ts +306 -0
  375. package/src/vite-plugin/import-map/index.ts +527 -0
  376. package/src/vite-plugin/index.ts +10 -0
  377. package/src/vite-plugin/manifest.test.ts +46 -0
  378. package/src/vite-plugin/manifest.ts +57 -0
  379. package/src/vite-plugin/packages.ts +187 -0
  380. package/tsconfig.json +24 -15
  381. package/tsconfig.node.json +2 -4
  382. package/typedoc.json +2 -4
  383. package/vitest.config.ts +8 -6
  384. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  385. package/.swc/plugins/linux_x86_64_19.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429.wasmer-v7 +0 -0
  386. package/dist/lib/browser/app-graph-builder-AFFC6VB2.mjs +0 -137
  387. package/dist/lib/browser/app-graph-builder-AFFC6VB2.mjs.map +0 -7
  388. package/dist/lib/browser/chunk-ORWHM7CO.mjs +0 -32
  389. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  390. package/dist/lib/browser/chunk-OZY7HV2A.mjs +0 -1643
  391. package/dist/lib/browser/chunk-OZY7HV2A.mjs.map +0 -7
  392. package/dist/lib/browser/chunk-T6M7JB7M.mjs +0 -471
  393. package/dist/lib/browser/chunk-T6M7JB7M.mjs.map +0 -7
  394. package/dist/lib/browser/intent-dispatcher-QG7UPGQX.mjs +0 -11
  395. package/dist/lib/browser/intent-resolver-4S4PSTM5.mjs +0 -39
  396. package/dist/lib/browser/intent-resolver-4S4PSTM5.mjs.map +0 -7
  397. package/dist/lib/browser/store-6E33KLGK.mjs +0 -30
  398. package/dist/lib/browser/store-6E33KLGK.mjs.map +0 -7
  399. package/dist/lib/browser/worker.mjs +0 -85
  400. package/dist/lib/node-esm/app-graph-builder-S4OAULX5.mjs +0 -138
  401. package/dist/lib/node-esm/app-graph-builder-S4OAULX5.mjs.map +0 -7
  402. package/dist/lib/node-esm/chunk-F63ZRXMK.mjs +0 -1645
  403. package/dist/lib/node-esm/chunk-F63ZRXMK.mjs.map +0 -7
  404. package/dist/lib/node-esm/chunk-HJFU7QOR.mjs +0 -472
  405. package/dist/lib/node-esm/chunk-HJFU7QOR.mjs.map +0 -7
  406. package/dist/lib/node-esm/chunk-UMZQERLE.mjs +0 -34
  407. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  408. package/dist/lib/node-esm/intent-dispatcher-NXBGPJOX.mjs +0 -12
  409. package/dist/lib/node-esm/intent-resolver-2ZKXI5ET.mjs +0 -40
  410. package/dist/lib/node-esm/intent-resolver-2ZKXI5ET.mjs.map +0 -7
  411. package/dist/lib/node-esm/store-QQUTQHHT.mjs +0 -31
  412. package/dist/lib/node-esm/store-QQUTQHHT.mjs.map +0 -7
  413. package/dist/lib/node-esm/worker.mjs +0 -86
  414. package/dist/types/src/common/collaboration.d.ts +0 -20
  415. package/dist/types/src/common/collaboration.d.ts.map +0 -1
  416. package/dist/types/src/common/events.d.ts +0 -52
  417. package/dist/types/src/common/events.d.ts.map +0 -1
  418. package/dist/types/src/common/file.d.ts +0 -14
  419. package/dist/types/src/common/file.d.ts.map +0 -1
  420. package/dist/types/src/common/graph.d.ts +0 -21
  421. package/dist/types/src/common/graph.d.ts.map +0 -1
  422. package/dist/types/src/common/layout.d.ts +0 -281
  423. package/dist/types/src/common/layout.d.ts.map +0 -1
  424. package/dist/types/src/common/surface.d.ts +0 -65
  425. package/dist/types/src/common/surface.d.ts.map +0 -1
  426. package/dist/types/src/components/App.d.ts +0 -10
  427. package/dist/types/src/components/App.d.ts.map +0 -1
  428. package/dist/types/src/components/App.stories.d.ts.map +0 -1
  429. package/dist/types/src/components/DefaultFallback.d.ts +0 -8
  430. package/dist/types/src/components/DefaultFallback.d.ts.map +0 -1
  431. package/dist/types/src/components/index.d.ts +0 -2
  432. package/dist/types/src/components/index.d.ts.map +0 -1
  433. package/dist/types/src/components/useApp.d.ts +0 -44
  434. package/dist/types/src/components/useApp.d.ts.map +0 -1
  435. package/dist/types/src/components/useLoading.d.ts.map +0 -1
  436. package/dist/types/src/core/capabilities.d.ts +0 -117
  437. package/dist/types/src/core/capabilities.d.ts.map +0 -1
  438. package/dist/types/src/core/capabilities.test.d.ts +0 -2
  439. package/dist/types/src/core/capabilities.test.d.ts.map +0 -1
  440. package/dist/types/src/core/events.d.ts.map +0 -1
  441. package/dist/types/src/core/manager.d.ts +0 -126
  442. package/dist/types/src/core/manager.d.ts.map +0 -1
  443. package/dist/types/src/core/manager.test.d.ts +0 -2
  444. package/dist/types/src/core/manager.test.d.ts.map +0 -1
  445. package/dist/types/src/playground/debug/Debug.d.ts +0 -6
  446. package/dist/types/src/playground/debug/Debug.d.ts.map +0 -1
  447. package/dist/types/src/playground/debug/index.d.ts +0 -2
  448. package/dist/types/src/playground/debug/index.d.ts.map +0 -1
  449. package/dist/types/src/playground/debug/plugin.d.ts +0 -2
  450. package/dist/types/src/playground/debug/plugin.d.ts.map +0 -1
  451. package/dist/types/src/playground/generator/Main.d.ts +0 -6
  452. package/dist/types/src/playground/generator/Main.d.ts.map +0 -1
  453. package/dist/types/src/playground/generator/Toolbar.d.ts +0 -6
  454. package/dist/types/src/playground/generator/Toolbar.d.ts.map +0 -1
  455. package/dist/types/src/playground/generator/generator.d.ts +0 -7
  456. package/dist/types/src/playground/generator/generator.d.ts.map +0 -1
  457. package/dist/types/src/playground/generator/index.d.ts +0 -3
  458. package/dist/types/src/playground/generator/index.d.ts.map +0 -1
  459. package/dist/types/src/playground/generator/plugin.d.ts +0 -2
  460. package/dist/types/src/playground/generator/plugin.d.ts.map +0 -1
  461. package/dist/types/src/playground/layout/Layout.d.ts +0 -8
  462. package/dist/types/src/playground/layout/Layout.d.ts.map +0 -1
  463. package/dist/types/src/playground/layout/index.d.ts +0 -2
  464. package/dist/types/src/playground/layout/index.d.ts.map +0 -1
  465. package/dist/types/src/playground/layout/plugin.d.ts +0 -2
  466. package/dist/types/src/playground/layout/plugin.d.ts.map +0 -1
  467. package/dist/types/src/playground/logger/Toolbar.d.ts +0 -6
  468. package/dist/types/src/playground/logger/Toolbar.d.ts.map +0 -1
  469. package/dist/types/src/playground/logger/index.d.ts +0 -2
  470. package/dist/types/src/playground/logger/index.d.ts.map +0 -1
  471. package/dist/types/src/playground/logger/plugin.d.ts +0 -2
  472. package/dist/types/src/playground/logger/plugin.d.ts.map +0 -1
  473. package/dist/types/src/playground/logger/schema.d.ts +0 -13
  474. package/dist/types/src/playground/logger/schema.d.ts.map +0 -1
  475. package/dist/types/src/playground/playground.stories.d.ts.map +0 -1
  476. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +0 -2
  477. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +0 -1
  478. package/dist/types/src/plugin-intent/actions.d.ts +0 -38
  479. package/dist/types/src/plugin-intent/actions.d.ts.map +0 -1
  480. package/dist/types/src/plugin-intent/errors.d.ts +0 -16
  481. package/dist/types/src/plugin-intent/errors.d.ts.map +0 -1
  482. package/dist/types/src/plugin-intent/index.d.ts +0 -6
  483. package/dist/types/src/plugin-intent/index.d.ts.map +0 -1
  484. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +0 -139
  485. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +0 -1
  486. package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts +0 -2
  487. package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +0 -1
  488. package/dist/types/src/plugin-intent/intent.d.ts +0 -63
  489. package/dist/types/src/plugin-intent/intent.d.ts.map +0 -1
  490. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +0 -2
  491. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +0 -1
  492. package/dist/types/src/plugin-settings/actions.d.ts +0 -27
  493. package/dist/types/src/plugin-settings/actions.d.ts.map +0 -1
  494. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +0 -4
  495. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +0 -1
  496. package/dist/types/src/plugin-settings/index.d.ts +0 -3
  497. package/dist/types/src/plugin-settings/index.d.ts.map +0 -1
  498. package/dist/types/src/plugin-settings/intent-resolver.d.ts +0 -4
  499. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +0 -1
  500. package/dist/types/src/plugin-settings/store.d.ts +0 -5
  501. package/dist/types/src/plugin-settings/store.d.ts.map +0 -1
  502. package/dist/types/src/plugin-settings/translations.d.ts +0 -10
  503. package/dist/types/src/plugin-settings/translations.d.ts.map +0 -1
  504. package/dist/types/src/react/ErrorBoundary.d.ts +0 -30
  505. package/dist/types/src/react/ErrorBoundary.d.ts.map +0 -1
  506. package/dist/types/src/react/IntentContext.d.ts +0 -8
  507. package/dist/types/src/react/IntentContext.d.ts.map +0 -1
  508. package/dist/types/src/react/PluginManagerProvider.d.ts +0 -10
  509. package/dist/types/src/react/PluginManagerProvider.d.ts.map +0 -1
  510. package/dist/types/src/react/Surface.d.ts +0 -12
  511. package/dist/types/src/react/Surface.d.ts.map +0 -1
  512. package/dist/types/src/react/Surface.stories.d.ts +0 -18
  513. package/dist/types/src/react/Surface.stories.d.ts.map +0 -1
  514. package/dist/types/src/react/common.d.ts +0 -13
  515. package/dist/types/src/react/common.d.ts.map +0 -1
  516. package/dist/types/src/react/index.d.ts +0 -7
  517. package/dist/types/src/react/index.d.ts.map +0 -1
  518. package/dist/types/src/react/useCapabilities.d.ts +0 -13
  519. package/dist/types/src/react/useCapabilities.d.ts.map +0 -1
  520. package/dist/types/src/react/useIntentResolver.d.ts +0 -3
  521. package/dist/types/src/react/useIntentResolver.d.ts.map +0 -1
  522. package/dist/types/src/worker.d.ts +0 -4
  523. package/dist/types/src/worker.d.ts.map +0 -1
  524. package/src/common/collaboration.ts +0 -18
  525. package/src/common/events.ts +0 -79
  526. package/src/common/file.ts +0 -22
  527. package/src/common/graph.ts +0 -30
  528. package/src/common/layout.ts +0 -278
  529. package/src/common/surface.ts +0 -86
  530. package/src/components/App.stories.tsx +0 -35
  531. package/src/components/App.tsx +0 -59
  532. package/src/components/DefaultFallback.tsx +0 -26
  533. package/src/components/useApp.tsx +0 -166
  534. package/src/core/capabilities.test.ts +0 -136
  535. package/src/core/capabilities.ts +0 -259
  536. package/src/core/manager.test.ts +0 -516
  537. package/src/core/manager.ts +0 -597
  538. package/src/playground/debug/Debug.tsx +0 -39
  539. package/src/playground/debug/plugin.ts +0 -17
  540. package/src/playground/generator/Main.tsx +0 -71
  541. package/src/playground/generator/Toolbar.tsx +0 -47
  542. package/src/playground/generator/generator.ts +0 -48
  543. package/src/playground/generator/index.ts +0 -6
  544. package/src/playground/generator/plugin.ts +0 -23
  545. package/src/playground/layout/Layout.tsx +0 -33
  546. package/src/playground/layout/plugin.ts +0 -17
  547. package/src/playground/logger/Toolbar.tsx +0 -30
  548. package/src/playground/logger/plugin.ts +0 -37
  549. package/src/playground/logger/schema.ts +0 -12
  550. package/src/playground/playground.stories.tsx +0 -47
  551. package/src/plugin-intent/IntentPlugin.ts +0 -21
  552. package/src/plugin-intent/actions.ts +0 -33
  553. package/src/plugin-intent/errors.ts +0 -39
  554. package/src/plugin-intent/index.ts +0 -9
  555. package/src/plugin-intent/intent-dispatcher.test.ts +0 -279
  556. package/src/plugin-intent/intent-dispatcher.ts +0 -335
  557. package/src/plugin-intent/intent.ts +0 -154
  558. package/src/plugin-settings/SettingsPlugin.ts +0 -36
  559. package/src/plugin-settings/actions.ts +0 -29
  560. package/src/plugin-settings/app-graph-builder.ts +0 -158
  561. package/src/plugin-settings/index.ts +0 -6
  562. package/src/plugin-settings/intent-resolver.ts +0 -35
  563. package/src/plugin-settings/store.ts +0 -33
  564. package/src/plugin-settings/translations.ts +0 -19
  565. package/src/react/ErrorBoundary.tsx +0 -54
  566. package/src/react/IntentContext.tsx +0 -35
  567. package/src/react/Surface.stories.tsx +0 -104
  568. package/src/react/Surface.tsx +0 -78
  569. package/src/react/common.ts +0 -13
  570. package/src/react/index.ts +0 -10
  571. package/src/react/useCapabilities.ts +0 -31
  572. package/src/react/useIntentResolver.ts +0 -22
  573. package/src/worker.ts +0 -11
  574. /package/dist/lib/{node-esm/worker.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
  575. /package/dist/lib/{node-esm/intent-dispatcher-NXBGPJOX.mjs.map → browser/common/activation-events.mjs.map} +0 -0
  576. /package/dist/lib/browser/{worker.mjs.map → common/capabilities.mjs.map} +0 -0
  577. /package/dist/lib/browser/{intent-dispatcher-QG7UPGQX.mjs.map → core/activation-event.mjs.map} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers.ts", "../../../src/ui/hooks/useSurface.ts", "../../../src/ui/components/PluginManager/PluginManagerProvider.ts", "../../../src/ui/components/Surface/context.ts", "../../../src/ui/components/Surface/SurfaceComponent.tsx", "../../../src/ui/components/Surface/SurfaceInfo.tsx", "../../../src/ui/components/Surface/SurfaceProfilerContext.tsx", "../../../src/ui/components/Surface/types.ts", "../../../src/ui/components/Surface/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\ntype DependencyNode = {\n id: string;\n dependsOn?: string[];\n};\n\n/**\n * Topologically sorts a list of nodes based on their dependencies.\n */\n// TODO(wittjosiah): Factor out?\nexport const topologicalSort = <T extends DependencyNode>(nodes: T[]): T[] => {\n const getDependencies = (nodeId: string, seen = new Set<string>(), path = new Set<string>()): string[] => {\n if (path.has(nodeId)) {\n throw new Error(`Circular dependency detected involving ${nodeId}`);\n }\n if (seen.has(nodeId)) {\n return [];\n }\n\n const node = nodes.find((n) => n.id === nodeId);\n if (!node) {\n throw new Error(`Node ${nodeId} not found but is listed as a dependency`);\n }\n\n const newPath = new Set([...path, nodeId]);\n const newSeen = new Set([...seen, nodeId]);\n\n const dependsOn = node.dependsOn ?? [];\n return [...dependsOn.flatMap((depId) => getDependencies(depId, newSeen, newPath)), nodeId];\n };\n\n // Get all unique dependencies.\n const allDependencies = nodes\n .map((node) => node.id)\n .flatMap((id) => getDependencies(id))\n .filter((id, index, self) => self.indexOf(id) === index);\n\n // Map back to original nodes\n return allDependencies\n .map((id) => nodes.find((node) => node.id === id))\n .filter((node): node is T => node !== undefined);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { Surface } from '../components';\n\nexport const useSurface = (): Surface.Context => {\n return useContext(Surface.Context) ?? raise(new Error('Missing SurfaceContext'));\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext, useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { type PluginManager } from '../../../core';\n\nconst PluginManagerContext = createContext<PluginManager.PluginManager | undefined>(undefined);\n\n/**\n * Get the plugin manager.\n */\nexport const usePluginManager = (): PluginManager.PluginManager =>\n useContext(PluginManagerContext) ?? raise(new Error('Missing PluginManagerContext'));\n\n/**\n * Context provider for a plugin manager.\n */\nexport const PluginManagerProvider = PluginManagerContext.Provider;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Props } from './types';\n\nexport type SurfaceContext = Pick<Props, 'id' | 'role' | 'data'>;\n\n// TODO(burdon): Use @radix-ui/react-context\nexport const SurfaceContext: Context<SurfaceContext | undefined> = createContext<SurfaceContext | undefined>(undefined);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useAtomValue } from '@effect-atom/atom-react';\nimport React, {\n Fragment,\n type NamedExoticComponent,\n Profiler,\n type RefAttributes,\n Suspense,\n forwardRef,\n memo,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { log } from '@dxos/log';\nimport { ErrorBoundary } from '@dxos/react-error-boundary';\nimport { useDefaultValue } from '@dxos/react-hooks';\nimport { byPosition } from '@dxos/util';\n\nimport { Capabilities } from '../../../common';\nimport { type CapabilityManager } from '../../../core';\nimport { usePluginManager } from '../PluginManager/PluginManagerProvider';\nimport { SurfaceContext } from './context';\nimport { SurfaceInfo } from './SurfaceInfo';\nimport { useSurfaceProfilerCallback } from './SurfaceProfilerContext';\nimport {\n type Definition,\n type Props,\n type RoleToken,\n type TokenData,\n type TypedProps,\n type WebComponentDefinition,\n} from './types';\n\nconst DEBUG = import.meta.env.VITE_DEBUG;\n\nconst DEFAULT_PLACEHOLDER = <Fragment />;\n\n/**\n * Wrapper component for rendering Web Component surfaces.\n * Handles creation, prop setting, and cleanup of Web Components.\n */\nconst WebComponentWrapper = memo(\n forwardRef<HTMLElement, Omit<Props, 'role'> & { role: string; definition: WebComponentDefinition }>(\n ({ id, role, data, limit, definition, ...rest }, forwardedRef) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const elementRef = useRef<HTMLElement | null>(null);\n const propsRef = useRef({ id, role, data, limit, ...rest });\n\n // Update props ref on every render\n propsRef.current = { id, role, data, limit, ...rest };\n\n // Create element only once\n useEffect(() => {\n if (!containerRef.current || elementRef.current) {\n return;\n }\n\n // Create the Web Component\n const element = document.createElement(definition.tagName);\n elementRef.current = element;\n\n // Set initial properties on the Web Component\n Object.assign(element, propsRef.current);\n\n // Append to container\n containerRef.current.appendChild(element);\n\n // Setup ref forwarding if provided\n if (typeof forwardedRef === 'function') {\n forwardedRef(element);\n } else if (forwardedRef) {\n forwardedRef.current = element;\n }\n\n // Cleanup on unmount to prevent memory leaks\n return () => {\n if (elementRef.current && containerRef.current?.contains(elementRef.current)) {\n containerRef.current.removeChild(elementRef.current);\n }\n if (typeof forwardedRef === 'function') {\n forwardedRef(null);\n } else if (forwardedRef) {\n forwardedRef.current = null;\n }\n elementRef.current = null;\n };\n }, [definition.tagName, forwardedRef]);\n\n // Update props on existing element without recreating it\n // This runs on every render to ensure all props (including those in `rest`) are kept up to date\n useEffect(() => {\n const element = elementRef.current;\n if (!element) {\n return;\n }\n\n // Update properties on the existing Web Component\n Object.assign(element, propsRef.current);\n });\n\n return <div ref={containerRef} />;\n },\n ),\n);\n\nWebComponentWrapper.displayName = 'WebComponentWrapper';\n\n/**\n * Wrapper component that provides context for a surface.\n */\n// TODO(burdon): Allow DebugPlugin to provide different fallback using react-ui ErrorFallback.\nconst SurfaceContextProvider = memo(\n forwardRef<HTMLElement, Omit<Props, 'role'> & { role: string; definition: Definition }>(\n ({ id, role, data, limit, fallback = ErrorFallback, definition, ...rest }, forwardedRef) => {\n const contextValue = useMemo(() => ({ id, role, data }), [id, role, data]);\n const onProfilerRender = useSurfaceProfilerCallback();\n const profilerId = `surface/${id}/${role}`;\n\n // Handle Web Component surfaces\n if (definition.kind === 'web-component') {\n return (\n <ErrorBoundary name='surface' resetKeys={[data]} FallbackComponent={fallback}>\n <SurfaceContext.Provider value={contextValue}>\n <WebComponentWrapper\n id={id}\n role={role}\n data={data}\n limit={limit}\n definition={definition}\n ref={forwardedRef}\n {...rest}\n />\n </SurfaceContext.Provider>\n </ErrorBoundary>\n );\n }\n\n // Handle React component surfaces\n const Component = definition.component;\n\n // TODO(burdon): Remove from production build?\n const debug = DEBUG || '__DX_DEBUG__' in window;\n if (debug) {\n return (\n <ErrorBoundary name='surface' resetKeys={[data]} FallbackComponent={fallback}>\n <div className='contents' data-id={id} data-role={role}>\n <SurfaceContext.Provider value={contextValue}>\n <SurfaceInfo ref={forwardedRef}>\n {onProfilerRender && !profilerId.includes('org.dxos.plugin.debug') ? (\n <Profiler id={profilerId} onRender={onProfilerRender}>\n <Component id={id} role={role} data={data} limit={limit} {...rest} />\n </Profiler>\n ) : (\n <Component id={id} role={role} data={data} limit={limit} {...rest} />\n )}\n </SurfaceInfo>\n </SurfaceContext.Provider>\n </div>\n </ErrorBoundary>\n );\n }\n\n return (\n <ErrorBoundary name='surface' resetKeys={[data]} FallbackComponent={fallback}>\n <div className='contents' data-id={id} data-role={role}>\n <SurfaceContext.Provider value={contextValue}>\n <Component id={id} role={role} data={data} limit={limit} {...rest} ref={forwardedRef} />\n </SurfaceContext.Provider>\n </div>\n </ErrorBoundary>\n );\n },\n ),\n);\n\nSurfaceContextProvider.displayName = 'SurfaceContextProvider';\n\n/**\n * A surface is a named region of the screen that can be populated by plugins.\n */\n// TODO(burdon): Remove `ref` since relying on this would be error prone.\nexport const SurfaceComponent = memo(\n forwardRef<HTMLElement, Props & { type?: RoleToken<any> }>(\n ({ id: _id, role, type, data: dataProp, limit, placeholder = DEFAULT_PLACEHOLDER, ...rest }, forwardedRef) => {\n const data = useDefaultValue(dataProp, () => ({}));\n // TODO(wittjosiah): This will make all surfaces depend on a single signal.\n // This isn't ideal because it means that any change to the data will cause all surfaces to re-render.\n // This effectively means that plugin modules which contribute surfaces need to all be activated at startup.\n // This should be fine for now because it's how it worked prior to capabilities api anyway.\n // In the future, it would be nice to be able to bucket the surface contributions by role.\n const surfaces = useSurfaces();\n\n const effectiveRole = role ?? type?.role;\n if (effectiveRole == null) {\n if (DEBUG) {\n log.warn('Surface has neither `role` nor `type` prop', { id: _id });\n }\n return null;\n }\n\n // NOTE: Memoizing the candidates makes the surface not re-render based on reactivity within data.\n const definitions = findCandidates(surfaces, { role: effectiveRole, data });\n const candidates = limit ? definitions.slice(0, limit) : definitions;\n if (DEBUG && candidates.length === 0) {\n log.warn('no candidates for surface', { role: effectiveRole, data });\n return null;\n }\n\n return (\n <Suspense fallback={placeholder}>\n {candidates.map((definition) => (\n <SurfaceContextProvider\n key={definition.id}\n id={definition.id}\n role={effectiveRole}\n data={data}\n limit={limit}\n definition={definition}\n ref={forwardedRef}\n {...rest}\n />\n ))}\n </Suspense>\n );\n },\n ),\n) as (<TToken extends RoleToken<any>>(props: TypedProps<TToken> & RefAttributes<HTMLElement>) => React.ReactNode) &\n NamedExoticComponent<Props & RefAttributes<HTMLElement>>;\n\nSurfaceComponent.displayName = 'Surface';\n\n// TODO(burdon): Make user facing, with telemetry.\nconst ErrorFallback = ({ error }: Props) => {\n const { message } = error instanceof Error ? error : { message: String(error) };\n return (\n <div role='alert' data-testid='error-boundary-fallback'>\n <h1 className='flex gap-2 text-sm mt-2 text-info-text'>{message}</h1>\n </div>\n );\n};\n\nconst findCandidates = (surfaces: Definition[], { role, data }: { role: string; data: Props['data'] }) => {\n return Object.values(surfaces)\n .filter((definition) =>\n Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,\n )\n .filter(({ filter }) => (filter ? filter(data ?? {}, role) : true))\n .toSorted(byPosition);\n};\n\n/**\n * @internal\n */\nexport const useSurfaces = () => {\n const manager = usePluginManager();\n const surfacesByModule = useAtomValue(manager.capabilities.atomByModule(Capabilities.ReactSurface));\n return useMemo(() => {\n const result: Definition[] = [];\n for (const [moduleId, surfaces] of Object.entries(surfacesByModule)) {\n for (const def of surfaces.flat()) {\n result.push({ ...def, id: `${moduleId}.${def.id}` });\n }\n }\n return result;\n }, [surfacesByModule]);\n};\n\n/**\n * @returns `true` if there is a contributed surface which matches the specified role & data, `false` otherwise.\n *\n * Two overloads:\n * - Typed: pass a `type` role token and `data` is constrained to the token's\n * declared contract (e.g. `AppSurface.Section` requires `attendableId`).\n * - Legacy: pass a string `role` and `data` is untyped.\n */\nexport function isSurfaceAvailable<TToken extends RoleToken<any>>(\n capabilityManager: CapabilityManager.CapabilityManager,\n args: { type: TToken; data?: TokenData<TToken>; role?: never },\n): boolean;\nexport function isSurfaceAvailable(\n capabilityManager: CapabilityManager.CapabilityManager,\n args: Pick<Props, 'role' | 'data'> & { type?: undefined },\n): boolean;\nexport function isSurfaceAvailable(\n capabilityManager: CapabilityManager.CapabilityManager,\n { role, type, data }: { role?: string; type?: RoleToken<any>; data?: unknown },\n): boolean {\n const effectiveRole = role ?? type?.role;\n if (effectiveRole == null) {\n return false;\n }\n const surfaces = capabilityManager.getAll(Capabilities.ReactSurface);\n const candidates = findCandidates(surfaces.flat(), {\n role: effectiveRole,\n data: data as Props['data'],\n });\n return candidates.length > 0;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport React, {\n type ReactElement,\n type Ref,\n cloneElement,\n forwardRef,\n useCallback,\n useLayoutEffect,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { addEventListener, combine } from '@dxos/async';\nimport { useMergeRefs } from '@dxos/react-hooks';\n\nimport { useSurface } from '../../hooks';\n\nexport type SurfaceInfoProps = {\n children: ReactElement<{ ref?: Ref<HTMLElement> }>;\n};\n\n/**\n * Debug wrapper for surfaces.\n */\nexport const SurfaceInfo = forwardRef<HTMLElement, SurfaceInfoProps>(({ children }, forwardedRef) => {\n const [rect, setRect] = useState<DOMRect | null>(null);\n const [expand, setExpand] = useState(false);\n const info = useSurface();\n\n const [root, setRoot] = useState<HTMLElement | null>(null);\n const measureRef = useCallback((node: HTMLElement | null) => setRoot(node), []);\n const mergedRef = useMergeRefs([measureRef, forwardedRef]);\n const childWithRef = cloneElement(children, { ref: mergedRef });\n\n useLayoutEffect(() => {\n if (!root) {\n setRect(null);\n return;\n }\n\n const measure = () => {\n setRect(root.getBoundingClientRect());\n };\n\n const observer = new ResizeObserver(measure);\n observer.observe(root);\n measure();\n\n return combine(\n addEventListener(window, 'scroll', measure, true),\n addEventListener(window, 'resize', measure),\n () => {\n observer.disconnect();\n },\n );\n }, [root]);\n\n const padding = 0;\n return (\n <>\n {childWithRef}\n {rect &&\n createPortal(\n <div\n className='z-[100] fixed flex flex-col-reverse scrollbar-none overflow-auto pointer-events-none'\n style={{\n top: rect.top + padding,\n left: rect.left + padding,\n width: rect.width - padding * 2,\n height: rect.height - padding * 2,\n }}\n >\n {expand ? (\n <div\n className='absolute inset-0 bg-deck-surface border border-green-500 cursor-pointer pointer-events-auto overflow-auto'\n onPointerDown={(ev) => ev.stopPropagation()}\n onClick={(ev) => {\n ev.stopPropagation();\n setExpand(false);\n }}\n >\n <pre className='p-2 text-xs text-description font-mono'>{JSON.stringify({ info }, null, 2)}</pre>\n </div>\n ) : (\n <span\n className='absolute right-1 bottom-0 flex items-center p-1 text-green-500 opacity-80 hover:opacity-100 text-xl cursor-pointer pointer-events-auto'\n title={info.id}\n onPointerDown={(ev) => ev.stopPropagation()}\n onClick={(ev) => {\n ev.stopPropagation();\n setExpand(true);\n }}\n >\n ⓘ\n </span>\n )}\n </div>,\n // TODO(burdon): Create well-known element to gather all debug portals.\n document.body,\n )}\n </>\n );\n});\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport React, {\n type Context,\n type PropsWithChildren,\n type ProfilerOnRenderCallback,\n createContext,\n useContext,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\nconst MAX_ENTRIES = 500;\n\n/**\n * Single profiler record captured from React Profiler onRender callback.\n */\nexport type SurfaceProfilerEntry = {\n id: string;\n phase: 'mount' | 'update' | 'nested-update';\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n timestamp: number;\n};\n\n/**\n * Aggregated stats for a single profiled surface.\n */\nexport type SurfaceProfilerStats = {\n id: string;\n mountCount: number;\n updateCount: number;\n totalRenders: number;\n avgActualDuration: number;\n maxActualDuration: number;\n avgBaseDuration: number;\n lastActualDuration: number;\n lastCommitTime: number;\n};\n\n/**\n * Store that collects profiler entries and notifies subscribers.\n */\nclass SurfaceProfilerStore {\n private _entries: SurfaceProfilerEntry[] = [];\n private _listeners = new Set<() => void>();\n private _snapshot: readonly SurfaceProfilerEntry[] = [];\n private _pendingNotify = false;\n\n /** Records an entry and schedules a deferred notification to avoid re-render loops. */\n record(entry: SurfaceProfilerEntry) {\n this._entries.push(entry);\n if (this._entries.length > MAX_ENTRIES) {\n this._entries = this._entries.slice(-MAX_ENTRIES);\n }\n this._snapshot = [...this._entries];\n this._scheduleNotify();\n }\n\n clear() {\n this._entries = [];\n this._snapshot = [];\n this._notifySync();\n }\n\n subscribe = (listener: () => void) => {\n this._listeners.add(listener);\n return () => {\n this._listeners.delete(listener);\n };\n };\n\n getSnapshot = (): readonly SurfaceProfilerEntry[] => {\n return this._snapshot;\n };\n\n /**\n * Defers notification to the next animation frame to break the\n * Profiler onRender → record → notify → re-render → onRender loop.\n */\n private _scheduleNotify() {\n if (!this._pendingNotify) {\n this._pendingNotify = true;\n requestAnimationFrame(() => {\n this._pendingNotify = false;\n this._notifySync();\n });\n }\n }\n\n private _notifySync() {\n for (const listener of this._listeners) {\n listener();\n }\n }\n}\n\ntype SurfaceProfilerContextValue = {\n store: SurfaceProfilerStore;\n};\n\nconst SurfaceProfilerContext: Context<SurfaceProfilerContextValue | undefined> = createContext<\n SurfaceProfilerContextValue | undefined\n>(undefined);\n\n/**\n * Provider that collects React Profiler data from Surface components.\n */\nexport const SurfaceProfilerProvider = ({ children }: PropsWithChildren) => {\n const storeRef = useRef<SurfaceProfilerStore>(null);\n if (!storeRef.current) {\n storeRef.current = new SurfaceProfilerStore();\n }\n return (\n <SurfaceProfilerContext.Provider value={{ store: storeRef.current }}>{children}</SurfaceProfilerContext.Provider>\n );\n};\n\n/**\n * Returns a stable onRender callback for use with React Profiler.\n */\nexport const useSurfaceProfilerCallback = (): ProfilerOnRenderCallback | undefined => {\n const store = useContext(SurfaceProfilerContext)?.store;\n return useMemo<ProfilerOnRenderCallback | undefined>(() => {\n if (!store) {\n return undefined;\n }\n return (id, phase, actualDuration, baseDuration, startTime, commitTime) => {\n store.record({\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime,\n timestamp: Date.now(),\n });\n };\n }, [store]);\n};\n\n/**\n * Returns all profiler entries reactively.\n */\nexport const useSurfaceProfilerEntries = (): readonly SurfaceProfilerEntry[] => {\n const context = useContext(SurfaceProfilerContext);\n return useSyncExternalStore(context?.store.subscribe ?? noop, context?.store.getSnapshot ?? emptySnapshot);\n};\n\n/**\n * Returns aggregated stats grouped by surface id.\n */\nexport const useSurfaceProfilerStats = (): SurfaceProfilerStats[] => {\n const entries = useSurfaceProfilerEntries();\n const statsMap = new Map<string, SurfaceProfilerStats>();\n\n for (const entry of entries) {\n let stats = statsMap.get(entry.id);\n if (!stats) {\n stats = {\n id: entry.id,\n mountCount: 0,\n updateCount: 0,\n totalRenders: 0,\n avgActualDuration: 0,\n maxActualDuration: 0,\n avgBaseDuration: 0,\n lastActualDuration: 0,\n lastCommitTime: 0,\n };\n statsMap.set(entry.id, stats);\n }\n\n if (entry.phase === 'mount') {\n stats.mountCount++;\n } else {\n stats.updateCount++;\n }\n stats.totalRenders++;\n stats.avgActualDuration =\n (stats.avgActualDuration * (stats.totalRenders - 1) + entry.actualDuration) / stats.totalRenders;\n stats.avgBaseDuration =\n (stats.avgBaseDuration * (stats.totalRenders - 1) + entry.baseDuration) / stats.totalRenders;\n stats.maxActualDuration = Math.max(stats.maxActualDuration, entry.actualDuration);\n stats.lastActualDuration = entry.actualDuration;\n stats.lastCommitTime = entry.commitTime;\n }\n\n return [...statsMap.values()].sort((a, b) => b.maxActualDuration - a.maxActualDuration);\n};\n\n/**\n * Clears all collected profiler entries.\n */\nexport const useSurfaceProfilerClear = (): (() => void) | undefined => {\n const store = useContext(SurfaceProfilerContext)?.store;\n return useMemo(() => (store ? () => store.clear() : undefined), [store]);\n};\n\nconst noop = () => () => {};\nconst EMPTY_SNAPSHOT: readonly SurfaceProfilerEntry[] = [];\nconst emptySnapshot = () => EMPTY_SNAPSHOT;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type { FC, PropsWithChildren, ReactNode, RefCallback } from 'react';\n\nimport type { MakeOptional, Position } from '@dxos/util';\n\n/**\n * A typed role token. Carries a role string for runtime dispatch plus a phantom\n * data type so consumers using `type={SomeToken}` and providers using\n * `AppSurface.object(SomeToken, ...)` share a single type-level contract.\n *\n * Mint via {@link makeType}.\n */\nexport type RoleToken<TData> = {\n readonly role: string;\n /** Covariant phantom; never accessed at runtime. */\n readonly _phantom?: TData;\n};\n\n/**\n * One entry in a {@link SurfaceFilter} — a role plus the guard that validates\n * the data shape when the Surface dispatcher is matching that role.\n */\nexport type SurfaceBinding = {\n readonly role: string;\n readonly guard: (data: unknown) => boolean;\n};\n\n/**\n * Typed filter binding for {@link create}. Combines one or more `(role, guard)`\n * pairs so a provider can register against multiple roles while keeping the\n * role and its data shape in a single expression.\n */\nexport type SurfaceFilter<TData> = {\n readonly bindings: ReadonlyArray<SurfaceBinding>;\n /** Covariant phantom; never accessed at runtime. */\n readonly _phantom?: TData;\n};\n\n/**\n * Narrow data type carried by a role token.\n */\nexport type TokenData<T> = T extends RoleToken<infer D> ? D : never;\n\n/**\n * Runtime guard for {@link SurfaceFilter}. Distinguishes new-style filter\n * bindings from legacy predicate filters.\n */\nexport const isSurfaceFilter = (value: unknown): value is SurfaceFilter<any> =>\n typeof value === 'object' && value !== null && Array.isArray((value as { bindings?: unknown }).bindings);\n\n/**\n * Mints a typed role token. Identity is structural; all tokens with the same\n * `role` string are interchangeable at runtime.\n */\nexport const makeType = <TData>(role: string): RoleToken<TData> => ({ role });\n\n/**\n * Props that are passed to the Surface component.\n *\n * The role can be provided either as a string via `role` or as a typed\n * {@link RoleToken} via `type`. The typed form narrows `data` to the token's\n * declared shape.\n */\nexport type Props<T extends Record<string, any> = Record<string, unknown>> = {\n /**\n * If specified, the Surface will be wrapped in an error boundary.\n * The fallback component will be rendered if an error occurs.\n */\n fallback?: FC<{ error: Error; data?: any }>;\n\n /**\n * If specified, the Surface will be wrapped in a suspense boundary.\n * The placeholder component will be rendered while the surface component is loading.\n */\n placeholder?: ReactNode;\n} & MakeOptional<CoreProps<T>, 'id' | 'data' | 'role'> & {\n /**\n * Explicitly disallow `type` on the untyped Props overload — if the caller\n * provides `type={AppSurface.X}`, TypeScript must route to the typed\n * overload (where `data` is narrowed by the token). Without this, the\n * catch-all index signature below would accept any `type` value and mask\n * the typed overload entirely.\n */\n type?: undefined;\n } /**\n * Additional props to pass to the component.\n * These props are not used by Surface itself but may be used by components which resolve the surface.\n * Exclude known prop names to prevent overriding well-defined props.\n */ & {\n [K in keyof Record<string, any>]: K extends keyof CoreProps<T> | 'fallback' | 'placeholder' | 'type' ? never : any;\n };\n\n/**\n * Typed Surface consumer props — carries the role/data-shape contract via a\n * {@link RoleToken}. Available as a typed overload of the Surface component so\n * ad-hoc `type` fields on arbitrary spread props don't conflict with the\n * untyped consumer form.\n */\nexport type TypedProps<TToken extends RoleToken<any>> = {\n fallback?: FC<{ error: Error; data?: any }>;\n placeholder?: ReactNode;\n id?: string;\n type: TToken;\n data?: TokenData<TToken>;\n limit?: number | undefined;\n} & {\n /**\n * Additional pass-through props. Known prop names are excluded so the\n * catch-all doesn't widen `data` / `type` / etc. to `any` at the intersection.\n */\n [K in keyof Record<string, any>]: K extends 'fallback' | 'placeholder' | 'id' | 'type' | 'data' | 'limit'\n ? never\n : any;\n};\n\n/**\n * NOTE: If `[key: string]: unknown` is included in shared types, when re-used other fields become unknown as well.\n */\nexport type CoreProps<T extends Record<string, any> = Record<string, unknown>> = PropsWithChildren<{\n /**\n * ID for debugging.\n */\n id: string;\n\n /**\n * Role defines how the data should be rendered. For new code, prefer the\n * typed overload of the Surface component which takes a {@link RoleToken}\n * via the `type` prop instead — it enforces a role/data contract at compile\n * time.\n */\n role: string;\n\n /**\n * The data to be rendered by the surface.\n * NOTE: This must be a stable value.\n */\n data: T;\n\n /**\n * If more than one component is resolved, the limit determines how many are rendered.\n */\n limit?: number | undefined;\n}>;\n\n// TODO(burdon): Remove ref since relying on this would be error prone.\nexport type ComponentProps<T extends Record<string, any> = Record<string, any>> = CoreProps<T> & {\n ref?: RefCallback<HTMLElement>;\n} & Record<string, any>;\n\n/**\n * React component used to render a surface once is has matched.\n */\nexport type ComponentFunction<T extends Record<string, any> = Record<string, any>> = (\n props: ComponentProps<T>,\n) => ReactNode;\n\n/**\n * Definition of when a React component surface should be rendered.\n *\n * The optional `filter` receives the consumer-supplied `role` as its second\n * argument so a single definition can encode role-specific guards (used by the\n * {@link SurfaceFilter}-based `create` overload).\n */\nexport type ReactDefinition<T extends Record<string, any> = any> = Readonly<{\n kind: 'react';\n id: string;\n role: string | string[];\n position?: Position;\n component: ComponentFunction<T>;\n filter?: (data: Record<string, unknown>, role?: string) => data is T;\n}>;\n\n/**\n * Definition of when a Web Component surface should be rendered.\n */\nexport type WebComponentDefinition<T extends Record<string, any> = any> = Readonly<{\n kind: 'web-component';\n id: string;\n role: string | string[];\n position?: Position;\n /**\n * The tag name of the Web Component to render.\n * The Web Component will receive the same props as React surfaces via properties/attributes.\n */\n tagName: string;\n filter?: (data: Record<string, unknown>, role?: string) => data is T;\n}>;\n\n/**\n * Definition of when a surface (React or Web Component) should be rendered.\n */\nexport type Definition<T extends Record<string, any> = any> = ReactDefinition<T> | WebComponentDefinition<T>;\n\n/**\n * Typed React surface definition — role is derived from the filter's bindings.\n */\nexport type TypedReactDefinition<T extends Record<string, any> = any> = Readonly<{\n id: string;\n filter: SurfaceFilter<T>;\n component: ComponentFunction<T>;\n position?: Position;\n}>;\n\n/**\n * Typed Web Component surface definition.\n */\nexport type TypedWebComponentDefinition<T extends Record<string, any> = any> = Readonly<{\n id: string;\n filter: SurfaceFilter<T>;\n tagName: string;\n position?: Position;\n}>;\n\nconst expandBindings = <T extends Record<string, any>>(\n filter: SurfaceFilter<T>,\n): { role: string | string[]; guard: (data: Record<string, unknown>, role?: string) => data is T } => {\n const bindings = filter.bindings;\n const roles = Array.from(new Set(bindings.map((binding) => binding.role)));\n const guard = (data: Record<string, unknown>, role?: string): data is T => {\n if (role != null) {\n // Multiple bindings may share a role (e.g. via `oneOf` of same-role filters);\n // the role matches if ANY of them passes.\n return bindings.some((entry) => entry.role === role && entry.guard(data));\n }\n return bindings.some((entry) => entry.guard(data));\n };\n return { role: roles.length === 1 ? roles[0] : roles, guard };\n};\n\n/**\n * Creates a React surface definition.\n */\nexport function create<T extends Record<string, any> = any>(definition: TypedReactDefinition<T>): ReactDefinition<T>;\nexport function create<T extends Record<string, any> = any>(\n definition: Omit<ReactDefinition<T>, 'kind'>,\n): ReactDefinition<T>;\nexport function create<T extends Record<string, any> = any>(\n definition: TypedReactDefinition<T> | Omit<ReactDefinition<T>, 'kind'>,\n): ReactDefinition<T> {\n if (isSurfaceFilter(definition.filter)) {\n const { id, filter, component, position } = definition as TypedReactDefinition<T>;\n const { role, guard } = expandBindings(filter);\n return { kind: 'react', id, role, position, component, filter: guard };\n }\n return { ...(definition as Omit<ReactDefinition<T>, 'kind'>), kind: 'react' };\n}\n\n/**\n * Creates a Web Component surface definition.\n */\nexport function createWeb<T extends Record<string, any> = any>(\n definition: TypedWebComponentDefinition<T>,\n): WebComponentDefinition<T>;\nexport function createWeb<T extends Record<string, any> = any>(\n definition: Omit<WebComponentDefinition<T>, 'kind'>,\n): WebComponentDefinition<T>;\nexport function createWeb<T extends Record<string, any> = any>(\n definition: TypedWebComponentDefinition<T> | Omit<WebComponentDefinition<T>, 'kind'>,\n): WebComponentDefinition<T> {\n if (isSurfaceFilter(definition.filter)) {\n const { id, filter, tagName, position } = definition as TypedWebComponentDefinition<T>;\n const { role, guard } = expandBindings(filter);\n return { kind: 'web-component', id, role, position, tagName, filter: guard };\n }\n return { ...(definition as Omit<WebComponentDefinition<T>, 'kind'>), kind: 'web-component' };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(wittjosiah): Cleanup to avoid re-naming.\nimport { SurfaceContext } from './context';\nimport { SurfaceComponent, isSurfaceAvailable } from './SurfaceComponent';\nimport {\n SurfaceProfilerProvider,\n useSurfaceProfilerCallback,\n useSurfaceProfilerClear,\n useSurfaceProfilerEntries,\n useSurfaceProfilerStats,\n} from './SurfaceProfilerContext';\nimport {\n type Definition as SurfaceDefinition,\n type RoleToken as SurfaceRoleToken,\n type SurfaceBinding as SurfaceBindingType,\n type SurfaceFilter as SurfaceFilterType,\n type TokenData as SurfaceTokenData,\n type TypedProps as SurfaceTypedProps,\n create as createSurface,\n createWeb as createWebSurface,\n isSurfaceFilter as isSurfaceFilterFn,\n makeType as makeTypeFn,\n} from './types';\n\nexport namespace Surface {\n export type Definition = SurfaceDefinition;\n export const create = createSurface;\n export const createWeb = createWebSurface;\n\n export type Context = SurfaceContext;\n export const Context = SurfaceContext;\n\n export const Surface = SurfaceComponent;\n export const isAvailable = isSurfaceAvailable;\n\n export type RoleToken<TData> = SurfaceRoleToken<TData>;\n export type Binding = SurfaceBindingType;\n export type Filter<TData> = SurfaceFilterType<TData>;\n export type TokenData<T> = SurfaceTokenData<T>;\n export type TypedProps<TToken extends SurfaceRoleToken<any>> = SurfaceTypedProps<TToken>;\n export const makeType = makeTypeFn;\n export const isFilter = isSurfaceFilterFn;\n\n export const ProfilerProvider = SurfaceProfilerProvider;\n export const useProfilerCallback = useSurfaceProfilerCallback;\n export const useProfilerEntries = useSurfaceProfilerEntries;\n export const useProfilerStats = useSurfaceProfilerStats;\n export const useProfilerClear = useSurfaceProfilerClear;\n}\n\nexport type { SurfaceProfilerEntry, SurfaceProfilerStats } from './SurfaceProfilerContext';\n"],
5
+ "mappings": ";;;;;AAaO,IAAMA,kBAAkB,CAA2BC,UAAAA;AACxD,QAAMC,kBAAkB,CAACC,QAAgBC,OAAO,oBAAIC,IAAAA,GAAeC,OAAO,oBAAID,IAAAA,MAAa;AACzF,QAAIC,KAAKC,IAAIJ,MAAAA,GAAS;AACpB,YAAM,IAAIK,MAAM,0CAA0CL,MAAAA,EAAQ;IACpE;AACA,QAAIC,KAAKG,IAAIJ,MAAAA,GAAS;AACpB,aAAO,CAAA;IACT;AAEA,UAAMM,OAAOR,MAAMS,KAAK,CAACC,MAAMA,EAAEC,OAAOT,MAAAA;AACxC,QAAI,CAACM,MAAM;AACT,YAAM,IAAID,MAAM,QAAQL,MAAAA,0CAAgD;IAC1E;AAEA,UAAMU,UAAU,oBAAIR,IAAI;SAAIC;MAAMH;KAAO;AACzC,UAAMW,UAAU,oBAAIT,IAAI;SAAID;MAAMD;KAAO;AAEzC,UAAMY,YAAYN,KAAKM,aAAa,CAAA;AACpC,WAAO;SAAIA,UAAUC,QAAQ,CAACC,UAAUf,gBAAgBe,OAAOH,SAASD,OAAAA,CAAAA;MAAWV;;EACrF;AAGA,QAAMe,kBAAkBjB,MACrBkB,IAAI,CAACV,SAASA,KAAKG,EAAE,EACrBI,QAAQ,CAACJ,OAAOV,gBAAgBU,EAAAA,CAAAA,EAChCQ,OAAO,CAACR,IAAIS,OAAOC,SAASA,KAAKC,QAA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AeC,MAAAA;AACvC,WAAO;MAAEgB,MAAM;MAAiBH;MAAIf;MAAMiB;MAAUG;MAASlB,QAAQM;IAAM;EAC7E;AACA,SAAO;IAAE,GAAIM;IAAwDI,MAAM;EAAgB;AAC7F;;;UCjPiBG,UAAAA;WAEFC,SAASC;WACTC,YAAYC;WAGZC,UAAUC;WAEVN,UAAUO;WACVC,cAAcC;WAOdC,WAAWC;WACXC,WAAWC;WAEXC,mBAAmBC;WACnBC,sBAAsBC;WACtBC,qBAAqBC;WACrBC,mBAAmBC;WACnBC,mBAAmBC;AAClC,GAxBiBvB,YAAAA,UAAAA,CAAAA,EAAAA;;;;APjBV,IAAMwB,aAAa,MAAA;AACxB,SAAOC,YAAWC,QAAQC,OAAO,KAAKC,OAAM,IAAIC,MAAM,wBAAA,CAAA;AACxD;",
6
+ "names": ["topologicalSort", "nodes", "getDependencies", "nodeId", "seen", "Set", "path", "has", "Error", "node", "find", "n", "id", "newPath", "newSeen", "dependsOn", "flatMap", "depId", "allDependencies", "map", "filter", "index", "self", "indexOf", "undefined", "useContext", "raise", "createContext", "useContext", "raise", "PluginManagerContext", "undefined", "usePluginManager", "Error", "PluginManagerProvider", "Provider", "createContext", "SurfaceContext", "undefined", "useAtomValue", "React", "Fragment", "Profiler", "Suspense", "forwardRef", "memo", "useEffect", "useMemo", "useRef", "log", "ErrorBoundary", "useDefaultValue", "byPosition", "React", "cloneElement", "forwardRef", "useCallback", "useLayoutEffect", "useState", "createPortal", "addEventListener", "combine", "useMergeRefs", "SurfaceInfo", "forwardRef", "children", "forwardedRef", "rect", "setRect", "useState", "expand", "setExpand", "info", "useSurface", "root", "setRoot", "measureRef", "useCallback", "node", "mergedRef", "useMergeRefs", "childWithRef", "cloneElement", "ref", "useLayoutEffect", "measure", "getBoundingClientRect", "observer", "ResizeObserver", "observe", "combine", "addEventListener", "window", "disconnect", "padding", "createPortal", "div", "className", "style", "top", "left", "width", "height", "onPointerDown", "ev", "stopPropagation", "onClick", "pre", "JSON", "stringify", "span", "title", "id", "document", "body", "React", "createContext", "useContext", "useMemo", "useRef", "useSyncExternalStore", "MAX_ENTRIES", "SurfaceProfilerStore", "_entries", "_listeners", "Set", "_snapshot", "_pendingNotify", "record", "entry", "push", "length", "slice", "_scheduleNotify", "clear", "_notifySync", "subscribe", "listener", "add", "delete", "getSnapshot", "requestAnimationFrame", "SurfaceProfilerContext", "undefined", "SurfaceProfilerProvider", "children", "storeRef", "current", "Provider", "value", "store", "useSurfaceProfilerCallback", "id", "phase", "actualDuration", "baseDuration", "startTime", "commitTime", "timestamp", "Date", "now", "useSurfaceProfilerEntries", "context", "noop", "emptySnapshot", "useSurfaceProfilerStats", "entries", "statsMap", "Map", "stats", "get", "mountCount", "updateCount", "totalRenders", "avgActualDuration", "maxActualDuration", "avgBaseDuration", "lastActualDuration", "lastCommitTime", "set", "Math", "max", "values", "sort", "a", "b", "useSurfaceProfilerClear", "EMPTY_SNAPSHOT", "elementRef", "forwardRef", "propsRef", "useRef", "id", "role", "data", "limit", "useEffect", "Object", "assign", "element", "containerRef", "current", "appendChild", "forwardedRef", "definition", "div", "WebComponentWrapper", "React", "FallbackComponent", "value", "contextValue", "ref", "debug", "DEBUG", "name", "className", "data-role", "SurfaceInfo", "onProfilerRender", "includes", "profilerId", "Component", "SurfaceContextProvider", "effectiveRole", "log", "SurfaceComponent", "ErrorFallback", "String", "error", "message", "findCandidates", "surfacesByModule", "useAtomValue", "useMemo", "moduleId", "def", "result", "surfaces", "isSurfaceFilter", "value", "Array", "isArray", "bindings", "makeType", "role", "expandBindings", "filter", "roles", "from", "Set", "map", "binding", "guard", "data", "some", "entry", "length", "create", "definition", "id", "component", "position", "kind", "createWeb", "tagName", "Surface", "create", "createSurface", "createWeb", "createWebSurface", "Context", "SurfaceContext", "SurfaceComponent", "isAvailable", "isSurfaceAvailable", "makeType", "makeTypeFn", "isFilter", "isSurfaceFilterFn", "ProfilerProvider", "SurfaceProfilerProvider", "useProfilerCallback", "useSurfaceProfilerCallback", "useProfilerEntries", "useSurfaceProfilerEntries", "useProfilerStats", "useSurfaceProfilerStats", "useProfilerClear", "useSurfaceProfilerClear", "useSurface", "useContext", "Surface", "Context", "raise", "Error"]
7
+ }
@@ -0,0 +1,422 @@
1
+ import {
2
+ isPlugin
3
+ } from "./chunk-Z55LVAGN.mjs";
4
+ import {
5
+ __export
6
+ } from "./chunk-J5LGTIGS.mjs";
7
+
8
+ // src/core/url-loader.ts
9
+ var url_loader_exports = {};
10
+ __export(url_loader_exports, {
11
+ RemotePluginLoadError: () => RemotePluginLoadError,
12
+ getInstalledVersion: () => getInstalledVersion,
13
+ getRemoteEntries: () => getRemoteEntries,
14
+ isLocalUrl: () => isLocalUrl,
15
+ make: () => make,
16
+ preload: () => preload,
17
+ setInstalledVersion: () => setInstalledVersion,
18
+ uninstall: () => uninstall
19
+ });
20
+ import * as Effect3 from "effect/Effect";
21
+ import * as Option from "effect/Option";
22
+ import { BaseError as BaseError3 } from "@dxos/errors";
23
+ import { log } from "@dxos/log";
24
+
25
+ // src/core/plugin-asset-cache.ts
26
+ var plugin_asset_cache_exports = {};
27
+ __export(plugin_asset_cache_exports, {
28
+ PluginAssetCacheError: () => PluginAssetCacheError,
29
+ noop: () => noop
30
+ });
31
+ import * as Effect from "effect/Effect";
32
+ import { BaseError } from "@dxos/errors";
33
+ var PluginAssetCacheError = class extends BaseError.extend("PluginAssetCacheError", "Plugin asset cache operation failed") {
34
+ };
35
+ var noop = () => ({
36
+ cache: () => Effect.void,
37
+ evict: () => Effect.void,
38
+ resolve: (_pluginId, url) => Effect.succeed(url),
39
+ list: () => Effect.succeed([])
40
+ });
41
+
42
+ // src/core/plugin-manifest.ts
43
+ var plugin_manifest_exports = {};
44
+ __export(plugin_manifest_exports, {
45
+ Manifest: () => Manifest,
46
+ PLUGIN_DEV_SERVER_PORT: () => PLUGIN_DEV_SERVER_PORT,
47
+ PluginManifestError: () => PluginManifestError,
48
+ fetchManifest: () => fetchManifest,
49
+ parse: () => parse
50
+ });
51
+ import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
52
+ import * as HttpClient from "@effect/platform/HttpClient";
53
+ import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
54
+ import * as HttpClientResponse from "@effect/platform/HttpClientResponse";
55
+ import * as Effect2 from "effect/Effect";
56
+ import * as Schema from "effect/Schema";
57
+ import { BaseError as BaseError2 } from "@dxos/errors";
58
+ import { PLUGIN_ENTRY_FILENAME } from "@dxos/protocols";
59
+ var PLUGIN_DEV_SERVER_PORT = 3967;
60
+ var PluginManifestError = class extends BaseError2.extend("PluginManifestError", "Plugin manifest is invalid") {
61
+ };
62
+ var Manifest = Schema.Struct({
63
+ id: Schema.String,
64
+ name: Schema.String,
65
+ version: Schema.String,
66
+ assets: Schema.Array(Schema.String),
67
+ devEntry: Schema.String.pipe(Schema.optional)
68
+ });
69
+ var resolve = (manifestUrl, manifest) => {
70
+ const dev = manifest.devEntry !== void 0;
71
+ return {
72
+ id: manifest.id,
73
+ name: manifest.name,
74
+ version: manifest.version,
75
+ entryUrl: new URL(dev ? manifest.devEntry : PLUGIN_ENTRY_FILENAME, manifestUrl).toString(),
76
+ assetUrls: manifest.assets.map((asset) => new URL(asset, manifestUrl).toString()),
77
+ dev
78
+ };
79
+ };
80
+ var parse = (manifestUrl, payload) => {
81
+ const manifest = Schema.decodeUnknownSync(Manifest)(payload);
82
+ if (manifest.devEntry === void 0 && !manifest.assets.includes(PLUGIN_ENTRY_FILENAME)) {
83
+ throw new Error(`Manifest at ${manifestUrl} does not list ${PLUGIN_ENTRY_FILENAME} in assets.`);
84
+ }
85
+ return resolve(manifestUrl, manifest);
86
+ };
87
+ var fetchManifest = (manifestUrl) => Effect2.gen(function* () {
88
+ const response = yield* HttpClientRequest.get(manifestUrl).pipe(HttpClient.execute, Effect2.mapError((cause) => new PluginManifestError({
89
+ context: {
90
+ manifestUrl,
91
+ reason: "fetch-failed"
92
+ },
93
+ cause
94
+ })));
95
+ if (response.status >= 400) {
96
+ return yield* Effect2.fail(new PluginManifestError({
97
+ context: {
98
+ manifestUrl,
99
+ reason: "http-error",
100
+ status: response.status
101
+ }
102
+ }));
103
+ }
104
+ const manifest = yield* HttpClientResponse.schemaBodyJson(Manifest)(response).pipe(Effect2.mapError((cause) => new PluginManifestError({
105
+ context: {
106
+ manifestUrl,
107
+ reason: "parse-failed"
108
+ },
109
+ cause
110
+ })));
111
+ if (manifest.devEntry === void 0 && !manifest.assets.includes(PLUGIN_ENTRY_FILENAME)) {
112
+ return yield* Effect2.fail(new PluginManifestError({
113
+ context: {
114
+ manifestUrl,
115
+ reason: "invalid"
116
+ },
117
+ cause: `assets does not include ${PLUGIN_ENTRY_FILENAME}`
118
+ }));
119
+ }
120
+ return resolve(manifestUrl, manifest);
121
+ }).pipe(Effect2.scoped, Effect2.provide(FetchHttpClient.layer));
122
+
123
+ // src/core/url-loader.ts
124
+ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/url-loader.ts";
125
+ var DEFAULT_KEY = "org.dxos.composer.remote-plugins";
126
+ var RemotePluginLoadError = class extends BaseError3.extend("RemotePluginLoadError", "Failed to load remote plugin") {
127
+ };
128
+ var defaultStorage = () => ({
129
+ get: (key) => localStorage.getItem(key),
130
+ set: (key, value) => localStorage.setItem(key, value)
131
+ });
132
+ var getPersistedRemotePlugins = (storage, key) => {
133
+ try {
134
+ const parsed = JSON.parse(storage.get(key) ?? "[]");
135
+ if (!Array.isArray(parsed)) {
136
+ return [];
137
+ }
138
+ return parsed.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.id === "string" && typeof entry.url === "string");
139
+ } catch {
140
+ return [];
141
+ }
142
+ };
143
+ var persistRemotePlugin = (storage, key, entry) => {
144
+ try {
145
+ const entries = getPersistedRemotePlugins(storage, key).filter((existing) => existing.id !== entry.id);
146
+ entries.push(entry);
147
+ storage.set(key, JSON.stringify(entries));
148
+ } catch (error) {
149
+ log.warn("failed to persist remote plugin entry", {
150
+ entry,
151
+ error
152
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 40, S: void 0 });
153
+ }
154
+ };
155
+ var removePersistedRemotePlugin = (storage, key, pluginId) => {
156
+ try {
157
+ const entries = getPersistedRemotePlugins(storage, key).filter((existing) => existing.id !== pluginId);
158
+ storage.set(key, JSON.stringify(entries));
159
+ } catch (error) {
160
+ log.warn("failed to remove remote plugin entry", {
161
+ pluginId,
162
+ error
163
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 51, S: void 0 });
164
+ }
165
+ };
166
+ var isUrl = (locator) => {
167
+ try {
168
+ const url = new URL(locator);
169
+ return url.protocol === "http:" || url.protocol === "https:";
170
+ } catch {
171
+ return false;
172
+ }
173
+ };
174
+ var isLocalUrl = (locator) => {
175
+ try {
176
+ const hostname = new URL(locator).hostname.toLowerCase();
177
+ return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "[::1]";
178
+ } catch {
179
+ return false;
180
+ }
181
+ };
182
+ var getRemoteEntries = (options = {}) => {
183
+ const storage = options.storage ?? defaultStorage();
184
+ const key = options.key ?? DEFAULT_KEY;
185
+ return getPersistedRemotePlugins(storage, key);
186
+ };
187
+ var setInstalledVersion = (id, version, options = {}) => {
188
+ const storage = options.storage ?? defaultStorage();
189
+ const key = options.key ?? DEFAULT_KEY;
190
+ const entries = getPersistedRemotePlugins(storage, key);
191
+ const index = entries.findIndex((entry) => entry.id === id);
192
+ if (index === -1) {
193
+ return;
194
+ }
195
+ entries[index] = {
196
+ ...entries[index],
197
+ version
198
+ };
199
+ try {
200
+ storage.set(key, JSON.stringify(entries));
201
+ } catch (error) {
202
+ log.warn("failed to update installed version for remote plugin", {
203
+ id,
204
+ version,
205
+ error
206
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 103, S: void 0 });
207
+ }
208
+ };
209
+ var getInstalledVersion = (id, options = {}) => {
210
+ const storage = options.storage ?? defaultStorage();
211
+ const key = options.key ?? DEFAULT_KEY;
212
+ return getPersistedRemotePlugins(storage, key).find((entry) => entry.id === id)?.version;
213
+ };
214
+ var normalizePluginExport = (mod) => {
215
+ const exported = mod.default;
216
+ if (isPlugin(exported)) {
217
+ return exported;
218
+ }
219
+ if (typeof exported === "function") {
220
+ const result = exported();
221
+ if (isPlugin(result)) {
222
+ return result;
223
+ }
224
+ }
225
+ throw new Error("Remote module default export is not a Plugin or a zero-arg plugin factory.");
226
+ };
227
+ var loadStylesheets = (manifest, cache) => Effect3.gen(function* () {
228
+ if (typeof document === "undefined") {
229
+ return;
230
+ }
231
+ const cssUrls = manifest.assetUrls.filter((url) => url.endsWith(".css"));
232
+ for (const url of cssUrls) {
233
+ const resolved = yield* cache.resolve(manifest.id, url);
234
+ if (document.querySelector(`link[data-dxos-plugin-id="${manifest.id}"][href="${resolved}"]`)) {
235
+ continue;
236
+ }
237
+ const link = document.createElement("link");
238
+ link.rel = "stylesheet";
239
+ link.href = resolved;
240
+ link.dataset.dxosPluginId = manifest.id;
241
+ document.head.appendChild(link);
242
+ }
243
+ });
244
+ var loadFromManifest = (manifestUrl, cache) => Effect3.gen(function* () {
245
+ log.info("loading remote plugin", {
246
+ manifestUrl
247
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 152, S: this });
248
+ const manifest = yield* fetchManifest(manifestUrl).pipe(Effect3.mapError((cause) => new RemotePluginLoadError({
249
+ context: {
250
+ locator: manifestUrl,
251
+ reason: "manifest-error"
252
+ },
253
+ cause
254
+ })));
255
+ const wrapCacheError = Effect3.mapError((cause) => new RemotePluginLoadError({
256
+ context: {
257
+ locator: manifestUrl,
258
+ reason: "cache-error"
259
+ },
260
+ cause
261
+ }));
262
+ if (!manifest.dev) {
263
+ const cachedUrls = manifest.assetUrls.indexOf(manifestUrl) === -1 ? [
264
+ manifestUrl,
265
+ ...manifest.assetUrls
266
+ ] : manifest.assetUrls;
267
+ yield* cache.cache(manifest.id, cachedUrls).pipe(wrapCacheError);
268
+ }
269
+ const entryUrl = manifest.dev ? manifest.entryUrl : yield* cache.resolve(manifest.id, manifest.entryUrl).pipe(wrapCacheError);
270
+ const mod = yield* Effect3.tryPromise({
271
+ try: () => import(
272
+ /* @vite-ignore */
273
+ entryUrl
274
+ ),
275
+ catch: (cause) => new RemotePluginLoadError({
276
+ context: {
277
+ locator: manifestUrl,
278
+ reason: "import-failed"
279
+ },
280
+ cause
281
+ })
282
+ });
283
+ const plugin = normalizePluginExport(mod);
284
+ if (!plugin.meta.id || !plugin.meta.name) {
285
+ return yield* Effect3.fail(new RemotePluginLoadError({
286
+ context: {
287
+ locator: manifestUrl,
288
+ reason: "meta-missing"
289
+ }
290
+ }));
291
+ }
292
+ if (plugin.meta.id !== manifest.id) {
293
+ return yield* Effect3.fail(new RemotePluginLoadError({
294
+ context: {
295
+ locator: manifestUrl,
296
+ reason: "meta-mismatch",
297
+ metaId: plugin.meta.id,
298
+ manifestId: manifest.id
299
+ }
300
+ }));
301
+ }
302
+ if (!manifest.dev) {
303
+ yield* loadStylesheets(manifest, cache).pipe(wrapCacheError);
304
+ }
305
+ return {
306
+ plugin,
307
+ manifest
308
+ };
309
+ });
310
+ var preload = (options = {}) => Effect3.gen(function* () {
311
+ const storage = options.storage ?? defaultStorage();
312
+ const key = options.key ?? DEFAULT_KEY;
313
+ const cache = options.cache ?? noop();
314
+ const onPluginLoaded = options.onPluginLoaded;
315
+ const entries = getPersistedRemotePlugins(storage, key);
316
+ if (entries.length === 0) {
317
+ return [];
318
+ }
319
+ log.info("preloading remote plugins", {
320
+ count: entries.length
321
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 240, S: this });
322
+ const total = entries.length;
323
+ let loaded = 0;
324
+ const results = yield* Effect3.all(entries.map((entry) => loadFromManifest(entry.url, cache).pipe(
325
+ Effect3.tapError((error) => Effect3.sync(() => log.warn("failed to preload remote plugin", {
326
+ entry,
327
+ error
328
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 245, S: this }))),
329
+ Effect3.option,
330
+ // Tick the progress hook on both success and recoverable failure so
331
+ // the counter monotonically reaches `total`. The host-supplied
332
+ // callback is best-effort: any synchronous throw flows through
333
+ // `Effect.try` and gets logged + ignored so a buggy hook can't
334
+ // derail the preload.
335
+ Effect3.tap(() => Effect3.sync(() => {
336
+ loaded += 1;
337
+ }).pipe(Effect3.andThen(Effect3.try(() => onPluginLoaded?.(loaded, total))), Effect3.tapError((error) => Effect3.sync(() => log.warn("onPluginLoaded threw", {
338
+ loaded,
339
+ total,
340
+ error
341
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 255, S: this }))), Effect3.ignore))
342
+ )), {
343
+ concurrency: "unbounded"
344
+ });
345
+ return results.flatMap((result) => Option.match(result, {
346
+ onNone: () => [],
347
+ onSome: ({ plugin }) => [
348
+ plugin
349
+ ]
350
+ }));
351
+ });
352
+ var make = (builtinPlugins, options = {}) => {
353
+ const storage = options.storage ?? defaultStorage();
354
+ const key = options.key ?? DEFAULT_KEY;
355
+ const cache = options.cache ?? noop();
356
+ return (locator) => Effect3.gen(function* () {
357
+ const builtin = builtinPlugins.find((plugin2) => plugin2.meta.id === locator);
358
+ if (builtin) {
359
+ return {
360
+ plugin: builtin
361
+ };
362
+ }
363
+ if (!isUrl(locator)) {
364
+ return yield* Effect3.fail(new RemotePluginLoadError({
365
+ context: {
366
+ locator,
367
+ reason: "invalid-locator"
368
+ }
369
+ }));
370
+ }
371
+ const { plugin, manifest } = yield* loadFromManifest(locator, cache);
372
+ if (!manifest.dev) {
373
+ const duplicate = builtinPlugins.find((existing) => existing.meta.id === plugin.meta.id);
374
+ if (duplicate) {
375
+ return yield* Effect3.fail(new RemotePluginLoadError({
376
+ context: {
377
+ locator,
378
+ reason: "duplicate-id",
379
+ id: plugin.meta.id
380
+ }
381
+ }));
382
+ }
383
+ persistRemotePlugin(storage, key, {
384
+ id: plugin.meta.id,
385
+ url: locator
386
+ });
387
+ }
388
+ return {
389
+ plugin,
390
+ dev: manifest.dev
391
+ };
392
+ });
393
+ };
394
+ var uninstall = (pluginId, options = {}) => Effect3.gen(function* () {
395
+ const storage = options.storage ?? defaultStorage();
396
+ const key = options.key ?? DEFAULT_KEY;
397
+ const cache = options.cache ?? noop();
398
+ removePersistedRemotePlugin(storage, key, pluginId);
399
+ if (typeof document !== "undefined") {
400
+ document.querySelectorAll(`link[data-dxos-plugin-id="${pluginId}"]`).forEach((node) => node.remove());
401
+ }
402
+ yield* cache.evict(pluginId).pipe(Effect3.tapError((error) => Effect3.sync(() => log.warn("failed to evict plugin assets", {
403
+ pluginId,
404
+ error
405
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 337, S: this }))), Effect3.ignore);
406
+ });
407
+
408
+ export {
409
+ plugin_asset_cache_exports,
410
+ PLUGIN_DEV_SERVER_PORT,
411
+ plugin_manifest_exports,
412
+ RemotePluginLoadError,
413
+ isLocalUrl,
414
+ getRemoteEntries,
415
+ setInstalledVersion,
416
+ getInstalledVersion,
417
+ preload,
418
+ make,
419
+ uninstall,
420
+ url_loader_exports
421
+ };
422
+ //# sourceMappingURL=chunk-CZ4BIAHH.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/core/url-loader.ts", "../../../src/core/plugin-asset-cache.ts", "../../../src/core/plugin-manifest.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\n\nimport { BaseError } from '@dxos/errors';\nimport { log } from '@dxos/log';\n\nimport * as Plugin from './plugin';\nimport * as PluginAssetCache from './plugin-asset-cache';\nimport * as PluginManifest from './plugin-manifest';\n\nconst DEFAULT_KEY = 'org.dxos.composer.remote-plugins';\n\n/**\n * Tagged error for any failure during remote plugin loading. Construction sites\n * set `context.locator` and `context.reason` (one of `'invalid-locator' |\n * 'manifest-error' | 'cache-error' | 'import-failed' | 'meta-missing' |\n * 'meta-mismatch' | 'duplicate-id'`) so handlers can route on the failure mode.\n */\nexport class RemotePluginLoadError extends BaseError.extend('RemotePluginLoadError', 'Failed to load remote plugin') {}\n\n/**\n * Abstraction over key-value storage (defaults to localStorage).\n */\nexport type Storage = {\n get(key: string): string | null;\n set(key: string, value: string): void;\n};\n\n/**\n * Options for configuring the URL loader.\n */\nexport type Options = {\n storage?: Storage;\n key?: string;\n /**\n * Per-platform offline asset cache. Defaults to a no-op cache (no offline support).\n */\n cache?: PluginAssetCache.Cache;\n};\n\n/**\n * Options for the preload entry point. Adds an optional progress hook so hosts\n * can drive a boot-loader counter (`Loading plugins (3/12)…`) as remote plugin\n * manifests resolve. Resolution order is *not* deterministic — each entry races\n * its own network fetch — so callers should treat `loaded` as a count, not an\n * index. Failures are still swallowed; `loaded` advances on both success and\n * recoverable failure so the counter always reaches `total`.\n */\nexport type PreloadOptions = Options & {\n onPluginLoaded?: (loaded: number, total: number) => void;\n};\n\n/**\n * Persisted record of a remote plugin that has been loaded previously.\n *\n * `url` is the URL of the plugin manifest (`plugin.json`), not the entry module.\n */\nexport type RemotePluginEntry = {\n id: string;\n url: string;\n /** Installed version string, e.g. `v1.0.0`. Populated after install from a community catalog entry. */\n version?: string;\n};\n\nconst defaultStorage = (): Storage => ({\n get: (key) => localStorage.getItem(key),\n set: (key, value) => localStorage.setItem(key, value),\n});\n\nconst getPersistedRemotePlugins = (storage: Storage, key: string): RemotePluginEntry[] => {\n try {\n const parsed: unknown = JSON.parse(storage.get(key) ?? '[]');\n if (!Array.isArray(parsed)) {\n return [];\n }\n return parsed.filter(\n (entry): entry is RemotePluginEntry =>\n typeof entry === 'object' && entry !== null && typeof entry.id === 'string' && typeof entry.url === 'string',\n );\n } catch {\n return [];\n }\n};\n\nconst persistRemotePlugin = (storage: Storage, key: string, entry: RemotePluginEntry): void => {\n try {\n const entries = getPersistedRemotePlugins(storage, key).filter((existing) => existing.id !== entry.id);\n entries.push(entry);\n storage.set(key, JSON.stringify(entries));\n } catch (error) {\n log.warn('failed to persist remote plugin entry', { entry, error });\n }\n};\n\nconst removePersistedRemotePlugin = (storage: Storage, key: string, pluginId: string): void => {\n try {\n const entries = getPersistedRemotePlugins(storage, key).filter((existing) => existing.id !== pluginId);\n storage.set(key, JSON.stringify(entries));\n } catch (error) {\n log.warn('failed to remove remote plugin entry', { pluginId, error });\n }\n};\n\nconst isUrl = (locator: string): boolean => {\n try {\n const url = new URL(locator);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n};\n\n/**\n * Returns true when the URL's hostname is the local host (localhost, 127.0.0.1, or ::1).\n */\nexport const isLocalUrl = (locator: string): boolean => {\n try {\n const hostname = new URL(locator).hostname.toLowerCase();\n // WHATWG URL returns '::1' without brackets in Node; some browsers return '[::1]'.\n return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1' || hostname === '[::1]';\n } catch {\n return false;\n }\n};\n\n/**\n * Returns the list of remote plugin entries previously persisted by {@link make}.\n * Useful for UI code that needs to know which loaded plugins were installed from a URL\n * (e.g. to surface a tag on remote or localhost-hosted plugins).\n */\nexport const getRemoteEntries = (options: Options = {}): readonly RemotePluginEntry[] => {\n const storage = options.storage ?? defaultStorage();\n const key = options.key ?? DEFAULT_KEY;\n return getPersistedRemotePlugins(storage, key);\n};\n\n/**\n * Updates the persisted installed version for an already-stored remote plugin entry.\n * Does nothing if the plugin has not been persisted yet.\n */\nexport const setInstalledVersion = (id: string, version: string, options: Options = {}): void => {\n const storage = options.storage ?? defaultStorage();\n const key = options.key ?? DEFAULT_KEY;\n const entries = getPersistedRemotePlugins(storage, key);\n const index = entries.findIndex((entry) => entry.id === id);\n if (index === -1) {\n return;\n }\n entries[index] = { ...entries[index], version };\n try {\n storage.set(key, JSON.stringify(entries));\n } catch (error) {\n log.warn('failed to update installed version for remote plugin', { id, version, error });\n }\n};\n\n/**\n * Returns the installed version string for the given plugin id, or `undefined` if\n * the plugin was installed without version tracking (legacy install) or is not found.\n */\nexport const getInstalledVersion = (id: string, options: Options = {}): string | undefined => {\n const storage = options.storage ?? defaultStorage();\n const key = options.key ?? DEFAULT_KEY;\n return getPersistedRemotePlugins(storage, key).find((entry) => entry.id === id)?.version;\n};\n\nconst normalizePluginExport = (mod: Record<string, unknown>): Plugin.Plugin => {\n const exported = mod.default;\n if (Plugin.isPlugin(exported)) {\n return exported;\n }\n if (typeof exported === 'function') {\n const result = (exported as () => unknown)();\n if (Plugin.isPlugin(result)) {\n return result;\n }\n }\n throw new Error('Remote module default export is not a Plugin or a zero-arg plugin factory.');\n};\n\n/**\n * Loads stylesheets declared in the manifest by appending `<link rel=\"stylesheet\">` elements to the host document.\n * Each link is tagged with `data-dxos-plugin-id` so `uninstall` can clean them up.\n */\nconst loadStylesheets = (\n manifest: PluginManifest.ResolvedManifest,\n cache: PluginAssetCache.Cache,\n): Effect.Effect<void, PluginAssetCache.PluginAssetCacheError> =>\n Effect.gen(function* () {\n if (typeof document === 'undefined') {\n return;\n }\n const cssUrls = manifest.assetUrls.filter((url) => url.endsWith('.css'));\n for (const url of cssUrls) {\n const resolved = yield* cache.resolve(manifest.id, url);\n if (document.querySelector(`link[data-dxos-plugin-id=\"${manifest.id}\"][href=\"${resolved}\"]`)) {\n continue;\n }\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = resolved;\n link.dataset.dxosPluginId = manifest.id;\n document.head.appendChild(link);\n }\n });\n\nconst loadFromManifest = (\n manifestUrl: string,\n cache: PluginAssetCache.Cache,\n): Effect.Effect<{ plugin: Plugin.Plugin; manifest: PluginManifest.ResolvedManifest }, RemotePluginLoadError> =>\n Effect.gen(function* () {\n log.info('loading remote plugin', { manifestUrl });\n const manifest = yield* PluginManifest.fetchManifest(manifestUrl).pipe(\n Effect.mapError(\n (cause) => new RemotePluginLoadError({ context: { locator: manifestUrl, reason: 'manifest-error' }, cause }),\n ),\n );\n const wrapCacheError = Effect.mapError(\n (cause: PluginAssetCache.PluginAssetCacheError) =>\n new RemotePluginLoadError({ context: { locator: manifestUrl, reason: 'cache-error' }, cause }),\n );\n // Dev-mode manifests (served by `vite dev` via composerPlugin) skip the offline\n // cache: chunks resolve on demand through the dev server, the asset list isn't\n // enumerable up-front, and CSS arrives via runtime <style> injection rather than\n // static <link> tags.\n if (!manifest.dev) {\n // Cache the manifest URL alongside its declared assets. Without it, `preload` on a\n // subsequent reload would fetch the manifest from the network — and fail when the\n // plugin's host is offline, dropping the plugin from the runtime.\n const cachedUrls =\n manifest.assetUrls.indexOf(manifestUrl) === -1 ? [manifestUrl, ...manifest.assetUrls] : manifest.assetUrls;\n yield* cache.cache(manifest.id, cachedUrls).pipe(wrapCacheError);\n }\n const entryUrl = manifest.dev\n ? manifest.entryUrl\n : yield* cache.resolve(manifest.id, manifest.entryUrl).pipe(wrapCacheError);\n const mod = yield* Effect.tryPromise({\n try: () => import(/* @vite-ignore */ entryUrl),\n catch: (cause) =>\n new RemotePluginLoadError({ context: { locator: manifestUrl, reason: 'import-failed' }, cause }),\n });\n const plugin = normalizePluginExport(mod);\n if (!plugin.meta.id || !plugin.meta.name) {\n return yield* Effect.fail(\n new RemotePluginLoadError({ context: { locator: manifestUrl, reason: 'meta-missing' } }),\n );\n }\n if (plugin.meta.id !== manifest.id) {\n return yield* Effect.fail(\n new RemotePluginLoadError({\n context: {\n locator: manifestUrl,\n reason: 'meta-mismatch',\n metaId: plugin.meta.id,\n manifestId: manifest.id,\n },\n }),\n );\n }\n // Append stylesheets only after the entry imports cleanly and meta validation\n // passes. If we did this earlier and the import or meta checks failed, the\n // `<link>` tags would leak into the host DOM with no plugin to own their\n // teardown — `uninstall` only runs for plugins the manager actually accepted.\n // In dev mode, Vite injects styles at runtime via the module graph, so static\n // <link> tags would duplicate (or 404, since CSS chunks aren't pre-built).\n if (!manifest.dev) {\n yield* loadStylesheets(manifest, cache).pipe(wrapCacheError);\n }\n return { plugin, manifest };\n });\n\n/**\n * Preloads previously persisted remote plugins from storage. Per-entry failures\n * are logged and swallowed — the returned effect always succeeds with whichever\n * plugins loaded cleanly, so a single bad entry can't block the host's startup.\n */\nexport const preload = (options: PreloadOptions = {}): Effect.Effect<Plugin.Plugin[], never> =>\n Effect.gen(function* () {\n const storage = options.storage ?? defaultStorage();\n const key = options.key ?? DEFAULT_KEY;\n const cache = options.cache ?? PluginAssetCache.noop();\n const onPluginLoaded = options.onPluginLoaded;\n\n const entries = getPersistedRemotePlugins(storage, key);\n if (entries.length === 0) {\n return [];\n }\n log.info('preloading remote plugins', { count: entries.length });\n const total = entries.length;\n let loaded = 0;\n const results = yield* Effect.all(\n entries.map((entry) =>\n loadFromManifest(entry.url, cache).pipe(\n Effect.tapError((error) => Effect.sync(() => log.warn('failed to preload remote plugin', { entry, error }))),\n Effect.option,\n // Tick the progress hook on both success and recoverable failure so\n // the counter monotonically reaches `total`. The host-supplied\n // callback is best-effort: any synchronous throw flows through\n // `Effect.try` and gets logged + ignored so a buggy hook can't\n // derail the preload.\n Effect.tap(() =>\n Effect.sync(() => {\n loaded += 1;\n }).pipe(\n Effect.andThen(Effect.try(() => onPluginLoaded?.(loaded, total))),\n Effect.tapError((error) => Effect.sync(() => log.warn('onPluginLoaded threw', { loaded, total, error }))),\n Effect.ignore,\n ),\n ),\n ),\n ),\n { concurrency: 'unbounded' },\n );\n return results.flatMap((result) =>\n Option.match(result, {\n onNone: () => [],\n onSome: ({ plugin }) => [plugin],\n }),\n );\n });\n\n/**\n * Creates a plugin loader that resolves built-in plugins by ID or loads remote plugins from URLs.\n *\n * Remote URLs must point at a plugin manifest (`plugin.json`). The loader fetches the manifest,\n * eagerly persists every declared asset via the configured `PluginAssetCache`, then dynamic-imports\n * the entry module.\n */\nexport const make = (builtinPlugins: Plugin.Plugin[], options: Options = {}) => {\n const storage = options.storage ?? defaultStorage();\n const key = options.key ?? DEFAULT_KEY;\n const cache = options.cache ?? PluginAssetCache.noop();\n\n return (locator: string): Effect.Effect<{ plugin: Plugin.Plugin; dev?: boolean }, RemotePluginLoadError> =>\n Effect.gen(function* () {\n const builtin = builtinPlugins.find((plugin) => plugin.meta.id === locator);\n if (builtin) {\n return { plugin: builtin };\n }\n if (!isUrl(locator)) {\n return yield* Effect.fail(new RemotePluginLoadError({ context: { locator, reason: 'invalid-locator' } }));\n }\n const { plugin, manifest } = yield* loadFromManifest(locator, cache);\n // Production manifests can't collide with a builtin id — that would make\n // the registered plugin permanently inaccessible. Dev manifests are\n // allowed to collide because the manager shadow primitive handles the\n // overlap (dev plugin takes the id slot for the session, original is\n // restored on uninstall or page reload).\n if (!manifest.dev) {\n const duplicate = builtinPlugins.find((existing) => existing.meta.id === plugin.meta.id);\n if (duplicate) {\n return yield* Effect.fail(\n new RemotePluginLoadError({ context: { locator, reason: 'duplicate-id', id: plugin.meta.id } }),\n );\n }\n persistRemotePlugin(storage, key, { id: plugin.meta.id, url: locator });\n }\n return { plugin, dev: manifest.dev };\n });\n};\n\n/**\n * Removes a previously installed remote plugin: drops the persisted entry, evicts cached\n * assets, and removes any stylesheet `<link>` tags that {@link loadFromManifest} appended.\n *\n * Cache eviction failures are logged and swallowed — the persisted entry has already been\n * dropped so the user-visible state is consistent regardless of whether the platform\n * cache cooperated.\n */\nexport const uninstall = (pluginId: string, options: Options = {}): Effect.Effect<void, never> =>\n Effect.gen(function* () {\n const storage = options.storage ?? defaultStorage();\n const key = options.key ?? DEFAULT_KEY;\n const cache = options.cache ?? PluginAssetCache.noop();\n\n removePersistedRemotePlugin(storage, key, pluginId);\n if (typeof document !== 'undefined') {\n document.querySelectorAll(`link[data-dxos-plugin-id=\"${pluginId}\"]`).forEach((node) => node.remove());\n }\n yield* cache.evict(pluginId).pipe(\n Effect.tapError((error) => Effect.sync(() => log.warn('failed to evict plugin assets', { pluginId, error }))),\n Effect.ignore,\n );\n });\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { BaseError } from '@dxos/errors';\n\n/**\n * Tagged error for cache operations. Construction sites supply `context.operation`\n * (one of `'cache' | 'evict' | 'resolve' | 'list'`) and `context.pluginId` so\n * downstream handlers can route on the failed call without scanning the message.\n */\nexport class PluginAssetCacheError extends BaseError.extend(\n 'PluginAssetCacheError',\n 'Plugin asset cache operation failed',\n) {}\n\n/**\n * Per-platform offline cache for third-party plugin assets.\n *\n * Implementations live alongside their platform glue (composer-app's\n * `asset-cache/{tauri,service-worker}.ts`); the no-op default is for tests\n * and unsupported environments.\n */\nexport interface Cache {\n /**\n * Persist all listed URLs under the namespace of `pluginId`. Idempotent.\n * The order of `urls` is significant — the first entry is treated as the entry module.\n */\n cache(pluginId: string, urls: readonly string[]): Effect.Effect<void, PluginAssetCacheError>;\n\n /**\n * Drop all assets for a plugin (uninstall).\n */\n evict(pluginId: string): Effect.Effect<void, PluginAssetCacheError>;\n\n /**\n * Resolves a plugin asset URL to a platform-specific cached URL when one is available.\n * Returns the original URL when no cached copy exists or the platform serves cached\n * responses transparently (e.g. service worker fetch interception on web).\n */\n resolve(pluginId: string, url: string): Effect.Effect<string, PluginAssetCacheError>;\n\n /**\n * List currently cached plugin ids (diagnostic).\n */\n list(): Effect.Effect<readonly string[], PluginAssetCacheError>;\n}\n\n/**\n * No-op implementation. Used when no platform cache is registered (tests, unsupported environments).\n * Plugins still load — they just have no offline guarantee.\n */\nexport const noop = (): Cache => ({\n cache: () => Effect.void,\n evict: () => Effect.void,\n resolve: (_pluginId, url) => Effect.succeed(url),\n list: () => Effect.succeed([] as readonly string[]),\n});\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as FetchHttpClient from '@effect/platform/FetchHttpClient';\nimport * as HttpClient from '@effect/platform/HttpClient';\nimport * as HttpClientRequest from '@effect/platform/HttpClientRequest';\nimport * as HttpClientResponse from '@effect/platform/HttpClientResponse';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { BaseError } from '@dxos/errors';\nimport { PLUGIN_ENTRY_FILENAME } from '@dxos/protocols';\n\n/**\n * Default port the Vite plugin (`composerPlugin`) binds the dev server to.\n *\n * Shared single source of truth — `composerPlugin` reads it as the default\n * port, and the host's \"Load Dev Plugin\" affordance pre-fills the manifest URL\n * with `http://localhost:${PLUGIN_DEV_SERVER_PORT}/manifest.json`. Lives in\n * app-framework rather than `@dxos/protocols` because the constant is a\n * client-side convention (host loader + Vite plugin) rather than a wire-level\n * protocol.\n */\nexport const PLUGIN_DEV_SERVER_PORT = 3967;\n\n/**\n * Tagged error for manifest fetch / parse failures. Construction sites set\n * `context.manifestUrl` and `context.reason` (one of `'fetch-failed' |\n * 'http-error' | 'parse-failed' | 'invalid'`) so handlers can route on the\n * specific failure mode.\n */\nexport class PluginManifestError extends BaseError.extend('PluginManifestError', 'Plugin manifest is invalid') {}\n\n/**\n * Schema for a third-party plugin manifest.\n *\n * Production manifests are published as a sibling of the plugin's entry module\n * ({@link PLUGIN_ENTRY_FILENAME}) and advertise every file the plugin needs at\n * runtime so the host can eagerly cache them for offline use.\n *\n * Dev manifests (served by `vite dev` via {@link composerPlugin}) set `devEntry`\n * to point at the unbundled source entry. The host's loader treats the presence\n * of `devEntry` as the dev-mode signal: it imports the entry directly from the\n * dev server, skips eager asset caching, and skips static stylesheet injection\n * (Vite handles CSS via runtime `<style>` injection during HMR). `assets` is not\n * required to enumerate every file in dev mode — chunks and styles flow through\n * the dev server on demand.\n */\nexport const Manifest = Schema.Struct({\n id: Schema.String,\n name: Schema.String,\n version: Schema.String,\n assets: Schema.Array(Schema.String),\n devEntry: Schema.String.pipe(Schema.optional),\n});\n\nexport type Manifest = Schema.Schema.Type<typeof Manifest>;\n\n/**\n * Resolved manifest with all asset paths converted to absolute URLs.\n *\n * `dev` reflects whether the source manifest declared a `devEntry`. Loaders branch\n * on this to skip offline caching and stylesheet injection — both are no-ops (or\n * actively wrong) when the plugin is being served by a Vite dev server.\n */\nexport type ResolvedManifest = {\n id: string;\n name: string;\n version: string;\n entryUrl: string;\n assetUrls: readonly string[];\n dev: boolean;\n};\n\n/**\n * Resolves a parsed manifest's relative asset paths against the manifest's URL.\n * In dev mode the entry comes from `devEntry`; otherwise it's the canonical\n * {@link PLUGIN_ENTRY_FILENAME} sitting next to the manifest.\n */\nconst resolve = (manifestUrl: string, manifest: Manifest): ResolvedManifest => {\n const dev = manifest.devEntry !== undefined;\n return {\n id: manifest.id,\n name: manifest.name,\n version: manifest.version,\n entryUrl: new URL(dev ? manifest.devEntry! : PLUGIN_ENTRY_FILENAME, manifestUrl).toString(),\n assetUrls: manifest.assets.map((asset) => new URL(asset, manifestUrl).toString()),\n dev,\n };\n};\n\n/**\n * Synchronous decode + validate + resolve for an in-memory manifest payload. Used\n * by tests and tooling that have the manifest body already loaded; the runtime\n * path goes through {@link fetchManifest}.\n */\nexport const parse = (manifestUrl: string, payload: unknown): ResolvedManifest => {\n const manifest = Schema.decodeUnknownSync(Manifest)(payload);\n if (manifest.devEntry === undefined && !manifest.assets.includes(PLUGIN_ENTRY_FILENAME)) {\n throw new Error(`Manifest at ${manifestUrl} does not list ${PLUGIN_ENTRY_FILENAME} in assets.`);\n }\n return resolve(manifestUrl, manifest);\n};\n\n/**\n * Fetches and parses a manifest from the given URL via Effect's HTTP client and\n * Schema-driven JSON decoding. All failure modes surface as a single tagged\n * {@link PluginManifestError}; callers route on `error.context.reason`.\n */\nexport const fetchManifest = (manifestUrl: string): Effect.Effect<ResolvedManifest, PluginManifestError> =>\n Effect.gen(function* () {\n const response = yield* HttpClientRequest.get(manifestUrl).pipe(\n HttpClient.execute,\n Effect.mapError((cause) => new PluginManifestError({ context: { manifestUrl, reason: 'fetch-failed' }, cause })),\n );\n if (response.status >= 400) {\n return yield* Effect.fail(\n new PluginManifestError({ context: { manifestUrl, reason: 'http-error', status: response.status } }),\n );\n }\n const manifest = yield* HttpClientResponse.schemaBodyJson(Manifest)(response).pipe(\n Effect.mapError((cause) => new PluginManifestError({ context: { manifestUrl, reason: 'parse-failed' }, cause })),\n );\n if (manifest.devEntry === undefined && !manifest.assets.includes(PLUGIN_ENTRY_FILENAME)) {\n return yield* Effect.fail(\n new PluginManifestError({\n context: { manifestUrl, reason: 'invalid' },\n cause: `assets does not include ${PLUGIN_ENTRY_FILENAME}`,\n }),\n );\n }\n return resolve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AAA,KAAA;UAEjG;QACA8C,CAAAA,CAAAA;;0BAA6DnD,SAAAA,KAAAA;QAAQ,IAAA,OAAA,KAAA;QACvE,KAAA;MACA,CAAA;;WAAiBoD;MAAkB;MACrC,KAAA,SAAA;IACF;EAEF,CAAA;;AAWI,IAAM/D,YAAcA,CAAAA,UAAOP,UAAAA,CAAAA,MAAAA,YAAAA,aAAAA;AAC3B,QAAM8C,UAAQ3B,QAAQ2B,WAASQ,eAAiBC;AAEhDgB,QAAAA,MAAAA,QAAAA,OAAAA;AACA,QAAI,QAAOtC,QAAAA,SAA0B,KAAA;8BAC1BuC,SAAkB,KAAA,QAAA;AAC7B,MAAA,OAAA,aAAA,aAAA;AACA,aAAaC,iBAAgBb,6BACAE,QAAOY,IAAK,EAAA,QAAUC,CAAAA,SAAK,KAAA,OAAA,CAAA;;eAA6ChE,MAAAA,QAAAA,EAAAA,KAAAA,iBAAAA,CAAAA,UAAAA,aAAAA,MAAAA,IAAAA,KAAAA,iCAAAA;IAAM;IAG1G;;;",
6
+ "names": ["Effect", "Option", "BaseError", "log", "Effect", "BaseError", "PluginAssetCacheError", "extend", "noop", "cache", "void", "evict", "resolve", "_pluginId", "url", "succeed", "list", "FetchHttpClient", "HttpClient", "HttpClientRequest", "HttpClientResponse", "Effect", "Schema", "BaseError", "PLUGIN_ENTRY_FILENAME", "PLUGIN_DEV_SERVER_PORT", "PluginManifestError", "extend", "Manifest", "Struct", "id", "String", "name", "version", "assets", "Array", "devEntry", "pipe", "optional", "resolve", "manifestUrl", "manifest", "dev", "undefined", "entryUrl", "URL", "toString", "assetUrls", "map", "asset", "parse", "payload", "decodeUnknownSync", "includes", "Error", "fetchManifest", "gen", "response", "get", "execute", "mapError", "cause", "context", "reason", "status", "fail", "schemaBodyJson", "scoped", "provide", "layer", "DEFAULT_KEY", "defaultStorage", "BaseError", "value", "localStorage", "getPersistedRemotePlugins", "storage", "key", "get", "parsed", "entries", "error", "log", "entry", "pluginId", "url", "URL", "hostname", "locator", "options", "index", "findIndex", "version", "id", "find", "normalizePluginExport", "mod", "exported", "Plugin", "result", "resolved", "resolve", "manifest", "document", "querySelector", "link", "href", "dataset", "head", "loadFromManifest", "manifestUrl", "context", "reason", "cause", "wrapCacheError", "assetUrls", "cache", "entryUrl", "try", "catch", "RemotePluginLoadError", "plugin", "metaId", "manifestId", "PluginAssetCache", "noop", "onPluginLoaded", "info", "total", "results", "pipe", "andThen", "Effect", "loaded", "flatMap", "onSome", "gen", "builtin", "duplicate", "persistRemotePlugin", "dev", "removePersistedRemotePlugin", "querySelectorAll", "evict", "sync", "warn"]
7
+ }
@@ -0,0 +1,8 @@
1
+ // src/context.ts
2
+ import { createContext } from "@dxos/web-context";
3
+ var PluginManagerContext = createContext("org.dxos.app-framework.plugin-manager");
4
+
5
+ export {
6
+ PluginManagerContext
7
+ };
8
+ //# sourceMappingURL=chunk-FJ4765WW.mjs.map