skybridge 0.0.0-dev.e508ce2 → 0.0.0-dev.e52a26e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/README.md +123 -116
  2. package/dist/cli/detect-port.js.map +1 -1
  3. package/dist/cli/header.js +1 -1
  4. package/dist/cli/header.js.map +1 -1
  5. package/dist/cli/resolve-views-dir.d.ts +1 -0
  6. package/dist/cli/resolve-views-dir.js +17 -0
  7. package/dist/cli/resolve-views-dir.js.map +1 -0
  8. package/dist/cli/run-command.js.map +1 -1
  9. package/dist/cli/telemetry.js.map +1 -1
  10. package/dist/cli/tunnel-control-server.d.ts +9 -0
  11. package/dist/cli/tunnel-control-server.js +31 -0
  12. package/dist/cli/tunnel-control-server.js.map +1 -0
  13. package/dist/cli/tunnel-control-server.test.js +39 -0
  14. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  15. package/dist/cli/tunnel-handler.d.ts +3 -0
  16. package/dist/cli/tunnel-handler.js +48 -0
  17. package/dist/cli/tunnel-handler.js.map +1 -0
  18. package/dist/cli/tunnel-handler.test.js +105 -0
  19. package/dist/cli/tunnel-handler.test.js.map +1 -0
  20. package/dist/cli/tunnel.d.ts +57 -0
  21. package/dist/cli/tunnel.js +154 -0
  22. package/dist/cli/tunnel.js.map +1 -0
  23. package/dist/cli/tunnel.test.js +190 -0
  24. package/dist/cli/tunnel.test.js.map +1 -0
  25. package/dist/cli/types.d.ts +5 -0
  26. package/dist/cli/types.js +2 -0
  27. package/dist/cli/types.js.map +1 -0
  28. package/dist/cli/use-execute-steps.js.map +1 -1
  29. package/dist/cli/use-messages.d.ts +3 -0
  30. package/dist/cli/use-messages.js +11 -0
  31. package/dist/cli/use-messages.js.map +1 -0
  32. package/dist/cli/use-nodemon.d.ts +2 -7
  33. package/dist/cli/use-nodemon.js +18 -21
  34. package/dist/cli/use-nodemon.js.map +1 -1
  35. package/dist/cli/use-open-browser.d.ts +1 -0
  36. package/dist/cli/use-open-browser.js +44 -0
  37. package/dist/cli/use-open-browser.js.map +1 -0
  38. package/dist/cli/use-tunnel.d.ts +14 -0
  39. package/dist/cli/use-tunnel.js +131 -0
  40. package/dist/cli/use-tunnel.js.map +1 -0
  41. package/dist/cli/use-typescript-check.d.ts +1 -0
  42. package/dist/cli/use-typescript-check.js +42 -7
  43. package/dist/cli/use-typescript-check.js.map +1 -1
  44. package/dist/commands/build.js +48 -7
  45. package/dist/commands/build.js.map +1 -1
  46. package/dist/commands/create.d.ts +9 -0
  47. package/dist/commands/create.js +30 -0
  48. package/dist/commands/create.js.map +1 -0
  49. package/dist/commands/dev.d.ts +3 -1
  50. package/dist/commands/dev.js +62 -8
  51. package/dist/commands/dev.js.map +1 -1
  52. package/dist/commands/start.js +7 -10
  53. package/dist/commands/start.js.map +1 -1
  54. package/dist/commands/telemetry/disable.js.map +1 -1
  55. package/dist/commands/telemetry/enable.js.map +1 -1
  56. package/dist/commands/telemetry/status.js.map +1 -1
  57. package/dist/server/asset-base-url-transform-plugin.d.ts +6 -6
  58. package/dist/server/asset-base-url-transform-plugin.js +25 -11
  59. package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
  60. package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
  61. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
  62. package/dist/server/auth.d.ts +20 -0
  63. package/dist/server/auth.js +28 -0
  64. package/dist/server/auth.js.map +1 -0
  65. package/dist/server/content-helpers.d.ts +67 -0
  66. package/dist/server/content-helpers.js +79 -0
  67. package/dist/server/content-helpers.js.map +1 -0
  68. package/dist/server/content-helpers.test.d.ts +1 -0
  69. package/dist/server/content-helpers.test.js +70 -0
  70. package/dist/server/content-helpers.test.js.map +1 -0
  71. package/dist/server/express.d.ts +7 -5
  72. package/dist/server/express.js +52 -23
  73. package/dist/server/express.js.map +1 -1
  74. package/dist/server/express.test.js +381 -25
  75. package/dist/server/express.test.js.map +1 -1
  76. package/dist/server/file-ref.d.ts +28 -0
  77. package/dist/server/file-ref.js +27 -0
  78. package/dist/server/file-ref.js.map +1 -0
  79. package/dist/server/index.d.ts +7 -4
  80. package/dist/server/index.js +5 -2
  81. package/dist/server/index.js.map +1 -1
  82. package/dist/server/inferUtilityTypes.d.ts +6 -6
  83. package/dist/server/inferUtilityTypes.js.map +1 -1
  84. package/dist/server/metric.d.ts +14 -0
  85. package/dist/server/metric.js +62 -0
  86. package/dist/server/metric.js.map +1 -0
  87. package/dist/server/middleware.d.ts +47 -6
  88. package/dist/server/middleware.js.map +1 -1
  89. package/dist/server/middleware.test-d.js +41 -18
  90. package/dist/server/middleware.test-d.js.map +1 -1
  91. package/dist/server/middleware.test.js +115 -5
  92. package/dist/server/middleware.test.js.map +1 -1
  93. package/dist/server/server.d.ts +334 -75
  94. package/dist/server/server.js +419 -117
  95. package/dist/server/server.js.map +1 -1
  96. package/dist/server/templateHelper.d.ts +5 -8
  97. package/dist/server/templateHelper.js +3 -22
  98. package/dist/server/templateHelper.js.map +1 -1
  99. package/dist/server/templates.generated.d.ts +4 -0
  100. package/dist/server/templates.generated.js +47 -0
  101. package/dist/server/templates.generated.js.map +1 -0
  102. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  103. package/dist/server/tunnel-proxy-router.js +110 -0
  104. package/dist/server/tunnel-proxy-router.js.map +1 -0
  105. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  106. package/dist/server/tunnel-proxy-router.test.js +229 -0
  107. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  108. package/dist/server/viewsDevServer.d.ts +14 -0
  109. package/dist/server/viewsDevServer.js +45 -0
  110. package/dist/server/viewsDevServer.js.map +1 -0
  111. package/dist/test/utils.d.ts +13 -21
  112. package/dist/test/utils.js +42 -37
  113. package/dist/test/utils.js.map +1 -1
  114. package/dist/test/view.test.d.ts +1 -0
  115. package/dist/test/view.test.js +568 -0
  116. package/dist/test/view.test.js.map +1 -0
  117. package/dist/version.d.ts +1 -0
  118. package/dist/version.js +3 -0
  119. package/dist/version.js.map +1 -0
  120. package/dist/web/bridges/adaptor.d.ts +50 -0
  121. package/dist/web/bridges/adaptor.js +314 -0
  122. package/dist/web/bridges/adaptor.js.map +1 -0
  123. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  124. package/dist/web/bridges/adaptor.test.js +205 -0
  125. package/dist/web/bridges/adaptor.test.js.map +1 -0
  126. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
  127. package/dist/web/bridges/apps-sdk/bridge.js +3 -3
  128. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  129. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  130. package/dist/web/bridges/apps-sdk/index.js +0 -1
  131. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  132. package/dist/web/bridges/apps-sdk/types.d.ts +18 -6
  133. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  134. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  135. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  136. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  137. package/dist/web/bridges/get-adaptor.d.ts +9 -0
  138. package/dist/web/bridges/get-adaptor.js +27 -5
  139. package/dist/web/bridges/get-adaptor.js.map +1 -1
  140. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  141. package/dist/web/bridges/get-adaptor.test.js +48 -0
  142. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  143. package/dist/web/bridges/host-context-stores.d.ts +27 -0
  144. package/dist/web/bridges/host-context-stores.js +73 -0
  145. package/dist/web/bridges/host-context-stores.js.map +1 -0
  146. package/dist/web/bridges/index.js.map +1 -1
  147. package/dist/web/bridges/mcp-app/bridge.d.ts +14 -30
  148. package/dist/web/bridges/mcp-app/bridge.js +43 -203
  149. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  150. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  151. package/dist/web/bridges/mcp-app/bridge.test.js +21 -0
  152. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  153. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  154. package/dist/web/bridges/mcp-app/index.js +0 -1
  155. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  156. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  157. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +17 -3
  158. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
  159. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  160. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -41
  161. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  162. package/dist/web/bridges/types.d.ts +95 -11
  163. package/dist/web/bridges/types.js +14 -1
  164. package/dist/web/bridges/types.js.map +1 -1
  165. package/dist/web/bridges/types.test.d.ts +1 -0
  166. package/dist/web/bridges/types.test.js +19 -0
  167. package/dist/web/bridges/types.test.js.map +1 -0
  168. package/dist/web/bridges/use-host-context.d.ts +5 -0
  169. package/dist/web/bridges/use-host-context.js +5 -0
  170. package/dist/web/bridges/use-host-context.js.map +1 -1
  171. package/dist/web/components/modal-provider.js +5 -6
  172. package/dist/web/components/modal-provider.js.map +1 -1
  173. package/dist/web/create-store.d.ts +26 -0
  174. package/dist/web/create-store.js +43 -3
  175. package/dist/web/create-store.js.map +1 -1
  176. package/dist/web/create-store.test.js +24 -22
  177. package/dist/web/create-store.test.js.map +1 -1
  178. package/dist/web/data-llm.d.ts +34 -1
  179. package/dist/web/data-llm.js +31 -3
  180. package/dist/web/data-llm.js.map +1 -1
  181. package/dist/web/data-llm.test.js +31 -27
  182. package/dist/web/data-llm.test.js.map +1 -1
  183. package/dist/web/generate-helpers.d.ts +22 -18
  184. package/dist/web/generate-helpers.js +22 -18
  185. package/dist/web/generate-helpers.js.map +1 -1
  186. package/dist/web/generate-helpers.test-d.js +26 -26
  187. package/dist/web/generate-helpers.test-d.js.map +1 -1
  188. package/dist/web/generate-helpers.test.js.map +1 -1
  189. package/dist/web/helpers/state.d.ts +2 -2
  190. package/dist/web/helpers/state.js +11 -11
  191. package/dist/web/helpers/state.js.map +1 -1
  192. package/dist/web/helpers/state.test.js +9 -9
  193. package/dist/web/helpers/state.test.js.map +1 -1
  194. package/dist/web/hooks/index.d.ts +4 -1
  195. package/dist/web/hooks/index.js +4 -1
  196. package/dist/web/hooks/index.js.map +1 -1
  197. package/dist/web/hooks/test/utils.d.ts +6 -2
  198. package/dist/web/hooks/test/utils.js +17 -2
  199. package/dist/web/hooks/test/utils.js.map +1 -1
  200. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  201. package/dist/web/hooks/use-call-tool.js +28 -0
  202. package/dist/web/hooks/use-call-tool.js.map +1 -1
  203. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  204. package/dist/web/hooks/use-call-tool.test.js +61 -27
  205. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  206. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  207. package/dist/web/hooks/use-display-mode.js +20 -0
  208. package/dist/web/hooks/use-display-mode.js.map +1 -1
  209. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -1
  210. package/dist/web/hooks/use-display-mode.test.js +55 -20
  211. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  212. package/dist/web/hooks/use-download.d.ts +5 -0
  213. package/dist/web/hooks/use-download.js +8 -0
  214. package/dist/web/hooks/use-download.js.map +1 -0
  215. package/dist/web/hooks/use-download.test.d.ts +1 -0
  216. package/dist/web/hooks/use-download.test.js +103 -0
  217. package/dist/web/hooks/use-download.test.js.map +1 -0
  218. package/dist/web/hooks/use-files.d.ts +34 -1
  219. package/dist/web/hooks/use-files.js +33 -0
  220. package/dist/web/hooks/use-files.js.map +1 -1
  221. package/dist/web/hooks/use-files.test.js +30 -2
  222. package/dist/web/hooks/use-files.test.js.map +1 -1
  223. package/dist/web/hooks/use-layout.d.ts +2 -0
  224. package/dist/web/hooks/use-layout.js +2 -0
  225. package/dist/web/hooks/use-layout.js.map +1 -1
  226. package/dist/web/hooks/use-layout.test.js +62 -29
  227. package/dist/web/hooks/use-layout.test.js.map +1 -1
  228. package/dist/web/hooks/use-open-external.d.ts +17 -0
  229. package/dist/web/hooks/use-open-external.js +16 -0
  230. package/dist/web/hooks/use-open-external.js.map +1 -1
  231. package/dist/web/hooks/use-open-external.test.js +34 -15
  232. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  233. package/dist/web/hooks/use-request-close.d.ts +16 -0
  234. package/dist/web/hooks/use-request-close.js +21 -0
  235. package/dist/web/hooks/use-request-close.js.map +1 -0
  236. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  237. package/dist/web/hooks/use-request-close.test.js +46 -0
  238. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  239. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  240. package/dist/web/hooks/use-request-modal.js +19 -4
  241. package/dist/web/hooks/use-request-modal.js.map +1 -1
  242. package/dist/web/hooks/use-request-modal.test.js +15 -1
  243. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  244. package/dist/web/hooks/use-request-size.d.ts +20 -0
  245. package/dist/web/hooks/use-request-size.js +24 -0
  246. package/dist/web/hooks/use-request-size.js.map +1 -0
  247. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  248. package/dist/web/hooks/use-request-size.test.js +47 -0
  249. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  250. package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
  251. package/dist/web/hooks/use-send-follow-up-message.js +19 -2
  252. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  253. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  254. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  255. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  256. package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
  257. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  258. package/dist/web/hooks/use-tool-info.d.ts +33 -0
  259. package/dist/web/hooks/use-tool-info.js +26 -0
  260. package/dist/web/hooks/use-tool-info.js.map +1 -1
  261. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  262. package/dist/web/hooks/use-tool-info.test.js +38 -28
  263. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  264. package/dist/web/hooks/use-user.d.ts +2 -0
  265. package/dist/web/hooks/use-user.js +20 -2
  266. package/dist/web/hooks/use-user.js.map +1 -1
  267. package/dist/web/hooks/use-user.test.js +101 -27
  268. package/dist/web/hooks/use-user.test.js.map +1 -1
  269. package/dist/web/hooks/use-view-state.d.ts +25 -0
  270. package/dist/web/hooks/use-view-state.js +32 -0
  271. package/dist/web/hooks/use-view-state.js.map +1 -0
  272. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  273. package/dist/web/hooks/use-view-state.test.js +181 -0
  274. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  275. package/dist/web/index.d.ts +1 -2
  276. package/dist/web/index.js +1 -2
  277. package/dist/web/index.js.map +1 -1
  278. package/dist/web/mount-view.d.ts +20 -0
  279. package/dist/web/{mount-widget.js → mount-view.js} +21 -2
  280. package/dist/web/mount-view.js.map +1 -0
  281. package/dist/web/plugin/data-llm.test.js.map +1 -1
  282. package/dist/web/plugin/plugin.d.ts +32 -1
  283. package/dist/web/plugin/plugin.js +160 -25
  284. package/dist/web/plugin/plugin.js.map +1 -1
  285. package/dist/web/plugin/scan-views.d.ts +16 -0
  286. package/dist/web/plugin/scan-views.js +88 -0
  287. package/dist/web/plugin/scan-views.js.map +1 -0
  288. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  289. package/dist/web/plugin/scan-views.test.js +99 -0
  290. package/dist/web/plugin/scan-views.test.js.map +1 -0
  291. package/dist/web/plugin/transform-data-llm.js +1 -1
  292. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  293. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  294. package/dist/web/plugin/validate-view.d.ts +1 -0
  295. package/dist/web/plugin/validate-view.js +9 -0
  296. package/dist/web/plugin/validate-view.js.map +1 -0
  297. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  298. package/dist/web/plugin/validate-view.test.js +24 -0
  299. package/dist/web/plugin/validate-view.test.js.map +1 -0
  300. package/dist/web/proxy.js.map +1 -1
  301. package/dist/web/types.d.ts +4 -0
  302. package/dist/web/types.js.map +1 -1
  303. package/package.json +34 -20
  304. package/tsconfig.base.json +5 -0
  305. package/dist/server/const.d.ts +0 -1
  306. package/dist/server/const.js +0 -2
  307. package/dist/server/const.js.map +0 -1
  308. package/dist/server/templates/development.hbs +0 -67
  309. package/dist/server/templates/production.hbs +0 -6
  310. package/dist/server/widgetsDevServer.d.ts +0 -12
  311. package/dist/server/widgetsDevServer.js +0 -63
  312. package/dist/server/widgetsDevServer.js.map +0 -1
  313. package/dist/test/widget.test.js +0 -261
  314. package/dist/test/widget.test.js.map +0 -1
  315. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -22
  316. package/dist/web/bridges/apps-sdk/adaptor.js +0 -75
  317. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  318. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -36
  319. package/dist/web/bridges/mcp-app/adaptor.js +0 -190
  320. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  321. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  322. package/dist/web/hooks/use-widget-state.js +0 -32
  323. package/dist/web/hooks/use-widget-state.js.map +0 -1
  324. package/dist/web/hooks/use-widget-state.test.js +0 -64
  325. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  326. package/dist/web/mount-widget.d.ts +0 -1
  327. package/dist/web/mount-widget.js.map +0 -1
  328. package/dist/web/plugin/validate-widget.d.ts +0 -5
  329. package/dist/web/plugin/validate-widget.js +0 -27
  330. package/dist/web/plugin/validate-widget.js.map +0 -1
  331. package/dist/web/plugin/validate-widget.test.js +0 -42
  332. package/dist/web/plugin/validate-widget.test.js.map +0 -1
  333. /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  334. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
  335. /package/dist/{web/plugin/validate-widget.test.d.ts → cli/tunnel.test.d.ts} +0 -0
