skybridge 0.0.0-dev.fbee5d9 → 0.0.0-dev.fc1170f

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 (382) hide show
  1. package/README.md +132 -120
  2. package/dist/cli/build-helpers.d.ts +7 -0
  3. package/dist/cli/build-helpers.js +82 -0
  4. package/dist/cli/build-helpers.js.map +1 -0
  5. package/dist/cli/build-helpers.test.js +64 -0
  6. package/dist/cli/build-helpers.test.js.map +1 -0
  7. package/dist/cli/detect-port.d.ts +2 -2
  8. package/dist/cli/detect-port.js +9 -20
  9. package/dist/cli/detect-port.js.map +1 -1
  10. package/dist/cli/header.js +1 -1
  11. package/dist/cli/header.js.map +1 -1
  12. package/dist/cli/resolve-views-dir.d.ts +1 -0
  13. package/dist/cli/resolve-views-dir.js +17 -0
  14. package/dist/cli/resolve-views-dir.js.map +1 -0
  15. package/dist/cli/run-command.js.map +1 -1
  16. package/dist/cli/telemetry.js.map +1 -1
  17. package/dist/cli/tunnel-control-server.d.ts +9 -0
  18. package/dist/cli/tunnel-control-server.js +31 -0
  19. package/dist/cli/tunnel-control-server.js.map +1 -0
  20. package/dist/cli/tunnel-control-server.test.js +39 -0
  21. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  22. package/dist/cli/tunnel-handler.d.ts +3 -0
  23. package/dist/cli/tunnel-handler.js +48 -0
  24. package/dist/cli/tunnel-handler.js.map +1 -0
  25. package/dist/cli/tunnel-handler.test.js +105 -0
  26. package/dist/cli/tunnel-handler.test.js.map +1 -0
  27. package/dist/cli/tunnel.d.ts +57 -0
  28. package/dist/cli/tunnel.js +154 -0
  29. package/dist/cli/tunnel.js.map +1 -0
  30. package/dist/cli/tunnel.test.d.ts +1 -0
  31. package/dist/cli/tunnel.test.js +190 -0
  32. package/dist/cli/tunnel.test.js.map +1 -0
  33. package/dist/cli/types.d.ts +5 -0
  34. package/dist/cli/types.js +2 -0
  35. package/dist/cli/types.js.map +1 -0
  36. package/dist/cli/use-execute-steps.js.map +1 -1
  37. package/dist/cli/use-messages.d.ts +3 -0
  38. package/dist/cli/use-messages.js +11 -0
  39. package/dist/cli/use-messages.js.map +1 -0
  40. package/dist/cli/use-nodemon.d.ts +2 -7
  41. package/dist/cli/use-nodemon.js +18 -21
  42. package/dist/cli/use-nodemon.js.map +1 -1
  43. package/dist/cli/use-open-browser.d.ts +1 -0
  44. package/dist/cli/use-open-browser.js +44 -0
  45. package/dist/cli/use-open-browser.js.map +1 -0
  46. package/dist/cli/use-tunnel.d.ts +14 -0
  47. package/dist/cli/use-tunnel.js +131 -0
  48. package/dist/cli/use-tunnel.js.map +1 -0
  49. package/dist/cli/use-typescript-check.d.ts +1 -0
  50. package/dist/cli/use-typescript-check.js +42 -7
  51. package/dist/cli/use-typescript-check.js.map +1 -1
  52. package/dist/commands/build.d.ts +0 -1
  53. package/dist/commands/build.js +52 -8
  54. package/dist/commands/build.js.map +1 -1
  55. package/dist/commands/create.d.ts +9 -0
  56. package/dist/commands/create.js +30 -0
  57. package/dist/commands/create.js.map +1 -0
  58. package/dist/commands/dev.d.ts +3 -0
  59. package/dist/commands/dev.js +63 -3
  60. package/dist/commands/dev.js.map +1 -1
  61. package/dist/commands/start.js +13 -10
  62. package/dist/commands/start.js.map +1 -1
  63. package/dist/commands/telemetry/disable.js.map +1 -1
  64. package/dist/commands/telemetry/enable.js.map +1 -1
  65. package/dist/commands/telemetry/status.js.map +1 -1
  66. package/dist/server/asset-base-url-transform-plugin.d.ts +6 -6
  67. package/dist/server/asset-base-url-transform-plugin.js +25 -11
  68. package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
  69. package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
  70. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
  71. package/dist/server/auth/discovery.d.ts +32 -0
  72. package/dist/server/auth/discovery.js +44 -0
  73. package/dist/server/auth/discovery.js.map +1 -0
  74. package/dist/server/auth/discovery.test.d.ts +1 -0
  75. package/dist/server/auth/discovery.test.js +71 -0
  76. package/dist/server/auth/discovery.test.js.map +1 -0
  77. package/dist/server/auth/index.d.ts +18 -0
  78. package/dist/server/auth/index.js +2 -0
  79. package/dist/server/auth/index.js.map +1 -0
  80. package/dist/server/auth/providers/custom.d.ts +12 -0
  81. package/dist/server/auth/providers/custom.js +28 -0
  82. package/dist/server/auth/providers/custom.js.map +1 -0
  83. package/dist/server/auth/providers/custom.test.d.ts +1 -0
  84. package/dist/server/auth/providers/custom.test.js +91 -0
  85. package/dist/server/auth/providers/custom.test.js.map +1 -0
  86. package/dist/server/auth/setup.d.ts +4 -0
  87. package/dist/server/auth/setup.js +51 -0
  88. package/dist/server/auth/setup.js.map +1 -0
  89. package/dist/server/auth/setup.test.d.ts +1 -0
  90. package/dist/server/auth/setup.test.js +185 -0
  91. package/dist/server/auth/setup.test.js.map +1 -0
  92. package/dist/server/auth/verify.d.ts +11 -0
  93. package/dist/server/auth/verify.js +37 -0
  94. package/dist/server/auth/verify.js.map +1 -0
  95. package/dist/server/auth/verify.test.d.ts +1 -0
  96. package/dist/server/auth/verify.test.js +87 -0
  97. package/dist/server/auth/verify.test.js.map +1 -0
  98. package/dist/server/auth.d.ts +20 -0
  99. package/dist/server/auth.js +28 -0
  100. package/dist/server/auth.js.map +1 -0
  101. package/dist/server/build-manifest.test.d.ts +1 -0
  102. package/dist/server/build-manifest.test.js +27 -0
  103. package/dist/server/build-manifest.test.js.map +1 -0
  104. package/dist/server/content-helpers.d.ts +67 -0
  105. package/dist/server/content-helpers.js +79 -0
  106. package/dist/server/content-helpers.js.map +1 -0
  107. package/dist/server/content-helpers.test.d.ts +1 -0
  108. package/dist/server/content-helpers.test.js +70 -0
  109. package/dist/server/content-helpers.test.js.map +1 -0
  110. package/dist/server/express.d.ts +5 -5
  111. package/dist/server/express.js +52 -23
  112. package/dist/server/express.js.map +1 -1
  113. package/dist/server/express.test.js +438 -27
  114. package/dist/server/express.test.js.map +1 -1
  115. package/dist/server/file-ref.d.ts +28 -0
  116. package/dist/server/file-ref.js +27 -0
  117. package/dist/server/file-ref.js.map +1 -0
  118. package/dist/server/index.d.ts +8 -3
  119. package/dist/server/index.js +6 -2
  120. package/dist/server/index.js.map +1 -1
  121. package/dist/server/inferUtilityTypes.d.ts +6 -6
  122. package/dist/server/inferUtilityTypes.js.map +1 -1
  123. package/dist/server/metric.d.ts +14 -0
  124. package/dist/server/metric.js +62 -0
  125. package/dist/server/metric.js.map +1 -0
  126. package/dist/server/middleware.d.ts +16 -3
  127. package/dist/server/middleware.js.map +1 -1
  128. package/dist/server/middleware.test-d.js.map +1 -1
  129. package/dist/server/middleware.test.js +115 -5
  130. package/dist/server/middleware.test.js.map +1 -1
  131. package/dist/server/requestOrigin.d.ts +7 -0
  132. package/dist/server/requestOrigin.js +25 -0
  133. package/dist/server/requestOrigin.js.map +1 -0
  134. package/dist/server/server.d.ts +333 -70
  135. package/dist/server/server.js +482 -140
  136. package/dist/server/server.js.map +1 -1
  137. package/dist/server/templateHelper.d.ts +5 -8
  138. package/dist/server/templateHelper.js +3 -22
  139. package/dist/server/templateHelper.js.map +1 -1
  140. package/dist/server/templates.generated.d.ts +4 -0
  141. package/dist/server/templates.generated.js +47 -0
  142. package/dist/server/templates.generated.js.map +1 -0
  143. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  144. package/dist/server/tunnel-proxy-router.js +110 -0
  145. package/dist/server/tunnel-proxy-router.js.map +1 -0
  146. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  147. package/dist/server/tunnel-proxy-router.test.js +229 -0
  148. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  149. package/dist/server/view-resource-resolution.test.d.ts +6 -0
  150. package/dist/server/view-resource-resolution.test.js +88 -0
  151. package/dist/server/view-resource-resolution.test.js.map +1 -0
  152. package/dist/server/viewsDevServer.d.ts +14 -0
  153. package/dist/server/viewsDevServer.js +45 -0
  154. package/dist/server/viewsDevServer.js.map +1 -0
  155. package/dist/test/utils.d.ts +13 -21
  156. package/dist/test/utils.js +42 -37
  157. package/dist/test/utils.js.map +1 -1
  158. package/dist/test/view.test.d.ts +1 -0
  159. package/dist/test/view.test.js +526 -0
  160. package/dist/test/view.test.js.map +1 -0
  161. package/dist/version.d.ts +1 -0
  162. package/dist/version.js +3 -0
  163. package/dist/version.js.map +1 -0
  164. package/dist/web/bridges/adaptor.d.ts +51 -0
  165. package/dist/web/bridges/adaptor.js +312 -0
  166. package/dist/web/bridges/adaptor.js.map +1 -0
  167. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  168. package/dist/web/bridges/adaptor.test.js +205 -0
  169. package/dist/web/bridges/adaptor.test.js.map +1 -0
  170. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
  171. package/dist/web/bridges/apps-sdk/bridge.js +3 -3
  172. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  173. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  174. package/dist/web/bridges/apps-sdk/index.js +0 -1
  175. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  176. package/dist/web/bridges/apps-sdk/types.d.ts +18 -6
  177. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  178. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  179. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  180. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  181. package/dist/web/bridges/get-adaptor.d.ts +9 -0
  182. package/dist/web/bridges/get-adaptor.js +19 -5
  183. package/dist/web/bridges/get-adaptor.js.map +1 -1
  184. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  185. package/dist/web/bridges/get-adaptor.test.js +32 -0
  186. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  187. package/dist/web/bridges/host-context-stores.d.ts +27 -0
  188. package/dist/web/bridges/host-context-stores.js +73 -0
  189. package/dist/web/bridges/host-context-stores.js.map +1 -0
  190. package/dist/web/bridges/index.js.map +1 -1
  191. package/dist/web/bridges/mcp-app/bridge.d.ts +4 -2
  192. package/dist/web/bridges/mcp-app/bridge.js +23 -4
  193. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  194. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  195. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  196. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  197. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  198. package/dist/web/bridges/mcp-app/index.js +0 -1
  199. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  200. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  201. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
  202. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
  203. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  204. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  205. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  206. package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
  207. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  208. package/dist/web/bridges/types.d.ts +128 -11
  209. package/dist/web/bridges/types.js +14 -1
  210. package/dist/web/bridges/types.js.map +1 -1
  211. package/dist/web/bridges/types.test.d.ts +1 -0
  212. package/dist/web/bridges/types.test.js +19 -0
  213. package/dist/web/bridges/types.test.js.map +1 -0
  214. package/dist/web/bridges/use-host-context.d.ts +5 -0
  215. package/dist/web/bridges/use-host-context.js +5 -0
  216. package/dist/web/bridges/use-host-context.js.map +1 -1
  217. package/dist/web/components/modal-provider.js +5 -6
  218. package/dist/web/components/modal-provider.js.map +1 -1
  219. package/dist/web/create-store.d.ts +26 -0
  220. package/dist/web/create-store.js +43 -3
  221. package/dist/web/create-store.js.map +1 -1
  222. package/dist/web/create-store.test.js +21 -21
  223. package/dist/web/create-store.test.js.map +1 -1
  224. package/dist/web/data-llm.d.ts +34 -1
  225. package/dist/web/data-llm.js +31 -3
  226. package/dist/web/data-llm.js.map +1 -1
  227. package/dist/web/data-llm.test.js +30 -27
  228. package/dist/web/data-llm.test.js.map +1 -1
  229. package/dist/web/generate-helpers.d.ts +22 -18
  230. package/dist/web/generate-helpers.js +22 -18
  231. package/dist/web/generate-helpers.js.map +1 -1
  232. package/dist/web/generate-helpers.test-d.js +30 -28
  233. package/dist/web/generate-helpers.test-d.js.map +1 -1
  234. package/dist/web/generate-helpers.test.js.map +1 -1
  235. package/dist/web/helpers/state.d.ts +2 -2
  236. package/dist/web/helpers/state.js +11 -11
  237. package/dist/web/helpers/state.js.map +1 -1
  238. package/dist/web/helpers/state.test.js +9 -9
  239. package/dist/web/helpers/state.test.js.map +1 -1
  240. package/dist/web/hooks/index.d.ts +5 -1
  241. package/dist/web/hooks/index.js +5 -1
  242. package/dist/web/hooks/index.js.map +1 -1
  243. package/dist/web/hooks/test/utils.d.ts +6 -2
  244. package/dist/web/hooks/test/utils.js +13 -2
  245. package/dist/web/hooks/test/utils.js.map +1 -1
  246. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  247. package/dist/web/hooks/use-call-tool.js +28 -0
  248. package/dist/web/hooks/use-call-tool.js.map +1 -1
  249. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  250. package/dist/web/hooks/use-call-tool.test.js +61 -27
  251. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  252. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  253. package/dist/web/hooks/use-display-mode.js +20 -0
  254. package/dist/web/hooks/use-display-mode.js.map +1 -1
  255. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -1
  256. package/dist/web/hooks/use-display-mode.test.js +55 -20
  257. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  258. package/dist/web/hooks/use-download.d.ts +5 -0
  259. package/dist/web/hooks/use-download.js +8 -0
  260. package/dist/web/hooks/use-download.js.map +1 -0
  261. package/dist/web/hooks/use-download.test.d.ts +1 -0
  262. package/dist/web/hooks/use-download.test.js +103 -0
  263. package/dist/web/hooks/use-download.test.js.map +1 -0
  264. package/dist/web/hooks/use-files.d.ts +34 -1
  265. package/dist/web/hooks/use-files.js +33 -0
  266. package/dist/web/hooks/use-files.js.map +1 -1
  267. package/dist/web/hooks/use-files.test.js +30 -2
  268. package/dist/web/hooks/use-files.test.js.map +1 -1
  269. package/dist/web/hooks/use-layout.d.ts +2 -0
  270. package/dist/web/hooks/use-layout.js +2 -0
  271. package/dist/web/hooks/use-layout.js.map +1 -1
  272. package/dist/web/hooks/use-layout.test.js +59 -26
  273. package/dist/web/hooks/use-layout.test.js.map +1 -1
  274. package/dist/web/hooks/use-open-external.d.ts +17 -0
  275. package/dist/web/hooks/use-open-external.js +16 -0
  276. package/dist/web/hooks/use-open-external.js.map +1 -1
  277. package/dist/web/hooks/use-open-external.test.js +19 -5
  278. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  279. package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
  280. package/dist/web/hooks/use-register-view-tool.js +50 -0
  281. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  282. package/dist/web/hooks/use-request-close.d.ts +16 -0
  283. package/dist/web/hooks/use-request-close.js +21 -0
  284. package/dist/web/hooks/use-request-close.js.map +1 -0
  285. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  286. package/dist/web/hooks/use-request-close.test.js +46 -0
  287. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  288. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  289. package/dist/web/hooks/use-request-modal.js +19 -4
  290. package/dist/web/hooks/use-request-modal.js.map +1 -1
  291. package/dist/web/hooks/use-request-modal.test.js +15 -1
  292. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  293. package/dist/web/hooks/use-request-size.d.ts +20 -0
  294. package/dist/web/hooks/use-request-size.js +24 -0
  295. package/dist/web/hooks/use-request-size.js.map +1 -0
  296. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  297. package/dist/web/hooks/use-request-size.test.js +47 -0
  298. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  299. package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
  300. package/dist/web/hooks/use-send-follow-up-message.js +19 -2
  301. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  302. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  303. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  304. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  305. package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
  306. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  307. package/dist/web/hooks/use-tool-info.d.ts +53 -2
  308. package/dist/web/hooks/use-tool-info.js +30 -7
  309. package/dist/web/hooks/use-tool-info.js.map +1 -1
  310. package/dist/web/hooks/use-tool-info.test-d.js +11 -29
  311. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  312. package/dist/web/hooks/use-tool-info.test.js +42 -32
  313. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  314. package/dist/web/hooks/use-user.d.ts +2 -0
  315. package/dist/web/hooks/use-user.js +20 -2
  316. package/dist/web/hooks/use-user.js.map +1 -1
  317. package/dist/web/hooks/use-user.test.js +100 -26
  318. package/dist/web/hooks/use-user.test.js.map +1 -1
  319. package/dist/web/hooks/use-view-state.d.ts +25 -0
  320. package/dist/web/hooks/use-view-state.js +32 -0
  321. package/dist/web/hooks/use-view-state.js.map +1 -0
  322. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  323. package/dist/web/hooks/use-view-state.test.js +181 -0
  324. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  325. package/dist/web/index.d.ts +1 -2
  326. package/dist/web/index.js +1 -2
  327. package/dist/web/index.js.map +1 -1
  328. package/dist/web/mount-view.d.ts +20 -0
  329. package/dist/web/{mount-widget.js → mount-view.js} +21 -2
  330. package/dist/web/mount-view.js.map +1 -0
  331. package/dist/web/plugin/data-llm.test.js.map +1 -1
  332. package/dist/web/plugin/plugin.d.ts +32 -1
  333. package/dist/web/plugin/plugin.js +160 -25
  334. package/dist/web/plugin/plugin.js.map +1 -1
  335. package/dist/web/plugin/scan-views.d.ts +16 -0
  336. package/dist/web/plugin/scan-views.js +88 -0
  337. package/dist/web/plugin/scan-views.js.map +1 -0
  338. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  339. package/dist/web/plugin/scan-views.test.js +99 -0
  340. package/dist/web/plugin/scan-views.test.js.map +1 -0
  341. package/dist/web/plugin/transform-data-llm.js +1 -1
  342. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  343. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  344. package/dist/web/plugin/validate-view.d.ts +1 -0
  345. package/dist/web/plugin/validate-view.js +9 -0
  346. package/dist/web/plugin/validate-view.js.map +1 -0
  347. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  348. package/dist/web/plugin/validate-view.test.js +24 -0
  349. package/dist/web/plugin/validate-view.test.js.map +1 -0
  350. package/dist/web/proxy.js.map +1 -1
  351. package/dist/web/types.d.ts +4 -0
  352. package/dist/web/types.js.map +1 -1
  353. package/package.json +36 -19
  354. package/tsconfig.base.json +5 -0
  355. package/dist/server/templates/development.hbs +0 -67
  356. package/dist/server/templates/production.hbs +0 -6
  357. package/dist/server/widgetsDevServer.d.ts +0 -13
  358. package/dist/server/widgetsDevServer.js +0 -57
  359. package/dist/server/widgetsDevServer.js.map +0 -1
  360. package/dist/test/widget.test.js +0 -263
  361. package/dist/test/widget.test.js.map +0 -1
  362. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -22
  363. package/dist/web/bridges/apps-sdk/adaptor.js +0 -75
  364. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  365. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -38
  366. package/dist/web/bridges/mcp-app/adaptor.js +0 -184
  367. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  368. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  369. package/dist/web/hooks/use-widget-state.js +0 -32
  370. package/dist/web/hooks/use-widget-state.js.map +0 -1
  371. package/dist/web/hooks/use-widget-state.test.js +0 -64
  372. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  373. package/dist/web/mount-widget.d.ts +0 -1
  374. package/dist/web/mount-widget.js.map +0 -1
  375. package/dist/web/plugin/validate-widget.d.ts +0 -5
  376. package/dist/web/plugin/validate-widget.js +0 -27
  377. package/dist/web/plugin/validate-widget.js.map +0 -1
  378. package/dist/web/plugin/validate-widget.test.js +0 -42
  379. package/dist/web/plugin/validate-widget.test.js.map +0 -1
  380. /package/dist/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  381. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  382. /package/dist/{web/plugin/validate-widget.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
@@ -2,10 +2,15 @@ import crypto from "node:crypto";
2
2
  import { readFileSync } from "node:fs";
3
3
  import http from "node:http";
4
4
  import path from "node:path";
5
- import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js";
6
+ import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
6
7
  import { mergeWith, union } from "es-toolkit";
7
- import { createServer } from "./express.js";
8
+ import express, {} from "express";
9
+ import { setupOAuth } from "./auth/setup.js";
10
+ import { createApp } from "./express.js";
11
+ import { createMiddlewareEntry } from "./metric.js";
8
12
  import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
13
+ import { resolveServerOrigin } from "./requestOrigin.js";
9
14
  import { templateHelper } from "./templateHelper.js";
10
15
  const mergeWithUnion = (target, source) => {
11
16
  return mergeWith(target, source, (targetVal, sourceVal) => {
@@ -14,20 +19,146 @@ const mergeWithUnion = (target, source) => {
14
19
  }
15
20
  });
16
21
  };
17
- export class McpServer extends McpServerBase {
22
+ /**
23
+ * Drop the query string from a `ui://` view URI, leaving the bare path. The
24
+ * `?v=` cache key is the only query we append, so a plain split is enough and
25
+ * sidesteps `URL` normalization quirks on the non-special `ui:` scheme.
26
+ */
27
+ function stripQuery(uri) {
28
+ const queryIndex = uri.indexOf("?");
29
+ return queryIndex === -1 ? uri : uri.slice(0, queryIndex);
30
+ }
31
+ /**
32
+ * Coerce a tool handler's return value into an MCP `content` array. Strings
33
+ * become a single `TextContent`; a single block is wrapped in an array;
34
+ * `undefined` produces `[]`. Mostly used internally — exported so consumers
35
+ * who build content lazily can apply the same normalization.
36
+ */
37
+ export function normalizeContent(content) {
38
+ if (content === undefined) {
39
+ return [];
40
+ }
41
+ if (typeof content === "string") {
42
+ return [{ type: "text", text: content }];
43
+ }
44
+ if (Array.isArray(content)) {
45
+ return content;
46
+ }
47
+ return [content];
48
+ }
49
+ const McpServerBaseOmitted = McpServerBase;
50
+ /**
51
+ * The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
52
+ * registry, view resources, an embedded Express app, and protocol-level
53
+ * middleware. Construct it with the same `Implementation` info you would pass
54
+ * to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
55
+ * then call {@link McpServer.run} to start the HTTP server.
56
+ *
57
+ * The `TTools` generic accumulates each registered tool's input/output/meta
58
+ * shape, so `typeof server` carries enough information for view-side helpers
59
+ * like {@link generateHelpers} to produce fully-typed hooks.
60
+ *
61
+ * @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
62
+ * chaining; you almost never set this manually.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
67
+ * .registerTool({
68
+ * name: "search",
69
+ * inputSchema: { query: z.string() },
70
+ * view: { component: "search" },
71
+ * }, async ({ query }) => ({ content: `Results for ${query}` }));
72
+ *
73
+ * await server.run();
74
+ * export type AppType = typeof server;
75
+ * ```
76
+ *
77
+ * @see https://docs.skybridge.tech/api-reference/mcp-server
78
+ */
79
+ // Side channel populated by `dist/__entry.js` before user code is imported.
80
+ // Set at module scope rather than passed through the constructor because the
81
+ // wrapper has the manifest before the user's `new McpServer(...)` runs, and
82
+ // threading it through every call site (including user templates) is exactly
83
+ // the boilerplate this design is trying to hide.
84
+ let pendingBuildManifest = null;
85
+ /**
86
+ * Prime the build-time Vite manifest before user code constructs its
87
+ * `McpServer`. Called from the generated `dist/__entry.js`; not part of the
88
+ * user-facing API.
89
+ *
90
+ * @internal
91
+ */
92
+ export function __setBuildManifest(manifest) {
93
+ pendingBuildManifest = manifest;
94
+ }
95
+ export class McpServer extends McpServerBaseOmitted {
96
+ /**
97
+ * The underlying Express app. Use this to extend the HTTP server with
98
+ * custom routes, middleware, or settings — e.g.
99
+ * `server.express.get("/health", ...)`.
100
+ *
101
+ * `express.json()` is pre-applied — tune it via the constructor's third
102
+ * argument, e.g. `new McpServer(info, {}, { json: { limit: "10mb" } })`.
103
+ * Register your handlers before `run()`;
104
+ * after `run()`, dev-mode middleware, the `/mcp` route, and the default
105
+ * error handler are appended in that order.
106
+ *
107
+ * Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
108
+ * locally and on self-hosted deployments.
109
+ */
18
110
  express;
19
- customMiddleware = [];
111
+ customErrorMiddleware = [];
20
112
  mcpMiddlewareEntries = [];
21
113
  mcpMiddlewareApplied = false;
114
+ claimedViews = new Map();
115
+ viewMetaBuilders = new Map();
116
+ /**
117
+ * Maps a view resource's query-less path to its canonical registered URI
118
+ * (the one carrying the `?v=` cache key). Lets `resources/read` resolve the
119
+ * underlying view no matter which version param the consumer sends, since
120
+ * the param is only a cache key, not part of the resource's identity.
121
+ */
122
+ viewUriByPath = new Map();
123
+ viteManifest = null;
124
+ serverInfo;
125
+ serverOptions;
126
+ constructor(serverInfo, options, skybridgeOptions) {
127
+ super(serverInfo, options);
128
+ this.serverInfo = serverInfo;
129
+ this.serverOptions = options;
130
+ this.express = express();
131
+ this.express.use(express.json(skybridgeOptions?.json));
132
+ if (skybridgeOptions?.oauth) {
133
+ setupOAuth(this.express, skybridgeOptions.oauth);
134
+ }
135
+ // Pick up the manifest if `dist/__entry.js` primed it before importing
136
+ // user code. Consume-once: clear after the first construction so a
137
+ // subsequent test that doesn't prime can't inherit stale state.
138
+ // Explicit `setViteManifest` calls still win because they happen after
139
+ // construction.
140
+ if (pendingBuildManifest) {
141
+ this.setViteManifest(pendingBuildManifest);
142
+ pendingBuildManifest = null;
143
+ }
144
+ }
22
145
  use(pathOrHandler, ...handlers) {
146
+ // Branching is load-bearing: Express's `app.use` overloads can't be
147
+ // resolved against a `string | RequestHandler` union, so we narrow.
23
148
  if (typeof pathOrHandler === "string") {
24
- this.customMiddleware.push({
25
- path: pathOrHandler,
26
- handlers,
27
- });
149
+ this.express.use(pathOrHandler, ...handlers);
28
150
  }
29
151
  else {
30
- this.customMiddleware.push({
152
+ this.express.use(pathOrHandler, ...handlers);
153
+ }
154
+ return this;
155
+ }
156
+ useOnError(pathOrHandler, ...handlers) {
157
+ if (typeof pathOrHandler === "string") {
158
+ this.customErrorMiddleware.push({ path: pathOrHandler, handlers });
159
+ }
160
+ else {
161
+ this.customErrorMiddleware.push({
31
162
  handlers: [pathOrHandler, ...handlers],
32
163
  });
33
164
  }
@@ -62,12 +193,73 @@ export class McpServer extends McpServerBase {
62
193
  return;
63
194
  }
64
195
  this.mcpMiddlewareApplied = true;
65
- if (this.mcpMiddlewareEntries.length === 0) {
196
+ // Surface view-resource _meta on `resources/list` (per ext-apps spec:
197
+ // hosts/checkers read CSP & domain at list time before fetching content).
198
+ const viewListMetaEntry = {
199
+ filter: "resources/list",
200
+ handler: async (_req, extra, next) => {
201
+ const result = (await next());
202
+ for (const resource of result.resources) {
203
+ const builder = this.viewMetaBuilders.get(resource.uri);
204
+ if (!builder) {
205
+ continue;
206
+ }
207
+ const meta = builder(extra);
208
+ resource._meta = {
209
+ ...(resource._meta ?? {}),
210
+ ...meta,
211
+ };
212
+ }
213
+ return result;
214
+ },
215
+ };
216
+ // Resolve a view's `resources/read` by its query-less path so the
217
+ // underlying asset is served no matter the `?v=` value (stale cache key,
218
+ // no param, etc.). The version param is a cache-busting hint for external
219
+ // consumers; it must not gate resolution. We rewrite the lookup URI to the
220
+ // canonical registered one, then restore the requested URI on the response
221
+ // so the consumer-facing URI is never rewritten.
222
+ const viewReadResolveEntry = {
223
+ filter: "resources/read",
224
+ handler: async (req, _extra, next) => {
225
+ const requested = req.params.uri;
226
+ if (typeof requested !== "string") {
227
+ return next();
228
+ }
229
+ const path = stripQuery(requested);
230
+ const canonical = this.viewUriByPath.get(path);
231
+ if (!canonical) {
232
+ return next();
233
+ }
234
+ req.params.uri = canonical;
235
+ try {
236
+ const result = (await next());
237
+ for (const content of result.contents ?? []) {
238
+ if (typeof content.uri === "string" &&
239
+ stripQuery(content.uri) === path) {
240
+ content.uri = requested;
241
+ }
242
+ }
243
+ return result;
244
+ }
245
+ finally {
246
+ // Restore the shared request params so middleware outer to us never
247
+ // observes the rewritten lookup URI after next() unwinds.
248
+ req.params.uri = requested;
249
+ }
250
+ },
251
+ };
252
+ const monitoringEntry = createMiddlewareEntry();
253
+ const entries = [
254
+ ...(monitoringEntry ? [monitoringEntry] : []),
255
+ viewListMetaEntry,
256
+ viewReadResolveEntry,
257
+ ...this.mcpMiddlewareEntries,
258
+ ];
259
+ if (entries.length === 0) {
66
260
  return;
67
261
  }
68
262
  const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
69
- const entries = this.mcpMiddlewareEntries;
70
- // Wrap existing handlers and proxy future .set() for lazy SDK registration
71
263
  const instrumentMap = (map, isNotification) => {
72
264
  for (const [method, handler] of map) {
73
265
  map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
@@ -78,180 +270,330 @@ export class McpServer extends McpServerBase {
78
270
  instrumentMap(requestHandlers, false);
79
271
  instrumentMap(notificationHandlers, true);
80
272
  }
273
+ /**
274
+ * Connect to an MCP transport (override of the SDK's `connect`). Use this
275
+ * when you're embedding Skybridge in a host that already manages its own
276
+ * transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
277
+ * which sets the transport up for you. Locks in any middleware registered
278
+ * via {@link McpServer.mcpMiddleware} — further calls to that method will
279
+ * throw afterwards.
280
+ */
81
281
  async connect(transport) {
82
282
  this.applyMcpMiddleware();
83
- return super.connect(transport);
283
+ return McpServerBase.prototype.connect.call(this, transport);
284
+ }
285
+ /**
286
+ * Per-request stateless connect. The SDK's `Protocol` only allows one
287
+ * transport per instance, so we can't reuse this `McpServer` across
288
+ * concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
289
+ * factory, but that would break Skybridge's singleton API — so instead
290
+ * we build a fresh underlying `Server` per request and share the main
291
+ * server's handler maps by reference. The cast is unavoidable: there's
292
+ * no public API to inject handler maps. `getHandlerMaps` validates the
293
+ * read side and fails fast on SDK field renames.
294
+ */
295
+ async connectStatelessTransport(transport) {
296
+ this.applyMcpMiddleware();
297
+ const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
298
+ const fresh = new SdkServer(this.serverInfo, this.serverOptions);
299
+ const target = fresh;
300
+ target._requestHandlers = requestHandlers;
301
+ target._notificationHandlers = notificationHandlers;
302
+ await fresh.connect(transport);
84
303
  }
304
+ /**
305
+ * Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
306
+ * mounts the `/mcp` route, applies any custom Express middleware registered
307
+ * via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
308
+ * any MCP middleware registered via {@link McpServer.mcpMiddleware}.
309
+ *
310
+ * On Cloudflare Workers / workerd, returns an object exposing `fetch` so
311
+ * the runtime can bridge incoming requests to the Node HTTP server. On
312
+ * Vercel (`VERCEL === "1"`), returns the Express app directly so the
313
+ * serverless function entry can call it as a `(req, res)` handler. On
314
+ * Node, returns `undefined` once listening.
315
+ */
85
316
  async run() {
86
317
  this.applyMcpMiddleware();
87
- const httpServer = http.createServer();
88
- if (!this.express) {
89
- this.express = await createServer({
90
- server: this,
318
+ if (process.env.VERCEL === "1") {
319
+ // createApp only reads httpServer inside its dev-only branch
320
+ // (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
321
+ // bare object passed to satisfy the required parameter.
322
+ const httpServer = http.createServer();
323
+ await createApp({
324
+ mcpServer: this,
91
325
  httpServer,
92
- customMiddleware: this.customMiddleware,
326
+ errorMiddleware: this.customErrorMiddleware,
93
327
  });
328
+ return this.express;
94
329
  }
330
+ const httpServer = http.createServer();
331
+ await createApp({
332
+ mcpServer: this,
333
+ httpServer,
334
+ errorMiddleware: this.customErrorMiddleware,
335
+ });
95
336
  httpServer.on("request", this.express);
96
- return new Promise((resolve, reject) => {
337
+ const port = parseInt(process.env.__PORT ?? "3000", 10);
338
+ await new Promise((resolve, reject) => {
97
339
  httpServer.on("error", (error) => {
98
340
  console.error("Failed to start server:", error);
99
341
  reject(error);
100
342
  });
101
- const port = parseInt(process.env.__PORT ?? "3000", 10);
102
343
  httpServer.listen(port, () => {
103
344
  resolve();
104
345
  });
105
346
  });
347
+ // On workerd, bridge the Node http server to a Workers fetch handler.
348
+ // The specifier is held in a variable to sidestep tsc's module resolution
349
+ // (`cloudflare:node` only exists under wrangler/workerd).
350
+ if (typeof navigator !== "undefined" &&
351
+ navigator.userAgent === "Cloudflare-Workers") {
352
+ const cloudflareNode = "cloudflare:node";
353
+ const { httpServerHandler } = await import(cloudflareNode);
354
+ return httpServerHandler({ port });
355
+ }
356
+ const shutdown = () => {
357
+ // Drop both handlers so a second signal falls through to Node's default
358
+ // (force-quit on a second Ctrl+C while drain is hanging).
359
+ process.off("SIGTERM", shutdown);
360
+ process.off("SIGINT", shutdown);
361
+ httpServer.close(() => process.exit(0));
362
+ // Force exit if connections don't drain in time so the port is still
363
+ // released promptly (e.g. for nodemon restarts).
364
+ setTimeout(() => process.exit(0), 3000).unref();
365
+ };
366
+ process.on("SIGTERM", shutdown);
367
+ process.on("SIGINT", shutdown);
368
+ return undefined;
106
369
  }
107
- registerWidget(name, resourceConfig, toolConfig, toolCallback) {
108
- const userMeta = resourceConfig._meta;
109
- const toolMeta = {
110
- ...toolConfig._meta,
370
+ enforceOneToolPerView(component, toolName) {
371
+ const existingTool = this.claimedViews.get(component);
372
+ if (existingTool) {
373
+ throw new Error(`skybridge: view "${component}" is already used by tool "${existingTool}". Tool "${toolName}" cannot also reference it — each view backs exactly one tool.`);
374
+ }
375
+ this.claimedViews.set(component, toolName);
376
+ }
377
+ resolveViewRequestContext(extra) {
378
+ const isProduction = process.env.NODE_ENV === "production";
379
+ const headers = extra?.requestInfo?.headers || {};
380
+ const header = (key) => {
381
+ const val = headers[key];
382
+ return Array.isArray(val) ? val[0] : val;
111
383
  };
112
- if (!resourceConfig.hosts || resourceConfig.hosts.includes("apps-sdk")) {
113
- const widgetConfig = {
114
- hostType: "apps-sdk",
115
- uri: `ui://widgets/apps-sdk/${name}.html`,
116
- mimeType: "text/html+skybridge",
117
- buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
118
- const userUi = userMeta?.ui;
119
- const userCsp = userUi?.csp;
120
- const defaults = {
121
- "openai/widgetCSP": {
122
- resource_domains: resourceDomains,
123
- connect_domains: connectDomains,
124
- },
125
- "openai/widgetDomain": domain,
126
- "openai/widgetDescription": resourceConfig.description,
127
- };
128
- const fromUi = {
129
- "openai/widgetCSP": {
130
- resource_domains: userCsp?.resourceDomains,
131
- connect_domains: userCsp?.connectDomains,
132
- frame_domains: userCsp?.frameDomains,
133
- redirect_domains: userCsp?.redirectDomains,
134
- },
135
- "openai/widgetDomain": userUi?.domain,
136
- "openai/widgetPrefersBorder": userUi?.prefersBorder,
137
- };
138
- const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
139
- return mergeWithUnion(mergeWithUnion(mergeWithUnion(defaults, fromUi), directOpenaiKeys), { "openai/widgetDomain": overrides.domain });
140
- },
141
- };
142
- this.registerWidgetResource({
143
- name,
144
- widgetConfig,
145
- resourceConfig,
146
- });
147
- toolMeta["openai/outputTemplate"] = widgetConfig.uri;
384
+ const isClaude = header("user-agent") === "Claude-User";
385
+ const serverUrl = resolveServerOrigin(header);
386
+ const connectDomains = [serverUrl];
387
+ if (!isProduction) {
388
+ const wsUrl = new URL(serverUrl);
389
+ wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
390
+ connectDomains.push(wsUrl.origin);
148
391
  }
149
- if (!resourceConfig.hosts || resourceConfig.hosts.includes("mcp-app")) {
150
- const widgetConfig = {
151
- hostType: "mcp-app",
152
- uri: `ui://widgets/ext-apps/${name}.html`,
153
- mimeType: "text/html;profile=mcp-app",
154
- buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
155
- const defaults = {
156
- ui: {
157
- csp: {
158
- resourceDomains,
159
- connectDomains,
160
- },
161
- domain,
162
- },
163
- };
164
- return mergeWithUnion(defaults, {
165
- ui: { ...userMeta?.ui, ...overrides },
166
- });
167
- },
168
- };
169
- this.registerWidgetResource({
170
- name,
171
- widgetConfig,
172
- resourceConfig,
173
- });
174
- // @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
175
- toolMeta["ui/resourceUri"] = widgetConfig.uri;
176
- toolMeta.ui = { resourceUri: widgetConfig.uri };
392
+ let contentMetaOverrides = {};
393
+ if (isClaude) {
394
+ const pathname = extra?.requestInfo?.url?.pathname ?? "";
395
+ const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
396
+ // Strip a lone trailing slash so the hash matches the connector URL
397
+ // as registered with Claude (which has no trailing slash on bare origins).
398
+ const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
399
+ const hash = crypto
400
+ .createHash("sha256")
401
+ .update(url)
402
+ .digest("hex")
403
+ .slice(0, 32);
404
+ contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
177
405
  }
178
- this.registerTool(name, {
179
- ...toolConfig,
180
- _meta: toolMeta,
181
- }, toolCallback);
182
- return this;
406
+ return { serverUrl, connectDomains, contentMetaOverrides };
183
407
  }
184
- registerTool(name, config, cb) {
185
- super.registerTool(name, config, cb);
186
- return this;
408
+ registerViewResources(toolName, view, toolMeta) {
409
+ // `hosts` is deprecated and ignored — every view emits the single ext-apps
410
+ // resource. Kept for backwards compatibility; see ViewConfig.hosts.
411
+ // Append a content-derived version param so hosts (e.g. ChatGPT) bust
412
+ // their cache when the bundle changes, but keep the URI stable across
413
+ // `tools/list` calls when the bundle hasn't changed.
414
+ const versionParam = this.computeViewVersionParam(view.component);
415
+ const viewResource = {
416
+ hostType: "mcp-app",
417
+ uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
418
+ mimeType: "text/html;profile=mcp-app",
419
+ buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
420
+ const defaults = {
421
+ ui: {
422
+ csp: {
423
+ resourceDomains,
424
+ connectDomains,
425
+ baseUriDomains,
426
+ },
427
+ domain,
428
+ },
429
+ };
430
+ const fromView = {
431
+ ui: {
432
+ ...(view.description && { description: view.description }),
433
+ ...(view.prefersBorder !== undefined && {
434
+ prefersBorder: view.prefersBorder,
435
+ }),
436
+ ...(view.domain && { domain: view.domain }),
437
+ csp: {
438
+ ...(view.csp?.resourceDomains && {
439
+ resourceDomains: view.csp.resourceDomains,
440
+ }),
441
+ ...(view.csp?.connectDomains && {
442
+ connectDomains: view.csp.connectDomains,
443
+ }),
444
+ ...(view.csp?.frameDomains && {
445
+ frameDomains: view.csp.frameDomains,
446
+ }),
447
+ ...(view.csp?.baseUriDomains && {
448
+ baseUriDomains: view.csp.baseUriDomains,
449
+ }),
450
+ ...(view.csp?.redirectDomains && {
451
+ redirectDomains: view.csp.redirectDomains,
452
+ }),
453
+ },
454
+ },
455
+ };
456
+ const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
457
+ ui: overrides,
458
+ });
459
+ if (view._meta) {
460
+ return { ...base, ...view._meta };
461
+ }
462
+ return base;
463
+ },
464
+ };
465
+ this.registerViewResource({ name: toolName, viewResource, view });
466
+ // Advertise the single resource through all three known pointers so both
467
+ // ext-apps hosts (ui.resourceUri) and ChatGPT (openai/outputTemplate) resolve it.
468
+ toolMeta["openai/outputTemplate"] = viewResource.uri;
469
+ // @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
470
+ toolMeta["ui/resourceUri"] = viewResource.uri;
471
+ toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
187
472
  }
188
- registerWidgetResource({ name, widgetConfig, resourceConfig, }) {
189
- const { hostType, uri: widgetUri, mimeType, buildContentMeta, } = widgetConfig;
190
- this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceConfig._meta }, async (uri, extra) => {
473
+ registerViewResource({ name, viewResource, view, }) {
474
+ const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
475
+ const buildMeta = (extra) => {
476
+ const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
477
+ return buildContentMeta({
478
+ resourceDomains: [serverUrl],
479
+ connectDomains,
480
+ domain: serverUrl,
481
+ baseUriDomains: [serverUrl],
482
+ }, contentMetaOverrides);
483
+ };
484
+ this.viewMetaBuilders.set(viewUri, buildMeta);
485
+ this.viewUriByPath.set(stripQuery(viewUri), viewUri);
486
+ this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
191
487
  const isProduction = process.env.NODE_ENV === "production";
192
- const isClaude = extra?.requestInfo?.headers?.["user-agent"] === "Claude-User";
193
- const forwardedHost = extra?.requestInfo?.headers?.["x-forwarded-host"];
194
- const forwardedProto = extra?.requestInfo?.headers?.["x-forwarded-proto"] ?? "https";
195
- const hostFromHeaders = forwardedHost ?? extra?.requestInfo?.headers?.host;
196
- const useExternalHost = isProduction || isClaude || forwardedHost != null;
197
- const devPort = process.env.__PORT || "3000";
198
- const serverUrl = useExternalHost
199
- ? `${forwardedProto}://${hostFromHeaders}`
200
- : `http://localhost:${devPort}`;
488
+ const { serverUrl } = this.resolveViewRequestContext(extra);
201
489
  const html = isProduction
202
490
  ? templateHelper.renderProduction({
203
491
  hostType,
204
492
  serverUrl,
205
- widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
206
- styleFile: this.lookupDistFile("style.css"),
493
+ viewFile: this.lookupViewFile(view.component),
494
+ styleFile: this.lookupDistFile("style.css") ?? "",
207
495
  })
208
496
  : templateHelper.renderDevelopment({
209
497
  hostType,
210
498
  serverUrl,
211
- useLocalNetworkAccess: !useExternalHost,
212
- widgetName: name,
499
+ viewName: view.component,
213
500
  });
214
- const connectDomains = [serverUrl];
215
- if (!isProduction) {
216
- connectDomains.push(serverUrl.replace(/^http/, "ws"));
217
- }
218
- const pathname = extra?.requestInfo?.url?.pathname ?? "";
219
- const url = `https://${hostFromHeaders}${pathname}`;
220
- const hash = crypto
221
- .createHash("sha256")
222
- .update(url)
223
- .digest("hex")
224
- .slice(0, 32);
225
- const contentMetaOverrides = isClaude
226
- ? {
227
- domain: `${hash}.claudemcpcontent.com`,
228
- }
229
- : {};
230
- const contentMeta = buildContentMeta({
231
- resourceDomains: [serverUrl],
232
- connectDomains,
233
- domain: serverUrl,
234
- baseUriDomains: [serverUrl],
235
- }, contentMetaOverrides);
236
501
  return {
237
502
  contents: [
238
- { uri: uri.href, mimeType, text: html, _meta: contentMeta },
503
+ { uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
239
504
  ],
240
505
  };
241
506
  });
242
507
  }
508
+ wrapHandler(cb, { attachViewUUID }) {
509
+ return async (args, extra) => {
510
+ const result = await cb(args, extra);
511
+ return {
512
+ ...result,
513
+ content: normalizeContent(result.content),
514
+ ...(attachViewUUID && {
515
+ _meta: {
516
+ ...result._meta,
517
+ viewUUID: crypto.randomUUID(),
518
+ },
519
+ }),
520
+ };
521
+ };
522
+ }
523
+ computeViewVersionParam(viewName) {
524
+ if (process.env.NODE_ENV !== "production") {
525
+ return "";
526
+ }
527
+ try {
528
+ const viewFile = this.lookupViewFile(viewName);
529
+ const styleFile = this.lookupDistFile("style.css") ?? "";
530
+ const hash = crypto
531
+ .createHash("sha256")
532
+ .update(viewFile)
533
+ .update("\0")
534
+ .update(styleFile)
535
+ .digest("hex")
536
+ .slice(0, 8);
537
+ return `?v=${hash}`;
538
+ }
539
+ catch {
540
+ return "";
541
+ }
542
+ }
543
+ lookupViewFile(viewName) {
544
+ const manifest = this.readManifest();
545
+ for (const entry of Object.values(manifest)) {
546
+ if (entry?.isEntry && entry.name === viewName && entry.file) {
547
+ return entry.file;
548
+ }
549
+ }
550
+ throw new Error(`View "${viewName}" not found in Vite manifest. Did the build complete successfully? Look for an entry with name "${viewName}" in dist/assets/.vite/manifest.json.`);
551
+ }
243
552
  lookupDistFile(key) {
244
553
  const manifest = this.readManifest();
245
554
  return manifest[key]?.file;
246
555
  }
247
- lookupDistFileWithIndexFallback(basePath) {
248
- const manifest = this.readManifest();
249
- const flatFileKey = `${basePath}.tsx`;
250
- const indexFileKey = `${basePath}/index.tsx`;
251
- return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
556
+ /**
557
+ * Inject the Vite manifest as a value rather than letting `readManifest()`
558
+ * load it from disk. Required for runtimes without a usable filesystem
559
+ * (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
560
+ * manifest as a JS module which the entry imports and passes here.
561
+ */
562
+ setViteManifest(manifest) {
563
+ this.viteManifest = manifest;
564
+ return this;
252
565
  }
253
566
  readManifest() {
567
+ if (this.viteManifest) {
568
+ return this.viteManifest;
569
+ }
254
570
  return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
255
571
  }
572
+ registerTool(...args) {
573
+ const baseFn = McpServerBase.prototype.registerTool;
574
+ if (typeof args[0] === "string") {
575
+ baseFn.call(this, args[0], args[1], args[2]);
576
+ return this;
577
+ }
578
+ const config = args[0];
579
+ const cb = args[1];
580
+ const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
581
+ const toolMeta = { ...userToolMeta };
582
+ if (securitySchemes) {
583
+ // SEP-1488 puts `securitySchemes` at the top level of the tool
584
+ // descriptor, but the SDK's `registerTool` drops unknown top-level
585
+ // fields, so the canonical spot isn't reachable without intercepting
586
+ // `tools/list`. Use the `_meta` back-compat mirror documented in the
587
+ // Apps SDK reference until SEP-1488 lands in the spec.
588
+ toolMeta.securitySchemes = securitySchemes;
589
+ }
590
+ if (view) {
591
+ this.enforceOneToolPerView(view.component, name);
592
+ this.registerViewResources(name, view, toolMeta);
593
+ }
594
+ const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });
595
+ baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
596
+ return this;
597
+ }
256
598
  }
257
599
  //# sourceMappingURL=server.js.map