UNPKG

@catalystlabs/tryai

Version:

Dead simple AI library. One line setup. Zero config. Just works.

3 lines 931 B
async function*u(s){if(!s.body)throw new Error("Response body is null");let r=s.body.getReader(),e=new TextDecoder,n="";try{for(;;){let{done:a,value:i}=await r.read();if(a){if(n.trim()){let o=d(n);o&&(yield o)}break}n+=e.decode(i,{stream:!0});let t=n.split(/\r\n\r\n|\n\n/);n=t.pop()||"";for(let o of t)if(o.trim()){let c=d(o);c&&(yield c)}}}finally{r.releaseLock()}}function d(s){let r=s.split(/\r\n|\n/),e={};for(let n of r){if(n.startsWith(":"))continue;let a=n.indexOf(":");if(a===-1)continue;let i=n.substring(0,a),t=n.substring(a+1);switch(t.startsWith(" ")&&(t=t.substring(1)),i){case"event":e.event=t;break;case"data":e.data=e.data?e.data+` `+t:t;break;case"id":e.id=t;break;case"retry":e.retry=parseInt(t,10);break}}return!e.data&&!e.event?null:e}function l(s,r={}){return{...r,headers:{...r.headers,Accept:"text/event-stream","Cache-Control":"no-cache"}}}export{u as a,l as b}; //# sourceMappingURL=chunk-LMOWCXXE.mjs.map