INIclaw / src /setup.js
NitishStark's picture
Upload folder using huggingface_hub
0722e92 verified
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 };