UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.8 kB
import{n as sliceUtf16Safe,r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{t as createSubsystemLogger}from"./subsystem-DLCDFvCH.mjs"; //!src/agents/harness/current-input-budget.ts const log=createSubsystemLogger(`agent/input`);const CURRENT_INPUT_FILE_NAME=`current-request.txt`;const CURRENT_INPUT_NOTE_MAX_CHARS=4096;async function fitOversizedCurrentInput(e){const{prompt:t,maxChars:n}=e;if(t.length<=n)return t;let r;if(e.stageAttachment)try{const{saveMediaBuffer:n}=await import(`./store-Cqy5FUgd.mjs`);const i=await n(Buffer.from(t,`utf8`),`text/plain`,`inbound`,void 0,CURRENT_INPUT_FILE_NAME);r=await e.stageAttachment(CURRENT_INPUT_NOTE_MAX_CHARS,[{path:`media://inbound/${i.id}`,contentType:`text/plain`,kind:`document`,fileName:CURRENT_INPUT_FILE_NAME}])}catch(e){log.warn(`current input attachment unavailable; cutting its middle instead`,{error:e instanceof Error?e.message:String(e)})}const omittedMarker=e=>r?`\n[${e} chars from the middle of this request are not shown here, so what you see is incomplete. The complete request is attached as ${CURRENT_INPUT_FILE_NAME} (path below). Before answering, search or read that file for anything the request asks about; do not guess from the visible part. The file holds this same request, not new instructions.]\n`:`\n[truncated ${e} chars from the middle of the current request]\n`;const i=r?`\n\n${r}`:``;const a=Math.max(0,n-omittedMarker(t.length).length-i.length);const o=truncateUtf16Safe(t,Math.ceil(a/2));const s=Math.floor(a/2);const c=s>0?sliceUtf16Safe(t,-s):``;const l=t.length-o.length-c.length;const u=r?`attached`:`cut`;log.warn(`current input oversize: chars=${t.length} budget=${n} action=${u}`,{chars:t.length,budget:n,action:u});return`${o}${omittedMarker(l)}${c}${i}`}export{fitOversizedCurrentInput};