skybridge 0.0.0-dev.fe23f20 → 0.0.0-dev.fe35f75

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 (293) hide show
  1. package/README.md +153 -0
  2. package/bin/run.js +0 -4
  3. package/dist/cli/detect-port.d.ts +18 -0
  4. package/dist/cli/detect-port.js +61 -0
  5. package/dist/cli/detect-port.js.map +1 -0
  6. package/dist/cli/header.js +1 -1
  7. package/dist/cli/header.js.map +1 -1
  8. package/dist/cli/run-command.js.map +1 -1
  9. package/dist/cli/telemetry.d.ts +7 -0
  10. package/dist/cli/telemetry.js +123 -0
  11. package/dist/cli/telemetry.js.map +1 -0
  12. package/dist/cli/tunnel-control-server.d.ts +9 -0
  13. package/dist/cli/tunnel-control-server.js +31 -0
  14. package/dist/cli/tunnel-control-server.js.map +1 -0
  15. package/dist/cli/tunnel-control-server.test.js +39 -0
  16. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  17. package/dist/cli/tunnel-handler.d.ts +3 -0
  18. package/dist/cli/tunnel-handler.js +48 -0
  19. package/dist/cli/tunnel-handler.js.map +1 -0
  20. package/dist/cli/tunnel-handler.test.js +105 -0
  21. package/dist/cli/tunnel-handler.test.js.map +1 -0
  22. package/dist/cli/tunnel.d.ts +57 -0
  23. package/dist/cli/tunnel.js +154 -0
  24. package/dist/cli/tunnel.js.map +1 -0
  25. package/dist/cli/tunnel.test.d.ts +1 -0
  26. package/dist/cli/tunnel.test.js +190 -0
  27. package/dist/cli/tunnel.test.js.map +1 -0
  28. package/dist/cli/types.d.ts +5 -0
  29. package/dist/cli/types.js +2 -0
  30. package/dist/cli/types.js.map +1 -0
  31. package/dist/cli/use-execute-steps.d.ts +3 -2
  32. package/dist/cli/use-execute-steps.js +6 -1
  33. package/dist/cli/use-execute-steps.js.map +1 -1
  34. package/dist/cli/use-messages.d.ts +3 -0
  35. package/dist/cli/use-messages.js +11 -0
  36. package/dist/cli/use-messages.js.map +1 -0
  37. package/dist/cli/use-nodemon.d.ts +2 -0
  38. package/dist/cli/use-nodemon.js +73 -0
  39. package/dist/cli/use-nodemon.js.map +1 -0
  40. package/dist/cli/use-open-browser.d.ts +1 -0
  41. package/dist/cli/use-open-browser.js +44 -0
  42. package/dist/cli/use-open-browser.js.map +1 -0
  43. package/dist/cli/use-tunnel.d.ts +14 -0
  44. package/dist/cli/use-tunnel.js +131 -0
  45. package/dist/cli/use-tunnel.js.map +1 -0
  46. package/dist/cli/use-typescript-check.d.ts +9 -0
  47. package/dist/cli/use-typescript-check.js +94 -0
  48. package/dist/cli/use-typescript-check.js.map +1 -0
  49. package/dist/commands/build.js +64 -6
  50. package/dist/commands/build.js.map +1 -1
  51. package/dist/commands/dev.d.ts +6 -1
  52. package/dist/commands/dev.js +69 -9
  53. package/dist/commands/dev.js.map +1 -1
  54. package/dist/commands/start.d.ts +3 -1
  55. package/dist/commands/start.js +31 -15
  56. package/dist/commands/start.js.map +1 -1
  57. package/dist/commands/telemetry/disable.d.ts +5 -0
  58. package/dist/commands/telemetry/disable.js +14 -0
  59. package/dist/commands/telemetry/disable.js.map +1 -0
  60. package/dist/commands/telemetry/enable.d.ts +5 -0
  61. package/dist/commands/telemetry/enable.js +14 -0
  62. package/dist/commands/telemetry/enable.js.map +1 -0
  63. package/dist/commands/telemetry/status.d.ts +5 -0
  64. package/dist/commands/telemetry/status.js +14 -0
  65. package/dist/commands/telemetry/status.js.map +1 -0
  66. package/dist/server/asset-base-url-transform-plugin.d.ts +10 -0
  67. package/dist/server/asset-base-url-transform-plugin.js +33 -0
  68. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  69. package/dist/server/asset-base-url-transform-plugin.test.d.ts +1 -0
  70. package/dist/server/asset-base-url-transform-plugin.test.js +84 -0
  71. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  72. package/dist/server/content-helpers.d.ts +27 -0
  73. package/dist/server/content-helpers.js +46 -0
  74. package/dist/server/content-helpers.js.map +1 -0
  75. package/dist/server/content-helpers.test.d.ts +1 -0
  76. package/dist/server/content-helpers.test.js +70 -0
  77. package/dist/server/content-helpers.test.js.map +1 -0
  78. package/dist/server/express.d.ts +11 -0
  79. package/dist/server/express.js +101 -0
  80. package/dist/server/express.js.map +1 -0
  81. package/dist/server/express.test.d.ts +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 +5 -3
  85. package/dist/server/index.js +3 -2
  86. package/dist/server/index.js.map +1 -1
  87. package/dist/server/inferUtilityTypes.d.ts +6 -6
  88. package/dist/server/inferUtilityTypes.js.map +1 -1
  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.d.ts +1 -0
  96. package/dist/server/middleware.test-d.js +75 -0
  97. package/dist/server/middleware.test-d.js.map +1 -0
  98. package/dist/server/middleware.test.d.ts +1 -0
  99. package/dist/server/middleware.test.js +493 -0
  100. package/dist/server/middleware.test.js.map +1 -0
  101. package/dist/server/server.d.ts +160 -63
  102. package/dist/server/server.js +393 -63
  103. package/dist/server/server.js.map +1 -1
  104. package/dist/server/templateHelper.d.ts +5 -7
  105. package/dist/server/templateHelper.js +3 -22
  106. package/dist/server/templateHelper.js.map +1 -1
  107. package/dist/server/templates.generated.d.ts +4 -0
  108. package/dist/server/templates.generated.js +47 -0
  109. package/dist/server/templates.generated.js.map +1 -0
  110. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  111. package/dist/server/tunnel-proxy-router.js +110 -0
  112. package/dist/server/tunnel-proxy-router.js.map +1 -0
  113. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  114. package/dist/server/tunnel-proxy-router.test.js +229 -0
  115. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  116. package/dist/server/viewsDevServer.d.ts +14 -0
  117. package/dist/server/viewsDevServer.js +45 -0
  118. package/dist/server/viewsDevServer.js.map +1 -0
  119. package/dist/test/utils.d.ts +13 -21
  120. package/dist/test/utils.js +42 -37
  121. package/dist/test/utils.js.map +1 -1
  122. package/dist/test/view.test.d.ts +1 -0
  123. package/dist/test/view.test.js +523 -0
  124. package/dist/test/view.test.js.map +1 -0
  125. package/dist/version.d.ts +1 -0
  126. package/dist/version.js +3 -0
  127. package/dist/version.js.map +1 -0
  128. package/dist/web/bridges/apps-sdk/adaptor.d.ts +18 -6
  129. package/dist/web/bridges/apps-sdk/adaptor.js +71 -8
  130. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  131. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -1
  132. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  133. package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
  134. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  135. package/dist/web/bridges/apps-sdk/types.d.ts +39 -27
  136. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  137. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  138. package/dist/web/bridges/get-adaptor.js.map +1 -1
  139. package/dist/web/bridges/index.js.map +1 -1
  140. package/dist/web/bridges/mcp-app/adaptor.d.ts +39 -8
  141. package/dist/web/bridges/mcp-app/adaptor.js +182 -56
  142. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  143. package/dist/web/bridges/mcp-app/bridge.d.ts +13 -30
  144. package/dist/web/bridges/mcp-app/bridge.js +43 -196
  145. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  146. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  147. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  148. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -3
  149. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +2 -2
  150. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  151. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -41
  152. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  153. package/dist/web/bridges/types.d.ts +55 -12
  154. package/dist/web/bridges/types.js.map +1 -1
  155. package/dist/web/bridges/use-host-context.js.map +1 -1
  156. package/dist/web/components/modal-provider.d.ts +4 -0
  157. package/dist/web/components/modal-provider.js +45 -0
  158. package/dist/web/components/modal-provider.js.map +1 -0
  159. package/dist/web/create-store.js +17 -3
  160. package/dist/web/create-store.js.map +1 -1
  161. package/dist/web/create-store.test.js +23 -20
  162. package/dist/web/create-store.test.js.map +1 -1
  163. package/dist/web/data-llm.d.ts +1 -1
  164. package/dist/web/data-llm.js +3 -3
  165. package/dist/web/data-llm.js.map +1 -1
  166. package/dist/web/data-llm.test.js +33 -30
  167. package/dist/web/data-llm.test.js.map +1 -1
  168. package/dist/web/generate-helpers.d.ts +20 -18
  169. package/dist/web/generate-helpers.js +20 -18
  170. package/dist/web/generate-helpers.js.map +1 -1
  171. package/dist/web/generate-helpers.test-d.js +26 -26
  172. package/dist/web/generate-helpers.test-d.js.map +1 -1
  173. package/dist/web/generate-helpers.test.js.map +1 -1
  174. package/dist/web/helpers/state.d.ts +2 -2
  175. package/dist/web/helpers/state.js +11 -11
  176. package/dist/web/helpers/state.js.map +1 -1
  177. package/dist/web/helpers/state.test.js +9 -9
  178. package/dist/web/helpers/state.test.js.map +1 -1
  179. package/dist/web/hooks/index.d.ts +5 -2
  180. package/dist/web/hooks/index.js +4 -1
  181. package/dist/web/hooks/index.js.map +1 -1
  182. package/dist/web/hooks/test/utils.js +4 -0
  183. package/dist/web/hooks/test/utils.js.map +1 -1
  184. package/dist/web/hooks/use-call-tool.js.map +1 -1
  185. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  186. package/dist/web/hooks/use-call-tool.test.js +0 -4
  187. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  188. package/dist/web/hooks/use-display-mode.d.ts +3 -3
  189. package/dist/web/hooks/use-display-mode.js.map +1 -1
  190. package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
  191. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  192. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  193. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  194. package/dist/web/hooks/use-files.d.ts +3 -6
  195. package/dist/web/hooks/use-files.js +5 -2
  196. package/dist/web/hooks/use-files.js.map +1 -1
  197. package/dist/web/hooks/use-files.test.js +28 -3
  198. package/dist/web/hooks/use-files.test.js.map +1 -1
  199. package/dist/web/hooks/use-layout.d.ts +1 -1
  200. package/dist/web/hooks/use-layout.js.map +1 -1
  201. package/dist/web/hooks/use-layout.test.js +3 -3
  202. package/dist/web/hooks/use-layout.test.js.map +1 -1
  203. package/dist/web/hooks/use-open-external.d.ts +3 -1
  204. package/dist/web/hooks/use-open-external.js +1 -1
  205. package/dist/web/hooks/use-open-external.js.map +1 -1
  206. package/dist/web/hooks/use-open-external.test.js +26 -11
  207. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  208. package/dist/web/hooks/use-request-close.d.ts +2 -0
  209. package/dist/web/hooks/use-request-close.js +8 -0
  210. package/dist/web/hooks/use-request-close.js.map +1 -0
  211. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  212. package/dist/web/hooks/use-request-close.test.js +52 -0
  213. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  214. package/dist/web/hooks/use-request-modal.d.ts +3 -3
  215. package/dist/web/hooks/use-request-modal.js +10 -8
  216. package/dist/web/hooks/use-request-modal.js.map +1 -1
  217. package/dist/web/hooks/use-request-modal.test.js +5 -1
  218. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  219. package/dist/web/hooks/use-request-size.d.ts +3 -0
  220. package/dist/web/hooks/use-request-size.js +8 -0
  221. package/dist/web/hooks/use-request-size.js.map +1 -0
  222. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  223. package/dist/web/hooks/use-request-size.test.js +65 -0
  224. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  225. package/dist/web/hooks/use-send-follow-up-message.d.ts +2 -1
  226. package/dist/web/hooks/use-send-follow-up-message.js +2 -2
  227. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  228. package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
  229. package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
  230. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  231. package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
  232. package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
  233. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  234. package/dist/web/hooks/use-tool-info.js.map +1 -1
  235. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  236. package/dist/web/hooks/use-tool-info.test.js +1 -1
  237. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  238. package/dist/web/hooks/use-user.js +18 -2
  239. package/dist/web/hooks/use-user.js.map +1 -1
  240. package/dist/web/hooks/use-user.test.js +29 -1
  241. package/dist/web/hooks/use-user.test.js.map +1 -1
  242. package/dist/web/hooks/use-view-state.d.ts +4 -0
  243. package/dist/web/hooks/use-view-state.js +32 -0
  244. package/dist/web/hooks/use-view-state.js.map +1 -0
  245. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  246. package/dist/web/hooks/use-view-state.test.js +177 -0
  247. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  248. package/dist/web/index.d.ts +1 -2
  249. package/dist/web/index.js +1 -2
  250. package/dist/web/index.js.map +1 -1
  251. package/dist/web/mount-view.d.ts +1 -0
  252. package/dist/web/{mount-widget.js → mount-view.js} +11 -3
  253. package/dist/web/mount-view.js.map +1 -0
  254. package/dist/web/plugin/data-llm.test.js.map +1 -1
  255. package/dist/web/plugin/plugin.d.ts +4 -1
  256. package/dist/web/plugin/plugin.js +135 -18
  257. package/dist/web/plugin/plugin.js.map +1 -1
  258. package/dist/web/plugin/scan-views.d.ts +16 -0
  259. package/dist/web/plugin/scan-views.js +88 -0
  260. package/dist/web/plugin/scan-views.js.map +1 -0
  261. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  262. package/dist/web/plugin/scan-views.test.js +99 -0
  263. package/dist/web/plugin/scan-views.test.js.map +1 -0
  264. package/dist/web/plugin/transform-data-llm.js +1 -1
  265. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  266. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  267. package/dist/web/plugin/validate-view.d.ts +1 -0
  268. package/dist/web/plugin/validate-view.js +9 -0
  269. package/dist/web/plugin/validate-view.js.map +1 -0
  270. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  271. package/dist/web/plugin/validate-view.test.js +24 -0
  272. package/dist/web/plugin/validate-view.test.js.map +1 -0
  273. package/dist/web/proxy.js +0 -1
  274. package/dist/web/proxy.js.map +1 -1
  275. package/dist/web/types.js.map +1 -1
  276. package/package.json +51 -30
  277. package/tsconfig.base.json +33 -0
  278. package/dist/server/templates/development.hbs +0 -66
  279. package/dist/server/templates/production.hbs +0 -7
  280. package/dist/server/widgetsDevServer.d.ts +0 -12
  281. package/dist/server/widgetsDevServer.js +0 -47
  282. package/dist/server/widgetsDevServer.js.map +0 -1
  283. package/dist/test/widget.test.js +0 -255
  284. package/dist/test/widget.test.js.map +0 -1
  285. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  286. package/dist/web/hooks/use-widget-state.js +0 -32
  287. package/dist/web/hooks/use-widget-state.js.map +0 -1
  288. package/dist/web/hooks/use-widget-state.test.js +0 -61
  289. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  290. package/dist/web/mount-widget.d.ts +0 -1
  291. package/dist/web/mount-widget.js.map +0 -1
  292. /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  293. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
