@xuda.io/ai_module 1.1.3824 → 1.1.3826

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 +11 -11
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -423,10 +423,7 @@ const create_landing_page_tool = tool({
423
423
  throw new Error(`table have at least one index id`);
424
424
  }
425
425
 
426
- const title_ret = await submit_chat_gpt_prompt({
427
- prompt: `create title for ${subject} return 5 words result maximum text only without options `,
428
- model: 'gpt-5-nano',
429
- });
426
+ const title_ret = await submit_chat_gpt_prompt({ uid, prompt: `create title for ${subject} return 5 words result maximum text only without options `, model: 'gpt-5-nano' });
430
427
 
431
428
  const menuType = 'component';
432
429
  const parentId = 'programs';
@@ -480,6 +477,7 @@ const create_landing_page_tool = tool({
480
477
  }
481
478
 
482
479
  const html_ret = await submit_chat_gpt_prompt({
480
+ uid,
483
481
  prompt: `Create a single-page landing layout with a Tailwind-styled contact form (fields: ${JSON.stringify(contactFormFields)}, subject: ${subject}). No navigation. Return only the <body> content. contact info:${JSON.stringify(account_info)} ${JSON.stringify(app_obj.app_general_prop)}`,
484
482
  model: 'gpt-5-nano',
485
483
  });
@@ -2903,6 +2901,7 @@ const upload_agent_files = async function (uid, agent_doc) {
2903
2901
  const arrayBuffer = await response.arrayBuffer();
2904
2902
  const base64Image = Buffer.from(arrayBuffer).toString('base64');
2905
2903
  const ret = await submit_chat_gpt_prompt({
2904
+ uid,
2906
2905
  prompt: [
2907
2906
  {
2908
2907
  role: 'user',
@@ -3977,7 +3976,7 @@ export const delete_prompt_attachment = async function (req, job_id, headers, fi
3977
3976
  };
3978
3977
 
3979
3978
  export const submit_chat_gpt_prompt = async function (req) {
3980
- const { model = 'gpt-5-mini', prompt, response_format } = req;
3979
+ const { model = 'gpt-5-mini', prompt, response_format, uid } = req;
3981
3980
 
3982
3981
  let formattedParams;
3983
3982
  if (response_format) {
@@ -4052,10 +4051,7 @@ export const create_conversation = async function (req, job_id, headers) {
4052
4051
 
4053
4052
  setTimeout(async () => {
4054
4053
  // Ask GPT for title
4055
- const title = await submit_chat_gpt_prompt({
4056
- prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`,
4057
- model: 'gpt-5-nano',
4058
- });
4054
+ const title = await submit_chat_gpt_prompt({ uid, prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`, model: 'gpt-5-nano' });
4059
4055
 
4060
4056
  conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_obj.id);
4061
4057
  conversation_doc.title = title.data;
@@ -4148,6 +4144,7 @@ const update_conversation_mood_level = async function (conversation_id, prompt,
4148
4144
  try {
4149
4145
  // analyze the mood of the conversation
4150
4146
  const mood_level = await submit_chat_gpt_prompt({
4147
+ uid,
4151
4148
  prompt: `analyze the mood of the following prompt: ${prompt}. return -2: very negative,-1: negative 0:natural 1:positive 2: very positive.`,
4152
4149
  model: 'gpt-5-nano',
4153
4150
  response_format: z.object({
@@ -4901,6 +4898,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4901
4898
  const base64 = fileBuffer.toString('base64');
4902
4899
 
4903
4900
  const ret = await submit_chat_gpt_prompt({
4901
+ uid,
4904
4902
  prompt: [
4905
4903
  {
4906
4904
  role: 'user',
@@ -4932,6 +4930,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4932
4930
  const base64 = fileBuffer.toString('base64');
4933
4931
 
4934
4932
  const ret = await submit_chat_gpt_prompt({
4933
+ uid,
4935
4934
  prompt: [
4936
4935
  {
4937
4936
  role: 'user',
@@ -5060,14 +5059,14 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5060
5059
  const output = await runner.run(_agent, prompt, opt);
5061
5060
  const done = async function (output) {
5062
5061
  try {
5063
- const obj = { id: output?.output?.[0]?.id, ts: Date.now(), usage: { inputTokens: output.state._context.usage.inputTokens, outputTokens: output.state._context.usage.outputTokens }, ai_agent_id: output.state._currentAgent.name, attachments };
5062
+ const obj = { id: output?.output?.[0]?.id, ts: Date.now(), ai_agent_id: output.state._currentAgent.name, attachments };
5064
5063
  conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
5065
5064
 
5066
5065
  conversation_doc.ts = Date.now();
5067
5066
  conversation_doc.stat = 3;
5068
5067
  conversation_doc.messages.push(obj);
5069
5068
  await db_module.save_app_couch_doc_native(app_id, conversation_doc);
5070
-
5069
+ record_chat_usage(uid, output.state._context.usage.inputTokens, output.state._context.usage.outputTokens, 'submit chat', prompt);
5071
5070
  // if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
5072
5071
  // update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
5073
5072
  // }
@@ -5590,6 +5589,7 @@ export const convert_profile_image_to_avatar = async function (req, job_id, head
5590
5589
 
5591
5590
  const detect_real_person_in_image = async function (base64) {
5592
5591
  const ret = await submit_chat_gpt_prompt({
5592
+ uid,
5593
5593
  model: 'gpt-5-nano',
5594
5594
  prompt: [
5595
5595
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.3824",
3
+ "version": "1.1.3826",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",