skybridge 0.0.0-dev.f76ccdc → 0.0.0-dev.f792261
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 +97 -142
- 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 +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 +102 -0
- package/dist/commands/build.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 +10 -0
- package/dist/server/asset-base-url-transform-plugin.js +33 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +84 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +27 -0
- package/dist/server/content-helpers.js +46 -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/index.d.ts +6 -0
- package/dist/server/index.js +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/inferUtilityTypes.d.ts +64 -0
- package/dist/server/inferUtilityTypes.js +2 -0
- 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 +124 -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 +196 -0
- package/dist/server/server.js +468 -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 +523 -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 +24 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +96 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -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 +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 +131 -0
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +2 -0
- package/dist/web/bridges/get-adaptor.js +8 -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 +48 -0
- package/dist/web/bridges/mcp-app/adaptor.js +263 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
- package/dist/web/bridges/mcp-app/bridge.js +102 -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 +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -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 +111 -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 +2 -0
- package/dist/web/bridges/use-host-context.js +8 -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 +3 -0
- package/dist/web/create-store.js +38 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.d.ts +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 +14 -0
- package/dist/web/data-llm.js +72 -0
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.d.ts +1 -0
- package/dist/web/data-llm.test.js +142 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/web/generate-helpers.d.ts +118 -0
- package/dist/web/generate-helpers.js +113 -0
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/web/generate-helpers.test-d.js +209 -0
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.d.ts +1 -0
- package/dist/web/generate-helpers.test.js +17 -0
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/web/helpers/state.d.ts +7 -0
- 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 +11 -0
- package/dist/web/hooks/index.js +12 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +16 -0
- package/dist/web/hooks/test/utils.js +64 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/web/hooks/use-call-tool.d.ts +101 -0
- package/dist/web/hooks/use-call-tool.js +68 -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/web/hooks/use-call-tool.test-d.js +104 -0
- 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/web/hooks/use-call-tool.test.js +186 -0
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/web/hooks/use-display-mode.js +9 -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/{src/web → web}/hooks/use-display-mode.test.js +3 -2
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +7 -0
- package/dist/web/hooks/use-files.js +10 -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/web/hooks/use-layout.d.ts +22 -0
- package/dist/web/hooks/use-layout.js +23 -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 +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +3 -0
- package/dist/web/hooks/use-open-external.js +8 -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 +65 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +9 -0
- package/dist/web/hooks/use-request-modal.js +16 -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 +61 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +2 -0
- package/dist/web/hooks/use-send-follow-up-message.js +8 -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 +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +8 -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 +36 -0
- package/dist/web/hooks/use-tool-info.js +26 -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 +109 -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/web/hooks/use-tool-info.test.js +130 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +18 -0
- package/dist/web/hooks/use-user.js +35 -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 +122 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-view-state.d.ts +4 -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/web/index.d.ts +7 -0
- package/dist/web/index.js +8 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-view.d.ts +1 -0
- package/dist/web/mount-view.js +27 -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 +81 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +5 -0
- package/dist/web/plugin/plugin.js +156 -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/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/web/plugin/transform-data-llm.js +96 -0
- 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 +81 -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/web/proxy.d.ts +1 -0
- package/dist/web/proxy.js +52 -0
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +82 -35
- package/tsconfig.base.json +33 -0
- package/dist/src/server/index.d.ts +0 -2
- package/dist/src/server/index.js +0 -3
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -13
- package/dist/src/server/server.js +0 -54
- 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/setup.js +0 -9
- package/dist/src/test/setup.js.map +0 -1
- package/dist/src/test/utils.d.ts +0 -28
- package/dist/src/test/utils.js +0 -43
- 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/hooks/index.d.ts +0 -13
- package/dist/src/web/hooks/index.js +0 -14
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.d.ts +0 -54
- package/dist/src/web/hooks/use-call-tool.js +0 -44
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js +0 -66
- 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.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 -21
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -5
- 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 -5
- package/dist/src/web/hooks/use-tool-info.js +0 -9
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -38
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-output.js +0 -9
- package/dist/src/web/hooks/use-tool-output.js.map +0 -1
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
- package/dist/src/web/hooks/use-tool-response-metadata.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 -30
- 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.d.ts +0 -4
- package/dist/src/web/index.js +0 -5
- 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 -14
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin.d.ts +0 -2
- package/dist/src/web/plugin.js +0 -28
- package/dist/src/web/plugin.js.map +0 -1
- package/dist/src/web/types.d.ts +0 -109
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -9
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/setup.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
- /package/dist/{src/test/widget.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → cli/tunnel.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → server/content-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → server/middleware.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → server/middleware.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → server/tunnel-proxy-router.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → test/view.test.d.ts} +0 -0
- /package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { McpAppBridge } from "../bridges/mcp-app/bridge.js";
|
|
4
|
+
import { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
5
|
+
import { useOpenExternal } from "./use-open-external.js";
|
|
6
|
+
describe("useOpenExternal", () => {
|
|
7
|
+
describe("apps-sdk host", () => {
|
|
8
|
+
let openExternalMock;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
openExternalMock = vi.fn();
|
|
11
|
+
vi.stubGlobal("openai", {
|
|
12
|
+
openExternal: openExternalMock,
|
|
13
|
+
});
|
|
14
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
vi.unstubAllGlobals();
|
|
18
|
+
vi.resetAllMocks();
|
|
19
|
+
});
|
|
20
|
+
it("should return a function that calls window.openai.openExternal with the href", () => {
|
|
21
|
+
const { result } = renderHook(() => useOpenExternal());
|
|
22
|
+
const href = "https://example.com";
|
|
23
|
+
result.current(href);
|
|
24
|
+
expect(openExternalMock).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(openExternalMock).toHaveBeenCalledWith({ href });
|
|
26
|
+
});
|
|
27
|
+
it("should forward redirectUrl false option to window.openai.openExternal", () => {
|
|
28
|
+
const { result } = renderHook(() => useOpenExternal());
|
|
29
|
+
const href = "https://example.com";
|
|
30
|
+
result.current(href, { redirectUrl: false });
|
|
31
|
+
expect(openExternalMock).toHaveBeenCalledTimes(1);
|
|
32
|
+
expect(openExternalMock).toHaveBeenCalledWith({
|
|
33
|
+
href,
|
|
34
|
+
redirectUrl: false,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("mcp-app host", () => {
|
|
39
|
+
let postMessageMock;
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
42
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
43
|
+
postMessageMock = getMcpAppHostPostMessageMock();
|
|
44
|
+
vi.stubGlobal("parent", { postMessage: postMessageMock });
|
|
45
|
+
});
|
|
46
|
+
afterEach(async () => {
|
|
47
|
+
vi.unstubAllGlobals();
|
|
48
|
+
vi.resetAllMocks();
|
|
49
|
+
McpAppBridge.resetInstance();
|
|
50
|
+
});
|
|
51
|
+
it("should return a function that sends ui/open-link request to the MCP host", async () => {
|
|
52
|
+
const { result } = renderHook(() => useOpenExternal());
|
|
53
|
+
const href = "https://example.com";
|
|
54
|
+
result.current(href, { redirectUrl: false });
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
expect(postMessageMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
57
|
+
jsonrpc: "2.0",
|
|
58
|
+
method: "ui/open-link",
|
|
59
|
+
params: { url: href },
|
|
60
|
+
}), "*");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=use-open-external.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-open-external.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;I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AC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useOpenExternal } from \"./use-open-external.js\";\n\ndescribe(\"useOpenExternal\", () => {\n describe(\"apps-sdk host\", () => {\n let openExternalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n openExternalMock = vi.fn();\n vi.stubGlobal(\"openai\", {\n openExternal: openExternalMock,\n });\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return a function that calls window.openai.openExternal with the href\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href);\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({ href });\n });\n\n it(\"should forward redirectUrl false option to window.openai.openExternal\", () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n expect(openExternalMock).toHaveBeenCalledTimes(1);\n expect(openExternalMock).toHaveBeenCalledWith({\n href,\n redirectUrl: false,\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n let postMessageMock: ReturnType<typeof getMcpAppHostPostMessageMock>;\n\n beforeEach(() => {\n vi.stubGlobal(\"skybridge\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n postMessageMock = getMcpAppHostPostMessageMock();\n vi.stubGlobal(\"parent\", { postMessage: postMessageMock });\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n });\n\n it(\"should return a function that sends ui/open-link request to the MCP host\", async () => {\n const { result } = renderHook(() => useOpenExternal());\n\n const href = \"https://example.com\";\n result.current(href, { redirectUrl: false });\n\n await waitFor(() => {\n expect(postMessageMock).toHaveBeenCalledWith(\n expect.objectContaining({\n jsonrpc: \"2.0\",\n method: \"ui/open-link\",\n params: { url: href },\n }),\n \"*\",\n );\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RequestModalOptions } from "../bridges/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Triggers a modal containing the view rendered in display mode "modal"
|
|
4
|
+
*/
|
|
5
|
+
export declare function useRequestModal(): {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
params: Record<string, unknown> | undefined;
|
|
8
|
+
open: (opts: RequestModalOptions) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor, useHostContext, } from "../bridges/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Triggers a modal containing the view rendered in display mode "modal"
|
|
5
|
+
*/
|
|
6
|
+
export function useRequestModal() {
|
|
7
|
+
const adaptor = getAdaptor();
|
|
8
|
+
const display = useHostContext("display");
|
|
9
|
+
const open = useCallback((opts) => adaptor.openModal(opts), [adaptor]);
|
|
10
|
+
return {
|
|
11
|
+
isOpen: display.mode === "modal",
|
|
12
|
+
params: display.params,
|
|
13
|
+
open,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=use-request-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,EAEV,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,WAAW,CACtB,CAAC,IAAyB,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EACtD,CAAC,OAAO,CAAC,CACV,CAAC;IACF,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,OAAO;QAChC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type RequestModalOptions,\n useHostContext,\n} from \"../bridges/index.js\";\n\n/**\n * Triggers a modal containing the view rendered in display mode \"modal\"\n */\nexport function useRequestModal() {\n const adaptor = getAdaptor();\n const display = useHostContext(\"display\");\n const open = useCallback(\n (opts: RequestModalOptions) => adaptor.openModal(opts),\n [adaptor],\n );\n return {\n isOpen: display.mode === \"modal\",\n params: display.params,\n open,\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { useRequestModal } from "./use-request-modal.js";
|
|
4
|
+
describe("useRequestModal", () => {
|
|
5
|
+
let requestModalMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
requestModalMock = vi.fn();
|
|
8
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
9
|
+
vi.stubGlobal("openai", {
|
|
10
|
+
requestModal: requestModalMock,
|
|
11
|
+
view: { mode: "inline" },
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.unstubAllGlobals();
|
|
16
|
+
vi.resetAllMocks();
|
|
17
|
+
});
|
|
18
|
+
it("should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal", () => {
|
|
19
|
+
const { result } = renderHook(() => useRequestModal());
|
|
20
|
+
expect(typeof result.current).toBe("object");
|
|
21
|
+
expect(result.current).toHaveProperty("open");
|
|
22
|
+
expect(result.current).toHaveProperty("isOpen");
|
|
23
|
+
expect(result.current).toHaveProperty("params");
|
|
24
|
+
const { open, isOpen, params } = result.current;
|
|
25
|
+
expect(typeof open).toBe("function");
|
|
26
|
+
expect(isOpen).toBe(false);
|
|
27
|
+
expect(params).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
it("should return isOpen as true when mode is modal", () => {
|
|
30
|
+
vi.stubGlobal("openai", {
|
|
31
|
+
requestModal: requestModalMock,
|
|
32
|
+
view: { mode: "modal" },
|
|
33
|
+
});
|
|
34
|
+
const { result } = renderHook(() => useRequestModal());
|
|
35
|
+
const { isOpen } = result.current;
|
|
36
|
+
expect(isOpen).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it("should return params from view when available", () => {
|
|
39
|
+
const testParams = { foo: "bar", baz: 42 };
|
|
40
|
+
vi.stubGlobal("openai", {
|
|
41
|
+
requestModal: requestModalMock,
|
|
42
|
+
view: { mode: "modal", params: testParams },
|
|
43
|
+
});
|
|
44
|
+
const { result } = renderHook(() => useRequestModal());
|
|
45
|
+
const { params } = result.current;
|
|
46
|
+
expect(params).toEqual(testParams);
|
|
47
|
+
});
|
|
48
|
+
it("should call window.openai.requestModal with the options when open is called", () => {
|
|
49
|
+
const { result } = renderHook(() => useRequestModal());
|
|
50
|
+
const { open } = result.current;
|
|
51
|
+
const options = {
|
|
52
|
+
title: "Test Modal",
|
|
53
|
+
params: { foo: "bar" },
|
|
54
|
+
template: "ui://view/modal-template.html",
|
|
55
|
+
};
|
|
56
|
+
open(options);
|
|
57
|
+
expect(requestModalMock).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(requestModalMock).toHaveBeenCalledWith(options);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=use-request-modal.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-request-modal.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA0C,CAAC;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,YAAY,EAAE,gBAAgB;YAC9B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+GAA+G,EAAE,GAAG,EAAE;QACvH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QAEvD,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,OAAO,CAA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D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;QAElC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6EAA6E,EAAE,GAAG,EAAE;QACrF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QACvD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;QAEhC,MAAM,OAAO,GAAG;YACd,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;YACtB,QAAQ,EAAE,+BAA+B;SAC1C,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,CAAC;QAEd,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { useRequestModal } from \"./use-request-modal.js\";\n\ndescribe(\"useRequestModal\", () => {\n let requestModalMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n requestModalMock = vi.fn();\n vi.stubGlobal(\"skybridge\", { hostType: \"apps-sdk\" });\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"inline\" },\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return an object with open, isOpen, and params properties where isOpen is false when mode is not modal\", () => {\n const { result } = renderHook(() => useRequestModal());\n\n expect(typeof result.current).toBe(\"object\");\n expect(result.current).toHaveProperty(\"open\");\n expect(result.current).toHaveProperty(\"isOpen\");\n expect(result.current).toHaveProperty(\"params\");\n\n const { open, isOpen, params } = result.current;\n expect(typeof open).toBe(\"function\");\n expect(isOpen).toBe(false);\n expect(params).toBeUndefined();\n });\n\n it(\"should return isOpen as true when mode is modal\", () => {\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\" },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { isOpen } = result.current;\n\n expect(isOpen).toBe(true);\n });\n\n it(\"should return params from view when available\", () => {\n const testParams = { foo: \"bar\", baz: 42 };\n vi.stubGlobal(\"openai\", {\n requestModal: requestModalMock,\n view: { mode: \"modal\", params: testParams },\n });\n\n const { result } = renderHook(() => useRequestModal());\n const { params } = result.current;\n\n expect(params).toEqual(testParams);\n });\n\n it(\"should call window.openai.requestModal with the options when open is called\", () => {\n const { result } = renderHook(() => useRequestModal());\n const { open } = result.current;\n\n const options = {\n title: \"Test Modal\",\n params: { foo: \"bar\" },\n template: \"ui://view/modal-template.html\",\n };\n open(options);\n\n expect(requestModalMock).toHaveBeenCalledTimes(1);\n expect(requestModalMock).toHaveBeenCalledWith(options);\n });\n});\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor, } from "../bridges/index.js";
|
|
3
|
+
export function useSendFollowUpMessage() {
|
|
4
|
+
const adaptor = getAdaptor();
|
|
5
|
+
const sendFollowUpMessage = useCallback((prompt, options) => adaptor.sendFollowUpMessage(prompt, options), [adaptor]);
|
|
6
|
+
return sendFollowUpMessage;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=use-send-follow-up-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-send-follow-up-message.js","sourceRoot":"","sources":["../../../src/web/hooks/use-send-follow-up-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EACL,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAE7B,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,WAAW,CACrC,CAAC,MAAc,EAAE,OAAoC,EAAE,EAAE,CACvD,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport {\n getAdaptor,\n type SendFollowUpMessageOptions,\n} from \"../bridges/index.js\";\n\nexport function useSendFollowUpMessage() {\n const adaptor = getAdaptor();\n const sendFollowUpMessage = useCallback(\n (prompt: string, options?: SendFollowUpMessageOptions) =>\n adaptor.sendFollowUpMessage(prompt, options),\n [adaptor],\n );\n\n return sendFollowUpMessage;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useSetOpenInAppUrl(): (href: string) => Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getAdaptor } from "../bridges/index.js";
|
|
3
|
+
export function useSetOpenInAppUrl() {
|
|
4
|
+
const adaptor = getAdaptor();
|
|
5
|
+
const setOpenInAppUrl = useCallback((href) => adaptor.setOpenInAppUrl(href), [adaptor]);
|
|
6
|
+
return setOpenInAppUrl;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=use-set-open-in-app-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-set-open-in-app-url.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,eAAe,GAAG,WAAW,CACjC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAC/C,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { getAdaptor } from \"../bridges/index.js\";\n\nexport function useSetOpenInAppUrl() {\n const adaptor = getAdaptor();\n const setOpenInAppUrl = useCallback(\n (href: string) => adaptor.setOpenInAppUrl(href),\n [adaptor],\n );\n\n return setOpenInAppUrl;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { AppsSdkAdaptor } from "../bridges/apps-sdk/adaptor.js";
|
|
4
|
+
import { useSetOpenInAppUrl } from "./use-set-open-in-app-url.js";
|
|
5
|
+
describe("useSetOpenInAppUrl", () => {
|
|
6
|
+
describe("apps-sdk host", () => {
|
|
7
|
+
let setOpenInAppUrlMock;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
setOpenInAppUrlMock = vi.fn().mockResolvedValue(undefined);
|
|
10
|
+
vi.stubGlobal("openai", {
|
|
11
|
+
setOpenInAppUrl: setOpenInAppUrlMock,
|
|
12
|
+
});
|
|
13
|
+
vi.stubGlobal("skybridge", {
|
|
14
|
+
hostType: "apps-sdk",
|
|
15
|
+
serverUrl: "https://example.com",
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.unstubAllGlobals();
|
|
20
|
+
vi.resetAllMocks();
|
|
21
|
+
AppsSdkAdaptor.resetInstance();
|
|
22
|
+
});
|
|
23
|
+
it("should return a function that calls window.openai.setOpenInAppUrl with the href", async () => {
|
|
24
|
+
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
25
|
+
const href = "https://example.com/path";
|
|
26
|
+
await result.current(href);
|
|
27
|
+
expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);
|
|
28
|
+
expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
|
|
29
|
+
});
|
|
30
|
+
it("should throw an error when href is empty", () => {
|
|
31
|
+
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
32
|
+
expect(() => result.current("")).toThrow("The href parameter is required.");
|
|
33
|
+
});
|
|
34
|
+
it("should call setOpenInAppUrl when href origin differs from serverUrl origin", async () => {
|
|
35
|
+
const { result } = renderHook(() => useSetOpenInAppUrl());
|
|
36
|
+
const href = "https://different-domain.com/path";
|
|
37
|
+
await result.current(href);
|
|
38
|
+
expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=use-set-open-in-app-url.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-set-open-in-app-url.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-set-open-in-app-url.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,mBAA6C,CAAC;QAElD,UAAU,CAAC,GAAG,EAAE;YACd,mBAAmB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;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YAE1D,MAAM,IAAI,GAAG,mCAAmC,CAAC;YACjD,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAE3B,MAAM,CAAC,mBAAmB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YACrD,MAAM,CAAC,mBAAmB,CAAC,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { AppsSdkAdaptor } from \"../bridges/apps-sdk/adaptor.js\";\nimport { useSetOpenInAppUrl } from \"./use-set-open-in-app-url.js\";\n\ndescribe(\"useSetOpenInAppUrl\", () => {\n describe(\"apps-sdk host\", () => {\n let setOpenInAppUrlMock: ReturnType<typeof vi.fn>;\n\n beforeEach(() => {\n setOpenInAppUrlMock = vi.fn().mockResolvedValue(undefined);\n vi.stubGlobal(\"openai\", {\n setOpenInAppUrl: setOpenInAppUrlMock,\n });\n vi.stubGlobal(\"skybridge\", {\n hostType: \"apps-sdk\",\n serverUrl: \"https://example.com\",\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n AppsSdkAdaptor.resetInstance();\n });\n\n it(\"should return a function that calls window.openai.setOpenInAppUrl with the href\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n const href = \"https://example.com/path\";\n await result.current(href);\n\n expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);\n expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });\n });\n\n it(\"should throw an error when href is empty\", () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n expect(() => result.current(\"\")).toThrow(\n \"The href parameter is required.\",\n );\n });\n\n it(\"should call setOpenInAppUrl when href origin differs from serverUrl origin\", async () => {\n const { result } = renderHook(() => useSetOpenInAppUrl());\n\n const href = \"https://different-domain.com/path\";\n await result.current(href);\n\n expect(setOpenInAppUrlMock).toHaveBeenCalledTimes(1);\n expect(setOpenInAppUrlMock).toHaveBeenCalledWith({ href });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { UnknownObject } from "../types.js";
|
|
2
|
+
export type ToolIdleState = {
|
|
3
|
+
status: "idle";
|
|
4
|
+
isIdle: true;
|
|
5
|
+
isPending: false;
|
|
6
|
+
isSuccess: false;
|
|
7
|
+
input: undefined;
|
|
8
|
+
output: undefined;
|
|
9
|
+
responseMetadata: undefined;
|
|
10
|
+
};
|
|
11
|
+
export type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
12
|
+
status: "pending";
|
|
13
|
+
isIdle: false;
|
|
14
|
+
isPending: true;
|
|
15
|
+
isSuccess: false;
|
|
16
|
+
input: ToolInput;
|
|
17
|
+
output: undefined;
|
|
18
|
+
responseMetadata: undefined;
|
|
19
|
+
};
|
|
20
|
+
export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
|
|
21
|
+
status: "success";
|
|
22
|
+
isIdle: false;
|
|
23
|
+
isPending: false;
|
|
24
|
+
isSuccess: true;
|
|
25
|
+
input: ToolInput;
|
|
26
|
+
output: ToolOutput;
|
|
27
|
+
responseMetadata: ToolResponseMetadata;
|
|
28
|
+
};
|
|
29
|
+
export type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolIdleState | ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
30
|
+
type ToolSignature = {
|
|
31
|
+
input: UnknownObject;
|
|
32
|
+
output: UnknownObject;
|
|
33
|
+
responseMetadata: UnknownObject;
|
|
34
|
+
};
|
|
35
|
+
export declare function useToolInfo<TS extends Partial<ToolSignature> = Record<string, never>>(): ToolState<UnknownObject & TS["input"], UnknownObject & TS["output"], UnknownObject & TS["responseMetadata"]>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useHostContext } from "../bridges/index.js";
|
|
2
|
+
function deriveStatus(input, output, responseMetadata) {
|
|
3
|
+
if (input === null) {
|
|
4
|
+
return "idle";
|
|
5
|
+
}
|
|
6
|
+
if (output === null && responseMetadata === null) {
|
|
7
|
+
return "pending";
|
|
8
|
+
}
|
|
9
|
+
return "success";
|
|
10
|
+
}
|
|
11
|
+
export function useToolInfo() {
|
|
12
|
+
const input = useHostContext("toolInput");
|
|
13
|
+
const output = useHostContext("toolOutput");
|
|
14
|
+
const responseMetadata = useHostContext("toolResponseMetadata");
|
|
15
|
+
const status = deriveStatus(input, output, responseMetadata);
|
|
16
|
+
return {
|
|
17
|
+
input,
|
|
18
|
+
status,
|
|
19
|
+
isIdle: status === "idle",
|
|
20
|
+
isPending: status === "pending",
|
|
21
|
+
isSuccess: status === "success",
|
|
22
|
+
output,
|
|
23
|
+
responseMetadata,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=use-tool-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAoDrD,SAAS,YAAY,CACnB,KAAqC,EACrC,MAAsC,EACtC,gBAAgD;IAEhD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW;IAGzB,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,cAAc,CAAC,sBAAsB,CAAC,CAAC;IAEhE,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAM7D,OAAO;QACL,KAAK;QACL,MAAM;QACN,MAAM,EAAE,MAAM,KAAK,MAAM;QACzB,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,MAAM;QACN,gBAAgB;KACqB,CAAC;AAC1C,CAAC","sourcesContent":["import { useHostContext } from \"../bridges/index.js\";\nimport type { UnknownObject } from \"../types.js\";\n\nexport type ToolIdleState = {\n status: \"idle\";\n isIdle: true;\n isPending: false;\n isSuccess: false;\n input: undefined;\n output: undefined;\n responseMetadata: undefined;\n};\n\nexport type ToolPendingState<ToolInput extends UnknownObject> = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n input: ToolInput;\n output: undefined;\n responseMetadata: undefined;\n};\n\nexport type ToolSuccessState<\n ToolInput extends UnknownObject,\n ToolOutput extends UnknownObject,\n ToolResponseMetadata extends UnknownObject,\n> = {\n status: \"success\";\n isIdle: false;\n isPending: false;\n isSuccess: true;\n input: ToolInput;\n output: ToolOutput;\n responseMetadata: ToolResponseMetadata;\n};\n\nexport type ToolState<\n ToolInput extends UnknownObject,\n ToolOutput extends UnknownObject,\n ToolResponseMetadata extends UnknownObject,\n> =\n | ToolIdleState\n | ToolPendingState<ToolInput>\n | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;\n\ntype ToolSignature = {\n input: UnknownObject;\n output: UnknownObject;\n responseMetadata: UnknownObject;\n};\n\nfunction deriveStatus(\n input: Record<string, unknown> | null,\n output: Record<string, unknown> | null,\n responseMetadata: Record<string, unknown> | null,\n): \"idle\" | \"pending\" | \"success\" {\n if (input === null) {\n return \"idle\";\n }\n if (output === null && responseMetadata === null) {\n return \"pending\";\n }\n return \"success\";\n}\n\nexport function useToolInfo<\n TS extends Partial<ToolSignature> = Record<string, never>,\n>() {\n const input = useHostContext(\"toolInput\");\n const output = useHostContext(\"toolOutput\");\n const responseMetadata = useHostContext(\"toolResponseMetadata\");\n\n const status = deriveStatus(input, output, responseMetadata);\n\n type Input = UnknownObject & TS[\"input\"];\n type Output = UnknownObject & TS[\"output\"];\n type Metadata = UnknownObject & TS[\"responseMetadata\"];\n\n return {\n input,\n status,\n isIdle: status === \"idle\",\n isPending: status === \"pending\",\n isSuccess: status === \"success\",\n output,\n responseMetadata,\n } as ToolState<Input, Output, Metadata>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
3
|
+
test("useToolInfo - TypeScript typing", () => {
|
|
4
|
+
test("should have correct types when no generic parameter is provided", () => {
|
|
5
|
+
const result = useToolInfo();
|
|
6
|
+
expectTypeOf(result.status);
|
|
7
|
+
expectTypeOf(result.isPending);
|
|
8
|
+
expectTypeOf(result.isSuccess);
|
|
9
|
+
expectTypeOf(result.isIdle);
|
|
10
|
+
expectTypeOf(result.input);
|
|
11
|
+
});
|
|
12
|
+
test("should correctly type input, output, and responseMetadata with explicit ToolSignature", () => {
|
|
13
|
+
const result = useToolInfo();
|
|
14
|
+
// When idle, input should be undefined
|
|
15
|
+
if (result.status === "idle") {
|
|
16
|
+
expectTypeOf(result.input);
|
|
17
|
+
expectTypeOf(result.output);
|
|
18
|
+
expectTypeOf(result.responseMetadata);
|
|
19
|
+
}
|
|
20
|
+
// When pending, output and responseMetadata should be undefined
|
|
21
|
+
if (result.status === "pending") {
|
|
22
|
+
expectTypeOf(result.input);
|
|
23
|
+
expectTypeOf(result.output);
|
|
24
|
+
expectTypeOf(result.responseMetadata);
|
|
25
|
+
}
|
|
26
|
+
// When success, output and responseMetadata should be defined
|
|
27
|
+
if (result.status === "success") {
|
|
28
|
+
expectTypeOf(result.input);
|
|
29
|
+
expectTypeOf(result.output);
|
|
30
|
+
expectTypeOf(result.responseMetadata);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
test("should correctly narrow types based on status discriminated union", () => {
|
|
34
|
+
const result = useToolInfo();
|
|
35
|
+
// Test type narrowing for idle
|
|
36
|
+
if (result.isIdle) {
|
|
37
|
+
expectTypeOf(result.status);
|
|
38
|
+
expectTypeOf(result.isIdle);
|
|
39
|
+
expectTypeOf(result.isPending);
|
|
40
|
+
expectTypeOf(result.isSuccess);
|
|
41
|
+
expectTypeOf(result.input);
|
|
42
|
+
expectTypeOf(result.output);
|
|
43
|
+
expectTypeOf(result.responseMetadata);
|
|
44
|
+
}
|
|
45
|
+
// Test type narrowing for pending
|
|
46
|
+
if (result.isPending) {
|
|
47
|
+
expectTypeOf(result.status);
|
|
48
|
+
expectTypeOf(result.isIdle);
|
|
49
|
+
expectTypeOf(result.isPending);
|
|
50
|
+
expectTypeOf(result.isSuccess);
|
|
51
|
+
expectTypeOf(result.output);
|
|
52
|
+
expectTypeOf(result.responseMetadata);
|
|
53
|
+
}
|
|
54
|
+
if (result.isSuccess) {
|
|
55
|
+
expectTypeOf(result.status);
|
|
56
|
+
expectTypeOf(result.isIdle);
|
|
57
|
+
expectTypeOf(result.isPending);
|
|
58
|
+
expectTypeOf(result.isSuccess);
|
|
59
|
+
expectTypeOf(result.output);
|
|
60
|
+
expectTypeOf(result.responseMetadata);
|
|
61
|
+
}
|
|
62
|
+
if (result.status === "idle") {
|
|
63
|
+
expectTypeOf(result.isIdle);
|
|
64
|
+
expectTypeOf(result.isPending);
|
|
65
|
+
expectTypeOf(result.isSuccess);
|
|
66
|
+
expectTypeOf(result.input);
|
|
67
|
+
expectTypeOf(result.output);
|
|
68
|
+
expectTypeOf(result.responseMetadata);
|
|
69
|
+
}
|
|
70
|
+
if (result.status === "pending") {
|
|
71
|
+
expectTypeOf(result.input);
|
|
72
|
+
expectTypeOf(result.isIdle);
|
|
73
|
+
expectTypeOf(result.isPending);
|
|
74
|
+
expectTypeOf(result.isSuccess);
|
|
75
|
+
expectTypeOf(result.output);
|
|
76
|
+
expectTypeOf(result.responseMetadata);
|
|
77
|
+
}
|
|
78
|
+
if (result.status === "success") {
|
|
79
|
+
expectTypeOf(result.input);
|
|
80
|
+
expectTypeOf(result.isIdle);
|
|
81
|
+
expectTypeOf(result.isPending);
|
|
82
|
+
expectTypeOf(result.isSuccess);
|
|
83
|
+
expectTypeOf(result.output);
|
|
84
|
+
expectTypeOf(result.responseMetadata);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
test("should handle partial ToolSignature with only input specified", () => {
|
|
88
|
+
const result = useToolInfo();
|
|
89
|
+
// Input can be TestInput or undefined (when idle)
|
|
90
|
+
if (result.status === "pending" || result.status === "success") {
|
|
91
|
+
expectTypeOf(result.input);
|
|
92
|
+
}
|
|
93
|
+
if (result.status === "success") {
|
|
94
|
+
expectTypeOf(result.output);
|
|
95
|
+
expectTypeOf(result.responseMetadata);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
test("should handle ToolSignature with only output specified", () => {
|
|
99
|
+
const result = useToolInfo();
|
|
100
|
+
// Input can be Record<string, unknown> or undefined (when idle)
|
|
101
|
+
if (result.status === "pending" || result.status === "success") {
|
|
102
|
+
expectTypeOf(result.input);
|
|
103
|
+
}
|
|
104
|
+
if (result.status === "success") {
|
|
105
|
+
expectTypeOf(result.output);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=use-tool-info.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-info.test-d.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,O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I,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/D,YAAY,CAAY,MAAM,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAA0B,MAAM,CAAC,MAAM,CAAC,CAAC;YACrD,YAAY,CAA0B,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAGlE,MAAM,MAAM,GAAG,WAAW,EAEtB,CAAC;QAEL,gEAAgE;QAChE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/D,YAAY,CAA0B,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAa,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expectTypeOf, test } from \"vitest\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ntest(\"useToolInfo - TypeScript typing\", () => {\n test(\"should have correct types when no generic parameter is provided\", () => {\n const result = useToolInfo();\n\n expectTypeOf<\"idle\" | \"pending\" | \"success\">(result.status);\n expectTypeOf<boolean>(result.isPending);\n expectTypeOf<boolean>(result.isSuccess);\n expectTypeOf<boolean>(result.isIdle);\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\n });\n\n test(\"should correctly type input, output, and responseMetadata with explicit ToolSignature\", () => {\n type TestInput = { name: string; args: { name: string } };\n type TestOutput = { name: string; color: string };\n type TestMetadata = { id: number };\n\n const result = useToolInfo<{\n input: TestInput;\n output: TestOutput;\n responseMetadata: TestMetadata;\n }>();\n\n // When idle, input should be undefined\n if (result.status === \"idle\") {\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When pending, output and responseMetadata should be undefined\n if (result.status === \"pending\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When success, output and responseMetadata should be defined\n if (result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n });\n\n test(\"should correctly narrow types based on status discriminated union\", () => {\n type TestInput = { query: string };\n type TestOutput = { result: string };\n type TestMetadata = { timestamp: number };\n\n const result = useToolInfo<{\n input: TestInput;\n output: TestOutput;\n responseMetadata: TestMetadata;\n }>();\n\n // Test type narrowing for idle\n if (result.isIdle) {\n expectTypeOf<\"idle\">(result.status);\n expectTypeOf<true>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // Test type narrowing for pending\n if (result.isPending) {\n expectTypeOf<\"pending\">(result.status);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<true>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.isSuccess) {\n expectTypeOf<\"success\">(result.status);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<true>(result.isSuccess);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n\n if (result.status === \"idle\") {\n expectTypeOf<true>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.status === \"pending\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<true>(result.isPending);\n expectTypeOf<false>(result.isSuccess);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n expectTypeOf<false>(result.isIdle);\n expectTypeOf<false>(result.isPending);\n expectTypeOf<true>(result.isSuccess);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n });\n\n test(\"should handle partial ToolSignature with only input specified\", () => {\n type TestInput = { id: number };\n\n const result = useToolInfo<{\n input: TestInput;\n }>();\n\n // Input can be TestInput or undefined (when idle)\n if (result.status === \"pending\" || result.status === \"success\") {\n expectTypeOf<TestInput>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<Record<string, unknown>>(result.output);\n expectTypeOf<Record<string, unknown>>(result.responseMetadata);\n }\n });\n\n test(\"should handle ToolSignature with only output specified\", () => {\n type TestOutput = { data: string[] };\n\n const result = useToolInfo<{\n output: TestOutput;\n }>();\n\n // Input can be Record<string, unknown> or undefined (when idle)\n if (result.status === \"pending\" || result.status === \"success\") {\n expectTypeOf<Record<string, unknown>>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestOutput>(result.output);\n }\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { act, fireEvent, renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../bridges/apps-sdk/index.js";
|
|
4
|
+
import { McpAppAdaptor, McpAppBridge } from "../bridges/mcp-app/index.js";
|
|
5
|
+
import { fireToolInputNotification, fireToolResultNotification, getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
7
|
+
describe("useToolInfo", () => {
|
|
8
|
+
describe("apps-sdk host", () => {
|
|
9
|
+
let OpenaiMock;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
OpenaiMock = {
|
|
12
|
+
toolInput: { name: "pokemon", args: { name: "pikachu" } },
|
|
13
|
+
toolOutput: null,
|
|
14
|
+
toolResponseMetadata: null,
|
|
15
|
+
};
|
|
16
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
17
|
+
vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
vi.unstubAllGlobals();
|
|
21
|
+
vi.resetAllMocks();
|
|
22
|
+
});
|
|
23
|
+
it("should return toolInput on initial mount window.openai", () => {
|
|
24
|
+
const { result } = renderHook(() => useToolInfo());
|
|
25
|
+
expect(result.current).toMatchObject({
|
|
26
|
+
input: { name: "pokemon", args: { name: "pikachu" } },
|
|
27
|
+
status: "pending",
|
|
28
|
+
isIdle: false,
|
|
29
|
+
isPending: true,
|
|
30
|
+
isSuccess: false,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it("should eventually return tool output and response metadata once tool call completes", async () => {
|
|
34
|
+
const toolOutput = {
|
|
35
|
+
name: "pikachu",
|
|
36
|
+
color: "yellow",
|
|
37
|
+
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
38
|
+
};
|
|
39
|
+
const toolResponseMetadata = { id: 12 };
|
|
40
|
+
const { result } = renderHook(() => useToolInfo());
|
|
41
|
+
act(() => {
|
|
42
|
+
OpenaiMock.toolOutput = toolOutput;
|
|
43
|
+
OpenaiMock.toolResponseMetadata = toolResponseMetadata;
|
|
44
|
+
fireEvent(window, new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {
|
|
45
|
+
detail: {
|
|
46
|
+
globals: {
|
|
47
|
+
toolOutput,
|
|
48
|
+
toolResponseMetadata,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
await waitFor(() => {
|
|
54
|
+
expect(result.current).toMatchObject({
|
|
55
|
+
status: "success",
|
|
56
|
+
isIdle: false,
|
|
57
|
+
isPending: false,
|
|
58
|
+
isSuccess: true,
|
|
59
|
+
output: toolOutput,
|
|
60
|
+
responseMetadata: toolResponseMetadata,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("mcp-app host", () => {
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
|
|
68
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
69
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
70
|
+
});
|
|
71
|
+
afterEach(async () => {
|
|
72
|
+
vi.unstubAllGlobals();
|
|
73
|
+
vi.resetAllMocks();
|
|
74
|
+
McpAppBridge.resetInstance();
|
|
75
|
+
McpAppAdaptor.resetInstance();
|
|
76
|
+
});
|
|
77
|
+
it("should return idle state initially when tool input is not yet set", async () => {
|
|
78
|
+
const { result } = renderHook(() => useToolInfo());
|
|
79
|
+
await waitFor(() => {
|
|
80
|
+
expect(result.current).toMatchObject({
|
|
81
|
+
status: "idle",
|
|
82
|
+
isIdle: true,
|
|
83
|
+
isPending: false,
|
|
84
|
+
isSuccess: false,
|
|
85
|
+
input: null,
|
|
86
|
+
output: null,
|
|
87
|
+
responseMetadata: null,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
it("should return pending state with tool input from tool-input notification", async () => {
|
|
92
|
+
const { result } = renderHook(() => useToolInfo());
|
|
93
|
+
act(() => {
|
|
94
|
+
fireToolInputNotification({ name: "pokemon", query: "pikachu" });
|
|
95
|
+
});
|
|
96
|
+
await waitFor(() => {
|
|
97
|
+
expect(result.current).toMatchObject({
|
|
98
|
+
status: "pending",
|
|
99
|
+
isIdle: false,
|
|
100
|
+
isPending: true,
|
|
101
|
+
isSuccess: false,
|
|
102
|
+
input: { name: "pokemon", query: "pikachu" },
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
it("should return success state with output from tool-result notification", async () => {
|
|
107
|
+
const { result } = renderHook(() => useToolInfo());
|
|
108
|
+
act(() => {
|
|
109
|
+
fireToolInputNotification({ name: "pokemon", query: "pikachu" });
|
|
110
|
+
fireToolResultNotification({
|
|
111
|
+
content: [{ type: "text", text: "Pikachu data" }],
|
|
112
|
+
structuredContent: { name: "pikachu", color: "yellow" },
|
|
113
|
+
_meta: { requestId: "123" },
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
await waitFor(() => {
|
|
117
|
+
expect(result.current).toMatchObject({
|
|
118
|
+
status: "success",
|
|
119
|
+
isIdle: false,
|
|
120
|
+
isPending: false,
|
|
121
|
+
isSuccess: true,
|
|
122
|
+
input: { name: "pokemon", query: "pikachu" },
|
|
123
|
+
output: { name: "pikachu", color: "yellow" },
|
|
124
|
+
responseMetadata: { requestId: "123" },
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=use-tool-info.test.js.map
|