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.
84 lines • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListGpuCloudOffers = void 0;
const either_1 = require("@/core/logic/either");
const instance_offers_fetch_error_1 = require("./errors/instance-offers-fetch-error");
const gpuPriority = ["B200", "H200", "H100", "MI300X", "A100"];
class ListGpuCloudOffers {
constructor(apiClient) {
this.apiClient = apiClient;
}
initalSortOffers(offers) {
return offers.sort((a, b) => {
var _a, _b, _c, _d;
// Sort by vRAM
if (b.configuration.vRamGB !== a.configuration.vRamGB) {
return b.configuration.vRamGB - a.configuration.vRamGB;
}
// Then by number of GPUs
if (b.gpuCount !== a.gpuCount) {
return b.gpuCount - a.gpuCount;
}
const priceA = ((_a = a.gpuCount) !== null && _a !== void 0 ? _a : 0) > 0
? ((_b = a.hourlyPrice) !== null && _b !== void 0 ? _b : Infinity) / (a.gpuCount || 1)
: Infinity;
const priceB = ((_c = b.gpuCount) !== null && _c !== void 0 ? _c : 0) > 0
? ((_d = b.hourlyPrice) !== null && _d !== void 0 ? _d : Infinity) / (b.gpuCount || 1)
: Infinity;
// Finally by price per GPU
return priceA - priceB;
});
}
groupOffers(offers) {
const groupedOffers = offers.reduce((acc, offer) => {
const key = `${offer.gpuName}-${offer.gpuCount}`;
if (!acc[key]) {
acc[key] = {
offer,
regions: [],
};
}
// Add regions from availability
offer.availability.forEach((availability) => {
var _a;
if (availability.available) {
if (!acc[key].regions.some((region) => region.region === availability.region)) {
acc[key].regions.push({
region: availability.region,
frontendName: availability.name,
countryCode: (_a = availability.countryCode) !== null && _a !== void 0 ? _a : null,
});
}
}
});
return acc;
}, {});
// Group by GPU type
return Object.values(groupedOffers).reduce((acc, groupedOffer) => {
const gpuType = groupedOffer.offer.gpuName;
if (!acc[gpuType]) {
acc[gpuType] = [];
}
acc[gpuType].push(groupedOffer);
return acc;
}, {});
}
sortOffersByPriority(groupedOffers) {
const sortedGpuTypes = gpuPriority.concat(Object.keys(groupedOffers).filter((gpuType) => !gpuPriority.includes(gpuType)));
return sortedGpuTypes.flatMap((gpuType) => groupedOffers[gpuType]);
}
async execute() {
try {
const offers = await this.apiClient.request("/gpu-cloud/instances/offers");
const sortedOffers = this.initalSortOffers(offers !== null && offers !== void 0 ? offers : []);
const groupedOffers = this.groupOffers(sortedOffers);
const sortedOffersByPriority = this.sortOffersByPriority(groupedOffers);
return (0, either_1.right)(sortedOffersByPriority.filter((offer) => offer.regions.length));
}
catch (error) {
return (0, either_1.left)(new instance_offers_fetch_error_1.InstanceOffersFetchError(error instanceof Error ? error.message : "Unexpected error occurred."));
}
}
}
exports.ListGpuCloudOffers = ListGpuCloudOffers;
//# sourceMappingURL=list-instance-offers.js.map