@xuda.io/ai_module 1.1.4606 → 1.1.4608
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 +56 -8
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4351,11 +4351,10 @@ const contact_chat_conversation = async function (req, job_id, headers) {
|
|
|
4351
4351
|
let receiver_conversation_doc = await db_module.get_app_couch_doc_native(receiver_app_id, conversation_id);
|
|
4352
4352
|
|
|
4353
4353
|
const sender_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
|
|
4354
|
-
// const sender_app_id = await account_module.get_account_default_project_id(uid);
|
|
4355
4354
|
const sender_app_id = account_profile_info.app_id;
|
|
4356
4355
|
let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
|
|
4357
4356
|
|
|
4358
|
-
const item = await client.conversations.items.create(
|
|
4357
|
+
const item = await client.conversations.items.create(conversation_doc.reference_conversation_id, {
|
|
4359
4358
|
items: [
|
|
4360
4359
|
{
|
|
4361
4360
|
type: 'message',
|
|
@@ -4365,12 +4364,33 @@ const contact_chat_conversation = async function (req, job_id, headers) {
|
|
|
4365
4364
|
],
|
|
4366
4365
|
});
|
|
4367
4366
|
|
|
4368
|
-
const obj = { id: item.data[0].id, ts: Date.now(), uid, read: true, conversation_type: 'chat' };
|
|
4369
|
-
receiver_conversation_doc.messages.push(obj);
|
|
4367
|
+
// const obj = { id: item.data[0].id, ts: Date.now(), uid, read: true, conversation_type: 'chat' };
|
|
4368
|
+
// receiver_conversation_doc.messages.push(obj);
|
|
4369
|
+
|
|
4370
4370
|
await db_module.save_app_couch_doc_native(receiver_app_id, receiver_conversation_doc);
|
|
4371
|
-
sender_conversation_doc.messages.push({ ...obj, ...{ read: false } });
|
|
4371
|
+
// sender_conversation_doc.messages.push({ ...obj, ...{ read: false } });
|
|
4372
|
+
|
|
4372
4373
|
await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
|
|
4373
4374
|
|
|
4375
|
+
let out_conversation_item_obj = {
|
|
4376
|
+
_id: await _common.xuda_get_uuid('chat_conversation_item'),
|
|
4377
|
+
stat: 3,
|
|
4378
|
+
docType: 'chat_conversation_item',
|
|
4379
|
+
uid,
|
|
4380
|
+
conversation_type: 'note',
|
|
4381
|
+
type: 'note',
|
|
4382
|
+
date_created_ts: Date.now(),
|
|
4383
|
+
ts: Date.now(),
|
|
4384
|
+
conversation_id,
|
|
4385
|
+
text: body,
|
|
4386
|
+
reference_id: conversation_doc.reference_id,
|
|
4387
|
+
conversation_item_reference_id: item.data[0].id,
|
|
4388
|
+
direction: 'out',
|
|
4389
|
+
role: 'user',
|
|
4390
|
+
};
|
|
4391
|
+
|
|
4392
|
+
const save_ret = await db_module.save_app_couch_doc(sender_app_id, out_conversation_item_obj);
|
|
4393
|
+
|
|
4374
4394
|
update_conversation_mood_level(uid, conversation_id, prompt, uid, receiver_contact_doc.contact_uid, conversation_doc.reference_type === 'contacts', account_profile_info);
|
|
4375
4395
|
|
|
4376
4396
|
return { code: 15, data: item };
|
|
@@ -6954,11 +6974,13 @@ export const get_business_info = async function (uid, name, email, account_profi
|
|
|
6954
6974
|
const business_info_ret = await submit_chat_gpt_prompt({
|
|
6955
6975
|
uid,
|
|
6956
6976
|
prompt: `Research the company: "${name}" (${email}).
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6977
|
+
1. get the company name.
|
|
6978
|
+
2. Provide a professional one-sentence biography of the company.
|
|
6979
|
+
3. Categorize them using the provided industry lists.
|
|
6980
|
+
4. Identify their primary country as a 2-letter ISO code (e.g., 'US').`,
|
|
6960
6981
|
model: 'gpt-5-nano',
|
|
6961
6982
|
response_format: z.object({
|
|
6983
|
+
business_name: z.string().describe('the company name'),
|
|
6962
6984
|
business_bio: z.string().describe('A concise, professional one-sentence summary of what the business does'),
|
|
6963
6985
|
business_size: z.enum(['unknown', 'small', 'medium', 'large', 'enterprise']),
|
|
6964
6986
|
business_category: z.enum(categoryNames),
|
|
@@ -7070,3 +7092,29 @@ const save_drive_file_to_disk = async function (drive_file) {
|
|
|
7070
7092
|
contentType: validation_ret.mime,
|
|
7071
7093
|
};
|
|
7072
7094
|
};
|
|
7095
|
+
|
|
7096
|
+
export const get_name_from_email_addr = async function (uid, email, account_profile_info) {
|
|
7097
|
+
const name_ret = await submit_chat_gpt_prompt({
|
|
7098
|
+
uid,
|
|
7099
|
+
prompt: `
|
|
7100
|
+
extract name from the email address: "${email}" return clean name result.
|
|
7101
|
+
`,
|
|
7102
|
+
model: 'gpt-5-nano',
|
|
7103
|
+
response_format: z.object({
|
|
7104
|
+
name: z.string().describe('name from email'),
|
|
7105
|
+
}),
|
|
7106
|
+
metadata: { func: 'get_name_from_email_addr' },
|
|
7107
|
+
account_profile_info,
|
|
7108
|
+
// tools: [{ type: 'web_search_preview' }],
|
|
7109
|
+
});
|
|
7110
|
+
|
|
7111
|
+
try {
|
|
7112
|
+
if (name_ret.code > -1) {
|
|
7113
|
+
const data = typeof name_ret.data === 'string' ? JSON.parse(name_ret.data) : name_ret.data;
|
|
7114
|
+
|
|
7115
|
+
return data;
|
|
7116
|
+
}
|
|
7117
|
+
} catch (error) {
|
|
7118
|
+
console.error('Error in get_name_from_email_addr:', error);
|
|
7119
|
+
}
|
|
7120
|
+
};
|