@xuda.io/account_module 1.2.1548 → 1.2.1550

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 +19 -11
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1825,7 +1825,7 @@ export const ts_contact = async function (uid, contact_id) {
1825
1825
  export const get_account_ai_usage = async function (req, job_id, headers) {
1826
1826
  const { uid, year, month, day, usage_scope = 'account' } = req;
1827
1827
  try {
1828
- const app_id = await get_account_default_project_id(uid);
1828
+ // const app_id = await get_account_default_project_id(uid);
1829
1829
  const { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
1830
1830
 
1831
1831
  const d = new Date();
@@ -1844,12 +1844,13 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
1844
1844
  let profile = {};
1845
1845
 
1846
1846
  for (const row of ai_usage.rows) {
1847
- const year = row.key[0];
1848
- const month = row.key[1];
1849
- const day = row.key[2];
1850
- const account_profile_id = row.key[3];
1851
- const uid = row.key[4];
1852
- const model = row.key[5];
1847
+ const user = row.key[0];
1848
+ const year = row.key[1];
1849
+ const month = row.key[2];
1850
+ const day = row.key[3];
1851
+ const account_profile_id = row.key[4];
1852
+ const uid = row.key[5];
1853
+ const model = row.key[6];
1853
1854
  const input_tokens = row.value[0];
1854
1855
  const output_tokens = row.value[1];
1855
1856
  const input_credits = row.value[2];
@@ -1865,10 +1866,17 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
1865
1866
  total_usage += input_credits + output_credits;
1866
1867
  }
1867
1868
 
1868
- let membership_plan = _conf.PLAN_OBJ?.[acc_obj?.ai_workspace_plan]?.features?.ai_credits || 0;
1869
- let ai_workspace_plan = _conf.PLAN_OBJ?.[acc_obj?.membership_plan]?.features?.ai_credits || 0;
1870
- let contact_connection = 0;
1871
- let total_credits = membership_plan + ai_workspace_plan + contact_connection;
1869
+ // let membership_plan = _conf.PLAN_OBJ?.[acc_obj?.ai_workspace_plan]?.features?.ai_credits || 0;
1870
+ // let ai_workspace_plan = _conf.PLAN_OBJ?.[acc_obj?.membership_plan]?.features?.ai_credits || 0;
1871
+ // let contact_connection = 0;
1872
+ // let total_credits = membership_plan + ai_workspace_plan + contact_connection;
1873
+
1874
+ const ai_credits = await db_module.get_couch_view('xuda_billing', 'ai_credits', {
1875
+ startkey: [uid, ''],
1876
+ endkey: [uid, 'zzz'],
1877
+ reduce: true,
1878
+ group_level: 999,
1879
+ });
1872
1880
 
1873
1881
  let data = { credits: { membership_plan, ai_workspace_plan, contact_connection, total: total_credits }, usage: { profile, projects: [], total: total_usage } };
1874
1882
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1548",
3
+ "version": "1.2.1550",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {