@xuda.io/ai_module 1.1.5092 → 1.1.5094

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 +32 -6
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1290,7 +1290,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1290
1290
  return ai_chats;
1291
1291
  };
1292
1292
 
1293
- const get_data_view = async function () {
1293
+ const get_data_view_conversation = async function () {
1294
1294
  // const profileId = account_profile_info.is_main ? 'ADMIN_OR_ALL' : account_profile_info.account_profile_id;
1295
1295
  // debugger;
1296
1296
  // // 1. Determine Sort Pattern and Key Prefix
@@ -1331,10 +1331,37 @@ export const get_ai_chats = async function (req, job_id, headers) {
1331
1331
 
1332
1332
  let stat_type = filter_type === 'archived' ? 'archived' : 'all';
1333
1333
 
1334
- // const profile_id = account_profile_info.is_main ? 'all' : account_profile_info.account_profile_id;
1335
- // const conv_type = conversation_type ? conversation_type : 'all';
1334
+ const ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_list', {
1335
+ startkey: [stat_type, reference_id, 0],
1336
+ endkey: [stat_type, reference_id, 9999999999999],
1337
+ limit: parseInt(limit) || 9999,
1338
+ skip: parseInt(skip) || 0,
1339
+ include_docs: true,
1340
+ descending: false,
1341
+ });
1342
+
1343
+ let conversations = {};
1344
+ let docs = [];
1345
+ for (let val of ret.rows || []) {
1346
+ if (!conversations[val.value.conversation_id]) {
1347
+ conversations[val.value.conversation_id] = {};
1348
+ }
1349
+ conversations[val.value.conversation_id][val.value.type] = val.doc;
1350
+ }
1351
+
1352
+ for (let val of ret.rows || []) {
1353
+ if (val.value.type === 'conversation') {
1354
+ docs.push(conversations[val.value.conversation_id]);
1355
+ }
1356
+ }
1357
+
1358
+ return { docs };
1359
+ };
1360
+
1361
+ const get_data_view_conversation_items = async function () {
1362
+ let stat_type = filter_type === 'archived' ? 'archived' : 'all';
1336
1363
 
1337
- const ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'ai_chat_list', {
1364
+ const ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_list', {
1338
1365
  startkey: [stat_type, reference_id, 0],
1339
1366
  endkey: [stat_type, reference_id, 9999999999999],
1340
1367
  limit: parseInt(limit) || 9999,
@@ -1391,9 +1418,8 @@ export const get_ai_chats = async function (req, job_id, headers) {
1391
1418
  let ai_chats = { docs: [], total_docs: 0 };
1392
1419
 
1393
1420
  if (filter_type !== 'pending') {
1394
- ai_chats = await get_data_view();
1395
1421
  if (reference_id && reference_type === 'contacts') {
1396
- ai_chats = await get_data_view();
1422
+ ai_chats = await get_data_view_conversation_items();
1397
1423
  } else {
1398
1424
  ai_chats = await get_data_find();
1399
1425
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5092",
3
+ "version": "1.1.5094",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",