@mountaya/studio 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (521) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/LICENCE.fr.txt +280 -0
  3. package/LICENSE.txt +262 -0
  4. package/README.md +917 -2
  5. package/dist/agent/index.cjs +2600 -0
  6. package/dist/agent/index.cjs.map +1 -0
  7. package/dist/agent/index.d.cts +1237 -0
  8. package/dist/agent/index.d.ts +1237 -0
  9. package/dist/agent/index.js +2581 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/chunk-3Oi_Zrtm.js +9 -0
  12. package/dist/chunk-3Oi_Zrtm.js.map +1 -0
  13. package/dist/chunk-B18OPIu_.js +6 -0
  14. package/dist/chunk-B18OPIu_.js.map +1 -0
  15. package/dist/chunk-B5Uz3Qct.cjs +15 -0
  16. package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
  17. package/dist/chunk-BBEJwkd3.d.cts +839 -0
  18. package/dist/chunk-BIEc_SkR.cjs +29 -0
  19. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  20. package/dist/chunk-BKMFOe-N.js +171 -0
  21. package/dist/chunk-BKMFOe-N.js.map +1 -0
  22. package/dist/chunk-BP4uy7E1.d.ts +11583 -0
  23. package/dist/chunk-BSHTsFiB.js +1403 -0
  24. package/dist/chunk-BSHTsFiB.js.map +1 -0
  25. package/dist/chunk-BTUUABGI.js +17 -0
  26. package/dist/chunk-BTUUABGI.js.map +1 -0
  27. package/dist/chunk-BaPiaz5X.cjs +115 -0
  28. package/dist/chunk-BaPiaz5X.cjs.map +1 -0
  29. package/dist/chunk-BeCVpkYr.cjs +542 -0
  30. package/dist/chunk-BeCVpkYr.cjs.map +1 -0
  31. package/dist/chunk-BgngsvK8.cjs +6202 -0
  32. package/dist/chunk-BgngsvK8.cjs.map +1 -0
  33. package/dist/chunk-BhInd7CJ.d.cts +253 -0
  34. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  35. package/dist/chunk-By9ZnkVI.js +60 -0
  36. package/dist/chunk-By9ZnkVI.js.map +1 -0
  37. package/dist/chunk-BzqPhxsz.cjs +367 -0
  38. package/dist/chunk-BzqPhxsz.cjs.map +1 -0
  39. package/dist/chunk-C2mMX81q.d.ts +443 -0
  40. package/dist/chunk-C2rr9Q0V.cjs +1402 -0
  41. package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
  42. package/dist/chunk-CDJCbwIQ.d.cts +78 -0
  43. package/dist/chunk-CLGvBOVH.d.cts +1654 -0
  44. package/dist/chunk-COdw1dc6.d.ts +525 -0
  45. package/dist/chunk-CQCJnT2i.d.ts +511 -0
  46. package/dist/chunk-CSyHY67q.cjs +353 -0
  47. package/dist/chunk-CSyHY67q.cjs.map +1 -0
  48. package/dist/chunk-CiK1Iqrv.js +950 -0
  49. package/dist/chunk-CiK1Iqrv.js.map +1 -0
  50. package/dist/chunk-CmJBgSwZ.cjs +24 -0
  51. package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
  52. package/dist/chunk-CnrsRK2u.cjs +83 -0
  53. package/dist/chunk-CnrsRK2u.cjs.map +1 -0
  54. package/dist/chunk-Co782_9r.js +326 -0
  55. package/dist/chunk-Co782_9r.js.map +1 -0
  56. package/dist/chunk-Csr3KDpZ.cjs +32 -0
  57. package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
  58. package/dist/chunk-CwkmccXv.js +89 -0
  59. package/dist/chunk-CwkmccXv.js.map +1 -0
  60. package/dist/chunk-D0Q4iL9B.cjs +255 -0
  61. package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
  62. package/dist/chunk-DFwiSzUS.cjs +72 -0
  63. package/dist/chunk-DFwiSzUS.cjs.map +1 -0
  64. package/dist/chunk-DIFayl2P.d.cts +443 -0
  65. package/dist/chunk-DIGF58ux.d.cts +525 -0
  66. package/dist/chunk-DKuuuld5.js +101 -0
  67. package/dist/chunk-DKuuuld5.js.map +1 -0
  68. package/dist/chunk-DMePkFEo.js +5054 -0
  69. package/dist/chunk-DMePkFEo.js.map +1 -0
  70. package/dist/chunk-DO5SIBgu.js +305 -0
  71. package/dist/chunk-DO5SIBgu.js.map +1 -0
  72. package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
  73. package/dist/chunk-DThaaNeb.d.cts +15 -0
  74. package/dist/chunk-DThaaNeb.d.ts +15 -0
  75. package/dist/chunk-DUQzjUJy.d.ts +78 -0
  76. package/dist/chunk-DX37IPhV.cjs +1903 -0
  77. package/dist/chunk-DX37IPhV.cjs.map +1 -0
  78. package/dist/chunk-Damps5Tk.cjs +155 -0
  79. package/dist/chunk-Damps5Tk.cjs.map +1 -0
  80. package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
  81. package/dist/chunk-De0vAASv.d.ts +253 -0
  82. package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
  83. package/dist/chunk-DjEvqvPA.cjs +43 -0
  84. package/dist/chunk-DjEvqvPA.cjs.map +1 -0
  85. package/dist/chunk-DkwDzwvu.d.cts +121 -0
  86. package/dist/chunk-DkwDzwvu.d.ts +121 -0
  87. package/dist/chunk-Dmszv9If.js +71 -0
  88. package/dist/chunk-Dmszv9If.js.map +1 -0
  89. package/dist/chunk-Dp_ftNWY.d.cts +511 -0
  90. package/dist/chunk-DsHQySz0.js +31 -0
  91. package/dist/chunk-DsHQySz0.js.map +1 -0
  92. package/dist/chunk-DwoUyHHh.js +281 -0
  93. package/dist/chunk-DwoUyHHh.js.map +1 -0
  94. package/dist/chunk-IaIDQflj.d.cts +2315 -0
  95. package/dist/chunk-IaIDQflj.d.ts +2315 -0
  96. package/dist/chunk-cVXLsZfL.d.ts +839 -0
  97. package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
  98. package/dist/chunk-nJQxbOwQ.cjs +8962 -0
  99. package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
  100. package/dist/chunk-o9jaxhCO.js +8852 -0
  101. package/dist/chunk-o9jaxhCO.js.map +1 -0
  102. package/dist/chunk-p-Tt_Lwz.js +14 -0
  103. package/dist/chunk-p-Tt_Lwz.js.map +1 -0
  104. package/dist/engines/index.cjs +2091 -0
  105. package/dist/engines/index.cjs.map +1 -0
  106. package/dist/engines/index.d.cts +2176 -0
  107. package/dist/engines/index.d.ts +2176 -0
  108. package/dist/engines/index.js +2075 -0
  109. package/dist/engines/index.js.map +1 -0
  110. package/dist/handlers/index.cjs +53 -0
  111. package/dist/handlers/index.cjs.map +1 -0
  112. package/dist/handlers/index.d.cts +403 -0
  113. package/dist/handlers/index.d.ts +403 -0
  114. package/dist/handlers/index.js +33 -0
  115. package/dist/handlers/index.js.map +1 -0
  116. package/dist/index.cjs +3511 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.cts +8 -0
  119. package/dist/index.d.ts +8 -0
  120. package/dist/index.js +3033 -0
  121. package/dist/index.js.map +1 -0
  122. package/dist/plugins/index.cjs +510 -0
  123. package/dist/plugins/index.cjs.map +1 -0
  124. package/dist/plugins/index.d.cts +296 -0
  125. package/dist/plugins/index.d.ts +296 -0
  126. package/dist/plugins/index.js +489 -0
  127. package/dist/plugins/index.js.map +1 -0
  128. package/dist/seams/index.cjs +89 -0
  129. package/dist/seams/index.cjs.map +1 -0
  130. package/dist/seams/index.d.cts +452 -0
  131. package/dist/seams/index.d.ts +452 -0
  132. package/dist/seams/index.js +49 -0
  133. package/dist/seams/index.js.map +1 -0
  134. package/dist/strings/fr/index.cjs +2135 -0
  135. package/dist/strings/fr/index.cjs.map +1 -0
  136. package/dist/strings/fr/index.d.cts +17 -0
  137. package/dist/strings/fr/index.d.ts +17 -0
  138. package/dist/strings/fr/index.js +2130 -0
  139. package/dist/strings/fr/index.js.map +1 -0
  140. package/dist/strings/index.cjs +2384 -0
  141. package/dist/strings/index.cjs.map +1 -0
  142. package/dist/strings/index.d.cts +3 -0
  143. package/dist/strings/index.d.ts +3 -0
  144. package/dist/strings/index.js +2353 -0
  145. package/dist/strings/index.js.map +1 -0
  146. package/dist/testing/index.cjs +230 -0
  147. package/dist/testing/index.cjs.map +1 -0
  148. package/dist/testing/index.d.cts +246 -0
  149. package/dist/testing/index.d.ts +246 -0
  150. package/dist/testing/index.js +219 -0
  151. package/dist/testing/index.js.map +1 -0
  152. package/dist/time/index.cjs +28 -0
  153. package/dist/time/index.cjs.map +1 -0
  154. package/dist/time/index.d.cts +41 -0
  155. package/dist/time/index.d.ts +41 -0
  156. package/dist/time/index.js +23 -0
  157. package/dist/time/index.js.map +1 -0
  158. package/package.json +224 -4
  159. package/src/agent/engines/agentThreads.ts +1601 -0
  160. package/src/agent/engines/directorChat.ts +500 -0
  161. package/src/agent/index.ts +67 -0
  162. package/src/agent/rules/agentEditLock.ts +115 -0
  163. package/src/agent/rules/agentErrorCopy.ts +44 -0
  164. package/src/agent/rules/copilotOrganization.ts +36 -0
  165. package/src/agent/rules/playbook.gen.ts +444 -0
  166. package/src/agent/rules/router.ts +518 -0
  167. package/src/agent/rules/stateDelta.ts +29 -0
  168. package/src/agent/rules/studioRouter.ts +123 -0
  169. package/src/agent/rules/surfaces.gen.ts +633 -0
  170. package/src/agent/rules/threadsUrl.ts +48 -0
  171. package/src/agent/rules/transcriptObserver.ts +90 -0
  172. package/src/agent/stores/agentThreads.ts +451 -0
  173. package/src/bus/contracts/noData.ts +18 -0
  174. package/src/bus/contracts/shared.ts +172 -0
  175. package/src/bus/contracts/studioTools.ts +224 -0
  176. package/src/bus/rules/bus.ts +857 -0
  177. package/src/bus/rules/confirmation.ts +22 -0
  178. package/src/bus/rules/defineRegistry.ts +24 -0
  179. package/src/bus/rules/errors.ts +401 -0
  180. package/src/bus/rules/handlerErrors.ts +103 -0
  181. package/src/bus/rules/handlerRegistry.ts +627 -0
  182. package/src/bus/rules/inputSchema.ts +232 -0
  183. package/src/bus/rules/invalidInput.ts +441 -0
  184. package/src/bus/rules/lateBoundTools.ts +100 -0
  185. package/src/bus/rules/studioRegistry.ts +324 -0
  186. package/src/bus/rules/studioToolBus.ts +73 -0
  187. package/src/bus/rules/types.ts +804 -0
  188. package/src/chrome/contracts/alert.ts +42 -0
  189. package/src/chrome/contracts/itinerary.ts +26 -0
  190. package/src/chrome/contracts/map.ts +23 -0
  191. package/src/chrome/contracts/overlay.ts +46 -0
  192. package/src/chrome/contracts/panel.ts +29 -0
  193. package/src/chrome/contracts/question.ts +52 -0
  194. package/src/chrome/contracts/selection.ts +26 -0
  195. package/src/chrome/contracts/sidenav.ts +23 -0
  196. package/src/chrome/contracts/snapshot.ts +319 -0
  197. package/src/chrome/contracts/state.ts +22 -0
  198. package/src/chrome/contracts/tabs.ts +56 -0
  199. package/src/chrome/handlers/alert.ts +91 -0
  200. package/src/chrome/handlers/introspection.ts +180 -0
  201. package/src/chrome/handlers/panels.ts +42 -0
  202. package/src/chrome/handlers/question.ts +24 -0
  203. package/src/chrome/handlers/sidenav.ts +116 -0
  204. package/src/chrome/handlers/snapshot.ts +451 -0
  205. package/src/chrome/handlers/stateDelta.ts +125 -0
  206. package/src/chrome/handlers/tabs.ts +143 -0
  207. package/src/chrome/handlers/timestamp.ts +19 -0
  208. package/src/chrome/rules/agentSelectors.ts +210 -0
  209. package/src/chrome/rules/mapAlert.ts +13 -0
  210. package/src/chrome/rules/question.ts +25 -0
  211. package/src/chrome/rules/tabs.ts +13 -0
  212. package/src/chrome/stores/activeDraftSession.ts +134 -0
  213. package/src/chrome/stores/chrome.ts +527 -0
  214. package/src/chrome/stores/uiStore.ts +575 -0
  215. package/src/collab/contracts/collab.ts +261 -0
  216. package/src/collab/handlers/collab.ts +468 -0
  217. package/src/collab/rules/toolNames.ts +33 -0
  218. package/src/collab/stores/collab.ts +899 -0
  219. package/src/collections/contracts/collection.ts +182 -0
  220. package/src/collections/handlers/collectionAttach.ts +141 -0
  221. package/src/collections/handlers/collections.ts +499 -0
  222. package/src/collections/handlers/heldCollection.ts +42 -0
  223. package/src/collections/handlers/restCollections.ts +386 -0
  224. package/src/collections/rules/collections.ts +138 -0
  225. package/src/collections/rules/entityCollections.ts +53 -0
  226. package/src/collections/stores/collections.ts +133 -0
  227. package/src/data/contracts/data.ts +233 -0
  228. package/src/data/contracts/itinerary.ts +71 -0
  229. package/src/data/handlers/activityResolve.ts +76 -0
  230. package/src/data/handlers/data.ts +200 -0
  231. package/src/data/handlers/graphql.ts +26 -0
  232. package/src/data/handlers/mutationSink.ts +1577 -0
  233. package/src/data/handlers/profile.ts +83 -0
  234. package/src/data/handlers/writeThrough.ts +417 -0
  235. package/src/data/rules/cache.ts +181 -0
  236. package/src/data/rules/dataTypes.ts +40 -0
  237. package/src/data/rules/keys.ts +106 -0
  238. package/src/data/rules/persistence.ts +1058 -0
  239. package/src/data/rules/requestBody.ts +43 -0
  240. package/src/data/rules/restErrors.ts +354 -0
  241. package/src/data/rules/sessionSurface.ts +156 -0
  242. package/src/data/rules/toolResultData.ts +73 -0
  243. package/src/data/rules/uuid.ts +24 -0
  244. package/src/edit/contracts/edit.ts +37 -0
  245. package/src/edit/contracts/itinerary.ts +57 -0
  246. package/src/edit/handlers/draftCommit.ts +257 -0
  247. package/src/edit/handlers/editDiscard.ts +34 -0
  248. package/src/edit/handlers/editLock.ts +949 -0
  249. package/src/edit/handlers/editor.ts +203 -0
  250. package/src/edit/handlers/formUnsaved.ts +24 -0
  251. package/src/edit/rules/draftMetadata.ts +117 -0
  252. package/src/edit/rules/editKeyboard.ts +222 -0
  253. package/src/edit/rules/editShortcuts.ts +102 -0
  254. package/src/edit/rules/editTooltip.ts +174 -0
  255. package/src/edit/rules/editorTaken.ts +49 -0
  256. package/src/edit/rules/history.ts +26 -0
  257. package/src/edit/rules/unsavedWork.ts +60 -0
  258. package/src/edit/stores/editorReservation.ts +70 -0
  259. package/src/edit/stores/formsUnsaved.ts +54 -0
  260. package/src/embed/contracts/embed.ts +48 -0
  261. package/src/embed/engines/embedFraming.ts +1329 -0
  262. package/src/embed/engines/embedReady.ts +353 -0
  263. package/src/embed/engines/framingPageSession.ts +169 -0
  264. package/src/embed/handlers/embed.ts +130 -0
  265. package/src/embed/rules/allowedDomains.ts +71 -0
  266. package/src/embed/rules/bridgeMessages.ts +224 -0
  267. package/src/embed/rules/defaults.ts +173 -0
  268. package/src/embed/rules/displaySeed.ts +115 -0
  269. package/src/embed/rules/embedAllowlist.ts +146 -0
  270. package/src/embed/rules/embedConstraints.ts +215 -0
  271. package/src/embed/rules/embedElements.ts +277 -0
  272. package/src/embed/rules/embedSectionFields.ts +126 -0
  273. package/src/embed/rules/embedSecurity.ts +116 -0
  274. package/src/embed/rules/fieldDependencies.ts +89 -0
  275. package/src/embed/rules/fieldOptions.ts +138 -0
  276. package/src/embed/rules/layerOptions.ts +161 -0
  277. package/src/embed/rules/readyProtocol.ts +66 -0
  278. package/src/embed/rules/safetyRules.ts +215 -0
  279. package/src/embed/rules/snippet.ts +531 -0
  280. package/src/embed/rules/tableCode.ts +270 -0
  281. package/src/embed/stores/embed.ts +60 -0
  282. package/src/embed/stores/embedContent.ts +77 -0
  283. package/src/engines/index.ts +81 -0
  284. package/src/handlers/index.ts +66 -0
  285. package/src/index.ts +1065 -0
  286. package/src/itinerary/contracts/itinerary.ts +705 -0
  287. package/src/itinerary/engines/itineraryPace.ts +612 -0
  288. package/src/itinerary/engines/profileMarker.ts +238 -0
  289. package/src/itinerary/handlers/importStaging.ts +352 -0
  290. package/src/itinerary/handlers/itinerary.ts +572 -0
  291. package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
  292. package/src/itinerary/handlers/itineraryExport.ts +117 -0
  293. package/src/itinerary/handlers/itineraryImport.ts +783 -0
  294. package/src/itinerary/handlers/itineraryPublish.ts +118 -0
  295. package/src/itinerary/handlers/itinerarySelection.ts +354 -0
  296. package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
  297. package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
  298. package/src/itinerary/handlers/publicationScope.ts +118 -0
  299. package/src/itinerary/handlers/restItineraries.ts +752 -0
  300. package/src/itinerary/handlers/restItineraryExport.ts +70 -0
  301. package/src/itinerary/handlers/restItineraryImport.ts +311 -0
  302. package/src/itinerary/handlers/restItineraryPace.ts +87 -0
  303. package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
  304. package/src/itinerary/handlers/suggestParams.ts +379 -0
  305. package/src/itinerary/handlers/suggestStaging.ts +363 -0
  306. package/src/itinerary/handlers/surfaceOpen.ts +389 -0
  307. package/src/itinerary/rules/activity.ts +139 -0
  308. package/src/itinerary/rules/analysis.ts +42 -0
  309. package/src/itinerary/rules/ceiling.ts +49 -0
  310. package/src/itinerary/rules/createFlow.ts +107 -0
  311. package/src/itinerary/rules/densify.ts +440 -0
  312. package/src/itinerary/rules/draftSurface.ts +219 -0
  313. package/src/itinerary/rules/editorView.ts +83 -0
  314. package/src/itinerary/rules/export.ts +159 -0
  315. package/src/itinerary/rules/friendlyName.ts +77 -0
  316. package/src/itinerary/rules/import.ts +1050 -0
  317. package/src/itinerary/rules/importFiles.ts +140 -0
  318. package/src/itinerary/rules/importTotals.ts +77 -0
  319. package/src/itinerary/rules/liveSegment.ts +712 -0
  320. package/src/itinerary/rules/lngLat.ts +17 -0
  321. package/src/itinerary/rules/mapSync.ts +100 -0
  322. package/src/itinerary/rules/previewRender.ts +416 -0
  323. package/src/itinerary/rules/profileReadout.ts +216 -0
  324. package/src/itinerary/rules/routing.ts +707 -0
  325. package/src/itinerary/rules/suggest.ts +522 -0
  326. package/src/itinerary/rules/suggestionPreview.ts +119 -0
  327. package/src/itinerary/rules/view.ts +61 -0
  328. package/src/itinerary/stores/importSession.ts +319 -0
  329. package/src/itinerary/stores/itinerary.ts +331 -0
  330. package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
  331. package/src/itinerary/stores/sessionIdentity.ts +43 -0
  332. package/src/itinerary/stores/suggestSession.ts +418 -0
  333. package/src/layers/contracts/itinerary.ts +46 -0
  334. package/src/layers/contracts/overlay.ts +132 -0
  335. package/src/layers/handlers/enrichment.ts +36 -0
  336. package/src/layers/handlers/overlay.ts +406 -0
  337. package/src/layers/handlers/restLayers.ts +94 -0
  338. package/src/layers/handlers/tiles.ts +25 -0
  339. package/src/layers/rules/layers.ts +212 -0
  340. package/src/layers/rules/overlayInstant.ts +12 -0
  341. package/src/layers/rules/reachabilityIcon.ts +18 -0
  342. package/src/layers/rules/readout.ts +102 -0
  343. package/src/layers/stores/layers.ts +262 -0
  344. package/src/map/contracts/contextmenu.ts +33 -0
  345. package/src/map/contracts/geolocate.ts +37 -0
  346. package/src/map/contracts/map.ts +146 -0
  347. package/src/map/contracts/streetview.ts +53 -0
  348. package/src/map/contracts/terrain.ts +152 -0
  349. package/src/map/handlers/contextMenu.ts +135 -0
  350. package/src/map/handlers/geolocate.ts +52 -0
  351. package/src/map/handlers/map.ts +391 -0
  352. package/src/map/handlers/streetview.ts +94 -0
  353. package/src/map/handlers/terrain.ts +663 -0
  354. package/src/map/rules/baseTerrain.ts +75 -0
  355. package/src/map/rules/clickTargets.ts +464 -0
  356. package/src/map/rules/constraints.ts +32 -0
  357. package/src/map/rules/contextMenuReadout.ts +67 -0
  358. package/src/map/rules/coordinates.ts +71 -0
  359. package/src/map/rules/itineraryFit.ts +8 -0
  360. package/src/map/rules/mapEvents.ts +64 -0
  361. package/src/map/rules/mapProjection.ts +476 -0
  362. package/src/map/rules/terrainReading.ts +62 -0
  363. package/src/plugins/contracts/ids.ts +66 -0
  364. package/src/plugins/contracts/plugin.ts +202 -0
  365. package/src/plugins/contracts/slots.ts +137 -0
  366. package/src/plugins/engines/studioPlugin.ts +1365 -0
  367. package/src/plugins/index.ts +111 -0
  368. package/src/plugins/rules/contributions.ts +152 -0
  369. package/src/plugins/rules/errors.ts +60 -0
  370. package/src/plugins/rules/ids.ts +42 -0
  371. package/src/plugins/rules/validation.ts +249 -0
  372. package/src/rules/listeners.ts +57 -0
  373. package/src/rules/origin.ts +13 -0
  374. package/src/rules/storeWrite.ts +37 -0
  375. package/src/rules/types.ts +136 -0
  376. package/src/seams/index.ts +79 -0
  377. package/src/seams/rules/clock.ts +28 -0
  378. package/src/seams/rules/formatters.ts +211 -0
  379. package/src/seams/rules/ids.ts +102 -0
  380. package/src/seams/rules/links.ts +66 -0
  381. package/src/seams/rules/navigation.ts +222 -0
  382. package/src/seams/rules/notify.ts +49 -0
  383. package/src/seams/rules/persistenceDrawer.ts +220 -0
  384. package/src/seams/rules/saveFile.ts +101 -0
  385. package/src/seams/rules/seams.ts +156 -0
  386. package/src/seams/rules/storage.ts +116 -0
  387. package/src/search/contracts/overlay.ts +74 -0
  388. package/src/search/contracts/search.ts +197 -0
  389. package/src/search/handlers/pois.ts +57 -0
  390. package/src/search/handlers/search.ts +280 -0
  391. package/src/search/rules/params.ts +925 -0
  392. package/src/search/rules/poiGroups.ts +138 -0
  393. package/src/search/rules/searchFetch.ts +139 -0
  394. package/src/search/rules/timeWindow.ts +30 -0
  395. package/src/search/stores/search.ts +51 -0
  396. package/src/segments/contracts/itinerary.ts +433 -0
  397. package/src/segments/contracts/segment.ts +35 -0
  398. package/src/segments/engines/segmentDraft.ts +926 -0
  399. package/src/segments/handlers/chainGuards.ts +67 -0
  400. package/src/segments/handlers/directions.ts +44 -0
  401. package/src/segments/handlers/itineraryEcho.ts +45 -0
  402. package/src/segments/handlers/roadAccessDialog.ts +34 -0
  403. package/src/segments/handlers/segment.ts +111 -0
  404. package/src/segments/handlers/segmentEdit.ts +1341 -0
  405. package/src/segments/handlers/segmentGroups.ts +347 -0
  406. package/src/segments/handlers/segmentStructure.ts +1144 -0
  407. package/src/segments/rules/chain.ts +196 -0
  408. package/src/segments/rules/chainModel.ts +217 -0
  409. package/src/segments/rules/colors.ts +11 -0
  410. package/src/segments/rules/commit.ts +76 -0
  411. package/src/segments/rules/draft.ts +90 -0
  412. package/src/segments/rules/draftDisposition.ts +43 -0
  413. package/src/segments/rules/draftSegmentEdit.ts +129 -0
  414. package/src/segments/rules/engine.ts +222 -0
  415. package/src/segments/rules/groupSave.ts +234 -0
  416. package/src/segments/rules/hazardPrompt.ts +60 -0
  417. package/src/segments/rules/itineraryEcho.ts +40 -0
  418. package/src/segments/rules/liveSegmentProjection.ts +55 -0
  419. package/src/segments/rules/merge.ts +51 -0
  420. package/src/segments/rules/metrics.ts +456 -0
  421. package/src/segments/rules/naming.ts +168 -0
  422. package/src/segments/rules/segmentArming.ts +144 -0
  423. package/src/segments/rules/splitPick.ts +84 -0
  424. package/src/segments/rules/viaSimplify.ts +230 -0
  425. package/src/segments/stores/directions.ts +77 -0
  426. package/src/segments/stores/roadAccessDialog.ts +58 -0
  427. package/src/segments/stores/segmentEdit.ts +922 -0
  428. package/src/segments/stores/segmentGroupEdit.ts +84 -0
  429. package/src/segments/stores/segmentSplit.ts +77 -0
  430. package/src/share/contracts/share.ts +39 -0
  431. package/src/share/contracts/shareLink.ts +63 -0
  432. package/src/share/engines/shareLink.ts +1053 -0
  433. package/src/share/handlers/share.ts +47 -0
  434. package/src/share/handlers/shareLink.ts +231 -0
  435. package/src/share/handlers/shareScope.ts +54 -0
  436. package/src/share/rules/link.ts +89 -0
  437. package/src/share/rules/shareLink.ts +218 -0
  438. package/src/share/rules/targets.ts +92 -0
  439. package/src/share/rules/viewConfig.ts +95 -0
  440. package/src/share/stores/share.ts +58 -0
  441. package/src/strings/fr/index.ts +18 -0
  442. package/src/strings/fr/rules/fr.ts +2368 -0
  443. package/src/strings/index.ts +98 -0
  444. package/src/strings/rules/confirmCopy.ts +156 -0
  445. package/src/strings/rules/draftToolNames.ts +94 -0
  446. package/src/strings/rules/en.ts +2519 -0
  447. package/src/strings/rules/failureAlert.ts +115 -0
  448. package/src/strings/rules/formError.ts +400 -0
  449. package/src/strings/rules/maneuvers.ts +107 -0
  450. package/src/strings/rules/outputOptions.ts +126 -0
  451. package/src/strings/rules/publicationState.ts +100 -0
  452. package/src/strings/rules/routeHazardCopy.ts +62 -0
  453. package/src/strings/rules/searchLabels.ts +50 -0
  454. package/src/strings/rules/segmentChainVerbs.ts +62 -0
  455. package/src/strings/rules/studioCopy.ts +130 -0
  456. package/src/strings/rules/unitOptions.ts +119 -0
  457. package/src/testing/checkedBus.ts +226 -0
  458. package/src/testing/index.ts +30 -0
  459. package/src/testing/plugins.ts +106 -0
  460. package/src/testing/studio.ts +267 -0
  461. package/src/testing/urlSeam.ts +153 -0
  462. package/src/time/index.ts +12 -0
  463. package/src/time/rules/sun.ts +78 -0
  464. package/src/video/contracts/cameraSchemas.ts +266 -0
  465. package/src/video/contracts/profileSchemas.ts +37 -0
  466. package/src/video/contracts/video.ts +601 -0
  467. package/src/video/handlers/video.ts +1638 -0
  468. package/src/video/handlers/videoDirector.ts +114 -0
  469. package/src/video/rules/previewRefresh.ts +76 -0
  470. package/src/video/rules/profileSource.ts +51 -0
  471. package/src/video/rules/routeSpans.ts +79 -0
  472. package/src/video/rules/shotDefaults.ts +28 -0
  473. package/src/video/rules/stepOrder.ts +17 -0
  474. package/src/video/rules/videoSnapshot.ts +136 -0
  475. package/src/video/stores/directorThreads.ts +167 -0
  476. package/src/video/stores/videoExport.ts +290 -0
  477. package/src/viewer/contracts/preferences.ts +40 -0
  478. package/src/viewer/handlers/preferences.ts +91 -0
  479. package/src/viewer/rules/capabilities.ts +42 -0
  480. package/src/viewer/rules/config.ts +266 -0
  481. package/src/viewer/rules/context.ts +375 -0
  482. package/src/viewer/rules/ownership.ts +134 -0
  483. package/src/viewer/rules/platformViewer.ts +199 -0
  484. package/src/viewer/rules/scope.ts +197 -0
  485. package/src/viewer/rules/url.ts +145 -0
  486. package/src/viewer/rules/viewer.ts +307 -0
  487. package/src/viewer/rules/viewerSeam.ts +49 -0
  488. package/src/viewer/rules/viewerUnits.ts +34 -0
  489. package/src/waypoints/contracts/itinerary.ts +417 -0
  490. package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
  491. package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
  492. package/src/waypoints/handlers/waypointEdit.ts +1073 -0
  493. package/src/waypoints/rules/amenities.ts +30 -0
  494. package/src/waypoints/rules/defaults.ts +31 -0
  495. package/src/waypoints/rules/details.ts +213 -0
  496. package/src/waypoints/rules/detailsDraft.ts +312 -0
  497. package/src/waypoints/rules/detailsPreview.ts +76 -0
  498. package/src/waypoints/rules/detailsSave.ts +356 -0
  499. package/src/waypoints/rules/draftDirty.ts +45 -0
  500. package/src/waypoints/rules/icons.ts +32 -0
  501. package/src/waypoints/rules/liveWaypoint.ts +63 -0
  502. package/src/waypoints/rules/naming.ts +185 -0
  503. package/src/waypoints/rules/sections.ts +77 -0
  504. package/src/waypoints/rules/waypointDraft.ts +62 -0
  505. package/src/waypoints/stores/waypointDetails.ts +62 -0
  506. package/src/waypoints/stores/waypointEdit.ts +566 -0
  507. package/src/zones/contracts/collection.ts +37 -0
  508. package/src/zones/contracts/zone.ts +528 -0
  509. package/src/zones/engines/zoneForm.ts +1773 -0
  510. package/src/zones/handlers/restZones.ts +287 -0
  511. package/src/zones/handlers/zonePublish.ts +206 -0
  512. package/src/zones/handlers/zoneUnpublish.ts +56 -0
  513. package/src/zones/handlers/zones.ts +2254 -0
  514. package/src/zones/rules/geometry.ts +946 -0
  515. package/src/zones/rules/zoneDefaults.ts +34 -0
  516. package/src/zones/rules/zoneDraft.ts +54 -0
  517. package/src/zones/rules/zoneForm.ts +563 -0
  518. package/src/zones/rules/zoneMetadata.ts +29 -0
  519. package/src/zones/rules/zoneSource.ts +87 -0
  520. package/src/zones/rules/zoneSourceRefusal.ts +104 -0
  521. package/src/zones/stores/zoneEdit.ts +998 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * `@mountaya/studio/plugins`: what a third party may ADD to a studio, and the machine that
