skybridge 0.0.0-dev.febcf34 → 0.0.0-dev.fec0253

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 (343) hide show
  1. package/README.md +16 -14
  2. package/dist/cli/build-helpers.d.ts +3 -2
  3. package/dist/cli/build-helpers.js +24 -10
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +48 -5
  6. package/dist/cli/build-helpers.test.js.map +1 -1
  7. package/dist/cli/build-steps.js +10 -5
  8. package/dist/cli/build-steps.js.map +1 -1
  9. package/dist/cli/build-steps.test.js +3 -3
  10. package/dist/cli/build-steps.test.js.map +1 -1
  11. package/dist/cli/detect-port.js +0 -1
  12. package/dist/cli/detect-port.js.map +1 -1
  13. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  14. package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
  15. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  16. package/dist/cli/run-plain.js +2 -1
  17. package/dist/cli/run-plain.js.map +1 -1
  18. package/dist/cli/telemetry.js +2 -0
  19. package/dist/cli/telemetry.js.map +1 -1
  20. package/dist/cli/use-nodemon.d.ts +11 -1
  21. package/dist/cli/use-nodemon.js +31 -9
  22. package/dist/cli/use-nodemon.js.map +1 -1
  23. package/dist/cli/use-typescript-check.js +1 -1
  24. package/dist/cli/use-typescript-check.js.map +1 -1
  25. package/dist/commands/dev.js +6 -6
  26. package/dist/commands/dev.js.map +1 -1
  27. package/dist/commands/start.js +2 -2
  28. package/dist/commands/start.js.map +1 -1
  29. package/dist/context-warnings.d.ts +5 -0
  30. package/dist/context-warnings.js +31 -0
  31. package/dist/context-warnings.js.map +1 -0
  32. package/dist/context-warnings.test.js +28 -0
  33. package/dist/context-warnings.test.js.map +1 -0
  34. package/dist/server/app.d.ts +194 -0
  35. package/dist/server/app.js +266 -0
  36. package/dist/server/app.js.map +1 -0
  37. package/dist/server/app.test.js +97 -0
  38. package/dist/server/app.test.js.map +1 -0
  39. package/dist/server/auth/discovery.d.ts +2 -1
  40. package/dist/server/auth/discovery.js +2 -2
  41. package/dist/server/auth/discovery.js.map +1 -1
  42. package/dist/server/auth/index.d.ts +35 -5
  43. package/dist/server/auth/index.js.map +1 -1
  44. package/dist/server/auth/providers/auth0.d.ts +25 -3
  45. package/dist/server/auth/providers/auth0.js +13 -8
  46. package/dist/server/auth/providers/auth0.js.map +1 -1
  47. package/dist/server/auth/providers/auth0.test.js +5 -3
  48. package/dist/server/auth/providers/auth0.test.js.map +1 -1
  49. package/dist/server/auth/providers/authplane.d.ts +49 -0
  50. package/dist/server/auth/providers/authplane.js +57 -0
  51. package/dist/server/auth/providers/authplane.js.map +1 -0
  52. package/dist/server/auth/providers/authplane.test.js +143 -0
  53. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  54. package/dist/server/auth/providers/clerk.d.ts +40 -3
  55. package/dist/server/auth/providers/clerk.js +4 -1
  56. package/dist/server/auth/providers/clerk.js.map +1 -1
  57. package/dist/server/auth/providers/clerk.test.js +5 -3
  58. package/dist/server/auth/providers/clerk.test.js.map +1 -1
  59. package/dist/server/auth/providers/custom.d.ts +24 -6
  60. package/dist/server/auth/providers/custom.js +33 -11
  61. package/dist/server/auth/providers/custom.js.map +1 -1
  62. package/dist/server/auth/providers/custom.test.js +71 -17
  63. package/dist/server/auth/providers/custom.test.js.map +1 -1
  64. package/dist/server/auth/providers/descope.d.ts +32 -3
  65. package/dist/server/auth/providers/descope.js +12 -2
  66. package/dist/server/auth/providers/descope.js.map +1 -1
  67. package/dist/server/auth/providers/descope.test.js +42 -18
  68. package/dist/server/auth/providers/descope.test.js.map +1 -1
  69. package/dist/server/auth/providers/stytch.d.ts +16 -3
  70. package/dist/server/auth/providers/stytch.js +4 -1
  71. package/dist/server/auth/providers/stytch.js.map +1 -1
  72. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  73. package/dist/server/auth/providers/verify-spy.js +21 -0
  74. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  75. package/dist/server/auth/providers/workos.d.ts +28 -5
  76. package/dist/server/auth/providers/workos.js +6 -2
  77. package/dist/server/auth/providers/workos.js.map +1 -1
  78. package/dist/server/auth/security-schemes.d.ts +23 -0
  79. package/dist/server/auth/security-schemes.js +64 -0
  80. package/dist/server/auth/security-schemes.js.map +1 -0
  81. package/dist/server/auth/security-schemes.test.js +99 -0
  82. package/dist/server/auth/security-schemes.test.js.map +1 -0
  83. package/dist/server/auth/setup.d.ts +3 -1
  84. package/dist/server/auth/setup.js +66 -26
  85. package/dist/server/auth/setup.js.map +1 -1
  86. package/dist/server/auth/setup.test.js +349 -20
  87. package/dist/server/auth/setup.test.js.map +1 -1
  88. package/dist/server/auth/verify.d.ts +42 -6
  89. package/dist/server/auth/verify.js +27 -3
  90. package/dist/server/auth/verify.js.map +1 -1
  91. package/dist/server/auth/verify.test.js +65 -0
  92. package/dist/server/auth/verify.test.js.map +1 -1
  93. package/dist/server/auth-extra.test-d.js +130 -0
  94. package/dist/server/auth-extra.test-d.js.map +1 -0
  95. package/dist/server/auth.d.ts +43 -6
  96. package/dist/server/auth.js +4 -5
  97. package/dist/server/auth.js.map +1 -1
  98. package/dist/server/build-manifest.test.js +7 -6
  99. package/dist/server/build-manifest.test.js.map +1 -1
  100. package/dist/server/content-helpers.d.ts +1 -1
  101. package/dist/server/content-helpers.js.map +1 -1
  102. package/dist/server/events.d.ts +113 -0
  103. package/dist/server/events.js +318 -0
  104. package/dist/server/events.js.map +1 -0
  105. package/dist/server/events.test.d.ts +1 -0
  106. package/dist/server/events.test.js +172 -0
  107. package/dist/server/events.test.js.map +1 -0
  108. package/dist/server/express.d.ts +23 -3
  109. package/dist/server/express.js +43 -32
  110. package/dist/server/express.js.map +1 -1
  111. package/dist/server/express.test.js +221 -103
  112. package/dist/server/express.test.js.map +1 -1
  113. package/dist/server/file-ref.d.ts +1 -1
  114. package/dist/server/file-ref.js +1 -1
  115. package/dist/server/file-ref.js.map +1 -1
  116. package/dist/server/form-input.d.ts +120 -0
  117. package/dist/server/form-input.js +89 -0
  118. package/dist/server/form-input.js.map +1 -0
  119. package/dist/server/host.d.ts +2 -0
  120. package/dist/server/host.js +11 -0
  121. package/dist/server/host.js.map +1 -0
  122. package/dist/server/host.test.d.ts +1 -0
  123. package/dist/server/host.test.js +13 -0
  124. package/dist/server/host.test.js.map +1 -0
  125. package/dist/server/index.d.ts +18 -9
  126. package/dist/server/index.js +11 -3
  127. package/dist/server/index.js.map +1 -1
  128. package/dist/server/mcp-errors.test.d.ts +1 -0
  129. package/dist/server/mcp-errors.test.js +41 -0
  130. package/dist/server/mcp-errors.test.js.map +1 -0
  131. package/dist/server/middleware.d.ts +35 -10
  132. package/dist/server/middleware.js +33 -0
  133. package/dist/server/middleware.js.map +1 -1
  134. package/dist/server/middleware.test-d.js +1 -1
  135. package/dist/server/middleware.test-d.js.map +1 -1
  136. package/dist/server/middleware.test.js +242 -134
  137. package/dist/server/middleware.test.js.map +1 -1
  138. package/dist/server/register-tool.test.d.ts +1 -0
  139. package/dist/server/register-tool.test.js +230 -0
  140. package/dist/server/register-tool.test.js.map +1 -0
  141. package/dist/server/server.d.ts +373 -128
  142. package/dist/server/server.js +441 -274
  143. package/dist/server/server.js.map +1 -1
  144. package/dist/server/skills-integration.test.d.ts +1 -0
  145. package/dist/server/skills-integration.test.js +86 -0
  146. package/dist/server/skills-integration.test.js.map +1 -0
  147. package/dist/server/skills.d.ts +27 -0
  148. package/dist/server/skills.js +188 -0
  149. package/dist/server/skills.js.map +1 -0
  150. package/dist/server/skills.test.d.ts +1 -0
  151. package/dist/server/skills.test.js +243 -0
  152. package/dist/server/skills.test.js.map +1 -0
  153. package/dist/server/templateHelper.d.ts +0 -3
  154. package/dist/server/templateHelper.js.map +1 -1
  155. package/dist/server/templates.generated.js +4 -8
  156. package/dist/server/templates.generated.js.map +1 -1
  157. package/dist/server/tool-extra.test.d.ts +1 -0
  158. package/dist/server/tool-extra.test.js +167 -0
  159. package/dist/server/tool-extra.test.js.map +1 -0
  160. package/dist/server/view-resource-resolution.test.js +18 -13
  161. package/dist/server/view-resource-resolution.test.js.map +1 -1
  162. package/dist/server/viewsDevServer.js +4 -1
  163. package/dist/server/viewsDevServer.js.map +1 -1
  164. package/dist/test/utils.d.ts +9 -11
  165. package/dist/test/utils.js +220 -201
  166. package/dist/test/utils.js.map +1 -1
  167. package/dist/test/view.test.js +44 -40
  168. package/dist/test/view.test.js.map +1 -1
  169. package/dist/views/index.d.ts +10 -0
  170. package/dist/views/index.js +3 -0
  171. package/dist/views/index.js.map +1 -0
  172. package/dist/{web/plugin → views}/scan-views.js +1 -1
  173. package/dist/views/scan-views.js.map +1 -0
  174. package/dist/views/scan-views.test.d.ts +1 -0
  175. package/dist/views/scan-views.test.js.map +1 -0
  176. package/dist/views/validate-view.d.ts +1 -0
  177. package/dist/{web/plugin → views}/validate-view.js +2 -2
  178. package/dist/views/validate-view.js.map +1 -0
  179. package/dist/views/validate-view.test.d.ts +1 -0
  180. package/dist/views/validate-view.test.js.map +1 -0
  181. package/dist/web/bridges/adaptor.d.ts +14 -3
  182. package/dist/web/bridges/adaptor.js +171 -30
  183. package/dist/web/bridges/adaptor.js.map +1 -1
  184. package/dist/web/bridges/adaptor.test.js +69 -13
  185. package/dist/web/bridges/adaptor.test.js.map +1 -1
  186. package/dist/web/bridges/apps-sdk/bridge.js +1 -1
  187. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  188. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +4 -4
  189. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +4 -4
  190. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  191. package/dist/web/bridges/get-adaptor.test.js +2 -2
  192. package/dist/web/bridges/get-adaptor.test.js.map +1 -1
  193. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -1
  194. package/dist/web/bridges/mcp-app/bridge.js +15 -6
  195. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  196. package/dist/web/bridges/mcp-app/bridge.test.js +2 -2
  197. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -1
  198. package/dist/web/bridges/mcp-app/types.d.ts +19 -2
  199. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  200. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
  201. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  202. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  203. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  204. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  205. package/dist/web/bridges/mcp-app/view-tools.test.js +1 -1
  206. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  207. package/dist/web/bridges/types.d.ts +74 -16
  208. package/dist/web/bridges/types.js +1 -1
  209. package/dist/web/bridges/types.js.map +1 -1
  210. package/dist/web/create-store.test.js +2 -2
  211. package/dist/web/create-store.test.js.map +1 -1
  212. package/dist/web/data-llm.js +3 -2
  213. package/dist/web/data-llm.js.map +1 -1
  214. package/dist/web/data-llm.test.js +11 -4
  215. package/dist/web/data-llm.test.js.map +1 -1
  216. package/dist/web/generate-helpers.d.ts +23 -19
  217. package/dist/web/generate-helpers.js +21 -17
  218. package/dist/web/generate-helpers.js.map +1 -1
  219. package/dist/web/generate-helpers.test-d.js +3 -3
  220. package/dist/web/generate-helpers.test-d.js.map +1 -1
  221. package/dist/web/generate-helpers.test.js +2 -2
  222. package/dist/web/generate-helpers.test.js.map +1 -1
  223. package/dist/web/hooks/index.d.ts +6 -1
  224. package/dist/web/hooks/index.js +6 -1
  225. package/dist/web/hooks/index.js.map +1 -1
  226. package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
  227. package/dist/web/hooks/openai-extensions.test.js +107 -0
  228. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  229. package/dist/web/hooks/test/utils.d.ts +2 -1
  230. package/dist/web/hooks/test/utils.js +1 -1
  231. package/dist/web/hooks/test/utils.js.map +1 -1
  232. package/dist/web/hooks/use-call-tool.d.ts +2 -2
  233. package/dist/web/hooks/use-call-tool.js +15 -10
  234. package/dist/web/hooks/use-call-tool.js.map +1 -1
  235. package/dist/web/hooks/use-call-tool.test.js +15 -4
  236. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  237. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  238. package/dist/web/hooks/use-deep-link.js +34 -0
  239. package/dist/web/hooks/use-deep-link.js.map +1 -0
  240. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  241. package/dist/web/hooks/use-display-mode.js +1 -1
  242. package/dist/web/hooks/use-display-mode.js.map +1 -1
  243. package/dist/web/hooks/use-display-mode.test.js +1 -1
  244. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  245. package/dist/web/hooks/use-download.d.ts +1 -3
  246. package/dist/web/hooks/use-download.js +1 -2
  247. package/dist/web/hooks/use-download.js.map +1 -1
  248. package/dist/web/hooks/use-download.test.js +7 -7
  249. package/dist/web/hooks/use-download.test.js.map +1 -1
  250. package/dist/web/hooks/use-file-resource.d.ts +37 -0
  251. package/dist/web/hooks/use-file-resource.js +98 -0
  252. package/dist/web/hooks/use-file-resource.js.map +1 -0
  253. package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
  254. package/dist/web/hooks/use-file-resource.test.js +65 -0
  255. package/dist/web/hooks/use-file-resource.test.js.map +1 -0
  256. package/dist/web/hooks/use-files.test.js +1 -1
  257. package/dist/web/hooks/use-files.test.js.map +1 -1
  258. package/dist/web/hooks/use-host.d.ts +44 -0
  259. package/dist/web/hooks/use-host.js +45 -0
  260. package/dist/web/hooks/use-host.js.map +1 -0
  261. package/dist/web/hooks/use-host.test.d.ts +1 -0
  262. package/dist/web/hooks/use-host.test.js +59 -0
  263. package/dist/web/hooks/use-host.test.js.map +1 -0
  264. package/dist/web/hooks/use-model-context.d.ts +44 -0
  265. package/dist/web/hooks/use-model-context.js +63 -0
  266. package/dist/web/hooks/use-model-context.js.map +1 -0
  267. package/dist/web/hooks/use-open-external.test.js +2 -2
  268. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  269. package/dist/web/hooks/use-open-file.d.ts +20 -0
  270. package/dist/web/hooks/use-open-file.js +25 -0
  271. package/dist/web/hooks/use-open-file.js.map +1 -0
  272. package/dist/web/hooks/use-register-view-tool.d.ts +3 -4
  273. package/dist/web/hooks/use-register-view-tool.js +1 -1
  274. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  275. package/dist/web/hooks/use-request-close.test.js +1 -1
  276. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  277. package/dist/web/hooks/use-request-modal.test.js +1 -1
  278. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  279. package/dist/web/hooks/use-request-size.d.ts +1 -1
  280. package/dist/web/hooks/use-request-size.js +1 -1
  281. package/dist/web/hooks/use-request-size.js.map +1 -1
  282. package/dist/web/hooks/use-request-size.test.js +1 -1
  283. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  284. package/dist/web/hooks/use-send-follow-up-message.d.ts +8 -2
  285. package/dist/web/hooks/use-send-follow-up-message.js +6 -0
  286. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  287. package/dist/web/hooks/use-set-open-in-app-url.test.js +2 -8
  288. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  289. package/dist/web/hooks/use-tool-info.d.ts +1 -20
  290. package/dist/web/hooks/use-tool-info.js +0 -1
  291. package/dist/web/hooks/use-tool-info.js.map +1 -1
  292. package/dist/web/hooks/use-tool-info.test-d.js +0 -5
  293. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  294. package/dist/web/hooks/use-tool-info.test.js +2 -7
  295. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  296. package/dist/web/hooks/use-user.d.ts +3 -2
  297. package/dist/web/hooks/use-user.js +4 -3
  298. package/dist/web/hooks/use-user.js.map +1 -1
  299. package/dist/web/hooks/use-user.test.js +5 -3
  300. package/dist/web/hooks/use-user.test.js.map +1 -1
  301. package/dist/web/hooks/use-view-state.js +19 -9
  302. package/dist/web/hooks/use-view-state.js.map +1 -1
  303. package/dist/web/hooks/use-view-state.test.js +33 -2
  304. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  305. package/dist/web/hooks/use-viewport.d.ts +20 -0
  306. package/dist/web/hooks/use-viewport.js +21 -0
  307. package/dist/web/hooks/use-viewport.js.map +1 -0
  308. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  309. package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +12 -32
  310. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  311. package/dist/web/mount-view.d.ts +3 -2
  312. package/dist/web/mount-view.js +5 -8
  313. package/dist/web/mount-view.js.map +1 -1
  314. package/package.json +22 -17
  315. package/dist/cli/resolve-views-dir.d.ts +0 -1
  316. package/dist/cli/resolve-views-dir.js.map +0 -1
  317. package/dist/web/hooks/use-layout.d.ts +0 -24
  318. package/dist/web/hooks/use-layout.js +0 -25
  319. package/dist/web/hooks/use-layout.js.map +0 -1
  320. package/dist/web/hooks/use-layout.test.js.map +0 -1
  321. package/dist/web/plugin/data-llm.test.js +0 -81
  322. package/dist/web/plugin/data-llm.test.js.map +0 -1
  323. package/dist/web/plugin/plugin.d.ts +0 -33
  324. package/dist/web/plugin/plugin.js +0 -188
  325. package/dist/web/plugin/plugin.js.map +0 -1
  326. package/dist/web/plugin/scan-views.js.map +0 -1
  327. package/dist/web/plugin/scan-views.test.js.map +0 -1
  328. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  329. package/dist/web/plugin/transform-data-llm.js +0 -96
  330. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  331. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  332. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  333. package/dist/web/plugin/validate-view.d.ts +0 -1
  334. package/dist/web/plugin/validate-view.js.map +0 -1
  335. package/dist/web/plugin/validate-view.test.js.map +0 -1
  336. /package/dist/{web/hooks/use-layout.test.d.ts → context-warnings.test.d.ts} +0 -0
  337. /package/dist/{web/plugin/data-llm.test.d.ts → server/app.test.d.ts} +0 -0
  338. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
  339. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
  340. /package/dist/{web/plugin/scan-views.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  341. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  342. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  343. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA4G7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IAGF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAK1D,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,MAAM,OAAO,GAAG,KAAK,EACnB,QAAkB,EACiB,EAAE;QACrC,MAAM,MAAM,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC;QACnC,gBAAgB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,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,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAa,CAAC;QACpE,CAAC;QAED,OAAO,CAAC,QAAQ,CAAC;aACd,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACzC,WAAW,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,WAAW,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACxC,WAAW,EAAE,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC,CAAmD,CAAC;IAErD,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,IAAI;QACJ,KAAK;QACL,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useRef, useState } from \"react\";\n\nimport {\n type CallToolArgs,\n type CallToolResponse,\n getAdaptor,\n} from \"../bridges/index.js\";\nimport type { HasRequiredKeys } from \"../types.js\";\n\ntype CallToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolPendingState = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n isError: false;\n data: TData;\n error: undefined;\n};\n\ntype CallToolErrorState = {\n status: \"error\";\n isIdle: false;\n isPending: false;\n isSuccess: false;\n isError: true;\n data: undefined;\n error: unknown;\n};\n\n/**\n * State of a {@link useCallTool} invocation, discriminated by `status`.\n * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.\n */\nexport type CallToolState<TData extends CallToolResponse = CallToolResponse> =\n | CallToolIdleState\n | CallToolPendingState\n | CallToolSuccessState<TData>\n | CallToolErrorState;\n\n/**\n * Optional callbacks fired around a {@link useCallTool} call.\n * `onSettled` runs after success or error.\n */\nexport type SideEffects<ToolArgs, ToolResponse> = {\n onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;\n onError?: (error: unknown, toolArgs: ToolArgs) => void;\n onSettled?: (\n data: ToolResponse | undefined,\n error: unknown | undefined,\n toolArgs: ToolArgs,\n ) => void;\n};\n\ntype IsArgsOptional<T> = [T] extends [null]\n ? true\n : HasRequiredKeys<T> extends false\n ? true\n : false;\n\n/**\n * Fire-and-forget call function returned by {@link useCallTool}. Tracks state\n * on the hook and supports optional {@link SideEffects} callbacks. Args are\n * optional when the tool accepts none.\n */\nexport type CallToolFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): void;\n (sideEffects: SideEffects<TArgs, TResponse>): void;\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n }\n : {\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n };\n\n/**\n * Promise-returning call function returned by {@link useCallTool}. Rejects\n * if the tool errors; use `try/catch` for error handling.\n */\nexport type CallToolAsyncFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): Promise<TResponse>;\n (args: TArgs): Promise<TResponse>;\n }\n : (args: TArgs) => Promise<TResponse>;\n\ntype ToolResponseSignature = Pick<\n CallToolResponse,\n \"structuredContent\" | \"meta\"\n>;\n\n/**\n * Call a server tool from a view and track its execution state.\n *\n * Returns the current {@link CallToolState} plus two callers: `callTool`\n * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`\n * (promise-returning). If the same instance is invoked again while a call is\n * in flight, the older response is dropped from the rendered state (but any\n * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).\n *\n * Pair with {@link useToolInfo} to read the result of the tool invocation\n * that produced the current view. For end-to-end type safety across tool\n * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}\n * over calling this hook directly.\n *\n * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).\n * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.\n *\n * @example\n * ```tsx\n * const { callTool, isPending, data } = useCallTool<{ query: string }>(\"search\");\n *\n * <button onClick={() => callTool({ query: \"skybridge\" }, {\n * onSuccess: (res) => console.log(res.structuredContent),\n * })} />\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-call-tool\n */\nexport const useCallTool = <\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>,\n>(\n name: string,\n) => {\n type CombinedCallToolResponse = CallToolResponse & ToolResponse;\n\n const [{ status, data, error }, setCallToolState] = useState<\n Omit<\n CallToolState<CombinedCallToolResponse>,\n \"isIdle\" | \"isPending\" | \"isSuccess\" | \"isError\"\n >\n >({ status: \"idle\", data: undefined, error: undefined });\n\n const callIdRef = useRef(0);\n const adaptor = getAdaptor();\n\n const execute = async (\n toolArgs: ToolArgs,\n ): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({ status: \"pending\", data: undefined, error: undefined });\n\n try {\n const data = await adaptor.callTool<ToolArgs, CombinedCallToolResponse>(\n name,\n toolArgs,\n );\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"success\", data, error: undefined });\n }\n\n return data;\n } catch (error) {\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"error\", data: undefined, error });\n }\n throw error;\n }\n };\n\n const callToolAsync = ((toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n }) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = ((\n firstArg?: ToolArgs | SideEffects<ToolArgs, CombinedCallToolResponse>,\n sideEffects?: SideEffects<ToolArgs, CombinedCallToolResponse>,\n ) => {\n let toolArgs: ToolArgs;\n if (\n firstArg &&\n typeof firstArg === \"object\" &&\n (\"onSuccess\" in firstArg ||\n \"onError\" in firstArg ||\n \"onSettled\" in firstArg)\n ) {\n toolArgs = null as ToolArgs; // no toolArgs provided\n sideEffects = firstArg;\n } else {\n toolArgs = (firstArg === undefined ? null : firstArg) as ToolArgs;\n }\n\n execute(toolArgs)\n .then((data) => {\n sideEffects?.onSuccess?.(data, toolArgs);\n sideEffects?.onSettled?.(data, undefined, toolArgs);\n })\n .catch((error) => {\n sideEffects?.onError?.(error, toolArgs);\n sideEffects?.onSettled?.(undefined, error, toolArgs);\n });\n }) as CallToolFn<ToolArgs, CombinedCallToolResponse>;\n\n const callToolState = {\n status,\n data,\n error,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n isError: status === \"error\",\n } as CallToolState<CombinedCallToolResponse>;\n\n return {\n ...callToolState,\n callTool,\n callToolAsync,\n };\n};\n"]}
