@miragon/mcp-toolkit-ui 2.7.0 → 2.8.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 (387) hide show
  1. package/README.md +7 -4
  2. package/dist/app/adapt-data-widget.d.ts +1 -22
  3. package/dist/app/adapt-data-widget.d.ts.map +1 -1
  4. package/dist/app/adapt-data-widget.js +1 -35
  5. package/dist/app/adapt-data-widget.js.map +1 -1
  6. package/dist/app/builder/BuilderBanners.js +1 -1
  7. package/dist/app/builder/BuilderBanners.js.map +1 -1
  8. package/dist/app/builder/CanvasRow.d.ts +4 -2
  9. package/dist/app/builder/CanvasRow.d.ts.map +1 -1
  10. package/dist/app/builder/CanvasRow.js +21 -7
  11. package/dist/app/builder/CanvasRow.js.map +1 -1
  12. package/dist/app/builder/CatalogueSheet.d.ts.map +1 -1
  13. package/dist/app/builder/CatalogueSheet.js +11 -4
  14. package/dist/app/builder/CatalogueSheet.js.map +1 -1
  15. package/dist/app/builder/CellPropsSheet.d.ts +7 -3
  16. package/dist/app/builder/CellPropsSheet.d.ts.map +1 -1
  17. package/dist/app/builder/CellPropsSheet.js +10 -3
  18. package/dist/app/builder/CellPropsSheet.js.map +1 -1
  19. package/dist/app/builder/DiscardDialog.d.ts +18 -0
  20. package/dist/app/builder/DiscardDialog.d.ts.map +1 -0
  21. package/dist/app/builder/DiscardDialog.js +18 -0
  22. package/dist/app/builder/DiscardDialog.js.map +1 -0
  23. package/dist/app/builder/LayoutSurface.d.ts +33 -9
  24. package/dist/app/builder/LayoutSurface.d.ts.map +1 -1
  25. package/dist/app/builder/LayoutSurface.js +74 -23
  26. package/dist/app/builder/LayoutSurface.js.map +1 -1
  27. package/dist/app/builder/PipelineStrip.d.ts +2 -1
  28. package/dist/app/builder/PipelineStrip.d.ts.map +1 -1
  29. package/dist/app/builder/PipelineStrip.js +26 -13
  30. package/dist/app/builder/PipelineStrip.js.map +1 -1
  31. package/dist/app/builder/SaveDialog.d.ts +9 -1
  32. package/dist/app/builder/SaveDialog.d.ts.map +1 -1
  33. package/dist/app/builder/SaveDialog.js +8 -2
  34. package/dist/app/builder/SaveDialog.js.map +1 -1
  35. package/dist/app/builder/Toolbar.d.ts +12 -4
  36. package/dist/app/builder/Toolbar.d.ts.map +1 -1
  37. package/dist/app/builder/Toolbar.js +18 -7
  38. package/dist/app/builder/Toolbar.js.map +1 -1
  39. package/dist/app/builder/Workspace.d.ts +23 -3
  40. package/dist/app/builder/Workspace.d.ts.map +1 -1
  41. package/dist/app/builder/Workspace.js +58 -8
  42. package/dist/app/builder/Workspace.js.map +1 -1
  43. package/dist/app/builder/builder-model.d.ts +143 -1
  44. package/dist/app/builder/builder-model.d.ts.map +1 -1
  45. package/dist/app/builder/builder-model.js +191 -1
  46. package/dist/app/builder/builder-model.js.map +1 -1
  47. package/dist/app/builder/reveal.d.ts +10 -0
  48. package/dist/app/builder/reveal.d.ts.map +1 -0
  49. package/dist/app/builder/reveal.js +10 -0
  50. package/dist/app/builder/reveal.js.map +1 -0
  51. package/dist/app/builder/use-builder-catalogue.d.ts +4 -1
  52. package/dist/app/builder/use-builder-catalogue.d.ts.map +1 -1
  53. package/dist/app/builder/use-builder-catalogue.js +44 -17
  54. package/dist/app/builder/use-builder-catalogue.js.map +1 -1
  55. package/dist/app/builder/use-builder-session.d.ts +30 -0
  56. package/dist/app/builder/use-builder-session.d.ts.map +1 -0
  57. package/dist/app/builder/use-builder-session.js +58 -0
  58. package/dist/app/builder/use-builder-session.js.map +1 -0
  59. package/dist/app/builder/use-display-resolver.d.ts +17 -0
  60. package/dist/app/builder/use-display-resolver.d.ts.map +1 -0
  61. package/dist/app/builder/use-display-resolver.js +16 -0
  62. package/dist/app/builder/use-display-resolver.js.map +1 -0
  63. package/dist/app/index.d.ts +8 -3
  64. package/dist/app/index.d.ts.map +1 -1
  65. package/dist/app/index.js +8 -2
  66. package/dist/app/index.js.map +1 -1
  67. package/dist/app/layout-builder.d.ts +13 -25
  68. package/dist/app/layout-builder.d.ts.map +1 -1
  69. package/dist/app/layout-builder.js +75 -81
  70. package/dist/app/layout-builder.js.map +1 -1
  71. package/dist/app/mcp-app-view-chrome.d.ts +12 -3
  72. package/dist/app/mcp-app-view-chrome.d.ts.map +1 -1
  73. package/dist/app/mcp-app-view-chrome.js +21 -5
  74. package/dist/app/mcp-app-view-chrome.js.map +1 -1
  75. package/dist/app/mcp-app-view-states.d.ts +11 -3
  76. package/dist/app/mcp-app-view-states.d.ts.map +1 -1
  77. package/dist/app/mcp-app-view-states.js +29 -8
  78. package/dist/app/mcp-app-view-states.js.map +1 -1
  79. package/dist/app/mcp-app-view.d.ts +33 -1
  80. package/dist/app/mcp-app-view.d.ts.map +1 -1
  81. package/dist/app/mcp-app-view.js +181 -127
  82. package/dist/app/mcp-app-view.js.map +1 -1
  83. package/dist/app/mcp-toolkit-app.d.ts +6 -1
  84. package/dist/app/mcp-toolkit-app.d.ts.map +1 -1
  85. package/dist/app/mcp-toolkit-app.js +8 -1
  86. package/dist/app/mcp-toolkit-app.js.map +1 -1
  87. package/dist/app/mcp-use-host-bridge.d.ts +15 -6
  88. package/dist/app/mcp-use-host-bridge.d.ts.map +1 -1
  89. package/dist/app/mcp-use-host-bridge.js +51 -22
  90. package/dist/app/mcp-use-host-bridge.js.map +1 -1
  91. package/dist/app/model-context.d.ts +71 -0
  92. package/dist/app/model-context.d.ts.map +1 -0
  93. package/dist/app/model-context.js +101 -0
  94. package/dist/app/model-context.js.map +1 -0
  95. package/dist/app/use-build-mode-focus.d.ts +33 -0
  96. package/dist/app/use-build-mode-focus.d.ts.map +1 -0
  97. package/dist/app/use-build-mode-focus.js +59 -0
  98. package/dist/app/use-build-mode-focus.js.map +1 -0
  99. package/dist/app/use-view-actions.d.ts +31 -0
  100. package/dist/app/use-view-actions.d.ts.map +1 -0
  101. package/dist/app/use-view-actions.js +81 -0
  102. package/dist/app/use-view-actions.js.map +1 -0
  103. package/dist/app/use-view-lifecycle.d.ts +4 -0
  104. package/dist/app/use-view-lifecycle.d.ts.map +1 -1
  105. package/dist/app/use-view-lifecycle.js +2 -0
  106. package/dist/app/use-view-lifecycle.js.map +1 -1
  107. package/dist/app/view-lifecycle.d.ts +80 -4
  108. package/dist/app/view-lifecycle.d.ts.map +1 -1
  109. package/dist/app/view-lifecycle.js +90 -3
  110. package/dist/app/view-lifecycle.js.map +1 -1
  111. package/dist/app/widget-fixture.d.ts +10 -3
  112. package/dist/app/widget-fixture.d.ts.map +1 -1
  113. package/dist/app/widget-fixture.js +21 -8
  114. package/dist/app/widget-fixture.js.map +1 -1
  115. package/dist/app/widget-props-sheet.d.ts +3 -1
  116. package/dist/app/widget-props-sheet.d.ts.map +1 -1
  117. package/dist/app/widget-props-sheet.js +22 -10
  118. package/dist/app/widget-props-sheet.js.map +1 -1
  119. package/dist/app/widget-renderer.js +1 -1
  120. package/dist/app/widget-renderer.js.map +1 -1
  121. package/dist/components/DrillButton.d.ts +9 -6
  122. package/dist/components/DrillButton.d.ts.map +1 -1
  123. package/dist/components/DrillButton.js +8 -6
  124. package/dist/components/DrillButton.js.map +1 -1
  125. package/dist/components/EmptyState.d.ts.map +1 -1
  126. package/dist/components/EmptyState.js +4 -2
  127. package/dist/components/EmptyState.js.map +1 -1
  128. package/dist/components/ErrorState.d.ts +5 -2
  129. package/dist/components/ErrorState.d.ts.map +1 -1
  130. package/dist/components/ErrorState.js +25 -8
  131. package/dist/components/ErrorState.js.map +1 -1
  132. package/dist/components/FilterBar.d.ts +15 -4
  133. package/dist/components/FilterBar.d.ts.map +1 -1
  134. package/dist/components/FilterBar.js +11 -6
  135. package/dist/components/FilterBar.js.map +1 -1
  136. package/dist/components/KpiGrid.d.ts +66 -21
  137. package/dist/components/KpiGrid.d.ts.map +1 -1
  138. package/dist/components/KpiGrid.js +101 -34
  139. package/dist/components/KpiGrid.js.map +1 -1
  140. package/dist/components/ListFooter.d.ts +31 -4
  141. package/dist/components/ListFooter.d.ts.map +1 -1
  142. package/dist/components/ListFooter.js +30 -11
  143. package/dist/components/ListFooter.js.map +1 -1
  144. package/dist/components/PagedListFooter.d.ts +57 -0
  145. package/dist/components/PagedListFooter.d.ts.map +1 -0
  146. package/dist/components/PagedListFooter.js +27 -0
  147. package/dist/components/PagedListFooter.js.map +1 -0
  148. package/dist/components/Pills.d.ts +27 -7
  149. package/dist/components/Pills.d.ts.map +1 -1
  150. package/dist/components/Pills.js +21 -6
  151. package/dist/components/Pills.js.map +1 -1
  152. package/dist/components/SectionHeading.d.ts +3 -1
  153. package/dist/components/SectionHeading.d.ts.map +1 -1
  154. package/dist/components/SectionHeading.js +6 -2
  155. package/dist/components/SectionHeading.js.map +1 -1
  156. package/dist/components/Toast.d.ts +9 -3
  157. package/dist/components/Toast.d.ts.map +1 -1
  158. package/dist/components/Toast.js +31 -16
  159. package/dist/components/Toast.js.map +1 -1
  160. package/dist/components/WidgetHeader.d.ts +34 -10
  161. package/dist/components/WidgetHeader.d.ts.map +1 -1
  162. package/dist/components/WidgetHeader.js +11 -6
  163. package/dist/components/WidgetHeader.js.map +1 -1
  164. package/dist/hooks/index.d.ts +4 -4
  165. package/dist/hooks/index.d.ts.map +1 -1
  166. package/dist/hooks/index.js +1 -1
  167. package/dist/hooks/index.js.map +1 -1
  168. package/dist/hooks/tool-result-recovery-model.d.ts +155 -0
  169. package/dist/hooks/tool-result-recovery-model.d.ts.map +1 -0
  170. package/dist/hooks/tool-result-recovery-model.js +273 -0
  171. package/dist/hooks/tool-result-recovery-model.js.map +1 -0
  172. package/dist/hooks/use-tool-query.d.ts +56 -14
  173. package/dist/hooks/use-tool-query.d.ts.map +1 -1
  174. package/dist/hooks/use-tool-query.js +102 -25
  175. package/dist/hooks/use-tool-query.js.map +1 -1
  176. package/dist/hooks/use-tool-result-recovery.d.ts +47 -52
  177. package/dist/hooks/use-tool-result-recovery.d.ts.map +1 -1
  178. package/dist/hooks/use-tool-result-recovery.js +58 -120
  179. package/dist/hooks/use-tool-result-recovery.js.map +1 -1
  180. package/dist/hooks/use-view-data.d.ts +52 -10
  181. package/dist/hooks/use-view-data.d.ts.map +1 -1
  182. package/dist/hooks/use-view-data.js +81 -16
  183. package/dist/hooks/use-view-data.js.map +1 -1
  184. package/dist/hooks/use-view-tool-query.d.ts +12 -7
  185. package/dist/hooks/use-view-tool-query.d.ts.map +1 -1
  186. package/dist/hooks/use-view-tool-query.js +15 -14
  187. package/dist/hooks/use-view-tool-query.js.map +1 -1
  188. package/dist/index.d.ts +17 -10
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +18 -6
  191. package/dist/index.js.map +1 -1
  192. package/dist/lib/focus-return.d.ts +61 -0
  193. package/dist/lib/focus-return.d.ts.map +1 -0
  194. package/dist/lib/focus-return.js +46 -0
  195. package/dist/lib/focus-return.js.map +1 -0
  196. package/dist/lib/parse-tool-result.d.ts +23 -1
  197. package/dist/lib/parse-tool-result.d.ts.map +1 -1
  198. package/dist/lib/parse-tool-result.js +38 -2
  199. package/dist/lib/parse-tool-result.js.map +1 -1
  200. package/dist/lib/toast-model.d.ts +41 -1
  201. package/dist/lib/toast-model.d.ts.map +1 -1
  202. package/dist/lib/toast-model.js +67 -1
  203. package/dist/lib/toast-model.js.map +1 -1
  204. package/dist/lib/tone-utils.d.ts +58 -6
  205. package/dist/lib/tone-utils.d.ts.map +1 -1
  206. package/dist/lib/tone-utils.js +66 -4
  207. package/dist/lib/tone-utils.js.map +1 -1
  208. package/dist/lib/tool-query.d.ts +107 -0
  209. package/dist/lib/tool-query.d.ts.map +1 -0
  210. package/dist/lib/tool-query.js +182 -0
  211. package/dist/lib/tool-query.js.map +1 -0
  212. package/dist/lib/tool-result-observer.d.ts +108 -0
  213. package/dist/lib/tool-result-observer.d.ts.map +1 -0
  214. package/dist/lib/tool-result-observer.js +158 -0
  215. package/dist/lib/tool-result-observer.js.map +1 -0
  216. package/dist/lib/typography.d.ts +37 -0
  217. package/dist/lib/typography.d.ts.map +1 -0
  218. package/dist/lib/typography.js +41 -0
  219. package/dist/lib/typography.js.map +1 -0
  220. package/dist/lib/utils.d.ts.map +1 -1
  221. package/dist/lib/utils.js +11 -1
  222. package/dist/lib/utils.js.map +1 -1
  223. package/dist/locale/index.d.ts +1 -1
  224. package/dist/locale/index.d.ts.map +1 -1
  225. package/dist/locale/message-types.d.ts +117 -4
  226. package/dist/locale/message-types.d.ts.map +1 -1
  227. package/dist/locale/messages-de.d.ts.map +1 -1
  228. package/dist/locale/messages-de.js +44 -10
  229. package/dist/locale/messages-de.js.map +1 -1
  230. package/dist/locale/messages-en.d.ts.map +1 -1
  231. package/dist/locale/messages-en.js +44 -10
  232. package/dist/locale/messages-en.js.map +1 -1
  233. package/dist/locale/toolkit-messages.d.ts +19 -1
  234. package/dist/locale/toolkit-messages.d.ts.map +1 -1
  235. package/dist/locale/toolkit-messages.js +54 -1
  236. package/dist/locale/toolkit-messages.js.map +1 -1
  237. package/dist/primitives/alert.d.ts +1 -1
  238. package/dist/primitives/alert.d.ts.map +1 -1
  239. package/dist/primitives/alert.js +2 -0
  240. package/dist/primitives/alert.js.map +1 -1
  241. package/dist/primitives/badge.d.ts +1 -1
  242. package/dist/primitives/badge.d.ts.map +1 -1
  243. package/dist/primitives/badge.js +9 -4
  244. package/dist/primitives/badge.js.map +1 -1
  245. package/dist/primitives/button.d.ts +1 -1
  246. package/dist/primitives/button.js +1 -1
  247. package/dist/primitives/button.js.map +1 -1
  248. package/dist/primitives/dialog.d.ts +1 -1
  249. package/dist/primitives/dialog.d.ts.map +1 -1
  250. package/dist/primitives/dialog.js +10 -3
  251. package/dist/primitives/dialog.js.map +1 -1
  252. package/dist/primitives/select.js +1 -1
  253. package/dist/primitives/select.js.map +1 -1
  254. package/dist/primitives/sheet.d.ts +1 -1
  255. package/dist/primitives/sheet.d.ts.map +1 -1
  256. package/dist/primitives/sheet.js +6 -2
  257. package/dist/primitives/sheet.js.map +1 -1
  258. package/dist/providers/query-provider.d.ts +32 -1
  259. package/dist/providers/query-provider.d.ts.map +1 -1
  260. package/dist/providers/query-provider.js +53 -4
  261. package/dist/providers/query-provider.js.map +1 -1
  262. package/dist/render-cases-primitives.js +1 -1
  263. package/dist/render-cases-primitives.js.map +1 -1
  264. package/dist/render-cases.d.ts.map +1 -1
  265. package/dist/render-cases.js +30 -6
  266. package/dist/render-cases.js.map +1 -1
  267. package/dist/render-effects.d.ts +42 -0
  268. package/dist/render-effects.d.ts.map +1 -0
  269. package/dist/render-effects.js +81 -0
  270. package/dist/render-effects.js.map +1 -0
  271. package/dist/theme/create-theme.d.ts +19 -1
  272. package/dist/theme/create-theme.d.ts.map +1 -1
  273. package/dist/theme/create-theme.js +15 -0
  274. package/dist/theme/create-theme.js.map +1 -1
  275. package/package.json +5 -4
  276. package/src/app/adapt-data-widget.tsx +2 -42
  277. package/src/app/builder/BuilderBanners.tsx +1 -1
  278. package/src/app/builder/CanvasRow.tsx +63 -17
  279. package/src/app/builder/CatalogueSheet.tsx +50 -29
  280. package/src/app/builder/CellPropsSheet.tsx +17 -2
  281. package/src/app/builder/DiscardDialog.tsx +59 -0
  282. package/src/app/builder/LayoutSurface.tsx +206 -66
  283. package/src/app/builder/PipelineStrip.tsx +253 -153
  284. package/src/app/builder/SaveDialog.tsx +14 -2
  285. package/src/app/builder/Toolbar.tsx +144 -59
  286. package/src/app/builder/Workspace.tsx +226 -58
  287. package/src/app/builder/builder-model.ts +341 -2
  288. package/src/app/builder/builder-model.ux.test.ts +456 -0
  289. package/src/app/builder/builder-ux.test.tsx +844 -0
  290. package/src/app/builder/reveal.ts +10 -0
  291. package/src/app/builder/use-builder-catalogue.ts +56 -19
  292. package/src/app/builder/use-builder-session.ts +68 -0
  293. package/src/app/builder/use-display-resolver.ts +24 -0
  294. package/src/app/index.ts +12 -2
  295. package/src/app/layout-builder.tsx +178 -191
  296. package/src/app/mcp-app-view-chrome.test.tsx +141 -1
  297. package/src/app/mcp-app-view-chrome.tsx +56 -6
  298. package/src/app/mcp-app-view-states.tsx +51 -11
  299. package/src/app/mcp-app-view.effects.test.tsx +292 -0
  300. package/src/app/mcp-app-view.test.tsx +222 -2
  301. package/src/app/mcp-app-view.tsx +267 -117
  302. package/src/app/mcp-toolkit-app.test.tsx +40 -0
  303. package/src/app/mcp-toolkit-app.tsx +8 -1
  304. package/src/app/mcp-use-host-bridge.test.tsx +180 -0
  305. package/src/app/mcp-use-host-bridge.tsx +67 -24
  306. package/src/app/model-context.test.tsx +116 -0
  307. package/src/app/model-context.tsx +125 -0
  308. package/src/app/use-build-mode-focus.ts +62 -0
  309. package/src/app/use-view-actions.ts +89 -0
  310. package/src/app/use-view-lifecycle.ts +6 -0
  311. package/src/app/view-lifecycle.test.ts +216 -0
  312. package/src/app/view-lifecycle.ts +165 -5
  313. package/src/app/widget-fixture.effects.test.tsx +51 -0
  314. package/src/app/widget-fixture.render.test.tsx +81 -0
  315. package/src/app/widget-fixture.tsx +34 -11
  316. package/src/app/widget-props-sheet.tsx +57 -16
  317. package/src/app/widget-renderer.tsx +1 -1
  318. package/src/components/DrillButton.tsx +23 -10
  319. package/src/components/EmptyState.tsx +6 -4
  320. package/src/components/ErrorState.tsx +31 -9
  321. package/src/components/FilterBar.test.tsx +82 -0
  322. package/src/components/FilterBar.tsx +52 -26
  323. package/src/components/KpiGrid.test.tsx +279 -0
  324. package/src/components/KpiGrid.tsx +297 -90
  325. package/src/components/ListFooter.test.tsx +116 -0
  326. package/src/components/ListFooter.tsx +102 -15
  327. package/src/components/PagedListFooter.test.tsx +140 -0
  328. package/src/components/PagedListFooter.tsx +107 -0
  329. package/src/components/Pills.test.tsx +77 -0
  330. package/src/components/Pills.tsx +63 -10
  331. package/src/components/SectionHeading.tsx +9 -3
  332. package/src/components/Toast.tsx +37 -19
  333. package/src/components/WidgetHeader.test.tsx +78 -0
  334. package/src/components/WidgetHeader.tsx +63 -16
  335. package/src/components/feedback-states.test.tsx +98 -9
  336. package/src/components/tone-figures.test.tsx +8 -4
  337. package/src/hooks/index.ts +6 -3
  338. package/src/hooks/tool-result-recovery-model.test.ts +744 -0
  339. package/src/hooks/tool-result-recovery-model.ts +418 -0
  340. package/src/hooks/use-tool-query.effects.test.tsx +205 -0
  341. package/src/hooks/use-tool-query.ts +156 -33
  342. package/src/hooks/use-tool-result-recovery.effects.test.tsx +141 -0
  343. package/src/hooks/use-tool-result-recovery.test.ts +3 -4
  344. package/src/hooks/use-tool-result-recovery.ts +84 -142
  345. package/src/hooks/use-view-data.test.tsx +118 -9
  346. package/src/hooks/use-view-data.ts +128 -18
  347. package/src/hooks/use-view-tool-query.ts +25 -19
  348. package/src/i18n-coverage.test.tsx +104 -2
  349. package/src/index.ts +48 -11
  350. package/src/lib/focus-return.test.ts +288 -0
  351. package/src/lib/focus-return.ts +96 -0
  352. package/src/lib/parse-tool-result.test.ts +46 -1
  353. package/src/lib/parse-tool-result.ts +40 -2
  354. package/src/lib/toast-model.test.ts +166 -1
  355. package/src/lib/toast-model.ts +104 -2
  356. package/src/lib/tone-utils.test.ts +86 -10
  357. package/src/lib/tone-utils.ts +89 -8
  358. package/src/lib/tool-query.test.ts +569 -0
  359. package/src/lib/tool-query.ts +253 -0
  360. package/src/lib/tool-result-observer.test.ts +296 -0
  361. package/src/lib/tool-result-observer.ts +211 -0
  362. package/src/lib/typography.test.ts +45 -0
  363. package/src/lib/typography.ts +47 -0
  364. package/src/lib/utils.ts +12 -1
  365. package/src/locale/index.ts +1 -0
  366. package/src/locale/message-types.ts +118 -2
  367. package/src/locale/messages-de.ts +49 -10
  368. package/src/locale/messages-en.ts +49 -10
  369. package/src/locale/toolkit-messages.test.ts +133 -0
  370. package/src/locale/toolkit-messages.ts +63 -2
  371. package/src/primitives/alert.tsx +3 -0
  372. package/src/primitives/badge.tsx +9 -4
  373. package/src/primitives/button.tsx +1 -1
  374. package/src/primitives/dialog.tsx +10 -1
  375. package/src/primitives/select.tsx +1 -1
  376. package/src/primitives/sheet.tsx +7 -0
  377. package/src/providers/query-provider.test.tsx +154 -0
  378. package/src/providers/query-provider.tsx +66 -5
  379. package/src/render-cases-primitives.tsx +1 -1
  380. package/src/render-cases.tsx +38 -6
  381. package/src/render-effects.tsx +96 -0
  382. package/src/theme/cd-tokens.test.ts +3 -1
  383. package/src/theme/create-theme.test.ts +10 -0
  384. package/src/theme/create-theme.ts +28 -0
  385. package/src/theme/theme-css.test.ts +51 -0
  386. package/src/theme.css +31 -1
  387. package/ui-catalog.json +448 -41
