@xuda.io/ai_module 1.1.4915 → 1.1.4917

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 +117 -164
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -61,12 +61,15 @@ const { init, check, check_structure, get_zod_schema, get_fields_z_schema } = aw
61
61
 
62
62
  const { get_xuda_couch } = _common;
63
63
 
64
- const account_module = await import(`${module_path}/account_module/index.mjs`);
64
+ // const account_module = await import(`${module_path}/account_module/index.mjs`);
65
65
  const db_module = await import(`${module_path}/db_module/index.mjs`);
66
- const drive_module = await import(`${module_path}/drive_module/index.mjs`);
67
- const jobs_module = await import(`${module_path}/jobs_module/index.mjs`);
66
+ // const drive_module = await import(`${module_path}/drive_module/index.mjs`);
67
+ // const jobs_module = await import(`${module_path}/jobs_module/index.mjs`);
68
68
 
69
69
  const account_ms = await import(`${module_path}/account_module/index_ms.mjs`);
70
+ const drive_ms = await import(`${module_path}/drive_module/index_ms.mjs`);
71
+ const jobs_ms = await import(`${module_path}/jobs_module/index_ms.mjs`);
72
+ const team_ms = await import(`${module_path}/team_module/index_ms.mjs`);
70
73
 
71
74
  var open_ai_status = {};