1
+ {"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAIL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA4G7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,OAAyB,EACzB,EAAE;IAGF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB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K,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useCallback, useRef, useState } from \"react\";\n\nimport {\n type CallToolArgs,\n type CallToolOptions,\n type CallToolResponse,\n getAdaptor,\n} from \"../bridges/index.js\";\nimport type { HasRequiredKeys } from \"../types.js\";\n\ntype CallToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolPendingState = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n isError: false;\n data: TData;\n error: undefined;\n};\n\ntype CallToolErrorState = {\n status: \"error\";\n isIdle: false;\n isPending: false;\n isSuccess: false;\n isError: true;\n data: undefined;\n error: unknown;\n};\n\n/**\n * State of a {@link useCallTool} invocation, discriminated by `status`.\n * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.\n */\nexport type CallToolState<TData extends CallToolResponse = CallToolResponse> =\n | CallToolIdleState\n | CallToolPendingState\n | CallToolSuccessState<TData>\n | CallToolErrorState;\n\n/**\n * Optional callbacks fired around a {@link useCallTool} call.\n * `onSettled` runs after success or error.\n */\nexport type SideEffects<ToolArgs, ToolResponse> = {\n onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;\n onError?: (error: unknown, toolArgs: ToolArgs) => void;\n onSettled?: (\n data: ToolResponse | undefined,\n error: unknown | undefined,\n toolArgs: ToolArgs,\n ) => void;\n};\n\ntype IsArgsOptional<T> = [T] extends [null]\n ? true\n : HasRequiredKeys<T> extends false\n ? true\n : false;\n\n/**\n * Fire-and-forget call function returned by {@link useCallTool}. Tracks state\n * on the hook and supports optional {@link SideEffects} callbacks. Args are\n * optional when the tool accepts none.\n */\nexport type CallToolFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): void;\n (sideEffects: SideEffects<TArgs, TResponse>): void;\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n }\n : {\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n };\n\n/**\n * Promise-returning call function returned by {@link useCallTool}. Rejects\n * if the tool errors; use `try/catch` for error handling.\n */\nexport type CallToolAsyncFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): Promise<TResponse>;\n (args: TArgs): Promise<TResponse>;\n }\n : (args: TArgs) => Promise<TResponse>;\n\ntype ToolResponseSignature = Pick<\n CallToolResponse,\n \"structuredContent\" | \"meta\"\n>;\n\n/**\n * Call a server tool from a view and track its execution state.\n *\n * Returns the current {@link CallToolState} plus two callers: `callTool`\n * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`\n * (promise-returning). If the same instance is invoked again while a call is\n * in flight, the older response is dropped from the rendered state (but any\n * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).\n *\n * Pair with {@link useToolInfo} to read the result of the tool invocation\n * that produced the current view. For end-to-end type safety across tool\n * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}\n * over calling this hook directly.\n *\n * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).\n * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.\n *\n * @example\n * ```tsx\n * const { callTool, isPending, data } = useCallTool<{ query: string }>(\"search\");\n *\n * <button onClick={() => callTool({ query: \"skybridge\" }, {\n * onSuccess: (res) => console.log(res.structuredContent),\n * })} />\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-call-tool\n */\nexport const useCallTool = <\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>,\n>(\n name: string,\n options?: CallToolOptions,\n) => {\n type CombinedCallToolResponse = CallToolResponse & ToolResponse;\n\n const [{ status, data, error }, setCallToolState] = useState<\n Omit<\n CallToolState<CombinedCallToolResponse>,\n \"isIdle\" | \"isPending\" | \"isSuccess\" | \"isError\"\n >\n >({ status: \"idle\", data: undefined, error: undefined });\n\n const callIdRef = useRef(0);\n const adaptor = getAdaptor();\n const timeout = options?.timeout;\n\n const execute = useCallback(\n async (toolArgs: ToolArgs): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({\n status: \"pending\",\n data: undefined,\n error: undefined,\n });\n\n try {\n const data = await adaptor.callTool<ToolArgs, CombinedCallToolResponse>(\n name,\n toolArgs,\n { timeout },\n );\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"success\", data, error: undefined });\n }\n\n return data;\n } catch (error) {\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"error\", data: undefined, error });\n }\n throw error;\n }\n },\n [adaptor, name, timeout],\n );\n\n const callToolAsync = useCallback(\n (toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n },\n [execute],\n ) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = useCallback(\n (\n firstArg?: ToolArgs | SideEffects<ToolArgs, CombinedCallToolResponse>,\n sideEffects?: SideEffects<ToolArgs, CombinedCallToolResponse>,\n ) => {\n let toolArgs: ToolArgs;\n if (\n firstArg &&\n typeof firstArg === \"object\" &&\n (\"onSuccess\" in firstArg ||\n \"onError\" in firstArg ||\n \"onSettled\" in firstArg)\n ) {\n toolArgs = null as ToolArgs; // no toolArgs provided\n sideEffects = firstArg;\n } else {\n toolArgs = (firstArg === undefined ? null : firstArg) as ToolArgs;\n }\n\n execute(toolArgs)\n .then((data) => {\n sideEffects?.onSuccess?.(data, toolArgs);\n sideEffects?.onSettled?.(data, undefined, toolArgs);\n })\n .catch((error) => {\n sideEffects?.onError?.(error, toolArgs);\n sideEffects?.onSettled?.(undefined, error, toolArgs);\n });\n },\n [execute],\n ) as CallToolFn<ToolArgs, CombinedCallToolResponse>;\n\n const callToolState = {\n status,\n data,\n error,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n isError: status === \"error\",\n } as CallToolState<CombinedCallToolResponse>;\n\n return {\n ...callToolState,\n callTool,\n callToolAsync,\n };\n};\n"]}
@@ -12,7 +12,7 @@ describe("useCallTool - onSuccess callback", () => {
12
12
  McpAppBridge.resetInstance();
13
13
  AppsSdkBridge.resetInstance();
14
14
  vi.stubGlobal("parent", { postMessage: vi.fn() });
15
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
15
+ vi.stubGlobal("skybridge", {});
16
16
  vi.stubGlobal("openai", { callTool: vi.fn() });
17
17
  callToolMock = vi.spyOn(getAdaptor(), "callTool");
18
18
  });
