UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.56 kB
import{i as e}from"./transcript-record-coerce-CPLgmAk9.mjs";import"./transcript-payload-limits-DETN1Ggi.mjs";function parseSessionPendingInputMessage(t){let n=JSON.parse(t);if(e(n)?.role!==`user`)throw Error(`Pending input has an invalid persisted user message`);return n}function isFinalInputCompletion(e){return e.reason===`completed`||e.reason===`cancelled`&&e.stopReason!==`restart`}function resolvePendingInputHistoryLimit(e){return Math.max(1,Math.min(20,Math.trunc(e??20)))}function selectPendingInputHistoryPage(e,t){let n=[],r=0;for(let i of e){if(n.length===t||r+i.serialized_bytes>26214400)break;n.push(i.seq),r+=i.serialized_bytes}if(e.length&&!n.length)throw Error(`Stored pending input exceeds the Gateway payload limit`);return{selected:n,nextBefore:n.length<e.length?n.at(-1):void 0}}function normalizePendingInputReceiptRunIds(e){if(e.length>50)throw Error(`Pending input receipt lookup accepts at most 50 run IDs`);return[...new Set(e)]}function projectPendingInputReceipts(e){if(e.length>50||new Set(e.map(e=>e.run_id)).size!==e.length)throw Error(`Pending input receipt lookup has ambiguous source run IDs`);return e.map(e=>e.consumed_event_id==null?e.state===`cancelled`?{runId:e.run_id,state:`pending`,cancelled:!0}:{runId:e.run_id,state:`pending`}:{runId:e.run_id,state:`consumed`,consumedByEventId:e.consumed_event_id})}export{resolvePendingInputHistoryLimit as a,projectPendingInputReceipts as i,normalizePendingInputReceiptRunIds as n,selectPendingInputHistoryPage as o,parseSessionPendingInputMessage as r,isFinalInputCompletion as t};