UNPKG

eve

Version:

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

4 lines (3 loc) 3.44 kB
import{markFrameworkStepInput}from"#harness/messages.js";import{getBackgroundWorkflowToolRuns,readWorkflowTaskView}from"#harness/workflow-tool-runs.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\nFor this background-task update, the accompanying ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists the settled tasks in this cohort and their available terminal outputs. Report their useful results together in one user-facing response without repeating results already reported. Do not reply with ${EMPTY_DELIVERY_SENTINEL}.`,TASK_DELIVERY_AUTO_INSTRUCTION=`Background task reporting\nFor this background-task update, the accompanying ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists the whole cohort, including pending tasks and every available terminal output. A received result has not necessarily been reported to the user. Report new results only when they are useful independently of unfinished work. When that work settles, combine its results with any previously withheld results. If there is nothing new and useful to report, reply with exactly ${EMPTY_DELIVERY_SENTINEL}. Do not repeat results already reported or send an acknowledgement just to say you are waiting.`;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=e.taskDeliveryIds[0];if(t===void 0)return;let n=getBackgroundWorkflowToolRuns(e.state),r=n.find(e=>t.startsWith(`${e.task.taskId}:`));return r===void 0?void 0:{...projectTaskCohort(n.filter(e=>getTaskCohortId(e.task)===getTaskCohortId(r.task)),e.taskDeliveryPolicy===`auto`),rootTurnId:r.origin.turnId}}function resolveInitiatingTaskContext(e){let t=getBackgroundWorkflowToolRuns(e.state).filter(t=>t.origin.turnId===e.turnId);if(t.some(e=>e.task.outcome===void 0))return{...projectTaskCohort(t,!1),phase:`initiating`}}function projectTaskCohort(e,t){let n=e.every(e=>e.task.outcome!==void 0),r=e.map(e=>{let r=readWorkflowTaskView(e.task);return{name:e.task.metadata.name,output:n||t?r?.lastOutput:void 0,status:r?.status??`pending`,taskId:e.task.taskId}});return{context:`${TASK_DELIVERY_CONTEXT_LABEL}\n${JSON.stringify({tasks:r})}`,phase:n?`settled`:`pending`}}export{TASK_DELIVERY_AUTO_INSTRUCTION,TASK_DELIVERY_CONTEXT_LABEL,TASK_DELIVERY_INITIATING_INSTRUCTION,TASK_DELIVERY_SETTLED_INSTRUCTION,getBackgroundTaskDelivery,markBackgroundTaskStepInput,resolveInitiatingTaskContext,resolveTaskDeliveryContext};