@xuda.io/ai_module 1.1.4996 → 1.1.4998
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 +15 -14
- package/index_msa.mjs +202 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -69,6 +69,7 @@ const team_ms = await import(`${module_path}/team_module/index_ms.mjs`);
|
|
|
69
69
|
const email_ms = await import(`${module_path}/email_module/index_ms.mjs`);
|
|
70
70
|
|
|
71
71
|
const ws_dashboard_msa = await import(`${module_path}/ws_dashboard_module/index_msa.mjs`);
|
|
72
|
+
const account_msa = await import(`${module_path}/account_module/index_msa.mjs`);
|
|
72
73
|
|
|
73
74
|
var open_ai_status = {};
|
|
74
75
|
const report_ai_status = function (model, err) {
|
|
@@ -1524,7 +1525,7 @@ const create_image = async function (uid, prompt, model = 'gpt-image-1-mini', si
|
|
|
1524
1525
|
|
|
1525
1526
|
const thumbnailBase64 = resized.toString('base64');
|
|
1526
1527
|
|
|
1527
|
-
|
|
1528
|
+
account_msa.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'create image', prompt, model, metadata, account_profile_info);
|
|
1528
1529
|
|
|
1529
1530
|
return thumbnailBase64;
|
|
1530
1531
|
} catch (err) {
|
|
@@ -2886,7 +2887,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
|
|
|
2886
2887
|
images_arr = [cache];
|
|
2887
2888
|
if (!cache) {
|
|
2888
2889
|
images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
|
|
2889
|
-
|
|
2890
|
+
account_msa.save_xuda_cache(uid, 'chat_thumbnail', doc.title, images_arr[0], { tags });
|
|
2890
2891
|
}
|
|
2891
2892
|
db_doc = await get_db_doc();
|
|
2892
2893
|
db_doc.thumbnail_request_ts = Date.now();
|
|
@@ -2905,7 +2906,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
|
|
|
2905
2906
|
images_arr = [cache];
|
|
2906
2907
|
if (!cache) {
|
|
2907
2908
|
images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
|
|
2908
|
-
|
|
2909
|
+
account_msa.save_xuda_cache(uid, 'chat_thumbnail', doc.category_info.category, images_arr[0], { tags });
|
|
2909
2910
|
}
|
|
2910
2911
|
db_doc = await get_db_doc();
|
|
2911
2912
|
db_doc.thumbnail_request_ts = Date.now();
|
|
@@ -3043,7 +3044,7 @@ const transcribe = async function (uid, stream, metadata, account_profile_info)
|
|
|
3043
3044
|
// temperature: 0 // lower = more literal
|
|
3044
3045
|
});
|
|
3045
3046
|
report_ai_status(model);
|
|
3046
|
-
|
|
3047
|
+
account_msa.record_ai_usage(uid, 0, resp.length || 0, 'transcribe', '', model, metadata, account_profile_info);
|
|
3047
3048
|
// console.log(resp); // or resp for JSON formats
|
|
3048
3049
|
return resp;
|
|
3049
3050
|
} catch (err) {
|
|
@@ -3363,7 +3364,7 @@ export const submit_chat_gpt_prompt = async function (req) {
|
|
|
3363
3364
|
report_ai_status(model, err);
|
|
3364
3365
|
throw err;
|
|
3365
3366
|
}
|
|
3366
|
-
|
|
3367
|
+
account_msa.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'submit chat', prompt, model, metadata, account_profile_info, tools);
|
|
3367
3368
|
return { code: 5, data: response.output_text };
|
|
3368
3369
|
} catch (err) {
|
|
3369
3370
|
return { code: -5, data: err.message };
|
|
@@ -3604,7 +3605,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
|
|
|
3604
3605
|
if (conversation_doc.reference_type === 'contacts') {
|
|
3605
3606
|
req._thread_reentry = Date.now() - conversation_doc.date_created_ts > 60000;
|
|
3606
3607
|
|
|
3607
|
-
|
|
3608
|
+
account_msa.ts_contact(uid, conversation_doc.reference_id);
|
|
3608
3609
|
|
|
3609
3610
|
switch (conversation_doc.conversation_type) {
|
|
3610
3611
|
case 'note': {
|
|
@@ -4635,7 +4636,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
4635
4636
|
out_conversation_item_doc.conversation_item_reference_id = conversation_items?.data?.[0]?.id;
|
|
4636
4637
|
await db_module.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_doc);
|
|
4637
4638
|
|
|
4638
|
-
|
|
4639
|
+
account_msa.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);
|
|
4639
4640
|
// if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
|
|
4640
4641
|
// update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
|
|
4641
4642
|
// }
|
|
@@ -5212,7 +5213,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5212
5213
|
throw err;
|
|
5213
5214
|
}
|
|
5214
5215
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5215
|
-
|
|
5216
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5216
5217
|
} else {
|
|
5217
5218
|
imageBase64 = Buffer.from(await image_blob_ret.image_blob.arrayBuffer()).toString('base64');
|
|
5218
5219
|
if (account_type === 'business') {
|
|
@@ -5304,7 +5305,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5304
5305
|
// The background should be fully removed, remove trees,clouds,sky or any landscape objects`,
|
|
5305
5306
|
// background: 'transparent',
|
|
5306
5307
|
// });
|
|
5307
|
-
//
|
|
5308
|
+
// account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5308
5309
|
// imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5309
5310
|
if (is_user) {
|
|
5310
5311
|
if (business_has_person) {
|
|
@@ -5331,7 +5332,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5331
5332
|
report_ai_status(model, err);
|
|
5332
5333
|
throw err;
|
|
5333
5334
|
}
|
|
5334
|
-
|
|
5335
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5335
5336
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5336
5337
|
}
|
|
5337
5338
|
} else {
|
|
@@ -5403,7 +5404,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5403
5404
|
report_ai_status(model, err);
|
|
5404
5405
|
throw err;
|
|
5405
5406
|
}
|
|
5406
|
-
|
|
5407
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5407
5408
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5408
5409
|
avatar_source = 'ai profile';
|
|
5409
5410
|
};
|
|
@@ -5626,7 +5627,7 @@ export const get_profile_picture = async function (uid, account_type = 'business
|
|
|
5626
5627
|
}
|
|
5627
5628
|
|
|
5628
5629
|
imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json, resize);
|
|
5629
|
-
|
|
5630
|
+
account_msa.record_ai_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'profile image', prompt, model, { url }, account_profile_info);
|
|
5630
5631
|
}
|
|
5631
5632
|
|
|
5632
5633
|
const outputBuffer = Buffer.from(imageBase64, 'base64');
|
|
@@ -5942,7 +5943,7 @@ const create_ai_agent_image = async function (req, job_id, headers) {
|
|
|
5942
5943
|
throw err;
|
|
5943
5944
|
}
|
|
5944
5945
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5945
|
-
|
|
5946
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'agent avatar', prompt, model, { ai_agent_id }, account_profile_info);
|
|
5946
5947
|
console.log('Normalizing final avatar to 1024 with transparent padding...');
|
|
5947
5948
|
imageBase64 = await normalizeBase64To1024(imageBase64);
|
|
5948
5949
|
|
|
@@ -6614,7 +6615,7 @@ const get_chat_picture_cache = async function (uid, docType, key) {
|
|
|
6614
6615
|
const ret = await db_module.find_couch_query('xuda_cache', query);
|
|
6615
6616
|
|
|
6616
6617
|
if (ret.docs.length > 0) {
|
|
6617
|
-
|
|
6618
|
+
account_msa.save_cache_hit(ret.docs[0]._id);
|
|
6618
6619
|
return ret.docs[0].file;
|
|
6619
6620
|
}
|
|
6620
6621
|
}
|
package/index_msa.mjs
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// =====================================================
|
|
2
|
+
// Queue wrapper – generated from index.mjs
|
|
3
|
+
// Queue target : ai_module
|
|
4
|
+
// =====================================================
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
const { MessageBroker } = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
|
|
10
|
+
|
|
11
|
+
const broker = new MessageBroker();
|
|
12
|
+
|
|
13
|
+
await broker.init({
|
|
14
|
+
queueName: 'ai_module',
|
|
15
|
+
module_in: global.module_in
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export const get_chat_conversation = function (...args) {
|
|
21
|
+
broker.send_to_queue_async("get_chat_conversation", ...args);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const get_ai_chats = function (...args) {
|
|
25
|
+
broker.send_to_queue_async("get_ai_chats", ...args);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const delete_ai_chat = function (...args) {
|
|
29
|
+
broker.send_to_queue_async("delete_ai_chat", ...args);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const archive_ai_chat = function (...args) {
|
|
33
|
+
broker.send_to_queue_async("archive_ai_chat", ...args);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const unarchive_ai_chat = function (...args) {
|
|
37
|
+
broker.send_to_queue_async("unarchive_ai_chat", ...args);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const get_ai_agent_info = function (...args) {
|
|
41
|
+
broker.send_to_queue_async("get_ai_agent_info", ...args);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const get_ai_agents = function (...args) {
|
|
45
|
+
broker.send_to_queue_async("get_ai_agents", ...args);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const delete_ai_agent = function (...args) {
|
|
49
|
+
broker.send_to_queue_async("delete_ai_agent", ...args);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const uninstall_ai_agent = function (...args) {
|
|
53
|
+
broker.send_to_queue_async("uninstall_ai_agent", ...args);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const unarchive_ai_agent = function (...args) {
|
|
57
|
+
broker.send_to_queue_async("unarchive_ai_agent", ...args);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const archive_ai_agent = function (...args) {
|
|
61
|
+
broker.send_to_queue_async("archive_ai_agent", ...args);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const archive_mini_app = function (...args) {
|
|
65
|
+
broker.send_to_queue_async("archive_mini_app", ...args);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const unarchive_mini_app = function (...args) {
|
|
69
|
+
broker.send_to_queue_async("unarchive_mini_app", ...args);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const delete_mini_app = function (...args) {
|
|
73
|
+
broker.send_to_queue_async("delete_mini_app", ...args);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const update_ai_agent = function (...args) {
|
|
77
|
+
broker.send_to_queue_async("update_ai_agent", ...args);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const get_apps = function (...args) {
|
|
81
|
+
broker.send_to_queue_async("get_apps", ...args);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const create_ai_agent = function (...args) {
|
|
85
|
+
broker.send_to_queue_async("create_ai_agent", ...args);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const update_ai_agent_properties = function (...args) {
|
|
89
|
+
broker.send_to_queue_async("update_ai_agent_properties", ...args);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const update_thumbnail = function (...args) {
|
|
93
|
+
broker.send_to_queue_async("update_thumbnail", ...args);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const upload_prompt_attachment = function (...args) {
|
|
97
|
+
broker.send_to_queue_async("upload_prompt_attachment", ...args);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const delete_prompt_attachment = function (...args) {
|
|
101
|
+
broker.send_to_queue_async("delete_prompt_attachment", ...args);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const submit_chat_gpt_prompt = function (...args) {
|
|
105
|
+
broker.send_to_queue_async("submit_chat_gpt_prompt", ...args);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const create_conversation = function (...args) {
|
|
109
|
+
broker.send_to_queue_async("create_conversation", ...args);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const submit_chat_conversation = function (...args) {
|
|
113
|
+
broker.send_to_queue_async("submit_chat_conversation", ...args);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const create_avatar = function (...args) {
|
|
117
|
+
broker.send_to_queue_async("create_avatar", ...args);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const get_profile_avatar = function (...args) {
|
|
121
|
+
broker.send_to_queue_async("get_profile_avatar", ...args);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const get_profile_picture = function (...args) {
|
|
125
|
+
broker.send_to_queue_async("get_profile_picture", ...args);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const conversation_actions = function (...args) {
|
|
129
|
+
broker.send_to_queue_async("conversation_actions", ...args);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const modify_profile_avatar = function (...args) {
|
|
133
|
+
broker.send_to_queue_async("modify_profile_avatar", ...args);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const get_ai_workspace_pending_counts = function (...args) {
|
|
137
|
+
broker.send_to_queue_async("get_ai_workspace_pending_counts", ...args);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const create_mini_app = function (...args) {
|
|
141
|
+
broker.send_to_queue_async("create_mini_app", ...args);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const pin_ai_agent = function (...args) {
|
|
145
|
+
broker.send_to_queue_async("pin_ai_agent", ...args);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const unpin_ai_agent = function (...args) {
|
|
149
|
+
broker.send_to_queue_async("unpin_ai_agent", ...args);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const get_transcript = function (...args) {
|
|
153
|
+
broker.send_to_queue_async("get_transcript", ...args);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const add_transcript_conversation_item = function (...args) {
|
|
157
|
+
broker.send_to_queue_async("add_transcript_conversation_item", ...args);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const is_spam_email = function (...args) {
|
|
161
|
+
broker.send_to_queue_async("is_spam_email", ...args);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const is_business_contact = function (...args) {
|
|
165
|
+
broker.send_to_queue_async("is_business_contact", ...args);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const is_business_contact_has_person = function (...args) {
|
|
169
|
+
broker.send_to_queue_async("is_business_contact_has_person", ...args);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const get_name_from_email_addr = function (...args) {
|
|
173
|
+
broker.send_to_queue_async("get_name_from_email_addr", ...args);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const categorize_email_subject = function (...args) {
|
|
177
|
+
broker.send_to_queue_async("categorize_email_subject", ...args);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export const categorize_ai_prompt = function (...args) {
|
|
181
|
+
broker.send_to_queue_async("categorize_ai_prompt", ...args);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const categorize_text_message = function (...args) {
|
|
185
|
+
broker.send_to_queue_async("categorize_text_message", ...args);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export const categorize_contact_note = function (...args) {
|
|
189
|
+
broker.send_to_queue_async("categorize_contact_note", ...args);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const get_business_info = function (...args) {
|
|
193
|
+
broker.send_to_queue_async("get_business_info", ...args);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const get_person_info = function (...args) {
|
|
197
|
+
broker.send_to_queue_async("get_person_info", ...args);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const open_ai_alive_check = function (...args) {
|
|
201
|
+
broker.send_to_queue_async("open_ai_alive_check", ...args);
|
|
202
|
+
};
|