@xuda.io/ai_module 1.1.4624 → 1.1.4626
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 +39 -9
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1786,8 +1786,6 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1786
1786
|
};
|
|
1787
1787
|
|
|
1788
1788
|
try {
|
|
1789
|
-
// if (_id) return await get_studio_doc({ _id, uid });
|
|
1790
|
-
|
|
1791
1789
|
if (_id) {
|
|
1792
1790
|
const app_id = await account_module.get_account_default_project_id(uid);
|
|
1793
1791
|
let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
|
|
@@ -1867,7 +1865,32 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1867
1865
|
};
|
|
1868
1866
|
}
|
|
1869
1867
|
|
|
1870
|
-
|
|
1868
|
+
const chat_conversation_count = async function (_id) {
|
|
1869
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
1870
|
+
|
|
1871
|
+
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
1872
|
+
reduce: true,
|
|
1873
|
+
group_level: 1,
|
|
1874
|
+
|
|
1875
|
+
startkey: [_id, ''],
|
|
1876
|
+
endkey: [_id, 'zzzzzz'],
|
|
1877
|
+
});
|
|
1878
|
+
|
|
1879
|
+
return counts_ret?.rows?.[0]?.value || 0;
|
|
1880
|
+
};
|
|
1881
|
+
const chat_conversation_read = async function (_id) {
|
|
1882
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
1883
|
+
|
|
1884
|
+
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
|
|
1885
|
+
reduce: true,
|
|
1886
|
+
group_level: 2,
|
|
1887
|
+
|
|
1888
|
+
startkey: [uid, _id, ''],
|
|
1889
|
+
endkey: [uid, _id, 'zzzzzz'],
|
|
1890
|
+
});
|
|
1891
|
+
|
|
1892
|
+
return counts_ret?.rows?.[0]?.value || 0;
|
|
1893
|
+
};
|
|
1871
1894
|
|
|
1872
1895
|
////// FROM - IN
|
|
1873
1896
|
let requests_from = { docs: [], total_docs: 0 };
|
|
@@ -1924,11 +1947,18 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1924
1947
|
doc.reference_doc = reference_doc;
|
|
1925
1948
|
}
|
|
1926
1949
|
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1950
|
+
const contact_chat_conversation_count_ret = await chat_conversation_count(doc._id);
|
|
1951
|
+
const contact_chat_conversation_read_ret = await chat_conversation_read(doc._id);
|
|
1952
|
+
|
|
1953
|
+
doc.interactions = contact_chat_conversation_count_ret;
|
|
1954
|
+
doc.notifications = contact_chat_conversation_count_ret - contact_chat_conversation_read_ret;
|
|
1955
|
+
doc.chats = doc.interactions;
|
|
1956
|
+
|
|
1957
|
+
// doc.notifications = 0;
|
|
1958
|
+
// doc.interactions = doc?.messages?.length || 0;
|
|
1959
|
+
// for (let msg of doc.messages) {
|
|
1960
|
+
// if (!msg.read) doc.notifications++;
|
|
1961
|
+
// }
|
|
1932
1962
|
|
|
1933
1963
|
// if (!doc.chat_image && (!doc.thumbnail_request_ts || Date.now() - doc.thumbnail_request_ts > 120000)) {
|
|
1934
1964
|
// if (headers) {
|
|
@@ -5229,7 +5259,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
5229
5259
|
outputTokens += item.usage.outputTokens;
|
|
5230
5260
|
}
|
|
5231
5261
|
|
|
5232
|
-
|
|
5262
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
5233
5263
|
|
|
5234
5264
|
// let conversation_item_obj = {
|
|
5235
5265
|
// _id: obj.id,
|