UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

3 lines 921 B
const MAX_OUTPUT_LINES=2e3,MAX_OUTPUT_BYTES=50*1024,MAX_LINE_LENGTH=2e3,LINE_TRUNCATION_SUFFIX=` [truncated]`;function truncateHead(e){return truncateByDirection(e,`head`)}function truncateTail(e){return truncateByDirection(e,`tail`)}function truncateByDirection(e,t){let n=e.split(` `),r=countLogicalLines(n),i=t===`head`,a=[],o=0,s=i?0:n.length-1,c=i?1:-1;for(let e=s;e>=0&&e<n.length&&a.length<2e3;e+=c){let t=capLineLength(n[e]??``),r=Buffer.byteLength(t,`utf8`)+1;if(o+r>51200&&a.length>0)break;a.push(t),o+=r}return i||a.reverse(),{output:a.join(` `),outputLines:a.length,totalLines:r,truncated:a.length<r}}function capLineLength(e){return e.length<=2e3?e:e.slice(0,MAX_LINE_LENGTH)+LINE_TRUNCATION_SUFFIX}function countLogicalLines(e){return e.length>0&&e[e.length-1]===``?e.length-1:e.length}export{LINE_TRUNCATION_SUFFIX,MAX_LINE_LENGTH,MAX_OUTPUT_BYTES,MAX_OUTPUT_LINES,capLineLength,truncateHead,truncateTail};