@xuda.io/ai_module 1.1.5580 → 1.1.5582

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.mjs +50 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2281,8 +2281,55 @@ export const unarchive_ai_agent = async function (req) {
2281
2281
  return { code: -9, data: err.message };
2282
2282
  }
2283
2283
  };
2284
+
2285
+ const update_agent_conversation_items_stat = async function (app_id, agent_id, stat, conversation_id) {
2286
+ const conversation_ids = [];
2287
+
2288
+ if (conversation_id) {
2289
+ conversation_ids.push(conversation_id);
2290
+ } else {
2291
+ const conversations_ret = await db_module.find_app_couch_query(app_id, {
2292
+ selector: {
2293
+ docType: 'chat_conversation',
2294
+ reference_id: agent_id,
2295
+ },
2296
+ fields: ['_id'],
2297
+ limit: 9999,
2298
+ });
2299
+
2300
+ conversation_ids.push(...(conversations_ret.docs || []).map((doc) => doc._id).filter(Boolean));
2301
+ }
2302
+
2303
+ let updated = 0;
2304
+ const ts = Date.now();
2305
+
2306
+ for (const conversation_id of conversation_ids) {
2307
+ const items_ret = await db_module.find_app_couch_query(app_id, {
2308
+ selector: {
2309
+ docType: 'chat_conversation_item',
2310
+ conversation_id,
2311
+ stat: { $lt: 4 },
2312
+ },
2313
+ limit: 9999,
2314
+ });
2315
+
2316
+ const docs = (items_ret.docs || []).map((doc) => ({
2317
+ ...doc,
2318
+ stat,
2319
+ ts,
2320
+ }));
2321
+
2322
+ if (docs.length) {
2323
+ await db_module.sava_app_couch_bulk_docs(app_id, docs);
2324
+ updated += docs.length;
2325
+ }
2326
+ }
2327
+
2328
+ return updated;
2329
+ };
2330
+
2284
2331
  export const archive_ai_agent = async function (req) {
2285
- let { agent_id, uid } = req;
2332
+ let { agent_id, uid, conversation_id } = req;
2286
2333
  const account_profile_info = await get_active_account_profile_info(uid);
2287
2334
 
2288
2335
  try {
@@ -2297,8 +2344,9 @@ export const archive_ai_agent = async function (req) {
2297
2344
  agent_doc.stat = 5;
2298
2345
  agent_doc.ts = Date.now();
2299
2346
  const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, agent_doc);
2347
+ const updated_conversation_items = await update_agent_conversation_items_stat(account_profile_info.app_id, agent_id, 5, conversation_id);
2300
2348
 
2301
- return save_ret;
2349
+ return { code: 1, data: { save_ret, updated_conversation_items } };
2302
2350
  } catch (err) {
2303
2351
  return { code: -9, data: err.message };
2304
2352
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5580",
3
+ "version": "1.1.5582",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",