skybridge 0.0.0-dev.fd77b0f → 0.0.0-dev.fd947a0

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 (445) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -0
  3. package/bin/run.js +5 -0
  4. package/dist/cli/detect-port.d.ts +18 -0
  5. package/dist/cli/detect-port.js +61 -0
  6. package/dist/cli/detect-port.js.map +1 -0
  7. package/dist/cli/header.d.ts +4 -0
  8. package/dist/cli/header.js +6 -0
  9. package/dist/cli/header.js.map +1 -0
  10. package/dist/cli/run-command.d.ts +2 -0
  11. package/dist/cli/run-command.js +43 -0
  12. package/dist/cli/run-command.js.map +1 -0
  13. package/dist/cli/telemetry.d.ts +7 -0
  14. package/dist/cli/telemetry.js +123 -0
  15. package/dist/cli/telemetry.js.map +1 -0
  16. package/dist/cli/tunnel-control-server.d.ts +9 -0
  17. package/dist/cli/tunnel-control-server.js +31 -0
  18. package/dist/cli/tunnel-control-server.js.map +1 -0
  19. package/dist/cli/tunnel-control-server.test.js +39 -0
  20. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  21. package/dist/cli/tunnel-handler.d.ts +3 -0
  22. package/dist/cli/tunnel-handler.js +48 -0
  23. package/dist/cli/tunnel-handler.js.map +1 -0
  24. package/dist/cli/tunnel-handler.test.js +105 -0
  25. package/dist/cli/tunnel-handler.test.js.map +1 -0
  26. package/dist/cli/tunnel.d.ts +57 -0
  27. package/dist/cli/tunnel.js +154 -0
  28. package/dist/cli/tunnel.js.map +1 -0
  29. package/dist/cli/tunnel.test.js +190 -0
  30. package/dist/cli/tunnel.test.js.map +1 -0
  31. package/dist/cli/types.d.ts +5 -0
  32. package/dist/cli/types.js.map +1 -0
  33. package/dist/cli/use-execute-steps.d.ts +11 -0
  34. package/dist/cli/use-execute-steps.js +36 -0
  35. package/dist/cli/use-execute-steps.js.map +1 -0
  36. package/dist/cli/use-messages.d.ts +3 -0
  37. package/dist/cli/use-messages.js +11 -0
  38. package/dist/cli/use-messages.js.map +1 -0
  39. package/dist/cli/use-nodemon.d.ts +2 -0
  40. package/dist/cli/use-nodemon.js +73 -0
  41. package/dist/cli/use-nodemon.js.map +1 -0
  42. package/dist/cli/use-open-browser.d.ts +1 -0
  43. package/dist/cli/use-open-browser.js +44 -0
  44. package/dist/cli/use-open-browser.js.map +1 -0
  45. package/dist/cli/use-tunnel.d.ts +14 -0
  46. package/dist/cli/use-tunnel.js +131 -0
  47. package/dist/cli/use-tunnel.js.map +1 -0
  48. package/dist/cli/use-typescript-check.d.ts +9 -0
  49. package/dist/cli/use-typescript-check.js +94 -0
  50. package/dist/cli/use-typescript-check.js.map +1 -0
  51. package/dist/commands/build.d.ts +9 -0
  52. package/dist/commands/build.js +102 -0
  53. package/dist/commands/build.js.map +1 -0
  54. package/dist/commands/dev.d.ts +12 -0
  55. package/dist/commands/dev.js +80 -0
  56. package/dist/commands/dev.js.map +1 -0
  57. package/dist/commands/start.d.ts +9 -0
  58. package/dist/commands/start.js +49 -0
  59. package/dist/commands/start.js.map +1 -0
  60. package/dist/commands/telemetry/disable.d.ts +5 -0
  61. package/dist/commands/telemetry/disable.js +14 -0
  62. package/dist/commands/telemetry/disable.js.map +1 -0
  63. package/dist/commands/telemetry/enable.d.ts +5 -0
  64. package/dist/commands/telemetry/enable.js +14 -0
  65. package/dist/commands/telemetry/enable.js.map +1 -0
  66. package/dist/commands/telemetry/status.d.ts +5 -0
  67. package/dist/commands/telemetry/status.js +14 -0
  68. package/dist/commands/telemetry/status.js.map +1 -0
  69. package/dist/server/asset-base-url-transform-plugin.d.ts +10 -0
  70. package/dist/server/asset-base-url-transform-plugin.js +33 -0
  71. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  72. package/dist/server/asset-base-url-transform-plugin.test.js +84 -0
  73. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  74. package/dist/server/content-helpers.d.ts +27 -0
  75. package/dist/server/content-helpers.js +46 -0
  76. package/dist/server/content-helpers.js.map +1 -0
  77. package/dist/server/content-helpers.test.js +70 -0
  78. package/dist/server/content-helpers.test.js.map +1 -0
  79. package/dist/server/express.d.ts +11 -0
  80. package/dist/server/express.js +101 -0
  81. package/dist/server/express.js.map +1 -0
  82. package/dist/server/express.test.js +430 -0
  83. package/dist/server/express.test.js.map +1 -0
  84. package/dist/server/index.d.ts +6 -0
  85. package/dist/server/index.js +4 -0
  86. package/dist/server/index.js.map +1 -0
  87. package/dist/{src/server → server}/inferUtilityTypes.d.ts +6 -6
  88. package/dist/server/inferUtilityTypes.js.map +1 -0
  89. package/dist/server/metric.d.ts +14 -0
  90. package/dist/server/metric.js +62 -0
  91. package/dist/server/metric.js.map +1 -0
  92. package/dist/server/middleware.d.ts +124 -0
  93. package/dist/server/middleware.js +93 -0
  94. package/dist/server/middleware.js.map +1 -0
  95. package/dist/server/middleware.test-d.js +75 -0
  96. package/dist/server/middleware.test-d.js.map +1 -0
  97. package/dist/server/middleware.test.js +493 -0
  98. package/dist/server/middleware.test.js.map +1 -0
  99. package/dist/server/server.d.ts +196 -0
  100. package/dist/server/server.js +468 -0
  101. package/dist/server/server.js.map +1 -0
  102. package/dist/{src/server → server}/templateHelper.d.ts +5 -7
  103. package/dist/server/templateHelper.js +11 -0
  104. package/dist/server/templateHelper.js.map +1 -0
  105. package/dist/server/templates.generated.d.ts +4 -0
  106. package/dist/server/templates.generated.js +47 -0
  107. package/dist/server/templates.generated.js.map +1 -0
  108. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  109. package/dist/server/tunnel-proxy-router.js +110 -0
  110. package/dist/server/tunnel-proxy-router.js.map +1 -0
  111. package/dist/server/tunnel-proxy-router.test.js +229 -0
  112. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  113. package/dist/server/viewsDevServer.d.ts +14 -0
  114. package/dist/server/viewsDevServer.js +45 -0
  115. package/dist/server/viewsDevServer.js.map +1 -0
  116. package/dist/{src/test → test}/utils.d.ts +13 -21
  117. package/dist/{src/test → test}/utils.js +42 -37
  118. package/dist/test/utils.js.map +1 -0
  119. package/dist/test/view.test.js +523 -0
  120. package/dist/test/view.test.js.map +1 -0
  121. package/dist/version.d.ts +1 -0
  122. package/dist/version.js +3 -0
  123. package/dist/version.js.map +1 -0
  124. package/dist/web/bridges/apps-sdk/adaptor.d.ts +24 -0
  125. package/dist/web/bridges/apps-sdk/adaptor.js +96 -0
  126. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
  127. package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
  128. package/dist/{src/web/bridges/apps-sdk-bridge.js → web/bridges/apps-sdk/bridge.js} +2 -2
  129. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
  130. package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
  131. package/dist/web/bridges/apps-sdk/index.js +5 -0
  132. package/dist/web/bridges/apps-sdk/index.js.map +1 -0
  133. package/dist/web/bridges/apps-sdk/types.d.ts +131 -0
  134. package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
  135. package/dist/web/bridges/apps-sdk/types.js.map +1 -0
  136. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
  137. package/dist/{src/web/bridges/hooks/use-apps-sdk-bridge.js → web/bridges/apps-sdk/use-apps-sdk-context.js} +3 -3
  138. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
  139. package/dist/web/bridges/get-adaptor.d.ts +2 -0
  140. package/dist/web/bridges/get-adaptor.js +8 -0
  141. package/dist/web/bridges/get-adaptor.js.map +1 -0
  142. package/dist/web/bridges/index.d.ts +5 -0
  143. package/dist/web/bridges/index.js +6 -0
  144. package/dist/web/bridges/index.js.map +1 -0
  145. package/dist/web/bridges/mcp-app/adaptor.d.ts +48 -0
  146. package/dist/web/bridges/mcp-app/adaptor.js +263 -0
  147. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
  148. package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
  149. package/dist/web/bridges/mcp-app/bridge.js +102 -0
  150. package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
  151. package/dist/web/bridges/mcp-app/index.d.ts +4 -0
  152. package/dist/web/bridges/mcp-app/index.js +4 -0
  153. package/dist/web/bridges/mcp-app/index.js.map +1 -0
  154. package/dist/web/bridges/mcp-app/types.d.ts +8 -0
  155. package/dist/web/bridges/mcp-app/types.js +2 -0
  156. package/dist/web/bridges/mcp-app/types.js.map +1 -0
  157. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +7 -0
  158. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
  159. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
  160. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
  161. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
  162. package/dist/web/bridges/types.d.ts +111 -0
  163. package/dist/web/bridges/types.js +2 -0
  164. package/dist/web/bridges/types.js.map +1 -0
  165. package/dist/web/bridges/use-host-context.d.ts +2 -0
  166. package/dist/web/bridges/use-host-context.js +8 -0
  167. package/dist/web/bridges/use-host-context.js.map +1 -0
  168. package/dist/web/components/modal-provider.d.ts +4 -0
  169. package/dist/web/components/modal-provider.js +45 -0
  170. package/dist/web/components/modal-provider.js.map +1 -0
  171. package/dist/web/create-store.js +38 -0
  172. package/dist/web/create-store.js.map +1 -0
  173. package/dist/web/create-store.test.js +129 -0
  174. package/dist/web/create-store.test.js.map +1 -0
  175. package/dist/{src/web → web}/data-llm.d.ts +1 -1
  176. package/dist/{src/web → web}/data-llm.js +7 -5
  177. package/dist/web/data-llm.js.map +1 -0
  178. package/dist/web/data-llm.test.js +142 -0
  179. package/dist/web/data-llm.test.js.map +1 -0
  180. package/dist/{src/web → web}/generate-helpers.d.ts +22 -19
  181. package/dist/{src/web → web}/generate-helpers.js +20 -18
  182. package/dist/web/generate-helpers.js.map +1 -0
  183. package/dist/{src/web → web}/generate-helpers.test-d.js +26 -26
  184. package/dist/web/generate-helpers.test-d.js.map +1 -0
  185. package/dist/web/generate-helpers.test.js.map +1 -0
  186. package/dist/{src/web → web}/helpers/state.d.ts +2 -2
  187. package/dist/web/helpers/state.js +45 -0
  188. package/dist/web/helpers/state.js.map +1 -0
  189. package/dist/{src/web → web}/helpers/state.test.js +9 -9
  190. package/dist/web/helpers/state.test.js.map +1 -0
  191. package/dist/{src/web → web}/hooks/index.d.ts +3 -3
  192. package/dist/{src/web → web}/hooks/index.js +2 -2
  193. package/dist/web/hooks/index.js.map +1 -0
  194. package/dist/{src/web → web}/hooks/test/utils.d.ts +8 -2
  195. package/dist/web/hooks/test/utils.js +64 -0
  196. package/dist/web/hooks/test/utils.js.map +1 -0
  197. package/dist/{src/web → web}/hooks/use-call-tool.d.ts +2 -1
  198. package/dist/{src/web → web}/hooks/use-call-tool.js +2 -2
  199. package/dist/web/hooks/use-call-tool.js.map +1 -0
  200. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
  201. package/dist/{src/web → web}/hooks/use-call-tool.test.js +0 -5
  202. package/dist/web/hooks/use-call-tool.test.js.map +1 -0
  203. package/dist/web/hooks/use-display-mode.d.ts +4 -0
  204. package/dist/web/hooks/use-display-mode.js +9 -0
  205. package/dist/web/hooks/use-display-mode.js.map +1 -0
  206. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  207. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  208. package/dist/web/hooks/use-display-mode.test.js.map +1 -0
  209. package/dist/web/hooks/use-files.d.ts +7 -0
  210. package/dist/web/hooks/use-files.js +10 -0
  211. package/dist/web/hooks/use-files.js.map +1 -0
  212. package/dist/web/hooks/use-files.test.d.ts +1 -0
  213. package/dist/web/hooks/use-files.test.js +54 -0
  214. package/dist/web/hooks/use-files.test.js.map +1 -0
  215. package/dist/{src/web → web}/hooks/use-layout.d.ts +2 -2
  216. package/dist/{src/web → web}/hooks/use-layout.js +4 -4
  217. package/dist/web/hooks/use-layout.js.map +1 -0
  218. package/dist/web/hooks/use-layout.test.d.ts +1 -0
  219. package/dist/{src/web → web}/hooks/use-layout.test.js +7 -6
  220. package/dist/web/hooks/use-layout.test.js.map +1 -0
  221. package/dist/web/hooks/use-open-external.d.ts +3 -0
  222. package/dist/web/hooks/use-open-external.js +8 -0
  223. package/dist/web/hooks/use-open-external.js.map +1 -0
  224. package/dist/web/hooks/use-open-external.test.d.ts +1 -0
  225. package/dist/{src/web → web}/hooks/use-open-external.test.js +27 -12
  226. package/dist/web/hooks/use-open-external.test.js.map +1 -0
  227. package/dist/web/hooks/use-request-modal.d.ts +9 -0
  228. package/dist/web/hooks/use-request-modal.js +16 -0
  229. package/dist/web/hooks/use-request-modal.js.map +1 -0
  230. package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
  231. package/dist/{src/web → web}/hooks/use-request-modal.test.js +5 -1
  232. package/dist/web/hooks/use-request-modal.test.js.map +1 -0
  233. package/dist/web/hooks/use-send-follow-up-message.d.ts +2 -0
  234. package/dist/web/hooks/use-send-follow-up-message.js +8 -0
  235. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
  236. package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
  237. package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
  238. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  239. package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
  240. package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
  241. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  242. package/dist/{src/web → web}/hooks/use-tool-info.js +4 -4
  243. package/dist/web/hooks/use-tool-info.js.map +1 -0
  244. package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
  245. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
  246. package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
  247. package/dist/{src/web → web}/hooks/use-tool-info.test.js +5 -5
  248. package/dist/web/hooks/use-tool-info.test.js.map +1 -0
  249. package/dist/{src/web → web}/hooks/use-user.d.ts +1 -1
  250. package/dist/web/hooks/use-user.js +35 -0
  251. package/dist/web/hooks/use-user.js.map +1 -0
  252. package/dist/web/hooks/use-user.test.d.ts +1 -0
  253. package/dist/{src/web → web}/hooks/use-user.test.js +33 -4
  254. package/dist/web/hooks/use-user.test.js.map +1 -0
  255. package/dist/web/hooks/use-view-state.d.ts +4 -0
  256. package/dist/web/hooks/use-view-state.js +32 -0
  257. package/dist/web/hooks/use-view-state.js.map +1 -0
  258. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  259. package/dist/web/hooks/use-view-state.test.js +177 -0
  260. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  261. package/dist/{src/web → web}/index.d.ts +1 -2
  262. package/dist/{src/web → web}/index.js +1 -2
  263. package/dist/web/index.js.map +1 -0
  264. package/dist/web/mount-view.d.ts +1 -0
  265. package/dist/{src/web/mount-widget.js → web/mount-view.js} +11 -3
  266. package/dist/web/mount-view.js.map +1 -0
  267. package/dist/web/plugin/data-llm.test.d.ts +1 -0
  268. package/dist/web/plugin/data-llm.test.js.map +1 -0
  269. package/dist/web/plugin/plugin.d.ts +5 -0
  270. package/dist/web/plugin/plugin.js +156 -0
  271. package/dist/web/plugin/plugin.js.map +1 -0
  272. package/dist/web/plugin/scan-views.d.ts +16 -0
  273. package/dist/web/plugin/scan-views.js +88 -0
  274. package/dist/web/plugin/scan-views.js.map +1 -0
  275. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  276. package/dist/web/plugin/scan-views.test.js +99 -0
  277. package/dist/web/plugin/scan-views.test.js.map +1 -0
  278. package/dist/{src/web → web}/plugin/transform-data-llm.js +1 -1
  279. package/dist/web/plugin/transform-data-llm.js.map +1 -0
  280. package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
  281. package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
  282. package/dist/web/plugin/validate-view.d.ts +1 -0
  283. package/dist/web/plugin/validate-view.js +9 -0
  284. package/dist/web/plugin/validate-view.js.map +1 -0
  285. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  286. package/dist/web/plugin/validate-view.test.js +24 -0
  287. package/dist/web/plugin/validate-view.test.js.map +1 -0
  288. package/dist/{src/web → web}/proxy.js +0 -1
  289. package/dist/web/proxy.js.map +1 -0
  290. package/dist/web/types.d.ts +16 -0
  291. package/dist/web/types.js +2 -0
  292. package/dist/web/types.js.map +1 -0
  293. package/package.json +74 -39
  294. package/tsconfig.base.json +33 -0
  295. package/dist/src/server/devtoolsStaticServer.d.ts +0 -15
  296. package/dist/src/server/devtoolsStaticServer.js +0 -38
  297. package/dist/src/server/devtoolsStaticServer.js.map +0 -1
  298. package/dist/src/server/index.d.ts +0 -5
  299. package/dist/src/server/index.js +0 -4
  300. package/dist/src/server/index.js.map +0 -1
  301. package/dist/src/server/inferUtilityTypes.js.map +0 -1
  302. package/dist/src/server/server.d.ts +0 -74
  303. package/dist/src/server/server.js +0 -82
  304. package/dist/src/server/server.js.map +0 -1
  305. package/dist/src/server/templateHelper.js +0 -30
  306. package/dist/src/server/templateHelper.js.map +0 -1
  307. package/dist/src/server/templates/development.hbs +0 -13
  308. package/dist/src/server/templates/production.hbs +0 -7
  309. package/dist/src/server/widgetsDevServer.d.ts +0 -12
  310. package/dist/src/server/widgetsDevServer.js +0 -38
  311. package/dist/src/server/widgetsDevServer.js.map +0 -1
  312. package/dist/src/test/utils.js.map +0 -1
  313. package/dist/src/test/widget.test.js +0 -146
  314. package/dist/src/test/widget.test.js.map +0 -1
  315. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +0 -13
  316. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +0 -33
  317. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
  318. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +0 -16
  319. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +0 -115
  320. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
  321. package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -10
  322. package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
  323. package/dist/src/web/bridges/hooks/use-adaptor.d.ts +0 -2
  324. package/dist/src/web/bridges/hooks/use-adaptor.js +0 -8
  325. package/dist/src/web/bridges/hooks/use-adaptor.js.map +0 -1
  326. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
  327. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
  328. package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -2
  329. package/dist/src/web/bridges/hooks/use-bridge.js +0 -8
  330. package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
  331. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -5
  332. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
  333. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
  334. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -41
  335. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
  336. package/dist/src/web/bridges/index.d.ts +0 -4
  337. package/dist/src/web/bridges/index.js +0 -5
  338. package/dist/src/web/bridges/index.js.map +0 -1
  339. package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -38
  340. package/dist/src/web/bridges/mcp-app-bridge.js +0 -162
  341. package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
  342. package/dist/src/web/bridges/types.d.ts +0 -57
  343. package/dist/src/web/bridges/types.js.map +0 -1
  344. package/dist/src/web/create-store.js +0 -25
  345. package/dist/src/web/create-store.js.map +0 -1
  346. package/dist/src/web/create-store.test.js +0 -70
  347. package/dist/src/web/create-store.test.js.map +0 -1
  348. package/dist/src/web/data-llm.js.map +0 -1
  349. package/dist/src/web/data-llm.test.js +0 -76
  350. package/dist/src/web/data-llm.test.js.map +0 -1
  351. package/dist/src/web/generate-helpers.js.map +0 -1
  352. package/dist/src/web/generate-helpers.test-d.js.map +0 -1
  353. package/dist/src/web/generate-helpers.test.js.map +0 -1
  354. package/dist/src/web/helpers/state.js +0 -40
  355. package/dist/src/web/helpers/state.js.map +0 -1
  356. package/dist/src/web/helpers/state.test.js.map +0 -1
  357. package/dist/src/web/hooks/index.js.map +0 -1
  358. package/dist/src/web/hooks/test/utils.js +0 -40
  359. package/dist/src/web/hooks/test/utils.js.map +0 -1
  360. package/dist/src/web/hooks/use-call-tool.js.map +0 -1
  361. package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
  362. package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
  363. package/dist/src/web/hooks/use-display-mode.d.ts +0 -4
  364. package/dist/src/web/hooks/use-display-mode.js +0 -10
  365. package/dist/src/web/hooks/use-display-mode.js.map +0 -1
  366. package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
  367. package/dist/src/web/hooks/use-files.d.ts +0 -10
  368. package/dist/src/web/hooks/use-files.js +0 -7
  369. package/dist/src/web/hooks/use-files.js.map +0 -1
  370. package/dist/src/web/hooks/use-files.test.js +0 -29
  371. package/dist/src/web/hooks/use-files.test.js.map +0 -1
  372. package/dist/src/web/hooks/use-layout.js.map +0 -1
  373. package/dist/src/web/hooks/use-layout.test.js.map +0 -1
  374. package/dist/src/web/hooks/use-open-external.d.ts +0 -1
  375. package/dist/src/web/hooks/use-open-external.js +0 -8
  376. package/dist/src/web/hooks/use-open-external.js.map +0 -1
  377. package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
  378. package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
  379. package/dist/src/web/hooks/use-openai-global.js +0 -6
  380. package/dist/src/web/hooks/use-openai-global.js.map +0 -1
  381. package/dist/src/web/hooks/use-request-modal.d.ts +0 -9
  382. package/dist/src/web/hooks/use-request-modal.js +0 -14
  383. package/dist/src/web/hooks/use-request-modal.js.map +0 -1
  384. package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
  385. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +0 -1
  386. package/dist/src/web/hooks/use-send-follow-up-message.js +0 -8
  387. package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
  388. package/dist/src/web/hooks/use-tool-info.js.map +0 -1
  389. package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
  390. package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
  391. package/dist/src/web/hooks/use-user.js +0 -19
  392. package/dist/src/web/hooks/use-user.js.map +0 -1
  393. package/dist/src/web/hooks/use-user.test.js.map +0 -1
  394. package/dist/src/web/hooks/use-widget-state.d.ts +0 -4
  395. package/dist/src/web/hooks/use-widget-state.js +0 -32
  396. package/dist/src/web/hooks/use-widget-state.js.map +0 -1
  397. package/dist/src/web/hooks/use-widget-state.test.js +0 -61
  398. package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
  399. package/dist/src/web/index.js.map +0 -1
  400. package/dist/src/web/mount-widget.d.ts +0 -1
  401. package/dist/src/web/mount-widget.js.map +0 -1
  402. package/dist/src/web/plugin/data-llm.test.js.map +0 -1
  403. package/dist/src/web/plugin/plugin.d.ts +0 -2
  404. package/dist/src/web/plugin/plugin.js +0 -39
  405. package/dist/src/web/plugin/plugin.js.map +0 -1
  406. package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
  407. package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
  408. package/dist/src/web/proxy.js.map +0 -1
  409. package/dist/src/web/types.d.ts +0 -149
  410. package/dist/src/web/types.js.map +0 -1
  411. package/dist/vitest.config.d.ts +0 -2
  412. package/dist/vitest.config.js +0 -8
  413. package/dist/vitest.config.js.map +0 -1
  414. /package/dist/{src/test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  415. /package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
  416. /package/dist/{src/web/create-store.test.d.ts → cli/tunnel.test.d.ts} +0 -0
  417. /package/dist/{src/web/bridges → cli}/types.js +0 -0
  418. /package/dist/{src/web/data-llm.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
  419. /package/dist/{src/web/generate-helpers.test-d.d.ts → server/content-helpers.test.d.ts} +0 -0
  420. /package/dist/{src/web/generate-helpers.test.d.ts → server/express.test.d.ts} +0 -0
  421. /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
  422. /package/dist/{src/web/helpers/state.test.d.ts → server/middleware.test-d.d.ts} +0 -0
  423. /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/middleware.test.d.ts} +0 -0
  424. /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/tunnel-proxy-router.test.d.ts} +0 -0
  425. /package/dist/{src/web/hooks/use-display-mode.test.d.ts → test/view.test.d.ts} +0 -0
  426. /package/dist/{src/web/hooks/use-files.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
  427. /package/dist/{src/web → web}/create-store.d.ts +0 -0
  428. /package/dist/{src/web/hooks/use-layout.test.d.ts → web/create-store.test.d.ts} +0 -0
  429. /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
  430. /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
  431. /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
  432. /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
  433. /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/helpers/state.test.d.ts} +0 -0
  434. /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
  435. /package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +0 -0
  436. /package/dist/{src/web/hooks/use-user.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
  437. /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-display-mode.test-d.d.ts} +0 -0
  438. /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
  439. /package/dist/{src/web → web}/hooks/use-display-mode.test.js +0 -0
  440. /package/dist/{src/web → web}/hooks/use-tool-info.d.ts +0 -0
  441. /package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +0 -0
  442. /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
  443. /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
  444. /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
  445. /package/dist/{src/web → web}/proxy.d.ts +0 -0
