Browse Source

Merge branch 'master' of http://git.fmode.cn:3000/4u/workspace

19136808282 3 months ago
parent
commit
3e1309a928
4 changed files with 163 additions and 49 deletions
  1. 136 3
      soul-app/package-lock.json
  2. 4 0
      soul-app/package.json
  3. 20 33
      soul-app/src/app/tab2/tab2.page.ts
  4. 3 13
      soul-app/src/lib/ncloud.ts

+ 136 - 3
soul-app/package-lock.json

@@ -22,6 +22,10 @@
         "@capacitor/keyboard": "6.0.3",
         "@capacitor/status-bar": "6.0.2",
         "@ionic/angular": "^8.0.0",
+        "@tensorflow-models/universal-sentence-encoder": "^1.3.3",
+        "@tensorflow/tfjs-backend-cpu": "^4.22.0",
+        "@tensorflow/tfjs-converter": "^4.22.0",
+        "@tensorflow/tfjs-core": "^4.22.0",
         "fmode-ng": "^0.0.63",
         "ionicons": "^7.2.1",
         "rxjs": "~7.8.0",
@@ -5786,6 +5790,59 @@
         "npm": ">=7.10.0"
       }
     },
+    "node_modules/@tensorflow-models/universal-sentence-encoder": {
+      "version": "1.3.3",
+      "resolved": "https://registry.npmmirror.com/@tensorflow-models/universal-sentence-encoder/-/universal-sentence-encoder-1.3.3.tgz",
+      "integrity": "sha512-mipL7ad0CW6uQ68FUkNgkNj/zgA4qgBnNcnMMkNTdL9MUMnzCxu3AE8pWnx2ReKHwdqEG4e8IpaYKfH4B8bojg==",
+      "license": "Apache-2.0",
+      "peerDependencies": {
+        "@tensorflow/tfjs-converter": "^3.6.0",
+        "@tensorflow/tfjs-core": "^3.6.0"
+      }
+    },
+    "node_modules/@tensorflow/tfjs-backend-cpu": {
+      "version": "4.22.0",
+      "resolved": "https://registry.npmmirror.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-4.22.0.tgz",
+      "integrity": "sha512-1u0FmuLGuRAi8D2c3cocHTASGXOmHc/4OvoVDENJayjYkS119fcTcQf4iHrtLthWyDIPy3JiPhRrZQC9EwnhLw==",
+      "license": "Apache-2.0",
+      "dependencies": {
+        "@types/seedrandom": "^2.4.28",
+        "seedrandom": "^3.0.5"
+      },
+      "engines": {
+        "yarn": ">= 1.3.2"
+      },
+      "peerDependencies": {
+        "@tensorflow/tfjs-core": "4.22.0"
+      }
+    },
+    "node_modules/@tensorflow/tfjs-converter": {
+      "version": "4.22.0",
+      "resolved": "https://registry.npmmirror.com/@tensorflow/tfjs-converter/-/tfjs-converter-4.22.0.tgz",
+      "integrity": "sha512-PT43MGlnzIo+YfbsjM79Lxk9lOq6uUwZuCc8rrp0hfpLjF6Jv8jS84u2jFb+WpUeuF4K33ZDNx8CjiYrGQ2trQ==",
+      "license": "Apache-2.0",
+      "peerDependencies": {
+        "@tensorflow/tfjs-core": "4.22.0"
+      }
+    },
+    "node_modules/@tensorflow/tfjs-core": {
+      "version": "4.22.0",
+      "resolved": "https://registry.npmmirror.com/@tensorflow/tfjs-core/-/tfjs-core-4.22.0.tgz",
+      "integrity": "sha512-LEkOyzbknKFoWUwfkr59vSB68DMJ4cjwwHgicXN0DUi3a0Vh1Er3JQqCI1Hl86GGZQvY8ezVrtDIvqR1ZFW55A==",
+      "license": "Apache-2.0",
+      "dependencies": {
+        "@types/long": "^4.0.1",
+        "@types/offscreencanvas": "~2019.7.0",
+        "@types/seedrandom": "^2.4.28",
+        "@webgpu/types": "0.1.38",
+        "long": "4.0.0",
+        "node-fetch": "~2.6.1",
+        "seedrandom": "^3.0.5"
+      },
+      "engines": {
+        "yarn": ">= 1.3.2"
+      }
+    },
     "node_modules/@tufjs/canonical-json": {
       "version": "2.0.0",
       "resolved": "https://registry.npmmirror.com/@tufjs/canonical-json/-/canonical-json-2.0.0.tgz",
@@ -5986,6 +6043,12 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/@types/long": {
+      "version": "4.0.2",
+      "resolved": "https://registry.npmmirror.com/@types/long/-/long-4.0.2.tgz",
+      "integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==",
+      "license": "MIT"
+    },
     "node_modules/@types/mime": {
       "version": "1.3.5",
       "resolved": "https://registry.npmmirror.com/@types/mime/-/mime-1.3.5.tgz",
@@ -6022,6 +6085,12 @@
         "@types/node": "*"
       }
     },
