import React from 'react' import { Box, Text } from 'ink' import { getGlobalConfig, saveGlobalConfig } from '../utils/config' import { getTheme } from '../utils/theme' import { Select } from './CustomSelect/select' import { useExitOnCtrlCD } from '../hooks/useExitOnCtrlCD' import chalk from 'chalk' type Props = { customApiKeyTruncated: string onDone(): void } export function ApproveApiKey({ customApiKeyTruncated, onDone, }: Props): React.ReactNode { const theme = getTheme() function onChange(value: 'yes' | 'no') { const config = getGlobalConfig() switch (value) { case 'yes': { saveGlobalConfig({ ...config, customApiKeyResponses: { ...config.customApiKeyResponses, approved: [ ...(config.customApiKeyResponses?.approved ?? []), customApiKeyTruncated, ], }, }) onDone() break } case 'no': { saveGlobalConfig({ ...config, customApiKeyResponses: { ...config.customApiKeyResponses, rejected: [ ...(config.customApiKeyResponses?.rejected ?? []), customApiKeyTruncated, ], }, }) onDone() break } } } const exitState = useExitOnCtrlCD(() => process.exit(0)) return ( <> Detected a custom API key in your environment Your environment sets{' '} ANTHROPIC_API_KEY:{' '} sk-ant-...{customApiKeyTruncated} Do you want to use this API key?