skybridge 0.0.0-dev.e523cea → 0.0.0-dev.e52a26e

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 (389) hide show
  1. package/README.md +152 -0
  2. package/bin/run.js +0 -4
  3. package/dist/cli/detect-port.d.ts +18 -0
  4. package/dist/cli/detect-port.js +61 -0
  5. package/dist/cli/detect-port.js.map +1 -0
  6. package/dist/cli/header.d.ts +4 -0
  7. package/dist/cli/header.js +6 -0
  8. package/dist/cli/header.js.map +1 -0
  9. package/dist/cli/resolve-views-dir.d.ts +1 -0
  10. package/dist/cli/resolve-views-dir.js +17 -0
  11. package/dist/cli/resolve-views-dir.js.map +1 -0
  12. package/dist/cli/run-command.d.ts +2 -0
  13. package/dist/cli/run-command.js +43 -0
  14. package/dist/cli/run-command.js.map +1 -0
  15. package/dist/cli/telemetry.d.ts +7 -0
  16. package/dist/cli/telemetry.js +123 -0
  17. package/dist/cli/telemetry.js.map +1 -0
  18. package/dist/cli/tunnel-control-server.d.ts +9 -0
  19. package/dist/cli/tunnel-control-server.js +31 -0
  20. package/dist/cli/tunnel-control-server.js.map +1 -0
  21. package/dist/cli/tunnel-control-server.test.js +39 -0
  22. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  23. package/dist/cli/tunnel-handler.d.ts +3 -0
  24. package/dist/cli/tunnel-handler.js +48 -0
  25. package/dist/cli/tunnel-handler.js.map +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.js +190 -0
  32. package/dist/cli/tunnel.test.js.map +1 -0
  33. package/dist/cli/types.d.ts +5 -0
  34. package/dist/cli/types.js +2 -0
  35. package/dist/cli/types.js.map +1 -0
  36. package/dist/cli/use-execute-steps.d.ts +11 -0
  37. package/dist/cli/use-execute-steps.js +36 -0
  38. package/dist/cli/use-execute-steps.js.map +1 -0
  39. package/dist/cli/use-messages.d.ts +3 -0
  40. package/dist/cli/use-messages.js +11 -0
  41. package/dist/cli/use-messages.js.map +1 -0
  42. package/dist/cli/use-nodemon.d.ts +2 -0
  43. package/dist/cli/use-nodemon.js +73 -0
  44. package/dist/cli/use-nodemon.js.map +1 -0
  45. package/dist/cli/use-open-browser.d.ts +1 -0
  46. package/dist/cli/use-open-browser.js +44 -0
  47. package/dist/cli/use-open-browser.js.map +1 -0
  48. package/dist/cli/use-tunnel.d.ts +14 -0
  49. package/dist/cli/use-tunnel.js +131 -0
  50. package/dist/cli/use-tunnel.js.map +1 -0
  51. package/dist/cli/use-typescript-check.d.ts +9 -0
  52. package/dist/cli/use-typescript-check.js +94 -0
  53. package/dist/cli/use-typescript-check.js.map +1 -0
  54. package/dist/commands/build.d.ts +9 -0
  55. package/dist/commands/build.js +87 -0
  56. package/dist/commands/build.js.map +1 -0
  57. package/dist/commands/create.d.ts +9 -0
  58. package/dist/commands/create.js +30 -0
  59. package/dist/commands/create.js.map +1 -0
  60. package/dist/commands/dev.d.ts +6 -1
  61. package/dist/commands/dev.js +87 -21
  62. package/dist/commands/dev.js.map +1 -1
  63. package/dist/commands/start.d.ts +9 -0
  64. package/dist/commands/start.js +49 -0
  65. package/dist/commands/start.js.map +1 -0
  66. package/dist/commands/telemetry/disable.d.ts +5 -0
  67. package/dist/commands/telemetry/disable.js +14 -0
  68. package/dist/commands/telemetry/disable.js.map +1 -0
  69. package/dist/commands/telemetry/enable.d.ts +5 -0
  70. package/dist/commands/telemetry/enable.js +14 -0
  71. package/dist/commands/telemetry/enable.js.map +1 -0
  72. package/dist/commands/telemetry/status.d.ts +5 -0
  73. package/dist/commands/telemetry/status.js +14 -0
  74. package/dist/commands/telemetry/status.js.map +1 -0
  75. package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
  76. package/dist/server/asset-base-url-transform-plugin.js +48 -0
  77. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  78. package/dist/server/asset-base-url-transform-plugin.test.d.ts +1 -0
  79. package/dist/server/asset-base-url-transform-plugin.test.js +134 -0
  80. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  81. package/dist/server/auth.d.ts +20 -0
  82. package/dist/server/auth.js +28 -0
  83. package/dist/server/auth.js.map +1 -0
  84. package/dist/server/content-helpers.d.ts +67 -0
  85. package/dist/server/content-helpers.js +79 -0
  86. package/dist/server/content-helpers.js.map +1 -0
  87. package/dist/server/content-helpers.test.d.ts +1 -0
  88. package/dist/server/content-helpers.test.js +70 -0
  89. package/dist/server/content-helpers.test.js.map +1 -0
  90. package/dist/server/express.d.ts +11 -0
  91. package/dist/server/express.js +101 -0
  92. package/dist/server/express.js.map +1 -0
  93. package/dist/server/express.test.d.ts +1 -0
  94. package/dist/server/express.test.js +430 -0
  95. package/dist/server/express.test.js.map +1 -0
  96. package/dist/server/file-ref.d.ts +28 -0
  97. package/dist/server/file-ref.js +27 -0
  98. package/dist/server/file-ref.js.map +1 -0
  99. package/dist/server/index.d.ts +7 -3
  100. package/dist/server/index.js +5 -2
  101. package/dist/server/index.js.map +1 -1
  102. package/dist/server/inferUtilityTypes.d.ts +6 -6
  103. package/dist/server/inferUtilityTypes.js.map +1 -1
  104. package/dist/server/metric.d.ts +14 -0
  105. package/dist/server/metric.js +62 -0
  106. package/dist/server/metric.js.map +1 -0
  107. package/dist/server/middleware.d.ts +137 -0
  108. package/dist/server/middleware.js +93 -0
  109. package/dist/server/middleware.js.map +1 -0
  110. package/dist/server/middleware.test-d.d.ts +1 -0
  111. package/dist/server/middleware.test-d.js +75 -0
  112. package/dist/server/middleware.test-d.js.map +1 -0
  113. package/dist/server/middleware.test.d.ts +1 -0
  114. package/dist/server/middleware.test.js +493 -0
  115. package/dist/server/middleware.test.js.map +1 -0
  116. package/dist/server/server.d.ts +358 -61
  117. package/dist/server/server.js +516 -87
  118. package/dist/server/server.js.map +1 -1
  119. package/dist/server/templateHelper.d.ts +5 -7
  120. package/dist/server/templateHelper.js +3 -22
  121. package/dist/server/templateHelper.js.map +1 -1
  122. package/dist/server/templates.generated.d.ts +4 -0
  123. package/dist/server/templates.generated.js +47 -0
  124. package/dist/server/templates.generated.js.map +1 -0
  125. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  126. package/dist/server/tunnel-proxy-router.js +110 -0
  127. package/dist/server/tunnel-proxy-router.js.map +1 -0
  128. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  129. package/dist/server/tunnel-proxy-router.test.js +229 -0
  130. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  131. package/dist/server/viewsDevServer.d.ts +14 -0
  132. package/dist/server/viewsDevServer.js +45 -0
  133. package/dist/server/viewsDevServer.js.map +1 -0
  134. package/dist/test/utils.d.ts +13 -21
  135. package/dist/test/utils.js +42 -37
  136. package/dist/test/utils.js.map +1 -1
  137. package/dist/test/view.test.d.ts +1 -0
  138. package/dist/test/view.test.js +568 -0
  139. package/dist/test/view.test.js.map +1 -0
  140. package/dist/version.d.ts +1 -0
  141. package/dist/version.js +3 -0
  142. package/dist/version.js.map +1 -0
  143. package/dist/web/bridges/adaptor.d.ts +50 -0
  144. package/dist/web/bridges/adaptor.js +314 -0
  145. package/dist/web/bridges/adaptor.js.map +1 -0
  146. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  147. package/dist/web/bridges/adaptor.test.js +205 -0
  148. package/dist/web/bridges/adaptor.test.js.map +1 -0
  149. package/dist/web/bridges/apps-sdk/bridge.d.ts +11 -0
  150. package/dist/web/bridges/{apps-sdk-bridge.js → apps-sdk/bridge.js} +5 -5
  151. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
  152. package/dist/web/bridges/apps-sdk/index.d.ts +4 -0
  153. package/dist/web/bridges/apps-sdk/index.js +4 -0
  154. package/dist/web/bridges/apps-sdk/index.js.map +1 -0
  155. package/dist/web/bridges/apps-sdk/types.d.ts +133 -0
  156. package/dist/web/bridges/apps-sdk/types.js +10 -0
  157. package/dist/web/bridges/apps-sdk/types.js.map +1 -0
  158. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +13 -0
  159. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +18 -0
  160. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
  161. package/dist/web/bridges/get-adaptor.d.ts +11 -0
  162. package/dist/web/bridges/get-adaptor.js +30 -0
  163. package/dist/web/bridges/get-adaptor.js.map +1 -0
  164. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  165. package/dist/web/bridges/get-adaptor.test.js +48 -0
  166. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  167. package/dist/web/bridges/host-context-stores.d.ts +27 -0
  168. package/dist/web/bridges/host-context-stores.js +73 -0
  169. package/dist/web/bridges/host-context-stores.js.map +1 -0
  170. package/dist/web/bridges/index.d.ts +5 -4
  171. package/dist/web/bridges/index.js +5 -4
  172. package/dist/web/bridges/index.js.map +1 -1
  173. package/dist/web/bridges/mcp-app/bridge.d.ts +27 -0
  174. package/dist/web/bridges/mcp-app/bridge.js +100 -0
  175. package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
  176. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  177. package/dist/web/bridges/mcp-app/bridge.test.js +21 -0
  178. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  179. package/dist/web/bridges/mcp-app/index.d.ts +3 -0
  180. package/dist/web/bridges/mcp-app/index.js +3 -0
  181. package/dist/web/bridges/mcp-app/index.js.map +1 -0
  182. package/dist/web/bridges/mcp-app/types.d.ts +8 -0
  183. package/dist/web/bridges/mcp-app/types.js +2 -0
  184. package/dist/web/bridges/mcp-app/types.js.map +1 -0
  185. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +19 -0
  186. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +19 -0
  187. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
  188. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.d.ts +1 -0
  189. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
  190. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
  191. package/dist/web/bridges/types.d.ts +159 -30
  192. package/dist/web/bridges/types.js +14 -1
  193. package/dist/web/bridges/types.js.map +1 -1
  194. package/dist/web/bridges/types.test.d.ts +1 -0
  195. package/dist/web/bridges/types.test.js +19 -0
  196. package/dist/web/bridges/types.test.js.map +1 -0
  197. package/dist/web/bridges/use-host-context.d.ts +7 -0
  198. package/dist/web/bridges/use-host-context.js +13 -0
  199. package/dist/web/bridges/use-host-context.js.map +1 -0
  200. package/dist/web/components/modal-provider.d.ts +4 -0
  201. package/dist/web/components/modal-provider.js +46 -0
  202. package/dist/web/components/modal-provider.js.map +1 -0
  203. package/dist/web/create-store.d.ts +26 -0
  204. package/dist/web/create-store.js +47 -8
  205. package/dist/web/create-store.js.map +1 -1
  206. package/dist/web/create-store.test.js +114 -53
  207. package/dist/web/create-store.test.js.map +1 -1
  208. package/dist/web/data-llm.d.ts +34 -1
  209. package/dist/web/data-llm.js +35 -5
  210. package/dist/web/data-llm.js.map +1 -1
  211. package/dist/web/data-llm.test.js +134 -65
  212. package/dist/web/data-llm.test.js.map +1 -1
  213. package/dist/web/generate-helpers.d.ts +24 -19
  214. package/dist/web/generate-helpers.js +22 -18
  215. package/dist/web/generate-helpers.js.map +1 -1
  216. package/dist/web/generate-helpers.test-d.js +26 -26
  217. package/dist/web/generate-helpers.test-d.js.map +1 -1
  218. package/dist/web/generate-helpers.test.js.map +1 -1
  219. package/dist/web/helpers/state.d.ts +2 -2
  220. package/dist/web/helpers/state.js +17 -12
  221. package/dist/web/helpers/state.js.map +1 -1
  222. package/dist/web/helpers/state.test.js +9 -9
  223. package/dist/web/helpers/state.test.js.map +1 -1
  224. package/dist/web/hooks/index.d.ts +6 -3
  225. package/dist/web/hooks/index.js +5 -2
  226. package/dist/web/hooks/index.js.map +1 -1
  227. package/dist/web/hooks/test/utils.d.ts +12 -2
  228. package/dist/web/hooks/test/utils.js +49 -14
  229. package/dist/web/hooks/test/utils.js.map +1 -1
  230. package/dist/web/hooks/use-call-tool.d.ts +48 -2
  231. package/dist/web/hooks/use-call-tool.js +30 -2
  232. package/dist/web/hooks/use-call-tool.js.map +1 -1
  233. package/dist/web/hooks/use-call-tool.test-d.js +1 -1
  234. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  235. package/dist/web/hooks/use-call-tool.test.js +64 -30
  236. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  237. package/dist/web/hooks/use-display-mode.d.ts +23 -3
  238. package/dist/web/hooks/use-display-mode.js +23 -4
  239. package/dist/web/hooks/use-display-mode.js.map +1 -1
  240. package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
  241. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  242. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  243. package/dist/web/hooks/use-display-mode.test.js +55 -20
  244. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  245. package/dist/web/hooks/use-download.d.ts +5 -0
  246. package/dist/web/hooks/use-download.js +8 -0
  247. package/dist/web/hooks/use-download.js.map +1 -0
  248. package/dist/web/hooks/use-download.test.d.ts +1 -0
  249. package/dist/web/hooks/use-download.test.js +103 -0
  250. package/dist/web/hooks/use-download.test.js.map +1 -0
  251. package/dist/web/hooks/use-files.d.ts +35 -6
  252. package/dist/web/hooks/use-files.js +37 -2
  253. package/dist/web/hooks/use-files.js.map +1 -1
  254. package/dist/web/hooks/use-files.test.js +40 -7
  255. package/dist/web/hooks/use-files.test.js.map +1 -1
  256. package/dist/web/hooks/use-layout.d.ts +4 -2
  257. package/dist/web/hooks/use-layout.js +6 -4
  258. package/dist/web/hooks/use-layout.js.map +1 -1
  259. package/dist/web/hooks/use-layout.test.js +65 -31
  260. package/dist/web/hooks/use-layout.test.js.map +1 -1
  261. package/dist/web/hooks/use-open-external.d.ts +20 -1
  262. package/dist/web/hooks/use-open-external.js +19 -3
  263. package/dist/web/hooks/use-open-external.js.map +1 -1
  264. package/dist/web/hooks/use-open-external.test.js +44 -15
  265. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  266. package/dist/web/hooks/use-request-close.d.ts +16 -0
  267. package/dist/web/hooks/use-request-close.js +21 -0
  268. package/dist/web/hooks/use-request-close.js.map +1 -0
  269. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  270. package/dist/web/hooks/use-request-close.test.js +46 -0
  271. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  272. package/dist/web/hooks/use-request-modal.d.ts +18 -3
  273. package/dist/web/hooks/use-request-modal.js +25 -8
  274. package/dist/web/hooks/use-request-modal.js.map +1 -1
  275. package/dist/web/hooks/use-request-modal.test.js +15 -1
  276. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  277. package/dist/web/hooks/use-request-size.d.ts +20 -0
  278. package/dist/web/hooks/use-request-size.js +24 -0
  279. package/dist/web/hooks/use-request-size.js.map +1 -0
  280. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  281. package/dist/web/hooks/use-request-size.test.js +47 -0
  282. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  283. package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
  284. package/dist/web/hooks/use-send-follow-up-message.js +20 -3
  285. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  286. package/dist/web/hooks/use-set-open-in-app-url.d.ts +18 -0
  287. package/dist/web/hooks/use-set-open-in-app-url.js +25 -0
  288. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  289. package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
  290. package/dist/web/hooks/use-set-open-in-app-url.test.js +63 -0
  291. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  292. package/dist/web/hooks/use-tool-info.d.ts +33 -0
  293. package/dist/web/hooks/use-tool-info.js +30 -4
  294. package/dist/web/hooks/use-tool-info.js.map +1 -1
  295. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  296. package/dist/web/hooks/use-tool-info.test.js +40 -30
  297. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  298. package/dist/web/hooks/use-user.d.ts +3 -1
  299. package/dist/web/hooks/use-user.js +22 -4
  300. package/dist/web/hooks/use-user.js.map +1 -1
  301. package/dist/web/hooks/use-user.test.js +104 -29
  302. package/dist/web/hooks/use-user.test.js.map +1 -1
  303. package/dist/web/hooks/use-view-state.d.ts +25 -0
  304. package/dist/web/hooks/use-view-state.js +32 -0
  305. package/dist/web/hooks/use-view-state.js.map +1 -0
  306. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  307. package/dist/web/hooks/use-view-state.test.js +181 -0
  308. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  309. package/dist/web/index.d.ts +1 -2
  310. package/dist/web/index.js +1 -2
  311. package/dist/web/index.js.map +1 -1
  312. package/dist/web/mount-view.d.ts +20 -0
  313. package/dist/web/mount-view.js +46 -0
  314. package/dist/web/mount-view.js.map +1 -0
  315. package/dist/web/plugin/data-llm.test.js.map +1 -1
  316. package/dist/web/plugin/plugin.d.ts +32 -1
  317. package/dist/web/plugin/plugin.js +168 -18
  318. package/dist/web/plugin/plugin.js.map +1 -1
  319. package/dist/web/plugin/scan-views.d.ts +16 -0
  320. package/dist/web/plugin/scan-views.js +88 -0
  321. package/dist/web/plugin/scan-views.js.map +1 -0
  322. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  323. package/dist/web/plugin/scan-views.test.js +99 -0
  324. package/dist/web/plugin/scan-views.test.js.map +1 -0
  325. package/dist/web/plugin/transform-data-llm.js +1 -1
  326. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  327. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  328. package/dist/web/plugin/validate-view.d.ts +1 -0
  329. package/dist/web/plugin/validate-view.js +9 -0
  330. package/dist/web/plugin/validate-view.js.map +1 -0
  331. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  332. package/dist/web/plugin/validate-view.test.js +24 -0
  333. package/dist/web/plugin/validate-view.test.js.map +1 -0
  334. package/dist/web/proxy.js +0 -1
  335. package/dist/web/proxy.js.map +1 -1
  336. package/dist/web/types.d.ts +4 -133
  337. package/dist/web/types.js +0 -9
  338. package/dist/web/types.js.map +1 -1
  339. package/package.json +56 -31
  340. package/tsconfig.base.json +33 -0
  341. package/dist/cli/use-version.d.ts +0 -1
  342. package/dist/cli/use-version.js +0 -33
  343. package/dist/cli/use-version.js.map +0 -1
  344. package/dist/server/templates/development.hbs +0 -66
  345. package/dist/server/templates/production.hbs +0 -7
  346. package/dist/server/widgetsDevServer.d.ts +0 -12
  347. package/dist/server/widgetsDevServer.js +0 -47
  348. package/dist/server/widgetsDevServer.js.map +0 -1
  349. package/dist/test/widget.test.js +0 -234
  350. package/dist/test/widget.test.js.map +0 -1
  351. package/dist/web/bridges/adaptors/apps-sdk-adaptor.d.ts +0 -13
  352. package/dist/web/bridges/adaptors/apps-sdk-adaptor.js +0 -33
  353. package/dist/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
  354. package/dist/web/bridges/adaptors/mcp-app-adaptor.d.ts +0 -16
  355. package/dist/web/bridges/adaptors/mcp-app-adaptor.js +0 -115
  356. package/dist/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
  357. package/dist/web/bridges/apps-sdk-bridge.d.ts +0 -10
  358. package/dist/web/bridges/apps-sdk-bridge.js.map +0 -1
  359. package/dist/web/bridges/hooks/use-adaptor.d.ts +0 -2
  360. package/dist/web/bridges/hooks/use-adaptor.js +0 -8
  361. package/dist/web/bridges/hooks/use-adaptor.js.map +0 -1
  362. package/dist/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
  363. package/dist/web/bridges/hooks/use-apps-sdk-bridge.js +0 -7
  364. package/dist/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
  365. package/dist/web/bridges/hooks/use-bridge.d.ts +0 -2
  366. package/dist/web/bridges/hooks/use-bridge.js +0 -8
  367. package/dist/web/bridges/hooks/use-bridge.js.map +0 -1
  368. package/dist/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -5
  369. package/dist/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
  370. package/dist/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
  371. package/dist/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -62
  372. package/dist/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
  373. package/dist/web/bridges/mcp-app-bridge.d.ts +0 -46
  374. package/dist/web/bridges/mcp-app-bridge.js +0 -217
  375. package/dist/web/bridges/mcp-app-bridge.js.map +0 -1
  376. package/dist/web/hooks/use-openai-global.d.ts +0 -3
  377. package/dist/web/hooks/use-openai-global.js +0 -6
  378. package/dist/web/hooks/use-openai-global.js.map +0 -1
  379. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  380. package/dist/web/hooks/use-widget-state.js +0 -32
  381. package/dist/web/hooks/use-widget-state.js.map +0 -1
  382. package/dist/web/hooks/use-widget-state.test.js +0 -61
  383. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  384. package/dist/web/mount-widget.d.ts +0 -1
  385. package/dist/web/mount-widget.js +0 -19
  386. package/dist/web/mount-widget.js.map +0 -1
  387. /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  388. /package/dist/{web/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
  389. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel.test.d.ts} +0 -0
