@xuda.io/account_module 1.2.2168 → 1.2.2170

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 +5 -28
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -3393,41 +3393,18 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
3393
3393
  const timestamp_to = new Date(Number(year_to) || year, (Number(month_to) || month) - 1, Number(day_to) || day).getTime();
3394
3394
 
3395
3395
  const query = {
3396
- // include_docs: true,
3396
+ include_docs: true,
3397
3397
  startkey: [uid, timestamp_from],
3398
3398
  endkey: [uid, timestamp_to],
3399
- reduce: true,
3400
- group_level: 999,
3399
+ // reduce: true,
3400
+ // group_level: 999,
3401
3401
  };
3402
3402
  const response = await db_module.call_list_function('xuda_usage', 'ai_usage2', 'filter_usage', query);
3403
3403
 
3404
3404
  // console.log('ai_usage', ai_usage.rows);
3405
3405
  debugger;
3406
- let total_usage = 0;
3407
- let profile = {};
3408
-
3409
- for (const row of ai_usage.data.rows) {
3410
- const user = row.key[0];
3411
- const year = row.key[1];
3412
- const month = row.key[2];
3413
- const day = row.key[3];
3414
- const account_profile_id = row.key[4];
3415
- const uid = row.key[5];
3416
- const model = row.key[6];
3417
- const input_tokens = row.value[0];
3418
- const output_tokens = row.value[1];
3419
- const input_credits = row.value[2];
3420
- const output_credits = row.value[3];
3421
- if (!profile[account_profile_id]) {
3422
- profile[account_profile_id] = {};
3423
- }
3424
- if (!profile[account_profile_id][uid]) {
3425
- profile[account_profile_id][uid] = 0;
3426
- }
3427
-
3428
- profile[account_profile_id][uid] += input_credits + output_credits;
3429
- total_usage += input_credits + output_credits;
3430
- }
3406
+ let total_usage = response.total_usage;
3407
+ let profile = response.profiles;
3431
3408
 
3432
3409
  const ai_credits = await db_module.get_couch_view('xuda_billing', 'ai_credits', {
3433
3410
  startkey: [uid, ''],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.2168",
3
+ "version": "1.2.2170",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {