@graphen.ai/aiia-sdk 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("rxjs"),e=require("socket.io-client"),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var o="object"==typeof r&&r&&r.Object===Object&&r,a=o,i="object"==typeof self&&self&&self.Object===Object&&self,u=a||i||Function("return this")(),s=u.Symbol,c=s,f=Object.prototype,l=f.hasOwnProperty,h=f.toString,d=c?c.toStringTag:void 0;var v=function(t){var e=l.call(t,d),r=t[d];try{t[d]=void 0;var n=!0}catch(t){}var o=h.call(t);return n&&(e?t[d]=r:delete t[d]),o},p=Object.prototype.toString;var b=v,y=function(t){return p.call(t)},g=s?s.toStringTag:void 0;var _=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?b(t):y(t)};var m=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},w=_,j=m;var O,S=function(t){if(!j(t))return!1;var e=w(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},R=u["__core-js_shared__"],k=(O=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var x=function(t){return!!k&&k in t},A=Function.prototype.toString;var N=function(t){if(null!=t){try{return A.call(t)}catch(t){}try{return t+""}catch(t){}}return""},E=S,C=x,M=m,z=N,D=/^\[object .+?Constructor\]$/,P=Function.prototype,B=Object.prototype,T=P.toString,F=B.hasOwnProperty,U=RegExp("^"+T.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var $=function(t){return!(!M(t)||C(t))&&(E(t)?U:D).test(z(t))},I=function(t,e){return null==t?void 0:t[e]};var V=function(t,e){var r=I(t,e);return $(r)?r:void 0},Q=V,q=function(){try{var t=Q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),W=q;var L=function(t,e,r){"__proto__"==e&&W?W(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var G=function(t,e){return t===e||t!=t&&e!=e},J=L,H=G,K=Object.prototype.hasOwnProperty;var X=function(t,e,r){var n=t[e];K.call(t,e)&&H(n,r)&&(void 0!==r||e in t)||J(t,e,r)},Y=X,Z=L;var tt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?Z(r,u,s):Y(r,u,s)}return r};var et=function(t){return t};var rt=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},nt=Math.max;var ot=function(t,e,r){return e=nt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=nt(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),rt(t,this,u)}};var at=function(t){return function(){return t}},it=q,ut=it?function(t,e){return it(t,"toString",{configurable:!0,enumerable:!1,value:at(e),writable:!0})}:et,st=Date.now;var ct=function(t){var e=0,r=0;return function(){var n=st(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ut),ft=et,lt=ot,ht=ct;var dt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},vt=S,pt=dt;var bt=function(t){return null!=t&&pt(t.length)&&!vt(t)},yt=/^(?:0|[1-9]\d*)$/;var gt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&yt.test(t))&&t>-1&&t%1==0&&t<e},_t=G,mt=bt,wt=gt,jt=m;var Ot=function(t,e){return ht(lt(t,e,ft),t+"")},St=function(t,e,r){if(!jt(r))return!1;var n=typeof e;return!!("number"==n?mt(r)&&wt(e,r.length):"string"==n&&e in r)&&_t(r[e],t)};var Rt=function(t){return Ot(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&St(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},kt=Object.prototype;var xt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||kt)};var At=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Nt=function(t){return null!=t&&"object"==typeof t},Et=_,Ct=Nt;var Mt=function(t){return Ct(t)&&"[object Arguments]"==Et(t)},zt=Nt,Dt=Object.prototype,Pt=Dt.hasOwnProperty,Bt=Dt.propertyIsEnumerable,Tt=Mt(function(){return arguments}())?Mt:function(t){return zt(t)&&Pt.call(t,"callee")&&!Bt.call(t,"callee")},Ft=Array.isArray,Ut=n(Ft),$t={exports:{}};var It=function(){return!1};!function(t,e){var r=u,n=It,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,s=(i?i.isBuffer:void 0)||n;t.exports=s}($t,$t.exports);var Vt=$t.exports,Qt=_,qt=dt,Wt=Nt,Lt={};Lt["[object Float32Array]"]=Lt["[object Float64Array]"]=Lt["[object Int8Array]"]=Lt["[object Int16Array]"]=Lt["[object Int32Array]"]=Lt["[object Uint8Array]"]=Lt["[object Uint8ClampedArray]"]=Lt["[object Uint16Array]"]=Lt["[object Uint32Array]"]=!0,Lt["[object Arguments]"]=Lt["[object Array]"]=Lt["[object ArrayBuffer]"]=Lt["[object Boolean]"]=Lt["[object DataView]"]=Lt["[object Date]"]=Lt["[object Error]"]=Lt["[object Function]"]=Lt["[object Map]"]=Lt["[object Number]"]=Lt["[object Object]"]=Lt["[object RegExp]"]=Lt["[object Set]"]=Lt["[object String]"]=Lt["[object WeakMap]"]=!1;var Gt=function(t){return Wt(t)&&qt(t.length)&&!!Lt[Qt(t)]};var Jt=function(t){return function(e){return t(e)}},Ht={exports:{}};!function(t,e){var r=o,n=e&&!e.nodeType&&e,a=n&&t&&!t.nodeType&&t,i=a&&a.exports===n&&r.process,u=function(){try{var t=a&&a.require&&a.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=u}(Ht,Ht.exports);var Kt=Ht.exports,Xt=Gt,Yt=Jt,Zt=Kt&&Kt.isTypedArray,te=Zt?Yt(Zt):Xt,ee=At,re=Tt,ne=Ft,oe=Vt,ae=gt,ie=te,ue=Object.prototype.hasOwnProperty;var se=function(t,e){var r=ne(t),n=!r&&re(t),o=!r&&!n&&oe(t),a=!r&&!n&&!o&&ie(t),i=r||n||o||a,u=i?ee(t.length,String):[],s=u.length;for(var c in t)!e&&!ue.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ae(c,s))||u.push(c);return u};var ce=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),fe=xt,le=ce,he=Object.prototype.hasOwnProperty;var de=se,ve=function(t){if(!fe(t))return le(t);var e=[];for(var r in Object(t))he.call(t,r)&&"constructor"!=r&&e.push(r);return e},pe=bt;var be,ye=function(t){return pe(t)?de(t):ve(t)},ge=X,_e=tt,me=Rt,we=bt,je=xt,Oe=ye,Se=Object.prototype.hasOwnProperty,Re=n(me(function(t,e){if(je(e)||we(e))_e(e,Oe(e),t);else for(var r in e)Se.call(e,r)&&ge(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(be||(be={}));const ke="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class xe{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Re({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Re({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ae=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Ne=Ae,Ee=function(t){return t!=t},Ce=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Me=function(t,e,r){return e==e?Ce(t,e,r):Ne(t,Ee,r)},ze=_,De=Ft,Pe=Nt;var Be=function(t){return"string"==typeof t||!De(t)&&Pe(t)&&"[object String]"==ze(t)},Te=/\s/;var Fe=function(t){for(var e=t.length;e--&&Te.test(t.charAt(e)););return e},Ue=/^\s+/;var $e=_,Ie=Nt;var Ve=function(t){return"symbol"==typeof t||Ie(t)&&"[object Symbol]"==$e(t)},Qe=function(t){return t?t.slice(0,Fe(t)+1).replace(Ue,""):t},qe=m,We=Ve,Le=/^[-+]0x[0-9a-f]+$/i,Ge=/^0b[01]+$/i,Je=/^0o[0-7]+$/i,He=parseInt;var Ke=function(t){if("number"==typeof t)return t;if(We(t))return NaN;if(qe(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=qe(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Qe(t);var r=Ge.test(t);return r||Je.test(t)?He(t.slice(2),r?2:8):Le.test(t)?NaN:+t},Xe=1/0;var Ye=function(t){return t?(t=Ke(t))===Xe||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ze=function(t){var e=Ye(t),r=e%1;return e==e?r?e-r:e:0};var tr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},er=tr;var rr=function(t,e){return er(e,function(e){return t[e]})},nr=ye;var or=function(t){return null==t?[]:rr(t,nr(t))},ar=n(or),ir=Me,ur=bt,sr=Be,cr=Ze,fr=or,lr=Math.max;var hr=n(function(t,e,r,n){t=ur(t)?t:fr(t),r=r&&!n?cr(r):0;var o=t.length;return r<0&&(r=lr(o+r,0)),sr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&ir(t,e,r)>-1});const dr={info:()=>{},error:()=>{},warn:()=>{}};function vr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:hr(t,"error"),warn:hr(t,"warn"),info:hr(t,"info")}}(t);e&&(dr.info=console.log),r&&(dr.error=console.error),n&&(dr.warn=console.warn)}var pr=Ft,br=Ve,yr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,gr=/^\w*$/;var _r=function(t,e){if(pr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!br(t))||(gr.test(t)||!yr.test(t)||null!=e&&t in Object(e))},mr=V(Object,"create"),wr=mr;var jr=function(){this.__data__=wr?wr(null):{},this.size=0};var Or=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Sr=mr,Rr=Object.prototype.hasOwnProperty;var kr=function(t){var e=this.__data__;if(Sr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Rr.call(e,t)?e[t]:void 0},xr=mr,Ar=Object.prototype.hasOwnProperty;var Nr=mr;var Er=jr,Cr=Or,Mr=kr,zr=function(t){var e=this.__data__;return xr?void 0!==e[t]:Ar.call(e,t)},Dr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Nr&&void 0===e?"__lodash_hash_undefined__":e,this};function Pr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Pr.prototype.clear=Er,Pr.prototype.delete=Cr,Pr.prototype.get=Mr,Pr.prototype.has=zr,Pr.prototype.set=Dr;var Br=Pr;var Tr=function(){this.__data__=[],this.size=0},Fr=G;var Ur=function(t,e){for(var r=t.length;r--;)if(Fr(t[r][0],e))return r;return-1},$r=Ur,Ir=Array.prototype.splice;var Vr=Ur;var Qr=Ur;var qr=Ur;var Wr=Tr,Lr=function(t){var e=this.__data__,r=$r(e,t);return!(r<0)&&(r==e.length-1?e.pop():Ir.call(e,r,1),--this.size,!0)},Gr=function(t){var e=this.__data__,r=Vr(e,t);return r<0?void 0:e[r][1]},Jr=function(t){return Qr(this.__data__,t)>-1},Hr=function(t,e){var r=this.__data__,n=qr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Kr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Kr.prototype.clear=Wr,Kr.prototype.delete=Lr,Kr.prototype.get=Gr,Kr.prototype.has=Jr,Kr.prototype.set=Hr;var Xr=Kr,Yr=V(u,"Map"),Zr=Br,tn=Xr,en=Yr;var rn=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var nn=function(t,e){var r=t.__data__;return rn(e)?r["string"==typeof e?"string":"hash"]:r.map},on=nn;var an=nn;var un=nn;var sn=nn;var cn=function(){this.size=0,this.__data__={hash:new Zr,map:new(en||tn),string:new Zr}},fn=function(t){var e=on(this,t).delete(t);return this.size-=e?1:0,e},ln=function(t){return an(this,t).get(t)},hn=function(t){return un(this,t).has(t)},dn=function(t,e){var r=sn(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function vn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}vn.prototype.clear=cn,vn.prototype.delete=fn,vn.prototype.get=ln,vn.prototype.has=hn,vn.prototype.set=dn;var pn=vn,bn=pn;function yn(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(yn.Cache||bn),r}yn.Cache=bn;var gn=yn;var _n=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,mn=/\\(\\)?/g,wn=function(t){var e=gn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(_n,function(t,r,n,o){e.push(n?o.replace(mn,"$1"):r||t)}),e}),jn=tr,On=Ft,Sn=Ve,Rn=s?s.prototype:void 0,kn=Rn?Rn.toString:void 0;var xn=function t(e){if("string"==typeof e)return e;if(On(e))return jn(e,t)+"";if(Sn(e))return kn?kn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},An=xn;var Nn=Ft,En=_r,Cn=wn,Mn=function(t){return null==t?"":An(t)};var zn=function(t,e){return Nn(t)?t:En(t,e)?[t]:Cn(Mn(t))},Dn=Ve;var Pn=function(t){if("string"==typeof t||Dn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Bn=zn,Tn=Pn;var Fn=function(t,e){for(var r=0,n=(e=Bn(e,t)).length;null!=t&&r<n;)t=t[Tn(e[r++])];return r&&r==n?t:void 0},Un=Fn;var $n,In,Vn=function(t,e,r){var n=null==t?void 0:Un(t,e);return void 0===n?r:n},Qn=n(Vn);function qn(t,e,r){return Math.max(r,Math.min(t,e))}function Wn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Ln(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=qn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}($n||($n={}));class Gn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Wn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{dr.error("[ERROR]: pause speech fail"),dr.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{dr.error("[ERROR]: resume speech fail"),dr.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Jn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(e,r){this.stream=e,this.audioContext=r,this.pcmSub=new t.Subject}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(In||(In={}));class Hn{state;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx.sampleRate}get pcm(){return this.pcmSub.asObservable()}constructor(){this.state=In.padding,this.pcmSub=new t.Subject,this.destory=new t.Subject}async init(e){if(this.destory.closed)throw new Error(be["實例已摧毀"]);const r=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===r)throw this.state=In.rejected,new Error(be["未獲得媒體裝置權限"]);const n=new AudioContext;try{await n.audioWorklet.addModule(e)}catch(t){throw dr.error(t),this.state=In.loadfail,new Error(be["Worklet模組載入失敗"])}this.state=In.allowed,this.audioManager=new Gn(n),this.vadManager=new Jn(r,n),this.vadManager.pcm.pipe(t.takeUntil(this.destory)).subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=Qn(t,"buffer",void 0),r=Qn(t,"float32",void 0),n=Qn(t,"int16",void 0),o=Qn(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx.close(),this.destory.next(),this.destory.complete()}}var Kn=Xr;var Xn=Xr,Yn=Yr,Zn=pn;var to=Xr,eo=function(){this.__data__=new Kn,this.size=0},ro=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},no=function(t){return this.__data__.get(t)},oo=function(t){return this.__data__.has(t)},ao=function(t,e){var r=this.__data__;if(r instanceof Xn){var n=r.__data__;if(!Yn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Zn(n)}return r.set(t,e),this.size=r.size,this};function io(t){var e=this.__data__=new to(t);this.size=e.size}io.prototype.clear=eo,io.prototype.delete=ro,io.prototype.get=no,io.prototype.has=oo,io.prototype.set=ao;var uo=io;var so=pn,co=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},fo=function(t){return this.__data__.has(t)};function lo(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new so;++e<r;)this.add(t[e])}lo.prototype.add=lo.prototype.push=co,lo.prototype.has=fo;var ho=lo,vo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},po=function(t,e){return t.has(e)};var bo=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),f=a.get(e);if(c&&f)return c==e&&f==t;var l=-1,h=!0,d=2&r?new ho:void 0;for(a.set(t,e),a.set(e,t);++l<u;){var v=t[l],p=e[l];if(n)var b=i?n(p,v,l,e,t,a):n(v,p,l,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!vo(e,function(t,e){if(!po(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var yo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var go=u.Uint8Array,_o=G,mo=bo,wo=yo,jo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},Oo=s?s.prototype:void 0,So=Oo?Oo.valueOf:void 0;var Ro=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new go(t),new go(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return _o(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=wo;case"[object Set]":var s=1&n;if(u||(u=jo),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var f=mo(u(t),u(e),n,o,a,i);return i.delete(t),f;case"[object Symbol]":if(So)return So.call(t)==So.call(e)}return!1};var ko=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},xo=ko,Ao=Ft;var No=function(t,e,r){var n=e(t);return Ao(t)?n:xo(n,r(t))};var Eo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Co=function(){return[]},Mo=Object.prototype.propertyIsEnumerable,zo=Object.getOwnPropertySymbols,Do=No,Po=zo?function(t){return null==t?[]:(t=Object(t),Eo(zo(t),function(e){return Mo.call(t,e)}))}:Co,Bo=ye;var To=function(t){return Do(t,Bo,Po)},Fo=Object.prototype.hasOwnProperty;var Uo=function(t,e,r,n,o,a){var i=1&r,u=To(t),s=u.length;if(s!=To(e).length&&!i)return!1;for(var c=s;c--;){var f=u[c];if(!(i?f in e:Fo.call(e,f)))return!1}var l=a.get(t),h=a.get(e);if(l&&h)return l==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[f=u[c]],b=e[f];if(n)var y=i?n(b,p,f,e,t,a):n(p,b,f,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==f)}if(d&&!v){var g=t.constructor,_=e.constructor;g==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof _&&_ instanceof _||(d=!1)}return a.delete(t),a.delete(e),d},$o=V(u,"DataView"),Io=Yr,Vo=V(u,"Promise"),Qo=V(u,"Set"),qo=V(u,"WeakMap"),Wo=_,Lo=N,Go="[object Map]",Jo="[object Promise]",Ho="[object Set]",Ko="[object WeakMap]",Xo="[object DataView]",Yo=Lo($o),Zo=Lo(Io),ta=Lo(Vo),ea=Lo(Qo),ra=Lo(qo),na=Wo;($o&&na(new $o(new ArrayBuffer(1)))!=Xo||Io&&na(new Io)!=Go||Vo&&na(Vo.resolve())!=Jo||Qo&&na(new Qo)!=Ho||qo&&na(new qo)!=Ko)&&(na=function(t){var e=Wo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Lo(r):"";if(n)switch(n){case Yo:return Xo;case Zo:return Go;case ta:return Jo;case ea:return Ho;case ra:return Ko}return e});var oa=uo,aa=bo,ia=Ro,ua=Uo,sa=na,ca=Ft,fa=Vt,la=te,ha="[object Arguments]",da="[object Array]",va="[object Object]",pa=Object.prototype.hasOwnProperty;var ba=function(t,e,r,n,o,a){var i=ca(t),u=ca(e),s=i?da:sa(t),c=u?da:sa(e),f=(s=s==ha?va:s)==va,l=(c=c==ha?va:c)==va,h=s==c;if(h&&fa(t)){if(!fa(e))return!1;i=!0,f=!1}if(h&&!f)return a||(a=new oa),i||la(t)?aa(t,e,r,n,o,a):ia(t,e,s,r,n,o,a);if(!(1&r)){var d=f&&pa.call(t,"__wrapped__"),v=l&&pa.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new oa),o(p,b,r,n,a)}}return!!h&&(a||(a=new oa),ua(t,e,r,n,o,a))},ya=Nt;var ga=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ya(e)&&!ya(r)?e!=e&&r!=r:ba(e,r,n,o,t,a))},_a=uo,ma=ga;var wa=m;var ja=function(t){return t==t&&!wa(t)},Oa=ja,Sa=ye;var Ra=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},ka=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],f=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var l=new _a;if(n)var h=n(c,f,s,t,e,l);if(!(void 0===h?ma(f,c,3,n,l):h))return!1}}return!0},xa=function(t){for(var e=Sa(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Oa(o)]}return e},Aa=Ra;var Na=zn,Ea=Tt,Ca=Ft,Ma=gt,za=dt,Da=Pn;var Pa=function(t,e){return null!=t&&e in Object(t)},Ba=function(t,e,r){for(var n=-1,o=(e=Na(e,t)).length,a=!1;++n<o;){var i=Da(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&za(o)&&Ma(i,o)&&(Ca(t)||Ea(t))};var Ta=ga,Fa=Vn,Ua=function(t,e){return null!=t&&Ba(t,e,Pa)},$a=_r,Ia=ja,Va=Ra,Qa=Pn;var qa=Fn;var Wa=function(t){return function(e){return null==e?void 0:e[t]}},La=function(t){return function(e){return qa(e,t)}},Ga=_r,Ja=Pn;var Ha=function(t){var e=xa(t);return 1==e.length&&e[0][2]?Aa(e[0][0],e[0][1]):function(r){return r===t||ka(r,t,e)}},Ka=function(t,e){return $a(t)&&Ia(e)?Va(Qa(t),e):function(r){var n=Fa(r,t);return void 0===n&&n===e?Ua(r,t):Ta(e,n,3)}},Xa=et,Ya=Ft,Za=function(t){return Ga(t)?Wa(Ja(t)):La(t)};var ti=function(t){return"function"==typeof t?t:null==t?Xa:"object"==typeof t?Ya(t)?Ka(t[0],t[1]):Ha(t):Za(t)};var ei=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ri=ye;var ni=bt;var oi=function(t,e){return function(r,n){if(null==r)return r;if(!ni(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&ei(t,e,ri)}),ai=bt;var ii=tr,ui=ti,si=function(t,e){var r=-1,n=ai(t)?Array(t.length):[];return oi(t,function(t,o,a){n[++r]=e(t,o,a)}),n},ci=Ft;var fi=n(function(t,e){return(ci(t)?ii:si)(t,ui(e))}),li=ti,hi=bt,di=ye;var vi=function(t){return function(e,r,n){var o=Object(e);if(!hi(e)){var a=li(r);e=di(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},pi=Ae,bi=ti,yi=Ze,gi=Math.max;var _i,mi=n(vi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:yi(r);return o<0&&(o=gi(n+o,0)),pi(t,bi(e),o)}));class wi{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(r){this.destorySub=new t.Subject,this.messageSub=new t.Subject;const{specific:n,id:o}=r.project;this.socket=e.io(r.ws_url,Re({autoConnect:!1},n&&void 0!==o?{query:{uuid:o}}:{}))}start(){const e="list",r="cloud",n="channel";t.fromEvent(this.socket,e).pipe(t.take(1),t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:e,data:t})}),t.fromEvent(this.socket,r).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),t.fromEvent(this.socket,n).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:n,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(_i||(_i={}));class ji{config;media;chat;destorySub;projectsSub;layoutSub;cloudSampleRate;get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(e,r){this.config=e,this.media=r,this.layoutSub=new t.Subject,this.projectsSub=new t.Subject,this.destorySub=new t.Subject,this.cloudSampleRate=16e3,this.chat=new wi(e)}start(){this.chat.message.pipe(t.takeUntil(this.destorySub)).subscribe(({event:t,data:e})=>{switch(t){case"cloud":this.cloudToObj(e);break;case"list":{const{id:t,name:r,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=mi(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):this.projectsSub.next(e);break}}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==Qn(e,"signal")?this.behavior(e):Ut(e)?fi(e,this.behavior):fi(ar(e),this.behavior)}catch(t){dr.error("aiia websocket","onmessage error",t)}}behavior(e){switch(e.signal){case"layout":this.layoutSub.next(e.content);break;case"audio":if("sampleRate"===e.command)this.cloudSampleRate=e.content;else if(this.media.state===In.allowed)switch(e.command){case"pcm":{const t=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Wn(new Int16Array(e.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:t}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===e.content&&this.media.state===In.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}),this.media.pcm.pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Ln(t)})}),this.media.startRecord()):dr.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.");break;default:dr.info(e.signal)}}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}exports.initSdk=function(t){if(ke){const e=new xe(Re({},t));vr(e.debug);const r=new Hn,n=new ji(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(be["環境錯誤(browser)"])};
1
+ "use strict";var t=require("rxjs"),e=require("socket.io-client"),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var o="object"==typeof r&&r&&r.Object===Object&&r,a=o,i="object"==typeof self&&self&&self.Object===Object&&self,u=a||i||Function("return this")(),s=u.Symbol,c=s,f=Object.prototype,l=f.hasOwnProperty,h=f.toString,d=c?c.toStringTag:void 0;var v=function(t){var e=l.call(t,d),r=t[d];try{t[d]=void 0;var n=!0}catch(t){}var o=h.call(t);return n&&(e?t[d]=r:delete t[d]),o},p=Object.prototype.toString;var b=v,y=function(t){return p.call(t)},g=s?s.toStringTag:void 0;var m=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?b(t):y(t)};var _=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},w=m,j=_;var O,S=function(t){if(!j(t))return!1;var e=w(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},R=u["__core-js_shared__"],x=(O=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var k=function(t){return!!x&&x in t},C=Function.prototype.toString;var A=function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""},N=S,E=k,M=_,z=A,D=/^\[object .+?Constructor\]$/,P=Function.prototype,B=Object.prototype,T=P.toString,F=B.hasOwnProperty,U=RegExp("^"+T.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var $=function(t){return!(!M(t)||E(t))&&(N(t)?U:D).test(z(t))},I=function(t,e){return null==t?void 0:t[e]};var V=function(t,e){var r=I(t,e);return $(r)?r:void 0},q=V,Q=function(){try{var t=q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),W=Q;var L=function(t,e,r){"__proto__"==e&&W?W(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var G=function(t,e){return t===e||t!=t&&e!=e},J=L,H=G,K=Object.prototype.hasOwnProperty;var X=function(t,e,r){var n=t[e];K.call(t,e)&&H(n,r)&&(void 0!==r||e in t)||J(t,e,r)},Y=X,Z=L;var tt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?Z(r,u,s):Y(r,u,s)}return r};var et=function(t){return t};var rt=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},nt=Math.max;var ot=function(t,e,r){return e=nt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=nt(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),rt(t,this,u)}};var at=function(t){return function(){return t}},it=Q,ut=it?function(t,e){return it(t,"toString",{configurable:!0,enumerable:!1,value:at(e),writable:!0})}:et,st=Date.now;var ct=function(t){var e=0,r=0;return function(){var n=st(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ut),ft=et,lt=ot,ht=ct;var dt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},vt=S,pt=dt;var bt=function(t){return null!=t&&pt(t.length)&&!vt(t)},yt=/^(?:0|[1-9]\d*)$/;var gt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&yt.test(t))&&t>-1&&t%1==0&&t<e},mt=G,_t=bt,wt=gt,jt=_;var Ot=function(t,e){return ht(lt(t,e,ft),t+"")},St=function(t,e,r){if(!jt(r))return!1;var n=typeof e;return!!("number"==n?_t(r)&&wt(e,r.length):"string"==n&&e in r)&&mt(r[e],t)};var Rt=function(t){return Ot(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&St(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},xt=Object.prototype;var kt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||xt)};var Ct=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var At=function(t){return null!=t&&"object"==typeof t},Nt=m,Et=At;var Mt=function(t){return Et(t)&&"[object Arguments]"==Nt(t)},zt=At,Dt=Object.prototype,Pt=Dt.hasOwnProperty,Bt=Dt.propertyIsEnumerable,Tt=Mt(function(){return arguments}())?Mt:function(t){return zt(t)&&Pt.call(t,"callee")&&!Bt.call(t,"callee")},Ft=Array.isArray,Ut=n(Ft),$t={exports:{}};var It=function(){return!1};!function(t,e){var r=u,n=It,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,s=(i?i.isBuffer:void 0)||n;t.exports=s}($t,$t.exports);var Vt=$t.exports,qt=m,Qt=dt,Wt=At,Lt={};Lt["[object Float32Array]"]=Lt["[object Float64Array]"]=Lt["[object Int8Array]"]=Lt["[object Int16Array]"]=Lt["[object Int32Array]"]=Lt["[object Uint8Array]"]=Lt["[object Uint8ClampedArray]"]=Lt["[object Uint16Array]"]=Lt["[object Uint32Array]"]=!0,Lt["[object Arguments]"]=Lt["[object Array]"]=Lt["[object ArrayBuffer]"]=Lt["[object Boolean]"]=Lt["[object DataView]"]=Lt["[object Date]"]=Lt["[object Error]"]=Lt["[object Function]"]=Lt["[object Map]"]=Lt["[object Number]"]=Lt["[object Object]"]=Lt["[object RegExp]"]=Lt["[object Set]"]=Lt["[object String]"]=Lt["[object WeakMap]"]=!1;var Gt=function(t){return Wt(t)&&Qt(t.length)&&!!Lt[qt(t)]};var Jt=function(t){return function(e){return t(e)}},Ht={exports:{}};!function(t,e){var r=o,n=e&&!e.nodeType&&e,a=n&&t&&!t.nodeType&&t,i=a&&a.exports===n&&r.process,u=function(){try{var t=a&&a.require&&a.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=u}(Ht,Ht.exports);var Kt=Ht.exports,Xt=Gt,Yt=Jt,Zt=Kt&&Kt.isTypedArray,te=Zt?Yt(Zt):Xt,ee=Ct,re=Tt,ne=Ft,oe=Vt,ae=gt,ie=te,ue=Object.prototype.hasOwnProperty;var se=function(t,e){var r=ne(t),n=!r&&re(t),o=!r&&!n&&oe(t),a=!r&&!n&&!o&&ie(t),i=r||n||o||a,u=i?ee(t.length,String):[],s=u.length;for(var c in t)!e&&!ue.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ae(c,s))||u.push(c);return u};var ce=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),fe=kt,le=ce,he=Object.prototype.hasOwnProperty;var de=se,ve=function(t){if(!fe(t))return le(t);var e=[];for(var r in Object(t))he.call(t,r)&&"constructor"!=r&&e.push(r);return e},pe=bt;var be,ye=function(t){return pe(t)?de(t):ve(t)},ge=X,me=tt,_e=Rt,we=bt,je=kt,Oe=ye,Se=Object.prototype.hasOwnProperty,Re=n(_e(function(t,e){if(je(e)||we(e))me(e,Oe(e),t);else for(var r in e)Se.call(e,r)&&ge(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(be||(be={}));const xe="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class ke{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Re({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Re({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ce=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Ae=Ce,Ne=function(t){return t!=t},Ee=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Me=function(t,e,r){return e==e?Ee(t,e,r):Ae(t,Ne,r)},ze=m,De=Ft,Pe=At;var Be=function(t){return"string"==typeof t||!De(t)&&Pe(t)&&"[object String]"==ze(t)},Te=/\s/;var Fe=function(t){for(var e=t.length;e--&&Te.test(t.charAt(e)););return e},Ue=/^\s+/;var $e=m,Ie=At;var Ve=function(t){return"symbol"==typeof t||Ie(t)&&"[object Symbol]"==$e(t)},qe=function(t){return t?t.slice(0,Fe(t)+1).replace(Ue,""):t},Qe=_,We=Ve,Le=/^[-+]0x[0-9a-f]+$/i,Ge=/^0b[01]+$/i,Je=/^0o[0-7]+$/i,He=parseInt;var Ke=function(t){if("number"==typeof t)return t;if(We(t))return NaN;if(Qe(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Qe(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=qe(t);var r=Ge.test(t);return r||Je.test(t)?He(t.slice(2),r?2:8):Le.test(t)?NaN:+t},Xe=1/0;var Ye=function(t){return t?(t=Ke(t))===Xe||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ze=function(t){var e=Ye(t),r=e%1;return e==e?r?e-r:e:0};var tr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},er=tr;var rr=function(t,e){return er(e,function(e){return t[e]})},nr=ye;var or=function(t){return null==t?[]:rr(t,nr(t))},ar=n(or),ir=Me,ur=bt,sr=Be,cr=Ze,fr=or,lr=Math.max;var hr=n(function(t,e,r,n){t=ur(t)?t:fr(t),r=r&&!n?cr(r):0;var o=t.length;return r<0&&(r=lr(o+r,0)),sr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&ir(t,e,r)>-1});const dr={info:()=>{},error:()=>{},warn:()=>{}};function vr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:hr(t,"error"),warn:hr(t,"warn"),info:hr(t,"info")}}(t);e&&(dr.info=console.log),r&&(dr.error=console.error),n&&(dr.warn=console.warn)}var pr=Ft,br=Ve,yr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,gr=/^\w*$/;var mr=function(t,e){if(pr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!br(t))||(gr.test(t)||!yr.test(t)||null!=e&&t in Object(e))},_r=V(Object,"create"),wr=_r;var jr=function(){this.__data__=wr?wr(null):{},this.size=0};var Or=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Sr=_r,Rr=Object.prototype.hasOwnProperty;var xr=function(t){var e=this.__data__;if(Sr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Rr.call(e,t)?e[t]:void 0},kr=_r,Cr=Object.prototype.hasOwnProperty;var Ar=_r;var Nr=jr,Er=Or,Mr=xr,zr=function(t){var e=this.__data__;return kr?void 0!==e[t]:Cr.call(e,t)},Dr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Ar&&void 0===e?"__lodash_hash_undefined__":e,this};function Pr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Pr.prototype.clear=Nr,Pr.prototype.delete=Er,Pr.prototype.get=Mr,Pr.prototype.has=zr,Pr.prototype.set=Dr;var Br=Pr;var Tr=function(){this.__data__=[],this.size=0},Fr=G;var Ur=function(t,e){for(var r=t.length;r--;)if(Fr(t[r][0],e))return r;return-1},$r=Ur,Ir=Array.prototype.splice;var Vr=Ur;var qr=Ur;var Qr=Ur;var Wr=Tr,Lr=function(t){var e=this.__data__,r=$r(e,t);return!(r<0)&&(r==e.length-1?e.pop():Ir.call(e,r,1),--this.size,!0)},Gr=function(t){var e=this.__data__,r=Vr(e,t);return r<0?void 0:e[r][1]},Jr=function(t){return qr(this.__data__,t)>-1},Hr=function(t,e){var r=this.__data__,n=Qr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Kr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Kr.prototype.clear=Wr,Kr.prototype.delete=Lr,Kr.prototype.get=Gr,Kr.prototype.has=Jr,Kr.prototype.set=Hr;var Xr=Kr,Yr=V(u,"Map"),Zr=Br,tn=Xr,en=Yr;var rn=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var nn=function(t,e){var r=t.__data__;return rn(e)?r["string"==typeof e?"string":"hash"]:r.map},on=nn;var an=nn;var un=nn;var sn=nn;var cn=function(){this.size=0,this.__data__={hash:new Zr,map:new(en||tn),string:new Zr}},fn=function(t){var e=on(this,t).delete(t);return this.size-=e?1:0,e},ln=function(t){return an(this,t).get(t)},hn=function(t){return un(this,t).has(t)},dn=function(t,e){var r=sn(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function vn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}vn.prototype.clear=cn,vn.prototype.delete=fn,vn.prototype.get=ln,vn.prototype.has=hn,vn.prototype.set=dn;var pn=vn,bn=pn;function yn(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(yn.Cache||bn),r}yn.Cache=bn;var gn=yn;var mn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,_n=/\\(\\)?/g,wn=function(t){var e=gn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(mn,function(t,r,n,o){e.push(n?o.replace(_n,"$1"):r||t)}),e}),jn=tr,On=Ft,Sn=Ve,Rn=s?s.prototype:void 0,xn=Rn?Rn.toString:void 0;var kn=function t(e){if("string"==typeof e)return e;if(On(e))return jn(e,t)+"";if(Sn(e))return xn?xn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Cn=kn;var An=Ft,Nn=mr,En=wn,Mn=function(t){return null==t?"":Cn(t)};var zn=function(t,e){return An(t)?t:Nn(t,e)?[t]:En(Mn(t))},Dn=Ve;var Pn=function(t){if("string"==typeof t||Dn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Bn=zn,Tn=Pn;var Fn=function(t,e){for(var r=0,n=(e=Bn(e,t)).length;null!=t&&r<n;)t=t[Tn(e[r++])];return r&&r==n?t:void 0},Un=Fn;var $n,In,Vn=function(t,e,r){var n=null==t?void 0:Un(t,e);return void 0===n?r:n},qn=n(Vn);function Qn(t,e,r){return Math.max(r,Math.min(t,e))}function Wn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Ln(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Qn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}($n||($n={}));class Gn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Wn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{dr.error("[ERROR]: pause speech fail"),dr.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{dr.error("[ERROR]: resume speech fail"),dr.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Jn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(e,r){this.stream=e,this.audioContext=r,this.pcmSub=new t.Subject}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(In||(In={}));class Hn{_state;stateSub;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get state(){return this._state}set state(t){t!==this._state&&(this._state=t,this.stateSub.next(t))}get stateObs(){return this.stateSub.asObservable()}constructor(){this.stateSub=new t.Subject,this.pcmSub=new t.Subject,this.destory=new t.Subject,this.state=In.padding}async init(e){if(this.destory.closed)throw new Error(be["實例已摧毀"]);const r=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===r)throw this.state=In.rejected,new Error(be["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(e)}catch(t){throw dr.error(t),this.state=In.loadfail,new Error(be["Worklet模組載入失敗"])}this.state=In.allowed,this.audioManager=new Gn(this.audioCtx),this.vadManager=new Jn(r,this.audioCtx),this.vadManager.pcm.pipe(t.takeUntil(this.destory)).subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=qn(t,"buffer",void 0),r=qn(t,"float32",void 0),n=qn(t,"int16",void 0),o=qn(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx.close(),this.destory.next(),this.destory.complete()}}var Kn=Xr;var Xn=Xr,Yn=Yr,Zn=pn;var to=Xr,eo=function(){this.__data__=new Kn,this.size=0},ro=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},no=function(t){return this.__data__.get(t)},oo=function(t){return this.__data__.has(t)},ao=function(t,e){var r=this.__data__;if(r instanceof Xn){var n=r.__data__;if(!Yn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Zn(n)}return r.set(t,e),this.size=r.size,this};function io(t){var e=this.__data__=new to(t);this.size=e.size}io.prototype.clear=eo,io.prototype.delete=ro,io.prototype.get=no,io.prototype.has=oo,io.prototype.set=ao;var uo=io;var so=pn,co=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},fo=function(t){return this.__data__.has(t)};function lo(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new so;++e<r;)this.add(t[e])}lo.prototype.add=lo.prototype.push=co,lo.prototype.has=fo;var ho=lo,vo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},po=function(t,e){return t.has(e)};var bo=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),f=a.get(e);if(c&&f)return c==e&&f==t;var l=-1,h=!0,d=2&r?new ho:void 0;for(a.set(t,e),a.set(e,t);++l<u;){var v=t[l],p=e[l];if(n)var b=i?n(p,v,l,e,t,a):n(v,p,l,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!vo(e,function(t,e){if(!po(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var yo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var go=u.Uint8Array,mo=G,_o=bo,wo=yo,jo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},Oo=s?s.prototype:void 0,So=Oo?Oo.valueOf:void 0;var Ro=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new go(t),new go(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return mo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=wo;case"[object Set]":var s=1&n;if(u||(u=jo),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var f=_o(u(t),u(e),n,o,a,i);return i.delete(t),f;case"[object Symbol]":if(So)return So.call(t)==So.call(e)}return!1};var xo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},ko=xo,Co=Ft;var Ao=function(t,e,r){var n=e(t);return Co(t)?n:ko(n,r(t))};var No=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Eo=function(){return[]},Mo=Object.prototype.propertyIsEnumerable,zo=Object.getOwnPropertySymbols,Do=Ao,Po=zo?function(t){return null==t?[]:(t=Object(t),No(zo(t),function(e){return Mo.call(t,e)}))}:Eo,Bo=ye;var To=function(t){return Do(t,Bo,Po)},Fo=Object.prototype.hasOwnProperty;var Uo=function(t,e,r,n,o,a){var i=1&r,u=To(t),s=u.length;if(s!=To(e).length&&!i)return!1;for(var c=s;c--;){var f=u[c];if(!(i?f in e:Fo.call(e,f)))return!1}var l=a.get(t),h=a.get(e);if(l&&h)return l==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[f=u[c]],b=e[f];if(n)var y=i?n(b,p,f,e,t,a):n(p,b,f,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==f)}if(d&&!v){var g=t.constructor,m=e.constructor;g==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof m&&m instanceof m||(d=!1)}return a.delete(t),a.delete(e),d},$o=V(u,"DataView"),Io=Yr,Vo=V(u,"Promise"),qo=V(u,"Set"),Qo=V(u,"WeakMap"),Wo=m,Lo=A,Go="[object Map]",Jo="[object Promise]",Ho="[object Set]",Ko="[object WeakMap]",Xo="[object DataView]",Yo=Lo($o),Zo=Lo(Io),ta=Lo(Vo),ea=Lo(qo),ra=Lo(Qo),na=Wo;($o&&na(new $o(new ArrayBuffer(1)))!=Xo||Io&&na(new Io)!=Go||Vo&&na(Vo.resolve())!=Jo||qo&&na(new qo)!=Ho||Qo&&na(new Qo)!=Ko)&&(na=function(t){var e=Wo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Lo(r):"";if(n)switch(n){case Yo:return Xo;case Zo:return Go;case ta:return Jo;case ea:return Ho;case ra:return Ko}return e});var oa=uo,aa=bo,ia=Ro,ua=Uo,sa=na,ca=Ft,fa=Vt,la=te,ha="[object Arguments]",da="[object Array]",va="[object Object]",pa=Object.prototype.hasOwnProperty;var ba=function(t,e,r,n,o,a){var i=ca(t),u=ca(e),s=i?da:sa(t),c=u?da:sa(e),f=(s=s==ha?va:s)==va,l=(c=c==ha?va:c)==va,h=s==c;if(h&&fa(t)){if(!fa(e))return!1;i=!0,f=!1}if(h&&!f)return a||(a=new oa),i||la(t)?aa(t,e,r,n,o,a):ia(t,e,s,r,n,o,a);if(!(1&r)){var d=f&&pa.call(t,"__wrapped__"),v=l&&pa.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new oa),o(p,b,r,n,a)}}return!!h&&(a||(a=new oa),ua(t,e,r,n,o,a))},ya=At;var ga=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ya(e)&&!ya(r)?e!=e&&r!=r:ba(e,r,n,o,t,a))},ma=uo,_a=ga;var wa=_;var ja=function(t){return t==t&&!wa(t)},Oa=ja,Sa=ye;var Ra=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},xa=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],f=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var l=new ma;if(n)var h=n(c,f,s,t,e,l);if(!(void 0===h?_a(f,c,3,n,l):h))return!1}}return!0},ka=function(t){for(var e=Sa(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Oa(o)]}return e},Ca=Ra;var Aa=zn,Na=Tt,Ea=Ft,Ma=gt,za=dt,Da=Pn;var Pa=function(t,e){return null!=t&&e in Object(t)},Ba=function(t,e,r){for(var n=-1,o=(e=Aa(e,t)).length,a=!1;++n<o;){var i=Da(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&za(o)&&Ma(i,o)&&(Ea(t)||Na(t))};var Ta=ga,Fa=Vn,Ua=function(t,e){return null!=t&&Ba(t,e,Pa)},$a=mr,Ia=ja,Va=Ra,qa=Pn;var Qa=Fn;var Wa=function(t){return function(e){return null==e?void 0:e[t]}},La=function(t){return function(e){return Qa(e,t)}},Ga=mr,Ja=Pn;var Ha=function(t){var e=ka(t);return 1==e.length&&e[0][2]?Ca(e[0][0],e[0][1]):function(r){return r===t||xa(r,t,e)}},Ka=function(t,e){return $a(t)&&Ia(e)?Va(qa(t),e):function(r){var n=Fa(r,t);return void 0===n&&n===e?Ua(r,t):Ta(e,n,3)}},Xa=et,Ya=Ft,Za=function(t){return Ga(t)?Wa(Ja(t)):La(t)};var ti=function(t){return"function"==typeof t?t:null==t?Xa:"object"==typeof t?Ya(t)?Ka(t[0],t[1]):Ha(t):Za(t)};var ei=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ri=ye;var ni=bt;var oi=function(t,e){return function(r,n){if(null==r)return r;if(!ni(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&ei(t,e,ri)}),ai=bt;var ii=tr,ui=ti,si=function(t,e){var r=-1,n=ai(t)?Array(t.length):[];return oi(t,function(t,o,a){n[++r]=e(t,o,a)}),n},ci=Ft;var fi=n(function(t,e){return(ci(t)?ii:si)(t,ui(e))}),li=ti,hi=bt,di=ye;var vi=function(t){return function(e,r,n){var o=Object(e);if(!hi(e)){var a=li(r);e=di(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},pi=Ce,bi=ti,yi=Ze,gi=Math.max;var mi,_i=n(vi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:yi(r);return o<0&&(o=gi(n+o,0)),pi(t,bi(e),o)}));class wi{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(r){this.destorySub=new t.Subject,this.messageSub=new t.Subject;const{specific:n,id:o}=r.project;this.socket=e.io(r.ws_url,Re({autoConnect:!1},n&&void 0!==o?{query:{uuid:o}}:{}))}start(){const e="list",r="cloud",n="channel";t.fromEvent(this.socket,e).pipe(t.take(1),t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:e,data:t})}),t.fromEvent(this.socket,r).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),t.fromEvent(this.socket,n).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:n,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(mi||(mi={}));class ji{config;media;chat;destorySub;projectsSub;layoutSub;cloudSampleRate;get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(e,r){this.config=e,this.media=r,this.layoutSub=new t.Subject,this.projectsSub=new t.Subject,this.destorySub=new t.Subject,this.cloudSampleRate=16e3,this.chat=new wi(e)}start(){this.chat.message.pipe(t.takeUntil(this.destorySub)).subscribe(({event:e,data:r})=>{switch(e){case"cloud":this.cloudToObj(r);break;case"list":{const{id:t,name:e,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=_i(r,r=>r.name===e||r.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):this.projectsSub.next(r);break}case"channel":this.media.state===In.allowed?this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}):this.media.state===In.padding&&this.media.stateObs.pipe(t.takeUntil(this.destorySub)).subscribe(t=>{t===In.allowed&&this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate})})}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==qn(e,"signal")?this.behavior(e):Ut(e)?fi(e,this.behavior):fi(ar(e),this.behavior)}catch(t){dr.error("aiia websocket","onmessage error",t)}}behavior(e){switch(e.signal){case"layout":this.layoutSub.next(e.content);break;case"audio":if("sampleRate"===e.command)this.cloudSampleRate=e.content;else if(this.media.state===In.allowed)switch(e.command){case"pcm":{const t=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Wn(new Int16Array(e.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:t}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===e.content&&this.media.state===In.allowed?(this.media.pcm.pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Ln(t)})}),this.media.startRecord()):dr.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.");break;default:dr.info(e.signal)}}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}exports.MediaManager=Hn,exports.initSdk=function(t){if(xe){const e=new ke(Re({},t));vr(e.debug);const r=new Hn,n=new ji(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(be["環境錯誤(browser)"])};
package/dist/browser.d.ts CHANGED
@@ -170,8 +170,9 @@ export declare function initSdk(options?: Omit<InitOptions, "webserver" | "port"
170
170
 
171
171
  declare type LayoutID = string | number;
172
172
 
173
- declare class MediaManager {
174
- state: MediaStateEnum;
173
+ export declare class MediaManager {
174
+ private _state;
175
+ private stateSub;
175
176
  audioCtx: AudioContext;
176
177
  audioManager: AudioManager;
177
178
  vadManager: VoiceDetectManager;
@@ -179,6 +180,9 @@ declare class MediaManager {
179
180
  private pcmSub;
180
181
  get sampleRate(): number;
181
182
  get pcm(): Observable<Float32Array<ArrayBufferLike>>;
183
+ get state(): MediaStateEnum;
184
+ set state(v: MediaStateEnum);
185
+ get stateObs(): Observable<MediaStateEnum>;
182
186
  constructor();
183
187
  init(workletUrl: string): Promise<void>;
184
188
  addAudioQueue(input: {
package/dist/browser.mjs CHANGED
@@ -1 +1 @@
1
- import{Subject as t,takeUntil as e,fromEvent as r,take as n}from"rxjs";import{io as o}from"socket.io-client";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u="object"==typeof a&&a&&a.Object===Object&&a,s=u,c="object"==typeof self&&self&&self.Object===Object&&self,f=s||c||Function("return this")(),l=f.Symbol,h=l,d=Object.prototype,v=d.hasOwnProperty,p=d.toString,b=h?h.toStringTag:void 0;var y=function(t){var e=v.call(t,b),r=t[b];try{t[b]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[b]=r:delete t[b]),o},g=Object.prototype.toString;var _=y,m=function(t){return g.call(t)},w=l?l.toStringTag:void 0;var j=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?_(t):m(t)};var O=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},S=j,R=O;var x,k=function(t){if(!R(t))return!1;var e=S(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},A=f["__core-js_shared__"],N=(x=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"";var C=function(t){return!!N&&N in t},E=Function.prototype.toString;var M=function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""},z=k,D=C,P=O,B=M,T=/^\[object .+?Constructor\]$/,F=Function.prototype,$=Object.prototype,I=F.toString,V=$.hasOwnProperty,Q=RegExp("^"+I.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var U=function(t){return!(!P(t)||D(t))&&(z(t)?Q:T).test(B(t))},W=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=W(t,e);return U(r)?r:void 0},L=q,G=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=G;var H=function(t,e,r){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var K=function(t,e){return t===e||t!=t&&e!=e},X=H,Y=K,Z=Object.prototype.hasOwnProperty;var tt=function(t,e,r){var n=t[e];Z.call(t,e)&&Y(n,r)&&(void 0!==r||e in t)||X(t,e,r)},et=tt,rt=H;var nt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?rt(r,u,s):et(r,u,s)}return r};var ot=function(t){return t};var at=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},it=Math.max;var ut=function(t,e,r){return e=it(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=it(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),at(t,this,u)}};var st=function(t){return function(){return t}},ct=G,ft=ct?function(t,e){return ct(t,"toString",{configurable:!0,enumerable:!1,value:st(e),writable:!0})}:ot,lt=Date.now;var ht=function(t){var e=0,r=0;return function(){var n=lt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ft),dt=ot,vt=ut,pt=ht;var bt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},yt=k,gt=bt;var _t=function(t){return null!=t&&gt(t.length)&&!yt(t)},mt=/^(?:0|[1-9]\d*)$/;var wt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&mt.test(t))&&t>-1&&t%1==0&&t<e},jt=K,Ot=_t,St=wt,Rt=O;var xt=function(t,e){return pt(vt(t,e,dt),t+"")},kt=function(t,e,r){if(!Rt(r))return!1;var n=typeof e;return!!("number"==n?Ot(r)&&St(e,r.length):"string"==n&&e in r)&&jt(r[e],t)};var At=function(t){return xt(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&kt(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},Nt=Object.prototype;var Ct=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Nt)};var Et=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Mt=function(t){return null!=t&&"object"==typeof t},zt=j,Dt=Mt;var Pt=function(t){return Dt(t)&&"[object Arguments]"==zt(t)},Bt=Mt,Tt=Object.prototype,Ft=Tt.hasOwnProperty,$t=Tt.propertyIsEnumerable,It=Pt(function(){return arguments}())?Pt:function(t){return Bt(t)&&Ft.call(t,"callee")&&!$t.call(t,"callee")},Vt=Array.isArray,Qt=i(Vt),Ut={exports:{}};var Wt=function(){return!1};!function(t,e){var r=f,n=Wt,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,u=(i?i.isBuffer:void 0)||n;t.exports=u}(Ut,Ut.exports);var qt=Ut.exports,Lt=j,Gt=bt,Jt=Mt,Ht={};Ht["[object Float32Array]"]=Ht["[object Float64Array]"]=Ht["[object Int8Array]"]=Ht["[object Int16Array]"]=Ht["[object Int32Array]"]=Ht["[object Uint8Array]"]=Ht["[object Uint8ClampedArray]"]=Ht["[object Uint16Array]"]=Ht["[object Uint32Array]"]=!0,Ht["[object Arguments]"]=Ht["[object Array]"]=Ht["[object ArrayBuffer]"]=Ht["[object Boolean]"]=Ht["[object DataView]"]=Ht["[object Date]"]=Ht["[object Error]"]=Ht["[object Function]"]=Ht["[object Map]"]=Ht["[object Number]"]=Ht["[object Object]"]=Ht["[object RegExp]"]=Ht["[object Set]"]=Ht["[object String]"]=Ht["[object WeakMap]"]=!1;var Kt=function(t){return Jt(t)&&Gt(t.length)&&!!Ht[Lt(t)]};var Xt=function(t){return function(e){return t(e)}},Yt={exports:{}};!function(t,e){var r=u,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,a=o&&o.exports===n&&r.process,i=function(){try{var t=o&&o.require&&o.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=i}(Yt,Yt.exports);var Zt=Yt.exports,te=Kt,ee=Xt,re=Zt&&Zt.isTypedArray,ne=re?ee(re):te,oe=Et,ae=It,ie=Vt,ue=qt,se=wt,ce=ne,fe=Object.prototype.hasOwnProperty;var le=function(t,e){var r=ie(t),n=!r&&ae(t),o=!r&&!n&&ue(t),a=!r&&!n&&!o&&ce(t),i=r||n||o||a,u=i?oe(t.length,String):[],s=u.length;for(var c in t)!e&&!fe.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||se(c,s))||u.push(c);return u};var he=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),de=Ct,ve=he,pe=Object.prototype.hasOwnProperty;var be=le,ye=function(t){if(!de(t))return ve(t);var e=[];for(var r in Object(t))pe.call(t,r)&&"constructor"!=r&&e.push(r);return e},ge=_t;var _e,me=function(t){return ge(t)?be(t):ye(t)},we=tt,je=nt,Oe=At,Se=_t,Re=Ct,xe=me,ke=Object.prototype.hasOwnProperty,Ae=i(Oe(function(t,e){if(Re(e)||Se(e))je(e,xe(e),t);else for(var r in e)ke.call(e,r)&&we(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(_e||(_e={}));const Ne="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class Ce{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Ae({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Ae({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ee=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Me=Ee,ze=function(t){return t!=t},De=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Pe=function(t,e,r){return e==e?De(t,e,r):Me(t,ze,r)},Be=j,Te=Vt,Fe=Mt;var $e=function(t){return"string"==typeof t||!Te(t)&&Fe(t)&&"[object String]"==Be(t)},Ie=/\s/;var Ve=function(t){for(var e=t.length;e--&&Ie.test(t.charAt(e)););return e},Qe=/^\s+/;var Ue=j,We=Mt;var qe=function(t){return"symbol"==typeof t||We(t)&&"[object Symbol]"==Ue(t)},Le=function(t){return t?t.slice(0,Ve(t)+1).replace(Qe,""):t},Ge=O,Je=qe,He=/^[-+]0x[0-9a-f]+$/i,Ke=/^0b[01]+$/i,Xe=/^0o[0-7]+$/i,Ye=parseInt;var Ze=function(t){if("number"==typeof t)return t;if(Je(t))return NaN;if(Ge(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Ge(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Le(t);var r=Ke.test(t);return r||Xe.test(t)?Ye(t.slice(2),r?2:8):He.test(t)?NaN:+t},tr=1/0;var er=function(t){return t?(t=Ze(t))===tr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var rr=function(t){var e=er(t),r=e%1;return e==e?r?e-r:e:0};var nr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},or=nr;var ar=function(t,e){return or(e,function(e){return t[e]})},ir=me;var ur=function(t){return null==t?[]:ar(t,ir(t))},sr=i(ur),cr=Pe,fr=_t,lr=$e,hr=rr,dr=ur,vr=Math.max;var pr=i(function(t,e,r,n){t=fr(t)?t:dr(t),r=r&&!n?hr(r):0;var o=t.length;return r<0&&(r=vr(o+r,0)),lr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&cr(t,e,r)>-1});const br={info:()=>{},error:()=>{},warn:()=>{}};function yr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:pr(t,"error"),warn:pr(t,"warn"),info:pr(t,"info")}}(t);e&&(br.info=console.log),r&&(br.error=console.error),n&&(br.warn=console.warn)}var gr=Vt,_r=qe,mr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wr=/^\w*$/;var jr=function(t,e){if(gr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!_r(t))||(wr.test(t)||!mr.test(t)||null!=e&&t in Object(e))},Or=q(Object,"create"),Sr=Or;var Rr=function(){this.__data__=Sr?Sr(null):{},this.size=0};var xr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},kr=Or,Ar=Object.prototype.hasOwnProperty;var Nr=function(t){var e=this.__data__;if(kr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Ar.call(e,t)?e[t]:void 0},Cr=Or,Er=Object.prototype.hasOwnProperty;var Mr=Or;var zr=Rr,Dr=xr,Pr=Nr,Br=function(t){var e=this.__data__;return Cr?void 0!==e[t]:Er.call(e,t)},Tr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Mr&&void 0===e?"__lodash_hash_undefined__":e,this};function Fr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Fr.prototype.clear=zr,Fr.prototype.delete=Dr,Fr.prototype.get=Pr,Fr.prototype.has=Br,Fr.prototype.set=Tr;var $r=Fr;var Ir=function(){this.__data__=[],this.size=0},Vr=K;var Qr=function(t,e){for(var r=t.length;r--;)if(Vr(t[r][0],e))return r;return-1},Ur=Qr,Wr=Array.prototype.splice;var qr=Qr;var Lr=Qr;var Gr=Qr;var Jr=Ir,Hr=function(t){var e=this.__data__,r=Ur(e,t);return!(r<0)&&(r==e.length-1?e.pop():Wr.call(e,r,1),--this.size,!0)},Kr=function(t){var e=this.__data__,r=qr(e,t);return r<0?void 0:e[r][1]},Xr=function(t){return Lr(this.__data__,t)>-1},Yr=function(t,e){var r=this.__data__,n=Gr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Zr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Zr.prototype.clear=Jr,Zr.prototype.delete=Hr,Zr.prototype.get=Kr,Zr.prototype.has=Xr,Zr.prototype.set=Yr;var tn=Zr,en=q(f,"Map"),rn=$r,nn=tn,on=en;var an=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var un=function(t,e){var r=t.__data__;return an(e)?r["string"==typeof e?"string":"hash"]:r.map},sn=un;var cn=un;var fn=un;var ln=un;var hn=function(){this.size=0,this.__data__={hash:new rn,map:new(on||nn),string:new rn}},dn=function(t){var e=sn(this,t).delete(t);return this.size-=e?1:0,e},vn=function(t){return cn(this,t).get(t)},pn=function(t){return fn(this,t).has(t)},bn=function(t,e){var r=ln(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function yn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}yn.prototype.clear=hn,yn.prototype.delete=dn,yn.prototype.get=vn,yn.prototype.has=pn,yn.prototype.set=bn;var gn=yn,_n=gn;function mn(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(mn.Cache||_n),r}mn.Cache=_n;var wn=mn;var jn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,On=/\\(\\)?/g,Sn=function(t){var e=wn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(jn,function(t,r,n,o){e.push(n?o.replace(On,"$1"):r||t)}),e}),Rn=nr,xn=Vt,kn=qe,An=l?l.prototype:void 0,Nn=An?An.toString:void 0;var Cn=function t(e){if("string"==typeof e)return e;if(xn(e))return Rn(e,t)+"";if(kn(e))return Nn?Nn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},En=Cn;var Mn=Vt,zn=jr,Dn=Sn,Pn=function(t){return null==t?"":En(t)};var Bn=function(t,e){return Mn(t)?t:zn(t,e)?[t]:Dn(Pn(t))},Tn=qe;var Fn=function(t){if("string"==typeof t||Tn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},$n=Bn,In=Fn;var Vn=function(t,e){for(var r=0,n=(e=$n(e,t)).length;null!=t&&r<n;)t=t[In(e[r++])];return r&&r==n?t:void 0},Qn=Vn;var Un,Wn,qn=function(t,e,r){var n=null==t?void 0:Qn(t,e);return void 0===n?r:n},Ln=i(qn);function Gn(t,e,r){return Math.max(r,Math.min(t,e))}function Jn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Hn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Gn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}(Un||(Un={}));class Kn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Jn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{br.error("[ERROR]: pause speech fail"),br.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{br.error("[ERROR]: resume speech fail"),br.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Xn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(e,r){this.stream=e,this.audioContext=r,this.pcmSub=new t}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(Wn||(Wn={}));class Yn{state;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx.sampleRate}get pcm(){return this.pcmSub.asObservable()}constructor(){this.state=Wn.padding,this.pcmSub=new t,this.destory=new t}async init(t){if(this.destory.closed)throw new Error(_e["實例已摧毀"]);const r=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===r)throw this.state=Wn.rejected,new Error(_e["未獲得媒體裝置權限"]);const n=new AudioContext;try{await n.audioWorklet.addModule(t)}catch(t){throw br.error(t),this.state=Wn.loadfail,new Error(_e["Worklet模組載入失敗"])}this.state=Wn.allowed,this.audioManager=new Kn(n),this.vadManager=new Xn(r,n),this.vadManager.pcm.pipe(e(this.destory)).subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=Ln(t,"buffer",void 0),r=Ln(t,"float32",void 0),n=Ln(t,"int16",void 0),o=Ln(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx.close(),this.destory.next(),this.destory.complete()}}var Zn=tn;var to=tn,eo=en,ro=gn;var no=tn,oo=function(){this.__data__=new Zn,this.size=0},ao=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},io=function(t){return this.__data__.get(t)},uo=function(t){return this.__data__.has(t)},so=function(t,e){var r=this.__data__;if(r instanceof to){var n=r.__data__;if(!eo||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new ro(n)}return r.set(t,e),this.size=r.size,this};function co(t){var e=this.__data__=new no(t);this.size=e.size}co.prototype.clear=oo,co.prototype.delete=ao,co.prototype.get=io,co.prototype.has=uo,co.prototype.set=so;var fo=co;var lo=gn,ho=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vo=function(t){return this.__data__.has(t)};function po(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new lo;++e<r;)this.add(t[e])}po.prototype.add=po.prototype.push=ho,po.prototype.has=vo;var bo=po,yo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},go=function(t,e){return t.has(e)};var _o=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),f=a.get(e);if(c&&f)return c==e&&f==t;var l=-1,h=!0,d=2&r?new bo:void 0;for(a.set(t,e),a.set(e,t);++l<u;){var v=t[l],p=e[l];if(n)var b=i?n(p,v,l,e,t,a):n(v,p,l,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!yo(e,function(t,e){if(!go(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var mo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var wo=f.Uint8Array,jo=K,Oo=_o,So=mo,Ro=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},xo=l?l.prototype:void 0,ko=xo?xo.valueOf:void 0;var Ao=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new wo(t),new wo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return jo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=So;case"[object Set]":var s=1&n;if(u||(u=Ro),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var f=Oo(u(t),u(e),n,o,a,i);return i.delete(t),f;case"[object Symbol]":if(ko)return ko.call(t)==ko.call(e)}return!1};var No=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Co=No,Eo=Vt;var Mo=function(t,e,r){var n=e(t);return Eo(t)?n:Co(n,r(t))};var zo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Do=function(){return[]},Po=Object.prototype.propertyIsEnumerable,Bo=Object.getOwnPropertySymbols,To=Mo,Fo=Bo?function(t){return null==t?[]:(t=Object(t),zo(Bo(t),function(e){return Po.call(t,e)}))}:Do,$o=me;var Io=function(t){return To(t,$o,Fo)},Vo=Object.prototype.hasOwnProperty;var Qo=function(t,e,r,n,o,a){var i=1&r,u=Io(t),s=u.length;if(s!=Io(e).length&&!i)return!1;for(var c=s;c--;){var f=u[c];if(!(i?f in e:Vo.call(e,f)))return!1}var l=a.get(t),h=a.get(e);if(l&&h)return l==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[f=u[c]],b=e[f];if(n)var y=i?n(b,p,f,e,t,a):n(p,b,f,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==f)}if(d&&!v){var g=t.constructor,_=e.constructor;g==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof _&&_ instanceof _||(d=!1)}return a.delete(t),a.delete(e),d},Uo=q(f,"DataView"),Wo=en,qo=q(f,"Promise"),Lo=q(f,"Set"),Go=q(f,"WeakMap"),Jo=j,Ho=M,Ko="[object Map]",Xo="[object Promise]",Yo="[object Set]",Zo="[object WeakMap]",ta="[object DataView]",ea=Ho(Uo),ra=Ho(Wo),na=Ho(qo),oa=Ho(Lo),aa=Ho(Go),ia=Jo;(Uo&&ia(new Uo(new ArrayBuffer(1)))!=ta||Wo&&ia(new Wo)!=Ko||qo&&ia(qo.resolve())!=Xo||Lo&&ia(new Lo)!=Yo||Go&&ia(new Go)!=Zo)&&(ia=function(t){var e=Jo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ho(r):"";if(n)switch(n){case ea:return ta;case ra:return Ko;case na:return Xo;case oa:return Yo;case aa:return Zo}return e});var ua=fo,sa=_o,ca=Ao,fa=Qo,la=ia,ha=Vt,da=qt,va=ne,pa="[object Arguments]",ba="[object Array]",ya="[object Object]",ga=Object.prototype.hasOwnProperty;var _a=function(t,e,r,n,o,a){var i=ha(t),u=ha(e),s=i?ba:la(t),c=u?ba:la(e),f=(s=s==pa?ya:s)==ya,l=(c=c==pa?ya:c)==ya,h=s==c;if(h&&da(t)){if(!da(e))return!1;i=!0,f=!1}if(h&&!f)return a||(a=new ua),i||va(t)?sa(t,e,r,n,o,a):ca(t,e,s,r,n,o,a);if(!(1&r)){var d=f&&ga.call(t,"__wrapped__"),v=l&&ga.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new ua),o(p,b,r,n,a)}}return!!h&&(a||(a=new ua),fa(t,e,r,n,o,a))},ma=Mt;var wa=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ma(e)&&!ma(r)?e!=e&&r!=r:_a(e,r,n,o,t,a))},ja=fo,Oa=wa;var Sa=O;var Ra=function(t){return t==t&&!Sa(t)},xa=Ra,ka=me;var Aa=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Na=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],f=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var l=new ja;if(n)var h=n(c,f,s,t,e,l);if(!(void 0===h?Oa(f,c,3,n,l):h))return!1}}return!0},Ca=function(t){for(var e=ka(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xa(o)]}return e},Ea=Aa;var Ma=Bn,za=It,Da=Vt,Pa=wt,Ba=bt,Ta=Fn;var Fa=function(t,e){return null!=t&&e in Object(t)},$a=function(t,e,r){for(var n=-1,o=(e=Ma(e,t)).length,a=!1;++n<o;){var i=Ta(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&Ba(o)&&Pa(i,o)&&(Da(t)||za(t))};var Ia=wa,Va=qn,Qa=function(t,e){return null!=t&&$a(t,e,Fa)},Ua=jr,Wa=Ra,qa=Aa,La=Fn;var Ga=Vn;var Ja=function(t){return function(e){return null==e?void 0:e[t]}},Ha=function(t){return function(e){return Ga(e,t)}},Ka=jr,Xa=Fn;var Ya=function(t){var e=Ca(t);return 1==e.length&&e[0][2]?Ea(e[0][0],e[0][1]):function(r){return r===t||Na(r,t,e)}},Za=function(t,e){return Ua(t)&&Wa(e)?qa(La(t),e):function(r){var n=Va(r,t);return void 0===n&&n===e?Qa(r,t):Ia(e,n,3)}},ti=ot,ei=Vt,ri=function(t){return Ka(t)?Ja(Xa(t)):Ha(t)};var ni=function(t){return"function"==typeof t?t:null==t?ti:"object"==typeof t?ei(t)?Za(t[0],t[1]):Ya(t):ri(t)};var oi=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ai=me;var ii=_t;var ui=function(t,e){return function(r,n){if(null==r)return r;if(!ii(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&oi(t,e,ai)}),si=_t;var ci=nr,fi=ni,li=function(t,e){var r=-1,n=si(t)?Array(t.length):[];return ui(t,function(t,o,a){n[++r]=e(t,o,a)}),n},hi=Vt;var di=i(function(t,e){return(hi(t)?ci:li)(t,fi(e))}),vi=ni,pi=_t,bi=me;var yi=function(t){return function(e,r,n){var o=Object(e);if(!pi(e)){var a=vi(r);e=bi(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},gi=Ee,_i=ni,mi=rr,wi=Math.max;var ji,Oi=i(yi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:mi(r);return o<0&&(o=wi(n+o,0)),gi(t,_i(e),o)}));class Si{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(e){this.destorySub=new t,this.messageSub=new t;const{specific:r,id:n}=e.project;this.socket=o(e.ws_url,Ae({autoConnect:!1},r&&void 0!==n?{query:{uuid:n}}:{}))}start(){const t="list",o="cloud",a="channel";r(this.socket,t).pipe(n(1),e(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),r(this.socket,o).pipe(e(this.destorySub)).subscribe(t=>{this.messageSub.next({event:o,data:t})}),r(this.socket,a).pipe(e(this.destorySub)).subscribe(t=>{this.messageSub.next({event:a,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(ji||(ji={}));class Ri{config;media;chat;destorySub;projectsSub;layoutSub;cloudSampleRate;get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(e,r){this.config=e,this.media=r,this.layoutSub=new t,this.projectsSub=new t,this.destorySub=new t,this.cloudSampleRate=16e3,this.chat=new Si(e)}start(){this.chat.message.pipe(e(this.destorySub)).subscribe(({event:t,data:e})=>{switch(t){case"cloud":this.cloudToObj(e);break;case"list":{const{id:t,name:r,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=Oi(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):this.projectsSub.next(e);break}}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==Ln(e,"signal")?this.behavior(e):Qt(e)?di(e,this.behavior):di(sr(e),this.behavior)}catch(t){br.error("aiia websocket","onmessage error",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate=t.content;else if(this.media.state===Wn.allowed)switch(t.command){case"pcm":{const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Jn(new Int16Array(t.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===t.content&&this.media.state===Wn.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}),this.media.pcm.pipe(e(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Hn(t)})}),this.media.startRecord()):br.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.");break;default:br.info(t.signal)}}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}function xi(t){if(Ne){const e=new Ce(Ae({},t));yr(e.debug);const r=new Yn,n=new Ri(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(_e["環境錯誤(browser)"])}export{xi as initSdk};
1
+ import{Subject as t,takeUntil as e,fromEvent as r,take as n}from"rxjs";import{io as o}from"socket.io-client";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u="object"==typeof a&&a&&a.Object===Object&&a,s=u,c="object"==typeof self&&self&&self.Object===Object&&self,f=s||c||Function("return this")(),l=f.Symbol,h=l,d=Object.prototype,v=d.hasOwnProperty,p=d.toString,b=h?h.toStringTag:void 0;var y=function(t){var e=v.call(t,b),r=t[b];try{t[b]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[b]=r:delete t[b]),o},g=Object.prototype.toString;var m=y,_=function(t){return g.call(t)},w=l?l.toStringTag:void 0;var j=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?m(t):_(t)};var O=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},S=j,R=O;var x,k=function(t){if(!R(t))return!1;var e=S(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},C=f["__core-js_shared__"],A=(x=/[^.]+$/.exec(C&&C.keys&&C.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"";var N=function(t){return!!A&&A in t},E=Function.prototype.toString;var M=function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""},z=k,D=N,P=O,B=M,T=/^\[object .+?Constructor\]$/,F=Function.prototype,$=Object.prototype,I=F.toString,V=$.hasOwnProperty,Q=RegExp("^"+I.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var U=function(t){return!(!P(t)||D(t))&&(z(t)?Q:T).test(B(t))},W=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=W(t,e);return U(r)?r:void 0},L=q,G=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=G;var H=function(t,e,r){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var K=function(t,e){return t===e||t!=t&&e!=e},X=H,Y=K,Z=Object.prototype.hasOwnProperty;var tt=function(t,e,r){var n=t[e];Z.call(t,e)&&Y(n,r)&&(void 0!==r||e in t)||X(t,e,r)},et=tt,rt=H;var nt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?rt(r,u,s):et(r,u,s)}return r};var ot=function(t){return t};var at=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},it=Math.max;var ut=function(t,e,r){return e=it(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=it(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),at(t,this,u)}};var st=function(t){return function(){return t}},ct=G,ft=ct?function(t,e){return ct(t,"toString",{configurable:!0,enumerable:!1,value:st(e),writable:!0})}:ot,lt=Date.now;var ht=function(t){var e=0,r=0;return function(){var n=lt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ft),dt=ot,vt=ut,pt=ht;var bt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},yt=k,gt=bt;var mt=function(t){return null!=t&&gt(t.length)&&!yt(t)},_t=/^(?:0|[1-9]\d*)$/;var wt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&_t.test(t))&&t>-1&&t%1==0&&t<e},jt=K,Ot=mt,St=wt,Rt=O;var xt=function(t,e){return pt(vt(t,e,dt),t+"")},kt=function(t,e,r){if(!Rt(r))return!1;var n=typeof e;return!!("number"==n?Ot(r)&&St(e,r.length):"string"==n&&e in r)&&jt(r[e],t)};var Ct=function(t){return xt(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&kt(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},At=Object.prototype;var Nt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||At)};var Et=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Mt=function(t){return null!=t&&"object"==typeof t},zt=j,Dt=Mt;var Pt=function(t){return Dt(t)&&"[object Arguments]"==zt(t)},Bt=Mt,Tt=Object.prototype,Ft=Tt.hasOwnProperty,$t=Tt.propertyIsEnumerable,It=Pt(function(){return arguments}())?Pt:function(t){return Bt(t)&&Ft.call(t,"callee")&&!$t.call(t,"callee")},Vt=Array.isArray,Qt=i(Vt),Ut={exports:{}};var Wt=function(){return!1};!function(t,e){var r=f,n=Wt,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,u=(i?i.isBuffer:void 0)||n;t.exports=u}(Ut,Ut.exports);var qt=Ut.exports,Lt=j,Gt=bt,Jt=Mt,Ht={};Ht["[object Float32Array]"]=Ht["[object Float64Array]"]=Ht["[object Int8Array]"]=Ht["[object Int16Array]"]=Ht["[object Int32Array]"]=Ht["[object Uint8Array]"]=Ht["[object Uint8ClampedArray]"]=Ht["[object Uint16Array]"]=Ht["[object Uint32Array]"]=!0,Ht["[object Arguments]"]=Ht["[object Array]"]=Ht["[object ArrayBuffer]"]=Ht["[object Boolean]"]=Ht["[object DataView]"]=Ht["[object Date]"]=Ht["[object Error]"]=Ht["[object Function]"]=Ht["[object Map]"]=Ht["[object Number]"]=Ht["[object Object]"]=Ht["[object RegExp]"]=Ht["[object Set]"]=Ht["[object String]"]=Ht["[object WeakMap]"]=!1;var Kt=function(t){return Jt(t)&&Gt(t.length)&&!!Ht[Lt(t)]};var Xt=function(t){return function(e){return t(e)}},Yt={exports:{}};!function(t,e){var r=u,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,a=o&&o.exports===n&&r.process,i=function(){try{var t=o&&o.require&&o.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=i}(Yt,Yt.exports);var Zt=Yt.exports,te=Kt,ee=Xt,re=Zt&&Zt.isTypedArray,ne=re?ee(re):te,oe=Et,ae=It,ie=Vt,ue=qt,se=wt,ce=ne,fe=Object.prototype.hasOwnProperty;var le=function(t,e){var r=ie(t),n=!r&&ae(t),o=!r&&!n&&ue(t),a=!r&&!n&&!o&&ce(t),i=r||n||o||a,u=i?oe(t.length,String):[],s=u.length;for(var c in t)!e&&!fe.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||se(c,s))||u.push(c);return u};var he=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),de=Nt,ve=he,pe=Object.prototype.hasOwnProperty;var be=le,ye=function(t){if(!de(t))return ve(t);var e=[];for(var r in Object(t))pe.call(t,r)&&"constructor"!=r&&e.push(r);return e},ge=mt;var me,_e=function(t){return ge(t)?be(t):ye(t)},we=tt,je=nt,Oe=Ct,Se=mt,Re=Nt,xe=_e,ke=Object.prototype.hasOwnProperty,Ce=i(Oe(function(t,e){if(Re(e)||Se(e))je(e,xe(e),t);else for(var r in e)ke.call(e,r)&&we(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(me||(me={}));const Ae="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class Ne{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Ce({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Ce({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ee=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Me=Ee,ze=function(t){return t!=t},De=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Pe=function(t,e,r){return e==e?De(t,e,r):Me(t,ze,r)},Be=j,Te=Vt,Fe=Mt;var $e=function(t){return"string"==typeof t||!Te(t)&&Fe(t)&&"[object String]"==Be(t)},Ie=/\s/;var Ve=function(t){for(var e=t.length;e--&&Ie.test(t.charAt(e)););return e},Qe=/^\s+/;var Ue=j,We=Mt;var qe=function(t){return"symbol"==typeof t||We(t)&&"[object Symbol]"==Ue(t)},Le=function(t){return t?t.slice(0,Ve(t)+1).replace(Qe,""):t},Ge=O,Je=qe,He=/^[-+]0x[0-9a-f]+$/i,Ke=/^0b[01]+$/i,Xe=/^0o[0-7]+$/i,Ye=parseInt;var Ze=function(t){if("number"==typeof t)return t;if(Je(t))return NaN;if(Ge(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Ge(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Le(t);var r=Ke.test(t);return r||Xe.test(t)?Ye(t.slice(2),r?2:8):He.test(t)?NaN:+t},tr=1/0;var er=function(t){return t?(t=Ze(t))===tr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var rr=function(t){var e=er(t),r=e%1;return e==e?r?e-r:e:0};var nr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},or=nr;var ar=function(t,e){return or(e,function(e){return t[e]})},ir=_e;var ur=function(t){return null==t?[]:ar(t,ir(t))},sr=i(ur),cr=Pe,fr=mt,lr=$e,hr=rr,dr=ur,vr=Math.max;var pr=i(function(t,e,r,n){t=fr(t)?t:dr(t),r=r&&!n?hr(r):0;var o=t.length;return r<0&&(r=vr(o+r,0)),lr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&cr(t,e,r)>-1});const br={info:()=>{},error:()=>{},warn:()=>{}};function yr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:pr(t,"error"),warn:pr(t,"warn"),info:pr(t,"info")}}(t);e&&(br.info=console.log),r&&(br.error=console.error),n&&(br.warn=console.warn)}var gr=Vt,mr=qe,_r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wr=/^\w*$/;var jr=function(t,e){if(gr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!mr(t))||(wr.test(t)||!_r.test(t)||null!=e&&t in Object(e))},Or=q(Object,"create"),Sr=Or;var Rr=function(){this.__data__=Sr?Sr(null):{},this.size=0};var xr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},kr=Or,Cr=Object.prototype.hasOwnProperty;var Ar=function(t){var e=this.__data__;if(kr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Cr.call(e,t)?e[t]:void 0},Nr=Or,Er=Object.prototype.hasOwnProperty;var Mr=Or;var zr=Rr,Dr=xr,Pr=Ar,Br=function(t){var e=this.__data__;return Nr?void 0!==e[t]:Er.call(e,t)},Tr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Mr&&void 0===e?"__lodash_hash_undefined__":e,this};function Fr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Fr.prototype.clear=zr,Fr.prototype.delete=Dr,Fr.prototype.get=Pr,Fr.prototype.has=Br,Fr.prototype.set=Tr;var $r=Fr;var Ir=function(){this.__data__=[],this.size=0},Vr=K;var Qr=function(t,e){for(var r=t.length;r--;)if(Vr(t[r][0],e))return r;return-1},Ur=Qr,Wr=Array.prototype.splice;var qr=Qr;var Lr=Qr;var Gr=Qr;var Jr=Ir,Hr=function(t){var e=this.__data__,r=Ur(e,t);return!(r<0)&&(r==e.length-1?e.pop():Wr.call(e,r,1),--this.size,!0)},Kr=function(t){var e=this.__data__,r=qr(e,t);return r<0?void 0:e[r][1]},Xr=function(t){return Lr(this.__data__,t)>-1},Yr=function(t,e){var r=this.__data__,n=Gr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Zr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Zr.prototype.clear=Jr,Zr.prototype.delete=Hr,Zr.prototype.get=Kr,Zr.prototype.has=Xr,Zr.prototype.set=Yr;var tn=Zr,en=q(f,"Map"),rn=$r,nn=tn,on=en;var an=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var un=function(t,e){var r=t.__data__;return an(e)?r["string"==typeof e?"string":"hash"]:r.map},sn=un;var cn=un;var fn=un;var ln=un;var hn=function(){this.size=0,this.__data__={hash:new rn,map:new(on||nn),string:new rn}},dn=function(t){var e=sn(this,t).delete(t);return this.size-=e?1:0,e},vn=function(t){return cn(this,t).get(t)},pn=function(t){return fn(this,t).has(t)},bn=function(t,e){var r=ln(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function yn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}yn.prototype.clear=hn,yn.prototype.delete=dn,yn.prototype.get=vn,yn.prototype.has=pn,yn.prototype.set=bn;var gn=yn,mn=gn;function _n(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(_n.Cache||mn),r}_n.Cache=mn;var wn=_n;var jn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,On=/\\(\\)?/g,Sn=function(t){var e=wn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(jn,function(t,r,n,o){e.push(n?o.replace(On,"$1"):r||t)}),e}),Rn=nr,xn=Vt,kn=qe,Cn=l?l.prototype:void 0,An=Cn?Cn.toString:void 0;var Nn=function t(e){if("string"==typeof e)return e;if(xn(e))return Rn(e,t)+"";if(kn(e))return An?An.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},En=Nn;var Mn=Vt,zn=jr,Dn=Sn,Pn=function(t){return null==t?"":En(t)};var Bn=function(t,e){return Mn(t)?t:zn(t,e)?[t]:Dn(Pn(t))},Tn=qe;var Fn=function(t){if("string"==typeof t||Tn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},$n=Bn,In=Fn;var Vn=function(t,e){for(var r=0,n=(e=$n(e,t)).length;null!=t&&r<n;)t=t[In(e[r++])];return r&&r==n?t:void 0},Qn=Vn;var Un,Wn,qn=function(t,e,r){var n=null==t?void 0:Qn(t,e);return void 0===n?r:n},Ln=i(qn);function Gn(t,e,r){return Math.max(r,Math.min(t,e))}function Jn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Hn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Gn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}(Un||(Un={}));class Kn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Jn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{br.error("[ERROR]: pause speech fail"),br.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{br.error("[ERROR]: resume speech fail"),br.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Xn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(e,r){this.stream=e,this.audioContext=r,this.pcmSub=new t}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(Wn||(Wn={}));class Yn{_state;stateSub;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get state(){return this._state}set state(t){t!==this._state&&(this._state=t,this.stateSub.next(t))}get stateObs(){return this.stateSub.asObservable()}constructor(){this.stateSub=new t,this.pcmSub=new t,this.destory=new t,this.state=Wn.padding}async init(t){if(this.destory.closed)throw new Error(me["實例已摧毀"]);const r=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===r)throw this.state=Wn.rejected,new Error(me["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw br.error(t),this.state=Wn.loadfail,new Error(me["Worklet模組載入失敗"])}this.state=Wn.allowed,this.audioManager=new Kn(this.audioCtx),this.vadManager=new Xn(r,this.audioCtx),this.vadManager.pcm.pipe(e(this.destory)).subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=Ln(t,"buffer",void 0),r=Ln(t,"float32",void 0),n=Ln(t,"int16",void 0),o=Ln(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx.close(),this.destory.next(),this.destory.complete()}}var Zn=tn;var to=tn,eo=en,ro=gn;var no=tn,oo=function(){this.__data__=new Zn,this.size=0},ao=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},io=function(t){return this.__data__.get(t)},uo=function(t){return this.__data__.has(t)},so=function(t,e){var r=this.__data__;if(r instanceof to){var n=r.__data__;if(!eo||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new ro(n)}return r.set(t,e),this.size=r.size,this};function co(t){var e=this.__data__=new no(t);this.size=e.size}co.prototype.clear=oo,co.prototype.delete=ao,co.prototype.get=io,co.prototype.has=uo,co.prototype.set=so;var fo=co;var lo=gn,ho=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vo=function(t){return this.__data__.has(t)};function po(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new lo;++e<r;)this.add(t[e])}po.prototype.add=po.prototype.push=ho,po.prototype.has=vo;var bo=po,yo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},go=function(t,e){return t.has(e)};var mo=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),f=a.get(e);if(c&&f)return c==e&&f==t;var l=-1,h=!0,d=2&r?new bo:void 0;for(a.set(t,e),a.set(e,t);++l<u;){var v=t[l],p=e[l];if(n)var b=i?n(p,v,l,e,t,a):n(v,p,l,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!yo(e,function(t,e){if(!go(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var _o=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var wo=f.Uint8Array,jo=K,Oo=mo,So=_o,Ro=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},xo=l?l.prototype:void 0,ko=xo?xo.valueOf:void 0;var Co=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new wo(t),new wo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return jo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=So;case"[object Set]":var s=1&n;if(u||(u=Ro),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var f=Oo(u(t),u(e),n,o,a,i);return i.delete(t),f;case"[object Symbol]":if(ko)return ko.call(t)==ko.call(e)}return!1};var Ao=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},No=Ao,Eo=Vt;var Mo=function(t,e,r){var n=e(t);return Eo(t)?n:No(n,r(t))};var zo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Do=function(){return[]},Po=Object.prototype.propertyIsEnumerable,Bo=Object.getOwnPropertySymbols,To=Mo,Fo=Bo?function(t){return null==t?[]:(t=Object(t),zo(Bo(t),function(e){return Po.call(t,e)}))}:Do,$o=_e;var Io=function(t){return To(t,$o,Fo)},Vo=Object.prototype.hasOwnProperty;var Qo=function(t,e,r,n,o,a){var i=1&r,u=Io(t),s=u.length;if(s!=Io(e).length&&!i)return!1;for(var c=s;c--;){var f=u[c];if(!(i?f in e:Vo.call(e,f)))return!1}var l=a.get(t),h=a.get(e);if(l&&h)return l==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[f=u[c]],b=e[f];if(n)var y=i?n(b,p,f,e,t,a):n(p,b,f,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==f)}if(d&&!v){var g=t.constructor,m=e.constructor;g==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof m&&m instanceof m||(d=!1)}return a.delete(t),a.delete(e),d},Uo=q(f,"DataView"),Wo=en,qo=q(f,"Promise"),Lo=q(f,"Set"),Go=q(f,"WeakMap"),Jo=j,Ho=M,Ko="[object Map]",Xo="[object Promise]",Yo="[object Set]",Zo="[object WeakMap]",ta="[object DataView]",ea=Ho(Uo),ra=Ho(Wo),na=Ho(qo),oa=Ho(Lo),aa=Ho(Go),ia=Jo;(Uo&&ia(new Uo(new ArrayBuffer(1)))!=ta||Wo&&ia(new Wo)!=Ko||qo&&ia(qo.resolve())!=Xo||Lo&&ia(new Lo)!=Yo||Go&&ia(new Go)!=Zo)&&(ia=function(t){var e=Jo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ho(r):"";if(n)switch(n){case ea:return ta;case ra:return Ko;case na:return Xo;case oa:return Yo;case aa:return Zo}return e});var ua=fo,sa=mo,ca=Co,fa=Qo,la=ia,ha=Vt,da=qt,va=ne,pa="[object Arguments]",ba="[object Array]",ya="[object Object]",ga=Object.prototype.hasOwnProperty;var ma=function(t,e,r,n,o,a){var i=ha(t),u=ha(e),s=i?ba:la(t),c=u?ba:la(e),f=(s=s==pa?ya:s)==ya,l=(c=c==pa?ya:c)==ya,h=s==c;if(h&&da(t)){if(!da(e))return!1;i=!0,f=!1}if(h&&!f)return a||(a=new ua),i||va(t)?sa(t,e,r,n,o,a):ca(t,e,s,r,n,o,a);if(!(1&r)){var d=f&&ga.call(t,"__wrapped__"),v=l&&ga.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new ua),o(p,b,r,n,a)}}return!!h&&(a||(a=new ua),fa(t,e,r,n,o,a))},_a=Mt;var wa=function t(e,r,n,o,a){return e===r||(null==e||null==r||!_a(e)&&!_a(r)?e!=e&&r!=r:ma(e,r,n,o,t,a))},ja=fo,Oa=wa;var Sa=O;var Ra=function(t){return t==t&&!Sa(t)},xa=Ra,ka=_e;var Ca=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Aa=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],f=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var l=new ja;if(n)var h=n(c,f,s,t,e,l);if(!(void 0===h?Oa(f,c,3,n,l):h))return!1}}return!0},Na=function(t){for(var e=ka(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xa(o)]}return e},Ea=Ca;var Ma=Bn,za=It,Da=Vt,Pa=wt,Ba=bt,Ta=Fn;var Fa=function(t,e){return null!=t&&e in Object(t)},$a=function(t,e,r){for(var n=-1,o=(e=Ma(e,t)).length,a=!1;++n<o;){var i=Ta(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&Ba(o)&&Pa(i,o)&&(Da(t)||za(t))};var Ia=wa,Va=qn,Qa=function(t,e){return null!=t&&$a(t,e,Fa)},Ua=jr,Wa=Ra,qa=Ca,La=Fn;var Ga=Vn;var Ja=function(t){return function(e){return null==e?void 0:e[t]}},Ha=function(t){return function(e){return Ga(e,t)}},Ka=jr,Xa=Fn;var Ya=function(t){var e=Na(t);return 1==e.length&&e[0][2]?Ea(e[0][0],e[0][1]):function(r){return r===t||Aa(r,t,e)}},Za=function(t,e){return Ua(t)&&Wa(e)?qa(La(t),e):function(r){var n=Va(r,t);return void 0===n&&n===e?Qa(r,t):Ia(e,n,3)}},ti=ot,ei=Vt,ri=function(t){return Ka(t)?Ja(Xa(t)):Ha(t)};var ni=function(t){return"function"==typeof t?t:null==t?ti:"object"==typeof t?ei(t)?Za(t[0],t[1]):Ya(t):ri(t)};var oi=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ai=_e;var ii=mt;var ui=function(t,e){return function(r,n){if(null==r)return r;if(!ii(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&oi(t,e,ai)}),si=mt;var ci=nr,fi=ni,li=function(t,e){var r=-1,n=si(t)?Array(t.length):[];return ui(t,function(t,o,a){n[++r]=e(t,o,a)}),n},hi=Vt;var di=i(function(t,e){return(hi(t)?ci:li)(t,fi(e))}),vi=ni,pi=mt,bi=_e;var yi=function(t){return function(e,r,n){var o=Object(e);if(!pi(e)){var a=vi(r);e=bi(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},gi=Ee,mi=ni,_i=rr,wi=Math.max;var ji,Oi=i(yi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:_i(r);return o<0&&(o=wi(n+o,0)),gi(t,mi(e),o)}));class Si{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(e){this.destorySub=new t,this.messageSub=new t;const{specific:r,id:n}=e.project;this.socket=o(e.ws_url,Ce({autoConnect:!1},r&&void 0!==n?{query:{uuid:n}}:{}))}start(){const t="list",o="cloud",a="channel";r(this.socket,t).pipe(n(1),e(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),r(this.socket,o).pipe(e(this.destorySub)).subscribe(t=>{this.messageSub.next({event:o,data:t})}),r(this.socket,a).pipe(e(this.destorySub)).subscribe(t=>{this.messageSub.next({event:a,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(ji||(ji={}));class Ri{config;media;chat;destorySub;projectsSub;layoutSub;cloudSampleRate;get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(e,r){this.config=e,this.media=r,this.layoutSub=new t,this.projectsSub=new t,this.destorySub=new t,this.cloudSampleRate=16e3,this.chat=new Si(e)}start(){this.chat.message.pipe(e(this.destorySub)).subscribe(({event:t,data:r})=>{switch(t){case"cloud":this.cloudToObj(r);break;case"list":{const{id:t,name:e,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=Oi(r,r=>r.name===e||r.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):this.projectsSub.next(r);break}case"channel":this.media.state===Wn.allowed?this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}):this.media.state===Wn.padding&&this.media.stateObs.pipe(e(this.destorySub)).subscribe(t=>{t===Wn.allowed&&this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate})})}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==Ln(e,"signal")?this.behavior(e):Qt(e)?di(e,this.behavior):di(sr(e),this.behavior)}catch(t){br.error("aiia websocket","onmessage error",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate=t.content;else if(this.media.state===Wn.allowed)switch(t.command){case"pcm":{const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Jn(new Int16Array(t.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===t.content&&this.media.state===Wn.allowed?(this.media.pcm.pipe(e(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Hn(t)})}),this.media.startRecord()):br.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.");break;default:br.info(t.signal)}}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}function xi(t){if(Ae){const e=new Ne(Ce({},t));yr(e.debug);const r=new Yn,n=new Ri(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(me["環境錯誤(browser)"])}export{Yn as MediaManager,xi as initSdk};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphen.ai/aiia-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "Jay Huang",
@@ -41,8 +41,7 @@
41
41
  "watch": "rollup -c -w",
42
42
  "types:extract": "npm run types:extract:browser && npm run types:extract:node && npm run clean:type",
43
43
  "types:extract:browser": "api-extractor run --local --config api-extractor.browser.json",
44
- "types:extract:node": "api-extractor run --local --config api-extractor.node.json",
45
- "publish": "npm run build && npm publish --access public"
44
+ "types:extract:node": "api-extractor run --local --config api-extractor.node.json"
46
45
  },
47
46
  "devDependencies": {
48
47
  "@microsoft/api-extractor": "^7.52.11",