skybridge 0.0.0-dev.fd77b0f → 0.0.0-dev.fda2b44
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 -0
- package/README.md +153 -0
- package/bin/run.js +5 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -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/tunnel-control-server.d.ts +9 -0
- package/dist/cli/tunnel-control-server.js +31 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.js +105 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel.d.ts +57 -0
- package/dist/cli/tunnel.js +154 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/{src/web/bridges → cli}/types.js.map +1 -1
- 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-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +2 -0
- package/dist/cli/use-nodemon.js +64 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +9 -0
- package/dist/cli/use-typescript-check.js +94 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +102 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +12 -0
- package/dist/commands/dev.js +80 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.js +49 -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 +10 -0
- package/dist/server/asset-base-url-transform-plugin.js +33 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +84 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +27 -0
- package/dist/server/content-helpers.js +46 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +11 -0
- package/dist/server/express.js +101 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.js +430 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/{src/server → server}/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +124 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +196 -0
- package/dist/server/server.js +468 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +5 -7
- package/dist/server/templateHelper.js +11 -0
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates.generated.d.ts +4 -0
- package/dist/server/templates.generated.js +47 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tunnel-proxy-router.d.ts +7 -0
- package/dist/server/tunnel-proxy-router.js +110 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/{src/test → test}/utils.d.ts +13 -21
- package/dist/{src/test → test}/utils.js +42 -37
- package/dist/test/utils.js.map +1 -0
- package/dist/test/view.test.js +523 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +24 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +93 -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/{src/web/bridges/apps-sdk-bridge.js → web/bridges/apps-sdk/bridge.js} +2 -2
- 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/web/bridges/apps-sdk/types.d.ts +126 -0
- 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/{src/web/bridges/hooks/use-apps-sdk-bridge.js → web/bridges/apps-sdk/use-apps-sdk-context.js} +3 -3
- 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 +48 -0
- package/dist/web/bridges/mcp-app/adaptor.js +268 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
- package/dist/web/bridges/mcp-app/bridge.js +102 -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 +7 -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 +26 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +109 -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 +45 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.js +38 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.js +129 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/{src/web → web}/data-llm.d.ts +1 -1
- package/dist/{src/web → web}/data-llm.js +7 -5
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +142 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +22 -19
- package/dist/{src/web → web}/generate-helpers.js +20 -18
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +26 -26
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/index.d.ts +3 -3
- package/dist/{src/web → web}/hooks/index.js +2 -2
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/{src/web → web}/hooks/test/utils.d.ts +8 -2
- package/dist/web/hooks/test/utils.js +64 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +2 -1
- package/dist/{src/web → web}/hooks/use-call-tool.js +2 -2
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +0 -1
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +7 -0
- package/dist/web/hooks/use-files.js +10 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/web/hooks/use-files.test.d.ts +1 -0
- package/dist/web/hooks/use-files.test.js +54 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-layout.d.ts +2 -2
- package/dist/{src/web → web}/hooks/use-layout.js +4 -4
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-layout.test.js +7 -6
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +3 -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.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-open-external.test.js +27 -12
- 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.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-request-modal.test.js +5 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-send-follow-up-message.js +2 -2
- 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.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -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.js +4 -4
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
- 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/{src/web → web}/hooks/use-tool-info.test.js +5 -5
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-user.d.ts +1 -1
- package/dist/web/hooks/use-user.js +35 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-user.test.js +33 -4
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-view-state.d.ts +4 -0
- package/dist/web/hooks/use-view-state.js +32 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +177 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +1 -2
- package/dist/{src/web → web}/index.js +1 -2
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-view.d.ts +1 -0
- package/dist/{src/web/mount-widget.js → web/mount-view.js} +11 -3
- package/dist/web/mount-view.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.d.ts +5 -0
- package/dist/web/plugin/plugin.js +156 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/web/plugin/scan-views.d.ts +16 -0
- package/dist/web/plugin/scan-views.js +88 -0
- package/dist/web/plugin/scan-views.js.map +1 -0
- package/dist/web/plugin/scan-views.test.d.ts +1 -0
- package/dist/web/plugin/scan-views.test.js +99 -0
- package/dist/web/plugin/scan-views.test.js.map +1 -0
- package/dist/{src/web → web}/plugin/transform-data-llm.js +1 -1
- 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/web/plugin/validate-view.d.ts +1 -0
- package/dist/web/plugin/validate-view.js +9 -0
- package/dist/web/plugin/validate-view.js.map +1 -0
- package/dist/web/plugin/validate-view.test.d.ts +1 -0
- package/dist/web/plugin/validate-view.test.js +24 -0
- package/dist/web/plugin/validate-view.test.js.map +1 -0
- package/dist/{src/web → web}/proxy.js +0 -1
- 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 +74 -39
- package/tsconfig.base.json +33 -0
- package/dist/src/server/devtoolsStaticServer.d.ts +0 -15
- package/dist/src/server/devtoolsStaticServer.js +0 -38
- package/dist/src/server/devtoolsStaticServer.js.map +0 -1
- package/dist/src/server/index.d.ts +0 -5
- package/dist/src/server/index.js +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 -74
- package/dist/src/server/server.js +0 -82
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js +0 -30
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -13
- package/dist/src/server/templates/production.hbs +0 -7
- package/dist/src/server/widgetsDevServer.d.ts +0 -12
- package/dist/src/server/widgetsDevServer.js +0 -38
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -146
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +0 -13
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +0 -33
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +0 -16
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +0 -115
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -10
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-adaptor.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-adaptor.js +0 -8
- package/dist/src/web/bridges/hooks/use-adaptor.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-bridge.js +0 -8
- package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -5
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -41
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
- package/dist/src/web/bridges/index.d.ts +0 -4
- package/dist/src/web/bridges/index.js +0 -5
- package/dist/src/web/bridges/index.js.map +0 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -38
- package/dist/src/web/bridges/mcp-app-bridge.js +0 -162
- package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/types.d.ts +0 -57
- package/dist/src/web/create-store.js +0 -25
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/create-store.test.js +0 -70
- package/dist/src/web/create-store.test.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 -40
- package/dist/src/web/helpers/state.js.map +0 -1
- package/dist/src/web/helpers/state.test.js.map +0 -1
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/test/utils.js +0 -40
- package/dist/src/web/hooks/test/utils.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.d.ts +0 -4
- package/dist/src/web/hooks/use-display-mode.js +0 -10
- 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 +0 -29
- package/dist/src/web/hooks/use-files.test.js.map +0 -1
- package/dist/src/web/hooks/use-layout.js.map +0 -1
- package/dist/src/web/hooks/use-layout.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.d.ts +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -8
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
- package/dist/src/web/hooks/use-openai-global.js +0 -6
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -9
- package/dist/src/web/hooks/use-request-modal.js +0 -14
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- 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.map +0 -1
- package/dist/src/web/hooks/use-user.js +0 -19
- package/dist/src/web/hooks/use-user.js.map +0 -1
- package/dist/src/web/hooks/use-user.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/src/web/hooks/use-widget-state.js +0 -32
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js +0 -61
- 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.d.ts +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.d.ts +0 -2
- package/dist/src/web/plugin/plugin.js +0 -39
- 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.d.ts +0 -149
- 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 → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{src/web/create-store.test.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{src/web/bridges → cli}/types.js +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → server/content-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web/helpers/state.test.d.ts → server/middleware.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/middleware.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/tunnel-proxy-router.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → test/view.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.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-layout.test.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/helpers/state.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +0 -0
- /package/dist/{src/web/hooks/use-user.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-display-mode.test-d.d.ts} +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-display-mode.test.js +0 -0
- /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-tool-info.d.ts +0 -0
- /package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +0 -0
- /package/dist/{src/web → web}/plugin/data-llm.test.js +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,196 @@
|
|
|
1
|
+
import { type ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { McpServer as McpServerBase } 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 { ContentBlock, Implementation, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
|
|
7
|
+
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
8
|
+
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
9
|
+
input: TInput;
|
|
10
|
+
output: TOutput;
|
|
11
|
+
responseMetadata: TResponseMetadata;
|
|
12
|
+
};
|
|
13
|
+
export type ViewHostType = "apps-sdk" | "mcp-app";
|
|
14
|
+
export interface ViewCsp {
|
|
15
|
+
/** Origins for static assets (images, fonts, scripts, styles). */
|
|
16
|
+
resourceDomains?: string[];
|
|
17
|
+
/** Origins the view may contact via fetch/XHR. */
|
|
18
|
+
connectDomains?: string[];
|
|
19
|
+
/** Origins allowed for iframe embeds (opts into stricter app review). */
|
|
20
|
+
frameDomains?: string[];
|
|
21
|
+
/** Origins that can receive openExternal redirects without the safe-link modal. */
|
|
22
|
+
redirectDomains?: string[];
|
|
23
|
+
/** Origins allowed in `<base href>` tags (mcp-apps only). */
|
|
24
|
+
baseUriDomains?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface ViewNameRegistry {
|
|
27
|
+
}
|
|
28
|
+
export type ViewName = keyof ViewNameRegistry & string;
|
|
29
|
+
export interface ViewConfig {
|
|
30
|
+
component: ViewName;
|
|
31
|
+
description?: string;
|
|
32
|
+
hosts?: ViewHostType[];
|
|
33
|
+
prefersBorder?: boolean;
|
|
34
|
+
domain?: string;
|
|
35
|
+
csp?: ViewCsp;
|
|
36
|
+
_meta?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface KnownToolMeta {
|
|
39
|
+
"openai/widgetAccessible"?: boolean;
|
|
40
|
+
"openai/toolInvocation/invoking"?: string;
|
|
41
|
+
"openai/toolInvocation/invoked"?: string;
|
|
42
|
+
}
|
|
43
|
+
export type ToolMeta = KnownToolMeta & Record<string, unknown>;
|
|
44
|
+
export type HandlerContent = string | ContentBlock | ContentBlock[];
|
|
45
|
+
/**
|
|
46
|
+
* Type-level marker interface for cross-package type inference.
|
|
47
|
+
*
|
|
48
|
+
* Consumers infer tool types via the structural `$types` property rather than
|
|
49
|
+
* the `McpServer` class generic, because class-generic inference breaks when
|
|
50
|
+
* `McpServer` comes from different package installations (e.g. a consumer
|
|
51
|
+
* with its own `skybridge` dep vs. the in-tree workspace version).
|
|
52
|
+
*
|
|
53
|
+
* Inspired by tRPC's `_def` pattern and Hono's type markers.
|
|
54
|
+
*/
|
|
55
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
56
|
+
readonly tools: TTools;
|
|
57
|
+
}
|
|
58
|
+
type Simplify<T> = {
|
|
59
|
+
[K in keyof T]: T[K];
|
|
60
|
+
};
|
|
61
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
62
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
63
|
+
} & {
|
|
64
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
65
|
+
}>;
|
|
66
|
+
type ExtractStructuredContent<T> = T extends {
|
|
67
|
+
structuredContent: infer SC;
|
|
68
|
+
} ? Simplify<SC> : never;
|
|
69
|
+
type ExtractMeta<T> = [Extract<T, {
|
|
70
|
+
_meta: unknown;
|
|
71
|
+
}>] extends [never] ? unknown : Extract<T, {
|
|
72
|
+
_meta: unknown;
|
|
73
|
+
}> extends {
|
|
74
|
+
_meta: infer M;
|
|
75
|
+
} ? Simplify<M> : unknown;
|
|
76
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
77
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
78
|
+
}>;
|
|
79
|
+
interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
|
|
80
|
+
name: string;
|
|
81
|
+
title?: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
inputSchema?: TInput;
|
|
84
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
85
|
+
annotations?: ToolAnnotations;
|
|
86
|
+
view?: ViewConfig;
|
|
87
|
+
_meta?: ToolMeta;
|
|
88
|
+
}
|
|
89
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
90
|
+
content?: HandlerContent;
|
|
91
|
+
} = {
|
|
92
|
+
content?: HandlerContent;
|
|
93
|
+
}> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
94
|
+
export declare function normalizeContent(content: HandlerContent | undefined): ContentBlock[];
|
|
95
|
+
interface McpServerBaseOmitted extends Omit<McpServerBase, "registerTool" | "connect"> {
|
|
96
|
+
}
|
|
97
|
+
declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof McpServerBase>) => McpServerBaseOmitted;
|
|
98
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
|
|
99
|
+
readonly $types: McpServerTypes<TTools>;
|
|
100
|
+
/**
|
|
101
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
102
|
+
* custom routes, middleware, or settings — e.g.
|
|
103
|
+
* `server.express.get("/health", ...)`.
|
|
104
|
+
*
|
|
105
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
106
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
107
|
+
* error handler are appended in that order.
|
|
108
|
+
*
|
|
109
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
110
|
+
* locally and on self-hosted deployments.
|
|
111
|
+
*/
|
|
112
|
+
readonly express: Express;
|
|
113
|
+
private customErrorMiddleware;
|
|
114
|
+
private mcpMiddlewareEntries;
|
|
115
|
+
private mcpMiddlewareApplied;
|
|
116
|
+
private claimedViews;
|
|
117
|
+
private viteManifest;
|
|
118
|
+
private readonly serverInfo;
|
|
119
|
+
private readonly serverOptions?;
|
|
120
|
+
constructor(serverInfo: Implementation, options?: ServerOptions);
|
|
121
|
+
use(...handlers: RequestHandler[]): this;
|
|
122
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
123
|
+
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
124
|
+
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
125
|
+
/** Register MCP protocol-level middleware (catch-all). */
|
|
126
|
+
mcpMiddleware(handler: McpMiddlewareFn): this;
|
|
127
|
+
/** Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`). */
|
|
128
|
+
mcpMiddleware(filter: "request", handler: (request: {
|
|
129
|
+
method: string;
|
|
130
|
+
params: Record<string, unknown>;
|
|
131
|
+
}, extra: McpExtra, next: () => Promise<ServerResult>) => Promise<unknown> | unknown): this;
|
|
132
|
+
/** Register MCP protocol-level middleware for all notifications (`extra` is `undefined`). */
|
|
133
|
+
mcpMiddleware(filter: "notification", handler: (request: {
|
|
134
|
+
method: string;
|
|
135
|
+
params: Record<string, unknown>;
|
|
136
|
+
}, extra: undefined, next: () => Promise<undefined>) => Promise<unknown> | unknown): this;
|
|
137
|
+
/**
|
|
138
|
+
* Register MCP protocol-level middleware for an exact method.
|
|
139
|
+
* Narrows `params`, `extra`, and `next()` result based on the method string.
|
|
140
|
+
*/
|
|
141
|
+
mcpMiddleware<M extends McpMethodString>(filter: M, handler: McpTypedMiddlewareFn<M>): this;
|
|
142
|
+
/**
|
|
143
|
+
* Register MCP protocol-level middleware for a wildcard pattern (e.g. `"tools/*"`).
|
|
144
|
+
* `next()` returns the union of result types for matching methods.
|
|
145
|
+
*/
|
|
146
|
+
mcpMiddleware<W extends McpWildcard>(filter: W, handler: (request: {
|
|
147
|
+
method: string;
|
|
148
|
+
params: Record<string, unknown>;
|
|
149
|
+
}, extra: McpExtraFor<W>, next: () => Promise<McpResultFor<W>>) => Promise<unknown> | unknown): this;
|
|
150
|
+
/**
|
|
151
|
+
* Register MCP protocol-level middleware with a method filter.
|
|
152
|
+
* Filter can be an exact method (`"tools/call"`), wildcard (`"tools/*"`),
|
|
153
|
+
* category (`"request"` | `"notification"`), or an array of those.
|
|
154
|
+
*/
|
|
155
|
+
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
156
|
+
private applyMcpMiddleware;
|
|
157
|
+
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
160
|
+
* transport per instance, so we can't reuse this `McpServer` across
|
|
161
|
+
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
162
|
+
* factory, but that would break Skybridge's singleton API — so instead
|
|
163
|
+
* we build a fresh underlying `Server` per request and share the main
|
|
164
|
+
* server's handler maps by reference. The cast is unavoidable: there's
|
|
165
|
+
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
166
|
+
* read side and fails fast on SDK field renames.
|
|
167
|
+
*/
|
|
168
|
+
connectStatelessTransport(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
169
|
+
run(): Promise<{
|
|
170
|
+
fetch: (...args: unknown[]) => unknown;
|
|
171
|
+
} | undefined>;
|
|
172
|
+
private enforceOneToolPerView;
|
|
173
|
+
private registerViewResources;
|
|
174
|
+
private registerViewResource;
|
|
175
|
+
private wrapHandler;
|
|
176
|
+
private computeViewVersionParam;
|
|
177
|
+
private lookupViewFile;
|
|
178
|
+
private lookupDistFile;
|
|
179
|
+
/**
|
|
180
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
181
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
182
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
183
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
184
|
+
*/
|
|
185
|
+
setViteManifest(manifest: Record<string, {
|
|
186
|
+
file: string;
|
|
187
|
+
}>): this;
|
|
188
|
+
private readManifest;
|
|
189
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
190
|
+
content?: HandlerContent;
|
|
191
|
+
}>(config: ToolConfig<InputArgs> & {
|
|
192
|
+
name: TName;
|
|
193
|
+
}, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
194
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): this;
|
|
195
|
+
}
|
|
196
|
+
export {};
|
|
@@ -0,0 +1,468 @@
|
|
|
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 { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
|
+
import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
import { mergeWith, union } from "es-toolkit";
|
|
8
|
+
import express, {} from "express";
|
|
9
|
+
import { createApp } from "./express.js";
|
|
10
|
+
import { createMiddlewareEntry } from "./metric.js";
|
|
11
|
+
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
12
|
+
import { templateHelper } from "./templateHelper.js";
|
|
13
|
+
const mergeWithUnion = (target, source) => {
|
|
14
|
+
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
15
|
+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
|
|
16
|
+
return union(targetVal, sourceVal);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export function normalizeContent(content) {
|
|
21
|
+
if (content === undefined) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
if (typeof content === "string") {
|
|
25
|
+
return [{ type: "text", text: content }];
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(content)) {
|
|
28
|
+
return content;
|
|
29
|
+
}
|
|
30
|
+
return [content];
|
|
31
|
+
}
|
|
32
|
+
const McpServerBaseOmitted = McpServerBase;
|
|
33
|
+
export class McpServer extends McpServerBaseOmitted {
|
|
34
|
+
/**
|
|
35
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
36
|
+
* custom routes, middleware, or settings — e.g.
|
|
37
|
+
* `server.express.get("/health", ...)`.
|
|
38
|
+
*
|
|
39
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
40
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
41
|
+
* error handler are appended in that order.
|
|
42
|
+
*
|
|
43
|
+
* Note: Alpic Cloud only routes traffic to `/mcp` — custom routes work
|
|
44
|
+
* locally and on self-hosted deployments.
|
|
45
|
+
*/
|
|
46
|
+
express;
|
|
47
|
+
customErrorMiddleware = [];
|
|
48
|
+
mcpMiddlewareEntries = [];
|
|
49
|
+
mcpMiddlewareApplied = false;
|
|
50
|
+
claimedViews = new Map();
|
|
51
|
+
viteManifest = null;
|
|
52
|
+
serverInfo;
|
|
53
|
+
serverOptions;
|
|
54
|
+
constructor(serverInfo, options) {
|
|
55
|
+
super(serverInfo, options);
|
|
56
|
+
this.serverInfo = serverInfo;
|
|
57
|
+
this.serverOptions = options;
|
|
58
|
+
this.express = express();
|
|
59
|
+
this.express.use(express.json());
|
|
60
|
+
}
|
|
61
|
+
use(pathOrHandler, ...handlers) {
|
|
62
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
63
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
64
|
+
if (typeof pathOrHandler === "string") {
|
|
65
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
useOnError(pathOrHandler, ...handlers) {
|
|
73
|
+
if (typeof pathOrHandler === "string") {
|
|
74
|
+
this.customErrorMiddleware.push({ path: pathOrHandler, handlers });
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.customErrorMiddleware.push({
|
|
78
|
+
handlers: [pathOrHandler, ...handlers],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
mcpMiddleware(filterOrHandler,
|
|
84
|
+
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
85
|
+
maybeHandler) {
|
|
86
|
+
if (this.mcpMiddlewareApplied) {
|
|
87
|
+
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
88
|
+
}
|
|
89
|
+
const handler = maybeHandler;
|
|
90
|
+
if (typeof filterOrHandler === "function") {
|
|
91
|
+
this.mcpMiddlewareEntries.push({
|
|
92
|
+
filter: null,
|
|
93
|
+
handler: filterOrHandler,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else if (handler) {
|
|
97
|
+
this.mcpMiddlewareEntries.push({
|
|
98
|
+
filter: filterOrHandler,
|
|
99
|
+
handler,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new Error("mcpMiddleware requires a handler function when a filter is provided");
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
applyMcpMiddleware() {
|
|
108
|
+
if (this.mcpMiddlewareApplied) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.mcpMiddlewareApplied = true;
|
|
112
|
+
const monitoringEntry = createMiddlewareEntry();
|
|
113
|
+
const entries = monitoringEntry
|
|
114
|
+
? [monitoringEntry, ...this.mcpMiddlewareEntries]
|
|
115
|
+
: this.mcpMiddlewareEntries;
|
|
116
|
+
if (entries.length === 0) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
120
|
+
const instrumentMap = (map, isNotification) => {
|
|
121
|
+
for (const [method, handler] of map) {
|
|
122
|
+
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
123
|
+
}
|
|
124
|
+
const originalSet = map.set.bind(map);
|
|
125
|
+
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
126
|
+
};
|
|
127
|
+
instrumentMap(requestHandlers, false);
|
|
128
|
+
instrumentMap(notificationHandlers, true);
|
|
129
|
+
}
|
|
130
|
+
async connect(transport) {
|
|
131
|
+
this.applyMcpMiddleware();
|
|
132
|
+
return McpServerBase.prototype.connect.call(this, transport);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
136
|
+
* transport per instance, so we can't reuse this `McpServer` across
|
|
137
|
+
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
138
|
+
* factory, but that would break Skybridge's singleton API — so instead
|
|
139
|
+
* we build a fresh underlying `Server` per request and share the main
|
|
140
|
+
* server's handler maps by reference. The cast is unavoidable: there's
|
|
141
|
+
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
142
|
+
* read side and fails fast on SDK field renames.
|
|
143
|
+
*/
|
|
144
|
+
async connectStatelessTransport(transport) {
|
|
145
|
+
this.applyMcpMiddleware();
|
|
146
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
147
|
+
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
148
|
+
const target = fresh;
|
|
149
|
+
target._requestHandlers = requestHandlers;
|
|
150
|
+
target._notificationHandlers = notificationHandlers;
|
|
151
|
+
await fresh.connect(transport);
|
|
152
|
+
}
|
|
153
|
+
async run() {
|
|
154
|
+
this.applyMcpMiddleware();
|
|
155
|
+
const httpServer = http.createServer();
|
|
156
|
+
await createApp({
|
|
157
|
+
mcpServer: this,
|
|
158
|
+
httpServer,
|
|
159
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
160
|
+
});
|
|
161
|
+
httpServer.on("request", this.express);
|
|
162
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
163
|
+
await new Promise((resolve, reject) => {
|
|
164
|
+
httpServer.on("error", (error) => {
|
|
165
|
+
console.error("Failed to start server:", error);
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
httpServer.listen(port, () => {
|
|
169
|
+
resolve();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
173
|
+
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
174
|
+
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
175
|
+
if (typeof navigator !== "undefined" &&
|
|
176
|
+
navigator.userAgent === "Cloudflare-Workers") {
|
|
177
|
+
const cloudflareNode = "cloudflare:node";
|
|
178
|
+
const { httpServerHandler } = await import(cloudflareNode);
|
|
179
|
+
return httpServerHandler({ port });
|
|
180
|
+
}
|
|
181
|
+
const shutdown = () => {
|
|
182
|
+
// Drop both handlers so a second signal falls through to Node's default
|
|
183
|
+
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
184
|
+
process.off("SIGTERM", shutdown);
|
|
185
|
+
process.off("SIGINT", shutdown);
|
|
186
|
+
httpServer.close(() => process.exit(0));
|
|
187
|
+
// Force exit if connections don't drain in time so the port is still
|
|
188
|
+
// released promptly (e.g. for nodemon restarts).
|
|
189
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
190
|
+
};
|
|
191
|
+
process.on("SIGTERM", shutdown);
|
|
192
|
+
process.on("SIGINT", shutdown);
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
enforceOneToolPerView(component, toolName) {
|
|
196
|
+
const existingTool = this.claimedViews.get(component);
|
|
197
|
+
if (existingTool) {
|
|
198
|
+
throw new Error(`skybridge: view "${component}" is already used by tool "${existingTool}". Tool "${toolName}" cannot also reference it — each view backs exactly one tool.`);
|
|
199
|
+
}
|
|
200
|
+
this.claimedViews.set(component, toolName);
|
|
201
|
+
}
|
|
202
|
+
registerViewResources(toolName, view, toolMeta) {
|
|
203
|
+
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
204
|
+
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
205
|
+
// their cache when the bundle changes, but keep the URI stable across
|
|
206
|
+
// `tools/list` calls when the bundle hasn't changed.
|
|
207
|
+
const versionParam = this.computeViewVersionParam(view.component);
|
|
208
|
+
if (hosts.includes("apps-sdk")) {
|
|
209
|
+
const viewResource = {
|
|
210
|
+
hostType: "apps-sdk",
|
|
211
|
+
uri: `ui://views/apps-sdk/${view.component}.html${versionParam}`,
|
|
212
|
+
mimeType: "text/html+skybridge",
|
|
213
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
214
|
+
const defaults = {
|
|
215
|
+
"openai/widgetCSP": {
|
|
216
|
+
resource_domains: resourceDomains,
|
|
217
|
+
connect_domains: connectDomains,
|
|
218
|
+
},
|
|
219
|
+
"openai/widgetDomain": domain,
|
|
220
|
+
"openai/widgetDescription": view.description,
|
|
221
|
+
};
|
|
222
|
+
const fromView = {
|
|
223
|
+
"openai/widgetCSP": {
|
|
224
|
+
resource_domains: view.csp?.resourceDomains,
|
|
225
|
+
connect_domains: view.csp?.connectDomains,
|
|
226
|
+
frame_domains: view.csp?.frameDomains,
|
|
227
|
+
redirect_domains: view.csp?.redirectDomains,
|
|
228
|
+
},
|
|
229
|
+
"openai/widgetDomain": view.domain,
|
|
230
|
+
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
231
|
+
};
|
|
232
|
+
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
233
|
+
"openai/widgetDomain": overrides.domain,
|
|
234
|
+
});
|
|
235
|
+
if (view._meta) {
|
|
236
|
+
return { ...base, ...view._meta };
|
|
237
|
+
}
|
|
238
|
+
return base;
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
this.registerViewResource({
|
|
242
|
+
name: toolName,
|
|
243
|
+
viewResource,
|
|
244
|
+
view,
|
|
245
|
+
});
|
|
246
|
+
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
247
|
+
}
|
|
248
|
+
if (hosts.includes("mcp-app")) {
|
|
249
|
+
const viewResource = {
|
|
250
|
+
hostType: "mcp-app",
|
|
251
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
252
|
+
mimeType: "text/html;profile=mcp-app",
|
|
253
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
254
|
+
const defaults = {
|
|
255
|
+
ui: {
|
|
256
|
+
csp: {
|
|
257
|
+
resourceDomains,
|
|
258
|
+
connectDomains,
|
|
259
|
+
baseUriDomains,
|
|
260
|
+
},
|
|
261
|
+
domain,
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
const fromView = {
|
|
265
|
+
ui: {
|
|
266
|
+
...(view.description && { description: view.description }),
|
|
267
|
+
...(view.prefersBorder !== undefined && {
|
|
268
|
+
prefersBorder: view.prefersBorder,
|
|
269
|
+
}),
|
|
270
|
+
...(view.domain && { domain: view.domain }),
|
|
271
|
+
csp: {
|
|
272
|
+
...(view.csp?.resourceDomains && {
|
|
273
|
+
resourceDomains: view.csp.resourceDomains,
|
|
274
|
+
}),
|
|
275
|
+
...(view.csp?.connectDomains && {
|
|
276
|
+
connectDomains: view.csp.connectDomains,
|
|
277
|
+
}),
|
|
278
|
+
...(view.csp?.frameDomains && {
|
|
279
|
+
frameDomains: view.csp.frameDomains,
|
|
280
|
+
}),
|
|
281
|
+
...(view.csp?.baseUriDomains && {
|
|
282
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
283
|
+
}),
|
|
284
|
+
...(view.csp?.redirectDomains && {
|
|
285
|
+
redirectDomains: view.csp.redirectDomains,
|
|
286
|
+
}),
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
291
|
+
ui: overrides,
|
|
292
|
+
});
|
|
293
|
+
if (view._meta) {
|
|
294
|
+
return { ...base, ...view._meta };
|
|
295
|
+
}
|
|
296
|
+
return base;
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
this.registerViewResource({
|
|
300
|
+
name: toolName,
|
|
301
|
+
viewResource,
|
|
302
|
+
view,
|
|
303
|
+
});
|
|
304
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
305
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
306
|
+
toolMeta.ui = { resourceUri: viewResource.uri };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
registerViewResource({ name, viewResource, view, }) {
|
|
310
|
+
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
311
|
+
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
312
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
313
|
+
const isClaude = extra?.requestInfo?.headers?.["user-agent"] === "Claude-User";
|
|
314
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
315
|
+
const header = (key) => {
|
|
316
|
+
const val = headers[key];
|
|
317
|
+
return Array.isArray(val) ? val[0] : val;
|
|
318
|
+
};
|
|
319
|
+
let serverUrl;
|
|
320
|
+
const forwardedHost = header("x-forwarded-host");
|
|
321
|
+
const origin = header("origin");
|
|
322
|
+
const host = header("host");
|
|
323
|
+
if (forwardedHost) {
|
|
324
|
+
const proto = header("x-forwarded-proto") || "https";
|
|
325
|
+
serverUrl = `${proto}://${forwardedHost}`;
|
|
326
|
+
}
|
|
327
|
+
else if (origin) {
|
|
328
|
+
serverUrl = origin;
|
|
329
|
+
}
|
|
330
|
+
else if (host) {
|
|
331
|
+
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
332
|
+
? "http"
|
|
333
|
+
: "https";
|
|
334
|
+
serverUrl = `${proto}://${host}`;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
const devPort = process.env.__PORT || "3000";
|
|
338
|
+
serverUrl = `http://localhost:${devPort}`;
|
|
339
|
+
}
|
|
340
|
+
const html = isProduction
|
|
341
|
+
? templateHelper.renderProduction({
|
|
342
|
+
hostType,
|
|
343
|
+
serverUrl,
|
|
344
|
+
viewFile: this.lookupViewFile(view.component),
|
|
345
|
+
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
346
|
+
})
|
|
347
|
+
: templateHelper.renderDevelopment({
|
|
348
|
+
hostType,
|
|
349
|
+
serverUrl,
|
|
350
|
+
viewName: view.component,
|
|
351
|
+
});
|
|
352
|
+
const connectDomains = [serverUrl];
|
|
353
|
+
if (!isProduction) {
|
|
354
|
+
const wsUrl = new URL(serverUrl);
|
|
355
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
356
|
+
connectDomains.push(wsUrl.origin);
|
|
357
|
+
}
|
|
358
|
+
let contentMetaOverrides = {};
|
|
359
|
+
if (isClaude) {
|
|
360
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
361
|
+
const rawUrl = header("x-alpic-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
362
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
363
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
364
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
365
|
+
const hash = crypto
|
|
366
|
+
.createHash("sha256")
|
|
367
|
+
.update(url)
|
|
368
|
+
.digest("hex")
|
|
369
|
+
.slice(0, 32);
|
|
370
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
371
|
+
}
|
|
372
|
+
const contentMeta = buildContentMeta({
|
|
373
|
+
resourceDomains: [serverUrl],
|
|
374
|
+
connectDomains,
|
|
375
|
+
domain: serverUrl,
|
|
376
|
+
baseUriDomains: [serverUrl],
|
|
377
|
+
}, contentMetaOverrides);
|
|
378
|
+
return {
|
|
379
|
+
contents: [
|
|
380
|
+
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|
|
381
|
+
],
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
wrapHandler(cb, { attachViewUUID }) {
|
|
386
|
+
return async (args, extra) => {
|
|
387
|
+
const result = await cb(args, extra);
|
|
388
|
+
return {
|
|
389
|
+
...result,
|
|
390
|
+
content: normalizeContent(result.content),
|
|
391
|
+
...(attachViewUUID && {
|
|
392
|
+
_meta: {
|
|
393
|
+
...result._meta,
|
|
394
|
+
viewUUID: crypto.randomUUID(),
|
|
395
|
+
},
|
|
396
|
+
}),
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
computeViewVersionParam(viewName) {
|
|
401
|
+
if (process.env.NODE_ENV !== "production") {
|
|
402
|
+
return "";
|
|
403
|
+
}
|
|
404
|
+
try {
|
|
405
|
+
const viewFile = this.lookupViewFile(viewName);
|
|
406
|
+
const styleFile = this.lookupDistFile("style.css") ?? "";
|
|
407
|
+
const hash = crypto
|
|
408
|
+
.createHash("sha256")
|
|
409
|
+
.update(viewFile)
|
|
410
|
+
.update("\0")
|
|
411
|
+
.update(styleFile)
|
|
412
|
+
.digest("hex")
|
|
413
|
+
.slice(0, 8);
|
|
414
|
+
return `?v=${hash}`;
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
return "";
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
lookupViewFile(viewName) {
|
|
421
|
+
const manifest = this.readManifest();
|
|
422
|
+
for (const entry of Object.values(manifest)) {
|
|
423
|
+
if (entry?.isEntry && entry.name === viewName && entry.file) {
|
|
424
|
+
return entry.file;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
throw new Error(`View "${viewName}" not found in Vite manifest. Did the build complete successfully? Look for an entry with name "${viewName}" in dist/assets/.vite/manifest.json.`);
|
|
428
|
+
}
|
|
429
|
+
lookupDistFile(key) {
|
|
430
|
+
const manifest = this.readManifest();
|
|
431
|
+
return manifest[key]?.file;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
435
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
436
|
+
* (Cloudflare Workers, etc.) — the user's `skybridge build` emits the
|
|
437
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
438
|
+
*/
|
|
439
|
+
setViteManifest(manifest) {
|
|
440
|
+
this.viteManifest = manifest;
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
readManifest() {
|
|
444
|
+
if (this.viteManifest) {
|
|
445
|
+
return this.viteManifest;
|
|
446
|
+
}
|
|
447
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
448
|
+
}
|
|
449
|
+
registerTool(...args) {
|
|
450
|
+
const baseFn = McpServerBase.prototype.registerTool;
|
|
451
|
+
if (typeof args[0] === "string") {
|
|
452
|
+
baseFn.call(this, args[0], args[1], args[2]);
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
const config = args[0];
|
|
456
|
+
const cb = args[1];
|
|
457
|
+
const { name, view, _meta: userToolMeta, ...toolFields } = config;
|
|
458
|
+
const toolMeta = { ...userToolMeta };
|
|
459
|
+
if (view) {
|
|
460
|
+
this.enforceOneToolPerView(view.component, name);
|
|
461
|
+
this.registerViewResources(name, view, toolMeta);
|
|
462
|
+
}
|
|
463
|
+
const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });
|
|
464
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
//# sourceMappingURL=server.js.map
|