@graphen.ai/aiia-sdk 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -166,9 +166,7 @@ declare interface InitOptions {
166
166
  debug?: boolean | "all" | "none" | ("info" | "error" | "warn")[];
167
167
  }
168
168
 
169
- export declare function initSdk(options?: Omit<InitOptions, "webserver" | "port"> & {
170
- workletUrl?: string | undefined;
171
- }): AiiaSdk;
169
+ export declare function initSdk(options?: Omit<InitOptions, "webserver" | "port">): AiiaSdk;
172
170
 
173
171
  declare type LayoutID = string | number;
174
172
 
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,T=I,x=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!(!x(t)||T(t))&&(C(t)?$:F).test(U(t))},X=function(t,e){return null==t?void 0:t[e]};var Y=function(t,e){var r=X(t,e);return V(r)?r:void 0},q=Y,H=function(){try{var t=q(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Q=H;var K=function(t,e,r){"__proto__"==e&&Q?Q(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var J=function(t,e){return t===e||t!=t&&e!=e},Z=K,tt=J,et=Object.prototype.hasOwnProperty;var rt=function(t,e,r){var n=t[e];et.call(t,e)&&tt(n,r)&&(void 0!==r||e in t)||Z(t,e,r)},nt=rt,ot=K;var it=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var s=e[i],c=n?n(r[s],t[s],s,r,t):void 0;void 0===c&&(c=t[s]),o?ot(r,s,c):nt(r,s,c)}return r};var at=function(t){return t};var st=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},ct=Math.max;var ut=function(t,e,r){return e=ct(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=ct(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var s=Array(e+1);++o<e;)s[o]=n[o];return s[e]=r(a),st(t,this,s)}};var ft=function(t){return function(){return t}},lt=H,ht=lt?function(t,e){return lt(t,"toString",{configurable:!0,enumerable:!1,value:ft(e),writable:!0})}:at,vt=Date.now;var pt=function(t){var e=0,r=0;return function(){var n=vt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ht),bt=at,yt=ut,_t=pt;var dt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},gt=R,jt=dt;var Ot=function(t){return null!=t&&jt(t.length)&&!gt(t)},St=/^(?:0|[1-9]\d*)$/;var wt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&St.test(t))&&t>-1&&t%1==0&&t<e},At=J,Et=Ot,Nt=wt,mt=E;var Dt=function(t,e){return _t(yt(t,e,bt),t+"")},Rt=function(t,e,r){if(!mt(r))return!1;var n=typeof e;return!!("number"==n?Et(r)&&Nt(e,r.length):"string"==n&&e in r)&&At(r[e],t)};var kt=function(t){return Dt(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,a&&Rt(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var s=r[n];s&&t(e,s,n,i)}return e})},Mt=Object.prototype;var It=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Mt)};var 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,Tt=Pt;var xt=function(t){return Tt(t)&&"[object Arguments]"==Ct(t)},Ut=Pt,Ft=Object.prototype,zt=Ft.hasOwnProperty,Wt=Ft.propertyIsEnumerable,Bt=xt(function(){return arguments}())?xt:function(t){return Ut(t)&&zt.call(t,"callee")&&!Wt.call(t,"callee")},Gt=Array.isArray,$t=c(Gt),Vt={exports:{}};var Xt=function(){return!1};!function(t,e){var r=h,n=Xt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,s=(a?a.isBuffer:void 0)||n;t.exports=s}(Vt,Vt.exports);var Yt=Vt.exports,qt=A,Ht=dt,Qt=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,Te=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,xe=/^\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))||(xe.test(t)||!Te.test(t)||null!=e&&t in Object(e))},Fe=Y(Object,"create"),ze=Fe;var We=function(){this.__data__=ze?ze(null):{},this.size=0};var Be=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ge=Fe,$e=Object.prototype.hasOwnProperty;var Ve=function(t){var e=this.__data__;if(Ge){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return $e.call(e,t)?e[t]:void 0},Xe=Fe,Ye=Object.prototype.hasOwnProperty;var qe=Fe;var He=We,Qe=Be,Ke=Ve,Je=function(t){var e=this.__data__;return Xe?void 0!==e[t]:Ye.call(e,t)},Ze=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=qe&&void 0===e?"__lodash_hash_undefined__":e,this};function tr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}tr.prototype.clear=He,tr.prototype.delete=Qe,tr.prototype.get=Ke,tr.prototype.has=Je,tr.prototype.set=Ze;var er=tr;var rr=function(){this.__data__=[],this.size=0},nr=J;var or=function(t,e){for(var r=t.length;r--;)if(nr(t[r][0],e))return r;return-1},ir=or,ar=Array.prototype.splice;var sr=or;var cr=or;var ur=or;var fr=rr,lr=function(t){var e=this.__data__,r=ir(e,t);return!(r<0)&&(r==e.length-1?e.pop():ar.call(e,r,1),--this.size,!0)},hr=function(t){var e=this.__data__,r=sr(e,t);return r<0?void 0:e[r][1]},vr=function(t){return cr(this.__data__,t)>-1},pr=function(t,e){var r=this.__data__,n=ur(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function br(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}br.prototype.clear=fr,br.prototype.delete=lr,br.prototype.get=hr,br.prototype.has=vr,br.prototype.set=pr;var yr=br,_r=Y(h,"Map"),dr=er,gr=yr,jr=_r;var Or=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Sr=function(t,e){var r=t.__data__;return Or(e)?r["string"==typeof e?"string":"hash"]:r.map},wr=Sr;var Ar=Sr;var Er=Sr;var Nr=Sr;var mr=function(){this.size=0,this.__data__={hash:new dr,map:new(jr||gr),string:new dr}},Dr=function(t){var e=wr(this,t).delete(t);return this.size-=e?1:0,e},Rr=function(t){return Ar(this,t).get(t)},kr=function(t){return Er(this,t).has(t)},Mr=function(t,e){var r=Nr(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Ir(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Ir.prototype.clear=mr,Ir.prototype.delete=Dr,Ir.prototype.get=Rr,Ir.prototype.has=kr,Ir.prototype.set=Mr;var 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 Tr=Cr;var xr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ur=/\\(\\)?/g,Fr=function(t){var e=Tr(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(xr,function(t,r,n,o){e.push(n?o.replace(Ur,"$1"):r||t)}),e});var zr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},Wr=zr,Br=Gt,Gr=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,Tn=function(t){return"string"==typeof t||!yn(t)&&_n(t)&&"[object String]"==bn(t)},xn=function(t){var e=kn(t),r=e%1;return e==e?r?e-r:e:0},Un=function(t){return null==t?[]:In(t,Ln(t))},Fn=Math.max;var zn=c(function(t,e,r,n){t=Cn(t)?t:Un(t),r=r&&!n?xn(r):0;var o=t.length;return r<0&&(r=Fn(o+r,0)),Tn(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&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,To=it,xo=Co;var Uo=function(t,e){return To(t,xo(t),e)},Fo=Ro,zo=Gt;var Wo=function(t,e,r){var n=e(t);return zo(t)?n:Fo(n,r(t))},Bo=Wo,Go=Eo,$o=Se;var Vo=function(t){return Bo(t,$o,Go)},Xo=Wo,Yo=Co,qo=ho;var Ho=function(t){return Xo(t,qo,Yo)},Qo=Y(h,"DataView"),Ko=_r,Jo=Y(h,"Promise"),Zo=Y(h,"Set"),ti=Y(h,"WeakMap"),ei=A,ri=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}}(),Ti=ko,xi=It;var Ui=function(t){return"function"!=typeof t.constructor||xi(t)?{}:Ci(Ti(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,Ta=Object.prototype,xa=Ca.toString,Ua=Ta.hasOwnProperty,Fa=xa.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&&xa.call(r)==Fa};var Wa=function(t){return za(t)?void 0:t},Ba=Bt,Ga=Gt,$a=v?v.isConcatSpreadable:void 0;var Va=Ro,Xa=function(t){return Ga(t)||Ba(t)||!!($a&&t&&t[$a])};var Ya=function t(e,r,n,o,i){var a=-1,s=e.length;for(n||(n=Xa),i||(i=[]);++a<s;){var c=e[a];r>0&&n(c)?r>1?t(c,r-1,n,o,i):Va(i,c):o||(i[i.length]=c)}return i},qa=Ya;var Ha=function(t){return(null==t?0:t.length)?qa(t,1):[]},Qa=ut,Ka=pt;var Ja=zr,Za=wa,ts=Ma,es=Jr,rs=it,ns=Wa,os=Ho,is=function(t){return Ka(Qa(t,void 0,Ha),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=Ja(e,function(e){return e=es(e,t),n||(n=e.length>1),e}),rs(t,os(t),r),n&&(r=Za(r,7,ns));for(var o=e.length;o--;)ts(r,e[o]);return r}),as=c(is);const ss=new class{AppName;platform;isMAC;isWIN;isLINUX;saveFolder;homedir;appFolder;constructor(t){switch(this.AppName=t,this.platform=process.platform,this.homedir=e.homedir(),this.platform){case"darwin":this.isMAC=!0,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=r.join(this.homedir,"Library","Application Support");break;case"win32":this.isMAC=!1,this.isWIN=!0,this.isLINUX=!1,this.saveFolder=process.env.APPDATA||r.join(this.homedir,"AppData","Roaming");break;case"linux":this.isMAC=!1,this.isWIN=!1,this.isLINUX=!0,this.saveFolder=process.env.XDG_CONFIG_HOME||r.join(this.homedir,".config");break;default:console.log(`當前系統是未知的平台: ${this.platform}`),this.isMAC=!1,this.isWIN=!1,this.isLINUX=!1,this.saveFolder=this.homedir}this.appFolder=r.join(this.saveFolder,this.AppName),this.folderCheck(this.appFolder)}addPath(...t){return r.join(...t)}folderCheck(e){t.mkdirSync(e,{recursive:!0})}fileCheck(e){t.existsSync(e)||t.writeFileSync(e,"",{encoding:"utf8"})}}("aiia-sdk");class cs{type="node";filePath;fileName;constructor(){this.fileName="storage.json",this.filePath=ss.addPath(ss.appFolder,this.fileName),ss.fileCheck(this.filePath)}getFileDataSync(){const e=t.readFileSync(this.filePath,"utf8");try{return JSON.parse(e)}catch(t){return{}}}setFileDataSync(e){try{const r=JSON.stringify(e);t.writeFileSync(this.filePath,r,"utf8")}catch(t){}}async getFileData(){return new Promise(e=>{t.readFile(this.filePath,"utf8",(t,r)=>{if(t)e({});else try{e(JSON.parse(r))}catch(t){e({})}})})}async setFileData(e){return new Promise(r=>{try{const n=JSON.stringify(e);t.writeFile(this.filePath,n,"utf8",t=>{r()})}catch(t){}})}async getItem(t){return(await this.getFileData())[t]??null}async setItem(t,e){const r=await this.getFileData();r[t]=e,await this.setFileData(r)}async removeItem(t){const e=await this.getFileData(),r=as(e,t);await this.setFileData(r)}async clear(){await this.setFileData({})}getItemSync(t){return this.getFileDataSync()[t]??null}setItemSync(t,e){const r=this.getFileDataSync();r[t]=e,this.setFileDataSync(r)}removeItemSync(t){const e=as(this.getFileDataSync(),t);this.setFileDataSync(e)}clearSync(){this.setFileDataSync({})}}var us=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,Ts="[object Arguments]",xs="[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?xs:Is(t),u=s?xs:Is(e),f=(c=c==Ts?Us:c)==Us,l=(u=u==Ts?Us:u)==Us,h=c==u;if(h&&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,Tc=Rc,xc=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:xc)(t,Tc(e))});class Wc{instance;controller;constructor(t){this.controller=new AbortController,this.instance=o.create({baseURL:t,signal:this.controller.signal})}async getAccessToken(t,e){const r={license_number:t,token_value:e??""},n=await this.instance.post("/api/v1/license/agent_token",r).then(t=>cn(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(an["網絡錯誤"]);if(""===n)throw new Error(an["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>zc(cn(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(an["網絡錯誤"]);if(0===e.length)throw new Error(an["沒有可用專案"]);return e}onDestory(){this.controller.abort()}}!function(t){t[t.MDN_NORMAL_CLOSURE=1e3]="MDN_NORMAL_CLOSURE",t[t.MDN_GOING_AWAY=1001]="MDN_GOING_AWAY",t[t.MDN_PROTOCOL_ERROR=1002]="MDN_PROTOCOL_ERROR",t[t.MDN_UNSUPPORTED_DATA=1003]="MDN_UNSUPPORTED_DATA",t[t.MDN_RESERVED_1004=1004]="MDN_RESERVED_1004",t[t.MDN_NO_STATUS_RECEIVED=1005]="MDN_NO_STATUS_RECEIVED",t[t.MDN_ABNORMAL_CLOSURE=1006]="MDN_ABNORMAL_CLOSURE",t[t.MDN_INVALID_FRAME_PAYLOAD=1007]="MDN_INVALID_FRAME_PAYLOAD",t[t.MDN_POLICY_VIOLATION=1008]="MDN_POLICY_VIOLATION",t[t.MDN_MESSAGE_TOO_BIG=1009]="MDN_MESSAGE_TOO_BIG",t[t.MDN_MANDATORY_EXTENSION=1010]="MDN_MANDATORY_EXTENSION",t[t.MDN_INTERNAL_ERROR=1011]="MDN_INTERNAL_ERROR",t[t.MDN_SERVICE_RESTART=1012]="MDN_SERVICE_RESTART",t[t.MDN_TRY_AGAIN_LATER=1013]="MDN_TRY_AGAIN_LATER",t[t.MDN_BAD_GATEWAY=1014]="MDN_BAD_GATEWAY",t[t.MDN_TLS_HANDSHAKE=1015]="MDN_TLS_HANDSHAKE",t[t.MANUAL_CLOSE=4001]="MANUAL_CLOSE",t[t.WS_5000_NORAML_CLOSURE=5e3]="WS_5000_NORAML_CLOSURE",t[t.WS_5001_UNAUTHORIZED=5001]="WS_5001_UNAUTHORIZED",t[t.WS_5002_LICENSE_EXPIRED=5002]="WS_5002_LICENSE_EXPIRED",t[t.WS_5003_TOKEN_EXPIRED=5003]="WS_5003_TOKEN_EXPIRED"}(Fc||(Fc={}));class Bc{socket;messageSub;startLinkSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get startLink(){return this.startLinkSub.asObservable()}messageQueue=[];isConnected;isStart;constructor(){this.isConnected=!1,this.isStart=!1,this.messageSub=new n.Subject,this.startLinkSub=new n.Subject,this.closeSub=new n.Subject,this.destorySub=new n.Subject}start(t){this.isStart=!0,this.socket=new a(t),Wn.info("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?(t.emit("list",[]),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}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("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)"])};
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},T=Function.prototype.toString;var x=function(t){if(null!=t){try{return T.call(t)}catch(t){}try{return t+""}catch(t){}}return""},U=k,F=C,z=D,W=x,B=/^\[object .+?Constructor\]$/,G=Function.prototype,$=Object.prototype,V=G.toString,X=$.hasOwnProperty,Y=RegExp("^"+V.call(X).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var H=function(t){return!(!z(t)||F(t))&&(U(t)?Y:B).test(W(t))},Q=function(t,e){return null==t?void 0:t[e]};var K=function(t,e){var r=Q(t,e);return H(r)?r:void 0},J=K,q=function(){try{var t=J(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Z=q;var tt=function(t,e,r){"__proto__"==e&&Z?Z(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var et=function(t,e){return t===e||t!=t&&e!=e},rt=tt,nt=et,ot=Object.prototype.hasOwnProperty;var it=function(t,e,r){var n=t[e];ot.call(t,e)&&nt(n,r)&&(void 0!==r||e in t)||rt(t,e,r)},at=it,st=tt;var ct=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var s=e[i],c=n?n(r[s],t[s],s,r,t):void 0;void 0===c&&(c=t[s]),o?st(r,s,c):at(r,s,c)}return r};var ut=function(t){return t};var ft=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},lt=Math.max;var ht=function(t,e,r){return e=lt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=lt(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var s=Array(e+1);++o<e;)s[o]=n[o];return s[e]=r(a),ft(t,this,s)}};var vt=function(t){return function(){return t}},pt=q,bt=pt?function(t,e){return pt(t,"toString",{configurable:!0,enumerable:!1,value:vt(e),writable:!0})}:ut,yt=Date.now;var _t=function(t){var e=0,r=0;return function(){var n=yt(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(bt),dt=ut,gt=ht,Ot=_t;var jt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},wt=k,St=jt;var At=function(t){return null!=t&&St(t.length)&&!wt(t)},Et=/^(?:0|[1-9]\d*)$/;var mt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Et.test(t))&&t>-1&&t%1==0&&t<e},Nt=et,Dt=At,Rt=mt,Mt=D;var It=function(t,e){return Ot(gt(t,e,dt),t+"")},kt=function(t,e,r){if(!Mt(r))return!1;var n=typeof e;return!!("number"==n?Dt(r)&&Rt(e,r.length):"string"==n&&e in r)&&Nt(r[e],t)};var 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 Tt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var xt=function(t){return null!=t&&"object"==typeof t},Ut=N,Ft=xt;var zt=function(t){return Ft(t)&&"[object Arguments]"==Ut(t)},Wt=xt,Bt=Object.prototype,Gt=Bt.hasOwnProperty,$t=Bt.propertyIsEnumerable,Vt=zt(function(){return arguments}())?zt:function(t){return Wt(t)&&Gt.call(t,"callee")&&!$t.call(t,"callee")},Xt=Array.isArray,Yt=l(Xt),Ht={exports:{}};var Qt=function(){return!1};!function(t,e){var r=b,n=Qt,o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,a=i&&i.exports===o?r.Buffer:void 0,s=(a?a.isBuffer:void 0)||n;t.exports=s}(Ht,Ht.exports);var Kt=Ht.exports,Jt=N,qt=jt,Zt=xt,te={};te["[object Float32Array]"]=te["[object Float64Array]"]=te["[object Int8Array]"]=te["[object Int16Array]"]=te["[object Int32Array]"]=te["[object Uint8Array]"]=te["[object Uint8ClampedArray]"]=te["[object Uint16Array]"]=te["[object Uint32Array]"]=!0,te["[object Arguments]"]=te["[object Array]"]=te["[object ArrayBuffer]"]=te["[object Boolean]"]=te["[object DataView]"]=te["[object Date]"]=te["[object Error]"]=te["[object Function]"]=te["[object Map]"]=te["[object Number]"]=te["[object Object]"]=te["[object RegExp]"]=te["[object Set]"]=te["[object String]"]=te["[object WeakMap]"]=!1;var ee=function(t){return Zt(t)&&qt(t.length)&&!!te[Jt(t)]};var re=function(t){return function(e){return t(e)}},ne={exports:{}};!function(t,e){var r=h,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n&&r.process,a=function(){try{var t=o&&o.require&&o.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=a}(ne,ne.exports);var oe=ne.exports,ie=ee,ae=re,se=oe&&oe.isTypedArray,ce=se?ae(se):ie,ue=Tt,fe=Vt,le=Xt,he=Kt,ve=mt,pe=ce,be=Object.prototype.hasOwnProperty;var ye=function(t,e){var r=le(t),n=!r&&fe(t),o=!r&&!n&&he(t),i=!r&&!n&&!o&&pe(t),a=r||n||o||i,s=a?ue(t.length,String):[],c=s.length;for(var u in t)!e&&!be.call(t,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||ve(u,c))||s.push(u);return s};var _e=function(t,e){return function(r){return t(e(r))}},de=_e(Object.keys,Object),ge=Ct,Oe=de,je=Object.prototype.hasOwnProperty;var we=ye,Se=function(t){if(!ge(t))return Oe(t);var e=[];for(var r in Object(t))je.call(t,r)&&"constructor"!=r&&e.push(r);return e},Ae=At;var Ee=function(t){return Ae(t)?we(t):Se(t)},me=it,Ne=ct,De=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=xt;var Te=function(t){return"symbol"==typeof t||Ce(t)&&"[object Symbol]"==Pe(t)},xe=Xt,Ue=Te,Fe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ze=/^\w*$/;var We=function(t,e){if(xe(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Ue(t))||(ze.test(t)||!Fe.test(t)||null!=e&&t in Object(e))},Be=K(Object,"create"),Ge=Be;var $e=function(){this.__data__=Ge?Ge(null):{},this.size=0};var Ve=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Xe=Be,Ye=Object.prototype.hasOwnProperty;var He=function(t){var e=this.__data__;if(Xe){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Ye.call(e,t)?e[t]:void 0},Qe=Be,Ke=Object.prototype.hasOwnProperty;var Je=Be;var qe=$e,Ze=Ve,tr=He,er=function(t){var e=this.__data__;return Qe?void 0!==e[t]:Ke.call(e,t)},rr=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Je&&void 0===e?"__lodash_hash_undefined__":e,this};function nr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}nr.prototype.clear=qe,nr.prototype.delete=Ze,nr.prototype.get=tr,nr.prototype.has=er,nr.prototype.set=rr;var or=nr;var ir=function(){this.__data__=[],this.size=0},ar=et;var sr=function(t,e){for(var r=t.length;r--;)if(ar(t[r][0],e))return r;return-1},cr=sr,ur=Array.prototype.splice;var fr=sr;var lr=sr;var hr=sr;var vr=ir,pr=function(t){var e=this.__data__,r=cr(e,t);return!(r<0)&&(r==e.length-1?e.pop():ur.call(e,r,1),--this.size,!0)},br=function(t){var e=this.__data__,r=fr(e,t);return r<0?void 0:e[r][1]},yr=function(t){return lr(this.__data__,t)>-1},_r=function(t,e){var r=this.__data__,n=hr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function dr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}dr.prototype.clear=vr,dr.prototype.delete=pr,dr.prototype.get=br,dr.prototype.has=yr,dr.prototype.set=_r;var gr=dr,Or=K(b,"Map"),jr=or,wr=gr,Sr=Or;var Ar=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Er=function(t,e){var r=t.__data__;return Ar(e)?r["string"==typeof e?"string":"hash"]:r.map},mr=Er;var Nr=Er;var Dr=Er;var Rr=Er;var Mr=function(){this.size=0,this.__data__={hash:new jr,map:new(Sr||wr),string:new jr}},Ir=function(t){var e=mr(this,t).delete(t);return this.size-=e?1:0,e},kr=function(t){return Nr(this,t).get(t)},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 Tr=Cr,xr=Tr;function Ur(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Ur.Cache||xr),r}Ur.Cache=xr;var Fr=Ur;var zr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Wr=/\\(\\)?/g,Br=function(t){var e=Fr(t,function(t){return 500===r.size&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(zr,function(t,r,n,o){e.push(n?o.replace(Wr,"$1"):r||t)}),e});var Gr=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},$r=Gr,Vr=Xt,Xr=Te,Yr=y?y.prototype:void 0,Hr=Yr?Yr.toString:void 0;var Qr=function t(e){if("string"==typeof e)return e;if(Vr(e))return $r(e,t)+"";if(Xr(e))return Hr?Hr.call(e):"";var r=e+"";return"0"==r&&1/e==-1/0?"-0":r},Kr=Qr;var Jr=Xt,qr=We,Zr=Br,tn=function(t){return null==t?"":Kr(t)};var en=function(t,e){return Jr(t)?t:qr(t,e)?[t]:Zr(tn(t))},rn=Te;var nn=function(t){if("string"==typeof t||rn(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e},on=en,an=nn;var sn=function(t,e){for(var r=0,n=(e=on(e,t)).length;null!=t&&r<n;)t=t[an(e[r++])];return r&&r==n?t:void 0},cn=sn;var un,fn=function(t,e,r){var n=null==t?void 0:cn(t,e);return void 0===n?r:n},ln=l(fn);!function(t){t["網絡錯誤"]="ERROR CODE: 500",t["環境錯誤(browser)"]="ERROR CODE: 1001",t["Worklet模組載入失敗"]="ERROR CODE: 1002",t["未獲得媒體裝置權限"]="ERROR CODE: 1003",t["實例已摧毀"]="ERROR CODE: 1004",t["環境錯誤(nodejs)"]="ERROR CODE: 2001",t["未提供憑證"]="ERROR CODE: 2002",t["獲取權杖失敗"]="ERROR CODE: 2003",t["沒有可用專案"]="ERROR CODE: 2004",t["重複初始化"]="ERROR CODE: 205"}(un||(un={}));const hn="access_token",vn="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node;class pn{config;get webserver(){return this.config.webserver}get environment(){return this.config.env}get license(){return this.config.license??""}get port(){return function(t,e){const r=e??NaN;if(t){const e=parseInt(t);return isNaN(e)?r:e}return r}(process.env.PORT,this.config.port??3e3)}get ws_url(){return this.config.ws_url??""}get worklet_url(){return this.config.worklet_url??""}get project(){const{project:t}=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=xt;var jn=/\s/;var wn=function(t){for(var e=t.length;e--&&jn.test(t.charAt(e)););return e},Sn=/^\s+/;var An=function(t){return t?t.slice(0,wn(t)+1).replace(Sn,""):t},En=D,mn=Te,Nn=/^[-+]0x[0-9a-f]+$/i,Dn=/^0b[01]+$/i,Rn=/^0o[0-7]+$/i,Mn=parseInt;var In=function(t){if("number"==typeof t)return t;if(mn(t))return NaN;if(En(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=En(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=An(t);var r=Dn.test(t);return r||Rn.test(t)?Mn(t.slice(2),r?2:8):Nn.test(t)?NaN:+t},kn=1/0;var 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]})},Tn=Ee;var xn=function(t,e,r){return e==e?_n(t,e,r):bn(t,yn,r)},Un=At,Fn=function(t){return"string"==typeof t||!gn(t)&&On(t)&&"[object String]"==dn(t)},zn=function(t){var e=Ln(t),r=e%1;return e==e?r?e-r:e:0},Wn=function(t){return null==t?[]:Cn(t,Tn(t))},Bn=Math.max;var Gn=l(function(t,e,r,n){t=Un(t)?t:Wn(t),r=r&&!n?zn(r):0;var o=t.length;return r<0&&(r=Bn(o+r,0)),Fn(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&xn(t,e,r)>-1});const $n={info:()=>{},error:()=>{},warn:()=>{}};function Vn(t){const{info:e,error:r,warn:n}=function(t){return void 0===t||"all"===t?{error:!0,warn:!0,info:!0}:"none"===t?{error:!1,warn:!1,info:!1}:"boolean"==typeof t?{error:t,warn:t,info:t}:{error:Gn(t,"error"),warn:Gn(t,"warn"),info:Gn(t,"info")}}(t);e&&($n.info=console.log),r&&($n.error=console.error),n&&($n.warn=console.warn)}var Xn=gr;var Yn=gr,Hn=Or,Qn=Tr;var Kn=gr,Jn=function(){this.__data__=new Xn,this.size=0},qn=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Zn=function(t){return this.__data__.get(t)},to=function(t){return this.__data__.has(t)},eo=function(t,e){var r=this.__data__;if(r instanceof Yn){var n=r.__data__;if(!Hn||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Qn(n)}return r.set(t,e),this.size=r.size,this};function ro(t){var e=this.__data__=new Kn(t);this.size=e.size}ro.prototype.clear=Jn,ro.prototype.delete=qn,ro.prototype.get=Zn,ro.prototype.has=to,ro.prototype.set=eo;var no=ro;var oo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t},io=ct,ao=Ee;var so=function(t,e){return t&&io(e,ao(e),t)};var co=D,uo=Ct,fo=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e},lo=Object.prototype.hasOwnProperty;var ho=ye,vo=function(t){if(!co(t))return fo(t);var e=uo(t),r=[];for(var n in t)("constructor"!=n||!e&&lo.call(t,n))&&r.push(n);return r},po=At;var bo=function(t){return po(t)?ho(t,!0):vo(t)},yo=ct,_o=bo;var go=function(t,e){return t&&yo(e,_o(e),t)},Oo={exports:{}};!function(t,e){var r=b,n=e&&!e.nodeType&&e,o=n&&t&&!t.nodeType&&t,i=o&&o.exports===n?r.Buffer:void 0,a=i?i.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var r=t.length,n=a?a(r):new t.constructor(r);return t.copy(n),n}}(Oo,Oo.exports);var jo=Oo.exports;var wo=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e};var So=function(){return[]},Ao=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i},Eo=So,mo=Object.prototype.propertyIsEnumerable,No=Object.getOwnPropertySymbols,Do=No?function(t){return null==t?[]:(t=Object(t),Ao(No(t),function(e){return mo.call(t,e)}))}:Eo,Ro=ct,Mo=Do;var Io=function(t,e){return Ro(t,Mo(t),e)};var ko=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Lo=_e(Object.getPrototypeOf,Object),Po=ko,Co=Lo,To=Do,xo=So,Uo=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Po(e,To(t)),t=Co(t);return e}:xo,Fo=ct,zo=Uo;var Wo=function(t,e){return Fo(t,zo(t),e)},Bo=ko,Go=Xt;var $o=function(t,e,r){var n=e(t);return Go(t)?n:Bo(n,r(t))},Vo=$o,Xo=Do,Yo=Ee;var Ho=function(t){return Vo(t,Yo,Xo)},Qo=$o,Ko=Uo,Jo=bo;var qo=function(t){return Qo(t,Jo,Ko)},Zo=K(b,"DataView"),ti=Or,ei=K(b,"Promise"),ri=K(b,"Set"),ni=K(b,"WeakMap"),oi=N,ii=x,ai="[object Map]",si="[object Promise]",ci="[object Set]",ui="[object WeakMap]",fi="[object DataView]",li=ii(Zo),hi=ii(ti),vi=ii(ei),pi=ii(ri),bi=ii(ni),yi=oi;(Zo&&yi(new Zo(new ArrayBuffer(1)))!=fi||ti&&yi(new ti)!=ai||ei&&yi(ei.resolve())!=si||ri&&yi(new ri)!=ci||ni&&yi(new ni)!=ui)&&(yi=function(t){var e=oi(t),r="[object Object]"==e?t.constructor:void 0,n=r?ii(r):"";if(n)switch(n){case li:return fi;case hi:return ai;case vi:return si;case pi:return ci;case bi:return ui}return e});var _i=yi,di=Object.prototype.hasOwnProperty;var gi=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&di.call(t,"index")&&(r.index=t.index,r.input=t.input),r},Oi=b.Uint8Array,ji=Oi;var wi=function(t){var e=new t.constructor(t.byteLength);return new ji(e).set(new ji(t)),e},Si=wi;var Ai=function(t,e){var r=e?Si(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)},Ei=/\w*$/;var mi=function(t){var e=new t.constructor(t.source,Ei.exec(t));return e.lastIndex=t.lastIndex,e},Ni=y?y.prototype:void 0,Di=Ni?Ni.valueOf:void 0;var Ri=wi;var Mi=wi,Ii=Ai,ki=mi,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)}},Ti=D,xi=Object.create,Ui=function(){function t(){}return function(e){if(!Ti(e))return{};if(xi)return xi(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Fi=Lo,zi=Ct;var Wi=function(t){return"function"!=typeof t.constructor||zi(t)?{}:Ui(Fi(t))},Bi=_i,Gi=xt;var $i=function(t){return Gi(t)&&"[object Map]"==Bi(t)},Vi=re,Xi=oe&&oe.isMap,Yi=Xi?Vi(Xi):$i,Hi=_i,Qi=xt;var Ki=function(t){return Qi(t)&&"[object Set]"==Hi(t)},Ji=re,qi=oe&&oe.isSet,Zi=qi?Ji(qi):Ki,ta=no,ea=oo,ra=it,na=so,oa=go,ia=jo,aa=wo,sa=Io,ca=Wo,ua=Ho,fa=qo,la=_i,ha=gi,va=Ci,pa=Wi,ba=Xt,ya=Kt,_a=Yi,da=D,ga=Zi,Oa=Ee,ja=bo,wa="[object Arguments]",Sa="[object Function]",Aa="[object Object]",Ea={};Ea[wa]=Ea["[object Array]"]=Ea["[object ArrayBuffer]"]=Ea["[object DataView]"]=Ea["[object Boolean]"]=Ea["[object Date]"]=Ea["[object Float32Array]"]=Ea["[object Float64Array]"]=Ea["[object Int8Array]"]=Ea["[object Int16Array]"]=Ea["[object Int32Array]"]=Ea["[object Map]"]=Ea["[object Number]"]=Ea[Aa]=Ea["[object RegExp]"]=Ea["[object Set]"]=Ea["[object String]"]=Ea["[object Symbol]"]=Ea["[object Uint8Array]"]=Ea["[object Uint8ClampedArray]"]=Ea["[object Uint16Array]"]=Ea["[object Uint32Array]"]=!0,Ea["[object Error]"]=Ea[Sa]=Ea["[object WeakMap]"]=!1;var ma=function t(e,r,n,o,i,a){var s,c=1&r,u=2&r,f=4&r;if(n&&(s=i?n(e,o,i,a):n(e)),void 0!==s)return s;if(!da(e))return e;var l=ba(e);if(l){if(s=ha(e),!c)return aa(e,s)}else{var h=la(e),v=h==Sa||"[object GeneratorFunction]"==h;if(ya(e))return ia(e,c);if(h==Aa||h==wa||v&&!i){if(s=u||v?{}:pa(e),!c)return u?ca(e,oa(s,e)):sa(e,na(s,e))}else{if(!Ea[h])return i?e:{};s=va(e,h,c)}}a||(a=new ta);var p=a.get(e);if(p)return p;a.set(e,s),ga(e)?e.forEach(function(o){s.add(t(o,r,n,o,e,a))}):_a(e)&&e.forEach(function(o,i){s.set(i,t(o,r,n,i,e,a))});var b=l?void 0:(f?u?fa:ua:u?ja:Oa)(e);return ea(b||e,function(o,i){b&&(o=e[i=o]),ra(s,i,t(o,r,n,i,e,a))}),s};var Na=sn,Da=function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i};var Ra=function(t,e){return e.length<2?t:Na(t,Da(e,0,-1))},Ma=en,Ia=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0},ka=Ra,La=nn;var Pa=function(t,e){return e=Ma(e,t),null==(t=ka(t,e))||delete t[La(Ia(e))]},Ca=N,Ta=Lo,xa=xt,Ua=Function.prototype,Fa=Object.prototype,za=Ua.toString,Wa=Fa.hasOwnProperty,Ba=za.call(Object);var Ga=function(t){if(!xa(t)||"[object Object]"!=Ca(t))return!1;var e=Ta(t);if(null===e)return!0;var r=Wa.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&za.call(r)==Ba};var $a=function(t){return Ga(t)?void 0:t},Va=Vt,Xa=Xt,Ya=y?y.isConcatSpreadable:void 0;var Ha=ko,Qa=function(t){return Xa(t)||Va(t)||!!(Ya&&t&&t[Ya])};var Ka=function t(e,r,n,o,i){var a=-1,s=e.length;for(n||(n=Qa),i||(i=[]);++a<s;){var c=e[a];r>0&&n(c)?r>1?t(c,r-1,n,o,i):Ha(i,c):o||(i[i.length]=c)}return i},Ja=Ka;var qa=function(t){return(null==t?0:t.length)?Ja(t,1):[]},Za=ht,ts=_t;var es=Gr,rs=ma,ns=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=Tr,vs=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ps=function(t){return this.__data__.has(t)};function bs(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new hs;++e<r;)this.add(t[e])}bs.prototype.add=bs.prototype.push=vs,bs.prototype.has=ps;var ys=bs,_s=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},ds=function(t,e){return t.has(e)};var gs=function(t,e,r,n,o,i){var a=1&r,s=t.length,c=e.length;if(s!=c&&!(a&&c>s))return!1;var u=i.get(t),f=i.get(e);if(u&&f)return u==e&&f==t;var l=-1,h=!0,v=2&r?new ys:void 0;for(i.set(t,e),i.set(e,t);++l<s;){var p=t[l],b=e[l];if(n)var y=a?n(b,p,l,e,t,i):n(p,b,l,t,e,i);if(void 0!==y){if(y)continue;h=!1;break}if(v){if(!_s(e,function(t,e){if(!ds(v,e)&&(p===t||o(p,t,r,n,i)))return v.push(e)})){h=!1;break}}else if(p!==b&&!o(p,b,r,n,i)){h=!1;break}}return i.delete(t),i.delete(e),h};var Os=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r};var js=Oi,ws=et,Ss=gs,As=Os,Es=function(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r},ms=y?y.prototype:void 0,Ns=ms?ms.valueOf:void 0;var Ds=function(t,e,r,n,o,i,a){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!i(new js(t),new js(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return ws(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var s=As;case"[object Set]":var c=1&n;if(s||(s=Es),t.size!=e.size&&!c)return!1;var u=a.get(t);if(u)return u==e;n|=2,a.set(t,e);var f=Ss(s(t),s(e),n,o,i,a);return a.delete(t),f;case"[object Symbol]":if(Ns)return Ns.call(t)==Ns.call(e)}return!1},Rs=Ho,Ms=Object.prototype.hasOwnProperty;var Is=no,ks=gs,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,Ts=Xt,xs=Kt,Us=ce,Fs="[object Arguments]",zs="[object Array]",Ws="[object Object]",Bs=Object.prototype.hasOwnProperty;var Gs=function(t,e,r,n,o,i){var a=Ts(t),s=Ts(e),c=a?zs:Cs(t),u=s?zs:Cs(e),f=(c=c==Fs?Ws:c)==Ws,l=(u=u==Fs?Ws:u)==Ws,h=c==u;if(h&&xs(t)){if(!xs(e))return!1;a=!0,f=!1}if(h&&!f)return i||(i=new Is),a||Us(t)?ks(t,e,r,n,o,i):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=xt;var Vs=function t(e,r,n,o,i){return e===r||(null==e||null==r||!$s(e)&&!$s(r)?e!=e&&r!=r:Gs(e,r,n,o,t,i))},Xs=no,Ys=Vs;var Hs=D;var Qs=function(t){return t==t&&!Hs(t)},Ks=Qs,Js=Ee;var qs=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Zs=function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var s=r[o];if(a&&s[2]?s[1]!==t[s[0]]:!(s[0]in t))return!1}for(;++o<i;){var c=(s=r[o])[0],u=t[c],f=s[1];if(a&&s[2]){if(void 0===u&&!(c in t))return!1}else{var l=new Xs;if(n)var h=n(u,f,c,t,e,l);if(!(void 0===h?Ys(f,u,3,n,l):h))return!1}}return!0},tc=function(t){for(var e=Js(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Ks(o)]}return e},ec=qs;var rc=en,nc=Vt,oc=Xt,ic=mt,ac=jt,sc=nn;var cc=function(t,e,r){for(var n=-1,o=(e=rc(e,t)).length,i=!1;++n<o;){var a=sc(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&ac(o)&&ic(a,o)&&(oc(t)||nc(t))},uc=function(t,e){return null!=t&&e in Object(t)},fc=cc;var lc=function(t,e){return null!=t&&fc(t,e,uc)},hc=Vs,vc=fn,pc=lc,bc=We,yc=Qs,_c=qs,dc=nn;var gc=function(t,e){return bc(t)&&yc(e)?_c(dc(t),e):function(r){var n=vc(r,t);return void 0===n&&n===e?pc(r,t):hc(e,n,3)}};var Oc=sn;var jc=function(t){return function(e){return Oc(e,t)}},wc=function(t){return function(e){return null==e?void 0:e[t]}},Sc=jc,Ac=We,Ec=nn;var mc=function(t){return Ac(t)?wc(Ec(t)):Sc(t)},Nc=function(t){var e=tc(t);return 1==e.length&&e[0][2]?ec(e[0][0],e[0][1]):function(r){return r===t||Zs(r,t,e)}},Dc=gc,Rc=ut,Mc=Xt,Ic=mc;var kc=function(t){return"function"==typeof t?t:null==t?Rc:"object"==typeof t?Mc(t)?Dc(t[0],t[1]):Nc(t):Ic(t)};var 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 Tc=function(t,e){return function(r,n){if(null==r)return r;if(!Cc(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}(function(t,e){return t&&Lc(t,e,Pc)}),xc=At;var Uc=Gr,Fc=kc,zc=function(t,e){var r=-1,n=xc(t)?Array(t.length):[];return Tc(t,function(t,o,i){n[++r]=e(t,o,i)}),n},Wc=Xt;var Bc,Gc=l(function(t,e){return(Wc(t)?Uc:zc)(t,Fc(e))});class $c{instance;controller;constructor(t){this.controller=new AbortController,this.instance=s.create({baseURL:t,signal:this.controller.signal})}async getAccessToken(t,e){const r={license_number:t,token_value:e??""},n=await this.instance.post("/api/v1/license/agent_token",r).then(t=>ln(t.data,"token_value","")).catch(()=>null);if(null===n)throw new Error(un["網絡錯誤"]);if(""===n)throw new Error(un["獲取權杖失敗"]);return n}async getProjectList(t){const e=await this.instance.post("/api/v1/license/projects",{license_number:t}).then(t=>Gc(ln(t,"data.projects",[]),({id:t,sub_project_name:e})=>({id:t,name:e}))).catch(t=>null);if(null===e)throw new Error(un["網絡錯誤"]);if(0===e.length)throw new Error(un["沒有可用專案"]);return e}onDestory(){this.controller.abort()}}!function(t){t[t.MDN_NORMAL_CLOSURE=1e3]="MDN_NORMAL_CLOSURE",t[t.MDN_GOING_AWAY=1001]="MDN_GOING_AWAY",t[t.MDN_PROTOCOL_ERROR=1002]="MDN_PROTOCOL_ERROR",t[t.MDN_UNSUPPORTED_DATA=1003]="MDN_UNSUPPORTED_DATA",t[t.MDN_RESERVED_1004=1004]="MDN_RESERVED_1004",t[t.MDN_NO_STATUS_RECEIVED=1005]="MDN_NO_STATUS_RECEIVED",t[t.MDN_ABNORMAL_CLOSURE=1006]="MDN_ABNORMAL_CLOSURE",t[t.MDN_INVALID_FRAME_PAYLOAD=1007]="MDN_INVALID_FRAME_PAYLOAD",t[t.MDN_POLICY_VIOLATION=1008]="MDN_POLICY_VIOLATION",t[t.MDN_MESSAGE_TOO_BIG=1009]="MDN_MESSAGE_TOO_BIG",t[t.MDN_MANDATORY_EXTENSION=1010]="MDN_MANDATORY_EXTENSION",t[t.MDN_INTERNAL_ERROR=1011]="MDN_INTERNAL_ERROR",t[t.MDN_SERVICE_RESTART=1012]="MDN_SERVICE_RESTART",t[t.MDN_TRY_AGAIN_LATER=1013]="MDN_TRY_AGAIN_LATER",t[t.MDN_BAD_GATEWAY=1014]="MDN_BAD_GATEWAY",t[t.MDN_TLS_HANDSHAKE=1015]="MDN_TLS_HANDSHAKE",t[t.MANUAL_CLOSE=4001]="MANUAL_CLOSE",t[t.WS_5000_NORAML_CLOSURE=5e3]="WS_5000_NORAML_CLOSURE",t[t.WS_5001_UNAUTHORIZED=5001]="WS_5001_UNAUTHORIZED",t[t.WS_5002_LICENSE_EXPIRED=5002]="WS_5002_LICENSE_EXPIRED",t[t.WS_5003_TOKEN_EXPIRED=5003]="WS_5003_TOKEN_EXPIRED"}(Bc||(Bc={}));class Vc{socket;messageSub;startLinkSub;destorySub;closeSub;get message(){return this.messageSub.asObservable()}get close(){return this.closeSub.asObservable()}get startLink(){return this.startLinkSub.asObservable()}messageQueue=[];isConnected;isStart;constructor(){this.isConnected=!1,this.isStart=!1,this.messageSub=new n,this.startLinkSub=new n,this.closeSub=new n,this.destorySub=new n}start(t){this.isStart=!0,this.socket=new u(t),$n.info("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?(t.emit("list",[]),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}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"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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphen.ai/aiia-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "Jay Huang",
@@ -41,7 +41,8 @@
41
41
  "watch": "rollup -c -w",
42
42
  "types:extract": "npm run types:extract:browser && npm run types:extract:node && npm run clean:type",
43
43
  "types:extract:browser": "api-extractor run --local --config api-extractor.browser.json",
44
- "types:extract:node": "api-extractor run --local --config api-extractor.node.json"
44
+ "types:extract:node": "api-extractor run --local --config api-extractor.node.json",
45
+ "publish": "npm run build && npm publish --access public"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@microsoft/api-extractor": "^7.52.11",