@xuda.io/account_module 1.2.2038 → 1.2.2040

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 +23 -160
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1579,18 +1579,6 @@ export const update_contact = async function (req) {
1579
1579
  }
1580
1580
  return { code: -1, data: 'contact not found' };
1581
1581
  };
1582
- // export const invite_user = async function (req) {
1583
- // const { email, name, uid } = req;
1584
-
1585
- // const team_module = await import(`${module_path}/team_module/index.mjs`);
1586
- // const ret = await team_module.create_team_request({
1587
- // email,
1588
- // access_type: 'contact',
1589
- // uid,
1590
- // });
1591
-
1592
- // // return { code: -1, data: "contact already exist active or deleted" };
1593
- // };
1594
1582
 
1595
1583
  export const get_account_rt_info = async function (uid) {
1596
1584
  const doc_ret = await db_module.get_couch_doc('xuda_accounts', uid);
@@ -1797,29 +1785,6 @@ export const get_user_card = async function (uid, uid_query) {
1797
1785
  return user_contact_obj;
1798
1786
  };
1799
1787
 
1800
- // export const generate_user_avatar = async function (req, job_id, headers) {
1801
- // const { uid, account_info } = req;
1802
- // try {
1803
- // const ai_module = await import(`${module_path}/ai_module/index.mjs`);
1804
-
1805
- // ai_module.get_profile_avatar({ url: account_info?.profile_picture, uid, account_obj }, job_id, headers);
1806
-
1807
- // // const account_info = await get_account_name({ uid });
1808
- // // let username = 'unknown';
1809
- // // if (account_info) {
1810
- // // username = account_info.first_name + ' ' + account_info.last_name;
1811
-
1812
- // // if (!username) {
1813
- // // username = +account_info.email;
1814
- // // }
1815
- // // }
1816
-
1817
- // // return username;
1818
- // } catch (err) {
1819
- // return 'unknown';
1820
- // }
1821
- // };
1822
-
1823
1788
  export const onboarding_completed = async function (req, job_id, headers) {
1824
1789
  const { uid } = req;
1825
1790
  try {
@@ -1939,8 +1904,6 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
1939
1904
  };
1940
1905
 
1941
1906
  const set_account_profile_picture = async function (uid, account_uid, metadata, job_id, headers, account_profile_info) {
1942
- const ai_module = await import(`${module_path}/ai_module/index.mjs`);
1943
- // const account_profile_info = await get_active_account_profile_info(uid);
1944
1907
  await update_account_profile_picture_status(account_uid, 1);
1945
1908
  try {
1946
1909
  let profile_picture;
@@ -1956,7 +1919,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
1956
1919
 
1957
1920
  await update_account_profile_picture_status(account_uid, 2);
1958
1921
  if (!account_info.profile_picture) {
1959
- const file_ret = await ai_module.get_profile_picture(uid, account_info.account_type, name, { email: account_info.email, metadata, account_info }, account_profile_info, job_id, headers);
1922
+ const file_ret = await ai_ms.get_profile_picture(uid, account_info.account_type, name, { email: account_info.email, metadata, account_info }, account_profile_info, job_id, headers);
1960
1923
 
1961
1924
  let { code: account_code, data: account_obj2 } = await db_module.get_couch_doc('xuda_accounts', account_uid);
1962
1925
  account_obj = account_obj2;
@@ -2008,7 +1971,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
2008
1971
 
2009
1972
  const { bio, country, mainCategory, subCategory } = account_info;
2010
1973
 
2011
- const file_ret = await ai_module.get_profile_avatar(account_info.profile_picture, uid, '', account_profile_info, account_info.account_type, 'account', account_uid, { bio, country, mainCategory, subCategory, is_user: true }, business_size, name, account_info.email, job_id, headers);
1974
+ const file_ret = await ai_ms.get_profile_avatar(account_info.profile_picture, uid, '', account_profile_info, account_info.account_type, 'account', account_uid, { bio, country, mainCategory, subCategory, is_user: true }, business_size, name, account_info.email, job_id, headers);
2012
1975
  if (file_ret.code < 0) {
2013
1976
  throw new Error(file_ret.data);
2014
1977
  }
@@ -2083,8 +2046,6 @@ export const add_contact = async function (req, job_id, headers) {
2083
2046
  const account_profile_info = await get_active_account_profile_info(uid, profile_id);
2084
2047
  const { account_profile_obj } = account_profile_info;
2085
2048
 
2086
- const ai_module = await import(`${module_path}/ai_module/index.mjs`);
2087
-
2088
2049
  //////////////////
2089
2050
  const opt = {
2090
2051
  selector: {
@@ -2129,15 +2090,15 @@ export const add_contact = async function (req, job_id, headers) {
2129
2090
  if (_.isEmpty(cached_contact)) {
2130
2091
  if (!is_spam && metadata.subject && !metadata.is_sent && !metadata.is_answered && !metadata.not_junk) {
2131
2092
  // deep search for spam
2132
- is_spam = await ai_module.is_spam_email(uid, email, metadata.subject, account_profile_info);
2093
+ is_spam = await ai_ms.is_spam_email(uid, email, metadata.subject, account_profile_info);
2133
2094
  }
2134
2095
  if (!is_spam) {
2135
- const is_business = await ai_module.is_business_contact(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2096
+ const is_business = await ai_ms.is_business_contact(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2136
2097
  account_type = is_business ? 'business' : 'personal';
2137
2098
  if (is_business) {
2138
- business_info = await ai_module.get_business_info(uid, '', email, account_profile_info, { light: true });
2099
+ business_info = await ai_ms.get_business_info(uid, '', email, account_profile_info, { light: true });
2139
2100
  if (business_info.business_name !== 'Not available') {
2140
- business_has_person = await ai_module.is_business_contact_has_person(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2101
+ business_has_person = await ai_ms.is_business_contact_has_person(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2141
2102
  } else {
2142
2103
  account_type = 'personal';
2143
2104
  business_info = undefined;
@@ -2182,9 +2143,9 @@ export const add_contact = async function (req, job_id, headers) {
2182
2143
 
2183
2144
  if (!is_spam) {
2184
2145
  if (account_type === 'personal' || contact_obj?.business_has_person) {
2185
- contact_obj.person_info = await ai_module.get_person_info(uid, contact_obj.name, contact_obj.email, account_profile_info, metadata?.summarized_body, { light: true });
2146
+ 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
2147
  if (!contact_obj.name) {
2187
- contact_obj.name = await ai_module.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
2148
+ contact_obj.name = await ai_ms.get_name_from_email_addr(uid, contact_obj.email, account_profile_info);
2188
2149
  }
2189
2150
  }
2190
2151
  } else {
@@ -2207,8 +2168,6 @@ export const add_contact = async function (req, job_id, headers) {
2207
2168
  };
2208
2169
 
2209
2170
  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
2171
  let contact_obj;
2213
2172
  await update_contact_profile_picture_status(uid, contact_id, 1);
2214
2173
  try {
@@ -2235,7 +2194,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2235
2194
 
2236
2195
  if (!cache) {
2237
2196
  // if personal, return profile pic, if business return logo
2238
- file_ret = await ai_module.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);
2197
+ 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
2198
 
2240
2199
  if (file_ret.code < 0) {
2241
2200
  throw new Error(file_ret.data);
@@ -2280,7 +2239,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2280
2239
  let file_ret = { code: 1, data: cache };
2281
2240
 
2282
2241
  if (!cache && create_avatar) {
2283
- file_ret = await ai_module.get_profile_avatar(
2242
+ file_ret = await ai_ms.get_profile_avatar(
2284
2243
  contact_obj.profile_picture,
2285
2244
  uid,
2286
2245
  '',
@@ -2578,8 +2537,8 @@ export const delete_contact = async function (req, job_id, headers) {
2578
2537
  contact_doc.stat_reason = 'deleted by the user';
2579
2538
 
2580
2539
  const contact_save_ret = await save_contact(uid, contact_doc);
2581
- const ai_module = await import(`${module_path}/ai_module/index.mjs`);
2582
- ai_module.delete_depended_chats(uid, contact_id);
2540
+
2541
+ ai_ms.delete_depended_chats(uid, contact_id);
2583
2542
  return contact_save_ret;
2584
2543
  } catch (err) {
2585
2544
  return {
@@ -2729,7 +2688,6 @@ export const unpin_contact = async function (req) {
2729
2688
 
2730
2689
  export const not_spam_contact = async function (req, job_id, headers) {
2731
2690
  const email_module = await import(`${module_path}/email_module/index.mjs`);
2732
- const ai_module = await import(`${module_path}/ai_module/index.mjs`);
2733
2691
 
2734
2692
  const { contact_id, uid } = req;
2735
2693
  const account_profile_info = await get_active_account_profile_info(uid);
@@ -2748,12 +2706,12 @@ export const not_spam_contact = async function (req, job_id, headers) {
2748
2706
  }
2749
2707
  contact_doc.is_spam = false;
2750
2708
 
2751
- const is_business = await ai_module.is_business_contact(uid, contact_doc.email, contact_doc.name, contact_doc?.metadata?.subject, contact_doc?.metadata?.summarized_body, account_profile_info);
2709
+ 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
2710
  contact_doc.account_type = is_business ? 'business' : 'personal';
2753
2711
  if (is_business) {
2754
- contact_doc.business_info = await ai_module.get_business_info(uid, '', contact_doc.email, account_profile_info, { light: true });
2712
+ contact_doc.business_info = await ai_ms.get_business_info(uid, '', contact_doc.email, account_profile_info, { light: true });
2755
2713
  if (contact_doc.business_info.business_name !== 'Not available') {
2756
- contact_doc.business_has_person = await ai_module.is_business_contact_has_person(uid, contact_doc.email, contact_doc.name, contact_doc?.metadata?.subject, contact_doc?.metadata?.summarized_body, account_profile_info);
2714
+ 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
2715
  } else {
2758
2716
  contact_doc.account_type = 'personal';
2759
2717
  contact_doc.business_info = undefined;
@@ -2793,35 +2751,6 @@ export const not_spam_contact = async function (req, job_id, headers) {
2793
2751
  await email_module.process_pending_email(req, job_id, headers);
2794
2752
  }
2795
2753
 
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
2754
  return contact_save_ret;
2826
2755
  } catch (err) {
2827
2756
  return {
@@ -2855,8 +2784,6 @@ export const generate_contact_avatar = async function (req, job_id, headers) {
2855
2784
  };
2856
2785
 
2857
2786
  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
2787
  const { contact_id, uid } = req;
2861
2788
  const account_profile_info = await get_active_account_profile_info(uid);
2862
2789
  try {
@@ -2864,9 +2791,9 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2864
2791
  contact_doc.deep_research = true;
2865
2792
 
2866
2793
  if (contact_doc.account_type === 'business') {
2867
- contact_doc.business_info = await ai_module.get_business_info(uid, '', contact_doc.email, account_profile_info);
2794
+ contact_doc.business_info = await ai_ms.get_business_info(uid, '', contact_doc.email, account_profile_info);
2868
2795
  if (contact_doc.business_info.business_name !== 'Not available') {
2869
- contact_doc.business_has_person = await ai_module.is_business_contact_has_person(uid, contact_doc.email, contact_doc.name, contact_doc?.metadata?.subject, contact_doc?.metadata?.summarized_body, account_profile_info);
2796
+ 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
2797
  } else {
2871
2798
  contact_doc.account_type = 'personal';
2872
2799
  contact_doc.business_info = undefined;
@@ -2874,9 +2801,9 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2874
2801
  }
2875
2802
 
2876
2803
  if (contact_doc.account_type === 'personal' || contact_doc?.business_has_person) {
2877
- contact_doc.person_info = await ai_module.get_person_info(uid, contact_doc.name, contact_doc.email, account_profile_info, contact_doc?.metadata?.summarized_body);
2804
+ 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
2805
  if (!contact_doc.name) {
2879
- contact_doc.name = await ai_module.get_name_from_email_addr(uid, contact_doc.email, account_profile_info);
2806
+ contact_doc.name = await ai_ms.get_name_from_email_addr(uid, contact_doc.email, account_profile_info);
2880
2807
  }
2881
2808
  }
2882
2809
 
@@ -2897,11 +2824,11 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2897
2824
  const account_profile_info = await get_active_account_profile_info(conversation_item.uid);
2898
2825
  let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item.conversation_id);
2899
2826
 
2900
- const transcript = await ai_module.get_transcript(conversation_item.uid, conversation_item.app_id, conversation_item.conversation_id, account_profile_info, conversation_item.file.filename);
2827
+ 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
2828
  let items;
2902
2829
 
2903
2830
  if (transcript) {
2904
- items = await ai_module.add_transcript_conversation_item(conversation_doc.reference_conversation_id, conversation_item.file.filename, transcript);
2831
+ items = await ai_ms.add_transcript_conversation_item(conversation_doc.reference_conversation_id, conversation_item.file.filename, transcript);
2905
2832
 
2906
2833
  conversation_item.text = transcript?.data || transcript || '';
2907
2834
  conversation_item.process_stat = 'full';
@@ -2912,67 +2839,6 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2912
2839
  }
2913
2840
  }
2914
2841
 
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
2842
  return contact_save_ret;
2977
2843
  } catch (err) {
2978
2844
  return {
@@ -2983,8 +2849,6 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2983
2849
  };
2984
2850
 
2985
2851
  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
2852
  const { contact_id, uid } = req;
2989
2853
  const account_profile_info = await get_active_account_profile_info(uid);
2990
2854
  try {
@@ -3028,7 +2892,6 @@ export const get_pending_share_profile_in = async function (uid, _id) {
3028
2892
  };
3029
2893
 
3030
2894
  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
2895
  const app_id = await get_account_default_project_id(uid);
3033
2896
  let doc = contact_profile_doc;
3034
2897
  if (_id) {
@@ -3337,8 +3200,8 @@ export const delete_account_profile = async function (req, job_id, headers) {
3337
3200
  account_profile_doc.stat_reason = 'deleted by the user';
3338
3201
 
3339
3202
  const account_profile_save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
3340
- const ai_module = await import(`${module_path}/ai_module/index.mjs`);
3341
- ai_module.delete_depended_chats(uid, profile_id);
3203
+
3204
+ ai_ms.delete_depended_chats(uid, profile_id);
3342
3205
  return account_profile_save_ret;
3343
3206
  } catch (err) {
3344
3207
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.2038",
3
+ "version": "1.2.2040",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {