skybridge 0.0.0-dev.d425dbf → 0.0.0-dev.d42daf9

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 (287) 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 +117 -5
  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/{src/web/bridges/apps-sdk-bridge.d.ts → web/bridges/apps-sdk/bridge.d.ts} +3 -3
  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 +10 -38
  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/{src/web/bridges/hooks → web/bridges/apps-sdk}/use-apps-sdk-bridge.d.ts +1 -1
  48. package/dist/{src/web/bridges/hooks → web/bridges/apps-sdk}/use-apps-sdk-bridge.js +1 -1
  49. package/dist/web/bridges/apps-sdk/use-apps-sdk-bridge.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} +43 -13
  58. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
  59. package/dist/{src/web/bridges/mcp-app-bridge.d.ts → web/bridges/mcp-app/bridge.d.ts} +14 -9
  60. package/dist/web/bridges/mcp-app/bridge.js +256 -0
  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/{src/web/bridges/hooks → web/bridges/mcp-app}/use-mcp-app-bridge.d.ts +1 -1
  68. package/dist/{src/web/bridges/hooks → web/bridges/mcp-app}/use-mcp-app-bridge.js +1 -1
  69. package/dist/web/bridges/mcp-app/use-mcp-app-bridge.js.map +1 -0
  70. package/dist/{src/web/bridges/hooks → web/bridges/mcp-app}/use-mcp-app-bridge.test.js +18 -2
  71. package/dist/web/bridges/mcp-app/use-mcp-app-bridge.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 +125 -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 +2 -1
  87. package/dist/web/generate-helpers.js.map +1 -0
  88. package/dist/web/generate-helpers.test-d.js.map +1 -0
  89. package/dist/web/generate-helpers.test.js.map +1 -0
  90. package/dist/{src/web → web}/helpers/state.js +13 -8
  91. package/dist/web/helpers/state.js.map +1 -0
  92. package/dist/web/helpers/state.test.js.map +1 -0
  93. package/dist/{src/web → web}/hooks/index.d.ts +0 -1
  94. package/dist/{src/web → web}/hooks/index.js +0 -1
  95. package/dist/web/hooks/index.js.map +1 -0
  96. package/dist/{src/web → web}/hooks/test/utils.d.ts +8 -2
  97. package/dist/web/hooks/test/utils.js +60 -0
  98. package/dist/web/hooks/test/utils.js.map +1 -0
  99. package/dist/{src/web → web}/hooks/use-call-tool.d.ts +2 -1
  100. package/dist/{src/web → web}/hooks/use-call-tool.js +2 -2
  101. package/dist/web/hooks/use-call-tool.js.map +1 -0
  102. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
  103. package/dist/{src/web → web}/hooks/use-call-tool.test.js +0 -1
  104. package/dist/web/hooks/use-call-tool.test.js.map +1 -0
  105. package/dist/web/hooks/use-display-mode.js +9 -0
  106. package/dist/web/hooks/use-display-mode.js.map +1 -0
  107. package/dist/web/hooks/use-display-mode.test.js.map +1 -0
  108. package/dist/{src/web → web}/hooks/use-files.d.ts +1 -1
  109. package/dist/web/hooks/use-files.js +7 -0
  110. package/dist/web/hooks/use-files.js.map +1 -0
  111. package/dist/{src/web → web}/hooks/use-files.test.js +4 -4
  112. package/dist/web/hooks/use-files.test.js.map +1 -0
  113. package/dist/{src/web → web}/hooks/use-layout.d.ts +1 -1
  114. package/dist/{src/web → web}/hooks/use-layout.js +4 -4
  115. package/dist/web/hooks/use-layout.js.map +1 -0
  116. package/dist/{src/web → web}/hooks/use-layout.test.js +4 -4
  117. package/dist/web/hooks/use-layout.test.js.map +1 -0
  118. package/dist/{src/web → web}/hooks/use-open-external.js +2 -2
  119. package/dist/web/hooks/use-open-external.js.map +1 -0
  120. package/dist/{src/web → web}/hooks/use-open-external.test.js +1 -1
  121. package/dist/web/hooks/use-open-external.test.js.map +1 -0
  122. package/dist/{src/web → web}/hooks/use-request-modal.d.ts +1 -1
  123. package/dist/{src/web → web}/hooks/use-request-modal.js +1 -1
  124. package/dist/web/hooks/use-request-modal.js.map +1 -0
  125. package/dist/web/hooks/use-request-modal.test.js.map +1 -0
  126. package/dist/{src/web → web}/hooks/use-send-follow-up-message.js +2 -2
  127. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
  128. package/dist/{src/web → web}/hooks/use-tool-info.js +4 -4
  129. package/dist/web/hooks/use-tool-info.js.map +1 -0
  130. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
  131. package/dist/{src/web → web}/hooks/use-tool-info.test.js +2 -3
  132. package/dist/web/hooks/use-tool-info.test.js.map +1 -0
  133. package/dist/{src/web → web}/hooks/use-user.d.ts +1 -1
  134. package/dist/{src/web → web}/hooks/use-user.js +3 -3
  135. package/dist/web/hooks/use-user.js.map +1 -0
  136. package/dist/{src/web → web}/hooks/use-user.test.js +2 -2
  137. package/dist/web/hooks/use-user.test.js.map +1 -0
  138. package/dist/{src/web → web}/hooks/use-widget-state.js +10 -10
  139. package/dist/web/hooks/use-widget-state.js.map +1 -0
  140. package/dist/web/hooks/use-widget-state.test.js.map +1 -0
  141. package/dist/web/index.js.map +1 -0
  142. package/dist/web/mount-widget.js.map +1 -0
  143. package/dist/web/plugin/data-llm.test.js.map +1 -0
  144. package/dist/web/plugin/plugin.js.map +1 -0
  145. package/dist/web/plugin/transform-data-llm.js.map +1 -0
  146. package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
  147. package/dist/web/proxy.js.map +1 -0
  148. package/dist/web/types.d.ts +16 -0
  149. package/dist/web/types.js +2 -0
  150. package/dist/web/types.js.map +1 -0
  151. package/package.json +26 -11
  152. package/dist/src/server/devtoolsStaticServer.d.ts +0 -19
  153. package/dist/src/server/devtoolsStaticServer.js +0 -48
  154. package/dist/src/server/devtoolsStaticServer.js.map +0 -1
  155. package/dist/src/server/index.js.map +0 -1
  156. package/dist/src/server/inferUtilityTypes.js.map +0 -1
  157. package/dist/src/server/server.js +0 -82
  158. package/dist/src/server/server.js.map +0 -1
  159. package/dist/src/server/templateHelper.js.map +0 -1
  160. package/dist/src/server/widgetsDevServer.js.map +0 -1
  161. package/dist/src/test/utils.js.map +0 -1
  162. package/dist/src/test/widget.test.js.map +0 -1
  163. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
  164. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
  165. package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
  166. package/dist/src/web/bridges/hooks/use-adaptor.d.ts +0 -2
  167. package/dist/src/web/bridges/hooks/use-adaptor.js +0 -8
  168. package/dist/src/web/bridges/hooks/use-adaptor.js.map +0 -1
  169. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
  170. package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -2
  171. package/dist/src/web/bridges/hooks/use-bridge.js +0 -8
  172. package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
  173. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
  174. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
  175. package/dist/src/web/bridges/index.d.ts +0 -4
  176. package/dist/src/web/bridges/index.js +0 -5
  177. package/dist/src/web/bridges/index.js.map +0 -1
  178. package/dist/src/web/bridges/mcp-app-bridge.js +0 -162
  179. package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
  180. package/dist/src/web/create-store.js.map +0 -1
  181. package/dist/src/web/create-store.test.js +0 -70
  182. package/dist/src/web/create-store.test.js.map +0 -1
  183. package/dist/src/web/data-llm.js.map +0 -1
  184. package/dist/src/web/data-llm.test.js +0 -76
  185. package/dist/src/web/data-llm.test.js.map +0 -1
  186. package/dist/src/web/generate-helpers.js.map +0 -1
  187. package/dist/src/web/generate-helpers.test-d.js.map +0 -1
  188. package/dist/src/web/generate-helpers.test.js.map +0 -1
  189. package/dist/src/web/helpers/state.js.map +0 -1
  190. package/dist/src/web/helpers/state.test.js.map +0 -1
  191. package/dist/src/web/hooks/index.js.map +0 -1
  192. package/dist/src/web/hooks/test/utils.js +0 -40
  193. package/dist/src/web/hooks/test/utils.js.map +0 -1
  194. package/dist/src/web/hooks/use-call-tool.js.map +0 -1
  195. package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
  196. package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
  197. package/dist/src/web/hooks/use-display-mode.js +0 -10
  198. package/dist/src/web/hooks/use-display-mode.js.map +0 -1
  199. package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
  200. package/dist/src/web/hooks/use-files.js +0 -7
  201. package/dist/src/web/hooks/use-files.js.map +0 -1
  202. package/dist/src/web/hooks/use-files.test.js.map +0 -1
  203. package/dist/src/web/hooks/use-layout.js.map +0 -1
  204. package/dist/src/web/hooks/use-layout.test.js.map +0 -1
  205. package/dist/src/web/hooks/use-open-external.js.map +0 -1
  206. package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
  207. package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
  208. package/dist/src/web/hooks/use-openai-global.js +0 -6
  209. package/dist/src/web/hooks/use-openai-global.js.map +0 -1
  210. package/dist/src/web/hooks/use-request-modal.js.map +0 -1
  211. package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
  212. package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
  213. package/dist/src/web/hooks/use-tool-info.js.map +0 -1
  214. package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
  215. package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
  216. package/dist/src/web/hooks/use-user.js.map +0 -1
  217. package/dist/src/web/hooks/use-user.test.js.map +0 -1
  218. package/dist/src/web/hooks/use-widget-state.js.map +0 -1
  219. package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
  220. package/dist/src/web/index.js.map +0 -1
  221. package/dist/src/web/mount-widget.js.map +0 -1
  222. package/dist/src/web/plugin/data-llm.test.js.map +0 -1
  223. package/dist/src/web/plugin/plugin.js.map +0 -1
  224. package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
  225. package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
  226. package/dist/src/web/proxy.js.map +0 -1
  227. package/dist/src/web/types.js.map +0 -1
  228. package/dist/vitest.config.d.ts +0 -2
  229. package/dist/vitest.config.js +0 -8
  230. package/dist/vitest.config.js.map +0 -1
  231. /package/dist/{src/server → server}/inferUtilityTypes.d.ts +0 -0
  232. /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
  233. /package/dist/{src/server → server}/templateHelper.d.ts +0 -0
  234. /package/dist/{src/server → server}/templateHelper.js +0 -0
  235. /package/dist/{src/server → server}/templates/production.hbs +0 -0
  236. /package/dist/{src/test → test}/utils.d.ts +0 -0
  237. /package/dist/{src/test → test}/utils.js +0 -0
  238. /package/dist/{src/test → test}/widget.test.d.ts +0 -0
  239. /package/dist/{src/web/bridges → web/bridges/mcp-app}/types.js +0 -0
  240. /package/dist/{src/web/bridges/hooks → web/bridges/mcp-app}/use-mcp-app-bridge.test.d.ts +0 -0
  241. /package/dist/{src/web → web}/create-store.d.ts +0 -0
  242. /package/dist/{src/web → web}/create-store.test.d.ts +0 -0
  243. /package/dist/{src/web → web}/data-llm.d.ts +0 -0
  244. /package/dist/{src/web → web}/data-llm.test.d.ts +0 -0
  245. /package/dist/{src/web → web}/generate-helpers.js +0 -0
  246. /package/dist/{src/web → web}/generate-helpers.test-d.d.ts +0 -0
  247. /package/dist/{src/web → web}/generate-helpers.test-d.js +0 -0
  248. /package/dist/{src/web → web}/generate-helpers.test.d.ts +0 -0
  249. /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
  250. /package/dist/{src/web → web}/helpers/state.d.ts +0 -0
  251. /package/dist/{src/web → web}/helpers/state.test.d.ts +0 -0
  252. /package/dist/{src/web → web}/helpers/state.test.js +0 -0
  253. /package/dist/{src/web → web}/hooks/use-call-tool.test-d.d.ts +0 -0
  254. /package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +0 -0
  255. /package/dist/{src/web → web}/hooks/use-call-tool.test.d.ts +0 -0
  256. /package/dist/{src/web → web}/hooks/use-display-mode.d.ts +0 -0
  257. /package/dist/{src/web → web}/hooks/use-display-mode.test.d.ts +0 -0
  258. /package/dist/{src/web → web}/hooks/use-display-mode.test.js +0 -0
  259. /package/dist/{src/web → web}/hooks/use-files.test.d.ts +0 -0
  260. /package/dist/{src/web → web}/hooks/use-layout.test.d.ts +0 -0
  261. /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
  262. /package/dist/{src/web → web}/hooks/use-open-external.test.d.ts +0 -0
  263. /package/dist/{src/web → web}/hooks/use-request-modal.test.d.ts +0 -0
  264. /package/dist/{src/web → web}/hooks/use-request-modal.test.js +0 -0
  265. /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
  266. /package/dist/{src/web → web}/hooks/use-tool-info.d.ts +0 -0
  267. /package/dist/{src/web → web}/hooks/use-tool-info.test-d.d.ts +0 -0
  268. /package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +0 -0
  269. /package/dist/{src/web → web}/hooks/use-tool-info.test.d.ts +0 -0
  270. /package/dist/{src/web → web}/hooks/use-user.test.d.ts +0 -0
  271. /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
  272. /package/dist/{src/web → web}/hooks/use-widget-state.test.d.ts +0 -0
  273. /package/dist/{src/web → web}/hooks/use-widget-state.test.js +0 -0
  274. /package/dist/{src/web → web}/index.d.ts +0 -0
  275. /package/dist/{src/web → web}/index.js +0 -0
  276. /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
  277. /package/dist/{src/web → web}/mount-widget.js +0 -0
  278. /package/dist/{src/web → web}/plugin/data-llm.test.d.ts +0 -0
  279. /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
  280. /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
  281. /package/dist/{src/web → web}/plugin/plugin.js +0 -0
  282. /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
  283. /package/dist/{src/web → web}/plugin/transform-data-llm.js +0 -0
  284. /package/dist/{src/web → web}/plugin/transform-data-llm.test.d.ts +0 -0
  285. /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
  286. /package/dist/{src/web → web}/proxy.d.ts +0 -0
  287. /package/dist/{src/web → web}/proxy.js +0 -0
@@ -53,6 +53,14 @@ describe("McpServer.registerWidget", () => {
53
53
  uri: "ui://widgets/apps-sdk/my-widget.html",
54
54
  mimeType: "text/html+skybridge",
55
55
  text: expect.stringContaining('<div id="root"></div>'),
56
+ _meta: {
57
+ "openai/widgetCSP": {
58
+ resource_domains: [serverUrl],
59
+ connect_domains: ["ws://localhost:24678"],
60
+ },
61
+ "openai/widgetDomain": serverUrl,
62
+ "openai/widgetDescription": "Test tool",
63
+ },
56
64
  },
57
65
  ],
58
66
  });
@@ -72,8 +80,9 @@ describe("McpServer.registerWidget", () => {
72
80
  const appsSdkResourceCallback = mockRegisterResource.mock
73
81
  .calls[0]?.[3];
74
82
  expect(appsSdkResourceCallback).toBeDefined();
75
- const serverUrl = "https://myapp.com";
76
- const mockExtra = createMockExtra(serverUrl);
83
+ const host = "myapp.com";
84
+ const serverUrl = `https://${host}`;
85
+ const mockExtra = createMockExtra(host);
77
86
  const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
78
87
  expect(result).toEqual({
79
88
  contents: [
@@ -81,6 +90,14 @@ describe("McpServer.registerWidget", () => {
81
90
  uri: "ui://widgets/apps-sdk/my-widget.html",
82
91
  mimeType: "text/html+skybridge",
83
92
  text: expect.stringContaining('<div id="root"></div>'),
93
+ _meta: {
94
+ "openai/widgetCSP": {
95
+ resource_domains: [serverUrl],
96
+ connect_domains: [],
97
+ },
98
+ "openai/widgetDomain": serverUrl,
99
+ "openai/widgetDescription": "Test tool",
100
+ },
84
101
  },
85
102
  ],
86
103
  });
@@ -99,15 +116,19 @@ describe("McpServer.registerWidget", () => {
99
116
  const appsSdkResourceCallback = mockRegisterResource.mock
100
117
  .calls[0]?.[3];
101
118
  expect(appsSdkResourceCallback).toBeDefined();
102
- const serverUrl = "https://myapp.com";
103
- const mockExtra = createMockExtra(serverUrl);
119
+ const host = "myapp.com";
120
+ const serverUrl = `https://${host}`;
121
+ const mockExtra = createMockExtra(host);
104
122
  const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/folder-widget.html"), mockExtra);
105
123
  // Should resolve to folder-widget.js from the manifest entry "src/widgets/folder-widget/index.tsx"
106
124
  expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/folder-widget.js`);
107
125
  });
108
126
  it("should register resources with correct hostType for both apps-sdk and ext-apps formats", async () => {
109
127
  const mockToolCallback = vi.fn();
110
- const mockRegisterResourceConfig = { description: "Test widget" };
128
+ const mockRegisterResourceConfig = {
129
+ description: "Test widget",
130
+ _meta: { "openai/widgetPrefersBorder": true },
131
+ };
111
132
  const mockToolConfig = { description: "Test tool" };
112
133
  server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
113
134
  expect(mockRegisterResource).toHaveBeenCalledTimes(2);
@@ -120,6 +141,15 @@ describe("McpServer.registerWidget", () => {
120
141
  uri: "ui://widgets/apps-sdk/my-widget.html",
121
142
  mimeType: "text/html+skybridge",
122
143
  text: expect.stringContaining('<div id="root"></div>'),
144
+ _meta: {
145
+ "openai/widgetCSP": {
146
+ resource_domains: ["http://localhost:3000"],
147
+ connect_domains: ["ws://localhost:24678"],
148
+ },
149
+ "openai/widgetDomain": "http://localhost:3000",
150
+ "openai/widgetDescription": "Test tool",
151
+ "openai/widgetPrefersBorder": true,
152
+ },
123
153
  },
124
154
  ],
125
155
  });
@@ -134,10 +164,92 @@ describe("McpServer.registerWidget", () => {
134
164
  uri: "ui://widgets/ext-apps/my-widget.html",
135
165
  mimeType: "text/html;profile=mcp-app",
136
166
  text: expect.stringContaining('<div id="root"></div>'),
167
+ _meta: {
168
+ ui: {
169
+ csp: {
170
+ resourceDomains: ["http://localhost:3000"],
171
+ connectDomains: ["ws://localhost:24678"],
172
+ },
173
+ domain: "http://localhost:3000",
174
+ },
175
+ },
137
176
  },
138
177
  ],
139
178
  });
140
179
  expect(extAppsResult.contents[0]?.text).toContain('window.skybridge = { hostType: "mcp-app" }');
141
180
  });
181
+ it("should register tool with ui.resourceUri metadata (not deprecated ui/resourceUri)", async () => {
182
+ const mockToolCallback = vi.fn();
183
+ const mockRegisterResourceConfig = { description: "Test widget" };
184
+ const mockToolConfig = { description: "Test tool" };
185
+ server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
186
+ expect(mockRegisterTool).toHaveBeenCalledTimes(1);
187
+ const toolCallArgs = mockRegisterTool.mock.calls[0];
188
+ const toolConfig = toolCallArgs?.[1];
189
+ expect(toolConfig._meta).toHaveProperty("ui");
190
+ expect(toolConfig._meta?.ui).toEqual({
191
+ resourceUri: "ui://widgets/ext-apps/my-widget.html",
192
+ });
193
+ });
194
+ it("should apply meta overrides in correct priority: defaults < ui.* < direct openai/* keys", async () => {
195
+ const mockToolCallback = vi.fn();
196
+ const mockRegisterResourceConfig = {
197
+ description: "Test widget",
198
+ _meta: {
199
+ // ui.csp overrides (middle priority)
200
+ ui: {
201
+ csp: {
202
+ resourceDomains: ["https://from-ui-csp.com"],
203
+ connectDomains: ["https://from-ui-csp.com"],
204
+ },
205
+ domain: "https://from-ui-domain.com",
206
+ prefersBorder: false,
207
+ },
208
+ // Direct openai/* keys (highest priority) - should override ui.*
209
+ "openai/widgetDomain": "https://direct-override.com",
210
+ "openai/widgetPrefersBorder": true,
211
+ },
212
+ };
213
+ const mockToolConfig = { description: "Test tool" };
214
+ server.registerWidget("override-test", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
215
+ const appsSdkCallback = mockRegisterResource.mock
216
+ .calls[0]?.[3];
217
+ const result = await appsSdkCallback(new URL("ui://widgets/apps-sdk/override-test.html"), createMockExtra("__not_used__"));
218
+ const meta = result.contents[0]?._meta;
219
+ // CSP arrays are merged with union - all unique domains from defaults and user config are preserved
220
+ expect(meta["openai/widgetCSP"]).toEqual({
221
+ resource_domains: ["http://localhost:3000", "https://from-ui-csp.com"],
222
+ connect_domains: ["ws://localhost:24678", "https://from-ui-csp.com"],
223
+ frame_domains: undefined,
224
+ redirect_domains: undefined,
225
+ });
226
+ // Domain should be overridden by direct openai/* key (highest priority)
227
+ expect(meta["openai/widgetDomain"]).toBe("https://direct-override.com");
228
+ // PrefersBorder should be overridden by direct openai/* key (highest priority)
229
+ expect(meta["openai/widgetPrefersBorder"]).toBe(true);
230
+ // Description should be from defaults (toolConfig.description)
231
+ expect(meta["openai/widgetDescription"]).toBe("Test tool");
232
+ });
233
+ it("should register tool with ui.resourceUri metadata only", async () => {
234
+ const mockToolCallback = vi.fn();
235
+ server.registerWidget("my-widget", { description: "Test widget", hosts: ["mcp-app"] }, { description: "Test tool" }, mockToolCallback);
236
+ expect(mockRegisterTool).toHaveBeenCalledTimes(1);
237
+ const toolCallArgs = mockRegisterTool.mock.calls[0];
238
+ const toolConfig = toolCallArgs?.[1];
239
+ expect(toolConfig._meta).toHaveProperty("ui");
240
+ expect(toolConfig._meta?.ui).toEqual({
241
+ resourceUri: "ui://widgets/ext-apps/my-widget.html",
242
+ });
243
+ expect(toolConfig._meta?.["openai/outputTemplate"]).to.be.undefined;
244
+ });
245
+ it("should register tool with uopenai/outputTemplate metadata only", async () => {
246
+ const mockToolCallback = vi.fn();
247
+ server.registerWidget("my-widget", { description: "Test widget", hosts: ["apps-sdk"] }, { description: "Test tool" }, mockToolCallback);
248
+ expect(mockRegisterTool).toHaveBeenCalledTimes(1);
249
+ const toolCallArgs = mockRegisterTool.mock.calls[0];
250
+ const toolConfig = toolCallArgs?.[1];
251
+ expect(toolConfig._meta).not.toHaveProperty("ui");
252
+ expect(toolConfig._meta?.["openai/outputTemplate"]).to.eq("ui://widgets/apps-sdk/my-widget.html");
253
+ });
142
254
  });
143
255
  //# sourceMappingURL=widget.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../src/test/widget.test.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,SAAS,EACT,UAA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AC,cAAc,CACnB,WAAW,EACX,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC,EAAE,EACnD,EAAE,WAAW,EAAE,WAAW,EAAE,EAC5B,gBAAgB,CACjB,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAElD,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,YAAY,EAAE,CAAC,CAAC,CAAwC,CAAC;QAE5E,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CACvD,sCAAsC,CACvC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,13 +1,14 @@
1
- import type { Adaptor, BridgeInterface, CallToolResponse, DisplayMode, ExternalStore } from "../types.js";
1
+ import type { Adaptor, CallToolResponse, DisplayMode, HostContext, HostContextStore, SetWidgetStateAction } from "../types.js";
2
2
  export declare class AppsSdkAdaptor implements Adaptor {
3
3
  private static instance;
4
4
  static getInstance(): AppsSdkAdaptor;
5
5
  static resetInstance(): void;
6
- getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
6
+ getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
7
7
  callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
8
8
  requestDisplayMode: (mode: DisplayMode) => Promise<{
9
9
  mode: DisplayMode;
10
10
  }>;
11
11
  sendFollowUpMessage: (prompt: string) => Promise<void>;
12
12
  openExternal(href: string): void;
13
+ setWidgetState: (stateOrUpdater: SetWidgetStateAction) => Promise<void>;
13
14
  }
@@ -1,4 +1,4 @@
1
- import { AppsSdkBridge } from "../apps-sdk-bridge.js";
1
+ import { AppsSdkBridge } from "./bridge.js";
2
2
  export class AppsSdkAdaptor {
3
3
  static instance = null;
4
4
  static getInstance() {
@@ -10,7 +10,7 @@ export class AppsSdkAdaptor {
10
10
  static resetInstance() {
11
11
  AppsSdkAdaptor.instance = null;
12
12
  }
13
- getExternalStore(key) {
13
+ getHostContextStore(key) {
14
14
  const bridge = AppsSdkBridge.getInstance();
15
15
  return {
16
16
  subscribe: bridge.subscribe(key),
@@ -29,5 +29,11 @@ export class AppsSdkAdaptor {
29
29
  openExternal(href) {
30
30
  window.openai.openExternal({ href });
31
31
  }
32
+ setWidgetState = (stateOrUpdater) => {
33
+ const newState = typeof stateOrUpdater === "function"
34
+ ? stateOrUpdater(window.openai.widgetState)
35
+ : stateOrUpdater;
36
+ return window.openai.setWidgetState(newState);
37
+ };
32
38
  }
33
- //# sourceMappingURL=apps-sdk-adaptor.js.map
39
+ //# sourceMappingURL=adaptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/adaptor.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,cAAc;IACjB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAE/C,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;IACjC,CAAC;IAEM,mBAAmB,CACxB,GAAM;QAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;YAChC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC;SAC3C,CAAC;IACJ,CAAC;IAEM,QAAQ,GAAG,KAAK,EAIrB,IAAY,EACZ,IAAc,EACS,EAAE;QACzB,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAyB,IAAI,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC,CAAC;IAEK,kBAAkB,GAAG,CAC1B,IAAiB,EACe,EAAE;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC;IAEK,mBAAmB,GAAG,CAAC,MAAc,EAAiB,EAAE;QAC7D,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC;IAEK,YAAY,CAAC,IAAY;QAC9B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAEM,cAAc,GAAG,CACtB,cAAoC,EACrB,EAAE;QACjB,MAAM,QAAQ,GACZ,OAAO,cAAc,KAAK,UAAU;YAClC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3C,CAAC,CAAC,cAAc,CAAC;QAErB,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC,CAAC"}
@@ -1,10 +1,10 @@
1
- import { type OpenAiProperties } from "../types.js";
2
- import type { Bridge, Subscribe } from "./types.js";
1
+ import type { Bridge, Subscribe } from "../types.js";
2
+ import { type OpenAiProperties } from "./types.js";
3
3
  export declare class AppsSdkBridge implements Bridge<OpenAiProperties> {
4
4
  private static instance;
5
5
  static getInstance(): AppsSdkBridge;
6
6
  static resetInstance(): void;
7
7
  subscribe(key: keyof OpenAiProperties): Subscribe;
8
8
  subscribe(keys: readonly (keyof OpenAiProperties)[]): Subscribe;
9
- getSnapshot: <K extends keyof OpenAiProperties>(key: K) => (import("../types.js").OpenAiMethods<import("../types.js").UnknownObject> & OpenAiProperties<Record<never, unknown>, import("../types.js").UnknownObject, import("../types.js").UnknownObject, import("../types.js").UnknownObject>)[K];
9
+ getSnapshot: <K extends keyof OpenAiProperties>(key: K) => (import("./types.js").OpenAiMethods<import("../../types.js").UnknownObject> & OpenAiProperties<Record<never, unknown>, import("../../types.js").UnknownObject, import("../../types.js").UnknownObject, import("../../types.js").UnknownObject>)[K];
10
10
  }
@@ -1,4 +1,4 @@
1
- import { SET_GLOBALS_EVENT_TYPE, } from "../types.js";
1
+ import { SET_GLOBALS_EVENT_TYPE, } from "./types.js";
2
2
  export class AppsSdkBridge {
3
3
  static instance = null;
4
4
  static getInstance() {
@@ -43,4 +43,4 @@ export class AppsSdkBridge {
43
43
  return window.openai[key];
44
44
  };
45
45
  }
46
- //# sourceMappingURL=apps-sdk-bridge.js.map
46
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,CAAC,WAAW;QACvB,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;YACxC,MAAM,CAAC,MAAM,KAAK,SAAS,EAC3B,CAAC;YACD,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QACJ,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;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.js";
2
+ export { AppsSdkBridge } from "./bridge.js";
3
+ export type { OpenAiMethods, OpenAiProperties, RequestModalOptions, ToolResponseEvent, } from "./types.js";
4
+ export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, TOOL_RESPONSE_EVENT_TYPE, } from "./types.js";
5
+ export { useAppsSdkBridge } from "./use-apps-sdk-bridge.js";
@@ -0,0 +1,5 @@
1
+ export { AppsSdkAdaptor } from "./adaptor.js";
2
+ export { AppsSdkBridge } from "./bridge.js";
3
+ export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, TOOL_RESPONSE_EVENT_TYPE, } from "./types.js";
4
+ export { useAppsSdkBridge } from "./use-apps-sdk-bridge.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,20 +1,6 @@
1
- import "react";
2
- import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
- import type { WidgetHostType } from "../server/index.js";
4
- declare module "react" {
5
- interface HTMLAttributes<T> {
6
- "data-llm"?: string;
7
- }
8
- }
9
- export type UnknownObject = Record<string, unknown>;
10
- export type Prettify<T> = {
11
- [K in keyof T]: T[K];
12
- } & {};
13
- export type Objectify<T> = T & UnknownObject;
14
- type RequiredKeys<T> = {
15
- [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
16
- }[keyof T];
17
- export type HasRequiredKeys<T> = RequiredKeys<T> extends never ? false : true;
1
+ import type { UnknownObject } from "../../types.js";
2
+ import type { CallToolArgs, CallToolResponse } from "../types.js";
3
+ type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
18
4
  type WidgetState = UnknownObject;
19
5
  type FileMetadata = {
20
6
  fileId: string;
@@ -30,16 +16,12 @@ export declare class ToolResponseEvent extends CustomEvent<{
30
16
  }
31
17
  declare global {
32
18
  interface Window {
33
- skybridge: SkybridgeProperties;
34
19
  openai: OpenAiMethods<WidgetState> & OpenAiProperties;
35
20
  }
36
21
  interface WindowEventMap {
37
22
  [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
38
23
  }
39
24
  }
40
- export type SkybridgeProperties = {
41
- hostType: WidgetHostType;
42
- };
43
25
  export type OpenAiProperties<ToolInput extends UnknownObject = Record<never, unknown>, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
44
26
  theme: Theme;
45
27
  userAgent: UserAgent;
@@ -55,14 +37,6 @@ export type OpenAiProperties<ToolInput extends UnknownObject = Record<never, unk
55
37
  toolResponseMetadata: ToolResponseMetadata | null;
56
38
  widgetState: WidgetState | null;
57
39
  };
58
- export type CallToolArgs = Record<string, unknown> | null;
59
- export type CallToolResponse = {
60
- content: CallToolResult["content"];
61
- structuredContent: Record<string, unknown>;
62
- isError: boolean;
63
- result: string;
64
- meta: Record<string, unknown>;
65
- };
66
40
  export type RequestModalOptions = {
67
41
  title?: string;
68
42
  params?: Record<string, unknown>;
@@ -110,7 +84,7 @@ export type OpenAiMethods<WidgetState extends UnknownObject = UnknownObject> = {
110
84
  * Downloads a file from the host that was previously uploaded.
111
85
  * Only files uploaded by the same connector instance can be downloaded.
112
86
  */
113
- downloadFile: (file: FileMetadata) => Promise<{
87
+ getFileDownloadUrl: (file: FileMetadata) => Promise<{
114
88
  downloadUrl: string;
115
89
  }>;
116
90
  };
@@ -120,24 +94,22 @@ export declare class SetGlobalsEvent extends CustomEvent<{
120
94
  }> {
121
95
  readonly type = "openai:set_globals";
122
96
  }
123
- export type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
124
- export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
125
- export type View = {
97
+ type View = {
126
98
  mode: DisplayMode;
127
99
  params?: Record<string, unknown>;
128
100
  };
129
- export type Theme = "light" | "dark";
130
- export type SafeAreaInsets = {
101
+ type Theme = "light" | "dark";
102
+ type SafeAreaInsets = {
131
103
  top: number;
132
104
  bottom: number;
133
105
  left: number;
134
106
  right: number;
135
107
  };
136
- export type SafeArea = {
108
+ type SafeArea = {
137
109
  insets: SafeAreaInsets;
138
110
  };
139
- export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
140
- export type UserAgent = {
111
+ type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
112
+ type UserAgent = {
141
113
  device: {
142
114
  type: DeviceType;
143
115
  };
@@ -1,4 +1,3 @@
1
- import "react";
2
1
  export const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
3
2
  export class ToolResponseEvent extends CustomEvent {
4
3
  type = TOOL_RESPONSE_EVENT_TYPE;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/types.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AAwFD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
@@ -1,2 +1,2 @@
1
- import type { OpenAiProperties } from "../../types.js";
1
+ import type { OpenAiProperties } from "./types.js";
2
2
  export declare function useAppsSdkBridge<K extends keyof OpenAiProperties>(key: K): OpenAiProperties[K];
@@ -1,5 +1,5 @@
1
1
  import { useSyncExternalStore } from "react";
2
- import { AppsSdkBridge } from "../apps-sdk-bridge.js";
2
+ import { AppsSdkBridge } from "./bridge.js";
3
3
  export function useAppsSdkBridge(key) {
4
4
  const bridge = AppsSdkBridge.getInstance();
5
5
  return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-apps-sdk-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/use-apps-sdk-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,UAAU,gBAAgB,CAC9B,GAAM;IAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAC3C,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,2 @@
1
+ import type { Adaptor } from "./types.js";
2
+ export declare const getAdaptor: () => Adaptor;
@@ -0,0 +1,8 @@
1
+ import { AppsSdkAdaptor } from "./apps-sdk/adaptor.js";
2
+ import { McpAppAdaptor } from "./mcp-app/adaptor.js";
3
+ export const getAdaptor = () => {
4
+ return window.skybridge.hostType === "apps-sdk"
5
+ ? AppsSdkAdaptor.getInstance()
6
+ : McpAppAdaptor.getInstance();
7
+ };
8
+ //# sourceMappingURL=get-adaptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-adaptor.js","sourceRoot":"","sources":["../../../src/web/bridges/get-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE;IACtC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE;QAC9B,CAAC,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./apps-sdk/index.js";
2
+ export { getAdaptor } from "./get-adaptor.js";
3
+ export * from "./mcp-app/index.js";
4
+ export * from "./types.js";
5
+ export { useHostContext } from "./use-host-context.js";
@@ -0,0 +1,6 @@
1
+ export * from "./apps-sdk/index.js";
2
+ export { getAdaptor } from "./get-adaptor.js";
3
+ export * from "./mcp-app/index.js";
4
+ export * from "./types.js";
5
+ export { useHostContext } from "./use-host-context.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,16 +1,19 @@
1
1
  import type { McpUiRequestDisplayModeResult } from "@modelcontextprotocol/ext-apps";
2
- import type { Adaptor, BridgeInterface, CallToolResponse, DisplayMode, ExternalStore } from "../types.js";
2
+ import type { Adaptor, CallToolResponse, DisplayMode, HostContext, HostContextStore, SetWidgetStateAction } from "../types.js";
3
3
  export declare class McpAppAdaptor implements Adaptor {
4
4
  private static instance;
5
5
  private stores;
6
+ private _widgetState;
7
+ private widgetStateListeners;
6
8
  private constructor();
7
9
  static getInstance(): McpAppAdaptor;
8
10
  static resetInstance(): void;
9
- getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
11
+ getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
10
12
  callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
11
13
  requestDisplayMode: (mode: DisplayMode) => Promise<McpUiRequestDisplayModeResult>;
12
14
  sendFollowUpMessage: (prompt: string) => Promise<void>;
13
15
  openExternal(href: string): void;
14
16
  private initializeStores;
15
- private createExternalStore;
17
+ setWidgetState: (stateOrUpdater: SetWidgetStateAction) => Promise<void>;
18
+ private createHostContextStore;
16
19
  }
@@ -1,8 +1,10 @@
1
1
  import { dequal } from "dequal/lite";
2
- import { McpAppBridge, } from "../mcp-app-bridge.js";
2
+ import { McpAppBridge } from "./bridge.js";
3
3
  export class McpAppAdaptor {
4
4
  static instance = null;
5
5
  stores;
6
+ _widgetState = null;
7
+ widgetStateListeners = new Set();
6
8
  constructor() {
7
9
  this.stores = this.initializeStores();
8
10
  }
@@ -15,7 +17,7 @@ export class McpAppAdaptor {
15
17
  static resetInstance() {
16
18
  McpAppAdaptor.instance = null;
17
19
  }
18
- getExternalStore(key) {
20
+ getHostContextStore(key) {
19
21
  return this.stores[key];
20
22
  }
21
23
  callTool = async (name, args) => {
@@ -73,14 +75,19 @@ export class McpAppAdaptor {
73
75
  }
74
76
  initializeStores() {
75
77
  return {
76
- theme: this.createExternalStore(["theme"], ({ theme }) => theme ?? "light"),
77
- locale: this.createExternalStore(["locale"], ({ locale }) => locale ?? "en-US"),
78
- safeArea: this.createExternalStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
78
+ theme: this.createHostContextStore(["theme"], ({ theme }) => theme ?? "light"),
79
+ locale: this.createHostContextStore(["locale"], ({ locale }) => locale ?? "en-US"),
80
+ safeArea: this.createHostContextStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
79
81
  insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
80
82
  })),
81
- displayMode: this.createExternalStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
82
- maxHeight: this.createExternalStore(["viewport"], ({ viewport }) => viewport?.maxHeight ?? window.innerHeight),
83
- userAgent: this.createExternalStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
83
+ displayMode: this.createHostContextStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
84
+ maxHeight: this.createHostContextStore(["containerDimensions"], ({ containerDimensions }) => {
85
+ if (containerDimensions && "maxHeight" in containerDimensions) {
86
+ return containerDimensions.maxHeight ?? window.innerHeight;
87
+ }
88
+ return window.innerHeight;
89
+ }),
90
+ userAgent: this.createHostContextStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
84
91
  device: {
85
92
  type: platform === "web" ? "desktop" : (platform ?? "unknown"),
86
93
  },
@@ -90,12 +97,35 @@ export class McpAppAdaptor {
90
97
  ...deviceCapabilities,
91
98
  },
92
99
  })),
93
- toolInput: this.createExternalStore(["toolInput"], ({ toolInput }) => toolInput ?? null),
94
- toolOutput: this.createExternalStore(["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
95
- toolResponseMetadata: this.createExternalStore(["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
100
+ toolInput: this.createHostContextStore(["toolInput"], ({ toolInput }) => toolInput ?? null),
101
+ toolOutput: this.createHostContextStore(["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
102
+ toolResponseMetadata: this.createHostContextStore(["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
103
+ widgetState: {
104
+ subscribe: (onChange) => {
105
+ this.widgetStateListeners.add(onChange);
106
+ return () => {
107
+ this.widgetStateListeners.delete(onChange);
108
+ };
109
+ },
110
+ getSnapshot: () => this._widgetState,
111
+ },
96
112
  };
97
113
  }
98
- createExternalStore(keys, computeSnapshot) {
114
+ setWidgetState = async (stateOrUpdater) => {
115
+ const newState = typeof stateOrUpdater === "function"
116
+ ? stateOrUpdater(this._widgetState)
117
+ : stateOrUpdater;
118
+ const bridge = McpAppBridge.getInstance();
119
+ await bridge.request({
120
+ method: "ui/update-model-context",
121
+ params: { structuredContent: newState },
122
+ });
123
+ this._widgetState = newState;
124
+ this.widgetStateListeners.forEach((listener) => {
125
+ listener();
126
+ });
127
+ };
128
+ createHostContextStore(keys, computeSnapshot) {
99
129
  const bridge = McpAppBridge.getInstance();
100
130
  let cachedValue;
101
131
  return {
@@ -112,4 +142,4 @@ export class McpAppAdaptor {
112
142
  };
113
143
  }
114
144
  }
115
- //# sourceMappingURL=mcp-app-adaptor.js.map
145
+ //# sourceMappingURL=adaptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACM,YAAY,GAA+B,IAAI,CAAC;IAChD,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAErD;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;IAChC,CAAC;IAEM,mBAAmB,CACxB,GAAM;QAEN,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEM,QAAQ,GAAG,KAAK,EAIrB,IAAY,EACZ,IAAc,EACS,EAAE;QACzB,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,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