@xuda.io/ai_module 1.1.4926 → 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.
Files changed (2) hide show
  1. package/index_ms.mjs +50 -120
  2. package/package.json +1 -1
package/index_ms.mjs CHANGED
@@ -3,261 +3,191 @@
3
3
  // Queue target : ai_module
4
4
  // =====================================================
5
5
 
6
- import amqplib from 'amqplib';
7
- import { randomUUID } from 'crypto';
8
-
9
- let queue = {};
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
- if (msg === null) {
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
- }
33
- });
34
-
35
- const send_to_queue = async function (ms_method, ...args) {
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';
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'));
80
10
 
81
11
  export const get_chat_conversation = async function (...args) {
82
- return await send_to_queue('get_chat_conversation', ...args);
12
+ return await _ms_broker.send_to_queue('get_chat_conversation', ...args);
83
13
  };
84
14
 
85
15
  export const get_ai_chats = async function (...args) {
86
- return await send_to_queue('get_ai_chats', ...args);
16
+ return await _ms_broker.send_to_queue('get_ai_chats', ...args);
87
17
  };
88
18
 
89
19
  export const delete_ai_chat = async function (...args) {
90
- return await send_to_queue('delete_ai_chat', ...args);
20
+ return await _ms_broker.send_to_queue('delete_ai_chat', ...args);
91
21
  };
92
22
 
93
23
  export const archive_ai_chat = async function (...args) {
94
- return await send_to_queue('archive_ai_chat', ...args);
24
+ return await _ms_broker.send_to_queue('archive_ai_chat', ...args);
95
25
  };
96
26
 
97
27
  export const unarchive_ai_chat = async function (...args) {
98
- return await send_to_queue('unarchive_ai_chat', ...args);
28
+ return await _ms_broker.send_to_queue('unarchive_ai_chat', ...args);
99
29
  };
100
30
 
101
31
  export const get_ai_agent_info = async function (...args) {
102
- return await send_to_queue('get_ai_agent_info', ...args);
32
+ return await _ms_broker.send_to_queue('get_ai_agent_info', ...args);
103
33
  };
104
34
 
105
35
  export const get_ai_agents = async function (...args) {
106
- return await send_to_queue('get_ai_agents', ...args);
36
+ return await _ms_broker.send_to_queue('get_ai_agents', ...args);
107
37
  };
108
38
 
109
39
  export const delete_ai_agent = async function (...args) {
110
- return await send_to_queue('delete_ai_agent', ...args);
40
+ return await _ms_broker.send_to_queue('delete_ai_agent', ...args);
111
41
  };
112
42
 
113
43
  export const uninstall_ai_agent = async function (...args) {
114
- return await send_to_queue('uninstall_ai_agent', ...args);
44
+ return await _ms_broker.send_to_queue('uninstall_ai_agent', ...args);
115
45
  };
116
46
 
117
47
  export const unarchive_ai_agent = async function (...args) {
118
- return await send_to_queue('unarchive_ai_agent', ...args);
48
+ return await _ms_broker.send_to_queue('unarchive_ai_agent', ...args);
119
49
  };
120
50
 
121
51
  export const archive_ai_agent = async function (...args) {
122
- return await send_to_queue('archive_ai_agent', ...args);
52
+ return await _ms_broker.send_to_queue('archive_ai_agent', ...args);
123
53
  };
124
54
 
125
55
  export const archive_mini_app = async function (...args) {
126
- return await send_to_queue('archive_mini_app', ...args);
56
+ return await _ms_broker.send_to_queue('archive_mini_app', ...args);
127
57
  };
128
58
 
129
59
  export const unarchive_mini_app = async function (...args) {
130
- return await send_to_queue('unarchive_mini_app', ...args);
60
+ return await _ms_broker.send_to_queue('unarchive_mini_app', ...args);
131
61
  };
132
62
 
133
63
  export const delete_mini_app = async function (...args) {
134
- return await send_to_queue('delete_mini_app', ...args);
64
+ return await _ms_broker.send_to_queue('delete_mini_app', ...args);
135
65
  };
136
66
 
137
67
  export const update_ai_agent = async function (...args) {
138
- return await send_to_queue('update_ai_agent', ...args);
68
+ return await _ms_broker.send_to_queue('update_ai_agent', ...args);
139
69
  };
140
70
 
141
71
  export const get_apps = async function (...args) {
142
- return await send_to_queue('get_apps', ...args);
72
+ return await _ms_broker.send_to_queue('get_apps', ...args);
143
73
  };
144
74
 
145
75
  export const create_ai_agent = async function (...args) {
146
- return await send_to_queue('create_ai_agent', ...args);
76
+ return await _ms_broker.send_to_queue('create_ai_agent', ...args);
147
77
  };
148
78
 
149
79
  export const update_ai_agent_properties = async function (...args) {
150
- return await send_to_queue('update_ai_agent_properties', ...args);
80
+ return await _ms_broker.send_to_queue('update_ai_agent_properties', ...args);
151
81
  };
152
82
 
153
83
  export const update_thumbnail = async function (...args) {
154
- return await send_to_queue('update_thumbnail', ...args);
84
+ return await _ms_broker.send_to_queue('update_thumbnail', ...args);
155
85
  };
156
86
 
157
87
  export const upload_prompt_attachment = async function (...args) {
158
- return await send_to_queue('upload_prompt_attachment', ...args);
88
+ return await _ms_broker.send_to_queue('upload_prompt_attachment', ...args);
159
89
  };
160
90
 
161
91
  export const delete_prompt_attachment = async function (...args) {
162
- return await send_to_queue('delete_prompt_attachment', ...args);
92
+ return await _ms_broker.send_to_queue('delete_prompt_attachment', ...args);
163
93
  };
164
94
 
165
95
  export const submit_chat_gpt_prompt = async function (...args) {
166
- return await send_to_queue('submit_chat_gpt_prompt', ...args);
96
+ return await _ms_broker.send_to_queue('submit_chat_gpt_prompt', ...args);
167
97
  };
168
98
 
169
99
  export const create_conversation = async function (...args) {
170
- return await send_to_queue('create_conversation', ...args);
100
+ return await _ms_broker.send_to_queue('create_conversation', ...args);
171
101
  };
172
102
 
173
103
  export const submit_chat_conversation = async function (...args) {
174
- return await send_to_queue('submit_chat_conversation', ...args);
104
+ return await _ms_broker.send_to_queue('submit_chat_conversation', ...args);
175
105
  };
176
106
 
177
107
  export const create_avatar = async function (...args) {
178
- return await send_to_queue('create_avatar', ...args);
108
+ return await _ms_broker.send_to_queue('create_avatar', ...args);
179
109
  };
180
110
 
181
111
  export const get_profile_avatar = async function (...args) {
182
- return await send_to_queue('get_profile_avatar', ...args);
112
+ return await _ms_broker.send_to_queue('get_profile_avatar', ...args);
183
113
  };
184
114
 
185
115
  export const get_profile_picture = async function (...args) {
186
- return await send_to_queue('get_profile_picture', ...args);
116
+ return await _ms_broker.send_to_queue('get_profile_picture', ...args);
187
117
  };
188
118
 
189
119
  export const conversation_actions = async function (...args) {
190
- return await send_to_queue('conversation_actions', ...args);
120
+ return await _ms_broker.send_to_queue('conversation_actions', ...args);
191
121
  };
192
122
 
193
123
  export const modify_profile_avatar = async function (...args) {
194
- return await send_to_queue('modify_profile_avatar', ...args);
124
+ return await _ms_broker.send_to_queue('modify_profile_avatar', ...args);
195
125
  };
196
126
 
197
127
  export const get_ai_workspace_pending_counts = async function (...args) {
198
- return await send_to_queue('get_ai_workspace_pending_counts', ...args);
128
+ return await _ms_broker.send_to_queue('get_ai_workspace_pending_counts', ...args);
199
129
  };
200
130
 
201
131
  export const create_mini_app = async function (...args) {
202
- return await send_to_queue('create_mini_app', ...args);
132
+ return await _ms_broker.send_to_queue('create_mini_app', ...args);
203
133
  };
204
134
 
205
135
  export const pin_ai_agent = async function (...args) {
206
- return await send_to_queue('pin_ai_agent', ...args);
136
+ return await _ms_broker.send_to_queue('pin_ai_agent', ...args);
207
137
  };
208
138
 
209
139
  export const unpin_ai_agent = async function (...args) {
210
- return await send_to_queue('unpin_ai_agent', ...args);
140
+ return await _ms_broker.send_to_queue('unpin_ai_agent', ...args);
211
141
  };
212
142
 
213
143
  export const get_transcript = async function (...args) {
214
- return await send_to_queue('get_transcript', ...args);
144
+ return await _ms_broker.send_to_queue('get_transcript', ...args);
215
145
  };
216
146
 
217
147
  export const add_transcript_conversation_item = async function (...args) {
218
- return await send_to_queue('add_transcript_conversation_item', ...args);
148
+ return await _ms_broker.send_to_queue('add_transcript_conversation_item', ...args);
219
149
  };
220
150
 
221
151
  export const is_spam_email = async function (...args) {
222
- return await send_to_queue('is_spam_email', ...args);
152
+ return await _ms_broker.send_to_queue('is_spam_email', ...args);
223
153
  };
224
154
 
225
155
  export const is_business_contact = async function (...args) {
226
- return await send_to_queue('is_business_contact', ...args);
156
+ return await _ms_broker.send_to_queue('is_business_contact', ...args);
227
157
  };
228
158
 
229
159
  export const is_business_contact_has_person = async function (...args) {
230
- return await send_to_queue('is_business_contact_has_person', ...args);
160
+ return await _ms_broker.send_to_queue('is_business_contact_has_person', ...args);
231
161
  };
232
162
 
233
163
  export const get_name_from_email_addr = async function (...args) {
234
- return await send_to_queue('get_name_from_email_addr', ...args);
164
+ return await _ms_broker.send_to_queue('get_name_from_email_addr', ...args);
235
165
  };
236
166
 
237
167
  export const categorize_email_subject = async function (...args) {
238
- return await send_to_queue('categorize_email_subject', ...args);
168
+ return await _ms_broker.send_to_queue('categorize_email_subject', ...args);
239
169
  };
240
170
 
241
171
  export const categorize_ai_prompt = async function (...args) {
242
- return await send_to_queue('categorize_ai_prompt', ...args);
172
+ return await _ms_broker.send_to_queue('categorize_ai_prompt', ...args);
243
173
  };
244
174
 
245
175
  export const categorize_text_message = async function (...args) {
246
- return await send_to_queue('categorize_text_message', ...args);
176
+ return await _ms_broker.send_to_queue('categorize_text_message', ...args);
247
177
  };
248
178
 
249
179
  export const categorize_contact_note = async function (...args) {
250
- return await send_to_queue('categorize_contact_note', ...args);
180
+ return await _ms_broker.send_to_queue('categorize_contact_note', ...args);
251
181
  };
252
182
 
253
183
  export const get_business_info = async function (...args) {
254
- return await send_to_queue('get_business_info', ...args);
184
+ return await _ms_broker.send_to_queue('get_business_info', ...args);
255
185
  };
256
186
 
257
187
  export const get_person_info = async function (...args) {
258
- return await send_to_queue('get_person_info', ...args);
188
+ return await _ms_broker.send_to_queue('get_person_info', ...args);
259
189
  };
260
190
 
261
191
  export const open_ai_alive_check = async function (...args) {
262
- return await send_to_queue('open_ai_alive_check', ...args);
192
+ return await _ms_broker.send_to_queue('open_ai_alive_check', ...args);
263
193
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4926",
3
+ "version": "1.1.4927",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",