eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2 kB
JavaScript
import{getPendingInputBatches,queueDeferredStepInput,removePendingInputBatches}from"#harness/pending-input-batches.js";import{buildResolvedInputBatch}from"#harness/input-request-resolution.js";import{appendResolvedBatchTranscript,compactStepInput,finishResolvedInput,responsesForBatches}from"#harness/hitl/pending-input-resolution.js";import{isSessionLimitContinuationRequest,resolveSessionLimitContinuation}from"#harness/session-limit-continuation.js";function isSessionLimitInputBatch(e){let t=e.requests.some(e=>e.kind===`session-limit`);if(t&&e.requests.some(e=>e.kind!==`session-limit`))throw TypeError(`Session-limit pending input batches must contain only session-limit requests.`);return t}function resolveSessionLimitInput(e){let t=new Set(e.responses.map(e=>e.requestId));if(!(e.pendingBatch.requests.some(e=>t.has(e.requestId))&&e.pendingBatch.requests.every(e=>t.has(e.requestId))))return{deferredMessage:!0,outcome:`unresolved`,messages:[...e.baseHistory],session:queueDeferredStepInput(e.session,compactStepInput(e.resolvedStepInput))};let n=e.batches.filter(t=>t!==e.pendingBatch),r=responsesForBatches(e.responses,n),i=n.some(e=>e.requests.some(e=>isSessionLimitContinuationRequest(e))),a=[...e.baseHistory];appendResolvedBatchTranscript(a,e.pendingBatch,[]);let o=removePendingInputBatches(e.session,[e.pendingBatch]),s=resolveSessionLimitContinuation({requests:e.pendingBatch.requests,responses:e.responses});return finishResolvedInput({deferTurnInput:e.deferTurnInput||i,leftoverResponses:r,limitContinuation:s,messages:a,resolvedInputs:[buildResolvedInputBatch(e.pendingBatch,e.responses)].filter(e=>e!==void 0),resolvedStepInput:e.resolvedStepInput,session:o})}function clearPendingSessionLimitPrompt(e){let t=getPendingInputBatches(e.state).filter(e=>e.requests.length>0&&e.requests.every(e=>isSessionLimitContinuationRequest(e)));return t.length===0?e:removePendingInputBatches(e,t)}export{clearPendingSessionLimitPrompt,isSessionLimitInputBatch,resolveSessionLimitInput};