eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.02 kB
JavaScript
import{escapeForQuote,isAstNode,keyMatches,lineAt,parseAgentObject,unwrapExpression}from"./agent-config-ast.js";async function applyModelNameToSource(t,n){let a=await parseAgentObject(t);if(a.kind===`bail`)return a;let o=a.object,s=findStringLiteralProperty(o,`model`);if(s===void 0)return{kind:`bail`,reason:"`model` is absent or is not a string literal (e.g. an env reference, a template, an inlined SDK model, or a defineDynamic() dynamic model)",line:lineAt(t,o.start)};let c=s.value;if(c===n)return{kind:`applied`,from:c,to:n,nextSource:t};let l=s.raw?.[0]===`'`?`'`:`"`,u=`${l}${escapeForQuote(n,l)}${l}`;return{kind:`applied`,from:c,to:n,nextSource:t.slice(0,s.start)+u+t.slice(s.end)}}function findStringLiteralProperty(e,r){for(let i of e.properties){if(i.type!==`Property`||i.computed||!keyMatches(i.key,r))continue;let e=i.value;if(!isAstNode(e))continue;let o=unwrapExpression(e);return o.type===`Literal`&&typeof o.value==`string`&&o.start!==void 0&&o.end!==void 0?o:void 0}}export{applyModelNameToSource};