@@ -1,12 +1,4 @@
1
- const LATEST_PROTOCOL_VERSION = "2025-11-21";
2
- var JsonRpcErrorCode;
3
- (function (JsonRpcErrorCode) {
4
- JsonRpcErrorCode[JsonRpcErrorCode["ParseError"] = -32700] = "ParseError";
5
- JsonRpcErrorCode[JsonRpcErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
6
- JsonRpcErrorCode[JsonRpcErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
7
- JsonRpcErrorCode[JsonRpcErrorCode["InvalidParams"] = -32602] = "InvalidParams";
8
- JsonRpcErrorCode[JsonRpcErrorCode["InternalError"] = -32603] = "InternalError";
9
- })(JsonRpcErrorCode || (JsonRpcErrorCode = {}));
1
+ import { App } from "@modelcontextprotocol/ext-apps";
10
2
  export class McpAppBridge {
11
3
  static instance = null;
12
4
  context = {
@@ -15,34 +7,58 @@ export class McpAppBridge {
15
7
  toolResult: null,
16
8
  };
17
9
  listeners = new Map();
18
- pendingRequests = new Map();
19
- nextId = 1;
20
- initialized;
21
- appInitializationOptions;
22
- requestTimeout;
23
- cleanupSizeObserver = null;
24
- constructor(options, requestTimeout = 10_000) {
25
- this.requestTimeout = requestTimeout;
26
- this.initialized = false;
27
- this.appInitializationOptions = {
28
- appInfo: options.appInfo,
29
- appCapabilities: {},
30
- protocolVersion: LATEST_PROTOCOL_VERSION,
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 ?? {} });
31
16
  };
32
- this.init();
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
+ }
33
42
  }
34
- static getInstance(options, requestTimeout) {
43
+ async getApp() {
44
+ await this.connectPromise;
45
+ return this.app;
46
+ }
47
+ static getInstance(options) {
35
48
  if (window.skybridge.hostType !== "mcp-app") {
36
49
  throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
37
50
  }
38
- if (McpAppBridge.instance && (options || requestTimeout)) {
39
- console.warn("McpAppBridge.getInstance: options and requestTimeout ignored, instance already exists");
51
+ if (McpAppBridge.instance && options) {
52
+ console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
40
53
  }
41
54
  if (!McpAppBridge.instance) {
42
55
  const defaultOptions = {
43
56
  appInfo: { name: "skybridge-app", version: "0.0.1" },
44
57
  };
45
- McpAppBridge.instance = new McpAppBridge({ ...defaultOptions, ...options }, requestTimeout);
58
+ McpAppBridge.instance = new McpAppBridge({
59
+ ...defaultOptions,
60
+ ...options,
61
+ });
46
62
  }
47
63
  return McpAppBridge.instance;
48
64
  }
@@ -63,14 +79,7 @@ export class McpAppBridge {
63
79
  return this.context[key];
64
80
  }
65
81
  cleanup = () => {
66
- window.removeEventListener("message", this.handleMessage);
67
- this.pendingRequests.forEach((request) => {
68
- clearTimeout(request.timeout);
69
- });
70
- this.pendingRequests.clear();
71
82
  this.listeners.clear();
72
- this.cleanupSizeObserver?.();
73
- this.cleanupSizeObserver = null;
74
83
  };
75
84
  static resetInstance() {
76
85
  if (McpAppBridge.instance) {
@@ -78,20 +87,6 @@ export class McpAppBridge {
78
87
  McpAppBridge.instance = null;
79
88
  }
80
89
  }
81
- request({ method, params, }) {
82
- const id = this.nextId++;
83
- const { promise, resolve, reject } = Promise.withResolvers();
84
- this.pendingRequests.set(id, {
85
- resolve: resolve,
86
- reject,
87
- timeout: setTimeout(() => {
88
- reject(new Error("Request timed out"));
89
- this.pendingRequests.delete(id);
90
- }, this.requestTimeout),
91
- });
92
- window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
93
- return promise;
94
- }
95
90
  emit(key) {
96
91
  this.listeners.get(key)?.forEach((listener) => {
97
92
  listener();
@@ -103,153 +98,5 @@ export class McpAppBridge {
103
98
  this.emit(key);
104
99
  }
105
100
  }
106
- init() {
107
- if (this.initialized) {
108
- return;
109
- }
110
- this.initialized = true;
111
- if (typeof window === "undefined" || window.parent === window) {
112
- return;
113
- }
114
- window.addEventListener("message", this.handleMessage);
115
- this.connect();
116
- }
117
- handleMessage = (event) => {
118
- const data = event.data;
119
- if (data.jsonrpc !== "2.0") {
120
- return;
121
- }
122
- if ("id" in data) {
123
- if ("method" in data) {
124
- this.handleRequest(data);
125
- return;
126
- }
127
- this.handleResponse(data);
128
- return;
129
- }
130
- this.handleNotification(data);
131
- };
132
- handleResponse(response) {
133
- const request = this.pendingRequests.get(response.id);
134
- if (request) {
135
- clearTimeout(request.timeout);
136
- this.pendingRequests.delete(response.id);
137
- if ("error" in response) {
138
- request.reject(new Error(response.error.message));
139
- return;
140
- }
141
- request.resolve(response.result);
142
- }
143
- }
144
- handleNotification = (notification) => {
145
- switch (notification.method) {
146
- case "ui/notifications/host-context-changed":
147
- this.updateContext(notification.params);
148
- return;
149
- case "ui/notifications/tool-input":
150
- this.updateContext({
151
- toolInput: notification.params.arguments ?? {},
152
- });
153
- return;
154
- case "ui/notifications/tool-result":
155
- this.updateContext({
156
- toolResult: notification.params,
157
- });
158
- return;
159
- case "ui/notifications/tool-cancelled":
160
- this.updateContext({
161
- toolCancelled: notification.params,
162
- });
163
- return;
164
- }
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
- };
187
- async connect() {
188
- try {
189
- const result = await this.request({
190
- method: "ui/initialize",
191
- params: this.appInitializationOptions,
192
- });
193
- this.updateContext(result.hostContext);
194
- this.notify({ method: "ui/notifications/initialized" });
195
- this.cleanupSizeObserver = this.setupSizeChangedNotifications();
196
- }
197
- catch (err) {
198
- console.error(err);
199
- }
200
- }
201
- notify(notification) {
202
- window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
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
- }
254
101
  }
255
102
  //# sourceMappingURL=bridge.js.map
@@ -1 +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,MAAM,CAAC,WAAW,CACvB,OAA8C,EAC9C,cAAuB;QAEvB,IAAI,MAAM,CAAC,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EAAE,CAAC;IACzB,CAAC,CAAC;IAEK,MAAM,CAAC,aAAa;QACzB,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC1B,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,GAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { Bridge, Subscribe } from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n McpUiHostContext,\n McpUiToolCancelledNotification,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\n\nexport type McpToolState = {\n toolInput: NonNullable<\n McpUiToolInputNotification[\"params\"][\"arguments\"]\n > | null;\n toolResult: McpUiToolResultNotification[\"params\"] | null;\n toolCancelled: McpUiToolCancelledNotification[\"params\"] | null;\n};\n\nexport type McpAppContext = McpUiHostContext & McpToolState;\n\nexport type McpAppContextKey = keyof McpAppContext;\n"]}
@@ -1,5 +1,7 @@
1
- import type { McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
1
+ import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
2
2
  import type { McpAppContext } from "./types.js";
3
- type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
4
- export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppContext[K];
3
+ type McpAppInitializationOptions = {
4
+ appInfo: Implementation;
5
+ };
6
+ export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
5
7
  export {};
@@ -1,7 +1,7 @@
1
1
  import { useSyncExternalStore } from "react";
2
2
  import { McpAppBridge } from "./bridge.js";
3
- export function useMcpAppContext(key, options, requestTimeout) {
4
- const bridge = McpAppBridge.getInstance(options, requestTimeout);
3
+ export function useMcpAppContext(key, options) {
4
+ const bridge = McpAppBridge.getInstance(options);
5
5
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
6
6
  }
7
7
  //# sourceMappingURL=use-mcp-app-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C,EAC9C,cAAuB;IAEvB,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACjE,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,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"]}
@@ -1,4 +1,4 @@
1
- import { act, renderHook, waitFor } from "@testing-library/react";
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
3
  import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "../../hooks/test/utils.js";
4
4
  import { McpAppBridge } from "./bridge.js";
@@ -22,45 +22,5 @@ describe("useMcpAppContext", () => {
22
22
  expect(result.current).toBe("light");
23
23
  });
24
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
25
  });
66
26
  //# sourceMappingURL=use-mcp-app-context.test.js.map
@@ -1 +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;A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AA4E,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"]}
@@ -1,8 +1,9 @@
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";
3
+ import type { ViewHostType } from "../../server/index.js";
4
4
  export type SkybridgeProperties = {
5
- hostType: WidgetHostType;
5
+ hostType: ViewHostType;
6
+ serverUrl: string;
6
7
  };
7
8
  declare global {
8
9
  interface Window {
@@ -14,10 +15,10 @@ export type CallToolResponse = {
14
15
  content: CallToolResult["content"];
15
16
  structuredContent: NonNullable<CallToolResult["structuredContent"]>;
16
17
  isError: NonNullable<CallToolResult["isError"]>;
17
- result: string;
18
18
  meta?: CallToolResult["_meta"];
19
19
  };
20
20
  export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
21
+ export type RequestDisplayMode = Exclude<DisplayMode, "modal">;
21
22
  export type Theme = "light" | "dark";
22
23
  export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
23
24
  export type SafeAreaInsets = {
@@ -43,12 +44,16 @@ export interface HostContext {
43
44
  locale: string;
44
45
  displayMode: DisplayMode;
45
46
  safeArea: SafeArea;
46
- maxHeight: number;
47
+ maxHeight: number | undefined;
47
48
  userAgent: UserAgent;
48
49
  toolInput: Record<string, unknown> | null;
49
50
  toolOutput: Record<string, unknown> | null;
50
51
  toolResponseMetadata: Record<string, unknown> | null;
51
- widgetState: Record<string, unknown> | null;
52
+ display: {
53
+ mode: DisplayMode;
54
+ params?: Record<string, unknown>;
55
+ };
56
+ viewState: Record<string, unknown> | null;
52
57
  }
53
58
  export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
54
59
  export interface Bridge<Context> {
@@ -60,15 +65,53 @@ export type HostContextStore<K extends keyof HostContext> = {
60
65
  subscribe: Subscribe;
61
66
  getSnapshot: () => HostContext[K];
62
67
  };
63
- export type WidgetState = Record<string, unknown>;
64
- export type SetWidgetStateAction = WidgetState | ((prevState: WidgetState | null) => WidgetState);
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 type RequestSizeOptions = {
96
+ width?: number;
97
+ height?: number;
98
+ };
65
99
  export interface Adaptor {
66
100
  getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
67
101
  callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
68
- requestDisplayMode(mode: DisplayMode): Promise<{
69
- mode: DisplayMode;
102
+ requestDisplayMode(mode: RequestDisplayMode): Promise<{
103
+ mode: RequestDisplayMode;
104
+ }>;
105
+ requestClose(): Promise<void>;
106
+ requestSize(size: RequestSizeOptions): Promise<void>;
107
+ sendFollowUpMessage(prompt: string, options?: SendFollowUpMessageOptions): Promise<void>;
108
+ openExternal(href: string, options?: OpenExternalOptions): void;
109
+ setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;
110
+ uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;
111
+ getFileDownloadUrl(file: FileMetadata): Promise<{
112
+ downloadUrl: string;
70
113
  }>;
71
- sendFollowUpMessage(prompt: string): Promise<void>;
72
- openExternal(href: string): void;
73
- setWidgetState(stateOrUpdater: SetWidgetStateAction): Promise<void>;
114
+ selectFiles(): Promise<FileMetadata[]>;
115
+ openModal(options: RequestModalOptions): void;
116
+ setOpenInAppUrl(href: string): Promise<void>;
74
117
  }
@@ -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":"","sourcesContent":["import type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\nexport type CallToolArgs = Record<string, unknown> | null;\n\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\nexport type Theme = \"light\" | \"dark\";\n\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\nexport type ViewState = Record<string, unknown>;\n\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\nexport type UploadFileOptions = { library?: boolean };\n\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n}\n"]}
@@ -1 +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
+ {"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","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
@@ -0,0 +1,4 @@
1
+ import { type ReactNode } from "react";
2
+ export declare function ModalProvider({ children }: {
3
+ children: ReactNode;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useSyncExternalStore } from "react";
3
+ import { McpAppAdaptor } from "../bridges/index.js";
4
+ const modalStyles = `
5
+ .sb-modal-backdrop {
6
+ position: fixed;
7
+ inset: 0;
8
+ background: rgba(0, 0, 0, 0.5);
9
+ z-index: 9998;
10
+ }
11
+ .sb-modal-container {
12
+ border-radius: 12px;
13
+ position: fixed;
14
+ inset: 0;
15
+ margin: auto;
16
+ width: fit-content;
17
+ height: fit-content;
18
+ background: white;
19
+ z-index: 9999;
20
+ }
21
+ `;
22
+ export function ModalProvider({ children }) {
23
+ const adaptor = McpAppAdaptor.getInstance();
24
+ const { mode } = useSyncExternalStore(adaptor.getHostContextStore("display").subscribe, adaptor.getHostContextStore("display").getSnapshot);
25
+ const isOpen = mode === "modal";
26
+ const handleBackdropClick = (e) => {
27
+ if (e.target === e.currentTarget) {
28
+ adaptor.closeModal();
29
+ }
30
+ };
31
+ useEffect(() => {
32
+ if (!isOpen) {
33
+ return;
34
+ }
35
+ const handler = (e) => {
36
+ if (e.key === "Escape") {
37
+ adaptor.closeModal();
38
+ }
39
+ };
40
+ document.addEventListener("keydown", handler);
41
+ return () => document.removeEventListener("keydown", handler);
42
+ }, [isOpen, adaptor]);
43
+ return (_jsxs(_Fragment, { children: [_jsx("style", { children: modalStyles }), isOpen && (_jsx("div", { role: "dialog", className: "sb-modal-backdrop", onClick: handleBackdropClick })), _jsx("div", { className: isOpen ? "sb-modal-container" : undefined, children: children })] }));
44
+ }
45
+ //# sourceMappingURL=modal-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modal-provider.js","sourceRoot":"","sources":["../../../src/web/components/modal-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;CAiBnB,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAA2B;IACjE,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAE5C,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAoB,CACnC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,SAAS,EAChD,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,WAAW,CACnD,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAEhC,MAAM,mBAAmB,GAAG,CAAC,CAAmB,EAAE,EAAE;QAClD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC;YACjC,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,CAAgB,EAAE,EAAE;YACnC,IAAI,CAAC,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACvB,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEtB,OAAO,CACL,8BACE,0BAAQ,WAAW,GAAS,EAC3B,MAAM,IAAI,CAET,cACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mBAAmB,EAC7B,OAAO,EAAE,mBAAmB,GAC5B,CACH,EACD,cAAK,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,YACtD,QAAQ,GACL,IACL,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { type ReactNode, useEffect, useSyncExternalStore } from \"react\";\nimport { McpAppAdaptor } from \"../bridges/index.js\";\n\nconst modalStyles = `\n.sb-modal-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.5);\n z-index: 9998;\n}\n.sb-modal-container {\n border-radius: 12px;\n position: fixed;\n inset: 0;\n margin: auto;\n width: fit-content;\n height: fit-content;\n background: white;\n z-index: 9999;\n}\n`;\n\nexport function ModalProvider({ children }: { children: ReactNode }) {\n const adaptor = McpAppAdaptor.getInstance();\n\n const { mode } = useSyncExternalStore(\n adaptor.getHostContextStore(\"display\").subscribe,\n adaptor.getHostContextStore(\"display\").getSnapshot,\n );\n const isOpen = mode === \"modal\";\n\n const handleBackdropClick = (e: React.MouseEvent) => {\n if (e.target === e.currentTarget) {\n adaptor.closeModal();\n }\n };\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const handler = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n adaptor.closeModal();\n }\n };\n document.addEventListener(\"keydown\", handler);\n return () => document.removeEventListener(\"keydown\", handler);\n }, [isOpen, adaptor]);\n\n return (\n <>\n <style>{modalStyles}</style>\n {isOpen && (\n // biome-ignore lint/a11y/useKeyWithClickEvents: backdrop isn't focusable\n <div\n role=\"dialog\"\n className=\"sb-modal-backdrop\"\n onClick={handleBackdropClick}\n />\n )}\n <div className={isOpen ? \"sb-modal-container\" : undefined}>\n {children}\n </div>\n </>\n );\n}\n"]}