UNPKG

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

105 lines (88 loc) • 3.68 kB
/** * Account migration command handler */ import { makeClient } from '../../api.js'; import { migrateAccount } from '../../sync/migrate.js'; import { getValidAccessToken } from '../../auth.js'; import { getCustomer } from '../../customer.js'; import type { MultiCustomerConfig, CliArgs } from '../../types.js'; export async function handleMigrateAccountCommand( customerConfig: MultiCustomerConfig, args: CliArgs, verbose: boolean ): Promise<void> { // Get source and destination customer IDNs const sourceIdn = args.source as string | undefined; const destIdn = args.dest as string | undefined; if (!sourceIdn || !destIdn) { console.error('āŒ Usage: newo migrate-account --source <sourceIdn> --dest <destIdn>'); console.error('Example: newo migrate-account --source NEWO_bb5lmJjg --dest NEq9OCwSXw'); process.exit(1); } const sourceCustomer = getCustomer(customerConfig, sourceIdn); const destCustomer = getCustomer(customerConfig, destIdn); if (!sourceCustomer) { console.error(`āŒ Source customer ${sourceIdn} not found in configuration`); process.exit(1); } if (!destCustomer) { console.error(`āŒ Destination customer ${destIdn} not found in configuration`); process.exit(1); } console.log('\nšŸ”„ Account Migration'); console.log(`Source: ${sourceIdn}`); console.log(`Destination: ${destIdn}`); console.log('\nāš ļø This will copy ALL data from source to destination'); console.log('āš ļø Source account will NOT be modified (read-only)'); // Confirm migration if (!args.yes && !args.y) { const readline = await import('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const answer = await new Promise<string>((resolve) => { rl.question('\nProceed with migration? (yes/NO): ', resolve); }); rl.close(); if (answer.toLowerCase() !== 'yes') { console.log('āŒ Migration cancelled'); return; } } // Authenticate const sourceToken = await getValidAccessToken(sourceCustomer); const destToken = await getValidAccessToken(destCustomer); const sourceClient = await makeClient(verbose, sourceToken); const destClient = await makeClient(verbose, destToken); // Run migration const result = await migrateAccount({ sourceCustomer, destCustomer, sourceClient, destClient, verbose }); // Print summary console.log('\nšŸ“Š MIGRATION SUMMARY\n'); console.log(`Projects created: ${result.projectsCreated}`); console.log(`Agents created: ${result.agentsCreated}`); console.log(`Flows created: ${result.flowsCreated}`); console.log(`Skills created: ${result.skillsCreated}`); console.log(`Attributes migrated: ${result.attributesMigrated}`); console.log(`Personas created: ${result.personasCreated}`); console.log(`AKB articles imported: ${result.articlesImported}`); console.log(`Connectors created: ${result.connectorsCreated}`); console.log(`Webhooks created: ${result.webhooksCreated}`); if (result.errors.length > 0) { console.log(`\nāš ļø Errors: ${result.errors.length}`); result.errors.forEach(err => console.error(` - ${err}`)); } console.log(`\n${result.success ? 'āœ… Migration completed successfully!' : 'āŒ Migration completed with errors'}\n`); if (result.success) { console.log('šŸ“‹ Next steps:'); console.log(` 1. Push skill content: npx newo push --customer ${destIdn}`); console.log(` 2. Verify migration: npx newo verify --source ${sourceIdn} --dest ${destIdn}`); console.log(` 3. Test agent: npx newo sandbox "test message" --customer ${destIdn}\n`); } }