@xuda.io/ai_module 1.1.5575 → 1.1.5577

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 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];
@@ -2154,6 +2160,7 @@ export const get_ai_agents = async function (req, job_id, headers) {
2154
2160
  //////////////////////
2155
2161
 
2156
2162
  let docs = [];
2163
+ debugger;
2157
2164
  for (let doc of user_agents.docs) {
2158
2165
  let reference_doc;
2159
2166
  // shares
@@ -2184,7 +2191,6 @@ export const get_ai_agents = async function (req, job_id, headers) {
2184
2191
 
2185
2192
  return { code: 8, data: { docs: [...requests_from.docs, ...docs], total_docs: user_agents.total_docs + requests_from.total_docs } };
2186
2193
  } catch (err) {
2187
- debugger;
2188
2194
  return { code: -8, data: err.message };
2189
2195
  }
2190
2196
  };
@@ -2466,6 +2472,11 @@ export const get_apps = async function (req, job_id, headers) {
2466
2472
  break;
2467
2473
  }
2468
2474
 
2475
+ case 'pinned': {
2476
+ opt.selector['studio_meta.pinned'] = true;
2477
+ break;
2478
+ }
2479
+
2469
2480
  default:
2470
2481
  break;
2471
2482
  }
@@ -2551,6 +2562,11 @@ export const get_apps = async function (req, job_id, headers) {
2551
2562
  reference_doc = _.cloneDeep(doc);
2552
2563
  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
2564
  doc.reference_doc = reference_doc;
2565
+ doc.stat = reference_doc.stat ?? doc.stat;
2566
+ doc.studio_meta = {
2567
+ ...(doc.studio_meta || {}),
2568
+ pinned: reference_doc?.studio_meta?.pinned ?? doc?.studio_meta?.pinned,
2569
+ };
2554
2570
  }
2555
2571
 
2556
2572
  doc.user_contact = await get_user_card({ uid, uid_query: doc.studio_meta.createdByUid });