@@ -0,0 +1,20 @@
1
+ import type { RequestSizeOptions } from "../bridges/types.js";
2
+ /** Function that asks the host to resize the view, returned by {@link useRequestSize}. */
3
+ export type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;
4
+ /**
5
+ * Ask the host to resize the view iframe. The applied size is host-driven —
6
+ * the host decides whether and how to honor the request, and {@link useLayout}
7
+ * still reports the final `maxHeight` it allows.
8
+ *
9
+ * Pair with a `ResizeObserver` on your root element to react to content size
10
+ * changes without hard-coded values.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const requestSize = useRequestSize();
15
+ * useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);
16
+ * ```
17
+ *
18
+ * @see https://docs.skybridge.tech/api-reference/use-request-size
19
+ */
20
+ export declare function useRequestSize(): RequestSizeFn;
@@ -0,0 +1,24 @@
1
+ import { useCallback } from "react";
2
+ import { getAdaptor } from "../bridges/index.js";
3
+ /**
4
+ * Ask the host to resize the view iframe. The applied size is host-driven —
5
+ * the host decides whether and how to honor the request, and {@link useLayout}
6
+ * still reports the final `maxHeight` it allows.
7
+ *
8
+ * Pair with a `ResizeObserver` on your root element to react to content size
9
+ * changes without hard-coded values.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const requestSize = useRequestSize();
14
+ * useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);
15
+ * ```
16
+ *
17
+ * @see https://docs.skybridge.tech/api-reference/use-request-size
18
+ */
19
+ export function useRequestSize() {
20
+ const adaptor = getAdaptor();
21
+ const requestSize = useCallback((size) => adaptor.requestSize(size), [adaptor]);
22
+ return requestSize;
23
+ }
24
+ //# sourceMappingURL=use-request-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-request-size.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EACvD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { RequestSizeOptions } from \"../bridges/types.js\";\n\n/** Function that asks the host to resize the view, returned by {@link useRequestSize}. */\nexport type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;\n\n/**\n * Ask the host to resize the view iframe. The applied size is host-driven —\n * the host decides whether and how to honor the request, and {@link useLayout}\n * still reports the final `maxHeight` it allows.\n *\n * Pair with a `ResizeObserver` on your root element to react to content size\n * changes without hard-coded values.\n *\n * @example\n * ```tsx\n * const requestSize = useRequestSize();\n * useEffect(() => { requestSize({ height: rootRef.current!.scrollHeight }); }, [content]);\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-size\n */\nexport function useRequestSize(): RequestSizeFn {\n const adaptor = getAdaptor();\n const requestSize = useCallback(\n (size: RequestSizeOptions) => adaptor.requestSize(size),\n [adaptor],\n );\n\n return requestSize;\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { _resetAdaptor } from "../bridges/get-adaptor.js";
4
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
5
+ import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
6
+ import { useRequestSize } from "./use-request-size.js";
7
+ describe("useRequestSize", () => {
8
+ let postMessageMock;
9
+ beforeEach(() => {
10
+ _resetAdaptor();
11
+ McpAppBridge.resetInstance();
12
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
13
+ vi.stubGlobal("openai", undefined);
14
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
15
+ postMessageMock = getMcpAppHostPostMessageMock();
16
+ vi.stubGlobal("parent", { postMessage: postMessageMock });
17
+ });
18
+ afterEach(() => {
19
+ vi.unstubAllGlobals();
20
+ vi.resetAllMocks();
21
+ _resetAdaptor();
22
+ McpAppBridge.resetInstance();
23
+ });
24
+ it("sends a ui/notifications/size-changed notification with width and height", async () => {
25
+ const { result } = renderHook(() => useRequestSize());
26
+ await result.current({ width: 800, height: 400 });
27
+ await waitFor(() => {
28
+ expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
29
+ jsonrpc: "2.0",
30
+ method: "ui/notifications/size-changed",
31
+ params: { width: 800, height: 400 },
32
+ }), "*");
33
+ });
34
+ });
35
+ it("forwards height-only payloads as-is", async () => {
36
+ const { result } = renderHook(() => useRequestSize());
37
+ await result.current({ height: 400 });
38
+ await waitFor(() => {
39
+ expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
40
+ jsonrpc: "2.0",
41
+ method: "ui/notifications/size-changed",
42
+ params: { height: 400 },
43
+ }), "*");
44
+ });
45
+ });
46
+ });
47
+ //# sourceMappingURL=use-request-size.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-request-size.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-size.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,eAAgE,CAAC;IAErE,UAAU,CAAC,GAAG,EAAE;QACd,aAAa,EAAE,CAAC;QAChB,YA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AAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QAEtC,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;gBACtB,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,+BAA+B;gBACvC,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;aACxB,CAAC,EACF,GAAG,CACJ,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { _resetAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useRequestSize } from \"./use-request-size.js\";\n\ndescribe(\"useRequestSize\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n _resetAdaptor();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n _resetAdaptor();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends a ui/notifications/size-changed notification with width and height\", async () => {\n const { result } = renderHook(() => useRequestSize());\n\n await result.current({ width: 800, height: 400 });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/size-changed\",\n params: { width: 800, height: 400 },\n }),\n \"*\",\n );\n });\n });\n\n it(\"forwards height-only payloads as-is\", async () => {\n const { result } = renderHook(() => useRequestSize());\n\n await result.current({ height: 400 });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/size-changed\",\n params: { height: 400 },\n }),\n \"*\",\n );\n });\n });\n});\n"]}
@@ -1 +1,19 @@
1
- export declare function useSendFollowUpMessage(): (prompt: string) => Promise<void>;
1
+ import { type SendFollowUpMessageOptions } from "../bridges/index.js";
2
+ /**
3
+ * Send a follow-up message to the LLM on behalf of the view, as if the user
4
+ * had sent it. Use to chain interactions from view UI (e.g. a button that
5
+ * triggers the next assistant turn).
6
+ *
7
+ * Pass `scrollToBottom: false` to keep the chat scroll position when the host
8
+ * posts the message. This option is Apps-SDK-only; it is silently ignored in
9
+ * the MCP Apps runtime.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const send = useSendFollowUpMessage();
14
+ * <button onClick={() => send("Summarize the last 5 results")}>Summarize</button>
15
+ * ```
16
+ *
17
+ * @see https://docs.skybridge.tech/api-reference/use-send-follow-up-message
18
+ */
19
+ export declare function useSendFollowUpMessage(): (prompt: string, options?: SendFollowUpMessageOptions) => Promise<void>;
@@ -1,8 +1,25 @@
1
1
  import { useCallback } from "react";
