skybridge 0.0.0-dev.dc576c4 → 0.0.0-dev.dc90b1c

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 (351) hide show
  1. package/README.md +10 -7
  2. package/dist/cli/build-helpers.d.ts +11 -0
  3. package/dist/cli/build-helpers.js +107 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.js +132 -0
  6. package/dist/cli/build-helpers.test.js.map +1 -0
  7. package/dist/cli/build-steps.d.ts +2 -0
  8. package/dist/cli/build-steps.js +73 -0
  9. package/dist/cli/build-steps.js.map +1 -0
  10. package/dist/cli/build-steps.test.js +52 -0
  11. package/dist/cli/build-steps.test.js.map +1 -0
  12. package/dist/cli/detect-port.d.ts +2 -2
  13. package/dist/cli/detect-port.js +8 -20
  14. package/dist/cli/detect-port.js.map +1 -1
  15. package/dist/cli/header.d.ts +1 -1
  16. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  17. package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
  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/use-execute-steps.d.ts +1 -1
  23. package/dist/cli/use-nodemon.d.ts +25 -1
  24. package/dist/cli/use-nodemon.js +96 -63
  25. package/dist/cli/use-nodemon.js.map +1 -1
  26. package/dist/cli/use-typescript-check.d.ts +8 -2
  27. package/dist/cli/use-typescript-check.js +70 -67
  28. package/dist/cli/use-typescript-check.js.map +1 -1
  29. package/dist/commands/build.d.ts +0 -3
  30. package/dist/commands/build.js +2 -58
  31. package/dist/commands/build.js.map +1 -1
  32. package/dist/commands/dev.d.ts +1 -0
  33. package/dist/commands/dev.js +38 -6
  34. package/dist/commands/dev.js.map +1 -1
  35. package/dist/commands/start.js +7 -1
  36. package/dist/commands/start.js.map +1 -1
  37. package/dist/context-warnings.d.ts +5 -0
  38. package/dist/context-warnings.js +31 -0
  39. package/dist/context-warnings.js.map +1 -0
  40. package/dist/context-warnings.test.js +28 -0
  41. package/dist/context-warnings.test.js.map +1 -0
  42. package/dist/server/app.d.ts +194 -0
  43. package/dist/server/app.js +266 -0
  44. package/dist/server/app.js.map +1 -0
  45. package/dist/server/app.test.js +97 -0
  46. package/dist/server/app.test.js.map +1 -0
  47. package/dist/server/auth/discovery.d.ts +33 -0
  48. package/dist/server/auth/discovery.js +56 -0
  49. package/dist/server/auth/discovery.js.map +1 -0
  50. package/dist/server/auth/discovery.test.d.ts +1 -0
  51. package/dist/server/auth/discovery.test.js +93 -0
  52. package/dist/server/auth/discovery.test.js.map +1 -0
  53. package/dist/server/auth/index.d.ts +48 -0
  54. package/dist/server/auth/index.js +2 -0
  55. package/dist/server/auth/index.js.map +1 -0
  56. package/dist/server/auth/providers/auth0.d.ts +40 -0
  57. package/dist/server/auth/providers/auth0.js +36 -0
  58. package/dist/server/auth/providers/auth0.js.map +1 -0
  59. package/dist/server/auth/providers/auth0.test.d.ts +1 -0
  60. package/dist/server/auth/providers/auth0.test.js +50 -0
  61. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  62. package/dist/server/auth/providers/authplane.d.ts +49 -0
  63. package/dist/server/auth/providers/authplane.js +57 -0
  64. package/dist/server/auth/providers/authplane.js.map +1 -0
  65. package/dist/server/auth/providers/authplane.test.d.ts +1 -0
  66. package/dist/server/auth/providers/authplane.test.js +143 -0
  67. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  68. package/dist/server/auth/providers/clerk.d.ts +51 -0
  69. package/dist/server/auth/providers/clerk.js +19 -0
  70. package/dist/server/auth/providers/clerk.js.map +1 -0
  71. package/dist/server/auth/providers/clerk.test.d.ts +1 -0
  72. package/dist/server/auth/providers/clerk.test.js +30 -0
  73. package/dist/server/auth/providers/clerk.test.js.map +1 -0
  74. package/dist/server/auth/providers/custom.d.ts +42 -0
  75. package/dist/server/auth/providers/custom.js +59 -0
  76. package/dist/server/auth/providers/custom.js.map +1 -0
  77. package/dist/server/auth/providers/custom.test.d.ts +1 -0
  78. package/dist/server/auth/providers/custom.test.js +161 -0
  79. package/dist/server/auth/providers/custom.test.js.map +1 -0
  80. package/dist/server/auth/providers/descope.d.ts +44 -0
  81. package/dist/server/auth/providers/descope.js +44 -0
  82. package/dist/server/auth/providers/descope.js.map +1 -0
  83. package/dist/server/auth/providers/descope.test.d.ts +1 -0
  84. package/dist/server/auth/providers/descope.test.js +62 -0
  85. package/dist/server/auth/providers/descope.test.js.map +1 -0
  86. package/dist/server/auth/providers/shared.d.ts +2 -0
  87. package/dist/server/auth/providers/shared.js +6 -0
  88. package/dist/server/auth/providers/shared.js.map +1 -0
  89. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  90. package/dist/server/auth/providers/shared.test.js +10 -0
  91. package/dist/server/auth/providers/shared.test.js.map +1 -0
  92. package/dist/server/auth/providers/stytch.d.ts +25 -0
  93. package/dist/server/auth/providers/stytch.js +16 -0
  94. package/dist/server/auth/providers/stytch.js.map +1 -0
  95. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  96. package/dist/server/auth/providers/verify-spy.js +21 -0
  97. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  98. package/dist/server/auth/providers/workos.d.ts +34 -0
  99. package/dist/server/auth/providers/workos.js +16 -0
  100. package/dist/server/auth/providers/workos.js.map +1 -0
  101. package/dist/server/auth/security-schemes.d.ts +23 -0
  102. package/dist/server/auth/security-schemes.js +64 -0
  103. package/dist/server/auth/security-schemes.js.map +1 -0
  104. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  105. package/dist/server/auth/security-schemes.test.js +99 -0
  106. package/dist/server/auth/security-schemes.test.js.map +1 -0
  107. package/dist/server/auth/setup.d.ts +6 -0
  108. package/dist/server/auth/setup.js +91 -0
  109. package/dist/server/auth/setup.js.map +1 -0
  110. package/dist/server/auth/setup.test.d.ts +1 -0
  111. package/dist/server/auth/setup.test.js +514 -0
  112. package/dist/server/auth/setup.test.js.map +1 -0
  113. package/dist/server/auth/verify.d.ts +48 -0
  114. package/dist/server/auth/verify.js +62 -0
  115. package/dist/server/auth/verify.js.map +1 -0
  116. package/dist/server/auth/verify.test.d.ts +1 -0
  117. package/dist/server/auth/verify.test.js +165 -0
  118. package/dist/server/auth/verify.test.js.map +1 -0
  119. package/dist/server/auth-extra.test-d.js +130 -0
  120. package/dist/server/auth-extra.test-d.js.map +1 -0
  121. package/dist/server/auth.d.ts +43 -6
  122. package/dist/server/auth.js +4 -5
  123. package/dist/server/auth.js.map +1 -1
  124. package/dist/server/build-manifest.test.d.ts +1 -0
  125. package/dist/server/build-manifest.test.js +28 -0
  126. package/dist/server/build-manifest.test.js.map +1 -0
  127. package/dist/server/content-helpers.d.ts +1 -1
  128. package/dist/server/content-helpers.js.map +1 -1
  129. package/dist/server/express.d.ts +23 -3
  130. package/dist/server/express.js +38 -32
  131. package/dist/server/express.js.map +1 -1
  132. package/dist/server/express.test.js +268 -90
  133. package/dist/server/express.test.js.map +1 -1
  134. package/dist/server/file-ref.d.ts +1 -1
  135. package/dist/server/file-ref.js +1 -1
  136. package/dist/server/file-ref.js.map +1 -1
  137. package/dist/server/host.d.ts +2 -0
  138. package/dist/server/host.js +11 -0
  139. package/dist/server/host.js.map +1 -0
  140. package/dist/server/host.test.d.ts +1 -0
  141. package/dist/server/host.test.js +13 -0
  142. package/dist/server/host.test.js.map +1 -0
  143. package/dist/server/index.d.ts +17 -3
  144. package/dist/server/index.js +14 -2
  145. package/dist/server/index.js.map +1 -1
  146. package/dist/server/mcp-errors.test.d.ts +1 -0
  147. package/dist/server/mcp-errors.test.js +41 -0
  148. package/dist/server/mcp-errors.test.js.map +1 -0
  149. package/dist/server/middleware.d.ts +35 -10
  150. package/dist/server/middleware.js +33 -0
  151. package/dist/server/middleware.js.map +1 -1
  152. package/dist/server/middleware.test-d.js +1 -1
  153. package/dist/server/middleware.test-d.js.map +1 -1
  154. package/dist/server/middleware.test.js +242 -134
  155. package/dist/server/middleware.test.js.map +1 -1
  156. package/dist/server/register-tool.test.d.ts +1 -0
  157. package/dist/server/register-tool.test.js +27 -0
  158. package/dist/server/register-tool.test.js.map +1 -0
  159. package/dist/server/requestOrigin.d.ts +7 -0
  160. package/dist/server/requestOrigin.js +25 -0
  161. package/dist/server/requestOrigin.js.map +1 -0
  162. package/dist/server/server.d.ts +144 -122
  163. package/dist/server/server.js +313 -328
  164. package/dist/server/server.js.map +1 -1
  165. package/dist/server/skills-integration.test.d.ts +1 -0
  166. package/dist/server/skills-integration.test.js +86 -0
  167. package/dist/server/skills-integration.test.js.map +1 -0
  168. package/dist/server/skills.d.ts +27 -0
  169. package/dist/server/skills.js +188 -0
  170. package/dist/server/skills.js.map +1 -0
  171. package/dist/server/skills.test.d.ts +1 -0
  172. package/dist/server/skills.test.js +243 -0
  173. package/dist/server/skills.test.js.map +1 -0
  174. package/dist/server/templateHelper.d.ts +0 -3
  175. package/dist/server/templateHelper.js.map +1 -1
  176. package/dist/server/templates.generated.js +4 -8
  177. package/dist/server/templates.generated.js.map +1 -1
  178. package/dist/server/tool-extra.test.d.ts +1 -0
  179. package/dist/server/tool-extra.test.js +88 -0
  180. package/dist/server/tool-extra.test.js.map +1 -0
  181. package/dist/server/view-name.test-d.d.ts +1 -0
  182. package/dist/server/view-name.test-d.js +8 -0
  183. package/dist/server/view-name.test-d.js.map +1 -0
  184. package/dist/server/view-resource-resolution.test.d.ts +6 -0
  185. package/dist/server/view-resource-resolution.test.js +176 -0
  186. package/dist/server/view-resource-resolution.test.js.map +1 -0
  187. package/dist/server/viewsDevServer.js +4 -1
  188. package/dist/server/viewsDevServer.js.map +1 -1
  189. package/dist/test/utils.d.ts +9 -11
  190. package/dist/test/utils.js +220 -201
  191. package/dist/test/utils.js.map +1 -1
  192. package/dist/test/view.test.js +105 -133
  193. package/dist/test/view.test.js.map +1 -1
  194. package/dist/views/index.d.ts +10 -0
  195. package/dist/views/index.js +3 -0
  196. package/dist/views/index.js.map +1 -0
  197. package/dist/{web/plugin → views}/scan-views.js +1 -1
  198. package/dist/views/scan-views.js.map +1 -0
  199. package/dist/views/scan-views.test.d.ts +1 -0
  200. package/dist/views/scan-views.test.js.map +1 -0
  201. package/dist/views/validate-view.d.ts +1 -0
  202. package/dist/{web/plugin → views}/validate-view.js +2 -2
  203. package/dist/views/validate-view.js.map +1 -0
  204. package/dist/views/validate-view.test.d.ts +1 -0
  205. package/dist/views/validate-view.test.js.map +1 -0
  206. package/dist/web/bridges/adaptor.d.ts +9 -6
  207. package/dist/web/bridges/adaptor.js +93 -74
  208. package/dist/web/bridges/adaptor.js.map +1 -1
  209. package/dist/web/bridges/adaptor.test.js +41 -21
  210. package/dist/web/bridges/adaptor.test.js.map +1 -1
  211. package/dist/web/bridges/apps-sdk/bridge.d.ts +5 -1
  212. package/dist/web/bridges/apps-sdk/bridge.js +12 -0
  213. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  214. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
  215. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
  216. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  217. package/dist/web/bridges/get-adaptor.d.ts +0 -2
  218. package/dist/web/bridges/get-adaptor.js +1 -21
  219. package/dist/web/bridges/get-adaptor.js.map +1 -1
  220. package/dist/web/bridges/get-adaptor.test.js +5 -21
  221. package/dist/web/bridges/get-adaptor.test.js.map +1 -1
  222. package/dist/web/bridges/mcp-app/bridge.d.ts +14 -2
  223. package/dist/web/bridges/mcp-app/bridge.js +77 -4
  224. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  225. package/dist/web/bridges/mcp-app/bridge.test.js +2 -6
  226. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -1
  227. package/dist/web/bridges/mcp-app/types.d.ts +2 -0
  228. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  229. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
  230. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  231. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  232. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  233. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  234. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  235. package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
  236. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  237. package/dist/web/bridges/types.d.ts +45 -12
  238. package/dist/web/bridges/types.js.map +1 -1
  239. package/dist/web/components/modal-provider.d.ts +1 -1
  240. package/dist/web/create-store.test.js +6 -5
  241. package/dist/web/create-store.test.js.map +1 -1
  242. package/dist/web/data-llm.d.ts +1 -1
  243. package/dist/web/data-llm.test.js +15 -5
  244. package/dist/web/data-llm.test.js.map +1 -1
  245. package/dist/web/generate-helpers.d.ts +22 -18
  246. package/dist/web/generate-helpers.js +19 -15
  247. package/dist/web/generate-helpers.js.map +1 -1
  248. package/dist/web/generate-helpers.test-d.js +7 -5
  249. package/dist/web/generate-helpers.test-d.js.map +1 -1
  250. package/dist/web/generate-helpers.test.js +2 -2
  251. package/dist/web/generate-helpers.test.js.map +1 -1
  252. package/dist/web/hooks/index.d.ts +3 -1
  253. package/dist/web/hooks/index.js +3 -1
  254. package/dist/web/hooks/index.js.map +1 -1
  255. package/dist/web/hooks/test/utils.d.ts +2 -1
  256. package/dist/web/hooks/test/utils.js +1 -1
  257. package/dist/web/hooks/test/utils.js.map +1 -1
  258. package/dist/web/hooks/use-call-tool.test.js +8 -7
  259. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  260. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  261. package/dist/web/hooks/use-display-mode.js +1 -1
  262. package/dist/web/hooks/use-display-mode.js.map +1 -1
  263. package/dist/web/hooks/use-display-mode.test.js +5 -4
  264. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  265. package/dist/web/hooks/use-download.d.ts +1 -3
  266. package/dist/web/hooks/use-download.js +1 -2
  267. package/dist/web/hooks/use-download.js.map +1 -1
  268. package/dist/web/hooks/use-download.test.js +12 -12
  269. package/dist/web/hooks/use-download.test.js.map +1 -1
  270. package/dist/web/hooks/use-files.test.js +4 -4
  271. package/dist/web/hooks/use-files.test.js.map +1 -1
  272. package/dist/web/hooks/use-host.d.ts +22 -0
  273. package/dist/web/hooks/use-host.js +30 -0
  274. package/dist/web/hooks/use-host.js.map +1 -0
  275. package/dist/web/hooks/use-host.test.d.ts +1 -0
  276. package/dist/web/hooks/use-host.test.js +59 -0
  277. package/dist/web/hooks/use-host.test.js.map +1 -0
  278. package/dist/web/hooks/use-open-external.test.js +9 -13
  279. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  280. package/dist/web/hooks/use-register-view-tool.d.ts +37 -0
  281. package/dist/web/hooks/use-register-view-tool.js +50 -0
  282. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  283. package/dist/web/hooks/use-request-close.test.js +6 -5
  284. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  285. package/dist/web/hooks/use-request-modal.test.js +4 -4
  286. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  287. package/dist/web/hooks/use-request-size.d.ts +1 -1
  288. package/dist/web/hooks/use-request-size.js +1 -1
  289. package/dist/web/hooks/use-request-size.js.map +1 -1
  290. package/dist/web/hooks/use-request-size.test.js +4 -4
  291. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  292. package/dist/web/hooks/use-set-open-in-app-url.test.js +4 -10
  293. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  294. package/dist/web/hooks/use-tool-info.d.ts +18 -19
  295. package/dist/web/hooks/use-tool-info.js +4 -8
  296. package/dist/web/hooks/use-tool-info.js.map +1 -1
  297. package/dist/web/hooks/use-tool-info.test-d.js +11 -34
  298. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  299. package/dist/web/hooks/use-tool-info.test.js +9 -14
  300. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  301. package/dist/web/hooks/use-user.d.ts +3 -2
  302. package/dist/web/hooks/use-user.js +4 -3
  303. package/dist/web/hooks/use-user.js.map +1 -1
  304. package/dist/web/hooks/use-user.test.js +10 -8
  305. package/dist/web/hooks/use-user.test.js.map +1 -1
  306. package/dist/web/hooks/use-view-state.js +19 -9
  307. package/dist/web/hooks/use-view-state.js.map +1 -1
  308. package/dist/web/hooks/use-view-state.test.js +36 -5
  309. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  310. package/dist/web/hooks/use-viewport.d.ts +20 -0
  311. package/dist/web/hooks/use-viewport.js +21 -0
  312. package/dist/web/hooks/use-viewport.js.map +1 -0
  313. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  314. package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +17 -37
  315. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  316. package/dist/web/mount-view.d.ts +3 -2
  317. package/dist/web/mount-view.js +5 -8
  318. package/dist/web/mount-view.js.map +1 -1
  319. package/package.json +31 -26
  320. package/dist/cli/resolve-views-dir.d.ts +0 -1
  321. package/dist/cli/resolve-views-dir.js.map +0 -1
  322. package/dist/web/bridges/host-context-stores.d.ts +0 -27
  323. package/dist/web/bridges/host-context-stores.js +0 -73
  324. package/dist/web/bridges/host-context-stores.js.map +0 -1
  325. package/dist/web/hooks/use-layout.d.ts +0 -24
  326. package/dist/web/hooks/use-layout.js +0 -25
  327. package/dist/web/hooks/use-layout.js.map +0 -1
  328. package/dist/web/hooks/use-layout.test.js.map +0 -1
  329. package/dist/web/plugin/data-llm.test.js +0 -81
  330. package/dist/web/plugin/data-llm.test.js.map +0 -1
  331. package/dist/web/plugin/plugin.d.ts +0 -33
  332. package/dist/web/plugin/plugin.js +0 -189
  333. package/dist/web/plugin/plugin.js.map +0 -1
  334. package/dist/web/plugin/scan-views.js.map +0 -1
  335. package/dist/web/plugin/scan-views.test.js.map +0 -1
  336. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  337. package/dist/web/plugin/transform-data-llm.js +0 -96
  338. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  339. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  340. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  341. package/dist/web/plugin/validate-view.d.ts +0 -1
  342. package/dist/web/plugin/validate-view.js.map +0 -1
  343. package/dist/web/plugin/validate-view.test.js.map +0 -1
  344. /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  345. /package/dist/{web/plugin/data-llm.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  346. /package/dist/{web/plugin/scan-views.test.d.ts → context-warnings.test.d.ts} +0 -0
  347. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/app.test.d.ts} +0 -0
  348. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  349. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  350. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  351. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -0,0 +1,20 @@
