@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
@@ -1,845 +0,0 @@
1
- import * as z from 'zod';
2
- import { RestSchema } from '@mountaya/client';
3
-
4
- /**
5
- * The vocabulary a studio mutation surface is spoken in.
6
- *
7
- * Everything here is generic over `TCtx`, the execution context a host threads into its
8
- * handlers. That parameter is the whole reason this module can be published: the context is
9
- * the one part of a tool bus that is irreducibly the host's (Mountaya's studio threads a map
10
- * client, a UI store and a query cache through it, an integrator will thread whatever their
11
- * application holds), while the dispatch machinery, the capability gate, the confirmation
12
- * protocol and the result shape are the same for everyone.
13
- *
14
- * Nothing here imports a renderer or React, and `@mountaya/client` is named for one type, the
15
- * wire's failure codes, which erases. A tool is a name, a Zod schema and a function;
16
- * `boundary.test.ts` keeps it that way.
17
- */
18
- /**
19
- * toolCapabilitySchema is the capabilities this package can mean on its own behalf.
20
- *
21
- * `authenticated` is "there is a session"; `editor` is "this surface may change the resource".
22
- * They are Zod-first because a host derives them from an auth context and may want to parse
23
- * what it derived.
24
- *
25
- * The set is deliberately small. A vocabulary is only useful where both sides agree on what a
26
- * word denotes, and these are the only ones a package that knows nothing about a host's
27
- * authorization model can define. Anything past them, such as a surface class, what an
28
- * agreement covers or a membership role, belongs to whoever grants it.
29
- */
30
- declare const toolCapabilitySchema: z.ZodEnum<{
31
- authenticated: "authenticated";
32
- editor: "editor";
33
- }>;
34
- /**
35
- * ToolCapability gates which tools are available to a surface: the ones above, plus whatever a
36
- * host's own model adds.
37
- *
38
- * The `(string & {})` arm is what makes the union open while keeping the published values in
39
- * autocomplete: a host declaring `capability: "embedding"` on its own tool is legal, and a host
40
- * reaching for `"editor"` still gets it offered. The gate itself is a `Set.has` over strings and
41
- * never narrows, so an unknown capability is refused rather than mistaken for a known one.
42
- *
43
- * A host with a closed vocabulary of its own states it in one place: declare a Zod enum over
44
- * every capability it grants and thread it through its own tool type, which is how a host
45
- * names the surfaces this package has no business naming.
46
- */
47
- type ToolCapability = z.infer<typeof toolCapabilitySchema> | (string & {});
48
- /**
49
- * confirmationToneSchema is the closed vocabulary of confirm treatments a tool may
50
- * ask its prompt to wear. It names the CONSEQUENCE, and the confirm surface owns the
51
- * paint, so a tool never hard-codes a color:
52
- *
53
- * - "destructive": data is removed or a grant is revoked.
54
- * - "cautionary": nothing is lost, but a live side effect follows that the user
55
- * cannot silently walk back (a chain re-shape, a re-route).
56
- * - "affirmative": a benign confirmation the user is simply being asked to own.
57
- *
58
- * Zod-first because it is a value enum shared across the tool definitions, the bus,
59
- * and the confirm surface. Absent on a policy, the tone is "destructive": the confirm
60
- * gate exists for consequential verbs, so the loudest treatment is the safe default and
61
- * a softer one is an explicit opt-in.
62
- */
63
- declare const confirmationToneSchema: z.ZodEnum<{
64
- affirmative: "affirmative";
65
- cautionary: "cautionary";
66
- destructive: "destructive";
67
- }>;
68
- /**
69
- * ConfirmationTone is the treatment a confirm prompt wears, derived from
70
- * {@link confirmationToneSchema}. See the schema's JSDoc for each member's meaning.
71
- */
72
- type ConfirmationTone = z.infer<typeof confirmationToneSchema>;
73
- /**
74
- * ConfirmationValues are the interpolation values a confirm prompt's copy keys are
75
- * resolved with, so a body can name the entities it is about to act on ("Merge
76
- * {{name}} into {{nextName}}") instead of describing them generically. A value the
77
- * entry does not reference is ignored, and a placeholder with no value renders as-is
78
- * rather than throwing.
79
- */
80
- type ConfirmationValues = Record<string, string | number>;
81
- /**
82
- * toolConfirmationSchema is the Zod source of truth for a tool's confirmation
83
- * policy. Every copy field is a key the confirm surface resolves, never raw copy:
84
- * this package carries no strings and does not translate.
85
- *
86
- * - acknowledgeLabel, when present, demands the user tick an "I understand…"
87
- * checkbox before the confirm control enables, reserved for the highest-stakes
88
- * tools so a stray click cannot destroy something.
89
- * - titleLabel / descriptionLabel override the dialog's title and body so each
90
- * destructive tool reads with its own resource-specific copy; absent, the surface
91
- * falls back to the tool's description and a generic title.
92
- * - confirmLabel overrides the confirm button's label.
93
- * - tone selects the prompt's treatment (see {@link confirmationToneSchema}) and
94
- * defaults to "destructive" when absent.
95
- *
96
- * A tool that supplies an empty object keeps the generic prompt; the empty form is the
97
- * explicit declaration that the generic prompt is the intended experience. A host may
98
- * introspect this schema at manifest time, so the contract is machine-readable rather
99
- * than implicit.
100
- */
101
- declare const toolConfirmationSchema: z.ZodObject<{
102
- acknowledgeLabel: z.ZodOptional<z.ZodString>;
103
- confirmLabel: z.ZodOptional<z.ZodString>;
104
- descriptionLabel: z.ZodOptional<z.ZodString>;
105
- titleLabel: z.ZodOptional<z.ZodString>;
106
- tone: z.ZodOptional<z.ZodEnum<{
107
- affirmative: "affirmative";
108
- cautionary: "cautionary";
109
- destructive: "destructive";
110
- }>>;
111
- }, z.core.$strip>;
112
- /**
113
- * ToolConfirmation is the confirmation policy a destructive tool attaches to
114
- * itself, derived from toolConfirmationSchema.
115
- */
116
- type ToolConfirmation = z.infer<typeof toolConfirmationSchema>;
117
- /**
118
- * ConfirmationRequest describes a destructive (requiresConfirmation) tool the
119
- * bus is about to run. The bus passes it to the context's confirm gate so the
120
- * application (or an agent host) can prompt for approval before the handler runs.
121
- *
122
- * The bus forwards the tool's policy two ways: `acknowledge` carries the whole policy
123
- * object, and the policy's display keys are also flattened onto the request as
124
- * `titleLabel` / `descriptionLabel` / `confirmLabel` so a surface resolves the dialog's
125
- * copy without reaching into the nested policy. `cancelLabel` optionally overrides the
126
- * cancel copy. All are keys, absent for a tool that keeps the generic prompt; a host
127
- * that builds a request by hand supplies a pre-resolved `description` and omits them.
128
- */
129
- interface ConfirmationRequest {
130
- acknowledge?: ToolConfirmation | undefined;
131
- cancelLabel?: string | undefined;
132
- confirmLabel?: string | undefined;
133
- description: string;
134
- descriptionLabel?: string | undefined;
135
- input: unknown;
136
- name: string;
137
- titleLabel?: string | undefined;
138
- tone?: ConfirmationTone | undefined;
139
- values?: ConfirmationValues | undefined;
140
- }
141
- /**
142
- * TabSurface is the narrow window onto a host's tab strip a tool handler needs: reveal
143
- * the co-pilot panel, switch the active tab, open a new one (returning its id), or close
144
- * one. A host injects it so the tab tools never reach into a specific store: the bus
145
- * stays the single mutation surface and the tab state stays a host detail. Optional,
146
- * since a surface with no tab strip omits it and those tools return a structured failure
147
- * rather than throwing.
148
- */
149
- interface TabSurface {
150
- addCopilotTab: () => string;
151
- closeCopilotTab: (tabId: string) => void;
152
- /** countOpen returns the number of co-pilot tabs currently open. */
153
- countOpen: () => number;
154
- /**
155
- * hasTab reports whether the strip holds a tab under `tabId`: a conversation that is open, or
156
- * a pseudo-tab the strip shows.
157
- *
158
- * It is what lets `studio.tabs.switch` and `studio.tabs.close` answer `not-found` for an id
159
- * that names no tab, where `setActiveTab` and `closeCopilotTab` report nothing
160
- * back. A strip that states none is not asked, and the two verbs answer success for an id
161
- * they could not check. The search pseudo-tab is always there, so `studio.tabs.switch` shows
162
- * it without asking.
163
- *
164
- * @default undefined, and no id is refused as unknown
165
- */
166
- hasTab?: ((tabId: string) => boolean) | undefined;
167
- /**
168
- * openCopilot reveals the co-pilot and returns the id of the tab it
169
- * activated. Idempotent focus-or-open: it activates an existing conversation when one
170
- * is open and opens one when none is, so a repeated request always lands on the panel
171
- * rather than silently hitting the open-tab cap.
172
- */
173
- openCopilot: () => string;
174
- /**
175
- * reset clears the co-pilot for a switched-to resource: it closes every thread so the
176
- * leaving resource's conversation cannot leak into the next one, then lands on the
177
- * default tab so the panel stays closed until asked again.
178
- */
179
- reset: () => void;
180
- setActiveTab: (tabId: string) => void;
181
- }
182
- /**
183
- * ViewerPreferences is how the person reading this studio wants measurements and copy
184
- * rendered. Every field is optional because a host hydrates them from a profile that may
185
- * carry none of them, and each consumer falls back to its own default rather than to a
186
- * shared one: an absent `length` is "this viewer has not said", not "metric".
187
- *
188
- * `UnitFormatOptions` on `@mountaya/elements` is the resolved form of every field: a formatter
189
- * needs an answer for each, so `resolveViewerUnits` fills the gaps and the sparse shape never
190
- * reaches one.
191
- */
192
- interface ViewerPreferences {
193
- /** A BCP 47 tag. Chooses the decimal separator and the localized unit name. */
194
- language?: string | undefined;
195
- length?: "metric" | "imperial" | undefined;
196
- /** The FORM a travel rate is stated in. The system still comes from `length`. */
197
- pace?: "per-time" | "per-distance" | undefined;
198
- slope?: "degrees" | "percentage" | undefined;
199
- temperature?: "celsius" | "fahrenheit" | undefined;
200
- }
201
- /**
202
- * ViewerSeam is the narrow window onto whoever is reading this studio: who they are, what
203
- * the host currently extends to them, and how they want measurements rendered.
204
- *
205
- * Three questions, one answer a surface can change, and a subscription. `setPreferences` is
206
- * the one WRITE.
207
- *
208
- * The questions: `getUserId` answers "is this mine?" (an edit lock's holder, a collection's
209
- * author, the creator of a personal resource). `hasEntitlement` answers "does this person's
210
- * agreement cover this surface?".
211
- * `getPreferences` lets a confirm prompt state a distance in the units the rest of the editor
212
- * shows. Nothing else about a session belongs to a tool.
213
- *
214
- * The write belongs HERE rather than on a seam of its own, and the reason is `subscribe`. It
215
- * writes exactly the state the reads read, and that state is the one thing on this interface
216
- * that changes under a session that stays put, so a second seam would be one object a host
217
- * wires separately, notifying listeners registered on the first. What would be wrong is a write
218
- * to something this seam does not also READ; there is none, and a reviewer adding one should
219
- * treat this paragraph as the argument against it.
220
- *
221
- * It is deliberately NOT a store. A host's identity store also carries how the session was
222
- * established (an email-verification flag, an identity provider's traits and metadata, the
223
- * setters a bootstrap calls), and none of that is a studio concern. Publishing the store
224
- * would put one identity provider's session vocabulary in every consumer's types; publishing
225
- * the three questions instead lets a host answer them from whatever it already has.
226
- *
227
- * Every member is a FUNCTION, not a value, and that is the load-bearing part. A host builds
228
- * its context once and hands the same object to every dispatch, so anything captured by
229
- * value is captured at mount, and entitlement is precisely what is not settled then, since
230
- * membership in an organization resolves from a lookup that lands after bootstrap. A
231
- * handler that read a snapshot would refuse a member the surface already offers.
232
- */
233
- interface ViewerSeam<TEntitlement extends string = string> {
234
- getPreferences: () => ViewerPreferences | null;
235
- getUserId: () => string | null;
236
- /**
237
- * hasEntitlement asks whether the host extends a named entitlement to this viewer right
238
- * now, such as a product the viewer's agreement covers or a membership.
239
- *
240
- * Distinct from `ToolBusContext.capabilities`, and the difference is what each describes.
241
- * `capabilities` is what the SURFACE is: an embed grants `embedding` for as long as it is an
242
- * embed, so the bus can settle it once and gate on a `Set`. This is what the PERSON
243
- * holds, which changes under a session that stays put.
244
- *
245
- * The vocabulary belongs to the host, for the same reason `ToolCapability` leaves what an
246
- * agreement covers to whoever grants it. A host with a closed set of its own states it once
247
- * as a Zod enum and binds it through `TEntitlement`, so a typo is a type error rather than a
248
- * silent `false`.
249
- */
250
- hasEntitlement: (entitlement: TEntitlement) => boolean;
251
- /**
252
- * setPreferences records a viewer's measurement choices, as a PARTIAL: a surface changing
253
- * the length system says only that, and the host folds it onto whatever it already held.
254
- *
255
- * The one member that is not a question, and it is on this interface because it writes the
256
- * state `getPreferences` reads and `subscribe` reports, as {@link ViewerSeam} argues. Where the
257
- * host PUTS it is the host's business: a signed-in studio persists it against the account, an
258
- * embed keeps it for the session, and a viewer built by `createStaticViewer` drops it.
259
- *
260
- * Total, like every seam in this family: a host that cannot store a preference does nothing
261
- * rather than throwing, and "the choice did not stick" is a state the surface already renders
262
- * by reading the value back.
263
- */
264
- setPreferences: (partial: ViewerPreferences) => void;
265
- /**
266
- * subscribe registers a listener for any change to the answers above, and returns the
267
- * unsubscribe.
268
- *
269
- * Every other member is a function so it can be READ late: the context is built once per
270
- * mount and a membership resolves after it. That is exactly right for a handler, which runs on
271
- * demand and wants the answer as of now. It is not enough for a surface: a component that
272
- * calls `hasEntitlement` during render is correct once and then stale, and the surfaces that
273
- * gate on this are the ones a session changes underneath (an invitation accepted in another
274
- * tab, an agreement that starts covering a product, a membership that resolves a beat after
275
- * the studio mounts).
276
- *
277
- * The signature is `useSyncExternalStore`'s deliberately, so a host holding this in any store
278
- * passes its own `subscribe` unchanged and a host holding constants passes one that never
279
- * fires. Required rather than optional: an optional subscription is one a component cannot
280
- * rely on, so every reader would need a stale path as well as a live one.
281
- */
282
- subscribe: (onChange: () => void) => () => void;
283
- }
284
- /**
285
- * ToolBusContext is the minimum a host's execution context must provide for the bus to do
286
- * its job, and the only part of that context this package is entitled to know about.
287
- *
288
- * Its members are what the bus itself reads of a context before a handler runs: `capabilities`,
289
- * to refuse a tool the caller was never granted, and `confirm`, called before a destructive one.
290
- * A tool's `precondition` and everything a handler touches (a map, a store, a cache) read the
291
- * host's own context, and none of it appears here.
292
- *
293
- * `confirm` is optional, and its absence is a REFUSAL rather than a bypass: a bus with no
294
- * confirm gate declines every tool that requires confirmation. That is what lets a read-only
295
- * surface omit the gate entirely and still be safe by construction, instead of relying on
296
- * nobody having registered a destructive tool.
297
- */
298
- interface ToolBusContext {
299
- capabilities: ReadonlySet<ToolCapability>;
300
- confirm?: ((request: ConfirmationRequest) => Promise<boolean>) | undefined;
301
- }
302
- /**
303
- * ToolDispatchRegistry maps every registered tool name to its raw (pre-parse) input
304
- * type. It is declared empty here and populated by a host via interface augmentation
305
- * (`declare module "@mountaya/studio"`), so this module stays a leaf (it never
306
- * imports the registry that knows the tools) while a handler chaining through the
307
- * context's bus still sees the full name union and each tool's input shape. Without an
308
- * augmentation present it is empty: {@link KnownToolInput} answers `unknown` for every name,
309
- * and the typed `dispatch` of a {@link ToolBusDispatch} left at this default takes no name, so
310
- * `dispatchUnsafe` is the entry point until the registry is augmented or the inputs are named.
311
- */
312
- interface ToolDispatchRegistry {
313
- }
314
- /**
315
- * KnownToolInput resolves a tool name to its raw (pre-parse) input type from the
316
- * augmented registry, or `unknown` for a name the registry does not carry (the
317
- * loose-seam fallback, and the type a dynamically-built name resolves to).
318
- */
319
- type KnownToolInput<TName> = TName extends keyof ToolDispatchRegistry ? ToolDispatchRegistry[TName] : unknown;
320
- /**
321
- * ToolOutputRegistry maps every registered tool name to the `data` its answer holds. It is the
322
- * second augmentation seam, beside {@link ToolDispatchRegistry} and declared empty for the same
323
- * reason: a host fills it by interface augmentation (`declare module "@mountaya/studio"`), so
324
- * this module names no tool and a dispatch through the context's bus still answers each verb's
325
- * own data.
326
- *
327
- * A registry of its own, because what a tool takes and what it answers are separate questions. A
328
- * host that augments the inputs alone has its names and payloads checked and reads every
329
- * answer's `data` as `unknown`, which is what a dispatch answers wherever this map does not hold
330
- * the name.
331
- */
332
- interface ToolOutputRegistry {
333
- }
334
- /**
335
- * KnownToolOutput resolves a tool name to the `data` its answer holds, read from the augmented
336
- * {@link ToolOutputRegistry}, or `unknown` for a name the registry does not carry: a tool whose
337
- * contract states no output, and every name while the registry is not augmented.
338
- */
339
- type KnownToolOutput<TName> = TName extends keyof ToolOutputRegistry ? ToolOutputRegistry[TName] : unknown;
340
- /**
341
- * unstated keys the answer of a name an outputs map does not hold. A symbol, so no tool name can
342
- * spell it, and declared only: it names a type and no value exists behind it.
343
- */
344
- declare const unstated: unique symbol;
345
- /**
346
- * ToolSuccess is the `ok` arm of {@link ToolResult}: a summary, and the data of type `TData`.
347
- */
348
- type ToolSuccess<TData = unknown> = Extract<ToolResult<TData>, {
349
- ok: true;
350
- }>;
351
- /**
352
- * ToolSuccessByName is an outputs map read as `ok` answers: each name to the {@link ToolSuccess}
353
- * holding its data, and {@link unstated} to the `ok` answer of every other name.
354
- *
355
- * A mapped type rather than `ToolResult<TOutputs[TName]>` written at the dispatch itself, because
356
- * each entry here is resolved once per name. A result parameterised by a name still to be
357
- * inferred stays unresolved, and nothing but the bus's own answer is assignable to it.
358
- */
359
- type ToolSuccessByName<TOutputs> = {
360
- [K in keyof TOutputs]: ToolSuccess<TOutputs[K]>;
361
- } & {
362
- [unstated]: ToolSuccess;
363
- };
364
- /**
365
- * ToolResultOf is what a dispatch of `TName` answers on a bus whose outputs are `TOutputs`: the
366
- * {@link ToolResult} of that verb's data, and a plain {@link ToolResult} for a name the map does
367
- * not hold.
368
- *
369
- * The arms ahead of the lookup are the names the compiler cannot match. No name at all is the
370
- * typed dispatch of a bus whose registry is not augmented, and the whole of `string` is a name
371
- * built at run time. Each answers `data` as `unknown`, whatever the map holds.
372
- *
373
- * The refusal is an arm of its own beside the lookup, and the lookup holds the `ok` arms alone.
374
- * A {@link ToolFailure} is therefore the answer of every verb while the name is still to be
375
- * resolved: a wrapper generic in the name returns a refusal of its own as written, and so does a
376
- * hand-written dispatch that refuses everything. A value that answers one `ok` shape under every
377
- * name is held to the lookup, and is refused with the two types named where a verb states data
378
- * it does not carry. A refusal held inside each entry would cost both: to relate such a value the
379
- * compiler intersects every verb's whole result, and over a map of many data types it gives up
380
- * with TS2590, which names neither type and is reported for the first such value of a program
381
- * alone.
382
- *
383
- * The `string` arm is also what makes `TOutputs` a way of READING a bus and no part of its
384
- * identity. TypeScript compares two instantiations of one generic interface with the method's
385
- * own type parameter erased, where every dispatch answers the plain result, so a dispatch slice
386
- * typed with one outputs map is assignable to a slot typed with another. A host that names no
387
- * outputs hands its `bus.dispatcher` to a studio context as it stands. A value of another type,
388
- * a bus instance or an object literal among them, is compared member by member, and there the
389
- * answers have to agree.
390
- *
391
- * Published for a wrapper that forwards a name it has not resolved. A function generic in the
392
- * name returns this type to hand its caller what the bus answered: a `ToolResult` written over
393
- * `TOutputs[TName]` is another unresolved type, and the bus's answer is not assignable to it.
394
- *
395
- * @example
396
- * ```ts
397
- * interface Inputs {
398
- * "acme.route.measure": { routeId: string };
399
- * }
400
- * interface Outputs {
401
- * "acme.route.measure": { meters: number };
402
- * }
403
- * declare const dispatcher: ToolBusDispatch<ToolBusContext, Inputs, Outputs>;
404
- * declare const context: ToolBusContext;
405
- *
406
- * const dispatch = <TName extends keyof Inputs & string>(
407
- * name: TName,
408
- * input: Inputs[TName],
409
- * ): Promise<ToolResultOf<Outputs, TName>> => dispatcher.dispatch(context, name, input);
410
- *
411
- * const measured = await dispatch("acme.route.measure", { routeId: "r-1" });
412
- * console.log(measured.ok ? measured.data.meters : measured.error);
413
- * ```
414
- */
415
- type ToolResultOf<TOutputs, TName> = [TName] extends [never] ? ToolResult : string extends TName ? ToolResult : ToolFailure | ToolSuccessByName<TOutputs>[[TName] extends [keyof TOutputs] ? TName & keyof TOutputs : typeof unstated];
416
- /**
417
- * ToolBusDispatch is the structural slice of the bus a chained handler reaches for: the
418
- * dispatch surface alone. Declared here rather than imported from the bus so this
419
- * module stays a leaf: a context shapes how the bus looks to a handler without inverting
420
- * the dependency edge that would make the two a circular pair.
421
- *
422
- * `TInputs` maps each tool name to its raw input, defaulting to
423
- * {@link ToolDispatchRegistry} (the map a host augments), so a handler reaching the
424
- * context's bus sees the full name union and each tool's input on `dispatch`. Until a host
425
- * augments it that map is empty, and `dispatch` takes no name.
426
- *
427
- * `TOutputs` maps each tool name to the `data` its answer holds, defaulting to
428
- * {@link ToolOutputRegistry}, the second map a host augments. `dispatch` answers the
429
- * {@link ToolResult} of the named verb's data, so a reader takes a member of it after `ok` with
430
- * no narrowing of its own, and a name the map does not hold answers `data` as `unknown`. The
431
- * bus parses no answer: the type is held by each handler being typed by its contract's `output`,
432
- * and by the testing bus, which checks every answer against that schema.
433
- *
434
- * `dispatch` is the typed entry point: a known literal name and its matching raw input,
435
- * with a stray field or wrong name a compile error at the call site. `dispatchUnsafe` is
436
- * the escape hatch for a dynamically-built name (an agent routing a model's
437
- * tool-call, a bridge mapping a postMessage type) where the name is a runtime `string`
438
- * the compiler cannot match against the union, and its answer is a plain {@link ToolResult}.
439
- * A concrete bus always provides both, so the member is required, not optional.
440
- */
441
- interface ToolBusDispatch<TCtx, TInputs extends object = ToolDispatchRegistry, TOutputs extends object = ToolOutputRegistry> {
442
- dispatch<TName extends keyof TInputs & string>(ctx: TCtx, name: TName, rawInput: TInputs[TName]): Promise<ToolResultOf<TOutputs, TName>>;
443
- dispatchUnsafe(ctx: TCtx, name: string, rawInput: unknown): Promise<ToolResult>;
444
- }
445
- /**
446
- * toolErrorCodeSchema is the closed vocabulary of machine-readable failure codes a
447
- * ToolResult may carry, the Zod source of truth so a consumer branches on a stable code
448
- * rather than substring-matching the human-readable message. Its members are
449
- * {@link toolErrorCodes}, and every one has a real producer:
450
- *
451
- * - "canceled": the run was ended by its caller before it produced its answer, such as a
452
- * recording a cancel, a close or a newer recording stopped. Its own code rather than
453
- * "internal" because nothing went wrong, and apart from "confirmation-denied", which is a
454
- * prompt declined before anything ran.
455
- * - "capability-denied": the context lacks the tool's capability gate.
456
- * - "collab-locked": a collaborator holds the entity's soft-lock (a REMOTE peer),
457
- * distinct from "edit-in-progress", which is the LOCAL one-edit-at-a-time gate.
458
- * - "confirmation-denied": the confirm gate rejected, or was absent for a destructive tool.
459
- * - "confirmation-timeout": a destructive server-side confirmation window elapsed with no
460
- * answer. Separate from "confirmation-denied" because nobody refused: re-asking is
461
- * reasonable here and rude after a refusal.
462
- * - "conflict": a write lost a revision race (a 409), or a segment's or a waypoint's commit
463
- * was asked with another draft while the create of that entity is still out, in which case
464
- * no request is made.
465
- * - "draft-open": a persisted-only verb was asked for while a draft owns the editor.
466
- * - "edit-in-progress": another authoring engine is already armed, or a split pick is.
467
- * - "forbidden": the caller is not allowed to perform the action (a 403).
468
- * - "internal": an unclassified handler throw or failure (the catch-all).
469
- * - "invalid-input": the schema rejected the raw input, or a server validation did (a 400).
470
- * - "limit-reached": a ceiling was reached: one the agreement sets (its seats, its published
471
- * itineraries, its monthly allowance), the itineraries a personal space keeps, or the co-pilot
472
- * tabs the studio keeps open. An API refusal is one when an entry carries `LIMIT_REACHED` (a
473
- * 429 naming no wait) or when a 429 names a wait longer than a minute, and a retry soon does
474
- * not lift it.
475
- * - "no-api": the handler needs a data seam the host did not supply. It, "no-map" and
476
- * "no-session" are the only refusals that describe the STUDIO rather than the request, and
477
- * they are codes for the same reason every other member is: a surface that can name the
478
- * category can say something useful ("the studio isn't connected"), where a handler's own
479
- * `error` string is written for a log and an agent, and a surface rendering it would be
480
- * showing a reader a sentence nobody translated.
481
- * - "no-map": the action drives the map and no map is mounted. Transient by nature: the
482
- * canvas is still loading, so the surface answers "try again in a moment" rather than
483
- * reporting a fault.
484
- * - "no-session": the session, draft, wizard or pick the action acts on is not open. The
485
- * editor is one-at-a-time in several places, and a verb aimed at a closed one is an
486
- * ordering mistake rather than a failure of the thing it names.
487
- * - "not-found": the targeted resource does not exist (a 404).
488
- * - "rate-limited": the caller exceeded a per-minute rate limit (a 429 not coded `LIMIT_REACHED`
489
- * naming no wait, or a wait of a minute or less), which a moment's wait clears.
490
- * - "split-on-end": a split point resolved to the very start or end of a segment, where
491
- * cutting would produce an empty half. Its own code because the surface answers it with
492
- * "aim further along the line", which a category alone cannot say.
493
- * - "split-too-far": a split point landed further from the line than the pointing
494
- * tolerance allows. The fix is "click nearer the itinerary", not "aim elsewhere along it".
495
- * - "timeout": the request outlived its budget (a 504). Its own code rather than
496
- * "internal" because nothing is broken: the work was too large, so the surface answers
497
- * with what would make it smaller.
498
- * - "unavailable": the device or the page does not give what the action needs, such as a
499
- * position the device cannot determine or a page with no geolocation. Its own code rather
500
- * than "internal" because the studio is whole, and apart from "forbidden", which is a
501
- * permission the reader or the device refused.
502
- * - "unknown-tool": the dispatched name is not registered.
503
- * - "upgrade-required": the action needs a product the caller's agreement does not include.
504
- *
505
- * The gate codes reuse the spellings the bus's own dispatch event carries, so telemetry
506
- * and the structured result speak one vocabulary.
507
- *
508
- * One spelling, the contract's: every code is kebab-case. A code the contract's
509
- * `AgentToolErrorCode` also declares is spelled exactly as it is there, because an agent run
510
- * copies it onto the model's tool result verbatim. The ones {@link busOnlyToolErrorCodes} holds
511
- * (`no-api`, `no-map`, `no-session`, `split-on-end`, `split-too-far`) never reach the wire at
512
- * all: `toWireErrorCode` reports each as `internal`, the contract's code for a failure with no
513
- * more specific one.
514
- */
515
- declare const toolErrorCodeSchema: z.ZodEnum<{
516
- readonly canceled: "canceled";
517
- readonly "capability-denied": "capability-denied";
518
- readonly "collab-locked": "collab-locked";
519
- readonly "confirmation-denied": "confirmation-denied";
520
- readonly "confirmation-timeout": "confirmation-timeout";
521
- readonly conflict: "conflict";
522
- readonly "draft-open": "draft-open";
523
- readonly "edit-in-progress": "edit-in-progress";
524
- readonly forbidden: "forbidden";
525
- readonly internal: "internal";
526
- readonly "invalid-input": "invalid-input";
527
- readonly "limit-reached": "limit-reached";
528
- readonly "no-api": "no-api";
529
- readonly "no-map": "no-map";
530
- readonly "no-session": "no-session";
531
- readonly "not-found": "not-found";
532
- readonly "rate-limited": "rate-limited";
533
- readonly "split-on-end": "split-on-end";
534
- readonly "split-too-far": "split-too-far";
535
- readonly timeout: "timeout";
536
- readonly unavailable: "unavailable";
537
- readonly "unknown-tool": "unknown-tool";
538
- readonly "upgrade-required": "upgrade-required";
539
- }>;
540
- /**
541
- * ToolErrorCode is the machine-readable failure code a ToolResult may carry, derived
542
- * from {@link toolErrorCodeSchema}.
543
- */
544
- type ToolErrorCode = z.infer<typeof toolErrorCodeSchema>;
545
- /**
546
- * ToolResult is the structured outcome every handler returns: success carries a
547
- * human/model-readable summary (and optional data); failure carries an error string and,
548
- * when classified, a machine-readable {@link ToolErrorCode}. `code` is optional and
549
- * additive: an unclassified failure omits it, while a classified one carries it so a
550
- * consumer branches on the code rather than substring-matching the message. The bus
551
- * boundary stamps the gate codes; a handler stamps the codes it knows.
552
- *
553
- * **`summary` and `error` are MACHINE NARRATION and must never be rendered to a user.** They
554
- * are written for three readers and a person is none of them: a model deciding what to do next,
555
- * an event log, and whoever is reading that log. They are in English because this package has no
556
- * language (it ships no strings and takes no locale), so a surface that put one on screen would
557
- * be showing a French reader an English sentence nobody translated, in a voice written for a
558
- * model. What a surface renders instead is `detail` when the server supplied one, and otherwise
559
- * its own copy for the `code`. `studio-react`'s boundary test refuses a render of either field.
560
- *
561
- * `detail` is the server's own already-localized sentence for the failure, lifted off the
562
- * error envelope. It is deliberately separate from `error`, which stays the technical
563
- * string analytics and an agent read. A code alone can only say a category
564
- * (`invalid-input`), while `detail` says which input and why, so a surface prefers it when
565
- * present and falls back to its own per-code copy when it is not. This package carries NO
566
- * strings: it forwards the server's verbatim and never translates.
567
- *
568
- * `data` is a required member where `TData` leaves `undefined` out, and an optional one
569
- * otherwise. So a reader of a verb whose data is an object takes a member of it after `ok` with
570
- * no narrowing of its own, and a handler that leaves the data out does not compile. A bare
571
- * `ToolResult`, whose data is `unknown`, and a `ToolResult<undefined>`, the answer of a verb with
572
- * no data, both hold it as optional: neither says there is anything to read.
573
- *
574
- * The condition tests the whole of `TData` at once, so a union is one answer and never one
575
- * result per member. It is written with `TData` on the checked side, against every value but
576
- * `undefined`, which is what lets TypeScript relate the results of two unresolved data types by
577
- * relating the data: a {@link Tool} stating an `output` is assignable to a bare one on that
578
- * account. The same test written as `undefined extends TData` puts the type on the far side,
579
- * where two unresolved types have to be identical.
580
- */
581
- type ToolResult<TData = unknown> = ([TData] extends [NonNullable<unknown> | null] ? {
582
- data: TData;
583
- ok: true;
584
- summary: string;
585
- } : {
586
- data?: TData | undefined;
587
- ok: true;
588
- summary: string;
589
- }) | {
590
- code?: ToolErrorCode | undefined;
591
- detail?: string | undefined;
592
- error: string;
593
- ok: false;
594
- };
595
- /**
596
- * ToolFailure is the refusal arm of {@link ToolResult}: an `error`, with a {@link ToolErrorCode}
597
- * when the failure is classified and the server's `detail` when it sent one.
598
- *
599
- * Named so a signature that can only fail says so: `isConfirmationWithheld` narrows to it, and a
600
- * handler's guard returns the failure, or null to carry on. An inline
601
- * `{ error: string; ok: false }` is the same shape only until the arm grows a member: a copy
602
- * without `code` fails to compile at the guard that sets one, which is the good case, and drops
603
- * the code from a refusal that passes through it, which is the silent one.
604
- */
605
- type ToolFailure = Extract<ToolResult, {
606
- ok: false;
607
- }>;
608
- /**
609
- * Tool is the unit of the bus: a stable namespaced name, a model-facing description, a
610
- * Zod input schema (→ runtime validation + types + JSON Schema), a capability gate, an
611
- * optional destructive-confirmation flag, an optional confirmation policy, and a handler
612
- * taking (ctx, input). `confirmation` is honored only when `requiresConfirmation` is set.
613
- *
614
- * `TCtx` is the execution context the host threads through: the one part of a tool that
615
- * cannot be published, and therefore the parameter that lets the rest of it be.
616
- *
617
- * The optional `TName` parameter pins `name` to a string literal. A bare `Tool<Ctx>`
618
- * leaves it the open `string`, while a definition supplying its own name lets a registry
619
- * require, at compile time, that each entry's key equals the tool's own name, so a typo
620
- * in either is a type error rather than a runtime drift a test has to catch.
621
- *
622
- * `agentHidden` opts a tool out of the model-facing manifest: a hidden tool stays fully
623
- * registered and dispatchable (a human click or an internal chain runs it as it runs
624
- * any other) and is refused only at the model entry point. It marks the tools a system
625
- * prompt categorically forbids, so the model is never even offered them rather than the
626
- * prompt alone holding the line.
627
- *
628
- * `TCapability` is how a host closes {@link ToolCapability} again on its own side. The published
629
- * union is open, because the words this package can define are not an authorization model;
630
- * a host that has one binds its own enum here once (`Tool<Ctx, TSchema, TName, MyCapability>`),
631
- * and a mistyped capability is then a compile error at the definition rather than a refusal at
632
- * runtime. It has to be a parameter rather than something a host narrows by intersecting: an
633
- * intersection stops being the same generic interface, and the comparison falls off the variance
634
- * path onto a structural one that `confirmationValues` cannot satisfy.
635
- *
636
- * `TOutput` is the Zod schema of the `data` the tool answers, and it types the handler: one that
637
- * returns other data, or none where the schema asks for some, does not compile. Left at its
638
- * default the data is `unknown` and the handler answers a plain {@link ToolResult}, so a tool
639
- * declared as a bare `Tool<Ctx>` compiles with or without an `output`.
640
- */
641
- interface Tool<TCtx, TSchema extends z.ZodTypeAny = z.ZodTypeAny, TName extends string = string, TCapability extends ToolCapability = ToolCapability, TOutput extends z.ZodTypeAny = z.ZodTypeAny> {
642
- agentHidden?: boolean | undefined;
643
- capability: TCapability;
644
- confirmation?: ToolConfirmation | undefined;
645
- /**
646
- * confirmationValues resolves the interpolation values the confirm surface fills this
647
- * tool's policy keys with, so a prompt can name the entities it is about to act on. It
648
- * runs AFTER the input parses and BEFORE the handler, with the same context the handler
649
- * will get, so it may read state to turn ids into names.
650
- *
651
- * It must produce a plain record and nothing else: no writes, no dispatch. A resolver
652
- * that throws costs only the interpolation: the prompt still opens, rendering its
653
- * placeholders verbatim, so a bad resolver can never turn a confirmable action into a
654
- * rejected dispatch.
655
- *
656
- * @default undefined, and the prompt renders its placeholders verbatim
657
- */
658
- confirmationValues?: ((ctx: TCtx, input: z.infer<TSchema>) => ConfirmationValues) | undefined;
659
- description: string;
660
- handler: (ctx: TCtx, input: z.infer<TSchema>) => ToolResult<z.infer<TOutput>> | Promise<ToolResult<z.infer<TOutput>>>;
661
- input: TSchema;
662
- name: TName;
663
- /**
664
- * output is the Zod schema of the `data` an `ok` answer holds, stated beside `input`.
665
- *
666
- * It is what the handler is typed by, and the bus that ships never parses with it: what a
667
- * handler returns is what a reader reads. The testing bus is where it runs, against every
668
- * answer of the tool. A verb that answers no data states `toolNoDataSchema`.
669
- *
670
- * It is transform-free for that reason. A schema that changes what it parses describes a value
671
- * no reader receives.
672
- *
673
- * @default undefined, and the data is `unknown`
674
- */
675
- output?: TOutput | undefined;
676
- /**
677
- * precondition answers what the tool refuses before it asks: a {@link ToolFailure} for a call
678
- * the tool can already tell it refuses, or null to carry on.
679
- *
680
- * The bus runs it after the input parses and before the confirmation, with the context the
681
- * handler gets, and runs it for a tool that asks nothing as well. A failure it answers is the
682
- * dispatch's answer: no prompt is raised and the handler never runs, so a reader is never asked
683
- * to approve what the tool then refuses. One that throws is answered as a handler that throws
684
- * is.
685
- *
686
- * It reads state and writes nothing, as `confirmationValues` does, and it answers at once: a
687
- * check that waits on a request is the handler's. The handler keeps every refusal it states
688
- * here, because what a precondition read can change while the reader is asked.
689
- *
690
- * @default undefined, and nothing is refused ahead of the confirmation
691
- */
692
- precondition?: ((ctx: TCtx, input: z.infer<TSchema>) => ToolFailure | null) | undefined;
693
- requiresConfirmation?: boolean | undefined;
694
- }
695
- /**
696
- * JsonSchema is a JSON Schema object as produced by `z.toJSONSchema`: the shape a
697
- * manifest renders a tool's input into for a model or a documentation page. Reusing Zod's
698
- * own type keeps a manifest entry assignable to a gateway's `parameters` object with no
699
- * cast.
700
- */
701
- type JsonSchema = z.core.JSONSchema.BaseSchema;
702
- /**
703
- * StudioToolManifestEntry is the model/UI-facing description of one of the STUDIO's tools, with
704
- * the input schema rendered as JSON Schema.
705
- *
706
- * `Studio` in the name because `@mountaya/elements/agent` publishes a `ToolManifestEntry` of its
707
- * own, and the two are not the same shape: that one is what the agent SESSION consumes, typed
708
- * against the agent service's `parameters`, where this is what a studio PRODUCES, typed against
709
- * the studio's capability vocabulary and Zod's JSON Schema. One name for both would hand a
710
- * consumer importing the obvious one a type error several frames from the import.
711
- */
712
- interface StudioToolManifestEntry {
713
- capability: ToolCapability;
714
- description: string;
715
- inputSchema: JsonSchema;
716
- name: string;
717
- /**
718
- * Whether the tool only reads state and changes nothing. Absent means unknown, which
719
- * every consumer must treat as "may mutate": a run uses it to decide what its
720
- * transcript may safely drop, and guessing wrong there erases the record of a real
721
- * change.
722
- */
723
- readOnly?: boolean | undefined;
724
- requiresConfirmation: boolean;
725
- }
726
-
727
- /**
728
- * The wire types the studio's rules read.
729
- *
730
- * Type-only imports from `@mountaya/client`, never value imports: the client is a peer
731
- * dependency so these names resolve, and the built bundle holds no client code.
732
- * `boundary.test.ts` enforces both halves.
733
- *
734
- * The aliases let the modules below read in the studio's own vocabulary rather than repeat
735
- * `RestSchema.` at every position. Most of them stay off the root barrel: a consumer holding a
736
- * segment has its type from `@mountaya/client`, where the contract lives, and a second name here
737
- * would be two spellings of one type and an open question about which one is authoritative.
738
- *
739
- * The root publishes the ones a published declaration of this package names, so a reader of a
740
- * studio signature finds every name it uses at the entry that declares it, spelled as the
741
- * studio spells it.
742
- */
743
-
744
- /** Activity is an activity of the contract's catalog: the contract's `RestSchema.Activity`. */
745
- type Activity = RestSchema.Activity;
746
- /**
747
- * ActivityCapabilities is what an activity can be planned with: the contract's
748
- * `RestSchema.ActivityCapabilities`.
749
- */
750
- type ActivityCapabilities = RestSchema.ActivityCapabilities;
751
- /**
752
- * CategoryActivities is the activities of one catalog category: the contract's
753
- * `RestSchema.CategoryActivities`.
754
- */
755
- type CategoryActivities = RestSchema.CategoryActivities;
756
- /**
757
- * CollabEntityKind is the kinds of entity a collaborator locks: the contract's
758
- * `RestSchema.CollabEntityKind`.
759
- */
760
- type CollabEntityKind = RestSchema.CollabEntityKind;
761
- /**
762
- * Collection is a folder of itineraries and zones: the contract's `RestSchema.Collection`.
763
- */
764
- type Collection = RestSchema.Collection;
765
- /**
766
- * EmbeddedStudioDefaultProps is an organization's default embed configuration: the contract's
767
- * `RestSchema.EmbeddedStudioDefaultProps`.
768
- */
769
- type EmbeddedStudioDefaultProps = RestSchema.EmbeddedStudioDefaultProps;
770
- /**
771
- * EmbeddedStudioSafetyRules is the safety rules an embed is held to: the contract's
772
- * `RestSchema.EmbeddedStudioSafetyRules`.
773
- */
774
- type EmbeddedStudioSafetyRules = RestSchema.EmbeddedStudioSafetyRules;
775
- /**
776
- * ExportFormat is a file format an itinerary exports to: the contract's
777
- * `RestSchema.ExportFormat`.
778
- */
779
- type ExportFormat = RestSchema.ExportFormat;
780
- /** ExportVariant is a variant of an export format: the contract's `RestSchema.ExportVariant`. */
781
- type ExportVariant = RestSchema.ExportVariant;
782
- type ImportGranularity = RestSchema.ImportGranularity;
783
- /**
784
- * ImportRecommendationReason is why an import preview recommends a granularity: the contract's
785
- * `RestSchema.ImportRecommendationReason`.
786
- */
787
- type ImportRecommendationReason = RestSchema.ImportRecommendationReason;
788
- /**
789
- * ImportWarning is a warning an import preview raises: the contract's `RestSchema.ImportWarning`.
790
- */
791
- type ImportWarning = RestSchema.ImportWarning;
792
- /** Itinerary is an itinerary as the REST API answers it: the contract's `RestSchema.Itinerary`. */
793
- type Itinerary = RestSchema.Itinerary;
794
- type ItineraryImportPreview = RestSchema.ItineraryImportPreview;
795
- /** Locales is the REST API's locale vocabulary: the contract's `RestSchema.Locales`. */
796
- type Locales = RestSchema.Locales;
797
- /** ManeuverType is a routing maneuver: the contract's `RestSchema.ManeuverType`. */
798
- type ManeuverType = RestSchema.ManeuverType;
799
- /**
800
- * OrganizationRole is a member's role in an organization: the contract's
801
- * `RestSchema.OrganizationRole`.
802
- */
803
- type OrganizationRole = RestSchema.OrganizationRole;
804
- /**
805
- * RestLanguage is the contract's `RestSchema.Language`: the lowercase REST spelling (`"en"`),
806
- * named apart from the Data API's uppercase vocabulary, which this package spells
807
- * `dataLanguageSchema`.
808
- */
809
- type RestLanguage = RestSchema.Language;
810
- /** SurfaceType is a surface type of the analysis: the contract's `RestSchema.SurfaceType`. */
811
- type SurfaceType = RestSchema.SurfaceType;
812
- /**
813
- * TrailDifficultyType is a trail difficulty grade of the analysis: the contract's
814
- * `RestSchema.TrailDifficultyType`.
815
- */
816
- type TrailDifficultyType = RestSchema.TrailDifficultyType;
817
- type UnitLength = RestSchema.UnitLength;
818
- /** UnitPace is the form a travel rate is stated in: the contract's `RestSchema.UnitPace`. */
819
- type UnitPace = RestSchema.UnitPace;
820
- type UnitSlope = RestSchema.UnitSlope;
821
- /** UnitTemperature is a temperature unit: the contract's `RestSchema.UnitTemperature`. */
822
- type UnitTemperature = RestSchema.UnitTemperature;
823
- /** WaypointAmenity is an amenity a waypoint lists: the contract's `RestSchema.WaypointAmenity`. */
824
- type WaypointAmenity = RestSchema.WaypointAmenity;
825
- /** WaypointIcon is a waypoint's glyph: the contract's `RestSchema.WaypointIcon`. */
826
- type WaypointIcon = RestSchema.WaypointIcon;
827
- /**
828
- * WaypointPropertyFormat is the format of a customer-defined waypoint field: the contract's
829
- * `RestSchema.WaypointPropertyFormat`.
830
- */
831
- type WaypointPropertyFormat = RestSchema.WaypointPropertyFormat;
832
- /**
833
- * WaypointTiming is a waypoint's cut-off and stop timing: the contract's
834
- * `RestSchema.WaypointTiming`.
835
- */
836
- type WaypointTiming = RestSchema.WaypointTiming;
837
- type WaypointUpdateParams = RestSchema.WaypointUpdateParams;
838
- /** WayType is a way type of the analysis: the contract's `RestSchema.WayType`. */
839
- type WayType = RestSchema.WayType;
840
- /** Zone is a zone as the REST API answers it: the contract's `RestSchema.Zone`. */
841
- type Zone = RestSchema.Zone;
842
- type ZoneSource = RestSchema.ZoneSource;
843
-
844
- export { confirmationToneSchema as N, toolCapabilitySchema as P, toolConfirmationSchema as Q, toolErrorCodeSchema as X };
845
- export type { UnitSlope as $, Activity as A, ToolErrorCode as B, CategoryActivities as C, ToolOutputRegistry as D, EmbeddedStudioDefaultProps as E, UnitTemperature as F, ViewerSeam as G, WaypointTiming as H, ImportRecommendationReason as I, JsonSchema as J, KnownToolInput as K, Locales as L, ManeuverType as M, OrganizationRole as O, RestLanguage as R, SurfaceType as S, TabSurface as T, UnitPace as U, ViewerPreferences as V, WayType as W, ZoneSource as Y, Zone as Z, UnitLength as _, ToolBusDispatch as a, WaypointUpdateParams as a0, ImportGranularity as a1, ItineraryImportPreview as a2, ToolBusContext as b, ToolResultOf as c, ToolFailure as d, ToolResult as e, TrailDifficultyType as f, Tool as g, Collection as h, ActivityCapabilities as i, ConfirmationRequest as j, WaypointPropertyFormat as k, WaypointAmenity as l, WaypointIcon as m, CollabEntityKind as n, ConfirmationTone as o, ConfirmationValues as p, EmbeddedStudioSafetyRules as q, ExportFormat as r, ExportVariant as s, ImportWarning as t, Itinerary as u, KnownToolOutput as v, StudioToolManifestEntry as w, ToolCapability as x, ToolConfirmation as y, ToolDispatchRegistry as z };