@xuda.io/ai_module 1.1.4209 → 1.1.4211

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 +20 -17
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -4140,7 +4140,7 @@ export const create_conversation = async function (req, job_id, headers) {
4140
4140
  let { reference_type, reference_id = '', conversation_type } = req;
4141
4141
 
4142
4142
  const account_profile_info = await account_module.get_active_account_profile_info(uid);
4143
-
4143
+ const { account_profile } = account_profile_info;
4144
4144
  try {
4145
4145
  const conversation_obj = await client.conversations.create();
4146
4146
  const t = Date.now();
@@ -4159,7 +4159,7 @@ export const create_conversation = async function (req, job_id, headers) {
4159
4159
  conversation_type,
4160
4160
  initiator_uid: uid,
4161
4161
 
4162
- account_profile_info,
4162
+ account_profiles: [account_profile],
4163
4163
  };
4164
4164
  const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
4165
4165
 
@@ -4402,6 +4402,7 @@ const update_conversation_mood_level = async function (conversation_id, prompt,
4402
4402
 
4403
4403
  const contact_chat_conversation = async function (req, job_id, headers) {
4404
4404
  const { uid } = req;
4405
+ const account_profile_info = await account_module.get_active_account_profile_info(uid);
4405
4406
  let { prompt, conversation_doc, attachments = [], ai_agents } = req;
4406
4407
 
4407
4408
  const conversation_id = conversation_doc._id;
@@ -4412,7 +4413,7 @@ const contact_chat_conversation = async function (req, job_id, headers) {
4412
4413
 
4413
4414
  const sender_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
4414
4415
  // const sender_app_id = await account_module.get_account_default_project_id(uid);
4415
- const sender_app_id = conversation_doc.account_profile_info.app_id;
4416
+ const sender_app_id = account_profile_info.app_id;
4416
4417
  let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
4417
4418
 
4418
4419
  const item = await client.conversations.items.create(conversation_id, {
@@ -4438,8 +4439,9 @@ const contact_chat_conversation = async function (req, job_id, headers) {
4438
4439
 
4439
4440
  const chat_note = async function (req, job_id, headers) {
4440
4441
  const { uid } = req;
4442
+ const account_profile_info = await account_module.get_active_account_profile_info(uid);
4441
4443
  let { prompt, conversation_doc, attachments = [], ai_agents } = req;
4442
- const { account_profile_info } = conversation_doc;
4444
+ // const { account_profile_info } = conversation_doc;
4443
4445
  const conversation_id = conversation_doc._id;
4444
4446
 
4445
4447
  // const receiver_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
@@ -4450,7 +4452,7 @@ const chat_note = async function (req, job_id, headers) {
4450
4452
 
4451
4453
  // account_module.ts_contact(conversation_doc.reference_id);
4452
4454
 
4453
- const sender_app_id = conversation_doc.account_profile_info.app_id; //await account_module.get_account_default_project_id(uid);
4455
+ const sender_app_id = account_profile_info.app_id; //await account_module.get_account_default_project_id(uid);
4454
4456
  let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
4455
4457
 
4456
4458
  await attachment_handler(uid, sender_app_id, conversation_id, attachments, account_profile_info);
@@ -4476,10 +4478,11 @@ const chat_note = async function (req, job_id, headers) {
4476
4478
 
4477
4479
  const ai_chat_conversation = async function (req, job_id, headers) {
4478
4480
  const { uid, gtp_token } = req;
4481
+ const account_profile_info = await account_module.get_active_account_profile_info(uid);
4479
4482
  let { prompt, conversation_doc, attachments = [], ai_agents, output_format = 'md', stream = true, with_context = true } = req;
4480
4483
  await _utils.delay(1000);
4481
4484
  const conversation_id = conversation_doc._id;
4482
- const { account_profile_info } = conversation_doc;
4485
+ // const { account_profile_info } = conversation_doc;
4483
4486
  const emitToDashboard = (type, content) => {
4484
4487
  // console.log(type, content);
4485
4488
  global[`_ai_module_ch`].sendToQueue(
@@ -4523,10 +4526,10 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4523
4526
 
4524
4527
  try {
4525
4528
  const app_id = await account_module.get_account_default_project_id(uid);
4526
- const app_obj = await get_app_obj(conversation_doc.account_profile_info.app_id);
4529
+ const app_obj = await get_app_obj(account_profile_info.app_id);
4527
4530
  const userName = await account_module.get_user_name(uid);
4528
4531
  const account_info = (await account_module.get_account_name({ uid })).data;
4529
- let context = { ...{ app_id: conversation_doc.account_profile_info.app_id, uid, userName, account_info, app_obj, account_id: uid }, ...extractClientInfo(headers) };
4532
+ let context = { ...{ app_id: account_profile_info.app_id, uid, userName, account_info, app_obj, account_id: uid }, ...extractClientInfo(headers) };
4530
4533
  const d = new Intl.DateTimeFormat('en-US').format(new Date());
4531
4534
  if (!visitors[d]) {
4532
4535
  visitors[d] = {};
@@ -4569,7 +4572,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4569
4572
 
4570
4573
  conversation_doc.stat = 2;
4571
4574
  conversation_doc.ts = Date.now();
4572
- await db_module.save_app_couch_doc_native(conversation_doc.account_profile_info.app_id, conversation_doc);
4575
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4573
4576
 
4574
4577
  await update_job('analyzing request');
4575
4578
 
@@ -4682,16 +4685,16 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4682
4685
  try {
4683
4686
  let ai_agent_doc;
4684
4687
  try {
4685
- ai_agent_doc = await db_module.get_app_couch_doc_native(conversation_doc.account_profile_info.app_id, agent_id);
4688
+ ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
4686
4689
  if (ai_agent_doc.studio_meta.shared_from_uid) {
4687
4690
  const reference_doc = _.cloneDeep(ai_agent_doc);
4688
4691
  const app_id = await account_module.get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
4689
- ai_agent_doc = await db_module.get_app_couch_doc_native(conversation_doc.account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4692
+ ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4690
4693
  ai_agent_doc.reference_doc = reference_doc;
4691
4694
  } else if (ai_agent_doc.studio_meta.installed_from_uid) {
4692
4695
  const reference_doc = _.cloneDeep(ai_agent_doc);
4693
4696
  const app_id = await account_module.get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_uid);
4694
- ai_agent_doc = await db_module.get_app_couch_doc_native(conversation_doc.account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4697
+ ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
4695
4698
  ai_agent_doc.reference_doc = reference_doc;
4696
4699
  }
4697
4700
  } catch (err) {
@@ -4842,7 +4845,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4842
4845
  const { prompt, numGenerations } = e;
4843
4846
  try {
4844
4847
  let imgTags = '';
4845
- const images_arr = await create_and_upload_image_to_drive('workspace', 'Chat Images', agent_id, prompt, numGenerations, uid, conversation_doc.account_profile_info.app_id, job_id, headers, null, null, account_profile_info);
4848
+ const images_arr = await create_and_upload_image_to_drive('workspace', 'Chat Images', agent_id, prompt, numGenerations, uid, account_profile_info.app_id, job_id, headers, null, null, account_profile_info);
4846
4849
  for (const img_obj of images_arr) {
4847
4850
  imgTags += `<img src="${img_obj.file_url}" alt="${prompt}" style="max-width: 100%; border-radius: 8px;" />`;
4848
4851
  }
@@ -5029,9 +5032,9 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5029
5032
 
5030
5033
  const set_ts_to_agent = async function () {
5031
5034
  try {
5032
- let agent_doc = await db_module.get_app_couch_doc_native(conversation_doc.account_profile_info.app_id, reference_id);
5035
+ let agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, reference_id);
5033
5036
  agent_doc.ts = Date.now();
5034
- await db_module.save_app_couch_doc_native(conversation_doc.account_profile_info.app_id, agent_doc);
5037
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
5035
5038
  } catch (err) {}
5036
5039
  };
5037
5040
 
@@ -5077,7 +5080,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5077
5080
  const done = async function (output) {
5078
5081
  try {
5079
5082
  const obj = { id: output?.output?.[0]?.id, ts: Date.now(), ai_agent_id: output.state._currentAgent.name, attachments };
5080
- conversation_doc = await db_module.get_app_couch_doc_native(conversation_doc.account_profile_info.app_id, conversation_id);
5083
+ conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
5081
5084
 
5082
5085
  conversation_doc.ts = Date.now();
5083
5086
  conversation_doc.stat = 3;
@@ -5091,7 +5094,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5091
5094
  outputTokens += item.usage.outputTokens;
5092
5095
  }
5093
5096
 
5094
- await db_module.save_app_couch_doc_native(conversation_doc.account_profile_info.app_id, conversation_doc);
5097
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
5095
5098
  record_chat_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: obj.ai_agent_id, item_id: obj.id });
5096
5099
  // if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
5097
5100
  // update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4209",
3
+ "version": "1.1.4211",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",