@glydeunity/voice-sdk 1.0.0

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.
@@ -0,0 +1,32 @@
1
+ export declare class GlydeVoice {
2
+ private config;
3
+ private _deepgram;
4
+ private unityUrl;
5
+ private active;
6
+ constructor(config: GlydeVoiceConfig);
7
+ /**
8
+ * Initialize and start the voice session
9
+ */
10
+ start(): Promise<void>;
11
+ /**
12
+ * Stop the voice session
13
+ */
14
+ stop(): void;
15
+ private emit;
16
+ private renderUI;
17
+ }
18
+
19
+ export declare interface GlydeVoiceConfig {
20
+ publishableKey: string;
21
+ contextId?: string;
22
+ unityBaseUrl?: string;
23
+ container?: HTMLElement | string;
24
+ onEvent?: (event: VoiceEvent) => void;
25
+ }
26
+
27
+ export declare interface VoiceEvent {
28
+ type: 'open' | 'close' | 'error' | 'transcript' | 'agent_audio';
29
+ payload?: any;
30
+ }
31
+
32
+ export { }
@@ -0,0 +1,4 @@
1
+ import { G as r } from "./index-BbD4w_Sz.js";
2
+ export {
3
+ r as GlydeVoice
4
+ };
@@ -0,0 +1,8 @@
1
+ (function($,X){typeof exports=="object"&&typeof module<"u"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):($=typeof globalThis<"u"?globalThis:$||self,X($.GlydeVoice={}))})(this,(function($){"use strict";function X(o,e){for(var t=0;t<e.length;t++){const n=e[t];if(typeof n!="string"&&!Array.isArray(n)){for(const r in n)if(r!=="default"&&!(r in o)){const s=Object.getOwnPropertyDescriptor(n,r);s&&Object.defineProperty(o,r,s.get?s:{enumerable:!0,get:()=>n[r]})}}}return Object.freeze(Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}))}class C extends Error{constructor(e){super(e),this.__dgError=!0,this.name="DeepgramError"}}function w(o){return typeof o=="object"&&o!==null&&"__dgError"in o}class Pe extends C{constructor(e,t){super(e),this.name="DeepgramApiError",this.status=t}toJSON(){return{name:this.name,message:this.message,status:this.status}}}class Q extends C{constructor(e,t){super(e),this.name="DeepgramUnknownError",this.originalError=t}}class N extends C{constructor(){super("You are attempting to use an old format for a newer SDK version. Read more here: https://dpgr.am/js-v3"),this.name="DeepgramVersionError"}}class Ne extends C{constructor(e,t={}){super(e),this.name="DeepgramWebSocketError",this.originalEvent=t.originalEvent,this.statusCode=t.statusCode,this.requestId=t.requestId,this.responseHeaders=t.responseHeaders,this.url=t.url,this.readyState=t.readyState}toJSON(){return{name:this.name,message:this.message,statusCode:this.statusCode,requestId:this.requestId,responseHeaders:this.responseHeaders,url:this.url,readyState:this.readyState,originalEvent:this.originalEvent?{type:this.originalEvent.type,timeStamp:this.originalEvent.timeStamp}:void 0}}}var ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function fe(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var te={exports:{}},we;function De(){if(we)return te.exports;we=1;var o=typeof Reflect=="object"?Reflect:null,e=o&&typeof o.apply=="function"?o.apply:function(u,h,y){return Function.prototype.apply.call(u,h,y)},t;o&&typeof o.ownKeys=="function"?t=o.ownKeys:Object.getOwnPropertySymbols?t=function(u){return Object.getOwnPropertyNames(u).concat(Object.getOwnPropertySymbols(u))}:t=function(u){return Object.getOwnPropertyNames(u)};function n(l){console&&console.warn&&console.warn(l)}var r=Number.isNaN||function(u){return u!==u};function s(){s.init.call(this)}te.exports=s,te.exports.once=v,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var i=10;function c(l){if(typeof l!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof l)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return i},set:function(l){if(typeof l!="number"||l<0||r(l))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+l+".");i=l}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(u){if(typeof u!="number"||u<0||r(u))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+u+".");return this._maxListeners=u,this};function p(l){return l._maxListeners===void 0?s.defaultMaxListeners:l._maxListeners}s.prototype.getMaxListeners=function(){return p(this)},s.prototype.emit=function(u){for(var h=[],y=1;y<arguments.length;y++)h.push(arguments[y]);var m=u==="error",U=this._events;if(U!==void 0)m=m&&U.error===void 0;else if(!m)return!1;if(m){var O;if(h.length>0&&(O=h[0]),O instanceof Error)throw O;var M=new Error("Unhandled error."+(O?" ("+O.message+")":""));throw M.context=O,M}var A=U[u];if(A===void 0)return!1;if(typeof A=="function")e(A,this,h);else for(var le=A.length,Z=F(A,le),y=0;y<le;++y)e(Z[y],this,h);return!0};function g(l,u,h,y){var m,U,O;if(c(h),U=l._events,U===void 0?(U=l._events=Object.create(null),l._eventsCount=0):(U.newListener!==void 0&&(l.emit("newListener",u,h.listener?h.listener:h),U=l._events),O=U[u]),O===void 0)O=U[u]=h,++l._eventsCount;else if(typeof O=="function"?O=U[u]=y?[h,O]:[O,h]:y?O.unshift(h):O.push(h),m=p(l),m>0&&O.length>m&&!O.warned){O.warned=!0;var M=new Error("Possible EventEmitter memory leak detected. "+O.length+" "+String(u)+" listeners added. Use emitter.setMaxListeners() to increase limit");M.name="MaxListenersExceededWarning",M.emitter=l,M.type=u,M.count=O.length,n(M)}return l}s.prototype.addListener=function(u,h){return g(this,u,h,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(u,h){return g(this,u,h,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function b(l,u,h){var y={fired:!1,wrapFn:void 0,target:l,type:u,listener:h},m=f.bind(y);return m.listener=h,y.wrapFn=m,m}s.prototype.once=function(u,h){return c(h),this.on(u,b(this,u,h)),this},s.prototype.prependOnceListener=function(u,h){return c(h),this.prependListener(u,b(this,u,h)),this},s.prototype.removeListener=function(u,h){var y,m,U,O,M;if(c(h),m=this._events,m===void 0)return this;if(y=m[u],y===void 0)return this;if(y===h||y.listener===h)--this._eventsCount===0?this._events=Object.create(null):(delete m[u],m.removeListener&&this.emit("removeListener",u,y.listener||h));else if(typeof y!="function"){for(U=-1,O=y.length-1;O>=0;O--)if(y[O]===h||y[O].listener===h){M=y[O].listener,U=O;break}if(U<0)return this;U===0?y.shift():q(y,U),y.length===1&&(m[u]=y[0]),m.removeListener!==void 0&&this.emit("removeListener",u,M||h)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(u){var h,y,m;if(y=this._events,y===void 0)return this;if(y.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):y[u]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete y[u]),this;if(arguments.length===0){var U=Object.keys(y),O;for(m=0;m<U.length;++m)O=U[m],O!=="removeListener"&&this.removeAllListeners(O);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(h=y[u],typeof h=="function")this.removeListener(u,h);else if(h!==void 0)for(m=h.length-1;m>=0;m--)this.removeListener(u,h[m]);return this};function I(l,u,h){var y=l._events;if(y===void 0)return[];var m=y[u];return m===void 0?[]:typeof m=="function"?h?[m.listener||m]:[m]:h?G(m):F(m,m.length)}s.prototype.listeners=function(u){return I(this,u,!0)},s.prototype.rawListeners=function(u){return I(this,u,!1)},s.listenerCount=function(l,u){return typeof l.listenerCount=="function"?l.listenerCount(u):D.call(l,u)},s.prototype.listenerCount=D;function D(l){var u=this._events;if(u!==void 0){var h=u[l];if(typeof h=="function")return 1;if(h!==void 0)return h.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]};function F(l,u){for(var h=new Array(u),y=0;y<u;++y)h[y]=l[y];return h}function q(l,u){for(;u+1<l.length;u++)l[u]=l[u+1];l.pop()}function G(l){for(var u=new Array(l.length),h=0;h<u.length;++h)u[h]=l[h].listener||l[h];return u}function v(l,u){return new Promise(function(h,y){function m(O){l.removeListener(u,U),y(O)}function U(){typeof l.removeListener=="function"&&l.removeListener("error",m),h([].slice.call(arguments))}S(l,u,U,{once:!0}),u!=="error"&&_(l,m,{once:!0})})}function _(l,u,h){typeof l.on=="function"&&S(l,"error",u,h)}function S(l,u,h,y){if(typeof l.on=="function")y.once?l.once(u,h):l.on(u,h);else if(typeof l.addEventListener=="function")l.addEventListener(u,function m(U){y.once&&l.removeEventListener(u,m),h(U)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof l)}return te.exports}var Fe=De(),re={exports:{}},_e;function He(){return _e||(_e=1,(function(o,e){var t=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof ee<"u"&&ee,n=(function(){function s(){this.fetch=!1,this.DOMException=t.DOMException}return s.prototype=t,new s})();(function(s){(function(i){var c=typeof s<"u"&&s||typeof self<"u"&&self||typeof ee<"u"&&ee||{},p={searchParams:"URLSearchParams"in c,iterable:"Symbol"in c&&"iterator"in Symbol,blob:"FileReader"in c&&"Blob"in c&&(function(){try{return new Blob,!0}catch{return!1}})(),formData:"FormData"in c,arrayBuffer:"ArrayBuffer"in c};function g(a){return a&&DataView.prototype.isPrototypeOf(a)}if(p.arrayBuffer)var f=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],b=ArrayBuffer.isView||function(a){return a&&f.indexOf(Object.prototype.toString.call(a))>-1};function I(a){if(typeof a!="string"&&(a=String(a)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(a)||a==="")throw new TypeError('Invalid character in header field name: "'+a+'"');return a.toLowerCase()}function D(a){return typeof a!="string"&&(a=String(a)),a}function F(a){var d={next:function(){var j=a.shift();return{done:j===void 0,value:j}}};return p.iterable&&(d[Symbol.iterator]=function(){return d}),d}function q(a){this.map={},a instanceof q?a.forEach(function(d,j){this.append(j,d)},this):Array.isArray(a)?a.forEach(function(d){if(d.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+d.length);this.append(d[0],d[1])},this):a&&Object.getOwnPropertyNames(a).forEach(function(d){this.append(d,a[d])},this)}q.prototype.append=function(a,d){a=I(a),d=D(d);var j=this.map[a];this.map[a]=j?j+", "+d:d},q.prototype.delete=function(a){delete this.map[I(a)]},q.prototype.get=function(a){return a=I(a),this.has(a)?this.map[a]:null},q.prototype.has=function(a){return this.map.hasOwnProperty(I(a))},q.prototype.set=function(a,d){this.map[I(a)]=D(d)},q.prototype.forEach=function(a,d){for(var j in this.map)this.map.hasOwnProperty(j)&&a.call(d,this.map[j],j,this)},q.prototype.keys=function(){var a=[];return this.forEach(function(d,j){a.push(j)}),F(a)},q.prototype.values=function(){var a=[];return this.forEach(function(d){a.push(d)}),F(a)},q.prototype.entries=function(){var a=[];return this.forEach(function(d,j){a.push([j,d])}),F(a)},p.iterable&&(q.prototype[Symbol.iterator]=q.prototype.entries);function G(a){if(!a._noBody){if(a.bodyUsed)return Promise.reject(new TypeError("Already read"));a.bodyUsed=!0}}function v(a){return new Promise(function(d,j){a.onload=function(){d(a.result)},a.onerror=function(){j(a.error)}})}function _(a){var d=new FileReader,j=v(d);return d.readAsArrayBuffer(a),j}function S(a){var d=new FileReader,j=v(d),R=/charset=([A-Za-z0-9_-]+)/.exec(a.type),x=R?R[1]:"utf-8";return d.readAsText(a,x),j}function l(a){for(var d=new Uint8Array(a),j=new Array(d.length),R=0;R<d.length;R++)j[R]=String.fromCharCode(d[R]);return j.join("")}function u(a){if(a.slice)return a.slice(0);var d=new Uint8Array(a.byteLength);return d.set(new Uint8Array(a)),d.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(a){this.bodyUsed=this.bodyUsed,this._bodyInit=a,a?typeof a=="string"?this._bodyText=a:p.blob&&Blob.prototype.isPrototypeOf(a)?this._bodyBlob=a:p.formData&&FormData.prototype.isPrototypeOf(a)?this._bodyFormData=a:p.searchParams&&URLSearchParams.prototype.isPrototypeOf(a)?this._bodyText=a.toString():p.arrayBuffer&&p.blob&&g(a)?(this._bodyArrayBuffer=u(a.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):p.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(a)||b(a))?this._bodyArrayBuffer=u(a):this._bodyText=a=Object.prototype.toString.call(a):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof a=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):p.searchParams&&URLSearchParams.prototype.isPrototypeOf(a)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},p.blob&&(this.blob=function(){var a=G(this);if(a)return a;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var a=G(this);return a||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(p.blob)return this.blob().then(_);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var a=G(this);if(a)return a;if(this._bodyBlob)return S(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(l(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},p.formData&&(this.formData=function(){return this.text().then(O)}),this.json=function(){return this.text().then(JSON.parse)},this}var y=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function m(a){var d=a.toUpperCase();return y.indexOf(d)>-1?d:a}function U(a,d){if(!(this instanceof U))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');d=d||{};var j=d.body;if(a instanceof U){if(a.bodyUsed)throw new TypeError("Already read");this.url=a.url,this.credentials=a.credentials,d.headers||(this.headers=new q(a.headers)),this.method=a.method,this.mode=a.mode,this.signal=a.signal,!j&&a._bodyInit!=null&&(j=a._bodyInit,a.bodyUsed=!0)}else this.url=String(a);if(this.credentials=d.credentials||this.credentials||"same-origin",(d.headers||!this.headers)&&(this.headers=new q(d.headers)),this.method=m(d.method||this.method||"GET"),this.mode=d.mode||this.mode||null,this.signal=d.signal||this.signal||(function(){if("AbortController"in c){var E=new AbortController;return E.signal}})(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&j)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(j),(this.method==="GET"||this.method==="HEAD")&&(d.cache==="no-store"||d.cache==="no-cache")){var R=/([?&])_=[^&]*/;if(R.test(this.url))this.url=this.url.replace(R,"$1_="+new Date().getTime());else{var x=/\?/;this.url+=(x.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}U.prototype.clone=function(){return new U(this,{body:this._bodyInit})};function O(a){var d=new FormData;return a.trim().split("&").forEach(function(j){if(j){var R=j.split("="),x=R.shift().replace(/\+/g," "),E=R.join("=").replace(/\+/g," ");d.append(decodeURIComponent(x),decodeURIComponent(E))}}),d}function M(a){var d=new q,j=a.replace(/\r?\n[\t ]+/g," ");return j.split("\r").map(function(R){return R.indexOf(`
2
+ `)===0?R.substr(1,R.length):R}).forEach(function(R){var x=R.split(":"),E=x.shift().trim();if(E){var de=x.join(":").trim();try{d.append(E,de)}catch(me){console.warn("Response "+me.message)}}}),d}h.call(U.prototype);function A(a,d){if(!(this instanceof A))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(d||(d={}),this.type="default",this.status=d.status===void 0?200:d.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=d.statusText===void 0?"":""+d.statusText,this.headers=new q(d.headers),this.url=d.url||"",this._initBody(a)}h.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new q(this.headers),url:this.url})},A.error=function(){var a=new A(null,{status:200,statusText:""});return a.ok=!1,a.status=0,a.type="error",a};var le=[301,302,303,307,308];A.redirect=function(a,d){if(le.indexOf(d)===-1)throw new RangeError("Invalid status code");return new A(null,{status:d,headers:{location:a}})},i.DOMException=c.DOMException;try{new i.DOMException}catch{i.DOMException=function(d,j){this.message=d,this.name=j;var R=Error(d);this.stack=R.stack},i.DOMException.prototype=Object.create(Error.prototype),i.DOMException.prototype.constructor=i.DOMException}function Z(a,d){return new Promise(function(j,R){var x=new U(a,d);if(x.signal&&x.signal.aborted)return R(new i.DOMException("Aborted","AbortError"));var E=new XMLHttpRequest;function de(){E.abort()}E.onload=function(){var T={statusText:E.statusText,headers:M(E.getAllResponseHeaders()||"")};x.url.indexOf("file://")===0&&(E.status<200||E.status>599)?T.status=200:T.status=E.status,T.url="responseURL"in E?E.responseURL:T.headers.get("X-Request-URL");var V="response"in E?E.response:E.responseText;setTimeout(function(){j(new A(V,T))},0)},E.onerror=function(){setTimeout(function(){R(new TypeError("Network request failed"))},0)},E.ontimeout=function(){setTimeout(function(){R(new TypeError("Network request timed out"))},0)},E.onabort=function(){setTimeout(function(){R(new i.DOMException("Aborted","AbortError"))},0)};function me(T){try{return T===""&&c.location.href?c.location.href:T}catch{return T}}if(E.open(x.method,me(x.url),!0),x.credentials==="include"?E.withCredentials=!0:x.credentials==="omit"&&(E.withCredentials=!1),"responseType"in E&&(p.blob?E.responseType="blob":p.arrayBuffer&&(E.responseType="arraybuffer")),d&&typeof d.headers=="object"&&!(d.headers instanceof q||c.Headers&&d.headers instanceof c.Headers)){var Ie=[];Object.getOwnPropertyNames(d.headers).forEach(function(T){Ie.push(I(T)),E.setRequestHeader(T,D(d.headers[T]))}),x.headers.forEach(function(T,V){Ie.indexOf(V)===-1&&E.setRequestHeader(V,T)})}else x.headers.forEach(function(T,V){E.setRequestHeader(V,T)});x.signal&&(x.signal.addEventListener("abort",de),E.onreadystatechange=function(){E.readyState===4&&x.signal.removeEventListener("abort",de)}),E.send(typeof x._bodyInit>"u"?null:x._bodyInit)})}return Z.polyfill=!0,c.fetch||(c.fetch=Z,c.Headers=q,c.Request=U,c.Response=A),i.Headers=q,i.Request=U,i.Response=A,i.fetch=Z,Object.defineProperty(i,"__esModule",{value:!0}),i})({})})(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var r=t.fetch?t:n;e=r.fetch,e.default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,o.exports=e})(re,re.exports)),re.exports}var he=He();const je=fe(he),Je=X({__proto__:null,default:je},[he]);var pe,Oe;function We(){if(Oe)return pe;Oe=1;var o=function(_){return e(_)&&!t(_)};function e(v){return!!v&&typeof v=="object"}function t(v){var _=Object.prototype.toString.call(v);return _==="[object RegExp]"||_==="[object Date]"||s(v)}var n=typeof Symbol=="function"&&Symbol.for,r=n?Symbol.for("react.element"):60103;function s(v){return v.$$typeof===r}function i(v){return Array.isArray(v)?[]:{}}function c(v,_){return _.clone!==!1&&_.isMergeableObject(v)?q(i(v),v,_):v}function p(v,_,S){return v.concat(_).map(function(l){return c(l,S)})}function g(v,_){if(!_.customMerge)return q;var S=_.customMerge(v);return typeof S=="function"?S:q}function f(v){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(v).filter(function(_){return Object.propertyIsEnumerable.call(v,_)}):[]}function b(v){return Object.keys(v).concat(f(v))}function I(v,_){try{return _ in v}catch{return!1}}function D(v,_){return I(v,_)&&!(Object.hasOwnProperty.call(v,_)&&Object.propertyIsEnumerable.call(v,_))}function F(v,_,S){var l={};return S.isMergeableObject(v)&&b(v).forEach(function(u){l[u]=c(v[u],S)}),b(_).forEach(function(u){D(v,u)||(I(v,u)&&S.isMergeableObject(_[u])?l[u]=g(u,S)(v[u],_[u],S):l[u]=c(_[u],S))}),l}function q(v,_,S){S=S||{},S.arrayMerge=S.arrayMerge||p,S.isMergeableObject=S.isMergeableObject||o,S.cloneUnlessOtherwiseSpecified=c;var l=Array.isArray(_),u=Array.isArray(v),h=l===u;return h?l?S.arrayMerge(v,_,S):F(v,_,S):c(_,S)}q.all=function(_,S){if(!Array.isArray(_))throw new Error("first argument should be an array");return _.reduce(function(l,u){return q(l,u,S)},{})};var G=q;return pe=G,pe}var ze=We();const K=fe(ze),Ue=typeof process<"u"&&process.versions&&process.versions.node?process.versions.node:"unknown",Ee=typeof process<"u"&&process.versions&&process.versions.bun?process.versions.bun:"unknown",Se=typeof window<"u"&&window.navigator&&window.navigator.userAgent?window.navigator.userAgent:"unknown",ne=()=>Se!=="unknown",Ge=()=>Ue!=="unknown",qe=()=>Ee!=="unknown";function Re(o={},e={}){return K(e,o)}function Ve(o,e){Object.keys(e).forEach(t=>{Array.isArray(e[t])?e[t].forEach(r=>{o.append(t,String(r))}):o.append(t,String(e[t]))})}const $e=()=>typeof Headers>"u"?he.Headers:Headers,se=o=>!!(o&&o.url),ye=o=>!!(o&&o.text),ke=o=>!!(Xe(o)||Ke(o)),Ke=o=>o!=null&&Buffer.isBuffer(o),Xe=o=>o==null||ne()?!1:typeof o=="object"&&typeof o.pipe=="function"&&typeof o.read=="function"&&typeof o._readableState=="object",Ye=o=>(t=>t.toLowerCase().replace(/^http/,"ws"))(o),Ze=o=>{var e,t,n,r,s,i;const c={};return o._experimentalCustomFetch&&(c.global={fetch:{client:o._experimentalCustomFetch}}),o=K(o,c),!((e=o.restProxy)===null||e===void 0)&&e.url&&(c.global={fetch:{options:{proxy:{url:(t=o.restProxy)===null||t===void 0?void 0:t.url}}}}),o=K(o,c),!((n=o.global)===null||n===void 0)&&n.url&&(c.global={fetch:{options:{url:o.global.url}},websocket:{options:{url:o.global.url}}}),o=K(o,c),!((r=o.global)===null||r===void 0)&&r.headers&&(c.global={fetch:{options:{headers:(s=o.global)===null||s===void 0?void 0:s.headers}},websocket:{options:{_nodeOnlyHeaders:(i=o.global)===null||i===void 0?void 0:i.headers}}}),o=K(o,c),o},xe="4.11.3",Qe=()=>Ge()?`node/${Ue}`:qe()?`bun/${Ee}`:ne()?`javascript ${Se}`:"unknown",oe={"Content-Type":"application/json","X-Client-Info":`@deepgram/sdk; ${ne()?"browser":"server"}; v${xe}`,"User-Agent":`@deepgram/sdk/${xe} ${Qe()}`},ie="https://api.deepgram.com",Ce="wss://agent.deepgram.com",et={global:{fetch:{options:{url:ie,headers:oe}},websocket:{options:{url:Ye(ie),_nodeOnlyHeaders:oe}}},agent:{fetch:{options:{url:ie,headers:oe}},websocket:{options:{url:Ce,_nodeOnlyHeaders:oe}}}};var H;(function(o){o[o.connecting=0]="connecting",o[o.open=1]="open",o[o.closing=2]="closing",o[o.closed=3]="closed"})(H||(H={}));var J;(function(o){o.Connecting="connecting",o.Open="open",o.Closing="closing",o.Closed="closed"})(J||(J={}));const Ae=()=>{};class Y extends Fe.EventEmitter{constructor(e){if(super(),this.factory=void 0,this.key=void 0,this.accessToken=void 0,this.namespace="global",this.version="v1",this.baseUrl=ie,this.logger=Ae,typeof e.accessToken=="function"?(this.factory=e.accessToken,this.accessToken=this.factory()):this.accessToken=e.accessToken,typeof e.key=="function"?(this.factory=e.key,this.key=this.factory()):this.key=e.key,!this.key&&!this.accessToken&&(this.accessToken=process.env.DEEPGRAM_ACCESS_TOKEN,this.accessToken||(this.key=process.env.DEEPGRAM_API_KEY)),!this.key&&!this.accessToken)throw new C("A deepgram API key or access token is required.");e=Ze(e),this.options=Re(e,et)}v(e="v1"){return this.version=e,this}get namespaceOptions(){const e=Re(this.options[this.namespace],this.options.global);return Object.assign(Object.assign({},e),{key:this.key})}getRequestUrl(e,t={version:this.version},n){t.version=this.version,e=e.replace(/:(\w+)/g,function(s,i){return t[i]});const r=new URL(e,this.baseUrl);return n&&Ve(r.searchParams,n),r}log(e,t,n){this.logger(e,t,n)}}var tt=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};const rt=typeof WebSocket<"u";class ge extends Y{constructor(e){super(e),this.conn=null,this.sendBuffer=[],this.reconnect=Ae;const{key:t,websocket:{options:n,client:r}}=this.namespaceOptions;this.proxy?this.baseUrl=n.proxy.url:this.baseUrl=n.url,r?this.transport=r:this.transport=null,n._nodeOnlyHeaders?this.headers=n._nodeOnlyHeaders:this.headers={},"Authorization"in this.headers||(this.accessToken?this.headers.Authorization=`Bearer ${this.accessToken}`:this.headers.Authorization=`Token ${t}`)}connect(e,t){if(this.conn)return;this.reconnect=(i=e)=>{this.connect(i,t)};const n=this.getRequestUrl(t,{},e),r=this.accessToken,s=this.key;if(!r&&!s)throw new Error("No key or access token provided for WebSocket connection.");if(this.transport){this.conn=new this.transport(n,void 0,{headers:this.headers}),this.setupConnection();return}if(qe()){Promise.resolve().then(()=>Me).then(({default:i})=>{this.conn=new i(n,{headers:this.headers}),console.log("Using WS package"),this.setupConnection()});return}if(rt){this.conn=new WebSocket(n,r?["bearer",r]:["token",s]),this.setupConnection();return}this.conn=new nt(n,void 0,{close:()=>{this.conn=null}}),Promise.resolve().then(()=>Me).then(({default:i})=>{this.conn=new i(n,void 0,{headers:this.headers}),this.setupConnection()})}disconnect(e,t){this.conn&&(this.conn.onclose=function(){},e?this.conn.close(e,t??""):this.conn.close(),this.conn=null)}connectionState(){switch(this.conn&&this.conn.readyState){case H.connecting:return J.Connecting;case H.open:return J.Open;case H.closing:return J.Closing;default:return J.Closed}}getReadyState(){var e,t;return(t=(e=this.conn)===null||e===void 0?void 0:e.readyState)!==null&&t!==void 0?t:H.closed}isConnected(){return this.connectionState()===J.Open}send(e){const t=()=>tt(this,void 0,void 0,function*(){var n;if(e instanceof Blob){if(e.size===0){this.log("warn","skipping `send` for zero-byte blob",e);return}e=yield e.arrayBuffer()}if(typeof e!="string"&&!e?.byteLength){this.log("warn","skipping `send` for zero-byte payload",e);return}(n=this.conn)===null||n===void 0||n.send(e)});this.isConnected()?t():this.sendBuffer.push(t)}get proxy(){var e;return this.key==="proxy"&&!!(!((e=this.namespaceOptions.websocket.options.proxy)===null||e===void 0)&&e.url)}extractErrorInformation(e,t){var n;const r={};if(t&&(r.readyState=t.readyState,r.url=typeof t.url=="string"?t.url:(n=t.url)===null||n===void 0?void 0:n.toString()),t&&typeof t=="object"){const s=t;if(s._req&&s._req.res&&(r.statusCode=s._req.res.statusCode,s._req.res.headers)){r.responseHeaders=Object.assign({},s._req.res.headers);const i=s._req.res.headers["dg-request-id"]||s._req.res.headers["x-dg-request-id"];i&&(r.requestId=i)}if(e&&"target"in e&&e.target){const i=e.target;i.url&&(r.url=i.url),i.readyState!==void 0&&(r.readyState=i.readyState)}}return r}createEnhancedError(e,t){const n=new Ne(e.message||"WebSocket connection error",Object.assign({originalEvent:e},t));return Object.assign(Object.assign({},e),{error:n,statusCode:t.statusCode,requestId:t.requestId,responseHeaders:t.responseHeaders,url:t.url,readyState:t.readyState,message:this.buildEnhancedErrorMessage(e,t)})}buildEnhancedErrorMessage(e,t){let n=e.message||"WebSocket connection error";const r=[];if(t.statusCode&&r.push(`Status: ${t.statusCode}`),t.requestId&&r.push(`Request ID: ${t.requestId}`),t.readyState!==void 0){const i=["CONNECTING","OPEN","CLOSING","CLOSED"][t.readyState]||`Unknown(${t.readyState})`;r.push(`Ready State: ${i}`)}return t.url&&r.push(`URL: ${t.url}`),r.length>0&&(n+=` (${r.join(", ")})`),n}setupConnectionEvents(e){this.conn&&(this.conn.onopen=()=>{this.emit(e.Open,this)},this.conn.onclose=t=>{this.emit(e.Close,t)},this.conn.onerror=t=>{const n=this.extractErrorInformation(t,this.conn||void 0),r=this.createEnhancedError(t,n);this.emit(e.Error,r)})}}class nt{constructor(e,t,n){this.binaryType="arraybuffer",this.onclose=()=>{},this.onerror=()=>{},this.onmessage=()=>{},this.onopen=()=>{},this.readyState=H.connecting,this.send=()=>{},this.url=null,this.url=e.toString(),this.close=n.close}}var Te=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};const st=o=>{let e;return o?e=o:typeof fetch>"u"?e=je:e=fetch,(...t)=>e(...t)},ot=({apiKey:o,customFetch:e,accessToken:t})=>{const n=st(e),r=$e();return(s,i)=>Te(void 0,void 0,void 0,function*(){const c=new r(i?.headers);return c.has("Authorization")||c.set("Authorization",t?`Bearer ${t}`:`Token ${o}`),n(s,Object.assign(Object.assign({},i),{headers:c}))})},it=()=>Te(void 0,void 0,void 0,function*(){return typeof Response>"u"?(yield Promise.resolve().then(()=>Je)).Response:Response});var W=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class z extends Y{constructor(e){if(super(e),ne()&&!this.proxy)throw new C("Due to CORS we are unable to support REST-based API calls to our API from the browser. Please consider using a proxy: https://dpgr.am/js-proxy for more information.");const{accessToken:t,key:n,fetch:r}=this;this.fetch=ot({accessToken:t,apiKey:n,customFetch:r}),this.proxy?this.baseUrl=this.namespaceOptions.fetch.options.proxy.url:this.baseUrl=this.namespaceOptions.fetch.options.url}_getErrorMessage(e){return e.msg||e.message||e.error_description||e.error||JSON.stringify(e)}_handleError(e,t){return W(this,void 0,void 0,function*(){const n=yield it();e instanceof n?e.json().then(r=>{t(new Pe(this._getErrorMessage(r),e.status||500))}).catch(r=>{t(new Q(this._getErrorMessage(r),r))}):t(new Q(this._getErrorMessage(e),e))})}_getRequestOptions(e,t,n){let r={method:e};return e==="GET"||e==="DELETE"?r=Object.assign(Object.assign({},r),t):r=Object.assign(Object.assign({duplex:"half",body:t},r),n),K(this.namespaceOptions.fetch.options,r,{clone:!1})}_handleRequest(e,t,n,r){return W(this,void 0,void 0,function*(){return new Promise((s,i)=>{const c=this.fetch;c(t,this._getRequestOptions(e,n,r)).then(p=>{if(!p.ok)throw p;s(p)}).catch(p=>this._handleError(p,i))})})}get(e,t){return W(this,void 0,void 0,function*(){return this._handleRequest("GET",e,t)})}post(e,t,n){return W(this,void 0,void 0,function*(){return this._handleRequest("POST",e,t,n)})}put(e,t,n){return W(this,void 0,void 0,function*(){return this._handleRequest("PUT",e,t,n)})}patch(e,t,n){return W(this,void 0,void 0,function*(){return this._handleRequest("PATCH",e,t,n)})}delete(e,t){return W(this,void 0,void 0,function*(){return this._handleRequest("DELETE",e,t)})}get proxy(){var e;return this.key==="proxy"&&!!(!((e=this.namespaceOptions.fetch.options.proxy)===null||e===void 0)&&e.url)}}var P;(function(o){o.Open="Open",o.Close="Close",o.Error="Error",o.Audio="Audio",o.Welcome="Welcome",o.SettingsApplied="SettingsApplied",o.ConversationText="ConversationText",o.UserStartedSpeaking="UserStartedSpeaking",o.AgentThinking="AgentThinking",o.FunctionCallRequest="FunctionCallRequest",o.AgentStartedSpeaking="AgentStartedSpeaking",o.AgentAudioDone="AgentAudioDone",o.InjectionRefused="InjectionRefused",o.PromptUpdated="PromptUpdated",o.SpeakUpdated="SpeakUpdated",o.Unhandled="Unhandled"})(P||(P={}));class at extends ge{constructor(e,t="/:version/agent/converse"){var n,r,s,i;super(e),this.namespace="agent",this.baseUrl=(i=(s=(r=(n=e.agent)===null||n===void 0?void 0:n.websocket)===null||r===void 0?void 0:r.options)===null||s===void 0?void 0:s.url)!==null&&i!==void 0?i:Ce,this.connect({},t)}setupConnection(){this.setupConnectionEvents({Open:P.Open,Close:P.Close,Error:P.Error}),this.conn&&(this.conn.onmessage=e=>{this.handleMessage(e)})}handleMessage(e){var t,n,r,s,i,c;if(typeof e.data=="string")try{const p=JSON.parse(e.data);this.handleTextMessage(p)}catch(p){this.emit(P.Error,{event:e,data:((t=e.data)===null||t===void 0?void 0:t.toString().substring(0,200))+(((n=e.data)===null||n===void 0?void 0:n.toString().length)>200?"...":""),message:"Unable to parse `data` as JSON.",error:p,url:(r=this.conn)===null||r===void 0?void 0:r.url,readyState:(s=this.conn)===null||s===void 0?void 0:s.readyState})}else e.data instanceof Blob?e.data.arrayBuffer().then(p=>{this.handleBinaryMessage(Buffer.from(p))}):e.data instanceof ArrayBuffer?this.handleBinaryMessage(Buffer.from(e.data)):Buffer.isBuffer(e.data)?this.handleBinaryMessage(e.data):(console.log("Received unknown data type",e.data),this.emit(P.Error,{event:e,message:"Received unknown data type.",url:(i=this.conn)===null||i===void 0?void 0:i.url,readyState:(c=this.conn)===null||c===void 0?void 0:c.readyState,dataType:typeof e.data}))}handleBinaryMessage(e){this.emit(P.Audio,e)}handleTextMessage(e){e.type in P?this.emit(e.type,e):this.emit(P.Unhandled,e)}configure(e){const t=JSON.stringify(Object.assign({type:"Settings"},e));this.send(t)}updatePrompt(e){this.send(JSON.stringify({type:"UpdatePrompt",prompt:e}))}updateSpeak(e){this.send(JSON.stringify({type:"UpdateSpeak",speak:e}))}injectAgentMessage(e){this.send(JSON.stringify({type:"InjectAgentMessage",content:e}))}injectUserMessage(e){this.send(JSON.stringify({type:"InjectUserMessage",content:e}))}functionCallResponse(e){this.send(JSON.stringify(Object.assign({type:"FunctionCallResponse"},e)))}keepAlive(){this.send(JSON.stringify({type:"KeepAlive"}))}}var ut=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class ct extends z{constructor(){super(...arguments),this.namespace="auth"}grantToken(e={},t=":version/auth/grant"){return ut(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t),r=JSON.stringify(e);return{result:yield this.post(n,r,{headers:{"Content-Type":"application/json"}}).then(i=>i.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}}var B;(function(o){o.Open="open",o.Close="close",o.Error="error",o.Transcript="Results",o.Metadata="Metadata",o.UtteranceEnd="UtteranceEnd",o.SpeechStarted="SpeechStarted",o.Unhandled="Unhandled"})(B||(B={}));var L;(function(o){o.Open="Open",o.Close="Close",o.Error="Error",o.Metadata="Metadata",o.Flushed="Flushed",o.Warning="Warning",o.Audio="Audio",o.Unhandled="Unhandled"})(L||(L={}));class lt extends ge{constructor(e,t={},n=":version/listen"){super(e),this.namespace="listen",this.connect(t,n)}setupConnection(){this.setupConnectionEvents({Open:B.Open,Close:B.Close,Error:B.Error}),this.conn&&(this.conn.onmessage=e=>{var t,n,r,s;try{const i=JSON.parse(e.data.toString());i.type===B.Metadata?this.emit(B.Metadata,i):i.type===B.Transcript?this.emit(B.Transcript,i):i.type===B.UtteranceEnd?this.emit(B.UtteranceEnd,i):i.type===B.SpeechStarted?this.emit(B.SpeechStarted,i):this.emit(B.Unhandled,i)}catch(i){this.emit(B.Error,{event:e,message:"Unable to parse `data` as JSON.",error:i,url:(t=this.conn)===null||t===void 0?void 0:t.url,readyState:(n=this.conn)===null||n===void 0?void 0:n.readyState,data:((r=e.data)===null||r===void 0?void 0:r.toString().substring(0,200))+(((s=e.data)===null||s===void 0?void 0:s.toString().length)>200?"...":"")})}})}configure(e){this.send(JSON.stringify({type:"Configure",processors:e}))}keepAlive(){this.send(JSON.stringify({type:"KeepAlive"}))}finalize(){this.send(JSON.stringify({type:"Finalize"}))}finish(){this.requestClose()}requestClose(){this.send(JSON.stringify({type:"CloseStream"}))}}var ae=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class dt extends z{constructor(){super(...arguments),this.namespace="listen"}transcribeUrl(e,t,n=":version/listen"){var r,s;return ae(this,void 0,void 0,function*(){try{let i;if(se(e))i=JSON.stringify(e);else throw new C("Unknown transcription source type");if(t!==void 0&&"callback"in t)throw new C("Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead.");if(!((r=t?.keyterm)===null||r===void 0)&&r.length&&!(!((s=t.model)===null||s===void 0)&&s.startsWith("nova-3")))throw new C("Keyterms are only supported with the Nova 3 models.");const c=this.getRequestUrl(n,{},Object.assign({},t));return{result:yield this.post(c,i).then(g=>g.json()),error:null}}catch(i){if(w(i))return{result:null,error:i};throw i}})}transcribeFile(e,t,n=":version/listen"){return ae(this,void 0,void 0,function*(){try{let r;if(ke(e))r=e;else throw new C("Unknown transcription source type");if(t!==void 0&&"callback"in t)throw new C("Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead.");const s=this.getRequestUrl(n,{},Object.assign({},t));return{result:yield this.post(s,r,{headers:{"Content-Type":"deepgram/audio+video"}}).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}transcribeUrlCallback(e,t,n,r=":version/listen"){return ae(this,void 0,void 0,function*(){try{let s;if(se(e))s=JSON.stringify(e);else throw new C("Unknown transcription source type");const i=this.getRequestUrl(r,{},Object.assign(Object.assign({},n),{callback:t.toString()}));return{result:yield this.post(i,s).then(p=>p.json()),error:null}}catch(s){if(w(s))return{result:null,error:s};throw s}})}transcribeFileCallback(e,t,n,r=":version/listen"){return ae(this,void 0,void 0,function*(){try{let s;if(ke(e))s=e;else throw new C("Unknown transcription source type");const i=this.getRequestUrl(r,{},Object.assign(Object.assign({},n),{callback:t.toString()}));return{result:yield this.post(i,s,{headers:{"Content-Type":"deepgram/audio+video"}}).then(p=>p.json()),error:null}}catch(s){if(w(s))return{result:null,error:s};throw s}})}}class ft extends Y{constructor(){super(...arguments),this.namespace="listen"}get prerecorded(){return new dt(this.options)}live(e={},t=":version/listen"){return new lt(this.options,e,t)}}var k=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class ht extends z{constructor(){super(...arguments),this.namespace="manage"}getTokenDetails(e=":version/auth/token"){return k(this,void 0,void 0,function*(){try{const t=this.getRequestUrl(e);return{result:yield this.get(t).then(r=>r.json()),error:null}}catch(t){if(w(t))return{result:null,error:t};throw t}})}getProjects(e=":version/projects"){return k(this,void 0,void 0,function*(){try{const t=this.getRequestUrl(e);return{result:yield this.get(t).then(r=>r.json()),error:null}}catch(t){if(w(t))return{result:null,error:t};throw t}})}getProject(e,t=":version/projects/:projectId"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}updateProject(e,t,n=":version/projects/:projectId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t),s=JSON.stringify(t);return{result:yield this.patch(r,s).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}deleteProject(e,t=":version/projects/:projectId"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return yield this.delete(n),{error:null}}catch(n){if(w(n))return{error:n};throw n}})}getProjectKeys(e,t=":version/projects/:projectId/keys"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}getProjectKey(e,t,n=":version/projects/:projectId/keys/:keyId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,keyId:t});return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}createProjectKey(e,t,n=":version/projects/:projectId/keys"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t),s=JSON.stringify(t);return{result:yield this.post(r,s).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}deleteProjectKey(e,t,n=":version/projects/:projectId/keys/:keyId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,keyId:t});return yield this.delete(r),{error:null}}catch(r){if(w(r))return{error:r};throw r}})}getProjectMembers(e,t=":version/projects/:projectId/members"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}removeProjectMember(e,t,n=":version/projects/:projectId/members/:memberId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,memberId:t});return yield this.delete(r),{error:null}}catch(r){if(w(r))return{error:r};throw r}})}getProjectMemberScopes(e,t,n=":version/projects/:projectId/members/:memberId/scopes"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,memberId:t});return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}updateProjectMemberScope(e,t,n,r=":version/projects/:projectId/members/:memberId/scopes"){return k(this,void 0,void 0,function*(){try{const s=this.getRequestUrl(r,{projectId:e,memberId:t},n),i=JSON.stringify(n);return{result:yield this.put(s,i).then(p=>p.json()),error:null}}catch(s){if(w(s))return{result:null,error:s};throw s}})}getProjectInvites(e,t=":version/projects/:projectId/invites"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}sendProjectInvite(e,t,n=":version/projects/:projectId/invites"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t),s=JSON.stringify(t);return{result:yield this.post(r,s).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}deleteProjectInvite(e,t,n=":version/projects/:projectId/invites/:email"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,email:t});return yield this.delete(r),{error:null}}catch(r){if(w(r))return{error:r};throw r}})}leaveProject(e,t=":version/projects/:projectId/leave"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.delete(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}getProjectUsageRequests(e,t,n=":version/projects/:projectId/requests"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t);return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}getProjectUsageRequest(e,t,n=":version/projects/:projectId/requests/:requestId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,requestId:t});return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}getProjectUsageSummary(e,t,n=":version/projects/:projectId/usage"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t);return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}getProjectUsageFields(e,t,n=":version/projects/:projectId/usage/fields"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t);return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}getProjectBalances(e,t=":version/projects/:projectId/balances"){return k(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}getProjectBalance(e,t,n=":version/projects/:projectId/balances/:balanceId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,balanceId:t});return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}getAllModels(e,t={},n=":version/projects/:projectId/models"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e},t);return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}getModel(e,t,n=":version/projects/:projectId/models/:modelId"){return k(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,modelId:t});return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}}var Be=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class pt extends z{constructor(){super(...arguments),this.namespace="models"}getAll(e=":version/models",t={}){return Be(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(e,{},t);return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}getModel(e,t=":version/models/:modelId"){return Be(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{modelId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}}var ue=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class yt extends z{constructor(){super(...arguments),this.namespace="read"}analyzeUrl(e,t,n=":version/read"){return ue(this,void 0,void 0,function*(){try{let r;if(se(e))r=JSON.stringify(e);else throw new C("Unknown source type");if(t!==void 0&&"callback"in t)throw new C("Callback cannot be provided as an option to a synchronous transcription. Use `analyzeUrlCallback` or `analyzeTextCallback` instead.");const s=this.getRequestUrl(n,{},Object.assign({},t));return{result:yield this.post(s,r).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}analyzeText(e,t,n=":version/read"){return ue(this,void 0,void 0,function*(){try{let r;if(ye(e))r=JSON.stringify(e);else throw new C("Unknown source type");if(t!==void 0&&"callback"in t)throw new C("Callback cannot be provided as an option to a synchronous requests. Use `analyzeUrlCallback` or `analyzeTextCallback` instead.");const s=this.getRequestUrl(n,{},Object.assign({},t));return{result:yield this.post(s,r).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}analyzeUrlCallback(e,t,n,r=":version/read"){return ue(this,void 0,void 0,function*(){try{let s;if(se(e))s=JSON.stringify(e);else throw new C("Unknown source type");const i=this.getRequestUrl(r,{},Object.assign(Object.assign({},n),{callback:t.toString()}));return{result:yield this.post(i,s).then(p=>p.json()),error:null}}catch(s){if(w(s))return{result:null,error:s};throw s}})}analyzeTextCallback(e,t,n,r=":version/read"){return ue(this,void 0,void 0,function*(){try{let s;if(ye(e))s=JSON.stringify(e);else throw new C("Unknown source type");const i=this.getRequestUrl(r,{},Object.assign(Object.assign({},n),{callback:t.toString()}));return{result:yield this.post(i,s,{headers:{"Content-Type":"deepgram/audio+video"}}).then(p=>p.json()),error:null}}catch(s){if(w(s))return{result:null,error:s};throw s}})}}var ce=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class gt extends z{constructor(){super(...arguments),this.namespace="selfhosted"}listCredentials(e,t=":version/projects/:projectId/onprem/distribution/credentials"){return ce(this,void 0,void 0,function*(){try{const n=this.getRequestUrl(t,{projectId:e});return{result:yield this.get(n).then(s=>s.json()),error:null}}catch(n){if(w(n))return{result:null,error:n};throw n}})}getCredentials(e,t,n=":version/projects/:projectId/onprem/distribution/credentials/:credentialsId"){return ce(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,credentialsId:t});return{result:yield this.get(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}createCredentials(e,t,n=":version/projects/:projectId/onprem/distribution/credentials"){return ce(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e}),s=JSON.stringify(t);return{result:yield this.post(r,s).then(c=>c.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}deleteCredentials(e,t,n=":version/projects/:projectId/onprem/distribution/credentials/:credentialsId"){return ce(this,void 0,void 0,function*(){try{const r=this.getRequestUrl(n,{projectId:e,credentialsId:t});return{result:yield this.delete(r).then(i=>i.json()),error:null}}catch(r){if(w(r))return{result:null,error:r};throw r}})}}class vt extends ge{constructor(e,t={},n=":version/speak"){super(e),this.namespace="speak",this.connect(t,n)}setupConnection(){this.setupConnectionEvents({Open:L.Open,Close:L.Close,Error:L.Error}),this.conn&&(this.conn.onmessage=e=>{this.handleMessage(e)})}handleTextMessage(e){e.type===L.Metadata?this.emit(L.Metadata,e):e.type===L.Flushed?this.emit(L.Flushed,e):e.type===L.Warning?this.emit(L.Warning,e):this.emit(L.Unhandled,e)}handleBinaryMessage(e){this.emit(L.Audio,e)}sendText(e){this.send(JSON.stringify({type:"Speak",text:e}))}flush(){this.send(JSON.stringify({type:"Flush"}))}clear(){this.send(JSON.stringify({type:"Clear"}))}requestClose(){this.send(JSON.stringify({type:"Close"}))}handleMessage(e){var t,n,r,s,i,c;if(typeof e.data=="string")try{const p=JSON.parse(e.data);this.handleTextMessage(p)}catch(p){this.emit(L.Error,{event:e,message:"Unable to parse `data` as JSON.",error:p,url:(t=this.conn)===null||t===void 0?void 0:t.url,readyState:(n=this.conn)===null||n===void 0?void 0:n.readyState,data:((r=e.data)===null||r===void 0?void 0:r.toString().substring(0,200))+(((s=e.data)===null||s===void 0?void 0:s.toString().length)>200?"...":"")})}else e.data instanceof Blob?e.data.arrayBuffer().then(p=>{this.handleBinaryMessage(Buffer.from(p))}):e.data instanceof ArrayBuffer?this.handleBinaryMessage(Buffer.from(e.data)):Buffer.isBuffer(e.data)?this.handleBinaryMessage(e.data):(console.log("Received unknown data type",e.data),this.emit(L.Error,{event:e,message:"Received unknown data type.",url:(i=this.conn)===null||i===void 0?void 0:i.url,readyState:(c=this.conn)===null||c===void 0?void 0:c.readyState,dataType:typeof e.data}))}}var ve=function(o,e,t,n){function r(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function c(f){try{g(n.next(f))}catch(b){i(b)}}function p(f){try{g(n.throw(f))}catch(b){i(b)}}function g(f){f.done?s(f.value):r(f.value).then(c,p)}g((n=n.apply(o,e||[])).next())})};class bt extends z{constructor(){super(...arguments),this.namespace="speak"}request(e,t,n=":version/speak"){return ve(this,void 0,void 0,function*(){let r;if(ye(e))r=JSON.stringify(e);else throw new C("Unknown transcription source type");const s=this.getRequestUrl(n,{},Object.assign({model:"aura-2-thalia-en"},t));return this.result=yield this.post(s,r,{headers:{Accept:"audio/*","Content-Type":"application/json"}}),this})}getStream(){return ve(this,void 0,void 0,function*(){if(!this.result)throw new Q("Tried to get stream before making request","");return this.result.body})}getHeaders(){return ve(this,void 0,void 0,function*(){if(!this.result)throw new Q("Tried to get headers before making request","");return this.result.headers})}}class mt extends Y{constructor(){super(...arguments),this.namespace="speak"}request(e,t,n=":version/speak"){return new bt(this.options).request(e,t,n)}live(e={},t=":version/speak"){return new vt(this.options,e,t)}}class wt extends Y{get auth(){return new ct(this.options)}get listen(){return new ft(this.options)}get manage(){return new ht(this.options)}get models(){return new pt(this.options)}get onprem(){return this.selfhosted}get selfhosted(){return new gt(this.options)}get read(){return new yt(this.options)}get speak(){return new mt(this.options)}agent(e="/:version/agent/converse"){return new at(this.options,e)}get transcription(){throw new N}get projects(){throw new N}get keys(){throw new N}get members(){throw new N}get scopes(){throw new N}get invitation(){throw new N}get usage(){throw new N}get billing(){throw new N}}function _t(o,e){let t={};return typeof o=="string"||typeof o=="function"?t.key=o:typeof o=="object"&&(t=o),new wt(t)}class jt{config;_deepgram=null;unityUrl;active=!1;constructor(e){this.config=e,this.unityUrl=e.unityBaseUrl||"https://api.glydebuddy.com"}async start(){if(!this.active)try{const e=await fetch(`${this.unityUrl}/api/unity/voice/auth`,{method:"POST",headers:{"Content-Type":"application/json","x-publishable-key":this.config.publishableKey},body:JSON.stringify({context_id:this.config.contextId,domain:window.location.hostname})});if(!e.ok){const s=await e.json();throw new Error(s.message||"Failed to authenticate voice session")}const{data:t}=await e.json(),{token:n,agent_config:r}=t;this.emit({type:"open",payload:{config:r}}),this._deepgram=_t(n),this._deepgram,console.log("[GlydeVoice] Connected to Deepgram with token",n),console.log("[GlydeVoice] Agent Instructions:",r.instructions),this.active=!0,this.renderUI()}catch(e){console.error("[GlydeVoice] Error starting session:",e),this.emit({type:"error",payload:e})}}stop(){this.active=!1,this.emit({type:"close"})}emit(e){this.config.onEvent&&this.config.onEvent(e)}renderUI(){if(!this.config.container)return;const e=typeof this.config.container=="string"?document.querySelector(this.config.container):this.config.container;e&&(e.innerHTML=`
3
+ <div style="padding: 20px; border: 1px solid #ccc; border-radius: 8px; background: #fff;">
4
+ <h3>Glyde Voice Agent</h3>
5
+ <p>Status: Active</p>
6
+ <button onclick="this.closest('div').remove()">Close</button>
7
+ </div>
8
+ `)}}var be,Le;function Ot(){return Le||(Le=1,be=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}),be}var Ut=Ot();const Me=Object.freeze(Object.defineProperty({__proto__:null,default:fe(Ut)},Symbol.toStringTag,{value:"Module"}));$.GlydeVoice=jt,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})}));
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@glydeunity/voice-sdk",
3
+ "version": "1.0.0",
4
+ "description": "GLYDE Voice Agent SDK - AI-powered voice interactions for web applications",
5
+ "type": "module",
6
+ "main": "./dist/voice-sdk.umd.js",
7
+ "module": "./dist/voice-sdk.es.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/voice-sdk.es.js",
13
+ "require": "./dist/voice-sdk.umd.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "dev": "vite",
22
+ "build": "tsc && vite build",
23
+ "preview": "vite preview",
24
+ "clean": "rm -rf dist"
25
+ },
26
+ "keywords": [
27
+ "voice",
28
+ "ai",
29
+ "sdk",
30
+ "speech-to-text",
31
+ "deepgram",
32
+ "recruitment",
33
+ "chatbot",
34
+ "voice-agent",
35
+ "glyde"
36
+ ],
37
+ "author": "GLYDE Inc.",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/Glyde-Inc/voice-agent-sdk.git",
42
+ "directory": "packages/sdk"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/Glyde-Inc/voice-agent-sdk/issues"
46
+ },
47
+ "homepage": "https://github.com/Glyde-Inc/voice-agent-sdk#readme",
48
+ "devDependencies": {
49
+ "typescript": "^5.9.3",
50
+ "vite": "^7.3.0",
51
+ "vite-plugin-dts": "^4.5.4"
52
+ },
53
+ "dependencies": {
54
+ "@deepgram/sdk": "^4.11.3"
55
+ },
56
+ "engines": {
57
+ "node": ">=22.0.0"
58
+ }
59
+ }
60
+