@xuda.io/ai_module 1.1.4976 → 1.1.4977

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 +126 -126
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -148,7 +148,7 @@ const get_studio_table_info_tool = tool({
148
148
  try {
149
149
  const project_db = await get_project_db(app_id);
150
150
  // let tables = await project_db.view('xuda', 'studio_docs_by_type', { key: 'table' });
151
- let tables = await db_ms.get_app_couch_view(app_id, 'studio_docs_by_type', { key: 'table' });
151
+ let tables = await db_module.get_app_couch_view(app_id, 'studio_docs_by_type', { key: 'table' });
152
152
  let response = '';
153
153
 
154
154
  for (const doc of tables.rows) {
@@ -1084,19 +1084,19 @@ export const get_chat_conversation = async function (req) {
1084
1084
  const account_profile_info = await get_active_account_profile_info(uid);
1085
1085
 
1086
1086
  if (_id) {
1087
- let data = await db_ms.get_app_couch_doc(account_profile_info.app_id, _id);
1087
+ let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
1088
1088
  return data;
1089
1089
  }
1090
1090
 
1091
1091
  try {
1092
- let conversation_doc = await db_ms.get_app_couch_doc(account_profile_info.app_id, conversation_id);
1092
+ let conversation_doc = await db_module.get_app_couch_doc(account_profile_info.app_id, conversation_id);
1093
1093
  let reference_doc;
1094
1094
  if (conversation_doc.shared_from_uid) {
1095
1095
  reference_doc = _.cloneDeep(conversation_doc);
1096
- conversation_doc = await db_ms.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
1096
+ conversation_doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
1097
1097
  conversation_doc.reference_doc = reference_doc;
1098
1098
  }
1099
- let conversation_items = await db_ms.find_app_couch_query(account_profile_info.app_id, {
1099
+ let conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
1100
1100
  selector: {
1101
1101
  docType: 'chat_conversation_item',
1102
1102
  conversation_id,
@@ -1112,7 +1112,7 @@ export const get_chat_conversation = async function (req) {
1112
1112
  conversation_item_doc.read = {};
1113
1113
  }
1114
1114
  conversation_item_doc.read[uid] = Date.now();
1115
- await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_item_doc);
1115
+ await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_item_doc);
1116
1116
  }
1117
1117
 
1118
1118
  return { code: 15, data: { conversation: conversation_items, ...conversation_doc } };
@@ -1161,7 +1161,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1161
1161
 
1162
1162
  try {
1163
1163
  if (_id) {
1164
- let data = await db_ms.get_app_couch_doc(account_profile_info.app_id, _id);
1164
+ let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
1165
1165
  return data;
1166
1166
  }
1167
1167
 
@@ -1239,7 +1239,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1239
1239
  }
1240
1240
 
1241
1241
  const chat_conversation_count = async function (contact_id, conversation_id) {
1242
- const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1242
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1243
1243
  reduce: true,
1244
1244
  group_level: 1,
1245
1245
 
@@ -1252,7 +1252,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1252
1252
  return counts_ret?.rows?.[0]?.value || 0;
1253
1253
  };
1254
1254
  const chat_conversation_read = async function (contact_id, conversation_id) {
1255
- const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
1255
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
1256
1256
  reduce: true,
1257
1257
  group_level: 2,
1258
1258
  key: [uid, contact_id, conversation_id],
@@ -1270,7 +1270,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1270
1270
  if (!reference_id) {
1271
1271
  if (filter_type === 'pending') {
1272
1272
  const from_opt = { selector: { docType: 'team_request', access_type: 'chat', team_req_stat: 2, team_req_to_uid: uid }, fields: ['_id', 'team_req_date', 'sender_account_info.email', 'team_req_from_uid', 'share_item_id'] };
1273
- const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
1273
+ const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
1274
1274
 
1275
1275
  for await (let e of requests_from_res.docs) {
1276
1276
  let doc = { date_created: e.team_req_date, pending: true, uid: e.team_req_from_uid, team_req_id: e._id };
@@ -1281,7 +1281,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1281
1281
 
1282
1282
  //share_item_id
1283
1283
  const app_id = await get_account_default_project_id(e.team_req_from_uid);
1284
- const chat_ret = await db_ms.get_app_couch_doc_native(app_id, e.share_item_id);
1284
+ const chat_ret = await db_module.get_app_couch_doc_native(app_id, e.share_item_id);
1285
1285
  doc.title = chat_ret.title;
1286
1286
  doc.chat_image = chat_ret.chat_image;
1287
1287
 
@@ -1294,7 +1294,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1294
1294
  let ai_chats = { docs: [], total_docs: 0 };
1295
1295
 
1296
1296
  if (filter_type !== 'pending') {
1297
- ai_chats = await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
1297
+ ai_chats = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
1298
1298
  if (!limit || conversation_id) {
1299
1299
  ai_chats.total_docs = ai_chats.docs.length;
1300
1300
  } else {
@@ -1303,7 +1303,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1303
1303
  opt.limit = 9999;
1304
1304
  opt.fields = ['_id'];
1305
1305
 
1306
- const counter = await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
1306
+ const counter = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
1307
1307
  ai_chats.total_docs = counter.docs.length;
1308
1308
  }
1309
1309
  }
@@ -1315,7 +1315,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1315
1315
 
1316
1316
  if (doc.shared_from_uid) {
1317
1317
  reference_doc = _.cloneDeep(doc);
1318
- doc = await db_ms.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
1318
+ doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
1319
1319
  doc.reference_doc = reference_doc;
1320
1320
  }
1321
1321
 
@@ -1361,7 +1361,7 @@ export const delete_ai_chat = async function (req) {
1361
1361
  const account_profile_info = await get_active_account_profile_info(uid);
1362
1362
 
1363
1363
  const app_id = await get_account_default_project_id(uid);
1364
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1364
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1365
1365
 
1366
1366
  let save_ret;
1367
1367
  try {
@@ -1376,7 +1376,7 @@ export const delete_ai_chat = async function (req) {
1376
1376
  } else {
1377
1377
  conversation_doc.stat = 4;
1378
1378
  conversation_doc.ts = Date.now();
1379
- save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
1379
+ save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
1380
1380
 
1381
1381
  client.conversations.delete(conversation_id);
1382
1382
 
@@ -1406,7 +1406,7 @@ export const archive_ai_chat = async function (req) {
1406
1406
  try {
1407
1407
  await team_ms.validate_share_exist(uid, 'chat', conversation_id);
1408
1408
 
1409
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1409
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1410
1410
 
1411
1411
  if (conversation_doc.uid !== uid && conversation_doc?.account_profile_info?.uid !== uid) {
1412
1412
  throw new Error('Operation not allowed');
@@ -1414,7 +1414,7 @@ export const archive_ai_chat = async function (req) {
1414
1414
 
1415
1415
  conversation_doc.stat = 5;
1416
1416
  conversation_doc.ts = Date.now();
1417
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
1417
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
1418
1418
 
1419
1419
  return save_ret;
1420
1420
  } catch (err) {
@@ -1427,7 +1427,7 @@ export const unarchive_ai_chat = async function (req) {
1427
1427
  const account_profile_info = await get_active_account_profile_info(uid);
1428
1428
 
1429
1429
  try {
1430
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1430
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
1431
1431
 
1432
1432
  if (conversation_doc.stat !== 5) {
1433
1433
  throw new Error('chat is not archived');
@@ -1435,7 +1435,7 @@ export const unarchive_ai_chat = async function (req) {
1435
1435
 
1436
1436
  conversation_doc.stat = 3;
1437
1437
  conversation_doc.ts = Date.now();
1438
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
1438
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
1439
1439
 
1440
1440
  return save_ret;
1441
1441
  } catch (err) {
@@ -1525,7 +1525,7 @@ const get_studio_doc = async function (req) {
1525
1525
 
1526
1526
  const app_id = await get_account_default_project_id(uid);
1527
1527
  try {
1528
- let data = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, _id);
1528
+ let data = await db_module.get_app_couch_doc_native(account_profile_info.app_id, _id);
1529
1529
 
1530
1530
  if (data?.studio_meta?.createdByUid !== uid) delete data.agentConfig; //throw new Error('doctype not supported');
1531
1531
  return { code: 7, data };
@@ -1796,7 +1796,7 @@ export const get_ai_agent_info = async function (uid, job_id, headers, doc, from
1796
1796
  };
1797
1797
 
1798
1798
  const agent_conversation_count = async function (agent_id) {
1799
- const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1799
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1800
1800
  reduce: true,
1801
1801
  group_level: 1,
1802
1802
 
@@ -1850,7 +1850,7 @@ const get_user_ai_agents = async function (uid) {
1850
1850
  'properties.menuType': 'ai_agent',
1851
1851
  },
1852
1852
  };
1853
- return await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
1853
+ return await db_module.find_app_couch_query(account_profile_info.app_id, opt);
1854
1854
  };
1855
1855
 
1856
1856
  export const get_ai_agents = async function (req, job_id, headers) {
@@ -1941,7 +1941,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
1941
1941
 
1942
1942
  let user_agents = { docs: [], total_docs: 0 };
1943
1943
  if (filter_type !== 'pending') {
1944
- user_agents = await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
1944
+ user_agents = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
1945
1945
  if (!limit || agent_id) {
1946
1946
  user_agents.total_docs = user_agents.docs.length;
1947
1947
  } else {
@@ -1950,7 +1950,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
1950
1950
  opt.limit = 9999;
1951
1951
  opt.fields = ['_id'];
1952
1952
 
1953
- const counter = await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
1953
+ const counter = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
1954
1954
  user_agents.total_docs = counter.docs.length;
1955
1955
  }
1956
1956
  }
@@ -1959,7 +1959,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
1959
1959
  let requests_from = { docs: [], total_docs: 0 };
1960
1960
  if (filter_type === 'pending') {
1961
1961
  const from_opt = { selector: { docType: 'team_request', access_type: 'ai_agent', team_req_stat: 2, team_req_to_uid: uid }, fields: ['_id', 'team_req_date', 'sender_account_info.email', 'team_req_from_uid', 'share_item_id'] };
1962
- const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
1962
+ const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
1963
1963
 
1964
1964
  for await (let e of requests_from_res.docs) {
1965
1965
  let doc = { ts: e.team_req_date, pending: true, properties: {}, studio_meta: { createdByUid: e.team_req_from_uid }, team_req_id: e._id };
@@ -1971,7 +1971,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
1971
1971
 
1972
1972
  //share_item_id
1973
1973
  const app_id = await get_account_default_project_id(e.team_req_from_uid);
1974
- const ai_agent_doc = await db_ms.get_app_couch_doc_native(app_id, e.share_item_id);
1974
+ const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, e.share_item_id);
1975
1975
  doc.properties.menuName = ai_agent_doc.properties.menuName;
1976
1976
  doc.studio_meta.agent_image = ai_agent_doc.studio_meta.agent_image;
1977
1977
 
@@ -1989,7 +1989,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
1989
1989
  if (doc.studio_meta.shared_from_uid && doc.studio_meta.shared_from_app_id) {
1990
1990
  reference_doc = _.cloneDeep(doc);
1991
1991
  try {
1992
- doc = await db_ms.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
1992
+ doc = await db_module.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
1993
1993
  } catch (error) {
1994
1994
  continue;
1995
1995
  }
@@ -2000,7 +2000,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
2000
2000
  // purchased
2001
2001
  if (doc.studio_meta.installed_from_uid && doc.studio_meta.installed_from_app_id) {
2002
2002
  reference_doc = _.cloneDeep(doc);
2003
- doc = await db_ms.get_app_couch_doc_native(reference_doc.studio_meta.installed_from_app_id, doc._id);
2003
+ doc = await db_module.get_app_couch_doc_native(reference_doc.studio_meta.installed_from_app_id, doc._id);
2004
2004
  doc.reference_doc = reference_doc;
2005
2005
  doc.stat = reference_doc.stat;
2006
2006
  }
@@ -2025,7 +2025,7 @@ export const delete_ai_agent = async function (req) {
2025
2025
  // const project_db = await get_account_project_db(uid);
2026
2026
 
2027
2027
  try {
2028
- let prog_doc = await db_ms.get_app_couch_doc_native(app_id, agent_id);
2028
+ let prog_doc = await db_module.get_app_couch_doc_native(app_id, agent_id);
2029
2029
 
2030
2030
  if (prog_doc.stat !== 5) {
2031
2031
  throw new Error('A document can only be deleted after it has been archived');
@@ -2037,10 +2037,10 @@ export const delete_ai_agent = async function (req) {
2037
2037
 
2038
2038
  save_ret = await team_ms.remove_team_member({ team_req_id: prog_doc.studio_meta.team_req_id });
2039
2039
  } else {
2040
- let agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2040
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2041
2041
  agent_doc.stat = 4;
2042
2042
  agent_doc.ts = Date.now();
2043
- const save_ret = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2043
+ const save_ret = await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2044
2044
 
2045
2045
  for (const [key, val] of Object.entries(agent_doc?.agentConfig?.agent_tools || [])) {
2046
2046
  const file_id = val?.youtube?.file_id || val?.file?.file_id;
@@ -2065,7 +2065,7 @@ export const uninstall_ai_agent = async function (req) {
2065
2065
  const account_profile_info = await get_active_account_profile_info(uid);
2066
2066
 
2067
2067
  try {
2068
- let agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2068
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2069
2069
 
2070
2070
  if (!agent_doc.studio_meta.installed_from_app_id) {
2071
2071
  throw new Error('agent not installed');
@@ -2074,7 +2074,7 @@ export const uninstall_ai_agent = async function (req) {
2074
2074
  agent_doc.stat = 4;
2075
2075
  agent_doc.ts = Date.now();
2076
2076
 
2077
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2077
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2078
2078
 
2079
2079
  return save_ret;
2080
2080
  } catch (err) {
@@ -2087,7 +2087,7 @@ export const unarchive_ai_agent = async function (req) {
2087
2087
  const account_profile_info = await get_active_account_profile_info(uid);
2088
2088
 
2089
2089
  try {
2090
- let agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2090
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2091
2091
 
2092
2092
  if (agent_doc.stat !== 5) {
2093
2093
  throw new Error('agent is not archived');
@@ -2096,7 +2096,7 @@ export const unarchive_ai_agent = async function (req) {
2096
2096
  agent_doc.stat = 3;
2097
2097
  agent_doc.ts = Date.now();
2098
2098
 
2099
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2099
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2100
2100
 
2101
2101
  return save_ret;
2102
2102
  } catch (err) {
@@ -2110,7 +2110,7 @@ export const archive_ai_agent = async function (req) {
2110
2110
  try {
2111
2111
  await team_ms.validate_share_exist(uid, 'ai_agent', agent_id);
2112
2112
 
2113
- let agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2113
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2114
2114
 
2115
2115
  if (agent_doc.studio_meta.createdByUid !== uid && agent_doc?.studio_meta?.account_profile_info?.uid !== uid) {
2116
2116
  throw new Error('Operation not allowed');
@@ -2118,7 +2118,7 @@ export const archive_ai_agent = async function (req) {
2118
2118
 
2119
2119
  agent_doc.stat = 5;
2120
2120
  agent_doc.ts = Date.now();
2121
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2121
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2122
2122
 
2123
2123
  return save_ret;
2124
2124
  } catch (err) {
@@ -2134,7 +2134,7 @@ export const archive_mini_app = async function (req) {
2134
2134
  try {
2135
2135
  await team_ms.validate_share_exist(uid, 'miniapp', prog_id);
2136
2136
 
2137
- let prog_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2137
+ let prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2138
2138
 
2139
2139
  if (agent_doc.studio_meta.createdByUid !== uid && agent_doc?.studio_meta?.account_profile_info?.uid !== uid) {
2140
2140
  throw new Error('Operation not allowed');
@@ -2142,7 +2142,7 @@ export const archive_mini_app = async function (req) {
2142
2142
 
2143
2143
  prog_doc.stat = 5;
2144
2144
  prog_doc.ts = Date.now();
2145
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, prog_doc);
2145
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
2146
2146
 
2147
2147
  return save_ret;
2148
2148
  } catch (err) {
@@ -2156,7 +2156,7 @@ export const unarchive_mini_app = async function (req) {
2156
2156
  const account_profile_info = await get_active_account_profile_info(uid);
2157
2157
 
2158
2158
  try {
2159
- let prog_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2159
+ let prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2160
2160
 
2161
2161
  if (prog_doc.stat !== 5) {
2162
2162
  throw new Error('mini app is not archived');
@@ -2164,7 +2164,7 @@ export const unarchive_mini_app = async function (req) {
2164
2164
 
2165
2165
  prog_doc.stat = 3;
2166
2166
  prog_doc.ts = Date.now();
2167
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, prog_doc);
2167
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
2168
2168
 
2169
2169
  return save_ret;
2170
2170
  } catch (err) {
@@ -2178,7 +2178,7 @@ export const delete_mini_app = async function (req) {
2178
2178
  const account_profile_info = await get_active_account_profile_info(uid);
2179
2179
 
2180
2180
  try {
2181
- let prog_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2181
+ let prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
2182
2182
 
2183
2183
  if (prog_doc.stat !== 5) {
2184
2184
  throw new Error('A document can only be deleted after it has been archived');
@@ -2192,7 +2192,7 @@ export const delete_mini_app = async function (req) {
2192
2192
  } else {
2193
2193
  prog_doc.stat = 4;
2194
2194
  prog_doc.ts = Date.now();
2195
- save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, prog_doc);
2195
+ save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
2196
2196
  delete_depended_chats(uid, prog_id);
2197
2197
  }
2198
2198
  return save_ret;
@@ -2207,7 +2207,7 @@ export const update_ai_agent = async function (req, job_id, headers) {
2207
2207
  const account_profile_info = await get_active_account_profile_info(uid);
2208
2208
 
2209
2209
  try {
2210
- let agent_doc = await await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2210
+ let agent_doc = await await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2211
2211
 
2212
2212
  agent_doc.ts = Date.now();
2213
2213
  agent_doc.agentConfig = agentConfig;
@@ -2227,7 +2227,7 @@ export const update_ai_agent = async function (req, job_id, headers) {
2227
2227
  agent_doc.studio_meta.agent_tags = agentConfig.agent_tags;
2228
2228
  agent_doc.studio_meta.agent_user_guide = agentConfig.agent_user_guide;
2229
2229
 
2230
- const data = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2230
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2231
2231
 
2232
2232
  setTimeout(async () => {
2233
2233
  await update_ai_agent_properties(agent_doc, account_profile_info.app_id, uid, { name_changed, agent_user_guide_changed, agent_category_changed, agent_subcategory_changed, agent_instructions_changed });
@@ -2315,7 +2315,7 @@ export const get_apps = async function (req, job_id, headers) {
2315
2315
 
2316
2316
  let user_apps = { docs: [], total_docs: 0 };
2317
2317
  if (filter_type !== 'pending') {
2318
- user_apps = await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
2318
+ user_apps = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
2319
2319
  if (!limit || mini_app_id) {
2320
2320
  user_apps.total_docs = user_apps.docs.length;
2321
2321
  } else {
@@ -2324,7 +2324,7 @@ export const get_apps = async function (req, job_id, headers) {
2324
2324
  opt.limit = 9999;
2325
2325
  opt.fields = ['_id'];
2326
2326
 
2327
- const counter = await db_ms.find_app_couch_query(account_profile_info.app_id, opt);
2327
+ const counter = await db_module.find_app_couch_query(account_profile_info.app_id, opt);
2328
2328
  user_apps.total_docs = counter.docs.length;
2329
2329
  }
2330
2330
  }
@@ -2336,7 +2336,7 @@ export const get_apps = async function (req, job_id, headers) {
2336
2336
  if (!mini_app_id) {
2337
2337
  if (filter_type === 'pending') {
2338
2338
  const from_opt = { selector: { docType: 'team_request', access_type: 'miniapp', team_req_stat: 2, team_req_to_uid: uid }, fields: ['_id', 'team_req_date', 'sender_account_info.email', 'team_req_from_uid', 'share_item_id'] };
2339
- const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
2339
+ const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
2340
2340
 
2341
2341
  for await (let e of requests_from_res.docs) {
2342
2342
  //account_info
@@ -2348,7 +2348,7 @@ export const get_apps = async function (req, job_id, headers) {
2348
2348
 
2349
2349
  //share_item_id
2350
2350
  const app_id = await get_account_default_project_id(e.team_req_from_uid);
2351
- const miniapp_ret = await db_ms.get_app_couch_doc_native(app_id, e.share_item_id);
2351
+ const miniapp_ret = await db_module.get_app_couch_doc_native(app_id, e.share_item_id);
2352
2352
  doc.properties.menuName = miniapp_ret.properties.menuName;
2353
2353
  doc.studio_meta.agent_image = miniapp_ret.studio_meta.agent_image;
2354
2354
 
@@ -2364,7 +2364,7 @@ export const get_apps = async function (req, job_id, headers) {
2364
2364
  let reference_doc;
2365
2365
  if (doc.studio_meta.shared_from_uid) {
2366
2366
  reference_doc = _.cloneDeep(doc);
2367
- doc = await db_ms.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
2367
+ doc = await db_module.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
2368
2368
  doc.reference_doc = reference_doc;
2369
2369
  }
2370
2370
 
@@ -2574,11 +2574,11 @@ const save_agent_status = async function (uid, agent_id, stat, agentConfig) {
2574
2574
  const account_profile_info = await get_active_account_profile_info(uid);
2575
2575
 
2576
2576
  try {
2577
- let agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2577
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2578
2578
  agent_doc.ts = Date.now();
2579
2579
  agent_doc.stat = stat;
2580
2580
  agent_doc.agentConfig = agentConfig;
2581
- const data = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2581
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2582
2582
 
2583
2583
  return { code: 12, data };
2584
2584
  } catch (err) {
@@ -2608,7 +2608,7 @@ export const create_ai_agent = async function (req, job_id, headers) {
2608
2608
 
2609
2609
  // const data = await db.insert(agent_doc);
2610
2610
 
2611
- const data = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2611
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2612
2612
  setTimeout(async () => {
2613
2613
  await update_ai_agent_properties(agent_doc, account_profile_info.app_id, uid);
2614
2614
  await update_thumbnail('ai_agent', agent_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
@@ -2623,7 +2623,7 @@ export const create_ai_agent = async function (req, job_id, headers) {
2623
2623
 
2624
2624
  export const update_ai_agent_properties = async function (doc, app_id, uid, fields_changed = {}) {
2625
2625
  debugger;
2626
- const db_doc = await db_ms.get_app_couch_doc_native(app_id, doc._id);
2626
+ const db_doc = await db_module.get_app_couch_doc_native(app_id, doc._id);
2627
2627
  // const { account_profile_info } = doc.studio_meta;
2628
2628
  const account_profile_info = await get_active_account_profile_info(uid);
2629
2629
 
@@ -2835,7 +2835,7 @@ export const update_ai_agent_properties = async function (doc, app_id, uid, fiel
2835
2835
  db_doc.studio_meta.agent_user_guide_steps = db_doc.agentConfig.agent_user_guide_steps;
2836
2836
  }
2837
2837
 
2838
- const save_ret = await db_ms.save_app_couch_doc_native(app_id, db_doc);
2838
+ const save_ret = await db_module.save_app_couch_doc_native(app_id, db_doc);
2839
2839
  return save_ret;
2840
2840
  };
2841
2841
 
@@ -2846,9 +2846,9 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
2846
2846
  try {
2847
2847
  const get_db_doc = async function () {
2848
2848
  if (xuda_db) {
2849
- return await db_ms.get_couch_doc_native(xuda_db, doc._id);
2849
+ return await db_module.get_couch_doc_native(xuda_db, doc._id);
2850
2850
  } else {
2851
- return await db_ms.get_app_couch_doc_native(account_profile_info.app_id, doc._id);
2851
+ return await db_module.get_app_couch_doc_native(account_profile_info.app_id, doc._id);
2852
2852
  }
2853
2853
  };
2854
2854
 
@@ -2951,9 +2951,9 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
2951
2951
  let save_ret;
2952
2952
 
2953
2953
  if (xuda_db) {
2954
- save_ret = await db_ms.save_couch_doc_native(xuda_db, db_doc);
2954
+ save_ret = await db_module.save_couch_doc_native(xuda_db, db_doc);
2955
2955
  } else {
2956
- save_ret = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, db_doc);
2956
+ save_ret = await db_module.save_app_couch_doc_native(account_profile_info.app_id, db_doc);
2957
2957
  }
2958
2958
  return save_ret;
2959
2959
  } catch (error) {
@@ -3416,7 +3416,7 @@ export const create_conversation = async function (req, job_id, headers) {
3416
3416
  from_mailbox,
3417
3417
  email_recipient_type,
3418
3418
  };
3419
- const save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
3419
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
3420
3420
 
3421
3421
  let contact_id, contact_doc, recipient_uid, recipient_contact_id;
3422
3422
 
@@ -3437,7 +3437,7 @@ export const create_conversation = async function (req, job_id, headers) {
3437
3437
  recipient_uid = contact_doc.connection_uid;
3438
3438
 
3439
3439
  const app_id = await get_account_default_project_id(recipient_uid);
3440
- const save_ret = await db_ms.save_app_couch_doc(app_id, { ...conversation_doc, ...{ uid: recipient_uid, reference_id: recipient_contact_id } });
3440
+ const save_ret = await db_module.save_app_couch_doc(app_id, { ...conversation_doc, ...{ uid: recipient_uid, reference_id: recipient_contact_id } });
3441
3441
  }
3442
3442
 
3443
3443
  setTimeout(async () => {
@@ -3452,15 +3452,15 @@ export const create_conversation = async function (req, job_id, headers) {
3452
3452
  // write conversation to host after thumbnail update
3453
3453
  // get sender conversation
3454
3454
 
3455
- const conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3455
+ const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3456
3456
 
3457
3457
  const recipient_account_profile_info = await get_active_account_profile_info(recipient_uid);
3458
- let recipient_conversation_doc = await db_ms.get_app_couch_doc_native(recipient_account_profile_info.app_id, conversation_doc._id);
3458
+ let recipient_conversation_doc = await db_module.get_app_couch_doc_native(recipient_account_profile_info.app_id, conversation_doc._id);
3459
3459
  recipient_conversation_doc.title = conversation_doc.title;
3460
3460
 
3461
3461
  recipient_conversation_doc.thumbnail_request_ts = conversation_doc.thumbnail_request_ts;
3462
3462
  recipient_conversation_doc.chat_image = conversation_doc.chat_image;
3463
- await db_ms.save_app_couch_doc_native(recipient_account_profile_info.app_id, recipient_conversation_doc);
3463
+ await db_module.save_app_couch_doc_native(recipient_account_profile_info.app_id, recipient_conversation_doc);
3464
3464
 
3465
3465
  await update_conversation_mood_level(
3466
3466
  uid,
@@ -3493,7 +3493,7 @@ export const create_conversation = async function (req, job_id, headers) {
3493
3493
  };
3494
3494
 
3495
3495
  const process_conversation = async function (uid, conversation_id, account_profile_info, job_id, headers) {
3496
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3496
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3497
3497
  const { conversation_type, prompt, reference_id } = conversation_doc;
3498
3498
 
3499
3499
  // Ask GPT for title
@@ -3501,10 +3501,10 @@ const process_conversation = async function (uid, conversation_id, account_profi
3501
3501
  if (prompt.split(' ').length > 10) {
3502
3502
  const title = await submit_chat_gpt_prompt({ uid, prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`, model: _conf.default_ai_model, metadata: { conversation_id: conversation_doc._id, func: 'create_conversation' }, account_profile_info });
3503
3503
 
3504
- conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3504
+ conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3505
3505
  conversation_doc.title = title.data;
3506
3506
 
3507
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3507
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3508
3508
  }
3509
3509
  }
3510
3510
  /// categorize prompt
@@ -3537,10 +3537,10 @@ const process_conversation = async function (uid, conversation_id, account_profi
3537
3537
  }
3538
3538
  }
3539
3539
 
3540
- conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3540
+ conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
3541
3541
  conversation_doc.category_info = category_info;
3542
3542
  conversation_doc.process_stat = 'full';
3543
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3543
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3544
3544
 
3545
3545
  if (category_info.category) {
3546
3546
  await update_thumbnail('conversation_category', conversation_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
@@ -3581,7 +3581,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
3581
3581
  if (!conversation_id) throw new Error('missing conversation_id');
3582
3582
  const account_profile_info = await get_active_account_profile_info(uid, profile_id);
3583
3583
 
3584
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3584
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3585
3585
  req.conversation_doc = conversation_doc;
3586
3586
  let ret;
3587
3587
  if (conversation_doc.reference_type === 'contacts') {
@@ -3646,9 +3646,9 @@ const update_conversation_mood_level = async function (uid, target_contacts = []
3646
3646
 
3647
3647
  for await (const target of target_contacts) {
3648
3648
  const account_profile_info = await get_active_account_profile_info(target.uid);
3649
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3649
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
3650
3650
  conversation_doc.mood_level = mood_level_obj.mood_level;
3651
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3651
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
3652
3652
 
3653
3653
  if (update_contact) {
3654
3654
  const account_profile_info = await get_active_account_profile_info(target.uid);
@@ -3672,11 +3672,11 @@ const contact_chat_conversation = async function (req, job_id, headers) {
3672
3672
 
3673
3673
  const receiver_contact_doc = await get_contact_info(uid, null, conversation_doc.reference_id);
3674
3674
  const receiver_app_id = await get_account_default_project_id(receiver_contact_doc.contact_uid);
3675
- let receiver_conversation_doc = await db_ms.get_app_couch_doc_native(receiver_app_id, conversation_id);
3675
+ let receiver_conversation_doc = await db_module.get_app_couch_doc_native(receiver_app_id, conversation_id);
3676
3676
 
3677
3677
  const sender_contact_doc = await get_contact_info(uid, null, conversation_doc.reference_id);
3678
3678
  const sender_app_id = account_profile_info.app_id;
3679
- let sender_conversation_doc = await db_ms.get_app_couch_doc_native(sender_app_id, conversation_id);
3679
+ let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
3680
3680
 
3681
3681
  let item;
3682
3682
  try {
@@ -3698,10 +3698,10 @@ const contact_chat_conversation = async function (req, job_id, headers) {
3698
3698
  // const obj = { id: item.data[0].id, ts: Date.now(), uid, read: true, conversation_type: 'chat' };
3699
3699
  // receiver_conversation_doc.messages.push(obj);
3700
3700
 
3701
- await db_ms.save_app_couch_doc_native(receiver_app_id, receiver_conversation_doc);
3701
+ await db_module.save_app_couch_doc_native(receiver_app_id, receiver_conversation_doc);
3702
3702
  // sender_conversation_doc.messages.push({ ...obj, ...{ read: false } });
3703
3703
 
3704
- await db_ms.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
3704
+ await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
3705
3705
 
3706
3706
  let out_conversation_item_obj = {
3707
3707
  _id: await _common.xuda_get_uuid('chat_conversation_item'),
@@ -3720,7 +3720,7 @@ const contact_chat_conversation = async function (req, job_id, headers) {
3720
3720
  role: 'user',
3721
3721
  };
3722
3722
 
3723
- const save_ret = await db_ms.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
3723
+ const save_ret = await db_module.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
3724
3724
 
3725
3725
  update_conversation_mood_level(uid, conversation_id, prompt, uid, receiver_contact_doc.contact_uid, conversation_doc.reference_type === 'contacts', account_profile_info);
3726
3726
 
@@ -3735,7 +3735,7 @@ const chat_note = async function (req, job_id, headers) {
3735
3735
  const conversation_id = conversation_doc._id;
3736
3736
 
3737
3737
  const sender_app_id = account_profile_info.app_id; //await get_account_default_project_id(uid);
3738
- let sender_conversation_doc = await db_ms.get_app_couch_doc_native(sender_app_id, conversation_id);
3738
+ let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
3739
3739
 
3740
3740
  await attachment_handler(uid, sender_app_id, conversation_id, attachments, account_profile_info);
3741
3741
  let item;
@@ -3758,7 +3758,7 @@ const chat_note = async function (req, job_id, headers) {
3758
3758
  // let obj = { id: item.data[0].id, ts: Date.now(), uid, read: true, conversation_type: 'note' };
3759
3759
 
3760
3760
  // sender_conversation_doc.messages.push(obj);
3761
- // await db_ms.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
3761
+ // await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
3762
3762
 
3763
3763
  let out_conversation_item_obj = {
3764
3764
  _id: await _common.xuda_get_uuid('chat_conversation_item'),
@@ -3779,9 +3779,9 @@ const chat_note = async function (req, job_id, headers) {
3779
3779
  rtl: _common.detectRTL(body),
3780
3780
  };
3781
3781
 
3782
- const save_ret = await db_ms.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
3782
+ const save_ret = await db_module.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
3783
3783
 
3784
- // await db_ms.save_app_couch_doc_native(sender_app_id, { _id: obj.id, stat: 3, docType: 'chat_conversation_item', ts: obj.ts, uid, conversation_type: obj.conversation_type, date_created_ts: obj.ts, conversation_id, body, reference_id: conversation_doc.reference_id });
3784
+ // await db_module.save_app_couch_doc_native(sender_app_id, { _id: obj.id, stat: 3, docType: 'chat_conversation_item', ts: obj.ts, uid, conversation_type: obj.conversation_type, date_created_ts: obj.ts, conversation_id, body, reference_id: conversation_doc.reference_id });
3785
3785
 
3786
3786
  return save_ret; //{ code: 15, data: item };
3787
3787
  } catch (err) {
@@ -3801,9 +3801,9 @@ const chat_email = async function (req, job_id, headers) {
3801
3801
  const conversation_id = conversation_doc._id;
3802
3802
  const sender_app_id = account_profile_info.app_id;
3803
3803
 
3804
- let email_account_doc = await db_ms.get_app_couch_doc_native(sender_app_id, account_profile_info.account_profile_obj?.email_account_id);
3804
+ let email_account_doc = await db_module.get_app_couch_doc_native(sender_app_id, account_profile_info.account_profile_obj?.email_account_id);
3805
3805
 
3806
- let sender_conversation_doc = await db_ms.get_app_couch_doc_native(sender_app_id, conversation_id);
3806
+ let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
3807
3807
 
3808
3808
  if (sender_conversation_doc.reference_type !== 'contacts') {
3809
3809
  throw new Error('not an contact conversation');
@@ -3820,7 +3820,7 @@ const chat_email = async function (req, job_id, headers) {
3820
3820
  if (!from_mailbox) {
3821
3821
  // get last email
3822
3822
 
3823
- const chat_conversation_item = await db_ms.find_app_couch_query(account_profile_info.app_id, {
3823
+ const chat_conversation_item = await db_module.find_app_couch_query(account_profile_info.app_id, {
3824
3824
  selector: {
3825
3825
  docType: 'chat_conversation_item',
3826
3826
  conversation_type: 'email',
@@ -3883,7 +3883,7 @@ const chat_email = async function (req, job_id, headers) {
3883
3883
  // let obj = { id: item.data[0].id, ts: Date.now(), uid, read: true, conversation_type: 'email' };
3884
3884
 
3885
3885
  // sender_conversation_doc.messages.push(obj);
3886
- await db_ms.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
3886
+ await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
3887
3887
 
3888
3888
  let out_conversation_item_obj = {
3889
3889
  _id: await _common.xuda_get_uuid('chat_conversation_item'),
@@ -3907,8 +3907,8 @@ const chat_email = async function (req, job_id, headers) {
3907
3907
  process_stat: perform_ai_execution ? 'full' : 'partial',
3908
3908
  };
3909
3909
 
3910
- const save_ret = await db_ms.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
3911
- // const save_ret = await db_ms.save_app_couch_doc_native(sender_app_id, {
3910
+ const save_ret = await db_module.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
3911
+ // const save_ret = await db_module.save_app_couch_doc_native(sender_app_id, {
3912
3912
  // _id: obj.id,
3913
3913
  // stat: 3,
3914
3914
  // docType: 'chat_conversation_item',
@@ -3961,7 +3961,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
3961
3961
  direction: 'out',
3962
3962
  role: 'user',
3963
3963
  };
3964
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_obj);
3964
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_obj);
3965
3965
 
3966
3966
  // const { account_profile_info } = conversation_doc;
3967
3967
  const emitToDashboard = (type, content) => {
@@ -4036,13 +4036,13 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4036
4036
  await _utils.delay(500);
4037
4037
  await update_job('initiating conversation');
4038
4038
 
4039
- // let conversation_doc = await db_ms.get_app_couch_doc_native(app_id, conversation_id);
4039
+ // let conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
4040
4040
  const reference_type = conversation_doc.reference_type;
4041
4041
  const reference_id = conversation_doc.reference_id;
4042
4042
 
4043
4043
  conversation_doc.stat = 2;
4044
4044
  conversation_doc.ts = Date.now();
4045
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4045
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4046
4046
 
4047
4047
  await update_job('analyzing request');
4048
4048
 
@@ -4155,16 +4155,16 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4155
4155
  try {
4156
4156
  let ai_agent_doc;
4157
4157
  try {
4158
- ai_agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
4158
+ ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
4159
4159
  if (ai_agent_doc.studio_meta.shared_from_uid) {
4160
4160
  const reference_doc = _.cloneDeep(ai_agent_doc);
4161
4161
  const app_id = await get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
4162
- ai_agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4162
+ ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4163
4163
  ai_agent_doc.reference_doc = reference_doc;
4164
4164
  } else if (ai_agent_doc.studio_meta.installed_from_uid) {
4165
4165
  const reference_doc = _.cloneDeep(ai_agent_doc);
4166
4166
  const app_id = await get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_uid);
4167
- ai_agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4167
+ ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4168
4168
  ai_agent_doc.reference_doc = reference_doc;
4169
4169
  }
4170
4170
  } catch (err) {
@@ -4417,7 +4417,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4417
4417
  opt.selector._id = val.ai_agent_id;
4418
4418
  }
4419
4419
 
4420
- const user_agents = await db_ms.find_app_couch_query(ai_agent_doc?.reference_doc?.studio_meta?.shared_from_app_id || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_app_id || app_id, opt);
4420
+ const user_agents = await db_module.find_app_couch_query(ai_agent_doc?.reference_doc?.studio_meta?.shared_from_app_id || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_app_id || app_id, opt);
4421
4421
  for (const agent_doc of user_agents.docs) {
4422
4422
  const agent = new Agent({
4423
4423
  name: agent_doc.agent_name.substring(0, 60),
@@ -4506,9 +4506,9 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4506
4506
 
4507
4507
  const set_ts_to_agent = async function () {
4508
4508
  try {
4509
- let agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, reference_id);
4509
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, reference_id);
4510
4510
  agent_doc.ts = Date.now();
4511
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
4511
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
4512
4512
  } catch (err) {}
4513
4513
  };
4514
4514
 
@@ -4554,7 +4554,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4554
4554
  const done = async function (output) {
4555
4555
  try {
4556
4556
  // const obj = { id: output.state._lastTurnResponse.responseId, ts: Date.now(), ai_agent_id: output.state._currentAgent.name, attachments, conversation_type: 'ai_chat' };
4557
- conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
4557
+ conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
4558
4558
 
4559
4559
  conversation_doc.ts = Date.now();
4560
4560
  conversation_doc.stat = 3;
@@ -4568,7 +4568,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4568
4568
  outputTokens += item.usage.outputTokens;
4569
4569
  }
4570
4570
 
4571
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4571
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4572
4572
 
4573
4573
  // let conversation_item_obj = {
4574
4574
  // _id: obj.id,
@@ -4587,7 +4587,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4587
4587
  // direction: 'out',
4588
4588
  // role: 'user',
4589
4589
  // };
4590
- // await db_ms.save_app_couch_doc_native(account_profile_info.app_id, conversation_item_obj);
4590
+ // await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_item_obj);
4591
4591
 
4592
4592
  let in_conversation_item_obj = {
4593
4593
  _id: await _common.xuda_get_uuid('chat_conversation_item'),
@@ -4606,16 +4606,16 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4606
4606
  role: 'assistant',
4607
4607
  ai_agent_id: output.state._currentAgent.name,
4608
4608
  };
4609
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, in_conversation_item_obj);
4609
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, in_conversation_item_obj);
4610
4610
 
4611
4611
  debugger;
4612
4612
 
4613
4613
  let conversation_items = await client.conversations.items.list(conversation_doc.reference_conversation_id, { order: 'asc', after: last_conversation_item });
4614
4614
 
4615
- let out_conversation_item_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_obj._id);
4615
+ let out_conversation_item_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_obj._id);
4616
4616
  // out_conversation_item_doc.stat = 3;
4617
4617
  out_conversation_item_doc.conversation_item_reference_id = conversation_items?.data?.[0]?.id;
4618
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_doc);
4618
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_doc);
4619
4619
 
4620
4620
  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);
4621
4621
  // if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
@@ -4823,7 +4823,7 @@ const run_plugin = async function (app_id, uid, plugin_name, method, prop_data,
4823
4823
 
4824
4824
  let plugin_doc;
4825
4825
  try {
4826
- plugin_doc = await db_ms.get_app_couch_doc_native(app_id, plugin_name);
4826
+ plugin_doc = await db_module.get_app_couch_doc_native(app_id, plugin_name);
4827
4827
  } catch (error) {
4828
4828
  throw new Error(`plugin_doc ${plugin_name} not found`);
4829
4829
  }
@@ -4951,7 +4951,7 @@ const get_plugin_tool = async function (app_id, uid, plugin_name, method, prop_d
4951
4951
 
4952
4952
  let plugin_doc;
4953
4953
  try {
4954
- plugin_doc = await db_ms.get_app_couch_doc_native(app_id, plugin_name);
4954
+ plugin_doc = await db_module.get_app_couch_doc_native(app_id, plugin_name);
4955
4955
  } catch (error) {
4956
4956
  throw new Error(`plugin_doc ${plugin_name} not found`);
4957
4957
  }
@@ -5123,7 +5123,7 @@ export const create_avatar = async function (req, job_id, headers) {
5123
5123
 
5124
5124
  const account_profile_info = await get_active_account_profile_info(uid);
5125
5125
 
5126
- const account_obj = await db_ms.get_couch_doc_native('xuda_accounts', uid);
5126
+ const account_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
5127
5127
  const account_info = account_obj.account_info;
5128
5128
  if (!metadata) {
5129
5129
  metadata = account_info;
@@ -5706,9 +5706,9 @@ export const conversation_actions = async function (req, job_id, headers) {
5706
5706
 
5707
5707
  // const update_profile_avatar_status = async function (uid, stat) {
5708
5708
  // try {
5709
- // let doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
5709
+ // let doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
5710
5710
  // doc.account_info.profile_avatar_stat = stat;
5711
- // const save_ret = await db_ms.save_couch_doc_native('xuda_accounts', doc);
5711
+ // const save_ret = await db_module.save_couch_doc_native('xuda_accounts', doc);
5712
5712
  // } catch (err) {
5713
5713
  // console.error(err);
5714
5714
  // }
@@ -5756,7 +5756,7 @@ export const modify_profile_avatar = async function (req, job_id, headers) {
5756
5756
  }
5757
5757
  }
5758
5758
 
5759
- const account_obj = await db_ms.get_couch_doc_native('xuda_accounts', uid);
5759
+ const account_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
5760
5760
  const account_info = account_obj.account_info;
5761
5761
  if (!metadata) {
5762
5762
  metadata = account_info;
@@ -5773,7 +5773,7 @@ export const get_ai_workspace_pending_counts = async function (req, job_id, head
5773
5773
  const { uid } = req;
5774
5774
 
5775
5775
  try {
5776
- const workspace_pending_counts_ret = await db_ms.get_couch_view('xuda_team', 'pending_workspace_requests_count', {
5776
+ const workspace_pending_counts_ret = await db_module.get_couch_view('xuda_team', 'pending_workspace_requests_count', {
5777
5777
  startkey: [uid, ''],
5778
5778
  endkey: [uid, 'zzzz'],
5779
5779
  reduce: true,
@@ -5834,8 +5834,8 @@ const create_ai_agent_image = async function (req, job_id, headers) {
5834
5834
 
5835
5835
  const { app_id, uid, ai_agent_id, tags } = req;
5836
5836
  const account_profile_info = await get_active_account_profile_info(uid);
5837
- const ai_agent_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_id);
5838
- const account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
5837
+ const ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_id);
5838
+ const account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
5839
5839
 
5840
5840
  // faceless humanoid for business
5841
5841
  if (account_doc.account_info.account_type === 'business') {
@@ -5977,7 +5977,7 @@ export const create_mini_app = async function (req, job_id, headers) {
5977
5977
  const name = await submit_chat_gpt_prompt({ uid, prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`, model: _conf.default_ai_model, metadata: { prog_id: component_doc._id, func: 'create_mini_app' } }, account_profile_info);
5978
5978
  component_doc.properties.menuName = name.data;
5979
5979
  component_doc.properties.menuTitle = name.data;
5980
- const data = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, component_doc);
5980
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, component_doc);
5981
5981
  setTimeout(async () => {
5982
5982
  await update_thumbnail('mini_app', component_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
5983
5983
  }, 500);
@@ -5993,11 +5993,11 @@ export const pin_ai_agent = async function (req, job_id, headers) {
5993
5993
  const { uid, agent_id } = req;
5994
5994
  try {
5995
5995
  const app_id = await get_account_default_project_id(uid);
5996
- const ai_agent_doc = await db_ms.get_app_couch_doc_native(app_id, agent_id);
5996
+ const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, agent_id);
5997
5997
 
5998
5998
  ai_agent_doc.studio_meta.pinned = true;
5999
5999
 
6000
- const save_ret = await db_ms.save_app_couch_doc(app_id, ai_agent_doc);
6000
+ const save_ret = await db_module.save_app_couch_doc(app_id, ai_agent_doc);
6001
6001
 
6002
6002
  ws_dashboard_ms.emit_message_to_dashboard({
6003
6003
  service: 'ai_agent_pinned',
@@ -6017,11 +6017,11 @@ export const unpin_ai_agent = async function (req, job_id, headers) {
6017
6017
  const { uid, agent_id } = req;
6018
6018
  try {
6019
6019
  const app_id = await get_account_default_project_id(uid);
6020
- const ai_agent_doc = await db_ms.get_app_couch_doc_native(app_id, agent_id);
6020
+ const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, agent_id);
6021
6021
 
6022
6022
  ai_agent_doc.studio_meta.pinned = false;
6023
6023
 
6024
- const save_ret = await db_ms.save_app_couch_doc(app_id, ai_agent_doc);
6024
+ const save_ret = await db_module.save_app_couch_doc(app_id, ai_agent_doc);
6025
6025
 
6026
6026
  ws_dashboard_ms.emit_message_to_dashboard({
6027
6027
  service: 'ai_agent_unpinned',
@@ -6164,7 +6164,7 @@ export const add_transcript_conversation_item = async function (reference_conver
6164
6164
 
6165
6165
  const attachment_handler = async function (uid, app_id, conversation_id, attachments, account_profile_info, date_created_ts) {
6166
6166
  if (!attachments?.length) return;
6167
- let conversation_doc = await db_ms.get_app_couch_doc_native(app_id, conversation_id);
6167
+ let conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
6168
6168
 
6169
6169
  // const get_transcript = async function (filename) {
6170
6170
  // async function streamToBuffer(fileStream) {
@@ -6326,21 +6326,21 @@ const attachment_handler = async function (uid, app_id, conversation_id, attachm
6326
6326
  read: { [uid]: Date.now() },
6327
6327
  process_stat,
6328
6328
  };
6329
- await db_ms.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_obj);
6329
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_obj);
6330
6330
  system_message_items.push(out_conversation_item_obj);
6331
6331
  }
6332
6332
 
6333
- conversation_doc = await db_ms.get_app_couch_doc_native(app_id, conversation_id);
6333
+ conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
6334
6334
 
6335
6335
  conversation_doc.ts = Date.now();
6336
6336
  conversation_doc.stat = 2;
6337
6337
 
6338
- await db_ms.save_app_couch_doc_native(app_id, conversation_doc);
6338
+ await db_module.save_app_couch_doc_native(app_id, conversation_doc);
6339
6339
  return system_message_items;
6340
6340
  };
6341
6341
 
6342
6342
  export const is_spam_email = async function (uid, email, subject, account_profile_info) {
6343
- const spam_whitelists = await db_ms.find_couch_query('xuda_accounts', {
6343
+ const spam_whitelists = await db_module.find_couch_query('xuda_accounts', {
6344
6344
  selector: {
6345
6345
  docType: 'spam_whitelist',
6346
6346
  email,
@@ -6562,7 +6562,7 @@ const get_chat_picture_cache = async function (uid, docType, key) {
6562
6562
 
6563
6563
  if (words.length < 3) {
6564
6564
  // Direct exact match for short names
6565
- const ret = await db_ms.find_couch_query('xuda_cache', {
6565
+ const ret = await db_module.find_couch_query('xuda_cache', {
6566
6566
  selector: { docType, key: key.toLowerCase().trim() },
6567
6567
  limit: 1,
6568
6568
  });
@@ -6593,7 +6593,7 @@ const get_chat_picture_cache = async function (uid, docType, key) {
6593
6593
  limit: 1,
6594
6594
  };
6595
6595
 
6596
- const ret = await db_ms.find_couch_query('xuda_cache', query);
6596
+ const ret = await db_module.find_couch_query('xuda_cache', query);
6597
6597
 
6598
6598
  if (ret.docs.length > 0) {
6599
6599
  account_ms.save_cache_hit(ret.docs[0]._id);
@@ -10726,11 +10726,11 @@ export const open_ai_alive_check = async function () {};
10726
10726
 
10727
10727
  // let account_profile_info;
10728
10728
  // try {
10729
- // account_profile_info = await db_ms.get_memcached_doc(key);
10729
+ // account_profile_info = await db_module.get_memcached_doc(key);
10730
10730
  // } catch (error) {
10731
10731
  // try {
10732
10732
  // account_profile_info = await account_ms.get_active_account_profile_info(uid);
10733
- // db_ms.set_memcached_doc(key, account_profile_info);
10733
+ // db_module.set_memcached_doc(key, account_profile_info);
10734
10734
  // } catch (error) {}
10735
10735
  // }
10736
10736
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4976",
3
+ "version": "1.1.4977",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",