@xuda.io/ai_module 1.1.5032 → 1.1.5034

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 +64 -38
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1284,52 +1284,78 @@ export const get_ai_chats = async function (req, job_id, headers) {
1284
1284
  };
1285
1285
 
1286
1286
  const get_data_view = async function () {
1287
- const profileId = account_profile_info.is_main ? 'ADMIN_OR_ALL' : account_profile_info.account_profile_id;
1287
+ // const profileId = account_profile_info.is_main ? 'ADMIN_OR_ALL' : account_profile_info.account_profile_id;
1288
+ // debugger;
1289
+ // // 1. Determine Sort Pattern and Key Prefix
1290
+ // const sortType = reference_id ? 'ref' : 'ts';
1288
1291
 
1289
- // 1. Determine Sort Pattern and Key Prefix
1290
- const sortType = reference_id ? 'ref' : 'ts';
1292
+ // // 2. Build Base Key
1293
+ // // Key Structure: [profileId, type, convType, sortType, sortVal1, sortVal2]
1294
+ // let startkey = [profileId, filter_type, conversation_type || null, sortType];
1295
+ // let endkey = [profileId, filter_type, conversation_type || null, sortType];
1291
1296
 
1292
- // 2. Build Base Key Arrays
1293
- // Key Structure: [profileId, type, convType, sortType, sortVal1, sortVal2]
1294
- // We use null for start and {} for end to capture ALL conversation types if conversation_type is missing
1295
- let startkey = [profileId, filter_type || 'all', conversation_type || null, sortType];
1296
- let endkey = [profileId, filter_type || 'all', conversation_type || {}, sortType];
1297
+ // if (reference_id) {
1298
+ // startkey.push(reference_id);
1299
+ // endkey.push(reference_id, {}); // {} acts as a high-value sentinel
1300
+ // } else {
1301
+ // startkey.push({}); // For 'ts' descending, start at the "highest" possible value
1302
+ // endkey.push(0);
1303
+ // }
1297
1304
 
1298
- if (reference_id) {
1299
- // Exact match for reference_id
1300
- startkey.push(reference_id);
1301
- // {} ensures we get all date_created_ts values for this reference_id
1302
- endkey.push(reference_id, {});
1303
- } else {
1304
- // For 'ts' descending, we reverse the start/end logic
1305
- startkey.push({});
1306
- endkey.push(0);
1307
- }
1305
+ // // 3. Construct Query
1306
+ // const query = {
1307
+ // include_docs: true, // Required for list function search and data retrieval
1308
+ // startkey: JSON.stringify(startkey),
1309
+ // endkey: JSON.stringify(endkey),
1310
+ // limit,
1311
+ // skip,
1312
+ // descending: !reference_id, // Descending for 'ts', Ascending for 'ref'
1313
+ // };
1308
1314
 
1309
- // 3. Construct Query Object
1310
- const query = {
1311
- include_docs: true,
1312
- startkey: startkey, // Pass as Array for Nano
1313
- endkey: endkey,
1314
- limit: parseInt(limit) || 9999,
1315
- skip: parseInt(skip) || 0,
1316
- descending: !reference_id,
1317
- };
1315
+ // if (search) query.search = encodeURIComponent(search);
1318
1316
 
1319
- if (search) {
1320
- query.search = encodeURIComponent(search);
1317
+ // // 4. Call the List Function
1318
+ // // URL: /db/_design/chats/_list/filter_chats/by_profile
1319
+ // const response = await db_module.call_app_list_function(account_profile_info.app_id, 'by_profile', 'filter_chats', query);
1320
+
1321
+ // return response;
1322
+
1323
+ //====================
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;
1321
1347
  }
1322
1348
 
1323
- // 4. Call the List Function
1324
- // Ensure the order matches your Nano documentation: (ddoc, view, list, query)
1325
- const response = await db_module.call_app_list_function(
1326
- account_profile_info.app_id,
1327
- 'by_profile', // viewname
1328
- 'filter_chats', // listname
1329
- query,
1330
- );
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
+ });
1331
1357
 
1332
- return response;
1358
+ debugger;
1333
1359
  };
1334
1360
 
1335
1361
  ////// FROM - IN
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5032",
3
+ "version": "1.1.5034",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",