eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.67 kB
JavaScript
const SANDBOX_URL_SCHEME=`eve-sandbox:`,PATH_QUERY_KEY=`path`,SIZE_QUERY_KEY=`size`,TYPE_QUERY_KEY=`type`;function isValidSize(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=0}function encodeSandboxRef(t){if(typeof t.path!=`string`||t.path.length===0)throw RangeError(`SandboxRef.path must be a non-empty string.`);if(!isValidSize(t.size))throw RangeError(`SandboxRef.size must be a non-negative integer. Received: ${String(t.size)}.`);if(typeof t.mediaType!=`string`||t.mediaType.length===0)throw RangeError(`SandboxRef.mediaType must be a non-empty string.`);let n=new URL(SANDBOX_URL_SCHEME);return n.searchParams.set(PATH_QUERY_KEY,t.path),n.searchParams.set(SIZE_QUERY_KEY,String(t.size)),n.searchParams.set(TYPE_QUERY_KEY,t.mediaType),n}function decodeSandboxRef(t){let n=t instanceof URL?t:new URL(t);if(n.protocol!==`eve-sandbox:`)throw Error(`SandboxRef URL must use scheme "${SANDBOX_URL_SCHEME}". Got: "${n.protocol}".`);let r=n.searchParams.get(PATH_QUERY_KEY);if(r===null||r===``)throw Error(`SandboxRef URL is missing the required "path" query param.`);let i=n.searchParams.get(SIZE_QUERY_KEY);if(i===null||i===``)throw Error(`SandboxRef URL is missing the required "size" query param.`);let a=Number(i);if(!isValidSize(a))throw Error(`SandboxRef URL "size" must be a non-negative integer. Got: ${JSON.stringify(i)}.`);let o=n.searchParams.get(TYPE_QUERY_KEY);if(o===null||o===``)throw Error(`SandboxRef URL is missing the required "type" query param.`);return{mediaType:o,path:r,size:a}}function isSandboxRefUrl(e){return e instanceof URL&&e.protocol===`eve-sandbox:`}export{SANDBOX_URL_SCHEME,decodeSandboxRef,encodeSandboxRef,isSandboxRefUrl};