@xuda.io/ai_module 1.1.5493 → 1.1.5495

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -4117,21 +4117,6 @@ const chat_email = async function (req, job_id, headers) {
4117
4117
  return { code: -15, data: err.message };
4118
4118
  }
4119
4119
  };
4120
-
4121
- const auto_response = async function (uid, profile_id, conversation_id) {
4122
- const account_profile_info = await get_active_account_profile_info(uid, profile_id);
4123
-
4124
- const account_profile_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, profile_id);
4125
- if (!account_profile_doc.auto_respond_mode) return;
4126
-
4127
- let account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
4128
-
4129
- if (account_profile_doc.auto_respond_mode === 'when_offline' && account_doc.socket_id) return;
4130
- if (account_profile_doc.auto_respond_mode !== 'always') return;
4131
-
4132
- ///
4133
- };
4134
-
4135
4120
  const ai_chat_conversation = async function (req, job_id, headers) {
4136
4121
  const { uid, gtp_token, profile_id, conversation_item_id } = req;
4137
4122
  const account_profile_info = await get_active_account_profile_info(uid, profile_id);
@@ -5127,6 +5112,82 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5127
5112
  }
5128
5113
  };
5129
5114
 
5115
+ const add_conversation_item = async function (uid, profile_id, text, conversation_type, contact_id, metadata = {}) {
5116
+ const { uid, profile_id } = req;
5117
+ const account_profile_info = await get_active_account_profile_info(uid, profile_id);
5118
+ let { prompt: body, conversation_doc, attachments = [], ai_agents } = req;
5119
+ try {
5120
+ const conversation_id = conversation_doc._id;
5121
+
5122
+ const sender_app_id = account_profile_info.app_id; //await get_account_default_project_id(uid);
5123
+ let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
5124
+
5125
+ await attachment_handler(uid, sender_app_id, conversation_id, attachments, account_profile_info);
5126
+ let item;
5127
+ try {
5128
+ item = await client.conversations.items.create(conversation_doc.reference_conversation_id, {
5129
+ items: [
5130
+ {
5131
+ type: 'message',
5132
+ role: 'user',
5133
+ content: [{ type: 'input_text', text: body }],
5134
+ },
5135
+ ],
5136
+ });
5137
+ report_ai_status('conversations');
5138
+ } catch (err) {
5139
+ report_ai_status('conversations', err);
5140
+ throw err;
5141
+ }
5142
+
5143
+ // let obj = { id: item.data[0].id, ts: Date.now(), uid, read: true, conversation_type: 'note' };
5144
+
5145
+ // sender_conversation_doc.messages.push(obj);
5146
+ // await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
5147
+
5148
+ let out_conversation_item_obj = {
5149
+ _id: await _common.xuda_get_uuid('chat_conversation_item'),
5150
+ stat: 3,
5151
+ docType: 'chat_conversation_item',
5152
+ uid,
5153
+ conversation_type: 'note',
5154
+ type: 'note',
5155
+ date_created_ts: Date.now(),
5156
+ ts: Date.now(),
5157
+ conversation_id,
5158
+ text: body,
5159
+ reference_id: conversation_doc.reference_id,
5160
+ conversation_item_reference_id: item.data[0].id,
5161
+ direction: 'out',
5162
+ role: 'user',
5163
+ read: { [uid]: Date.now() },
5164
+ rtl: _common.detectRTL(body),
5165
+ };
5166
+
5167
+ const save_ret = await db_module.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
5168
+
5169
+ // 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 });
5170
+
5171
+ return save_ret; //{ code: 15, data: item };
5172
+ } catch (err) {
5173
+ return { code: -15, data: err.message };
5174
+ }
5175
+ };
5176
+
5177
+ const auto_response = async function (uid, profile_id, conversation_id) {
5178
+ const account_profile_info = await get_active_account_profile_info(uid, profile_id);
5179
+
5180
+ const account_profile_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, profile_id);
5181
+ if (!account_profile_doc.auto_respond_mode) return;
5182
+
5183
+ let account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
5184
+
5185
+ if (account_profile_doc.auto_respond_mode === 'when_offline' && account_doc.socket_id) return;
5186
+ if (account_profile_doc.auto_respond_mode !== 'always') return;
5187
+
5188
+ ///
5189
+ };
5190
+
5130
5191
  setTimeout(async () => {
5131
5192
  const app_id = 'prj712ffdf5aa8adce6cedef988f9c12392'; //'prj3937cb6f9a31c8c7dea25055bba845b1'; //
5132
5193
  const uid = 'd39126e0e2c51ffbd1aad10709fc8335';
package/index_ms.mjs CHANGED
@@ -109,6 +109,10 @@ export const submit_chat_gpt_prompt = async function (...args) {
109
109
  return await broker.send_to_queue("submit_chat_gpt_prompt", ...args);
110
110
  };
111
111
 
112
+ export const create_openai_conversation = async function (...args) {
113
+ return await broker.send_to_queue("create_openai_conversation", ...args);
114
+ };
115
+
112
116
  export const create_conversation = async function (...args) {
113
117
  return await broker.send_to_queue("create_conversation", ...args);
114
118
  };
package/index_msa.mjs CHANGED
@@ -109,6 +109,10 @@ export const submit_chat_gpt_prompt = function (...args) {
109
109
  broker.send_to_queue_async("submit_chat_gpt_prompt", ...args);
110
110
  };
111
111
 
112
+ export const create_openai_conversation = function (...args) {
113
+ broker.send_to_queue_async("create_openai_conversation", ...args);
114
+ };
115
+
112
116
  export const create_conversation = function (...args) {
113
117
  broker.send_to_queue_async("create_conversation", ...args);
114
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5493",
3
+ "version": "1.1.5495",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",