import{e as v,q as y}from"./entry.BWtf2SiU.js";const S=async(a,e)=>{var n;const{supporterAPIUrl:i}=v().public,t=await y().$db().auth.getSession();if(!t.data)throw new Error("Unable to use this feature without logging in");const c=(n=t.data.session)==null?void 0:n.access_token;e&&(e.timezone=new Date().getTimezoneOffset()/60);const s=await fetch(i+a,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(e)}),d=await s.json();if(!s.ok)throw new Error(d.error);return d},A=async(a,e)=>{var n;const{supporterAPIUrl:i}=v().public,t=await y().$db().auth.getSession();if(!t.data)throw new Error("Unable to use this feature without logging in");const c=(n=t.data.session)==null?void 0:n.access_token,s=await fetch(i+a,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(e)});if(!s.body)throw new Error("Failed to fetch stream");return{eventListeners:{},addEventListener(o,r){this.eventListeners[o]=r},async stream(){var o,r,u,f,w,g,b,l,p,m;try{(r=(o=this.eventListeners).open)==null||r.call(o);const h=s.body.getReader(),T=new TextDecoder;for(;;){const{done:k,value:E}=await h.read();if(k){(f=(u=this.eventListeners).close)==null||f.call(u),(g=(w=this.eventListeners).message)==null||g.call(w,{event:"close",data:"[DONE]"});break}const O=T.decode(E);(l=(b=this.eventListeners).message)==null||l.call(b,{event:"message",data:O})}}catch(h){(m=(p=this.eventListeners).error)==null||m.call(p,h)}}}};export{S as f,A as s};