@xuda.io/ai_module 1.1.4925 → 1.1.4927
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_ms.mjs +50 -127
- package/package.json +1 -1
package/index_ms.mjs
CHANGED
|
@@ -3,268 +3,191 @@
|
|
|
3
3
|
// Queue target : ai_module
|
|
4
4
|
// =====================================================
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// --- AMQP Connection & Channel ---
|
|
12
|
-
const conn = await amqplib.connect('amqp://localhost');
|
|
13
|
-
const channel = await conn.createChannel();
|
|
14
|
-
await channel.assertQueue(`_ai_module-${global.module_in}_ch`, { durable: false });
|
|
15
|
-
|
|
16
|
-
channel.consume(`_ai_module-${global.module_in}_ch`, async (msg) => {
|
|
17
|
-
try{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (msg === null) {
|
|
21
|
-
console.log('Consumer cancelled by server');
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const content = JSON.parse(msg.content.toString());
|
|
26
|
-
|
|
27
|
-
queue[content.queue_id].resolve(content.ret)
|
|
28
|
-
|
|
29
|
-
channel.ack(msg);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
channel.ack(msg); // Acknowledge to prevent requeue loops on error
|
|
32
|
-
console.error(module_in, content.method, err.message, err);
|
|
33
|
-
// debugger;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const send_to_queue =async function(ms_method, ...args) {
|
|
39
|
-
|
|
40
|
-
const queue_id = randomUUID();
|
|
41
|
-
return new Promise((resolve,reject)=>{
|
|
42
|
-
|
|
43
|
-
queue[queue_id] = { resolve, reject };
|
|
44
|
-
|
|
45
|
-
// Set timeout to prevent hanging
|
|
46
|
-
const timeout = setTimeout(() => {
|
|
47
|
-
delete queue[queue_id];
|
|
48
|
-
reject(new Error(`Queue timeout for ${ms_method}`));
|
|
49
|
-
}, 300000); // 300 second timeout
|
|
50
|
-
|
|
51
|
-
// Wrap resolve to clean up
|
|
52
|
-
queue[queue_id].resolve = (value) => {
|
|
53
|
-
clearTimeout(timeout);
|
|
54
|
-
delete queue[queue_id];
|
|
55
|
-
resolve(value);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Wrap reject to clean up
|
|
59
|
-
queue[queue_id].reject = (error) => {
|
|
60
|
-
clearTimeout(timeout);
|
|
61
|
-
delete queue[queue_id];
|
|
62
|
-
reject(error);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
try{
|
|
66
|
-
global[`_${global.module_in}_ch`].sendToQueue(
|
|
67
|
-
'ai_module',
|
|
68
|
-
Buffer.from(
|
|
69
|
-
JSON.stringify({
|
|
70
|
-
ms_method,
|
|
71
|
-
data: args,
|
|
72
|
-
cb:`_ai_module-${global.module_in}_ch`,
|
|
73
|
-
queue_id
|
|
74
|
-
})
|
|
75
|
-
)
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
}catch(err){
|
|
79
|
-
debugger
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// You must define this somewhere before using these wrappers:
|
|
86
|
-
const module_name = 'ai_module';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
global.queueName = 'ai_module';
|
|
9
|
+
const _ms_broker = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
|
|
87
10
|
|
|
88
11
|
export const get_chat_conversation = async function (...args) {
|
|
89
|
-
return await send_to_queue(
|
|
12
|
+
return await _ms_broker.send_to_queue('get_chat_conversation', ...args);
|
|
90
13
|
};
|
|
91
14
|
|
|
92
15
|
export const get_ai_chats = async function (...args) {
|
|
93
|
-
return await send_to_queue(
|
|
16
|
+
return await _ms_broker.send_to_queue('get_ai_chats', ...args);
|
|
94
17
|
};
|
|
95
18
|
|
|
96
19
|
export const delete_ai_chat = async function (...args) {
|
|
97
|
-
return await send_to_queue(
|
|
20
|
+
return await _ms_broker.send_to_queue('delete_ai_chat', ...args);
|
|
98
21
|
};
|
|
99
22
|
|
|
100
23
|
export const archive_ai_chat = async function (...args) {
|
|
101
|
-
return await send_to_queue(
|
|
24
|
+
return await _ms_broker.send_to_queue('archive_ai_chat', ...args);
|
|
102
25
|
};
|
|
103
26
|
|
|
104
27
|
export const unarchive_ai_chat = async function (...args) {
|
|
105
|
-
return await send_to_queue(
|
|
28
|
+
return await _ms_broker.send_to_queue('unarchive_ai_chat', ...args);
|
|
106
29
|
};
|
|
107
30
|
|
|
108
31
|
export const get_ai_agent_info = async function (...args) {
|
|
109
|
-
return await send_to_queue(
|
|
32
|
+
return await _ms_broker.send_to_queue('get_ai_agent_info', ...args);
|
|
110
33
|
};
|
|
111
34
|
|
|
112
35
|
export const get_ai_agents = async function (...args) {
|
|
113
|
-
return await send_to_queue(
|
|
36
|
+
return await _ms_broker.send_to_queue('get_ai_agents', ...args);
|
|
114
37
|
};
|
|
115
38
|
|
|
116
39
|
export const delete_ai_agent = async function (...args) {
|
|
117
|
-
return await send_to_queue(
|
|
40
|
+
return await _ms_broker.send_to_queue('delete_ai_agent', ...args);
|
|
118
41
|
};
|
|
119
42
|
|
|
120
43
|
export const uninstall_ai_agent = async function (...args) {
|
|
121
|
-
return await send_to_queue(
|
|
44
|
+
return await _ms_broker.send_to_queue('uninstall_ai_agent', ...args);
|
|
122
45
|
};
|
|
123
46
|
|
|
124
47
|
export const unarchive_ai_agent = async function (...args) {
|
|
125
|
-
return await send_to_queue(
|
|
48
|
+
return await _ms_broker.send_to_queue('unarchive_ai_agent', ...args);
|
|
126
49
|
};
|
|
127
50
|
|
|
128
51
|
export const archive_ai_agent = async function (...args) {
|
|
129
|
-
return await send_to_queue(
|
|
52
|
+
return await _ms_broker.send_to_queue('archive_ai_agent', ...args);
|
|
130
53
|
};
|
|
131
54
|
|
|
132
55
|
export const archive_mini_app = async function (...args) {
|
|
133
|
-
return await send_to_queue(
|
|
56
|
+
return await _ms_broker.send_to_queue('archive_mini_app', ...args);
|
|
134
57
|
};
|
|
135
58
|
|
|
136
59
|
export const unarchive_mini_app = async function (...args) {
|
|
137
|
-
return await send_to_queue(
|
|
60
|
+
return await _ms_broker.send_to_queue('unarchive_mini_app', ...args);
|
|
138
61
|
};
|
|
139
62
|
|
|
140
63
|
export const delete_mini_app = async function (...args) {
|
|
141
|
-
return await send_to_queue(
|
|
64
|
+
return await _ms_broker.send_to_queue('delete_mini_app', ...args);
|
|
142
65
|
};
|
|
143
66
|
|
|
144
67
|
export const update_ai_agent = async function (...args) {
|
|
145
|
-
return await send_to_queue(
|
|
68
|
+
return await _ms_broker.send_to_queue('update_ai_agent', ...args);
|
|
146
69
|
};
|
|
147
70
|
|
|
148
71
|
export const get_apps = async function (...args) {
|
|
149
|
-
return await send_to_queue(
|
|
72
|
+
return await _ms_broker.send_to_queue('get_apps', ...args);
|
|
150
73
|
};
|
|
151
74
|
|
|
152
75
|
export const create_ai_agent = async function (...args) {
|
|
153
|
-
return await send_to_queue(
|
|
76
|
+
return await _ms_broker.send_to_queue('create_ai_agent', ...args);
|
|
154
77
|
};
|
|
155
78
|
|
|
156
79
|
export const update_ai_agent_properties = async function (...args) {
|
|
157
|
-
return await send_to_queue(
|
|
80
|
+
return await _ms_broker.send_to_queue('update_ai_agent_properties', ...args);
|
|
158
81
|
};
|
|
159
82
|
|
|
160
83
|
export const update_thumbnail = async function (...args) {
|
|
161
|
-
return await send_to_queue(
|
|
84
|
+
return await _ms_broker.send_to_queue('update_thumbnail', ...args);
|
|
162
85
|
};
|
|
163
86
|
|
|
164
87
|
export const upload_prompt_attachment = async function (...args) {
|
|
165
|
-
return await send_to_queue(
|
|
88
|
+
return await _ms_broker.send_to_queue('upload_prompt_attachment', ...args);
|
|
166
89
|
};
|
|
167
90
|
|
|
168
91
|
export const delete_prompt_attachment = async function (...args) {
|
|
169
|
-
return await send_to_queue(
|
|
92
|
+
return await _ms_broker.send_to_queue('delete_prompt_attachment', ...args);
|
|
170
93
|
};
|
|
171
94
|
|
|
172
95
|
export const submit_chat_gpt_prompt = async function (...args) {
|
|
173
|
-
return await send_to_queue(
|
|
96
|
+
return await _ms_broker.send_to_queue('submit_chat_gpt_prompt', ...args);
|
|
174
97
|
};
|
|
175
98
|
|
|
176
99
|
export const create_conversation = async function (...args) {
|
|
177
|
-
return await send_to_queue(
|
|
100
|
+
return await _ms_broker.send_to_queue('create_conversation', ...args);
|
|
178
101
|
};
|
|
179
102
|
|
|
180
103
|
export const submit_chat_conversation = async function (...args) {
|
|
181
|
-
return await send_to_queue(
|
|
104
|
+
return await _ms_broker.send_to_queue('submit_chat_conversation', ...args);
|
|
182
105
|
};
|
|
183
106
|
|
|
184
107
|
export const create_avatar = async function (...args) {
|
|
185
|
-
return await send_to_queue(
|
|
108
|
+
return await _ms_broker.send_to_queue('create_avatar', ...args);
|
|
186
109
|
};
|
|
187
110
|
|
|
188
111
|
export const get_profile_avatar = async function (...args) {
|
|
189
|
-
return await send_to_queue(
|
|
112
|
+
return await _ms_broker.send_to_queue('get_profile_avatar', ...args);
|
|
190
113
|
};
|
|
191
114
|
|
|
192
115
|
export const get_profile_picture = async function (...args) {
|
|
193
|
-
return await send_to_queue(
|
|
116
|
+
return await _ms_broker.send_to_queue('get_profile_picture', ...args);
|
|
194
117
|
};
|
|
195
118
|
|
|
196
119
|
export const conversation_actions = async function (...args) {
|
|
197
|
-
return await send_to_queue(
|
|
120
|
+
return await _ms_broker.send_to_queue('conversation_actions', ...args);
|
|
198
121
|
};
|
|
199
122
|
|
|
200
123
|
export const modify_profile_avatar = async function (...args) {
|
|
201
|
-
return await send_to_queue(
|
|
124
|
+
return await _ms_broker.send_to_queue('modify_profile_avatar', ...args);
|
|
202
125
|
};
|
|
203
126
|
|
|
204
127
|
export const get_ai_workspace_pending_counts = async function (...args) {
|
|
205
|
-
return await send_to_queue(
|
|
128
|
+
return await _ms_broker.send_to_queue('get_ai_workspace_pending_counts', ...args);
|
|
206
129
|
};
|
|
207
130
|
|
|
208
131
|
export const create_mini_app = async function (...args) {
|
|
209
|
-
return await send_to_queue(
|
|
132
|
+
return await _ms_broker.send_to_queue('create_mini_app', ...args);
|
|
210
133
|
};
|
|
211
134
|
|
|
212
135
|
export const pin_ai_agent = async function (...args) {
|
|
213
|
-
return await send_to_queue(
|
|
136
|
+
return await _ms_broker.send_to_queue('pin_ai_agent', ...args);
|
|
214
137
|
};
|
|
215
138
|
|
|
216
139
|
export const unpin_ai_agent = async function (...args) {
|
|
217
|
-
return await send_to_queue(
|
|
140
|
+
return await _ms_broker.send_to_queue('unpin_ai_agent', ...args);
|
|
218
141
|
};
|
|
219
142
|
|
|
220
143
|
export const get_transcript = async function (...args) {
|
|
221
|
-
return await send_to_queue(
|
|
144
|
+
return await _ms_broker.send_to_queue('get_transcript', ...args);
|
|
222
145
|
};
|
|
223
146
|
|
|
224
147
|
export const add_transcript_conversation_item = async function (...args) {
|
|
225
|
-
return await send_to_queue(
|
|
148
|
+
return await _ms_broker.send_to_queue('add_transcript_conversation_item', ...args);
|
|
226
149
|
};
|
|
227
150
|
|
|
228
151
|
export const is_spam_email = async function (...args) {
|
|
229
|
-
return await send_to_queue(
|
|
152
|
+
return await _ms_broker.send_to_queue('is_spam_email', ...args);
|
|
230
153
|
};
|
|
231
154
|
|
|
232
155
|
export const is_business_contact = async function (...args) {
|
|
233
|
-
return await send_to_queue(
|
|
156
|
+
return await _ms_broker.send_to_queue('is_business_contact', ...args);
|
|
234
157
|
};
|
|
235
158
|
|
|
236
159
|
export const is_business_contact_has_person = async function (...args) {
|
|
237
|
-
return await send_to_queue(
|
|
160
|
+
return await _ms_broker.send_to_queue('is_business_contact_has_person', ...args);
|
|
238
161
|
};
|
|
239
162
|
|
|
240
163
|
export const get_name_from_email_addr = async function (...args) {
|
|
241
|
-
return await send_to_queue(
|
|
164
|
+
return await _ms_broker.send_to_queue('get_name_from_email_addr', ...args);
|
|
242
165
|
};
|
|
243
166
|
|
|
244
167
|
export const categorize_email_subject = async function (...args) {
|
|
245
|
-
return await send_to_queue(
|
|
168
|
+
return await _ms_broker.send_to_queue('categorize_email_subject', ...args);
|
|
246
169
|
};
|
|
247
170
|
|
|
248
171
|
export const categorize_ai_prompt = async function (...args) {
|
|
249
|
-
return await send_to_queue(
|
|
172
|
+
return await _ms_broker.send_to_queue('categorize_ai_prompt', ...args);
|
|
250
173
|
};
|
|
251
174
|
|
|
252
175
|
export const categorize_text_message = async function (...args) {
|
|
253
|
-
return await send_to_queue(
|
|
176
|
+
return await _ms_broker.send_to_queue('categorize_text_message', ...args);
|
|
254
177
|
};
|
|
255
178
|
|
|
256
179
|
export const categorize_contact_note = async function (...args) {
|
|
257
|
-
return await send_to_queue(
|
|
180
|
+
return await _ms_broker.send_to_queue('categorize_contact_note', ...args);
|
|
258
181
|
};
|
|
259
182
|
|
|
260
183
|
export const get_business_info = async function (...args) {
|
|
261
|
-
return await send_to_queue(
|
|
184
|
+
return await _ms_broker.send_to_queue('get_business_info', ...args);
|
|
262
185
|
};
|
|
263
186
|
|
|
264
187
|
export const get_person_info = async function (...args) {
|
|
265
|
-
return await send_to_queue(
|
|
188
|
+
return await _ms_broker.send_to_queue('get_person_info', ...args);
|
|
266
189
|
};
|
|
267
190
|
|
|
268
191
|
export const open_ai_alive_check = async function (...args) {
|
|
269
|
-
return await send_to_queue(
|
|
192
|
+
return await _ms_broker.send_to_queue('open_ai_alive_check', ...args);
|
|
270
193
|
};
|