+    "node_modules/@types/offscreencanvas": {
+      "version": "2019.7.3",
+      "resolved": "https://registry.npmmirror.com/@types/offscreencanvas/-/offscreencanvas-2019.7.3.tgz",
+      "integrity": "sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==",
+      "license": "MIT"
+    },
     "node_modules/@types/parse": {
       "version": "3.0.9",
       "resolved": "https://registry.npmmirror.com/@types/parse/-/parse-3.0.9.tgz",
@@ -6053,6 +6122,12 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/@types/seedrandom": {
+      "version": "2.4.34",
+      "resolved": "https://registry.npmmirror.com/@types/seedrandom/-/seedrandom-2.4.34.tgz",
+      "integrity": "sha512-ytDiArvrn/3Xk6/vtylys5tlY6eo7Ane0hvcx++TKo6RxQXuVfW0AF/oeWqAj9dN29SyhtawuXstgmPlwNcv/A==",
+      "license": "MIT"
+    },
     "node_modules/@types/semver": {
       "version": "7.5.8",
       "resolved": "https://registry.npmmirror.com/@types/semver/-/semver-7.5.8.tgz",
@@ -6776,6 +6851,12 @@
         "@xtuc/long": "4.2.2"
       }
     },
+    "node_modules/@webgpu/types": {
+      "version": "0.1.38",
+      "resolved": "https://registry.npmmirror.com/@webgpu/types/-/types-0.1.38.tgz",
+      "integrity": "sha512-7LrhVKz2PRh+DD7+S+PVaFd5HxaWQvoMqBbsV9fNJO1pjUs1P8bM2vQVNfk+3URTqbuTI7gkXi0rfsN0IadoBA==",
+      "license": "BSD-3-Clause"
+    },
     "node_modules/@xmldom/xmldom": {
       "version": "0.8.10",
       "resolved": "https://registry.npmmirror.com/@xmldom/xmldom/-/xmldom-0.8.10.tgz",
@@ -9067,7 +9148,6 @@
       "version": "0.1.13",
       "resolved": "https://registry.npmmirror.com/encoding/-/encoding-0.1.13.tgz",
       "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==",
-      "dev": true,
       "license": "MIT",
       "optional": true,
       "dependencies": {
@@ -9078,7 +9158,6 @@
       "version": "0.6.3",
       "resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.6.3.tgz",
       "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
-      "dev": true,
       "license": "MIT",
       "optional": true,
       "dependencies": {
@@ -13202,6 +13281,12 @@
         "node": ">=8.0"
       }
     },
+    "node_modules/long": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmmirror.com/long/-/long-4.0.0.tgz",
+      "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==",
+      "license": "Apache-2.0"
+    },
     "node_modules/lru-cache": {
       "version": "5.1.1",
       "resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-5.1.1.tgz",
@@ -14117,6 +14202,26 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/node-fetch": {
+      "version": "2.6.13",
+      "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.13.tgz",
+      "integrity": "sha512-StxNAxh15zr77QvvkmveSQ8uCQ4+v5FkvNTj0OESmiHu+VRi/gXArXtkWMElOsOUNLtUEvI4yS+rdtOHZTwlQA==",
+      "license": "MIT",
+      "dependencies": {
+        "whatwg-url": "^5.0.0"
+      },
+      "engines": {
+        "node": "4.x || >=6.0.0"
+      },
+      "peerDependencies": {
+        "encoding": "^0.1.0"
+      },
+      "peerDependenciesMeta": {
+        "encoding": {
+          "optional": true
+        }
+      }
+    },
     "node_modules/node-forge": {
       "version": "1.3.1",
       "resolved": "https://registry.npmmirror.com/node-forge/-/node-forge-1.3.1.tgz",
@@ -16358,7 +16463,7 @@
       "version": "2.1.2",
       "resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
       "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
-      "dev": true,
+      "devOptional": true,
       "license": "MIT"
     },
     "node_modules/sass": {
@@ -16465,6 +16570,12 @@
         }
       }
     },
