enpilink 1.0.2
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 -0
- package/README.md +289 -0
- package/bin/run.js +5 -0
- package/dist/cli/build-helpers.d.ts +8 -0
- package/dist/cli/build-helpers.js +105 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +100 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +50 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/ensure-ssh-key.d.ts +17 -0
- package/dist/cli/ensure-ssh-key.js +45 -0
- package/dist/cli/ensure-ssh-key.js.map +1 -0
- package/dist/cli/ensure-ssh-key.test.d.ts +1 -0
- package/dist/cli/ensure-ssh-key.test.js +68 -0
- package/dist/cli/ensure-ssh-key.test.js.map +1 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/telemetry.d.ts +14 -0
- package/dist/cli/telemetry.js +24 -0
- package/dist/cli/telemetry.js.map +1 -0
- package/dist/cli/tunnel-control-server.d.ts +11 -0
- package/dist/cli/tunnel-control-server.js +35 -0
- package/dist/cli/tunnel-control-server.js.map +1 -0
- package/dist/cli/tunnel-control-server.test.d.ts +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.d.ts +1 -0
- package/dist/cli/tunnel-handler.test.js +107 -0
- package/dist/cli/tunnel-handler.test.js.map +1 -0
- package/dist/cli/tunnel-providers/index.d.ts +5 -0
- package/dist/cli/tunnel-providers/index.js +5 -0
- package/dist/cli/tunnel-providers/index.js.map +1 -0
- package/dist/cli/tunnel-providers/srv-us.d.ts +18 -0
- package/dist/cli/tunnel-providers/srv-us.js +66 -0
- package/dist/cli/tunnel-providers/srv-us.js.map +1 -0
- package/dist/cli/tunnel-providers/srv-us.test.d.ts +1 -0
- package/dist/cli/tunnel-providers/srv-us.test.js +74 -0
- package/dist/cli/tunnel-providers/srv-us.test.js.map +1 -0
- package/dist/cli/tunnel-providers/types.d.ts +49 -0
- package/dist/cli/tunnel-providers/types.js +2 -0
- package/dist/cli/tunnel-providers/types.js.map +1 -0
- package/dist/cli/tunnel.d.ts +75 -0
- package/dist/cli/tunnel.js +254 -0
- package/dist/cli/tunnel.js.map +1 -0
- package/dist/cli/tunnel.test.d.ts +1 -0
- package/dist/cli/tunnel.test.js +255 -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-open-tunnel-browser.d.ts +6 -0
- package/dist/cli/use-open-tunnel-browser.js +19 -0
- package/dist/cli/use-open-tunnel-browser.js.map +1 -0
- package/dist/cli/use-tunnel.d.ts +17 -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 +8 -0
- package/dist/commands/build.js +97 -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 +13 -0
- package/dist/commands/dev.js +112 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +10 -0
- package/dist/commands/start.js +76 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +12 -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 +12 -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 +12 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/admin.d.ts +79 -0
- package/dist/server/admin.js +239 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/admin.test.d.ts +1 -0
- package/dist/server/admin.test.js +226 -0
- package/dist/server/admin.test.js.map +1 -0
- package/dist/server/analytics.d.ts +60 -0
- package/dist/server/analytics.js +168 -0
- package/dist/server/analytics.js.map +1 -0
- package/dist/server/analytics.test.d.ts +1 -0
- package/dist/server/analytics.test.js +179 -0
- package/dist/server/analytics.test.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +48 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +134 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/auth.d.ts +20 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/config/config.test.d.ts +1 -0
- package/dist/server/config/config.test.js +214 -0
- package/dist/server/config/config.test.js.map +1 -0
- package/dist/server/config/index.d.ts +3 -0
- package/dist/server/config/index.js +4 -0
- package/dist/server/config/index.js.map +1 -0
- package/dist/server/config/resolve.d.ts +73 -0
- package/dist/server/config/resolve.js +167 -0
- package/dist/server/config/resolve.js.map +1 -0
- package/dist/server/config/router.d.ts +23 -0
- package/dist/server/config/router.js +119 -0
- package/dist/server/config/router.js.map +1 -0
- package/dist/server/config/schema.d.ts +78 -0
- package/dist/server/config/schema.js +158 -0
- package/dist/server/config/schema.js.map +1 -0
- package/dist/server/content-helpers.d.ts +67 -0
- package/dist/server/content-helpers.js +79 -0
- package/dist/server/content-helpers.js.map +1 -0
- package/dist/server/content-helpers.test.d.ts +1 -0
- package/dist/server/content-helpers.test.js +70 -0
- package/dist/server/content-helpers.test.js.map +1 -0
- package/dist/server/express.d.ts +11 -0
- package/dist/server/express.js +129 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +464 -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 +17 -0
- package/dist/server/index.js +14 -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/log-sink.d.ts +16 -0
- package/dist/server/log-sink.js +66 -0
- package/dist/server/log-sink.js.map +1 -0
- package/dist/server/metric.d.ts +12 -0
- package/dist/server/metric.js +13 -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.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +493 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/mock-seed.d.ts +62 -0
- package/dist/server/mock-seed.js +251 -0
- package/dist/server/mock-seed.js.map +1 -0
- package/dist/server/mock-seed.test.d.ts +1 -0
- package/dist/server/mock-seed.test.js +122 -0
- package/dist/server/mock-seed.test.js.map +1 -0
- package/dist/server/observability.d.ts +149 -0
- package/dist/server/observability.js +340 -0
- package/dist/server/observability.js.map +1 -0
- package/dist/server/observability.test.d.ts +1 -0
- package/dist/server/observability.test.js +251 -0
- package/dist/server/observability.test.js.map +1 -0
- package/dist/server/otel.d.ts +45 -0
- package/dist/server/otel.js +117 -0
- package/dist/server/otel.js.map +1 -0
- package/dist/server/otel.test.d.ts +1 -0
- package/dist/server/otel.test.js +122 -0
- package/dist/server/otel.test.js.map +1 -0
- package/dist/server/server.d.ts +422 -0
- package/dist/server/server.js +684 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/storage/index.d.ts +23 -0
- package/dist/server/storage/index.js +46 -0
- package/dist/server/storage/index.js.map +1 -0
- package/dist/server/storage/memory.d.ts +30 -0
- package/dist/server/storage/memory.js +98 -0
- package/dist/server/storage/memory.js.map +1 -0
- package/dist/server/storage/memory.test.d.ts +1 -0
- package/dist/server/storage/memory.test.js +81 -0
- package/dist/server/storage/memory.test.js.map +1 -0
- package/dist/server/storage/postgres.d.ts +65 -0
- package/dist/server/storage/postgres.js +242 -0
- package/dist/server/storage/postgres.js.map +1 -0
- package/dist/server/storage/postgres.test.d.ts +1 -0
- package/dist/server/storage/postgres.test.js +182 -0
- package/dist/server/storage/postgres.test.js.map +1 -0
- package/dist/server/storage/sqlite.d.ts +33 -0
- package/dist/server/storage/sqlite.js +250 -0
- package/dist/server/storage/sqlite.js.map +1 -0
- package/dist/server/storage/sqlite.test.d.ts +1 -0
- package/dist/server/storage/sqlite.test.js +133 -0
- package/dist/server/storage/sqlite.test.js.map +1 -0
- package/dist/server/storage/types.d.ts +119 -0
- package/dist/server/storage/types.js +11 -0
- package/dist/server/storage/types.js.map +1 -0
- package/dist/server/templateHelper.d.ts +16 -0
- 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.d.ts +1 -0
- package/dist/server/tunnel-proxy-router.test.js +229 -0
- package/dist/server/tunnel-proxy-router.test.js.map +1 -0
- package/dist/server/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.d.ts +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 +54 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +164 -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/web/bridges/apps-sdk/bridge.js +47 -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 +147 -0
- package/dist/web/bridges/apps-sdk/types.js +10 -0
- 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 +81 -0
- package/dist/web/bridges/mcp-app/adaptor.js +346 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +28 -0
- package/dist/web/bridges/mcp-app/bridge.js +124 -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.d.ts +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/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +243 -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.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 +47 -0
- package/dist/web/data-llm.js +100 -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 +120 -0
- package/dist/web/generate-helpers.js +115 -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 +211 -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 +17 -0
- package/dist/web/hooks/index.js +18 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +20 -0
- package/dist/web/hooks/test/utils.js +75 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/web/hooks/use-call-tool.d.ts +146 -0
- package/dist/web/hooks/use-call-tool.js +96 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/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 +211 -0
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +24 -0
- package/dist/web/hooks/use-display-mode.js +29 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test.js +41 -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/web/hooks/use-intent.d.ts +30 -0
- package/dist/web/hooks/use-intent.js +34 -0
- package/dist/web/hooks/use-intent.js.map +1 -0
- package/dist/web/hooks/use-intent.test.d.ts +1 -0
- package/dist/web/hooks/use-intent.test.js +85 -0
- package/dist/web/hooks/use-intent.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +24 -0
- package/dist/web/hooks/use-layout.js +25 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/web/hooks/use-layout.test.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-notify.d.ts +29 -0
- package/dist/web/hooks/use-notify.js +33 -0
- package/dist/web/hooks/use-notify.js.map +1 -0
- package/dist/web/hooks/use-notify.test.d.ts +1 -0
- package/dist/web/hooks/use-notify.test.js +105 -0
- package/dist/web/hooks/use-notify.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +20 -0
- package/dist/web/hooks/use-open-external.js +24 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/web/hooks/use-open-external.test.js +65 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +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/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-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 +87 -0
- package/dist/web/hooks/use-tool-info.js +49 -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 +91 -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 +20 -0
- package/dist/web/hooks/use-user.js +37 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +122 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-view-state.d.ts +25 -0
- package/dist/web/hooks/use-view-state.js +32 -0
- package/dist/web/hooks/use-view-state.js.map +1 -0
- package/dist/web/hooks/use-view-state.test.d.ts +1 -0
- package/dist/web/hooks/use-view-state.test.js +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 +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 +81 -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/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 +20 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +125 -0
- package/scripts/postinstall.mjs +45 -0
- package/tsconfig.base.json +36 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useHostContext } from "../bridges/index.js";
|
|
2
|
+
function deriveStatus(output, responseMetadata) {
|
|
3
|
+
if (output === null && responseMetadata === null) {
|
|
4
|
+
return "pending";
|
|
5
|
+
}
|
|
6
|
+
return "success";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Access the tool invocation that produced the current view: its `input`,
|
|
10
|
+
* resulting `output`, and `responseMetadata`. The shape evolves as the tool
|
|
11
|
+
* runs (pending → success), exposed through {@link ToolState}.
|
|
12
|
+
*
|
|
13
|
+
* For full input/output typing per tool name, prefer the typed `useToolInfo`
|
|
14
|
+
* returned by {@link generateHelpers} over the generic form.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`
|
|
17
|
+
* to refine each field's type. When omitted, each typed field resolves to
|
|
18
|
+
* `never` — pass an explicit shape or use the typed helper from
|
|
19
|
+
* {@link generateHelpers} to get usable types.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { isSuccess, input, output } = useToolInfo<{
|
|
24
|
+
* input: { query: string };
|
|
25
|
+
* output: { results: Result[] };
|
|
26
|
+
* }>();
|
|
27
|
+
*
|
|
28
|
+
* if (!isSuccess || !output) return <Skeleton />;
|
|
29
|
+
* return <Results items={output.results} />;
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see https://docs.enpitech.dev/api-reference/use-tool-info
|
|
33
|
+
*/
|
|
34
|
+
export function useToolInfo() {
|
|
35
|
+
const input = useHostContext("toolInput");
|
|
36
|
+
const output = useHostContext("toolOutput");
|
|
37
|
+
const responseMetadata = useHostContext("toolResponseMetadata");
|
|
38
|
+
const status = deriveStatus(output, responseMetadata);
|
|
39
|
+
return {
|
|
40
|
+
input: input ?? undefined,
|
|
41
|
+
status,
|
|
42
|
+
isIdle: false,
|
|
43
|
+
isPending: status === "pending",
|
|
44
|
+
isSuccess: status === "success",
|
|
45
|
+
output,
|
|
46
|
+
responseMetadata,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# 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;AA6ErD,SAAS,YAAY,CACnB,MAAsC,EACtC,gBAAgD;IAEhD,IAAI,MAAM,KAAK,IAAI,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,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,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAMtD,OAAO;QACL,KAAK,EAAE,KAAK,IAAI,SAAS;QACzB,MAAM;QACN,MAAM,EAAE,KAAK;QACb,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\n/**\n * {@link useToolInfo} state before the tool has been invoked.\n *\n * @deprecated `useToolInfo` no longer returns the idle state — it starts in\n * `\"pending\"` and transitions to `\"success\"`, so `isIdle` is always `false` at\n * runtime. This type is retained in {@link ToolState} for backwards\n * compatibility and will be removed in the next major.\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\n/**\n * {@link useToolInfo} state while the tool is executing — `output` is not yet\n * available.\n *\n * `input` is optional: the host may render the view before delivering the\n * tool arguments.\n */\nexport type ToolPendingState<ToolInput extends UnknownObject> = {\n status: \"pending\";\n isIdle: false;\n isPending: true;\n isSuccess: false;\n input: ToolInput | undefined;\n output: undefined;\n responseMetadata: undefined;\n};\n\n/**\n * {@link useToolInfo} state once the tool returned — `output` is available.\n *\n * `input` is optional: the host may not have surfaced the tool arguments by\n * the time `output` arrives.\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 | undefined;\n output: ToolOutput;\n responseMetadata: ToolResponseMetadata;\n};\n\n/**\n * Discriminated union describing the tool invocation that triggered the\n * current view render. Use `isPending` / `isSuccess` to narrow.\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 output: Record<string, unknown> | null,\n responseMetadata: Record<string, unknown> | null,\n): \"pending\" | \"success\" {\n if (output === null && responseMetadata === null) {\n return \"pending\";\n }\n return \"success\";\n}\n\n/**\n * Access the tool invocation that produced the current view: its `input`,\n * resulting `output`, and `responseMetadata`. The shape evolves as the tool\n * runs (pending → success), exposed through {@link ToolState}.\n *\n * For full input/output typing per tool name, prefer the typed `useToolInfo`\n * returned by {@link generateHelpers} over the generic form.\n *\n * @typeParam TS - Optional partial shape `{ input, output, responseMetadata }`\n * to refine each field's type. When omitted, each typed field resolves to\n * `never` — pass an explicit shape or use the typed helper from\n * {@link generateHelpers} to get usable types.\n *\n * @example\n * ```tsx\n * const { isSuccess, input, output } = useToolInfo<{\n * input: { query: string };\n * output: { results: Result[] };\n * }>();\n *\n * if (!isSuccess || !output) return <Skeleton />;\n * return <Results items={output.results} />;\n * ```\n *\n * @see https://docs.enpitech.dev/api-reference/use-tool-info\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(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: input ?? undefined,\n status,\n isIdle: false,\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,91 @@
|
|
|
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 pending, input may be undefined (host hasn't delivered args yet,
|
|
15
|
+
// or the tool has no input schema)
|
|
16
|
+
if (result.status === "pending") {
|
|
17
|
+
expectTypeOf(result.input);
|
|
18
|
+
expectTypeOf(result.output);
|
|
19
|
+
expectTypeOf(result.responseMetadata);
|
|
20
|
+
}
|
|
21
|
+
// When success, output and responseMetadata are defined; input may still
|
|
22
|
+
// be undefined if the host hasn't surfaced the tool arguments
|
|
23
|
+
if (result.status === "success") {
|
|
24
|
+
expectTypeOf(result.input);
|
|
25
|
+
expectTypeOf(result.output);
|
|
26
|
+
expectTypeOf(result.responseMetadata);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
test("should correctly narrow types based on status discriminated union", () => {
|
|
30
|
+
const result = useToolInfo();
|
|
31
|
+
// Test type narrowing for pending
|
|
32
|
+
if (result.isPending) {
|
|
33
|
+
expectTypeOf(result.status);
|
|
34
|
+
expectTypeOf(result.isIdle);
|
|
35
|
+
expectTypeOf(result.isPending);
|
|
36
|
+
expectTypeOf(result.isSuccess);
|
|
37
|
+
expectTypeOf(result.input);
|
|
38
|
+
expectTypeOf(result.output);
|
|
39
|
+
expectTypeOf(result.responseMetadata);
|
|
40
|
+
}
|
|
41
|
+
if (result.isSuccess) {
|
|
42
|
+
expectTypeOf(result.status);
|
|
43
|
+
expectTypeOf(result.isIdle);
|
|
44
|
+
expectTypeOf(result.isPending);
|
|
45
|
+
expectTypeOf(result.isSuccess);
|
|
46
|
+
expectTypeOf(result.input);
|
|
47
|
+
expectTypeOf(result.output);
|
|
48
|
+
expectTypeOf(result.responseMetadata);
|
|
49
|
+
}
|
|
50
|
+
if (result.status === "pending") {
|
|
51
|
+
expectTypeOf(result.input);
|
|
52
|
+
expectTypeOf(result.isIdle);
|
|
53
|
+
expectTypeOf(result.isPending);
|
|
54
|
+
expectTypeOf(result.isSuccess);
|
|
55
|
+
expectTypeOf(result.output);
|
|
56
|
+
expectTypeOf(result.responseMetadata);
|
|
57
|
+
}
|
|
58
|
+
if (result.status === "success") {
|
|
59
|
+
expectTypeOf(result.input);
|
|
60
|
+
expectTypeOf(result.isIdle);
|
|
61
|
+
expectTypeOf(result.isPending);
|
|
62
|
+
expectTypeOf(result.isSuccess);
|
|
63
|
+
expectTypeOf(result.output);
|
|
64
|
+
expectTypeOf(result.responseMetadata);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
test("should handle partial ToolSignature with only input specified", () => {
|
|
68
|
+
const result = useToolInfo();
|
|
69
|
+
// Input is optional in both states — undefined while args haven't arrived
|
|
70
|
+
// (pending) and for no-input tools (success).
|
|
71
|
+
if (result.status === "pending") {
|
|
72
|
+
expectTypeOf(result.input);
|
|
73
|
+
}
|
|
74
|
+
if (result.status === "success") {
|
|
75
|
+
expectTypeOf(result.input);
|
|
76
|
+
expectTypeOf(result.output);
|
|
77
|
+
expectTypeOf(result.responseMetadata);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
test("should handle ToolSignature with only output specified", () => {
|
|
81
|
+
const result = useToolInfo();
|
|
82
|
+
if (result.status === "pending") {
|
|
83
|
+
expectTypeOf(result.input);
|
|
84
|
+
}
|
|
85
|
+
if (result.status === "success") {
|
|
86
|
+
expectTypeOf(result.input);
|
|
87
|
+
expectTypeOf(result.output);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
//# 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,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,IAAI,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,iEAAiE,EAAE,GAAG,EAAE;QAC3E,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;QAE7B,YAAY,CAAiC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5D,YAAY,CAAU,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,YAAY,CAAU,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,YAAY,CAAU,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,YAAY,CAAsC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClE,CAAC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,CAAC;QACpD,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAwB,MAAM,CAAC,KAAK,CAAC,CAAC;YAClD,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,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAsC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAsC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,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 pending, input may be undefined (host hasn't delivered args yet,\n // or the tool has no input schema)\n if (result.status === \"pending\") {\n expectTypeOf<TestInput | undefined>(result.input);\n expectTypeOf<undefined>(result.output);\n expectTypeOf<undefined>(result.responseMetadata);\n }\n\n // When success, output and responseMetadata are defined; input may still\n // be undefined if the host hasn't surfaced the tool arguments\n if (result.status === \"success\") {\n expectTypeOf<TestInput | undefined>(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 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<TestInput | undefined>(result.input);\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<TestInput | undefined>(result.input);\n expectTypeOf<TestOutput>(result.output);\n expectTypeOf<TestMetadata>(result.responseMetadata);\n }\n\n if (result.status === \"pending\") {\n expectTypeOf<TestInput | undefined>(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 | undefined>(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 is optional in both states — undefined while args haven't arrived\n // (pending) and for no-input tools (success).\n if (result.status === \"pending\") {\n expectTypeOf<TestInput | undefined>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<TestInput | undefined>(result.input);\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 if (result.status === \"pending\") {\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\n }\n\n if (result.status === \"success\") {\n expectTypeOf<Record<string, unknown> | undefined>(result.input);\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("enpilink", { 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("enpilink", { 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 pending state with undefined input before tool-input notification arrives", async () => {
|
|
78
|
+
const { result } = renderHook(() => useToolInfo());
|
|
79
|
+
await waitFor(() => {
|
|
80
|
+
expect(result.current).toMatchObject({
|
|
81
|
+
status: "pending",
|
|
82
|
+
isIdle: false,
|
|
83
|
+
isPending: true,
|
|
84
|
+
isSuccess: false,
|
|
85
|
+
input: undefined,
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAEL,sBAAsB,EACtB,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAI,UAGH,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG;gBACX,SAA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I,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;gBACjE,0BAA0B,CAAC;oBACzB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;oBACjD,iBAAiB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBACvD,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBAC5B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;oBACnC,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,KAAK;oBACb,SAAS,EAAE,KAAK;oBAChB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;oBAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBAC5C,gBAAgB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, fireEvent, renderHook, waitFor } from \"@testing-library/react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n type AppsSdkContext,\n SET_GLOBALS_EVENT_TYPE,\n SetGlobalsEvent,\n} from \"../bridges/apps-sdk/index.js\";\nimport { McpAppAdaptor, McpAppBridge } from \"../bridges/mcp-app/index.js\";\nimport {\n fireToolInputNotification,\n fireToolResultNotification,\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useToolInfo } from \"./use-tool-info.js\";\n\ndescribe(\"useToolInfo\", () => {\n describe(\"apps-sdk host\", () => {\n let OpenaiMock: Pick<\n AppsSdkContext,\n \"toolInput\" | \"toolOutput\" | \"toolResponseMetadata\"\n >;\n\n beforeEach(() => {\n OpenaiMock = {\n toolInput: { name: \"pokemon\", args: { name: \"pikachu\" } },\n toolOutput: null,\n toolResponseMetadata: null,\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"enpilink\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return toolInput on initial mount window.openai\", () => {\n const { result } = renderHook(() => useToolInfo());\n\n expect(result.current).toMatchObject({\n input: { name: \"pokemon\", args: { name: \"pikachu\" } },\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n });\n });\n\n it(\"should eventually return tool output and response metadata once tool call completes\", async () => {\n const toolOutput = {\n name: \"pikachu\",\n color: \"yellow\",\n description:\n \"When several of these POKéMON gather, their\\felectricity could build and cause lightning storms.\",\n };\n const toolResponseMetadata = { id: 12 };\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n OpenaiMock.toolOutput = toolOutput;\n OpenaiMock.toolResponseMetadata = toolResponseMetadata;\n fireEvent(\n window,\n new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {\n detail: {\n globals: {\n toolOutput,\n toolResponseMetadata,\n },\n },\n }),\n );\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n output: toolOutput,\n responseMetadata: toolResponseMetadata,\n });\n });\n });\n });\n\n describe(\"mcp-app host\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"parent\", { postMessage: getMcpAppHostPostMessageMock() });\n vi.stubGlobal(\"enpilink\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n });\n\n it(\"should return pending state with undefined input before tool-input notification arrives\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: undefined,\n output: null,\n responseMetadata: null,\n });\n });\n });\n\n it(\"should return pending state with tool input from tool-input notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"pending\",\n isIdle: false,\n isPending: true,\n isSuccess: false,\n input: { name: \"pokemon\", query: \"pikachu\" },\n });\n });\n });\n\n it(\"should return success state with output from tool-result notification\", async () => {\n const { result } = renderHook(() => useToolInfo());\n\n act(() => {\n fireToolInputNotification({ name: \"pokemon\", query: \"pikachu\" });\n fireToolResultNotification({\n content: [{ type: \"text\", text: \"Pikachu data\" }],\n structuredContent: { name: \"pikachu\", color: \"yellow\" },\n _meta: { requestId: \"123\" },\n });\n });\n\n await waitFor(() => {\n expect(result.current).toMatchObject({\n status: \"success\",\n isIdle: false,\n isPending: false,\n isSuccess: true,\n input: { name: \"pokemon\", query: \"pikachu\" },\n output: { name: \"pikachu\", color: \"yellow\" },\n responseMetadata: { requestId: \"123\" },\n });\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type UserAgent } from "../bridges/index.js";
|
|
2
|
+
export type UserState = {
|
|
3
|
+
locale: string;
|
|
4
|
+
userAgent: UserAgent;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hook for accessing session-stable user information.
|
|
8
|
+
* These values are set once at initialization and do not change during the session.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { locale, userAgent } = useUser();
|
|
13
|
+
*
|
|
14
|
+
* // Access device type
|
|
15
|
+
* const isMobile = userAgent.device.type === "mobile";
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://docs.enpitech.dev/api-reference/use-user
|
|
19
|
+
*/
|
|
20
|
+
export declare function useUser(): UserState;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useHostContext } from "../bridges/index.js";
|
|
2
|
+
const DEFAULT_LOCALE = "en-US";
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.
|
|
5
|
+
*
|
|
6
|
+
* Handles underscored identifiers returned by the ChatGPT mobile app (e.g. "fr_FR" → "fr-FR"),
|
|
7
|
+
* incorrect casing (e.g. "en-us" → "en-US"), and complex subtags (e.g. "zh_Hans_CN" → "zh-Hans-CN").
|
|
8
|
+
* Falls back to "en-US" if the locale is invalid.
|
|
9
|
+
*/
|
|
10
|
+
function normalizeLocale(locale) {
|
|
11
|
+
try {
|
|
12
|
+
return new Intl.Locale(locale.replace(/_/g, "-")).toString();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return DEFAULT_LOCALE;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hook for accessing session-stable user information.
|
|
20
|
+
* These values are set once at initialization and do not change during the session.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const { locale, userAgent } = useUser();
|
|
25
|
+
*
|
|
26
|
+
* // Access device type
|
|
27
|
+
* const isMobile = userAgent.device.type === "mobile";
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see https://docs.enpitech.dev/api-reference/use-user
|
|
31
|
+
*/
|
|
32
|
+
export function useUser() {
|
|
33
|
+
const rawLocale = useHostContext("locale");
|
|
34
|
+
const userAgent = useHostContext("userAgent");
|
|
35
|
+
return { locale: normalizeLocale(rawLocale), userAgent };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=use-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-user.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrE,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAE9C,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["import { type UserAgent, useHostContext } from \"../bridges/index.js\";\n\nexport type UserState = {\n locale: string;\n userAgent: UserAgent;\n};\n\nconst DEFAULT_LOCALE = \"en-US\";\n\n/**\n * Normalizes a locale string to canonical BCP 47 format using {@link Intl.Locale}.\n *\n * Handles underscored identifiers returned by the ChatGPT mobile app (e.g. \"fr_FR\" → \"fr-FR\"),\n * incorrect casing (e.g. \"en-us\" → \"en-US\"), and complex subtags (e.g. \"zh_Hans_CN\" → \"zh-Hans-CN\").\n * Falls back to \"en-US\" if the locale is invalid.\n */\nfunction normalizeLocale(locale: string): string {\n try {\n return new Intl.Locale(locale.replace(/_/g, \"-\")).toString();\n } catch {\n return DEFAULT_LOCALE;\n }\n}\n\n/**\n * Hook for accessing session-stable user information.\n * These values are set once at initialization and do not change during the session.\n *\n * @example\n * ```tsx\n * const { locale, userAgent } = useUser();\n *\n * // Access device type\n * const isMobile = userAgent.device.type === \"mobile\";\n * ```\n *\n * @see https://docs.enpitech.dev/api-reference/use-user\n */\nexport function useUser(): UserState {\n const rawLocale = useHostContext(\"locale\");\n const userAgent = useHostContext(\"userAgent\");\n\n return { locale: normalizeLocale(rawLocale), userAgent };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { renderHook, waitFor } 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 { getMcpAppHostPostMessageMock, MockResizeObserver, } from "./test/utils.js";
|
|
6
|
+
import { useUser } from "./use-user.js";
|
|
7
|
+
describe("useUser", () => {
|
|
8
|
+
describe("apps-sdk host type", () => {
|
|
9
|
+
let OpenaiMock;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
OpenaiMock = {
|
|
12
|
+
locale: "en-US",
|
|
13
|
+
userAgent: {
|
|
14
|
+
device: { type: "desktop" },
|
|
15
|
+
capabilities: { hover: true, touch: false },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
19
|
+
vi.stubGlobal("enpilink", { hostType: "apps-sdk" });
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.unstubAllGlobals();
|
|
23
|
+
vi.resetAllMocks();
|
|
24
|
+
});
|
|
25
|
+
it("should return locale and userAgent from window.openai", () => {
|
|
26
|
+
const { result } = renderHook(() => useUser());
|
|
27
|
+
expect(result.current.locale).toBe("en-US");
|
|
28
|
+
expect(result.current.userAgent).toEqual({
|
|
29
|
+
device: { type: "desktop" },
|
|
30
|
+
capabilities: { hover: true, touch: false },
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it("should return mobile userAgent when set to mobile", () => {
|
|
34
|
+
OpenaiMock.userAgent = {
|
|
35
|
+
device: { type: "mobile" },
|
|
36
|
+
capabilities: { hover: false, touch: true },
|
|
37
|
+
};
|
|
38
|
+
const { result } = renderHook(() => useUser());
|
|
39
|
+
expect(result.current.userAgent.device.type).toBe("mobile");
|
|
40
|
+
expect(result.current.userAgent.capabilities.touch).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
it("should return different locale when set", () => {
|
|
43
|
+
OpenaiMock.locale = "es-ES";
|
|
44
|
+
const { result } = renderHook(() => useUser());
|
|
45
|
+
expect(result.current.locale).toBe("es-ES");
|
|
46
|
+
});
|
|
47
|
+
it("should normalize underscore locale to BCP 47 hyphen format", () => {
|
|
48
|
+
OpenaiMock.locale = "fr_FR";
|
|
49
|
+
const { result } = renderHook(() => useUser());
|
|
50
|
+
expect(result.current.locale).toBe("fr-FR");
|
|
51
|
+
});
|
|
52
|
+
it("should canonicalize locale casing", () => {
|
|
53
|
+
OpenaiMock.locale = "en-us";
|
|
54
|
+
const { result } = renderHook(() => useUser());
|
|
55
|
+
expect(result.current.locale).toBe("en-US");
|
|
56
|
+
});
|
|
57
|
+
it("should fall back to en-US for invalid locale", () => {
|
|
58
|
+
OpenaiMock.locale = "not-a-locale-!!";
|
|
59
|
+
const { result } = renderHook(() => useUser());
|
|
60
|
+
expect(result.current.locale).toBe("en-US");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("mcp-app host type", () => {
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
vi.stubGlobal("enpilink", { hostType: "mcp-app" });
|
|
66
|
+
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
67
|
+
});
|
|
68
|
+
afterEach(async () => {
|
|
69
|
+
vi.unstubAllGlobals();
|
|
70
|
+
vi.resetAllMocks();
|
|
71
|
+
McpAppBridge.resetInstance();
|
|
72
|
+
McpAppAdaptor.resetInstance();
|
|
73
|
+
});
|
|
74
|
+
it("should return locale and userAgent from mcp host context", async () => {
|
|
75
|
+
vi.stubGlobal("parent", {
|
|
76
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
77
|
+
locale: "fr-FR",
|
|
78
|
+
platform: "web",
|
|
79
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
const { result } = renderHook(() => useUser());
|
|
83
|
+
await waitFor(() => {
|
|
84
|
+
expect(result.current.locale).toBe("fr-FR");
|
|
85
|
+
expect(result.current.userAgent).toEqual({
|
|
86
|
+
device: { type: "desktop" },
|
|
87
|
+
capabilities: { hover: true, touch: false },
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
it("should normalize underscore locale to BCP 47 hyphen format", async () => {
|
|
92
|
+
vi.stubGlobal("parent", {
|
|
93
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
94
|
+
locale: "fr_FR",
|
|
95
|
+
platform: "web",
|
|
96
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
const { result } = renderHook(() => useUser());
|
|
100
|
+
await waitFor(() => {
|
|
101
|
+
expect(result.current.locale).toBe("fr-FR");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it("should maintain userAgent referential stability when data has not changed", async () => {
|
|
105
|
+
vi.stubGlobal("parent", {
|
|
106
|
+
postMessage: getMcpAppHostPostMessageMock({
|
|
107
|
+
locale: "en-US",
|
|
108
|
+
platform: "web",
|
|
109
|
+
deviceCapabilities: { hover: true, touch: false },
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
const { result, rerender } = renderHook(() => useUser());
|
|
113
|
+
await waitFor(() => {
|
|
114
|
+
expect(result.current.userAgent).toBeDefined();
|
|
115
|
+
});
|
|
116
|
+
const initialUserAgent = result.current.userAgent;
|
|
117
|
+
rerender();
|
|
118
|
+
expect(result.current.userAgent).toBe(initialUserAgent);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
//# sourceMappingURL=use-user.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../src/web/hooks/use-user.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,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,IAAI,UAGH,CAAC;QAEF,UAAU,CAAC,GAAG,EAAE;YACd,UAAU,GAAG;gBACX,MAAM,EAAE,OAAO;gBACf,SAAS,EAAE;oBACT,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC3B,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;iBAC5C;aACF,CAAC;YACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACpC,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,EAAE;YACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;YACtB,EAAE,CAAC,aAAa,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uDAAuD,EAAE,G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,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAE/C,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2EAA2E,EAAE,KAAK,IAAI,EAAE;YACzF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;gBACtB,WAAW,EAAE,4BAA4B,CAAC;oBACxC,MAAM,EAAE,OAAO;oBACf,QAAQ,EAAE,KAAK;oBACf,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;iBAClD,CAAC;aACH,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAEzD,MAAM,OAAO,CAAC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;YAElD,QAAQ,EAAE,CAAC;YAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC1D,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 { McpAppAdaptor } from \"../bridges/mcp-app/adaptor.js\";\nimport { McpAppBridge } from \"../bridges/mcp-app/bridge.js\";\nimport type { UserAgent } from \"../bridges/types.js\";\nimport {\n getMcpAppHostPostMessageMock,\n MockResizeObserver,\n} from \"./test/utils.js\";\nimport { useUser } from \"./use-user.js\";\n\ndescribe(\"useUser\", () => {\n describe(\"apps-sdk host type\", () => {\n let OpenaiMock: {\n locale: string;\n userAgent: UserAgent;\n };\n\n beforeEach(() => {\n OpenaiMock = {\n locale: \"en-US\",\n userAgent: {\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n },\n };\n vi.stubGlobal(\"openai\", OpenaiMock);\n vi.stubGlobal(\"enpilink\", { hostType: \"apps-sdk\" });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n });\n\n it(\"should return locale and userAgent from window.openai\", () => {\n const { result } = renderHook(() => useUser());\n\n expect(result.current.locale).toBe(\"en-US\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n\n it(\"should return mobile userAgent when set to mobile\", () => {\n OpenaiMock.userAgent = {\n device: { type: \"mobile\" },\n capabilities: { hover: false, touch: true },\n };\n const { result } = renderHook(() => useUser());\n\n expect(result.current.userAgent.device.type).toBe(\"mobile\");\n expect(result.current.userAgent.capabilities.touch).toBe(true);\n });\n\n it(\"should return different locale when set\", () => {\n OpenaiMock.locale = \"es-ES\";\n const { result } = renderHook(() => useUser());\n\n expect(result.current.locale).toBe(\"es-ES\");\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", () => {\n OpenaiMock.locale = \"fr_FR\";\n const { result } = renderHook(() => useUser());\n\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n\n it(\"should canonicalize locale casing\", () => {\n OpenaiMock.locale = \"en-us\";\n const { result } = renderHook(() => useUser());\n\n expect(result.current.locale).toBe(\"en-US\");\n });\n\n it(\"should fall back to en-US for invalid locale\", () => {\n OpenaiMock.locale = \"not-a-locale-!!\";\n const { result } = renderHook(() => useUser());\n\n expect(result.current.locale).toBe(\"en-US\");\n });\n });\n\n describe(\"mcp-app host type\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"enpilink\", { hostType: \"mcp-app\" });\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n });\n\n afterEach(async () => {\n vi.unstubAllGlobals();\n vi.resetAllMocks();\n McpAppBridge.resetInstance();\n McpAppAdaptor.resetInstance();\n });\n\n it(\"should return locale and userAgent from mcp host context\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr-FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n expect(result.current.userAgent).toEqual({\n device: { type: \"desktop\" },\n capabilities: { hover: true, touch: false },\n });\n });\n });\n\n it(\"should normalize underscore locale to BCP 47 hyphen format\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"fr_FR\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.locale).toBe(\"fr-FR\");\n });\n });\n\n it(\"should maintain userAgent referential stability when data has not changed\", async () => {\n vi.stubGlobal(\"parent\", {\n postMessage: getMcpAppHostPostMessageMock({\n locale: \"en-US\",\n platform: \"web\",\n deviceCapabilities: { hover: true, touch: false },\n }),\n });\n const { result, rerender } = renderHook(() => useUser());\n\n await waitFor(() => {\n expect(result.current.userAgent).toBeDefined();\n });\n\n const initialUserAgent = result.current.userAgent;\n\n rerender();\n\n expect(result.current.userAgent).toBe(initialUserAgent);\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type SetStateAction } from "react";
|
|
2
|
+
import type { UnknownObject } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Persist a piece of UI state on the host, so it survives view remounts and
|
|
5
|
+
* is restored on subsequent renders of the same tool invocation.
|
|
6
|
+
*
|
|
7
|
+
* Returns a `[state, setState]` pair with the same ergonomics as
|
|
8
|
+
* `useState`. State is filtered to strip enpilink-internal context fields
|
|
9
|
+
* (see {@link DataLLM}) before being returned to your component.
|
|
10
|
+
*
|
|
11
|
+
* Provide a `defaultState` (value or lazy initializer) to get a non-nullable
|
|
12
|
+
* tuple; omit it for `T | null`.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam T - Shape of the persisted state. Must be a plain object.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const [filters, setFilters] = useViewState({ sort: "newest", page: 1 });
|
|
19
|
+
* setFilters((f) => ({ ...f, page: f.page + 1 }));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @see https://docs.enpitech.dev/api-reference/use-view-state
|
|
23
|
+
*/
|
|
24
|
+
export declare function useViewState<T extends UnknownObject>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
|
|
25
|
+
export declare function useViewState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { getAdaptor, useHostContext } from "../bridges/index.js";
|
|
3
|
+
import { filterViewContext, injectViewContext } from "../helpers/state.js";
|
|
4
|
+
export function useViewState(defaultState) {
|
|
5
|
+
const adaptor = getAdaptor();
|
|
6
|
+
const viewStateFromBridge = useHostContext("viewState");
|
|
7
|
+
const [viewState, _setViewState] = useState(() => {
|
|
8
|
+
if (viewStateFromBridge !== null) {
|
|
9
|
+
return filterViewContext(viewStateFromBridge);
|
|
10
|
+
}
|
|
11
|
+
return typeof defaultState === "function"
|
|
12
|
+
? defaultState()
|
|
13
|
+
: (defaultState ?? null);
|
|
14
|
+
});
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (viewStateFromBridge !== null) {
|
|
17
|
+
_setViewState(filterViewContext(viewStateFromBridge));
|
|
18
|
+
}
|
|
19
|
+
}, [viewStateFromBridge]);
|
|
20
|
+
const setViewState = useCallback((state) => {
|
|
21
|
+
_setViewState((prevState) => {
|
|
22
|
+
const newState = typeof state === "function" ? state(prevState) : state;
|
|
23
|
+
const stateToSet = injectViewContext(newState);
|
|
24
|
+
if (stateToSet !== null) {
|
|
25
|
+
adaptor.setViewState(stateToSet);
|
|
26
|
+
}
|
|
27
|
+
return filterViewContext(stateToSet);
|
|
28
|
+
});
|
|
29
|
+
}, [adaptor]);
|
|
30
|
+
return [viewState, setViewState];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=use-view-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-view-state.js","sourceRoot":"","sources":["../../../src/web/hooks/use-view-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA8B3E,MAAM,UAAU,YAAY,CAC1B,YAA0C;IAE1C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,cAAc,CAAC,WAAW,CAAa,CAAC;IAEpE,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAW,GAAG,EAAE;QACzD,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC;YACjC,OAAO,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,OAAO,YAAY,KAAK,UAAU;YACvC,CAAC,CAAC,YAAY,EAAE;YAChB,CAAC,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC;YACjC,aAAa,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACxD,CAAC;IACH,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE1B,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,KAA+B,EAAE,EAAE;QAClC,aAAa,CAAC,CAAC,SAAS,EAAE,EAAE;YAC1B,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACxE,MAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YAE/C,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBACxB,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;YAED,OAAO,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,SAAS,EAAE,YAAY,CAAU,CAAC;AAC5C,CAAC","sourcesContent":["import { type SetStateAction, useCallback, useEffect, useState } from \"react\";\nimport { getAdaptor, useHostContext } from \"../bridges/index.js\";\nimport { filterViewContext, injectViewContext } from \"../helpers/state.js\";\nimport type { UnknownObject } from \"../types.js\";\n\n/**\n * Persist a piece of UI state on the host, so it survives view remounts and\n * is restored on subsequent renders of the same tool invocation.\n *\n * Returns a `[state, setState]` pair with the same ergonomics as\n * `useState`. State is filtered to strip enpilink-internal context fields\n * (see {@link DataLLM}) before being returned to your component.\n *\n * Provide a `defaultState` (value or lazy initializer) to get a non-nullable\n * tuple; omit it for `T | null`.\n *\n * @typeParam T - Shape of the persisted state. Must be a plain object.\n *\n * @example\n * ```tsx\n * const [filters, setFilters] = useViewState({ sort: \"newest\", page: 1 });\n * setFilters((f) => ({ ...f, page: f.page + 1 }));\n * ```\n *\n * @see https://docs.enpitech.dev/api-reference/use-view-state\n */\nexport function useViewState<T extends UnknownObject>(\n defaultState: T | (() => T),\n): readonly [T, (state: SetStateAction<T>) => void];\nexport function useViewState<T extends UnknownObject>(\n defaultState?: T | (() => T | null) | null,\n): readonly [T | null, (state: SetStateAction<T | null>) => void];\nexport function useViewState<T extends UnknownObject>(\n defaultState?: T | (() => T | null) | null,\n): readonly [T | null, (state: SetStateAction<T | null>) => void] {\n const adaptor = getAdaptor();\n const viewStateFromBridge = useHostContext(\"viewState\") as T | null;\n\n const [viewState, _setViewState] = useState<T | null>(() => {\n if (viewStateFromBridge !== null) {\n return filterViewContext(viewStateFromBridge);\n }\n\n return typeof defaultState === \"function\"\n ? defaultState()\n : (defaultState ?? null);\n });\n\n useEffect(() => {\n if (viewStateFromBridge !== null) {\n _setViewState(filterViewContext(viewStateFromBridge));\n }\n }, [viewStateFromBridge]);\n\n const setViewState = useCallback(\n (state: SetStateAction<T | null>) => {\n _setViewState((prevState) => {\n const newState = typeof state === \"function\" ? state(prevState) : state;\n const stateToSet = injectViewContext(newState);\n\n if (stateToSet !== null) {\n adaptor.setViewState(stateToSet);\n }\n\n return filterViewContext(stateToSet);\n });\n },\n [adaptor],\n );\n\n return [viewState, setViewState] as const;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|