@@ -55,7 +55,9 @@ describe("useCallTool - onSuccess callback", () => {
55
55
  await act(async () => {
56
56
  result.current.callTool(args);
57
57
  });
58
- expect(callToolMock).toHaveBeenCalledWith(toolName, args);
58
+ expect(callToolMock).toHaveBeenCalledWith(toolName, args, {
59
+ timeout: undefined,
60
+ });
59
61
  });
60
62
  it("should call onSuccess callback with correct data and toolArgs on successful execution", async () => {
61
63
  const onSuccess = vi.fn();
@@ -156,6 +158,13 @@ describe("useCallTool - onSuccess callback", () => {
156
158
  expect(result.current.data).toEqual(secondCallData);
157
159
  });
158
160
  });
161
+ it("should keep callTool and callToolAsync stable across renders", () => {
162
+ const { result, rerender } = renderHook(() => useCallTool(toolName));
163
+ const { callTool, callToolAsync } = result.current;
164
+ rerender();
165
+ expect(result.current.callTool).toBe(callTool);
166
+ expect(result.current.callToolAsync).toBe(callToolAsync);
167
+ });
159
168
  });
160
169
  describe("useCallTool - TypeScript typing", () => {
161
170
  let callToolMock;
@@ -164,7 +173,7 @@ describe("useCallTool - TypeScript typing", () => {
164
173
  McpAppBridge.resetInstance();
165
174
  AppsSdkBridge.resetInstance();
166
175
  vi.stubGlobal("parent", { postMessage: vi.fn() });
167
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
176
+ vi.stubGlobal("skybridge", {});
168
177
  vi.stubGlobal("openai", { callTool: vi.fn() });
169
178
  callToolMock = vi.spyOn(getAdaptor(), "callTool");
170
179
  });
@@ -187,7 +196,9 @@ describe("useCallTool - TypeScript typing", () => {
187
196
  await act(async () => {
188
197
  result.current.callTool();
189
198
  });
190
- expect(callToolMock).toHaveBeenCalledWith("test-tool", null);
199
+ expect(callToolMock).toHaveBeenCalledWith("test-tool", null, {
200
+ timeout: undefined,
201
+ });
191
202
  expectTypeOf(result.current.data);
192
203
  });
193
204
  it("should correctly type callToolAsync return value", async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,YAAkB,CAAC;IAEvB,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,aAAa,CA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;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n expectTypeOf,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport { useCallTool } from \"./use-call-tool.js\";\n\ndescribe(\"useCallTool - onSuccess callback\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n const toolName = \"test-tool\";\n const args = { input: \"test input\" };\n const data: CallToolResponse = {\n content: [{ type: \"text\" as const, text: \"test result\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: {},\n };\n const error = new Error(\"test error\");\n\n it(\"should normalize _meta to meta when SDK returns _meta instead of meta\", async () => {\n const rawSdkResponse = {\n content: [{ type: \"text\" as const, text: \"result\" }],\n structuredContent: { value: 1 },\n isError: false,\n meta: { secret: \"only visible to widget\" },\n };\n callToolMock.mockResolvedValueOnce(rawSdkResponse);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n await act(async () => {\n result.current.callTool(args);\n });\n\n await waitFor(() => {\n expect(result.current.data).toMatchObject({\n meta: { secret: \"only visible to widget\" },\n });\n });\n });\n\n it(\"should call adaptor.callTool with correct arguments\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n await act(async () => {\n result.current.callTool(args);\n });\n expect(callToolMock).toHaveBeenCalledWith(toolName, args);\n });\n\n it(\"should call onSuccess callback with correct data and toolArgs on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onError callback with error and toolArgs on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).not.toHaveBeenCalled();\n expect(onError).toHaveBeenCalledWith(error, args);\n });\n });\n\n it(\"should call onSettled callback with data and undefined error on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onSettled).toHaveBeenCalledWith(data, undefined, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onSettled callback with undefined data and error on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onError).toHaveBeenCalledWith(error, args);\n expect(onSettled).toHaveBeenCalledWith(undefined, error, args);\n expect(onSuccess).not.toHaveBeenCalled();\n });\n });\n\n it(\"should always return last call started state\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n const firstCallData = {\n ...data,\n structuredContent: { result: \"first call result\" },\n };\n const secondCallData = {\n ...data,\n structuredContent: { result: \"second call result\" },\n };\n const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } =\n Promise.withResolvers();\n const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } =\n Promise.withResolvers();\n callToolMock\n .mockImplementationOnce(() => firstCallToolPromise)\n .mockImplementationOnce(() => secondCallToolPromise);\n\n await act(() => {\n result.current.callTool(args);\n result.current.callTool(args);\n resolveFirstCallTool(firstCallData);\n return firstCallToolPromise;\n });\n\n expect(result.current.status).toEqual(\"pending\");\n expect(result.current.data).toEqual(undefined);\n resolveSecondCallTool(secondCallData);\n\n await waitFor(() => {\n expect(result.current.status).toEqual(\"success\");\n expect(result.current.data).toEqual(secondCallData);\n });\n });\n});\n\ndescribe(\"useCallTool - TypeScript typing\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should have correct return types when ToolArgs is null and ToolResponse is specified\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { result: string };\n meta: { id: number };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n const data: TestResponse = {\n content: [{ type: \"text\" as const, text: \"test\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: { id: 123 },\n };\n\n callToolMock.mockResolvedValueOnce(data);\n\n await act(async () => {\n result.current.callTool();\n });\n\n expect(callToolMock).toHaveBeenCalledWith(\"test-tool\", null);\n expectTypeOf<typeof data | undefined>(result.current.data);\n });\n\n it(\"should correctly type callToolAsync return value\", async () => {\n type TestArgs = { query: string };\n type TestResponse = CallToolResponse & {\n structuredContent: { answer: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<TestArgs, TestResponse>(\"test-tool\"),\n );\n\n const testArgs: TestArgs = { query: \"test\" };\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"answer\" }],\n structuredContent: { answer: \"test answer\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync(testArgs);\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n\n it(\"should correctly type callToolAsync when ToolArgs is null\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { data: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"data\" }],\n structuredContent: { data: \"test data\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync();\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n});\n"]}
1
+ {"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAA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,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE;YAC5C,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;SACT,CAAC;QAEF,YAAY,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAEjD,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACzC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QAKzE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CACjC,WAAW,CAAqB,WAAW,CAAC,CAC7C,CAAC;QAEF,MAAM,YAAY,GAAiB;YACjC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAClD,iBAAiB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACxC,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;SACT,CAAC;QAEF,YAAY,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAEjD,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACzC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,CAAC,CAAC,CAAC;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n expectTypeOf,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport { useCallTool } from \"./use-call-tool.js\";\n\ndescribe(\"useCallTool - onSuccess callback\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n const toolName = \"test-tool\";\n const args = { input: \"test input\" };\n const data: CallToolResponse = {\n content: [{ type: \"text\" as const, text: \"test result\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: {},\n };\n const error = new Error(\"test error\");\n\n it(\"should normalize _meta to meta when SDK returns _meta instead of meta\", async () => {\n const rawSdkResponse = {\n content: [{ type: \"text\" as const, text: \"result\" }],\n structuredContent: { value: 1 },\n isError: false,\n meta: { secret: \"only visible to widget\" },\n };\n callToolMock.mockResolvedValueOnce(rawSdkResponse);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n await act(async () => {\n result.current.callTool(args);\n });\n\n await waitFor(() => {\n expect(result.current.data).toMatchObject({\n meta: { secret: \"only visible to widget\" },\n });\n });\n });\n\n it(\"should call adaptor.callTool with correct arguments\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n await act(async () => {\n result.current.callTool(args);\n });\n expect(callToolMock).toHaveBeenCalledWith(toolName, args, {\n timeout: undefined,\n });\n });\n\n it(\"should call onSuccess callback with correct data and toolArgs on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onError callback with error and toolArgs on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).not.toHaveBeenCalled();\n expect(onError).toHaveBeenCalledWith(error, args);\n });\n });\n\n it(\"should call onSettled callback with data and undefined error on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onSettled).toHaveBeenCalledWith(data, undefined, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onSettled callback with undefined data and error on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onError).toHaveBeenCalledWith(error, args);\n expect(onSettled).toHaveBeenCalledWith(undefined, error, args);\n expect(onSuccess).not.toHaveBeenCalled();\n });\n });\n\n it(\"should always return last call started state\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n const firstCallData = {\n ...data,\n structuredContent: { result: \"first call result\" },\n };\n const secondCallData = {\n ...data,\n structuredContent: { result: \"second call result\" },\n };\n const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } =\n Promise.withResolvers();\n const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } =\n Promise.withResolvers();\n callToolMock\n .mockImplementationOnce(() => firstCallToolPromise)\n .mockImplementationOnce(() => secondCallToolPromise);\n\n await act(() => {\n result.current.callTool(args);\n result.current.callTool(args);\n resolveFirstCallTool(firstCallData);\n return firstCallToolPromise;\n });\n\n expect(result.current.status).toEqual(\"pending\");\n expect(result.current.data).toEqual(undefined);\n resolveSecondCallTool(secondCallData);\n\n await waitFor(() => {\n expect(result.current.status).toEqual(\"success\");\n expect(result.current.data).toEqual(secondCallData);\n });\n });\n\n it(\"should keep callTool and callToolAsync stable across renders\", () => {\n const { result, rerender } = renderHook(() => useCallTool(toolName));\n const { callTool, callToolAsync } = result.current;\n\n rerender();\n\n expect(result.current.callTool).toBe(callTool);\n expect(result.current.callToolAsync).toBe(callToolAsync);\n });\n});\n\ndescribe(\"useCallTool - TypeScript typing\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should have correct return types when ToolArgs is null and ToolResponse is specified\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { result: string };\n meta: { id: number };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n const data: TestResponse = {\n content: [{ type: \"text\" as const, text: \"test\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: { id: 123 },\n };\n\n callToolMock.mockResolvedValueOnce(data);\n\n await act(async () => {\n result.current.callTool();\n });\n\n expect(callToolMock).toHaveBeenCalledWith(\"test-tool\", null, {\n timeout: undefined,\n });\n expectTypeOf<typeof data | undefined>(result.current.data);\n });\n\n it(\"should correctly type callToolAsync return value\", async () => {\n type TestArgs = { query: string };\n type TestResponse = CallToolResponse & {\n structuredContent: { answer: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<TestArgs, TestResponse>(\"test-tool\"),\n );\n\n const testArgs: TestArgs = { query: \"test\" };\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"answer\" }],\n structuredContent: { answer: \"test answer\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync(testArgs);\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n\n it(\"should correctly type callToolAsync when ToolArgs is null\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { data: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"data\" }],\n structuredContent: { data: \"test data\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync();\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n});\n"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * App-relative URL (path and query, e.g. `"/parts?tag=bolt"`) that ChatGPT
3
+ * opened the view on through a deep link. Updates when the user follows
4
+ * another deep link while the view is open. `undefined` when the view was not
5
+ * opened through a deep link, on hosts other than ChatGPT, or when the host
6
+ * sends a URL that isn't app-relative (it must start with a single `/`) or
7
+ * that contains a fragment.
8
+ *
9
+ * Deep links target global entrypoints: set `openai.entrypoints` to include
10
+ * `{ type: "global" }` on the tool.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const deepLink = useDeepLink();
15
+ * useEffect(() => {
16
+ * if (deepLink) navigate(deepLink);
17
+ * }, [deepLink, navigate]);
18
+ * ```
19
+ *
20
+ * @see https://docs.skybridge.tech/api-reference/use-deep-link
21
+ */
22
+ export declare function useDeepLink(): string | undefined;
@@ -0,0 +1,34 @@
1
+ import { useMcpAppContext } from "../bridges/index.js";
2
+ /**
3
+ * App-relative URL (path and query, e.g. `"/parts?tag=bolt"`) that ChatGPT
4
+ * opened the view on through a deep link. Updates when the user follows
5
+ * another deep link while the view is open. `undefined` when the view was not
6
+ * opened through a deep link, on hosts other than ChatGPT, or when the host
7
+ * sends a URL that isn't app-relative (it must start with a single `/`) or
8
+ * that contains a fragment.
9
+ *
10
+ * Deep links target global entrypoints: set `openai.entrypoints` to include
11
+ * `{ type: "global" }` on the tool.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const deepLink = useDeepLink();
16
+ * useEffect(() => {
17
+ * if (deepLink) navigate(deepLink);
18
+ * }, [deepLink, navigate]);
19
+ * ```
20
+ *
21
+ * @see https://docs.skybridge.tech/api-reference/use-deep-link
22
+ */
23
+ export function useDeepLink() {
24
+ const url = useMcpAppContext("openai/deepLink")?.url;
25
+ if (typeof url !== "string" ||
26
+ !url.startsWith("/") ||
27
+ url.startsWith("//") ||
28
+ url.startsWith("/\\") ||
29
+ url.includes("#")) {
30
+ return undefined;
31
+ }
32
+ return url;
33
+ }
34
+ //# sourceMappingURL=use-deep-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-deep-link.js","sourceRoot":"","sources":["../../../src/web/hooks/use-deep-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,GAAG,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACrD,IACE,OAAO,GAAG,KAAK,QAAQ;QACvB,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QACpB,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QACpB,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;QACrB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EACjB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { useMcpAppContext } from \"../bridges/index.js\";\n\n/**\n * App-relative URL (path and query, e.g. `\"/parts?tag=bolt\"`) that ChatGPT\n * opened the view on through a deep link. Updates when the user follows\n * another deep link while the view is open. `undefined` when the view was not\n * opened through a deep link, on hosts other than ChatGPT, or when the host\n * sends a URL that isn't app-relative (it must start with a single `/`) or\n * that contains a fragment.\n *\n * Deep links target global entrypoints: set `openai.entrypoints` to include\n * `{ type: \"global\" }` on the tool.\n *\n * @example\n * ```tsx\n * const deepLink = useDeepLink();\n * useEffect(() => {\n * if (deepLink) navigate(deepLink);\n * }, [deepLink, navigate]);\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-deep-link\n */\nexport function useDeepLink(): string | undefined {\n const url = useMcpAppContext(\"openai/deepLink\")?.url;\n if (\n typeof url !== \"string\" ||\n !url.startsWith(\"/\") ||\n url.startsWith(\"//\") ||\n url.startsWith(\"/\\\\\") ||\n url.includes(\"#\")\n ) {\n return undefined;\n }\n return url;\n}\n"]}
@@ -9,7 +9,7 @@ import type { RequestDisplayMode } from "../bridges/types.js";
9
9
  *
10
10
  * `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
11
11
  * to layout changes that come with display-mode switches (e.g. `maxHeight`),
12
- * pair with {@link useLayout}.
12
+ * pair with {@link useViewport}.
13
13
  *
14
14
  * @example
15
15
  * ```tsx
@@ -10,7 +10,7 @@ import { getAdaptor, useHostContext } from "../bridges/index.js";
10
10
  *
11
11
  * `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
12
12
  * to layout changes that come with display-mode switches (e.g. `maxHeight`),
13
- * pair with {@link useLayout}.
13
+ * pair with {@link useViewport}.
14
14
  *
15
15
  * @example
16
16
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link useLayout}.\n *\n * @example\n * ```tsx\n * const [mode, setMode] = useDisplayMode();\n * <button onClick={() => setMode(\"fullscreen\")}>Expand</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-display-mode\n */\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
1
+ {"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link useViewport}.\n *\n * @example\n * ```tsx\n * const [mode, setMode] = useDisplayMode();\n * <button onClick={() => setMode(\"fullscreen\")}>Expand</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-display-mode\n */\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
@@ -11,7 +11,7 @@ describe("useDisplayMode", () => {
11
11
  HostAdaptor.resetInstance();
12
12
  McpAppBridge.resetInstance();
13
13
  AppsSdkBridge.resetInstance();
14
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
14
+ vi.stubGlobal("skybridge", {});
15
15
  vi.stubGlobal("openai", { view: { mode: "inline" } });
16
16
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
17
17
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-display-mode.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.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,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GAC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E,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9D,kDAAkD;QAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG;YACd,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;SACtE,CAAC;QACF,wDAAwD;QACvD,OAAe,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEjE,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC;YACtD,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, fireEvent, renderHook, waitFor } 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 { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDisplayMode } from \"./use-display-mode.js\";\n\ndescribe(\"useDisplayMode\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\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 the current display mode from MCP host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"inline\");\n });\n });\n\n it(\"should update display mode on host-context-changed notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"inline\");\n });\n\n act(() => {\n fireEvent(\n window,\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/host-context-changed\",\n params: { displayMode: \"fullscreen\" },\n },\n }),\n );\n });\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"fullscreen\");\n });\n });\n\n it(\"should call requestDisplayMode on the adaptor when setDisplayMode is called\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => expect(result.current[0]).toBe(\"inline\"));\n\n // Patch mcp.getApp to avoid real protocol request\n const adaptor = getAdaptor();\n const fakeApp = {\n requestDisplayMode: vi.fn().mockResolvedValue({ mode: \"fullscreen\" }),\n };\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n (adaptor as any).mcp.getApp = vi.fn().mockResolvedValue(fakeApp);\n\n await act(async () => {\n await result.current[1](\"fullscreen\");\n });\n\n expect(fakeApp.requestDisplayMode).toHaveBeenCalledWith({\n mode: \"fullscreen\",\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-display-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} 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 { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDisplayMode } from \"./use-display-mode.js\";\n\ndescribe(\"useDisplayMode\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\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 the current display mode from MCP host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"inline\");\n });\n });\n\n it(\"should update display mode on host-context-changed notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"inline\");\n });\n\n act(() => {\n fireEvent(\n window,\n new MessageEvent(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/host-context-changed\",\n params: { displayMode: \"fullscreen\" },\n },\n }),\n );\n });\n\n await waitFor(() => {\n expect(result.current[0]).toBe(\"fullscreen\");\n });\n });\n\n it(\"should call requestDisplayMode on the adaptor when setDisplayMode is called\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ displayMode: \"inline\" }),\n });\n\n const { result } = renderHook(() => useDisplayMode());\n\n await waitFor(() => expect(result.current[0]).toBe(\"inline\"));\n\n // Patch mcp.getApp to avoid real protocol request\n const adaptor = getAdaptor();\n const fakeApp = {\n requestDisplayMode: vi.fn().mockResolvedValue({ mode: \"fullscreen\" }),\n };\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n (adaptor as any).mcp.getApp = vi.fn().mockResolvedValue(fakeApp);\n\n await act(async () => {\n await result.current[1](\"fullscreen\");\n });\n\n expect(fakeApp.requestDisplayMode).toHaveBeenCalledWith({\n mode: \"fullscreen\",\n });\n });\n});\n"]}
@@ -1,5 +1,3 @@
1
1
  import type { DownloadParams, DownloadResult } from "../bridges/types.js";
2
2
  export type DownloadFn = (params: DownloadParams) => Promise<DownloadResult>;
3
- export declare function useDownload(): {
4
- download: DownloadFn;
5
- };
3
+ export declare function useDownload(): DownloadFn;
@@ -2,7 +2,6 @@ import { useCallback } from "react";
2
2
  import { getAdaptor } from "../bridges/index.js";
3
3
  export function useDownload() {
4
4
  const adaptor = getAdaptor();
5
- const download = useCallback((params) => adaptor.download(params), [adaptor]);
6
- return { download };
5
+ return useCallback((params) => adaptor.download(params), [adaptor]);
7
6
  }
8
7
  //# sourceMappingURL=use-download.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-download.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EACpC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { DownloadParams, DownloadResult } from \"../bridges/types.js\";\n\nexport type DownloadFn = (params: DownloadParams) => Promise<DownloadResult>;\n\nexport function useDownload(): { download: DownloadFn } {\n const adaptor = getAdaptor();\n const download = useCallback<DownloadFn>(\n (params) => adaptor.download(params),\n [adaptor],\n );\n\n return { download };\n}\n"]}
1
+ {"version":3,"file":"use-download.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,OAAO,WAAW,CAChB,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EACpC,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { DownloadParams, DownloadResult } from \"../bridges/types.js\";\n\nexport type DownloadFn = (params: DownloadParams) => Promise<DownloadResult>;\n\nexport function useDownload(): DownloadFn {\n const adaptor = getAdaptor();\n return useCallback<DownloadFn>(\n (params) => adaptor.download(params),\n [adaptor],\n );\n}\n"]}
@@ -20,7 +20,7 @@ describe("useDownload", () => {
20
20
  describe("apps-sdk host", () => {
21
21
  beforeEach(() => {
22
22
  vi.stubGlobal("openai", {});
23
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
23
+ vi.stubGlobal("skybridge", {});
24
24
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
25
25
  vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
26
26
  });
@@ -33,7 +33,7 @@ describe("useDownload", () => {
33
33
  it("returns { isError: true } and logs an error", async () => {
34
34
  const errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
35
35
  const { result } = renderHook(() => useDownload());
36
- const res = await result.current.download(params);
36
+ const res = await result.current(params);
37
37
  expect(res).toEqual({ isError: true });
38
38
  expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("does not support ui/download-file"));
39
39
  });
@@ -41,7 +41,7 @@ describe("useDownload", () => {
41
41
  describe("mcp-app host without downloadFile capability", () => {
42
42
  beforeEach(() => {
43
43
  vi.stubGlobal("openai", undefined);
44
- vi.stubGlobal("skybridge", { hostType: "mcp-app" });
44
+ vi.stubGlobal("skybridge", {});
45
45
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
46
46
  vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
47
47
  });
@@ -54,7 +54,7 @@ describe("useDownload", () => {
54
54
  it("returns { isError: true } and logs an error", async () => {
55
55
  const errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
56
56
  const { result } = renderHook(() => useDownload());
57
- const res = await result.current.download(params);
57
+ const res = await result.current(params);
58
58
  expect(res).toEqual({ isError: true });
59
59
  expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("does not support ui/download-file"));
60
60
  });
@@ -63,7 +63,7 @@ describe("useDownload", () => {
63
63
  let postMessageMock;
64
64
  beforeEach(() => {
65
65
  vi.stubGlobal("openai", undefined);
66
- vi.stubGlobal("skybridge", { hostType: "mcp-app" });
66
+ vi.stubGlobal("skybridge", {});
67
67
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
68
68
  postMessageMock = getMcpAppHostPostMessageMock({}, { hostCapabilities: { downloadFile: {} } });
69
69
  vi.stubGlobal("parent", { postMessage: postMessageMock });
@@ -76,7 +76,7 @@ describe("useDownload", () => {
76
76
  });
77
77
  it("sends ui/download-file with the provided contents", async () => {
78
78
  const { result } = renderHook(() => useDownload());
79
- const res = await result.current.download(params);
79
+ const res = await result.current(params);
80
80
  expect(res).toEqual({});
81
81
  await waitFor(() => {
82
82
  expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
@@ -95,7 +95,7 @@ describe("useDownload", () => {
95
95
  });
96
96
  vi.stubGlobal("parent", { postMessage: postMessageMock });
97
97
  const { result } = renderHook(() => useDownload());
98
- const res = await result.current.download(params);
98
+ const res = await result.current(params);
99
99
  expect(res).toEqual({ isError: true });
100
100
  });
101
101
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-download.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.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;AAE5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAmB;IAC7B,QAAQ,EAAE;QACR;YACE,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,GAAG,EAAE,qBAAqB;gBAC1B,QAAQ,EAAE,kBAAkB;gBAC5B,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF;CACF,CAAC;AAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE;YACd,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC5B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;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E,EAAE,YAAY,EAAE,EAAE,EAAE;gBACtC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aACtC,CACF,CAAC;YACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;YAE1D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAEnD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAElD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,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 type { DownloadParams } from \"../bridges/types.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDownload } from \"./use-download.js\";\n\nconst params: DownloadParams = {\n contents: [\n {\n type: \"resource\",\n resource: {\n uri: \"file:///export.json\",\n mimeType: \"application/json\",\n text: '{\"hello\":\"world\"}',\n },\n },\n ],\n};\n\ndescribe(\"useDownload\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", {});\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host without downloadFile capability\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host with downloadFile capability\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n { hostCapabilities: { downloadFile: {} } },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends ui/download-file with the provided contents\", async () => {\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({});\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/download-file\",\n params,\n }),\n \"*\",\n );\n });\n });\n\n it(\"returns { isError: true } when the host denies the request\", async () => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n {\n hostCapabilities: { downloadFile: {} },\n downloadFileResult: { isError: true },\n },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current.download(params);\n\n expect(res).toEqual({ isError: true });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"use-download.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-download.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;AAE5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAmB;IAC7B,QAAQ,EAAE;QACR;YACE,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,GAAG,EAAE,qBAAqB;gBAC1B,QAAQ,EAAE,kBAAkB;gBAC5B,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF;CACF,CAAC;AAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE;YACd,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,C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AY,EAAE,EAAE,EAAE;gBACtC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aACtC,CACF,CAAC;YACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;YAE1D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAEnD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAEzC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,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 type { DownloadParams } from \"../bridges/types.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useDownload } from \"./use-download.js\";\n\nconst params: DownloadParams = {\n contents: [\n {\n type: \"resource\",\n resource: {\n uri: \"file:///export.json\",\n mimeType: \"application/json\",\n text: '{\"hello\":\"world\"}',\n },\n },\n ],\n};\n\ndescribe(\"useDownload\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", {});\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host without downloadFile capability\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"returns { isError: true } and logs an error\", async () => {\n const errorSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current(params);\n\n expect(res).toEqual({ isError: true });\n expect(errorSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"does not support ui/download-file\"),\n );\n });\n });\n\n describe(\"mcp-app host with downloadFile capability\", () => {\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 {},\n { hostCapabilities: { downloadFile: {} } },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"sends ui/download-file with the provided contents\", async () => {\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current(params);\n\n expect(res).toEqual({});\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/download-file\",\n params,\n }),\n \"*\",\n );\n });\n });\n\n it(\"returns { isError: true } when the host denies the request\", async () => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n postMessageMock = getMcpAppHostPostMessageMock(\n {},\n {\n hostCapabilities: { downloadFile: {} },\n downloadFileResult: { isError: true },\n },\n );\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const { result } = renderHook(() => useDownload());\n\n const res = await result.current(params);\n\n expect(res).toEqual({ isError: true });\n });\n });\n});\n"]}
@@ -0,0 +1,37 @@
1
+ import { type FileResource, type FileResourceContent, type FileResourceWriteResult, type ResourceRepresentation } from "../bridges/index.js";
2
+ /** State and actions returned by {@link useFileResource}. */
3
+ export type FileResourceState = {
4
+ data: FileResource | undefined;
5
+ isLoading: boolean;
6
+ error: unknown;
7
+ write: (content: FileResourceContent) => Promise<FileResourceWriteResult>;
8
+ };
9
+ /**
10
+ * Read a resource by URI, re-read it whenever the host reports a change, and
11
+ * write it back. Built for the file a ChatGPT file entrypoint opened, whose
12
+ * `resourceUri` arrives in the tool input as `file.resourceUri`.
13
+ *
14
+ * Reading uses the standard `resources/read`. `representation` asks ChatGPT
15
+ * for text or a base64 blob. `write` uses the OpenAI MCP extensions
16
+ * (`openai/resources/write`) and sends the current `etag` as `ifMatch`, so it
17
+ * resolves with `conflict` instead of overwriting a newer version, and then
18
+ * re-reads the latest one. When ChatGPT returned no `etag`, the write has no
19
+ * version check. It rejects with `NotSupportedError` when the host doesn't
20
+ * advertise `openai/resource`, or the resource isn't loaded or writable.
21
+ *
22
+ * Pass `undefined` or an empty string as `uri` to do nothing, for example outside a file
23
+ * entrypoint.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const { input } = useToolInfo<"open-part">();
28
+ * const { data, write } = useFileResource(input.file?.resourceUri, {
29
+ * representation: "text",
30
+ * });
31
+ * ```
32
+ *
33
+ * @see https://docs.skybridge.tech/api-reference/use-file-resource
34
+ */
35
+ export declare function useFileResource(uri: string | undefined, options?: {
36
+ representation?: ResourceRepresentation;
37
+ }): FileResourceState;
@@ -0,0 +1,98 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { getAdaptor, NotSupportedError, } from "../bridges/index.js";
3
+ /**
4
+ * Read a resource by URI, re-read it whenever the host reports a change, and
5
+ * write it back. Built for the file a ChatGPT file entrypoint opened, whose
6
+ * `resourceUri` arrives in the tool input as `file.resourceUri`.
7
+ *
8
+ * Reading uses the standard `resources/read`. `representation` asks ChatGPT
9
+ * for text or a base64 blob. `write` uses the OpenAI MCP extensions
10
+ * (`openai/resources/write`) and sends the current `etag` as `ifMatch`, so it
11
+ * resolves with `conflict` instead of overwriting a newer version, and then
12
+ * re-reads the latest one. When ChatGPT returned no `etag`, the write has no
13
+ * version check. It rejects with `NotSupportedError` when the host doesn't
14
+ * advertise `openai/resource`, or the resource isn't loaded or writable.
15
+ *
16
+ * Pass `undefined` or an empty string as `uri` to do nothing, for example outside a file
17
+ * entrypoint.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * const { input } = useToolInfo<"open-part">();
22
+ * const { data, write } = useFileResource(input.file?.resourceUri, {
23
+ * representation: "text",
24
+ * });
25
+ * ```
26
+ *
27
+ * @see https://docs.skybridge.tech/api-reference/use-file-resource
28
+ */
29
+ export function useFileResource(uri, options) {
30
+ const representation = options?.representation;
31
+ const [state, setState] = useState();
32
+ const sequence = useRef(0);
33
+ const current = uri && state?.uri === uri ? state : undefined;
34
+ const currentRef = useRef(current);
35
+ currentRef.current = current;
36
+ const read = useCallback(() => {
37
+ if (!uri) {
38
+ return;
39
+ }
40
+ const id = ++sequence.current;
41
+ getAdaptor()
42
+ .readResource(uri, representation)
43
+ .then((resource) => ({ resource, error: undefined }), (error) => ({ error }))
44
+ .then((next) => {
45
+ if (id === sequence.current) {
46
+ setState((previous) => ({
47
+ ...(previous?.uri === uri && previous),
48
+ uri,
49
+ ...next,
50
+ }));
51
+ }
52
+ });
53
+ }, [uri, representation]);
54
+ useEffect(() => {
55
+ if (!uri) {
56
+ return;
57
+ }
58
+ read();
59
+ const stopWatching = getAdaptor().watchResource(uri, read);
60
+ return () => {
61
+ sequence.current++;
62
+ stopWatching();
63
+ };
64
+ }, [uri, read]);
65
+ const write = useCallback(async (content) => {
66
+ const resource = currentRef.current?.resource;
67
+ if (!uri || currentRef.current?.uri !== uri || !resource?.writable) {
68
+ throw new NotSupportedError("writeResource", "the resource is not loaded or not writable");
69
+ }
70
+ const result = await getAdaptor().writeResource(uri, content, resource.etag);
71
+ if (currentRef.current?.uri !== uri) {
72
+ return result;
73
+ }
74
+ if (result.outcome === "saved") {
75
+ sequence.current++;
76
+ setState({
77
+ uri,
78
+ resource: {
79
+ ...content,
80
+ mimeType: resource.mimeType,
81
+ writable: true,
82
+ etag: result.etag,
83
+ },
84
+ });
85
+ }
86
+ else if (result.outcome === "conflict") {
87
+ read();
88
+ }
89
+ return result;
90
+ }, [uri, read]);
91
+ return {
92
+ data: current?.resource,
93
+ isLoading: Boolean(uri) && current === undefined,
94
+ error: current?.error,
95
+ write,
96
+ };
97
+ }
98
+ //# sourceMappingURL=use-file-resource.js.map