skybridge 0.0.0-dev.fa3ebc3 → 0.0.0-dev.fa873ea

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 (291) hide show
  1. package/bin/run.js +9 -0
  2. package/dist/cli/header.d.ts +4 -0
  3. package/dist/cli/header.js +6 -0
  4. package/dist/cli/header.js.map +1 -0
  5. package/dist/cli/run-command.d.ts +2 -0
  6. package/dist/cli/run-command.js +43 -0
  7. package/dist/cli/run-command.js.map +1 -0
  8. package/dist/cli/use-execute-steps.d.ts +10 -0
  9. package/dist/cli/use-execute-steps.js +31 -0
  10. package/dist/cli/use-execute-steps.js.map +1 -0
  11. package/dist/commands/build.d.ts +9 -0
  12. package/dist/commands/build.js +44 -0
  13. package/dist/commands/build.js.map +1 -0
  14. package/dist/commands/dev.d.ts +7 -0
  15. package/dist/commands/dev.js +20 -0
  16. package/dist/commands/dev.js.map +1 -0
  17. package/dist/commands/start.d.ts +7 -0
  18. package/dist/commands/start.js +33 -0
  19. package/dist/commands/start.js.map +1 -0
  20. package/dist/{src/server → server}/index.d.ts +0 -1
  21. package/dist/{src/server → server}/index.js +0 -1
  22. package/dist/server/index.js.map +1 -0
  23. package/dist/server/inferUtilityTypes.js.map +1 -0
  24. package/dist/{src/server → server}/server.d.ts +26 -1
  25. package/dist/server/server.js +138 -0
  26. package/dist/server/server.js.map +1 -0
  27. package/dist/server/templateHelper.js.map +1 -0
  28. package/dist/{src/server → server}/templates/development.hbs +15 -0
  29. package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
  30. package/dist/{src/server → server}/widgetsDevServer.js +11 -2
  31. package/dist/server/widgetsDevServer.js.map +1 -0
  32. package/dist/test/utils.js.map +1 -0
  33. package/dist/{src/test → test}/widget.test.js +101 -6
  34. package/dist/test/widget.test.js.map +1 -0
  35. package/dist/{src/web/bridges/adaptors/apps-sdk-adaptor.d.ts → web/bridges/apps-sdk/adaptor.d.ts} +3 -2
  36. package/dist/{src/web/bridges/adaptors/apps-sdk-adaptor.js → web/bridges/apps-sdk/adaptor.js} +9 -3
  37. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
  38. package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
  39. package/dist/{src/web/bridges/apps-sdk-bridge.js → web/bridges/apps-sdk/bridge.js} +2 -2
  40. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
  41. package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
  42. package/dist/web/bridges/apps-sdk/index.js +5 -0
  43. package/dist/web/bridges/apps-sdk/index.js.map +1 -0
  44. package/dist/{src/web → web/bridges/apps-sdk}/types.d.ts +14 -42
  45. package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
  46. package/dist/web/bridges/apps-sdk/types.js.map +1 -0
  47. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
  48. package/dist/{src/web/bridges/hooks/use-apps-sdk-bridge.js → web/bridges/apps-sdk/use-apps-sdk-context.js} +3 -3
  49. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
  50. package/dist/web/bridges/get-adaptor.d.ts +2 -0
  51. package/dist/web/bridges/get-adaptor.js +8 -0
  52. package/dist/web/bridges/get-adaptor.js.map +1 -0
  53. package/dist/web/bridges/index.d.ts +5 -0
  54. package/dist/web/bridges/index.js +6 -0
  55. package/dist/web/bridges/index.js.map +1 -0
  56. package/dist/{src/web/bridges/adaptors/mcp-app-adaptor.d.ts → web/bridges/mcp-app/adaptor.d.ts} +6 -3
  57. package/dist/{src/web/bridges/adaptors/mcp-app-adaptor.js → web/bridges/mcp-app/adaptor.js} +44 -14
  58. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
  59. package/dist/web/bridges/mcp-app/bridge.d.ts +43 -0
  60. package/dist/{src/web/bridges/mcp-app-bridge.js → web/bridges/mcp-app/bridge.js} +109 -16
  61. package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
  62. package/dist/web/bridges/mcp-app/index.d.ts +4 -0
  63. package/dist/web/bridges/mcp-app/index.js +4 -0
  64. package/dist/web/bridges/mcp-app/index.js.map +1 -0
  65. package/dist/web/bridges/mcp-app/types.d.ts +8 -0
  66. package/dist/web/bridges/mcp-app/types.js.map +1 -0
  67. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -0
  68. package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.js → web/bridges/mcp-app/use-mcp-app-context.js} +3 -3
  69. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
  70. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +66 -0
  71. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
  72. package/dist/{src/web → web}/bridges/types.d.ts +40 -23
  73. package/dist/web/bridges/types.js +2 -0
  74. package/dist/{src/web → web}/bridges/types.js.map +1 -1
  75. package/dist/web/bridges/use-host-context.d.ts +2 -0
  76. package/dist/web/bridges/use-host-context.js +8 -0
  77. package/dist/web/bridges/use-host-context.js.map +1 -0
  78. package/dist/{src/web → web}/create-store.js +6 -7
  79. package/dist/web/create-store.js.map +1 -0
  80. package/dist/web/create-store.test.js +126 -0
  81. package/dist/web/create-store.test.js.map +1 -0
  82. package/dist/{src/web → web}/data-llm.js +5 -3
  83. package/dist/web/data-llm.js.map +1 -0
  84. package/dist/web/data-llm.test.js +139 -0
  85. package/dist/web/data-llm.test.js.map +1 -0
  86. package/dist/{src/web → web}/generate-helpers.d.ts +3 -2
  87. package/dist/{src/web → web}/generate-helpers.js +1 -1
  88. package/dist/web/generate-helpers.js.map +1 -0
  89. package/dist/web/generate-helpers.test-d.js.map +1 -0
  90. package/dist/web/generate-helpers.test.js.map +1 -0
  91. package/dist/{src/web → web}/helpers/state.js +13 -8
  92. package/dist/web/helpers/state.js.map +1 -0
  93. package/dist/web/helpers/state.test.js.map +1 -0
  94. package/dist/{src/web → web}/hooks/index.d.ts +0 -1
  95. package/dist/{src/web → web}/hooks/index.js +0 -1
  96. package/dist/web/hooks/index.js.map +1 -0
  97. package/dist/{src/web → web}/hooks/test/utils.d.ts +8 -2
  98. package/dist/web/hooks/test/utils.js +60 -0
  99. package/dist/web/hooks/test/utils.js.map +1 -0
  100. package/dist/{src/web → web}/hooks/use-call-tool.d.ts +3 -2
  101. package/dist/{src/web → web}/hooks/use-call-tool.js +2 -2
  102. package/dist/web/hooks/use-call-tool.js.map +1 -0
  103. package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +1 -1
  104. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
  105. package/dist/{src/web → web}/hooks/use-call-tool.test.js +3 -3
  106. package/dist/web/hooks/use-call-tool.test.js.map +1 -0
  107. package/dist/web/hooks/use-display-mode.js +9 -0
  108. package/dist/web/hooks/use-display-mode.js.map +1 -0
  109. package/dist/web/hooks/use-display-mode.test.js.map +1 -0
  110. package/dist/{src/web → web}/hooks/use-files.d.ts +1 -1
  111. package/dist/web/hooks/use-files.js +7 -0
  112. package/dist/web/hooks/use-files.js.map +1 -0
  113. package/dist/{src/web → web}/hooks/use-files.test.js +4 -4
  114. package/dist/web/hooks/use-files.test.js.map +1 -0
  115. package/dist/{src/web → web}/hooks/use-layout.d.ts +1 -1
  116. package/dist/{src/web → web}/hooks/use-layout.js +4 -4
  117. package/dist/web/hooks/use-layout.js.map +1 -0
  118. package/dist/{src/web → web}/hooks/use-layout.test.js +6 -5
  119. package/dist/web/hooks/use-layout.test.js.map +1 -0
  120. package/dist/{src/web → web}/hooks/use-open-external.js +2 -2
  121. package/dist/web/hooks/use-open-external.js.map +1 -0
  122. package/dist/{src/web → web}/hooks/use-open-external.test.js +1 -1
  123. package/dist/web/hooks/use-open-external.test.js.map +1 -0
  124. package/dist/{src/web → web}/hooks/use-request-modal.d.ts +1 -1
  125. package/dist/{src/web → web}/hooks/use-request-modal.js +2 -2
  126. package/dist/web/hooks/use-request-modal.js.map +1 -0
  127. package/dist/web/hooks/use-request-modal.test.js.map +1 -0
  128. package/dist/{src/web → web}/hooks/use-send-follow-up-message.js +2 -2
  129. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
  130. package/dist/{src/web → web}/hooks/use-tool-info.js +4 -4
  131. package/dist/web/hooks/use-tool-info.js.map +1 -0
  132. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
  133. package/dist/{src/web → web}/hooks/use-tool-info.test.js +4 -4
  134. package/dist/web/hooks/use-tool-info.test.js.map +1 -0
  135. package/dist/{src/web → web}/hooks/use-user.d.ts +1 -1
  136. package/dist/{src/web → web}/hooks/use-user.js +3 -3
  137. package/dist/web/hooks/use-user.js.map +1 -0
  138. package/dist/{src/web → web}/hooks/use-user.test.js +4 -3
  139. package/dist/web/hooks/use-user.test.js.map +1 -0
  140. package/dist/{src/web → web}/hooks/use-widget-state.js +10 -10
  141. package/dist/web/hooks/use-widget-state.js.map +1 -0
  142. package/dist/web/hooks/use-widget-state.test.js.map +1 -0
  143. package/dist/web/index.js.map +1 -0
  144. package/dist/web/mount-widget.js.map +1 -0
  145. package/dist/web/plugin/data-llm.test.js.map +1 -0
  146. package/dist/web/plugin/plugin.js.map +1 -0
  147. package/dist/web/plugin/transform-data-llm.js.map +1 -0
  148. package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
  149. package/dist/web/proxy.js.map +1 -0
  150. package/dist/web/types.d.ts +16 -0
  151. package/dist/web/types.js +2 -0
  152. package/dist/web/types.js.map +1 -0
  153. package/package.json +31 -15
  154. package/dist/src/server/devtoolsStaticServer.d.ts +0 -19
  155. package/dist/src/server/devtoolsStaticServer.js +0 -48
  156. package/dist/src/server/devtoolsStaticServer.js.map +0 -1
  157. package/dist/src/server/index.js.map +0 -1
  158. package/dist/src/server/inferUtilityTypes.js.map +0 -1
  159. package/dist/src/server/server.js +0 -86
  160. package/dist/src/server/server.js.map +0 -1
  161. package/dist/src/server/templateHelper.js.map +0 -1
  162. package/dist/src/server/widgetsDevServer.js.map +0 -1
  163. package/dist/src/test/utils.js.map +0 -1
  164. package/dist/src/test/widget.test.js.map +0 -1
  165. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
  166. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
  167. package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -10
  168. package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
  169. package/dist/src/web/bridges/hooks/use-adaptor.d.ts +0 -2
  170. package/dist/src/web/bridges/hooks/use-adaptor.js +0 -8
  171. package/dist/src/web/bridges/hooks/use-adaptor.js.map +0 -1
  172. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
  173. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
  174. package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -2
  175. package/dist/src/web/bridges/hooks/use-bridge.js +0 -8
  176. package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
  177. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -5
  178. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
  179. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -41
  180. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
  181. package/dist/src/web/bridges/index.d.ts +0 -4
  182. package/dist/src/web/bridges/index.js +0 -5
  183. package/dist/src/web/bridges/index.js.map +0 -1
  184. package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -38
  185. package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
  186. package/dist/src/web/create-store.js.map +0 -1
  187. package/dist/src/web/create-store.test.js +0 -70
  188. package/dist/src/web/create-store.test.js.map +0 -1
  189. package/dist/src/web/data-llm.js.map +0 -1
  190. package/dist/src/web/data-llm.test.js +0 -76
  191. package/dist/src/web/data-llm.test.js.map +0 -1
  192. package/dist/src/web/generate-helpers.js.map +0 -1
  193. package/dist/src/web/generate-helpers.test-d.js.map +0 -1
  194. package/dist/src/web/generate-helpers.test.js.map +0 -1
  195. package/dist/src/web/helpers/state.js.map +0 -1
  196. package/dist/src/web/helpers/state.test.js.map +0 -1
  197. package/dist/src/web/hooks/index.js.map +0 -1
  198. package/dist/src/web/hooks/test/utils.js +0 -40
  199. package/dist/src/web/hooks/test/utils.js.map +0 -1
  200. package/dist/src/web/hooks/use-call-tool.js.map +0 -1
  201. package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
  202. package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
  203. package/dist/src/web/hooks/use-display-mode.js +0 -10
  204. package/dist/src/web/hooks/use-display-mode.js.map +0 -1
  205. package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
  206. package/dist/src/web/hooks/use-files.js +0 -7
  207. package/dist/src/web/hooks/use-files.js.map +0 -1
  208. package/dist/src/web/hooks/use-files.test.js.map +0 -1
  209. package/dist/src/web/hooks/use-layout.js.map +0 -1
  210. package/dist/src/web/hooks/use-layout.test.js.map +0 -1
  211. package/dist/src/web/hooks/use-open-external.js.map +0 -1
  212. package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
  213. package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
  214. package/dist/src/web/hooks/use-openai-global.js +0 -6
  215. package/dist/src/web/hooks/use-openai-global.js.map +0 -1
  216. package/dist/src/web/hooks/use-request-modal.js.map +0 -1
  217. package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
  218. package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
  219. package/dist/src/web/hooks/use-tool-info.js.map +0 -1
  220. package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
  221. package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
  222. package/dist/src/web/hooks/use-user.js.map +0 -1
  223. package/dist/src/web/hooks/use-user.test.js.map +0 -1
  224. package/dist/src/web/hooks/use-widget-state.js.map +0 -1
  225. package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
  226. package/dist/src/web/index.js.map +0 -1
  227. package/dist/src/web/mount-widget.js.map +0 -1
  228. package/dist/src/web/plugin/data-llm.test.js.map +0 -1
  229. package/dist/src/web/plugin/plugin.js.map +0 -1
  230. package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
  231. package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
  232. package/dist/src/web/proxy.js.map +0 -1
  233. package/dist/src/web/types.js.map +0 -1
  234. package/dist/vitest.config.d.ts +0 -2
  235. package/dist/vitest.config.js +0 -8
  236. package/dist/vitest.config.js.map +0 -1
  237. /package/dist/{src/server → server}/inferUtilityTypes.d.ts +0 -0
  238. /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
  239. /package/dist/{src/server → server}/templateHelper.d.ts +0 -0
  240. /package/dist/{src/server → server}/templateHelper.js +0 -0
  241. /package/dist/{src/server → server}/templates/production.hbs +0 -0
  242. /package/dist/{src/test → test}/utils.d.ts +0 -0
  243. /package/dist/{src/test → test}/utils.js +0 -0
  244. /package/dist/{src/test → test}/widget.test.d.ts +0 -0
  245. /package/dist/{src/web/bridges → web/bridges/mcp-app}/types.js +0 -0
  246. /package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
  247. /package/dist/{src/web → web}/create-store.d.ts +0 -0
  248. /package/dist/{src/web → web}/create-store.test.d.ts +0 -0
  249. /package/dist/{src/web → web}/data-llm.d.ts +0 -0
  250. /package/dist/{src/web → web}/data-llm.test.d.ts +0 -0
  251. /package/dist/{src/web → web}/generate-helpers.test-d.d.ts +0 -0
  252. /package/dist/{src/web → web}/generate-helpers.test-d.js +0 -0
  253. /package/dist/{src/web → web}/generate-helpers.test.d.ts +0 -0
  254. /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
  255. /package/dist/{src/web → web}/helpers/state.d.ts +0 -0
  256. /package/dist/{src/web → web}/helpers/state.test.d.ts +0 -0
  257. /package/dist/{src/web → web}/helpers/state.test.js +0 -0
  258. /package/dist/{src/web → web}/hooks/use-call-tool.test-d.d.ts +0 -0
  259. /package/dist/{src/web → web}/hooks/use-call-tool.test.d.ts +0 -0
  260. /package/dist/{src/web → web}/hooks/use-display-mode.d.ts +0 -0
  261. /package/dist/{src/web → web}/hooks/use-display-mode.test.d.ts +0 -0
  262. /package/dist/{src/web → web}/hooks/use-display-mode.test.js +0 -0
  263. /package/dist/{src/web → web}/hooks/use-files.test.d.ts +0 -0
  264. /package/dist/{src/web → web}/hooks/use-layout.test.d.ts +0 -0
  265. /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
  266. /package/dist/{src/web → web}/hooks/use-open-external.test.d.ts +0 -0
  267. /package/dist/{src/web → web}/hooks/use-request-modal.test.d.ts +0 -0
  268. /package/dist/{src/web → web}/hooks/use-request-modal.test.js +0 -0
  269. /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
  270. /package/dist/{src/web → web}/hooks/use-tool-info.d.ts +0 -0
  271. /package/dist/{src/web → web}/hooks/use-tool-info.test-d.d.ts +0 -0
  272. /package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +0 -0
  273. /package/dist/{src/web → web}/hooks/use-tool-info.test.d.ts +0 -0
  274. /package/dist/{src/web → web}/hooks/use-user.test.d.ts +0 -0
  275. /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
  276. /package/dist/{src/web → web}/hooks/use-widget-state.test.d.ts +0 -0
  277. /package/dist/{src/web → web}/hooks/use-widget-state.test.js +0 -0
  278. /package/dist/{src/web → web}/index.d.ts +0 -0
  279. /package/dist/{src/web → web}/index.js +0 -0
  280. /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
  281. /package/dist/{src/web → web}/mount-widget.js +0 -0
  282. /package/dist/{src/web → web}/plugin/data-llm.test.d.ts +0 -0
  283. /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
  284. /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
  285. /package/dist/{src/web → web}/plugin/plugin.js +0 -0
  286. /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
  287. /package/dist/{src/web → web}/plugin/transform-data-llm.js +0 -0
  288. /package/dist/{src/web → web}/plugin/transform-data-llm.test.d.ts +0 -0
  289. /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
  290. /package/dist/{src/web → web}/proxy.d.ts +0 -0
  291. /package/dist/{src/web → web}/proxy.js +0 -0
