@amplitude/wizard 1.0.0-beta.0
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 +47 -0
- package/README.md +119 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +763 -0
- package/dist/package.json +144 -0
- package/dist/src/frameworks/android/android-wizard-agent.d.ts +6 -0
- package/dist/src/frameworks/android/android-wizard-agent.js +72 -0
- package/dist/src/frameworks/android/utils.d.ts +11 -0
- package/dist/src/frameworks/android/utils.js +32 -0
- package/dist/src/frameworks/django/django-wizard-agent.d.ts +8 -0
- package/dist/src/frameworks/django/django-wizard-agent.js +171 -0
- package/dist/src/frameworks/django/utils.d.ts +31 -0
- package/dist/src/frameworks/django/utils.js +305 -0
- package/dist/src/frameworks/fastapi/fastapi-wizard-agent.d.ts +11 -0
- package/dist/src/frameworks/fastapi/fastapi-wizard-agent.js +189 -0
- package/dist/src/frameworks/fastapi/utils.d.ts +26 -0
- package/dist/src/frameworks/fastapi/utils.js +257 -0
- package/dist/src/frameworks/flask/flask-wizard-agent.d.ts +8 -0
- package/dist/src/frameworks/flask/flask-wizard-agent.js +177 -0
- package/dist/src/frameworks/flask/utils.d.ts +28 -0
- package/dist/src/frameworks/flask/utils.js +343 -0
- package/dist/src/frameworks/flutter/flutter-wizard-agent.d.ts +4 -0
- package/dist/src/frameworks/flutter/flutter-wizard-agent.js +57 -0
- package/dist/src/frameworks/flutter/utils.d.ts +7 -0
- package/dist/src/frameworks/flutter/utils.js +64 -0
- package/dist/src/frameworks/generic/generic-wizard-agent.d.ts +2 -0
- package/dist/src/frameworks/generic/generic-wizard-agent.js +176 -0
- package/dist/src/frameworks/go/go-wizard-agent.d.ts +4 -0
- package/dist/src/frameworks/go/go-wizard-agent.js +57 -0
- package/dist/src/frameworks/go/utils.d.ts +5 -0
- package/dist/src/frameworks/go/utils.js +44 -0
- package/dist/src/frameworks/java/java-wizard-agent.d.ts +7 -0
- package/dist/src/frameworks/java/java-wizard-agent.js +73 -0
- package/dist/src/frameworks/java/utils.d.ts +15 -0
- package/dist/src/frameworks/java/utils.js +64 -0
- package/dist/src/frameworks/javascript-node/javascript-node-wizard-agent.d.ts +4 -0
- package/dist/src/frameworks/javascript-node/javascript-node-wizard-agent.js +57 -0
- package/dist/src/frameworks/javascript-web/javascript-web-wizard-agent.d.ts +3 -0
- package/dist/src/frameworks/javascript-web/javascript-web-wizard-agent.js +151 -0
- package/dist/src/frameworks/javascript-web/utils.d.ts +28 -0
- package/dist/src/frameworks/javascript-web/utils.js +153 -0
- package/dist/src/frameworks/nextjs/nextjs-wizard-agent.d.ts +7 -0
- package/dist/src/frameworks/nextjs/nextjs-wizard-agent.js +98 -0
- package/dist/src/frameworks/nextjs/utils.d.ts +12 -0
- package/dist/src/frameworks/nextjs/utils.js +51 -0
- package/dist/src/frameworks/python/python-wizard-agent.d.ts +7 -0
- package/dist/src/frameworks/python/python-wizard-agent.js +193 -0
- package/dist/src/frameworks/python/utils.d.ts +28 -0
- package/dist/src/frameworks/python/utils.js +146 -0
- package/dist/src/frameworks/react-native/react-native-wizard-agent.d.ts +6 -0
- package/dist/src/frameworks/react-native/react-native-wizard-agent.js +84 -0
- package/dist/src/frameworks/react-native/utils.d.ts +21 -0
- package/dist/src/frameworks/react-native/utils.js +82 -0
- package/dist/src/frameworks/react-router/react-router-wizard-agent.d.ts +7 -0
- package/dist/src/frameworks/react-router/react-router-wizard-agent.js +98 -0
- package/dist/src/frameworks/react-router/utils.d.ts +13 -0
- package/dist/src/frameworks/react-router/utils.js +160 -0
- package/dist/src/frameworks/swift/swift-wizard-agent.d.ts +7 -0
- package/dist/src/frameworks/swift/swift-wizard-agent.js +72 -0
- package/dist/src/frameworks/swift/utils.d.ts +12 -0
- package/dist/src/frameworks/swift/utils.js +82 -0
- package/dist/src/frameworks/unity/unity-wizard-agent.d.ts +6 -0
- package/dist/src/frameworks/unity/unity-wizard-agent.js +79 -0
- package/dist/src/frameworks/unity/utils.d.ts +12 -0
- package/dist/src/frameworks/unity/utils.js +66 -0
- package/dist/src/frameworks/unreal/unreal-wizard-agent.d.ts +6 -0
- package/dist/src/frameworks/unreal/unreal-wizard-agent.js +77 -0
- package/dist/src/frameworks/unreal/utils.d.ts +10 -0
- package/dist/src/frameworks/unreal/utils.js +29 -0
- package/dist/src/frameworks/vue/vue-wizard-agent.d.ts +4 -0
- package/dist/src/frameworks/vue/vue-wizard-agent.js +64 -0
- package/dist/src/lib/agent-hooks.d.ts +26 -0
- package/dist/src/lib/agent-hooks.js +118 -0
- package/dist/src/lib/agent-interface.d.ts +175 -0
- package/dist/src/lib/agent-interface.js +1217 -0
- package/dist/src/lib/agent-runner.d.ts +9 -0
- package/dist/src/lib/agent-runner.js +415 -0
- package/dist/src/lib/ampli-config.d.ts +105 -0
- package/dist/src/lib/ampli-config.js +178 -0
- package/dist/src/lib/api.d.ts +107 -0
- package/dist/src/lib/api.js +442 -0
- package/dist/src/lib/commandments.d.ts +1 -0
- package/dist/src/lib/commandments.js +24 -0
- package/dist/src/lib/console-query.d.ts +27 -0
- package/dist/src/lib/console-query.js +121 -0
- package/dist/src/lib/constants.d.ts +124 -0
- package/dist/src/lib/constants.js +170 -0
- package/dist/src/lib/detect-amplitude.d.ts +31 -0
- package/dist/src/lib/detect-amplitude.js +407 -0
- package/dist/src/lib/framework-config.d.ts +188 -0
- package/dist/src/lib/framework-config.js +21 -0
- package/dist/src/lib/health-checks/endpoints.d.ts +3 -0
- package/dist/src/lib/health-checks/endpoints.js +45 -0
- package/dist/src/lib/health-checks/index.d.ts +4 -0
- package/dist/src/lib/health-checks/index.js +22 -0
- package/dist/src/lib/health-checks/readiness.d.ts +24 -0
- package/dist/src/lib/health-checks/readiness.js +118 -0
- package/dist/src/lib/health-checks/statuspage.d.ts +9 -0
- package/dist/src/lib/health-checks/statuspage.js +104 -0
- package/dist/src/lib/health-checks/types.d.ts +31 -0
- package/dist/src/lib/health-checks/types.js +9 -0
- package/dist/src/lib/helper-functions.d.ts +1 -0
- package/dist/src/lib/helper-functions.js +5 -0
- package/dist/src/lib/middleware/benchmark.d.ts +54 -0
- package/dist/src/lib/middleware/benchmark.js +48 -0
- package/dist/src/lib/middleware/benchmarks/cache-tracker.d.ts +44 -0
- package/dist/src/lib/middleware/benchmarks/cache-tracker.js +80 -0
- package/dist/src/lib/middleware/benchmarks/compaction-tracker.d.ts +29 -0
- package/dist/src/lib/middleware/benchmarks/compaction-tracker.js +59 -0
- package/dist/src/lib/middleware/benchmarks/context-size-tracker.d.ts +26 -0
- package/dist/src/lib/middleware/benchmarks/context-size-tracker.js +55 -0
- package/dist/src/lib/middleware/benchmarks/cost-tracker.d.ts +16 -0
- package/dist/src/lib/middleware/benchmarks/cost-tracker.js +75 -0
- package/dist/src/lib/middleware/benchmarks/duration-tracker.d.ts +20 -0
- package/dist/src/lib/middleware/benchmarks/duration-tracker.js +39 -0
- package/dist/src/lib/middleware/benchmarks/index.d.ts +9 -0
- package/dist/src/lib/middleware/benchmarks/index.js +67 -0
- package/dist/src/lib/middleware/benchmarks/json-writer.d.ts +15 -0
- package/dist/src/lib/middleware/benchmarks/json-writer.js +144 -0
- package/dist/src/lib/middleware/benchmarks/summary.d.ts +9 -0
- package/dist/src/lib/middleware/benchmarks/summary.js +105 -0
- package/dist/src/lib/middleware/benchmarks/token-tracker.d.ts +40 -0
- package/dist/src/lib/middleware/benchmarks/token-tracker.js +76 -0
- package/dist/src/lib/middleware/benchmarks/turn-counter.d.ts +34 -0
- package/dist/src/lib/middleware/benchmarks/turn-counter.js +58 -0
- package/dist/src/lib/middleware/config.d.ts +24 -0
- package/dist/src/lib/middleware/config.js +96 -0
- package/dist/src/lib/middleware/index.d.ts +11 -0
- package/dist/src/lib/middleware/index.js +17 -0
- package/dist/src/lib/middleware/phase-detector.d.ts +8 -0
- package/dist/src/lib/middleware/phase-detector.js +63 -0
- package/dist/src/lib/middleware/pipeline.d.ts +29 -0
- package/dist/src/lib/middleware/pipeline.js +81 -0
- package/dist/src/lib/middleware/schemas.d.ts +27 -0
- package/dist/src/lib/middleware/schemas.js +84 -0
- package/dist/src/lib/middleware/types.d.ts +94 -0
- package/dist/src/lib/middleware/types.js +8 -0
- package/dist/src/lib/package-manager-detection.d.ts +42 -0
- package/dist/src/lib/package-manager-detection.js +292 -0
- package/dist/src/lib/registry.d.ts +3 -0
- package/dist/src/lib/registry.js +42 -0
- package/dist/src/lib/safe-tools.d.ts +2 -0
- package/dist/src/lib/safe-tools.js +214 -0
- package/dist/src/lib/wizard-session.d.ts +220 -0
- package/dist/src/lib/wizard-session.js +127 -0
- package/dist/src/lib/wizard-tools.d.ts +82 -0
- package/dist/src/lib/wizard-tools.js +499 -0
- package/dist/src/run.d.ts +19 -0
- package/dist/src/run.js +151 -0
- package/dist/src/steps/add-mcp-server-to-clients/MCPClient.d.ts +30 -0
- package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js +141 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.d.ts +29 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js +180 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude.d.ts +20 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude.js +63 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/codex.d.ts +28 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/codex.js +77 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.d.ts +24 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js +60 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.d.ts +27 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.js +101 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/zed.d.ts +26 -0
- package/dist/src/steps/add-mcp-server-to-clients/clients/zed.js +102 -0
- package/dist/src/steps/add-mcp-server-to-clients/defaults.d.ts +44 -0
- package/dist/src/steps/add-mcp-server-to-clients/defaults.js +123 -0
- package/dist/src/steps/add-mcp-server-to-clients/index.d.ts +19 -0
- package/dist/src/steps/add-mcp-server-to-clients/index.js +110 -0
- package/dist/src/steps/add-or-update-environment-variables.d.ts +10 -0
- package/dist/src/steps/add-or-update-environment-variables.js +188 -0
- package/dist/src/steps/index.d.ts +4 -0
- package/dist/src/steps/index.js +20 -0
- package/dist/src/steps/run-prettier.d.ts +5 -0
- package/dist/src/steps/run-prettier.js +90 -0
- package/dist/src/steps/upload-environment-variables/EnvironmentProvider.d.ts +11 -0
- package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js +11 -0
- package/dist/src/steps/upload-environment-variables/index.d.ts +6 -0
- package/dist/src/steps/upload-environment-variables/index.js +37 -0
- package/dist/src/steps/upload-environment-variables/providers/vercel.d.ts +15 -0
- package/dist/src/steps/upload-environment-variables/providers/vercel.js +145 -0
- package/dist/src/telemetry.d.ts +2 -0
- package/dist/src/telemetry.js +12 -0
- package/dist/src/ui/index.d.ts +8 -0
- package/dist/src/ui/index.js +16 -0
- package/dist/src/ui/logging-ui.d.ts +56 -0
- package/dist/src/ui/logging-ui.js +157 -0
- package/dist/src/ui/tui/App.d.ts +6 -0
- package/dist/src/ui/tui/App.js +34 -0
- package/dist/src/ui/tui/components/AmplitudeLogo.d.ts +5 -0
- package/dist/src/ui/tui/components/AmplitudeLogo.js +81 -0
- package/dist/src/ui/tui/components/AmplitudeTextLogo.d.ts +3 -0
- package/dist/src/ui/tui/components/AmplitudeTextLogo.js +31 -0
- package/dist/src/ui/tui/components/ConsoleView.d.ts +23 -0
- package/dist/src/ui/tui/components/ConsoleView.js +220 -0
- package/dist/src/ui/tui/components/TitleBar.d.ts +6 -0
- package/dist/src/ui/tui/components/TitleBar.js +16 -0
- package/dist/src/ui/tui/console-commands.d.ts +16 -0
- package/dist/src/ui/tui/console-commands.js +31 -0
- package/dist/src/ui/tui/context/CommandModeContext.d.ts +2 -0
- package/dist/src/ui/tui/context/CommandModeContext.js +3 -0
- package/dist/src/ui/tui/flows.d.ts +48 -0
- package/dist/src/ui/tui/flows.js +154 -0
- package/dist/src/ui/tui/hooks/useScreenInput.d.ts +13 -0
- package/dist/src/ui/tui/hooks/useScreenInput.js +18 -0
- package/dist/src/ui/tui/hooks/useStdoutDimensions.d.ts +9 -0
- package/dist/src/ui/tui/hooks/useStdoutDimensions.js +29 -0
- package/dist/src/ui/tui/ink-ui.d.ts +62 -0
- package/dist/src/ui/tui/ink-ui.js +142 -0
- package/dist/src/ui/tui/primitives/CardLayout.d.ts +12 -0
- package/dist/src/ui/tui/primitives/CardLayout.js +9 -0
- package/dist/src/ui/tui/primitives/ConfirmationInput.d.ts +13 -0
- package/dist/src/ui/tui/primitives/ConfirmationInput.js +35 -0
- package/dist/src/ui/tui/primitives/DissolveTransition.d.ts +21 -0
- package/dist/src/ui/tui/primitives/DissolveTransition.js +143 -0
- package/dist/src/ui/tui/primitives/EventPlanViewer.d.ts +9 -0
- package/dist/src/ui/tui/primitives/EventPlanViewer.js +9 -0
- package/dist/src/ui/tui/primitives/KagiSmallWebViewer.d.ts +7 -0
- package/dist/src/ui/tui/primitives/KagiSmallWebViewer.js +101 -0
- package/dist/src/ui/tui/primitives/LoadingBox.d.ts +8 -0
- package/dist/src/ui/tui/primitives/LoadingBox.js +9 -0
- package/dist/src/ui/tui/primitives/LogViewer.d.ts +11 -0
- package/dist/src/ui/tui/primitives/LogViewer.js +55 -0
- package/dist/src/ui/tui/primitives/PickerMenu.d.ts +20 -0
- package/dist/src/ui/tui/primitives/PickerMenu.js +212 -0
- package/dist/src/ui/tui/primitives/ProgressList.d.ts +15 -0
- package/dist/src/ui/tui/primitives/ProgressList.js +29 -0
- package/dist/src/ui/tui/primitives/PromptLabel.d.ts +11 -0
- package/dist/src/ui/tui/primitives/PromptLabel.js +12 -0
- package/dist/src/ui/tui/primitives/ReportViewer.d.ts +12 -0
- package/dist/src/ui/tui/primitives/ReportViewer.js +99 -0
- package/dist/src/ui/tui/primitives/ScreenErrorBoundary.d.ts +26 -0
- package/dist/src/ui/tui/primitives/ScreenErrorBoundary.js +29 -0
- package/dist/src/ui/tui/primitives/SlashCommandInput.d.ts +21 -0
- package/dist/src/ui/tui/primitives/SlashCommandInput.js +85 -0
- package/dist/src/ui/tui/primitives/SnakeGame.d.ts +1 -0
- package/dist/src/ui/tui/primitives/SnakeGame.js +1 -0
- package/dist/src/ui/tui/primitives/SplitView.d.ts +11 -0
- package/dist/src/ui/tui/primitives/SplitView.js +8 -0
- package/dist/src/ui/tui/primitives/TabContainer.d.ts +18 -0
- package/dist/src/ui/tui/primitives/TabContainer.js +30 -0
- package/dist/src/ui/tui/primitives/index.d.ts +23 -0
- package/dist/src/ui/tui/primitives/index.js +19 -0
- package/dist/src/ui/tui/router.d.ts +61 -0
- package/dist/src/ui/tui/router.js +104 -0
- package/dist/src/ui/tui/screen-registry.d.ts +19 -0
- package/dist/src/ui/tui/screen-registry.js +56 -0
- package/dist/src/ui/tui/screens/ActivationOptionsScreen.d.ts +12 -0
- package/dist/src/ui/tui/screens/ActivationOptionsScreen.js +57 -0
- package/dist/src/ui/tui/screens/AuthScreen.d.ts +18 -0
- package/dist/src/ui/tui/screens/AuthScreen.js +107 -0
- package/dist/src/ui/tui/screens/ChecklistScreen.d.ts +22 -0
- package/dist/src/ui/tui/screens/ChecklistScreen.js +122 -0
- package/dist/src/ui/tui/screens/DataIngestionCheckScreen.d.ts +24 -0
- package/dist/src/ui/tui/screens/DataIngestionCheckScreen.js +113 -0
- package/dist/src/ui/tui/screens/DataSetupScreen.d.ts +17 -0
- package/dist/src/ui/tui/screens/DataSetupScreen.js +73 -0
- package/dist/src/ui/tui/screens/IntroScreen.d.ts +16 -0
- package/dist/src/ui/tui/screens/IntroScreen.js +86 -0
- package/dist/src/ui/tui/screens/LoginScreen.d.ts +15 -0
- package/dist/src/ui/tui/screens/LoginScreen.js +65 -0
- package/dist/src/ui/tui/screens/LogoutScreen.d.ts +12 -0
- package/dist/src/ui/tui/screens/LogoutScreen.js +28 -0
- package/dist/src/ui/tui/screens/McpScreen.d.ts +26 -0
- package/dist/src/ui/tui/screens/McpScreen.js +148 -0
- package/dist/src/ui/tui/screens/OutageScreen.d.ts +10 -0
- package/dist/src/ui/tui/screens/OutageScreen.js +17 -0
- package/dist/src/ui/tui/screens/OutroScreen.d.ts +11 -0
- package/dist/src/ui/tui/screens/OutroScreen.js +69 -0
- package/dist/src/ui/tui/screens/RegionSelectScreen.d.ts +17 -0
- package/dist/src/ui/tui/screens/RegionSelectScreen.js +40 -0
- package/dist/src/ui/tui/screens/RunScreen.d.ts +16 -0
- package/dist/src/ui/tui/screens/RunScreen.js +212 -0
- package/dist/src/ui/tui/screens/SettingsOverrideScreen.d.ts +10 -0
- package/dist/src/ui/tui/screens/SettingsOverrideScreen.js +23 -0
- package/dist/src/ui/tui/screens/SetupScreen.d.ts +13 -0
- package/dist/src/ui/tui/screens/SetupScreen.js +73 -0
- package/dist/src/ui/tui/screens/SlackScreen.d.ts +25 -0
- package/dist/src/ui/tui/screens/SlackScreen.js +97 -0
- package/dist/src/ui/tui/services/mcp-installer.d.ts +25 -0
- package/dist/src/ui/tui/services/mcp-installer.js +82 -0
- package/dist/src/ui/tui/start-tui.d.ts +10 -0
- package/dist/src/ui/tui/start-tui.js +50 -0
- package/dist/src/ui/tui/store.d.ts +231 -0
- package/dist/src/ui/tui/store.js +568 -0
- package/dist/src/ui/tui/styles.d.ts +31 -0
- package/dist/src/ui/tui/styles.js +33 -0
- package/dist/src/ui/wizard-ui.d.ts +110 -0
- package/dist/src/ui/wizard-ui.js +18 -0
- package/dist/src/utils/ampli-settings.d.ts +37 -0
- package/dist/src/utils/ampli-settings.js +182 -0
- package/dist/src/utils/analytics.d.ts +35 -0
- package/dist/src/utils/analytics.js +133 -0
- package/dist/src/utils/anthropic-status.d.ts +17 -0
- package/dist/src/utils/anthropic-status.js +51 -0
- package/dist/src/utils/api-key-store.d.ts +35 -0
- package/dist/src/utils/api-key-store.js +176 -0
- package/dist/src/utils/bash.d.ts +2 -0
- package/dist/src/utils/bash.js +53 -0
- package/dist/src/utils/custom-headers.d.ts +9 -0
- package/dist/src/utils/custom-headers.js +23 -0
- package/dist/src/utils/debug.d.ts +23 -0
- package/dist/src/utils/debug.js +86 -0
- package/dist/src/utils/environment.d.ts +4 -0
- package/dist/src/utils/environment.js +76 -0
- package/dist/src/utils/file-utils.d.ts +2 -0
- package/dist/src/utils/file-utils.js +16 -0
- package/dist/src/utils/get-api-key.d.ts +17 -0
- package/dist/src/utils/get-api-key.js +50 -0
- package/dist/src/utils/logging.d.ts +9 -0
- package/dist/src/utils/logging.js +48 -0
- package/dist/src/utils/oauth.d.ts +53 -0
- package/dist/src/utils/oauth.js +354 -0
- package/dist/src/utils/package-json.d.ts +25 -0
- package/dist/src/utils/package-json.js +26 -0
- package/dist/src/utils/package-manager.d.ts +21 -0
- package/dist/src/utils/package-manager.js +208 -0
- package/dist/src/utils/semver.d.ts +21 -0
- package/dist/src/utils/semver.js +61 -0
- package/dist/src/utils/setup-utils.d.ts +82 -0
- package/dist/src/utils/setup-utils.js +467 -0
- package/dist/src/utils/shell-completions.d.ts +10 -0
- package/dist/src/utils/shell-completions.js +199 -0
- package/dist/src/utils/string.d.ts +1 -0
- package/dist/src/utils/string.js +8 -0
- package/dist/src/utils/types.d.ts +72 -0
- package/dist/src/utils/types.js +2 -0
- package/dist/src/utils/urls.d.ts +14 -0
- package/dist/src/utils/urls.js +69 -0
- package/dist/src/utils/vendor/is-unicorn-supported.d.ts +1 -0
- package/dist/src/utils/vendor/is-unicorn-supported.js +23 -0
- package/dist/src/utils/wizard-abort.d.ts +13 -0
- package/dist/src/utils/wizard-abort.js +56 -0
- package/man/amplitude-wizard.1 +170 -0
- package/package.json +144 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ApiProjectSchema = exports.ApiUserSchema = void 0;
|
|
7
|
+
exports.fetchAmplitudeUser = fetchAmplitudeUser;
|
|
8
|
+
exports.fetchBranches = fetchBranches;
|
|
9
|
+
exports.fetchWorkspaceEventTypes = fetchWorkspaceEventTypes;
|
|
10
|
+
exports.fetchOwnedDashboards = fetchOwnedDashboards;
|
|
11
|
+
exports.fetchSources = fetchSources;
|
|
12
|
+
exports.fetchProjectActivationStatus = fetchProjectActivationStatus;
|
|
13
|
+
exports.fetchUserData = fetchUserData;
|
|
14
|
+
exports.fetchProjectData = fetchProjectData;
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
const analytics_js_1 = require("../utils/analytics.js");
|
|
18
|
+
const constants_js_1 = require("./constants.js");
|
|
19
|
+
// ── Amplitude GraphQL types ───────────────────────────────────────────
|
|
20
|
+
const AmplitudeUserSchema = zod_1.z.object({
|
|
21
|
+
data: zod_1.z.object({
|
|
22
|
+
orgs: zod_1.z.array(zod_1.z.object({
|
|
23
|
+
id: zod_1.z.string(),
|
|
24
|
+
name: zod_1.z.string(),
|
|
25
|
+
user: zod_1.z.object({
|
|
26
|
+
id: zod_1.z.string(),
|
|
27
|
+
firstName: zod_1.z.string(),
|
|
28
|
+
lastName: zod_1.z.string(),
|
|
29
|
+
email: zod_1.z.string(),
|
|
30
|
+
}),
|
|
31
|
+
workspaces: zod_1.z.array(zod_1.z.object({
|
|
32
|
+
id: zod_1.z.string(),
|
|
33
|
+
name: zod_1.z.string(),
|
|
34
|
+
environments: zod_1.z
|
|
35
|
+
.array(zod_1.z.object({
|
|
36
|
+
name: zod_1.z.string(),
|
|
37
|
+
rank: zod_1.z.number(),
|
|
38
|
+
app: zod_1.z
|
|
39
|
+
.object({
|
|
40
|
+
id: zod_1.z.string(),
|
|
41
|
+
apiKey: zod_1.z.string().nullable().optional(),
|
|
42
|
+
})
|
|
43
|
+
.nullable(),
|
|
44
|
+
}))
|
|
45
|
+
.nullable()
|
|
46
|
+
.optional(),
|
|
47
|
+
})),
|
|
48
|
+
})),
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
const ORGS_QUERY = `
|
|
52
|
+
query orgs {
|
|
53
|
+
orgs {
|
|
54
|
+
id
|
|
55
|
+
name
|
|
56
|
+
user {
|
|
57
|
+
id
|
|
58
|
+
firstName
|
|
59
|
+
lastName
|
|
60
|
+
email
|
|
61
|
+
}
|
|
62
|
+
workspaces {
|
|
63
|
+
id
|
|
64
|
+
name
|
|
65
|
+
environments {
|
|
66
|
+
name
|
|
67
|
+
rank
|
|
68
|
+
app { id apiKey }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}`;
|
|
73
|
+
class ApiError extends Error {
|
|
74
|
+
statusCode;
|
|
75
|
+
endpoint;
|
|
76
|
+
constructor(message, statusCode, endpoint) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.statusCode = statusCode;
|
|
79
|
+
this.endpoint = endpoint;
|
|
80
|
+
this.name = 'ApiError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Fetches the authenticated user's org/workspace info from Amplitude's Data API.
|
|
85
|
+
* Uses the OAuth id_token as the Authorization header (same as ampli CLI).
|
|
86
|
+
*/
|
|
87
|
+
async function fetchAmplitudeUser(idToken, zone) {
|
|
88
|
+
const { dataApiUrl } = constants_js_1.AMPLITUDE_ZONE_SETTINGS[zone];
|
|
89
|
+
try {
|
|
90
|
+
const response = await axios_1.default.post(dataApiUrl, { query: ORGS_QUERY }, {
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: idToken,
|
|
93
|
+
'Content-Type': 'application/json',
|
|
94
|
+
'User-Agent': constants_js_1.WIZARD_USER_AGENT,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const parsed = AmplitudeUserSchema.parse(response.data);
|
|
98
|
+
const orgs = parsed.data.orgs;
|
|
99
|
+
const user = orgs[0]?.user;
|
|
100
|
+
if (!user)
|
|
101
|
+
throw new ApiError('No user data returned from Amplitude API');
|
|
102
|
+
return {
|
|
103
|
+
id: user.id,
|
|
104
|
+
firstName: user.firstName,
|
|
105
|
+
lastName: user.lastName,
|
|
106
|
+
email: user.email,
|
|
107
|
+
orgs: orgs.map((org) => ({
|
|
108
|
+
id: org.id,
|
|
109
|
+
name: org.name,
|
|
110
|
+
workspaces: org.workspaces,
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
const apiError = handleApiError(error, 'fetch Amplitude user data');
|
|
116
|
+
analytics_js_1.analytics.captureException(apiError, { endpoint: dataApiUrl });
|
|
117
|
+
throw apiError;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// ── Branches ──────────────────────────────────────────────────────────────
|
|
121
|
+
const BranchesSchema = zod_1.z.object({
|
|
122
|
+
data: zod_1.z.object({
|
|
123
|
+
orgs: zod_1.z.array(zod_1.z.object({
|
|
124
|
+
workspaces: zod_1.z.array(zod_1.z.object({
|
|
125
|
+
branches: zod_1.z.array(zod_1.z.object({
|
|
126
|
+
id: zod_1.z.string(),
|
|
127
|
+
name: zod_1.z.string(),
|
|
128
|
+
default: zod_1.z.boolean(),
|
|
129
|
+
currentVersionId: zod_1.z.string(),
|
|
130
|
+
})),
|
|
131
|
+
})),
|
|
132
|
+
})),
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
const BRANCHES_QUERY = `
|
|
136
|
+
query branches($orgId: ID!, $workspaceId: ID!) {
|
|
137
|
+
orgs(id: $orgId) {
|
|
138
|
+
workspaces(id: $workspaceId) {
|
|
139
|
+
branches {
|
|
140
|
+
id
|
|
141
|
+
name
|
|
142
|
+
default
|
|
143
|
+
currentVersionId
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}`;
|
|
148
|
+
/** Fetches branches for a workspace. */
|
|
149
|
+
async function fetchBranches(idToken, zone, orgId, workspaceId) {
|
|
150
|
+
const { dataApiUrl } = constants_js_1.AMPLITUDE_ZONE_SETTINGS[zone];
|
|
151
|
+
try {
|
|
152
|
+
const response = await axios_1.default.post(dataApiUrl, { query: BRANCHES_QUERY, variables: { orgId, workspaceId } }, {
|
|
153
|
+
headers: {
|
|
154
|
+
Authorization: idToken,
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
'User-Agent': constants_js_1.WIZARD_USER_AGENT,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
const parsed = BranchesSchema.parse(response.data);
|
|
160
|
+
return parsed.data.orgs[0]?.workspaces[0]?.branches ?? [];
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const apiError = handleApiError(error, 'fetch branches');
|
|
164
|
+
analytics_js_1.analytics.captureException(apiError, { endpoint: dataApiUrl });
|
|
165
|
+
throw apiError;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// ── Workspace event types ─────────────────────────────────────────────────
|
|
169
|
+
const WorkspaceEventsSchema = zod_1.z.object({
|
|
170
|
+
data: zod_1.z.object({
|
|
171
|
+
orgs: zod_1.z.array(zod_1.z.object({
|
|
172
|
+
workspaces: zod_1.z.array(zod_1.z.object({
|
|
173
|
+
branches: zod_1.z.array(zod_1.z.object({
|
|
174
|
+
versions: zod_1.z.array(zod_1.z.object({
|
|
175
|
+
events: zod_1.z.array(zod_1.z.object({ id: zod_1.z.string(), name: zod_1.z.string() })),
|
|
176
|
+
})),
|
|
177
|
+
})),
|
|
178
|
+
})),
|
|
179
|
+
})),
|
|
180
|
+
}),
|
|
181
|
+
});
|
|
182
|
+
const WORKSPACE_EVENTS_QUERY = `
|
|
183
|
+
query workspaceEvents($orgId: ID!, $workspaceId: ID!, $branchId: ID!, $versionId: ID!) {
|
|
184
|
+
orgs(id: $orgId) {
|
|
185
|
+
workspaces(id: $workspaceId) {
|
|
186
|
+
branches(id: $branchId) {
|
|
187
|
+
versions(id: $versionId) {
|
|
188
|
+
events { id name }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}`;
|
|
194
|
+
/**
|
|
195
|
+
* Fetches the event type names cataloged in the default branch of a workspace.
|
|
196
|
+
* Returns an empty array if the workspace has no events or the query fails.
|
|
197
|
+
*/
|
|
198
|
+
async function fetchWorkspaceEventTypes(idToken, zone, orgId, workspaceId) {
|
|
199
|
+
const { dataApiUrl } = constants_js_1.AMPLITUDE_ZONE_SETTINGS[zone];
|
|
200
|
+
try {
|
|
201
|
+
// Step 1: get default branch + its current version
|
|
202
|
+
const branches = await fetchBranches(idToken, zone, orgId, workspaceId);
|
|
203
|
+
const defaultBranch = branches.find((b) => b.default) ?? branches[0];
|
|
204
|
+
if (!defaultBranch)
|
|
205
|
+
return [];
|
|
206
|
+
// Step 2: fetch events for that version
|
|
207
|
+
const response = await axios_1.default.post(dataApiUrl, {
|
|
208
|
+
query: WORKSPACE_EVENTS_QUERY,
|
|
209
|
+
variables: {
|
|
210
|
+
orgId,
|
|
211
|
+
workspaceId,
|
|
212
|
+
branchId: defaultBranch.id,
|
|
213
|
+
versionId: defaultBranch.currentVersionId,
|
|
214
|
+
},
|
|
215
|
+
}, {
|
|
216
|
+
headers: {
|
|
217
|
+
Authorization: idToken,
|
|
218
|
+
'Content-Type': 'application/json',
|
|
219
|
+
'User-Agent': constants_js_1.WIZARD_USER_AGENT,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
const parsed = WorkspaceEventsSchema.parse(response.data);
|
|
223
|
+
return (parsed.data.orgs[0]?.workspaces[0]?.branches[0]?.versions[0]?.events.map((e) => e.name) ?? []);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// ── Owned dashboards ──────────────────────────────────────────────────────────
|
|
230
|
+
const OwnedDashboardsSchema = zod_1.z.object({
|
|
231
|
+
data: zod_1.z.object({
|
|
232
|
+
ownedDashboards: zod_1.z.array(zod_1.z.object({
|
|
233
|
+
id: zod_1.z.string(),
|
|
234
|
+
chartIds: zod_1.z.array(zod_1.z.string()),
|
|
235
|
+
})),
|
|
236
|
+
}),
|
|
237
|
+
});
|
|
238
|
+
const OWNED_DASHBOARDS_QUERY = `
|
|
239
|
+
query OwnedDashboards {
|
|
240
|
+
ownedDashboards {
|
|
241
|
+
id
|
|
242
|
+
chartIds
|
|
243
|
+
}
|
|
244
|
+
}`;
|
|
245
|
+
/**
|
|
246
|
+
* Checks whether the authenticated user has any charts or dashboards in their org.
|
|
247
|
+
* Uses the Thunder org-scoped GraphQL endpoint.
|
|
248
|
+
*
|
|
249
|
+
* Detection is org-scoped — Thunder has no project-level chart/dashboard listing
|
|
250
|
+
* API. For a typical new-project user this is equivalent to project-scoped.
|
|
251
|
+
*
|
|
252
|
+
* Returns { hasCharts: false, hasDashboards: false } on any error so the
|
|
253
|
+
* checklist falls back to the default empty state rather than crashing.
|
|
254
|
+
*/
|
|
255
|
+
async function fetchOwnedDashboards(idToken, zone, orgId) {
|
|
256
|
+
const { appApiUrlBase } = constants_js_1.AMPLITUDE_ZONE_SETTINGS[zone];
|
|
257
|
+
const url = `${appApiUrlBase}${orgId}`;
|
|
258
|
+
try {
|
|
259
|
+
const response = await axios_1.default.post(url, { query: OWNED_DASHBOARDS_QUERY }, {
|
|
260
|
+
headers: {
|
|
261
|
+
Authorization: idToken,
|
|
262
|
+
'Content-Type': 'application/json',
|
|
263
|
+
'User-Agent': constants_js_1.WIZARD_USER_AGENT,
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
const parsed = OwnedDashboardsSchema.parse(response.data);
|
|
267
|
+
const dashboards = parsed.data.ownedDashboards;
|
|
268
|
+
return {
|
|
269
|
+
hasDashboards: dashboards.length > 0,
|
|
270
|
+
hasCharts: dashboards.some((d) => d.chartIds.length > 0),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return { hasCharts: false, hasDashboards: false };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// ── Sources ───────────────────────────────────────────────────────────────
|
|
278
|
+
const SourcesSchema = zod_1.z.object({
|
|
279
|
+
data: zod_1.z.object({
|
|
280
|
+
orgs: zod_1.z.array(zod_1.z.object({
|
|
281
|
+
workspaces: zod_1.z.array(zod_1.z.object({
|
|
282
|
+
branches: zod_1.z.array(zod_1.z.object({
|
|
283
|
+
versions: zod_1.z.array(zod_1.z.object({
|
|
284
|
+
id: zod_1.z.string(),
|
|
285
|
+
sources: zod_1.z.array(zod_1.z.object({
|
|
286
|
+
id: zod_1.z.string(),
|
|
287
|
+
name: zod_1.z.string(),
|
|
288
|
+
runtime: zod_1.z
|
|
289
|
+
.object({
|
|
290
|
+
id: zod_1.z.string(),
|
|
291
|
+
platformId: zod_1.z.string(),
|
|
292
|
+
platformName: zod_1.z.string(),
|
|
293
|
+
languageId: zod_1.z.string(),
|
|
294
|
+
languageName: zod_1.z.string(),
|
|
295
|
+
})
|
|
296
|
+
.nullable(),
|
|
297
|
+
destinations: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), serviceId: zod_1.z.string() })),
|
|
298
|
+
})),
|
|
299
|
+
})),
|
|
300
|
+
})),
|
|
301
|
+
})),
|
|
302
|
+
})),
|
|
303
|
+
}),
|
|
304
|
+
});
|
|
305
|
+
const SOURCES_QUERY = `
|
|
306
|
+
query sources($orgId: ID!, $workspaceId: ID!, $branchId: ID!, $versionId: ID!) {
|
|
307
|
+
orgs(id: $orgId) {
|
|
308
|
+
workspaces(id: $workspaceId) {
|
|
309
|
+
branches(id: $branchId) {
|
|
310
|
+
versions(id: $versionId) {
|
|
311
|
+
id
|
|
312
|
+
sources {
|
|
313
|
+
id
|
|
314
|
+
name
|
|
315
|
+
runtime {
|
|
316
|
+
id
|
|
317
|
+
platformId
|
|
318
|
+
platformName
|
|
319
|
+
languageId
|
|
320
|
+
languageName
|
|
321
|
+
}
|
|
322
|
+
destinations { name serviceId }
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}`;
|
|
329
|
+
/** Fetches sources for a specific branch version. */
|
|
330
|
+
async function fetchSources(idToken, zone, orgId, workspaceId, branchId, versionId) {
|
|
331
|
+
const { dataApiUrl } = constants_js_1.AMPLITUDE_ZONE_SETTINGS[zone];
|
|
332
|
+
try {
|
|
333
|
+
const response = await axios_1.default.post(dataApiUrl, {
|
|
334
|
+
query: SOURCES_QUERY,
|
|
335
|
+
variables: { orgId, workspaceId, branchId, versionId },
|
|
336
|
+
}, {
|
|
337
|
+
headers: {
|
|
338
|
+
Authorization: idToken,
|
|
339
|
+
'Content-Type': 'application/json',
|
|
340
|
+
'User-Agent': constants_js_1.WIZARD_USER_AGENT,
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
const parsed = SourcesSchema.parse(response.data);
|
|
344
|
+
return (parsed.data.orgs[0]?.workspaces[0]?.branches[0]?.versions[0]?.sources ??
|
|
345
|
+
[]);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
const apiError = handleApiError(error, 'fetch sources');
|
|
349
|
+
analytics_js_1.analytics.captureException(apiError, { endpoint: dataApiUrl });
|
|
350
|
+
throw apiError;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// ── Project activation status ──────────────────────────────────────────────
|
|
354
|
+
const ActivationStatusSchema = zod_1.z.object({
|
|
355
|
+
data: zod_1.z.object({
|
|
356
|
+
hasAnyDefaultEventTrackingSourceAndEvents: zod_1.z.object({
|
|
357
|
+
hasDetSource: zod_1.z.boolean(),
|
|
358
|
+
hasPageViewedEvent: zod_1.z.boolean(),
|
|
359
|
+
hasSessionStartEvent: zod_1.z.boolean(),
|
|
360
|
+
hasSessionEndEvent: zod_1.z.boolean(),
|
|
361
|
+
}),
|
|
362
|
+
}),
|
|
363
|
+
});
|
|
364
|
+
const ACTIVATION_STATUS_QUERY = `
|
|
365
|
+
query hasAnyDefaultEventTrackingSourceAndEvents($appId: ID!) {
|
|
366
|
+
hasAnyDefaultEventTrackingSourceAndEvents(appId: $appId) {
|
|
367
|
+
hasDetSource
|
|
368
|
+
hasPageViewedEvent
|
|
369
|
+
hasSessionStartEvent
|
|
370
|
+
hasSessionEndEvent
|
|
371
|
+
}
|
|
372
|
+
}`;
|
|
373
|
+
/**
|
|
374
|
+
* Checks whether an Amplitude project has ingested any events and whether
|
|
375
|
+
* the SDK snippet is configured.
|
|
376
|
+
*
|
|
377
|
+
* The query lives in Thunder (the main Amplitude app GraphQL server), served
|
|
378
|
+
* at /graphql/org/:orgId. orgId is required to construct the endpoint URL.
|
|
379
|
+
*/
|
|
380
|
+
async function fetchProjectActivationStatus(idToken, zone, appId, orgId) {
|
|
381
|
+
const { appApiUrlBase, dataApiUrl } = constants_js_1.AMPLITUDE_ZONE_SETTINGS[zone];
|
|
382
|
+
// Use the Thunder org-scoped endpoint when orgId is available; fall back to
|
|
383
|
+
// the data API (which may not expose this field for all users).
|
|
384
|
+
const url = orgId ? `${appApiUrlBase}${orgId}` : dataApiUrl;
|
|
385
|
+
try {
|
|
386
|
+
const response = await axios_1.default.post(url, { query: ACTIVATION_STATUS_QUERY, variables: { appId: String(appId) } }, {
|
|
387
|
+
headers: {
|
|
388
|
+
Authorization: idToken,
|
|
389
|
+
'Content-Type': 'application/json',
|
|
390
|
+
'User-Agent': constants_js_1.WIZARD_USER_AGENT,
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
const parsed = ActivationStatusSchema.parse(response.data);
|
|
394
|
+
const s = parsed.data.hasAnyDefaultEventTrackingSourceAndEvents;
|
|
395
|
+
return {
|
|
396
|
+
...s,
|
|
397
|
+
hasAnyEvents: s.hasPageViewedEvent || s.hasSessionStartEvent || s.hasSessionEndEvent,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
const apiError = handleApiError(error, 'fetch project activation status');
|
|
402
|
+
analytics_js_1.analytics.captureException(apiError, { endpoint: url });
|
|
403
|
+
throw apiError;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function handleApiError(error, operation) {
|
|
407
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
408
|
+
const axiosError = error;
|
|
409
|
+
const status = axiosError.response?.status;
|
|
410
|
+
const endpoint = axiosError.config?.url;
|
|
411
|
+
const gqlMessage = axiosError.response?.data?.errors?.[0]?.message;
|
|
412
|
+
if (status === 401)
|
|
413
|
+
return new ApiError(`Authentication failed while trying to ${operation}`, status, endpoint);
|
|
414
|
+
if (status === 403)
|
|
415
|
+
return new ApiError(`Access denied while trying to ${operation}`, status, endpoint);
|
|
416
|
+
const message = gqlMessage ?? `Failed to ${operation}`;
|
|
417
|
+
return new ApiError(message, status, endpoint);
|
|
418
|
+
}
|
|
419
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
420
|
+
return new ApiError(`Invalid response format while trying to ${operation}`);
|
|
421
|
+
}
|
|
422
|
+
return new ApiError(`Unexpected error while trying to ${operation}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
423
|
+
}
|
|
424
|
+
// ── Legacy stubs — kept so files referencing the old Amplitude types compile ──
|
|
425
|
+
exports.ApiUserSchema = zod_1.z.object({ distinct_id: zod_1.z.string() });
|
|
426
|
+
exports.ApiProjectSchema = zod_1.z.object({
|
|
427
|
+
id: zod_1.z.number(),
|
|
428
|
+
uuid: zod_1.z.string(),
|
|
429
|
+
organization: zod_1.z.string(),
|
|
430
|
+
api_token: zod_1.z.string(),
|
|
431
|
+
name: zod_1.z.string(),
|
|
432
|
+
});
|
|
433
|
+
/** @deprecated Amplitude stub. Use fetchAmplitudeUser instead. */
|
|
434
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
435
|
+
async function fetchUserData(_accessToken, _baseUrl) {
|
|
436
|
+
throw new Error('fetchUserData is a Amplitude stub — use fetchAmplitudeUser instead');
|
|
437
|
+
}
|
|
438
|
+
/** @deprecated Amplitude stub. Use fetchAmplitudeUser instead. */
|
|
439
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
440
|
+
async function fetchProjectData(_accessToken, _projectId, _baseUrl) {
|
|
441
|
+
throw new Error('fetchProjectData is a Amplitude stub — use fetchAmplitudeUser instead');
|
|
442
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getWizardCommandments(): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWizardCommandments = getWizardCommandments;
|
|
4
|
+
/**
|
|
5
|
+
* Wizard-wide commandments that are always appended as a system prompt.
|
|
6
|
+
*
|
|
7
|
+
* Keep this as a simple string so it can be inlined into the compiled bundle
|
|
8
|
+
* without extra files, copying, or runtime I/O.
|
|
9
|
+
*/
|
|
10
|
+
const WIZARD_COMMANDMENTS = [
|
|
11
|
+
'Never hallucinate an Amplitude API key, host, or any other secret. Always use the real values that have been configured for this project (for example via environment variables).',
|
|
12
|
+
'Never write API keys, access tokens, or other secrets directly into source code. Always reference environment variables instead, and rely on the wizard-tools MCP server (check_env_keys / set_env_values) to create or update .env files.',
|
|
13
|
+
'Always use the detect_package_manager tool from the wizard-tools MCP server to determine the package manager. Do not guess based on lockfiles or hard-code npm, yarn, pnpm, bun, pip, etc.',
|
|
14
|
+
'When installing packages, start the installation as a background task and then continue with other work. Do not block waiting for installs to finish unless explicitly instructed.',
|
|
15
|
+
'Before writing to any file, you MUST read that exact file immediately beforehand using the Read tool, even if you have already read it earlier in the run. This avoids tool failures and stale edits.',
|
|
16
|
+
'Treat feature flags, custom properties, and event names as part of an analytics contract. Prefer reusing existing names and patterns in the project. When you must introduce new ones, make them clear, descriptive, and consistent with existing conventions, and avoid scattering the same flag or property across many unrelated callsites.',
|
|
17
|
+
'Prefer minimal, targeted edits that achieve the requested behavior while preserving existing structure and style. Avoid large refactors, broad reformatting, or unrelated changes unless explicitly requested.',
|
|
18
|
+
'Do not spawn subagents unless explicitly instructed to do so.',
|
|
19
|
+
'Use the TodoWrite tool to track your progress. Create a todo list at the start describing the high-level areas of work, mark each as in_progress when you begin it, and completed when done.',
|
|
20
|
+
'After installing the SDK and adding initialization code, but BEFORE writing any track() calls, you MUST call the confirm_event_plan tool to present the proposed instrumentation plan to the user. Only proceed with instrumentation after the plan is approved. If the user provides feedback, revise the plan accordingly and call confirm_event_plan again. If the plan is skipped, do not instrument any events.',
|
|
21
|
+
].join('\n');
|
|
22
|
+
function getWizardCommandments() {
|
|
23
|
+
return WIZARD_COMMANDMENTS;
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* console-query — single-turn Claude call for the ConsoleView.
|
|
3
|
+
*
|
|
4
|
+
* Uses the global agent (getAgent) so all calls share the same initialized
|
|
5
|
+
* SDK config (gateway URL, model, env) rather than making raw fetch calls.
|
|
6
|
+
*/
|
|
7
|
+
import type { WizardSession } from './wizard-session.js';
|
|
8
|
+
export type ConsoleCredentials = {
|
|
9
|
+
kind: 'gateway';
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'direct';
|
|
14
|
+
apiKey: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'none';
|
|
17
|
+
};
|
|
18
|
+
/** Resolve credentials from session + env, in priority order. */
|
|
19
|
+
export declare function resolveConsoleCredentials(session: WizardSession): ConsoleCredentials;
|
|
20
|
+
/** Build a compact plain-text summary of the current session state for the system prompt. */
|
|
21
|
+
export declare function buildSessionContext(session: WizardSession): string;
|
|
22
|
+
export interface ConversationTurn {
|
|
23
|
+
role: 'user' | 'assistant';
|
|
24
|
+
content: string;
|
|
25
|
+
}
|
|
26
|
+
/** Send a message to Claude with optional conversation history and return the text response. */
|
|
27
|
+
export declare function queryConsole(userMessage: string, sessionContext: string, creds: ConsoleCredentials, history?: ConversationTurn[]): Promise<string>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* console-query — single-turn Claude call for the ConsoleView.
|
|
4
|
+
*
|
|
5
|
+
* Uses the global agent (getAgent) so all calls share the same initialized
|
|
6
|
+
* SDK config (gateway URL, model, env) rather than making raw fetch calls.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.resolveConsoleCredentials = resolveConsoleCredentials;
|
|
10
|
+
exports.buildSessionContext = buildSessionContext;
|
|
11
|
+
exports.queryConsole = queryConsole;
|
|
12
|
+
const urls_js_1 = require("../utils/urls.js");
|
|
13
|
+
const wizard_session_js_1 = require("./wizard-session.js");
|
|
14
|
+
const agent_interface_js_1 = require("./agent-interface.js");
|
|
15
|
+
const schemas_js_1 = require("./middleware/schemas.js");
|
|
16
|
+
const wizard_tools_js_1 = require("./wizard-tools.js");
|
|
17
|
+
/** Resolve credentials from session + env, in priority order. */
|
|
18
|
+
function resolveConsoleCredentials(session) {
|
|
19
|
+
// Gateway: set after initializeAgent runs
|
|
20
|
+
if (process.env.ANTHROPIC_BASE_URL && process.env.ANTHROPIC_AUTH_TOKEN) {
|
|
21
|
+
return {
|
|
22
|
+
kind: 'gateway',
|
|
23
|
+
baseUrl: process.env.ANTHROPIC_BASE_URL,
|
|
24
|
+
apiKey: process.env.ANTHROPIC_AUTH_TOKEN,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Session credentials: available after auth screen
|
|
28
|
+
if (session.credentials?.projectApiKey && session.credentials?.host) {
|
|
29
|
+
const devToken = process.env.WIZARD_PROXY_DEV_TOKEN;
|
|
30
|
+
return {
|
|
31
|
+
kind: 'gateway',
|
|
32
|
+
baseUrl: (0, urls_js_1.getLlmGatewayUrlFromHost)(session.credentials.host),
|
|
33
|
+
apiKey: devToken ?? session.credentials.projectApiKey,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Direct Anthropic API key
|
|
37
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
38
|
+
return { kind: 'direct', apiKey: process.env.ANTHROPIC_API_KEY };
|
|
39
|
+
}
|
|
40
|
+
return { kind: 'none' };
|
|
41
|
+
}
|
|
42
|
+
/** Build a compact plain-text summary of the current session state for the system prompt. */
|
|
43
|
+
function buildSessionContext(session) {
|
|
44
|
+
const lines = [
|
|
45
|
+
'You are a helpful assistant embedded in the Amplitude Wizard CLI.',
|
|
46
|
+
"Answer the user's questions concisely. Focus on the current wizard state below.",
|
|
47
|
+
'',
|
|
48
|
+
'--- Current wizard state ---',
|
|
49
|
+
`Phase: ${session.runPhase ?? wizard_session_js_1.RunPhase.Idle}`,
|
|
50
|
+
];
|
|
51
|
+
if (session.region)
|
|
52
|
+
lines.push(`Region: ${session.region}`);
|
|
53
|
+
if (session.detectedFrameworkLabel)
|
|
54
|
+
lines.push(`Framework: ${session.detectedFrameworkLabel}`);
|
|
55
|
+
if (session.integration)
|
|
56
|
+
lines.push(`Integration: ${session.integration}`);
|
|
57
|
+
if (session.selectedOrgName)
|
|
58
|
+
lines.push(`Org: ${session.selectedOrgName}`);
|
|
59
|
+
if (session.selectedWorkspaceName)
|
|
60
|
+
lines.push(`Workspace: ${session.selectedWorkspaceName}`);
|
|
61
|
+
if (session.credentials?.projectId)
|
|
62
|
+
lines.push(`Project ID: ${session.credentials.projectId}`);
|
|
63
|
+
if (session.runPhase === wizard_session_js_1.RunPhase.Completed) {
|
|
64
|
+
lines.push('Status: Wizard run completed successfully.');
|
|
65
|
+
}
|
|
66
|
+
else if (session.runPhase === wizard_session_js_1.RunPhase.Error) {
|
|
67
|
+
lines.push('Status: Wizard run finished with an error.');
|
|
68
|
+
}
|
|
69
|
+
else if (session.runPhase === wizard_session_js_1.RunPhase.Running) {
|
|
70
|
+
lines.push('Status: Wizard agent is currently running.');
|
|
71
|
+
}
|
|
72
|
+
if (session.outroData?.message) {
|
|
73
|
+
lines.push(`Last message: ${session.outroData.message}`);
|
|
74
|
+
}
|
|
75
|
+
return lines.join('\n');
|
|
76
|
+
}
|
|
77
|
+
/** Send a message to Claude with optional conversation history and return the text response. */
|
|
78
|
+
async function queryConsole(userMessage, sessionContext, creds, history = []) {
|
|
79
|
+
if (creds.kind === 'none') {
|
|
80
|
+
return 'Claude is not available yet — complete authentication first.';
|
|
81
|
+
}
|
|
82
|
+
const agentConfig = await (0, agent_interface_js_1.getAgent)();
|
|
83
|
+
const { query } = (await import('@anthropic-ai/claude-agent-sdk'));
|
|
84
|
+
const historyBlock = history.length > 0
|
|
85
|
+
? '\n\n--- Conversation history ---\n' +
|
|
86
|
+
history
|
|
87
|
+
.map((t) => `${t.role === 'user' ? 'User' : 'Assistant'}: ${t.content}`)
|
|
88
|
+
.join('\n') +
|
|
89
|
+
'\n--- End of history ---'
|
|
90
|
+
: '';
|
|
91
|
+
const collectedText = [];
|
|
92
|
+
const response = query({
|
|
93
|
+
prompt: userMessage,
|
|
94
|
+
options: {
|
|
95
|
+
model: agentConfig.model,
|
|
96
|
+
cwd: agentConfig.workingDirectory,
|
|
97
|
+
permissionMode: 'bypassPermissions',
|
|
98
|
+
mcpServers: agentConfig.mcpServers,
|
|
99
|
+
allowedTools: wizard_tools_js_1.WIZARD_TOOL_NAMES,
|
|
100
|
+
systemPrompt: sessionContext + historyBlock,
|
|
101
|
+
env: process.env,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
for await (const rawMessage of response) {
|
|
105
|
+
const parsed = (0, schemas_js_1.safeParseSDKMessage)(rawMessage);
|
|
106
|
+
if (!parsed.ok)
|
|
107
|
+
continue;
|
|
108
|
+
const message = parsed.message;
|
|
109
|
+
if (message.type === 'assistant') {
|
|
110
|
+
const content = message.message?.content;
|
|
111
|
+
if (Array.isArray(content)) {
|
|
112
|
+
for (const block of content) {
|
|
113
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
114
|
+
collectedText.push(block.text);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return collectedText.join('') || '(empty response)';
|
|
121
|
+
}
|