UNPKG

eve

Version:

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

1 lines 3.02 kB
import{__toESM}from"../../_virtual/_rolldown/runtime.js";import{require_picocolors}from"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js";import{join}from"node:path";import{discoverAgent}from"#discover/discover-agent.js";import{formatLanguageModelGatewayId}from"#internal/runtime-model.js";import{createCompiledRuntimeModelCatalogLoader}from"#compiler/model-catalog.js";import{createStaticSourceChange}from"#source-change/static-source-change.js";var import_picocolors=__toESM(require_picocolors(),1);function formatApplyModelSettingsOutcome(e){return e.kind===`rejected`?e.message:e.kind===`unchanged`?`Model settings are already up to date.`:e.changed.length===1&&e.changed[0]===`model`&&e.model!==void 0?`Model changed to ${import_picocolors.default.bold(e.model)}. Live on your next prompt.`:`Model settings updated: ${e.changed.map(t=>t===`model`?`model ${e.model??`updated`}`:t===`reasoning`?`reasoning ${e.reasoning??`provider default`}`:`Fast mode ${e.fastMode?`on`:`off`}`).join(`, `)}. Live on your next prompt.`}function formatApplyModelOutcome(e){switch(e.kind){case`changed`:return`Model changed to ${import_picocolors.default.bold(e.to)}. Live on your next prompt.`;case`unchanged`:return`Model is already \`${e.model}\`.`;case`rejected`:return e.message}}async function changeAgentModelSettings(e){let{appRoot:t,patch:r}=e;if(r.model.kind===`set`){let e=await validateModelSlug(t,r.model.value);if(e!==null)return{kind:`rejected`,message:e}}let{manifest:i}=await discoverAgent({agentRoot:join(t,`agent`),appRoot:t}),a=await createStaticSourceChange(i).updateModelSettings(r);if(a.kind===`bail`)return{kind:`rejected`,message:`Couldn't edit ${a.at.logicalPath}: ${a.reason}. Change the model settings by hand.`};if(a.changed.length===0)return{kind:`unchanged`};let o={kind:`changed`,changed:a.changed};return r.model.kind===`set`&&(o.model=r.model.value),r.reasoning.kind!==`keep`&&(o.reasoning=r.reasoning.kind===`set`?r.reasoning.value:null),r.gatewayServiceTier.kind!==`keep`&&(o.fastMode=r.gatewayServiceTier.kind===`set`),o}async function changeAgentModel(e){let{appRoot:t,slug:r}=e,i=await validateModelSlug(t,r);if(i!==null)return{kind:`rejected`,message:i};let{manifest:a}=await discoverAgent({agentRoot:join(t,`agent`),appRoot:t}),o=await createStaticSourceChange(a).updateModelName(r);return o.kind===`bail`?{kind:`rejected`,message:`Couldn't edit ${o.at.logicalPath}: ${o.reason}. Change \`model\` by hand.`}:o.from===o.to?{kind:`unchanged`,model:o.to}:{kind:`changed`,to:o.to}}async function validateModelSlug(e,t){if(!t.includes(`/`))return`\`${t}\` isn't a provider/model id (e.g. anthropic/claude-sonnet-5).`;let n=createCompiledRuntimeModelCatalogLoader(e);try{if(await n.getModelLimits(formatLanguageModelGatewayId(t))===null)return`I couldn't confirm \`${t}\` in the AI Gateway model catalog, so I didn't change agent.ts.`}catch{return null}return null}export{changeAgentModel,changeAgentModelSettings,formatApplyModelOutcome,formatApplyModelSettingsOutcome};