+    "node_modules/seedrandom": {
+      "version": "3.0.5",
+      "resolved": "https://registry.npmmirror.com/seedrandom/-/seedrandom-3.0.5.tgz",
+      "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==",
+      "license": "MIT"
+    },
     "node_modules/select-hose": {
       "version": "2.0.0",
       "resolved": "https://registry.npmmirror.com/select-hose/-/select-hose-2.0.0.tgz",
@@ -17729,6 +17840,12 @@
         "node": ">=0.6"
       }
     },
+    "node_modules/tr46": {
+      "version": "0.0.3",
+      "resolved": "https://registry.npmmirror.com/tr46/-/tr46-0.0.3.tgz",
+      "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
+      "license": "MIT"
+    },
     "node_modules/tree-dump": {
       "version": "1.0.2",
       "resolved": "https://registry.npmmirror.com/tree-dump/-/tree-dump-1.0.2.tgz",
@@ -18821,6 +18938,12 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/webidl-conversions": {
+      "version": "3.0.1",
+      "resolved": "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+      "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
+      "license": "BSD-2-Clause"
+    },
     "node_modules/webpack": {
       "version": "5.94.0",
       "resolved": "https://registry.npmmirror.com/webpack/-/webpack-5.94.0.tgz",
@@ -19192,6 +19315,16 @@
         "node": ">=0.8.0"
       }
     },
