skybridge 0.0.0-dev.ff50fdb → 0.0.0-dev.ffaef7a
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 -114
- package/dist/cli/build-helpers.d.ts +10 -0
- package/dist/cli/build-helpers.js +93 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +89 -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 +68 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +50 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.d.ts +1 -1
- 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/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.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 +16 -0
- package/dist/cli/use-nodemon.js +84 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +131 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +15 -0
- package/dist/cli/use-typescript-check.js +97 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +3 -16
- 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 +5 -1
- package/dist/commands/dev.js +109 -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.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 +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/security-schemes.d.ts +13 -0
- package/dist/server/auth/security-schemes.js +53 -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 +90 -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 +98 -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 +450 -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 +391 -58
- package/dist/server/server.js +644 -97
- 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-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +171 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +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 +330 -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 +208 -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 +32 -14
- 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 +130 -14
- 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 +5 -6
- 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 +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 +35 -2
- package/dist/web/data-llm.js +31 -3
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +50 -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 +6 -2
- package/dist/web/hooks/index.js +5 -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 +34 -1
- package/dist/web/hooks/use-files.js +33 -0
- 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 +16 -1
- package/dist/web/hooks/use-request-modal.js +19 -4
- 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 +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 +30 -16
- 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 +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-widget.js → mount-view.js} +21 -2
- 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 +167 -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 +51 -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 -22
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -64
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -36
- package/dist/web/bridges/mcp-app/adaptor.js +0 -185
- 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.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/build-steps.test.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/web/hooks/test/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,OAAO,kBAAkB;IAC7B,OAAO,KAAU,CAAC;IAClB,SAAS,KAAU,CAAC;IACpB,UAAU,KAAU,CAAC;CACtB;AAED,MAAM,eAAe,GAAqB,EAAE,CAAC;AAO7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,iBAAmC,eAAe,EAClD,UAAiC,EAAE,EACnC,EAAE,CACF,EAAE,CAAC,EAAE,CAAC,CAAC,OAAuC,EAAE,EAAE;IAChD,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,MAAM,MAAM,GAA0B;gBACpC,eAAe,EAAE,YAAY;gBAC7B,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE;gBACjD,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,EAAE;gBAChD,WAAW,EAAE,cAAc;aAC5B,CAAC;YACF,GAAG,CAAC,GAAG,EAAE,CACP,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CAIb,SAAS,EAAE;gBACZ,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,IAAI,EAAE;oBACJ,OAAO,EAAE,KAAK;oBACd,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,MAAM;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AE;YACJ,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,8BAA8B;YACtC,MAAM;SACP;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n McpUiDownloadFileResult,\n McpUiHostCapabilities,\n McpUiHostContext,\n McpUiInitializeResult,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\nimport { fireEvent } from \"@testing-library/react\";\nimport { act } from \"react\";\nimport { vi } from \"vitest\";\n\nexport class MockResizeObserver {\n observe(): void {}\n unobserve(): void {}\n disconnect(): void {}\n}\n\nconst DEFAULT_CONTEXT: McpUiHostContext = {};\n\nexport type McpAppHostMockOptions = {\n hostCapabilities?: McpUiHostCapabilities;\n downloadFileResult?: McpUiDownloadFileResult;\n};\n\nexport const getMcpAppHostPostMessageMock = (\n initialContext: McpUiHostContext = DEFAULT_CONTEXT,\n options: McpAppHostMockOptions = {},\n) =>\n vi.fn((message: { method: string; id: number }) => {\n switch (message.method) {\n case \"ui/initialize\": {\n const result: McpUiInitializeResult = {\n protocolVersion: \"2025-06-18\",\n hostInfo: { name: \"test-host\", version: \"1.0.0\" },\n hostCapabilities: options.hostCapabilities ?? {},\n hostContext: initialContext,\n };\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiInitializeResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result,\n },\n }),\n ),\n );\n break;\n }\n case \"ui/update-model-context\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{ jsonrpc: \"2.0\"; id: number; result: unknown }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: {},\n },\n },\n ),\n ),\n );\n break;\n }\n case \"ui/download-file\": {\n act(() =>\n fireEvent(\n window,\n new MessageEvent<{\n jsonrpc: \"2.0\";\n id: number;\n result: McpUiDownloadFileResult;\n }>(\"message\", {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n id: message.id,\n result: options.downloadFileResult ?? {},\n },\n }),\n ),\n );\n break;\n }\n }\n });\n\nexport const fireToolInputNotification = (args: Record<string, unknown>) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolInputNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-input\",\n params: {\n arguments: args,\n },\n },\n },\n ),\n );\n};\n\nexport const fireToolResultNotification = (params: {\n content: McpUiToolResultNotification[\"params\"][\"content\"];\n structuredContent: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n}) => {\n fireEvent(\n window,\n new MessageEvent<McpUiToolResultNotification & { jsonrpc: \"2.0\" }>(\n \"message\",\n {\n source: window.parent,\n data: {\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-result\",\n params,\n },\n },\n ),\n );\n};\n"]}
|
|
@@ -36,13 +36,26 @@ type CallToolErrorState = {
|
|
|
36
36
|
data: undefined;
|
|
37
37
|
error: unknown;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* State of a {@link useCallTool} invocation, discriminated by `status`.
|
|
41
|
+
* Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.
|
|
42
|
+
*/
|
|
39
43
|
export type CallToolState<TData extends CallToolResponse = CallToolResponse> = CallToolIdleState | CallToolPendingState | CallToolSuccessState<TData> | CallToolErrorState;
|
|
44
|
+
/**
|
|
45
|
+
* Optional callbacks fired around a {@link useCallTool} call.
|
|
46
|
+
* `onSettled` runs after success or error.
|
|
47
|
+
*/
|
|
40
48
|
export type SideEffects<ToolArgs, ToolResponse> = {
|
|
41
49
|
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
42
50
|
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
43
51
|
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
44
52
|
};
|
|
45
53
|
type IsArgsOptional<T> = [T] extends [null] ? true : HasRequiredKeys<T> extends false ? true : false;
|
|
54
|
+
/**
|
|
55
|
+
* Fire-and-forget call function returned by {@link useCallTool}. Tracks state
|
|
56
|
+
* on the hook and supports optional {@link SideEffects} callbacks. Args are
|
|
57
|
+
* optional when the tool accepts none.
|
|
58
|
+
*/
|
|
46
59
|
export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
|
|
47
60
|
(): void;
|
|
48
61
|
(sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
@@ -52,11 +65,43 @@ export type CallToolFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ?
|
|
|
52
65
|
(args: TArgs): void;
|
|
53
66
|
(args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;
|
|
54
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Promise-returning call function returned by {@link useCallTool}. Rejects
|
|
70
|
+
* if the tool errors; use `try/catch` for error handling.
|
|
71
|
+
*/
|
|
55
72
|
export type CallToolAsyncFn<TArgs, TResponse> = IsArgsOptional<TArgs> extends true ? {
|
|
56
73
|
(): Promise<TResponse>;
|
|
57
74
|
(args: TArgs): Promise<TResponse>;
|
|
58
75
|
} : (args: TArgs) => Promise<TResponse>;
|
|
59
76
|
type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
|
|
77
|
+
/**
|
|
78
|
+
* Call a server tool from a view and track its execution state.
|
|
79
|
+
*
|
|
80
|
+
* Returns the current {@link CallToolState} plus two callers: `callTool`
|
|
81
|
+
* (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
|
|
82
|
+
* (promise-returning). If the same instance is invoked again while a call is
|
|
83
|
+
* in flight, the older response is dropped from the rendered state (but any
|
|
84
|
+
* `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
|
|
85
|
+
*
|
|
86
|
+
* Pair with {@link useToolInfo} to read the result of the tool invocation
|
|
87
|
+
* that produced the current view. For end-to-end type safety across tool
|
|
88
|
+
* inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
|
|
89
|
+
* over calling this hook directly.
|
|
90
|
+
*
|
|
91
|
+
* @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
|
|
92
|
+
* @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
|
|
97
|
+
*
|
|
98
|
+
* <button onClick={() => callTool({ query: "skybridge" }, {
|
|
99
|
+
* onSuccess: (res) => console.log(res.structuredContent),
|
|
100
|
+
* })} />
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @see https://docs.skybridge.tech/api-reference/use-call-tool
|
|
104
|
+
*/
|
|
60
105
|
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>>(name: string) => {
|
|
61
106
|
callTool: CallToolFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
62
107
|
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
2
|
import { getAdaptor, } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Call a server tool from a view and track its execution state.
|
|
5
|
+
*
|
|
6
|
+
* Returns the current {@link CallToolState} plus two callers: `callTool`
|
|
7
|
+
* (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`
|
|
8
|
+
* (promise-returning). If the same instance is invoked again while a call is
|
|
9
|
+
* in flight, the older response is dropped from the rendered state (but any
|
|
10
|
+
* `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).
|
|
11
|
+
*
|
|
12
|
+
* Pair with {@link useToolInfo} to read the result of the tool invocation
|
|
13
|
+
* that produced the current view. For end-to-end type safety across tool
|
|
14
|
+
* inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}
|
|
15
|
+
* over calling this hook directly.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).
|
|
18
|
+
* @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const { callTool, isPending, data } = useCallTool<{ query: string }>("search");
|
|
23
|
+
*
|
|
24
|
+
* <button onClick={() => callTool({ query: "skybridge" }, {
|
|
25
|
+
* onSuccess: (res) => console.log(res.structuredContent),
|
|
26
|
+
* })} />
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see https://docs.skybridge.tech/api-reference/use-call-tool
|
|
30
|
+
*/
|
|
3
31
|
export const useCallTool = (name) => {
|
|
4
32
|
const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
|
|
5
33
|
const callIdRef = useRef(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA4G7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IAGF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB,CAAC,GAAG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\nimport {\n type CallToolArgs,\n type CallToolResponse,\n getAdaptor,\n} from \"../bridges/index.js\";\nimport type { HasRequiredKeys } from \"../types.js\";\n\ntype CallToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolPendingState = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n isError: false;\n data: undefined;\n error: undefined;\n};\n\ntype CallToolSuccessState<TData extends CallToolResponse = CallToolResponse> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n isError: false;\n data: TData;\n error: undefined;\n};\n\ntype CallToolErrorState = {\n status: \"error\";\n isIdle: false;\n isPending: false;\n isSuccess: false;\n isError: true;\n data: undefined;\n error: unknown;\n};\n\n/**\n * State of a {@link useCallTool} invocation, discriminated by `status`.\n * Use `isIdle` / `isPending` / `isSuccess` / `isError` for ergonomic conditional rendering.\n */\nexport type CallToolState<TData extends CallToolResponse = CallToolResponse> =\n | CallToolIdleState\n | CallToolPendingState\n | CallToolSuccessState<TData>\n | CallToolErrorState;\n\n/**\n * Optional callbacks fired around a {@link useCallTool} call.\n * `onSettled` runs after success or error.\n */\nexport type SideEffects<ToolArgs, ToolResponse> = {\n onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;\n onError?: (error: unknown, toolArgs: ToolArgs) => void;\n onSettled?: (\n data: ToolResponse | undefined,\n error: unknown | undefined,\n toolArgs: ToolArgs,\n ) => void;\n};\n\ntype IsArgsOptional<T> = [T] extends [null]\n ? true\n : HasRequiredKeys<T> extends false\n ? true\n : false;\n\n/**\n * Fire-and-forget call function returned by {@link useCallTool}. Tracks state\n * on the hook and supports optional {@link SideEffects} callbacks. Args are\n * optional when the tool accepts none.\n */\nexport type CallToolFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): void;\n (sideEffects: SideEffects<TArgs, TResponse>): void;\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n }\n : {\n (args: TArgs): void;\n (args: TArgs, sideEffects: SideEffects<TArgs, TResponse>): void;\n };\n\n/**\n * Promise-returning call function returned by {@link useCallTool}. Rejects\n * if the tool errors; use `try/catch` for error handling.\n */\nexport type CallToolAsyncFn<TArgs, TResponse> =\n IsArgsOptional<TArgs> extends true\n ? {\n (): Promise<TResponse>;\n (args: TArgs): Promise<TResponse>;\n }\n : (args: TArgs) => Promise<TResponse>;\n\ntype ToolResponseSignature = Pick<\n CallToolResponse,\n \"structuredContent\" | \"meta\"\n>;\n\n/**\n * Call a server tool from a view and track its execution state.\n *\n * Returns the current {@link CallToolState} plus two callers: `callTool`\n * (fire-and-forget, with optional {@link SideEffects}) and `callToolAsync`\n * (promise-returning). If the same instance is invoked again while a call is\n * in flight, the older response is dropped from the rendered state (but any\n * `onSuccess` / `onError` / `onSettled` callbacks attached to it still fire).\n *\n * Pair with {@link useToolInfo} to read the result of the tool invocation\n * that produced the current view. For end-to-end type safety across tool\n * inputs and outputs, prefer the typed helpers produced by {@link generateHelpers}\n * over calling this hook directly.\n *\n * @typeParam ToolArgs - Shape of the tool's input args (`null` for no-arg tools).\n * @typeParam ToolResponse - Shape of the tool's `structuredContent` / `meta`.\n *\n * @example\n * ```tsx\n * const { callTool, isPending, data } = useCallTool<{ query: string }>(\"search\");\n *\n * <button onClick={() => callTool({ query: \"skybridge\" }, {\n * onSuccess: (res) => console.log(res.structuredContent),\n * })} />\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-call-tool\n */\nexport const useCallTool = <\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends Partial<ToolResponseSignature> = Record<string, never>,\n>(\n name: string,\n) => {\n type CombinedCallToolResponse = CallToolResponse & ToolResponse;\n\n const [{ status, data, error }, setCallToolState] = useState<\n Omit<\n CallToolState<CombinedCallToolResponse>,\n \"isIdle\" | \"isPending\" | \"isSuccess\" | \"isError\"\n >\n >({ status: \"idle\", data: undefined, error: undefined });\n\n const callIdRef = useRef(0);\n const adaptor = getAdaptor();\n\n const execute = async (\n toolArgs: ToolArgs,\n ): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({ status: \"pending\", data: undefined, error: undefined });\n\n try {\n const data = await adaptor.callTool<ToolArgs, CombinedCallToolResponse>(\n name,\n toolArgs,\n );\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"success\", data, error: undefined });\n }\n\n return data;\n } catch (error) {\n if (callId === callIdRef.current) {\n setCallToolState({ status: \"error\", data: undefined, error });\n }\n throw error;\n }\n };\n\n const callToolAsync = ((toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n }) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = ((\n firstArg?: ToolArgs | SideEffects<ToolArgs, CombinedCallToolResponse>,\n sideEffects?: SideEffects<ToolArgs, CombinedCallToolResponse>,\n ) => {\n let toolArgs: ToolArgs;\n if (\n firstArg &&\n typeof firstArg === \"object\" &&\n (\"onSuccess\" in firstArg ||\n \"onError\" in firstArg ||\n \"onSettled\" in firstArg)\n ) {\n toolArgs = null as ToolArgs; // no toolArgs provided\n sideEffects = firstArg;\n } else {\n toolArgs = (firstArg === undefined ? null : firstArg) as ToolArgs;\n }\n\n execute(toolArgs)\n .then((data) => {\n sideEffects?.onSuccess?.(data, toolArgs);\n sideEffects?.onSettled?.(data, undefined, toolArgs);\n })\n .catch((error) => {\n sideEffects?.onError?.(error, toolArgs);\n sideEffects?.onSettled?.(undefined, error, toolArgs);\n });\n }) as CallToolFn<ToolArgs, CombinedCallToolResponse>;\n\n const callToolState = {\n status,\n data,\n error,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n isError: status === \"error\",\n } as CallToolState<CombinedCallToolResponse>;\n\n return {\n ...callToolState,\n callTool,\n callToolAsync,\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
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AAC;AACxD,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport {\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\n\ntest(\"callTool can be called without args when ToolArgs is null\", () => {\n const { callTool, callToolAsync } = useCallTool<null>(\"test-tool\");\n callTool();\n callTool({ onSuccess: () => {} });\n callToolAsync();\n});\n\ntest(\"callTool requires args when ToolArgs has required properties\", () => {\n type Args = { query: string };\n const { callTool, callToolAsync } = useCallTool<Args>(\"test-tool\");\n\n // @ts-expect-error - query is required\n callTool();\n\n callTool({ query: \"test\" });\n callTool({ query: \"test\" }, { onSuccess: () => {} });\n\n // @ts-expect-error - query is required\n callToolAsync();\n callToolAsync({ query: \"test\" });\n});\n\ntest(\"callTool supports sideEffects with correct types\", () => {\n type Args = { id: number };\n type Response = { structuredContent: { result: string } };\n\n const { callTool } = useCallTool<Args, Response>(\"test-tool\");\n\n callTool(\n { id: 1 },\n {\n onSuccess: (data, args) => {\n expectTypeOf(data.structuredContent.result).toBeString();\n expectTypeOf(args.id).toBeNumber();\n },\n onError: (error, args) => {\n expectTypeOf(error).toBeUnknown();\n expectTypeOf(args.id).toBeNumber();\n },\n onSettled: (data, error, args) => {\n if (data) {\n expectTypeOf(data.structuredContent.result).toBeString();\n }\n expectTypeOf(error).toEqualTypeOf<unknown | undefined>();\n expectTypeOf(args.id).toBeNumber();\n },\n },\n );\n});\n\ntest(\"callTool allows sideEffects as first arg when ToolArgs is null\", () => {\n type Response = { structuredContent: { value: number } };\n const { callTool } = useCallTool<null, Response>(\"test-tool\");\n\n callTool({\n onSuccess: (data) => {\n expectTypeOf(data.structuredContent.value).toBeNumber();\n },\n });\n});\n\ntest(\"callToolAsync returns correctly typed promise\", () => {\n type Args = { name: string };\n type Response = {\n structuredContent: { greeting: string };\n meta: { id: number };\n };\n\n const { callToolAsync } = useCallTool<Args, Response>(\"test-tool\");\n\n const promise = callToolAsync({ name: \"test\" });\n\n expectTypeOf(promise).resolves.toHaveProperty(\"structuredContent\");\n expectTypeOf(promise).resolves.toHaveProperty(\"meta\");\n});\n\ntest(\"state narrowing works correctly with status\", () => {\n type Response = { structuredContent: { data: string } };\n const result = useCallTool<null, Response>(\"test-tool\");\n\n if (result.status === \"idle\") {\n expectTypeOf(result.isIdle).toEqualTypeOf<true>();\n expectTypeOf(result.data).toEqualTypeOf<undefined>();\n }\n\n if (result.status === \"pending\") {\n expectTypeOf(result.isPending).toEqualTypeOf<true>();\n expectTypeOf(result.data).toEqualTypeOf<undefined>();\n }\n\n if (result.status === \"success\") {\n expectTypeOf(result.isSuccess).toEqualTypeOf<true>();\n expectTypeOf(result.data).not.toEqualTypeOf<undefined>();\n expectTypeOf(result.data.structuredContent.data).toBeString();\n }\n\n if (result.status === \"error\") {\n expectTypeOf(result.isError).toEqualTypeOf<true>();\n expectTypeOf(result.error).toBeUnknown();\n }\n});\n\ntest(\"state narrowing works correctly with boolean flags\", () => {\n type Response = { structuredContent: { items: string[] } };\n const result = useCallTool<null, Response>(\"test-tool\");\n\n if (result.isIdle) {\n expectTypeOf(result.status).toEqualTypeOf<\"idle\">();\n }\n\n if (result.isPending) {\n expectTypeOf(result.status).toEqualTypeOf<\"pending\">();\n }\n\n if (result.isSuccess) {\n expectTypeOf(result.status).toEqualTypeOf<\"success\">();\n expectTypeOf(result.data.structuredContent.items).toBeArray();\n }\n\n if (result.isError) {\n expectTypeOf(result.status).toEqualTypeOf<\"error\">();\n }\n});\n\ntest(\"CallToolState type is correctly exported and usable\", () => {\n type Response = { structuredContent: { foo: string } };\n type MyState = CallToolState<CallToolResponse & Response>;\n\n const state: MyState = {} as MyState;\n\n if (state.status === \"success\") {\n expectTypeOf(state.data.structuredContent.foo).toBeString();\n }\n});\n\ntest(\"SideEffects type is correctly exported and usable\", () => {\n type Args = { x: number };\n type Response = CallToolResponse & { structuredContent: { y: string } };\n\n const sideEffects: SideEffects<Args, Response> = {\n onSuccess: (data, args) => {\n expectTypeOf(data.structuredContent.y).toBeString();\n expectTypeOf(args.x).toBeNumber();\n },\n };\n\n expectTypeOf(sideEffects).toHaveProperty(\"onSuccess\");\n});\n"]}
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi, } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { AppsSdkBridge } from "../bridges/apps-sdk/bridge.js";
|
|
5
|
+
import { getAdaptor } from "../bridges/get-adaptor.js";
|
|
6
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
3
7
|
import { useCallTool } from "./use-call-tool.js";
|
|
4
8
|
describe("useCallTool - onSuccess callback", () => {
|
|
5
|
-
let
|
|
9
|
+
let callToolMock;
|
|
6
10
|
beforeEach(() => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
vi.stubGlobal("
|
|
11
|
+
HostAdaptor.resetInstance();
|
|
12
|
+
McpAppBridge.resetInstance();
|
|
13
|
+
AppsSdkBridge.resetInstance();
|
|
14
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
11
15
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
16
|
+
vi.stubGlobal("openai", { callTool: vi.fn() });
|
|
17
|
+
callToolMock = vi.spyOn(getAdaptor(), "callTool");
|
|
12
18
|
});
|
|
13
19
|
afterEach(() => {
|
|
14
20
|
vi.unstubAllGlobals();
|
|
15
21
|
vi.resetAllMocks();
|
|
22
|
+
HostAdaptor.resetInstance();
|
|
23
|
+
McpAppBridge.resetInstance();
|
|
24
|
+
AppsSdkBridge.resetInstance();
|
|
16
25
|
});
|
|
17
26
|
const toolName = "test-tool";
|
|
18
27
|
const args = { input: "test input" };
|
|
@@ -20,20 +29,38 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
20
29
|
content: [{ type: "text", text: "test result" }],
|
|
21
30
|
structuredContent: { result: "test" },
|
|
22
31
|
isError: false,
|
|
23
|
-
|
|
32
|
+
meta: {},
|
|
24
33
|
};
|
|
25
34
|
const error = new Error("test error");
|
|
26
|
-
it("should
|
|
35
|
+
it("should normalize _meta to meta when SDK returns _meta instead of meta", async () => {
|
|
36
|
+
const rawSdkResponse = {
|
|
37
|
+
content: [{ type: "text", text: "result" }],
|
|
38
|
+
structuredContent: { value: 1 },
|
|
39
|
+
isError: false,
|
|
40
|
+
meta: { secret: "only visible to widget" },
|
|
41
|
+
};
|
|
42
|
+
callToolMock.mockResolvedValueOnce(rawSdkResponse);
|
|
43
|
+
const { result } = renderHook(() => useCallTool(toolName));
|
|
44
|
+
await act(async () => {
|
|
45
|
+
result.current.callTool(args);
|
|
46
|
+
});
|
|
47
|
+
await waitFor(() => {
|
|
48
|
+
expect(result.current.data).toMatchObject({
|
|
49
|
+
meta: { secret: "only visible to widget" },
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it("should call adaptor.callTool with correct arguments", async () => {
|
|
27
54
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
28
55
|
await act(async () => {
|
|
29
56
|
result.current.callTool(args);
|
|
30
57
|
});
|
|
31
|
-
expect(
|
|
58
|
+
expect(callToolMock).toHaveBeenCalledWith(toolName, args);
|
|
32
59
|
});
|
|
33
60
|
it("should call onSuccess callback with correct data and toolArgs on successful execution", async () => {
|
|
34
61
|
const onSuccess = vi.fn();
|
|
35
62
|
const onError = vi.fn();
|
|
36
|
-
|
|
63
|
+
callToolMock.mockResolvedValueOnce(data);
|
|
37
64
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
38
65
|
act(() => {
|
|
39
66
|
result.current.callTool(args, {
|
|
@@ -49,7 +76,7 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
49
76
|
it("should call onError callback with error and toolArgs on failed execution", async () => {
|
|
50
77
|
const onSuccess = vi.fn();
|
|
51
78
|
const onError = vi.fn();
|
|
52
|
-
|
|
79
|
+
callToolMock.mockRejectedValueOnce(error);
|
|
53
80
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
54
81
|
act(() => {
|
|
55
82
|
result.current.callTool(args, {
|
|
@@ -66,7 +93,7 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
66
93
|
const onSuccess = vi.fn();
|
|
67
94
|
const onError = vi.fn();
|
|
68
95
|
const onSettled = vi.fn();
|
|
69
|
-
|
|
96
|
+
callToolMock.mockResolvedValueOnce(data);
|
|
70
97
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
71
98
|
act(() => {
|
|
72
99
|
result.current.callTool(args, {
|
|
@@ -85,7 +112,7 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
85
112
|
const onSuccess = vi.fn();
|
|
86
113
|
const onError = vi.fn();
|
|
87
114
|
const onSettled = vi.fn();
|
|
88
|
-
|
|
115
|
+
callToolMock.mockRejectedValueOnce(error);
|
|
89
116
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
90
117
|
act(() => {
|
|
91
118
|
result.current.callTool(args, {
|
|
@@ -102,11 +129,17 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
102
129
|
});
|
|
103
130
|
it("should always return last call started state", async () => {
|
|
104
131
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
105
|
-
const firstCallData = {
|
|
106
|
-
|
|
132
|
+
const firstCallData = {
|
|
133
|
+
...data,
|
|
134
|
+
structuredContent: { result: "first call result" },
|
|
135
|
+
};
|
|
136
|
+
const secondCallData = {
|
|
137
|
+
...data,
|
|
138
|
+
structuredContent: { result: "second call result" },
|
|
139
|
+
};
|
|
107
140
|
const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } = Promise.withResolvers();
|
|
108
141
|
const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } = Promise.withResolvers();
|
|
109
|
-
|
|
142
|
+
callToolMock
|
|
110
143
|
.mockImplementationOnce(() => firstCallToolPromise)
|
|
111
144
|
.mockImplementationOnce(() => secondCallToolPromise);
|
|
112
145
|
await act(() => {
|
|
@@ -125,17 +158,22 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
125
158
|
});
|
|
126
159
|
});
|
|
127
160
|
describe("useCallTool - TypeScript typing", () => {
|
|
128
|
-
let
|
|
161
|
+
let callToolMock;
|
|
129
162
|
beforeEach(() => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
vi.stubGlobal("
|
|
163
|
+
HostAdaptor.resetInstance();
|
|
164
|
+
McpAppBridge.resetInstance();
|
|
165
|
+
AppsSdkBridge.resetInstance();
|
|
166
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
134
167
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
168
|
+
vi.stubGlobal("openai", { callTool: vi.fn() });
|
|
169
|
+
callToolMock = vi.spyOn(getAdaptor(), "callTool");
|
|
135
170
|
});
|
|
136
171
|
afterEach(() => {
|
|
137
172
|
vi.unstubAllGlobals();
|
|
138
173
|
vi.resetAllMocks();
|
|
174
|
+
HostAdaptor.resetInstance();
|
|
175
|
+
McpAppBridge.resetInstance();
|
|
176
|
+
AppsSdkBridge.resetInstance();
|
|
139
177
|
});
|
|
140
178
|
it("should have correct return types when ToolArgs is null and ToolResponse is specified", async () => {
|
|
141
179
|
const { result } = renderHook(() => useCallTool("test-tool"));
|
|
@@ -143,14 +181,13 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
143
181
|
content: [{ type: "text", text: "test" }],
|
|
144
182
|
structuredContent: { result: "test" },
|
|
145
183
|
isError: false,
|
|
146
|
-
result: "test",
|
|
147
184
|
meta: { id: 123 },
|
|
148
185
|
};
|
|
149
|
-
|
|
186
|
+
callToolMock.mockResolvedValueOnce(data);
|
|
150
187
|
await act(async () => {
|
|
151
188
|
result.current.callTool();
|
|
152
189
|
});
|
|
153
|
-
expect(
|
|
190
|
+
expect(callToolMock).toHaveBeenCalledWith("test-tool", null);
|
|
154
191
|
expectTypeOf(result.current.data);
|
|
155
192
|
});
|
|
156
193
|
it("should correctly type callToolAsync return value", async () => {
|
|
@@ -160,10 +197,9 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
160
197
|
content: [{ type: "text", text: "answer" }],
|
|
161
198
|
structuredContent: { answer: "test answer" },
|
|
162
199
|
isError: false,
|
|
163
|
-
result: "answer",
|
|
164
200
|
meta: {},
|
|
165
201
|
};
|
|
166
|
-
|
|
202
|
+
callToolMock.mockResolvedValueOnce(mockResponse);
|
|
167
203
|
const returnedValue = await act(async () => {
|
|
168
204
|
return result.current.callToolAsync(testArgs);
|
|
169
205
|
});
|
|
@@ -176,10 +212,9 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
176
212
|
content: [{ type: "text", text: "data" }],
|
|
177
213
|
structuredContent: { data: "test data" },
|
|
178
214
|
isError: false,
|
|
179
|
-
result: "data",
|
|
180
215
|
meta: {},
|
|
181
216
|
};
|
|
182
|
-
|
|
217
|
+
callToolMock.mockResolvedValueOnce(mockResponse);
|
|
183
218
|
const returnedValue = await act(async () => {
|
|
184
219
|
return result.current.callToolAsync();
|
|
185
220
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,UAA8B,CAAC;IAEnC,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,QAAQ,EAAE,EAAE,CAAC,EAA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,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CACjC,WAAW,CAAqB,WAAW,CAAC,CAC7C,CAAC;QAEF,MAAM,YAAY,GAAiB;YACjC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAClD,iBAAiB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACxC,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;SACT,CAAC;QAEF,YAAY,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAEjD,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACzC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,CAAC,CAAC,CAAC;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, renderHook, waitFor } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n expectTypeOf,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { AppsSdkBridge } from \"../bridges/apps-sdk/bridge.js\";\nimport { getAdaptor } from \"../bridges/get-adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { CallToolResponse } from \"../bridges/types.js\";\nimport { useCallTool } from \"./use-call-tool.js\";\n\ndescribe(\"useCallTool - onSuccess callback\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n const toolName = \"test-tool\";\n const args = { input: \"test input\" };\n const data: CallToolResponse = {\n content: [{ type: \"text\" as const, text: \"test result\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: {},\n };\n const error = new Error(\"test error\");\n\n it(\"should normalize _meta to meta when SDK returns _meta instead of meta\", async () => {\n const rawSdkResponse = {\n content: [{ type: \"text\" as const, text: \"result\" }],\n structuredContent: { value: 1 },\n isError: false,\n meta: { secret: \"only visible to widget\" },\n };\n callToolMock.mockResolvedValueOnce(rawSdkResponse);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n await act(async () => {\n result.current.callTool(args);\n });\n\n await waitFor(() => {\n expect(result.current.data).toMatchObject({\n meta: { secret: \"only visible to widget\" },\n });\n });\n });\n\n it(\"should call adaptor.callTool with correct arguments\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n await act(async () => {\n result.current.callTool(args);\n });\n expect(callToolMock).toHaveBeenCalledWith(toolName, args);\n });\n\n it(\"should call onSuccess callback with correct data and toolArgs on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onError callback with error and toolArgs on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).not.toHaveBeenCalled();\n expect(onError).toHaveBeenCalledWith(error, args);\n });\n });\n\n it(\"should call onSettled callback with data and undefined error on successful execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockResolvedValueOnce(data);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onSuccess).toHaveBeenCalledWith(data, args);\n expect(onSettled).toHaveBeenCalledWith(data, undefined, args);\n expect(onError).not.toHaveBeenCalled();\n });\n });\n\n it(\"should call onSettled callback with undefined data and error on failed execution\", async () => {\n const onSuccess = vi.fn();\n const onError = vi.fn();\n const onSettled = vi.fn();\n callToolMock.mockRejectedValueOnce(error);\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n act(() => {\n result.current.callTool(args, {\n onSuccess,\n onError,\n onSettled,\n });\n });\n\n await waitFor(() => {\n expect(onError).toHaveBeenCalledWith(error, args);\n expect(onSettled).toHaveBeenCalledWith(undefined, error, args);\n expect(onSuccess).not.toHaveBeenCalled();\n });\n });\n\n it(\"should always return last call started state\", async () => {\n const { result } = renderHook(() =>\n useCallTool<typeof args, typeof data>(toolName),\n );\n\n const firstCallData = {\n ...data,\n structuredContent: { result: \"first call result\" },\n };\n const secondCallData = {\n ...data,\n structuredContent: { result: \"second call result\" },\n };\n const { promise: firstCallToolPromise, resolve: resolveFirstCallTool } =\n Promise.withResolvers();\n const { promise: secondCallToolPromise, resolve: resolveSecondCallTool } =\n Promise.withResolvers();\n callToolMock\n .mockImplementationOnce(() => firstCallToolPromise)\n .mockImplementationOnce(() => secondCallToolPromise);\n\n await act(() => {\n result.current.callTool(args);\n result.current.callTool(args);\n resolveFirstCallTool(firstCallData);\n return firstCallToolPromise;\n });\n\n expect(result.current.status).toEqual(\"pending\");\n expect(result.current.data).toEqual(undefined);\n resolveSecondCallTool(secondCallData);\n\n await waitFor(() => {\n expect(result.current.status).toEqual(\"success\");\n expect(result.current.data).toEqual(secondCallData);\n });\n });\n});\n\ndescribe(\"useCallTool - TypeScript typing\", () => {\n let callToolMock: Mock;\n\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", { callTool: vi.fn() });\n callToolMock = vi.spyOn(getAdaptor(), \"callTool\") as unknown as Mock;\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n AppsSdkBridge.resetInstance();\n });\n\n it(\"should have correct return types when ToolArgs is null and ToolResponse is specified\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { result: string };\n meta: { id: number };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n const data: TestResponse = {\n content: [{ type: \"text\" as const, text: \"test\" }],\n structuredContent: { result: \"test\" },\n isError: false,\n meta: { id: 123 },\n };\n\n callToolMock.mockResolvedValueOnce(data);\n\n await act(async () => {\n result.current.callTool();\n });\n\n expect(callToolMock).toHaveBeenCalledWith(\"test-tool\", null);\n expectTypeOf<typeof data | undefined>(result.current.data);\n });\n\n it(\"should correctly type callToolAsync return value\", async () => {\n type TestArgs = { query: string };\n type TestResponse = CallToolResponse & {\n structuredContent: { answer: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<TestArgs, TestResponse>(\"test-tool\"),\n );\n\n const testArgs: TestArgs = { query: \"test\" };\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"answer\" }],\n structuredContent: { answer: \"test answer\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync(testArgs);\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n\n it(\"should correctly type callToolAsync when ToolArgs is null\", async () => {\n type TestResponse = CallToolResponse & {\n structuredContent: { data: string };\n };\n\n const { result } = renderHook(() =>\n useCallTool<null, TestResponse>(\"test-tool\"),\n );\n\n const mockResponse: TestResponse = {\n content: [{ type: \"text\" as const, text: \"data\" }],\n structuredContent: { data: \"test data\" },\n isError: false,\n meta: {},\n };\n\n callToolMock.mockResolvedValueOnce(mockResponse);\n\n const returnedValue = await act(async () => {\n return result.current.callToolAsync();\n });\n expectTypeOf<typeof mockResponse>(returnedValue);\n expect(returnedValue).toEqual(mockResponse);\n });\n});\n"]}
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { RequestDisplayMode } from "../bridges/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
|
|
4
|
+
*
|
|
5
|
+
* Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
|
|
6
|
+
* host to switch modes — the host returns the mode it actually applied, which
|
|
7
|
+
* may differ from the request. The reported value also updates when the host
|
|
8
|
+
* changes the mode on its own (e.g. user expands the widget).
|
|
9
|
+
*
|
|
10
|
+
* `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
|
|
11
|
+
* to layout changes that come with display-mode switches (e.g. `maxHeight`),
|
|
12
|
+
* pair with {@link useLayout}.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const [mode, setMode] = useDisplayMode();
|
|
17
|
+
* <button onClick={() => setMode("fullscreen")}>Expand</button>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see https://docs.skybridge.tech/api-reference/use-display-mode
|
|
21
|
+
*/
|
|
22
|
+
export declare function useDisplayMode(): readonly [import("../index.js").DisplayMode, (mode: RequestDisplayMode) => Promise<{
|
|
23
|
+
mode: RequestDisplayMode;
|
|
4
24
|
}>];
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor, useHostContext } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Read and change the view's display mode (`"inline"`, `"pip"`, `"fullscreen"`).
|
|
5
|
+
*
|
|
6
|
+
* Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the
|
|
7
|
+
* host to switch modes — the host returns the mode it actually applied, which
|
|
8
|
+
* may differ from the request. The reported value also updates when the host
|
|
9
|
+
* changes the mode on its own (e.g. user expands the widget).
|
|
10
|
+
*
|
|
11
|
+
* `"modal"` is reachable via {@link useRequestModal}, not this hook. To react
|
|
12
|
+
* to layout changes that come with display-mode switches (e.g. `maxHeight`),
|
|
13
|
+
* pair with {@link useLayout}.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const [mode, setMode] = useDisplayMode();
|
|
18
|
+
* <button onClick={() => setMode("fullscreen")}>Expand</button>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @see https://docs.skybridge.tech/api-reference/use-display-mode
|
|
22
|
+
*/
|
|
3
23
|
export function useDisplayMode() {
|
|
4
24
|
const displayMode = useHostContext("displayMode");
|
|
5
25
|
const adaptor = getAdaptor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,
|
|
1
|
+
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,IAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC9D,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\n\n/**\n * Read and change the view's display mode (`\"inline\"`, `\"pip\"`, `\"fullscreen\"`).\n *\n * Returns a tuple `[displayMode, setDisplayMode]`. `setDisplayMode` asks the\n * host to switch modes — the host returns the mode it actually applied, which\n * may differ from the request. The reported value also updates when the host\n * changes the mode on its own (e.g. user expands the widget).\n *\n * `\"modal\"` is reachable via {@link useRequestModal}, not this hook. To react\n * to layout changes that come with display-mode switches (e.g. `maxHeight`),\n * pair with {@link useLayout}.\n *\n * @example\n * ```tsx\n * const [mode, setMode] = useDisplayMode();\n * <button onClick={() => setMode(\"fullscreen\")}>Expand</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-display-mode\n */\nexport function useDisplayMode() {\n const displayMode = useHostContext(\"displayMode\");\n const adaptor = getAdaptor();\n const setDisplayMode = useCallback(\n (mode: RequestDisplayMode) => adaptor.requestDisplayMode(mode),\n [adaptor],\n );\n\n return [displayMode, setDisplayMode] as const;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
test("setDisplayMode only accepts requestable display modes", () => {
|
|
3
|
+
expectTypeOf().toEqualTypeOf();
|
|
4
|
+
// @ts-expect-error "modal" is a host state, not a valid request mode
|
|
5
|
+
const _invalidMode = "modal";
|
|
6
|
+
void _invalidMode;
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=use-display-mode.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-display-mode.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-display-mode.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAI5C,IAAI,CAAC,uDAAuD,EAAE,GAAG,EAAE;IAGjE,YAAY,EAET,CAAC,aAAa,EAAsB,CAAC;IAExC,qEAAqE;IACrE,MAAM,YAAY,GAAkC,OAAO,CAAC;IAC5D,KAAK,YAAY,CAAC;AACpB,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport type { RequestDisplayMode } from \"../bridges/types.js\";\nimport type { useDisplayMode } from \"./use-display-mode.js\";\n\ntest(\"setDisplayMode only accepts requestable display modes\", () => {\n type SetDisplayMode = ReturnType<typeof useDisplayMode>[1];\n\n expectTypeOf<\n Parameters<SetDisplayMode>[0]\n >().toEqualTypeOf<RequestDisplayMode>();\n\n // @ts-expect-error \"modal\" is a host state, not a valid request mode\n const _invalidMode: Parameters<SetDisplayMode>[0] = \"modal\";\n void _invalidMode;\n});\n"]}
|
|
@@ -1,39 +1,75 @@
|
|
|
1
|
-
import { act, renderHook } from "@testing-library/react";
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi
|
|
1
|
+
import { act, fireEvent, renderHook, waitFor } from "@testing-library/react";
|
|
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 { getAdaptor } from "../bridges/get-adaptor.js";
|
|
6
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
7
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
3
8
|
import { useDisplayMode } from "./use-display-mode.js";
|
|
4
9
|
describe("useDisplayMode", () => {
|
|
5
|
-
let OpenaiMock;
|
|
6
10
|
beforeEach(() => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
+
HostAdaptor.resetInstance();
|
|
12
|
+
McpAppBridge.resetInstance();
|
|
13
|
+
AppsSdkBridge.resetInstance();
|
|
12
14
|
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
15
|
+
vi.stubGlobal("openai", { view: { mode: "inline" } });
|
|
16
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
13
17
|
});
|
|
14
18
|
afterEach(() => {
|
|
15
19
|
vi.unstubAllGlobals();
|
|
16
20
|
vi.resetAllMocks();
|
|
21
|
+
HostAdaptor.resetInstance();
|
|
22
|
+
McpAppBridge.resetInstance();
|
|
23
|
+
AppsSdkBridge.resetInstance();
|
|
17
24
|
});
|
|
18
|
-
it("should return the current display mode from
|
|
19
|
-
|
|
25
|
+
it("should return the current display mode from MCP host context", async () => {
|
|
26
|
+
vi.stubGlobal("parent", {
|
|
27
|
+
postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
|
|
28
|
+
});
|
|
20
29
|
const { result } = renderHook(() => useDisplayMode());
|
|
21
|
-
|
|
30
|
+
await waitFor(() => {
|
|
31
|
+
expect(result.current[0]).toBe("inline");
|
|
32
|
+
});
|
|
22
33
|
});
|
|
23
|
-
it("should
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
it("should update display mode on host-context-changed notification", async () => {
|
|
35
|
+
vi.stubGlobal("parent", {
|
|
36
|
+
postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
|
|
37
|
+
});
|
|
38
|
+
const { result } = renderHook(() => useDisplayMode());
|
|
39
|
+
await waitFor(() => {
|
|
40
|
+
expect(result.current[0]).toBe("inline");
|
|
41
|
+
});
|
|
42
|
+
act(() => {
|
|
43
|
+
fireEvent(window, new MessageEvent("message", {
|
|
44
|
+
source: window.parent,
|
|
45
|
+
data: {
|
|
46
|
+
jsonrpc: "2.0",
|
|
47
|
+
method: "ui/notifications/host-context-changed",
|
|
48
|
+
params: { displayMode: "fullscreen" },
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
await waitFor(() => {
|
|
53
|
+
expect(result.current[0]).toBe("fullscreen");
|
|
54
|
+
});
|
|
30
55
|
});
|
|
31
|
-
it("should call
|
|
56
|
+
it("should call requestDisplayMode on the adaptor when setDisplayMode is called", async () => {
|
|
57
|
+
vi.stubGlobal("parent", {
|
|
58
|
+
postMessage: getMcpAppHostPostMessageMock({ displayMode: "inline" }),
|
|
59
|
+
});
|
|
32
60
|
const { result } = renderHook(() => useDisplayMode());
|
|
61
|
+
await waitFor(() => expect(result.current[0]).toBe("inline"));
|
|
62
|
+
// Patch mcp.getApp to avoid real protocol request
|
|
63
|
+
const adaptor = getAdaptor();
|
|
64
|
+
const fakeApp = {
|
|
65
|
+
requestDisplayMode: vi.fn().mockResolvedValue({ mode: "fullscreen" }),
|
|
66
|
+
};
|
|
67
|
+
// biome-ignore lint/suspicious/noExplicitAny: test seam
|
|
68
|
+
adaptor.mcp.getApp = vi.fn().mockResolvedValue(fakeApp);
|
|
33
69
|
await act(async () => {
|
|
34
70
|
await result.current[1]("fullscreen");
|
|
35
71
|
});
|
|
36
|
-
expect(
|
|
72
|
+
expect(fakeApp.requestDisplayMode).toHaveBeenCalledWith({
|
|
37
73
|
mode: "fullscreen",
|
|
38
74
|
});
|
|
39
75
|
});
|