uneeq-js 3.13.2 → 3.13.4

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.
@@ -1,2 +1,2 @@
1
- import{a as kt,b as xt,c as Qo,d as dr}from"./chunk-QNPFEGCG.js";var at=xt((ki,Zt)=>{"use strict";Zt.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}});var sr=xt(()=>{});var We=class{getAuthRequest(){return Promise.resolve({headers:{}})}};var lr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Pt={get:(s,e)=>lr(void 0,void 0,void 0,function*(){return typeof s=="function"?s(e):s})};var D=(s,e,o)=>JSON.stringify(s,e,o);function K(s,e){return JSON.parse(s,e)}var q={Debug:"debug",Info:"info",Warn:"warn",Error:"error"},Ct={[q.Debug]:1,[q.Info]:2,[q.Warn]:3,[q.Error]:4},ze=class{debug(e,...o){console.debug(e,...o)}info(e,...o){console.info(e,...o)}warn(e,...o){console.warn(e,...o)}error(e,...o){console.error(e,...o)}},ge=class{constructor(e){this.level=Ct[e.level],this.logger=e.logger,this.silent=e.silent}shouldLog(e){return!this.silent&&this.level<=Ct[e]}isDebug(){return this.shouldLog(q.Debug)}debug(e,...o){this.isDebug()&&this.logger.debug(e,...o)}isInfo(){return this.shouldLog(q.Info)}info(e,...o){this.isInfo()&&this.logger.info(e,...o)}isWarn(){return this.shouldLog(q.Warn)}warn(e,...o){this.isWarn()&&this.logger.warn(e,...o)}isError(){return this.shouldLog(q.Error)}error(e,...o){this.isError()&&this.logger.error(e,...o)}};function Xo(s){var e,o,t;return s==null?cr:s instanceof ge?s:(s=s??{},(e=s.level)!==null&&e!==void 0||(s.level=q.Info),(o=s.logger)!==null&&o!==void 0||(s.logger=new ze),(t=s.silent)!==null&&t!==void 0||(s.silent=!0),new ge(s))}var cr=new ge({level:q.Info,logger:new ze,silent:!0});var ur={arrayFormat:"indices",encode:!0};function jt(s,e){if(s===void 0||s===null)return"";let o=String(s);return e?encodeURIComponent(o):o}function Zo(s,e="",o){let t=[];for(let[r,i]of Object.entries(s)){let a=e?`${e}[${r}]`:r;if(i!==void 0)if(Array.isArray(i)){if(i.length===0)continue;for(let c=0;c<i.length;c++){let u=i[c];if(u!==void 0)if(typeof u=="object"&&!Array.isArray(u)&&u!==null){let d=o.arrayFormat==="indices"?`${a}[${c}]`:a;t.push(...Zo(u,d,o))}else{let d=o.arrayFormat==="indices"?`${a}[${c}]`:a,n=o.encode?encodeURIComponent(d):d;t.push(`${n}=${jt(u,o.encode)}`)}}}else if(typeof i=="object"&&i!==null){if(Object.keys(i).length===0)continue;t.push(...Zo(i,a,o))}else{let c=o.encode?encodeURIComponent(a):a;t.push(`${c}=${jt(i,o.encode)}`)}}return t}function de(s,e){return s==null||typeof s!="object"?"":Zo(s,"",Object.assign(Object.assign({},ur),e)).join("&")}function Tt(s,e){let o=de(e,{arrayFormat:"repeat"});return o?`${s}?${o}`:s}function Dt(s){let e={get bodyUsed(){return s.bodyUsed},stream:()=>s.body,arrayBuffer:s.arrayBuffer.bind(s),blob:s.blob.bind(s)};return"bytes"in s&&typeof s.bytes=="function"&&(e.bytes=s.bytes.bind(s)),e}var hr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function Qe(s,e){return hr(this,void 0,void 0,function*(){switch(e){case"binary-response":return Dt(s);case"blob":return yield s.blob();case"arrayBuffer":return yield s.arrayBuffer();case"sse":return s.body==null?{ok:!1,error:{reason:"body-is-null",statusCode:s.status}}:s.body;case"streaming":return s.body==null?{ok:!1,error:{reason:"body-is-null",statusCode:s.status}}:s.body;case"text":return yield s.text()}let o=yield s.text();if(o.length>0)try{return K(o)}catch{return{ok:!1,error:{reason:"non-json",statusCode:s.status,rawBody:o}}}})}var mr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function It(s){return mr(this,void 0,void 0,function*(){var e,o,t;let r=(e=s.headers.get("Content-Type"))===null||e===void 0?void 0:e.toLowerCase();if(r==null||r.length===0)return Qe(s);switch(r.indexOf(";")!==-1&&(r=(t=(o=r.split(";")[0])===null||o===void 0?void 0:o.trim())!==null&&t!==void 0?t:""),r){case"application/hal+json":case"application/json":case"application/ld+json":case"application/problem+json":case"application/vnd.api+json":case"text/json":{let i=yield s.text();return i.length>0?K(i):void 0}default:if(r.startsWith("application/vnd.")&&r.endsWith("+json")){let i=yield s.text();return i.length>0?K(i):void 0}return yield s.text()}})}var pr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function At(){return pr(this,void 0,void 0,function*(){return fetch})}var _r=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function Lt(s){return _r(this,arguments,void 0,function*({body:e,type:o}){return o==="form"?de(e,{arrayFormat:"repeat",encode:!0}):o.includes("json")?D(e):e})}var le;typeof globalThis.Headers<"u"?le=globalThis.Headers:le=class Mt{constructor(e){if(this.headers=new Map,e)if(e instanceof Mt)e.forEach((o,t)=>this.append(t,o));else if(Array.isArray(e))for(let[o,t]of e)if(typeof o=="string"&&typeof t=="string")this.append(o,t);else throw new TypeError("Each header entry must be a [string, string] tuple");else for(let[o,t]of Object.entries(e))if(typeof t=="string")this.append(o,t);else throw new TypeError("Header values must be strings")}append(e,o){let t=e.toLowerCase(),r=this.headers.get(t)||[];this.headers.set(t,[...r,o])}delete(e){let o=e.toLowerCase();this.headers.delete(o)}get(e){let o=e.toLowerCase(),t=this.headers.get(o);return t?t.join(", "):null}has(e){let o=e.toLowerCase();return this.headers.has(o)}set(e,o){let t=e.toLowerCase();this.headers.set(t,[o])}forEach(e,o){let t=o?e.bind(o):e;this.headers.forEach((r,i)=>t(r.join(", "),i,this))}getSetCookie(){return this.headers.get("set-cookie")||[]}*entries(){for(let[e,o]of this.headers.entries())yield[e,o.join(", ")]}*keys(){yield*this.headers.keys()}*values(){for(let e of this.headers.values())yield e.join(", ")}[Symbol.iterator](){return this.entries()}};var vr="timeout";function Ht(s){let e=new AbortController,o=setTimeout(()=>e.abort(vr),s);return{signal:e.signal,abortId:o}}function Bt(...s){let e=s.length===1&&Array.isArray(s[0])?s[0]:s,o=new AbortController;for(let t of e){if(t.aborted){o.abort(t?.reason);break}t.addEventListener("abort",()=>o.abort(t?.reason),{signal:o.signal})}return o.signal}var fr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},$e;function gr(){if($e!=null)return $e;try{new Request("http://localhost",{cache:"no-store"}),$e=!0}catch{$e=!1}return $e}var Ft=(s,e,o,t,r,i,a,c,u,d)=>fr(void 0,void 0,void 0,function*(){let n=[],l;if(i!=null){let{signal:v,abortId:m}=Ht(i);l=m,n.push(v)}a!=null&&n.push(a);let p=Bt(n),_=yield s(e,Object.assign({method:o,headers:t,body:r,signal:p,credentials:c?"include":void 0,duplex:u},d&&gr()?{cache:"no-store"}:{}));return l!=null&&clearTimeout(l),_});var Oo={headers:new le,redirected:!1,status:499,statusText:"Client Closed Request",type:"error",url:""},qo={headers:new le,redirected:!1,status:0,statusText:"Unknown Error",type:"error",url:""};function et(s){return{headers:s.headers,redirected:s.redirected,status:s.status,statusText:s.statusText,type:s.type,url:s.url}}var yr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function wr(s){let e=1+Math.random()*.2;return s*e}function br(s){let e=1+(Math.random()-.5)*.2;return s*e}function Rr(s,e){let o=s.headers.get("Retry-After");if(o){let r=parseInt(o,10);if(!Number.isNaN(r)&&r>0)return Math.min(r*1e3,6e4);let i=new Date(o);if(!Number.isNaN(i.getTime())){let a=i.getTime()-Date.now();if(a>0)return Math.min(Math.max(a,0),6e4)}}let t=s.headers.get("X-RateLimit-Reset");if(t){let r=parseInt(t,10);if(!Number.isNaN(r)){let i=r*1e3-Date.now();if(i>0)return wr(Math.min(i,6e4))}}return br(Math.min(1e3*Math.pow(2,e),6e4))}function Nt(s){return yr(this,arguments,void 0,function*(e,o=2){let t=yield e();for(let r=0;r<o&&([408,429].includes(t.status)||t.status>=500);++r){let i=Rr(t,r);yield new Promise(a=>setTimeout(a,i)),t=yield e()}return t})}var tt=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Er=new Set(["authorization","www-authenticate","x-api-key","api-key","apikey","x-api-token","x-auth-token","auth-token","cookie","set-cookie","proxy-authorization","proxy-authenticate","x-csrf-token","x-xsrf-token","x-session-token","x-access-token"]);function ot(s){let e={};for(let[o,t]of s instanceof le?s.entries():Object.entries(s))Er.has(o.toLowerCase())?e[o]="[REDACTED]":e[o]=t;return e}var rt=new Set(["api_key","api-key","apikey","token","access_token","access-token","auth_token","auth-token","password","passwd","secret","api_secret","api-secret","apisecret","key","session","session_id","session-id"]);function Sr(s){if(s==null)return s;let e={};for(let[o,t]of Object.entries(s))rt.has(o.toLowerCase())?e[o]="[REDACTED]":e[o]=t;return e}function _e(s){let e=s.indexOf("://");if(e===-1)return s;let o=e+3,t=s.indexOf("/",o),r=s.indexOf("?",o),i=s.indexOf("#",o),a=Math.min(t===-1?s.length:t,r===-1?s.length:r,i===-1?s.length:i),c=-1;for(let v=o;v<a;v++)s[v]==="@"&&(c=v);if(c!==-1&&(s=`${s.slice(0,o)}[REDACTED]@${s.slice(c+1)}`),r=s.indexOf("?"),r===-1)return s;i=s.indexOf("#",r);let u=i!==-1?i:s.length,d=s.slice(r+1,u);if(d.length===0)return s;let n=d.toLowerCase();if(!(n.includes("token")||n.includes("key")||n.includes("password")||n.includes("passwd")||n.includes("secret")||n.includes("session")||n.includes("auth")))return s;let p=[],_=d.split("&");for(let v of _){let m=v.indexOf("=");if(m===-1){p.push(v);continue}let h=v.slice(0,m),y=rt.has(h.toLowerCase());if(!y&&h.includes("%"))try{let T=decodeURIComponent(h);y=rt.has(T.toLowerCase())}catch{}p.push(y?`${h}=[REDACTED]`:v)}return s.slice(0,r+1)+p.join("&")+s.slice(u)}function kr(s){return tt(this,void 0,void 0,function*(){var e;let o=new le;if(o.set("Accept",s.responseType==="json"?"application/json":s.responseType==="text"?"text/plain":s.responseType==="sse"?"text/event-stream":"*/*"),s.body!==void 0&&s.contentType!=null&&o.set("Content-Type",s.contentType),s.headers==null)return o;for(let[t,r]of Object.entries(s.headers)){let i=yield Pt.get(r,{endpointMetadata:(e=s.endpointMetadata)!==null&&e!==void 0?e:{}});if(typeof i=="string"){o.set(t,i);continue}i!=null&&o.set(t,`${i}`)}return o})}function xr(s){return tt(this,void 0,void 0,function*(){var e,o,t;let r=Tt(s.url,s.queryParameters),i=yield Lt({body:s.body,type:(e=s.requestType)!==null&&e!==void 0?e:"other"}),a=(o=s.fetchFn)!==null&&o!==void 0?o:yield At(),c=yield kr(s),u=Xo(s.logging);if(u.isDebug()){let d={method:s.method,url:_e(r),headers:ot(c),queryParameters:Sr(s.queryParameters),hasBody:i!=null};u.debug("Making HTTP request",d)}try{let d=yield Nt(()=>tt(this,void 0,void 0,function*(){return Ft(a,r,s.method,c,i,s.timeoutMs,s.abortSignal,s.withCredentials,s.duplex,s.responseType==="streaming"||s.responseType==="sse")}),s.maxRetries);if(d.status>=200&&d.status<400){if(u.isDebug()){let l={method:s.method,url:_e(r),statusCode:d.status,responseHeaders:ot(d.headers)};u.debug("HTTP request succeeded",l)}return{ok:!0,body:yield Qe(d,s.responseType),headers:d.headers,rawResponse:et(d)}}else{if(u.isError()){let n={method:s.method,url:_e(r),statusCode:d.status,responseHeaders:ot(Object.fromEntries(d.headers.entries()))};u.error("HTTP request failed with error status",n)}return{ok:!1,error:{reason:"status-code",statusCode:d.status,body:yield It(d)},rawResponse:et(d)}}}catch(d){if(!((t=s.abortSignal)===null||t===void 0)&&t.aborted){if(u.isError()){let n={method:s.method,url:_e(r)};u.error("HTTP request was aborted",n)}return{ok:!1,error:{reason:"unknown",errorMessage:"The user aborted a request"},rawResponse:Oo}}else if(d instanceof Error&&d.name==="AbortError"){if(u.isError()){let n={method:s.method,url:_e(r),timeoutMs:s.timeoutMs};u.error("HTTP request timed out",n)}return{ok:!1,error:{reason:"timeout"},rawResponse:Oo}}else if(d instanceof Error){if(u.isError()){let n={method:s.method,url:_e(r),errorMessage:d.message};u.error("HTTP request failed with error",n)}return{ok:!1,error:{reason:"unknown",errorMessage:d.message},rawResponse:qo}}if(u.isError()){let n={method:s.method,url:_e(r),error:D(d)};u.error("HTTP request failed with unknown error",n)}return{ok:!1,error:{reason:"unknown",errorMessage:D(d)},rawResponse:qo}}})}var C=xr;var Pr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},k=class s extends Promise{constructor(e){super(o=>{o(void 0)}),this.innerPromise=e}static fromFunction(e,...o){return new s(e(...o))}static interceptFunction(e){return(...o)=>s.fromPromise(e(...o))}static fromPromise(e){return new s(e)}static fromExecutor(e){let o=new Promise(e);return new s(o)}static fromResult(e){let o=Promise.resolve(e);return new s(o)}unwrap(){return this.unwrappedPromise||(this.unwrappedPromise=this.innerPromise.then(({data:e})=>e)),this.unwrappedPromise}then(e,o){return this.unwrap().then(e,o)}catch(e){return this.unwrap().catch(e)}finally(e){return this.unwrap().finally(e)}withRawResponse(){return Pr(this,void 0,void 0,function*(){return yield this.innerPromise})}};var Cr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},f={get:s=>Cr(void 0,void 0,void 0,function*(){return typeof s=="function"?s():s})};var Xe={};Qo(Xe,{toBinaryUploadRequest:()=>jr,toMultipartDataPart:()=>Tr});var Ge=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function jr(s){return Ge(this,void 0,void 0,function*(){let{data:e,filename:o,contentLength:t,contentType:r}=yield nt(s),i={body:e,headers:{}};return o&&(i.headers["Content-Disposition"]=`attachment; filename="${o}"`),r&&(i.headers["Content-Type"]=r),t!=null&&(i.headers["Content-Length"]=t.toString()),i})}function Tr(s){return Ge(this,void 0,void 0,function*(){let{data:e,filename:o,contentType:t}=yield nt(s,{noSniffFileSize:!0});return{data:e,filename:o,contentType:t}})}function nt(s){return Ge(this,arguments,void 0,function*(e,{noSniffFileSize:o}={}){var t,r,i,a,c;if(Dr(e))return nt({data:e},{noSniffFileSize:o});if("path"in e){let u=yield import("./fs-TPREOTZZ.js");if(!u||!u.createReadStream)throw new Error("File path uploads are not supported in this environment.");let d=u.createReadStream(e.path),n=(t=e.contentLength)!==null&&t!==void 0?t:o===!0?void 0:yield Ut(e.path),l=(r=e.filename)!==null&&r!==void 0?r:Wt(e.path);return{data:d,filename:l,contentType:e.contentType,contentLength:n}}if("data"in e){let u=e.data,d=(i=e.contentLength)!==null&&i!==void 0?i:yield Ar(u,{noSniffFileSize:o}),n=(a=e.filename)!==null&&a!==void 0?a:Ir(u);return{data:u,filename:n,contentType:(c=e.contentType)!==null&&c!==void 0?c:Lr(u),contentLength:d}}throw new Error(`Invalid FileUpload of type ${typeof e}: ${JSON.stringify(e)}`)})}function Dr(s){return $t(s)||Gt(s)||Jt(s)||Fr(s)||it(s)||st(s)||Hr(s)||Br(s)}function Ut(s){return Ge(this,void 0,void 0,function*(){try{let e=yield import("./fs-TPREOTZZ.js");return!e||!e.promises||!e.promises.stat?void 0:(yield e.promises.stat(s)).size}catch{return}})}function Ir(s){if(Mr(s))return s.name;if(zt(s))return Wt(s.path.toString())}function Ar(s){return Ge(this,arguments,void 0,function*(e,{noSniffFileSize:o}={}){if($t(e))return e.length;if(Gt(e)||Jt(e))return e.byteLength;if(it(e)||st(e))return e.size;if(o!==!0&&zt(e))return yield Ut(e.path.toString())})}function Lr(s){if(it(s)||st(s))return s.type}function Wt(s){let e=s.lastIndexOf("/"),o=s.lastIndexOf("\\"),t=Math.max(e,o);return t>=0?s.substring(t+1):s}function Mr(s){return typeof s=="object"&&s!=null&&"name"in s}function zt(s){return typeof s=="object"&&s!=null&&"path"in s}function Hr(s){return typeof s=="object"&&s!=null&&("read"in s||"pipe"in s)}function Br(s){return typeof s=="object"&&s!=null&&"getReader"in s}function $t(s){return typeof Buffer<"u"&&Buffer.isBuffer&&Buffer.isBuffer(s)}function Gt(s){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(s)}function Jt(s){return typeof ArrayBuffer<"u"&&s instanceof ArrayBuffer}function Fr(s){return typeof Uint8Array<"u"&&s instanceof Uint8Array}function it(s){return typeof Blob<"u"&&s instanceof Blob}function st(s){return typeof File<"u"&&s instanceof File}var Ze={};Qo(Ze,{ConsoleLogger:()=>ze,LogLevel:()=>q,Logger:()=>ge,createLogger:()=>Xo});var O=Nr();function Nr(){var s,e,o,t,r;if(typeof window<"u"&&typeof window.document<"u")return{type:"browser",version:window.navigator.userAgent};if(typeof globalThis<"u"&&((s=globalThis?.navigator)===null||s===void 0?void 0:s.userAgent)==="Cloudflare-Workers")return{type:"workerd"};if(typeof EdgeRuntime=="string")return{type:"edge-runtime"};if(typeof self=="object"&&typeof self?.importScripts=="function"&&(((e=self.constructor)===null||e===void 0?void 0:e.name)==="DedicatedWorkerGlobalScope"||((o=self.constructor)===null||o===void 0?void 0:o.name)==="ServiceWorkerGlobalScope"||((t=self.constructor)===null||t===void 0?void 0:t.name)==="SharedWorkerGlobalScope"))return{type:"web-worker"};if(typeof Deno<"u"&&typeof Deno.version<"u"&&typeof Deno.version.deno<"u")return{type:"deno",version:Deno.version.deno};if(typeof Bun<"u"&&typeof Bun.version<"u")return{type:"bun",version:Bun.version};if(typeof navigator<"u"&&navigator?.product==="ReactNative")return{type:"react-native"};let p=typeof process<"u"?process:void 0;return typeof p<"u"&&typeof((r=p.versions)===null||r===void 0?void 0:r.node)=="string"?{type:"node",version:p.versions.node,parsedVersion:Number(p.versions.node.split(".")[0])}:{type:"unknown"}}var g={};Qo(g,{encodePathParam:()=>Kt,join:()=>Yt,toQueryString:()=>de});function Kt(s){if(s===null)return"null";switch(typeof s){case"undefined":return"undefined";case"string":case"number":case"boolean":break;default:s=String(s);break}return encodeURIComponent(s)}function Yt(s,...e){if(!s)return"";if(e.length===0)return s;if(s.includes("://")){let o;try{o=new URL(s)}catch{return Vt(s,...e)}let t=e[e.length-1],r=t?.endsWith("/");for(let i of e){let a=Xt(i);a&&(o.pathname=Qt(o.pathname,a))}return r&&!o.pathname.endsWith("/")&&(o.pathname+="/"),o.toString()}return Vt(s,...e)}function Vt(s,...e){if(e.length===0)return s;let o=s,t=e[e.length-1],r=t?.endsWith("/");for(let i of e){let a=Xt(i);a&&(o=Qt(o,a))}return r&&!o.endsWith("/")&&(o+="/"),o}function Qt(s,e){return s.endsWith("/")?s+e:`${s}/${e}`}function Xt(s){if(!s)return s;let e=0,o=s.length;return s.startsWith("/")&&(e=1),s.endsWith("/")&&(o=s.length-1),e===0&&o===s.length?s:s.slice(e,o)}var Ot=dr(at(),1);var Oe=class{constructor(e,o){this.target=o,this.type=e}},qe=class extends Oe{constructor(e,o){super("error",o),this.message=e.message,this.error=e}},Je=class extends Oe{constructor(e=1e3,o="",t){super("close",t),this.wasClean=!0,this.code=e,this.reason=o}};var Wr=()=>{if(typeof WebSocket<"u")return WebSocket;if(O.type==="node")return Ot.WebSocket},zr=s=>typeof s<"u"&&!!s&&s.CLOSING===2,ce={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},H=class s{constructor({url:e,protocols:o,options:t,headers:r,queryParameters:i,abortSignal:a}){this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.CONNECTING=s.CONNECTING,this.OPEN=s.OPEN,this.CLOSING=s.CLOSING,this.CLOSED=s.CLOSED,this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleAbort=()=>{if(!this._closeCalled&&(this._debug("abort signal fired"),this._shouldReconnect=!1,this._closeCalled=!0,this._clearTimeouts(),this._ws)){this._removeListeners();try{this._ws.close(1e3,"aborted"),this._handleClose(new Je(1e3,"aborted",this))}catch{}}},this._handleOpen=c=>{this._debug("open event");let{minUptime:u=ce.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),u),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(d=>{var n;return(n=this._ws)===null||n===void 0?void 0:n.send(d)}),this._messageQueue=[],this.onopen&&this.onopen(c),this._listeners.open.forEach(d=>this._callEventListener(c,d))},this._handleMessage=c=>{this._debug("message event"),this.onmessage&&this.onmessage(c),this._listeners.message.forEach(u=>this._callEventListener(c,u))},this._handleError=c=>{this._debug("error event",c.message),this._disconnect(void 0,c.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(c),this._debug("exec error listeners"),this._listeners.error.forEach(u=>this._callEventListener(c,u)),this._connect()},this._handleClose=c=>{this._debug("close event"),this._clearTimeouts(),c.code===1e3&&(this._shouldReconnect=!1),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(c),this._listeners.close.forEach(u=>this._callEventListener(c,u))},this._url=e,this._protocols=o,this._options=t??ce,this._headers=r,this._queryParameters=i,this._abortSignal=a,this._abortSignal&&this._abortSignal.addEventListener("abort",this._handleAbort,{once:!0}),this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((o,t)=>(typeof t=="string"?o+=t.length:t instanceof Blob?o+=t.size:o+=t.byteLength,o),0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._ws?this._ws.readyState:this._options.startClosed?s.CLOSED:s.CONNECTING}get url(){return this._ws?this._ws.url:""}close(e=1e3,o){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED){this._debug("close: already closed");return}this._ws.close(e,o)}reconnect(e,o){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(e,o),this._connect())}send(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{let{maxEnqueuedMessages:o=ce.maxEnqueuedMessages}=this._options;this._messageQueue.length<o&&(this._debug("enqueue",e),this._messageQueue.push(e))}}addEventListener(e,o){this._listeners[e]&&this._listeners[e].push(o)}dispatchEvent(e){let o=this._listeners[e.type];if(o)for(let t of o)this._callEventListener(e,t);return!0}removeEventListener(e,o){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter(t=>t!==o))}_debug(...e){this._options.debug&&console.log.apply(console,["RWS>",...e])}_getNextDelay(){let{reconnectionDelayGrowFactor:e=ce.reconnectionDelayGrowFactor,minReconnectionDelay:o=ce.minReconnectionDelay,maxReconnectionDelay:t=ce.maxReconnectionDelay}=this._options,r=0;return this._retryCount>0&&(r=o*Math.pow(e,this._retryCount-1),r>t&&(r=t)),this._debug("next delay",r),r}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_getNextUrl(e){if(typeof e=="string")return Promise.resolve(e);if(typeof e=="function"){let o=e();if(typeof o=="string")return Promise.resolve(o);if(o.then)return o}throw Error("Invalid URL")}_connect(){var e;if(this._connectLock||!this._shouldReconnect)return;if(!((e=this._abortSignal)===null||e===void 0)&&e.aborted){this._debug("connect aborted");return}this._connectLock=!0;let{maxRetries:o=ce.maxRetries,connectionTimeout:t=ce.connectionTimeout,WebSocket:r=Wr()}=this._options;if(this._retryCount>=o){this._debug("max retries reached",this._retryCount,">=",o);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!zr(r))throw Error("No valid WebSocket class provided");this._wait().then(()=>this._getNextUrl(this._url)).then(i=>{var a;if(this._closeCalled||!((a=this._abortSignal)===null||a===void 0)&&a.aborted){this._connectLock=!1;return}let c={};if(this._headers&&(c.headers=this._headers),this._queryParameters&&Object.keys(this._queryParameters).length>0){let u=de(this._queryParameters,{arrayFormat:"repeat"});u&&(i=`${i}?${u}`)}this._ws=new r(i,this._protocols,c),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),t)})}_handleTimeout(){this._debug("timeout event"),this._handleError(new qe(Error("TIMEOUT"),this))}_disconnect(e=1e3,o){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(e,o),this._handleClose(new Je(e,o,this))}catch{}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_callEventListener(e,o){"handleEvent"in o?o.handleEvent(e):o(e)}_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}};H.CONNECTING=0;H.OPEN=1;H.CLOSING=2;H.CLOSED=3;var w=class extends Error{constructor({message:e,statusCode:o,body:t,rawResponse:r}){super($r({message:e,statusCode:o,body:t})),Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.statusCode=o,this.body=t,this.rawResponse=r}};function $r({message:s,statusCode:e,body:o}){let t=[];return s!=null&&t.push(s),e!=null&&t.push(`Status code: ${e.toString()}`),o!=null&&t.push(`Body: ${D(o,void 0,2)}`),t.join(`
1
+ import{a as kt,b as xt,c as Qo,d as dr}from"./chunk-6GQSOKKS.js";var at=xt((ki,Zt)=>{"use strict";Zt.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}});var sr=xt(()=>{});var We=class{getAuthRequest(){return Promise.resolve({headers:{}})}};var lr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Pt={get:(s,e)=>lr(void 0,void 0,void 0,function*(){return typeof s=="function"?s(e):s})};var D=(s,e,o)=>JSON.stringify(s,e,o);function K(s,e){return JSON.parse(s,e)}var q={Debug:"debug",Info:"info",Warn:"warn",Error:"error"},Ct={[q.Debug]:1,[q.Info]:2,[q.Warn]:3,[q.Error]:4},ze=class{debug(e,...o){console.debug(e,...o)}info(e,...o){console.info(e,...o)}warn(e,...o){console.warn(e,...o)}error(e,...o){console.error(e,...o)}},ge=class{constructor(e){this.level=Ct[e.level],this.logger=e.logger,this.silent=e.silent}shouldLog(e){return!this.silent&&this.level<=Ct[e]}isDebug(){return this.shouldLog(q.Debug)}debug(e,...o){this.isDebug()&&this.logger.debug(e,...o)}isInfo(){return this.shouldLog(q.Info)}info(e,...o){this.isInfo()&&this.logger.info(e,...o)}isWarn(){return this.shouldLog(q.Warn)}warn(e,...o){this.isWarn()&&this.logger.warn(e,...o)}isError(){return this.shouldLog(q.Error)}error(e,...o){this.isError()&&this.logger.error(e,...o)}};function Xo(s){var e,o,t;return s==null?cr:s instanceof ge?s:(s=s??{},(e=s.level)!==null&&e!==void 0||(s.level=q.Info),(o=s.logger)!==null&&o!==void 0||(s.logger=new ze),(t=s.silent)!==null&&t!==void 0||(s.silent=!0),new ge(s))}var cr=new ge({level:q.Info,logger:new ze,silent:!0});var ur={arrayFormat:"indices",encode:!0};function jt(s,e){if(s===void 0||s===null)return"";let o=String(s);return e?encodeURIComponent(o):o}function Zo(s,e="",o){let t=[];for(let[r,i]of Object.entries(s)){let a=e?`${e}[${r}]`:r;if(i!==void 0)if(Array.isArray(i)){if(i.length===0)continue;for(let c=0;c<i.length;c++){let u=i[c];if(u!==void 0)if(typeof u=="object"&&!Array.isArray(u)&&u!==null){let d=o.arrayFormat==="indices"?`${a}[${c}]`:a;t.push(...Zo(u,d,o))}else{let d=o.arrayFormat==="indices"?`${a}[${c}]`:a,n=o.encode?encodeURIComponent(d):d;t.push(`${n}=${jt(u,o.encode)}`)}}}else if(typeof i=="object"&&i!==null){if(Object.keys(i).length===0)continue;t.push(...Zo(i,a,o))}else{let c=o.encode?encodeURIComponent(a):a;t.push(`${c}=${jt(i,o.encode)}`)}}return t}function de(s,e){return s==null||typeof s!="object"?"":Zo(s,"",Object.assign(Object.assign({},ur),e)).join("&")}function Tt(s,e){let o=de(e,{arrayFormat:"repeat"});return o?`${s}?${o}`:s}function Dt(s){let e={get bodyUsed(){return s.bodyUsed},stream:()=>s.body,arrayBuffer:s.arrayBuffer.bind(s),blob:s.blob.bind(s)};return"bytes"in s&&typeof s.bytes=="function"&&(e.bytes=s.bytes.bind(s)),e}var hr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function Qe(s,e){return hr(this,void 0,void 0,function*(){switch(e){case"binary-response":return Dt(s);case"blob":return yield s.blob();case"arrayBuffer":return yield s.arrayBuffer();case"sse":return s.body==null?{ok:!1,error:{reason:"body-is-null",statusCode:s.status}}:s.body;case"streaming":return s.body==null?{ok:!1,error:{reason:"body-is-null",statusCode:s.status}}:s.body;case"text":return yield s.text()}let o=yield s.text();if(o.length>0)try{return K(o)}catch{return{ok:!1,error:{reason:"non-json",statusCode:s.status,rawBody:o}}}})}var mr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function It(s){return mr(this,void 0,void 0,function*(){var e,o,t;let r=(e=s.headers.get("Content-Type"))===null||e===void 0?void 0:e.toLowerCase();if(r==null||r.length===0)return Qe(s);switch(r.indexOf(";")!==-1&&(r=(t=(o=r.split(";")[0])===null||o===void 0?void 0:o.trim())!==null&&t!==void 0?t:""),r){case"application/hal+json":case"application/json":case"application/ld+json":case"application/problem+json":case"application/vnd.api+json":case"text/json":{let i=yield s.text();return i.length>0?K(i):void 0}default:if(r.startsWith("application/vnd.")&&r.endsWith("+json")){let i=yield s.text();return i.length>0?K(i):void 0}return yield s.text()}})}var pr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function At(){return pr(this,void 0,void 0,function*(){return fetch})}var _r=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function Lt(s){return _r(this,arguments,void 0,function*({body:e,type:o}){return o==="form"?de(e,{arrayFormat:"repeat",encode:!0}):o.includes("json")?D(e):e})}var le;typeof globalThis.Headers<"u"?le=globalThis.Headers:le=class Mt{constructor(e){if(this.headers=new Map,e)if(e instanceof Mt)e.forEach((o,t)=>this.append(t,o));else if(Array.isArray(e))for(let[o,t]of e)if(typeof o=="string"&&typeof t=="string")this.append(o,t);else throw new TypeError("Each header entry must be a [string, string] tuple");else for(let[o,t]of Object.entries(e))if(typeof t=="string")this.append(o,t);else throw new TypeError("Header values must be strings")}append(e,o){let t=e.toLowerCase(),r=this.headers.get(t)||[];this.headers.set(t,[...r,o])}delete(e){let o=e.toLowerCase();this.headers.delete(o)}get(e){let o=e.toLowerCase(),t=this.headers.get(o);return t?t.join(", "):null}has(e){let o=e.toLowerCase();return this.headers.has(o)}set(e,o){let t=e.toLowerCase();this.headers.set(t,[o])}forEach(e,o){let t=o?e.bind(o):e;this.headers.forEach((r,i)=>t(r.join(", "),i,this))}getSetCookie(){return this.headers.get("set-cookie")||[]}*entries(){for(let[e,o]of this.headers.entries())yield[e,o.join(", ")]}*keys(){yield*this.headers.keys()}*values(){for(let e of this.headers.values())yield e.join(", ")}[Symbol.iterator](){return this.entries()}};var vr="timeout";function Ht(s){let e=new AbortController,o=setTimeout(()=>e.abort(vr),s);return{signal:e.signal,abortId:o}}function Bt(...s){let e=s.length===1&&Array.isArray(s[0])?s[0]:s,o=new AbortController;for(let t of e){if(t.aborted){o.abort(t?.reason);break}t.addEventListener("abort",()=>o.abort(t?.reason),{signal:o.signal})}return o.signal}var fr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},$e;function gr(){if($e!=null)return $e;try{new Request("http://localhost",{cache:"no-store"}),$e=!0}catch{$e=!1}return $e}var Ft=(s,e,o,t,r,i,a,c,u,d)=>fr(void 0,void 0,void 0,function*(){let n=[],l;if(i!=null){let{signal:v,abortId:m}=Ht(i);l=m,n.push(v)}a!=null&&n.push(a);let p=Bt(n),_=yield s(e,Object.assign({method:o,headers:t,body:r,signal:p,credentials:c?"include":void 0,duplex:u},d&&gr()?{cache:"no-store"}:{}));return l!=null&&clearTimeout(l),_});var Oo={headers:new le,redirected:!1,status:499,statusText:"Client Closed Request",type:"error",url:""},qo={headers:new le,redirected:!1,status:0,statusText:"Unknown Error",type:"error",url:""};function et(s){return{headers:s.headers,redirected:s.redirected,status:s.status,statusText:s.statusText,type:s.type,url:s.url}}var yr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function wr(s){let e=1+Math.random()*.2;return s*e}function br(s){let e=1+(Math.random()-.5)*.2;return s*e}function Rr(s,e){let o=s.headers.get("Retry-After");if(o){let r=parseInt(o,10);if(!Number.isNaN(r)&&r>0)return Math.min(r*1e3,6e4);let i=new Date(o);if(!Number.isNaN(i.getTime())){let a=i.getTime()-Date.now();if(a>0)return Math.min(Math.max(a,0),6e4)}}let t=s.headers.get("X-RateLimit-Reset");if(t){let r=parseInt(t,10);if(!Number.isNaN(r)){let i=r*1e3-Date.now();if(i>0)return wr(Math.min(i,6e4))}}return br(Math.min(1e3*Math.pow(2,e),6e4))}function Nt(s){return yr(this,arguments,void 0,function*(e,o=2){let t=yield e();for(let r=0;r<o&&([408,429].includes(t.status)||t.status>=500);++r){let i=Rr(t,r);yield new Promise(a=>setTimeout(a,i)),t=yield e()}return t})}var tt=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Er=new Set(["authorization","www-authenticate","x-api-key","api-key","apikey","x-api-token","x-auth-token","auth-token","cookie","set-cookie","proxy-authorization","proxy-authenticate","x-csrf-token","x-xsrf-token","x-session-token","x-access-token"]);function ot(s){let e={};for(let[o,t]of s instanceof le?s.entries():Object.entries(s))Er.has(o.toLowerCase())?e[o]="[REDACTED]":e[o]=t;return e}var rt=new Set(["api_key","api-key","apikey","token","access_token","access-token","auth_token","auth-token","password","passwd","secret","api_secret","api-secret","apisecret","key","session","session_id","session-id"]);function Sr(s){if(s==null)return s;let e={};for(let[o,t]of Object.entries(s))rt.has(o.toLowerCase())?e[o]="[REDACTED]":e[o]=t;return e}function _e(s){let e=s.indexOf("://");if(e===-1)return s;let o=e+3,t=s.indexOf("/",o),r=s.indexOf("?",o),i=s.indexOf("#",o),a=Math.min(t===-1?s.length:t,r===-1?s.length:r,i===-1?s.length:i),c=-1;for(let v=o;v<a;v++)s[v]==="@"&&(c=v);if(c!==-1&&(s=`${s.slice(0,o)}[REDACTED]@${s.slice(c+1)}`),r=s.indexOf("?"),r===-1)return s;i=s.indexOf("#",r);let u=i!==-1?i:s.length,d=s.slice(r+1,u);if(d.length===0)return s;let n=d.toLowerCase();if(!(n.includes("token")||n.includes("key")||n.includes("password")||n.includes("passwd")||n.includes("secret")||n.includes("session")||n.includes("auth")))return s;let p=[],_=d.split("&");for(let v of _){let m=v.indexOf("=");if(m===-1){p.push(v);continue}let h=v.slice(0,m),y=rt.has(h.toLowerCase());if(!y&&h.includes("%"))try{let T=decodeURIComponent(h);y=rt.has(T.toLowerCase())}catch{}p.push(y?`${h}=[REDACTED]`:v)}return s.slice(0,r+1)+p.join("&")+s.slice(u)}function kr(s){return tt(this,void 0,void 0,function*(){var e;let o=new le;if(o.set("Accept",s.responseType==="json"?"application/json":s.responseType==="text"?"text/plain":s.responseType==="sse"?"text/event-stream":"*/*"),s.body!==void 0&&s.contentType!=null&&o.set("Content-Type",s.contentType),s.headers==null)return o;for(let[t,r]of Object.entries(s.headers)){let i=yield Pt.get(r,{endpointMetadata:(e=s.endpointMetadata)!==null&&e!==void 0?e:{}});if(typeof i=="string"){o.set(t,i);continue}i!=null&&o.set(t,`${i}`)}return o})}function xr(s){return tt(this,void 0,void 0,function*(){var e,o,t;let r=Tt(s.url,s.queryParameters),i=yield Lt({body:s.body,type:(e=s.requestType)!==null&&e!==void 0?e:"other"}),a=(o=s.fetchFn)!==null&&o!==void 0?o:yield At(),c=yield kr(s),u=Xo(s.logging);if(u.isDebug()){let d={method:s.method,url:_e(r),headers:ot(c),queryParameters:Sr(s.queryParameters),hasBody:i!=null};u.debug("Making HTTP request",d)}try{let d=yield Nt(()=>tt(this,void 0,void 0,function*(){return Ft(a,r,s.method,c,i,s.timeoutMs,s.abortSignal,s.withCredentials,s.duplex,s.responseType==="streaming"||s.responseType==="sse")}),s.maxRetries);if(d.status>=200&&d.status<400){if(u.isDebug()){let l={method:s.method,url:_e(r),statusCode:d.status,responseHeaders:ot(d.headers)};u.debug("HTTP request succeeded",l)}return{ok:!0,body:yield Qe(d,s.responseType),headers:d.headers,rawResponse:et(d)}}else{if(u.isError()){let n={method:s.method,url:_e(r),statusCode:d.status,responseHeaders:ot(Object.fromEntries(d.headers.entries()))};u.error("HTTP request failed with error status",n)}return{ok:!1,error:{reason:"status-code",statusCode:d.status,body:yield It(d)},rawResponse:et(d)}}}catch(d){if(!((t=s.abortSignal)===null||t===void 0)&&t.aborted){if(u.isError()){let n={method:s.method,url:_e(r)};u.error("HTTP request was aborted",n)}return{ok:!1,error:{reason:"unknown",errorMessage:"The user aborted a request"},rawResponse:Oo}}else if(d instanceof Error&&d.name==="AbortError"){if(u.isError()){let n={method:s.method,url:_e(r),timeoutMs:s.timeoutMs};u.error("HTTP request timed out",n)}return{ok:!1,error:{reason:"timeout"},rawResponse:Oo}}else if(d instanceof Error){if(u.isError()){let n={method:s.method,url:_e(r),errorMessage:d.message};u.error("HTTP request failed with error",n)}return{ok:!1,error:{reason:"unknown",errorMessage:d.message},rawResponse:qo}}if(u.isError()){let n={method:s.method,url:_e(r),error:D(d)};u.error("HTTP request failed with unknown error",n)}return{ok:!1,error:{reason:"unknown",errorMessage:D(d)},rawResponse:qo}}})}var C=xr;var Pr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},k=class s extends Promise{constructor(e){super(o=>{o(void 0)}),this.innerPromise=e}static fromFunction(e,...o){return new s(e(...o))}static interceptFunction(e){return(...o)=>s.fromPromise(e(...o))}static fromPromise(e){return new s(e)}static fromExecutor(e){let o=new Promise(e);return new s(o)}static fromResult(e){let o=Promise.resolve(e);return new s(o)}unwrap(){return this.unwrappedPromise||(this.unwrappedPromise=this.innerPromise.then(({data:e})=>e)),this.unwrappedPromise}then(e,o){return this.unwrap().then(e,o)}catch(e){return this.unwrap().catch(e)}finally(e){return this.unwrap().finally(e)}withRawResponse(){return Pr(this,void 0,void 0,function*(){return yield this.innerPromise})}};var Cr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},f={get:s=>Cr(void 0,void 0,void 0,function*(){return typeof s=="function"?s():s})};var Xe={};Qo(Xe,{toBinaryUploadRequest:()=>jr,toMultipartDataPart:()=>Tr});var Ge=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})};function jr(s){return Ge(this,void 0,void 0,function*(){let{data:e,filename:o,contentLength:t,contentType:r}=yield nt(s),i={body:e,headers:{}};return o&&(i.headers["Content-Disposition"]=`attachment; filename="${o}"`),r&&(i.headers["Content-Type"]=r),t!=null&&(i.headers["Content-Length"]=t.toString()),i})}function Tr(s){return Ge(this,void 0,void 0,function*(){let{data:e,filename:o,contentType:t}=yield nt(s,{noSniffFileSize:!0});return{data:e,filename:o,contentType:t}})}function nt(s){return Ge(this,arguments,void 0,function*(e,{noSniffFileSize:o}={}){var t,r,i,a,c;if(Dr(e))return nt({data:e},{noSniffFileSize:o});if("path"in e){let u=yield import("./fs-TPREOTZZ.js");if(!u||!u.createReadStream)throw new Error("File path uploads are not supported in this environment.");let d=u.createReadStream(e.path),n=(t=e.contentLength)!==null&&t!==void 0?t:o===!0?void 0:yield Ut(e.path),l=(r=e.filename)!==null&&r!==void 0?r:Wt(e.path);return{data:d,filename:l,contentType:e.contentType,contentLength:n}}if("data"in e){let u=e.data,d=(i=e.contentLength)!==null&&i!==void 0?i:yield Ar(u,{noSniffFileSize:o}),n=(a=e.filename)!==null&&a!==void 0?a:Ir(u);return{data:u,filename:n,contentType:(c=e.contentType)!==null&&c!==void 0?c:Lr(u),contentLength:d}}throw new Error(`Invalid FileUpload of type ${typeof e}: ${JSON.stringify(e)}`)})}function Dr(s){return $t(s)||Gt(s)||Jt(s)||Fr(s)||it(s)||st(s)||Hr(s)||Br(s)}function Ut(s){return Ge(this,void 0,void 0,function*(){try{let e=yield import("./fs-TPREOTZZ.js");return!e||!e.promises||!e.promises.stat?void 0:(yield e.promises.stat(s)).size}catch{return}})}function Ir(s){if(Mr(s))return s.name;if(zt(s))return Wt(s.path.toString())}function Ar(s){return Ge(this,arguments,void 0,function*(e,{noSniffFileSize:o}={}){if($t(e))return e.length;if(Gt(e)||Jt(e))return e.byteLength;if(it(e)||st(e))return e.size;if(o!==!0&&zt(e))return yield Ut(e.path.toString())})}function Lr(s){if(it(s)||st(s))return s.type}function Wt(s){let e=s.lastIndexOf("/"),o=s.lastIndexOf("\\"),t=Math.max(e,o);return t>=0?s.substring(t+1):s}function Mr(s){return typeof s=="object"&&s!=null&&"name"in s}function zt(s){return typeof s=="object"&&s!=null&&"path"in s}function Hr(s){return typeof s=="object"&&s!=null&&("read"in s||"pipe"in s)}function Br(s){return typeof s=="object"&&s!=null&&"getReader"in s}function $t(s){return typeof Buffer<"u"&&Buffer.isBuffer&&Buffer.isBuffer(s)}function Gt(s){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(s)}function Jt(s){return typeof ArrayBuffer<"u"&&s instanceof ArrayBuffer}function Fr(s){return typeof Uint8Array<"u"&&s instanceof Uint8Array}function it(s){return typeof Blob<"u"&&s instanceof Blob}function st(s){return typeof File<"u"&&s instanceof File}var Ze={};Qo(Ze,{ConsoleLogger:()=>ze,LogLevel:()=>q,Logger:()=>ge,createLogger:()=>Xo});var O=Nr();function Nr(){var s,e,o,t,r;if(typeof window<"u"&&typeof window.document<"u")return{type:"browser",version:window.navigator.userAgent};if(typeof globalThis<"u"&&((s=globalThis?.navigator)===null||s===void 0?void 0:s.userAgent)==="Cloudflare-Workers")return{type:"workerd"};if(typeof EdgeRuntime=="string")return{type:"edge-runtime"};if(typeof self=="object"&&typeof self?.importScripts=="function"&&(((e=self.constructor)===null||e===void 0?void 0:e.name)==="DedicatedWorkerGlobalScope"||((o=self.constructor)===null||o===void 0?void 0:o.name)==="ServiceWorkerGlobalScope"||((t=self.constructor)===null||t===void 0?void 0:t.name)==="SharedWorkerGlobalScope"))return{type:"web-worker"};if(typeof Deno<"u"&&typeof Deno.version<"u"&&typeof Deno.version.deno<"u")return{type:"deno",version:Deno.version.deno};if(typeof Bun<"u"&&typeof Bun.version<"u")return{type:"bun",version:Bun.version};if(typeof navigator<"u"&&navigator?.product==="ReactNative")return{type:"react-native"};let p=typeof process<"u"?process:void 0;return typeof p<"u"&&typeof((r=p.versions)===null||r===void 0?void 0:r.node)=="string"?{type:"node",version:p.versions.node,parsedVersion:Number(p.versions.node.split(".")[0])}:{type:"unknown"}}var g={};Qo(g,{encodePathParam:()=>Kt,join:()=>Yt,toQueryString:()=>de});function Kt(s){if(s===null)return"null";switch(typeof s){case"undefined":return"undefined";case"string":case"number":case"boolean":break;default:s=String(s);break}return encodeURIComponent(s)}function Yt(s,...e){if(!s)return"";if(e.length===0)return s;if(s.includes("://")){let o;try{o=new URL(s)}catch{return Vt(s,...e)}let t=e[e.length-1],r=t?.endsWith("/");for(let i of e){let a=Xt(i);a&&(o.pathname=Qt(o.pathname,a))}return r&&!o.pathname.endsWith("/")&&(o.pathname+="/"),o.toString()}return Vt(s,...e)}function Vt(s,...e){if(e.length===0)return s;let o=s,t=e[e.length-1],r=t?.endsWith("/");for(let i of e){let a=Xt(i);a&&(o=Qt(o,a))}return r&&!o.endsWith("/")&&(o+="/"),o}function Qt(s,e){return s.endsWith("/")?s+e:`${s}/${e}`}function Xt(s){if(!s)return s;let e=0,o=s.length;return s.startsWith("/")&&(e=1),s.endsWith("/")&&(o=s.length-1),e===0&&o===s.length?s:s.slice(e,o)}var Ot=dr(at(),1);var Oe=class{constructor(e,o){this.target=o,this.type=e}},qe=class extends Oe{constructor(e,o){super("error",o),this.message=e.message,this.error=e}},Je=class extends Oe{constructor(e=1e3,o="",t){super("close",t),this.wasClean=!0,this.code=e,this.reason=o}};var Wr=()=>{if(typeof WebSocket<"u")return WebSocket;if(O.type==="node")return Ot.WebSocket},zr=s=>typeof s<"u"&&!!s&&s.CLOSING===2,ce={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},H=class s{constructor({url:e,protocols:o,options:t,headers:r,queryParameters:i,abortSignal:a}){this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.CONNECTING=s.CONNECTING,this.OPEN=s.OPEN,this.CLOSING=s.CLOSING,this.CLOSED=s.CLOSED,this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleAbort=()=>{if(!this._closeCalled&&(this._debug("abort signal fired"),this._shouldReconnect=!1,this._closeCalled=!0,this._clearTimeouts(),this._ws)){this._removeListeners();try{this._ws.close(1e3,"aborted"),this._handleClose(new Je(1e3,"aborted",this))}catch{}}},this._handleOpen=c=>{this._debug("open event");let{minUptime:u=ce.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),u),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(d=>{var n;return(n=this._ws)===null||n===void 0?void 0:n.send(d)}),this._messageQueue=[],this.onopen&&this.onopen(c),this._listeners.open.forEach(d=>this._callEventListener(c,d))},this._handleMessage=c=>{this._debug("message event"),this.onmessage&&this.onmessage(c),this._listeners.message.forEach(u=>this._callEventListener(c,u))},this._handleError=c=>{this._debug("error event",c.message),this._disconnect(void 0,c.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(c),this._debug("exec error listeners"),this._listeners.error.forEach(u=>this._callEventListener(c,u)),this._connect()},this._handleClose=c=>{this._debug("close event"),this._clearTimeouts(),c.code===1e3&&(this._shouldReconnect=!1),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(c),this._listeners.close.forEach(u=>this._callEventListener(c,u))},this._url=e,this._protocols=o,this._options=t??ce,this._headers=r,this._queryParameters=i,this._abortSignal=a,this._abortSignal&&this._abortSignal.addEventListener("abort",this._handleAbort,{once:!0}),this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((o,t)=>(typeof t=="string"?o+=t.length:t instanceof Blob?o+=t.size:o+=t.byteLength,o),0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._ws?this._ws.readyState:this._options.startClosed?s.CLOSED:s.CONNECTING}get url(){return this._ws?this._ws.url:""}close(e=1e3,o){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED){this._debug("close: already closed");return}this._ws.close(e,o)}reconnect(e,o){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(e,o),this._connect())}send(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{let{maxEnqueuedMessages:o=ce.maxEnqueuedMessages}=this._options;this._messageQueue.length<o&&(this._debug("enqueue",e),this._messageQueue.push(e))}}addEventListener(e,o){this._listeners[e]&&this._listeners[e].push(o)}dispatchEvent(e){let o=this._listeners[e.type];if(o)for(let t of o)this._callEventListener(e,t);return!0}removeEventListener(e,o){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter(t=>t!==o))}_debug(...e){this._options.debug&&console.log.apply(console,["RWS>",...e])}_getNextDelay(){let{reconnectionDelayGrowFactor:e=ce.reconnectionDelayGrowFactor,minReconnectionDelay:o=ce.minReconnectionDelay,maxReconnectionDelay:t=ce.maxReconnectionDelay}=this._options,r=0;return this._retryCount>0&&(r=o*Math.pow(e,this._retryCount-1),r>t&&(r=t)),this._debug("next delay",r),r}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_getNextUrl(e){if(typeof e=="string")return Promise.resolve(e);if(typeof e=="function"){let o=e();if(typeof o=="string")return Promise.resolve(o);if(o.then)return o}throw Error("Invalid URL")}_connect(){var e;if(this._connectLock||!this._shouldReconnect)return;if(!((e=this._abortSignal)===null||e===void 0)&&e.aborted){this._debug("connect aborted");return}this._connectLock=!0;let{maxRetries:o=ce.maxRetries,connectionTimeout:t=ce.connectionTimeout,WebSocket:r=Wr()}=this._options;if(this._retryCount>=o){this._debug("max retries reached",this._retryCount,">=",o);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!zr(r))throw Error("No valid WebSocket class provided");this._wait().then(()=>this._getNextUrl(this._url)).then(i=>{var a;if(this._closeCalled||!((a=this._abortSignal)===null||a===void 0)&&a.aborted){this._connectLock=!1;return}let c={};if(this._headers&&(c.headers=this._headers),this._queryParameters&&Object.keys(this._queryParameters).length>0){let u=de(this._queryParameters,{arrayFormat:"repeat"});u&&(i=`${i}?${u}`)}this._ws=new r(i,this._protocols,c),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),t)})}_handleTimeout(){this._debug("timeout event"),this._handleError(new qe(Error("TIMEOUT"),this))}_disconnect(e=1e3,o){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(e,o),this._handleClose(new Je(e,o,this))}catch{}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_callEventListener(e,o){"handleEvent"in o?o.handleEvent(e):o(e)}_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}};H.CONNECTING=0;H.OPEN=1;H.CLOSING=2;H.CLOSED=3;var w=class extends Error{constructor({message:e,statusCode:o,body:t,rawResponse:r}){super($r({message:e,statusCode:o,body:t})),Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.statusCode=o,this.body=t,this.rawResponse=r}};function $r({message:s,statusCode:e,body:o}){let t=[];return s!=null&&t.push(s),e!=null&&t.push(`Status code: ${e.toString()}`),o!=null&&t.push(`Body: ${D(o,void 0,2)}`),t.join(`
2
2
  `)}var Ke=class extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var Gr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},dt="apiKey",lt="DEEPGRAM_API_KEY",Jr="Authorization",ye=class s{constructor(e){this.options=e}static canCreate(e){var o;return e?.[dt]!=null||((o=process.env)===null||o===void 0?void 0:o[lt])!=null}getAuthRequest(){return Gr(this,arguments,void 0,function*({endpointMetadata:e}={}){var o,t;let r=(o=yield f.get(this.options[dt]))!==null&&o!==void 0?o:(t=process.env)===null||t===void 0?void 0:t[lt];if(r==null)throw new w({message:s.AUTH_CONFIG_ERROR_MESSAGE});return{headers:{[Jr]:r}}})}};(function(s){s.AUTH_SCHEME="ApiKeyAuth",s.AUTH_CONFIG_ERROR_MESSAGE=`Please provide '${dt}' when initializing the client, or set the '${lt}' environment variable`;function e(o){return new s(o)}s.createInstance=e})(ye||(ye={}));function b(...s){let e={};for(let[o,t]of s.filter(r=>r!=null).flatMap(r=>Object.entries(r))){let r=o.toLowerCase();t!=null?e[r]=t:r in e&&delete e[r]}return e}function ue(...s){let e={};for(let[o,t]of s.filter(r=>r!=null).flatMap(r=>Object.entries(r))){let r=o.toLowerCase();t!=null&&(e[r]=t)}return e}function Q(s){let e=b({"X-Fern-Language":"JavaScript","X-Fern-SDK-Name":"@deepgram/sdk","X-Fern-SDK-Version":"4.11.4","User-Agent":"@deepgram/sdk/4.11.4","X-Fern-Runtime":O.type,"X-Fern-Runtime-Version":O.version},s?.headers);return Object.assign(Object.assign({},s),{logging:Ze.createLogger(s?.logging),headers:e})}function S(s){var e;let o=Q(s),t=Kr(o);return(e=o.authProvider)!==null&&e!==void 0||(o.authProvider=new ye(t)),o}function Kr(s){return Object.assign(Object.assign({},s),{authProvider:new We})}var R={Production:{base:"https://api.deepgram.com",agent:"wss://agent.deepgram.com",production:"wss://api.deepgram.com"},Agent:{base:"https://agent.deepgram.com",agent:"wss://agent.deepgram.com",production:"wss://api.deepgram.com"}};function j(s,e,o,t){switch(s.reason){case"non-json":throw new w({statusCode:s.statusCode,body:s.rawBody,rawResponse:e});case"body-is-null":throw new w({statusCode:s.statusCode,rawResponse:e});case"timeout":throw new Ke(`Timeout exceeded when calling ${o} ${t}.`);case"unknown":throw new w({message:s.errorMessage,rawResponse:e});default:throw new w({message:"Unknown error",rawResponse:e})}}var P=class extends w{constructor(e,o){super({message:"BadRequestError",statusCode:400,body:e,rawResponse:o}),Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var Vr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},eo=class{constructor(e={}){this._options=Q(e)}list(e){return k.fromPromise(this.__list(e))}__list(e){return Vr(this,void 0,void 0,function*(){var o,t,r,i,a,c,u,d,n,l;let p=b((o=this._options)===null||o===void 0?void 0:o.headers,e?.headers),_=yield((t=this._options.fetcher)!==null&&t!==void 0?t:C)({url:g.join((r=yield f.get(this._options.baseUrl))!==null&&r!==void 0?r:((i=yield f.get(this._options.environment))!==null&&i!==void 0?i:R.Production).base,"v1/agent/settings/think/models"),method:"GET",headers:p,queryParameters:e?.queryParams,timeoutMs:((u=(a=e?.timeoutInSeconds)!==null&&a!==void 0?a:(c=this._options)===null||c===void 0?void 0:c.timeoutInSeconds)!==null&&u!==void 0?u:60)*1e3,maxRetries:(d=e?.maxRetries)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.maxRetries,abortSignal:e?.abortSignal,fetchFn:(l=this._options)===null||l===void 0?void 0:l.fetch,logging:this._options.logging});if(_.ok)return{data:_.body,rawResponse:_.rawResponse};if(_.error.reason==="status-code")throw _.error.statusCode===400?new P(_.error.body,_.rawResponse):new w({statusCode:_.error.statusCode,body:_.error.body,rawResponse:_.rawResponse});return j(_.error,_.rawResponse,"GET","/v1/agent/settings/think/models")})}};var oo=class{constructor(e={}){this._options=Q(e)}get models(){var e;return(e=this._models)!==null&&e!==void 0?e:this._models=new eo(this._options)}};var to=class{constructor(e={}){this._options=Q(e)}get think(){var e;return(e=this._think)!==null&&e!==void 0?e:this._think=new oo(this._options)}};var Yr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},we=class{constructor(e){this.eventHandlers={},this.handleOpen=()=>{var o,t;(t=(o=this.eventHandlers).open)===null||t===void 0||t.call(o)},this.handleMessage=o=>{var t,r;let i=K(o.data);(r=(t=this.eventHandlers).message)===null||r===void 0||r.call(t,i)},this.handleClose=o=>{var t,r;(r=(t=this.eventHandlers).close)===null||r===void 0||r.call(t,o)},this.handleError=o=>{var t,r;let i=o.message;(r=(t=this.eventHandlers).error)===null||r===void 0||r.call(t,new Error(i))},this.socket=e.socket,this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError)}get readyState(){return this.socket.readyState}on(e,o){this.eventHandlers[e]=o}sendSettings(e){this.assertSocketIsOpen(),this.sendJson(e)}sendUpdateSpeak(e){this.assertSocketIsOpen(),this.sendJson(e)}sendUpdateThink(e){this.assertSocketIsOpen(),this.sendJson(e)}sendInjectUserMessage(e){this.assertSocketIsOpen(),this.sendJson(e)}sendInjectAgentMessage(e){this.assertSocketIsOpen(),this.sendJson(e)}sendFunctionCallResponse(e){this.assertSocketIsOpen(),this.sendJson(e)}sendKeepAlive(e){this.assertSocketIsOpen(),this.sendJson(e)}sendUpdatePrompt(e){this.assertSocketIsOpen(),this.sendJson(e)}sendMedia(e){this.assertSocketIsOpen(),this.sendBinary(e)}connect(){return this.socket.reconnect(),this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError),this}close(){this.socket.close(),this.handleClose({code:1e3}),this.socket.removeEventListener("open",this.handleOpen),this.socket.removeEventListener("message",this.handleMessage),this.socket.removeEventListener("close",this.handleClose),this.socket.removeEventListener("error",this.handleError)}waitForOpen(){return Yr(this,void 0,void 0,function*(){return this.socket.readyState===H.OPEN?this.socket:new Promise((e,o)=>{this.socket.addEventListener("open",()=>{e(this.socket)}),this.socket.addEventListener("error",t=>{o(t)})})})}assertSocketIsOpen(){if(!this.socket)throw new Error("Socket is not connected.");if(this.socket.readyState!==H.OPEN)throw new Error("Socket is not open.")}sendBinary(e){this.socket.send(e)}sendJson(e){let o=D(e);this.socket.send(o)}};var Qr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},be=class{constructor(e={}){this._options=Q(e)}get settings(){var e;return(e=this._settings)!==null&&e!==void 0?e:this._settings=new to(this._options)}connect(e){return Qr(this,void 0,void 0,function*(){var o,t;let{queryParams:r,headers:i,debug:a,reconnectAttempts:c,connectionTimeoutInSeconds:u,abortSignal:d}=e,n=b(ue({Authorization:e.Authorization}),i),l=new H({url:g.join((o=yield f.get(this._options.baseUrl))!==null&&o!==void 0?o:((t=yield f.get(this._options.environment))!==null&&t!==void 0?t:R.Production).agent,"/v1/agent/converse"),protocols:[],queryParameters:r??{},headers:n,options:{debug:a??!1,maxRetries:c??30,connectionTimeout:u!=null?u*1e3:void 0},abortSignal:d});return new we({socket:l})})}};var Re=class{constructor(e={}){this._options=Q(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new be(this._options)}};var Xr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},ro=class{constructor(e={}){this._options=S(e)}grant(e={},o){return k.fromPromise(this.__grant(e,o))}__grant(){return Xr(this,arguments,void 0,function*(e={},o){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,"v1/auth/grant"),method:"POST",headers:v,contentType:"application/json",queryParameters:o?.queryParams,requestType:"json",body:e,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"POST","/v1/auth/grant")})}};var no=class{constructor(e={}){this._options=S(e)}get tokens(){var e;return(e=this._tokens)!==null&&e!==void 0?e:this._tokens=new ro(this._options)}};var io=class{constructor(e={}){this._options=S(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new no(this._options)}};var qt=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Zr=function(s,e){var o={};for(var t in s)Object.prototype.hasOwnProperty.call(s,t)&&e.indexOf(t)<0&&(o[t]=s[t]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(s);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(s,t[r])&&(o[t[r]]=s[t[r]]);return o},so=class{constructor(e={}){this._options=S(e)}transcribeUrl(e,o){return k.fromPromise(this.__transcribeUrl(e,o))}__transcribeUrl(e,o){return qt(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let{callback:_,callback_method:v,extra:m,sentiment:h,summarize:y,tag:T,topics:E,custom_topic:x,custom_topic_mode:I,intents:$,custom_intent:G,custom_intent_mode:z,detect_entities:M,detect_language:L,diarize:Y,dictation:F,encoding:N,filler_words:re,keyterm:ee,keywords:ne,language:ie,measurements:te,model:oe,multichannel:se,numerals:he,paragraphs:me,profanity_filter:pe,punctuate:ae,redact:ve,replace:De,search:Ie,smart_format:Ae,utterances:Le,utt_split:Me,version:fe,mip_opt_out:He}=e,Be=Zr(e,["callback","callback_method","extra","sentiment","summarize","tag","topics","custom_topic","custom_topic_mode","intents","custom_intent","custom_intent_mode","detect_entities","detect_language","diarize","dictation","encoding","filler_words","keyterm","keywords","language","measurements","model","multichannel","numerals","paragraphs","profanity_filter","punctuate","redact","replace","search","smart_format","utterances","utt_split","version","mip_opt_out"]),Fe={callback:_,callback_method:v??void 0,extra:m,sentiment:h,summarize:y??void 0,tag:T,topics:E,custom_topic:x,custom_topic_mode:I??void 0,intents:$,custom_intent:G,custom_intent_mode:z??void 0,detect_entities:M,detect_language:L,diarize:Y,dictation:F,encoding:N??void 0,filler_words:re,keyterm:ee,keywords:ne,language:ie,measurements:te,model:oe??void 0,multichannel:se,numerals:he,paragraphs:me,profanity_filter:pe,punctuate:ae,redact:ve,replace:De,search:Ie,smart_format:Ae,utterances:Le,utt_split:Me,version:fe??void 0,mip_opt_out:He},Ne=yield this._options.authProvider.getAuthRequest(),Ue=b(Ne.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),J=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,"v1/listen"),method:"POST",headers:Ue,contentType:"application/json",queryParameters:Object.assign(Object.assign({},Fe),o?.queryParams),requestType:"json",body:Be,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(J.ok)return{data:J.body,rawResponse:J.rawResponse};if(J.error.reason==="status-code")throw J.error.statusCode===400?new P(J.error.body,J.rawResponse):new w({statusCode:J.error.statusCode,body:J.error.body,rawResponse:J.rawResponse});return j(J.error,J.rawResponse,"POST","/v1/listen")})}transcribeFile(e,o,t){return k.fromPromise(this.__transcribeFile(e,o,t))}__transcribeFile(e,o,t){return qt(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v={callback:o.callback,callback_method:o.callback_method!=null?o.callback_method:void 0,extra:o.extra,sentiment:o.sentiment,summarize:o.summarize!=null?o.summarize:void 0,tag:o.tag,topics:o.topics,custom_topic:o.custom_topic,custom_topic_mode:o.custom_topic_mode!=null?o.custom_topic_mode:void 0,intents:o.intents,custom_intent:o.custom_intent,custom_intent_mode:o.custom_intent_mode!=null?o.custom_intent_mode:void 0,detect_entities:o.detect_entities,detect_language:o.detect_language,diarize:o.diarize,dictation:o.dictation,encoding:o.encoding!=null?o.encoding:void 0,filler_words:o.filler_words,keyterm:o.keyterm,keywords:o.keywords,language:o.language,measurements:o.measurements,model:o.model!=null?o.model:void 0,multichannel:o.multichannel,numerals:o.numerals,paragraphs:o.paragraphs,profanity_filter:o.profanity_filter,punctuate:o.punctuate,redact:o.redact,replace:o.replace,search:o.search,smart_format:o.smart_format,utterances:o.utterances,utt_split:o.utt_split,version:o.version!=null?o.version:void 0,mip_opt_out:o.mip_opt_out},m=yield Xe.toBinaryUploadRequest(e),h=yield this._options.authProvider.getAuthRequest(),y=b(h.headers,(r=this._options)===null||r===void 0?void 0:r.headers,m.headers,t?.headers),T=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,"v1/listen"),method:"POST",headers:y,contentType:"application/octet-stream",queryParameters:Object.assign(Object.assign({},v),t?.queryParams),requestType:"bytes",duplex:"half",body:m.body,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(T.ok)return{data:T.body,rawResponse:T.rawResponse};if(T.error.reason==="status-code")throw T.error.statusCode===400?new P(T.error.body,T.rawResponse):new w({statusCode:T.error.statusCode,body:T.error.body,rawResponse:T.rawResponse});return j(T.error,T.rawResponse,"POST","/v1/listen")})}};var Or=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Ee=class{constructor(e){this.eventHandlers={},this.handleOpen=()=>{var o,t;(t=(o=this.eventHandlers).open)===null||t===void 0||t.call(o)},this.handleMessage=o=>{var t,r;let i=K(o.data);(r=(t=this.eventHandlers).message)===null||r===void 0||r.call(t,i)},this.handleClose=o=>{var t,r;(r=(t=this.eventHandlers).close)===null||r===void 0||r.call(t,o)},this.handleError=o=>{var t,r;let i=o.message;(r=(t=this.eventHandlers).error)===null||r===void 0||r.call(t,new Error(i))},this.socket=e.socket,this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError)}get readyState(){return this.socket.readyState}on(e,o){this.eventHandlers[e]=o}sendMedia(e){this.assertSocketIsOpen(),this.sendBinary(e)}sendFinalize(e){this.assertSocketIsOpen(),this.sendJson(e)}sendCloseStream(e){this.assertSocketIsOpen(),this.sendJson(e)}sendKeepAlive(e){this.assertSocketIsOpen(),this.sendJson(e)}connect(){return this.socket.reconnect(),this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError),this}close(){this.socket.close(),this.handleClose({code:1e3}),this.socket.removeEventListener("open",this.handleOpen),this.socket.removeEventListener("message",this.handleMessage),this.socket.removeEventListener("close",this.handleClose),this.socket.removeEventListener("error",this.handleError)}waitForOpen(){return Or(this,void 0,void 0,function*(){return this.socket.readyState===H.OPEN?this.socket:new Promise((e,o)=>{this.socket.addEventListener("open",()=>{e(this.socket)}),this.socket.addEventListener("error",t=>{o(t)})})})}assertSocketIsOpen(){if(!this.socket)throw new Error("Socket is not connected.");if(this.socket.readyState!==H.OPEN)throw new Error("Socket is not open.")}sendBinary(e){this.socket.send(e)}sendJson(e){let o=D(e);this.socket.send(o)}};var qr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Se=class{constructor(e={}){this._options=S(e)}get media(){var e;return(e=this._media)!==null&&e!==void 0?e:this._media=new so(this._options)}connect(e){return qr(this,void 0,void 0,function*(){var o,t;let{callback:r,callback_method:i,channels:a,detect_entities:c,diarize:u,dictation:d,encoding:n,endpointing:l,extra:p,interim_results:_,keyterm:v,keywords:m,language:h,mip_opt_out:y,model:T,multichannel:E,numerals:x,profanity_filter:I,punctuate:$,redact:G,replace:z,sample_rate:M,search:L,smart_format:Y,tag:F,utterance_end_ms:N,vad_events:re,version:ee,queryParams:ne,headers:ie,debug:te,reconnectAttempts:oe,connectionTimeoutInSeconds:se,abortSignal:he}=e,me={callback:r!=null?typeof r=="string"?r:D(r):void 0,callback_method:i??void 0,channels:a!=null?typeof a=="string"?a:D(a):void 0,detect_entities:c??void 0,diarize:u??void 0,dictation:d??void 0,encoding:n??void 0,endpointing:l!=null?typeof l=="string"?l:D(l):void 0,extra:p!=null?typeof p=="string"?p:D(p):void 0,interim_results:_??void 0,keyterm:v!=null?typeof v=="string"?v:D(v):void 0,keywords:m!=null?typeof m=="string"?m:D(m):void 0,language:h!=null?typeof h=="string"?h:D(h):void 0,mip_opt_out:y!=null?typeof y=="string"?y:D(y):void 0,model:T,multichannel:E??void 0,numerals:x??void 0,profanity_filter:I??void 0,punctuate:$??void 0,redact:G??void 0,replace:z!=null?typeof z=="string"?z:D(z):void 0,sample_rate:M!=null?typeof M=="string"?M:D(M):void 0,search:L!=null?typeof L=="string"?L:D(L):void 0,smart_format:Y??void 0,tag:F!=null?typeof F=="string"?F:D(F):void 0,utterance_end_ms:N!=null?typeof N=="string"?N:D(N):void 0,vad_events:re??void 0,version:ee!=null?typeof ee=="string"?ee:D(ee):void 0},pe=b(ue({Authorization:e.Authorization}),ie),ae=new H({url:g.join((o=yield f.get(this._options.baseUrl))!==null&&o!==void 0?o:((t=yield f.get(this._options.environment))!==null&&t!==void 0?t:R.Production).production,"/v1/listen"),protocols:[],queryParameters:Object.assign(Object.assign({},me),ne),headers:pe,options:{debug:te??!1,maxRetries:oe??30,connectionTimeout:se!=null?se*1e3:void 0},abortSignal:he});return new Ee({socket:ae})})}};var en=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},ke=class{constructor(e){this.eventHandlers={},this.handleOpen=()=>{var o,t;(t=(o=this.eventHandlers).open)===null||t===void 0||t.call(o)},this.handleMessage=o=>{var t,r;let i=K(o.data);(r=(t=this.eventHandlers).message)===null||r===void 0||r.call(t,i)},this.handleClose=o=>{var t,r;(r=(t=this.eventHandlers).close)===null||r===void 0||r.call(t,o)},this.handleError=o=>{var t,r;let i=o.message;(r=(t=this.eventHandlers).error)===null||r===void 0||r.call(t,new Error(i))},this.socket=e.socket,this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError)}get readyState(){return this.socket.readyState}on(e,o){this.eventHandlers[e]=o}sendMedia(e){this.assertSocketIsOpen(),this.sendBinary(e)}sendCloseStream(e){this.assertSocketIsOpen(),this.sendJson(e)}sendListenV2Configure(e){this.assertSocketIsOpen(),this.sendJson(e)}connect(){return this.socket.reconnect(),this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError),this}close(){this.socket.close(),this.handleClose({code:1e3}),this.socket.removeEventListener("open",this.handleOpen),this.socket.removeEventListener("message",this.handleMessage),this.socket.removeEventListener("close",this.handleClose),this.socket.removeEventListener("error",this.handleError)}waitForOpen(){return en(this,void 0,void 0,function*(){return this.socket.readyState===H.OPEN?this.socket:new Promise((e,o)=>{this.socket.addEventListener("open",()=>{e(this.socket)}),this.socket.addEventListener("error",t=>{o(t)})})})}assertSocketIsOpen(){if(!this.socket)throw new Error("Socket is not connected.");if(this.socket.readyState!==H.OPEN)throw new Error("Socket is not open.")}sendBinary(e){this.socket.send(e)}sendJson(e){let o=D(e);this.socket.send(o)}};var on=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},xe=class{constructor(e={}){this._options=Q(e)}connect(e){return on(this,void 0,void 0,function*(){var o,t;let{model:r,encoding:i,sample_rate:a,eager_eot_threshold:c,eot_threshold:u,eot_timeout_ms:d,keyterm:n,mip_opt_out:l,tag:p,queryParams:_,headers:v,debug:m,reconnectAttempts:h,connectionTimeoutInSeconds:y,abortSignal:T}=e,E={model:r,encoding:i??void 0,sample_rate:a!=null?typeof a=="string"?a:D(a):void 0,eager_eot_threshold:c!=null?typeof c=="string"?c:D(c):void 0,eot_threshold:u!=null?typeof u=="string"?u:D(u):void 0,eot_timeout_ms:d!=null?typeof d=="string"?d:D(d):void 0,keyterm:n!=null?typeof n=="string"?n:D(n):void 0,mip_opt_out:l!=null?typeof l=="string"?l:D(l):void 0,tag:p!=null?typeof p=="string"?p:D(p):void 0},x=b(ue({Authorization:e.Authorization}),v),I=new H({url:g.join((o=yield f.get(this._options.baseUrl))!==null&&o!==void 0?o:((t=yield f.get(this._options.environment))!==null&&t!==void 0?t:R.Production).production,"/v2/listen"),protocols:[],queryParameters:Object.assign(Object.assign({},E),_),headers:x,options:{debug:m??!1,maxRetries:h??30,connectionTimeout:y!=null?y*1e3:void 0},abortSignal:T});return new ke({socket:I})})}};var Pe=class{constructor(e={}){this._options=S(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new Se(this._options)}get v2(){var e;return(e=this._v2)!==null&&e!==void 0?e:this._v2=new xe(this._options)}};var er=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},ao=class{constructor(e={}){this._options=S(e)}list(e={},o){return k.fromPromise(this.__list(e,o))}__list(){return er(this,arguments,void 0,function*(e={},o){var t,r,i,a,c,u,d,n,l,p;let{include_outdated:_}=e,v={include_outdated:_},m=yield this._options.authProvider.getAuthRequest(),h=b(m.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),y=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,"v1/models"),method:"GET",headers:h,queryParameters:Object.assign(Object.assign({},v),o?.queryParams),timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(y.ok)return{data:y.body,rawResponse:y.rawResponse};if(y.error.reason==="status-code")throw y.error.statusCode===400?new P(y.error.body,y.rawResponse):new w({statusCode:y.error.statusCode,body:y.error.body,rawResponse:y.rawResponse});return j(y.error,y.rawResponse,"GET","/v1/models")})}get(e,o){return k.fromPromise(this.__get(e,o))}__get(e,o){return er(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/models/${g.encodePathParam(e)}`),method:"GET",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"GET","/v1/models/{model_id}")})}};var or=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},lo=class{constructor(e={}){this._options=S(e)}list(e,o){return k.fromPromise(this.__list(e,o))}__list(e,o){return or(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/projects/${g.encodePathParam(e)}/balances`),method:"GET",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"GET","/v1/projects/{project_id}/balances")})}get(e,o,t){return k.fromPromise(this.__get(e,o,t))}__get(e,o,t){return or(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/balances/${g.encodePathParam(o)}`),method:"GET",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"GET","/v1/projects/{project_id}/balances/{balance_id}")})}};var tn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},co=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return tn(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{start:m,end:h,accessor:y,deployment:T,tag:E,line_item:x,grouping:I}=t,$={start:m,end:h,accessor:y,deployment:T??void 0,tag:E,line_item:x,grouping:Array.isArray(I)?I.map(L=>L):I??void 0},G=yield this._options.authProvider.getAuthRequest(),z=b(G.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),M=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/billing/breakdown`),method:"GET",headers:z,queryParameters:Object.assign(Object.assign({},$),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(M.ok)return{data:M.body,rawResponse:M.rawResponse};if(M.error.reason==="status-code")throw M.error.statusCode===400?new P(M.error.body,M.rawResponse):new w({statusCode:M.error.statusCode,body:M.error.body,rawResponse:M.rawResponse});return j(M.error,M.rawResponse,"GET","/v1/projects/{project_id}/billing/breakdown")})}};var rn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},uo=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return rn(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{start:m,end:h}=t,y={start:m,end:h},T=yield this._options.authProvider.getAuthRequest(),E=b(T.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),x=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/billing/fields`),method:"GET",headers:E,queryParameters:Object.assign(Object.assign({},y),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(x.ok)return{data:x.body,rawResponse:x.rawResponse};if(x.error.reason==="status-code")throw x.error.statusCode===400?new P(x.error.body,x.rawResponse):new w({statusCode:x.error.statusCode,body:x.error.body,rawResponse:x.rawResponse});return j(x.error,x.rawResponse,"GET","/v1/projects/{project_id}/billing/fields")})}};var nn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},ho=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return nn(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{limit:m}=t,h={limit:m},y=yield this._options.authProvider.getAuthRequest(),T=b(y.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),E=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/purchases`),method:"GET",headers:T,queryParameters:Object.assign(Object.assign({},h),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(E.ok)return{data:E.body,rawResponse:E.rawResponse};if(E.error.reason==="status-code")throw E.error.statusCode===400?new P(E.error.body,E.rawResponse):new w({statusCode:E.error.statusCode,body:E.error.body,rawResponse:E.rawResponse});return j(E.error,E.rawResponse,"GET","/v1/projects/{project_id}/purchases")})}};var mo=class{constructor(e={}){this._options=S(e)}get balances(){var e;return(e=this._balances)!==null&&e!==void 0?e:this._balances=new lo(this._options)}get breakdown(){var e;return(e=this._breakdown)!==null&&e!==void 0?e:this._breakdown=new co(this._options)}get fields(){var e;return(e=this._fields)!==null&&e!==void 0?e:this._fields=new uo(this._options)}get purchases(){var e;return(e=this._purchases)!==null&&e!==void 0?e:this._purchases=new ho(this._options)}};var po=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},_o=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return po(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{status:m}=t,h={status:m??void 0},y=yield this._options.authProvider.getAuthRequest(),T=b(y.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),E=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/keys`),method:"GET",headers:T,queryParameters:Object.assign(Object.assign({},h),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(E.ok)return{data:E.body,rawResponse:E.rawResponse};if(E.error.reason==="status-code")throw E.error.statusCode===400?new P(E.error.body,E.rawResponse):new w({statusCode:E.error.statusCode,body:E.error.body,rawResponse:E.rawResponse});return j(E.error,E.rawResponse,"GET","/v1/projects/{project_id}/keys")})}create(e,o,t){return k.fromPromise(this.__create(e,o,t))}__create(e,o,t){return po(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/keys`),method:"POST",headers:m,contentType:"application/json",queryParameters:t?.queryParams,requestType:"json",body:o,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"POST","/v1/projects/{project_id}/keys")})}get(e,o,t){return k.fromPromise(this.__get(e,o,t))}__get(e,o,t){return po(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/keys/${g.encodePathParam(o)}`),method:"GET",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"GET","/v1/projects/{project_id}/keys/{key_id}")})}delete(e,o,t){return k.fromPromise(this.__delete(e,o,t))}__delete(e,o,t){return po(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/keys/${g.encodePathParam(o)}`),method:"DELETE",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"DELETE","/v1/projects/{project_id}/keys/{key_id}")})}};var ct=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},vo=class{constructor(e={}){this._options=S(e)}list(e,o){return k.fromPromise(this.__list(e,o))}__list(e,o){return ct(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/projects/${g.encodePathParam(e)}/invites`),method:"GET",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"GET","/v1/projects/{project_id}/invites")})}create(e,o,t){return k.fromPromise(this.__create(e,o,t))}__create(e,o,t){return ct(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/invites`),method:"POST",headers:m,contentType:"application/json",queryParameters:t?.queryParams,requestType:"json",body:o,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"POST","/v1/projects/{project_id}/invites")})}delete(e,o,t){return k.fromPromise(this.__delete(e,o,t))}__delete(e,o,t){return ct(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/invites/${g.encodePathParam(o)}`),method:"DELETE",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"DELETE","/v1/projects/{project_id}/invites/{email}")})}};var tr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},fo=class{constructor(e={}){this._options=S(e)}list(e,o,t){return k.fromPromise(this.__list(e,o,t))}__list(e,o,t){return tr(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/members/${g.encodePathParam(o)}/scopes`),method:"GET",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"GET","/v1/projects/{project_id}/members/{member_id}/scopes")})}update(e,o,t,r){return k.fromPromise(this.__update(e,o,t,r))}__update(e,o,t,r){return tr(this,void 0,void 0,function*(){var i,a,c,u,d,n,l,p,_,v;let m=yield this._options.authProvider.getAuthRequest(),h=b(m.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),y=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(e)}/members/${g.encodePathParam(o)}/scopes`),method:"PUT",headers:h,contentType:"application/json",queryParameters:r?.queryParams,requestType:"json",body:t,timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(y.ok)return{data:y.body,rawResponse:y.rawResponse};if(y.error.reason==="status-code")throw y.error.statusCode===400?new P(y.error.body,y.rawResponse):new w({statusCode:y.error.statusCode,body:y.error.body,rawResponse:y.rawResponse});return j(y.error,y.rawResponse,"PUT","/v1/projects/{project_id}/members/{member_id}/scopes")})}};var rr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},go=class{constructor(e={}){this._options=S(e)}get invites(){var e;return(e=this._invites)!==null&&e!==void 0?e:this._invites=new vo(this._options)}get scopes(){var e;return(e=this._scopes)!==null&&e!==void 0?e:this._scopes=new fo(this._options)}list(e,o){return k.fromPromise(this.__list(e,o))}__list(e,o){return rr(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/projects/${g.encodePathParam(e)}/members`),method:"GET",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"GET","/v1/projects/{project_id}/members")})}delete(e,o,t){return k.fromPromise(this.__delete(e,o,t))}__delete(e,o,t){return rr(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/members/${g.encodePathParam(o)}`),method:"DELETE",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"DELETE","/v1/projects/{project_id}/members/{member_id}")})}};var nr=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},yo=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return nr(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{include_outdated:m}=t,h={include_outdated:m},y=yield this._options.authProvider.getAuthRequest(),T=b(y.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),E=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/models`),method:"GET",headers:T,queryParameters:Object.assign(Object.assign({},h),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(E.ok)return{data:E.body,rawResponse:E.rawResponse};if(E.error.reason==="status-code")throw E.error.statusCode===400?new P(E.error.body,E.rawResponse):new w({statusCode:E.error.statusCode,body:E.error.body,rawResponse:E.rawResponse});return j(E.error,E.rawResponse,"GET","/v1/projects/{project_id}/models")})}get(e,o,t){return k.fromPromise(this.__get(e,o,t))}__get(e,o,t){return nr(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/models/${g.encodePathParam(o)}`),method:"GET",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"GET","/v1/projects/{project_id}/models/{model_id}")})}};var ir=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},wo=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return ir(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{start:m,end:h,limit:y,page:T,accessor:E,request_id:x,deployment:I,endpoint:$,method:G,status:z}=t,M={start:m??void 0,end:h??void 0,limit:y,page:T,accessor:E,request_id:x,deployment:I??void 0,endpoint:$??void 0,method:G??void 0,status:z??void 0},L=yield this._options.authProvider.getAuthRequest(),Y=b(L.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),F=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/requests`),method:"GET",headers:Y,queryParameters:Object.assign(Object.assign({},M),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(F.ok)return{data:F.body,rawResponse:F.rawResponse};if(F.error.reason==="status-code")throw F.error.statusCode===400?new P(F.error.body,F.rawResponse):new w({statusCode:F.error.statusCode,body:F.error.body,rawResponse:F.rawResponse});return j(F.error,F.rawResponse,"GET","/v1/projects/{project_id}/requests")})}get(e,o,t){return k.fromPromise(this.__get(e,o,t))}__get(e,o,t){return ir(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/requests/${g.encodePathParam(o)}`),method:"GET",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"GET","/v1/projects/{project_id}/requests/{request_id}")})}};var sn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},bo=class{constructor(e={}){this._options=S(e)}get(e,o={},t){return k.fromPromise(this.__get(e,o,t))}__get(e){return sn(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{start:m,end:h,grouping:y,accessor:T,alternatives:E,callback_method:x,callback:I,channels:$,custom_intent_mode:G,custom_intent:z,custom_topic_mode:M,custom_topic:L,deployment:Y,detect_entities:F,detect_language:N,diarize:re,dictation:ee,encoding:ne,endpoint:ie,extra:te,filler_words:oe,intents:se,keyterm:he,keywords:me,language:pe,measurements:ae,method:ve,model:De,multichannel:Ie,numerals:Ae,paragraphs:Le,profanity_filter:Me,punctuate:fe,redact:He,replace:Be,sample_rate:Fe,search:Ne,sentiment:Ue,smart_format:J,summarize:Wo,tag:zo,topics:$o,utt_split:Go,utterances:Jo,version:Ko}=t,Vo={start:m,end:h,grouping:y??void 0,accessor:T,alternatives:E,callback_method:x,callback:I,channels:$,custom_intent_mode:G,custom_intent:z,custom_topic_mode:M,custom_topic:L,deployment:Y??void 0,detect_entities:F,detect_language:N,diarize:re,dictation:ee,encoding:ne,endpoint:ie??void 0,extra:te,filler_words:oe,intents:se,keyterm:he,keywords:me,language:pe,measurements:ae,method:ve??void 0,model:De,multichannel:Ie,numerals:Ae,paragraphs:Le,profanity_filter:Me,punctuate:fe,redact:He,replace:Be,sample_rate:Fe,search:Ne,sentiment:Ue,smart_format:J,summarize:Wo,tag:zo,topics:$o,utt_split:Go,utterances:Jo,version:Ko},Yo=yield this._options.authProvider.getAuthRequest(),V=b(Yo.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),Z=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/usage/breakdown`),method:"GET",headers:V,queryParameters:Object.assign(Object.assign({},Vo),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(Z.ok)return{data:Z.body,rawResponse:Z.rawResponse};if(Z.error.reason==="status-code")throw Z.error.statusCode===400?new P(Z.error.body,Z.rawResponse):new w({statusCode:Z.error.statusCode,body:Z.error.body,rawResponse:Z.rawResponse});return j(Z.error,Z.rawResponse,"GET","/v1/projects/{project_id}/usage/breakdown")})}};var an=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Ro=class{constructor(e={}){this._options=S(e)}list(e,o={},t){return k.fromPromise(this.__list(e,o,t))}__list(e){return an(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{start:m,end:h}=t,y={start:m,end:h},T=yield this._options.authProvider.getAuthRequest(),E=b(T.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),x=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/usage/fields`),method:"GET",headers:E,queryParameters:Object.assign(Object.assign({},y),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(x.ok)return{data:x.body,rawResponse:x.rawResponse};if(x.error.reason==="status-code")throw x.error.statusCode===400?new P(x.error.body,x.rawResponse):new w({statusCode:x.error.statusCode,body:x.error.body,rawResponse:x.rawResponse});return j(x.error,x.rawResponse,"GET","/v1/projects/{project_id}/usage/fields")})}};var dn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Eo=class{constructor(e={}){this._options=S(e)}get breakdown(){var e;return(e=this._breakdown)!==null&&e!==void 0?e:this._breakdown=new bo(this._options)}get fields(){var e;return(e=this._fields)!==null&&e!==void 0?e:this._fields=new Ro(this._options)}get(e,o={},t){return k.fromPromise(this.__get(e,o,t))}__get(e){return dn(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{start:m,end:h,accessor:y,alternatives:T,callback_method:E,callback:x,channels:I,custom_intent_mode:$,custom_intent:G,custom_topic_mode:z,custom_topic:M,deployment:L,detect_entities:Y,detect_language:F,diarize:N,dictation:re,encoding:ee,endpoint:ne,extra:ie,filler_words:te,intents:oe,keyterm:se,keywords:he,language:me,measurements:pe,method:ae,model:ve,multichannel:De,numerals:Ie,paragraphs:Ae,profanity_filter:Le,punctuate:Me,redact:fe,replace:He,sample_rate:Be,search:Fe,sentiment:Ne,smart_format:Ue,summarize:J,tag:Wo,topics:zo,utt_split:$o,utterances:Go,version:Jo}=t,Ko={start:m,end:h,accessor:y,alternatives:T,callback_method:E,callback:x,channels:I,custom_intent_mode:$,custom_intent:G,custom_topic_mode:z,custom_topic:M,deployment:L??void 0,detect_entities:Y,detect_language:F,diarize:N,dictation:re,encoding:ee,endpoint:ne??void 0,extra:ie,filler_words:te,intents:oe,keyterm:se,keywords:he,language:me,measurements:pe,method:ae??void 0,model:ve,multichannel:De,numerals:Ie,paragraphs:Ae,profanity_filter:Le,punctuate:Me,redact:fe,replace:He,sample_rate:Be,search:Fe,sentiment:Ne,smart_format:Ue,summarize:J,tag:Wo,topics:zo,utt_split:$o,utterances:Go,version:Jo},Vo=yield this._options.authProvider.getAuthRequest(),Yo=b(Vo.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),V=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/usage`),method:"GET",headers:Yo,queryParameters:Object.assign(Object.assign({},Ko),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(V.ok)return{data:V.body,rawResponse:V.rawResponse};if(V.error.reason==="status-code")throw V.error.statusCode===400?new P(V.error.body,V.rawResponse):new w({statusCode:V.error.statusCode,body:V.error.body,rawResponse:V.rawResponse});return j(V.error,V.rawResponse,"GET","/v1/projects/{project_id}/usage")})}};var Ve=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},So=class{constructor(e={}){this._options=S(e)}get keys(){var e;return(e=this._keys)!==null&&e!==void 0?e:this._keys=new _o(this._options)}get members(){var e;return(e=this._members)!==null&&e!==void 0?e:this._members=new go(this._options)}get models(){var e;return(e=this._models)!==null&&e!==void 0?e:this._models=new yo(this._options)}get requests(){var e;return(e=this._requests)!==null&&e!==void 0?e:this._requests=new wo(this._options)}get usage(){var e;return(e=this._usage)!==null&&e!==void 0?e:this._usage=new Eo(this._options)}get billing(){var e;return(e=this._billing)!==null&&e!==void 0?e:this._billing=new mo(this._options)}list(e){return k.fromPromise(this.__list(e))}__list(e){return Ve(this,void 0,void 0,function*(){var o,t,r,i,a,c,u,d,n,l;let p=yield this._options.authProvider.getAuthRequest(),_=b(p.headers,(o=this._options)===null||o===void 0?void 0:o.headers,e?.headers),v=yield((t=this._options.fetcher)!==null&&t!==void 0?t:C)({url:g.join((r=yield f.get(this._options.baseUrl))!==null&&r!==void 0?r:((i=yield f.get(this._options.environment))!==null&&i!==void 0?i:R.Production).base,"v1/projects"),method:"GET",headers:_,queryParameters:e?.queryParams,timeoutMs:((u=(a=e?.timeoutInSeconds)!==null&&a!==void 0?a:(c=this._options)===null||c===void 0?void 0:c.timeoutInSeconds)!==null&&u!==void 0?u:60)*1e3,maxRetries:(d=e?.maxRetries)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.maxRetries,abortSignal:e?.abortSignal,fetchFn:(l=this._options)===null||l===void 0?void 0:l.fetch,logging:this._options.logging});if(v.ok)return{data:v.body,rawResponse:v.rawResponse};if(v.error.reason==="status-code")throw v.error.statusCode===400?new P(v.error.body,v.rawResponse):new w({statusCode:v.error.statusCode,body:v.error.body,rawResponse:v.rawResponse});return j(v.error,v.rawResponse,"GET","/v1/projects")})}get(e,o={},t){return k.fromPromise(this.__get(e,o,t))}__get(e){return Ve(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{limit:m,page:h}=t,y={limit:m,page:h},T=yield this._options.authProvider.getAuthRequest(),E=b(T.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),x=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}`),method:"GET",headers:E,queryParameters:Object.assign(Object.assign({},y),r?.queryParams),timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(x.ok)return{data:x.body,rawResponse:x.rawResponse};if(x.error.reason==="status-code")throw x.error.statusCode===400?new P(x.error.body,x.rawResponse):new w({statusCode:x.error.statusCode,body:x.error.body,rawResponse:x.rawResponse});return j(x.error,x.rawResponse,"GET","/v1/projects/{project_id}")})}delete(e,o){return k.fromPromise(this.__delete(e,o))}__delete(e,o){return Ve(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/projects/${g.encodePathParam(e)}`),method:"DELETE",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"DELETE","/v1/projects/{project_id}")})}update(e,o={},t){return k.fromPromise(this.__update(e,o,t))}__update(e){return Ve(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let m=yield this._options.authProvider.getAuthRequest(),h=b(m.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),y=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}`),method:"PATCH",headers:h,contentType:"application/json",queryParameters:r?.queryParams,requestType:"json",body:t,timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(y.ok)return{data:y.body,rawResponse:y.rawResponse};if(y.error.reason==="status-code")throw y.error.statusCode===400?new P(y.error.body,y.rawResponse):new w({statusCode:y.error.statusCode,body:y.error.body,rawResponse:y.rawResponse});return j(y.error,y.rawResponse,"PATCH","/v1/projects/{project_id}")})}leave(e,o){return k.fromPromise(this.__leave(e,o))}__leave(e,o){return Ve(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/projects/${g.encodePathParam(e)}/leave`),method:"DELETE",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"DELETE","/v1/projects/{project_id}/leave")})}};var ko=class{constructor(e={}){this._options=S(e)}get models(){var e;return(e=this._models)!==null&&e!==void 0?e:this._models=new ao(this._options)}get projects(){var e;return(e=this._projects)!==null&&e!==void 0?e:this._projects=new So(this._options)}};var xo=class{constructor(e={}){this._options=S(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new ko(this._options)}};var ln=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Po=class{constructor(e={}){this._options=S(e)}analyze(e,o){return k.fromPromise(this.__analyze(e,o))}__analyze(e,o){return ln(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let{callback:_,callback_method:v,sentiment:m,summarize:h,tag:y,topics:T,custom_topic:E,custom_topic_mode:x,intents:I,custom_intent:$,custom_intent_mode:G,language:z,body:M}=e,L={callback:_,callback_method:v??void 0,sentiment:m,summarize:h??void 0,tag:y,topics:T,custom_topic:E,custom_topic_mode:x??void 0,intents:I,custom_intent:$,custom_intent_mode:G??void 0,language:z},Y=yield this._options.authProvider.getAuthRequest(),F=b(Y.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),N=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,"v1/read"),method:"POST",headers:F,contentType:"application/json",queryParameters:Object.assign(Object.assign({},L),o?.queryParams),requestType:"json",body:M,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(N.ok)return{data:N.body,rawResponse:N.rawResponse};if(N.error.reason==="status-code")throw N.error.statusCode===400?new P(N.error.body,N.rawResponse):new w({statusCode:N.error.statusCode,body:N.error.body,rawResponse:N.rawResponse});return j(N.error,N.rawResponse,"POST","/v1/read")})}};var Co=class{constructor(e={}){this._options=S(e)}get text(){var e;return(e=this._text)!==null&&e!==void 0?e:this._text=new Po(this._options)}};var jo=class{constructor(e={}){this._options=S(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new Co(this._options)}};var To=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},cn=function(s,e){var o={};for(var t in s)Object.prototype.hasOwnProperty.call(s,t)&&e.indexOf(t)<0&&(o[t]=s[t]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(s);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(s,t[r])&&(o[t[r]]=s[t[r]]);return o},Do=class{constructor(e={}){this._options=S(e)}list(e,o){return k.fromPromise(this.__list(e,o))}__list(e,o){return To(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let _=yield this._options.authProvider.getAuthRequest(),v=b(_.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),m=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,`v1/projects/${g.encodePathParam(e)}/self-hosted/distribution/credentials`),method:"GET",headers:v,queryParameters:o?.queryParams,timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(m.ok)return{data:m.body,rawResponse:m.rawResponse};if(m.error.reason==="status-code")throw m.error.statusCode===400?new P(m.error.body,m.rawResponse):new w({statusCode:m.error.statusCode,body:m.error.body,rawResponse:m.rawResponse});return j(m.error,m.rawResponse,"GET","/v1/projects/{project_id}/self-hosted/distribution/credentials")})}create(e,o={},t){return k.fromPromise(this.__create(e,o,t))}__create(e){return To(this,arguments,void 0,function*(o,t={},r){var i,a,c,u,d,n,l,p,_,v;let{scopes:m,provider:h}=t,y=cn(t,["scopes","provider"]),T={scopes:Array.isArray(m)?m.map($=>$):m??void 0,provider:h??void 0},E=yield this._options.authProvider.getAuthRequest(),x=b(E.headers,(i=this._options)===null||i===void 0?void 0:i.headers,r?.headers),I=yield((a=this._options.fetcher)!==null&&a!==void 0?a:C)({url:g.join((c=yield f.get(this._options.baseUrl))!==null&&c!==void 0?c:((u=yield f.get(this._options.environment))!==null&&u!==void 0?u:R.Production).base,`v1/projects/${g.encodePathParam(o)}/self-hosted/distribution/credentials`),method:"POST",headers:x,contentType:"application/json",queryParameters:Object.assign(Object.assign({},T),r?.queryParams),requestType:"json",body:y,timeoutMs:((l=(d=r?.timeoutInSeconds)!==null&&d!==void 0?d:(n=this._options)===null||n===void 0?void 0:n.timeoutInSeconds)!==null&&l!==void 0?l:60)*1e3,maxRetries:(p=r?.maxRetries)!==null&&p!==void 0?p:(_=this._options)===null||_===void 0?void 0:_.maxRetries,abortSignal:r?.abortSignal,fetchFn:(v=this._options)===null||v===void 0?void 0:v.fetch,logging:this._options.logging});if(I.ok)return{data:I.body,rawResponse:I.rawResponse};if(I.error.reason==="status-code")throw I.error.statusCode===400?new P(I.error.body,I.rawResponse):new w({statusCode:I.error.statusCode,body:I.error.body,rawResponse:I.rawResponse});return j(I.error,I.rawResponse,"POST","/v1/projects/{project_id}/self-hosted/distribution/credentials")})}get(e,o,t){return k.fromPromise(this.__get(e,o,t))}__get(e,o,t){return To(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/self-hosted/distribution/credentials/${g.encodePathParam(o)}`),method:"GET",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"GET","/v1/projects/{project_id}/self-hosted/distribution/credentials/{distribution_credentials_id}")})}delete(e,o,t){return k.fromPromise(this.__delete(e,o,t))}__delete(e,o,t){return To(this,void 0,void 0,function*(){var r,i,a,c,u,d,n,l,p,_;let v=yield this._options.authProvider.getAuthRequest(),m=b(v.headers,(r=this._options)===null||r===void 0?void 0:r.headers,t?.headers),h=yield((i=this._options.fetcher)!==null&&i!==void 0?i:C)({url:g.join((a=yield f.get(this._options.baseUrl))!==null&&a!==void 0?a:((c=yield f.get(this._options.environment))!==null&&c!==void 0?c:R.Production).base,`v1/projects/${g.encodePathParam(e)}/self-hosted/distribution/credentials/${g.encodePathParam(o)}`),method:"DELETE",headers:m,queryParameters:t?.queryParams,timeoutMs:((n=(u=t?.timeoutInSeconds)!==null&&u!==void 0?u:(d=this._options)===null||d===void 0?void 0:d.timeoutInSeconds)!==null&&n!==void 0?n:60)*1e3,maxRetries:(l=t?.maxRetries)!==null&&l!==void 0?l:(p=this._options)===null||p===void 0?void 0:p.maxRetries,abortSignal:t?.abortSignal,fetchFn:(_=this._options)===null||_===void 0?void 0:_.fetch,logging:this._options.logging});if(h.ok)return{data:h.body,rawResponse:h.rawResponse};if(h.error.reason==="status-code")throw h.error.statusCode===400?new P(h.error.body,h.rawResponse):new w({statusCode:h.error.statusCode,body:h.error.body,rawResponse:h.rawResponse});return j(h.error,h.rawResponse,"DELETE","/v1/projects/{project_id}/self-hosted/distribution/credentials/{distribution_credentials_id}")})}};var Io=class{constructor(e={}){this._options=S(e)}get distributionCredentials(){var e;return(e=this._distributionCredentials)!==null&&e!==void 0?e:this._distributionCredentials=new Do(this._options)}};var Ao=class{constructor(e={}){this._options=S(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new Io(this._options)}};var un=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},hn=function(s,e){var o={};for(var t in s)Object.prototype.hasOwnProperty.call(s,t)&&e.indexOf(t)<0&&(o[t]=s[t]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(s);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(s,t[r])&&(o[t[r]]=s[t[r]]);return o},Lo=class{constructor(e={}){this._options=S(e)}generate(e,o){return k.fromPromise(this.__generate(e,o))}__generate(e,o){return un(this,void 0,void 0,function*(){var t,r,i,a,c,u,d,n,l,p;let{callback:_,callback_method:v,mip_opt_out:m,tag:h,bit_rate:y,container:T,encoding:E,model:x,sample_rate:I}=e,$=hn(e,["callback","callback_method","mip_opt_out","tag","bit_rate","container","encoding","model","sample_rate"]),G={callback:_,callback_method:v??void 0,mip_opt_out:m,tag:h,bit_rate:y,container:T??void 0,encoding:E??void 0,model:x??void 0,sample_rate:I},z=yield this._options.authProvider.getAuthRequest(),M=b(z.headers,(t=this._options)===null||t===void 0?void 0:t.headers,o?.headers),L=yield((r=this._options.fetcher)!==null&&r!==void 0?r:C)({url:g.join((i=yield f.get(this._options.baseUrl))!==null&&i!==void 0?i:((a=yield f.get(this._options.environment))!==null&&a!==void 0?a:R.Production).base,"v1/speak"),method:"POST",headers:M,contentType:"application/json",queryParameters:Object.assign(Object.assign({},G),o?.queryParams),requestType:"json",body:$,responseType:"binary-response",timeoutMs:((d=(c=o?.timeoutInSeconds)!==null&&c!==void 0?c:(u=this._options)===null||u===void 0?void 0:u.timeoutInSeconds)!==null&&d!==void 0?d:60)*1e3,maxRetries:(n=o?.maxRetries)!==null&&n!==void 0?n:(l=this._options)===null||l===void 0?void 0:l.maxRetries,abortSignal:o?.abortSignal,fetchFn:(p=this._options)===null||p===void 0?void 0:p.fetch,logging:this._options.logging});if(L.ok)return{data:L.body,rawResponse:L.rawResponse};if(L.error.reason==="status-code")throw L.error.statusCode===400?new P(L.error.body,L.rawResponse):new w({statusCode:L.error.statusCode,body:L.error.body,rawResponse:L.rawResponse});return j(L.error,L.rawResponse,"POST","/v1/speak")})}};var mn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},Ce=class{constructor(e){this.eventHandlers={},this.handleOpen=()=>{var o,t;(t=(o=this.eventHandlers).open)===null||t===void 0||t.call(o)},this.handleMessage=o=>{var t,r;let i=K(o.data);(r=(t=this.eventHandlers).message)===null||r===void 0||r.call(t,i)},this.handleClose=o=>{var t,r;(r=(t=this.eventHandlers).close)===null||r===void 0||r.call(t,o)},this.handleError=o=>{var t,r;let i=o.message;(r=(t=this.eventHandlers).error)===null||r===void 0||r.call(t,new Error(i))},this.socket=e.socket,this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError)}get readyState(){return this.socket.readyState}on(e,o){this.eventHandlers[e]=o}sendText(e){this.assertSocketIsOpen(),this.sendJson(e)}sendFlush(e){this.assertSocketIsOpen(),this.sendJson(e)}sendClear(e){this.assertSocketIsOpen(),this.sendJson(e)}sendClose(e){this.assertSocketIsOpen(),this.sendJson(e)}connect(){return this.socket.reconnect(),this.socket.addEventListener("open",this.handleOpen),this.socket.addEventListener("message",this.handleMessage),this.socket.addEventListener("close",this.handleClose),this.socket.addEventListener("error",this.handleError),this}close(){this.socket.close(),this.handleClose({code:1e3}),this.socket.removeEventListener("open",this.handleOpen),this.socket.removeEventListener("message",this.handleMessage),this.socket.removeEventListener("close",this.handleClose),this.socket.removeEventListener("error",this.handleError)}waitForOpen(){return mn(this,void 0,void 0,function*(){return this.socket.readyState===H.OPEN?this.socket:new Promise((e,o)=>{this.socket.addEventListener("open",()=>{e(this.socket)}),this.socket.addEventListener("error",t=>{o(t)})})})}assertSocketIsOpen(){if(!this.socket)throw new Error("Socket is not connected.");if(this.socket.readyState!==H.OPEN)throw new Error("Socket is not open.")}sendBinary(e){this.socket.send(e)}sendJson(e){let o=D(e);this.socket.send(o)}};var pn=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},je=class{constructor(e={}){this._options=S(e)}get audio(){var e;return(e=this._audio)!==null&&e!==void 0?e:this._audio=new Lo(this._options)}connect(e){return pn(this,void 0,void 0,function*(){var o,t;let{encoding:r,mip_opt_out:i,model:a,sample_rate:c,queryParams:u,headers:d,debug:n,reconnectAttempts:l,connectionTimeoutInSeconds:p,abortSignal:_}=e,v={encoding:r??void 0,mip_opt_out:i!=null?typeof i=="string"?i:D(i):void 0,model:a??void 0,sample_rate:c??void 0},m=b(ue({Authorization:e.Authorization}),d),h=new H({url:g.join((o=yield f.get(this._options.baseUrl))!==null&&o!==void 0?o:((t=yield f.get(this._options.environment))!==null&&t!==void 0?t:R.Production).production,"/v1/speak"),protocols:[],queryParameters:Object.assign(Object.assign({},v),u),headers:m,options:{debug:n??!1,maxRetries:l??30,connectionTimeout:p!=null?p*1e3:void 0},abortSignal:_});return new Ce({socket:h})})}};var Te=class{constructor(e={}){this._options=S(e)}get v1(){var e;return(e=this._v1)!==null&&e!==void 0?e:this._v1=new je(this._options)}};var Mo=class{constructor(e={}){this._options=S(e)}get agent(){var e;return(e=this._agent)!==null&&e!==void 0?e:this._agent=new Re(this._options)}get auth(){var e;return(e=this._auth)!==null&&e!==void 0?e:this._auth=new io(this._options)}get listen(){var e;return(e=this._listen)!==null&&e!==void 0?e:this._listen=new Pe(this._options)}get manage(){var e;return(e=this._manage)!==null&&e!==void 0?e:this._manage=new xo(this._options)}get read(){var e;return(e=this._read)!==null&&e!==void 0?e:this._read=new jo(this._options)}get selfHosted(){var e;return(e=this._selfHosted)!==null&&e!==void 0?e:this._selfHosted=new Ao(this._options)}get speak(){var e;return(e=this._speak)!==null&&e!==void 0?e:this._speak=new Te(this._options)}};var X=function(s,e,o,t){function r(i){return i instanceof o?i:new o(function(a){a(i)})}return new(o||(o=Promise))(function(i,a){function c(n){try{d(t.next(n))}catch(l){a(l)}}function u(n){try{d(t.throw(n))}catch(l){a(l)}}function d(n){n.done?i(n.value):r(n.value).then(c,u)}d((t=t.apply(s,e||[])).next())})},_n=1e4,vn=new Set(["Authorization","headers","debug","reconnectAttempts","connectionTimeoutInSeconds","abortSignal","queryParams"]),Ye,ar=!1;function fn(){return X(this,void 0,void 0,function*(){var s;if(!ar){ar=!0;try{if(typeof kt<"u"){let e=at();Ye=e.WebSocket||e.default||e}else if(typeof process<"u"&&(!((s=process.versions)===null||s===void 0)&&s.node)){let o=yield new Function("specifier","return import(specifier)")("ws");Ye=o.WebSocket||o.default||o}}catch{Ye=void 0}}})}function gn(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();if(O.type==="node")try{return sr().randomUUID()}catch{}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,s=>{let e=Math.random()*16|0;return(s==="x"?e:e&3|8).toString(16)})}var ut=class{constructor(e){this.originalProvider=e}getAuthRequest(e){return X(this,void 0,void 0,function*(){var o,t;let r=yield this.originalProvider.getAuthRequest(e),i=((o=r.headers)===null||o===void 0?void 0:o.Authorization)||((t=r.headers)===null||t===void 0?void 0:t.authorization);return i&&typeof i=="string"&&!i.startsWith("Bearer ")&&!i.startsWith("Token ")&&!i.startsWith("token ")?{headers:Object.assign(Object.assign({},r.headers),{Authorization:`Token ${i}`})}:r})}},ht=class{constructor(e,o){this.originalProvider=e,this.accessToken=o}getAuthRequest(e){return X(this,void 0,void 0,function*(){var o,t;let r=(o=yield f.get(this.accessToken))!==null&&o!==void 0?o:(t=process.env)===null||t===void 0?void 0:t.DEEPGRAM_ACCESS_TOKEN;return r!=null?{headers:{Authorization:`Bearer ${r}`}}:this.originalProvider.getAuthRequest(e)})}},mt=class extends Mo{constructor(e={}){let o=gn(),t=Object.assign(Object.assign({},e),{headers:Object.assign(Object.assign({},e.headers),{"x-deepgram-session-id":o})});super(t),this._sessionId=o,this._options.authProvider=new ut(this._options.authProvider),e.accessToken!=null&&(this._options.authProvider=new ht(this._options.authProvider,e.accessToken))}get sessionId(){return this._sessionId}get agent(){return this._customAgent||(this._customAgent=new pt(this._options)),this._customAgent}get listen(){return this._customListen||(this._customListen=new _t(this._options)),this._customListen}get speak(){return this._customSpeak||(this._customSpeak=new vt(this._options)),this._customSpeak}},pt=class extends Re{get v1(){return new ft(this._options)}},_t=class extends Pe{get v1(){return new yt(this._options)}get v2(){return new bt(this._options)}},vt=class extends Te{get v1(){return new Et(this._options)}};function yn(s){return X(this,void 0,void 0,function*(){let e={};for(let[o,t]of Object.entries(s)){if(t==null)continue;let r=yield f.get(t);r!=null&&(e[o]=r)}return e})}function Ho(s){let e={};for(let[o,t]of Object.entries(s))!vn.has(o)&&t!=null&&(e[o]=t);return s.queryParams!=null&&typeof s.queryParams=="object"&&Object.assign(e,s.queryParams),e}function wn(s){let e={},o=O.type==="browser"||O.type==="web-worker",t=s["x-deepgram-session-id"]||s["X-Deepgram-Session-Id"];if(O.type==="node"&&Ye)e.WebSocket=Ye,e.headers=s;else if(o){let r=s.Authorization||s.authorization,i=Object.assign({},s);delete i.Authorization,delete i.authorization,delete i["x-deepgram-session-id"],delete i["X-Deepgram-Session-Id"],e.headers=i;let a=[];if(r&&typeof r=="string")if(r.startsWith("Token ")){let c=r.substring(6);a.push("token",c)}else if(r.startsWith("Bearer ")){let c=r.substring(7);a.push("bearer",c)}else a.push(r);t&&typeof t=="string"&&a.push("x-deepgram-session-id",t),a.length>0&&(e.protocols=a)}else e.headers=s;return e}function Bo(s,e){var o;let t=i=>{var a,c,u;if(typeof i.data=="string")try{let d=K(i.data);(a=e.message)===null||a===void 0||a.call(e,d)}catch{(c=e.message)===null||c===void 0||c.call(e,i.data)}else(u=e.message)===null||u===void 0||u.call(e,i.data)},r=s;return!((o=r._listeners)===null||o===void 0)&&o.message&&r._listeners.message.forEach(i=>{s.removeEventListener("message",i)}),s.addEventListener("message",t),t}function Fo(s,e){e.handleOpen&&s.removeEventListener("open",e.handleOpen),e.handleMessage&&s.removeEventListener("message",e.handleMessage),e.handleClose&&s.removeEventListener("close",e.handleClose),e.handleError&&s.removeEventListener("error",e.handleError)}function No(s){s.readyState===s.CLOSED&&(s._connectLock=!1,s._shouldReconnect=!0)}function Uo(s){return X(this,arguments,void 0,function*({options:e,urlPath:o,environmentKey:t,queryParams:r,headers:i,debug:a,reconnectAttempts:c,connectionTimeoutInSeconds:u,abortSignal:d}){var n,l,p,_,v,m;yield fn();let h=yield(n=e.authProvider)===null||n===void 0?void 0:n.getAuthRequest(),y=b((l=e.headers)!==null&&l!==void 0?l:{},(p=h?.headers)!==null&&p!==void 0?p:{},i),T=yield yn(y),E=wn(T),x=(_=yield f.get(e.baseUrl))!==null&&_!==void 0?_:((v=yield f.get(e.environment))!==null&&v!==void 0?v:R.Production)[t];return new H({url:g.join(x,o),protocols:(m=E.protocols)!==null&&m!==void 0?m:[],queryParameters:r,headers:E.headers,options:{WebSocket:E.WebSocket,debug:a??!1,maxRetries:c??30,startClosed:!0,connectionTimeout:u!=null?u*1e3:_n},abortSignal:d})})}var ft=class extends be{connect(){return X(this,arguments,void 0,function*(e={}){let{headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a}=e,c=yield Uo({options:this._options,urlPath:"/v1/agent/converse",environmentKey:"agent",queryParams:Ho(e),headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a});return new gt({socket:c})})}createConnection(){return X(this,arguments,void 0,function*(e={}){return this.connect(e)})}},gt=class extends we{constructor(e){super(e),this.setupBinaryHandling()}setupBinaryHandling(){this.binaryAwareHandler=Bo(this.socket,this.eventHandlers)}connect(){let e=this;return Fo(this.socket,{handleOpen:e.handleOpen,handleMessage:e.handleMessage,handleClose:e.handleClose,handleError:e.handleError}),No(this.socket),super.connect(),this.setupBinaryHandling(),this}},yt=class extends Se{connect(e){return X(this,void 0,void 0,function*(){let{headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a}=e,c=yield Uo({options:this._options,urlPath:"/v1/listen",environmentKey:"production",queryParams:Ho(e),headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a});return new wt({socket:c})})}createConnection(e){return X(this,void 0,void 0,function*(){return this.connect(e)})}},wt=class extends Ee{constructor(e){super(e),this.setupBinaryHandling()}setupBinaryHandling(){this.binaryAwareHandler=Bo(this.socket,this.eventHandlers)}connect(){let e=this;return Fo(this.socket,{handleOpen:e.handleOpen,handleMessage:e.handleMessage,handleClose:e.handleClose,handleError:e.handleError}),No(this.socket),super.connect(),this.setupBinaryHandling(),this}},bt=class extends xe{connect(e){return X(this,void 0,void 0,function*(){let{headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a}=e,c=yield Uo({options:this._options,urlPath:"/v2/listen",environmentKey:"production",queryParams:Ho(e),headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a});return new Rt({socket:c})})}createConnection(e){return X(this,void 0,void 0,function*(){return this.connect(e)})}},Rt=class extends ke{constructor(e){super(e),this.setupBinaryHandling()}setupBinaryHandling(){this.binaryAwareHandler=Bo(this.socket,this.eventHandlers)}connect(){let e=this;return Fo(this.socket,{handleOpen:e.handleOpen,handleMessage:e.handleMessage,handleClose:e.handleClose,handleError:e.handleError}),No(this.socket),super.connect(),this.setupBinaryHandling(),this}ping(e){let o=this.socket._ws;if(!o)throw new Error("WebSocket is not connected. Call connect() and waitForOpen() first.");if(o.readyState!==o.OPEN)throw new Error("WebSocket is not in OPEN state.");if(O.type==="node"&&typeof o.ping=="function")o.ping(e);else throw new Error("WebSocket ping is not supported in browser environments. Browser WebSocket connections handle ping/pong automatically. If you need keepalive in the browser, consider sending periodic audio data or using a timer.")}},Et=class extends je{connect(e){return X(this,void 0,void 0,function*(){let{headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a}=e,c=yield Uo({options:this._options,urlPath:"/v1/speak",environmentKey:"production",queryParams:Ho(e),headers:o,debug:t,reconnectAttempts:r,connectionTimeoutInSeconds:i,abortSignal:a});return new St({socket:c})})}createConnection(e){return X(this,void 0,void 0,function*(){return this.connect(e)})}},St=class extends Ce{constructor(e){super(e);let o=this;o.handleMessage&&this.socket.removeEventListener("message",o.handleMessage),this.setupBinaryHandling()}setupBinaryHandling(){this.binaryAwareHandler=Bo(this.socket,this.eventHandlers)}connect(){let e=this;return Fo(this.socket,{handleOpen:e.handleOpen,handleMessage:e.handleMessage,handleClose:e.handleClose,handleError:e.handleError}),No(this.socket),super.connect(),this.setupBinaryHandling(),this}};export{mt as a};
