skybridge 0.0.0-dev.ead707a → 0.0.0-dev.eaed8a9

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