@xuda.io/ai_module 1.1.5574 → 1.1.5576
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 +218 -1
- package/index_ms.mjs +16 -0
- package/index_msa.mjs +16 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1247,6 +1247,10 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1247
1247
|
// opt.selector.team_req_stat = { $eq: 3 };
|
|
1248
1248
|
break;
|
|
1249
1249
|
}
|
|
1250
|
+
case 'pinned': {
|
|
1251
|
+
opt.selector.pinned = true;
|
|
1252
|
+
break;
|
|
1253
|
+
}
|
|
1250
1254
|
|
|
1251
1255
|
case 'mine': {
|
|
1252
1256
|
opt.selector.uid = uid;
|
|
@@ -1451,6 +1455,8 @@ export const get_ai_chats = async function (req, job_id, headers) {
|
|
|
1451
1455
|
reference_doc = _.cloneDeep(doc);
|
|
1452
1456
|
doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
|
|
1453
1457
|
doc.reference_doc = reference_doc;
|
|
1458
|
+
doc.pinned = reference_doc.pinned ?? doc.pinned;
|
|
1459
|
+
doc.stat = reference_doc.stat ?? doc.stat;
|
|
1454
1460
|
}
|
|
1455
1461
|
|
|
1456
1462
|
doc.interactions = contact_chat_conversation_count_ret[doc._id];
|
|
@@ -1954,6 +1960,7 @@ export const get_ai_agent_info = async function (uid, job_id, headers, doc, from
|
|
|
1954
1960
|
};
|
|
1955
1961
|
|
|
1956
1962
|
const agent_conversation_count = async function (agent_id) {
|
|
1963
|
+
debugger;
|
|
1957
1964
|
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
1958
1965
|
reduce: true,
|
|
1959
1966
|
group_level: 1,
|
|
@@ -2466,6 +2473,11 @@ export const get_apps = async function (req, job_id, headers) {
|
|
|
2466
2473
|
break;
|
|
2467
2474
|
}
|
|
2468
2475
|
|
|
2476
|
+
case 'pinned': {
|
|
2477
|
+
opt.selector['studio_meta.pinned'] = true;
|
|
2478
|
+
break;
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2469
2481
|
default:
|
|
2470
2482
|
break;
|
|
2471
2483
|
}
|
|
@@ -2551,6 +2563,11 @@ export const get_apps = async function (req, job_id, headers) {
|
|
|
2551
2563
|
reference_doc = _.cloneDeep(doc);
|
|
2552
2564
|
doc = await db_module.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
|
|
2553
2565
|
doc.reference_doc = reference_doc;
|
|
2566
|
+
doc.stat = reference_doc.stat ?? doc.stat;
|
|
2567
|
+
doc.studio_meta = {
|
|
2568
|
+
...(doc.studio_meta || {}),
|
|
2569
|
+
pinned: reference_doc?.studio_meta?.pinned ?? doc?.studio_meta?.pinned,
|
|
2570
|
+
};
|
|
2554
2571
|
}
|
|
2555
2572
|
|
|
2556
2573
|
doc.user_contact = await get_user_card({ uid, uid_query: doc.studio_meta.createdByUid });
|
|
@@ -4190,7 +4207,15 @@ const chat_studio = async function (req, job_id, headers) {
|
|
|
4190
4207
|
const prompt_conversation_item_id = await _common.xuda_get_uuid('chat_conversation_item');
|
|
4191
4208
|
const response_conversation_item_id = await _common.xuda_get_uuid('chat_conversation_item');
|
|
4192
4209
|
|
|
4210
|
+
let stream_delta_seq = 0;
|
|
4211
|
+
let stream_delta_text = '';
|
|
4193
4212
|
const emitToDashboard = (type, content, params) => {
|
|
4213
|
+
const is_stream_delta = type === 'stream_delta';
|
|
4214
|
+
const is_stream_end = type === 'stream_end';
|
|
4215
|
+
const seq = is_stream_delta ? ++stream_delta_seq : undefined;
|
|
4216
|
+
if (is_stream_delta) {
|
|
4217
|
+
stream_delta_text += content || '';
|
|
4218
|
+
}
|
|
4194
4219
|
ws_dashboard_msa.emit_message_to_dashboard({
|
|
4195
4220
|
service: type,
|
|
4196
4221
|
to: uid,
|
|
@@ -4198,6 +4223,14 @@ const chat_studio = async function (req, job_id, headers) {
|
|
|
4198
4223
|
conversation_id,
|
|
4199
4224
|
job_id,
|
|
4200
4225
|
delta: content,
|
|
4226
|
+
...(seq ? { seq } : {}),
|
|
4227
|
+
...(is_stream_end
|
|
4228
|
+
? {
|
|
4229
|
+
stream_id: response_conversation_item_id,
|
|
4230
|
+
final_seq: stream_delta_seq,
|
|
4231
|
+
text: stream_delta_text,
|
|
4232
|
+
}
|
|
4233
|
+
: {}),
|
|
4201
4234
|
prompt_conversation_item_id,
|
|
4202
4235
|
response_conversation_item_id,
|
|
4203
4236
|
params,
|
|
@@ -4866,8 +4899,16 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
4866
4899
|
}
|
|
4867
4900
|
|
|
4868
4901
|
// const { account_profile_info } = conversation_doc;
|
|
4902
|
+
let stream_delta_seq = 0;
|
|
4903
|
+
let stream_delta_text = '';
|
|
4869
4904
|
const emitToDashboard = (type, content, params) => {
|
|
4870
4905
|
// console.log(type, content);
|
|
4906
|
+
const is_stream_delta = type === 'stream_delta';
|
|
4907
|
+
const is_stream_end = type === 'stream_end';
|
|
4908
|
+
const seq = is_stream_delta ? ++stream_delta_seq : undefined;
|
|
4909
|
+
if (is_stream_delta) {
|
|
4910
|
+
stream_delta_text += content || '';
|
|
4911
|
+
}
|
|
4871
4912
|
ws_dashboard_msa.emit_message_to_dashboard({
|
|
4872
4913
|
service: type,
|
|
4873
4914
|
to: uid,
|
|
@@ -4875,6 +4916,14 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
4875
4916
|
conversation_id,
|
|
4876
4917
|
job_id,
|
|
4877
4918
|
delta: content,
|
|
4919
|
+
...(seq ? { seq } : {}),
|
|
4920
|
+
...(is_stream_end
|
|
4921
|
+
? {
|
|
4922
|
+
stream_id: response_conversation_item_id,
|
|
4923
|
+
final_seq: stream_delta_seq,
|
|
4924
|
+
text: stream_delta_text,
|
|
4925
|
+
}
|
|
4926
|
+
: {}),
|
|
4878
4927
|
prompt_conversation_item_id,
|
|
4879
4928
|
response_conversation_item_id,
|
|
4880
4929
|
params,
|
|
@@ -6181,7 +6230,6 @@ const create_and_upload_image_to_drive = async function (drive_type, file_path,
|
|
|
6181
6230
|
};
|
|
6182
6231
|
|
|
6183
6232
|
export const create_avatar = async function (req, job_id, headers) {
|
|
6184
|
-
debugger;
|
|
6185
6233
|
const { docType, uid, url, _id, name, account_type } = req;
|
|
6186
6234
|
let { metadata } = req;
|
|
6187
6235
|
try {
|
|
@@ -7088,6 +7136,175 @@ export const create_mini_app = async function (req, job_id, headers) {
|
|
|
7088
7136
|
}
|
|
7089
7137
|
};
|
|
7090
7138
|
|
|
7139
|
+
const get_ai_chat_info = async function (uid, conversation_doc) {
|
|
7140
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
7141
|
+
let doc = _.cloneDeep(conversation_doc);
|
|
7142
|
+
|
|
7143
|
+
if (doc.shared_from_uid && doc.shared_from_app_id && doc.share_item_id) {
|
|
7144
|
+
const reference_doc = _.cloneDeep(doc);
|
|
7145
|
+
doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
|
|
7146
|
+
doc.reference_doc = reference_doc;
|
|
7147
|
+
doc.pinned = reference_doc.pinned ?? doc.pinned;
|
|
7148
|
+
doc.stat = reference_doc.stat ?? doc.stat;
|
|
7149
|
+
}
|
|
7150
|
+
|
|
7151
|
+
const reference_id = doc.reference_id || '';
|
|
7152
|
+
const [count_ret, read_ret] = await Promise.all([
|
|
7153
|
+
db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
7154
|
+
reduce: true,
|
|
7155
|
+
group_level: 999,
|
|
7156
|
+
startkey: [reference_id, ''],
|
|
7157
|
+
endkey: [reference_id, 'zzzzzz'],
|
|
7158
|
+
}),
|
|
7159
|
+
db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
|
|
7160
|
+
reduce: true,
|
|
7161
|
+
group_level: 999,
|
|
7162
|
+
startkey: [uid, reference_id, ''],
|
|
7163
|
+
endkey: [uid, reference_id, 'zzzzzz'],
|
|
7164
|
+
}),
|
|
7165
|
+
]);
|
|
7166
|
+
|
|
7167
|
+
const interactions = count_ret?.rows?.find((row) => row?.key?.[1] === doc._id)?.value || 0;
|
|
7168
|
+
const read_count = read_ret?.rows?.find((row) => row?.key?.[2] === doc._id)?.value || 0;
|
|
7169
|
+
|
|
7170
|
+
doc.interactions = interactions;
|
|
7171
|
+
doc.notifications = Math.max(0, interactions - read_count);
|
|
7172
|
+
doc.chats = interactions;
|
|
7173
|
+
|
|
7174
|
+
if (doc.uid) {
|
|
7175
|
+
doc.user_contact = await get_user_card({ uid, uid_query: doc.uid });
|
|
7176
|
+
}
|
|
7177
|
+
|
|
7178
|
+
doc.privilege = doc.uid === uid || doc?.account_profile_info?.uid === uid;
|
|
7179
|
+
|
|
7180
|
+
return doc;
|
|
7181
|
+
};
|
|
7182
|
+
|
|
7183
|
+
const get_mini_app_info = async function (uid, prog_doc) {
|
|
7184
|
+
let doc = _.cloneDeep(prog_doc);
|
|
7185
|
+
|
|
7186
|
+
if (doc?.studio_meta?.shared_from_uid && doc?.studio_meta?.shared_from_app_id) {
|
|
7187
|
+
const reference_doc = _.cloneDeep(doc);
|
|
7188
|
+
doc = await db_module.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
|
|
7189
|
+
doc.reference_doc = reference_doc;
|
|
7190
|
+
doc.stat = reference_doc.stat ?? doc.stat;
|
|
7191
|
+
doc.studio_meta = {
|
|
7192
|
+
...(doc.studio_meta || {}),
|
|
7193
|
+
pinned: reference_doc?.studio_meta?.pinned ?? doc?.studio_meta?.pinned,
|
|
7194
|
+
};
|
|
7195
|
+
}
|
|
7196
|
+
|
|
7197
|
+
if (doc?.studio_meta?.createdByUid) {
|
|
7198
|
+
doc.user_contact = await get_user_card({ uid, uid_query: doc.studio_meta.createdByUid });
|
|
7199
|
+
}
|
|
7200
|
+
|
|
7201
|
+
doc.privilege = doc?.studio_meta?.createdByUid === uid || doc?.studio_meta?.account_profile_info?.uid === uid;
|
|
7202
|
+
|
|
7203
|
+
return doc;
|
|
7204
|
+
};
|
|
7205
|
+
|
|
7206
|
+
export const pin_ai_chat = async function (req) {
|
|
7207
|
+
const { uid, conversation_id } = req;
|
|
7208
|
+
try {
|
|
7209
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
7210
|
+
const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
7211
|
+
|
|
7212
|
+
conversation_doc.pinned = true;
|
|
7213
|
+
|
|
7214
|
+
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
|
|
7215
|
+
|
|
7216
|
+
ws_dashboard_msa.emit_message_to_dashboard({
|
|
7217
|
+
service: 'ai_chat_pinned',
|
|
7218
|
+
to: [uid],
|
|
7219
|
+
data: await get_ai_chat_info(uid, conversation_doc),
|
|
7220
|
+
});
|
|
7221
|
+
|
|
7222
|
+
return save_ret;
|
|
7223
|
+
} catch (err) {
|
|
7224
|
+
return {
|
|
7225
|
+
code: -24,
|
|
7226
|
+
data: err.message,
|
|
7227
|
+
};
|
|
7228
|
+
}
|
|
7229
|
+
};
|
|
7230
|
+
|
|
7231
|
+
export const unpin_ai_chat = async function (req) {
|
|
7232
|
+
const { uid, conversation_id } = req;
|
|
7233
|
+
try {
|
|
7234
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
7235
|
+
const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
7236
|
+
|
|
7237
|
+
conversation_doc.pinned = false;
|
|
7238
|
+
|
|
7239
|
+
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
|
|
7240
|
+
|
|
7241
|
+
ws_dashboard_msa.emit_message_to_dashboard({
|
|
7242
|
+
service: 'ai_chat_unpinned',
|
|
7243
|
+
to: [uid],
|
|
7244
|
+
data: await get_ai_chat_info(uid, conversation_doc),
|
|
7245
|
+
});
|
|
7246
|
+
|
|
7247
|
+
return save_ret;
|
|
7248
|
+
} catch (err) {
|
|
7249
|
+
return {
|
|
7250
|
+
code: -24,
|
|
7251
|
+
data: err.message,
|
|
7252
|
+
};
|
|
7253
|
+
}
|
|
7254
|
+
};
|
|
7255
|
+
|
|
7256
|
+
export const pin_mini_app = async function (req) {
|
|
7257
|
+
const { uid, prog_id } = req;
|
|
7258
|
+
try {
|
|
7259
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
7260
|
+
const prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
|
|
7261
|
+
|
|
7262
|
+
prog_doc.studio_meta = prog_doc.studio_meta || {};
|
|
7263
|
+
prog_doc.studio_meta.pinned = true;
|
|
7264
|
+
|
|
7265
|
+
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
|
|
7266
|
+
|
|
7267
|
+
ws_dashboard_msa.emit_message_to_dashboard({
|
|
7268
|
+
service: 'mini_app_pinned',
|
|
7269
|
+
to: [uid],
|
|
7270
|
+
data: await get_mini_app_info(uid, prog_doc),
|
|
7271
|
+
});
|
|
7272
|
+
|
|
7273
|
+
return save_ret;
|
|
7274
|
+
} catch (err) {
|
|
7275
|
+
return {
|
|
7276
|
+
code: -24,
|
|
7277
|
+
data: err.message,
|
|
7278
|
+
};
|
|
7279
|
+
}
|
|
7280
|
+
};
|
|
7281
|
+
|
|
7282
|
+
export const unpin_mini_app = async function (req) {
|
|
7283
|
+
const { uid, prog_id } = req;
|
|
7284
|
+
try {
|
|
7285
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
7286
|
+
const prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
|
|
7287
|
+
|
|
7288
|
+
prog_doc.studio_meta = prog_doc.studio_meta || {};
|
|
7289
|
+
prog_doc.studio_meta.pinned = false;
|
|
7290
|
+
|
|
7291
|
+
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
|
|
7292
|
+
|
|
7293
|
+
ws_dashboard_msa.emit_message_to_dashboard({
|
|
7294
|
+
service: 'mini_app_unpinned',
|
|
7295
|
+
to: [uid],
|
|
7296
|
+
data: await get_mini_app_info(uid, prog_doc),
|
|
7297
|
+
});
|
|
7298
|
+
|
|
7299
|
+
return save_ret;
|
|
7300
|
+
} catch (err) {
|
|
7301
|
+
return {
|
|
7302
|
+
code: -24,
|
|
7303
|
+
data: err.message,
|
|
7304
|
+
};
|
|
7305
|
+
}
|
|
7306
|
+
};
|
|
7307
|
+
|
|
7091
7308
|
export const pin_ai_agent = async function (req, job_id, headers) {
|
|
7092
7309
|
const { uid, agent_id } = req;
|
|
7093
7310
|
try {
|
package/index_ms.mjs
CHANGED
|
@@ -149,6 +149,22 @@ export const create_mini_app = async function (...args) {
|
|
|
149
149
|
return await broker.send_to_queue("create_mini_app", ...args);
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
export const pin_ai_chat = async function (...args) {
|
|
153
|
+
return await broker.send_to_queue("pin_ai_chat", ...args);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const unpin_ai_chat = async function (...args) {
|
|
157
|
+
return await broker.send_to_queue("unpin_ai_chat", ...args);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const pin_mini_app = async function (...args) {
|
|
161
|
+
return await broker.send_to_queue("pin_mini_app", ...args);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const unpin_mini_app = async function (...args) {
|
|
165
|
+
return await broker.send_to_queue("unpin_mini_app", ...args);
|
|
166
|
+
};
|
|
167
|
+
|
|
152
168
|
export const pin_ai_agent = async function (...args) {
|
|
153
169
|
return await broker.send_to_queue("pin_ai_agent", ...args);
|
|
154
170
|
};
|
package/index_msa.mjs
CHANGED
|
@@ -149,6 +149,22 @@ export const create_mini_app = function (...args) {
|
|
|
149
149
|
broker.send_to_queue_async("create_mini_app", ...args);
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
export const pin_ai_chat = function (...args) {
|
|
153
|
+
broker.send_to_queue_async("pin_ai_chat", ...args);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const unpin_ai_chat = function (...args) {
|
|
157
|
+
broker.send_to_queue_async("unpin_ai_chat", ...args);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const pin_mini_app = function (...args) {
|
|
161
|
+
broker.send_to_queue_async("pin_mini_app", ...args);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const unpin_mini_app = function (...args) {
|
|
165
|
+
broker.send_to_queue_async("unpin_mini_app", ...args);
|
|
166
|
+
};
|
|
167
|
+
|
|
152
168
|
export const pin_ai_agent = function (...args) {
|
|
153
169
|
broker.send_to_queue_async("pin_ai_agent", ...args);
|
|
154
170
|
};
|