@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.
- package/CHANGELOG.md +39 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2854 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1257 -0
- package/dist/agent/index.d.ts +1257 -0
- package/dist/agent/index.js +2818 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/bus-BwiNiXdH.d.ts +514 -0
- package/dist/bus-DzmhPwdK.d.cts +514 -0
- package/dist/chainModel-B23pEP_1.d.cts +127 -0
- package/dist/chainModel-B23pEP_1.d.ts +127 -0
- package/dist/chunk-2HFY7ETU.js +5721 -0
- package/dist/chunk-2HFY7ETU.js.map +1 -0
- package/dist/chunk-355TOXSB.js +72 -0
- package/dist/chunk-355TOXSB.js.map +1 -0
- package/dist/chunk-4ZCUZVSV.js +10275 -0
- package/dist/chunk-4ZCUZVSV.js.map +1 -0
- package/dist/chunk-6HEKY3NF.js +95 -0
- package/dist/chunk-6HEKY3NF.js.map +1 -0
- package/dist/chunk-7GFLGGBX.cjs +8 -0
- package/dist/chunk-7GFLGGBX.cjs.map +1 -0
- package/dist/chunk-7NBRCENN.cjs +19 -0
- package/dist/chunk-7NBRCENN.cjs.map +1 -0
- package/dist/chunk-AF5GCXE3.js +8 -0
- package/dist/chunk-AF5GCXE3.js.map +1 -0
- package/dist/chunk-CJDIFRGZ.cjs +2005 -0
- package/dist/chunk-CJDIFRGZ.cjs.map +1 -0
- package/dist/chunk-CNPZY7N3.js +349 -0
- package/dist/chunk-CNPZY7N3.js.map +1 -0
- package/dist/chunk-DZJHTWSF.cjs +45 -0
- package/dist/chunk-DZJHTWSF.cjs.map +1 -0
- package/dist/chunk-EABIHHWA.js +42 -0
- package/dist/chunk-EABIHHWA.js.map +1 -0
- package/dist/chunk-EKZWV6RS.cjs +415 -0
- package/dist/chunk-EKZWV6RS.cjs.map +1 -0
- package/dist/chunk-EOKRXXAC.cjs +24 -0
- package/dist/chunk-EOKRXXAC.cjs.map +1 -0
- package/dist/chunk-F73W2ZTJ.js +1126 -0
- package/dist/chunk-F73W2ZTJ.js.map +1 -0
- package/dist/chunk-H4DVOZ5O.js +1897 -0
- package/dist/chunk-H4DVOZ5O.js.map +1 -0
- package/dist/chunk-HI52PBFT.cjs +10314 -0
- package/dist/chunk-HI52PBFT.cjs.map +1 -0
- package/dist/chunk-IDBXFBLG.cjs +1225 -0
- package/dist/chunk-IDBXFBLG.cjs.map +1 -0
- package/dist/chunk-LBWTJZUJ.js +297 -0
- package/dist/chunk-LBWTJZUJ.js.map +1 -0
- package/dist/chunk-NCLA6DKD.cjs +310 -0
- package/dist/chunk-NCLA6DKD.cjs.map +1 -0
- package/dist/chunk-O4MC5DPD.js +19 -0
- package/dist/chunk-O4MC5DPD.js.map +1 -0
- package/dist/chunk-OP37FKW6.cjs +98 -0
- package/dist/chunk-OP37FKW6.cjs.map +1 -0
- package/dist/chunk-OQSYFH3Z.cjs +5945 -0
- package/dist/chunk-OQSYFH3Z.cjs.map +1 -0
- package/dist/chunk-PACIO4NS.cjs +26 -0
- package/dist/chunk-PACIO4NS.cjs.map +1 -0
- package/dist/chunk-PSZ2R3TC.cjs +75 -0
- package/dist/chunk-PSZ2R3TC.cjs.map +1 -0
- package/dist/chunk-QFO5CZG2.cjs +136 -0
- package/dist/chunk-QFO5CZG2.cjs.map +1 -0
- package/dist/chunk-QL63MUEW.cjs +140 -0
- package/dist/chunk-QL63MUEW.cjs.map +1 -0
- package/dist/chunk-RFUPPVZO.js +17 -0
- package/dist/chunk-RFUPPVZO.js.map +1 -0
- package/dist/chunk-RPG2LWMP.js +23 -0
- package/dist/chunk-RPG2LWMP.js.map +1 -0
- package/dist/chunk-TIBXK6B7.cjs +12 -0
- package/dist/chunk-TIBXK6B7.cjs.map +1 -0
- package/dist/chunk-UU65VNEV.js +381 -0
- package/dist/chunk-UU65VNEV.js.map +1 -0
- package/dist/chunk-VGX6TR2I.js +209 -0
- package/dist/chunk-VGX6TR2I.js.map +1 -0
- package/dist/chunk-WUTDDBVP.js +130 -0
- package/dist/chunk-WUTDDBVP.js.map +1 -0
- package/dist/chunk-WVQQLKCI.cjs +224 -0
- package/dist/chunk-WVQQLKCI.cjs.map +1 -0
- package/dist/chunk-WZYXG3SE.js +111 -0
- package/dist/chunk-WZYXG3SE.js.map +1 -0
- package/dist/chunk-XDI2X3KE.js +6 -0
- package/dist/chunk-XDI2X3KE.js.map +1 -0
- package/dist/chunk-XKHLRIC7.cjs +381 -0
- package/dist/chunk-XKHLRIC7.cjs.map +1 -0
- package/dist/context-DNtd2WUv.d.cts +11666 -0
- package/dist/context-DgB72Bur.d.ts +11666 -0
- package/dist/directorThreads-CqmvsV8b.d.cts +80 -0
- package/dist/directorThreads-CqmvsV8b.d.ts +80 -0
- package/dist/en-Bu4Ti9Ev.d.cts +2315 -0
- package/dist/en-Bu4Ti9Ev.d.ts +2315 -0
- package/dist/engines/index.cjs +3446 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2216 -0
- package/dist/engines/index.d.ts +2216 -0
- package/dist/engines/index.js +3416 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +99 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +445 -0
- package/dist/handlers/index.d.ts +445 -0
- package/dist/handlers/index.js +42 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +4562 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7297 -0
- package/dist/index.d.ts +7297 -0
- package/dist/index.js +3223 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +977 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +313 -0
- package/dist/plugins/index.d.ts +313 -0
- package/dist/plugins/index.js +933 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/saveFile-j-1kkApx.d.cts +123 -0
- package/dist/saveFile-j-1kkApx.d.ts +123 -0
- package/dist/seams/index.cjs +152 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +485 -0
- package/dist/seams/index.d.ts +485 -0
- package/dist/seams/index.js +79 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/shareLink-B6hlt942.d.ts +144 -0
- package/dist/shareLink-C7rIMb7x.d.ts +527 -0
- package/dist/shareLink-CnTxxXjp.d.cts +144 -0
- package/dist/shareLink-DyZVYH2V.d.cts +527 -0
- package/dist/strings/fr/index.cjs +2121 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +19 -0
- package/dist/strings/fr/index.d.ts +19 -0
- package/dist/strings/fr/index.js +2119 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2678 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +731 -0
- package/dist/strings/index.d.ts +731 -0
- package/dist/strings/index.js +2644 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/studioPlugin-C3C7VjMy.d.ts +847 -0
- package/dist/studioPlugin-Cf3OBNUv.d.cts +847 -0
- package/dist/tabs-B2nRO4p_.d.cts +15 -0
- package/dist/tabs-B2nRO4p_.d.ts +15 -0
- package/dist/testing/index.cjs +292 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +306 -0
- package/dist/testing/index.d.ts +306 -0
- package/dist/testing/index.js +284 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time/index.cjs +28 -0
- package/dist/time/index.cjs.map +1 -0
- package/dist/time/index.d.cts +43 -0
- package/dist/time/index.d.ts +43 -0
- package/dist/time/index.js +26 -0
- package/dist/time/index.js.map +1 -0
- package/dist/types-BzJRV6UI.d.cts +845 -0
- package/dist/types-BzJRV6UI.d.ts +845 -0
- package/dist/zoneForm-CdYNtnnA.d.cts +320 -0
- package/dist/zoneForm-mG85yt5e.d.ts +320 -0
- package/package.json +225 -4
- package/src/agent/engines/agentThreads.ts +1601 -0
- package/src/agent/engines/directorChat.ts +500 -0
- package/src/agent/index.ts +67 -0
- package/src/agent/rules/agentEditLock.ts +115 -0
- package/src/agent/rules/agentErrorCopy.ts +44 -0
- package/src/agent/rules/copilotOrganization.ts +36 -0
- package/src/agent/rules/playbook.gen.ts +444 -0
- package/src/agent/rules/router.ts +518 -0
- package/src/agent/rules/stateDelta.ts +28 -0
- package/src/agent/rules/studioRouter.ts +123 -0
- package/src/agent/rules/surfaces.gen.ts +633 -0
- package/src/agent/rules/threadsUrl.ts +48 -0
- package/src/agent/rules/transcriptObserver.ts +90 -0
- package/src/agent/stores/agentThreads.ts +454 -0
- package/src/bus/contracts/noData.ts +18 -0
- package/src/bus/contracts/shared.ts +172 -0
- package/src/bus/contracts/studioTools.ts +224 -0
- package/src/bus/rules/bus.ts +858 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +26 -0
- package/src/bus/rules/errors.ts +401 -0
- package/src/bus/rules/handlerErrors.ts +103 -0
- package/src/bus/rules/handlerRegistry.ts +627 -0
- package/src/bus/rules/inputSchema.ts +232 -0
- package/src/bus/rules/invalidInput.ts +441 -0
- package/src/bus/rules/lateBoundTools.ts +100 -0
- package/src/bus/rules/studioRegistry.ts +324 -0
- package/src/bus/rules/studioToolBus.ts +73 -0
- package/src/bus/rules/types.ts +805 -0
- package/src/chrome/contracts/alert.ts +42 -0
- package/src/chrome/contracts/itinerary.ts +26 -0
- package/src/chrome/contracts/map.ts +23 -0
- package/src/chrome/contracts/overlay.ts +46 -0
- package/src/chrome/contracts/panel.ts +29 -0
- package/src/chrome/contracts/question.ts +52 -0
- package/src/chrome/contracts/selection.ts +26 -0
- package/src/chrome/contracts/sidenav.ts +23 -0
- package/src/chrome/contracts/snapshot.ts +319 -0
- package/src/chrome/contracts/state.ts +22 -0
- package/src/chrome/contracts/tabs.ts +56 -0
- package/src/chrome/handlers/alert.ts +91 -0
- package/src/chrome/handlers/introspection.ts +180 -0
- package/src/chrome/handlers/panels.ts +42 -0
- package/src/chrome/handlers/question.ts +24 -0
- package/src/chrome/handlers/sidenav.ts +116 -0
- package/src/chrome/handlers/snapshot.ts +451 -0
- package/src/chrome/handlers/stateDelta.ts +125 -0
- package/src/chrome/handlers/tabs.ts +143 -0
- package/src/chrome/handlers/timestamp.ts +19 -0
- package/src/chrome/rules/agentSelectors.ts +210 -0
- package/src/chrome/rules/mapAlert.ts +13 -0
- package/src/chrome/rules/question.ts +25 -0
- package/src/chrome/rules/tabs.ts +13 -0
- package/src/chrome/stores/activeDraftSession.ts +134 -0
- package/src/chrome/stores/chrome.ts +527 -0
- package/src/chrome/stores/uiStore.ts +573 -0
- package/src/collab/contracts/collab.ts +261 -0
- package/src/collab/handlers/collab.ts +468 -0
- package/src/collab/rules/toolNames.ts +33 -0
- package/src/collab/stores/collab.ts +899 -0
- package/src/collections/contracts/collection.ts +182 -0
- package/src/collections/handlers/collectionAttach.ts +141 -0
- package/src/collections/handlers/collections.ts +499 -0
- package/src/collections/handlers/heldCollection.ts +42 -0
- package/src/collections/handlers/restCollections.ts +386 -0
- package/src/collections/rules/collections.ts +138 -0
- package/src/collections/rules/entityCollections.ts +53 -0
- package/src/collections/stores/collections.ts +133 -0
- package/src/data/contracts/data.ts +233 -0
- package/src/data/contracts/itinerary.ts +71 -0
- package/src/data/handlers/activityResolve.ts +76 -0
- package/src/data/handlers/data.ts +200 -0
- package/src/data/handlers/graphql.ts +26 -0
- package/src/data/handlers/mutationSink.ts +1577 -0
- package/src/data/handlers/profile.ts +83 -0
- package/src/data/handlers/writeThrough.ts +417 -0
- package/src/data/rules/cache.ts +181 -0
- package/src/data/rules/dataTypes.ts +40 -0
- package/src/data/rules/keys.ts +106 -0
- package/src/data/rules/persistence.ts +1058 -0
- package/src/data/rules/requestBody.ts +43 -0
- package/src/data/rules/restErrors.ts +354 -0
- package/src/data/rules/sessionSurface.ts +156 -0
- package/src/data/rules/toolResultData.ts +73 -0
- package/src/data/rules/uuid.ts +24 -0
- package/src/edit/contracts/edit.ts +37 -0
- package/src/edit/contracts/itinerary.ts +57 -0
- package/src/edit/handlers/draftCommit.ts +257 -0
- package/src/edit/handlers/editDiscard.ts +34 -0
- package/src/edit/handlers/editLock.ts +949 -0
- package/src/edit/handlers/editor.ts +203 -0
- package/src/edit/handlers/formUnsaved.ts +24 -0
- package/src/edit/rules/draftMetadata.ts +117 -0
- package/src/edit/rules/editKeyboard.ts +222 -0
- package/src/edit/rules/editShortcuts.ts +102 -0
- package/src/edit/rules/editTooltip.ts +174 -0
- package/src/edit/rules/editorTaken.ts +49 -0
- package/src/edit/rules/history.ts +26 -0
- package/src/edit/rules/unsavedWork.ts +60 -0
- package/src/edit/stores/editorReservation.ts +70 -0
- package/src/edit/stores/formsUnsaved.ts +54 -0
- package/src/embed/contracts/embed.ts +48 -0
- package/src/embed/engines/embedFraming.ts +1329 -0
- package/src/embed/engines/embedReady.ts +353 -0
- package/src/embed/engines/framingPageSession.ts +169 -0
- package/src/embed/handlers/embed.ts +130 -0
- package/src/embed/rules/allowedDomains.ts +71 -0
- package/src/embed/rules/bridgeMessages.ts +224 -0
- package/src/embed/rules/defaults.ts +173 -0
- package/src/embed/rules/displaySeed.ts +115 -0
- package/src/embed/rules/embedAllowlist.ts +146 -0
- package/src/embed/rules/embedConstraints.ts +215 -0
- package/src/embed/rules/embedElements.ts +277 -0
- package/src/embed/rules/embedSectionFields.ts +126 -0
- package/src/embed/rules/embedSecurity.ts +116 -0
- package/src/embed/rules/fieldDependencies.ts +87 -0
- package/src/embed/rules/fieldOptions.ts +138 -0
- package/src/embed/rules/layerOptions.ts +161 -0
- package/src/embed/rules/readyProtocol.ts +66 -0
- package/src/embed/rules/safetyRules.ts +213 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +269 -0
- package/src/embed/stores/embed.ts +60 -0
- package/src/embed/stores/embedContent.ts +77 -0
- package/src/engines/index.ts +81 -0
- package/src/handlers/index.ts +66 -0
- package/src/index.ts +1086 -0
- package/src/itinerary/contracts/itinerary.ts +705 -0
- package/src/itinerary/engines/itineraryPace.ts +612 -0
- package/src/itinerary/engines/profileMarker.ts +238 -0
- package/src/itinerary/handlers/importStaging.ts +352 -0
- package/src/itinerary/handlers/itinerary.ts +572 -0
- package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
- package/src/itinerary/handlers/itineraryExport.ts +117 -0
- package/src/itinerary/handlers/itineraryImport.ts +783 -0
- package/src/itinerary/handlers/itineraryPublish.ts +118 -0
- package/src/itinerary/handlers/itinerarySelection.ts +354 -0
- package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
- package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
- package/src/itinerary/handlers/publicationScope.ts +118 -0
- package/src/itinerary/handlers/restItineraries.ts +752 -0
- package/src/itinerary/handlers/restItineraryExport.ts +70 -0
- package/src/itinerary/handlers/restItineraryImport.ts +311 -0
- package/src/itinerary/handlers/restItineraryPace.ts +87 -0
- package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
- package/src/itinerary/handlers/suggestParams.ts +379 -0
- package/src/itinerary/handlers/suggestStaging.ts +363 -0
- package/src/itinerary/handlers/surfaceOpen.ts +389 -0
- package/src/itinerary/rules/activity.ts +139 -0
- package/src/itinerary/rules/analysis.ts +42 -0
- package/src/itinerary/rules/ceiling.ts +49 -0
- package/src/itinerary/rules/createFlow.ts +107 -0
- package/src/itinerary/rules/densify.ts +440 -0
- package/src/itinerary/rules/draftSurface.ts +219 -0
- package/src/itinerary/rules/editorView.ts +83 -0
- package/src/itinerary/rules/export.ts +159 -0
- package/src/itinerary/rules/friendlyName.ts +77 -0
- package/src/itinerary/rules/import.ts +1052 -0
- package/src/itinerary/rules/importFiles.ts +140 -0
- package/src/itinerary/rules/importTotals.ts +77 -0
- package/src/itinerary/rules/liveSegment.ts +712 -0
- package/src/itinerary/rules/lngLat.ts +17 -0
- package/src/itinerary/rules/mapSync.ts +100 -0
- package/src/itinerary/rules/previewRender.ts +416 -0
- package/src/itinerary/rules/profileReadout.ts +216 -0
- package/src/itinerary/rules/routing.ts +707 -0
- package/src/itinerary/rules/suggest.ts +522 -0
- package/src/itinerary/rules/suggestionPreview.ts +119 -0
- package/src/itinerary/rules/view.ts +61 -0
- package/src/itinerary/stores/importSession.ts +319 -0
- package/src/itinerary/stores/itinerary.ts +331 -0
- package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
- package/src/itinerary/stores/sessionIdentity.ts +43 -0
- package/src/itinerary/stores/suggestSession.ts +418 -0
- package/src/layers/contracts/itinerary.ts +46 -0
- package/src/layers/contracts/overlay.ts +132 -0
- package/src/layers/handlers/enrichment.ts +36 -0
- package/src/layers/handlers/overlay.ts +406 -0
- package/src/layers/handlers/restLayers.ts +94 -0
- package/src/layers/handlers/tiles.ts +25 -0
- package/src/layers/rules/layers.ts +212 -0
- package/src/layers/rules/overlayInstant.ts +12 -0
- package/src/layers/rules/reachabilityIcon.ts +18 -0
- package/src/layers/rules/readout.ts +102 -0
- package/src/layers/stores/layers.ts +262 -0
- package/src/map/contracts/contextmenu.ts +33 -0
- package/src/map/contracts/geolocate.ts +37 -0
- package/src/map/contracts/map.ts +146 -0
- package/src/map/contracts/streetview.ts +53 -0
- package/src/map/contracts/terrain.ts +152 -0
- package/src/map/handlers/contextMenu.ts +135 -0
- package/src/map/handlers/geolocate.ts +52 -0
- package/src/map/handlers/map.ts +391 -0
- package/src/map/handlers/streetview.ts +94 -0
- package/src/map/handlers/terrain.ts +663 -0
- package/src/map/rules/baseTerrain.ts +75 -0
- package/src/map/rules/clickTargets.ts +464 -0
- package/src/map/rules/constraints.ts +32 -0
- package/src/map/rules/contextMenuReadout.ts +67 -0
- package/src/map/rules/coordinates.ts +71 -0
- package/src/map/rules/itineraryFit.ts +8 -0
- package/src/map/rules/mapEvents.ts +64 -0
- package/src/map/rules/mapProjection.ts +476 -0
- package/src/map/rules/terrainReading.ts +62 -0
- package/src/plugins/contracts/ids.ts +66 -0
- package/src/plugins/contracts/plugin.ts +200 -0
- package/src/plugins/contracts/slots.ts +137 -0
- package/src/plugins/engines/studioPlugin.ts +1365 -0
- package/src/plugins/index.ts +111 -0
- package/src/plugins/rules/contributions.ts +152 -0
- package/src/plugins/rules/errors.ts +60 -0
- package/src/plugins/rules/ids.ts +42 -0
- package/src/plugins/rules/validation.ts +249 -0
- package/src/rules/listeners.ts +57 -0
- package/src/rules/origin.ts +13 -0
- package/src/rules/storeWrite.ts +37 -0
- package/src/rules/types.ts +136 -0
- package/src/seams/index.ts +79 -0
- package/src/seams/rules/clock.ts +28 -0
- package/src/seams/rules/formatters.ts +209 -0
- package/src/seams/rules/ids.ts +102 -0
- package/src/seams/rules/links.ts +66 -0
- package/src/seams/rules/navigation.ts +222 -0
- package/src/seams/rules/notify.ts +49 -0
- package/src/seams/rules/persistenceDrawer.ts +220 -0
- package/src/seams/rules/saveFile.ts +101 -0
- package/src/seams/rules/seams.ts +156 -0
- package/src/seams/rules/storage.ts +116 -0
- package/src/search/contracts/overlay.ts +74 -0
- package/src/search/contracts/search.ts +197 -0
- package/src/search/handlers/pois.ts +57 -0
- package/src/search/handlers/search.ts +280 -0
- package/src/search/rules/params.ts +925 -0
- package/src/search/rules/poiGroups.ts +138 -0
- package/src/search/rules/searchFetch.ts +139 -0
- package/src/search/rules/timeWindow.ts +30 -0
- package/src/search/stores/search.ts +51 -0
- package/src/segments/contracts/itinerary.ts +433 -0
- package/src/segments/contracts/segment.ts +35 -0
- package/src/segments/engines/segmentDraft.ts +926 -0
- package/src/segments/handlers/chainGuards.ts +67 -0
- package/src/segments/handlers/directions.ts +44 -0
- package/src/segments/handlers/itineraryEcho.ts +45 -0
- package/src/segments/handlers/roadAccessDialog.ts +34 -0
- package/src/segments/handlers/segment.ts +111 -0
- package/src/segments/handlers/segmentEdit.ts +1341 -0
- package/src/segments/handlers/segmentGroups.ts +347 -0
- package/src/segments/handlers/segmentStructure.ts +1144 -0
- package/src/segments/rules/chain.ts +196 -0
- package/src/segments/rules/chainModel.ts +217 -0
- package/src/segments/rules/colors.ts +11 -0
- package/src/segments/rules/commit.ts +76 -0
- package/src/segments/rules/draft.ts +90 -0
- package/src/segments/rules/draftDisposition.ts +43 -0
- package/src/segments/rules/draftSegmentEdit.ts +129 -0
- package/src/segments/rules/engine.ts +222 -0
- package/src/segments/rules/groupSave.ts +234 -0
- package/src/segments/rules/hazardPrompt.ts +60 -0
- package/src/segments/rules/itineraryEcho.ts +40 -0
- package/src/segments/rules/liveSegmentProjection.ts +55 -0
- package/src/segments/rules/merge.ts +51 -0
- package/src/segments/rules/metrics.ts +456 -0
- package/src/segments/rules/naming.ts +168 -0
- package/src/segments/rules/segmentArming.ts +144 -0
- package/src/segments/rules/splitPick.ts +84 -0
- package/src/segments/rules/viaSimplify.ts +230 -0
- package/src/segments/stores/directions.ts +77 -0
- package/src/segments/stores/roadAccessDialog.ts +58 -0
- package/src/segments/stores/segmentEdit.ts +922 -0
- package/src/segments/stores/segmentGroupEdit.ts +84 -0
- package/src/segments/stores/segmentSplit.ts +77 -0
- package/src/share/contracts/share.ts +39 -0
- package/src/share/contracts/shareLink.ts +63 -0
- package/src/share/engines/shareLink.ts +1053 -0
- package/src/share/handlers/share.ts +47 -0
- package/src/share/handlers/shareLink.ts +231 -0
- package/src/share/handlers/shareScope.ts +54 -0
- package/src/share/rules/link.ts +89 -0
- package/src/share/rules/shareLink.ts +218 -0
- package/src/share/rules/targets.ts +92 -0
- package/src/share/rules/viewConfig.ts +95 -0
- package/src/share/stores/share.ts +58 -0
- package/src/strings/fr/index.ts +18 -0
- package/src/strings/fr/rules/fr.ts +2368 -0
- package/src/strings/index.ts +98 -0
- package/src/strings/rules/confirmCopy.ts +156 -0
- package/src/strings/rules/draftToolNames.ts +94 -0
- package/src/strings/rules/en.ts +2519 -0
- package/src/strings/rules/failureAlert.ts +115 -0
- package/src/strings/rules/formError.ts +400 -0
- package/src/strings/rules/maneuvers.ts +107 -0
- package/src/strings/rules/outputOptions.ts +126 -0
- package/src/strings/rules/publicationState.ts +100 -0
- package/src/strings/rules/routeHazardCopy.ts +62 -0
- package/src/strings/rules/searchLabels.ts +50 -0
- package/src/strings/rules/segmentChainVerbs.ts +62 -0
- package/src/strings/rules/studioCopy.ts +130 -0
- package/src/strings/rules/unitOptions.ts +119 -0
- package/src/testing/checkedBus.ts +226 -0
- package/src/testing/index.ts +34 -0
- package/src/testing/plugins.ts +106 -0
- package/src/testing/studio.ts +267 -0
- package/src/testing/urlSeam.ts +153 -0
- package/src/time/index.ts +12 -0
- package/src/time/rules/sun.ts +78 -0
- package/src/video/contracts/cameraSchemas.ts +266 -0
- package/src/video/contracts/profileSchemas.ts +37 -0
- package/src/video/contracts/video.ts +601 -0
- package/src/video/handlers/video.ts +1638 -0
- package/src/video/handlers/videoDirector.ts +114 -0
- package/src/video/rules/previewRefresh.ts +76 -0
- package/src/video/rules/profileSource.ts +51 -0
- package/src/video/rules/routeSpans.ts +79 -0
- package/src/video/rules/shotDefaults.ts +28 -0
- package/src/video/rules/stepOrder.ts +17 -0
- package/src/video/rules/videoSnapshot.ts +136 -0
- package/src/video/stores/directorThreads.ts +167 -0
- package/src/video/stores/videoExport.ts +290 -0
- package/src/viewer/contracts/preferences.ts +40 -0
- package/src/viewer/handlers/preferences.ts +91 -0
- package/src/viewer/rules/capabilities.ts +42 -0
- package/src/viewer/rules/config.ts +266 -0
- package/src/viewer/rules/context.ts +375 -0
- package/src/viewer/rules/ownership.ts +134 -0
- package/src/viewer/rules/platformViewer.ts +198 -0
- package/src/viewer/rules/scope.ts +197 -0
- package/src/viewer/rules/url.ts +145 -0
- package/src/viewer/rules/viewer.ts +307 -0
- package/src/viewer/rules/viewerSeam.ts +49 -0
- package/src/viewer/rules/viewerUnits.ts +34 -0
- package/src/waypoints/contracts/itinerary.ts +417 -0
- package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
- package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
- package/src/waypoints/handlers/waypointEdit.ts +1073 -0
- package/src/waypoints/rules/amenities.ts +30 -0
- package/src/waypoints/rules/defaults.ts +31 -0
- package/src/waypoints/rules/details.ts +213 -0
- package/src/waypoints/rules/detailsDraft.ts +312 -0
- package/src/waypoints/rules/detailsPreview.ts +76 -0
- package/src/waypoints/rules/detailsSave.ts +356 -0
- package/src/waypoints/rules/draftDirty.ts +45 -0
- package/src/waypoints/rules/icons.ts +32 -0
- package/src/waypoints/rules/liveWaypoint.ts +63 -0
- package/src/waypoints/rules/naming.ts +185 -0
- package/src/waypoints/rules/sections.ts +77 -0
- package/src/waypoints/rules/waypointDraft.ts +62 -0
- package/src/waypoints/stores/waypointDetails.ts +62 -0
- package/src/waypoints/stores/waypointEdit.ts +566 -0
- package/src/zones/contracts/collection.ts +37 -0
- package/src/zones/contracts/zone.ts +528 -0
- package/src/zones/engines/zoneForm.ts +1773 -0
- package/src/zones/handlers/restZones.ts +287 -0
- package/src/zones/handlers/zonePublish.ts +206 -0
- package/src/zones/handlers/zoneUnpublish.ts +56 -0
- package/src/zones/handlers/zones.ts +2254 -0
- package/src/zones/rules/geometry.ts +946 -0
- package/src/zones/rules/zoneDefaults.ts +34 -0
- package/src/zones/rules/zoneDraft.ts +54 -0
- package/src/zones/rules/zoneForm.ts +563 -0
- package/src/zones/rules/zoneMetadata.ts +29 -0
- package/src/zones/rules/zoneSource.ts +87 -0
- package/src/zones/rules/zoneSourceRefusal.ts +104 -0
- package/src/zones/stores/zoneEdit.ts +998 -0
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
import { MountayaElementsError } from "@mountaya/elements/errors";
|
|
2
|
+
|
|
3
|
+
import { notifyListeners } from "../../rules/listeners.js";
|
|
4
|
+
import { failureFromThrown, messageOf, type ThrownRecognizer } from "./errors.js";
|
|
5
|
+
import { renderInputSchema } from "./inputSchema.js";
|
|
6
|
+
import { describeInvalidInput } from "./invalidInput.js";
|
|
7
|
+
import type {
|
|
8
|
+
ConfirmationValues,
|
|
9
|
+
StudioToolManifestEntry,
|
|
10
|
+
Tool,
|
|
11
|
+
ToolBusContext,
|
|
12
|
+
ToolBusDispatch,
|
|
13
|
+
ToolCapability,
|
|
14
|
+
ToolDispatchRegistry,
|
|
15
|
+
ToolErrorCode,
|
|
16
|
+
ToolFailure,
|
|
17
|
+
ToolOutputRegistry,
|
|
18
|
+
ToolResult,
|
|
19
|
+
ToolResultOf,
|
|
20
|
+
} from "./types.js";
|
|
21
|
+
import { toolConfirmationSchema } from "./types.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ToolBusOptions carry what a host knows and this package cannot.
|
|
25
|
+
*
|
|
26
|
+
* `playbook` is the model-facing catalogue: a description written for whoever is CHOOSING a
|
|
27
|
+
* tool rather than for whoever registered it, plus whether the tool only reads. A host may
|
|
28
|
+
* have none, in which case every tool keeps its inline description and is treated as
|
|
29
|
+
* mutating: the only safe default, since dropping a mutation's record would let a model
|
|
30
|
+
* believe a change it made never happened.
|
|
31
|
+
*
|
|
32
|
+
* `recognizers` classify the host's own domain throws before the generic status table sees
|
|
33
|
+
* them. See {@link ThrownRecognizer}.
|
|
34
|
+
*
|
|
35
|
+
* `reserved` names the vendor segments whose tools {@link ToolBus.unregister} will not take
|
|
36
|
+
* back. See there for what it is and is not for.
|
|
37
|
+
*/
|
|
38
|
+
export interface ToolBusOptions {
|
|
39
|
+
readonly playbook?:
|
|
40
|
+
| readonly {
|
|
41
|
+
readonly description: string;
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly kind?: string | undefined;
|
|
44
|
+
}[]
|
|
45
|
+
| undefined;
|
|
46
|
+
readonly recognizers?: readonly ThrownRecognizer[] | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The FIRST dot-separated segments a name must not have, to be unregistered.
|
|
49
|
+
*
|
|
50
|
+
* Data rather than a rule this file knows, which is what keeps the bus ignorant of the
|
|
51
|
+
* plugin vocabulary that gives it meaning: `createStudioToolBus` passes
|
|
52
|
+
* `RESERVED_PLUGIN_NAMESPACES`, a host with their own namespace passes theirs, and a bus with
|
|
53
|
+
* no plugins passes nothing.
|
|
54
|
+
*
|
|
55
|
+
* @default undefined, and {@link ToolBus.unregister} takes back any name
|
|
56
|
+
*/
|
|
57
|
+
readonly reserved?: readonly string[] | undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* resolveConfirmationValues runs a tool's confirmationValues resolver so the confirm
|
|
62
|
+
* surface can interpolate the policy's i18n keys with the entities the tool is about
|
|
63
|
+
* to act on. Returns undefined when the tool declares no resolver, and ALSO when the
|
|
64
|
+
* resolver throws: the interpolation is presentation, so a failed lookup costs the
|
|
65
|
+
* prompt its placeholders and nothing more. Swallowing here is what keeps the bus's
|
|
66
|
+
* "always resolves, never rejects" contract true, since the confirmation gate runs outside
|
|
67
|
+
* the try that wraps the handler.
|
|
68
|
+
*/
|
|
69
|
+
const resolveConfirmationValues = <TCtx>(
|
|
70
|
+
tool: Tool<TCtx>,
|
|
71
|
+
ctx: TCtx,
|
|
72
|
+
input: unknown,
|
|
73
|
+
): ConfirmationValues | undefined => {
|
|
74
|
+
if (!tool.confirmationValues) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
return tool.confirmationValues(ctx, input);
|
|
80
|
+
} catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* askConfirmation raises a destructive tool's prompt on the context's confirm gate and reports
|
|
87
|
+
* whether the gate agreed. A context with no gate, a gate that declines and a gate that throws
|
|
88
|
+
* all answer false.
|
|
89
|
+
*/
|
|
90
|
+
const askConfirmation = async <TCtx extends ToolBusContext>(
|
|
91
|
+
tool: Tool<TCtx>,
|
|
92
|
+
ctx: TCtx,
|
|
93
|
+
input: unknown,
|
|
94
|
+
): Promise<boolean> => {
|
|
95
|
+
if (!ctx.confirm) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Forward the confirmation policy two ways: the whole object as `acknowledge`
|
|
100
|
+
// (the confirm surface reads acknowledgeLabel from it) and its display keys
|
|
101
|
+
// flattened onto the request, so the surface resolves the title/body/confirm
|
|
102
|
+
// copy without unpacking the nested policy. `tone` rides along so the surface
|
|
103
|
+
// paints the treatment the tool declared, and `values` carry the interpolation
|
|
104
|
+
// the policy's keys are filled with.
|
|
105
|
+
try {
|
|
106
|
+
return await ctx.confirm({
|
|
107
|
+
acknowledge: tool.confirmation,
|
|
108
|
+
confirmLabel: tool.confirmation?.confirmLabel,
|
|
109
|
+
description: tool.description,
|
|
110
|
+
descriptionLabel: tool.confirmation?.descriptionLabel,
|
|
111
|
+
input,
|
|
112
|
+
name: tool.name,
|
|
113
|
+
titleLabel: tool.confirmation?.titleLabel,
|
|
114
|
+
tone: tool.confirmation?.tone,
|
|
115
|
+
values: resolveConfirmationValues(tool, ctx, input),
|
|
116
|
+
});
|
|
117
|
+
} catch {
|
|
118
|
+
// A gate that throws answered nothing, and nothing is not consent: the verb does not
|
|
119
|
+
// run, and the dispatch still resolves.
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* isToolFailure reports whether a value is the refusal arm of a result: an object whose `ok` is
|
|
126
|
+
* false and whose `error` is a string.
|
|
127
|
+
*/
|
|
128
|
+
const isToolFailure = (value: unknown): value is ToolFailure =>
|
|
129
|
+
typeof value === "object" &&
|
|
130
|
+
value !== null &&
|
|
131
|
+
"ok" in value &&
|
|
132
|
+
value.ok === false &&
|
|
133
|
+
"error" in value &&
|
|
134
|
+
typeof value.error === "string";
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* refusalBeforeAsking runs a tool's `precondition` and returns the refusal the dispatch answers
|
|
138
|
+
* with, or null where the tool states no precondition or it refuses nothing.
|
|
139
|
+
*
|
|
140
|
+
* Total, since it runs outside the try that wraps the handler. A precondition that throws is
|
|
141
|
+
* classified as a handler that throws is, through {@link failureFromThrown}. An answer that is
|
|
142
|
+
* neither a refusal nor nothing is refused as `internal`: the member's type allows none, and a
|
|
143
|
+
* tool written with no type checker can still hand back a promise, which a dispatch that
|
|
144
|
+
* returned it would await as its own answer.
|
|
145
|
+
*/
|
|
146
|
+
const refusalBeforeAsking = <TCtx>(
|
|
147
|
+
tool: Tool<TCtx>,
|
|
148
|
+
ctx: TCtx,
|
|
149
|
+
input: unknown,
|
|
150
|
+
recognizers: readonly ThrownRecognizer[],
|
|
151
|
+
): ToolFailure | null => {
|
|
152
|
+
if (!tool.precondition) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
// Read as `unknown` and narrowed at once: the member's type is what a checked tool answers,
|
|
158
|
+
// and this is where a tool written without a checker is held to it.
|
|
159
|
+
const answered: unknown = tool.precondition(ctx, input);
|
|
160
|
+
if (answered === null || answered === undefined) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (isToolFailure(answered)) {
|
|
165
|
+
return answered;
|
|
166
|
+
}
|
|
167
|
+
} catch (err) {
|
|
168
|
+
return failureFromThrown(err, recognizers);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
code: "internal",
|
|
173
|
+
error: `the precondition of ${tool.name} answered neither a refusal nor null`,
|
|
174
|
+
ok: false,
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* ToolDispatchEvent is the structured readout the bus emits after every dispatch: the tool's
|
|
180
|
+
* name and capability, the wall-clock latency, and the outcome (success or a coarse-grained
|
|
181
|
+
* errorClass keyed off the bus's own failure branches). Observers turn this into per-tool
|
|
182
|
+
* latency and error metrics with no instrumentation inside the handlers themselves.
|
|
183
|
+
*
|
|
184
|
+
* errorClass is the coarse bucket the bus's own branches produce; errorCode is
|
|
185
|
+
* the FINE, machine-readable {@link ToolErrorCode} the failing result carried
|
|
186
|
+
* (or the gate's own code), so an observer can distinguish, say, a lost-revision
|
|
187
|
+
* `conflict` from any other `handler-error`. It is undefined on a success and on
|
|
188
|
+
* an unclassified failure that omitted a code.
|
|
189
|
+
*
|
|
190
|
+
* errorMessage is the failing result's human-readable error string (or the
|
|
191
|
+
* gate's own message), carried alongside errorCode so an observer can read the
|
|
192
|
+
* detail a code alone cannot express: the collab-lock refusal encodes the peer
|
|
193
|
+
* holder id in it, which the conflict/lock observer resolves to a name. It is
|
|
194
|
+
* undefined on a success, mirroring errorCode.
|
|
195
|
+
*
|
|
196
|
+
* errorClass, every member in kebab-case, the spelling the error codes take:
|
|
197
|
+
* - "unknown-tool": the dispatched name is not registered.
|
|
198
|
+
* - "capability-denied": the context lacks the tool's capability gate.
|
|
199
|
+
* - "agent-hidden": the MODEL named a tool withheld from its manifest. Its own
|
|
200
|
+
* bucket rather than a capability failure, because the context does hold the
|
|
201
|
+
* capability: this is a model reaching for a verb it was never offered, which is
|
|
202
|
+
* a distinct signal worth seeing on its own.
|
|
203
|
+
* - "invalid-input": Zod rejected the raw input at the boundary.
|
|
204
|
+
* - "confirmation-denied": ctx.confirm rejected or was absent for a destructive tool.
|
|
205
|
+
* - "handler-error": the tool's precondition or its handler returned { ok: false, error }, or
|
|
206
|
+
* threw.
|
|
207
|
+
*/
|
|
208
|
+
export interface ToolDispatchEvent {
|
|
209
|
+
capability?: ToolCapability | undefined;
|
|
210
|
+
errorClass?:
|
|
211
|
+
| "unknown-tool"
|
|
212
|
+
| "capability-denied"
|
|
213
|
+
| "agent-hidden"
|
|
214
|
+
| "invalid-input"
|
|
215
|
+
| "confirmation-denied"
|
|
216
|
+
| "handler-error"
|
|
217
|
+
| undefined;
|
|
218
|
+
errorCode?: ToolErrorCode | undefined;
|
|
219
|
+
errorMessage?: string | undefined;
|
|
220
|
+
latencyMs: number;
|
|
221
|
+
name: string;
|
|
222
|
+
ok: boolean;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* playbookDescriptions indexes a supplied playbook by tool name.
|
|
227
|
+
*
|
|
228
|
+
* A tool's inline `description` is written for whoever registers it. A playbook entry is
|
|
229
|
+
* written for the model, and it leads with the reason NOT to reach for the tool, because a
|
|
230
|
+
* tool list fails at the near-neighbour boundary far more often than it fails at "what does
|
|
231
|
+
* this do". Where an entry exists it wins; a tool without one keeps its inline string, so a
|
|
232
|
+
* playbook can grow one tool at a time rather than needing to cover the registry before it
|
|
233
|
+
* helps at all, and a host with no playbook at all loses nothing else.
|
|
234
|
+
*/
|
|
235
|
+
const playbookDescriptions = (playbook: ToolBusOptions["playbook"]): ReadonlyMap<string, string> =>
|
|
236
|
+
new Map((playbook ?? []).map((entry) => [entry.id, entry.description]));
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* playbookReadOnly names the tools a playbook classifies as reads.
|
|
240
|
+
*
|
|
241
|
+
* A run uses it to decide what its transcript may drop when it compacts: a superseded read is
|
|
242
|
+
* stale by construction, while anything that may have changed the world has to be kept. A tool
|
|
243
|
+
* with no entry is absent here and is treated as mutating, which is the only safe direction:
|
|
244
|
+
* dropping a mutation's record would let the model believe a change it made never happened.
|
|
245
|
+
*/
|
|
246
|
+
const playbookReadOnly = (playbook: ToolBusOptions["playbook"]): ReadonlySet<string> =>
|
|
247
|
+
new Set((playbook ?? []).filter((entry) => entry.kind === "read").map((entry) => entry.id));
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* ToolDispatchObserver receives one ToolDispatchEvent per completed dispatch.
|
|
251
|
+
* Observers run synchronously after the result is built, in registration order.
|
|
252
|
+
*
|
|
253
|
+
* One that throws changes no dispatch and stops no observer after it, so a telemetry
|
|
254
|
+
* sink never breaks a tool. Its fault is not dropped either: the first of a round
|
|
255
|
+
* reaches the program as an uncaught error on a microtask, by the rule
|
|
256
|
+
* `rules/listeners.ts` states for every fan-out of this package.
|
|
257
|
+
*/
|
|
258
|
+
export type ToolDispatchObserver = (event: ToolDispatchEvent) => void;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* ToolBusObserve is the OBSERVATION half of a bus, declared apart from {@link ToolBusDispatch}
|
|
262
|
+
* for the same reason that one is declared apart from the bus itself: a host may implement one
|
|
263
|
+
* and not the other.
|
|
264
|
+
*
|
|
265
|
+
* A bus this package builds carries both. A host that hands a surface a hand-written dispatch
|
|
266
|
+
* slice (a bridge, a scripted double, a print view) carries only the first, which is why
|
|
267
|
+
* every consumer of this one treats it as optional and answers "nothing observed" rather than
|
|
268
|
+
* throwing. That is a real answer: an observer reports on dispatches, so having none loses a
|
|
269
|
+
* report and never loses an action.
|
|
270
|
+
*
|
|
271
|
+
* `observe` returns its own detach function, so a caller's cleanup is the return value rather
|
|
272
|
+
* than a second call it has to spell.
|
|
273
|
+
*/
|
|
274
|
+
export interface ToolBusObserve {
|
|
275
|
+
observe(observer: ToolDispatchObserver): () => void;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* ToolBusObserveOverrides is the observation half of a bus as a host may hand it: present, left
|
|
280
|
+
* out, or written as `undefined`.
|
|
281
|
+
*
|
|
282
|
+
* It is what a surface takes beside {@link ToolBusDispatch} when the host's bus may be a
|
|
283
|
+
* hand-written dispatch slice (a bridge, a scripted double, a print view), which carries no
|
|
284
|
+
* `observe`. A bus this package builds satisfies it, and so does the bare slice. A surface that
|
|
285
|
+
* reads it answers "nothing observed" where the member is absent, for the reason
|
|
286
|
+
* {@link ToolBusObserve} gives.
|
|
287
|
+
*
|
|
288
|
+
* The member states `undefined`, so a host forwarding an `observe` it may not hold
|
|
289
|
+
* (`{ ...slice, observe: telemetry?.observe }`) compiles under `exactOptionalPropertyTypes`,
|
|
290
|
+
* which `Partial<ToolBusObserve>` refuses.
|
|
291
|
+
*/
|
|
292
|
+
export interface ToolBusObserveOverrides {
|
|
293
|
+
/**
|
|
294
|
+
* Registers a per-dispatch observer and returns its detach function, as
|
|
295
|
+
* {@link ToolBusObserve.observe} does.
|
|
296
|
+
*
|
|
297
|
+
* @default undefined, and nothing is observed
|
|
298
|
+
*/
|
|
299
|
+
readonly observe?: ((observer: ToolDispatchObserver) => () => void) | undefined;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* ToolBus is the single mutation surface for both humans (via component event
|
|
304
|
+
* handlers) and the agent. It registers tools, exposes a capability-filtered
|
|
305
|
+
* manifest, validates input with Zod, and dispatches to the handler, returning
|
|
306
|
+
* a structured result. Store layout is an implementation detail behind it.
|
|
307
|
+
*
|
|
308
|
+
* The `TInputs` parameter maps each tool name to its pre-parse input shape, so a
|
|
309
|
+
* caller that knows the bus's full tool set gets a name-checked, input-checked
|
|
310
|
+
* `dispatch`. Its default is {@link ToolDispatchRegistry}, which is empty until a
|
|
311
|
+
* host augments it, so the typed `dispatch` of a bus that is neither specialized
|
|
312
|
+
* nor augmented takes no name at all: such a bus dispatches through
|
|
313
|
+
* {@link ToolBus.dispatchUnsafe}, which takes any name and validates as fully.
|
|
314
|
+
* Specialize it through the constructor's type arguments (`StudioToolInputs` for the studio's
|
|
315
|
+
* own verbs) when the tool set is known at the call boundary, and with
|
|
316
|
+
* `Record<string, unknown>` for a `dispatch` that takes a free-form name and an
|
|
317
|
+
* unknown input.
|
|
318
|
+
*
|
|
319
|
+
* It implements {@link ToolBusDispatch} for its own `TInputs`, so the structural
|
|
320
|
+
* dispatch seam a handler reaches through ctx.bus is satisfied by the same typed
|
|
321
|
+
* `dispatch` the class exposes: a {@link ToolBus}<StudioToolInputs> is assignable
|
|
322
|
+
* to the default ctx.bus because both key the raw input off the same `TInputs`
|
|
323
|
+
* indexed access.
|
|
324
|
+
*
|
|
325
|
+
* The `TOutputs` parameter maps each tool name to the `data` its answer holds, and
|
|
326
|
+
* the typed `dispatch` answers the {@link ToolResult} of the named verb's data. Its
|
|
327
|
+
* default is {@link ToolOutputRegistry}, empty until a host augments it, where every
|
|
328
|
+
* answer's data is `unknown`. Name it beside `TInputs` for a bus whose instance is
|
|
329
|
+
* handed to a slot that states its outputs, a studio context's `bus` among them.
|
|
330
|
+
*
|
|
331
|
+
* observe() registers a per-dispatch telemetry observer (latency, outcome and coarse error
|
|
332
|
+
* class). Every dispatch builds its event, and each observer held is told of it.
|
|
333
|
+
*
|
|
334
|
+
* The options carry what this package cannot know: the model-facing playbook, the host's own
|
|
335
|
+
* throw recognizers and the reserved vendor segments. All are optional: a bus built with none
|
|
336
|
+
* still validates, gates, confirms and dispatches, it simply describes tools with their inline
|
|
337
|
+
* strings and classifies only what the API envelope can tell it. A host driving the studio's own
|
|
338
|
+
* verbs builds its bus with `createStudioToolBus` of `@mountaya/studio/handlers`, which states
|
|
339
|
+
* the studio's recognizers and reserved namespaces for it and takes the playbook as an option.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* interface RouteToolContext extends ToolBusContext {
|
|
344
|
+
* readonly routeId: string;
|
|
345
|
+
* }
|
|
346
|
+
*
|
|
347
|
+
* const bus = new ToolBus<RouteToolContext>({ reserved: ["acme"] });
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export class ToolBus<
|
|
351
|
+
TCtx extends ToolBusContext,
|
|
352
|
+
TInputs extends object = ToolDispatchRegistry,
|
|
353
|
+
TOutputs extends object = ToolOutputRegistry,
|
|
354
|
+
> implements ToolBusDispatch<TCtx, TInputs, TOutputs>
|
|
355
|
+
{
|
|
356
|
+
private readonly observers = new Set<ToolDispatchObserver>();
|
|
357
|
+
private readonly tools = new Map<string, Tool<TCtx>>();
|
|
358
|
+
|
|
359
|
+
/** The model-facing description per tool name, empty when the host supplied no playbook. */
|
|
360
|
+
private readonly descriptions: ReadonlyMap<string, string>;
|
|
361
|
+
|
|
362
|
+
/** The tools a playbook classifies as reads. Absent means "may mutate", the safe default. */
|
|
363
|
+
private readonly readOnly: ReadonlySet<string>;
|
|
364
|
+
|
|
365
|
+
/** The host's own throw classifiers, asked before the generic status table. */
|
|
366
|
+
private readonly recognizers: readonly ThrownRecognizer[];
|
|
367
|
+
|
|
368
|
+
/** The vendor segments whose names {@link unregister} refuses to take back. */
|
|
369
|
+
private readonly reserved: ReadonlySet<string>;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* dispatcher is this bus AS the dispatch surface: two methods, and nothing else on the object.
|
|
373
|
+
*
|
|
374
|
+
* A context's `bus` is typed {@link ToolBusDispatch}, and handing it the whole class would
|
|
375
|
+
* make that narrowing a claim the runtime does not keep. The gap is only visible to code that
|
|
376
|
+
* does not go through the types (a tool written in plain JavaScript, a handler that cast), and
|
|
377
|
+
* those are exactly the callers a narrowed type protects the bus from. Registering,
|
|
378
|
+
* unregistering and observing are the OWNER's verbs; a handler chaining into another verb
|
|
379
|
+
* needs `dispatch` and nothing more, so it is given nothing more.
|
|
380
|
+
*
|
|
381
|
+
* Reaching for one of the others through here is a `TypeError` at the call site rather than a
|
|
382
|
+
* silent success, which is the difference that matters: a plugin that took a tool off the bus
|
|
383
|
+
* would break the studio for the rest of the session with nothing anywhere saying why.
|
|
384
|
+
*
|
|
385
|
+
* One object per bus, built at construction, so the identity a context carries is stable for
|
|
386
|
+
* the bus's life and a memo keyed on `ctx.bus` never churns.
|
|
387
|
+
*/
|
|
388
|
+
readonly dispatcher: ToolBusDispatch<TCtx, TInputs, TOutputs>;
|
|
389
|
+
|
|
390
|
+
constructor(options: ToolBusOptions = {}) {
|
|
391
|
+
this.descriptions = playbookDescriptions(options.playbook);
|
|
392
|
+
this.readOnly = playbookReadOnly(options.playbook);
|
|
393
|
+
this.recognizers = options.recognizers ?? [];
|
|
394
|
+
this.reserved = new Set(options.reserved ?? []);
|
|
395
|
+
|
|
396
|
+
// Arrows closing over `this` rather than `bind`, so each keeps its own generic signature:
|
|
397
|
+
// `dispatch`'s `TName` is what makes a wrong input a compile error at the call site, and a
|
|
398
|
+
// bound method's is harder to read for the same result.
|
|
399
|
+
this.dispatcher = {
|
|
400
|
+
dispatch: <TName extends keyof TInputs & string>(
|
|
401
|
+
ctx: TCtx,
|
|
402
|
+
name: TName,
|
|
403
|
+
rawInput: TInputs[TName],
|
|
404
|
+
) => this.dispatch(ctx, name, rawInput),
|
|
405
|
+
dispatchUnsafe: (ctx: TCtx, name: string, rawInput: unknown) =>
|
|
406
|
+
this.dispatchUnsafe(ctx, name, rawInput),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* register adds a tool to the bus. A destructive tool's confirmation policy is parsed against
|
|
412
|
+
* toolConfirmationSchema at registration time, so an invalid policy (a typo, a structural
|
|
413
|
+
* drift) fails at app startup, not at the first dispatch.
|
|
414
|
+
*
|
|
415
|
+
* @throws MountayaElementsError when the bus holds a tool under the name already: a name is
|
|
416
|
+
* the stable public API, so a replacement is never silent. The message says how to replace
|
|
417
|
+
* it: through {@link ToolBus.unregister} first, or, under a `reserved` segment that
|
|
418
|
+
* unregister keeps, through the handlers the bus is built with.
|
|
419
|
+
* @throws MountayaElementsError when a destructive tool's confirmation policy fails
|
|
420
|
+
* toolConfirmationSchema, with the schema's own message.
|
|
421
|
+
*/
|
|
422
|
+
register(tool: Tool<TCtx>): void {
|
|
423
|
+
if (this.tools.has(tool.name)) {
|
|
424
|
+
const segment = tool.name.split(".")[0] ?? "";
|
|
425
|
+
throw new MountayaElementsError(
|
|
426
|
+
this.reserved.has(segment)
|
|
427
|
+
? `tool already registered: ${tool.name}. Its "${segment}" segment is reserved on this bus, so unregister keeps it: hand the replacement to the handlers the bus is built with (overrideStudioHandler replaces one studio verb).`
|
|
428
|
+
: `tool already registered: ${tool.name}. Take it off with unregister("${tool.name}"), then register the replacement.`,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (tool.requiresConfirmation && tool.confirmation !== undefined) {
|
|
433
|
+
const parsed = toolConfirmationSchema.safeParse(tool.confirmation);
|
|
434
|
+
if (!parsed.success) {
|
|
435
|
+
throw new MountayaElementsError(
|
|
436
|
+
`tool ${tool.name} carries an invalid confirmation policy: ${parsed.error.message}`,
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
this.tools.set(tool.name, tool);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* registerAll adds every tool in a registry, in the registry's own key order.
|
|
446
|
+
*
|
|
447
|
+
* A registry (from `defineRegistry`, from `studioRegistry`, or hand-written) is the unit
|
|
448
|
+
* tools arrive in, so registering one is one call rather than a loop every consumer writes
|
|
449
|
+
* identically. The values are what is registered; the keys are pinned to each tool's `name`
|
|
450
|
+
* at the type level by whichever builder produced the record, and are not re-read here.
|
|
451
|
+
*
|
|
452
|
+
* Not atomic, deliberately. `register` throws on a duplicate name, and a partial registry on
|
|
453
|
+
* a thrown bus is the correct outcome: registration happens once at startup, the throw is
|
|
454
|
+
* fatal there, and unwinding would only hide which tool collided behind a bus that looks
|
|
455
|
+
* empty.
|
|
456
|
+
*
|
|
457
|
+
* @throws MountayaElementsError when a tool's name is held already, as {@link register} states.
|
|
458
|
+
*/
|
|
459
|
+
registerAll(registry: Readonly<Record<string, Tool<TCtx>>>): void {
|
|
460
|
+
for (const tool of Object.values(registry)) {
|
|
461
|
+
this.register(tool);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* registered returns every tool currently in the bus, in registration order.
|
|
467
|
+
* Read-only access so a suite can assert structural properties (Zod schema present,
|
|
468
|
+
* capability canonical, no name collision, confirmation policy on destructive tools)
|
|
469
|
+
* without reaching into the private registry. The returned array is a fresh copy;
|
|
470
|
+
* mutating it does not affect the bus.
|
|
471
|
+
*/
|
|
472
|
+
registered(): readonly Tool<TCtx>[] {
|
|
473
|
+
return [...this.tools.values()];
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* unregister removes a tool by name, reporting whether one was there.
|
|
478
|
+
*
|
|
479
|
+
* It REPORTS rather than throws, which is the opposite of {@link register} and is the
|
|
480
|
+
* opposite case: removing a name nobody holds leaves the bus in exactly the state the caller
|
|
481
|
+
* asked for, while registering a name somebody already holds cannot leave it in the state
|
|
482
|
+
* BOTH callers asked for. A boolean is what a caller doing bookkeeping wants and what a
|
|
483
|
+
* caller cleaning up can ignore.
|
|
484
|
+
*
|
|
485
|
+
* It exists for the tools a PLUGIN declares, which arrive and leave with the plugin:
|
|
486
|
+
* `@mountaya/studio/plugins` registers them on install and takes them back on uninstall.
|
|
487
|
+
* Without it an uninstalled plugin's verbs would stay in the model's manifest for the rest of
|
|
488
|
+
* the session, and re-installing the same plugin would throw on its own names.
|
|
489
|
+
*
|
|
490
|
+
* There is nothing to invalidate: `manifest()` is rebuilt per call from this map, so the
|
|
491
|
+
* next one already omits the name. A dispatch to it answers `unknown-tool`, which is what a
|
|
492
|
+
* name that was never registered answers.
|
|
493
|
+
*
|
|
494
|
+
* **It refuses a name under a RESERVED vendor segment**, which the host names at construction:
|
|
495
|
+
* the studio passes the segments `plugins/contracts/ids` refuses a plugin id for.
|
|
496
|
+
*
|
|
497
|
+
* It is the SECOND of two answers, and the smaller one. The first is {@link dispatcher}: a
|
|
498
|
+
* context's `bus` carries the dispatch surface alone, so code reached through one (a plugin's
|
|
499
|
+
* `run`, a chained handler) cannot name this method at all, in TypeScript or out of it. What
|
|
500
|
+
* is left holding a concrete bus is its owner: the host that built it, and anything they hand
|
|
501
|
+
* it to. This is for THEM, and it is the ordinary mistake it catches (a cleanup unregistering
|
|
502
|
+
* the wrong name, a line copy-pasted out of a teardown) which would otherwise leave the studio
|
|
503
|
+
* silently unable to save for the rest of the session.
|
|
504
|
+
*
|
|
505
|
+
* Neither is a sandbox, and neither is trying to be. A plugin runs in the host's own realm: it
|
|
506
|
+
* can write the store and dispatch every verb whatever these two do. The boundary that matters
|
|
507
|
+
* is still the host's decision to install it; what these buy is that an ACCIDENT fails loudly
|
|
508
|
+
* and at the call site instead of quietly and hours later.
|
|
509
|
+
*
|
|
510
|
+
* A vendor RULE rather than a list of protected names, for the reason `ids.ts` is one: a list
|
|
511
|
+
* is right the day it is written and wrong the day the next tool ships. It is also why the
|
|
512
|
+
* guard is total where a playbook-derived one would not be: a playbook describes the tools a
|
|
513
|
+
* model chooses between, which is a subset of the tools a studio registers.
|
|
514
|
+
*
|
|
515
|
+
* It costs a HOST nothing: it exists for a plugin's uninstall, and a host disabling one of the
|
|
516
|
+
* studio's own features does it through `capabilities` or the studio's config rather than by
|
|
517
|
+
* editing the bus.
|
|
518
|
+
*
|
|
519
|
+
* @returns true when a tool was registered under `name` and is removed; false when none was,
|
|
520
|
+
* or when `name` sits under a reserved segment and is kept.
|
|
521
|
+
*/
|
|
522
|
+
unregister(name: string): boolean {
|
|
523
|
+
if (this.reserved.has(name.split(".")[0] ?? "")) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return this.tools.delete(name);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* observe registers a telemetry observer that receives one event per
|
|
532
|
+
* dispatch (start to result). Returns an unobserve fn that detaches it.
|
|
533
|
+
*
|
|
534
|
+
* An observer that throws is answered as {@link ToolDispatchObserver} states. The
|
|
535
|
+
* observers held when a dispatch reports are the ones told: one that joins or
|
|
536
|
+
* detaches while being told changes that round for nobody. One that mutates the
|
|
537
|
+
* bus from inside the callback is on its own.
|
|
538
|
+
*/
|
|
539
|
+
observe(observer: ToolDispatchObserver): () => void {
|
|
540
|
+
this.observers.add(observer);
|
|
541
|
+
|
|
542
|
+
return () => {
|
|
543
|
+
this.observers.delete(observer);
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
private emit(event: ToolDispatchEvent): void {
|
|
548
|
+
notifyListeners(this.observers, event);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* refuseInput answers an `invalid-input` refusal with `error` as its narration, and reports
|
|
553
|
+
* it to the observers first. One path for a schema that failed the input and one that threw
|
|
554
|
+
* while reading it, so both read the same to a caller and to telemetry.
|
|
555
|
+
*/
|
|
556
|
+
private refuseInput(
|
|
557
|
+
capability: ToolCapability,
|
|
558
|
+
name: string,
|
|
559
|
+
start: number,
|
|
560
|
+
error: string,
|
|
561
|
+
): ToolResult {
|
|
562
|
+
this.emit({
|
|
563
|
+
capability,
|
|
564
|
+
errorClass: "invalid-input",
|
|
565
|
+
errorCode: "invalid-input",
|
|
566
|
+
errorMessage: error,
|
|
567
|
+
latencyMs: performance.now() - start,
|
|
568
|
+
name,
|
|
569
|
+
ok: false,
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
return { code: "invalid-input", error, ok: false };
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* manifest returns the tools available for the given capability set, with
|
|
577
|
+
* each input schema rendered as JSON Schema for the LLM. A tool marked
|
|
578
|
+
* {@link Tool.agentHidden} is withheld here even when its capability is
|
|
579
|
+
* granted: the model never sees a verb the system prompt forbids it to call
|
|
580
|
+
* (an edit-session lifecycle verb, a step of a UI chain), while the
|
|
581
|
+
* same tool stays fully dispatchable for a human click or an internal tool
|
|
582
|
+
* chain. Withholding it here is paired with {@link ToolBus.dispatchFromModel},
|
|
583
|
+
* which refuses the same set, so a name the model invents is not merely
|
|
584
|
+
* unlisted, it does not run. Each schema is rendered through
|
|
585
|
+
* {@link renderInputSchema}, which also drops the keywords the model cannot act
|
|
586
|
+
* on.
|
|
587
|
+
*
|
|
588
|
+
* `surface` narrows the result to a routed subset of tool names. It is
|
|
589
|
+
* advisory over what the model can SEE and is never a gate: a tool left out of
|
|
590
|
+
* the surface stays fully dispatchable by a human click and by an internal
|
|
591
|
+
* tool chain, exactly as `agentHidden` behaves. Omitting it yields every
|
|
592
|
+
* permitted tool, which is what a caller with no router does.
|
|
593
|
+
*/
|
|
594
|
+
manifest(
|
|
595
|
+
capabilities: ReadonlySet<ToolCapability>,
|
|
596
|
+
surface?: ReadonlySet<string>,
|
|
597
|
+
): StudioToolManifestEntry[] {
|
|
598
|
+
const entries: StudioToolManifestEntry[] = [];
|
|
599
|
+
for (const tool of this.tools.values()) {
|
|
600
|
+
if (!capabilities.has(tool.capability) || tool.agentHidden) {
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (surface !== undefined && !surface.has(tool.name)) {
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
entries.push({
|
|
609
|
+
capability: tool.capability,
|
|
610
|
+
description: this.descriptions.get(tool.name) ?? tool.description,
|
|
611
|
+
inputSchema: renderInputSchema(tool.input),
|
|
612
|
+
name: tool.name,
|
|
613
|
+
readOnly: this.readOnly.has(tool.name),
|
|
614
|
+
requiresConfirmation: tool.requiresConfirmation ?? false,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
return entries;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* dispatchUnsafe answers the first refusal in a fixed order and runs the
|
|
623
|
+
* handler only past all of them: a name no tool is registered under, a
|
|
624
|
+
* capability the context lacks, a raw input (e.g. LLM tool-call args) the
|
|
625
|
+
* tool's Zod schema rejects, a refusal the tool's own {@link Tool.precondition}
|
|
626
|
+
* gives, and, when the tool is marked
|
|
627
|
+
* requiresConfirmation, a ctx.confirm that is declined, absent or failed.
|
|
628
|
+
* The bus owns this gate for both human clicks and agent-issued tools; if a
|
|
629
|
+
* destructive tool reaches dispatch with no confirm callback in context, it
|
|
630
|
+
* is denied (fail-safe). Never trusts unvalidated input.
|
|
631
|
+
*
|
|
632
|
+
* It always resolves to a structured ToolResult and never rejects: each gate
|
|
633
|
+
* returns a failure carrying its machine-readable code (unknown-tool,
|
|
634
|
+
* capability-denied, invalid-input, confirmation-denied), and a handler that
|
|
635
|
+
* throws is converted to a structured failure (its classified code, or
|
|
636
|
+
* "internal") rather than re-thrown. A schema that throws while parsing answers
|
|
637
|
+
* invalid-input, since the tool refused the input it was given, and a confirm
|
|
638
|
+
* gate that throws answers confirmation-denied, since a question left unanswered
|
|
639
|
+
* is not consent. Describing a failure never rejects either:
|
|
640
|
+
* {@link failureFromThrown} and {@link describeInvalidInput} are total, so a
|
|
641
|
+
* message that cannot be read or printed gives way to a plainer sentence and a
|
|
642
|
+
* symbol in an issue path is printed. This is what makes the documented
|
|
643
|
+
* "handlers never throw" contract true at the boundary: a caller awaiting a
|
|
644
|
+
* dispatch branches on `ok` instead of wrapping the call in try/catch.
|
|
645
|
+
*
|
|
646
|
+
* "Unsafe" is a TYPE qualifier only: full runtime validation still applies (an
|
|
647
|
+
* unregistered name and a schema-rejected input both fail here, structured).
|
|
648
|
+
* It is the path for a dynamically-named dispatch (an agent routing an LLM
|
|
649
|
+
* tool-call name, the embed bridge mapping a postMessage type, an
|
|
650
|
+
* editing keyboard building a tool name from a family prefix) where the name
|
|
651
|
+
* (and its input) is a runtime `string`/`unknown` rather than a literal the
|
|
652
|
+
* compiler can match against `TInputs`. The typed {@link dispatch} wraps this
|
|
653
|
+
* for the common case where the name is a known literal.
|
|
654
|
+
*/
|
|
655
|
+
async dispatchUnsafe(ctx: TCtx, name: string, rawInput: unknown): Promise<ToolResult> {
|
|
656
|
+
const start = performance.now();
|
|
657
|
+
const tool = this.tools.get(name);
|
|
658
|
+
if (!tool) {
|
|
659
|
+
this.emit({
|
|
660
|
+
errorClass: "unknown-tool",
|
|
661
|
+
errorCode: "unknown-tool",
|
|
662
|
+
errorMessage: `unknown tool: ${name}`,
|
|
663
|
+
latencyMs: performance.now() - start,
|
|
664
|
+
name,
|
|
665
|
+
ok: false,
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
return { code: "unknown-tool", error: `unknown tool: ${name}`, ok: false };
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (!ctx.capabilities.has(tool.capability)) {
|
|
672
|
+
this.emit({
|
|
673
|
+
capability: tool.capability,
|
|
674
|
+
errorClass: "capability-denied",
|
|
675
|
+
errorCode: "capability-denied",
|
|
676
|
+
errorMessage: `capability not granted: ${tool.capability}`,
|
|
677
|
+
latencyMs: performance.now() - start,
|
|
678
|
+
name,
|
|
679
|
+
ok: false,
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
return {
|
|
683
|
+
code: "capability-denied",
|
|
684
|
+
error: `capability not granted: ${tool.capability}`,
|
|
685
|
+
ok: false,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
let parsed: ReturnType<typeof tool.input.safeParse>;
|
|
690
|
+
try {
|
|
691
|
+
parsed = tool.input.safeParse(rawInput);
|
|
692
|
+
} catch (err) {
|
|
693
|
+
// A schema can throw out of `safeParse` rather than fail it: a transform that throws, or
|
|
694
|
+
// an async refinement met by a synchronous parse. Either is the tool refusing the input
|
|
695
|
+
// it was given, so it answers the refusal a caller already branches on.
|
|
696
|
+
return this.refuseInput(
|
|
697
|
+
tool.capability,
|
|
698
|
+
name,
|
|
699
|
+
start,
|
|
700
|
+
`invalid input for ${name}: ${messageOf(err)}`,
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (!parsed.success) {
|
|
705
|
+
// The message re-states the accepted shape, not just what failed: the
|
|
706
|
+
// caller that gets here most often is a model that guessed a parameter
|
|
707
|
+
// name, and an error naming only the field it omitted leaves it to guess
|
|
708
|
+
// again. See describeInvalidInput.
|
|
709
|
+
return this.refuseInput(
|
|
710
|
+
tool.capability,
|
|
711
|
+
name,
|
|
712
|
+
start,
|
|
713
|
+
describeInvalidInput(name, tool.input, parsed.error, rawInput),
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// The tool's own refusal comes ahead of the question, so a reader is never asked to approve
|
|
718
|
+
// a call the tool can already tell it refuses.
|
|
719
|
+
const refused = refusalBeforeAsking(tool, ctx, parsed.data, this.recognizers);
|
|
720
|
+
if (refused !== null) {
|
|
721
|
+
this.emit({
|
|
722
|
+
capability: tool.capability,
|
|
723
|
+
errorClass: "handler-error",
|
|
724
|
+
errorCode: refused.code,
|
|
725
|
+
errorMessage: refused.error,
|
|
726
|
+
latencyMs: performance.now() - start,
|
|
727
|
+
name,
|
|
728
|
+
ok: false,
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
return refused;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
if (tool.requiresConfirmation && !(await askConfirmation(tool, ctx, parsed.data))) {
|
|
735
|
+
this.emit({
|
|
736
|
+
capability: tool.capability,
|
|
737
|
+
errorClass: "confirmation-denied",
|
|
738
|
+
errorCode: "confirmation-denied",
|
|
739
|
+
errorMessage: `confirmation required, not granted: ${tool.name}`,
|
|
740
|
+
latencyMs: performance.now() - start,
|
|
741
|
+
name,
|
|
742
|
+
ok: false,
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
return {
|
|
746
|
+
code: "confirmation-denied",
|
|
747
|
+
error: `confirmation required, not granted: ${tool.name}`,
|
|
748
|
+
ok: false,
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
try {
|
|
753
|
+
const result = await tool.handler(ctx, parsed.data);
|
|
754
|
+
this.emit({
|
|
755
|
+
capability: tool.capability,
|
|
756
|
+
errorClass: result.ok ? undefined : "handler-error",
|
|
757
|
+
errorCode: result.ok ? undefined : result.code,
|
|
758
|
+
errorMessage: result.ok ? undefined : result.error,
|
|
759
|
+
latencyMs: performance.now() - start,
|
|
760
|
+
name,
|
|
761
|
+
ok: result.ok,
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
return result;
|
|
765
|
+
} catch (err) {
|
|
766
|
+
// Classify the throw BEFORE emitting so telemetry carries the fine code (a
|
|
767
|
+
// 409 → "conflict") alongside the coarse class, then return the same result.
|
|
768
|
+
const failure = failureFromThrown(err, this.recognizers);
|
|
769
|
+
this.emit({
|
|
770
|
+
capability: tool.capability,
|
|
771
|
+
errorClass: "handler-error",
|
|
772
|
+
errorCode: failure.code,
|
|
773
|
+
errorMessage: failure.error,
|
|
774
|
+
latencyMs: performance.now() - start,
|
|
775
|
+
name,
|
|
776
|
+
ok: false,
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
// A handler throw is converted to a structured failure here rather than
|
|
780
|
+
// re-thrown, so the dispatch boundary makes the "handlers never throw"
|
|
781
|
+
// contract true for every caller: a component awaiting a dispatch reads
|
|
782
|
+
// { ok: false } instead of facing an unhandled rejection, and a thrown
|
|
783
|
+
// API error (a 409, a stale revision) arrives as its classified code.
|
|
784
|
+
return failure;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* dispatchFromModel is the entry point for a tool call the MODEL emitted. It is
|
|
790
|
+
* the only dispatch that treats {@link Tool.agentHidden} as a gate rather than a
|
|
791
|
+
* manifest filter: a name the model was never shown but produced anyway is
|
|
792
|
+
* refused here, so the hidden set stops resting on the model not guessing it.
|
|
793
|
+
*
|
|
794
|
+
* It is a separate entry point rather than a branch inside dispatchUnsafe on
|
|
795
|
+
* `ctx.origin`, because the trust boundary is the MODEL, not the origin tag. A
|
|
796
|
+
* hidden tool used as an INTERNAL step (`studio.search.selectResult` lighting
|
|
797
|
+
* its pick through `studio.search.highlight` and clearing the last one through
|
|
798
|
+
* `studio.search.clearHighlight`) chains through ctx.bus with its caller's own
|
|
799
|
+
* context and must keep working. Gating on origin would break exactly those
|
|
800
|
+
* chains, and silently where a chain discards the chained result: the outer
|
|
801
|
+
* tool would report success for a step that never ran. Keeping the gate on this seam makes that
|
|
802
|
+
* failure mode unreachable instead of something each new handler must remember.
|
|
803
|
+
*
|
|
804
|
+
* The refusal is `forbidden`, not `capability-denied`: the context genuinely
|
|
805
|
+
* holds the capability, and mis-stating that would mislead both the model's
|
|
806
|
+
* recovery branch and the observer that reads the code.
|
|
807
|
+
*/
|
|
808
|
+
async dispatchFromModel(ctx: TCtx, name: string, rawInput: unknown): Promise<ToolResult> {
|
|
809
|
+
const tool = this.tools.get(name);
|
|
810
|
+
if (tool?.agentHidden) {
|
|
811
|
+
const error = `tool not available to the agent: ${name}`;
|
|
812
|
+
this.emit({
|
|
813
|
+
capability: tool.capability,
|
|
814
|
+
errorClass: "agent-hidden",
|
|
815
|
+
errorCode: "forbidden",
|
|
816
|
+
errorMessage: error,
|
|
817
|
+
latencyMs: 0,
|
|
818
|
+
name,
|
|
819
|
+
ok: false,
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
return { code: "forbidden", error, ok: false };
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return this.dispatchUnsafe(ctx, name, rawInput);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* dispatch is the name-checked, input-checked entry point: the name must be a
|
|
830
|
+
* key of this bus's `TInputs`, and the raw input must match that tool's
|
|
831
|
+
* pre-parse shape, so a stray field or a wrong tool name is a compile error at
|
|
832
|
+
* the call site rather than a silently-stripped field at runtime. It delegates
|
|
833
|
+
* straight to {@link dispatchUnsafe}, which still runs the full Zod validation
|
|
834
|
+
* the dispatch contract guarantees: the typing is a build-time guard layered
|
|
835
|
+
* over the same runtime path, never a replacement for it. On a bus left at the
|
|
836
|
+
* default `TInputs`, with {@link ToolDispatchRegistry} not augmented, there is no
|
|
837
|
+
* key and this method takes no name: {@link dispatchUnsafe} is the entry point
|
|
838
|
+
* there.
|
|
839
|
+
*
|
|
840
|
+
* It answers the {@link ToolResult} of the named verb's data, read from this bus's
|
|
841
|
+
* `TOutputs`, and `data` as `unknown` for a name that map does not hold. Nothing
|
|
842
|
+
* is parsed on the way out: what the handler returned is what the caller reads.
|
|
843
|
+
*/
|
|
844
|
+
dispatch<K extends keyof TInputs & string>(
|
|
845
|
+
ctx: TCtx,
|
|
846
|
+
name: K,
|
|
847
|
+
rawInput: TInputs[K],
|
|
848
|
+
): Promise<ToolResultOf<TOutputs, K>> {
|
|
849
|
+
// The one hand-off from an erased tool to a typed answer. The registry holds every tool as
|
|
850
|
+
// a bare `Tool<TCtx>`, whose handler answers `data` as `unknown`, so the verb's own data
|
|
851
|
+
// type is restated here and nowhere else. It is sound where the tool registered under `name`
|
|
852
|
+
// was typed by the contract `TOutputs` is read from: `studioRegistry` and
|
|
853
|
+
// `registerStudioTools` hold each handler's return to its contract's `output` at compile
|
|
854
|
+
// time, and the testing bus holds every answer to that schema when a suite runs. A refusal
|
|
855
|
+
// carries no data and is the same value under every `TOutputs`.
|
|
856
|
+
return this.dispatchUnsafe(ctx, name, rawInput) as Promise<ToolResultOf<TOutputs, K>>;
|
|
857
|
+
}
|
|
858
|
+
}
|