@xuda.io/ai_module 1.1.4651 → 1.1.4653
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 +162 -71
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4205,84 +4205,89 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4205
4205
|
const save_ret = await db_module.save_app_couch_doc(app_id, { ...conversation_doc, ...{ uid: recipient_uid, reference_id: recipient_contact_id } });
|
|
4206
4206
|
}
|
|
4207
4207
|
|
|
4208
|
-
setTimeout(async () => {
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4208
|
+
// setTimeout(async () => {
|
|
4209
|
+
// // Ask GPT for title
|
|
4210
|
+
// if (conversation_type !== 'email') {
|
|
4211
|
+
// if (prompt.split(' ').length > 10) {
|
|
4212
|
+
// 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: 'gpt-5-nano', metadata: { conversation_id: conversation_doc._id, func: 'create_conversation' }, account_profile_info });
|
|
4213
4213
|
|
|
4214
|
-
|
|
4215
|
-
|
|
4214
|
+
// conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4215
|
+
// conversation_doc.title = title.data;
|
|
4216
4216
|
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4217
|
+
// await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
4218
|
+
// }
|
|
4219
|
+
// }
|
|
4220
|
+
// /// categorize prompt
|
|
4221
|
+
// let category_info = {};
|
|
4222
|
+
// switch (conversation_type) {
|
|
4223
|
+
// case 'ai': {
|
|
4224
|
+
// category_info = await categorize_ai_prompt(uid, prompt, account_profile_info);
|
|
4225
|
+
// break;
|
|
4226
|
+
// }
|
|
4227
4227
|
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4228
|
+
// case 'email': {
|
|
4229
|
+
// category_info = await categorize_email_subject(uid, prompt, account_profile_info);
|
|
4230
|
+
// break;
|
|
4231
|
+
// }
|
|
4232
4232
|
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4233
|
+
// case 'chat': {
|
|
4234
|
+
// category_info = await categorize_text_message(uid, prompt, account_profile_info);
|
|
4235
|
+
// break;
|
|
4236
|
+
// }
|
|
4237
4237
|
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4238
|
+
// case 'note': {
|
|
4239
|
+
// category_info = await categorize_contact_note(uid, prompt, account_profile_info);
|
|
4240
|
+
// break;
|
|
4241
|
+
// }
|
|
4241
4242
|
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4243
|
+
// default:
|
|
4244
|
+
// break;
|
|
4245
|
+
// }
|
|
4245
4246
|
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
},
|
|
4247
|
+
// conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4248
|
+
// contact_doc.category_info = category_info;
|
|
4249
|
+
// await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
4250
|
+
|
|
4251
|
+
// if (perform_ai_execution) {
|
|
4252
|
+
// // await update_thumbnail('conversation', conversation_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
|
|
4253
|
+
// }
|
|
4254
|
+
// if (conversation_doc.reference_type === 'contacts') {
|
|
4255
|
+
// if (recipient_uid) {
|
|
4256
|
+
// // valid for chat conversation
|
|
4257
|
+
// // write conversation to host after thumbnail update
|
|
4258
|
+
// // get sender conversation
|
|
4259
|
+
|
|
4260
|
+
// const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4261
|
+
|
|
4262
|
+
// const recipient_account_profile_info = await ac3180count_module.get_active_account_profile_info(recipient_uid);
|
|
4263
|
+
// let recipient_conversation_doc = await db_module.get_app_couch_doc_native(recipient_account_profile_info.app_id, conversation_doc._id);
|
|
4264
|
+
// recipient_conversation_doc.title = conversation_doc.title;
|
|
4265
|
+
|
|
4266
|
+
// recipient_conversation_doc.thumbnail_request_ts = conversation_doc.thumbnail_request_ts;
|
|
4267
|
+
// recipient_conversation_doc.chat_image = conversation_doc.chat_image;
|
|
4268
|
+
// await db_module.save_app_couch_doc_native(recipient_account_profile_info.app_id, recipient_conversation_doc);
|
|
4269
|
+
|
|
4270
|
+
// await update_conversation_mood_level(
|
|
4271
|
+
// uid,
|
|
4272
|
+
// [
|
|
4273
|
+
// { uid: account_profile_info.uid, contact_id: reference_id },
|
|
4274
|
+
// { uid: recipient_uid, contact_id: recipient_contact_id },
|
|
4275
|
+
// ],
|
|
4276
|
+
// conversation_doc._id,
|
|
4277
|
+
// prompt,
|
|
4278
|
+
// uid,
|
|
4279
|
+
// recipient_uid,
|
|
4280
|
+
// true,
|
|
4281
|
+
// account_profile_info,
|
|
4282
|
+
// );
|
|
4283
|
+
// } else {
|
|
4284
|
+
// // other cases rather then chat
|
|
4285
|
+
// if (perform_ai_execution) {
|
|
4286
|
+
// await update_conversation_mood_level(uid, [{ uid: account_profile_info.uid, contact_id: reference_id }], conversation_doc._id, prompt, null, contact_id, conversation_doc.reference_type === 'contacts', account_profile_info);
|
|
4287
|
+
// }
|
|
4288
|
+
// }
|
|
4289
|
+
// }
|
|
4290
|
+
// }, 1000);
|
|
4286
4291
|
|
|
4287
4292
|
return save_ret;
|
|
4288
4293
|
} catch (err) {
|
|
@@ -4292,6 +4297,92 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4292
4297
|
}
|
|
4293
4298
|
};
|
|
4294
4299
|
|
|
4300
|
+
const process_conversation = async function (uid, conversation_id, account_profile_info, job_id, headers) {
|
|
4301
|
+
let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
4302
|
+
|
|
4303
|
+
// Ask GPT for title
|
|
4304
|
+
if (conversation_type !== 'email') {
|
|
4305
|
+
if (prompt.split(' ').length > 10) {
|
|
4306
|
+
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: 'gpt-5-nano', metadata: { conversation_id: conversation_doc._id, func: 'create_conversation' }, account_profile_info });
|
|
4307
|
+
|
|
4308
|
+
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4309
|
+
conversation_doc.title = title.data;
|
|
4310
|
+
|
|
4311
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
/// categorize prompt
|
|
4315
|
+
let category_info = {};
|
|
4316
|
+
switch (conversation_type) {
|
|
4317
|
+
case 'ai': {
|
|
4318
|
+
category_info = await categorize_ai_prompt(uid, prompt, account_profile_info);
|
|
4319
|
+
break;
|
|
4320
|
+
}
|
|
4321
|
+
|
|
4322
|
+
case 'email': {
|
|
4323
|
+
category_info = await categorize_email_subject(uid, prompt, account_profile_info);
|
|
4324
|
+
break;
|
|
4325
|
+
}
|
|
4326
|
+
|
|
4327
|
+
case 'chat': {
|
|
4328
|
+
category_info = await categorize_text_message(uid, prompt, account_profile_info);
|
|
4329
|
+
break;
|
|
4330
|
+
}
|
|
4331
|
+
|
|
4332
|
+
case 'note': {
|
|
4333
|
+
category_info = await categorize_contact_note(uid, prompt, account_profile_info);
|
|
4334
|
+
break;
|
|
4335
|
+
}
|
|
4336
|
+
|
|
4337
|
+
default:
|
|
4338
|
+
break;
|
|
4339
|
+
}
|
|
4340
|
+
|
|
4341
|
+
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4342
|
+
contact_doc.category_info = category_info;
|
|
4343
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
4344
|
+
|
|
4345
|
+
if (perform_ai_execution) {
|
|
4346
|
+
// await update_thumbnail('conversation', conversation_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
|
|
4347
|
+
}
|
|
4348
|
+
if (conversation_doc.reference_type === 'contacts') {
|
|
4349
|
+
if (recipient_uid) {
|
|
4350
|
+
// valid for chat conversation
|
|
4351
|
+
// write conversation to host after thumbnail update
|
|
4352
|
+
// get sender conversation
|
|
4353
|
+
|
|
4354
|
+
const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4355
|
+
|
|
4356
|
+
const recipient_account_profile_info = await ac3180count_module.get_active_account_profile_info(recipient_uid);
|
|
4357
|
+
let recipient_conversation_doc = await db_module.get_app_couch_doc_native(recipient_account_profile_info.app_id, conversation_doc._id);
|
|
4358
|
+
recipient_conversation_doc.title = conversation_doc.title;
|
|
4359
|
+
|
|
4360
|
+
recipient_conversation_doc.thumbnail_request_ts = conversation_doc.thumbnail_request_ts;
|
|
4361
|
+
recipient_conversation_doc.chat_image = conversation_doc.chat_image;
|
|
4362
|
+
await db_module.save_app_couch_doc_native(recipient_account_profile_info.app_id, recipient_conversation_doc);
|
|
4363
|
+
|
|
4364
|
+
await update_conversation_mood_level(
|
|
4365
|
+
uid,
|
|
4366
|
+
[
|
|
4367
|
+
{ uid: account_profile_info.uid, contact_id: reference_id },
|
|
4368
|
+
{ uid: recipient_uid, contact_id: recipient_contact_id },
|
|
4369
|
+
],
|
|
4370
|
+
conversation_doc._id,
|
|
4371
|
+
prompt,
|
|
4372
|
+
uid,
|
|
4373
|
+
recipient_uid,
|
|
4374
|
+
true,
|
|
4375
|
+
account_profile_info,
|
|
4376
|
+
);
|
|
4377
|
+
} else {
|
|
4378
|
+
// other cases rather then chat
|
|
4379
|
+
if (perform_ai_execution) {
|
|
4380
|
+
await update_conversation_mood_level(uid, [{ uid: account_profile_info.uid, contact_id: reference_id }], conversation_doc._id, prompt, null, contact_id, conversation_doc.reference_type === 'contacts', account_profile_info);
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
};
|
|
4385
|
+
|
|
4295
4386
|
const contactGuardrailAgent = new Agent({
|
|
4296
4387
|
name: 'Person Guardrail check',
|
|
4297
4388
|
instructions: 'Check if the prompt about person.',
|