enpilink 1.0.2
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 +289 -0
- package/bin/run.js +5 -0
- package/dist/cli/build-helpers.d.ts +8 -0
- package/dist/cli/build-helpers.js +105 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +100 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +50 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/ensure-ssh-key.d.ts +17 -0
- package/dist/cli/ensure-ssh-key.js +45 -0
- package/dist/cli/ensure-ssh-key.js.map +1 -0
- package/dist/cli/ensure-ssh-key.test.d.ts +1 -0
- package/dist/cli/ensure-ssh-key.test.js +68 -0
- package/dist/cli/ensure-ssh-key.test.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/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.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 +14 -0
- package/dist/cli/telemetry.js +24 -0
- package/dist/cli/telemetry.js.map +1 -0
- package/dist/cli/tunnel-control-server.d.ts +11 -0
- package/dist/cli/tunnel-control-server.js +35 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.d.ts +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.d.ts +1 -0
- package/dist/cli/tunnel-handler.test.js +107 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel-providers/index.d.ts +5 -0
- package/dist/cli/tunnel-providers/index.js +5 -0
- package/dist/cli/tunnel-providers/index.js.map +1 -0
- package/dist/cli/tunnel-providers/srv-us.d.ts +18 -0
- package/dist/cli/tunnel-providers/srv-us.js +66 -0
- package/dist/cli/tunnel-providers/srv-us.js.map +1 -0
- package/dist/cli/tunnel-providers/srv-us.test.d.ts +1 -0
- package/dist/cli/tunnel-providers/srv-us.test.js +74 -0
- package/dist/cli/tunnel-providers/srv-us.test.js.map +1 -0
- package/dist/cli/tunnel-providers/types.d.ts +49 -0
- package/dist/cli/tunnel-providers/types.js +2 -0
- package/dist/cli/tunnel-providers/types.js.map +1 -0
- package/dist/cli/tunnel.d.ts +75 -0
- package/dist/cli/tunnel.js +254 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.d.ts +1 -0
- package/dist/cli/tunnel.test.js +255 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.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-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 +73 -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-open-tunnel-browser.d.ts +6 -0
- package/dist/cli/use-open-tunnel-browser.js +19 -0
- package/dist/cli/use-open-tunnel-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +17 -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 +8 -0
- package/dist/commands/build.js +97 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +13 -0
- package/dist/commands/dev.js +112 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +10 -0
- package/dist/commands/start.js +76 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +12 -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 +12 -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 +12 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/admin.d.ts +79 -0
- package/dist/server/admin.js +239 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/admin.test.d.ts +1 -0
- package/dist/server/admin.test.js +226 -0
- package/dist/server/admin.test.js.map +1 -0
- package/dist/server/analytics.d.ts +60 -0
- package/dist/server/analytics.js +168 -0
- package/dist/server/analytics.js.map +1 -0
- package/dist/server/analytics.test.d.ts +1 -0
- package/dist/server/analytics.test.js +179 -0
- package/dist/server/analytics.test.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 +48 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +134 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/auth.d.ts +20 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/config/config.test.d.ts +1 -0
- package/dist/server/config/config.test.js +214 -0
- package/dist/server/config/config.test.js.map +1 -0
- package/dist/server/config/index.d.ts +3 -0
- package/dist/server/config/index.js +4 -0
- package/dist/server/config/index.js.map +1 -0
- package/dist/server/config/resolve.d.ts +73 -0
- package/dist/server/config/resolve.js +167 -0
- package/dist/server/config/resolve.js.map +1 -0
- package/dist/server/config/router.d.ts +23 -0
- package/dist/server/config/router.js +119 -0
- package/dist/server/config/router.js.map +1 -0
- package/dist/server/config/schema.d.ts +78 -0
- package/dist/server/config/schema.js +158 -0
- package/dist/server/config/schema.js.map +1 -0
- package/dist/server/content-helpers.d.ts +67 -0
- package/dist/server/content-helpers.js +79 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +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 +129 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +464 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/server/index.js +14 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/inferUtilityTypes.d.ts +64 -0
- package/dist/server/inferUtilityTypes.js +2 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/log-sink.d.ts +16 -0
- package/dist/server/log-sink.js +66 -0
- package/dist/server/log-sink.js.map +1 -0
- package/dist/server/metric.d.ts +12 -0
- package/dist/server/metric.js +13 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +137 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +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.d.ts +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/mock-seed.d.ts +62 -0
- package/dist/server/mock-seed.js +251 -0
- package/dist/server/mock-seed.js.map +1 -0
- package/dist/server/mock-seed.test.d.ts +1 -0
- package/dist/server/mock-seed.test.js +122 -0
- package/dist/server/mock-seed.test.js.map +1 -0
- package/dist/server/observability.d.ts +149 -0
- package/dist/server/observability.js +340 -0
- package/dist/server/observability.js.map +1 -0
- package/dist/server/observability.test.d.ts +1 -0
- package/dist/server/observability.test.js +251 -0
- package/dist/server/observability.test.js.map +1 -0
- package/dist/server/otel.d.ts +45 -0
- package/dist/server/otel.js +117 -0
- package/dist/server/otel.js.map +1 -0
- package/dist/server/otel.test.d.ts +1 -0
- package/dist/server/otel.test.js +122 -0
- package/dist/server/otel.test.js.map +1 -0
- package/dist/server/server.d.ts +422 -0
- package/dist/server/server.js +684 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/storage/index.d.ts +23 -0
- package/dist/server/storage/index.js +46 -0
- package/dist/server/storage/index.js.map +1 -0
- package/dist/server/storage/memory.d.ts +30 -0
- package/dist/server/storage/memory.js +98 -0
- package/dist/server/storage/memory.js.map +1 -0
- package/dist/server/storage/memory.test.d.ts +1 -0
- package/dist/server/storage/memory.test.js +81 -0
- package/dist/server/storage/memory.test.js.map +1 -0
- package/dist/server/storage/postgres.d.ts +65 -0
- package/dist/server/storage/postgres.js +242 -0
- package/dist/server/storage/postgres.js.map +1 -0
- package/dist/server/storage/postgres.test.d.ts +1 -0
- package/dist/server/storage/postgres.test.js +182 -0
- package/dist/server/storage/postgres.test.js.map +1 -0
- package/dist/server/storage/sqlite.d.ts +33 -0
- package/dist/server/storage/sqlite.js +250 -0
- package/dist/server/storage/sqlite.js.map +1 -0
- package/dist/server/storage/sqlite.test.d.ts +1 -0
- package/dist/server/storage/sqlite.test.js +133 -0
- package/dist/server/storage/sqlite.test.js.map +1 -0
- package/dist/server/storage/types.d.ts +119 -0
- package/dist/server/storage/types.js +11 -0
- package/dist/server/storage/types.js.map +1 -0
- package/dist/server/templateHelper.d.ts +16 -0
- 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.d.ts +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/test/utils.d.ts +127 -0
- package/dist/test/utils.js +247 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +568 -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 +54 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +164 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/bridge.js +47 -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/web/bridges/apps-sdk/types.d.ts +147 -0
- package/dist/web/bridges/apps-sdk/types.js +10 -0
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +13 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +18 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +9 -0
- package/dist/web/bridges/get-adaptor.js +15 -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 +81 -0
- package/dist/web/bridges/mcp-app/adaptor.js +346 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +28 -0
- package/dist/web/bridges/mcp-app/bridge.js +124 -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 +19 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +19 -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.d.ts +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/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +243 -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 +7 -0
- package/dist/web/bridges/use-host-context.js +13 -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.d.ts +29 -0
- package/dist/web/create-store.js +64 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.d.ts +1 -0
- package/dist/web/create-store.test.js +129 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/web/data-llm.d.ts +47 -0
- package/dist/web/data-llm.js +100 -0
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.d.ts +1 -0
- package/dist/web/data-llm.test.js +142 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/web/generate-helpers.d.ts +120 -0
- package/dist/web/generate-helpers.js +115 -0
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/web/generate-helpers.test-d.js +211 -0
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.d.ts +1 -0
- package/dist/web/generate-helpers.test.js +17 -0
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/web/helpers/state.d.ts +7 -0
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.d.ts +1 -0
- package/dist/web/helpers/state.test.js +53 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/web/hooks/index.d.ts +17 -0
- package/dist/web/hooks/index.js +18 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +20 -0
- package/dist/web/hooks/test/utils.js +75 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/web/hooks/use-call-tool.d.ts +146 -0
- package/dist/web/hooks/use-call-tool.js +96 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/web/hooks/use-call-tool.test-d.js +104 -0
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/web/hooks/use-call-tool.test.js +211 -0
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +24 -0
- package/dist/web/hooks/use-display-mode.js +29 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test-d.d.ts +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.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test.js +41 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-download.d.ts +5 -0
- package/dist/web/hooks/use-download.js +8 -0
- package/dist/web/hooks/use-download.js.map +1 -0
- package/dist/web/hooks/use-download.test.d.ts +1 -0
- package/dist/web/hooks/use-download.test.js +95 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +39 -0
- package/dist/web/hooks/use-files.js +42 -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/web/hooks/use-intent.d.ts +30 -0
- package/dist/web/hooks/use-intent.js +34 -0
- package/dist/web/hooks/use-intent.js.map +1 -0
- package/dist/web/hooks/use-intent.test.d.ts +1 -0
- package/dist/web/hooks/use-intent.test.js +85 -0
- package/dist/web/hooks/use-intent.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +24 -0
- package/dist/web/hooks/use-layout.js +25 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +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-notify.d.ts +29 -0
- package/dist/web/hooks/use-notify.js +33 -0
- package/dist/web/hooks/use-notify.js.map +1 -0
- package/dist/web/hooks/use-notify.test.d.ts +1 -0
- package/dist/web/hooks/use-notify.test.js +105 -0
- package/dist/web/hooks/use-notify.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +20 -0
- package/dist/web/hooks/use-open-external.js +24 -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/web/hooks/use-open-external.test.js +65 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +52 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +24 -0
- package/dist/web/hooks/use-request-modal.js +31 -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/web/hooks/use-request-modal.test.js +61 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-request-size.d.ts +20 -0
- package/dist/web/hooks/use-request-size.js +24 -0
- package/dist/web/hooks/use-request-size.js.map +1 -0
- package/dist/web/hooks/use-request-size.test.d.ts +1 -0
- package/dist/web/hooks/use-request-size.test.js +65 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -0
- package/dist/web/hooks/use-send-follow-up-message.js +25 -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 +18 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +25 -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/web/hooks/use-tool-info.d.ts +87 -0
- package/dist/web/hooks/use-tool-info.js +49 -0
- 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 +91 -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/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 +20 -0
- package/dist/web/hooks/use-user.js +37 -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 +122 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-view-state.d.ts +25 -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/web/index.d.ts +7 -0
- package/dist/web/index.js +8 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-view.d.ts +20 -0
- package/dist/web/mount-view.js +46 -0
- 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 +81 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +33 -0
- package/dist/web/plugin/plugin.js +189 -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/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/web/plugin/transform-data-llm.js +96 -0
- 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 +81 -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/web/proxy.d.ts +1 -0
- package/dist/web/proxy.js +52 -0
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +20 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +125 -0
- package/scripts/postinstall.mjs +45 -0
- package/tsconfig.base.json +36 -0
|
@@ -0,0 +1,684 @@
|
|
|
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 { installAnalytics } from "./analytics.js";
|
|
10
|
+
import { createApp } from "./express.js";
|
|
11
|
+
import { getActiveStorage, serverLog, setActiveStorage } from "./log-sink.js";
|
|
12
|
+
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
13
|
+
import { templateHelper } from "./templateHelper.js";
|
|
14
|
+
const mergeWithUnion = (target, source) => {
|
|
15
|
+
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
16
|
+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
|
|
17
|
+
return union(targetVal, sourceVal);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Coerce a tool handler's return value into an MCP `content` array. Strings
|
|
23
|
+
* become a single `TextContent`; a single block is wrapped in an array;
|
|
24
|
+
* `undefined` produces `[]`. Mostly used internally — exported so consumers
|
|
25
|
+
* who build content lazily can apply the same normalization.
|
|
26
|
+
*/
|
|
27
|
+
export function normalizeContent(content) {
|
|
28
|
+
if (content === undefined) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
if (typeof content === "string") {
|
|
32
|
+
return [{ type: "text", text: content }];
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(content)) {
|
|
35
|
+
return content;
|
|
36
|
+
}
|
|
37
|
+
return [content];
|
|
38
|
+
}
|
|
39
|
+
const McpServerBaseOmitted = McpServerBase;
|
|
40
|
+
/**
|
|
41
|
+
* The enpilink server. Extends the MCP SDK's `McpServer` with a typed tool
|
|
42
|
+
* registry, view resources, an embedded Express app, and protocol-level
|
|
43
|
+
* middleware. Construct it with the same `Implementation` info you would pass
|
|
44
|
+
* to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
|
|
45
|
+
* then call {@link McpServer.run} to start the HTTP server.
|
|
46
|
+
*
|
|
47
|
+
* The `TTools` generic accumulates each registered tool's input/output/meta
|
|
48
|
+
* shape, so `typeof server` carries enough information for view-side helpers
|
|
49
|
+
* like {@link generateHelpers} to produce fully-typed hooks.
|
|
50
|
+
*
|
|
51
|
+
* @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
|
|
52
|
+
* chaining; you almost never set this manually.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
|
|
57
|
+
* .registerTool({
|
|
58
|
+
* name: "search",
|
|
59
|
+
* inputSchema: { query: z.string() },
|
|
60
|
+
* view: { component: "search" },
|
|
61
|
+
* }, async ({ query }) => ({ content: `Results for ${query}` }));
|
|
62
|
+
*
|
|
63
|
+
* await server.run();
|
|
64
|
+
* export type AppType = typeof server;
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @see https://docs.enpitech.dev/api-reference/mcp-server
|
|
68
|
+
*/
|
|
69
|
+
// Side channel populated by `dist/__entry.js` before user code is imported.
|
|
70
|
+
// Set at module scope rather than passed through the constructor because the
|
|
71
|
+
// wrapper has the manifest before the user's `new McpServer(...)` runs, and
|
|
72
|
+
// threading it through every call site (including user templates) is exactly
|
|
73
|
+
// the boilerplate this design is trying to hide.
|
|
74
|
+
let pendingBuildManifest = null;
|
|
75
|
+
/**
|
|
76
|
+
* Prime the build-time Vite manifest before user code constructs its
|
|
77
|
+
* `McpServer`. Called from the generated `dist/__entry.js`; not part of the
|
|
78
|
+
* user-facing API.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function __setBuildManifest(manifest) {
|
|
83
|
+
pendingBuildManifest = manifest;
|
|
84
|
+
}
|
|
85
|
+
export class McpServer extends McpServerBaseOmitted {
|
|
86
|
+
/**
|
|
87
|
+
* The underlying Express app. Use this to extend the HTTP server with
|
|
88
|
+
* custom routes, middleware, or settings — e.g.
|
|
89
|
+
* `server.express.get("/health", ...)`.
|
|
90
|
+
*
|
|
91
|
+
* `express.json()` is pre-applied. Register your handlers before `run()`;
|
|
92
|
+
* after `run()`, dev-mode middleware, the `/mcp` route, and the default
|
|
93
|
+
* error handler are appended in that order.
|
|
94
|
+
*
|
|
95
|
+
* Note: enpitech Cloud only routes traffic to `/mcp` — custom routes work
|
|
96
|
+
* locally and on self-hosted deployments.
|
|
97
|
+
*/
|
|
98
|
+
express;
|
|
99
|
+
customErrorMiddleware = [];
|
|
100
|
+
mcpMiddlewareEntries = [];
|
|
101
|
+
mcpMiddlewareApplied = false;
|
|
102
|
+
/**
|
|
103
|
+
* The active analytics {@link StorageAdapter}, or `null` when analytics is
|
|
104
|
+
* disabled (`ENPILINK_ANALYTICS` unset). Set during `run()`/`connect()` and
|
|
105
|
+
* closed on shutdown.
|
|
106
|
+
*/
|
|
107
|
+
activeStorage = null;
|
|
108
|
+
/**
|
|
109
|
+
* The optional OTel export sink (M6), set when `ENPILINK_OTEL` + an OTLP
|
|
110
|
+
* endpoint are configured. Shut down on server shutdown via {@link closeStorage}.
|
|
111
|
+
*/
|
|
112
|
+
otelSink = null;
|
|
113
|
+
claimedViews = new Map();
|
|
114
|
+
viewMetaBuilders = new Map();
|
|
115
|
+
viteManifest = null;
|
|
116
|
+
serverInfo;
|
|
117
|
+
serverOptions;
|
|
118
|
+
constructor(serverInfo, options) {
|
|
119
|
+
super(serverInfo, options);
|
|
120
|
+
this.serverInfo = serverInfo;
|
|
121
|
+
this.serverOptions = options;
|
|
122
|
+
this.express = express();
|
|
123
|
+
this.express.use(express.json());
|
|
124
|
+
// Pick up the manifest if `dist/__entry.js` primed it before importing
|
|
125
|
+
// user code. Consume-once: clear after the first construction so a
|
|
126
|
+
// subsequent test that doesn't prime can't inherit stale state.
|
|
127
|
+
// Explicit `setViteManifest` calls still win because they happen after
|
|
128
|
+
// construction.
|
|
129
|
+
if (pendingBuildManifest) {
|
|
130
|
+
this.setViteManifest(pendingBuildManifest);
|
|
131
|
+
pendingBuildManifest = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The active analytics/observability {@link StorageAdapter} for this server,
|
|
136
|
+
* or `null` when analytics is disabled (`ENPILINK_ANALYTICS` unset) or before
|
|
137
|
+
* `run()`/`connect()` has been called.
|
|
138
|
+
*
|
|
139
|
+
* This is the in-process handoff for the observability API (M3): it is the
|
|
140
|
+
* SAME instance the analytics middleware writes `tool_call` events to and the
|
|
141
|
+
* log sink mirrors logs to. (A process-wide `getActiveStorage()` from
|
|
142
|
+
* `./log-sink.js` returns the same value for code without a server handle.)
|
|
143
|
+
*/
|
|
144
|
+
get storage() {
|
|
145
|
+
return this.activeStorage;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Adopt a storage adapter the server should OWN for shutdown — used by the
|
|
149
|
+
* prod admin plane (M5), which initializes a storage adapter independent of
|
|
150
|
+
* analytics so the config + observability routers have a backing store even
|
|
151
|
+
* when `ENPILINK_ANALYTICS` is off. Closed on shutdown via {@link closeStorage}.
|
|
152
|
+
*
|
|
153
|
+
* No-op when analytics already set `activeStorage` (the admin reuses it and
|
|
154
|
+
* does not pass its own adapter here).
|
|
155
|
+
*
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
adoptStorage(storage) {
|
|
159
|
+
if (!this.activeStorage) {
|
|
160
|
+
this.activeStorage = storage;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
use(pathOrHandler, ...handlers) {
|
|
164
|
+
// Branching is load-bearing: Express's `app.use` overloads can't be
|
|
165
|
+
// resolved against a `string | RequestHandler` union, so we narrow.
|
|
166
|
+
if (typeof pathOrHandler === "string") {
|
|
167
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.express.use(pathOrHandler, ...handlers);
|
|
171
|
+
}
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
useOnError(pathOrHandler, ...handlers) {
|
|
175
|
+
if (typeof pathOrHandler === "string") {
|
|
176
|
+
this.customErrorMiddleware.push({ path: pathOrHandler, handlers });
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.customErrorMiddleware.push({
|
|
180
|
+
handlers: [pathOrHandler, ...handlers],
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
mcpMiddleware(filterOrHandler,
|
|
186
|
+
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
187
|
+
maybeHandler) {
|
|
188
|
+
if (this.mcpMiddlewareApplied) {
|
|
189
|
+
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
190
|
+
}
|
|
191
|
+
const handler = maybeHandler;
|
|
192
|
+
if (typeof filterOrHandler === "function") {
|
|
193
|
+
this.mcpMiddlewareEntries.push({
|
|
194
|
+
filter: null,
|
|
195
|
+
handler: filterOrHandler,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
else if (handler) {
|
|
199
|
+
this.mcpMiddlewareEntries.push({
|
|
200
|
+
filter: filterOrHandler,
|
|
201
|
+
handler,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
throw new Error("mcpMiddleware requires a handler function when a filter is provided");
|
|
206
|
+
}
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
async applyMcpMiddleware() {
|
|
210
|
+
if (this.mcpMiddlewareApplied) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
this.mcpMiddlewareApplied = true;
|
|
214
|
+
// Surface view-resource _meta on `resources/list` (per ext-apps spec:
|
|
215
|
+
// hosts/checkers read CSP & domain at list time before fetching content).
|
|
216
|
+
const viewListMetaEntry = {
|
|
217
|
+
filter: "resources/list",
|
|
218
|
+
handler: async (_req, extra, next) => {
|
|
219
|
+
const result = (await next());
|
|
220
|
+
for (const resource of result.resources) {
|
|
221
|
+
const builder = this.viewMetaBuilders.get(resource.uri);
|
|
222
|
+
if (!builder) {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const meta = builder(extra);
|
|
226
|
+
resource._meta = {
|
|
227
|
+
...(resource._meta ?? {}),
|
|
228
|
+
...meta,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
// Opt-in analytics (M2): only when `ENPILINK_ANALYTICS` is set does this
|
|
235
|
+
// resolve + init a StorageAdapter and produce a monitoring entry. When off
|
|
236
|
+
// it returns null — no adapter, no file, no middleware, zero overhead.
|
|
237
|
+
const analytics = await installAnalytics();
|
|
238
|
+
if (analytics) {
|
|
239
|
+
this.activeStorage = analytics.storage;
|
|
240
|
+
this.otelSink = analytics.otel;
|
|
241
|
+
}
|
|
242
|
+
const entries = [
|
|
243
|
+
...(analytics ? [analytics.entry] : []),
|
|
244
|
+
viewListMetaEntry,
|
|
245
|
+
...this.mcpMiddlewareEntries,
|
|
246
|
+
];
|
|
247
|
+
if (entries.length === 0) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
251
|
+
const instrumentMap = (map, isNotification) => {
|
|
252
|
+
for (const [method, handler] of map) {
|
|
253
|
+
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
254
|
+
}
|
|
255
|
+
const originalSet = map.set.bind(map);
|
|
256
|
+
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
257
|
+
};
|
|
258
|
+
instrumentMap(requestHandlers, false);
|
|
259
|
+
instrumentMap(notificationHandlers, true);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Close the active analytics storage (if any) and clear the shared
|
|
263
|
+
* active-storage reference. Idempotent and error-swallowing — safe to call
|
|
264
|
+
* from a shutdown handler.
|
|
265
|
+
*/
|
|
266
|
+
async closeStorage() {
|
|
267
|
+
const otel = this.otelSink;
|
|
268
|
+
if (otel) {
|
|
269
|
+
this.otelSink = null;
|
|
270
|
+
try {
|
|
271
|
+
await otel.shutdown();
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
// Shutdown must not hang or throw on an OTel flush/close failure.
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const storage = this.activeStorage;
|
|
278
|
+
if (!storage) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.activeStorage = null;
|
|
282
|
+
if (getActiveStorage() === storage) {
|
|
283
|
+
setActiveStorage(null);
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
await storage.close();
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Shutdown must not hang or throw on a storage close failure.
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Connect to an MCP transport (override of the SDK's `connect`). Use this
|
|
294
|
+
* when you're embedding enpilink in a host that already manages its own
|
|
295
|
+
* transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
|
|
296
|
+
* which sets the transport up for you. Locks in any middleware registered
|
|
297
|
+
* via {@link McpServer.mcpMiddleware} — further calls to that method will
|
|
298
|
+
* throw afterwards.
|
|
299
|
+
*/
|
|
300
|
+
async connect(transport) {
|
|
301
|
+
await this.applyMcpMiddleware();
|
|
302
|
+
return McpServerBase.prototype.connect.call(this, transport);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Per-request stateless connect. The SDK's `Protocol` only allows one
|
|
306
|
+
* transport per instance, so we can't reuse this `McpServer` across
|
|
307
|
+
* concurrent requests. The SDK's idiomatic fix is a `() => McpServer`
|
|
308
|
+
* factory, but that would break enpilink's singleton API — so instead
|
|
309
|
+
* we build a fresh underlying `Server` per request and share the main
|
|
310
|
+
* server's handler maps by reference. The cast is unavoidable: there's
|
|
311
|
+
* no public API to inject handler maps. `getHandlerMaps` validates the
|
|
312
|
+
* read side and fails fast on SDK field renames.
|
|
313
|
+
*/
|
|
314
|
+
async connectStatelessTransport(transport) {
|
|
315
|
+
await this.applyMcpMiddleware();
|
|
316
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
317
|
+
const fresh = new SdkServer(this.serverInfo, this.serverOptions);
|
|
318
|
+
const target = fresh;
|
|
319
|
+
target._requestHandlers = requestHandlers;
|
|
320
|
+
target._notificationHandlers = notificationHandlers;
|
|
321
|
+
await fresh.connect(transport);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
|
|
325
|
+
* mounts the `/mcp` route, applies any custom Express middleware registered
|
|
326
|
+
* via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
|
|
327
|
+
* any MCP middleware registered via {@link McpServer.mcpMiddleware}.
|
|
328
|
+
*
|
|
329
|
+
* On Cloudflare Workers / workerd, returns an object exposing `fetch` so
|
|
330
|
+
* the runtime can bridge incoming requests to the Node HTTP server. On
|
|
331
|
+
* Vercel (`VERCEL === "1"`), returns the Express app directly so the
|
|
332
|
+
* serverless function entry can call it as a `(req, res)` handler. On
|
|
333
|
+
* Node, returns `undefined` once listening.
|
|
334
|
+
*/
|
|
335
|
+
async run() {
|
|
336
|
+
await this.applyMcpMiddleware();
|
|
337
|
+
if (process.env.VERCEL === "1") {
|
|
338
|
+
// createApp only reads httpServer inside its dev-only branch
|
|
339
|
+
// (viewsDevServer); under VERCEL=1 + NODE_ENV=production it's a
|
|
340
|
+
// bare object passed to satisfy the required parameter.
|
|
341
|
+
const httpServer = http.createServer();
|
|
342
|
+
await createApp({
|
|
343
|
+
mcpServer: this,
|
|
344
|
+
httpServer,
|
|
345
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
346
|
+
});
|
|
347
|
+
return this.express;
|
|
348
|
+
}
|
|
349
|
+
const httpServer = http.createServer();
|
|
350
|
+
await createApp({
|
|
351
|
+
mcpServer: this,
|
|
352
|
+
httpServer,
|
|
353
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
354
|
+
});
|
|
355
|
+
httpServer.on("request", this.express);
|
|
356
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
357
|
+
await new Promise((resolve, reject) => {
|
|
358
|
+
httpServer.on("error", (error) => {
|
|
359
|
+
serverLog("error", "Failed to start server", {
|
|
360
|
+
error: error.message,
|
|
361
|
+
});
|
|
362
|
+
reject(error);
|
|
363
|
+
});
|
|
364
|
+
httpServer.listen(port, () => {
|
|
365
|
+
resolve();
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
// On workerd, bridge the Node http server to a Workers fetch handler.
|
|
369
|
+
// The specifier is held in a variable to sidestep tsc's module resolution
|
|
370
|
+
// (`cloudflare:node` only exists under wrangler/workerd).
|
|
371
|
+
if (typeof navigator !== "undefined" &&
|
|
372
|
+
navigator.userAgent === "Cloudflare-Workers") {
|
|
373
|
+
const cloudflareNode = "cloudflare:node";
|
|
374
|
+
const { httpServerHandler } = await import(cloudflareNode);
|
|
375
|
+
return httpServerHandler({ port });
|
|
376
|
+
}
|
|
377
|
+
const shutdown = () => {
|
|
378
|
+
// Drop both handlers so a second signal falls through to Node's default
|
|
379
|
+
// (force-quit on a second Ctrl+C while drain is hanging).
|
|
380
|
+
process.off("SIGTERM", shutdown);
|
|
381
|
+
process.off("SIGINT", shutdown);
|
|
382
|
+
// Close the analytics storage (if any) so e.g. the sqlite file handle is
|
|
383
|
+
// released. Fire-and-forget + swallow: shutdown must not hang or throw.
|
|
384
|
+
void this.closeStorage();
|
|
385
|
+
httpServer.close(() => process.exit(0));
|
|
386
|
+
// Force exit if connections don't drain in time so the port is still
|
|
387
|
+
// released promptly (e.g. for nodemon restarts).
|
|
388
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
389
|
+
};
|
|
390
|
+
process.on("SIGTERM", shutdown);
|
|
391
|
+
process.on("SIGINT", shutdown);
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
enforceOneToolPerView(component, toolName) {
|
|
395
|
+
const existingTool = this.claimedViews.get(component);
|
|
396
|
+
if (existingTool) {
|
|
397
|
+
throw new Error(`enpilink: view "${component}" is already used by tool "${existingTool}". Tool "${toolName}" cannot also reference it — each view backs exactly one tool.`);
|
|
398
|
+
}
|
|
399
|
+
this.claimedViews.set(component, toolName);
|
|
400
|
+
}
|
|
401
|
+
resolveViewRequestContext(extra) {
|
|
402
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
403
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
404
|
+
const header = (key) => {
|
|
405
|
+
const val = headers[key];
|
|
406
|
+
return Array.isArray(val) ? val[0] : val;
|
|
407
|
+
};
|
|
408
|
+
const isClaude = header("user-agent") === "Claude-User";
|
|
409
|
+
let serverUrl;
|
|
410
|
+
const forwardedHost = header("x-forwarded-host");
|
|
411
|
+
const origin = header("origin");
|
|
412
|
+
const host = header("host");
|
|
413
|
+
if (forwardedHost) {
|
|
414
|
+
const proto = header("x-forwarded-proto") || "https";
|
|
415
|
+
serverUrl = `${proto}://${forwardedHost}`;
|
|
416
|
+
}
|
|
417
|
+
else if (origin) {
|
|
418
|
+
serverUrl = origin;
|
|
419
|
+
}
|
|
420
|
+
else if (host) {
|
|
421
|
+
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
422
|
+
? "http"
|
|
423
|
+
: "https";
|
|
424
|
+
serverUrl = `${proto}://${host}`;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
const devPort = process.env.__PORT || "3000";
|
|
428
|
+
serverUrl = `http://localhost:${devPort}`;
|
|
429
|
+
}
|
|
430
|
+
const connectDomains = [serverUrl];
|
|
431
|
+
if (!isProduction) {
|
|
432
|
+
const wsUrl = new URL(serverUrl);
|
|
433
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
434
|
+
connectDomains.push(wsUrl.origin);
|
|
435
|
+
}
|
|
436
|
+
let contentMetaOverrides = {};
|
|
437
|
+
if (isClaude) {
|
|
438
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
439
|
+
const rawUrl = header("x-enpitech-forwarded-url") ?? `${serverUrl}${pathname}`;
|
|
440
|
+
// Strip a lone trailing slash so the hash matches the connector URL
|
|
441
|
+
// as registered with Claude (which has no trailing slash on bare origins).
|
|
442
|
+
const url = rawUrl.endsWith("/") ? rawUrl.slice(0, -1) : rawUrl;
|
|
443
|
+
const hash = crypto
|
|
444
|
+
.createHash("sha256")
|
|
445
|
+
.update(url)
|
|
446
|
+
.digest("hex")
|
|
447
|
+
.slice(0, 32);
|
|
448
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
449
|
+
}
|
|
450
|
+
return { serverUrl, connectDomains, contentMetaOverrides };
|
|
451
|
+
}
|
|
452
|
+
registerViewResources(toolName, view, toolMeta) {
|
|
453
|
+
const hosts = view.hosts ?? ["apps-sdk", "mcp-app"];
|
|
454
|
+
// Append a content-derived version param so hosts (e.g. ChatGPT) bust
|
|
455
|
+
// their cache when the bundle changes, but keep the URI stable across
|
|
456
|
+
// `tools/list` calls when the bundle hasn't changed.
|
|
457
|
+
const versionParam = this.computeViewVersionParam(view.component);
|
|
458
|
+
if (hosts.includes("apps-sdk")) {
|
|
459
|
+
const viewResource = {
|
|
460
|
+
hostType: "apps-sdk",
|
|
461
|
+
uri: `ui://views/apps-sdk/${view.component}.html${versionParam}`,
|
|
462
|
+
mimeType: "text/html+enpilink",
|
|
463
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
464
|
+
const defaults = {
|
|
465
|
+
"openai/widgetCSP": {
|
|
466
|
+
resource_domains: resourceDomains,
|
|
467
|
+
connect_domains: connectDomains,
|
|
468
|
+
},
|
|
469
|
+
"openai/widgetDomain": domain,
|
|
470
|
+
"openai/widgetDescription": view.description,
|
|
471
|
+
};
|
|
472
|
+
const fromView = {
|
|
473
|
+
"openai/widgetCSP": {
|
|
474
|
+
resource_domains: view.csp?.resourceDomains,
|
|
475
|
+
connect_domains: view.csp?.connectDomains,
|
|
476
|
+
frame_domains: view.csp?.frameDomains,
|
|
477
|
+
redirect_domains: view.csp?.redirectDomains,
|
|
478
|
+
},
|
|
479
|
+
"openai/widgetDomain": view.domain,
|
|
480
|
+
"openai/widgetPrefersBorder": view.prefersBorder,
|
|
481
|
+
};
|
|
482
|
+
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
483
|
+
"openai/widgetDomain": overrides.domain,
|
|
484
|
+
});
|
|
485
|
+
if (view._meta) {
|
|
486
|
+
return { ...base, ...view._meta };
|
|
487
|
+
}
|
|
488
|
+
return base;
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
this.registerViewResource({
|
|
492
|
+
name: toolName,
|
|
493
|
+
viewResource,
|
|
494
|
+
view,
|
|
495
|
+
});
|
|
496
|
+
toolMeta["openai/outputTemplate"] = viewResource.uri;
|
|
497
|
+
}
|
|
498
|
+
if (hosts.includes("mcp-app")) {
|
|
499
|
+
const viewResource = {
|
|
500
|
+
hostType: "mcp-app",
|
|
501
|
+
uri: `ui://views/ext-apps/${view.component}.html${versionParam}`,
|
|
502
|
+
mimeType: "text/html;profile=mcp-app",
|
|
503
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain, baseUriDomains }, overrides) => {
|
|
504
|
+
const defaults = {
|
|
505
|
+
ui: {
|
|
506
|
+
csp: {
|
|
507
|
+
resourceDomains,
|
|
508
|
+
connectDomains,
|
|
509
|
+
baseUriDomains,
|
|
510
|
+
},
|
|
511
|
+
domain,
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
const fromView = {
|
|
515
|
+
ui: {
|
|
516
|
+
...(view.description && { description: view.description }),
|
|
517
|
+
...(view.prefersBorder !== undefined && {
|
|
518
|
+
prefersBorder: view.prefersBorder,
|
|
519
|
+
}),
|
|
520
|
+
...(view.domain && { domain: view.domain }),
|
|
521
|
+
csp: {
|
|
522
|
+
...(view.csp?.resourceDomains && {
|
|
523
|
+
resourceDomains: view.csp.resourceDomains,
|
|
524
|
+
}),
|
|
525
|
+
...(view.csp?.connectDomains && {
|
|
526
|
+
connectDomains: view.csp.connectDomains,
|
|
527
|
+
}),
|
|
528
|
+
...(view.csp?.frameDomains && {
|
|
529
|
+
frameDomains: view.csp.frameDomains,
|
|
530
|
+
}),
|
|
531
|
+
...(view.csp?.baseUriDomains && {
|
|
532
|
+
baseUriDomains: view.csp.baseUriDomains,
|
|
533
|
+
}),
|
|
534
|
+
...(view.csp?.redirectDomains && {
|
|
535
|
+
redirectDomains: view.csp.redirectDomains,
|
|
536
|
+
}),
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
const base = mergeWithUnion(mergeWithUnion(defaults, fromView), {
|
|
541
|
+
ui: overrides,
|
|
542
|
+
});
|
|
543
|
+
if (view._meta) {
|
|
544
|
+
return { ...base, ...view._meta };
|
|
545
|
+
}
|
|
546
|
+
return base;
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
this.registerViewResource({
|
|
550
|
+
name: toolName,
|
|
551
|
+
viewResource,
|
|
552
|
+
view,
|
|
553
|
+
});
|
|
554
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
555
|
+
toolMeta["ui/resourceUri"] = viewResource.uri;
|
|
556
|
+
toolMeta.ui = { ...toolMeta.ui, resourceUri: viewResource.uri };
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
registerViewResource({ name, viewResource, view, }) {
|
|
560
|
+
const { hostType, uri: viewUri, mimeType, buildContentMeta } = viewResource;
|
|
561
|
+
const buildMeta = (extra) => {
|
|
562
|
+
const { serverUrl, connectDomains, contentMetaOverrides } = this.resolveViewRequestContext(extra);
|
|
563
|
+
return buildContentMeta({
|
|
564
|
+
resourceDomains: [serverUrl],
|
|
565
|
+
connectDomains,
|
|
566
|
+
domain: serverUrl,
|
|
567
|
+
baseUriDomains: [serverUrl],
|
|
568
|
+
}, contentMetaOverrides);
|
|
569
|
+
};
|
|
570
|
+
this.viewMetaBuilders.set(viewUri, buildMeta);
|
|
571
|
+
this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
|
|
572
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
573
|
+
const { serverUrl } = this.resolveViewRequestContext(extra);
|
|
574
|
+
const html = isProduction
|
|
575
|
+
? templateHelper.renderProduction({
|
|
576
|
+
hostType,
|
|
577
|
+
serverUrl,
|
|
578
|
+
viewFile: this.lookupViewFile(view.component),
|
|
579
|
+
styleFile: this.lookupDistFile("style.css") ?? "",
|
|
580
|
+
})
|
|
581
|
+
: templateHelper.renderDevelopment({
|
|
582
|
+
hostType,
|
|
583
|
+
serverUrl,
|
|
584
|
+
viewName: view.component,
|
|
585
|
+
});
|
|
586
|
+
return {
|
|
587
|
+
contents: [
|
|
588
|
+
{ uri: uri.href, mimeType, text: html, _meta: buildMeta(extra) },
|
|
589
|
+
],
|
|
590
|
+
};
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
wrapHandler(cb, { attachViewUUID }) {
|
|
594
|
+
return async (args, extra) => {
|
|
595
|
+
const result = await cb(args, extra);
|
|
596
|
+
return {
|
|
597
|
+
...result,
|
|
598
|
+
content: normalizeContent(result.content),
|
|
599
|
+
...(attachViewUUID && {
|
|
600
|
+
_meta: {
|
|
601
|
+
...result._meta,
|
|
602
|
+
viewUUID: crypto.randomUUID(),
|
|
603
|
+
},
|
|
604
|
+
}),
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
computeViewVersionParam(viewName) {
|
|
609
|
+
if (process.env.NODE_ENV !== "production") {
|
|
610
|
+
return "";
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
const viewFile = this.lookupViewFile(viewName);
|
|
614
|
+
const styleFile = this.lookupDistFile("style.css") ?? "";
|
|
615
|
+
const hash = crypto
|
|
616
|
+
.createHash("sha256")
|
|
617
|
+
.update(viewFile)
|
|
618
|
+
.update("\0")
|
|
619
|
+
.update(styleFile)
|
|
620
|
+
.digest("hex")
|
|
621
|
+
.slice(0, 8);
|
|
622
|
+
return `?v=${hash}`;
|
|
623
|
+
}
|
|
624
|
+
catch {
|
|
625
|
+
return "";
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
lookupViewFile(viewName) {
|
|
629
|
+
const manifest = this.readManifest();
|
|
630
|
+
for (const entry of Object.values(manifest)) {
|
|
631
|
+
if (entry?.isEntry && entry.name === viewName && entry.file) {
|
|
632
|
+
return entry.file;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
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.`);
|
|
636
|
+
}
|
|
637
|
+
lookupDistFile(key) {
|
|
638
|
+
const manifest = this.readManifest();
|
|
639
|
+
return manifest[key]?.file;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Inject the Vite manifest as a value rather than letting `readManifest()`
|
|
643
|
+
* load it from disk. Required for runtimes without a usable filesystem
|
|
644
|
+
* (Cloudflare Workers, etc.) — the user's `enpilink build` emits the
|
|
645
|
+
* manifest as a JS module which the entry imports and passes here.
|
|
646
|
+
*/
|
|
647
|
+
setViteManifest(manifest) {
|
|
648
|
+
this.viteManifest = manifest;
|
|
649
|
+
return this;
|
|
650
|
+
}
|
|
651
|
+
readManifest() {
|
|
652
|
+
if (this.viteManifest) {
|
|
653
|
+
return this.viteManifest;
|
|
654
|
+
}
|
|
655
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
656
|
+
}
|
|
657
|
+
registerTool(...args) {
|
|
658
|
+
const baseFn = McpServerBase.prototype.registerTool;
|
|
659
|
+
if (typeof args[0] === "string") {
|
|
660
|
+
baseFn.call(this, args[0], args[1], args[2]);
|
|
661
|
+
return this;
|
|
662
|
+
}
|
|
663
|
+
const config = args[0];
|
|
664
|
+
const cb = args[1];
|
|
665
|
+
const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
|
|
666
|
+
const toolMeta = { ...userToolMeta };
|
|
667
|
+
if (securitySchemes) {
|
|
668
|
+
// SEP-1488 puts `securitySchemes` at the top level of the tool
|
|
669
|
+
// descriptor, but the SDK's `registerTool` drops unknown top-level
|
|
670
|
+
// fields, so the canonical spot isn't reachable without intercepting
|
|
671
|
+
// `tools/list`. Use the `_meta` back-compat mirror documented in the
|
|
672
|
+
// Apps SDK reference until SEP-1488 lands in the spec.
|
|
673
|
+
toolMeta.securitySchemes = securitySchemes;
|
|
674
|
+
}
|
|
675
|
+
if (view) {
|
|
676
|
+
this.enforceOneToolPerView(view.component, name);
|
|
677
|
+
this.registerViewResources(name, view, toolMeta);
|
|
678
|
+
}
|
|
679
|
+
const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });
|
|
680
|
+
baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
|
|
681
|
+
return this;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
//# sourceMappingURL=server.js.map
|