eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
4 lines • 3.96 kB
JavaScript
import{resolvePackageSourceFilePath}from"#internal/application/package.js";import{existsSync}from"node:fs";import{join}from"node:path";import{mkdir,writeFile}from"node:fs/promises";import{createCompiledModuleMapSource}from"#compiler/module-map.js";import{stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";async function writeCompiledArtifactsFiles(t){let a=join(t.outDir,`compiled-artifacts-bootstrap.mjs`),o=join(t.outDir,`compiled-artifacts-instrumentation.mjs`),s=resolveInstrumentationModule(t.compileResult.manifest.agentRoot);await mkdir(t.outDir,{recursive:!0}),await writeFile(a,await createCompiledArtifactsBootstrapSource({compileResult:t.compileResult,installModulePath:resolvePackageSourceFilePath(`src/runtime/loaders/bundled-artifacts.ts`),moduleMapPath:a,metadata:t.compileResult.metadata})),s!==void 0&&await writeFile(o,createInstrumentationPluginSource({agentName:t.compileResult.manifest.config.name,instrumentationPath:s,registerConfigPath:resolvePackageSourceFilePath(`src/harness/instrumentation-config.ts`)}));let c={bootstrapPath:a};return s!==void 0&&(c.instrumentationPluginPath=o,c.instrumentationSourcePath=s),c}const INSTRUMENTATION_EXTENSIONS=[`.ts`,`.mts`,`.js`,`.mjs`];function resolveInstrumentationModule(e){for(let r of INSTRUMENTATION_EXTENSIONS){let i=join(e,`instrumentation${r}`);if(existsSync(i))return i}}function stripCompiledModuleMapExports(e){return e.replace(/^export const moduleMap = /m,`const moduleMap = `).replace(/\nexport default moduleMap;\n?$/,`
`)}async function createCompiledArtifactsBootstrapSource(e){let t=e.compileResult.manifest.config.experimental?.workflow?.world,n=stripCompiledModuleMapExports(createCompiledModuleMapSource({importSpecifierStyle:`absolute`,manifest:e.compileResult.manifest,moduleMapPath:e.moduleMapPath})).trim();return[`// Generated by eve. Do not edit by hand.`,`import { installBundledCompiledArtifacts } from ${stringifyEsmImportSpecifier(e.installModulePath)};`,...createWorkflowWorldBootstrapImports(t),``,n,``,`const metadata = ${JSON.stringify(e.metadata,null,2)};`,``,`const manifest = ${JSON.stringify(e.compileResult.manifest,null,2)};`,``,`export function installCompiledArtifactsBootstrap() {`,` installBundledCompiledArtifacts({`,` manifest,`,` metadata,`,` moduleMap,`,` });`,`}`,``,`installCompiledArtifactsBootstrap();`,...createWorkflowWorldBootstrapBody(t),``,`// Default export satisfies the Nitro plugin contract so this file`,`// can be used directly as a Nitro plugin without a separate wrapper.`,`export default function installCompiledArtifactsPlugin() {`,` // Already installed on import above.`,`}`,``,`export async function __eveInstallCompiledArtifactsStep() {`,` "use step";`,` return null;`,`}`,``].join(`
`)}function createWorkflowWorldBootstrapImports(t){return t===void 0?[]:[`import * as workflowWorldModule from ${stringifyEsmImportSpecifier(t)};`,`import { installConfiguredWorkflowWorld } from ${stringifyEsmImportSpecifier(resolvePackageSourceFilePath(`src/internal/workflow/configure-world.ts`))};`]}function createWorkflowWorldBootstrapBody(e){return e===void 0?[]:[``,`await installConfiguredWorkflowWorld({ module: workflowWorldModule });`]}function createInstrumentationPluginSource(e){return[`// Generated by eve. Do not edit by hand.`,`import * as instrumentationModule from ${stringifyEsmImportSpecifier(e.instrumentationPath)};`,`import { registerInstrumentationConfig } from ${stringifyEsmImportSpecifier(e.registerConfigPath)};`,``,`if (instrumentationModule.default != null) {`,` registerInstrumentationConfig(instrumentationModule.default, { agentName: ${JSON.stringify(e.agentName)} });`,`}`,``,`// Default export satisfies the Nitro plugin contract so this file`,`// can be used directly as a Nitro plugin without a separate wrapper.`,`export default function installInstrumentationPlugin() {}`,``].join(`
`)}export{createCompiledArtifactsBootstrapSource,writeCompiledArtifactsFiles};