2
- import { useAdaptor } from "../bridges/index.js";
2
+ import { getAdaptor, } from "../bridges/index.js";
3
+ /**
4
+ * Send a follow-up message to the LLM on behalf of the view, as if the user
5
+ * had sent it. Use to chain interactions from view UI (e.g. a button that
6
+ * triggers the next assistant turn).
7
+ *
8
+ * Pass `scrollToBottom: false` to keep the chat scroll position when the host
9
+ * posts the message. This option is Apps-SDK-only; it is silently ignored in
10
+ * the MCP Apps runtime.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const send = useSendFollowUpMessage();
15
+ * <button onClick={() => send("Summarize the last 5 results")}>Summarize</button>
16
+ * ```
17
+ *
18
+ * @see https://docs.skybridge.tech/api-reference/use-send-follow-up-message
19
+ */
3
20
  export function useSendFollowUpMessage() {
4
- const adaptor = useAdaptor();
5
- const sendFollowUpMessage = useCallback((prompt) => adaptor.sendFollowUpMessage(prompt), [adaptor]);
21
+ const adaptor = getAdaptor();
22
+ const sendFollowUpMessage = useCallback((prompt, options) => adaptor.sendFollowUpMessage(prompt, options), [adaptor]);
6
23
  return sendFollowUpMessage;
7
24
  }