@@ -1,4 +1,4 @@
1
- import{a as k}from"./chunk-V5GQSIWD.js";import{B as r,S as T,T as h,U as a,f as t,h as l,j as d,l as g,m as f,p as m,t as p,u as S}from"./chunk-557JQDB4.js";var n="[Deepgram Flux STT]",E=1e4,u=16e3,y=1280,w=`
1
+ import{a as k}from"./chunk-PEQLP6DN.js";import{B as r,S as T,T as h,U as a,f as t,h as l,j as d,l as g,m as f,p as m,t as p,u as S}from"./chunk-6GQSOKKS.js";var n="[Deepgram Flux STT]",E=1e4,u=16e3,y=1280,w=`
2
2
  class PcmCaptureProcessor extends AudioWorkletProcessor {
3
3
  constructor() {
4
4
  super()
@@ -1 +1 @@
1
- import{a as b}from"./chunk-V5GQSIWD.js";import{B as p,S as M,T as h,U as C,f as t,h as S,j as g,l as T,m as f,p as v,t as k,u as y}from"./chunk-557JQDB4.js";var n="[Deepgram STT]",E=1e4,R=250,U=48e3,$=1e3,N=3e4,D=2,d=5,l=2e3;var m=3,w=class{constructor(e){this.options=e;this.options.model=this.options.model||"nova-3",this.options.language=this.options.language||"en",this.options.smartFormat=this.options.smartFormat??!0,this.options.interimResults=this.options.interimResults??!0,this.options.utteranceEndMs=this.options.utteranceEndMs??1500,this.options.vadEvents=this.options.vadEvents??!0,this.options.fillerWords=this.options.fillerWords??!1,this.options.endpointing=this.options.endpointing??500,this.options.echoCancellation=this.options.echoCancellation??!0,this.options.noiseSuppression=this.options.noiseSuppression??!0,this.options.autoGainControl=this.options.autoGainControl??!0,this.options.interruptionWordThreshold=this.options.interruptionWordThreshold??m,this.options.noDelay=this.options.noDelay??!1,this.options.safetyNetTimeoutMs=this.options.safetyNetTimeoutMs??l,this.options.safetyNetTimeoutMs<=500?(t.warn(`${n} safetyNetTimeoutMs is set to ${this.options.safetyNetTimeoutMs}ms. This is very short and may cause premature transcript finalization. Ignoring and default the value to ${l}ms.`),this.options.safetyNetTimeoutMs=l):this.options.safetyNetTimeoutMs<=1e3?t.warn(`${n} safetyNetTimeoutMs is set to ${this.options.safetyNetTimeoutMs}ms. This is very short and may cause premature transcript finalization. Recommended value is ${l}ms.`):t.info(`${n} safetyNetTimeoutMs is set to ${this.options.safetyNetTimeoutMs}ms.`),this.handleAppMessages()}options;connection=null;state="Idle";shouldReconnect=!0;microphone=null;stream=null;reconnectAttempts=0;reconnectDelay=$;reconnectTimeoutId=null;digitalHumanSpeaking=!1;isUserCurrentlySpeaking=!1;isUiShowingSpeaking=!1;accumulatedTranscript="";accumulatedConfidenceSum=0;accumulatedWordCount=0;lastDeepgramEventTime=0;safetyNetTimeoutId=null;async startRecognition(){t.info(`${n} Starting speech recognition`),this.shouldReconnect=!0,this.resetReconnectionState(),await this.connect()}async stopRecognition(){t.info(`${n} Stopping speech recognition`),this.shouldReconnect=!1,this.clearReconnectTimeout(),await this.disconnect()}async pause(){return t.info(`${n} Pausing speech recognition`),this.state="Paused",this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),this.resetAccumulatedState(),this.resetSpeakingStates(),this.stream&&(this.stream.getTracks().forEach(e=>{e.enabled=!1}),t.debug(`${n} Audio tracks disabled`)),!0}async resume(){if(t.info(`${n} Resuming speech recognition`),this.state==="Paused"){if(this.stream)return this.state="Connected",this.stream.getTracks().forEach(e=>{e.enabled=!0}),t.debug(`${n} Audio tracks re-enabled`),!0;if(this.connection)return this.state="Connected",await this.startMicrophone(),!0;this.state="Disconnected"}return t.debug(`${n} Initiating connection`),await this.connect(),!0}setChatMetadata(e){this.options.promptMetadata=e}async connect(){if(this.state==="Connected"){t.warn(`${n} Already connected`);return}if(this.state==="Connecting"){t.warn(`${n} Connection already in progress`);return}this.state="Connecting";try{let e=await this.getToken();t.info(`${n} Connecting to Deepgram`);let i=new b({accessToken:e.token,baseUrl:e.api_url}),a={model:this.options.model,language:this.options.language,smart_format:String(this.options.smartFormat),interim_results:String(this.options.interimResults),utterance_end_ms:this.options.utteranceEndMs,vad_events:String(this.options.vadEvents),filler_words:String(this.options.fillerWords),endpointing:this.options.endpointing,mip_opt_out:"true",...this.options.keyterms&&this.options.keyterms.length>0&&{keyterm:this.options.keyterms},...this.options.noDelay&&{queryParams:{no_delay:"true"}}},s=i.listen;if(this.connection=await s.v1.connect(a),this.connection.connect(),await Promise.race([this.connection.waitForOpen(),new Promise((o,r)=>setTimeout(()=>r(new Error("Connection timeout")),E))]),this.state!=="Paused"&&(this.state="Connected"),t.info(`${n} Connection opened`),this.setupEventHandlers(),this.state==="Paused"){t.info(`${n} Pause requested during connection \u2014 staying paused`),this.resetReconnectionState();return}await this.startMicrophone(),t.info(`${n} Connected successfully`),this.resetReconnectionState()}catch(e){this.state="Disconnected",t.error(`${n} Connection error`,t.serialiseError(e)),this.shouldReconnect&&(this.emitTransientError(e),this.scheduleReconnect())}}async disconnect(){if(!(this.state==="Idle"||this.state==="Disconnected"&&!this.connection)){t.info(`${n} Disconnecting`),this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null);try{this.stopMicrophone(),this.connection&&(this.connection.close(),this.connection=null)}catch(e){t.error(`${n} Disconnect error`,t.serialiseError(e))}this.resetAccumulatedState(),this.resetSpeakingStates(),this.state="Disconnected",this.clientMsgSend(new p(!1))}}scheduleReconnect(){if(this.reconnectAttempts>=d){t.error(`${n} Max reconnection attempts (${d}) reached`),this.clientMsgSend(new k(`Unable to connect to speech recognition service after ${d} attempts`));return}this.reconnectAttempts++,t.info(`${n} Scheduling reconnection attempt ${this.reconnectAttempts}/${d} in ${this.reconnectDelay}ms`),this.reconnectTimeoutId=setTimeout(()=>{this.connect()},this.reconnectDelay),this.reconnectDelay=Math.min(this.reconnectDelay*D,N)}resetReconnectionState(){this.reconnectAttempts=0,this.reconnectDelay=$,this.clearReconnectTimeout()}clearReconnectTimeout(){this.reconnectTimeoutId&&(clearTimeout(this.reconnectTimeoutId),this.reconnectTimeoutId=null)}async getToken(){let e=this.options.model||"nova-3",i=`${this.options.connectionUrl}/speech-recognition-service/deepgram/token?model=${encodeURIComponent(e)}`,a=await fetch(i,{method:"GET",headers:{Authorization:`Bearer ${this.options.jwtToken}`,"Content-Type":"application/json"}});if(!a.ok)throw new Error(`Token fetch failed: ${a.status} ${a.statusText}`);return await a.json()}async startMicrophone(){try{if(t.info(`${n} Starting microphone`),this.stopMicrophone(),!navigator.mediaDevices?.getUserMedia)throw new Error("Microphone access is not available in this context");if(this.stream=await navigator.mediaDevices.getUserMedia({audio:{deviceId:this.options.microphoneDeviceId?{exact:this.options.microphoneDeviceId}:void 0,echoCancellation:this.options.echoCancellation,noiseSuppression:this.options.noiseSuppression,autoGainControl:this.options.autoGainControl}}),this.state==="Paused"){t.info(`${n} Paused during getUserMedia \u2014 keeping stream but disabling tracks`),this.stream.getTracks().forEach(e=>{e.enabled=!1});return}this.microphone=new MediaRecorder(this.stream,{mimeType:"audio/webm;codecs=opus",audioBitsPerSecond:U}),this.microphone.ondataavailable=e=>{e.data.size>0&&this.connection&&this.state==="Connected"&&e.data.arrayBuffer().then(i=>{this.connection?.sendMedia(i)}).catch(i=>{t.error(`${n} Error converting audio data`,t.serialiseError(i))})},this.microphone.start(R),t.debug(`${n} Microphone started`),this.clientMsgSend(new p(!0))}catch(e){t.error(`${n} Microphone error`,t.serialiseError(e)),this.clientMsgSend(new S(new Error(JSON.stringify(e))))}}stopMicrophone(){this.microphone&&this.microphone.state==="recording"&&(this.microphone.stop(),this.microphone=null),this.stream&&(this.stream.getTracks().forEach(e=>{e.stop()}),this.stream=null),t.debug(`${n} Microphone stopped`)}setupEventHandlers(){this.connection&&(this.connection.on("open",()=>{this.handleConnectionOpen()}),this.connection.on("message",e=>{if(e!==null&&typeof e=="object"&&"type"in e){let i=e;i.type==="Results"?this.handleTranscript(e):i.type==="UtteranceEnd"?this.handleUtteranceEnd(e):i.type==="Metadata"&&t.debug(`${n} Metadata`,e)}}),this.connection.on("close",()=>{this.handleConnectionClose()}),this.connection.on("error",e=>{t.error(`${n} WebSocket error event`,t.serialiseError(e)),this.emitTransientError(e)}))}handleAppMessages(){this.options.messages.subscribe(e=>{switch(e.uneeqMessageType){case"AvatarStartedSpeaking":this.digitalHumanSpeaking=!0;break;case"PromptResult":{e.promptResult.success||this.handleSpeakingEnd();break}case"AvatarAnswer":{e.answerSpeech.replace(/<[^>]*>/g,"")===""&&this.handleSpeakingEnd();break}case"AvatarStoppedSpeaking":{this.handleSpeakingEnd();break}case"SessionEnded":{this.shouldReconnect=!1,this.stopRecognition();break}case"SessionReconnecting":{this.handleSpeakingEnd(),this.shouldReconnect=!1,this.stopRecognition();break}case"CustomMetadataUpdated":{this.options.promptMetadata=e.chatMetadata;break}case"SessionBackendError":{this.handleSpeakingEnd();break}default:}})}handleTranscript(e){try{this.lastDeepgramEventTime=Date.now();let i=e.channel;if(!i?.alternatives||i.alternatives.length===0)return;let a=i.alternatives[0],s=String(a.transcript||""),o=e.is_final,r=e.speech_final;if(t.debug(`${n} Transcript event: is_final=${o}, speech_final=${r}, transcript="${s.substring(0,50)}${s.length>50?"...":""}", accumulated="${this.accumulatedTranscript.substring(0,30)}${this.accumulatedTranscript.length>30?"...":""}", uiSpeaking=${this.isUiShowingSpeaking}, userSpeaking=${this.isUserCurrentlySpeaking}`),s===""&&r){this.endsWithPunctuation(this.accumulatedTranscript)?(this.sendAccumulatedTranscript("Final transcript (from accumulated)"),this.resetSpeakingStates()):t.debug(`${n} speech_final with empty transcript but no punctuation, waiting for more speech or safety net`);return}if(s==="")return;this.processTranscriptChunk(s,a.confidence,o,r),this.updateSpeakingAndInterruptionState(s,r),this.emitTranscriptionResult(s,a.confidence,r),this.resetSafetyNetTimeout()}catch(i){t.error(`${n} Error processing transcript`,t.serialiseError(i))}}processTranscriptChunk(e,i,a,s){if(a&&!s){this.accumulatedTranscript!==""&&(this.accumulatedTranscript+=" "),this.accumulatedTranscript+=e;let o=e.trim().split(/\s+/).length,r=i??1;this.accumulatedConfidenceSum+=r*o,this.accumulatedWordCount+=o,t.debug(`${n} Accumulated transcript: "${this.accumulatedTranscript}"`)}}updateSpeakingAndInterruptionState(e,i){let s=(this.accumulatedTranscript!==""?this.accumulatedTranscript:e).trim().split(/\s+/).length,o=this.options.interruptionWordThreshold??m;this.isUiShowingSpeaking||(this.isUiShowingSpeaking=!0,this.clientMsgSend(new T));let r=!this.digitalHumanSpeaking||s>=o,c=this.accumulatedTranscript!==""?this.accumulatedTranscript+" "+e:e,u=i&&this.endsWithPunctuation(c);!this.isUserCurrentlySpeaking&&r&&(this.isUserCurrentlySpeaking=!0,this.dataChannelMsgSend(new h("start"))),this.digitalHumanSpeaking&&s>=o&&(t.debug(`${n} Interrupting digital human`),this.dataChannelMsgSend(new C),this.clientMsgSend(new v),this.digitalHumanSpeaking=!1),this.isUserCurrentlySpeaking&&u&&(this.isUserCurrentlySpeaking=!1,this.dataChannelMsgSend(new h("stop"))),this.isUiShowingSpeaking&&u&&(this.isUiShowingSpeaking=!1,this.clientMsgSend(new f))}emitTranscriptionResult(e,i,a){let s=this.accumulatedTranscript!==""?this.accumulatedTranscript+" "+e:e,o=a&&this.endsWithPunctuation(s),r={transcript:a?s:e,final:o,confidence:i??1,language_code:this.options.language||""};if(this.clientMsgSend(new g(r)),o){let c=s.trim().split(/\s+/).length,u=this.options.interruptionWordThreshold??m;this.digitalHumanSpeaking&&c<u?t.debug(`${n} Discarding utterance during speaking (${c} words < ${u} threshold): "${s}"`):(t.info(`${n} Final transcript: "${s}"`),this.sendChatPrompt(s)),this.resetAccumulatedState()}else if(a){this.accumulatedTranscript!==""&&(this.accumulatedTranscript+=" "),this.accumulatedTranscript+=e;let c=e.trim().split(/\s+/).length;this.accumulatedConfidenceSum+=(i??1)*c,this.accumulatedWordCount+=c,t.debug(`${n} speech_final without punctuation, accumulated for safety net: "${this.accumulatedTranscript}"`)}}handleUtteranceEnd(e){this.lastDeepgramEventTime=Date.now(),t.debug(`${n} UtteranceEnd event received: last_word_end=${e?.last_word_end}, accumulated="${this.accumulatedTranscript.substring(0,50)}...", uiSpeaking=${this.isUiShowingSpeaking}, userSpeaking=${this.isUserCurrentlySpeaking}`),this.accumulatedTranscript.trim()!==""?this.endsWithPunctuation(this.accumulatedTranscript)?(this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),t.debug(`${n} UtteranceEnd fallback triggered with transcript: "${this.accumulatedTranscript}"`),this.sendAccumulatedTranscript("UtteranceEnd fallback"),this.resetSpeakingStates(),t.debug(`${n} UtteranceEnd: reset speaking states`)):t.debug(`${n} UtteranceEnd: no punctuation, waiting for more speech or safety net`):(this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),this.resetSpeakingStates(),t.debug(`${n} UtteranceEnd: no transcript, reset speaking states`))}resetSafetyNetTimeout(){this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),(this.isUiShowingSpeaking||this.isUserCurrentlySpeaking)&&this.accumulatedTranscript.trim()!==""&&(this.safetyNetTimeoutId=setTimeout(()=>{this.triggerSafetyNet()},this.options.safetyNetTimeoutMs))}triggerSafetyNet(){t.warn(`${n} Safety net triggered: no Deepgram events for ${this.options.safetyNetTimeoutMs}ms while speaking`),t.debug(`${n} Safety net triggered: accumulated="${this.accumulatedTranscript}", uiSpeaking=${this.isUiShowingSpeaking}, userSpeaking=${this.isUserCurrentlySpeaking}, timeSinceLastEvent=${Date.now()-this.lastDeepgramEventTime}ms`),this.sendAccumulatedTranscript("Safety net"),this.resetSpeakingStates(),this.safetyNetTimeoutId=null}sendAccumulatedTranscript(e){if(this.accumulatedTranscript.trim()==="")return;if(e!=="Safety net"&&!this.endsWithPunctuation(this.accumulatedTranscript)){t.debug(`${n} sendAccumulatedTranscript: not sending as source is ${e} and transcript doesn't end in punctuation: "${this.accumulatedTranscript}"`);return}let i=this.options.interruptionWordThreshold??m,a=this.accumulatedWordCount>0?this.accumulatedConfidenceSum/this.accumulatedWordCount:1,s={transcript:this.accumulatedTranscript,final:!0,confidence:a,language_code:this.options.language||""};this.clientMsgSend(new g(s));let o=this.accumulatedTranscript.trim().split(/\s+/).length;this.digitalHumanSpeaking&&o<i?t.debug(`${n} Discarding utterance during speaking (${o} words < ${i} threshold): "${this.accumulatedTranscript}"`):(t.info(`${n} ${e}: "${this.accumulatedTranscript}"`),this.sendChatPrompt(this.accumulatedTranscript)),this.resetAccumulatedState()}endsWithPunctuation(e){let i=e.trim();return i.length===0?!1:/[.!?;:]$/.test(i)}resetAccumulatedState(){this.accumulatedTranscript="",this.accumulatedConfidenceSum=0,this.accumulatedWordCount=0}resetSpeakingStates(){this.isUserCurrentlySpeaking&&(this.isUserCurrentlySpeaking=!1,this.dataChannelMsgSend(new h("stop"))),this.isUiShowingSpeaking&&(this.isUiShowingSpeaking=!1,this.clientMsgSend(new f))}handleConnectionOpen(){this.state!=="Paused"&&(this.state="Connected")}handleConnectionClose(){if(t.info(`${n} Connection closed`),this.state==="Paused"){t.info(`${n} Connection closed while paused \u2014 will reconnect on resume`),this.connection=null,this.stopMicrophone();return}this.state="Disconnected",this.clientMsgSend(new p(!1)),this.shouldReconnect&&(t.info(`${n} Unexpected disconnect, attempting reconnection...`),this.scheduleReconnect())}sendChatPrompt(e){e&&e.trim()!==""&&(this.options.language&&(this.options.promptMetadata.userSpokenLocale=this.options.language),this.dataChannelMsgSend(new M(e,this.options.promptMetadata)))}handleSpeakingEnd(){this.digitalHumanSpeaking=!1}emitTransientError(e){let i=e instanceof Error?e.message:String(e);this.clientMsgSend(new y(i))}dataChannelMsgSend(e){this.options.sendMessage(e)}clientMsgSend(e){this.options.messages.next(e)}};export{w as DeepgramSTT};
1
+ import{a as b}from"./chunk-PEQLP6DN.js";import{B as p,S as M,T as h,U as C,f as t,h as S,j as g,l as T,m as f,p as v,t as k,u as y}from"./chunk-6GQSOKKS.js";var n="[Deepgram STT]",E=1e4,U=250,R=48e3,$=1e3,N=3e4,D=2,d=5,l=2e3;var m=3,w=class{constructor(e){this.options=e;this.options.model=this.options.model||"nova-3",this.options.language=this.options.language||"en",this.options.smartFormat=this.options.smartFormat??!0,this.options.interimResults=this.options.interimResults??!0,this.options.utteranceEndMs=this.options.utteranceEndMs??1500,this.options.vadEvents=this.options.vadEvents??!0,this.options.fillerWords=this.options.fillerWords??!1,this.options.endpointing=this.options.endpointing??500,this.options.echoCancellation=this.options.echoCancellation??!0,this.options.noiseSuppression=this.options.noiseSuppression??!0,this.options.autoGainControl=this.options.autoGainControl??!0,this.options.interruptionWordThreshold=this.options.interruptionWordThreshold??m,this.options.noDelay=this.options.noDelay??!1,this.options.safetyNetTimeoutMs=this.options.safetyNetTimeoutMs??l,this.options.safetyNetTimeoutMs<=500?(t.warn(`${n} safetyNetTimeoutMs is set to ${this.options.safetyNetTimeoutMs}ms. This is very short and may cause premature transcript finalization. Ignoring and default the value to ${l}ms.`),this.options.safetyNetTimeoutMs=l):this.options.safetyNetTimeoutMs<=1e3?t.warn(`${n} safetyNetTimeoutMs is set to ${this.options.safetyNetTimeoutMs}ms. This is very short and may cause premature transcript finalization. Recommended value is ${l}ms.`):t.info(`${n} safetyNetTimeoutMs is set to ${this.options.safetyNetTimeoutMs}ms.`),this.handleAppMessages()}options;connection=null;state="Idle";shouldReconnect=!0;microphone=null;stream=null;reconnectAttempts=0;reconnectDelay=$;reconnectTimeoutId=null;digitalHumanSpeaking=!1;isUserCurrentlySpeaking=!1;isUiShowingSpeaking=!1;accumulatedTranscript="";accumulatedConfidenceSum=0;accumulatedWordCount=0;lastDeepgramEventTime=0;safetyNetTimeoutId=null;async startRecognition(){t.info(`${n} Starting speech recognition`),this.shouldReconnect=!0,this.resetReconnectionState(),await this.connect()}async stopRecognition(){t.info(`${n} Stopping speech recognition`),this.shouldReconnect=!1,this.clearReconnectTimeout(),await this.disconnect()}async pause(){return t.info(`${n} Pausing speech recognition`),this.state="Paused",this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),this.resetAccumulatedState(),this.resetSpeakingStates(),this.stream&&(this.stream.getTracks().forEach(e=>{e.enabled=!1}),t.debug(`${n} Audio tracks disabled`)),!0}async resume(){if(t.info(`${n} Resuming speech recognition`),this.state==="Paused"){if(this.stream)return this.state="Connected",this.stream.getTracks().forEach(e=>{e.enabled=!0}),t.debug(`${n} Audio tracks re-enabled`),!0;if(this.connection)return this.state="Connected",await this.startMicrophone(),!0;this.state="Disconnected"}return t.debug(`${n} Initiating connection`),await this.connect(),!0}setChatMetadata(e){this.options.promptMetadata=e}async connect(){if(this.state==="Connected"){t.warn(`${n} Already connected`);return}if(this.state==="Connecting"){t.warn(`${n} Connection already in progress`);return}this.state="Connecting";try{let e=await this.getToken();t.info(`${n} Connecting to Deepgram`);let i=new b({accessToken:e.token,baseUrl:e.api_url}),a={model:this.options.model,language:this.options.language,smart_format:String(this.options.smartFormat),interim_results:String(this.options.interimResults),utterance_end_ms:this.options.utteranceEndMs,vad_events:String(this.options.vadEvents),filler_words:String(this.options.fillerWords),endpointing:this.options.endpointing,mip_opt_out:"true",...this.options.keyterms&&this.options.keyterms.length>0&&{keyterm:this.options.keyterms},...this.options.noDelay&&{queryParams:{no_delay:"true"}}},s=i.listen;if(this.connection=await s.v1.connect(a),this.connection.connect(),await Promise.race([this.connection.waitForOpen(),new Promise((o,r)=>setTimeout(()=>r(new Error("Connection timeout")),E))]),this.state!=="Paused"&&(this.state="Connected"),t.info(`${n} Connection opened`),this.setupEventHandlers(),this.state==="Paused"){t.info(`${n} Pause requested during connection \u2014 staying paused`),this.resetReconnectionState();return}await this.startMicrophone(),t.info(`${n} Connected successfully`),this.resetReconnectionState()}catch(e){this.state="Disconnected",t.error(`${n} Connection error`,t.serialiseError(e)),this.shouldReconnect&&(this.emitTransientError(e),this.scheduleReconnect())}}async disconnect(){if(!(this.state==="Idle"||this.state==="Disconnected"&&!this.connection)){t.info(`${n} Disconnecting`),this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null);try{this.stopMicrophone(),this.connection&&(this.connection.close(),this.connection=null)}catch(e){t.error(`${n} Disconnect error`,t.serialiseError(e))}this.resetAccumulatedState(),this.resetSpeakingStates(),this.state="Disconnected",this.clientMsgSend(new p(!1))}}scheduleReconnect(){if(this.reconnectAttempts>=d){t.error(`${n} Max reconnection attempts (${d}) reached`),this.clientMsgSend(new k(`Unable to connect to speech recognition service after ${d} attempts`));return}this.reconnectAttempts++,t.info(`${n} Scheduling reconnection attempt ${this.reconnectAttempts}/${d} in ${this.reconnectDelay}ms`),this.reconnectTimeoutId=setTimeout(()=>{this.connect()},this.reconnectDelay),this.reconnectDelay=Math.min(this.reconnectDelay*D,N)}resetReconnectionState(){this.reconnectAttempts=0,this.reconnectDelay=$,this.clearReconnectTimeout()}clearReconnectTimeout(){this.reconnectTimeoutId&&(clearTimeout(this.reconnectTimeoutId),this.reconnectTimeoutId=null)}async getToken(){let e=this.options.model||"nova-3",i=`${this.options.connectionUrl}/speech-recognition-service/deepgram/token?model=${encodeURIComponent(e)}`,a=await fetch(i,{method:"GET",headers:{Authorization:`Bearer ${this.options.jwtToken}`,"Content-Type":"application/json"}});if(!a.ok)throw new Error(`Token fetch failed: ${a.status} ${a.statusText}`);return await a.json()}async startMicrophone(){try{if(t.info(`${n} Starting microphone`),this.stopMicrophone(),!navigator.mediaDevices?.getUserMedia)throw new Error("Microphone access is not available in this context");if(this.stream=await navigator.mediaDevices.getUserMedia({audio:{deviceId:this.options.microphoneDeviceId?{exact:this.options.microphoneDeviceId}:void 0,echoCancellation:this.options.echoCancellation,noiseSuppression:this.options.noiseSuppression,autoGainControl:this.options.autoGainControl}}),this.state==="Paused"){t.info(`${n} Paused during getUserMedia \u2014 keeping stream but disabling tracks`),this.stream.getTracks().forEach(e=>{e.enabled=!1});return}this.microphone=new MediaRecorder(this.stream,{mimeType:"audio/webm;codecs=opus",audioBitsPerSecond:R}),this.microphone.ondataavailable=e=>{e.data.size>0&&this.connection&&this.state==="Connected"&&e.data.arrayBuffer().then(i=>{this.connection?.sendMedia(i)}).catch(i=>{t.error(`${n} Error converting audio data`,t.serialiseError(i))})},this.microphone.start(U),t.debug(`${n} Microphone started`),this.clientMsgSend(new p(!0))}catch(e){t.error(`${n} Microphone error`,t.serialiseError(e)),this.clientMsgSend(new S(new Error(JSON.stringify(e))))}}stopMicrophone(){this.microphone&&this.microphone.state==="recording"&&(this.microphone.stop(),this.microphone=null),this.stream&&(this.stream.getTracks().forEach(e=>{e.stop()}),this.stream=null),t.debug(`${n} Microphone stopped`)}setupEventHandlers(){this.connection&&(this.connection.on("open",()=>{this.handleConnectionOpen()}),this.connection.on("message",e=>{if(e!==null&&typeof e=="object"&&"type"in e){let i=e;i.type==="Results"?this.handleTranscript(e):i.type==="UtteranceEnd"?this.handleUtteranceEnd(e):i.type==="Metadata"&&t.debug(`${n} Metadata`,e)}}),this.connection.on("close",()=>{this.handleConnectionClose()}),this.connection.on("error",e=>{t.error(`${n} WebSocket error event`,t.serialiseError(e)),this.emitTransientError(e)}))}handleAppMessages(){this.options.messages.subscribe(e=>{switch(e.uneeqMessageType){case"AvatarStartedSpeaking":this.digitalHumanSpeaking=!0;break;case"PromptResult":{e.promptResult.success||this.handleSpeakingEnd();break}case"AvatarAnswer":{e.answerSpeech.replace(/<[^>]*>/g,"")===""&&this.handleSpeakingEnd();break}case"AvatarStoppedSpeaking":{this.handleSpeakingEnd();break}case"SessionEnded":{this.shouldReconnect=!1,this.stopRecognition();break}case"SessionReconnecting":{this.handleSpeakingEnd(),this.pause();break}case"CustomMetadataUpdated":{this.options.promptMetadata=e.chatMetadata;break}case"SessionBackendError":{this.handleSpeakingEnd();break}default:}})}handleTranscript(e){try{this.lastDeepgramEventTime=Date.now();let i=e.channel;if(!i?.alternatives||i.alternatives.length===0)return;let a=i.alternatives[0],s=String(a.transcript||""),o=e.is_final,r=e.speech_final;if(t.debug(`${n} Transcript event: is_final=${o}, speech_final=${r}, transcript="${s.substring(0,50)}${s.length>50?"...":""}", accumulated="${this.accumulatedTranscript.substring(0,30)}${this.accumulatedTranscript.length>30?"...":""}", uiSpeaking=${this.isUiShowingSpeaking}, userSpeaking=${this.isUserCurrentlySpeaking}`),s===""&&r){this.endsWithPunctuation(this.accumulatedTranscript)?(this.sendAccumulatedTranscript("Final transcript (from accumulated)"),this.resetSpeakingStates()):t.debug(`${n} speech_final with empty transcript but no punctuation, waiting for more speech or safety net`);return}if(s==="")return;this.processTranscriptChunk(s,a.confidence,o,r),this.updateSpeakingAndInterruptionState(s,r),this.emitTranscriptionResult(s,a.confidence,r),this.resetSafetyNetTimeout()}catch(i){t.error(`${n} Error processing transcript`,t.serialiseError(i))}}processTranscriptChunk(e,i,a,s){if(a&&!s){this.accumulatedTranscript!==""&&(this.accumulatedTranscript+=" "),this.accumulatedTranscript+=e;let o=e.trim().split(/\s+/).length,r=i??1;this.accumulatedConfidenceSum+=r*o,this.accumulatedWordCount+=o,t.debug(`${n} Accumulated transcript: "${this.accumulatedTranscript}"`)}}updateSpeakingAndInterruptionState(e,i){let s=(this.accumulatedTranscript!==""?this.accumulatedTranscript:e).trim().split(/\s+/).length,o=this.options.interruptionWordThreshold??m;this.isUiShowingSpeaking||(this.isUiShowingSpeaking=!0,this.clientMsgSend(new T));let r=!this.digitalHumanSpeaking||s>=o,c=this.accumulatedTranscript!==""?this.accumulatedTranscript+" "+e:e,u=i&&this.endsWithPunctuation(c);!this.isUserCurrentlySpeaking&&r&&(this.isUserCurrentlySpeaking=!0,this.dataChannelMsgSend(new h("start"))),this.digitalHumanSpeaking&&s>=o&&(t.debug(`${n} Interrupting digital human`),this.dataChannelMsgSend(new C),this.clientMsgSend(new v),this.digitalHumanSpeaking=!1),this.isUserCurrentlySpeaking&&u&&(this.isUserCurrentlySpeaking=!1,this.dataChannelMsgSend(new h("stop"))),this.isUiShowingSpeaking&&u&&(this.isUiShowingSpeaking=!1,this.clientMsgSend(new f))}emitTranscriptionResult(e,i,a){let s=this.accumulatedTranscript!==""?this.accumulatedTranscript+" "+e:e,o=a&&this.endsWithPunctuation(s),r={transcript:a?s:e,final:o,confidence:i??1,language_code:this.options.language||""};if(this.clientMsgSend(new g(r)),o){let c=s.trim().split(/\s+/).length,u=this.options.interruptionWordThreshold??m;this.digitalHumanSpeaking&&c<u?t.debug(`${n} Discarding utterance during speaking (${c} words < ${u} threshold): "${s}"`):(t.info(`${n} Final transcript: "${s}"`),this.sendChatPrompt(s)),this.resetAccumulatedState()}else if(a){this.accumulatedTranscript!==""&&(this.accumulatedTranscript+=" "),this.accumulatedTranscript+=e;let c=e.trim().split(/\s+/).length;this.accumulatedConfidenceSum+=(i??1)*c,this.accumulatedWordCount+=c,t.debug(`${n} speech_final without punctuation, accumulated for safety net: "${this.accumulatedTranscript}"`)}}handleUtteranceEnd(e){this.lastDeepgramEventTime=Date.now(),t.debug(`${n} UtteranceEnd event received: last_word_end=${e?.last_word_end}, accumulated="${this.accumulatedTranscript.substring(0,50)}...", uiSpeaking=${this.isUiShowingSpeaking}, userSpeaking=${this.isUserCurrentlySpeaking}`),this.accumulatedTranscript.trim()!==""?this.endsWithPunctuation(this.accumulatedTranscript)?(this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),t.debug(`${n} UtteranceEnd fallback triggered with transcript: "${this.accumulatedTranscript}"`),this.sendAccumulatedTranscript("UtteranceEnd fallback"),this.resetSpeakingStates(),t.debug(`${n} UtteranceEnd: reset speaking states`)):t.debug(`${n} UtteranceEnd: no punctuation, waiting for more speech or safety net`):(this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),this.resetSpeakingStates(),t.debug(`${n} UtteranceEnd: no transcript, reset speaking states`))}resetSafetyNetTimeout(){this.safetyNetTimeoutId&&(clearTimeout(this.safetyNetTimeoutId),this.safetyNetTimeoutId=null),(this.isUiShowingSpeaking||this.isUserCurrentlySpeaking)&&this.accumulatedTranscript.trim()!==""&&(this.safetyNetTimeoutId=setTimeout(()=>{this.triggerSafetyNet()},this.options.safetyNetTimeoutMs))}triggerSafetyNet(){t.warn(`${n} Safety net triggered: no Deepgram events for ${this.options.safetyNetTimeoutMs}ms while speaking`),t.debug(`${n} Safety net triggered: accumulated="${this.accumulatedTranscript}", uiSpeaking=${this.isUiShowingSpeaking}, userSpeaking=${this.isUserCurrentlySpeaking}, timeSinceLastEvent=${Date.now()-this.lastDeepgramEventTime}ms`),this.sendAccumulatedTranscript("Safety net"),this.resetSpeakingStates(),this.safetyNetTimeoutId=null}sendAccumulatedTranscript(e){if(this.accumulatedTranscript.trim()==="")return;if(e!=="Safety net"&&!this.endsWithPunctuation(this.accumulatedTranscript)){t.debug(`${n} sendAccumulatedTranscript: not sending as source is ${e} and transcript doesn't end in punctuation: "${this.accumulatedTranscript}"`);return}let i=this.options.interruptionWordThreshold??m,a=this.accumulatedWordCount>0?this.accumulatedConfidenceSum/this.accumulatedWordCount:1,s={transcript:this.accumulatedTranscript,final:!0,confidence:a,language_code:this.options.language||""};this.clientMsgSend(new g(s));let o=this.accumulatedTranscript.trim().split(/\s+/).length;this.digitalHumanSpeaking&&o<i?t.debug(`${n} Discarding utterance during speaking (${o} words < ${i} threshold): "${this.accumulatedTranscript}"`):(t.info(`${n} ${e}: "${this.accumulatedTranscript}"`),this.sendChatPrompt(this.accumulatedTranscript)),this.resetAccumulatedState()}endsWithPunctuation(e){let i=e.trim();return i.length===0?!1:/[.!?;:]$/.test(i)}resetAccumulatedState(){this.accumulatedTranscript="",this.accumulatedConfidenceSum=0,this.accumulatedWordCount=0}resetSpeakingStates(){this.isUserCurrentlySpeaking&&(this.isUserCurrentlySpeaking=!1,this.dataChannelMsgSend(new h("stop"))),this.isUiShowingSpeaking&&(this.isUiShowingSpeaking=!1,this.clientMsgSend(new f))}handleConnectionOpen(){this.state!=="Paused"&&(this.state="Connected")}handleConnectionClose(){if(t.info(`${n} Connection closed`),this.state==="Paused"){t.info(`${n} Connection closed while paused \u2014 will reconnect on resume`),this.connection=null,this.stopMicrophone();return}this.state="Disconnected",this.clientMsgSend(new p(!1)),this.shouldReconnect&&(t.info(`${n} Unexpected disconnect, attempting reconnection...`),this.scheduleReconnect())}sendChatPrompt(e){e&&e.trim()!==""&&(this.options.language&&(this.options.promptMetadata.userSpokenLocale=this.options.language),this.dataChannelMsgSend(new M(e,this.options.promptMetadata)))}handleSpeakingEnd(){this.digitalHumanSpeaking=!1}emitTransientError(e){let i=e instanceof Error?e.message:String(e);this.clientMsgSend(new y(i))}dataChannelMsgSend(e){this.options.sendMessage(e)}clientMsgSend(e){this.options.messages.next(e)}};export{w as DeepgramSTT};