isdata-customer-sdk 0.1.60 → 0.1.62

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.
@@ -30836,7 +30836,7 @@ class ChatClientMgr {
30836
30836
  this.chatType = params.chatType || 0;
30837
30837
  this.singleChatID = params.singleChatID || "";
30838
30838
  this.chartOrigin = params.chartOrigin;
30839
- this.charAIs = {};
30839
+ // this.charAIs = {};
30840
30840
  }
30841
30841
  makeKey(key) {
30842
30842
  return `${key}-${this.actionKey}`;
@@ -30923,34 +30923,41 @@ class ChatClientMgr {
30923
30923
  appSKID: this.appSKID,
30924
30924
  onReady: this.onChatAIReady.bind(this)
30925
30925
  });
30926
+ if (!this.chatAIClient.charAIs) {
30927
+ this.chatAIClient.charAIs = {};
30928
+ }
30926
30929
  let robotInfos = await this.handler.getAIRobotInfos(this.userID, this.groupID);
30927
30930
  if (robotInfos && robotInfos.length > 0) {
30928
30931
  robotInfos.forEach(async robot => {
30929
30932
  let robotKey = robot.id;
30930
- robot.chatID = robotKey;
30931
- let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
30932
- if (!userSig) {
30933
- let sigIDObject = this.handler.genTestUserSig({
30934
- SDKAppID: this.appSKID,
30935
- userID: robotKey
30936
- });
30937
- userSig = sigIDObject.userSig;
30938
- await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
30933
+ if (!this.chatAIClient.charAIs[robotKey]) {
30934
+ robot.chatID = robotKey;
30935
+ let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
30936
+ if (!userSig) {
30937
+ let sigIDObject = this.handler.genTestUserSig({
30938
+ SDKAppID: this.appSKID,
30939
+ userID: robotKey
30940
+ });
30941
+ userSig = sigIDObject.userSig;
30942
+ await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
30943
+ }
30944
+ robot.userSig = userSig;
30945
+ this.chatAIClient.charAIs[robotKey] = {
30946
+ robot: robot,
30947
+ messageCache: []
30948
+ };
30939
30949
  }
30940
- robot.userSig = userSig;
30941
- this.charAIs[robotKey] = {
30942
- robot: robot,
30943
- messageCache: []
30944
- };
30945
30950
  });
30946
30951
  }
30947
30952
  }
30948
30953
  onChatAIReady(event) {
30949
- let robotID = this.lastRobotID;
30954
+ let robotID = this.chatAIClient.lastRobotID;
30950
30955
  let robotInfo = this.getAIRobotInfoByID(robotID);
30951
30956
  console.log(`[AI chat] ${robotInfo.name}已经就绪:`, event);
30952
30957
  if (this.chatAIClient) {
30953
30958
  let messages = this.getAIRobotCacheMessagesByID(robotID);
30959
+ console.log(`[AI chat] ${robotInfo.name}就绪后查到的缓存信息:`, messages);
30960
+ console.log(`[AI chat] ${robotInfo.name}所有信息仓:`, this.chatAIClient.charAIs);
30954
30961
  if (messages && messages.length > 0) {
30955
30962
  const newMessages = [...messages];
30956
30963
  messages.splice(0, messages.length);
@@ -30963,22 +30970,22 @@ class ChatClientMgr {
30963
30970
  }
30964
30971
  getAIRobotInfos() {
30965
30972
  let resultRobots = [];
30966
- for (let key in this.charAIs) {
30967
- resultRobots.push(this.charAIs[key].robot);
30973
+ for (let key in this.chatAIClient.charAIs) {
30974
+ resultRobots.push(this.chatAIClient.charAIs[key].robot);
30968
30975
  }
30969
30976
  return resultRobots;
30970
30977
  }
30971
30978
  getAIRobotInfoByID(robotID) {
30972
- return this.charAIs[robotID] ? this.charAIs[robotID].robot : null;
30979
+ return this.chatAIClient.charAIs[robotID] ? this.chatAIClient.charAIs[robotID].robot : null;
30973
30980
  }
30974
30981
  getAIRobotCacheMessagesByID(robotID) {
30975
- return this.charAIs[robotID] ? this.charAIs[robotID].messageCache : [];
30982
+ return this.chatAIClient.charAIs[robotID] ? this.chatAIClient.charAIs[robotID].messageCache : [];
30976
30983
  }
30977
30984
  async sendMessageToChatServer(robotID, messageOption) {
30978
30985
  let robotInfo = this.getAIRobotInfoByID(robotID);
30979
- if (this.lastRobotID != robotID) {
30986
+ if (this.chatAIClient.lastRobotID != robotID) {
30980
30987
  console.log(`[AI chat]需要新机器人回答,切换到新机器人${robotInfo.name}`);
30981
- if (this.lastRobotID) {
30988
+ if (this.chatAIClient.lastRobotID) {
30982
30989
  await this.chatAIClient.logout();
30983
30990
  }
30984
30991
  await this.chatAIClient.login({
@@ -30986,7 +30993,7 @@ class ChatClientMgr {
30986
30993
  userSig: robotInfo.userSig
30987
30994
  });
30988
30995
  }
30989
- this.lastRobotID = robotID;
30996
+ this.chatAIClient.lastRobotID = robotID;
30990
30997
  if (this.chatAIClient && this.chatAIClient.isReady()) {
30991
30998
  let new_message = await this.chatAIClient.createTextMessage(messageOption);
30992
30999
  this.chatAIClient.sendMessage(new_message).then(res => {
@@ -30995,9 +31002,9 @@ class ChatClientMgr {
30995
31002
  console.log(`[AI chat]${robotInfo.name}发送失败`, err);
30996
31003
  });
30997
31004
  } else {
30998
- console.log(`[AI chat]${robotInfo.name}未就绪,缓存消息:`, messageOption);
30999
31005
  let messageCache = this.getAIRobotCacheMessagesByID(robotID);
31000
31006
  messageCache.push(messageOption);
31007
+ console.log(`[AI chat]${robotInfo.name}未就绪,缓存后消息:`, messageCache);
31001
31008
  }
31002
31009
  }
31003
31010
  converToAIServerParams(message, robotInfo, param) {