isdata-customer-sdk 0.2.82 → 0.2.83

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/cjs/chat.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("axios"),e={},a=Object.prototype.hasOwnProperty;function s(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(t){return null}}function i(t){try{return encodeURIComponent(t)}catch(t){return null}}e.stringify=function(t,e){e=e||"";var s,n,r=[];for(n in"string"!=typeof e&&(e="?"),t)if(a.call(t,n)){if((s=t[n])||null!=s&&!isNaN(s)||(s=""),n=i(n),s=i(s),null===n||null===s)continue;r.push(n+"="+s)}return r.length?e+r.join("&"):""},e.parse=function(t){for(var e,a=/([^=?#&]+)=?([^&]*)/g,i={};e=a.exec(t);){var n=s(e[1]),r=s(e[2]);null===n||null===r||n in i||(i[n]=r)}return i};const n="development"===process.env.NODE_ENV,r="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;var o=((a="")=>{a&&(a.startsWith("/")&&(a=a.slice(1,a.length)),a.endsWith("/")&&(a=a.slice(0,-1)));const s=t.create({baseURL:`/${a?a+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(t){return t>=200&&t<300},headers:window.location.search&&e.parse(window.location.search).token||window.token?{token:e.parse(window.location.search).token||window.token}:{}});let i=s.post;return s.post=(t,e,a)=>{let n=window.VITE_SERVICE_BASE_URL||"";if(n){let r=n+t;return i.call(s,r,e,a)}return i.call(s,t,e,a)},s.interceptors.request.use(t=>{if(!r&&n){let e=window.mockData.PORTAL_SERVER_ADDRESS,a=window.mockData.VITE_SERVICE_BASE_URL;t.url=`${e}${a}${t.url}`}return t},t=>Promise.reject(t)),s.defaults.headers.post["Content-Type"]="application/json",s.interceptors.response.use(t=>{let{data:e}=t;return"string"==typeof e&&(e=JSON.parse(e)),!e||200===e.status||e instanceof Blob?e instanceof Blob?(t.data=e,t):(t.data=e&&e.result,t):Promise.reject(t)},t=>{if(!t.response||401!==t.response.status)return Promise.reject(t.response)}),s})(window.prefixPath||"");const h=(t,e)=>{window.sdataEventActions||(window.sdataEventActions={}),window.sdataEventActions[t]=e};exports.ChatClientMgr=class{constructor(t,e){this.handler=e,this.actionKey=t.actionKey,this.appSKID=t.appSKID,this.imType=t.imType,this.groupID=t.groupID,this.userID=t.userID,this.chatType=t.chatType||0,this.singleChatID=t.singleChatID||"",this.customParams=t.customParams||{},this.chartOrigin=t.chartOrigin}makeKey(t){return`${t}-${this.actionKey}`}async init(){this.handler.addChatListener(this.makeKey("sdata_get_access_token"),async t=>await this.handler.getPortalAccessToken(t)),this.handler.addChatListener(this.makeKey("sdata_get_portal_user_info"),async t=>await this.handler.getPortalUserInfo(t)),this.handler.addChatListener(this.makeKey("sdata_get_portal_user_sig"),async t=>{let e=t.userID,a=t.im_type,s=t.group_id;return await this.handler.getPortalUserSig(e,a,s)}),this.handler.addChatListener(this.makeKey("sdata_add_im_mapping"),async t=>{let e=t.userID,a=t.im_type,s=t.userSig;return await this.handler.addIMMapping(e,a,s,this.groupID)}),this.handler.addChatListener(this.makeKey("sdata_update_im_mapping"),async t=>await this.handler.updateIMMapping(t)),this.handler.addChatListener(this.makeKey("sdata_get_users_by_group_id"),async t=>await this.handler.getAllUserInfosByGroupID(t)),this.handler.addChatListener(this.makeKey("sdata_get_dpts_by_group_id"),async t=>await this.handler.getChildrenOfficeInfosByID(t)),this.handler.addChatListener(this.makeKey("sdata_get_project_dpts_by_user_group_id"),async t=>await this.handler.getPojectDptsByUserAndGroupID(t)),this.handler.addChatListener(this.makeKey("sdata_get_ai_robot_infos"),async t=>{let e=t.groupID,a=t.userID;return this.userID==a&&this.groupID==e?this.getAIRobotInfos():[]}),this.handler.addChatListener(this.makeKey("sdata_get_test_user_sig"),async t=>{let e=t.SDKAppID,a=t.userID;return(await this.handler.genTestUserSig({SDKAppID:e,userID:a})).userSig}),this.handler.addChatListener(this.makeKey("sdata_send_message_to_chat_server"),async(t,e)=>{let a=t.message,s=a.from;return await this.sendMessageToChatServer(s,a)}),this.handler.addChatListener(this.makeKey("sdata_close_frame_window"),async(t,e)=>this.handler.closeWindow()),this.handler.addChatListener(this.makeKey("sdata_get_portal_doc_info"),async(t,e)=>this.handler.getPortalDocmentInfo(t)),this.handler.addChatListener(this.makeKey("sdata_chat_aiAgent_event"),async(t,e)=>this.handler.onAIAgentEvent(t,e)),this.handler.addChatListener(this.makeKey("sdata_alllife_event_regist"),async(t,e)=>{console.log("recive chat regist event data:",t),this.appSKID=t.appid,this.imType=t.im_type,await this.initChatAIs();let a={type:this.getChatTypeKey(this.chatType),singleChatID:this.singleChatID,customParams:this.customParams};this.handler.fireEventToChatWindow(e,this.chartOrigin,this.makeKey("sdata_alllife_initChat"),a,t=>{t&&(console.log("chat init finished:",t),this.handler.onChatInitFinished())})})}getChatTypeKey(t){switch(t){case 0:default:return"IM_MULTIPLE_MODE";case 1:return"IM_SINGLE_MODE";case 2:return"IM_EMBED_MODE";case 3:return"IM_MOBILE_MULTIPLE_EMBED_MODE";case 4:return"IM_MOBILE_SINGLE_EMBED_MODE"}}async initChatAIs(){if(window.imClient)this.chatAIClient=window.imClient;else{let t=await this.handler.getChatClientClasses();const{TencentCloudChat:e,TIMUploadPlugin:a}=t;window.imClient=e.create({SDKAppID:this.appSKID,storage:{enable:!0}}),window.imClient.registerPlugin({"tim-upload-plugin":a}),window.imClient.on(e.EVENT.SDK_READY,this.onChatAIReady.bind(this)),window.imClient.charAIs={},this.chatAIClient=window.imClient}this.chatAIClient.charAIs||(this.chatAIClient.charAIs={});let t=await this.handler.getAIRobotInfos(this.userID,this.groupID);t&&t.length>0&&t.forEach(async t=>{let e=t.id;if(!this.chatAIClient.charAIs[e]){t.chatID=e;let a=await this.handler.getPortalUserSig(e,this.imType,this.groupID);a||(a=await this.generateUserSigAndAdd(e)),t.userSig=a,this.chatAIClient.charAIs[e]={robot:t,messageCache:[]}}})}async generateUserSigAndUpdate(t){let e=(await this.handler.genTestUserSig({SDKAppID:this.appSKID,userID:t})).userSig;if(e){await this.chatAIClient.login({userID:t,userSig:e}),await this.chatAIClient.logout();let a={userID:t,userSig:e,im_type:this.imType,group_id:this.groupID};await this.handler.updateIMMapping(a)}return e}async generateUserSigAndAdd(t){let e=(await this.handler.genTestUserSig({SDKAppID:this.appSKID,userID:t})).userSig;return e&&(await this.chatAIClient.login({userID:t,userSig:e}),await this.chatAIClient.logout(),await this.handler.addIMMapping(t,this.imType,e,this.groupID)),e}onChatAIReady(t){let e=this.chatAIClient.lastRobotID,a=this.getAIRobotInfoByID(e);if(console.log(`[AI chat] ${a.name}已经就绪:`,t),this.chatAIClient){let t=this.getAIRobotCacheMessagesByID(e);if(console.log(`[AI chat] ${a.name}就绪后查到的缓存信息:`,t),console.log(`[AI chat] ${a.name}所有信息仓:`,this.chatAIClient.charAIs),t&&t.length>0){const s=[...t];t.splice(0,t.length),s.forEach(t=>{console.log(`[AI chat] ${a.name}发送缓存消息:`,t),this.sendMessageToChatServer(e,t)})}}}getAIRobotInfos(){let t=[];for(let e in this.chatAIClient.charAIs)t.push(this.chatAIClient.charAIs[e].robot);return t}getAIRobotInfoByID(t){return this.chatAIClient.charAIs[t]?this.chatAIClient.charAIs[t].robot:null}getAIRobotCacheMessagesByID(t){return this.chatAIClient.charAIs[t]?this.chatAIClient.charAIs[t].messageCache:[]}async sendMessageToChatServer(t,e){let a=this.getAIRobotInfoByID(t);if(this.chatAIClient.lastRobotID!=t){console.log(`[AI chat]需要新机器人回答,切换到新机器人${a.name}`),this.chatAIClient.lastRobotID&&await this.chatAIClient.logout();try{await this.chatAIClient.login({userID:t,userSig:a.userSig})}catch(s){if(console.log(`[AI chat]${a.name}登录失败`,s),70001==s.code){console.log(`[AI chat]${a.name}UserSig过期,重新生成userSig`);let s=await this.generateUserSigAndUpdate(t);try{return await this.chatAIClient.login({userID:t,userSig:s}),void this.sendMessageToChatServer(t,e)}catch(t){return void console.log(`[AI chat]${a.name}重新登录失败`,t)}}}}if(this.chatAIClient.lastRobotID=t,this.chatAIClient&&this.chatAIClient.isReady()){let t=await this.chatAIClient.createTextMessage(e);this.chatAIClient.sendMessage(t).then(t=>{console.log(`[AI chat]${a.name}发送信息成功`,t)},t=>{console.log(`[AI chat]${a.name}发送失败`,t)})}else{let s=this.getAIRobotCacheMessagesByID(t);s.push(e),console.log(`[AI chat]${a.name}未就绪,缓存后消息:`,s)}}converToAIServerParams(t,e,a){let s="";if("TIMTextElem"===t.type)s=t.payload?.text||"";let i=(t.cloudCustomData||{}).conversation_id||"";return{prompt:s,params:a||{},robotKey:e.password,conversation_id:i||"",userID:t.from||""}}abort(){this.chatAIClient=null}},exports.getIMHanlder=t=>{let e={genTestUserSig:async t=>{},getChatClientClasses:async()=>[],getAIRobotInfos:async(t,e)=>(async(t,e)=>{let a={param:{userID:t,groupID:e}};return(await o.post("/dataservice/rest/orchestration/getAIRobotInfos",a)).data.robotInfos})(t,e),getPortalUserSig:async(t,e,a)=>(async(t,e,a)=>{let s={param:{userID:t,im_type:e,group_id:a}};return(await o.post("/dataservice/rest/orchestration/getIMUserSigByID",s)).data.userSig})(t,e,a),addIMMapping:async(t,e,a,s)=>(async(t,e,a,s)=>{let i={param:{data:{userID:t,im_type:e,group_id:a,userSig:s}}};return(await o.post("/dataservice/rest/orchestration/addIMMapping",i)).data})(t,e,s,a),updateIMMapping:async t=>(async(t,e,a,s)=>{let i={param:{userID:t,im_type:e,groupID:a,userSig:s}};return(await o.post("/dataservice/rest/orchestration/updateIMMapping",i)).data})(t.userID,t.im_type,t.group_id,t.userSig),getPortalAccessToken:async t=>(async(t,e)=>(await o.get(`/appAuth/getAccessToken?appKey=${t}&appSecret=${e}`)).data)(t.appKey,t.appSecret),getPortalUserInfo:async t=>(async(t,e)=>(await o.get(`/systhirdapp/user/getUserByCode?code=${t}&access_token=${e}`)).data)(t.code,t.access_token),getAllUserInfosByGroupID:async t=>(async t=>{let e={param:{groupID:t}};return(await o.post("/dataservice/rest/orchestration/getAllUserInfosByGroupID",e)).data.resultDatas})(t.groupID),getChildrenOfficeInfosByID:async t=>(async t=>{let e={param:{officeID:t}};return(await o.post("/dataservice/rest/orchestration/getChildrenOfficeInfosByID",e)).data.resultDatas})(t.groupID),getPojectDptsByUserAndGroupID:async t=>{let e=t.groupID;return(async(t,e)=>{let a={param:{userID:t,groupID:e}},s=await o.post("/dataservice/rest/orchestration/getPojectDptsByUserAndGroupID",a);return{dptDatas:s.data.officeDatas,userMappings:s.data.userMappings}})(t.userID,e)},closeWindow:()=>!0,addChatListener:async(t,e)=>{await h(t,e)},fireEventToChatWindow:async(t,e,a,s,i)=>{await(async(t,e,a,s,i)=>{let n=`${a}_${(new Date).getTime()}_${Math.floor(1e4*Math.random())+1}`;h(n,i);let r={eventOperateKey:n,eventKey:a,data:s};t.postMessage(r,e)})(t.source,e,a,s,i)},onChatInitFinished:async()=>{},onAIAgentEvent:async(t,e)=>{},getPortalDocmentInfo:async t=>{let e=t.kb_doc_id,a=await(async t=>{let e={param:{kb_doc_id:t}};return(await o.post("/dataservice/rest/orchestration/getPortalDocmentInfoByKBID",e)).data.docInfo})(e),s=a?.summary;if(s){let t=JSON.parse(s);if(t){let e=t[0].url,s=`${window.smardaten_api_context_path}/storage_area/public${e}`,i=await(async t=>{try{const e=await fetch(t,{method:"GET",headers:{Range:"bytes=0-0"}});if(206!==e.status)throw new Error("不支持 Range 请求");const a=e.headers.get("Content-Range"),s=a?.match(/\/(\d+)$/)?.[1];return s?parseInt(s,10):-1}catch(t){return console.error("获取文件大小失败:",t),-1}})(s);a.fileSize=i}}return a}};return e={...e,...t},e},exports.getRobotInfoByID=async(t,e)=>{let a={param:{id:t,groupID:e}};return(await o.post("/dataservice/rest/orchestration/getRobotInfoByID",a)).data.robotInfo};
1
+ "use strict";var t=require("axios"),e={},a=Object.prototype.hasOwnProperty;function s(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(t){return null}}function i(t){try{return encodeURIComponent(t)}catch(t){return null}}e.stringify=function(t,e){e=e||"";var s,n,r=[];for(n in"string"!=typeof e&&(e="?"),t)if(a.call(t,n)){if((s=t[n])||null!=s&&!isNaN(s)||(s=""),n=i(n),s=i(s),null===n||null===s)continue;r.push(n+"="+s)}return r.length?e+r.join("&"):""},e.parse=function(t){for(var e,a=/([^=?#&]+)=?([^&]*)/g,i={};e=a.exec(t);){var n=s(e[1]),r=s(e[2]);null===n||null===r||n in i||(i[n]=r)}return i};const n="development"===process.env.NODE_ENV,r="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;window.isDevopmentMode=n,window.isOnlineDevelopmentMode=r;var o=((a="")=>{a&&(a.startsWith("/")&&(a=a.slice(1,a.length)),a.endsWith("/")&&(a=a.slice(0,-1)));const s=t.create({baseURL:`/${a?a+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(t){return t>=200&&t<300},headers:window.location.search&&e.parse(window.location.search).token||window.token?{token:e.parse(window.location.search).token||window.token}:{}});let i=s.post;return s.post=(t,e,a)=>{let n=window.VITE_SERVICE_BASE_URL||"";if(n){let r=n+t;return i.call(s,r,e,a)}return i.call(s,t,e,a)},s.interceptors.request.use(t=>{if(!r&&n){let e=window.mockData.PORTAL_SERVER_ADDRESS,a=window.mockData.VITE_SERVICE_BASE_URL;t.url=`${e}${a}${t.url}`}return t},t=>Promise.reject(t)),s.defaults.headers.post["Content-Type"]="application/json",s.interceptors.response.use(t=>{let{data:e}=t;return"string"==typeof e&&(e=JSON.parse(e)),!e||200===e.status||e instanceof Blob?e instanceof Blob?(t.data=e,t):(t.data=e&&e.result,t):Promise.reject(t)},t=>{if(!t.response||401!==t.response.status)return Promise.reject(t.response)}),s})(window.prefixPath||"");const h=(t,e)=>{window.sdataEventActions||(window.sdataEventActions={}),window.sdataEventActions[t]=e};exports.ChatClientMgr=class{constructor(t,e){this.handler=e,this.actionKey=t.actionKey,this.appSKID=t.appSKID,this.imType=t.imType,this.groupID=t.groupID,this.userID=t.userID,this.chatType=t.chatType||0,this.singleChatID=t.singleChatID||"",this.customParams=t.customParams||{},this.chartOrigin=t.chartOrigin}makeKey(t){return`${t}-${this.actionKey}`}async init(){this.handler.addChatListener(this.makeKey("sdata_get_access_token"),async t=>await this.handler.getPortalAccessToken(t)),this.handler.addChatListener(this.makeKey("sdata_get_portal_user_info"),async t=>await this.handler.getPortalUserInfo(t)),this.handler.addChatListener(this.makeKey("sdata_get_portal_user_sig"),async t=>{let e=t.userID,a=t.im_type,s=t.group_id;return await this.handler.getPortalUserSig(e,a,s)}),this.handler.addChatListener(this.makeKey("sdata_add_im_mapping"),async t=>{let e=t.userID,a=t.im_type,s=t.userSig;return await this.handler.addIMMapping(e,a,s,this.groupID)}),this.handler.addChatListener(this.makeKey("sdata_update_im_mapping"),async t=>await this.handler.updateIMMapping(t)),this.handler.addChatListener(this.makeKey("sdata_get_users_by_group_id"),async t=>await this.handler.getAllUserInfosByGroupID(t)),this.handler.addChatListener(this.makeKey("sdata_get_dpts_by_group_id"),async t=>await this.handler.getChildrenOfficeInfosByID(t)),this.handler.addChatListener(this.makeKey("sdata_get_project_dpts_by_user_group_id"),async t=>await this.handler.getPojectDptsByUserAndGroupID(t)),this.handler.addChatListener(this.makeKey("sdata_get_ai_robot_infos"),async t=>{let e=t.groupID,a=t.userID;return this.userID==a&&this.groupID==e?this.getAIRobotInfos():[]}),this.handler.addChatListener(this.makeKey("sdata_get_test_user_sig"),async t=>{let e=t.SDKAppID,a=t.userID;return(await this.handler.genTestUserSig({SDKAppID:e,userID:a})).userSig}),this.handler.addChatListener(this.makeKey("sdata_send_message_to_chat_server"),async(t,e)=>{let a=t.message,s=a.from;return await this.sendMessageToChatServer(s,a)}),this.handler.addChatListener(this.makeKey("sdata_close_frame_window"),async(t,e)=>this.handler.closeWindow()),this.handler.addChatListener(this.makeKey("sdata_get_portal_doc_info"),async(t,e)=>this.handler.getPortalDocmentInfo(t)),this.handler.addChatListener(this.makeKey("sdata_chat_aiAgent_event"),async(t,e)=>this.handler.onAIAgentEvent(t,e)),this.handler.addChatListener(this.makeKey("sdata_alllife_event_regist"),async(t,e)=>{console.log("recive chat regist event data:",t),this.appSKID=t.appid,this.imType=t.im_type,await this.initChatAIs();let a={type:this.getChatTypeKey(this.chatType),singleChatID:this.singleChatID,customParams:this.customParams};this.handler.fireEventToChatWindow(e,this.chartOrigin,this.makeKey("sdata_alllife_initChat"),a,t=>{t&&(console.log("chat init finished:",t),this.handler.onChatInitFinished())})})}getChatTypeKey(t){switch(t){case 0:default:return"IM_MULTIPLE_MODE";case 1:return"IM_SINGLE_MODE";case 2:return"IM_EMBED_MODE";case 3:return"IM_MOBILE_MULTIPLE_EMBED_MODE";case 4:return"IM_MOBILE_SINGLE_EMBED_MODE"}}async initChatAIs(){if(window.imClient)this.chatAIClient=window.imClient;else{let t=await this.handler.getChatClientClasses();const{TencentCloudChat:e,TIMUploadPlugin:a}=t;window.imClient=e.create({SDKAppID:this.appSKID,storage:{enable:!0}}),window.imClient.registerPlugin({"tim-upload-plugin":a}),window.imClient.on(e.EVENT.SDK_READY,this.onChatAIReady.bind(this)),window.imClient.charAIs={},this.chatAIClient=window.imClient}this.chatAIClient.charAIs||(this.chatAIClient.charAIs={});let t=await this.handler.getAIRobotInfos(this.userID,this.groupID);t&&t.length>0&&t.forEach(async t=>{let e=t.id;if(!this.chatAIClient.charAIs[e]){t.chatID=e;let a=await this.handler.getPortalUserSig(e,this.imType,this.groupID);a||(a=await this.generateUserSigAndAdd(e)),t.userSig=a,this.chatAIClient.charAIs[e]={robot:t,messageCache:[]}}})}async generateUserSigAndUpdate(t){let e=(await this.handler.genTestUserSig({SDKAppID:this.appSKID,userID:t})).userSig;if(e){await this.chatAIClient.login({userID:t,userSig:e}),await this.chatAIClient.logout();let a={userID:t,userSig:e,im_type:this.imType,group_id:this.groupID};await this.handler.updateIMMapping(a)}return e}async generateUserSigAndAdd(t){let e=(await this.handler.genTestUserSig({SDKAppID:this.appSKID,userID:t})).userSig;return e&&(await this.chatAIClient.login({userID:t,userSig:e}),await this.chatAIClient.logout(),await this.handler.addIMMapping(t,this.imType,e,this.groupID)),e}onChatAIReady(t){let e=this.chatAIClient.lastRobotID,a=this.getAIRobotInfoByID(e);if(console.log(`[AI chat] ${a.name}已经就绪:`,t),this.chatAIClient){let t=this.getAIRobotCacheMessagesByID(e);if(console.log(`[AI chat] ${a.name}就绪后查到的缓存信息:`,t),console.log(`[AI chat] ${a.name}所有信息仓:`,this.chatAIClient.charAIs),t&&t.length>0){const s=[...t];t.splice(0,t.length),s.forEach(t=>{console.log(`[AI chat] ${a.name}发送缓存消息:`,t),this.sendMessageToChatServer(e,t)})}}}getAIRobotInfos(){let t=[];for(let e in this.chatAIClient.charAIs)t.push(this.chatAIClient.charAIs[e].robot);return t}getAIRobotInfoByID(t){return this.chatAIClient.charAIs[t]?this.chatAIClient.charAIs[t].robot:null}getAIRobotCacheMessagesByID(t){return this.chatAIClient.charAIs[t]?this.chatAIClient.charAIs[t].messageCache:[]}async sendMessageToChatServer(t,e){let a=this.getAIRobotInfoByID(t);if(this.chatAIClient.lastRobotID!=t){console.log(`[AI chat]需要新机器人回答,切换到新机器人${a.name}`),this.chatAIClient.lastRobotID&&await this.chatAIClient.logout();try{await this.chatAIClient.login({userID:t,userSig:a.userSig})}catch(s){if(console.log(`[AI chat]${a.name}登录失败`,s),70001==s.code){console.log(`[AI chat]${a.name}UserSig过期,重新生成userSig`);let s=await this.generateUserSigAndUpdate(t);try{return await this.chatAIClient.login({userID:t,userSig:s}),void this.sendMessageToChatServer(t,e)}catch(t){return void console.log(`[AI chat]${a.name}重新登录失败`,t)}}}}if(this.chatAIClient.lastRobotID=t,this.chatAIClient&&this.chatAIClient.isReady()){let t=await this.chatAIClient.createTextMessage(e);this.chatAIClient.sendMessage(t).then(t=>{console.log(`[AI chat]${a.name}发送信息成功`,t)},t=>{console.log(`[AI chat]${a.name}发送失败`,t)})}else{let s=this.getAIRobotCacheMessagesByID(t);s.push(e),console.log(`[AI chat]${a.name}未就绪,缓存后消息:`,s)}}converToAIServerParams(t,e,a){let s="";if("TIMTextElem"===t.type)s=t.payload?.text||"";let i=(t.cloudCustomData||{}).conversation_id||"";return{prompt:s,params:a||{},robotKey:e.password,conversation_id:i||"",userID:t.from||""}}abort(){this.chatAIClient=null}},exports.getIMHanlder=t=>{let e={genTestUserSig:async t=>{},getChatClientClasses:async()=>[],getAIRobotInfos:async(t,e)=>(async(t,e)=>{let a={param:{userID:t,groupID:e}};return(await o.post("/dataservice/rest/orchestration/getAIRobotInfos",a)).data.robotInfos})(t,e),getPortalUserSig:async(t,e,a)=>(async(t,e,a)=>{let s={param:{userID:t,im_type:e,group_id:a}};return(await o.post("/dataservice/rest/orchestration/getIMUserSigByID",s)).data.userSig})(t,e,a),addIMMapping:async(t,e,a,s)=>(async(t,e,a,s)=>{let i={param:{data:{userID:t,im_type:e,group_id:a,userSig:s}}};return(await o.post("/dataservice/rest/orchestration/addIMMapping",i)).data})(t,e,s,a),updateIMMapping:async t=>(async(t,e,a,s)=>{let i={param:{userID:t,im_type:e,groupID:a,userSig:s}};return(await o.post("/dataservice/rest/orchestration/updateIMMapping",i)).data})(t.userID,t.im_type,t.group_id,t.userSig),getPortalAccessToken:async t=>(async(t,e)=>(await o.get(`/appAuth/getAccessToken?appKey=${t}&appSecret=${e}`)).data)(t.appKey,t.appSecret),getPortalUserInfo:async t=>(async(t,e)=>(await o.get(`/systhirdapp/user/getUserByCode?code=${t}&access_token=${e}`)).data)(t.code,t.access_token),getAllUserInfosByGroupID:async t=>(async t=>{let e={param:{groupID:t}};return(await o.post("/dataservice/rest/orchestration/getAllUserInfosByGroupID",e)).data.resultDatas})(t.groupID),getChildrenOfficeInfosByID:async t=>(async t=>{let e={param:{officeID:t}};return(await o.post("/dataservice/rest/orchestration/getChildrenOfficeInfosByID",e)).data.resultDatas})(t.groupID),getPojectDptsByUserAndGroupID:async t=>{let e=t.groupID;return(async(t,e)=>{let a={param:{userID:t,groupID:e}},s=await o.post("/dataservice/rest/orchestration/getPojectDptsByUserAndGroupID",a);return{dptDatas:s.data.officeDatas,userMappings:s.data.userMappings}})(t.userID,e)},closeWindow:()=>!0,addChatListener:async(t,e)=>{await h(t,e)},fireEventToChatWindow:async(t,e,a,s,i)=>{await(async(t,e,a,s,i)=>{let n=`${a}_${(new Date).getTime()}_${Math.floor(1e4*Math.random())+1}`;h(n,i);let r={eventOperateKey:n,eventKey:a,data:s};t.postMessage(r,e)})(t.source,e,a,s,i)},onChatInitFinished:async()=>{},onAIAgentEvent:async(t,e)=>{},getPortalDocmentInfo:async t=>{let e=t.kb_doc_id,a=await(async t=>{let e={param:{kb_doc_id:t}};return(await o.post("/dataservice/rest/orchestration/getPortalDocmentInfoByKBID",e)).data.docInfo})(e),s=a?.summary;if(s){let t=JSON.parse(s);if(t){let e=t[0].url,s=`${window.smardaten_api_context_path}/storage_area/public${e}`,i=await(async t=>{try{const e=await fetch(t,{method:"GET",headers:{Range:"bytes=0-0"}});if(206!==e.status)throw new Error("不支持 Range 请求");const a=e.headers.get("Content-Range"),s=a?.match(/\/(\d+)$/)?.[1];return s?parseInt(s,10):-1}catch(t){return console.error("获取文件大小失败:",t),-1}})(s);a.fileSize=i}}return a}};return e={...e,...t},e},exports.getRobotInfoByID=async(t,e)=>{let a={param:{id:t,groupID:e}};return(await o.post("/dataservice/rest/orchestration/getRobotInfoByID",a)).data.robotInfo};
package/dist/cjs/dify.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("axios"),t={},o=Object.prototype.hasOwnProperty;function n(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function r(e){try{return encodeURIComponent(e)}catch(e){return null}}t.stringify=function(e,t){t=t||"";var n,a,s=[];for(a in"string"!=typeof t&&(t="?"),e)if(o.call(e,a)){if((n=e[a])||null!=n&&!isNaN(n)||(n=""),a=r(a),n=r(n),null===a||null===n)continue;s.push(a+"="+n)}return s.length?t+s.join("&"):""},t.parse=function(e){for(var t,o=/([^=?#&]+)=?([^&]*)/g,r={};t=o.exec(e);){var a=n(t[1]),s=n(t[2]);null===a||null===s||a in r||(r[a]=s)}return r};const a="development"===process.env.NODE_ENV,s="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;var i=((o="")=>{o&&(o.startsWith("/")&&(o=o.slice(1,o.length)),o.endsWith("/")&&(o=o.slice(0,-1)));const n=e.create({baseURL:`/${o?o+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(e){return e>=200&&e<300},headers:window.location.search&&t.parse(window.location.search).token||window.token?{token:t.parse(window.location.search).token||window.token}:{}});let r=n.post;return n.post=(e,t,o)=>{let a=window.VITE_SERVICE_BASE_URL||"";if(a){let s=a+e;return r.call(n,s,t,o)}return r.call(n,e,t,o)},n.interceptors.request.use(e=>{if(!s&&a){let t=window.mockData.PORTAL_SERVER_ADDRESS,o=window.mockData.VITE_SERVICE_BASE_URL;e.url=`${t}${o}${e.url}`}return e},e=>Promise.reject(e)),n.defaults.headers.post["Content-Type"]="application/json",n.interceptors.response.use(e=>{let{data:t}=e;return"string"==typeof t&&(t=JSON.parse(t)),!t||200===t.status||t instanceof Blob?t instanceof Blob?(e.data=t,e):(e.data=t&&t.result,e):Promise.reject(e)},e=>{if(!e.response||401!==e.response.status)return Promise.reject(e.response)}),n})(window.prefixPath||"");const c=()=>window.appSdk.getAppId()||window.localStorage.MobileAppId;exports.getDifyFileType=e=>({DOCX:"document",TXT:"document",MD:"document",MARKDOWN:"document",MDX:"document",PDF:"document",HTML:"document",XLSX:"document",XLS:"document",VTT:"document",DOC:"document",CSV:"document",EML:"document",MSG:"document",PPTX:"document",PPT:"document",XML:"document",EPUB:"document",JPG:"image",JPEG:"image",PNG:"image",GIF:"image",WEBP:"image",MP3:"audio",M4A:"audio",WAV:"audio",WEBM:"audio",MPGA:"audio",MP4:"video",MOV:"video",MPEG:"video"}[e.toUpperCase()]||"custom"),exports.sendPostToAIAgent=async(e,t,o)=>{let n=(()=>{let e=window.sessionStorage.getItem("iportal_app_id");return e||(e=c()),e})(),r=await(async e=>{let t={param:{appID:e}},o=(await i.post("/dataservice/rest/orchestration/getAppCustomData",t)).data.customData;return o=o?JSON.parse(o):{},o})(n),a=r?.aiAgentServerIP||"";if(!a)return console.error("没有配置AI Agent服务地址,请联系管理员"),void(o&&o("没有配置AI Agent服务地址,请联系管理员"));let s=`${a}/addAndCleanDocument`;i.post(s,JSON.stringify(e)).then(e=>{console.log("发送消息成功:",e),t&&t(e)}).catch(e=>{console.error("发送消息失败:",e),o&&o(e)})};
1
+ "use strict";var e=require("axios"),t={},o=Object.prototype.hasOwnProperty;function n(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function r(e){try{return encodeURIComponent(e)}catch(e){return null}}t.stringify=function(e,t){t=t||"";var n,a,s=[];for(a in"string"!=typeof t&&(t="?"),e)if(o.call(e,a)){if((n=e[a])||null!=n&&!isNaN(n)||(n=""),a=r(a),n=r(n),null===a||null===n)continue;s.push(a+"="+n)}return s.length?t+s.join("&"):""},t.parse=function(e){for(var t,o=/([^=?#&]+)=?([^&]*)/g,r={};t=o.exec(e);){var a=n(t[1]),s=n(t[2]);null===a||null===s||a in r||(r[a]=s)}return r};const a="development"===process.env.NODE_ENV,s="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;window.isDevopmentMode=a,window.isOnlineDevelopmentMode=s;var i=((o="")=>{o&&(o.startsWith("/")&&(o=o.slice(1,o.length)),o.endsWith("/")&&(o=o.slice(0,-1)));const n=e.create({baseURL:`/${o?o+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(e){return e>=200&&e<300},headers:window.location.search&&t.parse(window.location.search).token||window.token?{token:t.parse(window.location.search).token||window.token}:{}});let r=n.post;return n.post=(e,t,o)=>{let a=window.VITE_SERVICE_BASE_URL||"";if(a){let s=a+e;return r.call(n,s,t,o)}return r.call(n,e,t,o)},n.interceptors.request.use(e=>{if(!s&&a){let t=window.mockData.PORTAL_SERVER_ADDRESS,o=window.mockData.VITE_SERVICE_BASE_URL;e.url=`${t}${o}${e.url}`}return e},e=>Promise.reject(e)),n.defaults.headers.post["Content-Type"]="application/json",n.interceptors.response.use(e=>{let{data:t}=e;return"string"==typeof t&&(t=JSON.parse(t)),!t||200===t.status||t instanceof Blob?t instanceof Blob?(e.data=t,e):(e.data=t&&t.result,e):Promise.reject(e)},e=>{if(!e.response||401!==e.response.status)return Promise.reject(e.response)}),n})(window.prefixPath||"");const c=()=>window.appSdk.getAppId()||window.localStorage.MobileAppId;exports.getDifyFileType=e=>({DOCX:"document",TXT:"document",MD:"document",MARKDOWN:"document",MDX:"document",PDF:"document",HTML:"document",XLSX:"document",XLS:"document",VTT:"document",DOC:"document",CSV:"document",EML:"document",MSG:"document",PPTX:"document",PPT:"document",XML:"document",EPUB:"document",JPG:"image",JPEG:"image",PNG:"image",GIF:"image",WEBP:"image",MP3:"audio",M4A:"audio",WAV:"audio",WEBM:"audio",MPGA:"audio",MP4:"video",MOV:"video",MPEG:"video"}[e.toUpperCase()]||"custom"),exports.sendPostToAIAgent=async(e,t,o)=>{let n=(()=>{let e=window.sessionStorage.getItem("iportal_app_id");return e||(e=c()),e})(),r=await(async e=>{let t={param:{appID:e}},o=(await i.post("/dataservice/rest/orchestration/getAppCustomData",t)).data.customData;return o=o?JSON.parse(o):{},o})(n),a=r?.aiAgentServerIP||"";if(!a)return console.error("没有配置AI Agent服务地址,请联系管理员"),void(o&&o("没有配置AI Agent服务地址,请联系管理员"));let s=`${a}/addAndCleanDocument`;i.post(s,JSON.stringify(e)).then(e=>{console.log("发送消息成功:",e),t&&t(e)}).catch(e=>{console.error("发送消息失败:",e),o&&o(e)})};
package/dist/cjs/i18n.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var t=require("axios"),n=require("vue"),e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u={},i=Object.prototype.hasOwnProperty;function o(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(t){return null}}function a(t){try{return encodeURIComponent(t)}catch(t){return null}}u.stringify=function(t,n){n=n||"";var e,r,u=[];for(r in"string"!=typeof n&&(n="?"),t)if(i.call(t,r)){if((e=t[r])||null!=e&&!isNaN(e)||(e=""),r=a(r),e=a(e),null===r||null===e)continue;u.push(r+"="+e)}return u.length?n+u.join("&"):""},u.parse=function(t){for(var n,e=/([^=?#&]+)=?([^&]*)/g,r={};n=e.exec(t);){var u=o(n[1]),i=o(n[2]);null===u||null===i||u in r||(r[u]=i)}return r};const c="development"===process.env.NODE_ENV,l="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;var f=((n="")=>{n&&(n.startsWith("/")&&(n=n.slice(1,n.length)),n.endsWith("/")&&(n=n.slice(0,-1)));const e=t.create({baseURL:`/${n?n+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(t){return t>=200&&t<300},headers:window.location.search&&u.parse(window.location.search).token||window.token?{token:u.parse(window.location.search).token||window.token}:{}});let r=e.post;return e.post=(t,n,u)=>{let i=window.VITE_SERVICE_BASE_URL||"";if(i){let o=i+t;return r.call(e,o,n,u)}return r.call(e,t,n,u)},e.interceptors.request.use(t=>{if(!l&&c){let n=window.mockData.PORTAL_SERVER_ADDRESS,e=window.mockData.VITE_SERVICE_BASE_URL;t.url=`${n}${e}${t.url}`}return t},t=>Promise.reject(t)),e.defaults.headers.post["Content-Type"]="application/json",e.interceptors.response.use(t=>{let{data:n}=t;return"string"==typeof n&&(n=JSON.parse(n)),!n||200===n.status||n instanceof Blob?n instanceof Blob?(t.data=n,t):(t.data=n&&n.result,t):Promise.reject(t)},t=>{if(!t.response||401!==t.response.status)return Promise.reject(t.response)}),e})(window.prefixPath||""),s={exports:{}};
1
+ "use strict";var t=require("axios"),n=require("vue"),e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u={},i=Object.prototype.hasOwnProperty;function o(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(t){return null}}function a(t){try{return encodeURIComponent(t)}catch(t){return null}}u.stringify=function(t,n){n=n||"";var e,r,u=[];for(r in"string"!=typeof n&&(n="?"),t)if(i.call(t,r)){if((e=t[r])||null!=e&&!isNaN(e)||(e=""),r=a(r),e=a(e),null===r||null===e)continue;u.push(r+"="+e)}return u.length?n+u.join("&"):""},u.parse=function(t){for(var n,e=/([^=?#&]+)=?([^&]*)/g,r={};n=e.exec(t);){var u=o(n[1]),i=o(n[2]);null===u||null===i||u in r||(r[u]=i)}return r};const c="development"===process.env.NODE_ENV,l="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;window.isDevopmentMode=c,window.isOnlineDevelopmentMode=l;var f=((n="")=>{n&&(n.startsWith("/")&&(n=n.slice(1,n.length)),n.endsWith("/")&&(n=n.slice(0,-1)));const e=t.create({baseURL:`/${n?n+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(t){return t>=200&&t<300},headers:window.location.search&&u.parse(window.location.search).token||window.token?{token:u.parse(window.location.search).token||window.token}:{}});let r=e.post;return e.post=(t,n,u)=>{let i=window.VITE_SERVICE_BASE_URL||"";if(i){let o=i+t;return r.call(e,o,n,u)}return r.call(e,t,n,u)},e.interceptors.request.use(t=>{if(!l&&c){let n=window.mockData.PORTAL_SERVER_ADDRESS,e=window.mockData.VITE_SERVICE_BASE_URL;t.url=`${n}${e}${t.url}`}return t},t=>Promise.reject(t)),e.defaults.headers.post["Content-Type"]="application/json",e.interceptors.response.use(t=>{let{data:n}=t;return"string"==typeof n&&(n=JSON.parse(n)),!n||200===n.status||n instanceof Blob?n instanceof Blob?(t.data=n,t):(t.data=n&&n.result,t):Promise.reject(t)},t=>{if(!t.response||401!==t.response.status)return Promise.reject(t.response)}),e})(window.prefixPath||""),s={exports:{}};
2
2
  /**
3
3
  * @license
4
4
  * Lodash <https://lodash.com/>