@mountaya/studio 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/agent/index.cjs +2561 -2815
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +766 -786
  5. package/dist/agent/index.d.ts +766 -786
  6. package/dist/agent/index.js +2553 -2790
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/chunk-3Oi_Zrtm.js +9 -0
  9. package/dist/chunk-3Oi_Zrtm.js.map +1 -0
  10. package/dist/chunk-B18OPIu_.js +6 -0
  11. package/dist/chunk-B18OPIu_.js.map +1 -0
  12. package/dist/chunk-B5Uz3Qct.cjs +15 -0
  13. package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
  14. package/dist/chunk-BBEJwkd3.d.cts +839 -0
  15. package/dist/chunk-BIEc_SkR.cjs +29 -0
  16. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  17. package/dist/chunk-BKMFOe-N.js +171 -0
  18. package/dist/chunk-BKMFOe-N.js.map +1 -0
  19. package/dist/chunk-BP4uy7E1.d.ts +11583 -0
  20. package/dist/chunk-BSHTsFiB.js +1403 -0
  21. package/dist/chunk-BSHTsFiB.js.map +1 -0
  22. package/dist/chunk-BTUUABGI.js +17 -0
  23. package/dist/chunk-BTUUABGI.js.map +1 -0
  24. package/dist/chunk-BaPiaz5X.cjs +115 -0
  25. package/dist/chunk-BaPiaz5X.cjs.map +1 -0
  26. package/dist/chunk-BeCVpkYr.cjs +542 -0
  27. package/dist/chunk-BeCVpkYr.cjs.map +1 -0
  28. package/dist/chunk-BgngsvK8.cjs +6202 -0
  29. package/dist/chunk-BgngsvK8.cjs.map +1 -0
  30. package/dist/chunk-BhInd7CJ.d.cts +253 -0
  31. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  32. package/dist/chunk-By9ZnkVI.js +60 -0
  33. package/dist/chunk-By9ZnkVI.js.map +1 -0
  34. package/dist/chunk-BzqPhxsz.cjs +367 -0
  35. package/dist/chunk-BzqPhxsz.cjs.map +1 -0
  36. package/dist/chunk-C2mMX81q.d.ts +443 -0
  37. package/dist/chunk-C2rr9Q0V.cjs +1402 -0
  38. package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
  39. package/dist/{directorThreads-CqmvsV8b.d.cts → chunk-CDJCbwIQ.d.cts} +20 -22
  40. package/dist/chunk-CLGvBOVH.d.cts +1654 -0
  41. package/dist/chunk-COdw1dc6.d.ts +525 -0
  42. package/dist/chunk-CQCJnT2i.d.ts +511 -0
  43. package/dist/chunk-CSyHY67q.cjs +353 -0
  44. package/dist/chunk-CSyHY67q.cjs.map +1 -0
  45. package/dist/chunk-CiK1Iqrv.js +950 -0
  46. package/dist/chunk-CiK1Iqrv.js.map +1 -0
  47. package/dist/chunk-CmJBgSwZ.cjs +24 -0
  48. package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
  49. package/dist/chunk-CnrsRK2u.cjs +83 -0
  50. package/dist/chunk-CnrsRK2u.cjs.map +1 -0
  51. package/dist/chunk-Co782_9r.js +326 -0
  52. package/dist/chunk-Co782_9r.js.map +1 -0
  53. package/dist/chunk-Csr3KDpZ.cjs +32 -0
  54. package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
  55. package/dist/chunk-CwkmccXv.js +89 -0
  56. package/dist/chunk-CwkmccXv.js.map +1 -0
  57. package/dist/chunk-D0Q4iL9B.cjs +255 -0
  58. package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
  59. package/dist/chunk-DFwiSzUS.cjs +72 -0
  60. package/dist/chunk-DFwiSzUS.cjs.map +1 -0
  61. package/dist/chunk-DIFayl2P.d.cts +443 -0
  62. package/dist/chunk-DIGF58ux.d.cts +525 -0
  63. package/dist/chunk-DKuuuld5.js +101 -0
  64. package/dist/chunk-DKuuuld5.js.map +1 -0
  65. package/dist/chunk-DMePkFEo.js +5054 -0
  66. package/dist/chunk-DMePkFEo.js.map +1 -0
  67. package/dist/chunk-DO5SIBgu.js +305 -0
  68. package/dist/chunk-DO5SIBgu.js.map +1 -0
  69. package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
  70. package/dist/{tabs-B2nRO4p_.d.ts → chunk-DThaaNeb.d.cts} +2 -2
  71. package/dist/{tabs-B2nRO4p_.d.cts → chunk-DThaaNeb.d.ts} +2 -2
  72. package/dist/{directorThreads-CqmvsV8b.d.ts → chunk-DUQzjUJy.d.ts} +20 -22
  73. package/dist/chunk-DX37IPhV.cjs +1903 -0
  74. package/dist/chunk-DX37IPhV.cjs.map +1 -0
  75. package/dist/chunk-Damps5Tk.cjs +155 -0
  76. package/dist/chunk-Damps5Tk.cjs.map +1 -0
  77. package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
  78. package/dist/chunk-De0vAASv.d.ts +253 -0
  79. package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
  80. package/dist/chunk-DjEvqvPA.cjs +43 -0
  81. package/dist/chunk-DjEvqvPA.cjs.map +1 -0
  82. package/dist/{saveFile-j-1kkApx.d.cts → chunk-DkwDzwvu.d.cts} +7 -9
  83. package/dist/{saveFile-j-1kkApx.d.ts → chunk-DkwDzwvu.d.ts} +7 -9
  84. package/dist/chunk-Dmszv9If.js +71 -0
  85. package/dist/chunk-Dmszv9If.js.map +1 -0
  86. package/dist/chunk-Dp_ftNWY.d.cts +511 -0
  87. package/dist/chunk-DsHQySz0.js +31 -0
  88. package/dist/chunk-DsHQySz0.js.map +1 -0
  89. package/dist/chunk-DwoUyHHh.js +281 -0
  90. package/dist/chunk-DwoUyHHh.js.map +1 -0
  91. package/dist/chunk-IaIDQflj.d.cts +2315 -0
  92. package/dist/chunk-IaIDQflj.d.ts +2315 -0
  93. package/dist/chunk-cVXLsZfL.d.ts +839 -0
  94. package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
  95. package/dist/chunk-nJQxbOwQ.cjs +8962 -0
  96. package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
  97. package/dist/chunk-o9jaxhCO.js +8852 -0
  98. package/dist/chunk-o9jaxhCO.js.map +1 -0
  99. package/dist/chunk-p-Tt_Lwz.js +14 -0
  100. package/dist/chunk-p-Tt_Lwz.js.map +1 -0
  101. package/dist/engines/index.cjs +2046 -3401
  102. package/dist/engines/index.cjs.map +1 -1
  103. package/dist/engines/index.d.cts +1510 -1550
  104. package/dist/engines/index.d.ts +1510 -1550
  105. package/dist/engines/index.js +2039 -3380
  106. package/dist/engines/index.js.map +1 -1
  107. package/dist/handlers/index.cjs +47 -93
  108. package/dist/handlers/index.cjs.map +1 -1
  109. package/dist/handlers/index.d.cts +61 -103
  110. package/dist/handlers/index.d.ts +61 -103
  111. package/dist/handlers/index.js +27 -36
  112. package/dist/handlers/index.js.map +1 -1
  113. package/dist/index.cjs +3347 -4398
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.cts +8 -7297
  116. package/dist/index.d.ts +8 -7297
  117. package/dist/index.js +2997 -3187
  118. package/dist/index.js.map +1 -1
  119. package/dist/plugins/index.cjs +482 -949
  120. package/dist/plugins/index.cjs.map +1 -1
  121. package/dist/plugins/index.d.cts +44 -61
  122. package/dist/plugins/index.d.ts +44 -61
  123. package/dist/plugins/index.js +471 -915
  124. package/dist/plugins/index.js.map +1 -1
  125. package/dist/seams/index.cjs +77 -140
  126. package/dist/seams/index.cjs.map +1 -1
  127. package/dist/seams/index.d.cts +125 -158
  128. package/dist/seams/index.d.ts +125 -158
  129. package/dist/seams/index.js +41 -71
  130. package/dist/seams/index.js.map +1 -1
  131. package/dist/strings/fr/index.cjs +2130 -2116
  132. package/dist/strings/fr/index.cjs.map +1 -1
  133. package/dist/strings/fr/index.d.cts +3 -5
  134. package/dist/strings/fr/index.d.ts +3 -5
  135. package/dist/strings/fr/index.js +2125 -2114
  136. package/dist/strings/fr/index.js.map +1 -1
  137. package/dist/strings/index.cjs +2331 -2625
  138. package/dist/strings/index.cjs.map +1 -1
  139. package/dist/strings/index.d.cts +3 -731
  140. package/dist/strings/index.d.ts +3 -731
  141. package/dist/strings/index.js +2324 -2615
  142. package/dist/strings/index.js.map +1 -1
  143. package/dist/testing/index.cjs +214 -276
  144. package/dist/testing/index.cjs.map +1 -1
  145. package/dist/testing/index.d.cts +61 -121
  146. package/dist/testing/index.d.ts +61 -121
  147. package/dist/testing/index.js +208 -273
  148. package/dist/testing/index.js.map +1 -1
  149. package/dist/time/index.cjs +23 -23
  150. package/dist/time/index.cjs.map +1 -1
  151. package/dist/time/index.d.cts +5 -7
  152. package/dist/time/index.d.ts +5 -7
  153. package/dist/time/index.js +18 -21
  154. package/dist/time/index.js.map +1 -1
  155. package/package.json +14 -15
  156. package/src/agent/rules/stateDelta.ts +1 -0
  157. package/src/agent/stores/agentThreads.ts +1 -4
  158. package/src/bus/rules/bus.ts +1 -2
  159. package/src/bus/rules/defineRegistry.ts +3 -5
  160. package/src/bus/rules/types.ts +6 -7
  161. package/src/chrome/stores/uiStore.ts +4 -2
  162. package/src/embed/rules/fieldDependencies.ts +2 -0
  163. package/src/embed/rules/safetyRules.ts +2 -0
  164. package/src/embed/rules/tableCode.ts +4 -3
  165. package/src/index.ts +6 -27
  166. package/src/itinerary/rules/import.ts +6 -8
  167. package/src/plugins/contracts/plugin.ts +4 -2
  168. package/src/seams/rules/formatters.ts +5 -3
  169. package/src/testing/index.ts +1 -5
  170. package/src/viewer/rules/platformViewer.ts +1 -0
  171. package/dist/bus-BwiNiXdH.d.ts +0 -514
  172. package/dist/bus-DzmhPwdK.d.cts +0 -514
  173. package/dist/chainModel-B23pEP_1.d.cts +0 -127
  174. package/dist/chainModel-B23pEP_1.d.ts +0 -127
  175. package/dist/chunk-2HFY7ETU.js +0 -5721
  176. package/dist/chunk-2HFY7ETU.js.map +0 -1
  177. package/dist/chunk-355TOXSB.js +0 -72
  178. package/dist/chunk-355TOXSB.js.map +0 -1
  179. package/dist/chunk-4ZCUZVSV.js +0 -10275
  180. package/dist/chunk-4ZCUZVSV.js.map +0 -1
  181. package/dist/chunk-6HEKY3NF.js +0 -95
  182. package/dist/chunk-6HEKY3NF.js.map +0 -1
  183. package/dist/chunk-7GFLGGBX.cjs +0 -8
  184. package/dist/chunk-7GFLGGBX.cjs.map +0 -1
  185. package/dist/chunk-7NBRCENN.cjs +0 -19
  186. package/dist/chunk-7NBRCENN.cjs.map +0 -1
  187. package/dist/chunk-AF5GCXE3.js +0 -8
  188. package/dist/chunk-AF5GCXE3.js.map +0 -1
  189. package/dist/chunk-CJDIFRGZ.cjs +0 -2005
  190. package/dist/chunk-CJDIFRGZ.cjs.map +0 -1
  191. package/dist/chunk-CNPZY7N3.js +0 -349
  192. package/dist/chunk-CNPZY7N3.js.map +0 -1
  193. package/dist/chunk-DZJHTWSF.cjs +0 -45
  194. package/dist/chunk-DZJHTWSF.cjs.map +0 -1
  195. package/dist/chunk-EABIHHWA.js +0 -42
  196. package/dist/chunk-EABIHHWA.js.map +0 -1
  197. package/dist/chunk-EKZWV6RS.cjs +0 -415
  198. package/dist/chunk-EKZWV6RS.cjs.map +0 -1
  199. package/dist/chunk-EOKRXXAC.cjs +0 -24
  200. package/dist/chunk-EOKRXXAC.cjs.map +0 -1
  201. package/dist/chunk-F73W2ZTJ.js +0 -1126
  202. package/dist/chunk-F73W2ZTJ.js.map +0 -1
  203. package/dist/chunk-H4DVOZ5O.js +0 -1897
  204. package/dist/chunk-H4DVOZ5O.js.map +0 -1
  205. package/dist/chunk-HI52PBFT.cjs +0 -10314
  206. package/dist/chunk-HI52PBFT.cjs.map +0 -1
  207. package/dist/chunk-IDBXFBLG.cjs +0 -1225
  208. package/dist/chunk-IDBXFBLG.cjs.map +0 -1
  209. package/dist/chunk-LBWTJZUJ.js +0 -297
  210. package/dist/chunk-LBWTJZUJ.js.map +0 -1
  211. package/dist/chunk-NCLA6DKD.cjs +0 -310
  212. package/dist/chunk-NCLA6DKD.cjs.map +0 -1
  213. package/dist/chunk-O4MC5DPD.js +0 -19
  214. package/dist/chunk-O4MC5DPD.js.map +0 -1
  215. package/dist/chunk-OP37FKW6.cjs +0 -98
  216. package/dist/chunk-OP37FKW6.cjs.map +0 -1
  217. package/dist/chunk-OQSYFH3Z.cjs +0 -5945
  218. package/dist/chunk-OQSYFH3Z.cjs.map +0 -1
  219. package/dist/chunk-PACIO4NS.cjs +0 -26
  220. package/dist/chunk-PACIO4NS.cjs.map +0 -1
  221. package/dist/chunk-PSZ2R3TC.cjs +0 -75
  222. package/dist/chunk-PSZ2R3TC.cjs.map +0 -1
  223. package/dist/chunk-QFO5CZG2.cjs +0 -136
  224. package/dist/chunk-QFO5CZG2.cjs.map +0 -1
  225. package/dist/chunk-QL63MUEW.cjs +0 -140
  226. package/dist/chunk-QL63MUEW.cjs.map +0 -1
  227. package/dist/chunk-RFUPPVZO.js +0 -17
  228. package/dist/chunk-RFUPPVZO.js.map +0 -1
  229. package/dist/chunk-RPG2LWMP.js +0 -23
  230. package/dist/chunk-RPG2LWMP.js.map +0 -1
  231. package/dist/chunk-TIBXK6B7.cjs +0 -12
  232. package/dist/chunk-TIBXK6B7.cjs.map +0 -1
  233. package/dist/chunk-UU65VNEV.js +0 -381
  234. package/dist/chunk-UU65VNEV.js.map +0 -1
  235. package/dist/chunk-VGX6TR2I.js +0 -209
  236. package/dist/chunk-VGX6TR2I.js.map +0 -1
  237. package/dist/chunk-WUTDDBVP.js +0 -130
  238. package/dist/chunk-WUTDDBVP.js.map +0 -1
  239. package/dist/chunk-WVQQLKCI.cjs +0 -224
  240. package/dist/chunk-WVQQLKCI.cjs.map +0 -1
  241. package/dist/chunk-WZYXG3SE.js +0 -111
  242. package/dist/chunk-WZYXG3SE.js.map +0 -1
  243. package/dist/chunk-XDI2X3KE.js +0 -6
  244. package/dist/chunk-XDI2X3KE.js.map +0 -1
  245. package/dist/chunk-XKHLRIC7.cjs +0 -381
  246. package/dist/chunk-XKHLRIC7.cjs.map +0 -1
  247. package/dist/context-DNtd2WUv.d.cts +0 -11666
  248. package/dist/context-DgB72Bur.d.ts +0 -11666
  249. package/dist/en-Bu4Ti9Ev.d.cts +0 -2315
  250. package/dist/en-Bu4Ti9Ev.d.ts +0 -2315
  251. package/dist/shareLink-B6hlt942.d.ts +0 -144
  252. package/dist/shareLink-C7rIMb7x.d.ts +0 -527
  253. package/dist/shareLink-CnTxxXjp.d.cts +0 -144
  254. package/dist/shareLink-DyZVYH2V.d.cts +0 -527
  255. package/dist/studioPlugin-C3C7VjMy.d.ts +0 -847
  256. package/dist/studioPlugin-Cf3OBNUv.d.cts +0 -847
  257. package/dist/types-BzJRV6UI.d.cts +0 -845
  258. package/dist/types-BzJRV6UI.d.ts +0 -845
  259. package/dist/zoneForm-CdYNtnnA.d.cts +0 -320
  260. package/dist/zoneForm-mG85yt5e.d.ts +0 -320