+    "node_modules/whatwg-url": {
+      "version": "5.0.0",
+      "resolved": "https://registry.npmmirror.com/whatwg-url/-/whatwg-url-5.0.0.tgz",
+      "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
+      "license": "MIT",
+      "dependencies": {
+        "tr46": "~0.0.3",
+        "webidl-conversions": "^3.0.0"
+      }
+    },
     "node_modules/which": {
       "version": "2.0.2",
       "resolved": "https://registry.npmmirror.com/which/-/which-2.0.2.tgz",

+ 4 - 0
soul-app/package.json

@@ -27,6 +27,10 @@
     "@capacitor/keyboard": "6.0.3",
     "@capacitor/status-bar": "6.0.2",
     "@ionic/angular": "^8.0.0",
+    "@tensorflow-models/universal-sentence-encoder": "^1.3.3",
+    "@tensorflow/tfjs-backend-cpu": "^4.22.0",
+    "@tensorflow/tfjs-converter": "^4.22.0",
+    "@tensorflow/tfjs-core": "^4.22.0",
     "fmode-ng": "^0.0.63",
     "ionicons": "^7.2.1",
     "rxjs": "~7.8.0",

+ 20 - 33
soul-app/src/app/tab2/tab2.page.ts

@@ -53,8 +53,6 @@ export class Tab2Page {
     this.cyclePlaceholder();
   }
   async clickToConsult(chatpartner:CloudObject) {
-    let consult: CloudObject | null = null;
-    let messages: string[] = [];
     // 验证用户登录
     let currentUser = new CloudUser();
     let userPrompt = ``
@@ -79,17 +77,17 @@ export class Tab2Page {
       userPrompt += `,年龄:${currentUser?.get("age")}`
     }
 
+
     // 弹窗形式聊天:开始聊天
     localStorage.setItem("company","E4KpGvTEto")
     // 创建聊天记录对象
-    consult = new CloudObject("ChatRecord")
-    messages = [];// 清空之前的消息记录
+    let consult = new CloudObject("ChatRecord")
     // 设置聊天记录的基本信息
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
     //对象权限的精确制定
     let ACL:any = {//公开访客 不可读 不可写
-      "*":{read:false,write:false}
+      "*":{read:true,write:true}
     }
     if(currentUser?.id){//当前用户 可读 可写
       ACL[currentUser?.id] = {read:true,write:true}
@@ -126,22 +124,13 @@ export class Tab2Page {
 
       onMessage: (chat: FmodeChat, message: FmodeChatMessage) => {
         console.log("onMessage", message);
-        // 直接通过 chat.messageList 获取所有消息
-        // const allMessages = chat.messageList.map(msg => msg.content).join("\n");
+        let content:any = message?.content
         // 更新 consult 对象的内容
         consult.set({
             content: chat.messageList, // 直接存储数组
         });
-        // 在此之前检查 consult 对象是否有效
-        console.log("准备保存聊天记录:", consult);
         // 仅在内容发生变化时保存
-        consult.save().then(() => {
-          console.log("聊天记录已保存");
-      }).catch((error) => {
-          console.error("保存聊天记录时出错:", error);
-      });
-
-      
+        consult.save()
       },
         // chat?.chatSession?.id 本次会话的 chatId
         onChatSaved:(chat:FmodeChat)=>{
@@ -154,6 +143,8 @@ export class Tab2Page {
 
   matchedCounselor: { name: string; specialty: string } | null = null;
 
+
+
   async goChat(chatcompanion:CloudObject) {
     // 验证用户登录
     let currentUser = new CloudUser();
@@ -177,13 +168,14 @@ export class Tab2Page {
 
     // 弹窗形式聊天:开始聊天
     localStorage.setItem("company","E4KpGvTEto")
+    // 创建聊天记录对象
     let consult = new CloudObject("ChatRecord")
-    let messages: string[] = [];
+    // 设置聊天记录的基本信息
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
     //对象权限的精确制定
     let ACL:any = {//公开访客 不可读 不可写
-      "*":{read:false,write:false}
+      "*":{read:true,write:true}
     }
     if(currentUser?.id){//当前用户 可读 可写
       ACL[currentUser?.id] = {read:true,write:true}
@@ -192,6 +184,8 @@ export class Tab2Page {
       title:`${chatcompanion.get('expertise') || ""}领域聊天记录${dateStr}-${chatcompanion.get('name')}`,
       chatcompanion:chatcompanion.toPointer(),
       user:currentUser.toPointer(),
+      content: [], // 初始内容为空
+      createdAt: now, // 可以加上创建时间
       ACL:ACL
     })
     let options:ChatPanelOptions = {
@@ -213,22 +207,15 @@ export class Tab2Page {
         ${userPrompt}
         `);
       },
-      onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
-        console.log("onMessage",message)
+      onMessage: (chat: FmodeChat, message: FmodeChatMessage) => {
+        console.log("onMessage", message);
         let content:any = message?.content
-        if(typeof content == "string"){
-          messages.push(content); // 将新消息添加到 messages 数组中
-            consult.set({
-              content:chat.messageList
-              // content: messages.join("\n"), // 将所有消息合并为一个字符串
-            });
-            consult.save().then(() => {
-              console.log("聊天记录已保存");
-          }).catch((error) => {
-              console.error("保存聊天记录时出错:", error);
-          });
-          //}
-        }
+        // 更新 consult 对象的内容
+        consult.set({
+            content: chat.messageList, // 直接存储数组
+        });
+        // 仅在内容发生变化时保存
+        consult.save()
       },
         // chat?.chatSession?.id 本次会话的 chatId
         onChatSaved:(chat:FmodeChat)=>{

+ 3 - 13
soul-app/src/lib/ncloud.ts

@@ -28,6 +28,8 @@ export class CloudObject {
     }
 
     async save() {
+        console.log('Class Name:', this.className);
+        console.log('Object ID:', this.id);
         let method = "POST";
         let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}`;
 
@@ -152,7 +154,6 @@ export class CloudQuery {
             }
             if(key=="where"){
                 paramStr = JSON.stringify(this.queryParams[key]);
-
             }
             if(queryStr) {
                 url += `${key}=${paramStr}`;
@@ -307,8 +308,7 @@ export class CloudUser extends CloudObject {
     async logout() {
 
         if (!this.sessionToken) {
-            console.error("用户未登录或会话令牌无效,直接清除用户信息");
-            this.forceLogout(); // 直接强制登出
+            console.error("用户未登录");
             return;
         }
 
@@ -333,16 +333,6 @@ export class CloudUser extends CloudObject {
         this.data = {};
         return true;
     }
-    /** 强制登出 */
-    async forceLogout() {
-    // 清除本地存储中的用户信息
-    localStorage.removeItem("NCloud/dev/User");
-    // 清空当前用户的状态
-    this.id = null;
-    this.sessionToken = null;
-    this.data = {};
-    console.log("用户已被强制登出");
-    }
 
     override async save() {
         let method = "POST";