@nestbox-ai/cli
Version:
The cli tools that helps developers to build agents
121 lines • 6.22 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerListCommand = registerListCommand;
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const cli_table3_1 = __importDefault(require("cli-table3"));
const project_1 = require("../../utils/project");
const apiUtils_1 = require("./apiUtils");
const statusMapping_1 = require("../../types/statusMapping");
function registerListCommand(computeCommand) {
computeCommand
.command('list')
.description('List all compute instances')
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
.action((options) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
try {
const apis = (0, apiUtils_1.createComputeApis)();
if (!apis) {
return;
}
const { machineInstanceApi, projectsApi } = apis;
// Resolve project using the shared utility
const project = yield (0, project_1.resolveProject)(projectsApi, options);
const spinner = (0, ora_1.default)(`Fetching compute instances for project: ${project.name}`).start();
try {
// Fetch machine instances for the project
const instancesResponse = yield machineInstanceApi.machineInstancesControllerGetMachineInstanceByUserId(project.id, 0, // page
10 // limit
);
spinner.succeed('Successfully retrieved compute instances');
const instances = ((_a = instancesResponse.data) === null || _a === void 0 ? void 0 : _a.machineInstances) || [];
if (instances.length === 0) {
console.log(chalk_1.default.yellow('No compute instances found for this project.'));
return;
}
// Create table for display
const table = new cli_table3_1.default({
head: [
chalk_1.default.white.bold('ID'),
chalk_1.default.white.bold('Name'),
chalk_1.default.white.bold('Status'),
chalk_1.default.white.bold('API Key')
],
style: {
head: [], // Disable the default styling
border: []
}
});
// Add rows to the table
instances.forEach((instance) => {
// Map the status if a mapping exists
const originalStatus = instance.runningStatus || 'unknown';
const displayStatus = statusMapping_1.statusMappings[originalStatus] || originalStatus;
// Color the status based on its mapped value
let statusColor;
switch (displayStatus.toLowerCase()) {
case 'ready':
statusColor = chalk_1.default.green(displayStatus);
break;
case 'failed':
statusColor = chalk_1.default.red(displayStatus);
break;
case 'initializing':
statusColor = chalk_1.default.yellow(displayStatus);
break;
case 'scheduled':
statusColor = chalk_1.default.blue(displayStatus);
break;
case 'deleting':
statusColor = chalk_1.default.red(displayStatus);
break;
default:
statusColor = chalk_1.default.gray(displayStatus);
}
table.push([
instance.id || 'N/A',
instance.instanceName || 'N/A',
statusColor,
instance.instanceApiKey || 'N/A'
]);
});
// Display the table
console.log(table.toString());
}
catch (error) {
spinner.fail('Failed to retrieve compute instances');
if (error.response && error.response.status === 401) {
console.error(chalk_1.default.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
}
else if (error.response) {
console.error(chalk_1.default.red('API Error:'), ((_b = error.response.data) === null || _b === void 0 ? void 0 : _b.message) || 'Unknown error');
}
else {
console.error(chalk_1.default.red('Error:'), error.message || 'Unknown error');
}
}
}
catch (error) {
if (error.response && error.response.status === 401) {
console.error(chalk_1.default.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
}
else {
console.error(chalk_1.default.red('Error:'), error.message || 'Unknown error');
}
}
}));
}
//# sourceMappingURL=list.js.map