@@ -0,0 +1,511 @@
1
+ import { Ht as ToolBusContext, Kt as ToolDispatchRegistry, Ut as ToolBusDispatch, Vt as Tool, Wt as ToolCapability, Xt as ToolResult, Yt as ToolOutputRegistry, Zt as ToolResultOf, qt as ToolErrorCode, zt as StudioToolManifestEntry } from "./chunk-CLGvBOVH.cjs";
2
+ /**
3
+ * Turning a thrown value into the structured failure a handler returns.
4
+ *
5
+ * The wire half of this is universal: every Mountaya API failure arrives as a
6
+ * `MountayaApiError` carrying an HTTP status and a localized envelope, and the mapping from its
7
+ * status, and from what its envelope names (a lock holder, a ceiling), to {@link ToolErrorCode}
8
+ * is the same for every consumer. The application half is not: a host throws its own domain
9
+ * errors, and only it knows what they mean. So the universal half ships here and the
10
+ * application half arrives as {@link ThrownRecognizer}s.
11
+ *
12
+ * This module deliberately does not import `@mountaya/client`: matching on the error's SHAPE
13
+ * rather than on a class keeps the package's "no client code in the bundle" rule intact, and
14
+ * it means a consumer whose client is a different copy of the package (a duplicated install,
15
+ * a monorepo link) still gets its errors classified. An `instanceof` across two copies
16
+ * silently returns false, which would degrade every wire failure to "internal".
17
+ */
18
+ /**
19
+ * restStatusCodes maps the HTTP statuses an API error carries to the {@link ToolResult}
20
+ * error code a consumer branches on. Only the statuses with a real consumer are mapped; any
21
+ * other status (and any non-envelope throw) resolves to the "internal" catch-all via
22
+ * {@link codeForThrown} returning undefined.
23
+ *
24
+ * A 400 is the API REFUSING the request on its own rules: a split too close to an endpoint,
25
+ * a geometry the router cannot follow. That is an input problem the user can act on, so it
26
+ * maps to "invalid-input" rather than falling through to "internal", which would read as a
27
+ * bug in the application.
28
+ *
29
+ * A 402 is a product the agreement does not include and maps to "upgrade-required", and a 429 is
30
+ * a rate limit spent and maps to "rate-limited". The 429 is the fallback for its status: a
31
+ * refusal of a ceiling is a 429 too, and names itself by its entry's code, which
32
+ * {@link codeForThrown} reads before this table.
33
+ *
34
+ * A 412 is a write made conditional on a version the resource has since moved past: the same
35
+ * recovery as a lost revision, so it maps to "conflict" with it, and the caller reads the
36
+ * resource again before it writes.
37
+ *
38
+ * A 504 is the API abandoning a request that outlived its budget. It maps to "timeout" rather
39
+ * than "internal" so a surface can answer it with what would make the work smaller, which is
40
+ * the only thing that helps: a plain retry re-runs the same request into the same budget. 502
41
+ * and 503 fall through: those are a dependency being down, where retrying IS the answer.
42
+ */
43
+ declare const restStatusCodes: Readonly<Record<number, ToolErrorCode>>;
44
+ /**
45
+ * ThrownRecognizer classifies a thrown value a host knows about and this package does not:
46
+ * its own domain errors. It returns undefined for anything it does not recognise, so
47
+ * recognizers compose: each is asked in turn and the first answer wins.
48
+ */
49
+ type ThrownRecognizer = (error: unknown) => ToolErrorCode | undefined;
50
+ /**
51
+ * codeForThrown classifies a thrown value into the machine-readable {@link ToolErrorCode} a
52
+ * consumer branches on, or undefined when the throw is unclassified (the caller then falls
53
+ * back to "internal").
54
+ *
55
+ * Total: it never throws, whatever was thrown and whatever a recognizer does. A member of the
56
+ * thrown value that cannot be read reads as absent, and a recognizer that throws leaves the
57
+ * status table to classify the throw, with no recognizer after it asked.
58
+ *
59
+ * Host recognizers are asked FIRST, and deliberately: a host's domain error is more specific
60
+ * than the status it happens to travel with, so a revision conflict that arrives as a 409
61
+ * should be classified by the host that knows it is a revision conflict rather than by the
62
+ * generic status table.
63
+ *
64
+ * A 409 whose error carries `metadata.holder.id`, a non-empty string naming the member who holds
65
+ * the entity's edit lock (the contract's `ResponseMetadataLockConflict`), answers
66
+ * `"collab-locked"`, the code a lock-aware edit already answers when it finds the lock held
67
+ * locally, so a host's `collab-locked` branch receives the server's lock refusals too.
68
+ * `"conflict"` is any other 409: a stale revision, a name another resource already carries, or
69
+ * one of the two answering the request's `Idempotency-Key`, which {@link failureFromThrown} tags
70
+ * so a surface never reads a write being saved, or saved, as either of the others.
71
+ *
72
+ * A refusal of a ceiling answers `"limit-reached"`, read off what the API answers and never off
73
+ * where it answers it:
74
+ *
75
+ * - an entry carrying the code `LIMIT_REACHED`, read before the status: the seats, the published
76
+ * itineraries or the published zones an agreement allows, the itineraries a personal space
77
+ * keeps and the invitations an organization may hold waiting, each a 429 naming no wait;
78
+ * - a 429 whose `retryAfter` is longer than a minute: a daily bound or a monthly allowance spent,
79
+ * which names when it lifts. A 429 not coded `LIMIT_REACHED` naming no wait, or a wait of a
80
+ * minute or less, is a rate, `"rate-limited"`, which a moment's wait clears: a per-minute quota,
81
+ * a proxy's short 429, or the last minute of a billing period.
82
+ *
83
+ * So a 402 stays `"upgrade-required"`, a product the organization's agreement does not include,
84
+ * and a 403 `"forbidden"`.
85
+ */
86
+ declare const codeForThrown: (error: unknown, recognizers?: readonly ThrownRecognizer[]) => ToolErrorCode | undefined;
87
+ /**
88
+ * failureFromThrown builds the structured {@link ToolResult} a handler (or the bus catch
89
+ * boundary) returns for a thrown value: the classified code when {@link codeForThrown}
90
+ * recognises the throw, "internal" otherwise, and the thrown Error's message (or its String
91
+ * form) as the human-readable error. It is the single seam that turns a throw into the
92
+ * documented "handlers never throw" structured result, so the catch path and a handler's own
93
+ * fallback produce one shape.
94
+ *
95
+ * Total: it never throws, and `error` is always a string. A message that cannot be read or
96
+ * printed reads `a value that cannot be printed`, and a message of another type is printed.
97
+ *
98
+ * `detail` is the sentence the throw carries for a reader: a domain error's own `detail`,
99
+ * otherwise an API envelope's FIRST entry, and undefined where neither is a string. The API
100
+ * already resolved that sentence into the viewer's language and it names the actual refusal,
101
+ * which no client-side per-code copy can reproduce. `error` is the technical string analytics
102
+ * and an agent read, except for a lock refusal: classified `"collab-locked"` with a holder named
103
+ * at `metadata.holder.id`, it is `collab-locked: <holderId>`, the tagged form a lock-aware edit
104
+ * returns, so a host resolves the holder's name the same way whichever side refused. The two
105
+ * 409s answering the request's `Idempotency-Key` are `conflict`s whose `error` opens with
106
+ * {@link WRITE_STILL_RUNNING} or {@link WRITE_MADE}, so a surface tells a write that is being
107
+ * saved, or was, from a name another resource carries, and never asks for it again; the 412 of a
108
+ * conditional write opens with {@link VERSION_MOVED}, so it reads as a change since the reader
109
+ * opened the resource and never as a taken name.
110
+ */
111
+ declare const failureFromThrown: (error: unknown, recognizers?: readonly ThrownRecognizer[]) => Extract<ToolResult, {
112
+ ok: false;
113
+ }>;
114
+ /**
115
+ * ToolBusOptions carry what a host knows and this package cannot.
116
+ *
117
+ * `playbook` is the model-facing catalogue: a description written for whoever is CHOOSING a
118
+ * tool rather than for whoever registered it, plus whether the tool only reads. A host may
119
+ * have none, in which case every tool keeps its inline description and is treated as
120
+ * mutating: the only safe default, since dropping a mutation's record would let a model
121
+ * believe a change it made never happened.
122
+ *
123
+ * `recognizers` classify the host's own domain throws before the generic status table sees
124
+ * them. See {@link ThrownRecognizer}.
125
+ *
126
+ * `reserved` names the vendor segments whose tools {@link ToolBus.unregister} will not take
127
+ * back. See there for what it is and is not for.
128
+ */
129
+ interface ToolBusOptions {
130
+ readonly playbook?: readonly {
131
+ readonly description: string;
132
+ readonly id: string;
133
+ readonly kind?: string | undefined;
134
+ }[] | undefined;
135
+ readonly recognizers?: readonly ThrownRecognizer[] | undefined;
136
+ /**
137
+ * The FIRST dot-separated segments a name must not have, to be unregistered.
138
+ *
139
+ * Data rather than a rule this file knows, which is what keeps the bus ignorant of the
140
+ * plugin vocabulary that gives it meaning: `createStudioToolBus` passes
141
+ * `RESERVED_PLUGIN_NAMESPACES`, a host with their own namespace passes theirs, and a bus with
142
+ * no plugins passes nothing.
143
+ *
144
+ * @default undefined, and {@link ToolBus.unregister} takes back any name
145
+ */
146
+ readonly reserved?: readonly string[] | undefined;
147
+ }
148
+ /**
149
+ * ToolDispatchEvent is the structured readout the bus emits after every dispatch: the tool's
150
+ * name and capability, the wall-clock latency, and the outcome (success or a coarse-grained
151
+ * errorClass keyed off the bus's own failure branches). Observers turn this into per-tool
152
+ * latency and error metrics with no instrumentation inside the handlers themselves.
153
+ *
154
+ * errorClass is the coarse bucket the bus's own branches produce; errorCode is
155
+ * the FINE, machine-readable {@link ToolErrorCode} the failing result carried
156
+ * (or the gate's own code), so an observer can distinguish, say, a lost-revision
157
+ * `conflict` from any other `handler-error`. It is undefined on a success and on
158
+ * an unclassified failure that omitted a code.
159
+ *
160
+ * errorMessage is the failing result's human-readable error string (or the
161
+ * gate's own message), carried alongside errorCode so an observer can read the
162
+ * detail a code alone cannot express: the collab-lock refusal encodes the peer
163
+ * holder id in it, which the conflict/lock observer resolves to a name. It is
164
+ * undefined on a success, mirroring errorCode.
165
+ *
166
+ * errorClass, every member in kebab-case, the spelling the error codes take:
167
+ * - "unknown-tool": the dispatched name is not registered.
168
+ * - "capability-denied": the context lacks the tool's capability gate.
169
+ * - "agent-hidden": the MODEL named a tool withheld from its manifest. Its own
170
+ * bucket rather than a capability failure, because the context does hold the
171
+ * capability: this is a model reaching for a verb it was never offered, which is
172
+ * a distinct signal worth seeing on its own.
173
+ * - "invalid-input": Zod rejected the raw input at the boundary.
174
+ * - "confirmation-denied": ctx.confirm rejected or was absent for a destructive tool.
175
+ * - "handler-error": the tool's precondition or its handler returned { ok: false, error }, or
176
+ * threw.
177
+ */
178
+ interface ToolDispatchEvent {
179
+ capability?: ToolCapability | undefined;
180
+ errorClass?: "unknown-tool" | "capability-denied" | "agent-hidden" | "invalid-input" | "confirmation-denied" | "handler-error" | undefined;
181
+ errorCode?: ToolErrorCode | undefined;
182
+ errorMessage?: string | undefined;
183
+ latencyMs: number;
184
+ name: string;
185
+ ok: boolean;
186
+ }
187
+ /**
188
+ * ToolDispatchObserver receives one ToolDispatchEvent per completed dispatch.
189
+ * Observers run synchronously after the result is built, in registration order.
190
+ *
191
+ * One that throws changes no dispatch and stops no observer after it, so a telemetry
192
+ * sink never breaks a tool. Its fault is not dropped either: the first of a round
193
+ * reaches the program as an uncaught error on a microtask, by the rule
194
+ * `rules/listeners.ts` states for every fan-out of this package.
195
+ */
196
+ type ToolDispatchObserver = (event: ToolDispatchEvent) => void;
197
+ /**
198
+ * ToolBusObserve is the OBSERVATION half of a bus, declared apart from {@link ToolBusDispatch}
199
+ * for the same reason that one is declared apart from the bus itself: a host may implement one
200
+ * and not the other.
201
+ *
202
+ * A bus this package builds carries both. A host that hands a surface a hand-written dispatch
203
+ * slice (a bridge, a scripted double, a print view) carries only the first, which is why
204
+ * every consumer of this one treats it as optional and answers "nothing observed" rather than
205
+ * throwing. That is a real answer: an observer reports on dispatches, so having none loses a
206
+ * report and never loses an action.
207
+ *
208
+ * `observe` returns its own detach function, so a caller's cleanup is the return value rather
209
+ * than a second call it has to spell.
210
+ */
211
+ interface ToolBusObserve {
212
+ observe(observer: ToolDispatchObserver): () => void;
213
+ }
214
+ /**
215
+ * ToolBusObserveOverrides is the observation half of a bus as a host may hand it: present, left
216
+ * out, or written as `undefined`.
217
+ *
218
+ * It is what a surface takes beside {@link ToolBusDispatch} when the host's bus may be a
219
+ * hand-written dispatch slice (a bridge, a scripted double, a print view), which carries no
220
+ * `observe`. A bus this package builds satisfies it, and so does the bare slice. A surface that
221
+ * reads it answers "nothing observed" where the member is absent, for the reason
222
+ * {@link ToolBusObserve} gives.
223
+ *
224
+ * The member states `undefined`, so a host forwarding an `observe` it may not hold
225
+ * (`{ ...slice, observe: telemetry?.observe }`) compiles under `exactOptionalPropertyTypes`,
226
+ * which `Partial<ToolBusObserve>` refuses.
227
+ */
228
+ interface ToolBusObserveOverrides {
229
+ /**
230
+ * Registers a per-dispatch observer and returns its detach function, as
231
+ * {@link ToolBusObserve.observe} does.
232
+ *
233
+ * @default undefined, and nothing is observed
234
+ */
235
+ readonly observe?: ((observer: ToolDispatchObserver) => () => void) | undefined;
236
+ }
237
+ /**
238
+ * ToolBus is the single mutation surface for both humans (via component event
239
+ * handlers) and the agent. It registers tools, exposes a capability-filtered
240
+ * manifest, validates input with Zod, and dispatches to the handler, returning
241
+ * a structured result. Store layout is an implementation detail behind it.
242
+ *
243
+ * The `TInputs` parameter maps each tool name to its pre-parse input shape, so a
244
+ * caller that knows the bus's full tool set gets a name-checked, input-checked
245
+ * `dispatch`. Its default is {@link ToolDispatchRegistry}, which is empty until a
246
+ * host augments it, so the typed `dispatch` of a bus that is neither specialized
247
+ * nor augmented takes no name at all: such a bus dispatches through
248
+ * {@link ToolBus.dispatchUnsafe}, which takes any name and validates as fully.
249
+ * Specialize it through the constructor's type arguments (`StudioToolInputs` for the studio's
250
+ * own verbs) when the tool set is known at the call boundary, and with
251
+ * `Record<string, unknown>` for a `dispatch` that takes a free-form name and an
252
+ * unknown input.
253
+ *
254
+ * It implements {@link ToolBusDispatch} for its own `TInputs`, so the structural
255
+ * dispatch seam a handler reaches through ctx.bus is satisfied by the same typed
256
+ * `dispatch` the class exposes: a {@link ToolBus}<StudioToolInputs> is assignable
257
+ * to the default ctx.bus because both key the raw input off the same `TInputs`
258
+ * indexed access.
259
+ *
260
+ * The `TOutputs` parameter maps each tool name to the `data` its answer holds, and
261
+ * the typed `dispatch` answers the {@link ToolResult} of the named verb's data. Its
262
+ * default is {@link ToolOutputRegistry}, empty until a host augments it, where every
263
+ * answer's data is `unknown`. Name it beside `TInputs` for a bus whose instance is
264
+ * handed to a slot that states its outputs, a studio context's `bus` among them.
265
+ *
266
+ * observe() registers a per-dispatch telemetry observer (latency, outcome and coarse error
267
+ * class). Every dispatch builds its event, and each observer held is told of it.
268
+ *
269
+ * The options carry what this package cannot know: the model-facing playbook, the host's own
270
+ * throw recognizers and the reserved vendor segments. All are optional: a bus built with none
271
+ * still validates, gates, confirms and dispatches, it simply describes tools with their inline
272
+ * strings and classifies only what the API envelope can tell it. A host driving the studio's own
273
+ * verbs builds its bus with `createStudioToolBus` of `@mountaya/studio/handlers`, which states
274
+ * the studio's recognizers and reserved namespaces for it and takes the playbook as an option.
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * interface RouteToolContext extends ToolBusContext {
279
+ * readonly routeId: string;
280
+ * }
281
+ *
282
+ * const bus = new ToolBus<RouteToolContext>({ reserved: ["acme"] });
283
+ * ```
284
+ */
285
+ declare class ToolBus<TCtx extends ToolBusContext, TInputs extends object = ToolDispatchRegistry, TOutputs extends object = ToolOutputRegistry> implements ToolBusDispatch<TCtx, TInputs, TOutputs> {
286
+ private readonly observers;
287
+ private readonly tools;
288
+ /** The model-facing description per tool name, empty when the host supplied no playbook. */
289
+ private readonly descriptions;
290
+ /** The tools a playbook classifies as reads. Absent means "may mutate", the safe default. */
291
+ private readonly readOnly;
292
+ /** The host's own throw classifiers, asked before the generic status table. */
293
+ private readonly recognizers;
294
+ /** The vendor segments whose names {@link unregister} refuses to take back. */
295
+ private readonly reserved;
296
+ /**
297
+ * dispatcher is this bus AS the dispatch surface: two methods, and nothing else on the object.
298
+ *
299
+ * A context's `bus` is typed {@link ToolBusDispatch}, and handing it the whole class would
300
+ * make that narrowing a claim the runtime does not keep. The gap is only visible to code that
301
+ * does not go through the types (a tool written in plain JavaScript, a handler that cast), and
302
+ * those are exactly the callers a narrowed type protects the bus from. Registering,
303
+ * unregistering and observing are the OWNER's verbs; a handler chaining into another verb
304
+ * needs `dispatch` and nothing more, so it is given nothing more.
305
+ *
306
+ * Reaching for one of the others through here is a `TypeError` at the call site rather than a
307
+ * silent success, which is the difference that matters: a plugin that took a tool off the bus
308
+ * would break the studio for the rest of the session with nothing anywhere saying why.
309
+ *
310
+ * One object per bus, built at construction, so the identity a context carries is stable for
311
+ * the bus's life and a memo keyed on `ctx.bus` never churns.
312
+ */
313
+ readonly dispatcher: ToolBusDispatch<TCtx, TInputs, TOutputs>;
314
+ constructor(options?: ToolBusOptions);
315
+ /**
316
+ * register adds a tool to the bus. A destructive tool's confirmation policy is parsed against
317
+ * toolConfirmationSchema at registration time, so an invalid policy (a typo, a structural
318
+ * drift) fails at app startup, not at the first dispatch.
319
+ *
320
+ * @throws MountayaElementsError when the bus holds a tool under the name already: a name is
321
+ * the stable public API, so a replacement is never silent. The message says how to replace
322
+ * it: through {@link ToolBus.unregister} first, or, under a `reserved` segment that
323
+ * unregister keeps, through the handlers the bus is built with.
324
+ * @throws MountayaElementsError when a destructive tool's confirmation policy fails
325
+ * toolConfirmationSchema, with the schema's own message.
326
+ */
327
+ register(tool: Tool<TCtx>): void;
328
+ /**
329
+ * registerAll adds every tool in a registry, in the registry's own key order.
330
+ *
331
+ * A registry (from `defineRegistry`, from `studioRegistry`, or hand-written) is the unit
332
+ * tools arrive in, so registering one is one call rather than a loop every consumer writes
333
+ * identically. The values are what is registered; the keys are pinned to each tool's `name`
334
+ * at the type level by whichever builder produced the record, and are not re-read here.
335
+ *
336
+ * Not atomic, deliberately. `register` throws on a duplicate name, and a partial registry on
337
+ * a thrown bus is the correct outcome: registration happens once at startup, the throw is
338
+ * fatal there, and unwinding would only hide which tool collided behind a bus that looks
339
+ * empty.
340
+ *
341
+ * @throws MountayaElementsError when a tool's name is held already, as {@link register} states.
342
+ */
343
+ registerAll(registry: Readonly<Record<string, Tool<TCtx>>>): void;
344
+ /**
345
+ * registered returns every tool currently in the bus, in registration order.
346
+ * Read-only access so a suite can assert structural properties (Zod schema present,
347
+ * capability canonical, no name collision, confirmation policy on destructive tools)
348
+ * without reaching into the private registry. The returned array is a fresh copy;
349
+ * mutating it does not affect the bus.
350
+ */
351
+ registered(): readonly Tool<TCtx>[];
352
+ /**
353
+ * unregister removes a tool by name, reporting whether one was there.
354
+ *
355
+ * It REPORTS rather than throws, which is the opposite of {@link register} and is the
356
+ * opposite case: removing a name nobody holds leaves the bus in exactly the state the caller
357
+ * asked for, while registering a name somebody already holds cannot leave it in the state
358
+ * BOTH callers asked for. A boolean is what a caller doing bookkeeping wants and what a
359
+ * caller cleaning up can ignore.
360
+ *
361
+ * It exists for the tools a PLUGIN declares, which arrive and leave with the plugin:
362
+ * `@mountaya/studio/plugins` registers them on install and takes them back on uninstall.
363
+ * Without it an uninstalled plugin's verbs would stay in the model's manifest for the rest of
364
+ * the session, and re-installing the same plugin would throw on its own names.
365
+ *
366
+ * There is nothing to invalidate: `manifest()` is rebuilt per call from this map, so the
367
+ * next one already omits the name. A dispatch to it answers `unknown-tool`, which is what a
368
+ * name that was never registered answers.
369
+ *
370
+ * **It refuses a name under a RESERVED vendor segment**, which the host names at construction:
371
+ * the studio passes the segments `plugins/contracts/ids` refuses a plugin id for.
372
+ *
373
+ * It is the SECOND of two answers, and the smaller one. The first is {@link dispatcher}: a
374
+ * context's `bus` carries the dispatch surface alone, so code reached through one (a plugin's
375
+ * `run`, a chained handler) cannot name this method at all, in TypeScript or out of it. What
376
+ * is left holding a concrete bus is its owner: the host that built it, and anything they hand
377
+ * it to. This is for THEM, and it is the ordinary mistake it catches (a cleanup unregistering
378
+ * the wrong name, a line copy-pasted out of a teardown) which would otherwise leave the studio
379
+ * silently unable to save for the rest of the session.
380
+ *
381
+ * Neither is a sandbox, and neither is trying to be. A plugin runs in the host's own realm: it
382
+ * can write the store and dispatch every verb whatever these two do. The boundary that matters
383
+ * is still the host's decision to install it; what these buy is that an ACCIDENT fails loudly
384
+ * and at the call site instead of quietly and hours later.
385
+ *
386
+ * A vendor RULE rather than a list of protected names, for the reason `ids.ts` is one: a list
387
+ * is right the day it is written and wrong the day the next tool ships. It is also why the
388
+ * guard is total where a playbook-derived one would not be: a playbook describes the tools a
389
+ * model chooses between, which is a subset of the tools a studio registers.
390
+ *
391
+ * It costs a HOST nothing: it exists for a plugin's uninstall, and a host disabling one of the
392
+ * studio's own features does it through `capabilities` or the studio's config rather than by
393
+ * editing the bus.
394
+ *
395
+ * @returns true when a tool was registered under `name` and is removed; false when none was,
396
+ * or when `name` sits under a reserved segment and is kept.
397
+ */
398
+ unregister(name: string): boolean;
399
+ /**
400
+ * observe registers a telemetry observer that receives one event per
401
+ * dispatch (start to result). Returns an unobserve fn that detaches it.
402
+ *
403
+ * An observer that throws is answered as {@link ToolDispatchObserver} states. The
404
+ * observers held when a dispatch reports are the ones told: one that joins or
405
+ * detaches while being told changes that round for nobody. One that mutates the
406
+ * bus from inside the callback is on its own.
407
+ */
408
+ observe(observer: ToolDispatchObserver): () => void;
409
+ private emit;
410
+ /**
411
+ * refuseInput answers an `invalid-input` refusal with `error` as its narration, and reports
412
+ * it to the observers first. One path for a schema that failed the input and one that threw
413
+ * while reading it, so both read the same to a caller and to telemetry.
414
+ */
415
+ private refuseInput;
416
+ /**
417
+ * manifest returns the tools available for the given capability set, with
418
+ * each input schema rendered as JSON Schema for the LLM. A tool marked
419
+ * {@link Tool.agentHidden} is withheld here even when its capability is
420
+ * granted: the model never sees a verb the system prompt forbids it to call
421
+ * (an edit-session lifecycle verb, a step of a UI chain), while the
422
+ * same tool stays fully dispatchable for a human click or an internal tool
423
+ * chain. Withholding it here is paired with {@link ToolBus.dispatchFromModel},
424
+ * which refuses the same set, so a name the model invents is not merely
425
+ * unlisted, it does not run. Each schema is rendered through
426
+ * {@link renderInputSchema}, which also drops the keywords the model cannot act
427
+ * on.
428
+ *
429
+ * `surface` narrows the result to a routed subset of tool names. It is
430
+ * advisory over what the model can SEE and is never a gate: a tool left out of
431
+ * the surface stays fully dispatchable by a human click and by an internal
432
+ * tool chain, exactly as `agentHidden` behaves. Omitting it yields every
433
+ * permitted tool, which is what a caller with no router does.
434
+ */
435
+ manifest(capabilities: ReadonlySet<ToolCapability>, surface?: ReadonlySet<string>): StudioToolManifestEntry[];
436
+ /**
437
+ * dispatchUnsafe answers the first refusal in a fixed order and runs the
438
+ * handler only past all of them: a name no tool is registered under, a
439
+ * capability the context lacks, a raw input (e.g. LLM tool-call args) the
440
+ * tool's Zod schema rejects, a refusal the tool's own {@link Tool.precondition}
441
+ * gives, and, when the tool is marked
442
+ * requiresConfirmation, a ctx.confirm that is declined, absent or failed.
443
+ * The bus owns this gate for both human clicks and agent-issued tools; if a
444
+ * destructive tool reaches dispatch with no confirm callback in context, it
445
+ * is denied (fail-safe). Never trusts unvalidated input.
446
+ *
447
+ * It always resolves to a structured ToolResult and never rejects: each gate
448
+ * returns a failure carrying its machine-readable code (unknown-tool,
449
+ * capability-denied, invalid-input, confirmation-denied), and a handler that
450
+ * throws is converted to a structured failure (its classified code, or
451
+ * "internal") rather than re-thrown. A schema that throws while parsing answers
452
+ * invalid-input, since the tool refused the input it was given, and a confirm
453
+ * gate that throws answers confirmation-denied, since a question left unanswered
454
+ * is not consent. Describing a failure never rejects either:
455
+ * {@link failureFromThrown} and {@link describeInvalidInput} are total, so a
456
+ * message that cannot be read or printed gives way to a plainer sentence and a
457
+ * symbol in an issue path is printed. This is what makes the documented
458
+ * "handlers never throw" contract true at the boundary: a caller awaiting a
459
+ * dispatch branches on `ok` instead of wrapping the call in try/catch.
460
+ *
461
+ * "Unsafe" is a TYPE qualifier only: full runtime validation still applies (an
462
+ * unregistered name and a schema-rejected input both fail here, structured).
463
+ * It is the path for a dynamically-named dispatch (an agent routing an LLM
464
+ * tool-call name, the embed bridge mapping a postMessage type, an
465
+ * editing keyboard building a tool name from a family prefix) where the name
466
+ * (and its input) is a runtime `string`/`unknown` rather than a literal the
467
+ * compiler can match against `TInputs`. The typed {@link dispatch} wraps this
468
+ * for the common case where the name is a known literal.
469
+ */
470
+ dispatchUnsafe(ctx: TCtx, name: string, rawInput: unknown): Promise<ToolResult>;
471
+ /**
472
+ * dispatchFromModel is the entry point for a tool call the MODEL emitted. It is
473
+ * the only dispatch that treats {@link Tool.agentHidden} as a gate rather than a
474
+ * manifest filter: a name the model was never shown but produced anyway is
475
+ * refused here, so the hidden set stops resting on the model not guessing it.
476
+ *
477
+ * It is a separate entry point rather than a branch inside dispatchUnsafe on
478
+ * `ctx.origin`, because the trust boundary is the MODEL, not the origin tag. A
479
+ * hidden tool used as an INTERNAL step (`studio.search.selectResult` lighting
480
+ * its pick through `studio.search.highlight` and clearing the last one through
481
+ * `studio.search.clearHighlight`) chains through ctx.bus with its caller's own
482
+ * context and must keep working. Gating on origin would break exactly those
483
+ * chains, and silently where a chain discards the chained result: the outer
484
+ * tool would report success for a step that never ran. Keeping the gate on this seam makes that
485
+ * failure mode unreachable instead of something each new handler must remember.
486
+ *
487
+ * The refusal is `forbidden`, not `capability-denied`: the context genuinely
488
+ * holds the capability, and mis-stating that would mislead both the model's
489
+ * recovery branch and the observer that reads the code.
490
+ */
491
+ dispatchFromModel(ctx: TCtx, name: string, rawInput: unknown): Promise<ToolResult>;
492
+ /**
493
+ * dispatch is the name-checked, input-checked entry point: the name must be a
494
+ * key of this bus's `TInputs`, and the raw input must match that tool's
495
+ * pre-parse shape, so a stray field or a wrong tool name is a compile error at
496
+ * the call site rather than a silently-stripped field at runtime. It delegates
497
+ * straight to {@link dispatchUnsafe}, which still runs the full Zod validation
498
+ * the dispatch contract guarantees: the typing is a build-time guard layered
499
+ * over the same runtime path, never a replacement for it. On a bus left at the
500
+ * default `TInputs`, with {@link ToolDispatchRegistry} not augmented, there is no
501
+ * key and this method takes no name: {@link dispatchUnsafe} is the entry point
502
+ * there.
503
+ *
504
+ * It answers the {@link ToolResult} of the named verb's data, read from this bus's
505
+ * `TOutputs`, and `data` as `unknown` for a name that map does not hold. Nothing
506
+ * is parsed on the way out: what the handler returned is what the caller reads.
507
+ */
508
+ dispatch<K extends keyof TInputs & string>(ctx: TCtx, name: K, rawInput: TInputs[K]): Promise<ToolResultOf<TOutputs, K>>;
509
+ }
510
+ export { ToolDispatchEvent as a, codeForThrown as c, ToolBusOptions as i, failureFromThrown as l, ToolBusObserve as n, ToolDispatchObserver as o, ToolBusObserveOverrides as r, ThrownRecognizer as s, ToolBus as t, restStatusCodes as u };
511
+ //# sourceMappingURL=chunk-Dp_ftNWY.d.cts.map
@@ -0,0 +1,31 @@
1
+ import { c as messageOf, s as memberOf } from "./chunk-DKuuuld5.js";
2
+ import { MountayaElementsError } from "@mountaya/elements/errors";
3
+ const ZONE_SOURCE_REFUSED = "zone source refused";
4
+ const BAD_REQUEST_STATUS = 400;
5
+ const SOURCE_PATH = [
6
+ "request",
7
+ "body",
8
+ "source"
9
+ ];
10
+ const ZONE_SOURCE_REFUSED_NAME = "ZoneSourceRefusedError";
11
+ var ZoneSourceRefusedError = class extends MountayaElementsError {
12
+ name = ZONE_SOURCE_REFUSED_NAME;
13
+ detail;
14
+ status = BAD_REQUEST_STATUS;
15
+ constructor(message, detail, options) {
16
+ super(message, options);
17
+ this.detail = detail;
18
+ }
19
+ };
20
+ const namesSource = (path) => Array.isArray(path) && SOURCE_PATH.every((member, index) => path[index] === member);
21
+ const zoneSourceRefusalOf = (error) => {
22
+ if (memberOf(error, "status") !== BAD_REQUEST_STATUS) return;
23
+ const first = memberOf(memberOf(error, "errors"), 0);
24
+ if (!namesSource(memberOf(first, "path"))) return;
25
+ const sentence = memberOf(first, "message");
26
+ return new ZoneSourceRefusedError(`${ZONE_SOURCE_REFUSED}: ${messageOf(error)}`, typeof sentence === "string" ? sentence : void 0, { cause: error });
27
+ };
28
+ const zoneSourceRefused = (result) => !result.ok && result.code === "invalid-input" && result.error.startsWith(`zone source refused: `);
29
+ export { zoneSourceRefused as n, zoneSourceRefusalOf as t };
30
+
31
+ //# sourceMappingURL=chunk-DsHQySz0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-DsHQySz0.js","names":[],"sources":["../src/zones/rules/zoneSourceRefusal.ts"],"mappings":";;AAsBA,MAAa,sBAAsB;AAGnC,MAAM,qBAAqB;AAM3B,MAAM,cAAc;CAAC;CAAW;CAAQ;AAAQ;AAGhD,MAAM,2BAA2B;AASjC,IAAa,yBAAb,cAA4C,sBAAsB;CAChE,OAAiC;CAMjC;CAGA,SAA0B;CAE1B,YAAY,SAAiB,QAAiB,SAAwB;EACpE,MAAM,SAAS,OAAO;EACtB,KAAK,SAAS;CAChB;AACF;AAMA,MAAM,eAAe,SACnB,MAAM,QAAQ,IAAI,KAAK,YAAY,OAAO,QAAQ,UAAU,KAAK,WAAW,MAAM;AAWpF,MAAa,uBAAuB,UAAuD;CACzF,IAAI,SAAS,OAAO,QAAQ,MAAM,oBAChC;CAGF,MAAM,QAAQ,SAAS,SAAS,OAAO,QAAQ,GAAG,CAAC;CACnD,IAAI,CAAC,YAAY,SAAS,OAAO,MAAM,CAAC,GACtC;CAGF,MAAM,WAAW,SAAS,OAAO,SAAS;CAE1C,OAAO,IAAI,uBACT,GAAG,oBAAoB,IAAI,UAAU,KAAK,KAC1C,OAAO,aAAa,WAAW,WAAW,KAAA,GAC1C,EAAE,OAAO,MAAM,CACjB;AACF;AAMA,MAAa,qBAAqB,WAChC,CAAC,OAAO,MACR,OAAO,SAAS,mBAChB,OAAO,MAAM,WAAW,uBAA0B"}