UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.16 kB
import{r as selectBoundedContextStart}from"./session-bounded-context-selection--mHjSW_P.mjs";import{n as estimateTokens}from"./compaction-cut-point-CwzAZ7By.mjs";import{r as resolveExpiredRuntimeContextContentBytes}from"./transcript-byte-limit-_Kdc5zSm.mjs";import{createHash}from"node:crypto"; //!src/context-engine/bounded-context.ts function boundContextEngineAssembly(e,t,n,r,i=false){if(t===void 0)return e;const{messages:a}=e;const o=i?resolveExpiredRuntimeContextContentBytes(a):void 0;const s=selectBoundedContextStart(a,t,n,e=>{const t=a[e];const n=r?.get(t)??0;return{bytes:Buffer.byteLength(JSON.stringify(t),`utf8`)+n-(o?.get(t)??0),tokens:(o?.has(t)?0:estimateTokens(t))+(n?Math.ceil(n/4):0)}});if(!s)return e;const c=a.slice(s);const l=createHash(`sha256`).update(JSON.stringify([e.contextProjection,t,a[s-1],c,e.systemPromptAddition])).digest(`hex`);return{...e,messages:c,estimatedTokens:c.reduce((e,t)=>{const n=r?.get(t)??0;return e+(o?.has(t)?0:estimateTokens(t))+(n?Math.ceil(n/4):0)},0),promptAuthority:`assembled`,contextProjection:{mode:`thread_bootstrap`,epoch:`bounded:${l}`,fingerprint:l}}}export{boundContextEngineAssembly as t};