@meshcore/cli
Version:
Official CLI for managing AI agents in MeshCore.ai with LLM-powered metadata extraction
115 lines • 5.26 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHealthCommand = createHealthCommand;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const cli_table3_1 = __importDefault(require("cli-table3"));
const api_1 = require("../services/api");
const config_1 = require("../services/config");
function createHealthCommand() {
const health = new commander_1.Command('health');
health.description('Check agent health status');
health
.command('check <id>')
.description('Check health of a specific agent')
.option('-j, --json', 'Output as JSON')
.action(async (id, options) => {
const config = config_1.ConfigService.getInstance();
const api = api_1.ApiService.getInstance();
if (!config.isAuthenticated()) {
console.error(chalk_1.default.red('Error: Not authenticated. Run "mesh auth login" first.'));
process.exit(1);
}
const spinner = (0, ora_1.default)('Checking agent health...').start();
try {
const health = await api.checkAgentHealth(id);
spinner.stop();
if (options.json) {
console.log(JSON.stringify(health, null, 2));
}
else {
const statusColor = health.status === 'healthy' ? chalk_1.default.green : chalk_1.default.red;
const statusIcon = health.status === 'healthy' ? '✓' : '✗';
console.log(chalk_1.default.cyan('\n=== Agent Health Check ===\n'));
console.log(`Agent ID: ${chalk_1.default.white(health.agentId)}`);
console.log(`Status: ${statusColor(`${statusIcon} ${health.status.toUpperCase()}`)}`);
if (health.message) {
console.log(`Message: ${chalk_1.default.white(health.message)}`);
}
console.log(`Timestamp: ${chalk_1.default.white(new Date(health.timestamp).toLocaleString())}`);
}
}
catch (error) {
spinner.fail('Failed to check agent health');
console.error(chalk_1.default.red(`Error: ${error.message}`));
process.exit(1);
}
});
health
.command('check-all')
.description('Check health of all your agents')
.option('-j, --json', 'Output as JSON')
.action(async (options) => {
const config = config_1.ConfigService.getInstance();
const api = api_1.ApiService.getInstance();
if (!config.isAuthenticated()) {
console.error(chalk_1.default.red('Error: Not authenticated. Run "mesh auth login" first.'));
process.exit(1);
}
const spinner = (0, ora_1.default)('Checking all agents health...').start();
try {
const healthChecks = await api.checkAllAgentsHealth();
spinner.stop();
if (healthChecks.length === 0) {
console.log(chalk_1.default.yellow('No agents to check'));
return;
}
if (options.json) {
console.log(JSON.stringify(healthChecks, null, 2));
}
else {
const table = new cli_table3_1.default({
head: ['Agent ID', 'Status', 'Message', 'Timestamp'],
style: { head: ['cyan'] }
});
let healthyCount = 0;
let unhealthyCount = 0;
healthChecks.forEach(health => {
const statusColor = health.status === 'healthy' ? chalk_1.default.green : chalk_1.default.red;
const statusIcon = health.status === 'healthy' ? '✓' : '✗';
if (health.status === 'healthy') {
healthyCount++;
}
else {
unhealthyCount++;
}
table.push([
health.agentId.substring(0, 8) + '...',
statusColor(`${statusIcon} ${health.status}`),
health.message || '-',
new Date(health.timestamp).toLocaleString()
]);
});
console.log(chalk_1.default.cyan('\n=== All Agents Health Status ===\n'));
console.log(table.toString());
console.log(chalk_1.default.gray(`\nSummary:`));
console.log(chalk_1.default.green(` Healthy: ${healthyCount}`));
if (unhealthyCount > 0) {
console.log(chalk_1.default.red(` Unhealthy: ${unhealthyCount}`));
}
console.log(chalk_1.default.gray(` Total: ${healthChecks.length}`));
}
}
catch (error) {
spinner.fail('Failed to check agents health');
console.error(chalk_1.default.red(`Error: ${error.message}`));
process.exit(1);
}
});
return health;
}
//# sourceMappingURL=health.js.map
;