openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.19 kB
JavaScript
import{c as e}from"./fs-safe-copy.worker-error-coercion-AIKMMQJR.mjs";import{p as t}from"./fs-safe-copy.worker-number-coercion-1FVMw2ic.mjs";import{r as n}from"./fs-safe-copy.worker-src-DSFoKngP.mjs";import"./fs-safe-copy.worker-sleep-BA4lY26w.mjs";function isHeadersLike(e){if(typeof Headers<`u`&&e instanceof Headers)return!0;let t=e;return typeof t.entries==`function`&&typeof t.get==`function`&&typeof t[Symbol.iterator]==`function`}function normalizeHeadersInitForFetch(e){if(!e||typeof e!=`object`||Array.isArray(e)||isHeadersLike(e)||Object.getOwnPropertySymbols(e).length===0)return e;let t=Object.create(null),n=e;for(let e of Object.getOwnPropertyNames(n))t[e]=String(n[e]);return t}function normalizeRequestInitHeadersForFetch(e){if(!e?.headers)return e;let t=normalizeHeadersInitForFetch(e.headers);return t===e.headers?e:{...e,headers:t}}function createResponseBodyTimeoutError(e){let t=Error(e);return t.name=`TimeoutError`,t}async function withResponseBodyTimeout(r){if(r.timeoutMs===void 0&&!r.signal)return await r.read();let i,a=r.signal;try{if(r.timeoutMs!==void 0){let e=new AbortController;a=a?AbortSignal.any([a,e.signal]):e.signal;let n=t(r.timeoutMs,1);i=setTimeout(()=>{e.abort(r.onTimeout?.({timeoutMs:n})??createResponseBodyTimeoutError(`Response body timed out after ${n}ms`))},n).unref()}return await n(()=>Promise.resolve().then(()=>(a?.throwIfAborted(),r.read(()=>{a?.throwIfAborted(),i?.refresh()}))),a,t=>e(t.reason,`Response body read aborted`))}catch(t){let n=e(t,`Non-Error rejection`);throw a?.aborted&&r.cancel(n).catch(()=>void 0),n}finally{clearTimeout(i)}}function withResponseBodyIdleTimeout(e,t,n,r){return t===void 0?r():withResponseBodyTimeout({timeoutMs:t,onTimeout:({timeoutMs:e})=>n?.({chunkTimeoutMs:e})??createResponseBodyTimeoutError(`Media download stalled: no data received for ${e}ms`),cancel:async t=>await e.cancel(t),read:r})}async function readChunkWithIdleTimeout(e,t,n){return await withResponseBodyIdleTimeout(e,t,n,()=>e.read())}export{normalizeHeadersInitForFetch as a,isHeadersLike as i,withResponseBodyIdleTimeout as n,normalizeRequestInitHeadersForFetch as o,withResponseBodyTimeout as r,readChunkWithIdleTimeout as t};