skybridge 0.0.0-dev.dc4ed16 → 0.0.0-dev.dc576c4
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/LICENSE +21 -674
- package/README.md +123 -386
- package/bin/run.js +5 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/telemetry.d.ts +7 -0
- package/dist/cli/telemetry.js +123 -0
- package/dist/cli/telemetry.js.map +1 -0
- 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 +11 -0
- package/dist/cli/use-execute-steps.js +36 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- 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 +2 -0
- package/dist/cli/use-nodemon.js +73 -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 +9 -0
- package/dist/cli/use-typescript-check.js +94 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +87 -0
- package/dist/commands/build.js.map +1 -0
- 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 +12 -0
- package/dist/commands/dev.js +96 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.js +49 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.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.js +134 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/auth.d.ts +20 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/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.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +11 -0
- package/dist/server/express.js +101 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.js +430 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/{src/server → server}/inferUtilityTypes.d.ts +15 -5
- package/dist/server/inferUtilityTypes.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 +137 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +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.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +398 -0
- package/dist/server/server.js +561 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +5 -4
- package/dist/server/templateHelper.js +11 -0
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates.generated.d.ts +4 -0
- package/dist/server/templates.generated.js +47 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tunnel-proxy-router.d.ts +7 -0
- package/dist/server/tunnel-proxy-router.js +110 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/viewsDevServer.d.ts +14 -0
- package/dist/server/viewsDevServer.js +45 -0
- package/dist/server/viewsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +127 -0
- package/dist/test/utils.js +247 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/view.test.js +568 -0
- package/dist/test/view.test.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/adaptor.d.ts +48 -0
- package/dist/web/bridges/adaptor.js +308 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.js +205 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/bridge.js +46 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +4 -0
- package/dist/web/bridges/apps-sdk/index.js +4 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/web/bridges/apps-sdk/types.d.ts +133 -0
- package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +13 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +18 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +11 -0
- package/dist/web/bridges/get-adaptor.js +30 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/get-adaptor.test.js +48 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/host-context-stores.d.ts +27 -0
- package/dist/web/bridges/host-context-stores.js +73 -0
- package/dist/web/bridges/host-context-stores.js.map +1 -0
- package/dist/web/bridges/index.d.ts +5 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +27 -0
- package/dist/web/bridges/mcp-app/bridge.js +100 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +21 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +3 -0
- package/dist/web/bridges/mcp-app/index.js +3 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +8 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +19 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +19 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +186 -0
- package/dist/web/bridges/types.js +15 -0
- package/dist/web/bridges/types.js.map +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 +7 -0
- package/dist/web/bridges/use-host-context.js +13 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +4 -0
- package/dist/web/components/modal-provider.js +46 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.d.ts +29 -0
- package/dist/web/create-store.js +64 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.js +131 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/web/data-llm.d.ts +47 -0
- package/dist/{src/web → web}/data-llm.js +41 -9
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +145 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +32 -25
- package/dist/{src/web → web}/generate-helpers.js +26 -20
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +79 -23
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test.js +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.d.ts +2 -2
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.d.ts +1 -0
- package/dist/web/helpers/state.test.js +53 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/web/hooks/index.d.ts +14 -0
- package/dist/web/hooks/index.js +15 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +20 -0
- package/dist/web/hooks/test/utils.js +75 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +48 -2
- package/dist/web/hooks/use-call-tool.js +96 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +92 -39
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +24 -0
- package/dist/web/hooks/use-display-mode.js +29 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- 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.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test.js +76 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-download.d.ts +5 -0
- package/dist/web/hooks/use-download.js +8 -0
- package/dist/web/hooks/use-download.js.map +1 -0
- package/dist/web/hooks/use-download.test.d.ts +1 -0
- package/dist/web/hooks/use-download.test.js +103 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +39 -0
- package/dist/web/hooks/use-files.js +42 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/web/hooks/use-files.test.d.ts +1 -0
- package/dist/web/hooks/use-files.test.js +62 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +24 -0
- package/dist/web/hooks/use-layout.js +25 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/web/hooks/use-layout.test.js +129 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +20 -0
- package/dist/web/hooks/use-open-external.js +24 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/web/hooks/use-open-external.test.js +79 -0
- package/dist/web/hooks/use-open-external.test.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 +46 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +24 -0
- package/dist/web/hooks/use-request-modal.js +31 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/web/hooks/use-request-modal.test.js +71 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- 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 -0
- package/dist/web/hooks/use-send-follow-up-message.js +25 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +18 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +25 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +63 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
- package/dist/web/hooks/use-tool-info.d.ts +69 -0
- package/dist/web/hooks/use-tool-info.js +52 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test.js +140 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +20 -0
- package/dist/web/hooks/use-user.js +37 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +168 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-view-state.d.ts +25 -0
- package/dist/web/hooks/use-view-state.js +32 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +181 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +5 -5
- package/dist/{src/web → web}/index.js +5 -5
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-view.d.ts +20 -0
- package/dist/web/mount-view.js +46 -0
- package/dist/web/mount-view.js.map +1 -0
- package/dist/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +33 -0
- package/dist/web/plugin/plugin.js +189 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/web/plugin/scan-views.d.ts +16 -0
- package/dist/web/plugin/scan-views.js +88 -0
- package/dist/web/plugin/scan-views.js.map +1 -0
- package/dist/web/plugin/scan-views.test.d.ts +1 -0
- package/dist/web/plugin/scan-views.test.js +99 -0
- package/dist/web/plugin/scan-views.test.js.map +1 -0
- package/dist/{src/web → web}/plugin/transform-data-llm.js +7 -4
- package/dist/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/web/plugin/validate-view.d.ts +1 -0
- package/dist/web/plugin/validate-view.js +9 -0
- package/dist/web/plugin/validate-view.js.map +1 -0
- package/dist/web/plugin/validate-view.test.d.ts +1 -0
- package/dist/web/plugin/validate-view.test.js +24 -0
- package/dist/web/plugin/validate-view.test.js.map +1 -0
- package/dist/{src/web → web}/proxy.js +6 -2
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +20 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +83 -38
- package/tsconfig.base.json +33 -0
- package/dist/src/server/index.d.ts +0 -4
- package/dist/src/server/index.js +0 -3
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/inferUtilityTypes.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -48
- package/dist/src/server/server.js +0 -62
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js +0 -29
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -12
- package/dist/src/server/templates/production.hbs +0 -6
- package/dist/src/server/widgetsDevServer.d.ts +0 -12
- package/dist/src/server/widgetsDevServer.js +0 -39
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.d.ts +0 -89
- package/dist/src/test/utils.js +0 -164
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -90
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/create-store.d.ts +0 -3
- package/dist/src/web/create-store.js +0 -25
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/data-llm.d.ts +0 -14
- package/dist/src/web/data-llm.js.map +0 -1
- package/dist/src/web/data-llm.test.js +0 -76
- package/dist/src/web/data-llm.test.js.map +0 -1
- package/dist/src/web/generate-helpers.js.map +0 -1
- package/dist/src/web/generate-helpers.test-d.js.map +0 -1
- package/dist/src/web/generate-helpers.test.js.map +0 -1
- package/dist/src/web/helpers/state.js +0 -40
- package/dist/src/web/helpers/state.js.map +0 -1
- package/dist/src/web/helpers/state.test.js +0 -46
- package/dist/src/web/helpers/state.test.js.map +0 -1
- package/dist/src/web/hooks/index.d.ts +0 -12
- package/dist/src/web/hooks/index.js +0 -13
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js +0 -60
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +0 -4
- package/dist/src/web/hooks/use-display-mode.js +0 -7
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js +0 -40
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-files.d.ts +0 -10
- package/dist/src/web/hooks/use-files.js +0 -7
- package/dist/src/web/hooks/use-files.js.map +0 -1
- package/dist/src/web/hooks/use-files.test.js +0 -29
- package/dist/src/web/hooks/use-files.test.js.map +0 -1
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.d.ts +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
- package/dist/src/web/hooks/use-openai-global.js +0 -23
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
- package/dist/src/web/hooks/use-request-modal.js +0 -9
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js +0 -24
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.d.ts +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +0 -25
- package/dist/src/web/hooks/use-tool-info.js +0 -22
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -59
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.d.ts +0 -4
- package/dist/src/web/hooks/use-widget-state.js +0 -32
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js +0 -60
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.d.ts +0 -1
- package/dist/src/web/mount-widget.js +0 -19
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin/data-llm.test.js.map +0 -1
- package/dist/src/web/plugin/plugin.d.ts +0 -2
- package/dist/src/web/plugin/plugin.js +0 -33
- package/dist/src/web/plugin/plugin.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/src/web/proxy.js.map +0 -1
- package/dist/src/web/types.d.ts +0 -133
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/helpers/state.test.d.ts → server/content-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/middleware.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → server/middleware.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → server/tunnel-proxy-router.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → test/view.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/bridges/adaptor.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/bridges/get-adaptor.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → web/bridges/mcp-app/bridge.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/bridges/types.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
- /package/dist/{src/web → web}/proxy.d.ts +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { McpAppBridge } from "./mcp-app/bridge.js";
|
|
2
|
+
import type { HostContextStore } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build the host-context store map sourced from the MCP App bridge.
|
|
5
|
+
* `display` and `viewState` are *not* included here; those are handled
|
|
6
|
+
* by the adaptor itself because they have transport-specific overlays
|
|
7
|
+
* and additional state (polyfill modal state, localStorage hydration).
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildMcpContextStores(bridge: McpAppBridge): {
|
|
10
|
+
theme: HostContextStore<"theme">;
|
|
11
|
+
locale: HostContextStore<"locale">;
|
|
12
|
+
safeArea: HostContextStore<"safeArea">;
|
|
13
|
+
displayMode: HostContextStore<"displayMode">;
|
|
14
|
+
maxHeight: HostContextStore<"maxHeight">;
|
|
15
|
+
userAgent: HostContextStore<"userAgent">;
|
|
16
|
+
toolInput: HostContextStore<"toolInput">;
|
|
17
|
+
toolOutput: HostContextStore<"toolOutput">;
|
|
18
|
+
toolResponseMetadata: HostContextStore<"toolResponseMetadata">;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).
|
|
22
|
+
* Used by `HostAdaptor` only when `window.openai` is present.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildAppsSdkOverlayStores(bridge: import("./apps-sdk/bridge.js").AppsSdkBridge): {
|
|
25
|
+
display: HostContextStore<"display">;
|
|
26
|
+
viewState: HostContextStore<"viewState">;
|
|
27
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { dequal } from "dequal/lite";
|
|
2
|
+
/**
|
|
3
|
+
* Build a memoized {@link HostContextStore} backed by one or more
|
|
4
|
+
* `McpAppBridge` context keys. Recomputed values are deep-compared via
|
|
5
|
+
* `dequal` so unchanged snapshots return the cached reference.
|
|
6
|
+
*/
|
|
7
|
+
function createMcpStore(bridge, keys, computeSnapshot) {
|
|
8
|
+
let cachedValue;
|
|
9
|
+
return {
|
|
10
|
+
subscribe: bridge.subscribe(keys),
|
|
11
|
+
getSnapshot: () => {
|
|
12
|
+
const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
|
|
13
|
+
const newValue = computeSnapshot(context);
|
|
14
|
+
if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
|
|
15
|
+
return cachedValue;
|
|
16
|
+
}
|
|
17
|
+
cachedValue = newValue;
|
|
18
|
+
return newValue;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build the host-context store map sourced from the MCP App bridge.
|
|
24
|
+
* `display` and `viewState` are *not* included here; those are handled
|
|
25
|
+
* by the adaptor itself because they have transport-specific overlays
|
|
26
|
+
* and additional state (polyfill modal state, localStorage hydration).
|
|
27
|
+
*/
|
|
28
|
+
export function buildMcpContextStores(bridge) {
|
|
29
|
+
return {
|
|
30
|
+
theme: createMcpStore(bridge, ["theme"], ({ theme }) => theme ?? "light"),
|
|
31
|
+
locale: createMcpStore(bridge, ["locale"], ({ locale }) => locale ?? "en-US"),
|
|
32
|
+
safeArea: createMcpStore(bridge, ["safeAreaInsets"], ({ safeAreaInsets }) => ({
|
|
33
|
+
insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
|
|
34
|
+
})),
|
|
35
|
+
displayMode: createMcpStore(bridge, ["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
|
|
36
|
+
maxHeight: createMcpStore(bridge, ["containerDimensions"], ({ containerDimensions }) => {
|
|
37
|
+
if (containerDimensions && "maxHeight" in containerDimensions) {
|
|
38
|
+
return containerDimensions.maxHeight;
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}),
|
|
42
|
+
userAgent: createMcpStore(bridge, ["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
|
|
43
|
+
device: {
|
|
44
|
+
type: platform === "web" ? "desktop" : (platform ?? "unknown"),
|
|
45
|
+
},
|
|
46
|
+
capabilities: {
|
|
47
|
+
hover: true,
|
|
48
|
+
touch: true,
|
|
49
|
+
...deviceCapabilities,
|
|
50
|
+
},
|
|
51
|
+
})),
|
|
52
|
+
toolInput: createMcpStore(bridge, ["toolInput"], ({ toolInput }) => toolInput ?? null),
|
|
53
|
+
toolOutput: createMcpStore(bridge, ["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
|
|
54
|
+
toolResponseMetadata: createMcpStore(bridge, ["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).
|
|
59
|
+
* Used by `HostAdaptor` only when `window.openai` is present.
|
|
60
|
+
*/
|
|
61
|
+
export function buildAppsSdkOverlayStores(bridge) {
|
|
62
|
+
return {
|
|
63
|
+
display: {
|
|
64
|
+
subscribe: bridge.subscribe("view"),
|
|
65
|
+
getSnapshot: () => bridge.getSnapshot("view"),
|
|
66
|
+
},
|
|
67
|
+
viewState: {
|
|
68
|
+
subscribe: bridge.subscribe("widgetState"),
|
|
69
|
+
getSnapshot: () => bridge.getSnapshot("widgetState")?.modelContent ?? null,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=host-context-stores.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-context-stores.js","sourceRoot":"","sources":["../../../src/web/bridges/host-context-stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC;;;;GAIG;AACH,SAAS,cAAc,CACrB,MAAoB,EACpB,IAAU,EACV,eAAkD;IAElD,IAAI,WAA0B,CAAC;IAC/B,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QACjC,WAAW,EAAE,GAAG,EAAE;YAChB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CAAC;YACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;gBAC/D,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,WAAW,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I,EAAE,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,SAAS,CAAC;aAC/D;YACD,YAAY,EAAE;gBACZ,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,IAAI;gBACX,GAAG,kBAAkB;aACtB;SACF,CAAC,CACH;QACD,SAAS,EAAE,cAAc,CACvB,MAAM,EACN,CAAC,WAAW,CAAC,EACb,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,IAAI,IAAI,CACrC;QACD,UAAU,EAAE,cAAc,CACxB,MAAM,EACN,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,iBAAiB,IAAI,IAAI,CAC1D;QACD,oBAAoB,EAAE,cAAc,CAClC,MAAM,EACN,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,KAAK,IAAI,IAAI,CAC9C;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAoD;IAKpD,OAAO;QACL,OAAO,EAAE;YACP,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YACnC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;SAC9C;QACD,SAAS,EAAE;YACT,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC;YAC1C,WAAW,EAAE,GAAG,EAAE,CAChB,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,IAAI,IAAI;SAC1D;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport type { McpAppBridge } from \"./mcp-app/bridge.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./mcp-app/types.js\";\nimport type { HostContextStore } from \"./types.js\";\n\ntype PickContext<K extends readonly McpAppContextKey[]> = {\n [P in K[number]]: McpAppContext[P];\n};\n\n/**\n * Build a memoized {@link HostContextStore} backed by one or more\n * `McpAppBridge` context keys. Recomputed values are deep-compared via\n * `dequal` so unchanged snapshots return the cached reference.\n */\nfunction createMcpStore<const Keys extends readonly McpAppContextKey[], R>(\n bridge: McpAppBridge,\n keys: Keys,\n computeSnapshot: (context: PickContext<Keys>) => R,\n) {\n let cachedValue: R | undefined;\n return {\n subscribe: bridge.subscribe(keys),\n getSnapshot: () => {\n const context = Object.fromEntries(\n keys.map((k) => [k, bridge.getSnapshot(k)]),\n ) as PickContext<Keys>;\n const newValue = computeSnapshot(context);\n if (cachedValue !== undefined && dequal(cachedValue, newValue)) {\n return cachedValue;\n }\n cachedValue = newValue;\n return newValue;\n },\n };\n}\n\n/**\n * Build the host-context store map sourced from the MCP App bridge.\n * `display` and `viewState` are *not* included here; those are handled\n * by the adaptor itself because they have transport-specific overlays\n * and additional state (polyfill modal state, localStorage hydration).\n */\nexport function buildMcpContextStores(bridge: McpAppBridge): {\n theme: HostContextStore<\"theme\">;\n locale: HostContextStore<\"locale\">;\n safeArea: HostContextStore<\"safeArea\">;\n displayMode: HostContextStore<\"displayMode\">;\n maxHeight: HostContextStore<\"maxHeight\">;\n userAgent: HostContextStore<\"userAgent\">;\n toolInput: HostContextStore<\"toolInput\">;\n toolOutput: HostContextStore<\"toolOutput\">;\n toolResponseMetadata: HostContextStore<\"toolResponseMetadata\">;\n} {\n return {\n theme: createMcpStore(bridge, [\"theme\"], ({ theme }) => theme ?? \"light\"),\n locale: createMcpStore(\n bridge,\n [\"locale\"],\n ({ locale }) => locale ?? \"en-US\",\n ),\n safeArea: createMcpStore(\n bridge,\n [\"safeAreaInsets\"],\n ({ safeAreaInsets }) => ({\n insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },\n }),\n ),\n displayMode: createMcpStore(\n bridge,\n [\"displayMode\"],\n ({ displayMode }) => displayMode ?? \"inline\",\n ),\n maxHeight: createMcpStore(\n bridge,\n [\"containerDimensions\"],\n ({ containerDimensions }) => {\n if (containerDimensions && \"maxHeight\" in containerDimensions) {\n return containerDimensions.maxHeight;\n }\n return undefined;\n },\n ),\n userAgent: createMcpStore(\n bridge,\n [\"platform\", \"deviceCapabilities\"],\n ({ platform, deviceCapabilities }) => ({\n device: {\n type: platform === \"web\" ? \"desktop\" : (platform ?? \"unknown\"),\n },\n capabilities: {\n hover: true,\n touch: true,\n ...deviceCapabilities,\n },\n }),\n ),\n toolInput: createMcpStore(\n bridge,\n [\"toolInput\"],\n ({ toolInput }) => toolInput ?? null,\n ),\n toolOutput: createMcpStore(\n bridge,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?.structuredContent ?? null,\n ),\n toolResponseMetadata: createMcpStore(\n bridge,\n [\"toolResult\"],\n ({ toolResult }) => toolResult?._meta ?? null,\n ),\n };\n}\n\n/**\n * Build the Apps-SDK-sourced overlay stores (`display`, `viewState`).\n * Used by `HostAdaptor` only when `window.openai` is present.\n */\nexport function buildAppsSdkOverlayStores(\n bridge: import(\"./apps-sdk/bridge.js\").AppsSdkBridge,\n): {\n display: HostContextStore<\"display\">;\n viewState: HostContextStore<\"viewState\">;\n} {\n return {\n display: {\n subscribe: bridge.subscribe(\"view\"),\n getSnapshot: () => bridge.getSnapshot(\"view\"),\n },\n viewState: {\n subscribe: bridge.subscribe(\"widgetState\"),\n getSnapshot: () =>\n bridge.getSnapshot(\"widgetState\")?.modelContent ?? null,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export * from \"./apps-sdk/index.js\";\nexport { getAdaptor } from \"./get-adaptor.js\";\nexport * from \"./mcp-app/index.js\";\nexport * from \"./types.js\";\nexport { useHostContext } from \"./use-host-context.js\";\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { Bridge, Subscribe } from "../types.js";
|
|
4
|
+
import type { McpAppContext, McpAppContextKey } from "./types.js";
|
|
5
|
+
/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
|
|
6
|
+
export declare class McpAppBridge implements Bridge<McpAppContext> {
|
|
7
|
+
private static instance;
|
|
8
|
+
context: McpAppContext;
|
|
9
|
+
private listeners;
|
|
10
|
+
private app;
|
|
11
|
+
private connectPromise;
|
|
12
|
+
constructor(options: {
|
|
13
|
+
appInfo: Implementation;
|
|
14
|
+
});
|
|
15
|
+
private connect;
|
|
16
|
+
getApp(): Promise<App>;
|
|
17
|
+
static getInstance(options?: Partial<{
|
|
18
|
+
appInfo: Implementation;
|
|
19
|
+
}>): McpAppBridge;
|
|
20
|
+
subscribe(key: McpAppContextKey): Subscribe;
|
|
21
|
+
subscribe(keys: readonly McpAppContextKey[]): Subscribe;
|
|
22
|
+
getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
|
|
23
|
+
cleanup: () => void;
|
|
24
|
+
static resetInstance(): void;
|
|
25
|
+
private emit;
|
|
26
|
+
private updateContext;
|
|
27
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */
|
|
3
|
+
export class McpAppBridge {
|
|
4
|
+
static instance = null;
|
|
5
|
+
context = {
|
|
6
|
+
toolInput: null,
|
|
7
|
+
toolCancelled: null,
|
|
8
|
+
toolResult: null,
|
|
9
|
+
};
|
|
10
|
+
listeners = new Map();
|
|
11
|
+
app;
|
|
12
|
+
connectPromise;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.app = new App(options.appInfo);
|
|
15
|
+
this.app.ontoolinput = (params) => {
|
|
16
|
+
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
17
|
+
};
|
|
18
|
+
this.app.ontoolinputpartial = (params) => {
|
|
19
|
+
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
20
|
+
};
|
|
21
|
+
this.app.ontoolresult = (params) => {
|
|
22
|
+
this.updateContext({ toolResult: params });
|
|
23
|
+
};
|
|
24
|
+
this.app.ontoolcancelled = (params) => {
|
|
25
|
+
this.updateContext({ toolCancelled: params });
|
|
26
|
+
};
|
|
27
|
+
this.app.onhostcontextchanged = (params) => {
|
|
28
|
+
this.updateContext(params);
|
|
29
|
+
};
|
|
30
|
+
this.connectPromise = this.connect();
|
|
31
|
+
}
|
|
32
|
+
async connect() {
|
|
33
|
+
try {
|
|
34
|
+
await this.app.connect();
|
|
35
|
+
const hostContext = this.app.getHostContext();
|
|
36
|
+
if (hostContext) {
|
|
37
|
+
this.updateContext(hostContext);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.error(err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async getApp() {
|
|
45
|
+
await this.connectPromise;
|
|
46
|
+
return this.app;
|
|
47
|
+
}
|
|
48
|
+
static getInstance(options) {
|
|
49
|
+
if (McpAppBridge.instance && options) {
|
|
50
|
+
console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
|
|
51
|
+
}
|
|
52
|
+
if (!McpAppBridge.instance) {
|
|
53
|
+
const defaultOptions = {
|
|
54
|
+
appInfo: { name: "skybridge-app", version: "0.0.1" },
|
|
55
|
+
};
|
|
56
|
+
McpAppBridge.instance = new McpAppBridge({
|
|
57
|
+
...defaultOptions,
|
|
58
|
+
...options,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return McpAppBridge.instance;
|
|
62
|
+
}
|
|
63
|
+
subscribe(keyOrKeys) {
|
|
64
|
+
const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
65
|
+
return (onChange) => {
|
|
66
|
+
for (const key of keys) {
|
|
67
|
+
this.listeners.set(key, new Set([...(this.listeners.get(key) || []), onChange]));
|
|
68
|
+
}
|
|
69
|
+
return () => {
|
|
70
|
+
for (const key of keys) {
|
|
71
|
+
this.listeners.get(key)?.delete(onChange);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
getSnapshot(key) {
|
|
77
|
+
return this.context[key];
|
|
78
|
+
}
|
|
79
|
+
cleanup = () => {
|
|
80
|
+
this.listeners.clear();
|
|
81
|
+
};
|
|
82
|
+
static resetInstance() {
|
|
83
|
+
if (McpAppBridge.instance) {
|
|
84
|
+
McpAppBridge.instance.cleanup();
|
|
85
|
+
McpAppBridge.instance = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
emit(key) {
|
|
89
|
+
this.listeners.get(key)?.forEach((listener) => {
|
|
90
|
+
listener();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
updateContext(context) {
|
|
94
|
+
this.context = { ...this.context, ...context };
|
|
95
|
+
for (const key of Object.keys(context)) {
|
|
96
|
+
this.emit(key);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAKrD,qGAAqG;AACrG,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE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AI,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CACxD,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,EAAE;gBACV,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;oBACvB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC5C,CAAC;YACH,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,CAAgC,GAAM;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,GAAG,GAAG,EAAE;QACpB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC;IAEK,MAAM,CAAC,aAAa;QACzB,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC1B,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,GAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC","sourcesContent":["import { App } from \"@modelcontextprotocol/ext-apps\";\nimport type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { Bridge, Subscribe } from \"../types.js\";\nimport type { McpAppContext, McpAppContextKey } from \"./types.js\";\n\n/** @internal Singleton bridge over the `ext-apps` JSON-RPC App connection. Used by `HostAdaptor`. */\nexport class McpAppBridge implements Bridge<McpAppContext> {\n private static instance: McpAppBridge | null = null;\n public context: McpAppContext = {\n toolInput: null,\n toolCancelled: null,\n toolResult: null,\n };\n private listeners = new Map<McpAppContextKey, Set<() => void>>();\n private app: App;\n private connectPromise: Promise<void>;\n\n constructor(options: { appInfo: Implementation }) {\n this.app = new App(options.appInfo);\n\n this.app.ontoolinput = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolinputpartial = (params) => {\n this.updateContext({ toolInput: params.arguments ?? {} });\n };\n\n this.app.ontoolresult = (params) => {\n this.updateContext({ toolResult: params });\n };\n\n this.app.ontoolcancelled = (params) => {\n this.updateContext({ toolCancelled: params });\n };\n\n this.app.onhostcontextchanged = (params) => {\n this.updateContext(params);\n };\n\n this.connectPromise = this.connect();\n }\n\n private async connect() {\n try {\n await this.app.connect();\n const hostContext = this.app.getHostContext();\n if (hostContext) {\n this.updateContext(hostContext);\n }\n } catch (err) {\n console.error(err);\n }\n }\n\n public async getApp(): Promise<App> {\n await this.connectPromise;\n return this.app;\n }\n\n public static getInstance(\n options?: Partial<{ appInfo: Implementation }>,\n ): McpAppBridge {\n if (McpAppBridge.instance && options) {\n console.warn(\n \"McpAppBridge.getInstance: options ignored, instance already exists\",\n );\n }\n if (!McpAppBridge.instance) {\n const defaultOptions = {\n appInfo: { name: \"skybridge-app\", version: \"0.0.1\" },\n };\n McpAppBridge.instance = new McpAppBridge({\n ...defaultOptions,\n ...options,\n });\n }\n return McpAppBridge.instance;\n }\n\n public subscribe(key: McpAppContextKey): Subscribe;\n public subscribe(keys: readonly McpAppContextKey[]): Subscribe;\n public subscribe(\n keyOrKeys: McpAppContextKey | readonly McpAppContextKey[],\n ): Subscribe {\n const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];\n return (onChange: () => void) => {\n for (const key of keys) {\n this.listeners.set(\n key,\n new Set([...(this.listeners.get(key) || []), onChange]),\n );\n }\n return () => {\n for (const key of keys) {\n this.listeners.get(key)?.delete(onChange);\n }\n };\n };\n }\n\n public getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K] {\n return this.context[key];\n }\n\n public cleanup = () => {\n this.listeners.clear();\n };\n\n public static resetInstance(): void {\n if (McpAppBridge.instance) {\n McpAppBridge.instance.cleanup();\n McpAppBridge.instance = null;\n }\n }\n\n private emit(key: McpAppContextKey) {\n this.listeners.get(key)?.forEach((listener) => {\n listener();\n });\n }\n\n private updateContext(context: Partial<McpAppContext>) {\n this.context = { ...this.context, ...context };\n for (const key of Object.keys(context)) {\n this.emit(key);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { McpAppBridge } from "./bridge.js";
|
|
3
|
+
describe("McpAppBridge.getInstance", () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
McpAppBridge.resetInstance();
|
|
6
|
+
vi.stubGlobal("parent", { postMessage: vi.fn() });
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.unstubAllGlobals();
|
|
10
|
+
McpAppBridge.resetInstance();
|
|
11
|
+
});
|
|
12
|
+
it("instantiates when hostType is apps-sdk", () => {
|
|
13
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
14
|
+
expect(() => McpAppBridge.getInstance()).not.toThrow();
|
|
15
|
+
});
|
|
16
|
+
it("instantiates when hostType is mcp-app", () => {
|
|
17
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
18
|
+
expect(() => McpAppBridge.getInstance()).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=bridge.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.test.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,CAAC,aAAa,EAAE,CAAC;QAC7B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { McpAppBridge } from \"./bridge.js\";\n\ndescribe(\"McpAppBridge.getInstance\", () => {\n beforeEach(() => {\n McpAppBridge.resetInstance();\n vi.stubGlobal(\"parent\", { postMessage: vi.fn() });\n });\n afterEach(() => {\n vi.unstubAllGlobals();\n McpAppBridge.resetInstance();\n });\n\n it(\"instantiates when hostType is apps-sdk\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n\n it(\"instantiates when hostType is mcp-app\", () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n expect(() => McpAppBridge.getInstance()).not.toThrow();\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { McpAppBridge } from \"./bridge.js\";\nexport type {\n McpAppContext,\n McpAppContextKey,\n McpToolState,\n} from \"./types.js\";\nexport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { McpUiHostContext, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
export type McpToolState = {
|
|
3
|
+
toolInput: NonNullable<McpUiToolInputNotification["params"]["arguments"]> | null;
|
|
4
|
+
toolResult: McpUiToolResultNotification["params"] | null;
|
|
5
|
+
toolCancelled: McpUiToolCancelledNotification["params"] | null;
|
|
6
|
+
};
|
|
7
|
+
export type McpAppContext = McpUiHostContext & McpToolState;
|
|
8
|
+
export type McpAppContextKey = keyof McpAppContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n McpUiHostContext,\n McpUiToolCancelledNotification,\n McpUiToolInputNotification,\n McpUiToolResultNotification,\n} from \"@modelcontextprotocol/ext-apps\";\n\nexport type McpToolState = {\n toolInput: NonNullable<\n McpUiToolInputNotification[\"params\"][\"arguments\"]\n > | null;\n toolResult: McpUiToolResultNotification[\"params\"] | null;\n toolCancelled: McpUiToolCancelledNotification[\"params\"] | null;\n};\n\nexport type McpAppContext = McpUiHostContext & McpToolState;\n\nexport type McpAppContextKey = keyof McpAppContext;\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { McpAppContext } from "./types.js";
|
|
3
|
+
type McpAppInitializationOptions = {
|
|
4
|
+
appInfo: Implementation;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
8
|
+
*
|
|
9
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
10
|
+
* `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
11
|
+
* when you need protocol-level fields not surfaced by the public hooks.
|
|
12
|
+
*
|
|
13
|
+
* `options.appInfo` is honored only on the first call that creates the
|
|
14
|
+
* underlying bridge; subsequent calls reuse the singleton.
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
|
|
17
|
+
*/
|
|
18
|
+
export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { McpAppBridge } from "./bridge.js";
|
|
3
|
+
/**
|
|
4
|
+
* Read a single key from the raw MCP Apps (`ext-apps`) bridge context.
|
|
5
|
+
*
|
|
6
|
+
* Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,
|
|
7
|
+
* `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this
|
|
8
|
+
* when you need protocol-level fields not surfaced by the public hooks.
|
|
9
|
+
*
|
|
10
|
+
* `options.appInfo` is honored only on the first call that creates the
|
|
11
|
+
* underlying bridge; subsequent calls reuse the singleton.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.skybridge.tech/api-reference/use-mcp-app-context
|
|
14
|
+
*/
|
|
15
|
+
export function useMcpAppContext(key, options) {
|
|
16
|
+
const bridge = McpAppBridge.getInstance(options);
|
|
17
|
+
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=use-mcp-app-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { Implementation } from \"@modelcontextprotocol/sdk/types.js\";\n\nimport { useSyncExternalStore } from \"react\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport type { McpAppContext } from \"./types.js\";\n\ntype McpAppInitializationOptions = {\n appInfo: Implementation;\n};\n\n/**\n * Read a single key from the raw MCP Apps (`ext-apps`) bridge context.\n *\n * Advanced escape hatch — prefer the cross-host hooks (`useToolInfo`,\n * `useLayout`, etc.) which work in both MCP Apps and Apps SDK. Reach for this\n * when you need protocol-level fields not surfaced by the public hooks.\n *\n * `options.appInfo` is honored only on the first call that creates the\n * underlying bridge; subsequent calls reuse the singleton.\n *\n * @see https://docs.skybridge.tech/api-reference/use-mcp-app-context\n */\nexport function useMcpAppContext<K extends keyof McpAppContext>(\n key: K,\n options?: Partial<McpAppInitializationOptions>,\n): McpAppContext[K] {\n const bridge = McpAppBridge.getInstance(options);\n return useSyncExternalStore(bridge.subscribe(key), () =>\n bridge.getSnapshot(key),\n );\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "../../hooks/test/utils.js";
|
|
4
|
+
import { McpAppBridge } from "./bridge.js";
|
|
5
|
+
import { useMcpAppContext } from "./use-mcp-app-context.js";
|
|
6
|
+
describe("useMcpAppContext", () => {
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
9
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
10
|
+
McpAppBridge.resetInstance();
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
14
|
+
vi.clearAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it("should return the theme value from host context and update on notification", async () => {
|
|
17
|
+
vi.stubGlobal("parent", {
|
|
18
|
+
postMessage: getMcpAppHostPostMessageMock({ theme: "light" }),
|
|
19
|
+
});
|
|
20
|
+
const { result } = renderHook(() => useMcpAppContext("theme"));
|
|
21
|
+
await waitFor(() => {
|
|
22
|
+
expect(result.current).toBe("light");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=use-mcp-app-context.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,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 {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"../../hooks/test/utils.js\";\nimport { McpAppBridge } from \"./bridge.js\";\nimport { useMcpAppContext } from \"./use-mcp-app-context.js\";\n\ndescribe(\"useMcpAppContext\", () => {\n beforeEach(async () => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n McpAppBridge.resetInstance();\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.clearAllMocks();\n });\n\n it(\"should return the theme value from host context and update on notification\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({ theme: \"light\" }),\n });\n const { result } = renderHook(() => useMcpAppContext(\"theme\"));\n\n await waitFor(() => {\n expect(result.current).toBe(\"light\");\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { CallToolResult, EmbeddedResource, ResourceLink } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { useSyncExternalStore } from "react";
|
|
3
|
+
import type { ViewHostType } from "../../server/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Globals injected on `window.skybridge` by the host. Tells the view which
|
|
6
|
+
* runtime it's running under and where to reach the MCP server.
|
|
7
|
+
*/
|
|
8
|
+
export type SkybridgeProperties = {
|
|
9
|
+
hostType: ViewHostType;
|
|
10
|
+
serverUrl: string;
|
|
11
|
+
};
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
skybridge: SkybridgeProperties;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Arguments passed to a tool call. `null` for tools that take no input. */
|
|
18
|
+
export type CallToolArgs = Record<string, unknown> | null;
|
|
19
|
+
/**
|
|
20
|
+
* Result of a tool call as surfaced to the view: MCP `content` blocks plus
|
|
21
|
+
* the typed `structuredContent` and optional `meta`. `isError` is set when
|
|
22
|
+
* the server marks the call as failed.
|
|
23
|
+
*/
|
|
24
|
+
export type CallToolResponse = {
|
|
25
|
+
content: CallToolResult["content"];
|
|
26
|
+
structuredContent: NonNullable<CallToolResult["structuredContent"]>;
|
|
27
|
+
isError: NonNullable<CallToolResult["isError"]>;
|
|
28
|
+
meta?: CallToolResult["_meta"];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* How the view is laid out by the host. `"modal"` is host-driven (see
|
|
32
|
+
* {@link useRequestModal}); `"pip"`, `"inline"`, and `"fullscreen"` are
|
|
33
|
+
* requestable via {@link useDisplayMode}.
|
|
34
|
+
*/
|
|
35
|
+
export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
|
|
36
|
+
/** Subset of {@link DisplayMode} that the view can request from the host. */
|
|
37
|
+
export type RequestDisplayMode = Exclude<DisplayMode, "modal">;
|
|
38
|
+
/** Host theme. Mirror this in your view's styling for a native feel. */
|
|
39
|
+
export type Theme = "light" | "dark";
|
|
40
|
+
/** Coarse device class reported by the host. `"unknown"` when unavailable. */
|
|
41
|
+
export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
42
|
+
/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */
|
|
43
|
+
export type SafeAreaInsets = {
|
|
44
|
+
top: number;
|
|
45
|
+
right: number;
|
|
46
|
+
bottom: number;
|
|
47
|
+
left: number;
|
|
48
|
+
};
|
|
49
|
+
/** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */
|
|
50
|
+
export type SafeArea = {
|
|
51
|
+
insets: SafeAreaInsets;
|
|
52
|
+
};
|
|
53
|
+
/** Device and input-capability hints exposed via {@link useUser}. */
|
|
54
|
+
export type UserAgent = {
|
|
55
|
+
device: {
|
|
56
|
+
type: DeviceType;
|
|
57
|
+
};
|
|
58
|
+
capabilities: {
|
|
59
|
+
hover: boolean;
|
|
60
|
+
touch: boolean;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Full snapshot of state the host exposes to the view. Most fields are
|
|
65
|
+
* better accessed through their dedicated hooks (`useLayout`, `useUser`,
|
|
66
|
+
* `useToolInfo`, etc.) — read this directly only for advanced cases.
|
|
67
|
+
*/
|
|
68
|
+
export interface HostContext {
|
|
69
|
+
theme: Theme;
|
|
70
|
+
locale: string;
|
|
71
|
+
displayMode: DisplayMode;
|
|
72
|
+
safeArea: SafeArea;
|
|
73
|
+
maxHeight: number | undefined;
|
|
74
|
+
userAgent: UserAgent;
|
|
75
|
+
toolInput: Record<string, unknown> | null;
|
|
76
|
+
toolOutput: Record<string, unknown> | null;
|
|
77
|
+
toolResponseMetadata: Record<string, unknown> | null;
|
|
78
|
+
display: {
|
|
79
|
+
mode: DisplayMode;
|
|
80
|
+
params?: Record<string, unknown>;
|
|
81
|
+
};
|
|
82
|
+
viewState: Record<string, unknown> | null;
|
|
83
|
+
}
|
|
84
|
+
/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */
|
|
85
|
+
export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
|
|
86
|
+
/** @internal Bridge contract implemented by per-host bridge classes. */
|
|
87
|
+
export interface Bridge<Context> {
|
|
88
|
+
subscribe(key: keyof Context): Subscribe;
|
|
89
|
+
subscribe(keys: readonly (keyof Context)[]): Subscribe;
|
|
90
|
+
getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
|
|
91
|
+
}
|
|
92
|
+
/** @internal Per-key snapshot store backing {@link useHostContext}. */
|
|
93
|
+
export type HostContextStore<K extends keyof HostContext> = {
|
|
94
|
+
subscribe: Subscribe;
|
|
95
|
+
getSnapshot: () => HostContext[K];
|
|
96
|
+
};
|
|
97
|
+
/** Persisted view state shape (a plain object). See {@link useViewState}. */
|
|
98
|
+
export type ViewState = Record<string, unknown>;
|
|
99
|
+
/** Updater form accepted when writing to view state. */
|
|
100
|
+
export type SetViewStateAction = ViewState | ((prevState: ViewState | null) => ViewState);
|
|
101
|
+
/** Reference to a host-managed file (returned by {@link useFiles}). */
|
|
102
|
+
export type FileMetadata = {
|
|
103
|
+
fileId: string;
|
|
104
|
+
fileName?: string;
|
|
105
|
+
mimeType?: string;
|
|
106
|
+
};
|
|
107
|
+
/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */
|
|
108
|
+
export type UploadFileOptions = {
|
|
109
|
+
library?: boolean;
|
|
110
|
+
};
|
|
111
|
+
/** Options for {@link useRequestModal}'s `open` call. */
|
|
112
|
+
export type RequestModalOptions = {
|
|
113
|
+
title?: string;
|
|
114
|
+
params?: Record<string, unknown>;
|
|
115
|
+
template?: string;
|
|
116
|
+
anchor?: {
|
|
117
|
+
top?: number;
|
|
118
|
+
left?: number;
|
|
119
|
+
width?: number;
|
|
120
|
+
height?: number;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the
|
|
125
|
+
* host not to append its `?redirectUrl=…` tracking query parameter when
|
|
126
|
+
* opening allowlisted targets.
|
|
127
|
+
*/
|
|
128
|
+
export type OpenExternalOptions = {
|
|
129
|
+
redirectUrl?: false;
|
|
130
|
+
};
|
|
131
|
+
/** Options for {@link useSendFollowUpMessage}. */
|
|
132
|
+
export type SendFollowUpMessageOptions = {
|
|
133
|
+
scrollToBottom?: boolean;
|
|
134
|
+
};
|
|
135
|
+
/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */
|
|
136
|
+
export type RequestSizeOptions = {
|
|
137
|
+
width?: number;
|
|
138
|
+
height?: number;
|
|
139
|
+
};
|
|
140
|
+
export type DownloadParams = {
|
|
141
|
+
contents: (EmbeddedResource | ResourceLink)[];
|
|
142
|
+
};
|
|
143
|
+
export type DownloadResult = {
|
|
144
|
+
isError?: boolean;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
* Low-level interface every host bridge implements. End-user code should use
|
|
149
|
+
* the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than
|
|
150
|
+
* calling this directly.
|
|
151
|
+
*/
|
|
152
|
+
export interface Adaptor {
|
|
153
|
+
getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
|
|
154
|
+
callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
|
|
155
|
+
requestDisplayMode(mode: RequestDisplayMode): Promise<{
|
|
156
|
+
mode: RequestDisplayMode;
|
|
157
|
+
}>;
|
|
158
|
+
requestClose(): Promise<void>;
|
|
159
|
+
requestSize(size: RequestSizeOptions): Promise<void>;
|
|
160
|
+
sendFollowUpMessage(prompt: string, options?: SendFollowUpMessageOptions): Promise<void>;
|
|
161
|
+
openExternal(href: string, options?: OpenExternalOptions): void;
|
|
162
|
+
download(params: DownloadParams): Promise<DownloadResult>;
|
|
163
|
+
setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;
|
|
164
|
+
uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;
|
|
165
|
+
getFileDownloadUrl(file: FileMetadata): Promise<{
|
|
166
|
+
downloadUrl: string;
|
|
167
|
+
}>;
|
|
168
|
+
selectFiles(): Promise<FileMetadata[]>;
|
|
169
|
+
openModal(options: RequestModalOptions): void;
|
|
170
|
+
setOpenInAppUrl(href: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Close a modal opened via {@link Adaptor.openModal}. In the Apps SDK
|
|
173
|
+
* runtime this is a no-op (the host owns modal lifecycle). In the MCP App
|
|
174
|
+
* runtime it dismisses the in-iframe polyfill.
|
|
175
|
+
*/
|
|
176
|
+
closeModal(): void;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Thrown when a host bridge method is called in a runtime that doesn't
|
|
180
|
+
* support it (e.g. `uploadFile` outside the Apps SDK runtime).
|
|
181
|
+
*/
|
|
182
|
+
export declare class NotSupportedError extends Error {
|
|
183
|
+
readonly method: string;
|
|
184
|
+
readonly reason?: string | undefined;
|
|
185
|
+
constructor(method: string, reason?: string | undefined);
|
|
186
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a host bridge method is called in a runtime that doesn't
|
|
3
|
+
* support it (e.g. `uploadFile` outside the Apps SDK runtime).
|
|
4
|
+
*/
|
|
5
|
+
export class NotSupportedError extends Error {
|
|
6
|
+
method;
|
|
7
|
+
reason;
|
|
8
|
+
constructor(method, reason) {
|
|
9
|
+
super(`${method} is not supported in this runtime${reason ? `: ${reason}` : ""}`);
|
|
10
|
+
this.method = method;
|
|
11
|
+
this.reason = reason;
|
|
12
|
+
this.name = "NotSupportedError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=types.js.map
|