UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.28 kB
function resolveTranscriptPageEnd(e,t){let n=t.beforeSeq===void 0||!Number.isFinite(t.beforeSeq)?e:Math.min(e,Math.max(0,Math.floor(t.beforeSeq)-1)),r=t.offset??0;return Math.max(0,n-Math.max(0,Math.floor(Number.isFinite(r)?r:0)))}function resolveHistoryAnchorPageRange(e,t,{maxMessages:n,direction:r,excludeAnchor:i}){let a=Math.max(1,Math.floor(Number.isFinite(n)?n:1));if(r){let n=r===`older`?t+1:Math.min(e,t+a);return{readStart:(r===`older`?Math.max(0,n-a):t)+(i&&r===`newer`?1:0),endExclusive:n-(i&&r===`older`?1:0),hasOverreadContext:!1,offset:e-n}}let o=a-Math.floor(a/2)-1,s=Math.max(0,e-a),c=Math.min(Math.max(0,t-o),s),l=Math.min(e,c+a),u=Math.max(0,c-1);return{readStart:u,endExclusive:l,hasOverreadContext:u<c,offset:e-l}}function boundHistoryAnchorPageRange(e,t,n,r,i=!1){let a=Math.min(Math.max(t,e.readStart),e.endExclusive),o=a,s=2,include=e=>{let t=r(e,n-s);if(s+t>n){if(i&&a===o)throw Error(`Transcript history message exceeds the ${n}-byte page limit`);return!1}return s+=t,!0};if(a<e.endExclusive){if(!include(a))return{start:a,endExclusive:o};o++}for(;a>e.readStart&&include(a-1);)a--;for(;o<e.endExclusive&&include(o);)o++;return{start:a,endExclusive:o}}export{resolveHistoryAnchorPageRange as n,resolveTranscriptPageEnd as r,boundHistoryAnchorPageRange as t};