skybridge 0.0.0-dev.da22f74 → 0.0.0-dev.da39210

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 (428) hide show
  1. package/README.md +126 -124
  2. package/dist/cli/build-helpers.d.ts +11 -0
  3. package/dist/cli/build-helpers.js +107 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.js +132 -0
  6. package/dist/cli/build-helpers.test.js.map +1 -0
  7. package/dist/cli/build-steps.d.ts +2 -0
  8. package/dist/cli/build-steps.js +73 -0
  9. package/dist/cli/build-steps.js.map +1 -0
  10. package/dist/cli/build-steps.test.js +52 -0
  11. package/dist/cli/build-steps.test.js.map +1 -0
  12. package/dist/cli/detect-port.d.ts +2 -2
  13. package/dist/cli/detect-port.js +8 -20
  14. package/dist/cli/detect-port.js.map +1 -1
  15. package/dist/cli/header.d.ts +1 -1
  16. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  17. package/dist/cli/resolve-skybridge-config.js +18 -0
  18. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  19. package/dist/cli/run-plain.d.ts +18 -0
  20. package/dist/cli/run-plain.js +90 -0
  21. package/dist/cli/run-plain.js.map +1 -0
  22. package/dist/cli/telemetry.js +2 -0
  23. package/dist/cli/telemetry.js.map +1 -1
  24. package/dist/cli/use-execute-steps.d.ts +1 -1
  25. package/dist/cli/use-nodemon.d.ts +25 -1
  26. package/dist/cli/use-nodemon.js +96 -63
  27. package/dist/cli/use-nodemon.js.map +1 -1
  28. package/dist/cli/use-typescript-check.d.ts +8 -2
  29. package/dist/cli/use-typescript-check.js +71 -68
  30. package/dist/cli/use-typescript-check.js.map +1 -1
  31. package/dist/commands/build.d.ts +0 -3
  32. package/dist/commands/build.js +2 -73
  33. package/dist/commands/build.js.map +1 -1
  34. package/dist/commands/create.d.ts +9 -0
  35. package/dist/commands/create.js +30 -0
  36. package/dist/commands/create.js.map +1 -0
  37. package/dist/commands/dev.d.ts +1 -0
  38. package/dist/commands/dev.js +51 -3
  39. package/dist/commands/dev.js.map +1 -1
  40. package/dist/commands/start.js +7 -1
  41. package/dist/commands/start.js.map +1 -1
  42. package/dist/context-warnings.d.ts +5 -0
  43. package/dist/context-warnings.js +31 -0
  44. package/dist/context-warnings.js.map +1 -0
  45. package/dist/context-warnings.test.js +28 -0
  46. package/dist/context-warnings.test.js.map +1 -0
  47. package/dist/server/app.d.ts +194 -0
  48. package/dist/server/app.js +266 -0
  49. package/dist/server/app.js.map +1 -0
  50. package/dist/server/app.test.js +97 -0
  51. package/dist/server/app.test.js.map +1 -0
  52. package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
  53. package/dist/server/asset-base-url-transform-plugin.js +16 -1
  54. package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
  55. package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
  56. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
  57. package/dist/server/auth/discovery.d.ts +33 -0
  58. package/dist/server/auth/discovery.js +56 -0
  59. package/dist/server/auth/discovery.js.map +1 -0
  60. package/dist/server/auth/discovery.test.d.ts +1 -0
  61. package/dist/server/auth/discovery.test.js +93 -0
  62. package/dist/server/auth/discovery.test.js.map +1 -0
  63. package/dist/server/auth/index.d.ts +48 -0
  64. package/dist/server/auth/index.js +2 -0
  65. package/dist/server/auth/index.js.map +1 -0
  66. package/dist/server/auth/providers/auth0.d.ts +40 -0
  67. package/dist/server/auth/providers/auth0.js +36 -0
  68. package/dist/server/auth/providers/auth0.js.map +1 -0
  69. package/dist/server/auth/providers/auth0.test.d.ts +1 -0
  70. package/dist/server/auth/providers/auth0.test.js +50 -0
  71. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  72. package/dist/server/auth/providers/authplane.d.ts +49 -0
  73. package/dist/server/auth/providers/authplane.js +57 -0
  74. package/dist/server/auth/providers/authplane.js.map +1 -0
  75. package/dist/server/auth/providers/authplane.test.d.ts +1 -0
  76. package/dist/server/auth/providers/authplane.test.js +143 -0
  77. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  78. package/dist/server/auth/providers/clerk.d.ts +51 -0
  79. package/dist/server/auth/providers/clerk.js +19 -0
  80. package/dist/server/auth/providers/clerk.js.map +1 -0
  81. package/dist/server/auth/providers/clerk.test.d.ts +1 -0
  82. package/dist/server/auth/providers/clerk.test.js +30 -0
  83. package/dist/server/auth/providers/clerk.test.js.map +1 -0
  84. package/dist/server/auth/providers/custom.d.ts +42 -0
  85. package/dist/server/auth/providers/custom.js +59 -0
  86. package/dist/server/auth/providers/custom.js.map +1 -0
  87. package/dist/server/auth/providers/custom.test.d.ts +1 -0
  88. package/dist/server/auth/providers/custom.test.js +161 -0
  89. package/dist/server/auth/providers/custom.test.js.map +1 -0
  90. package/dist/server/auth/providers/descope.d.ts +44 -0
  91. package/dist/server/auth/providers/descope.js +44 -0
  92. package/dist/server/auth/providers/descope.js.map +1 -0
  93. package/dist/server/auth/providers/descope.test.d.ts +1 -0
  94. package/dist/server/auth/providers/descope.test.js +62 -0
  95. package/dist/server/auth/providers/descope.test.js.map +1 -0
  96. package/dist/server/auth/providers/shared.d.ts +2 -0
  97. package/dist/server/auth/providers/shared.js +6 -0
  98. package/dist/server/auth/providers/shared.js.map +1 -0
  99. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  100. package/dist/server/auth/providers/shared.test.js +10 -0
  101. package/dist/server/auth/providers/shared.test.js.map +1 -0
  102. package/dist/server/auth/providers/stytch.d.ts +25 -0
  103. package/dist/server/auth/providers/stytch.js +16 -0
  104. package/dist/server/auth/providers/stytch.js.map +1 -0
  105. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  106. package/dist/server/auth/providers/verify-spy.js +21 -0
  107. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  108. package/dist/server/auth/providers/workos.d.ts +34 -0
  109. package/dist/server/auth/providers/workos.js +16 -0
  110. package/dist/server/auth/providers/workos.js.map +1 -0
  111. package/dist/server/auth/security-schemes.d.ts +23 -0
  112. package/dist/server/auth/security-schemes.js +64 -0
  113. package/dist/server/auth/security-schemes.js.map +1 -0
  114. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  115. package/dist/server/auth/security-schemes.test.js +99 -0
  116. package/dist/server/auth/security-schemes.test.js.map +1 -0
  117. package/dist/server/auth/setup.d.ts +6 -0
  118. package/dist/server/auth/setup.js +91 -0
  119. package/dist/server/auth/setup.js.map +1 -0
  120. package/dist/server/auth/setup.test.d.ts +1 -0
  121. package/dist/server/auth/setup.test.js +514 -0
  122. package/dist/server/auth/setup.test.js.map +1 -0
  123. package/dist/server/auth/verify.d.ts +48 -0
  124. package/dist/server/auth/verify.js +62 -0
  125. package/dist/server/auth/verify.js.map +1 -0
  126. package/dist/server/auth/verify.test.d.ts +1 -0
  127. package/dist/server/auth/verify.test.js +165 -0
  128. package/dist/server/auth/verify.test.js.map +1 -0
  129. package/dist/server/auth-extra.test-d.js +130 -0
  130. package/dist/server/auth-extra.test-d.js.map +1 -0
  131. package/dist/server/auth.d.ts +57 -0
  132. package/dist/server/auth.js +27 -0
  133. package/dist/server/auth.js.map +1 -0
  134. package/dist/server/build-manifest.test.d.ts +1 -0
  135. package/dist/server/build-manifest.test.js +28 -0
  136. package/dist/server/build-manifest.test.js.map +1 -0
  137. package/dist/server/content-helpers.d.ts +41 -1
  138. package/dist/server/content-helpers.js +33 -0
  139. package/dist/server/content-helpers.js.map +1 -1
  140. package/dist/server/express.d.ts +23 -3
  141. package/dist/server/express.js +38 -32
  142. package/dist/server/express.js.map +1 -1
  143. package/dist/server/express.test.js +268 -90
  144. package/dist/server/express.test.js.map +1 -1
  145. package/dist/server/file-ref.d.ts +28 -0
  146. package/dist/server/file-ref.js +27 -0
  147. package/dist/server/file-ref.js.map +1 -0
  148. package/dist/server/host.d.ts +2 -0
  149. package/dist/server/host.js +11 -0
  150. package/dist/server/host.js.map +1 -0
  151. package/dist/server/host.test.d.ts +1 -0
  152. package/dist/server/host.test.js +13 -0
  153. package/dist/server/host.test.js.map +1 -0
  154. package/dist/server/index.d.ts +18 -2
  155. package/dist/server/index.js +15 -1
  156. package/dist/server/index.js.map +1 -1
  157. package/dist/server/mcp-errors.test.d.ts +1 -0
  158. package/dist/server/mcp-errors.test.js +41 -0
  159. package/dist/server/mcp-errors.test.js.map +1 -0
  160. package/dist/server/middleware.d.ts +51 -13
  161. package/dist/server/middleware.js +33 -0
  162. package/dist/server/middleware.js.map +1 -1
  163. package/dist/server/middleware.test-d.js +1 -1
  164. package/dist/server/middleware.test-d.js.map +1 -1
  165. package/dist/server/middleware.test.js +242 -134
  166. package/dist/server/middleware.test.js.map +1 -1
  167. package/dist/server/register-tool.test.d.ts +1 -0
  168. package/dist/server/register-tool.test.js +110 -0
  169. package/dist/server/register-tool.test.js.map +1 -0
  170. package/dist/server/requestOrigin.d.ts +7 -0
  171. package/dist/server/requestOrigin.js +25 -0
  172. package/dist/server/requestOrigin.js.map +1 -0
  173. package/dist/server/server.d.ts +403 -66
  174. package/dist/server/server.js +469 -316
  175. package/dist/server/server.js.map +1 -1
  176. package/dist/server/skills-integration.test.d.ts +1 -0
  177. package/dist/server/skills-integration.test.js +86 -0
  178. package/dist/server/skills-integration.test.js.map +1 -0
  179. package/dist/server/skills.d.ts +27 -0
  180. package/dist/server/skills.js +188 -0
  181. package/dist/server/skills.js.map +1 -0
  182. package/dist/server/skills.test.d.ts +1 -0
  183. package/dist/server/skills.test.js +243 -0
  184. package/dist/server/skills.test.js.map +1 -0
  185. package/dist/server/templateHelper.d.ts +0 -3
  186. package/dist/server/templateHelper.js.map +1 -1
  187. package/dist/server/templates.generated.js +4 -8
  188. package/dist/server/templates.generated.js.map +1 -1
  189. package/dist/server/tool-extra.test.d.ts +1 -0
  190. package/dist/server/tool-extra.test.js +88 -0
  191. package/dist/server/tool-extra.test.js.map +1 -0
  192. package/dist/server/view-name.test-d.d.ts +1 -0
  193. package/dist/server/view-name.test-d.js +8 -0
  194. package/dist/server/view-name.test-d.js.map +1 -0
  195. package/dist/server/view-resource-resolution.test.d.ts +6 -0
  196. package/dist/server/view-resource-resolution.test.js +176 -0
  197. package/dist/server/view-resource-resolution.test.js.map +1 -0
  198. package/dist/server/viewsDevServer.js +4 -1
  199. package/dist/server/viewsDevServer.js.map +1 -1
  200. package/dist/test/utils.d.ts +9 -11
  201. package/dist/test/utils.js +220 -201
  202. package/dist/test/utils.js.map +1 -1
  203. package/dist/test/view.test.js +123 -106
  204. package/dist/test/view.test.js.map +1 -1
  205. package/dist/views/index.d.ts +10 -0
  206. package/dist/views/index.js +3 -0
  207. package/dist/views/index.js.map +1 -0
  208. package/dist/{web/plugin → views}/scan-views.js +1 -1
  209. package/dist/views/scan-views.js.map +1 -0
  210. package/dist/views/scan-views.test.d.ts +1 -0
  211. package/dist/views/scan-views.test.js.map +1 -0
  212. package/dist/views/validate-view.d.ts +1 -0
  213. package/dist/{web/plugin → views}/validate-view.js +2 -2
  214. package/dist/views/validate-view.js.map +1 -0
  215. package/dist/views/validate-view.test.d.ts +1 -0
  216. package/dist/views/validate-view.test.js.map +1 -0
  217. package/dist/web/bridges/adaptor.d.ts +56 -0
  218. package/dist/web/bridges/adaptor.js +397 -0
  219. package/dist/web/bridges/adaptor.js.map +1 -0
  220. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  221. package/dist/web/bridges/adaptor.test.js +264 -0
  222. package/dist/web/bridges/adaptor.test.js.map +1 -0
  223. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -1
  224. package/dist/web/bridges/apps-sdk/bridge.js +15 -3
  225. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  226. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  227. package/dist/web/bridges/apps-sdk/index.js +0 -1
  228. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  229. package/dist/web/bridges/apps-sdk/types.d.ts +8 -1
  230. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  231. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  232. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  233. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  234. package/dist/web/bridges/get-adaptor.d.ts +7 -0
  235. package/dist/web/bridges/get-adaptor.js +9 -7
  236. package/dist/web/bridges/get-adaptor.js.map +1 -1
  237. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  238. package/dist/web/bridges/get-adaptor.test.js +32 -0
  239. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  240. package/dist/web/bridges/mcp-app/bridge.d.ts +15 -2
  241. package/dist/web/bridges/mcp-app/bridge.js +80 -7
  242. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  243. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  244. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  245. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  246. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  247. package/dist/web/bridges/mcp-app/index.js +0 -1
  248. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  249. package/dist/web/bridges/mcp-app/types.d.ts +19 -2
  250. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  251. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +13 -1
  252. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
  253. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  254. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  255. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  256. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  257. package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
  258. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  259. package/dist/web/bridges/types.d.ts +142 -6
  260. package/dist/web/bridges/types.js +14 -1
  261. package/dist/web/bridges/types.js.map +1 -1
  262. package/dist/web/bridges/types.test.d.ts +1 -0
  263. package/dist/web/bridges/types.test.js +19 -0
  264. package/dist/web/bridges/types.test.js.map +1 -0
  265. package/dist/web/bridges/use-host-context.d.ts +5 -0
  266. package/dist/web/bridges/use-host-context.js +5 -0
  267. package/dist/web/bridges/use-host-context.js.map +1 -1
  268. package/dist/web/components/modal-provider.d.ts +1 -1
  269. package/dist/web/components/modal-provider.js +4 -3
  270. package/dist/web/components/modal-provider.js.map +1 -1
  271. package/dist/web/create-store.d.ts +26 -0
  272. package/dist/web/create-store.js +26 -0
  273. package/dist/web/create-store.js.map +1 -1
  274. package/dist/web/create-store.test.js +10 -7
  275. package/dist/web/create-store.test.js.map +1 -1
  276. package/dist/web/data-llm.d.ts +34 -1
  277. package/dist/web/data-llm.js +31 -2
  278. package/dist/web/data-llm.js.map +1 -1
  279. package/dist/web/data-llm.test.js +26 -7
  280. package/dist/web/data-llm.test.js.map +1 -1
  281. package/dist/web/generate-helpers.d.ts +25 -19
  282. package/dist/web/generate-helpers.js +23 -17
  283. package/dist/web/generate-helpers.js.map +1 -1
  284. package/dist/web/generate-helpers.test-d.js +7 -5
  285. package/dist/web/generate-helpers.test-d.js.map +1 -1
  286. package/dist/web/generate-helpers.test.js +2 -2
  287. package/dist/web/generate-helpers.test.js.map +1 -1
  288. package/dist/web/hooks/index.d.ts +9 -1
  289. package/dist/web/hooks/index.js +9 -1
  290. package/dist/web/hooks/index.js.map +1 -1
  291. package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
  292. package/dist/web/hooks/openai-extensions.test.js +107 -0
  293. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  294. package/dist/web/hooks/test/utils.d.ts +7 -2
  295. package/dist/web/hooks/test/utils.js +14 -3
  296. package/dist/web/hooks/test/utils.js.map +1 -1
  297. package/dist/web/hooks/use-call-tool.d.ts +47 -2
  298. package/dist/web/hooks/use-call-tool.js +43 -10
  299. package/dist/web/hooks/use-call-tool.js.map +1 -1
  300. package/dist/web/hooks/use-call-tool.test.js +75 -29
  301. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  302. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  303. package/dist/web/hooks/use-deep-link.js +34 -0
  304. package/dist/web/hooks/use-deep-link.js.map +1 -0
  305. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  306. package/dist/web/hooks/use-display-mode.js +20 -0
  307. package/dist/web/hooks/use-display-mode.js.map +1 -1
  308. package/dist/web/hooks/use-display-mode.test.js +57 -21
  309. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  310. package/dist/web/hooks/use-download.d.ts +3 -0
  311. package/dist/web/hooks/use-download.js +7 -0
  312. package/dist/web/hooks/use-download.js.map +1 -0
  313. package/dist/web/hooks/use-download.test.d.ts +1 -0
  314. package/dist/web/hooks/use-download.test.js +103 -0
  315. package/dist/web/hooks/use-download.test.js.map +1 -0
  316. package/dist/web/hooks/use-files.d.ts +32 -0
  317. package/dist/web/hooks/use-files.js +32 -0
  318. package/dist/web/hooks/use-files.js.map +1 -1
  319. package/dist/web/hooks/use-files.test.js +11 -3
  320. package/dist/web/hooks/use-files.test.js.map +1 -1
  321. package/dist/web/hooks/use-host.d.ts +44 -0
  322. package/dist/web/hooks/use-host.js +45 -0
  323. package/dist/web/hooks/use-host.js.map +1 -0
  324. package/dist/web/hooks/use-host.test.d.ts +1 -0
  325. package/dist/web/hooks/use-host.test.js +59 -0
  326. package/dist/web/hooks/use-host.test.js.map +1 -0
  327. package/dist/web/hooks/use-model-context.d.ts +44 -0
  328. package/dist/web/hooks/use-model-context.js +63 -0
  329. package/dist/web/hooks/use-model-context.js.map +1 -0
  330. package/dist/web/hooks/use-open-external.d.ts +17 -0
  331. package/dist/web/hooks/use-open-external.js +16 -0
  332. package/dist/web/hooks/use-open-external.js.map +1 -1
  333. package/dist/web/hooks/use-open-external.test.js +15 -5
  334. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  335. package/dist/web/hooks/use-open-file.d.ts +19 -0
  336. package/dist/web/hooks/use-open-file.js +24 -0
  337. package/dist/web/hooks/use-open-file.js.map +1 -0
  338. package/dist/web/hooks/use-register-view-tool.d.ts +37 -0
  339. package/dist/web/hooks/use-register-view-tool.js +50 -0
  340. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  341. package/dist/web/hooks/use-request-close.d.ts +16 -0
  342. package/dist/web/hooks/use-request-close.js +21 -0
  343. package/dist/web/hooks/use-request-close.js.map +1 -0
  344. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  345. package/dist/web/hooks/use-request-close.test.js +47 -0
  346. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  347. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  348. package/dist/web/hooks/use-request-modal.js +16 -1
  349. package/dist/web/hooks/use-request-modal.js.map +1 -1
  350. package/dist/web/hooks/use-request-modal.test.js +11 -1
  351. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  352. package/dist/web/hooks/use-request-size.d.ts +20 -0
  353. package/dist/web/hooks/use-request-size.js +24 -0
  354. package/dist/web/hooks/use-request-size.js.map +1 -0
  355. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  356. package/dist/web/hooks/use-request-size.test.js +47 -0
  357. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  358. package/dist/web/hooks/use-send-follow-up-message.d.ts +25 -1
  359. package/dist/web/hooks/use-send-follow-up-message.js +25 -2
  360. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  361. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  362. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  363. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  364. package/dist/web/hooks/use-set-open-in-app-url.test.js +26 -12
  365. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  366. package/dist/web/hooks/use-tool-info.d.ts +46 -14
  367. package/dist/web/hooks/use-tool-info.js +29 -7
  368. package/dist/web/hooks/use-tool-info.js.map +1 -1
  369. package/dist/web/hooks/use-tool-info.test-d.js +11 -34
  370. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  371. package/dist/web/hooks/use-tool-info.test.js +42 -37
  372. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  373. package/dist/web/hooks/use-user.d.ts +5 -2
  374. package/dist/web/hooks/use-user.js +6 -3
  375. package/dist/web/hooks/use-user.js.map +1 -1
  376. package/dist/web/hooks/use-user.test.js +85 -37
  377. package/dist/web/hooks/use-user.test.js.map +1 -1
  378. package/dist/web/hooks/use-view-state.d.ts +21 -0
  379. package/dist/web/hooks/use-view-state.js +19 -9
  380. package/dist/web/hooks/use-view-state.js.map +1 -1
  381. package/dist/web/hooks/use-view-state.test.js +39 -4
  382. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  383. package/dist/web/hooks/use-viewport.d.ts +20 -0
  384. package/dist/web/hooks/use-viewport.js +21 -0
  385. package/dist/web/hooks/use-viewport.js.map +1 -0
  386. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  387. package/dist/web/hooks/use-viewport.test.js +109 -0
  388. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  389. package/dist/web/mount-view.d.ts +20 -0
  390. package/dist/web/mount-view.js +22 -6
  391. package/dist/web/mount-view.js.map +1 -1
  392. package/dist/web/types.d.ts +4 -0
  393. package/dist/web/types.js.map +1 -1
  394. package/package.json +36 -26
  395. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -24
  396. package/dist/web/bridges/apps-sdk/adaptor.js +0 -93
  397. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  398. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -48
  399. package/dist/web/bridges/mcp-app/adaptor.js +0 -268
  400. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  401. package/dist/web/hooks/use-layout.d.ts +0 -22
  402. package/dist/web/hooks/use-layout.js +0 -23
  403. package/dist/web/hooks/use-layout.js.map +0 -1
  404. package/dist/web/hooks/use-layout.test.js +0 -96
  405. package/dist/web/hooks/use-layout.test.js.map +0 -1
  406. package/dist/web/plugin/data-llm.test.js +0 -81
  407. package/dist/web/plugin/data-llm.test.js.map +0 -1
  408. package/dist/web/plugin/plugin.d.ts +0 -5
  409. package/dist/web/plugin/plugin.js +0 -156
  410. package/dist/web/plugin/plugin.js.map +0 -1
  411. package/dist/web/plugin/scan-views.js.map +0 -1
  412. package/dist/web/plugin/scan-views.test.js.map +0 -1
  413. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  414. package/dist/web/plugin/transform-data-llm.js +0 -96
  415. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  416. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  417. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  418. package/dist/web/plugin/validate-view.d.ts +0 -1
  419. package/dist/web/plugin/validate-view.js.map +0 -1
  420. package/dist/web/plugin/validate-view.test.js.map +0 -1
  421. /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  422. /package/dist/{web/plugin/data-llm.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  423. /package/dist/{web/plugin/scan-views.test.d.ts → context-warnings.test.d.ts} +0 -0
  424. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/app.test.d.ts} +0 -0
  425. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  426. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  427. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  428. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -1,18 +1,27 @@
