skybridge 0.0.0-dev.e9705ff → 0.0.0-dev.e9be772

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 (358) hide show
  1. package/LICENSE +21 -674
  2. package/README.md +86 -352
  3. package/bin/run.js +5 -0
  4. package/dist/cli/detect-port.d.ts +18 -0
  5. package/dist/cli/detect-port.js +61 -0
  6. package/dist/cli/detect-port.js.map +1 -0
  7. package/dist/cli/header.d.ts +4 -0
  8. package/dist/cli/header.js +6 -0
  9. package/dist/cli/header.js.map +1 -0
  10. package/dist/cli/run-command.d.ts +2 -0
  11. package/dist/cli/run-command.js +43 -0
  12. package/dist/cli/run-command.js.map +1 -0
  13. package/dist/cli/telemetry.d.ts +7 -0
  14. package/dist/cli/telemetry.js +123 -0
  15. package/dist/cli/telemetry.js.map +1 -0
  16. package/dist/cli/use-execute-steps.d.ts +11 -0
  17. package/dist/cli/use-execute-steps.js +36 -0
  18. package/dist/cli/use-execute-steps.js.map +1 -0
  19. package/dist/cli/use-nodemon.d.ts +7 -0
  20. package/dist/cli/use-nodemon.js +76 -0
  21. package/dist/cli/use-nodemon.js.map +1 -0
  22. package/dist/cli/use-typescript-check.d.ts +8 -0
  23. package/dist/cli/use-typescript-check.js +59 -0
  24. package/dist/cli/use-typescript-check.js.map +1 -0
  25. package/dist/commands/build.d.ts +9 -0
  26. package/dist/commands/build.js +46 -0
  27. package/dist/commands/build.js.map +1 -0
  28. package/dist/commands/dev.d.ts +9 -0
  29. package/dist/commands/dev.js +36 -0
  30. package/dist/commands/dev.js.map +1 -0
  31. package/dist/commands/start.d.ts +9 -0
  32. package/dist/commands/start.js +52 -0
  33. package/dist/commands/start.js.map +1 -0
  34. package/dist/commands/telemetry/disable.d.ts +5 -0
  35. package/dist/commands/telemetry/disable.js +14 -0
  36. package/dist/commands/telemetry/disable.js.map +1 -0
  37. package/dist/commands/telemetry/enable.d.ts +5 -0
  38. package/dist/commands/telemetry/enable.js +14 -0
  39. package/dist/commands/telemetry/enable.js.map +1 -0
  40. package/dist/commands/telemetry/status.d.ts +5 -0
  41. package/dist/commands/telemetry/status.js +14 -0
  42. package/dist/commands/telemetry/status.js.map +1 -0
  43. package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
  44. package/dist/server/asset-base-url-transform-plugin.js +34 -0
  45. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  46. package/dist/server/asset-base-url-transform-plugin.test.js +56 -0
  47. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  48. package/dist/server/express.d.ts +11 -0
  49. package/dist/server/express.js +72 -0
  50. package/dist/server/express.js.map +1 -0
  51. package/dist/server/express.test.js +80 -0
  52. package/dist/server/express.test.js.map +1 -0
  53. package/dist/server/index.d.ts +5 -0
  54. package/dist/server/index.js.map +1 -0
  55. package/dist/{src/server → server}/inferUtilityTypes.d.ts +10 -0
  56. package/dist/server/inferUtilityTypes.js.map +1 -0
  57. package/dist/server/middleware.d.ts +124 -0
  58. package/dist/server/middleware.js +93 -0
  59. package/dist/server/middleware.js.map +1 -0
  60. package/dist/server/middleware.test-d.js +75 -0
  61. package/dist/server/middleware.test-d.js.map +1 -0
  62. package/dist/server/middleware.test.js +383 -0
  63. package/dist/server/middleware.test.js.map +1 -0
  64. package/dist/server/server.d.ts +147 -0
  65. package/dist/server/server.js +275 -0
  66. package/dist/server/server.js.map +1 -0
  67. package/dist/{src/server → server}/templateHelper.d.ts +3 -0
  68. package/dist/{src/server → server}/templateHelper.js +5 -4
  69. package/dist/server/templateHelper.js.map +1 -0
  70. package/dist/server/templates/development.hbs +12 -0
  71. package/dist/{src/server → server}/templates/production.hbs +1 -1
  72. package/dist/{src/server → server}/widgetsDevServer.d.ts +3 -2
  73. package/dist/server/widgetsDevServer.js +57 -0
  74. package/dist/server/widgetsDevServer.js.map +1 -0
  75. package/dist/{src/test → test}/utils.d.ts +54 -8
  76. package/dist/{src/test → test}/utils.js +86 -8
  77. package/dist/test/utils.js.map +1 -0
  78. package/dist/test/widget.test.js +263 -0
  79. package/dist/test/widget.test.js.map +1 -0
  80. package/dist/web/bridges/apps-sdk/adaptor.d.ts +22 -0
  81. package/dist/web/bridges/apps-sdk/adaptor.js +75 -0
  82. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
  83. package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
  84. package/dist/web/bridges/apps-sdk/bridge.js +46 -0
  85. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
  86. package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
  87. package/dist/web/bridges/apps-sdk/index.js +5 -0
  88. package/dist/web/bridges/apps-sdk/index.js.map +1 -0
  89. package/dist/{src/web → web/bridges/apps-sdk}/types.d.ts +37 -49
  90. package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
  91. package/dist/web/bridges/apps-sdk/types.js.map +1 -0
  92. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
  93. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
  94. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
  95. package/dist/web/bridges/get-adaptor.d.ts +2 -0
  96. package/dist/web/bridges/get-adaptor.js +8 -0
  97. package/dist/web/bridges/get-adaptor.js.map +1 -0
  98. package/dist/web/bridges/index.d.ts +5 -0
  99. package/dist/web/bridges/index.js +6 -0
  100. package/dist/web/bridges/index.js.map +1 -0
  101. package/dist/web/bridges/mcp-app/adaptor.d.ts +38 -0
  102. package/dist/web/bridges/mcp-app/adaptor.js +184 -0
  103. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
  104. package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
  105. package/dist/web/bridges/mcp-app/bridge.js +102 -0
  106. package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
  107. package/dist/web/bridges/mcp-app/index.d.ts +4 -0
  108. package/dist/web/bridges/mcp-app/index.js +4 -0
  109. package/dist/web/bridges/mcp-app/index.js.map +1 -0
  110. package/dist/web/bridges/mcp-app/types.d.ts +8 -0
  111. package/dist/web/bridges/mcp-app/types.js +2 -0
  112. package/dist/web/bridges/mcp-app/types.js.map +1 -0
  113. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +7 -0
  114. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
  115. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
  116. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
  117. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
  118. package/dist/web/bridges/types.d.ts +102 -0
  119. package/dist/web/bridges/types.js +2 -0
  120. package/dist/web/bridges/types.js.map +1 -0
  121. package/dist/web/bridges/use-host-context.d.ts +2 -0
  122. package/dist/web/bridges/use-host-context.js +8 -0
  123. package/dist/web/bridges/use-host-context.js.map +1 -0
  124. package/dist/web/components/modal-provider.d.ts +4 -0
  125. package/dist/web/components/modal-provider.js +47 -0
  126. package/dist/web/components/modal-provider.js.map +1 -0
  127. package/dist/web/create-store.js +24 -0
  128. package/dist/web/create-store.js.map +1 -0
  129. package/dist/web/create-store.test.js +131 -0
  130. package/dist/web/create-store.test.js.map +1 -0
  131. package/dist/{src/web → web}/data-llm.js +11 -7
  132. package/dist/web/data-llm.js.map +1 -0
  133. package/dist/web/data-llm.test.js +142 -0
  134. package/dist/web/data-llm.test.js.map +1 -0
  135. package/dist/{src/web → web}/generate-helpers.d.ts +11 -8
  136. package/dist/{src/web → web}/generate-helpers.js +5 -3
  137. package/dist/web/generate-helpers.js.map +1 -0
  138. package/dist/{src/web → web}/generate-helpers.test-d.js +59 -3
  139. package/dist/web/generate-helpers.test-d.js.map +1 -0
  140. package/dist/{src/web → web}/generate-helpers.test.js +1 -1
  141. package/dist/web/generate-helpers.test.js.map +1 -0
  142. package/dist/{src/web → web}/helpers/state.js +14 -9
  143. package/dist/web/helpers/state.js.map +1 -0
  144. package/dist/{src/web → web}/helpers/state.test.js +19 -12
  145. package/dist/web/helpers/state.test.js.map +1 -0
  146. package/dist/web/hooks/index.d.ts +11 -0
  147. package/dist/{src/web → web}/hooks/index.js +3 -4
  148. package/dist/web/hooks/index.js.map +1 -0
  149. package/dist/web/hooks/test/utils.d.ts +16 -0
  150. package/dist/web/hooks/test/utils.js +64 -0
  151. package/dist/web/hooks/test/utils.js.map +1 -0
  152. package/dist/{src/web → web}/hooks/use-call-tool.d.ts +3 -2
  153. package/dist/{src/web → web}/hooks/use-call-tool.js +12 -4
  154. package/dist/web/hooks/use-call-tool.js.map +1 -0
  155. package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +1 -1
  156. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
  157. package/dist/{src/web → web}/hooks/use-call-tool.test.js +35 -16
  158. package/dist/web/hooks/use-call-tool.test.js.map +1 -0
  159. package/dist/web/hooks/use-display-mode.d.ts +4 -0
  160. package/dist/web/hooks/use-display-mode.js +9 -0
  161. package/dist/web/hooks/use-display-mode.js.map +1 -0
  162. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  163. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  164. package/dist/{src/web → web}/hooks/use-display-mode.test.js +3 -2
  165. package/dist/web/hooks/use-display-mode.test.js.map +1 -0
  166. package/dist/web/hooks/use-files.d.ts +6 -0
  167. package/dist/web/hooks/use-files.js +9 -0
  168. package/dist/web/hooks/use-files.js.map +1 -0
  169. package/dist/{src/web → web}/hooks/use-files.test.js +11 -6
  170. package/dist/web/hooks/use-files.test.js.map +1 -0
  171. package/dist/web/hooks/use-layout.d.ts +22 -0
  172. package/dist/web/hooks/use-layout.js +23 -0
  173. package/dist/web/hooks/use-layout.js.map +1 -0
  174. package/dist/web/hooks/use-layout.test.js +96 -0
  175. package/dist/web/hooks/use-layout.test.js.map +1 -0
  176. package/dist/web/hooks/use-open-external.d.ts +3 -0
  177. package/dist/web/hooks/use-open-external.js +8 -0
  178. package/dist/web/hooks/use-open-external.js.map +1 -0
  179. package/dist/web/hooks/use-open-external.test.js +65 -0
  180. package/dist/web/hooks/use-open-external.test.js.map +1 -0
  181. package/dist/web/hooks/use-request-modal.d.ts +9 -0
  182. package/dist/web/hooks/use-request-modal.js +16 -0
  183. package/dist/web/hooks/use-request-modal.js.map +1 -0
  184. package/dist/web/hooks/use-request-modal.test.js +57 -0
  185. package/dist/web/hooks/use-request-modal.test.js.map +1 -0
  186. package/dist/web/hooks/use-send-follow-up-message.js +8 -0
  187. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
  188. package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
  189. package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
  190. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  191. package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
  192. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  193. package/dist/{src/web → web}/hooks/use-tool-info.d.ts +13 -2
  194. package/dist/web/hooks/use-tool-info.js +26 -0
  195. package/dist/web/hooks/use-tool-info.js.map +1 -0
  196. package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
  197. package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -5
  198. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
  199. package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
  200. package/dist/web/hooks/use-tool-info.test.js +130 -0
  201. package/dist/web/hooks/use-tool-info.test.js.map +1 -0
  202. package/dist/web/hooks/use-user.d.ts +18 -0
  203. package/dist/web/hooks/use-user.js +19 -0
  204. package/dist/web/hooks/use-user.js.map +1 -0
  205. package/dist/web/hooks/use-user.test.d.ts +1 -0
  206. package/dist/web/hooks/use-user.test.js +94 -0
  207. package/dist/web/hooks/use-user.test.js.map +1 -0
  208. package/dist/{src/web → web}/hooks/use-widget-state.js +11 -11
  209. package/dist/web/hooks/use-widget-state.js.map +1 -0
  210. package/dist/web/hooks/use-widget-state.test.d.ts +1 -0
  211. package/dist/{src/web → web}/hooks/use-widget-state.test.js +12 -8
  212. package/dist/web/hooks/use-widget-state.test.js.map +1 -0
  213. package/dist/{src/web → web}/index.d.ts +5 -4
  214. package/dist/{src/web → web}/index.js +5 -4
  215. package/dist/web/index.js.map +1 -0
  216. package/dist/{src/web → web}/mount-widget.js +9 -1
  217. package/dist/web/mount-widget.js.map +1 -0
  218. package/dist/web/plugin/data-llm.test.d.ts +1 -0
  219. package/dist/web/plugin/data-llm.test.js.map +1 -0
  220. package/dist/web/plugin/plugin.js +54 -0
  221. package/dist/web/plugin/plugin.js.map +1 -0
  222. package/dist/{src/web → web}/plugin/transform-data-llm.js +6 -3
  223. package/dist/web/plugin/transform-data-llm.js.map +1 -0
  224. package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
  225. package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
  226. package/dist/web/plugin/validate-widget.d.ts +5 -0
  227. package/dist/web/plugin/validate-widget.js +27 -0
  228. package/dist/web/plugin/validate-widget.js.map +1 -0
  229. package/dist/web/plugin/validate-widget.test.d.ts +1 -0
  230. package/dist/web/plugin/validate-widget.test.js +42 -0
  231. package/dist/web/plugin/validate-widget.test.js.map +1 -0
  232. package/dist/{src/web → web}/proxy.js +6 -2
  233. package/dist/web/proxy.js.map +1 -0
  234. package/dist/web/types.d.ts +16 -0
  235. package/dist/web/types.js +2 -0
  236. package/dist/web/types.js.map +1 -0
  237. package/package.json +67 -36
  238. package/tsconfig.base.json +28 -0
  239. package/dist/src/server/index.d.ts +0 -4
  240. package/dist/src/server/index.js.map +0 -1
  241. package/dist/src/server/inferUtilityTypes.js.map +0 -1
  242. package/dist/src/server/server.d.ts +0 -48
  243. package/dist/src/server/server.js +0 -62
  244. package/dist/src/server/server.js.map +0 -1
  245. package/dist/src/server/templateHelper.js.map +0 -1
  246. package/dist/src/server/templates/development.hbs +0 -12
  247. package/dist/src/server/widgetsDevServer.js +0 -39
  248. package/dist/src/server/widgetsDevServer.js.map +0 -1
  249. package/dist/src/test/utils.js.map +0 -1
  250. package/dist/src/test/widget.test.js +0 -90
  251. package/dist/src/test/widget.test.js.map +0 -1
  252. package/dist/src/web/create-store.js +0 -25
  253. package/dist/src/web/create-store.js.map +0 -1
  254. package/dist/src/web/create-store.test.js +0 -70
  255. package/dist/src/web/create-store.test.js.map +0 -1
  256. package/dist/src/web/data-llm.js.map +0 -1
  257. package/dist/src/web/data-llm.test.js +0 -76
  258. package/dist/src/web/data-llm.test.js.map +0 -1
  259. package/dist/src/web/generate-helpers.js.map +0 -1
  260. package/dist/src/web/generate-helpers.test-d.js.map +0 -1
  261. package/dist/src/web/generate-helpers.test.js.map +0 -1
  262. package/dist/src/web/helpers/state.js.map +0 -1
  263. package/dist/src/web/helpers/state.test.js.map +0 -1
  264. package/dist/src/web/hooks/index.d.ts +0 -12
  265. package/dist/src/web/hooks/index.js.map +0 -1
  266. package/dist/src/web/hooks/use-call-tool.js.map +0 -1
  267. package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
  268. package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
  269. package/dist/src/web/hooks/use-display-mode.d.ts +0 -4
  270. package/dist/src/web/hooks/use-display-mode.js +0 -7
  271. package/dist/src/web/hooks/use-display-mode.js.map +0 -1
  272. package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
  273. package/dist/src/web/hooks/use-files.d.ts +0 -10
  274. package/dist/src/web/hooks/use-files.js +0 -7
  275. package/dist/src/web/hooks/use-files.js.map +0 -1
  276. package/dist/src/web/hooks/use-files.test.js.map +0 -1
  277. package/dist/src/web/hooks/use-locale.d.ts +0 -1
  278. package/dist/src/web/hooks/use-locale.js +0 -5
  279. package/dist/src/web/hooks/use-locale.js.map +0 -1
  280. package/dist/src/web/hooks/use-locale.test.js +0 -21
  281. package/dist/src/web/hooks/use-locale.test.js.map +0 -1
  282. package/dist/src/web/hooks/use-open-external.d.ts +0 -1
  283. package/dist/src/web/hooks/use-open-external.js +0 -6
  284. package/dist/src/web/hooks/use-open-external.js.map +0 -1
  285. package/dist/src/web/hooks/use-open-external.test.js +0 -24
  286. package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
  287. package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
  288. package/dist/src/web/hooks/use-openai-global.js +0 -23
  289. package/dist/src/web/hooks/use-openai-global.js.map +0 -1
  290. package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
  291. package/dist/src/web/hooks/use-request-modal.js +0 -9
  292. package/dist/src/web/hooks/use-request-modal.js.map +0 -1
  293. package/dist/src/web/hooks/use-request-modal.test.js +0 -24
  294. package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
  295. package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
  296. package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
  297. package/dist/src/web/hooks/use-theme.d.ts +0 -1
  298. package/dist/src/web/hooks/use-theme.js +0 -5
  299. package/dist/src/web/hooks/use-theme.js.map +0 -1
  300. package/dist/src/web/hooks/use-theme.test.js +0 -26
  301. package/dist/src/web/hooks/use-theme.test.js.map +0 -1
  302. package/dist/src/web/hooks/use-tool-info.js +0 -22
  303. package/dist/src/web/hooks/use-tool-info.js.map +0 -1
  304. package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
  305. package/dist/src/web/hooks/use-tool-info.test.js +0 -59
  306. package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
  307. package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
  308. package/dist/src/web/hooks/use-user-agent.js +0 -5
  309. package/dist/src/web/hooks/use-user-agent.js.map +0 -1
  310. package/dist/src/web/hooks/use-user-agent.test.js +0 -31
  311. package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
  312. package/dist/src/web/hooks/use-widget-state.js.map +0 -1
  313. package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
  314. package/dist/src/web/index.js.map +0 -1
  315. package/dist/src/web/mount-widget.js.map +0 -1
  316. package/dist/src/web/plugin/data-llm.test.js.map +0 -1
  317. package/dist/src/web/plugin/plugin.js +0 -33
  318. package/dist/src/web/plugin/plugin.js.map +0 -1
  319. package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
  320. package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
  321. package/dist/src/web/proxy.js.map +0 -1
  322. package/dist/src/web/types.js.map +0 -1
  323. package/dist/vitest.config.d.ts +0 -2
  324. package/dist/vitest.config.js +0 -8
  325. package/dist/vitest.config.js.map +0 -1
  326. /package/dist/{src/test/widget.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
  327. /package/dist/{src/web/create-store.test.d.ts → server/express.test.d.ts} +0 -0
  328. /package/dist/{src/server → server}/index.js +0 -0
  329. /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
  330. /package/dist/{src/web/data-llm.test.d.ts → server/middleware.test-d.d.ts} +0 -0
  331. /package/dist/{src/web/generate-helpers.test-d.d.ts → server/middleware.test.d.ts} +0 -0
  332. /package/dist/{src/web/generate-helpers.test.d.ts → test/widget.test.d.ts} +0 -0
  333. /package/dist/{src/web/helpers/state.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
  334. /package/dist/{src/web → web}/create-store.d.ts +0 -0
  335. /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → web/create-store.test.d.ts} +0 -0
  336. /package/dist/{src/web → web}/data-llm.d.ts +0 -0
  337. /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
  338. /package/dist/{src/web/hooks/use-call-tool.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
  339. /package/dist/{src/web/hooks/use-display-mode.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
  340. /package/dist/{src/web → web}/helpers/state.d.ts +0 -0
  341. /package/dist/{src/web/hooks/use-files.test.d.ts → web/helpers/state.test.d.ts} +0 -0
  342. /package/dist/{src/web/hooks/use-locale.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
  343. /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
  344. /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/hooks/use-display-mode.test-d.d.ts} +0 -0
  345. /package/dist/{src/web/hooks/use-theme.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
  346. /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/hooks/use-files.test.d.ts} +0 -0
  347. /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-layout.test.d.ts} +0 -0
  348. /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/hooks/use-open-external.test.d.ts} +0 -0
  349. /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-request-modal.test.d.ts} +0 -0
  350. /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
  351. /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-set-open-in-app-url.test.d.ts} +0 -0
  352. /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
  353. /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
  354. /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
  355. /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
  356. /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
  357. /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
  358. /package/dist/{src/web → web}/proxy.d.ts +0 -0
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Command } from "@oclif/core";
3
+ import { Box, render, Text } from "ink";
4
+ import { getMachineId, isEnabled } from "../../cli/telemetry.js";
5
+ export default class TelemetryStatus extends Command {
6
+ static description = "Get Skybridge current telemetry settings for this machine";
7
+ async run() {
8
+ await this.parse(TelemetryStatus);
9
+ const enabled = isEnabled();
10
+ const App = () => (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Text, { bold: true, underline: true, children: "Skybridge Telemetry" }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { children: "Status: " }), enabled ? (_jsx(Text, { color: "green", bold: true, children: "Enabled" })) : (_jsx(Text, { color: "yellow", bold: true, children: "Disabled" }))] }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "gray", children: "Machine ID: " }), _jsx(Text, { children: getMachineId() })] })] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { color: "gray", children: "To opt out, run: skybridge telemetry disable" }), _jsx(Text, { color: "gray", children: "Or set: SKYBRIDGE_TELEMETRY_DISABLED=1" }), _jsx(Text, { color: "gray", children: "Debug mode: SKYBRIDGE_TELEMETRY_DEBUG=1" })] })] }));
11
+ render(_jsx(App, {}));
12
+ }
13
+ }
14
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/commands/telemetry/status.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAClD,MAAM,CAAU,WAAW,GACzB,2DAA2D,CAAC;IAEvD,KAAK,CAAC,GAAG;QACd,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;QAE5B,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,CAChB,MAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,EAAC,OAAO,EAAE,CAAC,aACpC,KAAC,IAAI,IAAC,IAAI,QAAC,SAAS,0CAEb,EAEP,MAAC,GAAG,IAAC,SAAS,EAAE,CAAC,EAAE,aAAa,EAAC,QAAQ,aACvC,MAAC,GAAG,eACF,KAAC,IAAI,2BAAgB,EACpB,OAAO,CAAC,CAAC,CAAC,CACT,KAAC,IAAI,IAAC,KAAK,EAAC,OAAO,EAAC,IAAI,8BAEjB,CACR,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IAAC,KAAK,EAAC,QAAQ,EAAC,IAAI,+BAElB,CACR,IACG,EAEN,MAAC,GAAG,IAAC,SAAS,EAAE,CAAC,aACf,KAAC,IAAI,IAAC,KAAK,EAAC,MAAM,6BAAoB,EACtC,KAAC,IAAI,cAAE,YAAY,EAAE,GAAQ,IACzB,IACF,EAEN,MAAC,GAAG,IAAC,SAAS,EAAE,CAAC,EAAE,aAAa,EAAC,QAAQ,aACvC,KAAC,IAAI,IAAC,KAAK,EAAC,MAAM,6DAAoD,EACtE,KAAC,IAAI,IAAC,KAAK,EAAC,MAAM,uDAA8C,EAChE,KAAC,IAAI,IAAC,KAAK,EAAC,MAAM,wDAA+C,IAC7D,IACF,CACP,CAAC;QAEF,MAAM,CAAC,KAAC,GAAG,KAAG,CAAC,CAAC;IAClB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Transforms asset import paths to use the development server base URL.
4
+ */
5
+ export declare function assetBaseUrlTransform(code: string, devServerOrigin: string): string;
6
+ /**
7
+ * Vite plugin that transforms asset import paths to use the development server base URL.
8
+ */
9
+ export declare function assetBaseUrlTransformPlugin(options: {
10
+ devServerOrigin: string;
11
+ }): Plugin;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Transforms asset import paths to use the development server base URL.
3
+ */
4
+ export function assetBaseUrlTransform(code, devServerOrigin) {
5
+ const assetStringPattern = /(?<!https?:\/\/)(["'`])(\/[^"'`]+\.(svg|png|jpeg|jpg|gif|webp|mp3|mp4|woff|woff2|ttf|eot))\1/g;
6
+ code = code.replace(assetStringPattern, (_match, quote, assetPath) => {
7
+ return `${quote}${devServerOrigin}${assetPath}${quote}`;
8
+ });
9
+ return code;
10
+ }
11
+ /**
12
+ * Vite plugin that transforms asset import paths to use the development server base URL.
13
+ */
14
+ export function assetBaseUrlTransformPlugin(options) {
15
+ const { devServerOrigin } = options;
16
+ return {
17
+ name: "asset-base-url-transform",
18
+ enforce: "pre",
19
+ transform(code) {
20
+ if (!code) {
21
+ return null;
22
+ }
23
+ const transformedCode = assetBaseUrlTransform(code, devServerOrigin);
24
+ if (transformedCode === code) {
25
+ return null;
26
+ }
27
+ return {
28
+ code: transformedCode,
29
+ map: null,
30
+ };
31
+ },
32
+ };
33
+ }
34
+ //# 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;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAY,EACZ,eAAuB;IAEvB,MAAM,kBAAkB,GACtB,+FAA+F,CAAC;IAElG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;QACnE,OAAO,GAAG,KAAK,GAAG,eAAe,GAAG,SAAS,GAAG,KAAK,EAAE,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAE3C;IACC,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEpC,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,IAAI;YACZ,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,eAAe,GAAG,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YAErE,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"}
@@ -0,0 +1,56 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { assetBaseUrlTransform } from "./asset-base-url-transform-plugin.js";
3
+ describe("assetBaseUrlTransform", () => {
4
+ const devServerOrigin = "http://localhost:3000";
5
+ it("should transform asset paths in single, double, and backtick quotes", () => {
6
+ const cases = [
7
+ {
8
+ desc: "single-quoted",
9
+ code: `const image = '/assets/logo.png';`,
10
+ expected: `const image = '${devServerOrigin}/assets/logo.png';`,
11
+ },
12
+ {
13
+ desc: "double-quoted",
14
+ code: `const image = "/assets/logo.png";`,
15
+ expected: `const image = "${devServerOrigin}/assets/logo.png";`,
16
+ },
17
+ {
18
+ desc: "backtick-quoted",
19
+ code: "const image = `/assets/logo.png`;",
20
+ expected: `const image = \`${devServerOrigin}/assets/logo.png\`;`,
21
+ },
22
+ ];
23
+ for (const { code, expected } of cases) {
24
+ const result = assetBaseUrlTransform(code, devServerOrigin);
25
+ expect(result).toBe(expected);
26
+ }
27
+ });
28
+ it("should transform multiple asset paths", () => {
29
+ const code = `
30
+ const logo = '/assets/logo.png';
31
+ const icon = '/assets/icon.svg';
32
+ const font = '/assets/font.woff2';
33
+ `;
34
+ const result = assetBaseUrlTransform(code, devServerOrigin);
35
+ expect(result).toContain(`${devServerOrigin}/assets/logo.png`);
36
+ expect(result).toContain(`${devServerOrigin}/assets/icon.svg`);
37
+ expect(result).toContain(`${devServerOrigin}/assets/font.woff2`);
38
+ });
39
+ it("should not transform already absolute URLs", () => {
40
+ const code = `
41
+ const local = '/assets/logo.png';
42
+ const http = 'http://example.com/image.png';
43
+ const https = 'https://example.com/image.png';
44
+ `;
45
+ const result = assetBaseUrlTransform(code, devServerOrigin);
46
+ expect(result).toContain(`${devServerOrigin}/assets/logo.png`);
47
+ expect(result).toContain("http://example.com/image.png");
48
+ expect(result).toContain("https://example.com/image.png");
49
+ });
50
+ it("should not transform code without asset paths", () => {
51
+ const code = `const text = "Hello World";`;
52
+ const result = assetBaseUrlTransform(code, devServerOrigin);
53
+ expect(result).toBe(code);
54
+ });
55
+ });
56
+ //# sourceMappingURL=asset-base-url-transform-plugin.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-base-url-transform-plugin.test.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,MAAM,eAAe,GAAG,uBAAuB,CAAC;IAEhD,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;QAC7E,MAAM,KAAK,GAAG;YACZ;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,mCAAmC;gBACzC,QAAQ,EAAE,kBAAkB,eAAe,oBAAoB;aAChE;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,mCAAmC;gBACzC,QAAQ,EAAE,kBAAkB,eAAe,oBAAoB;aAChE;YACD;gBACE,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,mCAAmC;gBACzC,QAAQ,EAAE,mBAAmB,eAAe,qBAAqB;aAClE;SACF,CAAC;QAEF,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,KAAK,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YAC5D,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,IAAI,GAAG;;;;KAIZ,CAAC;QACF,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAE5D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,eAAe,kBAAkB,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,eAAe,kBAAkB,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,eAAe,oBAAoB,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,IAAI,GAAG;;;;KAIZ,CAAC;QACF,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAE5D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,eAAe,kBAAkB,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,+BAA+B,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,IAAI,GAAG,6BAA6B,CAAC;QAC3C,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAE5D,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type http from "node:http";
2
+ import express from "express";
3
+ import type { McpServer } from "./server";
4
+ export declare function createApp({ mcpServer, httpServer, customMiddleware, }: {
5
+ mcpServer: McpServer;
6
+ httpServer: http.Server;
7
+ customMiddleware?: {
8
+ path?: string;
9
+ handlers: express.RequestHandler[];
10
+ }[];
11
+ }): Promise<express.Express>;
@@ -0,0 +1,72 @@
1
+ import path from "node:path";
2
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3
+ import cors from "cors";
4
+ import express from "express";
5
+ export async function createApp({ mcpServer, httpServer, customMiddleware = [], }) {
6
+ const app = express();
7
+ app.use(express.json());
8
+ const env = process.env.NODE_ENV || "development";
9
+ for (const middleware of customMiddleware) {
10
+ if (middleware.path) {
11
+ app.use(middleware.path, ...middleware.handlers);
12
+ }
13
+ else {
14
+ app.use(...middleware.handlers);
15
+ }
16
+ }
17
+ if (env !== "production") {
18
+ const { devtoolsStaticServer } = await import("@skybridge/devtools");
19
+ app.use(await devtoolsStaticServer());
20
+ const { widgetsDevServer } = await import("./widgetsDevServer.js");
21
+ app.use(await widgetsDevServer(httpServer));
22
+ }
23
+ if (env === "production") {
24
+ const assetsPath = path.join(process.cwd(), "dist", "assets");
25
+ app.use("/assets", cors());
26
+ app.use("/assets", express.static(assetsPath));
27
+ }
28
+ app.use("/mcp", mcpMiddleware(mcpServer));
29
+ return app;
30
+ }
31
+ const mcpMiddleware = (server) => {
32
+ return async (req, res, _next) => {
33
+ if (req.method !== "POST") {
34
+ res.writeHead(405).end(JSON.stringify({
35
+ jsonrpc: "2.0",
36
+ error: {
37
+ code: -32000,
38
+ message: "Method not allowed.",
39
+ },
40
+ id: null,
41
+ }));
42
+ return;
43
+ }
44
+ try {
45
+ const transport = new StreamableHTTPServerTransport({
46
+ sessionIdGenerator: undefined,
47
+ });
48
+ res.on("close", () => {
49
+ transport.close();
50
+ });
51
+ await server.connect(transport);
52
+ // Express strips the mount path from req.url (e.g. "/mcp" becomes "/").
53
+ // Restore it so the SDK builds the correct requestInfo.url.
54
+ req.url = req.originalUrl;
55
+ await transport.handleRequest(req, res, req.body);
56
+ }
57
+ catch (error) {
58
+ console.error("Error handling MCP request:", error);
59
+ if (!res.headersSent) {
60
+ res.status(500).json({
61
+ jsonrpc: "2.0",
62
+ error: {
63
+ code: -32603,
64
+ message: "Internal server error",
65
+ },
66
+ id: null,
67
+ });
68
+ }
69
+ }
70
+ };
71
+ };
72
+ //# sourceMappingURL=express.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC9B,SAAS,EACT,UAAU,EACV,gBAAgB,GAAG,EAAE,GAKtB;IACC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IAElD,KAAK,MAAM,UAAU,IAAI,gBAAgB,EAAE,CAAC;QAC1C,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;YACpB,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,IAAI,GAAG,KAAK,YAAY,EAAE,CAAC;QACzB,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;QACrE,GAAG,CAAC,GAAG,CAAC,MAAM,oBAAoB,EAAE,CAAC,CAAC;QACtC,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;QACnE,GAAG,CAAC,GAAG,CA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D;YAC5D,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC;YAC1B,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;YACpD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,CAAC,KAAK;wBACZ,OAAO,EAAE,uBAAuB;qBACjC;oBACD,EAAE,EAAE,IAAI;iBACT,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,80 @@
1
+ import http from "node:http";
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ vi.mock("@skybridge/devtools", () => ({
4
+ devtoolsStaticServer: () => ((_req, _res, next) => next()),
5
+ }));
6
+ vi.mock("./widgetsDevServer.js", () => ({
7
+ widgetsDevServer: (_httpServer) => ((_req, _res, next) => next()),
8
+ }));
9
+ const fakeServer = {};
10
+ async function listen(app) {
11
+ const server = http.createServer(app);
12
+ await new Promise((resolve) => server.listen(0, resolve));
13
+ const port = server.address().port;
14
+ return { port, server };
15
+ }
16
+ let openServer;
17
+ afterEach(() => openServer?.close());
18
+ async function postMcp(port) {
19
+ return fetch(`http://localhost:${port}/mcp`, {
20
+ method: "POST",
21
+ headers: { "Content-Type": "application/json" },
22
+ body: JSON.stringify({ jsonrpc: "2.0", method: "initialize", id: 1 }),
23
+ });
24
+ }
25
+ describe("createApp", () => {
26
+ it("runs global custom middleware before the /mcp handler", async () => {
27
+ const { createApp } = await import("./express.js");
28
+ const calls = [];
29
+ const mw = (_req, _res, next) => {
30
+ calls.push("custom");
31
+ next();
32
+ };
33
+ const httpServer = http.createServer();
34
+ const app = await createApp({
35
+ mcpServer: fakeServer,
36
+ httpServer,
37
+ customMiddleware: [{ handlers: [mw] }],
38
+ });
39
+ const { port, server } = await listen(app);
40
+ openServer = server;
41
+ await postMcp(port);
42
+ expect(calls).toEqual(["custom"]);
43
+ });
44
+ it("runs path-scoped middleware on /mcp", async () => {
45
+ const { createApp } = await import("./express.js");
46
+ const calls = [];
47
+ const mw = (_req, _res, next) => {
48
+ calls.push("auth");
49
+ next();
50
+ };
51
+ const httpServer = http.createServer();
52
+ const app = await createApp({
53
+ mcpServer: fakeServer,
54
+ httpServer,
55
+ customMiddleware: [{ path: "/mcp", handlers: [mw] }],
56
+ });
57
+ const { port, server } = await listen(app);
58
+ openServer = server;
59
+ await postMcp(port);
60
+ expect(calls).toEqual(["auth"]);
61
+ });
62
+ it("allows middleware to short-circuit with 401", async () => {
63
+ const { createApp } = await import("./express.js");
64
+ const reject = (_req, res) => {
65
+ res.status(401).json({ error: "Unauthorized" });
66
+ };
67
+ const httpServer = http.createServer();
68
+ const app = await createApp({
69
+ mcpServer: fakeServer,
70
+ httpServer,
71
+ customMiddleware: [{ path: "/mcp", handlers: [reject] }],
72
+ });
73
+ const { port, server } = await listen(app);
74
+ openServer = server;
75
+ const res = await postMcp(port);
76
+ expect(res.status).toBe(401);
77
+ expect(await res.json()).toEqual({ error: "Unauthorized" });
78
+ });
79
+ });
80
+ //# sourceMappingURL=express.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.test.js","sourceRoot":"","sources":["../../src/server/express.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAG7D,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,oBAAoB,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,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
2
+ export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
3
+ export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
4
+ export { McpServer } from "./server.js";
5
+ export { widgetsDevServer } from "./widgetsDevServer.js";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -51,4 +51,14 @@ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = Extr
51
51
  * ```
52
52
  */
53
53
  export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
54
+ /**
55
+ * Get the responseMetadata type for a specific tool (widget or regular tool).
56
+ * This is inferred from the `_meta` property of the tool callback's return value.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * type SearchMeta = ToolResponseMetadata<MyServer, "search">;
61
+ * ```
62
+ */
63
+ export type ToolResponseMetadata<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["responseMetadata"];
54
64
  export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,124 @@
1
+ import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
+ import type { CallToolResult, CancelTaskResult, ClientNotification, ClientRequest, CompleteResult, EmptyResult, GetPromptResult, GetTaskPayloadResult, GetTaskResult, InitializeResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, ListTasksResult, ListToolsResult, ReadResourceResult, ServerNotification, ServerRequest, ServerResult } from "@modelcontextprotocol/sdk/types.js";
4
+ /**
5
+ * The `extra` context object provided by the MCP SDK to request handlers.
6
+ */
7
+ export type McpExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
8
+ /**
9
+ * A single MCP middleware function following the onion model.
10
+ * Call `next()` to invoke the next middleware or the final handler.
11
+ * For notifications, `extra` is `undefined` (SDK does not provide extra context)
12
+ * and `next()` resolves to `undefined`.
13
+ */
14
+ export type McpMiddlewareFn = (request: {
15
+ method: string;
16
+ params: Record<string, unknown>;
17
+ }, extra: McpExtra | undefined, next: () => Promise<unknown>) => Promise<unknown> | unknown;
18
+ /**
19
+ * MCP methods the server handles (incoming from client).
20
+ */
21
+ export type McpMethodString = ClientRequest["method"] | ClientNotification["method"];
22
+ /** Extract params type for a specific MCP method from SDK unions. */
23
+ export type McpRequestParams<M extends string> = Extract<ClientRequest, {
24
+ method: M;
25
+ }> extends {
26
+ params: infer P;
27
+ } ? P : Extract<ClientNotification, {
28
+ method: M;
29
+ }> extends {
30
+ params: infer P;
31
+ } ? P : Record<string, unknown>;
32
+ /** Resolve extra type: McpExtra for requests, undefined for notifications. */
33
+ export type McpExtraFor<M extends string> = M extends ClientRequest["method"] ? McpExtra : M extends ClientNotification["method"] ? undefined : McpExtra | undefined;
34
+ /** Maps each MCP request method to its SDK result type. */
35
+ interface McpResultMap {
36
+ ping: EmptyResult;
37
+ initialize: InitializeResult;
38
+ "tools/list": ListToolsResult;
39
+ "tools/call": CallToolResult;
40
+ "resources/list": ListResourcesResult;
41
+ "resources/templates/list": ListResourceTemplatesResult;
42
+ "resources/read": ReadResourceResult;
43
+ "resources/subscribe": EmptyResult;
44
+ "resources/unsubscribe": EmptyResult;
45
+ "prompts/list": ListPromptsResult;
46
+ "prompts/get": GetPromptResult;
47
+ "completion/complete": CompleteResult;
48
+ "logging/setLevel": EmptyResult;
49
+ "tasks/get": GetTaskResult;
50
+ "tasks/result": GetTaskPayloadResult;
51
+ "tasks/list": ListTasksResult;
52
+ "tasks/cancel": CancelTaskResult;
53
+ }
54
+ /**
55
+ * Map an MCP method string to its corresponding result type.
56
+ * For request methods, resolves to the specific SDK result type.
57
+ * For wildcard patterns (e.g. `"tools/*"`), resolves to the union of matching result types.
58
+ * For notification methods, resolves to `undefined`.
59
+ * For unknown/unmatched methods, falls back to `ServerResult`.
60
+ */
61
+ export type McpResultFor<M extends string> = M extends keyof McpResultMap ? McpResultMap[M] : M extends `${infer Prefix}/*` ? [McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]] extends [never] ? M extends ToWildcard<ClientNotification["method"]> ? undefined : ServerResult : McpResultMap[keyof McpResultMap & `${Prefix}/${string}`] : M extends ClientNotification["method"] ? undefined : ServerResult;
62
+ /** Typed middleware fn for a specific method — narrows params, extra, and next() result. */
63
+ export type McpTypedMiddlewareFn<M extends string> = (request: {
64
+ method: M;
65
+ params: McpRequestParams<M>;
66
+ }, extra: McpExtraFor<M>, next: () => Promise<McpResultFor<M>>) => Promise<unknown> | unknown;
67
+ /** Extracts `"prefix/*"` from `"prefix/anything"` — distributive over unions. */
68
+ type ToWildcard<T extends string> = T extends `${infer Prefix}/${string}` ? `${Prefix}/*` : never;
69
+ /** Wildcard prefixes derived from method strings (e.g. `"tools/*"` from `"tools/call"`). */
70
+ export type McpWildcard = ToWildcard<McpMethodString>;
71
+ /** Category keywords matching all requests or all notifications. */
72
+ type McpCategory = "request" | "notification";
73
+ /**
74
+ * A single filter pattern for MCP middleware:
75
+ * - Exact method: `"tools/call"`
76
+ * - Wildcard: `"tools/*"`
77
+ * - Category: `"request"` | `"notification"`
78
+ * - Escape hatch: arbitrary string via `string & {}`
79
+ */
80
+ type McpMiddlewareFilterPattern = McpMethodString | McpWildcard | McpCategory | (string & {});
81
+ /**
82
+ * Filter determining which MCP methods a middleware applies to.
83
+ * A single pattern or an array of patterns (OR logic).
84
+ */
85
+ export type McpMiddlewareFilter = McpMiddlewareFilterPattern | McpMiddlewareFilterPattern[];
86
+ /**
87
+ * Internal entry stored for each registered middleware.
88
+ * `filter: null` means catch-all (matches everything).
89
+ */
90
+ export type McpMiddlewareEntry = {
91
+ filter: McpMiddlewareFilter | null;
92
+ handler: McpMiddlewareFn;
93
+ };
94
+ type HandlerMap = Map<string, (...args: unknown[]) => Promise<unknown>>;
95
+ /**
96
+ * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps
97
+ * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible
98
+ * but declared `private` in TypeScript.
99
+ *
100
+ * Validates with `instanceof Map` so an incompatible SDK version fails fast
101
+ * instead of silently breaking.
102
+ */
103
+ export declare function getHandlerMaps(server: Server): {
104
+ requestHandlers: HandlerMap;
105
+ notificationHandlers: HandlerMap;
106
+ };
107
+ /**
108
+ * Check if a single filter pattern matches a given method.
109
+ *
110
+ * - Exact: `"tools/call"` matches only `"tools/call"`
111
+ * - Wildcard: `"tools/*"` matches any method starting with `"tools/"`
112
+ * - Category `"request"`: matches when `isNotification` is false
113
+ * - Category `"notification"`: matches when `isNotification` is true
114
+ */
115
+ export declare function matchesFilter(method: string, filter: string, isNotification: boolean): boolean;
116
+ /**
117
+ * Build an onion-model middleware chain for a specific method.
118
+ *
119
+ * Filters `entries` to those matching `method`, then composes them
120
+ * so the first registered middleware is the outermost layer.
121
+ * `next()` is guarded against multiple calls within a single middleware.
122
+ */
123
+ export declare function buildMiddlewareChain(method: string, isNotification: boolean, originalHandler: (...args: unknown[]) => Promise<unknown>, entries: McpMiddlewareEntry[]): (...args: unknown[]) => Promise<unknown>;
124
+ export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps
3
+ * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible
4
+ * but declared `private` in TypeScript.
5
+ *
6
+ * Validates with `instanceof Map` so an incompatible SDK version fails fast
7
+ * instead of silently breaking.
8
+ */
9
+ export function getHandlerMaps(server) {
10
+ const obj = server;
11
+ if (!("_requestHandlers" in obj && obj._requestHandlers instanceof Map) ||
12
+ !("_notificationHandlers" in obj && obj._notificationHandlers instanceof Map)) {
13
+ throw new Error("Incompatible MCP SDK version: expected _requestHandlers and _notificationHandlers on Server");
14
+ }
15
+ return {
16
+ requestHandlers: obj._requestHandlers,
17
+ notificationHandlers: obj._notificationHandlers,
18
+ };
19
+ }
20
+ /**
21
+ * Check if a single filter pattern matches a given method.
22
+ *
23
+ * - Exact: `"tools/call"` matches only `"tools/call"`
24
+ * - Wildcard: `"tools/*"` matches any method starting with `"tools/"`
25
+ * - Category `"request"`: matches when `isNotification` is false
26
+ * - Category `"notification"`: matches when `isNotification` is true
27
+ */
28
+ export function matchesFilter(method, filter, isNotification) {
29
+ if (filter === "request") {
30
+ return !isNotification;
31
+ }
32
+ if (filter === "notification") {
33
+ return isNotification;
34
+ }
35
+ if (filter.endsWith("/*")) {
36
+ const prefix = filter.slice(0, -1); // "tools/*" → "tools/"
37
+ return method.startsWith(prefix);
38
+ }
39
+ return method === filter;
40
+ }
41
+ function matchesAnyFilter(method, filter, isNotification) {
42
+ if (filter === null) {
43
+ return true;
44
+ }
45
+ if (typeof filter === "string") {
46
+ return matchesFilter(method, filter, isNotification);
47
+ }
48
+ return filter.some((pattern) => matchesFilter(method, pattern, isNotification));
49
+ }
50
+ /**
51
+ * Build an onion-model middleware chain for a specific method.
52
+ *
53
+ * Filters `entries` to those matching `method`, then composes them
54
+ * so the first registered middleware is the outermost layer.
55
+ * `next()` is guarded against multiple calls within a single middleware.
56
+ */
57
+ export function buildMiddlewareChain(method, isNotification, originalHandler, entries) {
58
+ const applicable = entries.filter((entry) => matchesAnyFilter(method, entry.filter, isNotification));
59
+ if (applicable.length === 0) {
60
+ return originalHandler;
61
+ }
62
+ return (...args) => {
63
+ const rawRequest = args[0];
64
+ // SDK calls request handlers as handler(request, extra) but
65
+ // notification handlers as handler(notification) — no extra arg.
66
+ const extra = isNotification ? undefined : args[1];
67
+ const mcpRequest = {
68
+ method,
69
+ params: rawRequest?.params ?? {},
70
+ };
71
+ let index = 0;
72
+ const executeLayer = () => {
73
+ const entry = applicable[index++];
74
+ if (!entry) {
75
+ if (rawRequest) {
76
+ rawRequest.params = mcpRequest.params;
77
+ }
78
+ return originalHandler(...args);
79
+ }
80
+ let nextCalled = false;
81
+ const next = () => {
82
+ if (nextCalled) {
83
+ throw new Error(`next() called multiple times in middleware for "${method}"`);
84
+ }
85
+ nextCalled = true;
86
+ return executeLayer();
87
+ };
88
+ return Promise.resolve(entry.handler(mcpRequest, extra, next));
89
+ };
90
+ return executeLayer();
91
+ };
92
+ }
93
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAyJA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,GAAG,GAAW,MAAM,CAAC;IAE3B,IACE,CAAC,CAAC,kBAAkB,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,YAAY,GAAG,CAAC;QACnE,CAAC,CACC,uBAAuB,IAAI,GAAG,IAAI,GAAG,CAAC,qBAAqB,YAAY,GAAG,CAC3E,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;IACJ,CAAC;IAED,OAAO;QACL,eAAe,EAAE,GAAG,CAAC,gBAA8B;QACnD,oBAAoB,EAAE,GAAG,CAAC,qBAAmC;KAC9D,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EACd,MAAc,EACd,cAAuB;IAEvB,IAAI,MAAM,KAAK,SAAS,EAAE,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C,CAAC;QAClE,4DAA4D;QAC5D,iEAAiE;QACjE,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAE,IAAI,CAAC,CAAC,CAAc,CAAC;QACjE,MAAM,UAAU,GAAG;YACjB,MAAM;YACN,MAAM,EAAG,UAAU,EAAE,MAAkC,IAAI,EAAE;SAC9D,CAAC;QAEF,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,GAAqB,EAAE;YAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;YAClC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,IAAI,UAAU,EAAE,CAAC;oBACf,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;gBACxC,CAAC;gBACD,OAAO,eAAe,CAAC,GAAG,IAAI,CAAC,CAAC;YAClC,CAAC;YAED,IAAI,UAAU,GAAG,KAAK,CAAC;YAEvB,MAAM,IAAI,GAAG,GAAqB,EAAE;gBAClC,IAAI,UAAU,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CACb,mDAAmD,MAAM,GAAG,CAC7D,CAAC;gBACJ,CAAC;gBACD,UAAU,GAAG,IAAI,CAAC;gBAClB,OAAO,YAAY,EAAE,CAAC;YACxB,CAAC,CAAC;YAEF,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC;QAEF,OAAO,YAAY,EAAE,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { expectTypeOf, test } from "vitest";
2
+ const server = null;
3
+ test("request category narrows extra and next() result", () => {
4
+ server.mcpMiddleware("request", async (_request, extra, next) => {
5
+ expectTypeOf(extra).toEqualTypeOf();
6
+ extra.signal;
7
+ const result = await next();
8
+ expectTypeOf(result).toEqualTypeOf();
9
+ return result;
10
+ });
11
+ });
12
+ test("notification category narrows extra and next() result", () => {
13
+ server.mcpMiddleware("notification", async (_request, extra, next) => {
14
+ expectTypeOf(extra).toEqualTypeOf();
15
+ // @ts-expect-error extra is undefined, cannot access .signal
16
+ extra.signal;
17
+ const result = await next();
18
+ expectTypeOf(result).toEqualTypeOf();
19
+ });
20
+ });
21
+ test("exact method tools/call narrows params, extra, and next() result", () => {
22
+ server.mcpMiddleware("tools/call", async (request, extra, next) => {
23
+ expectTypeOf(request.params.name).toBeString();
24
+ expectTypeOf(extra).toEqualTypeOf();
25
+ const result = await next();
26
+ expectTypeOf(result).toEqualTypeOf();
27
+ return result;
28
+ });
29
+ });
30
+ test("exact method tools/list narrows next() to ListToolsResult", () => {
31
+ server.mcpMiddleware("tools/list", async (_request, _extra, next) => {
32
+ const result = await next();
33
+ expectTypeOf(result).toEqualTypeOf();
34
+ return result;
35
+ });
36
+ });
37
+ test("exact notification method narrows extra and next() result", () => {
38
+ server.mcpMiddleware("notifications/initialized", async (_request, extra, next) => {
39
+ expectTypeOf(extra).toEqualTypeOf();
40
+ // @ts-expect-error extra is undefined
41
+ extra.signal;
42
+ const result = await next();
43
+ expectTypeOf(result).toEqualTypeOf();
44
+ });
45
+ });
46
+ test("McpTypedMiddlewareFn narrows params, extra, and next() per method", () => {
47
+ expectTypeOf().toBeString();
48
+ expectTypeOf().toEqualTypeOf();
49
+ expectTypeOf().toEqualTypeOf();
50
+ expectTypeOf().toEqualTypeOf();
51
+ expectTypeOf().toEqualTypeOf();
52
+ });
53
+ test("McpResultFor maps methods to correct result types", () => {
54
+ expectTypeOf().toEqualTypeOf();
55
+ expectTypeOf().toEqualTypeOf();
56
+ expectTypeOf().toEqualTypeOf();
57
+ });
58
+ test("wildcard tools/* narrows next() to union of tools result types", () => {
59
+ server.mcpMiddleware("tools/*", async (_request, _extra, next) => {
60
+ const result = await next();
61
+ expectTypeOf(result).toEqualTypeOf();
62
+ return result;
63
+ });
64
+ });
65
+ test("McpResultFor resolves wildcards to union of matching result types", () => {
66
+ expectTypeOf().toEqualTypeOf();
67
+ });
68
+ test("catch-all middleware has no narrowing on extra or params", () => {
69
+ server.mcpMiddleware((_request, extra, next) => {
70
+ expectTypeOf(extra).toEqualTypeOf();
71
+ expectTypeOf(_request.params).toEqualTypeOf();
72
+ return next();
73
+ });
74
+ });
75
+ //# sourceMappingURL=middleware.test-d.js.map