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.
80 lines (71 loc) • 2.79 kB
text/typescript
import {
InferenceInstance,
InferenceInstanceFeature,
} from "@/modules/ai-inference/domain/inference-instance";
import { listInferenceInstances } from "@/modules/ai-inference/use-cases/list-instances";
import { startInferenceInstance } from "@/modules/ai-inference/use-cases/start-instance";
import { search } from "@inquirer/prompts";
import { Command } from "commander";
const printInstance = (instance: InferenceInstance) => {
return `${instance.name} (${instance.features.join(", ")}) | ${instance.address} | ${instance.status} | ${instance.hourlyPrice.toFixed(2)}`;
};
export function createAIInferenceInstanceStartCommand(
aiInferenceInstanceCommand: Command
) {
aiInferenceInstanceCommand
.command("start")
.description("Start a launched instance in Sesterce AI Inference")
.option("-i, --instance-id <instanceId>", "The ID of the instance to start")
.action(async (args) => {
let instanceId = args.instanceId;
if (!instanceId) {
console.log("Loading inference instances...");
const result = await 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 search({
message: "Select an instance to start",
source: async (input, { signal }) => {
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() as InferenceInstanceFeature
) ||
instance.status.toLowerCase().includes(input.toLowerCase()) ||
instance.name.toLowerCase().includes(input.toLowerCase()) ||
instance.hourlyPrice.toFixed(2).includes(input)
)
.map((instance) => ({
name: printInstance(instance),
value: instance,
}));
},
});
instanceId = instance._id;
}
const result = await startInferenceInstance.execute(instanceId);
if (result.isLeft()) {
console.error(result.value.message);
return;
}
console.log("Instance started successfully");
});
}