1
1
  import { act, renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi, } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
5
+ import { getAdaptor } from "../bridges/get-adaptor.js";
6
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
3
7
  import { useCallTool } from "./use-call-tool.js";
4
8
  describe("useCallTool - onSuccess callback", () => {
5
- let OpenaiMock;
9
+ let callToolMock;
6
10
  beforeEach(() => {
7
- OpenaiMock = {
8
- callTool: vi.fn(),
9
- };
10
- vi.stubGlobal("openai", OpenaiMock);
11
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
11
+ HostAdaptor.resetInstance();
12
+ McpAppBridge.resetInstance();
13
+ AppsSdkBridge.resetInstance();
14
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
15
+ vi.stubGlobal("skybridge", {});
16
+ vi.stubGlobal("openai", { callTool: vi.fn() });
17
+ callToolMock = vi.spyOn(getAdaptor(), "callTool");
12
18
  });
13
19
  afterEach(() => {
14
20
  vi.unstubAllGlobals();
15
21
  vi.resetAllMocks();
22
+ HostAdaptor.resetInstance();
23
+ McpAppBridge.resetInstance();
24
+ AppsSdkBridge.resetInstance();
16
25
  });
17
26
  const toolName = "test-tool";
18
27
  const args = { input: "test input" };
@@ -20,20 +29,40 @@ describe("useCallTool - onSuccess callback", () => {
20
29
  content: [{ type: "text", text: "test result" }],
21
30
  structuredContent: { result: "test" },
22
31
  isError: false,
23
- result: "test result",
32
+ meta: {},
24
33
  };
25
34
  const error = new Error("test error");
26
- it("should call window.openai.callTool with correct arguments", async () => {
35
+ it("should normalize _meta to meta when SDK returns _meta instead of meta", async () => {
36
+ const rawSdkResponse = {
37
+ content: [{ type: "text", text: "result" }],
38
+ structuredContent: { value: 1 },
39
+ isError: false,
40
+ meta: { secret: "only visible to widget" },
41
+ };
42
+ callToolMock.mockResolvedValueOnce(rawSdkResponse);
27
43
  const { result } = renderHook(() => useCallTool(toolName));
28
44
  await act(async () => {
29
45
  result.current.callTool(args);
30
46
  });
31
- expect(OpenaiMock.callTool).toHaveBeenCalledWith(toolName, args);
47
+ await waitFor(() => {
48
+ expect(result.current.data).toMatchObject({
49
+ meta: { secret: "only visible to widget" },
50
+ });
51
+ });
52
+ });
53
+ it("should call adaptor.callTool with correct arguments", async () => {
54
+ const { result } = renderHook(() => useCallTool(toolName));
55
+ await act(async () => {
56
+ result.current.callTool(args);
57
+ });
58
+ expect(callToolMock).toHaveBeenCalledWith(toolName, args, {
59
+ timeout: undefined,
60
+ });
32
61
  });
33
62
  it("should call onSuccess callback with correct data and toolArgs on successful execution", async () => {
34
63
  const onSuccess = vi.fn();
35
64
  const onError = vi.fn();
36
- OpenaiMock.callTool.mockResolvedValueOnce(data);
65
+ callToolMock.mockResolvedValueOnce(data);
37
66
  const { result } = renderHook(() => useCallTool(toolName));
38
67
  act(() => {
39
68
  result.current.callTool(args, {
@@ -49,7 +78,7 @@ describe("useCallTool - onSuccess callback", () => {
49
78
  it("should call onError callback with error and toolArgs on failed execution", async () => {
50
79
  const onSuccess = vi.fn();
51
80
  const onError = vi.fn();
52
- OpenaiMock.callTool.mockRejectedValueOnce(error);
81
+ callToolMock.mockRejectedValueOnce(error);
53
82
  const { result } = renderHook(() => useCallTool(toolName));
54
83
  act(() => {
55
84
  result.current.callTool(args, {
@@ -66,7 +95,7 @@ describe("useCallTool - onSuccess callback", () => {
66
95
  const onSuccess = vi.fn();
67
96
  const onError = vi.fn();
68
97
  const onSettled = vi.fn();
69
- OpenaiMock.callTool.mockResolvedValueOnce(data);
98
+ callToolMock.mockResolvedValueOnce(data);
70
99
  const { result } = renderHook(() => useCallTool(toolName));
71
100
  act(() => {
72
101
  result.current.callTool(args, {
@@ -85,7 +114,7 @@ describe("useCallTool - onSuccess callback", () => {
85
114
  const onSuccess = vi.fn();
86
115
  const onError = vi.fn();
87
116
  const onSettled = vi.fn();
88
- OpenaiMock.callTool.mockRejectedValueOnce(error);
117
+ callToolMock.mockRejectedValueOnce(error);
89
118
  const { result } = renderHook(() => useCallTool(toolName));
90
119
  act(() => {
91
120
  result.current.callTool(args, {
@@ -102,11 +131,17 @@ describe("useCallTool - onSuccess callback", () => {
102
131
  });
103
132
  it("should always return last call started state", async () => {
104
133
  const { result } = renderHook(() => useCallTool(toolName));
105
- const firstCallData = { ...data, result: "first call result" };
106
- const secondCallData = { ...data, result: "second call result" };
134
+ const firstCallData = {
135
+ ...data,
136
+ structuredContent: { result: "first call result" },
137
+ };
138
+ const secondCallData = {
139
+ ...data,
140
+ structuredContent: { result: "second call result" },
141
+ };
107
142
  const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } = Promise.withResolvers();
108
143
  const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } = Promise.withResolvers();
109
- OpenaiMock.callTool
144
+ callToolMock
110
145
  .mockImplementationOnce(() => firstCallToolPromise)
111
146
  .mockImplementationOnce(() => secondCallToolPromise);
112
147
  await act(() => {
@@ -123,19 +158,31 @@ describe("useCallTool - onSuccess callback", () => {
123
158
  expect(result.current.data).toEqual(secondCallData);
124
159
  });
125
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
+ });
126
168
  });
127
169
  describe("useCallTool - TypeScript typing", () => {
128
- let OpenaiMock;
170
+ let callToolMock;
129
171
  beforeEach(() => {
130
- OpenaiMock = {
131
- callTool: vi.fn(),
132
- };
133
- vi.stubGlobal("openai", OpenaiMock);
134
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
172
+ HostAdaptor.resetInstance();
173
+ McpAppBridge.resetInstance();
174
+ AppsSdkBridge.resetInstance();
175
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
176
+ vi.stubGlobal("skybridge", {});
177
+ vi.stubGlobal("openai", { callTool: vi.fn() });
178
+ callToolMock = vi.spyOn(getAdaptor(), "callTool");
135
179
  });
136
180
  afterEach(() => {
137
181
  vi.unstubAllGlobals();
138
182
  vi.resetAllMocks();
183
+ HostAdaptor.resetInstance();
184
+ McpAppBridge.resetInstance();
185
+ AppsSdkBridge.resetInstance();
139
186
  });
140
187
  it("should have correct return types when ToolArgs is null and ToolResponse is specified", async () => {
141
188
  const { result } = renderHook(() => useCallTool("test-tool"));
@@ -143,14 +190,15 @@ describe("useCallTool - TypeScript typing", () => {
143
190
  content: [{ type: "text", text: "test" }],
144
191
  structuredContent: { result: "test" },
145
192
  isError: false,
146
- result: "test",
147
193
  meta: { id: 123 },
148
194
  };
149
- OpenaiMock.callTool.mockResolvedValueOnce(data);
195
+ callToolMock.mockResolvedValueOnce(data);
150
196
  await act(async () => {
151
197
  result.current.callTool();
152
198
  });
153
- expect(OpenaiMock.callTool).toHaveBeenCalledWith("test-tool", null);
199
+ expect(callToolMock).toHaveBeenCalledWith("test-tool", null, {
200
+ timeout: undefined,
201
+ });
154
202
  expectTypeOf(result.current.data);
155
203
  });
156
204
  it("should correctly type callToolAsync return value", async () => {
@@ -160,10 +208,9 @@ describe("useCallTool - TypeScript typing", () => {
160
208
  content: [{ type: "text", text: "answer" }],
161
209
  structuredContent: { answer: "test answer" },
162
210
  isError: false,
163
- result: "answer",
164
211
  meta: {},
165
212
  };
166
- OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
213
+ callToolMock.mockResolvedValueOnce(mockResponse);
167
214
  const returnedValue = await act(async () => {
168
215
  return result.current.callToolAsync(testArgs);
169
216
  });
@@ -176,10 +223,9 @@ describe("useCallTool - TypeScript typing", () => {
176
223
  content: [{ type: "text", text: "data" }],
177
224
  structuredContent: { data: "test data" },
178
225
  isError: false,
179
- result: "data",
180
226
  meta: {},
181
227
  };
182
- OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
228
+ callToolMock.mockResolvedValueOnce(mockResponse);
183
229
  const returnedValue = await act(async () => {
184
230
  return result.current.callToolAsync();
185
231
  });
@@ -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,wBAAw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,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\";\n\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport { useCallTool } from \"./use-call-tool.js\";\n\ndescribe(\"useCallTool - onSuccess callback\", () => {\n let OpenaiMock: { callTool: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n callTool: vi.fn(),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\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 result: \"test result\",\n };\n const error = new Error(\"test error\");\n\n it(\"should call window.openai.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(OpenaiMock.callTool).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 OpenaiMock.callTool.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 OpenaiMock.callTool.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 OpenaiMock.callTool.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 OpenaiMock.callTool.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 = { ...data, result: \"first call result\" };\n const secondCallData = { ...data, result: \"second call result\" };\n const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } =\n Promise.withResolvers();\n const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } =\n Promise.withResolvers();\n OpenaiMock.callTool\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 OpenaiMock: { callTool: Mock };\n\n beforeEach(() => {\n OpenaiMock = {\n callTool: vi.fn(),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\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 result: \"test\",\n meta: { id: 123 },\n };\n\n OpenaiMock.callTool.mockResolvedValueOnce(data);\n\n await act(async () => {\n result.current.callTool();\n });\n\n expect(OpenaiMock.callTool).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 result: \"answer\",\n meta: {},\n };\n\n OpenaiMock.callTool.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 result: \"data\",\n meta: {},\n };\n\n OpenaiMock.callTool.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,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,EA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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"]}
@@ -1,4 +1,24 @@
1
1
  import type { RequestDisplayMode } from "../bridges/types.js";
2
+ /**
3
+ * Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
4
+ *
5
+ * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
6
+ * host to switch modes — the host returns the mode it actually applied, which
7
+ * may differ from the request. The reported value also updates when the host
8
+ * changes the mode on its own (e.g. user expands the widget).
9
+ *
10
+ * `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
11
+ * to layout changes that come with display-mode switches (e.g. `maxHeight`),
12
+ * pair with {@link useViewport}.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const [mode, setMode] = useDisplayMode();
17
+ * <button onClick={() => setMode("fullscreen")}>Expand</button>
18
+ * ```
19
+ *
20
+ * @see https://docs.skybridge.tech/api-reference/use-display-mode
21
+ */
2
22
  export declare function useDisplayMode(): readonly [import("../index.js").DisplayMode, (mode: RequestDisplayMode) => Promise<{
3
23
  mode: RequestDisplayMode;
4
24
  }>];
@@ -1,5 +1,25 @@
1
1
  import { useCallback } from "react";
2
2
  import { getAdaptor, useHostContext } from "../bridges/index.js";
3
+ /**
4
+ * Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
5
+ *
6
+ * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
7
+ * host to switch modes — the host returns the mode it actually applied, which
8
+ * may differ from the request. The reported value also updates when the host
9
+ * changes the mode on its own (e.g. user expands the widget).
10
+ *
11
+ * `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
12
+ * to layout changes that come with display-mode switches (e.g. `maxHeight`),
13
+ * pair with {@link useViewport}.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const [mode, setMode] = useDisplayMode();
18
+ * <button onClick={() => setMode("fullscreen")}>Expand</button>
19
+ * ```
20
+ *
21
+ * @see https://docs.skybridge.tech/api-reference/use-display-mode
22
+ */
3
23
  export function useDisplayMode() {
4
24
  const displayMode = useHostContext("displayMode");
5
25
  const adaptor = getAdaptor();
@@ -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,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\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"]}
@@ -1,39 +1,75 @@
1
- import { act, renderHook } from "@testing-library/react";
2
- import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
1
+ import { act, fireEvent, renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
+ import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
5
+ import { getAdaptor } from "../bridges/get-adaptor.js";
6
+ import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
7
+ import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
3
8
  import { useDisplayMode } from "./use-display-mode.js";
4
9
  describe("useDisplayMode", () => {
5
- let OpenaiMock;
6
10
  beforeEach(() => {
7
- OpenaiMock = {
8
- displayMode: "inline",
9
- requestDisplayMode: vi.fn().mockResolvedValue({ mode: "inline" }),
10
- };
11
- vi.stubGlobal("openai", OpenaiMock);
12
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
11
+ HostAdaptor.resetInstance();
12
+ McpAppBridge.resetInstance();
13
+ AppsSdkBridge.resetInstance();
14
+ vi.stubGlobal("skybridge", {});
15
+ vi.stubGlobal("openai", { view: { mode: "inline" } });
16
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
13
17
  });
14
18
  afterEach(() => {
15
19
  vi.unstubAllGlobals();
16
20
  vi.resetAllMocks();
21
+ HostAdaptor.resetInstance();
22
+ McpAppBridge.resetInstance();
23
+ AppsSdkBridge.resetInstance();
17
24
  });
18
- it("should return the current display mode from window.openai.displayMode", () => {
19
- OpenaiMock.displayMode = "inline";
25
+ it("should return the current display mode from MCP host context", async () => {
26
+ vi.stubGlobal("parent", {
27
+ postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
28
+ });
20
29
  const { result } = renderHook(() => useDisplayMode());
21
- expect(result.current[0]).toBe("inline");
30
+ await waitFor(() => {
31
+ expect(result.current[0]).toBe("inline");
32
+ });
22
33
  });
23
- it("should return different display modes when window.openai.displayMode changes", () => {
24
- OpenaiMock.displayMode = "inline";
25
- const { result, rerender } = renderHook(() => useDisplayMode());
26
- expect(result.current[0]).toBe("inline");
27
- OpenaiMock.displayMode = "fullscreen";
28
- rerender();
29
- expect(result.current[0]).toBe("fullscreen");
34
+ it("should update display mode on host-context-changed notification", async () => {
35
+ vi.stubGlobal("parent", {
36
+ postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
37
+ });
38
+ const { result } = renderHook(() => useDisplayMode());
39
+ await waitFor(() => {
40
+ expect(result.current[0]).toBe("inline");
41
+ });
42
+ act(() => {
43
+ fireEvent(window, new MessageEvent("message", {
44
+ source: window.parent,
45
+ data: {
46
+ jsonrpc: "2.0",
47
+ method: "ui/notifications/host-context-changed",
48
+ params: { displayMode: "fullscreen" },
49
+ },
50
+ }));
51
+ });
52
+ await waitFor(() => {
53
+ expect(result.current[0]).toBe("fullscreen");
54
+ });
30
55
  });
31
- it("should call window.openai.requestDisplayMode with correct mode when setDisplayMode is called", async () => {
56
+ it("should call requestDisplayMode on the adaptor when setDisplayMode is called", async () => {
57
+ vi.stubGlobal("parent", {
58
+ postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
59
+ });
32
60
  const { result } = renderHook(() => useDisplayMode());
61
+ await waitFor(() => expect(result.current[0]).toBe("inline"));
62
+ // Patch mcp.getApp to avoid real protocol request
63
+ const adaptor = getAdaptor();
64
+ const fakeApp = {
65
+ requestDisplayMode: vi.fn().mockResolvedValue({ mode: "fullscreen" }),
66
+ };
67
+ // biome-ignore lint/suspicious/noExplicitAny: test seam
68
+ adaptor.mcp.getApp = vi.fn().mockResolvedValue(fakeApp);
33
69
  await act(async () => {
34
70
  await result.current[1]("fullscreen");
35
71
  });
36
- expect(OpenaiMock.requestDisplayMode).toHaveBeenCalledWith({
72
+ expect(fakeApp.requestDisplayMode).toHaveBeenCalledWith({
37
73
  mode: "fullscreen",
38
74
  });
39
75
  });
@@ -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,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,UAGH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,WAAW,EAAE,QAAQ;YACrB,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;SAClE,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uEAAuE,EAAE,GAAG,EAAE;QAC/E,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;QAClC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,GAAG,EAAE;QACtF,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;QAClC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEhE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzC,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;QACtC,QAAQ,EAAE,CAAC;QAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8FAA8F,EAAE,KAAK,IAAI,EAAE;QAC5G,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,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,UAAU,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC;YACzD,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport type { DisplayMode } from \"../bridges/types.js\";\nimport { useDisplayMode } from \"./use-display-mode.js\";\n\ndescribe(\"useDisplayMode\", () => {\n let OpenaiMock: {\n displayMode: DisplayMode;\n requestDisplayMode: Mock;\n };\n\n beforeEach(() => {\n OpenaiMock = {\n displayMode: \"inline\",\n requestDisplayMode: vi.fn().mockResolvedValue({ mode: \"inline\" }),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return the current display mode from window.openai.displayMode\", () => {\n OpenaiMock.displayMode = \"inline\";\n const { result } = renderHook(() => useDisplayMode());\n\n expect(result.current[0]).toBe(\"inline\");\n });\n\n it(\"should return different display modes when window.openai.displayMode changes\", () => {\n OpenaiMock.displayMode = \"inline\";\n const { result, rerender } = renderHook(() => useDisplayMode());\n\n expect(result.current[0]).toBe(\"inline\");\n\n OpenaiMock.displayMode = \"fullscreen\";\n rerender();\n\n expect(result.current[0]).toBe(\"fullscreen\");\n });\n\n it(\"should call window.openai.requestDisplayMode with correct mode when setDisplayMode is called\", async () => {\n const { result } = renderHook(() => useDisplayMode());\n\n await act(async () => {\n await result.current[1](\"fullscreen\");\n });\n\n expect(OpenaiMock.requestDisplayMode).toHaveBeenCalledWith({\n mode: \"fullscreen\",\n });\n });\n});\n"]}
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,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E,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,OAAO,CAAC,GAAG,EAAE,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\", {});\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"]}
@@ -0,0 +1,3 @@
1
+ import type { DownloadParams, DownloadResult } from "../bridges/types.js";
2
+ export type DownloadFn = (params: DownloadParams) => Promise<DownloadResult>;
3
+ export declare function useDownload(): DownloadFn;
@@ -0,0 +1,7 @@
1
+ import { useCallback } from "react";
2
+ import { getAdaptor } from "../bridges/index.js";
3
+ export function useDownload() {
4
+ const adaptor = getAdaptor();
5
+ return useCallback((params) => adaptor.download(params), [adaptor]);
6
+ }
7
+ //# sourceMappingURL=use-download.js.map
@@ -0,0 +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,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"]}
@@ -0,0 +1 @@
1
+ export {};