@@ -0,0 +1,263 @@
1
+ import { dequal } from "dequal/lite";
2
+ import { McpAppBridge } from "./bridge.js";
3
+ const STORAGE_PREFIX = "sb:";
4
+ const MAX_STORAGE_ENTRIES = 200;
5
+ function findStorageKey(viewUUID) {
6
+ const suffix = `:${viewUUID}`;
7
+ for (let i = 0; i < localStorage.length; i++) {
8
+ const key = localStorage.key(i);
9
+ if (key?.startsWith(STORAGE_PREFIX) && key.endsWith(suffix)) {
10
+ return key;
11
+ }
12
+ }
13
+ return undefined;
14
+ }
15
+ export class McpAppAdaptor {
16
+ static instance = null;
17
+ stores;
18
+ _viewState = null;
19
+ viewStateListeners = new Set();
20
+ _viewUUID = null;
21
+ _displayState = {
22
+ mode: "inline",
23
+ };
24
+ displayListeners = new Set();
25
+ constructor() {
26
+ this.stores = this.initializeStores();
27
+ this.subscribeToViewUUID();
28
+ }
29
+ static getInstance() {
30
+ if (!McpAppAdaptor.instance) {
31
+ McpAppAdaptor.instance = new McpAppAdaptor();
32
+ }
33
+ return McpAppAdaptor.instance;
34
+ }
35
+ static resetInstance() {
36
+ McpAppAdaptor.instance = null;
37
+ }
38
+ getHostContextStore(key) {
39
+ return this.stores[key];
40
+ }
41
+ callTool = async (name, args) => {
42
+ const app = await McpAppBridge.getInstance().getApp();
43
+ const response = await app.callServerTool({
44
+ name,
45
+ arguments: args ?? undefined,
46
+ });
47
+ return {
48
+ content: response.content,
49
+ structuredContent: response.structuredContent ?? {},
50
+ isError: response.isError ?? false,
51
+ meta: response._meta ?? {},
52
+ };
53
+ };
54
+ requestDisplayMode = async (mode) => {
55
+ const app = await McpAppBridge.getInstance().getApp();
56
+ return app.requestDisplayMode({ mode });
57
+ };
58
+ sendFollowUpMessage = async (prompt, _options) => {
59
+ const app = await McpAppBridge.getInstance().getApp();
60
+ await app.sendMessage({
61
+ role: "user",
62
+ content: [
63
+ {
64
+ type: "text",
65
+ text: prompt,
66
+ },
67
+ ],
68
+ });
69
+ };
70
+ openExternal(href, options) {
71
+ if (options?.redirectUrl === false) {
72
+ console.warn("[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.");
73
+ }
74
+ McpAppBridge.getInstance()
75
+ .getApp()
76
+ .then((app) => app.openLink({ url: href }))
77
+ .catch((err) => {
78
+ console.error("Failed to open external link:", err);
79
+ });
80
+ }
81
+ initializeStores() {
82
+ return {
83
+ theme: this.createHostContextStore(["theme"], ({ theme }) => theme ?? "light"),
84
+ locale: this.createHostContextStore(["locale"], ({ locale }) => locale ?? "en-US"),
85
+ safeArea: this.createHostContextStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
86
+ insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
87
+ })),
88
+ displayMode: this.createHostContextStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
89
+ maxHeight: this.createHostContextStore(["containerDimensions"], ({ containerDimensions }) => {
90
+ if (containerDimensions && "maxHeight" in containerDimensions) {
91
+ return containerDimensions.maxHeight;
92
+ }
93
+ return undefined;
94
+ }),
95
+ userAgent: this.createHostContextStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
96
+ device: {
97
+ type: platform === "web" ? "desktop" : (platform ?? "unknown"),
98
+ },
99
+ capabilities: {
100
+ hover: true,
101
+ touch: true,
102
+ ...deviceCapabilities,
103
+ },
104
+ })),
105
+ toolInput: this.createHostContextStore(["toolInput"], ({ toolInput }) => toolInput ?? null),
106
+ toolOutput: this.createHostContextStore(["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
107
+ toolResponseMetadata: this.createHostContextStore(["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
108
+ display: {
109
+ subscribe: (onChange) => {
110
+ this.displayListeners.add(onChange);
111
+ return () => {
112
+ this.displayListeners.delete(onChange);
113
+ };
114
+ },
115
+ getSnapshot: () => this._displayState,
116
+ },
117
+ viewState: {
118
+ subscribe: (onChange) => {
119
+ this.viewStateListeners.add(onChange);
120
+ return () => {
121
+ this.viewStateListeners.delete(onChange);
122
+ };
123
+ },
124
+ getSnapshot: () => this._viewState,
125
+ },
126
+ };
127
+ }
128
+ setViewState = async (stateOrUpdater) => {
129
+ const newState = typeof stateOrUpdater === "function"
130
+ ? stateOrUpdater(this._viewState)
131
+ : stateOrUpdater;
132
+ // must happen before the async bridge call to ensure the state is updated immediately for the UI,
133
+ // otherwise successive calls to setViewState may have stale state
134
+ this._viewState = newState;
135
+ this.viewStateListeners.forEach((listener) => {
136
+ listener();
137
+ });
138
+ this.persistToLocalStorage(newState);
139
+ try {
140
+ const app = await McpAppBridge.getInstance().getApp();
141
+ await app.updateModelContext({
142
+ structuredContent: newState,
143
+ content: [{ type: "text", text: JSON.stringify(newState) }],
144
+ });
145
+ }
146
+ catch (error) {
147
+ console.error("Failed to update view state in MCP App.", error);
148
+ }
149
+ };
150
+ /**
151
+ * @throws File upload is not supported in MCP App.
152
+ */
153
+ uploadFile() {
154
+ throw new Error("File upload is not supported in MCP App.");
155
+ }
156
+ /**
157
+ * @throws File download is not supported in MCP App.
158
+ */
159
+ getFileDownloadUrl() {
160
+ throw new Error("File download is not supported in MCP App.");
161
+ }
162
+ /**
163
+ * @throws File selection is not supported in MCP App.
164
+ */
165
+ selectFiles() {
166
+ throw new Error("File selection is not supported in MCP App.");
167
+ }
168
+ openModal(options) {
169
+ this._displayState = { mode: "modal", params: options.params };
170
+ this.displayListeners.forEach((listener) => {
171
+ listener();
172
+ });
173
+ }
174
+ closeModal() {
175
+ this._displayState = { mode: "inline" };
176
+ this.displayListeners.forEach((listener) => {
177
+ listener();
178
+ });
179
+ }
180
+ setOpenInAppUrl(_href) {
181
+ throw new Error("setOpenInAppUrl is not implemented in MCP App.");
182
+ }
183
+ subscribeToViewUUID() {
184
+ const bridge = McpAppBridge.getInstance();
185
+ bridge.subscribe("toolResult")(() => {
186
+ const toolResult = bridge.getSnapshot("toolResult");
187
+ const viewUUID = toolResult?._meta?.viewUUID;
188
+ if (viewUUID && viewUUID !== this._viewUUID) {
189
+ this._viewUUID = viewUUID;
190
+ this.restoreFromLocalStorage(viewUUID);
191
+ }
192
+ });
193
+ }
194
+ // localStorage keys: sb:{unix_ms}:{viewUUID}
195
+ // Timestamp is updated on every write (LRU); eviction drops the least recently used entries.
196
+ restoreFromLocalStorage(viewUUID) {
197
+ try {
198
+ const existingKey = findStorageKey(viewUUID);
199
+ if (existingKey) {
200
+ const stored = localStorage.getItem(existingKey);
201
+ if (stored !== null) {
202
+ this._viewState = JSON.parse(stored);
203
+ this.viewStateListeners.forEach((listener) => {
204
+ listener();
205
+ });
206
+ }
207
+ }
208
+ }
209
+ catch (err) {
210
+ console.error(err);
211
+ }
212
+ }
213
+ persistToLocalStorage(state) {
214
+ if (!this._viewUUID || state === null) {
215
+ return;
216
+ }
217
+ try {
218
+ // Remove old key for this view, write with fresh timestamp (LRU)
219
+ const oldKey = findStorageKey(this._viewUUID);
220
+ if (oldKey) {
221
+ localStorage.removeItem(oldKey);
222
+ }
223
+ const newKey = `${STORAGE_PREFIX}${Date.now()}:${this._viewUUID}`;
224
+ localStorage.setItem(newKey, JSON.stringify(state));
225
+ // lru cleanup
226
+ const keys = [];
227
+ for (let i = 0; i < localStorage.length; i++) {
228
+ const key = localStorage.key(i);
229
+ if (key?.startsWith(STORAGE_PREFIX)) {
230
+ keys.push(key);
231
+ }
232
+ }
233
+ if (keys.length <= MAX_STORAGE_ENTRIES) {
234
+ return;
235
+ }
236
+ keys.sort();
237
+ const toRemove = keys.slice(0, keys.length - MAX_STORAGE_ENTRIES);
238
+ for (const key of toRemove) {
239
+ localStorage.removeItem(key);
240
+ }
241
+ }
242
+ catch (err) {
243
+ console.error(err);
244
+ }
245
+ }
246
+ createHostContextStore(keys, computeSnapshot) {
247
+ const bridge = McpAppBridge.getInstance();
248
+ let cachedValue;
249
+ return {
250
+ subscribe: bridge.subscribe(keys),
251
+ getSnapshot: () => {
252
+ const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
253
+ const newValue = computeSnapshot(context);
254
+ if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
255
+ return cachedValue;
256
+ }
257
+ cachedValue = newValue;
258
+ return newValue;
259
+ },
260
+ };
261
+ }
262
+ }
263
+ //# sourceMappingURL=adaptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAYrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,GAAG,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5D,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,OAAO,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OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAEO,sBAAsB,CAG5B,IAAU,EAAE,eAAkD;QAC9D,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,WAA0B,CAAC;QAE/B,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACjC,WAAW,EAAE,GAAG,EAAE;gBAChB,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;gBACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;gBAE1C,IAAI,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAC/D,OAAO,WAAW,CAAC;gBACrB,CAAC;gBAED,WAAW,GAAG,QAAQ,CAAC;gBACvB,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type {\n Adaptor,\n CallToolResponse,\n HostContext,\n HostContextStore,\n OpenExternalOptions,\n RequestDisplayMode,\n RequestModalOptions,\n SendFollowUpMessageOptions,\n SetViewStateAction,\n} from \"../types.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\nconst STORAGE_PREFIX = \"sb:\";\nconst MAX_STORAGE_ENTRIES = 200;\n\nfunction findStorageKey(viewUUID: string): string | undefined {\n const suffix = `:${viewUUID}`;\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX) && key.endsWith(suffix)) {\n return key;\n }\n }\n return undefined;\n}\n\nexport class McpAppAdaptor implements Adaptor {\n private static instance: McpAppAdaptor | null = null;\n private stores: {\n [K in keyof HostContext]: HostContextStore<K>;\n };\n private _viewState: HostContext[\"viewState\"] = null;\n private viewStateListeners = new Set<() => void>();\n private _viewUUID: string | null = null;\n\n private _displayState: HostContext[\"display\"] = {\n mode: \"inline\",\n };\n private displayListeners = new Set<() => void>();\n\n private constructor() {\n this.stores = this.initializeStores();\n this.subscribeToViewUUID();\n }\n\n public static getInstance(): McpAppAdaptor {\n if (!McpAppAdaptor.instance) {\n McpAppAdaptor.instance = new McpAppAdaptor();\n }\n return McpAppAdaptor.instance;\n }\n\n public static resetInstance(): void {\n McpAppAdaptor.instance = null;\n }\n\n public getHostContextStore<K extends keyof HostContext>(\n key: K,\n ): HostContextStore<K> {\n return this.stores[key];\n }\n\n public callTool = async <\n ToolArgs extends Record<string, unknown> | null = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(\n name: string,\n args: ToolArgs,\n ): Promise<ToolResponse> => {\n const app = await McpAppBridge.getInstance().getApp();\n const response = await app.callServerTool({\n name,\n arguments: args ?? undefined,\n });\n\n return {\n content: response.content,\n structuredContent: response.structuredContent ?? {},\n isError: response.isError ?? false,\n meta: response._meta ?? {},\n } as ToolResponse;\n };\n\n public requestDisplayMode = async (mode: RequestDisplayMode) => {\n const app = await McpAppBridge.getInstance().getApp();\n return app.requestDisplayMode({ mode });\n };\n\n public sendFollowUpMessage = async (\n prompt: string,\n _options?: SendFollowUpMessageOptions,\n ) => {\n const app = await McpAppBridge.getInstance().getApp();\n await app.sendMessage({\n role: \"user\",\n content: [\n {\n type: \"text\",\n text: prompt,\n },\n ],\n });\n };\n\n public openExternal(href: string, options?: OpenExternalOptions): void {\n if (options?.redirectUrl === false) {\n console.warn(\n \"[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.\",\n );\n }\n\n McpAppBridge.getInstance()\n .getApp()\n .then((app) => app.openLink({ url: href }))\n .catch((err) => {\n console.error(\"Failed to open external link:\", err);\n });\n }\n\n private initializeStores(): {\n [K in keyof HostContext]: HostContextStore<K>;\n } {\n return {\n theme: this.createHostContextStore(\n [\"theme\"],\n ({ theme }) => theme ?? \"light\",\n ),\n locale: this.createHostContextStore(\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: this.createHostContextStore(\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: this.createHostContextStore(\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: this.createHostContextStore(\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n\n return undefined;\n },\n ),\n userAgent: this.createHostContextStore(\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: this.createHostContextStore(\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: this.createHostContextStore(\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n display: {\n subscribe: (onChange: () => void) => {\n this.displayListeners.add(onChange);\n return () => {\n this.displayListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._displayState,\n },\n viewState: {\n subscribe: (onChange: () => void) => {\n this.viewStateListeners.add(onChange);\n return () => {\n this.viewStateListeners.delete(onChange);\n };\n },\n getSnapshot: () => this._viewState,\n },\n };\n }\n\n public setViewState = async (\n stateOrUpdater: SetViewStateAction,\n ): Promise<void> => {\n const newState =\n typeof stateOrUpdater === \"function\"\n ? stateOrUpdater(this._viewState)\n : stateOrUpdater;\n\n // must happen before the async bridge call to ensure the state is updated immediately for the UI,\n // otherwise successive calls to setViewState may have stale state\n this._viewState = newState;\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n\n this.persistToLocalStorage(newState);\n\n try {\n const app = await McpAppBridge.getInstance().getApp();\n await app.updateModelContext({\n structuredContent: newState,\n content: [{ type: \"text\", text: JSON.stringify(newState) }],\n });\n } catch (error) {\n console.error(\"Failed to update view state in MCP App.\", error);\n }\n };\n\n /**\n * @throws File upload is not supported in MCP App.\n */\n public uploadFile(): Promise<{ fileId: string }> {\n throw new Error(\"File upload is not supported in MCP App.\");\n }\n\n /**\n * @throws File download is not supported in MCP App.\n */\n public getFileDownloadUrl(): Promise<{ downloadUrl: string }> {\n throw new Error(\"File download is not supported in MCP App.\");\n }\n\n /**\n * @throws File selection is not supported in MCP App.\n */\n public selectFiles(): Promise<{ fileId: string }[]> {\n throw new Error(\"File selection is not supported in MCP App.\");\n }\n\n public openModal(options: RequestModalOptions) {\n this._displayState = { mode: \"modal\", params: options.params };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public closeModal() {\n this._displayState = { mode: \"inline\" };\n this.displayListeners.forEach((listener) => {\n listener();\n });\n }\n\n public setOpenInAppUrl(_href: string): Promise<void> {\n throw new Error(\"setOpenInAppUrl is not implemented in MCP App.\");\n }\n\n private subscribeToViewUUID(): void {\n const bridge = McpAppBridge.getInstance();\n bridge.subscribe(\"toolResult\")(() => {\n const toolResult = bridge.getSnapshot(\"toolResult\");\n const viewUUID = (\n toolResult?._meta as Record<string, unknown> | undefined\n )?.viewUUID as string | undefined;\n\n if (viewUUID && viewUUID !== this._viewUUID) {\n this._viewUUID = viewUUID;\n this.restoreFromLocalStorage(viewUUID);\n }\n });\n }\n\n // localStorage keys: sb:{unix_ms}:{viewUUID}\n // Timestamp is updated on every write (LRU); eviction drops the least recently used entries.\n private restoreFromLocalStorage(viewUUID: string): void {\n try {\n const existingKey = findStorageKey(viewUUID);\n if (existingKey) {\n const stored = localStorage.getItem(existingKey);\n if (stored !== null) {\n this._viewState = JSON.parse(stored);\n this.viewStateListeners.forEach((listener) => {\n listener();\n });\n }\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private persistToLocalStorage(state: Record<string, unknown> | null): void {\n if (!this._viewUUID || state === null) {\n return;\n }\n try {\n // Remove old key for this view, write with fresh timestamp (LRU)\n const oldKey = findStorageKey(this._viewUUID);\n if (oldKey) {\n localStorage.removeItem(oldKey);\n }\n const newKey = `${STORAGE_PREFIX}${Date.now()}:${this._viewUUID}`;\n localStorage.setItem(newKey, JSON.stringify(state));\n\n // lru cleanup\n const keys: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const key = localStorage.key(i);\n if (key?.startsWith(STORAGE_PREFIX)) {\n keys.push(key);\n }\n }\n if (keys.length <= MAX_STORAGE_ENTRIES) {\n return;\n }\n keys.sort();\n const toRemove = keys.slice(0, keys.length - MAX_STORAGE_ENTRIES);\n for (const key of toRemove) {\n localStorage.removeItem(key);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n private createHostContextStore<\n const Keys extends readonly McpAppContextKey[],\n R,\n >(keys: Keys, computeSnapshot: (context: PickContext<Keys>) => R) {\n const bridge = McpAppBridge.getInstance();\n let cachedValue: R | undefined;\n\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\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n\n cachedValue = newValue;\n return newValue;\n },\n };\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { App } from "@modelcontextprotocol/ext-apps";
2
+ import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { Bridge, Subscribe } from "../types.js";
4
+ import type { McpAppContext, McpAppContextKey } from "./types.js";
5
+ export declare class McpAppBridge implements Bridge<McpAppContext> {
6
+ private static instance;
7
+ context: McpAppContext;
8
+ private listeners;
9
+ private app;
10
+ private connectPromise;
11
+ constructor(options: {
12
+ appInfo: Implementation;
13
+ });
14
+ private connect;
15
+ getApp(): Promise<App>;
16
+ static getInstance(options?: Partial<{
17
+ appInfo: Implementation;
18
+ }>): McpAppBridge;
19
+ subscribe(key: McpAppContextKey): Subscribe;
20
+ subscribe(keys: readonly McpAppContextKey[]): Subscribe;
21
+ getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
22
+ cleanup: () => void;
23
+ static resetInstance(): void;
24
+ private emit;
25
+ private updateContext;
26
+ }
@@ -0,0 +1,102 @@
1
+ import { App } from "@modelcontextprotocol/ext-apps";
2
+ export class McpAppBridge {
3
+ static instance = null;
4
+ context = {
5
+ toolInput: null,
6
+ toolCancelled: null,
7
+ toolResult: null,
8
+ };
9
+ listeners = new Map();
10
+ app;
11
+ connectPromise;
12
+ constructor(options) {
13
+ this.app = new App(options.appInfo);
14
+ this.app.ontoolinput = (params) => {
15
+ this.updateContext({ toolInput: params.arguments ?? {} });
16
+ };
17
+ this.app.ontoolinputpartial = (params) => {
18
+ this.updateContext({ toolInput: params.arguments ?? {} });
19
+ };
20
+ this.app.ontoolresult = (params) => {
21
+ this.updateContext({ toolResult: params });
22
+ };
23
+ this.app.ontoolcancelled = (params) => {
24
+ this.updateContext({ toolCancelled: params });
25
+ };
26
+ this.app.onhostcontextchanged = (params) => {
27
+ this.updateContext(params);
28
+ };
29
+ this.connectPromise = this.connect();
30
+ }
31
+ async connect() {
32
+ try {
33
+ await this.app.connect();
34
+ const hostContext = this.app.getHostContext();
35
+ if (hostContext) {
36
+ this.updateContext(hostContext);
37
+ }
38
+ }
39
+ catch (err) {
40
+ console.error(err);
41
+ }
42
+ }
43
+ async getApp() {
44
+ await this.connectPromise;
45
+ return this.app;
46
+ }
47
+ static getInstance(options) {
48
+ if (window.skybridge.hostType !== "mcp-app") {
49
+ throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
50
+ }
51
+ if (McpAppBridge.instance && options) {
52
+ console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
53
+ }
54
+ if (!McpAppBridge.instance) {
55
+ const defaultOptions = {
56
+ appInfo: { name: "skybridge-app", version: "0.0.1" },
57
+ };
58
+ McpAppBridge.instance = new McpAppBridge({
59
+ ...defaultOptions,
60
+ ...options,
61
+ });
62
+ }
63
+ return McpAppBridge.instance;
64
+ }
65
+ subscribe(keyOrKeys) {
66
+ const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
67
+ return (onChange) => {
68
+ for (const key of keys) {
69
+ this.listeners.set(key, new Set([...(this.listeners.get(key) || []), onChange]));
70
+ }
71
+ return () => {
72
+ for (const key of keys) {
73
+ this.listeners.get(key)?.delete(onChange);
74
+ }
75
+ };
76
+ };
77
+ }
78
+ getSnapshot(key) {
79
+ return this.context[key];
80
+ }
81
+ cleanup = () => {
82
+ this.listeners.clear();
83
+ };
84
+ static resetInstance() {
85
+ if (McpAppBridge.instance) {
86
+ McpAppBridge.instance.cleanup();
87
+ McpAppBridge.instance = null;
88
+ }
89
+ }
90
+ emit(key) {
91
+ this.listeners.get(key)?.forEach((listener) => {
92
+ listener();
93
+ });
94
+ }
95
+ updateContext(context) {
96
+ this.context = { ...this.context, ...context };
97
+ for (const key of Object.keys(context)) {
98
+ this.emit(key);
99
+ }
100
+ }
101
+ }
102
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAKrD,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,I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ACH,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\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 (window.skybridge.hostType !== \"mcp-app\") {\n throw new Error(\"MCP App Bridge can only be used in the mcp-app runtime\");\n }\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,4 @@
1
+ export { McpAppAdaptor } from "./adaptor.js";
2
+ export { McpAppBridge } from "./bridge.js";
3
+ export type { McpAppContext, McpAppContextKey, McpToolState, } from "./types.js";
4
+ export { useMcpAppContext } from "./use-mcp-app-context.js";
@@ -0,0 +1,4 @@
1
+ export { McpAppAdaptor } from "./adaptor.js";
2
+ export { McpAppBridge } from "./bridge.js";
3
+ export { useMcpAppContext } from "./use-mcp-app-context.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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","sourcesContent":["export { McpAppAdaptor } from \"./adaptor.js\";\nexport { 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"]}
@@ -0,0 +1,8 @@
1
+ import type { McpUiHostContext, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
2
+ export type McpToolState = {
3
+ toolInput: NonNullable<McpUiToolInputNotification["params"]["arguments"]> | null;
4
+ toolResult: McpUiToolResultNotification["params"] | null;
5
+ toolCancelled: McpUiToolCancelledNotification["params"] | null;
6
+ };
7
+ export type McpAppContext = McpUiHostContext & McpToolState;
8
+ export type McpAppContextKey = keyof McpAppContext;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,7 @@
1
+ import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
2
+ import type { McpAppContext } from "./types.js";
3
+ type McpAppInitializationOptions = {
4
+ appInfo: Implementation;
5
+ };
6
+ export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { McpAppBridge } from "./bridge.js";
3
+ export function useMcpAppContext(key, options) {
4
+ const bridge = McpAppBridge.getInstance(options);
5
+ return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
6
+ }
7
+ //# sourceMappingURL=use-mcp-app-context.js.map
@@ -0,0 +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;AAO3C,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\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"]}
@@ -0,0 +1,26 @@
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "../../hooks/test/utils.js";
4
+ import { McpAppBridge } from "./bridge.js";
5
+ import { useMcpAppContext } from "./use-mcp-app-context.js";
6
+ describe("useMcpAppContext", () => {
7
+ beforeEach(async () => {
8
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
9
+ vi.stubGlobal("ResizeObserver", MockResizeObserver);
10
+ McpAppBridge.resetInstance();
11
+ });
12
+ afterEach(() => {
13
+ vi.unstubAllGlobals();
14
+ vi.clearAllMocks();
15
+ });
16
+ it("should return the theme value from host context and update on notification", async () => {
17
+ vi.stubGlobal("parent", {
18
+ postMessage: getMcpAppHostPostMessageMock({ theme: "light" }),
19
+ });
20
+ const { result } = renderHook(() => useMcpAppContext("theme"));
21
+ await waitFor(() => {
22
+ expect(result.current).toBe("light");
23
+ });
24
+ });
25
+ });
26
+ //# sourceMappingURL=use-mcp-app-context.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-mcp-app-context.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.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,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QACpD,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QAE/D,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,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 {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"../../hooks/test/utils.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n\ndescribe(\"useMcpAppContext\", () => {\n beforeEach(async () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"should return the theme value from host context and update on notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ theme: \"light\" }),\n });\n const { result } = renderHook(() => useMcpAppContext(\"theme\"));\n\n await waitFor(() => {\n expect(result.current).toBe(\"light\");\n });\n });\n});\n"]}
@@ -0,0 +1,111 @@
1
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
+ import type { useSyncExternalStore } from "react";
3
+ import type { ViewHostType } from "../../server/index.js";
4
+ export type SkybridgeProperties = {
5
+ hostType: ViewHostType;
6
+ serverUrl: string;
7
+ };
8
+ declare global {
9
+ interface Window {
10
+ skybridge: SkybridgeProperties;
11
+ }
12
+ }
13
+ export type CallToolArgs = Record<string, unknown> | null;
14
+ export type CallToolResponse = {
15
+ content: CallToolResult["content"];
16
+ structuredContent: NonNullable<CallToolResult["structuredContent"]>;
17
+ isError: NonNullable<CallToolResult["isError"]>;
18
+ meta?: CallToolResult["_meta"];
19
+ };
20
+ export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
21
+ export type RequestDisplayMode = Exclude<DisplayMode, "modal">;
22
+ export type Theme = "light" | "dark";
23
+ export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
24
+ export type SafeAreaInsets = {
25
+ top: number;
26
+ right: number;
27
+ bottom: number;
28
+ left: number;
29
+ };
30
+ export type SafeArea = {
31
+ insets: SafeAreaInsets;
32
+ };
33
+ export type UserAgent = {
34
+ device: {
35
+ type: DeviceType;
36
+ };
37
+ capabilities: {
38
+ hover: boolean;
39
+ touch: boolean;
40
+ };
41
+ };
42
+ export interface HostContext {
43
+ theme: Theme;
44
+ locale: string;
45
+ displayMode: DisplayMode;
46
+ safeArea: SafeArea;
47
+ maxHeight: number | undefined;
48
+ userAgent: UserAgent;
49
+ toolInput: Record<string, unknown> | null;
50
+ toolOutput: Record<string, unknown> | null;
51
+ toolResponseMetadata: Record<string, unknown> | null;
52
+ display: {
53
+ mode: DisplayMode;
54
+ params?: Record<string, unknown>;
55
+ };
56
+ viewState: Record<string, unknown> | null;
57
+ }
58
+ export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
59
+ export interface Bridge<Context> {
60
+ subscribe(key: keyof Context): Subscribe;
61
+ subscribe(keys: readonly (keyof Context)[]): Subscribe;
62
+ getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
63
+ }
64
+ export type HostContextStore<K extends keyof HostContext> = {
65
+ subscribe: Subscribe;
66
+ getSnapshot: () => HostContext[K];
67
+ };
68
+ export type ViewState = Record<string, unknown>;
69
+ export type SetViewStateAction = ViewState | ((prevState: ViewState | null) => ViewState);
70
+ export type FileMetadata = {
71
+ fileId: string;
72
+ fileName?: string;
73
+ mimeType?: string;
74
+ };
75
+ export type UploadFileOptions = {
76
+ library?: boolean;
77
+ };
78
+ export type RequestModalOptions = {
79
+ title?: string;
80
+ params?: Record<string, unknown>;
81
+ template?: string;
82
+ anchor?: {
83
+ top?: number;
84
+ left?: number;
85
+ width?: number;
86
+ height?: number;
87
+ };
88
+ };
89
+ export type OpenExternalOptions = {
90
+ redirectUrl?: false;
91
+ };
92
+ export type SendFollowUpMessageOptions = {
93
+ scrollToBottom?: boolean;
94
+ };
95
+ export interface Adaptor {
96
+ getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
97
+ callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
98
+ requestDisplayMode(mode: RequestDisplayMode): Promise<{
99
+ mode: RequestDisplayMode;
100
+ }>;
101
+ sendFollowUpMessage(prompt: string, options?: SendFollowUpMessageOptions): Promise<void>;
102
+ openExternal(href: string, options?: OpenExternalOptions): void;
103
+ setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;
104
+ uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;
105
+ getFileDownloadUrl(file: FileMetadata): Promise<{
106
+ downloadUrl: string;
107
+ }>;
108
+ selectFiles(): Promise<FileMetadata[]>;
109
+ openModal(options: RequestModalOptions): void;
110
+ setOpenInAppUrl(href: string): Promise<void>;
111
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map