skybridge 0.0.0-dev.efbdb09 → 0.0.0-dev.efd00e6
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 +124 -124
- 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.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +130 -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.d.ts +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 +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/header.js.map +1 -1
- 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.js.map +1 -1
- 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.js.map +1 -1
- 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.d.ts +1 -0
- package/dist/cli/tunnel-control-server.test.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.d.ts +1 -0
- package/dist/cli/tunnel-handler.test.js +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.js.map +1 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.js.map +1 -1
- package/dist/cli/use-nodemon.d.ts +14 -0
- package/dist/cli/use-nodemon.js +72 -52
- package/dist/cli/use-nodemon.js.map +1 -1
- 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 +1 -1
- package/dist/cli/use-tunnel.js +102 -68
- package/dist/cli/use-tunnel.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +71 -68
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +2 -38
- 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 +2 -0
- package/dist/commands/dev.js +81 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +17 -2
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +80 -1
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- 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 +32 -0
- package/dist/server/auth/providers/custom.js +49 -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 +156 -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 +44 -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 +60 -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/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.d.ts +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.d.ts +1 -0
- package/dist/server/auth/setup.test.js +474 -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 +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/content-helpers.test.js.map +1 -1
- package/dist/server/express.d.ts +1 -5
- package/dist/server/express.js +31 -7
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +271 -69
- package/dist/server/express.test.js.map +1 -1
- 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 +12 -2
- package/dist/server/index.js +10 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js.map +1 -1
- 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 +292 -10
- package/dist/server/server.js +479 -184
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +63 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +178 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +210 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/templateHelper.d.ts +0 -2
- 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-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.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +109 -96
- package/dist/test/view.test.js.map +1 -1
- package/dist/version.js +1 -3
- package/dist/version.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +341 -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 +224 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -1
- 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 +0 -1
- 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 +8 -1
- 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 +15 -2
- package/dist/web/bridges/mcp-app/bridge.js +73 -7
- 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.d.ts +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- 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.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 +108 -3
- 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 +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- 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 +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +17 -5
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +4 -2
- 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.js.map +1 -1
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +5 -0
- package/dist/web/hooks/index.js +5 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +7 -2
- package/dist/web/hooks/test/utils.js +14 -3
- 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 +20 -0
- 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.js.map +1 -1
- 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 +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- 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/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 +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- 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 +16 -1
- package/dist/web/hooks/use-request-modal.js +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- 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 +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- 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 +42 -32
- 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 +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +21 -0
- package/dist/web/hooks/use-view-state.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +37 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +19 -0
- package/dist/web/mount-view.js +19 -0
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +34 -0
- package/dist/web/plugin/plugin.js +65 -17
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.d.ts +8 -0
- package/dist/web/plugin/scan-views.js +26 -8
- package/dist/web/plugin/scan-views.js.map +1 -1
- package/dist/web/plugin/scan-views.test.js +33 -1
- package/dist/web/plugin/scan-views.test.js.map +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.js.map +1 -1
- package/dist/web/plugin/validate-view.test.js.map +1 -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 +34 -24
- package/dist/server/templates/development.hbs +0 -12
- package/dist/server/templates/production.hbs +0 -6
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -24
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -93
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -48
- package/dist/web/bridges/mcp-app/adaptor.js +0 -268
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
|
@@ -1,62 +1,95 @@
|
|
|
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 { useLayout } from "./use-layout.js";
|
|
7
7
|
describe("useLayout", () => {
|
|
8
8
|
describe("apps-sdk host type", () => {
|
|
9
|
-
let OpenaiMock;
|
|
10
9
|
beforeEach(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
maxHeight: 500,
|
|
14
|
-
safeArea: { insets: { top: 0, bottom: 0, left: 0, right: 0 } },
|
|
15
|
-
};
|
|
16
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
10
|
+
HostAdaptor.resetInstance();
|
|
11
|
+
McpAppBridge.resetInstance();
|
|
17
12
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
13
|
+
vi.stubGlobal("openai", { view: { mode: "inline" } });
|
|
14
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
18
15
|
});
|
|
19
16
|
afterEach(() => {
|
|
20
17
|
vi.unstubAllGlobals();
|
|
21
18
|
vi.resetAllMocks();
|
|
19
|
+
McpAppBridge.resetInstance();
|
|
20
|
+
HostAdaptor.resetInstance();
|
|
22
21
|
});
|
|
23
|
-
it("should return theme, maxHeight, and safeArea from
|
|
22
|
+
it("should return theme, maxHeight, and safeArea from mcp host context", async () => {
|
|
23
|
+
vi.stubGlobal("parent", {
|
|
24
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
25
|
+
theme: "light",
|
|
26
|
+
containerDimensions: { maxHeight: 500, width: 400 },
|
|
27
|
+
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
24
30
|
const { result } = renderHook(() => useLayout());
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
await waitFor(() => {
|
|
32
|
+
expect(result.current.theme).toBe("light");
|
|
33
|
+
expect(result.current.maxHeight).toBe(500);
|
|
34
|
+
expect(result.current.safeArea).toEqual({
|
|
35
|
+
insets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
36
|
+
});
|
|
29
37
|
});
|
|
30
38
|
});
|
|
31
|
-
it("should return dark theme when set to dark", () => {
|
|
32
|
-
|
|
39
|
+
it("should return dark theme when set to dark", async () => {
|
|
40
|
+
vi.stubGlobal("parent", {
|
|
41
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
42
|
+
theme: "dark",
|
|
43
|
+
containerDimensions: { maxHeight: 500, width: 400 },
|
|
44
|
+
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
33
47
|
const { result } = renderHook(() => useLayout());
|
|
34
|
-
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(result.current.theme).toBe("dark");
|
|
50
|
+
});
|
|
35
51
|
});
|
|
36
|
-
it("should return different maxHeight when set", () => {
|
|
37
|
-
|
|
52
|
+
it("should return different maxHeight when set", async () => {
|
|
53
|
+
vi.stubGlobal("parent", {
|
|
54
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
55
|
+
theme: "light",
|
|
56
|
+
containerDimensions: { maxHeight: 800, width: 400 },
|
|
57
|
+
safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
38
60
|
const { result } = renderHook(() => useLayout());
|
|
39
|
-
|
|
61
|
+
await waitFor(() => {
|
|
62
|
+
expect(result.current.maxHeight).toBe(800);
|
|
63
|
+
});
|
|
40
64
|
});
|
|
41
|
-
it("should return safeArea with insets when set", () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
65
|
+
it("should return safeArea with insets when set", async () => {
|
|
66
|
+
vi.stubGlobal("parent", {
|
|
67
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
68
|
+
theme: "light",
|
|
69
|
+
containerDimensions: { maxHeight: 500, width: 400 },
|
|
70
|
+
safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
45
73
|
const { result } = renderHook(() => useLayout());
|
|
46
|
-
|
|
47
|
-
|
|
74
|
+
await waitFor(() => {
|
|
75
|
+
expect(result.current.safeArea.insets.top).toBe(44);
|
|
76
|
+
expect(result.current.safeArea.insets.bottom).toBe(34);
|
|
77
|
+
});
|
|
48
78
|
});
|
|
49
79
|
});
|
|
50
80
|
describe("mcp-app host type", () => {
|
|
51
81
|
beforeEach(() => {
|
|
82
|
+
HostAdaptor.resetInstance();
|
|
83
|
+
McpAppBridge.resetInstance();
|
|
52
84
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
85
|
+
vi.stubGlobal("openai", undefined);
|
|
53
86
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
54
87
|
});
|
|
55
88
|
afterEach(async () => {
|
|
56
89
|
vi.unstubAllGlobals();
|
|
57
90
|
vi.resetAllMocks();
|
|
58
91
|
McpAppBridge.resetInstance();
|
|
59
|
-
|
|
92
|
+
HostAdaptor.resetInstance();
|
|
60
93
|
});
|
|
61
94
|
it("should return theme, maxHeight, and safeArea from mcp host context", async () =>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AAE,4BAA4B,CAAC;oBACxC,KAAK,EAAE,OAAO;oBACd,mBAAmB,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE;oBACnD,cAAc,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;iBAC3D,CAAC;aACH,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC;YAE3D,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAEhD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,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 { useLayout } from \"./use-layout.js\";\n\ndescribe(\"useLayout\", () => {\n describe(\"apps-sdk host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { view: { mode: \"inline\" } });\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 theme, maxHeight, and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"light\");\n expect(result.current.maxHeight).toBe(500);\n expect(result.current.safeArea).toEqual({\n insets: { top: 0, bottom: 0, left: 0, right: 0 },\n });\n });\n });\n\n it(\"should return dark theme when set to dark\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"dark\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"dark\");\n });\n });\n\n it(\"should return different maxHeight when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 0, bottom: 0, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.maxHeight).toBe(800);\n });\n });\n\n it(\"should return safeArea with insets when set\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, bottom: 34, left: 0, right: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.safeArea.insets.top).toBe(44);\n expect(result.current.safeArea.insets.bottom).toBe(34);\n });\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\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 theme, maxHeight, and safeArea from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"dark\",\n containerDimensions: { maxHeight: 800, width: 400 },\n safeAreaInsets: { top: 20, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.theme).toBe(\"dark\");\n expect(result.current.maxHeight).toBe(800);\n expect(result.current.safeArea).toEqual({\n insets: { top: 20, right: 0, bottom: 34, left: 0 },\n });\n });\n });\n\n it(\"should maintain safeArea referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n theme: \"light\",\n containerDimensions: { maxHeight: 500, width: 400 },\n safeAreaInsets: { top: 44, right: 0, bottom: 34, left: 0 },\n }),\n });\n const { result, rerender } = renderHook(() => useLayout());\n\n await waitFor(() => {\n expect(result.current.safeArea).toBeDefined();\n });\n\n const initialSafeArea = result.current.safeArea;\n\n rerender();\n\n expect(result.current.safeArea).toBe(initialSafeArea);\n });\n });\n});\n"]}
|
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
import type { OpenExternalOptions } from "../bridges/types.js";
|
|
2
|
+
/** Function that opens a URL outside the view's iframe, returned by {@link useOpenExternal}. */
|
|
2
3
|
export type OpenExternalFn = (href: string, options?: OpenExternalOptions) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Open an external URL through the host (e.g. in the user's browser).
|
|
6
|
+
*
|
|
7
|
+
* Use this instead of `window.open` or anchor `target="_blank"`, which are
|
|
8
|
+
* unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.
|
|
9
|
+
* ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass
|
|
10
|
+
* `redirectUrl: false` to suppress it).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const openExternal = useOpenExternal();
|
|
15
|
+
* <button onClick={() => openExternal("https://example.com")}>Open docs</button>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-open-external
|
|
19
|
+
*/
|
|
3
20
|
export declare function useOpenExternal(): OpenExternalFn;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Open an external URL through the host (e.g. in the user's browser).
|
|
5
|
+
*
|
|
6
|
+
* Use this instead of `window.open` or anchor `target="_blank"`, which are
|
|
7
|
+
* unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.
|
|
8
|
+
* ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass
|
|
9
|
+
* `redirectUrl: false` to suppress it).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const openExternal = useOpenExternal();
|
|
14
|
+
* <button onClick={() => openExternal("https://example.com")}>Open docs</button>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @see https://docs.skybridge.tech/api-reference/use-open-external
|
|
18
|
+
*/
|
|
3
19
|
export function useOpenExternal() {
|
|
4
20
|
const adaptor = getAdaptor();
|
|
5
21
|
const openExternal = useCallback((href, options) => adaptor.openExternal(href, options), [adaptor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AASjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,IAAY,EAAE,OAA6B,EAAE,EAAE,CAC9C,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EACrC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { OpenExternalOptions } from \"../bridges/types.js\";\n\n/** Function that opens a URL outside the view's iframe, returned by {@link useOpenExternal}. */\nexport type OpenExternalFn = (\n href: string,\n options?: OpenExternalOptions,\n) => void;\n\n/**\n * Open an external URL through the host (e.g. in the user's browser).\n *\n * Use this instead of `window.open` or anchor `target=\"_blank\"`, which are\n * unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.\n * ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass\n * `redirectUrl: false` to suppress it).\n *\n * @example\n * ```tsx\n * const openExternal = useOpenExternal();\n * <button onClick={() => openExternal(\"https://example.com\")}>Open docs</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-open-external\n */\nexport function useOpenExternal(): OpenExternalFn {\n const adaptor = getAdaptor();\n const openExternal = useCallback(\n (href: string, options?: OpenExternalOptions) =>\n adaptor.openExternal(href, options),\n [adaptor],\n );\n\n return openExternal;\n}\n"]}
|
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
3
4
|
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
4
5
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
5
6
|
import { useOpenExternal } from "./use-open-external.js";
|
|
6
7
|
describe("useOpenExternal", () => {
|
|
7
8
|
describe("apps-sdk host", () => {
|
|
8
9
|
let openExternalMock;
|
|
10
|
+
let postMessageMock;
|
|
9
11
|
beforeEach(() => {
|
|
10
12
|
openExternalMock = vi.fn();
|
|
11
13
|
vi.stubGlobal("openai", {
|
|
12
14
|
openExternal: openExternalMock,
|
|
13
15
|
});
|
|
14
16
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
17
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
18
|
+
postMessageMock = getMcpAppHostPostMessageMock();
|
|
19
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
15
20
|
});
|
|
16
21
|
afterEach(() => {
|
|
22
|
+
HostAdaptor.resetInstance();
|
|
23
|
+
McpAppBridge.resetInstance();
|
|
17
24
|
vi.unstubAllGlobals();
|
|
18
25
|
vi.resetAllMocks();
|
|
19
26
|
});
|
|
20
|
-
it("should
|
|
27
|
+
it("should call window.openai.openExternal even without a redirectUrl option", () => {
|
|
21
28
|
const { result } = renderHook(() => useOpenExternal());
|
|
22
29
|
const href = "https://example.com";
|
|
23
30
|
result.current(href);
|
|
24
31
|
expect(openExternalMock).toHaveBeenCalledTimes(1);
|
|
25
32
|
expect(openExternalMock).toHaveBeenCalledWith({ href });
|
|
33
|
+
expect(postMessageMock).not.toHaveBeenCalledWith(expect.objectContaining({ method: "ui/open-link" }), "*");
|
|
26
34
|
});
|
|
27
|
-
it("should
|
|
35
|
+
it("should call window.openai.openExternal when redirectUrl is false", () => {
|
|
28
36
|
const { result } = renderHook(() => useOpenExternal());
|
|
29
37
|
const href = "https://example.com";
|
|
30
38
|
result.current(href, { redirectUrl: false });
|
|
@@ -38,15 +46,17 @@ describe("useOpenExternal", () => {
|
|
|
38
46
|
describe("mcp-app host", () => {
|
|
39
47
|
let postMessageMock;
|
|
40
48
|
beforeEach(() => {
|
|
49
|
+
vi.stubGlobal("openai", undefined);
|
|
41
50
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
42
51
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
43
52
|
postMessageMock = getMcpAppHostPostMessageMock();
|
|
44
53
|
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
45
54
|
});
|
|
46
55
|
afterEach(async () => {
|
|
56
|
+
HostAdaptor.resetInstance();
|
|
57
|
+
McpAppBridge.resetInstance();
|
|
47
58
|
vi.unstubAllGlobals();
|
|
48
59
|
vi.resetAllMocks();
|
|
49
|
-
McpAppBridge.resetInstance();
|
|
50
60
|
});
|
|
51
61
|
it("should return a function that sends ui/open-link request to the MCP host", async () => {
|
|
52
62
|
const { result } = renderHook(() => useOpenExternal());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.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,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,eA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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 { useOpenExternal } from \"./use-open-external.js\";\n\ndescribe(\"useOpenExternal\", () => {\n describe(\"apps-sdk host\", () => {\n let openExternalMock: ReturnType<typeof vi.fn>;\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n openExternalMock = vi.fn();\n vi.stubGlobal(\"openai\", {\n openExternal: openExternalMock,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should call window.openai.openExternal even without a redirectUrl option\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href);\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({ href });\n expect(postMessageMock).not.toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/open-link\" }),\n \"*\",\n );\n });\n\n it(\"should call window.openai.openExternal when redirectUrl is false\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({\n href,\n redirectUrl: false,\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return a function that sends ui/open-link request to the MCP host\", async () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/open-link\",\n params: { url: href },\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
2
|
+
import type { ViewToolConfig, ViewToolHandler } from "../bridges/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Register a tool the view exposes to the host and model — the MCP Apps
|
|
5
|
+
* "app-provided tools" feature. A view tool runs *inside the view*: the host
|
|
6
|
+
* discovers it via `tools/list` and invokes it via `tools/call`, and the
|
|
7
|
+
* handler executes against the view's live state. It is the inverse of
|
|
8
|
+
* {@link useCallTool} (which calls a server tool). Registered on mount, removed
|
|
9
|
+
* on unmount; re-registered when `config.name` changes.
|
|
10
|
+
*
|
|
11
|
+
* MCP Apps only — on the Apps SDK (`window.openai`) runtime it is a no-op.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import * as z from "zod";
|
|
16
|
+
* import { useRegisterViewTool } from "skybridge/web";
|
|
17
|
+
*
|
|
18
|
+
* useRegisterViewTool(
|
|
19
|
+
* {
|
|
20
|
+
* name: "chess_make_move",
|
|
21
|
+
* description: "Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.",
|
|
22
|
+
* inputSchema: { san: z.string() },
|
|
23
|
+
* annotations: { readOnlyHint: false },
|
|
24
|
+
* },
|
|
25
|
+
* ({ san }) => {
|
|
26
|
+
* const move = game.move(san);
|
|
27
|
+
* return {
|
|
28
|
+
* content: [{ type: "text", text: move ? `Played ${move.san}` : "Illegal move" }],
|
|
29
|
+
* structuredContent: { fen: game.fen() },
|
|
30
|
+
* isError: !move,
|
|
31
|
+
* };
|
|
32
|
+
* },
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see https://docs.skybridge.tech/api-reference/use-register-view-tool
|
|
37
|
+
*/
|
|
38
|
+
export declare const useRegisterViewTool: <TInput extends ZodRawShapeCompat = ZodRawShapeCompat>(config: ViewToolConfig<TInput>, handler: ViewToolHandler<TInput>) => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Register a tool the view exposes to the host and model — the MCP Apps
|
|
5
|
+
* "app-provided tools" feature. A view tool runs *inside the view*: the host
|
|
6
|
+
* discovers it via `tools/list` and invokes it via `tools/call`, and the
|
|
7
|
+
* handler executes against the view's live state. It is the inverse of
|
|
8
|
+
* {@link useCallTool} (which calls a server tool). Registered on mount, removed
|
|
9
|
+
* on unmount; re-registered when `config.name` changes.
|
|
10
|
+
*
|
|
11
|
+
* MCP Apps only — on the Apps SDK (`window.openai`) runtime it is a no-op.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import * as z from "zod";
|
|
16
|
+
* import { useRegisterViewTool } from "skybridge/web";
|
|
17
|
+
*
|
|
18
|
+
* useRegisterViewTool(
|
|
19
|
+
* {
|
|
20
|
+
* name: "chess_make_move",
|
|
21
|
+
* description: "Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.",
|
|
22
|
+
* inputSchema: { san: z.string() },
|
|
23
|
+
* annotations: { readOnlyHint: false },
|
|
24
|
+
* },
|
|
25
|
+
* ({ san }) => {
|
|
26
|
+
* const move = game.move(san);
|
|
27
|
+
* return {
|
|
28
|
+
* content: [{ type: "text", text: move ? `Played ${move.san}` : "Illegal move" }],
|
|
29
|
+
* structuredContent: { fen: game.fen() },
|
|
30
|
+
* isError: !move,
|
|
31
|
+
* };
|
|
32
|
+
* },
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see https://docs.skybridge.tech/api-reference/use-register-view-tool
|
|
37
|
+
*/
|
|
38
|
+
export const useRegisterViewTool = (config, handler) => {
|
|
39
|
+
const { name } = config;
|
|
40
|
+
const configRef = useRef(config);
|
|
41
|
+
configRef.current = config;
|
|
42
|
+
const handlerRef = useRef(handler);
|
|
43
|
+
handlerRef.current = handler;
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const adaptor = getAdaptor();
|
|
46
|
+
const wrappedHandler = (args) => handlerRef.current(args);
|
|
47
|
+
return adaptor.registerViewTool({ ...configRef.current, name }, wrappedHandler);
|
|
48
|
+
}, [name]);
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=use-register-view-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-register-view-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-register-view-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAOjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAGjC,MAA8B,EAC9B,OAAgC,EAChC,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAuB,CAAC,IAAI,EAAE,EAAE,CAClD,UAAU,CAAC,OAAO,CAAC,IAA8C,CAAC,CAAC;QAErE,OAAO,OAAO,CAAC,gBAAgB,CAC7B,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAC9B,cAAc,CACf,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import type { ZodRawShapeCompat } from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport { useEffect, useRef } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type {\n AnyViewToolHandler,\n ViewToolConfig,\n ViewToolHandler,\n} from \"../bridges/types.js\";\n\n/**\n * Register a tool the view exposes to the host and model — the MCP Apps\n * \"app-provided tools\" feature. A view tool runs *inside the view*: the host\n * discovers it via `tools/list` and invokes it via `tools/call`, and the\n * handler executes against the view's live state. It is the inverse of\n * {@link useCallTool} (which calls a server tool). Registered on mount, removed\n * on unmount; re-registered when `config.name` changes.\n *\n * MCP Apps only — on the Apps SDK (`window.openai`) runtime it is a no-op.\n *\n * @example\n * ```tsx\n * import * as z from \"zod\";\n * import { useRegisterViewTool } from \"skybridge/web\";\n *\n * useRegisterViewTool(\n * {\n * name: \"chess_make_move\",\n * description: \"Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.\",\n * inputSchema: { san: z.string() },\n * annotations: { readOnlyHint: false },\n * },\n * ({ san }) => {\n * const move = game.move(san);\n * return {\n * content: [{ type: \"text\", text: move ? `Played ${move.san}` : \"Illegal move\" }],\n * structuredContent: { fen: game.fen() },\n * isError: !move,\n * };\n * },\n * );\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-register-view-tool\n */\nexport const useRegisterViewTool = <\n TInput extends ZodRawShapeCompat = ZodRawShapeCompat,\n>(\n config: ViewToolConfig<TInput>,\n handler: ViewToolHandler<TInput>,\n) => {\n const { name } = config;\n const configRef = useRef(config);\n configRef.current = config;\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n\n useEffect(() => {\n const adaptor = getAdaptor();\n const wrappedHandler: AnyViewToolHandler = (args) =>\n handlerRef.current(args as Parameters<ViewToolHandler<TInput>>[0]);\n\n return adaptor.registerViewTool(\n { ...configRef.current, name },\n wrappedHandler,\n );\n }, [name]);\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Function that asks the host to close the current view, returned by {@link useRequestClose}. */
|
|
2
|
+
export type RequestCloseFn = () => Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Ask the host to close (dismiss) the current view. The host decides whether
|
|
5
|
+
* to honor the request. Useful from modal views or after a terminal action
|
|
6
|
+
* like "Done".
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const close = useRequestClose();
|
|
11
|
+
* <button onClick={() => close()}>Done</button>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-close
|
|
15
|
+
*/
|
|
16
|
+
export declare function useRequestClose(): RequestCloseFn;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ask the host to close (dismiss) the current view. The host decides whether
|
|
5
|
+
* to honor the request. Useful from modal views or after a terminal action
|
|
6
|
+
* like "Done".
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const close = useRequestClose();
|
|
11
|
+
* <button onClick={() => close()}>Done</button>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-close
|
|
15
|
+
*/
|
|
16
|
+
export function useRequestClose() {
|
|
17
|
+
const adaptor = getAdaptor();
|
|
18
|
+
const requestClose = useCallback(() => adaptor.requestClose(), [adaptor]);
|
|
19
|
+
return requestClose;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=use-request-close.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-close.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAE1E,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\n/** Function that asks the host to close the current view, returned by {@link useRequestClose}. */\nexport type RequestCloseFn = () => Promise<void>;\n\n/**\n * Ask the host to close (dismiss) the current view. The host decides whether\n * to honor the request. Useful from modal views or after a terminal action\n * like \"Done\".\n *\n * @example\n * ```tsx\n * const close = useRequestClose();\n * <button onClick={() => close()}>Done</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-close\n */\nexport function useRequestClose(): RequestCloseFn {\n const adaptor = getAdaptor();\n const requestClose = useCallback(() => adaptor.requestClose(), [adaptor]);\n\n return requestClose;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { getAdaptor } from "../bridges/get-adaptor.js";
|
|
5
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
6
|
+
import { useRequestClose } from "./use-request-close.js";
|
|
7
|
+
describe("useRequestClose", () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
HostAdaptor.resetInstance();
|
|
10
|
+
McpAppBridge.resetInstance();
|
|
11
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
12
|
+
vi.stubGlobal("openai", undefined);
|
|
13
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
vi.resetAllMocks();
|
|
18
|
+
HostAdaptor.resetInstance();
|
|
19
|
+
McpAppBridge.resetInstance();
|
|
20
|
+
});
|
|
21
|
+
it("calls app.requestTeardown via the MCP path", async () => {
|
|
22
|
+
const requestTeardown = vi.fn().mockResolvedValue(undefined);
|
|
23
|
+
// biome-ignore lint/suspicious/noExplicitAny: test seam
|
|
24
|
+
const adaptor = getAdaptor();
|
|
25
|
+
adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });
|
|
26
|
+
const { result } = renderHook(() => useRequestClose());
|
|
27
|
+
await act(async () => {
|
|
28
|
+
await result.current();
|
|
29
|
+
});
|
|
30
|
+
expect(requestTeardown).toHaveBeenCalledTimes(1);
|
|
31
|
+
});
|
|
32
|
+
it("calls app.requestTeardown even when window.openai is present", async () => {
|
|
33
|
+
vi.stubGlobal("openai", { requestClose: vi.fn() });
|
|
34
|
+
HostAdaptor.resetInstance();
|
|
35
|
+
McpAppBridge.resetInstance();
|
|
36
|
+
const requestTeardown = vi.fn().mockResolvedValue(undefined);
|
|
37
|
+
// biome-ignore lint/suspicious/noExplicitAny: test seam
|
|
38
|
+
const adaptor = getAdaptor();
|
|
39
|
+
adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });
|
|
40
|
+
const { result } = renderHook(() => useRequestClose());
|
|
41
|
+
await act(async () => {
|
|
42
|
+
await result.current();
|
|
43
|
+
});
|
|
44
|
+
expect(requestTeardown).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=use-request-close.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-close.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-close.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,UAAU,CAAC,GAAG,EAAE;QACd,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnC,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE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E,eAAe,EAAE,CAAC,CAAC;QAEpE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QACvD,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { useRequestClose } from \"./use-request-close.js\";\n\ndescribe(\"useRequestClose\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n });\n\n it(\"calls app.requestTeardown via the MCP path\", async () => {\n const requestTeardown = vi.fn().mockResolvedValue(undefined);\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n const adaptor = getAdaptor() as any;\n adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });\n\n const { result } = renderHook(() => useRequestClose());\n await act(async () => {\n await result.current();\n });\n\n expect(requestTeardown).toHaveBeenCalledTimes(1);\n });\n\n it(\"calls app.requestTeardown even when window.openai is present\", async () => {\n vi.stubGlobal(\"openai\", { requestClose: vi.fn() });\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n\n const requestTeardown = vi.fn().mockResolvedValue(undefined);\n // biome-ignore lint/suspicious/noExplicitAny: test seam\n const adaptor = getAdaptor() as any;\n adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });\n\n const { result } = renderHook(() => useRequestClose());\n await act(async () => {\n await result.current();\n });\n\n expect(requestTeardown).toHaveBeenCalledTimes(1);\n });\n});\n"]}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { type RequestModalOptions } from "../bridges/index.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Open the current view in a modal overlay (`displayMode === "modal"`).
|
|
4
|
+
*
|
|
5
|
+
* Returns `{ isOpen, params, open }`: `open(opts)` triggers the host to render
|
|
6
|
+
* the view in a modal, optionally passing `params` that are surfaced back via
|
|
7
|
+
* `params` here. Useful for confirmation flows, detail panels, or any modal
|
|
8
|
+
* lifecycle owned by the host.
|
|
9
|
+
*
|
|
10
|
+
* Use {@link useDisplayMode} for non-modal display modes.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const { isOpen, open } = useRequestModal();
|
|
15
|
+
* <button onClick={() => open({ params: { id: 42 } })}>Show details</button>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-modal
|
|
4
19
|
*/
|
|
5
20
|
export declare function useRequestModal(): {
|
|
6
21
|
isOpen: boolean;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor, useHostContext, } from "../bridges/index.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Open the current view in a modal overlay (`displayMode === "modal"`).
|
|
5
|
+
*
|
|
6
|
+
* Returns `{ isOpen, params, open }`: `open(opts)` triggers the host to render
|
|
7
|
+
* the view in a modal, optionally passing `params` that are surfaced back via
|
|
8
|
+
* `params` here. Useful for confirmation flows, detail panels, or any modal
|
|
9
|
+
* lifecycle owned by the host.
|
|
10
|
+
*
|
|
11
|
+
* Use {@link useDisplayMode} for non-modal display modes.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const { isOpen, open } = useRequestModal();
|
|
16
|
+
* <button onClick={() => open({ params: { id: 42 } })}>Show details</button>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-modal
|
|
5
20
|
*/
|
|
6
21
|
export function useRequestModal() {
|
|
7
22
|
const adaptor = getAdaptor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,EAEV,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B
|
|
1
|
+
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,EAEV,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,WAAW,CACtB,CAAC,IAAyB,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EACtD,CAAC,OAAO,CAAC,CACV,CAAC;IACF,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,OAAO;QAChC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type RequestModalOptions,\n useHostContext,\n} from \"../bridges/index.js\";\n\n/**\n * Open the current view in a modal overlay (`displayMode === \"modal\"`).\n *\n * Returns `{ isOpen, params, open }`: `open(opts)` triggers the host to render\n * the view in a modal, optionally passing `params` that are surfaced back via\n * `params` here. Useful for confirmation flows, detail panels, or any modal\n * lifecycle owned by the host.\n *\n * Use {@link useDisplayMode} for non-modal display modes.\n *\n * @example\n * ```tsx\n * const { isOpen, open } = useRequestModal();\n * <button onClick={() => open({ params: { id: 42 } })}>Show details</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-modal\n */\nexport function useRequestModal() {\n const adaptor = getAdaptor();\n const display = useHostContext(\"display\");\n const open = useCallback(\n (opts: RequestModalOptions) => adaptor.openModal(opts),\n [adaptor],\n );\n return {\n isOpen: display.mode === \"modal\",\n params: display.params,\n open,\n };\n}\n"]}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
|
|
5
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
3
6
|
import { useRequestModal } from "./use-request-modal.js";
|
|
4
7
|
describe("useRequestModal", () => {
|
|
5
8
|
let requestModalMock;
|
|
6
9
|
beforeEach(() => {
|
|
10
|
+
HostAdaptor.resetInstance();
|
|
11
|
+
McpAppBridge.resetInstance();
|
|
12
|
+
AppsSdkBridge.resetInstance();
|
|
7
13
|
requestModalMock = vi.fn();
|
|
8
14
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
15
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
9
16
|
vi.stubGlobal("openai", {
|
|
10
17
|
requestModal: requestModalMock,
|
|
11
18
|
view: { mode: "inline" },
|
|
@@ -14,6 +21,9 @@ describe("useRequestModal", () => {
|
|
|
14
21
|
afterEach(() => {
|
|
15
22
|
vi.unstubAllGlobals();
|
|
16
23
|
vi.resetAllMocks();
|
|
24
|
+
HostAdaptor.resetInstance();
|
|
25
|
+
McpAppBridge.resetInstance();
|
|
26
|
+
AppsSdkBridge.resetInstance();
|
|
17
27
|
});
|
|
18
28
|
it("should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal", () => {
|
|
19
29
|
const { result } = renderHook(() => useRequestModal());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA0C,CAAC;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,YAAY,EAAE,gBAAgB;YAC9B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.test.ts"],"names":[],"mappings":"AA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UAAU,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;QAC3C,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,YAAY,EAAE,gBAAgB;YAC9B,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE;SAC5C,CAAC,CAAC;QAEH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QACvD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;QAElC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6EAA6E,EAAE,GAAG,EAAE;QACrF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QACvD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;QAEhC,MAAM,OAAO,GAAG;YACd,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;YACtB,QAAQ,EAAE,+BAA+B;SAC1C,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,CAAC;QAEd,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport { useRequestModal } from \"./use-request-modal.js\";\n\ndescribe(\"useRequestModal\", () => {\n let requestModalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n requestModalMock = vi.fn();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"inline\" },\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal\", () => {\n const { result } = renderHook(() => useRequestModal());\n\n expect(typeof result.current).toBe(\"object\");\n expect(result.current).toHaveProperty(\"open\");\n expect(result.current).toHaveProperty(\"isOpen\");\n expect(result.current).toHaveProperty(\"params\");\n\n const { open, isOpen, params } = result.current;\n expect(typeof open).toBe(\"function\");\n expect(isOpen).toBe(false);\n expect(params).toBeUndefined();\n });\n\n it(\"should return isOpen as true when mode is modal\", () => {\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\" },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { isOpen } = result.current;\n\n expect(isOpen).toBe(true);\n });\n\n it(\"should return params from view when available\", () => {\n const testParams = { foo: \"bar\", baz: 42 };\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\", params: testParams },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { params } = result.current;\n\n expect(params).toEqual(testParams);\n });\n\n it(\"should call window.openai.requestModal with the options when open is called\", () => {\n const { result } = renderHook(() => useRequestModal());\n const { open } = result.current;\n\n const options = {\n title: \"Test Modal\",\n params: { foo: \"bar\" },\n template: \"ui://view/modal-template.html\",\n };\n open(options);\n\n expect(requestModalMock).toHaveBeenCalledTimes(1);\n expect(requestModalMock).toHaveBeenCalledWith(options);\n });\n});\n"]}
|