skybridge 0.0.0-dev.d0367d9 → 0.0.0-dev.d04feba

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 (327) hide show
  1. package/LICENSE +21 -674
  2. package/README.md +89 -142
  3. package/bin/run.js +5 -0
  4. package/dist/cli/header.d.ts +4 -0
  5. package/dist/cli/header.js +6 -0
  6. package/dist/cli/header.js.map +1 -0
  7. package/dist/cli/run-command.d.ts +2 -0
  8. package/dist/cli/run-command.js +43 -0
  9. package/dist/cli/run-command.js.map +1 -0
  10. package/dist/cli/telemetry.d.ts +7 -0
  11. package/dist/cli/telemetry.js +123 -0
  12. package/dist/cli/telemetry.js.map +1 -0
  13. package/dist/cli/use-execute-steps.d.ts +11 -0
  14. package/dist/cli/use-execute-steps.js +36 -0
  15. package/dist/cli/use-execute-steps.js.map +1 -0
  16. package/dist/cli/use-nodemon.d.ts +6 -0
  17. package/dist/cli/use-nodemon.js +61 -0
  18. package/dist/cli/use-nodemon.js.map +1 -0
  19. package/dist/cli/use-typescript-check.d.ts +8 -0
  20. package/dist/cli/use-typescript-check.js +59 -0
  21. package/dist/cli/use-typescript-check.js.map +1 -0
  22. package/dist/commands/build.d.ts +9 -0
  23. package/dist/commands/build.js +46 -0
  24. package/dist/commands/build.js.map +1 -0
  25. package/dist/commands/dev.d.ts +9 -0
  26. package/dist/commands/dev.js +31 -0
  27. package/dist/commands/dev.js.map +1 -0
  28. package/dist/commands/start.d.ts +7 -0
  29. package/dist/commands/start.js +28 -0
  30. package/dist/commands/start.js.map +1 -0
  31. package/dist/commands/telemetry/disable.d.ts +5 -0
  32. package/dist/commands/telemetry/disable.js +14 -0
  33. package/dist/commands/telemetry/disable.js.map +1 -0
  34. package/dist/commands/telemetry/enable.d.ts +5 -0
  35. package/dist/commands/telemetry/enable.js +14 -0
  36. package/dist/commands/telemetry/enable.js.map +1 -0
  37. package/dist/commands/telemetry/status.d.ts +5 -0
  38. package/dist/commands/telemetry/status.js +14 -0
  39. package/dist/commands/telemetry/status.js.map +1 -0
  40. package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
  41. package/dist/server/asset-base-url-transform-plugin.js +34 -0
  42. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  43. package/dist/server/asset-base-url-transform-plugin.test.js +56 -0
  44. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  45. package/dist/server/express.d.ts +5 -0
  46. package/dist/server/express.js +63 -0
  47. package/dist/server/express.js.map +1 -0
  48. package/dist/server/index.d.ts +4 -0
  49. package/dist/server/index.js.map +1 -0
  50. package/dist/server/inferUtilityTypes.d.ts +64 -0
  51. package/dist/server/inferUtilityTypes.js +2 -0
  52. package/dist/server/inferUtilityTypes.js.map +1 -0
  53. package/dist/server/server.d.ts +109 -0
  54. package/dist/server/server.js +201 -0
  55. package/dist/server/server.js.map +1 -0
  56. package/dist/{src/server → server}/templateHelper.d.ts +4 -0
  57. package/dist/{src/server → server}/templateHelper.js +5 -4
  58. package/dist/server/templateHelper.js.map +1 -0
  59. package/dist/server/templates/development.hbs +67 -0
  60. package/dist/{src/server → server}/templates/production.hbs +1 -1
  61. package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
  62. package/dist/server/widgetsDevServer.js +57 -0
  63. package/dist/server/widgetsDevServer.js.map +1 -0
  64. package/dist/test/utils.d.ts +355 -0
  65. package/dist/test/utils.js +242 -0
  66. package/dist/test/utils.js.map +1 -0
  67. package/dist/test/widget.test.js +261 -0
  68. package/dist/test/widget.test.js.map +1 -0
  69. package/dist/web/bridges/apps-sdk/adaptor.d.ts +22 -0
  70. package/dist/web/bridges/apps-sdk/adaptor.js +70 -0
  71. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
  72. package/dist/web/bridges/apps-sdk/bridge.d.ts +14 -0
  73. package/dist/web/bridges/apps-sdk/bridge.js +46 -0
  74. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
  75. package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
  76. package/dist/web/bridges/apps-sdk/index.js +5 -0
  77. package/dist/web/bridges/apps-sdk/index.js.map +1 -0
  78. package/dist/{src/web → web/bridges/apps-sdk}/types.d.ts +31 -33
  79. package/dist/web/bridges/apps-sdk/types.js.map +1 -0
  80. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
  81. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
  82. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
  83. package/dist/web/bridges/get-adaptor.d.ts +2 -0
  84. package/dist/web/bridges/get-adaptor.js +8 -0
  85. package/dist/web/bridges/get-adaptor.js.map +1 -0
  86. package/dist/web/bridges/index.d.ts +5 -0
  87. package/dist/web/bridges/index.js +6 -0
  88. package/dist/web/bridges/index.js.map +1 -0
  89. package/dist/web/bridges/mcp-app/adaptor.d.ts +36 -0
  90. package/dist/web/bridges/mcp-app/adaptor.js +188 -0
  91. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
  92. package/dist/web/bridges/mcp-app/bridge.d.ts +43 -0
  93. package/dist/web/bridges/mcp-app/bridge.js +255 -0
  94. package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
  95. package/dist/web/bridges/mcp-app/index.d.ts +4 -0
  96. package/dist/web/bridges/mcp-app/index.js +4 -0
  97. package/dist/web/bridges/mcp-app/index.js.map +1 -0
  98. package/dist/web/bridges/mcp-app/types.d.ts +8 -0
  99. package/dist/web/bridges/mcp-app/types.js +2 -0
  100. package/dist/web/bridges/mcp-app/types.js.map +1 -0
  101. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -0
  102. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
  103. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
  104. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +66 -0
  105. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
  106. package/dist/web/bridges/types.d.ts +98 -0
  107. package/dist/web/bridges/types.js +2 -0
  108. package/dist/web/bridges/types.js.map +1 -0
  109. package/dist/web/bridges/use-host-context.d.ts +2 -0
  110. package/dist/web/bridges/use-host-context.js +8 -0
  111. package/dist/web/bridges/use-host-context.js.map +1 -0
  112. package/dist/web/components/modal-provider.d.ts +4 -0
  113. package/dist/web/components/modal-provider.js +47 -0
  114. package/dist/web/components/modal-provider.js.map +1 -0
  115. package/dist/web/create-store.d.ts +3 -0
  116. package/dist/web/create-store.js +24 -0
  117. package/dist/web/create-store.js.map +1 -0
  118. package/dist/web/create-store.test.js +126 -0
  119. package/dist/web/create-store.test.js.map +1 -0
  120. package/dist/web/data-llm.d.ts +14 -0
  121. package/dist/web/data-llm.js +72 -0
  122. package/dist/web/data-llm.js.map +1 -0
  123. package/dist/web/data-llm.test.js +141 -0
  124. package/dist/web/data-llm.test.js.map +1 -0
  125. package/dist/web/generate-helpers.d.ts +116 -0
  126. package/dist/web/generate-helpers.js +111 -0
  127. package/dist/web/generate-helpers.js.map +1 -0
  128. package/dist/web/generate-helpers.test-d.js +209 -0
  129. package/dist/web/generate-helpers.test-d.js.map +1 -0
  130. package/dist/web/generate-helpers.test.js +17 -0
  131. package/dist/web/generate-helpers.test.js.map +1 -0
  132. package/dist/web/helpers/state.d.ts +7 -0
  133. package/dist/web/helpers/state.js +45 -0
  134. package/dist/web/helpers/state.js.map +1 -0
  135. package/dist/web/helpers/state.test.js +53 -0
  136. package/dist/web/helpers/state.test.js.map +1 -0
  137. package/dist/{src/web → web}/hooks/index.d.ts +4 -7
  138. package/dist/web/hooks/index.js +12 -0
  139. package/dist/web/hooks/index.js.map +1 -0
  140. package/dist/web/hooks/test/utils.d.ts +16 -0
  141. package/dist/web/hooks/test/utils.js +60 -0
  142. package/dist/web/hooks/test/utils.js.map +1 -0
  143. package/dist/web/hooks/use-call-tool.d.ts +101 -0
  144. package/dist/{src/web → web}/hooks/use-call-tool.js +19 -19
  145. package/dist/web/hooks/use-call-tool.js.map +1 -0
  146. package/dist/web/hooks/use-call-tool.test-d.js +104 -0
  147. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
  148. package/dist/{src/web → web}/hooks/use-call-tool.test.js +40 -13
  149. package/dist/web/hooks/use-call-tool.test.js.map +1 -0
  150. package/dist/{src/web → web}/hooks/use-display-mode.d.ts +1 -1
  151. package/dist/web/hooks/use-display-mode.js +9 -0
  152. package/dist/web/hooks/use-display-mode.js.map +1 -0
  153. package/dist/{src/web → web}/hooks/use-display-mode.test.js +3 -2
  154. package/dist/web/hooks/use-display-mode.test.js.map +1 -0
  155. package/dist/web/hooks/use-files.d.ts +6 -0
  156. package/dist/web/hooks/use-files.js +9 -0
  157. package/dist/web/hooks/use-files.js.map +1 -0
  158. package/dist/{src/web → web}/hooks/use-files.test.js +6 -5
  159. package/dist/web/hooks/use-files.test.js.map +1 -0
  160. package/dist/web/hooks/use-layout.d.ts +22 -0
  161. package/dist/web/hooks/use-layout.js +23 -0
  162. package/dist/web/hooks/use-layout.js.map +1 -0
  163. package/dist/web/hooks/use-layout.test.d.ts +1 -0
  164. package/dist/web/hooks/use-layout.test.js +96 -0
  165. package/dist/web/hooks/use-layout.test.js.map +1 -0
  166. package/dist/web/hooks/use-open-external.js +8 -0
  167. package/dist/web/hooks/use-open-external.js.map +1 -0
  168. package/dist/web/hooks/use-open-external.test.d.ts +1 -0
  169. package/dist/web/hooks/use-open-external.test.js +50 -0
  170. package/dist/web/hooks/use-open-external.test.js.map +1 -0
  171. package/dist/web/hooks/use-request-modal.d.ts +9 -0
  172. package/dist/web/hooks/use-request-modal.js +16 -0
  173. package/dist/web/hooks/use-request-modal.js.map +1 -0
  174. package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
  175. package/dist/web/hooks/use-request-modal.test.js +57 -0
  176. package/dist/web/hooks/use-request-modal.test.js.map +1 -0
  177. package/dist/web/hooks/use-send-follow-up-message.js +8 -0
  178. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
  179. package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
  180. package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
  181. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  182. package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
  183. package/dist/web/hooks/use-set-open-in-app-url.test.js +49 -0
  184. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  185. package/dist/web/hooks/use-tool-info.d.ts +36 -0
  186. package/dist/web/hooks/use-tool-info.js +26 -0
  187. package/dist/web/hooks/use-tool-info.js.map +1 -0
  188. package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
  189. package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -5
  190. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
  191. package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
  192. package/dist/web/hooks/use-tool-info.test.js +130 -0
  193. package/dist/web/hooks/use-tool-info.test.js.map +1 -0
  194. package/dist/web/hooks/use-user.d.ts +18 -0
  195. package/dist/web/hooks/use-user.js +19 -0
  196. package/dist/web/hooks/use-user.js.map +1 -0
  197. package/dist/web/hooks/use-user.test.d.ts +1 -0
  198. package/dist/web/hooks/use-user.test.js +94 -0
  199. package/dist/web/hooks/use-user.test.js.map +1 -0
  200. package/dist/web/hooks/use-widget-state.js +32 -0
  201. package/dist/web/hooks/use-widget-state.js.map +1 -0
  202. package/dist/web/hooks/use-widget-state.test.d.ts +1 -0
  203. package/dist/{src/web → web}/hooks/use-widget-state.test.js +10 -8
  204. package/dist/web/hooks/use-widget-state.test.js.map +1 -0
  205. package/dist/web/index.d.ts +8 -0
  206. package/dist/web/index.js +9 -0
  207. package/dist/web/index.js.map +1 -0
  208. package/dist/{src/web → web}/mount-widget.js +9 -1
  209. package/dist/web/mount-widget.js.map +1 -0
  210. package/dist/web/plugin/data-llm.test.d.ts +1 -0
  211. package/dist/web/plugin/data-llm.test.js +81 -0
  212. package/dist/web/plugin/data-llm.test.js.map +1 -0
  213. package/dist/web/plugin/plugin.js +46 -0
  214. package/dist/web/plugin/plugin.js.map +1 -0
  215. package/dist/web/plugin/transform-data-llm.d.ts +12 -0
  216. package/dist/web/plugin/transform-data-llm.js +96 -0
  217. package/dist/web/plugin/transform-data-llm.js.map +1 -0
  218. package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
  219. package/dist/web/plugin/transform-data-llm.test.js +81 -0
  220. package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
  221. package/dist/{src/web → web}/proxy.js +6 -2
  222. package/dist/web/proxy.js.map +1 -0
  223. package/dist/web/types.d.ts +16 -0
  224. package/dist/web/types.js +2 -0
  225. package/dist/web/types.js.map +1 -0
  226. package/package.json +65 -33
  227. package/dist/src/server/index.d.ts +0 -2
  228. package/dist/src/server/index.js.map +0 -1
  229. package/dist/src/server/server.d.ts +0 -13
  230. package/dist/src/server/server.js +0 -57
  231. package/dist/src/server/server.js.map +0 -1
  232. package/dist/src/server/templateHelper.js.map +0 -1
  233. package/dist/src/server/templates/development.hbs +0 -12
  234. package/dist/src/server/widgetsDevServer.js +0 -39
  235. package/dist/src/server/widgetsDevServer.js.map +0 -1
  236. package/dist/src/test/utils.d.ts +0 -28
  237. package/dist/src/test/utils.js +0 -43
  238. package/dist/src/test/utils.js.map +0 -1
  239. package/dist/src/test/widget.test.js +0 -90
  240. package/dist/src/test/widget.test.js.map +0 -1
  241. package/dist/src/web/hooks/index.js +0 -15
  242. package/dist/src/web/hooks/index.js.map +0 -1
  243. package/dist/src/web/hooks/use-call-tool.d.ts +0 -62
  244. package/dist/src/web/hooks/use-call-tool.js.map +0 -1
  245. package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
  246. package/dist/src/web/hooks/use-display-mode.js +0 -7
  247. package/dist/src/web/hooks/use-display-mode.js.map +0 -1
  248. package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
  249. package/dist/src/web/hooks/use-files.d.ts +0 -10
  250. package/dist/src/web/hooks/use-files.js +0 -7
  251. package/dist/src/web/hooks/use-files.js.map +0 -1
  252. package/dist/src/web/hooks/use-files.test.js.map +0 -1
  253. package/dist/src/web/hooks/use-locale.d.ts +0 -1
  254. package/dist/src/web/hooks/use-locale.js +0 -5
  255. package/dist/src/web/hooks/use-locale.js.map +0 -1
  256. package/dist/src/web/hooks/use-locale.test.js +0 -21
  257. package/dist/src/web/hooks/use-locale.test.js.map +0 -1
  258. package/dist/src/web/hooks/use-open-external.js +0 -6
  259. package/dist/src/web/hooks/use-open-external.js.map +0 -1
  260. package/dist/src/web/hooks/use-open-external.test.js +0 -24
  261. package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
  262. package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
  263. package/dist/src/web/hooks/use-openai-global.js +0 -23
  264. package/dist/src/web/hooks/use-openai-global.js.map +0 -1
  265. package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
  266. package/dist/src/web/hooks/use-request-modal.js +0 -9
  267. package/dist/src/web/hooks/use-request-modal.js.map +0 -1
  268. package/dist/src/web/hooks/use-request-modal.test.js +0 -24
  269. package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
  270. package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
  271. package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
  272. package/dist/src/web/hooks/use-theme.d.ts +0 -1
  273. package/dist/src/web/hooks/use-theme.js +0 -5
  274. package/dist/src/web/hooks/use-theme.js.map +0 -1
  275. package/dist/src/web/hooks/use-theme.test.js +0 -26
  276. package/dist/src/web/hooks/use-theme.test.js.map +0 -1
  277. package/dist/src/web/hooks/use-tool-info.d.ts +0 -25
  278. package/dist/src/web/hooks/use-tool-info.js +0 -22
  279. package/dist/src/web/hooks/use-tool-info.js.map +0 -1
  280. package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
  281. package/dist/src/web/hooks/use-tool-info.test.js +0 -59
  282. package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
  283. package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
  284. package/dist/src/web/hooks/use-tool-output.js +0 -9
  285. package/dist/src/web/hooks/use-tool-output.js.map +0 -1
  286. package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
  287. package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
  288. package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
  289. package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
  290. package/dist/src/web/hooks/use-user-agent.js +0 -5
  291. package/dist/src/web/hooks/use-user-agent.js.map +0 -1
  292. package/dist/src/web/hooks/use-user-agent.test.js +0 -31
  293. package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
  294. package/dist/src/web/hooks/use-widget-state.js +0 -30
  295. package/dist/src/web/hooks/use-widget-state.js.map +0 -1
  296. package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
  297. package/dist/src/web/index.d.ts +0 -4
  298. package/dist/src/web/index.js +0 -5
  299. package/dist/src/web/index.js.map +0 -1
  300. package/dist/src/web/mount-widget.js.map +0 -1
  301. package/dist/src/web/plugin.js +0 -28
  302. package/dist/src/web/plugin.js.map +0 -1
  303. package/dist/src/web/proxy.js.map +0 -1
  304. package/dist/src/web/types.js.map +0 -1
  305. package/dist/vitest.config.d.ts +0 -2
  306. package/dist/vitest.config.js +0 -8
  307. package/dist/vitest.config.js.map +0 -1
  308. /package/dist/{src/test/widget.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
  309. /package/dist/{src/server → server}/index.js +0 -0
  310. /package/dist/{src/web/hooks/use-call-tool.test.d.ts → test/widget.test.d.ts} +0 -0
  311. /package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -0
  312. /package/dist/{src/web/hooks/use-display-mode.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
  313. /package/dist/{src/web/hooks/use-files.test.d.ts → web/create-store.test.d.ts} +0 -0
  314. /package/dist/{src/web/hooks/use-locale.test.d.ts → web/data-llm.test.d.ts} +0 -0
  315. /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
  316. /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
  317. /package/dist/{src/web/hooks/use-theme.test.d.ts → web/helpers/state.test.d.ts} +0 -0
  318. /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
  319. /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
  320. /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
  321. /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-files.test.d.ts} +0 -0
  322. /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
  323. /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
  324. /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
  325. /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
  326. /package/dist/{src/web → web/plugin}/plugin.d.ts +0 -0
  327. /package/dist/{src/web → web}/proxy.d.ts +0 -0
@@ -0,0 +1,81 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { transform } from "./transform-data-llm.js";
3
+ describe("data-llm plugin", () => {
4
+ it("should transform JSX element with data-llm string attribute", async () => {
5
+ const code = `
6
+ function Component() {
7
+ return <div data-llm="Test description">Content</div>;
8
+ }
9
+ `;
10
+ const result = await transform(code, "test.tsx");
11
+ expect(result).not.toBeNull();
12
+ expect(result?.code).toContain("DataLLM");
13
+ expect(result?.code).toContain('content="Test description"');
14
+ expect(result?.code).not.toContain("data-llm");
15
+ });
16
+ it("should transform JSX element with data-llm expression attribute", async () => {
17
+ const code = `
18
+ function Component() {
19
+ const desc = "Dynamic description";
20
+ return <div data-llm={desc}>Content</div>;
21
+ }
22
+ `;
23
+ const result = await transform(code, "test.tsx");
24
+ expect(result).not.toBeNull();
25
+ expect(result?.code).toContain("DataLLM");
26
+ expect(result?.code).toContain("content={desc}");
27
+ expect(result?.code).not.toContain("data-llm");
28
+ });
29
+ it("should add import for DataLLM when not present", async () => {
30
+ const code = `
31
+ function Component() {
32
+ return <div data-llm="Test">Content</div>;
33
+ }
34
+ `;
35
+ const result = await transform(code, "test.tsx");
36
+ expect(result).not.toBeNull();
37
+ expect(result?.code).toContain('import { DataLLM } from "skybridge/web"');
38
+ });
39
+ it("should handle DataLLM imports correctly", async () => {
40
+ // No duplicate import
41
+ const codeWithImport = `
42
+ import { DataLLM } from "skybridge/web";
43
+ function Component() {
44
+ return <div data-llm="Test">Content</div>;
45
+ }
46
+ `;
47
+ const result1 = await transform(codeWithImport, "test.tsx");
48
+ expect(result1?.code.match(/import.*DataLLM.*from.*skybridge\/web/g)).toHaveLength(1);
49
+ // Preserve other imports and add missing DataLLM
50
+ const codeWithOthers = `
51
+ import React from "react";
52
+ import { useState } from "react";
53
+ function Component() {
54
+ return <div data-llm="Test">Content</div>;
55
+ }
56
+ `;
57
+ const result2 = await transform(codeWithOthers, "test.tsx");
58
+ expect(result2?.code).toContain('import React from "react"');
59
+ expect(result2?.code).toContain('import { useState } from "react"');
60
+ expect(result2?.code).toContain('import { DataLLM } from "skybridge/web"');
61
+ });
62
+ it("should handle complex JSX with multiple data-llm attributes", async () => {
63
+ const code = `
64
+ function Component() {
65
+ return (
66
+ <div>
67
+ <section data-llm="Section 1">
68
+ <p>Content 1</p>
69
+ </section>
70
+ <section data-llm="Section 2">
71
+ <p>Content 2</p>
72
+ </section>
73
+ </div>
74
+ );
75
+ }
76
+ `;
77
+ const result = await transform(code, "test.tsx");
78
+ expect(result).toMatchSnapshot();
79
+ });
80
+ });
81
+ //# sourceMappingURL=data-llm.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../../src/web/plugin/data-llm.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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ACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { transform as dataLlmTransform } from "./transform-data-llm.js";
2
+ export function skybridge() {
3
+ return {
4
+ name: "skybridge",
5
+ async config(config) {
6
+ // Dynamic imports to ensure Node modules are only loaded in Node.js context
7
+ const { globSync } = await import("node:fs");
8
+ const { basename, dirname, parse, resolve } = await import("node:path");
9
+ const projectRoot = config.root || process.cwd();
10
+ const flatWidgetPattern = resolve(projectRoot, "src/widgets/*.{js,ts,jsx,tsx,html}");
11
+ const dirWidgetPattern = resolve(projectRoot, "src/widgets/*/index.tsx");
12
+ const flatWidgets = globSync(flatWidgetPattern).map((file) => {
13
+ const name = parse(file).name;
14
+ return [name, file];
15
+ });
16
+ const dirWidgets = globSync(dirWidgetPattern).map((file) => {
17
+ const name = basename(dirname(file));
18
+ return [name, file];
19
+ });
20
+ const input = Object.fromEntries([...flatWidgets, ...dirWidgets]);
21
+ return {
22
+ base: "/assets",
23
+ build: {
24
+ manifest: true,
25
+ minify: true,
26
+ cssCodeSplit: false,
27
+ rollupOptions: {
28
+ input,
29
+ },
30
+ },
31
+ experimental: {
32
+ renderBuiltUrl: (filename) => {
33
+ return {
34
+ runtime: `window.skybridge.serverUrl + "/assets/${filename}"`,
35
+ };
36
+ },
37
+ },
38
+ };
39
+ },
40
+ enforce: "pre",
41
+ async transform(code, id) {
42
+ return await dataLlmTransform(code, id);
43
+ },
44
+ };
45
+ }
46
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAExE,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,4EAA4E;YAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAA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,CAAC;oBACJ,CAAC;iBACF;aACF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACtB,OAAO,MAAM,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const transform: (code: string, id: string) => Promise<{
2
+ code: string;
3
+ map: {
4
+ version: number;
5
+ sources: string[];
6
+ names: string[];
7
+ sourceRoot?: string | undefined;
8
+ sourcesContent?: string[] | undefined;
9
+ mappings: string;
10
+ file: string;
11
+ } | null;
12
+ } | null>;
@@ -0,0 +1,96 @@
1
+ const LLM_IMPORT_SOURCE = "skybridge/web";
2
+ function createBabelPlugin(t) {
3
+ return {
4
+ name: "data-llm-babel",
5
+ visitor: {
6
+ Program: {
7
+ enter(path, state) {
8
+ state.hasDataLLMImport = false;
9
+ state.needsDataLLMImport = false;
10
+ for (const node of path.node.body) {
11
+ if (!t.isImportDeclaration(node)) {
12
+ continue;
13
+ }
14
+ if (node.source.value !== LLM_IMPORT_SOURCE) {
15
+ continue;
16
+ }
17
+ const hasSpecifier = node.specifiers.some((s) => t.isImportSpecifier(s) &&
18
+ t.isIdentifier(s.imported, { name: "DataLLM" }));
19
+ if (hasSpecifier) {
20
+ state.hasDataLLMImport = true;
21
+ break;
22
+ }
23
+ }
24
+ },
25
+ exit(path, state) {
26
+ if (state.needsDataLLMImport && !state.hasDataLLMImport) {
27
+ const importDecl = t.importDeclaration([
28
+ t.importSpecifier(t.identifier("DataLLM"), t.identifier("DataLLM")),
29
+ ], t.stringLiteral(LLM_IMPORT_SOURCE));
30
+ path.node.body.unshift(importDecl);
31
+ }
32
+ },
33
+ },
34
+ JSXElement(path, state) {
35
+ const opening = path.node.openingElement;
36
+ const attributes = opening.attributes;
37
+ const llmAttributeIndex = attributes.findIndex((attribute) => t.isJSXAttribute(attribute) &&
38
+ t.isJSXIdentifier(attribute.name, { name: "data-llm" }));
39
+ if (llmAttributeIndex === -1) {
40
+ return;
41
+ }
42
+ const llmAttribute = attributes[llmAttributeIndex];
43
+ let contentExpression;
44
+ if (t.isStringLiteral(llmAttribute.value)) {
45
+ contentExpression = llmAttribute.value;
46
+ }
47
+ else if (t.isJSXExpressionContainer(llmAttribute.value)) {
48
+ contentExpression = llmAttribute.value.expression;
49
+ }
50
+ else {
51
+ return;
52
+ }
53
+ const contentAttr = t.jsxAttribute(t.jsxIdentifier("content"), t.isStringLiteral(contentExpression)
54
+ ? contentExpression
55
+ : t.jsxExpressionContainer(contentExpression));
56
+ const filteredAttributes = attributes.filter((_, index) => index !== llmAttributeIndex);
57
+ const newOpening = t.jsxOpeningElement(opening.name, filteredAttributes, opening.selfClosing);
58
+ const elementWithoutLlm = t.jsxElement(newOpening, path.node.closingElement, path.node.children, path.node.selfClosing);
59
+ const llmOpening = t.jsxOpeningElement(t.jsxIdentifier("DataLLM"), [
60
+ contentAttr,
61
+ ]);
62
+ const llmClosing = t.jsxClosingElement(t.jsxIdentifier("DataLLM"));
63
+ const wrapped = t.jsxElement(llmOpening, llmClosing, [elementWithoutLlm], false);
64
+ state.needsDataLLMImport = true;
65
+ path.replaceWith(wrapped);
66
+ },
67
+ },
68
+ };
69
+ }
70
+ export const transform = async (code, id) => {
71
+ if (!/\.(jsx|tsx)$/.test(id)) {
72
+ return null;
73
+ }
74
+ if (id.includes("node_modules")) {
75
+ return null;
76
+ }
77
+ // Dynamic import to ensure @babel/core is only loaded in Node.js context
78
+ const { types: t, transformSync } = await import("@babel/core");
79
+ const babelOptions = {
80
+ plugins: [createBabelPlugin(t)],
81
+ parserOpts: {
82
+ plugins: ["jsx", "typescript"],
83
+ },
84
+ filename: id,
85
+ sourceFileName: id,
86
+ };
87
+ const result = transformSync(code, babelOptions);
88
+ if (!result || !result.code) {
89
+ return null;
90
+ }
91
+ return {
92
+ code: result.code,
93
+ map: result.map || null,
94
+ };
95
+ };
96
+ //# sourceMappingURL=transform-data-llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data-llm.js","sourceRoot":"","sources":["../../../src/web/plugin/transform-data-llm.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAO1C,SAAS,iBAAiB,CAAC,CAAe;IACxC,OAAO;QACL,IAAI,EAAE,gBAAgB;QAEtB,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,KAAK,CAAC,IAAI,EAAE,KAAK;oBACf,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC;oBAC/B,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;oBAEjC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;wBAClC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;4BACjC,SAAS;wBACX,CAAC;wBACD,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,iBAAiB,EAAE,CAAC;4BAC5C,SAAS;wBACX,CAAC;wBAED,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACvC,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;4BACtB,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAClD,CAAC;wBAEF,IAAI,YAAY,EAAE,CAAC;4BACjB,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;4BAC9B,MAAM;wBACR,CAAC;oBACH,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,IAAI,EAAE,KAAK;oBACd,IAAI,KAAK,CAAC,kBAAkB,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;wBACxD,MAAM,UAAU,GAAG,CAAC,CAAC,iBAAiB,CACpC;4BACE,CAAC,CAAC,eAAe,CACf,CAAC,CAAC,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;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yEAAyE;IACzE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAEhE,MAAM,YAAY,GAAqB;QACrC,OAAO,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAC/B,UAAU,EAAE;YACV,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;SAC/B;QACD,QAAQ,EAAE,EAAE;QACZ,cAAc,EAAE,EAAE;KACnB,CAAC;IAEF,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEjD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;KACxB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { transform } from "./transform-data-llm.js";
3
+ describe("data-llm plugin", () => {
4
+ it("should transform JSX element with data-llm string attribute", async () => {
5
+ const code = `
6
+ function Component() {
7
+ return <div data-llm="Test description">Content</div>;
8
+ }
9
+ `;
10
+ const result = await transform(code, "test.tsx");
11
+ expect(result).not.toBeNull();
12
+ expect(result?.code).toContain("DataLLM");
13
+ expect(result?.code).toContain('content="Test description"');
14
+ expect(result?.code).not.toContain("data-llm");
15
+ });
16
+ it("should transform JSX element with data-llm expression attribute", async () => {
17
+ const code = `
18
+ function Component() {
19
+ const desc = "Dynamic description";
20
+ return <div data-llm={desc}>Content</div>;
21
+ }
22
+ `;
23
+ const result = await transform(code, "test.tsx");
24
+ expect(result).not.toBeNull();
25
+ expect(result?.code).toContain("DataLLM");
26
+ expect(result?.code).toContain("content={desc}");
27
+ expect(result?.code).not.toContain("data-llm");
28
+ });
29
+ it("should add import for DataLLM when not present", async () => {
30
+ const code = `
31
+ function Component() {
32
+ return <div data-llm="Test">Content</div>;
33
+ }
34
+ `;
35
+ const result = await transform(code, "test.tsx");
36
+ expect(result).not.toBeNull();
37
+ expect(result?.code).toContain('import { DataLLM } from "skybridge/web"');
38
+ });
39
+ it("should handle DataLLM imports correctly", async () => {
40
+ // No duplicate import
41
+ const codeWithImport = `
42
+ import { DataLLM } from "skybridge/web";
43
+ function Component() {
44
+ return <div data-llm="Test">Content</div>;
45
+ }
46
+ `;
47
+ const result1 = await transform(codeWithImport, "test.tsx");
48
+ expect(result1?.code.match(/import.*DataLLM.*from.*skybridge\/web/g)).toHaveLength(1);
49
+ // Preserve other imports and add missing DataLLM
50
+ const codeWithOthers = `
51
+ import React from "react";
52
+ import { useState } from "react";
53
+ function Component() {
54
+ return <div data-llm="Test">Content</div>;
55
+ }
56
+ `;
57
+ const result2 = await transform(codeWithOthers, "test.tsx");
58
+ expect(result2?.code).toContain('import React from "react"');
59
+ expect(result2?.code).toContain('import { useState } from "react"');
60
+ expect(result2?.code).toContain('import { DataLLM } from "skybridge/web"');
61
+ });
62
+ it("should handle complex JSX with multiple data-llm attributes", async () => {
63
+ const code = `
64
+ function Component() {
65
+ return (
66
+ <div>
67
+ <section data-llm="Section 1">
68
+ <p>Content 1</p>
69
+ </section>
70
+ <section data-llm="Section 2">
71
+ <p>Content 2</p>
72
+ </section>
73
+ </div>
74
+ );
75
+ }
76
+ `;
77
+ const result = await transform(code, "test.tsx");
78
+ expect(result).toMatchSnapshot();
79
+ });
80
+ });
81
+ //# sourceMappingURL=transform-data-llm.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data-llm.test.js","sourceRoot":"","sources":["../../../src/web/plugin/transform-data-llm.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,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
6
  };
