UNPKG

@luxorai/sandbox

Version:

TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud

50 lines • 2.32 kB
import { InvalidResourceConfigError } from "./errors.js"; export const MIN_CPU_CORES = 1; export const MAX_CPU_CORES = 128; export const MIN_CREATE_MEMORY_MB = 256; export const MIN_PROVISION_MEMORY_MB = 512; export const MAX_MEMORY_MB = 524288; export const MIN_DISK_SIZE_GB = 5; export const MAX_DISK_SIZE_GB = 100; /** * Checks create resources against the sandbox API's constraints without issuing a * request. Create applies it to every request; it is exported so callers building a * form can reject one field at a time, omitting the fields they are not checking. */ export function validateCreateResources(resources) { if (resources.cpuCores != null) validateCpuCores(resources.cpuCores); if (resources.memoryMb != null) validateMemoryMb(resources.memoryMb, MIN_CREATE_MEMORY_MB); if (resources.diskSizeGb != null) validateDiskSizeGb(resources.diskSizeGb); } export function validateTemplateResources(resources) { if (!resources) return; if (resources.cpuCores != null && resources.cpuCores !== 0) validateCpuCores(resources.cpuCores); if (resources.memoryMb != null && resources.memoryMb !== 0) validateMemoryMb(resources.memoryMb, MIN_PROVISION_MEMORY_MB); if (resources.diskSizeGb != null && resources.diskSizeGb !== 0) validateDiskSizeGb(resources.diskSizeGb); } function validateCpuCores(cpuCores) { if (Number.isInteger(cpuCores) && cpuCores >= MIN_CPU_CORES && cpuCores <= MAX_CPU_CORES) return; throw new InvalidResourceConfigError(`cpuCores must be between ${MIN_CPU_CORES} and ${MAX_CPU_CORES}`); } function validateMemoryMb(memoryMb, minMemoryMb) { if (!Number.isInteger(memoryMb) || memoryMb < minMemoryMb || memoryMb > MAX_MEMORY_MB) { throw new InvalidResourceConfigError(`memoryMb must be between ${minMemoryMb} and ${MAX_MEMORY_MB}`); } if (memoryMb % 2 !== 0) { throw new InvalidResourceConfigError("memoryMb must be aligned to 2 MiB"); } } function validateDiskSizeGb(diskSizeGb) { if (Number.isInteger(diskSizeGb) && diskSizeGb >= MIN_DISK_SIZE_GB && diskSizeGb <= MAX_DISK_SIZE_GB) return; throw new InvalidResourceConfigError(`diskSizeGb must be between ${MIN_DISK_SIZE_GB} and ${MAX_DISK_SIZE_GB}`); } //# sourceMappingURL=resources.js.map