@mountaya/studio 0.0.0-stage → 0.1.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 (524) hide show
  1. package/CHANGELOG.md +39 -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 +2854 -0
  6. package/dist/agent/index.cjs.map +1 -0
  7. package/dist/agent/index.d.cts +1257 -0
  8. package/dist/agent/index.d.ts +1257 -0
  9. package/dist/agent/index.js +2818 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/bus-BwiNiXdH.d.ts +514 -0
  12. package/dist/bus-DzmhPwdK.d.cts +514 -0
  13. package/dist/chainModel-B23pEP_1.d.cts +127 -0
  14. package/dist/chainModel-B23pEP_1.d.ts +127 -0
  15. package/dist/chunk-2HFY7ETU.js +5721 -0
  16. package/dist/chunk-2HFY7ETU.js.map +1 -0
  17. package/dist/chunk-355TOXSB.js +72 -0
  18. package/dist/chunk-355TOXSB.js.map +1 -0
  19. package/dist/chunk-4ZCUZVSV.js +10275 -0
  20. package/dist/chunk-4ZCUZVSV.js.map +1 -0
  21. package/dist/chunk-6HEKY3NF.js +95 -0
  22. package/dist/chunk-6HEKY3NF.js.map +1 -0
  23. package/dist/chunk-7GFLGGBX.cjs +8 -0
  24. package/dist/chunk-7GFLGGBX.cjs.map +1 -0
  25. package/dist/chunk-7NBRCENN.cjs +19 -0
  26. package/dist/chunk-7NBRCENN.cjs.map +1 -0
  27. package/dist/chunk-AF5GCXE3.js +8 -0
  28. package/dist/chunk-AF5GCXE3.js.map +1 -0
  29. package/dist/chunk-CJDIFRGZ.cjs +2005 -0
  30. package/dist/chunk-CJDIFRGZ.cjs.map +1 -0
  31. package/dist/chunk-CNPZY7N3.js +349 -0
  32. package/dist/chunk-CNPZY7N3.js.map +1 -0
  33. package/dist/chunk-DZJHTWSF.cjs +45 -0
  34. package/dist/chunk-DZJHTWSF.cjs.map +1 -0
  35. package/dist/chunk-EABIHHWA.js +42 -0
  36. package/dist/chunk-EABIHHWA.js.map +1 -0
  37. package/dist/chunk-EKZWV6RS.cjs +415 -0
  38. package/dist/chunk-EKZWV6RS.cjs.map +1 -0
  39. package/dist/chunk-EOKRXXAC.cjs +24 -0
  40. package/dist/chunk-EOKRXXAC.cjs.map +1 -0
  41. package/dist/chunk-F73W2ZTJ.js +1126 -0
  42. package/dist/chunk-F73W2ZTJ.js.map +1 -0
  43. package/dist/chunk-H4DVOZ5O.js +1897 -0
  44. package/dist/chunk-H4DVOZ5O.js.map +1 -0
  45. package/dist/chunk-HI52PBFT.cjs +10314 -0
  46. package/dist/chunk-HI52PBFT.cjs.map +1 -0
  47. package/dist/chunk-IDBXFBLG.cjs +1225 -0
  48. package/dist/chunk-IDBXFBLG.cjs.map +1 -0
  49. package/dist/chunk-LBWTJZUJ.js +297 -0
  50. package/dist/chunk-LBWTJZUJ.js.map +1 -0
  51. package/dist/chunk-NCLA6DKD.cjs +310 -0
  52. package/dist/chunk-NCLA6DKD.cjs.map +1 -0
  53. package/dist/chunk-O4MC5DPD.js +19 -0
  54. package/dist/chunk-O4MC5DPD.js.map +1 -0
  55. package/dist/chunk-OP37FKW6.cjs +98 -0
  56. package/dist/chunk-OP37FKW6.cjs.map +1 -0
  57. package/dist/chunk-OQSYFH3Z.cjs +5945 -0
  58. package/dist/chunk-OQSYFH3Z.cjs.map +1 -0
  59. package/dist/chunk-PACIO4NS.cjs +26 -0
  60. package/dist/chunk-PACIO4NS.cjs.map +1 -0
  61. package/dist/chunk-PSZ2R3TC.cjs +75 -0
  62. package/dist/chunk-PSZ2R3TC.cjs.map +1 -0
  63. package/dist/chunk-QFO5CZG2.cjs +136 -0
  64. package/dist/chunk-QFO5CZG2.cjs.map +1 -0
  65. package/dist/chunk-QL63MUEW.cjs +140 -0
  66. package/dist/chunk-QL63MUEW.cjs.map +1 -0
  67. package/dist/chunk-RFUPPVZO.js +17 -0
  68. package/dist/chunk-RFUPPVZO.js.map +1 -0
  69. package/dist/chunk-RPG2LWMP.js +23 -0
  70. package/dist/chunk-RPG2LWMP.js.map +1 -0
  71. package/dist/chunk-TIBXK6B7.cjs +12 -0
  72. package/dist/chunk-TIBXK6B7.cjs.map +1 -0
  73. package/dist/chunk-UU65VNEV.js +381 -0
  74. package/dist/chunk-UU65VNEV.js.map +1 -0
  75. package/dist/chunk-VGX6TR2I.js +209 -0
  76. package/dist/chunk-VGX6TR2I.js.map +1 -0
  77. package/dist/chunk-WUTDDBVP.js +130 -0
  78. package/dist/chunk-WUTDDBVP.js.map +1 -0
  79. package/dist/chunk-WVQQLKCI.cjs +224 -0
  80. package/dist/chunk-WVQQLKCI.cjs.map +1 -0
  81. package/dist/chunk-WZYXG3SE.js +111 -0
  82. package/dist/chunk-WZYXG3SE.js.map +1 -0
  83. package/dist/chunk-XDI2X3KE.js +6 -0
  84. package/dist/chunk-XDI2X3KE.js.map +1 -0
  85. package/dist/chunk-XKHLRIC7.cjs +381 -0
  86. package/dist/chunk-XKHLRIC7.cjs.map +1 -0
  87. package/dist/context-DNtd2WUv.d.cts +11666 -0
  88. package/dist/context-DgB72Bur.d.ts +11666 -0
  89. package/dist/directorThreads-CqmvsV8b.d.cts +80 -0
  90. package/dist/directorThreads-CqmvsV8b.d.ts +80 -0
  91. package/dist/en-Bu4Ti9Ev.d.cts +2315 -0
  92. package/dist/en-Bu4Ti9Ev.d.ts +2315 -0
  93. package/dist/engines/index.cjs +3446 -0
  94. package/dist/engines/index.cjs.map +1 -0
  95. package/dist/engines/index.d.cts +2216 -0
  96. package/dist/engines/index.d.ts +2216 -0
  97. package/dist/engines/index.js +3416 -0
  98. package/dist/engines/index.js.map +1 -0
  99. package/dist/handlers/index.cjs +99 -0
  100. package/dist/handlers/index.cjs.map +1 -0
  101. package/dist/handlers/index.d.cts +445 -0
  102. package/dist/handlers/index.d.ts +445 -0
  103. package/dist/handlers/index.js +42 -0
  104. package/dist/handlers/index.js.map +1 -0
  105. package/dist/index.cjs +4562 -0
  106. package/dist/index.cjs.map +1 -0
  107. package/dist/index.d.cts +7297 -0
  108. package/dist/index.d.ts +7297 -0
  109. package/dist/index.js +3223 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/plugins/index.cjs +977 -0
  112. package/dist/plugins/index.cjs.map +1 -0
  113. package/dist/plugins/index.d.cts +313 -0
  114. package/dist/plugins/index.d.ts +313 -0
  115. package/dist/plugins/index.js +933 -0
  116. package/dist/plugins/index.js.map +1 -0
  117. package/dist/saveFile-j-1kkApx.d.cts +123 -0
  118. package/dist/saveFile-j-1kkApx.d.ts +123 -0
  119. package/dist/seams/index.cjs +152 -0
  120. package/dist/seams/index.cjs.map +1 -0
  121. package/dist/seams/index.d.cts +485 -0
  122. package/dist/seams/index.d.ts +485 -0
  123. package/dist/seams/index.js +79 -0
  124. package/dist/seams/index.js.map +1 -0
  125. package/dist/shareLink-B6hlt942.d.ts +144 -0
  126. package/dist/shareLink-C7rIMb7x.d.ts +527 -0
  127. package/dist/shareLink-CnTxxXjp.d.cts +144 -0
  128. package/dist/shareLink-DyZVYH2V.d.cts +527 -0
  129. package/dist/strings/fr/index.cjs +2121 -0
  130. package/dist/strings/fr/index.cjs.map +1 -0
  131. package/dist/strings/fr/index.d.cts +19 -0
  132. package/dist/strings/fr/index.d.ts +19 -0
  133. package/dist/strings/fr/index.js +2119 -0
  134. package/dist/strings/fr/index.js.map +1 -0
  135. package/dist/strings/index.cjs +2678 -0
  136. package/dist/strings/index.cjs.map +1 -0
  137. package/dist/strings/index.d.cts +731 -0
  138. package/dist/strings/index.d.ts +731 -0
  139. package/dist/strings/index.js +2644 -0
  140. package/dist/strings/index.js.map +1 -0
  141. package/dist/studioPlugin-C3C7VjMy.d.ts +847 -0
  142. package/dist/studioPlugin-Cf3OBNUv.d.cts +847 -0
  143. package/dist/tabs-B2nRO4p_.d.cts +15 -0
  144. package/dist/tabs-B2nRO4p_.d.ts +15 -0
  145. package/dist/testing/index.cjs +292 -0
  146. package/dist/testing/index.cjs.map +1 -0
  147. package/dist/testing/index.d.cts +306 -0
  148. package/dist/testing/index.d.ts +306 -0
  149. package/dist/testing/index.js +284 -0
  150. package/dist/testing/index.js.map +1 -0
  151. package/dist/time/index.cjs +28 -0
  152. package/dist/time/index.cjs.map +1 -0
  153. package/dist/time/index.d.cts +43 -0
  154. package/dist/time/index.d.ts +43 -0
  155. package/dist/time/index.js +26 -0
  156. package/dist/time/index.js.map +1 -0
  157. package/dist/types-BzJRV6UI.d.cts +845 -0
  158. package/dist/types-BzJRV6UI.d.ts +845 -0
  159. package/dist/zoneForm-CdYNtnnA.d.cts +320 -0
  160. package/dist/zoneForm-mG85yt5e.d.ts +320 -0
  161. package/package.json +225 -4
  162. package/src/agent/engines/agentThreads.ts +1601 -0
  163. package/src/agent/engines/directorChat.ts +500 -0
  164. package/src/agent/index.ts +67 -0
  165. package/src/agent/rules/agentEditLock.ts +115 -0
  166. package/src/agent/rules/agentErrorCopy.ts +44 -0
  167. package/src/agent/rules/copilotOrganization.ts +36 -0
  168. package/src/agent/rules/playbook.gen.ts +444 -0
  169. package/src/agent/rules/router.ts +518 -0
  170. package/src/agent/rules/stateDelta.ts +28 -0
  171. package/src/agent/rules/studioRouter.ts +123 -0
  172. package/src/agent/rules/surfaces.gen.ts +633 -0
  173. package/src/agent/rules/threadsUrl.ts +48 -0
  174. package/src/agent/rules/transcriptObserver.ts +90 -0
  175. package/src/agent/stores/agentThreads.ts +454 -0
  176. package/src/bus/contracts/noData.ts +18 -0
  177. package/src/bus/contracts/shared.ts +172 -0
  178. package/src/bus/contracts/studioTools.ts +224 -0
  179. package/src/bus/rules/bus.ts +858 -0
  180. package/src/bus/rules/confirmation.ts +22 -0
  181. package/src/bus/rules/defineRegistry.ts +26 -0
  182. package/src/bus/rules/errors.ts +401 -0
  183. package/src/bus/rules/handlerErrors.ts +103 -0
  184. package/src/bus/rules/handlerRegistry.ts +627 -0
  185. package/src/bus/rules/inputSchema.ts +232 -0
  186. package/src/bus/rules/invalidInput.ts +441 -0
  187. package/src/bus/rules/lateBoundTools.ts +100 -0
  188. package/src/bus/rules/studioRegistry.ts +324 -0
  189. package/src/bus/rules/studioToolBus.ts +73 -0
  190. package/src/bus/rules/types.ts +805 -0
  191. package/src/chrome/contracts/alert.ts +42 -0
  192. package/src/chrome/contracts/itinerary.ts +26 -0
  193. package/src/chrome/contracts/map.ts +23 -0
  194. package/src/chrome/contracts/overlay.ts +46 -0
  195. package/src/chrome/contracts/panel.ts +29 -0
  196. package/src/chrome/contracts/question.ts +52 -0
  197. package/src/chrome/contracts/selection.ts +26 -0
  198. package/src/chrome/contracts/sidenav.ts +23 -0
  199. package/src/chrome/contracts/snapshot.ts +319 -0
  200. package/src/chrome/contracts/state.ts +22 -0
  201. package/src/chrome/contracts/tabs.ts +56 -0
  202. package/src/chrome/handlers/alert.ts +91 -0
  203. package/src/chrome/handlers/introspection.ts +180 -0
  204. package/src/chrome/handlers/panels.ts +42 -0
  205. package/src/chrome/handlers/question.ts +24 -0
  206. package/src/chrome/handlers/sidenav.ts +116 -0
  207. package/src/chrome/handlers/snapshot.ts +451 -0
  208. package/src/chrome/handlers/stateDelta.ts +125 -0
  209. package/src/chrome/handlers/tabs.ts +143 -0
  210. package/src/chrome/handlers/timestamp.ts +19 -0
  211. package/src/chrome/rules/agentSelectors.ts +210 -0
  212. package/src/chrome/rules/mapAlert.ts +13 -0
  213. package/src/chrome/rules/question.ts +25 -0
  214. package/src/chrome/rules/tabs.ts +13 -0
  215. package/src/chrome/stores/activeDraftSession.ts +134 -0
  216. package/src/chrome/stores/chrome.ts +527 -0
  217. package/src/chrome/stores/uiStore.ts +573 -0
  218. package/src/collab/contracts/collab.ts +261 -0
  219. package/src/collab/handlers/collab.ts +468 -0
  220. package/src/collab/rules/toolNames.ts +33 -0
  221. package/src/collab/stores/collab.ts +899 -0
  222. package/src/collections/contracts/collection.ts +182 -0
  223. package/src/collections/handlers/collectionAttach.ts +141 -0
  224. package/src/collections/handlers/collections.ts +499 -0
  225. package/src/collections/handlers/heldCollection.ts +42 -0
  226. package/src/collections/handlers/restCollections.ts +386 -0
  227. package/src/collections/rules/collections.ts +138 -0
  228. package/src/collections/rules/entityCollections.ts +53 -0
  229. package/src/collections/stores/collections.ts +133 -0
  230. package/src/data/contracts/data.ts +233 -0
  231. package/src/data/contracts/itinerary.ts +71 -0
  232. package/src/data/handlers/activityResolve.ts +76 -0
  233. package/src/data/handlers/data.ts +200 -0
  234. package/src/data/handlers/graphql.ts +26 -0
  235. package/src/data/handlers/mutationSink.ts +1577 -0
  236. package/src/data/handlers/profile.ts +83 -0
  237. package/src/data/handlers/writeThrough.ts +417 -0
  238. package/src/data/rules/cache.ts +181 -0
  239. package/src/data/rules/dataTypes.ts +40 -0
  240. package/src/data/rules/keys.ts +106 -0
  241. package/src/data/rules/persistence.ts +1058 -0
  242. package/src/data/rules/requestBody.ts +43 -0
  243. package/src/data/rules/restErrors.ts +354 -0
  244. package/src/data/rules/sessionSurface.ts +156 -0
  245. package/src/data/rules/toolResultData.ts +73 -0
  246. package/src/data/rules/uuid.ts +24 -0
  247. package/src/edit/contracts/edit.ts +37 -0
  248. package/src/edit/contracts/itinerary.ts +57 -0
  249. package/src/edit/handlers/draftCommit.ts +257 -0
  250. package/src/edit/handlers/editDiscard.ts +34 -0
  251. package/src/edit/handlers/editLock.ts +949 -0
  252. package/src/edit/handlers/editor.ts +203 -0
  253. package/src/edit/handlers/formUnsaved.ts +24 -0
  254. package/src/edit/rules/draftMetadata.ts +117 -0
  255. package/src/edit/rules/editKeyboard.ts +222 -0
  256. package/src/edit/rules/editShortcuts.ts +102 -0
  257. package/src/edit/rules/editTooltip.ts +174 -0
  258. package/src/edit/rules/editorTaken.ts +49 -0
  259. package/src/edit/rules/history.ts +26 -0
  260. package/src/edit/rules/unsavedWork.ts +60 -0
  261. package/src/edit/stores/editorReservation.ts +70 -0
  262. package/src/edit/stores/formsUnsaved.ts +54 -0
  263. package/src/embed/contracts/embed.ts +48 -0
  264. package/src/embed/engines/embedFraming.ts +1329 -0
  265. package/src/embed/engines/embedReady.ts +353 -0
  266. package/src/embed/engines/framingPageSession.ts +169 -0
  267. package/src/embed/handlers/embed.ts +130 -0
  268. package/src/embed/rules/allowedDomains.ts +71 -0
  269. package/src/embed/rules/bridgeMessages.ts +224 -0
  270. package/src/embed/rules/defaults.ts +173 -0
  271. package/src/embed/rules/displaySeed.ts +115 -0
  272. package/src/embed/rules/embedAllowlist.ts +146 -0
  273. package/src/embed/rules/embedConstraints.ts +215 -0
  274. package/src/embed/rules/embedElements.ts +277 -0
  275. package/src/embed/rules/embedSectionFields.ts +126 -0
  276. package/src/embed/rules/embedSecurity.ts +116 -0
  277. package/src/embed/rules/fieldDependencies.ts +87 -0
  278. package/src/embed/rules/fieldOptions.ts +138 -0
  279. package/src/embed/rules/layerOptions.ts +161 -0
  280. package/src/embed/rules/readyProtocol.ts +66 -0
  281. package/src/embed/rules/safetyRules.ts +213 -0
  282. package/src/embed/rules/snippet.ts +531 -0
  283. package/src/embed/rules/tableCode.ts +269 -0
  284. package/src/embed/stores/embed.ts +60 -0
  285. package/src/embed/stores/embedContent.ts +77 -0
  286. package/src/engines/index.ts +81 -0
  287. package/src/handlers/index.ts +66 -0
  288. package/src/index.ts +1086 -0
  289. package/src/itinerary/contracts/itinerary.ts +705 -0
  290. package/src/itinerary/engines/itineraryPace.ts +612 -0
  291. package/src/itinerary/engines/profileMarker.ts +238 -0
  292. package/src/itinerary/handlers/importStaging.ts +352 -0
  293. package/src/itinerary/handlers/itinerary.ts +572 -0
  294. package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
  295. package/src/itinerary/handlers/itineraryExport.ts +117 -0
  296. package/src/itinerary/handlers/itineraryImport.ts +783 -0
  297. package/src/itinerary/handlers/itineraryPublish.ts +118 -0
  298. package/src/itinerary/handlers/itinerarySelection.ts +354 -0
  299. package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
  300. package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
  301. package/src/itinerary/handlers/publicationScope.ts +118 -0
  302. package/src/itinerary/handlers/restItineraries.ts +752 -0
  303. package/src/itinerary/handlers/restItineraryExport.ts +70 -0
  304. package/src/itinerary/handlers/restItineraryImport.ts +311 -0
  305. package/src/itinerary/handlers/restItineraryPace.ts +87 -0
  306. package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
  307. package/src/itinerary/handlers/suggestParams.ts +379 -0
  308. package/src/itinerary/handlers/suggestStaging.ts +363 -0
  309. package/src/itinerary/handlers/surfaceOpen.ts +389 -0
  310. package/src/itinerary/rules/activity.ts +139 -0
  311. package/src/itinerary/rules/analysis.ts +42 -0
  312. package/src/itinerary/rules/ceiling.ts +49 -0
  313. package/src/itinerary/rules/createFlow.ts +107 -0
  314. package/src/itinerary/rules/densify.ts +440 -0
  315. package/src/itinerary/rules/draftSurface.ts +219 -0
  316. package/src/itinerary/rules/editorView.ts +83 -0
  317. package/src/itinerary/rules/export.ts +159 -0
  318. package/src/itinerary/rules/friendlyName.ts +77 -0
  319. package/src/itinerary/rules/import.ts +1052 -0
  320. package/src/itinerary/rules/importFiles.ts +140 -0
  321. package/src/itinerary/rules/importTotals.ts +77 -0
  322. package/src/itinerary/rules/liveSegment.ts +712 -0
  323. package/src/itinerary/rules/lngLat.ts +17 -0
  324. package/src/itinerary/rules/mapSync.ts +100 -0
  325. package/src/itinerary/rules/previewRender.ts +416 -0
  326. package/src/itinerary/rules/profileReadout.ts +216 -0
  327. package/src/itinerary/rules/routing.ts +707 -0
  328. package/src/itinerary/rules/suggest.ts +522 -0
  329. package/src/itinerary/rules/suggestionPreview.ts +119 -0
  330. package/src/itinerary/rules/view.ts +61 -0
  331. package/src/itinerary/stores/importSession.ts +319 -0
  332. package/src/itinerary/stores/itinerary.ts +331 -0
  333. package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
  334. package/src/itinerary/stores/sessionIdentity.ts +43 -0
  335. package/src/itinerary/stores/suggestSession.ts +418 -0
  336. package/src/layers/contracts/itinerary.ts +46 -0
  337. package/src/layers/contracts/overlay.ts +132 -0
  338. package/src/layers/handlers/enrichment.ts +36 -0
  339. package/src/layers/handlers/overlay.ts +406 -0
  340. package/src/layers/handlers/restLayers.ts +94 -0
  341. package/src/layers/handlers/tiles.ts +25 -0
  342. package/src/layers/rules/layers.ts +212 -0
  343. package/src/layers/rules/overlayInstant.ts +12 -0
  344. package/src/layers/rules/reachabilityIcon.ts +18 -0
  345. package/src/layers/rules/readout.ts +102 -0
  346. package/src/layers/stores/layers.ts +262 -0
  347. package/src/map/contracts/contextmenu.ts +33 -0
  348. package/src/map/contracts/geolocate.ts +37 -0
  349. package/src/map/contracts/map.ts +146 -0
  350. package/src/map/contracts/streetview.ts +53 -0
  351. package/src/map/contracts/terrain.ts +152 -0
  352. package/src/map/handlers/contextMenu.ts +135 -0
  353. package/src/map/handlers/geolocate.ts +52 -0
  354. package/src/map/handlers/map.ts +391 -0
  355. package/src/map/handlers/streetview.ts +94 -0
  356. package/src/map/handlers/terrain.ts +663 -0
  357. package/src/map/rules/baseTerrain.ts +75 -0
  358. package/src/map/rules/clickTargets.ts +464 -0
  359. package/src/map/rules/constraints.ts +32 -0
  360. package/src/map/rules/contextMenuReadout.ts +67 -0
  361. package/src/map/rules/coordinates.ts +71 -0
  362. package/src/map/rules/itineraryFit.ts +8 -0
  363. package/src/map/rules/mapEvents.ts +64 -0
  364. package/src/map/rules/mapProjection.ts +476 -0
  365. package/src/map/rules/terrainReading.ts +62 -0
  366. package/src/plugins/contracts/ids.ts +66 -0
  367. package/src/plugins/contracts/plugin.ts +200 -0
  368. package/src/plugins/contracts/slots.ts +137 -0
  369. package/src/plugins/engines/studioPlugin.ts +1365 -0
  370. package/src/plugins/index.ts +111 -0
  371. package/src/plugins/rules/contributions.ts +152 -0
  372. package/src/plugins/rules/errors.ts +60 -0
  373. package/src/plugins/rules/ids.ts +42 -0
  374. package/src/plugins/rules/validation.ts +249 -0
  375. package/src/rules/listeners.ts +57 -0
  376. package/src/rules/origin.ts +13 -0
  377. package/src/rules/storeWrite.ts +37 -0
  378. package/src/rules/types.ts +136 -0
  379. package/src/seams/index.ts +79 -0
  380. package/src/seams/rules/clock.ts +28 -0
  381. package/src/seams/rules/formatters.ts +209 -0
  382. package/src/seams/rules/ids.ts +102 -0
  383. package/src/seams/rules/links.ts +66 -0
  384. package/src/seams/rules/navigation.ts +222 -0
  385. package/src/seams/rules/notify.ts +49 -0
  386. package/src/seams/rules/persistenceDrawer.ts +220 -0
  387. package/src/seams/rules/saveFile.ts +101 -0
  388. package/src/seams/rules/seams.ts +156 -0
  389. package/src/seams/rules/storage.ts +116 -0
  390. package/src/search/contracts/overlay.ts +74 -0
  391. package/src/search/contracts/search.ts +197 -0
  392. package/src/search/handlers/pois.ts +57 -0
  393. package/src/search/handlers/search.ts +280 -0
  394. package/src/search/rules/params.ts +925 -0
  395. package/src/search/rules/poiGroups.ts +138 -0
  396. package/src/search/rules/searchFetch.ts +139 -0
  397. package/src/search/rules/timeWindow.ts +30 -0
  398. package/src/search/stores/search.ts +51 -0
  399. package/src/segments/contracts/itinerary.ts +433 -0
  400. package/src/segments/contracts/segment.ts +35 -0
  401. package/src/segments/engines/segmentDraft.ts +926 -0
  402. package/src/segments/handlers/chainGuards.ts +67 -0
  403. package/src/segments/handlers/directions.ts +44 -0
  404. package/src/segments/handlers/itineraryEcho.ts +45 -0
  405. package/src/segments/handlers/roadAccessDialog.ts +34 -0
  406. package/src/segments/handlers/segment.ts +111 -0
  407. package/src/segments/handlers/segmentEdit.ts +1341 -0
  408. package/src/segments/handlers/segmentGroups.ts +347 -0
  409. package/src/segments/handlers/segmentStructure.ts +1144 -0
  410. package/src/segments/rules/chain.ts +196 -0
  411. package/src/segments/rules/chainModel.ts +217 -0
  412. package/src/segments/rules/colors.ts +11 -0
  413. package/src/segments/rules/commit.ts +76 -0
  414. package/src/segments/rules/draft.ts +90 -0
  415. package/src/segments/rules/draftDisposition.ts +43 -0
  416. package/src/segments/rules/draftSegmentEdit.ts +129 -0
  417. package/src/segments/rules/engine.ts +222 -0
  418. package/src/segments/rules/groupSave.ts +234 -0
  419. package/src/segments/rules/hazardPrompt.ts +60 -0
  420. package/src/segments/rules/itineraryEcho.ts +40 -0
  421. package/src/segments/rules/liveSegmentProjection.ts +55 -0
  422. package/src/segments/rules/merge.ts +51 -0
  423. package/src/segments/rules/metrics.ts +456 -0
  424. package/src/segments/rules/naming.ts +168 -0
  425. package/src/segments/rules/segmentArming.ts +144 -0
  426. package/src/segments/rules/splitPick.ts +84 -0
  427. package/src/segments/rules/viaSimplify.ts +230 -0
  428. package/src/segments/stores/directions.ts +77 -0
  429. package/src/segments/stores/roadAccessDialog.ts +58 -0
  430. package/src/segments/stores/segmentEdit.ts +922 -0
  431. package/src/segments/stores/segmentGroupEdit.ts +84 -0
  432. package/src/segments/stores/segmentSplit.ts +77 -0
  433. package/src/share/contracts/share.ts +39 -0
  434. package/src/share/contracts/shareLink.ts +63 -0
  435. package/src/share/engines/shareLink.ts +1053 -0
  436. package/src/share/handlers/share.ts +47 -0
  437. package/src/share/handlers/shareLink.ts +231 -0
  438. package/src/share/handlers/shareScope.ts +54 -0
  439. package/src/share/rules/link.ts +89 -0
  440. package/src/share/rules/shareLink.ts +218 -0
  441. package/src/share/rules/targets.ts +92 -0
  442. package/src/share/rules/viewConfig.ts +95 -0
  443. package/src/share/stores/share.ts +58 -0
  444. package/src/strings/fr/index.ts +18 -0
  445. package/src/strings/fr/rules/fr.ts +2368 -0
  446. package/src/strings/index.ts +98 -0
  447. package/src/strings/rules/confirmCopy.ts +156 -0
  448. package/src/strings/rules/draftToolNames.ts +94 -0
  449. package/src/strings/rules/en.ts +2519 -0
  450. package/src/strings/rules/failureAlert.ts +115 -0
  451. package/src/strings/rules/formError.ts +400 -0
  452. package/src/strings/rules/maneuvers.ts +107 -0
  453. package/src/strings/rules/outputOptions.ts +126 -0
  454. package/src/strings/rules/publicationState.ts +100 -0
  455. package/src/strings/rules/routeHazardCopy.ts +62 -0
  456. package/src/strings/rules/searchLabels.ts +50 -0
  457. package/src/strings/rules/segmentChainVerbs.ts +62 -0
  458. package/src/strings/rules/studioCopy.ts +130 -0
  459. package/src/strings/rules/unitOptions.ts +119 -0
  460. package/src/testing/checkedBus.ts +226 -0
  461. package/src/testing/index.ts +34 -0
  462. package/src/testing/plugins.ts +106 -0
  463. package/src/testing/studio.ts +267 -0
  464. package/src/testing/urlSeam.ts +153 -0
  465. package/src/time/index.ts +12 -0
  466. package/src/time/rules/sun.ts +78 -0
  467. package/src/video/contracts/cameraSchemas.ts +266 -0
  468. package/src/video/contracts/profileSchemas.ts +37 -0
  469. package/src/video/contracts/video.ts +601 -0
  470. package/src/video/handlers/video.ts +1638 -0
  471. package/src/video/handlers/videoDirector.ts +114 -0
  472. package/src/video/rules/previewRefresh.ts +76 -0
  473. package/src/video/rules/profileSource.ts +51 -0
  474. package/src/video/rules/routeSpans.ts +79 -0
  475. package/src/video/rules/shotDefaults.ts +28 -0
  476. package/src/video/rules/stepOrder.ts +17 -0
  477. package/src/video/rules/videoSnapshot.ts +136 -0
  478. package/src/video/stores/directorThreads.ts +167 -0
  479. package/src/video/stores/videoExport.ts +290 -0
  480. package/src/viewer/contracts/preferences.ts +40 -0
  481. package/src/viewer/handlers/preferences.ts +91 -0
  482. package/src/viewer/rules/capabilities.ts +42 -0
  483. package/src/viewer/rules/config.ts +266 -0
  484. package/src/viewer/rules/context.ts +375 -0
  485. package/src/viewer/rules/ownership.ts +134 -0
  486. package/src/viewer/rules/platformViewer.ts +198 -0
  487. package/src/viewer/rules/scope.ts +197 -0
  488. package/src/viewer/rules/url.ts +145 -0
  489. package/src/viewer/rules/viewer.ts +307 -0
  490. package/src/viewer/rules/viewerSeam.ts +49 -0
  491. package/src/viewer/rules/viewerUnits.ts +34 -0
  492. package/src/waypoints/contracts/itinerary.ts +417 -0
  493. package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
  494. package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
  495. package/src/waypoints/handlers/waypointEdit.ts +1073 -0
  496. package/src/waypoints/rules/amenities.ts +30 -0
  497. package/src/waypoints/rules/defaults.ts +31 -0
  498. package/src/waypoints/rules/details.ts +213 -0
  499. package/src/waypoints/rules/detailsDraft.ts +312 -0
  500. package/src/waypoints/rules/detailsPreview.ts +76 -0
  501. package/src/waypoints/rules/detailsSave.ts +356 -0
  502. package/src/waypoints/rules/draftDirty.ts +45 -0
  503. package/src/waypoints/rules/icons.ts +32 -0
  504. package/src/waypoints/rules/liveWaypoint.ts +63 -0
  505. package/src/waypoints/rules/naming.ts +185 -0
  506. package/src/waypoints/rules/sections.ts +77 -0
  507. package/src/waypoints/rules/waypointDraft.ts +62 -0
  508. package/src/waypoints/stores/waypointDetails.ts +62 -0
  509. package/src/waypoints/stores/waypointEdit.ts +566 -0
  510. package/src/zones/contracts/collection.ts +37 -0
  511. package/src/zones/contracts/zone.ts +528 -0
  512. package/src/zones/engines/zoneForm.ts +1773 -0
  513. package/src/zones/handlers/restZones.ts +287 -0
  514. package/src/zones/handlers/zonePublish.ts +206 -0
  515. package/src/zones/handlers/zoneUnpublish.ts +56 -0
  516. package/src/zones/handlers/zones.ts +2254 -0
  517. package/src/zones/rules/geometry.ts +946 -0
  518. package/src/zones/rules/zoneDefaults.ts +34 -0
  519. package/src/zones/rules/zoneDraft.ts +54 -0
  520. package/src/zones/rules/zoneForm.ts +563 -0
  521. package/src/zones/rules/zoneMetadata.ts +29 -0
  522. package/src/zones/rules/zoneSource.ts +87 -0
  523. package/src/zones/rules/zoneSourceRefusal.ts +104 -0
  524. package/src/zones/stores/zoneEdit.ts +998 -0