7
7
  export function installOpenAILoggingProxy() {
8
8
  if (typeof window === "undefined" || !window.openai) {
9
- console.warn("[openai-proxy] window.openai not found, skipping proxy installation");
9
+ return;
10
+ }
11
+ const descriptor = Object.getOwnPropertyDescriptor(window, "openai");
12
+ if (descriptor?.configurable === false || descriptor?.writable === false) {
13
+ console.warn("[openai-proxy] window.openai is not configurable or writable, skipping proxy installation");
10
14
  return;
11
15
  }
12
16
  const originalOpenAI = window.openai;
@@ -16,7 +20,7 @@ export function installOpenAILoggingProxy() {
16
20
  if (typeof value !== "function") {
17
21
  return value;
18
22
  }
19
- return function (...args) {
23
+ return (...args) => {
20
24
  const methodName = String(prop);
21
25
  console.group(`%c[openai] %cmethod %c${methodName}`, `color: ${colors.brand}; font-weight: normal`, `color: ${colors.info}; font-weight: normal`, `color: ${colors.success}`);
22
26
  console.log("%c← args:", `color: ${colors.info}`, args);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/web/proxy.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;CACR,CAAC;AAEX,MAAM,UAAU,yBAAyB;IACvC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACpD,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrE,IAAI,UAAU,EAAE,YAAY,KAAK,KAAK,IAAI,UAAU,EAAE,QAAQ,KAAK,KAAK,EAAE,CAAC;QACzE,OAAO,CAAC,IAAI,CACV,2FAA2F,CAC5F,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAErC,MAAM,OAAO,GAAwC;QACnD,GAAG,CAAC,M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EAAE,UAAU,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;gBACjE,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAEnB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC;QAED,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ;YAC/B,OAAO,CAAC,GAAG,CACT,yBAAyB,MAAM,CAAC,IAAI,CAAC,EAAE,EACvC,UAAU,MAAM,CAAC,KAAK,EAAE,EACxB,UAAU,MAAM,CAAC,IAAI,EAAE,EACvB,UAAU,MAAM,CAAC,OAAO,qBAAqB,EAC7C,GAAG,EACH,KAAK,CACN,CAAC;YAEF,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IAEnD,OAAO,CAAC,GAAG,CACT,8DAA8D,EAC9D,UAAU,MAAM,CAAC,KAAK,EAAE,EACxB,UAAU,MAAM,CAAC,IAAI,EAAE,CACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ import "react";
2
+ declare module "react" {
3
+ interface HTMLAttributes<T> {
4
+ "data-llm"?: string;
5
+ }
6
+ }
7
+ export type UnknownObject = Record<string, unknown>;
8
+ export type Prettify<T> = {
9
+ [K in keyof T]: T[K];
10
+ } & {};
11
+ export type Objectify<T> = T & UnknownObject;
12
+ type RequiredKeys<T> = {
13
+ [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
14
+ }[keyof T];
15
+ export type HasRequiredKeys<T> = RequiredKeys<T> extends never ? false : true;
16
+ export {};
@@ -0,0 +1,2 @@
1
+ import "react";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/web/types.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,31 +1,26 @@
1
1
  {
2
2
  "name": "skybridge",
3
- "version": "0.0.0-dev.d0367d9",
4
- "description": "Skybridge is a framework for building ChatGPT apps",
3
+ "version": "0.0.0-dev.d04feba",
4
+ "description": "Skybridge is a framework for building ChatGPT and MCP Apps",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/alpic-ai/skybridge.git"
8
+ },
5
9
  "type": "module",
6
10
  "files": [
7
- "dist"
11
+ "dist",
12
+ "README.md"
8
13
  ],
9
14
  "exports": {
10
15
  "./server": {
11
- "types": "./dist/src/server/index.d.ts",
12
- "default": "./dist/src/server/index.js"
16
+ "types": "./dist/server/index.d.ts",
17
+ "default": "./dist/server/index.js"
13
18
  },
14
19
  "./web": {
15
- "types": "./dist/src/web/index.d.ts",
16
- "default": "./dist/src/web/index.js"
20
+ "types": "./dist/web/index.d.ts",
21
+ "default": "./dist/web/index.js"
17
22
  }
18
23
  },
19
- "scripts": {
20
- "build": "tsc && pnpm run build:templates",
21
- "build:templates": "cp -r src/server/templates dist/src/server/",
22
- "test": "pnpm run test:unit && pnpm run test:type",
23
- "test:unit": "vitest run --silent",
24
- "test:type": "tsc --noEmit",
25
- "docs:dev": "pnpm --filter @skybridge/docs start",
26
- "docs:build": "pnpm --filter @skybridge/docs build",
27
- "docs:serve": "pnpm --filter @skybridge/docs serve"
28
- },
29
24
  "keywords": [
30
25
  "chatgpt",
31
26
  "app",
@@ -35,31 +30,68 @@
35
30
  "author": "Frédéric Barthelet",
36
31
  "license": "ISC",
37
32
  "peerDependencies": {
33
+ "@modelcontextprotocol/sdk": ">=1.0.0",
34
+ "@skybridge/devtools": ">=0.26.1",
35
+ "nodemon": ">=3.0.0",
38
36
  "react": ">=18.0.0",
39
37
  "react-dom": ">=18.0.0"
40
38
  },
41
39
  "dependencies": {
42
- "@modelcontextprotocol/sdk": "^1.20.0",
43
- "cors": "^2.8.5",
44
- "express": "^5.1.0",
40
+ "@babel/core": "^7.29.0",
41
+ "@oclif/core": "^4.8.0",
42
+ "ci-info": "^4.4.0",
43
+ "cors": "^2.8.6",
44
+ "dequal": "^2.0.3",
45
+ "es-toolkit": "^1.44.0",
46
+ "express": "^5.2.1",
45
47
  "handlebars": "^4.7.8",
46
- "vite": "^7.1.11",
47
- "zod": "^3.25.51"
48
+ "ink": "^6.7.0",
49
+ "posthog-node": "^5.24.15",
50
+ "superjson": "^2.2.6",
51
+ "vite": "^7.3.1",
52
+ "zustand": "^5.0.11"
48
53
  },
49
54
  "devDependencies": {
55
+ "@modelcontextprotocol/ext-apps": "^1.0.1",
56
+ "@modelcontextprotocol/sdk": "^1.26.0",
50
57
  "@testing-library/dom": "^10.4.1",
51
- "@testing-library/react": "^16.3.0",
58
+ "@testing-library/react": "^16.3.2",
52
59
  "@total-typescript/tsconfig": "^1.0.4",
60
+ "@types/babel__core": "^7.20.5",
53
61
  "@types/cors": "^2.8.19",
54
- "@types/express": "^5.0.3",
55
- "@types/jsdom": "^21.1.6",
56
- "@types/node": "^22.15.30",
57
- "@types/react": "^19.2.2",
58
- "@types/react-dom": "^19.2.2",
59
- "@vitest/ui": "^2.1.8",
60
- "jsdom": "^25.0.1",
62
+ "@types/express": "^5.0.6",
63
+ "@types/jsdom": "^27.0.0",
64
+ "@types/node": "^24.10.13",
65
+ "@types/react": "^19.2.13",
66
+ "@types/react-dom": "^19.2.3",
67
+ "@vitest/ui": "^4.0.18",
68
+ "jsdom": "^28.0.0",
69
+ "shx": "^0.4.0",
70
+ "ts-node": "^10.9.2",
61
71
  "typescript": "^5.9.3",
62
- "vitest": "^2.1.8"
72
+ "vitest": "^4.0.18",
73
+ "zod": "^4.3.6"
74
+ },
75
+ "bin": {
76
+ "sb": "./bin/run.js",
77
+ "skybridge": "./bin/run.js"
63
78
  },
64
- "packageManager": "pnpm@10.17.1"
65
- }
79
+ "oclif": {
80
+ "bin": "skybridge",
81
+ "commands": "./dist/commands",
82
+ "dirname": "skybridge",
83
+ "topicSeparator": " ",
84
+ "hooks": {
85
+ "finally": "./dist/cli/telemetry"
86
+ }
87
+ },
88
+ "scripts": {
89
+ "build": "shx rm -rf dist && tsc && pnpm run build:templates",
90
+ "build:templates": "cp -r src/server/templates dist/server/",
91
+ "format": "biome check --write --error-on-warnings",
92
+ "test": "pnpm run test:unit && pnpm run test:type && pnpm run test:format",
93
+ "test:unit": "vitest run",
94
+ "test:type": "tsc --noEmit",
95
+ "test:format": "biome ci"
96
+ }
97
+ }
@@ -1,2 +0,0 @@
1
- export { McpServer } from "./server.js";
2
- export { widgetsDevServer } from "./widgetsDevServer.js";
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,13 +0,0 @@
1
- import { McpServer as McpServerBase, type ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { Resource } from "@modelcontextprotocol/sdk/types.js";
3
- import type { ZodRawShape } from "zod";
4
- type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
5
- type McpServerOriginalToolConfig = Omit<Parameters<McpServer["registerTool"]>[1], "inputSchema" | "outputSchema">;
6
- export declare class McpServer extends McpServerBase {
7
- widget<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape>(name: string, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
8
- inputSchema?: InputArgs;
9
- outputSchema?: OutputArgs;
10
- }, toolCallback: ToolCallback<InputArgs>): void;
11
- private lookupDistFile;
12
- }
13
- export {};
@@ -1,57 +0,0 @@
1
- import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import { templateHelper } from "./templateHelper.js";
3
- import { readFileSync } from "node:fs";
4
- import path from "node:path";
5
- export class McpServer extends McpServerBase {
6
- widget(name, resourceConfig, toolConfig, toolCallback) {
7
- const uri = `ui://widgets/${name}.html`;
8
- const resourceMetadata = {
9
- ...(resourceConfig._meta ?? {}),
10
- };
11
- if (toolConfig.description !== undefined) {
12
- resourceMetadata["openai/widgetDescription"] = toolConfig.description;
13
- }
14
- this.resource(name, uri, {
15
- ...resourceConfig,
16
- _meta: resourceMetadata,
17
- }, async (_uri, extra) => {
18
- const serverUrl = process.env.NODE_ENV === "production"
19
- ? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
20
- extra?.requestInfo?.headers?.host}`
21
- : `http://localhost:3000`;
22
- const html = process.env.NODE_ENV === "production"
23
- ? templateHelper.renderProduction({
24
- serverUrl,
25
- widgetFile: this.lookupDistFile(`src/widgets/${name}.tsx`),
26
- styleFile: this.lookupDistFile("style.css"),
27
- })
28
- : templateHelper.renderDevelopment({
29
- serverUrl,
30
- widgetName: name,
31
- });
32
- return {
33
- contents: [
34
- {
35
- uri,
36
- mimeType: "text/html+skybridge",
37
- text: html,
38
- },
39
- ],
40
- };
41
- });
42
- const toolMeta = {
43
- ...toolConfig._meta,
44
- "openai/outputTemplate": uri,
45
- "ui/resourceUri": uri,
46
- };
47
- this.registerTool(name, {
48
- ...toolConfig,
49
- _meta: toolMeta,
50
- }, toolCallback);
51
- }
52
- lookupDistFile(key) {
53
- const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
54
- return manifest[key]?.file;
55
- }
56
- }
57
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,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CAAE,CAAC;QAC/C,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QACzE,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,IAIhB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,iBAAiB,CAAC,IAA+C;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QAClD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
@@ -1,12 +0,0 @@
1
- <base href="{{serverUrl}}" />
2
- <script type="module">
3
- import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
4
- injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
5
- window.$RefreshSig$ = () => (type) => type;
6
- window.__vite_plugin_react_preamble_installed__ = true;
7
- </script>
8
- <script type="module" src="{{serverUrl}}/@vite/client"></script>
9
- <div id="root"></div>
10
- <script type="module">
11
- import('{{serverUrl}}/src/widgets/{{widgetName}}.tsx');
12
- </script>