8
25
  //# sourceMappingURL=use-send-follow-up-message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-send-follow-up-message.js","sourceRoot":"","sources":["../../../src/web/hooks/use-send-follow-up-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,MAAc,EAAE,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,EACvD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"use-send-follow-up-message.js","sourceRoot":"","sources":["../../../src/web/hooks/use-send-follow-up-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,MAAc,EAAE,OAAoC,EAAE,EAAE,CACvD,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type SendFollowUpMessageOptions,\n} from \"../bridges/index.js\";\n\n/**\n * Send a follow-up message to the LLM on behalf of the view, as if the user\n * had sent it. Use to chain interactions from view UI (e.g. a button that\n * triggers the next assistant turn).\n *\n * Pass `scrollToBottom: false` to keep the chat scroll position when the host\n * posts the message. This option is Apps-SDK-only; it is silently ignored in\n * the MCP Apps runtime.\n *\n * @example\n * ```tsx\n * const send = useSendFollowUpMessage();\n * <button onClick={() => send(\"Summarize the last 5 results\")}>Summarize</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-send-follow-up-message\n */\nexport function useSendFollowUpMessage() {\n const adaptor = getAdaptor();\n const sendFollowUpMessage = useCallback(\n (prompt: string, options?: SendFollowUpMessageOptions) =>\n adaptor.sendFollowUpMessage(prompt, options),\n [adaptor],\n );\n\n return sendFollowUpMessage;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Override the target URL the host opens from its fullscreen "Open in <App>"
