skybridge 0.0.0-dev.fc7beaf → 0.0.0-dev.fca7959

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 (368) hide show
  1. package/README.md +10 -7
  2. package/dist/cli/build-helpers.d.ts +11 -0
  3. package/dist/cli/build-helpers.js +107 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.js +132 -0
  6. package/dist/cli/build-helpers.test.js.map +1 -0
  7. package/dist/cli/build-steps.d.ts +2 -0
  8. package/dist/cli/build-steps.js +73 -0
  9. package/dist/cli/build-steps.js.map +1 -0
  10. package/dist/cli/build-steps.test.js +52 -0
  11. package/dist/cli/build-steps.test.js.map +1 -0
  12. package/dist/cli/detect-port.d.ts +2 -2
  13. package/dist/cli/detect-port.js +8 -20
  14. package/dist/cli/detect-port.js.map +1 -1
  15. package/dist/cli/header.d.ts +1 -1
  16. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  17. package/dist/cli/resolve-skybridge-config.js +18 -0
  18. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  19. package/dist/cli/run-plain.d.ts +18 -0
  20. package/dist/cli/run-plain.js +89 -0
  21. package/dist/cli/run-plain.js.map +1 -0
  22. package/dist/cli/use-execute-steps.d.ts +1 -1
  23. package/dist/cli/use-nodemon.d.ts +14 -0
  24. package/dist/cli/use-nodemon.js +81 -62
  25. package/dist/cli/use-nodemon.js.map +1 -1
  26. package/dist/cli/use-typescript-check.d.ts +8 -2
  27. package/dist/cli/use-typescript-check.js +70 -67
  28. package/dist/cli/use-typescript-check.js.map +1 -1
  29. package/dist/commands/build.d.ts +0 -3
  30. package/dist/commands/build.js +2 -73
  31. package/dist/commands/build.js.map +1 -1
  32. package/dist/commands/dev.d.ts +1 -0
  33. package/dist/commands/dev.js +48 -0
  34. package/dist/commands/dev.js.map +1 -1
  35. package/dist/commands/start.js +7 -1
  36. package/dist/commands/start.js.map +1 -1
  37. package/dist/context-warnings.d.ts +5 -0
  38. package/dist/context-warnings.js +31 -0
  39. package/dist/context-warnings.js.map +1 -0
  40. package/dist/context-warnings.test.js +28 -0
  41. package/dist/context-warnings.test.js.map +1 -0
  42. package/dist/server/app.d.ts +194 -0
  43. package/dist/server/app.js +266 -0
  44. package/dist/server/app.js.map +1 -0
  45. package/dist/server/app.test.js +97 -0
  46. package/dist/server/app.test.js.map +1 -0
  47. package/dist/server/auth/discovery.d.ts +33 -0
  48. package/dist/server/auth/discovery.js +56 -0
  49. package/dist/server/auth/discovery.js.map +1 -0
  50. package/dist/server/auth/discovery.test.d.ts +1 -0
  51. package/dist/server/auth/discovery.test.js +93 -0
  52. package/dist/server/auth/discovery.test.js.map +1 -0
  53. package/dist/server/auth/index.d.ts +48 -0
  54. package/dist/server/auth/index.js +2 -0
  55. package/dist/server/auth/index.js.map +1 -0
  56. package/dist/server/auth/providers/auth0.d.ts +40 -0
  57. package/dist/server/auth/providers/auth0.js +36 -0
  58. package/dist/server/auth/providers/auth0.js.map +1 -0
  59. package/dist/server/auth/providers/auth0.test.d.ts +1 -0
  60. package/dist/server/auth/providers/auth0.test.js +50 -0
  61. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  62. package/dist/server/auth/providers/authplane.d.ts +49 -0
  63. package/dist/server/auth/providers/authplane.js +57 -0
  64. package/dist/server/auth/providers/authplane.js.map +1 -0
  65. package/dist/server/auth/providers/authplane.test.d.ts +1 -0
  66. package/dist/server/auth/providers/authplane.test.js +143 -0
  67. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  68. package/dist/server/auth/providers/clerk.d.ts +51 -0
  69. package/dist/server/auth/providers/clerk.js +19 -0
  70. package/dist/server/auth/providers/clerk.js.map +1 -0
  71. package/dist/server/auth/providers/clerk.test.d.ts +1 -0
  72. package/dist/server/auth/providers/clerk.test.js +30 -0
  73. package/dist/server/auth/providers/clerk.test.js.map +1 -0
  74. package/dist/server/auth/providers/custom.d.ts +40 -0
  75. package/dist/server/auth/providers/custom.js +59 -0
  76. package/dist/server/auth/providers/custom.js.map +1 -0
  77. package/dist/server/auth/providers/custom.test.d.ts +1 -0
  78. package/dist/server/auth/providers/custom.test.js +161 -0
  79. package/dist/server/auth/providers/custom.test.js.map +1 -0
  80. package/dist/server/auth/providers/descope.d.ts +44 -0
  81. package/dist/server/auth/providers/descope.js +44 -0
  82. package/dist/server/auth/providers/descope.js.map +1 -0
  83. package/dist/server/auth/providers/descope.test.d.ts +1 -0
  84. package/dist/server/auth/providers/descope.test.js +62 -0
  85. package/dist/server/auth/providers/descope.test.js.map +1 -0
  86. package/dist/server/auth/providers/shared.d.ts +2 -0
  87. package/dist/server/auth/providers/shared.js +6 -0
  88. package/dist/server/auth/providers/shared.js.map +1 -0
  89. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  90. package/dist/server/auth/providers/shared.test.js +10 -0
  91. package/dist/server/auth/providers/shared.test.js.map +1 -0
  92. package/dist/server/auth/providers/stytch.d.ts +25 -0
  93. package/dist/server/auth/providers/stytch.js +16 -0
  94. package/dist/server/auth/providers/stytch.js.map +1 -0
  95. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  96. package/dist/server/auth/providers/verify-spy.js +21 -0
  97. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  98. package/dist/server/auth/providers/workos.d.ts +33 -0
  99. package/dist/server/auth/providers/workos.js +15 -0
  100. package/dist/server/auth/providers/workos.js.map +1 -0
  101. package/dist/server/auth/security-schemes.d.ts +23 -0
  102. package/dist/server/auth/security-schemes.js +64 -0
  103. package/dist/server/auth/security-schemes.js.map +1 -0
  104. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  105. package/dist/server/auth/security-schemes.test.js +99 -0
  106. package/dist/server/auth/security-schemes.test.js.map +1 -0
  107. package/dist/server/auth/setup.d.ts +6 -0
  108. package/dist/server/auth/setup.js +91 -0
  109. package/dist/server/auth/setup.js.map +1 -0
  110. package/dist/server/auth/setup.test.d.ts +1 -0
  111. package/dist/server/auth/setup.test.js +514 -0
  112. package/dist/server/auth/setup.test.js.map +1 -0
  113. package/dist/server/auth/verify.d.ts +46 -0
  114. package/dist/server/auth/verify.js +62 -0
  115. package/dist/server/auth/verify.js.map +1 -0
  116. package/dist/server/auth/verify.test.d.ts +1 -0
  117. package/dist/server/auth/verify.test.js +149 -0
  118. package/dist/server/auth/verify.test.js.map +1 -0
  119. package/dist/server/auth-extra.test-d.js +130 -0
  120. package/dist/server/auth-extra.test-d.js.map +1 -0
  121. package/dist/server/auth.d.ts +43 -6
  122. package/dist/server/auth.js +4 -5
  123. package/dist/server/auth.js.map +1 -1
  124. package/dist/server/build-manifest.test.d.ts +1 -0
  125. package/dist/server/build-manifest.test.js +28 -0
  126. package/dist/server/build-manifest.test.js.map +1 -0
  127. package/dist/server/content-helpers.d.ts +1 -1
  128. package/dist/server/content-helpers.js.map +1 -1
  129. package/dist/server/express.d.ts +23 -3
  130. package/dist/server/express.js +38 -32
  131. package/dist/server/express.js.map +1 -1
  132. package/dist/server/express.test.js +268 -90
  133. package/dist/server/express.test.js.map +1 -1
  134. package/dist/server/file-ref.d.ts +1 -1
  135. package/dist/server/file-ref.js +1 -1
  136. package/dist/server/file-ref.js.map +1 -1
  137. package/dist/server/host.d.ts +2 -0
  138. package/dist/server/host.js +11 -0
  139. package/dist/server/host.js.map +1 -0
  140. package/dist/server/host.test.d.ts +1 -0
  141. package/dist/server/host.test.js +13 -0
  142. package/dist/server/host.test.js.map +1 -0
  143. package/dist/server/index.d.ts +17 -3
  144. package/dist/server/index.js +14 -2
  145. package/dist/server/index.js.map +1 -1
  146. package/dist/server/mcp-errors.test.d.ts +1 -0
  147. package/dist/server/mcp-errors.test.js +41 -0
  148. package/dist/server/mcp-errors.test.js.map +1 -0
  149. package/dist/server/middleware.d.ts +35 -10
  150. package/dist/server/middleware.js +33 -0
  151. package/dist/server/middleware.js.map +1 -1
  152. package/dist/server/middleware.test-d.js +1 -1
  153. package/dist/server/middleware.test-d.js.map +1 -1
  154. package/dist/server/middleware.test.js +242 -134
  155. package/dist/server/middleware.test.js.map +1 -1
  156. package/dist/server/register-tool.test.d.ts +1 -0
  157. package/dist/server/register-tool.test.js +27 -0
  158. package/dist/server/register-tool.test.js.map +1 -0
  159. package/dist/server/requestOrigin.d.ts +7 -0
  160. package/dist/server/requestOrigin.js +25 -0
  161. package/dist/server/requestOrigin.js.map +1 -0
  162. package/dist/server/server.d.ts +144 -122
  163. package/dist/server/server.js +313 -328
  164. package/dist/server/server.js.map +1 -1
  165. package/dist/server/skills-integration.test.d.ts +1 -0
  166. package/dist/server/skills-integration.test.js +86 -0
  167. package/dist/server/skills-integration.test.js.map +1 -0
  168. package/dist/server/skills.d.ts +27 -0
  169. package/dist/server/skills.js +188 -0
  170. package/dist/server/skills.js.map +1 -0
  171. package/dist/server/skills.test.d.ts +1 -0
  172. package/dist/server/skills.test.js +243 -0
  173. package/dist/server/skills.test.js.map +1 -0
  174. package/dist/server/templateHelper.d.ts +0 -3
  175. package/dist/server/templateHelper.js.map +1 -1
  176. package/dist/server/templates.generated.js +4 -8
  177. package/dist/server/templates.generated.js.map +1 -1
  178. package/dist/server/tool-extra.test.d.ts +1 -0
  179. package/dist/server/tool-extra.test.js +88 -0
  180. package/dist/server/tool-extra.test.js.map +1 -0
  181. package/dist/server/view-name.test-d.d.ts +1 -0
  182. package/dist/server/view-name.test-d.js +8 -0
  183. package/dist/server/view-name.test-d.js.map +1 -0
  184. package/dist/server/view-resource-resolution.test.d.ts +6 -0
  185. package/dist/server/view-resource-resolution.test.js +176 -0
  186. package/dist/server/view-resource-resolution.test.js.map +1 -0
  187. package/dist/server/viewsDevServer.js +4 -1
  188. package/dist/server/viewsDevServer.js.map +1 -1
  189. package/dist/test/utils.d.ts +9 -11
  190. package/dist/test/utils.js +220 -201
  191. package/dist/test/utils.js.map +1 -1
  192. package/dist/test/view.test.js +105 -133
  193. package/dist/test/view.test.js.map +1 -1
  194. package/dist/views/index.d.ts +10 -0
  195. package/dist/views/index.js +3 -0
  196. package/dist/views/index.js.map +1 -0
  197. package/dist/{web/plugin → views}/scan-views.js +1 -1
  198. package/dist/views/scan-views.js.map +1 -0
  199. package/dist/views/scan-views.test.d.ts +1 -0
  200. package/dist/views/scan-views.test.js.map +1 -0
  201. package/dist/views/validate-view.d.ts +1 -0
  202. package/dist/{web/plugin → views}/validate-view.js +2 -2
  203. package/dist/views/validate-view.js.map +1 -0
  204. package/dist/views/validate-view.test.d.ts +1 -0
  205. package/dist/views/validate-view.test.js.map +1 -0
  206. package/dist/web/bridges/adaptor.d.ts +51 -0
  207. package/dist/web/bridges/adaptor.js +327 -0
  208. package/dist/web/bridges/adaptor.js.map +1 -0
  209. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  210. package/dist/web/bridges/adaptor.test.js +225 -0
  211. package/dist/web/bridges/adaptor.test.js.map +1 -0
  212. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  213. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  214. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  215. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  216. package/dist/web/bridges/apps-sdk/index.js +0 -1
  217. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  218. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
  219. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
  220. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  221. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  222. package/dist/web/bridges/get-adaptor.js +6 -11
  223. package/dist/web/bridges/get-adaptor.js.map +1 -1
  224. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  225. package/dist/web/bridges/get-adaptor.test.js +32 -0
  226. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  227. package/dist/web/bridges/mcp-app/bridge.d.ts +15 -3
  228. package/dist/web/bridges/mcp-app/bridge.js +73 -8
  229. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  230. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  231. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  232. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  233. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  234. package/dist/web/bridges/mcp-app/index.js +0 -1
  235. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  236. package/dist/web/bridges/mcp-app/types.d.ts +2 -0
  237. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  238. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
  239. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  240. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  241. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  242. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  243. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  244. package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
  245. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  246. package/dist/web/bridges/types.d.ts +55 -7
  247. package/dist/web/bridges/types.js +14 -1
  248. package/dist/web/bridges/types.js.map +1 -1
  249. package/dist/web/bridges/types.test.d.ts +1 -0
  250. package/dist/web/bridges/types.test.js +19 -0
  251. package/dist/web/bridges/types.test.js.map +1 -0
  252. package/dist/web/components/modal-provider.d.ts +1 -1
  253. package/dist/web/components/modal-provider.js +4 -3
  254. package/dist/web/components/modal-provider.js.map +1 -1
  255. package/dist/web/create-store.test.js +10 -7
  256. package/dist/web/create-store.test.js.map +1 -1
  257. package/dist/web/data-llm.d.ts +1 -1
  258. package/dist/web/data-llm.test.js +20 -7
  259. package/dist/web/data-llm.test.js.map +1 -1
  260. package/dist/web/generate-helpers.d.ts +22 -18
  261. package/dist/web/generate-helpers.js +19 -15
  262. package/dist/web/generate-helpers.js.map +1 -1
  263. package/dist/web/generate-helpers.test-d.js +7 -5
  264. package/dist/web/generate-helpers.test-d.js.map +1 -1
  265. package/dist/web/generate-helpers.test.js +2 -2
  266. package/dist/web/generate-helpers.test.js.map +1 -1
  267. package/dist/web/hooks/index.d.ts +3 -1
  268. package/dist/web/hooks/index.js +3 -1
  269. package/dist/web/hooks/index.js.map +1 -1
  270. package/dist/web/hooks/test/utils.d.ts +2 -1
  271. package/dist/web/hooks/test/utils.js +1 -1
  272. package/dist/web/hooks/test/utils.js.map +1 -1
  273. package/dist/web/hooks/use-call-tool.test.js +39 -25
  274. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  275. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  276. package/dist/web/hooks/use-display-mode.js +1 -1
  277. package/dist/web/hooks/use-display-mode.js.map +1 -1
  278. package/dist/web/hooks/use-display-mode.test.js +57 -21
  279. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  280. package/dist/web/hooks/use-download.d.ts +1 -3
  281. package/dist/web/hooks/use-download.js +1 -2
  282. package/dist/web/hooks/use-download.js.map +1 -1
  283. package/dist/web/hooks/use-download.test.js +18 -10
  284. package/dist/web/hooks/use-download.test.js.map +1 -1
  285. package/dist/web/hooks/use-files.test.js +11 -3
  286. package/dist/web/hooks/use-files.test.js.map +1 -1
  287. package/dist/web/hooks/use-host.d.ts +22 -0
  288. package/dist/web/hooks/use-host.js +30 -0
  289. package/dist/web/hooks/use-host.js.map +1 -0
  290. package/dist/web/hooks/use-host.test.d.ts +1 -0
  291. package/dist/web/hooks/use-host.test.js +59 -0
  292. package/dist/web/hooks/use-host.test.js.map +1 -0
  293. package/dist/web/hooks/use-open-external.test.js +15 -5
  294. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  295. package/dist/web/hooks/use-register-view-tool.d.ts +37 -0
  296. package/dist/web/hooks/use-register-view-tool.js +50 -0
  297. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  298. package/dist/web/hooks/use-request-close.test.js +35 -40
  299. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  300. package/dist/web/hooks/use-request-modal.test.js +11 -1
  301. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  302. package/dist/web/hooks/use-request-size.d.ts +1 -1
  303. package/dist/web/hooks/use-request-size.js +1 -1
  304. package/dist/web/hooks/use-request-size.js.map +1 -1
  305. package/dist/web/hooks/use-request-size.test.js +35 -53
  306. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  307. package/dist/web/hooks/use-set-open-in-app-url.test.js +26 -12
  308. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  309. package/dist/web/hooks/use-tool-info.d.ts +18 -19
  310. package/dist/web/hooks/use-tool-info.js +4 -8
  311. package/dist/web/hooks/use-tool-info.js.map +1 -1
  312. package/dist/web/hooks/use-tool-info.test-d.js +11 -34
  313. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  314. package/dist/web/hooks/use-tool-info.test.js +42 -37
  315. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  316. package/dist/web/hooks/use-user.d.ts +3 -2
  317. package/dist/web/hooks/use-user.js +4 -3
  318. package/dist/web/hooks/use-user.js.map +1 -1
  319. package/dist/web/hooks/use-user.test.js +85 -37
  320. package/dist/web/hooks/use-user.test.js.map +1 -1
  321. package/dist/web/hooks/use-view-state.js +19 -9
  322. package/dist/web/hooks/use-view-state.js.map +1 -1
  323. package/dist/web/hooks/use-view-state.test.js +39 -4
  324. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  325. package/dist/web/hooks/use-viewport.d.ts +20 -0
  326. package/dist/web/hooks/use-viewport.js +21 -0
  327. package/dist/web/hooks/use-viewport.js.map +1 -0
  328. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  329. package/dist/web/hooks/use-viewport.test.js +109 -0
  330. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  331. package/dist/web/mount-view.d.ts +3 -2
  332. package/dist/web/mount-view.js +5 -8
  333. package/dist/web/mount-view.js.map +1 -1
  334. package/package.json +32 -26
  335. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -28
  336. package/dist/web/bridges/apps-sdk/adaptor.js +0 -113
  337. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  338. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -52
  339. package/dist/web/bridges/mcp-app/adaptor.js +0 -280
  340. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  341. package/dist/web/hooks/use-layout.d.ts +0 -24
  342. package/dist/web/hooks/use-layout.js +0 -25
  343. package/dist/web/hooks/use-layout.js.map +0 -1
  344. package/dist/web/hooks/use-layout.test.js +0 -96
  345. package/dist/web/hooks/use-layout.test.js.map +0 -1
  346. package/dist/web/plugin/data-llm.test.js +0 -81
  347. package/dist/web/plugin/data-llm.test.js.map +0 -1
  348. package/dist/web/plugin/plugin.d.ts +0 -33
  349. package/dist/web/plugin/plugin.js +0 -189
  350. package/dist/web/plugin/plugin.js.map +0 -1
  351. package/dist/web/plugin/scan-views.js.map +0 -1
  352. package/dist/web/plugin/scan-views.test.js.map +0 -1
  353. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  354. package/dist/web/plugin/transform-data-llm.js +0 -96
  355. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  356. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  357. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  358. package/dist/web/plugin/validate-view.d.ts +0 -1
  359. package/dist/web/plugin/validate-view.js.map +0 -1
  360. package/dist/web/plugin/validate-view.test.js.map +0 -1
  361. /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  362. /package/dist/{web/plugin/data-llm.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  363. /package/dist/{web/plugin/scan-views.test.d.ts → context-warnings.test.d.ts} +0 -0
  364. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/app.test.d.ts} +0 -0
  365. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  366. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  367. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  368. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"use-files.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-files.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,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,MAAM,UAAU,GAA4B;QAC1C,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;YACpC,MAAM,EAAE,wBAAwB;SACjC,CAAC;QACF,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE;QAC3B,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE;KACxB,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;QACnB,cAAc,CAAC,aAAa,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IAE3C,EAAE,CAAC,iCAA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;QAErC,OAAO,UAAU,CAAC,WAAW,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { AppsSdkAdaptor } from \"../bridges/apps-sdk/adaptor.js\";\nimport { useFiles } from \"./use-files.js\";\n\ndescribe(\"useFiles\", () => {\n const OpenaiMock: Record<string, unknown> = {\n uploadFile: vi.fn().mockResolvedValue({\n fileId: `sediment://file_abc123`,\n }),\n getFileDownloadUrl: vi.fn(),\n widgetState: null,\n setWidgetState: vi.fn(),\n };\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", OpenaiMock);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n AppsSdkAdaptor.resetInstance();\n });\n\n const dummyFile = new File([], \"test.txt\");\n\n it(\"should upload a file to ChatGPT\", () => {\n const { result } = renderHook(() => useFiles());\n\n result.current.upload(dummyFile);\n expect(OpenaiMock.uploadFile).toHaveBeenCalledWith(dummyFile, undefined);\n });\n\n it(\"should upload a file with library option\", () => {\n const { result } = renderHook(() => useFiles());\n\n result.current.upload(dummyFile, { library: true });\n expect(OpenaiMock.uploadFile).toHaveBeenCalledWith(dummyFile, {\n library: true,\n });\n });\n\n it(\"should select files from ChatGPT\", async () => {\n const selectedFiles = [\n { fileId: \"file_1\", fileName: \"doc.pdf\", mimeType: \"application/pdf\" },\n ];\n OpenaiMock.selectFiles = vi.fn().mockResolvedValue(selectedFiles);\n\n const { result } = renderHook(() => useFiles());\n\n const files = await result.current.selectFiles();\n expect(OpenaiMock.selectFiles).toHaveBeenCalled();\n expect(files).toEqual(selectedFiles);\n\n delete OpenaiMock.selectFiles;\n });\n\n it(\"should download a file from ChatGPT\", () => {\n const fileId = \"123\";\n const { result } = renderHook(() => useFiles());\n\n result.current.getDownloadUrl({ fileId });\n expect(OpenaiMock.getFileDownloadUrl).toHaveBeenCalledWith({ fileId });\n });\n});\n"]}