72
75
  const report_ai_status = function (model, err) {
@@ -1080,7 +1083,7 @@ const check_studio_doc_tool = tool({
1080
1083
  export const get_chat_conversation = async function (req) {
1081
1084
  let { conversation_id, order = 'asc', limit = 9999, skip = 0, _id, uid } = req;
1082
1085
 
1083
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
1086
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
1084
1087
 
1085
1088
  if (_id) {
1086
1089
  let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
@@ -1123,7 +1126,7 @@ export const get_chat_conversation = async function (req) {
1123
1126
  export const get_ai_chats = async function (req, job_id, headers) {
1124
1127
  let { uid, reference_id, _id, search, filter_type = 'all', conversation_type, limit, skip, conversation_id, profile_id } = req;
1125
1128
 
1126
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
1129
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
1127
1130
 
1128
1131
  const get_conversation_background = function (doc) {
1129
1132
  let deg = 145;
@@ -1160,7 +1163,6 @@ export const get_ai_chats = async function (req, job_id, headers) {
1160
1163
 
1161
1164
  try {
1162
1165
  if (_id) {
1163
- // const app_id = await account_module.get_account_default_project_id(uid);
1164
1166
  let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
1165
1167
  return data;
1166
1168
  }
@@ -1276,11 +1278,11 @@ export const get_ai_chats = async function (req, job_id, headers) {
1276
1278
  let doc = { date_created: e.team_req_date, pending: true, uid: e.team_req_from_uid, team_req_id: e._id };
1277
1279
 
1278
1280
  if (e.team_req_from_uid) {
1279
- doc.user_contact = await account_module.get_user_card(uid, e.team_req_from_uid);
1281
+ doc.user_contact = await account_ms.get_user_card(uid, e.team_req_from_uid);
1280
1282
  }
1281
1283
 
1282
1284
  //share_item_id
1283
- const app_id = await account_module.get_account_default_project_id(e.team_req_from_uid);
1285
+ const app_id = await account_ms.get_account_default_project_id(e.team_req_from_uid);
1284
1286
  const chat_ret = await db_module.get_app_couch_doc_native(app_id, e.share_item_id);
1285
1287
  doc.title = chat_ret.title;
1286
1288
  doc.chat_image = chat_ret.chat_image;
@@ -1338,7 +1340,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1338
1340
  // }
1339
1341
  // }
1340
1342
 
1341
- doc.user_contact = await account_module.get_user_card(uid, doc.uid);
1343
+ doc.user_contact = await account_ms.get_user_card(uid, doc.uid);
1342
1344
 
1343
1345
  doc.privilege = doc.uid === uid || doc?.account_profile_info?.uid === uid;
1344
1346
 
@@ -1358,9 +1360,9 @@ export const get_ai_chats = async function (req, job_id, headers) {
1358
1360
  export const delete_ai_chat = async function (req) {
1359
1361
  let { conversation_id, uid } = req;
1360
1362
 
1361
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
1363
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
1362
1364
 
1363
- const app_id = await account_module.get_account_default_project_id(uid);
1365
+ const app_id = await account_ms.get_account_default_project_id(uid);
1364
1366
  let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1365
1367
 
1366
1368
  let save_ret;
@@ -1371,8 +1373,8 @@ export const delete_ai_chat = async function (req) {
1371
1373
 
1372
1374
  if (conversation_doc.shared_from_uid) {
1373
1375
  // delete the share , the doc will delete by the remove_team_member
1374
- const team_module = await import(`${module_path}/team_module/index.mjs`);
1375
- save_ret = await team_module.remove_team_member({ team_req_id: conversation_doc.team_req_id });
1376
+
1377
+ save_ret = await team_ms.remove_team_member({ team_req_id: conversation_doc.team_req_id });
1376
1378
  } else {
1377
1379
  conversation_doc.stat = 4;
1378
1380
  conversation_doc.ts = Date.now();
@@ -1389,7 +1391,7 @@ export const delete_ai_chat = async function (req) {
1389
1391
  }
1390
1392
 
1391
1393
  if (conversation_doc?.chat_image?.[0]) {
1392
- drive_module.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join(conversation_doc.chat_image[0].file_path, conversation_doc.chat_image[0].filename) }] });
1394
+ drive_ms.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join(conversation_doc.chat_image[0].file_path, conversation_doc.chat_image[0].filename) }] });
1393
1395
  }
1394
1396
  }
1395
1397
 
@@ -1401,12 +1403,10 @@ export const delete_ai_chat = async function (req) {
1401
1403
  export const archive_ai_chat = async function (req) {
1402
1404
  let { conversation_id, uid } = req;
1403
1405
 
1404
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
1406
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
1405
1407
 
1406
- const app_id = await account_module.get_account_default_project_id(uid);
1407
1408
  try {
1408
- const team_module = await import(`${module_path}/team_module/index.mjs`);
1409
- await team_module.validate_share_exist(uid, 'chat', conversation_id);
1409
+ await team_ms.validate_share_exist(uid, 'chat', conversation_id);
1410
1410
 
1411
1411
  let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1412
1412
 
@@ -1426,8 +1426,8 @@ export const archive_ai_chat = async function (req) {
1426
1426
 
1427
1427
  export const unarchive_ai_chat = async function (req) {
1428
1428
  let { conversation_id, uid } = req;
1429
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
1430
- const app_id = await account_module.get_account_default_project_id(uid);
1429
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
1430
+
1431
1431
  try {
1432
1432
  let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1433
1433
 
@@ -1512,7 +1512,7 @@ const create_image = async function (uid, prompt, model = 'gpt-image-1-mini', si
1512
1512
 
1513
1513
  const thumbnailBase64 = resized.toString('base64');
1514
1514
 
1515
- account_module.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'create image', prompt, model, metadata, account_profile_info);
1515
+ account_ms.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'create image', prompt, model, metadata, account_profile_info);
1516
1516
 
1517
1517
  return thumbnailBase64;
1518
1518
  } catch (err) {
@@ -1523,9 +1523,9 @@ const create_image = async function (uid, prompt, model = 'gpt-image-1-mini', si
1523
1523
 
1524
1524
  const get_studio_doc = async function (req) {
1525
1525
  let { uid, _id } = req;
1526
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
1526
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
1527
1527
 
1528
- const app_id = await account_module.get_account_default_project_id(uid);
1528
+ const app_id = await account_ms.get_account_default_project_id(uid);
1529
1529
  try {
1530
1530
  let data = await db_module.get_app_couch_doc_native(account_profile_info.app_id, _id);
1531
1531
 
@@ -1802,7 +1802,7 @@ export const get_ai_agent_info = async function (uid, job_id, headers, doc, from
1802
1802
  }
1803
1803
 
1804
1804
  if (doc?.studio_meta?.createdByUid) {
1805
- doc.user_contact = await account_module.get_user_card(uid, doc.studio_meta.createdByUid);
1805
+ doc.user_contact = await account_ms.get_user_card(uid, doc.studio_meta.createdByUid);
1806
1806
  }
1807
1807
  if (!from_marketplace) {
1808
1808
  doc.interactions = 0;
@@ -1820,7 +1820,7 @@ export const get_ai_agent_info = async function (uid, job_id, headers, doc, from
1820
1820
 
1821
1821
  if (!from_marketplace) {
1822
1822
  if (doc?.reference_doc?.studio_meta?.shared_from_uid) {
1823
- const shared_from_uid_ret = await account_module.get_account_name({ uid_query: doc.reference_doc.studio_meta.shared_from_uid });
1823
+ const shared_from_uid_ret = await account_ms.get_account_name({ uid_query: doc.reference_doc.studio_meta.shared_from_uid });
1824
1824
  doc.icon_pattern = shared_from_uid_ret.data.profile_avatar;
1825
1825
  }
1826
1826
  }
@@ -1828,9 +1828,8 @@ export const get_ai_agent_info = async function (uid, job_id, headers, doc, from
1828
1828
  };
1829
1829
 
1830
1830
  const get_user_ai_agents = async function (uid) {
1831
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
1831
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
1832
1832
 
1833
- const app_id = await account_module.get_account_default_project_id(uid);
1834
1833
  let opt = {
1835
1834
  selector: {
1836
1835
  docType: 'studio',
@@ -1843,7 +1842,7 @@ const get_user_ai_agents = async function (uid) {
1843
1842
 
1844
1843
  export const get_ai_agents = async function (req, job_id, headers) {
1845
1844
  let { uid, _id, search, filter_type = 'all', limit, skip, agent_id, profile_id } = req;
1846
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
1845
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
1847
1846
  try {
1848
1847
  if (_id) {
1849
1848
  let doc_ret = await get_studio_doc({ _id, uid });
@@ -1927,8 +1926,6 @@ export const get_ai_agents = async function (req, job_id, headers) {
1927
1926
  }
1928
1927
  //////////////
1929
1928
 
1930
- // const app_id = await account_module.get_account_default_project_id(uid);
1931
-
1932
1929
  let user_agents = { docs: [], total_docs: 0 };
1933
1930
  if (filter_type !== 'pending') {
1934
1931
  user_agents = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
@@ -1955,12 +1952,12 @@ export const get_ai_agents = async function (req, job_id, headers) {
1955
1952
  let doc = { ts: e.team_req_date, pending: true, properties: {}, studio_meta: { createdByUid: e.team_req_from_uid }, team_req_id: e._id };
1956
1953
 
1957
1954
  if (e.team_req_from_uid) {
1958
- doc.user_contact = await account_module.get_user_card(uid, e.team_req_from_uid);
1955
+ doc.user_contact = await account_ms.get_user_card(uid, e.team_req_from_uid);
1959
1956
  doc.icon_pattern = doc.user_contact.profile_avatar;
1960
1957
  }
1961
1958
 
1962
1959
  //share_item_id
1963
- const app_id = await account_module.get_account_default_project_id(e.team_req_from_uid);
1960
+ const app_id = await account_ms.get_account_default_project_id(e.team_req_from_uid);
1964
1961
  const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, e.share_item_id);
1965
1962
  doc.properties.menuName = ai_agent_doc.properties.menuName;
1966
1963
  doc.studio_meta.agent_image = ai_agent_doc.studio_meta.agent_image;
@@ -2010,7 +2007,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
2010
2007
  export const delete_ai_agent = async function (req) {
2011
2008
  let { agent_id, uid, app_id } = req;
2012
2009
 
2013
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2010
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2014
2011
 
2015
2012
  // const project_db = await get_account_project_db(uid);
2016
2013
 
@@ -2024,8 +2021,8 @@ export const delete_ai_agent = async function (req) {
2024
2021
  let save_ret;
2025
2022
  if (prog_doc.studio_meta.shared_from_uid) {
2026
2023
  // delete the share , the doc will delete by the remove_team_member
2027
- const team_module = await import(`${module_path}/team_module/index.mjs`);
2028
- save_ret = await team_module.remove_team_member({ team_req_id: prog_doc.studio_meta.team_req_id });
2024
+
2025
+ save_ret = await team_ms.remove_team_member({ team_req_id: prog_doc.studio_meta.team_req_id });
2029
2026
  } else {
2030
2027
  let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2031
2028
  agent_doc.stat = 4;
@@ -2052,9 +2049,7 @@ export const delete_ai_agent = async function (req) {
2052
2049
  export const uninstall_ai_agent = async function (req) {
2053
2050
  let { agent_id, uid } = req;
2054
2051
 
2055
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2056
-
2057
- const app_id = await account_module.get_account_default_project_id(uid);
2052
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2058
2053
 
2059
2054
  try {
2060
2055
  let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
@@ -2076,9 +2071,7 @@ export const uninstall_ai_agent = async function (req) {
2076
2071
  export const unarchive_ai_agent = async function (req) {
2077
2072
  let { agent_id, uid } = req;
2078
2073
 
2079
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2080
-
2081
- const app_id = await account_module.get_account_default_project_id(uid);
2074
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2082
2075
 
2083
2076
  try {
2084
2077
  let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
@@ -2099,11 +2092,10 @@ export const unarchive_ai_agent = async function (req) {
2099
2092
  };
2100
2093
  export const archive_ai_agent = async function (req) {
2101
2094
  let { agent_id, uid } = req;
2102
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2103
- const app_id = await account_module.get_account_default_project_id(uid);
2095
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2096
+
2104
2097
  try {
2105
- const team_module = await import(`${module_path}/team_module/index.mjs`);
2106
- await team_module.validate_share_exist(uid, 'ai_agent', agent_id);
2098
+ await team_ms.validate_share_exist(uid, 'ai_agent', agent_id);
2107
2099
 
2108
2100
  let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2109
2101
 
@@ -2124,11 +2116,10 @@ export const archive_ai_agent = async function (req) {
2124
2116
  export const archive_mini_app = async function (req) {
2125
2117
  let { prog_id, uid } = req;
2126
2118
 
2127
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2128
- const app_id = await account_module.get_account_default_project_id(uid);
2119
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2120
+
2129
2121
  try {
2130
- const team_module = await import(`${module_path}/team_module/index.mjs`);
2131
- await team_module.validate_share_exist(uid, 'miniapp', prog_id);
2122
+ await team_ms.validate_share_exist(uid, 'miniapp', prog_id);
2132
2123
 
2133
2124
  let prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2134
2125
 
@@ -2149,8 +2140,8 @@ export const archive_mini_app = async function (req) {
2149
2140
  export const unarchive_mini_app = async function (req) {
2150
2141
  let { prog_id, uid } = req;
2151
2142
 
2152
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2153
- const app_id = await account_module.get_account_default_project_id(uid);
2143
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2144
+
2154
2145
  try {
2155
2146
  let prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2156
2147
 
@@ -2171,8 +2162,8 @@ export const unarchive_mini_app = async function (req) {
2171
2162
  export const delete_mini_app = async function (req) {
2172
2163
  let { prog_id, uid } = req;
2173
2164
 
2174
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2175
- const app_id = await account_module.get_account_default_project_id(uid);
2165
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2166
+
2176
2167
  try {
2177
2168
  let prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2178
2169
 
@@ -2183,8 +2174,8 @@ export const delete_mini_app = async function (req) {
2183
2174
  let save_ret;
2184
2175
  if (prog_doc.studio_meta.shared_from_uid) {
2185
2176
  // delete the share , the doc will delete by the remove_team_member
2186
- const team_module = await import(`${module_path}/team_module/index.mjs`);
2187
- save_ret = await team_module.remove_team_member({ team_req_id: prog_doc.studio_meta.team_req_id });
2177
+
2178
+ save_ret = await team_ms.remove_team_member({ team_req_id: prog_doc.studio_meta.team_req_id });
2188
2179
  } else {
2189
2180
  prog_doc.stat = 4;
2190
2181
  prog_doc.ts = Date.now();
@@ -2200,9 +2191,7 @@ export const delete_mini_app = async function (req) {
2200
2191
  export const update_ai_agent = async function (req, job_id, headers) {
2201
2192
  let { agent_id, agentConfig, uid } = req;
2202
2193
 
2203
- // const app_id = await account_module.get_account_default_project_id(uid);
2204
-
2205
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2194
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2206
2195
 
2207
2196
  try {
2208
2197
  let agent_doc = await await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
@@ -2241,33 +2230,9 @@ export const update_ai_agent = async function (req, job_id, headers) {
2241
2230
  }
2242
2231
  };
2243
2232
 
2244
- // export const install_ai_agent = async function (req) {
2245
- // let { agent_id, agent_uid, uid } = req;
2246
-
2247
- // const source_project_db = await get_account_project_db(agent_uid);
2248
- // const target_project_db = await get_account_project_db(uid);
2249
-
2250
- // try {
2251
- // let agent_doc = await source_project_db.get(agent_id);
2252
- // if (agent_doc.agentConfig.agent_visibility === 'private') {
2253
- // throw new Error('agent is private');
2254
- // }
2255
- // const t = Date.now();
2256
- // agent_doc.ts = t;
2257
- // agent_doc.studio_meta.installed_ts = t;
2258
- // agent_doc.studio_meta.installed_from_app_id = await account_module.get_account_default_project_id(agent_uid);
2259
-
2260
- // const data = await target_project_db.insert(agent_doc);
2261
-
2262
- // return { code: 10, data };
2263
- // } catch (err) {
2264
- // return { code: -10, data: err.message };
2265
- // }
2266
- // };
2267
-
2268
2233
  export const get_apps = async function (req, job_id, headers) {
2269
2234
  let { uid, _id, search, filter_type = 'all', limit, skip, mini_app_id, profile_id } = req;
2270
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
2235
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
2271
2236
  try {
2272
2237
  if (_id) return await get_studio_doc({ _id, uid });
2273
2238
  ///////////////
@@ -2335,8 +2300,6 @@ export const get_apps = async function (req, job_id, headers) {
2335
2300
  }
2336
2301
  //////////////
2337
2302
 
2338
- // const app_id = await account_module.get_account_default_project_id(uid);
2339
-
2340
2303
  let user_apps = { docs: [], total_docs: 0 };
2341
2304
  if (filter_type !== 'pending') {
2342
2305
  user_apps = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
@@ -2367,11 +2330,11 @@ export const get_apps = async function (req, job_id, headers) {
2367
2330
  let doc = { ts: e.team_req_date, pending: true, properties: {}, studio_meta: { createdByUid: e.team_req_from_uid }, team_req_id: e._id };
2368
2331
 
2369
2332
  if (e.team_req_from_uid) {
2370
- doc.user_contact = await account_module.get_user_card(uid, e.team_req_from_uid);
2333
+ doc.user_contact = await account_ms.get_user_card(uid, e.team_req_from_uid);
2371
2334
  }
2372
2335
 
2373
2336
  //share_item_id
2374
- const app_id = await account_module.get_account_default_project_id(e.team_req_from_uid);
2337
+ const app_id = await account_ms.get_account_default_project_id(e.team_req_from_uid);
2375
2338
  const miniapp_ret = await db_module.get_app_couch_doc_native(app_id, e.share_item_id);
2376
2339
  doc.properties.menuName = miniapp_ret.properties.menuName;
2377
2340
  doc.studio_meta.agent_image = miniapp_ret.studio_meta.agent_image;
@@ -2392,7 +2355,7 @@ export const get_apps = async function (req, job_id, headers) {
2392
2355
  doc.reference_doc = reference_doc;
2393
2356
  }
2394
2357
 
2395
- doc.user_contact = await account_module.get_user_card(uid, doc.studio_meta.createdByUid);
2358
+ doc.user_contact = await account_ms.get_user_card(uid, doc.studio_meta.createdByUid);
2396
2359
 
2397
2360
  doc.privilege = doc.studio_meta.createdByUid === uid || doc?.studio_meta?.account_profile_info?.uid === uid;
2398
2361
 
@@ -2411,14 +2374,14 @@ export const get_apps = async function (req, job_id, headers) {
2411
2374
  // };
2412
2375
 
2413
2376
  const upload_agent_files = async function (uid, agent_doc) {
2414
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2377
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2415
2378
 
2416
2379
  let { agentConfig } = agent_doc;
2417
2380
  for await (let tool of agentConfig.agent_tools || []) {
2418
2381
  if (tool.type === 'file_search') {
2419
2382
  if (!_.isEmpty(tool.file)) {
2420
2383
  if (!tool.file.file_id) {
2421
- const validation_ret = drive_module.file_upload_validator(tool.file.name);
2384
+ const validation_ret = drive_ms.file_upload_validator(tool.file.name);
2422
2385
  if (!validation_ret.valid) {
2423
2386
  throw new Error(validation_ret.error);
2424
2387
  }
@@ -2595,7 +2558,7 @@ const upload_agent_files = async function (uid, agent_doc) {
2595
2558
 
2596
2559
  const save_agent_status = async function (uid, agent_id, stat, agentConfig) {
2597
2560
  // const project_db = await get_account_project_db(uid);
2598
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2561
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2599
2562
 
2600
2563
  try {
2601
2564
  let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
@@ -2613,9 +2576,9 @@ const save_agent_status = async function (uid, agent_id, stat, agentConfig) {
2613
2576
  export const create_ai_agent = async function (req, job_id, headers) {
2614
2577
  const { agentConfig, uid } = req;
2615
2578
 
2616
- const { account_project_id: app_id, account_info } = await account_module.get_default_project_account_doc(uid);
2579
+ const { account_project_id: app_id, account_info } = await account_ms.get_default_project_account_doc(uid);
2617
2580
 
2618
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2581
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2619
2582
  const { account_profile_obj } = account_profile_info;
2620
2583
  try {
2621
2584
  const param = { uid, properties: { menuName: agentConfig.agent_name, menuTitle: agentConfig.agent_name, menuType: 'ai_agent' }, checkedInUserName: account_info.first_name + ' ' + account_info.last_name, app_id: account_profile_info.app_id, parentId: 'ai_agents' };
@@ -2649,7 +2612,7 @@ export const update_ai_agent_properties = async function (doc, app_id, uid, fiel
2649
2612
  debugger;
2650
2613
  const db_doc = await db_module.get_app_couch_doc_native(app_id, doc._id);
2651
2614
  // const { account_profile_info } = doc.studio_meta;
2652
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
2615
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
2653
2616
 
2654
2617
  const get_agent_assistant_name = async function () {
2655
2618
  const ret = await submit_chat_gpt_prompt({
@@ -2896,7 +2859,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
2896
2859
  images_arr = [cache];
2897
2860
  if (!cache) {
2898
2861
  images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
2899
- account_module.save_xuda_cache(uid, 'chat_thumbnail', doc.title, images_arr[0], { tags });
2862
+ account_ms.save_xuda_cache(uid, 'chat_thumbnail', doc.title, images_arr[0], { tags });
2900
2863
  }
2901
2864
  db_doc = await get_db_doc();
2902
2865
  db_doc.thumbnail_request_ts = Date.now();
@@ -2915,7 +2878,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
2915
2878
  images_arr = [cache];
2916
2879
  if (!cache) {
2917
2880
  images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
2918
- account_module.save_xuda_cache(uid, 'chat_thumbnail', doc.category_info.category, images_arr[0], { tags });
2881
+ account_ms.save_xuda_cache(uid, 'chat_thumbnail', doc.category_info.category, images_arr[0], { tags });
2919
2882
  }
2920
2883
  db_doc = await get_db_doc();
2921
2884
  db_doc.thumbnail_request_ts = Date.now();
@@ -2987,7 +2950,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
2987
2950
  };
2988
2951
 
2989
2952
  const get_drive_file_response = async function (drive_type, app_id, uid, file_path) {
2990
- const check_existing_file_ret = await drive_module.check_drive_file({ drive_type, app_id, uid, file_path });
2953
+ const check_existing_file_ret = await drive_ms.check_drive_file({ drive_type, app_id, uid, file_path });
2991
2954
 
2992
2955
  if (!check_existing_file_ret?.duplicates) {
2993
2956
  throw new Error(`${file_path} document not found`);
@@ -3053,7 +3016,7 @@ const transcribe = async function (uid, stream, metadata, account_profile_info)
3053
3016
  // temperature: 0 // lower = more literal
3054
3017
  });
3055
3018
  report_ai_status(model);
3056
- account_module.record_ai_usage(uid, 0, resp.length || 0, 'transcribe', '', model, metadata, account_profile_info);
3019
+ account_ms.record_ai_usage(uid, 0, resp.length || 0, 'transcribe', '', model, metadata, account_profile_info);
3057
3020
  // console.log(resp); // or resp for JSON formats
3058
3021
  return resp;
3059
3022
  } catch (err) {
@@ -3062,13 +3025,6 @@ const transcribe = async function (uid, stream, metadata, account_profile_info)
3062
3025
  }
3063
3026
  };
3064
3027
 
3065
- // const get_account_project_db = async function (uid) {
3066
- // const user_project_id = await account_module.get_account_default_project_id(uid);
3067
-
3068
- // const project_db = await get_project_db(user_project_id);
3069
- // return project_db;
3070
- // };
3071
-
3072
3028
  const get_app_obj = async function (app_id) {
3073
3029
  const db = get_xuda_couch('xuda_master');
3074
3030
  const app_obj = await db.get(app_id);
@@ -3328,13 +3284,13 @@ export const upload_prompt_attachment = async function (req, job_id, headers, fi
3328
3284
 
3329
3285
  const file_name = file_obj?.['originalname'];
3330
3286
 
3331
- const validation_ret = drive_module.file_upload_validator(file_name);
3287
+ const validation_ret = drive_ms.file_upload_validator(file_name);
3332
3288
 
3333
3289
  if (!validation_ret.valid) {
3334
3290
  throw new Error(validation_ret.error);
3335
3291
  }
3336
3292
 
3337
- const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Chat Attachments' }, job_id, headers, file_obj);
3293
+ const drive_ret = await drive_ms.upload_drive_file_user({ uid, path: '/Chat Attachments' }, job_id, headers, file_obj);
3338
3294
 
3339
3295
  return drive_ret;
3340
3296
  } catch (err) {
@@ -3380,7 +3336,7 @@ export const submit_chat_gpt_prompt = async function (req) {
3380
3336
  report_ai_status(model, err);
3381
3337
  throw err;
3382
3338
  }
3383
- account_module.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'submit chat', prompt, model, metadata, account_profile_info, tools);
3339
+ account_ms.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'submit chat', prompt, model, metadata, account_profile_info, tools);
3384
3340
  return { code: 5, data: response.output_text };
3385
3341
  } catch (err) {
3386
3342
  return { code: -5, data: err.message };
@@ -3397,7 +3353,7 @@ export const create_conversation = async function (req, job_id, headers) {
3397
3353
  const { profile_id, uid, prompt, perform_ai_execution = true, email_id, email_direction = 'out', from_mailbox, date_created } = req;
3398
3354
  let { reference_type, reference_id = '', conversation_type, email_recipient_type } = req;
3399
3355
 
3400
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
3356
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
3401
3357
  const { account_profile_obj } = account_profile_info;
3402
3358
  try {
3403
3359
  if (conversation_type === 'email') {
@@ -3407,7 +3363,7 @@ export const create_conversation = async function (req, job_id, headers) {
3407
3363
  }
3408
3364
  }
3409
3365
 
3410
- let { data: ai_credits } = await account_module.get_account_ai_usage(account_profile_info.uid);
3366
+ let { data: ai_credits } = await account_ms.get_account_ai_usage(account_profile_info.uid);
3411
3367
 
3412
3368
  if (ai_credits.credits.total - ai_credits.usage.total < -0.5) {
3413
3369
  throw new Error('ai credits reach to hard limit');
@@ -3454,7 +3410,7 @@ export const create_conversation = async function (req, job_id, headers) {
3454
3410
  if (conversation_doc.reference_type === 'contacts' && conversation_type === 'chat') {
3455
3411
  // reference_id is the contact id
3456
3412
  contact_id = reference_id;
3457
- contact_doc = await account_module.get_contact_info(uid, null, contact_id);
3413
+ contact_doc = await account_ms.get_contact_info(uid, null, contact_id);
3458
3414
 
3459
3415
  if (!contact_doc?.contact_uid) {
3460
3416
  throw new Error('chat conversation to non user recipient is not allowed');
@@ -3467,7 +3423,7 @@ export const create_conversation = async function (req, job_id, headers) {
3467
3423
  recipient_contact_id = contact_doc.connection_contact_id;
3468
3424
  recipient_uid = contact_doc.connection_uid;
3469
3425
 
3470
- const app_id = await account_module.get_account_default_project_id(recipient_uid);
3426
+ const app_id = await account_ms.get_account_default_project_id(recipient_uid);
3471
3427
  const save_ret = await db_module.save_app_couch_doc(app_id, { ...conversation_doc, ...{ uid: recipient_uid, reference_id: recipient_contact_id } });
3472
3428
  }
3473
3429
 
@@ -3484,7 +3440,7 @@ export const create_conversation = async function (req, job_id, headers) {
3484
3440
 
3485
3441
  const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3486
3442
 
3487
- const recipient_account_profile_info = await account_module.get_active_account_profile_info(recipient_uid);
3443
+ const recipient_account_profile_info = await account_ms.get_active_account_profile_info(recipient_uid);
3488
3444
  let recipient_conversation_doc = await db_module.get_app_couch_doc_native(recipient_account_profile_info.app_id, conversation_doc._id);
3489
3445
  recipient_conversation_doc.title = conversation_doc.title;
3490
3446
 
@@ -3609,7 +3565,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
3609
3565
  let { conversation_id } = req;
3610
3566
  try {
3611
3567
  if (!conversation_id) throw new Error('missing conversation_id');
3612
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
3568
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
3613
3569
 
3614
3570
  let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3615
3571
  req.conversation_doc = conversation_doc;
@@ -3617,7 +3573,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
3617
3573
  if (conversation_doc.reference_type === 'contacts') {
3618
3574
  req._thread_reentry = Date.now() - conversation_doc.date_created_ts > 60000;
3619
3575
 
3620
- account_module.ts_contact(uid, conversation_doc.reference_id);
3576
+ account_ms.ts_contact(uid, conversation_doc.reference_id);
3621
3577
 
3622
3578
  switch (conversation_doc.conversation_type) {
3623
3579
  case 'note': {
@@ -3675,17 +3631,17 @@ const update_conversation_mood_level = async function (uid, target_contacts = []
3675
3631
  const mood_level_obj = JSON5.parse(mood_level.data);
3676
3632
 
3677
3633
  for await (const target of target_contacts) {
3678
- const account_profile_info = await account_module.get_active_account_profile_info(target.uid);
3634
+ const account_profile_info = await account_ms.get_active_account_profile_info(target.uid);
3679
3635
  let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3680
3636
  conversation_doc.mood_level = mood_level_obj.mood_level;
3681
3637
  await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3682
3638
 
3683
3639
  if (update_contact) {
3684
- const account_profile_info = await account_module.get_active_account_profile_info(target.uid);
3685
- let contact_doc = await account_module.get_contact(account_profile_info.uid, target.contact_id);
3640
+ const account_profile_info = await account_ms.get_active_account_profile_info(target.uid);
3641
+ let contact_doc = await account_ms.get_contact(account_profile_info.uid, target.contact_id);
3686
3642
  contact_doc.contact_mood_level = mood_level_obj.mood_level;
3687
3643
  contact_doc.ts = Date.now();
3688
- await account_module.save_contact(target.uid, contact_doc);
3644
+ await account_ms.save_contact(target.uid, contact_doc);
3689
3645
  }
3690
3646
  }
3691
3647
  } catch (err) {
@@ -3695,16 +3651,16 @@ const update_conversation_mood_level = async function (uid, target_contacts = []
3695
3651
 
3696
3652
  const contact_chat_conversation = async function (req, job_id, headers) {
3697
3653
  const { uid, profile_id } = req;
3698
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
3654
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
3699
3655
  let { prompt, conversation_doc, attachments = [], ai_agents } = req;
3700
3656
 
3701
3657
  const conversation_id = conversation_doc._id;
3702
3658
 
3703
- const receiver_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
3704
- const receiver_app_id = await account_module.get_account_default_project_id(receiver_contact_doc.contact_uid);
3659
+ const receiver_contact_doc = await account_ms.get_contact_info(uid, null, conversation_doc.reference_id);
3660
+ const receiver_app_id = await account_ms.get_account_default_project_id(receiver_contact_doc.contact_uid);
3705
3661
  let receiver_conversation_doc = await db_module.get_app_couch_doc_native(receiver_app_id, conversation_id);
3706
3662
 
3707
- const sender_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
3663
+ const sender_contact_doc = await account_ms.get_contact_info(uid, null, conversation_doc.reference_id);
3708
3664
  const sender_app_id = account_profile_info.app_id;
3709
3665
  let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
3710
3666
 
@@ -3759,12 +3715,12 @@ const contact_chat_conversation = async function (req, job_id, headers) {
3759
3715
 
3760
3716
  const chat_note = async function (req, job_id, headers) {
3761
3717
  const { uid, profile_id } = req;
3762
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
3718
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
3763
3719
  let { prompt: body, conversation_doc, attachments = [], ai_agents } = req;
3764
3720
  try {
3765
3721
  const conversation_id = conversation_doc._id;
3766
3722
 
3767
- const sender_app_id = account_profile_info.app_id; //await account_module.get_account_default_project_id(uid);
3723
+ const sender_app_id = account_profile_info.app_id; //await account_ms.get_account_default_project_id(uid);
3768
3724
  let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
3769
3725
 
3770
3726
  await attachment_handler(uid, sender_app_id, conversation_id, attachments, account_profile_info);
@@ -3821,7 +3777,7 @@ const chat_note = async function (req, job_id, headers) {
3821
3777
 
3822
3778
  const chat_email = async function (req, job_id, headers) {
3823
3779
  const { profile_id, uid, email_id, perform_ai_execution = true, from_mailbox, _thread_reentry, email_direction } = req;
3824
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
3780
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
3825
3781
  let { prompt: body, conversation_doc, attachments = [], ai_agents } = req;
3826
3782
  try {
3827
3783
  if (!account_profile_info.account_profile_obj?.email_account_id) {
@@ -3839,7 +3795,7 @@ const chat_email = async function (req, job_id, headers) {
3839
3795
  throw new Error('not an contact conversation');
3840
3796
  }
3841
3797
  const contact_id = sender_conversation_doc.reference_id;
3842
- const contact_info = await account_module.get_contact_info(uid, null, contact_id);
3798
+ const contact_info = await account_ms.get_contact_info(uid, null, contact_id);
3843
3799
  if (!contact_info.email) {
3844
3800
  throw new Error('empty contact email');
3845
3801
  }
@@ -3964,7 +3920,7 @@ const chat_email = async function (req, job_id, headers) {
3964
3920
 
3965
3921
  const ai_chat_conversation = async function (req, job_id, headers) {
3966
3922
  const { uid, gtp_token, profile_id } = req;
3967
- const account_profile_info = await account_module.get_active_account_profile_info(uid, profile_id);
3923
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid, profile_id);
3968
3924
  let { prompt, conversation_doc, attachments = [], ai_agents, output_format = 'md', stream = true, with_context = true } = req;
3969
3925
  await _utils.delay(1000);
3970
3926
  const conversation_id = conversation_doc._id;
@@ -4032,10 +3988,10 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4032
3988
  };
4033
3989
 
4034
3990
  try {
4035
- const app_id = await account_module.get_account_default_project_id(uid);
3991
+ const app_id = await account_ms.get_account_default_project_id(uid);
4036
3992
  const app_obj = await get_app_obj(account_profile_info.app_id);
4037
- const userName = await account_module.get_user_name(uid);
4038
- const account_info = (await account_module.get_account_name({ uid })).data;
3993
+ const userName = await account_ms.get_user_name(uid);
3994
+ const account_info = (await account_ms.get_account_name({ uid })).data;
4039
3995
  let context = { ...{ app_id: account_profile_info.app_id, uid, userName, account_info, app_obj, account_id: uid }, ...extractClientInfo(headers) };
4040
3996
  const d = new Intl.DateTimeFormat('en-US').format(new Date());
4041
3997
  if (!visitors[d]) {
@@ -4054,7 +4010,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4054
4010
  // emitToDashboard_interval = setInterval(() => {
4055
4011
  // emitToDashboard('stream_delta', '.');
4056
4012
  // }, 500);
4057
- await jobs_module.update_job(
4013
+ await jobs_ms.update_job(
4058
4014
  {
4059
4015
  job_id,
4060
4016
  current_step_name: current_step_name,
@@ -4073,9 +4029,6 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4073
4029
  // let conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
4074
4030
  const reference_type = conversation_doc.reference_type;
4075
4031
  const reference_id = conversation_doc.reference_id;
4076
- // if (reference_type === 'contact') {
4077
- // account_module.ts_contact(reference_id);
4078
- // }
4079
4032
 
4080
4033
  conversation_doc.stat = 2;
4081
4034
  conversation_doc.ts = Date.now();
@@ -4195,12 +4148,12 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4195
4148
  ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
4196
4149
  if (ai_agent_doc.studio_meta.shared_from_uid) {
4197
4150
  const reference_doc = _.cloneDeep(ai_agent_doc);
4198
- const app_id = await account_module.get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
4151
+ const app_id = await account_ms.get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
4199
4152
  ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4200
4153
  ai_agent_doc.reference_doc = reference_doc;
4201
4154
  } else if (ai_agent_doc.studio_meta.installed_from_uid) {
4202
4155
  const reference_doc = _.cloneDeep(ai_agent_doc);
4203
- const app_id = await account_module.get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_uid);
4156
+ const app_id = await account_ms.get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_uid);
4204
4157
  ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4205
4158
  ai_agent_doc.reference_doc = reference_doc;
4206
4159
  }
@@ -4650,7 +4603,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4650
4603
  out_conversation_item_doc.conversation_item_reference_id = conversation_items?.data?.[0]?.id;
4651
4604
  await db_module.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_doc);
4652
4605
 
4653
- account_module.record_ai_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: in_conversation_item_obj.ai_agent_id, item_id: in_conversation_item_obj._id }, account_profile_info);
4606
+ account_ms.record_ai_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: in_conversation_item_obj.ai_agent_id, item_id: in_conversation_item_obj._id }, account_profile_info);
4654
4607
  // if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
4655
4608
  // update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
4656
4609
  // }
@@ -4716,7 +4669,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4716
4669
  setTimeout(async () => {
4717
4670
  const app_id = 'prj712ffdf5aa8adce6cedef988f9c12392'; //'prj3937cb6f9a31c8c7dea25055bba845b1'; //
4718
4671
  const uid = 'd39126e0e2c51ffbd1aad10709fc8335';
4719
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
4672
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
4720
4673
 
4721
4674
  // await init_studio_units();
4722
4675
  let ret;
@@ -4747,8 +4700,8 @@ setTimeout(async () => {
4747
4700
 
4748
4701
  // ret = await conversation_actions({ action: 'save_to_drive', conversation_id: 'conv_6935865eb6388193bc266aa33e5ad1e10932c1744e314a2f', item_id: 'msg_0932c1744e314a2f00693586a7cae48193a52be621d41a8755' });
4749
4702
 
4750
- // ret = await drive_module.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join('/Chat Thumbnails', 'conv_69368cb025208194bce284cf2185d7b80321fd7a19a74e74.png') }] });
4751
- // ret = await drive_module.delete_file_from_bucket({
4703
+ // ret = await drive_ms.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join('/Chat Thumbnails', 'conv_69368cb025208194bce284cf2185d7b80321fd7a19a74e74.png') }] });
4704
+ // ret = await drive_ms.delete_file_from_bucket({
4752
4705
  // 'dev.xuda.io': {
4753
4706
  // ETag: '"0e89207990ce19d8b3e61dfea6e61919"',
4754
4707
  // $metadata: {
@@ -5106,7 +5059,7 @@ const create_and_upload_image_to_drive = async function (drive_type, file_path,
5106
5059
  // C. Upload to Drive Module
5107
5060
  // FIX 2: Sending file_obj directly (not wrapped in object)
5108
5061
 
5109
- const drive_ret = await drive_module[`upload_drive_file_${drive_type}`]({ uid, tags, app_id, path: path.join('/', file_path), is_system }, job_id, headers, file_obj);
5062
+ const drive_ret = await drive_ms[`upload_drive_file_${drive_type}`]({ uid, tags, app_id, path: path.join('/', file_path), is_system }, job_id, headers, file_obj);
5110
5063
 
5111
5064
  // FIX 1: Check return code
5112
5065
  if (drive_ret.code < 0) {
@@ -5150,7 +5103,7 @@ export const create_avatar = async function (req, job_id, headers) {
5150
5103
  throw new Error('invalid url');
5151
5104
  }
5152
5105
 
5153
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
5106
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
5154
5107
 
5155
5108
  const account_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
5156
5109
  const account_info = account_obj.account_info;
@@ -5223,7 +5176,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
5223
5176
  throw err;
5224
5177
  }
5225
5178
  imageBase64 = ai_avatar_response.data[0].b64_json;
5226
- account_module.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5179
+ account_ms.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5227
5180
  } else {
5228
5181
  imageBase64 = Buffer.from(await image_blob_ret.image_blob.arrayBuffer()).toString('base64');
5229
5182
  if (account_type === 'business') {
@@ -5315,7 +5268,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
5315
5268
  // The background should be fully removed, remove trees,clouds,sky or any landscape objects`,
5316
5269
  // background: 'transparent',
5317
5270
  // });
5318
- // account_module.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5271
+ // account_ms.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5319
5272
  // imageBase64 = ai_avatar_response.data[0].b64_json;
5320
5273
  if (is_user) {
5321
5274
  if (business_has_person) {
@@ -5342,7 +5295,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
5342
5295
  report_ai_status(model, err);
5343
5296
  throw err;
5344
5297
  }
5345
- account_module.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5298
+ account_ms.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5346
5299
  imageBase64 = ai_avatar_response.data[0].b64_json;
5347
5300
  }
5348
5301
  } else {
@@ -5414,7 +5367,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
5414
5367
  report_ai_status(model, err);
5415
5368
  throw err;
5416
5369
  }
5417
- account_module.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5370
+ account_ms.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
5418
5371
  imageBase64 = ai_avatar_response.data[0].b64_json;
5419
5372
  avatar_source = 'ai profile';
5420
5373
  };
@@ -5463,7 +5416,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
5463
5416
  mimetype: `image/${ext}`,
5464
5417
  };
5465
5418
 
5466
- let drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
5419
+ let drive_ret = await drive_ms.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
5467
5420
  drive_ret.data.avatar_source = avatar_source;
5468
5421
 
5469
5422
  return drive_ret;
@@ -5637,7 +5590,7 @@ export const get_profile_picture = async function (uid, account_type = 'business
5637
5590
  }
5638
5591
 
5639
5592
  imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json, resize);
5640
- account_module.record_ai_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'profile image', prompt, model, { url }, account_profile_info);
5593
+ account_ms.record_ai_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'profile image', prompt, model, { url }, account_profile_info);
5641
5594
  }
5642
5595
 
5643
5596
  const outputBuffer = Buffer.from(imageBase64, 'base64');
@@ -5654,7 +5607,7 @@ export const get_profile_picture = async function (uid, account_type = 'business
5654
5607
  mimetype: `image/png`,
5655
5608
  };
5656
5609
 
5657
- drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
5610
+ drive_ret = await drive_ms.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
5658
5611
  drive_ret.profile_picture_source = profile_picture_source;
5659
5612
  }
5660
5613
  return drive_ret;
@@ -5716,7 +5669,7 @@ export const conversation_actions = async function (req, job_id, headers) {
5716
5669
  mimetype: `application/pdf`,
5717
5670
  };
5718
5671
 
5719
- const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/' }, job_id, headers, file_obj);
5672
+ const drive_ret = await drive_ms.upload_drive_file_user({ uid, path: '/' }, job_id, headers, file_obj);
5720
5673
 
5721
5674
  return {
5722
5675
  code: 20,
@@ -5747,7 +5700,7 @@ export const modify_profile_avatar = async function (req, job_id, headers) {
5747
5700
  // the function modify human avatar
5748
5701
  const { methods = [], docType, uid, url, _id, name, account_type } = req;
5749
5702
  let { metadata } = req;
5750
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
5703
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
5751
5704
 
5752
5705
  try {
5753
5706
  let prompt = '';
@@ -5862,7 +5815,7 @@ const create_ai_agent_image = async function (req, job_id, headers) {
5862
5815
  const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`);
5863
5816
 
5864
5817
  const { app_id, uid, ai_agent_id, tags } = req;
5865
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
5818
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
5866
5819
  const ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_id);
5867
5820
  const account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
5868
5821
 
@@ -5953,7 +5906,7 @@ const create_ai_agent_image = async function (req, job_id, headers) {
5953
5906
  throw err;
5954
5907
  }
5955
5908
  imageBase64 = ai_avatar_response.data[0].b64_json;
5956
- account_module.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'agent avatar', prompt, model, { ai_agent_id }, account_profile_info);
5909
+ account_ms.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'agent avatar', prompt, model, { ai_agent_id }, account_profile_info);
5957
5910
  console.log('Normalizing final avatar to 1024 with transparent padding...');
5958
5911
  imageBase64 = await normalizeBase64To1024(imageBase64);
5959
5912
 
@@ -5977,7 +5930,7 @@ const create_ai_agent_image = async function (req, job_id, headers) {
5977
5930
  mimetype: `image/${ext}`,
5978
5931
  };
5979
5932
 
5980
- const drive_ret = await drive_module.upload_drive_file_studio({ uid, app_id, path: '/Progs Thumbnails' }, job_id, headers, file_obj);
5933
+ const drive_ret = await drive_ms.upload_drive_file_studio({ uid, app_id, path: '/Progs Thumbnails' }, job_id, headers, file_obj);
5981
5934
 
5982
5935
  if (drive_ret.code > 0) {
5983
5936
  return drive_ret;
@@ -5995,8 +5948,8 @@ const create_ai_agent_image = async function (req, job_id, headers) {
5995
5948
  export const create_mini_app = async function (req, job_id, headers) {
5996
5949
  const { uid, prompt } = req;
5997
5950
  try {
5998
- const { account_project_id: app_id, account_info } = await account_module.get_default_project_account_doc(uid);
5999
- const account_profile_info = await account_module.get_active_account_profile_info(uid);
5951
+ const { account_project_id: app_id, account_info } = await account_ms.get_default_project_account_doc(uid);
5952
+ const account_profile_info = await account_ms.get_active_account_profile_info(uid);
6000
5953
  const { account_profile_obj } = account_profile_info;
6001
5954
 
6002
5955
  const param = { uid, properties: { menuName: prompt, menuTitle: prompt, menuType: 'component' }, checkedInUserName: account_info.first_name + ' ' + account_info.last_name, app_id, parentId: 'programs' };
@@ -6021,7 +5974,7 @@ export const create_mini_app = async function (req, job_id, headers) {
6021
5974
  export const pin_ai_agent = async function (req, job_id, headers) {
6022
5975
  const { uid, agent_id } = req;
6023
5976
  try {
6024
- const app_id = await account_module.get_account_default_project_id(uid);
5977
+ const app_id = await account_ms.get_account_default_project_id(uid);
6025
5978
  const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, agent_id);
6026
5979
 
6027
5980
  ai_agent_doc.studio_meta.pinned = true;
@@ -6053,7 +6006,7 @@ export const pin_ai_agent = async function (req, job_id, headers) {
6053
6006
  export const unpin_ai_agent = async function (req, job_id, headers) {
6054
6007
  const { uid, agent_id } = req;
6055
6008
  try {
6056
- const app_id = await account_module.get_account_default_project_id(uid);
6009
+ const app_id = await account_ms.get_account_default_project_id(uid);
6057
6010
  const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, agent_id);
6058
6011
 
6059
6012
  ai_agent_doc.studio_meta.pinned = false;
@@ -6092,7 +6045,7 @@ export const get_transcript = async function (uid, app_id, conversation_id, acco
6092
6045
  return Buffer.concat(chunks);
6093
6046
  }
6094
6047
 
6095
- const validation_ret = drive_module.file_upload_validator(filename);
6048
+ const validation_ret = drive_ms.file_upload_validator(filename);
6096
6049
  if (!validation_ret.valid) {
6097
6050
  throw new Error(validation_ret.error);
6098
6051
  }
@@ -6220,7 +6173,7 @@ const attachment_handler = async function (uid, app_id, conversation_id, attachm
6220
6173
  // return Buffer.concat(chunks);
6221
6174
  // }
6222
6175
 
6223
- // const validation_ret = drive_module.file_upload_validator(filename);
6176
+ // const validation_ret = drive_ms.file_upload_validator(filename);
6224
6177
  // if (!validation_ret.valid) {
6225
6178
  // throw new Error(validation_ret.error);
6226
6179
  // }
@@ -6324,7 +6277,7 @@ const attachment_handler = async function (uid, app_id, conversation_id, attachm
6324
6277
  let transcript;
6325
6278
  try {
6326
6279
  if (conversation_doc.reference_type === 'contacts' && conversation_doc.conversation_type === 'email') {
6327
- let contact_doc = await account_module.get_contact(uid, conversation_doc.reference_id);
6280
+ let contact_doc = await account_ms.get_contact(uid, conversation_doc.reference_id);
6328
6281
  if (!contact_doc.deep_research) throw new Error('deep research not set');
6329
6282
  }
6330
6283
 
@@ -6641,7 +6594,7 @@ const get_chat_picture_cache = async function (uid, docType, key) {
6641
6594
  const ret = await db_module.find_couch_query('xuda_cache', query);
6642
6595
 
6643
6596
  if (ret.docs.length > 0) {
6644
- account_module.save_cache_hit(ret.docs[0]._id);
6597
+ account_ms.save_cache_hit(ret.docs[0]._id);
6645
6598
  return ret.docs[0].file;
6646
6599
  }
6647
6600
  }
@@ -6666,7 +6619,7 @@ const save_drive_file_to_disk = async function (drive_file) {
6666
6619
  const tempDir = os.tmpdir();
6667
6620
 
6668
6621
  const tempOutputPath = path.join(tempDir, drive_file.filename + '_' + Date.now());
6669
- const validation_ret = drive_module.file_upload_validator(drive_file.filename);
6622
+ const validation_ret = drive_ms.file_upload_validator(drive_file.filename);
6670
6623
 
6671
6624
  // 5. Write the downloaded image to disk
6672
6625
  fs.writeFileSync(tempOutputPath, imageBuffer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4915",
3
+ "version": "1.1.4917",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",