eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.59 kB
JavaScript
import{expectFunction,expectObjectRecord,expectOnlyKnownKeys}from"#internal/authored-module.js";import{lazyBackend}from"#execution/sandbox/lazy-backend.js";function normalizeSandboxDefinition(n,r){let i=expectObjectRecord(n,r);expectOnlyKnownKeys(i,[`backend`,`bootstrap`,`description`,`onSession`,`revalidationKey`],r);let a={};if(i.backend!==void 0&&(a.backend=expectSandboxBackend(i.backend,r)),i.description!==void 0){if(typeof i.description!=`string`)throw Error(`${r} The "description" field must be a string when set.`);a.description=i.description}if(i.bootstrap!==void 0&&(a.bootstrap=expectFunction(i.bootstrap,r)),i.revalidationKey!==void 0&&(a.revalidationKey=expectFunction(i.revalidationKey,r)),a.bootstrap===void 0&&a.revalidationKey!==void 0)throw Error(`${r} The "revalidationKey" field can only be set when "bootstrap" is set.`);return i.onSession!==void 0&&(a.onSession=expectFunction(i.onSession,r)),a}function expectSandboxBackend(e,t){if(typeof e==`function`)return lazyBackend(e);let r=expectObjectRecord(e,`${t} The "backend" field must be a SandboxBackend value (use docker(), vercel(), or your own factory) or a zero-arg function returning one.`);if(typeof r.name!=`string`||r.name.length===0)throw Error(`${t} The "backend" value must expose a non-empty string "name" identifier.`);if(typeof r.create!=`function`)throw Error(`${t} The "backend" value must expose a "create" function.`);if(r.prewarm!==void 0&&typeof r.prewarm!=`function`)throw Error(`${t} The "backend.prewarm" property must be a function when set.`);return r}export{normalizeSandboxDefinition};