UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

22 lines (21 loc) • 1.11 kB
//#region extensions/file-transfer/src/shared/file-create-protocol.ts /** Binary messages are small even when an admitted attachment exceeds an inline RPC. */ const FILE_CREATE_CHUNK_BYTES = 1048576; const FILE_CREATE_DEFAULT_MAX_BYTES = 52428800; function readFileCreateMetadata(e, t) { const n = e.sizeBytes; const r = e.maxBytes ?? FILE_CREATE_DEFAULT_MAX_BYTES; const i = e.expectedSha256; if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 0) throw new Error("file.create sizeBytes must be a non-negative safe integer"); if (typeof r !== "number" || !Number.isSafeInteger(r) || r < 0) throw new Error("file.create maxBytes must be a non-negative safe integer"); const a = t === void 0 ? r : Math.min(r, t); if (n > a) throw new Error("file.create sizeBytes exceeds the authorized byte limit"); if (typeof i !== "string" || !/^[a-fA-F0-9]{64}$/u.test(i)) throw new Error("file.create expectedSha256 must be a SHA-256 digest"); return { sizeBytes: n, maxBytes: a, expectedSha256: i.toLowerCase() }; } //#endregion export { readFileCreateMetadata as n, FILE_CREATE_CHUNK_BYTES as t };