skybridge 0.0.0-dev.efb7a49 → 0.0.0-dev.efba8c5
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 +126 -128
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +107 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +132 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +73 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +8 -20
- package/dist/cli/detect-port.js.map +1 -1
- 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-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.js +39 -0
- package/dist/cli/tunnel-control-server.test.js.map +1 -0
- package/dist/cli/tunnel-handler.d.ts +3 -0
- package/dist/cli/tunnel-handler.js +48 -0
- package/dist/cli/tunnel-handler.js.map +1 -0
- package/dist/cli/tunnel-handler.test.js +105 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel.d.ts +57 -0
- package/dist/cli/tunnel.js +154 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.js +190 -0
- package/dist/cli/tunnel.test.js.map +1 -0
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/use-execute-steps.d.ts +1 -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 -2
- package/dist/cli/use-nodemon.js +84 -72
- 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 +13 -7
- package/dist/cli/use-tunnel.js +103 -73
- package/dist/cli/use-tunnel.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +9 -2
- package/dist/cli/use-typescript-check.js +89 -51
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +3 -18
- 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 +3 -0
- package/dist/commands/dev.js +90 -6
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +13 -10
- 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/context-warnings.d.ts +5 -0
- package/dist/context-warnings.js +31 -0
- package/dist/context-warnings.js.map +1 -0
- package/dist/context-warnings.test.js +28 -0
- package/dist/context-warnings.test.js.map +1 -0
- package/dist/server/app.d.ts +194 -0
- package/dist/server/app.js +266 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/app.test.d.ts +1 -0
- package/dist/server/app.test.js +97 -0
- package/dist/server/app.test.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +6 -6
- package/dist/server/asset-base-url-transform-plugin.js +25 -11
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +92 -14
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +33 -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 +48 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +40 -0
- package/dist/server/auth/providers/auth0.js +36 -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 +50 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +143 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +51 -0
- package/dist/server/auth/providers/clerk.js +19 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +30 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +40 -0
- package/dist/server/auth/providers/custom.js +59 -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 +161 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +44 -0
- package/dist/server/auth/providers/descope.js +44 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +62 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.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 +25 -0
- package/dist/server/auth/providers/stytch.js +16 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +33 -0
- package/dist/server/auth/providers/workos.js +15 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.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 +91 -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 +514 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +46 -0
- package/dist/server/auth/verify.js +62 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +149 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth-extra.test-d.d.ts +1 -0
- package/dist/server/auth-extra.test-d.js +130 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +57 -0
- package/dist/server/auth.js +27 -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 +28 -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 +23 -7
- package/dist/server/express.js +62 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +429 -73
- 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 +20 -3
- package/dist/server/index.js +17 -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/mcp-errors.test.d.ts +1 -0
- package/dist/server/mcp-errors.test.js +41 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +51 -13
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +242 -131
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +27 -0
- package/dist/server/register-tool.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 +359 -89
- package/dist/server/server.js +488 -230
- 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 +86 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +27 -0
- package/dist/server/skills.js +188 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +243 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/templateHelper.d.ts +2 -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 +43 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +88 -0
- package/dist/server/tool-extra.test.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 +176 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +48 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +21 -31
- package/dist/test/utils.js +222 -198
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.d.ts +1 -0
- package/dist/test/view.test.js +540 -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/views/index.d.ts +10 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/views/scan-views.d.ts +16 -0
- package/dist/views/scan-views.js +88 -0
- package/dist/views/scan-views.js.map +1 -0
- package/dist/views/scan-views.test.d.ts +1 -0
- package/dist/views/scan-views.test.js +99 -0
- package/dist/views/scan-views.test.js.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/views/validate-view.js +9 -0
- package/dist/views/validate-view.js.map +1 -0
- package/dist/views/validate-view.test.d.ts +1 -0
- package/dist/views/validate-view.test.js +24 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +327 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +225 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +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 +18 -6
- 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 +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 +127 -11
- 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 +43 -3
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +24 -23
- 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 +42 -29
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +39 -31
- package/dist/web/generate-helpers.js +36 -28
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +33 -31
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +11 -11
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +7 -2
- package/dist/web/hooks/index.js +7 -2
- 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 +64 -29
- 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 +57 -21
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +3 -0
- package/dist/web/hooks/use-download.js +7 -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 +31 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +22 -0
- package/dist/web/hooks/use-host.js +30 -0
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/use-host.test.js +59 -0
- package/dist/web/hooks/use-host.test.js.map +1 -0
- 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 +15 -5
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +37 -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 +12 -2
- 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 +26 -12
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +46 -14
- package/dist/web/hooks/use-tool-info.js +29 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -34
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +42 -37
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +5 -2
- package/dist/web/hooks/use-user.js +6 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +85 -37
- 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 +42 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +212 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/use-viewport.test.d.ts +1 -0
- package/dist/web/hooks/use-viewport.test.js +109 -0
- package/dist/web/hooks/use-viewport.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 +21 -0
- package/dist/web/mount-view.js +43 -0
- package/dist/web/mount-view.js.map +1 -0
- 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 +46 -26
- package/tsconfig.base.json +2 -0
- package/dist/server/templates/development.hbs +0 -12
- package/dist/server/templates/production.hbs +0 -6
- package/dist/server/widgetsDevServer.d.ts +0 -13
- package/dist/server/widgetsDevServer.js +0 -57
- package/dist/server/widgetsDevServer.js.map +0 -1
- package/dist/test/widget.test.js +0 -263
- 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 -75
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -38
- package/dist/web/bridges/mcp-app/adaptor.js +0 -184
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -22
- package/dist/web/hooks/use-layout.js +0 -23
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.js +0 -96
- package/dist/web/hooks/use-layout.test.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 -64
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js +0 -27
- package/dist/web/mount-widget.js.map +0 -1
- package/dist/web/plugin/data-llm.test.js +0 -81
- package/dist/web/plugin/data-llm.test.js.map +0 -1
- package/dist/web/plugin/plugin.d.ts +0 -2
- package/dist/web/plugin/plugin.js +0 -54
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.d.ts +0 -12
- package/dist/web/plugin/transform-data-llm.js +0 -96
- package/dist/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.test.js +0 -81
- package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/web/plugin/validate-widget.d.ts +0 -5
- package/dist/web/plugin/validate-widget.js +0 -27
- package/dist/web/plugin/validate-widget.js.map +0 -1
- package/dist/web/plugin/validate-widget.test.js +0 -42
- package/dist/web/plugin/validate-widget.test.js.map +0 -1
- /package/dist/{test/widget.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-widget.test.d.ts → context-warnings.test.d.ts} +0 -0
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { VIEW_CONTEXT_KEY } from "../data-llm.js";
|
|
3
|
+
import { filterViewContext, serializeState } from "./state.js";
|
|
4
4
|
describe("state helpers", () => {
|
|
5
|
-
describe("
|
|
5
|
+
describe("filterViewContext", () => {
|
|
6
6
|
it("should return null when state is null", () => {
|
|
7
|
-
expect(
|
|
7
|
+
expect(filterViewContext(null)).toBe(null);
|
|
8
8
|
});
|
|
9
9
|
it("should return null when state is undefined", () => {
|
|
10
|
-
expect(
|
|
10
|
+
expect(filterViewContext(undefined)).toBe(null);
|
|
11
11
|
});
|
|
12
|
-
it("should correctly filter
|
|
12
|
+
it("should correctly filter VIEW_CONTEXT_KEY and preserve other properties", () => {
|
|
13
13
|
const stateWithContextAndOthers = {
|
|
14
14
|
a: 1,
|
|
15
15
|
b: "two",
|
|
16
16
|
c: { nested: true },
|
|
17
|
-
[
|
|
17
|
+
[VIEW_CONTEXT_KEY]: "context",
|
|
18
18
|
};
|
|
19
|
-
const filteredWithContextAndOthers =
|
|
19
|
+
const filteredWithContextAndOthers = filterViewContext(stateWithContextAndOthers);
|
|
20
20
|
expect(filteredWithContextAndOthers).toEqual({
|
|
21
21
|
a: 1,
|
|
22
22
|
b: "two",
|
|
23
23
|
c: { nested: true },
|
|
24
24
|
});
|
|
25
25
|
const stateNoContext = { count: 5, name: "test" };
|
|
26
|
-
const filteredNoContext =
|
|
26
|
+
const filteredNoContext = filterViewContext(stateNoContext);
|
|
27
27
|
expect(filteredNoContext).toEqual(stateNoContext);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../src/web/helpers/state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../src/web/helpers/state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE/D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAA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AAC,EAAE,IAAI;gBACP,KAAK;gBACL,IAAI;gBACJ,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;aACvB,CAAC;YACF,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,EAAE,IAAI;gBACP,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBAC/B,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC;aAC3C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { VIEW_CONTEXT_KEY } from \"../data-llm.js\";\nimport { filterViewContext, serializeState } from \"./state.js\";\n\ndescribe(\"state helpers\", () => {\n describe(\"filterViewContext\", () => {\n it(\"should return null when state is null\", () => {\n expect(filterViewContext(null)).toBe(null);\n });\n\n it(\"should return null when state is undefined\", () => {\n expect(filterViewContext(undefined)).toBe(null);\n });\n\n it(\"should correctly filter VIEW_CONTEXT_KEY and preserve other properties\", () => {\n const stateWithContextAndOthers = {\n a: 1,\n b: \"two\",\n c: { nested: true },\n [VIEW_CONTEXT_KEY]: \"context\",\n };\n const filteredWithContextAndOthers = filterViewContext(\n stateWithContextAndOthers,\n );\n expect(filteredWithContextAndOthers).toEqual({\n a: 1,\n b: \"two\",\n c: { nested: true },\n });\n\n const stateNoContext = { count: 5, name: \"test\" };\n const filteredNoContext = filterViewContext(stateNoContext);\n expect(filteredNoContext).toEqual(stateNoContext);\n });\n });\n\n describe(\"serializeState\", () => {\n it(\"should serialize plain objects\", () => {\n const array = [1, \"two\", { three: 3 }];\n const date = new Date(\"2023-01-01T00:00:00Z\");\n const object = {\n a: 1,\n b: \"test\",\n c: true,\n array,\n date,\n function: () => \"test\",\n };\n const result = serializeState(object);\n\n expect(result).toEqual({\n a: 1,\n b: \"test\",\n c: true,\n array: [1, \"two\", { three: 3 }],\n date: new Date(\"2023-01-01T00:00:00.000Z\"),\n });\n });\n });\n});\n"]}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { type DownloadFn, useDownload } from "./use-download.js";
|
|
3
4
|
export { useFiles } from "./use-files.js";
|
|
4
|
-
export { type
|
|
5
|
+
export { type Host, type HostInfo, useHost } from "./use-host.js";
|
|
5
6
|
export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
|
|
7
|
+
export { useRegisterViewTool } from "./use-register-view-tool.js";
|
|
8
|
+
export { type RequestCloseFn, useRequestClose } from "./use-request-close.js";
|
|
6
9
|
export { useRequestModal } from "./use-request-modal.js";
|
|
10
|
+
export { type RequestSizeFn, useRequestSize } from "./use-request-size.js";
|
|
7
11
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
12
|
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
13
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
14
|
export { type UserState, useUser } from "./use-user.js";
|
|
11
|
-
export {
|
|
15
|
+
export { useViewState } from "./use-view-state.js";
|
|
16
|
+
export { useViewport, type ViewportState } from "./use-viewport.js";
|
package/dist/web/hooks/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
export { useCallTool, } from "./use-call-tool.js";
|
|
2
2
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useDownload } from "./use-download.js";
|
|
3
4
|
export { useFiles } from "./use-files.js";
|
|
4
|
-
export {
|
|
5
|
+
export { useHost } from "./use-host.js";
|
|
5
6
|
export { useOpenExternal } from "./use-open-external.js";
|
|
7
|
+
export { useRegisterViewTool } from "./use-register-view-tool.js";
|
|
8
|
+
export { useRequestClose } from "./use-request-close.js";
|
|
6
9
|
export { useRequestModal } from "./use-request-modal.js";
|
|
10
|
+
export { useRequestSize } from "./use-request-size.js";
|
|
7
11
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
12
|
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
13
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
14
|
export { useUser } from "./use-user.js";
|
|
11
|
-
export {
|
|
15
|
+
export { useViewState } from "./use-view-state.js";
|
|
16
|
+
export { useViewport } from "./use-viewport.js";
|
|
12
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAA4B,OAAO,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAkB,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAsB,MAAM,mBAAmB,CAAC","sourcesContent":["export {\n type CallToolAsyncFn,\n type CallToolFn,\n type CallToolState,\n type SideEffects,\n useCallTool,\n} from \"./use-call-tool.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport { type Host, type HostInfo, useHost } from \"./use-host.js\";\nexport { type OpenExternalFn, useOpenExternal } from \"./use-open-external.js\";\nexport { useRegisterViewTool } from \"./use-register-view-tool.js\";\nexport { type RequestCloseFn, useRequestClose } from \"./use-request-close.js\";\nexport { useRequestModal } from \"./use-request-modal.js\";\nexport { type RequestSizeFn, useRequestSize } from \"./use-request-size.js\";\nexport { useSendFollowUpMessage } from \"./use-send-follow-up-message.js\";\nexport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\nexport { useToolInfo } from \"./use-tool-info.js\";\nexport { type UserState, useUser } from \"./use-user.js\";\nexport { useViewState } from \"./use-view-state.js\";\nexport { useViewport, type ViewportState } from \"./use-viewport.js\";\n"]}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { McpUiHostContext, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
1
|
+
import type { McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiInitializeResult, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
2
|
export declare class MockResizeObserver {
|
|
3
3
|
observe(): void;
|
|
4
4
|
unobserve(): void;
|
|
5
5
|
disconnect(): void;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type McpAppHostMockOptions = {
|
|
8
|
+
hostCapabilities?: McpUiHostCapabilities;
|
|
9
|
+
downloadFileResult?: McpUiDownloadFileResult;
|
|
10
|
+
hostInfo?: McpUiInitializeResult["hostInfo"];
|
|
11
|
+
};
|
|
12
|
+
export declare const getMcpAppHostPostMessageMock: (initialContext?: McpUiHostContext, options?: McpAppHostMockOptions) => import("vitest").Mock<(message: {
|
|
8
13
|
method: string;
|
|
9
14
|
id: number;
|
|
10
15
|
}) => void>;
|
|
@@ -7,13 +7,13 @@ export class MockResizeObserver {
|
|
|
7
7
|
disconnect() { }
|
|
8
8
|
}
|
|
9
9
|
const DEFAULT_CONTEXT = {};
|
|
10
|
-
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) => vi.fn((message) => {
|
|
10
|
+
export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT, options = {}) => vi.fn((message) => {
|
|
11
11
|
switch (message.method) {
|
|
12
12
|
case "ui/initialize": {
|
|
13
13
|
const result = {
|
|
14
14
|
protocolVersion: "2025-06-18",
|
|
15
|
-
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
16
|
-
hostCapabilities: {},
|
|
15
|
+
hostInfo: options.hostInfo ?? { name: "test-host", version: "1.0.0" },
|
|
16
|
+
hostCapabilities: options.hostCapabilities ?? {},
|
|
17
17
|
hostContext: initialContext,
|
|
18
18
|
};
|
|
19
19
|
act(() => fireEvent(window, new MessageEvent("message", {
|
|
@@ -37,6 +37,17 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
|
|
|
37
37
|
})));
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
|
+
case "ui/download-file": {
|
|
41
|
+
act(() => fireEvent(window, new MessageEvent("message", {
|
|
42
|
+
source: window.parent,
|
|
43
|
+
data: {
|
|
44
|
+
jsonrpc: "2.0",
|
|
45
|
+
id: message.id,
|
|
46
|
+
result: options.downloadFileResult ?? {},
|
|
47
|
+
},
|
|
48
|
+
})));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
52
|
});
|
|
42
53
|
export const fireToolInputNotification = (args) => {
|
|
@@ -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;AAQ7C,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,OAAO,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE;gBACrE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,EAAE;gBAChD,WAAW,EAAE,cAAc;aAC5B,CAAC;YACF,GAAG,CAAC,GAAG,EAAE,CACP,SAAS,CACP,MA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;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAI1C,EAAE,EAAE;IACH,SAAS,CACP,MAAM,EACN,IAAI,YAAY,CACd,SAAS,EACT;QACE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE;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 hostInfo?: McpUiInitializeResult[\"hostInfo\"];\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: options.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,G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MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,OAAO,EAAE,MAAM,KAAK,OAAO;KACe,CAAC;IAE7C,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useRef, useState } from \"react\";\n\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
|
-
{"version":3,"file":"use-call-tool.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,EAGL,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAE5B,IAAI,CAAC,2DAA2D,EAAE,GAAG,EAAE;IACrE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,WAAW,CAAO,WAAW,CAAC,CAAC;IACnE,QAAQ,EAAE,CAAC;IACX,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;IAClC,aAAa,EAAE,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8DAA8D,EAAE,GAAG,EAAE;IAExE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,WAAW,CAAO,WAAW,CAAC,CAAC;IAEnE,uCAAuC;IACvC,QAAQ,EAAE,CAAC;IAEX,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;IAErD,uCAAuC;IACvC,aAAa,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAI5D,MAAM,EAAE,QAA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AC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;YACpD,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QACpC,CAAC;KACF,CAAC;IAEF,YAAY,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;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
|
-
vi.stubGlobal("skybridge", {
|
|
11
|
+
HostAdaptor.resetInstance();
|
|
12
|
+
McpAppBridge.resetInstance();
|
|
13
|
+
AppsSdkBridge.resetInstance();
|
|
14
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
15
|
+
vi.stubGlobal("skybridge", {});
|
|
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("
|
|
134
|
-
vi.stubGlobal("skybridge", {
|
|
163
|
+
HostAdaptor.resetInstance();
|
|
164
|
+
McpAppBridge.resetInstance();
|
|
165
|
+
AppsSdkBridge.resetInstance();
|
|
166
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
167
|
+
vi.stubGlobal("skybridge", {});
|
|
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,E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C;QACH,YAAY,CAAsB,aAAa,CAAC,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QAKzE,MAAM,EAAE,MAAM,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\", {});\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\", {});\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"]}
|