1
+ {"version":3,"file":"use-files.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-files.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,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,MAAM,UAAU,GAA4B;QAC1C,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;YACpC,MAAM,EAAE,wBAAwB;SACjC,CAAC;QACF,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE;QAC3B,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE;KACxB,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC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AC,oBAAoB,CAAC,SAAS,EAAE;YAC5D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QAChD,MAAM,aAAa,GAAG;YACpB,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE;SACvE,CAAC;QACF,UAAU,CAAC,WAAW,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAElE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACjD,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAErC,OAAO,UAAU,CAAC,WAAW,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { useFiles } from \"./use-files.js\";\n\ndescribe(\"useFiles\", () => {\n const OpenaiMock: Record<string, unknown> = {\n uploadFile: vi.fn().mockResolvedValue({\n fileId: `sediment://file_abc123`,\n }),\n getFileDownloadUrl: vi.fn(),\n widgetState: null,\n setWidgetState: vi.fn(),\n };\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n const dummyFile = new File([], \"test.txt\");\n\n it(\"should upload a file to ChatGPT\", () => {\n const { result } = renderHook(() => useFiles());\n\n result.current.upload(dummyFile);\n expect(OpenaiMock.uploadFile).toHaveBeenCalledWith(dummyFile, undefined);\n });\n\n it(\"should upload a file with library option\", () => {\n const { result } = renderHook(() => useFiles());\n\n result.current.upload(dummyFile, { library: true });\n expect(OpenaiMock.uploadFile).toHaveBeenCalledWith(dummyFile, {\n library: true,\n });\n });\n\n it(\"should select files from ChatGPT\", async () => {\n const selectedFiles = [\n { fileId: \"file_1\", fileName: \"doc.pdf\", mimeType: \"application/pdf\" },\n ];\n OpenaiMock.selectFiles = vi.fn().mockResolvedValue(selectedFiles);\n\n const { result } = renderHook(() => useFiles());\n\n const files = await result.current.selectFiles();\n expect(OpenaiMock.selectFiles).toHaveBeenCalled();\n expect(files).toEqual(selectedFiles);\n\n delete OpenaiMock.selectFiles;\n });\n\n it(\"should download a file from ChatGPT\", () => {\n const fileId = \"123\";\n const { result } = renderHook(() => useFiles());\n\n result.current.getDownloadUrl({ fileId });\n expect(OpenaiMock.getFileDownloadUrl).toHaveBeenCalledWith({ fileId });\n });\n});\n"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Known host applications, as normalized slugs. Unrecognized hosts surface
3
+ * their raw `hostInfo.name` string instead.
4
+ */
5
+ export type Host = "chatgpt" | "claude" | "cursor" | "goose" | "mistral-vibe" | "alpic";
6
+ export type HostInfo = {
7
+ name: Host | (string & {}) | undefined;
8
+ version: string | undefined;
9
+ };
10
+ /**
11
+ * Identity of the host application rendering the view, from the MCP Apps
12
+ * `ui/initialize` handshake. `name` is normalized to a {@link Host} slug when
13
+ * recognized, otherwise the raw string; both fields are `undefined` until the
14
+ * handshake resolves (the view renders first and re-renders once it lands).
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const { name } = useHost();
19
+ * if (name === "claude") return <ClaudeLayout />;
20
+ * ```
21
+ */
22
+ export declare function useHost(): HostInfo;
@@ -0,0 +1,30 @@
1
+ import { useMcpAppContext } from "../bridges/index.js";
2
+ const HOST_BY_REPORTED_NAME = {
3
+ chatgpt: "chatgpt",
4
+ Claude: "claude",
5
+ Cursor: "cursor",
6
+ "MCP-UI Host": "goose",
7
+ "Le Chat": "mistral-vibe",
8
+ "alpic-playground": "alpic",
9
+ };
10
+ /**
11
+ * Identity of the host application rendering the view, from the MCP Apps
12
+ * `ui/initialize` handshake. `name` is normalized to a {@link Host} slug when
13
+ * recognized, otherwise the raw string; both fields are `undefined` until the
14
+ * handshake resolves (the view renders first and re-renders once it lands).
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const { name } = useHost();
19
+ * if (name === "claude") return <ClaudeLayout />;
20
+ * ```
21
+ */
22
+ export function useHost() {
23
+ const hostInfo = useMcpAppContext("hostInfo");
24
+ const name = hostInfo?.name;
25
+ return {
26
+ name: name !== undefined ? (HOST_BY_REPORTED_NAME[name] ?? name) : undefined,
27
+ version: hostInfo?.version,
28
+ };
29
+ }
30
+ //# sourceMappingURL=use-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-host.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAcvD,MAAM,qBAAqB,GAAyB;IAClD,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,aAAa,EAAE,OAAO;IACtB,SAAS,EAAE,cAAc;IACzB,kBAAkB,EAAE,OAAO;CAC5B,CAAC;AAOF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC;IAE5B,OAAO;QACL,IAAI,EACF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QACxE,OAAO,EAAE,QAAQ,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import { useMcpAppContext } from \"../bridges/index.js\";\n\n/**\n * Known host applications, as normalized slugs. Unrecognized hosts surface\n * their raw `hostInfo.name` string instead.\n */\nexport type Host =\n | \"chatgpt\"\n | \"claude\"\n | \"cursor\"\n | \"goose\"\n | \"mistral-vibe\"\n | \"alpic\";\n\nconst HOST_BY_REPORTED_NAME: Record<string, Host> = {\n chatgpt: \"chatgpt\",\n Claude: \"claude\",\n Cursor: \"cursor\",\n \"MCP-UI Host\": \"goose\",\n \"Le Chat\": \"mistral-vibe\",\n \"alpic-playground\": \"alpic\",\n};\n\nexport type HostInfo = {\n name: Host | (string & {}) | undefined;\n version: string | undefined;\n};\n\n/**\n * Identity of the host application rendering the view, from the MCP Apps\n * `ui/initialize` handshake. `name` is normalized to a {@link Host} slug when\n * recognized, otherwise the raw string; both fields are `undefined` until the\n * handshake resolves (the view renders first and re-renders once it lands).\n *\n * @example\n * ```tsx\n * const { name } = useHost();\n * if (name === \"claude\") return <ClaudeLayout />;\n * ```\n */\nexport function useHost(): HostInfo {\n const hostInfo = useMcpAppContext(\"hostInfo\");\n const name = hostInfo?.name;\n\n return {\n name:\n name !== undefined ? (HOST_BY_REPORTED_NAME[name] ?? name) : undefined,\n version: hostInfo?.version,\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
5
+ import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
6
+ import { useHost } from "./use-host.js";
7
+ const stubHost = (hostInfo) => {
8
+ vi.stubGlobal("parent", {
9
+ postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),
10
+ });
11
+ };
12
+ describe("useHost", () => {
13
+ beforeEach(() => {
14
+ HostAdaptor.resetInstance();
15
+ McpAppBridge.resetInstance();
16
+ vi.stubGlobal("openai", undefined);
17
+ vi.stubGlobal("skybridge", {});
18
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
19
+ });
20
+ afterEach(() => {
21
+ vi.unstubAllGlobals();
22
+ vi.resetAllMocks();
23
+ McpAppBridge.resetInstance();
24
+ HostAdaptor.resetInstance();
25
+ });
26
+ it("is undefined before the handshake resolves, then populated after", async () => {
27
+ stubHost({ name: "Claude", version: "1.2.3" });
28
+ const { result } = renderHook(() => useHost());
29
+ expect(result.current.name).toBeUndefined();
30
+ expect(result.current.version).toBeUndefined();
31
+ await waitFor(() => {
32
+ expect(result.current.name).toBe("claude");
33
+ expect(result.current.version).toBe("1.2.3");
34
+ });
35
+ });
36
+ it.each([
37
+ ["chatgpt", "chatgpt"],
38
+ ["Claude", "claude"],
39
+ ["Cursor", "cursor"],
40
+ ["MCP-UI Host", "goose"],
41
+ ["Le Chat", "mistral-vibe"],
42
+ ["alpic-playground", "alpic"],
43
+ ])("normalizes reported name %j to slug %j", async (reported, slug) => {
44
+ stubHost({ name: reported, version: "1.0.0" });
45
+ const { result } = renderHook(() => useHost());
46
+ await waitFor(() => {
47
+ expect(result.current.name).toBe(slug);
48
+ });
49
+ });
50
+ it("preserves an unrecognized reported name as-is", async () => {
51
+ stubHost({ name: "Some Future Host", version: "9.9.9" });
52
+ const { result } = renderHook(() => useHost());
53
+ await waitFor(() => {
54
+ expect(result.current.name).toBe("Some Future Host");
55
+ expect(result.current.version).toBe("9.9.9");
56
+ });
57
+ });
58
+ });
59
+ //# sourceMappingURL=use-host.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-host.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host.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,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAa,OAAO,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,QAAQ,GAAG,CAAC,QAA4C,EAAE,EAAE;IAChE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;QACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;KAC5D,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,E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CAAC,aAAa,EAAE,OAAO,CAAC;QACxB,CAAC,SAAS,EAAE,cAAc,CAAC;QAC3B,CAAC,kBAAkB,EAAE,OAAO,CAAC;KAC9B,CAAC,CAAC,wCAAwC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QACpE,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/C,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/C,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,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 { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { type Host, useHost } from \"./use-host.js\";\n\nconst stubHost = (hostInfo?: { name: string; version: string }) => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),\n });\n};\n\ndescribe(\"useHost\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"is undefined before the handshake resolves, then populated after\", async () => {\n stubHost({ name: \"Claude\", version: \"1.2.3\" });\n const { result } = renderHook(() => useHost());\n\n expect(result.current.name).toBeUndefined();\n expect(result.current.version).toBeUndefined();\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"claude\");\n expect(result.current.version).toBe(\"1.2.3\");\n });\n });\n\n it.each<[string, Host]>([\n [\"chatgpt\", \"chatgpt\"],\n [\"Claude\", \"claude\"],\n [\"Cursor\", \"cursor\"],\n [\"MCP-UI Host\", \"goose\"],\n [\"Le Chat\", \"mistral-vibe\"],\n [\"alpic-playground\", \"alpic\"],\n ])(\"normalizes reported name %j to slug %j\", async (reported, slug) => {\n stubHost({ name: reported, version: \"1.0.0\" });\n const { result } = renderHook(() => useHost());\n\n await waitFor(() => {\n expect(result.current.name).toBe(slug);\n });\n });\n\n it(\"preserves an unrecognized reported name as-is\", async () => {\n stubHost({ name: \"Some Future Host\", version: \"9.9.9\" });\n const { result } = renderHook(() => useHost());\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"Some Future Host\");\n expect(result.current.version).toBe(\"9.9.9\");\n });\n });\n});\n"]}
@@ -1,30 +1,38 @@
1
1
  import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
