UNPKG

@astrasyncai/sdk

Version:

Universal SDK for registering AI agents with AstraSync

121 lines 4.83 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const fs_1 = require("fs"); const __1 = require(".."); const program = new commander_1.Command(); program .name('astrasync') .description('AstraSync AI Agent Registration CLI') .version('0.1.0'); program .command('register <file-or-json>') .description('Register an AI agent with AstraSync') .option('-e, --email <email>', 'Developer email (overrides env)') .option('-o, --output <file>', 'Save results to file') .action(async (input, options) => { const spinner = (0, ora_1.default)('Initializing AstraSync...').start(); try { const email = options.email || process.env.ASTRASYNC_EMAIL; if (!email) { spinner.fail(chalk_1.default.red('Email required. Use --email or set ASTRASYNC_EMAIL')); process.exit(1); } // Parse input let agentData; try { // Try as file first const content = (0, fs_1.readFileSync)(input, 'utf-8'); agentData = input.endsWith('.json') ? JSON.parse(content) : input; } catch { // Try as inline JSON agentData = JSON.parse(input); } spinner.text = 'Detecting agent format...'; const client = new __1.AstraSync({ developerEmail: email }); spinner.text = 'Registering with AstraSync...'; const result = await client.register(agentData); spinner.succeed(chalk_1.default.green('✅ Registration complete!')); console.log('\n' + chalk_1.default.cyan('Registration Details:')); console.log(chalk_1.default.gray('─'.repeat(40))); console.log(`${chalk_1.default.bold('Agent ID:')} ${result.agentId}`); console.log(`${chalk_1.default.bold('Status:')} ${result.status}`); console.log(`${chalk_1.default.bold('Trust Score:')} ${result.trustScore}`); console.log(`${chalk_1.default.bold('Format Detected:')} ${result.detectedFormat}`); if (options.output) { (0, fs_1.writeFileSync)(options.output, JSON.stringify(result, null, 2)); console.log(`\n${chalk_1.default.green('✅')} Results saved to ${options.output}`); } } catch (error) { spinner.fail(chalk_1.default.red(`Error: ${error.message}`)); process.exit(1); } }); program .command('verify <agentId>') .description('Verify an agent exists') .option('-e, --email <email>', 'Developer email') .action(async (agentId, options) => { const spinner = (0, ora_1.default)('Verifying agent...').start(); try { const email = options.email || process.env.ASTRASYNC_EMAIL || 'verify@astrasync.ai'; const client = new __1.AstraSync({ developerEmail: email }); const exists = await client.verify(agentId); if (exists) { spinner.succeed(chalk_1.default.green(`✅ Agent ${agentId} is registered`)); } else { spinner.fail(chalk_1.default.yellow(`⚠️ Agent ${agentId} not found`)); } } catch (error) { spinner.fail(chalk_1.default.red(`Error: ${error.message}`)); process.exit(1); } }); program .command('detect <file>') .description('Detect agent format without registering') .action(async (file) => { try { const content = (0, fs_1.readFileSync)(file, 'utf-8'); const data = JSON.parse(content); const client = new __1.AstraSync({ developerEmail: 'detect@astrasync.ai' }); const format = client.detect(data); console.log(chalk_1.default.cyan(`Detected format: ${chalk_1.default.bold(format)}`)); } catch (error) { console.error(chalk_1.default.red(`Error: ${error.message}`)); process.exit(1); } }); program .command('health') .description('Check AstraSync API health') .action(async () => { const spinner = (0, ora_1.default)('Checking API health...').start(); try { const client = new __1.AstraSync({ developerEmail: 'health@astrasync.ai' }); const healthy = await client.health(); if (healthy) { spinner.succeed(chalk_1.default.green('✅ AstraSync API is healthy')); } else { spinner.fail(chalk_1.default.red('❌ AstraSync API is down')); } } catch (error) { spinner.fail(chalk_1.default.red('❌ Could not reach AstraSync API')); process.exit(1); } }); program.parse(); //# sourceMappingURL=index.js.map