skybridge 0.0.0-dev.f29d75c → 0.0.0-dev.f2d6084

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 (331) hide show
  1. package/README.md +123 -116
  2. package/dist/cli/build-helpers.d.ts +7 -0
  3. package/dist/cli/build-helpers.js +82 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.js +64 -0
  6. package/dist/cli/build-helpers.test.js.map +1 -0
  7. package/dist/cli/detect-port.d.ts +18 -0
  8. package/dist/cli/detect-port.js +50 -0
  9. package/dist/cli/detect-port.js.map +1 -0
  10. package/dist/cli/header.js +1 -1
  11. package/dist/cli/header.js.map +1 -1
  12. package/dist/cli/resolve-views-dir.d.ts +1 -0
  13. package/dist/cli/resolve-views-dir.js +17 -0
  14. package/dist/cli/resolve-views-dir.js.map +1 -0
  15. package/dist/cli/run-command.js.map +1 -1
  16. package/dist/cli/telemetry.js.map +1 -1
  17. package/dist/cli/tunnel-control-server.d.ts +9 -0
  18. package/dist/cli/tunnel-control-server.js +31 -0
  19. package/dist/cli/tunnel-control-server.js.map +1 -0
  20. package/dist/cli/tunnel-control-server.test.js +39 -0
  21. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  22. package/dist/cli/tunnel-handler.d.ts +3 -0
  23. package/dist/cli/tunnel-handler.js +48 -0
  24. package/dist/cli/tunnel-handler.js.map +1 -0
  25. package/dist/cli/tunnel-handler.test.d.ts +1 -0
  26. package/dist/cli/tunnel-handler.test.js +105 -0
  27. package/dist/cli/tunnel-handler.test.js.map +1 -0
  28. package/dist/cli/tunnel.d.ts +57 -0
  29. package/dist/cli/tunnel.js +154 -0
  30. package/dist/cli/tunnel.js.map +1 -0
  31. package/dist/cli/tunnel.test.d.ts +1 -0
  32. package/dist/cli/tunnel.test.js +190 -0
  33. package/dist/cli/tunnel.test.js.map +1 -0
  34. package/dist/cli/types.d.ts +5 -0
  35. package/dist/cli/types.js +2 -0
  36. package/dist/cli/types.js.map +1 -0
  37. package/dist/cli/use-execute-steps.js.map +1 -1
  38. package/dist/cli/use-messages.d.ts +3 -0
  39. package/dist/cli/use-messages.js +11 -0
  40. package/dist/cli/use-messages.js.map +1 -0
  41. package/dist/cli/use-nodemon.d.ts +2 -6
  42. package/dist/cli/use-nodemon.js +18 -14
  43. package/dist/cli/use-nodemon.js.map +1 -1
  44. package/dist/cli/use-open-browser.d.ts +1 -0
  45. package/dist/cli/use-open-browser.js +44 -0
  46. package/dist/cli/use-open-browser.js.map +1 -0
  47. package/dist/cli/use-open-tunnel-browser.d.ts +6 -0
  48. package/dist/cli/use-open-tunnel-browser.js +19 -0
  49. package/dist/cli/use-open-tunnel-browser.js.map +1 -0
  50. package/dist/cli/use-tunnel.d.ts +14 -0
  51. package/dist/cli/use-tunnel.js +131 -0
  52. package/dist/cli/use-tunnel.js.map +1 -0
  53. package/dist/cli/use-typescript-check.d.ts +1 -0
  54. package/dist/cli/use-typescript-check.js +42 -7
  55. package/dist/cli/use-typescript-check.js.map +1 -1
  56. package/dist/commands/build.d.ts +0 -1
  57. package/dist/commands/build.js +52 -8
  58. package/dist/commands/build.js.map +1 -1
  59. package/dist/commands/create.d.ts +9 -0
  60. package/dist/commands/create.js +30 -0
  61. package/dist/commands/create.js.map +1 -0
  62. package/dist/commands/dev.d.ts +4 -1
  63. package/dist/commands/dev.js +75 -8
  64. package/dist/commands/dev.js.map +1 -1
  65. package/dist/commands/start.d.ts +3 -1
  66. package/dist/commands/start.js +34 -12
  67. package/dist/commands/start.js.map +1 -1
  68. package/dist/commands/telemetry/disable.js.map +1 -1
  69. package/dist/commands/telemetry/enable.js.map +1 -1
  70. package/dist/commands/telemetry/status.js.map +1 -1
  71. package/dist/server/asset-base-url-transform-plugin.d.ts +6 -6
  72. package/dist/server/asset-base-url-transform-plugin.js +25 -11
  73. package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
  74. package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
  75. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
  76. package/dist/server/auth.d.ts +20 -0
  77. package/dist/server/auth.js +28 -0
  78. package/dist/server/auth.js.map +1 -0
  79. package/dist/server/build-manifest.test.d.ts +1 -0
  80. package/dist/server/build-manifest.test.js +27 -0
  81. package/dist/server/build-manifest.test.js.map +1 -0
  82. package/dist/server/content-helpers.d.ts +67 -0
  83. package/dist/server/content-helpers.js +79 -0
  84. package/dist/server/content-helpers.js.map +1 -0
  85. package/dist/server/content-helpers.test.d.ts +1 -0
  86. package/dist/server/content-helpers.test.js +70 -0
  87. package/dist/server/content-helpers.test.js.map +1 -0
  88. package/dist/server/express.d.ts +7 -5
  89. package/dist/server/express.js +52 -23
  90. package/dist/server/express.js.map +1 -1
  91. package/dist/server/express.test.js +411 -25
  92. package/dist/server/express.test.js.map +1 -1
  93. package/dist/server/file-ref.d.ts +28 -0
  94. package/dist/server/file-ref.js +27 -0
  95. package/dist/server/file-ref.js.map +1 -0
  96. package/dist/server/index.d.ts +7 -3
  97. package/dist/server/index.js +5 -2
  98. package/dist/server/index.js.map +1 -1
  99. package/dist/server/inferUtilityTypes.d.ts +6 -6
  100. package/dist/server/inferUtilityTypes.js.map +1 -1
  101. package/dist/server/metric.d.ts +14 -0
  102. package/dist/server/metric.js +62 -0
  103. package/dist/server/metric.js.map +1 -0
  104. package/dist/server/middleware.d.ts +137 -0
  105. package/dist/server/middleware.js +93 -0
  106. package/dist/server/middleware.js.map +1 -0
  107. package/dist/server/middleware.test-d.d.ts +1 -0
  108. package/dist/server/middleware.test-d.js +75 -0
  109. package/dist/server/middleware.test-d.js.map +1 -0
  110. package/dist/server/middleware.test.d.ts +1 -0
  111. package/dist/server/middleware.test.js +493 -0
  112. package/dist/server/middleware.test.js.map +1 -0
  113. package/dist/server/server.d.ts +340 -64
  114. package/dist/server/server.js +507 -102
  115. package/dist/server/server.js.map +1 -1
  116. package/dist/server/templateHelper.d.ts +5 -8
  117. package/dist/server/templateHelper.js +3 -22
  118. package/dist/server/templateHelper.js.map +1 -1
  119. package/dist/server/templates.generated.d.ts +4 -0
  120. package/dist/server/templates.generated.js +47 -0
  121. package/dist/server/templates.generated.js.map +1 -0
  122. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  123. package/dist/server/tunnel-proxy-router.js +110 -0
  124. package/dist/server/tunnel-proxy-router.js.map +1 -0
  125. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  126. package/dist/server/tunnel-proxy-router.test.js +229 -0
  127. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  128. package/dist/server/viewsDevServer.d.ts +14 -0
  129. package/dist/server/viewsDevServer.js +45 -0
  130. package/dist/server/viewsDevServer.js.map +1 -0
  131. package/dist/test/utils.d.ts +13 -21
  132. package/dist/test/utils.js +42 -37
  133. package/dist/test/utils.js.map +1 -1
  134. package/dist/test/view.test.d.ts +1 -0
  135. package/dist/test/view.test.js +568 -0
  136. package/dist/test/view.test.js.map +1 -0
  137. package/dist/version.d.ts +1 -0
  138. package/dist/version.js +3 -0
  139. package/dist/version.js.map +1 -0
  140. package/dist/web/bridges/apps-sdk/adaptor.d.ts +14 -7
  141. package/dist/web/bridges/apps-sdk/adaptor.js +66 -29
  142. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  143. package/dist/web/bridges/apps-sdk/bridge.d.ts +2 -1
  144. package/dist/web/bridges/apps-sdk/bridge.js +1 -0
  145. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  146. package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
  147. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  148. package/dist/web/bridges/apps-sdk/types.d.ts +26 -11
  149. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  150. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  151. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  152. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  153. package/dist/web/bridges/get-adaptor.d.ts +7 -0
  154. package/dist/web/bridges/get-adaptor.js +7 -0
  155. package/dist/web/bridges/get-adaptor.js.map +1 -1
  156. package/dist/web/bridges/index.js.map +1 -1
  157. package/dist/web/bridges/mcp-app/adaptor.d.ts +26 -9
  158. package/dist/web/bridges/mcp-app/adaptor.js +159 -66
  159. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  160. package/dist/web/bridges/mcp-app/bridge.d.ts +16 -31
  161. package/dist/web/bridges/mcp-app/bridge.js +65 -201
  162. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  163. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  164. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  165. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +17 -3
  166. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
  167. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  168. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -41
  169. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  170. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  171. package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
  172. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  173. package/dist/web/bridges/types.d.ts +120 -14
  174. package/dist/web/bridges/types.js.map +1 -1
  175. package/dist/web/bridges/use-host-context.d.ts +5 -0
  176. package/dist/web/bridges/use-host-context.js +5 -0
  177. package/dist/web/bridges/use-host-context.js.map +1 -1
  178. package/dist/web/components/modal-provider.js +3 -5
  179. package/dist/web/components/modal-provider.js.map +1 -1
  180. package/dist/web/create-store.d.ts +26 -0
  181. package/dist/web/create-store.js +43 -3
  182. package/dist/web/create-store.js.map +1 -1
  183. package/dist/web/create-store.test.js +21 -18
  184. package/dist/web/create-store.test.js.map +1 -1
  185. package/dist/web/data-llm.d.ts +34 -1
  186. package/dist/web/data-llm.js +31 -3
  187. package/dist/web/data-llm.js.map +1 -1
  188. package/dist/web/data-llm.test.js +24 -23
  189. package/dist/web/data-llm.test.js.map +1 -1
  190. package/dist/web/generate-helpers.d.ts +22 -18
  191. package/dist/web/generate-helpers.js +22 -18
  192. package/dist/web/generate-helpers.js.map +1 -1
  193. package/dist/web/generate-helpers.test-d.js +26 -26
  194. package/dist/web/generate-helpers.test-d.js.map +1 -1
  195. package/dist/web/generate-helpers.test.js.map +1 -1
  196. package/dist/web/helpers/state.d.ts +2 -2
  197. package/dist/web/helpers/state.js +11 -11
  198. package/dist/web/helpers/state.js.map +1 -1
  199. package/dist/web/helpers/state.test.js +9 -9
  200. package/dist/web/helpers/state.test.js.map +1 -1
  201. package/dist/web/hooks/index.d.ts +6 -2
  202. package/dist/web/hooks/index.js +5 -1
  203. package/dist/web/hooks/index.js.map +1 -1
  204. package/dist/web/hooks/test/utils.d.ts +6 -2
  205. package/dist/web/hooks/test/utils.js +17 -2
  206. package/dist/web/hooks/test/utils.js.map +1 -1
  207. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  208. package/dist/web/hooks/use-call-tool.js +28 -0
  209. package/dist/web/hooks/use-call-tool.js.map +1 -1
  210. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  211. package/dist/web/hooks/use-call-tool.test.js +27 -6
  212. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  213. package/dist/web/hooks/use-display-mode.d.ts +23 -3
  214. package/dist/web/hooks/use-display-mode.js +20 -0
  215. package/dist/web/hooks/use-display-mode.js.map +1 -1
  216. package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
  217. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  218. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  219. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  220. package/dist/web/hooks/use-download.d.ts +5 -0
  221. package/dist/web/hooks/use-download.js +8 -0
  222. package/dist/web/hooks/use-download.js.map +1 -0
  223. package/dist/web/hooks/use-download.test.d.ts +1 -0
  224. package/dist/web/hooks/use-download.test.js +95 -0
  225. package/dist/web/hooks/use-download.test.js.map +1 -0
  226. package/dist/web/hooks/use-files.d.ts +34 -1
  227. package/dist/web/hooks/use-files.js +33 -0
  228. package/dist/web/hooks/use-files.js.map +1 -1
  229. package/dist/web/hooks/use-files.test.js +22 -2
  230. package/dist/web/hooks/use-files.test.js.map +1 -1
  231. package/dist/web/hooks/use-layout.d.ts +2 -0
  232. package/dist/web/hooks/use-layout.js +2 -0
  233. package/dist/web/hooks/use-layout.js.map +1 -1
  234. package/dist/web/hooks/use-layout.test.js +3 -3
  235. package/dist/web/hooks/use-layout.test.js.map +1 -1
  236. package/dist/web/hooks/use-open-external.d.ts +20 -1
  237. package/dist/web/hooks/use-open-external.js +17 -1
  238. package/dist/web/hooks/use-open-external.js.map +1 -1
  239. package/dist/web/hooks/use-open-external.test.js +26 -11
  240. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  241. package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
  242. package/dist/web/hooks/use-register-view-tool.js +50 -0
  243. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  244. package/dist/web/hooks/use-request-close.d.ts +16 -0
  245. package/dist/web/hooks/use-request-close.js +21 -0
  246. package/dist/web/hooks/use-request-close.js.map +1 -0
  247. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  248. package/dist/web/hooks/use-request-close.test.js +52 -0
  249. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  250. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  251. package/dist/web/hooks/use-request-modal.js +19 -4
  252. package/dist/web/hooks/use-request-modal.js.map +1 -1
  253. package/dist/web/hooks/use-request-modal.test.js +5 -1
  254. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  255. package/dist/web/hooks/use-request-size.d.ts +20 -0
  256. package/dist/web/hooks/use-request-size.js +24 -0
  257. package/dist/web/hooks/use-request-size.js.map +1 -0
  258. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  259. package/dist/web/hooks/use-request-size.test.js +65 -0
  260. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  261. package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
  262. package/dist/web/hooks/use-send-follow-up-message.js +19 -2
  263. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  264. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  265. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  266. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  267. package/dist/web/hooks/use-set-open-in-app-url.test.js +5 -11
  268. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  269. package/dist/web/hooks/use-tool-info.d.ts +33 -0
  270. package/dist/web/hooks/use-tool-info.js +26 -0
  271. package/dist/web/hooks/use-tool-info.js.map +1 -1
  272. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  273. package/dist/web/hooks/use-tool-info.test.js +1 -1
  274. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  275. package/dist/web/hooks/use-user.d.ts +2 -0
  276. package/dist/web/hooks/use-user.js +20 -2
  277. package/dist/web/hooks/use-user.js.map +1 -1
  278. package/dist/web/hooks/use-user.test.js +29 -1
  279. package/dist/web/hooks/use-user.test.js.map +1 -1
  280. package/dist/web/hooks/use-view-state.d.ts +25 -0
  281. package/dist/web/hooks/use-view-state.js +32 -0
  282. package/dist/web/hooks/use-view-state.js.map +1 -0
  283. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  284. package/dist/web/hooks/use-view-state.test.js +177 -0
  285. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  286. package/dist/web/index.d.ts +1 -2
  287. package/dist/web/index.js +1 -2
  288. package/dist/web/index.js.map +1 -1
  289. package/dist/web/mount-view.d.ts +20 -0
  290. package/dist/web/{mount-widget.js → mount-view.js} +21 -2
  291. package/dist/web/mount-view.js.map +1 -0
  292. package/dist/web/plugin/data-llm.test.js.map +1 -1
  293. package/dist/web/plugin/plugin.d.ts +32 -1
  294. package/dist/web/plugin/plugin.js +161 -18
  295. package/dist/web/plugin/plugin.js.map +1 -1
  296. package/dist/web/plugin/scan-views.d.ts +16 -0
  297. package/dist/web/plugin/scan-views.js +88 -0
  298. package/dist/web/plugin/scan-views.js.map +1 -0
  299. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  300. package/dist/web/plugin/scan-views.test.js +99 -0
  301. package/dist/web/plugin/scan-views.test.js.map +1 -0
  302. package/dist/web/plugin/transform-data-llm.js +1 -1
  303. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  304. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  305. package/dist/web/plugin/validate-view.d.ts +1 -0
  306. package/dist/web/plugin/validate-view.js +9 -0
  307. package/dist/web/plugin/validate-view.js.map +1 -0
  308. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  309. package/dist/web/plugin/validate-view.test.js +24 -0
  310. package/dist/web/plugin/validate-view.test.js.map +1 -0
  311. package/dist/web/proxy.js.map +1 -1
  312. package/dist/web/types.d.ts +4 -0
  313. package/dist/web/types.js.map +1 -1
  314. package/package.json +39 -23
  315. package/tsconfig.base.json +5 -0
  316. package/dist/server/templates/development.hbs +0 -67
  317. package/dist/server/templates/production.hbs +0 -6
  318. package/dist/server/widgetsDevServer.d.ts +0 -12
  319. package/dist/server/widgetsDevServer.js +0 -57
  320. package/dist/server/widgetsDevServer.js.map +0 -1
  321. package/dist/test/widget.test.js +0 -261
  322. package/dist/test/widget.test.js.map +0 -1
  323. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  324. package/dist/web/hooks/use-widget-state.js +0 -32
  325. package/dist/web/hooks/use-widget-state.js.map +0 -1
  326. package/dist/web/hooks/use-widget-state.test.js +0 -62
  327. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  328. package/dist/web/mount-widget.d.ts +0 -1
  329. package/dist/web/mount-widget.js.map +0 -1
  330. /package/dist/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  331. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