3
+ * affordance. If unset, the host opens the view's current iframe path.
4
+ *
5
+ * Currently Apps-SDK-only — calling this from MCP Apps throws.
6
+ *
7
+ * Call this once your view has enough context to construct the canonical URL
8
+ * (e.g. a permalink to the entity the user is currently viewing).
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const setOpenInAppUrl = useSetOpenInAppUrl();
13
+ * useEffect(() => { setOpenInAppUrl(`https://example.com/orders/${orderId}`); }, [orderId]);
14
+ * ```
15
+ *
16
+ * @see https://docs.skybridge.tech/api-reference/use-set-open-in-app-url
17
+ */
18
+ export declare function useSetOpenInAppUrl(): (href: string) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ import { useCallback } from "react";
2
+ import { getAdaptor } from "../bridges/index.js";
3
+ /**
4
+ * Override the target URL the host opens from its fullscreen "Open in <App>"
5
+ * affordance. If unset, the host opens the view's current iframe path.
6
+ *
7
+ * Currently Apps-SDK-only — calling this from MCP Apps throws.
8
+ *
9
+ * Call this once your view has enough context to construct the canonical URL
10
+ * (e.g. a permalink to the entity the user is currently viewing).
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const setOpenInAppUrl = useSetOpenInAppUrl();
15
+ * useEffect(() => { setOpenInAppUrl(`https://example.com/orders/${orderId}`); }, [orderId]);
16
+ * ```
17
+ *
18
+ * @see https://docs.skybridge.tech/api-reference/use-set-open-in-app-url
19
+ */
20
+ export function useSetOpenInAppUrl() {
21
+ const adaptor = getAdaptor();
22
+ const setOpenInAppUrl = useCallback((href) => adaptor.setOpenInAppUrl(href), [adaptor]);
23
+ return setOpenInAppUrl;
24
+ }
25
+ //# sourceMappingURL=use-set-open-in-app-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-set-open-in-app-url.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,eAAe,GAAG,WAAW,CACjC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAC/C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\n/**\n * Override the target URL the host opens from its fullscreen \"Open in <App>\"\n * affordance. If unset, the host opens the view's current iframe path.\n *\n * Currently Apps-SDK-only — calling this from MCP Apps throws.\n *\n * Call this once your view has enough context to construct the canonical URL\n * (e.g. a permalink to the entity the user is currently viewing).\n *\n * @example\n * ```tsx\n * const setOpenInAppUrl = useSetOpenInAppUrl();\n * useEffect(() => { setOpenInAppUrl(`https://example.com/orders/${orderId}`); }, [orderId]);\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-set-open-in-app-url\n */\nexport function useSetOpenInAppUrl() {\n const adaptor = getAdaptor();\n const setOpenInAppUrl = useCallback(\n (href: string) => adaptor.setOpenInAppUrl(href),\n [adaptor],\n );\n\n return setOpenInAppUrl;\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ import { renderHook } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
4
+ import { _resetAdaptor } from "../bridges/get-adaptor.js";
5
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
6
+ import { NotSupportedError } from "../bridges/types.js";
7
+ import { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
8
+ describe("useSetOpenInAppUrl", () => {
9
+ afterEach(() => {
10
+ vi.unstubAllGlobals();
11
+ vi.resetAllMocks();
12
+ _resetAdaptor();
13
+ AppsSdkBridge.resetInstance();
14
+ McpAppBridge.resetInstance();
15
+ });
16
+ describe("apps-sdk host", () => {
17
+ let setOpenInAppUrlMock;
18
+ beforeEach(() => {
19
+ setOpenInAppUrlMock = vi.fn().mockResolvedValue(undefined);
20
+ vi.stubGlobal("openai", {
21
+ setOpenInAppUrl: setOpenInAppUrlMock,
22
+ });
23
+ vi.stubGlobal("skybridge", {
24
+ hostType: "apps-sdk",
25
+ serverUrl: "https://example.com",
26
+ });
27
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
28
+ });
29
+ it("should return a function that calls window.openai.setOpenInAppUrl with the href", async () => {
30
+ const { result } = renderHook(() => useSetOpenInAppUrl());
31
+ const href = "https://example.com/path";
32
+ await result.current(href);
33
+ expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);
34
+ expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
35
+ });
36
+ it("should reject when href is empty", async () => {
37
+ const { result } = renderHook(() => useSetOpenInAppUrl());
38
+ await expect(result.current("")).rejects.toThrow("The href parameter is required.");
39
+ });
40
+ it("should call setOpenInAppUrl when href origin differs from serverUrl origin", async () => {
41
+ const { result } = renderHook(() => useSetOpenInAppUrl());
42
+ const href = "https://different-domain.com/path";
43
+ await result.current(href);
44
+ expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);
45
+ expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
46
+ });
47
+ });
48
+ describe("mcp-app host", () => {
49
+ beforeEach(() => {
50
+ vi.stubGlobal("openai", undefined);
51
+ vi.stubGlobal("skybridge", {
52
+ hostType: "mcp-app",
53
+ serverUrl: "https://example.com",
54
+ });
55
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
56
+ });
57
+ it("should throw NotSupportedError when called from an MCP App runtime", async () => {
58
+ const { result } = renderHook(() => useSetOpenInAppUrl());
59
+ await expect(result.current("https://example.com/path")).rejects.toBeInstanceOf(NotSupportedError);
60
+ });
61
+ });
62
+ });
63
+ //# sourceMappingURL=use-set-open-in-app-url.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-set-open-in-app-url.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACx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E,CAAC,kBAAkB,EAAE,CAAC,CAAC;YAE1D,MAAM,MAAM,CACV,MAAM,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAC3C,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { _resetAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { NotSupportedError } from \"../bridges/types.js\";\nimport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\n\ndescribe(\"useSetOpenInAppUrl\", () => {\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n _resetAdaptor();\n AppsSdkBridge.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n describe(\"apps-sdk host\", () => {\n let setOpenInAppUrlMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n setOpenInAppUrlMock = vi.fn().mockResolvedValue(undefined);\n vi.stubGlobal(\"openai\", {\n setOpenInAppUrl: setOpenInAppUrlMock,\n });\n vi.stubGlobal(\"skybridge\", {\n hostType: \"apps-sdk\",\n serverUrl: \"https://example.com\",\n });\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n it(\"should return a function that calls window.openai.setOpenInAppUrl with the href\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n const href = \"https://example.com/path\";\n await result.current(href);\n\n expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);\n expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });\n });\n\n it(\"should reject when href is empty\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n await expect(result.current(\"\")).rejects.toThrow(\n \"The href parameter is required.\",\n );\n });\n\n it(\"should call setOpenInAppUrl when href origin differs from serverUrl origin\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n const href = \"https://different-domain.com/path\";\n await result.current(href);\n\n expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);\n expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {\n hostType: \"mcp-app\",\n serverUrl: \"https://example.com\",\n });\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n it(\"should throw NotSupportedError when called from an MCP App runtime\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n await expect(\n result.current(\"https://example.com/path\"),\n ).rejects.toBeInstanceOf(NotSupportedError);\n });\n });\n});\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { UnknownObject } from "../types.js";
2
+ /** {@link useToolInfo} state before the tool has been invoked. */
2
3
  export type ToolIdleState = {
3
4
  status: "idle";
4
5
  isIdle: true;
@@ -8,6 +9,7 @@ export type ToolIdleState = {
8
9
  output: undefined;
9
10
  responseMetadata: undefined;
10
11
  };
12
+ /** {@link useToolInfo} state while the tool is executing — `input` is available, output is not yet. */
11
13
  export type ToolPendingState<ToolInput extends UnknownObject> = {
12
14
  status: "pending";
13
15
  isIdle: false;
@@ -17,6 +19,7 @@ export type ToolPendingState<ToolInput extends UnknownObject> = {
17
19
  output: undefined;
18
20
  responseMetadata: undefined;
19
21
  };
22
+ /** {@link useToolInfo} state once the tool returned — `input`, `output`, and `responseMetadata` are all available. */
20
23
  export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
21
24
  status: "success";
22
25
  isIdle: false;
@@ -26,11 +29,41 @@ export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends
26
29
  output: ToolOutput;
27
30
  responseMetadata: ToolResponseMetadata;
28
31
  };
32
+ /**
33
+ * Discriminated union describing the tool invocation that triggered the
34
+ * current view render. Use `isIdle` / `isPending` / `isSuccess` to narrow.
35
+ */
29
36
  export type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolIdleState | ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
30
37
  type ToolSignature = {
31
38
  input: UnknownObject;
32
39
  output: UnknownObject;
33
40
  responseMetadata: UnknownObject;
34
41
  };
42
+ /**
43
+ * Access the tool invocation that produced the current view: its `input`,
44
+ * resulting `output`, and `responseMetadata`. The shape evolves as the tool
45
+ * runs (idle → pending → success), exposed through {@link ToolState}.
46
+ *
47
+ * For full input/output typing per tool name, prefer the typed `useToolInfo`
48
+ * returned by {@link generateHelpers} over the generic form.
49
+ *
50
+ * @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
51
+ * to refine each field's type. When omitted, each typed field resolves to
52
+ * `never` — pass an explicit shape or use the typed helper from
53
+ * {@link generateHelpers} to get usable types.
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * const { isSuccess, input, output } = useToolInfo<{
58
+ * input: { query: string };
59
+ * output: { results: Result[] };
60
+ * }>();
61
+ *
62
+ * if (!isSuccess || !output) return <Skeleton />;
63
+ * return <Results items={output.results} />;
64
+ * ```
65
+ *
66
+ * @see https://docs.skybridge.tech/api-reference/use-tool-info
67
+ */
35
68
  export declare function useToolInfo<TS extends Partial<ToolSignature> = Record<string, never>>(): ToolState<UnknownObject & TS["input"], UnknownObject & TS["output"], UnknownObject & TS["responseMetadata"]>;
36
69
  export {};
@@ -1,4 +1,4 @@
1
- import { useBridge } from "../bridges/index.js";
1
+ import { useHostContext } from "../bridges/index.js";
2
2
  function deriveStatus(input, output, responseMetadata) {
3
3
  if (input === null) {
4
4
  return "idle";
@@ -8,10 +8,36 @@ function deriveStatus(input, output, responseMetadata) {
8
8
  }
9
9
  return "success";
10
10
  }
11
+ /**
12
+ * Access the tool invocation that produced the current view: its `input`,
13
+ * resulting `output`, and `responseMetadata`. The shape evolves as the tool
14
+ * runs (idle → pending → success), exposed through {@link ToolState}.
15
+ *
16
+ * For full input/output typing per tool name, prefer the typed `useToolInfo`
17
+ * returned by {@link generateHelpers} over the generic form.
18
+ *
19
+ * @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
20
+ * to refine each field's type. When omitted, each typed field resolves to
21
+ * `never` — pass an explicit shape or use the typed helper from
22
+ * {@link generateHelpers} to get usable types.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const { isSuccess, input, output } = useToolInfo<{
27
+ * input: { query: string };
28
+ * output: { results: Result[] };
29
+ * }>();
30
+ *
31
+ * if (!isSuccess || !output) return <Skeleton />;
32
+ * return <Results items={output.results} />;
33
+ * ```
34
+ *
35
+ * @see https://docs.skybridge.tech/api-reference/use-tool-info
36
+ */
11
37
  export function useToolInfo() {
12
- const input = useBridge("toolInput");
13
- const output = useBridge("toolOutput");
14
- const responseMetadata = useBridge("toolResponseMetadata");
38
+ const input = useHostContext("toolInput");
39
+ const output = useHostContext("toolOutput");
40
+ const responseMetadata = useHostContext("toolResponseMetadata");
15
41
  const status = deriveStatus(input, output, responseMetadata);
16
42
  return {
17
43
  input,
@@ -1 +1 @@
1
- {"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAoDhD,SAAS,YAAY,CACnB,KAAqC,EACrC,MAAsC,EACtC,gBAAgD;IAEhD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,W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,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,MAAM;QACN,gBAAgB;KACqB,CAAC;AAC1C,CAAC","sourcesContent":["import { useHostContext } from \"../bridges/index.js\";\nimport type { UnknownObject } from \"../types.js\";\n\n/** {@link useToolInfo} state before the tool has been invoked. */\nexport type ToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n input: undefined;\n output: undefined;\n responseMetadata: undefined;\n};\n\n/** {@link useToolInfo} state while the tool is executing — `input` is available, output is not yet. */\nexport type ToolPendingState<ToolInput extends UnknownObject> = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n input: ToolInput;\n output: undefined;\n responseMetadata: undefined;\n};\n\n/** {@link useToolInfo} state once the tool returned — `input`, `output`, and `responseMetadata` are all available. */\nexport type ToolSuccessState<\n ToolInput extends UnknownObject,\n ToolOutput extends UnknownObject,\n ToolResponseMetadata extends UnknownObject,\n> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n input: ToolInput;\n output: ToolOutput;\n responseMetadata: ToolResponseMetadata;\n};\n\n/**\n * Discriminated union describing the tool invocation that triggered the\n * current view render. Use `isIdle` / `isPending` / `isSuccess` to narrow.\n */\nexport type ToolState<\n ToolInput extends UnknownObject,\n ToolOutput extends UnknownObject,\n ToolResponseMetadata extends UnknownObject,\n> =\n | ToolIdleState\n | ToolPendingState<ToolInput>\n | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;\n\ntype ToolSignature = {\n input: UnknownObject;\n output: UnknownObject;\n responseMetadata: UnknownObject;\n};\n\nfunction deriveStatus(\n input: Record<string, unknown> | null,\n output: Record<string, unknown> | null,\n responseMetadata: Record<string, unknown> | null,\n): \"idle\" | \"pending\" | \"success\" {\n if (input === null) {\n return \"idle\";\n }\n if (output === null && responseMetadata === null) {\n return \"pending\";\n }\n return \"success\";\n}\n\n/**\n * Access the tool invocation that produced the current view: its `input`,\n * resulting `output`, and `responseMetadata`. The shape evolves as the tool\n * runs (idle → pending → success), exposed through {@link ToolState}.\n *\n * For full input/output typing per tool name, prefer the typed `useToolInfo`\n * returned by {@link generateHelpers} over the generic form.\n *\n * @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`\n * to refine each field's type. When omitted, each typed field resolves to\n * `never` — pass an explicit shape or use the typed helper from\n * {@link generateHelpers} to get usable types.\n *\n * @example\n * ```tsx\n * const { isSuccess, input, output } = useToolInfo<{\n * input: { query: string };\n * output: { results: Result[] };\n * }>();\n *\n * if (!isSuccess || !output) return <Skeleton />;\n * return <Results items={output.results} />;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-tool-info\n */\nexport function useToolInfo<\n TS extends Partial<ToolSignature> = Record<string, never>,\n>() {\n const input = useHostContext(\"toolInput\");\n const output = useHostContext(\"toolOutput\");\n const responseMetadata = useHostContext(\"toolResponseMetadata\");\n\n const status = deriveStatus(input, output, responseMetadata);\n\n type Input = UnknownObject & TS[\"input\"];\n type Output = UnknownObject & TS[\"output\"];\n type Metadata = UnknownObject & TS[\"responseMetadata\"];\n\n return {\n input,\n status,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n output,\n responseMetadata,\n } as ToolState<Input, Output, Metadata>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-tool-info.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,IAAI,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,iEAAiE,EAAE,GAAG,EAAE;QAC3E,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;QAE7B,YAAY,CAAiC,MAAM,CAAC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M,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAa,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ntest(\"useToolInfo - TypeScript typing\", () => {\n test(\"should have correct types when no generic parameter is provided\", () => {\n const result = useToolInfo();\n\n expectTypeOf<\"idle\" | \"pending\" | \"success\">(result.status);\n expectTypeOf<boolean>(result.isPending);\n expectTypeOf<boolean>(result.isSuccess);\n expectTypeOf<boolean>(result.isIdle);\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\n });\n\n test(\"should correctly type input, output, and responseMetadata with explicit ToolSignature\", () => {\n type TestInput = { name: string; args: { name: string } };\n type TestOutput = { name: string; color: string };\n type TestMetadata = { id: number };\n\n const result = useToolInfo<{\n input: TestInput;\n output: TestOutput;\n responseMetadata: TestMetadata;\n }>();\n\n // When idle, input should be undefined\n if (result.status === \"idle\") {\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When pending, output and responseMetadata should be undefined\n if (result.status === \"pending\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When success, output and responseMetadata should be defined\n if (result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n });\n\n test(\"should correctly narrow types based on status discriminated union\", () => {\n type TestInput = { query: string };\n type TestOutput = { result: string };\n type TestMetadata = { timestamp: number };\n\n const result = useToolInfo<{\n input: TestInput;\n output: TestOutput;\n responseMetadata: TestMetadata;\n }>();\n\n // Test type narrowing for idle\n if (result.isIdle) {\n expectTypeOf<\"idle\">(result.status);\n expectTypeOf<true>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // Test type narrowing for pending\n if (result.isPending) {\n expectTypeOf<\"pending\">(result.status);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<true>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.isSuccess) {\n expectTypeOf<\"success\">(result.status);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<true>(result.isSuccess);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n\n if (result.status === \"idle\") {\n expectTypeOf<true>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.status === \"pending\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<true>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<true>(result.isSuccess);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n });\n\n test(\"should handle partial ToolSignature with only input specified\", () => {\n type TestInput = { id: number };\n\n const result = useToolInfo<{\n input: TestInput;\n }>();\n\n // Input can be TestInput or undefined (when idle)\n if (result.status === \"pending\" || result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<Record<string, unknown>>(result.output);\n expectTypeOf<Record<string, unknown>>(result.responseMetadata);\n }\n });\n\n test(\"should handle ToolSignature with only output specified\", () => {\n type TestOutput = { data: string[] };\n\n const result = useToolInfo<{\n output: TestOutput;\n }>();\n\n // Input can be Record<string, unknown> or undefined (when idle)\n if (result.status === \"pending\" || result.status === \"success\") {\n expectTypeOf<Record<string, unknown>>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestOutput>(result.output);\n }\n });\n});\n"]}
@@ -1,37 +1,46 @@
1
- import { act, fireEvent, renderHook, waitFor } from "@testing-library/react";
1
+ import { act, renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import { McpAppAdaptor } from "../bridges/adaptors/mcp-app-adaptor.js";
4
- import { McpAppBridge } from "../bridges/mcp-app-bridge.js";
5
- import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../types.js";
6
- import { fireToolInputNotification, fireToolResultNotification, getMcpAppHostPostMessageMock, } from "./test/utils.js";
3
+ import { _resetAdaptor } from "../bridges/get-adaptor.js";
4
+ import { McpAppBridge } from "../bridges/mcp-app/index.js";
5
+ import { fireToolInputNotification, fireToolResultNotification, getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
7
6
  import { useToolInfo } from "./use-tool-info.js";
8
7
  describe("useToolInfo", () => {
9
8
  describe("apps-sdk host", () => {
10
- let OpenaiMock;
11
9
  beforeEach(() => {
12
- OpenaiMock = {
13
- toolInput: { name: "pokemon", args: { name: "pikachu" } },
10
+ vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
11
+ vi.stubGlobal("openai", {
12
+ toolInput: null,
14
13
  toolOutput: null,
15
14
  toolResponseMetadata: null,
16
- };
17
- vi.stubGlobal("openai", OpenaiMock);
15
+ });
18
16
  vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
17
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
19
18
  });
20
19
  afterEach(() => {
20
+ _resetAdaptor();
21
21
  vi.unstubAllGlobals();
22
22
  vi.resetAllMocks();
23
+ McpAppBridge.resetInstance();
23
24
  });
24
- it("should return toolInput on initial mount window.openai", () => {
25
+ it("should return pending state with tool input from tool-input notification", async () => {
25
26
  const { result } = renderHook(() => useToolInfo());
26
- expect(result.current).toMatchObject({
27
- input: { name: "pokemon", args: { name: "pikachu" } },
28
- status: "pending",
29
- isIdle: false,
30
- isPending: true,
31
- isSuccess: false,
27
+ act(() => {
28
+ fireToolInputNotification({
29
+ name: "pokemon",
30
+ args: { name: "pikachu" },
31
+ });
32
+ });
33
+ await waitFor(() => {
34
+ expect(result.current).toMatchObject({
35
+ input: { name: "pokemon", args: { name: "pikachu" } },
36
+ status: "pending",
37
+ isIdle: false,
38
+ isPending: true,
39
+ isSuccess: false,
40
+ });
32
41
  });
33
42
  });
34
- it("should eventually return tool output and response metadata once tool call completes", async () => {
43
+ it("should return success state once tool-result notification arrives", async () => {
35
44
  const toolOutput = {
36
45
  name: "pikachu",
37
46
  color: "yellow",
@@ -40,16 +49,15 @@ describe("useToolInfo", () => {
40
49
  const toolResponseMetadata = { id: 12 };
41
50
  const { result } = renderHook(() => useToolInfo());
42
51
  act(() => {
43
- OpenaiMock.toolOutput = toolOutput;
44
- OpenaiMock.toolResponseMetadata = toolResponseMetadata;
45
- fireEvent(window, new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {
46
- detail: {
47
- globals: {
48
- toolOutput,
49
- toolResponseMetadata,
50
- },
51
- },
52
- }));
52
+ fireToolInputNotification({
53
+ name: "pokemon",
54
+ args: { name: "pikachu" },
55
+ });
56
+ fireToolResultNotification({
57
+ content: [{ type: "text", text: JSON.stringify(toolOutput) }],
58
+ structuredContent: toolOutput,
59
+ _meta: toolResponseMetadata,
60
+ });
53
61
  });
54
62
  await waitFor(() => {
55
63
  expect(result.current).toMatchObject({
@@ -67,12 +75,14 @@ describe("useToolInfo", () => {
67
75
  beforeEach(() => {
68
76
  vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
69
77
  vi.stubGlobal("skybridge", { hostType: "mcp-app" });
78
+ vi.stubGlobal("openai", undefined);
79
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
70
80
  });
71
- afterEach(() => {
81
+ afterEach(async () => {
82
+ _resetAdaptor();
72
83
  vi.unstubAllGlobals();
73
84
  vi.resetAllMocks();
74
85
  McpAppBridge.resetInstance();
75
- McpAppAdaptor.resetInstance();
76
86
  });
77
87
  it("should return idle state initially when tool input is not yet set", async () => {
78
88
  const { result } = renderHook(() => useToolInfo());
@@ -1 +1 @@
1
- {"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAEL,sBAAsB,EACtB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,UAGH,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG;gBACX,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;gBACzD,UAAU,EAAE,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AE,KAAK,EAAE,QAAQ,EAAE;oBAC5C,gBAAgB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { _resetAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n fireToolInputNotification,\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ndescribe(\"useToolInfo\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"openai\", {\n toolInput: null,\n toolOutput: null,\n toolResponseMetadata: null,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n _resetAdaptor();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n input: { name: \"pokemon\", args: { name: \"pikachu\" } },\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n });\n });\n });\n\n it(\"should return success state once tool-result notification arrives\", async () => {\n const toolOutput = {\n name: \"pikachu\",\n color: \"yellow\",\n description:\n \"When several of these POKéMON gather, their\\felectricity could build and cause lightning storms.\",\n };\n const toolResponseMetadata = { id: 12 };\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n fireToolResultNotification({\n content: [{ type: \"text\", text: JSON.stringify(toolOutput) }],\n structuredContent: toolOutput,\n _meta: toolResponseMetadata,\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n output: toolOutput,\n responseMetadata: toolResponseMetadata,\n });\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n _resetAdaptor();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return idle state initially when tool input is not yet set\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"idle\",\n isIdle: true,\n isPending: false,\n isSuccess: false,\n input: null,\n output: null,\n responseMetadata: null,\n });\n });\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: { name: \"pokemon\", query: \"pikachu\" },\n });\n });\n });\n\n it(\"should return success state with output from tool-result notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"Pikachu data\" }],\n structuredContent: { name: \"pikachu\", color: \"yellow\" },\n _meta: { requestId: \"123\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n input: { name: \"pokemon\", query: \"pikachu\" },\n output: { name: \"pikachu\", color: \"yellow\" },\n responseMetadata: { requestId: \"123\" },\n });\n });\n });\n });\n});\n"]}