@@ -1 +1 @@
1
- {"version":3,"file":"toast-model.js","sourceRoot":"","sources":["../../src/lib/toast-model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH,wDAAwD;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAA;AACrC,sFAAsF;AACtF,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAC3C,+DAA+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAA;AAEnC,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,IAAe,EAAE,QAAiB;IAC9D,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAA;IACxF,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,iBAAiB,CAAA;AACxE,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,WAAW,CAAC,EAAU,EAAE,OAAqB;IAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,CAAA;IACnC,OAAO;QACL,EAAE;QACF,IAAI;QACJ,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,QAAQ,EAAE,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC;KAChD,CAAA;AACH,CAAC;AAID,kG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AO;QACL,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACf,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACjB,KAAK,EAAE,CAAA;QACT,CAAC;QACD,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;YAClB,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YACpB,KAAK,EAAE,CAAA;QACT,CAAC;QACD,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,EAAE,EAAE,CAAC,CAAC;QAC9C,MAAM,EAAE,GAAG,EAAE;YACX,KAAK,EAAE,CAAA;YACP,QAAQ,GAAG,IAAI,CAAA;QACjB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * Single source of truth for the semantic "tones" used across the tone-aware
3
- * components (`Pills`, `KpiGrid`, `WidgetHeader`, `Badge`, …).
3
+ * components (`Pills`, `StatusBadge`, `KpiGrid`, `Badge`, …).
4
+ *
5
+ * ONE vocabulary: `success | warning | danger | info | neutral`
6
+ * ({@link TONE_VARIANTS}). Retired or foreign names (`critical`, `error`,
7
+ * `destructive`, …) map onto it through {@link resolveTone}, so a tone that
8
+ * arrives as data (a server-built KPI cell) never renders without a colour.
4
9
  *
5
10
  * Every status tone has THREE roles (Miragon CI §3.3), each its own token in
6
11
  * `theme.css` with light and dark values:
@@ -8,14 +13,14 @@
8
13
  * | Role | Token | Map |
9
14
  * | ---------------------------- | --------------- | -------------- |
10
15
  * | fill, dot, border, icon | `--<tone>` | `TONE_DOT`, `TONE_BORDER`, `TONE_ICON` |
11
- * | tint (badge/banner surface) | `--<tone>-soft` | `TONE_SOFT` (text on it: the foreground) |
12
- * | text on a plain surface | `--<tone>-ink` | `TONE_TEXT` |
16
+ * | tint (badge/banner surface) | `--<tone>-soft` | `TONE_SOFT`, `TONE_TINT` (text on it: the foreground) |
17
+ * | text on a plain surface | `--<tone>-ink` | `TONE_INK` |
13
18
  *
14
19
  * Status is never text in its own colour: success and warning reach only
15
20
  * 1.67:1 / 1.83:1 on white, so their ink is the foreground and the tone shows
16
21
  * as a dot, icon or border NEXT to the text. On a tint the text is always the
17
22
  * foreground (CI §3.3: "-soft: Text darauf --cd-schwarz, Rand in der
18
- * Statusfarbe"), so pair `TONE_SOFT` with `TONE_BORDER`. `TONE_TEXT` is for
23
+ * Statusfarbe"), so pair `TONE_SOFT` with `TONE_BORDER`. `TONE_INK` is for
19
24
  * a tone's words on a plain surface (a field error); figures — counts, KPI
20
25
  * values, trends — never take it: they stay in the foreground next to a
21
26
  * `TONE_DOT`. In dark mode the colours are the `-hell` values and the tints
@@ -26,13 +31,55 @@
26
31
  * `tone === "x" ? "…" : "…"` ternaries at every call site.
27
32
  */
28
33
  export type ToneVariant = "neutral" | "info" | "success" | "warning" | "danger";
34
+ /** Every tone, in severity order (for loops, pickers and validation). */
35
+ export declare const TONE_VARIANTS: readonly ToneVariant[];
36
+ /**
37
+ * Retired or foreign tone names and the tone each one means. One red and one
38
+ * amber (CI §3.3): `critical`, `error` and `destructive` are `danger`; there
39
+ * is no separate severity above it. The names on the left are deprecated:
40
+ * write the {@link ToneVariant} on the right. The map stays so data written
41
+ * against an older vocabulary (a widget-shell `critical`, a shadcn
42
+ * `destructive`) keeps its colour.
43
+ */
44
+ export declare const TONE_ALIASES: {
45
+ readonly critical: "danger";
46
+ readonly error: "danger";
47
+ readonly destructive: "danger";
48
+ readonly failure: "danger";
49
+ readonly warn: "warning";
50
+ readonly ok: "success";
51
+ readonly positive: "success";
52
+ readonly notice: "info";
53
+ readonly default: "neutral";
54
+ readonly muted: "neutral";
55
+ readonly secondary: "neutral";
56
+ };
57
+ /** A name {@link resolveTone} maps onto a tone (see {@link TONE_ALIASES}). */
58
+ export type ToneAlias = keyof typeof TONE_ALIASES;
59
+ /**
60
+ * What a tone-aware component accepts: a {@link ToneVariant}, or a retired
61
+ * name that {@link resolveTone} maps onto one.
62
+ */
63
+ export type ToneName = ToneVariant | ToneAlias;
64
+ /** Whether `value` is one of the five tones (a type guard for data from the wire). */
65
+ export declare function isToneVariant(value: unknown): value is ToneVariant;
66
+ /**
67
+ * Map any tone name onto the vocabulary: a {@link ToneVariant} as is, a
68
+ * retired name ({@link TONE_ALIASES}, case-insensitive) onto its tone, and
69
+ * anything else — unknown, empty, not a string — onto `fallback` (default
70
+ * `"neutral"`, the tone without a state).
71
+ */
72
+ export declare function resolveTone(name: unknown, fallback?: ToneVariant): ToneVariant;
29
73
  /**
30
74
  * Tinted surface + its text (the foreground: CI §3.3) — badges, pills,
31
75
  * banners. Pair it with {@link TONE_BORDER}: the rim carries the tone, and in
32
- * dark mode (no tints) it is all that does.
76
+ * dark mode (no tints) it is all that does. The neutral tint is the muted
77
+ * surface, its text the foreground too (a count on it is a figure).
33
78
  */
34
79
  export declare const TONE_SOFT: Record<ToneVariant, string>;
35
- /** Solid dot colour — a status dot next to a label. */
80
+ /** The tint alone, for a surface that sets its text itself (a soft KPI card). */
81
+ export declare const TONE_TINT: Record<ToneVariant, string>;
82
+ /** Solid dot colour — a status dot next to a label, a bar, a meter fill. */
36
83
  export declare const TONE_DOT: Record<ToneVariant, string>;
37
84
  /**
38
85
  * The tone's TEXT colour (its `-ink` role) for words on a plain surface — a
@@ -41,6 +88,11 @@ export declare const TONE_DOT: Record<ToneVariant, string>;
41
88
  * {@link TONE_ICON} to show the tone. Never on a tint (use {@link TONE_SOFT})
42
89
  * and never for figures (they stay in the foreground next to a dot).
43
90
  */
91
+ export declare const TONE_INK: Record<ToneVariant, string>;
92
+ /**
93
+ * @deprecated Renamed to {@link TONE_INK} after the role it maps onto
94
+ * (`--<tone>-ink`); the same object, kept for existing imports.
95
+ */
44
96
  export declare const TONE_TEXT: Record<ToneVariant, string>;
45
97
  /** Border colour in the tone — the rim of a tinted badge, banner or toast. */
46
98
  export declare const TONE_BORDER: Record<ToneVariant, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"tone-utils.d.ts","sourceRoot":"","sources":["../../src/lib/tone-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE/E;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA;AAED,uDAAuD;AACvD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMhD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA;AAED,8EAA8E;AAC9E,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMnD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA"}
1
+ {"version":3,"file":"tone-utils.d.ts","sourceRoot":"","sources":["../../src/lib/tone-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE/E,yEAAyE;AACzE,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAM/C,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;CAYuB,CAAA;AAEhD,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,YAAY,CAAA;AAEjD;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAA;AAI9C,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,GAAE,WAAuB,GAAG,WAAW,CAKzF;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA;AAED,iFAAiF;AACjF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA;AAED,4EAA4E;AAC5E,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMhD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMhD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAY,CAAA;AAE9D,8EAA8E;AAC9E,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMnD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA"}
@@ -1,16 +1,73 @@
1
+ /** Every tone, in severity order (for loops, pickers and validation). */
2
+ export const TONE_VARIANTS = [
3
+ "danger",
4
+ "warning",
5
+ "success",
6
+ "info",
7
+ "neutral",
8
+ ];
9
+ /**
10
+ * Retired or foreign tone names and the tone each one means. One red and one
11
+ * amber (CI §3.3): `critical`, `error` and `destructive` are `danger`; there
12
+ * is no separate severity above it. The names on the left are deprecated:
13
+ * write the {@link ToneVariant} on the right. The map stays so data written
14
+ * against an older vocabulary (a widget-shell `critical`, a shadcn
15
+ * `destructive`) keeps its colour.
16
+ */
17
+ export const TONE_ALIASES = {
18
+ critical: "danger",
19
+ error: "danger",
20
+ destructive: "danger",
21
+ failure: "danger",
22
+ warn: "warning",
23
+ ok: "success",
24
+ positive: "success",
25
+ notice: "info",
26
+ default: "neutral",
27
+ muted: "neutral",
28
+ secondary: "neutral",
29
+ };
30
+ const TONE_SET = new Set(TONE_VARIANTS);
31
+ /** Whether `value` is one of the five tones (a type guard for data from the wire). */
32
+ export function isToneVariant(value) {
33
+ return typeof value === "string" && TONE_SET.has(value);
34
+ }
35
+ /**
36
+ * Map any tone name onto the vocabulary: a {@link ToneVariant} as is, a
37
+ * retired name ({@link TONE_ALIASES}, case-insensitive) onto its tone, and
38
+ * anything else — unknown, empty, not a string — onto `fallback` (default
39
+ * `"neutral"`, the tone without a state).
40
+ */
41
+ export function resolveTone(name, fallback = "neutral") {
42
+ if (typeof name !== "string")
43
+ return fallback;
44
+ const key = name.trim().toLowerCase();
45
+ if (TONE_SET.has(key))
46
+ return key;
47
+ return Object.hasOwn(TONE_ALIASES, key) ? TONE_ALIASES[key] : fallback;
48
+ }
1
49
  /**
2
50
  * Tinted surface + its text (the foreground: CI §3.3) — badges, pills,
3
51
  * banners. Pair it with {@link TONE_BORDER}: the rim carries the tone, and in
4
- * dark mode (no tints) it is all that does.
52
+ * dark mode (no tints) it is all that does. The neutral tint is the muted
53
+ * surface, its text the foreground too (a count on it is a figure).
5
54
  */
6
55
  export const TONE_SOFT = {
7
- neutral: "bg-muted text-muted-foreground",
56
+ neutral: "bg-muted text-foreground",
8
57
  info: "bg-info-soft text-foreground",
9
58
  success: "bg-success-soft text-foreground",
10
59
  warning: "bg-warning-soft text-foreground",
11
60
  danger: "bg-danger-soft text-foreground",
12
61
  };
13
- /** Solid dot colour — a status dot next to a label. */
62
+ /** The tint alone, for a surface that sets its text itself (a soft KPI card). */
63
+ export const TONE_TINT = {
64
+ neutral: "bg-muted",
65
+ info: "bg-info-soft",
66
+ success: "bg-success-soft",
67
+ warning: "bg-warning-soft",
68
+ danger: "bg-danger-soft",
69
+ };
70
+ /** Solid dot colour — a status dot next to a label, a bar, a meter fill. */
14
71
  export const TONE_DOT = {
15
72
  neutral: "bg-muted-foreground",
16
73
  info: "bg-info",
@@ -25,13 +82,18 @@ export const TONE_DOT = {
25
82
  * {@link TONE_ICON} to show the tone. Never on a tint (use {@link TONE_SOFT})
26
83
  * and never for figures (they stay in the foreground next to a dot).
27
84
  */
28
- export const TONE_TEXT = {
85
+ export const TONE_INK = {
29
86
  neutral: "text-foreground",
30
87
  info: "text-info-ink",
31
88
  success: "text-success-ink",
32
89
  warning: "text-warning-ink",
33
90
  danger: "text-danger-ink",
34
91
  };
92
+ /**
93
+ * @deprecated Renamed to {@link TONE_INK} after the role it maps onto
94
+ * (`--<tone>-ink`); the same object, kept for existing imports.
95
+ */
96
+ export const TONE_TEXT = TONE_INK;
35
97
  /** Border colour in the tone — the rim of a tinted badge, banner or toast. */
36
98
  export const TONE_BORDER = {
37
99
  neutral: "border-border",
@@ -1 +1 @@
1
- {"version":3,"file":"tone-utils.js","sourceRoot":"","sources":["../../src/lib/tone-utils.ts"],"names":[],"mappings":"AA6BA;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAgC;IACpD,OAAO,EAAE,gCAAgC;IACzC,IAAI,EAAE,8BAA8B;IACpC,OAAO,EAAE,iCAAiC;IAC1C,OAAO,EAAE,iCAAiC;IAC1C,MAAM,EAAE,gCAAgC;CACzC,CAAA;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,QAAQ,GAAgC;IACnD,OAAO,EAAE,qBAAqB;IAC9B,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAgC;IACpD,OAAO,EAAE,iBAAiB;IAC1B,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,kBAAkB;IAC3B,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,iBAAiB;CAC1B,CAAA;AAED,8EAA8E;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAgC;IACtD,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,gBAAgB;I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AGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAgC;IACpD,OAAO,EAAE,uBAAuB;IAChC,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,cAAc;IACvB,MAAM,EAAE,aAAa;CACtB,CAAA"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The plain logic behind `useToolQuery`, `useViewToolQuery`, `useViewData`
3
+ * and `useToolMutation` (toolkit#176 K18): the effective cache key and its
4
+ * collision guard, the opt-in retry policy for tool errors, the TanStack
5
+ * options a tool query runs with, and per-call mutation callbacks that fire
6
+ * for EVERY call. No React, no `mcp-use/react`, so it is unit-tested without
7
+ * a renderer.
8
+ */
9
+ import { type MutateOptions, type MutationFunctionContext, type QueryClient, type UseQueryOptions } from "@tanstack/react-query";
10
+ /** A `(name, args)` tool caller — the shape of `useCallTool()` and `HostBridge.callTool`. */
11
+ export type ToolCaller = (name: string, args: object) => Promise<unknown>;
12
+ /**
13
+ * TanStack query options a tool query passes through: everything except the
14
+ * key and the fetcher, which the hooks build from the tool and its args
15
+ * (`retry`, `retryDelay`, `staleTime`, `placeholderData` / `keepPreviousData`,
16
+ * `initialData` + `initialDataUpdatedAt`, `enabled`, `select`, …).
17
+ */
18
+ export type UseToolQueryOptions<TData = unknown, TSelected = TData> = Omit<UseQueryOptions<TData, Error, TSelected>, "queryKey" | "queryFn">;
19
+ /**
20
+ * Neither an `AppQueryProvider` `callTool` nor a `HostBridgeProvider` is in
21
+ * reach, so the query cannot call any tool. Never retried: nothing changes
22
+ * until the mount does.
23
+ */
24
+ export declare class NoToolTransportError extends Error {
25
+ constructor(toolName: string);
26
+ }
27
+ /** Retries {@link shouldRetryToolCall} grants a failed transport (TanStack's own default count). */
28
+ export declare const TOOL_QUERY_RETRIES = 3;
29
+ /**
30
+ * A retry policy for tool queries: up to {@link TOOL_QUERY_RETRIES} retries
31
+ * for a failed transport, none for a tool's own `isError` answer
32
+ * (`isToolError`) or a missing transport — repeating a deterministic answer
33
+ * only repeats it and holds the error back about 7 s.
34
+ *
35
+ * Opt-in in 2.x (the hooks keep the client's `retry`, TanStack's 3 by
36
+ * default, because a tool may also answer a transient failure with
37
+ * `isError`): pass `retry: shouldRetryToolCall` to a hook, or set it as the
38
+ * client's default (`queryClient.setDefaultOptions`, or an `AppQueryProvider`
39
+ * `client` of your own).
40
+ */
41
+ export declare function shouldRetryToolCall(failureCount: number, error: unknown): boolean;
42
+ /**
43
+ * The effective cache key of a tool query (toolkit#176 K18).
44
+ *
45
+ * - 2.x default: the caller's key, then the args (`[...queryKey, args]`), so
46
+ * two callers sharing a key with different args get separate entries.
47
+ * - `toolNameInKey`: the caller's key, the tool name, then the args
48
+ * (`[...queryKey, toolName, args]`), so two tools never share an entry,
49
+ * whatever key their callers pass. Opt-in in 2.x (`AppQueryProvider` /
50
+ * `McpAppView` `toolNameInQueryKey`), the default from the next major.
51
+ *
52
+ * Build exact keys (`getQueryData`, `setQueryData`, `cancelQueries` with
53
+ * `exact: true`) with this helper, or with `useToolQueryKey`, which reads the
54
+ * provider's setting, rather than by hand: code that goes through them keeps
55
+ * working when the default changes. Prefix invalidation by `queryKey`
56
+ * matches either way.
57
+ */
58
+ export declare function toolQueryKey(queryKey: readonly unknown[], toolName: string, args: object, toolNameInKey?: boolean): unknown[];
59
+ /**
60
+ * Claim the cache key `keyId` (`hashKey` of a {@link toolQueryKey}) for
61
+ * `toolName` on `client`. Returns the tool that held it
62
+ * before when that is ANOTHER tool — a collision the hooks report — else
63
+ * `null`. The latest claim wins, so each collision is reported once per
64
+ * switch.
65
+ */
66
+ export declare function claimToolQueryKey(client: QueryClient, keyId: string, toolName: string): string | null;
67
+ /** The console line for a {@link claimToolQueryKey} collision. */
68
+ export declare function toolKeyCollisionMessage(keyId: string, toolName: string, previous: string): string;
69
+ /** How {@link toolQueryOptions} decodes a result and builds the key. */
70
+ export interface ToolQueryBuild<TData> {
71
+ /** Decodes the tool result. Default: `parseToolResult` (structured-first). */
72
+ decode?: (result: unknown) => TData;
73
+ /** Put the tool name into the key (see {@link toolQueryKey}). Default `false`. */
74
+ toolNameInKey?: boolean;
75
+ }
76
+ /**
77
+ * The TanStack options of a tool query: the caller's options, the
78
+ * {@link toolQueryKey} and a fetcher that calls `toolName` and decodes the
79
+ * result. `retry` stays the caller's, else the client's default; only a
80
+ * missing transport is never retried. Without a transport the fetcher fails
81
+ * with {@link NoToolTransportError} instead of leaving the query idle.
82
+ */
83
+ export declare function toolQueryOptions<TData, TSelected = TData>(queryKey: readonly unknown[], toolName: string, args: object, callTool: ToolCaller | undefined, opts?: UseToolQueryOptions<TData, TSelected>, build?: ToolQueryBuild<TData>): UseQueryOptions<TData, Error, TSelected>;
84
+ /**
85
+ * Seed `queryKey` with host-delivered `seed`: written when the entry is
86
+ * empty, or when the seed is a payload this client has not seeded for the
87
+ * key before (a new delivery). Returns whether the cache was written.
88
+ */
89
+ export declare function seedToolQuery(client: QueryClient, queryKey: readonly unknown[], seed: unknown, updatedAt?: number): boolean;
90
+ /** Callbacks of one `mutate` call, typed as TanStack's per-call options. */
91
+ export type PerCallCallbacks<TData, TVariables> = MutateOptions<TData, Error, TVariables, unknown>;
92
+ /**
93
+ * Fire one call's per-call `onSuccess` / `onError` / `onSettled` once `call`
94
+ * settles — for EVERY call. TanStack's own `mutate` keeps only the latest
95
+ * call's callbacks, so two quick calls (retrying two incidents in a row)
96
+ * would confirm only the second. `context()` is read when the call settles:
97
+ * `null` (the component unmounted) skips the callbacks, as TanStack does.
98
+ * A rejected `call` is handled here, never left unhandled.
99
+ */
100
+ export declare function settleEachCall<TData, TVariables>(call: Promise<TData>, variables: TVariables, callbacks: PerCallCallbacks<TData, TVariables> | undefined, context: () => MutationFunctionContext | null): void;
101
+ /**
102
+ * Invalidate the query keys (prefixes) a mutation names: matching ACTIVE
103
+ * queries refetch now, inactive ones are only marked stale and refetch when
104
+ * they are next used — never a refetch of every inactive cached page.
105
+ */
106
+ export declare function invalidateToolQueries(client: QueryClient, keys: readonly (readonly unknown[])[] | undefined): Promise<void>;
107
+ //# sourceMappingURL=tool-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-query.d.ts","sourceRoot":"","sources":["../../src/lib/tool-query.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAA;AAG9B,6FAA6F;AAC7F,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAEzE;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,GAAG,OAAO,EAAE,SAAS,GAAG,KAAK,IAAI,IAAI,CACxE,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,EACxC,UAAU,GAAG,SAAS,CACvB,CAAA;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,QAAQ,EAAE,MAAM;CAO7B;AAED,oGAAoG;AACpG,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAGjF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,aAAa,UAAQ,GACpB,OAAO,EAAE,CAEX;AAQD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAMf;AAED,kEAAkE;AAClE,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MA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AqB,CACzC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,SAAS,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,GAAG,SAAS,GAChD,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * The plain logic behind `useToolQuery`, `useViewToolQuery`, `useViewData`
3
+ * and `useToolMutation` (toolkit#176 K18): the effective cache key and its
4
+ * collision guard, the opt-in retry policy for tool errors, the TanStack
5
+ * options a tool query runs with, and per-call mutation callbacks that fire
6
+ * for EVERY call. No React, no `mcp-use/react`, so it is unit-tested without
7
+ * a renderer.
8
+ */
9
+ import { hashKey, } from "@tanstack/react-query";
10
+ import { isToolError, parseToolResult } from "./parse-tool-result.js";
11
+ /**
12
+ * Neither an `AppQueryProvider` `callTool` nor a `HostBridgeProvider` is in
13
+ * reach, so the query cannot call any tool. Never retried: nothing changes
14
+ * until the mount does.
15
+ */
16
+ export class NoToolTransportError extends Error {
17
+ constructor(toolName) {
18
+ super(`[mcp-toolkit] cannot call "${toolName}": no tool transport. Mount the widget under ` +
19
+ "AppQueryProvider with callTool, or a HostBridgeProvider.");
20
+ this.name = "NoToolTransportError";
21
+ }
22
+ }
23
+ /** Retries {@link shouldRetryToolCall} grants a failed transport (TanStack's own default count). */
24
+ export const TOOL_QUERY_RETRIES = 3;
25
+ /**
26
+ * A retry policy for tool queries: up to {@link TOOL_QUERY_RETRIES} retries
27
+ * for a failed transport, none for a tool's own `isError` answer
28
+ * (`isToolError`) or a missing transport — repeating a deterministic answer
29
+ * only repeats it and holds the error back about 7 s.
30
+ *
31
+ * Opt-in in 2.x (the hooks keep the client's `retry`, TanStack's 3 by
32
+ * default, because a tool may also answer a transient failure with
33
+ * `isError`): pass `retry: shouldRetryToolCall` to a hook, or set it as the
34
+ * client's default (`queryClient.setDefaultOptions`, or an `AppQueryProvider`
35
+ * `client` of your own).
36
+ */
37
+ export function shouldRetryToolCall(failureCount, error) {
38
+ if (isToolError(error) || error instanceof NoToolTransportError)
39
+ return false;
40
+ return failureCount < TOOL_QUERY_RETRIES;
41
+ }
42
+ /**
43
+ * The effective cache key of a tool query (toolkit#176 K18).
44
+ *
45
+ * - 2.x default: the caller's key, then the args (`[...queryKey, args]`), so
46
+ * two callers sharing a key with different args get separate entries.
47
+ * - `toolNameInKey`: the caller's key, the tool name, then the args
48
+ * (`[...queryKey, toolName, args]`), so two tools never share an entry,
49
+ * whatever key their callers pass. Opt-in in 2.x (`AppQueryProvider` /
50
+ * `McpAppView` `toolNameInQueryKey`), the default from the next major.
51
+ *
52
+ * Build exact keys (`getQueryData`, `setQueryData`, `cancelQueries` with
53
+ * `exact: true`) with this helper, or with `useToolQueryKey`, which reads the
54
+ * provider's setting, rather than by hand: code that goes through them keeps
55
+ * working when the default changes. Prefix invalidation by `queryKey`
56
+ * matches either way.
57
+ */
58
+ export function toolQueryKey(queryKey, toolName, args, toolNameInKey = false) {
59
+ return toolNameInKey ? [...queryKey, toolName, args] : [...queryKey, args];
60
+ }
61
+ /**
62
+ * The tool that last claimed each cache key, per client — the guard against
63
+ * two tools sharing one entry (their answers would overwrite each other).
64
+ */
65
+ const keyOwners = new WeakMap();
66
+ /**
67
+ * Claim the cache key `keyId` (`hashKey` of a {@link toolQueryKey}) for
68
+ * `toolName` on `client`. Returns the tool that held it
69
+ * before when that is ANOTHER tool — a collision the hooks report — else
70
+ * `null`. The latest claim wins, so each collision is reported once per
71
+ * switch.
72
+ */
73
+ export function claimToolQueryKey(client, keyId, toolName) {
74
+ const owners = keyOwners.get(client) ?? new Map();
75
+ keyOwners.set(client, owners);
76
+ const previous = owners.get(keyId);
77
+ owners.set(keyId, toolName);
78
+ return previous !== undefined && previous !== toolName ? previous : null;
79
+ }
80
+ /** The console line for a {@link claimToolQueryKey} collision. */
81
+ export function toolKeyCollisionMessage(keyId, toolName, previous) {
82
+ return (`[mcp-toolkit] the query key ${keyId} is used by "${previous}" and "${toolName}": ` +
83
+ "both share one cache entry and overwrite each other's answer. Give each tool its own queryKey.");
84
+ }
85
+ /**
86
+ * The TanStack options of a tool query: the caller's options, the
87
+ * {@link toolQueryKey} and a fetcher that calls `toolName` and decodes the
88
+ * result. `retry` stays the caller's, else the client's default; only a
89
+ * missing transport is never retried. Without a transport the fetcher fails
90
+ * with {@link NoToolTransportError} instead of leaving the query idle.
91
+ */
92
+ export function toolQueryOptions(queryKey, toolName, args, callTool, opts, build = {}) {
93
+ const decode = build.decode ?? ((result) => parseToolResult(result));
94
+ return {
95
+ ...opts,
96
+ // An omitted `retry` must stay omitted: an explicit `undefined` would
97
+ // shadow the client's default.
98
+ ...(callTool ? null : { retry: false }),
99
+ queryKey: toolQueryKey(queryKey, toolName, args, build.toolNameInKey),
100
+ queryFn: async () => {
101
+ if (!callTool)
102
+ throw new NoToolTransportError(toolName);
103
+ return decode(await callTool(toolName, args));
104
+ },
105
+ };
106
+ }
107
+ /**
108
+ * The content of the payload last seeded per query key, per client: a
109
+ * remounted or re-rendered OLD payload must not roll a refetched answer
110
+ * back, while a payload not seeded before is a new delivery and wins.
111
+ */
112
+ const lastSeeded = new WeakMap();
113
+ function contentOf(value) {
114
+ try {
115
+ return JSON.stringify(value);
116
+ }
117
+ catch {
118
+ return undefined;
119
+ }
120
+ }
121
+ /**
122
+ * Seed `queryKey` with host-delivered `seed`: written when the entry is
123
+ * empty, or when the seed is a payload this client has not seeded for the
124
+ * key before (a new delivery). Returns whether the cache was written.
125
+ */
126
+ export function seedToolQuery(client, queryKey, seed, updatedAt) {
127
+ const keyId = hashKey(queryKey);
128
+ const seeded = lastSeeded.get(client) ?? new Map();
129
+ lastSeeded.set(client, seeded);
130
+ const content = contentOf(seed);
131
+ const delivered = content === undefined || seeded.get(keyId) !== content;
132
+ if (content !== undefined)
133
+ seeded.set(keyId, content);
134
+ if (!delivered && client.getQueryData(queryKey) !== undefined)
135
+ return false;
136
+ client.setQueryData(queryKey, seed, updatedAt === undefined ? undefined : { updatedAt });
137
+ return true;
138
+ }
139
+ function settle(run) {
140
+ try {
141
+ run();
142
+ }
143
+ catch (err) {
144
+ // Surface a throwing callback as an unhandled rejection, as TanStack
145
+ // does, without skipping the callbacks after it.
146
+ void Promise.reject(err instanceof Error ? err : new Error(String(err)));
147
+ }
148
+ }
149
+ /**
150
+ * Fire one call's per-call `onSuccess` / `onError` / `onSettled` once `call`
151
+ * settles — for EVERY call. TanStack's own `mutate` keeps only the latest
152
+ * call's callbacks, so two quick calls (retrying two incidents in a row)
153
+ * would confirm only the second. `context()` is read when the call settles:
154
+ * `null` (the component unmounted) skips the callbacks, as TanStack does.
155
+ * A rejected `call` is handled here, never left unhandled.
156
+ */
157
+ export function settleEachCall(call, variables, callbacks, context) {
158
+ call.then((data) => {
159
+ const ctx = callbacks ? context() : null;
160
+ if (!callbacks || !ctx)
161
+ return;
162
+ settle(() => callbacks.onSuccess?.(data, variables, undefined, ctx));
163
+ settle(() => callbacks.onSettled?.(data, null, variables, undefined, ctx));
164
+ }, (error) => {
165
+ const ctx = callbacks ? context() : null;
166
+ if (!callbacks || !ctx)
167
+ return;
168
+ settle(() => callbacks.onError?.(error, variables, undefined, ctx));
169
+ settle(() => callbacks.onSettled?.(undefined, error, variables, undefined, ctx));
170
+ });
171
+ }
172
+ /**
173
+ * Invalidate the query keys (prefixes) a mutation names: matching ACTIVE
174
+ * queries refetch now, inactive ones are only marked stale and refetch when
175
+ * they are next used — never a refetch of every inactive cached page.
176
+ */
177
+ export async function invalidateToolQueries(client, keys) {
178
+ if (!keys)
179
+ return;
180
+ await Promise.all(keys.map((queryKey) => client.invalidateQueries({ queryKey })));
181
+ }
182
+ //# sourceMappingURL=tool-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-query.js","sourceRoot":"","sources":["../../src/lib/tool-query.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,OAAO,GAKR,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAg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AAC,CAAC,CAAC,CAAA;AACnF,CAAC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * A passive observer of the MCP Apps (SEP-1865) host → view lifecycle
3
+ * notifications, read straight off the postMessage channel the view runtime
4
+ * itself listens on (toolkit#176 K13, N21).
5
+ *
6
+ * mcp-use 2.x latches only a result WITH `structuredContent` (or an
7
+ * `isError`); a content-only result, which claude.ai and Claude Desktop send,
8
+ * leaves its status `"pending"` forever, and its tool input merges partial and
9
+ * complete arguments into one field. Watching the notifications themselves
10
+ * tells the three cases apart that the latch cannot:
11
+ *
12
+ * - the host delivered a STRIPPED result (re-run the tool now, with the
13
+ * complete arguments it was called with),
14
+ * - the host delivered a structured result (the latch follows; never re-run),
15
+ * - nothing arrived yet (a slow tool on a compliant host: keep waiting).
16
+ *
17
+ * The last case is only certain when the observer was listening before the
18
+ * host answered `ui/initialize` ({@link ToolObservation.sawHandshake}): hosts
19
+ * send the lifecycle notifications after the handshake, so an observer that
20
+ * saw it has seen everything sent so far. `mountMcpToolkitApp` installs it
21
+ * ahead of `bootstrapView` for exactly that reason.
22
+ *
23
+ * Read-only: it never sends, never answers and never stops a message.
24
+ */
25
+ /** What the host's `ui/notifications/tool-result` carried. */
26
+ export type ObservedToolResult = "none" | "structured" | "stripped" | "error";
27
+ /** Everything the observer learned about the rendering call so far. */
28
+ export interface ToolObservation {
29
+ /**
30
+ * The observer saw the host answer `ui/initialize`, so it was listening
31
+ * before any lifecycle notification could be sent: a result it has not
32
+ * seen has not been delivered yet.
33
+ */
34
+ sawHandshake: boolean;
35
+ /**
36
+ * The arguments of the complete `ui/notifications/tool-input` — never a
37
+ * partial stream (`tool-input-partial` is ignored). `undefined` until it
38
+ * arrived.
39
+ */
40
+ completeInput: Record<string, unknown> | undefined;
41
+ /** What the first `ui/notifications/tool-result` carried. */
42
+ result: ObservedToolResult;
43
+ /** The host sent `ui/notifications/tool-cancelled`. */
44
+ cancelled: boolean;
45
+ }
46
+ export declare const EMPTY_TOOL_OBSERVATION: ToolObservation;
47
+ /** A host → view message the observer acts on. */
48
+ export type HostLifecycleMessage = {
49
+ kind: "handshake";
50
+ } | {
51
+ kind: "tool-input";
52
+ arguments: Record<string, unknown>;
53
+ } | {
54
+ kind: "tool-result";
55
+ result: Exclude<ObservedToolResult, "none">;
56
+ } | {
57
+ kind: "tool-cancelled";
58
+ };
59
+ /**
60
+ * Classify a tool-result notification the way mcp-use 2.x's latch does: an
61
+ * `isError` result is an error, a result with `structuredContent` (even
62
+ * `null`) latches as ready, and anything else is the stripped, content-only
63
+ * result the latch ignores.
64
+ */
65
+ export declare function classifyToolResult(params: Record<string, unknown>): Exclude<ObservedToolResult, "none">;
66
+ /**
67
+ * Decode one postMessage payload into the lifecycle message it is, or `null`
68
+ * for anything else (other methods, requests, responses, foreign traffic).
69
+ */
70
+ export declare function classifyHostMessage(data: unknown): HostLifecycleMessage | null;
71
+ /**
72
+ * Fold one message into the observation. Like the mcp-use latch, the call
73
+ * settles once: after its result or cancellation, later inputs, results and
74
+ * cancellations change nothing.
75
+ */
76
+ export declare function reduceToolObservation(state: ToolObservation, message: HostLifecycleMessage): ToolObservation;
77
+ /** The `window` slice the observer listens on (any `EventTarget`, e.g. in tests). */
78
+ export interface MessageEventSource {
79
+ addEventListener(type: "message", listener: (event: Event) => void): void;
80
+ removeEventListener(type: "message", listener: (event: Event) => void): void;
81
+ }
82
+ /** A subscribable observation, shaped for `useSyncExternalStore`. */
83
+ export interface ToolResultObserver {
84
+ subscribe: (listener: () => void) => () => void;
85
+ getSnapshot: () => ToolObservation;
86
+ /** Stop listening; the last observation stays readable. */
87
+ dispose: () => void;
88
+ }
89
+ /**
90
+ * Observe the lifecycle notifications arriving on `source`. `accept` filters
91
+ * the events (the view accepts only its host: `event.source === window.parent`,
92
+ * the same check the ext-apps transport makes).
93
+ */
94
+ export declare function createToolResultObserver(source: MessageEventSource, accept?: (event: MessageEvent) => boolean): ToolResultObserver;
95
+ /**
96
+ * The view document's observer: installed once and kept for the document's
97
+ * lifetime (one document renders one view). `null` outside a browser and in
98
+ * a top-level window, where no host frames the view.
99
+ *
100
+ * It must listen before the view runtime connects, so it sees the
101
+ * handshake. This module therefore installs it as the bundle evaluates
102
+ * (below), ahead of any `bootstrapView` call in the entry module, whatever
103
+ * the mount; `mountMcpToolkitApp` calls it again (idempotent). Installed any
104
+ * later, it still sees what arrives afterwards, and the recovery falls back
105
+ * to its grace timer for the rest.
106
+ */
107
+ export declare function installToolResultObserver(): ToolResultObserver | null;
108
+ //# sourceMappingURL=tool-result-observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result-observer.d.ts","sourceRoot":"","sources":["../../src/lib/tool-result-observer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,CAAA;AAE7E,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,YAAY,EAAE,OAAO,CAAA;IACrB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAClD,6DAA6D;IAC7D,MAAM,EAAE,kBAAkB,CAAA;IAC1B,uDAAuD;IACvD,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,eAAO,MAAM,sBAAsB,EAAE,eAKnC,CAAA;AAEF,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CA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