eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
4 lines (3 loc) • 2.65 kB
JavaScript
import{markFrameworkStepInput}from"#harness/messages.js";import{getSessionTaskIndex}from"#tasks/session-index.js";import{getTaskCohortId}from"#tasks/session-task-cohorts.js";import{EMPTY_DELIVERY_SENTINEL}from"#shared/empty-delivery.js";const TASK_DELIVERY_CONTEXT_LABEL=`[Task state]`,TASK_DELIVERY_INITIATING_INSTRUCTION=`Background task reporting: launch acknowledgement
The latest ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists background tasks accepted so far from the current turn. They continue independently after this turn.
Continue carrying out the user's request, including starting any remaining background work. When no further tool calls are needed in this turn, send one brief user-facing acknowledgement that the background work has started. Do not wait for results or report results that are not available yet. End the turn after the acknowledgement.`,TASK_DELIVERY_SETTLED_INSTRUCTION=`Background task reporting\nThis turn was triggered by background task activity. The accompanying ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists overlapping background tasks in the same cohort, potentially started across different user turns, all settled, with every available terminal output. Do not reply with ${EMPTY_DELIVERY_SENTINEL}. Send one user-facing response that combines their useful results.`;function getBackgroundTaskDelivery(e){if(typeof e!=`object`||!e)return;let t=e;return t.kind===`deliver`&&typeof t.taskDeliveryId==`string`?e:void 0}function markBackgroundTaskStepInput(e){return e.message===void 0?e:markFrameworkStepInput(e,`execution.background_task`)}function resolveTaskDeliveryContext(e){let t=getSessionTaskIndex(e.state),n=t.find(t=>e.taskDeliveryId.startsWith(`${t.taskId}:`));return n===void 0?void 0:{...projectTaskCohort(t.filter(e=>getTaskCohortId(e)===getTaskCohortId(n))),rootTurnId:n.createdByTurnId}}function resolveInitiatingTaskContext(e){let t=getSessionTaskIndex(e.state).filter(t=>t.createdByTurnId===e.turnId);if(t.some(e=>e.executor!==void 0&&e.terminalView===void 0))return{...projectTaskCohort(t),phase:`initiating`}}function projectTaskCohort(e){let t=e.every(e=>e.terminalView!==void 0),n=e.map(e=>({name:e.metadata.name,output:t?e.terminalView?.lastOutput:void 0,status:e.terminalView?.status??`pending`,taskId:e.taskId}));return{context:`${TASK_DELIVERY_CONTEXT_LABEL}\n${JSON.stringify({tasks:n})}`,phase:t?`settled`:`pending`}}export{TASK_DELIVERY_CONTEXT_LABEL,TASK_DELIVERY_INITIATING_INSTRUCTION,TASK_DELIVERY_SETTLED_INSTRUCTION,getBackgroundTaskDelivery,markBackgroundTaskStepInput,resolveInitiatingTaskContext,resolveTaskDeliveryContext};