1
+ import { type SafeArea } from "../bridges/index.js";
2
+ export type ViewportState = {
3
+ maxHeight: number | undefined;
4
+ safeArea: SafeArea;
5
+ };
6
+ /**
7
+ * Hook for accessing the live viewport geometry the host grants the view.
8
+ * These values change on resize, so consumers re-render with them by design.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { maxHeight, safeArea } = useViewport();
13
+ *
14
+ * // Respect safe area insets
15
+ * const paddingTop = safeArea.insets.top;
16
+ * ```
17
+ *
18
+ * @see https://docs.skybridge.tech/api-reference/use-viewport
19
+ */
20
+ export declare function useViewport(): ViewportState;
@@ -0,0 +1,21 @@
1
+ import { useHostContext } from "../bridges/index.js";
2
+ /**
3
+ * Hook for accessing the live viewport geometry the host grants the view.
4
+ * These values change on resize, so consumers re-render with them by design.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * const { maxHeight, safeArea } = useViewport();
9
+ *
10
+ * // Respect safe area insets
11
+ * const paddingTop = safeArea.insets.top;
12
+ * ```
13
+ *
14
+ * @see https://docs.skybridge.tech/api-reference/use-viewport
15
+ */
16
+ export function useViewport() {
17
+ const maxHeight = useHostContext("maxHeight");
18
+ const safeArea = useHostContext("safeArea");
19
+ return { maxHeight, safeArea };
20
+ }
21
+ //# sourceMappingURL=use-viewport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-viewport.js","sourceRoot":"","sources":["../../../src/web/hooks/use-viewport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOpE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import { type SafeArea, useHostContext } from \"../bridges/index.js\";\n\nexport type ViewportState = {\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing the live viewport geometry the host grants the view.\n * These values change on resize, so consumers re-render with them by design.\n *\n * @example\n * ```tsx\n * const { maxHeight, safeArea } = useViewport();\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-viewport\n */\nexport function useViewport(): ViewportState {\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { maxHeight, safeArea };\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,15 @@
1
1
  import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import { _resetAdaptor } from "../bridges/get-adaptor.js";
