UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 1.33 kB
const MOUNTED_EXTENSION=Symbol.for(`eve.mounted-extension`),CONFIG_REGISTRY=Symbol.for(`eve.extension-config-registry`),EXT_CONFIG_SCOPE=Symbol.for(`eve.ext-config-scope`);function ambientConfigScope(){let e=globalThis[EXT_CONFIG_SCOPE];return typeof e==`string`&&e.length>0?e:void 0}function configRegistry(){let e=globalThis,n=e[CONFIG_REGISTRY];return n===void 0&&(n=new Map,e[CONFIG_REGISTRY]=n),n}function validateConfig(e,t){if(e===void 0)return{};let n=e[`~standard`].validate(t??{});if(n instanceof Promise)throw Error(`Extension config must validate synchronously; the config schema uses async validation, which is not supported at mount.`);if(n.issues!==void 0){let e=n.issues.map(e=>{let t=e.path?.map(e=>String(typeof e==`object`?e.key:e)).join(`.`);return t!==void 0&&t.length>0?`${t}: ${e.message}`:e.message}).join(`; `);throw Error(`Invalid extension config: ${e}`)}return n.value}function defineExtension(t,n){let r=t?.config,i=n??ambientConfigScope(),handle=(t=>{let n=validateConfig(r,t);return i!==void 0&&i.length>0&&configRegistry().set(i,n),{[MOUNTED_EXTENSION]:!0}});return Object.defineProperty(handle,"schema",{value:r,enumerable:!0}),Object.defineProperty(handle,"config",{enumerable:!0,get(){return(i===void 0?void 0:configRegistry().get(i))??validateConfig(r,{})}}),handle}export{defineExtension};