UNPKG

eve

Version:

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

1 lines 1.36 kB
import{join}from"node:path";import{existsSync,readdirSync,statSync}from"node:fs";const INSTRUMENTATION_EXTENSIONS=[`.ts`,`.mts`,`.js`,`.mjs`],INSTRUMENTATION_DIRECTORY=`instrumentation`;function resolveInstrumentationLayout(e){let t=findRemovedInstrumentationFile(e.agentRoot),n=join(e.agentRoot,INSTRUMENTATION_DIRECTORY),r=existsSync(n)&&statSync(n).isDirectory();if(t!==void 0)throw Error(`Found removed instrumentation file "${t}". Move it into the "${INSTRUMENTATION_DIRECTORY}/" directory as one file per provider. See the instrumentation migration guide.`);return r?{kind:`directory`,modulePathsBySlot:collectInstrumentationProviderModules(n)}:{kind:`directory`,modulePathsBySlot:{}}}function collectInstrumentationProviderModules(e){let t=new Map;for(let n of readdirSync(e,{withFileTypes:!0})){if(!n.isFile())continue;let r=INSTRUMENTATION_EXTENSIONS.find(e=>n.name.endsWith(e));if(r===void 0)continue;let i=n.name.slice(0,-r.length);if(i!==``){if(t.get(i)!==void 0)throw Error(`Two files declare the "${i}" instrumentation provider in "${e}". Keep one of them.`);t.set(i,join(e,n.name))}}return Object.fromEntries([...t].sort(([e],[t])=>e.localeCompare(t)))}function findRemovedInstrumentationFile(e){for(let t of INSTRUMENTATION_EXTENSIONS){let n=join(e,`${INSTRUMENTATION_DIRECTORY}${t}`);if(existsSync(n))return n}}export{resolveInstrumentationLayout};