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