@graphen.ai/aiia-sdk 1.0.4 → 1.0.6
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/LICENSE +1 -1
- package/README.md +40 -2
- package/dist/aiia-worklet.js +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.d.ts +106 -16
- package/dist/browser.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.ts +24 -3
- package/dist/node.mjs +1 -1
- package/package.json +7 -1
package/LICENSE
CHANGED
|
@@ -25,12 +25,12 @@ SOFTWARE.
|
|
|
25
25
|
This project uses the following third-party packages and complies with their respective licenses:
|
|
26
26
|
|
|
27
27
|
- axios (MIT License)
|
|
28
|
-
- cors (MIT License)
|
|
29
28
|
- lodash (MIT License)
|
|
30
29
|
- rxjs (Apache License 2.0)
|
|
31
30
|
- socket.io (MIT License)
|
|
32
31
|
- socket.io-client (MIT License)
|
|
33
32
|
- ws (MIT License)
|
|
33
|
+
- moment (MIT License)
|
|
34
34
|
|
|
35
35
|
Development dependencies:
|
|
36
36
|
- @microsoft/api-extractor (MIT License)
|
package/README.md
CHANGED
|
@@ -23,7 +23,9 @@ yarn add @graphen.ai/aiia-sdk
|
|
|
23
23
|
```typescript
|
|
24
24
|
import { initSdk } from '@graphen.ai/aiia-sdk/browser';
|
|
25
25
|
|
|
26
|
-
const sdk = new initSdk(
|
|
26
|
+
const sdk = new initSdk({
|
|
27
|
+
worklet_url: "<Please copy '@graphen.ai/aiia-sdk/dist/aiia-worklet.js' to your project's public folder and provide the source url>"
|
|
28
|
+
});
|
|
27
29
|
sdk.start()
|
|
28
30
|
```
|
|
29
31
|
|
|
@@ -35,9 +37,45 @@ import { aiiaCore } from '@graphen.ai/aiia-sdk/node';
|
|
|
35
37
|
const core = aiiaCore({ license: "<Your Token>" });
|
|
36
38
|
```
|
|
37
39
|
|
|
40
|
+
## 錯誤碼(Error Codes)
|
|
41
|
+
|
|
42
|
+
| 錯誤碼(Error Codes) | 描述 | desc |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| ERROR CODE: 500 | 網絡錯誤 | Network Error |
|
|
45
|
+
| ERROR CODE: 1001 | 環境錯誤(browser) | Environment Error - Browser |
|
|
46
|
+
| ERROR CODE: 1002 | Worklet模組載入失敗 | Worklet Module Loading Failed |
|
|
47
|
+
| ERROR CODE: 1003 | 未獲得媒體裝置權限 | Media Device Permission Not Granted |
|
|
48
|
+
| ERROR CODE: 1004 | 實例已摧毀 | Instance Destroyed |
|
|
49
|
+
| ERROR CODE: 2001 | 環境錯誤(nodejs) | Environment Error - Node.js |
|
|
50
|
+
| ERROR CODE: 2002 | 未提供憑證 | Credentials Not Provided |
|
|
51
|
+
| ERROR CODE: 2003 | 獲取權杖失敗 | Failed to Obtain Token |
|
|
52
|
+
| ERROR CODE: 2004 | 沒有可用專案 | No Available Project |
|
|
53
|
+
| ERROR CODE: 2005 | 重複初始化 | Duplicate Initialization |
|
|
54
|
+
|
|
55
|
+
## 訊息碼(Message Codes)
|
|
56
|
+
|
|
57
|
+
| 訊息碼(Message Codes) | 描述 | desc |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| CODE: 1000 | 通道、雲端服務、麥克風都已就緒 | Channel, Cloud Service, Microphone Ready |
|
|
60
|
+
| CODE: 1001 | 未取得媒體裝置權限,請重新設定或忽略此訊息 | Media Device Permission Not Granted, Please Reconfigure or Ignore This Message |
|
|
61
|
+
| CODE: 1002 | 請訂閱專案列表 | Please Subscribe to Project List |
|
|
62
|
+
| CODE: 1010 | 初始化必要依賴 | Initializing Required Dependencies |
|
|
63
|
+
| CODE: 1011 | 指定依賴已完成 | Specified Dependencies Completed |
|
|
64
|
+
| CODE: 1012 | 啟動SDK | Starting SDK |
|
|
65
|
+
| CODE: 1013 | 結束SDK | Ending SDK |
|
|
66
|
+
| CODE: 2000 | 安全的關閉連線 | Safely Closing Connection |
|
|
67
|
+
| CODE: 2001 | 無副作用的關閉連線 | Closing Connection Without Side Effects |
|
|
68
|
+
| CODE: 2002 | 與雲端的服務中斷 | Disconnected from Cloud Service |
|
|
69
|
+
| CODE: 2003 | 沒有授權,請聯繫Graphen | No Authorization, Please Contact Graphen |
|
|
70
|
+
| CODE: 2004 | 自動重新連線連端服務 | Automatically Reconnecting to Cloud Service |
|
|
71
|
+
| CODE: 2005 | 未預期的斷線,請聯繫Graphen | Unexpected Disconnection, Please Contact Graphen |
|
|
72
|
+
| CODE: 2010 | 開始初始化必要模組 | Starting Initialization of Required Modules |
|
|
73
|
+
| CODE: 2011 | 指定模組初始化完成 | Specified Module Initialization Completed |
|
|
74
|
+
| CODE: 2012 | 啟動服務 | Starting Service |
|
|
75
|
+
| CODE: 2013 | 服務結束 | Service Ended |
|
|
76
|
+
|
|
38
77
|
## 授權條款(LICENSE)
|
|
39
78
|
|
|
40
79
|
本專案採用 MIT 授權。詳見 [LICENSE](./LICENSE) 檔案。
|
|
41
80
|
|
|
42
81
|
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
|
43
|
-
|
package/dist/aiia-worklet.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";class e extends AudioWorkletProcessor{
|
|
1
|
+
!function(){"use strict";var t;!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}(t||(t={}));class e extends AudioWorkletProcessor{inputBuffer;inputBufferLength;processChunkSize;outputSampleRate;originalSampleRate;constructor(t){super(),this.inputBuffer=[],this.inputBufferLength=0;const{outputSampleRate:e,chunkTimeInSeconds:n}=Object.assign({outputSampleRate:16e3,chunkTimeInSeconds:1},t?.processorOptions);this.originalSampleRate=sampleRate,this.outputSampleRate=e,this.processChunkSize=function(t,e,n=1){const s=e*n,u=t/e;return Math.ceil(s*u)}(this.originalSampleRate,this.outputSampleRate,n)}process(t,e,n){const s=t[0][0];if(!s)return!0;const u=new Float32Array(s);if(this.inputBuffer.push(u),this.inputBufferLength+=s.length,this.inputBufferLength>=this.processChunkSize){const t=function(t){const e=t.reduce((t,e)=>t+e.length,0),n=new Float32Array(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n}(this.inputBuffer);this.inputBuffer=[],this.inputBufferLength=0;const e=function(t,e,n){if(e===n)return t;const s=n/e,u=Math.ceil(t.length*s),i=new Float32Array(u);for(let e=0;e<u;e++){const n=e/s,u=Math.floor(n),o=n-u,r=t[u],a=t[Math.min(u+1,t.length-1)];i[e]=r+(a-r)*o}return i}(t,this.originalSampleRate,this.outputSampleRate);this.port.postMessage({float32:e,outputSampleRate:this.outputSampleRate},[e.buffer])}return!0}}registerProcessor("aiia-vad",e)}();
|
package/dist/browser.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("rxjs"),e=require("socket.io-client"),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var o="object"==typeof r&&r&&r.Object===Object&&r,a=o,i="object"==typeof self&&self&&self.Object===Object&&self,u=a||i||Function("return this")(),s=u.Symbol,c=s,l=Object.prototype,f=l.hasOwnProperty,h=l.toString,d=c?c.toStringTag:void 0;var v=function(t){var e=f.call(t,d),r=t[d];try{t[d]=void 0;var n=!0}catch(t){}var o=h.call(t);return n&&(e?t[d]=r:delete t[d]),o},p=Object.prototype.toString;var b=v,y=function(t){return p.call(t)},g=s?s.toStringTag:void 0;var _=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?b(t):y(t)};var m=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},w=_,j=m;var S,O=function(t){if(!j(t))return!1;var e=w(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},R=u["__core-js_shared__"],x=(S=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"";var k=function(t){return!!x&&x in t},C=Function.prototype.toString;var A=function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""},N=O,E=k,M=m,P=A,z=/^\[object .+?Constructor\]$/,D=Function.prototype,B=Object.prototype,T=D.toString,F=B.hasOwnProperty,U=RegExp("^"+T.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var $=function(t){return!(!M(t)||E(t))&&(N(t)?U:z).test(P(t))},I=function(t,e){return null==t?void 0:t[e]};var V=function(t,e){var r=I(t,e);return $(r)?r:void 0},Q=V,q=function(){try{var t=Q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),W=q;var L=function(t,e,r){"__proto__"==e&&W?W(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var G=function(t,e){return t===e||t!=t&&e!=e},J=L,H=G,K=Object.prototype.hasOwnProperty;var X=function(t,e,r){var n=t[e];K.call(t,e)&&H(n,r)&&(void 0!==r||e in t)||J(t,e,r)},Y=X,Z=L;var tt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?Z(r,u,s):Y(r,u,s)}return r};var et=function(t){return t};var rt=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},nt=Math.max;var ot=function(t,e,r){return e=nt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=nt(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),rt(t,this,u)}};var at=function(t){return function(){return t}},it=q,ut=it?function(t,e){return it(t,"toString",{configurable:!0,enumerable:!1,value:at(e),writable:!0})}:et,st=Date.now;var ct=function(t){var e=0,r=0;return function(){var n=st(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ut),lt=et,ft=ot,ht=ct;var dt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},vt=O,pt=dt;var bt=function(t){return null!=t&&pt(t.length)&&!vt(t)},yt=/^(?:0|[1-9]\d*)$/;var gt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&yt.test(t))&&t>-1&&t%1==0&&t<e},_t=G,mt=bt,wt=gt,jt=m;var St=function(t,e){return ht(ft(t,e,lt),t+"")},Ot=function(t,e,r){if(!jt(r))return!1;var n=typeof e;return!!("number"==n?mt(r)&&wt(e,r.length):"string"==n&&e in r)&&_t(r[e],t)};var Rt=function(t){return St(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&Ot(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},xt=Object.prototype;var kt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||xt)};var Ct=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var At=function(t){return null!=t&&"object"==typeof t},Nt=_,Et=At;var Mt=function(t){return Et(t)&&"[object Arguments]"==Nt(t)},Pt=At,zt=Object.prototype,Dt=zt.hasOwnProperty,Bt=zt.propertyIsEnumerable,Tt=Mt(function(){return arguments}())?Mt:function(t){return Pt(t)&&Dt.call(t,"callee")&&!Bt.call(t,"callee")},Ft=Array.isArray,Ut=n(Ft),$t={exports:{}};var It=function(){return!1};!function(t,e){var r=u,n=It,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,s=(i?i.isBuffer:void 0)||n;t.exports=s}($t,$t.exports);var Vt=$t.exports,Qt=_,qt=dt,Wt=At,Lt={};Lt["[object Float32Array]"]=Lt["[object Float64Array]"]=Lt["[object Int8Array]"]=Lt["[object Int16Array]"]=Lt["[object Int32Array]"]=Lt["[object Uint8Array]"]=Lt["[object Uint8ClampedArray]"]=Lt["[object Uint16Array]"]=Lt["[object Uint32Array]"]=!0,Lt["[object Arguments]"]=Lt["[object Array]"]=Lt["[object ArrayBuffer]"]=Lt["[object Boolean]"]=Lt["[object DataView]"]=Lt["[object Date]"]=Lt["[object Error]"]=Lt["[object Function]"]=Lt["[object Map]"]=Lt["[object Number]"]=Lt["[object Object]"]=Lt["[object RegExp]"]=Lt["[object Set]"]=Lt["[object String]"]=Lt["[object WeakMap]"]=!1;var Gt=function(t){return Wt(t)&&qt(t.length)&&!!Lt[Qt(t)]};var Jt=function(t){return function(e){return t(e)}},Ht={exports:{}};!function(t,e){var r=o,n=e&&!e.nodeType&&e,a=n&&t&&!t.nodeType&&t,i=a&&a.exports===n&&r.process,u=function(){try{var t=a&&a.require&&a.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=u}(Ht,Ht.exports);var Kt=Ht.exports,Xt=Gt,Yt=Jt,Zt=Kt&&Kt.isTypedArray,te=Zt?Yt(Zt):Xt,ee=Ct,re=Tt,ne=Ft,oe=Vt,ae=gt,ie=te,ue=Object.prototype.hasOwnProperty;var se=function(t,e){var r=ne(t),n=!r&&re(t),o=!r&&!n&&oe(t),a=!r&&!n&&!o&&ie(t),i=r||n||o||a,u=i?ee(t.length,String):[],s=u.length;for(var c in t)!e&&!ue.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ae(c,s))||u.push(c);return u};var ce=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),le=kt,fe=ce,he=Object.prototype.hasOwnProperty;var de=se,ve=function(t){if(!le(t))return fe(t);var e=[];for(var r in Object(t))he.call(t,r)&&"constructor"!=r&&e.push(r);return e},pe=bt;var be,ye=function(t){return pe(t)?de(t):ve(t)},ge=X,_e=tt,me=Rt,we=bt,je=kt,Se=ye,Oe=Object.prototype.hasOwnProperty,Re=n(me(function(t,e){if(je(e)||we(e))_e(e,Se(e),t);else for(var r in e)Oe.call(e,r)&&ge(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(be||(be={}));const xe="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class ke{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Re({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Re({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ce=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Ae=Ce,Ne=function(t){return t!=t},Ee=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Me=function(t,e,r){return e==e?Ee(t,e,r):Ae(t,Ne,r)},Pe=_,ze=Ft,De=At;var Be=function(t){return"string"==typeof t||!ze(t)&&De(t)&&"[object String]"==Pe(t)},Te=/\s/;var Fe=function(t){for(var e=t.length;e--&&Te.test(t.charAt(e)););return e},Ue=/^\s+/;var $e=_,Ie=At;var Ve=function(t){return"symbol"==typeof t||Ie(t)&&"[object Symbol]"==$e(t)},Qe=function(t){return t?t.slice(0,Fe(t)+1).replace(Ue,""):t},qe=m,We=Ve,Le=/^[-+]0x[0-9a-f]+$/i,Ge=/^0b[01]+$/i,Je=/^0o[0-7]+$/i,He=parseInt;var Ke=function(t){if("number"==typeof t)return t;if(We(t))return NaN;if(qe(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=qe(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Qe(t);var r=Ge.test(t);return r||Je.test(t)?He(t.slice(2),r?2:8):Le.test(t)?NaN:+t},Xe=1/0;var Ye=function(t){return t?(t=Ke(t))===Xe||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ze=function(t){var e=Ye(t),r=e%1;return e==e?r?e-r:e:0};var tr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},er=tr;var rr=function(t,e){return er(e,function(e){return t[e]})},nr=ye;var or=function(t){return null==t?[]:rr(t,nr(t))},ar=n(or),ir=Me,ur=bt,sr=Be,cr=Ze,lr=or,fr=Math.max;var hr=n(function(t,e,r,n){t=ur(t)?t:lr(t),r=r&&!n?cr(r):0;var o=t.length;return r<0&&(r=fr(o+r,0)),sr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&ir(t,e,r)>-1});const dr={info:()=>{},error:()=>{},warn:()=>{}};function vr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:hr(t,"error"),warn:hr(t,"warn"),info:hr(t,"info")}}(t);e&&(dr.info=console.log),r&&(dr.error=console.error),n&&(dr.warn=console.warn)}var pr=Ft,br=Ve,yr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,gr=/^\w*$/;var _r=function(t,e){if(pr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!br(t))||(gr.test(t)||!yr.test(t)||null!=e&&t in Object(e))},mr=V(Object,"create"),wr=mr;var jr=function(){this.__data__=wr?wr(null):{},this.size=0};var Sr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Or=mr,Rr=Object.prototype.hasOwnProperty;var xr=function(t){var e=this.__data__;if(Or){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Rr.call(e,t)?e[t]:void 0},kr=mr,Cr=Object.prototype.hasOwnProperty;var Ar=mr;var Nr=jr,Er=Sr,Mr=xr,Pr=function(t){var e=this.__data__;return kr?void 0!==e[t]:Cr.call(e,t)},zr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Ar&&void 0===e?"__lodash_hash_undefined__":e,this};function 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=Nr,Dr.prototype.delete=Er,Dr.prototype.get=Mr,Dr.prototype.has=Pr,Dr.prototype.set=zr;var Br=Dr;var Tr=function(){this.__data__=[],this.size=0},Fr=G;var Ur=function(t,e){for(var r=t.length;r--;)if(Fr(t[r][0],e))return r;return-1},$r=Ur,Ir=Array.prototype.splice;var Vr=Ur;var Qr=Ur;var qr=Ur;var Wr=Tr,Lr=function(t){var e=this.__data__,r=$r(e,t);return!(r<0)&&(r==e.length-1?e.pop():Ir.call(e,r,1),--this.size,!0)},Gr=function(t){var e=this.__data__,r=Vr(e,t);return r<0?void 0:e[r][1]},Jr=function(t){return Qr(this.__data__,t)>-1},Hr=function(t,e){var r=this.__data__,n=qr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Kr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Kr.prototype.clear=Wr,Kr.prototype.delete=Lr,Kr.prototype.get=Gr,Kr.prototype.has=Jr,Kr.prototype.set=Hr;var Xr=Kr,Yr=V(u,"Map"),Zr=Br,tn=Xr,en=Yr;var rn=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var nn=function(t,e){var r=t.__data__;return rn(e)?r["string"==typeof e?"string":"hash"]:r.map},on=nn;var an=nn;var un=nn;var sn=nn;var cn=function(){this.size=0,this.__data__={hash:new Zr,map:new(en||tn),string:new Zr}},ln=function(t){var e=on(this,t).delete(t);return this.size-=e?1:0,e},fn=function(t){return an(this,t).get(t)},hn=function(t){return un(this,t).has(t)},dn=function(t,e){var r=sn(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function vn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}vn.prototype.clear=cn,vn.prototype.delete=ln,vn.prototype.get=fn,vn.prototype.has=hn,vn.prototype.set=dn;var pn=vn,bn=pn;function yn(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(yn.Cache||bn),r}yn.Cache=bn;var gn=yn;var _n=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,mn=/\\(\\)?/g,wn=function(t){var e=gn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(_n,function(t,r,n,o){e.push(n?o.replace(mn,"$1"):r||t)}),e}),jn=tr,Sn=Ft,On=Ve,Rn=s?s.prototype:void 0,xn=Rn?Rn.toString:void 0;var kn=function t(e){if("string"==typeof e)return e;if(Sn(e))return jn(e,t)+"";if(On(e))return xn?xn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Cn=kn;var An=Ft,Nn=_r,En=wn,Mn=function(t){return null==t?"":Cn(t)};var Pn=function(t,e){return An(t)?t:Nn(t,e)?[t]:En(Mn(t))},zn=Ve;var Dn=function(t){if("string"==typeof t||zn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Bn=Pn,Tn=Dn;var Fn=function(t,e){for(var r=0,n=(e=Bn(e,t)).length;null!=t&&r<n;)t=t[Tn(e[r++])];return r&&r==n?t:void 0},Un=Fn;var $n,In,Vn=function(t,e,r){var n=null==t?void 0:Un(t,e);return void 0===n?r:n},Qn=n(Vn);function qn(t,e,r){return Math.max(r,Math.min(t,e))}function Wn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Ln(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=qn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}($n||($n={}));class Gn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Wn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{dr.error("[ERROR]: pause speech fail"),dr.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{dr.error("[ERROR]: resume speech fail"),dr.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Jn{stream;audioContext;pcmSub;type="vad";workletNode;source;isRecording=!1;constructor(t,e,r){this.stream=t,this.audioContext=e,this.pcmSub=r}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(In||(In={}));class Hn{_state;stateSub;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get state(){return this._state}set state(t){t!==this._state&&(this._state=t,this.stateSub.next(t))}get stateObs(){return this.stateSub.asObservable()}constructor(){this.stateSub=new t.Subject,this.pcmSub=new t.Subject,this.destory=new t.Subject,this.state=In.padding}async init(t){if(this.destory.closed)throw new Error(be["實例已摧毀"]);const e=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===e)throw this.state=In.rejected,new Error(be["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw dr.error(t),this.state=In.loadfail,new Error(be["Worklet模組載入失敗"])}this.state=In.allowed,this.audioManager=new Gn(this.audioCtx),this.vadManager=new Jn(e,this.audioCtx,this.pcmSub)}addAudioQueue(t){const e=Qn(t,"buffer",void 0),r=Qn(t,"float32",void 0),n=Qn(t,"int16",void 0),o=Qn(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx?.close(),this.destory.next(),this.destory.complete()}}var Kn=Xr;var Xn=Xr,Yn=Yr,Zn=pn;var to=Xr,eo=function(){this.__data__=new Kn,this.size=0},ro=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},no=function(t){return this.__data__.get(t)},oo=function(t){return this.__data__.has(t)},ao=function(t,e){var r=this.__data__;if(r instanceof Xn){var n=r.__data__;if(!Yn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Zn(n)}return r.set(t,e),this.size=r.size,this};function io(t){var e=this.__data__=new to(t);this.size=e.size}io.prototype.clear=eo,io.prototype.delete=ro,io.prototype.get=no,io.prototype.has=oo,io.prototype.set=ao;var uo=io;var so=pn,co=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},lo=function(t){return this.__data__.has(t)};function fo(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new so;++e<r;)this.add(t[e])}fo.prototype.add=fo.prototype.push=co,fo.prototype.has=lo;var ho=fo,vo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},po=function(t,e){return t.has(e)};var bo=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),l=a.get(e);if(c&&l)return c==e&&l==t;var f=-1,h=!0,d=2&r?new ho:void 0;for(a.set(t,e),a.set(e,t);++f<u;){var v=t[f],p=e[f];if(n)var b=i?n(p,v,f,e,t,a):n(v,p,f,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!vo(e,function(t,e){if(!po(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var yo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var go=u.Uint8Array,_o=G,mo=bo,wo=yo,jo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},So=s?s.prototype:void 0,Oo=So?So.valueOf:void 0;var Ro=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new go(t),new go(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return _o(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=wo;case"[object Set]":var s=1&n;if(u||(u=jo),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var l=mo(u(t),u(e),n,o,a,i);return i.delete(t),l;case"[object Symbol]":if(Oo)return Oo.call(t)==Oo.call(e)}return!1};var xo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},ko=xo,Co=Ft;var Ao=function(t,e,r){var n=e(t);return Co(t)?n:ko(n,r(t))};var No=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Eo=function(){return[]},Mo=Object.prototype.propertyIsEnumerable,Po=Object.getOwnPropertySymbols,zo=Ao,Do=Po?function(t){return null==t?[]:(t=Object(t),No(Po(t),function(e){return Mo.call(t,e)}))}:Eo,Bo=ye;var To=function(t){return zo(t,Bo,Do)},Fo=Object.prototype.hasOwnProperty;var Uo=function(t,e,r,n,o,a){var i=1&r,u=To(t),s=u.length;if(s!=To(e).length&&!i)return!1;for(var c=s;c--;){var l=u[c];if(!(i?l in e:Fo.call(e,l)))return!1}var f=a.get(t),h=a.get(e);if(f&&h)return f==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[l=u[c]],b=e[l];if(n)var y=i?n(b,p,l,e,t,a):n(p,b,l,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==l)}if(d&&!v){var g=t.constructor,_=e.constructor;g==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof _&&_ instanceof _||(d=!1)}return a.delete(t),a.delete(e),d},$o=V(u,"DataView"),Io=Yr,Vo=V(u,"Promise"),Qo=V(u,"Set"),qo=V(u,"WeakMap"),Wo=_,Lo=A,Go="[object Map]",Jo="[object Promise]",Ho="[object Set]",Ko="[object WeakMap]",Xo="[object DataView]",Yo=Lo($o),Zo=Lo(Io),ta=Lo(Vo),ea=Lo(Qo),ra=Lo(qo),na=Wo;($o&&na(new $o(new ArrayBuffer(1)))!=Xo||Io&&na(new Io)!=Go||Vo&&na(Vo.resolve())!=Jo||Qo&&na(new Qo)!=Ho||qo&&na(new qo)!=Ko)&&(na=function(t){var e=Wo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Lo(r):"";if(n)switch(n){case Yo:return Xo;case Zo:return Go;case ta:return Jo;case ea:return Ho;case ra:return Ko}return e});var oa=uo,aa=bo,ia=Ro,ua=Uo,sa=na,ca=Ft,la=Vt,fa=te,ha="[object Arguments]",da="[object Array]",va="[object Object]",pa=Object.prototype.hasOwnProperty;var ba=function(t,e,r,n,o,a){var i=ca(t),u=ca(e),s=i?da:sa(t),c=u?da:sa(e),l=(s=s==ha?va:s)==va,f=(c=c==ha?va:c)==va,h=s==c;if(h&&la(t)){if(!la(e))return!1;i=!0,l=!1}if(h&&!l)return a||(a=new oa),i||fa(t)?aa(t,e,r,n,o,a):ia(t,e,s,r,n,o,a);if(!(1&r)){var d=l&&pa.call(t,"__wrapped__"),v=f&&pa.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new oa),o(p,b,r,n,a)}}return!!h&&(a||(a=new oa),ua(t,e,r,n,o,a))},ya=At;var ga=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ya(e)&&!ya(r)?e!=e&&r!=r:ba(e,r,n,o,t,a))},_a=uo,ma=ga;var wa=m;var ja=function(t){return t==t&&!wa(t)},Sa=ja,Oa=ye;var Ra=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},xa=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],l=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var f=new _a;if(n)var h=n(c,l,s,t,e,f);if(!(void 0===h?ma(l,c,3,n,f):h))return!1}}return!0},ka=function(t){for(var e=Oa(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Sa(o)]}return e},Ca=Ra;var Aa=Pn,Na=Tt,Ea=Ft,Ma=gt,Pa=dt,za=Dn;var Da=function(t,e){return null!=t&&e in Object(t)},Ba=function(t,e,r){for(var n=-1,o=(e=Aa(e,t)).length,a=!1;++n<o;){var i=za(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&Pa(o)&&Ma(i,o)&&(Ea(t)||Na(t))};var Ta=ga,Fa=Vn,Ua=function(t,e){return null!=t&&Ba(t,e,Da)},$a=_r,Ia=ja,Va=Ra,Qa=Dn;var qa=Fn;var Wa=function(t){return function(e){return null==e?void 0:e[t]}},La=function(t){return function(e){return qa(e,t)}},Ga=_r,Ja=Dn;var Ha=function(t){var e=ka(t);return 1==e.length&&e[0][2]?Ca(e[0][0],e[0][1]):function(r){return r===t||xa(r,t,e)}},Ka=function(t,e){return $a(t)&&Ia(e)?Va(Qa(t),e):function(r){var n=Fa(r,t);return void 0===n&&n===e?Ua(r,t):Ta(e,n,3)}},Xa=et,Ya=Ft,Za=function(t){return Ga(t)?Wa(Ja(t)):La(t)};var ti=function(t){return"function"==typeof t?t:null==t?Xa:"object"==typeof t?Ya(t)?Ka(t[0],t[1]):Ha(t):Za(t)};var ei=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ri=ye;var ni=bt;var oi=function(t,e){return function(r,n){if(null==r)return r;if(!ni(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&ei(t,e,ri)}),ai=bt;var ii=tr,ui=ti,si=function(t,e){var r=-1,n=ai(t)?Array(t.length):[];return oi(t,function(t,o,a){n[++r]=e(t,o,a)}),n},ci=Ft;var li=n(function(t,e){return(ci(t)?ii:si)(t,ui(e))}),fi=ti,hi=bt,di=ye;var vi=function(t){return function(e,r,n){var o=Object(e);if(!hi(e)){var a=fi(r);e=di(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},pi=Ce,bi=ti,yi=Ze,gi=Math.max;var _i,mi=n(vi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:yi(r);return o<0&&(o=gi(n+o,0)),pi(t,bi(e),o)}));class wi{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(r){this.destorySub=new t.Subject,this.messageSub=new t.Subject;const{specific:n,id:o}=r.project;this.socket=e.io(r.ws_url,Re({autoConnect:!1},n&&void 0!==o?{query:{uuid:o}}:{}))}start(){const e="list",r="cloud",n="channel";t.fromEvent(this.socket,e).pipe(t.take(1),t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:e,data:t})}),t.fromEvent(this.socket,r).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),t.fromEvent(this.socket,n).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:n,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(_i||(_i={}));class ji{config;media;chat;destorySub;projectsSub;layoutSub;aiiaSubtitleSub;userSubtitleSub;cloudSampleRate;channelState;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(e,r){this.config=e,this.media=r,this.layoutSub=new t.Subject,this.projectsSub=new t.Subject,this.destorySub=new t.Subject,this.aiiaSubtitleSub=new t.Subject,this.userSubtitleSub=new t.Subject,this.cloudSampleRate=16e3,this.channelState={proxy:!1,cloud:!1},this.chat=new wi(e)}start(){this.media.stateObs.pipe(t.takeUntil(this.destorySub)).subscribe(()=>{this.channelCheck()}),this.chat.message.pipe(t.takeUntil(this.destorySub)).subscribe(({event:t,data:e})=>{switch(t){case"cloud":this.cloudToObj(e);break;case"list":{const{id:t,name:r,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=mi(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):(this.projectsSub.next(e),dr.info("Please subscribe `projects` and call `chooseProject` method"));break}case"channel":"open"===e&&(this.channelState.proxy=!0,this.channelCheck())}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==Qn(e,"signal")?this.behavior(e):Ut(e)?li(e,this.behavior):li(ar(e),this.behavior)}catch(t){dr.error("aiia websocket","onmessage error",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate=t.content;else switch(t.command){case"pcm":{const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Wn(new Int16Array(t.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===Qn(t,"content")&&(this.channelState.cloud=!0,this.channelCheck());break;case"agent":{const e=Qn(t,"content.function_result.response");e&&this.aiiaSubtitleSub.next(e);break}case"asr":if("ASR"===Qn(t,"content.function_type")){const e=Qn(t,"content.function_result.result");e&&this.userSubtitleSub.next(e)}break;default:dr.info(t.signal)}}channelCheck(){const{proxy:e,cloud:r}=this.channelState;e&&r&&this.media.state===In.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}),this.media.pcm.pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Ln(t)})}),this.media.startRecord(),dr.info("Channel, Cloud and Media are ready.")):e&&r&&this.media.state!==In.allowed&&dr.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.")}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}exports.MediaManager=Hn,exports.initSdk=function(t){if(xe){const e=new ke(Re({},t));vr(e.debug);const r=new Hn,n=new ji(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(be["環境錯誤(browser)"])};
|
|
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&>.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)"])};
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { Http2SecureServer } from 'http2';
|
|
2
2
|
import { Http2Server } from 'http2';
|
|
3
|
-
import { Http2ServerRequest } from 'http2';
|
|
4
|
-
import { Http2ServerResponse } from 'http2';
|
|
5
|
-
import { IncomingMessage } from 'http';
|
|
6
3
|
import { Observable } from 'rxjs';
|
|
7
4
|
import { Server } from 'http';
|
|
8
5
|
import { Server as Server_2 } from 'https';
|
|
9
|
-
import { ServerResponse } from 'http';
|
|
10
6
|
|
|
11
7
|
declare class AiiaConfig {
|
|
12
8
|
private config;
|
|
13
|
-
get webserver(): Server<
|
|
9
|
+
get webserver(): (Server<any, any> | Server_2<any, any> | Http2SecureServer<any, any, any, any> | Http2Server<any, any, any, any>) | undefined;
|
|
14
10
|
get environment(): "developement" | "production" | undefined;
|
|
15
11
|
get license(): string;
|
|
16
12
|
get port(): number;
|
|
@@ -23,7 +19,10 @@ declare class AiiaConfig {
|
|
|
23
19
|
api: string;
|
|
24
20
|
socket: string;
|
|
25
21
|
};
|
|
26
|
-
get debug(): boolean | "all" | "none" |
|
|
22
|
+
get debug(): boolean | "all" | "none" | LoggerLevel[];
|
|
23
|
+
get mediaStream(): MediaStream | undefined;
|
|
24
|
+
get chunkTimeInSeconds(): number;
|
|
25
|
+
get llmSampleRate(): number;
|
|
27
26
|
constructor(config: InitOptions);
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -33,7 +32,7 @@ export declare interface AiiaProjectItem {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
declare class AiiaSdk {
|
|
36
|
-
config
|
|
35
|
+
private config;
|
|
37
36
|
private media;
|
|
38
37
|
private chat;
|
|
39
38
|
private destorySub;
|
|
@@ -43,9 +42,19 @@ declare class AiiaSdk {
|
|
|
43
42
|
private userSubtitleSub;
|
|
44
43
|
private cloudSampleRate;
|
|
45
44
|
private channelState;
|
|
45
|
+
private stateSub;
|
|
46
|
+
private isMuteAiia;
|
|
47
|
+
/**
|
|
48
|
+
* [zh]
|
|
49
|
+
* 服務的狀態
|
|
50
|
+
*
|
|
51
|
+
* [en]
|
|
52
|
+
* state of service
|
|
53
|
+
*/
|
|
54
|
+
get state(): Observable<AiiaState>;
|
|
46
55
|
/**
|
|
47
56
|
* [zh]
|
|
48
|
-
*
|
|
57
|
+
* 控制組件
|
|
49
58
|
*
|
|
50
59
|
* [en]
|
|
51
60
|
* Control Layout
|
|
@@ -64,6 +73,8 @@ declare class AiiaSdk {
|
|
|
64
73
|
} | {
|
|
65
74
|
type: "unmount";
|
|
66
75
|
id: LayoutID;
|
|
76
|
+
} | {
|
|
77
|
+
type: "resetLayout";
|
|
67
78
|
}>;
|
|
68
79
|
/**
|
|
69
80
|
* [zh]
|
|
@@ -105,23 +116,77 @@ declare class AiiaSdk {
|
|
|
105
116
|
set volume(val: number);
|
|
106
117
|
get volume(): number;
|
|
107
118
|
constructor(config: AiiaConfig, media: MediaManager);
|
|
119
|
+
/**
|
|
120
|
+
* [zh]
|
|
121
|
+
* 啟動完整服務
|
|
122
|
+
*
|
|
123
|
+
* [en]
|
|
124
|
+
* Start the full service
|
|
125
|
+
*/
|
|
108
126
|
start(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Alias for `onDestory`.
|
|
129
|
+
*
|
|
130
|
+
* [zh]
|
|
131
|
+
* 停止所有服務,釋放資源
|
|
132
|
+
*
|
|
133
|
+
* [en]
|
|
134
|
+
* Stop all services to release resources
|
|
135
|
+
*/
|
|
136
|
+
close: () => void;
|
|
137
|
+
/**
|
|
138
|
+
* [zh]
|
|
139
|
+
* 重置當前對話,清除播放中的語音
|
|
140
|
+
*
|
|
141
|
+
* [en]
|
|
142
|
+
* Reset the current conversation and clear the playing voice.
|
|
143
|
+
*/
|
|
144
|
+
resetSession(): void;
|
|
109
145
|
/**
|
|
110
146
|
* [zh]
|
|
111
147
|
* 若沒有明確指定 Project 時,請呼叫此方法
|
|
112
148
|
*
|
|
113
149
|
* [en]
|
|
114
|
-
* If no Project is explicitly specified, please execute this method
|
|
150
|
+
* If no Project is explicitly specified, please execute this method.
|
|
115
151
|
* @param project_id
|
|
116
152
|
*/
|
|
117
|
-
chooseProject(project_id:
|
|
153
|
+
chooseProject(project_id: AiiaProjectItem["id"]): void;
|
|
154
|
+
/**
|
|
155
|
+
* [zh]
|
|
156
|
+
* 不同於`this.volume = 0`的調整輸出音量
|
|
157
|
+
*
|
|
158
|
+
* 此方法會暫停麥克風輸入及清除所有音訊資料
|
|
159
|
+
*
|
|
160
|
+
* [en]
|
|
161
|
+
* Unlike `this.volume = 0` which adjusts the output volume,
|
|
162
|
+
*
|
|
163
|
+
* This method will pause mic record and clear all audio data
|
|
164
|
+
*/
|
|
165
|
+
mute(): void;
|
|
166
|
+
/**
|
|
167
|
+
* [zh]
|
|
168
|
+
* 恢復聲音訊號資料
|
|
169
|
+
*
|
|
170
|
+
* [en]
|
|
171
|
+
* Restore audio signal data
|
|
172
|
+
*/
|
|
173
|
+
unmute(): void;
|
|
118
174
|
private cloudToObj;
|
|
119
175
|
private behavior;
|
|
120
176
|
private channelCheck;
|
|
177
|
+
/**
|
|
178
|
+
* [zh]
|
|
179
|
+
* 停止所有服務,釋放資源
|
|
180
|
+
*
|
|
181
|
+
* [en]
|
|
182
|
+
* Stop all services to release resources
|
|
183
|
+
*/
|
|
121
184
|
onDestory(): void;
|
|
122
185
|
}
|
|
123
186
|
|
|
124
|
-
export declare type
|
|
187
|
+
export declare type AiiaState = "NotStart" | "ConnectingCloud" | "ReconnectingCloud" | "InService" | "InServiceNoMedia" | "NoPermissions" | "CloseService" | "Destory";
|
|
188
|
+
|
|
189
|
+
export declare type BrowserInitOptions = Omit<InitOptions, "webserver" | "port" | "license">;
|
|
125
190
|
|
|
126
191
|
declare interface InitOptions {
|
|
127
192
|
/**
|
|
@@ -155,7 +220,7 @@ declare interface InitOptions {
|
|
|
155
220
|
* [en]
|
|
156
221
|
* Extending "socket.io" to your web server
|
|
157
222
|
*/
|
|
158
|
-
webserver?:
|
|
223
|
+
webserver?: Webserver;
|
|
159
224
|
/**
|
|
160
225
|
* [zh]
|
|
161
226
|
* 伺服器 port
|
|
@@ -189,14 +254,34 @@ declare interface InitOptions {
|
|
|
189
254
|
* [en]
|
|
190
255
|
* Switch message(info, error, warn) dispaly, default: true
|
|
191
256
|
*/
|
|
192
|
-
debug?: boolean | "all" | "none" |
|
|
257
|
+
debug?: boolean | "all" | "none" | LoggerLevel[];
|
|
258
|
+
mediaStream?: MediaStream;
|
|
259
|
+
/**
|
|
260
|
+
* [zh]
|
|
261
|
+
* 檢測聲音的區塊大小(秒),預設 1 秒
|
|
262
|
+
*
|
|
263
|
+
* [en]
|
|
264
|
+
* Detecting the chunk size of the sound(unit is second), default 1 second.
|
|
265
|
+
*/
|
|
266
|
+
chunkTimeInSeconds?: number;
|
|
267
|
+
/**
|
|
268
|
+
* [zh]
|
|
269
|
+
* 指定音訊輸出的採樣率(提供給LLM分析)。不推薦更動
|
|
270
|
+
*
|
|
271
|
+
* [en]
|
|
272
|
+
* Specify the sampling rate of audio output (provided for LLM analysis). Changing is not recommended.
|
|
273
|
+
*/
|
|
274
|
+
llmSampleRate?: number;
|
|
193
275
|
}
|
|
194
276
|
|
|
195
277
|
export declare function initSdk(options?: BrowserInitOptions): AiiaSdk;
|
|
196
278
|
|
|
197
279
|
declare type LayoutID = string | number;
|
|
198
280
|
|
|
199
|
-
|
|
281
|
+
declare type LoggerLevel = "info" | "error" | "warn" | "debug" | "fatal" | "code";
|
|
282
|
+
|
|
283
|
+
declare class MediaManager {
|
|
284
|
+
stream?: MediaStream | undefined;
|
|
200
285
|
private _state;
|
|
201
286
|
private stateSub;
|
|
202
287
|
private audioCtx?;
|
|
@@ -209,8 +294,11 @@ export declare class MediaManager {
|
|
|
209
294
|
get state(): MediaStateEnum;
|
|
210
295
|
set state(v: MediaStateEnum);
|
|
211
296
|
get stateObs(): Observable<MediaStateEnum>;
|
|
212
|
-
constructor();
|
|
213
|
-
init(workletUrl: string
|
|
297
|
+
constructor(stream?: MediaStream | undefined);
|
|
298
|
+
init(workletUrl: string, config?: {
|
|
299
|
+
chunkTimeInSeconds?: number | undefined;
|
|
300
|
+
outputSampleRate?: number | undefined;
|
|
301
|
+
}): Promise<void>;
|
|
214
302
|
addAudioQueue(input: {
|
|
215
303
|
buffer: AudioBuffer;
|
|
216
304
|
} | {
|
|
@@ -236,4 +324,6 @@ declare enum MediaStateEnum {
|
|
|
236
324
|
allowed = 3
|
|
237
325
|
}
|
|
238
326
|
|
|
327
|
+
declare type Webserver = Server<any, any> | Server_2<any, any> | Http2SecureServer<any, any, any, any> | Http2Server<any, any, any, any>;
|
|
328
|
+
|
|
239
329
|
export { }
|
package/dist/browser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Subject as t,fromEvent as e,take as r,takeUntil as n}from"rxjs";import{io as o}from"socket.io-client";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u="object"==typeof a&&a&&a.Object===Object&&a,s=u,c="object"==typeof self&&self&&self.Object===Object&&self,l=s||c||Function("return this")(),f=l.Symbol,h=f,d=Object.prototype,v=d.hasOwnProperty,p=d.toString,b=h?h.toStringTag:void 0;var y=function(t){var e=v.call(t,b),r=t[b];try{t[b]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[b]=r:delete t[b]),o},g=Object.prototype.toString;var _=y,m=function(t){return g.call(t)},w=f?f.toStringTag:void 0;var j=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?_(t):m(t)};var S=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},O=j,R=S;var x,k=function(t){if(!R(t))return!1;var e=O(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},C=l["__core-js_shared__"],A=(x=/[^.]+$/.exec(C&&C.keys&&C.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"";var N=function(t){return!!A&&A in t},E=Function.prototype.toString;var M=function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""},P=k,z=N,D=S,B=M,T=/^\[object .+?Constructor\]$/,F=Function.prototype,$=Object.prototype,I=F.toString,V=$.hasOwnProperty,Q=RegExp("^"+I.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var U=function(t){return!(!D(t)||z(t))&&(P(t)?Q:T).test(B(t))},W=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=W(t,e);return U(r)?r:void 0},L=q,G=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=G;var H=function(t,e,r){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var K=function(t,e){return t===e||t!=t&&e!=e},X=H,Y=K,Z=Object.prototype.hasOwnProperty;var tt=function(t,e,r){var n=t[e];Z.call(t,e)&&Y(n,r)&&(void 0!==r||e in t)||X(t,e,r)},et=tt,rt=H;var nt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?rt(r,u,s):et(r,u,s)}return r};var ot=function(t){return t};var at=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},it=Math.max;var ut=function(t,e,r){return e=it(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=it(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),at(t,this,u)}};var st=function(t){return function(){return t}},ct=G,lt=ct?function(t,e){return ct(t,"toString",{configurable:!0,enumerable:!1,value:st(e),writable:!0})}:ot,ft=Date.now;var ht=function(t){var e=0,r=0;return function(){var n=ft(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(lt),dt=ot,vt=ut,pt=ht;var bt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},yt=k,gt=bt;var _t=function(t){return null!=t&>(t.length)&&!yt(t)},mt=/^(?:0|[1-9]\d*)$/;var wt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&mt.test(t))&&t>-1&&t%1==0&&t<e},jt=K,St=_t,Ot=wt,Rt=S;var xt=function(t,e){return pt(vt(t,e,dt),t+"")},kt=function(t,e,r){if(!Rt(r))return!1;var n=typeof e;return!!("number"==n?St(r)&&Ot(e,r.length):"string"==n&&e in r)&&jt(r[e],t)};var Ct=function(t){return xt(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&kt(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},At=Object.prototype;var Nt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||At)};var Et=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Mt=function(t){return null!=t&&"object"==typeof t},Pt=j,zt=Mt;var Dt=function(t){return zt(t)&&"[object Arguments]"==Pt(t)},Bt=Mt,Tt=Object.prototype,Ft=Tt.hasOwnProperty,$t=Tt.propertyIsEnumerable,It=Dt(function(){return arguments}())?Dt:function(t){return Bt(t)&&Ft.call(t,"callee")&&!$t.call(t,"callee")},Vt=Array.isArray,Qt=i(Vt),Ut={exports:{}};var Wt=function(){return!1};!function(t,e){var r=l,n=Wt,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,u=(i?i.isBuffer:void 0)||n;t.exports=u}(Ut,Ut.exports);var qt=Ut.exports,Lt=j,Gt=bt,Jt=Mt,Ht={};Ht["[object Float32Array]"]=Ht["[object Float64Array]"]=Ht["[object Int8Array]"]=Ht["[object Int16Array]"]=Ht["[object Int32Array]"]=Ht["[object Uint8Array]"]=Ht["[object Uint8ClampedArray]"]=Ht["[object Uint16Array]"]=Ht["[object Uint32Array]"]=!0,Ht["[object Arguments]"]=Ht["[object Array]"]=Ht["[object ArrayBuffer]"]=Ht["[object Boolean]"]=Ht["[object DataView]"]=Ht["[object Date]"]=Ht["[object Error]"]=Ht["[object Function]"]=Ht["[object Map]"]=Ht["[object Number]"]=Ht["[object Object]"]=Ht["[object RegExp]"]=Ht["[object Set]"]=Ht["[object String]"]=Ht["[object WeakMap]"]=!1;var Kt=function(t){return Jt(t)&&Gt(t.length)&&!!Ht[Lt(t)]};var Xt=function(t){return function(e){return t(e)}},Yt={exports:{}};!function(t,e){var r=u,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,a=o&&o.exports===n&&r.process,i=function(){try{var t=o&&o.require&&o.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=i}(Yt,Yt.exports);var Zt=Yt.exports,te=Kt,ee=Xt,re=Zt&&Zt.isTypedArray,ne=re?ee(re):te,oe=Et,ae=It,ie=Vt,ue=qt,se=wt,ce=ne,le=Object.prototype.hasOwnProperty;var fe=function(t,e){var r=ie(t),n=!r&&ae(t),o=!r&&!n&&ue(t),a=!r&&!n&&!o&&ce(t),i=r||n||o||a,u=i?oe(t.length,String):[],s=u.length;for(var c in t)!e&&!le.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||se(c,s))||u.push(c);return u};var he=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),de=Nt,ve=he,pe=Object.prototype.hasOwnProperty;var be=fe,ye=function(t){if(!de(t))return ve(t);var e=[];for(var r in Object(t))pe.call(t,r)&&"constructor"!=r&&e.push(r);return e},ge=_t;var _e,me=function(t){return ge(t)?be(t):ye(t)},we=tt,je=nt,Se=Ct,Oe=_t,Re=Nt,xe=me,ke=Object.prototype.hasOwnProperty,Ce=i(Se(function(t,e){if(Re(e)||Oe(e))je(e,xe(e),t);else for(var r in e)ke.call(e,r)&&we(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(_e||(_e={}));const Ae="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class Ne{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Ce({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Ce({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ee=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Me=Ee,Pe=function(t){return t!=t},ze=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var De=function(t,e,r){return e==e?ze(t,e,r):Me(t,Pe,r)},Be=j,Te=Vt,Fe=Mt;var $e=function(t){return"string"==typeof t||!Te(t)&&Fe(t)&&"[object String]"==Be(t)},Ie=/\s/;var Ve=function(t){for(var e=t.length;e--&&Ie.test(t.charAt(e)););return e},Qe=/^\s+/;var Ue=j,We=Mt;var qe=function(t){return"symbol"==typeof t||We(t)&&"[object Symbol]"==Ue(t)},Le=function(t){return t?t.slice(0,Ve(t)+1).replace(Qe,""):t},Ge=S,Je=qe,He=/^[-+]0x[0-9a-f]+$/i,Ke=/^0b[01]+$/i,Xe=/^0o[0-7]+$/i,Ye=parseInt;var Ze=function(t){if("number"==typeof t)return t;if(Je(t))return NaN;if(Ge(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Ge(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Le(t);var r=Ke.test(t);return r||Xe.test(t)?Ye(t.slice(2),r?2:8):He.test(t)?NaN:+t},tr=1/0;var er=function(t){return t?(t=Ze(t))===tr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var rr=function(t){var e=er(t),r=e%1;return e==e?r?e-r:e:0};var nr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},or=nr;var ar=function(t,e){return or(e,function(e){return t[e]})},ir=me;var ur=function(t){return null==t?[]:ar(t,ir(t))},sr=i(ur),cr=De,lr=_t,fr=$e,hr=rr,dr=ur,vr=Math.max;var pr=i(function(t,e,r,n){t=lr(t)?t:dr(t),r=r&&!n?hr(r):0;var o=t.length;return r<0&&(r=vr(o+r,0)),fr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&cr(t,e,r)>-1});const br={info:()=>{},error:()=>{},warn:()=>{}};function yr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:pr(t,"error"),warn:pr(t,"warn"),info:pr(t,"info")}}(t);e&&(br.info=console.log),r&&(br.error=console.error),n&&(br.warn=console.warn)}var gr=Vt,_r=qe,mr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wr=/^\w*$/;var jr=function(t,e){if(gr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!_r(t))||(wr.test(t)||!mr.test(t)||null!=e&&t in Object(e))},Sr=q(Object,"create"),Or=Sr;var Rr=function(){this.__data__=Or?Or(null):{},this.size=0};var xr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},kr=Sr,Cr=Object.prototype.hasOwnProperty;var Ar=function(t){var e=this.__data__;if(kr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Cr.call(e,t)?e[t]:void 0},Nr=Sr,Er=Object.prototype.hasOwnProperty;var Mr=Sr;var Pr=Rr,zr=xr,Dr=Ar,Br=function(t){var e=this.__data__;return Nr?void 0!==e[t]:Er.call(e,t)},Tr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Mr&&void 0===e?"__lodash_hash_undefined__":e,this};function Fr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Fr.prototype.clear=Pr,Fr.prototype.delete=zr,Fr.prototype.get=Dr,Fr.prototype.has=Br,Fr.prototype.set=Tr;var $r=Fr;var Ir=function(){this.__data__=[],this.size=0},Vr=K;var Qr=function(t,e){for(var r=t.length;r--;)if(Vr(t[r][0],e))return r;return-1},Ur=Qr,Wr=Array.prototype.splice;var qr=Qr;var Lr=Qr;var Gr=Qr;var Jr=Ir,Hr=function(t){var e=this.__data__,r=Ur(e,t);return!(r<0)&&(r==e.length-1?e.pop():Wr.call(e,r,1),--this.size,!0)},Kr=function(t){var e=this.__data__,r=qr(e,t);return r<0?void 0:e[r][1]},Xr=function(t){return Lr(this.__data__,t)>-1},Yr=function(t,e){var r=this.__data__,n=Gr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Zr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Zr.prototype.clear=Jr,Zr.prototype.delete=Hr,Zr.prototype.get=Kr,Zr.prototype.has=Xr,Zr.prototype.set=Yr;var tn=Zr,en=q(l,"Map"),rn=$r,nn=tn,on=en;var an=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var un=function(t,e){var r=t.__data__;return an(e)?r["string"==typeof e?"string":"hash"]:r.map},sn=un;var cn=un;var ln=un;var fn=un;var hn=function(){this.size=0,this.__data__={hash:new rn,map:new(on||nn),string:new rn}},dn=function(t){var e=sn(this,t).delete(t);return this.size-=e?1:0,e},vn=function(t){return cn(this,t).get(t)},pn=function(t){return ln(this,t).has(t)},bn=function(t,e){var r=fn(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function yn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}yn.prototype.clear=hn,yn.prototype.delete=dn,yn.prototype.get=vn,yn.prototype.has=pn,yn.prototype.set=bn;var gn=yn,_n=gn;function mn(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(mn.Cache||_n),r}mn.Cache=_n;var wn=mn;var jn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Sn=/\\(\\)?/g,On=function(t){var e=wn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(jn,function(t,r,n,o){e.push(n?o.replace(Sn,"$1"):r||t)}),e}),Rn=nr,xn=Vt,kn=qe,Cn=f?f.prototype:void 0,An=Cn?Cn.toString:void 0;var Nn=function t(e){if("string"==typeof e)return e;if(xn(e))return Rn(e,t)+"";if(kn(e))return An?An.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},En=Nn;var Mn=Vt,Pn=jr,zn=On,Dn=function(t){return null==t?"":En(t)};var Bn=function(t,e){return Mn(t)?t:Pn(t,e)?[t]:zn(Dn(t))},Tn=qe;var Fn=function(t){if("string"==typeof t||Tn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},$n=Bn,In=Fn;var Vn=function(t,e){for(var r=0,n=(e=$n(e,t)).length;null!=t&&r<n;)t=t[In(e[r++])];return r&&r==n?t:void 0},Qn=Vn;var Un,Wn,qn=function(t,e,r){var n=null==t?void 0:Qn(t,e);return void 0===n?r:n},Ln=i(qn);function Gn(t,e,r){return Math.max(r,Math.min(t,e))}function Jn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Hn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Gn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}(Un||(Un={}));class Kn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Jn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{br.error("[ERROR]: pause speech fail"),br.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{br.error("[ERROR]: resume speech fail"),br.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Xn{stream;audioContext;pcmSub;type="vad";workletNode;source;isRecording=!1;constructor(t,e,r){this.stream=t,this.audioContext=e,this.pcmSub=r}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(Wn||(Wn={}));class Yn{_state;stateSub;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get state(){return this._state}set state(t){t!==this._state&&(this._state=t,this.stateSub.next(t))}get stateObs(){return this.stateSub.asObservable()}constructor(){this.stateSub=new t,this.pcmSub=new t,this.destory=new t,this.state=Wn.padding}async init(t){if(this.destory.closed)throw new Error(_e["實例已摧毀"]);const e=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===e)throw this.state=Wn.rejected,new Error(_e["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw br.error(t),this.state=Wn.loadfail,new Error(_e["Worklet模組載入失敗"])}this.state=Wn.allowed,this.audioManager=new Kn(this.audioCtx),this.vadManager=new Xn(e,this.audioCtx,this.pcmSub)}addAudioQueue(t){const e=Ln(t,"buffer",void 0),r=Ln(t,"float32",void 0),n=Ln(t,"int16",void 0),o=Ln(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx?.close(),this.destory.next(),this.destory.complete()}}var Zn=tn;var to=tn,eo=en,ro=gn;var no=tn,oo=function(){this.__data__=new Zn,this.size=0},ao=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},io=function(t){return this.__data__.get(t)},uo=function(t){return this.__data__.has(t)},so=function(t,e){var r=this.__data__;if(r instanceof to){var n=r.__data__;if(!eo||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new ro(n)}return r.set(t,e),this.size=r.size,this};function co(t){var e=this.__data__=new no(t);this.size=e.size}co.prototype.clear=oo,co.prototype.delete=ao,co.prototype.get=io,co.prototype.has=uo,co.prototype.set=so;var lo=co;var fo=gn,ho=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vo=function(t){return this.__data__.has(t)};function po(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new fo;++e<r;)this.add(t[e])}po.prototype.add=po.prototype.push=ho,po.prototype.has=vo;var bo=po,yo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},go=function(t,e){return t.has(e)};var _o=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),l=a.get(e);if(c&&l)return c==e&&l==t;var f=-1,h=!0,d=2&r?new bo:void 0;for(a.set(t,e),a.set(e,t);++f<u;){var v=t[f],p=e[f];if(n)var b=i?n(p,v,f,e,t,a):n(v,p,f,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!yo(e,function(t,e){if(!go(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var mo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var wo=l.Uint8Array,jo=K,So=_o,Oo=mo,Ro=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},xo=f?f.prototype:void 0,ko=xo?xo.valueOf:void 0;var Co=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new wo(t),new wo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return jo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=Oo;case"[object Set]":var s=1&n;if(u||(u=Ro),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var l=So(u(t),u(e),n,o,a,i);return i.delete(t),l;case"[object Symbol]":if(ko)return ko.call(t)==ko.call(e)}return!1};var Ao=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},No=Ao,Eo=Vt;var Mo=function(t,e,r){var n=e(t);return Eo(t)?n:No(n,r(t))};var Po=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},zo=function(){return[]},Do=Object.prototype.propertyIsEnumerable,Bo=Object.getOwnPropertySymbols,To=Mo,Fo=Bo?function(t){return null==t?[]:(t=Object(t),Po(Bo(t),function(e){return Do.call(t,e)}))}:zo,$o=me;var Io=function(t){return To(t,$o,Fo)},Vo=Object.prototype.hasOwnProperty;var Qo=function(t,e,r,n,o,a){var i=1&r,u=Io(t),s=u.length;if(s!=Io(e).length&&!i)return!1;for(var c=s;c--;){var l=u[c];if(!(i?l in e:Vo.call(e,l)))return!1}var f=a.get(t),h=a.get(e);if(f&&h)return f==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[l=u[c]],b=e[l];if(n)var y=i?n(b,p,l,e,t,a):n(p,b,l,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==l)}if(d&&!v){var g=t.constructor,_=e.constructor;g==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof _&&_ instanceof _||(d=!1)}return a.delete(t),a.delete(e),d},Uo=q(l,"DataView"),Wo=en,qo=q(l,"Promise"),Lo=q(l,"Set"),Go=q(l,"WeakMap"),Jo=j,Ho=M,Ko="[object Map]",Xo="[object Promise]",Yo="[object Set]",Zo="[object WeakMap]",ta="[object DataView]",ea=Ho(Uo),ra=Ho(Wo),na=Ho(qo),oa=Ho(Lo),aa=Ho(Go),ia=Jo;(Uo&&ia(new Uo(new ArrayBuffer(1)))!=ta||Wo&&ia(new Wo)!=Ko||qo&&ia(qo.resolve())!=Xo||Lo&&ia(new Lo)!=Yo||Go&&ia(new Go)!=Zo)&&(ia=function(t){var e=Jo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ho(r):"";if(n)switch(n){case ea:return ta;case ra:return Ko;case na:return Xo;case oa:return Yo;case aa:return Zo}return e});var ua=lo,sa=_o,ca=Co,la=Qo,fa=ia,ha=Vt,da=qt,va=ne,pa="[object Arguments]",ba="[object Array]",ya="[object Object]",ga=Object.prototype.hasOwnProperty;var _a=function(t,e,r,n,o,a){var i=ha(t),u=ha(e),s=i?ba:fa(t),c=u?ba:fa(e),l=(s=s==pa?ya:s)==ya,f=(c=c==pa?ya:c)==ya,h=s==c;if(h&&da(t)){if(!da(e))return!1;i=!0,l=!1}if(h&&!l)return a||(a=new ua),i||va(t)?sa(t,e,r,n,o,a):ca(t,e,s,r,n,o,a);if(!(1&r)){var d=l&&ga.call(t,"__wrapped__"),v=f&&ga.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new ua),o(p,b,r,n,a)}}return!!h&&(a||(a=new ua),la(t,e,r,n,o,a))},ma=Mt;var wa=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ma(e)&&!ma(r)?e!=e&&r!=r:_a(e,r,n,o,t,a))},ja=lo,Sa=wa;var Oa=S;var Ra=function(t){return t==t&&!Oa(t)},xa=Ra,ka=me;var Ca=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Aa=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],l=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var f=new ja;if(n)var h=n(c,l,s,t,e,f);if(!(void 0===h?Sa(l,c,3,n,f):h))return!1}}return!0},Na=function(t){for(var e=ka(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xa(o)]}return e},Ea=Ca;var Ma=Bn,Pa=It,za=Vt,Da=wt,Ba=bt,Ta=Fn;var Fa=function(t,e){return null!=t&&e in Object(t)},$a=function(t,e,r){for(var n=-1,o=(e=Ma(e,t)).length,a=!1;++n<o;){var i=Ta(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&Ba(o)&&Da(i,o)&&(za(t)||Pa(t))};var Ia=wa,Va=qn,Qa=function(t,e){return null!=t&&$a(t,e,Fa)},Ua=jr,Wa=Ra,qa=Ca,La=Fn;var Ga=Vn;var Ja=function(t){return function(e){return null==e?void 0:e[t]}},Ha=function(t){return function(e){return Ga(e,t)}},Ka=jr,Xa=Fn;var Ya=function(t){var e=Na(t);return 1==e.length&&e[0][2]?Ea(e[0][0],e[0][1]):function(r){return r===t||Aa(r,t,e)}},Za=function(t,e){return Ua(t)&&Wa(e)?qa(La(t),e):function(r){var n=Va(r,t);return void 0===n&&n===e?Qa(r,t):Ia(e,n,3)}},ti=ot,ei=Vt,ri=function(t){return Ka(t)?Ja(Xa(t)):Ha(t)};var ni=function(t){return"function"==typeof t?t:null==t?ti:"object"==typeof t?ei(t)?Za(t[0],t[1]):Ya(t):ri(t)};var oi=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ai=me;var ii=_t;var ui=function(t,e){return function(r,n){if(null==r)return r;if(!ii(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&oi(t,e,ai)}),si=_t;var ci=nr,li=ni,fi=function(t,e){var r=-1,n=si(t)?Array(t.length):[];return ui(t,function(t,o,a){n[++r]=e(t,o,a)}),n},hi=Vt;var di=i(function(t,e){return(hi(t)?ci:fi)(t,li(e))}),vi=ni,pi=_t,bi=me;var yi=function(t){return function(e,r,n){var o=Object(e);if(!pi(e)){var a=vi(r);e=bi(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},gi=Ee,_i=ni,mi=rr,wi=Math.max;var ji,Si=i(yi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:mi(r);return o<0&&(o=wi(n+o,0)),gi(t,_i(e),o)}));class Oi{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(e){this.destorySub=new t,this.messageSub=new t;const{specific:r,id:n}=e.project;this.socket=o(e.ws_url,Ce({autoConnect:!1},r&&void 0!==n?{query:{uuid:n}}:{}))}start(){const t="list",o="cloud",a="channel";e(this.socket,t).pipe(r(1),n(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),e(this.socket,o).pipe(n(this.destorySub)).subscribe(t=>{this.messageSub.next({event:o,data:t})}),e(this.socket,a).pipe(n(this.destorySub)).subscribe(t=>{this.messageSub.next({event:a,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(ji||(ji={}));class Ri{config;media;chat;destorySub;projectsSub;layoutSub;aiiaSubtitleSub;userSubtitleSub;cloudSampleRate;channelState;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(e,r){this.config=e,this.media=r,this.layoutSub=new t,this.projectsSub=new t,this.destorySub=new t,this.aiiaSubtitleSub=new t,this.userSubtitleSub=new t,this.cloudSampleRate=16e3,this.channelState={proxy:!1,cloud:!1},this.chat=new Oi(e)}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 o=null;if(n&&void 0!==t)o=t;else{const n=Si(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):(this.projectsSub.next(e),br.info("Please subscribe `projects` and call `chooseProject` method"));break}case"channel":"open"===e&&(this.channelState.proxy=!0,this.channelCheck())}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==Ln(e,"signal")?this.behavior(e):Qt(e)?di(e,this.behavior):di(sr(e),this.behavior)}catch(t){br.error("aiia websocket","onmessage error",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate=t.content;else switch(t.command){case"pcm":{const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Jn(new Int16Array(t.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===Ln(t,"content")&&(this.channelState.cloud=!0,this.channelCheck());break;case"agent":{const e=Ln(t,"content.function_result.response");e&&this.aiiaSubtitleSub.next(e);break}case"asr":if("ASR"===Ln(t,"content.function_type")){const e=Ln(t,"content.function_result.result");e&&this.userSubtitleSub.next(e)}break;default:br.info(t.signal)}}channelCheck(){const{proxy:t,cloud:e}=this.channelState;t&&e&&this.media.state===Wn.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}),this.media.pcm.pipe(n(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Hn(t)})}),this.media.startRecord(),br.info("Channel, Cloud and Media are ready.")):t&&e&&this.media.state!==Wn.allowed&&br.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.")}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}function xi(t){if(Ae){const e=new Ne(Ce({},t));yr(e.debug);const r=new Yn,n=new Ri(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(_e["環境錯誤(browser)"])}export{Yn as MediaManager,xi as initSdk};
|
|
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};
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("fs"),e=require("os"),r=require("path"),n=require("rxjs"),o=require("axios"),i=require("socket.io"),a=require("ws"),s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u="object"==typeof s&&s&&s.Object===Object&&s,f=u,l="object"==typeof self&&self&&self.Object===Object&&self,h=f||l||Function("return this")(),v=h.Symbol,p=v,b=Object.prototype,y=b.hasOwnProperty,_=b.toString,d=p?p.toStringTag:void 0;var g=function(t){var e=y.call(t,d),r=t[d];try{t[d]=void 0;var n=!0}catch(t){}var o=_.call(t);return n&&(e?t[d]=r:delete t[d]),o},j=Object.prototype.toString;var O=g,S=function(t){return j.call(t)},w=v?v.toStringTag:void 0;var A=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?O(t):S(t)};var E=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},N=A,m=E;var D,R=function(t){if(!m(t))return!1;var e=N(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},k=h["__core-js_shared__"],M=(D=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||""))?"Symbol(src)_1."+D:"";var I=function(t){return!!M&&M in t},P=Function.prototype.toString;var L=function(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""},C=R,T=I,x=E,U=L,F=/^\[object .+?Constructor\]$/,z=Function.prototype,W=Object.prototype,B=z.toString,G=W.hasOwnProperty,$=RegExp("^"+B.call(G).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var V=function(t){return!(!x(t)||T(t))&&(C(t)?$:F).test(U(t))},X=function(t,e){return null==t?void 0:t[e]};var Y=function(t,e){var r=X(t,e);return V(r)?r:void 0},q=Y,H=function(){try{var t=q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Q=H;var K=function(t,e,r){"__proto__"==e&&Q?Q(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var J=function(t,e){return t===e||t!=t&&e!=e},Z=K,tt=J,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=K;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],c=n?n(r[s],t[s],s,r,t):void 0;void 0===c&&(c=t[s]),o?ot(r,s,c):nt(r,s,c)}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)},ct=Math.max;var ut=function(t,e,r){return e=ct(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=ct(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 ft=function(t){return function(){return t}},lt=H,ht=lt?function(t,e){return lt(t,"toString",{configurable:!0,enumerable:!1,value:ft(e),writable:!0})}:at,vt=Date.now;var pt=function(t){var e=0,r=0;return function(){var n=vt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ht),bt=at,yt=ut,_t=pt;var dt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},gt=R,jt=dt;var Ot=function(t){return null!=t&&jt(t.length)&&!gt(t)},St=/^(?:0|[1-9]\d*)$/;var wt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&St.test(t))&&t>-1&&t%1==0&&t<e},At=J,Et=Ot,Nt=wt,mt=E;var Dt=function(t,e){return _t(yt(t,e,bt),t+"")},Rt=function(t,e,r){if(!mt(r))return!1;var n=typeof e;return!!("number"==n?Et(r)&&Nt(e,r.length):"string"==n&&e in r)&&At(r[e],t)};var kt=function(t){return Dt(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&&Rt(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})},Mt=Object.prototype;var It=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Mt)};var Pt=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},Ct=A,Tt=Lt;var xt=function(t){return Tt(t)&&"[object Arguments]"==Ct(t)},Ut=Lt,Ft=Object.prototype,zt=Ft.hasOwnProperty,Wt=Ft.propertyIsEnumerable,Bt=xt(function(){return arguments}())?xt:function(t){return Ut(t)&&zt.call(t,"callee")&&!Wt.call(t,"callee")},Gt=Array.isArray,$t=c(Gt),Vt={exports:{}};var Xt=function(){return!1};!function(t,e){var r=h,n=Xt,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}(Vt,Vt.exports);var Yt=Vt.exports,qt=A,Ht=dt,Qt=Lt,Kt={};Kt["[object Float32Array]"]=Kt["[object Float64Array]"]=Kt["[object Int8Array]"]=Kt["[object Int16Array]"]=Kt["[object Int32Array]"]=Kt["[object Uint8Array]"]=Kt["[object Uint8ClampedArray]"]=Kt["[object Uint16Array]"]=Kt["[object Uint32Array]"]=!0,Kt["[object Arguments]"]=Kt["[object Array]"]=Kt["[object ArrayBuffer]"]=Kt["[object Boolean]"]=Kt["[object DataView]"]=Kt["[object Date]"]=Kt["[object Error]"]=Kt["[object Function]"]=Kt["[object Map]"]=Kt["[object Number]"]=Kt["[object Object]"]=Kt["[object RegExp]"]=Kt["[object Set]"]=Kt["[object String]"]=Kt["[object WeakMap]"]=!1;var Jt=function(t){return Qt(t)&&Ht(t.length)&&!!Kt[qt(t)]};var Zt=function(t){return function(e){return t(e)}},te={exports:{}};!function(t,e){var r=u,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=Jt,ne=Zt,oe=ee&&ee.isTypedArray,ie=oe?ne(oe):re,ae=Pt,se=Bt,ce=Gt,ue=Yt,fe=wt,le=ie,he=Object.prototype.hasOwnProperty;var ve=function(t,e){var r=ce(t),n=!r&&se(t),o=!r&&!n&&ue(t),i=!r&&!n&&!o&&le(t),a=r||n||o||i,s=a?ae(t.length,String):[],c=s.length;for(var u in t)!e&&!he.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||fe(u,c))||s.push(u);return s};var pe=function(t,e){return function(r){return t(e(r))}},be=pe(Object.keys,Object),ye=It,_e=be,de=Object.prototype.hasOwnProperty;var ge=ve,je=function(t){if(!ye(t))return _e(t);var e=[];for(var r in Object(t))de.call(t,r)&&"constructor"!=r&&e.push(r);return e},Oe=Ot;var Se=function(t){return Oe(t)?ge(t):je(t)},we=rt,Ae=it,Ee=kt,Ne=Ot,me=It,De=Se,Re=Object.prototype.hasOwnProperty,ke=c(Ee(function(t,e){if(me(e)||Ne(e))Ae(e,De(e),t);else for(var r in e)Re.call(e,r)&&we(t,r,e[r])})),Me=A,Ie=Lt;var Pe=function(t){return"symbol"==typeof t||Ie(t)&&"[object Symbol]"==Me(t)},Le=Gt,Ce=Pe,Te=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,xe=/^\w*$/;var Ue=function(t,e){if(Le(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Ce(t))||(xe.test(t)||!Te.test(t)||null!=e&&t in Object(e))},Fe=Y(Object,"create"),ze=Fe;var We=function(){this.__data__=ze?ze(null):{},this.size=0};var Be=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ge=Fe,$e=Object.prototype.hasOwnProperty;var Ve=function(t){var e=this.__data__;if(Ge){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return $e.call(e,t)?e[t]:void 0},Xe=Fe,Ye=Object.prototype.hasOwnProperty;var qe=Fe;var He=We,Qe=Be,Ke=Ve,Je=function(t){var e=this.__data__;return Xe?void 0!==e[t]:Ye.call(e,t)},Ze=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 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=He,tr.prototype.delete=Qe,tr.prototype.get=Ke,tr.prototype.has=Je,tr.prototype.set=Ze;var er=tr;var rr=function(){this.__data__=[],this.size=0},nr=J;var or=function(t,e){for(var r=t.length;r--;)if(nr(t[r][0],e))return r;return-1},ir=or,ar=Array.prototype.splice;var sr=or;var cr=or;var ur=or;var fr=rr,lr=function(t){var e=this.__data__,r=ir(e,t);return!(r<0)&&(r==e.length-1?e.pop():ar.call(e,r,1),--this.size,!0)},hr=function(t){var e=this.__data__,r=sr(e,t);return r<0?void 0:e[r][1]},vr=function(t){return cr(this.__data__,t)>-1},pr=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 br(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])}}br.prototype.clear=fr,br.prototype.delete=lr,br.prototype.get=hr,br.prototype.has=vr,br.prototype.set=pr;var yr=br,_r=Y(h,"Map"),dr=er,gr=yr,jr=_r;var Or=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Sr=function(t,e){var r=t.__data__;return Or(e)?r["string"==typeof e?"string":"hash"]:r.map},wr=Sr;var Ar=Sr;var Er=Sr;var Nr=Sr;var mr=function(){this.size=0,this.__data__={hash:new dr,map:new(jr||gr),string:new dr}},Dr=function(t){var e=wr(this,t).delete(t);return this.size-=e?1:0,e},Rr=function(t){return Ar(this,t).get(t)},kr=function(t){return Er(this,t).has(t)},Mr=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 Ir(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])}}Ir.prototype.clear=mr,Ir.prototype.delete=Dr,Ir.prototype.get=Rr,Ir.prototype.has=kr,Ir.prototype.set=Mr;var Pr=Ir,Lr=Pr;function Cr(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(Cr.Cache||Lr),r}Cr.Cache=Lr;var Tr=Cr;var xr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ur=/\\(\\)?/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(xr,function(t,r,n,o){e.push(n?o.replace(Ur,"$1"):r||t)}),e});var zr=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},Wr=zr,Br=Gt,Gr=Pe,$r=v?v.prototype:void 0,Vr=$r?$r.toString:void 0;var Xr=function t(e){if("string"==typeof e)return e;if(Br(e))return Wr(e,t)+"";if(Gr(e))return Vr?Vr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Yr=Xr;var qr=Gt,Hr=Ue,Qr=Fr,Kr=function(t){return null==t?"":Yr(t)};var Jr=function(t,e){return qr(t)?t:Hr(t,e)?[t]:Qr(Kr(t))},Zr=Pe;var tn=function(t){if("string"==typeof t||Zr(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},en=Jr,rn=tn;var nn=function(t,e){for(var r=0,n=(e=en(e,t)).length;null!=t&&r<n;)t=t[rn(e[r++])];return r&&r==n?t:void 0},on=nn;var an,sn=function(t,e,r){var n=null==t?void 0:on(t,e);return void 0===n?r:n},cn=c(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: 205"}(an||(an={}));const un="access_token",fn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class ln{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}constructor(t){this.config=t}}var hn=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},vn=function(t){return t!=t},pn=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var bn=A,yn=Gt,_n=Lt;var dn=/\s/;var gn=function(t){for(var e=t.length;e--&&dn.test(t.charAt(e)););return e},jn=/^\s+/;var On=function(t){return t?t.slice(0,gn(t)+1).replace(jn,""):t},Sn=E,wn=Pe,An=/^[-+]0x[0-9a-f]+$/i,En=/^0b[01]+$/i,Nn=/^0o[0-7]+$/i,mn=parseInt;var Dn=function(t){if("number"==typeof t)return t;if(wn(t))return NaN;if(Sn(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Sn(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=On(t);var r=En.test(t);return r||Nn.test(t)?mn(t.slice(2),r?2:8):An.test(t)?NaN:+t},Rn=1/0;var kn=function(t){return t?(t=Dn(t))===Rn||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Mn=zr;var In=function(t,e){return Mn(e,function(e){return t[e]})},Pn=Se;var Ln=function(t,e,r){return e==e?pn(t,e,r):hn(t,vn,r)},Cn=Ot,Tn=function(t){return"string"==typeof t||!yn(t)&&_n(t)&&"[object String]"==bn(t)},xn=function(t){var e=kn(t),r=e%1;return e==e?r?e-r:e:0},Un=function(t){return null==t?[]:In(t,Pn(t))},Fn=Math.max;var zn=c(function(t,e,r,n){t=Cn(t)?t:Un(t),r=r&&!n?xn(r):0;var o=t.length;return r<0&&(r=Fn(o+r,0)),Tn(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&Ln(t,e,r)>-1});const Wn={info:()=>{},error:()=>{},warn:()=>{}};function Bn(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:zn(t,"error"),warn:zn(t,"warn"),info:zn(t,"info")}}(t);e&&(Wn.info=console.log),r&&(Wn.error=console.error),n&&(Wn.warn=console.warn)}var Gn=yr;var $n=yr,Vn=_r,Xn=Pr;var Yn=yr,qn=function(){this.__data__=new Gn,this.size=0},Hn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Qn=function(t){return this.__data__.get(t)},Kn=function(t){return this.__data__.has(t)},Jn=function(t,e){var r=this.__data__;if(r instanceof $n){var n=r.__data__;if(!Vn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Xn(n)}return r.set(t,e),this.size=r.size,this};function Zn(t){var e=this.__data__=new Yn(t);this.size=e.size}Zn.prototype.clear=qn,Zn.prototype.delete=Hn,Zn.prototype.get=Qn,Zn.prototype.has=Kn,Zn.prototype.set=Jn;var to=Zn;var eo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t},ro=it,no=Se;var oo=function(t,e){return t&&ro(e,no(e),t)};var io=E,ao=It,so=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},co=Object.prototype.hasOwnProperty;var uo=ve,fo=function(t){if(!io(t))return so(t);var e=ao(t),r=[];for(var n in t)("constructor"!=n||!e&&co.call(t,n))&&r.push(n);return r},lo=Ot;var ho=function(t){return lo(t)?uo(t,!0):fo(t)},vo=it,po=ho;var bo=function(t,e){return t&&vo(e,po(e),t)},yo={exports:{}};!function(t,e){var r=h,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}}(yo,yo.exports);var _o=yo.exports;var go=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e};var jo=function(){return[]},Oo=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},So=jo,wo=Object.prototype.propertyIsEnumerable,Ao=Object.getOwnPropertySymbols,Eo=Ao?function(t){return null==t?[]:(t=Object(t),Oo(Ao(t),function(e){return wo.call(t,e)}))}:So,No=it,mo=Eo;var Do=function(t,e){return No(t,mo(t),e)};var Ro=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},ko=pe(Object.getPrototypeOf,Object),Mo=Ro,Io=ko,Po=Eo,Lo=jo,Co=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Mo(e,Po(t)),t=Io(t);return e}:Lo,To=it,xo=Co;var Uo=function(t,e){return To(t,xo(t),e)},Fo=Ro,zo=Gt;var Wo=function(t,e,r){var n=e(t);return zo(t)?n:Fo(n,r(t))},Bo=Wo,Go=Eo,$o=Se;var Vo=function(t){return Bo(t,$o,Go)},Xo=Wo,Yo=Co,qo=ho;var Ho=function(t){return Xo(t,qo,Yo)},Qo=Y(h,"DataView"),Ko=_r,Jo=Y(h,"Promise"),Zo=Y(h,"Set"),ti=Y(h,"WeakMap"),ei=A,ri=L,ni="[object Map]",oi="[object Promise]",ii="[object Set]",ai="[object WeakMap]",si="[object DataView]",ci=ri(Qo),ui=ri(Ko),fi=ri(Jo),li=ri(Zo),hi=ri(ti),vi=ei;(Qo&&vi(new Qo(new ArrayBuffer(1)))!=si||Ko&&vi(new Ko)!=ni||Jo&&vi(Jo.resolve())!=oi||Zo&&vi(new Zo)!=ii||ti&&vi(new ti)!=ai)&&(vi=function(t){var e=ei(t),r="[object Object]"==e?t.constructor:void 0,n=r?ri(r):"";if(n)switch(n){case ci:return si;case ui:return ni;case fi:return oi;case li:return ii;case hi:return ai}return e});var pi=vi,bi=Object.prototype.hasOwnProperty;var yi=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&bi.call(t,"index")&&(r.index=t.index,r.input=t.input),r},_i=h.Uint8Array,di=_i;var gi=function(t){var e=new t.constructor(t.byteLength);return new di(e).set(new di(t)),e},ji=gi;var Oi=function(t,e){var r=e?ji(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},Si=/\w*$/;var wi=function(t){var e=new t.constructor(t.source,Si.exec(t));return e.lastIndex=t.lastIndex,e},Ai=v?v.prototype:void 0,Ei=Ai?Ai.valueOf:void 0;var Ni=gi;var mi=gi,Di=Oi,Ri=wi,ki=function(t){return Ei?Object(Ei.call(t)):{}},Mi=function(t,e){var r=e?Ni(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var Ii=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return mi(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return Di(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 Mi(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 Ri(t);case"[object Symbol]":return ki(t)}},Pi=E,Li=Object.create,Ci=function(){function t(){}return function(e){if(!Pi(e))return{};if(Li)return Li(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Ti=ko,xi=It;var Ui=function(t){return"function"!=typeof t.constructor||xi(t)?{}:Ci(Ti(t))},Fi=pi,zi=Lt;var Wi=function(t){return zi(t)&&"[object Map]"==Fi(t)},Bi=Zt,Gi=ee&&ee.isMap,$i=Gi?Bi(Gi):Wi,Vi=pi,Xi=Lt;var Yi=function(t){return Xi(t)&&"[object Set]"==Vi(t)},qi=Zt,Hi=ee&&ee.isSet,Qi=Hi?qi(Hi):Yi,Ki=to,Ji=eo,Zi=rt,ta=oo,ea=bo,ra=_o,na=go,oa=Do,ia=Uo,aa=Vo,sa=Ho,ca=pi,ua=yi,fa=Ii,la=Ui,ha=Gt,va=Yt,pa=$i,ba=E,ya=Qi,_a=Se,da=ho,ga="[object Arguments]",ja="[object Function]",Oa="[object Object]",Sa={};Sa[ga]=Sa["[object Array]"]=Sa["[object ArrayBuffer]"]=Sa["[object DataView]"]=Sa["[object Boolean]"]=Sa["[object Date]"]=Sa["[object Float32Array]"]=Sa["[object Float64Array]"]=Sa["[object Int8Array]"]=Sa["[object Int16Array]"]=Sa["[object Int32Array]"]=Sa["[object Map]"]=Sa["[object Number]"]=Sa[Oa]=Sa["[object RegExp]"]=Sa["[object Set]"]=Sa["[object String]"]=Sa["[object Symbol]"]=Sa["[object Uint8Array]"]=Sa["[object Uint8ClampedArray]"]=Sa["[object Uint16Array]"]=Sa["[object Uint32Array]"]=!0,Sa["[object Error]"]=Sa[ja]=Sa["[object WeakMap]"]=!1;var wa=function t(e,r,n,o,i,a){var s,c=1&r,u=2&r,f=4&r;if(n&&(s=i?n(e,o,i,a):n(e)),void 0!==s)return s;if(!ba(e))return e;var l=ha(e);if(l){if(s=ua(e),!c)return na(e,s)}else{var h=ca(e),v=h==ja||"[object GeneratorFunction]"==h;if(va(e))return ra(e,c);if(h==Oa||h==ga||v&&!i){if(s=u||v?{}:la(e),!c)return u?ia(e,ea(s,e)):oa(e,ta(s,e))}else{if(!Sa[h])return i?e:{};s=fa(e,h,c)}}a||(a=new Ki);var p=a.get(e);if(p)return p;a.set(e,s),ya(e)?e.forEach(function(o){s.add(t(o,r,n,o,e,a))}):pa(e)&&e.forEach(function(o,i){s.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?sa:aa:u?da:_a)(e);return Ji(b||e,function(o,i){b&&(o=e[i=o]),Zi(s,i,t(o,r,n,i,e,a))}),s};var Aa=nn,Ea=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 Na=function(t,e){return e.length<2?t:Aa(t,Ea(e,0,-1))},ma=Jr,Da=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},Ra=Na,ka=tn;var Ma=function(t,e){return e=ma(e,t),null==(t=Ra(t,e))||delete t[ka(Da(e))]},Ia=A,Pa=ko,La=Lt,Ca=Function.prototype,Ta=Object.prototype,xa=Ca.toString,Ua=Ta.hasOwnProperty,Fa=xa.call(Object);var za=function(t){if(!La(t)||"[object Object]"!=Ia(t))return!1;var e=Pa(t);if(null===e)return!0;var r=Ua.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&xa.call(r)==Fa};var Wa=function(t){return za(t)?void 0:t},Ba=Bt,Ga=Gt,$a=v?v.isConcatSpreadable:void 0;var Va=Ro,Xa=function(t){return Ga(t)||Ba(t)||!!($a&&t&&t[$a])};var Ya=function t(e,r,n,o,i){var a=-1,s=e.length;for(n||(n=Xa),i||(i=[]);++a<s;){var c=e[a];r>0&&n(c)?r>1?t(c,r-1,n,o,i):Va(i,c):o||(i[i.length]=c)}return i},qa=Ya;var Ha=function(t){return(null==t?0:t.length)?qa(t,1):[]},Qa=ut,Ka=pt;var Ja=zr,Za=wa,ts=Ma,es=Jr,rs=it,ns=Wa,os=Ho,is=function(t){return Ka(Qa(t,void 0,Ha),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=Ja(e,function(e){return e=es(e,t),n||(n=e.length>1),e}),rs(t,os(t),r),n&&(r=Za(r,7,ns));for(var o=e.length;o--;)ts(r,e[o]);return r}),as=c(is);const ss=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=e.homedir(),this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=r.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||r.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||r.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=r.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return r.join(...t)}folderCheck(e){t.mkdirSync(e,{recursive:!0})}fileCheck(e){t.existsSync(e)||t.writeFileSync(e,"",{encoding:"utf8"})}}("aiia-sdk");class cs{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=ss.addPath(ss.appFolder,this.fileName),ss.fileCheck(this.filePath)}getFileDataSync(){const e=t.readFileSync(this.filePath,"utf8");try{return JSON.parse(e)}catch(t){return{}}}setFileDataSync(e){try{const r=JSON.stringify(e);t.writeFileSync(this.filePath,r,"utf8")}catch(t){}}async getFileData(){return new Promise(e=>{t.readFile(this.filePath,"utf8",(t,r)=>{if(t)e({});else try{e(JSON.parse(r))}catch(t){e({})}})})}async setFileData(e){return new Promise(r=>{try{const n=JSON.stringify(e);t.writeFile(this.filePath,n,"utf8",t=>{r()})}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({})}}var us=Pr,fs=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ls=function(t){return this.__data__.has(t)};function hs(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new us;++e<r;)this.add(t[e])}hs.prototype.add=hs.prototype.push=fs,hs.prototype.has=ls;var vs=hs,ps=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},bs=function(t,e){return t.has(e)};var ys=function(t,e,r,n,o,i){var a=1&r,s=t.length,c=e.length;if(s!=c&&!(a&&c>s))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 vs:void 0;for(i.set(t,e),i.set(e,t);++l<s;){var p=t[l],b=e[l];if(n)var y=a?n(b,p,l,e,t,i):n(p,b,l,t,e,i);if(void 0!==y){if(y)continue;h=!1;break}if(v){if(!ps(e,function(t,e){if(!bs(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};var _s=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var ds=_i,gs=J,js=ys,Os=_s,Ss=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},ws=v?v.prototype:void 0,As=ws?ws.valueOf:void 0;var Es=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 ds(t),new ds(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return gs(+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=Os;case"[object Set]":var c=1&n;if(s||(s=Ss),t.size!=e.size&&!c)return!1;var u=a.get(t);if(u)return u==e;n|=2,a.set(t,e);var f=js(s(t),s(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(As)return As.call(t)==As.call(e)}return!1},Ns=Vo,ms=Object.prototype.hasOwnProperty;var Ds=to,Rs=ys,ks=Es,Ms=function(t,e,r,n,o,i){var a=1&r,s=Ns(t),c=s.length;if(c!=Ns(e).length&&!a)return!1;for(var u=c;u--;){var f=s[u];if(!(a?f in e:ms.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<c;){var b=t[f=s[u]],y=e[f];if(n)var _=a?n(y,b,f,e,t,i):n(b,y,f,t,e,i);if(!(void 0===_?b===y||o(b,y,r,n,i):_)){v=!1;break}p||(p="constructor"==f)}if(v&&!p){var d=t.constructor,g=e.constructor;d==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof d&&d instanceof d&&"function"==typeof g&&g instanceof g||(v=!1)}return i.delete(t),i.delete(e),v},Is=pi,Ps=Gt,Ls=Yt,Cs=ie,Ts="[object Arguments]",xs="[object Array]",Us="[object Object]",Fs=Object.prototype.hasOwnProperty;var zs=function(t,e,r,n,o,i){var a=Ps(t),s=Ps(e),c=a?xs:Is(t),u=s?xs:Is(e),f=(c=c==Ts?Us:c)==Us,l=(u=u==Ts?Us:u)==Us,h=c==u;if(h&&Ls(t)){if(!Ls(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Ds),a||Cs(t)?Rs(t,e,r,n,o,i):ks(t,e,c,r,n,o,i);if(!(1&r)){var v=f&&Fs.call(t,"__wrapped__"),p=l&&Fs.call(e,"__wrapped__");if(v||p){var b=v?t.value():t,y=p?e.value():e;return i||(i=new Ds),o(b,y,r,n,i)}}return!!h&&(i||(i=new Ds),Ms(t,e,r,n,o,i))},Ws=Lt;var Bs=function t(e,r,n,o,i){return e===r||(null==e||null==r||!Ws(e)&&!Ws(r)?e!=e&&r!=r:zs(e,r,n,o,t,i))},Gs=to,$s=Bs;var Vs=E;var Xs=function(t){return t==t&&!Vs(t)},Ys=Xs,qs=Se;var Hs=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Qs=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 c=(s=r[o])[0],u=t[c],f=s[1];if(a&&s[2]){if(void 0===u&&!(c in t))return!1}else{var l=new Gs;if(n)var h=n(u,f,c,t,e,l);if(!(void 0===h?$s(f,u,3,n,l):h))return!1}}return!0},Ks=function(t){for(var e=qs(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Ys(o)]}return e},Js=Hs;var Zs=Jr,tc=Bt,ec=Gt,rc=wt,nc=dt,oc=tn;var ic=function(t,e,r){for(var n=-1,o=(e=Zs(e,t)).length,i=!1;++n<o;){var a=oc(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&nc(o)&&rc(a,o)&&(ec(t)||tc(t))},ac=function(t,e){return null!=t&&e in Object(t)},sc=ic;var cc=function(t,e){return null!=t&&sc(t,e,ac)},uc=Bs,fc=sn,lc=cc,hc=Ue,vc=Xs,pc=Hs,bc=tn;var yc=function(t,e){return hc(t)&&vc(e)?pc(bc(t),e):function(r){var n=fc(r,t);return void 0===n&&n===e?lc(r,t):uc(e,n,3)}};var _c=nn;var dc=function(t){return function(e){return _c(e,t)}},gc=function(t){return function(e){return null==e?void 0:e[t]}},jc=dc,Oc=Ue,Sc=tn;var wc=function(t){return Oc(t)?gc(Sc(t)):jc(t)},Ac=function(t){var e=Ks(t);return 1==e.length&&e[0][2]?Js(e[0][0],e[0][1]):function(r){return r===t||Qs(r,t,e)}},Ec=yc,Nc=at,mc=Gt,Dc=wc;var Rc=function(t){return"function"==typeof t?t:null==t?Nc:"object"==typeof t?mc(t)?Ec(t[0],t[1]):Ac(t):Dc(t)};var kc=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),s=a.length;s--;){var c=a[t?s:++o];if(!1===r(i[c],c,i))break}return e}}(),Mc=Se;var Ic=Ot;var Pc=function(t,e){return function(r,n){if(null==r)return r;if(!Ic(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&&kc(t,e,Mc)}),Lc=Ot;var Cc=zr,Tc=Rc,xc=function(t,e){var r=-1,n=Lc(t)?Array(t.length):[];return Pc(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Uc=Gt;var Fc,zc=c(function(t,e){return(Uc(t)?Cc:xc)(t,Tc(e))});class Wc{instance;controller;constructor(t){this.controller=new AbortController,this.instance=o.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=>cn(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(an["網絡錯誤"]);if(""===n)throw new Error(an["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>zc(cn(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(an["網絡錯誤"]);if(0===e.length)throw new Error(an["沒有可用專案"]);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"}(Fc||(Fc={}));class Bc{socket;messageSub;startLinkSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get startLink(){return this.startLinkSub.asObservable()}messageQueue=[];isConnected;isStart;constructor(){this.isConnected=!1,this.isStart=!1,this.messageSub=new n.Subject,this.startLinkSub=new n.Subject,this.closeSub=new n.Subject,this.destorySub=new n.Subject}start(t){this.isStart=!0,this.socket=new a(t),Wn.info("Proxy to",t),n.fromEvent(this.socket,"open").pipe(n.takeUntil(this.destorySub)).subscribe(t=>{this.isConnected=!0,this.startLinkSub.next(),Wn.info("Proxy startup"),this.flushMessageQueue()}),n.fromEvent(this.socket,"message").pipe(n.takeUntil(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),n.fromEvent(this.socket,"error").pipe(n.takeUntil(this.destorySub)).subscribe(t=>{const{error:e}=t;Wn.error("Proxy has some problem",e)}),n.fromEvent(this.socket,"close").pipe(n.takeUntil(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e}=t;switch(Wn.error("Proxy closed",{code:e}),e){case Fc.MANUAL_CLOSE:Wn.info("MANUAL_CLOSE stop emit event and reconnecting");break;case Fc.WS_5000_NORAML_CLOSURE:case Fc.MDN_NORMAL_CLOSURE:case Fc.MDN_GOING_AWAY:this.closeSub.next("close"),Wn.info("Safe close connection");break;case Fc.MDN_NO_STATUS_RECEIVED:case Fc.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),Wn.error("Cloud disconnect");break;case Fc.WS_5001_UNAUTHORIZED:case Fc.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),Wn.error("Please contact Graphen");break;case Fc.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect");break;default:this.closeSub.next("close"),Wn.warn("Other status always close connection")}})}flushMessageQueue(){for(;this.messageQueue.length>0&&this.isConnected;){const t=this.messageQueue.shift();t&&this.socket.send(t)}}send(t){this.isConnected?this.socket.send(t):this.messageQueue.push(t)}onManualClose(){this.isStart&&this.socket?.close(Fc.MANUAL_CLOSE)}onDestory(){this.destorySub.next(),this.destorySub.complete()}}class Gc{sdk;server;get url(){return this.sdk.config.endPoint.socket}get port(){return this.sdk.config.port}get webserver(){return this.sdk.config.webserver}constructor(t){this.sdk=t}start(){this.server=new i.Server(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{const e=new n.Subject;let r=(o=t.handshake.query.uuid,$t(o)?cn(o,"[0]",void 0):o??void 0);var o;const i=new Bc;void 0===r?(this.sdk.getProjectList().then(e=>{t.emit("list",e)}),n.fromEvent(t,"uuid").pipe(n.take(1),n.takeUntil(e)).subscribe(n=>{r=n,this.openChannel(r,t,i,e)})):this.openChannel(r,t,i,e),t.on("disconnect",t=>{e.next(),e.complete(),Wn.info(t)})}),void 0===this.webserver&&this.server.listen(this.port)}openChannel(t,e,r,o){n.fromEvent(e,"cloud").pipe(n.takeUntil(o)).subscribe(t=>{r.send(t)}),r.message.pipe(n.takeUntil(o)).subscribe(t=>{e.emit("cloud",t)}),r.close.pipe(n.takeUntil(o)).subscribe(async n=>{switch(n){case"close":case"no_permissions":e.emit("channel",n),r.onDestory();break;case"reconnect":await this.sdk.replaceAccessToken(),r.start(this.getProxySocketURL(t))}}),r.startLink.pipe(n.takeUntil(o)).subscribe(()=>{e.emit("channel","open")}),r.start(this.getProxySocketURL(t))}getProxySocketURL(t){return`${this.url}/v1/chat/project/${this.sdk.accessToken}/${t}`}onDestory(){this.server&&this.server.close()}}class $c{config;stroage;apiProxy;chat;isStart;destorySub;get destoryObs(){return this.destorySub.asObservable()}access_token;get accessToken(){return this.access_token}constructor(t,e){this.config=t,this.stroage=e,this.isStart=!1,this.destorySub=new n.Subject,this.access_token=e.getItemSync(un),this.apiProxy=new Wc(this.config.endPoint.api),Wn.info("[Initialize] proxy is finished"),this.chat=new Gc(this),Wn.info("[Initialize] chat is finished","Start at PORT:",this.config.port)}async start(){if(this.isStart)throw new Error(an["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.start(),Wn.info("Chat service startup")}async replaceAccessToken(){const t=await this.apiProxy.getAccessToken(this.config.license,this.access_token);return this.access_token=t,this.stroage.setItemSync(un,t),t}async getProjectList(){return await this.apiProxy.getProjectList(this.config.license)}onDestory(){this.apiProxy.onDestory(),this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete(),Wn.info("[Destory] core module done")}}exports.aiiaCore=function(t){if(fn){if(void 0===cn(t,"license",void 0))throw new Error(an["未提供憑證"]);Wn.info("Initialize necessary modules");const e=new ln(ke({},t));Bn(e.debug),Wn.info("[Initialize] config finished");const r=new cs;Wn.info("[Initialize] storage finished");const n=new $c(e,r);return Wn.info("[Initialize] core finished"),n.start(),Wn.info("Service startup"),()=>{n.onDestory()}}throw new Error(an["環境錯誤(nodejs)"])};
|
|
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)"])};
|
package/dist/node.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ declare interface InitOptions {
|
|
|
47
47
|
* [en]
|
|
48
48
|
* Extending "socket.io" to your web server
|
|
49
49
|
*/
|
|
50
|
-
webserver?:
|
|
50
|
+
webserver?: Webserver;
|
|
51
51
|
/**
|
|
52
52
|
* [zh]
|
|
53
53
|
* 伺服器 port
|
|
@@ -81,9 +81,30 @@ declare interface InitOptions {
|
|
|
81
81
|
* [en]
|
|
82
82
|
* Switch message(info, error, warn) dispaly, default: true
|
|
83
83
|
*/
|
|
84
|
-
debug?: boolean | "all" | "none" |
|
|
84
|
+
debug?: boolean | "all" | "none" | LoggerLevel[];
|
|
85
|
+
mediaStream?: MediaStream;
|
|
86
|
+
/**
|
|
87
|
+
* [zh]
|
|
88
|
+
* 檢測聲音的區塊大小(秒),預設 1 秒
|
|
89
|
+
*
|
|
90
|
+
* [en]
|
|
91
|
+
* Detecting the chunk size of the sound(unit is second), default 1 second.
|
|
92
|
+
*/
|
|
93
|
+
chunkTimeInSeconds?: number;
|
|
94
|
+
/**
|
|
95
|
+
* [zh]
|
|
96
|
+
* 指定音訊輸出的採樣率(提供給LLM分析)。不推薦更動
|
|
97
|
+
*
|
|
98
|
+
* [en]
|
|
99
|
+
* Specify the sampling rate of audio output (provided for LLM analysis). Changing is not recommended.
|
|
100
|
+
*/
|
|
101
|
+
llmSampleRate?: number;
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
|
|
104
|
+
declare type LoggerLevel = "info" | "error" | "warn" | "debug" | "fatal" | "code";
|
|
105
|
+
|
|
106
|
+
export declare type NodeInitOptions = Omit<InitOptions, "project" | "ws_url" | "worklet_url" | "mediaStream" | "chunkTimeInSeconds" | "llmSampleRate">;
|
|
107
|
+
|
|
108
|
+
declare type Webserver = Server<any, any> | Server_2<any, any> | Http2SecureServer<any, any, any, any> | Http2Server<any, any, any, any>;
|
|
88
109
|
|
|
89
110
|
export { }
|
package/dist/node.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"fs";import e from"os";import r from"path";import{Subject as n,fromEvent as o,takeUntil as i,take as a}from"rxjs";import s from"axios";import{Server as c}from"socket.io";import u from"ws";var f="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h="object"==typeof f&&f&&f.Object===Object&&f,v=h,p="object"==typeof self&&self&&self.Object===Object&&self,b=v||p||Function("return this")(),y=b.Symbol,_=y,d=Object.prototype,g=d.hasOwnProperty,O=d.toString,j=_?_.toStringTag:void 0;var w=function(t){var e=g.call(t,j),r=t[j];try{t[j]=void 0;var n=!0}catch(t){}var o=O.call(t);return n&&(e?t[j]=r:delete t[j]),o},S=Object.prototype.toString;var A=w,E=function(t){return S.call(t)},m=y?y.toStringTag:void 0;var N=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m in Object(t)?A(t):E(t)};var D=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},R=N,M=D;var I,k=function(t){if(!M(t))return!1;var e=R(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},P=b["__core-js_shared__"],L=(I=/[^.]+$/.exec(P&&P.keys&&P.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"";var C=function(t){return!!L&&L in t},T=Function.prototype.toString;var x=function(t){if(null!=t){try{return T.call(t)}catch(t){}try{return t+""}catch(t){}}return""},U=k,F=C,z=D,W=x,B=/^\[object .+?Constructor\]$/,G=Function.prototype,$=Object.prototype,V=G.toString,X=$.hasOwnProperty,Y=RegExp("^"+V.call(X).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var H=function(t){return!(!z(t)||F(t))&&(U(t)?Y:B).test(W(t))},Q=function(t,e){return null==t?void 0:t[e]};var K=function(t,e){var r=Q(t,e);return H(r)?r:void 0},J=K,q=function(){try{var t=J(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Z=q;var tt=function(t,e,r){"__proto__"==e&&Z?Z(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var et=function(t,e){return t===e||t!=t&&e!=e},rt=tt,nt=et,ot=Object.prototype.hasOwnProperty;var it=function(t,e,r){var n=t[e];ot.call(t,e)&&nt(n,r)&&(void 0!==r||e in t)||rt(t,e,r)},at=it,st=tt;var ct=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var s=e[i],c=n?n(r[s],t[s],s,r,t):void 0;void 0===c&&(c=t[s]),o?st(r,s,c):at(r,s,c)}return r};var ut=function(t){return t};var ft=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)},lt=Math.max;var ht=function(t,e,r){return e=lt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=lt(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),ft(t,this,s)}};var vt=function(t){return function(){return t}},pt=q,bt=pt?function(t,e){return pt(t,"toString",{configurable:!0,enumerable:!1,value:vt(e),writable:!0})}:ut,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)}}(bt),dt=ut,gt=ht,Ot=_t;var jt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},wt=k,St=jt;var At=function(t){return null!=t&&St(t.length)&&!wt(t)},Et=/^(?:0|[1-9]\d*)$/;var mt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Et.test(t))&&t>-1&&t%1==0&&t<e},Nt=et,Dt=At,Rt=mt,Mt=D;var It=function(t,e){return Ot(gt(t,e,dt),t+"")},kt=function(t,e,r){if(!Mt(r))return!1;var n=typeof e;return!!("number"==n?Dt(r)&&Rt(e,r.length):"string"==n&&e in r)&&Nt(r[e],t)};var Pt=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&&kt(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})},Lt=Object.prototype;var Ct=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Lt)};var Tt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var xt=function(t){return null!=t&&"object"==typeof t},Ut=N,Ft=xt;var zt=function(t){return Ft(t)&&"[object Arguments]"==Ut(t)},Wt=xt,Bt=Object.prototype,Gt=Bt.hasOwnProperty,$t=Bt.propertyIsEnumerable,Vt=zt(function(){return arguments}())?zt:function(t){return Wt(t)&&Gt.call(t,"callee")&&!$t.call(t,"callee")},Xt=Array.isArray,Yt=l(Xt),Ht={exports:{}};var Qt=function(){return!1};!function(t,e){var r=b,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}(Ht,Ht.exports);var Kt=Ht.exports,Jt=N,qt=jt,Zt=xt,te={};te["[object Float32Array]"]=te["[object Float64Array]"]=te["[object Int8Array]"]=te["[object Int16Array]"]=te["[object Int32Array]"]=te["[object Uint8Array]"]=te["[object Uint8ClampedArray]"]=te["[object Uint16Array]"]=te["[object Uint32Array]"]=!0,te["[object Arguments]"]=te["[object Array]"]=te["[object ArrayBuffer]"]=te["[object Boolean]"]=te["[object DataView]"]=te["[object Date]"]=te["[object Error]"]=te["[object Function]"]=te["[object Map]"]=te["[object Number]"]=te["[object Object]"]=te["[object RegExp]"]=te["[object Set]"]=te["[object String]"]=te["[object WeakMap]"]=!1;var ee=function(t){return Zt(t)&&qt(t.length)&&!!te[Jt(t)]};var re=function(t){return function(e){return t(e)}},ne={exports:{}};!function(t,e){var r=h,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}(ne,ne.exports);var oe=ne.exports,ie=ee,ae=re,se=oe&&oe.isTypedArray,ce=se?ae(se):ie,ue=Tt,fe=Vt,le=Xt,he=Kt,ve=mt,pe=ce,be=Object.prototype.hasOwnProperty;var ye=function(t,e){var r=le(t),n=!r&&fe(t),o=!r&&!n&&he(t),i=!r&&!n&&!o&&pe(t),a=r||n||o||i,s=a?ue(t.length,String):[],c=s.length;for(var u in t)!e&&!be.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||ve(u,c))||s.push(u);return s};var _e=function(t,e){return function(r){return t(e(r))}},de=_e(Object.keys,Object),ge=Ct,Oe=de,je=Object.prototype.hasOwnProperty;var we=ye,Se=function(t){if(!ge(t))return Oe(t);var e=[];for(var r in Object(t))je.call(t,r)&&"constructor"!=r&&e.push(r);return e},Ae=At;var Ee=function(t){return Ae(t)?we(t):Se(t)},me=it,Ne=ct,De=Pt,Re=At,Me=Ct,Ie=Ee,ke=Object.prototype.hasOwnProperty,Pe=l(De(function(t,e){if(Me(e)||Re(e))Ne(e,Ie(e),t);else for(var r in e)ke.call(e,r)&&me(t,r,e[r])})),Le=N,Ce=xt;var Te=function(t){return"symbol"==typeof t||Ce(t)&&"[object Symbol]"==Le(t)},xe=Xt,Ue=Te,Fe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ze=/^\w*$/;var We=function(t,e){if(xe(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Ue(t))||(ze.test(t)||!Fe.test(t)||null!=e&&t in Object(e))},Be=K(Object,"create"),Ge=Be;var $e=function(){this.__data__=Ge?Ge(null):{},this.size=0};var Ve=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Xe=Be,Ye=Object.prototype.hasOwnProperty;var He=function(t){var e=this.__data__;if(Xe){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Ye.call(e,t)?e[t]:void 0},Qe=Be,Ke=Object.prototype.hasOwnProperty;var Je=Be;var qe=$e,Ze=Ve,tr=He,er=function(t){var e=this.__data__;return Qe?void 0!==e[t]:Ke.call(e,t)},rr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Je&&void 0===e?"__lodash_hash_undefined__":e,this};function nr(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])}}nr.prototype.clear=qe,nr.prototype.delete=Ze,nr.prototype.get=tr,nr.prototype.has=er,nr.prototype.set=rr;var or=nr;var ir=function(){this.__data__=[],this.size=0},ar=et;var sr=function(t,e){for(var r=t.length;r--;)if(ar(t[r][0],e))return r;return-1},cr=sr,ur=Array.prototype.splice;var fr=sr;var lr=sr;var hr=sr;var vr=ir,pr=function(t){var e=this.__data__,r=cr(e,t);return!(r<0)&&(r==e.length-1?e.pop():ur.call(e,r,1),--this.size,!0)},br=function(t){var e=this.__data__,r=fr(e,t);return r<0?void 0:e[r][1]},yr=function(t){return lr(this.__data__,t)>-1},_r=function(t,e){var r=this.__data__,n=hr(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=vr,dr.prototype.delete=pr,dr.prototype.get=br,dr.prototype.has=yr,dr.prototype.set=_r;var gr=dr,Or=K(b,"Map"),jr=or,wr=gr,Sr=Or;var Ar=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Er=function(t,e){var r=t.__data__;return Ar(e)?r["string"==typeof e?"string":"hash"]:r.map},mr=Er;var Nr=Er;var Dr=Er;var Rr=Er;var Mr=function(){this.size=0,this.__data__={hash:new jr,map:new(Sr||wr),string:new jr}},Ir=function(t){var e=mr(this,t).delete(t);return this.size-=e?1:0,e},kr=function(t){return Nr(this,t).get(t)},Pr=function(t){return Dr(this,t).has(t)},Lr=function(t,e){var r=Rr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,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=Mr,Cr.prototype.delete=Ir,Cr.prototype.get=kr,Cr.prototype.has=Pr,Cr.prototype.set=Lr;var Tr=Cr,xr=Tr;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||xr),r}Ur.Cache=xr;var Fr=Ur;var zr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Wr=/\\(\\)?/g,Br=function(t){var e=Fr(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(Wr,"$1"):r||t)}),e});var Gr=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=Gr,Vr=Xt,Xr=Te,Yr=y?y.prototype:void 0,Hr=Yr?Yr.toString:void 0;var Qr=function t(e){if("string"==typeof e)return e;if(Vr(e))return $r(e,t)+"";if(Xr(e))return Hr?Hr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Kr=Qr;var Jr=Xt,qr=We,Zr=Br,tn=function(t){return null==t?"":Kr(t)};var en=function(t,e){return Jr(t)?t:qr(t,e)?[t]:Zr(tn(t))},rn=Te;var nn=function(t){if("string"==typeof t||rn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},on=en,an=nn;var sn=function(t,e){for(var r=0,n=(e=on(e,t)).length;null!=t&&r<n;)t=t[an(e[r++])];return r&&r==n?t:void 0},cn=sn;var un,fn=function(t,e,r){var n=null==t?void 0:cn(t,e);return void 0===n?r:n},ln=l(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: 205"}(un||(un={}));const hn="access_token",vn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class pn{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}=Pe({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Pe({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var bn=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},yn=function(t){return t!=t},_n=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var dn=N,gn=Xt,On=xt;var jn=/\s/;var wn=function(t){for(var e=t.length;e--&&jn.test(t.charAt(e)););return e},Sn=/^\s+/;var An=function(t){return t?t.slice(0,wn(t)+1).replace(Sn,""):t},En=D,mn=Te,Nn=/^[-+]0x[0-9a-f]+$/i,Dn=/^0b[01]+$/i,Rn=/^0o[0-7]+$/i,Mn=parseInt;var In=function(t){if("number"==typeof t)return t;if(mn(t))return NaN;if(En(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=En(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=An(t);var r=Dn.test(t);return r||Rn.test(t)?Mn(t.slice(2),r?2:8):Nn.test(t)?NaN:+t},kn=1/0;var Pn=function(t){return t?(t=In(t))===kn||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ln=Gr;var Cn=function(t,e){return Ln(e,function(e){return t[e]})},Tn=Ee;var xn=function(t,e,r){return e==e?_n(t,e,r):bn(t,yn,r)},Un=At,Fn=function(t){return"string"==typeof t||!gn(t)&&On(t)&&"[object String]"==dn(t)},zn=function(t){var e=Pn(t),r=e%1;return e==e?r?e-r:e:0},Wn=function(t){return null==t?[]:Cn(t,Tn(t))},Bn=Math.max;var Gn=l(function(t,e,r,n){t=Un(t)?t:Wn(t),r=r&&!n?zn(r):0;var o=t.length;return r<0&&(r=Bn(o+r,0)),Fn(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&xn(t,e,r)>-1});const $n={info:()=>{},error:()=>{},warn:()=>{}};function Vn(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:Gn(t,"error"),warn:Gn(t,"warn"),info:Gn(t,"info")}}(t);e&&($n.info=console.log),r&&($n.error=console.error),n&&($n.warn=console.warn)}var Xn=gr;var Yn=gr,Hn=Or,Qn=Tr;var Kn=gr,Jn=function(){this.__data__=new Xn,this.size=0},qn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Zn=function(t){return this.__data__.get(t)},to=function(t){return this.__data__.has(t)},eo=function(t,e){var r=this.__data__;if(r instanceof Yn){var n=r.__data__;if(!Hn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Qn(n)}return r.set(t,e),this.size=r.size,this};function ro(t){var e=this.__data__=new Kn(t);this.size=e.size}ro.prototype.clear=Jn,ro.prototype.delete=qn,ro.prototype.get=Zn,ro.prototype.has=to,ro.prototype.set=eo;var no=ro;var oo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t},io=ct,ao=Ee;var so=function(t,e){return t&&io(e,ao(e),t)};var co=D,uo=Ct,fo=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},lo=Object.prototype.hasOwnProperty;var ho=ye,vo=function(t){if(!co(t))return fo(t);var e=uo(t),r=[];for(var n in t)("constructor"!=n||!e&&lo.call(t,n))&&r.push(n);return r},po=At;var bo=function(t){return po(t)?ho(t,!0):vo(t)},yo=ct,_o=bo;var go=function(t,e){return t&&yo(e,_o(e),t)},Oo={exports:{}};!function(t,e){var r=b,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}}(Oo,Oo.exports);var jo=Oo.exports;var wo=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e};var So=function(){return[]},Ao=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},Eo=So,mo=Object.prototype.propertyIsEnumerable,No=Object.getOwnPropertySymbols,Do=No?function(t){return null==t?[]:(t=Object(t),Ao(No(t),function(e){return mo.call(t,e)}))}:Eo,Ro=ct,Mo=Do;var Io=function(t,e){return Ro(t,Mo(t),e)};var ko=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Po=_e(Object.getPrototypeOf,Object),Lo=ko,Co=Po,To=Do,xo=So,Uo=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Lo(e,To(t)),t=Co(t);return e}:xo,Fo=ct,zo=Uo;var Wo=function(t,e){return Fo(t,zo(t),e)},Bo=ko,Go=Xt;var $o=function(t,e,r){var n=e(t);return Go(t)?n:Bo(n,r(t))},Vo=$o,Xo=Do,Yo=Ee;var Ho=function(t){return Vo(t,Yo,Xo)},Qo=$o,Ko=Uo,Jo=bo;var qo=function(t){return Qo(t,Jo,Ko)},Zo=K(b,"DataView"),ti=Or,ei=K(b,"Promise"),ri=K(b,"Set"),ni=K(b,"WeakMap"),oi=N,ii=x,ai="[object Map]",si="[object Promise]",ci="[object Set]",ui="[object WeakMap]",fi="[object DataView]",li=ii(Zo),hi=ii(ti),vi=ii(ei),pi=ii(ri),bi=ii(ni),yi=oi;(Zo&&yi(new Zo(new ArrayBuffer(1)))!=fi||ti&&yi(new ti)!=ai||ei&&yi(ei.resolve())!=si||ri&&yi(new ri)!=ci||ni&&yi(new ni)!=ui)&&(yi=function(t){var e=oi(t),r="[object Object]"==e?t.constructor:void 0,n=r?ii(r):"";if(n)switch(n){case li:return fi;case hi:return ai;case vi:return si;case pi:return ci;case bi:return ui}return e});var _i=yi,di=Object.prototype.hasOwnProperty;var gi=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&di.call(t,"index")&&(r.index=t.index,r.input=t.input),r},Oi=b.Uint8Array,ji=Oi;var wi=function(t){var e=new t.constructor(t.byteLength);return new ji(e).set(new ji(t)),e},Si=wi;var Ai=function(t,e){var r=e?Si(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},Ei=/\w*$/;var mi=function(t){var e=new t.constructor(t.source,Ei.exec(t));return e.lastIndex=t.lastIndex,e},Ni=y?y.prototype:void 0,Di=Ni?Ni.valueOf:void 0;var Ri=wi;var Mi=wi,Ii=Ai,ki=mi,Pi=function(t){return Di?Object(Di.call(t)):{}},Li=function(t,e){var r=e?Ri(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var Ci=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return Mi(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return Ii(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 Li(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 ki(t);case"[object Symbol]":return Pi(t)}},Ti=D,xi=Object.create,Ui=function(){function t(){}return function(e){if(!Ti(e))return{};if(xi)return xi(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Fi=Po,zi=Ct;var Wi=function(t){return"function"!=typeof t.constructor||zi(t)?{}:Ui(Fi(t))},Bi=_i,Gi=xt;var $i=function(t){return Gi(t)&&"[object Map]"==Bi(t)},Vi=re,Xi=oe&&oe.isMap,Yi=Xi?Vi(Xi):$i,Hi=_i,Qi=xt;var Ki=function(t){return Qi(t)&&"[object Set]"==Hi(t)},Ji=re,qi=oe&&oe.isSet,Zi=qi?Ji(qi):Ki,ta=no,ea=oo,ra=it,na=so,oa=go,ia=jo,aa=wo,sa=Io,ca=Wo,ua=Ho,fa=qo,la=_i,ha=gi,va=Ci,pa=Wi,ba=Xt,ya=Kt,_a=Yi,da=D,ga=Zi,Oa=Ee,ja=bo,wa="[object Arguments]",Sa="[object Function]",Aa="[object Object]",Ea={};Ea[wa]=Ea["[object Array]"]=Ea["[object ArrayBuffer]"]=Ea["[object DataView]"]=Ea["[object Boolean]"]=Ea["[object Date]"]=Ea["[object Float32Array]"]=Ea["[object Float64Array]"]=Ea["[object Int8Array]"]=Ea["[object Int16Array]"]=Ea["[object Int32Array]"]=Ea["[object Map]"]=Ea["[object Number]"]=Ea[Aa]=Ea["[object RegExp]"]=Ea["[object Set]"]=Ea["[object String]"]=Ea["[object Symbol]"]=Ea["[object Uint8Array]"]=Ea["[object Uint8ClampedArray]"]=Ea["[object Uint16Array]"]=Ea["[object Uint32Array]"]=!0,Ea["[object Error]"]=Ea[Sa]=Ea["[object WeakMap]"]=!1;var ma=function t(e,r,n,o,i,a){var s,c=1&r,u=2&r,f=4&r;if(n&&(s=i?n(e,o,i,a):n(e)),void 0!==s)return s;if(!da(e))return e;var l=ba(e);if(l){if(s=ha(e),!c)return aa(e,s)}else{var h=la(e),v=h==Sa||"[object GeneratorFunction]"==h;if(ya(e))return ia(e,c);if(h==Aa||h==wa||v&&!i){if(s=u||v?{}:pa(e),!c)return u?ca(e,oa(s,e)):sa(e,na(s,e))}else{if(!Ea[h])return i?e:{};s=va(e,h,c)}}a||(a=new ta);var p=a.get(e);if(p)return p;a.set(e,s),ga(e)?e.forEach(function(o){s.add(t(o,r,n,o,e,a))}):_a(e)&&e.forEach(function(o,i){s.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?fa:ua:u?ja:Oa)(e);return ea(b||e,function(o,i){b&&(o=e[i=o]),ra(s,i,t(o,r,n,i,e,a))}),s};var Na=sn,Da=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 Ra=function(t,e){return e.length<2?t:Na(t,Da(e,0,-1))},Ma=en,Ia=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},ka=Ra,Pa=nn;var La=function(t,e){return e=Ma(e,t),null==(t=ka(t,e))||delete t[Pa(Ia(e))]},Ca=N,Ta=Po,xa=xt,Ua=Function.prototype,Fa=Object.prototype,za=Ua.toString,Wa=Fa.hasOwnProperty,Ba=za.call(Object);var Ga=function(t){if(!xa(t)||"[object Object]"!=Ca(t))return!1;var e=Ta(t);if(null===e)return!0;var r=Wa.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&za.call(r)==Ba};var $a=function(t){return Ga(t)?void 0:t},Va=Vt,Xa=Xt,Ya=y?y.isConcatSpreadable:void 0;var Ha=ko,Qa=function(t){return Xa(t)||Va(t)||!!(Ya&&t&&t[Ya])};var Ka=function t(e,r,n,o,i){var a=-1,s=e.length;for(n||(n=Qa),i||(i=[]);++a<s;){var c=e[a];r>0&&n(c)?r>1?t(c,r-1,n,o,i):Ha(i,c):o||(i[i.length]=c)}return i},Ja=Ka;var qa=function(t){return(null==t?0:t.length)?Ja(t,1):[]},Za=ht,ts=_t;var es=Gr,rs=ma,ns=La,os=en,is=ct,as=$a,ss=qo,cs=function(t){return ts(Za(t,void 0,qa),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=es(e,function(e){return e=os(e,t),n||(n=e.length>1),e}),is(t,ss(t),r),n&&(r=rs(r,7,as));for(var o=e.length;o--;)ns(r,e[o]);return r}),us=l(cs);const fs=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=e.homedir(),this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=r.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||r.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||r.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=r.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return r.join(...t)}folderCheck(e){t.mkdirSync(e,{recursive:!0})}fileCheck(e){t.existsSync(e)||t.writeFileSync(e,"",{encoding:"utf8"})}}("aiia-sdk");class ls{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=fs.addPath(fs.appFolder,this.fileName),fs.fileCheck(this.filePath)}getFileDataSync(){const e=t.readFileSync(this.filePath,"utf8");try{return JSON.parse(e)}catch(t){return{}}}setFileDataSync(e){try{const r=JSON.stringify(e);t.writeFileSync(this.filePath,r,"utf8")}catch(t){}}async getFileData(){return new Promise(e=>{t.readFile(this.filePath,"utf8",(t,r)=>{if(t)e({});else try{e(JSON.parse(r))}catch(t){e({})}})})}async setFileData(e){return new Promise(r=>{try{const n=JSON.stringify(e);t.writeFile(this.filePath,n,"utf8",t=>{r()})}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=us(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=us(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}var hs=Tr,vs=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ps=function(t){return this.__data__.has(t)};function bs(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new hs;++e<r;)this.add(t[e])}bs.prototype.add=bs.prototype.push=vs,bs.prototype.has=ps;var ys=bs,_s=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},ds=function(t,e){return t.has(e)};var gs=function(t,e,r,n,o,i){var a=1&r,s=t.length,c=e.length;if(s!=c&&!(a&&c>s))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 ys:void 0;for(i.set(t,e),i.set(e,t);++l<s;){var p=t[l],b=e[l];if(n)var y=a?n(b,p,l,e,t,i):n(p,b,l,t,e,i);if(void 0!==y){if(y)continue;h=!1;break}if(v){if(!_s(e,function(t,e){if(!ds(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};var Os=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var js=Oi,ws=et,Ss=gs,As=Os,Es=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},ms=y?y.prototype:void 0,Ns=ms?ms.valueOf:void 0;var Ds=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 js(t),new js(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return ws(+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=As;case"[object Set]":var c=1&n;if(s||(s=Es),t.size!=e.size&&!c)return!1;var u=a.get(t);if(u)return u==e;n|=2,a.set(t,e);var f=Ss(s(t),s(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(Ns)return Ns.call(t)==Ns.call(e)}return!1},Rs=Ho,Ms=Object.prototype.hasOwnProperty;var Is=no,ks=gs,Ps=Ds,Ls=function(t,e,r,n,o,i){var a=1&r,s=Rs(t),c=s.length;if(c!=Rs(e).length&&!a)return!1;for(var u=c;u--;){var f=s[u];if(!(a?f in e:Ms.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<c;){var b=t[f=s[u]],y=e[f];if(n)var _=a?n(y,b,f,e,t,i):n(b,y,f,t,e,i);if(!(void 0===_?b===y||o(b,y,r,n,i):_)){v=!1;break}p||(p="constructor"==f)}if(v&&!p){var d=t.constructor,g=e.constructor;d==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof d&&d instanceof d&&"function"==typeof g&&g instanceof g||(v=!1)}return i.delete(t),i.delete(e),v},Cs=_i,Ts=Xt,xs=Kt,Us=ce,Fs="[object Arguments]",zs="[object Array]",Ws="[object Object]",Bs=Object.prototype.hasOwnProperty;var Gs=function(t,e,r,n,o,i){var a=Ts(t),s=Ts(e),c=a?zs:Cs(t),u=s?zs:Cs(e),f=(c=c==Fs?Ws:c)==Ws,l=(u=u==Fs?Ws:u)==Ws,h=c==u;if(h&&xs(t)){if(!xs(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Is),a||Us(t)?ks(t,e,r,n,o,i):Ps(t,e,c,r,n,o,i);if(!(1&r)){var v=f&&Bs.call(t,"__wrapped__"),p=l&&Bs.call(e,"__wrapped__");if(v||p){var b=v?t.value():t,y=p?e.value():e;return i||(i=new Is),o(b,y,r,n,i)}}return!!h&&(i||(i=new Is),Ls(t,e,r,n,o,i))},$s=xt;var Vs=function t(e,r,n,o,i){return e===r||(null==e||null==r||!$s(e)&&!$s(r)?e!=e&&r!=r:Gs(e,r,n,o,t,i))},Xs=no,Ys=Vs;var Hs=D;var Qs=function(t){return t==t&&!Hs(t)},Ks=Qs,Js=Ee;var qs=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Zs=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 c=(s=r[o])[0],u=t[c],f=s[1];if(a&&s[2]){if(void 0===u&&!(c in t))return!1}else{var l=new Xs;if(n)var h=n(u,f,c,t,e,l);if(!(void 0===h?Ys(f,u,3,n,l):h))return!1}}return!0},tc=function(t){for(var e=Js(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Ks(o)]}return e},ec=qs;var rc=en,nc=Vt,oc=Xt,ic=mt,ac=jt,sc=nn;var cc=function(t,e,r){for(var n=-1,o=(e=rc(e,t)).length,i=!1;++n<o;){var a=sc(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&ac(o)&&ic(a,o)&&(oc(t)||nc(t))},uc=function(t,e){return null!=t&&e in Object(t)},fc=cc;var lc=function(t,e){return null!=t&&fc(t,e,uc)},hc=Vs,vc=fn,pc=lc,bc=We,yc=Qs,_c=qs,dc=nn;var gc=function(t,e){return bc(t)&&yc(e)?_c(dc(t),e):function(r){var n=vc(r,t);return void 0===n&&n===e?pc(r,t):hc(e,n,3)}};var Oc=sn;var jc=function(t){return function(e){return Oc(e,t)}},wc=function(t){return function(e){return null==e?void 0:e[t]}},Sc=jc,Ac=We,Ec=nn;var mc=function(t){return Ac(t)?wc(Ec(t)):Sc(t)},Nc=function(t){var e=tc(t);return 1==e.length&&e[0][2]?ec(e[0][0],e[0][1]):function(r){return r===t||Zs(r,t,e)}},Dc=gc,Rc=ut,Mc=Xt,Ic=mc;var kc=function(t){return"function"==typeof t?t:null==t?Rc:"object"==typeof t?Mc(t)?Dc(t[0],t[1]):Nc(t):Ic(t)};var Pc=function(t){return function(e,r,n){for(var o=-1,i=Object(e),a=n(e),s=a.length;s--;){var c=a[t?s:++o];if(!1===r(i[c],c,i))break}return e}}(),Lc=Ee;var Cc=At;var Tc=function(t,e){return function(r,n){if(null==r)return r;if(!Cc(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&&Pc(t,e,Lc)}),xc=At;var Uc=Gr,Fc=kc,zc=function(t,e){var r=-1,n=xc(t)?Array(t.length):[];return Tc(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Wc=Xt;var Bc,Gc=l(function(t,e){return(Wc(t)?Uc:zc)(t,Fc(e))});class $c{instance;controller;constructor(t){this.controller=new AbortController,this.instance=s.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=>ln(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(un["網絡錯誤"]);if(""===n)throw new Error(un["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>Gc(ln(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(un["網絡錯誤"]);if(0===e.length)throw new Error(un["沒有可用專案"]);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"}(Bc||(Bc={}));class Vc{socket;messageSub;startLinkSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get startLink(){return this.startLinkSub.asObservable()}messageQueue=[];isConnected;isStart;constructor(){this.isConnected=!1,this.isStart=!1,this.messageSub=new n,this.startLinkSub=new n,this.closeSub=new n,this.destorySub=new n}start(t){this.isStart=!0,this.socket=new u(t),$n.info("Proxy to",t),o(this.socket,"open").pipe(i(this.destorySub)).subscribe(t=>{this.isConnected=!0,this.startLinkSub.next(),$n.info("Proxy startup"),this.flushMessageQueue()}),o(this.socket,"message").pipe(i(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),o(this.socket,"error").pipe(i(this.destorySub)).subscribe(t=>{const{error:e}=t;$n.error("Proxy has some problem",e)}),o(this.socket,"close").pipe(i(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e}=t;switch($n.error("Proxy closed",{code:e}),e){case Bc.MANUAL_CLOSE:$n.info("MANUAL_CLOSE stop emit event and reconnecting");break;case Bc.WS_5000_NORAML_CLOSURE:case Bc.MDN_NORMAL_CLOSURE:case Bc.MDN_GOING_AWAY:this.closeSub.next("close"),$n.info("Safe close connection");break;case Bc.MDN_NO_STATUS_RECEIVED:case Bc.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),$n.error("Cloud disconnect");break;case Bc.WS_5001_UNAUTHORIZED:case Bc.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),$n.error("Please contact Graphen");break;case Bc.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect");break;default:this.closeSub.next("close"),$n.warn("Other status always close connection")}})}flushMessageQueue(){for(;this.messageQueue.length>0&&this.isConnected;){const t=this.messageQueue.shift();t&&this.socket.send(t)}}send(t){this.isConnected?this.socket.send(t):this.messageQueue.push(t)}onManualClose(){this.isStart&&this.socket?.close(Bc.MANUAL_CLOSE)}onDestory(){this.destorySub.next(),this.destorySub.complete()}}class Xc{sdk;server;get url(){return this.sdk.config.endPoint.socket}get port(){return this.sdk.config.port}get webserver(){return this.sdk.config.webserver}constructor(t){this.sdk=t}start(){this.server=new c(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{const e=new n;let r=(s=t.handshake.query.uuid,Yt(s)?ln(s,"[0]",void 0):s??void 0);var s;const c=new Vc;void 0===r?(this.sdk.getProjectList().then(e=>{t.emit("list",e)}),o(t,"uuid").pipe(a(1),i(e)).subscribe(n=>{r=n,this.openChannel(r,t,c,e)})):this.openChannel(r,t,c,e),t.on("disconnect",t=>{e.next(),e.complete(),$n.info(t)})}),void 0===this.webserver&&this.server.listen(this.port)}openChannel(t,e,r,n){o(e,"cloud").pipe(i(n)).subscribe(t=>{r.send(t)}),r.message.pipe(i(n)).subscribe(t=>{e.emit("cloud",t)}),r.close.pipe(i(n)).subscribe(async n=>{switch(n){case"close":case"no_permissions":e.emit("channel",n),r.onDestory();break;case"reconnect":await this.sdk.replaceAccessToken(),r.start(this.getProxySocketURL(t))}}),r.startLink.pipe(i(n)).subscribe(()=>{e.emit("channel","open")}),r.start(this.getProxySocketURL(t))}getProxySocketURL(t){return`${this.url}/v1/chat/project/${this.sdk.accessToken}/${t}`}onDestory(){this.server&&this.server.close()}}class Yc{config;stroage;apiProxy;chat;isStart;destorySub;get destoryObs(){return this.destorySub.asObservable()}access_token;get accessToken(){return this.access_token}constructor(t,e){this.config=t,this.stroage=e,this.isStart=!1,this.destorySub=new n,this.access_token=e.getItemSync(hn),this.apiProxy=new $c(this.config.endPoint.api),$n.info("[Initialize] proxy is finished"),this.chat=new Xc(this),$n.info("[Initialize] chat is finished","Start at PORT:",this.config.port)}async start(){if(this.isStart)throw new Error(un["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.start(),$n.info("Chat service startup")}async replaceAccessToken(){const t=await this.apiProxy.getAccessToken(this.config.license,this.access_token);return this.access_token=t,this.stroage.setItemSync(hn,t),t}async getProjectList(){return await this.apiProxy.getProjectList(this.config.license)}onDestory(){this.apiProxy.onDestory(),this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete(),$n.info("[Destory] core module done")}}function Hc(t){if(vn){if(void 0===ln(t,"license",void 0))throw new Error(un["未提供憑證"]);$n.info("Initialize necessary modules");const e=new pn(Pe({},t));Vn(e.debug),$n.info("[Initialize] config finished");const r=new ls;$n.info("[Initialize] storage finished");const n=new Yc(e,r);return $n.info("[Initialize] core finished"),n.start(),$n.info("Service startup"),()=>{n.onDestory()}}throw new Error(un["環境錯誤(nodejs)"])}export{Hc 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";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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphen.ai/aiia-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jay Huang",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"clean:type": "rm -rf ./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
44
|
"types:extract": "npm run types:extract:browser && npm run types:extract:node && npm run clean:type",
|
|
44
45
|
"types:extract:browser": "api-extractor run --local --config api-extractor.browser.json",
|
|
45
46
|
"types:extract:node": "api-extractor run --local --config api-extractor.node.json"
|
|
@@ -51,17 +52,22 @@
|
|
|
51
52
|
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
52
53
|
"@rollup/plugin-terser": "^0.4.4",
|
|
53
54
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
55
|
+
"@types/audioworklet": "^0.0.83",
|
|
56
|
+
"@types/jest": "^30.0.0",
|
|
54
57
|
"@types/lodash": "^4.17.20",
|
|
55
58
|
"@types/node": "^24.2.1",
|
|
56
59
|
"@types/ws": "^8.18.1",
|
|
60
|
+
"jest": "^30.1.3",
|
|
57
61
|
"rollup": "^4.46.2",
|
|
58
62
|
"rollup-plugin-javascript-obfuscator": "^1.0.1",
|
|
63
|
+
"ts-jest": "^29.4.1",
|
|
59
64
|
"tslib": "^2.6.2",
|
|
60
65
|
"typescript": "^5.9.2"
|
|
61
66
|
},
|
|
62
67
|
"dependencies": {
|
|
63
68
|
"axios": "^1.11.0",
|
|
64
69
|
"lodash": "^4.17.21",
|
|
70
|
+
"moment": "^2.30.1",
|
|
65
71
|
"rxjs": "^7.8.2",
|
|
66
72
|
"socket.io": "^4.8.1",
|
|
67
73
|
"socket.io-client": "^4.8.1",
|