1 line
7.6 KiB
JSON
1 line
7.6 KiB
JSON
{"repo": "12errh/antigravity-proxy", "files": {"proxy/src/cli/commands/setup.ts": {"7b4e9d16623a91b92bf115d1b0a3775eb274a5b6": {"t": 1785846955.0539, "n": 7368, "h": "eb6da335f67c3ce8", "c": "import fs from 'fs';\nimport path from 'path';\nimport chalk from 'chalk';\nimport { USER_ENV_PATH as ENV_PATH, ENV_EXAMPLE } from '../utils/paths.js';\nimport { header, section, ok, warn, info, confirm, prompt, select, maskKey, arrow, divider } from '../ui.js';\n\nconst PROVIDERS = [\n { id: 'openrouter', name: 'OpenRouter', envKey: 'OPENROUTER_API_KEY', placeholder: 'sk-or-v1-...' },\n { id: 'nvidia', name: 'NVIDIA', envKey: 'NVIDIA_API_KEY', placeholder: 'nvapi-...' },\n { id: 'openai', name: 'OpenAI', envKey: 'OPENAI_API_KEY', placeholder: 'sk-...' },\n { id: 'anthropic', name: 'Anthropic', envKey: 'ANTHROPIC_API_KEY', placeholder: 'sk-ant-...' },\n { id: 'groq', name: 'Groq', envKey: 'GROQ_API_KEY', placeholder: 'gsk_...' },\n { id: 'google', name: 'Google AI', envKey: 'GOOGLE_API_KEY', placeholder: 'AIza...' },\n { id: 'zen', name: 'OpenCode Zen', envKey: 'OPENCODE_API_KEY', placeholder: 'sk-...' },\n { id: 'opencode-go', name: 'OpenCode Go', envKey: 'OPENCODE_GO_API_KEY', placeholder: 'sk-...' },\n { id: 'ollama', name: 'Ollama (local)', envKey: '', placeholder: '' },\n { id: 'vllm', name: 'vLLM (local)', envKey: '', placeholder: '' },\n { id: 'lmstudio', name: 'LM Studio (local)', envKey: '', placeholder: '' },\n];\n\nfunction ensureEnvExists(): void {\n if (!fs.existsSync(ENV_PATH) && fs.existsSync(ENV_EXAMPLE)) {\n fs.copyFileSync(ENV_EXAMPLE, ENV_PATH);\n }\n}\n\nfunction readEnv(): Record<string, string> {\n const result: Record<string, string> = {};\n try {\n const raw = fs.readFileSync(ENV_PATH, 'utf-8');\n for (const line of raw.split('\\n')) {\n const m = line.match(/^([A-Z_]+)=(.*)/);\n if (m) result[m[1]] = m[2].trim();\n }\n } catch {}\n return result;\n}\n\nfunction writeEnv(updates: Record<string, string>): void {\n let raw = '';\n try { raw = fs.readFileSync(ENV_PATH, 'utf-8'); } catch { raw = ''; }\n for (const [k, v] of Object.entries(updates)) {\n const re = new RegExp(`^${k}=.*`, 'm');\n if (re.test(raw)) raw = raw.replace(re, `${k}=${v}`);\n else raw += `\\n${k}=${v}`;\n }\n fs.writeFileSync(ENV_PATH, raw, 'utf-8');\n}\n\nexport async function setupCommand(): Promise<void> {\n ensureEnvExists();\n\n const env = readEnv();\n\n header('Antigravity Setup Wizard');\n console.log(` ${chalk.dim(\"Let's configure your proxy in a few steps.\")}\\n`);\n\n const existingKeys = Object.keys(env).filter(k => k.includes('API_KEY') && env[k]);\n if (existingKeys.length > 0) {\n section('Existing Configuration');\n for (const k of existingKeys) {\n console.log(` ${chalk.cyan(k)}${chalk.dim('=')}${maskKey(env[k])}`);\n }\n console.log('');\n const keep = await confirm('Keep existing configuration?', true);\n if (!keep) {\n console.log(` ${info('Starting fresh')}\\n`);\n } else {\n console.log(` ${ok('Preserving existing config')}\\n`);\n }\n }\n\n section('Step 1: Choose Provider');\n const providerChoices = PROVIDERS.map(p => ({ name: p.name, value: p.id }));\n const providerId = await select('Select your LLM provider:', providerChoices);\n const provider = PROVIDERS.find(p => p.id === providerId)!;\n console.log(` ${arrow(`Selected: ${chalk.bold(provider.name)}`)}\\n`);\n\n section('Step 2: API Key');\n let apiKey = '';\n if (provider.envKey) {\n const existingKey = env[provider.envKey] || '';\n if (existingKey && existingKey !== `sk-...` && !existingKey.startsWith('sk-...')) {\n console.log(` ${info(`Existing key: ${maskKey(existingKey)}`)}`);\n const keep = await confirm('Keep existing key?', true);\n if (keep) {\n apiKey = existingKey;\n console.log(` ${ok('Keeping existing key')}\\n`);\n }\n }\n if (!apiKey) {\n apiKey = await prompt(`Enter your ${provider.name} API key:`);\n if (apiKey) {\n console.log(` ${arrow(`Key: ${maskKey(apiKey)}`)}\\n`);\n } else {\n console.log(` ${warn('Skipped — set it later from the dashboard Config tab')}\\n`);\n }\n }\n }\n\n section('Step 3: Proxy Port');\n const currentPort = env['PROXY_PORT'] || '443';\n const portChoices = [\n { name: `443 (default, requires admin/root)`, value: '443' },\n { name: `8443 (no admin needed)`, value: '8443' },\n ];\n const defaultPort = currentPort === '8443' ? '8443' : '443';\n const proxyPort = await select(`Select proxy port [current: ${currentPort}]:`, portChoices);\n console.log(` ${arrow(`Port: ${chalk.bold(proxyPort)}`)}\\n`);\n\n section('Step 4: Context Mode');\n const currentMode = env['CONTEXT_STRIP_MODE'] || 'passthrough';\n const contextChoices = [\n { name: `lite (recommended) — compressed context, ~66% fewer tokens`, value: 'lite' },\n { name: `strip — remove skills/plugins, inject full agent-context.md`, value: 'strip' },\n { name: `passthrough — send full Antigravity context unchanged`, value: 'passthrough' },\n ];\n const contextMode = await select(`Context strip mode [current: ${currentMode}]:`, contextChoices);\n console.log(` ${arrow(`Mode: ${chalk.bold(contextMode)}`)}\\n`);\n\n section('Step 5: Certificate Trust');\n const trustCerts = await confirm('Auto-trust TLS certificate on this machine?', true);\n console.log(` ${trustCerts ? ok('Will trust certificates') : warn('Will skip certificate trust')}\\n`);\n\n section('Step 6: Dashboard Auth');\n const existingUser = env['DASHBOARD_USER'] || '';\n if (existingUser) {\n console.log(` ${info(`Existing auth user: ${existingUser}`)}`);\n const keep = await confirm('Keep existing auth?', true);\n if (keep) {\n console.log(` ${ok('Keeping existing auth')}\\n`);\n } else {\n const dashUser = await prompt('Username:', existingUser);\n const dashPass = await prompt('Password:');\n if (dashUser && dashPass) {\n writeEnv({\n 'DASHBOARD_USER': dashUser,\n 'DASHBOARD_PASSWORD': dashPass,\n 'PROVIDER_PRIORITY': providerId,\n ...(apiKey && provider.envKey ? { [provider.envKey]: apiKey } : {}),\n 'PROXY_PORT': proxyPort,\n 'CONTEXT_STRIP_MODE': contextMode,\n });\n }\n }\n if (keep) {\n writeEnv({\n 'PROVIDER_PRIORITY': providerId,\n ...(apiKey && provider.envKey ? { [provider.envKey]: apiKey } : {}),\n 'PROXY_PORT': proxyPort,\n 'CONTEXT_STRIP_MODE': contextMode,\n });\n }\n } else {\n const enableAuth = await confirm('Enable dashboard authentication?', false);\n let dashUser = '';\n let dashPass = '';\n if (enableAuth) {\n dashUser = await prompt('Username:');\n dashPass = await prompt('Password:');\n }\n writeEnv({\n 'PROVIDER_PRIORITY': providerId,\n ...(apiKey && provider.envKey ? { [provider.envKey]: apiKey } : {}),\n 'PROXY_PORT': proxyPort,\n 'CONTEXT_STRIP_MODE': contextMode,\n 'DASHBOARD_USER': dashUser,\n 'DASHBOARD_PASSWORD': dashPass,\n });\n }\n\n divider();\n console.log(` ${ok('Configuration saved!')}`);\n console.log(` ${info(`File: ${chalk.dim(ENV_PATH)}`)}\\n`);\n\n const startNow = await confirm('Start the proxy now?', true);\n if (startNow) {\n console.log('');\n const { startCommand } = await import('./start.js');\n await startCommand({ port: proxyPort, browser: true, trustCert: trustCerts });\n } else {\n console.log(` ${arrow('Run `antigravity start` when ready.')}`);\n console.log(` ${arrow('Run `antigravity start --trust-cert` to auto-trust the TLS cert.')}`);\n console.log('');\n }\n}\n"}}}} |