((e,t)=>{"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MpaasAtb=t():e.MpaasAtb=t()})(window,function(){return o=[function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,o){var r=o(3);function n(e,t){for(var o=0;o",t);if(t&&t.interactiveConfigResult){var o=t.interactiveConfigResult;var n=o.bubbleConfig||[];if(typeof n==="string"){n=JSON.parse(n);o.bubbleConfig=n}var r=o.componentConfig||[];if(typeof r==="string"){r=JSON.parse(r);o.componentConfig=r}f.interactiveConfig=o;if(o.humanId)f.avatarId=o.humanId;if(o.chatConfig){var a=JSON.parse(o.chatConfig);if(a&&a.libraryIds)f.libraryIds=a.libraryIds}if(o.llmChatCode)f.llmChatCode=o.llmChatCode;var s=r.filter(function(e,t){return e.code.indexOf("bizType")!==-1});if(s&&s[0]){var i=s[0].value;if(i.length>0)f.llmType=i}var l=r.filter(function(e,t){return e.code.indexOf("userId")!==-1});if(l&&l[0]){var u=l[0].value;if(u.length>0)f.appId=u}}else console.log("[2D][LLM] interactiveConfigResult is null");if(d)d(e)}else{console.log("[2D][LLM] interactive result is null, interactiveCode = ",f.interactCode);if(d)d(e)}})});(0,c["default"])(this,"initAsr",function(){var e=f.aiHost+"/asr/getToken?tenantCode="+f.tenantCode;p.requestBase(e,"GET",{},function(e){if(e&&e.success){console.log("[2D][LLM] asr result: ",e);if(e.appKeys.length>0){var t=e.appKeys;var o=JSON.parse(t);f.asrKeys=o}if(e.appToken.length>0)f.asrtoken=e.appToken;if(f.onGetTokenSuccess)f.onGetTokenSuccess()}else console.log("[2D][LLM] asr result is null")})});(0,c["default"])(this,"onReceiveMessage",function(e){if(e&&e.detail&&e.detail.message){var t=JSON.parse(e.detail.message);if(t){if(t.type=="current_status"){var o=t.data;if(o.status==="speak"){console.log(v()+"[2D][LLM] avatar play begin");f.clearTimerId();if(f.onAvatarPlayBegin)f.onAvatarPlayBegin()}else if(o.status==="silent"){console.log(v()+"[2D][LLM] avatar paly end");if(!f.timerId)f.setTimerId();if(f.onAvatarPlayEnd)f.onAvatarPlayEnd()}}else if(t.type=="current_text"){var n=t.data;if(n&&n.text&&f.onAvatarMessage){console.log(v()+"[2D][LLM] current_result=",n.text);var r={text:n.text,eventStreamResp:f.llmResult.eventStreamResp?f.llmResult.eventStreamResp:{},chatSessionId:f.llmResult.chatSessionId?f.llmResult.chatSessionId:"",sessionId:f.llmResult.sessionId?f.llmResult.sessionId:""};f.onAvatarMessage(r)}}}else f.loggerError(50010003,"[2D][LLM] avatar event result is null")}});(0,c["default"])(this,"onError",function(e){console.log(v()+"onError, e="+JSON.stringify(e))});(0,c["default"])(this,"onRoomInfo",function(e){console.log(v()+" onRoomInfo, e="+JSON.stringify(e))});(0,c["default"])(this,"onEnterRoom",function(e){console.log(v()+" onEnterRoom, e="+JSON.stringify(e))});(0,c["default"])(this,"onFirstRender",function(e){console.log(v()+" onFirstRender"+JSON.stringify(e));f.isLiving=true;if(f.onInitSuccess)f.onInitSuccess(f.streamId)});(0,c["default"])(this,"setTimerId",function(){if(f.overtimeInterval<0)return;f.timerId=setTimeout(function(){if(f.isLiving){console.log(v()+"[2D][LLM] trigger auto resetAll with timerId=",f.timerId);f.clearTimerId();if(f.onOverTimeTrigger)f.onOverTimeTrigger(f.streamId)}},f.overtimeInterval*1e3);console.log(v()+"[2D][LLM] setTimerId="+f.streamId+", timerId="+f.timerId)});(0,c["default"])(this,"clearTimerId",function(){if(f.timerId){console.log(v()+"[2D][LLM] clear timerId=",f.timerId);clearTimeout(f.timerId);f.timerId=null}});(0,c["default"])(this,"initWssServer",function(e){var t=true?f.aiHost.substring(8):undefined;var o={tenantCode:f.tenantCode,configCode:f.interactCode,avatarId:f.avatarId,llmType:f.llmType,llmChatCode:f.llmChatCode,libraryIds:f.libraryIds,streamId:e,shengjiAppId:f.appId,wssHost:"wss://"+t};p.initWSS(o,f.onWsMessage)});(0,c["default"])(this,"startLive",function(t){var e=f.aiHost+"/llm/startRtsLive";var o={shengjiAppId:f.appId,tenantCode:f.tenantCode,avatarId:f.avatarId,background:f.interactiveConfig.bgImg,webrtcType:"mrtc"};console.log(v()+"[2D][LLM] start live data: ",o);p.requestBase(e,"POST",o,function(e){console.log(v()+"[2D][LLM] end live result: ",e);if(e&&e.streamId&&e.webrtcInfo){f.initWssServer(e.streamId);f.streamId=e.streamId;t(e);setTimeout(function(){f.joinRoom(e.webrtcInfo)},.5*1e3)}else if(e&&!e.success&&e.resultMsg==="auth check fail"){f.loggerError("3001","auth check fail");t(e)}else{f.loggerError("3002","result error = ",e.message);t(e)}})});(0,c["default"])(this,"sendText",function(e,t){if(!e)return;f.clearTimerId();console.log(v()+"[2D][LLM] send text:",e);p.sendQuery(e,t)});(0,c["default"])(this,"interruptBoardcast",function(){if(f.streamId.length>0)p.interrunptChat();else console.log(v()+"[2D][LLM] stop live streamId is empty")});(0,c["default"])(this,"stopLive",function(r){return new Promise(function(t,e){if(r&&r.length<=0)if(f.streamId&&f.streamId.length>0)r=f.streamId;else{console.log(v()+"[2D][LLM] stop live streamId is empty");t("streamId is empty")}console.log(v()+"[2D][LLM] stop live streamId =",r);if(f.isLiving)f.isLiving=false;if(f.isASR)f.stopAsr();f.clearTimerId();if(f.rtcroomContext)f.rtcroomContext.stop();var o=f.aiHost+"/llm/stopRtsLive";var n={shengjiAppId:f.appId,tenantCode:f.tenantCode,streamId:r};p.requestBase(o,"POST",n,function(e){if(e&&e.success){console.log(v()+"[2D][LLM] stop success="+e.success);p.closeWss();r="";f.streamId=""}else if(e&&!e.success&&e.resultMsg==="auth check fail")f.loggerError("3001","auth check fail");t(e)})})});(0,c["default"])(this,"refreshToken",function(e){if(e&&e.length>0){f.token=e;p.token=f.token}});(0,c["default"])(this,"startAsr",function(){f.isASR=true;m.startAsr()});(0,c["default"])(this,"stopAsr",function(){f.isASR=false;m.stopAsr()});(0,c["default"])(this,"loggerError",function(e,t,o){console.log(v()+"[2D][LLM] errorCode="+e+", errorMessage="+t);var n={errorCode:e,errorMessage:t,type:o?o:"Avatar"};if(f.onError)f.onError(n)});(0,c["default"])(this,"onWsMessage",function(e){if(e)f.llmResult=e;else f.loggerError(50010003,"avatar chat result is null")});if(!e||!t||!o)if(onError){var i={errorCode:50000001,errorMessage:"Invalid settings specified for the AvatarllmService."};onError(i)}this.tenantCode=e;this.interactCode=t;this.rtcroomId=o;this.token=r;this.lang=a?a:"zh-CN";this.aiHost=s?s:"https://premrtc.mpaas.cn-hangzhou.aliyuncs.com";this.appId="";this.llmType="";this.llmChatCode="";this.libraryIds=null;this.overtimeInterval=-1;m.initAsr(this.tenantCode,"cn");if(this.token&&this.token.length>0)p.token=this.token;if(n){var l=this;n.onReceiveMessage=function(e){l.onReceiveMessage(e)};n.onError=function(e){l.onError(e)};n.onRoomInfo=function(e){l.onRoomInfo(e)};n.onEnterRoom=function(e){l.onEnterRoom(e)};n.onFirstRender=function(e){l.onFirstRender(e)};n.data.extraInfo=l.rtcroomParam.extraInfo}this.rtcroomContext=my.createRtcRoomContext(o);this.addASRLisener()}return(0,t["default"])(u,[{key:"joinRoom",value:function e(t){if(t){this.rtcroomParam.webrtcInfo=t;console.log(v()+"[2D][LLM] this.rtcroomParam.webrtcInfo=",this.rtcroomParam.webrtcInfo);this.rtcroomContext.start({roomId:this.rtcroomParam.webrtcInfo.roomId,token:this.rtcroomParam.webrtcInfo.rtoken,userId:this.rtcroomParam.webrtcInfo.uid,signature:this.rtcroomParam.webrtcInfo.signature})}}}])}()})?o.apply(t,n):o)&&(e.exports=t)},function(e,t,o){var n=o(4).default;e.exports=function(e,t){if("object"!=n(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0===o)return("string"===t?String:Number)(e);if(o=o.call(e,t||"default"),"object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,a){var o,n;n=[t,a(0),a(1)],void 0!==(t="function"==typeof(o=function(e,t,o){"use strict";var n=a(2),r=(Object.defineProperty(e,"__esModule",{value:true}),e["default"]=void 0,t=n(t),o=n(o),e["default"]=function(){function e(){(0,t["default"])(this,e)}return(0,o["default"])(e,[{key:"initAsr",value:function e(t,o){if(!t||!o)return;console.log("[HHASR] can init",t);var n={action:"doASR",event:"init",taskId:"3",params:{tenantCode:t,lang:o}};my.call("ampeHHCommunication",n,function(e){console.log("[HHASR] init result=",e)})}},{key:"startAsr",value:function e(){var t={action:"doASR",event:"start",taskId:"3",params:{}};my.call("ampeHHCommunication",t,function(e){console.log("[HHASR] start result=",e)})}},{key:"stopAsr",value:function e(){var t={action:"doASR",event:"stop",taskId:"3",params:{}};my.call("ampeHHCommunication",t,function(e){console.log("[HHASR] stop result=",e)})}},{key:"setCurrentMusicVolume",value:function e(t){var o={action:"loudspeaker",event:"set",taskId:"3",params:{volume:t}};my.call("ampeHHCommunication",o,function(e){console.log("[loudspeaker] set volume =",e)})}},{key:"getCurrentMusicVolume",value:function e(){var t={action:"loudspeaker",event:"get",taskId:"3",params:{}};my.call("ampeHHCommunication",t,function(e){console.log("[loudspeaker] get volume =",e)})}}])}())})?o.apply(t,n):o)&&(e.exports=t)},function(e,t,s){var o,n;n=[t,s(1),s(0),s(5)],void 0!==(t="function"==typeof(o=function(e,t,o,n){"use strict";var r=s(2),l=(Object.defineProperty(e,"__esModule",{value:true}),e["default"]=void 0,t=r(t),o=r(o),n=r(n),null),u=null,a=e["default"]=(0,t["default"])(function e(){var i=this;(0,o["default"])(this,e);(0,n["default"])(this,"token","");(0,n["default"])(this,"tenantCode","");(0,n["default"])(this,"configCode","");(0,n["default"])(this,"avatarId","");(0,n["default"])(this,"llmType","");(0,n["default"])(this,"llmChatCode","");(0,n["default"])(this,"libraryIds",null);(0,n["default"])(this,"chatSessionId","");(0,n["default"])(this,"shengjiAppId","");(0,n["default"])(this,"streamId","");(0,n["default"])(this,"getTime",function(){var e=new Date;var t=e.getHours();var o=e.getMinutes();var n=e.getSeconds();var r=e.getMilliseconds();return t+":"+o+":"+n+":"+r});(0,n["default"])(this,"generateUniqueID",function(){console.log("[sdk] Math.random");return Array(32).fill(0).map(function(){return Math.floor(Math.random()*16).toString(16)}).join("")});(0,n["default"])(this,"requestBase",function(e,t,o,n){my.request({url:e,method:t,data:o,dataType:"json_or_text",success:function e(t){if(t.data){var o=t.data;if(o.data)n(o.data);else if(o)n(o)}else n(t)},fail:function e(t){console.error(t);n(t)},complete:function e(t){}})});(0,n["default"])(this,"initWSS",function(n,r,a){var s=i.getTime;var e=n.wssHost;i.tenantCode=n.tenantCode;i.configCode=n.configCode;i.avatarId=n.avatarId;i.llmType=n.llmType;i.llmChatCode=n.llmChatCode;i.libraryIds=n.libraryIds;i.shengjiAppId=n.shengjiAppId;i.streamId=n.streamId;var t="wss_"+i.generateUniqueID();var o=e+"/avatar/ws?wsSessionId="+t;l=my.connectSocket({url:o,multiple:true,success:function e(t){console.log("connectSocket1 鎴愬姛"+JSON.stringify(t))},fail:function e(t){console.log("connectSocket1 澶辫触"+JSON.stringify(t))}});l.onOpen(function(e){console.log(s()+"[RequestService] wssClient connected");if(a)a();if(u==null){var t={type:1001,tenantCode:n.tenantCode,avatarId:n.avatarId,shengjiAppId:n.shengjiAppId,streamId:n.streamId};var o=JSON.stringify(t);l.send({data:o});u=setInterval(function(){l.send({data:o})},30*1e3)}});l.onMessage(function(e){if(e.data){var t=e.message;var o=JSON.parse(t);if(o.type==2006&&o.resultData){console.log(s()+"[RequestService] llm result: %s",o.resultData);var n={text:o.resultData,eventStreamResp:o.eventStreamResp?o.eventStreamResp:{},sessionId:o.sessionId?o.sessionId:""};r(n)}else if(o.type==3001){console.log(s()+"[RequestService] wssClient error: %s",e);r(o)}else if(o.type==2004)r(o)}});l.onError(function(e){console.log(s()+"[RequestService] wssClient error: %s",data);l&&l.close();l=null});l.onClose(function(e){console.log(s()+"[RequestService] wssClient close");if(u!=null){clearInterval(u);u=null}})});(0,n["default"])(this,"sendQuery",function(e,t){if(!l)return;if(!e)return;console.log(i.getTime()+"[RequestService] llm query: ",e);i.chatSessionId=i.generateUniqueID();var o={type:2005,tenantCode:i.tenantCode,avatarId:i.avatarId,shengjiAppId:i.shengjiAppId,streamId:i.streamId,chatSessionId:i.chatSessionId,llmType:i.llmType,llmChatCode:i.llmChatCode,configCode:i.configCode,libraryIds:i.libraryIds,query:e,sessionId:t,token:i.token?i.token:"",ext:""};var n=JSON.stringify(o);l.send({data:n})});(0,n["default"])(this,"interrunptChat",function(){if(!l)return;if(!i.chatSessionId)return;var e={type:1003,token:i.token?i.token:"",chatSessionId:i.chatSessionId};var t=JSON.stringify(e);l.send({data:t});console.log(i.getTime()+"[RequestService] interrupt current chatSessionId: "+i.chatSessionId)});(0,n["default"])(this,"closeWss",function(){if(l){l.close();l=null;i.tenantCode="";i.avatarId="";i.llmType="";i.chatSessionId="";i.shengjiAppId="";i.streamId=""}});(0,n["default"])(this,"sendQuery3D",function(e,t){if(!l)return;if(!e)return;console.log(i.getTime()+"[RequestService] 3D llm query:",e);i.chatSessionId=i.generateUniqueID();var o={type:2003,tenantCode:i.tenantCode,avatarId:i.avatarId,chatSessionId:i.chatSessionId,llmType:i.llmType,query:e,sessionId:t,token:i.token?i.token:"",ext:""};var n=JSON.stringify(o);l.send(n)});this.token="";this.tenantCode="";this.configCode="";this.avatarId="";this.llmType="";this.libraryIds=null;this.chatSessionId="";this.shengjiAppId="";this.streamId=""})})?o.apply(t,n):o)&&(e.exports=t)}],n={},r.m=o,r.c=n,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(o,n,function(e){return t[e]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/proxy/assets/",r(r.s=6).default;function r(e){var t;return(n[e]||(t=n[e]={i:e,l:!1,exports:{}},o[e].call(t.exports,t,t.exports,r),t.l=!0,t)).exports}var o,n});