( configPath: string | undefined, )
| 49 | } |
| 50 | |
| 51 | export async function runOnboardingFlow( |
| 52 | configPath: string | undefined, |
| 53 | ): Promise<boolean> { |
| 54 | // Step 1: Check if --config flag is provided |
| 55 | if (configPath !== undefined) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | // Step 2: Check for CONTINUE_USE_BEDROCK environment variable first (before test env check) |
| 60 | if (process.env.CONTINUE_USE_BEDROCK === "1") { |
| 61 | console.log( |
| 62 | chalk.blue("✓ Using AWS Bedrock (CONTINUE_USE_BEDROCK detected)"), |
| 63 | ); |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | // Step 3: Check if we're in a test/CI environment - if so, skip interactive prompts |
| 68 | const isTestEnv = |
| 69 | process.env.NODE_ENV === "test" || |
| 70 | process.env.CI === "true" || |
| 71 | process.env.VITEST === "true" || |
| 72 | process.env.GITHUB_ACTIONS === "true" || |
| 73 | !process.stdin.isTTY; |
| 74 | |
| 75 | if (isTestEnv) { |
| 76 | // In test/CI environment, check for ANTHROPIC_API_KEY first |
| 77 | if (process.env.ANTHROPIC_API_KEY) { |
| 78 | console.log(chalk.blue("✓ Using ANTHROPIC_API_KEY from environment")); |
| 79 | await createOrUpdateConfig(process.env.ANTHROPIC_API_KEY); |
| 80 | console.log(chalk.gray(` Config saved to: ${CONFIG_PATH}`)); |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | // Otherwise return a minimal working configuration |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | // Step 4: Prompt for API key |
| 89 | console.log(chalk.yellow("To get started, enter your Anthropic API key.")); |
| 90 | |
| 91 | const apiKey = await question( |
| 92 | chalk.white("\nEnter your Anthropic API key: "), |
| 93 | ); |
| 94 | |
| 95 | if (!isValidAnthropicApiKey(apiKey)) { |
| 96 | throw new Error(getApiKeyValidationError(apiKey)); |
| 97 | } |
| 98 | |
| 99 | await createOrUpdateConfig(apiKey); |
| 100 | console.log( |
| 101 | chalk.green(`✓ Config file updated successfully at ${CONFIG_PATH}`), |
| 102 | ); |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | export async function isFirstTime(): Promise<boolean> { |
| 108 | return !fs.existsSync(path.join(env.continueHome, ".onboarding_complete")); |
no test coverage detected