@graphen.ai/aiia-sdk 1.0.3 → 1.0.5
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 +45 -0
- package/NOTICE +29 -0
- package/README.md +44 -0
- package/dist/browser.cjs +1 -1
- package/dist/browser.d.ts +55 -43
- package/dist/browser.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.ts +5 -3
- package/dist/node.mjs +1 -1
- package/package.json +4 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Graphen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This project uses the following third-party packages and complies with their respective licenses:
|
|
26
|
+
|
|
27
|
+
- axios (MIT License)
|
|
28
|
+
- cors (MIT License)
|
|
29
|
+
- lodash (MIT License)
|
|
30
|
+
- rxjs (Apache License 2.0)
|
|
31
|
+
- socket.io (MIT License)
|
|
32
|
+
- socket.io-client (MIT License)
|
|
33
|
+
- ws (MIT License)
|
|
34
|
+
- moment (MIT License)
|
|
35
|
+
|
|
36
|
+
Development dependencies:
|
|
37
|
+
- @microsoft/api-extractor (MIT License)
|
|
38
|
+
- @rollup/* (MIT License)
|
|
39
|
+
- @types/* (MIT License)
|
|
40
|
+
- rollup (MIT License)
|
|
41
|
+
- rollup-plugin-javascript-obfuscator (MIT License)
|
|
42
|
+
- tslib (MIT License)
|
|
43
|
+
- typescript (Apache License 2.0)
|
|
44
|
+
|
|
45
|
+
Please refer to each package's official documentation for full license details.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
This project includes software developed by others and distributed under the Apache License 2.0. The following is a list of these components and their respective copyright notices, as required by the Apache License 2.0.
|
|
2
|
+
|
|
3
|
+
typescript
|
|
4
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
rxjs
|
|
18
|
+
Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
|
25
|
+
Unless required by applicable law or agreed to in writing, software
|
|
26
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
+
See the License for the specific language governing permissions and
|
|
29
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# AIIA SDK
|
|
2
|
+
|
|
3
|
+
AIIA SDK provided by Graphen
|
|
4
|
+
|
|
5
|
+
## 安裝方式(How to install)
|
|
6
|
+
|
|
7
|
+
使用 npm 安裝:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @graphen.ai/aiia-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
或 yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @graphen.ai/aiia-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 使用說明(Instructions)
|
|
20
|
+
|
|
21
|
+
### 瀏覽器端(Browser)
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { initSdk } from '@graphen.ai/aiia-sdk/browser';
|
|
25
|
+
|
|
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
|
+
});
|
|
29
|
+
sdk.start()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Node.js 端
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { aiiaCore } from '@graphen.ai/aiia-sdk/node';
|
|
36
|
+
|
|
37
|
+
const core = aiiaCore({ license: "<Your Token>" });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 授權條款(LICENSE)
|
|
41
|
+
|
|
42
|
+
本專案採用 MIT 授權。詳見 [LICENSE](./LICENSE) 檔案。
|
|
43
|
+
|
|
44
|
+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
package/dist/browser.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("rxjs"),e=require("socket.io-client"),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var o="object"==typeof r&&r&&r.Object===Object&&r,a=o,i="object"==typeof self&&self&&self.Object===Object&&self,u=a||i||Function("return this")(),s=u.Symbol,c=s,f=Object.prototype,l=f.hasOwnProperty,h=f.toString,d=c?c.toStringTag:void 0;var v=function(t){var e=l.call(t,d),r=t[d];try{t[d]=void 0;var n=!0}catch(t){}var o=h.call(t);return n&&(e?t[d]=r:delete t[d]),o},p=Object.prototype.toString;var b=v,y=function(t){return p.call(t)},g=s?s.toStringTag:void 0;var m=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?b(t):y(t)};var _=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},w=m,j=_;var O,S=function(t){if(!j(t))return!1;var e=w(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},R=u["__core-js_shared__"],x=(O=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var k=function(t){return!!x&&x in t},C=Function.prototype.toString;var A=function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""},N=S,E=k,M=_,z=A,D=/^\[object .+?Constructor\]$/,P=Function.prototype,B=Object.prototype,T=P.toString,F=B.hasOwnProperty,U=RegExp("^"+T.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var $=function(t){return!(!M(t)||E(t))&&(N(t)?U:D).test(z(t))},I=function(t,e){return null==t?void 0:t[e]};var V=function(t,e){var r=I(t,e);return $(r)?r:void 0},q=V,Q=function(){try{var t=q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),W=Q;var L=function(t,e,r){"__proto__"==e&&W?W(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var G=function(t,e){return t===e||t!=t&&e!=e},J=L,H=G,K=Object.prototype.hasOwnProperty;var X=function(t,e,r){var n=t[e];K.call(t,e)&&H(n,r)&&(void 0!==r||e in t)||J(t,e,r)},Y=X,Z=L;var tt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?Z(r,u,s):Y(r,u,s)}return r};var et=function(t){return t};var rt=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},nt=Math.max;var ot=function(t,e,r){return e=nt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=nt(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),rt(t,this,u)}};var at=function(t){return function(){return t}},it=Q,ut=it?function(t,e){return it(t,"toString",{configurable:!0,enumerable:!1,value:at(e),writable:!0})}:et,st=Date.now;var ct=function(t){var e=0,r=0;return function(){var n=st(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ut),ft=et,lt=ot,ht=ct;var dt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},vt=S,pt=dt;var bt=function(t){return null!=t&&pt(t.length)&&!vt(t)},yt=/^(?:0|[1-9]\d*)$/;var gt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&yt.test(t))&&t>-1&&t%1==0&&t<e},mt=G,_t=bt,wt=gt,jt=_;var Ot=function(t,e){return ht(lt(t,e,ft),t+"")},St=function(t,e,r){if(!jt(r))return!1;var n=typeof e;return!!("number"==n?_t(r)&&wt(e,r.length):"string"==n&&e in r)&&mt(r[e],t)};var Rt=function(t){return Ot(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&St(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},xt=Object.prototype;var kt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||xt)};var Ct=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var At=function(t){return null!=t&&"object"==typeof t},Nt=m,Et=At;var Mt=function(t){return Et(t)&&"[object Arguments]"==Nt(t)},zt=At,Dt=Object.prototype,Pt=Dt.hasOwnProperty,Bt=Dt.propertyIsEnumerable,Tt=Mt(function(){return arguments}())?Mt:function(t){return zt(t)&&Pt.call(t,"callee")&&!Bt.call(t,"callee")},Ft=Array.isArray,Ut=n(Ft),$t={exports:{}};var It=function(){return!1};!function(t,e){var r=u,n=It,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,s=(i?i.isBuffer:void 0)||n;t.exports=s}($t,$t.exports);var Vt=$t.exports,qt=m,Qt=dt,Wt=At,Lt={};Lt["[object Float32Array]"]=Lt["[object Float64Array]"]=Lt["[object Int8Array]"]=Lt["[object Int16Array]"]=Lt["[object Int32Array]"]=Lt["[object Uint8Array]"]=Lt["[object Uint8ClampedArray]"]=Lt["[object Uint16Array]"]=Lt["[object Uint32Array]"]=!0,Lt["[object Arguments]"]=Lt["[object Array]"]=Lt["[object ArrayBuffer]"]=Lt["[object Boolean]"]=Lt["[object DataView]"]=Lt["[object Date]"]=Lt["[object Error]"]=Lt["[object Function]"]=Lt["[object Map]"]=Lt["[object Number]"]=Lt["[object Object]"]=Lt["[object RegExp]"]=Lt["[object Set]"]=Lt["[object String]"]=Lt["[object WeakMap]"]=!1;var Gt=function(t){return Wt(t)&&Qt(t.length)&&!!Lt[qt(t)]};var Jt=function(t){return function(e){return t(e)}},Ht={exports:{}};!function(t,e){var r=o,n=e&&!e.nodeType&&e,a=n&&t&&!t.nodeType&&t,i=a&&a.exports===n&&r.process,u=function(){try{var t=a&&a.require&&a.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=u}(Ht,Ht.exports);var Kt=Ht.exports,Xt=Gt,Yt=Jt,Zt=Kt&&Kt.isTypedArray,te=Zt?Yt(Zt):Xt,ee=Ct,re=Tt,ne=Ft,oe=Vt,ae=gt,ie=te,ue=Object.prototype.hasOwnProperty;var se=function(t,e){var r=ne(t),n=!r&&re(t),o=!r&&!n&&oe(t),a=!r&&!n&&!o&&ie(t),i=r||n||o||a,u=i?ee(t.length,String):[],s=u.length;for(var c in t)!e&&!ue.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ae(c,s))||u.push(c);return u};var ce=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),fe=kt,le=ce,he=Object.prototype.hasOwnProperty;var de=se,ve=function(t){if(!fe(t))return le(t);var e=[];for(var r in Object(t))he.call(t,r)&&"constructor"!=r&&e.push(r);return e},pe=bt;var be,ye=function(t){return pe(t)?de(t):ve(t)},ge=X,me=tt,_e=Rt,we=bt,je=kt,Oe=ye,Se=Object.prototype.hasOwnProperty,Re=n(_e(function(t,e){if(je(e)||we(e))me(e,Oe(e),t);else for(var r in e)Se.call(e,r)&&ge(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(be||(be={}));const xe="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class ke{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Re({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Re({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ce=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Ae=Ce,Ne=function(t){return t!=t},Ee=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Me=function(t,e,r){return e==e?Ee(t,e,r):Ae(t,Ne,r)},ze=m,De=Ft,Pe=At;var Be=function(t){return"string"==typeof t||!De(t)&&Pe(t)&&"[object String]"==ze(t)},Te=/\s/;var Fe=function(t){for(var e=t.length;e--&&Te.test(t.charAt(e)););return e},Ue=/^\s+/;var $e=m,Ie=At;var Ve=function(t){return"symbol"==typeof t||Ie(t)&&"[object Symbol]"==$e(t)},qe=function(t){return t?t.slice(0,Fe(t)+1).replace(Ue,""):t},Qe=_,We=Ve,Le=/^[-+]0x[0-9a-f]+$/i,Ge=/^0b[01]+$/i,Je=/^0o[0-7]+$/i,He=parseInt;var Ke=function(t){if("number"==typeof t)return t;if(We(t))return NaN;if(Qe(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Qe(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=qe(t);var r=Ge.test(t);return r||Je.test(t)?He(t.slice(2),r?2:8):Le.test(t)?NaN:+t},Xe=1/0;var Ye=function(t){return t?(t=Ke(t))===Xe||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ze=function(t){var e=Ye(t),r=e%1;return e==e?r?e-r:e:0};var tr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},er=tr;var rr=function(t,e){return er(e,function(e){return t[e]})},nr=ye;var or=function(t){return null==t?[]:rr(t,nr(t))},ar=n(or),ir=Me,ur=bt,sr=Be,cr=Ze,fr=or,lr=Math.max;var hr=n(function(t,e,r,n){t=ur(t)?t:fr(t),r=r&&!n?cr(r):0;var o=t.length;return r<0&&(r=lr(o+r,0)),sr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&ir(t,e,r)>-1});const dr={info:()=>{},error:()=>{},warn:()=>{}};function vr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:hr(t,"error"),warn:hr(t,"warn"),info:hr(t,"info")}}(t);e&&(dr.info=console.log),r&&(dr.error=console.error),n&&(dr.warn=console.warn)}var pr=Ft,br=Ve,yr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,gr=/^\w*$/;var mr=function(t,e){if(pr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!br(t))||(gr.test(t)||!yr.test(t)||null!=e&&t in Object(e))},_r=V(Object,"create"),wr=_r;var jr=function(){this.__data__=wr?wr(null):{},this.size=0};var Or=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Sr=_r,Rr=Object.prototype.hasOwnProperty;var xr=function(t){var e=this.__data__;if(Sr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Rr.call(e,t)?e[t]:void 0},kr=_r,Cr=Object.prototype.hasOwnProperty;var Ar=_r;var Nr=jr,Er=Or,Mr=xr,zr=function(t){var e=this.__data__;return kr?void 0!==e[t]:Cr.call(e,t)},Dr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Ar&&void 0===e?"__lodash_hash_undefined__":e,this};function Pr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Pr.prototype.clear=Nr,Pr.prototype.delete=Er,Pr.prototype.get=Mr,Pr.prototype.has=zr,Pr.prototype.set=Dr;var Br=Pr;var Tr=function(){this.__data__=[],this.size=0},Fr=G;var Ur=function(t,e){for(var r=t.length;r--;)if(Fr(t[r][0],e))return r;return-1},$r=Ur,Ir=Array.prototype.splice;var Vr=Ur;var qr=Ur;var Qr=Ur;var Wr=Tr,Lr=function(t){var e=this.__data__,r=$r(e,t);return!(r<0)&&(r==e.length-1?e.pop():Ir.call(e,r,1),--this.size,!0)},Gr=function(t){var e=this.__data__,r=Vr(e,t);return r<0?void 0:e[r][1]},Jr=function(t){return qr(this.__data__,t)>-1},Hr=function(t,e){var r=this.__data__,n=Qr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Kr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Kr.prototype.clear=Wr,Kr.prototype.delete=Lr,Kr.prototype.get=Gr,Kr.prototype.has=Jr,Kr.prototype.set=Hr;var Xr=Kr,Yr=V(u,"Map"),Zr=Br,tn=Xr,en=Yr;var rn=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var nn=function(t,e){var r=t.__data__;return rn(e)?r["string"==typeof e?"string":"hash"]:r.map},on=nn;var an=nn;var un=nn;var sn=nn;var cn=function(){this.size=0,this.__data__={hash:new Zr,map:new(en||tn),string:new Zr}},fn=function(t){var e=on(this,t).delete(t);return this.size-=e?1:0,e},ln=function(t){return an(this,t).get(t)},hn=function(t){return un(this,t).has(t)},dn=function(t,e){var r=sn(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function vn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}vn.prototype.clear=cn,vn.prototype.delete=fn,vn.prototype.get=ln,vn.prototype.has=hn,vn.prototype.set=dn;var pn=vn,bn=pn;function yn(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(yn.Cache||bn),r}yn.Cache=bn;var gn=yn;var mn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,_n=/\\(\\)?/g,wn=function(t){var e=gn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(mn,function(t,r,n,o){e.push(n?o.replace(_n,"$1"):r||t)}),e}),jn=tr,On=Ft,Sn=Ve,Rn=s?s.prototype:void 0,xn=Rn?Rn.toString:void 0;var kn=function t(e){if("string"==typeof e)return e;if(On(e))return jn(e,t)+"";if(Sn(e))return xn?xn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Cn=kn;var An=Ft,Nn=mr,En=wn,Mn=function(t){return null==t?"":Cn(t)};var zn=function(t,e){return An(t)?t:Nn(t,e)?[t]:En(Mn(t))},Dn=Ve;var Pn=function(t){if("string"==typeof t||Dn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Bn=zn,Tn=Pn;var Fn=function(t,e){for(var r=0,n=(e=Bn(e,t)).length;null!=t&&r<n;)t=t[Tn(e[r++])];return r&&r==n?t:void 0},Un=Fn;var $n,In,Vn=function(t,e,r){var n=null==t?void 0:Un(t,e);return void 0===n?r:n},qn=n(Vn);function Qn(t,e,r){return Math.max(r,Math.min(t,e))}function Wn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Ln(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Qn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}($n||($n={}));class Gn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Wn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{dr.error("[ERROR]: pause speech fail"),dr.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{dr.error("[ERROR]: resume speech fail"),dr.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Jn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(e,r){this.stream=e,this.audioContext=r,this.pcmSub=new t.Subject}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(In||(In={}));class Hn{_state;stateSub;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get state(){return this._state}set state(t){t!==this._state&&(this._state=t,this.stateSub.next(t))}get stateObs(){return this.stateSub.asObservable()}constructor(){this.stateSub=new t.Subject,this.pcmSub=new t.Subject,this.destory=new t.Subject,this.state=In.padding}async init(e){if(this.destory.closed)throw new Error(be["實例已摧毀"]);const r=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===r)throw this.state=In.rejected,new Error(be["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(e)}catch(t){throw dr.error(t),this.state=In.loadfail,new Error(be["Worklet模組載入失敗"])}this.state=In.allowed,this.audioManager=new Gn(this.audioCtx),this.vadManager=new Jn(r,this.audioCtx),this.vadManager.pcm.pipe(t.takeUntil(this.destory)).subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=qn(t,"buffer",void 0),r=qn(t,"float32",void 0),n=qn(t,"int16",void 0),o=qn(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx.close(),this.destory.next(),this.destory.complete()}}var Kn=Xr;var Xn=Xr,Yn=Yr,Zn=pn;var to=Xr,eo=function(){this.__data__=new Kn,this.size=0},ro=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},no=function(t){return this.__data__.get(t)},oo=function(t){return this.__data__.has(t)},ao=function(t,e){var r=this.__data__;if(r instanceof Xn){var n=r.__data__;if(!Yn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Zn(n)}return r.set(t,e),this.size=r.size,this};function io(t){var e=this.__data__=new to(t);this.size=e.size}io.prototype.clear=eo,io.prototype.delete=ro,io.prototype.get=no,io.prototype.has=oo,io.prototype.set=ao;var uo=io;var so=pn,co=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},fo=function(t){return this.__data__.has(t)};function lo(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new so;++e<r;)this.add(t[e])}lo.prototype.add=lo.prototype.push=co,lo.prototype.has=fo;var ho=lo,vo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},po=function(t,e){return t.has(e)};var bo=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),f=a.get(e);if(c&&f)return c==e&&f==t;var l=-1,h=!0,d=2&r?new ho:void 0;for(a.set(t,e),a.set(e,t);++l<u;){var v=t[l],p=e[l];if(n)var b=i?n(p,v,l,e,t,a):n(v,p,l,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!vo(e,function(t,e){if(!po(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var yo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var go=u.Uint8Array,mo=G,_o=bo,wo=yo,jo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},Oo=s?s.prototype:void 0,So=Oo?Oo.valueOf:void 0;var Ro=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new go(t),new go(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return mo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=wo;case"[object Set]":var s=1&n;if(u||(u=jo),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var f=_o(u(t),u(e),n,o,a,i);return i.delete(t),f;case"[object Symbol]":if(So)return So.call(t)==So.call(e)}return!1};var xo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},ko=xo,Co=Ft;var Ao=function(t,e,r){var n=e(t);return Co(t)?n:ko(n,r(t))};var No=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Eo=function(){return[]},Mo=Object.prototype.propertyIsEnumerable,zo=Object.getOwnPropertySymbols,Do=Ao,Po=zo?function(t){return null==t?[]:(t=Object(t),No(zo(t),function(e){return Mo.call(t,e)}))}:Eo,Bo=ye;var To=function(t){return Do(t,Bo,Po)},Fo=Object.prototype.hasOwnProperty;var Uo=function(t,e,r,n,o,a){var i=1&r,u=To(t),s=u.length;if(s!=To(e).length&&!i)return!1;for(var c=s;c--;){var f=u[c];if(!(i?f in e:Fo.call(e,f)))return!1}var l=a.get(t),h=a.get(e);if(l&&h)return l==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[f=u[c]],b=e[f];if(n)var y=i?n(b,p,f,e,t,a):n(p,b,f,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==f)}if(d&&!v){var g=t.constructor,m=e.constructor;g==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof m&&m instanceof m||(d=!1)}return a.delete(t),a.delete(e),d},$o=V(u,"DataView"),Io=Yr,Vo=V(u,"Promise"),qo=V(u,"Set"),Qo=V(u,"WeakMap"),Wo=m,Lo=A,Go="[object Map]",Jo="[object Promise]",Ho="[object Set]",Ko="[object WeakMap]",Xo="[object DataView]",Yo=Lo($o),Zo=Lo(Io),ta=Lo(Vo),ea=Lo(qo),ra=Lo(Qo),na=Wo;($o&&na(new $o(new ArrayBuffer(1)))!=Xo||Io&&na(new Io)!=Go||Vo&&na(Vo.resolve())!=Jo||qo&&na(new qo)!=Ho||Qo&&na(new Qo)!=Ko)&&(na=function(t){var e=Wo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Lo(r):"";if(n)switch(n){case Yo:return Xo;case Zo:return Go;case ta:return Jo;case ea:return Ho;case ra:return Ko}return e});var oa=uo,aa=bo,ia=Ro,ua=Uo,sa=na,ca=Ft,fa=Vt,la=te,ha="[object Arguments]",da="[object Array]",va="[object Object]",pa=Object.prototype.hasOwnProperty;var ba=function(t,e,r,n,o,a){var i=ca(t),u=ca(e),s=i?da:sa(t),c=u?da:sa(e),f=(s=s==ha?va:s)==va,l=(c=c==ha?va:c)==va,h=s==c;if(h&&fa(t)){if(!fa(e))return!1;i=!0,f=!1}if(h&&!f)return a||(a=new oa),i||la(t)?aa(t,e,r,n,o,a):ia(t,e,s,r,n,o,a);if(!(1&r)){var d=f&&pa.call(t,"__wrapped__"),v=l&&pa.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new oa),o(p,b,r,n,a)}}return!!h&&(a||(a=new oa),ua(t,e,r,n,o,a))},ya=At;var ga=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ya(e)&&!ya(r)?e!=e&&r!=r:ba(e,r,n,o,t,a))},ma=uo,_a=ga;var wa=_;var ja=function(t){return t==t&&!wa(t)},Oa=ja,Sa=ye;var Ra=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},xa=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],f=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var l=new ma;if(n)var h=n(c,f,s,t,e,l);if(!(void 0===h?_a(f,c,3,n,l):h))return!1}}return!0},ka=function(t){for(var e=Sa(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Oa(o)]}return e},Ca=Ra;var Aa=zn,Na=Tt,Ea=Ft,Ma=gt,za=dt,Da=Pn;var Pa=function(t,e){return null!=t&&e in Object(t)},Ba=function(t,e,r){for(var n=-1,o=(e=Aa(e,t)).length,a=!1;++n<o;){var i=Da(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&za(o)&&Ma(i,o)&&(Ea(t)||Na(t))};var Ta=ga,Fa=Vn,Ua=function(t,e){return null!=t&&Ba(t,e,Pa)},$a=mr,Ia=ja,Va=Ra,qa=Pn;var Qa=Fn;var Wa=function(t){return function(e){return null==e?void 0:e[t]}},La=function(t){return function(e){return Qa(e,t)}},Ga=mr,Ja=Pn;var Ha=function(t){var e=ka(t);return 1==e.length&&e[0][2]?Ca(e[0][0],e[0][1]):function(r){return r===t||xa(r,t,e)}},Ka=function(t,e){return $a(t)&&Ia(e)?Va(qa(t),e):function(r){var n=Fa(r,t);return void 0===n&&n===e?Ua(r,t):Ta(e,n,3)}},Xa=et,Ya=Ft,Za=function(t){return Ga(t)?Wa(Ja(t)):La(t)};var ti=function(t){return"function"==typeof t?t:null==t?Xa:"object"==typeof t?Ya(t)?Ka(t[0],t[1]):Ha(t):Za(t)};var ei=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ri=ye;var ni=bt;var oi=function(t,e){return function(r,n){if(null==r)return r;if(!ni(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&ei(t,e,ri)}),ai=bt;var ii=tr,ui=ti,si=function(t,e){var r=-1,n=ai(t)?Array(t.length):[];return oi(t,function(t,o,a){n[++r]=e(t,o,a)}),n},ci=Ft;var fi=n(function(t,e){return(ci(t)?ii:si)(t,ui(e))}),li=ti,hi=bt,di=ye;var vi=function(t){return function(e,r,n){var o=Object(e);if(!hi(e)){var a=li(r);e=di(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},pi=Ce,bi=ti,yi=Ze,gi=Math.max;var mi,_i=n(vi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:yi(r);return o<0&&(o=gi(n+o,0)),pi(t,bi(e),o)}));class wi{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(r){this.destorySub=new t.Subject,this.messageSub=new t.Subject;const{specific:n,id:o}=r.project;this.socket=e.io(r.ws_url,Re({autoConnect:!1},n&&void 0!==o?{query:{uuid:o}}:{}))}start(){const e="list",r="cloud",n="channel";t.fromEvent(this.socket,e).pipe(t.take(1),t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:e,data:t})}),t.fromEvent(this.socket,r).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:r,data:t})}),t.fromEvent(this.socket,n).pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.messageSub.next({event:n,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(mi||(mi={}));class ji{config;media;chat;destorySub;projectsSub;layoutSub;cloudSampleRate;get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(e,r){this.config=e,this.media=r,this.layoutSub=new t.Subject,this.projectsSub=new t.Subject,this.destorySub=new t.Subject,this.cloudSampleRate=16e3,this.chat=new wi(e)}start(){this.chat.message.pipe(t.takeUntil(this.destorySub)).subscribe(({event:e,data:r})=>{switch(e){case"cloud":this.cloudToObj(r);break;case"list":{const{id:t,name:e,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=_i(r,r=>r.name===e||r.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):this.projectsSub.next(r);break}case"channel":this.media.state===In.allowed?this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}):this.media.state===In.padding&&this.media.stateObs.pipe(t.takeUntil(this.destorySub)).subscribe(t=>{t===In.allowed&&this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate})})}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==qn(e,"signal")?this.behavior(e):Ut(e)?fi(e,this.behavior):fi(ar(e),this.behavior)}catch(t){dr.error("aiia websocket","onmessage error",t)}}behavior(e){switch(e.signal){case"layout":this.layoutSub.next(e.content);break;case"audio":if("sampleRate"===e.command)this.cloudSampleRate=e.content;else if(this.media.state===In.allowed)switch(e.command){case"pcm":{const t=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Wn(new Int16Array(e.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:t}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===e.content&&this.media.state===In.allowed?(this.media.pcm.pipe(t.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Ln(t)})}),this.media.startRecord()):dr.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.");break;default:dr.info(e.signal)}}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}exports.MediaManager=Hn,exports.initSdk=function(t){if(xe){const e=new ke(Re({},t));vr(e.debug);const r=new Hn,n=new ji(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(be["環境錯誤(browser)"])};
|
|
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 a="object"==typeof n&&n&&n.Object===Object&&n,i=a,u="object"==typeof self&&self&&self.Object===Object&&self,s=i||u||Function("return this")(),c=s.Symbol,l=c,f=Object.prototype,h=f.hasOwnProperty,d=f.toString,v=l?l.toStringTag:void 0;var p=function(t){var e=h.call(t,v),r=t[v];try{t[v]=void 0;var n=!0}catch(t){}var o=d.call(t);return n&&(e?t[v]=r:delete t[v]),o},b=Object.prototype.toString;var g=p,y=function(t){return b.call(t)},_=c?c.toStringTag:void 0;var m=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":_&&_ in Object(t)?g(t):y(t)};var w=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},j=m,S=w;var O,x=function(t){if(!S(t))return!1;var e=j(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 N=function(t){if(null!=t){try{return A.call(t)}catch(t){}try{return t+""}catch(t){}}return""},M=x,E=C,D=w,P=N,z=/^\[object .+?Constructor\]$/,B=Function.prototype,T=Object.prototype,$=B.toString,F=T.hasOwnProperty,U=RegExp("^"+$.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var I=function(t){return!(!D(t)||E(t))&&(M(t)?U:z).test(P(t))},V=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=V(t,e);return I(r)?r:void 0},Q=q,W=function(){try{var t=Q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),L=W;var G=function(t,e,r){"__proto__"==e&&L?L(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var H=function(t,e){return t===e||t!=t&&e!=e},J=G,K=H,X=Object.prototype.hasOwnProperty;var Y=function(t,e,r){var n=t[e];X.call(t,e)&&K(n,r)&&(void 0!==r||e in t)||J(t,e,r)},Z=Y,tt=G;var et=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?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 at=function(t,e,r){return e=ot(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=ot(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),nt(t,this,u)}};var it=function(t){return function(){return t}},ut=W,st=ut?function(t,e){return ut(t,"toString",{configurable:!0,enumerable:!1,value:it(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),ft=rt,ht=at,dt=lt;var vt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},pt=x,bt=vt;var gt=function(t){return null!=t&&bt(t.length)&&!pt(t)},yt=/^(?:0|[1-9]\d*)$/;var _t=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&yt.test(t))&&t>-1&&t%1==0&&t<e},mt=H,wt=gt,jt=_t,St=w;var Ot=function(t,e){return dt(ht(t,e,ft),t+"")},xt=function(t,e,r){if(!St(r))return!1;var n=typeof e;return!!("number"==n?wt(r)&&jt(e,r.length):"string"==n&&e in r)&&mt(r[e],t)};var Rt=function(t){return Ot(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&xt(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},kt=Object.prototype;var 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 Nt=function(t){return null!=t&&"object"==typeof t},Mt=m,Et=Nt;var Dt=function(t){return Et(t)&&"[object Arguments]"==Mt(t)},Pt=Nt,zt=Object.prototype,Bt=zt.hasOwnProperty,Tt=zt.propertyIsEnumerable,$t=Dt(function(){return arguments}())?Dt:function(t){return Pt(t)&&Bt.call(t,"callee")&&!Tt.call(t,"callee")},Ft=Array.isArray,Ut=o(Ft),It={exports:{}};var Vt=function(){return!1};!function(t,e){var r=s,n=Vt,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}(It,It.exports);var qt=It.exports,Qt=m,Wt=vt,Lt=Nt,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 Ht=function(t){return Lt(t)&&Wt(t.length)&&!!Gt[Qt(t)]};var Jt=function(t){return function(e){return t(e)}},Kt={exports:{}};!function(t,e){var r=a,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n&&r.process,u=function(){try{var t=o&&o.require&&o.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=u}(Kt,Kt.exports);var Xt=Kt.exports,Yt=Ht,Zt=Jt,te=Xt&&Xt.isTypedArray,ee=te?Zt(te):Yt,re=At,ne=$t,oe=Ft,ae=qt,ie=_t,ue=ee,se=Object.prototype.hasOwnProperty;var ce=function(t,e){var r=oe(t),n=!r&&ne(t),o=!r&&!n&&ae(t),a=!r&&!n&&!o&&ue(t),i=r||n||o||a,u=i?re(t.length,String):[],s=u.length;for(var c in t)!e&&!se.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ie(c,s))||u.push(c);return u};var le=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),fe=Ct,he=le,de=Object.prototype.hasOwnProperty;var ve=ce,pe=function(t){if(!fe(t))return he(t);var e=[];for(var r in Object(t))de.call(t,r)&&"constructor"!=r&&e.push(r);return e},be=gt;var ge,ye=function(t){return be(t)?ve(t):pe(t)},_e=Y,me=et,we=Rt,je=gt,Se=Ct,Oe=ye,xe=Object.prototype.hasOwnProperty,Re=o(we(function(t,e){if(Se(e)||je(e))me(e,Oe(e),t);else for(var r in e)xe.call(e,r)&&_e(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"}(ge||(ge={}));const ke="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class Ce{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=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??!0}constructor(t){this.config=t}}var Ae=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Ne=Ae,Me=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 De=function(t,e,r){return e==e?Ee(t,e,r):Ne(t,Me,r)},Pe=m,ze=Ft,Be=Nt;var Te=function(t){return"string"==typeof t||!ze(t)&&Be(t)&&"[object String]"==Pe(t)},$e=/\s/;var Fe=function(t){for(var e=t.length;e--&&$e.test(t.charAt(e)););return e},Ue=/^\s+/;var Ie=m,Ve=Nt;var qe=function(t){return"symbol"==typeof t||Ve(t)&&"[object Symbol]"==Ie(t)},Qe=function(t){return t?t.slice(0,Fe(t)+1).replace(Ue,""):t},We=w,Le=qe,Ge=/^[-+]0x[0-9a-f]+$/i,He=/^0b[01]+$/i,Je=/^0o[0-7]+$/i,Ke=parseInt;var Xe=function(t){if("number"==typeof t)return t;if(Le(t))return NaN;if(We(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=We(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Qe(t);var r=He.test(t);return r||Je.test(t)?Ke(t.slice(2),r?2:8):Ge.test(t)?NaN:+t},Ye=1/0;var Ze=function(t){return t?(t=Xe(t))===Ye||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var tr=function(t){var e=Ze(t),r=e%1;return e==e?r?e-r:e:0};var er=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},rr=er;var nr=function(t,e){return rr(e,function(e){return t[e]})},or=ye;var ar=function(t){return null==t?[]:nr(t,or(t))},ir=o(ar),ur=De,sr=gt,cr=Te,lr=tr,fr=ar,hr=Math.max;var dr=o(function(t,e,r,n){t=sr(t)?t:fr(t),r=r&&!n?lr(r):0;var o=t.length;return r<0&&(r=hr(o+r,0)),cr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&ur(t,e,r)>-1});const vr={debug:()=>{},info:()=>{},error:()=>{},warn:()=>{},fatal:()=>{}};function pr(){return t().format("yyyy-MM-DD[T]HH:mm:ss")}function br(t){const{info:e,error:r,warn:n,debug:o,fatal:a}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0,debug:!0,fatal:!0}:"none"===t?{error:!1,warn:!1,info:!1,debug:!1,fatal:!1}:"boolean"==typeof t?{error:t,warn:t,info:t,debug:t,fatal:t}:{debug:dr(t,"debug"),fatal:dr(t,"fatal"),error:dr(t,"error"),warn:dr(t,"warn"),info:dr(t,"info")}}(t);o&&(vr.debug=(...t)=>{const e=pr();console.log(`[Aiia::debug_${e}_]`,...t)}),e&&(vr.info=(...t)=>{const e=pr();console.log(`[Aiia::info_${e}_]`,...t)}),n&&(vr.warn=(...t)=>{const e=pr();console.warn(`[Aiia::warn_${e}_]`,...t)}),r&&(vr.error=(...t)=>{const e=pr();console.error(`[Aiia::error_${e}_]`,...t)}),a&&(vr.fatal=(...t)=>{const e=pr();console.error(`[Aiia::fatal_${e}_]`,...t)})}var gr=Ft,yr=qe,_r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,mr=/^\w*$/;var wr=function(t,e){if(gr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!yr(t))||(mr.test(t)||!_r.test(t)||null!=e&&t in Object(e))},jr=q(Object,"create"),Sr=jr;var Or=function(){this.__data__=Sr?Sr(null):{},this.size=0};var xr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Rr=jr,kr=Object.prototype.hasOwnProperty;var Cr=function(t){var e=this.__data__;if(Rr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return kr.call(e,t)?e[t]:void 0},Ar=jr,Nr=Object.prototype.hasOwnProperty;var Mr=jr;var Er=Or,Dr=xr,Pr=Cr,zr=function(t){var e=this.__data__;return Ar?void 0!==e[t]:Nr.call(e,t)},Br=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 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=Er,Tr.prototype.delete=Dr,Tr.prototype.get=Pr,Tr.prototype.has=zr,Tr.prototype.set=Br;var $r=Tr;var Fr=function(){this.__data__=[],this.size=0},Ur=H;var Ir=function(t,e){for(var r=t.length;r--;)if(Ur(t[r][0],e))return r;return-1},Vr=Ir,qr=Array.prototype.splice;var Qr=Ir;var Wr=Ir;var Lr=Ir;var Gr=Fr,Hr=function(t){var e=this.__data__,r=Vr(e,t);return!(r<0)&&(r==e.length-1?e.pop():qr.call(e,r,1),--this.size,!0)},Jr=function(t){var e=this.__data__,r=Qr(e,t);return r<0?void 0:e[r][1]},Kr=function(t){return Wr(this.__data__,t)>-1},Xr=function(t,e){var r=this.__data__,n=Lr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Yr(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])}}Yr.prototype.clear=Gr,Yr.prototype.delete=Hr,Yr.prototype.get=Jr,Yr.prototype.has=Kr,Yr.prototype.set=Xr;var Zr=Yr,tn=q(s,"Map"),en=$r,rn=Zr,nn=tn;var on=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var an=function(t,e){var r=t.__data__;return on(e)?r["string"==typeof e?"string":"hash"]:r.map},un=an;var sn=an;var cn=an;var ln=an;var fn=function(){this.size=0,this.__data__={hash:new en,map:new(nn||rn),string:new en}},hn=function(t){var e=un(this,t).delete(t);return this.size-=e?1:0,e},dn=function(t){return sn(this,t).get(t)},vn=function(t){return cn(this,t).has(t)},pn=function(t,e){var r=ln(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function bn(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])}}bn.prototype.clear=fn,bn.prototype.delete=hn,bn.prototype.get=dn,bn.prototype.has=vn,bn.prototype.set=pn;var gn=bn,yn=gn;function _n(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(_n.Cache||yn),r}_n.Cache=yn;var mn=_n;var wn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,jn=/\\(\\)?/g,Sn=function(t){var e=mn(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(wn,function(t,r,n,o){e.push(n?o.replace(jn,"$1"):r||t)}),e}),On=er,xn=Ft,Rn=qe,kn=c?c.prototype:void 0,Cn=kn?kn.toString:void 0;var An=function t(e){if("string"==typeof e)return e;if(xn(e))return On(e,t)+"";if(Rn(e))return Cn?Cn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Nn=An;var Mn=Ft,En=wr,Dn=Sn,Pn=function(t){return null==t?"":Nn(t)};var zn=function(t,e){return Mn(t)?t:En(t,e)?[t]:Dn(Pn(t))},Bn=qe;var Tn=function(t){if("string"==typeof t||Bn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},$n=zn,Fn=Tn;var Un=function(t,e){for(var r=0,n=(e=$n(e,t)).length;null!=t&&r<n;)t=t[Fn(e[r++])];return r&&r==n?t:void 0},In=Un;var Vn,qn,Qn=function(t,e,r){var n=null==t?void 0:In(t,e);return void 0===n?r:n},Wn=o(Qn);function Ln(t,e,r){return Math.max(r,Math.min(t,e))}function Gn(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=Ln(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"}(Vn||(Vn={}));class Jn{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(Gn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{vr.error("pause speech fail",t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{vr.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;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"}(qn||(qn={}));class Xn{_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 e.Subject,this.pcmSub=new e.Subject,this.destory=new e.Subject,this.state=qn.padding}async init(t){if(this.destory.closed)throw new Error(ge["實例已摧毀"]);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=qn.rejected,new Error(ge["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw vr.fatal(t),this.state=qn.loadfail,new Error(ge["Worklet模組載入失敗"])}this.state=qn.allowed,this.audioManager=new Jn(this.audioCtx),this.vadManager=new Kn(e,this.audioCtx,this.pcmSub)}addAudioQueue(t){const e=Wn(t,"buffer",void 0),r=Wn(t,"float32",void 0),n=Wn(t,"int16",void 0),o=Wn(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 Yn=Zr;var Zn=Zr,to=tn,eo=gn;var ro=Zr,no=function(){this.__data__=new Yn,this.size=0},oo=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},ao=function(t){return this.__data__.get(t)},io=function(t){return this.__data__.has(t)},uo=function(t,e){var r=this.__data__;if(r instanceof Zn){var n=r.__data__;if(!to||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new eo(n)}return r.set(t,e),this.size=r.size,this};function so(t){var e=this.__data__=new ro(t);this.size=e.size}so.prototype.clear=no,so.prototype.delete=oo,so.prototype.get=ao,so.prototype.has=io,so.prototype.set=uo;var co=so;var lo=gn,fo=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ho=function(t){return this.__data__.has(t)};function vo(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new lo;++e<r;)this.add(t[e])}vo.prototype.add=vo.prototype.push=fo,vo.prototype.has=ho;var po=vo,bo=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 yo=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 po: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(!bo(e,function(t,e){if(!go(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var _o=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var mo=s.Uint8Array,wo=H,jo=yo,So=_o,Oo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},xo=c?c.prototype:void 0,Ro=xo?xo.valueOf:void 0;var ko=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 mo(t),new mo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return wo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=So;case"[object Set]":var s=1&n;if(u||(u=Oo),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=jo(u(t),u(e),n,o,a,i);return i.delete(t),l;case"[object Symbol]":if(Ro)return Ro.call(t)==Ro.call(e)}return!1};var Co=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Ao=Co,No=Ft;var Mo=function(t,e,r){var n=e(t);return No(t)?n:Ao(n,r(t))};var Eo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Do=function(){return[]},Po=Object.prototype.propertyIsEnumerable,zo=Object.getOwnPropertySymbols,Bo=Mo,To=zo?function(t){return null==t?[]:(t=Object(t),Eo(zo(t),function(e){return Po.call(t,e)}))}:Do,$o=ye;var Fo=function(t){return Bo(t,$o,To)},Uo=Object.prototype.hasOwnProperty;var Io=function(t,e,r,n,o,a){var i=1&r,u=Fo(t),s=u.length;if(s!=Fo(e).length&&!i)return!1;for(var c=s;c--;){var l=u[c];if(!(i?l in e:Uo.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 g=i?n(b,p,l,e,t,a):n(p,b,l,t,e,a);if(!(void 0===g?p===b||o(p,b,r,n,a):g)){d=!1;break}v||(v="constructor"==l)}if(d&&!v){var y=t.constructor,_=e.constructor;y==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof _&&_ instanceof _||(d=!1)}return a.delete(t),a.delete(e),d},Vo=q(s,"DataView"),qo=tn,Qo=q(s,"Promise"),Wo=q(s,"Set"),Lo=q(s,"WeakMap"),Go=m,Ho=N,Jo="[object Map]",Ko="[object Promise]",Xo="[object Set]",Yo="[object WeakMap]",Zo="[object DataView]",ta=Ho(Vo),ea=Ho(qo),ra=Ho(Qo),na=Ho(Wo),oa=Ho(Lo),aa=Go;(Vo&&aa(new Vo(new ArrayBuffer(1)))!=Zo||qo&&aa(new qo)!=Jo||Qo&&aa(Qo.resolve())!=Ko||Wo&&aa(new Wo)!=Xo||Lo&&aa(new Lo)!=Yo)&&(aa=function(t){var e=Go(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ho(r):"";if(n)switch(n){case ta:return Zo;case ea:return Jo;case ra:return Ko;case na:return Xo;case oa:return Yo}return e});var ia=co,ua=yo,sa=ko,ca=Io,la=aa,fa=Ft,ha=qt,da=ee,va="[object Arguments]",pa="[object Array]",ba="[object Object]",ga=Object.prototype.hasOwnProperty;var ya=function(t,e,r,n,o,a){var i=fa(t),u=fa(e),s=i?pa:la(t),c=u?pa:la(e),l=(s=s==va?ba:s)==ba,f=(c=c==va?ba:c)==ba,h=s==c;if(h&&ha(t)){if(!ha(e))return!1;i=!0,l=!1}if(h&&!l)return a||(a=new ia),i||da(t)?ua(t,e,r,n,o,a):sa(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 ia),o(p,b,r,n,a)}}return!!h&&(a||(a=new ia),ca(t,e,r,n,o,a))},_a=Nt;var ma=function t(e,r,n,o,a){return e===r||(null==e||null==r||!_a(e)&&!_a(r)?e!=e&&r!=r:ya(e,r,n,o,t,a))},wa=co,ja=ma;var Sa=w;var Oa=function(t){return t==t&&!Sa(t)},xa=Oa,Ra=ye;var ka=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Ca=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 wa;if(n)var h=n(c,l,s,t,e,f);if(!(void 0===h?ja(l,c,3,n,f):h))return!1}}return!0},Aa=function(t){for(var e=Ra(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xa(o)]}return e},Na=ka;var Ma=zn,Ea=$t,Da=Ft,Pa=_t,za=vt,Ba=Tn;var Ta=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=Ba(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&za(o)&&Pa(i,o)&&(Da(t)||Ea(t))};var Fa=ma,Ua=Qn,Ia=function(t,e){return null!=t&&$a(t,e,Ta)},Va=wr,qa=Oa,Qa=ka,Wa=Tn;var La=Un;var Ga=function(t){return function(e){return null==e?void 0:e[t]}},Ha=function(t){return function(e){return La(e,t)}},Ja=wr,Ka=Tn;var Xa=function(t){var e=Aa(t);return 1==e.length&&e[0][2]?Na(e[0][0],e[0][1]):function(r){return r===t||Ca(r,t,e)}},Ya=function(t,e){return Va(t)&&qa(e)?Qa(Wa(t),e):function(r){var n=Ua(r,t);return void 0===n&&n===e?Ia(r,t):Fa(e,n,3)}},Za=rt,ti=Ft,ei=function(t){return Ja(t)?Ga(Ka(t)):Ha(t)};var ri=function(t){return"function"==typeof t?t:null==t?Za:"object"==typeof t?ti(t)?Ya(t[0],t[1]):Xa(t):ei(t)};var ni=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}}(),oi=ye;var ai=gt;var ii=function(t,e){return function(r,n){if(null==r)return r;if(!ai(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&&ni(t,e,oi)}),ui=gt;var si=er,ci=ri,li=function(t,e){var r=-1,n=ui(t)?Array(t.length):[];return ii(t,function(t,o,a){n[++r]=e(t,o,a)}),n},fi=Ft;var hi=o(function(t,e){return(fi(t)?si:li)(t,ci(e))}),di=ri,vi=gt,pi=ye;var bi=function(t){return function(e,r,n){var o=Object(e);if(!vi(e)){var a=di(r);e=pi(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=Ae,yi=ri,_i=tr,mi=Math.max;var wi,ji=o(bi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:_i(r);return o<0&&(o=mi(n+o,0)),gi(t,yi(e),o)}));class Si{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,Re({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()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(wi||(wi={}));class Oi{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(t,r){this.config=t,this.media=r,this.layoutSub=new e.Subject,this.projectsSub=new e.Subject,this.destorySub=new e.Subject,this.aiiaSubtitleSub=new e.Subject,this.userSubtitleSub=new e.Subject,this.cloudSampleRate=16e3,this.channelState={proxy:!1,cloud:!1},this.chat=new Si(t)}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=ji(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):(this.projectsSub.next(e),vr.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!==Wn(e,"signal")?this.behavior(e):Ut(e)?hi(e,this.behavior):hi(ir(e),this.behavior)}catch(t){vr.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=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}(Gn(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"===Wn(t,"content")&&(this.channelState.cloud=!0,this.channelCheck());break;case"agent":{const e=Wn(t,"content.function_result.response");e&&this.aiiaSubtitleSub.next(e);break}case"asr":if("ASR"===Wn(t,"content.function_type")){const e=Wn(t,"content.function_result.result");e&&this.userSubtitleSub.next(e)}break;default:vr.debug(t.signal)}}channelCheck(){const{proxy:t,cloud:r}=this.channelState;t&&r&&this.media.state===qn.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}),this.media.pcm.pipe(e.takeUntil(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Hn(t)})}),this.media.startRecord(),vr.debug("Channel, Cloud and Media are ready.")):t&&r&&this.media.state!==qn.allowed&&vr.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=Xn,exports.initSdk=function(t){if(ke){const e=new Ce(Re({},t));br(e.debug);const r=new Xn,n=new Oi(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(ge["環境錯誤(browser)"])};
|
package/dist/browser.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { Observable } from 'rxjs';
|
|
|
7
7
|
import { Server } from 'http';
|
|
8
8
|
import { Server as Server_2 } from 'https';
|
|
9
9
|
import { ServerResponse } from 'http';
|
|
10
|
-
import { Subject } from 'rxjs';
|
|
11
10
|
|
|
12
11
|
declare class AiiaConfig {
|
|
13
12
|
private config;
|
|
@@ -24,11 +23,11 @@ declare class AiiaConfig {
|
|
|
24
23
|
api: string;
|
|
25
24
|
socket: string;
|
|
26
25
|
};
|
|
27
|
-
get debug(): boolean | "all" | "none" | ("info" | "error" | "warn")[]
|
|
26
|
+
get debug(): boolean | "all" | "none" | ("info" | "error" | "warn" | "debug" | "fatal")[];
|
|
28
27
|
constructor(config: InitOptions);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
declare interface AiiaProjectItem {
|
|
30
|
+
export declare interface AiiaProjectItem {
|
|
32
31
|
id: string;
|
|
33
32
|
name: string;
|
|
34
33
|
}
|
|
@@ -40,7 +39,17 @@ declare class AiiaSdk {
|
|
|
40
39
|
private destorySub;
|
|
41
40
|
private projectsSub;
|
|
42
41
|
private layoutSub;
|
|
42
|
+
private aiiaSubtitleSub;
|
|
43
|
+
private userSubtitleSub;
|
|
43
44
|
private cloudSampleRate;
|
|
45
|
+
private channelState;
|
|
46
|
+
/**
|
|
47
|
+
* [zh]
|
|
48
|
+
* 控制畫面 Layout
|
|
49
|
+
*
|
|
50
|
+
* [en]
|
|
51
|
+
* Control Layout
|
|
52
|
+
*/
|
|
44
53
|
get layout(): Observable< {
|
|
45
54
|
type: "mount";
|
|
46
55
|
id: LayoutID;
|
|
@@ -56,9 +65,36 @@ declare class AiiaSdk {
|
|
|
56
65
|
type: "unmount";
|
|
57
66
|
id: LayoutID;
|
|
58
67
|
}>;
|
|
68
|
+
/**
|
|
69
|
+
* [zh]
|
|
70
|
+
* 若沒有明確指定 Project ID 時,請訂閱此物件
|
|
71
|
+
*
|
|
72
|
+
* [en]
|
|
73
|
+
* If no Project ID is explicitly specified, please subscribe to this object
|
|
74
|
+
*/
|
|
59
75
|
get projects(): Observable<AiiaProjectItem[]>;
|
|
60
76
|
/**
|
|
61
77
|
* [zh]
|
|
78
|
+
* Aiia 的回應字幕
|
|
79
|
+
*
|
|
80
|
+
* [en]
|
|
81
|
+
* Aiia's subtitle of response
|
|
82
|
+
*/
|
|
83
|
+
get aiiaSubtitle(): Observable<string>;
|
|
84
|
+
/**
|
|
85
|
+
* [zh]
|
|
86
|
+
* 使用者語音輸入的字幕
|
|
87
|
+
*
|
|
88
|
+
* [en]
|
|
89
|
+
* User's subtitle of voice input
|
|
90
|
+
*/
|
|
91
|
+
get userSubtitle(): Observable<string>;
|
|
92
|
+
/**
|
|
93
|
+
* [zh]
|
|
94
|
+
* 設定音量
|
|
95
|
+
*
|
|
96
|
+
* [en]
|
|
97
|
+
* Setting volume
|
|
62
98
|
*
|
|
63
99
|
* @example```js
|
|
64
100
|
* const sdk = new AiiaSdk()
|
|
@@ -70,32 +106,22 @@ declare class AiiaSdk {
|
|
|
70
106
|
get volume(): number;
|
|
71
107
|
constructor(config: AiiaConfig, media: MediaManager);
|
|
72
108
|
start(): void;
|
|
109
|
+
/**
|
|
110
|
+
* [zh]
|
|
111
|
+
* 若沒有明確指定 Project 時,請呼叫此方法
|
|
112
|
+
*
|
|
113
|
+
* [en]
|
|
114
|
+
* If no Project is explicitly specified, please execute this method
|
|
115
|
+
* @param project_id
|
|
116
|
+
*/
|
|
73
117
|
chooseProject(project_id: string): void;
|
|
74
118
|
private cloudToObj;
|
|
75
119
|
private behavior;
|
|
120
|
+
private channelCheck;
|
|
76
121
|
onDestory(): void;
|
|
77
122
|
}
|
|
78
123
|
|
|
79
|
-
declare
|
|
80
|
-
audioContext: AudioContext;
|
|
81
|
-
readonly type = "audio";
|
|
82
|
-
private currentNode;
|
|
83
|
-
private bufferQueue;
|
|
84
|
-
private gainNode;
|
|
85
|
-
set volume(val: number);
|
|
86
|
-
get volume(): number;
|
|
87
|
-
constructor(audioContext: AudioContext);
|
|
88
|
-
addBuffer(buffer: AudioBuffer): void;
|
|
89
|
-
addBufferByFloat32(float32: Float32Array, numberOfChannels?: number): void;
|
|
90
|
-
addBufferByInt16(int16: Int16Array, numberOfChannels?: number): void;
|
|
91
|
-
startSpeech(): void;
|
|
92
|
-
pauseSpeech(): void;
|
|
93
|
-
resumeSpeech(): void;
|
|
94
|
-
nextSpeech(): void;
|
|
95
|
-
stopSpeech(): void;
|
|
96
|
-
private clearNode;
|
|
97
|
-
private continue;
|
|
98
|
-
}
|
|
124
|
+
export declare type BrowserInitOptions = Omit<InitOptions, "webserver" | "port">;
|
|
99
125
|
|
|
100
126
|
declare interface InitOptions {
|
|
101
127
|
/**
|
|
@@ -163,20 +189,20 @@ declare interface InitOptions {
|
|
|
163
189
|
* [en]
|
|
164
190
|
* Switch message(info, error, warn) dispaly, default: true
|
|
165
191
|
*/
|
|
166
|
-
debug?: boolean | "all" | "none" | ("info" | "error" | "warn")[];
|
|
192
|
+
debug?: boolean | "all" | "none" | ("info" | "error" | "warn" | "debug" | "fatal")[];
|
|
167
193
|
}
|
|
168
194
|
|
|
169
|
-
export declare function initSdk(options?:
|
|
195
|
+
export declare function initSdk(options?: BrowserInitOptions): AiiaSdk;
|
|
170
196
|
|
|
171
197
|
declare type LayoutID = string | number;
|
|
172
198
|
|
|
173
199
|
export declare class MediaManager {
|
|
174
200
|
private _state;
|
|
175
201
|
private stateSub;
|
|
176
|
-
audioCtx
|
|
177
|
-
audioManager
|
|
178
|
-
vadManager
|
|
179
|
-
destory
|
|
202
|
+
private audioCtx?;
|
|
203
|
+
private audioManager?;
|
|
204
|
+
private vadManager?;
|
|
205
|
+
private destory;
|
|
180
206
|
private pcmSub;
|
|
181
207
|
get sampleRate(): number;
|
|
182
208
|
get pcm(): Observable<Float32Array<ArrayBufferLike>>;
|
|
@@ -210,18 +236,4 @@ declare enum MediaStateEnum {
|
|
|
210
236
|
allowed = 3
|
|
211
237
|
}
|
|
212
238
|
|
|
213
|
-
declare class VoiceDetectManager {
|
|
214
|
-
stream: MediaStream;
|
|
215
|
-
private audioContext;
|
|
216
|
-
readonly type = "vad";
|
|
217
|
-
private workletNode?;
|
|
218
|
-
private source?;
|
|
219
|
-
private isRecording;
|
|
220
|
-
private pcmSub;
|
|
221
|
-
get pcm(): Observable<Float32Array<ArrayBufferLike>>;
|
|
222
|
-
constructor(stream: MediaStream, audioContext: AudioContext);
|
|
223
|
-
startRecord(): Promise<void>;
|
|
224
|
-
stopRecord(): void;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
239
|
export { }
|
package/dist/browser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Subject as t,takeUntil as e,fromEvent as r,take as n}from"rxjs";import{io as o}from"socket.io-client";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u="object"==typeof a&&a&&a.Object===Object&&a,s=u,c="object"==typeof self&&self&&self.Object===Object&&self,f=s||c||Function("return this")(),l=f.Symbol,h=l,d=Object.prototype,v=d.hasOwnProperty,p=d.toString,b=h?h.toStringTag:void 0;var y=function(t){var e=v.call(t,b),r=t[b];try{t[b]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[b]=r:delete t[b]),o},g=Object.prototype.toString;var m=y,_=function(t){return g.call(t)},w=l?l.toStringTag:void 0;var j=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?m(t):_(t)};var O=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},S=j,R=O;var x,k=function(t){if(!R(t))return!1;var e=S(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},C=f["__core-js_shared__"],A=(x=/[^.]+$/.exec(C&&C.keys&&C.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"";var N=function(t){return!!A&&A in t},E=Function.prototype.toString;var M=function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""},z=k,D=N,P=O,B=M,T=/^\[object .+?Constructor\]$/,F=Function.prototype,$=Object.prototype,I=F.toString,V=$.hasOwnProperty,Q=RegExp("^"+I.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var U=function(t){return!(!P(t)||D(t))&&(z(t)?Q:T).test(B(t))},W=function(t,e){return null==t?void 0:t[e]};var q=function(t,e){var r=W(t,e);return U(r)?r:void 0},L=q,G=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=G;var H=function(t,e,r){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var K=function(t,e){return t===e||t!=t&&e!=e},X=H,Y=K,Z=Object.prototype.hasOwnProperty;var tt=function(t,e,r){var n=t[e];Z.call(t,e)&&Y(n,r)&&(void 0!==r||e in t)||X(t,e,r)},et=tt,rt=H;var nt=function(t,e,r,n){var o=!r;r||(r={});for(var a=-1,i=e.length;++a<i;){var u=e[a],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?rt(r,u,s):et(r,u,s)}return r};var ot=function(t){return t};var at=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},it=Math.max;var ut=function(t,e,r){return e=it(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=it(n.length-e,0),i=Array(a);++o<a;)i[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(i),at(t,this,u)}};var st=function(t){return function(){return t}},ct=G,ft=ct?function(t,e){return ct(t,"toString",{configurable:!0,enumerable:!1,value:st(e),writable:!0})}:ot,lt=Date.now;var ht=function(t){var e=0,r=0;return function(){var n=lt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ft),dt=ot,vt=ut,pt=ht;var bt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},yt=k,gt=bt;var mt=function(t){return null!=t&>(t.length)&&!yt(t)},_t=/^(?:0|[1-9]\d*)$/;var wt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&_t.test(t))&&t>-1&&t%1==0&&t<e},jt=K,Ot=mt,St=wt,Rt=O;var xt=function(t,e){return pt(vt(t,e,dt),t+"")},kt=function(t,e,r){if(!Rt(r))return!1;var n=typeof e;return!!("number"==n?Ot(r)&&St(e,r.length):"string"==n&&e in r)&&jt(r[e],t)};var Ct=function(t){return xt(function(e,r){var n=-1,o=r.length,a=o>1?r[o-1]:void 0,i=o>2?r[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&kt(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},At=Object.prototype;var Nt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||At)};var Et=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Mt=function(t){return null!=t&&"object"==typeof t},zt=j,Dt=Mt;var Pt=function(t){return Dt(t)&&"[object Arguments]"==zt(t)},Bt=Mt,Tt=Object.prototype,Ft=Tt.hasOwnProperty,$t=Tt.propertyIsEnumerable,It=Pt(function(){return arguments}())?Pt:function(t){return Bt(t)&&Ft.call(t,"callee")&&!$t.call(t,"callee")},Vt=Array.isArray,Qt=i(Vt),Ut={exports:{}};var Wt=function(){return!1};!function(t,e){var r=f,n=Wt,o=e&&!e.nodeType&&e,a=o&&t&&!t.nodeType&&t,i=a&&a.exports===o?r.Buffer:void 0,u=(i?i.isBuffer:void 0)||n;t.exports=u}(Ut,Ut.exports);var qt=Ut.exports,Lt=j,Gt=bt,Jt=Mt,Ht={};Ht["[object Float32Array]"]=Ht["[object Float64Array]"]=Ht["[object Int8Array]"]=Ht["[object Int16Array]"]=Ht["[object Int32Array]"]=Ht["[object Uint8Array]"]=Ht["[object Uint8ClampedArray]"]=Ht["[object Uint16Array]"]=Ht["[object Uint32Array]"]=!0,Ht["[object Arguments]"]=Ht["[object Array]"]=Ht["[object ArrayBuffer]"]=Ht["[object Boolean]"]=Ht["[object DataView]"]=Ht["[object Date]"]=Ht["[object Error]"]=Ht["[object Function]"]=Ht["[object Map]"]=Ht["[object Number]"]=Ht["[object Object]"]=Ht["[object RegExp]"]=Ht["[object Set]"]=Ht["[object String]"]=Ht["[object WeakMap]"]=!1;var Kt=function(t){return Jt(t)&&Gt(t.length)&&!!Ht[Lt(t)]};var Xt=function(t){return function(e){return t(e)}},Yt={exports:{}};!function(t,e){var r=u,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,a=o&&o.exports===n&&r.process,i=function(){try{var t=o&&o.require&&o.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=i}(Yt,Yt.exports);var Zt=Yt.exports,te=Kt,ee=Xt,re=Zt&&Zt.isTypedArray,ne=re?ee(re):te,oe=Et,ae=It,ie=Vt,ue=qt,se=wt,ce=ne,fe=Object.prototype.hasOwnProperty;var le=function(t,e){var r=ie(t),n=!r&&ae(t),o=!r&&!n&&ue(t),a=!r&&!n&&!o&&ce(t),i=r||n||o||a,u=i?oe(t.length,String):[],s=u.length;for(var c in t)!e&&!fe.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||se(c,s))||u.push(c);return u};var he=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),de=Nt,ve=he,pe=Object.prototype.hasOwnProperty;var be=le,ye=function(t){if(!de(t))return ve(t);var e=[];for(var r in Object(t))pe.call(t,r)&&"constructor"!=r&&e.push(r);return e},ge=mt;var me,_e=function(t){return ge(t)?be(t):ye(t)},we=tt,je=nt,Oe=Ct,Se=mt,Re=Nt,xe=_e,ke=Object.prototype.hasOwnProperty,Ce=i(Oe(function(t,e){if(Re(e)||Se(e))je(e,xe(e),t);else for(var r in e)ke.call(e,r)&&we(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(me||(me={}));const Ae="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class Ne{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=Ce({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Ce({},t,{specific:!0})}get endPoint(){return this.environment,{api:"https://aiia-content-management-dev-21193779403.asia-east1.run.app",socket:"wss://graphen-agentic-workflow-dev-21193779403.asia-east1.run.app"}}get debug(){return this.config.debug}constructor(t){this.config=t}}var Ee=function(t,e,r,n){for(var o=t.length,a=r+(n?1:-1);n?a--:++a<o;)if(e(t[a],a,t))return a;return-1};var Me=Ee,ze=function(t){return t!=t},De=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var Pe=function(t,e,r){return e==e?De(t,e,r):Me(t,ze,r)},Be=j,Te=Vt,Fe=Mt;var $e=function(t){return"string"==typeof t||!Te(t)&&Fe(t)&&"[object String]"==Be(t)},Ie=/\s/;var Ve=function(t){for(var e=t.length;e--&&Ie.test(t.charAt(e)););return e},Qe=/^\s+/;var Ue=j,We=Mt;var qe=function(t){return"symbol"==typeof t||We(t)&&"[object Symbol]"==Ue(t)},Le=function(t){return t?t.slice(0,Ve(t)+1).replace(Qe,""):t},Ge=O,Je=qe,He=/^[-+]0x[0-9a-f]+$/i,Ke=/^0b[01]+$/i,Xe=/^0o[0-7]+$/i,Ye=parseInt;var Ze=function(t){if("number"==typeof t)return t;if(Je(t))return NaN;if(Ge(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Ge(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Le(t);var r=Ke.test(t);return r||Xe.test(t)?Ye(t.slice(2),r?2:8):He.test(t)?NaN:+t},tr=1/0;var er=function(t){return t?(t=Ze(t))===tr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var rr=function(t){var e=er(t),r=e%1;return e==e?r?e-r:e:0};var nr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},or=nr;var ar=function(t,e){return or(e,function(e){return t[e]})},ir=_e;var ur=function(t){return null==t?[]:ar(t,ir(t))},sr=i(ur),cr=Pe,fr=mt,lr=$e,hr=rr,dr=ur,vr=Math.max;var pr=i(function(t,e,r,n){t=fr(t)?t:dr(t),r=r&&!n?hr(r):0;var o=t.length;return r<0&&(r=vr(o+r,0)),lr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&cr(t,e,r)>-1});const br={info:()=>{},error:()=>{},warn:()=>{}};function yr(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:pr(t,"error"),warn:pr(t,"warn"),info:pr(t,"info")}}(t);e&&(br.info=console.log),r&&(br.error=console.error),n&&(br.warn=console.warn)}var gr=Vt,mr=qe,_r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wr=/^\w*$/;var jr=function(t,e){if(gr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!mr(t))||(wr.test(t)||!_r.test(t)||null!=e&&t in Object(e))},Or=q(Object,"create"),Sr=Or;var Rr=function(){this.__data__=Sr?Sr(null):{},this.size=0};var xr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},kr=Or,Cr=Object.prototype.hasOwnProperty;var Ar=function(t){var e=this.__data__;if(kr){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Cr.call(e,t)?e[t]:void 0},Nr=Or,Er=Object.prototype.hasOwnProperty;var Mr=Or;var zr=Rr,Dr=xr,Pr=Ar,Br=function(t){var e=this.__data__;return Nr?void 0!==e[t]:Er.call(e,t)},Tr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Mr&&void 0===e?"__lodash_hash_undefined__":e,this};function Fr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Fr.prototype.clear=zr,Fr.prototype.delete=Dr,Fr.prototype.get=Pr,Fr.prototype.has=Br,Fr.prototype.set=Tr;var $r=Fr;var Ir=function(){this.__data__=[],this.size=0},Vr=K;var Qr=function(t,e){for(var r=t.length;r--;)if(Vr(t[r][0],e))return r;return-1},Ur=Qr,Wr=Array.prototype.splice;var qr=Qr;var Lr=Qr;var Gr=Qr;var Jr=Ir,Hr=function(t){var e=this.__data__,r=Ur(e,t);return!(r<0)&&(r==e.length-1?e.pop():Wr.call(e,r,1),--this.size,!0)},Kr=function(t){var e=this.__data__,r=qr(e,t);return r<0?void 0:e[r][1]},Xr=function(t){return Lr(this.__data__,t)>-1},Yr=function(t,e){var r=this.__data__,n=Gr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Zr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Zr.prototype.clear=Jr,Zr.prototype.delete=Hr,Zr.prototype.get=Kr,Zr.prototype.has=Xr,Zr.prototype.set=Yr;var tn=Zr,en=q(f,"Map"),rn=$r,nn=tn,on=en;var an=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var un=function(t,e){var r=t.__data__;return an(e)?r["string"==typeof e?"string":"hash"]:r.map},sn=un;var cn=un;var fn=un;var ln=un;var hn=function(){this.size=0,this.__data__={hash:new rn,map:new(on||nn),string:new rn}},dn=function(t){var e=sn(this,t).delete(t);return this.size-=e?1:0,e},vn=function(t){return cn(this,t).get(t)},pn=function(t){return fn(this,t).has(t)},bn=function(t,e){var r=ln(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function yn(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}yn.prototype.clear=hn,yn.prototype.delete=dn,yn.prototype.get=vn,yn.prototype.has=pn,yn.prototype.set=bn;var gn=yn,mn=gn;function _n(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var i=t.apply(this,n);return r.cache=a.set(o,i)||a,i};return r.cache=new(_n.Cache||mn),r}_n.Cache=mn;var wn=_n;var jn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,On=/\\(\\)?/g,Sn=function(t){var e=wn(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(jn,function(t,r,n,o){e.push(n?o.replace(On,"$1"):r||t)}),e}),Rn=nr,xn=Vt,kn=qe,Cn=l?l.prototype:void 0,An=Cn?Cn.toString:void 0;var Nn=function t(e){if("string"==typeof e)return e;if(xn(e))return Rn(e,t)+"";if(kn(e))return An?An.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},En=Nn;var Mn=Vt,zn=jr,Dn=Sn,Pn=function(t){return null==t?"":En(t)};var Bn=function(t,e){return Mn(t)?t:zn(t,e)?[t]:Dn(Pn(t))},Tn=qe;var Fn=function(t){if("string"==typeof t||Tn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},$n=Bn,In=Fn;var Vn=function(t,e){for(var r=0,n=(e=$n(e,t)).length;null!=t&&r<n;)t=t[In(e[r++])];return r&&r==n?t:void 0},Qn=Vn;var Un,Wn,qn=function(t,e,r){var n=null==t?void 0:Qn(t,e);return void 0===n?r:n},Ln=i(qn);function Gn(t,e,r){return Math.max(r,Math.min(t,e))}function Jn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=e.getInt16(2*n,!0)/32768;r.push(t)}return new Float32Array(r)}function Hn(t){const e=new DataView(t.buffer),r=[];for(let n=0;n<t.length;n++){const t=Gn(32768*e.getFloat32(4*n,!0),32767,-32768);r.push(t)}return r}!function(t){t[t.unknow=0]="unknow",t[t.allowed=1]="allowed",t[t.rejected=2]="rejected"}(Un||(Un={}));class Kn{audioContext;type="audio";currentNode;bufferQueue;gainNode;set volume(t){t<0&&(t=0),t>100&&(t=100),this.gainNode.gain.value=t/100}get volume(){return Math.round(100*this.gainNode.gain.value)}constructor(t){this.audioContext=t,this.bufferQueue=[],this.currentNode=null,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}addBuffer(t){this.bufferQueue.push(t)}addBufferByFloat32(t,e=1){const r=t.length,n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(e,r,n),a=t.slice();for(let t=0;t<e;t++)o.copyToChannel(a,t);this.addBuffer(o)}addBufferByInt16(t,e=1){this.addBufferByFloat32(Jn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{br.error("[ERROR]: pause speech fail"),br.error(t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{br.error("[ERROR]: resume speech fail"),br.error(t)})}nextSpeech(){this.bufferQueue.length>0&&(this.clearNode(),this.continue())}stopSpeech(){this.bufferQueue=[],this.clearNode()}clearNode(){this.currentNode&&(this.currentNode.onended=function(){},this.currentNode.stop(),this.currentNode.disconnect(),this.currentNode=null)}continue(){const t=this.bufferQueue.shift();if(t){this.currentNode=this.audioContext.createBufferSource(),this.currentNode.buffer=t,this.currentNode.connect(this.gainNode);const e=this.continue.bind(this);this.currentNode.onended=e,this.currentNode.start()}else this.clearNode()}}class Xn{stream;audioContext;type="vad";workletNode;source;isRecording=!1;pcmSub;get pcm(){return this.pcmSub.asObservable()}constructor(e,r){this.stream=e,this.audioContext=r,this.pcmSub=new t}async startRecord(){this.isRecording||(this.source=this.audioContext.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.audioContext,"aiia-vad"),this.source.connect(this.workletNode),this.workletNode.port.onmessage=t=>{const{float32:e,energy:r}=t.data;e&&this.pcmSub.next(new Float32Array(e))},this.isRecording=!0)}stopRecord(){this.isRecording&&(this.workletNode&&(this.workletNode.port.onmessage=null,this.workletNode.disconnect()),this.source&&this.source.disconnect(),this.isRecording=!1)}}!function(t){t[t.padding=0]="padding",t[t.rejected=1]="rejected",t[t.loadfail=2]="loadfail",t[t.allowed=3]="allowed"}(Wn||(Wn={}));class Yn{_state;stateSub;audioCtx;audioManager;vadManager;destory;pcmSub;get sampleRate(){return this.audioCtx?this.audioCtx.sampleRate:16e3}get pcm(){return this.pcmSub.asObservable()}get state(){return this._state}set state(t){t!==this._state&&(this._state=t,this.stateSub.next(t))}get stateObs(){return this.stateSub.asObservable()}constructor(){this.stateSub=new t,this.pcmSub=new t,this.destory=new t,this.state=Wn.padding}async init(t){if(this.destory.closed)throw new Error(me["實例已摧毀"]);const r=await async function(t){try{return await navigator.mediaDevices.getUserMedia(t)}catch(t){return null}}({audio:{echoCancellation:!0,noiseSuppression:!0}});if(null===r)throw this.state=Wn.rejected,new Error(me["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw br.error(t),this.state=Wn.loadfail,new Error(me["Worklet模組載入失敗"])}this.state=Wn.allowed,this.audioManager=new Kn(this.audioCtx),this.vadManager=new Xn(r,this.audioCtx),this.vadManager.pcm.pipe(e(this.destory)).subscribe(t=>{this.pcmSub.next(t)})}addAudioQueue(t){const e=Ln(t,"buffer",void 0),r=Ln(t,"float32",void 0),n=Ln(t,"int16",void 0),o=Ln(t,"numberOfChannels",void 0);e?this.audioManager?.addBuffer(e):r?this.audioManager?.addBufferByFloat32(r,o):n&&this.audioManager?.addBufferByInt16(n,o)}playAudio(){this.audioManager?.startSpeech()}stopAudio(){this.audioManager?.stopSpeech()}startRecord(){this.vadManager?.startRecord()}stopRecord(){this.vadManager?.stopRecord()}setVolume(t){this.audioManager&&(this.audioManager.volume=t)}getVolume(){return this.audioManager?this.audioManager.volume:0}onDestory(){this.audioCtx.close(),this.destory.next(),this.destory.complete()}}var Zn=tn;var to=tn,eo=en,ro=gn;var no=tn,oo=function(){this.__data__=new Zn,this.size=0},ao=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},io=function(t){return this.__data__.get(t)},uo=function(t){return this.__data__.has(t)},so=function(t,e){var r=this.__data__;if(r instanceof to){var n=r.__data__;if(!eo||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new ro(n)}return r.set(t,e),this.size=r.size,this};function co(t){var e=this.__data__=new no(t);this.size=e.size}co.prototype.clear=oo,co.prototype.delete=ao,co.prototype.get=io,co.prototype.has=uo,co.prototype.set=so;var fo=co;var lo=gn,ho=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vo=function(t){return this.__data__.has(t)};function po(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new lo;++e<r;)this.add(t[e])}po.prototype.add=po.prototype.push=ho,po.prototype.has=vo;var bo=po,yo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},go=function(t,e){return t.has(e)};var mo=function(t,e,r,n,o,a){var i=1&r,u=t.length,s=e.length;if(u!=s&&!(i&&s>u))return!1;var c=a.get(t),f=a.get(e);if(c&&f)return c==e&&f==t;var l=-1,h=!0,d=2&r?new bo:void 0;for(a.set(t,e),a.set(e,t);++l<u;){var v=t[l],p=e[l];if(n)var b=i?n(p,v,l,e,t,a):n(v,p,l,t,e,a);if(void 0!==b){if(b)continue;h=!1;break}if(d){if(!yo(e,function(t,e){if(!go(d,e)&&(v===t||o(v,t,r,n,a)))return d.push(e)})){h=!1;break}}else if(v!==p&&!o(v,p,r,n,a)){h=!1;break}}return a.delete(t),a.delete(e),h};var _o=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var wo=f.Uint8Array,jo=K,Oo=mo,So=_o,Ro=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},xo=l?l.prototype:void 0,ko=xo?xo.valueOf:void 0;var Co=function(t,e,r,n,o,a,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!a(new wo(t),new wo(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return jo(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=So;case"[object Set]":var s=1&n;if(u||(u=Ro),t.size!=e.size&&!s)return!1;var c=i.get(t);if(c)return c==e;n|=2,i.set(t,e);var f=Oo(u(t),u(e),n,o,a,i);return i.delete(t),f;case"[object Symbol]":if(ko)return ko.call(t)==ko.call(e)}return!1};var Ao=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},No=Ao,Eo=Vt;var Mo=function(t,e,r){var n=e(t);return Eo(t)?n:No(n,r(t))};var zo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Do=function(){return[]},Po=Object.prototype.propertyIsEnumerable,Bo=Object.getOwnPropertySymbols,To=Mo,Fo=Bo?function(t){return null==t?[]:(t=Object(t),zo(Bo(t),function(e){return Po.call(t,e)}))}:Do,$o=_e;var Io=function(t){return To(t,$o,Fo)},Vo=Object.prototype.hasOwnProperty;var Qo=function(t,e,r,n,o,a){var i=1&r,u=Io(t),s=u.length;if(s!=Io(e).length&&!i)return!1;for(var c=s;c--;){var f=u[c];if(!(i?f in e:Vo.call(e,f)))return!1}var l=a.get(t),h=a.get(e);if(l&&h)return l==e&&h==t;var d=!0;a.set(t,e),a.set(e,t);for(var v=i;++c<s;){var p=t[f=u[c]],b=e[f];if(n)var y=i?n(b,p,f,e,t,a):n(p,b,f,t,e,a);if(!(void 0===y?p===b||o(p,b,r,n,a):y)){d=!1;break}v||(v="constructor"==f)}if(d&&!v){var g=t.constructor,m=e.constructor;g==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof m&&m instanceof m||(d=!1)}return a.delete(t),a.delete(e),d},Uo=q(f,"DataView"),Wo=en,qo=q(f,"Promise"),Lo=q(f,"Set"),Go=q(f,"WeakMap"),Jo=j,Ho=M,Ko="[object Map]",Xo="[object Promise]",Yo="[object Set]",Zo="[object WeakMap]",ta="[object DataView]",ea=Ho(Uo),ra=Ho(Wo),na=Ho(qo),oa=Ho(Lo),aa=Ho(Go),ia=Jo;(Uo&&ia(new Uo(new ArrayBuffer(1)))!=ta||Wo&&ia(new Wo)!=Ko||qo&&ia(qo.resolve())!=Xo||Lo&&ia(new Lo)!=Yo||Go&&ia(new Go)!=Zo)&&(ia=function(t){var e=Jo(t),r="[object Object]"==e?t.constructor:void 0,n=r?Ho(r):"";if(n)switch(n){case ea:return ta;case ra:return Ko;case na:return Xo;case oa:return Yo;case aa:return Zo}return e});var ua=fo,sa=mo,ca=Co,fa=Qo,la=ia,ha=Vt,da=qt,va=ne,pa="[object Arguments]",ba="[object Array]",ya="[object Object]",ga=Object.prototype.hasOwnProperty;var ma=function(t,e,r,n,o,a){var i=ha(t),u=ha(e),s=i?ba:la(t),c=u?ba:la(e),f=(s=s==pa?ya:s)==ya,l=(c=c==pa?ya:c)==ya,h=s==c;if(h&&da(t)){if(!da(e))return!1;i=!0,f=!1}if(h&&!f)return a||(a=new ua),i||va(t)?sa(t,e,r,n,o,a):ca(t,e,s,r,n,o,a);if(!(1&r)){var d=f&&ga.call(t,"__wrapped__"),v=l&&ga.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new ua),o(p,b,r,n,a)}}return!!h&&(a||(a=new ua),fa(t,e,r,n,o,a))},_a=Mt;var wa=function t(e,r,n,o,a){return e===r||(null==e||null==r||!_a(e)&&!_a(r)?e!=e&&r!=r:ma(e,r,n,o,t,a))},ja=fo,Oa=wa;var Sa=O;var Ra=function(t){return t==t&&!Sa(t)},xa=Ra,ka=_e;var Ca=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Aa=function(t,e,r,n){var o=r.length,a=o,i=!n;if(null==t)return!a;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<a;){var s=(u=r[o])[0],c=t[s],f=u[1];if(i&&u[2]){if(void 0===c&&!(s in t))return!1}else{var l=new ja;if(n)var h=n(c,f,s,t,e,l);if(!(void 0===h?Oa(f,c,3,n,l):h))return!1}}return!0},Na=function(t){for(var e=ka(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xa(o)]}return e},Ea=Ca;var Ma=Bn,za=It,Da=Vt,Pa=wt,Ba=bt,Ta=Fn;var Fa=function(t,e){return null!=t&&e in Object(t)},$a=function(t,e,r){for(var n=-1,o=(e=Ma(e,t)).length,a=!1;++n<o;){var i=Ta(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&Ba(o)&&Pa(i,o)&&(Da(t)||za(t))};var Ia=wa,Va=qn,Qa=function(t,e){return null!=t&&$a(t,e,Fa)},Ua=jr,Wa=Ra,qa=Ca,La=Fn;var Ga=Vn;var Ja=function(t){return function(e){return null==e?void 0:e[t]}},Ha=function(t){return function(e){return Ga(e,t)}},Ka=jr,Xa=Fn;var Ya=function(t){var e=Na(t);return 1==e.length&&e[0][2]?Ea(e[0][0],e[0][1]):function(r){return r===t||Aa(r,t,e)}},Za=function(t,e){return Ua(t)&&Wa(e)?qa(La(t),e):function(r){var n=Va(r,t);return void 0===n&&n===e?Qa(r,t):Ia(e,n,3)}},ti=ot,ei=Vt,ri=function(t){return Ka(t)?Ja(Xa(t)):Ha(t)};var ni=function(t){return"function"==typeof t?t:null==t?ti:"object"==typeof t?ei(t)?Za(t[0],t[1]):Ya(t):ri(t)};var oi=function(t){return function(e,r,n){for(var o=-1,a=Object(e),i=n(e),u=i.length;u--;){var s=i[t?u:++o];if(!1===r(a[s],s,a))break}return e}}(),ai=_e;var ii=mt;var ui=function(t,e){return function(r,n){if(null==r)return r;if(!ii(r))return t(r,n);for(var o=r.length,a=e?o:-1,i=Object(r);(e?a--:++a<o)&&!1!==n(i[a],a,i););return r}}(function(t,e){return t&&oi(t,e,ai)}),si=mt;var ci=nr,fi=ni,li=function(t,e){var r=-1,n=si(t)?Array(t.length):[];return ui(t,function(t,o,a){n[++r]=e(t,o,a)}),n},hi=Vt;var di=i(function(t,e){return(hi(t)?ci:li)(t,fi(e))}),vi=ni,pi=mt,bi=_e;var yi=function(t){return function(e,r,n){var o=Object(e);if(!pi(e)){var a=vi(r);e=bi(e),r=function(t){return a(o[t],t,o)}}var i=t(e,r,n);return i>-1?o[a?e[i]:i]:void 0}},gi=Ee,mi=ni,_i=rr,wi=Math.max;var ji,Oi=i(yi(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:_i(r);return o<0&&(o=wi(n+o,0)),gi(t,mi(e),o)}));class Si{socket;messageSub;destorySub;get message(){return this.messageSub.asObservable()}constructor(e){this.destorySub=new t,this.messageSub=new t;const{specific:r,id:n}=e.project;this.socket=o(e.ws_url,Ce({autoConnect:!1},r&&void 0!==n?{query:{uuid:n}}:{}))}start(){const t="list",o="cloud",a="channel";r(this.socket,t).pipe(n(1),e(this.destorySub)).subscribe(e=>{this.messageSub.next({event:t,data:e})}),r(this.socket,o).pipe(e(this.destorySub)).subscribe(t=>{this.messageSub.next({event:o,data:t})}),r(this.socket,a).pipe(e(this.destorySub)).subscribe(t=>{this.messageSub.next({event:a,data:t})}),this.socket.connect()}send(t,e){this.socket.emit(t,e)}sendToCloud(t){this.send("cloud",JSON.stringify(t))}onDestory(){this.destorySub.next(),this.destorySub.complete(),this.messageSub.complete(),this.socket.disconnect()}}!function(t){t[t.interrupted=0]="interrupted",t[t.pcm=1]="pcm",t[t.cloudSampleRate=2]="cloudSampleRate"}(ji||(ji={}));class Ri{config;media;chat;destorySub;projectsSub;layoutSub;cloudSampleRate;get layout(){return this.layoutSub.asObservable()}get projects(){return this.projectsSub.asObservable()}set volume(t){this.media.setVolume(t)}get volume(){return this.media.getVolume()}constructor(e,r){this.config=e,this.media=r,this.layoutSub=new t,this.projectsSub=new t,this.destorySub=new t,this.cloudSampleRate=16e3,this.chat=new Si(e)}start(){this.chat.message.pipe(e(this.destorySub)).subscribe(({event:t,data:r})=>{switch(t){case"cloud":this.cloudToObj(r);break;case"list":{const{id:t,name:e,specific:n}=this.config.project;let o=null;if(n&&void 0!==t)o=t;else{const n=Oi(r,r=>r.name===e||r.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):this.projectsSub.next(r);break}case"channel":this.media.state===Wn.allowed?this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}):this.media.state===Wn.padding&&this.media.stateObs.pipe(e(this.destorySub)).subscribe(t=>{t===Wn.allowed&&this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate})})}}),this.chat.start()}chooseProject(t){this.chat.send("uuid",t)}cloudToObj(t){try{const e=JSON.parse(t);void 0!==Ln(e,"signal")?this.behavior(e):Qt(e)?di(e,this.behavior):di(sr(e),this.behavior)}catch(t){br.error("aiia websocket","onmessage error",t)}}behavior(t){switch(t.signal){case"layout":this.layoutSub.next(t.content);break;case"audio":if("sampleRate"===t.command)this.cloudSampleRate=t.content;else if(this.media.state===Wn.allowed)switch(t.command){case"pcm":{const e=function(t,e,r){if(e===r)return t;const n=r/e,o=Math.ceil(t.length*n),a=new Float32Array(o);for(let e=0;e<o;e++){const r=e/n,o=Math.floor(r),i=r-o,u=t[o],s=t[Math.min(o+1,t.length-1)];a[e]=u+(s-u)*i}return a}(Jn(new Int16Array(t.content)),this.cloudSampleRate,this.media.sampleRate);this.media.addAudioQueue({float32:e}),this.media.playAudio();break}case"interrupted":this.media.stopAudio()}break;case"status":"Connected"===t.content&&this.media.state===Wn.allowed?(this.media.pcm.pipe(e(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Hn(t)})}),this.media.startRecord()):br.warn("Media permission didn't get. Please reload page after reset permission or ignore this message.");break;default:br.info(t.signal)}}onDestory(){this.chat.onDestory(),this.destorySub.next(),this.destorySub.complete()}}function xi(t){if(Ae){const e=new Ne(Ce({},t));yr(e.debug);const r=new Yn,n=new Ri(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(me["環境錯誤(browser)"])}export{Yn as MediaManager,xi as initSdk};
|
|
1
|
+
import t from"moment";import{Subject as e,fromEvent as r,take as n,takeUntil as o}from"rxjs";import{io as a}from"socket.io-client";var i="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 s="object"==typeof i&&i&&i.Object===Object&&i,c=s,l="object"==typeof self&&self&&self.Object===Object&&self,f=c||l||Function("return this")(),h=f.Symbol,d=h,v=Object.prototype,p=v.hasOwnProperty,b=v.toString,g=d?d.toStringTag:void 0;var y=function(t){var e=p.call(t,g),r=t[g];try{t[g]=void 0;var n=!0}catch(t){}var o=b.call(t);return n&&(e?t[g]=r:delete t[g]),o},_=Object.prototype.toString;var m=y,w=function(t){return _.call(t)},j=h?h.toStringTag:void 0;var S=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":j&&j in Object(t)?m(t):w(t)};var O=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},x=S,R=O;var k,C=function(t){if(!R(t))return!1;var e=x(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},A=f["__core-js_shared__"],N=(k=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var M=function(t){return!!N&&N in t},E=Function.prototype.toString;var D=function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""},P=C,z=M,B=O,T=D,$=/^\[object .+?Constructor\]$/,F=Function.prototype,I=Object.prototype,V=F.toString,Q=I.hasOwnProperty,U=RegExp("^"+V.call(Q).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var W=function(t){return!(!B(t)||z(t))&&(P(t)?U:$).test(T(t))},q=function(t,e){return null==t?void 0:t[e]};var L=function(t,e){var r=q(t,e);return W(r)?r:void 0},G=L,H=function(){try{var t=G(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=H;var K=function(t,e,r){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var X=function(t,e){return t===e||t!=t&&e!=e},Y=K,Z=X,tt=Object.prototype.hasOwnProperty;var et=function(t,e,r){var n=t[e];tt.call(t,e)&&Z(n,r)&&(void 0!==r||e in t)||Y(t,e,r)},rt=et,nt=K;var ot=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?nt(r,u,s):rt(r,u,s)}return r};var at=function(t){return t};var it=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},ut=Math.max;var st=function(t,e,r){return e=ut(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,a=ut(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),it(t,this,u)}};var ct=function(t){return function(){return t}},lt=H,ft=lt?function(t,e){return lt(t,"toString",{configurable:!0,enumerable:!1,value:ct(e),writable:!0})}:at,ht=Date.now;var dt=function(t){var e=0,r=0;return function(){var n=ht(),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,pt=st,bt=dt;var gt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},yt=C,_t=gt;var mt=function(t){return null!=t&&_t(t.length)&&!yt(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},St=X,Ot=mt,xt=jt,Rt=O;var kt=function(t,e){return bt(pt(t,e,vt),t+"")},Ct=function(t,e,r){if(!Rt(r))return!1;var n=typeof e;return!!("number"==n?Ot(r)&&xt(e,r.length):"string"==n&&e in r)&&St(r[e],t)};var At=function(t){return kt(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&&Ct(r[0],r[1],i)&&(a=o<3?void 0:a,o=1),e=Object(e);++n<o;){var u=r[n];u&&t(e,u,n,a)}return e})},Nt=Object.prototype;var Mt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Nt)};var Et=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Dt=function(t){return null!=t&&"object"==typeof t},Pt=S,zt=Dt;var Bt=function(t){return zt(t)&&"[object Arguments]"==Pt(t)},Tt=Dt,$t=Object.prototype,Ft=$t.hasOwnProperty,It=$t.propertyIsEnumerable,Vt=Bt(function(){return arguments}())?Bt:function(t){return Tt(t)&&Ft.call(t,"callee")&&!It.call(t,"callee")},Qt=Array.isArray,Ut=u(Qt),Wt={exports:{}};var qt=function(){return!1};!function(t,e){var r=f,n=qt,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}(Wt,Wt.exports);var Lt=Wt.exports,Gt=S,Ht=gt,Jt=Dt,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 Xt=function(t){return Jt(t)&&Ht(t.length)&&!!Kt[Gt(t)]};var Yt=function(t){return function(e){return t(e)}},Zt={exports:{}};!function(t,e){var r=s,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}(Zt,Zt.exports);var te=Zt.exports,ee=Xt,re=Yt,ne=te&&te.isTypedArray,oe=ne?re(ne):ee,ae=Et,ie=Vt,ue=Qt,se=Lt,ce=jt,le=oe,fe=Object.prototype.hasOwnProperty;var he=function(t,e){var r=ue(t),n=!r&&ie(t),o=!r&&!n&&se(t),a=!r&&!n&&!o&&le(t),i=r||n||o||a,u=i?ae(t.length,String):[],s=u.length;for(var c in t)!e&&!fe.call(t,c)||i&&("length"==c||o&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ce(c,s))||u.push(c);return u};var de=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),ve=Mt,pe=de,be=Object.prototype.hasOwnProperty;var ge=he,ye=function(t){if(!ve(t))return pe(t);var e=[];for(var r in Object(t))be.call(t,r)&&"constructor"!=r&&e.push(r);return e},_e=mt;var me,we=function(t){return _e(t)?ge(t):ye(t)},je=et,Se=ot,Oe=At,xe=mt,Re=Mt,ke=we,Ce=Object.prototype.hasOwnProperty,Ae=u(Oe(function(t,e){if(Re(e)||xe(e))Se(e,ke(e),t);else for(var r in e)Ce.call(e,r)&&je(t,r,e[r])}));!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(me||(me={}));const Ne="undefined"!=typeof window;"undefined"!=typeof process&&null!=process.versions&&process.versions.node;class Me{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}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 De=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 Be=function(t,e,r){return e==e?ze(t,e,r):De(t,Pe,r)},Te=S,$e=Qt,Fe=Dt;var Ie=function(t){return"string"==typeof t||!$e(t)&&Fe(t)&&"[object String]"==Te(t)},Ve=/\s/;var Qe=function(t){for(var e=t.length;e--&&Ve.test(t.charAt(e)););return e},Ue=/^\s+/;var We=S,qe=Dt;var Le=function(t){return"symbol"==typeof t||qe(t)&&"[object Symbol]"==We(t)},Ge=function(t){return t?t.slice(0,Qe(t)+1).replace(Ue,""):t},He=O,Je=Le,Ke=/^[-+]0x[0-9a-f]+$/i,Xe=/^0b[01]+$/i,Ye=/^0o[0-7]+$/i,Ze=parseInt;var tr=function(t){if("number"==typeof t)return t;if(Je(t))return NaN;if(He(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=He(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Ge(t);var r=Xe.test(t);return r||Ye.test(t)?Ze(t.slice(2),r?2:8):Ke.test(t)?NaN:+t},er=1/0;var rr=function(t){return t?(t=tr(t))===er||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var nr=function(t){var e=rr(t),r=e%1;return e==e?r?e-r:e:0};var or=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},ar=or;var ir=function(t,e){return ar(e,function(e){return t[e]})},ur=we;var sr=function(t){return null==t?[]:ir(t,ur(t))},cr=u(sr),lr=Be,fr=mt,hr=Ie,dr=nr,vr=sr,pr=Math.max;var br=u(function(t,e,r,n){t=fr(t)?t:vr(t),r=r&&!n?dr(r):0;var o=t.length;return r<0&&(r=pr(o+r,0)),hr(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&lr(t,e,r)>-1});const gr={debug:()=>{},info:()=>{},error:()=>{},warn:()=>{},fatal:()=>{}};function yr(){return t().format("yyyy-MM-DD[T]HH:mm:ss")}function _r(t){const{info:e,error:r,warn:n,debug:o,fatal:a}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0,debug:!0,fatal:!0}:"none"===t?{error:!1,warn:!1,info:!1,debug:!1,fatal:!1}:"boolean"==typeof t?{error:t,warn:t,info:t,debug:t,fatal:t}:{debug:br(t,"debug"),fatal:br(t,"fatal"),error:br(t,"error"),warn:br(t,"warn"),info:br(t,"info")}}(t);o&&(gr.debug=(...t)=>{const e=yr();console.log(`[Aiia::debug_${e}_]`,...t)}),e&&(gr.info=(...t)=>{const e=yr();console.log(`[Aiia::info_${e}_]`,...t)}),n&&(gr.warn=(...t)=>{const e=yr();console.warn(`[Aiia::warn_${e}_]`,...t)}),r&&(gr.error=(...t)=>{const e=yr();console.error(`[Aiia::error_${e}_]`,...t)}),a&&(gr.fatal=(...t)=>{const e=yr();console.error(`[Aiia::fatal_${e}_]`,...t)})}var mr=Qt,wr=Le,jr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Sr=/^\w*$/;var Or=function(t,e){if(mr(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!wr(t))||(Sr.test(t)||!jr.test(t)||null!=e&&t in Object(e))},xr=L(Object,"create"),Rr=xr;var kr=function(){this.__data__=Rr?Rr(null):{},this.size=0};var Cr=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ar=xr,Nr=Object.prototype.hasOwnProperty;var Mr=function(t){var e=this.__data__;if(Ar){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Nr.call(e,t)?e[t]:void 0},Er=xr,Dr=Object.prototype.hasOwnProperty;var Pr=xr;var zr=kr,Br=Cr,Tr=Mr,$r=function(t){var e=this.__data__;return Er?void 0!==e[t]:Dr.call(e,t)},Fr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Pr&&void 0===e?"__lodash_hash_undefined__":e,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=zr,Ir.prototype.delete=Br,Ir.prototype.get=Tr,Ir.prototype.has=$r,Ir.prototype.set=Fr;var Vr=Ir;var Qr=function(){this.__data__=[],this.size=0},Ur=X;var Wr=function(t,e){for(var r=t.length;r--;)if(Ur(t[r][0],e))return r;return-1},qr=Wr,Lr=Array.prototype.splice;var Gr=Wr;var Hr=Wr;var Jr=Wr;var Kr=Qr,Xr=function(t){var e=this.__data__,r=qr(e,t);return!(r<0)&&(r==e.length-1?e.pop():Lr.call(e,r,1),--this.size,!0)},Yr=function(t){var e=this.__data__,r=Gr(e,t);return r<0?void 0:e[r][1]},Zr=function(t){return Hr(this.__data__,t)>-1},tn=function(t,e){var r=this.__data__,n=Jr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function en(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])}}en.prototype.clear=Kr,en.prototype.delete=Xr,en.prototype.get=Yr,en.prototype.has=Zr,en.prototype.set=tn;var rn=en,nn=L(f,"Map"),on=Vr,an=rn,un=nn;var sn=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var cn=function(t,e){var r=t.__data__;return sn(e)?r["string"==typeof e?"string":"hash"]:r.map},ln=cn;var fn=cn;var hn=cn;var dn=cn;var vn=function(){this.size=0,this.__data__={hash:new on,map:new(un||an),string:new on}},pn=function(t){var e=ln(this,t).delete(t);return this.size-=e?1:0,e},bn=function(t){return fn(this,t).get(t)},gn=function(t){return hn(this,t).has(t)},yn=function(t,e){var r=dn(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function _n(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])}}_n.prototype.clear=vn,_n.prototype.delete=pn,_n.prototype.get=bn,_n.prototype.has=gn,_n.prototype.set=yn;var mn=_n,wn=mn;function jn(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(jn.Cache||wn),r}jn.Cache=wn;var Sn=jn;var On=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,xn=/\\(\\)?/g,Rn=function(t){var e=Sn(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(On,function(t,r,n,o){e.push(n?o.replace(xn,"$1"):r||t)}),e}),kn=or,Cn=Qt,An=Le,Nn=h?h.prototype:void 0,Mn=Nn?Nn.toString:void 0;var En=function t(e){if("string"==typeof e)return e;if(Cn(e))return kn(e,t)+"";if(An(e))return Mn?Mn.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Dn=En;var Pn=Qt,zn=Or,Bn=Rn,Tn=function(t){return null==t?"":Dn(t)};var $n=function(t,e){return Pn(t)?t:zn(t,e)?[t]:Bn(Tn(t))},Fn=Le;var In=function(t){if("string"==typeof t||Fn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},Vn=$n,Qn=In;var Un=function(t,e){for(var r=0,n=(e=Vn(e,t)).length;null!=t&&r<n;)t=t[Qn(e[r++])];return r&&r==n?t:void 0},Wn=Un;var qn,Ln,Gn=function(t,e,r){var n=null==t?void 0:Wn(t,e);return void 0===n?r:n},Hn=u(Gn);function Jn(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 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"}(qn||(qn={}));class Yn{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(Kn(t),e)}startSpeech(){null===this.currentNode&&this.continue()}pauseSpeech(){this.audioContext.suspend().catch(t=>{gr.error("pause speech fail",t)})}resumeSpeech(){this.audioContext.resume().catch(t=>{gr.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 Zn{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"}(Ln||(Ln={}));class to{_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 e,this.pcmSub=new e,this.destory=new e,this.state=Ln.padding}async init(t){if(this.destory.closed)throw new Error(me["實例已摧毀"]);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=Ln.rejected,new Error(me["未獲得媒體裝置權限"]);this.audioCtx=new AudioContext;try{await this.audioCtx.audioWorklet.addModule(t)}catch(t){throw gr.fatal(t),this.state=Ln.loadfail,new Error(me["Worklet模組載入失敗"])}this.state=Ln.allowed,this.audioManager=new Yn(this.audioCtx),this.vadManager=new Zn(e,this.audioCtx,this.pcmSub)}addAudioQueue(t){const e=Hn(t,"buffer",void 0),r=Hn(t,"float32",void 0),n=Hn(t,"int16",void 0),o=Hn(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 eo=rn;var ro=rn,no=nn,oo=mn;var ao=rn,io=function(){this.__data__=new eo,this.size=0},uo=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},so=function(t){return this.__data__.get(t)},co=function(t){return this.__data__.has(t)},lo=function(t,e){var r=this.__data__;if(r instanceof ro){var n=r.__data__;if(!no||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new oo(n)}return r.set(t,e),this.size=r.size,this};function fo(t){var e=this.__data__=new ao(t);this.size=e.size}fo.prototype.clear=io,fo.prototype.delete=uo,fo.prototype.get=so,fo.prototype.has=co,fo.prototype.set=lo;var ho=fo;var vo=mn,po=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},bo=function(t){return this.__data__.has(t)};function go(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new vo;++e<r;)this.add(t[e])}go.prototype.add=go.prototype.push=po,go.prototype.has=bo;var yo=go,_o=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},mo=function(t,e){return t.has(e)};var wo=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 yo: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(!_o(e,function(t,e){if(!mo(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 jo=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var So=f.Uint8Array,Oo=X,xo=wo,Ro=jo,ko=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},Co=h?h.prototype:void 0,Ao=Co?Co.valueOf:void 0;var No=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 So(t),new So(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Oo(+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=Ro;case"[object Set]":var s=1&n;if(u||(u=ko),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=xo(u(t),u(e),n,o,a,i);return i.delete(t),l;case"[object Symbol]":if(Ao)return Ao.call(t)==Ao.call(e)}return!1};var Mo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Eo=Mo,Do=Qt;var Po=function(t,e,r){var n=e(t);return Do(t)?n:Eo(n,r(t))};var zo=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a},Bo=function(){return[]},To=Object.prototype.propertyIsEnumerable,$o=Object.getOwnPropertySymbols,Fo=Po,Io=$o?function(t){return null==t?[]:(t=Object(t),zo($o(t),function(e){return To.call(t,e)}))}:Bo,Vo=we;var Qo=function(t){return Fo(t,Vo,Io)},Uo=Object.prototype.hasOwnProperty;var Wo=function(t,e,r,n,o,a){var i=1&r,u=Qo(t),s=u.length;if(s!=Qo(e).length&&!i)return!1;for(var c=s;c--;){var l=u[c];if(!(i?l in e:Uo.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 g=i?n(b,p,l,e,t,a):n(p,b,l,t,e,a);if(!(void 0===g?p===b||o(p,b,r,n,a):g)){d=!1;break}v||(v="constructor"==l)}if(d&&!v){var y=t.constructor,_=e.constructor;y==_||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof _&&_ instanceof _||(d=!1)}return a.delete(t),a.delete(e),d},qo=L(f,"DataView"),Lo=nn,Go=L(f,"Promise"),Ho=L(f,"Set"),Jo=L(f,"WeakMap"),Ko=S,Xo=D,Yo="[object Map]",Zo="[object Promise]",ta="[object Set]",ea="[object WeakMap]",ra="[object DataView]",na=Xo(qo),oa=Xo(Lo),aa=Xo(Go),ia=Xo(Ho),ua=Xo(Jo),sa=Ko;(qo&&sa(new qo(new ArrayBuffer(1)))!=ra||Lo&&sa(new Lo)!=Yo||Go&&sa(Go.resolve())!=Zo||Ho&&sa(new Ho)!=ta||Jo&&sa(new Jo)!=ea)&&(sa=function(t){var e=Ko(t),r="[object Object]"==e?t.constructor:void 0,n=r?Xo(r):"";if(n)switch(n){case na:return ra;case oa:return Yo;case aa:return Zo;case ia:return ta;case ua:return ea}return e});var ca=ho,la=wo,fa=No,ha=Wo,da=sa,va=Qt,pa=Lt,ba=oe,ga="[object Arguments]",ya="[object Array]",_a="[object Object]",ma=Object.prototype.hasOwnProperty;var wa=function(t,e,r,n,o,a){var i=va(t),u=va(e),s=i?ya:da(t),c=u?ya:da(e),l=(s=s==ga?_a:s)==_a,f=(c=c==ga?_a:c)==_a,h=s==c;if(h&&pa(t)){if(!pa(e))return!1;i=!0,l=!1}if(h&&!l)return a||(a=new ca),i||ba(t)?la(t,e,r,n,o,a):fa(t,e,s,r,n,o,a);if(!(1&r)){var d=l&&ma.call(t,"__wrapped__"),v=f&&ma.call(e,"__wrapped__");if(d||v){var p=d?t.value():t,b=v?e.value():e;return a||(a=new ca),o(p,b,r,n,a)}}return!!h&&(a||(a=new ca),ha(t,e,r,n,o,a))},ja=Dt;var Sa=function t(e,r,n,o,a){return e===r||(null==e||null==r||!ja(e)&&!ja(r)?e!=e&&r!=r:wa(e,r,n,o,t,a))},Oa=ho,xa=Sa;var Ra=O;var ka=function(t){return t==t&&!Ra(t)},Ca=ka,Aa=we;var Na=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Ma=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 Oa;if(n)var h=n(c,l,s,t,e,f);if(!(void 0===h?xa(l,c,3,n,f):h))return!1}}return!0},Ea=function(t){for(var e=Aa(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Ca(o)]}return e},Da=Na;var Pa=$n,za=Vt,Ba=Qt,Ta=jt,$a=gt,Fa=In;var Ia=function(t,e){return null!=t&&e in Object(t)},Va=function(t,e,r){for(var n=-1,o=(e=Pa(e,t)).length,a=!1;++n<o;){var i=Fa(e[n]);if(!(a=null!=t&&r(t,i)))break;t=t[i]}return a||++n!=o?a:!!(o=null==t?0:t.length)&&$a(o)&&Ta(i,o)&&(Ba(t)||za(t))};var Qa=Sa,Ua=Gn,Wa=function(t,e){return null!=t&&Va(t,e,Ia)},qa=Or,La=ka,Ga=Na,Ha=In;var Ja=Un;var Ka=function(t){return function(e){return null==e?void 0:e[t]}},Xa=function(t){return function(e){return Ja(e,t)}},Ya=Or,Za=In;var ti=function(t){var e=Ea(t);return 1==e.length&&e[0][2]?Da(e[0][0],e[0][1]):function(r){return r===t||Ma(r,t,e)}},ei=function(t,e){return qa(t)&&La(e)?Ga(Ha(t),e):function(r){var n=Ua(r,t);return void 0===n&&n===e?Wa(r,t):Qa(e,n,3)}},ri=at,ni=Qt,oi=function(t){return Ya(t)?Ka(Za(t)):Xa(t)};var ai=function(t){return"function"==typeof t?t:null==t?ri:"object"==typeof t?ni(t)?ei(t[0],t[1]):ti(t):oi(t)};var ii=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}}(),ui=we;var si=mt;var ci=function(t,e){return function(r,n){if(null==r)return r;if(!si(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&&ii(t,e,ui)}),li=mt;var fi=or,hi=ai,di=function(t,e){var r=-1,n=li(t)?Array(t.length):[];return ci(t,function(t,o,a){n[++r]=e(t,o,a)}),n},vi=Qt;var pi=u(function(t,e){return(vi(t)?fi:di)(t,hi(e))}),bi=ai,gi=mt,yi=we;var _i=function(t){return function(e,r,n){var o=Object(e);if(!gi(e)){var a=bi(r);e=yi(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}},mi=Ee,wi=ai,ji=nr,Si=Math.max;var Oi,xi=u(_i(function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var o=null==r?0:ji(r);return o<0&&(o=Si(n+o,0)),mi(t,wi(e),o)}));class Ri{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",a="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,a).pipe(o(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"}(Oi||(Oi={}));class ki{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(t,r){this.config=t,this.media=r,this.layoutSub=new e,this.projectsSub=new e,this.destorySub=new e,this.aiiaSubtitleSub=new e,this.userSubtitleSub=new e,this.cloudSampleRate=16e3,this.channelState={proxy:!1,cloud:!1},this.chat=new Ri(t)}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=xi(e,e=>e.name===r||e.id===t);n&&(o=n.id)}null!==o?this.chooseProject(o):(this.projectsSub.next(e),gr.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!==Hn(e,"signal")?this.behavior(e):Ut(e)?pi(e,this.behavior):pi(cr(e),this.behavior)}catch(t){gr.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=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}(Kn(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"===Hn(t,"content")&&(this.channelState.cloud=!0,this.channelCheck());break;case"agent":{const e=Hn(t,"content.function_result.response");e&&this.aiiaSubtitleSub.next(e);break}case"asr":if("ASR"===Hn(t,"content.function_type")){const e=Hn(t,"content.function_result.result");e&&this.userSubtitleSub.next(e)}break;default:gr.debug(t.signal)}}channelCheck(){const{proxy:t,cloud:e}=this.channelState;t&&e&&this.media.state===Ln.allowed?(this.chat.sendToCloud({request:"audio",command:"sampleRate",content:this.media.sampleRate}),this.media.pcm.pipe(o(this.destorySub)).subscribe(t=>{this.chat.sendToCloud({request:"audio",command:"pcm",content:Xn(t)})}),this.media.startRecord(),gr.debug("Channel, Cloud and Media are ready.")):t&&e&&this.media.state!==Ln.allowed&&gr.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 Ci(t){if(Ne){const e=new Me(Ae({},t));_r(e.debug);const r=new to,n=new ki(e,r);return""!==e.worklet_url&&r.init(e.worklet_url),n}throw new Error(me["環境錯誤(browser)"])}export{to as MediaManager,Ci 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},L=Function.prototype.toString;var P=function(t){if(null!=t){try{return L.call(t)}catch(t){}try{return t+""}catch(t){}}return""},C=R,x=I,T=E,U=P,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!(!T(t)||x(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 Lt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Pt=function(t){return null!=t&&"object"==typeof t},Ct=A,xt=Pt;var Tt=function(t){return xt(t)&&"[object Arguments]"==Ct(t)},Ut=Pt,Ft=Object.prototype,zt=Ft.hasOwnProperty,Wt=Ft.propertyIsEnumerable,Bt=Tt(function(){return arguments}())?Tt: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=Pt,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=Lt,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=Pt;var Le=function(t){return"symbol"==typeof t||Ie(t)&&"[object Symbol]"==Me(t)},Pe=Gt,Ce=Le,xe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Te=/^\w*$/;var Ue=function(t,e){if(Pe(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Ce(t))||(Te.test(t)||!xe.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 Lr=Ir,Pr=Lr;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||Pr),r}Cr.Cache=Pr;var xr=Cr;var Tr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ur=/\\(\\)?/g,Fr=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(Tr,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=Le,$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=Le;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=Pt;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=Le,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]})},Ln=Se;var Pn=function(t,e,r){return e==e?pn(t,e,r):hn(t,vn,r)},Cn=Ot,xn=function(t){return"string"==typeof t||!yn(t)&&_n(t)&&"[object String]"==bn(t)},Tn=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,Ln(t))},Fn=Math.max;var zn=c(function(t,e,r,n){t=Cn(t)?t:Un(t),r=r&&!n?Tn(r):0;var o=t.length;return r<0&&(r=Fn(o+r,0)),xn(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&Pn(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=Lr;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,Lo=Eo,Po=jo,Co=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Mo(e,Lo(t)),t=Io(t);return e}:Po,xo=it,To=Co;var Uo=function(t,e){return xo(t,To(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=P,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)}},Li=E,Pi=Object.create,Ci=function(){function t(){}return function(e){if(!Li(e))return{};if(Pi)return Pi(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),xi=ko,Ti=It;var Ui=function(t){return"function"!=typeof t.constructor||Ti(t)?{}:Ci(xi(t))},Fi=pi,zi=Pt;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=Pt;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,La=ko,Pa=Pt,Ca=Function.prototype,xa=Object.prototype,Ta=Ca.toString,Ua=xa.hasOwnProperty,Fa=Ta.call(Object);var za=function(t){if(!Pa(t)||"[object Object]"!=Ia(t))return!1;var e=La(t);if(null===e)return!0;var r=Ua.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Ta.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=Lr,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,Ls=Gt,Ps=Yt,Cs=ie,xs="[object Arguments]",Ts="[object Array]",Us="[object Object]",Fs=Object.prototype.hasOwnProperty;var zs=function(t,e,r,n,o,i){var a=Ls(t),s=Ls(e),c=a?Ts:Is(t),u=s?Ts:Is(e),f=(c=c==xs?Us:c)==Us,l=(u=u==xs?Us:u)==Us,h=c==u;if(h&&Ps(t)){if(!Ps(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=Pt;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 Lc=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)}),Pc=Ot;var Cc=zr,xc=Rc,Tc=function(t,e){var r=-1,n=Pc(t)?Array(t.length):[];return Lc(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:Tc)(t,xc(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("Message proxy to"),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 connection and stop emit event");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(t){this.isStart&&this.socket?.close(t)}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":r.onDestory(),e.emit("channel",n);break;case"reconnect":r.onManualClose(Fc.MANUAL_CLOSE),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.access_token}/${t}`}onDestory(){this.server&&this.server.close()}}class $c{config;stroage;apiProxy;chat;isStart;destorySub;get destoryObs(){return this.destorySub.asObservable()}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["重複初始化"]);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(cn(t,"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("fs"),r=require("os"),n=require("path"),o=require("rxjs"),i=require("axios"),a=require("socket.io"),s=require("ws"),c="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 c&&c&&c.Object===Object&&c,l=f,h="object"==typeof self&&self&&self.Object===Object&&self,v=l||h||Function("return this")(),p=v.Symbol,b=p,y=Object.prototype,_=y.hasOwnProperty,d=y.toString,g=b?b.toStringTag:void 0;var j=function(t){var e=_.call(t,g),r=t[g];try{t[g]=void 0;var n=!0}catch(t){}var o=d.call(t);return n&&(e?t[g]=r:delete t[g]),o},O=Object.prototype.toString;var S=j,w=function(t){return O.call(t)},A=p?p.toStringTag:void 0;var E=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":A&&A in Object(t)?S(t):w(t)};var m=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},N=E,D=m;var R,k=function(t){if(!D(t))return!1;var e=N(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},M=v["__core-js_shared__"],I=(R=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"";var L=function(t){return!!I&&I in t},P=Function.prototype.toString;var C=function(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""},T=k,U=L,x=m,F=C,z=/^\[object .+?Constructor\]$/,W=Function.prototype,$=Object.prototype,B=W.toString,G=$.hasOwnProperty,V=RegExp("^"+B.call(G).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var X=function(t){return!(!x(t)||U(t))&&(T(t)?V:z).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,Q=function(){try{var t=H(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),K=Q;var J=function(t,e,r){"__proto__"==e&&K?K(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 s=e[i],c=n?n(r[s],t[s],s,r,t):void 0;void 0===c&&(c=t[s]),o?it(r,s,c):ot(r,s,c)}return r};var st=function(t){return t};var ct=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 s=Array(e+1);++o<e;)s[o]=n[o];return s[e]=r(a),ct(t,this,s)}};var lt=function(t){return function(){return t}},ht=Q,vt=ht?function(t,e){return ht(t,"toString",{configurable:!0,enumerable:!1,value:lt(e),writable:!0})}:st,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),yt=st,_t=ft,dt=bt;var gt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},jt=k,Ot=gt;var St=function(t){return null!=t&&Ot(t.length)&&!jt(t)},wt=/^(?:0|[1-9]\d*)$/;var At=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,mt=St,Nt=At,Dt=m;var Rt=function(t,e){return dt(_t(t,e,yt),t+"")},kt=function(t,e,r){if(!Dt(r))return!1;var n=typeof e;return!!("number"==n?mt(r)&&Nt(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 s=r[n];s&&t(e,s,n,i)}return e})},It=Object.prototype;var Lt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||It)};var Pt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Ct=function(t){return null!=t&&"object"==typeof t},Tt=E,Ut=Ct;var xt=function(t){return Ut(t)&&"[object Arguments]"==Tt(t)},Ft=Ct,zt=Object.prototype,Wt=zt.hasOwnProperty,$t=zt.propertyIsEnumerable,Bt=xt(function(){return arguments}())?xt:function(t){return Ft(t)&&Wt.call(t,"callee")&&!$t.call(t,"callee")},Gt=Array.isArray,Vt=u(Gt),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,s=(a?a.isBuffer:void 0)||n;t.exports=s}(Xt,Xt.exports);var qt=Xt.exports,Ht=E,Qt=gt,Kt=Ct,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 Kt(t)&&Qt(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,se=Pt,ce=Bt,ue=Gt,fe=qt,le=At,he=ae,ve=Object.prototype.hasOwnProperty;var pe=function(t,e){var r=ue(t),n=!r&&ce(t),o=!r&&!n&&fe(t),i=!r&&!n&&!o&&he(t),a=r||n||o||i,s=a?se(t.length,String):[],c=s.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,c))||s.push(u);return s};var be=function(t,e){return function(r){return t(e(r))}},ye=be(Object.keys,Object),_e=Lt,de=ye,ge=Object.prototype.hasOwnProperty;var je=pe,Oe=function(t){if(!_e(t))return de(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)?je(t):Oe(t)},Ae=nt,Ee=at,me=Mt,Ne=St,De=Lt,Re=we,ke=Object.prototype.hasOwnProperty,Me=u(me(function(t,e){if(De(e)||Ne(e))Ee(e,Re(e),t);else for(var r in e)ke.call(e,r)&&Ae(t,r,e[r])})),Ie=E,Le=Ct;var Pe=function(t){return"symbol"==typeof t||Le(t)&&"[object Symbol]"==Ie(t)},Ce=Gt,Te=Pe,Ue=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,xe=/^\w*$/;var Fe=function(t,e){if(Ce(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Te(t))||(xe.test(t)||!Ue.test(t)||null!=e&&t in Object(e))},ze=q(Object,"create"),We=ze;var $e=function(){this.__data__=We?We(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=ze,Ve=Object.prototype.hasOwnProperty;var Xe=function(t){var e=this.__data__;if(Ge){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Ve.call(e,t)?e[t]:void 0},Ye=ze,qe=Object.prototype.hasOwnProperty;var He=ze;var Qe=$e,Ke=Be,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=Qe,er.prototype.delete=Ke,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,sr=Array.prototype.splice;var cr=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():sr.call(e,r,1),--this.size,!0)},vr=function(t){var e=this.__data__,r=cr(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 yr(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])}}yr.prototype.clear=lr,yr.prototype.delete=hr,yr.prototype.get=vr,yr.prototype.has=pr,yr.prototype.set=br;var _r=yr,dr=q(v,"Map"),gr=rr,jr=_r,Or=dr;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},Ar=wr;var Er=wr;var mr=wr;var Nr=wr;var Dr=function(){this.size=0,this.__data__={hash:new gr,map:new(Or||jr),string:new gr}},Rr=function(t){var e=Ar(this,t).delete(t);return this.size-=e?1:0,e},kr=function(t){return Er(this,t).get(t)},Mr=function(t){return mr(this,t).has(t)},Ir=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 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=Dr,Lr.prototype.delete=Rr,Lr.prototype.get=kr,Lr.prototype.has=Mr,Lr.prototype.set=Ir;var Pr=Lr,Cr=Pr;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||Cr),r}Tr.Cache=Cr;var Ur=Tr;var xr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Fr=/\\(\\)?/g,zr=function(t){var e=Ur(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(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},$r=Wr,Br=Gt,Gr=Pe,Vr=p?p.prototype:void 0,Xr=Vr?Vr.toString:void 0;var Yr=function t(e){if("string"==typeof e)return e;if(Br(e))return $r(e,t)+"";if(Gr(e))return Xr?Xr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},qr=Yr;var Hr=Gt,Qr=Fe,Kr=zr,Jr=function(t){return null==t?"":qr(t)};var Zr=function(t,e){return Hr(t)?t:Qr(t,e)?[t]:Kr(Jr(t))},tn=Pe;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 sn,cn=function(t,e,r){var n=null==t?void 0:an(t,e);return void 0===n?r:n},un=u(cn);!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"}(sn||(sn={}));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}constructor(t){this.config=t}}var vn=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},pn=function(t){return t!=t},bn=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var yn=E,_n=Gt,dn=Ct;var gn=/\s/;var jn=function(t){for(var e=t.length;e--&&gn.test(t.charAt(e)););return e},On=/^\s+/;var Sn=function(t){return t?t.slice(0,jn(t)+1).replace(On,""):t},wn=m,An=Pe,En=/^[-+]0x[0-9a-f]+$/i,mn=/^0b[01]+$/i,Nn=/^0o[0-7]+$/i,Dn=parseInt;var Rn=function(t){if("number"==typeof t)return t;if(An(t))return NaN;if(wn(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=wn(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Sn(t);var r=mn.test(t);return r||Nn.test(t)?Dn(t.slice(2),r?2:8):En.test(t)?NaN:+t},kn=1/0;var Mn=function(t){return t?(t=Rn(t))===kn||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var In=Wr;var Ln=function(t,e){return In(e,function(e){return t[e]})},Pn=we;var Cn=function(t,e,r){return e==e?bn(t,e,r):vn(t,pn,r)},Tn=St,Un=function(t){return"string"==typeof t||!_n(t)&&dn(t)&&"[object String]"==yn(t)},xn=function(t){var e=Mn(t),r=e%1;return e==e?r?e-r:e:0},Fn=function(t){return null==t?[]:Ln(t,Pn(t))},zn=Math.max;var Wn=u(function(t,e,r,n){t=Tn(t)?t:Fn(t),r=r&&!n?xn(r):0;var o=t.length;return r<0&&(r=zn(o+r,0)),Un(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&Cn(t,e,r)>-1});const $n={debug:()=>{},info:()=>{},error:()=>{},warn:()=>{},fatal:()=>{}};function Bn(){return t().format("yyyy-MM-DD[T]HH:mm:ss")}function Gn(t){const{info:e,error:r,warn:n,debug:o,fatal:i}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0,debug:!0,fatal:!0}:"none"===t?{error:!1,warn:!1,info:!1,debug:!1,fatal:!1}:"boolean"==typeof t?{error:t,warn:t,info:t,debug:t,fatal:t}:{debug:Wn(t,"debug"),fatal:Wn(t,"fatal"),error:Wn(t,"error"),warn:Wn(t,"warn"),info:Wn(t,"info")}}(t);o&&($n.debug=(...t)=>{const e=Bn();console.log(`[Aiia::debug_${e}_]`,...t)}),e&&($n.info=(...t)=>{const e=Bn();console.log(`[Aiia::info_${e}_]`,...t)}),n&&($n.warn=(...t)=>{const e=Bn();console.warn(`[Aiia::warn_${e}_]`,...t)}),r&&($n.error=(...t)=>{const e=Bn();console.error(`[Aiia::error_${e}_]`,...t)}),i&&($n.fatal=(...t)=>{const e=Bn();console.error(`[Aiia::fatal_${e}_]`,...t)})}var Vn=_r;var Xn=_r,Yn=dr,qn=Pr;var Hn=_r,Qn=function(){this.__data__=new Vn,this.size=0},Kn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Jn=function(t){return this.__data__.get(t)},Zn=function(t){return this.__data__.has(t)},to=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 qn(n)}return r.set(t,e),this.size=r.size,this};function eo(t){var e=this.__data__=new Hn(t);this.size=e.size}eo.prototype.clear=Qn,eo.prototype.delete=Kn,eo.prototype.get=Jn,eo.prototype.has=Zn,eo.prototype.set=to;var ro=eo;var no=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t},oo=at,io=we;var ao=function(t,e){return t&&oo(e,io(e),t)};var so=m,co=Lt,uo=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},fo=Object.prototype.hasOwnProperty;var lo=pe,ho=function(t){if(!so(t))return uo(t);var e=co(t),r=[];for(var n in t)("constructor"!=n||!e&&fo.call(t,n))&&r.push(n);return r},vo=St;var po=function(t){return vo(t)?lo(t,!0):ho(t)},bo=at,yo=po;var _o=function(t,e){return t&&bo(e,yo(e),t)},go={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}}(go,go.exports);var jo=go.exports;var Oo=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[]},wo=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},Ao=So,Eo=Object.prototype.propertyIsEnumerable,mo=Object.getOwnPropertySymbols,No=mo?function(t){return null==t?[]:(t=Object(t),wo(mo(t),function(e){return Eo.call(t,e)}))}:Ao,Do=at,Ro=No;var ko=function(t,e){return Do(t,Ro(t),e)};var Mo=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Io=be(Object.getPrototypeOf,Object),Lo=Mo,Po=Io,Co=No,To=So,Uo=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Lo(e,Co(t)),t=Po(t);return e}:To,xo=at,Fo=Uo;var zo=function(t,e){return xo(t,Fo(t),e)},Wo=Mo,$o=Gt;var Bo=function(t,e,r){var n=e(t);return $o(t)?n:Wo(n,r(t))},Go=Bo,Vo=No,Xo=we;var Yo=function(t){return Go(t,Xo,Vo)},qo=Bo,Ho=Uo,Qo=po;var Ko=function(t){return qo(t,Qo,Ho)},Jo=q(v,"DataView"),Zo=dr,ti=q(v,"Promise"),ei=q(v,"Set"),ri=q(v,"WeakMap"),ni=E,oi=C,ii="[object Map]",ai="[object Promise]",si="[object Set]",ci="[object WeakMap]",ui="[object DataView]",fi=oi(Jo),li=oi(Zo),hi=oi(ti),vi=oi(ei),pi=oi(ri),bi=ni;(Jo&&bi(new Jo(new ArrayBuffer(1)))!=ui||Zo&&bi(new Zo)!=ii||ti&&bi(ti.resolve())!=ai||ei&&bi(new ei)!=si||ri&&bi(new ri)!=ci)&&(bi=function(t){var e=ni(t),r="[object Object]"==e?t.constructor:void 0,n=r?oi(r):"";if(n)switch(n){case fi:return ui;case li:return ii;case hi:return ai;case vi:return si;case pi:return ci}return e});var yi=bi,_i=Object.prototype.hasOwnProperty;var di=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&_i.call(t,"index")&&(r.index=t.index,r.input=t.input),r},gi=v.Uint8Array,ji=gi;var Oi=function(t){var e=new t.constructor(t.byteLength);return new ji(e).set(new ji(t)),e},Si=Oi;var wi=function(t,e){var r=e?Si(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},Ai=/\w*$/;var Ei=function(t){var e=new t.constructor(t.source,Ai.exec(t));return e.lastIndex=t.lastIndex,e},mi=p?p.prototype:void 0,Ni=mi?mi.valueOf:void 0;var Di=Oi;var Ri=Oi,ki=wi,Mi=Ei,Ii=function(t){return Ni?Object(Ni.call(t)):{}},Li=function(t,e){var r=e?Di(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var Pi=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return Ri(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return ki(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 Mi(t);case"[object Symbol]":return Ii(t)}},Ci=m,Ti=Object.create,Ui=function(){function t(){}return function(e){if(!Ci(e))return{};if(Ti)return Ti(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),xi=Io,Fi=Lt;var zi=function(t){return"function"!=typeof t.constructor||Fi(t)?{}:Ui(xi(t))},Wi=yi,$i=Ct;var Bi=function(t){return $i(t)&&"[object Map]"==Wi(t)},Gi=te,Vi=re&&re.isMap,Xi=Vi?Gi(Vi):Bi,Yi=yi,qi=Ct;var Hi=function(t){return qi(t)&&"[object Set]"==Yi(t)},Qi=te,Ki=re&&re.isSet,Ji=Ki?Qi(Ki):Hi,Zi=ro,ta=no,ea=nt,ra=ao,na=_o,oa=jo,ia=Oo,aa=ko,sa=zo,ca=Yo,ua=Ko,fa=yi,la=di,ha=Pi,va=zi,pa=Gt,ba=qt,ya=Xi,_a=m,da=Ji,ga=we,ja=po,Oa="[object Arguments]",Sa="[object Function]",wa="[object Object]",Aa={};Aa[Oa]=Aa["[object Array]"]=Aa["[object ArrayBuffer]"]=Aa["[object DataView]"]=Aa["[object Boolean]"]=Aa["[object Date]"]=Aa["[object Float32Array]"]=Aa["[object Float64Array]"]=Aa["[object Int8Array]"]=Aa["[object Int16Array]"]=Aa["[object Int32Array]"]=Aa["[object Map]"]=Aa["[object Number]"]=Aa[wa]=Aa["[object RegExp]"]=Aa["[object Set]"]=Aa["[object String]"]=Aa["[object Symbol]"]=Aa["[object Uint8Array]"]=Aa["[object Uint8ClampedArray]"]=Aa["[object Uint16Array]"]=Aa["[object Uint32Array]"]=!0,Aa["[object Error]"]=Aa[Sa]=Aa["[object WeakMap]"]=!1;var Ea=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(!_a(e))return e;var l=pa(e);if(l){if(s=la(e),!c)return ia(e,s)}else{var h=fa(e),v=h==Sa||"[object GeneratorFunction]"==h;if(ba(e))return oa(e,c);if(h==wa||h==Oa||v&&!i){if(s=u||v?{}:va(e),!c)return u?sa(e,na(s,e)):aa(e,ra(s,e))}else{if(!Aa[h])return i?e:{};s=ha(e,h,c)}}a||(a=new Zi);var p=a.get(e);if(p)return p;a.set(e,s),da(e)?e.forEach(function(o){s.add(t(o,r,n,o,e,a))}):ya(e)&&e.forEach(function(o,i){s.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?ua:ca:u?ja:ga)(e);return ta(b||e,function(o,i){b&&(o=e[i=o]),ea(s,i,t(o,r,n,i,e,a))}),s};var ma=on,Na=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 Da=function(t,e){return e.length<2?t:ma(t,Na(e,0,-1))},Ra=Zr,ka=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},Ma=Da,Ia=en;var La=function(t,e){return e=Ra(e,t),null==(t=Ma(t,e))||delete t[Ia(ka(e))]},Pa=E,Ca=Io,Ta=Ct,Ua=Function.prototype,xa=Object.prototype,Fa=Ua.toString,za=xa.hasOwnProperty,Wa=Fa.call(Object);var $a=function(t){if(!Ta(t)||"[object Object]"!=Pa(t))return!1;var e=Ca(t);if(null===e)return!0;var r=za.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Fa.call(r)==Wa};var Ba=function(t){return $a(t)?void 0:t},Ga=Bt,Va=Gt,Xa=p?p.isConcatSpreadable:void 0;var Ya=Mo,qa=function(t){return Va(t)||Ga(t)||!!(Xa&&t&&t[Xa])};var Ha=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):Ya(i,c):o||(i[i.length]=c)}return i},Qa=Ha;var Ka=function(t){return(null==t?0:t.length)?Qa(t,1):[]},Ja=ft,Za=bt;var ts=Wr,es=Ea,rs=La,ns=Zr,os=at,is=Ba,as=Ko,ss=function(t){return Za(Ja(t,void 0,Ka),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=ts(e,function(e){return e=ns(e,t),n||(n=e.length>1),e}),os(t,as(t),r),n&&(r=es(r,7,is));for(var o=e.length;o--;)rs(r,e[o]);return r}),cs=u(ss);const us=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=r.homedir(),this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=n.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||n.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||n.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=n.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return n.join(...t)}folderCheck(t){e.mkdirSync(t,{recursive:!0})}fileCheck(t){e.existsSync(t)||e.writeFileSync(t,"",{encoding:"utf8"})}}("aiia-sdk");class fs{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=us.addPath(us.appFolder,this.fileName),us.fileCheck(this.filePath)}getFileDataSync(){const t=e.readFileSync(this.filePath,"utf8");try{return JSON.parse(t)}catch(t){return{}}}setFileDataSync(t){try{const r=JSON.stringify(t);e.writeFileSync(this.filePath,r,"utf8")}catch(t){}}async getFileData(){return new Promise(t=>{e.readFile(this.filePath,"utf8",(e,r)=>{if(e)t({});else try{t(JSON.parse(r))}catch(e){t({})}})})}async setFileData(t){return new Promise(r=>{try{const n=JSON.stringify(t);e.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=cs(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=cs(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}var ls=Pr,hs=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vs=function(t){return this.__data__.has(t)};function ps(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new ls;++e<r;)this.add(t[e])}ps.prototype.add=ps.prototype.push=hs,ps.prototype.has=vs;var bs=ps,ys=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},_s=function(t,e){return t.has(e)};var ds=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 bs: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(!ys(e,function(t,e){if(!_s(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 gs=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var js=gi,Os=Z,Ss=ds,ws=gs,As=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},Es=p?p.prototype:void 0,ms=Es?Es.valueOf:void 0;var Ns=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 Os(+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=ws;case"[object Set]":var c=1&n;if(s||(s=As),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(ms)return ms.call(t)==ms.call(e)}return!1},Ds=Yo,Rs=Object.prototype.hasOwnProperty;var ks=ro,Ms=ds,Is=Ns,Ls=function(t,e,r,n,o,i){var a=1&r,s=Ds(t),c=s.length;if(c!=Ds(e).length&&!a)return!1;for(var u=c;u--;){var f=s[u];if(!(a?f in e:Rs.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},Ps=yi,Cs=Gt,Ts=qt,Us=ae,xs="[object Arguments]",Fs="[object Array]",zs="[object Object]",Ws=Object.prototype.hasOwnProperty;var $s=function(t,e,r,n,o,i){var a=Cs(t),s=Cs(e),c=a?Fs:Ps(t),u=s?Fs:Ps(e),f=(c=c==xs?zs:c)==zs,l=(u=u==xs?zs:u)==zs,h=c==u;if(h&&Ts(t)){if(!Ts(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new ks),a||Us(t)?Ms(t,e,r,n,o,i):Is(t,e,c,r,n,o,i);if(!(1&r)){var v=f&&Ws.call(t,"__wrapped__"),p=l&&Ws.call(e,"__wrapped__");if(v||p){var b=v?t.value():t,y=p?e.value():e;return i||(i=new ks),o(b,y,r,n,i)}}return!!h&&(i||(i=new ks),Ls(t,e,r,n,o,i))},Bs=Ct;var Gs=function t(e,r,n,o,i){return e===r||(null==e||null==r||!Bs(e)&&!Bs(r)?e!=e&&r!=r:$s(e,r,n,o,t,i))},Vs=ro,Xs=Gs;var Ys=m;var qs=function(t){return t==t&&!Ys(t)},Hs=qs,Qs=we;var Ks=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Js=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 Vs;if(n)var h=n(u,f,c,t,e,l);if(!(void 0===h?Xs(f,u,3,n,l):h))return!1}}return!0},Zs=function(t){for(var e=Qs(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Hs(o)]}return e},tc=Ks;var ec=Zr,rc=Bt,nc=Gt,oc=At,ic=gt,ac=en;var sc=function(t,e,r){for(var n=-1,o=(e=ec(e,t)).length,i=!1;++n<o;){var a=ac(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&ic(o)&&oc(a,o)&&(nc(t)||rc(t))},cc=function(t,e){return null!=t&&e in Object(t)},uc=sc;var fc=function(t,e){return null!=t&&uc(t,e,cc)},lc=Gs,hc=cn,vc=fc,pc=Fe,bc=qs,yc=Ks,_c=en;var dc=function(t,e){return pc(t)&&bc(e)?yc(_c(t),e):function(r){var n=hc(r,t);return void 0===n&&n===e?vc(r,t):lc(e,n,3)}};var gc=on;var jc=function(t){return function(e){return gc(e,t)}},Oc=function(t){return function(e){return null==e?void 0:e[t]}},Sc=jc,wc=Fe,Ac=en;var Ec=function(t){return wc(t)?Oc(Ac(t)):Sc(t)},mc=function(t){var e=Zs(t);return 1==e.length&&e[0][2]?tc(e[0][0],e[0][1]):function(r){return r===t||Js(r,t,e)}},Nc=dc,Dc=st,Rc=Gt,kc=Ec;var Mc=function(t){return"function"==typeof t?t:null==t?Dc:"object"==typeof t?Rc(t)?Nc(t[0],t[1]):mc(t):kc(t)};var Ic=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=we;var Pc=St;var Cc=function(t,e){return function(r,n){if(null==r)return r;if(!Pc(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&&Ic(t,e,Lc)}),Tc=St;var Uc=Wr,xc=Mc,Fc=function(t,e){var r=-1,n=Tc(t)?Array(t.length):[];return Cc(t,function(t,o,i){n[++r]=e(t,o,i)}),n},zc=Gt;var Wc,$c=u(function(t,e){return(zc(t)?Uc:Fc)(t,xc(e))});class Bc{instance;controller;constructor(t){this.controller=new AbortController,this.instance=i.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(sn["網絡錯誤"]);if(""===n)throw new Error(sn["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>$c(un(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(sn["網絡錯誤"]);if(0===e.length)throw new Error(sn["沒有可用專案"]);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"}(Wc||(Wc={}));class Gc{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 o.Subject,this.startLinkSub=new o.Subject,this.closeSub=new o.Subject,this.destorySub=new o.Subject}start(t){this.isStart=!0,this.socket=new s(t,{autoPong:!0}),o.fromEvent(this.socket,"open").pipe(o.takeUntil(this.destorySub)).subscribe(t=>{this.isConnected=!0,this.startLinkSub.next(),$n.info("Proxy startup"),this.flushMessageQueue()}),o.fromEvent(this.socket,"message").pipe(o.takeUntil(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),o.fromEvent(this.socket,"error").pipe(o.takeUntil(this.destorySub)).subscribe(t=>{const{error:e}=t;$n.error("Proxy has some problem",e)}),o.fromEvent(this.socket,"close").pipe(o.takeUntil(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e}=t;switch(e){case Wc.MANUAL_CLOSE:$n.debug("MANUAL_CLOSE stop emit event and reconnecting");break;case Wc.WS_5000_NORAML_CLOSURE:case Wc.MDN_NORMAL_CLOSURE:case Wc.MDN_GOING_AWAY:this.closeSub.next("close"),$n.debug("Safe close connection");break;case Wc.MDN_NO_STATUS_RECEIVED:case Wc.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),$n.warn("Cloud disconnect",{code:e},t);break;case Wc.WS_5001_UNAUTHORIZED:case Wc.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),$n.warn("Please contact Graphen");break;case Wc.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect"),$n.debug("Reconnect");break;default:this.closeSub.next("close"),$n.error("Other status always close connection",{code:e})}})}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(Wc.MANUAL_CLOSE)}onDestory(){this.destorySub.next(),this.destorySub.complete()}}class Vc{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 a.Server(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{const e=new o.Subject;let r=(n=t.handshake.query.uuid,Vt(n)?un(n,"[0]",void 0):n??void 0);var n;const i=new Gc;$n.debug("client on",t.id),void 0===r?(this.sdk.getProjectList().then(e=>{t.emit("list",e)}),o.fromEvent(t,"uuid").pipe(o.take(1),o.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(),$n.debug("client off",t)})}),void 0===this.webserver&&this.server.listen(this.port)}openChannel(t,e,r,n){o.fromEvent(e,"cloud").pipe(o.takeUntil(n)).subscribe(t=>{r.send(t)}),r.message.pipe(o.takeUntil(n)).subscribe(t=>{e.emit("cloud",t)}),r.close.pipe(o.takeUntil(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(o.takeUntil(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 Xc{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 o.Subject,this.access_token=e.getItemSync(fn),this.apiProxy=new Bc(this.config.endPoint.api),$n.info("[Initialize] proxy is finished"),this.chat=new Vc(this),$n.info("[Initialize] chat is finished","Start at PORT:",this.config.port)}async start(){if(this.isStart)throw new Error(sn["重複初始化"]);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(fn,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")}}exports.aiiaCore=function(t){if(ln){if(void 0===un(t,"license",void 0))throw new Error(sn["未提供憑證"]);$n.info("Initialize necessary modules");const e=new hn(Me({},t));Gn(e.debug),$n.info("config finished");const r=new fs;$n.info("storage finished");const n=new Xc(e,r);return $n.info("core finished"),n.start(),$n.info("Service startup"),()=>{n.onDestory()}}throw new Error(sn["環境錯誤(nodejs)"])};
|
package/dist/node.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type { Server as Server_2 } from 'https';
|
|
|
8
8
|
* @param options
|
|
9
9
|
* @returns method of clean for service
|
|
10
10
|
*/
|
|
11
|
-
export declare function aiiaCore(options?:
|
|
11
|
+
export declare function aiiaCore(options?: NodeInitOptions): () => void;
|
|
12
12
|
|
|
13
|
-
declare interface AiiaProjectItem {
|
|
13
|
+
export declare interface AiiaProjectItem {
|
|
14
14
|
id: string;
|
|
15
15
|
name: string;
|
|
16
16
|
}
|
|
@@ -81,7 +81,9 @@ declare interface InitOptions {
|
|
|
81
81
|
* [en]
|
|
82
82
|
* Switch message(info, error, warn) dispaly, default: true
|
|
83
83
|
*/
|
|
84
|
-
debug?: boolean | "all" | "none" | ("info" | "error" | "warn")[];
|
|
84
|
+
debug?: boolean | "all" | "none" | ("info" | "error" | "warn" | "debug" | "fatal")[];
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
export declare type NodeInitOptions = Omit<InitOptions, "project" | "ws_url" | "worklet_url">;
|
|
88
|
+
|
|
87
89
|
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},L=b["__core-js_shared__"],P=(I=/[^.]+$/.exec(L&&L.keys&&L.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"";var C=function(t){return!!P&&P in t},x=Function.prototype.toString;var T=function(t){if(null!=t){try{return x.call(t)}catch(t){}try{return t+""}catch(t){}}return""},U=k,F=C,z=D,W=T,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 Lt=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})},Pt=Object.prototype;var Ct=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Pt)};var xt=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},Ut=N,Ft=Tt;var zt=function(t){return Ft(t)&&"[object Arguments]"==Ut(t)},Wt=Tt,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=Tt,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=xt,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=Lt,Re=At,Me=Ct,Ie=Ee,ke=Object.prototype.hasOwnProperty,Le=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])})),Pe=N,Ce=Tt;var xe=function(t){return"symbol"==typeof t||Ce(t)&&"[object Symbol]"==Pe(t)},Te=Xt,Ue=xe,Fe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ze=/^\w*$/;var We=function(t,e){if(Te(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)},Lr=function(t){return Dr(this,t).has(t)},Pr=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=Lr,Cr.prototype.set=Pr;var xr=Cr,Tr=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||Tr),r}Ur.Cache=Tr;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=xe,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=xe;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}=Le({},this.config);return void 0===t?{specific:!1}:"string"==typeof t?{name:t,id:t,specific:!1}:Le({},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=Tt;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=xe,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 Ln=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 Pn=Gr;var Cn=function(t,e){return Pn(e,function(e){return t[e]})},xn=Ee;var Tn=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=Ln(t),r=e%1;return e==e?r?e-r:e:0},Wn=function(t){return null==t?[]:Cn(t,xn(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&&Tn(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=xr;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},Lo=_e(Object.getPrototypeOf,Object),Po=ko,Co=Lo,xo=Do,To=So,Uo=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Po(e,xo(t)),t=Co(t);return e}:To,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=T,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,Li=function(t){return Di?Object(Di.call(t)):{}},Pi=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 Pi(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 Li(t)}},xi=D,Ti=Object.create,Ui=function(){function t(){}return function(e){if(!xi(e))return{};if(Ti)return Ti(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Fi=Lo,zi=Ct;var Wi=function(t){return"function"!=typeof t.constructor||zi(t)?{}:Ui(Fi(t))},Bi=_i,Gi=Tt;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=Tt;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,La=nn;var Pa=function(t,e){return e=Ma(e,t),null==(t=ka(t,e))||delete t[La(Ia(e))]},Ca=N,xa=Lo,Ta=Tt,Ua=Function.prototype,Fa=Object.prototype,za=Ua.toString,Wa=Fa.hasOwnProperty,Ba=za.call(Object);var Ga=function(t){if(!Ta(t)||"[object Object]"!=Ca(t))return!1;var e=xa(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=Pa,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=xr,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,Ls=Ds,Ps=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,xs=Xt,Ts=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=xs(t),s=xs(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&&Ts(t)){if(!Ts(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):Ls(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),Ps(t,e,r,n,o,i))},$s=Tt;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 Lc=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}}(),Pc=Ee;var Cc=At;var xc=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&&Lc(t,e,Pc)}),Tc=At;var Uc=Gr,Fc=kc,zc=function(t,e){var r=-1,n=Tc(t)?Array(t.length):[];return xc(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("Message proxy to"),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 connection and stop emit event");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(t){this.isStart&&this.socket?.close(t)}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":r.onDestory(),e.emit("channel",n);break;case"reconnect":r.onManualClose(Bc.MANUAL_CLOSE),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.access_token}/${t}`}onDestory(){this.server&&this.server.close()}}class Yc{config;stroage;apiProxy;chat;isStart;destorySub;get destoryObs(){return this.destorySub.asObservable()}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["重複初始化"]);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(Le({},t));Vn(ln(t,"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 e from"fs";import r from"os";import n from"path";import{Subject as o,fromEvent as i,takeUntil as a,take as s}from"rxjs";import c from"axios";import{Server as u}from"socket.io";import f from"ws";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 v="object"==typeof l&&l&&l.Object===Object&&l,p=v,b="object"==typeof self&&self&&self.Object===Object&&self,y=p||b||Function("return this")(),_=y.Symbol,d=_,g=Object.prototype,O=g.hasOwnProperty,j=g.toString,w=d?d.toStringTag:void 0;var A=function(t){var e=O.call(t,w),r=t[w];try{t[w]=void 0;var n=!0}catch(t){}var o=j.call(t);return n&&(e?t[w]=r:delete t[w]),o},S=Object.prototype.toString;var m=A,E=function(t){return S.call(t)},N=_?_.toStringTag:void 0;var D=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":N&&N in Object(t)?m(t):E(t)};var R=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},M=D,k=R;var I,L=function(t){if(!k(t))return!1;var e=M(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},P=y["__core-js_shared__"],C=(I=/[^.]+$/.exec(P&&P.keys&&P.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"";var T=function(t){return!!C&&C in t},x=Function.prototype.toString;var U=function(t){if(null!=t){try{return x.call(t)}catch(t){}try{return t+""}catch(t){}}return""},F=L,z=T,W=R,$=U,B=/^\[object .+?Constructor\]$/,G=Function.prototype,V=Object.prototype,X=G.toString,Y=V.hasOwnProperty,H=RegExp("^"+X.call(Y).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Q=function(t){return!(!W(t)||z(t))&&(F(t)?H:B).test($(t))},K=function(t,e){return null==t?void 0:t[e]};var J=function(t,e){var r=K(t,e);return Q(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)},st=at,ct=et;var ut=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?ct(r,s,c):st(r,s,c)}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 vt=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 s=Array(e+1);++o<e;)s[o]=n[o];return s[e]=r(a),lt(t,this,s)}};var pt=function(t){return function(){return t}},bt=Z,yt=bt?function(t,e){return bt(t,"toString",{configurable:!0,enumerable:!1,value:pt(e),writable:!0})}:ft,_t=Date.now;var dt=function(t){var e=0,r=0;return function(){var n=_t(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(yt),gt=ft,Ot=vt,jt=dt;var wt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},At=L,St=wt;var mt=function(t){return null!=t&&St(t.length)&&!At(t)},Et=/^(?:0|[1-9]\d*)$/;var Nt=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},Dt=rt,Rt=mt,Mt=Nt,kt=R;var It=function(t,e){return jt(Ot(t,e,gt),t+"")},Lt=function(t,e,r){if(!kt(r))return!1;var n=typeof e;return!!("number"==n?Rt(r)&&Mt(e,r.length):"string"==n&&e in r)&&Dt(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&&Lt(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})},Ct=Object.prototype;var Tt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ct)};var xt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var Ut=function(t){return null!=t&&"object"==typeof t},Ft=D,zt=Ut;var Wt=function(t){return zt(t)&&"[object Arguments]"==Ft(t)},$t=Ut,Bt=Object.prototype,Gt=Bt.hasOwnProperty,Vt=Bt.propertyIsEnumerable,Xt=Wt(function(){return arguments}())?Wt:function(t){return $t(t)&&Gt.call(t,"callee")&&!Vt.call(t,"callee")},Yt=Array.isArray,Ht=h(Yt),Qt={exports:{}};var Kt=function(){return!1};!function(t,e){var r=y,n=Kt,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}(Qt,Qt.exports);var Jt=Qt.exports,qt=D,Zt=wt,te=Ut,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=v,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,se=ne,ce=ie&&ie.isTypedArray,ue=ce?se(ce):ae,fe=xt,le=Xt,he=Yt,ve=Jt,pe=Nt,be=ue,ye=Object.prototype.hasOwnProperty;var _e=function(t,e){var r=he(t),n=!r&&le(t),o=!r&&!n&&ve(t),i=!r&&!n&&!o&&be(t),a=r||n||o||i,s=a?fe(t.length,String):[],c=s.length;for(var u in t)!e&&!ye.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||pe(u,c))||s.push(u);return s};var de=function(t,e){return function(r){return t(e(r))}},ge=de(Object.keys,Object),Oe=Tt,je=ge,we=Object.prototype.hasOwnProperty;var Ae=_e,Se=function(t){if(!Oe(t))return je(t);var e=[];for(var r in Object(t))we.call(t,r)&&"constructor"!=r&&e.push(r);return e},me=mt;var Ee=function(t){return me(t)?Ae(t):Se(t)},Ne=at,De=ut,Re=Pt,Me=mt,ke=Tt,Ie=Ee,Le=Object.prototype.hasOwnProperty,Pe=h(Re(function(t,e){if(ke(e)||Me(e))De(e,Ie(e),t);else for(var r in e)Le.call(e,r)&&Ne(t,r,e[r])})),Ce=D,Te=Ut;var xe=function(t){return"symbol"==typeof t||Te(t)&&"[object Symbol]"==Ce(t)},Ue=Yt,Fe=xe,ze=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,We=/^\w*$/;var $e=function(t,e){if(Ue(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Fe(t))||(We.test(t)||!ze.test(t)||null!=e&&t in Object(e))},Be=J(Object,"create"),Ge=Be;var Ve=function(){this.__data__=Ge?Ge(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=Be,He=Object.prototype.hasOwnProperty;var Qe=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},Ke=Be,Je=Object.prototype.hasOwnProperty;var qe=Be;var Ze=Ve,tr=Xe,er=Qe,rr=function(t){var e=this.__data__;return Ke?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},sr=rt;var cr=function(t,e){for(var r=t.length;r--;)if(sr(t[r][0],e))return r;return-1},ur=cr,fr=Array.prototype.splice;var lr=cr;var hr=cr;var vr=cr;var pr=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)},yr=function(t){var e=this.__data__,r=lr(e,t);return r<0?void 0:e[r][1]},_r=function(t){return hr(this.__data__,t)>-1},dr=function(t,e){var r=this.__data__,n=vr(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=pr,gr.prototype.delete=br,gr.prototype.get=yr,gr.prototype.has=_r,gr.prototype.set=dr;var Or=gr,jr=J(y,"Map"),wr=ir,Ar=Or,Sr=jr;var mr=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 mr(e)?r["string"==typeof e?"string":"hash"]:r.map},Nr=Er;var Dr=Er;var Rr=Er;var Mr=Er;var kr=function(){this.size=0,this.__data__={hash:new wr,map:new(Sr||Ar),string:new wr}},Ir=function(t){var e=Nr(this,t).delete(t);return this.size-=e?1:0,e},Lr=function(t){return Dr(this,t).get(t)},Pr=function(t){return Rr(this,t).has(t)},Cr=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=kr,Tr.prototype.delete=Ir,Tr.prototype.get=Lr,Tr.prototype.has=Pr,Tr.prototype.set=Cr;var xr=Tr,Ur=xr;function Fr(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(Fr.Cache||Ur),r}Fr.Cache=Ur;var zr=Fr;var Wr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,$r=/\\(\\)?/g,Br=function(t){var e=zr(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($r,"$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},Vr=Gr,Xr=Yt,Yr=xe,Hr=_?_.prototype:void 0,Qr=Hr?Hr.toString:void 0;var Kr=function t(e){if("string"==typeof e)return e;if(Xr(e))return Vr(e,t)+"";if(Yr(e))return Qr?Qr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Jr=Kr;var qr=Yt,Zr=$e,tn=Br,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,sn=on;var cn=function(t,e){for(var r=0,n=(e=an(e,t)).length;null!=t&&r<n;)t=t[sn(e[r++])];return r&&r==n?t:void 0},un=cn;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: 205"}(fn||(fn={}));const vn="access_token",pn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class bn{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(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??!0}constructor(t){this.config=t}}var yn=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},_n=function(t){return t!=t},dn=function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1};var gn=D,On=Yt,jn=Ut;var wn=/\s/;var An=function(t){for(var e=t.length;e--&&wn.test(t.charAt(e)););return e},Sn=/^\s+/;var mn=function(t){return t?t.slice(0,An(t)+1).replace(Sn,""):t},En=R,Nn=xe,Dn=/^[-+]0x[0-9a-f]+$/i,Rn=/^0b[01]+$/i,Mn=/^0o[0-7]+$/i,kn=parseInt;var In=function(t){if("number"==typeof t)return t;if(Nn(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=mn(t);var r=Rn.test(t);return r||Mn.test(t)?kn(t.slice(2),r?2:8):Dn.test(t)?NaN:+t},Ln=1/0;var Pn=function(t){return t?(t=In(t))===Ln||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Cn=Gr;var Tn=function(t,e){return Cn(e,function(e){return t[e]})},xn=Ee;var Un=function(t,e,r){return e==e?dn(t,e,r):yn(t,_n,r)},Fn=mt,zn=function(t){return"string"==typeof t||!On(t)&&jn(t)&&"[object String]"==gn(t)},Wn=function(t){var e=Pn(t),r=e%1;return e==e?r?e-r:e:0},$n=function(t){return null==t?[]:Tn(t,xn(t))},Bn=Math.max;var Gn=h(function(t,e,r,n){t=Fn(t)?t:$n(t),r=r&&!n?Wn(r):0;var o=t.length;return r<0&&(r=Bn(o+r,0)),zn(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&Un(t,e,r)>-1});const Vn={debug:()=>{},info:()=>{},error:()=>{},warn:()=>{},fatal:()=>{}};function Xn(){return t().format("yyyy-MM-DD[T]HH:mm:ss")}function Yn(t){const{info:e,error:r,warn:n,debug:o,fatal:i}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0,debug:!0,fatal:!0}:"none"===t?{error:!1,warn:!1,info:!1,debug:!1,fatal:!1}:"boolean"==typeof t?{error:t,warn:t,info:t,debug:t,fatal:t}:{debug:Gn(t,"debug"),fatal:Gn(t,"fatal"),error:Gn(t,"error"),warn:Gn(t,"warn"),info:Gn(t,"info")}}(t);o&&(Vn.debug=(...t)=>{const e=Xn();console.log(`[Aiia::debug_${e}_]`,...t)}),e&&(Vn.info=(...t)=>{const e=Xn();console.log(`[Aiia::info_${e}_]`,...t)}),n&&(Vn.warn=(...t)=>{const e=Xn();console.warn(`[Aiia::warn_${e}_]`,...t)}),r&&(Vn.error=(...t)=>{const e=Xn();console.error(`[Aiia::error_${e}_]`,...t)}),i&&(Vn.fatal=(...t)=>{const e=Xn();console.error(`[Aiia::fatal_${e}_]`,...t)})}var Hn=Or;var Qn=Or,Kn=jr,Jn=xr;var qn=Or,Zn=function(){this.__data__=new Hn,this.size=0},to=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},eo=function(t){return this.__data__.get(t)},ro=function(t){return this.__data__.has(t)},no=function(t,e){var r=this.__data__;if(r instanceof Qn){var n=r.__data__;if(!Kn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Jn(n)}return r.set(t,e),this.size=r.size,this};function oo(t){var e=this.__data__=new qn(t);this.size=e.size}oo.prototype.clear=Zn,oo.prototype.delete=to,oo.prototype.get=eo,oo.prototype.has=ro,oo.prototype.set=no;var io=oo;var ao=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t},so=ut,co=Ee;var uo=function(t,e){return t&&so(e,co(e),t)};var fo=R,lo=Tt,ho=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},vo=Object.prototype.hasOwnProperty;var po=_e,bo=function(t){if(!fo(t))return ho(t);var e=lo(t),r=[];for(var n in t)("constructor"!=n||!e&&vo.call(t,n))&&r.push(n);return r},yo=mt;var _o=function(t){return yo(t)?po(t,!0):bo(t)},go=ut,Oo=_o;var jo=function(t,e){return t&&go(e,Oo(e),t)},wo={exports:{}};!function(t,e){var r=y,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n?r.Buffer:void 0,a=i?i.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var r=t.length,n=a?a(r):new t.constructor(r);return t.copy(n),n}}(wo,wo.exports);var Ao=wo.exports;var So=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e};var mo=function(){return[]},Eo=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},No=mo,Do=Object.prototype.propertyIsEnumerable,Ro=Object.getOwnPropertySymbols,Mo=Ro?function(t){return null==t?[]:(t=Object(t),Eo(Ro(t),function(e){return Do.call(t,e)}))}:No,ko=ut,Io=Mo;var Lo=function(t,e){return ko(t,Io(t),e)};var Po=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Co=de(Object.getPrototypeOf,Object),To=Po,xo=Co,Uo=Mo,Fo=mo,zo=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)To(e,Uo(t)),t=xo(t);return e}:Fo,Wo=ut,$o=zo;var Bo=function(t,e){return Wo(t,$o(t),e)},Go=Po,Vo=Yt;var Xo=function(t,e,r){var n=e(t);return Vo(t)?n:Go(n,r(t))},Yo=Xo,Ho=Mo,Qo=Ee;var Ko=function(t){return Yo(t,Qo,Ho)},Jo=Xo,qo=zo,Zo=_o;var ti=function(t){return Jo(t,Zo,qo)},ei=J(y,"DataView"),ri=jr,ni=J(y,"Promise"),oi=J(y,"Set"),ii=J(y,"WeakMap"),ai=D,si=U,ci="[object Map]",ui="[object Promise]",fi="[object Set]",li="[object WeakMap]",hi="[object DataView]",vi=si(ei),pi=si(ri),bi=si(ni),yi=si(oi),_i=si(ii),di=ai;(ei&&di(new ei(new ArrayBuffer(1)))!=hi||ri&&di(new ri)!=ci||ni&&di(ni.resolve())!=ui||oi&&di(new oi)!=fi||ii&&di(new ii)!=li)&&(di=function(t){var e=ai(t),r="[object Object]"==e?t.constructor:void 0,n=r?si(r):"";if(n)switch(n){case vi:return hi;case pi:return ci;case bi:return ui;case yi:return fi;case _i:return li}return e});var gi=di,Oi=Object.prototype.hasOwnProperty;var ji=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Oi.call(t,"index")&&(r.index=t.index,r.input=t.input),r},wi=y.Uint8Array,Ai=wi;var Si=function(t){var e=new t.constructor(t.byteLength);return new Ai(e).set(new Ai(t)),e},mi=Si;var Ei=function(t,e){var r=e?mi(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},Ni=/\w*$/;var Di=function(t){var e=new t.constructor(t.source,Ni.exec(t));return e.lastIndex=t.lastIndex,e},Ri=_?_.prototype:void 0,Mi=Ri?Ri.valueOf:void 0;var ki=Si;var Ii=Si,Li=Ei,Pi=Di,Ci=function(t){return Mi?Object(Mi.call(t)):{}},Ti=function(t,e){var r=e?ki(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var xi=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return Ii(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return Li(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 Ti(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 Pi(t);case"[object Symbol]":return Ci(t)}},Ui=R,Fi=Object.create,zi=function(){function t(){}return function(e){if(!Ui(e))return{};if(Fi)return Fi(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Wi=Co,$i=Tt;var Bi=function(t){return"function"!=typeof t.constructor||$i(t)?{}:zi(Wi(t))},Gi=gi,Vi=Ut;var Xi=function(t){return Vi(t)&&"[object Map]"==Gi(t)},Yi=ne,Hi=ie&&ie.isMap,Qi=Hi?Yi(Hi):Xi,Ki=gi,Ji=Ut;var qi=function(t){return Ji(t)&&"[object Set]"==Ki(t)},Zi=ne,ta=ie&&ie.isSet,ea=ta?Zi(ta):qi,ra=io,na=ao,oa=at,ia=uo,aa=jo,sa=Ao,ca=So,ua=Lo,fa=Bo,la=Ko,ha=ti,va=gi,pa=ji,ba=xi,ya=Bi,_a=Yt,da=Jt,ga=Qi,Oa=R,ja=ea,wa=Ee,Aa=_o,Sa="[object Arguments]",ma="[object Function]",Ea="[object Object]",Na={};Na[Sa]=Na["[object Array]"]=Na["[object ArrayBuffer]"]=Na["[object DataView]"]=Na["[object Boolean]"]=Na["[object Date]"]=Na["[object Float32Array]"]=Na["[object Float64Array]"]=Na["[object Int8Array]"]=Na["[object Int16Array]"]=Na["[object Int32Array]"]=Na["[object Map]"]=Na["[object Number]"]=Na[Ea]=Na["[object RegExp]"]=Na["[object Set]"]=Na["[object String]"]=Na["[object Symbol]"]=Na["[object Uint8Array]"]=Na["[object Uint8ClampedArray]"]=Na["[object Uint16Array]"]=Na["[object Uint32Array]"]=!0,Na["[object Error]"]=Na[ma]=Na["[object WeakMap]"]=!1;var Da=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(!Oa(e))return e;var l=_a(e);if(l){if(s=pa(e),!c)return ca(e,s)}else{var h=va(e),v=h==ma||"[object GeneratorFunction]"==h;if(da(e))return sa(e,c);if(h==Ea||h==Sa||v&&!i){if(s=u||v?{}:ya(e),!c)return u?fa(e,aa(s,e)):ua(e,ia(s,e))}else{if(!Na[h])return i?e:{};s=ba(e,h,c)}}a||(a=new ra);var p=a.get(e);if(p)return p;a.set(e,s),ja(e)?e.forEach(function(o){s.add(t(o,r,n,o,e,a))}):ga(e)&&e.forEach(function(o,i){s.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?ha:la:u?Aa:wa)(e);return na(b||e,function(o,i){b&&(o=e[i=o]),oa(s,i,t(o,r,n,i,e,a))}),s};var Ra=cn,Ma=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 ka=function(t,e){return e.length<2?t:Ra(t,Ma(e,0,-1))},Ia=rn,La=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},Pa=ka,Ca=on;var Ta=function(t,e){return e=Ia(e,t),null==(t=Pa(t,e))||delete t[Ca(La(e))]},xa=D,Ua=Co,Fa=Ut,za=Function.prototype,Wa=Object.prototype,$a=za.toString,Ba=Wa.hasOwnProperty,Ga=$a.call(Object);var Va=function(t){if(!Fa(t)||"[object Object]"!=xa(t))return!1;var e=Ua(t);if(null===e)return!0;var r=Ba.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&$a.call(r)==Ga};var Xa=function(t){return Va(t)?void 0:t},Ya=Xt,Ha=Yt,Qa=_?_.isConcatSpreadable:void 0;var Ka=Po,Ja=function(t){return Ha(t)||Ya(t)||!!(Qa&&t&&t[Qa])};var qa=function t(e,r,n,o,i){var a=-1,s=e.length;for(n||(n=Ja),i||(i=[]);++a<s;){var c=e[a];r>0&&n(c)?r>1?t(c,r-1,n,o,i):Ka(i,c):o||(i[i.length]=c)}return i},Za=qa;var ts=function(t){return(null==t?0:t.length)?Za(t,1):[]},es=vt,rs=dt;var ns=Gr,os=Da,is=Ta,as=rn,ss=ut,cs=Xa,us=ti,fs=function(t){return rs(es(t,void 0,ts),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=ns(e,function(e){return e=as(e,t),n||(n=e.length>1),e}),ss(t,us(t),r),n&&(r=os(r,7,cs));for(var o=e.length;o--;)is(r,e[o]);return r}),ls=h(fs);const hs=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=r.homedir(),this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=n.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||n.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||n.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=n.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return n.join(...t)}folderCheck(t){e.mkdirSync(t,{recursive:!0})}fileCheck(t){e.existsSync(t)||e.writeFileSync(t,"",{encoding:"utf8"})}}("aiia-sdk");class vs{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=hs.addPath(hs.appFolder,this.fileName),hs.fileCheck(this.filePath)}getFileDataSync(){const t=e.readFileSync(this.filePath,"utf8");try{return JSON.parse(t)}catch(t){return{}}}setFileDataSync(t){try{const r=JSON.stringify(t);e.writeFileSync(this.filePath,r,"utf8")}catch(t){}}async getFileData(){return new Promise(t=>{e.readFile(this.filePath,"utf8",(e,r)=>{if(e)t({});else try{t(JSON.parse(r))}catch(e){t({})}})})}async setFileData(t){return new Promise(r=>{try{const n=JSON.stringify(t);e.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=ls(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=ls(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}var ps=xr,bs=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ys=function(t){return this.__data__.has(t)};function _s(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new ps;++e<r;)this.add(t[e])}_s.prototype.add=_s.prototype.push=bs,_s.prototype.has=ys;var ds=_s,gs=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},Os=function(t,e){return t.has(e)};var js=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 ds: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(!gs(e,function(t,e){if(!Os(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 ws=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var As=wi,Ss=rt,ms=js,Es=ws,Ns=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},Ds=_?_.prototype:void 0,Rs=Ds?Ds.valueOf:void 0;var Ms=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 As(t),new As(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Ss(+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=Es;case"[object Set]":var c=1&n;if(s||(s=Ns),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=ms(s(t),s(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(Rs)return Rs.call(t)==Rs.call(e)}return!1},ks=Ko,Is=Object.prototype.hasOwnProperty;var Ls=io,Ps=js,Cs=Ms,Ts=function(t,e,r,n,o,i){var a=1&r,s=ks(t),c=s.length;if(c!=ks(e).length&&!a)return!1;for(var u=c;u--;){var f=s[u];if(!(a?f in e:Is.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},xs=gi,Us=Yt,Fs=Jt,zs=ue,Ws="[object Arguments]",$s="[object Array]",Bs="[object Object]",Gs=Object.prototype.hasOwnProperty;var Vs=function(t,e,r,n,o,i){var a=Us(t),s=Us(e),c=a?$s:xs(t),u=s?$s:xs(e),f=(c=c==Ws?Bs:c)==Bs,l=(u=u==Ws?Bs:u)==Bs,h=c==u;if(h&&Fs(t)){if(!Fs(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Ls),a||zs(t)?Ps(t,e,r,n,o,i):Cs(t,e,c,r,n,o,i);if(!(1&r)){var v=f&&Gs.call(t,"__wrapped__"),p=l&&Gs.call(e,"__wrapped__");if(v||p){var b=v?t.value():t,y=p?e.value():e;return i||(i=new Ls),o(b,y,r,n,i)}}return!!h&&(i||(i=new Ls),Ts(t,e,r,n,o,i))},Xs=Ut;var Ys=function t(e,r,n,o,i){return e===r||(null==e||null==r||!Xs(e)&&!Xs(r)?e!=e&&r!=r:Vs(e,r,n,o,t,i))},Hs=io,Qs=Ys;var Ks=R;var Js=function(t){return t==t&&!Ks(t)},qs=Js,Zs=Ee;var tc=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},ec=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 Hs;if(n)var h=n(u,f,c,t,e,l);if(!(void 0===h?Qs(f,u,3,n,l):h))return!1}}return!0},rc=function(t){for(var e=Zs(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,qs(o)]}return e},nc=tc;var oc=rn,ic=Xt,ac=Yt,sc=Nt,cc=wt,uc=on;var fc=function(t,e,r){for(var n=-1,o=(e=oc(e,t)).length,i=!1;++n<o;){var a=uc(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&cc(o)&&sc(a,o)&&(ac(t)||ic(t))},lc=function(t,e){return null!=t&&e in Object(t)},hc=fc;var vc=function(t,e){return null!=t&&hc(t,e,lc)},pc=Ys,bc=ln,yc=vc,_c=$e,dc=Js,gc=tc,Oc=on;var jc=function(t,e){return _c(t)&&dc(e)?gc(Oc(t),e):function(r){var n=bc(r,t);return void 0===n&&n===e?yc(r,t):pc(e,n,3)}};var wc=cn;var Ac=function(t){return function(e){return wc(e,t)}},Sc=function(t){return function(e){return null==e?void 0:e[t]}},mc=Ac,Ec=$e,Nc=on;var Dc=function(t){return Ec(t)?Sc(Nc(t)):mc(t)},Rc=function(t){var e=rc(t);return 1==e.length&&e[0][2]?nc(e[0][0],e[0][1]):function(r){return r===t||ec(r,t,e)}},Mc=jc,kc=ft,Ic=Yt,Lc=Dc;var Pc=function(t){return"function"==typeof t?t:null==t?kc:"object"==typeof t?Ic(t)?Mc(t[0],t[1]):Rc(t):Lc(t)};var Cc=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}}(),Tc=Ee;var xc=mt;var Uc=function(t,e){return function(r,n){if(null==r)return r;if(!xc(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&&Cc(t,e,Tc)}),Fc=mt;var zc=Gr,Wc=Pc,$c=function(t,e){var r=-1,n=Fc(t)?Array(t.length):[];return Uc(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Bc=Yt;var Gc,Vc=h(function(t,e){return(Bc(t)?zc:$c)(t,Wc(e))});class Xc{instance;controller;constructor(t){this.controller=new AbortController,this.instance=c.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=>Vc(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"}(Gc||(Gc={}));class Yc{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 o,this.startLinkSub=new o,this.closeSub=new o,this.destorySub=new o}start(t){this.isStart=!0,this.socket=new f(t,{autoPong:!0}),i(this.socket,"open").pipe(a(this.destorySub)).subscribe(t=>{this.isConnected=!0,this.startLinkSub.next(),Vn.info("Proxy startup"),this.flushMessageQueue()}),i(this.socket,"message").pipe(a(this.destorySub)).subscribe(t=>{const{data:e}=t;this.messageSub.next(e)}),i(this.socket,"error").pipe(a(this.destorySub)).subscribe(t=>{const{error:e}=t;Vn.error("Proxy has some problem",e)}),i(this.socket,"close").pipe(a(this.destorySub)).subscribe(t=>{this.isConnected=!1;const{code:e}=t;switch(e){case Gc.MANUAL_CLOSE:Vn.debug("MANUAL_CLOSE stop emit event and reconnecting");break;case Gc.WS_5000_NORAML_CLOSURE:case Gc.MDN_NORMAL_CLOSURE:case Gc.MDN_GOING_AWAY:this.closeSub.next("close"),Vn.debug("Safe close connection");break;case Gc.MDN_NO_STATUS_RECEIVED:case Gc.MDN_ABNORMAL_CLOSURE:this.closeSub.next("close"),Vn.warn("Cloud disconnect",{code:e},t);break;case Gc.WS_5001_UNAUTHORIZED:case Gc.WS_5002_LICENSE_EXPIRED:this.closeSub.next("no_permissions"),Vn.warn("Please contact Graphen");break;case Gc.WS_5003_TOKEN_EXPIRED:this.closeSub.next("reconnect"),Vn.debug("Reconnect");break;default:this.closeSub.next("close"),Vn.error("Other status always close connection",{code:e})}})}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(Gc.MANUAL_CLOSE)}onDestory(){this.destorySub.next(),this.destorySub.complete()}}class Hc{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 u(this.webserver,{cors:{origin:"*"}}),this.server.on("connection",t=>{const e=new o;let r=(n=t.handshake.query.uuid,Ht(n)?hn(n,"[0]",void 0):n??void 0);var n;const c=new Yc;Vn.debug("client on",t.id),void 0===r?(this.sdk.getProjectList().then(e=>{t.emit("list",e)}),i(t,"uuid").pipe(s(1),a(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(),Vn.debug("client off",t)})}),void 0===this.webserver&&this.server.listen(this.port)}openChannel(t,e,r,n){i(e,"cloud").pipe(a(n)).subscribe(t=>{r.send(t)}),r.message.pipe(a(n)).subscribe(t=>{e.emit("cloud",t)}),r.close.pipe(a(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(a(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 Qc{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 o,this.access_token=e.getItemSync(vn),this.apiProxy=new Xc(this.config.endPoint.api),Vn.info("[Initialize] proxy is finished"),this.chat=new Hc(this),Vn.info("[Initialize] chat is finished","Start at PORT:",this.config.port)}async start(){if(this.isStart)throw new Error(fn["重複初始化"]);this.isStart=!0,await this.replaceAccessToken(),this.chat.start(),Vn.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(vn,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(),Vn.info("[Destory] core module done")}}function Kc(t){if(pn){if(void 0===hn(t,"license",void 0))throw new Error(fn["未提供憑證"]);Vn.info("Initialize necessary modules");const e=new bn(Pe({},t));Yn(e.debug),Vn.info("config finished");const r=new vs;Vn.info("storage finished");const n=new Qc(e,r);return Vn.info("core finished"),n.start(),Vn.info("Service startup"),()=>{n.onDestory()}}throw new Error(fn["環境錯誤(nodejs)"])}export{Kc as aiiaCore};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphen.ai/aiia-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jay Huang",
|
|
7
7
|
"email": "jayhuang@graphen.ai"
|
|
8
8
|
},
|
|
9
|
-
"license": "
|
|
9
|
+
"license": "MIT",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
"./browser": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
|
35
|
+
"NOTICE",
|
|
35
36
|
"tsdoc-metadata.json"
|
|
36
37
|
],
|
|
37
38
|
"scripts": {
|
|
@@ -50,20 +51,18 @@
|
|
|
50
51
|
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
51
52
|
"@rollup/plugin-terser": "^0.4.4",
|
|
52
53
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
53
|
-
"@types/cors": "^2.8.19",
|
|
54
54
|
"@types/lodash": "^4.17.20",
|
|
55
55
|
"@types/node": "^24.2.1",
|
|
56
56
|
"@types/ws": "^8.18.1",
|
|
57
57
|
"rollup": "^4.46.2",
|
|
58
58
|
"rollup-plugin-javascript-obfuscator": "^1.0.1",
|
|
59
|
-
"tsc-alias": "^1.8.16",
|
|
60
59
|
"tslib": "^2.6.2",
|
|
61
60
|
"typescript": "^5.9.2"
|
|
62
61
|
},
|
|
63
62
|
"dependencies": {
|
|
64
63
|
"axios": "^1.11.0",
|
|
65
|
-
"cors": "^2.8.5",
|
|
66
64
|
"lodash": "^4.17.21",
|
|
65
|
+
"moment": "^2.30.1",
|
|
67
66
|
"rxjs": "^7.8.2",
|
|
68
67
|
"socket.io": "^4.8.1",
|
|
69
68
|
"socket.io-client": "^4.8.1",
|