File size: 2,723 Bytes
0722e92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import fs from 'fs';
import path from 'path';
import os from 'os';
import inquirer from 'inquirer';

const CREDS_DIR = path.join(os.homedir(), '.iniclaw');
const CREDS_FILE = path.join(CREDS_DIR, 'credentials.json');

const PROVIDERS = [
  {
    name: 'NVIDIA Nemotron',
    url: 'https://build.nvidia.com/settings/api-keys',
    prefix: 'nvapi-',
    envVar: 'NVIDIA_API_KEY'
  },
  {
    name: 'Groq',
    url: 'https://console.groq.com/keys',
    prefix: 'gsk_',
    envVar: 'GROQ_API_KEY'
  },
  {
    name: 'Google Gemini',
    url: 'https://aistudio.google.com/app/apikey',
    prefix: '',
    envVar: 'GOOGLE_API_KEY'
  },
  {
    name: 'OpenAI',
    url: 'https://platform.openai.com/api-keys',
    prefix: 'sk-',
    envVar: 'OPENAI_API_KEY'
  }
];

async function runSetup() {
  console.log("\nini_claw by Inmodel Labs — Setup Wizard\n");

  const { providerName } = await inquirer.prompt([
    {
      type: 'list',
      name: 'providerName',
      message: 'Choose your AI provider:',
      choices: PROVIDERS.map(p => p.name)
    }
  ]);

  const provider = PROVIDERS.find(p => p.name === providerName);

  console.log(`\nTo get your ${provider.name} API key, visit:`);
  console.log(`\x1b[36m${provider.url}\x1b[0m\n`);

  const { apiKey } = await inquirer.prompt([
    {
      type: 'input',
      name: 'apiKey',
      message: `Paste your ${provider.name} API key:`,
      validate: (input) => {
        if (!input) return 'API key cannot be empty';
        if (provider.prefix && !input.startsWith(provider.prefix)) {
          return `Invalid key format. Should start with "${provider.prefix}"`;
        }
        return true;
      }
    }
  ]);

  // Ensure credentials directory exists
  if (!fs.existsSync(CREDS_DIR)) {
    fs.mkdirSync(CREDS_DIR, { recursive: true, mode: 0o700 });
  }

  // Load existing credentials if any
  let creds = {};
  if (fs.existsSync(CREDS_FILE)) {
    try {
      creds = JSON.parse(fs.readFileSync(CREDS_FILE, 'utf8'));
    } catch (e) {
      // Ignore parse errors, start fresh
    }
  }

  // Save new credential
  creds[provider.envVar] = apiKey;
  // Also set as generic INICLAW_API_KEY for convenience
  creds['INICLAW_API_KEY'] = apiKey;

  fs.writeFileSync(CREDS_FILE, JSON.stringify(creds, null, 2), { mode: 0o600 });

  console.log(`\n\x1b[32mSUCCESS:\x1b[0m Credentials saved to ${CREDS_FILE}`);
  console.log("\nNext steps:");
  console.log("1. Run `iniclaw onboard` to create your first sandbox.");
  console.log("2. Use `iniclaw status` to check your setup.\n");
}

if (import.meta.url === `file://${process.argv[1]}`) {
  runSetup().catch(err => {
    console.error("\nSetup failed:", err.message);
    process.exit(1);
  });
}

export { runSetup };