eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.07 kB
JavaScript
import{isNonEmptyString,isObject}from"#shared/guards.js";const SESSION_TASKS_STATE_KEY=`eve.tasks`,SESSION_TASKS_STATE_VERSION=2;function getTaskCohortId(e){return e.cohortId??e.taskId}function getSessionTaskCohorts(e){let t=new Map,n=e?.[SESSION_TASKS_STATE_KEY];if(n===void 0)return t;if(!isObject(n)||n.version!==2)throw Error(`Unsupported task index version under session state key "${SESSION_TASKS_STATE_KEY}".`);if(!Array.isArray(n.tasks))throw Error(`Corrupt task index under session state key "${SESSION_TASKS_STATE_KEY}": expected tasks array.`);for(let e of n.tasks){if(!isObject(e)||!isNonEmptyString(e.taskId)||!isNonEmptyString(e.createdByTurnId)||e.cohortId!==void 0&&!isNonEmptyString(e.cohortId)||t.has(e.taskId))throw Error(`Corrupt task index under session state key "${SESSION_TASKS_STATE_KEY}": invalid task cohort identity.`);t.set(e.taskId,{cohortId:getTaskCohortId({taskId:e.taskId,cohortId:e.cohortId}),settled:e.terminalView!==void 0})}return t}export{SESSION_TASKS_STATE_KEY,SESSION_TASKS_STATE_VERSION,getSessionTaskCohorts,getTaskCohortId};