UNPKG

eve

Version:

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

1 lines 2.37 kB
import{stripLogicalPathExtension}from"#discover/filesystem.js";import{normalizeInstructionsDefinition}from"#internal/authored-definition/core.js";import{loadModuleBackedDefinition,requireModuleBackedDefinitionLoadOptions}from"#compiler/normalize-helpers.js";import{ALLOWED_DYNAMIC_INSTRUCTION_EVENTS,assertResolverOnlyDynamicSentinel,isDynamicSentinel}from"#dynamic/definition.js";async function compileInstructionsEntry(e,t,n){if(t.sourceKind===`markdown`){let e=normalizeInstructionsDefinition(t.definition,`Expected the compiled instructions definition at "${t.logicalPath}" to match the public eve shape.`);return{kind:`instructions`,definition:{name:stripLogicalPathExtension(t.logicalPath),logicalPath:t.logicalPath,owner:n.owner,content:e.content,role:e.role,sourceId:t.sourceId,sourceKind:t.sourceKind}}}let r=requireModuleBackedDefinitionLoadOptions(n,t.logicalPath),i=await loadModuleBackedDefinition({binding:r.binding,kind:`instructions`,loadNamespace:r.loadNamespace,source:t});if(isDynamicSentinel(i)){assertResolverOnlyDynamicSentinel(i,`Expected the instructions export "${t.exportName??`default`}" from "${t.logicalPath}" to match the public eve shape.`);let e=Object.keys(i.events),n=e.find(e=>!ALLOWED_DYNAMIC_INSTRUCTION_EVENTS.has(e));if(n!==void 0)throw Error(`Expected the instructions export "${t.exportName??`default`}" from "${t.logicalPath}" to use only "session.started" or "turn.started" events. Unsupported event: "${n}".`);let r=stripLogicalPathExtension(t.logicalPath).replace(/^instructions\//,``);return{kind:`dynamic-instructions`,definition:{eventNames:e,exportName:t.exportName,logicalPath:t.logicalPath,slug:r,sourceId:t.sourceId,sourceKind:`module`}}}let a=normalizeInstructionsDefinition(i,`Expected the instructions export "${t.exportName??`default`}" from "${t.logicalPath}" to match the public eve shape.`);return{kind:`instructions`,definition:{name:stripLogicalPathExtension(t.logicalPath),logicalPath:t.logicalPath,content:a.content,role:a.role,sourceId:t.sourceId,sourceKind:t.sourceKind}}}async function compileInstructions(e,t,n){let r=await compileInstructionsEntry(e,t,n);if(r.kind===`dynamic-instructions`)throw Error(`Expected static instructions from "${t.logicalPath}" but got a dynamic resolver. Use compileInstructionsEntry instead.`);return r.definition}export{compileInstructions,compileInstructionsEntry};