skybridge 0.0.0-dev.f3fc72c → 0.0.0-dev.f40327b
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 +152 -0
- 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/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.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 +102 -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 +80 -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 +6 -6
- 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 -7
- 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/{src/test → test}/utils.d.ts +13 -21
- package/dist/{src/test → test}/utils.js +42 -37
- 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/apps-sdk/adaptor.d.ts +28 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +113 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +11 -0
- package/dist/{src/web/bridges/apps-sdk-bridge.js → web/bridges/apps-sdk/bridge.js} +3 -2
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
- package/dist/web/bridges/apps-sdk/index.js +5 -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 +9 -0
- package/dist/web/bridges/get-adaptor.js +15 -0
- package/dist/web/bridges/get-adaptor.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/adaptor.d.ts +52 -0
- package/dist/web/bridges/mcp-app/adaptor.js +280 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +27 -0
- package/dist/web/bridges/mcp-app/bridge.js +103 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +4 -0
- package/dist/web/bridges/mcp-app/index.js +4 -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 +171 -0
- package/dist/web/bridges/types.js +2 -0
- package/dist/web/bridges/types.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 +45 -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 +129 -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 +35 -5
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +142 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +24 -19
- package/dist/{src/web → web}/generate-helpers.js +22 -18
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +26 -26
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- 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/{src/web → web}/helpers/state.test.js +9 -9
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/index.d.ts +6 -3
- package/dist/{src/web → web}/hooks/index.js +5 -2
- 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/{src/web → web}/hooks/use-call-tool.js +30 -2
- package/dist/web/hooks/use-call-tool.js.map +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/{src/web → web}/hooks/use-call-tool.test.js +30 -9
- 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.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.js.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 +95 -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 +54 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-layout.d.ts +4 -2
- package/dist/{src/web → web}/hooks/use-layout.js +6 -4
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-layout.test.js +7 -6
- 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/{src/web → web}/hooks/use-open-external.test.js +27 -12
- 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 +52 -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/{src/web → web}/hooks/use-request-modal.test.js +5 -1
- 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 +65 -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 +43 -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/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/{src/web → web}/hooks/use-tool-info.test.js +5 -5
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-user.d.ts +3 -1
- 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/{src/web → web}/hooks/use-user.test.js +33 -4
- 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 +177 -0
- package/dist/web/hooks/use-view-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +1 -2
- package/dist/{src/web → web}/index.js +1 -2
- 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 +1 -1
- 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 +0 -1
- 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 +70 -30
- 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 -101
- package/dist/src/server/server.js +0 -120
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js +0 -30
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -66
- package/dist/src/server/templates/production.hbs +0 -7
- package/dist/src/server/widgetsDevServer.d.ts +0 -12
- package/dist/src/server/widgetsDevServer.js +0 -47
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -237
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +0 -13
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +0 -33
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +0 -1
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +0 -16
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +0 -115
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +0 -1
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +0 -10
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-adaptor.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-adaptor.js +0 -8
- package/dist/src/web/bridges/hooks/use-adaptor.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +0 -7
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +0 -2
- package/dist/src/web/bridges/hooks/use-bridge.js +0 -8
- package/dist/src/web/bridges/hooks/use-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +0 -5
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +0 -7
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +0 -41
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +0 -1
- package/dist/src/web/bridges/index.d.ts +0 -4
- package/dist/src/web/bridges/index.js +0 -5
- package/dist/src/web/bridges/index.js.map +0 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +0 -38
- package/dist/src/web/bridges/mcp-app-bridge.js +0 -162
- package/dist/src/web/bridges/mcp-app-bridge.js.map +0 -1
- package/dist/src/web/bridges/types.d.ts +0 -57
- package/dist/src/web/bridges/types.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/create-store.test.js +0 -70
- package/dist/src/web/create-store.test.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.map +0 -1
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/test/utils.d.ts +0 -10
- package/dist/src/web/hooks/test/utils.js +0 -40
- package/dist/src/web/hooks/test/utils.js.map +0 -1
- 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 -10
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- 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-layout.js.map +0 -1
- package/dist/src/web/hooks/use-layout.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 -8
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -3
- package/dist/src/web/hooks/use-openai-global.js +0 -6
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -9
- package/dist/src/web/hooks/use-request-modal.js +0 -14
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- 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 -8
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +0 -36
- package/dist/src/web/hooks/use-tool-info.js +0 -26
- 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.map +0 -1
- package/dist/src/web/hooks/use-user.js +0 -19
- package/dist/src/web/hooks/use-user.js.map +0 -1
- package/dist/src/web/hooks/use-user.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 -61
- 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 -39
- 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 -149
- 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/bridges/hooks/use-mcp-app-bridge.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{src/web/create-store.test.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{src/web/bridges → cli}/types.js +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → server/content-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web/helpers/state.test.d.ts → server/middleware.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → server/middleware.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → server/tunnel-proxy-router.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → test/view.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-layout.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-open-external.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web → web}/generate-helpers.test.js +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/helpers/state.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-display-mode.test-d.d.ts} +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-display-mode.test.js +0 -0
- /package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +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,171 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/bridges/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CallToolResult,\n EmbeddedResource,\n ResourceLink,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport type { useSyncExternalStore } from \"react\";\nimport type { ViewHostType } from \"../../server/index.js\";\n\n/**\n * Globals injected on `window.skybridge` by the host. Tells the view which\n * runtime it's running under and where to reach the MCP server.\n */\nexport type SkybridgeProperties = {\n hostType: ViewHostType;\n serverUrl: string;\n};\n\ndeclare global {\n interface Window {\n skybridge: SkybridgeProperties;\n }\n}\n\n/** Arguments passed to a tool call. `null` for tools that take no input. */\nexport type CallToolArgs = Record<string, unknown> | null;\n\n/**\n * Result of a tool call as surfaced to the view: MCP `content` blocks plus\n * the typed `structuredContent` and optional `meta`. `isError` is set when\n * the server marks the call as failed.\n */\nexport type CallToolResponse = {\n content: CallToolResult[\"content\"];\n structuredContent: NonNullable<CallToolResult[\"structuredContent\"]>;\n isError: NonNullable<CallToolResult[\"isError\"]>;\n meta?: CallToolResult[\"_meta\"];\n};\n\n/**\n * How the view is laid out by the host. `\"modal\"` is host-driven (see\n * {@link useRequestModal}); `\"pip\"`, `\"inline\"`, and `\"fullscreen\"` are\n * requestable via {@link useDisplayMode}.\n */\nexport type DisplayMode = \"pip\" | \"inline\" | \"fullscreen\" | \"modal\";\n/** Subset of {@link DisplayMode} that the view can request from the host. */\nexport type RequestDisplayMode = Exclude<DisplayMode, \"modal\">;\n\n/** Host theme. Mirror this in your view's styling for a native feel. */\nexport type Theme = \"light\" | \"dark\";\n\n/** Coarse device class reported by the host. `\"unknown\"` when unavailable. */\nexport type DeviceType = \"mobile\" | \"tablet\" | \"desktop\" | \"unknown\";\n\n/** Pixel insets the view should keep clear of (notches, home indicators, etc.). */\nexport type SafeAreaInsets = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\n/** Wrapper around {@link SafeAreaInsets} exposed via {@link useLayout}. */\nexport type SafeArea = {\n insets: SafeAreaInsets;\n};\n\n/** Device and input-capability hints exposed via {@link useUser}. */\nexport type UserAgent = {\n device: {\n type: DeviceType;\n };\n capabilities: {\n hover: boolean;\n touch: boolean;\n };\n};\n\n/**\n * Full snapshot of state the host exposes to the view. Most fields are\n * better accessed through their dedicated hooks (`useLayout`, `useUser`,\n * `useToolInfo`, etc.) — read this directly only for advanced cases.\n */\nexport interface HostContext {\n theme: Theme;\n locale: string;\n displayMode: DisplayMode;\n safeArea: SafeArea;\n maxHeight: number | undefined;\n userAgent: UserAgent;\n toolInput: Record<string, unknown> | null;\n toolOutput: Record<string, unknown> | null;\n toolResponseMetadata: Record<string, unknown> | null;\n display: {\n mode: DisplayMode;\n params?: Record<string, unknown>;\n };\n viewState: Record<string, unknown> | null;\n}\n\n/** @internal `useSyncExternalStore` subscribe signature, re-exported for bridge implementations. */\nexport type Subscribe = Parameters<typeof useSyncExternalStore>[0];\n\n/** @internal Bridge contract implemented by per-host bridge classes. */\nexport interface Bridge<Context> {\n subscribe(key: keyof Context): Subscribe;\n subscribe(keys: readonly (keyof Context)[]): Subscribe;\n getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;\n}\n\n/** @internal Per-key snapshot store backing {@link useHostContext}. */\nexport type HostContextStore<K extends keyof HostContext> = {\n subscribe: Subscribe;\n getSnapshot: () => HostContext[K];\n};\n\n/** Persisted view state shape (a plain object). See {@link useViewState}. */\nexport type ViewState = Record<string, unknown>;\n\n/** Updater form accepted when writing to view state. */\nexport type SetViewStateAction =\n | ViewState\n | ((prevState: ViewState | null) => ViewState);\n\n/** Reference to a host-managed file (returned by {@link useFiles}). */\nexport type FileMetadata = {\n fileId: string;\n fileName?: string;\n mimeType?: string;\n};\n\n/** Options for {@link useFiles}'s `upload`. `library: true` saves into the user's library when supported. */\nexport type UploadFileOptions = { library?: boolean };\n\n/** Options for {@link useRequestModal}'s `open` call. */\nexport type RequestModalOptions = {\n title?: string;\n params?: Record<string, unknown>;\n template?: string;\n anchor?: { top?: number; left?: number; width?: number; height?: number };\n};\n\n/**\n * Options for {@link useOpenExternal}. Set `redirectUrl: false` to tell the\n * host not to append its `?redirectUrl=…` tracking query parameter when\n * opening allowlisted targets.\n */\nexport type OpenExternalOptions = {\n redirectUrl?: false;\n};\n\n/** Options for {@link useSendFollowUpMessage}. */\nexport type SendFollowUpMessageOptions = { scrollToBottom?: boolean };\n\n/** Options for {@link useRequestSize}. Omit a dimension to leave it unchanged. */\nexport type RequestSizeOptions = {\n width?: number;\n height?: number;\n};\n\nexport type DownloadParams = {\n contents: (EmbeddedResource | ResourceLink)[];\n};\n\nexport type DownloadResult = {\n isError?: boolean;\n};\n\n/**\n * @internal\n * Low-level interface every host bridge implements. End-user code should use\n * the React hooks (`useCallTool`, `useViewState`, `useFiles`, …) rather than\n * calling this directly.\n */\nexport interface Adaptor {\n getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;\n callTool<\n ToolArgs extends CallToolArgs = null,\n ToolResponse extends CallToolResponse = CallToolResponse,\n >(name: string, args: ToolArgs): Promise<ToolResponse>;\n requestDisplayMode(mode: RequestDisplayMode): Promise<{\n mode: RequestDisplayMode;\n }>;\n requestClose(): Promise<void>;\n requestSize(size: RequestSizeOptions): Promise<void>;\n sendFollowUpMessage(\n prompt: string,\n options?: SendFollowUpMessageOptions,\n ): Promise<void>;\n openExternal(href: string, options?: OpenExternalOptions): void;\n download(params: DownloadParams): Promise<DownloadResult>;\n setViewState(stateOrUpdater: SetViewStateAction): Promise<void>;\n uploadFile(file: File, options?: UploadFileOptions): Promise<FileMetadata>;\n getFileDownloadUrl(file: FileMetadata): Promise<{ downloadUrl: string }>;\n selectFiles(): Promise<FileMetadata[]>;\n openModal(options: RequestModalOptions): void;\n setOpenInAppUrl(href: string): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HostContext } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
|
|
5
|
+
* Used to build the higher-level hooks; prefer those for app code.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useHostContext: <K extends keyof HostContext>(key: K) => HostContext[K];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { getAdaptor } from "./get-adaptor.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.
|
|
6
|
+
* Used to build the higher-level hooks; prefer those for app code.
|
|
7
|
+
*/
|
|
8
|
+
export const useHostContext = (key) => {
|
|
9
|
+
const adaptor = getAdaptor();
|
|
10
|
+
const store = adaptor.getHostContextStore(key);
|
|
11
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=use-host-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-host-context.js","sourceRoot":"","sources":["../../../src/web/bridges/use-host-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAM,EACU,EAAE;IAClB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { getAdaptor } from \"./get-adaptor.js\";\nimport type { HostContext } from \"./types.js\";\n\n/**\n * @internal\n * Subscribe to a single {@link HostContext} key via `useSyncExternalStore`.\n * Used to build the higher-level hooks; prefer those for app code.\n */\nexport const useHostContext = <K extends keyof HostContext>(\n key: K,\n): HostContext[K] => {\n const adaptor = getAdaptor();\n const store = adaptor.getHostContextStore(key);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n};\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useSyncExternalStore } from "react";
|
|
3
|
+
import { McpAppAdaptor } from "../bridges/index.js";
|
|
4
|
+
const modalStyles = `
|
|
5
|
+
.sb-modal-backdrop {
|
|
6
|
+
position: fixed;
|
|
7
|
+
inset: 0;
|
|
8
|
+
background: rgba(0, 0, 0, 0.5);
|
|
9
|
+
z-index: 9998;
|
|
10
|
+
}
|
|
11
|
+
.sb-modal-container {
|
|
12
|
+
border-radius: 12px;
|
|
13
|
+
position: fixed;
|
|
14
|
+
inset: 0;
|
|
15
|
+
margin: auto;
|
|
16
|
+
width: fit-content;
|
|
17
|
+
height: fit-content;
|
|
18
|
+
background: white;
|
|
19
|
+
z-index: 9999;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
export function ModalProvider({ children }) {
|
|
23
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
24
|
+
const { mode } = useSyncExternalStore(adaptor.getHostContextStore("display").subscribe, adaptor.getHostContextStore("display").getSnapshot);
|
|
25
|
+
const isOpen = mode === "modal";
|
|
26
|
+
const handleBackdropClick = (e) => {
|
|
27
|
+
if (e.target === e.currentTarget) {
|
|
28
|
+
adaptor.closeModal();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!isOpen) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const handler = (e) => {
|
|
36
|
+
if (e.key === "Escape") {
|
|
37
|
+
adaptor.closeModal();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
document.addEventListener("keydown", handler);
|
|
41
|
+
return () => document.removeEventListener("keydown", handler);
|
|
42
|
+
}, [isOpen, adaptor]);
|
|
43
|
+
return (_jsxs(_Fragment, { children: [_jsx("style", { children: modalStyles }), isOpen && (_jsx("div", { role: "dialog", className: "sb-modal-backdrop", onClick: handleBackdropClick })), _jsx("div", { className: isOpen ? "sb-modal-container" : undefined, children: children })] }));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=modal-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-provider.js","sourceRoot":"","sources":["../../../src/web/components/modal-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;CAiBnB,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAA2B;IACjE,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAE5C,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAoB,CACnC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,SAAS,EAChD,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,WAAW,CACnD,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAEhC,MAAM,mBAAmB,GAAG,CAAC,CAAmB,EAAE,EAAE;QAClD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC;YACjC,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,CAAgB,EAAE,EAAE;YACnC,IAAI,CAAC,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACvB,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEtB,OAAO,CACL,8BACE,0BAAQ,WAAW,GAAS,EAC3B,MAAM,IAAI,CAET,cACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mBAAmB,EAC7B,OAAO,EAAE,mBAAmB,GAC5B,CACH,EACD,cAAK,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,YACtD,QAAQ,GACL,IACL,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { type ReactNode, useEffect, useSyncExternalStore } from \"react\";\nimport { McpAppAdaptor } from \"../bridges/index.js\";\n\nconst modalStyles = `\n.sb-modal-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.5);\n z-index: 9998;\n}\n.sb-modal-container {\n border-radius: 12px;\n position: fixed;\n inset: 0;\n margin: auto;\n width: fit-content;\n height: fit-content;\n background: white;\n z-index: 9999;\n}\n`;\n\nexport function ModalProvider({ children }: { children: ReactNode }) {\n const adaptor = McpAppAdaptor.getInstance();\n\n const { mode } = useSyncExternalStore(\n adaptor.getHostContextStore(\"display\").subscribe,\n adaptor.getHostContextStore(\"display\").getSnapshot,\n );\n const isOpen = mode === \"modal\";\n\n const handleBackdropClick = (e: React.MouseEvent) => {\n if (e.target === e.currentTarget) {\n adaptor.closeModal();\n }\n };\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const handler = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n adaptor.closeModal();\n }\n };\n document.addEventListener(\"keydown\", handler);\n return () => document.removeEventListener(\"keydown\", handler);\n }, [isOpen, adaptor]);\n\n return (\n <>\n <style>{modalStyles}</style>\n {isOpen && (\n // biome-ignore lint/a11y/useKeyWithClickEvents: backdrop isn't focusable\n <div\n role=\"dialog\"\n className=\"sb-modal-backdrop\"\n onClick={handleBackdropClick}\n />\n )}\n <div className={isOpen ? \"sb-modal-container\" : undefined}>\n {children}\n </div>\n </>\n );\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type StateCreator } from "zustand";
|
|
2
|
+
import type { UnknownObject } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a Zustand store that is bidirectionally synced with the host's
|
|
5
|
+
* `viewState`. Local store updates persist to the host, and external host
|
|
6
|
+
* updates rehydrate the store — making the store the single source of truth
|
|
7
|
+
* for state that should survive view remounts.
|
|
8
|
+
*
|
|
9
|
+
* Use this when you outgrow {@link useViewState} and want first-class Zustand
|
|
10
|
+
* ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
|
|
11
|
+
*
|
|
12
|
+
* Skybridge-internal context fields (see {@link DataLLM}) are filtered out
|
|
13
|
+
* automatically before reaching your store.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam State - Shape of the store's state. Must be a plain object.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* export const useStore = createStore<{ count: number; inc: () => void }>(
|
|
20
|
+
* (set) => ({
|
|
21
|
+
* count: 0,
|
|
22
|
+
* inc: () => set((s) => ({ count: s.count + 1 })),
|
|
23
|
+
* }),
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see https://docs.skybridge.tech/api-reference/create-store
|
|
28
|
+
*/
|
|
29
|
+
export declare function createStore<State extends UnknownObject>(storeCreator: StateCreator<State, [], [], State>, defaultState?: State | (() => State)): import("zustand").UseBoundStore<import("zustand").StoreApi<State>>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { dequal } from "dequal/lite";
|
|
2
|
+
import { create } from "zustand";
|
|
3
|
+
import { getAdaptor } from "./bridges/index.js";
|
|
4
|
+
import { filterViewContext, getInitialState, injectViewContext, serializeState, } from "./helpers/state.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a Zustand store that is bidirectionally synced with the host's
|
|
7
|
+
* `viewState`. Local store updates persist to the host, and external host
|
|
8
|
+
* updates rehydrate the store — making the store the single source of truth
|
|
9
|
+
* for state that should survive view remounts.
|
|
10
|
+
*
|
|
11
|
+
* Use this when you outgrow {@link useViewState} and want first-class Zustand
|
|
12
|
+
* ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.
|
|
13
|
+
*
|
|
14
|
+
* Skybridge-internal context fields (see {@link DataLLM}) are filtered out
|
|
15
|
+
* automatically before reaching your store.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam State - Shape of the store's state. Must be a plain object.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* export const useStore = createStore<{ count: number; inc: () => void }>(
|
|
22
|
+
* (set) => ({
|
|
23
|
+
* count: 0,
|
|
24
|
+
* inc: () => set((s) => ({ count: s.count + 1 })),
|
|
25
|
+
* }),
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see https://docs.skybridge.tech/api-reference/create-store
|
|
30
|
+
*/
|
|
31
|
+
export function createStore(storeCreator, defaultState) {
|
|
32
|
+
const initialState = getInitialState(defaultState);
|
|
33
|
+
const store = create()((...args) => {
|
|
34
|
+
const baseStore = storeCreator(...args);
|
|
35
|
+
if (initialState !== null) {
|
|
36
|
+
return { ...baseStore, ...initialState };
|
|
37
|
+
}
|
|
38
|
+
return baseStore;
|
|
39
|
+
});
|
|
40
|
+
// Bidirectional sync between the Zustand store and the adaptor's viewState.
|
|
41
|
+
// Store changes persist to the host; external viewState changes rehydrate the store.
|
|
42
|
+
store.subscribe((state) => {
|
|
43
|
+
const serializedState = serializeState(state);
|
|
44
|
+
if (serializedState !== null && serializedState !== undefined) {
|
|
45
|
+
const stateToPersist = injectViewContext(serializedState);
|
|
46
|
+
if (stateToPersist !== null) {
|
|
47
|
+
getAdaptor().setViewState(stateToPersist);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const viewStateStore = getAdaptor().getHostContextStore("viewState");
|
|
52
|
+
viewStateStore.subscribe(() => {
|
|
53
|
+
const externalState = viewStateStore.getSnapshot();
|
|
54
|
+
if (externalState !== null) {
|
|
55
|
+
const filtered = filterViewContext(externalState);
|
|
56
|
+
const current = serializeState(store.getState());
|
|
57
|
+
if (!dequal(filtered, current)) {
|
|
58
|
+
store.setState(filtered);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return store;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=create-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-store.js","sourceRoot":"","sources":["../../src/web/create-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,e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AAC,QAAQ,EAAE,CAAU,CAAC;YAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;gBAC/B,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { dequal } from \"dequal/lite\";\nimport { create, type StateCreator } from \"zustand\";\nimport { getAdaptor } from \"./bridges/index.js\";\nimport {\n filterViewContext,\n getInitialState,\n injectViewContext,\n serializeState,\n} from \"./helpers/state.js\";\nimport type { UnknownObject } from \"./types.js\";\n\n/**\n * Create a Zustand store that is bidirectionally synced with the host's\n * `viewState`. Local store updates persist to the host, and external host\n * updates rehydrate the store — making the store the single source of truth\n * for state that should survive view remounts.\n *\n * Use this when you outgrow {@link useViewState} and want first-class Zustand\n * ergonomics (selectors, actions, middleware). Otherwise prefer `useViewState`.\n *\n * Skybridge-internal context fields (see {@link DataLLM}) are filtered out\n * automatically before reaching your store.\n *\n * @typeParam State - Shape of the store's state. Must be a plain object.\n *\n * @example\n * ```ts\n * export const useStore = createStore<{ count: number; inc: () => void }>(\n * (set) => ({\n * count: 0,\n * inc: () => set((s) => ({ count: s.count + 1 })),\n * }),\n * );\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/create-store\n */\nexport function createStore<State extends UnknownObject>(\n storeCreator: StateCreator<State, [], [], State>,\n defaultState?: State | (() => State),\n) {\n const initialState = getInitialState(defaultState);\n\n const store = create<State>()(\n (...args: Parameters<StateCreator<State, [], [], State>>) => {\n const baseStore = storeCreator(...args);\n\n if (initialState !== null) {\n return { ...baseStore, ...initialState };\n }\n\n return baseStore;\n },\n );\n\n // Bidirectional sync between the Zustand store and the adaptor's viewState.\n // Store changes persist to the host; external viewState changes rehydrate the store.\n store.subscribe((state: State) => {\n const serializedState = serializeState(state);\n if (serializedState !== null && serializedState !== undefined) {\n const stateToPersist = injectViewContext(serializedState as State);\n if (stateToPersist !== null) {\n getAdaptor().setViewState(stateToPersist);\n }\n }\n });\n\n const viewStateStore = getAdaptor().getHostContextStore(\"viewState\");\n viewStateStore.subscribe(() => {\n const externalState = viewStateStore.getSnapshot();\n if (externalState !== null) {\n const filtered = filterViewContext(externalState) as State;\n const current = serializeState(store.getState()) as State;\n if (!dequal(filtered, current)) {\n store.setState(filtered);\n }\n }\n });\n\n return store;\n}\n"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { cleanup } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
3
|
+
import { McpAppAdaptor } from "./bridges/mcp-app/adaptor.js";
|
|
4
|
+
import { McpAppBridge } from "./bridges/mcp-app/bridge.js";
|
|
5
|
+
import { createStore } from "./create-store.js";
|
|
6
|
+
import { VIEW_CONTEXT_KEY } from "./data-llm.js";
|
|
7
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./hooks/test/utils.js";
|
|
8
|
+
describe("createStore", () => {
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.unstubAllGlobals();
|
|
11
|
+
vi.resetAllMocks();
|
|
12
|
+
});
|
|
13
|
+
describe("apps-sdk mode", () => {
|
|
14
|
+
let OpenaiMock;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
OpenaiMock = {
|
|
17
|
+
widgetState: null,
|
|
18
|
+
setWidgetState: vi.fn().mockResolvedValue(undefined),
|
|
19
|
+
};
|
|
20
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
21
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
22
|
+
});
|
|
23
|
+
it("should create a store without default state", () => {
|
|
24
|
+
const storeCreator = () => ({
|
|
25
|
+
count: 0,
|
|
26
|
+
});
|
|
27
|
+
const store = createStore(storeCreator);
|
|
28
|
+
expect(store.getState()).toEqual({ count: 0 });
|
|
29
|
+
});
|
|
30
|
+
it("should create a store with default state", () => {
|
|
31
|
+
const storeCreator = () => ({
|
|
32
|
+
count: 0,
|
|
33
|
+
name: "initial",
|
|
34
|
+
});
|
|
35
|
+
const defaultState = { count: 5, name: "default" };
|
|
36
|
+
const store = createStore(storeCreator, defaultState);
|
|
37
|
+
expect(store.getState()).toEqual({ count: 5, name: "default" });
|
|
38
|
+
});
|
|
39
|
+
it("should initialize from window.openai.widgetState when available", () => {
|
|
40
|
+
const storeCreator = () => ({
|
|
41
|
+
count: 0,
|
|
42
|
+
name: "initial",
|
|
43
|
+
});
|
|
44
|
+
const windowState = { count: 20, name: "window" };
|
|
45
|
+
OpenaiMock.widgetState = { modelContent: windowState };
|
|
46
|
+
const store = createStore(storeCreator);
|
|
47
|
+
expect(store.getState()).toEqual({ count: 20, name: "window" });
|
|
48
|
+
});
|
|
49
|
+
it("should persist state changes to window.openai.setWidgetState", async () => {
|
|
50
|
+
const storeCreator = (set) => ({
|
|
51
|
+
count: 0,
|
|
52
|
+
increment: () => set((state) => ({ count: state.count + 1 })),
|
|
53
|
+
});
|
|
54
|
+
const store = createStore(storeCreator);
|
|
55
|
+
store.getState().increment();
|
|
56
|
+
await vi.waitFor(() => {
|
|
57
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalled();
|
|
58
|
+
});
|
|
59
|
+
const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];
|
|
60
|
+
expect(callArgs).toEqual({
|
|
61
|
+
modelContent: { count: 1 },
|
|
62
|
+
privateContent: {},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it("should filter view context from initial state", () => {
|
|
66
|
+
const storeCreator = () => ({
|
|
67
|
+
count: 0,
|
|
68
|
+
});
|
|
69
|
+
const windowState = {
|
|
70
|
+
count: 5,
|
|
71
|
+
[VIEW_CONTEXT_KEY]: "context-value",
|
|
72
|
+
};
|
|
73
|
+
OpenaiMock.widgetState = { modelContent: windowState };
|
|
74
|
+
const store = createStore(storeCreator);
|
|
75
|
+
expect(store.getState()).toEqual({ count: 5 });
|
|
76
|
+
expect(store.getState()[VIEW_CONTEXT_KEY]).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("mcp-app mode", () => {
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
82
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
83
|
+
});
|
|
84
|
+
afterEach(async () => {
|
|
85
|
+
cleanup();
|
|
86
|
+
McpAppBridge.resetInstance();
|
|
87
|
+
McpAppAdaptor.resetInstance();
|
|
88
|
+
});
|
|
89
|
+
it("should initialize with null viewState", () => {
|
|
90
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
91
|
+
const viewState = adaptor.getHostContextStore("viewState").getSnapshot();
|
|
92
|
+
expect(viewState).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
it("should create a store with default state when no persisted state exists", () => {
|
|
95
|
+
const storeCreator = () => ({
|
|
96
|
+
count: 0,
|
|
97
|
+
});
|
|
98
|
+
const store = createStore(storeCreator);
|
|
99
|
+
expect(store.getState()).toEqual({ count: 0 });
|
|
100
|
+
});
|
|
101
|
+
it("should update in-memory state via setViewState", async () => {
|
|
102
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
103
|
+
vi.spyOn(adaptor, "setViewState").mockResolvedValue(undefined);
|
|
104
|
+
const storeCreator = (set) => ({
|
|
105
|
+
count: 0,
|
|
106
|
+
increment: () => set((state) => ({ count: state.count + 1 })),
|
|
107
|
+
});
|
|
108
|
+
const store = createStore(storeCreator);
|
|
109
|
+
store.getState().increment();
|
|
110
|
+
await vi.waitFor(() => {
|
|
111
|
+
expect(adaptor.setViewState).toHaveBeenCalledWith({ count: 1 });
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
it("should notify listeners when view state changes", async () => {
|
|
115
|
+
const postMessageMock = getMcpAppHostPostMessageMock();
|
|
116
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
117
|
+
const adaptor = McpAppAdaptor.getInstance();
|
|
118
|
+
const listener = vi.fn();
|
|
119
|
+
adaptor.getHostContextStore("viewState").subscribe(listener);
|
|
120
|
+
await adaptor.setViewState({ count: 42 });
|
|
121
|
+
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({ method: "ui/update-model-context" }), "*");
|
|
122
|
+
expect(listener).toHaveBeenCalled();
|
|
123
|
+
expect(adaptor.getHostContextStore("viewState").getSnapshot()).toEqual({
|
|
124
|
+
count: 42,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=create-store.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-store.test.js","sourceRoot":"","sources":["../../src/web/create-store.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAE/B,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,UAGH,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG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E,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;YAE1D,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAEzB,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAC7D,MAAM,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;YAE1C,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,MAAM,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC,EAC9D,GAAG,CACJ,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,CAAC,gBAAgB,EAAE,CAAC;YACpC,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC;gBACrE,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { cleanup } from \"@testing-library/react\";\nimport {\n afterEach,\n beforeEach,\n describe,\n expect,\n it,\n type Mock,\n vi,\n} from \"vitest\";\nimport type { StateCreator } from \"zustand\";\nimport { McpAppAdaptor } from \"./bridges/mcp-app/adaptor.js\";\nimport { McpAppBridge } from \"./bridges/mcp-app/bridge.js\";\nimport { createStore } from \"./create-store.js\";\nimport { VIEW_CONTEXT_KEY } from \"./data-llm.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./hooks/test/utils.js\";\n\ndescribe(\"createStore\", () => {\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n describe(\"apps-sdk mode\", () => {\n let OpenaiMock: {\n widgetState: unknown;\n setWidgetState: Mock;\n };\n\n beforeEach(() => {\n OpenaiMock = {\n widgetState: null,\n setWidgetState: vi.fn().mockResolvedValue(undefined),\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n it(\"should create a store without default state\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 0 });\n });\n\n it(\"should create a store with default state\", () => {\n type TestState = { count: number; name: string };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n name: \"initial\",\n });\n const defaultState = { count: 5, name: \"default\" };\n\n const store = createStore(storeCreator, defaultState);\n\n expect(store.getState()).toEqual({ count: 5, name: \"default\" });\n });\n\n it(\"should initialize from window.openai.widgetState when available\", () => {\n type TestState = { count: number; name: string };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n name: \"initial\",\n });\n const windowState = { count: 20, name: \"window\" };\n OpenaiMock.widgetState = { modelContent: windowState };\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 20, name: \"window\" });\n });\n\n it(\"should persist state changes to window.openai.setWidgetState\", async () => {\n type TestState = { count: number; increment: () => void };\n const storeCreator: StateCreator<TestState, [], [], TestState> = (\n set,\n ) => ({\n count: 0,\n increment: () => set((state) => ({ count: state.count + 1 })),\n });\n\n const store = createStore(storeCreator);\n store.getState().increment();\n\n await vi.waitFor(() => {\n expect(OpenaiMock.setWidgetState).toHaveBeenCalled();\n });\n\n const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];\n expect(callArgs).toEqual({\n modelContent: { count: 1 },\n privateContent: {},\n });\n });\n\n it(\"should filter view context from initial state\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n const windowState = {\n count: 5,\n [VIEW_CONTEXT_KEY]: \"context-value\",\n };\n OpenaiMock.widgetState = { modelContent: windowState };\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 5 });\n expect(\n (store.getState() as Record<string, unknown>)[VIEW_CONTEXT_KEY],\n ).toBeUndefined();\n });\n });\n\n describe(\"mcp-app mode\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n cleanup();\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n });\n\n it(\"should initialize with null viewState\", () => {\n const adaptor = McpAppAdaptor.getInstance();\n const viewState = adaptor.getHostContextStore(\"viewState\").getSnapshot();\n\n expect(viewState).toBeNull();\n });\n\n it(\"should create a store with default state when no persisted state exists\", () => {\n type TestState = { count: number };\n const storeCreator: StateCreator<TestState, [], [], TestState> = () => ({\n count: 0,\n });\n\n const store = createStore(storeCreator);\n\n expect(store.getState()).toEqual({ count: 0 });\n });\n\n it(\"should update in-memory state via setViewState\", async () => {\n const adaptor = McpAppAdaptor.getInstance();\n vi.spyOn(adaptor, \"setViewState\").mockResolvedValue(undefined);\n\n type TestState = { count: number; increment: () => void };\n const storeCreator: StateCreator<TestState, [], [], TestState> = (\n set,\n ) => ({\n count: 0,\n increment: () => set((state) => ({ count: state.count + 1 })),\n });\n\n const store = createStore(storeCreator);\n store.getState().increment();\n\n await vi.waitFor(() => {\n expect(adaptor.setViewState).toHaveBeenCalledWith({ count: 1 });\n });\n });\n\n it(\"should notify listeners when view state changes\", async () => {\n const postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n\n const adaptor = McpAppAdaptor.getInstance();\n const listener = vi.fn();\n\n adaptor.getHostContextStore(\"viewState\").subscribe(listener);\n await adaptor.setViewState({ count: 42 });\n\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({ method: \"ui/update-model-context\" }),\n \"*\",\n );\n expect(listener).toHaveBeenCalled();\n expect(adaptor.getHostContextStore(\"viewState\").getSnapshot()).toEqual({\n count: 42,\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/** Text content surfaced to the model by a {@link DataLLM} component. */
|
|
3
|
+
export type DataLLMContent = string;
|
|
4
|
+
/**
|
|
5
|
+
* A node in the {@link DataLLM} tree. Nested `<DataLLM>` elements form a
|
|
6
|
+
* hierarchy that is serialized as an indented bullet list for the model.
|
|
7
|
+
*/
|
|
8
|
+
export interface DataLLMNode {
|
|
9
|
+
id: string;
|
|
10
|
+
parentId: string | null;
|
|
11
|
+
content: string | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Key under which the serialized {@link DataLLM} tree is persisted on the
|
|
15
|
+
* host's `viewState`. The host exposes the value to the model on subsequent
|
|
16
|
+
* turns.
|
|
17
|
+
*/
|
|
18
|
+
export declare const VIEW_CONTEXT_KEY: "__view_context";
|
|
19
|
+
interface DataLLMProps {
|
|
20
|
+
content: DataLLMContent | null | undefined;
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Surface in-view content to the LLM so it can reason about what the user is
|
|
25
|
+
* seeing without an extra tool call.
|
|
26
|
+
*
|
|
27
|
+
* Each `<DataLLM>` registers `content` as a node in a tree (parented by any
|
|
28
|
+
* enclosing `<DataLLM>`). The flattened tree is serialized as an indented
|
|
29
|
+
* bullet list and persisted on the host's `viewState` under
|
|
30
|
+
* {@link VIEW_CONTEXT_KEY}; the host then surfaces it to the model as part of
|
|
31
|
+
* the next turn's context.
|
|
32
|
+
*
|
|
33
|
+
* Pass `null`/`undefined` for `content` to register only as a structural
|
|
34
|
+
* parent (useful for grouping).
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <DataLLM content="Active filters">
|
|
39
|
+
* <DataLLM content={`Sort: ${sort}`} />
|
|
40
|
+
* <DataLLM content={`Page: ${page}`} />
|
|
41
|
+
* </DataLLM>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see https://docs.skybridge.tech/api-reference/data-llm
|
|
45
|
+
*/
|
|
46
|
+
export declare function DataLLM({ content, children }: DataLLMProps): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export {};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useEffect, useId, } from "react";
|
|
3
|
-
|
|
3
|
+
import { getAdaptor } from "./bridges/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Key under which the serialized {@link DataLLM} tree is persisted on the
|
|
6
|
+
* host's `viewState`. The host exposes the value to the model on subsequent
|
|
7
|
+
* turns.
|
|
8
|
+
*/
|
|
9
|
+
export const VIEW_CONTEXT_KEY = "__view_context";
|
|
4
10
|
const nodes = new Map();
|
|
5
11
|
function setNode(node) {
|
|
6
12
|
nodes.set(node.id, node);
|
|
@@ -12,12 +18,36 @@ function removeNode(id) {
|
|
|
12
18
|
}
|
|
13
19
|
function onChange() {
|
|
14
20
|
const description = getLLMDescriptionString();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
const adaptor = getAdaptor();
|
|
22
|
+
adaptor.setViewState((prevState) => ({
|
|
23
|
+
...prevState,
|
|
24
|
+
[VIEW_CONTEXT_KEY]: description,
|
|
25
|
+
}));
|
|
19
26
|
}
|
|
20
27
|
const ParentIdContext = createContext(null);
|
|
28
|
+
/**
|
|
29
|
+
* Surface in-view content to the LLM so it can reason about what the user is
|
|
30
|
+
* seeing without an extra tool call.
|
|
31
|
+
*
|
|
32
|
+
* Each `<DataLLM>` registers `content` as a node in a tree (parented by any
|
|
33
|
+
* enclosing `<DataLLM>`). The flattened tree is serialized as an indented
|
|
34
|
+
* bullet list and persisted on the host's `viewState` under
|
|
35
|
+
* {@link VIEW_CONTEXT_KEY}; the host then surfaces it to the model as part of
|
|
36
|
+
* the next turn's context.
|
|
37
|
+
*
|
|
38
|
+
* Pass `null`/`undefined` for `content` to register only as a structural
|
|
39
|
+
* parent (useful for grouping).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <DataLLM content="Active filters">
|
|
44
|
+
* <DataLLM content={`Sort: ${sort}`} />
|
|
45
|
+
* <DataLLM content={`Page: ${page}`} />
|
|
46
|
+
* </DataLLM>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see https://docs.skybridge.tech/api-reference/data-llm
|
|
50
|
+
*/
|
|
21
51
|
export function DataLLM({ content, children }) {
|
|
22
52
|
const parentId = useContext(ParentIdContext);
|
|
23
53
|
const id = useId();
|