@@ -0,0 +1,805 @@
1
+ import * as z from "zod";
2
+
3
+ import type { AgentToolErrorCode } from "@mountaya/client";
4
+
5
+ /**
6
+ * The vocabulary a studio mutation surface is spoken in.
7
+ *
8
+ * Everything here is generic over `TCtx`, the execution context a host threads into its
9
+ * handlers. That parameter is the whole reason this module can be published: the context is
10
+ * the one part of a tool bus that is irreducibly the host's (Mountaya's studio threads a map
11
+ * client, a UI store and a query cache through it, an integrator will thread whatever their
12
+ * application holds), while the dispatch machinery, the capability gate, the confirmation
13
+ * protocol and the result shape are the same for everyone.
14
+ *
15
+ * Nothing here imports a renderer or React, and `@mountaya/client` is named for one type, the
16
+ * wire's failure codes, which erases. A tool is a name, a Zod schema and a function;
17
+ * `boundary.test.ts` keeps it that way.
18
+ */
19
+
20
+ /**
21
+ * toolCapabilitySchema is the capabilities this package can mean on its own behalf.
22
+ *
23
+ * `authenticated` is "there is a session"; `editor` is "this surface may change the resource".
24
+ * They are Zod-first because a host derives them from an auth context and may want to parse
25
+ * what it derived.
26
+ *
27
+ * The set is deliberately small. A vocabulary is only useful where both sides agree on what a
28
+ * word denotes, and these are the only ones a package that knows nothing about a host's
29
+ * authorization model can define. Anything past them, such as a surface class, what an
30
+ * agreement covers or a membership role, belongs to whoever grants it.
31
+ */
32
+ export const toolCapabilitySchema = z.enum(["authenticated", "editor"]);
33
+
34
+ /**
35
+ * ToolCapability gates which tools are available to a surface: the ones above, plus whatever a
36
+ * host's own model adds.
37
+ *
38
+ * The `(string & {})` arm is what makes the union open while keeping the published values in
39
+ * autocomplete: a host declaring `capability: "embedding"` on its own tool is legal, and a host
40
+ * reaching for `"editor"` still gets it offered. The gate itself is a `Set.has` over strings and
41
+ * never narrows, so an unknown capability is refused rather than mistaken for a known one.
42
+ *
43
+ * A host with a closed vocabulary of its own states it in one place: declare a Zod enum over
44
+ * every capability it grants and thread it through its own tool type, which is how a host
45
+ * names the surfaces this package has no business naming.
46
+ */
47
+ export type ToolCapability = z.infer<typeof toolCapabilitySchema> | (string & {});
48
+
49
+ // Named `ToolCapability` rather than `Capability`, and the prefix is load-bearing rather
50
+ // than decorative. `@mountaya/client` publishes a `Capability` of its own, drawn from the
51
+ // contract, and it means a product an organization HOLDS: `studio-online`, `publishing`, `tiles`,
52
+ // `data`, `studio-embedded`, `white-label`. This one means which TOOLS a surface may reach,
53
+ // which is a different question with a different answer set, and a consumer installs both
54
+ // packages.
55
+ // `src/wireVocabulary.test.ts` compiles the two barrels against each other and fails on a
56
+ // bare name that means two things.
57
+
58
+ /**
59
+ * confirmationToneSchema is the closed vocabulary of confirm treatments a tool may
60
+ * ask its prompt to wear. It names the CONSEQUENCE, and the confirm surface owns the
61
+ * paint, so a tool never hard-codes a color:
62
+ *
63
+ * - "destructive": data is removed or a grant is revoked.
64
+ * - "cautionary": nothing is lost, but a live side effect follows that the user
65
+ * cannot silently walk back (a chain re-shape, a re-route).
66
+ * - "affirmative": a benign confirmation the user is simply being asked to own.
67
+ *
68
+ * Zod-first because it is a value enum shared across the tool definitions, the bus,
69
+ * and the confirm surface. Absent on a policy, the tone is "destructive": the confirm
70
+ * gate exists for consequential verbs, so the loudest treatment is the safe default and
71
+ * a softer one is an explicit opt-in.
72
+ */
73
+ export const confirmationToneSchema = z.enum(["affirmative", "cautionary", "destructive"]);
74
+
75
+ /**
76
+ * ConfirmationTone is the treatment a confirm prompt wears, derived from
77
+ * {@link confirmationToneSchema}. See the schema's JSDoc for each member's meaning.
78
+ */
79
+ export type ConfirmationTone = z.infer<typeof confirmationToneSchema>;
80
+
81
+ /**
82
+ * ConfirmationValues are the interpolation values a confirm prompt's copy keys are
83
+ * resolved with, so a body can name the entities it is about to act on ("Merge
84
+ * {{name}} into {{nextName}}") instead of describing them generically. A value the
85
+ * entry does not reference is ignored, and a placeholder with no value renders as-is
86
+ * rather than throwing.
87
+ */
88
+ export type ConfirmationValues = Record<string, string | number>;
89
+
90
+ /**
91
+ * toolConfirmationSchema is the Zod source of truth for a tool's confirmation
92
+ * policy. Every copy field is a key the confirm surface resolves, never raw copy:
93
+ * this package carries no strings and does not translate.
94
+ *
95
+ * - acknowledgeLabel, when present, demands the user tick an "I understand…"
96
+ * checkbox before the confirm control enables, reserved for the highest-stakes
97
+ * tools so a stray click cannot destroy something.
98
+ * - titleLabel / descriptionLabel override the dialog's title and body so each
99
+ * destructive tool reads with its own resource-specific copy; absent, the surface
100
+ * falls back to the tool's description and a generic title.
101
+ * - confirmLabel overrides the confirm button's label.
102
+ * - tone selects the prompt's treatment (see {@link confirmationToneSchema}) and
103
+ * defaults to "destructive" when absent.
104
+ *
105
+ * A tool that supplies an empty object keeps the generic prompt; the empty form is the
106
+ * explicit declaration that the generic prompt is the intended experience. A host may
107
+ * introspect this schema at manifest time, so the contract is machine-readable rather
108
+ * than implicit.
109
+ */
110
+ export const toolConfirmationSchema = z.object({
111
+ acknowledgeLabel: z.string().optional(),
112
+ confirmLabel: z.string().optional(),
113
+ descriptionLabel: z.string().optional(),
114
+ titleLabel: z.string().optional(),
115
+ tone: confirmationToneSchema.optional(),
116
+ });
117
+
118
+ /**
119
+ * ToolConfirmation is the confirmation policy a destructive tool attaches to
120
+ * itself, derived from toolConfirmationSchema.
121
+ */
122
+ export type ToolConfirmation = z.infer<typeof toolConfirmationSchema>;
123
+
124
+ /**
125
+ * ConfirmationRequest describes a destructive (requiresConfirmation) tool the
126
+ * bus is about to run. The bus passes it to the context's confirm gate so the
127
+ * application (or an agent host) can prompt for approval before the handler runs.
128
+ *
129
+ * The bus forwards the tool's policy two ways: `acknowledge` carries the whole policy
130
+ * object, and the policy's display keys are also flattened onto the request as
131
+ * `titleLabel` / `descriptionLabel` / `confirmLabel` so a surface resolves the dialog's
132
+ * copy without reaching into the nested policy. `cancelLabel` optionally overrides the
133
+ * cancel copy. All are keys, absent for a tool that keeps the generic prompt; a host
134
+ * that builds a request by hand supplies a pre-resolved `description` and omits them.
135
+ */
136
+ export interface ConfirmationRequest {
137
+ acknowledge?: ToolConfirmation | undefined;
138
+ cancelLabel?: string | undefined;
139
+ confirmLabel?: string | undefined;
140
+ description: string;
141
+ descriptionLabel?: string | undefined;
142
+ input: unknown;
143
+ name: string;
144
+ titleLabel?: string | undefined;
145
+ tone?: ConfirmationTone | undefined;
146
+ values?: ConfirmationValues | undefined;
147
+ }
148
+
149
+ /**
150
+ * TabSurface is the narrow window onto a host's tab strip a tool handler needs: reveal
151
+ * the co-pilot panel, switch the active tab, open a new one (returning its id), or close
152
+ * one. A host injects it so the tab tools never reach into a specific store: the bus
153
+ * stays the single mutation surface and the tab state stays a host detail. Optional,
154
+ * since a surface with no tab strip omits it and those tools return a structured failure
155
+ * rather than throwing.
156
+ */
157
+ export interface TabSurface {
158
+ addCopilotTab: () => string;
159
+ closeCopilotTab: (tabId: string) => void;
160
+ /** countOpen returns the number of co-pilot tabs currently open. */
161
+ countOpen: () => number;
162
+ /**
163
+ * hasTab reports whether the strip holds a tab under `tabId`: a conversation that is open, or
164
+ * a pseudo-tab the strip shows.
165
+ *
166
+ * It is what lets `studio.tabs.switch` and `studio.tabs.close` answer `not-found` for an id
167
+ * that names no tab, where `setActiveTab` and `closeCopilotTab` report nothing
168
+ * back. A strip that states none is not asked, and the two verbs answer success for an id
169
+ * they could not check. The search pseudo-tab is always there, so `studio.tabs.switch` shows
170
+ * it without asking.
171
+ *
172
+ * @default undefined, and no id is refused as unknown
173
+ */
174
+ hasTab?: ((tabId: string) => boolean) | undefined;
175
+ /**
176
+ * openCopilot reveals the co-pilot and returns the id of the tab it
177
+ * activated. Idempotent focus-or-open: it activates an existing conversation when one
178
+ * is open and opens one when none is, so a repeated request always lands on the panel
179
+ * rather than silently hitting the open-tab cap.
180
+ */
181
+ openCopilot: () => string;
182
+ /**
183
+ * reset clears the co-pilot for a switched-to resource: it closes every thread so the
184
+ * leaving resource's conversation cannot leak into the next one, then lands on the
185
+ * default tab so the panel stays closed until asked again.
186
+ */
187
+ reset: () => void;
188
+ setActiveTab: (tabId: string) => void;
189
+ }
190
+
191
+ /**
192
+ * ViewerPreferences is how the person reading this studio wants measurements and copy
193
+ * rendered. Every field is optional because a host hydrates them from a profile that may
194
+ * carry none of them, and each consumer falls back to its own default rather than to a
195
+ * shared one: an absent `length` is "this viewer has not said", not "metric".
196
+ *
197
+ * `UnitFormatOptions` on `@mountaya/elements` is the resolved form of every field: a formatter
198
+ * needs an answer for each, so `resolveViewerUnits` fills the gaps and the sparse shape never
199
+ * reaches one.
200
+ */
201
+ export interface ViewerPreferences {
202
+ /** A BCP 47 tag. Chooses the decimal separator and the localized unit name. */
203
+ language?: string | undefined;
204
+ length?: "metric" | "imperial" | undefined;
205
+ /** The FORM a travel rate is stated in. The system still comes from `length`. */
206
+ pace?: "per-time" | "per-distance" | undefined;
207
+ slope?: "degrees" | "percentage" | undefined;
208
+ temperature?: "celsius" | "fahrenheit" | undefined;
209
+ }
210
+
211
+ /**
212
+ * ViewerSeam is the narrow window onto whoever is reading this studio: who they are, what
213
+ * the host currently extends to them, and how they want measurements rendered.
214
+ *
215
+ * Three questions, one answer a surface can change, and a subscription. `setPreferences` is
216
+ * the one WRITE.
217
+ *
218
+ * The questions: `getUserId` answers "is this mine?" (an edit lock's holder, a collection's
219
+ * author, the creator of a personal resource). `hasEntitlement` answers "does this person's
220
+ * agreement cover this surface?".
221
+ * `getPreferences` lets a confirm prompt state a distance in the units the rest of the editor
222
+ * shows. Nothing else about a session belongs to a tool.
223
+ *
224
+ * The write belongs HERE rather than on a seam of its own, and the reason is `subscribe`. It
225
+ * writes exactly the state the reads read, and that state is the one thing on this interface
226
+ * that changes under a session that stays put, so a second seam would be one object a host
227
+ * wires separately, notifying listeners registered on the first. What would be wrong is a write
228
+ * to something this seam does not also READ; there is none, and a reviewer adding one should
229
+ * treat this paragraph as the argument against it.
230
+ *
231
+ * It is deliberately NOT a store. A host's identity store also carries how the session was
232
+ * established (an email-verification flag, an identity provider's traits and metadata, the
233
+ * setters a bootstrap calls), and none of that is a studio concern. Publishing the store
234
+ * would put one identity provider's session vocabulary in every consumer's types; publishing
235
+ * the three questions instead lets a host answer them from whatever it already has.
236
+ *
237
+ * Every member is a FUNCTION, not a value, and that is the load-bearing part. A host builds
238
+ * its context once and hands the same object to every dispatch, so anything captured by
239
+ * value is captured at mount, and entitlement is precisely what is not settled then, since
240
+ * membership in an organization resolves from a lookup that lands after bootstrap. A
241
+ * handler that read a snapshot would refuse a member the surface already offers.
242
+ */
243
+ export interface ViewerSeam<TEntitlement extends string = string> {
244
+ getPreferences: () => ViewerPreferences | null;
245
+ getUserId: () => string | null;
246
+ /**
247
+ * hasEntitlement asks whether the host extends a named entitlement to this viewer right
248
+ * now, such as a product the viewer's agreement covers or a membership.
249
+ *
250
+ * Distinct from `ToolBusContext.capabilities`, and the difference is what each describes.
251
+ * `capabilities` is what the SURFACE is: an embed grants `embedding` for as long as it is an
252
+ * embed, so the bus can settle it once and gate on a `Set`. This is what the PERSON
253
+ * holds, which changes under a session that stays put.
254
+ *
255
+ * The vocabulary belongs to the host, for the same reason `ToolCapability` leaves what an
256
+ * agreement covers to whoever grants it. A host with a closed set of its own states it once
257
+ * as a Zod enum and binds it through `TEntitlement`, so a typo is a type error rather than a
258
+ * silent `false`.
259
+ */
260
+ hasEntitlement: (entitlement: TEntitlement) => boolean;
261
+ /**
262
+ * setPreferences records a viewer's measurement choices, as a PARTIAL: a surface changing
263
+ * the length system says only that, and the host folds it onto whatever it already held.
264
+ *
265
+ * The one member that is not a question, and it is on this interface because it writes the
266
+ * state `getPreferences` reads and `subscribe` reports, as {@link ViewerSeam} argues. Where the
267
+ * host PUTS it is the host's business: a signed-in studio persists it against the account, an
268
+ * embed keeps it for the session, and a viewer built by `createStaticViewer` drops it.
269
+ *
270
+ * Total, like every seam in this family: a host that cannot store a preference does nothing
271
+ * rather than throwing, and "the choice did not stick" is a state the surface already renders
272
+ * by reading the value back.
273
+ */
274
+ setPreferences: (partial: ViewerPreferences) => void;
275
+ /**
276
+ * subscribe registers a listener for any change to the answers above, and returns the
277
+ * unsubscribe.
278
+ *
279
+ * Every other member is a function so it can be READ late: the context is built once per
280
+ * mount and a membership resolves after it. That is exactly right for a handler, which runs on
281
+ * demand and wants the answer as of now. It is not enough for a surface: a component that
282
+ * calls `hasEntitlement` during render is correct once and then stale, and the surfaces that
283
+ * gate on this are the ones a session changes underneath (an invitation accepted in another
284
+ * tab, an agreement that starts covering a product, a membership that resolves a beat after
285
+ * the studio mounts).
286
+ *
287
+ * The signature is `useSyncExternalStore`'s deliberately, so a host holding this in any store
288
+ * passes its own `subscribe` unchanged and a host holding constants passes one that never
289
+ * fires. Required rather than optional: an optional subscription is one a component cannot
290
+ * rely on, so every reader would need a stale path as well as a live one.
291
+ */
292
+ subscribe: (onChange: () => void) => () => void;
293
+ }
294
+
295
+ /**
296
+ * ToolBusContext is the minimum a host's execution context must provide for the bus to do
297
+ * its job, and the only part of that context this package is entitled to know about.
298
+ *
299
+ * Its members are what the bus itself reads of a context before a handler runs: `capabilities`,
300
+ * to refuse a tool the caller was never granted, and `confirm`, called before a destructive one.
301
+ * A tool's `precondition` and everything a handler touches (a map, a store, a cache) read the
302
+ * host's own context, and none of it appears here.
303
+ *
304
+ * `confirm` is optional, and its absence is a REFUSAL rather than a bypass: a bus with no
305
+ * confirm gate declines every tool that requires confirmation. That is what lets a read-only
306
+ * surface omit the gate entirely and still be safe by construction, instead of relying on
307
+ * nobody having registered a destructive tool.
308
+ */
309
+ export interface ToolBusContext {
310
+ capabilities: ReadonlySet<ToolCapability>;
311
+ confirm?: ((request: ConfirmationRequest) => Promise<boolean>) | undefined;
312
+ }
313
+
314
+ /**
315
+ * ToolDispatchRegistry maps every registered tool name to its raw (pre-parse) input
316
+ * type. It is declared empty here and populated by a host via interface augmentation
317
+ * (`declare module "@mountaya/studio"`), so this module stays a leaf (it never
318
+ * imports the registry that knows the tools) while a handler chaining through the
319
+ * context's bus still sees the full name union and each tool's input shape. Without an
320
+ * augmentation present it is empty: {@link KnownToolInput} answers `unknown` for every name,
321
+ * and the typed `dispatch` of a {@link ToolBusDispatch} left at this default takes no name, so
322
+ * `dispatchUnsafe` is the entry point until the registry is augmented or the inputs are named.
323
+ */
324
+ // biome-ignore lint/suspicious/noEmptyInterface: the empty body is the augmentation seam: a host fills it via declaration merging, and an interface (not a type alias) is what `declare module` can merge into.
325
+ export interface ToolDispatchRegistry {}
326
+
327
+ /**
328
+ * KnownToolInput resolves a tool name to its raw (pre-parse) input type from the
329
+ * augmented registry, or `unknown` for a name the registry does not carry (the
330
+ * loose-seam fallback, and the type a dynamically-built name resolves to).
331
+ */
332
+ export type KnownToolInput<TName> = TName extends keyof ToolDispatchRegistry
333
+ ? ToolDispatchRegistry[TName]
334
+ : unknown;
335
+
336
+ /**
337
+ * ToolOutputRegistry maps every registered tool name to the `data` its answer holds. It is the
338
+ * second augmentation seam, beside {@link ToolDispatchRegistry} and declared empty for the same
339
+ * reason: a host fills it by interface augmentation (`declare module "@mountaya/studio"`), so
340
+ * this module names no tool and a dispatch through the context's bus still answers each verb's
341
+ * own data.
342
+ *
343
+ * A registry of its own, because what a tool takes and what it answers are separate questions. A
344
+ * host that augments the inputs alone has its names and payloads checked and reads every
345
+ * answer's `data` as `unknown`, which is what a dispatch answers wherever this map does not hold
346
+ * the name.
347
+ */
348
+ // biome-ignore lint/suspicious/noEmptyInterface: the empty body is the augmentation seam. A host fills it by declaration merging, and an interface (not a type alias) is what `declare module` can merge into.
349
+ export interface ToolOutputRegistry {}
350
+
351
+ /**
352
+ * KnownToolOutput resolves a tool name to the `data` its answer holds, read from the augmented
353
+ * {@link ToolOutputRegistry}, or `unknown` for a name the registry does not carry: a tool whose
354
+ * contract states no output, and every name while the registry is not augmented.
355
+ */
356
+ export type KnownToolOutput<TName> = TName extends keyof ToolOutputRegistry
357
+ ? ToolOutputRegistry[TName]
358
+ : unknown;
359
+
360
+ /**
361
+ * unstated keys the answer of a name an outputs map does not hold. A symbol, so no tool name can
362
+ * spell it, and declared only: it names a type and no value exists behind it.
363
+ */
364
+ declare const unstated: unique symbol;
365
+
366
+ /**
367
+ * ToolSuccess is the `ok` arm of {@link ToolResult}: a summary, and the data of type `TData`.
368
+ */
369
+ type ToolSuccess<TData = unknown> = Extract<ToolResult<TData>, { ok: true }>;
370
+
371
+ /**
372
+ * ToolSuccessByName is an outputs map read as `ok` answers: each name to the {@link ToolSuccess}
373
+ * holding its data, and {@link unstated} to the `ok` answer of every other name.
374
+ *
375
+ * A mapped type rather than `ToolResult<TOutputs[TName]>` written at the dispatch itself, because
376
+ * each entry here is resolved once per name. A result parameterised by a name still to be
377
+ * inferred stays unresolved, and nothing but the bus's own answer is assignable to it.
378
+ */
379
+ type ToolSuccessByName<TOutputs> = { [K in keyof TOutputs]: ToolSuccess<TOutputs[K]> } & {
380
+ [unstated]: ToolSuccess;
381
+ };
382
+
383
+ /**
384
+ * ToolResultOf is what a dispatch of `TName` answers on a bus whose outputs are `TOutputs`: the
385
+ * {@link ToolResult} of that verb's data, and a plain {@link ToolResult} for a name the map does
386
+ * not hold.
387
+ *
388
+ * The arms ahead of the lookup are the names the compiler cannot match. No name at all is the
389
+ * typed dispatch of a bus whose registry is not augmented, and the whole of `string` is a name
390
+ * built at run time. Each answers `data` as `unknown`, whatever the map holds.
391
+ *
392
+ * The refusal is an arm of its own beside the lookup, and the lookup holds the `ok` arms alone.
393
+ * A {@link ToolFailure} is therefore the answer of every verb while the name is still to be
394
+ * resolved: a wrapper generic in the name returns a refusal of its own as written, and so does a
395
+ * hand-written dispatch that refuses everything. A value that answers one `ok` shape under every
396
+ * name is held to the lookup, and is refused with the two types named where a verb states data
397
+ * it does not carry. A refusal held inside each entry would cost both: to relate such a value the
398
+ * compiler intersects every verb's whole result, and over a map of many data types it gives up
399
+ * with TS2590, which names neither type and is reported for the first such value of a program
400
+ * alone.
401
+ *
402
+ * The `string` arm is also what makes `TOutputs` a way of READING a bus and no part of its
403
+ * identity. TypeScript compares two instantiations of one generic interface with the method's
404
+ * own type parameter erased, where every dispatch answers the plain result, so a dispatch slice
405
+ * typed with one outputs map is assignable to a slot typed with another. A host that names no
406
+ * outputs hands its `bus.dispatcher` to a studio context as it stands. A value of another type,
407
+ * a bus instance or an object literal among them, is compared member by member, and there the
408
+ * answers have to agree.
409
+ *
410
+ * Published for a wrapper that forwards a name it has not resolved. A function generic in the
411
+ * name returns this type to hand its caller what the bus answered: a `ToolResult` written over
412
+ * `TOutputs[TName]` is another unresolved type, and the bus's answer is not assignable to it.
413
+ *
414
+ * @example
415
+ * ```ts
416
+ * interface Inputs {
417
+ * "acme.route.measure": { routeId: string };
418
+ * }
419
+ * interface Outputs {
420
+ * "acme.route.measure": { meters: number };
421
+ * }
422
+ * declare const dispatcher: ToolBusDispatch<ToolBusContext, Inputs, Outputs>;
423
+ * declare const context: ToolBusContext;
424
+ *
425
+ * const dispatch = <TName extends keyof Inputs & string>(
426
+ * name: TName,
427
+ * input: Inputs[TName],
428
+ * ): Promise<ToolResultOf<Outputs, TName>> => dispatcher.dispatch(context, name, input);
429
+ *
430
+ * const measured = await dispatch("acme.route.measure", { routeId: "r-1" });
431
+ * console.log(measured.ok ? measured.data.meters : measured.error);
432
+ * ```
433
+ */
434
+ export type ToolResultOf<TOutputs, TName> = [TName] extends [never]
435
+ ? ToolResult
436
+ : string extends TName
437
+ ? ToolResult
438
+ :
439
+ | ToolFailure
440
+ | ToolSuccessByName<TOutputs>[[TName] extends [keyof TOutputs]
441
+ ? TName & keyof TOutputs
442
+ : typeof unstated];
443
+
444
+ /**
445
+ * ToolBusDispatch is the structural slice of the bus a chained handler reaches for: the
446
+ * dispatch surface alone. Declared here rather than imported from the bus so this
447
+ * module stays a leaf: a context shapes how the bus looks to a handler without inverting
448
+ * the dependency edge that would make the two a circular pair.
449
+ *
450
+ * `TInputs` maps each tool name to its raw input, defaulting to
451
+ * {@link ToolDispatchRegistry} (the map a host augments), so a handler reaching the
452
+ * context's bus sees the full name union and each tool's input on `dispatch`. Until a host
453
+ * augments it that map is empty, and `dispatch` takes no name.
454
+ *
455
+ * `TOutputs` maps each tool name to the `data` its answer holds, defaulting to
456
+ * {@link ToolOutputRegistry}, the second map a host augments. `dispatch` answers the
457
+ * {@link ToolResult} of the named verb's data, so a reader takes a member of it after `ok` with
458
+ * no narrowing of its own, and a name the map does not hold answers `data` as `unknown`. The
459
+ * bus parses no answer: the type is held by each handler being typed by its contract's `output`,
460
+ * and by the testing bus, which checks every answer against that schema.
461
+ *
462
+ * `dispatch` is the typed entry point: a known literal name and its matching raw input,
463
+ * with a stray field or wrong name a compile error at the call site. `dispatchUnsafe` is
464
+ * the escape hatch for a dynamically-built name (an agent routing a model's
465
+ * tool-call, a bridge mapping a postMessage type) where the name is a runtime `string`
466
+ * the compiler cannot match against the union, and its answer is a plain {@link ToolResult}.
467
+ * A concrete bus always provides both, so the member is required, not optional.
468
+ */
469
+ export interface ToolBusDispatch<
470
+ TCtx,
471
+ TInputs extends object = ToolDispatchRegistry,
472
+ TOutputs extends object = ToolOutputRegistry,
473
+ > {
474
+ // The constraint is `object`, not `Record<string, unknown>`, and that is load-bearing
475
+ // rather than loose. `ToolDispatchRegistry` is an empty INTERFACE (the shape `declare
476
+ // module` can merge into), and an empty interface has no index signature, so it fails a
477
+ // `Record<string, unknown>` constraint in any program that has not augmented it. A host
478
+ // whose augmentation is always in the same program would never see it; a consumer who takes
479
+ // the default without registering tools would meet it at once.
480
+ dispatch<TName extends keyof TInputs & string>(
481
+ ctx: TCtx,
482
+ name: TName,
483
+ rawInput: TInputs[TName],
484
+ ): Promise<ToolResultOf<TOutputs, TName>>;
485
+ dispatchUnsafe(ctx: TCtx, name: string, rawInput: unknown): Promise<ToolResult>;
486
+ }
487
+
488
+ /**
489
+ * BusOnlyToolErrorCode is a failure code the bus raises and the wire never carries: one that
490
+ * describes the studio or a missed pointer gesture rather than the request. `toWireErrorCode`
491
+ * reports each as `internal`.
492
+ */
493
+ type BusOnlyToolErrorCode = "no-api" | "no-map" | "no-session" | "split-on-end" | "split-too-far";
494
+
495
+ /**
496
+ * busOnlyToolErrorCodes is every {@link BusOnlyToolErrorCode}, each keyed by itself: the set as a
497
+ * value, for the suite that holds the bus's codes against the wire's.
498
+ *
499
+ * The `satisfies` clause fails `tsc` in both directions, so the union and this literal are one
500
+ * list: a member the union gains leaves a missing key, and a key the union does not declare is
501
+ * an excess property.
502
+ */
503
+ export const busOnlyToolErrorCodes = {
504
+ "no-api": "no-api",
505
+ "no-map": "no-map",
506
+ "no-session": "no-session",
507
+ "split-on-end": "split-on-end",
508
+ "split-too-far": "split-too-far",
509
+ } as const satisfies { [K in BusOnlyToolErrorCode]: K };
510
+
511
+ /**
512
+ * toolErrorCodes is every code {@link toolErrorCodeSchema} accepts, each keyed by itself: the
513
+ * contract's `AgentToolErrorCode` and the bus's own {@link BusOnlyToolErrorCode}.
514
+ *
515
+ * The `satisfies` clause fails `tsc` in both directions: a code the contract adds leaves a
516
+ * missing key, and a code neither side declares is an excess property of the literal. Listed in
517
+ * the order the schema's `options` report them.
518
+ */
519
+ const toolErrorCodes = {
520
+ canceled: "canceled",
521
+ "capability-denied": "capability-denied",
522
+ "collab-locked": "collab-locked",
523
+ "confirmation-denied": "confirmation-denied",
524
+ "confirmation-timeout": "confirmation-timeout",
525
+ conflict: "conflict",
526
+ "draft-open": "draft-open",
527
+ "edit-in-progress": "edit-in-progress",
528
+ forbidden: "forbidden",
529
+ internal: "internal",
530
+ "invalid-input": "invalid-input",
531
+ "limit-reached": "limit-reached",
532
+ "no-api": "no-api",
533
+ "no-map": "no-map",
534
+ "no-session": "no-session",
535
+ "not-found": "not-found",
536
+ "rate-limited": "rate-limited",
537
+ "split-on-end": "split-on-end",
538
+ "split-too-far": "split-too-far",
539
+ timeout: "timeout",
540
+ unavailable: "unavailable",
541
+ "unknown-tool": "unknown-tool",
542
+ "upgrade-required": "upgrade-required",
543
+ } as const satisfies { [K in AgentToolErrorCode | BusOnlyToolErrorCode]: K };
544
+
545
+ /**
546
+ * toolErrorCodeSchema is the closed vocabulary of machine-readable failure codes a
547
+ * ToolResult may carry, the Zod source of truth so a consumer branches on a stable code
548
+ * rather than substring-matching the human-readable message. Its members are
549
+ * {@link toolErrorCodes}, and every one has a real producer:
550
+ *
551
+ * - "canceled": the run was ended by its caller before it produced its answer, such as a
552
+ * recording a cancel, a close or a newer recording stopped. Its own code rather than
553
+ * "internal" because nothing went wrong, and apart from "confirmation-denied", which is a
554
+ * prompt declined before anything ran.
555
+ * - "capability-denied": the context lacks the tool's capability gate.
556
+ * - "collab-locked": a collaborator holds the entity's soft-lock (a REMOTE peer),
557
+ * distinct from "edit-in-progress", which is the LOCAL one-edit-at-a-time gate.
558
+ * - "confirmation-denied": the confirm gate rejected, or was absent for a destructive tool.
559
+ * - "confirmation-timeout": a destructive server-side confirmation window elapsed with no
560
+ * answer. Separate from "confirmation-denied" because nobody refused: re-asking is
561
+ * reasonable here and rude after a refusal.
562
+ * - "conflict": a write lost a revision race (a 409), or a segment's or a waypoint's commit
563
+ * was asked with another draft while the create of that entity is still out, in which case
564
+ * no request is made.
565
+ * - "draft-open": a persisted-only verb was asked for while a draft owns the editor.
566
+ * - "edit-in-progress": another authoring engine is already armed, or a split pick is.
567
+ * - "forbidden": the caller is not allowed to perform the action (a 403).
568
+ * - "internal": an unclassified handler throw or failure (the catch-all).
569
+ * - "invalid-input": the schema rejected the raw input, or a server validation did (a 400).
570
+ * - "limit-reached": a ceiling was reached: one the agreement sets (its seats, its published
571
+ * itineraries, its monthly allowance), the itineraries a personal space keeps, or the co-pilot
572
+ * tabs the studio keeps open. An API refusal is one when an entry carries `LIMIT_REACHED` (a
573
+ * 429 naming no wait) or when a 429 names a wait longer than a minute, and a retry soon does
574
+ * not lift it.
575
+ * - "no-api": the handler needs a data seam the host did not supply. It, "no-map" and
576
+ * "no-session" are the only refusals that describe the STUDIO rather than the request, and
577
+ * they are codes for the same reason every other member is: a surface that can name the
578
+ * category can say something useful ("the studio isn't connected"), where a handler's own
579
+ * `error` string is written for a log and an agent, and a surface rendering it would be
580
+ * showing a reader a sentence nobody translated.
581
+ * - "no-map": the action drives the map and no map is mounted. Transient by nature: the
582
+ * canvas is still loading, so the surface answers "try again in a moment" rather than
583
+ * reporting a fault.
584
+ * - "no-session": the session, draft, wizard or pick the action acts on is not open. The
585
+ * editor is one-at-a-time in several places, and a verb aimed at a closed one is an
586
+ * ordering mistake rather than a failure of the thing it names.
587
+ * - "not-found": the targeted resource does not exist (a 404).
588
+ * - "rate-limited": the caller exceeded a per-minute rate limit (a 429 not coded `LIMIT_REACHED`
589
+ * naming no wait, or a wait of a minute or less), which a moment's wait clears.
590
+ * - "split-on-end": a split point resolved to the very start or end of a segment, where
591
+ * cutting would produce an empty half. Its own code because the surface answers it with
592
+ * "aim further along the line", which a category alone cannot say.
593
+ * - "split-too-far": a split point landed further from the line than the pointing
594
+ * tolerance allows. The fix is "click nearer the itinerary", not "aim elsewhere along it".
595
+ * - "timeout": the request outlived its budget (a 504). Its own code rather than
596
+ * "internal" because nothing is broken: the work was too large, so the surface answers
597
+ * with what would make it smaller.
598
+ * - "unavailable": the device or the page does not give what the action needs, such as a
599
+ * position the device cannot determine or a page with no geolocation. Its own code rather
600
+ * than "internal" because the studio is whole, and apart from "forbidden", which is a
601
+ * permission the reader or the device refused.
602
+ * - "unknown-tool": the dispatched name is not registered.
603
+ * - "upgrade-required": the action needs a product the caller's agreement does not include.
604
+ *
605
+ * The gate codes reuse the spellings the bus's own dispatch event carries, so telemetry
606
+ * and the structured result speak one vocabulary.
607
+ *
608
+ * One spelling, the contract's: every code is kebab-case. A code the contract's
609
+ * `AgentToolErrorCode` also declares is spelled exactly as it is there, because an agent run
610
+ * copies it onto the model's tool result verbatim. The ones {@link busOnlyToolErrorCodes} holds
611
+ * (`no-api`, `no-map`, `no-session`, `split-on-end`, `split-too-far`) never reach the wire at
612
+ * all: `toWireErrorCode` reports each as `internal`, the contract's code for a failure with no
613
+ * more specific one.
614
+ */
615
+ export const toolErrorCodeSchema = z.enum(toolErrorCodes);
616
+
617
+ /**
618
+ * ToolErrorCode is the machine-readable failure code a ToolResult may carry, derived
619
+ * from {@link toolErrorCodeSchema}.
620
+ */
621
+ export type ToolErrorCode = z.infer<typeof toolErrorCodeSchema>;
622
+
623
+ /**
624
+ * ToolResult is the structured outcome every handler returns: success carries a
625
+ * human/model-readable summary (and optional data); failure carries an error string and,
626
+ * when classified, a machine-readable {@link ToolErrorCode}. `code` is optional and
627
+ * additive: an unclassified failure omits it, while a classified one carries it so a
628
+ * consumer branches on the code rather than substring-matching the message. The bus
629
+ * boundary stamps the gate codes; a handler stamps the codes it knows.
630
+ *
631
+ * **`summary` and `error` are MACHINE NARRATION and must never be rendered to a user.** They
632
+ * are written for three readers and a person is none of them: a model deciding what to do next,
633
+ * an event log, and whoever is reading that log. They are in English because this package has no
634
+ * language (it ships no strings and takes no locale), so a surface that put one on screen would
635
+ * be showing a French reader an English sentence nobody translated, in a voice written for a
636
+ * model. What a surface renders instead is `detail` when the server supplied one, and otherwise
637
+ * its own copy for the `code`. `studio-react`'s boundary test refuses a render of either field.
638
+ *
639
+ * `detail` is the server's own already-localized sentence for the failure, lifted off the
640
+ * error envelope. It is deliberately separate from `error`, which stays the technical
641
+ * string analytics and an agent read. A code alone can only say a category
642
+ * (`invalid-input`), while `detail` says which input and why, so a surface prefers it when
643
+ * present and falls back to its own per-code copy when it is not. This package carries NO
644
+ * strings: it forwards the server's verbatim and never translates.
645
+ *
646
+ * `data` is a required member where `TData` leaves `undefined` out, and an optional one
647
+ * otherwise. So a reader of a verb whose data is an object takes a member of it after `ok` with
648
+ * no narrowing of its own, and a handler that leaves the data out does not compile. A bare
649
+ * `ToolResult`, whose data is `unknown`, and a `ToolResult<undefined>`, the answer of a verb with
650
+ * no data, both hold it as optional: neither says there is anything to read.
651
+ *
652
+ * The condition tests the whole of `TData` at once, so a union is one answer and never one
653
+ * result per member. It is written with `TData` on the checked side, against every value but
654
+ * `undefined`, which is what lets TypeScript relate the results of two unresolved data types by
655
+ * relating the data: a {@link Tool} stating an `output` is assignable to a bare one on that
656
+ * account. The same test written as `undefined extends TData` puts the type on the far side,
657
+ * where two unresolved types have to be identical.
658
+ */
659
+ export type ToolResult<TData = unknown> =
660
+ | ([TData] extends [NonNullable<unknown> | null]
661
+ ? { data: TData; ok: true; summary: string }
662
+ : { data?: TData | undefined; ok: true; summary: string })
663
+ | { code?: ToolErrorCode | undefined; detail?: string | undefined; error: string; ok: false };
664
+
665
+ /**
666
+ * ToolFailure is the refusal arm of {@link ToolResult}: an `error`, with a {@link ToolErrorCode}
667
+ * when the failure is classified and the server's `detail` when it sent one.
668
+ *
669
+ * Named so a signature that can only fail says so: `isConfirmationWithheld` narrows to it, and a
670
+ * handler's guard returns the failure, or null to carry on. An inline
671
+ * `{ error: string; ok: false }` is the same shape only until the arm grows a member: a copy
672
+ * without `code` fails to compile at the guard that sets one, which is the good case, and drops
673
+ * the code from a refusal that passes through it, which is the silent one.
674
+ */
675
+ export type ToolFailure = Extract<ToolResult, { ok: false }>;
676
+
677
+ /**
678
+ * Tool is the unit of the bus: a stable namespaced name, a model-facing description, a
679
+ * Zod input schema (→ runtime validation + types + JSON Schema), a capability gate, an
680
+ * optional destructive-confirmation flag, an optional confirmation policy, and a handler
681
+ * taking (ctx, input). `confirmation` is honored only when `requiresConfirmation` is set.
682
+ *
683
+ * `TCtx` is the execution context the host threads through: the one part of a tool that
684
+ * cannot be published, and therefore the parameter that lets the rest of it be.
685
+ *
686
+ * The optional `TName` parameter pins `name` to a string literal. A bare `Tool<Ctx>`
687
+ * leaves it the open `string`, while a definition supplying its own name lets a registry
688
+ * require, at compile time, that each entry's key equals the tool's own name, so a typo
689
+ * in either is a type error rather than a runtime drift a test has to catch.
690
+ *
691
+ * `agentHidden` opts a tool out of the model-facing manifest: a hidden tool stays fully
692
+ * registered and dispatchable (a human click or an internal chain runs it as it runs
693
+ * any other) and is refused only at the model entry point. It marks the tools a system
694
+ * prompt categorically forbids, so the model is never even offered them rather than the
695
+ * prompt alone holding the line.
696
+ *
697
+ * `TCapability` is how a host closes {@link ToolCapability} again on its own side. The published
698
+ * union is open, because the words this package can define are not an authorization model;
699
+ * a host that has one binds its own enum here once (`Tool<Ctx, TSchema, TName, MyCapability>`),
700
+ * and a mistyped capability is then a compile error at the definition rather than a refusal at
701
+ * runtime. It has to be a parameter rather than something a host narrows by intersecting: an
702
+ * intersection stops being the same generic interface, and the comparison falls off the variance
703
+ * path onto a structural one that `confirmationValues` cannot satisfy.
704
+ *
705
+ * `TOutput` is the Zod schema of the `data` the tool answers, and it types the handler: one that
706
+ * returns other data, or none where the schema asks for some, does not compile. Left at its
707
+ * default the data is `unknown` and the handler answers a plain {@link ToolResult}, so a tool
708
+ * declared as a bare `Tool<Ctx>` compiles with or without an `output`.
709
+ */
710
+ export interface Tool<
711
+ TCtx,
712
+ TSchema extends z.ZodTypeAny = z.ZodTypeAny,
713
+ TName extends string = string,
714
+ TCapability extends ToolCapability = ToolCapability,
715
+ TOutput extends z.ZodTypeAny = z.ZodTypeAny,
716
+ > {
717
+ agentHidden?: boolean | undefined;
718
+ capability: TCapability;
719
+ confirmation?: ToolConfirmation | undefined;
720
+ /**
721
+ * confirmationValues resolves the interpolation values the confirm surface fills this
722
+ * tool's policy keys with, so a prompt can name the entities it is about to act on. It
723
+ * runs AFTER the input parses and BEFORE the handler, with the same context the handler
724
+ * will get, so it may read state to turn ids into names.
725
+ *
726
+ * It must produce a plain record and nothing else: no writes, no dispatch. A resolver
727
+ * that throws costs only the interpolation: the prompt still opens, rendering its
728
+ * placeholders verbatim, so a bad resolver can never turn a confirmable action into a
729
+ * rejected dispatch.
730
+ *
731
+ * @default undefined, and the prompt renders its placeholders verbatim
732
+ */
733
+ confirmationValues?: ((ctx: TCtx, input: z.infer<TSchema>) => ConfirmationValues) | undefined;
734
+ description: string;
735
+ handler: (
736
+ ctx: TCtx,
737
+ input: z.infer<TSchema>,
738
+ ) => ToolResult<z.infer<TOutput>> | Promise<ToolResult<z.infer<TOutput>>>;
739
+ input: TSchema;
740
+ name: TName;
741
+ /**
742
+ * output is the Zod schema of the `data` an `ok` answer holds, stated beside `input`.
743
+ *
744
+ * It is what the handler is typed by, and the bus that ships never parses with it: what a
745
+ * handler returns is what a reader reads. The testing bus is where it runs, against every
746
+ * answer of the tool. A verb that answers no data states `toolNoDataSchema`.
747
+ *
748
+ * It is transform-free for that reason. A schema that changes what it parses describes a value
749
+ * no reader receives.
750
+ *
751
+ * @default undefined, and the data is `unknown`
752
+ */
753
+ output?: TOutput | undefined;
754
+ /**
755
+ * precondition answers what the tool refuses before it asks: a {@link ToolFailure} for a call
756
+ * the tool can already tell it refuses, or null to carry on.
757
+ *
758
+ * The bus runs it after the input parses and before the confirmation, with the context the
759
+ * handler gets, and runs it for a tool that asks nothing as well. A failure it answers is the
760
+ * dispatch's answer: no prompt is raised and the handler never runs, so a reader is never asked
761
+ * to approve what the tool then refuses. One that throws is answered as a handler that throws
762
+ * is.
763
+ *
764
+ * It reads state and writes nothing, as `confirmationValues` does, and it answers at once: a
765
+ * check that waits on a request is the handler's. The handler keeps every refusal it states
766
+ * here, because what a precondition read can change while the reader is asked.
767
+ *
768
+ * @default undefined, and nothing is refused ahead of the confirmation
769
+ */
770
+ precondition?: ((ctx: TCtx, input: z.infer<TSchema>) => ToolFailure | null) | undefined;
771
+ requiresConfirmation?: boolean | undefined;
772
+ }
773
+
774
+ /**
775
+ * JsonSchema is a JSON Schema object as produced by `z.toJSONSchema`: the shape a
776
+ * manifest renders a tool's input into for a model or a documentation page. Reusing Zod's
777
+ * own type keeps a manifest entry assignable to a gateway's `parameters` object with no
778
+ * cast.
779
+ */
780
+ export type JsonSchema = z.core.JSONSchema.BaseSchema;
781
+
782
+ /**
783
+ * StudioToolManifestEntry is the model/UI-facing description of one of the STUDIO's tools, with
784
+ * the input schema rendered as JSON Schema.
785
+ *
786
+ * `Studio` in the name because `@mountaya/elements/agent` publishes a `ToolManifestEntry` of its
787
+ * own, and the two are not the same shape: that one is what the agent SESSION consumes, typed
788
+ * against the agent service's `parameters`, where this is what a studio PRODUCES, typed against
789
+ * the studio's capability vocabulary and Zod's JSON Schema. One name for both would hand a
790
+ * consumer importing the obvious one a type error several frames from the import.
791
+ */
792
+ export interface StudioToolManifestEntry {
793
+ capability: ToolCapability;
794
+ description: string;
795
+ inputSchema: JsonSchema;
796
+ name: string;
797
+ /**
798
+ * Whether the tool only reads state and changes nothing. Absent means unknown, which
799
+ * every consumer must treat as "may mutate": a run uses it to decide what its
800
+ * transcript may safely drop, and guessing wrong there erases the record of a real
801
+ * change.
802
+ */
803
+ readOnly?: boolean | undefined;
804
+ requiresConfirmation: boolean;
805
+ }