@xuda.io/ai_module 1.1.5017 → 1.1.5019
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/index.mjs +64 -26
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1284,38 +1284,76 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1284
1284
|
};
|
|
1285
1285
|
|
|
1286
1286
|
const get_data_view = async function () {
|
|
1287
|
-
|
|
1287
|
+
const { account_profile_info, filter_type = 'default', conversation_type, reference_id, conversation_id, search, limit = 9999, skip = 0 } = params;
|
|
1288
1288
|
|
|
1289
|
-
|
|
1290
|
-
case 'archived': {
|
|
1291
|
-
stat = 5;
|
|
1292
|
-
break;
|
|
1293
|
-
}
|
|
1294
|
-
case 'shared': {
|
|
1295
|
-
opt.selector.shared_from_uid = { $gt: null };
|
|
1296
|
-
// opt.selector.team_req_stat = { $eq: 3 };
|
|
1297
|
-
break;
|
|
1298
|
-
}
|
|
1289
|
+
const profileId = account_profile_info.is_main ? 'ADMIN_OR_ALL' : account_profile_info.account_profile_id;
|
|
1299
1290
|
|
|
1300
|
-
|
|
1301
|
-
|
|
1291
|
+
// 1. Determine Sort Pattern and Key Prefix
|
|
1292
|
+
const sortType = reference_id ? 'ref' : 'ts';
|
|
1302
1293
|
|
|
1303
|
-
|
|
1304
|
-
|
|
1294
|
+
// 2. Build Base Key
|
|
1295
|
+
// Key Structure: [profileId, type, convType, sortType, sortVal1, sortVal2]
|
|
1296
|
+
let startkey = [profileId, filter_type, conversation_type || null, sortType];
|
|
1297
|
+
let endkey = [profileId, filter_type, conversation_type || null, sortType];
|
|
1305
1298
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1299
|
+
if (reference_id) {
|
|
1300
|
+
startkey.push(reference_id);
|
|
1301
|
+
endkey.push(reference_id, {}); // {} acts as a high-value sentinel
|
|
1302
|
+
} else {
|
|
1303
|
+
startkey.push({}); // For 'ts' descending, start at the "highest" possible value
|
|
1304
|
+
endkey.push(0);
|
|
1309
1305
|
}
|
|
1310
1306
|
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1307
|
+
// 3. Construct Query
|
|
1308
|
+
const query = {
|
|
1309
|
+
include_docs: true, // Required for list function search and data retrieval
|
|
1310
|
+
startkey: JSON.stringify(startkey),
|
|
1311
|
+
endkey: JSON.stringify(endkey),
|
|
1312
|
+
limit,
|
|
1313
|
+
skip,
|
|
1314
|
+
descending: !reference_id, // Descending for 'ts', Ascending for 'ref'
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
if (search) query.search = encodeURIComponent(search);
|
|
1318
|
+
|
|
1319
|
+
// 4. Call the List Function
|
|
1320
|
+
// URL: /db/_design/chats/_list/filter_chats/by_profile
|
|
1321
|
+
const response = await db_module.call_list_function(account_profile_info.app_id, 'filter_chats', 'by_profile', query);
|
|
1322
|
+
|
|
1323
|
+
return response;
|
|
1324
|
+
|
|
1325
|
+
// let stat = 3;
|
|
1326
|
+
|
|
1327
|
+
// switch (filter_type) {
|
|
1328
|
+
// case 'archived': {
|
|
1329
|
+
// stat = 5;
|
|
1330
|
+
// break;
|
|
1331
|
+
// }
|
|
1332
|
+
// case 'shared': {
|
|
1333
|
+
// opt.selector.shared_from_uid = { $gt: null };
|
|
1334
|
+
// // opt.selector.team_req_stat = { $eq: 3 };
|
|
1335
|
+
// break;
|
|
1336
|
+
// }
|
|
1337
|
+
|
|
1338
|
+
// case 'mine': {
|
|
1339
|
+
// opt.selector.uid = uid;
|
|
1340
|
+
|
|
1341
|
+
// break;
|
|
1342
|
+
// }
|
|
1343
|
+
|
|
1344
|
+
// default:
|
|
1345
|
+
// // opt.selector.team_req_stat = { $eq: 3 };
|
|
1346
|
+
// break;
|
|
1347
|
+
// }
|
|
1348
|
+
|
|
1349
|
+
// const ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'ai_chat_list', {
|
|
1350
|
+
// startkey: [stat, reference_id, 0],
|
|
1351
|
+
// endkey: [stat, reference_id, 9999999999999],
|
|
1352
|
+
// limit: limit || 9999,
|
|
1353
|
+
// skip: skip || 0,
|
|
1354
|
+
// include_docs: true,
|
|
1355
|
+
// descending: reference_id ? false : true,
|
|
1356
|
+
// });
|
|
1319
1357
|
};
|
|
1320
1358
|
|
|
1321
1359
|
////// FROM - IN
|