import{join}from"node:path";import{readFile,rename,writeFile}from"node:fs/promises";import{applyModelNameToSource}from"#source-change/apply-model-name.js";function createStaticSourceChange(e){return{updateModelName:t=>updateAgentModelName(e,t)}}async function updateAgentModelName(n,r){let i=n.configModule;if(i===void 0)return{kind:`bail`,reason:`agent has no agent.ts config module to edit`,at:{logicalPath:`agent.ts`,line:1}};let a=join(n.agentRoot,i.logicalPath),o=await readFile(a,`utf8`),s=applyModelNameToSource(o,r);if(s.kind===`bail`)return{kind:`bail`,reason:s.reason,at:{logicalPath:i.logicalPath,line:s.line}};if(s.nextSource!==o){let e=`${a}.${process.pid}.eve-tmp`;await writeFile(e,s.nextSource,`utf8`),await rename(e,a)}return{kind:`applied`,from:s.from,to:s.to}}export{createStaticSourceChange};