skybridge 0.0.0-dev.db51ef5 → 0.0.0-dev.db532c6
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 +155 -0
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +107 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.js +132 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +73 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +49 -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-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 +90 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/telemetry.js +2 -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.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 +26 -0
- package/dist/cli/use-nodemon.js +106 -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/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.d.ts +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 +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 +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 +42 -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 +34 -0
- package/dist/server/auth/providers/workos.js +16 -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 +48 -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 +165 -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 +31 -0
- package/dist/server/express.js +107 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +608 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.d.ts +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +21 -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 +162 -0
- package/dist/server/middleware.js +126 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +601 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/openai-ui.d.ts +11 -0
- package/dist/server/openai-ui.js +82 -0
- package/dist/server/openai-ui.js.map +1 -0
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +74 -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 +459 -64
- package/dist/server/server.js +533 -109
- 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 +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 +118 -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.d.ts +21 -2
- 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 +2 -42
- 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 +135 -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 +33 -27
- 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 +53 -37
- 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 +9 -3
- package/dist/web/hooks/index.js +8 -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 +18 -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 +40 -8
- 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 +71 -29
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-deep-link.d.ts +22 -0
- package/dist/web/hooks/use-deep-link.js +34 -0
- package/dist/web/hooks/use-deep-link.js.map +1 -0
- 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 +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 +36 -4
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +44 -0
- package/dist/web/hooks/use-host.js +45 -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 +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 +40 -15
- 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 +16 -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 +29 -21
- 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 +43 -38
- 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 +23 -4
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +105 -29
- 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 +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 +56 -31
- 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-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 -61
- package/dist/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/web/mount-widget.d.ts +0 -1
- package/dist/web/mount-widget.js +0 -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 -39
- 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/{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
|
@@ -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,QA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AAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YACvC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG;gBACb,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,MAAM;gBACT,CAAC,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,17 @@
|
|
|
1
1
|
export { type CallToolAsyncFn, type CallToolFn, type CallToolState, type SideEffects, useCallTool, } from "./use-call-tool.js";
|
|
2
|
+
export { useDeepLink } from "./use-deep-link.js";
|
|
2
3
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
4
|
+
export { type DownloadFn, useDownload } from "./use-download.js";
|
|
3
5
|
export { useFiles } from "./use-files.js";
|
|
4
|
-
export { type
|
|
5
|
-
export { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
export { type Host, type HostInfo, type OpenAIHostCapabilities, useHost, } from "./use-host.js";
|
|
7
|
+
export { type OpenExternalFn, useOpenExternal } from "./use-open-external.js";
|
|
8
|
+
export { useRegisterViewTool } from "./use-register-view-tool.js";
|
|
9
|
+
export { type RequestCloseFn, useRequestClose } from "./use-request-close.js";
|
|
6
10
|
export { useRequestModal } from "./use-request-modal.js";
|
|
11
|
+
export { type RequestSizeFn, useRequestSize } from "./use-request-size.js";
|
|
7
12
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
13
|
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
14
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
15
|
export { type UserState, useUser } from "./use-user.js";
|
|
11
|
-
export {
|
|
16
|
+
export { useViewState } from "./use-view-state.js";
|
|
17
|
+
export { useViewport, type ViewportState } from "./use-viewport.js";
|
package/dist/web/hooks/index.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export { useCallTool, } from "./use-call-tool.js";
|
|
2
|
+
export { useDeepLink } from "./use-deep-link.js";
|
|
2
3
|
export { useDisplayMode } from "./use-display-mode.js";
|
|
4
|
+
export { useDownload } from "./use-download.js";
|
|
3
5
|
export { useFiles } from "./use-files.js";
|
|
4
|
-
export {
|
|
6
|
+
export { useHost, } from "./use-host.js";
|
|
5
7
|
export { useOpenExternal } from "./use-open-external.js";
|
|
8
|
+
export { useRegisterViewTool } from "./use-register-view-tool.js";
|
|
9
|
+
export { useRequestClose } from "./use-request-close.js";
|
|
6
10
|
export { useRequestModal } from "./use-request-modal.js";
|
|
11
|
+
export { useRequestSize } from "./use-request-size.js";
|
|
7
12
|
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
13
|
export { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
9
14
|
export { useToolInfo } from "./use-tool-info.js";
|
|
10
15
|
export { useUser } from "./use-user.js";
|
|
11
|
-
export {
|
|
16
|
+
export { useViewState } from "./use-view-state.js";
|
|
17
|
+
export { useViewport } from "./use-viewport.js";
|
|
12
18
|
//# 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,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,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,EAIL,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,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 { useDeepLink } from \"./use-deep-link.js\";\nexport { useDisplayMode } from \"./use-display-mode.js\";\nexport { type DownloadFn, useDownload } from \"./use-download.js\";\nexport { useFiles } from \"./use-files.js\";\nexport {\n type Host,\n type HostInfo,\n type OpenAIHostCapabilities,\n useHost,\n} 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,16 +7,17 @@ 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", {
|
|
20
|
+
source: window.parent,
|
|
20
21
|
data: {
|
|
21
22
|
jsonrpc: "2.0",
|
|
22
23
|
id: message.id,
|
|
@@ -27,6 +28,7 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
|
|
|
27
28
|
}
|
|
28
29
|
case "ui/update-model-context": {
|
|
29
30
|
act(() => fireEvent(window, new MessageEvent("message", {
|
|
31
|
+
source: window.parent,
|
|
30
32
|
data: {
|
|
31
33
|
jsonrpc: "2.0",
|
|
32
34
|
id: message.id,
|
|
@@ -35,10 +37,22 @@ export const getMcpAppHostPostMessageMock = (initialContext = DEFAULT_CONTEXT) =
|
|
|
35
37
|
})));
|
|
36
38
|
break;
|
|
37
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
|
+
}
|
|
38
51
|
}
|
|
39
52
|
});
|
|
40
53
|
export const fireToolInputNotification = (args) => {
|
|
41
54
|
fireEvent(window, new MessageEvent("message", {
|
|
55
|
+
source: window.parent,
|
|
42
56
|
data: {
|
|
43
57
|
jsonrpc: "2.0",
|
|
44
58
|
method: "ui/notifications/tool-input",
|
|
@@ -50,6 +64,7 @@ export const fireToolInputNotification = (args) => {
|
|
|
50
64
|
};
|
|
51
65
|
export const fireToolResultNotification = (params) => {
|
|
52
66
|
fireEvent(window, new MessageEvent("message", {
|
|
67
|
+
source: window.parent,
|
|
53
68
|
data: {
|
|
54
69
|
jsonrpc: "2.0",
|
|
55
70
|
method: "ui/notifications/tool-result",
|
|
@@ -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,CAA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;aAChB;SACF;KACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC;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,12 +1,44 @@
|
|
|
1
|
-
import { useRef, useState } from "react";
|
|
1
|
+
import { useCallback, 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);
|
|
6
34
|
const adaptor = getAdaptor();
|
|
7
|
-
const execute = async (toolArgs) => {
|
|
35
|
+
const execute = useCallback(async (toolArgs) => {
|
|
8
36
|
const callId = ++callIdRef.current;
|
|
9
|
-
setCallToolState({
|
|
37
|
+
setCallToolState({
|
|
38
|
+
status: "pending",
|
|
39
|
+
data: undefined,
|
|
40
|
+
error: undefined,
|
|
41
|
+
});
|
|
10
42
|
try {
|
|
11
43
|
const data = await adaptor.callTool(name, toolArgs);
|
|
12
44
|
if (callId === callIdRef.current) {
|
|
@@ -20,14 +52,14 @@ export const useCallTool = (name) => {
|
|
|
20
52
|
}
|
|
21
53
|
throw error;
|
|
22
54
|
}
|
|
23
|
-
};
|
|
24
|
-
const callToolAsync = ((toolArgs) => {
|
|
55
|
+
}, [adaptor, name]);
|
|
56
|
+
const callToolAsync = useCallback((toolArgs) => {
|
|
25
57
|
if (toolArgs === undefined) {
|
|
26
58
|
return execute(null);
|
|
27
59
|
}
|
|
28
60
|
return execute(toolArgs);
|
|
29
|
-
});
|
|
30
|
-
const callTool = ((firstArg, sideEffects) => {
|
|
61
|
+
}, [execute]);
|
|
62
|
+
const callTool = useCallback((firstArg, sideEffects) => {
|
|
31
63
|
let toolArgs;
|
|
32
64
|
if (firstArg &&
|
|
33
65
|
typeof firstArg === "object" &&
|
|
@@ -49,7 +81,7 @@ export const useCallTool = (name) => {
|
|
|
49
81
|
sideEffects?.onError?.(error, toolArgs);
|
|
50
82
|
sideEffects?.onSettled?.(undefined, error, toolArgs);
|
|
51
83
|
});
|
|
52
|
-
});
|
|
84
|
+
}, [execute]);
|
|
53
85
|
const callToolState = {
|
|
54
86
|
status,
|
|
55
87
|
data,
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAGL,UAAU,GACX,MAAM,qBAAqB,CAAC;AA4G7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IAGF,MAAM,CAAC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AAM,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 { useCallback, 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 = useCallback(\n async (toolArgs: ToolArgs): Promise<CombinedCallToolResponse> => {\n const callId = ++callIdRef.current;\n setCallToolState({\n status: \"pending\",\n data: undefined,\n error: undefined,\n });\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 [adaptor, name],\n );\n\n const callToolAsync = useCallback(\n (toolArgs?: ToolArgs) => {\n if (toolArgs === undefined) {\n return execute(null as ToolArgs);\n }\n return execute(toolArgs);\n },\n [execute],\n ) as CallToolAsyncFn<ToolArgs, CombinedCallToolResponse>;\n\n const callTool = useCallback(\n (\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 },\n [execute],\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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AI,EAAE,EAAE;YACxB,YAAY,CAAC,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);
|
|
27
43
|
const { result } = renderHook(() => useCallTool(toolName));
|
|
28
44
|
await act(async () => {
|
|
29
45
|
result.current.callTool(args);
|
|
30
46
|
});
|
|
31
|
-
|
|
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 () => {
|
|
54
|
+
const { result } = renderHook(() => useCallTool(toolName));
|
|
55
|
+
await act(async () => {
|
|
56
|
+
result.current.callTool(args);
|
|
57
|
+
});
|
|
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(() => {
|
|
@@ -123,19 +156,31 @@ describe("useCallTool - onSuccess callback", () => {
|
|
|
123
156
|
expect(result.current.data).toEqual(secondCallData);
|
|
124
157
|
});
|
|
125
158
|
});
|
|
159
|
+
it("should keep callTool and callToolAsync stable across renders", () => {
|
|
160
|
+
const { result, rerender } = renderHook(() => useCallTool(toolName));
|
|
161
|
+
const { callTool, callToolAsync } = result.current;
|
|
162
|
+
rerender();
|
|
163
|
+
expect(result.current.callTool).toBe(callTool);
|
|
164
|
+
expect(result.current.callToolAsync).toBe(callToolAsync);
|
|
165
|
+
});
|
|
126
166
|
});
|
|
127
167
|
describe("useCallTool - TypeScript typing", () => {
|
|
128
|
-
let
|
|
168
|
+
let callToolMock;
|
|
129
169
|
beforeEach(() => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
vi.stubGlobal("
|
|
134
|
-
vi.stubGlobal("skybridge", {
|
|
170
|
+
HostAdaptor.resetInstance();
|
|
171
|
+
McpAppBridge.resetInstance();
|
|
172
|
+
AppsSdkBridge.resetInstance();
|
|
173
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
174
|
+
vi.stubGlobal("skybridge", {});
|
|
175
|
+
vi.stubGlobal("openai", { callTool: vi.fn() });
|
|
176
|
+
callToolMock = vi.spyOn(getAdaptor(), "callTool");
|
|
135
177
|
});
|
|
136
178
|
afterEach(() => {
|
|
137
179
|
vi.unstubAllGlobals();
|
|
138
180
|
vi.resetAllMocks();
|
|
181
|
+
HostAdaptor.resetInstance();
|
|
182
|
+
McpAppBridge.resetInstance();
|
|
183
|
+
AppsSdkBridge.resetInstance();
|
|
139
184
|
});
|
|
140
185
|
it("should have correct return types when ToolArgs is null and ToolResponse is specified", async () => {
|
|
141
186
|
const { result } = renderHook(() => useCallTool("test-tool"));
|
|
@@ -143,14 +188,13 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
143
188
|
content: [{ type: "text", text: "test" }],
|
|
144
189
|
structuredContent: { result: "test" },
|
|
145
190
|
isError: false,
|
|
146
|
-
result: "test",
|
|
147
191
|
meta: { id: 123 },
|
|
148
192
|
};
|
|
149
|
-
|
|
193
|
+
callToolMock.mockResolvedValueOnce(data);
|
|
150
194
|
await act(async () => {
|
|
151
195
|
result.current.callTool();
|
|
152
196
|
});
|
|
153
|
-
expect(
|
|
197
|
+
expect(callToolMock).toHaveBeenCalledWith("test-tool", null);
|
|
154
198
|
expectTypeOf(result.current.data);
|
|
155
199
|
});
|
|
156
200
|
it("should correctly type callToolAsync return value", async () => {
|
|
@@ -160,10 +204,9 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
160
204
|
content: [{ type: "text", text: "answer" }],
|
|
161
205
|
structuredContent: { answer: "test answer" },
|
|
162
206
|
isError: false,
|
|
163
|
-
result: "answer",
|
|
164
207
|
meta: {},
|
|
165
208
|
};
|
|
166
|
-
|
|
209
|
+
callToolMock.mockResolvedValueOnce(mockResponse);
|
|
167
210
|
const returnedValue = await act(async () => {
|
|
168
211
|
return result.current.callToolAsync(testArgs);
|
|
169
212
|
});
|
|
@@ -176,10 +219,9 @@ describe("useCallTool - TypeScript typing", () => {
|
|
|
176
219
|
content: [{ type: "text", text: "data" }],
|
|
177
220
|
structuredContent: { data: "test data" },
|
|
178
221
|
isError: false,
|
|
179
|
-
result: "data",
|
|
180
222
|
meta: {},
|
|
181
223
|
};
|
|
182
|
-
|
|
224
|
+
callToolMock.mockResolvedValueOnce(mockResponse);
|
|
183
225
|
const returnedValue = await act(async () => {
|
|
184
226
|
return result.current.callToolAsync();
|
|
185
227
|
});
|