@@ -4190,7 +4206,15 @@ const chat_studio = async function (req, job_id, headers) {
4190
4206
  const prompt_conversation_item_id = await _common.xuda_get_uuid('chat_conversation_item');
4191
4207
  const response_conversation_item_id = await _common.xuda_get_uuid('chat_conversation_item');
4192
4208
 
4209
+ let stream_delta_seq = 0;
4210
+ let stream_delta_text = '';
4193
4211
  const emitToDashboard = (type, content, params) => {
4212
+ const is_stream_delta = type === 'stream_delta';
4213
+ const is_stream_end = type === 'stream_end';
4214
+ const seq = is_stream_delta ? ++stream_delta_seq : undefined;
4215
+ if (is_stream_delta) {
4216
+ stream_delta_text += content || '';
4217
+ }
4194
4218
  ws_dashboard_msa.emit_message_to_dashboard({
4195
4219
  service: type,
4196
4220
  to: uid,
@@ -4198,6 +4222,14 @@ const chat_studio = async function (req, job_id, headers) {
4198
4222
  conversation_id,
4199
4223
  job_id,
4200
4224
  delta: content,
4225
+ ...(seq ? { seq } : {}),
4226
+ ...(is_stream_end
4227
+ ? {
4228
+ stream_id: response_conversation_item_id,
4229
+ final_seq: stream_delta_seq,
4230
+ text: stream_delta_text,
4231
+ }
4232
+ : {}),
4201
4233
  prompt_conversation_item_id,
4202
4234
  response_conversation_item_id,
4203
4235
  params,
@@ -4866,8 +4898,16 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4866
4898
  }
4867
4899
 
4868
4900
  // const { account_profile_info } = conversation_doc;
4901
+ let stream_delta_seq = 0;
4902
+ let stream_delta_text = '';
4869
4903
  const emitToDashboard = (type, content, params) => {
4870
4904
  // console.log(type, content);
4905
+ const is_stream_delta = type === 'stream_delta';
4906
+ const is_stream_end = type === 'stream_end';
4907
+ const seq = is_stream_delta ? ++stream_delta_seq : undefined;
4908
+ if (is_stream_delta) {
4909
+ stream_delta_text += content || '';
4910
+ }
4871
4911
  ws_dashboard_msa.emit_message_to_dashboard({
4872
4912
  service: type,
4873
4913
  to: uid,
@@ -4875,6 +4915,14 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4875
4915
  conversation_id,
4876
4916
  job_id,
4877
4917
  delta: content,
4918
+ ...(seq ? { seq } : {}),
4919
+ ...(is_stream_end
4920
+ ? {
4921
+ stream_id: response_conversation_item_id,
4922
+ final_seq: stream_delta_seq,
4923
+ text: stream_delta_text,
4924
+ }
4925
+ : {}),
4878
4926
  prompt_conversation_item_id,
4879
4927
  response_conversation_item_id,
4880
4928
  params,
@@ -7087,6 +7135,175 @@ export const create_mini_app = async function (req, job_id, headers) {
7087
7135
  }
7088
7136
  };
7089
7137
 
7138
+ const get_ai_chat_info = async function (uid, conversation_doc) {
7139
+ const account_profile_info = await get_active_account_profile_info(uid);
7140
+ let doc = _.cloneDeep(conversation_doc);
7141
+
7142
+ if (doc.shared_from_uid && doc.shared_from_app_id && doc.share_item_id) {
7143
+ const reference_doc = _.cloneDeep(doc);
7144
+ doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
7145
+ doc.reference_doc = reference_doc;
7146
+ doc.pinned = reference_doc.pinned ?? doc.pinned;
7147
+ doc.stat = reference_doc.stat ?? doc.stat;
7148
+ }
7149
+
7150
+ const reference_id = doc.reference_id || '';
7151
+ const [count_ret, read_ret] = await Promise.all([
7152
+ db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
7153
+ reduce: true,
7154
+ group_level: 999,
7155
+ startkey: [reference_id, ''],
7156
+ endkey: [reference_id, 'zzzzzz'],
7157
+ }),
7158
+ db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
7159
+ reduce: true,
7160
+ group_level: 999,
7161
+ startkey: [uid, reference_id, ''],
7162
+ endkey: [uid, reference_id, 'zzzzzz'],
7163
+ }),
7164
+ ]);
7165
+
7166
+ const interactions = count_ret?.rows?.find((row) => row?.key?.[1] === doc._id)?.value || 0;
7167
+ const read_count = read_ret?.rows?.find((row) => row?.key?.[2] === doc._id)?.value || 0;
7168
+
7169
+ doc.interactions = interactions;
7170
+ doc.notifications = Math.max(0, interactions - read_count);
7171
+ doc.chats = interactions;
7172
+
7173
+ if (doc.uid) {
7174
+ doc.user_contact = await get_user_card({ uid, uid_query: doc.uid });
7175
+ }
7176
+
7177
+ doc.privilege = doc.uid === uid || doc?.account_profile_info?.uid === uid;
7178
+
7179
+ return doc;
7180
+ };
7181
+
7182
+ const get_mini_app_info = async function (uid, prog_doc) {
7183
+ let doc = _.cloneDeep(prog_doc);
7184
+
7185
+ if (doc?.studio_meta?.shared_from_uid && doc?.studio_meta?.shared_from_app_id) {
7186
+ const reference_doc = _.cloneDeep(doc);
7187
+ doc = await db_module.get_app_couch_doc_native(reference_doc.studio_meta.shared_from_app_id, reference_doc.studio_meta.share_item_id);
7188
+ doc.reference_doc = reference_doc;
7189
+ doc.stat = reference_doc.stat ?? doc.stat;
7190
+ doc.studio_meta = {
7191
+ ...(doc.studio_meta || {}),
7192
+ pinned: reference_doc?.studio_meta?.pinned ?? doc?.studio_meta?.pinned,
7193
+ };
7194
+ }
7195
+
7196
+ if (doc?.studio_meta?.createdByUid) {
7197
+ doc.user_contact = await get_user_card({ uid, uid_query: doc.studio_meta.createdByUid });
7198
+ }
7199
+
7200
+ doc.privilege = doc?.studio_meta?.createdByUid === uid || doc?.studio_meta?.account_profile_info?.uid === uid;
7201
+
7202
+ return doc;
7203
+ };
7204
+
7205
+ export const pin_ai_chat = async function (req) {
7206
+ const { uid, conversation_id } = req;
7207
+ try {
7208
+ const account_profile_info = await get_active_account_profile_info(uid);
7209
+ const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
7210
+
7211
+ conversation_doc.pinned = true;
7212
+
7213
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
7214
+
7215
+ ws_dashboard_msa.emit_message_to_dashboard({
7216
+ service: 'ai_chat_pinned',
7217
+ to: [uid],
7218
+ data: await get_ai_chat_info(uid, conversation_doc),
7219
+ });
7220
+
7221
+ return save_ret;
7222
+ } catch (err) {
7223
+ return {
7224
+ code: -24,
7225
+ data: err.message,
7226
+ };
7227
+ }
7228
+ };
7229
+
7230
+ export const unpin_ai_chat = async function (req) {
7231
+ const { uid, conversation_id } = req;
7232
+ try {
7233
+ const account_profile_info = await get_active_account_profile_info(uid);
7234
+ const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
7235
+
7236
+ conversation_doc.pinned = false;
7237
+
7238
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
7239
+
7240
+ ws_dashboard_msa.emit_message_to_dashboard({
7241
+ service: 'ai_chat_unpinned',
7242
+ to: [uid],
7243
+ data: await get_ai_chat_info(uid, conversation_doc),
7244
+ });
7245
+
7246
+ return save_ret;
7247
+ } catch (err) {
7248
+ return {
7249
+ code: -24,
7250
+ data: err.message,
7251
+ };
7252
+ }
7253
+ };
7254
+
7255
+ export const pin_mini_app = async function (req) {
7256
+ const { uid, prog_id } = req;
7257
+ try {
7258
+ const account_profile_info = await get_active_account_profile_info(uid);
7259
+ const prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
7260
+
7261
+ prog_doc.studio_meta = prog_doc.studio_meta || {};
7262
+ prog_doc.studio_meta.pinned = true;
7263
+
7264
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
7265
+
7266
+ ws_dashboard_msa.emit_message_to_dashboard({
7267
+ service: 'mini_app_pinned',
7268
+ to: [uid],
7269
+ data: await get_mini_app_info(uid, prog_doc),
7270
+ });
7271
+
7272
+ return save_ret;
7273
+ } catch (err) {
7274
+ return {
7275
+ code: -24,
7276
+ data: err.message,
7277
+ };
7278
+ }
7279
+ };
7280
+
7281
+ export const unpin_mini_app = async function (req) {
7282
+ const { uid, prog_id } = req;
7283
+ try {
7284
+ const account_profile_info = await get_active_account_profile_info(uid);
7285
+ const prog_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, prog_id);
7286
+
7287
+ prog_doc.studio_meta = prog_doc.studio_meta || {};
7288
+ prog_doc.studio_meta.pinned = false;
7289
+
7290
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, prog_doc);
7291
+
7292
+ ws_dashboard_msa.emit_message_to_dashboard({
7293
+ service: 'mini_app_unpinned',
7294
+ to: [uid],
7295
+ data: await get_mini_app_info(uid, prog_doc),
7296
+ });
7297
+
7298
+ return save_ret;
7299
+ } catch (err) {
7300
+ return {
7301
+ code: -24,
7302
+ data: err.message,
7303
+ };
7304
+ }
7305
+ };
7306
+
7090
7307
  export const pin_ai_agent = async function (req, job_id, headers) {
7091
7308
  const { uid, agent_id } = req;
7092
7309
  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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5575",
3
+ "version": "1.1.5577",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",