@xuda.io/ai_module 1.1.5031 → 1.1.5032
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 +11 -10
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1289,17 +1289,19 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1289
1289
|
// 1. Determine Sort Pattern and Key Prefix
|
|
1290
1290
|
const sortType = reference_id ? 'ref' : 'ts';
|
|
1291
1291
|
|
|
1292
|
-
// 2. Build Base Key Arrays
|
|
1292
|
+
// 2. Build Base Key Arrays
|
|
1293
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
|
|
1294
1295
|
let startkey = [profileId, filter_type || 'all', conversation_type || null, sortType];
|
|
1295
|
-
let endkey = [profileId, filter_type || 'all', conversation_type ||
|
|
1296
|
+
let endkey = [profileId, filter_type || 'all', conversation_type || {}, sortType];
|
|
1296
1297
|
|
|
1297
1298
|
if (reference_id) {
|
|
1298
|
-
// Exact match for reference_id
|
|
1299
|
+
// Exact match for reference_id
|
|
1299
1300
|
startkey.push(reference_id);
|
|
1300
|
-
|
|
1301
|
+
// {} ensures we get all date_created_ts values for this reference_id
|
|
1302
|
+
endkey.push(reference_id, {});
|
|
1301
1303
|
} else {
|
|
1302
|
-
// For 'ts' descending,
|
|
1304
|
+
// For 'ts' descending, we reverse the start/end logic
|
|
1303
1305
|
startkey.push({});
|
|
1304
1306
|
endkey.push(0);
|
|
1305
1307
|
}
|
|
@@ -1307,9 +1309,8 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1307
1309
|
// 3. Construct Query Object
|
|
1308
1310
|
const query = {
|
|
1309
1311
|
include_docs: true,
|
|
1310
|
-
startkey: startkey, // Pass as Array
|
|
1312
|
+
startkey: startkey, // Pass as Array for Nano
|
|
1311
1313
|
endkey: endkey,
|
|
1312
|
-
// Cast to Number to prevent CouchDB "Invalid value" errors
|
|
1313
1314
|
limit: parseInt(limit) || 9999,
|
|
1314
1315
|
skip: parseInt(skip) || 0,
|
|
1315
1316
|
descending: !reference_id,
|
|
@@ -1320,11 +1321,11 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1320
1321
|
}
|
|
1321
1322
|
|
|
1322
1323
|
// 4. Call the List Function
|
|
1323
|
-
//
|
|
1324
|
+
// Ensure the order matches your Nano documentation: (ddoc, view, list, query)
|
|
1324
1325
|
const response = await db_module.call_app_list_function(
|
|
1325
1326
|
account_profile_info.app_id,
|
|
1326
|
-
'by_profile', //
|
|
1327
|
-
'filter_chats', //
|
|
1327
|
+
'by_profile', // viewname
|
|
1328
|
+
'filter_chats', // listname
|
|
1328
1329
|
query,
|
|
1329
1330
|
);
|
|
1330
1331
|
|