openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
30 lines (29 loc) • 918 B
JavaScript
import { t as parseByteSize } from "./parse-bytes-BaENXJY2.mjs";
//#region src/config/byte-size.ts
/**
* Parse an optional byte-size value from config.
* Accepts non-negative numbers or strings like "2mb".
*/
function parseNonNegativeByteSize(value) {
if (typeof value === "number") {
const int = Math.floor(value);
return Number.isSafeInteger(int) && int >= 0 ? int : null;
}
if (typeof value === "string") {
const trimmed = value.trim();
if (!trimmed) return null;
try {
const bytes = parseByteSize(trimmed, { defaultUnit: "b" });
return bytes >= 0 ? bytes : null;
} catch {
return null;
}
}
return null;
}
/** Validates byte-size strings accepted by agent default byte-threshold config. */
function isValidNonNegativeByteSizeString(value) {
return parseNonNegativeByteSize(value) !== null;
}
//#endregion
export { parseNonNegativeByteSize as n, isValidNonNegativeByteSizeString as t };