@graphen.ai/aiia-sdk 1.0.6 → 1.0.8

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("moment"),e=require("rxjs"),r=require("socket.io-client"),n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i="object"==typeof n&&n&&n.Object===Object&&n,a=i,u="object"==typeof self&&self&&self.Object===Object&&self,s=a||u||Function("return this")(),c=s.Symbol,l=c,h=Object.prototype,f=h.hasOwnProperty,d=h.toString,p=l?l.toStringTag:void 0;var v=function(t){var e=f.call(t,p),r=t[p];try{t[p]=void 0;var n=!0}catch(t){}var o=d.call(t);return n&&(e?t[p]=r:delete t[p]),o},b=Object.prototype.toString;var y=v,g=function(t){return b.call(t)},m=c?c.toStringTag:void 0;var S=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m in Object(t)?y(t):g(t)};var _=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},w=S,j=_;var O,x=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=s["__core-js_shared__"],k=(O=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var C=function(t){return!!k&&k in t},A=Function.prototype.toString;var E=function(t){if(null!=t){try{return A.call(t)}catch(t){}try{return t+""}catch(t){}}return""},D=x,N=C,M=_,T=E,I=/^\[object .+?Constructor\]$/,z=Function.prototype,P=Object.prototype,B=z.toString,F=P.hasOwnProperty,$=RegExp("^"+B.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var U=function(t){return!(!M(t)||N(t))&&(D(t)?$:I).test(T(t))},V=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=V(t,e);return U(r)?r:void 0},Q=q,L=function(){try{var t=Q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),W=L;var G=function(t,e,r){"__proto__"==e&&W?W(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},H=G,J=K,X=Object.prototype.hasOwnProperty;var Y=function(t,e,r){var n=t[e];X.call(t,e)&&J(n,r)&&(void 0!==r||e in t)||H(t,e,r)},Z=Y,tt=G;var et=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var u=e[i],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?tt(r,u,s):Z(r,u,s)}return r};var rt=function(t){return t};var nt=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)},ot=Math.max;var it=function(t,e,r){return e=ot(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=ot(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(a),nt(t,this,u)}};var at=function(t){return function(){return t}},ut=L,st=ut?function(t,e){return ut(t,"toString",{configurable:!0,enumerable:!1,value:at(e),writable:!0})}:rt,ct=Date.now;var lt=function(t){var e=0,r=0;return function(){var n=ct(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(st),ht=rt,ft=it,dt=lt;var pt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},vt=x,bt=pt;var yt=function(t){return null!=t&&bt(t.length)&&!vt(t)},gt=/^(?:0|[1-9]\d*)$/;var mt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&gt.test(t))&&t>-1&&t%1==0&&t<e},St=K,_t=yt,wt=mt,jt=_;var Ot=function(t,e){return dt(ft(t,e,ht),t+"")},xt=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)&&St(r[e],t)};var Rt=function(t){return Ot(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,a&&xt(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,i)}return e})},kt=Object.prototype;var Ct=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 Et=function(t){return null!=t&&"object"==typeof t},Dt=S,Nt=Et;var Mt=function(t){return Nt(t)&&"[object Arguments]"==Dt(t)},Tt=Et,It=Object.prototype,zt=It.hasOwnProperty,Pt=It.propertyIsEnumerable,Bt=Mt(function(){return arguments}())?Mt:function(t){return Tt(t)&&zt.call(t,"callee")&&!Pt.call(t,"callee")},Ft=Array.isArray,$t=o(Ft),Ut={exports:{}};var Vt=function(){return!1};!function(t,e){var r=s,n=Vt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,u=(a?a.isBuffer:void 0)||n;t.exports=u}(Ut,Ut.exports);var qt=Ut.exports,Qt=S,Lt=pt,Wt=Et,Gt={};Gt["[object Float32Array]"]=Gt["[object Float64Array]"]=Gt["[object Int8Array]"]=Gt["[object Int16Array]"]=Gt["[object Int32Array]"]=Gt["[object Uint8Array]"]=Gt["[object Uint8ClampedArray]"]=Gt["[object Uint16Array]"]=Gt["[object Uint32Array]"]=!0,Gt["[object Arguments]"]=Gt["[object Array]"]=Gt["[object ArrayBuffer]"]=Gt["[object Boolean]"]=Gt["[object DataView]"]=Gt["[object Date]"]=Gt["[object Error]"]=Gt["[object Function]"]=Gt["[object Map]"]=Gt["[object Number]"]=Gt["[object Object]"]=Gt["[object RegExp]"]=Gt["[object Set]"]=Gt["[object String]"]=Gt["[object WeakMap]"]=!1;var Kt=function(t){return Wt(t)&&Lt(t.length)&&!!Gt[Qt(t)]};var Ht=function(t){return function(e){return t(e)}},Jt={exports:{}};!function(t,e){var r=i,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,a=o&&o.exports===n&&r.process,u=function(){try{var t=o&&o.require&&o.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=u}(Jt,Jt.exports);var Xt=Jt.exports,Yt=Kt,Zt=Ht,te=Xt&&Xt.isTypedArray,ee=te?Zt(te):Yt,re=At,ne=Bt,oe=Ft,ie=qt,ae=mt,ue=ee,se=Object.prototype.hasOwnProperty;var ce=function(t,e){var r=oe(t),n=!r&&ne(t),o=!r&&!n&&ie(t),i=!r&&!n&&!o&&ue(t),a=r||n||o||i,u=a?re(t.length,String):[],s=u.length;for(var c in t)!e&&!se.call(t,c)||a&&("length"==c||o&&("offset"==c||"parent"==c)||i&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ae(c,s))||u.push(c);return u};var le=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),he=Ct,fe=le,de=Object.prototype.hasOwnProperty;var pe=ce,ve=function(t){if(!he(t))return fe(t);var e=[];for(var r in Object(t))de.call(t,r)&&"constructor"!=r&&e.push(r);return e},be=yt;var ye=function(t){return be(t)?pe(t):ve(t)},ge=Y,me=et,Se=Rt,_e=yt,we=Ct,je=ye,Oe=Object.prototype.hasOwnProperty,xe=o(Se(function(t,e){if(we(e)||_e(e))me(e,je(e),t);else for(var r in e)Oe.call(e,r)&&ge(t,r,e[r])})),Re=S,ke=Et;var Ce=function(t){return"symbol"==typeof t||ke(t)&&"[object Symbol]"==Re(t)},Ae=Ft,Ee=Ce,De=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ne=/^\w*$/;var Me=function(t,e){if(Ae(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Ee(t))||(Ne.test(t)||!De.test(t)||null!=e&&t in Object(e))},Te=q(Object,"create"),Ie=Te;var ze=function(){this.__data__=Ie?Ie(null):{},this.size=0};var Pe=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Be=Te,Fe=Object.prototype.hasOwnProperty;var $e=function(t){var e=this.__data__;if(Be){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Fe.call(e,t)?e[t]:void 0},Ue=Te,Ve=Object.prototype.hasOwnProperty;var qe=Te;var Qe=ze,Le=Pe,We=$e,Ge=function(t){var e=this.__data__;return Ue?void 0!==e[t]:Ve.call(e,t)},Ke=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=qe&&void 0===e?"__lodash_hash_undefined__":e,this};function He(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])}}He.prototype.clear=Qe,He.prototype.delete=Le,He.prototype.get=We,He.prototype.has=Ge,He.prototype.set=Ke;var Je=He;var Xe=function(){this.__data__=[],this.size=0},Ye=K;var Ze=function(t,e){for(var r=t.length;r--;)if(Ye(t[r][0],e))return r;return-1},tr=Ze,er=Array.prototype.splice;var rr=Ze;var nr=Ze;var or=Ze;var ir=Xe,ar=function(t){var e=this.__data__,r=tr(e,t);return!(r<0)&&(r==e.length-1?e.pop():er.call(e,r,1),--this.size,!0)},ur=function(t){var e=this.__data__,r=rr(e,t);return r<0?void 0:e[r][1]},sr=function(t){return nr(this.__data__,t)>-1},cr=function(t,e){var r=this.__data__,n=or(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function lr(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])}}lr.prototype.clear=ir,lr.prototype.delete=ar,lr.prototype.get=ur,lr.prototype.has=sr,lr.prototype.set=cr;var hr=lr,fr=q(s,"Map"),dr=Je,pr=hr,vr=fr;var br=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var yr=function(t,e){var r=t.__data__;return br(e)?r["string"==typeof e?"string":"hash"]:r.map},gr=yr;var mr=yr;var Sr=yr;var _r=yr;var wr=function(){this.size=0,this.__data__={hash:new dr,map:new(vr||pr),string:new dr}},jr=function(t){var e=gr(this,t).delete(t);return this.size-=e?1:0,e},Or=function(t){return mr(this,t).get(t)},xr=function(t){return Sr(this,t).has(t)},Rr=function(t,e){var r=_r(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,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=jr,kr.prototype.get=Or,kr.prototype.has=xr,kr.prototype.set=Rr;var Cr=kr,Ar=Cr;function Er(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],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Er.Cache||Ar),r}Er.Cache=Ar;var Dr=Er;var Nr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Mr=/\\(\\)?/g,Tr=function(t){var e=Dr(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(Nr,function(t,r,n,o){e.push(n?o.replace(Mr,"$1"):r||t)}),e});var Ir=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},zr=Ir,Pr=Ft,Br=Ce,Fr=c?c.prototype:void 0,$r=Fr?Fr.toString:void 0;var Ur=function t(e){if("string"==typeof e)return e;if(Pr(e))return zr(e,t)+"";if(Br(e))return $r?$r.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Vr=Ur;var qr=Ft,Qr=Me,Lr=Tr,Wr=function(t){return null==t?"":Vr(t)};var Gr=function(t,e){return qr(t)?t:Qr(t,e)?[t]:Lr(Wr(t))},Kr=Ce;var Hr=function(t){if("string"==typeof t||Kr(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Jr=Gr,Xr=Hr;var Yr=function(t,e){for(var r=0,n=(e=Jr(e,t)).length;null!=t&&r<n;)t=t[Xr(e[r++])];return r&&r==n?t:void 0},Zr=Yr;var tn,en=function(t,e,r){var n=null==t?void 0:Zr(t,e);return void 0===n?r:n},rn=o(en);!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: 2005"}(tn||(tn={}));const nn="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class on{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}=xe({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:xe({},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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}constructor(t){this.config=t}}var an=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var un=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),u=a.length;u--;){var s=a[t?u:++o];if(!1===r(i[s],s,i))break}return e}}(),sn=ye;var cn=yt;var ln=function(t,e){return function(r,n){if(null==r)return r;if(!cn(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(t,e){return t&&un(t,e,sn)}),hn=rt;var fn=an,dn=ln,pn=function(t){return"function"==typeof t?t:hn},vn=Ft;var bn,yn=o(function(t,e){return(vn(t)?fn:dn)(t,pn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(bn||(bn={}));const gn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},mn=[];const Sn=new Proxy(gn,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const o=t().format("yyyy-MM-DD[T]HH:mm:ss");yn(mn,t=>{t.next(r,o,...n)}),e[r](`[Aiia::${r}_${o}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});var _n,wn;function jn(t,e,r){return Math.max(r,Math.min(t,e))}function On(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 xn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=jn(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 Rn{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),i=t.slice();for(let t=0;t<e;t++)o.copyToChannel(i,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(On(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{Sn.error("pause speech fail",t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{Sn.error("resume speech fail",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 kn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;outputSampleRate;chunkTimeInSeconds;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(t,r,n){this.stream=t,this.audioContext=r;const{outputSampleRate:o,chunkTimeInSeconds:i}=xe({outputSampleRate:16e3,chunkTimeInSeconds:1},n);this.outputSampleRate=o,this.chunkTimeInSeconds=i,this.pcmSub=new e.Subject}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad",{processorOptions:{outputSampleRate:this.outputSampleRate,chunkTimeInSeconds:this.chunkTimeInSeconds}}),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e}=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 Cn{stream;_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(t){this.stream=t,this.stateSub=new e.Subject,this.pcmSub=new e.Subject,this.destory=new e.Subject,this.state=wn.padding}async init(t,e){const r=this.stream??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(tn["未獲得媒體裝置權限"]);this.stream=r,this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw Sn.fatal(t),this.state=wn.loadfail,new Error(tn["Worklet模組載入失敗"])}this.state=wn.allowed,this.audioManager=new Rn(this.audioCtx),this.vadManager=new kn(r,this.audioCtx,e),this.vadManager.pcm.subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=rn(t,"buffer",void 0),r=rn(t,"float32",void 0),n=rn(t,"int16",void 0),o=rn(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 An=hr;var En=hr,Dn=fr,Nn=Cr;var Mn=hr,Tn=function(){this.__data__=new An,this.size=0},In=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},zn=function(t){return this.__data__.get(t)},Pn=function(t){return this.__data__.has(t)},Bn=function(t,e){var r=this.__data__;if(r instanceof En){var n=r.__data__;if(!Dn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Nn(n)}return r.set(t,e),this.size=r.size,this};function Fn(t){var e=this.__data__=new Mn(t);this.size=e.size}Fn.prototype.clear=Tn,Fn.prototype.delete=In,Fn.prototype.get=zn,Fn.prototype.has=Pn,Fn.prototype.set=Bn;var $n=Fn;var Un=Cr,Vn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},qn=function(t){return this.__data__.has(t)};function Qn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Un;++e<r;)this.add(t[e])}Qn.prototype.add=Qn.prototype.push=Vn,Qn.prototype.has=qn;var Ln=Qn,Wn=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},Gn=function(t,e){return t.has(e)};var Kn=function(t,e,r,n,o,i){var a=1&r,u=t.length,s=e.length;if(u!=s&&!(a&&s>u))return!1;var c=i.get(t),l=i.get(e);if(c&&l)return c==e&&l==t;var h=-1,f=!0,d=2&r?new Ln:void 0;for(i.set(t,e),i.set(e,t);++h<u;){var p=t[h],v=e[h];if(n)var b=a?n(v,p,h,e,t,i):n(p,v,h,t,e,i);if(void 0!==b){if(b)continue;f=!1;break}if(d){if(!Wn(e,function(t,e){if(!Gn(d,e)&&(p===t||o(p,t,r,n,i)))return d.push(e)})){f=!1;break}}else if(p!==v&&!o(p,v,r,n,i)){f=!1;break}}return i.delete(t),i.delete(e),f};var Hn=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var Jn=s.Uint8Array,Xn=K,Yn=Kn,Zn=Hn,to=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},eo=c?c.prototype:void 0,ro=eo?eo.valueOf:void 0;var no=function(t,e,r,n,o,i,a){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||!i(new Jn(t),new Jn(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Xn(+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=Zn;case"[object Set]":var s=1&n;if(u||(u=to),t.size!=e.size&&!s)return!1;var c=a.get(t);if(c)return c==e;n|=2,a.set(t,e);var l=Yn(u(t),u(e),n,o,i,a);return a.delete(t),l;case"[object Symbol]":if(ro)return ro.call(t)==ro.call(e)}return!1};var oo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},io=oo,ao=Ft;var uo=function(t,e,r){var n=e(t);return ao(t)?n:io(n,r(t))};var so=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i},co=function(){return[]},lo=Object.prototype.propertyIsEnumerable,ho=Object.getOwnPropertySymbols,fo=uo,po=ho?function(t){return null==t?[]:(t=Object(t),so(ho(t),function(e){return lo.call(t,e)}))}:co,vo=ye;var bo=function(t){return fo(t,vo,po)},yo=Object.prototype.hasOwnProperty;var go=function(t,e,r,n,o,i){var a=1&r,u=bo(t),s=u.length;if(s!=bo(e).length&&!a)return!1;for(var c=s;c--;){var l=u[c];if(!(a?l in e:yo.call(e,l)))return!1}var h=i.get(t),f=i.get(e);if(h&&f)return h==e&&f==t;var d=!0;i.set(t,e),i.set(e,t);for(var p=a;++c<s;){var v=t[l=u[c]],b=e[l];if(n)var y=a?n(b,v,l,e,t,i):n(v,b,l,t,e,i);if(!(void 0===y?v===b||o(v,b,r,n,i):y)){d=!1;break}p||(p="constructor"==l)}if(d&&!p){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 i.delete(t),i.delete(e),d},mo=q(s,"DataView"),So=fr,_o=q(s,"Promise"),wo=q(s,"Set"),jo=q(s,"WeakMap"),Oo=S,xo=E,Ro="[object Map]",ko="[object Promise]",Co="[object Set]",Ao="[object WeakMap]",Eo="[object DataView]",Do=xo(mo),No=xo(So),Mo=xo(_o),To=xo(wo),Io=xo(jo),zo=Oo;(mo&&zo(new mo(new ArrayBuffer(1)))!=Eo||So&&zo(new So)!=Ro||_o&&zo(_o.resolve())!=ko||wo&&zo(new wo)!=Co||jo&&zo(new jo)!=Ao)&&(zo=function(t){var e=Oo(t),r="[object Object]"==e?t.constructor:void 0,n=r?xo(r):"";if(n)switch(n){case Do:return Eo;case No:return Ro;case Mo:return ko;case To:return Co;case Io:return Ao}return e});var Po=$n,Bo=Kn,Fo=no,$o=go,Uo=zo,Vo=Ft,qo=qt,Qo=ee,Lo="[object Arguments]",Wo="[object Array]",Go="[object Object]",Ko=Object.prototype.hasOwnProperty;var Ho=function(t,e,r,n,o,i){var a=Vo(t),u=Vo(e),s=a?Wo:Uo(t),c=u?Wo:Uo(e),l=(s=s==Lo?Go:s)==Go,h=(c=c==Lo?Go:c)==Go,f=s==c;if(f&&qo(t)){if(!qo(e))return!1;a=!0,l=!1}if(f&&!l)return i||(i=new Po),a||Qo(t)?Bo(t,e,r,n,o,i):Fo(t,e,s,r,n,o,i);if(!(1&r)){var d=l&&Ko.call(t,"__wrapped__"),p=h&&Ko.call(e,"__wrapped__");if(d||p){var v=d?t.value():t,b=p?e.value():e;return i||(i=new Po),o(v,b,r,n,i)}}return!!f&&(i||(i=new Po),$o(t,e,r,n,o,i))},Jo=Et;var Xo=function t(e,r,n,o,i){return e===r||(null==e||null==r||!Jo(e)&&!Jo(r)?e!=e&&r!=r:Ho(e,r,n,o,t,i))},Yo=$n,Zo=Xo;var ti=_;var ei=function(t){return t==t&&!ti(t)},ri=ei,ni=ye;var oi=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},ii=function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var u=r[o];if(a&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<i;){var s=(u=r[o])[0],c=t[s],l=u[1];if(a&&u[2]){if(void 0===c&&!(s in t))return!1}else{var h=new Yo;if(n)var f=n(c,l,s,t,e,h);if(!(void 0===f?Zo(l,c,3,n,h):f))return!1}}return!0},ai=function(t){for(var e=ni(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,ri(o)]}return e},ui=oi;var si=Gr,ci=Bt,li=Ft,hi=mt,fi=pt,di=Hr;var pi=function(t,e){return null!=t&&e in Object(t)},vi=function(t,e,r){for(var n=-1,o=(e=si(e,t)).length,i=!1;++n<o;){var a=di(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&fi(o)&&hi(a,o)&&(li(t)||ci(t))};var bi=Xo,yi=en,gi=function(t,e){return null!=t&&vi(t,e,pi)},mi=Me,Si=ei,_i=oi,wi=Hr;var ji=Yr;var Oi=function(t){return function(e){return null==e?void 0:e[t]}},xi=function(t){return function(e){return ji(e,t)}},Ri=Me,ki=Hr;var Ci=function(t){var e=ai(t);return 1==e.length&&e[0][2]?ui(e[0][0],e[0][1]):function(r){return r===t||ii(r,t,e)}},Ai=function(t,e){return mi(t)&&Si(e)?_i(wi(t),e):function(r){var n=yi(r,t);return void 0===n&&n===e?gi(r,t):bi(e,n,3)}},Ei=rt,Di=Ft,Ni=function(t){return Ri(t)?Oi(ki(t)):xi(t)};var Mi=function(t){return"function"==typeof t?t:null==t?Ei:"object"==typeof t?Di(t)?Ai(t[0],t[1]):Ci(t):Ni(t)},Ti=ln,Ii=yt;var zi=Ir,Pi=Mi,Bi=function(t,e){var r=-1,n=Ii(t)?Array(t.length):[];return Ti(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Fi=Ft;var $i=o(function(t,e){return(Fi(t)?zi:Bi)(t,Pi(e))}),Ui=Mi,Vi=yt,qi=ye;var Qi=function(t){return function(e,r,n){var o=Object(e);if(!Vi(e)){var i=Ui(r);e=qi(e),r=function(t){return i(o[t],t,o)}}var a=t(e,r,n);return a>-1?o[i?e[a]:a]:void 0}};var Li=/\s/;var Wi=function(t){for(var e=t.length;e--&&Li.test(t.charAt(e)););return e},Gi=/^\s+/;var Ki=function(t){return t?t.slice(0,Wi(t)+1).replace(Gi,""):t},Hi=_,Ji=Ce,Xi=/^[-+]0x[0-9a-f]+$/i,Yi=/^0b[01]+$/i,Zi=/^0o[0-7]+$/i,ta=parseInt;var ea=function(t){if("number"==typeof t)return t;if(Ji(t))return NaN;if(Hi(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Hi(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Ki(t);var r=Yi.test(t);return r||Zi.test(t)?ta(t.slice(2),r?2:8):Xi.test(t)?NaN:+t},ra=1/0;var na=function(t){return t?(t=ea(t))===ra||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var oa=function(t,e,r,n){for(var o=t.length,i=r+(n?1:-1);n?i--:++i<o;)if(e(t[i],i,t))return i;return-1},ia=Mi,aa=function(t){var e=na(t),r=e%1;return e==e?r?e-r:e:0},ua=Math.max;var sa=o(Qi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:aa(r);return o<0&&(o=ua(n+o,0)),oa(t,ia(e),o)})),ca=Ir;var la=function(t,e){return ca(e,function(e){return t[e]})},ha=ye;var fa=o(function(t){return null==t?[]:la(t,ha(t))});class da{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(t){this.destorySub=new e.Subject,this.messageSub=new e.Subject;const{specific:n,id:o}=t.project;this.socket=r.io(t.ws_url,xe({autoConnect:!1},n&&void 0!==o?{query:{uuid:o}}:{}))}start(){const t="list",r="cloud",n="channel";e.fromEvent(this.socket,t).pipe(e.take(1),e.takeUntil(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),e.fromEvent(this.socket,r).pipe(e.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),e.fromEvent(this.socket,n).pipe(e.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()}}class pa{config;media;chat;destorySub;projectsSub;layoutSub;aiiaSubtitleSub;userSubtitleSub;cloudSampleRate;channelState;stateSub;isMuteAiia;get state(){return this.stateSub.asObservable()}get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}get aiiaSubtitle(){return this.aiiaSubtitleSub.asObservable()}get userSubtitle(){return this.userSubtitleSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(t,r){this.config=t,this.media=r,this.layoutSub=new e.Subject,this.projectsSub=new e.ReplaySubject(1),this.destorySub=new e.Subject,this.aiiaSubtitleSub=new e.Subject,this.userSubtitleSub=new e.Subject,this.stateSub=new e.ReplaySubject(1),this.cloudSampleRate={input:16e3,output:16e3},this.channelState={proxy:!1,cloud:!1},this.isMuteAiia=!1,this.chat=new da(t),Sn.code(bn["指定依賴已完成"],"chat"),this.close=this.onDestory,this.stateSub.next("NotStart")}start(){this.media.stateObs.pipe(e.takeUntil(this.destorySub)).subscribe(()=>{this.channelCheck()}),this.chat.message.pipe(e.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=sa(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):(this.projectsSub.next(e),Sn.code(bn["請訂閱專案列表"]));break}case"channel":switch(e){case"open":this.channelState.proxy=!0,this.channelCheck();break;case"close":this.channelState.proxy=!1,this.media.stopRecord(),this.stateSub.next("CloseService");break;case"no_permissions":this.channelState.proxy=!1,this.stateSub.next("NoPermissions");break;case"reconnect":this.channelState.proxy=!1,this.stateSub.next("ReconnectingCloud")}}}),this.chat.start(),this.stateSub.next("ConnectingCloud"),Sn.code(bn["啟動SDK"])}close;resetSession(){this.chat.sendToCloud({request:"reset"}),this.aiiaSubtitleSub.next(""),this.userSubtitleSub.next(""),this.media.stopAudio(),this.layoutSub.next({type:"resetLayout"})}chooseProject(t){this.chat.send("uuid",t)}mute(){this.isMuteAiia=!0,this.media.stopAudio(),this.media.stopRecord()}unmute(){this.isMuteAiia=!1,this.media.startRecord()}cloudToObj(t){try{const e=JSON.parse(t);void 0!==rn(e,"signal")?this.behavior(e):$t(e)?$i(e,this.behavior):$i(fa(e),this.behavior)}catch(t){Sn.error("message transfer fail",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate.output=t.content;else switch(t.command){case"pcm":if(!this.isMuteAiia){const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),i=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),a=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];i[e]=u+(s-u)*a}return i}(On(new Int16Array(t.content)),this.cloudSampleRate.output,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio()}break;case"interrupted":this.media.stopAudio(),this.aiiaSubtitleSub.next("")}break;case"status":"Connected"===rn(t,"content")&&(this.channelState.cloud=!0,this.channelCheck(),this.layoutSub.next({type:"resetLayout"}));break;case"agent":if(!this.isMuteAiia){const e=rn(t,"content.function_result.response");e&&this.aiiaSubtitleSub.next(e)}break;case"asr":if(!this.isMuteAiia&&"ASR"===rn(t,"content.function_type")){const e=rn(t,"content.function_result.result");e&&this.userSubtitleSub.next(e)}break;default:Sn.debug(t.signal)}}channelCheck(){const{proxy:t,cloud:r}=this.channelState;t&&r&&this.media.state===wn.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.cloudSampleRate.input}),this.media.pcm.pipe(e.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:xn(t)})}),this.media.startRecord(),this.stateSub.next("InService"),Sn.code(bn["通道、雲端服務、麥克風都已就緒"])):t&&r&&this.media.state!==wn.allowed&&(this.stateSub.next("InServiceNoMedia"),Sn.code(bn["未取得媒體裝置權限,請重新設定或忽略此訊息"]))}onDestory(){this.chat.onDestory(),this.media.onDestory(),this.destorySub.next(),this.destorySub.complete(),this.stateSub.next("Destory"),this.stateSub.complete(),Sn.code(bn["結束SDK"])}}exports.initSdk=function(t){if(nn){!function(t){const{info:e,error:r,warn:n,debug:o,fatal:i,code:a}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);a||(gn.code=()=>{}),o||(gn.debug=()=>{}),e||(gn.info=()=>{}),n||(gn.warn=()=>{}),r||(gn.error=()=>{}),i||(gn.fatal=()=>{})}(rn(t,"debug",!0)),Sn.code(bn["初始化必要依賴"]);const e=new on(xe({},t));Sn.code(bn["指定依賴已完成"],"config");const r=new Cn(e.mediaStream);Sn.code(bn["指定依賴已完成"],"config");const n=new pa(e,r);return Sn.code(bn["指定依賴已完成"],"sdk"),""!==e.worklet_url&&r.init(e.worklet_url,{chunkTimeInSeconds:e.chunkTimeInSeconds,outputSampleRate:e.llmSampleRate}),n}throw new Error(tn["環境錯誤(browser)"])};
1
+ "use strict";var t=require("moment"),e=require("rxjs"),r=require("@mediapipe/tasks-vision"),n=require("socket.io-client"),i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var o="object"==typeof i&&i&&i.Object===Object&&i,s=o,u="object"==typeof self&&self&&self.Object===Object&&self,c=s||u||Function("return this")(),l=c.Symbol,h=l,d=Object.prototype,f=d.hasOwnProperty,p=d.toString,b=h?h.toStringTag:void 0;var v=function(t){var e=f.call(t,b),r=t[b];try{t[b]=void 0;var n=!0}catch(t){}var i=p.call(t);return n&&(e?t[b]=r:delete t[b]),i},g=Object.prototype.toString;var y=v,m=function(t){return g.call(t)},_=l?l.toStringTag:void 0;var S=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":_&&_ in Object(t)?y(t):m(t)};var w=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},j=S,O=w;var C,x=function(t){if(!O(t))return!1;var e=j(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},E=c["__core-js_shared__"],k=(C=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+C:"";var R=function(t){return!!k&&k in t},D=Function.prototype.toString;var A=function(t){if(null!=t){try{return D.call(t)}catch(t){}try{return t+""}catch(t){}}return""},N=x,M=R,T=w,I=A,z=/^\[object .+?Constructor\]$/,F=Function.prototype,P=Object.prototype,B=F.toString,W=P.hasOwnProperty,U=RegExp("^"+B.call(W).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var $=function(t){return!(!T(t)||M(t))&&(N(t)?U:z).test(I(t))},V=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=V(t,e);return $(r)?r:void 0},L=q,Q=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),G=Q;var K=function(t,e,r){"__proto__"==e&&G?G(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var H=function(t,e){return t===e||t!=t&&e!=e},J=K,X=H,Y=Object.prototype.hasOwnProperty;var Z=function(t,e,r){var n=t[e];Y.call(t,e)&&X(n,r)&&(void 0!==r||e in t)||J(t,e,r)},tt=Z,et=K;var rt=function(t,e,r,n){var i=!r;r||(r={});for(var a=-1,o=e.length;++a<o;){var s=e[a],u=n?n(r[s],t[s],s,r,t):void 0;void 0===u&&(u=t[s]),i?et(r,s,u):tt(r,s,u)}return r};var nt=function(t){return t};var it=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)},at=Math.max;var ot=function(t,e,r){return e=at(void 0===e?t.length-1:e,0),function(){for(var n=arguments,i=-1,a=at(n.length-e,0),o=Array(a);++i<a;)o[i]=n[e+i];i=-1;for(var s=Array(e+1);++i<e;)s[i]=n[i];return s[e]=r(o),it(t,this,s)}};var st=function(t){return function(){return t}},ut=Q,ct=ut?function(t,e){return ut(t,"toString",{configurable:!0,enumerable:!1,value:st(e),writable:!0})}:nt,lt=Date.now;var ht=function(t){var e=0,r=0;return function(){var n=lt(),i=16-(n-r);if(r=n,i>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ct),dt=nt,ft=ot,pt=ht;var bt=function(t,e){return pt(ft(t,e,dt),t+"")};var vt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},gt=x,yt=vt;var mt=function(t){return null!=t&&yt(t.length)&&!gt(t)},_t=/^(?:0|[1-9]\d*)$/;var St=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},wt=H,jt=mt,Ot=St,Ct=w;var xt=function(t,e,r){if(!Ct(r))return!1;var n=typeof e;return!!("number"==n?jt(r)&&Ot(e,r.length):"string"==n&&e in r)&&wt(r[e],t)},Et=bt,kt=xt;var Rt=function(t){return Et(function(e,r){var n=-1,i=r.length,a=i>1?r[i-1]:void 0,o=i>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(i--,a):void 0,o&&kt(r[0],r[1],o)&&(a=i<3?void 0:a,i=1),e=Object(e);++n<i;){var s=r[n];s&&t(e,s,n,a)}return e})},Dt=Object.prototype;var At=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Dt)};var Nt=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},Tt=S,It=Mt;var zt=function(t){return It(t)&&"[object Arguments]"==Tt(t)},Ft=Mt,Pt=Object.prototype,Bt=Pt.hasOwnProperty,Wt=Pt.propertyIsEnumerable,Ut=zt(function(){return arguments}())?zt:function(t){return Ft(t)&&Bt.call(t,"callee")&&!Wt.call(t,"callee")},$t=Array.isArray,Vt=a($t),qt={exports:{}};var Lt=function(){return!1};!function(t,e){var r=c,n=Lt,i=e&&!e.nodeType&&e,a=i&&t&&!t.nodeType&&t,o=a&&a.exports===i?r.Buffer:void 0,s=(o?o.isBuffer:void 0)||n;t.exports=s}(qt,qt.exports);var Qt=qt.exports,Gt=S,Kt=vt,Ht=Mt,Jt={};Jt["[object Float32Array]"]=Jt["[object Float64Array]"]=Jt["[object Int8Array]"]=Jt["[object Int16Array]"]=Jt["[object Int32Array]"]=Jt["[object Uint8Array]"]=Jt["[object Uint8ClampedArray]"]=Jt["[object Uint16Array]"]=Jt["[object Uint32Array]"]=!0,Jt["[object Arguments]"]=Jt["[object Array]"]=Jt["[object ArrayBuffer]"]=Jt["[object Boolean]"]=Jt["[object DataView]"]=Jt["[object Date]"]=Jt["[object Error]"]=Jt["[object Function]"]=Jt["[object Map]"]=Jt["[object Number]"]=Jt["[object Object]"]=Jt["[object RegExp]"]=Jt["[object Set]"]=Jt["[object String]"]=Jt["[object WeakMap]"]=!1;var Xt=function(t){return Ht(t)&&Kt(t.length)&&!!Jt[Gt(t)]};var Yt=function(t){return function(e){return t(e)}},Zt={exports:{}};!function(t,e){var r=o,n=e&&!e.nodeType&&e,i=n&&t&&!t.nodeType&&t,a=i&&i.exports===n&&r.process,s=function(){try{var t=i&&i.require&&i.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=s}(Zt,Zt.exports);var te=Zt.exports,ee=Xt,re=Yt,ne=te&&te.isTypedArray,ie=ne?re(ne):ee,ae=Nt,oe=Ut,se=$t,ue=Qt,ce=St,le=ie,he=Object.prototype.hasOwnProperty;var de=function(t,e){var r=se(t),n=!r&&oe(t),i=!r&&!n&&ue(t),a=!r&&!n&&!i&&le(t),o=r||n||i||a,s=o?ae(t.length,String):[],u=s.length;for(var c in t)!e&&!he.call(t,c)||o&&("length"==c||i&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ce(c,u))||s.push(c);return s};var fe=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),pe=At,be=fe,ve=Object.prototype.hasOwnProperty;var ge=de,ye=function(t){if(!pe(t))return be(t);var e=[];for(var r in Object(t))ve.call(t,r)&&"constructor"!=r&&e.push(r);return e},me=mt;var _e=function(t){return me(t)?ge(t):ye(t)},Se=Z,we=rt,je=Rt,Oe=mt,Ce=At,xe=_e,Ee=Object.prototype.hasOwnProperty,ke=a(je(function(t,e){if(Ce(e)||Oe(e))we(e,xe(e),t);else for(var r in e)Ee.call(e,r)&&Se(t,r,e[r])})),Re=S,De=Mt;var Ae=function(t){return"symbol"==typeof t||De(t)&&"[object Symbol]"==Re(t)},Ne=$t,Me=Ae,Te=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ie=/^\w*$/;var ze=function(t,e){if(Ne(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Me(t))||(Ie.test(t)||!Te.test(t)||null!=e&&t in Object(e))},Fe=q(Object,"create"),Pe=Fe;var Be=function(){this.__data__=Pe?Pe(null):{},this.size=0};var We=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ue=Fe,$e=Object.prototype.hasOwnProperty;var Ve=function(t){var e=this.__data__;if(Ue){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return $e.call(e,t)?e[t]:void 0},qe=Fe,Le=Object.prototype.hasOwnProperty;var Qe=Fe;var Ge=Be,Ke=We,He=Ve,Je=function(t){var e=this.__data__;return qe?void 0!==e[t]:Le.call(e,t)},Xe=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Qe&&void 0===e?"__lodash_hash_undefined__":e,this};function Ye(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])}}Ye.prototype.clear=Ge,Ye.prototype.delete=Ke,Ye.prototype.get=He,Ye.prototype.has=Je,Ye.prototype.set=Xe;var Ze=Ye;var tr=function(){this.__data__=[],this.size=0},er=H;var rr=function(t,e){for(var r=t.length;r--;)if(er(t[r][0],e))return r;return-1},nr=rr,ir=Array.prototype.splice;var ar=rr;var or=rr;var sr=rr;var ur=tr,cr=function(t){var e=this.__data__,r=nr(e,t);return!(r<0)&&(r==e.length-1?e.pop():ir.call(e,r,1),--this.size,!0)},lr=function(t){var e=this.__data__,r=ar(e,t);return r<0?void 0:e[r][1]},hr=function(t){return or(this.__data__,t)>-1},dr=function(t,e){var r=this.__data__,n=sr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=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=ur,fr.prototype.delete=cr,fr.prototype.get=lr,fr.prototype.has=hr,fr.prototype.set=dr;var pr=fr,br=q(c,"Map"),vr=Ze,gr=pr,yr=br;var mr=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var _r=function(t,e){var r=t.__data__;return mr(e)?r["string"==typeof e?"string":"hash"]:r.map},Sr=_r;var wr=_r;var jr=_r;var Or=_r;var Cr=function(){this.size=0,this.__data__={hash:new vr,map:new(yr||gr),string:new vr}},xr=function(t){var e=Sr(this,t).delete(t);return this.size-=e?1:0,e},Er=function(t){return wr(this,t).get(t)},kr=function(t){return jr(this,t).has(t)},Rr=function(t,e){var r=Or(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Dr(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])}}Dr.prototype.clear=Cr,Dr.prototype.delete=xr,Dr.prototype.get=Er,Dr.prototype.has=kr,Dr.prototype.set=Rr;var Ar=Dr,Nr=Ar;function Mr(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],a=r.cache;if(a.has(i))return a.get(i);var o=t.apply(this,n);return r.cache=a.set(i,o)||a,o};return r.cache=new(Mr.Cache||Nr),r}Mr.Cache=Nr;var Tr=Mr;var Ir=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,zr=/\\(\\)?/g,Fr=function(t){var e=Tr(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(Ir,function(t,r,n,i){e.push(n?i.replace(zr,"$1"):r||t)}),e});var Pr=function(t,e){for(var r=-1,n=null==t?0:t.length,i=Array(n);++r<n;)i[r]=e(t[r],r,t);return i},Br=Pr,Wr=$t,Ur=Ae,$r=l?l.prototype:void 0,Vr=$r?$r.toString:void 0;var qr=function t(e){if("string"==typeof e)return e;if(Wr(e))return Br(e,t)+"";if(Ur(e))return Vr?Vr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Lr=qr;var Qr=$t,Gr=ze,Kr=Fr,Hr=function(t){return null==t?"":Lr(t)};var Jr=function(t,e){return Qr(t)?t:Gr(t,e)?[t]:Kr(Hr(t))},Xr=Ae;var Yr=function(t){if("string"==typeof t||Xr(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Zr=Jr,tn=Yr;var en=function(t,e){for(var r=0,n=(e=Zr(e,t)).length;null!=t&&r<n;)t=t[tn(e[r++])];return r&&r==n?t:void 0},rn=en;var nn,an=function(t,e,r){var n=null==t?void 0:rn(t,e);return void 0===n?r:n},on=a(an);!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: 2005"}(nn||(nn={}));const sn="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class un{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}=ke({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:ke({},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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}get faceDetection(){return ke({frame:3,confidence:80},this.config.faceDetection)}get autoClearSubtitle(){const{user:t,aiia:e}=ke({},this.config.autoClearSubtitle);let r=3e3,n=3e3;return"number"==typeof t?r=t>=0?t:r:!1===t&&(r=NaN),"number"==typeof e?n=e>=0?e:n:!1===e&&(n=NaN),{userDelayTime:r,aiiaDelayTime:n}}constructor(t){this.config=t}}var cn=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var ln=function(t){return function(e,r,n){for(var i=-1,a=Object(e),o=n(e),s=o.length;s--;){var u=o[t?s:++i];if(!1===r(a[u],u,a))break}return e}}(),hn=_e;var dn=mt;var fn=function(t,e){return function(r,n){if(null==r)return r;if(!dn(r))return t(r,n);for(var i=r.length,a=e?i:-1,o=Object(r);(e?a--:++a<i)&&!1!==n(o[a],a,o););return r}}(function(t,e){return t&&ln(t,e,hn)}),pn=nt;var bn=cn,vn=fn,gn=function(t){return"function"==typeof t?t:pn},yn=$t;var mn,_n=a(function(t,e){return(yn(t)?bn:vn)(t,gn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(mn||(mn={}));const Sn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},wn=[];const jn=new Proxy(Sn,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const i=t().format("yyyy-MM-DD[T]HH:mm:ss");_n(wn,t=>{t.next(r,i,...n)}),e[r](`[Aiia::${r}_${i}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});var On=function(t,e){for(var r=-1,n=null==t?0:t.length,i=0,a=[];++r<n;){var o=t[r];e(o,r,t)&&(a[i++]=o)}return a},Cn=fn;var xn=function(t,e){var r=[];return Cn(t,function(t,n,i){e(t,n,i)&&r.push(t)}),r},En=pr;var kn=pr,Rn=br,Dn=Ar;var An=pr,Nn=function(){this.__data__=new En,this.size=0},Mn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Tn=function(t){return this.__data__.get(t)},In=function(t){return this.__data__.has(t)},zn=function(t,e){var r=this.__data__;if(r instanceof kn){var n=r.__data__;if(!Rn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Dn(n)}return r.set(t,e),this.size=r.size,this};function Fn(t){var e=this.__data__=new An(t);this.size=e.size}Fn.prototype.clear=Nn,Fn.prototype.delete=Mn,Fn.prototype.get=Tn,Fn.prototype.has=In,Fn.prototype.set=zn;var Pn=Fn;var Bn=Ar,Wn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Un=function(t){return this.__data__.has(t)};function $n(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Bn;++e<r;)this.add(t[e])}$n.prototype.add=$n.prototype.push=Wn,$n.prototype.has=Un;var Vn=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};var qn=$n,Ln=Vn,Qn=function(t,e){return t.has(e)};var Gn=function(t,e,r,n,i,a){var o=1&r,s=t.length,u=e.length;if(s!=u&&!(o&&u>s))return!1;var c=a.get(t),l=a.get(e);if(c&&l)return c==e&&l==t;var h=-1,d=!0,f=2&r?new qn:void 0;for(a.set(t,e),a.set(e,t);++h<s;){var p=t[h],b=e[h];if(n)var v=o?n(b,p,h,e,t,a):n(p,b,h,t,e,a);if(void 0!==v){if(v)continue;d=!1;break}if(f){if(!Ln(e,function(t,e){if(!Qn(f,e)&&(p===t||i(p,t,r,n,a)))return f.push(e)})){d=!1;break}}else if(p!==b&&!i(p,b,r,n,a)){d=!1;break}}return a.delete(t),a.delete(e),d};var Kn=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var Hn=c.Uint8Array,Jn=H,Xn=Gn,Yn=Kn,Zn=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},ti=l?l.prototype:void 0,ei=ti?ti.valueOf:void 0;var ri=function(t,e,r,n,i,a,o){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 Hn(t),new Hn(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Jn(+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 s=Yn;case"[object Set]":var u=1&n;if(s||(s=Zn),t.size!=e.size&&!u)return!1;var c=o.get(t);if(c)return c==e;n|=2,o.set(t,e);var l=Xn(s(t),s(e),n,i,a,o);return o.delete(t),l;case"[object Symbol]":if(ei)return ei.call(t)==ei.call(e)}return!1};var ni=function(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t},ii=ni,ai=$t;var oi=function(t,e,r){var n=e(t);return ai(t)?n:ii(n,r(t))};var si=On,ui=function(){return[]},ci=Object.prototype.propertyIsEnumerable,li=Object.getOwnPropertySymbols,hi=oi,di=li?function(t){return null==t?[]:(t=Object(t),si(li(t),function(e){return ci.call(t,e)}))}:ui,fi=_e;var pi=function(t){return hi(t,fi,di)},bi=Object.prototype.hasOwnProperty;var vi=function(t,e,r,n,i,a){var o=1&r,s=pi(t),u=s.length;if(u!=pi(e).length&&!o)return!1;for(var c=u;c--;){var l=s[c];if(!(o?l in e:bi.call(e,l)))return!1}var h=a.get(t),d=a.get(e);if(h&&d)return h==e&&d==t;var f=!0;a.set(t,e),a.set(e,t);for(var p=o;++c<u;){var b=t[l=s[c]],v=e[l];if(n)var g=o?n(v,b,l,e,t,a):n(b,v,l,t,e,a);if(!(void 0===g?b===v||i(b,v,r,n,a):g)){f=!1;break}p||(p="constructor"==l)}if(f&&!p){var y=t.constructor,m=e.constructor;y==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof m&&m instanceof m||(f=!1)}return a.delete(t),a.delete(e),f},gi=q(c,"DataView"),yi=br,mi=q(c,"Promise"),_i=q(c,"Set"),Si=q(c,"WeakMap"),wi=S,ji=A,Oi="[object Map]",Ci="[object Promise]",xi="[object Set]",Ei="[object WeakMap]",ki="[object DataView]",Ri=ji(gi),Di=ji(yi),Ai=ji(mi),Ni=ji(_i),Mi=ji(Si),Ti=wi;(gi&&Ti(new gi(new ArrayBuffer(1)))!=ki||yi&&Ti(new yi)!=Oi||mi&&Ti(mi.resolve())!=Ci||_i&&Ti(new _i)!=xi||Si&&Ti(new Si)!=Ei)&&(Ti=function(t){var e=wi(t),r="[object Object]"==e?t.constructor:void 0,n=r?ji(r):"";if(n)switch(n){case Ri:return ki;case Di:return Oi;case Ai:return Ci;case Ni:return xi;case Mi:return Ei}return e});var Ii=Pn,zi=Gn,Fi=ri,Pi=vi,Bi=Ti,Wi=$t,Ui=Qt,$i=ie,Vi="[object Arguments]",qi="[object Array]",Li="[object Object]",Qi=Object.prototype.hasOwnProperty;var Gi=function(t,e,r,n,i,a){var o=Wi(t),s=Wi(e),u=o?qi:Bi(t),c=s?qi:Bi(e),l=(u=u==Vi?Li:u)==Li,h=(c=c==Vi?Li:c)==Li,d=u==c;if(d&&Ui(t)){if(!Ui(e))return!1;o=!0,l=!1}if(d&&!l)return a||(a=new Ii),o||$i(t)?zi(t,e,r,n,i,a):Fi(t,e,u,r,n,i,a);if(!(1&r)){var f=l&&Qi.call(t,"__wrapped__"),p=h&&Qi.call(e,"__wrapped__");if(f||p){var b=f?t.value():t,v=p?e.value():e;return a||(a=new Ii),i(b,v,r,n,a)}}return!!d&&(a||(a=new Ii),Pi(t,e,r,n,i,a))},Ki=Mt;var Hi=function t(e,r,n,i,a){return e===r||(null==e||null==r||!Ki(e)&&!Ki(r)?e!=e&&r!=r:Gi(e,r,n,i,t,a))},Ji=Pn,Xi=Hi;var Yi=w;var Zi=function(t){return t==t&&!Yi(t)},ta=Zi,ea=_e;var ra=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 i=r.length,a=i,o=!n;if(null==t)return!a;for(t=Object(t);i--;){var s=r[i];if(o&&s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++i<a;){var u=(s=r[i])[0],c=t[u],l=s[1];if(o&&s[2]){if(void 0===c&&!(u in t))return!1}else{var h=new Ji;if(n)var d=n(c,l,u,t,e,h);if(!(void 0===d?Xi(l,c,3,n,h):d))return!1}}return!0},ia=function(t){for(var e=ea(t),r=e.length;r--;){var n=e[r],i=t[n];e[r]=[n,i,ta(i)]}return e},aa=ra;var oa=Jr,sa=Ut,ua=$t,ca=St,la=vt,ha=Yr;var da=function(t,e){return null!=t&&e in Object(t)},fa=function(t,e,r){for(var n=-1,i=(e=oa(e,t)).length,a=!1;++n<i;){var o=ha(e[n]);if(!(a=null!=t&&r(t,o)))break;t=t[o]}return a||++n!=i?a:!!(i=null==t?0:t.length)&&la(i)&&ca(o,i)&&(ua(t)||sa(t))};var pa=Hi,ba=an,va=function(t,e){return null!=t&&fa(t,e,da)},ga=ze,ya=Zi,ma=ra,_a=Yr;var Sa=en;var wa=function(t){return function(e){return null==e?void 0:e[t]}},ja=function(t){return function(e){return Sa(e,t)}},Oa=ze,Ca=Yr;var xa=function(t){var e=ia(t);return 1==e.length&&e[0][2]?aa(e[0][0],e[0][1]):function(r){return r===t||na(r,t,e)}},Ea=function(t,e){return ga(t)&&ya(e)?ma(_a(t),e):function(r){var n=ba(r,t);return void 0===n&&n===e?va(r,t):pa(e,n,3)}},ka=nt,Ra=$t,Da=function(t){return Oa(t)?wa(Ca(t)):ja(t)};var Aa=function(t){return"function"==typeof t?t:null==t?ka:"object"==typeof t?Ra(t)?Ea(t[0],t[1]):xa(t):Da(t)},Na=On,Ma=xn,Ta=Aa,Ia=$t;var za=a(function(t,e){return(Ia(t)?Na:Ma)(t,Ta(e))}),Fa=fn;var Pa=Vn,Ba=Aa,Wa=function(t,e){var r;return Fa(t,function(t,n,i){return!(r=e(t,n,i))}),!!r},Ua=$t,$a=xt;var Va=a(function(t,e,r){var n=Ua(t)?Pa:Wa;return r&&$a(t,e,r)&&(e=void 0),n(t,Ba(e))}),qa=fn,La=mt;var Qa=function(t,e){var r=-1,n=La(t)?Array(t.length):[];return qa(t,function(t,i,a){n[++r]=e(t,i,a)}),n},Ga=Pr,Ka=Aa,Ha=Qa,Ja=$t;var Xa=a(function(t,e){return(Ja(t)?Ga:Ha)(t,Ka(e))});var Ya=a(function(t){for(var e=-1,r=null==t?0:t.length,n=0,i=[];++e<r;){var a=t[e];a&&(i[n++]=a)}return i}),Za=Ut,to=$t,eo=l?l.isConcatSpreadable:void 0;var ro=ni,no=function(t){return to(t)||Za(t)||!!(eo&&t&&t[eo])};var io=function t(e,r,n,i,a){var o=-1,s=e.length;for(n||(n=no),a||(a=[]);++o<s;){var u=e[o];r>0&&n(u)?r>1?t(u,r-1,n,i,a):ro(a,u):i||(a[a.length]=u)}return a};var ao=Ae;var oo=function(t,e){if(t!==e){var r=void 0!==t,n=null===t,i=t==t,a=ao(t),o=void 0!==e,s=null===e,u=e==e,c=ao(e);if(!s&&!c&&!a&&t>e||a&&o&&u&&!s&&!c||n&&o&&u||!r&&u||!i)return 1;if(!n&&!a&&!c&&t<e||c&&r&&i&&!n&&!a||s&&r&&i||!o&&i||!u)return-1}return 0};var so=Pr,uo=en,co=Aa,lo=Qa,ho=function(t,e){var r=t.length;for(t.sort(e);r--;)t[r]=t[r].value;return t},fo=Yt,po=function(t,e,r){for(var n=-1,i=t.criteria,a=e.criteria,o=i.length,s=r.length;++n<o;){var u=oo(i[n],a[n]);if(u)return n>=s?u:u*("desc"==r[n]?-1:1)}return t.index-e.index},bo=nt,vo=$t;var go,yo,mo=io,_o=function(t,e,r){e=e.length?so(e,function(t){return vo(t)?function(e){return uo(e,1===t.length?t[0]:t)}:t}):[bo];var n=-1;e=so(e,fo(co));var i=lo(t,function(t,r,i){return{criteria:so(e,function(e){return e(t)}),index:++n,value:t}});return ho(i,function(t,e){return po(t,e,r)})},So=xt,wo=a(bt(function(t,e){if(null==t)return[];var r=e.length;return r>1&&So(t,e[0],e[1])?e=[]:r>2&&So(e[0],e[1],e[2])&&(e=[e[0]]),_o(t,mo(e,1),[])}));function jo(t,e,r){return Math.max(r,Math.min(t,e))}function Oo(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 Co(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=jo(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"}(go||(go={}));class xo{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,i=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)i.copyToChannel(a,t);this.addBuffer(i)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Oo(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{jn.error("pause speech fail",t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{jn.error("resume speech fail",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 Eo{stream;audioContext;type="vad";workletNode;source;isRecording=!1;outputSampleRate;chunkTimeInSeconds;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(t,r,n){this.stream=t,this.audioContext=r,this.outputSampleRate=n?.llmSampleRate??16e3,this.chunkTimeInSeconds=n?.chunkTimeInSeconds??1,this.pcmSub=new e.Subject}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad",{processorOptions:{outputSampleRate:this.outputSampleRate,chunkTimeInSeconds:this.chunkTimeInSeconds}}),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e}=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)}}class ko{type="camera";confidenceScore;aiiaCamera;get detections(){return this.aiiaCamera.detections}get faceResult(){const t=this.confidenceScore;return this.aiiaCamera.detections.pipe(e.map(e=>function(t,e){const r=za(t,t=>{const r=t.categories[0]?.score??0,n=t.keypoints,i=100*r>=e,a=Va(n,t=>"leftEye"===t.label||"rightEye"===t.label);return i&&a});if(0===r.length)return null;const n=Ya(Xa(r,t=>{if(void 0!==t.boundingBox){const e=t.boundingBox,r=e.width*e.height,n=t.categories[0]?.score??0;return{...e,area:r,confidenceScore:100*n}}return null}));return wo(n,["area","confidenceScore"])[0]??null}(e,t)))}constructor(t,e,r){const{frame:n,confidence:i}=ke({frame:3,confidence:80},r);this.confidenceScore=i,this.aiiaCamera=new Ro,this.aiiaCamera.setAttribute("frequency",`${n}`),this.aiiaCamera.setStream(t),this.aiiaCamera.setFaceDetector(e),document.body.append(this.aiiaCamera)}startCapture(){this.aiiaCamera.startCapture()}stopCapture(){this.aiiaCamera.stopCapture()}onDestroy(){this.aiiaCamera.remove()}}class Ro extends HTMLElement{static get observedAttributes(){return["debug","frequency"]}_shadow;_containerEl;_styleEl;_videoEl;_isDebug;_debugElements;_analyzeInterval;_frameCount;_loopFrameID;_faceDetector;_detectionsSub;_isReady;get detections(){return this._detectionsSub.asObservable()}constructor(){super(),this._isDebug=!1,this._isReady=!1,this._shadow=this.attachShadow({mode:"open"}),this._containerEl=document.createElement("div"),this._videoEl=document.createElement("video"),this._styleEl=document.createElement("style"),this._debugElements=[],this._loopFrameID=null,this._analyzeInterval=3,this._frameCount=this._analyzeInterval,this._detectionsSub=new e.Subject,this.predictWebcam=this.predictWebcam.bind(this),this._settingContainer(),this._settingStyle(),this._settingVideo(),this._containerEl.appendChild(this._videoEl),this._shadow.appendChild(this._styleEl),this._shadow.appendChild(this._containerEl)}connectedCallback(){this.startCapture()}disconnectedCallback(){this.stopCapture()}attributeChangedCallback(t,e,r){switch(t){case"debug":this._isDebug=null!==r&&("true"===r||""===r),this._containerEl.style.visibility=this._isDebug?"visible":"hidden";break;case"frequency":{const t=Number(r);!isNaN(t)&&t>0&&(this._analyzeInterval=t,this._frameCount=this._analyzeInterval)}}}setStream(t){this._videoEl.srcObject=t,this._videoEl.onloadedmetadata=()=>{this._isReady=!0}}setFaceDetector(t){this._faceDetector=t}_settingStyle(){this._styleEl.textContent="\n .aiia_container {\n visibility: hidden;\n position: fixed;\n top: 0;\n left: 0;\n }\n .aiia_container .highlighter {\n background: rgba(0, 255, 0, 0.25);\n border: 1px dashed #fff;\n z-index: 1;\n position: absolute;\n }\n .aiia_container .confidence {\n position: absolute;\n padding-bottom: 5px;\n padding-top: 5px;\n background-color: #007f8b;\n color: #fff;\n border: 1px dashed rgba(255, 255, 255, 0.7);\n z-index: 2;\n font-size: 12px;\n margin: 0;\n }\n "}_settingContainer(){this._containerEl.classList.add("aiia_container")}_settingVideo(){this._videoEl.autoplay=!0,this._videoEl.playsInline=!0,this._videoEl.muted=!0}getVideo(){return this._videoEl}startCapture(){this._videoEl.play(),this._loopFrameID=window.requestAnimationFrame(this.predictWebcam)}stopCapture(){null!==this._loopFrameID&&(window.cancelAnimationFrame(this._loopFrameID),this._loopFrameID=null),this._videoEl.pause()}async predictWebcam(){if(this._loopFrameID=window.requestAnimationFrame(this.predictWebcam),void 0!==this._faceDetector&&this._isReady){if(this._frameCount===this._analyzeInterval){const t=this._faceDetector.detectForVideo(this._videoEl,performance.now()).detections;this._isDebug&&this._drawRect(t),this._detectionsSub.next(t),this._frameCount=0}this._frameCount++}}_drawRect(t){_n(this._debugElements,t=>{t.style.display="none"}),_n(t,(t,e)=>{const{categories:r,boundingBox:n}=t;if(n){let t=this._debugElements[2*e],i=this._debugElements[2*e+1];t&&i||(t=document.createElement("div"),t.classList.add("highlighter"),i=document.createElement("p"),i.classList.add("confidence"),this._containerEl.append(i,t),this._debugElements.push(t,i)),t.style.display="block",i.style.display="block";const a=100*r[0].score;i.innerText="Confidence: "+Math.round(a)+"% .",i.style.right=this._videoEl.offsetWidth-n.width-n.originX+"px",i.style.top=n.originY-30+"px",i.style.width=n.width-10+"px",t.style.right=this._videoEl.offsetWidth-n.width-n.originX+"px",t.style.top=`${n.originY}px`,t.style.width=n.width-10+"px",t.style.height=`${n.height}px`}});for(let e=2*t.length;e<this._debugElements.length;e++)this._debugElements[e].style.display="none"}destroy(){this._detectionsSub.complete(),this.remove()}}customElements.define("aiia-camera",Ro),function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(yo||(yo={}));class Do{stream;_state;stateSub;audioCtx;audioManager;vadManager;camManager;destory;pcmSub;faceResultSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get faceResult(){return this.faceResultSub.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(t){this.stream=t,this.stateSub=new e.Subject,this.pcmSub=new e.Subject,this.destory=new e.Subject,this.faceResultSub=new e.Subject,this.state=yo.padding}async init(t,n){const i=this.stream??await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0},video:!0});if(null===i)throw this.state=yo.rejected,new Error(nn["未獲得媒體裝置權限"]);this.stream=i,this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw jn.fatal(t),this.state=yo.loadfail,new Error(nn["Worklet模組載入失敗"])}this.state=yo.allowed;const a=await async function(){const t=await r.FilesetResolver.forVisionTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm");return await r.FaceDetector.createFromOptions(t,{baseOptions:{modelAssetPath:"https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite",delegate:"GPU"},runningMode:"VIDEO"})}();this.audioManager=new xo(this.audioCtx),this.vadManager=new Eo(i,this.audioCtx,n),this.vadManager.pcm.pipe(e.takeUntil(this.destory)).subscribe(t=>{this.pcmSub.next(t)}),this.camManager=new ko(i,a,n?.faceDetection),this.camManager.faceResult.pipe(e.takeUntil(this.destory)).subscribe(t=>{this.faceResultSub.next(t)})}addAudioQueue(t){const e=on(t,"buffer",void 0),r=on(t,"float32",void 0),n=on(t,"int16",void 0),i=on(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,i):n&&this.audioManager?.addBufferByInt16(n,i)}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}startCapture(){this.camManager?.startCapture()}stopCapture(){this.camManager?.stopCapture()}onDestroy(){this.camManager?.onDestroy(),this.audioCtx?.close(),this.destory.next(),this.destory.complete()}}var Ao=Aa,No=mt,Mo=_e;var To=function(t){return function(e,r,n){var i=Object(e);if(!No(e)){var a=Ao(r);e=Mo(e),r=function(t){return a(i[t],t,i)}}var o=t(e,r,n);return o>-1?i[a?e[o]:o]:void 0}};var Io=/\s/;var zo=function(t){for(var e=t.length;e--&&Io.test(t.charAt(e)););return e},Fo=/^\s+/;var Po=function(t){return t?t.slice(0,zo(t)+1).replace(Fo,""):t},Bo=w,Wo=Ae,Uo=/^[-+]0x[0-9a-f]+$/i,$o=/^0b[01]+$/i,Vo=/^0o[0-7]+$/i,qo=parseInt;var Lo=function(t){if("number"==typeof t)return t;if(Wo(t))return NaN;if(Bo(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Bo(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Po(t);var r=$o.test(t);return r||Vo.test(t)?qo(t.slice(2),r?2:8):Uo.test(t)?NaN:+t},Qo=1/0;var Go=function(t){return t?(t=Lo(t))===Qo||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ko=function(t,e,r,n){for(var i=t.length,a=r+(n?1:-1);n?a--:++a<i;)if(e(t[a],a,t))return a;return-1},Ho=Aa,Jo=function(t){var e=Go(t),r=e%1;return e==e?r?e-r:e:0},Xo=Math.max;var Yo=a(To(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var i=null==r?0:Jo(r);return i<0&&(i=Xo(n+i,0)),Ko(t,Ho(e),i)})),Zo=Pr;var ts=function(t,e){return Zo(e,function(e){return t[e]})},es=_e;var rs=a(function(t){return null==t?[]:ts(t,es(t))});class ns{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(t){this.destorySub=new e.Subject,this.messageSub=new e.Subject;const{specific:r,id:i}=t.project;this.socket=n.io(t.ws_url,ke({autoConnect:!1},r&&void 0!==i?{query:{uuid:i}}:{}))}start(){const t="list",r="cloud",n="channel";e.fromEvent(this.socket,t).pipe(e.take(1),e.takeUntil(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),e.fromEvent(this.socket,r).pipe(e.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),e.fromEvent(this.socket,n).pipe(e.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))}onDestroy(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}class is{config;media;chat;destorySub;projectsSub;layoutSub;aiiaSubtitleSub;userSubtitleSub;sampleRateOfWhisper;channelState;stateSub;isMuteAiia;aiiaSubtitleClearSub;userSubtitleClearSub;get state(){return this.stateSub.asObservable()}get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}get aiiaSubtitle(){return this.aiiaSubtitleSub.asObservable()}get userSubtitle(){return this.userSubtitleSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(t,r){this.config=t,this.media=r,this.layoutSub=new e.Subject,this.projectsSub=new e.ReplaySubject(1),this.destorySub=new e.Subject,this.aiiaSubtitleSub=new e.Subject,this.userSubtitleSub=new e.Subject,this.aiiaSubtitleClearSub=new e.Subject,this.userSubtitleClearSub=new e.Subject,this.stateSub=new e.BehaviorSubject("NotStart"),this.sampleRateOfWhisper={input:t.llmSampleRate,output:16e3},this.channelState={proxy:!1,cloud:!1},this.isMuteAiia=!1,this.chat=new ns(t),jn.code(mn["指定依賴已完成"],"chat"),this.close=this.onDestroy,this.behavior=this.behavior.bind(this),this.cloudToObj=this.cloudToObj.bind(this);const{userDelayTime:n,aiiaDelayTime:i}=t.autoClearSubtitle;isNaN(i)||this.aiiaSubtitleClearSub.pipe(e.debounceTime(i),e.takeUntil(this.destorySub)).subscribe(()=>{this.aiiaSubtitleSub.next("")}),isNaN(n)||this.userSubtitleClearSub.pipe(e.debounceTime(n),e.takeUntil(this.destorySub)).subscribe(()=>{this.userSubtitleSub.next("")})}start(){this.media.stateObs.pipe(e.takeUntil(this.destorySub)).subscribe(()=>{this.channelCheck()}),this.chat.message.pipe(e.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 i=null;if(n&&void 0!==t)i=t;else{const n=Yo(e,e=>e.name===r||e.id===t);n&&(i=n.id)}null!==i?this.chooseProject(i):(this.projectsSub.next(e),this.stateSub.next("WattingProjectID"),jn.code(mn["請訂閱專案列表"]));break}case"channel":switch(e){case"open":this.channelState.proxy=!0,this.channelCheck();break;case"close":this.channelState.proxy=!1,this.media.stopRecord(),this.stateSub.next("CloseService");break;case"no_permissions":this.channelState.proxy=!1,this.stateSub.next("NoPermissions");break;case"reconnect":this.channelState.proxy=!1,this.stateSub.next("ReconnectingCloud")}}}),this.chat.start(),this.stateSub.next("ConnectingCloud"),jn.code(mn["啟動SDK"])}close;resetSession(){this.chat.sendToCloud({request:"reset"}),this.aiiaSubtitleSub.next(""),this.userSubtitleSub.next(""),this.media.stopAudio(),this.layoutSub.next({type:"resetLayout"})}chooseProject(t){this.chat.send("uuid",t),this.stateSub.next("ConnectingCloud")}mute(){this.isMuteAiia=!0,this.media.stopAudio(),this.media.stopRecord()}unmute(){this.isMuteAiia=!1,this.media.startRecord()}cloudToObj(t){try{const e=JSON.parse(t);void 0!==on(e,"signal")?this.behavior(e):Vt(e)?Xa(e,this.behavior):Xa(rs(e),this.behavior)}catch(t){jn.error("message transfer fail",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.sampleRateOfWhisper.output=t.content;else switch(t.command){case"pcm":if(!this.isMuteAiia){const e=function(t,e,r){if(e===r)return t;const n=r/e,i=Math.ceil(t.length*n),a=new Float32Array(i);for(let e=0;e<i;e++){const r=e/n,i=Math.floor(r),o=r-i,s=t[i],u=t[Math.min(i+1,t.length-1)];a[e]=s+(u-s)*o}return a}(Oo(new Int16Array(t.content)),this.sampleRateOfWhisper.output,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio()}break;case"interrupted":this.media.stopAudio(),this.aiiaSubtitleSub.next("")}break;case"status":"Connected"===on(t,"content")&&(this.channelState.cloud=!0,this.channelCheck(),this.layoutSub.next({type:"resetLayout"}));break;case"agent":if(!this.isMuteAiia){const e=on(t,"content.function_result.response");void 0!==e&&(this.aiiaSubtitleSub.next(e),this.aiiaSubtitleClearSub.next())}break;case"asr":if(!this.isMuteAiia&&"ASR"===on(t,"content.function_type")){const e=on(t,"content.function_result.result");void 0!==e&&(this.userSubtitleSub.next(e),this.userSubtitleClearSub.next())}break;default:jn.debug(t.signal)}}channelCheck(){const{proxy:t,cloud:r}=this.channelState;t&&r&&this.media.state===yo.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.sampleRateOfWhisper.input}),this.media.pcm.pipe(e.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Co(t)})}),this.media.faceResult.pipe(e.takeUntil(this.destorySub)).subscribe(t=>{this.chat.send("face",t)}),this.media.startRecord(),this.media.startCapture(),this.stateSub.next("InService"),jn.code(mn["通道、雲端服務、麥克風都已就緒"])):t&&r&&this.media.state!==yo.allowed&&(this.stateSub.next("InServiceNoMedia"),jn.code(mn["未取得媒體裝置權限,請重新設定或忽略此訊息"]))}onDestroy(){this.chat.onDestroy(),this.media.onDestroy(),this.destorySub.next(),this.destorySub.complete(),this.stateSub.next("Destroy"),this.stateSub.complete(),jn.code(mn["結束SDK"])}}exports.initSdk=function(t){if(sn){!function(t){const{info:e,error:r,warn:n,debug:i,fatal:a,code:o}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);o||(Sn.code=()=>{}),i||(Sn.debug=()=>{}),e||(Sn.info=()=>{}),n||(Sn.warn=()=>{}),r||(Sn.error=()=>{}),a||(Sn.fatal=()=>{})}(on(t,"debug",!0)),jn.code(mn["初始化必要依賴"]);const e=new un(ke({},t));jn.code(mn["指定依賴已完成"],"config");const r=new Do(e.mediaStream);jn.code(mn["指定依賴已完成"],"config");const n=new is(e,r);return jn.code(mn["指定依賴已完成"],"sdk"),""!==e.worklet_url&&r.init(e.worklet_url,e),n}throw new Error(nn["環境錯誤(browser)"])};
package/dist/browser.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { BoundingBox } from '@mediapipe/tasks-vision';
1
2
  import { Http2SecureServer } from 'http2';
2
3
  import { Http2Server } from 'http2';
3
4
  import { Observable } from 'rxjs';
@@ -23,6 +24,14 @@ declare class AiiaConfig {
23
24
  get mediaStream(): MediaStream | undefined;
24
25
  get chunkTimeInSeconds(): number;
25
26
  get llmSampleRate(): number;
27
+ get faceDetection(): {
28
+ frame: number;
29
+ confidence: number;
30
+ };
31
+ get autoClearSubtitle(): {
32
+ userDelayTime: number;
33
+ aiiaDelayTime: number;
34
+ };
26
35
  constructor(config: InitOptions);
27
36
  }
28
37
 
@@ -40,10 +49,12 @@ declare class AiiaSdk {
40
49
  private layoutSub;
41
50
  private aiiaSubtitleSub;
42
51
  private userSubtitleSub;
43
- private cloudSampleRate;
52
+ private sampleRateOfWhisper;
44
53
  private channelState;
45
54
  private stateSub;
46
55
  private isMuteAiia;
56
+ private aiiaSubtitleClearSub;
57
+ private userSubtitleClearSub;
47
58
  /**
48
59
  * [zh]
49
60
  * 服務的狀態
@@ -125,7 +136,7 @@ declare class AiiaSdk {
125
136
  */
126
137
  start(): void;
127
138
  /**
128
- * Alias for `onDestory`.
139
+ * Alias for `onDestroy`.
129
140
  *
130
141
  * [zh]
131
142
  * 停止所有服務,釋放資源
@@ -181,13 +192,18 @@ declare class AiiaSdk {
181
192
  * [en]
182
193
  * Stop all services to release resources
183
194
  */
184
- onDestory(): void;
195
+ onDestroy(): void;
185
196
  }
186
197
 
187
- export declare type AiiaState = "NotStart" | "ConnectingCloud" | "ReconnectingCloud" | "InService" | "InServiceNoMedia" | "NoPermissions" | "CloseService" | "Destory";
198
+ export declare type AiiaState = "NotStart" | "WattingProjectID" | "ConnectingCloud" | "ReconnectingCloud" | "InService" | "InServiceNoMedia" | "NoPermissions" | "CloseService" | "Destroy";
188
199
 
189
200
  export declare type BrowserInitOptions = Omit<InitOptions, "webserver" | "port" | "license">;
190
201
 
202
+ declare type FaceDetectorResult = ({
203
+ area: number;
204
+ confidenceScore: number;
205
+ } & BoundingBox) | null;
206
+
191
207
  declare interface InitOptions {
192
208
  /**
193
209
  * [zh]
@@ -255,6 +271,15 @@ declare interface InitOptions {
255
271
  * Switch message(info, error, warn) dispaly, default: true
256
272
  */
257
273
  debug?: boolean | "all" | "none" | LoggerLevel[];
274
+ /**
275
+ * [zh]
276
+ * 授權的媒體裝置,請包含麥克風及鏡頭/攝影機權限
277
+ *
278
+ * [en]
279
+ * Authorized media devices, please include microphone and lens/camera permissions.
280
+ *
281
+ * https://developer.mozilla.org/en-US/docs/Web/API/MediaStream
282
+ */
258
283
  mediaStream?: MediaStream;
259
284
  /**
260
285
  * [zh]
@@ -272,6 +297,36 @@ declare interface InitOptions {
272
297
  * Specify the sampling rate of audio output (provided for LLM analysis). Changing is not recommended.
273
298
  */
274
299
  llmSampleRate?: number;
300
+ /**
301
+ * [zh]
302
+ * 人臉辨識
303
+ *
304
+ * frame: 每幾幀更新一次, 預設: 3
305
+ *
306
+ * confidence: 分數(0 ~ 100), 預設: 80
307
+ *
308
+ * [en]
309
+ * facial recognition
310
+ *
311
+ * frame: Update every few frames, default: 3
312
+ *
313
+ * confidence: score(0 ~ 100), default: 80
314
+ */
315
+ faceDetection?: {
316
+ frame?: number;
317
+ confidence?: number;
318
+ };
319
+ /**
320
+ * [zh]
321
+ * 清除字幕,可指定時間(毫秒),預設 3000 毫秒後清除
322
+ *
323
+ * [en]
324
+ * Clear subtitles, you can specify the time (milliseconds), the default is to clear after 3000 milliseconds.
325
+ */
326
+ autoClearSubtitle?: {
327
+ user?: boolean | number;
328
+ aiia?: boolean | number;
329
+ };
275
330
  }
276
331
 
277
332
  export declare function initSdk(options?: BrowserInitOptions): AiiaSdk;
@@ -287,17 +342,21 @@ declare class MediaManager {
287
342
  private audioCtx?;
288
343
  private audioManager?;
289
344
  private vadManager?;
345
+ private camManager?;
290
346
  private destory;
291
347
  private pcmSub;
348
+ private faceResultSub;
292
349
  get sampleRate(): number;
293
350
  get pcm(): Observable<Float32Array<ArrayBufferLike>>;
351
+ get faceResult(): Observable<FaceDetectorResult>;
294
352
  get state(): MediaStateEnum;
295
353
  set state(v: MediaStateEnum);
296
354
  get stateObs(): Observable<MediaStateEnum>;
297
355
  constructor(stream?: MediaStream | undefined);
298
356
  init(workletUrl: string, config?: {
299
- chunkTimeInSeconds?: number | undefined;
300
- outputSampleRate?: number | undefined;
357
+ llmSampleRate?: AiiaConfig["llmSampleRate"];
358
+ chunkTimeInSeconds?: AiiaConfig["chunkTimeInSeconds"];
359
+ faceDetection?: AiiaConfig["faceDetection"];
301
360
  }): Promise<void>;
302
361
  addAudioQueue(input: {
303
362
  buffer: AudioBuffer;
@@ -314,7 +373,9 @@ declare class MediaManager {
314
373
  stopRecord(): void;
315
374
  setVolume(val: number): void;
316
375
  getVolume(): number;
317
- onDestory(): void;
376
+ startCapture(): void;
377
+ stopCapture(): void;
378
+ onDestroy(): void;
318
379
  }
319
380
 
320
381
  declare enum MediaStateEnum {
package/dist/browser.mjs CHANGED
@@ -1 +1 @@
1
- import t from"moment";import{Subject as e,fromEvent as r,take as n,takeUntil as o,ReplaySubject as i}from"rxjs";import{io as a}from"socket.io-client";var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var c="object"==typeof s&&s&&s.Object===Object&&s,l=c,h="object"==typeof self&&self&&self.Object===Object&&self,f=l||h||Function("return this")(),d=f.Symbol,p=d,v=Object.prototype,b=v.hasOwnProperty,g=v.toString,y=p?p.toStringTag:void 0;var m=function(t){var e=b.call(t,y),r=t[y];try{t[y]=void 0;var n=!0}catch(t){}var o=g.call(t);return n&&(e?t[y]=r:delete t[y]),o},S=Object.prototype.toString;var _=m,w=function(t){return S.call(t)},j=d?d.toStringTag:void 0;var O=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":j&&j in Object(t)?_(t):w(t)};var x=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},R=O,C=x;var k,A=function(t){if(!C(t))return!1;var e=R(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},E=f["__core-js_shared__"],D=(k=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var N=function(t){return!!D&&D in t},M=Function.prototype.toString;var T=function(t){if(null!=t){try{return M.call(t)}catch(t){}try{return t+""}catch(t){}}return""},I=A,z=N,P=x,B=T,F=/^\[object .+?Constructor\]$/,$=Function.prototype,V=Object.prototype,Q=$.toString,L=V.hasOwnProperty,U=RegExp("^"+Q.call(L).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var W=function(t){return!(!P(t)||z(t))&&(I(t)?U:F).test(B(t))},q=function(t,e){return null==t?void 0:t[e]};var G=function(t,e){var r=q(t,e);return W(r)?r:void 0},K=G,H=function(){try{var t=K(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=H;var X=function(t,e,r){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var Y=function(t,e){return t===e||t!=t&&e!=e},Z=X,tt=Y,et=Object.prototype.hasOwnProperty;var rt=function(t,e,r){var n=t[e];et.call(t,e)&&tt(n,r)&&(void 0!==r||e in t)||Z(t,e,r)},nt=rt,ot=X;var it=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var s=e[i],u=n?n(r[s],t[s],s,r,t):void 0;void 0===u&&(u=t[s]),o?ot(r,s,u):nt(r,s,u)}return r};var at=function(t){return t};var st=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)},ut=Math.max;var ct=function(t,e,r){return e=ut(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=ut(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var s=Array(e+1);++o<e;)s[o]=n[o];return s[e]=r(a),st(t,this,s)}};var lt=function(t){return function(){return t}},ht=H,ft=ht?function(t,e){return ht(t,"toString",{configurable:!0,enumerable:!1,value:lt(e),writable:!0})}:at,dt=Date.now;var pt=function(t){var e=0,r=0;return function(){var n=dt(),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),vt=at,bt=ct,gt=pt;var yt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},mt=A,St=yt;var _t=function(t){return null!=t&&St(t.length)&&!mt(t)},wt=/^(?:0|[1-9]\d*)$/;var jt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&wt.test(t))&&t>-1&&t%1==0&&t<e},Ot=Y,xt=_t,Rt=jt,Ct=x;var kt=function(t,e){return gt(bt(t,e,vt),t+"")},At=function(t,e,r){if(!Ct(r))return!1;var n=typeof e;return!!("number"==n?xt(r)&&Rt(e,r.length):"string"==n&&e in r)&&Ot(r[e],t)};var Et=function(t){return kt(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,a&&At(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var s=r[n];s&&t(e,s,n,i)}return e})},Dt=Object.prototype;var Nt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Dt)};var Mt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Tt=function(t){return null!=t&&"object"==typeof t},It=O,zt=Tt;var Pt=function(t){return zt(t)&&"[object Arguments]"==It(t)},Bt=Tt,Ft=Object.prototype,$t=Ft.hasOwnProperty,Vt=Ft.propertyIsEnumerable,Qt=Pt(function(){return arguments}())?Pt:function(t){return Bt(t)&&$t.call(t,"callee")&&!Vt.call(t,"callee")},Lt=Array.isArray,Ut=u(Lt),Wt={exports:{}};var qt=function(){return!1};!function(t,e){var r=f,n=qt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,s=(a?a.isBuffer:void 0)||n;t.exports=s}(Wt,Wt.exports);var Gt=Wt.exports,Kt=O,Ht=yt,Jt=Tt,Xt={};Xt["[object Float32Array]"]=Xt["[object Float64Array]"]=Xt["[object Int8Array]"]=Xt["[object Int16Array]"]=Xt["[object Int32Array]"]=Xt["[object Uint8Array]"]=Xt["[object Uint8ClampedArray]"]=Xt["[object Uint16Array]"]=Xt["[object Uint32Array]"]=!0,Xt["[object Arguments]"]=Xt["[object Array]"]=Xt["[object ArrayBuffer]"]=Xt["[object Boolean]"]=Xt["[object DataView]"]=Xt["[object Date]"]=Xt["[object Error]"]=Xt["[object Function]"]=Xt["[object Map]"]=Xt["[object Number]"]=Xt["[object Object]"]=Xt["[object RegExp]"]=Xt["[object Set]"]=Xt["[object String]"]=Xt["[object WeakMap]"]=!1;var Yt=function(t){return Jt(t)&&Ht(t.length)&&!!Xt[Kt(t)]};var Zt=function(t){return function(e){return t(e)}},te={exports:{}};!function(t,e){var r=c,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n&&r.process,a=function(){try{var t=o&&o.require&&o.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=a}(te,te.exports);var ee=te.exports,re=Yt,ne=Zt,oe=ee&&ee.isTypedArray,ie=oe?ne(oe):re,ae=Mt,se=Qt,ue=Lt,ce=Gt,le=jt,he=ie,fe=Object.prototype.hasOwnProperty;var de=function(t,e){var r=ue(t),n=!r&&se(t),o=!r&&!n&&ce(t),i=!r&&!n&&!o&&he(t),a=r||n||o||i,s=a?ae(t.length,String):[],u=s.length;for(var c in t)!e&&!fe.call(t,c)||a&&("length"==c||o&&("offset"==c||"parent"==c)||i&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||le(c,u))||s.push(c);return s};var pe=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),ve=Nt,be=pe,ge=Object.prototype.hasOwnProperty;var ye=de,me=function(t){if(!ve(t))return be(t);var e=[];for(var r in Object(t))ge.call(t,r)&&"constructor"!=r&&e.push(r);return e},Se=_t;var _e=function(t){return Se(t)?ye(t):me(t)},we=rt,je=it,Oe=Et,xe=_t,Re=Nt,Ce=_e,ke=Object.prototype.hasOwnProperty,Ae=u(Oe(function(t,e){if(Re(e)||xe(e))je(e,Ce(e),t);else for(var r in e)ke.call(e,r)&&we(t,r,e[r])})),Ee=O,De=Tt;var Ne=function(t){return"symbol"==typeof t||De(t)&&"[object Symbol]"==Ee(t)},Me=Lt,Te=Ne,Ie=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ze=/^\w*$/;var Pe=function(t,e){if(Me(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Te(t))||(ze.test(t)||!Ie.test(t)||null!=e&&t in Object(e))},Be=G(Object,"create"),Fe=Be;var $e=function(){this.__data__=Fe?Fe(null):{},this.size=0};var Ve=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Qe=Be,Le=Object.prototype.hasOwnProperty;var Ue=function(t){var e=this.__data__;if(Qe){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Le.call(e,t)?e[t]:void 0},We=Be,qe=Object.prototype.hasOwnProperty;var Ge=Be;var Ke=$e,He=Ve,Je=Ue,Xe=function(t){var e=this.__data__;return We?void 0!==e[t]:qe.call(e,t)},Ye=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Ge&&void 0===e?"__lodash_hash_undefined__":e,this};function Ze(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])}}Ze.prototype.clear=Ke,Ze.prototype.delete=He,Ze.prototype.get=Je,Ze.prototype.has=Xe,Ze.prototype.set=Ye;var tr=Ze;var er=function(){this.__data__=[],this.size=0},rr=Y;var nr=function(t,e){for(var r=t.length;r--;)if(rr(t[r][0],e))return r;return-1},or=nr,ir=Array.prototype.splice;var ar=nr;var sr=nr;var ur=nr;var cr=er,lr=function(t){var e=this.__data__,r=or(e,t);return!(r<0)&&(r==e.length-1?e.pop():ir.call(e,r,1),--this.size,!0)},hr=function(t){var e=this.__data__,r=ar(e,t);return r<0?void 0:e[r][1]},fr=function(t){return sr(this.__data__,t)>-1},dr=function(t,e){var r=this.__data__,n=ur(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=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=cr,pr.prototype.delete=lr,pr.prototype.get=hr,pr.prototype.has=fr,pr.prototype.set=dr;var vr=pr,br=G(f,"Map"),gr=tr,yr=vr,mr=br;var Sr=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var _r=function(t,e){var r=t.__data__;return Sr(e)?r["string"==typeof e?"string":"hash"]:r.map},wr=_r;var jr=_r;var Or=_r;var xr=_r;var Rr=function(){this.size=0,this.__data__={hash:new gr,map:new(mr||yr),string:new gr}},Cr=function(t){var e=wr(this,t).delete(t);return this.size-=e?1:0,e},kr=function(t){return jr(this,t).get(t)},Ar=function(t){return Or(this,t).has(t)},Er=function(t,e){var r=xr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Dr(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])}}Dr.prototype.clear=Rr,Dr.prototype.delete=Cr,Dr.prototype.get=kr,Dr.prototype.has=Ar,Dr.prototype.set=Er;var Nr=Dr,Mr=Nr;function Tr(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],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Tr.Cache||Mr),r}Tr.Cache=Mr;var Ir=Tr;var zr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Pr=/\\(\\)?/g,Br=function(t){var e=Ir(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(zr,function(t,r,n,o){e.push(n?o.replace(Pr,"$1"):r||t)}),e});var Fr=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},$r=Fr,Vr=Lt,Qr=Ne,Lr=d?d.prototype:void 0,Ur=Lr?Lr.toString:void 0;var Wr=function t(e){if("string"==typeof e)return e;if(Vr(e))return $r(e,t)+"";if(Qr(e))return Ur?Ur.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},qr=Wr;var Gr=Lt,Kr=Pe,Hr=Br,Jr=function(t){return null==t?"":qr(t)};var Xr=function(t,e){return Gr(t)?t:Kr(t,e)?[t]:Hr(Jr(t))},Yr=Ne;var Zr=function(t){if("string"==typeof t||Yr(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},tn=Xr,en=Zr;var rn=function(t,e){for(var r=0,n=(e=tn(e,t)).length;null!=t&&r<n;)t=t[en(e[r++])];return r&&r==n?t:void 0},nn=rn;var on,an=function(t,e,r){var n=null==t?void 0:nn(t,e);return void 0===n?r:n},sn=u(an);!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: 2005"}(on||(on={}));const un="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class cn{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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}constructor(t){this.config=t}}var ln=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var hn=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),s=a.length;s--;){var u=a[t?s:++o];if(!1===r(i[u],u,i))break}return e}}(),fn=_e;var dn=_t;var pn=function(t,e){return function(r,n){if(null==r)return r;if(!dn(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(t,e){return t&&hn(t,e,fn)}),vn=at;var bn=ln,gn=pn,yn=function(t){return"function"==typeof t?t:vn},mn=Lt;var Sn,_n=u(function(t,e){return(mn(t)?bn:gn)(t,yn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(Sn||(Sn={}));const wn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},jn=[];const On=new Proxy(wn,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const o=t().format("yyyy-MM-DD[T]HH:mm:ss");_n(jn,t=>{t.next(r,o,...n)}),e[r](`[Aiia::${r}_${o}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});var xn,Rn;function Cn(t,e,r){return Math.max(r,Math.min(t,e))}function kn(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 An(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Cn(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"}(xn||(xn={}));class En{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),i=t.slice();for(let t=0;t<e;t++)o.copyToChannel(i,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(kn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{On.error("pause speech fail",t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{On.error("resume speech fail",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 Dn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;outputSampleRate;chunkTimeInSeconds;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(t,r,n){this.stream=t,this.audioContext=r;const{outputSampleRate:o,chunkTimeInSeconds:i}=Ae({outputSampleRate:16e3,chunkTimeInSeconds:1},n);this.outputSampleRate=o,this.chunkTimeInSeconds=i,this.pcmSub=new e}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad",{processorOptions:{outputSampleRate:this.outputSampleRate,chunkTimeInSeconds:this.chunkTimeInSeconds}}),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e}=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"}(Rn||(Rn={}));class Nn{stream;_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(t){this.stream=t,this.stateSub=new e,this.pcmSub=new e,this.destory=new e,this.state=Rn.padding}async init(t,e){const r=this.stream??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=Rn.rejected,new Error(on["未獲得媒體裝置權限"]);this.stream=r,this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw On.fatal(t),this.state=Rn.loadfail,new Error(on["Worklet模組載入失敗"])}this.state=Rn.allowed,this.audioManager=new En(this.audioCtx),this.vadManager=new Dn(r,this.audioCtx,e),this.vadManager.pcm.subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=sn(t,"buffer",void 0),r=sn(t,"float32",void 0),n=sn(t,"int16",void 0),o=sn(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 Mn=vr;var Tn=vr,In=br,zn=Nr;var Pn=vr,Bn=function(){this.__data__=new Mn,this.size=0},Fn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},$n=function(t){return this.__data__.get(t)},Vn=function(t){return this.__data__.has(t)},Qn=function(t,e){var r=this.__data__;if(r instanceof Tn){var n=r.__data__;if(!In||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 Ln(t){var e=this.__data__=new Pn(t);this.size=e.size}Ln.prototype.clear=Bn,Ln.prototype.delete=Fn,Ln.prototype.get=$n,Ln.prototype.has=Vn,Ln.prototype.set=Qn;var Un=Ln;var Wn=Nr,qn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Gn=function(t){return this.__data__.has(t)};function Kn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Wn;++e<r;)this.add(t[e])}Kn.prototype.add=Kn.prototype.push=qn,Kn.prototype.has=Gn;var Hn=Kn,Jn=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},Xn=function(t,e){return t.has(e)};var Yn=function(t,e,r,n,o,i){var a=1&r,s=t.length,u=e.length;if(s!=u&&!(a&&u>s))return!1;var c=i.get(t),l=i.get(e);if(c&&l)return c==e&&l==t;var h=-1,f=!0,d=2&r?new Hn:void 0;for(i.set(t,e),i.set(e,t);++h<s;){var p=t[h],v=e[h];if(n)var b=a?n(v,p,h,e,t,i):n(p,v,h,t,e,i);if(void 0!==b){if(b)continue;f=!1;break}if(d){if(!Jn(e,function(t,e){if(!Xn(d,e)&&(p===t||o(p,t,r,n,i)))return d.push(e)})){f=!1;break}}else if(p!==v&&!o(p,v,r,n,i)){f=!1;break}}return i.delete(t),i.delete(e),f};var Zn=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var to=f.Uint8Array,eo=Y,ro=Yn,no=Zn,oo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},io=d?d.prototype:void 0,ao=io?io.valueOf:void 0;var so=function(t,e,r,n,o,i,a){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||!i(new to(t),new to(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return eo(+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 s=no;case"[object Set]":var u=1&n;if(s||(s=oo),t.size!=e.size&&!u)return!1;var c=a.get(t);if(c)return c==e;n|=2,a.set(t,e);var l=ro(s(t),s(e),n,o,i,a);return a.delete(t),l;case"[object Symbol]":if(ao)return ao.call(t)==ao.call(e)}return!1};var uo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},co=uo,lo=Lt;var ho=function(t,e,r){var n=e(t);return lo(t)?n:co(n,r(t))};var fo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i},po=function(){return[]},vo=Object.prototype.propertyIsEnumerable,bo=Object.getOwnPropertySymbols,go=ho,yo=bo?function(t){return null==t?[]:(t=Object(t),fo(bo(t),function(e){return vo.call(t,e)}))}:po,mo=_e;var So=function(t){return go(t,mo,yo)},_o=Object.prototype.hasOwnProperty;var wo=function(t,e,r,n,o,i){var a=1&r,s=So(t),u=s.length;if(u!=So(e).length&&!a)return!1;for(var c=u;c--;){var l=s[c];if(!(a?l in e:_o.call(e,l)))return!1}var h=i.get(t),f=i.get(e);if(h&&f)return h==e&&f==t;var d=!0;i.set(t,e),i.set(e,t);for(var p=a;++c<u;){var v=t[l=s[c]],b=e[l];if(n)var g=a?n(b,v,l,e,t,i):n(v,b,l,t,e,i);if(!(void 0===g?v===b||o(v,b,r,n,i):g)){d=!1;break}p||(p="constructor"==l)}if(d&&!p){var y=t.constructor,m=e.constructor;y==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof m&&m instanceof m||(d=!1)}return i.delete(t),i.delete(e),d},jo=G(f,"DataView"),Oo=br,xo=G(f,"Promise"),Ro=G(f,"Set"),Co=G(f,"WeakMap"),ko=O,Ao=T,Eo="[object Map]",Do="[object Promise]",No="[object Set]",Mo="[object WeakMap]",To="[object DataView]",Io=Ao(jo),zo=Ao(Oo),Po=Ao(xo),Bo=Ao(Ro),Fo=Ao(Co),$o=ko;(jo&&$o(new jo(new ArrayBuffer(1)))!=To||Oo&&$o(new Oo)!=Eo||xo&&$o(xo.resolve())!=Do||Ro&&$o(new Ro)!=No||Co&&$o(new Co)!=Mo)&&($o=function(t){var e=ko(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ao(r):"";if(n)switch(n){case Io:return To;case zo:return Eo;case Po:return Do;case Bo:return No;case Fo:return Mo}return e});var Vo=Un,Qo=Yn,Lo=so,Uo=wo,Wo=$o,qo=Lt,Go=Gt,Ko=ie,Ho="[object Arguments]",Jo="[object Array]",Xo="[object Object]",Yo=Object.prototype.hasOwnProperty;var Zo=function(t,e,r,n,o,i){var a=qo(t),s=qo(e),u=a?Jo:Wo(t),c=s?Jo:Wo(e),l=(u=u==Ho?Xo:u)==Xo,h=(c=c==Ho?Xo:c)==Xo,f=u==c;if(f&&Go(t)){if(!Go(e))return!1;a=!0,l=!1}if(f&&!l)return i||(i=new Vo),a||Ko(t)?Qo(t,e,r,n,o,i):Lo(t,e,u,r,n,o,i);if(!(1&r)){var d=l&&Yo.call(t,"__wrapped__"),p=h&&Yo.call(e,"__wrapped__");if(d||p){var v=d?t.value():t,b=p?e.value():e;return i||(i=new Vo),o(v,b,r,n,i)}}return!!f&&(i||(i=new Vo),Uo(t,e,r,n,o,i))},ti=Tt;var ei=function t(e,r,n,o,i){return e===r||(null==e||null==r||!ti(e)&&!ti(r)?e!=e&&r!=r:Zo(e,r,n,o,t,i))},ri=Un,ni=ei;var oi=x;var ii=function(t){return t==t&&!oi(t)},ai=ii,si=_e;var ui=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},ci=function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var s=r[o];if(a&&s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++o<i;){var u=(s=r[o])[0],c=t[u],l=s[1];if(a&&s[2]){if(void 0===c&&!(u in t))return!1}else{var h=new ri;if(n)var f=n(c,l,u,t,e,h);if(!(void 0===f?ni(l,c,3,n,h):f))return!1}}return!0},li=function(t){for(var e=si(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,ai(o)]}return e},hi=ui;var fi=Xr,di=Qt,pi=Lt,vi=jt,bi=yt,gi=Zr;var yi=function(t,e){return null!=t&&e in Object(t)},mi=function(t,e,r){for(var n=-1,o=(e=fi(e,t)).length,i=!1;++n<o;){var a=gi(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&bi(o)&&vi(a,o)&&(pi(t)||di(t))};var Si=ei,_i=an,wi=function(t,e){return null!=t&&mi(t,e,yi)},ji=Pe,Oi=ii,xi=ui,Ri=Zr;var Ci=rn;var ki=function(t){return function(e){return null==e?void 0:e[t]}},Ai=function(t){return function(e){return Ci(e,t)}},Ei=Pe,Di=Zr;var Ni=function(t){var e=li(t);return 1==e.length&&e[0][2]?hi(e[0][0],e[0][1]):function(r){return r===t||ci(r,t,e)}},Mi=function(t,e){return ji(t)&&Oi(e)?xi(Ri(t),e):function(r){var n=_i(r,t);return void 0===n&&n===e?wi(r,t):Si(e,n,3)}},Ti=at,Ii=Lt,zi=function(t){return Ei(t)?ki(Di(t)):Ai(t)};var Pi=function(t){return"function"==typeof t?t:null==t?Ti:"object"==typeof t?Ii(t)?Mi(t[0],t[1]):Ni(t):zi(t)},Bi=pn,Fi=_t;var $i=Fr,Vi=Pi,Qi=function(t,e){var r=-1,n=Fi(t)?Array(t.length):[];return Bi(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Li=Lt;var Ui=u(function(t,e){return(Li(t)?$i:Qi)(t,Vi(e))}),Wi=Pi,qi=_t,Gi=_e;var Ki=function(t){return function(e,r,n){var o=Object(e);if(!qi(e)){var i=Wi(r);e=Gi(e),r=function(t){return i(o[t],t,o)}}var a=t(e,r,n);return a>-1?o[i?e[a]:a]:void 0}};var Hi=/\s/;var Ji=function(t){for(var e=t.length;e--&&Hi.test(t.charAt(e)););return e},Xi=/^\s+/;var Yi=function(t){return t?t.slice(0,Ji(t)+1).replace(Xi,""):t},Zi=x,ta=Ne,ea=/^[-+]0x[0-9a-f]+$/i,ra=/^0b[01]+$/i,na=/^0o[0-7]+$/i,oa=parseInt;var ia=function(t){if("number"==typeof t)return t;if(ta(t))return NaN;if(Zi(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Zi(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Yi(t);var r=ra.test(t);return r||na.test(t)?oa(t.slice(2),r?2:8):ea.test(t)?NaN:+t},aa=1/0;var sa=function(t){return t?(t=ia(t))===aa||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var ua=function(t,e,r,n){for(var o=t.length,i=r+(n?1:-1);n?i--:++i<o;)if(e(t[i],i,t))return i;return-1},ca=Pi,la=function(t){var e=sa(t),r=e%1;return e==e?r?e-r:e:0},ha=Math.max;var fa=u(Ki(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:la(r);return o<0&&(o=ha(n+o,0)),ua(t,ca(e),o)})),da=Fr;var pa=function(t,e){return da(e,function(e){return t[e]})},va=_e;var ba=u(function(t){return null==t?[]:pa(t,va(t))});class ga{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(t){this.destorySub=new e,this.messageSub=new e;const{specific:r,id:n}=t.project;this.socket=a(t.ws_url,Ae({autoConnect:!1},r&&void 0!==n?{query:{uuid:n}}:{}))}start(){const t="list",e="cloud",i="channel";r(this.socket,t).pipe(n(1),o(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),r(this.socket,e).pipe(o(this.destorySub)).subscribe(t=>{this.messageSub.next({event:e,data:t})}),r(this.socket,i).pipe(o(this.destorySub)).subscribe(t=>{this.messageSub.next({event:i,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()}}class ya{config;media;chat;destorySub;projectsSub;layoutSub;aiiaSubtitleSub;userSubtitleSub;cloudSampleRate;channelState;stateSub;isMuteAiia;get state(){return this.stateSub.asObservable()}get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}get aiiaSubtitle(){return this.aiiaSubtitleSub.asObservable()}get userSubtitle(){return this.userSubtitleSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(t,r){this.config=t,this.media=r,this.layoutSub=new e,this.projectsSub=new i(1),this.destorySub=new e,this.aiiaSubtitleSub=new e,this.userSubtitleSub=new e,this.stateSub=new i(1),this.cloudSampleRate={input:16e3,output:16e3},this.channelState={proxy:!1,cloud:!1},this.isMuteAiia=!1,this.chat=new ga(t),On.code(Sn["指定依賴已完成"],"chat"),this.close=this.onDestory,this.stateSub.next("NotStart")}start(){this.media.stateObs.pipe(o(this.destorySub)).subscribe(()=>{this.channelCheck()}),this.chat.message.pipe(o(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=fa(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):(this.projectsSub.next(e),On.code(Sn["請訂閱專案列表"]));break}case"channel":switch(e){case"open":this.channelState.proxy=!0,this.channelCheck();break;case"close":this.channelState.proxy=!1,this.media.stopRecord(),this.stateSub.next("CloseService");break;case"no_permissions":this.channelState.proxy=!1,this.stateSub.next("NoPermissions");break;case"reconnect":this.channelState.proxy=!1,this.stateSub.next("ReconnectingCloud")}}}),this.chat.start(),this.stateSub.next("ConnectingCloud"),On.code(Sn["啟動SDK"])}close;resetSession(){this.chat.sendToCloud({request:"reset"}),this.aiiaSubtitleSub.next(""),this.userSubtitleSub.next(""),this.media.stopAudio(),this.layoutSub.next({type:"resetLayout"})}chooseProject(t){this.chat.send("uuid",t)}mute(){this.isMuteAiia=!0,this.media.stopAudio(),this.media.stopRecord()}unmute(){this.isMuteAiia=!1,this.media.startRecord()}cloudToObj(t){try{const e=JSON.parse(t);void 0!==sn(e,"signal")?this.behavior(e):Ut(e)?Ui(e,this.behavior):Ui(ba(e),this.behavior)}catch(t){On.error("message transfer fail",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate.output=t.content;else switch(t.command){case"pcm":if(!this.isMuteAiia){const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),i=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),a=r-o,s=t[o],u=t[Math.min(o+1,t.length-1)];i[e]=s+(u-s)*a}return i}(kn(new Int16Array(t.content)),this.cloudSampleRate.output,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio()}break;case"interrupted":this.media.stopAudio(),this.aiiaSubtitleSub.next("")}break;case"status":"Connected"===sn(t,"content")&&(this.channelState.cloud=!0,this.channelCheck(),this.layoutSub.next({type:"resetLayout"}));break;case"agent":if(!this.isMuteAiia){const e=sn(t,"content.function_result.response");e&&this.aiiaSubtitleSub.next(e)}break;case"asr":if(!this.isMuteAiia&&"ASR"===sn(t,"content.function_type")){const e=sn(t,"content.function_result.result");e&&this.userSubtitleSub.next(e)}break;default:On.debug(t.signal)}}channelCheck(){const{proxy:t,cloud:e}=this.channelState;t&&e&&this.media.state===Rn.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.cloudSampleRate.input}),this.media.pcm.pipe(o(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:An(t)})}),this.media.startRecord(),this.stateSub.next("InService"),On.code(Sn["通道、雲端服務、麥克風都已就緒"])):t&&e&&this.media.state!==Rn.allowed&&(this.stateSub.next("InServiceNoMedia"),On.code(Sn["未取得媒體裝置權限,請重新設定或忽略此訊息"]))}onDestory(){this.chat.onDestory(),this.media.onDestory(),this.destorySub.next(),this.destorySub.complete(),this.stateSub.next("Destory"),this.stateSub.complete(),On.code(Sn["結束SDK"])}}function ma(t){if(un){!function(t){const{info:e,error:r,warn:n,debug:o,fatal:i,code:a}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);a||(wn.code=()=>{}),o||(wn.debug=()=>{}),e||(wn.info=()=>{}),n||(wn.warn=()=>{}),r||(wn.error=()=>{}),i||(wn.fatal=()=>{})}(sn(t,"debug",!0)),On.code(Sn["初始化必要依賴"]);const e=new cn(Ae({},t));On.code(Sn["指定依賴已完成"],"config");const r=new Nn(e.mediaStream);On.code(Sn["指定依賴已完成"],"config");const n=new ya(e,r);return On.code(Sn["指定依賴已完成"],"sdk"),""!==e.worklet_url&&r.init(e.worklet_url,{chunkTimeInSeconds:e.chunkTimeInSeconds,outputSampleRate:e.llmSampleRate}),n}throw new Error(on["環境錯誤(browser)"])}export{ma as initSdk};
1
+ import t from"moment";import{Subject as e,map as r,takeUntil as n,fromEvent as i,take as a,ReplaySubject as o,BehaviorSubject as s,debounceTime as u}from"rxjs";import{FilesetResolver as c,FaceDetector as l}from"@mediapipe/tasks-vision";import{io as h}from"socket.io-client";var d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function f(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var p="object"==typeof d&&d&&d.Object===Object&&d,b=p,v="object"==typeof self&&self&&self.Object===Object&&self,g=b||v||Function("return this")(),y=g.Symbol,m=y,_=Object.prototype,S=_.hasOwnProperty,w=_.toString,O=m?m.toStringTag:void 0;var C=function(t){var e=S.call(t,O),r=t[O];try{t[O]=void 0;var n=!0}catch(t){}var i=w.call(t);return n&&(e?t[O]=r:delete t[O]),i},j=Object.prototype.toString;var x=C,E=function(t){return j.call(t)},R=y?y.toStringTag:void 0;var D=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":R&&R in Object(t)?x(t):E(t)};var k=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},A=D,N=k;var M,I=function(t){if(!N(t))return!1;var e=A(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},T=g["__core-js_shared__"],z=(M=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||""))?"Symbol(src)_1."+M:"";var F=function(t){return!!z&&z in t},P=Function.prototype.toString;var B=function(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""},W=I,$=F,V=k,q=B,L=/^\[object .+?Constructor\]$/,Q=Function.prototype,U=Object.prototype,G=Q.toString,K=U.hasOwnProperty,H=RegExp("^"+G.call(K).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var J=function(t){return!(!V(t)||$(t))&&(W(t)?H:L).test(q(t))},X=function(t,e){return null==t?void 0:t[e]};var Y=function(t,e){var r=X(t,e);return J(r)?r:void 0},Z=Y,tt=function(){try{var t=Z(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),et=tt;var rt=function(t,e,r){"__proto__"==e&&et?et(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var nt=function(t,e){return t===e||t!=t&&e!=e},it=rt,at=nt,ot=Object.prototype.hasOwnProperty;var st=function(t,e,r){var n=t[e];ot.call(t,e)&&at(n,r)&&(void 0!==r||e in t)||it(t,e,r)},ut=st,ct=rt;var lt=function(t,e,r,n){var i=!r;r||(r={});for(var a=-1,o=e.length;++a<o;){var s=e[a],u=n?n(r[s],t[s],s,r,t):void 0;void 0===u&&(u=t[s]),i?ct(r,s,u):ut(r,s,u)}return r};var ht=function(t){return t};var dt=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)},ft=Math.max;var pt=function(t,e,r){return e=ft(void 0===e?t.length-1:e,0),function(){for(var n=arguments,i=-1,a=ft(n.length-e,0),o=Array(a);++i<a;)o[i]=n[e+i];i=-1;for(var s=Array(e+1);++i<e;)s[i]=n[i];return s[e]=r(o),dt(t,this,s)}};var bt=function(t){return function(){return t}},vt=tt,gt=vt?function(t,e){return vt(t,"toString",{configurable:!0,enumerable:!1,value:bt(e),writable:!0})}:ht,yt=Date.now;var mt=function(t){var e=0,r=0;return function(){var n=yt(),i=16-(n-r);if(r=n,i>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(gt),_t=ht,St=pt,wt=mt;var Ot=function(t,e){return wt(St(t,e,_t),t+"")};var Ct=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},jt=I,xt=Ct;var Et=function(t){return null!=t&&xt(t.length)&&!jt(t)},Rt=/^(?:0|[1-9]\d*)$/;var Dt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Rt.test(t))&&t>-1&&t%1==0&&t<e},kt=nt,At=Et,Nt=Dt,Mt=k;var It=function(t,e,r){if(!Mt(r))return!1;var n=typeof e;return!!("number"==n?At(r)&&Nt(e,r.length):"string"==n&&e in r)&&kt(r[e],t)},Tt=Ot,zt=It;var Ft=function(t){return Tt(function(e,r){var n=-1,i=r.length,a=i>1?r[i-1]:void 0,o=i>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(i--,a):void 0,o&&zt(r[0],r[1],o)&&(a=i<3?void 0:a,i=1),e=Object(e);++n<i;){var s=r[n];s&&t(e,s,n,a)}return e})},Pt=Object.prototype;var Bt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Pt)};var Wt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var $t=function(t){return null!=t&&"object"==typeof t},Vt=D,qt=$t;var Lt=function(t){return qt(t)&&"[object Arguments]"==Vt(t)},Qt=$t,Ut=Object.prototype,Gt=Ut.hasOwnProperty,Kt=Ut.propertyIsEnumerable,Ht=Lt(function(){return arguments}())?Lt:function(t){return Qt(t)&&Gt.call(t,"callee")&&!Kt.call(t,"callee")},Jt=Array.isArray,Xt=f(Jt),Yt={exports:{}};var Zt=function(){return!1};!function(t,e){var r=g,n=Zt,i=e&&!e.nodeType&&e,a=i&&t&&!t.nodeType&&t,o=a&&a.exports===i?r.Buffer:void 0,s=(o?o.isBuffer:void 0)||n;t.exports=s}(Yt,Yt.exports);var te=Yt.exports,ee=D,re=Ct,ne=$t,ie={};ie["[object Float32Array]"]=ie["[object Float64Array]"]=ie["[object Int8Array]"]=ie["[object Int16Array]"]=ie["[object Int32Array]"]=ie["[object Uint8Array]"]=ie["[object Uint8ClampedArray]"]=ie["[object Uint16Array]"]=ie["[object Uint32Array]"]=!0,ie["[object Arguments]"]=ie["[object Array]"]=ie["[object ArrayBuffer]"]=ie["[object Boolean]"]=ie["[object DataView]"]=ie["[object Date]"]=ie["[object Error]"]=ie["[object Function]"]=ie["[object Map]"]=ie["[object Number]"]=ie["[object Object]"]=ie["[object RegExp]"]=ie["[object Set]"]=ie["[object String]"]=ie["[object WeakMap]"]=!1;var ae=function(t){return ne(t)&&re(t.length)&&!!ie[ee(t)]};var oe=function(t){return function(e){return t(e)}},se={exports:{}};!function(t,e){var r=p,n=e&&!e.nodeType&&e,i=n&&t&&!t.nodeType&&t,a=i&&i.exports===n&&r.process,o=function(){try{var t=i&&i.require&&i.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=o}(se,se.exports);var ue=se.exports,ce=ae,le=oe,he=ue&&ue.isTypedArray,de=he?le(he):ce,fe=Wt,pe=Ht,be=Jt,ve=te,ge=Dt,ye=de,me=Object.prototype.hasOwnProperty;var _e=function(t,e){var r=be(t),n=!r&&pe(t),i=!r&&!n&&ve(t),a=!r&&!n&&!i&&ye(t),o=r||n||i||a,s=o?fe(t.length,String):[],u=s.length;for(var c in t)!e&&!me.call(t,c)||o&&("length"==c||i&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ge(c,u))||s.push(c);return s};var Se=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),we=Bt,Oe=Se,Ce=Object.prototype.hasOwnProperty;var je=_e,xe=function(t){if(!we(t))return Oe(t);var e=[];for(var r in Object(t))Ce.call(t,r)&&"constructor"!=r&&e.push(r);return e},Ee=Et;var Re=function(t){return Ee(t)?je(t):xe(t)},De=st,ke=lt,Ae=Ft,Ne=Et,Me=Bt,Ie=Re,Te=Object.prototype.hasOwnProperty,ze=f(Ae(function(t,e){if(Me(e)||Ne(e))ke(e,Ie(e),t);else for(var r in e)Te.call(e,r)&&De(t,r,e[r])})),Fe=D,Pe=$t;var Be=function(t){return"symbol"==typeof t||Pe(t)&&"[object Symbol]"==Fe(t)},We=Jt,$e=Be,Ve=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,qe=/^\w*$/;var Le=function(t,e){if(We(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!$e(t))||(qe.test(t)||!Ve.test(t)||null!=e&&t in Object(e))},Qe=Y(Object,"create"),Ue=Qe;var Ge=function(){this.__data__=Ue?Ue(null):{},this.size=0};var Ke=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},He=Qe,Je=Object.prototype.hasOwnProperty;var Xe=function(t){var e=this.__data__;if(He){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Je.call(e,t)?e[t]:void 0},Ye=Qe,Ze=Object.prototype.hasOwnProperty;var tr=Qe;var er=Ge,rr=Ke,nr=Xe,ir=function(t){var e=this.__data__;return Ye?void 0!==e[t]:Ze.call(e,t)},ar=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=tr&&void 0===e?"__lodash_hash_undefined__":e,this};function or(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])}}or.prototype.clear=er,or.prototype.delete=rr,or.prototype.get=nr,or.prototype.has=ir,or.prototype.set=ar;var sr=or;var ur=function(){this.__data__=[],this.size=0},cr=nt;var lr=function(t,e){for(var r=t.length;r--;)if(cr(t[r][0],e))return r;return-1},hr=lr,dr=Array.prototype.splice;var fr=lr;var pr=lr;var br=lr;var vr=ur,gr=function(t){var e=this.__data__,r=hr(e,t);return!(r<0)&&(r==e.length-1?e.pop():dr.call(e,r,1),--this.size,!0)},yr=function(t){var e=this.__data__,r=fr(e,t);return r<0?void 0:e[r][1]},mr=function(t){return pr(this.__data__,t)>-1},_r=function(t,e){var r=this.__data__,n=br(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Sr(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])}}Sr.prototype.clear=vr,Sr.prototype.delete=gr,Sr.prototype.get=yr,Sr.prototype.has=mr,Sr.prototype.set=_r;var wr=Sr,Or=Y(g,"Map"),Cr=sr,jr=wr,xr=Or;var Er=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Rr=function(t,e){var r=t.__data__;return Er(e)?r["string"==typeof e?"string":"hash"]:r.map},Dr=Rr;var kr=Rr;var Ar=Rr;var Nr=Rr;var Mr=function(){this.size=0,this.__data__={hash:new Cr,map:new(xr||jr),string:new Cr}},Ir=function(t){var e=Dr(this,t).delete(t);return this.size-=e?1:0,e},Tr=function(t){return kr(this,t).get(t)},zr=function(t){return Ar(this,t).has(t)},Fr=function(t,e){var r=Nr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,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=Mr,Pr.prototype.delete=Ir,Pr.prototype.get=Tr,Pr.prototype.has=zr,Pr.prototype.set=Fr;var Br=Pr,Wr=Br;function $r(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],a=r.cache;if(a.has(i))return a.get(i);var o=t.apply(this,n);return r.cache=a.set(i,o)||a,o};return r.cache=new($r.Cache||Wr),r}$r.Cache=Wr;var Vr=$r;var qr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Lr=/\\(\\)?/g,Qr=function(t){var e=Vr(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(qr,function(t,r,n,i){e.push(n?i.replace(Lr,"$1"):r||t)}),e});var Ur=function(t,e){for(var r=-1,n=null==t?0:t.length,i=Array(n);++r<n;)i[r]=e(t[r],r,t);return i},Gr=Ur,Kr=Jt,Hr=Be,Jr=y?y.prototype:void 0,Xr=Jr?Jr.toString:void 0;var Yr=function t(e){if("string"==typeof e)return e;if(Kr(e))return Gr(e,t)+"";if(Hr(e))return Xr?Xr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Zr=Yr;var tn=Jt,en=Le,rn=Qr,nn=function(t){return null==t?"":Zr(t)};var an=function(t,e){return tn(t)?t:en(t,e)?[t]:rn(nn(t))},on=Be;var sn=function(t){if("string"==typeof t||on(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},un=an,cn=sn;var ln=function(t,e){for(var r=0,n=(e=un(e,t)).length;null!=t&&r<n;)t=t[cn(e[r++])];return r&&r==n?t:void 0},hn=ln;var dn,fn=function(t,e,r){var n=null==t?void 0:hn(t,e);return void 0===n?r:n},pn=f(fn);!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: 2005"}(dn||(dn={}));const bn="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class vn{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}=ze({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:ze({},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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}get faceDetection(){return ze({frame:3,confidence:80},this.config.faceDetection)}get autoClearSubtitle(){const{user:t,aiia:e}=ze({},this.config.autoClearSubtitle);let r=3e3,n=3e3;return"number"==typeof t?r=t>=0?t:r:!1===t&&(r=NaN),"number"==typeof e?n=e>=0?e:n:!1===e&&(n=NaN),{userDelayTime:r,aiiaDelayTime:n}}constructor(t){this.config=t}}var gn=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var yn=function(t){return function(e,r,n){for(var i=-1,a=Object(e),o=n(e),s=o.length;s--;){var u=o[t?s:++i];if(!1===r(a[u],u,a))break}return e}}(),mn=Re;var _n=Et;var Sn=function(t,e){return function(r,n){if(null==r)return r;if(!_n(r))return t(r,n);for(var i=r.length,a=e?i:-1,o=Object(r);(e?a--:++a<i)&&!1!==n(o[a],a,o););return r}}(function(t,e){return t&&yn(t,e,mn)}),wn=ht;var On=gn,Cn=Sn,jn=function(t){return"function"==typeof t?t:wn},xn=Jt;var En,Rn=f(function(t,e){return(xn(t)?On:Cn)(t,jn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(En||(En={}));const Dn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},kn=[];const An=new Proxy(Dn,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const i=t().format("yyyy-MM-DD[T]HH:mm:ss");Rn(kn,t=>{t.next(r,i,...n)}),e[r](`[Aiia::${r}_${i}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});var Nn=function(t,e){for(var r=-1,n=null==t?0:t.length,i=0,a=[];++r<n;){var o=t[r];e(o,r,t)&&(a[i++]=o)}return a},Mn=Sn;var In=function(t,e){var r=[];return Mn(t,function(t,n,i){e(t,n,i)&&r.push(t)}),r},Tn=wr;var zn=wr,Fn=Or,Pn=Br;var Bn=wr,Wn=function(){this.__data__=new Tn,this.size=0},$n=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Vn=function(t){return this.__data__.get(t)},qn=function(t){return this.__data__.has(t)},Ln=function(t,e){var r=this.__data__;if(r instanceof zn){var n=r.__data__;if(!Fn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Pn(n)}return r.set(t,e),this.size=r.size,this};function Qn(t){var e=this.__data__=new Bn(t);this.size=e.size}Qn.prototype.clear=Wn,Qn.prototype.delete=$n,Qn.prototype.get=Vn,Qn.prototype.has=qn,Qn.prototype.set=Ln;var Un=Qn;var Gn=Br,Kn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Hn=function(t){return this.__data__.has(t)};function Jn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Gn;++e<r;)this.add(t[e])}Jn.prototype.add=Jn.prototype.push=Kn,Jn.prototype.has=Hn;var Xn=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};var Yn=Jn,Zn=Xn,ti=function(t,e){return t.has(e)};var ei=function(t,e,r,n,i,a){var o=1&r,s=t.length,u=e.length;if(s!=u&&!(o&&u>s))return!1;var c=a.get(t),l=a.get(e);if(c&&l)return c==e&&l==t;var h=-1,d=!0,f=2&r?new Yn:void 0;for(a.set(t,e),a.set(e,t);++h<s;){var p=t[h],b=e[h];if(n)var v=o?n(b,p,h,e,t,a):n(p,b,h,t,e,a);if(void 0!==v){if(v)continue;d=!1;break}if(f){if(!Zn(e,function(t,e){if(!ti(f,e)&&(p===t||i(p,t,r,n,a)))return f.push(e)})){d=!1;break}}else if(p!==b&&!i(p,b,r,n,a)){d=!1;break}}return a.delete(t),a.delete(e),d};var ri=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var ni=g.Uint8Array,ii=nt,ai=ei,oi=ri,si=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},ui=y?y.prototype:void 0,ci=ui?ui.valueOf:void 0;var li=function(t,e,r,n,i,a,o){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 ni(t),new ni(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return ii(+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 s=oi;case"[object Set]":var u=1&n;if(s||(s=si),t.size!=e.size&&!u)return!1;var c=o.get(t);if(c)return c==e;n|=2,o.set(t,e);var l=ai(s(t),s(e),n,i,a,o);return o.delete(t),l;case"[object Symbol]":if(ci)return ci.call(t)==ci.call(e)}return!1};var hi=function(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t},di=hi,fi=Jt;var pi=function(t,e,r){var n=e(t);return fi(t)?n:di(n,r(t))};var bi=Nn,vi=function(){return[]},gi=Object.prototype.propertyIsEnumerable,yi=Object.getOwnPropertySymbols,mi=pi,_i=yi?function(t){return null==t?[]:(t=Object(t),bi(yi(t),function(e){return gi.call(t,e)}))}:vi,Si=Re;var wi=function(t){return mi(t,Si,_i)},Oi=Object.prototype.hasOwnProperty;var Ci=function(t,e,r,n,i,a){var o=1&r,s=wi(t),u=s.length;if(u!=wi(e).length&&!o)return!1;for(var c=u;c--;){var l=s[c];if(!(o?l in e:Oi.call(e,l)))return!1}var h=a.get(t),d=a.get(e);if(h&&d)return h==e&&d==t;var f=!0;a.set(t,e),a.set(e,t);for(var p=o;++c<u;){var b=t[l=s[c]],v=e[l];if(n)var g=o?n(v,b,l,e,t,a):n(b,v,l,t,e,a);if(!(void 0===g?b===v||i(b,v,r,n,a):g)){f=!1;break}p||(p="constructor"==l)}if(f&&!p){var y=t.constructor,m=e.constructor;y==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof m&&m instanceof m||(f=!1)}return a.delete(t),a.delete(e),f},ji=Y(g,"DataView"),xi=Or,Ei=Y(g,"Promise"),Ri=Y(g,"Set"),Di=Y(g,"WeakMap"),ki=D,Ai=B,Ni="[object Map]",Mi="[object Promise]",Ii="[object Set]",Ti="[object WeakMap]",zi="[object DataView]",Fi=Ai(ji),Pi=Ai(xi),Bi=Ai(Ei),Wi=Ai(Ri),$i=Ai(Di),Vi=ki;(ji&&Vi(new ji(new ArrayBuffer(1)))!=zi||xi&&Vi(new xi)!=Ni||Ei&&Vi(Ei.resolve())!=Mi||Ri&&Vi(new Ri)!=Ii||Di&&Vi(new Di)!=Ti)&&(Vi=function(t){var e=ki(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ai(r):"";if(n)switch(n){case Fi:return zi;case Pi:return Ni;case Bi:return Mi;case Wi:return Ii;case $i:return Ti}return e});var qi=Un,Li=ei,Qi=li,Ui=Ci,Gi=Vi,Ki=Jt,Hi=te,Ji=de,Xi="[object Arguments]",Yi="[object Array]",Zi="[object Object]",ta=Object.prototype.hasOwnProperty;var ea=function(t,e,r,n,i,a){var o=Ki(t),s=Ki(e),u=o?Yi:Gi(t),c=s?Yi:Gi(e),l=(u=u==Xi?Zi:u)==Zi,h=(c=c==Xi?Zi:c)==Zi,d=u==c;if(d&&Hi(t)){if(!Hi(e))return!1;o=!0,l=!1}if(d&&!l)return a||(a=new qi),o||Ji(t)?Li(t,e,r,n,i,a):Qi(t,e,u,r,n,i,a);if(!(1&r)){var f=l&&ta.call(t,"__wrapped__"),p=h&&ta.call(e,"__wrapped__");if(f||p){var b=f?t.value():t,v=p?e.value():e;return a||(a=new qi),i(b,v,r,n,a)}}return!!d&&(a||(a=new qi),Ui(t,e,r,n,i,a))},ra=$t;var na=function t(e,r,n,i,a){return e===r||(null==e||null==r||!ra(e)&&!ra(r)?e!=e&&r!=r:ea(e,r,n,i,t,a))},ia=Un,aa=na;var oa=k;var sa=function(t){return t==t&&!oa(t)},ua=sa,ca=Re;var la=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},ha=function(t,e,r,n){var i=r.length,a=i,o=!n;if(null==t)return!a;for(t=Object(t);i--;){var s=r[i];if(o&&s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++i<a;){var u=(s=r[i])[0],c=t[u],l=s[1];if(o&&s[2]){if(void 0===c&&!(u in t))return!1}else{var h=new ia;if(n)var d=n(c,l,u,t,e,h);if(!(void 0===d?aa(l,c,3,n,h):d))return!1}}return!0},da=function(t){for(var e=ca(t),r=e.length;r--;){var n=e[r],i=t[n];e[r]=[n,i,ua(i)]}return e},fa=la;var pa=an,ba=Ht,va=Jt,ga=Dt,ya=Ct,ma=sn;var _a=function(t,e){return null!=t&&e in Object(t)},Sa=function(t,e,r){for(var n=-1,i=(e=pa(e,t)).length,a=!1;++n<i;){var o=ma(e[n]);if(!(a=null!=t&&r(t,o)))break;t=t[o]}return a||++n!=i?a:!!(i=null==t?0:t.length)&&ya(i)&&ga(o,i)&&(va(t)||ba(t))};var wa=na,Oa=fn,Ca=function(t,e){return null!=t&&Sa(t,e,_a)},ja=Le,xa=sa,Ea=la,Ra=sn;var Da=ln;var ka=function(t){return function(e){return null==e?void 0:e[t]}},Aa=function(t){return function(e){return Da(e,t)}},Na=Le,Ma=sn;var Ia=function(t){var e=da(t);return 1==e.length&&e[0][2]?fa(e[0][0],e[0][1]):function(r){return r===t||ha(r,t,e)}},Ta=function(t,e){return ja(t)&&xa(e)?Ea(Ra(t),e):function(r){var n=Oa(r,t);return void 0===n&&n===e?Ca(r,t):wa(e,n,3)}},za=ht,Fa=Jt,Pa=function(t){return Na(t)?ka(Ma(t)):Aa(t)};var Ba=function(t){return"function"==typeof t?t:null==t?za:"object"==typeof t?Fa(t)?Ta(t[0],t[1]):Ia(t):Pa(t)},Wa=Nn,$a=In,Va=Ba,qa=Jt;var La=f(function(t,e){return(qa(t)?Wa:$a)(t,Va(e))}),Qa=Sn;var Ua=Xn,Ga=Ba,Ka=function(t,e){var r;return Qa(t,function(t,n,i){return!(r=e(t,n,i))}),!!r},Ha=Jt,Ja=It;var Xa=f(function(t,e,r){var n=Ha(t)?Ua:Ka;return r&&Ja(t,e,r)&&(e=void 0),n(t,Ga(e))}),Ya=Sn,Za=Et;var to=function(t,e){var r=-1,n=Za(t)?Array(t.length):[];return Ya(t,function(t,i,a){n[++r]=e(t,i,a)}),n},eo=Ur,ro=Ba,no=to,io=Jt;var ao=f(function(t,e){return(io(t)?eo:no)(t,ro(e))});var oo=f(function(t){for(var e=-1,r=null==t?0:t.length,n=0,i=[];++e<r;){var a=t[e];a&&(i[n++]=a)}return i}),so=Ht,uo=Jt,co=y?y.isConcatSpreadable:void 0;var lo=hi,ho=function(t){return uo(t)||so(t)||!!(co&&t&&t[co])};var fo=function t(e,r,n,i,a){var o=-1,s=e.length;for(n||(n=ho),a||(a=[]);++o<s;){var u=e[o];r>0&&n(u)?r>1?t(u,r-1,n,i,a):lo(a,u):i||(a[a.length]=u)}return a};var po=Be;var bo=function(t,e){if(t!==e){var r=void 0!==t,n=null===t,i=t==t,a=po(t),o=void 0!==e,s=null===e,u=e==e,c=po(e);if(!s&&!c&&!a&&t>e||a&&o&&u&&!s&&!c||n&&o&&u||!r&&u||!i)return 1;if(!n&&!a&&!c&&t<e||c&&r&&i&&!n&&!a||s&&r&&i||!o&&i||!u)return-1}return 0};var vo=Ur,go=ln,yo=Ba,mo=to,_o=function(t,e){var r=t.length;for(t.sort(e);r--;)t[r]=t[r].value;return t},So=oe,wo=function(t,e,r){for(var n=-1,i=t.criteria,a=e.criteria,o=i.length,s=r.length;++n<o;){var u=bo(i[n],a[n]);if(u)return n>=s?u:u*("desc"==r[n]?-1:1)}return t.index-e.index},Oo=ht,Co=Jt;var jo,xo,Eo=fo,Ro=function(t,e,r){e=e.length?vo(e,function(t){return Co(t)?function(e){return go(e,1===t.length?t[0]:t)}:t}):[Oo];var n=-1;e=vo(e,So(yo));var i=mo(t,function(t,r,i){return{criteria:vo(e,function(e){return e(t)}),index:++n,value:t}});return _o(i,function(t,e){return wo(t,e,r)})},Do=It,ko=f(Ot(function(t,e){if(null==t)return[];var r=e.length;return r>1&&Do(t,e[0],e[1])?e=[]:r>2&&Do(e[0],e[1],e[2])&&(e=[e[0]]),Ro(t,Eo(e,1),[])}));function Ao(t,e,r){return Math.max(r,Math.min(t,e))}function No(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 Mo(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Ao(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"}(jo||(jo={}));class Io{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,i=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)i.copyToChannel(a,t);this.addBuffer(i)}addBufferByInt16(t,e=1){this.addBufferByFloat32(No(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{An.error("pause speech fail",t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{An.error("resume speech fail",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 To{stream;audioContext;type="vad";workletNode;source;isRecording=!1;outputSampleRate;chunkTimeInSeconds;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(t,r,n){this.stream=t,this.audioContext=r,this.outputSampleRate=n?.llmSampleRate??16e3,this.chunkTimeInSeconds=n?.chunkTimeInSeconds??1,this.pcmSub=new e}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad",{processorOptions:{outputSampleRate:this.outputSampleRate,chunkTimeInSeconds:this.chunkTimeInSeconds}}),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e}=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)}}class zo{type="camera";confidenceScore;aiiaCamera;get detections(){return this.aiiaCamera.detections}get faceResult(){const t=this.confidenceScore;return this.aiiaCamera.detections.pipe(r(e=>function(t,e){const r=La(t,t=>{const r=t.categories[0]?.score??0,n=t.keypoints,i=100*r>=e,a=Xa(n,t=>"leftEye"===t.label||"rightEye"===t.label);return i&&a});if(0===r.length)return null;const n=oo(ao(r,t=>{if(void 0!==t.boundingBox){const e=t.boundingBox,r=e.width*e.height,n=t.categories[0]?.score??0;return{...e,area:r,confidenceScore:100*n}}return null}));return ko(n,["area","confidenceScore"])[0]??null}(e,t)))}constructor(t,e,r){const{frame:n,confidence:i}=ze({frame:3,confidence:80},r);this.confidenceScore=i,this.aiiaCamera=new Fo,this.aiiaCamera.setAttribute("frequency",`${n}`),this.aiiaCamera.setStream(t),this.aiiaCamera.setFaceDetector(e),document.body.append(this.aiiaCamera)}startCapture(){this.aiiaCamera.startCapture()}stopCapture(){this.aiiaCamera.stopCapture()}onDestroy(){this.aiiaCamera.remove()}}class Fo extends HTMLElement{static get observedAttributes(){return["debug","frequency"]}_shadow;_containerEl;_styleEl;_videoEl;_isDebug;_debugElements;_analyzeInterval;_frameCount;_loopFrameID;_faceDetector;_detectionsSub;_isReady;get detections(){return this._detectionsSub.asObservable()}constructor(){super(),this._isDebug=!1,this._isReady=!1,this._shadow=this.attachShadow({mode:"open"}),this._containerEl=document.createElement("div"),this._videoEl=document.createElement("video"),this._styleEl=document.createElement("style"),this._debugElements=[],this._loopFrameID=null,this._analyzeInterval=3,this._frameCount=this._analyzeInterval,this._detectionsSub=new e,this.predictWebcam=this.predictWebcam.bind(this),this._settingContainer(),this._settingStyle(),this._settingVideo(),this._containerEl.appendChild(this._videoEl),this._shadow.appendChild(this._styleEl),this._shadow.appendChild(this._containerEl)}connectedCallback(){this.startCapture()}disconnectedCallback(){this.stopCapture()}attributeChangedCallback(t,e,r){switch(t){case"debug":this._isDebug=null!==r&&("true"===r||""===r),this._containerEl.style.visibility=this._isDebug?"visible":"hidden";break;case"frequency":{const t=Number(r);!isNaN(t)&&t>0&&(this._analyzeInterval=t,this._frameCount=this._analyzeInterval)}}}setStream(t){this._videoEl.srcObject=t,this._videoEl.onloadedmetadata=()=>{this._isReady=!0}}setFaceDetector(t){this._faceDetector=t}_settingStyle(){this._styleEl.textContent="\n .aiia_container {\n visibility: hidden;\n position: fixed;\n top: 0;\n left: 0;\n }\n .aiia_container .highlighter {\n background: rgba(0, 255, 0, 0.25);\n border: 1px dashed #fff;\n z-index: 1;\n position: absolute;\n }\n .aiia_container .confidence {\n position: absolute;\n padding-bottom: 5px;\n padding-top: 5px;\n background-color: #007f8b;\n color: #fff;\n border: 1px dashed rgba(255, 255, 255, 0.7);\n z-index: 2;\n font-size: 12px;\n margin: 0;\n }\n "}_settingContainer(){this._containerEl.classList.add("aiia_container")}_settingVideo(){this._videoEl.autoplay=!0,this._videoEl.playsInline=!0,this._videoEl.muted=!0}getVideo(){return this._videoEl}startCapture(){this._videoEl.play(),this._loopFrameID=window.requestAnimationFrame(this.predictWebcam)}stopCapture(){null!==this._loopFrameID&&(window.cancelAnimationFrame(this._loopFrameID),this._loopFrameID=null),this._videoEl.pause()}async predictWebcam(){if(this._loopFrameID=window.requestAnimationFrame(this.predictWebcam),void 0!==this._faceDetector&&this._isReady){if(this._frameCount===this._analyzeInterval){const t=this._faceDetector.detectForVideo(this._videoEl,performance.now()).detections;this._isDebug&&this._drawRect(t),this._detectionsSub.next(t),this._frameCount=0}this._frameCount++}}_drawRect(t){Rn(this._debugElements,t=>{t.style.display="none"}),Rn(t,(t,e)=>{const{categories:r,boundingBox:n}=t;if(n){let t=this._debugElements[2*e],i=this._debugElements[2*e+1];t&&i||(t=document.createElement("div"),t.classList.add("highlighter"),i=document.createElement("p"),i.classList.add("confidence"),this._containerEl.append(i,t),this._debugElements.push(t,i)),t.style.display="block",i.style.display="block";const a=100*r[0].score;i.innerText="Confidence: "+Math.round(a)+"% .",i.style.right=this._videoEl.offsetWidth-n.width-n.originX+"px",i.style.top=n.originY-30+"px",i.style.width=n.width-10+"px",t.style.right=this._videoEl.offsetWidth-n.width-n.originX+"px",t.style.top=`${n.originY}px`,t.style.width=n.width-10+"px",t.style.height=`${n.height}px`}});for(let e=2*t.length;e<this._debugElements.length;e++)this._debugElements[e].style.display="none"}destroy(){this._detectionsSub.complete(),this.remove()}}customElements.define("aiia-camera",Fo),function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(xo||(xo={}));class Po{stream;_state;stateSub;audioCtx;audioManager;vadManager;camManager;destory;pcmSub;faceResultSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get faceResult(){return this.faceResultSub.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(t){this.stream=t,this.stateSub=new e,this.pcmSub=new e,this.destory=new e,this.faceResultSub=new e,this.state=xo.padding}async init(t,e){const r=this.stream??await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0},video:!0});if(null===r)throw this.state=xo.rejected,new Error(dn["未獲得媒體裝置權限"]);this.stream=r,this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw An.fatal(t),this.state=xo.loadfail,new Error(dn["Worklet模組載入失敗"])}this.state=xo.allowed;const i=await async function(){const t=await c.forVisionTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm");return await l.createFromOptions(t,{baseOptions:{modelAssetPath:"https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite",delegate:"GPU"},runningMode:"VIDEO"})}();this.audioManager=new Io(this.audioCtx),this.vadManager=new To(r,this.audioCtx,e),this.vadManager.pcm.pipe(n(this.destory)).subscribe(t=>{this.pcmSub.next(t)}),this.camManager=new zo(r,i,e?.faceDetection),this.camManager.faceResult.pipe(n(this.destory)).subscribe(t=>{this.faceResultSub.next(t)})}addAudioQueue(t){const e=pn(t,"buffer",void 0),r=pn(t,"float32",void 0),n=pn(t,"int16",void 0),i=pn(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,i):n&&this.audioManager?.addBufferByInt16(n,i)}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}startCapture(){this.camManager?.startCapture()}stopCapture(){this.camManager?.stopCapture()}onDestroy(){this.camManager?.onDestroy(),this.audioCtx?.close(),this.destory.next(),this.destory.complete()}}var Bo=Ba,Wo=Et,$o=Re;var Vo=function(t){return function(e,r,n){var i=Object(e);if(!Wo(e)){var a=Bo(r);e=$o(e),r=function(t){return a(i[t],t,i)}}var o=t(e,r,n);return o>-1?i[a?e[o]:o]:void 0}};var qo=/\s/;var Lo=function(t){for(var e=t.length;e--&&qo.test(t.charAt(e)););return e},Qo=/^\s+/;var Uo=function(t){return t?t.slice(0,Lo(t)+1).replace(Qo,""):t},Go=k,Ko=Be,Ho=/^[-+]0x[0-9a-f]+$/i,Jo=/^0b[01]+$/i,Xo=/^0o[0-7]+$/i,Yo=parseInt;var Zo=function(t){if("number"==typeof t)return t;if(Ko(t))return NaN;if(Go(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Go(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Uo(t);var r=Jo.test(t);return r||Xo.test(t)?Yo(t.slice(2),r?2:8):Ho.test(t)?NaN:+t},ts=1/0;var es=function(t){return t?(t=Zo(t))===ts||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var rs=function(t,e,r,n){for(var i=t.length,a=r+(n?1:-1);n?a--:++a<i;)if(e(t[a],a,t))return a;return-1},ns=Ba,is=function(t){var e=es(t),r=e%1;return e==e?r?e-r:e:0},as=Math.max;var os=f(Vo(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var i=null==r?0:is(r);return i<0&&(i=as(n+i,0)),rs(t,ns(e),i)})),ss=Ur;var us=function(t,e){return ss(e,function(e){return t[e]})},cs=Re;var ls=f(function(t){return null==t?[]:us(t,cs(t))});class hs{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(t){this.destorySub=new e,this.messageSub=new e;const{specific:r,id:n}=t.project;this.socket=h(t.ws_url,ze({autoConnect:!1},r&&void 0!==n?{query:{uuid:n}}:{}))}start(){const t="list",e="cloud",r="channel";i(this.socket,t).pipe(a(1),n(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),i(this.socket,e).pipe(n(this.destorySub)).subscribe(t=>{this.messageSub.next({event:e,data:t})}),i(this.socket,r).pipe(n(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestroy(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}class ds{config;media;chat;destorySub;projectsSub;layoutSub;aiiaSubtitleSub;userSubtitleSub;sampleRateOfWhisper;channelState;stateSub;isMuteAiia;aiiaSubtitleClearSub;userSubtitleClearSub;get state(){return this.stateSub.asObservable()}get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}get aiiaSubtitle(){return this.aiiaSubtitleSub.asObservable()}get userSubtitle(){return this.userSubtitleSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(t,r){this.config=t,this.media=r,this.layoutSub=new e,this.projectsSub=new o(1),this.destorySub=new e,this.aiiaSubtitleSub=new e,this.userSubtitleSub=new e,this.aiiaSubtitleClearSub=new e,this.userSubtitleClearSub=new e,this.stateSub=new s("NotStart"),this.sampleRateOfWhisper={input:t.llmSampleRate,output:16e3},this.channelState={proxy:!1,cloud:!1},this.isMuteAiia=!1,this.chat=new hs(t),An.code(En["指定依賴已完成"],"chat"),this.close=this.onDestroy,this.behavior=this.behavior.bind(this),this.cloudToObj=this.cloudToObj.bind(this);const{userDelayTime:i,aiiaDelayTime:a}=t.autoClearSubtitle;isNaN(a)||this.aiiaSubtitleClearSub.pipe(u(a),n(this.destorySub)).subscribe(()=>{this.aiiaSubtitleSub.next("")}),isNaN(i)||this.userSubtitleClearSub.pipe(u(i),n(this.destorySub)).subscribe(()=>{this.userSubtitleSub.next("")})}start(){this.media.stateObs.pipe(n(this.destorySub)).subscribe(()=>{this.channelCheck()}),this.chat.message.pipe(n(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 i=null;if(n&&void 0!==t)i=t;else{const n=os(e,e=>e.name===r||e.id===t);n&&(i=n.id)}null!==i?this.chooseProject(i):(this.projectsSub.next(e),this.stateSub.next("WattingProjectID"),An.code(En["請訂閱專案列表"]));break}case"channel":switch(e){case"open":this.channelState.proxy=!0,this.channelCheck();break;case"close":this.channelState.proxy=!1,this.media.stopRecord(),this.stateSub.next("CloseService");break;case"no_permissions":this.channelState.proxy=!1,this.stateSub.next("NoPermissions");break;case"reconnect":this.channelState.proxy=!1,this.stateSub.next("ReconnectingCloud")}}}),this.chat.start(),this.stateSub.next("ConnectingCloud"),An.code(En["啟動SDK"])}close;resetSession(){this.chat.sendToCloud({request:"reset"}),this.aiiaSubtitleSub.next(""),this.userSubtitleSub.next(""),this.media.stopAudio(),this.layoutSub.next({type:"resetLayout"})}chooseProject(t){this.chat.send("uuid",t),this.stateSub.next("ConnectingCloud")}mute(){this.isMuteAiia=!0,this.media.stopAudio(),this.media.stopRecord()}unmute(){this.isMuteAiia=!1,this.media.startRecord()}cloudToObj(t){try{const e=JSON.parse(t);void 0!==pn(e,"signal")?this.behavior(e):Xt(e)?ao(e,this.behavior):ao(ls(e),this.behavior)}catch(t){An.error("message transfer fail",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.sampleRateOfWhisper.output=t.content;else switch(t.command){case"pcm":if(!this.isMuteAiia){const e=function(t,e,r){if(e===r)return t;const n=r/e,i=Math.ceil(t.length*n),a=new Float32Array(i);for(let e=0;e<i;e++){const r=e/n,i=Math.floor(r),o=r-i,s=t[i],u=t[Math.min(i+1,t.length-1)];a[e]=s+(u-s)*o}return a}(No(new Int16Array(t.content)),this.sampleRateOfWhisper.output,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio()}break;case"interrupted":this.media.stopAudio(),this.aiiaSubtitleSub.next("")}break;case"status":"Connected"===pn(t,"content")&&(this.channelState.cloud=!0,this.channelCheck(),this.layoutSub.next({type:"resetLayout"}));break;case"agent":if(!this.isMuteAiia){const e=pn(t,"content.function_result.response");void 0!==e&&(this.aiiaSubtitleSub.next(e),this.aiiaSubtitleClearSub.next())}break;case"asr":if(!this.isMuteAiia&&"ASR"===pn(t,"content.function_type")){const e=pn(t,"content.function_result.result");void 0!==e&&(this.userSubtitleSub.next(e),this.userSubtitleClearSub.next())}break;default:An.debug(t.signal)}}channelCheck(){const{proxy:t,cloud:e}=this.channelState;t&&e&&this.media.state===xo.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.sampleRateOfWhisper.input}),this.media.pcm.pipe(n(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Mo(t)})}),this.media.faceResult.pipe(n(this.destorySub)).subscribe(t=>{this.chat.send("face",t)}),this.media.startRecord(),this.media.startCapture(),this.stateSub.next("InService"),An.code(En["通道、雲端服務、麥克風都已就緒"])):t&&e&&this.media.state!==xo.allowed&&(this.stateSub.next("InServiceNoMedia"),An.code(En["未取得媒體裝置權限,請重新設定或忽略此訊息"]))}onDestroy(){this.chat.onDestroy(),this.media.onDestroy(),this.destorySub.next(),this.destorySub.complete(),this.stateSub.next("Destroy"),this.stateSub.complete(),An.code(En["結束SDK"])}}function fs(t){if(bn){!function(t){const{info:e,error:r,warn:n,debug:i,fatal:a,code:o}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);o||(Dn.code=()=>{}),i||(Dn.debug=()=>{}),e||(Dn.info=()=>{}),n||(Dn.warn=()=>{}),r||(Dn.error=()=>{}),a||(Dn.fatal=()=>{})}(pn(t,"debug",!0)),An.code(En["初始化必要依賴"]);const e=new vn(ze({},t));An.code(En["指定依賴已完成"],"config");const r=new Po(e.mediaStream);An.code(En["指定依賴已完成"],"config");const n=new ds(e,r);return An.code(En["指定依賴已完成"],"sdk"),""!==e.worklet_url&&r.init(e.worklet_url,e),n}throw new Error(dn["環境錯誤(browser)"])}export{fs as initSdk};
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("moment"),e=require("socket.io"),r=require("rxjs"),n=require("axios"),o=require("ws"),i=require("fs"),a=require("os"),c=require("path"),s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var f="object"==typeof s&&s&&s.Object===Object&&s,l=f,h="object"==typeof self&&self&&self.Object===Object&&self,v=l||h||Function("return this")(),p=v.Symbol,b=p,d=Object.prototype,y=d.hasOwnProperty,_=d.toString,g=b?b.toStringTag:void 0;var O=function(t){var e=y.call(t,g),r=t[g];try{t[g]=void 0;var n=!0}catch(t){}var o=_.call(t);return n&&(e?t[g]=r:delete t[g]),o},j=Object.prototype.toString;var S=O,w=function(t){return j.call(t)},m=p?p.toStringTag:void 0;var E=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m in Object(t)?S(t):w(t)};var A=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},D=E,N=A;var R,k=function(t){if(!N(t))return!1;var e=D(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},M=v["__core-js_shared__"],C=(R=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"";var P=function(t){return!!C&&C in t},I=Function.prototype.toString;var L=function(t){if(null!=t){try{return I.call(t)}catch(t){}try{return t+""}catch(t){}}return""},T=k,x=P,U=A,F=L,$=/^\[object .+?Constructor\]$/,W=Function.prototype,z=Object.prototype,G=W.toString,B=z.hasOwnProperty,V=RegExp("^"+G.call(B).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var X=function(t){return!(!U(t)||x(t))&&(T(t)?V:$).test(F(t))},Y=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=Y(t,e);return X(r)?r:void 0},H=q,K=function(){try{var t=H(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Q=K;var J=function(t,e,r){"__proto__"==e&&Q?Q(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var Z=function(t,e){return t===e||t!=t&&e!=e},tt=J,et=Z,rt=Object.prototype.hasOwnProperty;var nt=function(t,e,r){var n=t[e];rt.call(t,e)&&et(n,r)&&(void 0!==r||e in t)||tt(t,e,r)},ot=nt,it=J;var at=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var c=e[i],s=n?n(r[c],t[c],c,r,t):void 0;void 0===s&&(s=t[c]),o?it(r,c,s):ot(r,c,s)}return r};var ct=function(t){return t};var st=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)},ut=Math.max;var ft=function(t,e,r){return e=ut(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=ut(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(a),st(t,this,c)}};var lt=function(t){return function(){return t}},ht=K,vt=ht?function(t,e){return ht(t,"toString",{configurable:!0,enumerable:!1,value:lt(e),writable:!0})}:ct,pt=Date.now;var bt=function(t){var e=0,r=0;return function(){var n=pt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(vt),dt=ct,yt=ft,_t=bt;var gt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},Ot=k,jt=gt;var St=function(t){return null!=t&&jt(t.length)&&!Ot(t)},wt=/^(?:0|[1-9]\d*)$/;var mt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&wt.test(t))&&t>-1&&t%1==0&&t<e},Et=Z,At=St,Dt=mt,Nt=A;var Rt=function(t,e){return _t(yt(t,e,dt),t+"")},kt=function(t,e,r){if(!Nt(r))return!1;var n=typeof e;return!!("number"==n?At(r)&&Dt(e,r.length):"string"==n&&e in r)&&Et(r[e],t)};var Mt=function(t){return Rt(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,a&&kt(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var c=r[n];c&&t(e,c,n,i)}return e})},Ct=Object.prototype;var Pt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ct)};var It=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Lt=function(t){return null!=t&&"object"==typeof t},Tt=E,xt=Lt;var Ut=function(t){return xt(t)&&"[object Arguments]"==Tt(t)},Ft=Lt,$t=Object.prototype,Wt=$t.hasOwnProperty,zt=$t.propertyIsEnumerable,Gt=Ut(function(){return arguments}())?Ut:function(t){return Ft(t)&&Wt.call(t,"callee")&&!zt.call(t,"callee")},Bt=Array.isArray,Vt=u(Bt),Xt={exports:{}};var Yt=function(){return!1};!function(t,e){var r=v,n=Yt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,c=(a?a.isBuffer:void 0)||n;t.exports=c}(Xt,Xt.exports);var qt=Xt.exports,Ht=E,Kt=gt,Qt=Lt,Jt={};Jt["[object Float32Array]"]=Jt["[object Float64Array]"]=Jt["[object Int8Array]"]=Jt["[object Int16Array]"]=Jt["[object Int32Array]"]=Jt["[object Uint8Array]"]=Jt["[object Uint8ClampedArray]"]=Jt["[object Uint16Array]"]=Jt["[object Uint32Array]"]=!0,Jt["[object Arguments]"]=Jt["[object Array]"]=Jt["[object ArrayBuffer]"]=Jt["[object Boolean]"]=Jt["[object DataView]"]=Jt["[object Date]"]=Jt["[object Error]"]=Jt["[object Function]"]=Jt["[object Map]"]=Jt["[object Number]"]=Jt["[object Object]"]=Jt["[object RegExp]"]=Jt["[object Set]"]=Jt["[object String]"]=Jt["[object WeakMap]"]=!1;var Zt=function(t){return Qt(t)&&Kt(t.length)&&!!Jt[Ht(t)]};var te=function(t){return function(e){return t(e)}},ee={exports:{}};!function(t,e){var r=f,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n&&r.process,a=function(){try{var t=o&&o.require&&o.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=a}(ee,ee.exports);var re=ee.exports,ne=Zt,oe=te,ie=re&&re.isTypedArray,ae=ie?oe(ie):ne,ce=It,se=Gt,ue=Bt,fe=qt,le=mt,he=ae,ve=Object.prototype.hasOwnProperty;var pe=function(t,e){var r=ue(t),n=!r&&se(t),o=!r&&!n&&fe(t),i=!r&&!n&&!o&&he(t),a=r||n||o||i,c=a?ce(t.length,String):[],s=c.length;for(var u in t)!e&&!ve.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||le(u,s))||c.push(u);return c};var be=function(t,e){return function(r){return t(e(r))}},de=be(Object.keys,Object),ye=Pt,_e=de,ge=Object.prototype.hasOwnProperty;var Oe=pe,je=function(t){if(!ye(t))return _e(t);var e=[];for(var r in Object(t))ge.call(t,r)&&"constructor"!=r&&e.push(r);return e},Se=St;var we=function(t){return Se(t)?Oe(t):je(t)},me=nt,Ee=at,Ae=Mt,De=St,Ne=Pt,Re=we,ke=Object.prototype.hasOwnProperty,Me=u(Ae(function(t,e){if(Ne(e)||De(e))Ee(e,Re(e),t);else for(var r in e)ke.call(e,r)&&me(t,r,e[r])})),Ce=E,Pe=Lt;var Ie=function(t){return"symbol"==typeof t||Pe(t)&&"[object Symbol]"==Ce(t)},Le=Bt,Te=Ie,xe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ue=/^\w*$/;var Fe=function(t,e){if(Le(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Te(t))||(Ue.test(t)||!xe.test(t)||null!=e&&t in Object(e))},$e=q(Object,"create"),We=$e;var ze=function(){this.__data__=We?We(null):{},this.size=0};var Ge=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Be=$e,Ve=Object.prototype.hasOwnProperty;var Xe=function(t){var e=this.__data__;if(Be){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Ve.call(e,t)?e[t]:void 0},Ye=$e,qe=Object.prototype.hasOwnProperty;var He=$e;var Ke=ze,Qe=Ge,Je=Xe,Ze=function(t){var e=this.__data__;return Ye?void 0!==e[t]:qe.call(e,t)},tr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=He&&void 0===e?"__lodash_hash_undefined__":e,this};function er(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])}}er.prototype.clear=Ke,er.prototype.delete=Qe,er.prototype.get=Je,er.prototype.has=Ze,er.prototype.set=tr;var rr=er;var nr=function(){this.__data__=[],this.size=0},or=Z;var ir=function(t,e){for(var r=t.length;r--;)if(or(t[r][0],e))return r;return-1},ar=ir,cr=Array.prototype.splice;var sr=ir;var ur=ir;var fr=ir;var lr=nr,hr=function(t){var e=this.__data__,r=ar(e,t);return!(r<0)&&(r==e.length-1?e.pop():cr.call(e,r,1),--this.size,!0)},vr=function(t){var e=this.__data__,r=sr(e,t);return r<0?void 0:e[r][1]},pr=function(t){return ur(this.__data__,t)>-1},br=function(t,e){var r=this.__data__,n=fr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function dr(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])}}dr.prototype.clear=lr,dr.prototype.delete=hr,dr.prototype.get=vr,dr.prototype.has=pr,dr.prototype.set=br;var yr=dr,_r=q(v,"Map"),gr=rr,Or=yr,jr=_r;var Sr=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var wr=function(t,e){var r=t.__data__;return Sr(e)?r["string"==typeof e?"string":"hash"]:r.map},mr=wr;var Er=wr;var Ar=wr;var Dr=wr;var Nr=function(){this.size=0,this.__data__={hash:new gr,map:new(jr||Or),string:new gr}},Rr=function(t){var e=mr(this,t).delete(t);return this.size-=e?1:0,e},kr=function(t){return Er(this,t).get(t)},Mr=function(t){return Ar(this,t).has(t)},Cr=function(t,e){var r=Dr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,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=Rr,Pr.prototype.get=kr,Pr.prototype.has=Mr,Pr.prototype.set=Cr;var Ir=Pr,Lr=Ir;function Tr(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],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Tr.Cache||Lr),r}Tr.Cache=Lr;var xr=Tr;var Ur=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Fr=/\\(\\)?/g,$r=function(t){var e=xr(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(Ur,function(t,r,n,o){e.push(n?o.replace(Fr,"$1"):r||t)}),e});var Wr=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},zr=Wr,Gr=Bt,Br=Ie,Vr=p?p.prototype:void 0,Xr=Vr?Vr.toString:void 0;var Yr=function t(e){if("string"==typeof e)return e;if(Gr(e))return zr(e,t)+"";if(Br(e))return Xr?Xr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},qr=Yr;var Hr=Bt,Kr=Fe,Qr=$r,Jr=function(t){return null==t?"":qr(t)};var Zr=function(t,e){return Hr(t)?t:Kr(t,e)?[t]:Qr(Jr(t))},tn=Ie;var en=function(t){if("string"==typeof t||tn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},rn=Zr,nn=en;var on=function(t,e){for(var r=0,n=(e=rn(e,t)).length;null!=t&&r<n;)t=t[nn(e[r++])];return r&&r==n?t:void 0},an=on;var cn,sn=function(t,e,r){var n=null==t?void 0:an(t,e);return void 0===n?r:n},un=u(sn);!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: 2005"}(cn||(cn={}));const fn="access_token",ln="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class hn{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}=Me({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Me({},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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}constructor(t){this.config=t}}var vn=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var pn=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),c=a.length;c--;){var s=a[t?c:++o];if(!1===r(i[s],s,i))break}return e}}(),bn=we;var dn=St;var yn=function(t,e){return function(r,n){if(null==r)return r;if(!dn(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(t,e){return t&&pn(t,e,bn)}),_n=ct;var gn=vn,On=yn,jn=function(t){return"function"==typeof t?t:_n},Sn=Bt;var wn,mn=u(function(t,e){return(Sn(t)?gn:On)(t,jn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(wn||(wn={}));const En={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},An=[];function Dn(t){return An.push(t),Dn}const Nn=new Proxy(En,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const o=t().format("yyyy-MM-DD[T]HH:mm:ss");mn(An,t=>{t.next(r,o,...n)}),e[r](`[Aiia::${r}_${o}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});class Rn{config;server;memberSub;get port(){return this.config.port}get webserver(){return this.config.webserver}get memberChange(){return this.memberSub.asObservable()}constructor(t){this.config=t,this.memberSub=new r.Subject}start(){this.server=new e.Server(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{this.memberSub.next({type:"in",socket:t}),Nn.debug("client on",t.id),t.on("disconnect",e=>{this.memberSub.next({type:"out",socket:t}),Nn.debug("client off",e)})}),void 0===this.webserver&&this.server.listen(this.port)}onDestory(){this.server&&this.server.close()}}var kn=yr;var Mn=yr,Cn=_r,Pn=Ir;var In=yr,Ln=function(){this.__data__=new kn,this.size=0},Tn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},xn=function(t){return this.__data__.get(t)},Un=function(t){return this.__data__.has(t)},Fn=function(t,e){var r=this.__data__;if(r instanceof Mn){var n=r.__data__;if(!Cn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Pn(n)}return r.set(t,e),this.size=r.size,this};function $n(t){var e=this.__data__=new In(t);this.size=e.size}$n.prototype.clear=Ln,$n.prototype.delete=Tn,$n.prototype.get=xn,$n.prototype.has=Un,$n.prototype.set=Fn;var Wn=$n;var zn=Ir,Gn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Bn=function(t){return this.__data__.has(t)};function Vn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new zn;++e<r;)this.add(t[e])}Vn.prototype.add=Vn.prototype.push=Gn,Vn.prototype.has=Bn;var Xn=Vn,Yn=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},qn=function(t,e){return t.has(e)};var Hn=function(t,e,r,n,o,i){var a=1&r,c=t.length,s=e.length;if(c!=s&&!(a&&s>c))return!1;var u=i.get(t),f=i.get(e);if(u&&f)return u==e&&f==t;var l=-1,h=!0,v=2&r?new Xn:void 0;for(i.set(t,e),i.set(e,t);++l<c;){var p=t[l],b=e[l];if(n)var d=a?n(b,p,l,e,t,i):n(p,b,l,t,e,i);if(void 0!==d){if(d)continue;h=!1;break}if(v){if(!Yn(e,function(t,e){if(!qn(v,e)&&(p===t||o(p,t,r,n,i)))return v.push(e)})){h=!1;break}}else if(p!==b&&!o(p,b,r,n,i)){h=!1;break}}return i.delete(t),i.delete(e),h},Kn=v.Uint8Array;var Qn=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var Jn=Kn,Zn=Z,to=Hn,eo=Qn,ro=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},no=p?p.prototype:void 0,oo=no?no.valueOf:void 0;var io=function(t,e,r,n,o,i,a){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||!i(new Jn(t),new Jn(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Zn(+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 c=eo;case"[object Set]":var s=1&n;if(c||(c=ro),t.size!=e.size&&!s)return!1;var u=a.get(t);if(u)return u==e;n|=2,a.set(t,e);var f=to(c(t),c(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(oo)return oo.call(t)==oo.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},co=ao,so=Bt;var uo=function(t,e,r){var n=e(t);return so(t)?n:co(n,r(t))};var fo=function(){return[]},lo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i},ho=fo,vo=Object.prototype.propertyIsEnumerable,po=Object.getOwnPropertySymbols,bo=po?function(t){return null==t?[]:(t=Object(t),lo(po(t),function(e){return vo.call(t,e)}))}:ho,yo=uo,_o=bo,go=we;var Oo=function(t){return yo(t,go,_o)},jo=Oo,So=Object.prototype.hasOwnProperty;var wo=function(t,e,r,n,o,i){var a=1&r,c=jo(t),s=c.length;if(s!=jo(e).length&&!a)return!1;for(var u=s;u--;){var f=c[u];if(!(a?f in e:So.call(e,f)))return!1}var l=i.get(t),h=i.get(e);if(l&&h)return l==e&&h==t;var v=!0;i.set(t,e),i.set(e,t);for(var p=a;++u<s;){var b=t[f=c[u]],d=e[f];if(n)var y=a?n(d,b,f,e,t,i):n(b,d,f,t,e,i);if(!(void 0===y?b===d||o(b,d,r,n,i):y)){v=!1;break}p||(p="constructor"==f)}if(v&&!p){var _=t.constructor,g=e.constructor;_==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(v=!1)}return i.delete(t),i.delete(e),v},mo=q(v,"DataView"),Eo=_r,Ao=q(v,"Promise"),Do=q(v,"Set"),No=q(v,"WeakMap"),Ro=E,ko=L,Mo="[object Map]",Co="[object Promise]",Po="[object Set]",Io="[object WeakMap]",Lo="[object DataView]",To=ko(mo),xo=ko(Eo),Uo=ko(Ao),Fo=ko(Do),$o=ko(No),Wo=Ro;(mo&&Wo(new mo(new ArrayBuffer(1)))!=Lo||Eo&&Wo(new Eo)!=Mo||Ao&&Wo(Ao.resolve())!=Co||Do&&Wo(new Do)!=Po||No&&Wo(new No)!=Io)&&(Wo=function(t){var e=Ro(t),r="[object Object]"==e?t.constructor:void 0,n=r?ko(r):"";if(n)switch(n){case To:return Lo;case xo:return Mo;case Uo:return Co;case Fo:return Po;case $o:return Io}return e});var zo=Wo,Go=Wn,Bo=Hn,Vo=io,Xo=wo,Yo=zo,qo=Bt,Ho=qt,Ko=ae,Qo="[object Arguments]",Jo="[object Array]",Zo="[object Object]",ti=Object.prototype.hasOwnProperty;var ei=function(t,e,r,n,o,i){var a=qo(t),c=qo(e),s=a?Jo:Yo(t),u=c?Jo:Yo(e),f=(s=s==Qo?Zo:s)==Zo,l=(u=u==Qo?Zo:u)==Zo,h=s==u;if(h&&Ho(t)){if(!Ho(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Go),a||Ko(t)?Bo(t,e,r,n,o,i):Vo(t,e,s,r,n,o,i);if(!(1&r)){var v=f&&ti.call(t,"__wrapped__"),p=l&&ti.call(e,"__wrapped__");if(v||p){var b=v?t.value():t,d=p?e.value():e;return i||(i=new Go),o(b,d,r,n,i)}}return!!h&&(i||(i=new Go),Xo(t,e,r,n,o,i))},ri=Lt;var ni=function t(e,r,n,o,i){return e===r||(null==e||null==r||!ri(e)&&!ri(r)?e!=e&&r!=r:ei(e,r,n,o,t,i))},oi=Wn,ii=ni;var ai=A;var ci=function(t){return t==t&&!ai(t)},si=ci,ui=we;var fi=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},li=function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var c=r[o];if(a&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<i;){var s=(c=r[o])[0],u=t[s],f=c[1];if(a&&c[2]){if(void 0===u&&!(s in t))return!1}else{var l=new oi;if(n)var h=n(u,f,s,t,e,l);if(!(void 0===h?ii(f,u,3,n,l):h))return!1}}return!0},hi=function(t){for(var e=ui(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,si(o)]}return e},vi=fi;var pi=Zr,bi=Gt,di=Bt,yi=mt,_i=gt,gi=en;var Oi=function(t,e,r){for(var n=-1,o=(e=pi(e,t)).length,i=!1;++n<o;){var a=gi(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&_i(o)&&yi(a,o)&&(di(t)||bi(t))},ji=function(t,e){return null!=t&&e in Object(t)},Si=Oi;var wi=function(t,e){return null!=t&&Si(t,e,ji)},mi=ni,Ei=sn,Ai=wi,Di=Fe,Ni=ci,Ri=fi,ki=en;var Mi=function(t,e){return Di(t)&&Ni(e)?Ri(ki(t),e):function(r){var n=Ei(r,t);return void 0===n&&n===e?Ai(r,t):mi(e,n,3)}};var Ci=on;var Pi=function(t){return function(e){return Ci(e,t)}},Ii=function(t){return function(e){return null==e?void 0:e[t]}},Li=Pi,Ti=Fe,xi=en;var Ui=function(t){return Ti(t)?Ii(xi(t)):Li(t)},Fi=function(t){var e=hi(t);return 1==e.length&&e[0][2]?vi(e[0][0],e[0][1]):function(r){return r===t||li(r,t,e)}},$i=Mi,Wi=ct,zi=Bt,Gi=Ui;var Bi=yn,Vi=St;var Xi=Wr,Yi=function(t){return"function"==typeof t?t:null==t?Wi:"object"==typeof t?zi(t)?$i(t[0],t[1]):Fi(t):Gi(t)},qi=function(t,e){var r=-1,n=Vi(t)?Array(t.length):[];return Bi(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Hi=Bt;var Ki,Qi=u(function(t,e){return(Hi(t)?Xi:qi)(t,Yi(e))});class Ji{instance;controller;constructor(t){this.controller=new AbortController,this.instance=n.create({baseURL:t,signal:this.controller.signal})}async getAccessToken(t,e){const r={license_number:t,token_value:e??""},n=await this.instance.post("/api/v1/license/agent_token",r).then(t=>un(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(cn["網絡錯誤"]);if(""===n)throw new Error(cn["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>Qi(un(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(cn["網絡錯誤"]);if(0===e.length)throw new Error(cn["沒有可用專案"]);return e}onDestory(){this.controller.abort()}}!function(t){t[t.MDN_NORMAL_CLOSURE=1e3]="MDN_NORMAL_CLOSURE",t[t.MDN_GOING_AWAY=1001]="MDN_GOING_AWAY",t[t.MDN_PROTOCOL_ERROR=1002]="MDN_PROTOCOL_ERROR",t[t.MDN_UNSUPPORTED_DATA=1003]="MDN_UNSUPPORTED_DATA",t[t.MDN_RESERVED_1004=1004]="MDN_RESERVED_1004",t[t.MDN_NO_STATUS_RECEIVED=1005]="MDN_NO_STATUS_RECEIVED",t[t.MDN_ABNORMAL_CLOSURE=1006]="MDN_ABNORMAL_CLOSURE",t[t.MDN_INVALID_FRAME_PAYLOAD=1007]="MDN_INVALID_FRAME_PAYLOAD",t[t.MDN_POLICY_VIOLATION=1008]="MDN_POLICY_VIOLATION",t[t.MDN_MESSAGE_TOO_BIG=1009]="MDN_MESSAGE_TOO_BIG",t[t.MDN_MANDATORY_EXTENSION=1010]="MDN_MANDATORY_EXTENSION",t[t.MDN_INTERNAL_ERROR=1011]="MDN_INTERNAL_ERROR",t[t.MDN_SERVICE_RESTART=1012]="MDN_SERVICE_RESTART",t[t.MDN_TRY_AGAIN_LATER=1013]="MDN_TRY_AGAIN_LATER",t[t.MDN_BAD_GATEWAY=1014]="MDN_BAD_GATEWAY",t[t.MDN_TLS_HANDSHAKE=1015]="MDN_TLS_HANDSHAKE",t[t.MANUAL_CLOSE=4001]="MANUAL_CLOSE",t[t.WS_5000_NORAML_CLOSURE=5e3]="WS_5000_NORAML_CLOSURE",t[t.WS_5001_UNAUTHORIZED=5001]="WS_5001_UNAUTHORIZED",t[t.WS_5002_LICENSE_EXPIRED=5002]="WS_5002_LICENSE_EXPIRED",t[t.WS_5003_TOKEN_EXPIRED=5003]="WS_5003_TOKEN_EXPIRED"}(Ki||(Ki={}));class Zi{socket;messageSub;linkStartSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get linkStart(){return this.linkStartSub.asObservable()}messageQueue=[];isConnected;constructor(){this.isConnected=!1,this.messageSub=new r.Subject,this.linkStartSub=new r.Subject,this.closeSub=new r.Subject,this.destorySub=new r.Subject}start(t){this.socket=new o(t,{autoPong:!0}),r.fromEvent(this.socket,"open").pipe(r.takeUntil(this.destorySub)).subscribe(()=>{this.isConnected=!0,this.linkStartSub.next(),Nn.code(wn["啟動服務"],"proxy"),this.flushMessageQueue()}),r.fromEvent(this.socket,"message").pipe(r.takeUntil(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),r.fromEvent(this.socket,"error").pipe(r.takeUntil(this.destorySub)).subscribe(t=>{const{error:e}=t;Nn.error("Proxy has some problem",e)}),r.fromEvent(this.socket,"close").pipe(r.takeUntil(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e,reason:r}=t;switch(e){case Ki.MANUAL_CLOSE:Nn.code(wn["無副作用的關閉連線"]);break;case Ki.WS_5000_NORAML_CLOSURE:case Ki.MDN_NORMAL_CLOSURE:case Ki.MDN_GOING_AWAY:this.closeSub.next("close"),Nn.code(wn["安全的關閉連線"]);break;case Ki.MDN_NO_STATUS_RECEIVED:case Ki.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),Nn.code(wn["與雲端的服務中斷"],{code:e,reason:r});break;case Ki.WS_5001_UNAUTHORIZED:case Ki.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),Nn.code(wn["沒有授權,請聯繫Graphen"]);break;case Ki.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect"),Nn.code(wn["自動重新連線連端服務"]);break;default:this.closeSub.next("close"),Nn.code(wn["未預期的斷線,請聯繫Graphen"],{code:e,reason:r})}})}reconnect(t){this.onDestory(),this.destorySub=new r.Subject,this.start(t)}flushMessageQueue(){for(;this.messageQueue.length>0&&this.isConnected&&void 0!==this.socket;){const t=this.messageQueue.shift();t&&this.socket.send(t)}}send(t){this.isConnected&&void 0!==this.socket?this.socket.send(t):this.messageQueue.push(t)}onClose(){this.socket?.close(Ki.MANUAL_CLOSE)}onDestory(){this.destorySub.next(),this.destorySub.complete()}}var ta=at,ea=we;var ra=function(t,e){return t&&ta(e,ea(e),t)};var na=A,oa=Pt,ia=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},aa=Object.prototype.hasOwnProperty;var ca=pe,sa=function(t){if(!na(t))return ia(t);var e=oa(t),r=[];for(var n in t)("constructor"!=n||!e&&aa.call(t,n))&&r.push(n);return r},ua=St;var fa=function(t){return ua(t)?ca(t,!0):sa(t)},la=at,ha=fa;var va=function(t,e){return t&&la(e,ha(e),t)},pa={exports:{}};!function(t,e){var r=v,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n?r.Buffer:void 0,a=i?i.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var r=t.length,n=a?a(r):new t.constructor(r);return t.copy(n),n}}(pa,pa.exports);var ba=pa.exports;var da=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e},ya=at,_a=bo;var ga=function(t,e){return ya(t,_a(t),e)},Oa=be(Object.getPrototypeOf,Object),ja=ao,Sa=Oa,wa=bo,ma=fo,Ea=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)ja(e,wa(t)),t=Sa(t);return e}:ma,Aa=at,Da=Ea;var Na=function(t,e){return Aa(t,Da(t),e)},Ra=uo,ka=Ea,Ma=fa;var Ca=function(t){return Ra(t,Ma,ka)},Pa=Object.prototype.hasOwnProperty;var Ia=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Pa.call(t,"index")&&(r.index=t.index,r.input=t.input),r},La=Kn;var Ta=function(t){var e=new t.constructor(t.byteLength);return new La(e).set(new La(t)),e},xa=Ta;var Ua=function(t,e){var r=e?xa(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},Fa=/\w*$/;var $a=function(t){var e=new t.constructor(t.source,Fa.exec(t));return e.lastIndex=t.lastIndex,e},Wa=p?p.prototype:void 0,za=Wa?Wa.valueOf:void 0;var Ga=Ta;var Ba=Ta,Va=Ua,Xa=$a,Ya=function(t){return za?Object(za.call(t)):{}},qa=function(t,e){var r=e?Ga(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var Ha=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return Ba(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return Va(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return qa(t,r);case"[object Map]":case"[object Set]":return new n;case"[object Number]":case"[object String]":return new n(t);case"[object RegExp]":return Xa(t);case"[object Symbol]":return Ya(t)}},Ka=A,Qa=Object.create,Ja=function(){function t(){}return function(e){if(!Ka(e))return{};if(Qa)return Qa(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Za=Oa,tc=Pt;var ec=function(t){return"function"!=typeof t.constructor||tc(t)?{}:Ja(Za(t))},rc=zo,nc=Lt;var oc=function(t){return nc(t)&&"[object Map]"==rc(t)},ic=te,ac=re&&re.isMap,cc=ac?ic(ac):oc,sc=zo,uc=Lt;var fc=function(t){return uc(t)&&"[object Set]"==sc(t)},lc=te,hc=re&&re.isSet,vc=hc?lc(hc):fc,pc=Wn,bc=vn,dc=nt,yc=ra,_c=va,gc=ba,Oc=da,jc=ga,Sc=Na,wc=Oo,mc=Ca,Ec=zo,Ac=Ia,Dc=Ha,Nc=ec,Rc=Bt,kc=qt,Mc=cc,Cc=A,Pc=vc,Ic=we,Lc=fa,Tc="[object Arguments]",xc="[object Function]",Uc="[object Object]",Fc={};Fc[Tc]=Fc["[object Array]"]=Fc["[object ArrayBuffer]"]=Fc["[object DataView]"]=Fc["[object Boolean]"]=Fc["[object Date]"]=Fc["[object Float32Array]"]=Fc["[object Float64Array]"]=Fc["[object Int8Array]"]=Fc["[object Int16Array]"]=Fc["[object Int32Array]"]=Fc["[object Map]"]=Fc["[object Number]"]=Fc[Uc]=Fc["[object RegExp]"]=Fc["[object Set]"]=Fc["[object String]"]=Fc["[object Symbol]"]=Fc["[object Uint8Array]"]=Fc["[object Uint8ClampedArray]"]=Fc["[object Uint16Array]"]=Fc["[object Uint32Array]"]=!0,Fc["[object Error]"]=Fc[xc]=Fc["[object WeakMap]"]=!1;var $c=function t(e,r,n,o,i,a){var c,s=1&r,u=2&r,f=4&r;if(n&&(c=i?n(e,o,i,a):n(e)),void 0!==c)return c;if(!Cc(e))return e;var l=Rc(e);if(l){if(c=Ac(e),!s)return Oc(e,c)}else{var h=Ec(e),v=h==xc||"[object GeneratorFunction]"==h;if(kc(e))return gc(e,s);if(h==Uc||h==Tc||v&&!i){if(c=u||v?{}:Nc(e),!s)return u?Sc(e,_c(c,e)):jc(e,yc(c,e))}else{if(!Fc[h])return i?e:{};c=Dc(e,h,s)}}a||(a=new pc);var p=a.get(e);if(p)return p;a.set(e,c),Pc(e)?e.forEach(function(o){c.add(t(o,r,n,o,e,a))}):Mc(e)&&e.forEach(function(o,i){c.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?mc:wc:u?Lc:Ic)(e);return bc(b||e,function(o,i){b&&(o=e[i=o]),dc(c,i,t(o,r,n,i,e,a))}),c};var Wc=on,zc=function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i};var Gc=function(t,e){return e.length<2?t:Wc(t,zc(e,0,-1))},Bc=Zr,Vc=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},Xc=Gc,Yc=en;var qc=function(t,e){return e=Bc(e,t),null==(t=Xc(t,e))||delete t[Yc(Vc(e))]},Hc=E,Kc=Oa,Qc=Lt,Jc=Function.prototype,Zc=Object.prototype,ts=Jc.toString,es=Zc.hasOwnProperty,rs=ts.call(Object);var ns=function(t){if(!Qc(t)||"[object Object]"!=Hc(t))return!1;var e=Kc(t);if(null===e)return!0;var r=es.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&ts.call(r)==rs};var os=function(t){return ns(t)?void 0:t},is=Gt,as=Bt,cs=p?p.isConcatSpreadable:void 0;var ss=ao,us=function(t){return as(t)||is(t)||!!(cs&&t&&t[cs])};var fs=function t(e,r,n,o,i){var a=-1,c=e.length;for(n||(n=us),i||(i=[]);++a<c;){var s=e[a];r>0&&n(s)?r>1?t(s,r-1,n,o,i):ss(i,s):o||(i[i.length]=s)}return i},ls=fs;var hs=function(t){return(null==t?0:t.length)?ls(t,1):[]},vs=ft,ps=bt;var bs=Wr,ds=$c,ys=qc,_s=Zr,gs=at,Os=os,js=Ca,Ss=function(t){return ps(vs(t,void 0,hs),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=bs(e,function(e){return e=_s(e,t),n||(n=e.length>1),e}),gs(t,js(t),r),n&&(r=ds(r,7,Os));for(var o=e.length;o--;)ys(r,e[o]);return r}),ws=u(Ss);const ms=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;EOL;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=a.homedir(),this.EOL=a.EOL,this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=c.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||c.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||c.join(this.homedir,".config");break;default:console.log(`當前系統是未知的平台: ${this.platform}`),this.isMAC=!1,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=this.homedir}this.appFolder=c.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return c.join(...t)}folderCheck(t){i.mkdirSync(t,{recursive:!0})}fileCheck(t){i.existsSync(t)||i.writeFileSync(t,"",{encoding:"utf8"})}}("aiia-sdk");class Es{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=ms.addPath(ms.appFolder,this.fileName),ms.fileCheck(this.filePath)}getFileDataSync(){const t=i.readFileSync(this.filePath,"utf8");try{return JSON.parse(t)}catch(t){return{}}}setFileDataSync(t){try{const e=JSON.stringify(t);i.writeFileSync(this.filePath,e,"utf8")}catch(t){}}async getFileData(){return new Promise(t=>{i.readFile(this.filePath,"utf8",(e,r)=>{if(e)t({});else try{t(JSON.parse(r))}catch(e){t({})}})})}async setFileData(t){return new Promise(e=>{try{const r=JSON.stringify(t);i.writeFile(this.filePath,r,"utf8",t=>{e()})}catch(t){}})}async getItem(t){return(await this.getFileData())[t]??null}async setItem(t,e){const r=await this.getFileData();r[t]=e,await this.setFileData(r)}async removeItem(t){const e=await this.getFileData(),r=ws(e,t);await this.setFileData(r)}async clear(){await this.setFileData({})}getItemSync(t){return this.getFileDataSync()[t]??null}setItemSync(t,e){const r=this.getFileDataSync();r[t]=e,this.setFileDataSync(r)}removeItemSync(t){const e=ws(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}class As{filePath;fileName;constructor(){this.fileName="log.txt",this.filePath=ms.addPath(ms.appFolder,this.fileName)}next(t,e,...r){try{const n=r.reduce((t,e)=>{switch(typeof e){case"string":case"number":case"bigint":return`${t} ${e.toString()}`;case"boolean":return`${t} ${e?"true":"false"}`;case"object":try{return`${t} ${JSON.stringify(e)}`}catch(e){return t}case"symbol":case"undefined":case"function":return`${t} [${typeof e}]`}},"");i.appendFileSync(this.filePath,`LOG(${t})__${e}__:: ${n}${ms.EOL}`,{encoding:"utf8"})}catch(t){}}}class Ds{config;constructor(t){this.config=t}onDestory(){}send(t){}start(){}}class Ns{config;stroage;apiProxy;chat;udpProxy;isStart;channelMap;destorySub;access_token;get accessToken(){return this.access_token}constructor(t,e){this.config=t,this.stroage=e,this.isStart=!1,this.destorySub=new r.Subject,this.channelMap=new Map,this.access_token=e.getItemSync(fn),this.apiProxy=new Ji(this.config.endPoint.api),Nn.code(wn["指定模組初始化完成"],"api"),this.chat=new Rn(this.config),Nn.code(wn["指定模組初始化完成"],"chat"),this.udpProxy=new Ds(this.config),Nn.code(wn["指定模組初始化完成"],"udp")}async start(){if(this.isStart)throw new Error(cn["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.memberChange.pipe(r.takeUntil(this.destorySub)).subscribe(({type:t,socket:e})=>{switch(t){case"in":{Nn.debug("member join",e.id);const t=new Zi,o=new r.Subject,i=(n=e.handshake.query.uuid,Vt(n)?un(n,"[0]",void 0):n??void 0);void 0===i?(this.getProjectList().then(t=>{e.emit("list",t)}),r.fromEvent(e,"uuid").pipe(r.take(1),r.takeUntil(o)).subscribe(r=>{this.openChannel(r,e,t,o)})):this.openChannel(i,e,t,o),this.channelMap.set(e.id,()=>{o.next(),o.complete()});break}case"out":Nn.debug("member leave",e.id),this.channelMap.has(e.id)&&(this.channelMap.get(e.id)(),this.channelMap.delete(e.id))}var n}),this.chat.start(),Nn.code(wn["啟動服務"],"chat"),this.udpProxy.start(),Nn.code(wn["啟動服務"],"udp")}async replaceAccessToken(){const t=await this.apiProxy.getAccessToken(this.config.license,this.access_token);return this.access_token=t,this.stroage.setItemSync(fn,t),t}async getProjectList(){return await this.apiProxy.getProjectList(this.config.license)}getProxySocketURL(t){return`${this.config.endPoint.socket}/v1/chat/project/${this.accessToken}/${t}`}openChannel(t,e,n,o){r.fromEvent(e,"cloud").pipe(r.takeUntil(o)).subscribe(t=>{n.send(t)}),n.message.pipe(r.takeUntil(o)).subscribe(t=>{e.emit("cloud",t),this.udpProxy.send(t)}),n.close.pipe(r.takeUntil(o)).subscribe(async r=>{switch(e.emit("channel",r),r){case"close":case"no_permissions":n.onDestory();break;case"reconnect":await this.replaceAccessToken(),n.reconnect(this.getProxySocketURL(t))}}),n.linkStart.pipe(r.takeUntil(o)).subscribe(()=>{e.emit("channel","open")}),o.subscribe(()=>{n.onClose()}),n.start(this.getProxySocketURL(t))}onDestory(){this.apiProxy.onDestory(),this.chat.onDestory(),this.udpProxy.onDestory(),this.destorySub.next(),this.destorySub.complete(),Nn.code(wn["服務結束"])}}exports.aiiaCore=function(t){if(ln){if(void 0===un(t,"license",void 0))throw new Error(cn["未提供憑證"]);!function(t){const{info:e,error:r,warn:n,debug:o,fatal:i,code:a}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);return a||(En.code=()=>{}),o||(En.debug=()=>{}),e||(En.info=()=>{}),n||(En.warn=()=>{}),r||(En.error=()=>{}),i||(En.fatal=()=>{}),Dn}(un(t,"debug",!0))(new As),Nn.code(wn["開始初始化必要模組"]);const e=new hn(Me({},t));Nn.code(wn["指定模組初始化完成"],"config");const r=new Es;Nn.code(wn["指定模組初始化完成"],"storage");const n=new Ns(e,r);return Nn.code(wn["指定模組初始化完成"],"core"),n.start(),Nn.code(wn["啟動服務"]),()=>{n.onDestory()}}throw new Error(cn["環境錯誤(nodejs)"])};
1
+ "use strict";var e=require("moment"),t=require("socket.io"),r=require("rxjs"),n=require("axios"),o=require("ws"),i=require("fs"),a=require("os"),c=require("path"),s=require("node-osc"),u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var f="object"==typeof u&&u&&u.Object===Object&&u,h=f,v="object"==typeof self&&self&&self.Object===Object&&self,p=h||v||Function("return this")(),b=p.Symbol,d=b,y=Object.prototype,_=y.hasOwnProperty,g=y.toString,O=d?d.toStringTag:void 0;var j=function(e){var t=_.call(e,O),r=e[O];try{e[O]=void 0;var n=!0}catch(e){}var o=g.call(e);return n&&(t?e[O]=r:delete e[O]),o},S=Object.prototype.toString;var m=j,w=function(e){return S.call(e)},E=b?b.toStringTag:void 0;var A=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":E&&E in Object(e)?m(e):w(e)};var D=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},N=A,R=D;var k,C=function(e){if(!R(e))return!1;var t=N(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},P=p["__core-js_shared__"],M=(k=/[^.]+$/.exec(P&&P.keys&&P.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var x=function(e){return!!M&&M in e},I=Function.prototype.toString;var L=function(e){if(null!=e){try{return I.call(e)}catch(e){}try{return e+""}catch(e){}}return""},T=C,U=x,F=D,W=L,$=/^\[object .+?Constructor\]$/,z=Function.prototype,G=Object.prototype,B=z.toString,V=G.hasOwnProperty,X=RegExp("^"+B.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Y=function(e){return!(!F(e)||U(e))&&(T(e)?X:$).test(W(e))},q=function(e,t){return null==e?void 0:e[t]};var H=function(e,t){var r=q(e,t);return Y(r)?r:void 0},K=H,J=function(){try{var e=K(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),Q=J;var Z=function(e,t,r){"__proto__"==t&&Q?Q(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r};var ee=function(e,t){return e===t||e!=e&&t!=t},te=Z,re=ee,ne=Object.prototype.hasOwnProperty;var oe=function(e,t,r){var n=e[t];ne.call(e,t)&&re(n,r)&&(void 0!==r||t in e)||te(e,t,r)},ie=oe,ae=Z;var ce=function(e,t,r,n){var o=!r;r||(r={});for(var i=-1,a=t.length;++i<a;){var c=t[i],s=n?n(r[c],e[c],c,r,e):void 0;void 0===s&&(s=e[c]),o?ae(r,c,s):ie(r,c,s)}return r};var se=function(e){return e};var ue=function(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)},le=Math.max;var fe=function(e,t,r){return t=le(void 0===t?e.length-1:t,0),function(){for(var n=arguments,o=-1,i=le(n.length-t,0),a=Array(i);++o<i;)a[o]=n[t+o];o=-1;for(var c=Array(t+1);++o<t;)c[o]=n[o];return c[t]=r(a),ue(e,this,c)}};var he=function(e){return function(){return e}},ve=J,pe=ve?function(e,t){return ve(e,"toString",{configurable:!0,enumerable:!1,value:he(t),writable:!0})}:se,be=Date.now;var de=function(e){var t=0,r=0;return function(){var n=be(),o=16-(n-r);if(r=n,o>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(pe),ye=se,_e=fe,ge=de;var Oe=function(e,t){return ge(_e(e,t,ye),e+"")};var je=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991},Se=C,me=je;var we=function(e){return null!=e&&me(e.length)&&!Se(e)},Ee=/^(?:0|[1-9]\d*)$/;var Ae=function(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&Ee.test(e))&&e>-1&&e%1==0&&e<t},De=ee,Ne=we,Re=Ae,ke=D;var Ce=function(e,t,r){if(!ke(r))return!1;var n=typeof t;return!!("number"==n?Ne(r)&&Re(t,r.length):"string"==n&&t in r)&&De(r[t],e)},Pe=Oe,Me=Ce;var xe=function(e){return Pe(function(t,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=e.length>3&&"function"==typeof i?(o--,i):void 0,a&&Me(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),t=Object(t);++n<o;){var c=r[n];c&&e(t,c,n,i)}return t})},Ie=Object.prototype;var Le=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||Ie)};var Te=function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n};var Ue=function(e){return null!=e&&"object"==typeof e},Fe=A,We=Ue;var $e=function(e){return We(e)&&"[object Arguments]"==Fe(e)},ze=Ue,Ge=Object.prototype,Be=Ge.hasOwnProperty,Ve=Ge.propertyIsEnumerable,Xe=$e(function(){return arguments}())?$e:function(e){return ze(e)&&Be.call(e,"callee")&&!Ve.call(e,"callee")},Ye=Array.isArray,qe=l(Ye),He={exports:{}};var Ke=function(){return!1};!function(e,t){var r=p,n=Ke,o=t&&!t.nodeType&&t,i=o&&e&&!e.nodeType&&e,a=i&&i.exports===o?r.Buffer:void 0,c=(a?a.isBuffer:void 0)||n;e.exports=c}(He,He.exports);var Je=He.exports,Qe=A,Ze=je,et=Ue,tt={};tt["[object Float32Array]"]=tt["[object Float64Array]"]=tt["[object Int8Array]"]=tt["[object Int16Array]"]=tt["[object Int32Array]"]=tt["[object Uint8Array]"]=tt["[object Uint8ClampedArray]"]=tt["[object Uint16Array]"]=tt["[object Uint32Array]"]=!0,tt["[object Arguments]"]=tt["[object Array]"]=tt["[object ArrayBuffer]"]=tt["[object Boolean]"]=tt["[object DataView]"]=tt["[object Date]"]=tt["[object Error]"]=tt["[object Function]"]=tt["[object Map]"]=tt["[object Number]"]=tt["[object Object]"]=tt["[object RegExp]"]=tt["[object Set]"]=tt["[object String]"]=tt["[object WeakMap]"]=!1;var rt=function(e){return et(e)&&Ze(e.length)&&!!tt[Qe(e)]};var nt=function(e){return function(t){return e(t)}},ot={exports:{}};!function(e,t){var r=f,n=t&&!t.nodeType&&t,o=n&&e&&!e.nodeType&&e,i=o&&o.exports===n&&r.process,a=function(){try{var e=o&&o.require&&o.require("util").types;return e||i&&i.binding&&i.binding("util")}catch(e){}}();e.exports=a}(ot,ot.exports);var it=ot.exports,at=rt,ct=nt,st=it&&it.isTypedArray,ut=st?ct(st):at,lt=Te,ft=Xe,ht=Ye,vt=Je,pt=Ae,bt=ut,dt=Object.prototype.hasOwnProperty;var yt=function(e,t){var r=ht(e),n=!r&&ft(e),o=!r&&!n&&vt(e),i=!r&&!n&&!o&&bt(e),a=r||n||o||i,c=a?lt(e.length,String):[],s=c.length;for(var u in e)!t&&!dt.call(e,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||pt(u,s))||c.push(u);return c};var _t=function(e,t){return function(r){return e(t(r))}},gt=_t(Object.keys,Object),Ot=Le,jt=gt,St=Object.prototype.hasOwnProperty;var mt=yt,wt=function(e){if(!Ot(e))return jt(e);var t=[];for(var r in Object(e))St.call(e,r)&&"constructor"!=r&&t.push(r);return t},Et=we;var At=function(e){return Et(e)?mt(e):wt(e)},Dt=oe,Nt=ce,Rt=xe,kt=we,Ct=Le,Pt=At,Mt=Object.prototype.hasOwnProperty,xt=l(Rt(function(e,t){if(Ct(t)||kt(t))Nt(t,Pt(t),e);else for(var r in t)Mt.call(t,r)&&Dt(e,r,t[r])})),It=A,Lt=Ue;var Tt=function(e){return"symbol"==typeof e||Lt(e)&&"[object Symbol]"==It(e)},Ut=Ye,Ft=Tt,Wt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,$t=/^\w*$/;var zt=function(e,t){if(Ut(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!Ft(e))||($t.test(e)||!Wt.test(e)||null!=t&&e in Object(t))},Gt=H(Object,"create"),Bt=Gt;var Vt=function(){this.__data__=Bt?Bt(null):{},this.size=0};var Xt=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Yt=Gt,qt=Object.prototype.hasOwnProperty;var Ht=function(e){var t=this.__data__;if(Yt){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return qt.call(t,e)?t[e]:void 0},Kt=Gt,Jt=Object.prototype.hasOwnProperty;var Qt=Gt;var Zt=Vt,er=Xt,tr=Ht,rr=function(e){var t=this.__data__;return Kt?void 0!==t[e]:Jt.call(t,e)},nr=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Qt&&void 0===t?"__lodash_hash_undefined__":t,this};function or(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}or.prototype.clear=Zt,or.prototype.delete=er,or.prototype.get=tr,or.prototype.has=rr,or.prototype.set=nr;var ir=or;var ar=function(){this.__data__=[],this.size=0},cr=ee;var sr=function(e,t){for(var r=e.length;r--;)if(cr(e[r][0],t))return r;return-1},ur=sr,lr=Array.prototype.splice;var fr=sr;var hr=sr;var vr=sr;var pr=ar,br=function(e){var t=this.__data__,r=ur(t,e);return!(r<0)&&(r==t.length-1?t.pop():lr.call(t,r,1),--this.size,!0)},dr=function(e){var t=this.__data__,r=fr(t,e);return r<0?void 0:t[r][1]},yr=function(e){return hr(this.__data__,e)>-1},_r=function(e,t){var r=this.__data__,n=vr(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};function gr(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}gr.prototype.clear=pr,gr.prototype.delete=br,gr.prototype.get=dr,gr.prototype.has=yr,gr.prototype.set=_r;var Or=gr,jr=H(p,"Map"),Sr=ir,mr=Or,wr=jr;var Er=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var Ar=function(e,t){var r=e.__data__;return Er(t)?r["string"==typeof t?"string":"hash"]:r.map},Dr=Ar;var Nr=Ar;var Rr=Ar;var kr=Ar;var Cr=function(){this.size=0,this.__data__={hash:new Sr,map:new(wr||mr),string:new Sr}},Pr=function(e){var t=Dr(this,e).delete(e);return this.size-=t?1:0,t},Mr=function(e){return Nr(this,e).get(e)},xr=function(e){return Rr(this,e).has(e)},Ir=function(e,t){var r=kr(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function Lr(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Lr.prototype.clear=Cr,Lr.prototype.delete=Pr,Lr.prototype.get=Mr,Lr.prototype.has=xr,Lr.prototype.set=Ir;var Tr=Lr,Ur=Tr;function Fr(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=t?t.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=e.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Fr.Cache||Ur),r}Fr.Cache=Ur;var Wr=Fr;var $r=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,zr=/\\(\\)?/g,Gr=function(e){var t=Wr(e,function(e){return 500===r.size&&r.clear(),e}),r=t.cache;return t}(function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace($r,function(e,r,n,o){t.push(n?o.replace(zr,"$1"):r||e)}),t});var Br=function(e,t){for(var r=-1,n=null==e?0:e.length,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o},Vr=Br,Xr=Ye,Yr=Tt,qr=b?b.prototype:void 0,Hr=qr?qr.toString:void 0;var Kr=function e(t){if("string"==typeof t)return t;if(Xr(t))return Vr(t,e)+"";if(Yr(t))return Hr?Hr.call(t):"";var r=t+"";return"0"==r&&1/t==-1/0?"-0":r},Jr=Kr;var Qr=Ye,Zr=zt,en=Gr,tn=function(e){return null==e?"":Jr(e)};var rn=function(e,t){return Qr(e)?e:Zr(e,t)?[e]:en(tn(e))},nn=Tt;var on=function(e){if("string"==typeof e||nn(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t},an=rn,cn=on;var sn=function(e,t){for(var r=0,n=(t=an(t,e)).length;null!=e&&r<n;)e=e[cn(t[r++])];return r&&r==n?e:void 0},un=sn;var ln,fn=function(e,t,r){var n=null==e?void 0:un(e,t);return void 0===n?r:n},hn=l(fn);!function(e){e["網絡錯誤"]="ERROR CODE: 500",e["環境錯誤(browser)"]="ERROR CODE: 1001",e["Worklet模組載入失敗"]="ERROR CODE: 1002",e["未獲得媒體裝置權限"]="ERROR CODE: 1003",e["實例已摧毀"]="ERROR CODE: 1004",e["環境錯誤(nodejs)"]="ERROR CODE: 2001",e["未提供憑證"]="ERROR CODE: 2002",e["獲取權杖失敗"]="ERROR CODE: 2003",e["沒有可用專案"]="ERROR CODE: 2004",e["重複初始化"]="ERROR CODE: 2005"}(ln||(ln={}));const vn="access_token",pn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class bn{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(e,t){const r=t??NaN;if(e){const t=parseInt(e);return isNaN(t)?r:t}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:e}=xt({},this.config);return void 0===e?{specific:!1}:"string"==typeof e?{name:e,id:e,specific:!1}:xt({},e,{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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}get faceDetection(){return xt({frame:3,confidence:80},this.config.faceDetection)}get autoClearSubtitle(){const{user:e,aiia:t}=xt({},this.config.autoClearSubtitle);let r=3e3,n=3e3;return"number"==typeof e?r=e>=0?e:r:!1===e&&(r=NaN),"number"==typeof t?n=t>=0?t:n:!1===t&&(n=NaN),{userDelayTime:r,aiiaDelayTime:n}}constructor(e){this.config=e}}var dn=function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n&&!1!==t(e[r],r,e););return e};var yn=function(e){return function(t,r,n){for(var o=-1,i=Object(t),a=n(t),c=a.length;c--;){var s=a[e?c:++o];if(!1===r(i[s],s,i))break}return t}}(),_n=At;var gn=we;var On=function(e,t){return function(r,n){if(null==r)return r;if(!gn(r))return e(r,n);for(var o=r.length,i=t?o:-1,a=Object(r);(t?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(e,t){return e&&yn(e,t,_n)}),jn=se;var Sn=dn,mn=On,wn=function(e){return"function"==typeof e?e:jn},En=Ye;var An,Dn=l(function(e,t){return(En(e)?Sn:mn)(e,wn(t))});!function(e){e["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",e["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",e["請訂閱專案列表"]="CODE: 1002",e["初始化必要依賴"]="CODE: 1010",e["指定依賴已完成"]="CODE: 1011",e["啟動SDK"]="CODE: 1012",e["結束SDK"]="CODE: 1013",e["安全的關閉連線"]="CODE: 2000",e["無副作用的關閉連線"]="CODE: 2001",e["與雲端的服務中斷"]="CODE: 2002",e["沒有授權,請聯繫Graphen"]="CODE: 2003",e["自動重新連線連端服務"]="CODE: 2004",e["未預期的斷線,請聯繫Graphen"]="CODE: 2005",e["開始初始化必要模組"]="CODE: 2010",e["指定模組初始化完成"]="CODE: 2011",e["啟動服務"]="CODE: 2012",e["服務結束"]="CODE: 2013"}(An||(An={}));const Nn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},Rn=[];function kn(e){return Rn.push(e),kn}const Cn=new Proxy(Nn,{get(t,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const o=e().format("yyyy-MM-DD[T]HH:mm:ss");Dn(Rn,e=>{e.next(r,o,...n)}),t[r](`[Aiia::${r}_${o}_]`,...n)};default:return}},set:(e,t,r,n)=>!0});var Pn=function(e,t){for(var r=-1,n=null==e?0:e.length,o=0,i=[];++r<n;){var a=e[r];t(a,r,e)&&(i[o++]=a)}return i},Mn=Or;var xn=Or,In=jr,Ln=Tr;var Tn=Or,Un=function(){this.__data__=new Mn,this.size=0},Fn=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Wn=function(e){return this.__data__.get(e)},$n=function(e){return this.__data__.has(e)},zn=function(e,t){var r=this.__data__;if(r instanceof xn){var n=r.__data__;if(!In||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new Ln(n)}return r.set(e,t),this.size=r.size,this};function Gn(e){var t=this.__data__=new Tn(e);this.size=t.size}Gn.prototype.clear=Un,Gn.prototype.delete=Fn,Gn.prototype.get=Wn,Gn.prototype.has=$n,Gn.prototype.set=zn;var Bn=Gn;var Vn=Tr,Xn=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},Yn=function(e){return this.__data__.has(e)};function qn(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new Vn;++t<r;)this.add(e[t])}qn.prototype.add=qn.prototype.push=Xn,qn.prototype.has=Yn;var Hn=qn,Kn=function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1},Jn=function(e,t){return e.has(t)};var Qn=function(e,t,r,n,o,i){var a=1&r,c=e.length,s=t.length;if(c!=s&&!(a&&s>c))return!1;var u=i.get(e),l=i.get(t);if(u&&l)return u==t&&l==e;var f=-1,h=!0,v=2&r?new Hn:void 0;for(i.set(e,t),i.set(t,e);++f<c;){var p=e[f],b=t[f];if(n)var d=a?n(b,p,f,t,e,i):n(p,b,f,e,t,i);if(void 0!==d){if(d)continue;h=!1;break}if(v){if(!Kn(t,function(e,t){if(!Jn(v,t)&&(p===e||o(p,e,r,n,i)))return v.push(t)})){h=!1;break}}else if(p!==b&&!o(p,b,r,n,i)){h=!1;break}}return i.delete(e),i.delete(t),h},Zn=p.Uint8Array;var eo=function(e){var t=-1,r=Array(e.size);return e.forEach(function(e,n){r[++t]=[n,e]}),r};var to=Zn,ro=ee,no=Qn,oo=eo,io=function(e){var t=-1,r=Array(e.size);return e.forEach(function(e){r[++t]=e}),r},ao=b?b.prototype:void 0,co=ao?ao.valueOf:void 0;var so=function(e,t,r,n,o,i,a){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!i(new to(e),new to(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return ro(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var c=oo;case"[object Set]":var s=1&n;if(c||(c=io),e.size!=t.size&&!s)return!1;var u=a.get(e);if(u)return u==t;n|=2,a.set(e,t);var l=no(c(e),c(t),n,o,i,a);return a.delete(e),l;case"[object Symbol]":if(co)return co.call(e)==co.call(t)}return!1};var uo=function(e,t){for(var r=-1,n=t.length,o=e.length;++r<n;)e[o+r]=t[r];return e},lo=uo,fo=Ye;var ho=function(e,t,r){var n=t(e);return fo(e)?n:lo(n,r(e))};var vo=function(){return[]},po=Pn,bo=vo,yo=Object.prototype.propertyIsEnumerable,_o=Object.getOwnPropertySymbols,go=_o?function(e){return null==e?[]:(e=Object(e),po(_o(e),function(t){return yo.call(e,t)}))}:bo,Oo=ho,jo=go,So=At;var mo=function(e){return Oo(e,So,jo)},wo=mo,Eo=Object.prototype.hasOwnProperty;var Ao=function(e,t,r,n,o,i){var a=1&r,c=wo(e),s=c.length;if(s!=wo(t).length&&!a)return!1;for(var u=s;u--;){var l=c[u];if(!(a?l in t:Eo.call(t,l)))return!1}var f=i.get(e),h=i.get(t);if(f&&h)return f==t&&h==e;var v=!0;i.set(e,t),i.set(t,e);for(var p=a;++u<s;){var b=e[l=c[u]],d=t[l];if(n)var y=a?n(d,b,l,t,e,i):n(b,d,l,e,t,i);if(!(void 0===y?b===d||o(b,d,r,n,i):y)){v=!1;break}p||(p="constructor"==l)}if(v&&!p){var _=e.constructor,g=t.constructor;_==g||!("constructor"in e)||!("constructor"in t)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(v=!1)}return i.delete(e),i.delete(t),v},Do=H(p,"DataView"),No=jr,Ro=H(p,"Promise"),ko=H(p,"Set"),Co=H(p,"WeakMap"),Po=A,Mo=L,xo="[object Map]",Io="[object Promise]",Lo="[object Set]",To="[object WeakMap]",Uo="[object DataView]",Fo=Mo(Do),Wo=Mo(No),$o=Mo(Ro),zo=Mo(ko),Go=Mo(Co),Bo=Po;(Do&&Bo(new Do(new ArrayBuffer(1)))!=Uo||No&&Bo(new No)!=xo||Ro&&Bo(Ro.resolve())!=Io||ko&&Bo(new ko)!=Lo||Co&&Bo(new Co)!=To)&&(Bo=function(e){var t=Po(e),r="[object Object]"==t?e.constructor:void 0,n=r?Mo(r):"";if(n)switch(n){case Fo:return Uo;case Wo:return xo;case $o:return Io;case zo:return Lo;case Go:return To}return t});var Vo=Bo,Xo=Bn,Yo=Qn,qo=so,Ho=Ao,Ko=Vo,Jo=Ye,Qo=Je,Zo=ut,ei="[object Arguments]",ti="[object Array]",ri="[object Object]",ni=Object.prototype.hasOwnProperty;var oi=function(e,t,r,n,o,i){var a=Jo(e),c=Jo(t),s=a?ti:Ko(e),u=c?ti:Ko(t),l=(s=s==ei?ri:s)==ri,f=(u=u==ei?ri:u)==ri,h=s==u;if(h&&Qo(e)){if(!Qo(t))return!1;a=!0,l=!1}if(h&&!l)return i||(i=new Xo),a||Zo(e)?Yo(e,t,r,n,o,i):qo(e,t,s,r,n,o,i);if(!(1&r)){var v=l&&ni.call(e,"__wrapped__"),p=f&&ni.call(t,"__wrapped__");if(v||p){var b=v?e.value():e,d=p?t.value():t;return i||(i=new Xo),o(b,d,r,n,i)}}return!!h&&(i||(i=new Xo),Ho(e,t,r,n,o,i))},ii=Ue;var ai=function e(t,r,n,o,i){return t===r||(null==t||null==r||!ii(t)&&!ii(r)?t!=t&&r!=r:oi(t,r,n,o,e,i))},ci=Bn,si=ai;var ui=D;var li=function(e){return e==e&&!ui(e)},fi=li,hi=At;var vi=function(e,t){return function(r){return null!=r&&(r[e]===t&&(void 0!==t||e in Object(r)))}},pi=function(e,t,r,n){var o=r.length,i=o,a=!n;if(null==e)return!i;for(e=Object(e);o--;){var c=r[o];if(a&&c[2]?c[1]!==e[c[0]]:!(c[0]in e))return!1}for(;++o<i;){var s=(c=r[o])[0],u=e[s],l=c[1];if(a&&c[2]){if(void 0===u&&!(s in e))return!1}else{var f=new ci;if(n)var h=n(u,l,s,e,t,f);if(!(void 0===h?si(l,u,3,n,f):h))return!1}}return!0},bi=function(e){for(var t=hi(e),r=t.length;r--;){var n=t[r],o=e[n];t[r]=[n,o,fi(o)]}return t},di=vi;var yi=rn,_i=Xe,gi=Ye,Oi=Ae,ji=je,Si=on;var mi=function(e,t,r){for(var n=-1,o=(t=yi(t,e)).length,i=!1;++n<o;){var a=Si(t[n]);if(!(i=null!=e&&r(e,a)))break;e=e[a]}return i||++n!=o?i:!!(o=null==e?0:e.length)&&ji(o)&&Oi(a,o)&&(gi(e)||_i(e))},wi=function(e,t){return null!=e&&t in Object(e)},Ei=mi;var Ai=function(e,t){return null!=e&&Ei(e,t,wi)},Di=ai,Ni=fn,Ri=Ai,ki=zt,Ci=li,Pi=vi,Mi=on;var xi=function(e,t){return ki(e)&&Ci(t)?Pi(Mi(e),t):function(r){var n=Ni(r,e);return void 0===n&&n===t?Ri(r,e):Di(t,n,3)}};var Ii=sn;var Li=function(e){return function(t){return Ii(t,e)}},Ti=function(e){return function(t){return null==t?void 0:t[e]}},Ui=Li,Fi=zt,Wi=on;var $i=function(e){return Fi(e)?Ti(Wi(e)):Ui(e)},zi=function(e){var t=bi(e);return 1==t.length&&t[0][2]?di(t[0][0],t[0][1]):function(r){return r===e||pi(r,e,t)}},Gi=xi,Bi=se,Vi=Ye,Xi=$i;var Yi=function(e){return"function"==typeof e?e:null==e?Bi:"object"==typeof e?Vi(e)?Gi(e[0],e[1]):zi(e):Xi(e)},qi=On,Hi=we;var Ki=function(e,t){var r=-1,n=Hi(e)?Array(e.length):[];return qi(e,function(e,o,i){n[++r]=t(e,o,i)}),n},Ji=Br,Qi=Yi,Zi=Ki,ea=Ye;var ta=l(function(e,t){return(ea(e)?Ji:Zi)(e,Qi(t))}),ra=Xe,na=Ye,oa=b?b.isConcatSpreadable:void 0;var ia=uo,aa=function(e){return na(e)||ra(e)||!!(oa&&e&&e[oa])};var ca=function e(t,r,n,o,i){var a=-1,c=t.length;for(n||(n=aa),i||(i=[]);++a<c;){var s=t[a];r>0&&n(s)?r>1?e(s,r-1,n,o,i):ia(i,s):o||(i[i.length]=s)}return i};var sa=Tt;var ua=function(e,t){if(e!==t){var r=void 0!==e,n=null===e,o=e==e,i=sa(e),a=void 0!==t,c=null===t,s=t==t,u=sa(t);if(!c&&!u&&!i&&e>t||i&&a&&s&&!c&&!u||n&&a&&s||!r&&s||!o)return 1;if(!n&&!i&&!u&&e<t||u&&r&&o&&!n&&!i||c&&r&&o||!a&&o||!s)return-1}return 0};var la=Br,fa=sn,ha=Yi,va=Ki,pa=function(e,t){var r=e.length;for(e.sort(t);r--;)e[r]=e[r].value;return e},ba=nt,da=function(e,t,r){for(var n=-1,o=e.criteria,i=t.criteria,a=o.length,c=r.length;++n<a;){var s=ua(o[n],i[n]);if(s)return n>=c?s:s*("desc"==r[n]?-1:1)}return e.index-t.index},ya=se,_a=Ye;var ga,Oa=ca,ja=function(e,t,r){t=t.length?la(t,function(e){return _a(e)?function(t){return fa(t,1===e.length?e[0]:e)}:e}):[ya];var n=-1;t=la(t,ba(ha));var o=va(e,function(e,r,o){return{criteria:la(t,function(t){return t(e)}),index:++n,value:e}});return pa(o,function(e,t){return da(e,t,r)})},Sa=Ce;Oe(function(e,t){if(null==e)return[];var r=t.length;return r>1&&Sa(e,t[0],t[1])?t=[]:r>2&&Sa(t[0],t[1],t[2])&&(t=[t[0]]),ja(e,Oa(t,1),[])});class ma{config;server;memberSub;get port(){return this.config.port}get webserver(){return this.config.webserver}get memberChange(){return this.memberSub.asObservable()}constructor(e){this.config=e,this.memberSub=new r.Subject}start(){if(this.server=new t.Server(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",e=>{this.memberSub.next({type:"in",socket:e}),Cn.debug("client on",e.id),e.on("disconnect",t=>{this.memberSub.next({type:"out",socket:e}),Cn.debug("client off",t)})}),void 0===this.webserver){const e=this.port;this.server.listen(e),Cn.info("Websocket server run on",e)}else Cn.info("Websocket server rely your webserver.")}onDestroy(){this.server&&this.server.close()}}class wa{instance;controller;constructor(e){this.controller=new AbortController,this.instance=n.create({baseURL:e,signal:this.controller.signal})}async getAccessToken(e,t){const r={license_number:e,token_value:t??""},n=await this.instance.post("/api/v1/license/agent_token",r).then(e=>hn(e.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(ln["網絡錯誤"]);if(""===n)throw new Error(ln["獲取權杖失敗"]);return n}async getProjectList(e){const t=await this.instance.post("/api/v1/license/projects",{license_number:e}).then(e=>ta(hn(e,"data.projects",[]),({id:e,sub_project_name:t})=>({id:e,name:t}))).catch(e=>null);if(null===t)throw new Error(ln["網絡錯誤"]);if(0===t.length)throw new Error(ln["沒有可用專案"]);return t}onDestroy(){this.controller.abort()}}!function(e){e[e.MDN_NORMAL_CLOSURE=1e3]="MDN_NORMAL_CLOSURE",e[e.MDN_GOING_AWAY=1001]="MDN_GOING_AWAY",e[e.MDN_PROTOCOL_ERROR=1002]="MDN_PROTOCOL_ERROR",e[e.MDN_UNSUPPORTED_DATA=1003]="MDN_UNSUPPORTED_DATA",e[e.MDN_RESERVED_1004=1004]="MDN_RESERVED_1004",e[e.MDN_NO_STATUS_RECEIVED=1005]="MDN_NO_STATUS_RECEIVED",e[e.MDN_ABNORMAL_CLOSURE=1006]="MDN_ABNORMAL_CLOSURE",e[e.MDN_INVALID_FRAME_PAYLOAD=1007]="MDN_INVALID_FRAME_PAYLOAD",e[e.MDN_POLICY_VIOLATION=1008]="MDN_POLICY_VIOLATION",e[e.MDN_MESSAGE_TOO_BIG=1009]="MDN_MESSAGE_TOO_BIG",e[e.MDN_MANDATORY_EXTENSION=1010]="MDN_MANDATORY_EXTENSION",e[e.MDN_INTERNAL_ERROR=1011]="MDN_INTERNAL_ERROR",e[e.MDN_SERVICE_RESTART=1012]="MDN_SERVICE_RESTART",e[e.MDN_TRY_AGAIN_LATER=1013]="MDN_TRY_AGAIN_LATER",e[e.MDN_BAD_GATEWAY=1014]="MDN_BAD_GATEWAY",e[e.MDN_TLS_HANDSHAKE=1015]="MDN_TLS_HANDSHAKE",e[e.MANUAL_CLOSE=4001]="MANUAL_CLOSE",e[e.WS_5000_NORAML_CLOSURE=5e3]="WS_5000_NORAML_CLOSURE",e[e.WS_5001_UNAUTHORIZED=5001]="WS_5001_UNAUTHORIZED",e[e.WS_5002_LICENSE_EXPIRED=5002]="WS_5002_LICENSE_EXPIRED",e[e.WS_5003_TOKEN_EXPIRED=5003]="WS_5003_TOKEN_EXPIRED"}(ga||(ga={}));class Ea{socket;messageSub;linkStartSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get linkStart(){return this.linkStartSub.asObservable()}messageQueue=[];isConnected;constructor(){this.isConnected=!1,this.messageSub=new r.Subject,this.linkStartSub=new r.Subject,this.closeSub=new r.Subject,this.destorySub=new r.Subject}start(e){this.socket=new o(e,{autoPong:!0}),r.fromEvent(this.socket,"open").pipe(r.takeUntil(this.destorySub)).subscribe(()=>{this.isConnected=!0,Cn.code(An["啟動服務"],"proxy"),this.flushMessageQueue(),this.linkStartSub.next()}),r.fromEvent(this.socket,"message").pipe(r.takeUntil(this.destorySub)).subscribe(e=>{const{data:t}=e;this.messageSub.next(t)}),r.fromEvent(this.socket,"error").pipe(r.takeUntil(this.destorySub)).subscribe(e=>{const{error:t}=e;Cn.error("Proxy has some problem",t)}),r.fromEvent(this.socket,"close").pipe(r.takeUntil(this.destorySub)).subscribe(e=>{this.isConnected=!1;const{code:t,reason:r}=e;switch(t){case ga.MANUAL_CLOSE:Cn.code(An["無副作用的關閉連線"]);break;case ga.WS_5000_NORAML_CLOSURE:case ga.MDN_NORMAL_CLOSURE:case ga.MDN_GOING_AWAY:this.closeSub.next("close"),Cn.code(An["安全的關閉連線"]);break;case ga.MDN_NO_STATUS_RECEIVED:case ga.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),Cn.code(An["與雲端的服務中斷"],{code:t,reason:r});break;case ga.WS_5001_UNAUTHORIZED:case ga.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),Cn.code(An["沒有授權,請聯繫Graphen"]);break;case ga.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect"),Cn.code(An["自動重新連線連端服務"]);break;default:this.closeSub.next("close"),Cn.code(An["未預期的斷線,請聯繫Graphen"],{code:t,reason:r})}})}reconnect(e){this.onDestroy(),this.destorySub=new r.Subject,this.start(e)}flushMessageQueue(){for(;this.messageQueue.length>0&&this.isConnected&&void 0!==this.socket;){const e=this.messageQueue.shift();e&&this.socket.send(e)}}send(e){this.isConnected&&void 0!==this.socket?this.socket.send(e):this.messageQueue.push(e)}onClose(){this.socket?.close(ga.MANUAL_CLOSE)}onDestroy(){this.destorySub.next(),this.destorySub.complete()}}var Aa=ce,Da=At;var Na=function(e,t){return e&&Aa(t,Da(t),e)};var Ra=D,ka=Le,Ca=function(e){var t=[];if(null!=e)for(var r in Object(e))t.push(r);return t},Pa=Object.prototype.hasOwnProperty;var Ma=yt,xa=function(e){if(!Ra(e))return Ca(e);var t=ka(e),r=[];for(var n in e)("constructor"!=n||!t&&Pa.call(e,n))&&r.push(n);return r},Ia=we;var La=function(e){return Ia(e)?Ma(e,!0):xa(e)},Ta=ce,Ua=La;var Fa=function(e,t){return e&&Ta(t,Ua(t),e)},Wa={exports:{}};!function(e,t){var r=p,n=t&&!t.nodeType&&t,o=n&&e&&!e.nodeType&&e,i=o&&o.exports===n?r.Buffer:void 0,a=i?i.allocUnsafe:void 0;e.exports=function(e,t){if(t)return e.slice();var r=e.length,n=a?a(r):new e.constructor(r);return e.copy(n),n}}(Wa,Wa.exports);var $a=Wa.exports;var za=function(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t},Ga=ce,Ba=go;var Va=function(e,t){return Ga(e,Ba(e),t)},Xa=_t(Object.getPrototypeOf,Object),Ya=uo,qa=Xa,Ha=go,Ka=vo,Ja=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)Ya(t,Ha(e)),e=qa(e);return t}:Ka,Qa=ce,Za=Ja;var ec=function(e,t){return Qa(e,Za(e),t)},tc=ho,rc=Ja,nc=La;var oc=function(e){return tc(e,nc,rc)},ic=Object.prototype.hasOwnProperty;var ac=function(e){var t=e.length,r=new e.constructor(t);return t&&"string"==typeof e[0]&&ic.call(e,"index")&&(r.index=e.index,r.input=e.input),r},cc=Zn;var sc=function(e){var t=new e.constructor(e.byteLength);return new cc(t).set(new cc(e)),t},uc=sc;var lc=function(e,t){var r=t?uc(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)},fc=/\w*$/;var hc=function(e){var t=new e.constructor(e.source,fc.exec(e));return t.lastIndex=e.lastIndex,t},vc=b?b.prototype:void 0,pc=vc?vc.valueOf:void 0;var bc=sc;var dc=sc,yc=lc,_c=hc,gc=function(e){return pc?Object(pc.call(e)):{}},Oc=function(e,t){var r=t?bc(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)};var jc=function(e,t,r){var n=e.constructor;switch(t){case"[object ArrayBuffer]":return dc(e);case"[object Boolean]":case"[object Date]":return new n(+e);case"[object DataView]":return yc(e,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return Oc(e,r);case"[object Map]":case"[object Set]":return new n;case"[object Number]":case"[object String]":return new n(e);case"[object RegExp]":return _c(e);case"[object Symbol]":return gc(e)}},Sc=D,mc=Object.create,wc=function(){function e(){}return function(t){if(!Sc(t))return{};if(mc)return mc(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}(),Ec=Xa,Ac=Le;var Dc=function(e){return"function"!=typeof e.constructor||Ac(e)?{}:wc(Ec(e))},Nc=Vo,Rc=Ue;var kc=function(e){return Rc(e)&&"[object Map]"==Nc(e)},Cc=nt,Pc=it&&it.isMap,Mc=Pc?Cc(Pc):kc,xc=Vo,Ic=Ue;var Lc=function(e){return Ic(e)&&"[object Set]"==xc(e)},Tc=nt,Uc=it&&it.isSet,Fc=Uc?Tc(Uc):Lc,Wc=Bn,$c=dn,zc=oe,Gc=Na,Bc=Fa,Vc=$a,Xc=za,Yc=Va,qc=ec,Hc=mo,Kc=oc,Jc=Vo,Qc=ac,Zc=jc,es=Dc,ts=Ye,rs=Je,ns=Mc,os=D,is=Fc,as=At,cs=La,ss="[object Arguments]",us="[object Function]",ls="[object Object]",fs={};fs[ss]=fs["[object Array]"]=fs["[object ArrayBuffer]"]=fs["[object DataView]"]=fs["[object Boolean]"]=fs["[object Date]"]=fs["[object Float32Array]"]=fs["[object Float64Array]"]=fs["[object Int8Array]"]=fs["[object Int16Array]"]=fs["[object Int32Array]"]=fs["[object Map]"]=fs["[object Number]"]=fs[ls]=fs["[object RegExp]"]=fs["[object Set]"]=fs["[object String]"]=fs["[object Symbol]"]=fs["[object Uint8Array]"]=fs["[object Uint8ClampedArray]"]=fs["[object Uint16Array]"]=fs["[object Uint32Array]"]=!0,fs["[object Error]"]=fs[us]=fs["[object WeakMap]"]=!1;var hs=function e(t,r,n,o,i,a){var c,s=1&r,u=2&r,l=4&r;if(n&&(c=i?n(t,o,i,a):n(t)),void 0!==c)return c;if(!os(t))return t;var f=ts(t);if(f){if(c=Qc(t),!s)return Xc(t,c)}else{var h=Jc(t),v=h==us||"[object GeneratorFunction]"==h;if(rs(t))return Vc(t,s);if(h==ls||h==ss||v&&!i){if(c=u||v?{}:es(t),!s)return u?qc(t,Bc(c,t)):Yc(t,Gc(c,t))}else{if(!fs[h])return i?t:{};c=Zc(t,h,s)}}a||(a=new Wc);var p=a.get(t);if(p)return p;a.set(t,c),is(t)?t.forEach(function(o){c.add(e(o,r,n,o,t,a))}):ns(t)&&t.forEach(function(o,i){c.set(i,e(o,r,n,i,t,a))});var b=f?void 0:(l?u?Kc:Hc:u?cs:as)(t);return $c(b||t,function(o,i){b&&(o=t[i=o]),zc(c,i,e(o,r,n,i,t,a))}),c};var vs=sn,ps=function(e,t,r){var n=-1,o=e.length;t<0&&(t=-t>o?0:o+t),(r=r>o?o:r)<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+t];return i};var bs=function(e,t){return t.length<2?e:vs(e,ps(t,0,-1))},ds=rn,ys=function(e){var t=null==e?0:e.length;return t?e[t-1]:void 0},_s=bs,gs=on;var Os=function(e,t){return t=ds(t,e),null==(e=_s(e,t))||delete e[gs(ys(t))]},js=A,Ss=Xa,ms=Ue,ws=Function.prototype,Es=Object.prototype,As=ws.toString,Ds=Es.hasOwnProperty,Ns=As.call(Object);var Rs=function(e){if(!ms(e)||"[object Object]"!=js(e))return!1;var t=Ss(e);if(null===t)return!0;var r=Ds.call(t,"constructor")&&t.constructor;return"function"==typeof r&&r instanceof r&&As.call(r)==Ns};var ks=ca;var Cs=function(e){return(null==e?0:e.length)?ks(e,1):[]},Ps=fe,Ms=de;var xs=Br,Is=hs,Ls=Os,Ts=rn,Us=ce,Fs=function(e){return Rs(e)?void 0:e},Ws=oc,$s=function(e){return Ms(Ps(e,void 0,Cs),e+"")}(function(e,t){var r={};if(null==e)return r;var n=!1;t=xs(t,function(t){return t=Ts(t,e),n||(n=t.length>1),t}),Us(e,Ws(e),r),n&&(r=Is(r,7,Fs));for(var o=t.length;o--;)Ls(r,t[o]);return r}),zs=l($s);const Gs=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;EOL;constructor(e){switch(this.AppName=e,this.platform=process.platform,this.homedir=a.homedir(),this.EOL=a.EOL,this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=c.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||c.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||c.join(this.homedir,".config");break;default:console.log(`當前系統是未知的平台: ${this.platform}`),this.isMAC=!1,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=this.homedir}this.appFolder=c.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...e){return c.join(...e)}folderCheck(e){i.mkdirSync(e,{recursive:!0})}fileCheck(e){i.existsSync(e)||i.writeFileSync(e,"",{encoding:"utf8"})}}("aiia-sdk");class Bs{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=Gs.addPath(Gs.appFolder,this.fileName),Gs.fileCheck(this.filePath)}getFileDataSync(){const e=i.readFileSync(this.filePath,"utf8");try{return JSON.parse(e)}catch(e){return{}}}setFileDataSync(e){try{const t=JSON.stringify(e);i.writeFileSync(this.filePath,t,"utf8")}catch(e){}}async getFileData(){return new Promise(e=>{i.readFile(this.filePath,"utf8",(t,r)=>{if(t)e({});else try{e(JSON.parse(r))}catch(t){e({})}})})}async setFileData(e){return new Promise(t=>{try{const r=JSON.stringify(e);i.writeFile(this.filePath,r,"utf8",e=>{t()})}catch(e){}})}async getItem(e){return(await this.getFileData())[e]??null}async setItem(e,t){const r=await this.getFileData();r[e]=t,await this.setFileData(r)}async removeItem(e){const t=await this.getFileData(),r=zs(t,e);await this.setFileData(r)}async clear(){await this.setFileData({})}getItemSync(e){return this.getFileDataSync()[e]??null}setItemSync(e,t){const r=this.getFileDataSync();r[e]=t,this.setFileDataSync(r)}removeItemSync(e){const t=zs(this.getFileDataSync(),e);this.setFileDataSync(t)}clearSync(){this.setFileDataSync({})}}class Vs{config;constructor(e){this.config=e,console.log("UEProxy, config=",e)}start(){console.log("UEProxy, start proxy")}send(e){let t=this.cloudToObj(e);if(t&&t.signal&&"osc"==t.signal){console.log("UEProxy, payload=",t);try{let e=t.content;const r=new s.Client(e.host,e.port);console.debug("UEProxy, client open to port "+e.port),r.send(e.message,e=>{e&&console.error(e),r.close(),console.debug("UEProxy, client closed")})}catch(e){console.log(e)}}}cloudToObj(e){try{return JSON.parse(e)}catch(e){console.error("message transfer fail",e)}}onDestroy(){console.log("UEProxy, destroy proxy")}}class Xs{filePath;fileName;constructor(){this.fileName="log.txt",this.filePath=Gs.addPath(Gs.appFolder,this.fileName)}next(e,t,...r){try{const n=r.reduce((e,t)=>{switch(typeof t){case"string":case"number":case"bigint":return`${e} ${t.toString()}`;case"boolean":return`${e} ${t?"true":"false"}`;case"object":try{return`${e} ${JSON.stringify(t)}`}catch(t){return e}case"symbol":case"undefined":case"function":return`${e} [${typeof t}]`}},"");i.appendFileSync(this.filePath,`LOG(${e})__${t}__::${n}${Gs.EOL}`,{encoding:"utf8"})}catch(e){}}}class Ys{config;stroage;apiProxy;chat;udpProxy;isStart;channelMap;destorySub;access_token;get accessToken(){return this.access_token}constructor(e,t){this.config=e,this.stroage=t,this.isStart=!1,this.destorySub=new r.Subject,this.channelMap=new Map,this.access_token=t.getItemSync(vn),this.apiProxy=new wa(this.config.endPoint.api),Cn.code(An["指定模組初始化完成"],"api"),this.chat=new ma(this.config),Cn.code(An["指定模組初始化完成"],"chat"),this.udpProxy=new Vs(this.config),Cn.code(An["指定模組初始化完成"],"udp")}async start(){if(this.isStart)throw new Error(ln["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.memberChange.pipe(r.takeUntil(this.destorySub)).subscribe(({type:e,socket:t})=>{switch(e){case"in":{Cn.debug("member join",t.id);const e=new Ea,o=new r.Subject,i=(n=t.handshake.query.uuid,qe(n)?hn(n,"[0]",void 0):n??void 0);void 0===i?(this.getProjectList().then(e=>{t.emit("list",e)}),r.fromEvent(t,"uuid").pipe(r.take(1),r.takeUntil(o)).subscribe(r=>{this.openChannel(r,t,e,o)})):this.openChannel(i,t,e,o),this.channelMap.set(t.id,()=>{o.next(),o.complete()});break}case"out":Cn.debug("member leave",t.id),this.channelMap.has(t.id)&&(this.channelMap.get(t.id)(),this.channelMap.delete(t.id))}var n}),this.chat.start(),Cn.code(An["啟動服務"],"chat"),this.udpProxy.start(),Cn.code(An["啟動服務"],"udp")}async replaceAccessToken(){const e=await this.apiProxy.getAccessToken(this.config.license,this.access_token);return this.access_token=e,this.stroage.setItemSync(vn,e),e}async getProjectList(){return await this.apiProxy.getProjectList(this.config.license)}getProxySocketURL(e){return`${this.config.endPoint.socket}/v1/chat/project/${this.accessToken}/${e}`}openChannel(e,t,n,o){r.fromEvent(t,"cloud").pipe(r.takeUntil(o)).subscribe(e=>{n.send(e)}),n.message.pipe(r.takeUntil(o)).subscribe(e=>{t.emit("cloud",e),this.udpProxy.send(e)}),n.close.pipe(r.takeUntil(o)).subscribe(async r=>{switch(t.emit("channel",r),r){case"close":case"no_permissions":n.onDestroy();break;case"reconnect":await this.replaceAccessToken(),n.reconnect(this.getProxySocketURL(e))}}),n.linkStart.pipe(r.takeUntil(o)).subscribe(()=>{t.emit("channel","open")}),o.subscribe(()=>{n.onClose()}),n.start(this.getProxySocketURL(e))}onDestroy(){this.apiProxy.onDestroy(),this.chat.onDestroy(),this.udpProxy.onDestroy(),this.destorySub.next(),this.destorySub.complete(),Cn.code(An["服務結束"])}}exports.aiiaCore=function(e){if(pn){if(void 0===hn(e,"license",void 0))throw new Error(ln["未提供憑證"]);!function(e){const{info:t,error:r,warn:n,debug:o,fatal:i,code:a}=function(e){if(void 0===e||"all"===e)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===e)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof e)return{code:e,error:e,warn:e,info:e,debug:e,fatal:e};{const t=new Set(e);return{code:t.has("code"),debug:t.has("debug"),fatal:t.has("fatal"),error:t.has("error"),warn:t.has("warn"),info:t.has("info")}}}(e);return a||(Nn.code=()=>{}),o||(Nn.debug=()=>{}),t||(Nn.info=()=>{}),n||(Nn.warn=()=>{}),r||(Nn.error=()=>{}),i||(Nn.fatal=()=>{}),kn}(hn(e,"debug",!0))(new Xs),Cn.code(An["開始初始化必要模組"]);const t=new bn(xt({},e));Cn.code(An["指定模組初始化完成"],"config");const r=new Bs;Cn.code(An["指定模組初始化完成"],"storage");const n=new Ys(t,r);return Cn.code(An["指定模組初始化完成"],"core"),n.start(),Cn.code(An["啟動服務"]),()=>{n.onDestroy()}}throw new Error(ln["環境錯誤(nodejs)"])};
package/dist/node.d.ts CHANGED
@@ -82,6 +82,15 @@ declare interface InitOptions {
82
82
  * Switch message(info, error, warn) dispaly, default: true
83
83
  */
84
84
  debug?: boolean | "all" | "none" | LoggerLevel[];
85
+ /**
86
+ * [zh]
87
+ * 授權的媒體裝置,請包含麥克風及鏡頭/攝影機權限
88
+ *
89
+ * [en]
90
+ * Authorized media devices, please include microphone and lens/camera permissions.
91
+ *
92
+ * https://developer.mozilla.org/en-US/docs/Web/API/MediaStream
93
+ */
85
94
  mediaStream?: MediaStream;
86
95
  /**
87
96
  * [zh]
@@ -99,11 +108,41 @@ declare interface InitOptions {
99
108
  * Specify the sampling rate of audio output (provided for LLM analysis). Changing is not recommended.
100
109
  */
101
110
  llmSampleRate?: number;
111
+ /**
112
+ * [zh]
113
+ * 人臉辨識
114
+ *
115
+ * frame: 每幾幀更新一次, 預設: 3
116
+ *
117
+ * confidence: 分數(0 ~ 100), 預設: 80
118
+ *
119
+ * [en]
120
+ * facial recognition
121
+ *
122
+ * frame: Update every few frames, default: 3
123
+ *
124
+ * confidence: score(0 ~ 100), default: 80
125
+ */
126
+ faceDetection?: {
127
+ frame?: number;
128
+ confidence?: number;
129
+ };
130
+ /**
131
+ * [zh]
132
+ * 清除字幕,可指定時間(毫秒),預設 3000 毫秒後清除
133
+ *
134
+ * [en]
135
+ * Clear subtitles, you can specify the time (milliseconds), the default is to clear after 3000 milliseconds.
136
+ */
137
+ autoClearSubtitle?: {
138
+ user?: boolean | number;
139
+ aiia?: boolean | number;
140
+ };
102
141
  }
103
142
 
104
143
  declare type LoggerLevel = "info" | "error" | "warn" | "debug" | "fatal" | "code";
105
144
 
106
- export declare type NodeInitOptions = Omit<InitOptions, "project" | "ws_url" | "worklet_url" | "mediaStream" | "chunkTimeInSeconds" | "llmSampleRate">;
145
+ export declare type NodeInitOptions = Omit<InitOptions, "project" | "ws_url" | "worklet_url" | "mediaStream" | "chunkTimeInSeconds" | "llmSampleRate" | "autoClearSubtitle">;
107
146
 
108
147
  declare type Webserver = Server<any, any> | Server_2<any, any> | Http2SecureServer<any, any, any, any> | Http2Server<any, any, any, any>;
109
148
 
package/dist/node.mjs CHANGED
@@ -1 +1 @@
1
- import t from"moment";import{Server as e}from"socket.io";import{Subject as r,fromEvent as n,takeUntil as o,take as i}from"rxjs";import a from"axios";import c from"ws";import s from"fs";import u from"os";import f from"path";var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function h(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var p="object"==typeof l&&l&&l.Object===Object&&l,v=p,b="object"==typeof self&&self&&self.Object===Object&&self,d=v||b||Function("return this")(),y=d.Symbol,_=y,g=Object.prototype,O=g.hasOwnProperty,j=g.toString,S=_?_.toStringTag:void 0;var m=function(t){var e=O.call(t,S),r=t[S];try{t[S]=void 0;var n=!0}catch(t){}var o=j.call(t);return n&&(e?t[S]=r:delete t[S]),o},w=Object.prototype.toString;var E=m,A=function(t){return w.call(t)},D=y?y.toStringTag:void 0;var N=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":D&&D in Object(t)?E(t):A(t)};var R=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},M=N,C=R;var P,k=function(t){if(!C(t))return!1;var e=M(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},I=d["__core-js_shared__"],L=(P=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+P:"";var T=function(t){return!!L&&L in t},x=Function.prototype.toString;var F=function(t){if(null!=t){try{return x.call(t)}catch(t){}try{return t+""}catch(t){}}return""},U=k,$=T,W=R,z=F,G=/^\[object .+?Constructor\]$/,B=Function.prototype,V=Object.prototype,X=B.toString,Y=V.hasOwnProperty,H=RegExp("^"+X.call(Y).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var K=function(t){return!(!W(t)||$(t))&&(U(t)?H:G).test(z(t))},Q=function(t,e){return null==t?void 0:t[e]};var J=function(t,e){var r=Q(t,e);return K(r)?r:void 0},q=J,Z=function(){try{var t=q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),tt=Z;var et=function(t,e,r){"__proto__"==e&&tt?tt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var rt=function(t,e){return t===e||t!=t&&e!=e},nt=et,ot=rt,it=Object.prototype.hasOwnProperty;var at=function(t,e,r){var n=t[e];it.call(t,e)&&ot(n,r)&&(void 0!==r||e in t)||nt(t,e,r)},ct=at,st=et;var ut=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var c=e[i],s=n?n(r[c],t[c],c,r,t):void 0;void 0===s&&(s=t[c]),o?st(r,c,s):ct(r,c,s)}return r};var ft=function(t){return t};var lt=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)},ht=Math.max;var pt=function(t,e,r){return e=ht(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=ht(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(a),lt(t,this,c)}};var vt=function(t){return function(){return t}},bt=Z,dt=bt?function(t,e){return bt(t,"toString",{configurable:!0,enumerable:!1,value:vt(e),writable:!0})}:ft,yt=Date.now;var _t=function(t){var e=0,r=0;return function(){var n=yt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(dt),gt=ft,Ot=pt,jt=_t;var St=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},mt=k,wt=St;var Et=function(t){return null!=t&&wt(t.length)&&!mt(t)},At=/^(?:0|[1-9]\d*)$/;var Dt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&At.test(t))&&t>-1&&t%1==0&&t<e},Nt=rt,Rt=Et,Mt=Dt,Ct=R;var Pt=function(t,e){return jt(Ot(t,e,gt),t+"")},kt=function(t,e,r){if(!Ct(r))return!1;var n=typeof e;return!!("number"==n?Rt(r)&&Mt(e,r.length):"string"==n&&e in r)&&Nt(r[e],t)};var It=function(t){return Pt(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,a&&kt(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var c=r[n];c&&t(e,c,n,i)}return e})},Lt=Object.prototype;var Tt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Lt)};var xt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Ft=function(t){return null!=t&&"object"==typeof t},Ut=N,$t=Ft;var Wt=function(t){return $t(t)&&"[object Arguments]"==Ut(t)},zt=Ft,Gt=Object.prototype,Bt=Gt.hasOwnProperty,Vt=Gt.propertyIsEnumerable,Xt=Wt(function(){return arguments}())?Wt:function(t){return zt(t)&&Bt.call(t,"callee")&&!Vt.call(t,"callee")},Yt=Array.isArray,Ht=h(Yt),Kt={exports:{}};var Qt=function(){return!1};!function(t,e){var r=d,n=Qt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,c=(a?a.isBuffer:void 0)||n;t.exports=c}(Kt,Kt.exports);var Jt=Kt.exports,qt=N,Zt=St,te=Ft,ee={};ee["[object Float32Array]"]=ee["[object Float64Array]"]=ee["[object Int8Array]"]=ee["[object Int16Array]"]=ee["[object Int32Array]"]=ee["[object Uint8Array]"]=ee["[object Uint8ClampedArray]"]=ee["[object Uint16Array]"]=ee["[object Uint32Array]"]=!0,ee["[object Arguments]"]=ee["[object Array]"]=ee["[object ArrayBuffer]"]=ee["[object Boolean]"]=ee["[object DataView]"]=ee["[object Date]"]=ee["[object Error]"]=ee["[object Function]"]=ee["[object Map]"]=ee["[object Number]"]=ee["[object Object]"]=ee["[object RegExp]"]=ee["[object Set]"]=ee["[object String]"]=ee["[object WeakMap]"]=!1;var re=function(t){return te(t)&&Zt(t.length)&&!!ee[qt(t)]};var ne=function(t){return function(e){return t(e)}},oe={exports:{}};!function(t,e){var r=p,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n&&r.process,a=function(){try{var t=o&&o.require&&o.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=a}(oe,oe.exports);var ie=oe.exports,ae=re,ce=ne,se=ie&&ie.isTypedArray,ue=se?ce(se):ae,fe=xt,le=Xt,he=Yt,pe=Jt,ve=Dt,be=ue,de=Object.prototype.hasOwnProperty;var ye=function(t,e){var r=he(t),n=!r&&le(t),o=!r&&!n&&pe(t),i=!r&&!n&&!o&&be(t),a=r||n||o||i,c=a?fe(t.length,String):[],s=c.length;for(var u in t)!e&&!de.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||ve(u,s))||c.push(u);return c};var _e=function(t,e){return function(r){return t(e(r))}},ge=_e(Object.keys,Object),Oe=Tt,je=ge,Se=Object.prototype.hasOwnProperty;var me=ye,we=function(t){if(!Oe(t))return je(t);var e=[];for(var r in Object(t))Se.call(t,r)&&"constructor"!=r&&e.push(r);return e},Ee=Et;var Ae=function(t){return Ee(t)?me(t):we(t)},De=at,Ne=ut,Re=It,Me=Et,Ce=Tt,Pe=Ae,ke=Object.prototype.hasOwnProperty,Ie=h(Re(function(t,e){if(Ce(e)||Me(e))Ne(e,Pe(e),t);else for(var r in e)ke.call(e,r)&&De(t,r,e[r])})),Le=N,Te=Ft;var xe=function(t){return"symbol"==typeof t||Te(t)&&"[object Symbol]"==Le(t)},Fe=Yt,Ue=xe,$e=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,We=/^\w*$/;var ze=function(t,e){if(Fe(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Ue(t))||(We.test(t)||!$e.test(t)||null!=e&&t in Object(e))},Ge=J(Object,"create"),Be=Ge;var Ve=function(){this.__data__=Be?Be(null):{},this.size=0};var Xe=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ye=Ge,He=Object.prototype.hasOwnProperty;var Ke=function(t){var e=this.__data__;if(Ye){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return He.call(e,t)?e[t]:void 0},Qe=Ge,Je=Object.prototype.hasOwnProperty;var qe=Ge;var Ze=Ve,tr=Xe,er=Ke,rr=function(t){var e=this.__data__;return Qe?void 0!==e[t]:Je.call(e,t)},nr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=qe&&void 0===e?"__lodash_hash_undefined__":e,this};function or(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])}}or.prototype.clear=Ze,or.prototype.delete=tr,or.prototype.get=er,or.prototype.has=rr,or.prototype.set=nr;var ir=or;var ar=function(){this.__data__=[],this.size=0},cr=rt;var sr=function(t,e){for(var r=t.length;r--;)if(cr(t[r][0],e))return r;return-1},ur=sr,fr=Array.prototype.splice;var lr=sr;var hr=sr;var pr=sr;var vr=ar,br=function(t){var e=this.__data__,r=ur(e,t);return!(r<0)&&(r==e.length-1?e.pop():fr.call(e,r,1),--this.size,!0)},dr=function(t){var e=this.__data__,r=lr(e,t);return r<0?void 0:e[r][1]},yr=function(t){return hr(this.__data__,t)>-1},_r=function(t,e){var r=this.__data__,n=pr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function gr(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])}}gr.prototype.clear=vr,gr.prototype.delete=br,gr.prototype.get=dr,gr.prototype.has=yr,gr.prototype.set=_r;var Or=gr,jr=J(d,"Map"),Sr=ir,mr=Or,wr=jr;var Er=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Ar=function(t,e){var r=t.__data__;return Er(e)?r["string"==typeof e?"string":"hash"]:r.map},Dr=Ar;var Nr=Ar;var Rr=Ar;var Mr=Ar;var Cr=function(){this.size=0,this.__data__={hash:new Sr,map:new(wr||mr),string:new Sr}},Pr=function(t){var e=Dr(this,t).delete(t);return this.size-=e?1:0,e},kr=function(t){return Nr(this,t).get(t)},Ir=function(t){return Rr(this,t).has(t)},Lr=function(t,e){var r=Mr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Tr(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])}}Tr.prototype.clear=Cr,Tr.prototype.delete=Pr,Tr.prototype.get=kr,Tr.prototype.has=Ir,Tr.prototype.set=Lr;var xr=Tr,Fr=xr;function Ur(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],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Ur.Cache||Fr),r}Ur.Cache=Fr;var $r=Ur;var Wr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,zr=/\\(\\)?/g,Gr=function(t){var e=$r(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(Wr,function(t,r,n,o){e.push(n?o.replace(zr,"$1"):r||t)}),e});var Br=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},Vr=Br,Xr=Yt,Yr=xe,Hr=y?y.prototype:void 0,Kr=Hr?Hr.toString:void 0;var Qr=function t(e){if("string"==typeof e)return e;if(Xr(e))return Vr(e,t)+"";if(Yr(e))return Kr?Kr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Jr=Qr;var qr=Yt,Zr=ze,tn=Gr,en=function(t){return null==t?"":Jr(t)};var rn=function(t,e){return qr(t)?t:Zr(t,e)?[t]:tn(en(t))},nn=xe;var on=function(t){if("string"==typeof t||nn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},an=rn,cn=on;var sn=function(t,e){for(var r=0,n=(e=an(e,t)).length;null!=t&&r<n;)t=t[cn(e[r++])];return r&&r==n?t:void 0},un=sn;var fn,ln=function(t,e,r){var n=null==t?void 0:un(t,e);return void 0===n?r:n},hn=h(ln);!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: 2005"}(fn||(fn={}));const pn="access_token",vn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class bn{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}=Ie({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Ie({},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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}constructor(t){this.config=t}}var dn=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var yn=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),c=a.length;c--;){var s=a[t?c:++o];if(!1===r(i[s],s,i))break}return e}}(),_n=Ae;var gn=Et;var On=function(t,e){return function(r,n){if(null==r)return r;if(!gn(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(t,e){return t&&yn(t,e,_n)}),jn=ft;var Sn=dn,mn=On,wn=function(t){return"function"==typeof t?t:jn},En=Yt;var An,Dn=h(function(t,e){return(En(t)?Sn:mn)(t,wn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(An||(An={}));const Nn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},Rn=[];function Mn(t){return Rn.push(t),Mn}const Cn=new Proxy(Nn,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const o=t().format("yyyy-MM-DD[T]HH:mm:ss");Dn(Rn,t=>{t.next(r,o,...n)}),e[r](`[Aiia::${r}_${o}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});class Pn{config;server;memberSub;get port(){return this.config.port}get webserver(){return this.config.webserver}get memberChange(){return this.memberSub.asObservable()}constructor(t){this.config=t,this.memberSub=new r}start(){this.server=new e(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{this.memberSub.next({type:"in",socket:t}),Cn.debug("client on",t.id),t.on("disconnect",e=>{this.memberSub.next({type:"out",socket:t}),Cn.debug("client off",e)})}),void 0===this.webserver&&this.server.listen(this.port)}onDestory(){this.server&&this.server.close()}}var kn=Or;var In=Or,Ln=jr,Tn=xr;var xn=Or,Fn=function(){this.__data__=new kn,this.size=0},Un=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},$n=function(t){return this.__data__.get(t)},Wn=function(t){return this.__data__.has(t)},zn=function(t,e){var r=this.__data__;if(r instanceof In){var n=r.__data__;if(!Ln||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Tn(n)}return r.set(t,e),this.size=r.size,this};function Gn(t){var e=this.__data__=new xn(t);this.size=e.size}Gn.prototype.clear=Fn,Gn.prototype.delete=Un,Gn.prototype.get=$n,Gn.prototype.has=Wn,Gn.prototype.set=zn;var Bn=Gn;var Vn=xr,Xn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Yn=function(t){return this.__data__.has(t)};function Hn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Vn;++e<r;)this.add(t[e])}Hn.prototype.add=Hn.prototype.push=Xn,Hn.prototype.has=Yn;var Kn=Hn,Qn=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},Jn=function(t,e){return t.has(e)};var qn=function(t,e,r,n,o,i){var a=1&r,c=t.length,s=e.length;if(c!=s&&!(a&&s>c))return!1;var u=i.get(t),f=i.get(e);if(u&&f)return u==e&&f==t;var l=-1,h=!0,p=2&r?new Kn:void 0;for(i.set(t,e),i.set(e,t);++l<c;){var v=t[l],b=e[l];if(n)var d=a?n(b,v,l,e,t,i):n(v,b,l,t,e,i);if(void 0!==d){if(d)continue;h=!1;break}if(p){if(!Qn(e,function(t,e){if(!Jn(p,e)&&(v===t||o(v,t,r,n,i)))return p.push(e)})){h=!1;break}}else if(v!==b&&!o(v,b,r,n,i)){h=!1;break}}return i.delete(t),i.delete(e),h},Zn=d.Uint8Array;var to=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var eo=Zn,ro=rt,no=qn,oo=to,io=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},ao=y?y.prototype:void 0,co=ao?ao.valueOf:void 0;var so=function(t,e,r,n,o,i,a){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||!i(new eo(t),new eo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return ro(+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 c=oo;case"[object Set]":var s=1&n;if(c||(c=io),t.size!=e.size&&!s)return!1;var u=a.get(t);if(u)return u==e;n|=2,a.set(t,e);var f=no(c(t),c(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(co)return co.call(t)==co.call(e)}return!1};var uo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},fo=uo,lo=Yt;var ho=function(t,e,r){var n=e(t);return lo(t)?n:fo(n,r(t))};var po=function(){return[]},vo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i},bo=po,yo=Object.prototype.propertyIsEnumerable,_o=Object.getOwnPropertySymbols,go=_o?function(t){return null==t?[]:(t=Object(t),vo(_o(t),function(e){return yo.call(t,e)}))}:bo,Oo=ho,jo=go,So=Ae;var mo=function(t){return Oo(t,So,jo)},wo=mo,Eo=Object.prototype.hasOwnProperty;var Ao=function(t,e,r,n,o,i){var a=1&r,c=wo(t),s=c.length;if(s!=wo(e).length&&!a)return!1;for(var u=s;u--;){var f=c[u];if(!(a?f in e:Eo.call(e,f)))return!1}var l=i.get(t),h=i.get(e);if(l&&h)return l==e&&h==t;var p=!0;i.set(t,e),i.set(e,t);for(var v=a;++u<s;){var b=t[f=c[u]],d=e[f];if(n)var y=a?n(d,b,f,e,t,i):n(b,d,f,t,e,i);if(!(void 0===y?b===d||o(b,d,r,n,i):y)){p=!1;break}v||(v="constructor"==f)}if(p&&!v){var _=t.constructor,g=e.constructor;_==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(p=!1)}return i.delete(t),i.delete(e),p},Do=J(d,"DataView"),No=jr,Ro=J(d,"Promise"),Mo=J(d,"Set"),Co=J(d,"WeakMap"),Po=N,ko=F,Io="[object Map]",Lo="[object Promise]",To="[object Set]",xo="[object WeakMap]",Fo="[object DataView]",Uo=ko(Do),$o=ko(No),Wo=ko(Ro),zo=ko(Mo),Go=ko(Co),Bo=Po;(Do&&Bo(new Do(new ArrayBuffer(1)))!=Fo||No&&Bo(new No)!=Io||Ro&&Bo(Ro.resolve())!=Lo||Mo&&Bo(new Mo)!=To||Co&&Bo(new Co)!=xo)&&(Bo=function(t){var e=Po(t),r="[object Object]"==e?t.constructor:void 0,n=r?ko(r):"";if(n)switch(n){case Uo:return Fo;case $o:return Io;case Wo:return Lo;case zo:return To;case Go:return xo}return e});var Vo=Bo,Xo=Bn,Yo=qn,Ho=so,Ko=Ao,Qo=Vo,Jo=Yt,qo=Jt,Zo=ue,ti="[object Arguments]",ei="[object Array]",ri="[object Object]",ni=Object.prototype.hasOwnProperty;var oi=function(t,e,r,n,o,i){var a=Jo(t),c=Jo(e),s=a?ei:Qo(t),u=c?ei:Qo(e),f=(s=s==ti?ri:s)==ri,l=(u=u==ti?ri:u)==ri,h=s==u;if(h&&qo(t)){if(!qo(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Xo),a||Zo(t)?Yo(t,e,r,n,o,i):Ho(t,e,s,r,n,o,i);if(!(1&r)){var p=f&&ni.call(t,"__wrapped__"),v=l&&ni.call(e,"__wrapped__");if(p||v){var b=p?t.value():t,d=v?e.value():e;return i||(i=new Xo),o(b,d,r,n,i)}}return!!h&&(i||(i=new Xo),Ko(t,e,r,n,o,i))},ii=Ft;var ai=function t(e,r,n,o,i){return e===r||(null==e||null==r||!ii(e)&&!ii(r)?e!=e&&r!=r:oi(e,r,n,o,t,i))},ci=Bn,si=ai;var ui=R;var fi=function(t){return t==t&&!ui(t)},li=fi,hi=Ae;var pi=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},vi=function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var c=r[o];if(a&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<i;){var s=(c=r[o])[0],u=t[s],f=c[1];if(a&&c[2]){if(void 0===u&&!(s in t))return!1}else{var l=new ci;if(n)var h=n(u,f,s,t,e,l);if(!(void 0===h?si(f,u,3,n,l):h))return!1}}return!0},bi=function(t){for(var e=hi(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,li(o)]}return e},di=pi;var yi=rn,_i=Xt,gi=Yt,Oi=Dt,ji=St,Si=on;var mi=function(t,e,r){for(var n=-1,o=(e=yi(e,t)).length,i=!1;++n<o;){var a=Si(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&ji(o)&&Oi(a,o)&&(gi(t)||_i(t))},wi=function(t,e){return null!=t&&e in Object(t)},Ei=mi;var Ai=function(t,e){return null!=t&&Ei(t,e,wi)},Di=ai,Ni=ln,Ri=Ai,Mi=ze,Ci=fi,Pi=pi,ki=on;var Ii=function(t,e){return Mi(t)&&Ci(e)?Pi(ki(t),e):function(r){var n=Ni(r,t);return void 0===n&&n===e?Ri(r,t):Di(e,n,3)}};var Li=sn;var Ti=function(t){return function(e){return Li(e,t)}},xi=function(t){return function(e){return null==e?void 0:e[t]}},Fi=Ti,Ui=ze,$i=on;var Wi=function(t){return Ui(t)?xi($i(t)):Fi(t)},zi=function(t){var e=bi(t);return 1==e.length&&e[0][2]?di(e[0][0],e[0][1]):function(r){return r===t||vi(r,t,e)}},Gi=Ii,Bi=ft,Vi=Yt,Xi=Wi;var Yi=On,Hi=Et;var Ki=Br,Qi=function(t){return"function"==typeof t?t:null==t?Bi:"object"==typeof t?Vi(t)?Gi(t[0],t[1]):zi(t):Xi(t)},Ji=function(t,e){var r=-1,n=Hi(t)?Array(t.length):[];return Yi(t,function(t,o,i){n[++r]=e(t,o,i)}),n},qi=Yt;var Zi,ta=h(function(t,e){return(qi(t)?Ki:Ji)(t,Qi(e))});class ea{instance;controller;constructor(t){this.controller=new AbortController,this.instance=a.create({baseURL:t,signal:this.controller.signal})}async getAccessToken(t,e){const r={license_number:t,token_value:e??""},n=await this.instance.post("/api/v1/license/agent_token",r).then(t=>hn(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(fn["網絡錯誤"]);if(""===n)throw new Error(fn["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>ta(hn(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(fn["網絡錯誤"]);if(0===e.length)throw new Error(fn["沒有可用專案"]);return e}onDestory(){this.controller.abort()}}!function(t){t[t.MDN_NORMAL_CLOSURE=1e3]="MDN_NORMAL_CLOSURE",t[t.MDN_GOING_AWAY=1001]="MDN_GOING_AWAY",t[t.MDN_PROTOCOL_ERROR=1002]="MDN_PROTOCOL_ERROR",t[t.MDN_UNSUPPORTED_DATA=1003]="MDN_UNSUPPORTED_DATA",t[t.MDN_RESERVED_1004=1004]="MDN_RESERVED_1004",t[t.MDN_NO_STATUS_RECEIVED=1005]="MDN_NO_STATUS_RECEIVED",t[t.MDN_ABNORMAL_CLOSURE=1006]="MDN_ABNORMAL_CLOSURE",t[t.MDN_INVALID_FRAME_PAYLOAD=1007]="MDN_INVALID_FRAME_PAYLOAD",t[t.MDN_POLICY_VIOLATION=1008]="MDN_POLICY_VIOLATION",t[t.MDN_MESSAGE_TOO_BIG=1009]="MDN_MESSAGE_TOO_BIG",t[t.MDN_MANDATORY_EXTENSION=1010]="MDN_MANDATORY_EXTENSION",t[t.MDN_INTERNAL_ERROR=1011]="MDN_INTERNAL_ERROR",t[t.MDN_SERVICE_RESTART=1012]="MDN_SERVICE_RESTART",t[t.MDN_TRY_AGAIN_LATER=1013]="MDN_TRY_AGAIN_LATER",t[t.MDN_BAD_GATEWAY=1014]="MDN_BAD_GATEWAY",t[t.MDN_TLS_HANDSHAKE=1015]="MDN_TLS_HANDSHAKE",t[t.MANUAL_CLOSE=4001]="MANUAL_CLOSE",t[t.WS_5000_NORAML_CLOSURE=5e3]="WS_5000_NORAML_CLOSURE",t[t.WS_5001_UNAUTHORIZED=5001]="WS_5001_UNAUTHORIZED",t[t.WS_5002_LICENSE_EXPIRED=5002]="WS_5002_LICENSE_EXPIRED",t[t.WS_5003_TOKEN_EXPIRED=5003]="WS_5003_TOKEN_EXPIRED"}(Zi||(Zi={}));class ra{socket;messageSub;linkStartSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get linkStart(){return this.linkStartSub.asObservable()}messageQueue=[];isConnected;constructor(){this.isConnected=!1,this.messageSub=new r,this.linkStartSub=new r,this.closeSub=new r,this.destorySub=new r}start(t){this.socket=new c(t,{autoPong:!0}),n(this.socket,"open").pipe(o(this.destorySub)).subscribe(()=>{this.isConnected=!0,this.linkStartSub.next(),Cn.code(An["啟動服務"],"proxy"),this.flushMessageQueue()}),n(this.socket,"message").pipe(o(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),n(this.socket,"error").pipe(o(this.destorySub)).subscribe(t=>{const{error:e}=t;Cn.error("Proxy has some problem",e)}),n(this.socket,"close").pipe(o(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e,reason:r}=t;switch(e){case Zi.MANUAL_CLOSE:Cn.code(An["無副作用的關閉連線"]);break;case Zi.WS_5000_NORAML_CLOSURE:case Zi.MDN_NORMAL_CLOSURE:case Zi.MDN_GOING_AWAY:this.closeSub.next("close"),Cn.code(An["安全的關閉連線"]);break;case Zi.MDN_NO_STATUS_RECEIVED:case Zi.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),Cn.code(An["與雲端的服務中斷"],{code:e,reason:r});break;case Zi.WS_5001_UNAUTHORIZED:case Zi.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),Cn.code(An["沒有授權,請聯繫Graphen"]);break;case Zi.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect"),Cn.code(An["自動重新連線連端服務"]);break;default:this.closeSub.next("close"),Cn.code(An["未預期的斷線,請聯繫Graphen"],{code:e,reason:r})}})}reconnect(t){this.onDestory(),this.destorySub=new r,this.start(t)}flushMessageQueue(){for(;this.messageQueue.length>0&&this.isConnected&&void 0!==this.socket;){const t=this.messageQueue.shift();t&&this.socket.send(t)}}send(t){this.isConnected&&void 0!==this.socket?this.socket.send(t):this.messageQueue.push(t)}onClose(){this.socket?.close(Zi.MANUAL_CLOSE)}onDestory(){this.destorySub.next(),this.destorySub.complete()}}var na=ut,oa=Ae;var ia=function(t,e){return t&&na(e,oa(e),t)};var aa=R,ca=Tt,sa=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},ua=Object.prototype.hasOwnProperty;var fa=ye,la=function(t){if(!aa(t))return sa(t);var e=ca(t),r=[];for(var n in t)("constructor"!=n||!e&&ua.call(t,n))&&r.push(n);return r},ha=Et;var pa=function(t){return ha(t)?fa(t,!0):la(t)},va=ut,ba=pa;var da=function(t,e){return t&&va(e,ba(e),t)},ya={exports:{}};!function(t,e){var r=d,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n?r.Buffer:void 0,a=i?i.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var r=t.length,n=a?a(r):new t.constructor(r);return t.copy(n),n}}(ya,ya.exports);var _a=ya.exports;var ga=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e},Oa=ut,ja=go;var Sa=function(t,e){return Oa(t,ja(t),e)},ma=_e(Object.getPrototypeOf,Object),wa=uo,Ea=ma,Aa=go,Da=po,Na=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)wa(e,Aa(t)),t=Ea(t);return e}:Da,Ra=ut,Ma=Na;var Ca=function(t,e){return Ra(t,Ma(t),e)},Pa=ho,ka=Na,Ia=pa;var La=function(t){return Pa(t,Ia,ka)},Ta=Object.prototype.hasOwnProperty;var xa=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Ta.call(t,"index")&&(r.index=t.index,r.input=t.input),r},Fa=Zn;var Ua=function(t){var e=new t.constructor(t.byteLength);return new Fa(e).set(new Fa(t)),e},$a=Ua;var Wa=function(t,e){var r=e?$a(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},za=/\w*$/;var Ga=function(t){var e=new t.constructor(t.source,za.exec(t));return e.lastIndex=t.lastIndex,e},Ba=y?y.prototype:void 0,Va=Ba?Ba.valueOf:void 0;var Xa=Ua;var Ya=Ua,Ha=Wa,Ka=Ga,Qa=function(t){return Va?Object(Va.call(t)):{}},Ja=function(t,e){var r=e?Xa(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var qa=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return Ya(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return Ha(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return Ja(t,r);case"[object Map]":case"[object Set]":return new n;case"[object Number]":case"[object String]":return new n(t);case"[object RegExp]":return Ka(t);case"[object Symbol]":return Qa(t)}},Za=R,tc=Object.create,ec=function(){function t(){}return function(e){if(!Za(e))return{};if(tc)return tc(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),rc=ma,nc=Tt;var oc=function(t){return"function"!=typeof t.constructor||nc(t)?{}:ec(rc(t))},ic=Vo,ac=Ft;var cc=function(t){return ac(t)&&"[object Map]"==ic(t)},sc=ne,uc=ie&&ie.isMap,fc=uc?sc(uc):cc,lc=Vo,hc=Ft;var pc=function(t){return hc(t)&&"[object Set]"==lc(t)},vc=ne,bc=ie&&ie.isSet,dc=bc?vc(bc):pc,yc=Bn,_c=dn,gc=at,Oc=ia,jc=da,Sc=_a,mc=ga,wc=Sa,Ec=Ca,Ac=mo,Dc=La,Nc=Vo,Rc=xa,Mc=qa,Cc=oc,Pc=Yt,kc=Jt,Ic=fc,Lc=R,Tc=dc,xc=Ae,Fc=pa,Uc="[object Arguments]",$c="[object Function]",Wc="[object Object]",zc={};zc[Uc]=zc["[object Array]"]=zc["[object ArrayBuffer]"]=zc["[object DataView]"]=zc["[object Boolean]"]=zc["[object Date]"]=zc["[object Float32Array]"]=zc["[object Float64Array]"]=zc["[object Int8Array]"]=zc["[object Int16Array]"]=zc["[object Int32Array]"]=zc["[object Map]"]=zc["[object Number]"]=zc[Wc]=zc["[object RegExp]"]=zc["[object Set]"]=zc["[object String]"]=zc["[object Symbol]"]=zc["[object Uint8Array]"]=zc["[object Uint8ClampedArray]"]=zc["[object Uint16Array]"]=zc["[object Uint32Array]"]=!0,zc["[object Error]"]=zc[$c]=zc["[object WeakMap]"]=!1;var Gc=function t(e,r,n,o,i,a){var c,s=1&r,u=2&r,f=4&r;if(n&&(c=i?n(e,o,i,a):n(e)),void 0!==c)return c;if(!Lc(e))return e;var l=Pc(e);if(l){if(c=Rc(e),!s)return mc(e,c)}else{var h=Nc(e),p=h==$c||"[object GeneratorFunction]"==h;if(kc(e))return Sc(e,s);if(h==Wc||h==Uc||p&&!i){if(c=u||p?{}:Cc(e),!s)return u?Ec(e,jc(c,e)):wc(e,Oc(c,e))}else{if(!zc[h])return i?e:{};c=Mc(e,h,s)}}a||(a=new yc);var v=a.get(e);if(v)return v;a.set(e,c),Tc(e)?e.forEach(function(o){c.add(t(o,r,n,o,e,a))}):Ic(e)&&e.forEach(function(o,i){c.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?Dc:Ac:u?Fc:xc)(e);return _c(b||e,function(o,i){b&&(o=e[i=o]),gc(c,i,t(o,r,n,i,e,a))}),c};var Bc=sn,Vc=function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i};var Xc=function(t,e){return e.length<2?t:Bc(t,Vc(e,0,-1))},Yc=rn,Hc=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},Kc=Xc,Qc=on;var Jc=function(t,e){return e=Yc(e,t),null==(t=Kc(t,e))||delete t[Qc(Hc(e))]},qc=N,Zc=ma,ts=Ft,es=Function.prototype,rs=Object.prototype,ns=es.toString,os=rs.hasOwnProperty,is=ns.call(Object);var as=function(t){if(!ts(t)||"[object Object]"!=qc(t))return!1;var e=Zc(t);if(null===e)return!0;var r=os.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&ns.call(r)==is};var cs=function(t){return as(t)?void 0:t},ss=Xt,us=Yt,fs=y?y.isConcatSpreadable:void 0;var ls=uo,hs=function(t){return us(t)||ss(t)||!!(fs&&t&&t[fs])};var ps=function t(e,r,n,o,i){var a=-1,c=e.length;for(n||(n=hs),i||(i=[]);++a<c;){var s=e[a];r>0&&n(s)?r>1?t(s,r-1,n,o,i):ls(i,s):o||(i[i.length]=s)}return i},vs=ps;var bs=function(t){return(null==t?0:t.length)?vs(t,1):[]},ds=pt,ys=_t;var _s=Br,gs=Gc,Os=Jc,js=rn,Ss=ut,ms=cs,ws=La,Es=function(t){return ys(ds(t,void 0,bs),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=_s(e,function(e){return e=js(e,t),n||(n=e.length>1),e}),Ss(t,ws(t),r),n&&(r=gs(r,7,ms));for(var o=e.length;o--;)Os(r,e[o]);return r}),As=h(Es);const Ds=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;EOL;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=u.homedir(),this.EOL=u.EOL,this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=f.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||f.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||f.join(this.homedir,".config");break;default:console.log(`當前系統是未知的平台: ${this.platform}`),this.isMAC=!1,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=this.homedir}this.appFolder=f.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return f.join(...t)}folderCheck(t){s.mkdirSync(t,{recursive:!0})}fileCheck(t){s.existsSync(t)||s.writeFileSync(t,"",{encoding:"utf8"})}}("aiia-sdk");class Ns{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=Ds.addPath(Ds.appFolder,this.fileName),Ds.fileCheck(this.filePath)}getFileDataSync(){const t=s.readFileSync(this.filePath,"utf8");try{return JSON.parse(t)}catch(t){return{}}}setFileDataSync(t){try{const e=JSON.stringify(t);s.writeFileSync(this.filePath,e,"utf8")}catch(t){}}async getFileData(){return new Promise(t=>{s.readFile(this.filePath,"utf8",(e,r)=>{if(e)t({});else try{t(JSON.parse(r))}catch(e){t({})}})})}async setFileData(t){return new Promise(e=>{try{const r=JSON.stringify(t);s.writeFile(this.filePath,r,"utf8",t=>{e()})}catch(t){}})}async getItem(t){return(await this.getFileData())[t]??null}async setItem(t,e){const r=await this.getFileData();r[t]=e,await this.setFileData(r)}async removeItem(t){const e=await this.getFileData(),r=As(e,t);await this.setFileData(r)}async clear(){await this.setFileData({})}getItemSync(t){return this.getFileDataSync()[t]??null}setItemSync(t,e){const r=this.getFileDataSync();r[t]=e,this.setFileDataSync(r)}removeItemSync(t){const e=As(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}class Rs{filePath;fileName;constructor(){this.fileName="log.txt",this.filePath=Ds.addPath(Ds.appFolder,this.fileName)}next(t,e,...r){try{const n=r.reduce((t,e)=>{switch(typeof e){case"string":case"number":case"bigint":return`${t} ${e.toString()}`;case"boolean":return`${t} ${e?"true":"false"}`;case"object":try{return`${t} ${JSON.stringify(e)}`}catch(e){return t}case"symbol":case"undefined":case"function":return`${t} [${typeof e}]`}},"");s.appendFileSync(this.filePath,`LOG(${t})__${e}__:: ${n}${Ds.EOL}`,{encoding:"utf8"})}catch(t){}}}class Ms{config;constructor(t){this.config=t}onDestory(){}send(t){}start(){}}class Cs{config;stroage;apiProxy;chat;udpProxy;isStart;channelMap;destorySub;access_token;get accessToken(){return this.access_token}constructor(t,e){this.config=t,this.stroage=e,this.isStart=!1,this.destorySub=new r,this.channelMap=new Map,this.access_token=e.getItemSync(pn),this.apiProxy=new ea(this.config.endPoint.api),Cn.code(An["指定模組初始化完成"],"api"),this.chat=new Pn(this.config),Cn.code(An["指定模組初始化完成"],"chat"),this.udpProxy=new Ms(this.config),Cn.code(An["指定模組初始化完成"],"udp")}async start(){if(this.isStart)throw new Error(fn["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.memberChange.pipe(o(this.destorySub)).subscribe(({type:t,socket:e})=>{switch(t){case"in":{Cn.debug("member join",e.id);const t=new ra,c=new r,s=(a=e.handshake.query.uuid,Ht(a)?hn(a,"[0]",void 0):a??void 0);void 0===s?(this.getProjectList().then(t=>{e.emit("list",t)}),n(e,"uuid").pipe(i(1),o(c)).subscribe(r=>{this.openChannel(r,e,t,c)})):this.openChannel(s,e,t,c),this.channelMap.set(e.id,()=>{c.next(),c.complete()});break}case"out":Cn.debug("member leave",e.id),this.channelMap.has(e.id)&&(this.channelMap.get(e.id)(),this.channelMap.delete(e.id))}var a}),this.chat.start(),Cn.code(An["啟動服務"],"chat"),this.udpProxy.start(),Cn.code(An["啟動服務"],"udp")}async replaceAccessToken(){const t=await this.apiProxy.getAccessToken(this.config.license,this.access_token);return this.access_token=t,this.stroage.setItemSync(pn,t),t}async getProjectList(){return await this.apiProxy.getProjectList(this.config.license)}getProxySocketURL(t){return`${this.config.endPoint.socket}/v1/chat/project/${this.accessToken}/${t}`}openChannel(t,e,r,i){n(e,"cloud").pipe(o(i)).subscribe(t=>{r.send(t)}),r.message.pipe(o(i)).subscribe(t=>{e.emit("cloud",t),this.udpProxy.send(t)}),r.close.pipe(o(i)).subscribe(async n=>{switch(e.emit("channel",n),n){case"close":case"no_permissions":r.onDestory();break;case"reconnect":await this.replaceAccessToken(),r.reconnect(this.getProxySocketURL(t))}}),r.linkStart.pipe(o(i)).subscribe(()=>{e.emit("channel","open")}),i.subscribe(()=>{r.onClose()}),r.start(this.getProxySocketURL(t))}onDestory(){this.apiProxy.onDestory(),this.chat.onDestory(),this.udpProxy.onDestory(),this.destorySub.next(),this.destorySub.complete(),Cn.code(An["服務結束"])}}function Ps(t){if(vn){if(void 0===hn(t,"license",void 0))throw new Error(fn["未提供憑證"]);!function(t){const{info:e,error:r,warn:n,debug:o,fatal:i,code:a}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);return a||(Nn.code=()=>{}),o||(Nn.debug=()=>{}),e||(Nn.info=()=>{}),n||(Nn.warn=()=>{}),r||(Nn.error=()=>{}),i||(Nn.fatal=()=>{}),Mn}(hn(t,"debug",!0))(new Rs),Cn.code(An["開始初始化必要模組"]);const e=new bn(Ie({},t));Cn.code(An["指定模組初始化完成"],"config");const r=new Ns;Cn.code(An["指定模組初始化完成"],"storage");const n=new Cs(e,r);return Cn.code(An["指定模組初始化完成"],"core"),n.start(),Cn.code(An["啟動服務"]),()=>{n.onDestory()}}throw new Error(fn["環境錯誤(nodejs)"])}export{Ps as aiiaCore};
1
+ import t from"moment";import{Server as e}from"socket.io";import{Subject as r,fromEvent as n,takeUntil as o,take as i}from"rxjs";import a from"axios";import c from"ws";import s from"fs";import u from"os";import f from"path";import{Client as l}from"node-osc";var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function v(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var p="object"==typeof h&&h&&h.Object===Object&&h,b=p,d="object"==typeof self&&self&&self.Object===Object&&self,y=b||d||Function("return this")(),_=y.Symbol,g=_,O=Object.prototype,j=O.hasOwnProperty,m=O.toString,S=g?g.toStringTag:void 0;var w=function(t){var e=j.call(t,S),r=t[S];try{t[S]=void 0;var n=!0}catch(t){}var o=m.call(t);return n&&(e?t[S]=r:delete t[S]),o},E=Object.prototype.toString;var A=w,D=function(t){return E.call(t)},N=_?_.toStringTag:void 0;var R=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":N&&N in Object(t)?A(t):D(t)};var P=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},C=R,M=P;var k,x=function(t){if(!M(t))return!1;var e=C(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},I=y["__core-js_shared__"],L=(k=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var T=function(t){return!!L&&L in t},U=Function.prototype.toString;var F=function(t){if(null!=t){try{return U.call(t)}catch(t){}try{return t+""}catch(t){}}return""},W=x,$=T,z=P,G=F,B=/^\[object .+?Constructor\]$/,V=Function.prototype,X=Object.prototype,Y=V.toString,H=X.hasOwnProperty,K=RegExp("^"+Y.call(H).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var J=function(t){return!(!z(t)||$(t))&&(W(t)?K:B).test(G(t))},Q=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=Q(t,e);return J(r)?r:void 0},Z=q,tt=function(){try{var t=Z(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),et=tt;var rt=function(t,e,r){"__proto__"==e&&et?et(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var nt=function(t,e){return t===e||t!=t&&e!=e},ot=rt,it=nt,at=Object.prototype.hasOwnProperty;var ct=function(t,e,r){var n=t[e];at.call(t,e)&&it(n,r)&&(void 0!==r||e in t)||ot(t,e,r)},st=ct,ut=rt;var ft=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var c=e[i],s=n?n(r[c],t[c],c,r,t):void 0;void 0===s&&(s=t[c]),o?ut(r,c,s):st(r,c,s)}return r};var lt=function(t){return t};var ht=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)},vt=Math.max;var pt=function(t,e,r){return e=vt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=vt(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(a),ht(t,this,c)}};var bt=function(t){return function(){return t}},dt=tt,yt=dt?function(t,e){return dt(t,"toString",{configurable:!0,enumerable:!1,value:bt(e),writable:!0})}:lt,_t=Date.now;var gt=function(t){var e=0,r=0;return function(){var n=_t(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(yt),Ot=lt,jt=pt,mt=gt;var St=function(t,e){return mt(jt(t,e,Ot),t+"")};var wt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},Et=x,At=wt;var Dt=function(t){return null!=t&&At(t.length)&&!Et(t)},Nt=/^(?:0|[1-9]\d*)$/;var Rt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Nt.test(t))&&t>-1&&t%1==0&&t<e},Pt=nt,Ct=Dt,Mt=Rt,kt=P;var xt=function(t,e,r){if(!kt(r))return!1;var n=typeof e;return!!("number"==n?Ct(r)&&Mt(e,r.length):"string"==n&&e in r)&&Pt(r[e],t)},It=St,Lt=xt;var Tt=function(t){return It(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,a&&Lt(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var c=r[n];c&&t(e,c,n,i)}return e})},Ut=Object.prototype;var Ft=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ut)};var Wt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var $t=function(t){return null!=t&&"object"==typeof t},zt=R,Gt=$t;var Bt=function(t){return Gt(t)&&"[object Arguments]"==zt(t)},Vt=$t,Xt=Object.prototype,Yt=Xt.hasOwnProperty,Ht=Xt.propertyIsEnumerable,Kt=Bt(function(){return arguments}())?Bt:function(t){return Vt(t)&&Yt.call(t,"callee")&&!Ht.call(t,"callee")},Jt=Array.isArray,Qt=v(Jt),qt={exports:{}};var Zt=function(){return!1};!function(t,e){var r=y,n=Zt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,c=(a?a.isBuffer:void 0)||n;t.exports=c}(qt,qt.exports);var te=qt.exports,ee=R,re=wt,ne=$t,oe={};oe["[object Float32Array]"]=oe["[object Float64Array]"]=oe["[object Int8Array]"]=oe["[object Int16Array]"]=oe["[object Int32Array]"]=oe["[object Uint8Array]"]=oe["[object Uint8ClampedArray]"]=oe["[object Uint16Array]"]=oe["[object Uint32Array]"]=!0,oe["[object Arguments]"]=oe["[object Array]"]=oe["[object ArrayBuffer]"]=oe["[object Boolean]"]=oe["[object DataView]"]=oe["[object Date]"]=oe["[object Error]"]=oe["[object Function]"]=oe["[object Map]"]=oe["[object Number]"]=oe["[object Object]"]=oe["[object RegExp]"]=oe["[object Set]"]=oe["[object String]"]=oe["[object WeakMap]"]=!1;var ie=function(t){return ne(t)&&re(t.length)&&!!oe[ee(t)]};var ae=function(t){return function(e){return t(e)}},ce={exports:{}};!function(t,e){var r=p,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n&&r.process,a=function(){try{var t=o&&o.require&&o.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=a}(ce,ce.exports);var se=ce.exports,ue=ie,fe=ae,le=se&&se.isTypedArray,he=le?fe(le):ue,ve=Wt,pe=Kt,be=Jt,de=te,ye=Rt,_e=he,ge=Object.prototype.hasOwnProperty;var Oe=function(t,e){var r=be(t),n=!r&&pe(t),o=!r&&!n&&de(t),i=!r&&!n&&!o&&_e(t),a=r||n||o||i,c=a?ve(t.length,String):[],s=c.length;for(var u in t)!e&&!ge.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||ye(u,s))||c.push(u);return c};var je=function(t,e){return function(r){return t(e(r))}},me=je(Object.keys,Object),Se=Ft,we=me,Ee=Object.prototype.hasOwnProperty;var Ae=Oe,De=function(t){if(!Se(t))return we(t);var e=[];for(var r in Object(t))Ee.call(t,r)&&"constructor"!=r&&e.push(r);return e},Ne=Dt;var Re=function(t){return Ne(t)?Ae(t):De(t)},Pe=ct,Ce=ft,Me=Tt,ke=Dt,xe=Ft,Ie=Re,Le=Object.prototype.hasOwnProperty,Te=v(Me(function(t,e){if(xe(e)||ke(e))Ce(e,Ie(e),t);else for(var r in e)Le.call(e,r)&&Pe(t,r,e[r])})),Ue=R,Fe=$t;var We=function(t){return"symbol"==typeof t||Fe(t)&&"[object Symbol]"==Ue(t)},$e=Jt,ze=We,Ge=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Be=/^\w*$/;var Ve=function(t,e){if($e(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!ze(t))||(Be.test(t)||!Ge.test(t)||null!=e&&t in Object(e))},Xe=q(Object,"create"),Ye=Xe;var He=function(){this.__data__=Ye?Ye(null):{},this.size=0};var Ke=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Je=Xe,Qe=Object.prototype.hasOwnProperty;var qe=function(t){var e=this.__data__;if(Je){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Qe.call(e,t)?e[t]:void 0},Ze=Xe,tr=Object.prototype.hasOwnProperty;var er=Xe;var rr=He,nr=Ke,or=qe,ir=function(t){var e=this.__data__;return Ze?void 0!==e[t]:tr.call(e,t)},ar=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=er&&void 0===e?"__lodash_hash_undefined__":e,this};function cr(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])}}cr.prototype.clear=rr,cr.prototype.delete=nr,cr.prototype.get=or,cr.prototype.has=ir,cr.prototype.set=ar;var sr=cr;var ur=function(){this.__data__=[],this.size=0},fr=nt;var lr=function(t,e){for(var r=t.length;r--;)if(fr(t[r][0],e))return r;return-1},hr=lr,vr=Array.prototype.splice;var pr=lr;var br=lr;var dr=lr;var yr=ur,_r=function(t){var e=this.__data__,r=hr(e,t);return!(r<0)&&(r==e.length-1?e.pop():vr.call(e,r,1),--this.size,!0)},gr=function(t){var e=this.__data__,r=pr(e,t);return r<0?void 0:e[r][1]},Or=function(t){return br(this.__data__,t)>-1},jr=function(t,e){var r=this.__data__,n=dr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function mr(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])}}mr.prototype.clear=yr,mr.prototype.delete=_r,mr.prototype.get=gr,mr.prototype.has=Or,mr.prototype.set=jr;var Sr=mr,wr=q(y,"Map"),Er=sr,Ar=Sr,Dr=wr;var Nr=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Rr=function(t,e){var r=t.__data__;return Nr(e)?r["string"==typeof e?"string":"hash"]:r.map},Pr=Rr;var Cr=Rr;var Mr=Rr;var kr=Rr;var xr=function(){this.size=0,this.__data__={hash:new Er,map:new(Dr||Ar),string:new Er}},Ir=function(t){var e=Pr(this,t).delete(t);return this.size-=e?1:0,e},Lr=function(t){return Cr(this,t).get(t)},Tr=function(t){return Mr(this,t).has(t)},Ur=function(t,e){var r=kr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,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=xr,Fr.prototype.delete=Ir,Fr.prototype.get=Lr,Fr.prototype.has=Tr,Fr.prototype.set=Ur;var Wr=Fr,$r=Wr;function zr(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],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(zr.Cache||$r),r}zr.Cache=$r;var Gr=zr;var Br=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Vr=/\\(\\)?/g,Xr=function(t){var e=Gr(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(Br,function(t,r,n,o){e.push(n?o.replace(Vr,"$1"):r||t)}),e});var Yr=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},Hr=Yr,Kr=Jt,Jr=We,Qr=_?_.prototype:void 0,qr=Qr?Qr.toString:void 0;var Zr=function t(e){if("string"==typeof e)return e;if(Kr(e))return Hr(e,t)+"";if(Jr(e))return qr?qr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},tn=Zr;var en=Jt,rn=Ve,nn=Xr,on=function(t){return null==t?"":tn(t)};var an=function(t,e){return en(t)?t:rn(t,e)?[t]:nn(on(t))},cn=We;var sn=function(t){if("string"==typeof t||cn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},un=an,fn=sn;var ln=function(t,e){for(var r=0,n=(e=un(e,t)).length;null!=t&&r<n;)t=t[fn(e[r++])];return r&&r==n?t:void 0},hn=ln;var vn,pn=function(t,e,r){var n=null==t?void 0:hn(t,e);return void 0===n?r:n},bn=v(pn);!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: 2005"}(vn||(vn={}));const dn="access_token",yn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class _n{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}=Te({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Te({},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??!0}get mediaStream(){return this.config.mediaStream}get chunkTimeInSeconds(){return"number"==typeof this.config.chunkTimeInSeconds&&this.config.chunkTimeInSeconds>0?this.config.chunkTimeInSeconds:1}get llmSampleRate(){return"number"==typeof this.config.llmSampleRate&&this.config.llmSampleRate>0?this.config.llmSampleRate:16e3}get faceDetection(){return Te({frame:3,confidence:80},this.config.faceDetection)}get autoClearSubtitle(){const{user:t,aiia:e}=Te({},this.config.autoClearSubtitle);let r=3e3,n=3e3;return"number"==typeof t?r=t>=0?t:r:!1===t&&(r=NaN),"number"==typeof e?n=e>=0?e:n:!1===e&&(n=NaN),{userDelayTime:r,aiiaDelayTime:n}}constructor(t){this.config=t}}var gn=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var On=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),c=a.length;c--;){var s=a[t?c:++o];if(!1===r(i[s],s,i))break}return e}}(),jn=Re;var mn=Dt;var Sn=function(t,e){return function(r,n){if(null==r)return r;if(!mn(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(t,e){return t&&On(t,e,jn)}),wn=lt;var En=gn,An=Sn,Dn=function(t){return"function"==typeof t?t:wn},Nn=Jt;var Rn,Pn=v(function(t,e){return(Nn(t)?En:An)(t,Dn(e))});!function(t){t["通道、雲端服務、麥克風都已就緒"]="CODE: 1000",t["未取得媒體裝置權限,請重新設定或忽略此訊息"]="CODE: 1001",t["請訂閱專案列表"]="CODE: 1002",t["初始化必要依賴"]="CODE: 1010",t["指定依賴已完成"]="CODE: 1011",t["啟動SDK"]="CODE: 1012",t["結束SDK"]="CODE: 1013",t["安全的關閉連線"]="CODE: 2000",t["無副作用的關閉連線"]="CODE: 2001",t["與雲端的服務中斷"]="CODE: 2002",t["沒有授權,請聯繫Graphen"]="CODE: 2003",t["自動重新連線連端服務"]="CODE: 2004",t["未預期的斷線,請聯繫Graphen"]="CODE: 2005",t["開始初始化必要模組"]="CODE: 2010",t["指定模組初始化完成"]="CODE: 2011",t["啟動服務"]="CODE: 2012",t["服務結束"]="CODE: 2013"}(Rn||(Rn={}));const Cn={code:console.log,debug:console.log,info:console.log,warn:console.warn,error:console.error,fatal:console.error},Mn=[];function kn(t){return Mn.push(t),kn}const xn=new Proxy(Cn,{get(e,r,n){if("string"==typeof r)switch(r){case"debug":case"info":case"error":case"warn":case"fatal":case"code":return(...n)=>{const o=t().format("yyyy-MM-DD[T]HH:mm:ss");Pn(Mn,t=>{t.next(r,o,...n)}),e[r](`[Aiia::${r}_${o}_]`,...n)};default:return}},set:(t,e,r,n)=>!0});var In=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i},Ln=Sr;var Tn=Sr,Un=wr,Fn=Wr;var Wn=Sr,$n=function(){this.__data__=new Ln,this.size=0},zn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Gn=function(t){return this.__data__.get(t)},Bn=function(t){return this.__data__.has(t)},Vn=function(t,e){var r=this.__data__;if(r instanceof Tn){var n=r.__data__;if(!Un||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Fn(n)}return r.set(t,e),this.size=r.size,this};function Xn(t){var e=this.__data__=new Wn(t);this.size=e.size}Xn.prototype.clear=$n,Xn.prototype.delete=zn,Xn.prototype.get=Gn,Xn.prototype.has=Bn,Xn.prototype.set=Vn;var Yn=Xn;var Hn=Wr,Kn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Jn=function(t){return this.__data__.has(t)};function Qn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Hn;++e<r;)this.add(t[e])}Qn.prototype.add=Qn.prototype.push=Kn,Qn.prototype.has=Jn;var qn=Qn,Zn=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},to=function(t,e){return t.has(e)};var eo=function(t,e,r,n,o,i){var a=1&r,c=t.length,s=e.length;if(c!=s&&!(a&&s>c))return!1;var u=i.get(t),f=i.get(e);if(u&&f)return u==e&&f==t;var l=-1,h=!0,v=2&r?new qn:void 0;for(i.set(t,e),i.set(e,t);++l<c;){var p=t[l],b=e[l];if(n)var d=a?n(b,p,l,e,t,i):n(p,b,l,t,e,i);if(void 0!==d){if(d)continue;h=!1;break}if(v){if(!Zn(e,function(t,e){if(!to(v,e)&&(p===t||o(p,t,r,n,i)))return v.push(e)})){h=!1;break}}else if(p!==b&&!o(p,b,r,n,i)){h=!1;break}}return i.delete(t),i.delete(e),h},ro=y.Uint8Array;var no=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var oo=ro,io=nt,ao=eo,co=no,so=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},uo=_?_.prototype:void 0,fo=uo?uo.valueOf:void 0;var lo=function(t,e,r,n,o,i,a){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||!i(new oo(t),new oo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return io(+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 c=co;case"[object Set]":var s=1&n;if(c||(c=so),t.size!=e.size&&!s)return!1;var u=a.get(t);if(u)return u==e;n|=2,a.set(t,e);var f=ao(c(t),c(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(fo)return fo.call(t)==fo.call(e)}return!1};var ho=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},vo=ho,po=Jt;var bo=function(t,e,r){var n=e(t);return po(t)?n:vo(n,r(t))};var yo=function(){return[]},_o=In,go=yo,Oo=Object.prototype.propertyIsEnumerable,jo=Object.getOwnPropertySymbols,mo=jo?function(t){return null==t?[]:(t=Object(t),_o(jo(t),function(e){return Oo.call(t,e)}))}:go,So=bo,wo=mo,Eo=Re;var Ao=function(t){return So(t,Eo,wo)},Do=Ao,No=Object.prototype.hasOwnProperty;var Ro=function(t,e,r,n,o,i){var a=1&r,c=Do(t),s=c.length;if(s!=Do(e).length&&!a)return!1;for(var u=s;u--;){var f=c[u];if(!(a?f in e:No.call(e,f)))return!1}var l=i.get(t),h=i.get(e);if(l&&h)return l==e&&h==t;var v=!0;i.set(t,e),i.set(e,t);for(var p=a;++u<s;){var b=t[f=c[u]],d=e[f];if(n)var y=a?n(d,b,f,e,t,i):n(b,d,f,t,e,i);if(!(void 0===y?b===d||o(b,d,r,n,i):y)){v=!1;break}p||(p="constructor"==f)}if(v&&!p){var _=t.constructor,g=e.constructor;_==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(v=!1)}return i.delete(t),i.delete(e),v},Po=q(y,"DataView"),Co=wr,Mo=q(y,"Promise"),ko=q(y,"Set"),xo=q(y,"WeakMap"),Io=R,Lo=F,To="[object Map]",Uo="[object Promise]",Fo="[object Set]",Wo="[object WeakMap]",$o="[object DataView]",zo=Lo(Po),Go=Lo(Co),Bo=Lo(Mo),Vo=Lo(ko),Xo=Lo(xo),Yo=Io;(Po&&Yo(new Po(new ArrayBuffer(1)))!=$o||Co&&Yo(new Co)!=To||Mo&&Yo(Mo.resolve())!=Uo||ko&&Yo(new ko)!=Fo||xo&&Yo(new xo)!=Wo)&&(Yo=function(t){var e=Io(t),r="[object Object]"==e?t.constructor:void 0,n=r?Lo(r):"";if(n)switch(n){case zo:return $o;case Go:return To;case Bo:return Uo;case Vo:return Fo;case Xo:return Wo}return e});var Ho=Yo,Ko=Yn,Jo=eo,Qo=lo,qo=Ro,Zo=Ho,ti=Jt,ei=te,ri=he,ni="[object Arguments]",oi="[object Array]",ii="[object Object]",ai=Object.prototype.hasOwnProperty;var ci=function(t,e,r,n,o,i){var a=ti(t),c=ti(e),s=a?oi:Zo(t),u=c?oi:Zo(e),f=(s=s==ni?ii:s)==ii,l=(u=u==ni?ii:u)==ii,h=s==u;if(h&&ei(t)){if(!ei(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Ko),a||ri(t)?Jo(t,e,r,n,o,i):Qo(t,e,s,r,n,o,i);if(!(1&r)){var v=f&&ai.call(t,"__wrapped__"),p=l&&ai.call(e,"__wrapped__");if(v||p){var b=v?t.value():t,d=p?e.value():e;return i||(i=new Ko),o(b,d,r,n,i)}}return!!h&&(i||(i=new Ko),qo(t,e,r,n,o,i))},si=$t;var ui=function t(e,r,n,o,i){return e===r||(null==e||null==r||!si(e)&&!si(r)?e!=e&&r!=r:ci(e,r,n,o,t,i))},fi=Yn,li=ui;var hi=P;var vi=function(t){return t==t&&!hi(t)},pi=vi,bi=Re;var di=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},yi=function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var c=r[o];if(a&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<i;){var s=(c=r[o])[0],u=t[s],f=c[1];if(a&&c[2]){if(void 0===u&&!(s in t))return!1}else{var l=new fi;if(n)var h=n(u,f,s,t,e,l);if(!(void 0===h?li(f,u,3,n,l):h))return!1}}return!0},_i=function(t){for(var e=bi(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,pi(o)]}return e},gi=di;var Oi=an,ji=Kt,mi=Jt,Si=Rt,wi=wt,Ei=sn;var Ai=function(t,e,r){for(var n=-1,o=(e=Oi(e,t)).length,i=!1;++n<o;){var a=Ei(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&wi(o)&&Si(a,o)&&(mi(t)||ji(t))},Di=function(t,e){return null!=t&&e in Object(t)},Ni=Ai;var Ri=function(t,e){return null!=t&&Ni(t,e,Di)},Pi=ui,Ci=pn,Mi=Ri,ki=Ve,xi=vi,Ii=di,Li=sn;var Ti=function(t,e){return ki(t)&&xi(e)?Ii(Li(t),e):function(r){var n=Ci(r,t);return void 0===n&&n===e?Mi(r,t):Pi(e,n,3)}};var Ui=ln;var Fi=function(t){return function(e){return Ui(e,t)}},Wi=function(t){return function(e){return null==e?void 0:e[t]}},$i=Fi,zi=Ve,Gi=sn;var Bi=function(t){return zi(t)?Wi(Gi(t)):$i(t)},Vi=function(t){var e=_i(t);return 1==e.length&&e[0][2]?gi(e[0][0],e[0][1]):function(r){return r===t||yi(r,t,e)}},Xi=Ti,Yi=lt,Hi=Jt,Ki=Bi;var Ji=function(t){return"function"==typeof t?t:null==t?Yi:"object"==typeof t?Hi(t)?Xi(t[0],t[1]):Vi(t):Ki(t)},Qi=Sn,qi=Dt;var Zi=function(t,e){var r=-1,n=qi(t)?Array(t.length):[];return Qi(t,function(t,o,i){n[++r]=e(t,o,i)}),n},ta=Yr,ea=Ji,ra=Zi,na=Jt;var oa=v(function(t,e){return(na(t)?ta:ra)(t,ea(e))}),ia=Kt,aa=Jt,ca=_?_.isConcatSpreadable:void 0;var sa=ho,ua=function(t){return aa(t)||ia(t)||!!(ca&&t&&t[ca])};var fa=function t(e,r,n,o,i){var a=-1,c=e.length;for(n||(n=ua),i||(i=[]);++a<c;){var s=e[a];r>0&&n(s)?r>1?t(s,r-1,n,o,i):sa(i,s):o||(i[i.length]=s)}return i};var la=We;var ha=function(t,e){if(t!==e){var r=void 0!==t,n=null===t,o=t==t,i=la(t),a=void 0!==e,c=null===e,s=e==e,u=la(e);if(!c&&!u&&!i&&t>e||i&&a&&s&&!c&&!u||n&&a&&s||!r&&s||!o)return 1;if(!n&&!i&&!u&&t<e||u&&r&&o&&!n&&!i||c&&r&&o||!a&&o||!s)return-1}return 0};var va=Yr,pa=ln,ba=Ji,da=Zi,ya=function(t,e){var r=t.length;for(t.sort(e);r--;)t[r]=t[r].value;return t},_a=ae,ga=function(t,e,r){for(var n=-1,o=t.criteria,i=e.criteria,a=o.length,c=r.length;++n<a;){var s=ha(o[n],i[n]);if(s)return n>=c?s:s*("desc"==r[n]?-1:1)}return t.index-e.index},Oa=lt,ja=Jt;var ma,Sa=fa,wa=function(t,e,r){e=e.length?va(e,function(t){return ja(t)?function(e){return pa(e,1===t.length?t[0]:t)}:t}):[Oa];var n=-1;e=va(e,_a(ba));var o=da(t,function(t,r,o){return{criteria:va(e,function(e){return e(t)}),index:++n,value:t}});return ya(o,function(t,e){return ga(t,e,r)})},Ea=xt;St(function(t,e){if(null==t)return[];var r=e.length;return r>1&&Ea(t,e[0],e[1])?e=[]:r>2&&Ea(e[0],e[1],e[2])&&(e=[e[0]]),wa(t,Sa(e,1),[])});class Aa{config;server;memberSub;get port(){return this.config.port}get webserver(){return this.config.webserver}get memberChange(){return this.memberSub.asObservable()}constructor(t){this.config=t,this.memberSub=new r}start(){if(this.server=new e(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{this.memberSub.next({type:"in",socket:t}),xn.debug("client on",t.id),t.on("disconnect",e=>{this.memberSub.next({type:"out",socket:t}),xn.debug("client off",e)})}),void 0===this.webserver){const t=this.port;this.server.listen(t),xn.info("Websocket server run on",t)}else xn.info("Websocket server rely your webserver.")}onDestroy(){this.server&&this.server.close()}}class Da{instance;controller;constructor(t){this.controller=new AbortController,this.instance=a.create({baseURL:t,signal:this.controller.signal})}async getAccessToken(t,e){const r={license_number:t,token_value:e??""},n=await this.instance.post("/api/v1/license/agent_token",r).then(t=>bn(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(vn["網絡錯誤"]);if(""===n)throw new Error(vn["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>oa(bn(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(vn["網絡錯誤"]);if(0===e.length)throw new Error(vn["沒有可用專案"]);return e}onDestroy(){this.controller.abort()}}!function(t){t[t.MDN_NORMAL_CLOSURE=1e3]="MDN_NORMAL_CLOSURE",t[t.MDN_GOING_AWAY=1001]="MDN_GOING_AWAY",t[t.MDN_PROTOCOL_ERROR=1002]="MDN_PROTOCOL_ERROR",t[t.MDN_UNSUPPORTED_DATA=1003]="MDN_UNSUPPORTED_DATA",t[t.MDN_RESERVED_1004=1004]="MDN_RESERVED_1004",t[t.MDN_NO_STATUS_RECEIVED=1005]="MDN_NO_STATUS_RECEIVED",t[t.MDN_ABNORMAL_CLOSURE=1006]="MDN_ABNORMAL_CLOSURE",t[t.MDN_INVALID_FRAME_PAYLOAD=1007]="MDN_INVALID_FRAME_PAYLOAD",t[t.MDN_POLICY_VIOLATION=1008]="MDN_POLICY_VIOLATION",t[t.MDN_MESSAGE_TOO_BIG=1009]="MDN_MESSAGE_TOO_BIG",t[t.MDN_MANDATORY_EXTENSION=1010]="MDN_MANDATORY_EXTENSION",t[t.MDN_INTERNAL_ERROR=1011]="MDN_INTERNAL_ERROR",t[t.MDN_SERVICE_RESTART=1012]="MDN_SERVICE_RESTART",t[t.MDN_TRY_AGAIN_LATER=1013]="MDN_TRY_AGAIN_LATER",t[t.MDN_BAD_GATEWAY=1014]="MDN_BAD_GATEWAY",t[t.MDN_TLS_HANDSHAKE=1015]="MDN_TLS_HANDSHAKE",t[t.MANUAL_CLOSE=4001]="MANUAL_CLOSE",t[t.WS_5000_NORAML_CLOSURE=5e3]="WS_5000_NORAML_CLOSURE",t[t.WS_5001_UNAUTHORIZED=5001]="WS_5001_UNAUTHORIZED",t[t.WS_5002_LICENSE_EXPIRED=5002]="WS_5002_LICENSE_EXPIRED",t[t.WS_5003_TOKEN_EXPIRED=5003]="WS_5003_TOKEN_EXPIRED"}(ma||(ma={}));class Na{socket;messageSub;linkStartSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get linkStart(){return this.linkStartSub.asObservable()}messageQueue=[];isConnected;constructor(){this.isConnected=!1,this.messageSub=new r,this.linkStartSub=new r,this.closeSub=new r,this.destorySub=new r}start(t){this.socket=new c(t,{autoPong:!0}),n(this.socket,"open").pipe(o(this.destorySub)).subscribe(()=>{this.isConnected=!0,xn.code(Rn["啟動服務"],"proxy"),this.flushMessageQueue(),this.linkStartSub.next()}),n(this.socket,"message").pipe(o(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),n(this.socket,"error").pipe(o(this.destorySub)).subscribe(t=>{const{error:e}=t;xn.error("Proxy has some problem",e)}),n(this.socket,"close").pipe(o(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e,reason:r}=t;switch(e){case ma.MANUAL_CLOSE:xn.code(Rn["無副作用的關閉連線"]);break;case ma.WS_5000_NORAML_CLOSURE:case ma.MDN_NORMAL_CLOSURE:case ma.MDN_GOING_AWAY:this.closeSub.next("close"),xn.code(Rn["安全的關閉連線"]);break;case ma.MDN_NO_STATUS_RECEIVED:case ma.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),xn.code(Rn["與雲端的服務中斷"],{code:e,reason:r});break;case ma.WS_5001_UNAUTHORIZED:case ma.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),xn.code(Rn["沒有授權,請聯繫Graphen"]);break;case ma.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect"),xn.code(Rn["自動重新連線連端服務"]);break;default:this.closeSub.next("close"),xn.code(Rn["未預期的斷線,請聯繫Graphen"],{code:e,reason:r})}})}reconnect(t){this.onDestroy(),this.destorySub=new r,this.start(t)}flushMessageQueue(){for(;this.messageQueue.length>0&&this.isConnected&&void 0!==this.socket;){const t=this.messageQueue.shift();t&&this.socket.send(t)}}send(t){this.isConnected&&void 0!==this.socket?this.socket.send(t):this.messageQueue.push(t)}onClose(){this.socket?.close(ma.MANUAL_CLOSE)}onDestroy(){this.destorySub.next(),this.destorySub.complete()}}var Ra=ft,Pa=Re;var Ca=function(t,e){return t&&Ra(e,Pa(e),t)};var Ma=P,ka=Ft,xa=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},Ia=Object.prototype.hasOwnProperty;var La=Oe,Ta=function(t){if(!Ma(t))return xa(t);var e=ka(t),r=[];for(var n in t)("constructor"!=n||!e&&Ia.call(t,n))&&r.push(n);return r},Ua=Dt;var Fa=function(t){return Ua(t)?La(t,!0):Ta(t)},Wa=ft,$a=Fa;var za=function(t,e){return t&&Wa(e,$a(e),t)},Ga={exports:{}};!function(t,e){var r=y,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n?r.Buffer:void 0,a=i?i.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var r=t.length,n=a?a(r):new t.constructor(r);return t.copy(n),n}}(Ga,Ga.exports);var Ba=Ga.exports;var Va=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e},Xa=ft,Ya=mo;var Ha=function(t,e){return Xa(t,Ya(t),e)},Ka=je(Object.getPrototypeOf,Object),Ja=ho,Qa=Ka,qa=mo,Za=yo,tc=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Ja(e,qa(t)),t=Qa(t);return e}:Za,ec=ft,rc=tc;var nc=function(t,e){return ec(t,rc(t),e)},oc=bo,ic=tc,ac=Fa;var cc=function(t){return oc(t,ac,ic)},sc=Object.prototype.hasOwnProperty;var uc=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&sc.call(t,"index")&&(r.index=t.index,r.input=t.input),r},fc=ro;var lc=function(t){var e=new t.constructor(t.byteLength);return new fc(e).set(new fc(t)),e},hc=lc;var vc=function(t,e){var r=e?hc(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},pc=/\w*$/;var bc=function(t){var e=new t.constructor(t.source,pc.exec(t));return e.lastIndex=t.lastIndex,e},dc=_?_.prototype:void 0,yc=dc?dc.valueOf:void 0;var _c=lc;var gc=lc,Oc=vc,jc=bc,mc=function(t){return yc?Object(yc.call(t)):{}},Sc=function(t,e){var r=e?_c(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var wc=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return gc(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return Oc(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return Sc(t,r);case"[object Map]":case"[object Set]":return new n;case"[object Number]":case"[object String]":return new n(t);case"[object RegExp]":return jc(t);case"[object Symbol]":return mc(t)}},Ec=P,Ac=Object.create,Dc=function(){function t(){}return function(e){if(!Ec(e))return{};if(Ac)return Ac(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Nc=Ka,Rc=Ft;var Pc=function(t){return"function"!=typeof t.constructor||Rc(t)?{}:Dc(Nc(t))},Cc=Ho,Mc=$t;var kc=function(t){return Mc(t)&&"[object Map]"==Cc(t)},xc=ae,Ic=se&&se.isMap,Lc=Ic?xc(Ic):kc,Tc=Ho,Uc=$t;var Fc=function(t){return Uc(t)&&"[object Set]"==Tc(t)},Wc=ae,$c=se&&se.isSet,zc=$c?Wc($c):Fc,Gc=Yn,Bc=gn,Vc=ct,Xc=Ca,Yc=za,Hc=Ba,Kc=Va,Jc=Ha,Qc=nc,qc=Ao,Zc=cc,ts=Ho,es=uc,rs=wc,ns=Pc,os=Jt,is=te,as=Lc,cs=P,ss=zc,us=Re,fs=Fa,ls="[object Arguments]",hs="[object Function]",vs="[object Object]",ps={};ps[ls]=ps["[object Array]"]=ps["[object ArrayBuffer]"]=ps["[object DataView]"]=ps["[object Boolean]"]=ps["[object Date]"]=ps["[object Float32Array]"]=ps["[object Float64Array]"]=ps["[object Int8Array]"]=ps["[object Int16Array]"]=ps["[object Int32Array]"]=ps["[object Map]"]=ps["[object Number]"]=ps[vs]=ps["[object RegExp]"]=ps["[object Set]"]=ps["[object String]"]=ps["[object Symbol]"]=ps["[object Uint8Array]"]=ps["[object Uint8ClampedArray]"]=ps["[object Uint16Array]"]=ps["[object Uint32Array]"]=!0,ps["[object Error]"]=ps[hs]=ps["[object WeakMap]"]=!1;var bs=function t(e,r,n,o,i,a){var c,s=1&r,u=2&r,f=4&r;if(n&&(c=i?n(e,o,i,a):n(e)),void 0!==c)return c;if(!cs(e))return e;var l=os(e);if(l){if(c=es(e),!s)return Kc(e,c)}else{var h=ts(e),v=h==hs||"[object GeneratorFunction]"==h;if(is(e))return Hc(e,s);if(h==vs||h==ls||v&&!i){if(c=u||v?{}:ns(e),!s)return u?Qc(e,Yc(c,e)):Jc(e,Xc(c,e))}else{if(!ps[h])return i?e:{};c=rs(e,h,s)}}a||(a=new Gc);var p=a.get(e);if(p)return p;a.set(e,c),ss(e)?e.forEach(function(o){c.add(t(o,r,n,o,e,a))}):as(e)&&e.forEach(function(o,i){c.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?Zc:qc:u?fs:us)(e);return Bc(b||e,function(o,i){b&&(o=e[i=o]),Vc(c,i,t(o,r,n,i,e,a))}),c};var ds=ln,ys=function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i};var _s=function(t,e){return e.length<2?t:ds(t,ys(e,0,-1))},gs=an,Os=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},js=_s,ms=sn;var Ss=function(t,e){return e=gs(e,t),null==(t=js(t,e))||delete t[ms(Os(e))]},ws=R,Es=Ka,As=$t,Ds=Function.prototype,Ns=Object.prototype,Rs=Ds.toString,Ps=Ns.hasOwnProperty,Cs=Rs.call(Object);var Ms=function(t){if(!As(t)||"[object Object]"!=ws(t))return!1;var e=Es(t);if(null===e)return!0;var r=Ps.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Rs.call(r)==Cs};var ks=fa;var xs=function(t){return(null==t?0:t.length)?ks(t,1):[]},Is=pt,Ls=gt;var Ts=Yr,Us=bs,Fs=Ss,Ws=an,$s=ft,zs=function(t){return Ms(t)?void 0:t},Gs=cc,Bs=function(t){return Ls(Is(t,void 0,xs),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=Ts(e,function(e){return e=Ws(e,t),n||(n=e.length>1),e}),$s(t,Gs(t),r),n&&(r=Us(r,7,zs));for(var o=e.length;o--;)Fs(r,e[o]);return r}),Vs=v(Bs);const Xs=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;EOL;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=u.homedir(),this.EOL=u.EOL,this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=f.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||f.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||f.join(this.homedir,".config");break;default:console.log(`當前系統是未知的平台: ${this.platform}`),this.isMAC=!1,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=this.homedir}this.appFolder=f.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return f.join(...t)}folderCheck(t){s.mkdirSync(t,{recursive:!0})}fileCheck(t){s.existsSync(t)||s.writeFileSync(t,"",{encoding:"utf8"})}}("aiia-sdk");class Ys{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=Xs.addPath(Xs.appFolder,this.fileName),Xs.fileCheck(this.filePath)}getFileDataSync(){const t=s.readFileSync(this.filePath,"utf8");try{return JSON.parse(t)}catch(t){return{}}}setFileDataSync(t){try{const e=JSON.stringify(t);s.writeFileSync(this.filePath,e,"utf8")}catch(t){}}async getFileData(){return new Promise(t=>{s.readFile(this.filePath,"utf8",(e,r)=>{if(e)t({});else try{t(JSON.parse(r))}catch(e){t({})}})})}async setFileData(t){return new Promise(e=>{try{const r=JSON.stringify(t);s.writeFile(this.filePath,r,"utf8",t=>{e()})}catch(t){}})}async getItem(t){return(await this.getFileData())[t]??null}async setItem(t,e){const r=await this.getFileData();r[t]=e,await this.setFileData(r)}async removeItem(t){const e=await this.getFileData(),r=Vs(e,t);await this.setFileData(r)}async clear(){await this.setFileData({})}getItemSync(t){return this.getFileDataSync()[t]??null}setItemSync(t,e){const r=this.getFileDataSync();r[t]=e,this.setFileDataSync(r)}removeItemSync(t){const e=Vs(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}class Hs{config;constructor(t){this.config=t,console.log("UEProxy, config=",t)}start(){console.log("UEProxy, start proxy")}send(t){let e=this.cloudToObj(t);if(e&&e.signal&&"osc"==e.signal){console.log("UEProxy, payload=",e);try{let t=e.content;const r=new l(t.host,t.port);console.debug("UEProxy, client open to port "+t.port),r.send(t.message,t=>{t&&console.error(t),r.close(),console.debug("UEProxy, client closed")})}catch(t){console.log(t)}}}cloudToObj(t){try{return JSON.parse(t)}catch(t){console.error("message transfer fail",t)}}onDestroy(){console.log("UEProxy, destroy proxy")}}class Ks{filePath;fileName;constructor(){this.fileName="log.txt",this.filePath=Xs.addPath(Xs.appFolder,this.fileName)}next(t,e,...r){try{const n=r.reduce((t,e)=>{switch(typeof e){case"string":case"number":case"bigint":return`${t} ${e.toString()}`;case"boolean":return`${t} ${e?"true":"false"}`;case"object":try{return`${t} ${JSON.stringify(e)}`}catch(e){return t}case"symbol":case"undefined":case"function":return`${t} [${typeof e}]`}},"");s.appendFileSync(this.filePath,`LOG(${t})__${e}__::${n}${Xs.EOL}`,{encoding:"utf8"})}catch(t){}}}class Js{config;stroage;apiProxy;chat;udpProxy;isStart;channelMap;destorySub;access_token;get accessToken(){return this.access_token}constructor(t,e){this.config=t,this.stroage=e,this.isStart=!1,this.destorySub=new r,this.channelMap=new Map,this.access_token=e.getItemSync(dn),this.apiProxy=new Da(this.config.endPoint.api),xn.code(Rn["指定模組初始化完成"],"api"),this.chat=new Aa(this.config),xn.code(Rn["指定模組初始化完成"],"chat"),this.udpProxy=new Hs(this.config),xn.code(Rn["指定模組初始化完成"],"udp")}async start(){if(this.isStart)throw new Error(vn["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.memberChange.pipe(o(this.destorySub)).subscribe(({type:t,socket:e})=>{switch(t){case"in":{xn.debug("member join",e.id);const t=new Na,c=new r,s=(a=e.handshake.query.uuid,Qt(a)?bn(a,"[0]",void 0):a??void 0);void 0===s?(this.getProjectList().then(t=>{e.emit("list",t)}),n(e,"uuid").pipe(i(1),o(c)).subscribe(r=>{this.openChannel(r,e,t,c)})):this.openChannel(s,e,t,c),this.channelMap.set(e.id,()=>{c.next(),c.complete()});break}case"out":xn.debug("member leave",e.id),this.channelMap.has(e.id)&&(this.channelMap.get(e.id)(),this.channelMap.delete(e.id))}var a}),this.chat.start(),xn.code(Rn["啟動服務"],"chat"),this.udpProxy.start(),xn.code(Rn["啟動服務"],"udp")}async replaceAccessToken(){const t=await this.apiProxy.getAccessToken(this.config.license,this.access_token);return this.access_token=t,this.stroage.setItemSync(dn,t),t}async getProjectList(){return await this.apiProxy.getProjectList(this.config.license)}getProxySocketURL(t){return`${this.config.endPoint.socket}/v1/chat/project/${this.accessToken}/${t}`}openChannel(t,e,r,i){n(e,"cloud").pipe(o(i)).subscribe(t=>{r.send(t)}),r.message.pipe(o(i)).subscribe(t=>{e.emit("cloud",t),this.udpProxy.send(t)}),r.close.pipe(o(i)).subscribe(async n=>{switch(e.emit("channel",n),n){case"close":case"no_permissions":r.onDestroy();break;case"reconnect":await this.replaceAccessToken(),r.reconnect(this.getProxySocketURL(t))}}),r.linkStart.pipe(o(i)).subscribe(()=>{e.emit("channel","open")}),i.subscribe(()=>{r.onClose()}),r.start(this.getProxySocketURL(t))}onDestroy(){this.apiProxy.onDestroy(),this.chat.onDestroy(),this.udpProxy.onDestroy(),this.destorySub.next(),this.destorySub.complete(),xn.code(Rn["服務結束"])}}function Qs(t){if(yn){if(void 0===bn(t,"license",void 0))throw new Error(vn["未提供憑證"]);!function(t){const{info:e,error:r,warn:n,debug:o,fatal:i,code:a}=function(t){if(void 0===t||"all"===t)return{code:!0,error:!0,warn:!0,info:!0,debug:!0,fatal:!0};if("none"===t)return{error:!1,code:!1,warn:!1,info:!1,debug:!1,fatal:!1};if("boolean"==typeof t)return{code:t,error:t,warn:t,info:t,debug:t,fatal:t};{const e=new Set(t);return{code:e.has("code"),debug:e.has("debug"),fatal:e.has("fatal"),error:e.has("error"),warn:e.has("warn"),info:e.has("info")}}}(t);return a||(Cn.code=()=>{}),o||(Cn.debug=()=>{}),e||(Cn.info=()=>{}),n||(Cn.warn=()=>{}),r||(Cn.error=()=>{}),i||(Cn.fatal=()=>{}),kn}(bn(t,"debug",!0))(new Ks),xn.code(Rn["開始初始化必要模組"]);const e=new _n(Te({},t));xn.code(Rn["指定模組初始化完成"],"config");const r=new Ys;xn.code(Rn["指定模組初始化完成"],"storage");const n=new Js(e,r);return xn.code(Rn["指定模組初始化完成"],"core"),n.start(),xn.code(Rn["啟動服務"]),()=>{n.onDestroy()}}throw new Error(vn["環境錯誤(nodejs)"])}export{Qs as aiiaCore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphen.ai/aiia-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "Jay Huang",
@@ -36,11 +36,12 @@
36
36
  "tsdoc-metadata.json"
37
37
  ],
38
38
  "scripts": {
39
- "clean": "rm -rf ./dist",
40
- "clean:type": "rm -rf ./dist/types",
39
+ "clean": "node rm.cjs ./dist",
40
+ "clean:type": "node rm.cjs ./dist/types",
41
41
  "build": "npm run clean && rollup -c && npm run types:extract",
42
42
  "watch": "rollup -c -w",
43
- "build:testmodule": "rm -rf ./dist_test && rollup -c ./rollup.module.config.js",
43
+ "build:testmodule": "node rm.cjs ./dist_test && rollup -c ./rollup.module.config.js",
44
+ "test": "jest",
44
45
  "types:extract": "npm run types:extract:browser && npm run types:extract:node && npm run clean:type",
45
46
  "types:extract:browser": "api-extractor run --local --config api-extractor.browser.json",
46
47
  "types:extract:node": "api-extractor run --local --config api-extractor.node.json"
@@ -56,8 +57,10 @@
56
57
  "@types/jest": "^30.0.0",
57
58
  "@types/lodash": "^4.17.20",
58
59
  "@types/node": "^24.2.1",
60
+ "@types/node-osc": "^9.1.0",
59
61
  "@types/ws": "^8.18.1",
60
62
  "jest": "^30.1.3",
63
+ "jest-environment-jsdom": "^30.1.2",
61
64
  "rollup": "^4.46.2",
62
65
  "rollup-plugin-javascript-obfuscator": "^1.0.1",
63
66
  "ts-jest": "^29.4.1",
@@ -65,9 +68,11 @@
65
68
  "typescript": "^5.9.2"
66
69
  },
67
70
  "dependencies": {
71
+ "@mediapipe/tasks-vision": "^0.10.22-rc.20250304",
68
72
  "axios": "^1.11.0",
69
73
  "lodash": "^4.17.21",
70
74
  "moment": "^2.30.1",
75
+ "node-osc": "^11.0.0",
71
76
  "rxjs": "^7.8.2",
72
77
  "socket.io": "^4.8.1",
73
78
  "socket.io-client": "^4.8.1",
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.11"
8
+ "packageVersion": "7.52.13"
9
9
  }
10
10
  ]
11
11
  }