English
core/platform/resources.ts
Generated from the exports of core/platform/resources.ts · npm run docs:gen
What a step, a choice or an executor needs of the machine, written like Kubernetes resources (docs/standards/ resources.md): { cpu: 4, memory: "16Gi", disk: "20Gi", gpu: true, arch: ["arm64"] }, any subset. The server measures the machine read only (Host.machine, server/lib/mode.mjs); missing() says what falls short, and shortText() says it to the player in one line ("Needs 16 GB of memory (this machine: 8 GB)"). A resource the server did not measure is never refused on a guess.
Standards that cite this file: Resources: what a step, a choice or an executor needs of the machine
Exports
Resources interface
Declared needs. cpu: cores (a number, "4" or "500m"); memory and disk: bytes or a quantity ("16Gi", "512Mi", "20G").
ts
interface Resources {
cpu?: number | string;
memory?: number | string;
/** Free disk space on the volume of the player's home. */
disk?: number | string;
/** A GPU the models can use (Apple Silicon's unified memory counts). */
gpu?: boolean;
/** The processor families it runs on. */
arch?: Arch[];
}RESOURCE_KEYS const
ts
const RESOURCE_KEYS = ["cpu", "memory", "disk", "gpu", "arch"] as constResourceKey type
ts
type ResourceKey = (typeof RESOURCE_KEYS)[number];Measured interface
What the server measured (Host.machine): cores, total memory and free disk in bytes, a usable GPU.
ts
interface Measured { cpu?: number; memory?: number; disk?: number; gpu?: boolean }parseBytes function
A quantity in bytes ("16Gi", "20G", "512Mi", 1073741824), or null when malformed.
ts
function parseBytes(q: unknown): number | nullparseCpu function
Cores (4, "4", "2.5", "500m" = half a core), or null when malformed.
ts
function parseCpu(q: unknown): number | nullcheckResources function
The problems of a declared block, each "resources.<key>: …" (rule ids resources.*), empty when valid.
ts
function checkResources(r: unknown): string[]Short interface
One resource that falls short: what is needed, what the machine has (bytes, cores, or the arch).
ts
interface Short { key: ResourceKey; need: number | boolean | Arch[]; have: number | boolean | Arch }MachineSide interface
The machine a check is made against: its arch and its measures.
ts
interface MachineSide { arch?: Arch; machine?: Measured }missing function
What falls short on this machine, in the order cpu, memory, disk, gpu, arch. Unmeasured: never short.
ts
function missing(r: Resources | null | undefined, h: MachineSide | null | undefined): Short[]mergeResources function
The larger of two blocks, key by key (a step and its executor).
ts
function mergeResources(a: Resources | null | undefined, b: Resources | null | undefined): Resources | undefinedshortText function
The one-line reason, in English and French: "Needs 16 GB of memory (this machine: 8 GB)." Null when nothing is short.
ts
function shortText(short: Short[]): TextSMALLEST_MACHINE const
The smallest machine the validators try a choice step on: one core, 1 GB of memory, no free disk, no GPU.
ts
const SMALLEST_MACHINE: Measured