import{loadContext}from"#context/container.js";import{ContextKey}from"#context/key.js";const RESERVED_STATE_NAME_PREFIX=`eve.`;function defineState(n,r){if(n.startsWith(RESERVED_STATE_NAME_PREFIX))throw Error(`defineState() name "${n}" uses the reserved "${RESERVED_STATE_NAME_PREFIX}" prefix, which Eve reserves for its own framework context keys (e.g. "eve.channel", "eve.bundle"). Colliding with one silently corrupts context serialization. Use your own namespace, e.g. "my-agent.${n.slice(4)}".`);let i=new ContextKey(n);return{get(){return loadContext().ensure(i,r)},update(e){let t=loadContext(),n=t.ensure(i,r);t.set(i,e(n))}}}export{defineState};