sesterce-cli
Version:
A powerful command-line interface tool for managing Sesterce Cloud services. Sesterce CLI provides easy access to GPU cloud instances, AI inference services, container registries, and SSH key management directly from your terminal.
185 lines • 12.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAIInferenceInstanceDetailsCommand = createAIInferenceInstanceDetailsCommand;
const get_instance_details_1 = require("@/modules/ai-inference/use-cases/get-instance-details");
const list_instances_1 = require("@/modules/ai-inference/use-cases/list-instances");
const prompts_1 = require("@inquirer/prompts");
const chalk_1 = __importDefault(require("chalk"));
const figlet_1 = __importDefault(require("figlet"));
const getStatusColor = (status) => {
switch (status) {
case "ACTIVE":
return chalk_1.default.hex("#50FA7B"); // Green
case "PENDING":
case "DEPLOYING":
return chalk_1.default.hex("#FFB86C"); // Orange
case "ERROR":
case "FAILED":
return chalk_1.default.hex("#FF5555"); // Red
case "DISABLED":
case "DELETED":
case "DELETING":
return chalk_1.default.hex("#6272A4"); // Gray
case "PARTIALLYDEPLOYED":
return chalk_1.default.hex("#FF79C6"); // Pink
default:
return chalk_1.default.white;
}
};
const printInstance = (instance) => {
return `${instance.name} (${instance.features.join(", ")}) | ${instance.address} | ${instance.status} | ${instance.hourlyPrice.toFixed(2)}`;
};
function createAIInferenceInstanceDetailsCommand(aiInferenceInstanceCommand) {
aiInferenceInstanceCommand
.command("details")
.description("Get details of a launched instance in Sesterce AI Inference")
.option("-i, --instance-id <instanceId>", "The ID of the instance to get details of")
.action(async (args) => {
let instanceId = args.instanceId;
if (!instanceId) {
console.log("Loading inference instances...");
const result = await list_instances_1.listInferenceInstances.execute();
if (result.isLeft()) {
console.error(result.value.message);
return;
}
const instances = result.value;
if (instances.length === 0) {
console.log("No instances found");
return;
}
const instance = await (0, prompts_1.search)({
message: "Select an instance to get details for",
source: async (input) => {
if (!input) {
return instances.map((instance) => ({
name: printInstance(instance),
value: instance,
}));
}
return instances
.filter((instance) => instance.name.toLowerCase().includes(input.toLowerCase()) ||
instance.address
.toLowerCase()
.includes(input.toLowerCase()) ||
instance.features.includes(input.toLowerCase()) ||
instance.status.toLowerCase().includes(input.toLowerCase()) ||
instance.hourlyPrice.toFixed(2).includes(input))
.map((instance) => ({
name: printInstance(instance),
value: instance,
}));
},
});
instanceId = instance._id;
}
const result = await get_instance_details_1.getInstanceDetails.execute(instanceId);
if (result.isLeft()) {
console.error(result.value.message);
return;
}
const instance = result.value;
// Header with instance name
console.log("\n" + "=".repeat(80));
console.log(chalk_1.default.hex("#21C65D")(figlet_1.default.textSync(instance.name, { font: "Standard" })));
console.log("=".repeat(80) + "\n");
// Basic Information Section
console.log(chalk_1.default.hex("#FF6B6B")(chalk_1.default.bold("📋 BASIC INFORMATION")));
console.log(chalk_1.default.hex("#4ECDC4")("┌─" + "─".repeat(78) + "─┐"));
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("ID:")} ${chalk_1.default.white(instance._id)}${" ".repeat(78 - 4 - instance._id.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Name:")} ${chalk_1.default.white(instance.name)}${" ".repeat(78 - 6 - instance.name.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Status:")} ${getStatusColor(instance.status)(instance.status)}${" ".repeat(78 - 8 - instance.status.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Address:")} ${chalk_1.default.cyan(instance.address)}${" ".repeat(78 - 9 - instance.address.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Port:")} ${chalk_1.default.white(instance.containerPort)}${" ".repeat(78 - 5 - instance.containerPort.toString().length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("└─" + "─".repeat(78) + "─┘\n"));
// Features and Pricing Section
console.log(chalk_1.default.hex("#FF6B6B")(chalk_1.default.bold("🚀 FEATURES & PRICING")));
console.log(chalk_1.default.hex("#4ECDC4")("┌─" + "─".repeat(78) + "─┐"));
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Features:")} ${instance.features.map((f) => chalk_1.default.hex("#FFE66D")(f)).join(", ")}${" ".repeat(78 - 10 - instance.features.join(", ").length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Hardware:")} ${chalk_1.default.white(instance.hardwareName)}${" ".repeat(78 - 9 - instance.hardwareName.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Hourly Price:")} ${chalk_1.default.hex("#50FA7B")(`$${instance.hourlyPrice.toFixed(2)}`)}${" ".repeat(78 - 13 - instance.hourlyPrice.toFixed(2).length - 1)}${chalk_1.default.hex("#4ECDC4")("│")}`);
if (instance.description) {
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Description:")} ${chalk_1.default.white(instance.description)}${" ".repeat(78 - 12 - instance.description.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
}
console.log(chalk_1.default.hex("#4ECDC4")("└─" + "─".repeat(78) + "─┘\n"));
// Container Information Section
console.log(chalk_1.default.hex("#FF6B6B")(chalk_1.default.bold("🐳 CONTAINER INFORMATION")));
instance.containers.forEach((container, index) => {
console.log(chalk_1.default.hex("#4ECDC4")("┌─" + "─".repeat(78) + "─┐"));
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold(`Container ${index + 1}:`)}${" ".repeat(78 - 12)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Region ID:")} ${chalk_1.default.white(container.regionId)}${" ".repeat(78 - 11 - container.regionId.toString().length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Scale:")} ${chalk_1.default.white(`${container.scale.min}-${container.scale.max}`)}${" ".repeat(78 - 6 - `${container.scale.min}-${container.scale.max}`.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
// Triggers
const triggers = container.scale.triggers || {};
const triggerEntries = [];
if (triggers.cpu)
triggerEntries.push(`CPU: ${chalk_1.default.yellow(triggers.cpu.threshold + "%")}`);
if (triggers.gpuMemory)
triggerEntries.push(`GPU Memory: ${chalk_1.default.yellow(triggers.gpuMemory.threshold + "%")}`);
if (triggers.gpuUtilization)
triggerEntries.push(`GPU Util: ${chalk_1.default.yellow(triggers.gpuUtilization.threshold + "%")}`);
if (triggers.memory)
triggerEntries.push(`RAM: ${chalk_1.default.yellow(triggers.memory.threshold + "%")}`);
if (triggers.http)
triggerEntries.push(`HTTP: ${chalk_1.default.yellow(triggers.http.rate + "/s (" + triggers.http.window + "s)")}`);
if (triggerEntries.length > 0) {
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` Triggers: ${triggerEntries.join(", ")}${" ".repeat(78 - 10 - triggerEntries.join(", ").length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
}
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Deploy Status:")} ${chalk_1.default.hex("#50FA7B")(`${container.deployStatus.ready}/${container.deployStatus.total}`)}${" ".repeat(78 - 14 - `${container.deployStatus.ready}/${container.deployStatus.total}`.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
if (container.errorMessage) {
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Error:")} ${chalk_1.default.red(container.errorMessage)}${" ".repeat(78 - 6 - container.errorMessage.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
}
console.log(chalk_1.default.hex("#4ECDC4")("└─" + "─".repeat(78) + "─┘"));
});
// Environment Variables Section
if (Object.keys(instance.envs).length > 0) {
console.log(chalk_1.default.hex("#FF6B6B")(chalk_1.default.bold("🔧 ENVIRONMENT VARIABLES")));
console.log(chalk_1.default.hex("#4ECDC4")("┌─" + "─".repeat(78) + "─┐"));
Object.entries(instance.envs).forEach(([key, value]) => {
const displayValue = value.length > 60 ? value.substring(0, 57) + "..." : value;
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold(key)}: ${chalk_1.default.white(displayValue)}${" ".repeat(78 - key.length - 2 - displayValue.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
});
console.log(chalk_1.default.hex("#4ECDC4")("└─" + "─".repeat(78) + "─┘\n"));
}
// Startup Command Section
if (instance.startupCommand) {
console.log(chalk_1.default.hex("#FF6B6B")(chalk_1.default.bold("⚡ STARTUP COMMAND")));
console.log(chalk_1.default.hex("#4ECDC4")("┌─" + "─".repeat(78) + "─┐"));
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.white(instance.startupCommand)}${" ".repeat(78 - instance.startupCommand.length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("└─" + "─".repeat(78) + "─┘\n"));
}
// Timestamps Section
console.log(chalk_1.default.hex("#FF6B6B")(chalk_1.default.bold("⏰ TIMESTAMPS")));
console.log(chalk_1.default.hex("#4ECDC4")("┌─" + "─".repeat(78) + "─┐"));
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Created:")} ${chalk_1.default.white(new Date(instance.createdAt).toLocaleString())}${" ".repeat(78 - 9 - new Date(instance.createdAt).toLocaleString().length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("│") +
` ${chalk_1.default.bold("Updated:")} ${chalk_1.default.white(new Date(instance.updatedAt).toLocaleString())}${" ".repeat(78 - 9 - new Date(instance.updatedAt).toLocaleString().length)}${chalk_1.default.hex("#4ECDC4")("│")}`);
console.log(chalk_1.default.hex("#4ECDC4")("└─" + "─".repeat(78) + "─┘\n"));
// Footer
console.log(chalk_1.default.hex("#21C65D")("=".repeat(80)));
console.log(chalk_1.default.hex("#21C65D")(chalk_1.default.bold("✨ Instance details displayed successfully!")));
console.log(chalk_1.default.hex("#21C65D")("=".repeat(80)) + "\n");
});
}
//# sourceMappingURL=details.js.map