3
4
  import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
4
5
  import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
5
6
  import { useOpenExternal } from "./use-open-external.js";
6
7
  describe("useOpenExternal", () => {
7
8
  describe("apps-sdk host", () => {
8
9
  let openExternalMock;
10
+ let postMessageMock;
9
11
  beforeEach(() => {
10
12
  openExternalMock = vi.fn();
11
13
  vi.stubGlobal("openai", {
12
14
  openExternal: openExternalMock,
13
15
  });
14
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
16
+ vi.stubGlobal("skybridge", {});
17
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
18
+ postMessageMock = getMcpAppHostPostMessageMock();
19
+ vi.stubGlobal("parent", { postMessage: postMessageMock });
15
20
  });
16
21
  afterEach(() => {
22
+ HostAdaptor.resetInstance();
23
+ McpAppBridge.resetInstance();
17
24
  vi.unstubAllGlobals();
18
25
  vi.resetAllMocks();
19
26
  });
20
- it("should return a function that calls window.openai.openExternal with the href", () => {
27
+ it("should call window.openai.openExternal even without a redirectUrl option", () => {
21
28
  const { result } = renderHook(() => useOpenExternal());
22
29
  const href = "https://example.com";
23
30
  result.current(href);
24
31
  expect(openExternalMock).toHaveBeenCalledTimes(1);
25
32
  expect(openExternalMock).toHaveBeenCalledWith({ href });
33
+ expect(postMessageMock).not.toHaveBeenCalledWith(expect.objectContaining({ method: "ui/open-link" }), "*");
26
34
  });
27
- it("should forward redirectUrl false option to window.openai.openExternal", () => {
35
+ it("should call window.openai.openExternal when redirectUrl is false", () => {
28
36
  const { result } = renderHook(() => useOpenExternal());
29
37
  const href = "https://example.com";
30
38
  result.current(href, { redirectUrl: false });
@@ -38,15 +46,17 @@ describe("useOpenExternal", () => {
38
46
  describe("mcp-app host", () => {
39
47
  let postMessageMock;
40
48
  beforeEach(() => {
41
- vi.stubGlobal("skybridge", { hostType: "mcp-app" });
49
+ vi.stubGlobal("openai", undefined);
50
+ vi.stubGlobal("skybridge", {});
42
51
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
43
52
  postMessageMock = getMcpAppHostPostMessageMock();
44
53
  vi.stubGlobal("parent", { postMessage: postMessageMock });
45
54
  });
46
55
  afterEach(async () => {
56
+ HostAdaptor.resetInstance();
57
+ McpAppBridge.resetInstance();
47
58
  vi.unstubAllGlobals();
48
59
  vi.resetAllMocks();
49
- McpAppBridge.resetInstance();
50
60
  });
51
61
  it("should return a function that sends ui/open-link request to the MCP host", async () => {
52
62
  const { result } = renderHook(() => useOpenExternal());
@@ -1 +1 @@
1
- {"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.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,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,gBAA0C,CAAC;QAE/C,UAAU,CAAC,GAAG,EAAE;YACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,YAAY,EAAE,gBAAgB;aAC/B,CAAC,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,SAAS,CAA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BAAkB,CAAC,CAAC;YACpD,eAAe,GAAG,4BAA4B,EAAE,CAAC;YACjD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,KAAK,IAAI,EAAE;YACnB,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;YACnB,YAAY,CAAC,aAAa,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;YACxF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;YAEvD,MAAM,IAAI,GAAG,qBAAqB,CAAC;YACnC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;YAE7C,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,cAAc;oBACtB,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;iBACtB,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,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 { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useOpenExternal } from \"./use-open-external.js\";\n\ndescribe(\"useOpenExternal\", () => {\n describe(\"apps-sdk host\", () => {\n let openExternalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n openExternalMock = vi.fn();\n vi.stubGlobal(\"openai\", {\n openExternal: openExternalMock,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return a function that calls window.openai.openExternal with the href\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href);\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({ href });\n });\n\n it(\"should forward redirectUrl false option to window.openai.openExternal\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({\n href,\n redirectUrl: false,\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return a function that sends ui/open-link request to the MCP host\", async () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/open-link\",\n params: { url: href },\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,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BAAkB,CAAC,CAAC;YACpD,eAAe,GAAG,4BAA4B,EAAE,CAAC;YACjD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,KAAK,IAAI,EAAE;YACnB,WAAW,CAAC,aAAa,EAAE,CAAC;YAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;YACxF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;YAEvD,MAAM,IAAI,GAAG,qBAAqB,CAAC;YACnC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;YAE7C,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,cAAc;oBACtB,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;iBACtB,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,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 { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useOpenExternal } from \"./use-open-external.js\";\n\ndescribe(\"useOpenExternal\", () => {\n describe(\"apps-sdk host\", () => {\n let openExternalMock: ReturnType<typeof vi.fn>;\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n openExternalMock = vi.fn();\n vi.stubGlobal(\"openai\", {\n openExternal: openExternalMock,\n });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should call window.openai.openExternal even without a redirectUrl option\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href);\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({ href });\n expect(postMessageMock).not.toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/open-link\" }),\n \"*\",\n );\n });\n\n it(\"should call window.openai.openExternal when redirectUrl is false\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({\n href,\n redirectUrl: false,\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return a function that sends ui/open-link request to the MCP host\", async () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/open-link\",\n params: { url: href },\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
@@ -0,0 +1,37 @@
1
+ import type { ViewToolConfig, ViewToolHandler, ViewToolInputShape } from "../bridges/types.js";
2
+ /**
3
+ * Register a tool the view exposes to the host and model — the MCP Apps
4
+ * "app-provided tools" feature. A view tool runs *inside the view*: the host
5
+ * discovers it via `tools/list` and invokes it via `tools/call`, and the
6
+ * handler executes against the view's live state. It is the inverse of
7
+ * {@link useCallTool} (which calls a server tool). Registered on mount, removed
8
+ * on unmount; re-registered when `config.name` changes.
9
+ *
10
+ * MCP Apps only — on the Apps SDK (`window.openai`) runtime it is a no-op.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import * as z from "zod";
15
+ * import { useRegisterViewTool } from "skybridge/web";
16
+ *
17
+ * useRegisterViewTool(
18
+ * {
19
+ * name: "chess_make_move",
20
+ * description: "Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.",
21
+ * inputSchema: { san: z.string() },
22
+ * annotations: { readOnlyHint: false },
23
+ * },
24
+ * ({ san }) => {
25
+ * const move = game.move(san);
26
+ * return {
27
+ * content: [{ type: "text", text: move ? `Played ${move.san}` : "Illegal move" }],
28
+ * structuredContent: { fen: game.fen() },
29
+ * isError: !move,
30
+ * };
31
+ * },
32
+ * );
33
+ * ```
34
+ *
35
+ * @see https://docs.skybridge.tech/api-reference/use-register-view-tool
36
+ */
37
+ export declare const useRegisterViewTool: <TInput extends ViewToolInputShape = ViewToolInputShape>(config: ViewToolConfig<TInput>, handler: ViewToolHandler<TInput>) => void;
@@ -0,0 +1,50 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { getAdaptor } from "../bridges/index.js";
3
+ /**
4
+ * Register a tool the view exposes to the host and model — the MCP Apps
5
+ * "app-provided tools" feature. A view tool runs *inside the view*: the host
6
+ * discovers it via `tools/list` and invokes it via `tools/call`, and the
7
+ * handler executes against the view's live state. It is the inverse of
8
+ * {@link useCallTool} (which calls a server tool). Registered on mount, removed
9
+ * on unmount; re-registered when `config.name` changes.
10
+ *
11
+ * MCP Apps only — on the Apps SDK (`window.openai`) runtime it is a no-op.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import * as z from "zod";
16
+ * import { useRegisterViewTool } from "skybridge/web";
17
+ *
18
+ * useRegisterViewTool(
19
+ * {
20
+ * name: "chess_make_move",
21
+ * description: "Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.",
22
+ * inputSchema: { san: z.string() },
23
+ * annotations: { readOnlyHint: false },
24
+ * },
25
+ * ({ san }) => {
26
+ * const move = game.move(san);
27
+ * return {
28
+ * content: [{ type: "text", text: move ? `Played ${move.san}` : "Illegal move" }],
29
+ * structuredContent: { fen: game.fen() },
30
+ * isError: !move,
31
+ * };
32
+ * },
33
+ * );
34
+ * ```
35
+ *
36
+ * @see https://docs.skybridge.tech/api-reference/use-register-view-tool
37
+ */
38
+ export const useRegisterViewTool = (config, handler) => {
39
+ const { name } = config;
40
+ const configRef = useRef(config);
41
+ configRef.current = config;
42
+ const handlerRef = useRef(handler);
43
+ handlerRef.current = handler;
44
+ useEffect(() => {
45
+ const adaptor = getAdaptor();
46
+ const wrappedHandler = (args) => handlerRef.current(args);
47
+ return adaptor.registerViewTool({ ...configRef.current, name }, wrappedHandler);
48
+ }, [name]);
49
+ };
50
+ //# sourceMappingURL=use-register-view-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-register-view-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-register-view-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAGjC,MAA8B,EAC9B,OAAgC,EAChC,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAuB,CAAC,IAAI,EAAE,EAAE,CAClD,UAAU,CAAC,OAAO,CAAC,IAA8C,CAAC,CAAC;QAErE,OAAO,OAAO,CAAC,gBAAgB,CAC7B,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAC9B,cAAc,CACf,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type {\n AnyViewToolHandler,\n ViewToolConfig,\n ViewToolHandler,\n ViewToolInputShape,\n} from \"../bridges/types.js\";\n\n/**\n * Register a tool the view exposes to the host and model — the MCP Apps\n * \"app-provided tools\" feature. A view tool runs *inside the view*: the host\n * discovers it via `tools/list` and invokes it via `tools/call`, and the\n * handler executes against the view's live state. It is the inverse of\n * {@link useCallTool} (which calls a server tool). Registered on mount, removed\n * on unmount; re-registered when `config.name` changes.\n *\n * MCP Apps only — on the Apps SDK (`window.openai`) runtime it is a no-op.\n *\n * @example\n * ```tsx\n * import * as z from \"zod\";\n * import { useRegisterViewTool } from \"skybridge/web\";\n *\n * useRegisterViewTool(\n * {\n * name: \"chess_make_move\",\n * description: \"Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.\",\n * inputSchema: { san: z.string() },\n * annotations: { readOnlyHint: false },\n * },\n * ({ san }) => {\n * const move = game.move(san);\n * return {\n * content: [{ type: \"text\", text: move ? `Played ${move.san}` : \"Illegal move\" }],\n * structuredContent: { fen: game.fen() },\n * isError: !move,\n * };\n * },\n * );\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-register-view-tool\n */\nexport const useRegisterViewTool = <\n TInput extends ViewToolInputShape = ViewToolInputShape,\n>(\n config: ViewToolConfig<TInput>,\n handler: ViewToolHandler<TInput>,\n) => {\n const { name } = config;\n const configRef = useRef(config);\n configRef.current = config;\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n\n useEffect(() => {\n const adaptor = getAdaptor();\n const wrappedHandler: AnyViewToolHandler = (args) =>\n handlerRef.current(args as Parameters<ViewToolHandler<TInput>>[0]);\n\n return adaptor.registerViewTool(\n { ...configRef.current, name },\n wrappedHandler,\n );\n }, [name]);\n};\n"]}
@@ -1,52 +1,47 @@
1
- import { renderHook, waitFor } from "@testing-library/react";
1
+ import { act, renderHook } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { getAdaptor } from "../bridges/get-adaptor.js";
3
5
  import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
4
- import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
5
6
  import { useRequestClose } from "./use-request-close.js";
6
7
  describe("useRequestClose", () => {
7
- describe("apps-sdk host", () => {
8
- let requestCloseMock;
9
- beforeEach(() => {
10
- requestCloseMock = vi.fn().mockResolvedValue(undefined);
11
- vi.stubGlobal("openai", {
12
- requestClose: requestCloseMock,
13
- });
14
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
15
- });
16
- afterEach(() => {
17
- vi.unstubAllGlobals();
18
- vi.resetAllMocks();
19
- });
20
- it("should return a function that calls window.openai.requestClose", async () => {
21
- const { result } = renderHook(() => useRequestClose());
8
+ beforeEach(() => {
9
+ HostAdaptor.resetInstance();
10
+ McpAppBridge.resetInstance();
11
+ vi.stubGlobal("skybridge", {});
12
+ vi.stubGlobal("openai", undefined);
13
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
14
+ });
15
+ afterEach(() => {
16
+ vi.unstubAllGlobals();
17
+ vi.resetAllMocks();
18
+ HostAdaptor.resetInstance();
19
+ McpAppBridge.resetInstance();
20
+ });
21
+ it("calls app.requestTeardown via the MCP path", async () => {
22
+ const requestTeardown = vi.fn().mockResolvedValue(undefined);
23
+ // biome-ignore lint/suspicious/noExplicitAny: test seam
24
+ const adaptor = getAdaptor();
25
+ adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });
26
+ const { result } = renderHook(() => useRequestClose());
27
+ await act(async () => {
22
28
  await result.current();
23
- expect(requestCloseMock).toHaveBeenCalledTimes(1);
24
- expect(requestCloseMock).toHaveBeenCalledWith();
25
29
  });
30
+ expect(requestTeardown).toHaveBeenCalledTimes(1);
26
31
  });
27
- describe("mcp-app host", () => {
28
- let postMessageMock;
29
- beforeEach(() => {
30
- vi.stubGlobal("skybridge", { hostType: "mcp-app" });
31
- vi.stubGlobal("ResizeObserver", MockResizeObserver);
32
- postMessageMock = getMcpAppHostPostMessageMock();
33
- vi.stubGlobal("parent", { postMessage: postMessageMock });
34
- });
35
- afterEach(async () => {
36
- vi.unstubAllGlobals();
37
- vi.resetAllMocks();
38
- McpAppBridge.resetInstance();
39
- });
40
- it("should send a ui/notifications/request-teardown notification to the MCP host", async () => {
41
- const { result } = renderHook(() => useRequestClose());
32
+ it("calls app.requestTeardown even when window.openai is present", async () => {
33
+ vi.stubGlobal("openai", { requestClose: vi.fn() });
34
+ HostAdaptor.resetInstance();
35
+ McpAppBridge.resetInstance();
36
+ const requestTeardown = vi.fn().mockResolvedValue(undefined);
37
+ // biome-ignore lint/suspicious/noExplicitAny: test seam
38
+ const adaptor = getAdaptor();
39
+ adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });
40
+ const { result } = renderHook(() => useRequestClose());
41
+ await act(async () => {
42
42
  await result.current();
43
- await waitFor(() => {
44
- expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
45
- jsonrpc: "2.0",
46
- method: "ui/notifications/request-teardown",
47
- }), "*");
48
- });
49
43
  });
44
+ expect(requestTeardown).toHaveBeenCalledTimes(1);
50
45
  });
51
46
  });
52
47
  //# sourceMappingURL=use-request-close.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-request-close.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-close.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,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,gBAA0C,CAAC;QAE/C,UAAU,CAAC,GAAG,EAAE;YACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YACxD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,YAAY,EAAE,gBAAgB;aAC/B,CAAC,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE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AAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;iBAC5C,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,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 { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useRequestClose } from \"./use-request-close.js\";\n\ndescribe(\"useRequestClose\", () => {\n describe(\"apps-sdk host\", () => {\n let requestCloseMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n requestCloseMock = vi.fn().mockResolvedValue(undefined);\n vi.stubGlobal(\"openai\", {\n requestClose: requestCloseMock,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return a function that calls window.openai.requestClose\", async () => {\n const { result } = renderHook(() => useRequestClose());\n\n await result.current();\n\n expect(requestCloseMock).toHaveBeenCalledTimes(1);\n expect(requestCloseMock).toHaveBeenCalledWith();\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should send a ui/notifications/request-teardown notification to the MCP host\", async () => {\n const { result } = renderHook(() => useRequestClose());\n\n await result.current();\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/request-teardown\",\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-request-close.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-close.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC/B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;QACnB,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,C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AC;QACvD,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { useRequestClose } from \"./use-request-close.js\";\n\ndescribe(\"useRequestClose\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"calls app.requestTeardown via the MCP path\", async () => {\n const requestTeardown = vi.fn().mockResolvedValue(undefined);\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n const adaptor = getAdaptor() as any;\n adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });\n\n const { result } = renderHook(() => useRequestClose());\n await act(async () => {\n await result.current();\n });\n\n expect(requestTeardown).toHaveBeenCalledTimes(1);\n });\n\n it(\"calls app.requestTeardown even when window.openai is present\", async () => {\n vi.stubGlobal(\"openai\", { requestClose: vi.fn() });\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n\n const requestTeardown = vi.fn().mockResolvedValue(undefined);\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n const adaptor = getAdaptor() as any;\n adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });\n\n const { result } = renderHook(() => useRequestClose());\n await act(async () => {\n await result.current();\n });\n\n expect(requestTeardown).toHaveBeenCalledTimes(1);\n });\n});\n"]}
@@ -1,11 +1,18 @@
1
1
  import { renderHook } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
5
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
3
6
  import { useRequestModal } from "./use-request-modal.js";
4
7
  describe("useRequestModal", () => {
5
8
  let requestModalMock;
6
9
  beforeEach(() => {
10
+ HostAdaptor.resetInstance();
11
+ McpAppBridge.resetInstance();
12
+ AppsSdkBridge.resetInstance();
7
13
  requestModalMock = vi.fn();
8
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
14
+ vi.stubGlobal("skybridge", {});
15
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
9
16
  vi.stubGlobal("openai", {
10
17
  requestModal: requestModalMock,
11
18
  view: { mode: "inline" },
@@ -14,6 +21,9 @@ describe("useRequestModal", () => {
14
21
  afterEach(() => {
15
22
  vi.unstubAllGlobals();
16
23
  vi.resetAllMocks();
24
+ HostAdaptor.resetInstance();
25
+ McpAppBridge.resetInstance();
26
+ AppsSdkBridge.resetInstance();
17
27
  });
18
28
  it("should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal", () => {
19
29
  const { result } = renderHook(() => useRequestModal());
@@ -1 +1 @@
1
- {"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.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,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD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;YACd,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;YACtB,QAAQ,EAAE,+BAA+B;SAC1C,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,CAAC;QAEd,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { useRequestModal } from \"./use-request-modal.js\";\n\ndescribe(\"useRequestModal\", () => {\n let requestModalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n requestModalMock = vi.fn();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"inline\" },\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal\", () => {\n const { result } = renderHook(() => useRequestModal());\n\n expect(typeof result.current).toBe(\"object\");\n expect(result.current).toHaveProperty(\"open\");\n expect(result.current).toHaveProperty(\"isOpen\");\n expect(result.current).toHaveProperty(\"params\");\n\n const { open, isOpen, params } = result.current;\n expect(typeof open).toBe(\"function\");\n expect(isOpen).toBe(false);\n expect(params).toBeUndefined();\n });\n\n it(\"should return isOpen as true when mode is modal\", () => {\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\" },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { isOpen } = result.current;\n\n expect(isOpen).toBe(true);\n });\n\n it(\"should return params from view when available\", () => {\n const testParams = { foo: \"bar\", baz: 42 };\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\", params: testParams },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { params } = result.current;\n\n expect(params).toEqual(testParams);\n });\n\n it(\"should call window.openai.requestModal with the options when open is called\", () => {\n const { result } = renderHook(() => useRequestModal());\n const { open } = result.current;\n\n const options = {\n title: \"Test Modal\",\n params: { foo: \"bar\" },\n template: \"ui://view/modal-template.html\",\n };\n open(options);\n\n expect(requestModalMock).toHaveBeenCalledTimes(1);\n expect(requestModalMock).toHaveBeenCalledWith(options);\n });\n});\n"]}
1
+ {"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.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,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA0C,CAAC;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,aAAa,CAAC,aAAa,EAAE,CAAC;QAC9B,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC/B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAClD,EAAE,CAAC,UAA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;QAEd,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { useRequestModal } from \"./use-request-modal.js\";\n\ndescribe(\"useRequestModal\", () => {\n let requestModalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n requestModalMock = vi.fn();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"inline\" },\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal\", () => {\n const { result } = renderHook(() => useRequestModal());\n\n expect(typeof result.current).toBe(\"object\");\n expect(result.current).toHaveProperty(\"open\");\n expect(result.current).toHaveProperty(\"isOpen\");\n expect(result.current).toHaveProperty(\"params\");\n\n const { open, isOpen, params } = result.current;\n expect(typeof open).toBe(\"function\");\n expect(isOpen).toBe(false);\n expect(params).toBeUndefined();\n });\n\n it(\"should return isOpen as true when mode is modal\", () => {\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\" },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { isOpen } = result.current;\n\n expect(isOpen).toBe(true);\n });\n\n it(\"should return params from view when available\", () => {\n const testParams = { foo: \"bar\", baz: 42 };\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\", params: testParams },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { params } = result.current;\n\n expect(params).toEqual(testParams);\n });\n\n it(\"should call window.openai.requestModal with the options when open is called\", () => {\n const { result } = renderHook(() => useRequestModal());\n const { open } = result.current;\n\n const options = {\n title: \"Test Modal\",\n params: { foo: \"bar\" },\n template: \"ui://view/modal-template.html\",\n };\n open(options);\n\n expect(requestModalMock).toHaveBeenCalledTimes(1);\n expect(requestModalMock).toHaveBeenCalledWith(options);\n });\n});\n"]}
@@ -3,7 +3,7 @@ import type { RequestSizeOptions } from "../bridges/types.js";
3
3
  export type RequestSizeFn = (size: RequestSizeOptions) => Promise<void>;
4
4
  /**
5
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}
6
+ * the host decides whether and how to honor the request, and {@link useViewport}
7
7
  * still reports the final `maxHeight` it allows.
8
8
  *
9
9
  * Pair with a `ResizeObserver` on your root element to react to content size
@@ -2,7 +2,7 @@ import { useCallback } from "react";
2
2
  import { getAdaptor } from "../bridges/index.js";
3
3
  /**
4
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}
5
+ * the host decides whether and how to honor the request, and {@link useViewport}
6
6
  * still reports the final `maxHeight` it allows.
7
7
  *
8
8
  * Pair with a `ResizeObserver` on your root element to react to content size
@@ -1 +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"]}
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 useViewport}\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"]}