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