UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.2 kB
import{r as e}from"./transcript-tool-result-pairing-DrpmDHYa.mjs";import{i as t,l as n,n as r,r as i,t as a}from"./transcript-session-accessor.sqlite-visible-cursor-CP4ccuQd.mjs";function normalizeBoundedContextLimits(e){return`compaction`in e?void 0:{maxBytes:n(e.maxBytes,a,i,`maxBytes`),maxEvents:n(e.maxEvents,r,t,`maxEvents`)}}function selectBoundedContextRows(e,t,n){if(n&&t>n.maxBytes)throw RangeError(`Session transcript header exceeds the active-context byte limit`);let r=[],i=t,a=!1;for(let t of e){if(n&&(r.length>=n.maxEvents||i+t.serialized_bytes>n.maxBytes)){a=!0;break}r.push(t),i+=t.serialized_bytes}return{selectedRows:r,serializedBytes:i,truncated:a}}function selectBoundedContextStart(t,n,r,i){let a=2,o=0,s=t.length,c=!1;for(let e=t.length-1;e>=0;e--){let l=i(e);if(a+=l.bytes+1,o+=l.tokens,a>n){c=!0;break}r!==void 0&&o>r||(e===0||t[e].role===`user`)&&(s=e)}if(!c)return 0;for(let n of e(t)){if(n.startIndex>=s)break;for(let e of n.occurrences)if(e.sourceResultIndex!==void 0&&e.sourceResultIndex>=s)for(s=e.sourceResultIndex+1;s<t.length&&t[s]?.role!==`user`;)s++}return s}export{selectBoundedContextRows as n,selectBoundedContextStart as r,normalizeBoundedContextLimits as t};