@xuda.io/ai_module 1.1.5027 → 1.1.5029

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 +27 -49
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1285,73 +1285,51 @@ export const get_ai_chats = async function (req, job_id, headers) {
1285
1285
 
1286
1286
  const get_data_view = async function () {
1287
1287
  const profileId = account_profile_info.is_main ? 'ADMIN_OR_ALL' : account_profile_info.account_profile_id;
1288
- debugger;
1288
+
1289
1289
  // 1. Determine Sort Pattern and Key Prefix
1290
1290
  const sortType = reference_id ? 'ref' : 'ts';
1291
1291
 
1292
- // 2. Build Base Key
1292
+ // 2. Build Base Key Arrays as raw objects
1293
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];
1294
+ let startkey = [profileId, filter_type || 'all', conversation_type || null, sortType];
1295
+ let endkey = [profileId, filter_type || 'all', conversation_type || null, sortType];
1296
1296
 
1297
1297
  if (reference_id) {
1298
+ // Exact match for reference_id, sorted by date_created_ts ASC
1298
1299
  startkey.push(reference_id);
1299
- endkey.push(reference_id, {}); // {} acts as a high-value sentinel
1300
+ endkey.push(reference_id, {}); // {} is the high-value sentinel
1300
1301
  } else {
1301
- startkey.push({}); // For 'ts' descending, start at the "highest" possible value
1302
+ // For 'ts' descending, startkey must be the "highest" value
1303
+ startkey.push({});
1302
1304
  endkey.push(0);
1303
1305
  }
1304
1306
 
1305
- // 3. Construct Query
1307
+ // 3. Construct Query Object
1306
1308
  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'
1309
+ include_docs: true,
1310
+ startkey: startkey, // Pass as Array; Nano handles the stringification
1311
+ endkey: endkey,
1312
+ // Cast to Number to prevent CouchDB "Invalid value" errors
1313
+ limit: parseInt(limit) || 9999,
1314
+ skip: parseInt(skip) || 0,
1315
+ descending: !reference_id,
1313
1316
  };
1314
1317
 
1315
- if (search) query.search = encodeURIComponent(search);
1318
+ if (search) {
1319
+ query.search = encodeURIComponent(search);
1320
+ }
1316
1321
 
1317
1322
  // 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
- // let stat = 3;
1324
-
1325
- // switch (filter_type) {
1326
- // case 'archived': {
1327
- // stat = 5;
1328
- // break;
1329
- // }
1330
- // case 'shared': {
1331
- // opt.selector.shared_from_uid = { $gt: null };
1332
- // // opt.selector.team_req_stat = { $eq: 3 };
1333
- // break;
1334
- // }
1335
-
1336
- // case 'mine': {
1337
- // opt.selector.uid = uid;
1338
-
1339
- // break;
1340
- // }
1323
+ // Adjusted to match your signature without the redundant 'chats' arg
1324
+ const response = await db_module.call_app_list_function(
1325
+ account_profile_info.app_id,
1341
1326
 
1342
- // default:
1343
- // // opt.selector.team_req_stat = { $eq: 3 };
1344
- // break;
1345
- // }
1327
+ 'by_profile', // View Name ,
1328
+ // 'filter_chats', // List Name
1329
+ query,
1330
+ );
1346
1331
 
1347
- // const ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'ai_chat_list', {
1348
- // startkey: [stat, reference_id, 0],
1349
- // endkey: [stat, reference_id, 9999999999999],
1350
- // limit: limit || 9999,
1351
- // skip: skip || 0,
1352
- // include_docs: true,
1353
- // descending: reference_id ? false : true,
1354
- // });
1332
+ return response;
1355
1333
  };
1356
1334
 
1357
1335
  ////// FROM - IN
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5027",
3
+ "version": "1.1.5029",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",