UNPKG

@elevenlabs/convai-cli

Version:

CLI tool to manage ElevenLabs conversational AI agents

151 lines 4.68 kB
"use strict"; /** * Configuration management for CLI * Simple credential storage with keychain support */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.LOCATIONS = void 0; exports.getConfigPath = getConfigPath; exports.loadConfig = loadConfig; exports.saveConfig = saveConfig; exports.getApiKey = getApiKey; exports.setApiKey = setApiKey; exports.removeApiKey = removeApiKey; exports.isLoggedIn = isLoggedIn; exports.getDefaultEnvironment = getDefaultEnvironment; exports.setDefaultEnvironment = setDefaultEnvironment; exports.getResidency = getResidency; exports.setResidency = setResidency; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const os = __importStar(require("os")); const auth_1 = require("./auth"); exports.LOCATIONS = ["us", "global", "eu-residency", "in-residency"]; /** * Get the path to the CLI config file */ function getConfigPath() { const configDir = path.join(os.homedir(), '.convai'); return path.join(configDir, 'config.json'); } /** * Load CLI configuration from file */ async function loadConfig() { const configPath = getConfigPath(); try { if (await fs.pathExists(configPath)) { const configContent = await fs.readFile(configPath, 'utf-8'); return JSON.parse(configContent); } } catch (error) { // If config file is corrupted or unreadable, start fresh console.warn('Warning: Config file corrupted, starting fresh'); } return {}; } /** * Save CLI configuration to file */ async function saveConfig(config) { const configPath = getConfigPath(); const configDir = path.dirname(configPath); // Ensure config directory exists await fs.ensureDir(configDir); // Don't store API key in config file for security const { apiKey, ...configWithoutKey } = config; // Save config with proper formatting and secure permissions await fs.writeFile(configPath, JSON.stringify(configWithoutKey, null, 2), { mode: 0o600, encoding: 'utf-8' }); } /** * Get API key from storage or environment variable */ async function getApiKey() { return await (0, auth_1.retrieveApiKey)(); } /** * Set API key in secure storage */ async function setApiKey(apiKey) { await (0, auth_1.storeApiKey)(apiKey); } /** * Remove API key from storage */ async function removeApiKey() { await (0, auth_1.removeApiKey)(); } /** * Check if user is logged in (has API key) */ async function isLoggedIn() { return await (0, auth_1.hasApiKey)(); } /** * Get default environment from config */ async function getDefaultEnvironment() { const config = await loadConfig(); return config.defaultEnvironment || 'prod'; } /** * Set default environment in config */ async function setDefaultEnvironment(environment) { const config = await loadConfig(); config.defaultEnvironment = environment; await saveConfig(config); } /** * Get residency from config */ async function getResidency() { const config = await loadConfig(); return config.residency || 'global'; } /** * Set residency in config */ async function setResidency(residency) { const config = await loadConfig(); config.residency = residency; await saveConfig(config); } //# sourceMappingURL=config.js.map