@@ -0,0 +1,73 @@
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
@@ -0,0 +1 @@
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,GAA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AAC,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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export * from \"./apps-sdk/index.js\";\nexport { getAdaptor } from \"./get-adaptor.js\";\nexport * from \"./mcp-app/index.js\";\nexport * from \"./types.js\";\nexport { useHostContext } from \"./use-host-context.js\";\n"]}
@@ -1,43 +1,27 @@
1
- import type { McpUiHostContext, McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
1
+ import { App } from "@modelcontextprotocol/ext-apps";
2
+ import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
2
3
  import type { Bridge, Subscribe } from "../types.js";
3
4
  import type { McpAppContext, McpAppContextKey } from "./types.js";
4
- type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
5
- export declare class McpAppBridge implements Bridge<McpUiHostContext> {
5
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
6
+ export declare class McpAppBridge implements Bridge<McpAppContext> {
6
7
  private static instance;
7
8
  context: McpAppContext;
8
9
  private listeners;
9
- private pendingRequests;
10
- private nextId;
11
- private initialized;
12
- private appInitializationOptions;
13
- private requestTimeout;
14
- private cleanupSizeObserver;
15
- constructor(options: McpAppInitializationOptions, requestTimeout?: number);
16
- static getInstance(options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridge;
10
+ private app;
11
+ private connectPromise;
12
+ constructor(options: {
13
+ appInfo: Implementation;
14
+ });
15
+ private connect;
16
+ getApp(): Promise<App>;
17
+ static getInstance(options?: Partial<{
18
+ appInfo: Implementation;
19
+ }>): McpAppBridge;
17
20
  subscribe(key: McpAppContextKey): Subscribe;
18
21
  subscribe(keys: readonly McpAppContextKey[]): Subscribe;
19
22
  getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
20
23
  cleanup: () => void;
21
24
  static resetInstance(): void;
22
- request<R extends {
23
- method: string;
24
- params?: unknown;
25
- }, T>({ method, params, }: R): Promise<T>;
26
25
  private emit;
27
26
  private updateContext;
28
- private init;
29
- private handleMessage;
30
- private handleResponse;
31
- private handleNotification;
32
- private handleRequest;
33
- private connect;
34
- private notify;
35
- private sendSizeChanged;
36
- /**
37
- * Set up automatic size change notifications using ResizeObserver.
38
- * Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
39
- * @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
40
- */
41
- private setupSizeChangedNotifications;
42
27
  }
43
- export {};
@@ -1,12 +1,5 @@
1
- const LATEST_PROTOCOL_VERSION = "2025-11-21";
2
- var JsonRpcErrorCode;
3
- (function (JsonRpcErrorCode) {
4
- JsonRpcErrorCode[JsonRpcErrorCode["ParseError"] = -32700] = "ParseError";
5
- JsonRpcErrorCode[JsonRpcErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
6
- JsonRpcErrorCode[JsonRpcErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
7
- JsonRpcErrorCode[JsonRpcErrorCode["InvalidParams"] = -32602] = "InvalidParams";
8
- JsonRpcErrorCode[JsonRpcErrorCode["InternalError"] = -32603] = "InternalError";
9
- })(JsonRpcErrorCode || (JsonRpcErrorCode = {}));
1
+ import { App } from "@modelcontextprotocol/ext-apps";
2
+ /** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
10
3
  export class McpAppBridge {
11
4
  static instance = null;
12
5
  context = {
@@ -15,34 +8,55 @@ export class McpAppBridge {
15
8
  toolResult: null,
16
9
  };
17
10
  listeners = new Map();
18
- pendingRequests = new Map();
19
- nextId = 1;
20
- initialized;
21
- appInitializationOptions;
22
- requestTimeout;
23
- cleanupSizeObserver = null;
24
- constructor(options, requestTimeout = 10_000) {
25
- this.requestTimeout = requestTimeout;
26
- this.initialized = false;
27
- this.appInitializationOptions = {
28
- appInfo: options.appInfo,
29
- appCapabilities: {},
30
- protocolVersion: LATEST_PROTOCOL_VERSION,
11
+ app;
12
+ connectPromise;
13
+ constructor(options) {
14
+ this.app = new App(options.appInfo);
15
+ this.app.ontoolinput = (params) => {
16
+ this.updateContext({ toolInput: params.arguments ?? {} });
31
17
  };
32
- this.init();
18
+ this.app.ontoolinputpartial = (params) => {
19
+ this.updateContext({ toolInput: params.arguments ?? {} });
20
+ };
21
+ this.app.ontoolresult = (params) => {
22
+ this.updateContext({ toolResult: params });
23
+ };
24
+ this.app.ontoolcancelled = (params) => {
25
+ this.updateContext({ toolCancelled: params });
26
+ };
27
+ this.app.onhostcontextchanged = (params) => {
28
+ this.updateContext(params);
29
+ };
30
+ this.connectPromise = this.connect();
33
31
  }
34
- static getInstance(options, requestTimeout) {
35
- if (window.skybridge.hostType !== "mcp-app") {
36
- throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
32
+ async connect() {
33
+ try {
34
+ await this.app.connect();
35
+ const hostContext = this.app.getHostContext();
36
+ if (hostContext) {
37
+ this.updateContext(hostContext);
38
+ }
39
+ }
40
+ catch (err) {
41
+ console.error(err);
37
42
  }
38
- if (McpAppBridge.instance && (options || requestTimeout)) {
39
- console.warn("McpAppBridge.getInstance: options and requestTimeout ignored, instance already exists");
43
+ }
44
+ async getApp() {
45
+ await this.connectPromise;
46
+ return this.app;
47
+ }
48
+ static getInstance(options) {
49
+ if (McpAppBridge.instance && options) {
50
+ console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
40
51
  }
41
52
  if (!McpAppBridge.instance) {
42
53
  const defaultOptions = {
43
54
  appInfo: { name: "skybridge-app", version: "0.0.1" },
44
55
  };
45
- McpAppBridge.instance = new McpAppBridge({ ...defaultOptions, ...options }, requestTimeout);
56
+ McpAppBridge.instance = new McpAppBridge({
57
+ ...defaultOptions,
58
+ ...options,
59
+ });
46
60
  }
47
61
  return McpAppBridge.instance;
48
62
  }
@@ -63,14 +77,7 @@ export class McpAppBridge {
63
77
  return this.context[key];
64
78
  }
65
79
  cleanup = () => {
66
- window.removeEventListener("message", this.handleMessage);
67
- this.pendingRequests.forEach((request) => {
68
- clearTimeout(request.timeout);
69
- });
70
- this.pendingRequests.clear();
71
80
  this.listeners.clear();
72
- this.cleanupSizeObserver?.();
73
- this.cleanupSizeObserver = null;
74
81
  };
75
82
  static resetInstance() {
76
83
  if (McpAppBridge.instance) {
@@ -78,20 +85,6 @@ export class McpAppBridge {
78
85
  McpAppBridge.instance = null;
79
86
  }
80
87
  }
81
- request({ method, params, }) {
82
- const id = this.nextId++;
83
- const { promise, resolve, reject } = Promise.withResolvers();
84
- this.pendingRequests.set(id, {
85
- resolve: resolve,
86
- reject,
87
- timeout: setTimeout(() => {
88
- reject(new Error("Request timed out"));
89
- this.pendingRequests.delete(id);
90
- }, this.requestTimeout),
91
- });
92
- window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
93
- return promise;
94
- }
95
88
  emit(key) {
96
89
  this.listeners.get(key)?.forEach((listener) => {
97
90
  listener();
@@ -103,158 +96,5 @@ export class McpAppBridge {
103
96
  this.emit(key);
104
97
  }
105
98
  }
106
- init() {
107
- if (this.initialized) {
108
- return;
109
- }
110
- this.initialized = true;
111
- if (typeof window === "undefined" || window.parent === window) {
112
- return;
113
- }
114
- window.addEventListener("message", this.handleMessage);
115
- this.connect();
116
- }
117
- handleMessage = (event) => {
118
- const data = event.data;
119
- if (data.jsonrpc !== "2.0") {
120
- return;
121
- }
122
- if ("id" in data) {
123
- if ("method" in data) {
124
- this.handleRequest(data);
125
- return;
126
- }
127
- this.handleResponse(data);
128
- return;
129
- }
130
- this.handleNotification(data);
131
- };
132
- handleResponse(response) {
133
- const request = this.pendingRequests.get(response.id);
134
- if (request) {
135
- clearTimeout(request.timeout);
136
- this.pendingRequests.delete(response.id);
137
- if ("error" in response) {
138
- request.reject(new Error(response.error.message));
139
- return;
140
- }
141
- request.resolve(response.result);
142
- }
143
- }
144
- handleNotification = (notification) => {
145
- switch (notification.method) {
146
- case "ui/notifications/host-context-changed":
147
- this.updateContext(notification.params);
148
- return;
149
- case "ui/notifications/tool-input-partial":
150
- this.updateContext({
151
- toolInput: notification.params.arguments ?? {},
152
- });
153
- return;
154
- case "ui/notifications/tool-input":
155
- this.updateContext({
156
- toolInput: notification.params.arguments ?? {},
157
- });
158
- return;
159
- case "ui/notifications/tool-result":
160
- this.updateContext({
161
- toolResult: notification.params,
162
- });
163
- return;
164
- case "ui/notifications/tool-cancelled":
165
- this.updateContext({
166
- toolCancelled: notification.params,
167
- });
168
- return;
169
- }
170
- };
171
- handleRequest = (request) => {
172
- switch (request.method) {
173
- case "ui/resource-teardown":
174
- this.cleanup();
175
- window.parent.postMessage({
176
- jsonrpc: "2.0",
177
- id: request.id,
178
- result: {},
179
- }, "*");
180
- return;
181
- default:
182
- window.parent.postMessage({
183
- jsonrpc: "2.0",
184
- id: request.id,
185
- error: {
186
- code: JsonRpcErrorCode.MethodNotFound,
187
- message: "Unsupported Request",
188
- },
189
- }, "*");
190
- }
191
- };
192
- async connect() {
193
- try {
194
- const result = await this.request({
195
- method: "ui/initialize",
196
- params: this.appInitializationOptions,
197
- });
198
- this.updateContext(result.hostContext);
199
- this.notify({ method: "ui/notifications/initialized" });
200
- this.cleanupSizeObserver = this.setupSizeChangedNotifications();
201
- }
202
- catch (err) {
203
- console.error(err);
204
- }
205
- }
206
- notify(notification) {
207
- window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
208
- }
209
- sendSizeChanged(params) {
210
- this.notify({ method: "ui/notifications/size-changed", params });
211
- }
212
- /**
213
- * Set up automatic size change notifications using ResizeObserver.
214
- * Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
215
- * @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
216
- */
217
- setupSizeChangedNotifications() {
218
- let scheduled = false;
219
- let lastWidth = 0;
220
- let lastHeight = 0;
221
- const sendBodySizeChanged = () => {
222
- if (scheduled) {
223
- return;
224
- }
225
- scheduled = true;
226
- requestAnimationFrame(() => {
227
- scheduled = false;
228
- let width;
229
- let height;
230
- // In fullscreen mode, use viewport size since the widget should fill
231
- // the entire available space provided by the host.
232
- if (this.context.displayMode === "fullscreen") {
233
- width = window.innerWidth;
234
- height = window.innerHeight;
235
- }
236
- else {
237
- // Use scrollWidth/scrollHeight to measure actual rendered content size.
238
- // This works better than fit-content for viewport-based layouts (vw/vh)
239
- // and fluid elements like maps that want to fill available space.
240
- const body = document.body;
241
- width = Math.ceil(body.scrollWidth);
242
- height = Math.ceil(body.scrollHeight);
243
- }
244
- // Only send if size actually changed (prevents feedback loops from
245
- // style changes)
246
- if (width !== lastWidth || height !== lastHeight) {
247
- lastWidth = width;
248
- lastHeight = height;
249
- this.sendSizeChanged({ width, height });
250
- }
251
- });
252
- };
253
- sendBodySizeChanged();
254
- const resizeObserver = new ResizeObserver(sendBodySizeChanged);
255
- resizeObserver.observe(document.documentElement);
256
- resizeObserver.observe(document.body);
257
- return () => resizeObserver.disconnect();
258
- }
259
99
  }
260
100
  //# sourceMappingURL=bridge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AA4BA,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAE7C,IAAK,gBAMJ;AAND,WAAK,gBAAgB;IACnB,wEAAmB,CAAA;IACnB,g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Q,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { Bridge, Subscribe } from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo);\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { McpAppBridge } from "./bridge.js";
3
+ describe("McpAppBridge.getInstance", () => {
4
+ beforeEach(() => {
5
+ McpAppBridge.resetInstance();
6
+ vi.stubGlobal("parent", { postMessage: vi.fn() });
7
+ });
8
+ afterEach(() => {
9
+ vi.unstubAllGlobals();
10
+ McpAppBridge.resetInstance();
11
+ });
12
+ it("instantiates when hostType is apps-sdk", () => {
13
+ vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
14
+ expect(() => McpAppBridge.getInstance()).not.toThrow();
15
+ });
16
+ it("instantiates when hostType is mcp-app", () => {
17
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
18
+ expect(() => McpAppBridge.getInstance()).not.toThrow();
19
+ });
20
+ });
21
+ //# sourceMappingURL=bridge.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ndescribe(\"McpAppBridge.getInstance\", () => {\n beforeEach(() => {\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n McpAppBridge.resetInstance();\n });\n\n it(\"instantiates when hostType is apps-sdk\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n\n it(\"instantiates when hostType is mcp-app\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n});\n"]}
@@ -1,4 +1,3 @@
1
- export { McpAppAdaptor } from "./adaptor.js";
2
1
  export { McpAppBridge } from "./bridge.js";
3
2
  export type { McpAppContext, McpAppContextKey, McpToolState, } from "./types.js";
4
3
  export { useMcpAppContext } from "./use-mcp-app-context.js";
@@ -1,4 +1,3 @@
1
- export { McpAppAdaptor } from "./adaptor.js";
2
1
  export { McpAppBridge } from "./bridge.js";
3
2
  export { useMcpAppContext } from "./use-mcp-app-context.js";
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n McpUiHostContext,\n McpUiToolCancelledNotification,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\n\nexport type McpToolState = {\n toolInput: NonNullable<\n McpUiToolInputNotification[\"params\"][\"arguments\"]\n > | null;\n toolResult: McpUiToolResultNotification[\"params\"] | null;\n toolCancelled: McpUiToolCancelledNotification[\"params\"] | null;\n};\n\nexport type McpAppContext = McpUiHostContext & McpToolState;\n\nexport type McpAppContextKey = keyof McpAppContext;\n"]}
@@ -1,5 +1,19 @@
1
- import type { McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
1
+ import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
2
2
  import type { McpAppContext } from "./types.js";
3
- type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
4
- export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppContext[K];
3
+ type McpAppInitializationOptions = {
4
+ appInfo: Implementation;
5
+ };
6
+ /**
7
+ * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
8
+ *
9
+ * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
10
+ * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
11
+ * when you need protocol-level fields not surfaced by the public hooks.
12
+ *
13
+ * `options.appInfo` is honored only on the first call that creates the
14
+ * underlying bridge; subsequent calls reuse the singleton.
15
+ *
16
+ * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
17
+ */
18
+ export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
5
19
  export {};
@@ -1,7 +1,19 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { McpAppBridge } from "./bridge.js";
3
- export function useMcpAppContext(key, options, requestTimeout) {
4
- const bridge = McpAppBridge.getInstance(options, requestTimeout);
3
+ /**
4
+ * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
5
+ *
6
+ * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
7
+ * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
8
+ * when you need protocol-level fields not surfaced by the public hooks.
9
+ *
10
+ * `options.appInfo` is honored only on the first call that creates the
11
+ * underlying bridge; subsequent calls reuse the singleton.
12
+ *
13
+ * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
14
+ */
15
+ export function useMcpAppContext(key, options) {
16
+ const bridge = McpAppBridge.getInstance(options);
5
17
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
6
18
  }
7
19
  //# sourceMappingURL=use-mcp-app-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C,EAC9C,cAAuB;IAEvB,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACjE,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\n/**\n * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,\n * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this\n * when you need protocol-level fields not surfaced by the public hooks.\n *\n * `options.appInfo` is honored only on the first call that creates the\n * underlying bridge; subsequent calls reuse the singleton.\n *\n * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context\n */\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}