skybridge 0.0.0-dev.fc66837 → 0.0.0-dev.fc750de
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/README.md +161 -0
- package/dist/cli/build-helpers.d.ts +7 -0
- package/dist/cli/build-helpers.js +82 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +64 -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/header.js +1 -1
- package/dist/cli/header.js.map +1 -1
- 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.js.map +1 -1
- 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.d.ts +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.d.ts +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 +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +3 -2
- package/dist/cli/use-execute-steps.js +6 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- 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-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +9 -0
- package/dist/cli/use-typescript-check.js +94 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +53 -7
- package/dist/commands/build.js.map +1 -1
- 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 +4 -1
- package/dist/commands/dev.js +78 -13
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +37 -15
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +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/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.d.ts +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 +18 -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 +18 -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.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +48 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +16 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +28 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +24 -0
- package/dist/server/auth/providers/custom.js +37 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +107 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +15 -0
- package/dist/server/auth/providers/descope.js +33 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +37 -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.d.ts +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 +12 -0
- package/dist/server/auth/providers/stytch.js +13 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +12 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +100 -0
- package/dist/server/auth/verify.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/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 +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/index.d.ts +14 -3
- package/dist/server/index.js +11 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.d.ts +6 -6
- package/dist/server/inferUtilityTypes.js.map +1 -1
- 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 +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/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 +371 -59
- package/dist/server/server.js +565 -96
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +5 -7
- package/dist/server/templateHelper.js +3 -22
- package/dist/server/templateHelper.js.map +1 -1
- 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-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +103 -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 +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +13 -21
- package/dist/test/utils.js +42 -37
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +536 -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 +310 -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 +197 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +7 -2
- package/dist/web/bridges/apps-sdk/bridge.js +15 -3
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +1 -2
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +39 -24
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +9 -7
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- 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.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +27 -31
- package/dist/web/bridges/mcp-app/bridge.js +109 -198
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- 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 +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +17 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +14 -2
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -41
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- 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 +146 -13
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- 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 +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- 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 +26 -0
- package/dist/web/create-store.js +43 -3
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +31 -25
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +34 -1
- package/dist/web/data-llm.js +31 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +42 -35
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -18
- package/dist/web/generate-helpers.js +22 -18
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +30 -28
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +11 -11
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +7 -2
- package/dist/web/hooks/index.js +6 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +6 -2
- package/dist/web/hooks/test/utils.js +17 -2
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +62 -27
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +23 -3
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- 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.js +56 -20
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- 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 +35 -2
- package/dist/web/hooks/use-files.js +34 -1
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +35 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.d.ts +2 -0
- package/dist/web/hooks/use-layout.js +2 -0
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +62 -29
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +20 -1
- package/dist/web/hooks/use-open-external.js +17 -1
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +38 -13
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- 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 +18 -3
- package/dist/web/hooks/use-request-modal.js +25 -8
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +15 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- 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 -1
- package/dist/web/hooks/use-send-follow-up-message.js +19 -2
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- 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 +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +43 -33
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +20 -2
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +101 -27
- package/dist/web/hooks/use-user.test.js.map +1 -1
- 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 +181 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -2
- package/dist/web/index.js +1 -2
- package/dist/web/index.js.map +1 -1
- 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.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +32 -1
- package/dist/web/plugin/plugin.js +168 -18
- package/dist/web/plugin/plugin.js.map +1 -1
- 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.js +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
- 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.js +0 -1
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +57 -29
- package/tsconfig.base.json +33 -0
- package/dist/server/templates/development.hbs +0 -66
- package/dist/server/templates/production.hbs +0 -7
- package/dist/server/widgetsDevServer.d.ts +0 -12
- package/dist/server/widgetsDevServer.js +0 -47
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -255
- package/dist/test/widget.test.js.map +0 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -20
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -45
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -31
- package/dist/web/bridges/mcp-app/adaptor.js +0 -157
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- package/dist/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/web/hooks/use-widget-state.js +0 -32
- package/dist/web/hooks/use-widget-state.js.map +0 -1
- package/dist/web/hooks/use-widget-state.test.js +0 -61
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js +0 -19
- package/dist/web/mount-widget.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
import { act,
|
|
1
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { McpAppBridge } from "../bridges/mcp-app/index.js";
|
|
5
5
|
import { fireToolInputNotification, fireToolResultNotification, getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
6
|
import { useToolInfo } from "./use-tool-info.js";
|
|
7
7
|
describe("useToolInfo", () => {
|
|
8
8
|
describe("apps-sdk host", () => {
|
|
9
|
-
let OpenaiMock;
|
|
10
9
|
beforeEach(() => {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
11
|
+
vi.stubGlobal("openai", {
|
|
12
|
+
toolInput: null,
|
|
13
13
|
toolOutput: null,
|
|
14
14
|
toolResponseMetadata: null,
|
|
15
|
-
};
|
|
16
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
15
|
+
});
|
|
17
16
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
17
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
18
18
|
});
|
|
19
19
|
afterEach(() => {
|
|
20
|
+
HostAdaptor.resetInstance();
|
|
20
21
|
vi.unstubAllGlobals();
|
|
21
22
|
vi.resetAllMocks();
|
|
23
|
+
McpAppBridge.resetInstance();
|
|
22
24
|
});
|
|
23
|
-
it("should return
|
|
25
|
+
it("should return pending state with tool input from tool-input notification", async () => {
|
|
24
26
|
const { result } = renderHook(() => useToolInfo());
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
act(() => {
|
|
28
|
+
fireToolInputNotification({
|
|
29
|
+
name: "pokemon",
|
|
30
|
+
args: { name: "pikachu" },
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
await waitFor(() => {
|
|
34
|
+
expect(result.current).toMatchObject({
|
|
35
|
+
input: { name: "pokemon", args: { name: "pikachu" } },
|
|
36
|
+
status: "pending",
|
|
37
|
+
isIdle: false,
|
|
38
|
+
isPending: true,
|
|
39
|
+
isSuccess: false,
|
|
40
|
+
});
|
|
31
41
|
});
|
|
32
42
|
});
|
|
33
|
-
it("should
|
|
43
|
+
it("should return success state once tool-result notification arrives", async () => {
|
|
34
44
|
const toolOutput = {
|
|
35
45
|
name: "pikachu",
|
|
36
46
|
color: "yellow",
|
|
@@ -39,16 +49,15 @@ describe("useToolInfo", () => {
|
|
|
39
49
|
const toolResponseMetadata = { id: 12 };
|
|
40
50
|
const { result } = renderHook(() => useToolInfo());
|
|
41
51
|
act(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}));
|
|
52
|
+
fireToolInputNotification({
|
|
53
|
+
name: "pokemon",
|
|
54
|
+
args: { name: "pikachu" },
|
|
55
|
+
});
|
|
56
|
+
fireToolResultNotification({
|
|
57
|
+
content: [{ type: "text", text: JSON.stringify(toolOutput) }],
|
|
58
|
+
structuredContent: toolOutput,
|
|
59
|
+
_meta: toolResponseMetadata,
|
|
60
|
+
});
|
|
52
61
|
});
|
|
53
62
|
await waitFor(() => {
|
|
54
63
|
expect(result.current).toMatchObject({
|
|
@@ -66,23 +75,24 @@ describe("useToolInfo", () => {
|
|
|
66
75
|
beforeEach(() => {
|
|
67
76
|
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
68
77
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
78
|
+
vi.stubGlobal("openai", undefined);
|
|
69
79
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
70
80
|
});
|
|
71
|
-
afterEach(() => {
|
|
81
|
+
afterEach(async () => {
|
|
82
|
+
HostAdaptor.resetInstance();
|
|
72
83
|
vi.unstubAllGlobals();
|
|
73
84
|
vi.resetAllMocks();
|
|
74
85
|
McpAppBridge.resetInstance();
|
|
75
|
-
McpAppAdaptor.resetInstance();
|
|
76
86
|
});
|
|
77
|
-
it("should return
|
|
87
|
+
it("should return pending state with undefined input before tool-input notification arrives", async () => {
|
|
78
88
|
const { result } = renderHook(() => useToolInfo());
|
|
79
89
|
await waitFor(() => {
|
|
80
90
|
expect(result.current).toMatchObject({
|
|
81
|
-
status: "
|
|
82
|
-
isIdle:
|
|
83
|
-
isPending:
|
|
91
|
+
status: "pending",
|
|
92
|
+
isIdle: false,
|
|
93
|
+
isPending: true,
|
|
84
94
|
isSuccess: false,
|
|
85
|
-
input:
|
|
95
|
+
input: undefined,
|
|
86
96
|
output: null,
|
|
87
97
|
responseMetadata: null,
|
|
88
98
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAEL,sBAAsB,EACtB,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,UAGH,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG;gBACX,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,IAAI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AChB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;oBAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBAC5C,gBAAgB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n fireToolInputNotification,\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ndescribe(\"useToolInfo\", () => {\n describe(\"apps-sdk host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"openai\", {\n toolInput: null,\n toolOutput: null,\n toolResponseMetadata: null,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n input: { name: \"pokemon\", args: { name: \"pikachu\" } },\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n });\n });\n });\n\n it(\"should return success state once tool-result notification arrives\", async () => {\n const toolOutput = {\n name: \"pikachu\",\n color: \"yellow\",\n description:\n \"When several of these POKéMON gather, their\\felectricity could build and cause lightning storms.\",\n };\n const toolResponseMetadata = { id: 12 };\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({\n name: \"pokemon\",\n args: { name: \"pikachu\" },\n });\n fireToolResultNotification({\n content: [{ type: \"text\", text: JSON.stringify(toolOutput) }],\n structuredContent: toolOutput,\n _meta: toolResponseMetadata,\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n output: toolOutput,\n responseMetadata: toolResponseMetadata,\n });\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n HostAdaptor.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return pending state with undefined input before tool-input notification arrives\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: undefined,\n output: null,\n responseMetadata: null,\n });\n });\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: { name: \"pokemon\", query: \"pikachu\" },\n });\n });\n });\n\n it(\"should return success state with output from tool-result notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"Pikachu data\" }],\n structuredContent: { name: \"pikachu\", color: \"yellow\" },\n _meta: { requestId: \"123\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n input: { name: \"pokemon\", query: \"pikachu\" },\n output: { name: \"pikachu\", color: \"yellow\" },\n responseMetadata: { requestId: \"123\" },\n });\n });\n });\n });\n});\n"]}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { useHostContext } from "../bridges/index.js";
|
|
2
|
+
const DEFAULT_LOCALE = "en-US";
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.
|
|
5
|
+
*
|
|
6
|
+
* Handles underscored identifiers returned by the ChatGPT mobile app (e.g. "fr_FR" → "fr-FR"),
|
|
7
|
+
* incorrect casing (e.g. "en-us" → "en-US"), and complex subtags (e.g. "zh_Hans_CN" → "zh-Hans-CN").
|
|
8
|
+
* Falls back to "en-US" if the locale is invalid.
|
|
9
|
+
*/
|
|
10
|
+
function normalizeLocale(locale) {
|
|
11
|
+
try {
|
|
12
|
+
return new Intl.Locale(locale.replace(/_/g, "-")).toString();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return DEFAULT_LOCALE;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
2
18
|
/**
|
|
3
19
|
* Hook for accessing session-stable user information.
|
|
4
20
|
* These values are set once at initialization and do not change during the session.
|
|
@@ -10,10 +26,12 @@ import { useHostContext } from "../bridges/index.js";
|
|
|
10
26
|
* // Access device type
|
|
11
27
|
* const isMobile = userAgent.device.type === "mobile";
|
|
12
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see https://docs.skybridge.tech/api-reference/use-user
|
|
13
31
|
*/
|
|
14
32
|
export function useUser() {
|
|
15
|
-
const
|
|
33
|
+
const rawLocale = useHostContext("locale");
|
|
16
34
|
const userAgent = useHostContext("userAgent");
|
|
17
|
-
return { locale, userAgent };
|
|
35
|
+
return { locale: normalizeLocale(rawLocale), userAgent };
|
|
18
36
|
}
|
|
19
37
|
//# sourceMappingURL=use-user.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrE
|
|
1
|
+
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrE,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAE9C,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["import { type UserAgent, useHostContext } from \"../bridges/index.js\";\n\nexport type UserState = {\n locale: string;\n userAgent: UserAgent;\n};\n\nconst DEFAULT_LOCALE = \"en-US\";\n\n/**\n * Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.\n *\n * Handles underscored identifiers returned by the ChatGPT mobile app (e.g. \"fr_FR\" → \"fr-FR\"),\n * incorrect casing (e.g. \"en-us\" → \"en-US\"), and complex subtags (e.g. \"zh_Hans_CN\" → \"zh-Hans-CN\").\n * Falls back to \"en-US\" if the locale is invalid.\n */\nfunction normalizeLocale(locale: string): string {\n try {\n return new Intl.Locale(locale.replace(/_/g, \"-\")).toString();\n } catch {\n return DEFAULT_LOCALE;\n }\n}\n\n/**\n * Hook for accessing session-stable user information.\n * These values are set once at initialization and do not change during the session.\n *\n * @example\n * ```tsx\n * const { locale, userAgent } = useUser();\n *\n * // Access device type\n * const isMobile = userAgent.device.type === \"mobile\";\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-user\n */\nexport function useUser(): UserState {\n const rawLocale = useHostContext(\"locale\");\n const userAgent = useHostContext(\"userAgent\");\n\n return { locale: normalizeLocale(rawLocale), userAgent };\n}\n"]}
|
|
@@ -1,60 +1,121 @@
|
|
|
1
1
|
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
4
|
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
5
5
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
6
|
import { useUser } from "./use-user.js";
|
|
7
7
|
describe("useUser", () => {
|
|
8
8
|
describe("apps-sdk host type", () => {
|
|
9
|
-
let OpenaiMock;
|
|
10
9
|
beforeEach(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
device: { type: "desktop" },
|
|
15
|
-
capabilities: { hover: true, touch: false },
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
10
|
+
HostAdaptor.resetInstance();
|
|
11
|
+
McpAppBridge.resetInstance();
|
|
12
|
+
vi.stubGlobal("openai", { locale: "en-US" });
|
|
19
13
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
14
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
20
15
|
});
|
|
21
16
|
afterEach(() => {
|
|
22
17
|
vi.unstubAllGlobals();
|
|
23
18
|
vi.resetAllMocks();
|
|
19
|
+
McpAppBridge.resetInstance();
|
|
20
|
+
HostAdaptor.resetInstance();
|
|
24
21
|
});
|
|
25
|
-
it("should return locale and userAgent from
|
|
22
|
+
it("should return locale and userAgent from mcp host context", async () => {
|
|
23
|
+
vi.stubGlobal("parent", {
|
|
24
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
25
|
+
locale: "en-US",
|
|
26
|
+
platform: "web",
|
|
27
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
26
30
|
const { result } = renderHook(() => useUser());
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
await waitFor(() => {
|
|
32
|
+
expect(result.current.locale).toBe("en-US");
|
|
33
|
+
expect(result.current.userAgent).toEqual({
|
|
34
|
+
device: { type: "desktop" },
|
|
35
|
+
capabilities: { hover: true, touch: false },
|
|
36
|
+
});
|
|
31
37
|
});
|
|
32
38
|
});
|
|
33
|
-
it("should return mobile userAgent when set to mobile", () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
it("should return mobile userAgent when set to mobile", async () => {
|
|
40
|
+
vi.stubGlobal("parent", {
|
|
41
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
42
|
+
locale: "en-US",
|
|
43
|
+
platform: "mobile",
|
|
44
|
+
deviceCapabilities: { hover: false, touch: true },
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
38
47
|
const { result } = renderHook(() => useUser());
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(result.current.userAgent.device.type).toBe("mobile");
|
|
50
|
+
expect(result.current.userAgent.capabilities.touch).toBe(true);
|
|
51
|
+
});
|
|
41
52
|
});
|
|
42
|
-
it("should return different locale when set", () => {
|
|
43
|
-
|
|
53
|
+
it("should return different locale when set", async () => {
|
|
54
|
+
vi.stubGlobal("parent", {
|
|
55
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
56
|
+
locale: "es-ES",
|
|
57
|
+
platform: "web",
|
|
58
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
44
61
|
const { result } = renderHook(() => useUser());
|
|
45
|
-
|
|
62
|
+
await waitFor(() => {
|
|
63
|
+
expect(result.current.locale).toBe("es-ES");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it("should normalize underscore locale to BCP 47 hyphen format", async () => {
|
|
67
|
+
vi.stubGlobal("parent", {
|
|
68
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
69
|
+
locale: "fr_FR",
|
|
70
|
+
platform: "web",
|
|
71
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
const { result } = renderHook(() => useUser());
|
|
75
|
+
await waitFor(() => {
|
|
76
|
+
expect(result.current.locale).toBe("fr-FR");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("should canonicalize locale casing", async () => {
|
|
80
|
+
vi.stubGlobal("parent", {
|
|
81
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
82
|
+
locale: "en-us",
|
|
83
|
+
platform: "web",
|
|
84
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
const { result } = renderHook(() => useUser());
|
|
88
|
+
await waitFor(() => {
|
|
89
|
+
expect(result.current.locale).toBe("en-US");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it("should fall back to en-US for invalid locale", async () => {
|
|
93
|
+
vi.stubGlobal("parent", {
|
|
94
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
95
|
+
locale: "not-a-locale-!!",
|
|
96
|
+
platform: "web",
|
|
97
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
const { result } = renderHook(() => useUser());
|
|
101
|
+
await waitFor(() => {
|
|
102
|
+
expect(result.current.locale).toBe("en-US");
|
|
103
|
+
});
|
|
46
104
|
});
|
|
47
105
|
});
|
|
48
106
|
describe("mcp-app host type", () => {
|
|
49
107
|
beforeEach(() => {
|
|
108
|
+
HostAdaptor.resetInstance();
|
|
109
|
+
McpAppBridge.resetInstance();
|
|
110
|
+
vi.stubGlobal("openai", undefined);
|
|
50
111
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
51
112
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
52
113
|
});
|
|
53
|
-
afterEach(() => {
|
|
114
|
+
afterEach(async () => {
|
|
54
115
|
vi.unstubAllGlobals();
|
|
55
116
|
vi.resetAllMocks();
|
|
56
117
|
McpAppBridge.resetInstance();
|
|
57
|
-
|
|
118
|
+
HostAdaptor.resetInstance();
|
|
58
119
|
});
|
|
59
120
|
it("should return locale and userAgent from mcp host context", async () => {
|
|
60
121
|
vi.stubGlobal("parent", {
|
|
@@ -73,6 +134,19 @@ describe("useUser", () => {
|
|
|
73
134
|
});
|
|
74
135
|
});
|
|
75
136
|
});
|
|
137
|
+
it("should normalize underscore locale to BCP 47 hyphen format", async () => {
|
|
138
|
+
vi.stubGlobal("parent", {
|
|
139
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
140
|
+
locale: "fr_FR",
|
|
141
|
+
platform: "web",
|
|
142
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
const { result } = renderHook(() => useUser());
|
|
146
|
+
await waitFor(() => {
|
|
147
|
+
expect(result.current.locale).toBe("fr-FR");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
76
150
|
it("should maintain userAgent referential stability when data has not changed", async () => {
|
|
77
151
|
vi.stubGlobal("parent", {
|
|
78
152
|
postMessage: getMcpAppHostPostMessageMock({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,IAAI,UAGH,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG;gBACX,MAAM,EAAE,OAAO;gBACf,SAAS,EAAE;oBACT,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC3B,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;iBAC5C;aACF,CAAC;YACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uDAAuD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CAAC;YAE/C,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2EAA2E,EAAE,KAAK,IAAI,EAAE;YACzF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,WAAW,EAAE,4BAA4B,CAAC;oBACxC,MAAM,EAAE,OAAO;oBACf,QAAQ,EAAE,KAAK;oBACf,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;iBAClD,CAAC;aACH,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAEzD,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;YAElD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useUser } from \"./use-user.js\";\n\ndescribe(\"useUser\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", { locale: \"en-US\" });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should return mobile userAgent when set to mobile\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"mobile\",\n deviceCapabilities: { hover: false, touch: true },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent.device.type).toBe(\"mobile\");\n expect(result.current.userAgent.capabilities.touch).toBe(true);\n });\n });\n\n it(\"should return different locale when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"es-ES\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"es-ES\");\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should canonicalize locale casing\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-us\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n\n it(\"should fall back to en-US for invalid locale\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"not-a-locale-!!\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr-FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should maintain userAgent referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result, rerender } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent).toBeDefined();\n });\n\n const initialUserAgent = result.current.userAgent;\n\n rerender();\n\n expect(result.current.userAgent).toBe(initialUserAgent);\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type SetStateAction } from "react";
|
|
2
|
+
import type { UnknownObject } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Persist a piece of UI state on the host, so it survives view remounts and
|
|
5
|
+
* is restored on subsequent renders of the same tool invocation.
|
|
6
|
+
*
|
|
7
|
+
* Returns a `[state, setState]` pair with the same ergonomics as
|
|
8
|
+
* `useState`. State is filtered to strip Skybridge-internal context fields
|
|
9
|
+
* (see {@link DataLLM}) before being returned to your component.
|
|
10
|
+
*
|
|
11
|
+
* Provide a `defaultState` (value or lazy initializer) to get a non-nullable
|
|
12
|
+
* tuple; omit it for `T | null`.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam T - Shape of the persisted state. Must be a plain object.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const [filters, setFilters] = useViewState({ sort: "newest", page: 1 });
|
|
19
|
+
* setFilters((f) => ({ ...f, page: f.page + 1 }));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @see https://docs.skybridge.tech/api-reference/use-view-state
|
|
23
|
+
*/
|
|
24
|
+
export declare function useViewState<T extends UnknownObject>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
|
|
25
|
+
export declare function useViewState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { getAdaptor, useHostContext } from "../bridges/index.js";
|
|
3
|
+
import { filterViewContext, injectViewContext } from "../helpers/state.js";
|
|
4
|
+
export function useViewState(defaultState) {
|
|
5
|
+
const adaptor = getAdaptor();
|
|
6
|
+
const viewStateFromBridge = useHostContext("viewState");
|
|
7
|
+
const [viewState, _setViewState] = useState(() => {
|
|
8
|
+
if (viewStateFromBridge !== null) {
|
|
9
|
+
return filterViewContext(viewStateFromBridge);
|
|
10
|
+
}
|
|
11
|
+
return typeof defaultState === "function"
|
|
12
|
+
? defaultState()
|
|
13
|
+
: (defaultState ?? null);
|
|
14
|
+
});
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (viewStateFromBridge !== null) {
|
|
17
|
+
_setViewState(filterViewContext(viewStateFromBridge));
|
|
18
|
+
}
|
|
19
|
+
}, [viewStateFromBridge]);
|
|
20
|
+
const setViewState = useCallback((state) => {
|
|
21
|
+
_setViewState((prevState) => {
|
|
22
|
+
const newState = typeof state === "function" ? state(prevState) : state;
|
|
23
|
+
const stateToSet = injectViewContext(newState);
|
|
24
|
+
if (stateToSet !== null) {
|
|
25
|
+
adaptor.setViewState(stateToSet);
|
|
26
|
+
}
|
|
27
|
+
return filterViewContext(stateToSet);
|
|
28
|
+
});
|
|
29
|
+
}, [adaptor]);
|
|
30
|
+
return [viewState, setViewState];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=use-view-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-view-state.js","sourceRoot":"","sources":["../../../src/web/hooks/use-view-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,iBA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AAE,YAAY,CAAU,CAAC;AAC5C,CAAC","sourcesContent":["import { type SetStateAction, useCallback, useEffect, useState } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport { filterViewContext, injectViewContext } from \"../helpers/state.js\";\nimport type { UnknownObject } from \"../types.js\";\n\n/**\n * Persist a piece of UI state on the host, so it survives view remounts and\n * is restored on subsequent renders of the same tool invocation.\n *\n * Returns a `[state, setState]` pair with the same ergonomics as\n * `useState`. State is filtered to strip Skybridge-internal context fields\n * (see {@link DataLLM}) before being returned to your component.\n *\n * Provide a `defaultState` (value or lazy initializer) to get a non-nullable\n * tuple; omit it for `T | null`.\n *\n * @typeParam T - Shape of the persisted state. Must be a plain object.\n *\n * @example\n * ```tsx\n * const [filters, setFilters] = useViewState({ sort: \"newest\", page: 1 });\n * setFilters((f) => ({ ...f, page: f.page + 1 }));\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-view-state\n */\nexport function useViewState<T extends UnknownObject>(\n defaultState: T | (() => T),\n): readonly [T, (state: SetStateAction<T>) => void];\nexport function useViewState<T extends UnknownObject>(\n defaultState?: T | (() => T | null) | null,\n): readonly [T | null, (state: SetStateAction<T | null>) => void];\nexport function useViewState<T extends UnknownObject>(\n defaultState?: T | (() => T | null) | null,\n): readonly [T | null, (state: SetStateAction<T | null>) => void] {\n const adaptor = getAdaptor();\n const viewStateFromBridge = useHostContext(\"viewState\") as T | null;\n\n const [viewState, _setViewState] = useState<T | null>(() => {\n if (viewStateFromBridge !== null) {\n return filterViewContext(viewStateFromBridge);\n }\n\n return typeof defaultState === \"function\"\n ? defaultState()\n : (defaultState ?? null);\n });\n\n useEffect(() => {\n if (viewStateFromBridge !== null) {\n _setViewState(filterViewContext(viewStateFromBridge));\n }\n }, [viewStateFromBridge]);\n\n const setViewState = useCallback(\n (state: SetStateAction<T | null>) => {\n _setViewState((prevState) => {\n const newState = typeof state === \"function\" ? state(prevState) : state;\n const stateToSet = injectViewContext(newState);\n\n if (stateToSet !== null) {\n adaptor.setViewState(stateToSet);\n }\n\n return filterViewContext(stateToSet);\n });\n },\n [adaptor],\n );\n\n return [viewState, setViewState] as const;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|