@@ -3,18 +3,18 @@ import { createInterfaceTestServer, createTestServer } from "../test/utils.js";
3
3
  import { generateHelpers } from "./generate-helpers.js";
4
4
  const server = createTestServer();
5
5
  const interfaceServer = createInterfaceTestServer();
6
- test("InferTools extracts the tool registry type (widgets + registerTool)", () => {
7
- expectTypeOf().toHaveProperty("search-voyage");
6
+ test("InferTools extracts the tool registry type (views + registerTool)", () => {
7
+ expectTypeOf().toHaveProperty("search-trip");
8
8
  expectTypeOf().toHaveProperty("get-trip-details");
9
- expectTypeOf().toHaveProperty("no-input-widget");
9
+ expectTypeOf().toHaveProperty("no-input-view");
10
10
  expectTypeOf().toHaveProperty("calculate-price");
11
- expectTypeOf().toHaveProperty("inferred-output-widget");
11
+ expectTypeOf().toHaveProperty("inferred-output-view");
12
12
  expectTypeOf().toHaveProperty("inferred-tool");
13
- expectTypeOf().toHaveProperty("widget-with-metadata");
13
+ expectTypeOf().toHaveProperty("view-with-metadata");
14
14
  expectTypeOf().toHaveProperty("tool-with-metadata");
15
- expectTypeOf().toHaveProperty("widget-with-mixed-returns");
15
+ expectTypeOf().toHaveProperty("view-with-mixed-returns");
16
16
  });
17
- test("ToolNames returns a union of tool name literals (widgets + registerTool)", () => {
17
+ test("ToolNames returns a union of tool name literals (views + registerTool)", () => {
18
18
  expectTypeOf().toEqualTypeOf();
19
19
  });
20
20
  test("ToolInput extracts the correct input type from Zod schema", () => {
@@ -32,23 +32,23 @@ test("ToolOutput extracts the correct output type from callback (inferred)", ()
32
32
  expectTypeOf().toEqualTypeOf();
33
33
  expectTypeOf().toEqualTypeOf();
34
34
  });
35
- test("generateHelpers provides autocomplete for tool names (widgets + registerTool)", () => {
35
+ test("generateHelpers provides autocomplete for tool names (views + registerTool)", () => {
36
36
  const { useCallTool } = generateHelpers();
37
- useCallTool("search-voyage");
37
+ useCallTool("search-trip");
38
38
  useCallTool("get-trip-details");
39
- useCallTool("no-input-widget");
39
+ useCallTool("no-input-view");
40
40
  useCallTool("calculate-price");
41
- useCallTool("inferred-output-widget");
41
+ useCallTool("inferred-output-view");
42
42
  useCallTool("inferred-tool");
43
- useCallTool("widget-with-metadata");
43
+ useCallTool("view-with-metadata");
44
44
  useCallTool("tool-with-metadata");
45
- useCallTool("widget-with-mixed-returns");
45
+ useCallTool("view-with-mixed-returns");
46
46
  // @ts-expect-error - "invalid-name" is not a valid tool name
47
47
  useCallTool("invalid-name");
48
48
  });
49
49
  test("useCallTool returns correctly typed callTool function", () => {
50
50
  const { useCallTool } = generateHelpers();
51
- const { callTool } = useCallTool("search-voyage");
51
+ const { callTool } = useCallTool("search-trip");
52
52
  callTool({ destination: "Spain" });
53
53
  callTool({ destination: "France", departureDate: "2024-06-01" });
54
54
  callTool({ destination: "Italy", maxPrice: 1000 });
@@ -57,7 +57,7 @@ test("useCallTool returns correctly typed callTool function", () => {
57
57
  });
58
58
  test("callTool can be called without args for tools with no required inputs", () => {
59
59
  const { useCallTool } = generateHelpers();
60
- const { callTool, callToolAsync } = useCallTool("no-input-widget");
60
+ const { callTool, callToolAsync } = useCallTool("no-input-view");
61
61
  callTool();
62
62
  callTool({});
63
63
  callToolAsync();
@@ -65,7 +65,7 @@ test("callTool can be called without args for tools with no required inputs", ()
65
65
  });
66
66
  test("callTool requires args for tools with required inputs", () => {
67
67
  const { useCallTool } = generateHelpers();
68
- const { callTool } = useCallTool("search-voyage");
68
+ const { callTool } = useCallTool("search-trip");
69
69
  // @ts-expect-error - "destination" is required
70
70
  callTool();
71
71
  // @ts-expect-error - "destination" is required
@@ -75,7 +75,7 @@ test("callTool requires args for tools with required inputs", () => {
75
75
  });
76
76
  test("callTool supports sideEffects for tools with required inputs", () => {
77
77
  const { useCallTool } = generateHelpers();
78
- const { callTool } = useCallTool("search-voyage");
78
+ const { callTool } = useCallTool("search-trip");
79
79
  callTool({ destination: "Spain" }, {
80
80
  onSuccess: (response, args) => {
81
81
  expectTypeOf(response.structuredContent.results).toBeArray();
@@ -96,7 +96,7 @@ test("callTool supports sideEffects for tools with required inputs", () => {
96
96
  });
97
97
  test("callTool supports sideEffects for tools with no required inputs", () => {
98
98
  const { useCallTool } = generateHelpers();
99
- const { callTool } = useCallTool("no-input-widget");
99
+ const { callTool } = useCallTool("no-input-view");
100
100
  callTool({
101
101
  onSuccess: (response) => {
102
102
  expectTypeOf(response).toHaveProperty("structuredContent");
@@ -110,16 +110,16 @@ test("callTool supports sideEffects for tools with no required inputs", () => {
110
110
  });
111
111
  test("callToolAsync returns correctly typed promise", () => {
112
112
  const { useCallTool } = generateHelpers();
113
- const { callToolAsync: searchAsync } = useCallTool("search-voyage");
113
+ const { callToolAsync: searchAsync } = useCallTool("search-trip");
114
114
  const searchPromise = searchAsync({ destination: "Spain" });
115
115
  expectTypeOf(searchPromise).resolves.toHaveProperty("structuredContent");
116
- const { callToolAsync: noInputAsync } = useCallTool("no-input-widget");
116
+ const { callToolAsync: noInputAsync } = useCallTool("no-input-view");
117
117
  const noInputPromise = noInputAsync();
118
118
  expectTypeOf(noInputPromise).resolves.toHaveProperty("structuredContent");
119
119
  });
120
120
  test("useCallTool returns correctly typed data", () => {
121
121
  const { useCallTool } = generateHelpers();
122
- const { data } = useCallTool("search-voyage");
122
+ const { data } = useCallTool("search-trip");
123
123
  if (data) {
124
124
  expectTypeOf(data.structuredContent).toExtend();
125
125
  expectTypeOf(data.structuredContent.results).toBeArray();
@@ -128,16 +128,16 @@ test("useCallTool returns correctly typed data", () => {
128
128
  });
129
129
  test("useCallTool returns correctly typed data for callback-inferred outputs", () => {
130
130
  const { useCallTool } = generateHelpers();
131
- const { data: widgetData } = useCallTool("inferred-output-widget");
132
- if (widgetData) {
133
- expectTypeOf(widgetData.structuredContent).toExtend();
131
+ const { data: viewData } = useCallTool("inferred-output-view");
132
+ if (viewData) {
133
+ expectTypeOf(viewData.structuredContent).toExtend();
134
134
  }
135
135
  const { data: toolData } = useCallTool("inferred-tool");
136
136
  if (toolData) {
137
137
  expectTypeOf(toolData.structuredContent).toExtend();
138
138
  }
139
139
  });
140
- test("generateHelpers provides autocomplete for tool names in useToolInfo (widgets + registerTool)", () => {
140
+ test("generateHelpers provides autocomplete for tool names in useToolInfo (views + registerTool)", () => {
141
141
  const { useToolInfo } = generateHelpers();
142
142
  useToolInfo();
143
143
  useToolInfo();
@@ -193,7 +193,7 @@ test("ToolResponseMetadata extracts correct type when using interface declaratio
193
193
  });
194
194
  test("generateHelpers works with interface-typed server", () => {
195
195
  const { useCallTool, useToolInfo } = generateHelpers();
196
- const { data } = useCallTool("interface-widget");
196
+ const { data } = useCallTool("interface-view");
197
197
  if (data) {
198
198
  expectTypeOf(data.structuredContent.itemName).toBeString();
199
199
  expectTypeOf(data.structuredContent.quantity).toBeNumber();
@@ -1 +1 @@
1
- {"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAGlC,MAAM,eAAe,GAAG,yBAAyB,EAAE,CAAC;AAGpD,IAAI,CAAC,qEAAqE,EAAE,GAAG,EAAE;IAG/E,YAAY,EAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,YAAY,EAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACzD,YAAY,EAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACxD,YAAY,EAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACxD,YAAY,EAAS,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;IAC/D,YAAY,EAAS,CAAC,cAAc,CAAC,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import type {\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"../server/index.js\";\nimport { createInterfaceTestServer, createTestServer } from \"../test/utils.js\";\nimport { generateHelpers } from \"./generate-helpers.js\";\n\nconst server = createTestServer();\ntype TestServer = typeof server;\n\nconst interfaceServer = createInterfaceTestServer();\ntype InterfaceTestServer = typeof interfaceServer;\n\ntest(\"InferTools extracts the tool registry type (views + registerTool)\", () => {\n type Tools = InferTools<TestServer>;\n\n expectTypeOf<Tools>().toHaveProperty(\"search-trip\");\n expectTypeOf<Tools>().toHaveProperty(\"get-trip-details\");\n expectTypeOf<Tools>().toHaveProperty(\"no-input-view\");\n expectTypeOf<Tools>().toHaveProperty(\"calculate-price\");\n expectTypeOf<Tools>().toHaveProperty(\"inferred-output-view\");\n expectTypeOf<Tools>().toHaveProperty(\"inferred-tool\");\n expectTypeOf<Tools>().toHaveProperty(\"view-with-metadata\");\n expectTypeOf<Tools>().toHaveProperty(\"tool-with-metadata\");\n expectTypeOf<Tools>().toHaveProperty(\"view-with-mixed-returns\");\n});\n\ntest(\"ToolNames returns a union of tool name literals (views + registerTool)\", () => {\n type Names = ToolNames<TestServer>;\n\n expectTypeOf<Names>().toEqualTypeOf<\n | \"search-trip\"\n | \"get-trip-details\"\n | \"no-input-view\"\n | \"calculate-price\"\n | \"inferred-output-view\"\n | \"inferred-tool\"\n | \"view-with-metadata\"\n | \"tool-with-metadata\"\n | \"view-with-mixed-returns\"\n >();\n});\n\ntest(\"ToolInput extracts the correct input type from Zod schema\", () => {\n type SearchInput = ToolInput<TestServer, \"search-trip\">;\n\n expectTypeOf<SearchInput>().toEqualTypeOf<{\n destination: string;\n departureDate?: string | undefined;\n maxPrice?: number | undefined;\n }>();\n\n type DetailsInput = ToolInput<TestServer, \"get-trip-details\">;\n\n expectTypeOf<DetailsInput>().toEqualTypeOf<{\n tripId: string;\n }>();\n\n type CalculateInput = ToolInput<TestServer, \"calculate-price\">;\n\n expectTypeOf<CalculateInput>().toEqualTypeOf<{\n tripId: string;\n passengers: number;\n }>();\n});\n\ntest(\"ToolOutput extracts the correct output type from callback's structuredContent\", () => {\n type SearchOutput = ToolOutput<TestServer, \"search-trip\">;\n\n expectTypeOf<SearchOutput>().toEqualTypeOf<{\n results: Array<{\n id: string;\n name: string;\n price: number;\n }>;\n totalCount: number;\n }>();\n\n type DetailsOutput = ToolOutput<TestServer, \"get-trip-details\">;\n\n expectTypeOf<DetailsOutput>().toEqualTypeOf<{\n name: string;\n description: string;\n images: string[];\n }>();\n\n // Note: outputSchema has totalPrice: z.string(), but callback returns number\n // Type is inferred from callback, so totalPrice is number\n type CalculateOutput = ToolOutput<TestServer, \"calculate-price\">;\n\n expectTypeOf<CalculateOutput>().toEqualTypeOf<{\n totalPrice: number;\n currency: string;\n }>();\n\n type NoInputOutput = ToolOutput<TestServer, \"no-input-view\">;\n expectTypeOf<NoInputOutput>().toEqualTypeOf<Record<never, unknown>>();\n});\n\ntest(\"ToolOutput extracts the correct output type from callback (inferred)\", () => {\n type InferredViewOutput = ToolOutput<TestServer, \"inferred-output-view\">;\n\n expectTypeOf<InferredViewOutput>().toEqualTypeOf<{\n inferredResults: { id: string; score: number }[];\n inferredCount: number;\n }>();\n\n type InferredToolOutput = ToolOutput<TestServer, \"inferred-tool\">;\n\n expectTypeOf<InferredToolOutput>().toEqualTypeOf<{\n itemDetails: { name: string; available: boolean };\n fetchedAt: string;\n }>();\n});\n\ntest(\"generateHelpers provides autocomplete for tool names (views + registerTool)\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n\n useCallTool(\"search-trip\");\n useCallTool(\"get-trip-details\");\n useCallTool(\"no-input-view\");\n useCallTool(\"calculate-price\");\n useCallTool(\"inferred-output-view\");\n useCallTool(\"inferred-tool\");\n useCallTool(\"view-with-metadata\");\n useCallTool(\"tool-with-metadata\");\n useCallTool(\"view-with-mixed-returns\");\n\n // @ts-expect-error - \"invalid-name\" is not a valid tool name\n useCallTool(\"invalid-name\");\n});\n\ntest(\"useCallTool returns correctly typed callTool function\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"search-trip\");\n\n callTool({ destination: \"Spain\" });\n callTool({ destination: \"France\", departureDate: \"2024-06-01\" });\n callTool({ destination: \"Italy\", maxPrice: 1000 });\n\n const { callTool: calculateTool } = useCallTool(\"calculate-price\");\n calculateTool({ tripId: \"123\", passengers: 2 });\n});\n\ntest(\"callTool can be called without args for tools with no required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool, callToolAsync } = useCallTool(\"no-input-view\");\n\n callTool();\n\n callTool({});\n\n callToolAsync();\n callToolAsync({});\n});\n\ntest(\"callTool requires args for tools with required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"search-trip\");\n\n // @ts-expect-error - \"destination\" is required\n callTool();\n\n // @ts-expect-error - \"destination\" is required\n callTool({});\n\n // This should work\n callTool({ destination: \"Spain\" });\n});\n\ntest(\"callTool supports sideEffects for tools with required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"search-trip\");\n\n callTool(\n { destination: \"Spain\" },\n {\n onSuccess: (response, args) => {\n expectTypeOf(response.structuredContent.results).toBeArray();\n expectTypeOf(args.destination).toBeString();\n },\n onError: (error, args) => {\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.destination).toBeString();\n },\n onSettled: (response, error, args) => {\n if (response) {\n expectTypeOf(response.structuredContent.totalCount).toBeNumber();\n }\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.destination).toBeString();\n },\n },\n );\n});\n\ntest(\"callTool supports sideEffects for tools with no required inputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { callTool } = useCallTool(\"no-input-view\");\n\n callTool({\n onSuccess: (response) => {\n expectTypeOf(response).toHaveProperty(\"structuredContent\");\n },\n });\n\n callTool(\n {},\n {\n onSuccess: (response) => {\n expectTypeOf(response).toHaveProperty(\"structuredContent\");\n },\n },\n );\n});\n\ntest(\"callToolAsync returns correctly typed promise\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n\n const { callToolAsync: searchAsync } = useCallTool(\"search-trip\");\n const searchPromise = searchAsync({ destination: \"Spain\" });\n expectTypeOf(searchPromise).resolves.toHaveProperty(\"structuredContent\");\n\n const { callToolAsync: noInputAsync } = useCallTool(\"no-input-view\");\n const noInputPromise = noInputAsync();\n expectTypeOf(noInputPromise).resolves.toHaveProperty(\"structuredContent\");\n});\n\ntest(\"useCallTool returns correctly typed data\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n const { data } = useCallTool(\"search-trip\");\n\n if (data) {\n expectTypeOf(data.structuredContent).toExtend<{\n results: Array<{\n id: string;\n name: string;\n price: number;\n }>;\n totalCount: number;\n }>();\n\n expectTypeOf(data.structuredContent.results).toBeArray();\n expectTypeOf(data.structuredContent.totalCount).toBeNumber();\n }\n});\n\ntest(\"useCallTool returns correctly typed data for callback-inferred outputs\", () => {\n const { useCallTool } = generateHelpers<TestServer>();\n\n const { data: viewData } = useCallTool(\"inferred-output-view\");\n if (viewData) {\n expectTypeOf(viewData.structuredContent).toExtend<{\n inferredResults: { id: string; score: number }[];\n inferredCount: number;\n }>();\n }\n\n const { data: toolData } = useCallTool(\"inferred-tool\");\n if (toolData) {\n expectTypeOf(toolData.structuredContent).toExtend<{\n itemDetails: { name: string; available: boolean };\n fetchedAt: string;\n }>();\n }\n});\n\ntest(\"generateHelpers provides autocomplete for tool names in useToolInfo (views + registerTool)\", () => {\n const { useToolInfo } = generateHelpers<TestServer>();\n\n useToolInfo<\"search-trip\">();\n useToolInfo<\"get-trip-details\">();\n useToolInfo<\"no-input-view\">();\n useToolInfo<\"calculate-price\">();\n useToolInfo<\"inferred-output-view\">();\n useToolInfo<\"inferred-tool\">();\n useToolInfo<\"view-with-metadata\">();\n useToolInfo<\"tool-with-metadata\">();\n useToolInfo<\"view-with-mixed-returns\">();\n\n // @ts-expect-error - \"invalid-name\" is not a valid tool name\n useToolInfo<\"invalid-name\">();\n});\n\ntest(\"useToolInfo infers input and output types\", () => {\n const { useToolInfo } = generateHelpers<TestServer>();\n const toolInfo = useToolInfo<\"search-trip\">();\n\n // Input is only available when not in idle state\n if (!(toolInfo.status === \"idle\")) {\n expectTypeOf(toolInfo.input).toExtend<\n ToolInput<TestServer, \"search-trip\">\n >();\n }\n\n if (toolInfo.status === \"success\") {\n expectTypeOf(toolInfo.output).toExtend<\n ToolOutput<TestServer, \"search-trip\">\n >();\n expectTypeOf(toolInfo.output.results).toBeArray();\n expectTypeOf(toolInfo.output.totalCount).toBeNumber();\n }\n});\n\ntest(\"ToolResponseMetadata extracts _meta type from callback\", () => {\n type ViewMeta = ToolResponseMetadata<TestServer, \"view-with-metadata\">;\n expectTypeOf<ViewMeta>().toEqualTypeOf<{\n requestId: string;\n timestamp: number;\n cached: boolean;\n }>();\n\n type ToolMeta = ToolResponseMetadata<TestServer, \"tool-with-metadata\">;\n expectTypeOf<ToolMeta>().toEqualTypeOf<{\n executionTime: number;\n source: string;\n }>();\n\n type SearchMeta = ToolResponseMetadata<TestServer, \"search-trip\">;\n expectTypeOf<SearchMeta>().toBeUnknown();\n});\n\ntest(\"useToolInfo infers responseMetadata type from generateHelpers\", () => {\n const { useToolInfo } = generateHelpers<TestServer>();\n const toolInfo = useToolInfo<\"view-with-metadata\">();\n\n if (toolInfo.isSuccess) {\n expectTypeOf(toolInfo.responseMetadata.requestId).toBeString();\n expectTypeOf(toolInfo.responseMetadata.timestamp).toBeNumber();\n expectTypeOf(toolInfo.responseMetadata.cached).toBeBoolean();\n }\n});\n\ntest(\"ToolResponseMetadata extracts _meta from mixed return paths\", () => {\n // View has multiple return paths: some with _meta, some without\n // ExtractMeta should still infer the _meta type from branches that have it\n type MixedMeta = ToolResponseMetadata<TestServer, \"view-with-mixed-returns\">;\n expectTypeOf<MixedMeta>().toEqualTypeOf<{\n processedAt: number;\n region: string;\n }>();\n});\n\ntest(\"ToolOutput extracts correct type when using interface declaration\", () => {\n type InterfaceViewOutput = ToolOutput<InterfaceTestServer, \"interface-view\">;\n\n expectTypeOf<InterfaceViewOutput>().toHaveProperty(\"itemName\");\n expectTypeOf<InterfaceViewOutput[\"itemName\"]>().toBeString();\n expectTypeOf<InterfaceViewOutput[\"quantity\"]>().toBeNumber();\n});\n\ntest(\"ToolResponseMetadata extracts correct type when using interface declaration\", () => {\n type InterfaceViewMeta = ToolResponseMetadata<\n InterfaceTestServer,\n \"interface-view\"\n >;\n\n expectTypeOf<InterfaceViewMeta>().toHaveProperty(\"processedBy\");\n expectTypeOf<InterfaceViewMeta[\"processedBy\"]>().toBeString();\n expectTypeOf<InterfaceViewMeta[\"version\"]>().toBeNumber();\n});\n\ntest(\"generateHelpers works with interface-typed server\", () => {\n const { useCallTool, useToolInfo } = generateHelpers<InterfaceTestServer>();\n\n const { data } = useCallTool(\"interface-view\");\n if (data) {\n expectTypeOf(data.structuredContent.itemName).toBeString();\n expectTypeOf(data.structuredContent.quantity).toBeNumber();\n }\n\n const toolInfo = useToolInfo<\"interface-view\">();\n if (toolInfo.isSuccess) {\n expectTypeOf(toolInfo.output.itemName).toBeString();\n expectTypeOf(toolInfo.output.quantity).toBeNumber();\n expectTypeOf(toolInfo.responseMetadata.processedBy).toBeString();\n expectTypeOf(toolInfo.responseMetadata.version).toBeNumber();\n }\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;AAGzC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC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c,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { createMinimalTestServer } from \"../test/utils.js\";\nimport { generateHelpers } from \"./generate-helpers.js\";\n\nconst server = createMinimalTestServer();\ntype TestServer = typeof server;\n\ndescribe(\"generateHelpers\", () => {\n it(\"should return an object with useCallTool hook\", () => {\n const hooks = generateHelpers<TestServer>();\n expect(hooks).toHaveProperty(\"useCallTool\");\n expect(typeof hooks.useCallTool).toBe(\"function\");\n });\n\n it(\"should return an object with useToolInfo hook\", () => {\n const hooks = generateHelpers<TestServer>();\n expect(hooks).toHaveProperty(\"useToolInfo\");\n expect(typeof hooks.useToolInfo).toBe(\"function\");\n });\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type SuperJSONResult } from "superjson";
2
2
  import type { UnknownObject } from "../types.js";
3
- export declare function filterWidgetContext<T extends UnknownObject>(state?: T | null): T | null;
4
- export declare function injectWidgetContext<T extends UnknownObject>(newState: T | null): T | null;
3
+ export declare function filterViewContext<T extends UnknownObject>(state?: T | null): T | null;
4
+ export declare function injectViewContext<T extends UnknownObject>(newState: T | null): T | null;
5
5
  export declare function serializeState(value: UnknownObject): unknown;
6
6
  export declare function deserializeState(value: SuperJSONResult): unknown;
7
7
  export declare function getInitialState<State extends UnknownObject>(defaultState?: State | (() => State)): State | null;
@@ -1,26 +1,26 @@
1
1
  import superjson, {} from "superjson";
2
2
  import { getAdaptor } from "../bridges/index.js";
3
- import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
4
- export function filterWidgetContext(state) {
3
+ import { VIEW_CONTEXT_KEY } from "../data-llm.js";
4
+ export function filterViewContext(state) {
5
5
  if (state === null || state === undefined) {
6
6
  return null;
7
7
  }
8
- const { [WIDGET_CONTEXT_KEY]: _, ...filteredState } = state;
8
+ const { [VIEW_CONTEXT_KEY]: _, ...filteredState } = state;
9
9
  return filteredState;
10
10
  }
11
- export function injectWidgetContext(newState) {
11
+ export function injectViewContext(newState) {
12
12
  if (newState === null) {
13
13
  return null;
14
14
  }
15
15
  const currentState = getAdaptor()
16
- .getHostContextStore("widgetState")
16
+ .getHostContextStore("viewState")
17
17
  .getSnapshot();
18
18
  if (currentState !== null &&
19
19
  currentState !== undefined &&
20
- WIDGET_CONTEXT_KEY in currentState) {
20
+ VIEW_CONTEXT_KEY in currentState) {
21
21
  return {
22
22
  ...newState,
23
- [WIDGET_CONTEXT_KEY]: currentState[WIDGET_CONTEXT_KEY],
23
+ [VIEW_CONTEXT_KEY]: currentState[VIEW_CONTEXT_KEY],
24
24
  };
25
25
  }
26
26
  return newState;
@@ -32,11 +32,11 @@ export function deserializeState(value) {
32
32
  return superjson.deserialize(value);
33
33
  }
34
34
  export function getInitialState(defaultState) {
35
- const widgetState = getAdaptor()
36
- .getHostContextStore("widgetState")
35
+ const viewState = getAdaptor()
36
+ .getHostContextStore("viewState")
37
37
  .getSnapshot();
38
- if (widgetState !== null && widgetState !== undefined) {
39
- return filterWidgetContext(widgetState);
38
+ if (viewState !== null && viewState !== undefined) {
39
+ return filterViewContext(viewState);
40
40
  }
41
41
  return typeof defaultState === "function"
42
42
  ? defaultState()
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/web/helpers/state.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAwB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,UAAU,mBAAmB,CACjC,KAAgB;IAEhB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QA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AED,MAAM,UAAU,eAAe,CAC7B,YAAoC;IAEpC,MAAM,SAAS,GAAG,UAAU,EAAE;SAC3B,mBAAmB,CAAC,WAAW,CAAC;SAChC,WAAW,EAAkB,CAAC;IAEjC,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAClD,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,OAAO,YAAY,KAAK,UAAU;QACvC,CAAC,CAAC,YAAY,EAAE;QAChB,CAAC,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import superjson, { type SuperJSONResult } from \"superjson\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport { VIEW_CONTEXT_KEY } from \"../data-llm.js\";\nimport type { UnknownObject } from \"../types.js\";\n\nexport function filterViewContext<T extends UnknownObject>(\n state?: T | null,\n): T | null {\n if (state === null || state === undefined) {\n return null;\n }\n\n const { [VIEW_CONTEXT_KEY]: _, ...filteredState } = state as T & {\n [VIEW_CONTEXT_KEY]?: unknown;\n };\n\n return filteredState as T;\n}\n\nexport function injectViewContext<T extends UnknownObject>(\n newState: T | null,\n): T | null {\n if (newState === null) {\n return null;\n }\n\n const currentState = getAdaptor()\n .getHostContextStore(\"viewState\")\n .getSnapshot() as (T & { [VIEW_CONTEXT_KEY]?: unknown }) | null;\n\n if (\n currentState !== null &&\n currentState !== undefined &&\n VIEW_CONTEXT_KEY in currentState\n ) {\n return {\n ...newState,\n [VIEW_CONTEXT_KEY]: currentState[VIEW_CONTEXT_KEY],\n } as T;\n }\n\n return newState;\n}\n\nexport function serializeState(value: UnknownObject) {\n return superjson.parse(superjson.stringify(value)); // Strips functions\n}\n\nexport function deserializeState(value: SuperJSONResult): unknown {\n return superjson.deserialize(value);\n}\n\nexport function getInitialState<State extends UnknownObject>(\n defaultState?: State | (() => State),\n): State | null {\n const viewState = getAdaptor()\n .getHostContextStore(\"viewState\")\n .getSnapshot() as State | null;\n\n if (viewState !== null && viewState !== undefined) {\n return filterViewContext(viewState);\n }\n\n return typeof defaultState === \"function\"\n ? defaultState()\n : (defaultState ?? null);\n}\n"]}
@@ -1,29 +1,29 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
3
- import { filterWidgetContext, serializeState } from "./state.js";
2
+ import { VIEW_CONTEXT_KEY } from "../data-llm.js";
3
+ import { filterViewContext, serializeState } from "./state.js";
4
4
  describe("state helpers", () => {
5
- describe("filterWidgetContext", () => {
5
+ describe("filterViewContext", () => {
6
6
  it("should return null when state is null", () => {
7
- expect(filterWidgetContext(null)).toBe(null);
7
+ expect(filterViewContext(null)).toBe(null);
8
8
  });
9
9
  it("should return null when state is undefined", () => {
10
- expect(filterWidgetContext(undefined)).toBe(null);
10
+ expect(filterViewContext(undefined)).toBe(null);
11
11
  });
12
- it("should correctly filter WIDGET_CONTEXT_KEY and preserve other properties", () => {
12
+ it("should correctly filter VIEW_CONTEXT_KEY and preserve other properties", () => {
13
13
  const stateWithContextAndOthers = {
14
14
  a: 1,
15
15
  b: "two",
16
16
  c: { nested: true },
17
- [WIDGET_CONTEXT_KEY]: "context",
17
+ [VIEW_CONTEXT_KEY]: "context",
18
18
  };
19
- const filteredWithContextAndOthers = filterWidgetContext(stateWithContextAndOthers);
19
+ const filteredWithContextAndOthers = filterViewContext(stateWithContextAndOthers);
20
20
  expect(filteredWithContextAndOthers).toEqual({
21
21
  a: 1,
22
22
  b: "two",
23
23
  c: { nested: true },
24
24
  });
25
25
  const stateNoContext = { count: 5, name: "test" };
26
- const filteredNoContext = filterWidgetContext(stateNoContext);
26
+ const filteredNoContext = filterViewContext(stateNoContext);
27
27
  expect(filteredNoContext).toEqual(stateNoContext);
28
28
  });
29
29
  });
@@ -1 +1 @@
1
- {"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../src/web/helpers/state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,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IAAI,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG;gBACb,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK;gBACL,IAAI;gBACJ,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;aACvB,CAAC;YACF,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBAC/B,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC;aAC3C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { VIEW_CONTEXT_KEY } from \"../data-llm.js\";\nimport { filterViewContext, serializeState } from \"./state.js\";\n\ndescribe(\"state helpers\", () => {\n describe(\"filterViewContext\", () => {\n it(\"should return null when state is null\", () => {\n expect(filterViewContext(null)).toBe(null);\n });\n\n it(\"should return null when state is undefined\", () => {\n expect(filterViewContext(undefined)).toBe(null);\n });\n\n it(\"should correctly filter VIEW_CONTEXT_KEY and preserve other properties\", () => {\n const stateWithContextAndOthers = {\n a: 1,\n b: \"two\",\n c: { nested: true },\n [VIEW_CONTEXT_KEY]: \"context\",\n };\n const filteredWithContextAndOthers = filterViewContext(\n stateWithContextAndOthers,\n );\n expect(filteredWithContextAndOthers).toEqual({\n a: 1,\n b: \"two\",\n c: { nested: true },\n });\n\n const stateNoContext = { count: 5, name: \"test\" };\n const filteredNoContext = filterViewContext(stateNoContext);\n expect(filteredNoContext).toEqual(stateNoContext);\n });\n });\n\n describe(\"serializeState\", () => {\n it(\"should serialize plain objects\", () => {\n const array = [1, \"two\", { three: 3 }];\n const date = new Date(\"2023-01-01T00:00:00Z\");\n const object = {\n a: 1,\n b: \"test\",\n c: true,\n array,\n date,\n function: () => \"test\",\n };\n const result = serializeState(object);\n\n expect(result).toEqual({\n a: 1,\n b: \"test\",\n c: true,\n array: [1, \"two\", { three: 3 }],\n date: new Date(\"2023-01-01T00:00:00.000Z\"),\n });\n });\n });\n});\n"]}
@@ -1,11 +1,15 @@
1
1
  export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
2
2
  export { useDisplayMode } from "./use-display-mode.js";
3
+ export { type DownloadFn, useDownload } from "./use-download.js";
3
4
  export { useFiles } from "./use-files.js";
4
5
  export { type LayoutState, useLayout } from "./use-layout.js";
5
- export { useOpenExternal } from "./use-open-external.js";
6
+ export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
7
+ export { useRegisterViewTool } from "./use-register-view-tool.js";
8
+ export { type RequestCloseFn, useRequestClose } from "./use-request-close.js";
6
9
  export { useRequestModal } from "./use-request-modal.js";
10
+ export { type RequestSizeFn, useRequestSize } from "./use-request-size.js";
7
11
  export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
8
12
  export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
9
13
  export { useToolInfo } from "./use-tool-info.js";
10
14
  export { type UserState, useUser } from "./use-user.js";
11
- export { useWidgetState } from "./use-widget-state.js";
15
+ export { useViewState } from "./use-view-state.js";
@@ -1,12 +1,16 @@
1
1
  export { useCallTool, } from "./use-call-tool.js";
2
2
  export { useDisplayMode } from "./use-display-mode.js";
3
+ export { useDownload } from "./use-download.js";
3
4
  export { useFiles } from "./use-files.js";
4
5
  export { useLayout } from "./use-layout.js";
5
6
  export { useOpenExternal } from "./use-open-external.js";
7
+ export { useRegisterViewTool } from "./use-register-view-tool.js";
8
+ export { useRequestClose } from "./use-request-close.js";
6
9
  export { useRequestModal } from "./use-request-modal.js";
10
+ export { useRequestSize } from "./use-request-size.js";
7
11
  export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
8
12
  export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
9
13
  export { useToolInfo } from "./use-tool-info.js";
10
14
  export { useUser } from "./use-user.js";
11
- export { useWidgetState } from "./use-widget-state.js";
15
+ export { useViewState } from "./use-view-state.js";
12
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAoB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type LayoutState, useLayout } from \"./use-layout.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { useRegisterViewTool } from \"./use-register-view-tool.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\n"]}
@@ -1,10 +1,14 @@
1
- import type { McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
1
+ import type { McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
2
2
  export declare class MockResizeObserver {
3
3
  observe(): void;
4
4
  unobserve(): void;
5
5
  disconnect(): void;
6
6
  }
7
- export declare const getMcpAppHostPostMessageMock: (initialContext?: McpUiHostContext) => import("vitest").Mock<(message: {
7
+ export type McpAppHostMockOptions = {
8
+ hostCapabilities?: McpUiHostCapabilities;
9
+ downloadFileResult?: McpUiDownloadFileResult;
10
+ };
11
+ export declare const getMcpAppHostPostMessageMock: (initialContext?: McpUiHostContext, options?: McpAppHostMockOptions) => import("vitest").Mock<(message: {
8
12
  method: string;
9
13
  id: number;
10
14
  }) => void>;
@@ -7,16 +7,17 @@ export class MockResizeObserver {
7
7
  disconnect() { }
8
8
  }
9
9
  const DEFAULT_CONTEXT = {};
10
- export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) => vi.fn((message) => {
10
+ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT, options = {}) => vi.fn((message) => {
11
11
  switch (message.method) {
12
12
  case "ui/initialize": {
13
13
  const result = {
14
14
  protocolVersion: "2025-06-18",
15
15
  hostInfo: { name: "test-host", version: "1.0.0" },
16
- hostCapabilities: {},
16
+ hostCapabilities: options.hostCapabilities ?? {},
17
17
  hostContext: initialContext,
18
18
  };
19
19
  act(() => fireEvent(window, new MessageEvent("message", {
20
+ source: window.parent,
20
21
  data: {
21
22
  jsonrpc: "2.0",
22
23
  id: message.id,
@@ -27,6 +28,7 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
27
28
  }
28
29
  case "ui/update-model-context": {
29
30
  act(() => fireEvent(window, new MessageEvent("message", {
31
+ source: window.parent,
30
32
  data: {
31
33
  jsonrpc: "2.0",
32
34
  id: message.id,
@@ -35,10 +37,22 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
35
37
  })));
36
38
  break;
37
39
  }
40
+ case "ui/download-file": {
41
+ act(() => fireEvent(window, new MessageEvent("message", {
42
+ source: window.parent,
43
+ data: {
44
+ jsonrpc: "2.0",
45
+ id: message.id,
46
+ result: options.downloadFileResult ?? {},
47
+ },
48
+ })));
49
+ break;
50
+ }
38
51
  }
39
52
  });
40
53
  export const fireToolInputNotification = (args) => {
41
54
  fireEvent(window, new MessageEvent("message", {
55
+ source: window.parent,
42
56
  data: {
43
57
  jsonrpc: "2.0",
44
58
  method: "ui/notifications/tool-input",
@@ -50,6 +64,7 @@ export const fireToolInputNotification = (args) => {
50
64
  };
51
65
  export const fireToolResultNotification = (params) => {
52
66
  fireEvent(window, new MessageEvent("message", {
67
+ source: window.parent,
53
68
  data: {
54
69
  jsonrpc: "2.0",
55
70
  method: "ui/notifications/tool-result",
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,OAAO,kBAAkB;IAC7B,OAAO,KAAU,CAAC;IAClB,SAAS,KAAU,CAAC;IACpB,UAAU,KAAU,CAAC;CACtB;AAED,MAAM,eAAe,GAAqB,EAAE,CAAC;AAE7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,iBAAmC,eAAe,EAClD,EAAE,CACF,EAAE,CAAC,EAAE,CAAC,CAAC,OAAuC,EAAE,EAAE;IAChD,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,MAAM,MAAM,GAA0B;gBACpC,eAAe,EAAE,YAAY;gBAC7B,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE;gBACjD,gBAAgB,EAAE,EAAE;gBACpB,WAAW,EAAE,cAAc;aAC5B,CAAC;YACF,GAAG,CAAC,GAAG,EAAE,CACP,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CAIb,SAAS,EAAE;gBACZ,IAAI,EAAE;oBACJ,OAAO,EAAE,KAAK;oBACd,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,MAAM;iBACP;aACF,CAAC,CACH,CACF,CAAC;YACF,MAAM;QACR,CAAC;QACD,KAAK,yBAAyB,CAAC,CAAC,CAAC;YAC/B,GAAG,CAAC,GAAG,EAAE,CACP,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;gBACE,IAAI,EAAE;oBACJ,OAAO,EAAE,KAAK;oBACd,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,MAAM,EAAE,EAAE;iBACX;aACF,CACF,CACF,CACF,CAAC;YACF,MAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,IAA6B,EAAE,EAAE;IACzE,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,6BAA6B;YACrC,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAI1C,EAAE,EAAE;IACH,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,8BAA8B;YACtC,MAAM;SACP;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,w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;iBACX;aACF,CACF,CACF,CACF,CAAC;YACF,MAAM;QACR,CAAC;QACD,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,GAAG,CAAC,GAAG,EAAE,CACP,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CAIb,SAAS,EAAE;gBACZ,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,IAAI,EAAE;oBACJ,OAAO,EAAE,KAAK;oBACd,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,MAAM,EAAE,OAAO,CAAC,kBAAkB,IAAI,EAAE;iBACzC;aACF,CAAC,CACH,CACF,CAAC;YACF,MAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,IAA6B,EAAE,EAAE;IACzE,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,6BAA6B;YACrC,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAI1C,EAAE,EAAE;IACH,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,8BAA8B;YACtC,MAAM;SACP;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n McpUiDownloadFileResult,\n McpUiHostCapabilities,\n McpUiHostContext,\n McpUiInitializeResult,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\nimport { fireEvent } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { vi } from \"vitest\";\n\nexport class MockResizeObserver {\n observe(): void {}\n unobserve(): void {}\n disconnect(): void {}\n}\n\nconst DEFAULT_CONTEXT: McpUiHostContext = {};\n\nexport type McpAppHostMockOptions = {\n hostCapabilities?: McpUiHostCapabilities;\n downloadFileResult?: McpUiDownloadFileResult;\n};\n\nexport const getMcpAppHostPostMessageMock = (\n initialContext: McpUiHostContext = DEFAULT_CONTEXT,\n options: McpAppHostMockOptions = {},\n) =>\n vi.fn((message: { method: string; id: number }) => {\n switch (message.method) {\n case \"ui/initialize\": {\n const result: McpUiInitializeResult = {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: options.hostCapabilities ?? {},\n hostContext: initialContext,\n };\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiInitializeResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result,\n },\n }),\n ),\n );\n break;\n }\n case \"ui/update-model-context\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{ jsonrpc: \"2.0\"; id: number; result: unknown }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {},\n },\n },\n ),\n ),\n );\n break;\n }\n case \"ui/download-file\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiDownloadFileResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: options.downloadFileResult ?? {},\n },\n }),\n ),\n );\n break;\n }\n }\n });\n\nexport const fireToolInputNotification = (args: Record<string, unknown>) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolInputNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-input\",\n params: {\n arguments: args,\n },\n },\n },\n ),\n );\n};\n\nexport const fireToolResultNotification = (params: {\n content: McpUiToolResultNotification[\"params\"][\"content\"];\n structuredContent: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n}) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolResultNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-result\",\n params,\n },\n },\n ),\n );\n};\n"]}
@@ -36,13 +36,26 @@ type CallToolErrorState = {
36
36
  data: undefined;
37
37
  error: unknown;
38
38
  };
39
+ /**
40
+ * State of a {@link useCallTool} invocation, discriminated by `status`.
41
+ * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.
42
+ */
39
43
  export type CallToolState<TData extends CallToolResponse = CallToolResponse> = CallToolIdleState | CallToolPendingState | CallToolSuccessState<TData> | CallToolErrorState;
44
+ /**
45
+ * Optional callbacks fired around a {@link useCallTool} call.
46
+ * `onSettled` runs after success or error.
47
+ */
40
48
  export type SideEffects<ToolArgs, ToolResponse> = {
41
49
  onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
42
50
  onError?: (error: unknown, toolArgs: ToolArgs) => void;
43
51
  onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
44
52
  };
45
53
  type IsArgsOptional<T> = [T] extends [null] ? true : HasRequiredKeys<T> extends false ? true : false;
54
+ /**
55
+ * Fire-and-forget call function returned by {@link useCallTool}. Tracks state
56
+ * on the hook and supports optional {@link SideEffects} callbacks. Args are
57
+ * optional when the tool accepts none.
58
+ */
46
59
  export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
47
60
  (): void;
48
61
  (sideEffects: SideEffects<TArgs, TResponse>): void;
@@ -52,11 +65,43 @@ export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ?
52
65
  (args: TArgs): void;
53
66
  (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;
54
67
  };
68
+ /**
69
+ * Promise-returning call function returned by {@link useCallTool}. Rejects
70
+ * if the tool errors; use `try/catch` for error handling.
71
+ */
55
72
  export type CallToolAsyncFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
56
73
  (): Promise<TResponse>;
57
74
  (args: TArgs): Promise<TResponse>;
58
75
  } : (args: TArgs) => Promise<TResponse>;
59
76
  type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
77
+ /**
78
+ * Call a server tool from a view and track its execution state.
79
+ *
80
+ * Returns the current {@link CallToolState} plus two callers: `callTool`
81
+ * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
82
+ * (promise-returning). If the same instance is invoked again while a call is
83
+ * in flight, the older response is dropped from the rendered state (but any
84
+ * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
85
+ *
86
+ * Pair with {@link useToolInfo} to read the result of the tool invocation
87
+ * that produced the current view. For end-to-end type safety across tool
88
+ * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
89
+ * over calling this hook directly.
90
+ *
91
+ * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
92
+ * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
97
+ *
98
+ * <button onClick={() => callTool({ query: "skybridge" }, {
99
+ * onSuccess: (res) => console.log(res.structuredContent),
100
+ * })} />
101
+ * ```
102
+ *
103
+ * @see https://docs.skybridge.tech/api-reference/use-call-tool
104
+ */
60
105
  export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
61
106
  callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
62
107
  callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
@@ -1,5 +1,33 @@
1
1
  import { useRef, useState } from "react";
2
2
  import { getAdaptor, } from "../bridges/index.js";
3
+ /**
4
+ * Call a server tool from a view and track its execution state.
5
+ *
6
+ * Returns the current {@link CallToolState} plus two callers: `callTool`
7
+ * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
8
+ * (promise-returning). If the same instance is invoked again while a call is
9
+ * in flight, the older response is dropped from the rendered state (but any
10
+ * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
11
+ *
12
+ * Pair with {@link useToolInfo} to read the result of the tool invocation
13
+ * that produced the current view. For end-to-end type safety across tool
14
+ * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
15
+ * over calling this hook directly.
16
+ *
17
+ * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
18
+ * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
23
+ *
24
+ * <button onClick={() => callTool({ query: "skybridge" }, {
25
+ * onSuccess: (res) => console.log(res.structuredContent),
26
+ * })} />
27
+ * ```
28
+ *
29
+ * @see https://docs.skybridge.tech/api-reference/use-call-tool
30
+ */
3
31
  export const useCallTool = (name) => {
4
32
  const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
5
33
  const callIdRef = useRef(0);