UNPKG

eve

Version:

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

1 lines 1.68 kB
import{createLogger}from"#internal/logging.js";import{join}from"node:path";import{existsSync,readdirSync,statSync}from"node:fs";const INSTRUMENTATION_EXTENSIONS=[`.ts`,`.mts`,`.js`,`.mjs`],INSTRUMENTATION_DIRECTORY=`instrumentation`,PROVIDERS_FLAG=`experimental.instrumentationProviders`,log=createLogger(`internal.instrumentation-layout`);function resolveInstrumentationLayout(e){let t=resolveInstrumentationFile(e.agentRoot),n=join(e.agentRoot,INSTRUMENTATION_DIRECTORY),r=existsSync(n)&&statSync(n).isDirectory();if(!e.providersEnabled)return r&&log.warn(`ignoring instrumentation provider directory because providers are off`,{agentRoot:e.agentRoot,flag:PROVIDERS_FLAG}),t===void 0?void 0:{kind:`file`,modulePath:t};if(t!==void 0)throw Error(`Found "${t}", but \`${PROVIDERS_FLAG}\` is on. Move it into the "${INSTRUMENTATION_DIRECTORY}/" directory as one file per provider.`);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 resolveInstrumentationFile(e){for(let t of INSTRUMENTATION_EXTENSIONS){let n=join(e,`${INSTRUMENTATION_DIRECTORY}${t}`);if(existsSync(n))return n}}export{resolveInstrumentationLayout};