openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.65 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Nc as t,Tc as n}from"./control-ui-connection-Bfj9beF_.js";import{r,t as i}from"./canvas-limits-DuPWavzb.js";async function a(e,n,r={}){let i=e.headers.get(`Content-Length`),a=i===null?void 0:Number(i);if(!r.truncate&&a!==void 0&&Number.isFinite(a)&&a>n)return await e.body?.cancel().catch(()=>void 0),null;let o=e.body?.getReader();if(!o)return null;let s=[],c=0;try{if((await t({maxBytes:n,stopAtLimit:r.truncate,skipEmptyChunks:!1,read:()=>o.read(),onChunk:e=>{s.push(e),c+=e.byteLength},onLimit:()=>o.cancel().catch(()=>void 0)})).truncated&&!r.truncate)return null}finally{o.releaseLock()}let l=new Uint8Array(c),u=0;for(let e of s)l.set(e,u),u+=e.byteLength;return l.buffer}function o(){return(o=e((()=>{n()})))()}async function s(e,t,n,r=`full`){let o=r===`excerpt`,s=r===`html`?i:c;if(!o&&t!==void 0&&t>s)throw Error(`Text attachment exceeds preview limit`);let l=new AbortController,u=setTimeout(()=>l.abort(),1e4),d=AbortSignal.any([n,l.signal]),f=e.startsWith(`data:`);try{let t=await fetch(e,{credentials:`same-origin`,redirect:`error`,signal:f?void 0:d});if(f&&d.aborted)throw await t.body?.cancel().catch(()=>void 0),d.reason;if(!t.ok)throw await t.body?.cancel(),Error(`Text attachment unavailable`);let n=await a(t,s,{truncate:o});if(f&&d.aborted)throw d.reason;if(!n)throw Error(`Text attachment exceeds preview limit`);let r=new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(n,{stream:o});if(r.includes(`\0`))throw Error(`Binary attachment`);return r}finally{clearTimeout(u)}}var c;function l(){return(l=e((()=>{r(),o(),c=262144})))()}export{a,o as i,l as n,s as r,c as t};