3
+ import { HostAdaptor } from "../bridges/adaptor.js";
4
4
  import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
5
5
  import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
6
- import { useLayout } from "./use-layout.js";
7
- describe("useLayout", () => {
6
+ import { useViewport } from "./use-viewport.js";
7
+ describe("useViewport", () => {
8
8
  describe("apps-sdk host type", () => {
9
9
  beforeEach(() => {
10
- _resetAdaptor();
10
+ HostAdaptor.resetInstance();
11
11
  McpAppBridge.resetInstance();
12
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
12
+ vi.stubGlobal("skybridge", {});
13
13
  vi.stubGlobal("openai", { view: { mode: "inline" } });
14
14
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
15
15
  });
@@ -17,47 +17,31 @@ describe("useLayout", () => {
17
17
  vi.unstubAllGlobals();
18
18
  vi.resetAllMocks();
19
19
  McpAppBridge.resetInstance();
20
- _resetAdaptor();
20
+ HostAdaptor.resetInstance();
21
21
  });
22
- it("should return theme, maxHeight, and safeArea from mcp host context", async () => {
22
+ it("should return maxHeight and safeArea from mcp host context", async () => {
23
23
  vi.stubGlobal("parent", {
24
24
  postMessage: getMcpAppHostPostMessageMock({
25
- theme: "light",
26
25
  containerDimensions: { maxHeight: 500, width: 400 },
27
26
  safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
28
27
  }),
29
28
  });
30
- const { result } = renderHook(() => useLayout());
29
+ const { result } = renderHook(() => useViewport());
31
30
  await waitFor(() => {
32
- expect(result.current.theme).toBe("light");
33
31
  expect(result.current.maxHeight).toBe(500);
34
32
  expect(result.current.safeArea).toEqual({
35
33
  insets: { top: 0, bottom: 0, left: 0, right: 0 },
36
34
  });
37
35
  });
38
36
  });
39
- it("should return dark theme when set to dark", async () => {
40
- vi.stubGlobal("parent", {
41
- postMessage: getMcpAppHostPostMessageMock({
42
- theme: "dark",
43
- containerDimensions: { maxHeight: 500, width: 400 },
44
- safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
45
- }),
46
- });
47
- const { result } = renderHook(() => useLayout());
48
- await waitFor(() => {
49
- expect(result.current.theme).toBe("dark");
50
- });
51
- });
52
37
  it("should return different maxHeight when set", async () => {
53
38
  vi.stubGlobal("parent", {
54
39
  postMessage: getMcpAppHostPostMessageMock({
55
- theme: "light",
56
40
  containerDimensions: { maxHeight: 800, width: 400 },
57
41
  safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
58
42
  }),
59
43
  });
60
- const { result } = renderHook(() => useLayout());
44
+ const { result } = renderHook(() => useViewport());
61
45
  await waitFor(() => {
62
46
  expect(result.current.maxHeight).toBe(800);
63
47
  });
@@ -65,12 +49,11 @@ describe("useLayout", () => {
65
49
  it("should return safeArea with insets when set", async () => {
66
50
  vi.stubGlobal("parent", {
67
51
  postMessage: getMcpAppHostPostMessageMock({
68
- theme: "light",
69
52
  containerDimensions: { maxHeight: 500, width: 400 },
70
53
  safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },
71
54
  }),
72
55
  });
73
- const { result } = renderHook(() => useLayout());
56
+ const { result } = renderHook(() => useViewport());
74
57
  await waitFor(() => {
75
58
  expect(result.current.safeArea.insets.top).toBe(44);
76
59
  expect(result.current.safeArea.insets.bottom).toBe(34);
@@ -79,9 +62,9 @@ describe("useLayout", () => {
79
62
  });
80
63
  describe("mcp-app host type", () => {
81
64
  beforeEach(() => {
82
- _resetAdaptor();
65
+ HostAdaptor.resetInstance();
83
66
  McpAppBridge.resetInstance();
84
- vi.stubGlobal("skybridge", { hostType: "mcp-app" });
67
+ vi.stubGlobal("skybridge", {});
85
68
  vi.stubGlobal("openai", undefined);
86
69
  vi.stubGlobal("ResizeObserver", MockResizeObserver);
87
70
  });
@@ -89,19 +72,17 @@ describe("useLayout", () => {
89
72
  vi.unstubAllGlobals();
90
73
  vi.resetAllMocks();
91
74
  McpAppBridge.resetInstance();
92
- _resetAdaptor();
75
+ HostAdaptor.resetInstance();
93
76
  });
94
- it("should return theme, maxHeight, and safeArea from mcp host context", async () => {
77
+ it("should return maxHeight and safeArea from mcp host context", async () => {
95
78
  vi.stubGlobal("parent", {
96
79
  postMessage: getMcpAppHostPostMessageMock({
97
- theme: "dark",
98
80
  containerDimensions: { maxHeight: 800, width: 400 },
99
81
  safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },
100
82
  }),
101
83
  });
102
- const { result } = renderHook(() => useLayout());
84
+ const { result } = renderHook(() => useViewport());
103
85
  await waitFor(() => {
104
- expect(result.current.theme).toBe("dark");
105
86
  expect(result.current.maxHeight).toBe(800);
106
87
  expect(result.current.safeArea).toEqual({
107
88
  insets: { top: 20, right: 0, bottom: 34, left: 0 },
@@ -111,12 +92,11 @@ describe("useLayout", () => {
111
92
  it("should maintain safeArea referential stability when data has not changed", async () => {
112
93
  vi.stubGlobal("parent", {
113
94
  postMessage: getMcpAppHostPostMessageMock({
114
- theme: "light",
115
95
  containerDimensions: { maxHeight: 500, width: 400 },
116
96
  safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },
117
97
  }),
118
98
  });
119
- const { result, rerender } = renderHook(() => useLayout());
99
+ const { result, rerender } = renderHook(() => useViewport());
120
100
  await waitFor(() => {
121
101
  expect(result.current.safeArea).toBeDefined();
122
102
  });
@@ -126,4 +106,4 @@ describe("useLayout", () => {
126
106
  });
127
107
  });
128
108
  });
129
- //# sourceMappingURL=use-layout.test.js.map
109
+ //# sourceMappingURL=use-viewport.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-viewport.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-viewport.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,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,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAE7D,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAEhD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useViewport } from \"./use-viewport.js\";\n\ndescribe(\"useViewport\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.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 McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return maxHeight and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(500);\n expect(result.current.safeArea).toEqual({\n insets: { top: 0, bottom: 0, left: 0, right: 0 },\n });\n });\n });\n\n it(\"should return different maxHeight when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n });\n });\n\n it(\"should return safeArea with insets when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.safeArea.insets.top).toBe(44);\n expect(result.current.safeArea.insets.bottom).toBe(34);\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return maxHeight and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n expect(result.current.safeArea).toEqual({\n insets: { top: 20, right: 0, bottom: 34, left: 0 },\n });\n });\n });\n\n it(\"should maintain safeArea referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result, rerender } = renderHook(() => useViewport());\n\n await waitFor(() => {\n expect(result.current.safeArea).toBeDefined();\n });\n\n const initialSafeArea = result.current.safeArea;\n\n rerender();\n\n expect(result.current.safeArea).toBe(initialSafeArea);\n });\n });\n});\n"]}
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Mount a view's root React component into `#root`. Each view file's entry
3
- * point should call this exactly once.
2
+ * Mount a view's root React component into `#root`. The Vite plugin
3
+ * auto-mounts every view, so apps normally never call this themselves —
4
+ * it is the entry point the generated view wrappers use.
4
5
  *
5
6
  * Wraps the component in `StrictMode`, applies host-specific providers
6
7
  * automatically (e.g. modal support for MCP Apps), and installs the dev-mode
@@ -4,8 +4,9 @@ import { createRoot } from "react-dom/client";
4
4
  import { installOpenAILoggingProxy } from "./proxy.js";
5
5
  let rootInstance = null;
6
6
  /**
7
- * Mount a view's root React component into `#root`. Each view file's entry
8
- * point should call this exactly once.
7
+ * Mount a view's root React component into `#root`. The Vite plugin
8
+ * auto-mounts every view, so apps normally never call this themselves —
9
+ * it is the entry point the generated view wrappers use.
9
10
  *
10
11
  * Wraps the component in `StrictMode`, applies host-specific providers
11
12
  * automatically (e.g. modal support for MCP Apps), and installs the dev-mode
@@ -33,13 +34,9 @@ export const mountView = (component) => {
33
34
  if (import.meta.env.DEV) {
34
35
  installOpenAILoggingProxy();
35
36
  }
36
- const hostType = window.skybridge?.hostType;
37
37
  (async () => {
38
- let app = component;
39
- if (hostType === "mcp-app") {
40
- const { ModalProvider } = await import("./components/modal-provider.js");
41
- app = createElement(ModalProvider, null, component);
42
- }
38
+ const { ModalProvider } = await import("./components/modal-provider.js");
39
+ const app = createElement(ModalProvider, null, component);
43
40
  rootInstance.render(createElement(StrictMode, null, app));
44
41
  })();
45
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mount-view.js","sourceRoot":"","sources":["../../src/web/mount-view.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAA0B,EAAE,EAAE;IACtD,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,yBAAyB,EAAE,CAAC;IAC9B,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC;IAE5C,CAAC,KAAK,IAAI,EAAE;QACV,IAAI,GAAG,GAAG,SAAS,CAAC;QACpB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;YACzE,GAAG,GAAG,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QACtD,CAAC;QACD,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,EAAE,CAAC;AACP,CAAC,CAAC","sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { createElement, StrictMode } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { installOpenAILoggingProxy } from \"./proxy.js\";\n\nlet rootInstance: Root | null = null;\n\n/**\n * Mount a view's root React component into `#root`. Each view file's entry\n * point should call this exactly once.\n *\n * Wraps the component in `StrictMode`, applies host-specific providers\n * automatically (e.g. modal support for MCP Apps), and installs the dev-mode\n * logging proxy for `window.openai` calls.\n *\n * @param component - Your root React element (already constructed, e.g. `<App />`).\n *\n * @example\n * ```tsx\n * // src/views/search.tsx\n * import { mountView } from \"skybridge/web\";\n * import { App } from \"./App\";\n *\n * mountView(<App />);\n * ```\n */\nexport const mountView = (component: React.ReactNode) => {\n const rootElement = document.getElementById(\"root\");\n if (!rootElement) {\n throw new Error(\"Root element not found\");\n }\n\n if (!rootInstance) {\n rootInstance = createRoot(rootElement);\n }\n\n if (import.meta.env.DEV) {\n installOpenAILoggingProxy();\n }\n\n const hostType = window.skybridge?.hostType;\n\n (async () => {\n let app = component;\n if (hostType === \"mcp-app\") {\n const { ModalProvider } = await import(\"./components/modal-provider.js\");\n app = createElement(ModalProvider, null, component);\n }\n rootInstance.render(createElement(StrictMode, null, app));\n })();\n};\n"]}
1
+ {"version":3,"file":"mount-view.js","sourceRoot":"","sources":["../../src/web/mount-view.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAA0B,EAAE,EAAE;IACtD,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,yBAAyB,EAAE,CAAC;IAC9B,CAAC;IAED,CAAC,KAAK,IAAI,EAAE;QACV,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;QACzE,MAAM,GAAG,GAAG,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAC1D,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,EAAE,CAAC;AACP,CAAC,CAAC","sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { createElement, StrictMode } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { installOpenAILoggingProxy } from \"./proxy.js\";\n\nlet rootInstance: Root | null = null;\n\n/**\n * Mount a view's root React component into `#root`. The Vite plugin\n * auto-mounts every view, so apps normally never call this themselves —\n * it is the entry point the generated view wrappers use.\n *\n * Wraps the component in `StrictMode`, applies host-specific providers\n * automatically (e.g. modal support for MCP Apps), and installs the dev-mode\n * logging proxy for `window.openai` calls.\n *\n * @param component - Your root React element (already constructed, e.g. `<App />`).\n *\n * @example\n * ```tsx\n * // src/views/search.tsx\n * import { mountView } from \"skybridge/web\";\n * import { App } from \"./App\";\n *\n * mountView(<App />);\n * ```\n */\nexport const mountView = (component: React.ReactNode) => {\n const rootElement = document.getElementById(\"root\");\n if (!rootElement) {\n throw new Error(\"Root element not found\");\n }\n\n if (!rootInstance) {\n rootInstance = createRoot(rootElement);\n }\n\n if (import.meta.env.DEV) {\n installOpenAILoggingProxy();\n }\n\n (async () => {\n const { ModalProvider } = await import(\"./components/modal-provider.js\");\n const app = createElement(ModalProvider, null, component);\n rootInstance.render(createElement(StrictMode, null, app));\n })();\n};\n"]}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "skybridge",
3
- "version": "0.0.0-dev.dc576c4",
3
+ "version": "0.0.0-dev.dc90b1c",
4
4
  "description": "Skybridge is a framework for building ChatGPT and MCP Apps",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/alpic-ai/skybridge.git"
8
8
  },
9
9
  "type": "module",
10
+ "sideEffects": false,
10
11
  "engines": {
11
- "node": ">=22.0.0"
12
+ "node": ">=22.23.1"
12
13
  },
13
14
  "files": [
14
15
  "dist",
@@ -26,9 +27,9 @@
26
27
  "types": "./dist/web/index.d.ts",
27
28
  "default": "./dist/web/index.js"
28
29
  },
29
- "./vite": {
30
- "types": "./dist/web/plugin/plugin.d.ts",
31
- "default": "./dist/web/plugin/plugin.js"
30
+ "./views": {
31
+ "types": "./dist/views/index.d.ts",
32
+ "default": "./dist/views/index.js"
32
33
  }
33
34
  },
34
35
  "keywords": [
@@ -40,51 +41,55 @@
40
41
  "author": "Frédéric Barthelet",
41
42
  "license": "ISC",
42
43
  "peerDependencies": {
43
- "@modelcontextprotocol/sdk": ">=1.27.0",
44
- "@skybridge/devtools": "^1.0.0",
44
+ "@skybridge/devtools": "^2.0.0",
45
45
  "nodemon": ">=3.0.0",
46
46
  "react": ">=18.0.0",
47
47
  "react-dom": ">=18.0.0",
48
- "vite": ">=7.3.1"
48
+ "vite": ">=7.3.1",
49
+ "zod": "^4.2.0"
49
50
  },
50
51
  "dependencies": {
51
- "@babel/core": "^7.29.0",
52
- "@modelcontextprotocol/ext-apps": "^1.3.2",
53
- "@oclif/core": "^4.10.3",
52
+ "@modelcontextprotocol/client": "^2.0.0",
53
+ "@modelcontextprotocol/core": "^2.0.0",
54
+ "@modelcontextprotocol/ext-apps": "^2.0.0",
55
+ "@modelcontextprotocol/express": "^2.0.0",
56
+ "@modelcontextprotocol/node": "^2.0.0",
57
+ "@modelcontextprotocol/server": "^2.0.0",
58
+ "@oclif/core": "^4.11.14",
54
59
  "ci-info": "^4.4.0",
55
60
  "cors": "^2.8.6",
56
61
  "cross-spawn": "^7.0.6",
57
62
  "dequal": "^2.0.3",
58
- "es-toolkit": "^1.45.1",
63
+ "esbuild": "^0.28.1",
59
64
  "express": "^5.2.1",
60
65
  "handlebars": "^4.7.9",
61
- "ink": "^7.0.0",
66
+ "ink": "^7.1.1",
67
+ "jose": "^6.2.3",
62
68
  "open": "^11.0.0",
63
- "posthog-node": "^5.28.9",
69
+ "posthog-node": "^5.45.2",
64
70
  "superjson": "^2.2.6",
65
- "zustand": "^5.0.12"
71
+ "yaml": "^2.9.0",
72
+ "zustand": "^5.0.14"
66
73
  },
67
74
  "devDependencies": {
68
- "@modelcontextprotocol/sdk": "^1.29.0",
69
75
  "@testing-library/dom": "^10.4.1",
70
76
  "@testing-library/react": "^16.3.2",
71
77
  "@total-typescript/tsconfig": "^1.0.4",
72
- "@types/babel__core": "^7.20.5",
73
78
  "@types/cors": "^2.8.19",
74
79
  "@types/cross-spawn": "^6.0.6",
75
80
  "@types/express": "^5.0.6",
76
- "@types/jsdom": "^28.0.1",
77
- "@types/node": "^24.12.0",
78
- "@types/react": "^19.2.14",
81
+ "@types/jsdom": "^28.0.3",
82
+ "@types/node": "^24.13.3",
83
+ "@types/react": "^19.2.17",
79
84
  "@types/react-dom": "^19.2.3",
80
- "@vitest/ui": "^4.1.4",
81
- "jsdom": "^29.0.1",
85
+ "@vitest/ui": "^4.1.10",
86
+ "jsdom": "^29.1.1",
82
87
  "shx": "^0.4.0",
83
88
  "ts-node": "^10.9.2",
84
- "typescript": "^6.0.2",
85
- "vite": "^8.0.0",
86
- "vitest": "^4.1.4",
87
- "zod": "^4.3.6"
89
+ "typescript": "^6.0.3",
90
+ "vite": "^8.1.5",
91
+ "vitest": "^4.1.10",
92
+ "zod": "^4.4.3"
88
93
  },
89
94
  "bin": {
90
95
  "sb": "./bin/run.js",
@@ -1 +0,0 @@
1
- export declare function resolveViewsDir(root: string): Promise<string | undefined>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-views-dir.js","sourceRoot":"","sources":["../../src/cli/resolve-views-dir.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAY;IAEZ,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,MAAM,kBAAkB,CACrC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,EACxC,SAAS,EACT,IAAI,CACL,CAAC;IAEF,MAAM,iBAAiB,GAAG,CACxB,KAAc,EAC2C,EAAE,CAC3D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;IAE9C,MAAM,OAAO,GAA0D,EAAE,CAAC;IAC1E,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;aAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;AACpE,CAAC","sourcesContent":["export async function resolveViewsDir(\n root: string,\n): Promise<string | undefined> {\n const { loadConfigFromFile } = await import(\"vite\");\n const loaded = await loadConfigFromFile(\n { command: \"build\", mode: \"production\" },\n undefined,\n root,\n );\n\n const isPluginCandidate = (\n value: unknown,\n ): value is { name?: string; api?: { viewsDir?: string } } =>\n typeof value === \"object\" && value !== null;\n\n const plugins: Array<{ name?: string; api?: { viewsDir?: string } }> = [];\n const walk = (value: unknown) => {\n if (Array.isArray(value)) {\n value.forEach(walk);\n } else if (isPluginCandidate(value)) {\n plugins.push(value);\n }\n };\n walk(loaded?.config.plugins ?? []);\n return plugins.find((p) => p.name === \"skybridge\")?.api?.viewsDir;\n}\n"]}
@@ -1,27 +0,0 @@
1
- import type { McpAppBridge } from "./mcp-app/bridge.js";
2
- import type { HostContextStore } from "./types.js";
3
- /**
4
- * Build the host-context store map sourced from the MCP App bridge.
5
- * `display` and `viewState` are *not* included here; those are handled
6
- * by the adaptor itself because they have transport-specific overlays
7
- * and additional state (polyfill modal state, localStorage hydration).
8
- */
9
- export declare function buildMcpContextStores(bridge: McpAppBridge): {
10
- theme: HostContextStore<"theme">;
11
- locale: HostContextStore<"locale">;
12
- safeArea: HostContextStore<"safeArea">;
13
- displayMode: HostContextStore<"displayMode">;
14
- maxHeight: HostContextStore<"maxHeight">;
15
- userAgent: HostContextStore<"userAgent">;
16
- toolInput: HostContextStore<"toolInput">;
17
- toolOutput: HostContextStore<"toolOutput">;
18
- toolResponseMetadata: HostContextStore<"toolResponseMetadata">;
19
- };
20
- /**
21
- * Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).
22
- * Used by `HostAdaptor` only when `window.openai` is present.
23
- */
24
- export declare function buildAppsSdkOverlayStores(bridge: import("./apps-sdk/bridge.js").AppsSdkBridge): {
25
- display: HostContextStore<"display">;
26
- viewState: HostContextStore<"viewState">;
27
- };
@@ -1,73 +0,0 @@
1
- import { dequal } from "dequal/lite";
2
- /**
3
- * Build a memoized {@link HostContextStore} backed by one or more
4
- * `McpAppBridge` context keys. Recomputed values are deep-compared via
5
- * `dequal` so unchanged snapshots return the cached reference.
6
- */
7
- function createMcpStore(bridge, keys, computeSnapshot) {
8
- let cachedValue;
9
- return {
10
- subscribe: bridge.subscribe(keys),
11
- getSnapshot: () => {
12
- const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
13
- const newValue = computeSnapshot(context);
14
- if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
15
- return cachedValue;
16
- }
17
- cachedValue = newValue;
18
- return newValue;
19
- },
20
- };
21
- }
22
- /**
23
- * Build the host-context store map sourced from the MCP App bridge.
24
- * `display` and `viewState` are *not* included here; those are handled
25
- * by the adaptor itself because they have transport-specific overlays
26
- * and additional state (polyfill modal state, localStorage hydration).
27
- */
28
- export function buildMcpContextStores(bridge) {
29
- return {
30
- theme: createMcpStore(bridge, ["theme"], ({ theme }) => theme ?? "light"),
31
- locale: createMcpStore(bridge, ["locale"], ({ locale }) => locale ?? "en-US"),
32
- safeArea: createMcpStore(bridge, ["safeAreaInsets"], ({ safeAreaInsets }) => ({
33
- insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
34
- })),
35
- displayMode: createMcpStore(bridge, ["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
36
- maxHeight: createMcpStore(bridge, ["containerDimensions"], ({ containerDimensions }) => {
37
- if (containerDimensions && "maxHeight" in containerDimensions) {
38
- return containerDimensions.maxHeight;
39
- }
40
- return undefined;
41
- }),
42
- userAgent: createMcpStore(bridge, ["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
43
- device: {
44
- type: platform === "web" ? "desktop" : (platform ?? "unknown"),
45
- },
46
- capabilities: {
47
- hover: true,
48
- touch: true,
49
- ...deviceCapabilities,
50
- },
51
- })),
52
- toolInput: createMcpStore(bridge, ["toolInput"], ({ toolInput }) => toolInput ?? null),
53
- toolOutput: createMcpStore(bridge, ["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
54
- toolResponseMetadata: createMcpStore(bridge, ["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
55
- };
56
- }
57
- /**
58
- * Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).
59
- * Used by `HostAdaptor` only when `window.openai` is present.
60
- */
61
- export function buildAppsSdkOverlayStores(bridge) {
62
- return {
63
- display: {
64
- subscribe: bridge.subscribe("view"),
65
- getSnapshot: () => bridge.getSnapshot("view"),
66
- },
67
- viewState: {
68
- subscribe: bridge.subscribe("widgetState"),
69
- getSnapshot: () => bridge.getSnapshot("widgetState")?.modelContent ?? null,
70
- },
71
- };
72
- }
73
- //# sourceMappingURL=host-context-stores.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"host-context-stores.js","sourceRoot":"","sources":["../../../src/web/bridges/host-context-stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC;;;;GAIG;AACH,SAAS,cAAc,CACrB,MAAoB,EACpB,IAAU,EACV,eAAkD;IAElD,IAAI,WAA0B,CAAC;IAC/B,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QACjC,WAAW,EAAE,GAAG,EAAE;YAChB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CAAC;YACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;gBAC/D,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,WAAW,GAAG,QAAQ,CAAC;YACvB,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAoB;IAWxD,OAAO;QACL,KAAK,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,IAAI,OAAO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AC,EACb,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,IAAI,IAAI,CACrC;QACD,UAAU,EAAE,cAAc,CACxB,MAAM,EACN,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,iBAAiB,IAAI,IAAI,CAC1D;QACD,oBAAoB,EAAE,cAAc,CAClC,MAAM,EACN,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,KAAK,IAAI,IAAI,CAC9C;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAoD;IAKpD,OAAO;QACL,OAAO,EAAE;YACP,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YACnC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;SAC9C;QACD,SAAS,EAAE;YACT,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC;YAC1C,WAAW,EAAE,GAAG,EAAE,CAChB,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,IAAI,IAAI;SAC1D;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type { McpAppBridge } from \"./mcp-app/bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./mcp-app/types.js\";\nimport type { HostContextStore } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\n/**\n * Build a memoized {@link HostContextStore} backed by one or more\n * `McpAppBridge` context keys. Recomputed values are deep-compared via\n * `dequal` so unchanged snapshots return the cached reference.\n */\nfunction createMcpStore<const Keys extends readonly McpAppContextKey[], R>(\n bridge: McpAppBridge,\n keys: Keys,\n computeSnapshot: (context: PickContext<Keys>) => R,\n) {\n let cachedValue: R | undefined;\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n cachedValue = newValue;\n return newValue;\n },\n };\n}\n\n/**\n * Build the host-context store map sourced from the MCP App bridge.\n * `display` and `viewState` are *not* included here; those are handled\n * by the adaptor itself because they have transport-specific overlays\n * and additional state (polyfill modal state, localStorage hydration).\n */\nexport function buildMcpContextStores(bridge: McpAppBridge): {\n theme: HostContextStore<\"theme\">;\n locale: HostContextStore<\"locale\">;\n safeArea: HostContextStore<\"safeArea\">;\n displayMode: HostContextStore<\"displayMode\">;\n maxHeight: HostContextStore<\"maxHeight\">;\n userAgent: HostContextStore<\"userAgent\">;\n toolInput: HostContextStore<\"toolInput\">;\n toolOutput: HostContextStore<\"toolOutput\">;\n toolResponseMetadata: HostContextStore<\"toolResponseMetadata\">;\n} {\n return {\n theme: createMcpStore(bridge, [\"theme\"], ({ theme }) => theme ?? \"light\"),\n locale: createMcpStore(\n bridge,\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: createMcpStore(\n bridge,\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: createMcpStore(\n bridge,\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: createMcpStore(\n bridge,\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n return undefined;\n },\n ),\n userAgent: createMcpStore(\n bridge,\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: createMcpStore(\n bridge,\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: createMcpStore(\n bridge,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: createMcpStore(\n bridge,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n };\n}\n\n/**\n * Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).\n * Used by `HostAdaptor` only when `window.openai` is present.\n */\nexport function buildAppsSdkOverlayStores(\n bridge: import(\"./apps-sdk/bridge.js\").AppsSdkBridge,\n): {\n display: HostContextStore<\"display\">;\n viewState: HostContextStore<\"viewState\">;\n} {\n return {\n display: {\n subscribe: bridge.subscribe(\"view\"),\n getSnapshot: () => bridge.getSnapshot(\"view\"),\n },\n viewState: {\n subscribe: bridge.subscribe(\"widgetState\"),\n getSnapshot: () =>\n bridge.getSnapshot(\"widgetState\")?.modelContent ?? null,\n },\n };\n}\n"]}
@@ -1,24 +0,0 @@
1
- import { type SafeArea, type Theme } from "../bridges/index.js";
2
- export type LayoutState = {
3
- theme: Theme;
4
- maxHeight: number | undefined;
5
- safeArea: SafeArea;
6
- };
7
- /**
8
- * Hook for accessing layout and visual environment information.
9
- * These values may change on resize or theme toggle.
10
- *
11
- * @example
12
- * ```tsx
13
- * const { theme, maxHeight, safeArea } = useLayout();
14
- *
15
- * // Apply theme-aware styling
16
- * const backgroundColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
17
- *
18
- * // Respect safe area insets
19
- * const paddingTop = safeArea.insets.top;
20
- * ```
21
- *
22
- * @see https://docs.skybridge.tech/api-reference/use-layout
23
- */
24
- export declare function useLayout(): LayoutState;
@@ -1,25 +0,0 @@
1
- import { useHostContext } from "../bridges/index.js";
2
- /**
3
- * Hook for accessing layout and visual environment information.
4
- * These values may change on resize or theme toggle.
5
- *
6
- * @example
7
- * ```tsx
8
- * const { theme, maxHeight, safeArea } = useLayout();
9
- *
10
- * // Apply theme-aware styling
11
- * const backgroundColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
12
- *
13
- * // Respect safe area insets
14
- * const paddingTop = safeArea.insets.top;
15
- * ```
16
- *
17
- * @see https://docs.skybridge.tech/api-reference/use-layout
18
- */
19
- export function useLayout() {
20
- const theme = useHostContext("theme");
21
- const maxHeight = useHostContext("maxHeight");
22
- const safeArea = useHostContext("safeArea");
23
- return { theme, maxHeight, safeArea };
24
- }
25
- //# sourceMappingURL=use-layout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-layout.js","sourceRoot":"","sources":["../../../src/web/hooks/use-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQhF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { type SafeArea, type Theme, useHostContext } from \"../bridges/index.js\";\n\nexport type LayoutState = {\n theme: Theme;\n maxHeight: number | undefined;\n safeArea: SafeArea;\n};\n\n/**\n * Hook for accessing layout and visual environment information.\n * These values may change on resize or theme toggle.\n *\n * @example\n * ```tsx\n * const { theme, maxHeight, safeArea } = useLayout();\n *\n * // Apply theme-aware styling\n * const backgroundColor = theme === \"dark\" ? \"#1a1a1a\" : \"#ffffff\";\n *\n * // Respect safe area insets\n * const paddingTop = safeArea.insets.top;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-layout\n */\nexport function useLayout(): LayoutState {\n const theme = useHostContext(\"theme\");\n const maxHeight = useHostContext(\"maxHeight\");\n const safeArea = useHostContext(\"safeArea\");\n\n return { theme, maxHeight, safeArea };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-layout.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-layout.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,UAAU,CAAC,GAAG,EAAE;YACd,aAAa,EAAE,CAAC;YAChB,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;YACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;YACnB,YAAY,CAAC,aAAa,EAAE,CAAC;YAC7B,aAAa,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oEA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AAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC;YAE3D,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAEhD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { _resetAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useLayout } from \"./use-layout.js\";\n\ndescribe(\"useLayout\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n _resetAdaptor();\n McpAppBridge.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 McpAppBridge.resetInstance();\n _resetAdaptor();\n });\n\n it(\"should return theme, maxHeight, and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"light\");\n expect(result.current.maxHeight).toBe(500);\n expect(result.current.safeArea).toEqual({\n insets: { top: 0, bottom: 0, left: 0, right: 0 },\n });\n });\n });\n\n it(\"should return dark theme when set to dark\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"dark\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"dark\");\n });\n });\n\n it(\"should return different maxHeight when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n });\n });\n\n it(\"should return safeArea with insets when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.safeArea.insets.top).toBe(44);\n expect(result.current.safeArea.insets.bottom).toBe(34);\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n _resetAdaptor();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n _resetAdaptor();\n });\n\n it(\"should return theme, maxHeight, and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"dark\",\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"dark\");\n expect(result.current.maxHeight).toBe(800);\n expect(result.current.safeArea).toEqual({\n insets: { top: 20, right: 0, bottom: 34, left: 0 },\n });\n });\n });\n\n it(\"should maintain safeArea referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result, rerender } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.safeArea).toBeDefined();\n });\n\n const initialSafeArea = result.current.safeArea;\n\n rerender();\n\n expect(result.current.safeArea).toBe(initialSafeArea);\n });\n });\n});\n"]}