@@ -0,0 +1,43 @@
1
+ import type { McpUiHostContext, McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
2
+ import type { Bridge, Subscribe } from "../types.js";
3
+ import type { McpAppContext, McpAppContextKey } from "./types.js";
4
+ type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
5
+ export declare class McpAppBridge implements Bridge<McpUiHostContext> {
6
+ private static instance;
7
+ context: McpAppContext;
8
+ 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;
17
+ subscribe(key: McpAppContextKey): Subscribe;
18
+ subscribe(keys: readonly McpAppContextKey[]): Subscribe;
19
+ getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
20
+ cleanup: () => void;
21
+ static resetInstance(): void;
22
+ request<R extends {
23
+ method: string;
24
+ params?: unknown;
25
+ }, T>({ method, params, }: R): Promise<T>;
26
+ private emit;
27
+ 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
+ }
43
+ export {};
@@ -1,4 +1,12 @@
1
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 = {}));
2
10
  export class McpAppBridge {
3
11
  static instance = null;
4
12
  context = {
@@ -12,6 +20,7 @@ export class McpAppBridge {
12
20
  initialized;
13
21
  appInitializationOptions;
14
22
  requestTimeout;
23
+ cleanupSizeObserver = null;
15
24
  constructor(options, requestTimeout = 10_000) {
16
25
  this.requestTimeout = requestTimeout;
17
26
  this.initialized = false;
@@ -20,6 +29,7 @@ export class McpAppBridge {
20
29
  appCapabilities: {},
21
30
  protocolVersion: LATEST_PROTOCOL_VERSION,
22
31
  };
32
+ this.init();
23
33
  }
24
34
  static getInstance(options, requestTimeout) {
25
35
  if (window.skybridge.hostType !== "mcp-app") {
@@ -42,7 +52,6 @@ export class McpAppBridge {
42
52
  for (const key of keys) {
43
53
  this.listeners.set(key, new Set([...(this.listeners.get(key) || []), onChange]));
44
54
  }
45
- this.init();
46
55
  return () => {
47
56
  for (const key of keys) {
48
57
  this.listeners.get(key)?.delete(onChange);
@@ -60,6 +69,8 @@ export class McpAppBridge {
60
69
  });
61
70
  this.pendingRequests.clear();
62
71
  this.listeners.clear();
72
+ this.cleanupSizeObserver?.();
73
+ this.cleanupSizeObserver = null;
63
74
  };
64
75
  static resetInstance() {
65
76
  if (McpAppBridge.instance) {
@@ -109,39 +120,70 @@ export class McpAppBridge {
109
120
  return;
110
121
  }
111
122
  if ("id" in data) {
112
- const request = this.pendingRequests.get(data.id);
113
- if (request) {
114
- clearTimeout(request.timeout);
115
- this.pendingRequests.delete(data.id);
116
- if ("error" in data) {
117
- request.reject(new Error(data.error.message));
118
- return;
119
- }
120
- request.resolve(data.result);
123
+ if ("method" in data) {
124
+ this.handleRequest(data);
125
+ return;
121
126
  }
127
+ this.handleResponse(data);
122
128
  return;
123
129
  }
124
- switch (data.method) {
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) {
125
146
  case "ui/notifications/host-context-changed":
126
- this.updateContext(data.params);
147
+ this.updateContext(notification.params);
127
148
  return;
128
149
  case "ui/notifications/tool-input":
129
150
  this.updateContext({
130
- toolInput: data.params.arguments ?? {},
151
+ toolInput: notification.params.arguments ?? {},
131
152
  });
132
153
  return;
133
154
  case "ui/notifications/tool-result":
134
155
  this.updateContext({
135
- toolResult: data.params,
156
+ toolResult: notification.params,
136
157
  });
137
158
  return;
138
159
  case "ui/notifications/tool-cancelled":
139
160
  this.updateContext({
140
- toolCancelled: data.params,
161
+ toolCancelled: notification.params,
141
162
  });
142
163
  return;
143
164
  }
144
165
  };
166
+ handleRequest = (request) => {
167
+ switch (request.method) {
168
+ case "ui/resource-teardown":
169
+ this.cleanup();
170
+ window.parent.postMessage({
171
+ jsonrpc: "2.0",
172
+ id: request.id,
173
+ result: {},
174
+ }, "*");
175
+ return;
176
+ default:
177
+ window.parent.postMessage({
178
+ jsonrpc: "2.0",
179
+ id: request.id,
180
+ error: {
181
+ code: JsonRpcErrorCode.MethodNotFound,
182
+ message: "Unsupported Request",
183
+ },
184
+ }, "*");
185
+ }
186
+ };
145
187
  async connect() {
146
188
  try {
147
189
  const result = await this.request({
@@ -150,6 +192,7 @@ export class McpAppBridge {
150
192
  });
151
193
  this.updateContext(result.hostContext);
152
194
  this.notify({ method: "ui/notifications/initialized" });
195
+ this.cleanupSizeObserver = this.setupSizeChangedNotifications();
153
196
  }
154
197
  catch (err) {
155
198
  console.error(err);
@@ -158,5 +201,55 @@ export class McpAppBridge {
158
201
  notify(notification) {
159
202
  window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
160
203
  }
204
+ sendSizeChanged(params) {
205
+ this.notify({ method: "ui/notifications/size-changed", params });
206
+ }
207
+ /**
208
+ * Set up automatic size change notifications using ResizeObserver.
209
+ * Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
210
+ * @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
211
+ */
212
+ setupSizeChangedNotifications() {
213
+ let scheduled = false;
214
+ let lastWidth = 0;
215
+ let lastHeight = 0;
216
+ const sendBodySizeChanged = () => {
217
+ if (scheduled) {
218
+ return;
219
+ }
220
+ scheduled = true;
221
+ requestAnimationFrame(() => {
222
+ scheduled = false;
223
+ let width;
224
+ let height;
225
+ // In fullscreen mode, use viewport size since the widget should fill
226
+ // the entire available space provided by the host.
227
+ if (this.context.displayMode === "fullscreen") {
228
+ width = window.innerWidth;
229
+ height = window.innerHeight;
230
+ }
231
+ else {
232
+ // Use scrollWidth/scrollHeight to measure actual rendered content size.
233
+ // This works better than fit-content for viewport-based layouts (vw/vh)
234
+ // and fluid elements like maps that want to fill available space.
235
+ const body = document.body;
236
+ width = Math.ceil(body.scrollWidth);
237
+ height = Math.ceil(body.scrollHeight);
238
+ }
239
+ // Only send if size actually changed (prevents feedback loops from
240
+ // style changes)
241
+ if (width !== lastWidth || height !== lastHeight) {
242
+ lastWidth = width;
243
+ lastHeight = height;
244
+ this.sendSizeChanged({ width, height });
245
+ }
246
+ });
247
+ };
248
+ sendBodySizeChanged();
249
+ const resizeObserver = new ResizeObserver(sendBodySizeChanged);
250
+ resizeObserver.observe(document.documentElement);
251
+ resizeObserver.observe(document.body);
252
+ return () => resizeObserver.disconnect();
253
+ }
161
254
  }
162
- //# sourceMappingURL=mcp-app-bridge.js.map
255
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AA2BA,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAE7C,IAAK,gBAMJ;AAND,WAAK,gBAAgB;IACnB,wEAAmB,CAAA;IACnB,gFAAuB,CAAA;IACvB,gFAAuB,CAAA;IACvB,8EAAsB,CAAA;IACtB,8EAAsB,CAAA;AACxB,CAAC,EANI,gBAAgB,KAAhB,gBAAgB,QAMpB;AA0BD,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IACzD,eAAe,GAAG,IAAI,GAAG,EAA4C,CAAC;IACtE,MAAM,GAAG,CAAC,CAAC;IACX,WAAW,CAAU;IACrB,wBAAwB,CAAmC;IAC3D,cAAc,CAAS;IACvB,mBAAmB,GAAwB,IAAI,CAAC;IAExD,YACE,OAAoC,EACpC,iBAAyB,MAAM;QAE/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,wBAAwB,GAAG;YAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,EAAE;YACnB,eAAe,EAAE,uBAAuB;SACzC,CAAC;QACF,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAEM,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oBACjD,SAAS,GAAG,KAAK,CAAC;oBAClB,UAAU,GAAG,MAAM,CAAC;oBACpB,IAAI,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,mBAAmB,EAAE,CAAC;QAEtB,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,mBAAmB,CAAC,CAAC;QAC/D,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjD,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEtC,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IAC3C,CAAC"}
@@ -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"}
@@ -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 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
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];
5
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { useSyncExternalStore } from "react";
2
- import { McpAppBridge } from "../mcp-app-bridge.js";
3
- export function useMcpAppBridge(key, options, requestTimeout) {
2
+ import { McpAppBridge } from "./bridge.js";
3
+ export function useMcpAppContext(key, options, requestTimeout) {
4
4
  const bridge = McpAppBridge.getInstance(options, requestTimeout);
5
5
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
6
6
  }
7
- //# sourceMappingURL=use-mcp-app-bridge.js.map
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;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"}
@@ -0,0 +1,66 @@
1
+ import { act, 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
+ it("should reject the request after timeout", async () => {
26
+ vi.useFakeTimers();
27
+ const consoleErrorSpy = vi
28
+ .spyOn(console, "error")
29
+ .mockImplementation(() => { });
30
+ const nonRespondingMock = vi.fn();
31
+ vi.stubGlobal("parent", { postMessage: nonRespondingMock });
32
+ renderHook(() => useMcpAppContext("theme", undefined, 100));
33
+ expect(nonRespondingMock).toHaveBeenCalledWith(expect.objectContaining({ method: "ui/initialize" }), "*");
34
+ await act(async () => {
35
+ await vi.advanceTimersByTimeAsync(100);
36
+ });
37
+ expect(consoleErrorSpy).toHaveBeenCalledWith(new Error("Request timed out"));
38
+ consoleErrorSpy.mockRestore();
39
+ vi.useRealTimers();
40
+ });
41
+ it("should send size-changed notification after successful initialization", async () => {
42
+ // Mock body dimensions to non-zero (size-changed only sends when dimensions change)
43
+ Object.defineProperty(document.body, "scrollWidth", {
44
+ value: 800,
45
+ configurable: true,
46
+ });
47
+ Object.defineProperty(document.body, "scrollHeight", {
48
+ value: 600,
49
+ configurable: true,
50
+ });
51
+ const postMessageMock = getMcpAppHostPostMessageMock({ theme: "light" });
52
+ vi.stubGlobal("parent", { postMessage: postMessageMock });
53
+ renderHook(() => useMcpAppContext("theme"));
54
+ await waitFor(() => {
55
+ expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
56
+ jsonrpc: "2.0",
57
+ method: "ui/notifications/size-changed",
58
+ params: expect.objectContaining({
59
+ width: expect.any(Number),
60
+ height: expect.any(Number),
61
+ }),
62
+ }), "*");
63
+ });
64
+ });
65
+ });
66
+ //# 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,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,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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,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,40 +1,54 @@
1
1
  import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import type { useSyncExternalStore } from "react";
3
+ import type { WidgetHostType } from "../../server/index.js";
4
+ export type SkybridgeProperties = {
5
+ hostType: WidgetHostType;
6
+ };
7
+ declare global {
8
+ interface Window {
9
+ skybridge: SkybridgeProperties;
10
+ }
11
+ }
3
12
  export type CallToolArgs = Record<string, unknown> | null;
4
13
  export type CallToolResponse = {
5
14
  content: CallToolResult["content"];
6
15
  structuredContent: NonNullable<CallToolResult["structuredContent"]>;
7
16
  isError: NonNullable<CallToolResult["isError"]>;
8
17
  result: string;
9
- _meta?: CallToolResult["_meta"];
18
+ meta?: CallToolResult["_meta"];
10
19
  };
11
20
  export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
21
+ export type Theme = "light" | "dark";
12
22
  export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
13
- export interface BridgeInterface {
14
- theme: "light" | "dark";
23
+ export type SafeAreaInsets = {
24
+ top: number;
25
+ right: number;
26
+ bottom: number;
27
+ left: number;
28
+ };
29
+ export type SafeArea = {
30
+ insets: SafeAreaInsets;
31
+ };
32
+ export type UserAgent = {
33
+ device: {
34
+ type: DeviceType;
35
+ };
36
+ capabilities: {
37
+ hover: boolean;
38
+ touch: boolean;
39
+ };
40
+ };
41
+ export interface HostContext {
42
+ theme: Theme;
15
43
  locale: string;
16
44
  displayMode: DisplayMode;
17
- safeArea: {
18
- insets: {
19
- top: number;
20
- right: number;
21
- bottom: number;
22
- left: number;
23
- };
24
- };
45
+ safeArea: SafeArea;
25
46
  maxHeight: number;
26
- userAgent: {
27
- device: {
28
- type: DeviceType;
29
- };
30
- capabilities: {
31
- hover: boolean;
32
- touch: boolean;
33
- };
34
- };
47
+ userAgent: UserAgent;
35
48
  toolInput: Record<string, unknown> | null;
36
49
  toolOutput: Record<string, unknown> | null;
37
50
  toolResponseMetadata: Record<string, unknown> | null;
51
+ widgetState: Record<string, unknown> | null;
38
52
  }
39
53
  export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
40
54
  export interface Bridge<Context> {
@@ -42,16 +56,19 @@ export interface Bridge<Context> {
42
56
  subscribe(keys: readonly (keyof Context)[]): Subscribe;
43
57
  getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
44
58
  }
45
- export type ExternalStore<K extends keyof BridgeInterface> = {
59
+ export type HostContextStore<K extends keyof HostContext> = {
46
60
  subscribe: Subscribe;
47
- getSnapshot: () => BridgeInterface[K];
61
+ getSnapshot: () => HostContext[K];
48
62
  };
63
+ export type WidgetState = Record<string, unknown>;
64
+ export type SetWidgetStateAction = WidgetState | ((prevState: WidgetState | null) => WidgetState);
49
65
  export interface Adaptor {
50
- getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
66
+ getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
51
67
  callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
52
68
  requestDisplayMode(mode: DisplayMode): Promise<{
53
69
  mode: DisplayMode;
54
70
  }>;
55
71
  sendFollowUpMessage(prompt: string): Promise<void>;
56
72
  openExternal(href: string): void;
73
+ setWidgetState(stateOrUpdater: SetWidgetStateAction): Promise<void>;
57
74
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import type { HostContext } from "./types.js";
2
+ export declare const useHostContext: <K extends keyof HostContext>(key: K) => HostContext[K];
@@ -0,0 +1,8 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { getAdaptor } from "./get-adaptor.js";
3
+ export const useHostContext = (key) => {
4
+ const adaptor = getAdaptor();
5
+ const store = adaptor.getHostContextStore(key);
6
+ return useSyncExternalStore(store.subscribe, store.getSnapshot);
7
+ };
8
+ //# sourceMappingURL=use-host-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { create } from "zustand";
2
+ import { getAdaptor } from "./bridges/index.js";
2
3
  import { getInitialState, injectWidgetContext, serializeState, } from "./helpers/state.js";
3
4
  export function createStore(storeCreator, defaultState) {
4
5
  const initialState = getInitialState(defaultState);
@@ -10,13 +11,11 @@ export function createStore(storeCreator, defaultState) {
10
11
  return baseStore;
11
12
  });
12
13
  store.subscribe((state) => {
13
- if (window.openai) {
14
- const serializedState = serializeState(state);
15
- if (serializedState !== null && serializedState !== undefined) {
16
- const stateToPersist = injectWidgetContext(serializedState);
17
- if (stateToPersist !== null) {
18
- window.openai.setWidgetState(stateToPersist);
19
- }
14
+ const serializedState = serializeState(state);
15
+ if (serializedState !== null && serializedState !== undefined) {
16
+ const stateToPersist = injectWidgetContext(serializedState);
17
+ if (stateToPersist !== null) {
18
+ getAdaptor().setWidgetState(stateToPersist);
20
19
  }
21
20
  }
22
21
  });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-store.js","sourceRoot":"","sources":["../../src/web/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,MAAM,UAAU,WAAW,CACzB,YAAgD,EAChD,YAAoC;IAEpC,MAAM,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAEnD,MAAM,KAAK,GAAG,MAAM,EAAS,CAC3B,CAAC,GAAG,IAAoD,EAAE,EAAE;QAC1D,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QAExC,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;QAC3C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CACF,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,CAAC,KAAY,EAAE,EAAE;QAC/B,MAAM,eAAe,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,eAAe,KAAK,IAAI,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAC9D,MAAM,cAAc,GAAG,mBAAmB,CAAC,eAAwB,CAAC,CAAC;YACrE,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;gBAC5B,UAAU,EAAE,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC"}