skybridge 0.0.0-dev.8027fea → 0.0.0-dev.8054fa4

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