newo
Version:
NEWO CLI: Professional command-line tool with modular architecture for NEWO AI Agent development. Features account migration, integration management, webhook automation, AKB knowledge base, project attributes, sandbox testing, IDN-based file management, r
62 lines ⢠2.75 kB
JavaScript
/**
* Import AKB command handler
*/
import path from 'path';
import { makeClient, importAkbArticle } from '../../api.js';
import { parseAkbFile, prepareArticlesForImport } from '../../akb.js';
import { getValidAccessToken } from '../../auth.js';
import { requireSingleCustomer } from '../customer-selection.js';
export async function handleImportAkbCommand(customerConfig, args, verbose) {
const selectedCustomer = requireSingleCustomer(customerConfig, args.customer);
const akbFile = args._[1];
const personaId = args._[2];
if (!akbFile || !personaId) {
console.error('Usage: newo import-akb <file> <persona_id>');
console.error('Example: newo import-akb akb.txt da4550db-2b95-4500-91ff-fb4b60fe7be9');
process.exit(1);
}
const filePath = path.resolve(akbFile);
const accessToken = await getValidAccessToken(selectedCustomer);
const client = await makeClient(verbose, accessToken);
try {
if (verbose)
console.log(`š Parsing AKB file: ${filePath}`);
const articles = await parseAkbFile(filePath);
console.log(`ā Parsed ${articles.length} articles from ${akbFile}`);
if (verbose)
console.log(`š§ Preparing articles for persona: ${personaId}`);
const preparedArticles = prepareArticlesForImport(articles, personaId);
let successCount = 0;
let errorCount = 0;
console.log(`š¤ Importing ${preparedArticles.length} articles...`);
for (const [index, article] of preparedArticles.entries()) {
try {
if (verbose) {
console.log(` [${index + 1}/${preparedArticles.length}] Importing ${article.topic_name}...`);
}
await importAkbArticle(client, article);
successCount++;
if (!verbose)
process.stdout.write('.');
}
catch (error) {
errorCount++;
const errorMessage = error instanceof Error && 'response' in error
? error?.response?.data
: error instanceof Error
? error.message
: String(error);
console.error(`\nā Failed to import ${article.topic_name}:`, errorMessage);
}
}
if (!verbose)
console.log(''); // new line after dots
console.log(`ā
Import complete: ${successCount} successful, ${errorCount} failed`);
}
catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error('ā AKB import failed:', message);
process.exit(1);
}
}
//# sourceMappingURL=import-akb.js.map