@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,2818 @@
|
|
|
1
|
+
import { createVideoDirectorStore, buildVideoSnapshot } from '../chunk-WZYXG3SE.js';
|
|
2
|
+
import { layerToolContext } from '../chunk-RFUPPVZO.js';
|
|
3
|
+
import { SEARCH_TAB_ID, buildStudioSnapshot, MAX_OPEN_COPILOT_TABS } from '../chunk-LBWTJZUJ.js';
|
|
4
|
+
export { SEARCH_TAB_ID } from '../chunk-LBWTJZUJ.js';
|
|
5
|
+
import { agentHandoffTarget, questionToolContracts, selectSuggestionSession, defaultSegmentName, studioToolContracts } from '../chunk-2HFY7ETU.js';
|
|
6
|
+
import { notifyListeners, surfaceFault } from '../chunk-RPG2LWMP.js';
|
|
7
|
+
import { confirmSentence } from '../chunk-6HEKY3NF.js';
|
|
8
|
+
import { isConfirmationWithheld } from '../chunk-O4MC5DPD.js';
|
|
9
|
+
import { failureFromThrown } from '../chunk-WUTDDBVP.js';
|
|
10
|
+
import { createConversationHost, AgentEngine, createConversationFaults, boundedInputJson, resolveAgentError, settleActivityEntry, replaceAssistant, chooseSuggestionEntry, appendUserEntry, settleOpenSuggestionEntries, settleOpenQuestionEntries, appendActivityEntry, appendSuggestionsEntry, appendQuestionEntry, appendErrorEntry, appendWarningEntry, accumulateAssistant, answerQuestionEntry } from '@mountaya/elements/agent';
|
|
11
|
+
import { boundsOf } from '@mountaya/elements/geo';
|
|
12
|
+
import * as z from 'zod';
|
|
13
|
+
import { createStore } from 'zustand/vanilla';
|
|
14
|
+
|
|
15
|
+
// src/chrome/handlers/stateDelta.ts
|
|
16
|
+
var editingOf = (ui) => {
|
|
17
|
+
if (ui.segmentEditSession) {
|
|
18
|
+
return [ui.segmentEditSession.segmentId ?? null, "segment"];
|
|
19
|
+
}
|
|
20
|
+
if (ui.waypointEditSession) {
|
|
21
|
+
return [ui.waypointEditSession.waypointId ?? null, "waypoint"];
|
|
22
|
+
}
|
|
23
|
+
if (ui.zoneEditSession) {
|
|
24
|
+
return [ui.zoneEditSession.zoneId ?? null, "zone"];
|
|
25
|
+
}
|
|
26
|
+
return [null, null];
|
|
27
|
+
};
|
|
28
|
+
var captureStudioState = (ctx) => {
|
|
29
|
+
const ui = ctx.ui.getState();
|
|
30
|
+
const itinerary = ui.activeItinerary;
|
|
31
|
+
const [editingId, editingKind] = editingOf(ui);
|
|
32
|
+
return {
|
|
33
|
+
activeOverlay: ui.activeOverlay ?? null,
|
|
34
|
+
editingId,
|
|
35
|
+
editingKind,
|
|
36
|
+
itineraryId: itinerary?.id ?? null,
|
|
37
|
+
itineraryName: itinerary?.name ?? null,
|
|
38
|
+
segmentCount: itinerary?.segments.length ?? 0,
|
|
39
|
+
selectionId: ui.selection?.id ?? null,
|
|
40
|
+
selectionKind: ui.selection?.kind ?? null,
|
|
41
|
+
waypointCount: itinerary?.waypoints.length ?? 0
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var diffStudioState = (before, after) => {
|
|
45
|
+
const delta = {};
|
|
46
|
+
let changed = false;
|
|
47
|
+
for (const key of Object.keys(after)) {
|
|
48
|
+
if (before[key] !== after[key]) {
|
|
49
|
+
Object.assign(delta, { [key]: after[key] });
|
|
50
|
+
changed = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return changed ? delta : void 0;
|
|
54
|
+
};
|
|
55
|
+
var segmentTargetSchema = z.object({ segmentId: z.string().min(1) });
|
|
56
|
+
var waypointTargetSchema = z.object({ waypointId: z.string().min(1) });
|
|
57
|
+
var contracts = studioToolContracts;
|
|
58
|
+
var agentEditLockTarget = (name, input) => {
|
|
59
|
+
const contract = contracts[name];
|
|
60
|
+
if (contract?.capability !== "editor") {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const segment = segmentTargetSchema.safeParse(input);
|
|
64
|
+
if (segment.success) {
|
|
65
|
+
return { id: segment.data.segmentId, kind: "segment" };
|
|
66
|
+
}
|
|
67
|
+
const waypoint = waypointTargetSchema.safeParse(input);
|
|
68
|
+
if (waypoint.success) {
|
|
69
|
+
return { id: waypoint.data.waypointId, kind: "waypoint" };
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
var agentHandoffTools = /* @__PURE__ */ new Set([
|
|
74
|
+
"studio.itinerary.segment.editPropose",
|
|
75
|
+
"studio.itinerary.waypoint.editPropose"
|
|
76
|
+
]);
|
|
77
|
+
var agentTakesEntityBack = (name, input) => !agentHandoffTools.has(name) && agentEditLockTarget(name, input) !== null;
|
|
78
|
+
|
|
79
|
+
// src/agent/rules/copilotOrganization.ts
|
|
80
|
+
var copilotOrganizationId = (state) => {
|
|
81
|
+
if (state.activeItinerary) {
|
|
82
|
+
return state.activeItinerary.organization_id;
|
|
83
|
+
}
|
|
84
|
+
if (state.activeZone) {
|
|
85
|
+
return state.activeZone.organization_id;
|
|
86
|
+
}
|
|
87
|
+
return state.zoneEditSession?.intent === "create" ? state.zoneEditSession.organizationId : void 0;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/agent/rules/router.ts
|
|
91
|
+
var routerStateFrom = (ctx) => {
|
|
92
|
+
const ui = ctx.ui.getState();
|
|
93
|
+
const editSession = ui.segmentEditSession ? "segment" : ui.waypointEditSession ? "waypoint" : ui.zoneEditSession ? "zone" : null;
|
|
94
|
+
const openResource = ui.activeZone !== null ? "zone" : ui.activeItinerary !== null ? "itinerary" : null;
|
|
95
|
+
return {
|
|
96
|
+
editSession,
|
|
97
|
+
importDraft: ui.importSession !== null,
|
|
98
|
+
openResource,
|
|
99
|
+
suggestDraft: ui.suggestSession !== null,
|
|
100
|
+
videoOpen: ui.videoExport !== null
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var compareIds = (a, b) => {
|
|
104
|
+
if (a === b) {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
return a < b ? -1 : 1;
|
|
108
|
+
};
|
|
109
|
+
var createStudioRouter = ({
|
|
110
|
+
playbook,
|
|
111
|
+
skillRoutes,
|
|
112
|
+
surfaceLocks,
|
|
113
|
+
surfaces: surfaceTable
|
|
114
|
+
}) => {
|
|
115
|
+
const wideFallbackSurfaces = () => surfaceTable.filter((surface) => surface.wideFallback).map((surface) => surface.id);
|
|
116
|
+
const alwaysOn = () => surfaceTable.filter((surface) => surface.always).map((surface) => surface.id);
|
|
117
|
+
const lockHolds = (lock, state) => state[lock.field] === lock.equals;
|
|
118
|
+
const MAX_TASK_SURFACES = 2;
|
|
119
|
+
const MAX_CARRIED_SURFACES = 4;
|
|
120
|
+
const foldApostrophes = (message) => message.replace(/’/g, "'");
|
|
121
|
+
const matchSkillRoutes = (message) => {
|
|
122
|
+
const lowered = message.toLowerCase();
|
|
123
|
+
const hits = skillRoutes.map((route) => ({
|
|
124
|
+
matches: route.intents.filter((intent) => intent !== "" && lowered.includes(intent)).length,
|
|
125
|
+
route
|
|
126
|
+
})).filter((entry) => entry.matches > 0).sort((a, b) => b.matches - a.matches || compareIds(a.route.id, b.route.id)).slice(0, 3);
|
|
127
|
+
const surfaces = [];
|
|
128
|
+
for (const hit of hits) {
|
|
129
|
+
for (const id of hit.route.surfaces) {
|
|
130
|
+
if (surfaces.length >= MAX_CARRIED_SURFACES) {
|
|
131
|
+
return surfaces;
|
|
132
|
+
}
|
|
133
|
+
if (!surfaces.includes(id)) {
|
|
134
|
+
surfaces.push(id);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return surfaces;
|
|
139
|
+
};
|
|
140
|
+
const surfacePatterns = new Map(
|
|
141
|
+
surfaceTable.map((surface) => [
|
|
142
|
+
surface.id,
|
|
143
|
+
surface.keywords.map(
|
|
144
|
+
// Unicode-aware word boundaries, not \b. \b is defined by ASCII \w
|
|
145
|
+
// transitions, so a keyword starting or ending on an accented letter
|
|
146
|
+
// ("météo", "vidéo", "évite") could NEVER match: there is no \w transition
|
|
147
|
+
// at "é", so \bé matches nothing. Half the product's languages is French.
|
|
148
|
+
//
|
|
149
|
+
// The LEADING boundary excludes letters but not digits: people glue a
|
|
150
|
+
// number onto a unit ("target 12km", "600m ascent"), and a digit-blind
|
|
151
|
+
// boundary would make the unit keyword unmatchable exactly in the messages
|
|
152
|
+
// it exists for. A letter still blocks ("workman" does not fire "km"); the
|
|
153
|
+
// trailing boundary keeps digits so "km2" stays a non-match.
|
|
154
|
+
(keyword) => new RegExp(
|
|
155
|
+
`(?<![\\p{L}_])${keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\p{L}\\p{N}_])`,
|
|
156
|
+
"iu"
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
])
|
|
160
|
+
);
|
|
161
|
+
const scoreSurface = (surface, message) => {
|
|
162
|
+
let score = 0;
|
|
163
|
+
for (const pattern of surfacePatterns.get(surface.id) ?? []) {
|
|
164
|
+
if (pattern.test(message)) {
|
|
165
|
+
score += 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return score;
|
|
169
|
+
};
|
|
170
|
+
const selectSurfaces2 = (message, state = {}, previous = []) => {
|
|
171
|
+
const core = alwaysOn();
|
|
172
|
+
const known = new Set(surfaceTable.map((surface) => surface.id));
|
|
173
|
+
const folded = foldApostrophes(message);
|
|
174
|
+
const locked = surfaceLocks.filter((lock) => lockHolds(lock, state)).map((lock) => lock.surface).filter((id) => known.has(id) && !core.includes(id)).slice(0, MAX_TASK_SURFACES);
|
|
175
|
+
const skillDriven = matchSkillRoutes(folded).filter(
|
|
176
|
+
(id) => known.has(id) && !core.includes(id)
|
|
177
|
+
);
|
|
178
|
+
const scored = surfaceTable.filter((surface) => !surface.always && surface.keywords.length > 0).map((surface) => ({ id: surface.id, score: scoreSurface(surface, folded) })).filter((entry) => entry.score > 0).sort((a, b) => b.score - a.score || compareIds(a.id, b.id));
|
|
179
|
+
const keywordMatched = scored.slice(0, MAX_TASK_SURFACES).map((entry) => entry.id);
|
|
180
|
+
const matched = [];
|
|
181
|
+
for (const id of [...locked, ...skillDriven, ...keywordMatched]) {
|
|
182
|
+
if (matched.length >= MAX_CARRIED_SURFACES) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
if (!matched.includes(id)) {
|
|
186
|
+
matched.push(id);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
let carried = previous.filter((id) => known.has(id) && !core.includes(id));
|
|
190
|
+
if (carried.length > MAX_CARRIED_SURFACES) {
|
|
191
|
+
carried = [];
|
|
192
|
+
}
|
|
193
|
+
if (matched.length === 0) {
|
|
194
|
+
if (carried.length > 0) {
|
|
195
|
+
return { reason: "sticky", surfaces: [...core, ...carried] };
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
reason: "wide",
|
|
199
|
+
surfaces: wideFallbackSurfaces()
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (carried.length > 0 && matched.every((id) => carried.includes(id))) {
|
|
203
|
+
return { reason: "sticky", surfaces: [...core, ...carried] };
|
|
204
|
+
}
|
|
205
|
+
let reason = "intent";
|
|
206
|
+
if (locked.length > 0) {
|
|
207
|
+
reason = "lock";
|
|
208
|
+
} else if (skillDriven.length > 0) {
|
|
209
|
+
reason = "skill";
|
|
210
|
+
}
|
|
211
|
+
return { reason, surfaces: [...core, ...matched] };
|
|
212
|
+
};
|
|
213
|
+
const surfaceTools2 = (surfaces) => {
|
|
214
|
+
const wanted = new Set(surfaces);
|
|
215
|
+
const tools = /* @__PURE__ */ new Set();
|
|
216
|
+
for (const surface of surfaceTable) {
|
|
217
|
+
if (!wanted.has(surface.id)) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
for (const member of surface.members) {
|
|
221
|
+
tools.add(member);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return tools;
|
|
225
|
+
};
|
|
226
|
+
const recoveryFor2 = (tool, code) => {
|
|
227
|
+
if (!code) {
|
|
228
|
+
return void 0;
|
|
229
|
+
}
|
|
230
|
+
return playbook.find((entry) => entry.id === tool)?.recovery.find((item) => item.code === code)?.do;
|
|
231
|
+
};
|
|
232
|
+
return { recoveryFor: recoveryFor2, selectSurfaces: selectSurfaces2, surfaceTools: surfaceTools2 };
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/agent/rules/stateDelta.ts
|
|
236
|
+
var studioStateDelta = {
|
|
237
|
+
capture: captureStudioState,
|
|
238
|
+
diff: diffStudioState
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/agent/rules/playbook.gen.ts
|
|
242
|
+
var PLAYBOOK = [
|
|
243
|
+
{
|
|
244
|
+
confirms: false,
|
|
245
|
+
description: "Classify an existing line by surface, way type, trail difficulty, and steepness. Typed operation first, and anything else only when none of them fits.",
|
|
246
|
+
id: "analyzeGeometry",
|
|
247
|
+
kind: "read",
|
|
248
|
+
recovery: [
|
|
249
|
+
{ code: "invalid-input", do: "Coordinates are [longitude, latitude] pairs. A saved segment's positions carry an altitude, and a routed one is a GeometryCollection: take its LineString, drop the altitude, and retry once." }
|
|
250
|
+
],
|
|
251
|
+
surfaces: ["routing"]
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
confirms: false,
|
|
255
|
+
description: "Run a raw read-only GraphQL query against the Data API. Typed operation first, and anything else only when none of them fits.",
|
|
256
|
+
id: "data.query",
|
|
257
|
+
kind: "read",
|
|
258
|
+
recovery: [
|
|
259
|
+
{ code: "invalid-input", do: "Do not iterate on the syntax. Switch to the typed operation that covers the question." },
|
|
260
|
+
{ code: "forbidden", do: "The query attempted a write or an unpermitted root field. It will not succeed rewritten." }
|
|
261
|
+
],
|
|
262
|
+
surfaces: ["advanced"]
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
confirms: false,
|
|
266
|
+
description: "Compute a route between waypoints for an activity, with its distance, duration, and geometry. You intend to change the user's route. This alone changes nothing; propose the edit.",
|
|
267
|
+
id: "directions.compute",
|
|
268
|
+
kind: "read",
|
|
269
|
+
recovery: [
|
|
270
|
+
{ code: "invalid-input", do: "Check dimensionality and coordinate order, then retry once." },
|
|
271
|
+
{ code: "not-found", do: "Report it as a real answer, not a failure. The network may genuinely not connect them for this activity." },
|
|
272
|
+
{ code: "rate-limited", do: "Stop computing alternatives and report what you have." }
|
|
273
|
+
],
|
|
274
|
+
surfaces: ["routing"]
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
confirms: false,
|
|
278
|
+
description: "Compute the area reachable from one or more origins within a time or distance budget. Typed operation first, and anything else only when none of them fits.",
|
|
279
|
+
id: "isochrones",
|
|
280
|
+
kind: "read",
|
|
281
|
+
recovery: [
|
|
282
|
+
{ code: "invalid-input", do: "Reduce the budget and retry once. Very large ranges are refused rather than truncated." },
|
|
283
|
+
{ code: "upgrade-required", do: "The organization does not hold the Data API. Say so; do not retry." }
|
|
284
|
+
],
|
|
285
|
+
surfaces: ["zones"]
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
confirms: false,
|
|
289
|
+
description: "Compute travel time and distance between many origins and destinations in one call. Typed operation first, and anything else only when none of them fits.",
|
|
290
|
+
id: "matrix",
|
|
291
|
+
kind: "read",
|
|
292
|
+
recovery: [
|
|
293
|
+
{ code: "invalid-input", do: "Indices are into the locations array. Rebuild them and retry once with fewer points." },
|
|
294
|
+
{ code: "rate-limited", do: "Stop. Rank what you already have rather than waiting." }
|
|
295
|
+
],
|
|
296
|
+
surfaces: ["routing"]
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
capability: "authenticated",
|
|
300
|
+
confirms: false,
|
|
301
|
+
description: 'Resolve a named place to coordinates. Named place, free text, category, or "propose me something".',
|
|
302
|
+
id: "studio.data.geocode",
|
|
303
|
+
kind: "read",
|
|
304
|
+
recovery: [
|
|
305
|
+
{ code: "not-found", do: "No place by that name. Try search, which matches loosely, before telling the user it does not exist." },
|
|
306
|
+
{ code: "rate-limited", do: "Stop looking things up. Work with what you have and say so." }
|
|
307
|
+
],
|
|
308
|
+
surfaces: ["discovery"]
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
capability: "authenticated",
|
|
312
|
+
confirms: false,
|
|
313
|
+
description: 'List points of interest of a category within an area. Named place, free text, category, or "propose me something".',
|
|
314
|
+
id: "studio.data.pois",
|
|
315
|
+
kind: "read",
|
|
316
|
+
recovery: [
|
|
317
|
+
{ code: "invalid-input", do: "A bbox is [minLongitude, minLatitude, maxLongitude, maxLatitude]. Rebuild it and retry once." }
|
|
318
|
+
],
|
|
319
|
+
surfaces: ["discovery"]
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
capability: "authenticated",
|
|
323
|
+
confirms: false,
|
|
324
|
+
description: 'Name the place at a coordinate. Named place, free text, category, or "propose me something".',
|
|
325
|
+
id: "studio.data.reverseGeocode",
|
|
326
|
+
kind: "read",
|
|
327
|
+
recovery: [
|
|
328
|
+
{ code: "not-found", do: "Nothing named there. Describe the point by its position on the route instead." }
|
|
329
|
+
],
|
|
330
|
+
surfaces: ["discovery"]
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
capability: "authenticated",
|
|
334
|
+
confirms: false,
|
|
335
|
+
description: 'Search free text across places, points of interest, and itineraries, collections, and zones the user can see. Named place, free text, category, or "propose me something".',
|
|
336
|
+
id: "studio.data.search",
|
|
337
|
+
kind: "read",
|
|
338
|
+
recovery: [
|
|
339
|
+
{ code: "rate-limited", do: "Stop searching. Report what you have already found." }
|
|
340
|
+
],
|
|
341
|
+
surfaces: ["discovery"]
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
capability: "editor",
|
|
345
|
+
confirms: false,
|
|
346
|
+
description: "Copy an itinerary, or a continuous stretch of it, into a new itinerary. Not for moving or renaming an itinerary; this always leaves the original in place and adds a second one.",
|
|
347
|
+
id: "studio.itinerary.duplicate",
|
|
348
|
+
kind: "mutate",
|
|
349
|
+
recovery: [
|
|
350
|
+
{ code: "draft-open", do: "A proposal is not a saved itinerary and has nothing to copy. Tell the user to save or discard the draft first, and stop." },
|
|
351
|
+
{ code: "invalid-input", do: "Re-read the itinerary and keep an unbroken stretch, or leave segmentIds and waypointIds out to copy it whole, before retrying once." },
|
|
352
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." },
|
|
353
|
+
{ code: "forbidden", do: "Report which organization was refused and offer the ones they can write to, then stop." },
|
|
354
|
+
{ code: "conflict", do: "When the refusal names the itinerary holding the name, ask the user for another name and copy under it. Otherwise this same copy is still being made and may yet land: wait a moment and look for the new itinerary before telling the user it failed, and do not copy again while it may appear. Never resend a write that may still land." },
|
|
355
|
+
{ code: "limit-reached", do: "The personal space is full. Say so and stop; do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
356
|
+
],
|
|
357
|
+
surfaces: ["authoring"]
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
capability: "authenticated",
|
|
361
|
+
confirms: false,
|
|
362
|
+
description: "Read the open itinerary: its segments, waypoints, and elevation summary. The narrowest read that answers the question.",
|
|
363
|
+
id: "studio.itinerary.getActive",
|
|
364
|
+
kind: "read",
|
|
365
|
+
recovery: [
|
|
366
|
+
{ code: "not-found", do: "No itinerary is open. Ask the user to open one rather than creating one uninvited." }
|
|
367
|
+
],
|
|
368
|
+
surfaces: ["core"]
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
capability: "editor",
|
|
372
|
+
confirms: false,
|
|
373
|
+
description: "Present a run of neighbouring segments as one named, coloured leg on the elevation profile. Not for actually joining the segments into one; that is studio.itinerary.segment.merge.",
|
|
374
|
+
id: "studio.itinerary.group.create",
|
|
375
|
+
kind: "mutate",
|
|
376
|
+
recovery: [
|
|
377
|
+
{ code: "draft-open", do: "A proposal has no stored segments to group. Tell the user to save or discard the draft first, and stop." },
|
|
378
|
+
{ code: "invalid-input", do: "Re-read the itinerary, pick neighbours in chain order, and retry once." },
|
|
379
|
+
{ code: "conflict", do: "Re-read the itinerary. If the group you asked for is there, it landed: do not make it again. Otherwise tell the user which group holds the segment. Do not retry blind: edit or remove that group first, only if the user agrees. When no group holds it yet, wait a moment and re-read once more, since a conflict can mean the write is still being made. Never resend a write that may still land." },
|
|
380
|
+
{ code: "collab-locked", do: "Report who holds it and stop. Grouping is serialized to one editor at a time." },
|
|
381
|
+
{ code: "not-found", do: "Re-read the itinerary; the chain changed underneath you." },
|
|
382
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
383
|
+
],
|
|
384
|
+
surfaces: ["authoring"]
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
capability: "editor",
|
|
388
|
+
confirms: false,
|
|
389
|
+
description: "Dissolve a group so its segments read as separate legs again. Not for deleting segments. This removes a label; the route is untouched. Deleting a segment is its own verb.",
|
|
390
|
+
id: "studio.itinerary.group.delete",
|
|
391
|
+
kind: "mutate",
|
|
392
|
+
recovery: [
|
|
393
|
+
{ code: "draft-open", do: "A proposal carries no stored groups. Tell the user to save or discard the draft first, and stop." },
|
|
394
|
+
{ code: "collab-locked", do: "Report who holds it and stop. Group edits are serialized to one editor at a time." },
|
|
395
|
+
{ code: "conflict", do: "Re-read the itinerary. If the group is gone, the dissolve landed: do not make it again. If it is still there, wait a moment and re-read once more, since a conflict can mean the write is still being made, and dissolve it again only if it remains. Never resend a write that may still land." },
|
|
396
|
+
{ code: "not-found", do: "Re-read the itinerary. It may already have been dissolved, including automatically, when a merge or a delete dropped its run below two segments." },
|
|
397
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
398
|
+
],
|
|
399
|
+
surfaces: ["authoring"]
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
capability: "editor",
|
|
403
|
+
confirms: false,
|
|
404
|
+
description: "Change which run of segments an existing group covers. Not for renaming or recolouring; that is studio.itinerary.group.update.",
|
|
405
|
+
id: "studio.itinerary.group.setRange",
|
|
406
|
+
kind: "mutate",
|
|
407
|
+
recovery: [
|
|
408
|
+
{ code: "draft-open", do: "A proposal carries no stored groups. Tell the user to save or discard the draft first, and stop." },
|
|
409
|
+
{ code: "invalid-input", do: "Re-read the itinerary, rebuild the full membership in chain order, and retry once. If the user wanted the group gone, dissolve it instead." },
|
|
410
|
+
{ code: "collab-locked", do: "Report who holds it and stop. Group edits are serialized to one editor at a time." },
|
|
411
|
+
{ code: "conflict", do: "Re-read the itinerary. If the group already spans the run you sent, the change landed: do not make it again. Otherwise tell the user which group now holds the segment. Do not retry blind: the run they asked for may no longer be free. When no other group holds it, wait a moment and re-read once more, since a conflict can mean the write is still being made. Never resend a write that may still land." },
|
|
412
|
+
{ code: "not-found", do: "Re-read the itinerary; the chain changed underneath you." },
|
|
413
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
414
|
+
],
|
|
415
|
+
surfaces: ["authoring"]
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
capability: "editor",
|
|
419
|
+
confirms: false,
|
|
420
|
+
description: "Change what an existing group is called, what colour it paints, or the pace it is timed at. Not for changing which segments the group covers; that is studio.itinerary.group.setRange.",
|
|
421
|
+
id: "studio.itinerary.group.update",
|
|
422
|
+
kind: "mutate",
|
|
423
|
+
recovery: [
|
|
424
|
+
{ code: "draft-open", do: "A proposal carries no stored groups. Tell the user to save or discard the draft first, and stop." },
|
|
425
|
+
{ code: "invalid-input", do: "Correct the field the message names and retry once. A speed of zero is not a pace; send null if the user wanted the override removed." },
|
|
426
|
+
{ code: "collab-locked", do: "Report who holds it and stop. Group edits are serialized to one editor at a time." },
|
|
427
|
+
{ code: "conflict", do: "Re-read the itinerary. If the group already reads as you asked, the change landed: do not make it again. If it does not, wait a moment and re-read once more, since a conflict can mean the write is still being made, then apply the user's change to the group as it stands now, and retry once. Never resend a write that may still land." },
|
|
428
|
+
{ code: "not-found", do: "Re-read the itinerary; it may have been dissolved underneath you." },
|
|
429
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
430
|
+
],
|
|
431
|
+
surfaces: ["authoring"]
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
capability: "editor",
|
|
435
|
+
confirms: false,
|
|
436
|
+
description: "Append a new routed segment to the end of the open itinerary, through 2\u201345 vias. Ask when they have not said which, and where. A wrong guess rewrites their work.",
|
|
437
|
+
id: "studio.itinerary.segment.create",
|
|
438
|
+
kind: "mutate",
|
|
439
|
+
recovery: [
|
|
440
|
+
{ code: "invalid-input", do: "Coordinates are [longitude, latitude], longitude first. Simplify to the working range and retry once." },
|
|
441
|
+
{ code: "conflict", do: "Re-read the itinerary. If the segment you appended is there, the append landed: do not make it again. If it is not, wait a moment and re-read once more, since a conflict can mean the write is still being made, and rebuild the append against the current revision only if it is still absent. Never resend a write that may still land." },
|
|
442
|
+
{ code: "collab-locked", do: "Report who holds it and stop." },
|
|
443
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
444
|
+
],
|
|
445
|
+
surfaces: ["routing"]
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
capability: "editor",
|
|
449
|
+
confirms: false,
|
|
450
|
+
description: "Propose new via points for a segment, opening a live editable draft the user reviews and saves. Propose opens a draft the user saves. The agent never commits.",
|
|
451
|
+
id: "studio.itinerary.segment.editPropose",
|
|
452
|
+
kind: "propose",
|
|
453
|
+
recovery: [
|
|
454
|
+
{ code: "edit-in-progress", do: "Read the live draft. Iterate on it rather than starting a new one." },
|
|
455
|
+
{ code: "collab-locked", do: "Report who holds it and stop. Retrying will not acquire the lock." },
|
|
456
|
+
{ code: "conflict", do: "Re-read the itinerary and rebuild the proposal against the current revision." },
|
|
457
|
+
{ code: "invalid-input", do: "Coordinates are [longitude, latitude], longitude first, and the cap is 45. Reduce to the working range of two to six and retry once." }
|
|
458
|
+
],
|
|
459
|
+
surfaces: ["routing"]
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
capability: "editor",
|
|
463
|
+
confirms: false,
|
|
464
|
+
description: "Add a new segment INSIDE the chain, after a named segment or at the head, and renumber what follows. Ask when they have not said which, and where. A wrong guess rewrites their work.",
|
|
465
|
+
id: "studio.itinerary.segment.insert",
|
|
466
|
+
kind: "mutate",
|
|
467
|
+
recovery: [
|
|
468
|
+
{ code: "draft-open", do: "A proposal has nothing to insert into. Tell the user to save or discard the draft first, and stop." },
|
|
469
|
+
{ code: "invalid-input", do: "Append with studio.itinerary.segment.create when the gap is at the end. Otherwise re-read the chain and retry once with a valid anchor." },
|
|
470
|
+
{ code: "collab-locked", do: "Report who holds it and stop." },
|
|
471
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." },
|
|
472
|
+
{ code: "forbidden", do: "Report which organization refused the edit and stop. Nothing changed." },
|
|
473
|
+
{ code: "conflict", do: "Re-read the itinerary; the anchor you picked may have moved or gone. If the segment you inserted is there, the insert landed: do not make it again. If it is not, wait a moment and re-read once more, since a conflict can mean the write is still being made, and insert again only if it is still absent. Never resend a write that may still land." }
|
|
474
|
+
],
|
|
475
|
+
surfaces: ["routing"]
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
capability: "editor",
|
|
479
|
+
confirms: true,
|
|
480
|
+
description: "Join a segment with the one that follows it, leaving a single segment in their place. Not for making two segments merely READ as one leg; that is studio.itinerary.group.create.",
|
|
481
|
+
id: "studio.itinerary.segment.merge",
|
|
482
|
+
kind: "mutate",
|
|
483
|
+
recovery: [
|
|
484
|
+
{ code: "draft-open", do: "A proposal has no stored segments to join. Tell the user to save or discard the draft first, and stop." },
|
|
485
|
+
{ code: "invalid-input", do: "Nothing was changed. The refusal states the limit the two segments pass together, such as the 45 waypoints of a routed merge or the 10,000 positions of a freehand one. Report it and stop; do not thin the user's via points or line to make the merge fit." },
|
|
486
|
+
{ code: "collab-locked", do: "Report who holds it and stop. Both segments must be free to merge." },
|
|
487
|
+
{ code: "conflict", do: "Re-read the itinerary. If the two segments are already one, the merge landed: do not make it again. Otherwise check the segment is not last, that both use the same engine and belong to the same group or to none, and re-decide which pair the user meant before retrying once. When nothing in the itinerary explains the refusal, wait a moment and re-read first, since a conflict can mean the write is still being made. Never resend a write that may still land." },
|
|
488
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
489
|
+
],
|
|
490
|
+
surfaces: ["routing"]
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
capability: "editor",
|
|
494
|
+
confirms: true,
|
|
495
|
+
description: "Switch one segment between following the trail network and following the line as drawn. Not for making the route take a different path; that is studio.itinerary.segment.editPropose.",
|
|
496
|
+
id: "studio.itinerary.segment.setMode",
|
|
497
|
+
kind: "mutate",
|
|
498
|
+
recovery: [
|
|
499
|
+
{ code: "draft-open", do: "A proposal has no stored segment whose engine could change. Tell the user to save or discard the draft first, and stop." },
|
|
500
|
+
{ code: "invalid-input", do: "Nothing was written. When the refusal names the engine the segment already uses, there is nothing to change: say so. Otherwise report that the line cannot be routed and leave the segment freehand. Do not retry the same call." },
|
|
501
|
+
{ code: "collab-locked", do: "Report who holds it and stop." },
|
|
502
|
+
{ code: "conflict", do: "Re-read the itinerary. If the segment already uses the engine you asked for, the switch landed: do not make it again. If it does not, wait a moment and re-read once more, since a conflict can mean the write is still being made, and switch again only if it is still unchanged. Never resend a write that may still land." },
|
|
503
|
+
{ code: "internal", do: "The segment is unchanged. Report the failure and retry once at most." },
|
|
504
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." }
|
|
505
|
+
],
|
|
506
|
+
surfaces: ["routing"]
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
capability: "editor",
|
|
510
|
+
confirms: true,
|
|
511
|
+
description: "Cut one segment in two at a point along its length, given as a fraction of that length. Not for making the route go somewhere else; that is studio.itinerary.segment.editPropose.",
|
|
512
|
+
id: "studio.itinerary.segment.split",
|
|
513
|
+
kind: "mutate",
|
|
514
|
+
recovery: [
|
|
515
|
+
{ code: "draft-open", do: "A proposal has no stored segment to cut. Tell the user to save or discard the draft first, and stop." },
|
|
516
|
+
{ code: "invalid-input", do: "Pick a point further from both ends and retry once." },
|
|
517
|
+
{ code: "collab-locked", do: "Report who holds it and stop." },
|
|
518
|
+
{ code: "upgrade-required", do: "This organization's agreement does not include this action. Say so and stop. Do not retry, and do not copy the itinerary elsewhere unless the user asks." },
|
|
519
|
+
{ code: "forbidden", do: "Report which organization refused the edit and stop. Nothing changed." },
|
|
520
|
+
{ code: "conflict", do: "Re-read the itinerary; the length you based the fraction on may have changed. If the segment is already split where you asked, the split landed: do not make it again. If it is not, wait a moment and re-read once more, since a conflict can mean the write is still being made, and split again only if it is still whole. Never resend a write that may still land." }
|
|
521
|
+
],
|
|
522
|
+
surfaces: ["routing"]
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
capability: "editor",
|
|
526
|
+
confirms: false,
|
|
527
|
+
description: "Write a segment's geometry directly, the path a human drag-and-drop takes. Propose opens a draft the user saves. The agent never commits.",
|
|
528
|
+
id: "studio.itinerary.segment.updateGeometry",
|
|
529
|
+
kind: "mutate",
|
|
530
|
+
recovery: [
|
|
531
|
+
{ code: "capability-denied", do: "Expected. Propose the edit instead." }
|
|
532
|
+
],
|
|
533
|
+
surfaces: ["routing"]
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
capability: "authenticated",
|
|
537
|
+
confirms: false,
|
|
538
|
+
description: "Read the map viewport: centre, zoom, bearing, and pitch. The narrowest read that answers the question.",
|
|
539
|
+
id: "studio.map.getView",
|
|
540
|
+
kind: "read",
|
|
541
|
+
recovery: [
|
|
542
|
+
{ code: "internal", do: "The map is not ready. Proceed without it and bound your work by the itinerary instead." }
|
|
543
|
+
],
|
|
544
|
+
surfaces: ["core"]
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
capability: "authenticated",
|
|
548
|
+
confirms: false,
|
|
549
|
+
description: "List the overlays the scope in view can draw, with their kind and category. You already listed them in this run and the scope has not moved since.",
|
|
550
|
+
id: "studio.overlay.listAvailable",
|
|
551
|
+
kind: "read",
|
|
552
|
+
recovery: [
|
|
553
|
+
{ code: "internal", do: "Proceed without the catalog and let studio.overlay.set report not-found for an identifier that does not exist, rather than blocking the task." }
|
|
554
|
+
],
|
|
555
|
+
surfaces: ["terrain"]
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
capability: "embedding",
|
|
559
|
+
confirms: false,
|
|
560
|
+
description: "Show or hide a raster overlay on the map for the user to look at. Overlays are for the user's eyes. Numbers come from sampling, never from a visual.",
|
|
561
|
+
id: "studio.overlay.set",
|
|
562
|
+
kind: "mutate",
|
|
563
|
+
recovery: [
|
|
564
|
+
{ code: "invalid-input", do: "Call studio.overlay.listAvailable and pick from the catalog it returns." },
|
|
565
|
+
{ code: "capability-denied", do: "The caller cannot change overlays. Report what you found in words instead." },
|
|
566
|
+
{ code: "upgrade-required", do: "Report what you found in words instead, and say overlays are not available in this scope. Do not retry." }
|
|
567
|
+
],
|
|
568
|
+
surfaces: ["terrain"]
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
capability: "authenticated",
|
|
572
|
+
confirms: false,
|
|
573
|
+
description: "Read what is currently selected. The narrowest read that answers the question.",
|
|
574
|
+
id: "studio.selection.get",
|
|
575
|
+
kind: "read",
|
|
576
|
+
recovery: [
|
|
577
|
+
{ code: "capability-denied", do: "The caller cannot read the studio. Ask the user what they meant instead." }
|
|
578
|
+
],
|
|
579
|
+
surfaces: ["core"]
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
capability: "authenticated",
|
|
583
|
+
confirms: false,
|
|
584
|
+
description: "Open the share-link dialog for one itinerary or one collection, named by its kind and id. Not for the map running inside a page of their own. That is the embed wizard, not a link.",
|
|
585
|
+
id: "studio.share.open",
|
|
586
|
+
kind: "navigate",
|
|
587
|
+
recovery: [
|
|
588
|
+
{ code: "forbidden", do: "Report why rather than retrying. There is no second route to a link." },
|
|
589
|
+
{ code: "not-found", do: "Re-read the itineraries or collections the user can see and confirm which one they meant." },
|
|
590
|
+
{ code: "capability-denied", do: "The caller cannot open studio dialogs. Say the link has to be made from the studio." }
|
|
591
|
+
],
|
|
592
|
+
surfaces: ["sharing", "collections"]
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
capability: "authenticated",
|
|
596
|
+
confirms: false,
|
|
597
|
+
description: "Read the whole studio state: itinerary, open zone, selection, open edit draft, overlays, viewport, preferences. The narrowest read that answers the question.",
|
|
598
|
+
id: "studio.state.get",
|
|
599
|
+
kind: "read",
|
|
600
|
+
recovery: [
|
|
601
|
+
{ code: "internal", do: "Fall back to the narrow reads (selection, viewport, active itinerary) and proceed with what you can establish." }
|
|
602
|
+
],
|
|
603
|
+
surfaces: ["core"]
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
confirms: false,
|
|
607
|
+
description: 'Propose candidate routes matching activity, distance, and ascent constraints. Named place, free text, category, or "propose me something".',
|
|
608
|
+
id: "suggestions",
|
|
609
|
+
kind: "read",
|
|
610
|
+
recovery: [
|
|
611
|
+
{ code: "not-found", do: "No candidates fit. Loosen the tightest constraint once, then report that the ask is too narrow." },
|
|
612
|
+
{ code: "invalid-input", do: "A real answer, not a failure. Try a different start point once; if it repeats, say the area cannot be suggested from there and offer to draw the route with directions instead, which the user can take across it knowingly." },
|
|
613
|
+
{ code: "upgrade-required", do: "The organization does not hold the Data API. Say so; do not retry." }
|
|
614
|
+
],
|
|
615
|
+
surfaces: ["discovery"]
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
confirms: false,
|
|
619
|
+
description: "Sample elevation, slope and aspect over a rectangular grid of the DEM. A few known points, along a known line, or over an unknown area.",
|
|
620
|
+
id: "terrainGrid",
|
|
621
|
+
kind: "read",
|
|
622
|
+
recovery: [
|
|
623
|
+
{ code: "invalid-input", do: "The box may cover at most 100 km\xB2: shrink it around the feature, about 10 km a side, rather than reusing the view bounds; resolution does not change the area. Keep cols and rows between 2 and 64, then retry once." },
|
|
624
|
+
{ code: "rate-limited", do: "Stop sampling. Report what you already have rather than waiting." },
|
|
625
|
+
{ code: "upgrade-required", do: "The organization does not hold the Data API. Say so; do not retry." }
|
|
626
|
+
],
|
|
627
|
+
surfaces: ["terrain"]
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
confirms: false,
|
|
631
|
+
description: "Sample the surface at a fixed interval along a geometry. A few known points, along a known line, or over an unknown area.",
|
|
632
|
+
id: "terrainProfile",
|
|
633
|
+
kind: "read",
|
|
634
|
+
recovery: [
|
|
635
|
+
{ code: "invalid-input", do: "Coordinates are [longitude, latitude] pairs, longitude first. A saved segment's positions carry an altitude, and a routed one is a GeometryCollection: take its LineString, drop the altitude, and retry once with spacing at the default." },
|
|
636
|
+
{ code: "rate-limited", do: "Stop sampling. Report what you already have rather than waiting." }
|
|
637
|
+
],
|
|
638
|
+
surfaces: ["terrain"]
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
confirms: false,
|
|
642
|
+
description: "Sample elevation, slope, and aspect at specific coordinates. A few known points, along a known line, or over an unknown area.",
|
|
643
|
+
id: "terrainSamples",
|
|
644
|
+
kind: "read",
|
|
645
|
+
recovery: [
|
|
646
|
+
{ code: "invalid-input", do: "Coordinates are [longitude, latitude], longitude first. Split the batch and retry once." },
|
|
647
|
+
{ code: "upgrade-required", do: "The organization does not hold the Data API. Say so; do not retry." }
|
|
648
|
+
],
|
|
649
|
+
surfaces: ["terrain"]
|
|
650
|
+
}
|
|
651
|
+
];
|
|
652
|
+
|
|
653
|
+
// src/agent/rules/surfaces.gen.ts
|
|
654
|
+
var SURFACES = [
|
|
655
|
+
{
|
|
656
|
+
always: true,
|
|
657
|
+
id: "core",
|
|
658
|
+
keywords: [],
|
|
659
|
+
members: [
|
|
660
|
+
"studio.alert.dismiss",
|
|
661
|
+
"studio.alert.show",
|
|
662
|
+
"studio.itinerary.getActive",
|
|
663
|
+
"studio.map.applyCamera",
|
|
664
|
+
"studio.map.fitBounds",
|
|
665
|
+
"studio.map.fitBoundsOrFly",
|
|
666
|
+
"studio.map.fitBoundsToSegment",
|
|
667
|
+
"studio.map.getView",
|
|
668
|
+
"studio.map.resetNorth",
|
|
669
|
+
"studio.map.zoomIn",
|
|
670
|
+
"studio.map.zoomOut",
|
|
671
|
+
"studio.overlay.getActive",
|
|
672
|
+
"studio.panel.close",
|
|
673
|
+
"studio.panel.toggle",
|
|
674
|
+
"studio.preferences.set",
|
|
675
|
+
"studio.question.ask",
|
|
676
|
+
"studio.selection.get",
|
|
677
|
+
"studio.sidenav.back",
|
|
678
|
+
"studio.state.get",
|
|
679
|
+
"studio.tabs.close",
|
|
680
|
+
"studio.tabs.create",
|
|
681
|
+
"studio.tabs.open",
|
|
682
|
+
"studio.tabs.switch"
|
|
683
|
+
],
|
|
684
|
+
purpose: "Read the world, move the map, talk to the user. Needed by every run.",
|
|
685
|
+
title: "Core",
|
|
686
|
+
wideFallback: true
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
always: false,
|
|
690
|
+
id: "routing",
|
|
691
|
+
keywords: ["reroute", "via", "waypoint order", "steeper", "flatter", "avoid", "detour", "shorter", "longer", "how long", "compare", "split", "cut", "merge", "join", "insert", "freehand", "routed", "engine", "\xE9vite", "\xE9viter", "contourne", "contourner", "d\xE9tour", "passe par", "passer par", "plus court", "plus courte", "plus long", "plus longue", "plus raide", "moins raide", "raccourci", "trac\xE9", "couper", "scinder", "fusionner", "joindre", "ins\xE9rer", "trac\xE9 libre", "moteur"],
|
|
692
|
+
members: [
|
|
693
|
+
"analyzeGeometry",
|
|
694
|
+
"directions.compute",
|
|
695
|
+
"matrix",
|
|
696
|
+
"studio.itinerary.directions.close",
|
|
697
|
+
"studio.itinerary.directions.open",
|
|
698
|
+
"studio.itinerary.segment.create",
|
|
699
|
+
"studio.itinerary.segment.editBegin",
|
|
700
|
+
"studio.itinerary.segment.editCancel",
|
|
701
|
+
"studio.itinerary.segment.editCommit",
|
|
702
|
+
"studio.itinerary.segment.editPropose",
|
|
703
|
+
"studio.itinerary.segment.editRedo",
|
|
704
|
+
"studio.itinerary.segment.editUndo",
|
|
705
|
+
"studio.itinerary.segment.insert",
|
|
706
|
+
"studio.itinerary.segment.insertBegin",
|
|
707
|
+
"studio.itinerary.segment.merge",
|
|
708
|
+
"studio.itinerary.segment.recolor",
|
|
709
|
+
"studio.itinerary.segment.remove",
|
|
710
|
+
"studio.itinerary.segment.rename",
|
|
711
|
+
"studio.itinerary.segment.roadAccessClose",
|
|
712
|
+
"studio.itinerary.segment.roadAccessOpen",
|
|
713
|
+
"studio.itinerary.segment.select",
|
|
714
|
+
"studio.itinerary.segment.setMode",
|
|
715
|
+
"studio.itinerary.segment.setSpeed",
|
|
716
|
+
"studio.itinerary.segment.split",
|
|
717
|
+
"studio.itinerary.segment.splitPickBegin",
|
|
718
|
+
"studio.itinerary.segment.splitPickCancel",
|
|
719
|
+
"studio.itinerary.segment.splitPickSet",
|
|
720
|
+
"studio.itinerary.segment.updateGeometry",
|
|
721
|
+
"studio.itinerary.segment.via.promptClose",
|
|
722
|
+
"studio.itinerary.segment.via.promptOpen",
|
|
723
|
+
"studio.itinerary.segment.via.remove",
|
|
724
|
+
"studio.itinerary.segment.via.repeat",
|
|
725
|
+
"studio.segment.length",
|
|
726
|
+
"studio.segment.pointAtFraction"
|
|
727
|
+
],
|
|
728
|
+
purpose: "Change the geometry of an existing route by proposing vias for the user to save.",
|
|
729
|
+
title: "Segment routing and editing",
|
|
730
|
+
wideFallback: true
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
always: false,
|
|
734
|
+
id: "terrain",
|
|
735
|
+
keywords: ["elevation", "slope", "aspect", "steep", "north face", "hillshade", "snow", "weather", "overlay", "altitude", "d\xE9nivel\xE9", "pente", "orientation", "exposition", "raide", "versant", "face nord", "relief", "ombrage", "neige", "m\xE9t\xE9o", "vent", "calque", "couche"],
|
|
736
|
+
members: [
|
|
737
|
+
"studio.itinerary.profile.sheet.set",
|
|
738
|
+
"studio.itinerary.profileMarker.set",
|
|
739
|
+
"studio.overlay.category.set",
|
|
740
|
+
"studio.overlay.enrichment.set",
|
|
741
|
+
"studio.overlay.listAvailable",
|
|
742
|
+
"studio.overlay.pois.display.set",
|
|
743
|
+
"studio.overlay.pois.group.set",
|
|
744
|
+
"studio.overlay.sampleAlongSegment",
|
|
745
|
+
"studio.overlay.sampleAt",
|
|
746
|
+
"studio.overlay.set",
|
|
747
|
+
"studio.overlay.timestamp.set",
|
|
748
|
+
"studio.terrain.set",
|
|
749
|
+
"terrainGrid",
|
|
750
|
+
"terrainProfile",
|
|
751
|
+
"terrainSamples"
|
|
752
|
+
],
|
|
753
|
+
purpose: "Measure the surface (elevation, slope, aspect) and control what the user sees on it.",
|
|
754
|
+
title: "Terrain and overlays",
|
|
755
|
+
wideFallback: true
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
always: false,
|
|
759
|
+
id: "authoring",
|
|
760
|
+
keywords: ["create", "copy", "duplicate", "rename", "delete", "colour", "icon", "emphasis", "waypoint", "name it", "group", "stage", "leg", "cr\xE9e", "cr\xE9er", "copie", "copier", "dupliquer", "renomme", "renommer", "supprime", "supprimer", "couleur", "ic\xF4ne", "\xE9tape", "point de passage", "groupe", "grouper"],
|
|
761
|
+
members: [
|
|
762
|
+
"itinerary.get",
|
|
763
|
+
"studio.itinerary.activate",
|
|
764
|
+
"studio.itinerary.create",
|
|
765
|
+
"studio.itinerary.createOpen",
|
|
766
|
+
"studio.itinerary.delete",
|
|
767
|
+
"studio.itinerary.duplicate",
|
|
768
|
+
"studio.itinerary.emphasis.set",
|
|
769
|
+
"studio.itinerary.exclusions.set",
|
|
770
|
+
"studio.itinerary.group.create",
|
|
771
|
+
"studio.itinerary.group.delete",
|
|
772
|
+
"studio.itinerary.group.modal.close",
|
|
773
|
+
"studio.itinerary.group.modal.open",
|
|
774
|
+
"studio.itinerary.group.setRange",
|
|
775
|
+
"studio.itinerary.group.update",
|
|
776
|
+
"studio.itinerary.openForEdit",
|
|
777
|
+
"studio.itinerary.rename",
|
|
778
|
+
"studio.itinerary.tiles.refresh",
|
|
779
|
+
"studio.itinerary.update",
|
|
780
|
+
"studio.itinerary.waypoint.create",
|
|
781
|
+
"studio.itinerary.waypoint.detailsClose",
|
|
782
|
+
"studio.itinerary.waypoint.detailsOpen",
|
|
783
|
+
"studio.itinerary.waypoint.editBegin",
|
|
784
|
+
"studio.itinerary.waypoint.editCancel",
|
|
785
|
+
"studio.itinerary.waypoint.editCommit",
|
|
786
|
+
"studio.itinerary.waypoint.editPropose",
|
|
787
|
+
"studio.itinerary.waypoint.editRedo",
|
|
788
|
+
"studio.itinerary.waypoint.editSetColor",
|
|
789
|
+
"studio.itinerary.waypoint.editSetIcon",
|
|
790
|
+
"studio.itinerary.waypoint.editSetName",
|
|
791
|
+
"studio.itinerary.waypoint.editSetPosition",
|
|
792
|
+
"studio.itinerary.waypoint.editUndo",
|
|
793
|
+
"studio.itinerary.waypoint.recolor",
|
|
794
|
+
"studio.itinerary.waypoint.remove",
|
|
795
|
+
"studio.itinerary.waypoint.rename",
|
|
796
|
+
"studio.itinerary.waypoint.select",
|
|
797
|
+
"studio.itinerary.waypoint.setDetails",
|
|
798
|
+
"studio.itinerary.waypoint.setIcon"
|
|
799
|
+
],
|
|
800
|
+
purpose: "Create, copy, rename, restyle, and delete itineraries, their waypoints, and their segment groups.",
|
|
801
|
+
title: "Itinerary authoring",
|
|
802
|
+
wideFallback: true
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
always: false,
|
|
806
|
+
id: "discovery",
|
|
807
|
+
keywords: ["find", "near", "where is", "hut", "peak", "parking", "suggest", "propose a route", "plan a route", "plan me a route", "loop", "plan", "target", "ascent", "km", "options", "trouve", "trouver", "cherche", "chercher", "pr\xE8s de", "autour de", "o\xF9 est", "refuge", "sommet", "col", "boucle", "sugg\xE8re", "sugg\xE9rer", "propose", "proposer", "planifie", "planifier", "g\xE9n\xE8re", "g\xE9n\xE9rer", "objectif", "ascension", "mont\xE9e"],
|
|
808
|
+
members: [
|
|
809
|
+
"studio.contextmenu.close",
|
|
810
|
+
"studio.contextmenu.open",
|
|
811
|
+
"studio.data.geocode",
|
|
812
|
+
"studio.data.pois",
|
|
813
|
+
"studio.data.reverseGeocode",
|
|
814
|
+
"studio.data.search",
|
|
815
|
+
"studio.geolocate.confirm",
|
|
816
|
+
"studio.geolocate.prompt.close",
|
|
817
|
+
"studio.geolocate.prompt.open",
|
|
818
|
+
"studio.itinerary.suggest.applyCandidate",
|
|
819
|
+
"studio.itinerary.suggest.beginPick",
|
|
820
|
+
"studio.itinerary.suggest.cancelPick",
|
|
821
|
+
"studio.itinerary.suggest.clearDraft",
|
|
822
|
+
"studio.itinerary.suggest.commit",
|
|
823
|
+
"studio.itinerary.suggest.discard",
|
|
824
|
+
"studio.itinerary.suggest.generate",
|
|
825
|
+
"studio.itinerary.suggest.select",
|
|
826
|
+
"studio.itinerary.suggest.setActivity",
|
|
827
|
+
"studio.itinerary.suggest.setAscent",
|
|
828
|
+
"studio.itinerary.suggest.setCollections",
|
|
829
|
+
"studio.itinerary.suggest.setDistance",
|
|
830
|
+
"studio.itinerary.suggest.setEnd",
|
|
831
|
+
"studio.itinerary.suggest.setName",
|
|
832
|
+
"studio.itinerary.suggest.setOrganization",
|
|
833
|
+
"studio.itinerary.suggest.setPrivate",
|
|
834
|
+
"studio.itinerary.suggest.setRouteType",
|
|
835
|
+
"studio.itinerary.suggest.setSpeed",
|
|
836
|
+
"studio.itinerary.suggest.setStart",
|
|
837
|
+
"studio.itinerary.suggest.startFrom",
|
|
838
|
+
"studio.itinerary.suggest.toggleKeep",
|
|
839
|
+
"studio.itinerary.suggestOpen",
|
|
840
|
+
"studio.map.locate",
|
|
841
|
+
"suggestions"
|
|
842
|
+
],
|
|
843
|
+
purpose: "Find a place, a point of interest, or a candidate route to start from.",
|
|
844
|
+
title: "Places and route discovery",
|
|
845
|
+
wideFallback: true
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
always: false,
|
|
849
|
+
id: "zones",
|
|
850
|
+
keywords: ["zone", "area", "reachability", "isochrone", "hazard", "perimeter", "sector", "radius", "how far can I get", "reachable", "secteur", "p\xE9rim\xE8tre", "rayon", "accessible", "danger"],
|
|
851
|
+
members: [
|
|
852
|
+
"isochrones",
|
|
853
|
+
"studio.zone.beginOriginPick",
|
|
854
|
+
"studio.zone.cancelOriginPick",
|
|
855
|
+
"studio.zone.create",
|
|
856
|
+
"studio.zone.createBegin",
|
|
857
|
+
"studio.zone.delete",
|
|
858
|
+
"studio.zone.editBegin",
|
|
859
|
+
"studio.zone.editCancel",
|
|
860
|
+
"studio.zone.editCommit",
|
|
861
|
+
"studio.zone.editPropose",
|
|
862
|
+
"studio.zone.editRedo",
|
|
863
|
+
"studio.zone.editUndo",
|
|
864
|
+
"studio.zone.open",
|
|
865
|
+
"studio.zone.openForEdit",
|
|
866
|
+
"studio.zone.openForView",
|
|
867
|
+
"studio.zone.publish",
|
|
868
|
+
"studio.zone.reachabilityPreview",
|
|
869
|
+
"studio.zone.recompute",
|
|
870
|
+
"studio.zone.setCreateMethod",
|
|
871
|
+
"studio.zone.setLevel",
|
|
872
|
+
"studio.zone.setOrigin",
|
|
873
|
+
"studio.zone.unpublish",
|
|
874
|
+
"studio.zone.update"
|
|
875
|
+
],
|
|
876
|
+
purpose: "Draw and maintain zones, the map areas marking reachability, hazard, or interest.",
|
|
877
|
+
title: "Zones",
|
|
878
|
+
wideFallback: true
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
always: false,
|
|
882
|
+
id: "collections",
|
|
883
|
+
keywords: ["collection", "group", "folder", "add to", "organize", "tidy up", "groupe", "dossier", "ajoute \xE0", "ajouter \xE0", "range", "ranger", "organise", "organiser"],
|
|
884
|
+
members: [
|
|
885
|
+
"studio.collection.addItinerary",
|
|
886
|
+
"studio.collection.addZone",
|
|
887
|
+
"studio.collection.create",
|
|
888
|
+
"studio.collection.createClose",
|
|
889
|
+
"studio.collection.createOpen",
|
|
890
|
+
"studio.collection.delete",
|
|
891
|
+
"studio.collection.editClose",
|
|
892
|
+
"studio.collection.editOpen",
|
|
893
|
+
"studio.collection.manage.close",
|
|
894
|
+
"studio.collection.manage.open",
|
|
895
|
+
"studio.collection.openForEdit",
|
|
896
|
+
"studio.collection.removeItinerary",
|
|
897
|
+
"studio.collection.removeZone",
|
|
898
|
+
"studio.collection.reorderItinerary",
|
|
899
|
+
"studio.collection.update",
|
|
900
|
+
"studio.share.close",
|
|
901
|
+
"studio.share.open"
|
|
902
|
+
],
|
|
903
|
+
purpose: "Group itineraries and zones into a folder the whole organization shares.",
|
|
904
|
+
title: "Collections",
|
|
905
|
+
wideFallback: true
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
always: false,
|
|
909
|
+
id: "import",
|
|
910
|
+
keywords: ["import", "GPX", "upload", "from Strava", "from Garmin", "from a file", "importe", "importer", "t\xE9l\xE9verse", "t\xE9l\xE9verser", "depuis un fichier", "depuis strava", "depuis garmin"],
|
|
911
|
+
members: [
|
|
912
|
+
"studio.itinerary.import.clearDraft",
|
|
913
|
+
"studio.itinerary.import.confirm",
|
|
914
|
+
"studio.itinerary.import.discard",
|
|
915
|
+
"studio.itinerary.import.open",
|
|
916
|
+
"studio.itinerary.import.setActivity",
|
|
917
|
+
"studio.itinerary.import.setCollections",
|
|
918
|
+
"studio.itinerary.import.setGranularity",
|
|
919
|
+
"studio.itinerary.import.setName",
|
|
920
|
+
"studio.itinerary.import.setOrganization",
|
|
921
|
+
"studio.itinerary.import.setPrivate",
|
|
922
|
+
"studio.itinerary.import.setProvider",
|
|
923
|
+
"studio.itinerary.import.setSegmentModes",
|
|
924
|
+
"studio.itinerary.import.submitPreview",
|
|
925
|
+
"studio.itinerary.import.toggleMode"
|
|
926
|
+
],
|
|
927
|
+
purpose: "Bring an external track into the studio and reconcile it before saving.",
|
|
928
|
+
title: "Import",
|
|
929
|
+
wideFallback: true
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
always: false,
|
|
933
|
+
id: "sharing",
|
|
934
|
+
keywords: ["export", "GPX", "download", "share", "link", "embed", "iframe", "exporte", "exporter", "t\xE9l\xE9charge", "t\xE9l\xE9charger", "partage", "partager", "lien", "int\xE9gration"],
|
|
935
|
+
members: [
|
|
936
|
+
"studio.embed.close",
|
|
937
|
+
"studio.embed.open",
|
|
938
|
+
"studio.itinerary.export",
|
|
939
|
+
"studio.itinerary.export.close",
|
|
940
|
+
"studio.itinerary.export.open",
|
|
941
|
+
"studio.share.close",
|
|
942
|
+
"studio.share.open"
|
|
943
|
+
],
|
|
944
|
+
purpose: "Get an itinerary or a collection out of the studio, as a file, a link, or an embedded map.",
|
|
945
|
+
title: "Export, share, and embed",
|
|
946
|
+
wideFallback: true
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
always: false,
|
|
950
|
+
id: "streetview",
|
|
951
|
+
keywords: ["street view", "ground level", "what does it look like", "photo", "\xE0 quoi ressemble", "au niveau du sol", "vue immersive"],
|
|
952
|
+
members: [
|
|
953
|
+
"studio.streetview.close",
|
|
954
|
+
"studio.streetview.corridor.set",
|
|
955
|
+
"studio.streetview.coverage.set",
|
|
956
|
+
"studio.streetview.move",
|
|
957
|
+
"studio.streetview.open"
|
|
958
|
+
],
|
|
959
|
+
purpose: "Inspect a location at ground level along a route corridor.",
|
|
960
|
+
title: "Street view",
|
|
961
|
+
wideFallback: true
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
always: false,
|
|
965
|
+
id: "video",
|
|
966
|
+
keywords: ["video", "flythrough", "shot", "orbit", "record", "export video", "vid\xE9o", "survol", "orbite", "filme", "filmer"],
|
|
967
|
+
members: [
|
|
968
|
+
"studio.video.cancel",
|
|
969
|
+
"studio.video.close",
|
|
970
|
+
"studio.video.download",
|
|
971
|
+
"studio.video.duration.set",
|
|
972
|
+
"studio.video.mode.set",
|
|
973
|
+
"studio.video.open",
|
|
974
|
+
"studio.video.orbit",
|
|
975
|
+
"studio.video.output.set",
|
|
976
|
+
"studio.video.plan.get",
|
|
977
|
+
"studio.video.preset.set",
|
|
978
|
+
"studio.video.preview.pause",
|
|
979
|
+
"studio.video.preview.play",
|
|
980
|
+
"studio.video.preview.seek",
|
|
981
|
+
"studio.video.preview.start",
|
|
982
|
+
"studio.video.preview.stop",
|
|
983
|
+
"studio.video.profile.design.set",
|
|
984
|
+
"studio.video.profile.language.set",
|
|
985
|
+
"studio.video.profile.toggle",
|
|
986
|
+
"studio.video.profile.units.set",
|
|
987
|
+
"studio.video.record",
|
|
988
|
+
"studio.video.route.set",
|
|
989
|
+
"studio.video.shot.add",
|
|
990
|
+
"studio.video.shot.addHold",
|
|
991
|
+
"studio.video.shot.remove",
|
|
992
|
+
"studio.video.shot.set",
|
|
993
|
+
"studio.video.step.set"
|
|
994
|
+
],
|
|
995
|
+
purpose: "Compose a flythrough video of a route. Owned by the Video Director, not the studio co-pilot.",
|
|
996
|
+
title: "Video director",
|
|
997
|
+
wideFallback: false
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1000
|
+
always: false,
|
|
1001
|
+
id: "advanced",
|
|
1002
|
+
keywords: ["graphql", "data api", "raw query", "requ\xEAte brute"],
|
|
1003
|
+
members: [
|
|
1004
|
+
"data.query",
|
|
1005
|
+
"data.schema"
|
|
1006
|
+
],
|
|
1007
|
+
purpose: "Escape hatch for geospatial questions no typed operation covers. Off by default: a typed operation is always the better answer when one exists.",
|
|
1008
|
+
title: "Raw Data API access",
|
|
1009
|
+
wideFallback: false
|
|
1010
|
+
}
|
|
1011
|
+
];
|
|
1012
|
+
var SURFACE_LOCKS = [
|
|
1013
|
+
{ equals: "segment", field: "editSession", surface: "routing" },
|
|
1014
|
+
{ equals: "waypoint", field: "editSession", surface: "authoring" },
|
|
1015
|
+
{ equals: true, field: "suggestDraft", surface: "discovery" },
|
|
1016
|
+
{ equals: "zone", field: "editSession", surface: "zones" },
|
|
1017
|
+
{ equals: "zone", field: "openResource", surface: "zones" },
|
|
1018
|
+
{ equals: true, field: "importDraft", surface: "import" },
|
|
1019
|
+
{ equals: true, field: "videoOpen", surface: "video" }
|
|
1020
|
+
];
|
|
1021
|
+
var SKILL_ROUTES = [
|
|
1022
|
+
{
|
|
1023
|
+
id: "analyze-terrain-along-route",
|
|
1024
|
+
intents: [
|
|
1025
|
+
"how steep is this",
|
|
1026
|
+
"where does it get hard",
|
|
1027
|
+
"is this north facing",
|
|
1028
|
+
"what's the terrain like",
|
|
1029
|
+
"how exposed is this route",
|
|
1030
|
+
"how technical is this trail",
|
|
1031
|
+
"is this route hard underfoot",
|
|
1032
|
+
"c'est raide",
|
|
1033
|
+
"c'est technique",
|
|
1034
|
+
"o\xF9 \xE7a devient dur",
|
|
1035
|
+
"comment est le terrain",
|
|
1036
|
+
"est-ce expos\xE9",
|
|
1037
|
+
"orient\xE9 nord"
|
|
1038
|
+
],
|
|
1039
|
+
surfaces: ["terrain"]
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
id: "build-route-from-scratch",
|
|
1043
|
+
intents: [
|
|
1044
|
+
"plan a route from",
|
|
1045
|
+
"create a new route",
|
|
1046
|
+
"i want to go from the village to the hut",
|
|
1047
|
+
"make me a loop starting here",
|
|
1048
|
+
"planifie un itin\xE9raire",
|
|
1049
|
+
"cr\xE9e un itin\xE9raire",
|
|
1050
|
+
"fais-moi une boucle depuis",
|
|
1051
|
+
"du village au refuge"
|
|
1052
|
+
],
|
|
1053
|
+
surfaces: ["authoring", "discovery", "routing"]
|
|
1054
|
+
},
|
|
1055
|
+
{
|
|
1056
|
+
id: "compare-alternative-routes",
|
|
1057
|
+
intents: [
|
|
1058
|
+
"which way is better",
|
|
1059
|
+
"compare these two",
|
|
1060
|
+
"worth going via",
|
|
1061
|
+
"what if i went the other way",
|
|
1062
|
+
"quel chemin est mieux",
|
|
1063
|
+
"compare ces deux",
|
|
1064
|
+
"\xE7a vaut le coup de passer par",
|
|
1065
|
+
"par l'autre c\xF4t\xE9"
|
|
1066
|
+
],
|
|
1067
|
+
surfaces: ["routing", "terrain"]
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
id: "create-reachability-zone",
|
|
1071
|
+
intents: [
|
|
1072
|
+
"how far can i get in 2 hours",
|
|
1073
|
+
"what's within an hour of the hut",
|
|
1074
|
+
"draw the reachable area from here",
|
|
1075
|
+
"mark everything within 5 km on foot",
|
|
1076
|
+
"jusqu'o\xF9 puis-je aller",
|
|
1077
|
+
"\xE0 moins d'une heure",
|
|
1078
|
+
"dessine la zone accessible",
|
|
1079
|
+
"accessible \xE0 pied"
|
|
1080
|
+
],
|
|
1081
|
+
surfaces: ["discovery", "zones"]
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
id: "create-zone-from-terrain-threshold",
|
|
1085
|
+
intents: [
|
|
1086
|
+
"mark everything steeper than",
|
|
1087
|
+
"highlight the north facing slopes",
|
|
1088
|
+
"show me the avalanche terrain here",
|
|
1089
|
+
"draw a zone over the steep part",
|
|
1090
|
+
"marque tout ce qui est plus raide",
|
|
1091
|
+
"les pentes orient\xE9es nord",
|
|
1092
|
+
"le terrain avalancheux",
|
|
1093
|
+
"dessine une zone sur les pentes"
|
|
1094
|
+
],
|
|
1095
|
+
surfaces: ["terrain", "zones"]
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
id: "export-and-share",
|
|
1099
|
+
intents: [
|
|
1100
|
+
"export this as gpx",
|
|
1101
|
+
"send this to my watch",
|
|
1102
|
+
"share this route",
|
|
1103
|
+
"share this collection",
|
|
1104
|
+
"give me a link",
|
|
1105
|
+
"embed this on my site",
|
|
1106
|
+
"exporte en gpx",
|
|
1107
|
+
"envoie sur ma montre",
|
|
1108
|
+
"partage cet itin\xE9raire",
|
|
1109
|
+
"partage cette collection",
|
|
1110
|
+
"donne-moi un lien",
|
|
1111
|
+
"int\xE8gre sur mon site"
|
|
1112
|
+
],
|
|
1113
|
+
surfaces: ["sharing"]
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
id: "find-and-add-waypoints",
|
|
1117
|
+
intents: [
|
|
1118
|
+
"are there huts on this route",
|
|
1119
|
+
"where can i park",
|
|
1120
|
+
"add a water stop",
|
|
1121
|
+
"mark the summit",
|
|
1122
|
+
"des refuges sur ce parcours",
|
|
1123
|
+
"o\xF9 me garer",
|
|
1124
|
+
"ajoute une \xE9tape",
|
|
1125
|
+
"marque le sommet",
|
|
1126
|
+
"un point d'eau"
|
|
1127
|
+
],
|
|
1128
|
+
surfaces: ["discovery", "authoring"]
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
id: "generate-route-suggestions",
|
|
1132
|
+
intents: [
|
|
1133
|
+
"suggest a route",
|
|
1134
|
+
"find me a 20 km loop",
|
|
1135
|
+
"something with 1000 m of climbing near here",
|
|
1136
|
+
"what can i do around",
|
|
1137
|
+
"sugg\xE8re un itin\xE9raire",
|
|
1138
|
+
"propose une boucle",
|
|
1139
|
+
"boucle de",
|
|
1140
|
+
"avec du d\xE9nivel\xE9 pr\xE8s de",
|
|
1141
|
+
"que faire autour de",
|
|
1142
|
+
"g\xE9n\xE8re des itin\xE9raires",
|
|
1143
|
+
"propose des itin\xE9raires",
|
|
1144
|
+
"itin\xE9raires de",
|
|
1145
|
+
"d\xE9nivel\xE9 positif",
|
|
1146
|
+
"point de d\xE9part"
|
|
1147
|
+
],
|
|
1148
|
+
surfaces: ["discovery", "authoring"]
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
id: "increase-route-ascent",
|
|
1152
|
+
intents: [
|
|
1153
|
+
"make it steeper",
|
|
1154
|
+
"more climbing",
|
|
1155
|
+
"meters of elevation gain",
|
|
1156
|
+
"metres of elevation gain",
|
|
1157
|
+
"harder version of this route",
|
|
1158
|
+
"i want more vertical",
|
|
1159
|
+
"plus raide",
|
|
1160
|
+
"plus de d\xE9nivel\xE9",
|
|
1161
|
+
"plus de mont\xE9e",
|
|
1162
|
+
"version plus dure",
|
|
1163
|
+
"ajoute du d\xE9nivel\xE9",
|
|
1164
|
+
"de d\xE9nivel\xE9 en plus"
|
|
1165
|
+
],
|
|
1166
|
+
surfaces: ["terrain", "routing"]
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
id: "modify-existing-segment",
|
|
1170
|
+
intents: [
|
|
1171
|
+
"reroute this",
|
|
1172
|
+
"avoid the",
|
|
1173
|
+
"go via",
|
|
1174
|
+
"make it shorter",
|
|
1175
|
+
"take the other side of the valley",
|
|
1176
|
+
"keep it off the road",
|
|
1177
|
+
"modifie le trac\xE9",
|
|
1178
|
+
"\xE9vite",
|
|
1179
|
+
"passe par",
|
|
1180
|
+
"plus court",
|
|
1181
|
+
"raccourcis",
|
|
1182
|
+
"int\xE8gre la boucle",
|
|
1183
|
+
"int\xE8gre cette boucle",
|
|
1184
|
+
"ajoute cette boucle"
|
|
1185
|
+
],
|
|
1186
|
+
surfaces: ["routing", "discovery"]
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
id: "prepare-map-for-editing",
|
|
1190
|
+
intents: [
|
|
1191
|
+
"let's work on this route",
|
|
1192
|
+
"open my route",
|
|
1193
|
+
"i want to edit this",
|
|
1194
|
+
"show me the whole thing",
|
|
1195
|
+
"travaillons sur",
|
|
1196
|
+
"ouvre mon itin\xE9raire",
|
|
1197
|
+
"je veux modifier",
|
|
1198
|
+
"montre-moi tout le parcours"
|
|
1199
|
+
],
|
|
1200
|
+
surfaces: ["routing"]
|
|
1201
|
+
},
|
|
1202
|
+
{
|
|
1203
|
+
id: "visualize-terrain",
|
|
1204
|
+
intents: [
|
|
1205
|
+
"show me the steepness",
|
|
1206
|
+
"turn on hillshade",
|
|
1207
|
+
"can i see the snow depth",
|
|
1208
|
+
"display the aspect",
|
|
1209
|
+
"montre la pente",
|
|
1210
|
+
"affiche la pente",
|
|
1211
|
+
"active le calque",
|
|
1212
|
+
"montre le relief",
|
|
1213
|
+
"hauteur de neige"
|
|
1214
|
+
],
|
|
1215
|
+
surfaces: ["terrain"]
|
|
1216
|
+
}
|
|
1217
|
+
];
|
|
1218
|
+
|
|
1219
|
+
// src/agent/rules/studioRouter.ts
|
|
1220
|
+
var studioRouter = createStudioRouter({
|
|
1221
|
+
playbook: PLAYBOOK,
|
|
1222
|
+
skillRoutes: SKILL_ROUTES,
|
|
1223
|
+
surfaceLocks: SURFACE_LOCKS,
|
|
1224
|
+
surfaces: SURFACES
|
|
1225
|
+
});
|
|
1226
|
+
var recoveryFor = studioRouter.recoveryFor;
|
|
1227
|
+
var selectSurfaces = studioRouter.selectSurfaces;
|
|
1228
|
+
var surfaceTools = studioRouter.surfaceTools;
|
|
1229
|
+
var addendumFor = (addendum, tool, code) => {
|
|
1230
|
+
if (addendum === void 0) {
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
let answered;
|
|
1234
|
+
try {
|
|
1235
|
+
answered = addendum(tool, code);
|
|
1236
|
+
} catch (fault) {
|
|
1237
|
+
surfaceFault(fault);
|
|
1238
|
+
return void 0;
|
|
1239
|
+
}
|
|
1240
|
+
const sentence = typeof answered === "string" ? answered.trim() : "";
|
|
1241
|
+
return sentence === "" ? void 0 : sentence;
|
|
1242
|
+
};
|
|
1243
|
+
var studioRecoveryFor = (tool, code, addendum) => {
|
|
1244
|
+
if (code === void 0 || code === "") {
|
|
1245
|
+
return void 0;
|
|
1246
|
+
}
|
|
1247
|
+
const recovery = recoveryFor(tool, code);
|
|
1248
|
+
const extra = addendumFor(addendum, tool, code);
|
|
1249
|
+
if (recovery === void 0 || extra === void 0) {
|
|
1250
|
+
return recovery ?? extra;
|
|
1251
|
+
}
|
|
1252
|
+
return `${recovery} ${extra}`;
|
|
1253
|
+
};
|
|
1254
|
+
var transcriptObserver = (config) => {
|
|
1255
|
+
const { draftWarning, errorCopy, writer } = config;
|
|
1256
|
+
return {
|
|
1257
|
+
onChecksUnmet: writer.appendChecksUnmet,
|
|
1258
|
+
onError: (message, code) => writer.appendError(resolveAgentError(message, code, errorCopy(), draftWarning?.())),
|
|
1259
|
+
onMessage: writer.setAssistantMessage,
|
|
1260
|
+
onMessageDelta: writer.appendAssistantDelta,
|
|
1261
|
+
onRunId: writer.setRunId,
|
|
1262
|
+
onStateChange: writer.setSessionState,
|
|
1263
|
+
onToolActivity: writer.setActiveTool,
|
|
1264
|
+
onToolCall: (name, input, toolCallId) => writer.appendToolActivity({ input: boundedInputJson(input), name, toolCallId }),
|
|
1265
|
+
onToolResult: writer.settleToolActivity
|
|
1266
|
+
};
|
|
1267
|
+
};
|
|
1268
|
+
var WITHHELD_TAB_ID = "withheld";
|
|
1269
|
+
var idleThread = (runId) => ({
|
|
1270
|
+
pendingConfirmation: null,
|
|
1271
|
+
runId,
|
|
1272
|
+
state: "awaiting_input",
|
|
1273
|
+
transcript: []
|
|
1274
|
+
});
|
|
1275
|
+
var heldThread = (threads, threadId) => Object.hasOwn(threads, threadId) ? threads[threadId] : void 0;
|
|
1276
|
+
var updateThread = (threads, threadId, transform) => {
|
|
1277
|
+
const thread = heldThread(threads, threadId);
|
|
1278
|
+
if (!thread) {
|
|
1279
|
+
return threads;
|
|
1280
|
+
}
|
|
1281
|
+
return { ...threads, [threadId]: transform(thread) };
|
|
1282
|
+
};
|
|
1283
|
+
var initialState = {
|
|
1284
|
+
activeId: null,
|
|
1285
|
+
activeTabId: null,
|
|
1286
|
+
order: [],
|
|
1287
|
+
threads: {}
|
|
1288
|
+
};
|
|
1289
|
+
var createAgentThreadsStore = () => createStore((set) => ({
|
|
1290
|
+
...initialState,
|
|
1291
|
+
addCopilotTab: (threadId) => set((current) => {
|
|
1292
|
+
if (heldThread(current.threads, threadId)) {
|
|
1293
|
+
return current;
|
|
1294
|
+
}
|
|
1295
|
+
return {
|
|
1296
|
+
activeId: threadId,
|
|
1297
|
+
activeTabId: threadId,
|
|
1298
|
+
order: [...current.order, threadId],
|
|
1299
|
+
threads: { ...current.threads, [threadId]: idleThread(null) }
|
|
1300
|
+
};
|
|
1301
|
+
}),
|
|
1302
|
+
answerQuestion: (threadId, entryId, label) => set((current) => ({
|
|
1303
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1304
|
+
...thread,
|
|
1305
|
+
// The shared helper never re-settles: a double click races the send,
|
|
1306
|
+
// and the first answer is the one that was sent.
|
|
1307
|
+
transcript: answerQuestionEntry(thread.transcript, entryId, label)
|
|
1308
|
+
}))
|
|
1309
|
+
})),
|
|
1310
|
+
appendAssistantDelta: (threadId, delta) => set((current) => ({
|
|
1311
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1312
|
+
...thread,
|
|
1313
|
+
transcript: accumulateAssistant(thread.transcript, delta)
|
|
1314
|
+
}))
|
|
1315
|
+
})),
|
|
1316
|
+
appendChecksUnmet: (threadId, unmet) => set((current) => ({
|
|
1317
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1318
|
+
...thread,
|
|
1319
|
+
// A warning, not an error: the run answered and is still healthy, but
|
|
1320
|
+
// the workspace does not back part of what the answer claims. The
|
|
1321
|
+
// shared helper drops an empty list, so a stray empty event renders
|
|
1322
|
+
// nothing rather than an empty orange box.
|
|
1323
|
+
transcript: appendWarningEntry(thread.transcript, unmet)
|
|
1324
|
+
}))
|
|
1325
|
+
})),
|
|
1326
|
+
appendError: (threadId, message) => set((current) => ({
|
|
1327
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1328
|
+
...thread,
|
|
1329
|
+
// The failure is a turn in the conversation, not a transient banner:
|
|
1330
|
+
// appended as its own error entry so it renders in the assistant's lane
|
|
1331
|
+
// and survives in the history as the reply to the turn that failed.
|
|
1332
|
+
transcript: appendErrorEntry(thread.transcript, message)
|
|
1333
|
+
}))
|
|
1334
|
+
})),
|
|
1335
|
+
appendQuestion: (threadId, question) => set((current) => ({
|
|
1336
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1337
|
+
...thread,
|
|
1338
|
+
// The shared helper is idempotent by call id, so a replayed frame
|
|
1339
|
+
// emitting the same asking call twice appends no duplicate card.
|
|
1340
|
+
transcript: appendQuestionEntry(thread.transcript, question)
|
|
1341
|
+
}))
|
|
1342
|
+
})),
|
|
1343
|
+
appendSuggestions: (threadId, suggestions) => set((current) => ({
|
|
1344
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1345
|
+
...thread,
|
|
1346
|
+
// The shared helper is idempotent by entry id (a replayed settle
|
|
1347
|
+
// appends no duplicate card), drops an empty batch, and settles any
|
|
1348
|
+
// prior open batch, whose candidates a regenerate replaced.
|
|
1349
|
+
transcript: appendSuggestionsEntry(thread.transcript, suggestions)
|
|
1350
|
+
}))
|
|
1351
|
+
})),
|
|
1352
|
+
appendToolActivity: (threadId, activity) => set((current) => ({
|
|
1353
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1354
|
+
...thread,
|
|
1355
|
+
// The shared helper is idempotent by call id, so a re-render or a
|
|
1356
|
+
// replayed frame emitting the same call twice appends no duplicate row.
|
|
1357
|
+
transcript: appendActivityEntry(thread.transcript, activity)
|
|
1358
|
+
}))
|
|
1359
|
+
})),
|
|
1360
|
+
appendUserMessage: (threadId, content) => set((current) => ({
|
|
1361
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1362
|
+
...thread,
|
|
1363
|
+
// Any user message settles the open question AND suggestions cards
|
|
1364
|
+
// first: whether the user tapped an option/row (already settled, a
|
|
1365
|
+
// no-op here) or typed their own words, the reply supersedes the
|
|
1366
|
+
// buttons and they go inert.
|
|
1367
|
+
transcript: appendUserEntry(
|
|
1368
|
+
settleOpenSuggestionEntries(settleOpenQuestionEntries(thread.transcript)),
|
|
1369
|
+
content
|
|
1370
|
+
)
|
|
1371
|
+
}))
|
|
1372
|
+
})),
|
|
1373
|
+
chooseSuggestion: (threadId, entryId, seed) => set((current) => ({
|
|
1374
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1375
|
+
...thread,
|
|
1376
|
+
// The shared helper never re-settles: a double click races the staging
|
|
1377
|
+
// chain, and the first pick is the one that ran.
|
|
1378
|
+
transcript: chooseSuggestionEntry(thread.transcript, entryId, seed)
|
|
1379
|
+
}))
|
|
1380
|
+
})),
|
|
1381
|
+
clearPendingConfirmation: (threadId) => set((current) => ({
|
|
1382
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1383
|
+
...thread,
|
|
1384
|
+
pendingConfirmation: null
|
|
1385
|
+
}))
|
|
1386
|
+
})),
|
|
1387
|
+
closeCopilotTab: (threadId) => set((current) => {
|
|
1388
|
+
if (threadId === SEARCH_TAB_ID || threadId === WITHHELD_TAB_ID) {
|
|
1389
|
+
return current;
|
|
1390
|
+
}
|
|
1391
|
+
const order = current.order.filter((id) => id !== threadId);
|
|
1392
|
+
const { [threadId]: _closed, ...threads } = current.threads;
|
|
1393
|
+
const activeId = current.activeId === threadId ? order.at(-1) ?? null : current.activeId;
|
|
1394
|
+
const activeTabId = current.activeTabId === threadId ? activeId ?? SEARCH_TAB_ID : current.activeTabId;
|
|
1395
|
+
return { activeId, activeTabId, order, threads };
|
|
1396
|
+
}),
|
|
1397
|
+
closeThread: (threadId) => set((current) => {
|
|
1398
|
+
const order = current.order.filter((id) => id !== threadId);
|
|
1399
|
+
const { [threadId]: _closed, ...threads } = current.threads;
|
|
1400
|
+
const activeId = current.activeId === threadId ? order.at(-1) ?? null : current.activeId;
|
|
1401
|
+
const activeTabId = current.activeTabId === threadId ? activeId ?? SEARCH_TAB_ID : current.activeTabId;
|
|
1402
|
+
return { activeId, activeTabId, order, threads };
|
|
1403
|
+
}),
|
|
1404
|
+
createThread: (threadId, runId = null) => set((current) => {
|
|
1405
|
+
if (heldThread(current.threads, threadId)) {
|
|
1406
|
+
return current;
|
|
1407
|
+
}
|
|
1408
|
+
return {
|
|
1409
|
+
activeId: threadId,
|
|
1410
|
+
order: [...current.order, threadId],
|
|
1411
|
+
threads: { ...current.threads, [threadId]: idleThread(runId) }
|
|
1412
|
+
};
|
|
1413
|
+
}),
|
|
1414
|
+
setActive: (threadId) => set((current) => heldThread(current.threads, threadId) ? { activeId: threadId } : current),
|
|
1415
|
+
setActiveTab: (tabId) => set((current) => {
|
|
1416
|
+
if (tabId === SEARCH_TAB_ID) {
|
|
1417
|
+
return { activeTabId: SEARCH_TAB_ID };
|
|
1418
|
+
}
|
|
1419
|
+
if (tabId === WITHHELD_TAB_ID) {
|
|
1420
|
+
return { activeTabId: WITHHELD_TAB_ID };
|
|
1421
|
+
}
|
|
1422
|
+
if (!heldThread(current.threads, tabId)) {
|
|
1423
|
+
return current;
|
|
1424
|
+
}
|
|
1425
|
+
return { activeId: tabId, activeTabId: tabId };
|
|
1426
|
+
}),
|
|
1427
|
+
// The run's own index rides onto the settled turn, so a rating on it names the
|
|
1428
|
+
// message the backend will see rather than the position it happens to occupy in
|
|
1429
|
+
// this browser's transcript, which a reload mid-run resets to zero.
|
|
1430
|
+
setAssistantMessage: (threadId, content, messageIndex) => set((current) => ({
|
|
1431
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1432
|
+
...thread,
|
|
1433
|
+
transcript: replaceAssistant(thread.transcript, content, messageIndex)
|
|
1434
|
+
}))
|
|
1435
|
+
})),
|
|
1436
|
+
setPendingConfirmation: (threadId, confirmation) => set((current) => ({
|
|
1437
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1438
|
+
...thread,
|
|
1439
|
+
pendingConfirmation: confirmation
|
|
1440
|
+
}))
|
|
1441
|
+
})),
|
|
1442
|
+
setRunId: (threadId, runId) => set((current) => ({
|
|
1443
|
+
threads: updateThread(current.threads, threadId, (thread) => ({ ...thread, runId }))
|
|
1444
|
+
})),
|
|
1445
|
+
setSessionState: (threadId, state) => set((current) => ({
|
|
1446
|
+
threads: updateThread(current.threads, threadId, (thread) => ({ ...thread, state }))
|
|
1447
|
+
})),
|
|
1448
|
+
settleToolActivity: (threadId, toolCallId, outcome) => set((current) => ({
|
|
1449
|
+
threads: updateThread(current.threads, threadId, (thread) => ({
|
|
1450
|
+
...thread,
|
|
1451
|
+
// The shared helper settles the latest running row for the id, appends
|
|
1452
|
+
// an already-settled row for a server tool the host saw no call for,
|
|
1453
|
+
// and never re-settles a terminal row.
|
|
1454
|
+
transcript: settleActivityEntry(thread.transcript, toolCallId, outcome)
|
|
1455
|
+
}))
|
|
1456
|
+
}))
|
|
1457
|
+
}));
|
|
1458
|
+
var selectAgentDriving = (state) => state.order.some((id) => state.threads[id]?.state === "running");
|
|
1459
|
+
|
|
1460
|
+
// src/agent/engines/agentThreads.ts
|
|
1461
|
+
var QUESTION_TOOL = "studio.question.ask";
|
|
1462
|
+
var GENERATE_TOOL = "studio.itinerary.suggest.generate";
|
|
1463
|
+
var ACCESS_REVOKED = "access-revoked";
|
|
1464
|
+
var holdRejection = (dispatched) => {
|
|
1465
|
+
Promise.resolve(dispatched).then(void 0, () => void 0);
|
|
1466
|
+
};
|
|
1467
|
+
var isOutcome = (answered) => typeof answered === "object" && answered !== null && "ok" in answered && typeof answered.ok === "boolean";
|
|
1468
|
+
var restorableThreads = (named) => {
|
|
1469
|
+
const kept = /* @__PURE__ */ new Map();
|
|
1470
|
+
const entries = Array.isArray(named) ? named : [];
|
|
1471
|
+
for (const entry of entries) {
|
|
1472
|
+
if (kept.size >= MAX_OPEN_COPILOT_TABS) {
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1475
|
+
if (typeof entry !== "object" || entry === null) {
|
|
1476
|
+
continue;
|
|
1477
|
+
}
|
|
1478
|
+
const id = "id" in entry ? entry.id : void 0;
|
|
1479
|
+
const runId = "runId" in entry ? entry.runId : void 0;
|
|
1480
|
+
if (typeof id !== "string" || id === "" || id === SEARCH_TAB_ID || id === WITHHELD_TAB_ID || kept.has(id)) {
|
|
1481
|
+
continue;
|
|
1482
|
+
}
|
|
1483
|
+
kept.set(id, { id, runId: typeof runId === "string" && runId !== "" ? runId : null });
|
|
1484
|
+
}
|
|
1485
|
+
return [...kept.values()];
|
|
1486
|
+
};
|
|
1487
|
+
var AgentThreadsEngine = class {
|
|
1488
|
+
config;
|
|
1489
|
+
ids;
|
|
1490
|
+
store;
|
|
1491
|
+
tabs;
|
|
1492
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
1493
|
+
/** The store subscription the listeners are notified through, while the engine runs. */
|
|
1494
|
+
releaseStore = null;
|
|
1495
|
+
/** The UI store the driving flag is mirrored into, while the engine runs. */
|
|
1496
|
+
mirrored = null;
|
|
1497
|
+
/**
|
|
1498
|
+
* What the URL named at construction, kept while the viewer the seed read is withheld the
|
|
1499
|
+
* co-pilot and restored for that viewer once entitled. Null for a seed that read an entitled
|
|
1500
|
+
* viewer, and once restored.
|
|
1501
|
+
*/
|
|
1502
|
+
unrestored = null;
|
|
1503
|
+
/** The viewer seam the engine hears a change of the entitlement from, while it runs. */
|
|
1504
|
+
heard = null;
|
|
1505
|
+
/** One host per thread: its session and its started guard. */
|
|
1506
|
+
hosts = /* @__PURE__ */ new Map();
|
|
1507
|
+
/** The resolver of each thread's parked confirmation. */
|
|
1508
|
+
confirmations = /* @__PURE__ */ new Map();
|
|
1509
|
+
/** The surfaces each thread's run is routed to; a thread with none offers every tool. */
|
|
1510
|
+
surfaces = /* @__PURE__ */ new Map();
|
|
1511
|
+
/** The last message each thread routed on, replayed by a re-route from state. */
|
|
1512
|
+
lastRouted = /* @__PURE__ */ new Map();
|
|
1513
|
+
/** The generate call that owns the workspace's one suggest session, and its thread. */
|
|
1514
|
+
suggestBatchOwner = null;
|
|
1515
|
+
/** The suggestions cards whose pick is still applying, by entry id. */
|
|
1516
|
+
stagingPicks = /* @__PURE__ */ new Set();
|
|
1517
|
+
/**
|
|
1518
|
+
* The threads whose last message is out and whose turn the session has not picked up. While
|
|
1519
|
+
* a thread is here, its session's `awaiting_input` is the run being readied and never the
|
|
1520
|
+
* turn settling.
|
|
1521
|
+
*/
|
|
1522
|
+
awaitingTurn = /* @__PURE__ */ new Set();
|
|
1523
|
+
/**
|
|
1524
|
+
* The state each thread's session last reported, and no entry for one that has reported none,
|
|
1525
|
+
* which reads `awaiting_input`. It says whether a message is sent into a turn under way, which
|
|
1526
|
+
* the session answers with no report of `running`.
|
|
1527
|
+
*/
|
|
1528
|
+
sessionStates = /* @__PURE__ */ new Map();
|
|
1529
|
+
/** Whether nobody is watching. A parked engine opens nothing and answers no command. */
|
|
1530
|
+
parked = true;
|
|
1531
|
+
disposed = false;
|
|
1532
|
+
/**
|
|
1533
|
+
* The tab strip the studio's tab verbs mutate through. Every member but the two reads,
|
|
1534
|
+
* `countOpen` and `hasTab`, does nothing while the engine is parked, and an opening member
|
|
1535
|
+
* then answers the tab already shown.
|
|
1536
|
+
*/
|
|
1537
|
+
tabSurface = {
|
|
1538
|
+
addCopilotTab: () => this.live() ? this.openTab() : this.shownTab(),
|
|
1539
|
+
closeCopilotTab: (tabId) => {
|
|
1540
|
+
if (this.live()) {
|
|
1541
|
+
this.closeTab(tabId);
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
// The Search and withheld pseudo-tabs are not in `order`, so its length is exactly the
|
|
1545
|
+
// number of conversations the create gate compares against the limit.
|
|
1546
|
+
countOpen: () => this.store.getState().order.length,
|
|
1547
|
+
// The strip holds Search, each open conversation and, for a viewer withheld the co-pilot,
|
|
1548
|
+
// the withheld tab, and no other id.
|
|
1549
|
+
hasTab: (tabId) => tabId === SEARCH_TAB_ID || tabId === WITHHELD_TAB_ID && this.withheld() || this.store.getState().order.includes(tabId),
|
|
1550
|
+
openCopilot: () => this.live() ? this.openOrReveal() : this.shownTab(),
|
|
1551
|
+
reset: () => {
|
|
1552
|
+
if (this.live()) {
|
|
1553
|
+
this.resetThreads();
|
|
1554
|
+
}
|
|
1555
|
+
},
|
|
1556
|
+
setActiveTab: (tabId) => {
|
|
1557
|
+
if (this.live()) {
|
|
1558
|
+
this.showTab(tabId);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
/**
|
|
1563
|
+
* Constructing one seeds the store and does nothing else: it reads the URL seam once and the
|
|
1564
|
+
* viewer's entitlement as it stands, builds no host, opens no run and writes no URL. A React
|
|
1565
|
+
* binding constructs during a render React is free to throw away, and a constructor with a side
|
|
1566
|
+
* effect outside its own store would leave the discarded copy acting.
|
|
1567
|
+
*/
|
|
1568
|
+
constructor(options) {
|
|
1569
|
+
const { ids, store, tabs, ...config } = options;
|
|
1570
|
+
this.config = config;
|
|
1571
|
+
this.ids = ids;
|
|
1572
|
+
this.tabs = tabs;
|
|
1573
|
+
this.store = store ?? createAgentThreadsStore();
|
|
1574
|
+
this.seed(config.threadsUrl?.readOnce() ?? {});
|
|
1575
|
+
}
|
|
1576
|
+
/** getSnapshot returns the conversations' state, by reference and stable between changes. */
|
|
1577
|
+
getSnapshot() {
|
|
1578
|
+
return this.store.getState();
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
1582
|
+
* unsubscribe, which is idempotent.
|
|
1583
|
+
*
|
|
1584
|
+
* The first listener resumes the engine and the last one leaving parks it, which is the whole
|
|
1585
|
+
* lifecycle a component can express correctly: React tears an effect down and sets it up
|
|
1586
|
+
* again with the same object under StrictMode, so a latch here would leave a live surface
|
|
1587
|
+
* bound to a dead engine. Each call is its own subscription, so two owners subscribing one
|
|
1588
|
+
* shared function each hold the engine until they release it.
|
|
1589
|
+
*/
|
|
1590
|
+
subscribe(listener) {
|
|
1591
|
+
if (this.disposed) {
|
|
1592
|
+
return () => {
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
const subscription = { listener };
|
|
1596
|
+
this.subscriptions.add(subscription);
|
|
1597
|
+
if (this.parked) {
|
|
1598
|
+
this.resume();
|
|
1599
|
+
}
|
|
1600
|
+
return () => {
|
|
1601
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
if (!this.parked) {
|
|
1605
|
+
this.park();
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* configure replaces the configuration. Nothing is asked and no session is rebuilt: every
|
|
1611
|
+
* member is read when it is used, so a binding may call this on every render and an unchanged
|
|
1612
|
+
* configuration costs an assignment. Two things move with the context: the driving flag's
|
|
1613
|
+
* mirror, when it carries a different UI store (the store it leaves is reset, and the new one is
|
|
1614
|
+
* brought in line with the conversations), and the subscription to the viewer, when it carries
|
|
1615
|
+
* a different viewer.
|
|
1616
|
+
*/
|
|
1617
|
+
configure(config) {
|
|
1618
|
+
this.config = config;
|
|
1619
|
+
if (this.mirrored !== null && this.mirrored !== config.context.ui) {
|
|
1620
|
+
this.releaseMirror();
|
|
1621
|
+
this.mirrorInto(config.context.ui);
|
|
1622
|
+
}
|
|
1623
|
+
if (this.heard !== null && this.heard.viewer !== config.context.viewer) {
|
|
1624
|
+
this.hearViewer(config.context.viewer);
|
|
1625
|
+
this.restoreForEntitled();
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* dispose parks the engine and drops every listener, for good.
|
|
1630
|
+
*
|
|
1631
|
+
* Idempotent, and every call after it is a no-op rather than an error, a subscription
|
|
1632
|
+
* included: an owner torn down mid-run should not have to guard the calls it already queued.
|
|
1633
|
+
*/
|
|
1634
|
+
dispose() {
|
|
1635
|
+
if (this.disposed) {
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
if (!this.parked) {
|
|
1639
|
+
this.park();
|
|
1640
|
+
}
|
|
1641
|
+
this.disposed = true;
|
|
1642
|
+
this.subscriptions.clear();
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* answerQuestion settles the active conversation's question card with the picked option, then
|
|
1646
|
+
* sends its label as the next message. Settling first is what makes the send's sweep of open
|
|
1647
|
+
* cards leave the pick marked.
|
|
1648
|
+
*
|
|
1649
|
+
* It does nothing unless `entryId` names a question card of the conversation that is still
|
|
1650
|
+
* open: a second answer to one card, and an answer to a card a typed reply already settled,
|
|
1651
|
+
* send no message, since the run is waiting on neither.
|
|
1652
|
+
*/
|
|
1653
|
+
answerQuestion(entryId, label) {
|
|
1654
|
+
const threadId = this.activeThread();
|
|
1655
|
+
if (threadId === null || !this.hasOpenQuestion(threadId, entryId)) {
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
this.store.getState().answerQuestion(threadId, entryId, label);
|
|
1659
|
+
this.send(threadId, label);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* chooseSuggestion applies one suggested route from a suggestions card, settles the card, and
|
|
1663
|
+
* sends the pick's label as the next message.
|
|
1664
|
+
*
|
|
1665
|
+
* The pick is applied client-side through `studio.itinerary.suggest.applyCandidate`, which
|
|
1666
|
+
* reshapes the segment the batch was generated for or appends the route as a new one, so the
|
|
1667
|
+
* route is on the map before the model reads the reply. It applies to the open itinerary and
|
|
1668
|
+
* never creates one. A second pick on a card whose apply is still out does nothing, since two
|
|
1669
|
+
* appends would put the route in the itinerary twice. A failed apply leaves the card open and
|
|
1670
|
+
* writes the staging error, so the user can pick again; an apply a host's bus rejects, or
|
|
1671
|
+
* answers with no result, is a failed one. A pick whose confirmation was withheld (the user
|
|
1672
|
+
* kept a staged draft the apply would drop, or left the prompt to expire) leaves the card open
|
|
1673
|
+
* and writes nothing. A pick whose apply lands after the engine parked, or after its
|
|
1674
|
+
* conversation closed, writes nothing and opens no run.
|
|
1675
|
+
*/
|
|
1676
|
+
chooseSuggestion(entryId, seed, label) {
|
|
1677
|
+
const threadId = this.activeThread();
|
|
1678
|
+
if (threadId === null || this.stagingPicks.has(entryId)) {
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
this.stagingPicks.add(entryId);
|
|
1682
|
+
void this.applyPick(threadId, entryId, seed, label);
|
|
1683
|
+
}
|
|
1684
|
+
/** closeAiTab closes one conversation through `studio.tabs.close`. */
|
|
1685
|
+
closeAiTab(tabId) {
|
|
1686
|
+
if (this.live()) {
|
|
1687
|
+
holdRejection(this.config.bus.dispatch(this.tabsContext(), "studio.tabs.close", { tabId }));
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
/** newAiTab opens a conversation through `studio.tabs.create`. */
|
|
1691
|
+
newAiTab() {
|
|
1692
|
+
if (this.live()) {
|
|
1693
|
+
holdRejection(
|
|
1694
|
+
this.config.bus.dispatch(this.tabsContext(), "studio.tabs.create", {
|
|
1695
|
+
kind: "copilot"
|
|
1696
|
+
})
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* previewCandidate paints one staged suggestion on the map through
|
|
1702
|
+
* `studio.itinerary.suggest.select`, the call the suggestions panel's own rows make, so
|
|
1703
|
+
* hovering a card option and hovering a panel row cannot diverge.
|
|
1704
|
+
*/
|
|
1705
|
+
previewCandidate(seed) {
|
|
1706
|
+
if (this.live()) {
|
|
1707
|
+
holdRejection(
|
|
1708
|
+
this.config.bus.dispatch(this.config.context, "studio.itinerary.suggest.select", {
|
|
1709
|
+
seed
|
|
1710
|
+
})
|
|
1711
|
+
);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* resolveConfirmation settles the active conversation's confirmation card with the user's
|
|
1716
|
+
* decision and clears the card. With nothing pending (a stale click after a stop already
|
|
1717
|
+
* settled it) it does nothing.
|
|
1718
|
+
*/
|
|
1719
|
+
resolveConfirmation(approved) {
|
|
1720
|
+
const threadId = this.activeThread();
|
|
1721
|
+
if (threadId === null) {
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1724
|
+
const resolve = this.confirmations.get(threadId);
|
|
1725
|
+
if (resolve === void 0) {
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
this.confirmations.delete(threadId);
|
|
1729
|
+
this.store.getState().clearPendingConfirmation(threadId);
|
|
1730
|
+
resolve(approved);
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* stopActive ends the active conversation's run: it denies a pending confirmation, asks the
|
|
1734
|
+
* gateway to close the run (a run the session gave up reading included), swaps a fresh session
|
|
1735
|
+
* in under the same thread so the next message opens a clean run, drops the run id and parks
|
|
1736
|
+
* the thread on `awaiting_input`. The close is what stops the run spending model budget: a
|
|
1737
|
+
* session torn down without it leaves the run going until the gateway's own timeout. The
|
|
1738
|
+
* transcript stays, since a stop is the user's choice rather than a failure.
|
|
1739
|
+
*/
|
|
1740
|
+
stopActive() {
|
|
1741
|
+
const threadId = this.activeThread();
|
|
1742
|
+
if (threadId === null) {
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1745
|
+
this.denyPendingConfirmation(threadId);
|
|
1746
|
+
this.ensureHost(threadId).restart();
|
|
1747
|
+
this.store.getState().setRunId(threadId, null);
|
|
1748
|
+
this.settle(threadId);
|
|
1749
|
+
this.syncUrl();
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* submit sends a message into the active conversation: the first one opens a run scoped to
|
|
1753
|
+
* the organization of the resource the co-pilot is open on, with the studio snapshot as its
|
|
1754
|
+
* context, and a later one is delivered into the open run.
|
|
1755
|
+
*
|
|
1756
|
+
* The conversation reads `running` from the submit, so the workspace locks and a surface
|
|
1757
|
+
* offers its Stop before the run's context is captured and its start is made. It returns to
|
|
1758
|
+
* `awaiting_input` when the turn settles, and at once when there is no organization to scope
|
|
1759
|
+
* a run to or the gateway refuses the start.
|
|
1760
|
+
*/
|
|
1761
|
+
submit(message) {
|
|
1762
|
+
const threadId = this.activeThread();
|
|
1763
|
+
if (threadId !== null) {
|
|
1764
|
+
this.send(threadId, message);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
/** switchTab shows another tab, a conversation or a pseudo-tab, through `studio.tabs.switch`. */
|
|
1768
|
+
switchTab(tabId) {
|
|
1769
|
+
if (this.live()) {
|
|
1770
|
+
holdRejection(this.config.bus.dispatch(this.tabsContext(), "studio.tabs.switch", { tabId }));
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* live reports whether something watches the engine, which is when it acts. Every command asks
|
|
1775
|
+
* it first, so a live engine restores the URL's conversations for a viewer entitled since the
|
|
1776
|
+
* seed (see {@link restoreForEntitled}) ahead of the act: a host whose viewer tells no change
|
|
1777
|
+
* still meets them there.
|
|
1778
|
+
*/
|
|
1779
|
+
live() {
|
|
1780
|
+
if (this.parked || this.disposed) {
|
|
1781
|
+
return false;
|
|
1782
|
+
}
|
|
1783
|
+
this.restoreForEntitled();
|
|
1784
|
+
return true;
|
|
1785
|
+
}
|
|
1786
|
+
/**
|
|
1787
|
+
* isOpen reports whether an answer for a conversation still has somewhere to land: the engine
|
|
1788
|
+
* is live and the conversation has not closed. An answer that arrives after either belongs to
|
|
1789
|
+
* nobody.
|
|
1790
|
+
*/
|
|
1791
|
+
isOpen(threadId) {
|
|
1792
|
+
return this.live() && this.store.getState().threads[threadId] !== void 0;
|
|
1793
|
+
}
|
|
1794
|
+
/** activeThread is the conversation a command acts on, or null while the engine is not live. */
|
|
1795
|
+
activeThread() {
|
|
1796
|
+
return this.live() ? this.store.getState().activeId : null;
|
|
1797
|
+
}
|
|
1798
|
+
/** shownTab is the tab the strip shows, what an opening tab verb answers while parked. */
|
|
1799
|
+
shownTab() {
|
|
1800
|
+
return this.store.getState().activeTabId ?? SEARCH_TAB_ID;
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* withheld reads whether the viewer is withheld the co-pilot, from the viewer seam as it
|
|
1804
|
+
* answers now. A membership resolves after a host has mounted and an entitlement can lapse
|
|
1805
|
+
* mid-session, so the answer is never held: each decision that turns on it asks again.
|
|
1806
|
+
*/
|
|
1807
|
+
withheld() {
|
|
1808
|
+
return !this.config.context.viewer.hasEntitlement("copilot");
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* seed writes the conversations a mount opens with, from the URL and the entitlement.
|
|
1812
|
+
*
|
|
1813
|
+
* A viewer withheld the co-pilot is restored none, whatever the URL names: their one way into
|
|
1814
|
+
* the co-pilot is the withheld tab. What the URL named is kept for them, and
|
|
1815
|
+
* {@link restoreForEntitled} restores it once they are entitled.
|
|
1816
|
+
*/
|
|
1817
|
+
seed(mirrored) {
|
|
1818
|
+
if (this.withheld()) {
|
|
1819
|
+
this.unrestored = mirrored;
|
|
1820
|
+
this.store.getState().setActiveTab(
|
|
1821
|
+
mirrored.activeThreadId === WITHHELD_TAB_ID ? WITHHELD_TAB_ID : SEARCH_TAB_ID
|
|
1822
|
+
);
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
this.restore(mirrored);
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* restore writes the conversations of an entitled viewer, from what the URL names, and answers
|
|
1829
|
+
* the ids it created.
|
|
1830
|
+
*
|
|
1831
|
+
* The URL's list passes through {@link restorableThreads} first, and a conversation already
|
|
1832
|
+
* open keeps its place. With none to restore, a viewer holding no conversation is opened a
|
|
1833
|
+
* fresh one, and the panel lands on Search. Otherwise it lands on the tab the URL names when
|
|
1834
|
+
* that tab is now open, and on Search when it is not: the withheld tab is never an entitled
|
|
1835
|
+
* viewer's.
|
|
1836
|
+
*/
|
|
1837
|
+
restore(mirrored) {
|
|
1838
|
+
const state = this.store.getState();
|
|
1839
|
+
const named = restorableThreads(mirrored.threads).filter(
|
|
1840
|
+
({ id }) => !Object.hasOwn(state.threads, id)
|
|
1841
|
+
);
|
|
1842
|
+
const initial = mirrored.activeThreadId;
|
|
1843
|
+
if (named.length === 0) {
|
|
1844
|
+
const created = state.order.length === 0 ? [this.ids.next()] : [];
|
|
1845
|
+
for (const id of created) {
|
|
1846
|
+
state.createThread(id);
|
|
1847
|
+
}
|
|
1848
|
+
state.setActiveTab(SEARCH_TAB_ID);
|
|
1849
|
+
return created;
|
|
1850
|
+
}
|
|
1851
|
+
for (const { id, runId } of named) {
|
|
1852
|
+
state.createThread(id, runId);
|
|
1853
|
+
}
|
|
1854
|
+
const open = this.store.getState().order;
|
|
1855
|
+
state.setActiveTab(
|
|
1856
|
+
initial !== void 0 && (initial === SEARCH_TAB_ID || open.includes(initial)) ? initial : SEARCH_TAB_ID
|
|
1857
|
+
);
|
|
1858
|
+
return named.map(({ id }) => id);
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* restoreForEntitled restores what the URL named at construction for a viewer the seed read as
|
|
1862
|
+
* withheld and the viewer seam now answers as entitled. It runs once: a viewer who loses the
|
|
1863
|
+
* entitlement afterwards and regains it is not restored a second time. A live engine connects
|
|
1864
|
+
* each conversation it restores, so one carrying a run id reconnects to its run; a parked one
|
|
1865
|
+
* leaves that to the next resume. The URL is written with what the restore holds: a withheld
|
|
1866
|
+
* viewer's reveal may have mirrored the withheld tab over the conversations it named.
|
|
1867
|
+
*/
|
|
1868
|
+
restoreForEntitled() {
|
|
1869
|
+
const mirrored = this.unrestored;
|
|
1870
|
+
if (mirrored === null || this.withheld()) {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
this.unrestored = null;
|
|
1874
|
+
const created = this.restore(mirrored);
|
|
1875
|
+
this.syncUrl();
|
|
1876
|
+
if (!this.parked && !this.disposed) {
|
|
1877
|
+
for (const id of created) {
|
|
1878
|
+
this.connect(id);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* hearViewer subscribes to a viewer seam's changes, releasing the one heard before, so a
|
|
1884
|
+
* viewer entitled while the engine runs is restored the URL's conversations as the seam tells.
|
|
1885
|
+
*/
|
|
1886
|
+
hearViewer(viewer) {
|
|
1887
|
+
this.heard?.release();
|
|
1888
|
+
this.heard = null;
|
|
1889
|
+
let release = () => void 0;
|
|
1890
|
+
this.tellSeam(() => {
|
|
1891
|
+
release = viewer.subscribe(() => this.restoreForEntitled());
|
|
1892
|
+
});
|
|
1893
|
+
this.heard = { release, viewer };
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* connect builds a thread's host and resumes its session, reconnecting to the run the thread
|
|
1897
|
+
* carries. A resume that faults drops the stale run id, mirrors the drop and leaves the
|
|
1898
|
+
* conversation usable, through the thread's faults, which also tell the host a reconnect
|
|
1899
|
+
* refused 401.
|
|
1900
|
+
*/
|
|
1901
|
+
connect(threadId) {
|
|
1902
|
+
this.ensureHost(threadId).resume(
|
|
1903
|
+
this.store.getState().threads[threadId]?.runId ?? null,
|
|
1904
|
+
(error) => this.faultsFor(threadId).resumeFailed(error)
|
|
1905
|
+
);
|
|
1906
|
+
}
|
|
1907
|
+
/** resume starts the engine for its first subscriber. */
|
|
1908
|
+
resume() {
|
|
1909
|
+
this.restoreForEntitled();
|
|
1910
|
+
this.parked = false;
|
|
1911
|
+
this.releaseStore = this.store.subscribe((state) => {
|
|
1912
|
+
this.syncDriving(state);
|
|
1913
|
+
notifyListeners(Array.from(this.subscriptions, ({ listener }) => listener));
|
|
1914
|
+
});
|
|
1915
|
+
this.mirrorInto(this.config.context.ui);
|
|
1916
|
+
for (const id of [...this.store.getState().order]) {
|
|
1917
|
+
this.connect(id);
|
|
1918
|
+
}
|
|
1919
|
+
this.hearViewer(this.config.context.viewer);
|
|
1920
|
+
this.tellSeam(() => this.tabs?.register(this.tabSurface));
|
|
1921
|
+
}
|
|
1922
|
+
/** park stops the engine when its last subscriber leaves. */
|
|
1923
|
+
park() {
|
|
1924
|
+
this.parked = true;
|
|
1925
|
+
this.releaseStore?.();
|
|
1926
|
+
this.releaseStore = null;
|
|
1927
|
+
for (const host of this.hosts.values()) {
|
|
1928
|
+
host.dispose();
|
|
1929
|
+
}
|
|
1930
|
+
this.awaitingTurn.clear();
|
|
1931
|
+
this.sessionStates.clear();
|
|
1932
|
+
this.settleStreamingThreads();
|
|
1933
|
+
for (const threadId of [...this.confirmations.keys()]) {
|
|
1934
|
+
this.denyPendingConfirmation(threadId);
|
|
1935
|
+
}
|
|
1936
|
+
this.releaseMirror();
|
|
1937
|
+
const heard = this.heard;
|
|
1938
|
+
this.heard = null;
|
|
1939
|
+
if (heard !== null) {
|
|
1940
|
+
this.tellSeam(heard.release);
|
|
1941
|
+
}
|
|
1942
|
+
this.tellSeam(() => this.tabs?.unregister());
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* tellSeam calls one of the host's seams the engine writes to on its own paths: the URL
|
|
1946
|
+
* mirror and the tab strip's slot. A seam that throws stops neither the resume, the park nor
|
|
1947
|
+
* the command that reached it, and its fault is surfaced apart, as a listener's is.
|
|
1948
|
+
*/
|
|
1949
|
+
tellSeam(tell) {
|
|
1950
|
+
try {
|
|
1951
|
+
tell();
|
|
1952
|
+
} catch (fault) {
|
|
1953
|
+
surfaceFault(fault);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* send hands a message to a thread's host, with the conversation on `running` from this
|
|
1958
|
+
* moment: the workspace is the model's from the submit, across the capture of the run's
|
|
1959
|
+
* context, its start and the opening of its stream.
|
|
1960
|
+
*
|
|
1961
|
+
* Written before the host is called, so a submit the host answers at once (no organization
|
|
1962
|
+
* to scope a run to) returns the conversation to `awaiting_input` through its fault.
|
|
1963
|
+
*/
|
|
1964
|
+
send(threadId, message) {
|
|
1965
|
+
if (this.sessionStates.get(threadId) !== "running") {
|
|
1966
|
+
this.awaitingTurn.add(threadId);
|
|
1967
|
+
}
|
|
1968
|
+
this.writeSessionState(threadId, "running");
|
|
1969
|
+
this.ensureHost(threadId).submit(message);
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1972
|
+
* settle returns a conversation to `awaiting_input`: its turn settled, its run faulted or was
|
|
1973
|
+
* stopped. It ends the wait for a turn, so the next report of its session is read as it is.
|
|
1974
|
+
*/
|
|
1975
|
+
settle(threadId) {
|
|
1976
|
+
this.awaitingTurn.delete(threadId);
|
|
1977
|
+
this.writeSessionState(threadId, "awaiting_input");
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* reportSessionState writes the lifecycle state a thread's session reports, while the engine
|
|
1981
|
+
* is live.
|
|
1982
|
+
*
|
|
1983
|
+
* A session reports `ended` as it is disposed, and the park disposes every one of them. The
|
|
1984
|
+
* park ends no conversation, so what its teardown reports is not written: a conversation that
|
|
1985
|
+
* never ran keeps reading `awaiting_input`, and a host reading the store sees no state the
|
|
1986
|
+
* park passed through.
|
|
1987
|
+
*
|
|
1988
|
+
* While a thread waits on its turn, its session's `awaiting_input` is not written either: a
|
|
1989
|
+
* session that read a run before reports it as it readies the next one, which would lower the
|
|
1990
|
+
* lock between the submit and the turn. The wait ends when the session reports `running`,
|
|
1991
|
+
* which it does from the message it takes, and its reports are the conversation's from
|
|
1992
|
+
* there: the turn's settle is one of them, whether or not the turn carried a frame of its own.
|
|
1993
|
+
*/
|
|
1994
|
+
reportSessionState(threadId, state) {
|
|
1995
|
+
this.sessionStates.set(threadId, state);
|
|
1996
|
+
if (!this.live() || state === "awaiting_input" && this.awaitingTurn.has(threadId)) {
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
this.awaitingTurn.delete(threadId);
|
|
2000
|
+
this.writeSessionState(threadId, state);
|
|
2001
|
+
}
|
|
2002
|
+
/** writeSessionState writes a thread's state when it differs from the one it reads. */
|
|
2003
|
+
writeSessionState(threadId, state) {
|
|
2004
|
+
const thread = this.store.getState().threads[threadId];
|
|
2005
|
+
if (thread !== void 0 && thread.state !== state) {
|
|
2006
|
+
this.store.getState().setSessionState(threadId, state);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
/** hasOpenQuestion reports whether `entryId` is a question card the thread has not settled. */
|
|
2010
|
+
hasOpenQuestion(threadId, entryId) {
|
|
2011
|
+
return this.store.getState().threads[threadId]?.transcript.some(
|
|
2012
|
+
(entry) => entry.role === "question" && entry.id === entryId && !entry.settled
|
|
2013
|
+
) ?? false;
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* settleStreamingThreads returns every conversation that reads `running` to `awaiting_input`
|
|
2017
|
+
* once the park has disposed its session.
|
|
2018
|
+
*
|
|
2019
|
+
* No session streams the turn any more, and the session the next resume builds starts on
|
|
2020
|
+
* `awaiting_input` and reports a change only. A conversation left on `running` would raise
|
|
2021
|
+
* the driving lock at that resume with nothing to lower it. Its run id stays, so the resume
|
|
2022
|
+
* reconnects the run and the turn's frames report `running` again.
|
|
2023
|
+
*/
|
|
2024
|
+
settleStreamingThreads() {
|
|
2025
|
+
const { order, threads } = this.store.getState();
|
|
2026
|
+
for (const id of order) {
|
|
2027
|
+
if (threads[id]?.state === "running") {
|
|
2028
|
+
this.store.getState().setSessionState(id, "awaiting_input");
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
/** mirrorInto starts mirroring the driving flag into `ui`, brought in line at once. */
|
|
2033
|
+
mirrorInto(ui) {
|
|
2034
|
+
this.mirrored = ui;
|
|
2035
|
+
this.syncDriving(this.store.getState());
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* releaseMirror stops mirroring, leaving the UI store with no driving flag, no edit lock and
|
|
2039
|
+
* no hand-off: a studio the co-pilot left is never stranded inert.
|
|
2040
|
+
*/
|
|
2041
|
+
releaseMirror() {
|
|
2042
|
+
const ui = this.mirrored;
|
|
2043
|
+
if (ui === null) {
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
this.mirrored = null;
|
|
2047
|
+
ui.getState().setAgentDriving(false);
|
|
2048
|
+
ui.getState().agentClearEditLocks();
|
|
2049
|
+
ui.getState().setAgentHandoff(null);
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* syncDriving writes the driving flag through to the UI store on a real flip only, so a token
|
|
2053
|
+
* stream does not churn it.
|
|
2054
|
+
*
|
|
2055
|
+
* When the runs yield the workspace, the entities they locked are released, except the one a
|
|
2056
|
+
* run left in an open edit session for the user to adjust and save: that draft outlives the
|
|
2057
|
+
* run, and so does the co-pilot's authorship of it.
|
|
2058
|
+
*/
|
|
2059
|
+
syncDriving(state) {
|
|
2060
|
+
const ui = this.mirrored;
|
|
2061
|
+
if (ui === null) {
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
const driving = selectAgentDriving(state);
|
|
2065
|
+
if (ui.getState().agentDriving === driving) {
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
ui.getState().setAgentDriving(driving);
|
|
2069
|
+
if (!driving) {
|
|
2070
|
+
ui.getState().agentClearEditLocks(agentHandoffTarget(ui.getState()));
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
/** syncUrl mirrors the thread ids, their run ids and the active tab through the URL seam. */
|
|
2074
|
+
syncUrl() {
|
|
2075
|
+
const state = this.store.getState();
|
|
2076
|
+
const threads = state.order.map((id) => ({ id, runId: state.threads[id]?.runId ?? null }));
|
|
2077
|
+
this.tellSeam(
|
|
2078
|
+
() => this.config.threadsUrl?.write({ activeThreadId: state.activeTabId ?? null, threads })
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* tabsContext is the tool context a tab verb is dispatched with: the studio's own, with this
|
|
2083
|
+
* engine's tab strip layered over it and every other seam left live.
|
|
2084
|
+
*/
|
|
2085
|
+
tabsContext() {
|
|
2086
|
+
return layerToolContext(this.config.context, { tabs: this.tabSurface });
|
|
2087
|
+
}
|
|
2088
|
+
/** ensureHost returns a thread's host, building it on first use. */
|
|
2089
|
+
ensureHost(threadId) {
|
|
2090
|
+
let host = this.hosts.get(threadId);
|
|
2091
|
+
if (host === void 0) {
|
|
2092
|
+
host = this.hostFor(threadId);
|
|
2093
|
+
this.hosts.set(threadId, host);
|
|
2094
|
+
}
|
|
2095
|
+
return host;
|
|
2096
|
+
}
|
|
2097
|
+
/**
|
|
2098
|
+
* hostFor builds one thread's host. The run is scoped to the organization of the resource the
|
|
2099
|
+
* co-pilot is open on, read through the rule the panel's gate reads, so a run opens for the
|
|
2100
|
+
* organization whose card the panel shows and a personal resource opens none. A snapshot that
|
|
2101
|
+
* fails to build opens the run without a context rather than blocking the message.
|
|
2102
|
+
*/
|
|
2103
|
+
hostFor(threadId) {
|
|
2104
|
+
return createConversationHost({
|
|
2105
|
+
appendUserMessage: (message) => this.store.getState().appendUserMessage(threadId, message),
|
|
2106
|
+
buildContext: () => buildStudioSnapshot(this.config.context).catch(() => void 0),
|
|
2107
|
+
buildSession: () => this.sessionFor(threadId),
|
|
2108
|
+
onMissingOrganization: () => this.faultsFor(threadId).missingOrganization(),
|
|
2109
|
+
onSendFault: (error, runGone) => this.faultsFor(threadId).recover(runGone, error),
|
|
2110
|
+
onStartError: (organizationId, error, runId) => this.faultsFor(threadId).handleStartError(organizationId, error, runId),
|
|
2111
|
+
resolveOrganizationId: () => copilotOrganizationId(this.config.context.ui.getState()),
|
|
2112
|
+
routeForMessage: (message) => this.routeForMessage(threadId, message),
|
|
2113
|
+
routeForState: () => this.routeForState(threadId)
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* sessionFor builds one thread's session. Both confirmation gates, the server tool's and the
|
|
2118
|
+
* client tool's the bus raises through `ctx.confirm`, park on that thread's in-chat card, and
|
|
2119
|
+
* a client tool's card reads its localized body with the request's values, so a merge names
|
|
2120
|
+
* the rows it is about to join.
|
|
2121
|
+
*/
|
|
2122
|
+
sessionFor(threadId) {
|
|
2123
|
+
this.sessionStates.delete(threadId);
|
|
2124
|
+
return new AgentEngine({
|
|
2125
|
+
bus: this.config.bus,
|
|
2126
|
+
confirmServerTool: (confirmation) => this.requestConfirmation(
|
|
2127
|
+
threadId,
|
|
2128
|
+
confirmation.name,
|
|
2129
|
+
this.config.strings.confirm.serverToolFallback(confirmation.name)
|
|
2130
|
+
),
|
|
2131
|
+
// Layered rather than spread: a spread would evaluate the context's late-bound getters once,
|
|
2132
|
+
// and a session built before the map mounts would carry no map for its whole life.
|
|
2133
|
+
ctx: layerToolContext(this.config.context, {
|
|
2134
|
+
confirm: (request) => this.requestConfirmation(
|
|
2135
|
+
threadId,
|
|
2136
|
+
request.name,
|
|
2137
|
+
confirmSentence(this.config.strings, request.descriptionLabel, request.values) ?? request.description
|
|
2138
|
+
),
|
|
2139
|
+
origin: "agent"
|
|
2140
|
+
}),
|
|
2141
|
+
observer: this.observerFor(threadId),
|
|
2142
|
+
// What a tool moved rides its result, and a failure carries the playbook's recovery: the
|
|
2143
|
+
// playbook tells the model both, so a session without them would answer every call bare.
|
|
2144
|
+
// The host's addendum is read at the failure, so a host that changes it reaches the
|
|
2145
|
+
// sessions it already built.
|
|
2146
|
+
recoveryFor: (tool, code) => studioRecoveryFor(tool, code, this.config.recoveryAddendum),
|
|
2147
|
+
routesServerTools: this.config.routesServerTools,
|
|
2148
|
+
stateDelta: studioStateDelta,
|
|
2149
|
+
toolSurface: () => {
|
|
2150
|
+
const surfaces = this.surfaces.get(threadId);
|
|
2151
|
+
return surfaces === void 0 ? void 0 : surfaceTools(surfaces);
|
|
2152
|
+
},
|
|
2153
|
+
transport: this.config.transport
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
/**
|
|
2157
|
+
* observerFor maps one thread's session onto its transcript, then layers the co-pilot's own
|
|
2158
|
+
* side effects over it: the URL mirror of a new run id, the question card, the suggest
|
|
2159
|
+
* session's owner, the edit lock and the hand-off, the suggestions card and the re-route.
|
|
2160
|
+
*/
|
|
2161
|
+
observerFor(threadId) {
|
|
2162
|
+
const store = this.store;
|
|
2163
|
+
const transcript = transcriptObserver({
|
|
2164
|
+
draftWarning: () => ({
|
|
2165
|
+
note: this.config.strings.prompt.budgetDraftOpen,
|
|
2166
|
+
// Whether a draft sits unsaved is a fact about the moment the run ends. `editingKind`
|
|
2167
|
+
// counts a create armed with no id yet, which is just as losable.
|
|
2168
|
+
open: captureStudioState(this.config.context).editingKind !== null
|
|
2169
|
+
}),
|
|
2170
|
+
errorCopy: () => this.config.errorCopy,
|
|
2171
|
+
writer: {
|
|
2172
|
+
appendAssistantDelta: (delta) => store.getState().appendAssistantDelta(threadId, delta),
|
|
2173
|
+
appendChecksUnmet: (unmet) => store.getState().appendChecksUnmet(threadId, unmet),
|
|
2174
|
+
appendError: (message) => store.getState().appendError(threadId, message),
|
|
2175
|
+
appendToolActivity: (activity) => store.getState().appendToolActivity(threadId, activity),
|
|
2176
|
+
setAssistantMessage: (content, messageIndex) => store.getState().setAssistantMessage(threadId, content, messageIndex),
|
|
2177
|
+
setRunId: (runId) => store.getState().setRunId(threadId, runId),
|
|
2178
|
+
setSessionState: (state) => this.reportSessionState(threadId, state),
|
|
2179
|
+
settleToolActivity: (toolCallId, outcome) => store.getState().settleToolActivity(threadId, toolCallId, outcome)
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
return {
|
|
2183
|
+
...transcript,
|
|
2184
|
+
onError: (message, code) => {
|
|
2185
|
+
transcript.onError?.(message, code);
|
|
2186
|
+
if (code === ACCESS_REVOKED) {
|
|
2187
|
+
this.tellSeam(() => this.config.invalidateMemberships?.());
|
|
2188
|
+
}
|
|
2189
|
+
},
|
|
2190
|
+
onRunId: (runId) => {
|
|
2191
|
+
transcript.onRunId?.(runId);
|
|
2192
|
+
this.syncUrl();
|
|
2193
|
+
},
|
|
2194
|
+
onToolCall: (name, input, toolCallId) => {
|
|
2195
|
+
if (this.appendQuestionCard(threadId, name, input, toolCallId)) {
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
if (name === GENERATE_TOOL) {
|
|
2199
|
+
this.suggestBatchOwner = { threadId, toolCallId };
|
|
2200
|
+
}
|
|
2201
|
+
const ui = this.config.context.ui;
|
|
2202
|
+
const target = agentEditLockTarget(name, input);
|
|
2203
|
+
if (target !== null) {
|
|
2204
|
+
ui.getState().agentLockEntity(target.kind, target.id);
|
|
2205
|
+
}
|
|
2206
|
+
if (agentTakesEntityBack(name, input)) {
|
|
2207
|
+
ui.getState().setAgentHandoff(null);
|
|
2208
|
+
}
|
|
2209
|
+
transcript.onToolCall?.(name, input, toolCallId);
|
|
2210
|
+
},
|
|
2211
|
+
onToolResult: (toolCallId, outcome) => {
|
|
2212
|
+
const settledGenerate = outcome.status === "ok" && this.isGenerate(threadId, toolCallId);
|
|
2213
|
+
transcript.onToolResult?.(toolCallId, outcome);
|
|
2214
|
+
if (settledGenerate) {
|
|
2215
|
+
this.appendSuggestionsCard(threadId, toolCallId);
|
|
2216
|
+
}
|
|
2217
|
+
this.hosts.get(threadId)?.reroute();
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* appendQuestionCard renders a question call as its own card, parsed with the tool's own
|
|
2223
|
+
* schema, and reports whether it did. A malformed input falls through to the ordinary
|
|
2224
|
+
* activity row, whose dispatch then settles red, which is the honest rendering of that call.
|
|
2225
|
+
*/
|
|
2226
|
+
appendQuestionCard(threadId, name, input, toolCallId) {
|
|
2227
|
+
if (name !== QUESTION_TOOL) {
|
|
2228
|
+
return false;
|
|
2229
|
+
}
|
|
2230
|
+
const parsed = questionToolContracts[QUESTION_TOOL].input.safeParse(input);
|
|
2231
|
+
if (!parsed.success) {
|
|
2232
|
+
return false;
|
|
2233
|
+
}
|
|
2234
|
+
this.store.getState().appendQuestion(threadId, {
|
|
2235
|
+
options: parsed.data.options.map((option) => ({
|
|
2236
|
+
description: option.description ?? null,
|
|
2237
|
+
label: option.label
|
|
2238
|
+
})),
|
|
2239
|
+
question: parsed.data.question,
|
|
2240
|
+
toolCallId
|
|
2241
|
+
});
|
|
2242
|
+
return true;
|
|
2243
|
+
}
|
|
2244
|
+
/** isGenerate reports whether a thread recorded `toolCallId` as a generate's activity row. */
|
|
2245
|
+
isGenerate(threadId, toolCallId) {
|
|
2246
|
+
return this.store.getState().threads[threadId]?.transcript.some(
|
|
2247
|
+
(entry) => entry.role === "activity" && entry.id === toolCallId && entry.name === GENERATE_TOOL
|
|
2248
|
+
) ?? false;
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* appendSuggestionsCard renders the live suggest session's candidates as the thread's
|
|
2252
|
+
* suggestions card, keyed off the generating call so a replayed settle appends no duplicate,
|
|
2253
|
+
* and frames the batch once while the thread is the tab on screen.
|
|
2254
|
+
*
|
|
2255
|
+
* It snapshots the SESSION, never the model's echo, so every candidate shows its true colour
|
|
2256
|
+
* and metrics. A settle whose call no longer owns the session renders nothing: another thread
|
|
2257
|
+
* re-pointed the session, and its candidates belong to that conversation.
|
|
2258
|
+
*/
|
|
2259
|
+
appendSuggestionsCard(threadId, toolCallId) {
|
|
2260
|
+
const owner = this.suggestBatchOwner;
|
|
2261
|
+
if (owner?.threadId !== threadId || owner.toolCallId !== toolCallId) {
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
const context = this.config.context;
|
|
2265
|
+
const candidates = selectSuggestionSession(context.ui.getState())?.candidates ?? [];
|
|
2266
|
+
if (candidates.length === 0) {
|
|
2267
|
+
return;
|
|
2268
|
+
}
|
|
2269
|
+
const entryId = `${toolCallId}:card`;
|
|
2270
|
+
const transcript = this.store.getState().threads[threadId]?.transcript ?? [];
|
|
2271
|
+
if (transcript.some((entry) => entry.id === entryId)) {
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
this.store.getState().appendSuggestions(threadId, {
|
|
2275
|
+
candidates: candidates.map((candidate) => ({
|
|
2276
|
+
ascentMeters: candidate.ascentMeters,
|
|
2277
|
+
color: candidate.color,
|
|
2278
|
+
distanceMeters: candidate.distanceMeters,
|
|
2279
|
+
durationSeconds: candidate.durationSeconds,
|
|
2280
|
+
seed: candidate.seed
|
|
2281
|
+
})),
|
|
2282
|
+
entryId
|
|
2283
|
+
});
|
|
2284
|
+
if (this.store.getState().activeTabId !== threadId) {
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
const bounds = boundsOf(candidates.map((candidate) => candidate.geometry));
|
|
2288
|
+
if (bounds) {
|
|
2289
|
+
holdRejection(this.config.bus.dispatch(context, "studio.map.fitBounds", { bounds }));
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* stagePick applies one suggested route through the bus, and answers how it ended.
|
|
2294
|
+
*
|
|
2295
|
+
* A tool bus's dispatch never rejects and always answers a result, and a host's own may do
|
|
2296
|
+
* neither: an apply that rejects answers the refusal the bus would have made of the throw, and
|
|
2297
|
+
* one whose answer states no outcome is refused as `internal`.
|
|
2298
|
+
*/
|
|
2299
|
+
async stagePick(seed) {
|
|
2300
|
+
const context = this.config.context;
|
|
2301
|
+
try {
|
|
2302
|
+
const applied = await this.config.bus.dispatch(
|
|
2303
|
+
context,
|
|
2304
|
+
"studio.itinerary.suggest.applyCandidate",
|
|
2305
|
+
{
|
|
2306
|
+
seed,
|
|
2307
|
+
segmentName: defaultSegmentName(
|
|
2308
|
+
context.ui.getState().activeItinerary?.segments?.length ?? 0
|
|
2309
|
+
)
|
|
2310
|
+
}
|
|
2311
|
+
);
|
|
2312
|
+
if (isOutcome(applied)) {
|
|
2313
|
+
return applied;
|
|
2314
|
+
}
|
|
2315
|
+
return {
|
|
2316
|
+
code: "internal",
|
|
2317
|
+
error: "the apply of a suggested route answered no result",
|
|
2318
|
+
ok: false
|
|
2319
|
+
};
|
|
2320
|
+
} catch (err) {
|
|
2321
|
+
return failureFromThrown(err);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* applyPick runs one suggestions-card pick, releasing the card's guard however it ends.
|
|
2326
|
+
*
|
|
2327
|
+
* The apply asks before it drops a staged draft. A reader who keeps theirs (a confirmation
|
|
2328
|
+
* denied or left to expire) refused nothing: the card stays pickable and nothing is written.
|
|
2329
|
+
*/
|
|
2330
|
+
async applyPick(threadId, entryId, seed, label) {
|
|
2331
|
+
try {
|
|
2332
|
+
const applied = await this.stagePick(seed);
|
|
2333
|
+
if (!this.isOpen(threadId)) {
|
|
2334
|
+
return;
|
|
2335
|
+
}
|
|
2336
|
+
if (!applied.ok) {
|
|
2337
|
+
if (isConfirmationWithheld(applied)) {
|
|
2338
|
+
return;
|
|
2339
|
+
}
|
|
2340
|
+
this.store.getState().appendError(threadId, this.config.strings.prompt.suggestionsStageError);
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
this.store.getState().chooseSuggestion(threadId, entryId, seed);
|
|
2344
|
+
this.send(threadId, label);
|
|
2345
|
+
} finally {
|
|
2346
|
+
this.stagingPicks.delete(entryId);
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* requestConfirmation parks a thread's decision on its in-chat card. A decision already parked
|
|
2351
|
+
* on the thread is denied first, so no resolver is stranded, and one requested while the
|
|
2352
|
+
* engine is parked, or for a conversation that has closed, is denied at once: no card could
|
|
2353
|
+
* show it.
|
|
2354
|
+
*/
|
|
2355
|
+
requestConfirmation(threadId, name, summary) {
|
|
2356
|
+
if (!this.isOpen(threadId)) {
|
|
2357
|
+
return Promise.resolve(false);
|
|
2358
|
+
}
|
|
2359
|
+
return new Promise((resolve) => {
|
|
2360
|
+
this.confirmations.get(threadId)?.(false);
|
|
2361
|
+
this.confirmations.set(threadId, resolve);
|
|
2362
|
+
this.store.getState().setPendingConfirmation(threadId, { name, summary });
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
/** denyPendingConfirmation denies a thread's parked decision, if any, and clears its card. */
|
|
2366
|
+
denyPendingConfirmation(threadId) {
|
|
2367
|
+
const resolve = this.confirmations.get(threadId);
|
|
2368
|
+
if (resolve !== void 0) {
|
|
2369
|
+
this.confirmations.delete(threadId);
|
|
2370
|
+
resolve(false);
|
|
2371
|
+
}
|
|
2372
|
+
this.store.getState().clearPendingConfirmation(threadId);
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* faultsFor binds the shared fault handling to one thread. The missing-organization line
|
|
2376
|
+
* depends on why there is none, read when the fault happens: with nothing open it asks for an
|
|
2377
|
+
* itinerary or a zone, and with a personal one open it says the co-pilot works on an
|
|
2378
|
+
* organization's.
|
|
2379
|
+
*/
|
|
2380
|
+
faultsFor(threadId) {
|
|
2381
|
+
const { context, invalidateAiConfig, invalidateMemberships, onSignInRefused, strings } = this.config;
|
|
2382
|
+
const store = this.store;
|
|
2383
|
+
return createConversationFaults({
|
|
2384
|
+
copy: {
|
|
2385
|
+
generic: strings.prompt.errorGeneric,
|
|
2386
|
+
missingOrganization: copilotOrganizationId(context.ui.getState()) === null ? strings.copilot.errorPersonalResource : strings.copilot.errorNoResource,
|
|
2387
|
+
noAccess: strings.copilot.errorNoAccess,
|
|
2388
|
+
notConfigured: strings.copilot.errorNotConfigured,
|
|
2389
|
+
notEntitled: strings.copilot.withheld,
|
|
2390
|
+
rateLimited: strings.prompt.errorRateLimited,
|
|
2391
|
+
tooLarge: strings.prompt.errorTooLarge
|
|
2392
|
+
},
|
|
2393
|
+
invalidateAiConfig,
|
|
2394
|
+
invalidateMemberships,
|
|
2395
|
+
// A fault that dropped the run id has to reach the URL, or a reload would resume a run
|
|
2396
|
+
// that is gone.
|
|
2397
|
+
onSettled: () => this.syncUrl(),
|
|
2398
|
+
onSignInRefused,
|
|
2399
|
+
writer: {
|
|
2400
|
+
appendError: (message) => store.getState().appendError(threadId, message),
|
|
2401
|
+
setRunId: (runId) => store.getState().setRunId(threadId, runId),
|
|
2402
|
+
// A fault ends the wait for a turn that will not come, so the state it writes (every one
|
|
2403
|
+
// returns the conversation to `awaiting_input`) lands as it is.
|
|
2404
|
+
setSessionState: (state) => {
|
|
2405
|
+
this.awaitingTurn.delete(threadId);
|
|
2406
|
+
this.writeSessionState(threadId, state);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
/** routeForMessage picks the surfaces a thread's next turn offers, from its message. */
|
|
2412
|
+
routeForMessage(threadId, message) {
|
|
2413
|
+
this.lastRouted.set(threadId, message);
|
|
2414
|
+
this.route(threadId, message);
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* routeForState re-picks from live state, replaying the thread's last message: its words
|
|
2418
|
+
* carry the keyword and skill matches, and dropping them would narrow the manifest at the
|
|
2419
|
+
* moment the run needs it wider.
|
|
2420
|
+
*/
|
|
2421
|
+
routeForState(threadId) {
|
|
2422
|
+
this.route(threadId, this.lastRouted.get(threadId) ?? "");
|
|
2423
|
+
}
|
|
2424
|
+
/** route records a thread's pick, with its previous one as the stickiness input. */
|
|
2425
|
+
route(threadId, message) {
|
|
2426
|
+
const decision = selectSurfaces(
|
|
2427
|
+
message,
|
|
2428
|
+
routerStateFrom(this.config.context),
|
|
2429
|
+
this.surfaces.get(threadId) ?? []
|
|
2430
|
+
);
|
|
2431
|
+
this.surfaces.set(threadId, decision.surfaces);
|
|
2432
|
+
}
|
|
2433
|
+
/** openTab opens a conversation, with its host built so the tools and a submit find it. */
|
|
2434
|
+
openTab() {
|
|
2435
|
+
const id = this.ids.next();
|
|
2436
|
+
this.store.getState().addCopilotTab(id);
|
|
2437
|
+
this.ensureHost(id);
|
|
2438
|
+
this.syncUrl();
|
|
2439
|
+
return id;
|
|
2440
|
+
}
|
|
2441
|
+
/**
|
|
2442
|
+
* closeTab finishes one conversation's run and disposes its session, and the others run on.
|
|
2443
|
+
*
|
|
2444
|
+
* A pending confirmation is denied, and the suggest session is discarded when it is headless
|
|
2445
|
+
* (no draft, no open panel) and this thread staged it or nobody did: a session the human is
|
|
2446
|
+
* using stays, and so does one another conversation owns. Closing the last conversation of an
|
|
2447
|
+
* entitled viewer opens a fresh one, so the strip always carries one.
|
|
2448
|
+
*/
|
|
2449
|
+
closeTab(tabId) {
|
|
2450
|
+
this.hosts.get(tabId)?.finish();
|
|
2451
|
+
this.hosts.delete(tabId);
|
|
2452
|
+
this.surfaces.delete(tabId);
|
|
2453
|
+
this.lastRouted.delete(tabId);
|
|
2454
|
+
this.awaitingTurn.delete(tabId);
|
|
2455
|
+
this.sessionStates.delete(tabId);
|
|
2456
|
+
this.denyPendingConfirmation(tabId);
|
|
2457
|
+
const context = this.config.context;
|
|
2458
|
+
const owner = this.suggestBatchOwner;
|
|
2459
|
+
const session = selectSuggestionSession(context.ui.getState());
|
|
2460
|
+
if (session !== null && !session.draft && context.ui.getState().openContent !== "suggest" && (owner === null || owner.threadId === tabId)) {
|
|
2461
|
+
this.suggestBatchOwner = null;
|
|
2462
|
+
holdRejection(this.config.bus.dispatch(context, "studio.itinerary.suggest.discard", {}));
|
|
2463
|
+
}
|
|
2464
|
+
this.store.getState().closeCopilotTab(tabId);
|
|
2465
|
+
if (!this.withheld() && this.store.getState().order.length === 0) {
|
|
2466
|
+
this.openTab();
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
this.syncUrl();
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* showTab points the panel at a tab and mirrors it. The withheld tab is Search for an entitled
|
|
2473
|
+
* viewer, so no caller shows them the host's own content over their conversations.
|
|
2474
|
+
*/
|
|
2475
|
+
showTab(tabId) {
|
|
2476
|
+
this.store.getState().setActiveTab(tabId === WITHHELD_TAB_ID && !this.withheld() ? SEARCH_TAB_ID : tabId);
|
|
2477
|
+
this.syncUrl();
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* resetThreads clears the co-pilot for a switched-to resource: every conversation closes, so
|
|
2481
|
+
* the one about the resource being left cannot leak into the next, and the panel lands on
|
|
2482
|
+
* Search behind the fresh conversation the last close opens.
|
|
2483
|
+
*/
|
|
2484
|
+
resetThreads() {
|
|
2485
|
+
for (const id of [...this.store.getState().order]) {
|
|
2486
|
+
this.closeTab(id);
|
|
2487
|
+
}
|
|
2488
|
+
this.showTab(SEARCH_TAB_ID);
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* openOrReveal reveals the co-pilot, focusing a conversation rather than opening a second one:
|
|
2492
|
+
* a withheld viewer lands on the withheld tab, an entitled one on their latest
|
|
2493
|
+
* conversation, and a new one opens only when there is none.
|
|
2494
|
+
*/
|
|
2495
|
+
openOrReveal() {
|
|
2496
|
+
if (this.withheld()) {
|
|
2497
|
+
this.showTab(WITHHELD_TAB_ID);
|
|
2498
|
+
return WITHHELD_TAB_ID;
|
|
2499
|
+
}
|
|
2500
|
+
const existing = this.store.getState().order.at(-1);
|
|
2501
|
+
if (existing !== void 0) {
|
|
2502
|
+
this.showTab(existing);
|
|
2503
|
+
return existing;
|
|
2504
|
+
}
|
|
2505
|
+
return this.openTab();
|
|
2506
|
+
}
|
|
2507
|
+
};
|
|
2508
|
+
var DirectorChatEngine = class {
|
|
2509
|
+
config;
|
|
2510
|
+
store;
|
|
2511
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
2512
|
+
/** The store subscription the listeners are notified through, while the engine runs. */
|
|
2513
|
+
releaseStore = null;
|
|
2514
|
+
/** The conversation's host: its one session and its started guard, built on first use. */
|
|
2515
|
+
host = null;
|
|
2516
|
+
/**
|
|
2517
|
+
* Whether the last instruction is out and the session has not picked its turn up. While it
|
|
2518
|
+
* is, the session's `awaiting_input` is the run being readied and never the turn settling.
|
|
2519
|
+
*/
|
|
2520
|
+
awaitingTurn = false;
|
|
2521
|
+
/**
|
|
2522
|
+
* The state the conversation's session last reported, `awaiting_input` for one that has
|
|
2523
|
+
* reported none. It says whether an instruction is sent into a turn under way, which the
|
|
2524
|
+
* session answers with no report of `running`.
|
|
2525
|
+
*/
|
|
2526
|
+
sessionState = "awaiting_input";
|
|
2527
|
+
/** Whether nobody is watching. A parked engine opens nothing and answers no command. */
|
|
2528
|
+
parked = true;
|
|
2529
|
+
disposed = false;
|
|
2530
|
+
/**
|
|
2531
|
+
* Constructing one holds the options and does nothing else: no host, no session, no run. A
|
|
2532
|
+
* React binding constructs during a render React is free to throw away.
|
|
2533
|
+
*/
|
|
2534
|
+
constructor(options) {
|
|
2535
|
+
const { store, ...config } = options;
|
|
2536
|
+
this.config = config;
|
|
2537
|
+
this.store = store ?? createVideoDirectorStore();
|
|
2538
|
+
}
|
|
2539
|
+
/** getSnapshot returns the conversation's state, by reference and stable between changes. */
|
|
2540
|
+
getSnapshot() {
|
|
2541
|
+
return this.store.getState();
|
|
2542
|
+
}
|
|
2543
|
+
/**
|
|
2544
|
+
* subscribe registers a listener for every change of the snapshot, and returns its own
|
|
2545
|
+
* unsubscribe, which is idempotent. The first listener starts the engine, reconnecting the
|
|
2546
|
+
* run a park left behind, and the last one leaving parks it; each call is its own
|
|
2547
|
+
* subscription.
|
|
2548
|
+
*/
|
|
2549
|
+
subscribe(listener) {
|
|
2550
|
+
if (this.disposed) {
|
|
2551
|
+
return () => {
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
const subscription = { listener };
|
|
2555
|
+
this.subscriptions.add(subscription);
|
|
2556
|
+
if (this.parked) {
|
|
2557
|
+
this.resume();
|
|
2558
|
+
}
|
|
2559
|
+
return () => {
|
|
2560
|
+
if (!this.subscriptions.delete(subscription) || this.subscriptions.size > 0) {
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
if (!this.parked) {
|
|
2564
|
+
this.park();
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* configure replaces the configuration. Nothing is asked and no session is rebuilt, since
|
|
2570
|
+
* every member is read when it is used, so a binding may call this on every render.
|
|
2571
|
+
*/
|
|
2572
|
+
configure(config) {
|
|
2573
|
+
this.config = config;
|
|
2574
|
+
}
|
|
2575
|
+
/**
|
|
2576
|
+
* dispose parks the engine and drops every listener, for good, and asks the gateway to close
|
|
2577
|
+
* the conversation's run: nothing reads it again, and a run left open spends model budget
|
|
2578
|
+
* until the gateway's own timeout. The conversation is left on `awaiting_input` with no run
|
|
2579
|
+
* id and its transcript intact. Idempotent, and every call after it is a no-op rather than an
|
|
2580
|
+
* error.
|
|
2581
|
+
*/
|
|
2582
|
+
dispose() {
|
|
2583
|
+
if (this.disposed) {
|
|
2584
|
+
return;
|
|
2585
|
+
}
|
|
2586
|
+
this.disposed = true;
|
|
2587
|
+
this.closeRun();
|
|
2588
|
+
if (!this.parked) {
|
|
2589
|
+
this.park();
|
|
2590
|
+
}
|
|
2591
|
+
this.subscriptions.clear();
|
|
2592
|
+
const { runId, state } = this.store.getState();
|
|
2593
|
+
if (runId !== null || state !== "awaiting_input") {
|
|
2594
|
+
this.store.getState().stopRun();
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* stop ends the run: the gateway is asked to close it (a run the session gave up reading
|
|
2599
|
+
* included), a fresh session is swapped in so the next instruction opens a clean run, and the
|
|
2600
|
+
* conversation is parked on `awaiting_input`. The close is what stops the run spending model
|
|
2601
|
+
* budget: a session torn down without it leaves the run going until the gateway's own timeout.
|
|
2602
|
+
* The transcript stays, since a stop is the user's choice and nothing the run did may vanish.
|
|
2603
|
+
*/
|
|
2604
|
+
stop() {
|
|
2605
|
+
if (!this.live()) {
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
this.ensureHost().restart();
|
|
2609
|
+
this.awaitingTurn = false;
|
|
2610
|
+
this.store.getState().stopRun();
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* submit sends an instruction: the first one opens a run scoped to the wizard itinerary's
|
|
2614
|
+
* organization, with the camera plan as its context, and a later one is delivered into the
|
|
2615
|
+
* open run.
|
|
2616
|
+
*
|
|
2617
|
+
* The conversation reads `running` from the submit, so a surface offers its Stop before the
|
|
2618
|
+
* run has started. It returns to `awaiting_input` when the turn settles, and at once when the
|
|
2619
|
+
* itinerary's organization is not known yet or the gateway refuses the start.
|
|
2620
|
+
*/
|
|
2621
|
+
submit(message) {
|
|
2622
|
+
if (!this.live()) {
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
this.awaitingTurn = this.sessionState !== "running";
|
|
2626
|
+
this.writeSessionState("running");
|
|
2627
|
+
this.ensureHost().submit(message);
|
|
2628
|
+
}
|
|
2629
|
+
/** live reports whether something watches the engine, which is when it acts. */
|
|
2630
|
+
live() {
|
|
2631
|
+
return !this.parked && !this.disposed;
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* resume starts the engine for its first subscriber, and reconnects the run a park left
|
|
2635
|
+
* behind. A reconnect that faults drops the stale run id and leaves the conversation usable.
|
|
2636
|
+
* With no run to reconnect it builds nothing: the session is built by the first instruction.
|
|
2637
|
+
*/
|
|
2638
|
+
resume() {
|
|
2639
|
+
this.parked = false;
|
|
2640
|
+
this.releaseStore = this.store.subscribe(() => {
|
|
2641
|
+
notifyListeners(Array.from(this.subscriptions, ({ listener }) => listener));
|
|
2642
|
+
});
|
|
2643
|
+
const { runId } = this.store.getState();
|
|
2644
|
+
if (runId !== null) {
|
|
2645
|
+
this.ensureHost().resume(runId, () => {
|
|
2646
|
+
this.store.getState().setRunId(null);
|
|
2647
|
+
this.settle();
|
|
2648
|
+
});
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* park stops the engine when its last subscriber leaves: the session is disposed with no
|
|
2653
|
+
* close, so the run goes on at the gateway and the conversation keeps its id for the next
|
|
2654
|
+
* subscriber to reconnect.
|
|
2655
|
+
*
|
|
2656
|
+
* A conversation that read `running` settles on `awaiting_input`: no session streams it any
|
|
2657
|
+
* more, and the session the next resume builds starts on `awaiting_input` and reports a
|
|
2658
|
+
* change only. A conversation at rest is left as it is, so a remount writes nothing.
|
|
2659
|
+
*/
|
|
2660
|
+
park() {
|
|
2661
|
+
this.parked = true;
|
|
2662
|
+
this.releaseStore?.();
|
|
2663
|
+
this.releaseStore = null;
|
|
2664
|
+
this.host?.dispose();
|
|
2665
|
+
this.awaitingTurn = false;
|
|
2666
|
+
if (this.store.getState().state === "running") {
|
|
2667
|
+
this.store.getState().setSessionState("awaiting_input");
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
* closeRun asks the gateway to close the conversation's run, for {@link dispose}.
|
|
2672
|
+
*
|
|
2673
|
+
* While the engine runs, the session holds the run and knows whether a close is still owed,
|
|
2674
|
+
* so the host finishes it. After a park no session holds it: the close is posted through the
|
|
2675
|
+
* transport for the run id the park kept, unless that run had already ended. A close the
|
|
2676
|
+
* gateway refuses is dropped, since the run it names is gone or expires on the gateway's own
|
|
2677
|
+
* timeout, and nothing is left to report it to.
|
|
2678
|
+
*/
|
|
2679
|
+
closeRun() {
|
|
2680
|
+
if (!this.parked) {
|
|
2681
|
+
this.host?.finish();
|
|
2682
|
+
return;
|
|
2683
|
+
}
|
|
2684
|
+
const { runId, state } = this.store.getState();
|
|
2685
|
+
if (runId !== null && state !== "ended") {
|
|
2686
|
+
void this.config.transport.sendInput(runId, { type: "close" }).catch(() => void 0);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
/**
|
|
2690
|
+
* settle returns the conversation to `awaiting_input`: its turn settled or its run faulted.
|
|
2691
|
+
* It ends the wait for a turn, so the next report of its session is read as it is.
|
|
2692
|
+
*/
|
|
2693
|
+
settle() {
|
|
2694
|
+
this.awaitingTurn = false;
|
|
2695
|
+
this.writeSessionState("awaiting_input");
|
|
2696
|
+
}
|
|
2697
|
+
/**
|
|
2698
|
+
* reportSessionState writes the lifecycle state the session reports, while the engine is
|
|
2699
|
+
* live: a session reports `ended` as the park disposes it, and the park ends no conversation.
|
|
2700
|
+
* While the conversation waits on its turn, the session's `awaiting_input` is not written
|
|
2701
|
+
* either: it is the run being readied. The wait ends when the session reports `running`,
|
|
2702
|
+
* which it does from the message it takes, and its reports are the conversation's from
|
|
2703
|
+
* there: the turn's settle is one of them, whether or not the turn carried a frame of its own.
|
|
2704
|
+
*/
|
|
2705
|
+
reportSessionState(state) {
|
|
2706
|
+
this.sessionState = state;
|
|
2707
|
+
if (!this.live() || state === "awaiting_input" && this.awaitingTurn) {
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
this.awaitingTurn = false;
|
|
2711
|
+
this.writeSessionState(state);
|
|
2712
|
+
}
|
|
2713
|
+
/** writeSessionState writes the conversation's state when it differs from the one it reads. */
|
|
2714
|
+
writeSessionState(state) {
|
|
2715
|
+
if (this.store.getState().state !== state) {
|
|
2716
|
+
this.store.getState().setSessionState(state);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
/** ensureHost returns the conversation's host, building it on first use. */
|
|
2720
|
+
ensureHost() {
|
|
2721
|
+
this.host ??= createConversationHost({
|
|
2722
|
+
appendUserMessage: (message) => this.store.getState().appendUserMessage(message),
|
|
2723
|
+
buildContext: () => Promise.resolve(buildVideoSnapshot(this.config.context) ?? void 0),
|
|
2724
|
+
buildSession: () => this.session(),
|
|
2725
|
+
onMissingOrganization: () => this.faults().missingOrganization(),
|
|
2726
|
+
onSendFault: (error, runGone) => this.faults().recover(runGone, error),
|
|
2727
|
+
onStartError: (organizationId, error, runId) => this.faults().handleStartError(organizationId, error, runId),
|
|
2728
|
+
resolveOrganizationId: () => this.config.organizationId
|
|
2729
|
+
});
|
|
2730
|
+
return this.host;
|
|
2731
|
+
}
|
|
2732
|
+
/** session builds the conversation's session over the camera-scoped bus. */
|
|
2733
|
+
session() {
|
|
2734
|
+
const store = this.store;
|
|
2735
|
+
this.sessionState = "awaiting_input";
|
|
2736
|
+
return new AgentEngine({
|
|
2737
|
+
bus: this.config.bus,
|
|
2738
|
+
// A destructive server tool gets the studio's own prompt, built from its name. The camera
|
|
2739
|
+
// verbs never take this path; the contract of a session requires a gate regardless.
|
|
2740
|
+
confirmServerTool: (confirmation) => this.config.context.confirm?.({
|
|
2741
|
+
description: this.config.strings.confirm.serverToolFallback(confirmation.name),
|
|
2742
|
+
input: void 0,
|
|
2743
|
+
name: confirmation.name
|
|
2744
|
+
}) ?? Promise.resolve(false),
|
|
2745
|
+
ctx: this.config.context,
|
|
2746
|
+
// No draft warning: the camera verbs arm no edit session, so a budget ceiling has no
|
|
2747
|
+
// draft to lose.
|
|
2748
|
+
observer: transcriptObserver({
|
|
2749
|
+
errorCopy: () => this.config.errorCopy,
|
|
2750
|
+
writer: {
|
|
2751
|
+
appendAssistantDelta: (delta) => store.getState().appendAssistantDelta(delta),
|
|
2752
|
+
appendError: (message) => store.getState().appendError(message),
|
|
2753
|
+
appendToolActivity: (activity) => store.getState().appendToolActivity(activity),
|
|
2754
|
+
setActiveTool: (summary) => store.getState().setActiveTool(summary),
|
|
2755
|
+
setAssistantMessage: (content) => store.getState().setAssistantMessage(content),
|
|
2756
|
+
setRunId: (runId) => store.getState().setRunId(runId),
|
|
2757
|
+
setSessionState: (state) => this.reportSessionState(state),
|
|
2758
|
+
settleToolActivity: (toolCallId, outcome) => store.getState().settleToolActivity(toolCallId, outcome)
|
|
2759
|
+
}
|
|
2760
|
+
}),
|
|
2761
|
+
// The director's own prompt: the co-pilot's would teach itineraries, zones and overlays to
|
|
2762
|
+
// a run whose whole manifest is the camera verbs.
|
|
2763
|
+
profile: "video-director",
|
|
2764
|
+
// A failed camera verb carries the playbook's recovery, and the host's addendum read at the
|
|
2765
|
+
// failure. No state delta: the camera verbs move no part of the studio one reports.
|
|
2766
|
+
recoveryFor: (tool, code) => studioRecoveryFor(tool, code, this.config.recoveryAddendum),
|
|
2767
|
+
transport: this.config.transport
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
/**
|
|
2771
|
+
* faults binds the shared fault handling to the conversation. No URL is mirrored, so nothing
|
|
2772
|
+
* follows a fault that dropped the run id.
|
|
2773
|
+
*/
|
|
2774
|
+
faults() {
|
|
2775
|
+
const { invalidateAiConfig, strings } = this.config;
|
|
2776
|
+
const store = this.store;
|
|
2777
|
+
return createConversationFaults({
|
|
2778
|
+
copy: {
|
|
2779
|
+
generic: strings.prompt.errorGeneric,
|
|
2780
|
+
missingOrganization: strings.director.errorNoOrganization,
|
|
2781
|
+
noAccess: strings.copilot.errorNoAccess,
|
|
2782
|
+
notConfigured: strings.copilot.errorNotConfigured,
|
|
2783
|
+
notEntitled: strings.copilot.withheld,
|
|
2784
|
+
rateLimited: strings.prompt.errorRateLimited,
|
|
2785
|
+
tooLarge: strings.prompt.errorTooLarge
|
|
2786
|
+
},
|
|
2787
|
+
invalidateAiConfig,
|
|
2788
|
+
writer: {
|
|
2789
|
+
appendError: (message) => store.getState().appendError(message),
|
|
2790
|
+
setRunId: (runId) => store.getState().setRunId(runId),
|
|
2791
|
+
// A fault ends the wait for a turn that will not come, so the state it writes lands as
|
|
2792
|
+
// it is.
|
|
2793
|
+
setSessionState: (state) => {
|
|
2794
|
+
this.awaitingTurn = false;
|
|
2795
|
+
this.writeSessionState(state);
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
};
|
|
2801
|
+
|
|
2802
|
+
// src/agent/rules/agentErrorCopy.ts
|
|
2803
|
+
var agentErrorCopy = (strings) => ({
|
|
2804
|
+
accessRevoked: strings.prompt.errorAccessRevoked,
|
|
2805
|
+
budget: {
|
|
2806
|
+
cost: strings.prompt.budgetCost,
|
|
2807
|
+
generic: strings.prompt.budgetGeneric,
|
|
2808
|
+
turns: strings.prompt.budgetTurns
|
|
2809
|
+
},
|
|
2810
|
+
generic: strings.prompt.errorGeneric,
|
|
2811
|
+
looping: strings.prompt.errorLooping,
|
|
2812
|
+
notConfigured: strings.copilot.errorNotConfigured,
|
|
2813
|
+
rateLimited: strings.prompt.errorRateLimited
|
|
2814
|
+
});
|
|
2815
|
+
|
|
2816
|
+
export { AgentThreadsEngine, DirectorChatEngine, PLAYBOOK, SURFACES, WITHHELD_TAB_ID, agentErrorCopy, copilotOrganizationId, createAgentThreadsStore, recoveryFor, selectAgentDriving, selectSurfaces, surfaceTools };
|
|
2817
|
+
//# sourceMappingURL=index.js.map
|
|
2818
|
+
//# sourceMappingURL=index.js.map
|