@xuda.io/ai_module 1.1.4352 → 1.1.4354

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 +29 -27
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -5291,16 +5291,16 @@ setTimeout(async () => {
5291
5291
  // });
5292
5292
 
5293
5293
  // ret = await get_profile_image(uid, 'business', 'ioshka media', {}, account_profile_info);
5294
- ret = await get_profile_image(
5295
- uid,
5296
- 'personal',
5297
- 'Glenn Willett',
5298
- {
5299
- email: 'glennwillett@schoolsponsoringregionzft.com',
5300
- body: 'We have a couple middle and elementary schools a few minutes from you in Boca Raton that have available sponsorship slots. The parents would see your sponsorship in the student progress reports each week.Is it okay if I send over the available spots?',
5301
- },
5302
- account_profile_info,
5303
- );
5294
+ // ret = await get_profile_image(
5295
+ // uid,
5296
+ // 'personal',
5297
+ // 'Glenn Willett',
5298
+ // {
5299
+ // email: 'glennwillett@schoolsponsoringregionzft.com',
5300
+ // body: 'We have a couple middle and elementary schools a few minutes from you in Boca Raton that have available sponsorship slots. The parents would see your sponsorship in the student progress reports each week.Is it okay if I send over the available spots?',
5301
+ // },
5302
+ // account_profile_info,
5303
+ // );
5304
5304
 
5305
5305
  console.log(ret);
5306
5306
  }, 1000);
@@ -6734,7 +6734,11 @@ export const is_business_contact = async function (uid, email, name, subject, bo
6734
6734
  } catch (error) {}
6735
6735
  };
6736
6736
 
6737
- const get_profile_image = async function (uid, account_type = 'business', name, facts = {}, account_profile_info) {
6737
+ const get_profile_image = async function (uid, account_type = 'business', name, facts = {}, account_profile_info, job_id, headers) {
6738
+ const tempDir = os.tmpdir();
6739
+ const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
6740
+ const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`);
6741
+
6738
6742
  function normalizeFilename(name) {
6739
6743
  return name
6740
6744
  .toLowerCase() // lowercase
@@ -6744,7 +6748,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6744
6748
  .replace(/^_+|_+$/g, ''); // trim leading/trailing underscores
6745
6749
  }
6746
6750
 
6747
- let prompt, factual_prompt, originalname, factual_image_mode, imageBase64;
6751
+ let prompt, factual_prompt, originalname, factual_image_mode, imageBase64, image_blob, file;
6748
6752
 
6749
6753
  switch (account_type) {
6750
6754
  case 'personal': {
@@ -6777,26 +6781,26 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6777
6781
  account_profile_info,
6778
6782
  tools: [{ type: 'web_search_preview' }],
6779
6783
  });
6780
- console.log('=============', ret);
6784
+ // console.log('=============', ret);
6781
6785
 
6782
6786
  return ret.data;
6783
6787
  };
6784
6788
 
6785
- debugger;
6789
+ // debugger;
6786
6790
  try {
6787
6791
  // first attempt
6788
6792
  let url = await get_url();
6789
- if (url.substr(0, 7) !== 'https://') {
6793
+ if (url.substr(0, 8) !== 'https://') {
6790
6794
  // second attempt
6791
6795
  url = await get_url();
6792
- if (url.substr(0, 7) !== 'https://') {
6796
+ if (url.substr(0, 8) !== 'https://') {
6793
6797
  factual_image_mode = true;
6794
6798
  }
6795
6799
  } else {
6796
6800
  // success
6797
- let file;
6801
+
6798
6802
  try {
6799
- file = await get_image_blob_from_downloaded_image(url);
6803
+ image_blob = await get_image_blob_from_downloaded_image(url);
6800
6804
  } catch (err) {
6801
6805
  if (!err.message.includes('Failed to fetch image URL')) {
6802
6806
  console.error(err);
@@ -6815,7 +6819,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6815
6819
  `;
6816
6820
  const image_response = await client.images.edit({
6817
6821
  model,
6818
- image: file.image_blob, //logo
6822
+ image: image_blob,
6819
6823
  prompt,
6820
6824
  background: 'transparent',
6821
6825
  });
@@ -6823,7 +6827,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6823
6827
  imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json);
6824
6828
  }
6825
6829
  const outputBuffer = Buffer.from(imageBase64, 'base64');
6826
- const outputPath = file.tempOutputPath;
6830
+ const outputPath = tempOutputPath;
6827
6831
  await fs.promises.writeFile(outputPath, outputBuffer);
6828
6832
 
6829
6833
  console.log('Success! Saved →', outputPath);
@@ -6838,12 +6842,12 @@ const get_profile_image = async function (uid, account_type = 'business', name,
6838
6842
 
6839
6843
  const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
6840
6844
 
6841
- record_chat_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'business logo', prompt, model, { url }, account_profile_info);
6845
+ record_chat_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'profile image', prompt, model, { url }, account_profile_info);
6842
6846
 
6843
6847
  return drive_ret;
6844
6848
  } catch (err) {
6845
6849
  console.error(err);
6846
- return '';
6850
+ return;
6847
6851
  }
6848
6852
  };
6849
6853
 
@@ -6933,7 +6937,7 @@ const get_image_blob_from_downloaded_image = async function (url) {
6933
6937
 
6934
6938
  const inputExt = path.extname(url) || '.jpg';
6935
6939
  const tempInputPath = path.join(tempDir, `input_${uniqueId}${inputExt}`);
6936
- const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
6940
+ // const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
6937
6941
 
6938
6942
  // 5. Write the downloaded image to disk
6939
6943
  fs.writeFileSync(tempInputPath, imageBuffer);
@@ -6955,8 +6959,6 @@ const get_image_blob_from_downloaded_image = async function (url) {
6955
6959
  return { is_transparent: img_ret.is_transparent, image_blob: blob };
6956
6960
  }),
6957
6961
  );
6958
- return { image_blob: images[0].image_blob, is_transparent: images[0].is_transparent, tempOutputPath };
6959
- // } catch (err) {
6960
- // console.error(err);
6961
- // }
6962
+
6963
+ return images[0].image_blob;
6962
6964
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4352",
3
+ "version": "1.1.4354",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",