@xuda.io/ai_module 1.1.4419 → 1.1.4421

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.
Files changed (2) hide show
  1. package/index.mjs +55 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -3359,7 +3359,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
3359
3359
  case 'conversation': {
3360
3360
  prompt = `create image: ${doc.title}`;
3361
3361
  let images_arr;
3362
- const cache = await account_module.get_picture_cache(uid, 'chat_thumbnail', doc.title);
3362
+ const cache = await get_chat_picture_cache(uid, 'chat_thumbnail', doc.title);
3363
3363
  images_arr = [cache];
3364
3364
  if (!cache) {
3365
3365
  images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
@@ -5667,7 +5667,8 @@ const create_and_upload_image_to_drive = async function (drive_type, file_path,
5667
5667
  };
5668
5668
 
5669
5669
  export const create_avatar = async function (req, job_id, headers) {
5670
- const { docType, uid, url, _id, name, account_type, metadata } = req;
5670
+ const { docType, uid, url, _id, name, account_type } = req;
5671
+ let { metadata } = req;
5671
5672
  try {
5672
5673
  if (!['account', 'account_profile'].includes(docType)) {
5673
5674
  throw new Error('invalid docType value');
@@ -7005,3 +7006,55 @@ export const get_business_info = async function (uid, name, email, account_profi
7005
7006
  console.error('Error in get_business_info:', error);
7006
7007
  }
7007
7008
  };
7009
+
7010
+ const get_chat_picture_cache = async function (uid, docType, name) {
7011
+ if (!name || typeof name !== 'string') return null;
7012
+
7013
+ const words = name
7014
+ .trim()
7015
+ .toLowerCase()
7016
+ .split(/\s+/)
7017
+ .filter((w) => w.length > 1); // ignore very short words
7018
+
7019
+ if (words.length < 3) {
7020
+ // Direct exact match for short names
7021
+ const ret = await db_module.find_couch_query('xuda_cache', {
7022
+ selector: { docType, name: name.trim() },
7023
+ limit: 1,
7024
+ });
7025
+
7026
+ return ret.docs[0]?.file ?? null;
7027
+ }
7028
+
7029
+ // Try combinations of 3 words — but **limit** the number of attempts
7030
+ const MAX_ATTEMPTS = 15; // prevent explosion on long names
7031
+ const combinations = [];
7032
+
7033
+ for (let i = 0; i < words.length - 2 && combinations.length < MAX_ATTEMPTS; i++) {
7034
+ for (let j = i + 1; j < words.length - 1 && combinations.length < MAX_ATTEMPTS; j++) {
7035
+ for (let k = j + 1; k < words.length && combinations.length < MAX_ATTEMPTS; k++) {
7036
+ combinations.push([words[i], words[j], words[k]]);
7037
+ }
7038
+ }
7039
+ }
7040
+
7041
+ for (const threeWords of combinations) {
7042
+ const query = {
7043
+ selector: {
7044
+ docType,
7045
+ $and: threeWords.map((word) => ({
7046
+ name: { $regex: `(?i)\\b${word}\\b` },
7047
+ })),
7048
+ },
7049
+ limit: 1,
7050
+ };
7051
+
7052
+ const ret = await db_module.find_couch_query('xuda_cache', query);
7053
+
7054
+ if (ret.docs.length > 0) {
7055
+ return ret.docs[0].file;
7056
+ }
7057
+ }
7058
+
7059
+ return null;
7060
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4419",
3
+ "version": "1.1.4421",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",