@xuda.io/ai_module 1.1.4250 → 1.1.4252

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 -8
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -5120,7 +5120,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5120
5120
  const output = await runner.run(_agent, prompt, opt);
5121
5121
  const done = async function (output) {
5122
5122
  try {
5123
- const obj = { id: output?.output?.[0]?.id, ts: Date.now(), ai_agent_id: output.state._currentAgent.name, attachments, conversation_type: 'ai_chat' };
5123
+ const obj = { id: output.state._lastTurnResponse.responseId, ts: Date.now(), ai_agent_id: output.state._currentAgent.name, attachments, conversation_type: 'ai_chat' };
5124
5124
  conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
5125
5125
 
5126
5126
  conversation_doc.ts = Date.now();
@@ -5134,11 +5134,22 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5134
5134
  inputTokens += item.usage.inputTokens;
5135
5135
  outputTokens += item.usage.outputTokens;
5136
5136
  }
5137
- debugger;
5137
+
5138
5138
  await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
5139
- // await db_module.save_app_couch_doc_native(account_profile_info.app_id, { _id: obj.id, stat: 3, docType: 'chat_conversation_item', uid, conversation_type: obj.conversation_type, date_created_ts: obj.ts, conversation_id, response: output.output });
5139
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, {
5140
+ _id: obj.id,
5141
+ stat: 3,
5142
+ docType: 'chat_conversation_item',
5143
+ uid,
5144
+ conversation_type: obj.conversation_type,
5145
+ date_created_ts: obj.ts,
5146
+ conversation_id,
5147
+ output: output.output,
5148
+ prompt,
5149
+ response: output.state._currentStep.output,
5150
+ });
5140
5151
 
5141
- record_chat_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: obj.ai_agent_id, item_id: obj.id });
5152
+ record_chat_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: obj.ai_agent_id, item_id: obj.id }, account_profile_info);
5142
5153
  // if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
5143
5154
  // update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
5144
5155
  // }
@@ -5764,7 +5775,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5764
5775
  background: 'transparent',
5765
5776
  });
5766
5777
  imageBase64 = ai_avatar_response.data[0].b64_json;
5767
- record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url });
5778
+ record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url }, account_profile_info);
5768
5779
  } else {
5769
5780
  //////////////////
5770
5781
  imageBase64 = Buffer.from(await images[0].image_blob.arrayBuffer()).toString('base64');
@@ -5842,7 +5853,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5842
5853
  The background should be fully removed, remove trees,clouds,sky or any landscape objects`,
5843
5854
  background: 'transparent',
5844
5855
  });
5845
- record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url });
5856
+ record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url }, account_profile_info);
5846
5857
  imageBase64 = ai_avatar_response.data[0].b64_json;
5847
5858
  avatar_source = 'fictional';
5848
5859
  } else {
@@ -5859,7 +5870,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5859
5870
  Context: ${JSON.stringify({ first_name, last_name, bio, country, mainCategory, subCategory })}`,
5860
5871
  background: 'transparent',
5861
5872
  });
5862
- record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url });
5873
+ record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url }, account_profile_info);
5863
5874
  imageBase64 = ai_avatar_response.data[0].b64_json;
5864
5875
  avatar_source = 'ai profile';
5865
5876
  };
@@ -6313,7 +6324,7 @@ const create_ai_agent_image = async function (req, job_id, headers) {
6313
6324
  background: 'transparent',
6314
6325
  });
6315
6326
  imageBase64 = ai_avatar_response.data[0].b64_json;
6316
- record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'agent avatar', prompt, model, { ai_agent_id });
6327
+ record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'agent avatar', prompt, model, { ai_agent_id }, account_profile_info);
6317
6328
  console.log('Normalizing final avatar to 1024 with transparent padding...');
6318
6329
  imageBase64 = await normalizeBase64To1024(imageBase64);
6319
6330
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4250",
3
+ "version": "1.1.4252",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",