skybridge 0.0.0-dev.fe84ef2 → 0.0.0-dev.fefabd5
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.
- package/LICENSE +21 -674
- package/README.md +82 -352
- package/bin/run.js +5 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/telemetry.d.ts +7 -0
- package/dist/cli/telemetry.js +123 -0
- package/dist/cli/telemetry.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +11 -0
- package/dist/cli/use-execute-steps.js +36 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +6 -0
- package/dist/cli/use-nodemon.js +69 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +8 -0
- package/dist/cli/use-typescript-check.js +59 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +46 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +9 -0
- package/dist/commands/dev.js +31 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +7 -0
- package/dist/commands/start.js +28 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +34 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +56 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/express.d.ts +9 -0
- package/dist/server/express.js +69 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.js +74 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/{src/server → server}/inferUtilityTypes.d.ts +10 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/server.d.ts +109 -0
- package/dist/server/server.js +194 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +4 -0
- package/dist/{src/server → server}/templateHelper.js +5 -4
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +67 -0
- package/dist/{src/server → server}/templates/production.hbs +1 -1
- package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
- package/dist/server/widgetsDevServer.js +57 -0
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +355 -0
- package/dist/{src/test → test}/utils.js +86 -8
- package/dist/test/utils.js.map +1 -0
- package/dist/test/widget.test.js +261 -0
- package/dist/test/widget.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +22 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +80 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
- package/dist/web/bridges/apps-sdk/bridge.js +46 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
- package/dist/web/bridges/apps-sdk/index.js +5 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/{src/web → web/bridges/apps-sdk}/types.d.ts +32 -47
- package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +2 -0
- package/dist/web/bridges/get-adaptor.js +8 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/index.d.ts +5 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/adaptor.d.ts +36 -0
- package/dist/web/bridges/mcp-app/adaptor.js +190 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +43 -0
- package/dist/web/bridges/mcp-app/bridge.js +255 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +4 -0
- package/dist/web/bridges/mcp-app/index.js +4 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +8 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +66 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +98 -0
- package/dist/web/bridges/types.js +2 -0
- package/dist/web/bridges/types.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +2 -0
- package/dist/web/bridges/use-host-context.js +8 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +4 -0
- package/dist/web/components/modal-provider.js +47 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.js +24 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.js +126 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/{src/web → web}/data-llm.js +11 -7
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +141 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +11 -8
- package/dist/{src/web → web}/generate-helpers.js +5 -3
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +59 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test.js +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.d.ts +3 -1
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.js +53 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/index.d.ts +4 -5
- package/dist/{src/web → web}/hooks/index.js +3 -4
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +16 -0
- package/dist/web/hooks/test/utils.js +60 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +3 -2
- package/dist/{src/web → web}/hooks/use-call-tool.js +12 -4
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +35 -16
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.test.js +3 -2
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +6 -0
- package/dist/web/hooks/use-files.js +9 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-files.test.js +11 -6
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +22 -0
- package/dist/web/hooks/use-layout.js +23 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.js +8 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +50 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +9 -0
- package/dist/web/hooks/use-request-modal.js +16 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.js +57 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.js +8 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +49 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.d.ts +13 -2
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test.js +130 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +18 -0
- package/dist/web/hooks/use-user.js +19 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +94 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.js +11 -11
- package/dist/web/hooks/use-widget-state.js.map +1 -0
- package/dist/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.test.js +10 -8
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +5 -4
- package/dist/{src/web → web}/index.js +5 -4
- package/dist/web/index.js.map +1 -0
- package/dist/{src/web → web}/mount-widget.js +9 -1
- package/dist/web/mount-widget.js.map +1 -0
- package/dist/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.js +46 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/{src/web → web}/plugin/transform-data-llm.js +6 -3
- package/dist/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/proxy.js +6 -2
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +64 -36
- package/dist/src/server/index.d.ts +0 -4
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/inferUtilityTypes.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -48
- package/dist/src/server/server.js +0 -62
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -12
- package/dist/src/server/widgetsDevServer.js +0 -39
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.d.ts +0 -89
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -90
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/create-store.js +0 -41
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/data-llm.js.map +0 -1
- package/dist/src/web/data-llm.test.js +0 -76
- package/dist/src/web/data-llm.test.js.map +0 -1
- package/dist/src/web/generate-helpers.js.map +0 -1
- package/dist/src/web/generate-helpers.test-d.js.map +0 -1
- package/dist/src/web/generate-helpers.test.js.map +0 -1
- package/dist/src/web/helpers/state.js +0 -37
- package/dist/src/web/helpers/state.js.map +0 -1
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.js +0 -7
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-files.d.ts +0 -10
- package/dist/src/web/hooks/use-files.js +0 -7
- package/dist/src/web/hooks/use-files.js.map +0 -1
- package/dist/src/web/hooks/use-files.test.js.map +0 -1
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
- package/dist/src/web/hooks/use-openai-global.js +0 -23
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
- package/dist/src/web/hooks/use-request-modal.js +0 -9
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js +0 -24
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.js +0 -22
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -59
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin/data-llm.test.js.map +0 -1
- package/dist/src/web/plugin/plugin.js +0 -33
- package/dist/src/web/plugin/plugin.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/src/web/proxy.js.map +0 -1
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/widget.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/server → server}/index.js +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → test/widget.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web → web}/create-store.d.ts +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web → web}/data-llm.d.ts +0 -0
- /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → web/helpers/state.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → web/hooks/use-files.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/hooks/use-layout.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-open-external.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/hooks/use-request-modal.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-set-open-in-app-url.test.d.ts} +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-tool-info.test-d.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
- /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
- /package/dist/{src/web → web}/proxy.d.ts +0 -0
|
@@ -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;YAC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express from "express";
|
|
2
|
+
import type { McpServer } from "./server";
|
|
3
|
+
export declare function createServer({ server, customMiddleware, }: {
|
|
4
|
+
server: McpServer;
|
|
5
|
+
customMiddleware?: {
|
|
6
|
+
path?: string;
|
|
7
|
+
handlers: express.RequestHandler[];
|
|
8
|
+
}[];
|
|
9
|
+
}): Promise<express.Express>;
|
|
@@ -0,0 +1,69 @@
|
|
|
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 createServer({ server, customMiddleware = [], }) {
|
|
6
|
+
const app = express();
|
|
7
|
+
app.use(express.json());
|
|
8
|
+
const env = process.env.NODE_ENV || "development";
|
|
9
|
+
if (env !== "production") {
|
|
10
|
+
const { devtoolsStaticServer } = await import("@skybridge/devtools");
|
|
11
|
+
app.use(await devtoolsStaticServer());
|
|
12
|
+
const { widgetsDevServer } = await import("./widgetsDevServer.js");
|
|
13
|
+
app.use(await widgetsDevServer());
|
|
14
|
+
}
|
|
15
|
+
if (env === "production") {
|
|
16
|
+
const assetsPath = path.join(process.cwd(), "dist", "assets");
|
|
17
|
+
app.use("/assets", cors());
|
|
18
|
+
app.use("/assets", express.static(assetsPath));
|
|
19
|
+
}
|
|
20
|
+
for (const middleware of customMiddleware) {
|
|
21
|
+
if (middleware.path) {
|
|
22
|
+
app.use(middleware.path, ...middleware.handlers);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
app.use(...middleware.handlers);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
app.use("/mcp", mcpMiddleware(server));
|
|
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
|
+
await transport.handleRequest(req, res, req.body);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error("Error handling MCP request:", error);
|
|
56
|
+
if (!res.headersSent) {
|
|
57
|
+
res.status(500).json({
|
|
58
|
+
jsonrpc: "2.0",
|
|
59
|
+
error: {
|
|
60
|
+
code: -32603,
|
|
61
|
+
message: "Internal server error",
|
|
62
|
+
},
|
|
63
|
+
id: null,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAAA,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,YAAY,CAAC,EACjC,MAAM,EACN,gBAAgB,GAAG,EAAE,GAItB;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,IAAI,GAA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G,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CACpB,IAAI,CAAC,SAAS,CAAC;gBACb,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,CAAC,KAAK;oBACZ,OAAO,EAAE,qBAAqB;iBAC/B;gBACD,EAAE,EAAE,IAAI;aACT,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC;gBAClD,kBAAkB,EAAE,SAAS;aAC9B,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACnB,SAAS,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC,CAAC,CAAC;YAEH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChC,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,74 @@
|
|
|
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: () => ((_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("createServer", () => {
|
|
26
|
+
it("runs global custom middleware before the /mcp handler", async () => {
|
|
27
|
+
const { createServer } = await import("./express.js");
|
|
28
|
+
const calls = [];
|
|
29
|
+
const mw = (_req, _res, next) => {
|
|
30
|
+
calls.push("custom");
|
|
31
|
+
next();
|
|
32
|
+
};
|
|
33
|
+
const app = await createServer({
|
|
34
|
+
server: fakeServer,
|
|
35
|
+
customMiddleware: [{ handlers: [mw] }],
|
|
36
|
+
});
|
|
37
|
+
const { port, server } = await listen(app);
|
|
38
|
+
openServer = server;
|
|
39
|
+
await postMcp(port);
|
|
40
|
+
expect(calls).toEqual(["custom"]);
|
|
41
|
+
});
|
|
42
|
+
it("runs path-scoped middleware on /mcp", async () => {
|
|
43
|
+
const { createServer } = await import("./express.js");
|
|
44
|
+
const calls = [];
|
|
45
|
+
const mw = (_req, _res, next) => {
|
|
46
|
+
calls.push("auth");
|
|
47
|
+
next();
|
|
48
|
+
};
|
|
49
|
+
const app = await createServer({
|
|
50
|
+
server: fakeServer,
|
|
51
|
+
customMiddleware: [{ path: "/mcp", handlers: [mw] }],
|
|
52
|
+
});
|
|
53
|
+
const { port, server } = await listen(app);
|
|
54
|
+
openServer = server;
|
|
55
|
+
await postMcp(port);
|
|
56
|
+
expect(calls).toEqual(["auth"]);
|
|
57
|
+
});
|
|
58
|
+
it("allows middleware to short-circuit with 401", async () => {
|
|
59
|
+
const { createServer } = await import("./express.js");
|
|
60
|
+
const reject = (_req, res) => {
|
|
61
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
62
|
+
};
|
|
63
|
+
const app = await createServer({
|
|
64
|
+
server: fakeServer,
|
|
65
|
+
customMiddleware: [{ path: "/mcp", handlers: [reject] }],
|
|
66
|
+
});
|
|
67
|
+
const { port, server } = await listen(app);
|
|
68
|
+
openServer = server;
|
|
69
|
+
const res = await postMcp(port);
|
|
70
|
+
expect(res.status).toBe(401);
|
|
71
|
+
expect(await res.json()).toEqual({ error: "Unauthorized" });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
//# 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,EAAE,GAAG,EAAE,CACzB,CAAC,CAAC,IAAa,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE,CAClD,IAAI,EAAE,CAAmB;CAC9B,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACtC,gBAAgB,EAAE,GAAG,EAAE,CACrB,CAAC,CAAC,IAAa,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE,CAClD,IAAI,EAAE,CAAmB;CAC9B,C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,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC3C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QAClD,CAAC,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC;YAC7B,MAAM,EAAE,UAAU;YAClB,gBAAgB,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;SACzD,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3C,UAAU,GAAG,MAAM,CAAC;QAEpB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,CAAC,MAAM,GAAG,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,4 @@
|
|
|
1
|
+
export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
|
|
2
|
+
export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
|
|
3
|
+
export { McpServer } from "./server.js";
|
|
4
|
+
export { widgetsDevServer } from "./widgetsDevServer.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AASA,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,109 @@
|
|
|
1
|
+
import type { McpUiResourceMeta } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
4
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
|
+
import type { CallToolResult, Resource, ServerNotification, ServerRequest, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import type { RequestHandler } from "express";
|
|
7
|
+
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
8
|
+
input: TInput;
|
|
9
|
+
output: TOutput;
|
|
10
|
+
responseMetadata: TResponseMetadata;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Extended MCP Apps CSP with upcoming fields from ext-apps PR #158
|
|
14
|
+
* and Skybridge-specific fields for OpenAI compatibility
|
|
15
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/pull/158
|
|
16
|
+
*/
|
|
17
|
+
type ExtendedMcpUiResourceCsp = McpUiResourceMeta["csp"] & {
|
|
18
|
+
/**
|
|
19
|
+
* Origins that can receive openExternal redirects without safe-link modal (OpenAI-specific)
|
|
20
|
+
* @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields
|
|
21
|
+
*/
|
|
22
|
+
redirectDomains?: string[];
|
|
23
|
+
};
|
|
24
|
+
/** Extended MCP Apps resource metadata with upcoming CSP fields */
|
|
25
|
+
type ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, "csp"> & {
|
|
26
|
+
csp?: ExtendedMcpUiResourceCsp;
|
|
27
|
+
};
|
|
28
|
+
/** User-provided resource configuration with optional CSP override */
|
|
29
|
+
export type WidgetResourceMeta = {
|
|
30
|
+
ui?: ExtendedMcpUiResourceMeta;
|
|
31
|
+
} & Resource["_meta"];
|
|
32
|
+
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
33
|
+
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType" | "_meta"> & {
|
|
34
|
+
_meta?: WidgetResourceMeta;
|
|
35
|
+
/** Restrict host types to a specific subset */
|
|
36
|
+
hosts?: WidgetHostType[];
|
|
37
|
+
};
|
|
38
|
+
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
39
|
+
type Simplify<T> = {
|
|
40
|
+
[K in keyof T]: T[K];
|
|
41
|
+
};
|
|
42
|
+
type ExtractStructuredContent<T> = T extends {
|
|
43
|
+
structuredContent: infer SC;
|
|
44
|
+
} ? Simplify<SC> : never;
|
|
45
|
+
type ExtractMeta<T> = [Extract<T, {
|
|
46
|
+
_meta: unknown;
|
|
47
|
+
}>] extends [never] ? unknown : Extract<T, {
|
|
48
|
+
_meta: unknown;
|
|
49
|
+
}> extends {
|
|
50
|
+
_meta: infer M;
|
|
51
|
+
} ? Simplify<M> : unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Type-level marker interface for cross-package type inference.
|
|
54
|
+
* This enables TypeScript to infer tool types across package boundaries
|
|
55
|
+
* using structural typing on the $types property, rather than relying on
|
|
56
|
+
* class generic inference which fails when McpServer comes from different
|
|
57
|
+
* package installations.
|
|
58
|
+
*
|
|
59
|
+
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
60
|
+
*/
|
|
61
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
62
|
+
readonly tools: TTools;
|
|
63
|
+
}
|
|
64
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
65
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
66
|
+
} & {
|
|
67
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
68
|
+
}>;
|
|
69
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
70
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
71
|
+
}> & {
|
|
72
|
+
use(...handlers: RequestHandler[]): AddTool<TTools, TName, TInput, TOutput, TResponseMetadata>;
|
|
73
|
+
use(path: string, ...handlers: RequestHandler[]): AddTool<TTools, TName, TInput, TOutput, TResponseMetadata>;
|
|
74
|
+
run(): Promise<void>;
|
|
75
|
+
};
|
|
76
|
+
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
77
|
+
title?: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
inputSchema?: TInput;
|
|
80
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
81
|
+
annotations?: ToolAnnotations;
|
|
82
|
+
_meta?: Record<string, unknown>;
|
|
83
|
+
};
|
|
84
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
85
|
+
content: CallToolResult["content"];
|
|
86
|
+
} = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
87
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
|
|
88
|
+
readonly $types: McpServerTypes<TTools>;
|
|
89
|
+
private express?;
|
|
90
|
+
private customMiddleware;
|
|
91
|
+
use(...handlers: RequestHandler[]): this;
|
|
92
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
93
|
+
run(): Promise<void>;
|
|
94
|
+
registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends {
|
|
95
|
+
content: CallToolResult["content"];
|
|
96
|
+
}>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
97
|
+
inputSchema?: TInput;
|
|
98
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
99
|
+
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
100
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
101
|
+
content: CallToolResult["content"];
|
|
102
|
+
}>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
103
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
104
|
+
private registerWidgetResource;
|
|
105
|
+
private lookupDistFile;
|
|
106
|
+
private lookupDistFileWithIndexFallback;
|
|
107
|
+
private readManifest;
|
|
108
|
+
}
|
|
109
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
import { mergeWith, union } from "es-toolkit";
|
|
7
|
+
import { createServer } from "./express.js";
|
|
8
|
+
import { templateHelper } from "./templateHelper.js";
|
|
9
|
+
const mergeWithUnion = (target, source) => {
|
|
10
|
+
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
11
|
+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
|
|
12
|
+
return union(targetVal, sourceVal);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export class McpServer extends McpServerBase {
|
|
17
|
+
express;
|
|
18
|
+
customMiddleware = [];
|
|
19
|
+
use(pathOrHandler, ...handlers) {
|
|
20
|
+
if (typeof pathOrHandler === "string") {
|
|
21
|
+
this.customMiddleware.push({
|
|
22
|
+
path: pathOrHandler,
|
|
23
|
+
handlers,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.customMiddleware.push({
|
|
28
|
+
handlers: [pathOrHandler, ...handlers],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
async run() {
|
|
34
|
+
if (!this.express) {
|
|
35
|
+
this.express = await createServer({
|
|
36
|
+
server: this,
|
|
37
|
+
customMiddleware: this.customMiddleware,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const express = this.express;
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const server = http.createServer(express);
|
|
43
|
+
server.on("error", (error) => {
|
|
44
|
+
console.error("Failed to start server:", error);
|
|
45
|
+
reject(error);
|
|
46
|
+
});
|
|
47
|
+
server.listen(3000, () => {
|
|
48
|
+
resolve();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
53
|
+
const userMeta = resourceConfig._meta;
|
|
54
|
+
const toolMeta = {
|
|
55
|
+
...toolConfig._meta,
|
|
56
|
+
};
|
|
57
|
+
if (!resourceConfig.hosts || resourceConfig.hosts.includes("apps-sdk")) {
|
|
58
|
+
const widgetConfig = {
|
|
59
|
+
hostType: "apps-sdk",
|
|
60
|
+
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
61
|
+
mimeType: "text/html+skybridge",
|
|
62
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }) => {
|
|
63
|
+
const userUi = userMeta?.ui;
|
|
64
|
+
const userCsp = userUi?.csp;
|
|
65
|
+
const defaults = {
|
|
66
|
+
"openai/widgetCSP": {
|
|
67
|
+
resource_domains: resourceDomains,
|
|
68
|
+
connect_domains: connectDomains,
|
|
69
|
+
},
|
|
70
|
+
"openai/widgetDomain": domain,
|
|
71
|
+
"openai/widgetDescription": resourceConfig.description,
|
|
72
|
+
};
|
|
73
|
+
const fromUi = {
|
|
74
|
+
"openai/widgetCSP": {
|
|
75
|
+
resource_domains: userCsp?.resourceDomains,
|
|
76
|
+
connect_domains: userCsp?.connectDomains,
|
|
77
|
+
frame_domains: userCsp?.frameDomains,
|
|
78
|
+
redirect_domains: userCsp?.redirectDomains,
|
|
79
|
+
},
|
|
80
|
+
"openai/widgetDomain": userUi?.domain,
|
|
81
|
+
"openai/widgetPrefersBorder": userUi?.prefersBorder,
|
|
82
|
+
};
|
|
83
|
+
const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
|
|
84
|
+
return mergeWithUnion(mergeWithUnion(defaults, fromUi), directOpenaiKeys);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
this.registerWidgetResource({
|
|
88
|
+
name,
|
|
89
|
+
widgetConfig,
|
|
90
|
+
resourceConfig,
|
|
91
|
+
});
|
|
92
|
+
toolMeta["openai/outputTemplate"] = widgetConfig.uri;
|
|
93
|
+
}
|
|
94
|
+
if (!resourceConfig.hosts || resourceConfig.hosts.includes("mcp-app")) {
|
|
95
|
+
const widgetConfig = {
|
|
96
|
+
hostType: "mcp-app",
|
|
97
|
+
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
98
|
+
mimeType: "text/html;profile=mcp-app",
|
|
99
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }) => {
|
|
100
|
+
const defaults = {
|
|
101
|
+
ui: {
|
|
102
|
+
csp: {
|
|
103
|
+
resourceDomains,
|
|
104
|
+
connectDomains,
|
|
105
|
+
},
|
|
106
|
+
domain,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
return mergeWithUnion(defaults, { ui: userMeta?.ui });
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
this.registerWidgetResource({
|
|
113
|
+
name,
|
|
114
|
+
widgetConfig,
|
|
115
|
+
resourceConfig,
|
|
116
|
+
});
|
|
117
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
118
|
+
toolMeta["ui/resourceUri"] = widgetConfig.uri;
|
|
119
|
+
toolMeta.ui = { resourceUri: widgetConfig.uri };
|
|
120
|
+
}
|
|
121
|
+
this.registerTool(name, {
|
|
122
|
+
...toolConfig,
|
|
123
|
+
_meta: toolMeta,
|
|
124
|
+
}, toolCallback);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
registerTool(name, config, cb) {
|
|
128
|
+
super.registerTool(name, config, cb);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
registerWidgetResource({ name, widgetConfig, resourceConfig, }) {
|
|
132
|
+
const { hostType, uri: widgetUri, mimeType, buildContentMeta, } = widgetConfig;
|
|
133
|
+
this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceConfig._meta }, async (uri, extra) => {
|
|
134
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
135
|
+
const useForwardedHost = process.env.SKYBRIDGE_USE_FORWARDED_HOST === "true";
|
|
136
|
+
const isClaude = extra?.requestInfo?.headers?.["user-agent"] === "Claude-User";
|
|
137
|
+
const hostFromHeaders = extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
138
|
+
extra?.requestInfo?.headers?.host;
|
|
139
|
+
const useExternalHost = isProduction || useForwardedHost || isClaude;
|
|
140
|
+
const serverUrl = useExternalHost
|
|
141
|
+
? `https://${hostFromHeaders}`
|
|
142
|
+
: "http://localhost:3000";
|
|
143
|
+
const html = isProduction
|
|
144
|
+
? templateHelper.renderProduction({
|
|
145
|
+
hostType,
|
|
146
|
+
serverUrl,
|
|
147
|
+
widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
|
|
148
|
+
styleFile: this.lookupDistFile("style.css"),
|
|
149
|
+
})
|
|
150
|
+
: templateHelper.renderDevelopment({
|
|
151
|
+
hostType,
|
|
152
|
+
serverUrl,
|
|
153
|
+
useLocalNetworkAccess: !useExternalHost,
|
|
154
|
+
widgetName: name,
|
|
155
|
+
});
|
|
156
|
+
const connectDomains = [serverUrl];
|
|
157
|
+
if (!isProduction) {
|
|
158
|
+
const VITE_HMR_WEBSOCKET_DEFAULT_URL = "ws://localhost:24678";
|
|
159
|
+
connectDomains.push(VITE_HMR_WEBSOCKET_DEFAULT_URL);
|
|
160
|
+
}
|
|
161
|
+
const contentMeta = buildContentMeta({
|
|
162
|
+
resourceDomains: [serverUrl],
|
|
163
|
+
connectDomains,
|
|
164
|
+
domain: isClaude
|
|
165
|
+
? `${crypto
|
|
166
|
+
.createHash("sha256")
|
|
167
|
+
.update(`https://${hostFromHeaders}/mcp`)
|
|
168
|
+
.digest("hex")
|
|
169
|
+
.slice(0, 32)}.claudemcpcontent.com`
|
|
170
|
+
: serverUrl,
|
|
171
|
+
baseUriDomains: [serverUrl],
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
contents: [
|
|
175
|
+
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
lookupDistFile(key) {
|
|
181
|
+
const manifest = this.readManifest();
|
|
182
|
+
return manifest[key]?.file;
|
|
183
|
+
}
|
|
184
|
+
lookupDistFileWithIndexFallback(basePath) {
|
|
185
|
+
const manifest = this.readManifest();
|
|
186
|
+
const flatFileKey = `${basePath}.tsx`;
|
|
187
|
+
const indexFileKey = `${basePath}/index.tsx`;
|
|
188
|
+
return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
|
|
189
|
+
}
|
|
190
|
+
readManifest() {
|
|
191
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EACL,SAAS,IAAI,aAAa,GAG3B,MAAM,yCAAyC,CAAC;AAcjD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,cAAc,GAAG,CACrB,MAAS,EACT,MAAS,EACF,EAAE;IACT,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SA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c,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;IAEO,+BAA+B,CAAC,QAAgB;QACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAErC,MAAM,WAAW,GAAG,GAAG,QAAQ,MAAM,CAAC;QACtC,MAAM,YAAY,GAAG,GAAG,QAAQ,YAAY,CAAC;QAC7C,OAAO,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,IAAI,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;IACrE,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,CAAC,KAAK,CACf,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import type { WidgetHostType } from "./server.js";
|
|
1
2
|
declare class TemplateHelper {
|
|
2
3
|
private templateCache;
|
|
3
4
|
private loadTemplate;
|
|
4
5
|
renderProduction(data: {
|
|
6
|
+
hostType: WidgetHostType;
|
|
5
7
|
serverUrl: string;
|
|
6
8
|
widgetFile: string;
|
|
7
9
|
styleFile: string;
|
|
8
10
|
}): string;
|
|
9
11
|
renderDevelopment(data: {
|
|
12
|
+
hostType: WidgetHostType;
|
|
10
13
|
serverUrl: string;
|
|
14
|
+
useLocalNetworkAccess: boolean;
|
|
11
15
|
widgetName: string;
|
|
12
16
|
}): string;
|
|
13
17
|
}
|