@xuda.io/account_module 1.2.2038 → 1.2.2039
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 +21 -121
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2083,8 +2083,6 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2083
2083
|
const account_profile_info = await get_active_account_profile_info(uid, profile_id);
|
|
2084
2084
|
const { account_profile_obj } = account_profile_info;
|
|
2085
2085
|
|
|
2086
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2087
|
-
|
|
2088
2086
|
//////////////////
|
|
2089
2087
|
const opt = {
|
|
2090
2088
|
selector: {
|
|
@@ -2129,15 +2127,15 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2129
2127
|
if (_.isEmpty(cached_contact)) {
|
|
2130
2128
|
if (!is_spam && metadata.subject && !metadata.is_sent && !metadata.is_answered && !metadata.not_junk) {
|
|
2131
2129
|
// deep search for spam
|
|
2132
|
-
is_spam = await
|
|
2130
|
+
is_spam = await ai_ms.is_spam_email(uid, email, metadata.subject, account_profile_info);
|
|
2133
2131
|
}
|
|
2134
2132
|
if (!is_spam) {
|
|
2135
|
-
const is_business = await
|
|
2133
|
+
const is_business = await ai_ms.is_business_contact(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
|
|
2136
2134
|
account_type = is_business ? 'business' : 'personal';
|
|
2137
2135
|
if (is_business) {
|
|
2138
|
-
business_info = await
|
|
2136
|
+
business_info = await ai_ms.get_business_info(uid, '', email, account_profile_info, { light: true });
|
|
2139
2137
|
if (business_info.business_name !== 'Not available') {
|
|
2140
|
-
business_has_person = await
|
|
2138
|
+
business_has_person = await ai_ms.is_business_contact_has_person(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
|
|
2141
2139
|
} else {
|
|
2142
2140
|
account_type = 'personal';
|
|
2143
2141
|
business_info = undefined;
|
|
@@ -2182,9 +2180,9 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2182
2180
|
|
|
2183
2181
|
if (!is_spam) {
|
|
2184
2182
|
if (account_type === 'personal' || contact_obj?.business_has_person) {
|
|
2185
|
-
contact_obj.person_info = await
|
|
2183
|
+
contact_obj.person_info = await ai_ms.get_person_info(uid, contact_obj.name, contact_obj.email, account_profile_info, metadata?.summarized_body, { light: true });
|
|
2186
2184
|
if (!contact_obj.name) {
|
|
2187
|
-
contact_obj.name = await
|
|
2185
|
+
contact_obj.name = await ai_ms.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
|
|
2188
2186
|
}
|
|
2189
2187
|
}
|
|
2190
2188
|
} else {
|
|
@@ -2207,8 +2205,6 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2207
2205
|
};
|
|
2208
2206
|
|
|
2209
2207
|
const set_contact_profile_picture = async function (uid, contact_id, metadata, job_id, headers, account_profile_info, create_avatar) {
|
|
2210
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2211
|
-
|
|
2212
2208
|
let contact_obj;
|
|
2213
2209
|
await update_contact_profile_picture_status(uid, contact_id, 1);
|
|
2214
2210
|
try {
|
|
@@ -2235,7 +2231,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2235
2231
|
|
|
2236
2232
|
if (!cache) {
|
|
2237
2233
|
// if personal, return profile pic, if business return logo
|
|
2238
|
-
file_ret = await
|
|
2234
|
+
file_ret = await ai_ms.get_profile_picture(uid, contact_obj.account_type, contact_obj?.business_info?.business_domain || contact_obj.name, { email: contact_obj.email, metadata: contact_obj, create_avatar }, account_profile_info, job_id, headers);
|
|
2239
2235
|
|
|
2240
2236
|
if (file_ret.code < 0) {
|
|
2241
2237
|
throw new Error(file_ret.data);
|
|
@@ -2280,7 +2276,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2280
2276
|
let file_ret = { code: 1, data: cache };
|
|
2281
2277
|
|
|
2282
2278
|
if (!cache && create_avatar) {
|
|
2283
|
-
file_ret = await
|
|
2279
|
+
file_ret = await ai_ms.get_profile_avatar(
|
|
2284
2280
|
contact_obj.profile_picture,
|
|
2285
2281
|
uid,
|
|
2286
2282
|
'',
|
|
@@ -2578,8 +2574,8 @@ export const delete_contact = async function (req, job_id, headers) {
|
|
|
2578
2574
|
contact_doc.stat_reason = 'deleted by the user';
|
|
2579
2575
|
|
|
2580
2576
|
const contact_save_ret = await save_contact(uid, contact_doc);
|
|
2581
|
-
|
|
2582
|
-
|
|
2577
|
+
|
|
2578
|
+
ai_ms.delete_depended_chats(uid, contact_id);
|
|
2583
2579
|
return contact_save_ret;
|
|
2584
2580
|
} catch (err) {
|
|
2585
2581
|
return {
|
|
@@ -2729,7 +2725,6 @@ export const unpin_contact = async function (req) {
|
|
|
2729
2725
|
|
|
2730
2726
|
export const not_spam_contact = async function (req, job_id, headers) {
|
|
2731
2727
|
const email_module = await import(`${module_path}/email_module/index.mjs`);
|
|
2732
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2733
2728
|
|
|
2734
2729
|
const { contact_id, uid } = req;
|
|
2735
2730
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
@@ -2748,12 +2743,12 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2748
2743
|
}
|
|
2749
2744
|
contact_doc.is_spam = false;
|
|
2750
2745
|
|
|
2751
|
-
const is_business = await
|
|
2746
|
+
const is_business = await ai_ms.is_business_contact(uid, contact_doc.email, contact_doc.name, contact_doc?.metadata?.subject, contact_doc?.metadata?.summarized_body, account_profile_info);
|
|
2752
2747
|
contact_doc.account_type = is_business ? 'business' : 'personal';
|
|
2753
2748
|
if (is_business) {
|
|
2754
|
-
contact_doc.business_info = await
|
|
2749
|
+
contact_doc.business_info = await ai_ms.get_business_info(uid, '', contact_doc.email, account_profile_info, { light: true });
|
|
2755
2750
|
if (contact_doc.business_info.business_name !== 'Not available') {
|
|
2756
|
-
contact_doc.business_has_person = await
|
|
2751
|
+
contact_doc.business_has_person = await ai_ms.is_business_contact_has_person(uid, contact_doc.email, contact_doc.name, contact_doc?.metadata?.subject, contact_doc?.metadata?.summarized_body, account_profile_info);
|
|
2757
2752
|
} else {
|
|
2758
2753
|
contact_doc.account_type = 'personal';
|
|
2759
2754
|
contact_doc.business_info = undefined;
|
|
@@ -2793,35 +2788,6 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2793
2788
|
await email_module.process_pending_email(req, job_id, headers);
|
|
2794
2789
|
}
|
|
2795
2790
|
|
|
2796
|
-
// const conversations = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2797
|
-
// selector: {
|
|
2798
|
-
// docType: 'chat_conversation',
|
|
2799
|
-
// reference_id: contact_id,
|
|
2800
|
-
// stat: 3,
|
|
2801
|
-
|
|
2802
|
-
// process_stat: 'partial',
|
|
2803
|
-
// },
|
|
2804
|
-
// });
|
|
2805
|
-
|
|
2806
|
-
// for await (let conversation of conversations.docs) {
|
|
2807
|
-
// await ai_module.process_conversation(uid, conversation._id, account_profile_info, job_id, headers);
|
|
2808
|
-
// await ai_module.update_conversation_mood_level(uid, [{ uid: account_profile_info.uid, contact_id }], conversation._id, conversation.prompt, null, reference_id, conversation.reference_type === 'contacts', account_profile_info);
|
|
2809
|
-
|
|
2810
|
-
// const conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2811
|
-
// selector: {
|
|
2812
|
-
// docType: 'chat_conversation_item',
|
|
2813
|
-
// conversation_id: conversation._id,
|
|
2814
|
-
// stat: 3,
|
|
2815
|
-
// process_stat: 'partial',
|
|
2816
|
-
// },
|
|
2817
|
-
// });
|
|
2818
|
-
// for await (let conversation_item of conversation_items.docs) {
|
|
2819
|
-
// }
|
|
2820
|
-
// }
|
|
2821
|
-
|
|
2822
|
-
// update_conversation_mood_level
|
|
2823
|
-
// attachment_handler
|
|
2824
|
-
|
|
2825
2791
|
return contact_save_ret;
|
|
2826
2792
|
} catch (err) {
|
|
2827
2793
|
return {
|
|
@@ -2855,8 +2821,6 @@ export const generate_contact_avatar = async function (req, job_id, headers) {
|
|
|
2855
2821
|
};
|
|
2856
2822
|
|
|
2857
2823
|
export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
2858
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2859
|
-
|
|
2860
2824
|
const { contact_id, uid } = req;
|
|
2861
2825
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
2862
2826
|
try {
|
|
@@ -2864,9 +2828,9 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2864
2828
|
contact_doc.deep_research = true;
|
|
2865
2829
|
|
|
2866
2830
|
if (contact_doc.account_type === 'business') {
|
|
2867
|
-
contact_doc.business_info = await
|
|
2831
|
+
contact_doc.business_info = await ai_ms.get_business_info(uid, '', contact_doc.email, account_profile_info);
|
|
2868
2832
|
if (contact_doc.business_info.business_name !== 'Not available') {
|
|
2869
|
-
contact_doc.business_has_person = await
|
|
2833
|
+
contact_doc.business_has_person = await ai_ms.is_business_contact_has_person(uid, contact_doc.email, contact_doc.name, contact_doc?.metadata?.subject, contact_doc?.metadata?.summarized_body, account_profile_info);
|
|
2870
2834
|
} else {
|
|
2871
2835
|
contact_doc.account_type = 'personal';
|
|
2872
2836
|
contact_doc.business_info = undefined;
|
|
@@ -2874,9 +2838,9 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2874
2838
|
}
|
|
2875
2839
|
|
|
2876
2840
|
if (contact_doc.account_type === 'personal' || contact_doc?.business_has_person) {
|
|
2877
|
-
contact_doc.person_info = await
|
|
2841
|
+
contact_doc.person_info = await ai_ms.get_person_info(uid, contact_doc.name, contact_doc.email, account_profile_info, contact_doc?.metadata?.summarized_body);
|
|
2878
2842
|
if (!contact_doc.name) {
|
|
2879
|
-
contact_doc.name = await
|
|
2843
|
+
contact_doc.name = await ai_ms.get_name_from_email_addr(uid, contact_doc.email, account_profile_info);
|
|
2880
2844
|
}
|
|
2881
2845
|
}
|
|
2882
2846
|
|
|
@@ -2897,11 +2861,11 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2897
2861
|
const account_profile_info = await get_active_account_profile_info(conversation_item.uid);
|
|
2898
2862
|
let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item.conversation_id);
|
|
2899
2863
|
|
|
2900
|
-
const transcript = await
|
|
2864
|
+
const transcript = await ai_ms.get_transcript(conversation_item.uid, conversation_item.app_id, conversation_item.conversation_id, account_profile_info, conversation_item.file.filename);
|
|
2901
2865
|
let items;
|
|
2902
2866
|
|
|
2903
2867
|
if (transcript) {
|
|
2904
|
-
items = await
|
|
2868
|
+
items = await ai_ms.add_transcript_conversation_item(conversation_doc.reference_conversation_id, conversation_item.file.filename, transcript);
|
|
2905
2869
|
|
|
2906
2870
|
conversation_item.text = transcript?.data || transcript || '';
|
|
2907
2871
|
conversation_item.process_stat = 'full';
|
|
@@ -2912,67 +2876,6 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2912
2876
|
}
|
|
2913
2877
|
}
|
|
2914
2878
|
|
|
2915
|
-
// set_contact_profile_picture(uid, contact_doc._id, {}, job_id, headers, account_profile_info, false);
|
|
2916
|
-
|
|
2917
|
-
// const emails = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2918
|
-
// selector: {
|
|
2919
|
-
// docType: 'email',
|
|
2920
|
-
// contact_id,
|
|
2921
|
-
// stat: 3,
|
|
2922
|
-
// process_stat: 'partial',
|
|
2923
|
-
// },
|
|
2924
|
-
// });
|
|
2925
|
-
|
|
2926
|
-
// for await (let email of emails.docs) {
|
|
2927
|
-
// const app_id = await get_account_default_project_id(uid);
|
|
2928
|
-
// if (email.conversation_id) {
|
|
2929
|
-
// db_module.delete_app_couch_doc(app_id, email.conversation_id);
|
|
2930
|
-
// email.conversation_id = null;
|
|
2931
|
-
// }
|
|
2932
|
-
// if (email.conversation_item_id) {
|
|
2933
|
-
// db_module.delete_app_couch_doc(app_id, email.conversation_item_id);
|
|
2934
|
-
// email.conversation_item_id = null;
|
|
2935
|
-
// }
|
|
2936
|
-
// const save_ret = await db_module.save_app_couch_doc_native(app_id, email);
|
|
2937
|
-
|
|
2938
|
-
// // save attachments
|
|
2939
|
-
// // summarized_body
|
|
2940
|
-
// req.uid = email.uid;
|
|
2941
|
-
// req.email_id = email._id;
|
|
2942
|
-
// await email_module.process_pending_email(req, job_id, headers);
|
|
2943
|
-
|
|
2944
|
-
// // await process_email(email.email_account_id, profile, uid, email._id, job_id, headers, null, true);
|
|
2945
|
-
// }
|
|
2946
|
-
|
|
2947
|
-
// const conversations = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2948
|
-
// selector: {
|
|
2949
|
-
// docType: 'chat_conversation',
|
|
2950
|
-
// reference_id: contact_id,
|
|
2951
|
-
// stat: 3,
|
|
2952
|
-
|
|
2953
|
-
// process_stat: 'partial',
|
|
2954
|
-
// },
|
|
2955
|
-
// });
|
|
2956
|
-
|
|
2957
|
-
// for await (let conversation of conversations.docs) {
|
|
2958
|
-
// await ai_module.process_conversation(uid, conversation._id, account_profile_info, job_id, headers);
|
|
2959
|
-
// await ai_module.update_conversation_mood_level(uid, [{ uid: account_profile_info.uid, contact_id }], conversation._id, conversation.prompt, null, reference_id, conversation.reference_type === 'contacts', account_profile_info);
|
|
2960
|
-
|
|
2961
|
-
// const conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2962
|
-
// selector: {
|
|
2963
|
-
// docType: 'chat_conversation_item',
|
|
2964
|
-
// conversation_id: conversation._id,
|
|
2965
|
-
// stat: 3,
|
|
2966
|
-
// process_stat: 'partial',
|
|
2967
|
-
// },
|
|
2968
|
-
// });
|
|
2969
|
-
// for await (let conversation_item of conversation_items.docs) {
|
|
2970
|
-
// }
|
|
2971
|
-
// }
|
|
2972
|
-
|
|
2973
|
-
// update_conversation_mood_level
|
|
2974
|
-
// attachment_handler
|
|
2975
|
-
|
|
2976
2879
|
return contact_save_ret;
|
|
2977
2880
|
} catch (err) {
|
|
2978
2881
|
return {
|
|
@@ -2983,8 +2886,6 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2983
2886
|
};
|
|
2984
2887
|
|
|
2985
2888
|
export const unset_deep_research_contact = async function (req, job_id, headers) {
|
|
2986
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2987
|
-
|
|
2988
2889
|
const { contact_id, uid } = req;
|
|
2989
2890
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
2990
2891
|
try {
|
|
@@ -3028,7 +2929,6 @@ export const get_pending_share_profile_in = async function (uid, _id) {
|
|
|
3028
2929
|
};
|
|
3029
2930
|
|
|
3030
2931
|
export const get_account_profile_info = async function (uid, contact_profile_doc, _id) {
|
|
3031
|
-
// const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
3032
2932
|
const app_id = await get_account_default_project_id(uid);
|
|
3033
2933
|
let doc = contact_profile_doc;
|
|
3034
2934
|
if (_id) {
|
|
@@ -3337,8 +3237,8 @@ export const delete_account_profile = async function (req, job_id, headers) {
|
|
|
3337
3237
|
account_profile_doc.stat_reason = 'deleted by the user';
|
|
3338
3238
|
|
|
3339
3239
|
const account_profile_save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
|
|
3340
|
-
|
|
3341
|
-
|
|
3240
|
+
|
|
3241
|
+
ai_ms.delete_depended_chats(uid, profile_id);
|
|
3342
3242
|
return account_profile_save_ret;
|
|
3343
3243
|
} catch (err) {
|
|
3344
3244
|
return {
|