UNPKG

eve

Version:

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

1 lines • 1.8 kB
import"#evals/assertions/collector.js";import"#evals/session-manager.js";import{createScopedAssertions}from"#evals/assertions/scoped.js";import{buildJudgeContext}from"#evals/judge.js";import{EvalRequirementFailed,EvalSkipped}from"#evals/control-flow.js";function createEvalContext(e){let t=e.collector,n=buildJudgeContext({collector:t,getReply:()=>e.manager.lastTurnSession()?.lastTurn?.message??null,getInput:()=>e.manager.lastTurnSession()?.lastInput??``,judge:e.judge,signal:e.signal});return{context:{session:t=>e.manager.session(t),send:(t,n)=>e.manager.send(t,n),context:e.setupContext,signal:e.signal,target:e.target,log:e.log,sleep:t=>sleep(t,e.signal),...createScopedAssertions(t,{timing:`final`,select:e=>e}),check:(e,n)=>recordCheck(t,e,n),require:(e,n)=>requireCheck(t,e,n),skip:n=>{throw n.trim().length===0?Error(`skip() requires a non-empty reason.`):t.hasEntries||e.manager.hasActivity()?Error(`skip() must be called before creating sessions, sending messages, or recording assertions.`):new EvalSkipped(n)},judge:n},collector:t}}async function requireCheck(e,t,n){let r=n.gate(n.threshold);if(!await e.recordRequirement({name:r.name,threshold:r.threshold,score:()=>evaluateAssertion(r,t)}))throw new EvalRequirementFailed;return t}function recordCheck(e,t,n){return e.recordValue({name:n.name,severity:n.severity,threshold:n.threshold,score:()=>evaluateAssertion(n,t)})}async function evaluateAssertion(e,t){return e.evaluate===void 0?{score:await e.score(t)}:await e.evaluate(t)}function sleep(e=1e3,t){if(!Number.isFinite(e)||e<0)throw Error(`sleep() duration must be a non-negative finite number.`);return t?.aborted?Promise.reject(t.reason):new Promise((n,r)=>{let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(t.reason)},{once:!0})})}export{createEvalContext};