3
+ * holds it.
4
+ *
5
+ * A host replaces what the studio DOES through a handler, a seam, the confirm gate or the
6
+ * notifier; a plugin adds to it. "Send this segment to Strava", "band the elevation plot with
7
+ * today's avalanche bulletin" or "put our own button on the map" is a contribution to a named
8
+ * slot rather than a fork of the component that draws it.
9
+ *
10
+ * A plugin is a DECLARATION: an id, what it contributes to named slots, and optionally tools
11
+ * for the bus. The contract and the registry are both here, framework-free, so a Dart, Swift or
12
+ * Kotlin studio reimplements ONE vocabulary rather than inventing three; `@mountaya/studio-react`
13
+ * binds the view type to `ReactNode` and mounts the renderers.
14
+ *
15
+ * ```ts
16
+ * import * as z from "zod";
17
+ *
18
+ * import { StudioPluginEngine, type StudioPlugin } from "@mountaya/studio/plugins";
19
+ *
20
+ * const strava: StudioPlugin = {
21
+ * contributions: [
22
+ * {
23
+ * id: "send",
24
+ * label: "Send to Strava",
25
+ * run: (ctx, target) => void ctx.bus?.dispatchUnsafe(ctx, "acme.strava.send", target),
26
+ * slot: "segment.menu",
27
+ * },
28
+ * ],
29
+ * id: "acme.strava",
30
+ * tools: {
31
+ * "acme.strava.send": {
32
+ * capability: "editor",
33
+ * description: "Send a segment to Strava.",
34
+ * handler: () => ({ ok: true, summary: "Sent the segment to Strava." }),
35
+ * input: z.object({ itineraryId: z.string().nullable(), segmentId: z.string() }),
36
+ * name: "acme.strava.send",
37
+ * },
38
+ * },
39
+ * };
40
+ *
41
+ * const engine = new StudioPluginEngine({ install: [strava] });
42
+ * ```
43
+ *
44
+ * `dispatchUnsafe` rather than `dispatch`, and it is the one line of this example worth reading
45
+ * twice: the typed member is keyed on the STUDIO's tool names, and a plugin's verb is not one of
46
+ * them. Nothing is lost by it: see {@link StudioPlugin.tools}.
47
+ *
48
+ * An entry of its own rather than names on the root barrel, for the reason the root is kept
49
+ * narrow: a consumer who takes the tool contracts should not type-check a plugin engine to
50
+ * reach them, and the root's declarations are held to a size ceiling that this would spend.
51
+ *
52
+ * The fixtures a consumer's own suite stands on are in `@mountaya/studio/testing`, beside the
53
+ * rest of them, rather than under this entry.
54
+ */
55
+
56
+ export {
57
+ RESERVED_PLUGIN_NAMESPACES,
58
+ studioContributionIdPattern,
59
+ studioPluginIdPattern,
60
+ } from "./contracts/ids.js";
61
+ export type {
62
+ StudioPlugin,
63
+ StudioPluginContribution,
64
+ StudioPluginEntry,
65
+ StudioPluginGate,
66
+ StudioPluginSubject,
67
+ StudioSlotContribution,
68
+ StudioSlotEntry,
69
+ } from "./contracts/plugin.js";
70
+ export {
71
+ type StudioPluginItineraryMenuTarget,
72
+ type StudioPluginMapContextMenuTarget,
73
+ type StudioPluginMapControlsTarget,
74
+ type StudioPluginProfileTarget,
75
+ type StudioPluginSegmentMenuTarget,
76
+ type StudioPluginSlot,
77
+ type StudioPluginSlotTargets,
78
+ type StudioPluginTarget,
79
+ type StudioPluginWaypointMenuTarget,
80
+ type StudioPluginZoneMenuTarget,
81
+ studioPluginSlotSchema,
82
+ } from "./contracts/slots.js";
83
+ export {
84
+ StudioPluginEngine,
85
+ type StudioPluginEngineOptions,
86
+ type StudioPluginObserver,
87
+ type StudioPluginRefusalReporter,
88
+ type StudioPluginRunEvent,
89
+ type StudioPluginRunOutcome,
90
+ type StudioPluginToolSink,
91
+ } from "./engines/studioPlugin.js";
92
+ export {
93
+ availableStudioContributions,
94
+ isStudioContributionAvailable,
95
+ type StudioGatedContribution,
96
+ type StudioOrderedContribution,
97
+ sortStudioContributions,
98
+ } from "./rules/contributions.js";
99
+ export { isStudioPluginError, StudioPluginError } from "./rules/errors.js";
100
+ export {
101
+ isStudioPluginToolName,
102
+ qualifyStudioContributionId,
103
+ studioPluginToolPrefix,
104
+ } from "./rules/ids.js";
105
+ export {
106
+ type StudioPluginDefect,
107
+ type StudioPluginDefectCode,
108
+ type StudioPluginValidationScope,
109
+ studioPluginDefectCodeSchema,
110
+ validateStudioPlugin,
111
+ } from "./rules/validation.js";
@@ -0,0 +1,152 @@
1
+ import { surfaceFault } from "../../rules/listeners.js";
2
+ import type { StudioToolContext } from "../../viewer/rules/context.js";
3
+ import type { StudioPluginGate } from "../contracts/plugin.js";
4
+
5
+ /**
6
+ * Whether a contribution shows, and in what order: the two render-time questions.
7
+ *
8
+ * Both are here rather than on the registry, and that split is the registry's whole snapshot
9
+ * contract: `at(slot)` is a STORE, stable between mutations, and a gate reads the tool context,
10
+ * which changes underneath it. A gated snapshot could not be stable by construction, so the
11
+ * registry hands back everything installed and the surface filters at render.
12
+ */
13
+
14
+ /**
15
+ * StudioGatedContribution is the shape gating needs, which both a declaration and a resolved
16
+ * registry entry satisfy.
17
+ *
18
+ * Exported because it appears in an exported signature. An unexported local surfaces in the
19
+ * emitted `.d.ts` as a type a consumer can read and cannot NAME, so a host writing their own
20
+ * helper over the same rule, or a port author writing the constraint down, has nothing to import.
21
+ */
22
+ export interface StudioGatedContribution {
23
+ readonly gate?: StudioPluginGate | undefined;
24
+ }
25
+
26
+ /**
27
+ * StudioOrderedContribution is the shape sorting needs: a declared `order` and an install-order
28
+ * tiebreak.
29
+ *
30
+ * `sequence` is optional and absent means 0, which is what lets a host sort DECLARATIONS: a
31
+ * `StudioPluginContribution` has no sequence, because the number is assigned when the registry
32
+ * adopts one. Exported for the reason {@link StudioGatedContribution} is.
33
+ */
34
+ export interface StudioOrderedContribution {
35
+ readonly order?: number | undefined;
36
+ readonly sequence?: number | undefined;
37
+ }
38
+
39
+ /**
40
+ * isStudioContributionAvailable answers whether a contribution's gate passes right now.
41
+ *
42
+ * STRUCTURAL in its first argument (it asks for a `gate` and nothing else), so it applies
43
+ * unchanged to a declaration a host is validating and to an entry the registry already holds. A
44
+ * signature naming either concrete type would need a second copy for the other.
45
+ *
46
+ * The three clauses are ANDed and each ABSENT one is no constraint, so a contribution with no
47
+ * gate is always available. A `when` that THROWS resolves to unavailable: a predicate that
48
+ * cannot answer has not said yes, and this runs inside somebody else's render, so letting the
49
+ * throw out would take the whole menu down over one plugin's bad guard. The fault still reaches
50
+ * the program's uncaught-error handling on a microtask, once per gate however often the gate is
51
+ * asked, so the author of an item that never shows has a signal. A `when` that answers anything
52
+ * but `true` is unavailable for the same reason, and is no fault.
53
+ */
54
+ export const isStudioContributionAvailable = (
55
+ contribution: StudioGatedContribution,
56
+ ctx: StudioToolContext,
57
+ ): boolean => {
58
+ const gate = contribution.gate;
59
+ if (gate === undefined) {
60
+ return true;
61
+ }
62
+
63
+ // ONE try/catch around the whole evaluation, not just around `when`. Two of the three clauses
64
+ // are somebody else's code as well: `hasEntitlement` is a seam a host implements and
65
+ // `capabilities` is a Set a caller passed, and a throw from either would escape into the render
66
+ // this is written to protect. Every one of them means the same thing: a gate that cannot
67
+ // answer has not said yes.
68
+ try {
69
+ for (const capability of gate.capabilities ?? []) {
70
+ if (!ctx.capabilities.has(capability)) {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ for (const entitlement of gate.entitlements ?? []) {
76
+ if (!ctx.viewer.hasEntitlement(entitlement)) {
77
+ return false;
78
+ }
79
+ }
80
+
81
+ // Only a `when` that answers true opens the gate. One that answers nothing, or a truthy
82
+ // value that is no boolean, comes from a plugin the type checker never read, and it has
83
+ // not said yes any more than one that throws has.
84
+ return gate.when === undefined || gate.when(ctx) === true;
85
+ } catch (fault) {
86
+ // A plugin the type checker never read may write a gate that is no object (`gate: null`),
87
+ // which a WeakSet cannot hold: the contribution that carries it stands for it.
88
+ const faulted: object = typeof gate === "object" && gate !== null ? gate : contribution;
89
+ if (!faultedGates.has(faulted)) {
90
+ faultedGates.add(faulted);
91
+ surfaceFault(fault);
92
+ }
93
+
94
+ return false;
95
+ }
96
+ };
97
+
98
+ /**
99
+ * The gates whose fault has reached the program already, each held by the gate or, for a gate
100
+ * that is no object, by its contribution. A gate is asked at every render, and one report is the
101
+ * signal: the next would be the same defect again.
102
+ */
103
+ const faultedGates = new WeakSet<object>();
104
+
105
+ /**
106
+ * availableStudioContributions filters a list to the contributions whose gates pass.
107
+ *
108
+ * **It returns its INPUT by reference when nothing was dropped**, and that is the property the
109
+ * whole thing exists for rather than an optimisation. Its caller is a `useMemo` feeding a list
110
+ * that re-renders per segment row; a fresh array on every render would churn every consumer of
111
+ * it, and the common case by far is that every gate passes.
112
+ */
113
+ export const availableStudioContributions = <TContribution extends StudioGatedContribution>(
114
+ contributions: readonly TContribution[],
115
+ ctx: StudioToolContext,
116
+ ): readonly TContribution[] => {
117
+ // `every` first, so the all-pass path allocates NOTHING, not even the array a filter would
118
+ // build and this function would then discard. What it costs is a second evaluation of the gates
119
+ // on the path where something WAS dropped, which the contract already requires be cheap and
120
+ // side-effect-free, and which is the rare path by construction.
121
+ if (contributions.every((contribution) => isStudioContributionAvailable(contribution, ctx))) {
122
+ return contributions;
123
+ }
124
+
125
+ return contributions.filter((contribution) => isStudioContributionAvailable(contribution, ctx));
126
+ };
127
+
128
+ /**
129
+ * orderOf reads a contribution's rank, treating anything non-finite as 0.
130
+ *
131
+ * `undefined` is the common case (no opinion). `NaN` and `±Infinity` are the ones worth guarding:
132
+ * `Infinity - Infinity` is `NaN`, a comparator returning `NaN` makes `Array.prototype.sort`
133
+ * implementation-defined, and the symptom is a menu whose items shuffle between renders with
134
+ * nothing in the source looking wrong.
135
+ */
136
+ const orderOf = ({ order }: StudioOrderedContribution): number =>
137
+ order !== undefined && Number.isFinite(order) ? order : 0;
138
+
139
+ /**
140
+ * sortStudioContributions returns a new list in render order: `order` ascending, ties on install
141
+ * order.
142
+ *
143
+ * The tiebreak is what makes the result TOTAL. `order` is an uncoordinated number a plugin
144
+ * author picks alone, so two plugins choosing `100` is the normal case rather than the edge one,
145
+ * and `sequence` resolves it the same way on every render and every reload.
146
+ */
147
+ export const sortStudioContributions = <TContribution extends StudioOrderedContribution>(
148
+ contributions: readonly TContribution[],
149
+ ): TContribution[] =>
150
+ [...contributions].sort(
151
+ (left, right) => orderOf(left) - orderOf(right) || (left.sequence ?? 0) - (right.sequence ?? 0),
152
+ );
@@ -0,0 +1,60 @@
1
+ import { MountayaElementsError } from "@mountaya/elements/errors";
2
+
3
+ import type { StudioPluginDefect } from "./validation.js";
4
+
5
+ /**
6
+ * STUDIO_PLUGIN_ERROR_NAME is the class's `name` as a string LITERAL.
7
+ *
8
+ * Read off the class identifier it would produce the same string right up until a consumer
9
+ * minifies: a class name is an identifier, every production bundler renames identifiers, and the
10
+ * `error.name === "StudioPluginError"` check that passed in development then meets `name: "a"`.
11
+ * A literal is data and survives: the same treatment `RevisionConflictError` and
12
+ * `SegmentDeleteNotEdgeError` get one directory over in `data/rules/restErrors.ts`.
13
+ */
14
+ const STUDIO_PLUGIN_ERROR_NAME = "StudioPluginError";
15
+
16
+ /**
17
+ * StudioPluginError is what a refused install throws, carrying every defect that refused it.
18
+ *
19
+ * Every defect rather than the first, which is why the list is on the error rather than folded
20
+ * into the message: a plugin with three malformed contribution ids should report three, once,
21
+ * rather than teaching its author one fix per reinstall. The `message` is a readable join of the
22
+ * codes for a log line; `defects` is the part a host's own surface renders.
23
+ *
24
+ * It extends the ELEMENTS' error family rather than starting a studio family of its own, which
25
+ * is the rule `boundary.test.ts` holds this package to: a consumer narrows on ONE family across
26
+ * the whole stack, and a second hierarchy would mean two.
27
+ */
28
+ export class StudioPluginError extends MountayaElementsError {
29
+ override readonly name: string = STUDIO_PLUGIN_ERROR_NAME;
30
+
31
+ readonly defects: readonly StudioPluginDefect[];
32
+
33
+ constructor(defects: readonly StudioPluginDefect[], options?: ErrorOptions) {
34
+ super(
35
+ `plugin install refused: ${defects.map((defect) => `${defect.pluginId} ${defect.code}${defect.subject === undefined ? "" : ` (${defect.subject})`}`).join(", ")}`,
36
+ options,
37
+ );
38
+ this.defects = defects;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * isStudioPluginError recognises a refused install STRUCTURALLY, with no `instanceof`.
44
+ *
45
+ * The reason generalizes past this package and is written out in `data/rules/restErrors.ts`:
46
+ * `instanceof` asks whether a value came from one constructor IDENTITY, which is a stronger
47
+ * question than any caller here is asking. A second copy of this module in a consumer's graph, a
48
+ * structured clone across a worker boundary, a bundler that duplicated the chunk: each breaks
49
+ * the check while leaving the value perfectly intact, and none of them fails loudly.
50
+ *
51
+ * It checks the DEFECT LIST as well as the name, because the name alone is a predicate anything
52
+ * can satisfy, and everything downstream of this narrowing reads `.defects` as a non-optional
53
+ * array. A structured clone carries the list; `{ name: "StudioPluginError" }` does not, and is
54
+ * exactly the shape that would otherwise pass here and throw at the first `.map`.
55
+ */
56
+ export const isStudioPluginError = (error: unknown): error is StudioPluginError =>
57
+ typeof error === "object" &&
58
+ error !== null &&
59
+ (error as { name?: unknown }).name === STUDIO_PLUGIN_ERROR_NAME &&
60
+ Array.isArray((error as { defects?: unknown }).defects);
@@ -0,0 +1,42 @@
1
+ /**
2
+ * How a plugin's names are kept out of everybody else's.
3
+ *
4
+ * Three rules, and they only work together: plugin ids are unique and vendor-namespaced, the
5
+ * reserved namespaces are refused, and every tool a plugin registers carries its plugin's id as
6
+ * a prefix. That composition is what protects the studio's `studio.*` verbs without a list of
7
+ * reserved tool names, a list that would be complete the day it is written and silently wrong
8
+ * the day the next studio tool ships.
9
+ */
10
+
11
+ /**
12
+ * studioPluginToolPrefix is what every tool a plugin registers must start with.
13
+ *
14
+ * `${pluginId}.`: a DOT, because a tool name is already a dotted path
15
+ * (`studio.itinerary.export`) and a plugin's verbs should read as one: `acme.avalanche.refresh`
16
+ * is a tool name a model can be shown beside the studio's own without explanation.
17
+ */
18
+ export const studioPluginToolPrefix = (pluginId: string): string => `${pluginId}.`;
19
+
20
+ /**
21
+ * isStudioPluginToolName answers whether a tool name belongs to a given plugin.
22
+ *
23
+ * The prefix and not merely a `startsWith` on the bare id: `acme.avalanche` must not be read as
24
+ * owning `acme.avalanche-pro.refresh`, which is a different plugin from a vendor who picked an
25
+ * adjacent name.
26
+ *
27
+ * It reads the prefix and nothing after it, so `acme.avalanche.` belongs to `acme.avalanche`
28
+ * while naming no tool. `validateStudioPlugin` refuses that name under `tool_name_empty`.
29
+ */
30
+ export const isStudioPluginToolName = (pluginId: string, name: string): boolean =>
31
+ name.startsWith(studioPluginToolPrefix(pluginId));
32
+
33
+ /**
34
+ * qualifyStudioContributionId makes a plugin-local contribution id globally unique.
35
+ *
36
+ * A COLON separates the two halves, and the choice is load-bearing rather than cosmetic: a dot
37
+ * already separates a tool's namespaces and a slot's regions, so `acme.avalanche.risk` would be
38
+ * ambiguous about where the plugin ends. `acme.avalanche:risk` cannot be misread, and it splits
39
+ * back apart with no grammar.
40
+ */
41
+ export const qualifyStudioContributionId = (pluginId: string, contributionId: string): string =>
42
+ `${pluginId}:${contributionId}`;
@@ -0,0 +1,249 @@
1
+ import * as z from "zod";
2
+
3
+ import {
4
+ RESERVED_PLUGIN_NAMESPACES,
5
+ studioContributionIdPattern,
6
+ studioPluginIdPattern,
7
+ } from "../contracts/ids.js";
8
+ import type { StudioPlugin } from "../contracts/plugin.js";
9
+ import { studioPluginSlotSchema } from "../contracts/slots.js";
10
+ import { isStudioPluginToolName, studioPluginToolPrefix } from "./ids.js";
11
+
12
+ /**
13
+ * studioPluginDefectCodeSchema is every way a plugin declaration can be refused, closed.
14
+ *
15
+ * CODES rather than sentences, for the reason every other vocabulary in this package is one:
16
+ * this package renders nothing and translates nothing, so a defect carrying an English string
17
+ * would put English in a host's French settings screen. A host that surfaces install failures
18
+ * maps these to their own copy; a host that only logs them reads the code.
19
+ *
20
+ * What each one means:
21
+ *
22
+ * - `contribution_empty`: neither `label` + `run` nor `view`, so there is nothing to draw. A
23
+ * `view` of `null` and a `label` of `""` count as absent: both draw nothing, which is the thing
24
+ * being refused rather than a spelling of it.
25
+ * - `contribution_id_duplicate`: two contributions in ONE plugin share an id.
26
+ * - `contribution_id_invalid`: the id is not {@link studioContributionIdPattern}.
27
+ * - `plugin_id_invalid`: the id is not {@link studioPluginIdPattern}; usually a missing
28
+ * vendor segment.
29
+ * - `plugin_id_reserved`: the vendor segment is one of {@link RESERVED_PLUGIN_NAMESPACES}.
30
+ * - `plugin_id_taken`: a plugin with this id is already installed.
31
+ * - `slot_unknown`: the slot names no region this studio has.
32
+ * - `tool_key_mismatch`: the record key is not the tool's own `name`, which would make the
33
+ * declaration read one way and register another.
34
+ * - `tool_name_empty`: the tool name is the plugin's prefix and nothing more, so the tool has no
35
+ * name of its own. The name carries the id, which is why this is a code of its own and no case
36
+ * of `tool_name_not_namespaced`.
37
+ * - `tool_name_not_namespaced`: the tool name is not prefixed with the plugin's id.
38
+ * - `tool_name_taken`: the bus already holds this name, the studio's own verbs included.
39
+ */
40
+ export const studioPluginDefectCodeSchema = z.enum([
41
+ "contribution_empty",
42
+ "contribution_id_duplicate",
43
+ "contribution_id_invalid",
44
+ "plugin_id_invalid",
45
+ "plugin_id_reserved",
46
+ "plugin_id_taken",
47
+ "slot_unknown",
48
+ "tool_key_mismatch",
49
+ "tool_name_empty",
50
+ "tool_name_not_namespaced",
51
+ "tool_name_taken",
52
+ ]);
53
+
54
+ /** One way a plugin declaration is refused, derived from {@link studioPluginDefectCodeSchema}. */
55
+ export type StudioPluginDefectCode = z.infer<typeof studioPluginDefectCodeSchema>;
56
+
57
+ /**
58
+ * StudioPluginDefect is one refusal: what was wrong, whose plugin it was, and which part of it.
59
+ *
60
+ * `subject` is the contribution id, tool name or slot the code is about, and it is absent for
61
+ * the three codes that are about the plugin id itself, where `pluginId` already names the
62
+ * subject and repeating it would read as two different things being wrong.
63
+ */
64
+ export interface StudioPluginDefect {
65
+ readonly code: StudioPluginDefectCode;
66
+ readonly pluginId: string;
67
+ readonly subject?: string | undefined;
68
+ }
69
+
70
+ /**
71
+ * StudioPluginValidationScope is what the rest of the world already holds, passed IN.
72
+ *
73
+ * Passed and never read, which keeps the validation pure and portable: `plugin_id_taken` and
74
+ * `tool_name_taken` are about collisions, and a collision is a question about a live registry and
75
+ * a live bus, neither of which a rule may reach for. A port reimplements the validation against
76
+ * its own two sets and gets the same answers.
77
+ */
78
+ export interface StudioPluginValidationScope {
79
+ /** The plugin ids already installed. */
80
+ readonly installed: ReadonlySet<string>;
81
+ /** Every tool name already on the bus, the studio's own verbs included. */
82
+ readonly tools: ReadonlySet<string>;
83
+ }
84
+
85
+ /** Whether a value a wire may have shaped holds members to read. */
86
+ const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
87
+ typeof value === "object" && value !== null;
88
+
89
+ /**
90
+ * Prints a value as the subject of a defect, whatever it is: a string as written, and anything
91
+ * else as text. A value that cannot be converted prints as its type, so a subject never throws.
92
+ */
93
+ const printed = (value: unknown): string => {
94
+ if (typeof value === "string") {
95
+ return value;
96
+ }
97
+
98
+ try {
99
+ return String(value);
100
+ } catch {
101
+ return typeof value;
102
+ }
103
+ };
104
+
105
+ /**
106
+ * validateStudioPlugin returns every defect in a declaration, or an empty list.
107
+ *
108
+ * **Every defect, never the first.** An install is refused as a whole, so stopping early would
109
+ * teach an author one fix per attempt: three malformed contribution ids costing three
110
+ * reinstalls to discover. The list is the report.
111
+ *
112
+ * It reports rather than throws for the same reason: the caller decides what a refusal IS. The
113
+ * registry's `install` throws a {@link StudioPluginError} carrying this list, because an install
114
+ * a host asked for and did not get has to be loud; a host validating a plugin they are about to
115
+ * offer in a settings screen wants the list and no exception.
116
+ *
117
+ * It is total over what a wire can hold. A manifest read from storage has no type behind it, so
118
+ * every member is read as it stands: an id that is no string is `plugin_id_invalid` under an
119
+ * empty `pluginId`, a contribution whose label is no text or whose `run` is no function has
120
+ * nothing to draw, contributions that are no list are read as one malformed contribution, and a
121
+ * tool that holds no name is a `tool_key_mismatch` under its key, as tools that are no record
122
+ * are one under what stands there.
123
+ *
124
+ * @param plugin - The declaration to judge, typed or read off a wire.
125
+ * @param scope - The plugin ids and tool names already taken, for the collision codes.
126
+ * @returns Every defect found, in declaration order; empty for a declaration that installs.
127
+ */
128
+ export const validateStudioPlugin = <TView>(
129
+ plugin: StudioPlugin<TView>,
130
+ scope: StudioPluginValidationScope,
131
+ ): readonly StudioPluginDefect[] => {
132
+ // The declaration as a wire may have shaped it. Every member below is narrowed where it is
133
+ // read, which is what makes the validation total: the type is a promise a manifest never made.
134
+ const declaration: unknown = plugin;
135
+ const members = isRecord(declaration) ? declaration : {};
136
+ const defects: StudioPluginDefect[] = [];
137
+ const pluginId = typeof members.id === "string" ? members.id : "";
138
+ const defect = (code: StudioPluginDefectCode, subject?: string): void => {
139
+ defects.push(subject === undefined ? { code, pluginId } : { code, pluginId, subject });
140
+ };
141
+
142
+ if (!studioPluginIdPattern.test(pluginId)) {
143
+ defect("plugin_id_invalid");
144
+ }
145
+
146
+ // The vendor segment alone. A reserved word LATER in the id (`acme.studio.risk`) is a
147
+ // vendor's own business: nothing this package publishes can collide with it, because the
148
+ // collision rules are all about what an id STARTS with.
149
+ // `some` rather than `includes`, because the list is `as const`: its element type is the union
150
+ // of the two literals, which is what lets a port derive the vocabulary from it, and which makes
151
+ // `includes(someString)` a type error rather than the question being asked.
152
+ const vendor = pluginId.split(".")[0];
153
+ if (RESERVED_PLUGIN_NAMESPACES.some((reserved) => reserved === vendor)) {
154
+ defect("plugin_id_reserved");
155
+ }
156
+
157
+ if (scope.installed.has(pluginId)) {
158
+ defect("plugin_id_taken");
159
+ }
160
+
161
+ const seen = new Set<string>();
162
+
163
+ // A value that is no list is read as the one malformed contribution it is, so it is reported
164
+ // here and never met as a list by the install that follows.
165
+ const declared = members.contributions ?? [];
166
+ const contributions: readonly unknown[] = Array.isArray(declared) ? declared : [declared];
167
+
168
+ for (const entry of contributions) {
169
+ const contribution = isRecord(entry) ? entry : {};
170
+ const subject = printed(contribution.id);
171
+
172
+ if (!studioPluginSlotSchema.safeParse(contribution.slot).success) {
173
+ defect("slot_unknown", printed(contribution.slot));
174
+ }
175
+
176
+ // A string, held to the pattern. An absent id would otherwise be read as the word
177
+ // `undefined`, which fits the grammar.
178
+ if (typeof contribution.id !== "string" || !studioContributionIdPattern.test(contribution.id)) {
179
+ defect("contribution_id_invalid", subject);
180
+ } else if (seen.has(contribution.id)) {
181
+ // Only for an id that is otherwise well-formed. A plugin with two contributions both
182
+ // called `Send To Strava` has one problem, not two, and reporting the duplicate as well
183
+ // would name the same typo twice.
184
+ defect("contribution_id_duplicate", subject);
185
+ }
186
+
187
+ // The id itself and never its printed form: a contribution named `undefined` is unique
188
+ // beside one that holds no id.
189
+ if (typeof contribution.id === "string") {
190
+ seen.add(contribution.id);
191
+ }
192
+
193
+ // A view wins outright: it draws itself, so it owes neither a label nor a verb. Otherwise
194
+ // BOTH halves of the action form are required: a label with no `run` is a menu item that
195
+ // does nothing, and a `run` with no label is a verb with no way to reach it.
196
+ //
197
+ // NULLISH on the view rather than `=== undefined`, and a label that is more than whitespace.
198
+ // Both are the same defect this code exists for arriving through the binding's own view type:
199
+ // `null` is a perfectly good `ReactNode`, so `{ id, slot, view: null }` would otherwise
200
+ // validate and then draw nothing, and `label: ""` would draw an empty row. An install that
201
+ // silently does nothing is the outcome, which is exactly what is being refused.
202
+ //
203
+ // A label that is no text and a `run` that is no function are the same absence.
204
+ const hasView = contribution.view !== undefined && contribution.view !== null;
205
+ const hasAction =
206
+ typeof contribution.label === "string" &&
207
+ contribution.label.trim() !== "" &&
208
+ typeof contribution.run === "function";
209
+
210
+ if (!hasView && !hasAction) {
211
+ defect("contribution_empty", subject);
212
+ }
213
+ }
214
+
215
+ // Tools that are no record are one malformed tool, reported under what stands there, so the
216
+ // install that follows never meets a value it would read as a list of tools.
217
+ if (members.tools !== undefined && members.tools !== null && !isRecord(members.tools)) {
218
+ defect("tool_key_mismatch", printed(members.tools));
219
+ }
220
+
221
+ for (const [key, tool] of Object.entries(isRecord(members.tools) ? members.tools : {})) {
222
+ const name = isRecord(tool) ? tool.name : undefined;
223
+
224
+ // A tool that holds no name has one problem, the first one below, and nothing after it has
225
+ // a name to judge.
226
+ if (typeof name !== "string") {
227
+ defect("tool_key_mismatch", key);
228
+ continue;
229
+ }
230
+
231
+ if (key !== name) {
232
+ defect("tool_key_mismatch", key);
233
+ }
234
+
235
+ if (!isStudioPluginToolName(pluginId, name)) {
236
+ defect("tool_name_not_namespaced", name);
237
+ } else if (name === studioPluginToolPrefix(pluginId)) {
238
+ // The prefix rule reads the id and its dot and nothing after them, so a name that ends at
239
+ // the dot passes it. Such a name is the namespace itself and names no tool in it.
240
+ defect("tool_name_empty", name);
241
+ }
242
+
243
+ if (scope.tools.has(name)) {
244
+ defect("tool_name_taken", name);
245
+ }
246
+ }
247
+
248
+ return defects;
249
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * How a studio engine tells the callbacks a host handed it, stated once.
3
+ *
4
+ * One rule for every engine of this package. Every listener is told. A listener that throws stops
5
+ * neither the engine nor the listeners after it. The first fault of a round reaches the program
6
+ * as an uncaught error on a microtask, and never as the outcome of a command: one report per
7
+ * round, so a defect every listener shares is raised once. An engine imports the two
8
+ * functions below and never writes the loop or the microtask itself.
9
+ */
10
+
11
+ /**
12
+ * surfaceFault hands a callback's own fault to the runtime as an uncaught error, on a microtask.
13
+ *
14
+ * A callback that throws is a defect of the program that handed it over. Thrown through the
15
+ * engine it would read as the engine's own command failing, and dropped it would hide the defect,
16
+ * so it leaves the engine's flow and reaches the program's own uncaught-error handling.
17
+ *
18
+ * It is the answer for a single callback too: a reporter or a sink an engine calls inside a
19
+ * `try`, whose `catch` hands the fault here.
20
+ *
21
+ * @param fault What the callback threw, as thrown.
22
+ */
23
+ export const surfaceFault = (fault: unknown): void => {
24
+ queueMicrotask(() => {
25
+ throw fault;
26
+ });
27
+ };
28
+
29
+ /**
30
+ * notifyListeners tells every listener, whatever one of them does. It never throws.
31
+ *
32
+ * The listeners are told in the order they are iterated, over a copy: the listeners held when the
33
+ * round starts are the round, so one that subscribes or detaches while being told changes it for
34
+ * nobody. The first fault a listener throws is handed to {@link surfaceFault} once they have all
35
+ * been told, so no caller has to decide what a listener's exception does to a command.
36
+ *
37
+ * @param listeners The callbacks to tell.
38
+ * @param args What each one is told, for a fan-out that carries an event.
39
+ */
40
+ export const notifyListeners = <TArgs extends readonly unknown[]>(
41
+ listeners: Iterable<(...args: TArgs) => void>,
42
+ ...args: TArgs
43
+ ): void => {
44
+ let fault: { readonly thrown: unknown } | undefined;
45
+
46
+ for (const listener of [...listeners]) {
47
+ try {
48
+ listener(...args);
49
+ } catch (thrown) {
50
+ fault ??= { thrown };
51
+ }
52
+ }
53
+
54
+ if (fault !== undefined) {
55
+ surfaceFault(fault.thrown);
56
+ }
57
+ };