@kivox/client 0.1.0-beta.44 → 0.1.0-beta.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1,5 @@
1
- var{defineProperty:b,getOwnPropertyNames:$G,getOwnPropertyDescriptor:JG}=Object,KG=Object.prototype.hasOwnProperty;function NG(G){return this[G]}var WG=(G)=>{var V=(l??=new WeakMap).get(G),X;if(V)return V;if(V=b({},"__esModule",{value:!0}),G&&typeof G==="object"||typeof G==="function"){for(var Z of $G(G))if(!KG.call(V,Z))b(V,Z,{get:NG.bind(G,Z),enumerable:!(X=JG(G,Z))||X.enumerable})}return l.set(G,V),V},l;var DG=(G)=>G;function _G(G,V){this[G]=DG.bind(null,V)}var IG=(G,V)=>{for(var X in V)b(G,X,{get:V[X],enumerable:!0,configurable:!0,set:_G.bind(V,X)})};var TG={};IG(TG,{createSessionClient:()=>kG,createBearerClient:()=>LG,ConversationTransportError:()=>O,ConversationSession:()=>T});module.exports=WG(TG);var QG=/\{[^{}]+\}/g,OG=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function BG(){return Math.random().toString(36).slice(2,11)}function s(G){let{baseUrl:V="",Request:X=globalThis.Request,fetch:Z=globalThis.fetch,querySerializer:Y,bodySerializer:$,pathSerializer:J,headers:_,requestInitExt:S=void 0,...GG}={...G};S=OG()?S:void 0,V=n(V);let A=[];async function Q(N,K){let{baseUrl:F,fetch:c=Z,Request:v=X,headers:h,params:k={},parseAs:j="json",querySerializer:x,bodySerializer:d=$??FG,pathSerializer:VG,body:m,middleware:XG=[],...z}=K||{},U=V;if(F)U=n(F)??V;let g=typeof Y==="function"?Y:o(Y);if(x)g=typeof x==="function"?x:o({...typeof Y==="object"?Y:{},...x});let u=VG||J||HG,P=m===void 0?void 0:d(m,i(_,h,k.header)),YG=i(P===void 0||P instanceof FormData?{}:{"Content-Type":"application/json"},_,h,k.header),B=[...A,...XG],ZG={redirect:"follow",...GG,...z,body:P,headers:YG},R,E,H=new v(MG(N,{baseUrl:U,params:k,querySerializer:g,pathSerializer:u}),ZG),W;for(let I in z)if(!(I in H))H[I]=z[I];if(B.length){R=BG(),E=Object.freeze({baseUrl:U,fetch:c,parseAs:j,querySerializer:g,bodySerializer:d,pathSerializer:u});for(let I of B)if(I&&typeof I==="object"&&typeof I.onRequest==="function"){let D=await I.onRequest({request:H,schemaPath:N,params:k,options:E,id:R});if(D)if(D instanceof v)H=D;else if(D instanceof Response){W=D;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!W){try{W=await c(H,S)}catch(I){let D=I;if(B.length)for(let M=B.length-1;M>=0;M--){let w=B[M];if(w&&typeof w==="object"&&typeof w.onError==="function"){let L=await w.onError({request:H,error:D,schemaPath:N,params:k,options:E,id:R});if(L){if(L instanceof Response){D=void 0,W=L;break}if(L instanceof Error){D=L;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(D)throw D}if(B.length)for(let I=B.length-1;I>=0;I--){let D=B[I];if(D&&typeof D==="object"&&typeof D.onResponse==="function"){let M=await D.onResponse({request:H,response:W,schemaPath:N,params:k,options:E,id:R});if(M){if(!(M instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");W=M}}}}let p=W.headers.get("Content-Length");if(W.status===204||H.method==="HEAD"||p==="0"&&!W.headers.get("Transfer-Encoding")?.includes("chunked"))return W.ok?{data:void 0,response:W}:{error:void 0,response:W};if(W.ok)return{data:await(async()=>{if(j==="stream")return W.body;if(j==="json"&&!p){let D=await W.text();return D?JSON.parse(D):void 0}return await W[j]()})(),response:W};let f=await W.text();try{f=JSON.parse(f)}catch{}return{error:f,response:W}}return{request(N,K,F){return Q(K,{...F,method:N.toUpperCase()})},GET(N,K){return Q(N,{...K,method:"GET"})},PUT(N,K){return Q(N,{...K,method:"PUT"})},POST(N,K){return Q(N,{...K,method:"POST"})},DELETE(N,K){return Q(N,{...K,method:"DELETE"})},OPTIONS(N,K){return Q(N,{...K,method:"OPTIONS"})},HEAD(N,K){return Q(N,{...K,method:"HEAD"})},PATCH(N,K){return Q(N,{...K,method:"PATCH"})},TRACE(N,K){return Q(N,{...K,method:"TRACE"})},use(...N){for(let K of N){if(!K)continue;if(typeof K!=="object"||!(("onRequest"in K)||("onResponse"in K)||("onError"in K)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");A.push(K)}},eject(...N){for(let K of N){let F=A.indexOf(K);if(F!==-1)A.splice(F,1)}}}}function q(G,V,X){if(V===void 0||V===null)return"";if(typeof V==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${G}=${X?.allowReserved===!0?V:encodeURIComponent(V)}`}function t(G,V,X){if(!V||typeof V!=="object")return"";let Z=[],Y={simple:",",label:".",matrix:";"}[X.style]||"&";if(X.style!=="deepObject"&&X.explode===!1){for(let _ in V)Z.push(_,X.allowReserved===!0?V[_]:encodeURIComponent(V[_]));let J=Z.join(",");switch(X.style){case"form":return`${G}=${J}`;case"label":return`.${J}`;case"matrix":return`;${G}=${J}`;default:return J}}for(let J in V){let _=X.style==="deepObject"?`${G}[${J}]`:J;Z.push(q(_,V[J],X))}let $=Z.join(Y);return X.style==="label"||X.style==="matrix"?`${Y}${$}`:$}function a(G,V,X){if(!Array.isArray(V))return"";if(X.explode===!1){let $={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[X.style]||",",J=(X.allowReserved===!0?V:V.map((_)=>encodeURIComponent(_))).join($);switch(X.style){case"simple":return J;case"label":return`.${J}`;case"matrix":return`;${G}=${J}`;default:return`${G}=${J}`}}let Z={simple:",",label:".",matrix:";"}[X.style]||"&",Y=[];for(let $ of V)if(X.style==="simple"||X.style==="label")Y.push(X.allowReserved===!0?$:encodeURIComponent($));else Y.push(q(G,$,X));return X.style==="label"||X.style==="matrix"?`${Z}${Y.join(Z)}`:Y.join(Z)}function o(G){return function(X){let Z=[];if(X&&typeof X==="object")for(let Y in X){let $=X[Y];if($===void 0||$===null)continue;if(Array.isArray($)){if($.length===0)continue;Z.push(a(Y,$,{style:"form",explode:!0,...G?.array,allowReserved:G?.allowReserved||!1}));continue}if(typeof $==="object"){Z.push(t(Y,$,{style:"deepObject",explode:!0,...G?.object,allowReserved:G?.allowReserved||!1}));continue}Z.push(q(Y,$,G))}return Z.join("&")}}function HG(G,V){let X=G;for(let Z of G.match(QG)??[]){let Y=Z.substring(1,Z.length-1),$=!1,J="simple";if(Y.endsWith("*"))$=!0,Y=Y.substring(0,Y.length-1);if(Y.startsWith("."))J="label",Y=Y.substring(1);else if(Y.startsWith(";"))J="matrix",Y=Y.substring(1);if(!V||V[Y]===void 0||V[Y]===null)continue;let _=V[Y];if(Array.isArray(_)){X=X.replace(Z,a(Y,_,{style:J,explode:$}));continue}if(typeof _==="object"){X=X.replace(Z,t(Y,_,{style:J,explode:$}));continue}if(J==="matrix"){X=X.replace(Z,`;${q(Y,_)}`);continue}X=X.replace(Z,J==="label"?`.${encodeURIComponent(_)}`:encodeURIComponent(_))}return X}function FG(G,V){if(G instanceof FormData)return G;if(V){if((V.get instanceof Function?V.get("Content-Type")??V.get("content-type"):V["Content-Type"]??V["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(G).toString()}return JSON.stringify(G)}function MG(G,V){let X=`${V.baseUrl}${G}`;if(V.params?.path)X=V.pathSerializer(X,V.params.path);let Z=V.querySerializer(V.params.query??{});if(Z.startsWith("?"))Z=Z.substring(1);if(Z)X+=`?${Z}`;return X}function i(...G){let V=new Headers;for(let X of G){if(!X||typeof X!=="object")continue;let Z=X instanceof Headers?X.entries():Object.entries(X);for(let[Y,$]of Z)if($===null)V.delete(Y);else if(Array.isArray($))for(let J of $)V.append(Y,J);else if($!==void 0)V.set(Y,$)}return V}function n(G){if(G.endsWith("/"))return G.substring(0,G.length-1);return G}class T{_transport;_conversationId;_closed=!1;_onEvent;_pendingAudioMetadata=null;_remainingMs=0;_elapsedMs=0;get conversationId(){return this._conversationId}get remainingMs(){return this._remainingMs}get elapsedMs(){return this._elapsedMs}get closed(){return this._closed}constructor(G,V,X){this._transport=G,this._conversationId=V,this._onEvent=X.onEvent,this.#G()}sendText(G){if(this._closed){console.warn("Cannot send text: session is closed");return}this._transport.send({type:"input_text",text:G})}sendAudio(G){if(this._closed){console.warn("Cannot send audio: session is closed");return}this._transport.send({type:"input_audio"}),this._transport.sendBinary(G)}streamAudio(G){if(this._closed){console.warn("Cannot stream audio: session is closed");return}this._transport.send({type:"input_audio_stream"}),this._transport.sendBinary(G)}cancelRequest(){if(this._closed){console.warn("Cannot cancel request: session is closed");return}this._transport.send({type:"cancel"})}end(){if(this._closed){console.warn("Cannot end session: session is closed");return}this._transport.send({type:"end"})}close(){if(this._closed)return;this._closed=!0,this._transport.close()}#G(){this._transport.onMessage((G)=>{let V=G;if(V.type==="audio_delta"){this._pendingAudioMetadata={size:V.size};return}if(V.type==="tick")this._remainingMs=V.remaining_ms,this._elapsedMs=V.elapsed_ms;if(V.type==="session_closed")this._closed=!0;this._onEvent?.(V)}),this._transport.onBinary((G)=>{if(this._pendingAudioMetadata){let V={type:"audio_delta",size:this._pendingAudioMetadata.size,audio:G};this._pendingAudioMetadata=null,this._onEvent?.(V)}}),this._transport.onClose(()=>{if(this._closed)return;this._closed=!0,this._onEvent?.({type:"connection_lost",reason:"socket_closed"})}),this._transport.onError(()=>{if(this._closed)return;this._closed=!0,this._onEvent?.({type:"connection_lost",reason:"socket_error"})})}}class O extends Error{code;constructor(G,V="TRANSPORT_ERROR"){super(G);this.code=V;this.name="ConversationTransportError"}}class y{_ws;_closed=!1;_onMessage=null;_onBinary=null;_onError=null;_onClose=null;constructor(G){this._ws=G}async connect(){if(this._ws.readyState===WebSocket.OPEN)throw new O("Already connected","ALREADY_CONNECTED");if(this._ws.readyState===WebSocket.CLOSING||this._ws.readyState===WebSocket.CLOSED)throw new O("Socket is closing or closed","SOCKET_CLOSED");return new Promise((G,V)=>{let X,Z;X=()=>{this._ws.removeEventListener("open",X),this._ws.removeEventListener("error",Z),this.#G(),G()},Z=()=>{this._ws.removeEventListener("open",X),this._ws.removeEventListener("error",Z),V(new O("Connection failed","CONNECTION_FAILED"))},this._ws.addEventListener("open",X),this._ws.addEventListener("error",Z)})}send(G){if(this._ws.readyState!==WebSocket.OPEN)throw new O("Not connected","NOT_CONNECTED");this._ws.send(JSON.stringify(G))}async sendBinary(G){if(this._ws.readyState!==WebSocket.OPEN)throw new O("Not connected","NOT_CONNECTED");let V=await G.arrayBuffer();this._ws.send(V)}onMessage(G){this._onMessage=G}onBinary(G){this._onBinary=G}onError(G){this._onError=G}onClose(G){this._onClose=G}close(){if(this._closed)return;if(this._closed=!0,this._ws.readyState===WebSocket.OPEN||this._ws.readyState===WebSocket.CONNECTING)this._ws.close();this._onClose?.()}#G(){this._ws.addEventListener("message",(G)=>{if(G.data instanceof Blob)this._onBinary?.(G.data);else if(G.data instanceof ArrayBuffer)this._onBinary?.(new Blob([G.data]));else if(typeof G.data==="string")try{let V=JSON.parse(G.data);this._onMessage?.(V)}catch(V){console.warn("Failed to parse JSON message:",G.data,V)}}),this._ws.addEventListener("error",()=>{if(this._closed)return;this._onError?.(new O("WebSocket error")),this.close()}),this._ws.addEventListener("close",()=>{if(this._closed)return;this.close()})}}class C{#G;constructor(G){this.#G=G}async connect(G){let V=this.#V("/conversations/ws"),X=new y(new WebSocket(V));return await X.connect(),X.send({type:"handshake",agent_id:G.agent_id,channel:G.channel}),new Promise((Z,Y)=>{let $=!1;X.onMessage((J)=>{switch(J.type){case"handshake_ok":$=!0,G.onConnection?.(J),Z(new T(X,J.conversation_id,G));break;case"handshake_error":$=!0,G.onConnection?.(J),X.close(),Y(Error(`Handshake rejected: ${J.reason}`));break;default:}}),X.onError((J)=>{if(!$)Y(J)}),X.onClose(()=>{if(!$)Y(Error("Connection lost during handshake"))})})}#V(G){return`${this.#G.replace(/^https:\/\//,"wss://").replace(/^http:\/\//,"ws://").replace(/\/$/,"")}${G}`}}var r="https://server.kivox.com.co";function e(G){return s(G)}function kG({baseUrl:G=r}={}){return{api:e({baseUrl:G,credentials:"include"}),realtime:new C(G)}}function LG({bearerToken:G,baseUrl:V=r}){return{api:e({baseUrl:V,headers:{Authorization:`Bearer ${G}`}}),realtime:new C(V)}}
1
+ var{defineProperty:b,getOwnPropertyNames:KG,getOwnPropertyDescriptor:VG}=Object,WG=Object.prototype.hasOwnProperty;function XG(V){return this[V]}var YG=(V)=>{var G=(m??=new WeakMap).get(V),K;if(G)return G;if(G=b({},"__esModule",{value:!0}),V&&typeof V==="object"||typeof V==="function"){for(var X of KG(V))if(!WG.call(G,X))b(G,X,{get:XG.bind(V,X),enumerable:!(K=VG(V,X))||K.enumerable})}return m.set(V,G),G},m;var ZG=(V)=>V;function $G(V,G){this[V]=ZG.bind(null,G)}var JG=(V,G)=>{for(var K in G)b(V,K,{get:G[K],enumerable:!0,configurable:!0,set:$G.bind(G,K)})};var BG={};JG(BG,{readSSE:()=>QG,createSessionClient:()=>OG,createBearerClient:()=>HG});module.exports=YG(BG);var DG=/\{[^{}]+\}/g,NG=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function _G(){return Math.random().toString(36).slice(2,11)}function l(V){let{baseUrl:G="",Request:K=globalThis.Request,fetch:X=globalThis.fetch,querySerializer:W,bodySerializer:Y,pathSerializer:J,headers:D,requestInitExt:k=void 0,...F}={...V};k=NG()?k:void 0,G=o(G);let E=[];async function I(Z,$){let{baseUrl:O,fetch:P=X,Request:f=K,headers:y,params:B={},parseAs:M="json",querySerializer:g,bodySerializer:v=Y??TG,pathSerializer:r,body:c,middleware:a=[],...U}=$||{},q=G;if(O)q=o(O)??G;let S=typeof W==="function"?W:p(W);if(g)S=typeof g==="function"?g:p({...typeof W==="object"?W:{},...g});let h=r||J||IG,w=c===void 0?void 0:v(c,u(D,y,B.header)),e=u(w===void 0||w instanceof FormData?{}:{"Content-Type":"application/json"},D,y,B.header),j=[...E,...a],GG={redirect:"follow",...F,...U,body:w,headers:e},x,A,Q=new f(EG(Z,{baseUrl:q,params:B,querySerializer:S,pathSerializer:h}),GG),N;for(let T in U)if(!(T in Q))Q[T]=U[T];if(j.length){x=_G(),A=Object.freeze({baseUrl:q,fetch:P,parseAs:M,querySerializer:S,bodySerializer:v,pathSerializer:h});for(let T of j)if(T&&typeof T==="object"&&typeof T.onRequest==="function"){let _=await T.onRequest({request:Q,schemaPath:Z,params:B,options:A,id:x});if(_)if(_ instanceof f)Q=_;else if(_ instanceof Response){N=_;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!N){try{N=await P(Q,k)}catch(T){let _=T;if(j.length)for(let H=j.length-1;H>=0;H--){let L=j[H];if(L&&typeof L==="object"&&typeof L.onError==="function"){let C=await L.onError({request:Q,error:_,schemaPath:Z,params:B,options:A,id:x});if(C){if(C instanceof Response){_=void 0,N=C;break}if(C instanceof Error){_=C;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(_)throw _}if(j.length)for(let T=j.length-1;T>=0;T--){let _=j[T];if(_&&typeof _==="object"&&typeof _.onResponse==="function"){let H=await _.onResponse({request:Q,response:N,schemaPath:Z,params:B,options:A,id:x});if(H){if(!(H instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");N=H}}}}let d=N.headers.get("Content-Length");if(N.status===204||Q.method==="HEAD"||d==="0"&&!N.headers.get("Transfer-Encoding")?.includes("chunked"))return N.ok?{data:void 0,response:N}:{error:void 0,response:N};if(N.ok)return{data:await(async()=>{if(M==="stream")return N.body;if(M==="json"&&!d){let _=await N.text();return _?JSON.parse(_):void 0}return await N[M]()})(),response:N};let z=await N.text();try{z=JSON.parse(z)}catch{}return{error:z,response:N}}return{request(Z,$,O){return I($,{...O,method:Z.toUpperCase()})},GET(Z,$){return I(Z,{...$,method:"GET"})},PUT(Z,$){return I(Z,{...$,method:"PUT"})},POST(Z,$){return I(Z,{...$,method:"POST"})},DELETE(Z,$){return I(Z,{...$,method:"DELETE"})},OPTIONS(Z,$){return I(Z,{...$,method:"OPTIONS"})},HEAD(Z,$){return I(Z,{...$,method:"HEAD"})},PATCH(Z,$){return I(Z,{...$,method:"PATCH"})},TRACE(Z,$){return I(Z,{...$,method:"TRACE"})},use(...Z){for(let $ of Z){if(!$)continue;if(typeof $!=="object"||!(("onRequest"in $)||("onResponse"in $)||("onError"in $)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");E.push($)}},eject(...Z){for(let $ of Z){let O=E.indexOf($);if(O!==-1)E.splice(O,1)}}}}function R(V,G,K){if(G===void 0||G===null)return"";if(typeof G==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${V}=${K?.allowReserved===!0?G:encodeURIComponent(G)}`}function n(V,G,K){if(!G||typeof G!=="object")return"";let X=[],W={simple:",",label:".",matrix:";"}[K.style]||"&";if(K.style!=="deepObject"&&K.explode===!1){for(let D in G)X.push(D,K.allowReserved===!0?G[D]:encodeURIComponent(G[D]));let J=X.join(",");switch(K.style){case"form":return`${V}=${J}`;case"label":return`.${J}`;case"matrix":return`;${V}=${J}`;default:return J}}for(let J in G){let D=K.style==="deepObject"?`${V}[${J}]`:J;X.push(R(D,G[J],K))}let Y=X.join(W);return K.style==="label"||K.style==="matrix"?`${W}${Y}`:Y}function s(V,G,K){if(!Array.isArray(G))return"";if(K.explode===!1){let Y={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[K.style]||",",J=(K.allowReserved===!0?G:G.map((D)=>encodeURIComponent(D))).join(Y);switch(K.style){case"simple":return J;case"label":return`.${J}`;case"matrix":return`;${V}=${J}`;default:return`${V}=${J}`}}let X={simple:",",label:".",matrix:";"}[K.style]||"&",W=[];for(let Y of G)if(K.style==="simple"||K.style==="label")W.push(K.allowReserved===!0?Y:encodeURIComponent(Y));else W.push(R(V,Y,K));return K.style==="label"||K.style==="matrix"?`${X}${W.join(X)}`:W.join(X)}function p(V){return function(K){let X=[];if(K&&typeof K==="object")for(let W in K){let Y=K[W];if(Y===void 0||Y===null)continue;if(Array.isArray(Y)){if(Y.length===0)continue;X.push(s(W,Y,{style:"form",explode:!0,...V?.array,allowReserved:V?.allowReserved||!1}));continue}if(typeof Y==="object"){X.push(n(W,Y,{style:"deepObject",explode:!0,...V?.object,allowReserved:V?.allowReserved||!1}));continue}X.push(R(W,Y,V))}return X.join("&")}}function IG(V,G){let K=V;for(let X of V.match(DG)??[]){let W=X.substring(1,X.length-1),Y=!1,J="simple";if(W.endsWith("*"))Y=!0,W=W.substring(0,W.length-1);if(W.startsWith("."))J="label",W=W.substring(1);else if(W.startsWith(";"))J="matrix",W=W.substring(1);if(!G||G[W]===void 0||G[W]===null)continue;let D=G[W];if(Array.isArray(D)){K=K.replace(X,s(W,D,{style:J,explode:Y}));continue}if(typeof D==="object"){K=K.replace(X,n(W,D,{style:J,explode:Y}));continue}if(J==="matrix"){K=K.replace(X,`;${R(W,D)}`);continue}K=K.replace(X,J==="label"?`.${encodeURIComponent(D)}`:encodeURIComponent(D))}return K}function TG(V,G){if(V instanceof FormData)return V;if(G){if((G.get instanceof Function?G.get("Content-Type")??G.get("content-type"):G["Content-Type"]??G["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(V).toString()}return JSON.stringify(V)}function EG(V,G){let K=`${G.baseUrl}${V}`;if(G.params?.path)K=G.pathSerializer(K,G.params.path);let X=G.querySerializer(G.params.query??{});if(X.startsWith("?"))X=X.substring(1);if(X)K+=`?${X}`;return K}function u(...V){let G=new Headers;for(let K of V){if(!K||typeof K!=="object")continue;let X=K instanceof Headers?K.entries():Object.entries(K);for(let[W,Y]of X)if(Y===null)G.delete(W);else if(Array.isArray(Y))for(let J of Y)G.append(W,J);else if(Y!==void 0)G.set(W,Y)}return G}function o(V){if(V.endsWith("/"))return V.substring(0,V.length-1);return V}function jG(V,G){if(!G)return{};try{return JSON.parse(G)}catch{return G}}async function*QG(V){let G=V.getReader(),K=new TextDecoder,X="";try{while(!0){let{done:W,value:Y}=await G.read();if(W)break;X+=K.decode(Y,{stream:!0});let J=X.split(`
2
+
3
+ `);X=J.pop()??"";for(let D of J){let k=D.split(`
4
+ `),F="message",E=[];for(let I of k)if(I.startsWith("event:"))F=I.slice(6).trim();else if(I.startsWith("data:")){let Z=I.slice(5);E.push(Z.startsWith(" ")?Z.slice(1):Z)}if(E.length>0){let I=E.join(`
5
+ `);yield{event:F,data:jG(F,I)}}}}}finally{G.releaseLock()}}var t="https://server.kivox.com.co";function i(V){return l(V)}function OG(V={}){let{baseUrl:G=t,version:K="v1",headers:X={}}=V;return{api:i({baseUrl:`${G}/${K}`,credentials:"include",headers:X})}}function HG(V){let{baseUrl:G=t,version:K="v1",headers:X={},bearerToken:W}=V;return{api:i({baseUrl:`${G}/${K}`,headers:{...X,Authorization:`Bearer ${W}`}})}}