skybridge 0.0.0-dev.e97960f → 0.0.0-dev.e99ee17
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 -124
- package/dist/cli/build-helpers.d.ts +11 -0
- package/dist/cli/build-helpers.js +107 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.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/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-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/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +25 -1
- package/dist/cli/use-nodemon.js +96 -63
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +71 -68
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -3
- package/dist/commands/build.js +2 -73
- 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 +1 -0
- package/dist/commands/dev.js +51 -3
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/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.js +97 -0
- package/dist/server/app.test.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +16 -1
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
- 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 +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.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 +41 -1
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/events.d.ts +113 -0
- package/dist/server/events.js +318 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/events.test.d.ts +1 -0
- package/dist/server/events.test.js +172 -0
- package/dist/server/events.test.js.map +1 -0
- package/dist/server/express.d.ts +23 -3
- package/dist/server/express.js +43 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +269 -90
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +21 -1
- package/dist/server/file-ref.js +20 -1
- package/dist/server/file-ref.js.map +1 -1
- package/dist/server/form-input.d.ts +120 -0
- package/dist/server/form-input.js +89 -0
- package/dist/server/form-input.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 +19 -2
- package/dist/server/index.js +16 -1
- package/dist/server/index.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/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 -134
- 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 +230 -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 +532 -67
- package/dist/server/server.js +646 -315
- 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 +0 -3
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js +4 -8
- package/dist/server/templates.generated.js.map +1 -1
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +167 -0
- package/dist/server/tool-extra.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.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +9 -11
- package/dist/test/utils.js +220 -201
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +123 -106
- package/dist/test/view.test.js.map +1 -1
- 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/{web/plugin → views}/scan-views.js +1 -1
- 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.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/{web/plugin → views}/validate-view.js +2 -2
- 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.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +62 -0
- package/dist/web/bridges/adaptor.js +471 -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 +264 -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/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/mcp-app/bridge.d.ts +15 -2
- package/dist/web/bridges/mcp-app/bridge.js +80 -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 +19 -2
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +13 -1
- 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 +160 -5
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +10 -7
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +34 -1
- package/dist/web/data-llm.js +31 -2
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js +26 -7
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +25 -19
- package/dist/web/generate-helpers.js +23 -17
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +7 -5
- 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/hooks/index.d.ts +8 -1
- package/dist/web/hooks/index.js +8 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
- package/dist/web/hooks/openai-extensions.test.js +107 -0
- package/dist/web/hooks/openai-extensions.test.js.map +1 -0
- 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 +47 -2
- package/dist/web/hooks/use-call-tool.js +43 -10
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +75 -25
- 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 +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.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-file-resource.d.ts +37 -0
- package/dist/web/hooks/use-file-resource.js +98 -0
- package/dist/web/hooks/use-file-resource.js.map +1 -0
- package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
- package/dist/web/hooks/use-file-resource.test.js +65 -0
- package/dist/web/hooks/use-file-resource.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +11 -3
- 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-model-context.d.ts +44 -0
- package/dist/web/hooks/use-model-context.js +63 -0
- package/dist/web/hooks/use-model-context.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-open-file.d.ts +20 -0
- package/dist/web/hooks/use-open-file.js +25 -0
- package/dist/web/hooks/use-open-file.js.map +1 -0
- 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 +14 -0
- package/dist/web/hooks/use-request-close.js +13 -0
- package/dist/web/hooks/use-request-close.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +11 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +17 -0
- package/dist/web/hooks/use-request-size.js +16 -0
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-send-follow-up-message.d.ts +25 -2
- package/dist/web/hooks/use-send-follow-up-message.js +23 -0
- 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 +21 -0
- package/dist/web/hooks/use-view-state.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +39 -4
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- 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/mount-view.d.ts +20 -0
- package/dist/web/mount-view.js +22 -6
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +35 -23
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -26
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -102
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -50
- package/dist/web/bridges/mcp-app/adaptor.js +0 -271
- 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/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 -5
- package/dist/web/plugin/plugin.js +0 -163
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/scan-views.js.map +0 -1
- package/dist/web/plugin/scan-views.test.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-view.d.ts +0 -1
- package/dist/web/plugin/validate-view.js.map +0 -1
- package/dist/web/plugin/validate-view.test.js.map +0 -1
- /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-helpers.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
- /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
- /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
5
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
+
import { useHost } from "./use-host.js";
|
|
7
|
+
const stubHost = (hostInfo) => {
|
|
8
|
+
vi.stubGlobal("parent", {
|
|
9
|
+
postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
describe("useHost", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
HostAdaptor.resetInstance();
|
|
15
|
+
McpAppBridge.resetInstance();
|
|
16
|
+
vi.stubGlobal("openai", undefined);
|
|
17
|
+
vi.stubGlobal("skybridge", {});
|
|
18
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.unstubAllGlobals();
|
|
22
|
+
vi.resetAllMocks();
|
|
23
|
+
McpAppBridge.resetInstance();
|
|
24
|
+
HostAdaptor.resetInstance();
|
|
25
|
+
});
|
|
26
|
+
it("is undefined before the handshake resolves, then populated after", async () => {
|
|
27
|
+
stubHost({ name: "Claude", version: "1.2.3" });
|
|
28
|
+
const { result } = renderHook(() => useHost());
|
|
29
|
+
expect(result.current.name).toBeUndefined();
|
|
30
|
+
expect(result.current.version).toBeUndefined();
|
|
31
|
+
await waitFor(() => {
|
|
32
|
+
expect(result.current.name).toBe("claude");
|
|
33
|
+
expect(result.current.version).toBe("1.2.3");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it.each([
|
|
37
|
+
["chatgpt", "chatgpt"],
|
|
38
|
+
["Claude", "claude"],
|
|
39
|
+
["Cursor", "cursor"],
|
|
40
|
+
["MCP-UI Host", "goose"],
|
|
41
|
+
["Le Chat", "mistral-vibe"],
|
|
42
|
+
["alpic-playground", "alpic"],
|
|
43
|
+
])("normalizes reported name %j to slug %j", async (reported, slug) => {
|
|
44
|
+
stubHost({ name: reported, version: "1.0.0" });
|
|
45
|
+
const { result } = renderHook(() => useHost());
|
|
46
|
+
await waitFor(() => {
|
|
47
|
+
expect(result.current.name).toBe(slug);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it("preserves an unrecognized reported name as-is", async () => {
|
|
51
|
+
stubHost({ name: "Some Future Host", version: "9.9.9" });
|
|
52
|
+
const { result } = renderHook(() => useHost());
|
|
53
|
+
await waitFor(() => {
|
|
54
|
+
expect(result.current.name).toBe("Some Future Host");
|
|
55
|
+
expect(result.current.version).toBe("9.9.9");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=use-host.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-host.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-host.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iB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O,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { type Host, useHost } from \"./use-host.js\";\n\nconst stubHost = (hostInfo?: { name: string; version: string }) => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({}, { hostInfo }),\n });\n};\n\ndescribe(\"useHost\", () => {\n beforeEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n HostAdaptor.resetInstance();\n });\n\n it(\"is undefined before the handshake resolves, then populated after\", async () => {\n stubHost({ name: \"Claude\", version: \"1.2.3\" });\n const { result } = renderHook(() => useHost());\n\n expect(result.current.name).toBeUndefined();\n expect(result.current.version).toBeUndefined();\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"claude\");\n expect(result.current.version).toBe(\"1.2.3\");\n });\n });\n\n it.each<[string, Host]>([\n [\"chatgpt\", \"chatgpt\"],\n [\"Claude\", \"claude\"],\n [\"Cursor\", \"cursor\"],\n [\"MCP-UI Host\", \"goose\"],\n [\"Le Chat\", \"mistral-vibe\"],\n [\"alpic-playground\", \"alpic\"],\n ])(\"normalizes reported name %j to slug %j\", async (reported, slug) => {\n stubHost({ name: reported, version: \"1.0.0\" });\n const { result } = renderHook(() => useHost());\n\n await waitFor(() => {\n expect(result.current.name).toBe(slug);\n });\n });\n\n it(\"preserves an unrecognized reported name as-is\", async () => {\n stubHost({ name: \"Some Future Host\", version: \"9.9.9\" });\n const { result } = renderHook(() => useHost());\n\n await waitFor(() => {\n expect(result.current.name).toBe(\"Some Future Host\");\n expect(result.current.version).toBe(\"9.9.9\");\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { OpenAIHostContext } from "../bridges/mcp-app/types.js";
|
|
2
|
+
import type { ModelContextParams } from "../bridges/types.js";
|
|
3
|
+
/** Model context the view attached, as ChatGPT reports it back. */
|
|
4
|
+
export type ModelContextState = OpenAIHostContext["openai/modelContext"];
|
|
5
|
+
/**
|
|
6
|
+
* Send content to the model through the MCP Apps `ui/update-model-context`
|
|
7
|
+
* request. Each `update` replaces what this hook sent before. Outside ChatGPT
|
|
8
|
+
* it is merged with the {@link useViewState} state, which wins on shared
|
|
9
|
+
* `structuredContent` keys.
|
|
10
|
+
*
|
|
11
|
+
* ChatGPT also reads the OpenAI presentation metadata, shows each block as a
|
|
12
|
+
* composer attachment and reports the attached context back:
|
|
13
|
+
* `_meta["openai/title"]`, `_meta["openai/thumbnail"]` on text blocks, and
|
|
14
|
+
* `annotations.audience: ["assistant"]` to hide a block from the user.
|
|
15
|
+
*
|
|
16
|
+
* - `supported`: whether the host advertises `updateModelContext` or
|
|
17
|
+
* `openai/modelContext`.
|
|
18
|
+
* - `context`: ChatGPT only, the attached context; `null` once the user
|
|
19
|
+
* removed it, `undefined` when the host never reported one.
|
|
20
|
+
* - `update`: replaces the context and resolves with ChatGPT's `updateId`,
|
|
21
|
+
* to compare with `context.updateId`. Rejects with `NotSupportedError` on
|
|
22
|
+
* hosts that don't advertise model context updates.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const { supported, update } = useModelContext();
|
|
27
|
+
* update({
|
|
28
|
+
* content: [
|
|
29
|
+
* {
|
|
30
|
+
* type: "text",
|
|
31
|
+
* text: "Selected: M6 hex bolt",
|
|
32
|
+
* _meta: { "openai/title": "Hex bolt" },
|
|
33
|
+
* },
|
|
34
|
+
* ],
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @see https://docs.skybridge.tech/api-reference/use-model-context
|
|
39
|
+
*/
|
|
40
|
+
export declare function useModelContext(): {
|
|
41
|
+
supported: boolean;
|
|
42
|
+
context: ModelContextState;
|
|
43
|
+
update: (params: ModelContextParams) => Promise<string | undefined>;
|
|
44
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ContentBlockSchema } from "@modelcontextprotocol/core";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import * as z from "zod/v4";
|
|
4
|
+
import { getAdaptor, useMcpAppContext } from "../bridges/index.js";
|
|
5
|
+
import { useHost } from "./use-host.js";
|
|
6
|
+
const ModelContextSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
updateId: z.string().min(1),
|
|
9
|
+
content: z.array(ContentBlockSchema).optional(),
|
|
10
|
+
structuredContent: z.record(z.string(), z.unknown()).optional(),
|
|
11
|
+
})
|
|
12
|
+
.nullable();
|
|
13
|
+
/**
|
|
14
|
+
* Send content to the model through the MCP Apps `ui/update-model-context`
|
|
15
|
+
* request. Each `update` replaces what this hook sent before. Outside ChatGPT
|
|
16
|
+
* it is merged with the {@link useViewState} state, which wins on shared
|
|
17
|
+
* `structuredContent` keys.
|
|
18
|
+
*
|
|
19
|
+
* ChatGPT also reads the OpenAI presentation metadata, shows each block as a
|
|
20
|
+
* composer attachment and reports the attached context back:
|
|
21
|
+
* `_meta["openai/title"]`, `_meta["openai/thumbnail"]` on text blocks, and
|
|
22
|
+
* `annotations.audience: ["assistant"]` to hide a block from the user.
|
|
23
|
+
*
|
|
24
|
+
* - `supported`: whether the host advertises `updateModelContext` or
|
|
25
|
+
* `openai/modelContext`.
|
|
26
|
+
* - `context`: ChatGPT only, the attached context; `null` once the user
|
|
27
|
+
* removed it, `undefined` when the host never reported one.
|
|
28
|
+
* - `update`: replaces the context and resolves with ChatGPT's `updateId`,
|
|
29
|
+
* to compare with `context.updateId`. Rejects with `NotSupportedError` on
|
|
30
|
+
* hosts that don't advertise model context updates.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const { supported, update } = useModelContext();
|
|
35
|
+
* update({
|
|
36
|
+
* content: [
|
|
37
|
+
* {
|
|
38
|
+
* type: "text",
|
|
39
|
+
* text: "Selected: M6 hex bolt",
|
|
40
|
+
* _meta: { "openai/title": "Hex bolt" },
|
|
41
|
+
* },
|
|
42
|
+
* ],
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @see https://docs.skybridge.tech/api-reference/use-model-context
|
|
47
|
+
*/
|
|
48
|
+
export function useModelContext() {
|
|
49
|
+
const { capabilities, openaiCapabilities } = useHost();
|
|
50
|
+
const reported = useMcpAppContext("openai/modelContext");
|
|
51
|
+
const context = useMemo(() => {
|
|
52
|
+
const parsed = ModelContextSchema.safeParse(reported);
|
|
53
|
+
return parsed.success ? parsed.data : undefined;
|
|
54
|
+
}, [reported]);
|
|
55
|
+
const update = useCallback((params) => getAdaptor().updateModelContext(params), []);
|
|
56
|
+
return {
|
|
57
|
+
supported: Boolean(capabilities?.updateModelContext) ||
|
|
58
|
+
openaiCapabilities.modelContext,
|
|
59
|
+
context,
|
|
60
|
+
update,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=use-model-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-model-context.js","sourceRoot":"","sources":["../../../src/web/hooks/use-model-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4B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AAC,YAAY,EAAE,kBAAkB,CAAC;YACzC,kBAAkB,CAAC,YAAY;QACjC,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import { ContentBlockSchema } from \"@modelcontextprotocol/core\";\nimport { useCallback, useMemo } from \"react\";\nimport * as z from \"zod/v4\";\nimport { getAdaptor, useMcpAppContext } from \"../bridges/index.js\";\nimport type { OpenAIHostContext } from \"../bridges/mcp-app/types.js\";\nimport type { ModelContextParams } from \"../bridges/types.js\";\nimport { useHost } from \"./use-host.js\";\n\nconst ModelContextSchema = z\n .object({\n updateId: z.string().min(1),\n content: z.array(ContentBlockSchema).optional(),\n structuredContent: z.record(z.string(), z.unknown()).optional(),\n })\n .nullable();\n\n/** Model context the view attached, as ChatGPT reports it back. */\nexport type ModelContextState = OpenAIHostContext[\"openai/modelContext\"];\n\n/**\n * Send content to the model through the MCP Apps `ui/update-model-context`\n * request. Each `update` replaces what this hook sent before. Outside ChatGPT\n * it is merged with the {@link useViewState} state, which wins on shared\n * `structuredContent` keys.\n *\n * ChatGPT also reads the OpenAI presentation metadata, shows each block as a\n * composer attachment and reports the attached context back:\n * `_meta[\"openai/title\"]`, `_meta[\"openai/thumbnail\"]` on text blocks, and\n * `annotations.audience: [\"assistant\"]` to hide a block from the user.\n *\n * - `supported`: whether the host advertises `updateModelContext` or\n * `openai/modelContext`.\n * - `context`: ChatGPT only, the attached context; `null` once the user\n * removed it, `undefined` when the host never reported one.\n * - `update`: replaces the context and resolves with ChatGPT's `updateId`,\n * to compare with `context.updateId`. Rejects with `NotSupportedError` on\n * hosts that don't advertise model context updates.\n *\n * @example\n * ```tsx\n * const { supported, update } = useModelContext();\n * update({\n * content: [\n * {\n * type: \"text\",\n * text: \"Selected: M6 hex bolt\",\n * _meta: { \"openai/title\": \"Hex bolt\" },\n * },\n * ],\n * });\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-model-context\n */\nexport function useModelContext(): {\n supported: boolean;\n context: ModelContextState;\n update: (params: ModelContextParams) => Promise<string | undefined>;\n} {\n const { capabilities, openaiCapabilities } = useHost();\n const reported = useMcpAppContext(\"openai/modelContext\");\n const context = useMemo(() => {\n const parsed = ModelContextSchema.safeParse(reported);\n return parsed.success ? parsed.data : undefined;\n }, [reported]);\n const update = useCallback(\n (params: ModelContextParams) => getAdaptor().updateModelContext(params),\n [],\n );\n\n return {\n supported:\n Boolean(capabilities?.updateModelContext) ||\n openaiCapabilities.modelContext,\n context,\n update,\n };\n}\n"]}
|
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
import type { OpenExternalOptions } from "../bridges/types.js";
|
|
2
|
+
/** Function that opens a URL outside the view's iframe, returned by {@link useOpenExternal}. */
|
|
2
3
|
export type OpenExternalFn = (href: string, options?: OpenExternalOptions) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Open an external URL through the host (e.g. in the user's browser).
|
|
6
|
+
*
|
|
7
|
+
* Use this instead of `window.open` or anchor `target="_blank"`, which are
|
|
8
|
+
* unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.
|
|
9
|
+
* ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass
|
|
10
|
+
* `redirectUrl: false` to suppress it).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const openExternal = useOpenExternal();
|
|
15
|
+
* <button onClick={() => openExternal("https://example.com")}>Open docs</button>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-open-external
|
|
19
|
+
*/
|
|
3
20
|
export declare function useOpenExternal(): OpenExternalFn;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Open an external URL through the host (e.g. in the user's browser).
|
|
5
|
+
*
|
|
6
|
+
* Use this instead of `window.open` or anchor `target="_blank"`, which are
|
|
7
|
+
* unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.
|
|
8
|
+
* ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass
|
|
9
|
+
* `redirectUrl: false` to suppress it).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const openExternal = useOpenExternal();
|
|
14
|
+
* <button onClick={() => openExternal("https://example.com")}>Open docs</button>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @see https://docs.skybridge.tech/api-reference/use-open-external
|
|
18
|
+
*/
|
|
3
19
|
export function useOpenExternal() {
|
|
4
20
|
const adaptor = getAdaptor();
|
|
5
21
|
const openExternal = useCallback((href, options) => adaptor.openExternal(href, options), [adaptor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AASjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,IAAY,EAAE,OAA6B,EAAE,EAAE,CAC9C,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EACrC,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type { OpenExternalOptions } from \"../bridges/types.js\";\n\n/** Function that opens a URL outside the view's iframe, returned by {@link useOpenExternal}. */\nexport type OpenExternalFn = (\n href: string,\n options?: OpenExternalOptions,\n) => void;\n\n/**\n * Open an external URL through the host (e.g. in the user's browser).\n *\n * Use this instead of `window.open` or anchor `target=\"_blank\"`, which are\n * unreliable inside a sandboxed iframe. Hosts may transform the URL (e.g.\n * ChatGPT appends a `?redirectUrl=…` parameter for allowlisted targets — pass\n * `redirectUrl: false` to suppress it).\n *\n * @example\n * ```tsx\n * const openExternal = useOpenExternal();\n * <button onClick={() => openExternal(\"https://example.com\")}>Open docs</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-open-external\n */\nexport function useOpenExternal(): OpenExternalFn {\n const adaptor = getAdaptor();\n const openExternal = useCallback(\n (href: string, options?: OpenExternalOptions) =>\n adaptor.openExternal(href, options),\n [adaptor],\n );\n\n return openExternal;\n}\n"]}
|
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
3
4
|
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
4
5
|
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
5
6
|
import { useOpenExternal } from "./use-open-external.js";
|
|
6
7
|
describe("useOpenExternal", () => {
|
|
7
8
|
describe("apps-sdk host", () => {
|
|
8
9
|
let openExternalMock;
|
|
10
|
+
let postMessageMock;
|
|
9
11
|
beforeEach(() => {
|
|
10
12
|
openExternalMock = vi.fn();
|
|
11
13
|
vi.stubGlobal("openai", {
|
|
12
14
|
openExternal: openExternalMock,
|
|
13
15
|
});
|
|
14
|
-
vi.stubGlobal("skybridge", {
|
|
16
|
+
vi.stubGlobal("skybridge", {});
|
|
17
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
18
|
+
postMessageMock = getMcpAppHostPostMessageMock();
|
|
19
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
15
20
|
});
|
|
16
21
|
afterEach(() => {
|
|
22
|
+
HostAdaptor.resetInstance();
|
|
23
|
+
McpAppBridge.resetInstance();
|
|
17
24
|
vi.unstubAllGlobals();
|
|
18
25
|
vi.resetAllMocks();
|
|
19
26
|
});
|
|
20
|
-
it("should
|
|
27
|
+
it("should call window.openai.openExternal even without a redirectUrl option", () => {
|
|
21
28
|
const { result } = renderHook(() => useOpenExternal());
|
|
22
29
|
const href = "https://example.com";
|
|
23
30
|
result.current(href);
|
|
24
31
|
expect(openExternalMock).toHaveBeenCalledTimes(1);
|
|
25
32
|
expect(openExternalMock).toHaveBeenCalledWith({ href });
|
|
33
|
+
expect(postMessageMock).not.toHaveBeenCalledWith(expect.objectContaining({ method: "ui/open-link" }), "*");
|
|
26
34
|
});
|
|
27
|
-
it("should
|
|
35
|
+
it("should call window.openai.openExternal when redirectUrl is false", () => {
|
|
28
36
|
const { result } = renderHook(() => useOpenExternal());
|
|
29
37
|
const href = "https://example.com";
|
|
30
38
|
result.current(href, { redirectUrl: false });
|
|
@@ -38,15 +46,17 @@ describe("useOpenExternal", () => {
|
|
|
38
46
|
describe("mcp-app host", () => {
|
|
39
47
|
let postMessageMock;
|
|
40
48
|
beforeEach(() => {
|
|
41
|
-
vi.stubGlobal("
|
|
49
|
+
vi.stubGlobal("openai", undefined);
|
|
50
|
+
vi.stubGlobal("skybridge", {});
|
|
42
51
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
43
52
|
postMessageMock = getMcpAppHostPostMessageMock();
|
|
44
53
|
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
45
54
|
});
|
|
46
55
|
afterEach(async () => {
|
|
56
|
+
HostAdaptor.resetInstance();
|
|
57
|
+
McpAppBridge.resetInstance();
|
|
47
58
|
vi.unstubAllGlobals();
|
|
48
59
|
vi.resetAllMocks();
|
|
49
|
-
McpAppBridge.resetInstance();
|
|
50
60
|
});
|
|
51
61
|
it("should return a function that sends ui/open-link request to the MCP host", async () => {
|
|
52
62
|
const { result } = renderHook(() => useOpenExternal());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,gBAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,eA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MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;YAEvD,MAAM,IAAI,GAAG,qBAAqB,CAAC;YACnC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;YAE7C,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC;oBACtB,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,cAAc;oBACtB,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;iBACtB,CAAC,EACF,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { HostAdaptor } from \"../bridges/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useOpenExternal } from \"./use-open-external.js\";\n\ndescribe(\"useOpenExternal\", () => {\n describe(\"apps-sdk host\", () => {\n let openExternalMock: ReturnType<typeof vi.fn>;\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n openExternalMock = vi.fn();\n vi.stubGlobal(\"openai\", {\n openExternal: openExternalMock,\n });\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(() => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should call window.openai.openExternal even without a redirectUrl option\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href);\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({ href });\n expect(postMessageMock).not.toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/open-link\" }),\n \"*\",\n );\n });\n\n it(\"should call window.openai.openExternal when redirectUrl is false\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({\n href,\n redirectUrl: false,\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"openai\", undefined);\n vi.stubGlobal(\"skybridge\", {});\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n HostAdaptor.resetInstance();\n McpAppBridge.resetInstance();\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return a function that sends ui/open-link request to the MCP host\", async () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/open-link\",\n params: { url: href },\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ask ChatGPT to open a local file by its absolute path, through the OpenAI
|
|
3
|
+
* MCP extensions (`openai/files/open`). ChatGPT desktop only, with a path on
|
|
4
|
+
* the machine that runs ChatGPT, which shows the file in its built-in viewer
|
|
5
|
+
* rather than in the app's own file entrypoint. Rejects with `NotSupportedError` on
|
|
6
|
+
* hosts that don't advertise `openai/files`: check `useHost().openaiCapabilities.files`
|
|
7
|
+
* before showing the control.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const { openaiCapabilities } = useHost();
|
|
12
|
+
* const openFile = useOpenFile();
|
|
13
|
+
* if (openaiCapabilities.files) {
|
|
14
|
+
* return <button onClick={() => openFile(part.path)}>Open in ChatGPT</button>;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.skybridge.tech/api-reference/use-open-file
|
|
19
|
+
*/
|
|
20
|
+
export declare function useOpenFile(): (path: string) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ask ChatGPT to open a local file by its absolute path, through the OpenAI
|
|
5
|
+
* MCP extensions (`openai/files/open`). ChatGPT desktop only, with a path on
|
|
6
|
+
* the machine that runs ChatGPT, which shows the file in its built-in viewer
|
|
7
|
+
* rather than in the app's own file entrypoint. Rejects with `NotSupportedError` on
|
|
8
|
+
* hosts that don't advertise `openai/files`: check `useHost().openaiCapabilities.files`
|
|
9
|
+
* before showing the control.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const { openaiCapabilities } = useHost();
|
|
14
|
+
* const openFile = useOpenFile();
|
|
15
|
+
* if (openaiCapabilities.files) {
|
|
16
|
+
* return <button onClick={() => openFile(part.path)}>Open in ChatGPT</button>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see https://docs.skybridge.tech/api-reference/use-open-file
|
|
21
|
+
*/
|
|
22
|
+
export function useOpenFile() {
|
|
23
|
+
return useCallback((path) => getAdaptor().openFile(path), []);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=use-open-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-open-file.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,WAAW,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\n/**\n * Ask ChatGPT to open a local file by its absolute path, through the OpenAI\n * MCP extensions (`openai/files/open`). ChatGPT desktop only, with a path on\n * the machine that runs ChatGPT, which shows the file in its built-in viewer\n * rather than in the app's own file entrypoint. Rejects with `NotSupportedError` on\n * hosts that don't advertise `openai/files`: check `useHost().openaiCapabilities.files`\n * before showing the control.\n *\n * @example\n * ```tsx\n * const { openaiCapabilities } = useHost();\n * const openFile = useOpenFile();\n * if (openaiCapabilities.files) {\n * return <button onClick={() => openFile(part.path)}>Open in ChatGPT</button>;\n * }\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-open-file\n */\nexport function useOpenFile(): (path: string) => Promise<void> {\n return useCallback((path: string) => getAdaptor().openFile(path), []);\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ViewToolConfig, ViewToolHandler, ViewToolInputShape } from "../bridges/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Register a tool the view exposes to the host and model — the MCP Apps
|
|
4
|
+
* "app-provided tools" feature. A view tool runs *inside the view*: the host
|
|
5
|
+
* discovers it via `tools/list` and invokes it via `tools/call`, and the
|
|
6
|
+
* handler executes against the view's live state. It is the inverse of
|
|
7
|
+
* {@link useCallTool} (which calls a server tool). Registered on mount, removed
|
|
8
|
+
* on unmount; re-registered when `config.name` changes.
|
|
9
|
+
*
|
|
10
|
+
* MCP Apps only — on the ChatGPT (`window.openai`) runtime it is a no-op.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import * as z from "zod";
|
|
15
|
+
* import { useRegisterViewTool } from "skybridge/web";
|
|
16
|
+
*
|
|
17
|
+
* useRegisterViewTool(
|
|
18
|
+
* {
|
|
19
|
+
* name: "chess_make_move",
|
|
20
|
+
* description: "Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.",
|
|
21
|
+
* inputSchema: { san: z.string() },
|
|
22
|
+
* annotations: { readOnlyHint: false },
|
|
23
|
+
* },
|
|
24
|
+
* ({ san }) => {
|
|
25
|
+
* const move = game.move(san);
|
|
26
|
+
* return {
|
|
27
|
+
* content: [{ type: "text", text: move ? `Played ${move.san}` : "Illegal move" }],
|
|
28
|
+
* structuredContent: { fen: game.fen() },
|
|
29
|
+
* isError: !move,
|
|
30
|
+
* };
|
|
31
|
+
* },
|
|
32
|
+
* );
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see https://docs.skybridge.tech/api-reference/use-register-view-tool
|
|
36
|
+
*/
|
|
37
|
+
export declare const useRegisterViewTool: <TInput extends ViewToolInputShape = ViewToolInputShape>(config: ViewToolConfig<TInput>, handler: ViewToolHandler<TInput>) => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Register a tool the view exposes to the host and model — the MCP Apps
|
|
5
|
+
* "app-provided tools" feature. A view tool runs *inside the view*: the host
|
|
6
|
+
* discovers it via `tools/list` and invokes it via `tools/call`, and the
|
|
7
|
+
* handler executes against the view's live state. It is the inverse of
|
|
8
|
+
* {@link useCallTool} (which calls a server tool). Registered on mount, removed
|
|
9
|
+
* on unmount; re-registered when `config.name` changes.
|
|
10
|
+
*
|
|
11
|
+
* MCP Apps only — on the ChatGPT (`window.openai`) runtime it is a no-op.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import * as z from "zod";
|
|
16
|
+
* import { useRegisterViewTool } from "skybridge/web";
|
|
17
|
+
*
|
|
18
|
+
* useRegisterViewTool(
|
|
19
|
+
* {
|
|
20
|
+
* name: "chess_make_move",
|
|
21
|
+
* description: "Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.",
|
|
22
|
+
* inputSchema: { san: z.string() },
|
|
23
|
+
* annotations: { readOnlyHint: false },
|
|
24
|
+
* },
|
|
25
|
+
* ({ san }) => {
|
|
26
|
+
* const move = game.move(san);
|
|
27
|
+
* return {
|
|
28
|
+
* content: [{ type: "text", text: move ? `Played ${move.san}` : "Illegal move" }],
|
|
29
|
+
* structuredContent: { fen: game.fen() },
|
|
30
|
+
* isError: !move,
|
|
31
|
+
* };
|
|
32
|
+
* },
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see https://docs.skybridge.tech/api-reference/use-register-view-tool
|
|
37
|
+
*/
|
|
38
|
+
export const useRegisterViewTool = (config, handler) => {
|
|
39
|
+
const { name } = config;
|
|
40
|
+
const configRef = useRef(config);
|
|
41
|
+
configRef.current = config;
|
|
42
|
+
const handlerRef = useRef(handler);
|
|
43
|
+
handlerRef.current = handler;
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const adaptor = getAdaptor();
|
|
46
|
+
const wrappedHandler = (args) => handlerRef.current(args);
|
|
47
|
+
return adaptor.registerViewTool({ ...configRef.current, name }, wrappedHandler);
|
|
48
|
+
}, [name]);
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=use-register-view-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-register-view-tool.js","sourceRoot":"","sources":["../../../src/web/hooks/use-register-view-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAGjC,MAA8B,EAC9B,OAAgC,EAChC,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAuB,CAAC,IAAI,EAAE,EAAE,CAClD,UAAU,CAAC,OAAO,CAAC,IAA8C,CAAC,CAAC;QAErE,OAAO,OAAO,CAAC,gBAAgB,CAC7B,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAC9B,cAAc,CACf,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\nimport type {\n AnyViewToolHandler,\n ViewToolConfig,\n ViewToolHandler,\n ViewToolInputShape,\n} from \"../bridges/types.js\";\n\n/**\n * Register a tool the view exposes to the host and model — the MCP Apps\n * \"app-provided tools\" feature. A view tool runs *inside the view*: the host\n * discovers it via `tools/list` and invokes it via `tools/call`, and the\n * handler executes against the view's live state. It is the inverse of\n * {@link useCallTool} (which calls a server tool). Registered on mount, removed\n * on unmount; re-registered when `config.name` changes.\n *\n * MCP Apps only — on the ChatGPT (`window.openai`) runtime it is a no-op.\n *\n * @example\n * ```tsx\n * import * as z from \"zod\";\n * import { useRegisterViewTool } from \"skybridge/web\";\n *\n * useRegisterViewTool(\n * {\n * name: \"chess_make_move\",\n * description: \"Play a move in algebraic notation, e.g. 'e4' or 'Nf3'.\",\n * inputSchema: { san: z.string() },\n * annotations: { readOnlyHint: false },\n * },\n * ({ san }) => {\n * const move = game.move(san);\n * return {\n * content: [{ type: \"text\", text: move ? `Played ${move.san}` : \"Illegal move\" }],\n * structuredContent: { fen: game.fen() },\n * isError: !move,\n * };\n * },\n * );\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-register-view-tool\n */\nexport const useRegisterViewTool = <\n TInput extends ViewToolInputShape = ViewToolInputShape,\n>(\n config: ViewToolConfig<TInput>,\n handler: ViewToolHandler<TInput>,\n) => {\n const { name } = config;\n const configRef = useRef(config);\n configRef.current = config;\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n\n useEffect(() => {\n const adaptor = getAdaptor();\n const wrappedHandler: AnyViewToolHandler = (args) =>\n handlerRef.current(args as Parameters<ViewToolHandler<TInput>>[0]);\n\n return adaptor.registerViewTool(\n { ...configRef.current, name },\n wrappedHandler,\n );\n }, [name]);\n};\n"]}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
/** Function that asks the host to close the current view, returned by {@link useRequestClose}. */
|
|
1
2
|
export type RequestCloseFn = () => Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Ask the host to close (dismiss) the current view. The host decides whether
|
|
5
|
+
* to honor the request. Useful from modal views or after a terminal action
|
|
6
|
+
* like "Done".
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const close = useRequestClose();
|
|
11
|
+
* <button onClick={() => close()}>Done</button>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-close
|
|
15
|
+
*/
|
|
2
16
|
export declare function useRequestClose(): RequestCloseFn;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ask the host to close (dismiss) the current view. The host decides whether
|
|
5
|
+
* to honor the request. Useful from modal views or after a terminal action
|
|
6
|
+
* like "Done".
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const close = useRequestClose();
|
|
11
|
+
* <button onClick={() => close()}>Done</button>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.skybridge.tech/api-reference/use-request-close
|
|
15
|
+
*/
|
|
3
16
|
export function useRequestClose() {
|
|
4
17
|
const adaptor = getAdaptor();
|
|
5
18
|
const requestClose = useCallback(() => adaptor.requestClose(), [adaptor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-close.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-request-close.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-close.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAE1E,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\n/** Function that asks the host to close the current view, returned by {@link useRequestClose}. */\nexport type RequestCloseFn = () => Promise<void>;\n\n/**\n * Ask the host to close (dismiss) the current view. The host decides whether\n * to honor the request. Useful from modal views or after a terminal action\n * like \"Done\".\n *\n * @example\n * ```tsx\n * const close = useRequestClose();\n * <button onClick={() => close()}>Done</button>\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/use-request-close\n */\nexport function useRequestClose(): RequestCloseFn {\n const adaptor = getAdaptor();\n const requestClose = useCallback(() => adaptor.requestClose(), [adaptor]);\n\n return requestClose;\n}\n"]}
|
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { HostAdaptor } from "../bridges/adaptor.js";
|
|
4
|
+
import { getAdaptor } from "../bridges/get-adaptor.js";
|
|
3
5
|
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
4
|
-
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
5
6
|
import { useRequestClose } from "./use-request-close.js";
|
|
6
7
|
describe("useRequestClose", () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
HostAdaptor.resetInstance();
|
|
10
|
+
McpAppBridge.resetInstance();
|
|
11
|
+
vi.stubGlobal("skybridge", {});
|
|
12
|
+
vi.stubGlobal("openai", undefined);
|
|
13
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
vi.resetAllMocks();
|
|
18
|
+
HostAdaptor.resetInstance();
|
|
19
|
+
McpAppBridge.resetInstance();
|
|
20
|
+
});
|
|
21
|
+
it("calls app.requestTeardown via the MCP path", async () => {
|
|
22
|
+
const requestTeardown = vi.fn().mockResolvedValue(undefined);
|
|
23
|
+
// biome-ignore lint/suspicious/noExplicitAny: test seam
|
|
24
|
+
const adaptor = getAdaptor();
|
|
25
|
+
adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });
|
|
26
|
+
const { result } = renderHook(() => useRequestClose());
|
|
27
|
+
await act(async () => {
|
|
22
28
|
await result.current();
|
|
23
|
-
expect(requestCloseMock).toHaveBeenCalledTimes(1);
|
|
24
|
-
expect(requestCloseMock).toHaveBeenCalledWith();
|
|
25
29
|
});
|
|
30
|
+
expect(requestTeardown).toHaveBeenCalledTimes(1);
|
|
26
31
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
vi.resetAllMocks();
|
|
38
|
-
McpAppBridge.resetInstance();
|
|
39
|
-
});
|
|
40
|
-
it("should send a ui/notifications/request-teardown notification to the MCP host", async () => {
|
|
41
|
-
const { result } = renderHook(() => useRequestClose());
|
|
32
|
+
it("calls app.requestTeardown even when window.openai is present", async () => {
|
|
33
|
+
vi.stubGlobal("openai", { requestClose: vi.fn() });
|
|
34
|
+
HostAdaptor.resetInstance();
|
|
35
|
+
McpAppBridge.resetInstance();
|
|
36
|
+
const requestTeardown = vi.fn().mockResolvedValue(undefined);
|
|
37
|
+
// biome-ignore lint/suspicious/noExplicitAny: test seam
|
|
38
|
+
const adaptor = getAdaptor();
|
|
39
|
+
adaptor.mcp.getApp = vi.fn().mockResolvedValue({ requestTeardown });
|
|
40
|
+
const { result } = renderHook(() => useRequestClose());
|
|
41
|
+
await act(async () => {
|
|
42
42
|
await result.current();
|
|
43
|
-
await waitFor(() => {
|
|
44
|
-
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
45
|
-
jsonrpc: "2.0",
|
|
46
|
-
method: "ui/notifications/request-teardown",
|
|
47
|
-
}), "*");
|
|
48
|
-
});
|
|
49
43
|
});
|
|
44
|
+
expect(requestTeardown).toHaveBeenCalledTimes(1);
|
|
50
45
|
});
|
|
51
46
|
});
|
|
52
47
|
//# sourceMappingURL=use-request-close.test.js.map
|