skybridge 0.0.0-dev.ecf87cf → 0.0.0-dev.ed29eee
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 +154 -0
- package/bin/run.js +5 -0
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +107 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +132 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +73 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.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/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/resolve-skybridge-config.d.ts +5 -0
- package/dist/cli/resolve-skybridge-config.js +18 -0
- package/dist/cli/resolve-skybridge-config.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/run-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +89 -0
- package/dist/cli/run-plain.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/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 +16 -0
- package/dist/cli/use-nodemon.js +84 -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 +15 -0
- package/dist/cli/use-typescript-check.js +97 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +6 -0
- package/dist/commands/build.js +31 -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 +128 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.js +55 -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/context-warnings.d.ts +5 -0
- package/dist/context-warnings.js +31 -0
- package/dist/context-warnings.js.map +1 -0
- package/dist/context-warnings.test.js +28 -0
- package/dist/context-warnings.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.js +134 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/auth/discovery.d.ts +32 -0
- package/dist/server/auth/discovery.js +56 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +44 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +40 -0
- package/dist/server/auth/providers/auth0.js +31 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.js +50 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.js +140 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +51 -0
- package/dist/server/auth/providers/clerk.js +19 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.js +30 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +40 -0
- package/dist/server/auth/providers/custom.js +56 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.js +158 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +44 -0
- package/dist/server/auth/providers/descope.js +44 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.js +62 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +25 -0
- package/dist/server/auth/providers/stytch.js +16 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +33 -0
- package/dist/server/auth/providers/workos.js +15 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +6 -0
- package/dist/server/auth/setup.js +92 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.js +508 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +46 -0
- package/dist/server/auth/verify.js +62 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.js +149 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth-extra.test-d.js +82 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +58 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.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.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.d.ts +1 -0
- package/dist/server/express.test.js +491 -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/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.d.ts +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +16 -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 +162 -0
- package/dist/server/middleware.js +126 -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 +529 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +465 -0
- package/dist/server/server.js +742 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +79 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +29 -0
- package/dist/server/skills.js +195 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +247 -0
- package/dist/server/skills.test.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.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/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +171 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +48 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/{src/test → test}/utils.d.ts +16 -24
- package/dist/{src/test → test}/utils.js +42 -37
- package/dist/test/utils.js.map +1 -0
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +552 -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/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +327 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +225 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +15 -0
- package/dist/web/bridges/apps-sdk/bridge.js +58 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +4 -0
- package/dist/web/bridges/apps-sdk/index.js +4 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/web/bridges/apps-sdk/types.d.ts +133 -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 +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 +10 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.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/bridge.d.ts +39 -0
- package/dist/web/bridges/mcp-app/bridge.js +168 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +3 -0
- package/dist/web/bridges/mcp-app/index.js +3 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +10 -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 +143 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +214 -0
- package/dist/web/bridges/types.js +15 -0
- package/dist/web/bridges/types.js.map +1 -0
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.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 +46 -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 +132 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/web/data-llm.d.ts +47 -0
- package/dist/{src/web → web}/data-llm.js +39 -7
- 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 +155 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +24 -19
- package/dist/{src/web → web}/generate-helpers.js +22 -18
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +32 -27
- 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.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/web/helpers/state.test.d.ts +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/web/hooks/index.d.ts +16 -0
- package/dist/{src/web → web}/hooks/index.js +7 -2
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +21 -0
- package/dist/web/hooks/test/utils.js +75 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +47 -1
- 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.map +1 -0
- package/dist/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +84 -24
- 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 +77 -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 +103 -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 +62 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-host-info.d.ts +22 -0
- package/dist/web/hooks/use-host-info.js +30 -0
- package/dist/web/hooks/use-host-info.js.map +1 -0
- package/dist/web/hooks/use-host-info.test.d.ts +1 -0
- package/dist/web/hooks/use-host-info.test.js +59 -0
- package/dist/web/hooks/use-host-info.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-layout.d.ts +4 -2
- package/dist/{src/web → web}/hooks/use-layout.js +6 -4
- 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 +129 -0
- package/dist/web/hooks/use-layout.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 +75 -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 +47 -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/{src/web → web}/hooks/use-request-modal.test.js +15 -1
- 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 +47 -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 +63 -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/{src/web → web}/hooks/use-tool-info.test-d.js +24 -6
- 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 +140 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-user.d.ts +3 -1
- 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 +168 -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 +42 -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 +212 -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 +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.map +1 -0
- package/dist/web/plugin/plugin-build.test.d.ts +1 -0
- package/dist/web/plugin/plugin-build.test.js +54 -0
- package/dist/web/plugin/plugin-build.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +39 -0
- package/dist/web/plugin/plugin.js +200 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/web/plugin/plugin.test.d.ts +1 -0
- package/dist/web/plugin/plugin.test.js +61 -0
- package/dist/web/plugin/plugin.test.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 +7 -4
- 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 +20 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +83 -40
- 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 -39
- 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/apps-sdk-adapter.d.ts +0 -2
- package/dist/src/web/bridges/apps-sdk-adapter.js +0 -4
- package/dist/src/web/bridges/apps-sdk-adapter.js.map +0 -1
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -8
- package/dist/src/web/bridges/apps-sdk-bridge.js +0 -41
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/get-bridge-methods.d.ts +0 -2
- package/dist/src/web/bridges/get-bridge-methods.js +0 -8
- package/dist/src/web/bridges/get-bridge-methods.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 +0 -7
- 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 -90
- 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 -4
- 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 -58
- 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-adapter.d.ts +0 -2
- package/dist/src/web/bridges/mcp-app-adapter.js +0 -12
- package/dist/src/web/bridges/mcp-app-adapter.js.map +0 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -30
- package/dist/src/web/bridges/mcp-app-bridge.js +0 -139
- package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/types.d.ts +0 -32
- package/dist/src/web/bridges/types.js.map +0 -1
- package/dist/src/web/create-store.d.ts +0 -3
- 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.d.ts +0 -14
- 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.d.ts +0 -11
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js +0 -60
- 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 +0 -41
- 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 +0 -46
- 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 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -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.d.ts +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +0 -25
- package/dist/src/web/hooks/use-tool-info.js +0 -20
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -60
- 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 +0 -44
- 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 +0 -19
- 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 -151
- 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/build-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{src/web/create-store.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{src/web/bridges → cli}/types.js +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{src/web/helpers/state.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/auth/discovery.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → server/auth/providers/auth0.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-layout.test.d.ts → server/auth/providers/clerk.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → server/auth/providers/custom.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → server/auth/providers/descope.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → server/auth/providers/shared.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user.test.d.ts → server/auth/setup.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → server/auth/verify.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/auth-extra.test-d.d.ts} +0 -0
- /package/dist/{src/web/plugin/data-llm.test.d.ts → server/build-manifest.test.d.ts} +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → server/content-helpers.test.d.ts} +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
- /package/dist/{src/web → web}/hooks/use-call-tool.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,46 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import { createElement, StrictMode } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { installOpenAILoggingProxy } from "./proxy.js";
|
|
5
|
+
let rootInstance = null;
|
|
6
|
+
/**
|
|
7
|
+
* Mount a view's root React component into `#root`. Each view file's entry
|
|
8
|
+
* point should call this exactly once.
|
|
9
|
+
*
|
|
10
|
+
* Wraps the component in `StrictMode`, applies host-specific providers
|
|
11
|
+
* automatically (e.g. modal support for MCP Apps), and installs the dev-mode
|
|
12
|
+
* logging proxy for `window.openai` calls.
|
|
13
|
+
*
|
|
14
|
+
* @param component - Your root React element (already constructed, e.g. `<App />`).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* // src/views/search.tsx
|
|
19
|
+
* import { mountView } from "skybridge/web";
|
|
20
|
+
* import { App } from "./App";
|
|
21
|
+
*
|
|
22
|
+
* mountView(<App />);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const mountView = (component) => {
|
|
26
|
+
const rootElement = document.getElementById("root");
|
|
27
|
+
if (!rootElement) {
|
|
28
|
+
throw new Error("Root element not found");
|
|
29
|
+
}
|
|
30
|
+
if (!rootInstance) {
|
|
31
|
+
rootInstance = createRoot(rootElement);
|
|
32
|
+
}
|
|
33
|
+
if (import.meta.env.DEV) {
|
|
34
|
+
installOpenAILoggingProxy();
|
|
35
|
+
}
|
|
36
|
+
const hostType = window.skybridge?.hostType;
|
|
37
|
+
(async () => {
|
|
38
|
+
let app = component;
|
|
39
|
+
if (hostType === "mcp-app") {
|
|
40
|
+
const { ModalProvider } = await import("./components/modal-provider.js");
|
|
41
|
+
app = createElement(ModalProvider, null, component);
|
|
42
|
+
}
|
|
43
|
+
rootInstance.render(createElement(StrictMode, null, app));
|
|
44
|
+
})();
|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AC,CAAC,CAAC;IAC5D,CAAC,CAAC,EAAE,CAAC;AACP,CAAC,CAAC","sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { createElement, StrictMode } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { installOpenAILoggingProxy } from \"./proxy.js\";\n\nlet rootInstance: Root | null = null;\n\n/**\n * Mount a view's root React component into `#root`. Each view file's entry\n * point should call this exactly once.\n *\n * Wraps the component in `StrictMode`, applies host-specific providers\n * automatically (e.g. modal support for MCP Apps), and installs the dev-mode\n * logging proxy for `window.openai` calls.\n *\n * @param component - Your root React element (already constructed, e.g. `<App />`).\n *\n * @example\n * ```tsx\n * // src/views/search.tsx\n * import { mountView } from \"skybridge/web\";\n * import { App } from \"./App\";\n *\n * mountView(<App />);\n * ```\n */\nexport const mountView = (component: React.ReactNode) => {\n const rootElement = document.getElementById(\"root\");\n if (!rootElement) {\n throw new Error(\"Root element not found\");\n }\n\n if (!rootInstance) {\n rootInstance = createRoot(rootElement);\n }\n\n if (import.meta.env.DEV) {\n installOpenAILoggingProxy();\n }\n\n const hostType = window.skybridge?.hostType;\n\n (async () => {\n let app = component;\n if (hostType === \"mcp-app\") {\n const { ModalProvider } = await import(\"./components/modal-provider.js\");\n app = createElement(ModalProvider, null, component);\n }\n rootInstance.render(createElement(StrictMode, null, app));\n })();\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../../src/web/plugin/data-llm.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,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,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACvD,sBAAsB;QACtB,MAAM,cAAc,GAAG;;;;;KAKtB,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAC5D,MAAM,CACJ,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAC9D,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAElB,iDAAiD;QACjD,MAAM,cAAc,GAAG;;;;;;KAMtB,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;QAC7D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,kCAAkC,CAAC,CAAC;QACpE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,IAAI,GAAG;;;;;;;;;;;;;KAaZ,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { transform } from \"./transform-data-llm.js\";\n\ndescribe(\"data-llm plugin\", () => {\n it(\"should transform JSX element with data-llm string attribute\", async () => {\n const code = `\n function Component() {\n return <div data-llm=\"Test description\">Content</div>;\n }\n `;\n\n const result = await transform(code, \"test.tsx\");\n\n expect(result).not.toBeNull();\n expect(result?.code).toContain(\"DataLLM\");\n expect(result?.code).toContain('content=\"Test description\"');\n expect(result?.code).not.toContain(\"data-llm\");\n });\n\n it(\"should transform JSX element with data-llm expression attribute\", async () => {\n const code = `\n function Component() {\n const desc = \"Dynamic description\";\n return <div data-llm={desc}>Content</div>;\n }\n `;\n\n const result = await transform(code, \"test.tsx\");\n\n expect(result).not.toBeNull();\n expect(result?.code).toContain(\"DataLLM\");\n expect(result?.code).toContain(\"content={desc}\");\n expect(result?.code).not.toContain(\"data-llm\");\n });\n\n it(\"should add import for DataLLM when not present\", async () => {\n const code = `\n function Component() {\n return <div data-llm=\"Test\">Content</div>;\n }\n `;\n\n const result = await transform(code, \"test.tsx\");\n\n expect(result).not.toBeNull();\n expect(result?.code).toContain('import { DataLLM } from \"skybridge/web\"');\n });\n\n it(\"should handle DataLLM imports correctly\", async () => {\n // No duplicate import\n const codeWithImport = `\n import { DataLLM } from \"skybridge/web\";\n function Component() {\n return <div data-llm=\"Test\">Content</div>;\n }\n `;\n const result1 = await transform(codeWithImport, \"test.tsx\");\n expect(\n result1?.code.match(/import.*DataLLM.*from.*skybridge\\/web/g),\n ).toHaveLength(1);\n\n // Preserve other imports and add missing DataLLM\n const codeWithOthers = `\n import React from \"react\";\n import { useState } from \"react\";\n function Component() {\n return <div data-llm=\"Test\">Content</div>;\n }\n `;\n const result2 = await transform(codeWithOthers, \"test.tsx\");\n expect(result2?.code).toContain('import React from \"react\"');\n expect(result2?.code).toContain('import { useState } from \"react\"');\n expect(result2?.code).toContain('import { DataLLM } from \"skybridge/web\"');\n });\n\n it(\"should handle complex JSX with multiple data-llm attributes\", async () => {\n const code = `\n function Component() {\n return (\n <div>\n <section data-llm=\"Section 1\">\n <p>Content 1</p>\n </section>\n <section data-llm=\"Section 2\">\n <p>Content 2</p>\n </section>\n </div>\n );\n }\n `;\n\n const result = await transform(code, \"test.tsx\");\n\n expect(result).toMatchSnapshot();\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { build } from "vite";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
7
|
+
import { skybridge } from "./plugin.js";
|
|
8
|
+
/**
|
|
9
|
+
* Full `vite build` over a fixture whose stylesheet contains a `url()`. The
|
|
10
|
+
* unit test pins the `renderBuiltUrl` contract; this one proves Vite actually
|
|
11
|
+
* accepts what the plugin returns.
|
|
12
|
+
*/
|
|
13
|
+
describe("skybridge plugin build", () => {
|
|
14
|
+
let root;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
root = mkdtempSync(join(tmpdir(), "skybridge-build-"));
|
|
17
|
+
mkdirSync(join(root, "views"), { recursive: true });
|
|
18
|
+
mkdirSync(join(root, "src"), { recursive: true });
|
|
19
|
+
writeFileSync(join(root, "src/demo.woff2"), Buffer.alloc(64, 1));
|
|
20
|
+
writeFileSync(join(root, "src/styles.css"), [
|
|
21
|
+
"@font-face {",
|
|
22
|
+
' font-family: "Demo";',
|
|
23
|
+
' src: url("./demo.woff2") format("woff2");',
|
|
24
|
+
"}",
|
|
25
|
+
].join("\n"));
|
|
26
|
+
writeFileSync(join(root, "src/entry.js"), `import "./styles.css";\n`);
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
rmSync(root, { recursive: true, force: true });
|
|
30
|
+
});
|
|
31
|
+
it("builds a view stylesheet that references a font", async () => {
|
|
32
|
+
const result = await build({
|
|
33
|
+
root,
|
|
34
|
+
logLevel: "silent",
|
|
35
|
+
plugins: [skybridge({ viewsDir: join(root, "views") })],
|
|
36
|
+
build: {
|
|
37
|
+
// Force the font to be emitted as a file rather than inlined, so the
|
|
38
|
+
// stylesheet actually carries a `url()`.
|
|
39
|
+
assetsInlineLimit: 0,
|
|
40
|
+
rollupOptions: { input: { entry: join(root, "src/entry.js") } },
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const outputs = (Array.isArray(result) ? result : [result]).flatMap((bundle) => ("output" in bundle ? bundle.output : []));
|
|
44
|
+
const css = outputs.find((chunk) => chunk.type === "asset" && chunk.fileName.endsWith(".css"));
|
|
45
|
+
if (css?.type !== "asset") {
|
|
46
|
+
throw new Error("no CSS asset was emitted");
|
|
47
|
+
}
|
|
48
|
+
// The font resolves relative to the stylesheet, which the server hands out
|
|
49
|
+
// from `${serverUrl}/assets/` — no runtime expression, which CSS can't run.
|
|
50
|
+
expect(String(css.source)).toMatch(/url\(\.\/demo-[\w-]+\.woff2\)/);
|
|
51
|
+
expect(String(css.source)).not.toContain("window.skybridge");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=plugin-build.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-build.test.js","sourceRoot":"","sources":["../../../src/web/plugin/plugin-build.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AACH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,IAAI,IAAY,CAAC;IAEjB,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,GAA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;aAChE;SACF,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CACjE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CACtD,CAAC;QACF,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CACtB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CACrE,CAAC;QACF,IAAI,GAAG,EAAE,IAAI,KAAK,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,2EAA2E;QAC3E,4EAA4E;QAC5E,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;QACpE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport { mkdirSync, mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { build } from \"vite\";\nimport { afterEach, beforeEach, describe, expect, it } from \"vitest\";\nimport { skybridge } from \"./plugin.js\";\n\n/**\n * Full `vite build` over a fixture whose stylesheet contains a `url()`. The\n * unit test pins the `renderBuiltUrl` contract; this one proves Vite actually\n * accepts what the plugin returns.\n */\ndescribe(\"skybridge plugin build\", () => {\n let root: string;\n\n beforeEach(() => {\n root = mkdtempSync(join(tmpdir(), \"skybridge-build-\"));\n mkdirSync(join(root, \"views\"), { recursive: true });\n mkdirSync(join(root, \"src\"), { recursive: true });\n\n writeFileSync(join(root, \"src/demo.woff2\"), Buffer.alloc(64, 1));\n writeFileSync(\n join(root, \"src/styles.css\"),\n [\n \"@font-face {\",\n ' font-family: \"Demo\";',\n ' src: url(\"./demo.woff2\") format(\"woff2\");',\n \"}\",\n ].join(\"\\n\"),\n );\n writeFileSync(join(root, \"src/entry.js\"), `import \"./styles.css\";\\n`);\n });\n\n afterEach(() => {\n rmSync(root, { recursive: true, force: true });\n });\n\n it(\"builds a view stylesheet that references a font\", async () => {\n const result = await build({\n root,\n logLevel: \"silent\",\n plugins: [skybridge({ viewsDir: join(root, \"views\") })],\n build: {\n // Force the font to be emitted as a file rather than inlined, so the\n // stylesheet actually carries a `url()`.\n assetsInlineLimit: 0,\n rollupOptions: { input: { entry: join(root, \"src/entry.js\") } },\n },\n });\n\n const outputs = (Array.isArray(result) ? result : [result]).flatMap(\n (bundle) => (\"output\" in bundle ? bundle.output : []),\n );\n const css = outputs.find(\n (chunk) => chunk.type === \"asset\" && chunk.fileName.endsWith(\".css\"),\n );\n if (css?.type !== \"asset\") {\n throw new Error(\"no CSS asset was emitted\");\n }\n\n // The font resolves relative to the stylesheet, which the server hands out\n // from `${serverUrl}/assets/` — no runtime expression, which CSS can't run.\n expect(String(css.source)).toMatch(/url\\(\\.\\/demo-[\\w-]+\\.woff2\\)/);\n expect(String(css.source)).not.toContain(\"window.skybridge\");\n });\n});\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
/** Options for the {@link skybridge} Vite plugin. */
|
|
3
|
+
export interface SkybridgePluginOptions {
|
|
4
|
+
/** Directory scanned for view modules. Defaults to `"src/views"`. */
|
|
5
|
+
viewsDir?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Package names to leave unbundled when `skybridge build` bundles the server
|
|
8
|
+
* for deployment. Use it for dependencies esbuild can't resolve or load —
|
|
9
|
+
* typically optional native modules pulled in by a transitive dependency.
|
|
10
|
+
*/
|
|
11
|
+
serverExternal?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Vite plugin that wires a Skybridge project's view files into Vite.
|
|
15
|
+
*
|
|
16
|
+
* For each `.tsx` / `.jsx` file in `viewsDir` with a default export, the
|
|
17
|
+
* plugin:
|
|
18
|
+
* - exposes a virtual entry that calls {@link mountView} with the view's
|
|
19
|
+
* default export,
|
|
20
|
+
* - generates `.skybridge/views.d.ts` to augment {@link ViewNameRegistry} so
|
|
21
|
+
* {@link ViewName} narrows to the actual view names,
|
|
22
|
+
* - rewrites `<DataLLM>` JSX so the host can extract its content,
|
|
23
|
+
* - warns in dev if a view file is missing a default export.
|
|
24
|
+
*
|
|
25
|
+
* Add it to your `vite.config.ts` alongside `@vitejs/plugin-react`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // vite.config.ts
|
|
30
|
+
* import { defineConfig } from "vite";
|
|
31
|
+
* import react from "@vitejs/plugin-react";
|
|
32
|
+
* import { skybridge } from "skybridge/vite";
|
|
33
|
+
*
|
|
34
|
+
* export default defineConfig({
|
|
35
|
+
* plugins: [react(), skybridge({ viewsDir: "src/views" })],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function skybridge(options?: SkybridgePluginOptions): Plugin;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
2
|
+
import { assertUniqueViewNames, discoverViewsSync, scanViewsSync, writeViewsDts, } from "./scan-views.js";
|
|
3
|
+
import { transform as dataLlmTransform } from "./transform-data-llm.js";
|
|
4
|
+
import { hasDefaultExport } from "./validate-view.js";
|
|
5
|
+
const VIRTUAL_PREFIX = "/_skybridge/view/";
|
|
6
|
+
const VIRTUAL_MODULE_PREFIX = "\0skybridge:view:";
|
|
7
|
+
function buildVirtualEntry(viewFilePath) {
|
|
8
|
+
const normalized = viewFilePath.replace(/\\/g, "/");
|
|
9
|
+
return [
|
|
10
|
+
`import { mountView } from "skybridge/web";`,
|
|
11
|
+
`import Component from "${normalized}";`,
|
|
12
|
+
`import { createElement } from "react";`,
|
|
13
|
+
`mountView(createElement(Component));`,
|
|
14
|
+
].join("\n");
|
|
15
|
+
}
|
|
16
|
+
function getViewEntryPattern(viewsDir) {
|
|
17
|
+
const escaped = viewsDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
return new RegExp(`${escaped}\\/(?:[^/]+\\.(?:jsx|tsx)|[^/]+\\/index\\.(?:tsx|jsx))(?:\\?.*)?$`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Vite plugin that wires a Skybridge project's view files into Vite.
|
|
22
|
+
*
|
|
23
|
+
* For each `.tsx` / `.jsx` file in `viewsDir` with a default export, the
|
|
24
|
+
* plugin:
|
|
25
|
+
* - exposes a virtual entry that calls {@link mountView} with the view's
|
|
26
|
+
* default export,
|
|
27
|
+
* - generates `.skybridge/views.d.ts` to augment {@link ViewNameRegistry} so
|
|
28
|
+
* {@link ViewName} narrows to the actual view names,
|
|
29
|
+
* - rewrites `<DataLLM>` JSX so the host can extract its content,
|
|
30
|
+
* - warns in dev if a view file is missing a default export.
|
|
31
|
+
*
|
|
32
|
+
* Add it to your `vite.config.ts` alongside `@vitejs/plugin-react`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // vite.config.ts
|
|
37
|
+
* import { defineConfig } from "vite";
|
|
38
|
+
* import react from "@vitejs/plugin-react";
|
|
39
|
+
* import { skybridge } from "skybridge/vite";
|
|
40
|
+
*
|
|
41
|
+
* export default defineConfig({
|
|
42
|
+
* plugins: [react(), skybridge({ viewsDir: "src/views" })],
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function skybridge(options) {
|
|
47
|
+
const rawViewsDir = options?.viewsDir ?? "src/views";
|
|
48
|
+
let resolvedViewsDir;
|
|
49
|
+
let projectRoot;
|
|
50
|
+
let viewMap = new Map();
|
|
51
|
+
let viewEntryPattern;
|
|
52
|
+
return {
|
|
53
|
+
name: "skybridge",
|
|
54
|
+
enforce: "pre",
|
|
55
|
+
// Read by `skybridge build` to resolve viewsDir before `tsc -b` runs, and
|
|
56
|
+
// to feed esbuild's external list when bundling the server.
|
|
57
|
+
api: { viewsDir: rawViewsDir, serverExternal: options?.serverExternal },
|
|
58
|
+
config(config) {
|
|
59
|
+
projectRoot = config.root || process.cwd();
|
|
60
|
+
resolvedViewsDir = isAbsolute(rawViewsDir)
|
|
61
|
+
? rawViewsDir
|
|
62
|
+
: resolve(projectRoot, rawViewsDir);
|
|
63
|
+
viewEntryPattern = getViewEntryPattern(resolvedViewsDir);
|
|
64
|
+
const views = discoverViewsSync(resolvedViewsDir);
|
|
65
|
+
viewMap = new Map(views.map((v) => [v.name, v]));
|
|
66
|
+
writeViewsDts(projectRoot, views);
|
|
67
|
+
const input = {};
|
|
68
|
+
for (const view of views) {
|
|
69
|
+
input[view.name] = `${VIRTUAL_PREFIX}${view.name}`;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
base: "/assets",
|
|
73
|
+
// Fixes "Invalid hook call" on createStore by forcing a single
|
|
74
|
+
// copy of React. Under pnpm's isolated node_modules, zustand
|
|
75
|
+
// inside `skybridge` resolves React from skybridge's own
|
|
76
|
+
// dependencies while the host app loads its own copy
|
|
77
|
+
resolve: {
|
|
78
|
+
dedupe: ["react", "react-dom"],
|
|
79
|
+
},
|
|
80
|
+
build: {
|
|
81
|
+
outDir: "dist/assets",
|
|
82
|
+
emptyOutDir: true,
|
|
83
|
+
manifest: true,
|
|
84
|
+
minify: true,
|
|
85
|
+
cssCodeSplit: false,
|
|
86
|
+
rollupOptions: {
|
|
87
|
+
input,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
// Pre-bundle view deps at startup so the first tool invocation
|
|
91
|
+
// doesn't hit Vite's on-demand re-optimization path (which sends
|
|
92
|
+
// `full-reload` over HMR — in our iframe flow the parent host
|
|
93
|
+
// can't honour a reload, and the view silently never mounts).
|
|
94
|
+
optimizeDeps: {
|
|
95
|
+
// Scan view files so transitive user deps (zod, tailwind, etc.)
|
|
96
|
+
// get pre-bundled at startup.
|
|
97
|
+
entries: [
|
|
98
|
+
`${resolvedViewsDir}/*.{tsx,jsx}`,
|
|
99
|
+
`${resolvedViewsDir}/*/index.{tsx,jsx}`,
|
|
100
|
+
],
|
|
101
|
+
include: ["react", "react-dom/client", "react/jsx-runtime"],
|
|
102
|
+
},
|
|
103
|
+
experimental: {
|
|
104
|
+
renderBuiltUrl: (filename, { hostType }) => {
|
|
105
|
+
// Views render inside a host sandbox iframe, so `import.meta.url`
|
|
106
|
+
// points at the sandbox domain rather than the Skybridge server.
|
|
107
|
+
// JS asset references have to be resolved at runtime against
|
|
108
|
+
// `window.skybridge.serverUrl` so they follow tunnels too.
|
|
109
|
+
if (hostType === "js") {
|
|
110
|
+
return {
|
|
111
|
+
runtime: `window.skybridge.serverUrl + "/assets/${filename}"`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// CSS has nowhere to evaluate a runtime expression — `vite:css-post`
|
|
115
|
+
// throws on one. It doesn't need it either: the stylesheet is served
|
|
116
|
+
// from `${serverUrl}/assets/…` and a relative `url()` resolves
|
|
117
|
+
// against the stylesheet's own URL, tunnel origin included.
|
|
118
|
+
return { relative: true };
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
resolveId(id) {
|
|
124
|
+
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
125
|
+
const name = id.slice(VIRTUAL_PREFIX.length);
|
|
126
|
+
if (viewMap.has(name)) {
|
|
127
|
+
return `${VIRTUAL_MODULE_PREFIX}${name}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
},
|
|
132
|
+
load(id) {
|
|
133
|
+
if (id.startsWith(VIRTUAL_MODULE_PREFIX)) {
|
|
134
|
+
const name = id.slice(VIRTUAL_MODULE_PREFIX.length);
|
|
135
|
+
const view = viewMap.get(name);
|
|
136
|
+
if (view) {
|
|
137
|
+
return buildVirtualEntry(view.filePath);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
},
|
|
142
|
+
configureServer(server) {
|
|
143
|
+
if (!resolvedViewsDir) {
|
|
144
|
+
const root = server.config.root || process.cwd();
|
|
145
|
+
resolvedViewsDir = isAbsolute(rawViewsDir)
|
|
146
|
+
? rawViewsDir
|
|
147
|
+
: resolve(root, rawViewsDir);
|
|
148
|
+
projectRoot = root;
|
|
149
|
+
viewEntryPattern = getViewEntryPattern(resolvedViewsDir);
|
|
150
|
+
}
|
|
151
|
+
server.watcher.add(resolvedViewsDir);
|
|
152
|
+
// Track which view files we've already warned about so a rescan
|
|
153
|
+
// triggered by an unrelated edit doesn't re-emit the same warning.
|
|
154
|
+
let knownInvalid = new Set();
|
|
155
|
+
const rescan = () => {
|
|
156
|
+
try {
|
|
157
|
+
// Surface broken view files. Without this, files lacking a
|
|
158
|
+
// default export are silently dropped from the input and the
|
|
159
|
+
// user has no idea why their widget never mounts.
|
|
160
|
+
const { valid, invalid } = scanViewsSync(resolvedViewsDir);
|
|
161
|
+
const nextInvalid = new Set(invalid.map((v) => v.filePath));
|
|
162
|
+
for (const filePath of nextInvalid) {
|
|
163
|
+
if (!knownInvalid.has(filePath)) {
|
|
164
|
+
server.config.logger.warn(`[skybridge] view file "${relative(projectRoot, filePath)}" is missing a default export — it won't be served until fixed.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const filePath of knownInvalid) {
|
|
168
|
+
if (!nextInvalid.has(filePath)) {
|
|
169
|
+
server.config.logger.info(`[skybridge] view file "${relative(projectRoot, filePath)}" resolved.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
knownInvalid = nextInvalid;
|
|
173
|
+
assertUniqueViewNames(valid);
|
|
174
|
+
viewMap = new Map(valid.map((v) => [v.name, v]));
|
|
175
|
+
writeViewsDts(projectRoot, valid);
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
// assertUniqueViewNames throws on duplicate view names. Catch so
|
|
179
|
+
// chokidar's listener chain doesn't surface it as unhandled and
|
|
180
|
+
// crash the dev server — previous viewMap stays active until
|
|
181
|
+
// the user fixes the conflict.
|
|
182
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
183
|
+
server.config.logger.error(`[skybridge] view rescan failed: ${message}`);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
// Initial scan emits warnings for broken files that exist at startup.
|
|
187
|
+
rescan();
|
|
188
|
+
server.watcher.on("add", rescan);
|
|
189
|
+
server.watcher.on("change", rescan);
|
|
190
|
+
server.watcher.on("unlink", rescan);
|
|
191
|
+
},
|
|
192
|
+
async transform(code, id) {
|
|
193
|
+
if (viewEntryPattern?.test(id) && !hasDefaultExport(code, id)) {
|
|
194
|
+
this.warn(`View file "${id.split("/").pop()}" is missing a default export.`);
|
|
195
|
+
}
|
|
196
|
+
return await dataLlmTransform(code, id);
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EACL,qBAAqB,EAErB,iBAAiB,EACjB,aAAa,EACb,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACxE,O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,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { isAbsolute, relative, resolve } from \"node:path\";\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport {\n assertUniqueViewNames,\n type DiscoveredView,\n discoverViewsSync,\n scanViewsSync,\n writeViewsDts,\n} from \"./scan-views.js\";\nimport { transform as dataLlmTransform } from \"./transform-data-llm.js\";\nimport { hasDefaultExport } from \"./validate-view.js\";\n\nconst VIRTUAL_PREFIX = \"/_skybridge/view/\";\nconst VIRTUAL_MODULE_PREFIX = \"\\0skybridge:view:\";\n\n/** Options for the {@link skybridge} Vite plugin. */\nexport interface SkybridgePluginOptions {\n /** Directory scanned for view modules. Defaults to `\"src/views\"`. */\n viewsDir?: string;\n /**\n * Package names to leave unbundled when `skybridge build` bundles the server\n * for deployment. Use it for dependencies esbuild can't resolve or load —\n * typically optional native modules pulled in by a transitive dependency.\n */\n serverExternal?: string[];\n}\n\nfunction buildVirtualEntry(viewFilePath: string): string {\n const normalized = viewFilePath.replace(/\\\\/g, \"/\");\n return [\n `import { mountView } from \"skybridge/web\";`,\n `import Component from \"${normalized}\";`,\n `import { createElement } from \"react\";`,\n `mountView(createElement(Component));`,\n ].join(\"\\n\");\n}\n\nfunction getViewEntryPattern(viewsDir: string): RegExp {\n const escaped = viewsDir.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n return new RegExp(\n `${escaped}\\\\/(?:[^/]+\\\\.(?:jsx|tsx)|[^/]+\\\\/index\\\\.(?:tsx|jsx))(?:\\\\?.*)?$`,\n );\n}\n\n/**\n * Vite plugin that wires a Skybridge project's view files into Vite.\n *\n * For each `.tsx` / `.jsx` file in `viewsDir` with a default export, the\n * plugin:\n * - exposes a virtual entry that calls {@link mountView} with the view's\n * default export,\n * - generates `.skybridge/views.d.ts` to augment {@link ViewNameRegistry} so\n * {@link ViewName} narrows to the actual view names,\n * - rewrites `<DataLLM>` JSX so the host can extract its content,\n * - warns in dev if a view file is missing a default export.\n *\n * Add it to your `vite.config.ts` alongside `@vitejs/plugin-react`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import react from \"@vitejs/plugin-react\";\n * import { skybridge } from \"skybridge/vite\";\n *\n * export default defineConfig({\n * plugins: [react(), skybridge({ viewsDir: \"src/views\" })],\n * });\n * ```\n */\nexport function skybridge(options?: SkybridgePluginOptions): Plugin {\n const rawViewsDir = options?.viewsDir ?? \"src/views\";\n let resolvedViewsDir: string;\n let projectRoot: string;\n let viewMap = new Map<string, DiscoveredView>();\n let viewEntryPattern: RegExp;\n\n return {\n name: \"skybridge\",\n enforce: \"pre\",\n // Read by `skybridge build` to resolve viewsDir before `tsc -b` runs, and\n // to feed esbuild's external list when bundling the server.\n api: { viewsDir: rawViewsDir, serverExternal: options?.serverExternal },\n\n config(config) {\n projectRoot = config.root || process.cwd();\n resolvedViewsDir = isAbsolute(rawViewsDir)\n ? rawViewsDir\n : resolve(projectRoot, rawViewsDir);\n viewEntryPattern = getViewEntryPattern(resolvedViewsDir);\n\n const views = discoverViewsSync(resolvedViewsDir);\n viewMap = new Map(views.map((v) => [v.name, v]));\n writeViewsDts(projectRoot, views);\n\n const input: Record<string, string> = {};\n for (const view of views) {\n input[view.name] = `${VIRTUAL_PREFIX}${view.name}`;\n }\n\n return {\n base: \"/assets\",\n // Fixes \"Invalid hook call\" on createStore by forcing a single\n // copy of React. Under pnpm's isolated node_modules, zustand\n // inside `skybridge` resolves React from skybridge's own\n // dependencies while the host app loads its own copy\n resolve: {\n dedupe: [\"react\", \"react-dom\"],\n },\n build: {\n outDir: \"dist/assets\",\n emptyOutDir: true,\n manifest: true,\n minify: true,\n cssCodeSplit: false,\n rollupOptions: {\n input,\n },\n },\n // Pre-bundle view deps at startup so the first tool invocation\n // doesn't hit Vite's on-demand re-optimization path (which sends\n // `full-reload` over HMR — in our iframe flow the parent host\n // can't honour a reload, and the view silently never mounts).\n optimizeDeps: {\n // Scan view files so transitive user deps (zod, tailwind, etc.)\n // get pre-bundled at startup.\n entries: [\n `${resolvedViewsDir}/*.{tsx,jsx}`,\n `${resolvedViewsDir}/*/index.{tsx,jsx}`,\n ],\n include: [\"react\", \"react-dom/client\", \"react/jsx-runtime\"],\n },\n experimental: {\n renderBuiltUrl: (filename, { hostType }) => {\n // Views render inside a host sandbox iframe, so `import.meta.url`\n // points at the sandbox domain rather than the Skybridge server.\n // JS asset references have to be resolved at runtime against\n // `window.skybridge.serverUrl` so they follow tunnels too.\n if (hostType === \"js\") {\n return {\n runtime: `window.skybridge.serverUrl + \"/assets/${filename}\"`,\n };\n }\n // CSS has nowhere to evaluate a runtime expression — `vite:css-post`\n // throws on one. It doesn't need it either: the stylesheet is served\n // from `${serverUrl}/assets/…` and a relative `url()` resolves\n // against the stylesheet's own URL, tunnel origin included.\n return { relative: true };\n },\n },\n };\n },\n\n resolveId(id) {\n if (id.startsWith(VIRTUAL_PREFIX)) {\n const name = id.slice(VIRTUAL_PREFIX.length);\n if (viewMap.has(name)) {\n return `${VIRTUAL_MODULE_PREFIX}${name}`;\n }\n }\n return null;\n },\n\n load(id) {\n if (id.startsWith(VIRTUAL_MODULE_PREFIX)) {\n const name = id.slice(VIRTUAL_MODULE_PREFIX.length);\n const view = viewMap.get(name);\n if (view) {\n return buildVirtualEntry(view.filePath);\n }\n }\n return null;\n },\n\n configureServer(server: ViteDevServer) {\n if (!resolvedViewsDir) {\n const root = server.config.root || process.cwd();\n resolvedViewsDir = isAbsolute(rawViewsDir)\n ? rawViewsDir\n : resolve(root, rawViewsDir);\n projectRoot = root;\n viewEntryPattern = getViewEntryPattern(resolvedViewsDir);\n }\n\n server.watcher.add(resolvedViewsDir);\n // Track which view files we've already warned about so a rescan\n // triggered by an unrelated edit doesn't re-emit the same warning.\n let knownInvalid = new Set<string>();\n const rescan = () => {\n try {\n // Surface broken view files. Without this, files lacking a\n // default export are silently dropped from the input and the\n // user has no idea why their widget never mounts.\n const { valid, invalid } = scanViewsSync(resolvedViewsDir);\n const nextInvalid = new Set(invalid.map((v) => v.filePath));\n\n for (const filePath of nextInvalid) {\n if (!knownInvalid.has(filePath)) {\n server.config.logger.warn(\n `[skybridge] view file \"${relative(projectRoot, filePath)}\" is missing a default export — it won't be served until fixed.`,\n );\n }\n }\n for (const filePath of knownInvalid) {\n if (!nextInvalid.has(filePath)) {\n server.config.logger.info(\n `[skybridge] view file \"${relative(projectRoot, filePath)}\" resolved.`,\n );\n }\n }\n knownInvalid = nextInvalid;\n\n assertUniqueViewNames(valid);\n viewMap = new Map(valid.map((v) => [v.name, v]));\n writeViewsDts(projectRoot, valid);\n } catch (err) {\n // assertUniqueViewNames throws on duplicate view names. Catch so\n // chokidar's listener chain doesn't surface it as unhandled and\n // crash the dev server — previous viewMap stays active until\n // the user fixes the conflict.\n const message = err instanceof Error ? err.message : String(err);\n server.config.logger.error(\n `[skybridge] view rescan failed: ${message}`,\n );\n }\n };\n\n // Initial scan emits warnings for broken files that exist at startup.\n rescan();\n server.watcher.on(\"add\", rescan);\n server.watcher.on(\"change\", rescan);\n server.watcher.on(\"unlink\", rescan);\n },\n\n async transform(code, id) {\n if (viewEntryPattern?.test(id) && !hasDefaultExport(code, id)) {\n this.warn(\n `View file \"${id.split(\"/\").pop()}\" is missing a default export.`,\n );\n }\n\n return await dataLlmTransform(code, id);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { skybridge } from "./plugin.js";
|
|
6
|
+
function getRenderBuiltUrl(root) {
|
|
7
|
+
const plugin = skybridge({ viewsDir: join(root, "views") });
|
|
8
|
+
const hook = plugin.config;
|
|
9
|
+
if (!hook) {
|
|
10
|
+
throw new Error("plugin.config is not defined");
|
|
11
|
+
}
|
|
12
|
+
const handler = typeof hook === "function" ? hook : hook.handler;
|
|
13
|
+
const config = handler.call(
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: vitest harness for plugin hook
|
|
15
|
+
{}, { root }, { command: "build", mode: "production" });
|
|
16
|
+
const renderBuiltUrl = config.experimental?.renderBuiltUrl;
|
|
17
|
+
if (!renderBuiltUrl) {
|
|
18
|
+
throw new Error("experimental.renderBuiltUrl is not defined");
|
|
19
|
+
}
|
|
20
|
+
return renderBuiltUrl;
|
|
21
|
+
}
|
|
22
|
+
describe("skybridge plugin renderBuiltUrl", () => {
|
|
23
|
+
let root;
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
root = mkdtempSync(join(tmpdir(), "skybridge-plugin-"));
|
|
26
|
+
mkdirSync(join(root, "views"), { recursive: true });
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
rmSync(root, { recursive: true, force: true });
|
|
30
|
+
});
|
|
31
|
+
// Assets referenced from JS can't use `import.meta.url`: views render in a
|
|
32
|
+
// host sandbox iframe (web-sandbox.oaiusercontent.com), so the module origin
|
|
33
|
+
// doesn't point back at the Skybridge server. They have to be resolved at
|
|
34
|
+
// runtime against `window.skybridge.serverUrl` instead.
|
|
35
|
+
it("resolves JS asset references against window.skybridge.serverUrl", () => {
|
|
36
|
+
const renderBuiltUrl = getRenderBuiltUrl(root);
|
|
37
|
+
expect(renderBuiltUrl("assets/logo-BXtQ8kd2.png", {
|
|
38
|
+
hostId: "assets/view-CwF9pQ1a.js",
|
|
39
|
+
hostType: "js",
|
|
40
|
+
type: "asset",
|
|
41
|
+
ssr: false,
|
|
42
|
+
})).toEqual({
|
|
43
|
+
runtime: `window.skybridge.serverUrl + "/assets/assets/logo-BXtQ8kd2.png"`,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
// Reproducer for the CSS build failure: Vite has nowhere to evaluate a
|
|
47
|
+
// runtime expression inside a stylesheet, so `{ runtime }` makes
|
|
48
|
+
// `vite:css-post` throw for any `url()` in CSS. It isn't needed either — the
|
|
49
|
+
// stylesheet is served from `${serverUrl}/assets/…`, and a relative `url()`
|
|
50
|
+
// resolves against the stylesheet's own URL, tunnel origin included.
|
|
51
|
+
it("resolves CSS asset references relatively", () => {
|
|
52
|
+
const renderBuiltUrl = getRenderBuiltUrl(root);
|
|
53
|
+
expect(renderBuiltUrl("assets/demo-0IQFxQqs.woff2", {
|
|
54
|
+
hostId: "assets/style-DmQ2xY7b.css",
|
|
55
|
+
hostType: "css",
|
|
56
|
+
type: "asset",
|
|
57
|
+
ssr: false,
|
|
58
|
+
})).toEqual({ relative: true });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=plugin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.test.js","sourceRoot":"","sources":["../../../src/web/plugin/plugin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,UAAU,CAA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AO,EAAE,iEAAiE;SAC3E,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,uEAAuE;IACvE,iEAAiE;IACjE,6EAA6E;IAC7E,4EAA4E;IAC5E,qEAAqE;IACrE,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAE/C,MAAM,CACJ,cAAc,CAAC,4BAA4B,EAAE;YAC3C,MAAM,EAAE,2BAA2B;YACnC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,OAAO;YACb,GAAG,EAAE,KAAK;SACX,CAAC,CACH,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { mkdirSync, mkdtempSync, rmSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { UserConfig } from \"vite\";\nimport { afterEach, beforeEach, describe, expect, it } from \"vitest\";\nimport { skybridge } from \"./plugin.js\";\n\ntype RenderBuiltUrl = NonNullable<\n NonNullable<UserConfig[\"experimental\"]>[\"renderBuiltUrl\"]\n>;\n\nfunction getRenderBuiltUrl(root: string): RenderBuiltUrl {\n const plugin = skybridge({ viewsDir: join(root, \"views\") });\n const hook = plugin.config;\n if (!hook) {\n throw new Error(\"plugin.config is not defined\");\n }\n const handler = typeof hook === \"function\" ? hook : hook.handler;\n const config = handler.call(\n // biome-ignore lint/suspicious/noExplicitAny: vitest harness for plugin hook\n {} as any,\n { root },\n { command: \"build\", mode: \"production\" },\n ) as UserConfig;\n\n const renderBuiltUrl = config.experimental?.renderBuiltUrl;\n if (!renderBuiltUrl) {\n throw new Error(\"experimental.renderBuiltUrl is not defined\");\n }\n return renderBuiltUrl;\n}\n\ndescribe(\"skybridge plugin renderBuiltUrl\", () => {\n let root: string;\n\n beforeEach(() => {\n root = mkdtempSync(join(tmpdir(), \"skybridge-plugin-\"));\n mkdirSync(join(root, \"views\"), { recursive: true });\n });\n\n afterEach(() => {\n rmSync(root, { recursive: true, force: true });\n });\n\n // Assets referenced from JS can't use `import.meta.url`: views render in a\n // host sandbox iframe (web-sandbox.oaiusercontent.com), so the module origin\n // doesn't point back at the Skybridge server. They have to be resolved at\n // runtime against `window.skybridge.serverUrl` instead.\n it(\"resolves JS asset references against window.skybridge.serverUrl\", () => {\n const renderBuiltUrl = getRenderBuiltUrl(root);\n\n expect(\n renderBuiltUrl(\"assets/logo-BXtQ8kd2.png\", {\n hostId: \"assets/view-CwF9pQ1a.js\",\n hostType: \"js\",\n type: \"asset\",\n ssr: false,\n }),\n ).toEqual({\n runtime: `window.skybridge.serverUrl + \"/assets/assets/logo-BXtQ8kd2.png\"`,\n });\n });\n\n // Reproducer for the CSS build failure: Vite has nowhere to evaluate a\n // runtime expression inside a stylesheet, so `{ runtime }` makes\n // `vite:css-post` throw for any `url()` in CSS. It isn't needed either — the\n // stylesheet is served from `${serverUrl}/assets/…`, and a relative `url()`\n // resolves against the stylesheet's own URL, tunnel origin included.\n it(\"resolves CSS asset references relatively\", () => {\n const renderBuiltUrl = getRenderBuiltUrl(root);\n\n expect(\n renderBuiltUrl(\"assets/demo-0IQFxQqs.woff2\", {\n hostId: \"assets/style-DmQ2xY7b.css\",\n hostType: \"css\",\n type: \"asset\",\n ssr: false,\n }),\n ).toEqual({ relative: true });\n });\n});\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface DiscoveredView {
|
|
2
|
+
name: string;
|
|
3
|
+
filePath: string;
|
|
4
|
+
}
|
|
5
|
+
export interface InvalidView {
|
|
6
|
+
filePath: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function scanViewsSync(viewsDir: string): {
|
|
9
|
+
valid: DiscoveredView[];
|
|
10
|
+
invalid: InvalidView[];
|
|
11
|
+
};
|
|
12
|
+
export declare function assertUniqueViewNames(views: DiscoveredView[]): void;
|
|
13
|
+
export declare function discoverViewsSync(viewsDir: string): DiscoveredView[];
|
|
14
|
+
export declare function generateViewsDts(views: DiscoveredView[]): string;
|
|
15
|
+
export declare function writeViewsDts(projectRoot: string, views: DiscoveredView[]): void;
|
|
16
|
+
export declare function scanAndWriteViewsDts(projectRoot?: string, viewsDir?: string): void;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { globSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, parse, resolve } from "node:path";
|
|
3
|
+
import { hasDefaultExport } from "./validate-view.js";
|
|
4
|
+
export function scanViewsSync(viewsDir) {
|
|
5
|
+
const flatPattern = resolve(viewsDir, "*.{tsx,jsx}");
|
|
6
|
+
const dirPattern = resolve(viewsDir, "*/index.{tsx,jsx}");
|
|
7
|
+
const flatFiles = globSync(flatPattern).map((file) => ({
|
|
8
|
+
name: parse(file).name,
|
|
9
|
+
filePath: file,
|
|
10
|
+
}));
|
|
11
|
+
const dirFiles = globSync(dirPattern).map((file) => ({
|
|
12
|
+
name: basename(dirname(file)),
|
|
13
|
+
filePath: file,
|
|
14
|
+
}));
|
|
15
|
+
// A barrel file like `views/foo/index.tsx` (no default export) must not
|
|
16
|
+
// falsely collide with a sibling `views/foo.tsx`. Drop top-level `index`
|
|
17
|
+
// before splitting valid vs invalid.
|
|
18
|
+
const candidates = [...flatFiles, ...dirFiles].filter((v) => v.name !== "index");
|
|
19
|
+
const valid = [];
|
|
20
|
+
const invalid = [];
|
|
21
|
+
for (const candidate of candidates) {
|
|
22
|
+
const code = readFileSync(candidate.filePath, "utf-8");
|
|
23
|
+
if (hasDefaultExport(code, candidate.filePath)) {
|
|
24
|
+
valid.push(candidate);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
invalid.push({
|
|
28
|
+
filePath: candidate.filePath,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { valid, invalid };
|
|
33
|
+
}
|
|
34
|
+
export function assertUniqueViewNames(views) {
|
|
35
|
+
const nameMap = new Map();
|
|
36
|
+
for (const view of views) {
|
|
37
|
+
const paths = nameMap.get(view.name) ?? [];
|
|
38
|
+
paths.push(view.filePath);
|
|
39
|
+
nameMap.set(view.name, paths);
|
|
40
|
+
}
|
|
41
|
+
for (const [name, paths] of nameMap) {
|
|
42
|
+
if (paths.length > 1) {
|
|
43
|
+
throw new Error(`skybridge: duplicate view name "${name}" resolved from:\n - ${paths.join("\n - ")}\nRename one of the files to avoid the conflict.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function discoverViewsSync(viewsDir) {
|
|
48
|
+
const { valid } = scanViewsSync(viewsDir);
|
|
49
|
+
assertUniqueViewNames(valid);
|
|
50
|
+
return valid;
|
|
51
|
+
}
|
|
52
|
+
export function generateViewsDts(views) {
|
|
53
|
+
const entries = views.map((v) => ` "${v.name}": true;`).join("\n");
|
|
54
|
+
return [
|
|
55
|
+
"export {};",
|
|
56
|
+
"",
|
|
57
|
+
'declare module "skybridge/server" {',
|
|
58
|
+
" interface ViewNameRegistry {",
|
|
59
|
+
entries,
|
|
60
|
+
" }",
|
|
61
|
+
"}",
|
|
62
|
+
"",
|
|
63
|
+
].join("\n");
|
|
64
|
+
}
|
|
65
|
+
export function writeViewsDts(projectRoot, views) {
|
|
66
|
+
const dir = join(projectRoot, ".skybridge");
|
|
67
|
+
mkdirSync(dir, { recursive: true });
|
|
68
|
+
const filePath = join(dir, "views.d.ts");
|
|
69
|
+
const content = generateViewsDts(views);
|
|
70
|
+
try {
|
|
71
|
+
const existing = readFileSync(filePath, "utf-8");
|
|
72
|
+
if (existing === content) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// File doesn't exist yet
|
|
78
|
+
}
|
|
79
|
+
writeFileSync(filePath, content, "utf-8");
|
|
80
|
+
}
|
|
81
|
+
export function scanAndWriteViewsDts(projectRoot, viewsDir) {
|
|
82
|
+
const root = projectRoot ?? process.cwd();
|
|
83
|
+
const rawDir = viewsDir ?? "src/views";
|
|
84
|
+
const resolvedDir = isAbsolute(rawDir) ? rawDir : resolve(root, rawDir);
|
|
85
|
+
const views = discoverViewsSync(resolvedDir);
|
|
86
|
+
writeViewsDts(root, views);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=scan-views.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan-views.js","sourceRoot":"","sources":["../../../src/web/plugin/scan-views.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAWtD,MAAM,UAAU,aAAa,CAAC,QAAgB;IAI5C,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IAE1D,MAAM,SAAS,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI;QACtB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC,CAAC;IAEJ,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnD,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC,CAAC;IAEJ,wEAAwE;IACxE,yEAAyE;IAC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AED,MAAM,UAAU,oBAAoB,CAClC,WAAoB,EACpB,QAAiB;IAEjB,MAAM,IAAI,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1C,MAAM,MAAM,GAAG,QAAQ,IAAI,WAAW,CAAC;IACvC,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAExE,MAAM,KAAK,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC7C,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { globSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { basename, dirname, isAbsolute, join, parse, resolve } from \"node:path\";\nimport { hasDefaultExport } from \"./validate-view.js\";\n\nexport interface DiscoveredView {\n name: string;\n filePath: string;\n}\n\nexport interface InvalidView {\n filePath: string;\n}\n\nexport function scanViewsSync(viewsDir: string): {\n valid: DiscoveredView[];\n invalid: InvalidView[];\n} {\n const flatPattern = resolve(viewsDir, \"*.{tsx,jsx}\");\n const dirPattern = resolve(viewsDir, \"*/index.{tsx,jsx}\");\n\n const flatFiles = globSync(flatPattern).map((file) => ({\n name: parse(file).name,\n filePath: file,\n }));\n\n const dirFiles = globSync(dirPattern).map((file) => ({\n name: basename(dirname(file)),\n filePath: file,\n }));\n\n // A barrel file like `views/foo/index.tsx` (no default export) must not\n // falsely collide with a sibling `views/foo.tsx`. Drop top-level `index`\n // before splitting valid vs invalid.\n const candidates = [...flatFiles, ...dirFiles].filter(\n (v) => v.name !== \"index\",\n );\n\n const valid: DiscoveredView[] = [];\n const invalid: InvalidView[] = [];\n for (const candidate of candidates) {\n const code = readFileSync(candidate.filePath, \"utf-8\");\n if (hasDefaultExport(code, candidate.filePath)) {\n valid.push(candidate);\n } else {\n invalid.push({\n filePath: candidate.filePath,\n });\n }\n }\n\n return { valid, invalid };\n}\n\nexport function assertUniqueViewNames(views: DiscoveredView[]): void {\n const nameMap = new Map<string, string[]>();\n for (const view of views) {\n const paths = nameMap.get(view.name) ?? [];\n paths.push(view.filePath);\n nameMap.set(view.name, paths);\n }\n\n for (const [name, paths] of nameMap) {\n if (paths.length > 1) {\n throw new Error(\n `skybridge: duplicate view name \"${name}\" resolved from:\\n - ${paths.join(\"\\n - \")}\\nRename one of the files to avoid the conflict.`,\n );\n }\n }\n}\n\nexport function discoverViewsSync(viewsDir: string): DiscoveredView[] {\n const { valid } = scanViewsSync(viewsDir);\n assertUniqueViewNames(valid);\n return valid;\n}\n\nexport function generateViewsDts(views: DiscoveredView[]): string {\n const entries = views.map((v) => ` \"${v.name}\": true;`).join(\"\\n\");\n return [\n \"export {};\",\n \"\",\n 'declare module \"skybridge/server\" {',\n \" interface ViewNameRegistry {\",\n entries,\n \" }\",\n \"}\",\n \"\",\n ].join(\"\\n\");\n}\n\nexport function writeViewsDts(\n projectRoot: string,\n views: DiscoveredView[],\n): void {\n const dir = join(projectRoot, \".skybridge\");\n mkdirSync(dir, { recursive: true });\n\n const filePath = join(dir, \"views.d.ts\");\n const content = generateViewsDts(views);\n\n try {\n const existing = readFileSync(filePath, \"utf-8\");\n if (existing === content) {\n return;\n }\n } catch {\n // File doesn't exist yet\n }\n\n writeFileSync(filePath, content, \"utf-8\");\n}\n\nexport function scanAndWriteViewsDts(\n projectRoot?: string,\n viewsDir?: string,\n): void {\n const root = projectRoot ?? process.cwd();\n const rawDir = viewsDir ?? \"src/views\";\n const resolvedDir = isAbsolute(rawDir) ? rawDir : resolve(root, rawDir);\n\n const views = discoverViewsSync(resolvedDir);\n writeViewsDts(root, views);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|