@xuda.io/account_module 1.2.2037 → 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 -154
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1835,41 +1835,8 @@ export const onboarding_completed = async function (req, job_id, headers) {
|
|
|
1835
1835
|
throw new Error(`missing profile_avatar`);
|
|
1836
1836
|
}
|
|
1837
1837
|
|
|
1838
|
-
// if (!account_doc.account_project_id) {
|
|
1839
|
-
// const app_module = await import(`${module_path}/app_module/index.mjs`);
|
|
1840
|
-
|
|
1841
|
-
// const ret = await app_module.create_project({ token_ret: req.token_ret, uid, data: { app_name: `Account ${uid} main project`, is_account_project: true, app_plugins_purchased: [' @xuda.io/xuda-dbs-plugin-xuda', '@xuda.io/xuda-framework-plugin-tailwind'] } }, job_id, headers);
|
|
1842
|
-
// if (ret.code > -1) {
|
|
1843
|
-
// account_doc.account_project_id = ret.data;
|
|
1844
|
-
// const drive_module = await import(`${module_path}/drive_module/index.mjs`);
|
|
1845
|
-
// let drive_req = { app_id: account_doc.account_project_id, uid, path: '/' };
|
|
1846
|
-
// await drive_module.create_drive_folder_user({ ...drive_req, ...{ folder_name: 'Profile Images', is_system: true } }, job_id, headers);
|
|
1847
|
-
// await drive_module.create_drive_folder_user({ ...drive_req, ...{ folder_name: 'Chat Thumbnails', is_system: true } }, job_id, headers);
|
|
1848
|
-
// await drive_module.create_drive_folder_user({ ...drive_req, ...{ folder_name: 'Chat Attachments', is_system: true } }, job_id, headers);
|
|
1849
|
-
// }
|
|
1850
|
-
// }
|
|
1851
|
-
|
|
1852
1838
|
account_doc.account_info.full_name = `${account_doc.account_info.first_name} ${account_doc.account_info.last_name}`;
|
|
1853
1839
|
|
|
1854
|
-
// if (!account_doc.ai_workspace_plan) {
|
|
1855
|
-
// account_doc.ai_workspace_plan = 'free_ai_workspace';
|
|
1856
|
-
// }
|
|
1857
|
-
|
|
1858
|
-
//// validate account_profile_id
|
|
1859
|
-
|
|
1860
|
-
// if (!account_doc.account_profile_id) {
|
|
1861
|
-
// const account_profile_ret = await create_account_profile({ uid, profile_name: account_doc.account_info.full_name, main: true });
|
|
1862
|
-
// account_doc.account_profile_id = account_profile_ret.data.id;
|
|
1863
|
-
// account_doc.account_info.active_account_profile_id = account_doc.account_profile_id;
|
|
1864
|
-
// } else {
|
|
1865
|
-
// let account_profile_ret = await db_module.get_app_couch_doc(account_doc.account_project_id, account_doc.account_profile_id);
|
|
1866
|
-
// if (account_profile_ret.code < 0) {
|
|
1867
|
-
// const account_profile_ret = await create_account_profile({ uid, profile_name: account_doc.account_info.full_name, main: true });
|
|
1868
|
-
// account_doc.account_profile_id = account_profile_ret.data.id;
|
|
1869
|
-
// account_doc.account_info.active_account_profile_id = account_doc.account_profile_id;
|
|
1870
|
-
// }
|
|
1871
|
-
// }
|
|
1872
|
-
|
|
1873
1840
|
account_doc.boarded_info = { headers, date_ts: Date.now() };
|
|
1874
1841
|
account_doc.isBoarded = true;
|
|
1875
1842
|
const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
|
|
@@ -2116,8 +2083,6 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2116
2083
|
const account_profile_info = await get_active_account_profile_info(uid, profile_id);
|
|
2117
2084
|
const { account_profile_obj } = account_profile_info;
|
|
2118
2085
|
|
|
2119
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2120
|
-
|
|
2121
2086
|
//////////////////
|
|
2122
2087
|
const opt = {
|
|
2123
2088
|
selector: {
|
|
@@ -2162,15 +2127,15 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2162
2127
|
if (_.isEmpty(cached_contact)) {
|
|
2163
2128
|
if (!is_spam && metadata.subject && !metadata.is_sent && !metadata.is_answered && !metadata.not_junk) {
|
|
2164
2129
|
// deep search for spam
|
|
2165
|
-
is_spam = await
|
|
2130
|
+
is_spam = await ai_ms.is_spam_email(uid, email, metadata.subject, account_profile_info);
|
|
2166
2131
|
}
|
|
2167
2132
|
if (!is_spam) {
|
|
2168
|
-
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);
|
|
2169
2134
|
account_type = is_business ? 'business' : 'personal';
|
|
2170
2135
|
if (is_business) {
|
|
2171
|
-
business_info = await
|
|
2136
|
+
business_info = await ai_ms.get_business_info(uid, '', email, account_profile_info, { light: true });
|
|
2172
2137
|
if (business_info.business_name !== 'Not available') {
|
|
2173
|
-
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);
|
|
2174
2139
|
} else {
|
|
2175
2140
|
account_type = 'personal';
|
|
2176
2141
|
business_info = undefined;
|
|
@@ -2215,9 +2180,9 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2215
2180
|
|
|
2216
2181
|
if (!is_spam) {
|
|
2217
2182
|
if (account_type === 'personal' || contact_obj?.business_has_person) {
|
|
2218
|
-
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 });
|
|
2219
2184
|
if (!contact_obj.name) {
|
|
2220
|
-
contact_obj.name = await
|
|
2185
|
+
contact_obj.name = await ai_ms.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
|
|
2221
2186
|
}
|
|
2222
2187
|
}
|
|
2223
2188
|
} else {
|
|
@@ -2240,8 +2205,6 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2240
2205
|
};
|
|
2241
2206
|
|
|
2242
2207
|
const set_contact_profile_picture = async function (uid, contact_id, metadata, job_id, headers, account_profile_info, create_avatar) {
|
|
2243
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2244
|
-
|
|
2245
2208
|
let contact_obj;
|
|
2246
2209
|
await update_contact_profile_picture_status(uid, contact_id, 1);
|
|
2247
2210
|
try {
|
|
@@ -2268,7 +2231,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2268
2231
|
|
|
2269
2232
|
if (!cache) {
|
|
2270
2233
|
// if personal, return profile pic, if business return logo
|
|
2271
|
-
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);
|
|
2272
2235
|
|
|
2273
2236
|
if (file_ret.code < 0) {
|
|
2274
2237
|
throw new Error(file_ret.data);
|
|
@@ -2313,7 +2276,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2313
2276
|
let file_ret = { code: 1, data: cache };
|
|
2314
2277
|
|
|
2315
2278
|
if (!cache && create_avatar) {
|
|
2316
|
-
file_ret = await
|
|
2279
|
+
file_ret = await ai_ms.get_profile_avatar(
|
|
2317
2280
|
contact_obj.profile_picture,
|
|
2318
2281
|
uid,
|
|
2319
2282
|
'',
|
|
@@ -2611,8 +2574,8 @@ export const delete_contact = async function (req, job_id, headers) {
|
|
|
2611
2574
|
contact_doc.stat_reason = 'deleted by the user';
|
|
2612
2575
|
|
|
2613
2576
|
const contact_save_ret = await save_contact(uid, contact_doc);
|
|
2614
|
-
|
|
2615
|
-
|
|
2577
|
+
|
|
2578
|
+
ai_ms.delete_depended_chats(uid, contact_id);
|
|
2616
2579
|
return contact_save_ret;
|
|
2617
2580
|
} catch (err) {
|
|
2618
2581
|
return {
|
|
@@ -2762,7 +2725,6 @@ export const unpin_contact = async function (req) {
|
|
|
2762
2725
|
|
|
2763
2726
|
export const not_spam_contact = async function (req, job_id, headers) {
|
|
2764
2727
|
const email_module = await import(`${module_path}/email_module/index.mjs`);
|
|
2765
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2766
2728
|
|
|
2767
2729
|
const { contact_id, uid } = req;
|
|
2768
2730
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
@@ -2781,12 +2743,12 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2781
2743
|
}
|
|
2782
2744
|
contact_doc.is_spam = false;
|
|
2783
2745
|
|
|
2784
|
-
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);
|
|
2785
2747
|
contact_doc.account_type = is_business ? 'business' : 'personal';
|
|
2786
2748
|
if (is_business) {
|
|
2787
|
-
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 });
|
|
2788
2750
|
if (contact_doc.business_info.business_name !== 'Not available') {
|
|
2789
|
-
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);
|
|
2790
2752
|
} else {
|
|
2791
2753
|
contact_doc.account_type = 'personal';
|
|
2792
2754
|
contact_doc.business_info = undefined;
|
|
@@ -2826,35 +2788,6 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2826
2788
|
await email_module.process_pending_email(req, job_id, headers);
|
|
2827
2789
|
}
|
|
2828
2790
|
|
|
2829
|
-
// const conversations = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2830
|
-
// selector: {
|
|
2831
|
-
// docType: 'chat_conversation',
|
|
2832
|
-
// reference_id: contact_id,
|
|
2833
|
-
// stat: 3,
|
|
2834
|
-
|
|
2835
|
-
// process_stat: 'partial',
|
|
2836
|
-
// },
|
|
2837
|
-
// });
|
|
2838
|
-
|
|
2839
|
-
// for await (let conversation of conversations.docs) {
|
|
2840
|
-
// await ai_module.process_conversation(uid, conversation._id, account_profile_info, job_id, headers);
|
|
2841
|
-
// 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);
|
|
2842
|
-
|
|
2843
|
-
// const conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2844
|
-
// selector: {
|
|
2845
|
-
// docType: 'chat_conversation_item',
|
|
2846
|
-
// conversation_id: conversation._id,
|
|
2847
|
-
// stat: 3,
|
|
2848
|
-
// process_stat: 'partial',
|
|
2849
|
-
// },
|
|
2850
|
-
// });
|
|
2851
|
-
// for await (let conversation_item of conversation_items.docs) {
|
|
2852
|
-
// }
|
|
2853
|
-
// }
|
|
2854
|
-
|
|
2855
|
-
// update_conversation_mood_level
|
|
2856
|
-
// attachment_handler
|
|
2857
|
-
|
|
2858
2791
|
return contact_save_ret;
|
|
2859
2792
|
} catch (err) {
|
|
2860
2793
|
return {
|
|
@@ -2888,8 +2821,6 @@ export const generate_contact_avatar = async function (req, job_id, headers) {
|
|
|
2888
2821
|
};
|
|
2889
2822
|
|
|
2890
2823
|
export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
2891
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
2892
|
-
|
|
2893
2824
|
const { contact_id, uid } = req;
|
|
2894
2825
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
2895
2826
|
try {
|
|
@@ -2897,9 +2828,9 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2897
2828
|
contact_doc.deep_research = true;
|
|
2898
2829
|
|
|
2899
2830
|
if (contact_doc.account_type === 'business') {
|
|
2900
|
-
contact_doc.business_info = await
|
|
2831
|
+
contact_doc.business_info = await ai_ms.get_business_info(uid, '', contact_doc.email, account_profile_info);
|
|
2901
2832
|
if (contact_doc.business_info.business_name !== 'Not available') {
|
|
2902
|
-
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);
|
|
2903
2834
|
} else {
|
|
2904
2835
|
contact_doc.account_type = 'personal';
|
|
2905
2836
|
contact_doc.business_info = undefined;
|
|
@@ -2907,9 +2838,9 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2907
2838
|
}
|
|
2908
2839
|
|
|
2909
2840
|
if (contact_doc.account_type === 'personal' || contact_doc?.business_has_person) {
|
|
2910
|
-
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);
|
|
2911
2842
|
if (!contact_doc.name) {
|
|
2912
|
-
contact_doc.name = await
|
|
2843
|
+
contact_doc.name = await ai_ms.get_name_from_email_addr(uid, contact_doc.email, account_profile_info);
|
|
2913
2844
|
}
|
|
2914
2845
|
}
|
|
2915
2846
|
|
|
@@ -2930,11 +2861,11 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2930
2861
|
const account_profile_info = await get_active_account_profile_info(conversation_item.uid);
|
|
2931
2862
|
let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item.conversation_id);
|
|
2932
2863
|
|
|
2933
|
-
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);
|
|
2934
2865
|
let items;
|
|
2935
2866
|
|
|
2936
2867
|
if (transcript) {
|
|
2937
|
-
items = await
|
|
2868
|
+
items = await ai_ms.add_transcript_conversation_item(conversation_doc.reference_conversation_id, conversation_item.file.filename, transcript);
|
|
2938
2869
|
|
|
2939
2870
|
conversation_item.text = transcript?.data || transcript || '';
|
|
2940
2871
|
conversation_item.process_stat = 'full';
|
|
@@ -2945,67 +2876,6 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2945
2876
|
}
|
|
2946
2877
|
}
|
|
2947
2878
|
|
|
2948
|
-
// set_contact_profile_picture(uid, contact_doc._id, {}, job_id, headers, account_profile_info, false);
|
|
2949
|
-
|
|
2950
|
-
// const emails = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2951
|
-
// selector: {
|
|
2952
|
-
// docType: 'email',
|
|
2953
|
-
// contact_id,
|
|
2954
|
-
// stat: 3,
|
|
2955
|
-
// process_stat: 'partial',
|
|
2956
|
-
// },
|
|
2957
|
-
// });
|
|
2958
|
-
|
|
2959
|
-
// for await (let email of emails.docs) {
|
|
2960
|
-
// const app_id = await get_account_default_project_id(uid);
|
|
2961
|
-
// if (email.conversation_id) {
|
|
2962
|
-
// db_module.delete_app_couch_doc(app_id, email.conversation_id);
|
|
2963
|
-
// email.conversation_id = null;
|
|
2964
|
-
// }
|
|
2965
|
-
// if (email.conversation_item_id) {
|
|
2966
|
-
// db_module.delete_app_couch_doc(app_id, email.conversation_item_id);
|
|
2967
|
-
// email.conversation_item_id = null;
|
|
2968
|
-
// }
|
|
2969
|
-
// const save_ret = await db_module.save_app_couch_doc_native(app_id, email);
|
|
2970
|
-
|
|
2971
|
-
// // save attachments
|
|
2972
|
-
// // summarized_body
|
|
2973
|
-
// req.uid = email.uid;
|
|
2974
|
-
// req.email_id = email._id;
|
|
2975
|
-
// await email_module.process_pending_email(req, job_id, headers);
|
|
2976
|
-
|
|
2977
|
-
// // await process_email(email.email_account_id, profile, uid, email._id, job_id, headers, null, true);
|
|
2978
|
-
// }
|
|
2979
|
-
|
|
2980
|
-
// const conversations = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2981
|
-
// selector: {
|
|
2982
|
-
// docType: 'chat_conversation',
|
|
2983
|
-
// reference_id: contact_id,
|
|
2984
|
-
// stat: 3,
|
|
2985
|
-
|
|
2986
|
-
// process_stat: 'partial',
|
|
2987
|
-
// },
|
|
2988
|
-
// });
|
|
2989
|
-
|
|
2990
|
-
// for await (let conversation of conversations.docs) {
|
|
2991
|
-
// await ai_module.process_conversation(uid, conversation._id, account_profile_info, job_id, headers);
|
|
2992
|
-
// 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);
|
|
2993
|
-
|
|
2994
|
-
// const conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
2995
|
-
// selector: {
|
|
2996
|
-
// docType: 'chat_conversation_item',
|
|
2997
|
-
// conversation_id: conversation._id,
|
|
2998
|
-
// stat: 3,
|
|
2999
|
-
// process_stat: 'partial',
|
|
3000
|
-
// },
|
|
3001
|
-
// });
|
|
3002
|
-
// for await (let conversation_item of conversation_items.docs) {
|
|
3003
|
-
// }
|
|
3004
|
-
// }
|
|
3005
|
-
|
|
3006
|
-
// update_conversation_mood_level
|
|
3007
|
-
// attachment_handler
|
|
3008
|
-
|
|
3009
2879
|
return contact_save_ret;
|
|
3010
2880
|
} catch (err) {
|
|
3011
2881
|
return {
|
|
@@ -3016,8 +2886,6 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
3016
2886
|
};
|
|
3017
2887
|
|
|
3018
2888
|
export const unset_deep_research_contact = async function (req, job_id, headers) {
|
|
3019
|
-
const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
3020
|
-
|
|
3021
2889
|
const { contact_id, uid } = req;
|
|
3022
2890
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
3023
2891
|
try {
|
|
@@ -3061,7 +2929,6 @@ export const get_pending_share_profile_in = async function (uid, _id) {
|
|
|
3061
2929
|
};
|
|
3062
2930
|
|
|
3063
2931
|
export const get_account_profile_info = async function (uid, contact_profile_doc, _id) {
|
|
3064
|
-
// const ai_module = await import(`${module_path}/ai_module/index.mjs`);
|
|
3065
2932
|
const app_id = await get_account_default_project_id(uid);
|
|
3066
2933
|
let doc = contact_profile_doc;
|
|
3067
2934
|
if (_id) {
|
|
@@ -3370,8 +3237,8 @@ export const delete_account_profile = async function (req, job_id, headers) {
|
|
|
3370
3237
|
account_profile_doc.stat_reason = 'deleted by the user';
|
|
3371
3238
|
|
|
3372
3239
|
const account_profile_save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
|
|
3373
|
-
|
|
3374
|
-
|
|
3240
|
+
|
|
3241
|
+
ai_ms.delete_depended_chats(uid, profile_id);
|
|
3375
3242
|
return account_profile_save_ret;
|
|
3376
3243
|
} catch (err) {
|
|
3377
3244
|
return {
|