skybridge 0.0.0-dev.f5759ba → 0.0.0-dev.f58ff90

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 (662) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +155 -0
  3. package/bin/run.js +5 -0
  4. package/dist/cli/build-helpers.d.ts +11 -0
  5. package/dist/cli/build-helpers.js +115 -0
  6. package/dist/cli/build-helpers.js.map +1 -0
  7. package/dist/cli/build-helpers.test.js +156 -0
  8. package/dist/cli/build-helpers.test.js.map +1 -0
  9. package/dist/cli/build-steps.d.ts +2 -0
  10. package/dist/cli/build-steps.js +84 -0
  11. package/dist/cli/build-steps.js.map +1 -0
  12. package/dist/cli/build-steps.test.js +72 -0
  13. package/dist/cli/build-steps.test.js.map +1 -0
  14. package/dist/cli/detect-port.d.ts +18 -0
  15. package/dist/cli/detect-port.js +49 -0
  16. package/dist/cli/detect-port.js.map +1 -0
  17. package/dist/cli/header.d.ts +4 -0
  18. package/dist/cli/header.js +6 -0
  19. package/dist/cli/header.js.map +1 -0
  20. package/dist/cli/resolve-skybridge-config.d.ts +6 -0
  21. package/dist/cli/resolve-skybridge-config.js +28 -0
  22. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  23. package/dist/cli/run-command.d.ts +2 -0
  24. package/dist/cli/run-command.js +43 -0
  25. package/dist/cli/run-command.js.map +1 -0
  26. package/dist/cli/run-plain.d.ts +18 -0
  27. package/dist/cli/run-plain.js +90 -0
  28. package/dist/cli/run-plain.js.map +1 -0
  29. package/dist/cli/telemetry.d.ts +7 -0
  30. package/dist/cli/telemetry.js +125 -0
  31. package/dist/cli/telemetry.js.map +1 -0
  32. package/dist/cli/tunnel-control-server.d.ts +9 -0
  33. package/dist/cli/tunnel-control-server.js +31 -0
  34. package/dist/cli/tunnel-control-server.js.map +1 -0
  35. package/dist/cli/tunnel-control-server.test.js +39 -0
  36. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  37. package/dist/cli/tunnel-handler.d.ts +3 -0
  38. package/dist/cli/tunnel-handler.js +48 -0
  39. package/dist/cli/tunnel-handler.js.map +1 -0
  40. package/dist/cli/tunnel-handler.test.js +105 -0
  41. package/dist/cli/tunnel-handler.test.js.map +1 -0
  42. package/dist/cli/tunnel.d.ts +57 -0
  43. package/dist/cli/tunnel.js +154 -0
  44. package/dist/cli/tunnel.js.map +1 -0
  45. package/dist/cli/tunnel.test.js +190 -0
  46. package/dist/cli/tunnel.test.js.map +1 -0
  47. package/dist/cli/types.d.ts +5 -0
  48. package/dist/cli/types.js +2 -0
  49. package/dist/cli/types.js.map +1 -0
  50. package/dist/cli/use-execute-steps.d.ts +11 -0
  51. package/dist/cli/use-execute-steps.js +36 -0
  52. package/dist/cli/use-execute-steps.js.map +1 -0
  53. package/dist/cli/use-messages.d.ts +3 -0
  54. package/dist/cli/use-messages.js +11 -0
  55. package/dist/cli/use-messages.js.map +1 -0
  56. package/dist/cli/use-nodemon.d.ts +26 -0
  57. package/dist/cli/use-nodemon.js +106 -0
  58. package/dist/cli/use-nodemon.js.map +1 -0
  59. package/dist/cli/use-open-browser.d.ts +1 -0
  60. package/dist/cli/use-open-browser.js +44 -0
  61. package/dist/cli/use-open-browser.js.map +1 -0
  62. package/dist/cli/use-tunnel.d.ts +14 -0
  63. package/dist/cli/use-tunnel.js +131 -0
  64. package/dist/cli/use-tunnel.js.map +1 -0
  65. package/dist/cli/use-typescript-check.d.ts +15 -0
  66. package/dist/cli/use-typescript-check.js +99 -0
  67. package/dist/cli/use-typescript-check.js.map +1 -0
  68. package/dist/commands/build.d.ts +6 -0
  69. package/dist/commands/build.js +31 -0
  70. package/dist/commands/build.js.map +1 -0
  71. package/dist/commands/create.d.ts +9 -0
  72. package/dist/commands/create.js +30 -0
  73. package/dist/commands/create.js.map +1 -0
  74. package/dist/commands/dev.d.ts +13 -0
  75. package/dist/commands/dev.js +128 -0
  76. package/dist/commands/dev.js.map +1 -0
  77. package/dist/commands/start.d.ts +9 -0
  78. package/dist/commands/start.js +55 -0
  79. package/dist/commands/start.js.map +1 -0
  80. package/dist/commands/telemetry/disable.d.ts +5 -0
  81. package/dist/commands/telemetry/disable.js +14 -0
  82. package/dist/commands/telemetry/disable.js.map +1 -0
  83. package/dist/commands/telemetry/enable.d.ts +5 -0
  84. package/dist/commands/telemetry/enable.js +14 -0
  85. package/dist/commands/telemetry/enable.js.map +1 -0
  86. package/dist/commands/telemetry/status.d.ts +5 -0
  87. package/dist/commands/telemetry/status.js +14 -0
  88. package/dist/commands/telemetry/status.js.map +1 -0
  89. package/dist/context-warnings.d.ts +5 -0
  90. package/dist/context-warnings.js +31 -0
  91. package/dist/context-warnings.js.map +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/app.d.ts +211 -0
  95. package/dist/server/app.js +277 -0
  96. package/dist/server/app.js.map +1 -0
  97. package/dist/server/app.test.js +178 -0
  98. package/dist/server/app.test.js.map +1 -0
  99. package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
  100. package/dist/server/asset-base-url-transform-plugin.js +48 -0
  101. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  102. package/dist/server/asset-base-url-transform-plugin.test.js +134 -0
  103. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  104. package/dist/server/auth/discovery.d.ts +33 -0
  105. package/dist/server/auth/discovery.js +56 -0
  106. package/dist/server/auth/discovery.js.map +1 -0
  107. package/dist/server/auth/discovery.test.js +93 -0
  108. package/dist/server/auth/discovery.test.js.map +1 -0
  109. package/dist/server/auth/index.d.ts +48 -0
  110. package/dist/server/auth/index.js +2 -0
  111. package/dist/server/auth/index.js.map +1 -0
  112. package/dist/server/auth/providers/auth0.d.ts +40 -0
  113. package/dist/server/auth/providers/auth0.js +36 -0
  114. package/dist/server/auth/providers/auth0.js.map +1 -0
  115. package/dist/server/auth/providers/auth0.test.js +50 -0
  116. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  117. package/dist/server/auth/providers/authplane.d.ts +49 -0
  118. package/dist/server/auth/providers/authplane.js +57 -0
  119. package/dist/server/auth/providers/authplane.js.map +1 -0
  120. package/dist/server/auth/providers/authplane.test.js +143 -0
  121. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  122. package/dist/server/auth/providers/clerk.d.ts +51 -0
  123. package/dist/server/auth/providers/clerk.js +19 -0
  124. package/dist/server/auth/providers/clerk.js.map +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 +42 -0
  128. package/dist/server/auth/providers/custom.js +59 -0
  129. package/dist/server/auth/providers/custom.js.map +1 -0
  130. package/dist/server/auth/providers/custom.test.js +161 -0
  131. package/dist/server/auth/providers/custom.test.js.map +1 -0
  132. package/dist/server/auth/providers/descope.d.ts +44 -0
  133. package/dist/server/auth/providers/descope.js +44 -0
  134. package/dist/server/auth/providers/descope.js.map +1 -0
  135. package/dist/server/auth/providers/descope.test.js +62 -0
  136. package/dist/server/auth/providers/descope.test.js.map +1 -0
  137. package/dist/server/auth/providers/shared.d.ts +2 -0
  138. package/dist/server/auth/providers/shared.js +6 -0
  139. package/dist/server/auth/providers/shared.js.map +1 -0
  140. package/dist/server/auth/providers/shared.test.js +10 -0
  141. package/dist/server/auth/providers/shared.test.js.map +1 -0
  142. package/dist/server/auth/providers/stytch.d.ts +25 -0
  143. package/dist/server/auth/providers/stytch.js +16 -0
  144. package/dist/server/auth/providers/stytch.js.map +1 -0
  145. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  146. package/dist/server/auth/providers/verify-spy.js +21 -0
  147. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  148. package/dist/server/auth/providers/workos.d.ts +34 -0
  149. package/dist/server/auth/providers/workos.js +16 -0
  150. package/dist/server/auth/providers/workos.js.map +1 -0
  151. package/dist/server/auth/security-schemes.d.ts +23 -0
  152. package/dist/server/auth/security-schemes.js +64 -0
  153. package/dist/server/auth/security-schemes.js.map +1 -0
  154. package/dist/server/auth/security-schemes.test.js +99 -0
  155. package/dist/server/auth/security-schemes.test.js.map +1 -0
  156. package/dist/server/auth/setup.d.ts +6 -0
  157. package/dist/server/auth/setup.js +91 -0
  158. package/dist/server/auth/setup.js.map +1 -0
  159. package/dist/server/auth/setup.test.js +514 -0
  160. package/dist/server/auth/setup.test.js.map +1 -0
  161. package/dist/server/auth/verify.d.ts +48 -0
  162. package/dist/server/auth/verify.js +62 -0
  163. package/dist/server/auth/verify.js.map +1 -0
  164. package/dist/server/auth/verify.test.js +165 -0
  165. package/dist/server/auth/verify.test.js.map +1 -0
  166. package/dist/server/auth-extra.test-d.js +130 -0
  167. package/dist/server/auth-extra.test-d.js.map +1 -0
  168. package/dist/server/auth.d.ts +57 -0
  169. package/dist/server/auth.js +27 -0
  170. package/dist/server/auth.js.map +1 -0
  171. package/dist/server/build-manifest.test.js +28 -0
  172. package/dist/server/build-manifest.test.js.map +1 -0
  173. package/dist/server/content-helpers.d.ts +67 -0
  174. package/dist/server/content-helpers.js +79 -0
  175. package/dist/server/content-helpers.js.map +1 -0
  176. package/dist/server/content-helpers.test.d.ts +1 -0
  177. package/dist/server/content-helpers.test.js +70 -0
  178. package/dist/server/content-helpers.test.js.map +1 -0
  179. package/dist/server/events.d.ts +113 -0
  180. package/dist/server/events.js +318 -0
  181. package/dist/server/events.js.map +1 -0
  182. package/dist/server/events.test.d.ts +1 -0
  183. package/dist/server/events.test.js +172 -0
  184. package/dist/server/events.test.js.map +1 -0
  185. package/dist/server/express.d.ts +32 -0
  186. package/dist/server/express.js +113 -0
  187. package/dist/server/express.js.map +1 -0
  188. package/dist/server/express.test.d.ts +1 -0
  189. package/dist/server/express.test.js +653 -0
  190. package/dist/server/express.test.js.map +1 -0
  191. package/dist/server/file-ref.d.ts +28 -0
  192. package/dist/server/file-ref.js +27 -0
  193. package/dist/server/file-ref.js.map +1 -0
  194. package/dist/server/form-input.d.ts +120 -0
  195. package/dist/server/form-input.js +89 -0
  196. package/dist/server/form-input.js.map +1 -0
  197. package/dist/server/host.d.ts +2 -0
  198. package/dist/server/host.js +11 -0
  199. package/dist/server/host.js.map +1 -0
  200. package/dist/server/host.test.d.ts +1 -0
  201. package/dist/server/host.test.js +13 -0
  202. package/dist/server/host.test.js.map +1 -0
  203. package/dist/server/index.d.ts +24 -0
  204. package/dist/server/index.js +20 -0
  205. package/dist/server/index.js.map +1 -0
  206. package/dist/{src/server → server}/inferUtilityTypes.d.ts +6 -6
  207. package/dist/server/inferUtilityTypes.js.map +1 -0
  208. package/dist/server/mcp-errors.test.d.ts +1 -0
  209. package/dist/server/mcp-errors.test.js +229 -0
  210. package/dist/server/mcp-errors.test.js.map +1 -0
  211. package/dist/server/metric.d.ts +16 -0
  212. package/dist/server/metric.js +62 -0
  213. package/dist/server/metric.js.map +1 -0
  214. package/dist/server/middleware.d.ts +162 -0
  215. package/dist/server/middleware.js +126 -0
  216. package/dist/server/middleware.js.map +1 -0
  217. package/dist/server/middleware.test-d.d.ts +1 -0
  218. package/dist/server/middleware.test-d.js +75 -0
  219. package/dist/server/middleware.test-d.js.map +1 -0
  220. package/dist/server/middleware.test.d.ts +1 -0
  221. package/dist/server/middleware.test.js +601 -0
  222. package/dist/server/middleware.test.js.map +1 -0
  223. package/dist/server/register-tool.test.d.ts +1 -0
  224. package/dist/server/register-tool.test.js +230 -0
  225. package/dist/server/register-tool.test.js.map +1 -0
  226. package/dist/server/requestOrigin.d.ts +7 -0
  227. package/dist/server/requestOrigin.js +25 -0
  228. package/dist/server/requestOrigin.js.map +1 -0
  229. package/dist/server/server.d.ts +665 -0
  230. package/dist/server/server.js +815 -0
  231. package/dist/server/server.js.map +1 -0
  232. package/dist/server/skills-integration.test.d.ts +1 -0
  233. package/dist/server/skills-integration.test.js +86 -0
  234. package/dist/server/skills-integration.test.js.map +1 -0
  235. package/dist/server/skills.d.ts +27 -0
  236. package/dist/server/skills.js +188 -0
  237. package/dist/server/skills.js.map +1 -0
  238. package/dist/server/skills.test.d.ts +1 -0
  239. package/dist/server/skills.test.js +243 -0
  240. package/dist/server/skills.test.js.map +1 -0
  241. package/dist/{src/server → server}/templateHelper.d.ts +3 -7
  242. package/dist/server/templateHelper.js +11 -0
  243. package/dist/server/templateHelper.js.map +1 -0
  244. package/dist/server/templates.generated.d.ts +4 -0
  245. package/dist/server/templates.generated.js +57 -0
  246. package/dist/server/templates.generated.js.map +1 -0
  247. package/dist/server/tool-extra.test.d.ts +1 -0
  248. package/dist/server/tool-extra.test.js +167 -0
  249. package/dist/server/tool-extra.test.js.map +1 -0
  250. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  251. package/dist/server/tunnel-proxy-router.js +110 -0
  252. package/dist/server/tunnel-proxy-router.js.map +1 -0
  253. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  254. package/dist/server/tunnel-proxy-router.test.js +229 -0
  255. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  256. package/dist/server/view-name.test-d.d.ts +1 -0
  257. package/dist/server/view-name.test-d.js +8 -0
  258. package/dist/server/view-name.test-d.js.map +1 -0
  259. package/dist/server/view-resource-resolution.test.d.ts +6 -0
  260. package/dist/server/view-resource-resolution.test.js +211 -0
  261. package/dist/server/view-resource-resolution.test.js.map +1 -0
  262. package/dist/server/viewsDevServer.d.ts +14 -0
  263. package/dist/server/viewsDevServer.js +48 -0
  264. package/dist/server/viewsDevServer.js.map +1 -0
  265. package/dist/{src/test → test}/utils.d.ts +21 -31
  266. package/dist/test/utils.js +266 -0
  267. package/dist/test/utils.js.map +1 -0
  268. package/dist/test/view.test.d.ts +1 -0
  269. package/dist/test/view.test.js +540 -0
  270. package/dist/test/view.test.js.map +1 -0
  271. package/dist/version.d.ts +1 -0
  272. package/dist/version.js +3 -0
  273. package/dist/version.js.map +1 -0
  274. package/dist/views/index.d.ts +10 -0
  275. package/dist/views/index.js +3 -0
  276. package/dist/views/index.js.map +1 -0
  277. package/dist/views/scan-views.d.ts +16 -0
  278. package/dist/views/scan-views.js +88 -0
  279. package/dist/views/scan-views.js.map +1 -0
  280. package/dist/views/scan-views.test.d.ts +1 -0
  281. package/dist/views/scan-views.test.js +99 -0
  282. package/dist/views/scan-views.test.js.map +1 -0
  283. package/dist/views/validate-view.d.ts +1 -0
  284. package/dist/views/validate-view.js +9 -0
  285. package/dist/views/validate-view.js.map +1 -0
  286. package/dist/views/validate-view.test.d.ts +1 -0
  287. package/dist/views/validate-view.test.js +24 -0
  288. package/dist/views/validate-view.test.js.map +1 -0
  289. package/dist/web/bridges/adaptor.d.ts +62 -0
  290. package/dist/web/bridges/adaptor.js +480 -0
  291. package/dist/web/bridges/adaptor.js.map +1 -0
  292. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  293. package/dist/web/bridges/adaptor.test.js +292 -0
  294. package/dist/web/bridges/adaptor.test.js.map +1 -0
  295. package/dist/web/bridges/apps-sdk/bridge.d.ts +15 -0
  296. package/dist/web/bridges/apps-sdk/bridge.js +58 -0
  297. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
  298. package/dist/web/bridges/apps-sdk/index.d.ts +4 -0
  299. package/dist/web/bridges/apps-sdk/index.js +4 -0
  300. package/dist/web/bridges/apps-sdk/index.js.map +1 -0
  301. package/dist/web/bridges/apps-sdk/types.d.ts +132 -0
  302. package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
  303. package/dist/web/bridges/apps-sdk/types.js.map +1 -0
  304. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +13 -0
  305. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +18 -0
  306. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
  307. package/dist/web/bridges/get-adaptor.d.ts +9 -0
  308. package/dist/web/bridges/get-adaptor.js +10 -0
  309. package/dist/web/bridges/get-adaptor.js.map +1 -0
  310. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  311. package/dist/web/bridges/get-adaptor.test.js +32 -0
  312. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  313. package/dist/web/bridges/index.d.ts +5 -0
  314. package/dist/web/bridges/index.js +6 -0
  315. package/dist/web/bridges/index.js.map +1 -0
  316. package/dist/web/bridges/mcp-app/bridge.d.ts +39 -0
  317. package/dist/web/bridges/mcp-app/bridge.js +175 -0
  318. package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
  319. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  320. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  321. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  322. package/dist/web/bridges/mcp-app/index.d.ts +3 -0
  323. package/dist/web/bridges/mcp-app/index.js +3 -0
  324. package/dist/web/bridges/mcp-app/index.js.map +1 -0
  325. package/dist/web/bridges/mcp-app/types.d.ts +25 -0
  326. package/dist/web/bridges/mcp-app/types.js +2 -0
  327. package/dist/web/bridges/mcp-app/types.js.map +1 -0
  328. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +19 -0
  329. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +19 -0
  330. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
  331. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.d.ts +1 -0
  332. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
  333. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
  334. package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
  335. package/dist/web/bridges/mcp-app/view-tools.test.js +143 -0
  336. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
  337. package/dist/web/bridges/types.d.ts +272 -0
  338. package/dist/web/bridges/types.js +15 -0
  339. package/dist/web/bridges/types.js.map +1 -0
  340. package/dist/web/bridges/types.test.d.ts +1 -0
  341. package/dist/web/bridges/types.test.js +19 -0
  342. package/dist/web/bridges/types.test.js.map +1 -0
  343. package/dist/web/bridges/use-host-context.d.ts +7 -0
  344. package/dist/web/bridges/use-host-context.js +13 -0
  345. package/dist/web/bridges/use-host-context.js.map +1 -0
  346. package/dist/web/components/modal-provider.d.ts +4 -0
  347. package/dist/web/components/modal-provider.js +46 -0
  348. package/dist/web/components/modal-provider.js.map +1 -0
  349. package/dist/web/create-store.d.ts +29 -0
  350. package/dist/web/create-store.js +64 -0
  351. package/dist/web/create-store.js.map +1 -0
  352. package/dist/web/create-store.test.d.ts +1 -0
  353. package/dist/web/create-store.test.js +132 -0
  354. package/dist/web/create-store.test.js.map +1 -0
  355. package/dist/web/data-llm.d.ts +47 -0
  356. package/dist/{src/web → web}/data-llm.js +42 -9
  357. package/dist/web/data-llm.js.map +1 -0
  358. package/dist/web/data-llm.test.d.ts +1 -0
  359. package/dist/web/data-llm.test.js +161 -0
  360. package/dist/web/data-llm.test.js.map +1 -0
  361. package/dist/{src/web → web}/generate-helpers.d.ts +41 -32
  362. package/dist/{src/web → web}/generate-helpers.js +38 -30
  363. package/dist/web/generate-helpers.js.map +1 -0
  364. package/dist/web/generate-helpers.test-d.d.ts +1 -0
  365. package/dist/{src/web → web}/generate-helpers.test-d.js +35 -30
  366. package/dist/web/generate-helpers.test-d.js.map +1 -0
  367. package/dist/web/generate-helpers.test.d.ts +1 -0
  368. package/dist/{src/web → web}/generate-helpers.test.js +2 -2
  369. package/dist/web/generate-helpers.test.js.map +1 -0
  370. package/dist/{src/web → web}/helpers/state.d.ts +2 -2
  371. package/dist/web/helpers/state.js +45 -0
  372. package/dist/web/helpers/state.js.map +1 -0
  373. package/dist/web/helpers/state.test.d.ts +1 -0
  374. package/dist/{src/web → web}/helpers/state.test.js +9 -9
  375. package/dist/web/helpers/state.test.js.map +1 -0
  376. package/dist/web/hooks/index.d.ts +20 -0
  377. package/dist/web/hooks/index.js +21 -0
  378. package/dist/web/hooks/index.js.map +1 -0
  379. package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
  380. package/dist/web/hooks/openai-extensions.test.js +107 -0
  381. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  382. package/dist/web/hooks/test/utils.d.ts +21 -0
  383. package/dist/web/hooks/test/utils.js +75 -0
  384. package/dist/web/hooks/test/utils.js.map +1 -0
  385. package/dist/{src/web → web}/hooks/use-call-tool.d.ts +48 -2
  386. package/dist/web/hooks/use-call-tool.js +101 -0
  387. package/dist/web/hooks/use-call-tool.js.map +1 -0
  388. package/dist/web/hooks/use-call-tool.test-d.d.ts +1 -0
  389. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
  390. package/dist/web/hooks/use-call-tool.test.d.ts +1 -0
  391. package/dist/{src/web → web}/hooks/use-call-tool.test.js +95 -24
  392. package/dist/web/hooks/use-call-tool.test.js.map +1 -0
  393. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  394. package/dist/web/hooks/use-deep-link.js +34 -0
  395. package/dist/web/hooks/use-deep-link.js.map +1 -0
  396. package/dist/web/hooks/use-display-mode.d.ts +24 -0
  397. package/dist/web/hooks/use-display-mode.js +29 -0
  398. package/dist/web/hooks/use-display-mode.js.map +1 -0
  399. package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
  400. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  401. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  402. package/dist/web/hooks/use-display-mode.test.d.ts +1 -0
  403. package/dist/web/hooks/use-display-mode.test.js +77 -0
  404. package/dist/web/hooks/use-display-mode.test.js.map +1 -0
  405. package/dist/web/hooks/use-download.d.ts +3 -0
  406. package/dist/web/hooks/use-download.js +7 -0
  407. package/dist/web/hooks/use-download.js.map +1 -0
  408. package/dist/web/hooks/use-download.test.d.ts +1 -0
  409. package/dist/web/hooks/use-download.test.js +103 -0
  410. package/dist/web/hooks/use-download.test.js.map +1 -0
  411. package/dist/web/hooks/use-file-resource.d.ts +37 -0
  412. package/dist/web/hooks/use-file-resource.js +98 -0
  413. package/dist/web/hooks/use-file-resource.js.map +1 -0
  414. package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
  415. package/dist/web/hooks/use-file-resource.test.js +65 -0
  416. package/dist/web/hooks/use-file-resource.test.js.map +1 -0
  417. package/dist/web/hooks/use-files.d.ts +39 -0
  418. package/dist/web/hooks/use-files.js +42 -0
  419. package/dist/web/hooks/use-files.js.map +1 -0
  420. package/dist/web/hooks/use-files.test.d.ts +1 -0
  421. package/dist/web/hooks/use-files.test.js +62 -0
  422. package/dist/web/hooks/use-files.test.js.map +1 -0
  423. package/dist/web/hooks/use-host.d.ts +44 -0
  424. package/dist/web/hooks/use-host.js +45 -0
  425. package/dist/web/hooks/use-host.js.map +1 -0
  426. package/dist/web/hooks/use-host.test.d.ts +1 -0
  427. package/dist/web/hooks/use-host.test.js +59 -0
  428. package/dist/web/hooks/use-host.test.js.map +1 -0
  429. package/dist/web/hooks/use-model-context.d.ts +44 -0
  430. package/dist/web/hooks/use-model-context.js +63 -0
  431. package/dist/web/hooks/use-model-context.js.map +1 -0
  432. package/dist/web/hooks/use-open-external.d.ts +20 -0
  433. package/dist/web/hooks/use-open-external.js +24 -0
  434. package/dist/web/hooks/use-open-external.js.map +1 -0
  435. package/dist/web/hooks/use-open-external.test.d.ts +1 -0
  436. package/dist/web/hooks/use-open-external.test.js +75 -0
  437. package/dist/web/hooks/use-open-external.test.js.map +1 -0
  438. package/dist/web/hooks/use-open-file.d.ts +20 -0
  439. package/dist/web/hooks/use-open-file.js +25 -0
  440. package/dist/web/hooks/use-open-file.js.map +1 -0
  441. package/dist/web/hooks/use-register-view-tool.d.ts +37 -0
  442. package/dist/web/hooks/use-register-view-tool.js +50 -0
  443. package/dist/web/hooks/use-register-view-tool.js.map +1 -0
  444. package/dist/web/hooks/use-request-close.d.ts +16 -0
  445. package/dist/web/hooks/use-request-close.js +21 -0
  446. package/dist/web/hooks/use-request-close.js.map +1 -0
  447. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  448. package/dist/web/hooks/use-request-close.test.js +47 -0
  449. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  450. package/dist/web/hooks/use-request-modal.d.ts +24 -0
  451. package/dist/web/hooks/use-request-modal.js +31 -0
  452. package/dist/web/hooks/use-request-modal.js.map +1 -0
  453. package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
  454. package/dist/web/hooks/use-request-modal.test.js +71 -0
  455. package/dist/web/hooks/use-request-modal.test.js.map +1 -0
  456. package/dist/web/hooks/use-request-size.d.ts +20 -0
  457. package/dist/web/hooks/use-request-size.js +24 -0
  458. package/dist/web/hooks/use-request-size.js.map +1 -0
  459. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  460. package/dist/web/hooks/use-request-size.test.js +47 -0
  461. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  462. package/dist/web/hooks/use-send-follow-up-message.d.ts +25 -0
  463. package/dist/web/hooks/use-send-follow-up-message.js +31 -0
  464. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
  465. package/dist/web/hooks/use-set-open-in-app-url.d.ts +18 -0
  466. package/dist/web/hooks/use-set-open-in-app-url.js +25 -0
  467. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  468. package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
  469. package/dist/web/hooks/use-set-open-in-app-url.test.js +57 -0
  470. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  471. package/dist/web/hooks/use-tool-info.d.ts +68 -0
  472. package/dist/web/hooks/use-tool-info.js +48 -0
  473. package/dist/web/hooks/use-tool-info.js.map +1 -0
  474. package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
  475. package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +19 -6
  476. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
  477. package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
  478. package/dist/web/hooks/use-tool-info.test.js +135 -0
  479. package/dist/web/hooks/use-tool-info.test.js.map +1 -0
  480. package/dist/{src/web → web}/hooks/use-user.d.ts +5 -2
  481. package/dist/web/hooks/use-user.js +38 -0
  482. package/dist/web/hooks/use-user.js.map +1 -0
  483. package/dist/web/hooks/use-user.test.d.ts +1 -0
  484. package/dist/web/hooks/use-user.test.js +170 -0
  485. package/dist/web/hooks/use-user.test.js.map +1 -0
  486. package/dist/web/hooks/use-view-state.d.ts +25 -0
  487. package/dist/web/hooks/use-view-state.js +42 -0
  488. package/dist/web/hooks/use-view-state.js.map +1 -0
  489. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  490. package/dist/web/hooks/use-view-state.test.js +212 -0
  491. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  492. package/dist/web/hooks/use-viewport.d.ts +20 -0
  493. package/dist/web/hooks/use-viewport.js +21 -0
  494. package/dist/web/hooks/use-viewport.js.map +1 -0
  495. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  496. package/dist/web/hooks/use-viewport.test.js +109 -0
  497. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  498. package/dist/{src/web → web}/index.d.ts +1 -2
  499. package/dist/{src/web → web}/index.js +1 -2
  500. package/dist/web/index.js.map +1 -0
  501. package/dist/web/mount-view.d.ts +21 -0
  502. package/dist/web/mount-view.js +41 -0
  503. package/dist/web/mount-view.js.map +1 -0
  504. package/dist/{src/web → web}/proxy.js +0 -1
  505. package/dist/web/proxy.js.map +1 -0
  506. package/dist/web/types.d.ts +20 -0
  507. package/dist/web/types.js +2 -0
  508. package/dist/web/types.js.map +1 -0
  509. package/package.json +92 -41
  510. package/tsconfig.base.json +33 -0
  511. package/dist/src/server/devtoolsStaticServer.d.ts +0 -15
  512. package/dist/src/server/devtoolsStaticServer.js +0 -38
  513. package/dist/src/server/devtoolsStaticServer.js.map +0 -1
  514. package/dist/src/server/index.d.ts +0 -5
  515. package/dist/src/server/index.js +0 -4
  516. package/dist/src/server/index.js.map +0 -1
  517. package/dist/src/server/inferUtilityTypes.js.map +0 -1
  518. package/dist/src/server/server.d.ts +0 -74
  519. package/dist/src/server/server.js +0 -82
  520. package/dist/src/server/server.js.map +0 -1
  521. package/dist/src/server/templateHelper.js +0 -30
  522. package/dist/src/server/templateHelper.js.map +0 -1
  523. package/dist/src/server/templates/development.hbs +0 -13
  524. package/dist/src/server/templates/production.hbs +0 -7
  525. package/dist/src/server/widgetsDevServer.d.ts +0 -12
  526. package/dist/src/server/widgetsDevServer.js +0 -39
  527. package/dist/src/server/widgetsDevServer.js.map +0 -1
  528. package/dist/src/test/utils.js +0 -242
  529. package/dist/src/test/utils.js.map +0 -1
  530. package/dist/src/test/widget.test.js +0 -146
  531. package/dist/src/test/widget.test.js.map +0 -1
  532. package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -8
  533. package/dist/src/web/bridges/apps-sdk-bridge.js +0 -41
  534. package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
  535. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
  536. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +0 -7
  537. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
  538. package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -3
  539. package/dist/src/web/bridges/hooks/use-bridge.js +0 -27
  540. package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
  541. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -4
  542. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
  543. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
  544. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -58
  545. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
  546. package/dist/src/web/bridges/index.d.ts +0 -3
  547. package/dist/src/web/bridges/index.js +0 -4
  548. package/dist/src/web/bridges/index.js.map +0 -1
  549. package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -26
  550. package/dist/src/web/bridges/mcp-app-bridge.js +0 -130
  551. package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
  552. package/dist/src/web/create-store.d.ts +0 -3
  553. package/dist/src/web/create-store.js +0 -25
  554. package/dist/src/web/create-store.js.map +0 -1
  555. package/dist/src/web/create-store.test.js +0 -70
  556. package/dist/src/web/create-store.test.js.map +0 -1
  557. package/dist/src/web/data-llm.d.ts +0 -14
  558. package/dist/src/web/data-llm.js.map +0 -1
  559. package/dist/src/web/data-llm.test.js +0 -76
  560. package/dist/src/web/data-llm.test.js.map +0 -1
  561. package/dist/src/web/generate-helpers.js.map +0 -1
  562. package/dist/src/web/generate-helpers.test-d.js.map +0 -1
  563. package/dist/src/web/generate-helpers.test.js.map +0 -1
  564. package/dist/src/web/helpers/state.js +0 -40
  565. package/dist/src/web/helpers/state.js.map +0 -1
  566. package/dist/src/web/helpers/state.test.js.map +0 -1
  567. package/dist/src/web/hooks/index.d.ts +0 -11
  568. package/dist/src/web/hooks/index.js +0 -12
  569. package/dist/src/web/hooks/index.js.map +0 -1
  570. package/dist/src/web/hooks/use-call-tool.js +0 -60
  571. package/dist/src/web/hooks/use-call-tool.js.map +0 -1
  572. package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
  573. package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
  574. package/dist/src/web/hooks/use-display-mode.d.ts +0 -4
  575. package/dist/src/web/hooks/use-display-mode.js +0 -7
  576. package/dist/src/web/hooks/use-display-mode.js.map +0 -1
  577. package/dist/src/web/hooks/use-display-mode.test.js +0 -41
  578. package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
  579. package/dist/src/web/hooks/use-files.d.ts +0 -10
  580. package/dist/src/web/hooks/use-files.js +0 -7
  581. package/dist/src/web/hooks/use-files.js.map +0 -1
  582. package/dist/src/web/hooks/use-files.test.js +0 -29
  583. package/dist/src/web/hooks/use-files.test.js.map +0 -1
  584. package/dist/src/web/hooks/use-layout.d.ts +0 -22
  585. package/dist/src/web/hooks/use-layout.js +0 -23
  586. package/dist/src/web/hooks/use-layout.js.map +0 -1
  587. package/dist/src/web/hooks/use-layout.test.js +0 -46
  588. package/dist/src/web/hooks/use-layout.test.js.map +0 -1
  589. package/dist/src/web/hooks/use-open-external.d.ts +0 -1
  590. package/dist/src/web/hooks/use-open-external.js +0 -6
  591. package/dist/src/web/hooks/use-open-external.js.map +0 -1
  592. package/dist/src/web/hooks/use-open-external.test.js +0 -24
  593. package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
  594. package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
  595. package/dist/src/web/hooks/use-openai-global.js +0 -6
  596. package/dist/src/web/hooks/use-openai-global.js.map +0 -1
  597. package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
  598. package/dist/src/web/hooks/use-request-modal.js +0 -9
  599. package/dist/src/web/hooks/use-request-modal.js.map +0 -1
  600. package/dist/src/web/hooks/use-request-modal.test.js +0 -24
  601. package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
  602. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +0 -1
  603. package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
  604. package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
  605. package/dist/src/web/hooks/use-tool-info.d.ts +0 -25
  606. package/dist/src/web/hooks/use-tool-info.js +0 -20
  607. package/dist/src/web/hooks/use-tool-info.js.map +0 -1
  608. package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
  609. package/dist/src/web/hooks/use-tool-info.test.js +0 -60
  610. package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
  611. package/dist/src/web/hooks/use-user.js +0 -19
  612. package/dist/src/web/hooks/use-user.js.map +0 -1
  613. package/dist/src/web/hooks/use-user.test.js +0 -44
  614. package/dist/src/web/hooks/use-user.test.js.map +0 -1
  615. package/dist/src/web/hooks/use-widget-state.d.ts +0 -4
  616. package/dist/src/web/hooks/use-widget-state.js +0 -32
  617. package/dist/src/web/hooks/use-widget-state.js.map +0 -1
  618. package/dist/src/web/hooks/use-widget-state.test.js +0 -61
  619. package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
  620. package/dist/src/web/index.js.map +0 -1
  621. package/dist/src/web/mount-widget.d.ts +0 -1
  622. package/dist/src/web/mount-widget.js +0 -19
  623. package/dist/src/web/mount-widget.js.map +0 -1
  624. package/dist/src/web/plugin/data-llm.test.js +0 -81
  625. package/dist/src/web/plugin/data-llm.test.js.map +0 -1
  626. package/dist/src/web/plugin/plugin.d.ts +0 -2
  627. package/dist/src/web/plugin/plugin.js +0 -39
  628. package/dist/src/web/plugin/plugin.js.map +0 -1
  629. package/dist/src/web/plugin/transform-data-llm.d.ts +0 -12
  630. package/dist/src/web/plugin/transform-data-llm.js +0 -93
  631. package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
  632. package/dist/src/web/plugin/transform-data-llm.test.js +0 -81
  633. package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
  634. package/dist/src/web/proxy.js.map +0 -1
  635. package/dist/src/web/types.d.ts +0 -138
  636. package/dist/src/web/types.js.map +0 -1
  637. package/dist/vitest.config.d.ts +0 -2
  638. package/dist/vitest.config.js +0 -8
  639. package/dist/vitest.config.js.map +0 -1
  640. /package/dist/{src/test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
  641. /package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  642. /package/dist/{src/web/create-store.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  643. /package/dist/{src/web/data-llm.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
  644. /package/dist/{src/web/generate-helpers.test-d.d.ts → cli/tunnel.test.d.ts} +0 -0
  645. /package/dist/{src/web/generate-helpers.test.d.ts → context-warnings.test.d.ts} +0 -0
  646. /package/dist/{src/web/helpers/state.test.d.ts → server/app.test.d.ts} +0 -0
  647. /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
  648. /package/dist/{src/web/hooks/use-display-mode.test.d.ts → server/auth/discovery.test.d.ts} +0 -0
  649. /package/dist/{src/web/hooks/use-files.test.d.ts → server/auth/providers/auth0.test.d.ts} +0 -0
  650. /package/dist/{src/web/hooks/use-layout.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
  651. /package/dist/{src/web/hooks/use-open-external.test.d.ts → server/auth/providers/clerk.test.d.ts} +0 -0
  652. /package/dist/{src/web/hooks/use-request-modal.test.d.ts → server/auth/providers/custom.test.d.ts} +0 -0
  653. /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → server/auth/providers/descope.test.d.ts} +0 -0
  654. /package/dist/{src/web/hooks/use-tool-info.test.d.ts → server/auth/providers/shared.test.d.ts} +0 -0
  655. /package/dist/{src/web/hooks/use-user.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
  656. /package/dist/{src/web/hooks/use-widget-state.test.d.ts → server/auth/setup.test.d.ts} +0 -0
  657. /package/dist/{src/web/plugin/data-llm.test.d.ts → server/auth/verify.test.d.ts} +0 -0
  658. /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  659. /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → server/build-manifest.test.d.ts} +0 -0
  660. /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
  661. /package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +0 -0
  662. /package/dist/{src/web → web}/proxy.d.ts +0 -0
@@ -0,0 +1,277 @@
1
+ import http from "node:http";
2
+ import { setupOAuth } from "./auth/setup.js";
3
+ import { buildMcpHandler, createApp, createBaseApp } from "./express.js";
4
+ import { registerMonitoring } from "./metric.js";
5
+ import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
6
+ import { McpServer, } from "./server.js";
7
+ const SLOW_HANDLER_THRESHOLD_MS = 50;
8
+ async function resolveOAuthInput(input, config) {
9
+ const resolved = typeof input === "function" ? input(config) : input;
10
+ return resolved && "resolve" in resolved
11
+ ? await resolved.resolve()
12
+ : resolved;
13
+ }
14
+ /**
15
+ * A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`
16
+ * route) plus a handler that builds the MCP server for each request.
17
+ *
18
+ * The handler runs for every request, so tools, resources, prompts and views
19
+ * are always registered on the instance that serves the request. Anything in
20
+ * the handler body other than registration therefore runs per request too.
21
+ * Anything asynchronous the app needs (remote config, secrets, …) goes in
22
+ * `setup`, which runs once and feeds the handler's second argument.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * export const app = new Skybridge({
27
+ * name: "my-app",
28
+ * version: "1.0.0",
29
+ * setup: async () => loadConfig(),
30
+ * oauth: (config) => descopeProvider({ url: config.mcpServerUrl }),
31
+ * handler: (server, config) =>
32
+ * server.registerTool(
33
+ * {
34
+ * name: "search",
35
+ * inputSchema: { query: z.string() },
36
+ * view: { component: "search" },
37
+ * },
38
+ * async ({ query }) => ({ content: `Results for ${query}` }),
39
+ * ),
40
+ * });
41
+ *
42
+ * export type AppType = typeof app;
43
+ * ```
44
+ *
45
+ * @see https://docs.skybridge.tech/api-reference/mcp-server
46
+ */
47
+ export class Skybridge {
48
+ serverInfo;
49
+ serverOptions;
50
+ skills;
51
+ oauthEnabled = false;
52
+ handler;
53
+ setup;
54
+ oauthInput;
55
+ config;
56
+ expressApp;
57
+ onMcpError;
58
+ errorMiddleware = [];
59
+ mcpMiddlewareEntries = [];
60
+ resolveResourceMetadataUrl;
61
+ readyPromise;
62
+ slowHandlerWarned = false;
63
+ constructor({ name, title, version, description, icons, websiteUrl, json, skills, onMcpError, setup, oauth, handler, ...serverOptions }) {
64
+ this.serverInfo = { name, title, version, description, icons, websiteUrl };
65
+ this.serverOptions = serverOptions;
66
+ this.skills = skills;
67
+ this.onMcpError = onMcpError;
68
+ this.setup = setup;
69
+ this.oauthInput = oauth;
70
+ this.handler = handler;
71
+ this.expressApp = createBaseApp(json);
72
+ registerMonitoring(this);
73
+ }
74
+ /**
75
+ * Resolve `setup` and `oauth`, then wire OAuth onto the Express app. Runs
76
+ * once; every entry point that needs a built server awaits it, and a failed
77
+ * attempt is retried on the next call.
78
+ *
79
+ * @internal
80
+ */
81
+ ready() {
82
+ this.readyPromise ??= (async () => {
83
+ if (this.setup) {
84
+ this.config = await this.setup();
85
+ }
86
+ const oauth = await resolveOAuthInput(this.oauthInput, this.config);
87
+ this.oauthEnabled = Boolean(oauth);
88
+ const sample = this.buildServer();
89
+ if (oauth) {
90
+ this.resolveResourceMetadataUrl = setupOAuth(this.expressApp, oauth, sample.securitySchemesByTool);
91
+ }
92
+ })().catch((error) => {
93
+ this.readyPromise = undefined;
94
+ throw error;
95
+ });
96
+ return this.readyPromise;
97
+ }
98
+ /**
99
+ * The underlying Express app. Use this to extend the HTTP server with
100
+ * custom routes, middleware, or settings — e.g.
101
+ * `app.express.get("/health", ...)`.
102
+ *
103
+ * `express.json()` is pre-applied — tune it via the `json` config field,
104
+ * e.g. `new Skybridge({ name, version, json: { limit: "10mb" }, handler })`.
105
+ * Register your handlers before `run()`; after `run()`, dev-mode middleware,
106
+ * the `/mcp` route, and the default error handler are appended in that order.
107
+ *
108
+ * Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
109
+ * locally and on self-hosted deployments.
110
+ */
111
+ get express() {
112
+ return this.expressApp;
113
+ }
114
+ /**
115
+ * Build a fresh server for one stateless HTTP request, as
116
+ * `createMcpHandler`'s factory contract requires: the handler runs again so
117
+ * the SDK's handler closures belong to the instance whose protocol era it
118
+ * stamps. Sharing one instance's handler maps instead would bind them to an
119
+ * instance that is never marked, pinning every request to the 2025 codec and
120
+ * letting concurrent callers overwrite each other's negotiated version.
121
+ *
122
+ * Awaits `setup` and the `oauth` input on first use. Additional middleware
123
+ * wraps the app pipeline for this instance only; it is not registered on the app.
124
+ *
125
+ * @internal
126
+ */
127
+ async createServerInstance(middleware = []) {
128
+ await this.ready();
129
+ const server = this.buildServer();
130
+ this.instrumentHandlers(server, middleware);
131
+ return server.server;
132
+ }
133
+ /** Register outer MCP middleware on this app, in registration order. @internal */
134
+ withMcpMiddleware(entry) {
135
+ this.mcpMiddlewareEntries.push(entry);
136
+ return this;
137
+ }
138
+ /**
139
+ * Connect a Skybridge app to an MCP transport. Use this when you're
140
+ * embedding Skybridge in a host that already manages its own transport
141
+ * (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}
142
+ * which sets the transport up for you.
143
+ */
144
+ async connect(transport) {
145
+ const instance = await this.createServerInstance();
146
+ await instance.connect(transport);
147
+ }
148
+ use(pathOrHandler, ...handlers) {
149
+ // Branching is load-bearing: Express's `app.use` overloads can't be
150
+ // resolved against a `string | RequestHandler` union, so we narrow.
151
+ if (typeof pathOrHandler === "string") {
152
+ this.expressApp.use(pathOrHandler, ...handlers);
153
+ }
154
+ else {
155
+ this.expressApp.use(pathOrHandler, ...handlers);
156
+ }
157
+ return this;
158
+ }
159
+ useOnError(pathOrHandler, ...handlers) {
160
+ if (typeof pathOrHandler === "string") {
161
+ this.errorMiddleware.push({ path: pathOrHandler, handlers });
162
+ }
163
+ else {
164
+ this.errorMiddleware.push({ handlers: [pathOrHandler, ...handlers] });
165
+ }
166
+ return this;
167
+ }
168
+ /**
169
+ * Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
170
+ * mounts the `/mcp` route, and applies any custom Express middleware
171
+ * registered via {@link Skybridge.use} / {@link Skybridge.useOnError}.
172
+ *
173
+ * On Cloudflare Workers / workerd, returns an object exposing `fetch` so
174
+ * the runtime can bridge incoming requests to the Node HTTP server. On
175
+ * Vercel (`VERCEL === "1"`), returns the Express app directly so the
176
+ * serverless function entry can call it as a `(req, res)` handler. On
177
+ * Node, returns `undefined` once listening. When the process was spawned
178
+ * with an IPC channel, the bound port is reported to the parent as
179
+ * `{ type: "skybridge:listening", port }`, the readiness signal test runners
180
+ * wait on instead of polling.
181
+ */
182
+ async run() {
183
+ if (process.env.VERCEL === "1") {
184
+ // createApp only reads httpServer inside its dev-only branch
185
+ // (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
186
+ // bare object passed to satisfy the required parameter.
187
+ const httpServer = http.createServer();
188
+ await createApp({
189
+ app: this,
190
+ httpServer,
191
+ onMcpError: this.onMcpError,
192
+ errorMiddleware: this.errorMiddleware,
193
+ });
194
+ return this.expressApp;
195
+ }
196
+ const httpServer = http.createServer();
197
+ const mcpHandler = buildMcpHandler(this, this.onMcpError);
198
+ await createApp({
199
+ app: this,
200
+ httpServer,
201
+ mcpHandler,
202
+ onMcpError: this.onMcpError,
203
+ errorMiddleware: this.errorMiddleware,
204
+ });
205
+ httpServer.on("request", this.expressApp);
206
+ const intendedPort = parseInt(process.env.__PORT ?? "3000", 10);
207
+ await new Promise((resolve, reject) => {
208
+ httpServer.on("error", (error) => {
209
+ console.error("Failed to start server:", error);
210
+ reject(error);
211
+ });
212
+ httpServer.listen(intendedPort, () => {
213
+ resolve();
214
+ });
215
+ });
216
+ const { port } = httpServer.address();
217
+ process.send?.({ type: "skybridge:listening", port });
218
+ // On workerd, bridge the Node http server to a Workers fetch handler.
219
+ // The specifier is held in a variable to sidestep tsc's module resolution
220
+ // (`cloudflare:node` only exists under wrangler/workerd).
221
+ if (typeof navigator !== "undefined" &&
222
+ navigator.userAgent === "Cloudflare-Workers") {
223
+ const cloudflareNode = "cloudflare:node";
224
+ const { httpServerHandler } = await import(cloudflareNode);
225
+ return httpServerHandler({ port });
226
+ }
227
+ const shutdown = () => {
228
+ // Drop both handlers so a second signal falls through to Node's default
229
+ // (force-quit on a second Ctrl+C while drain is hanging).
230
+ process.off("SIGTERM", shutdown);
231
+ process.off("SIGINT", shutdown);
232
+ mcpHandler.close().catch(() => { });
233
+ httpServer.close(() => process.exit(0));
234
+ // Force exit if connections don't drain in time so the port is still
235
+ // released promptly (e.g. for nodemon restarts).
236
+ setTimeout(() => process.exit(0), 3000).unref();
237
+ };
238
+ process.on("SIGTERM", shutdown);
239
+ process.on("SIGINT", shutdown);
240
+ return undefined;
241
+ }
242
+ buildServer() {
243
+ const server = new McpServer(this.serverInfo, this.serverOptions, { skills: this.skills, oauth: this.oauthEnabled });
244
+ if (this.resolveResourceMetadataUrl) {
245
+ server.setResourceMetadataUrlResolver(this.resolveResourceMetadataUrl);
246
+ }
247
+ const startedAt = performance.now();
248
+ const built = this.handler(server, this.config);
249
+ const elapsed = performance.now() - startedAt;
250
+ if (typeof built.then === "function") {
251
+ throw new Error("The Skybridge handler must be synchronous — it runs on every request. Load config or secrets in `setup` instead and read them from the handler's second argument.");
252
+ }
253
+ if (elapsed > SLOW_HANDLER_THRESHOLD_MS && !this.slowHandlerWarned) {
254
+ this.slowHandlerWarned = true;
255
+ console.warn(`The Skybridge handler took ${Math.round(elapsed)}ms — it runs on every request, so this cost is paid per request. Move expensive work into \`setup\`, whose result is passed to the handler.`);
256
+ }
257
+ return built;
258
+ }
259
+ instrumentHandlers(server, middleware) {
260
+ const entries = [
261
+ ...middleware,
262
+ ...this.mcpMiddlewareEntries,
263
+ ...server.protocolMiddlewareEntries(),
264
+ ];
265
+ const { requestHandlers, notificationHandlers } = getHandlerMaps(server.server);
266
+ const instrumentMap = (map, isNotification) => {
267
+ for (const [method, handler] of map) {
268
+ map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
269
+ }
270
+ const originalSet = map.set.bind(map);
271
+ map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
272
+ };
273
+ instrumentMap(requestHandlers, false);
274
+ instrumentMap(notificationHandlers, true);
275
+ }
276
+ }
277
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,OAAO,EAAoC,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAA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;gBACpC,GAAG,CAAC,GAAG,CACL,MAAM,EACN,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,CAC/D,CAAC;YACJ,CAAC;YACD,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtC,GAAG,CAAC,GAAG,GAAG,CACR,MAAc,EACd,OAAiD,EACjD,EAAE,CACF,WAAW,CACT,MAAM,EACN,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,CAC/D,CAAC;QACN,CAAC,CAAC;QAEF,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QACtC,aAAa,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import http from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\nimport type {\n Implementation,\n Server as SdkServer,\n ServerOptions,\n} from \"@modelcontextprotocol/server\";\nimport type { ErrorRequestHandler, Express, RequestHandler } from \"express\";\nimport type { OAuthConfig, OAuthProvider } from \"./auth/index.js\";\nimport { type ResourceMetadataUrlResolver, setupOAuth } from \"./auth/setup.js\";\nimport type { ExtraClaims } from \"./auth.js\";\nimport { buildMcpHandler, createApp, createBaseApp } from \"./express.js\";\nimport { registerMonitoring } from \"./metric.js\";\nimport type { McpMiddlewareEntry } from \"./middleware.js\";\nimport { buildMiddlewareChain, getHandlerMaps } from \"./middleware.js\";\nimport {\n type JsonOptions,\n McpServer,\n type McpServerTypes,\n type ToolDef,\n} from \"./server.js\";\n\nconst SLOW_HANDLER_THRESHOLD_MS = 50;\n\ntype ErrorMiddlewareConfig = {\n path?: string;\n handlers: ErrorRequestHandler[];\n};\n\n/**\n * The `handler` field of {@link SkybridgeConfig}: builds the app's MCP\n * surface. Runs again for **every incoming request**, on a fresh\n * {@link McpServer}, so keep it to registration: pools, clients and any other\n * one-time work belong in `setup`, whose result is the second argument. It\n * must **return** the chained server so `typeof app` carries the registered\n * tool types.\n *\n * @typeParam TConfig - What `setup` resolved to, passed as the second argument.\n */\nexport type SkybridgeHandler<\n TTools extends Record<string, ToolDef>,\n TConfig,\n TAuthExtra extends ExtraClaims,\n> = (\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n config: TConfig,\n) => McpServer<TTools, TAuthExtra>;\n\n/**\n * What the `oauth` field accepts: an {@link OAuthConfig}, a provider\n * (`oauth: auth0Provider(...)`), or a function of the `setup` result returning\n * either. Providers and functions resolve once, at {@link Skybridge.run} or on\n * the first request, never at module import. Anything asynchronous belongs in\n * a provider's `resolve`.\n */\nexport type SkybridgeOAuthInput<TConfig, TExtra extends ExtraClaims> =\n | OAuthConfig<TExtra>\n | OAuthProvider<TExtra>\n | ((config: TConfig) => OAuthConfig<TExtra> | OAuthProvider<TExtra>);\n\nasync function resolveOAuthInput<TConfig, TExtra extends ExtraClaims>(\n input: SkybridgeOAuthInput<TConfig, TExtra> | undefined,\n config: TConfig,\n): Promise<OAuthConfig<TExtra> | undefined> {\n const resolved = typeof input === \"function\" ? input(config) : input;\n return resolved && \"resolve\" in resolved\n ? await resolved.resolve()\n : resolved;\n}\n\n/**\n * Everything a Skybridge app needs in one bag: the MCP implementation info\n * (`name`, `version`, …), the SDK's {@link ServerOptions} (`capabilities`,\n * `instructions`, …), the Express and skills options, and the app's behavior\n * (`setup`, `oauth`, `handler`).\n *\n * All type parameters are inferred from the value: the config from `setup`,\n * the auth claims from `oauth`, and the tool registry from the server\n * `handler` returns.\n */\nexport type SkybridgeConfig<\n TTools extends Record<string, ToolDef> = Record<never, ToolDef>,\n TConfig = undefined,\n TAuthExtra extends ExtraClaims = ExtraClaims,\n> = Implementation &\n ServerOptions & {\n /** Options for the built-in `express.json()` middleware, e.g. `{ limit: \"10mb\" }`. */\n json?: JsonOptions;\n /**\n * @experimental Serve Agent Skills from `src/skills` over MCP (SEP-2640).\n * API may change.\n */\n skills?: boolean;\n /**\n * Replaces the error reporter of the built-in `/mcp` handler. Receives every\n * error the MCP SDK handler or its Node adapter reports: rejected requests,\n * including the `UnsupportedProtocolVersionError` the default skips, and\n * failures to build or serve the per-request server. Reporting only: the\n * response does not change. It can run before the response is sent, so keep\n * it fast and synchronous. Default: `console.error` for every error the MCP\n * SDK handler reports, except `UnsupportedProtocolVersionError`. Node\n * adapter errors are not logged by default.\n */\n onMcpError?: (error: Error) => void;\n /**\n * Loads whatever the app needs up front (remote config, secrets, datasets,\n * …). Runs **once** — at {@link Skybridge.run} or on the first request,\n * never at module import — and its awaited return value is passed to an\n * `oauth` function and to `handler` as the second argument.\n */\n setup?: () => TConfig;\n /**\n * Resource-server OAuth. When set, mounts the well-known metadata routes\n * and bearer auth on `/mcp`, and the verifier's claims type\n * `extra.http.authInfo.extra` in tool handlers.\n */\n oauth?: SkybridgeOAuthInput<Awaited<TConfig>, TAuthExtra>;\n /** Registers the MCP surface, per request. See {@link SkybridgeHandler}. */\n handler: SkybridgeHandler<TTools, Awaited<TConfig>, TAuthExtra>;\n };\n\n/**\n * A Skybridge app: the HTTP surface (Express, OAuth metadata, the `/mcp`\n * route) plus a handler that builds the MCP server for each request.\n *\n * The handler runs for every request, so tools, resources, prompts and views\n * are always registered on the instance that serves the request. Anything in\n * the handler body other than registration therefore runs per request too.\n * Anything asynchronous the app needs (remote config, secrets, …) goes in\n * `setup`, which runs once and feeds the handler's second argument.\n *\n * @example\n * ```ts\n * export const app = new Skybridge({\n * name: \"my-app\",\n * version: \"1.0.0\",\n * setup: async () => loadConfig(),\n * oauth: (config) => descopeProvider({ url: config.mcpServerUrl }),\n * handler: (server, config) =>\n * server.registerTool(\n * {\n * name: \"search\",\n * inputSchema: { query: z.string() },\n * view: { component: \"search\" },\n * },\n * async ({ query }) => ({ content: `Results for ${query}` }),\n * ),\n * });\n *\n * export type AppType = typeof app;\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/mcp-server\n */\nexport class Skybridge<\n TTools extends Record<string, ToolDef> = Record<never, ToolDef>,\n TConfig = undefined,\n TAuthExtra extends ExtraClaims = ExtraClaims,\n> {\n declare readonly $types: McpServerTypes<TTools>;\n private readonly serverInfo: Implementation;\n private readonly serverOptions: ServerOptions;\n private readonly skills?: boolean;\n private oauthEnabled = false;\n private readonly handler: SkybridgeHandler<\n TTools,\n Awaited<TConfig>,\n TAuthExtra\n >;\n private readonly setup?: () => TConfig;\n private readonly oauthInput?: SkybridgeOAuthInput<\n Awaited<TConfig>,\n TAuthExtra\n >;\n private config?: Awaited<TConfig>;\n private readonly expressApp: Express;\n private readonly onMcpError?: (error: Error) => void;\n private readonly errorMiddleware: ErrorMiddlewareConfig[] = [];\n private readonly mcpMiddlewareEntries: McpMiddlewareEntry[] = [];\n private resolveResourceMetadataUrl?: ResourceMetadataUrlResolver;\n private readyPromise?: Promise<void>;\n private slowHandlerWarned = false;\n\n constructor({\n name,\n title,\n version,\n description,\n icons,\n websiteUrl,\n json,\n skills,\n onMcpError,\n setup,\n oauth,\n handler,\n ...serverOptions\n }: SkybridgeConfig<TTools, TConfig, TAuthExtra>) {\n this.serverInfo = { name, title, version, description, icons, websiteUrl };\n this.serverOptions = serverOptions;\n this.skills = skills;\n this.onMcpError = onMcpError;\n this.setup = setup;\n this.oauthInput = oauth;\n this.handler = handler;\n this.expressApp = createBaseApp(json);\n registerMonitoring(this);\n }\n\n /**\n * Resolve `setup` and `oauth`, then wire OAuth onto the Express app. Runs\n * once; every entry point that needs a built server awaits it, and a failed\n * attempt is retried on the next call.\n *\n * @internal\n */\n ready(): Promise<void> {\n this.readyPromise ??= (async () => {\n if (this.setup) {\n this.config = await this.setup();\n }\n const oauth = await resolveOAuthInput(\n this.oauthInput,\n this.config as Awaited<TConfig>,\n );\n this.oauthEnabled = Boolean(oauth);\n const sample = this.buildServer();\n if (oauth) {\n this.resolveResourceMetadataUrl = setupOAuth(\n this.expressApp,\n oauth,\n sample.securitySchemesByTool,\n );\n }\n })().catch((error) => {\n this.readyPromise = undefined;\n throw error;\n });\n return this.readyPromise;\n }\n\n /**\n * The underlying Express app. Use this to extend the HTTP server with\n * custom routes, middleware, or settings — e.g.\n * `app.express.get(\"/health\", ...)`.\n *\n * `express.json()` is pre-applied — tune it via the `json` config field,\n * e.g. `new Skybridge({ name, version, json: { limit: \"10mb\" }, handler })`.\n * Register your handlers before `run()`; after `run()`, dev-mode middleware,\n * the `/mcp` route, and the default error handler are appended in that order.\n *\n * Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work\n * locally and on self-hosted deployments.\n */\n get express(): Express {\n return this.expressApp;\n }\n\n /**\n * Build a fresh server for one stateless HTTP request, as\n * `createMcpHandler`'s factory contract requires: the handler runs again so\n * the SDK's handler closures belong to the instance whose protocol era it\n * stamps. Sharing one instance's handler maps instead would bind them to an\n * instance that is never marked, pinning every request to the 2025 codec and\n * letting concurrent callers overwrite each other's negotiated version.\n *\n * Awaits `setup` and the `oauth` input on first use. Additional middleware\n * wraps the app pipeline for this instance only; it is not registered on the app.\n *\n * @internal\n */\n async createServerInstance(\n middleware: McpMiddlewareEntry[] = [],\n ): Promise<SdkServer> {\n await this.ready();\n const server = this.buildServer();\n this.instrumentHandlers(server, middleware);\n return server.server;\n }\n\n /** Register outer MCP middleware on this app, in registration order. @internal */\n withMcpMiddleware(entry: McpMiddlewareEntry): this {\n this.mcpMiddlewareEntries.push(entry);\n return this;\n }\n\n /**\n * Connect a Skybridge app to an MCP transport. Use this when you're\n * embedding Skybridge in a host that already manages its own transport\n * (e.g. stdio for desktop apps); for HTTP, prefer {@link Skybridge.run}\n * which sets the transport up for you.\n */\n async connect(transport: Parameters<SdkServer[\"connect\"]>[0]): Promise<void> {\n const instance = await this.createServerInstance();\n await instance.connect(transport);\n }\n\n /**\n * Register Express middleware on the underlying app. Mirrors `app.use` —\n * pass handlers directly or a path-prefixed handler list. Register before\n * {@link Skybridge.run}; ordering matches Express.\n *\n * Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work\n * locally and on self-hosted deployments.\n */\n use(...handlers: RequestHandler[]): this;\n use(path: string, ...handlers: RequestHandler[]): this;\n use(\n pathOrHandler: string | RequestHandler,\n ...handlers: RequestHandler[]\n ): this {\n // Branching is load-bearing: Express's `app.use` overloads can't be\n // resolved against a `string | RequestHandler` union, so we narrow.\n if (typeof pathOrHandler === \"string\") {\n this.expressApp.use(pathOrHandler, ...handlers);\n } else {\n this.expressApp.use(pathOrHandler, ...handlers);\n }\n return this;\n }\n\n /**\n * Register Express error-handling middleware to run after the built-in\n * `/mcp` route (or your custom route). Use this to log or transform errors\n * thrown by tool handlers before the default error handler responds.\n *\n * @example\n * ```ts\n * app.useOnError((err, _req, _res, next) => {\n * logger.error(err);\n * next(err);\n * });\n * ```\n */\n useOnError(...handlers: ErrorRequestHandler[]): this;\n useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;\n useOnError(\n pathOrHandler: string | ErrorRequestHandler,\n ...handlers: ErrorRequestHandler[]\n ): this {\n if (typeof pathOrHandler === \"string\") {\n this.errorMiddleware.push({ path: pathOrHandler, handlers });\n } else {\n this.errorMiddleware.push({ handlers: [pathOrHandler, ...handlers] });\n }\n return this;\n }\n\n /**\n * Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),\n * mounts the `/mcp` route, and applies any custom Express middleware\n * registered via {@link Skybridge.use} / {@link Skybridge.useOnError}.\n *\n * On Cloudflare Workers / workerd, returns an object exposing `fetch` so\n * the runtime can bridge incoming requests to the Node HTTP server. On\n * Vercel (`VERCEL === \"1\"`), returns the Express app directly so the\n * serverless function entry can call it as a `(req, res)` handler. On\n * Node, returns `undefined` once listening. When the process was spawned\n * with an IPC channel, the bound port is reported to the parent as\n * `{ type: \"skybridge:listening\", port }`, the readiness signal test runners\n * wait on instead of polling.\n */\n async run(): Promise<\n { fetch: (...args: unknown[]) => unknown } | Express | undefined\n > {\n if (process.env.VERCEL === \"1\") {\n // createApp only reads httpServer inside its dev-only branch\n // (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a\n // bare object passed to satisfy the required parameter.\n const httpServer = http.createServer();\n await createApp({\n app: this,\n httpServer,\n onMcpError: this.onMcpError,\n errorMiddleware: this.errorMiddleware,\n });\n return this.expressApp;\n }\n\n const httpServer = http.createServer();\n const mcpHandler = buildMcpHandler(this, this.onMcpError);\n\n await createApp({\n app: this,\n httpServer,\n mcpHandler,\n onMcpError: this.onMcpError,\n errorMiddleware: this.errorMiddleware,\n });\n\n httpServer.on(\"request\", this.expressApp);\n const intendedPort = parseInt(process.env.__PORT ?? \"3000\", 10);\n await new Promise<void>((resolve, reject) => {\n httpServer.on(\"error\", (error: Error) => {\n console.error(\"Failed to start server:\", error);\n reject(error);\n });\n httpServer.listen(intendedPort, () => {\n resolve();\n });\n });\n\n const { port } = httpServer.address() as AddressInfo;\n process.send?.({ type: \"skybridge:listening\", port });\n\n // On workerd, bridge the Node http server to a Workers fetch handler.\n // The specifier is held in a variable to sidestep tsc's module resolution\n // (`cloudflare:node` only exists under wrangler/workerd).\n if (\n typeof navigator !== \"undefined\" &&\n navigator.userAgent === \"Cloudflare-Workers\"\n ) {\n const cloudflareNode = \"cloudflare:node\";\n const { httpServerHandler } = await import(cloudflareNode);\n return httpServerHandler({ port });\n }\n\n const shutdown = () => {\n // Drop both handlers so a second signal falls through to Node's default\n // (force-quit on a second Ctrl+C while drain is hanging).\n process.off(\"SIGTERM\", shutdown);\n process.off(\"SIGINT\", shutdown);\n mcpHandler.close().catch(() => {});\n httpServer.close(() => process.exit(0));\n // Force exit if connections don't drain in time so the port is still\n // released promptly (e.g. for nodemon restarts).\n setTimeout(() => process.exit(0), 3000).unref();\n };\n process.on(\"SIGTERM\", shutdown);\n process.on(\"SIGINT\", shutdown);\n return undefined;\n }\n\n private buildServer(): McpServer<TTools, TAuthExtra> {\n const server = new McpServer<Record<never, ToolDef>, TAuthExtra>(\n this.serverInfo,\n this.serverOptions,\n { skills: this.skills, oauth: this.oauthEnabled },\n );\n if (this.resolveResourceMetadataUrl) {\n server.setResourceMetadataUrlResolver(this.resolveResourceMetadataUrl);\n }\n const startedAt = performance.now();\n const built = this.handler(server, this.config as Awaited<TConfig>);\n const elapsed = performance.now() - startedAt;\n if (typeof (built as { then?: unknown }).then === \"function\") {\n throw new Error(\n \"The Skybridge handler must be synchronous — it runs on every request. Load config or secrets in `setup` instead and read them from the handler's second argument.\",\n );\n }\n if (elapsed > SLOW_HANDLER_THRESHOLD_MS && !this.slowHandlerWarned) {\n this.slowHandlerWarned = true;\n console.warn(\n `The Skybridge handler took ${Math.round(elapsed)}ms — it runs on every request, so this cost is paid per request. Move expensive work into \\`setup\\`, whose result is passed to the handler.`,\n );\n }\n return built;\n }\n\n private instrumentHandlers(\n server: McpServer<Record<never, ToolDef>, TAuthExtra>,\n middleware: McpMiddlewareEntry[],\n ): void {\n const entries = [\n ...middleware,\n ...this.mcpMiddlewareEntries,\n ...server.protocolMiddlewareEntries(),\n ];\n const { requestHandlers, notificationHandlers } = getHandlerMaps(\n server.server,\n );\n\n const instrumentMap = (\n map: Map<string, (...args: unknown[]) => Promise<unknown>>,\n isNotification: boolean,\n ) => {\n for (const [method, handler] of map) {\n map.set(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n }\n const originalSet = map.set.bind(map);\n map.set = (\n method: string,\n handler: (...args: unknown[]) => Promise<unknown>,\n ) =>\n originalSet(\n method,\n buildMiddlewareChain(method, isNotification, handler, entries),\n );\n };\n\n instrumentMap(requestHandlers, false);\n instrumentMap(notificationHandlers, true);\n }\n}\n"]}
@@ -0,0 +1,178 @@
1
+ import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
2
+ import { describe, expect, it } from "vitest";
3
+ import { Skybridge } from "./app.js";
4
+ const oauthConfig = {
5
+ oauthMetadata: {
6
+ issuer: "https://issuer.example.com",
7
+ authorization_endpoint: "https://issuer.example.com/authorize",
8
+ token_endpoint: "https://issuer.example.com/token",
9
+ response_types_supported: ["code"],
10
+ },
11
+ verifier: {
12
+ verifyAccessToken: async () => ({
13
+ token: "t",
14
+ clientId: "c",
15
+ scopes: [],
16
+ extra: {},
17
+ }),
18
+ },
19
+ };
20
+ describe("Skybridge setup and handler", () => {
21
+ it("resolves setup once and passes the context to the per-request handler", async () => {
22
+ let loads = 0;
23
+ const app = new Skybridge({
24
+ name: "test",
25
+ version: "1.0.0",
26
+ setup: async () => {
27
+ loads++;
28
+ return { greeting: await Promise.resolve("hello") };
29
+ },
30
+ handler: (server, { greeting }) => server.registerTool({ name: "greet", description: "greet" }, async () => ({ content: [{ type: "text", text: greeting }] })),
31
+ });
32
+ expect(loads).toBe(0);
33
+ const call = async () => {
34
+ const client = new Client({ name: "client", version: "1.0.0" });
35
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
36
+ await app.connect(serverTransport);
37
+ await client.connect(clientTransport);
38
+ const result = await client.callTool({ name: "greet" });
39
+ await client.close();
40
+ return result;
41
+ };
42
+ expect(await call()).toMatchObject({
43
+ content: [{ type: "text", text: "hello" }],
44
+ });
45
+ expect(await call()).toMatchObject({
46
+ content: [{ type: "text", text: "hello" }],
47
+ });
48
+ expect(loads).toBe(1);
49
+ });
50
+ it("retries setup after a failed first resolution", async () => {
51
+ let attempts = 0;
52
+ const app = new Skybridge({
53
+ name: "test",
54
+ version: "1.0.0",
55
+ setup: async () => {
56
+ attempts++;
57
+ if (attempts === 1) {
58
+ throw new Error("transient");
59
+ }
60
+ },
61
+ handler: (server) => server,
62
+ });
63
+ const [, first] = InMemoryTransport.createLinkedPair();
64
+ await expect(app.connect(first)).rejects.toThrow("transient");
65
+ const [, second] = InMemoryTransport.createLinkedPair();
66
+ await expect(app.connect(second)).resolves.toBeUndefined();
67
+ expect(attempts).toBe(2);
68
+ });
69
+ it("rejects a handler that returns a promise", async () => {
70
+ const app = new Skybridge({
71
+ name: "test",
72
+ version: "1.0.0",
73
+ // @ts-expect-error the handler runs per request and must stay synchronous
74
+ handler: async (server) => server,
75
+ });
76
+ const [, serverTransport] = InMemoryTransport.createLinkedPair();
77
+ await expect(app.connect(serverTransport)).rejects.toThrow(/must be synchronous/);
78
+ });
79
+ it("resolves an oauth function with the setup config before wiring the routes", async () => {
80
+ let seen;
81
+ const app = new Skybridge({
82
+ name: "test",
83
+ version: "1.0.0",
84
+ setup: () => ({ issuer: "https://issuer.example.com" }),
85
+ oauth: (config) => {
86
+ seen = config;
87
+ return oauthConfig;
88
+ },
89
+ handler: (server) => server,
90
+ });
91
+ expect(seen).toBeUndefined();
92
+ const [, serverTransport] = InMemoryTransport.createLinkedPair();
93
+ await app.connect(serverTransport);
94
+ expect(seen).toEqual({ issuer: "https://issuer.example.com" });
95
+ });
96
+ });
97
+ it("registers outer middleware on the app while preserving its setup lifecycle", async () => {
98
+ let loads = 0;
99
+ const events = [];
100
+ const app = new Skybridge({
101
+ name: "outer-middleware",
102
+ version: "1",
103
+ setup: () => ++loads,
104
+ handler: (server) => server
105
+ .registerTool({ name: "echo" }, () => ({ content: "live" }))
106
+ .mcpMiddleware("tools/call", async (_request, _extra, next) => {
107
+ events.push("app:before");
108
+ const result = await next();
109
+ events.push("app:after");
110
+ return result;
111
+ }),
112
+ });
113
+ const configured = app
114
+ .withMcpMiddleware({
115
+ filter: "tools/call",
116
+ handler: async (_request, _extra, next) => {
117
+ events.push("outer:before");
118
+ const result = await next();
119
+ events.push("outer:after");
120
+ return result;
121
+ },
122
+ })
123
+ .withMcpMiddleware({
124
+ filter: "tools/list",
125
+ handler: (_request, _extra, next) => {
126
+ events.push("list");
127
+ return next();
128
+ },
129
+ });
130
+ const [outer, ordinary, conversation] = await Promise.all([
131
+ configured.createServerInstance(),
132
+ app.createServerInstance(),
133
+ app.createServerInstance([
134
+ {
135
+ filter: "tools/call",
136
+ handler: async (_request, _extra, next) => {
137
+ events.push("conversation:before");
138
+ const result = await next();
139
+ events.push("conversation:after");
140
+ return result;
141
+ },
142
+ },
143
+ ]),
144
+ ]);
145
+ expect(configured).toBe(app);
146
+ expect(outer).not.toBe(ordinary);
147
+ expect(loads).toBe(1);
148
+ for (const [server, expected] of [
149
+ [
150
+ conversation,
151
+ [
152
+ "conversation:before",
153
+ "outer:before",
154
+ "app:before",
155
+ "app:after",
156
+ "outer:after",
157
+ "conversation:after",
158
+ ],
159
+ ],
160
+ [outer, ["outer:before", "app:before", "app:after", "outer:after"]],
161
+ [ordinary, ["outer:before", "app:before", "app:after", "outer:after"]],
162
+ ]) {
163
+ const client = new Client({ name: "test", version: "1" });
164
+ const [a, b] = InMemoryTransport.createLinkedPair();
165
+ try {
166
+ await server.connect(b);
167
+ await client.connect(a);
168
+ events.length = 0;
169
+ await client.callTool({ name: "echo" });
170
+ expect(events).toEqual(expected);
171
+ }
172
+ finally {
173
+ await client.close();
174
+ await server.close();
175
+ }
176
+ }
177
+ });
178
+ //# sourceMappingURL=app.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.test.js","sourceRoot":"","sources":["../../src/server/app.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,WAAW,GAAG;IAClB,aAAa,EAAE;QACb,MAAM,EAAE,4BAA4B;QACpC,sBAAsB,EAAE,sCAAsC;QAC9D,cAAc,EAAE,kCAAkC;QAClD,wBAAwB,EAAE,CAAC,MAAM,CAAC;KACnC;IACD,QAAQ,EAAE;QACR,iBAAiB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YAC9B,KAAK,EAAE,GAAG;YACV,QAAQ,EAAE,GAAG;YACb,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;SACV,CAAC;KACH;CACF,CAAC;AAEF,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;QACrF,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,G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CAAC,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;QACpD,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACxB,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACxB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;YAClB,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACrB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { Client, InMemoryTransport } from \"@modelcontextprotocol/client\";\nimport { describe, expect, it } from \"vitest\";\nimport { Skybridge } from \"./app.js\";\n\nconst oauthConfig = {\n oauthMetadata: {\n issuer: \"https://issuer.example.com\",\n authorization_endpoint: \"https://issuer.example.com/authorize\",\n token_endpoint: \"https://issuer.example.com/token\",\n response_types_supported: [\"code\"],\n },\n verifier: {\n verifyAccessToken: async () => ({\n token: \"t\",\n clientId: \"c\",\n scopes: [],\n extra: {},\n }),\n },\n};\n\ndescribe(\"Skybridge setup and handler\", () => {\n it(\"resolves setup once and passes the context to the per-request handler\", async () => {\n let loads = 0;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: async () => {\n loads++;\n return { greeting: await Promise.resolve(\"hello\") };\n },\n handler: (server, { greeting }) =>\n server.registerTool(\n { name: \"greet\", description: \"greet\" },\n async () => ({ content: [{ type: \"text\", text: greeting }] }),\n ),\n });\n\n expect(loads).toBe(0);\n\n const call = async () => {\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await app.connect(serverTransport);\n await client.connect(clientTransport);\n const result = await client.callTool({ name: \"greet\" });\n await client.close();\n return result;\n };\n\n expect(await call()).toMatchObject({\n content: [{ type: \"text\", text: \"hello\" }],\n });\n expect(await call()).toMatchObject({\n content: [{ type: \"text\", text: \"hello\" }],\n });\n expect(loads).toBe(1);\n });\n\n it(\"retries setup after a failed first resolution\", async () => {\n let attempts = 0;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: async () => {\n attempts++;\n if (attempts === 1) {\n throw new Error(\"transient\");\n }\n },\n handler: (server) => server,\n });\n\n const [, first] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(first)).rejects.toThrow(\"transient\");\n\n const [, second] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(second)).resolves.toBeUndefined();\n expect(attempts).toBe(2);\n });\n\n it(\"rejects a handler that returns a promise\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n // @ts-expect-error the handler runs per request and must stay synchronous\n handler: async (server) => server,\n });\n const [, serverTransport] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(serverTransport)).rejects.toThrow(\n /must be synchronous/,\n );\n });\n\n it(\"resolves an oauth function with the setup config before wiring the routes\", async () => {\n let seen: unknown;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: () => ({ issuer: \"https://issuer.example.com\" }),\n oauth: (config) => {\n seen = config;\n return oauthConfig;\n },\n handler: (server) => server,\n });\n\n expect(seen).toBeUndefined();\n const [, serverTransport] = InMemoryTransport.createLinkedPair();\n await app.connect(serverTransport);\n expect(seen).toEqual({ issuer: \"https://issuer.example.com\" });\n });\n});\n\nit(\"registers outer middleware on the app while preserving its setup lifecycle\", async () => {\n let loads = 0;\n const events: string[] = [];\n const app = new Skybridge({\n name: \"outer-middleware\",\n version: \"1\",\n setup: () => ++loads,\n handler: (server) =>\n server\n .registerTool({ name: \"echo\" }, () => ({ content: \"live\" }))\n .mcpMiddleware(\"tools/call\", async (_request, _extra, next) => {\n events.push(\"app:before\");\n const result = await next();\n events.push(\"app:after\");\n return result;\n }),\n });\n const configured = app\n .withMcpMiddleware({\n filter: \"tools/call\",\n handler: async (_request, _extra, next) => {\n events.push(\"outer:before\");\n const result = await next();\n events.push(\"outer:after\");\n return result;\n },\n })\n .withMcpMiddleware({\n filter: \"tools/list\",\n handler: (_request, _extra, next) => {\n events.push(\"list\");\n return next();\n },\n });\n const [outer, ordinary, conversation] = await Promise.all([\n configured.createServerInstance(),\n app.createServerInstance(),\n app.createServerInstance([\n {\n filter: \"tools/call\",\n handler: async (_request, _extra, next) => {\n events.push(\"conversation:before\");\n const result = await next();\n events.push(\"conversation:after\");\n return result;\n },\n },\n ]),\n ]);\n expect(configured).toBe(app);\n expect(outer).not.toBe(ordinary);\n expect(loads).toBe(1);\n for (const [server, expected] of [\n [\n conversation,\n [\n \"conversation:before\",\n \"outer:before\",\n \"app:before\",\n \"app:after\",\n \"outer:after\",\n \"conversation:after\",\n ],\n ],\n [outer, [\"outer:before\", \"app:before\", \"app:after\", \"outer:after\"]],\n [ordinary, [\"outer:before\", \"app:before\", \"app:after\", \"outer:after\"]],\n ] as const) {\n const client = new Client({ name: \"test\", version: \"1\" });\n const [a, b] = InMemoryTransport.createLinkedPair();\n try {\n await server.connect(b);\n await client.connect(a);\n events.length = 0;\n await client.callTool({ name: \"echo\" });\n expect(events).toEqual(expected);\n } finally {\n await client.close();\n await server.close();\n }\n }\n});\n"]}
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function isCssRequest(id: string): boolean;
3
+ /**
4
+ * Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,
5
+ * so they work both locally and behind tunnels.
6
+ */
7
+ export declare function assetBaseUrlTransform(code: string): string;
8
+ /**
9
+ * Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.
10
+ */
11
+ export declare function assetBaseUrlTransformPlugin(): Plugin;
@@ -0,0 +1,48 @@
1
+ // Mirrors Vite's own `isCSSRequest`: matches the css family of extensions
2
+ // either at the end of the id or right before the query string. Catches both
3
+ // plain `.css` requests and SFC style blocks (e.g. `Foo.vue?vue&type=style&lang.css`).
4
+ const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
5
+ export function isCssRequest(id) {
6
+ return CSS_LANGS_RE.test(id);
7
+ }
8
+ /**
9
+ * Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,
10
+ * so they work both locally and behind tunnels.
11
+ */
12
+ export function assetBaseUrlTransform(code) {
13
+ const assetStringPattern = /(?<!\bfrom\s)(?<!https?:\/\/)(["'`])(\/[^"'`]+\.(svg|png|jpeg|jpg|gif|webp|mp3|mp4|woff|woff2|ttf|eot))\1/g;
14
+ code = code.replace(assetStringPattern, (_match, _quote, assetPath) => {
15
+ return `(window.skybridge?.serverUrl ?? "") + "${assetPath}"`;
16
+ });
17
+ return code;
18
+ }
19
+ /**
20
+ * Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.
21
+ */
22
+ export function assetBaseUrlTransformPlugin() {
23
+ return {
24
+ name: "asset-base-url-transform",
25
+ transform(code, id) {
26
+ if (!code) {
27
+ return null;
28
+ }
29
+ // Vite serves CSS modules as JS that embeds the stylesheet as a string
30
+ // literal. Rewriting `url("/foo.woff2")` inside that string to a JS
31
+ // concatenation expression produces invalid CSS once it lands in a
32
+ // <style> tag. CSS asset URLs are already handled at build time by
33
+ // `experimental.renderBuiltUrl`, so skip CSS requests here.
34
+ if (isCssRequest(id)) {
35
+ return null;
36
+ }
37
+ const transformedCode = assetBaseUrlTransform(code);
38
+ if (transformedCode === code) {
39
+ return null;
40
+ }
41
+ return {
42
+ code: transformedCode,
43
+ map: null,
44
+ };
45
+ },
46
+ };
47
+ }
48
+ //# sourceMappingURL=asset-base-url-transform-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-base-url-transform-plugin.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,6EAA6E;AAC7E,uFAAuF;AACvF,MAAM,YAAY,GAChB,6DAA6D,CAAC;AAEhE,MAAM,UAAU,YAAY,CAAC,EAAU;IACrC,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,kBAAkB,GACtB,4GAA4G,CAAC;IAE/G,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE;QACpE,OAAO,0CAA0C,SAAS,GAAG,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,SAAS,CAAC,IAAI,EAAE,EAAE;YAChB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YACd,CAAC;YAED,uEAAuE;YACvE,oEAAoE;YACpE,mEAAmE;YACnE,mEAAmE;YACnE,4DAA4D;YAC5D,IAAI,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;gBACrB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,eAAe,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;YAEpD,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,GAAG,EAAE,IAAI;aACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from \"vite\";\n\n// Mirrors Vite's own `isCSSRequest`: matches the css family of extensions\n// either at the end of the id or right before the query string. Catches both\n// plain `.css` requests and SFC style blocks (e.g. `Foo.vue?vue&type=style&lang.css`).\nconst CSS_LANGS_RE =\n /\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\\?)/;\n\nexport function isCssRequest(id: string): boolean {\n return CSS_LANGS_RE.test(id);\n}\n\n/**\n * Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,\n * so they work both locally and behind tunnels.\n */\nexport function assetBaseUrlTransform(code: string): string {\n const assetStringPattern =\n /(?<!\\bfrom\\s)(?<!https?:\\/\\/)([\"'`])(\\/[^\"'`]+\\.(svg|png|jpeg|jpg|gif|webp|mp3|mp4|woff|woff2|ttf|eot))\\1/g;\n\n code = code.replace(assetStringPattern, (_match, _quote, assetPath) => {\n return `(window.skybridge?.serverUrl ?? \"\") + \"${assetPath}\"`;\n });\n\n return code;\n}\n\n/**\n * Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.\n */\nexport function assetBaseUrlTransformPlugin(): Plugin {\n return {\n name: \"asset-base-url-transform\",\n transform(code, id) {\n if (!code) {\n return null;\n }\n\n // Vite serves CSS modules as JS that embeds the stylesheet as a string\n // literal. Rewriting `url(\"/foo.woff2\")` inside that string to a JS\n // concatenation expression produces invalid CSS once it lands in a\n // <style> tag. CSS asset URLs are already handled at build time by\n // `experimental.renderBuiltUrl`, so skip CSS requests here.\n if (isCssRequest(id)) {\n return null;\n }\n\n const transformedCode = assetBaseUrlTransform(code);\n\n if (transformedCode === code) {\n return null;\n }\n\n return {\n code: transformedCode,\n map: null,\n };\n },\n };\n}\n"]}