@xuda.io/ai_module 1.1.4551 → 1.1.4553

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 +0 -108
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -6067,73 +6067,6 @@ const create_ai_agent_image = async function (req, job_id, headers) {
6067
6067
  const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
6068
6068
  const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`);
6069
6069
 
6070
- // async function normalizeBase64To1024(base64Image) {
6071
- // const inputBuffer = Buffer.from(base64Image, 'base64');
6072
-
6073
- // const normalizedBuffer = await sharp(inputBuffer)
6074
- // .resize(1024, 1024, {
6075
- // fit: 'contain', // Preserve aspect ratio, fit within 211x211
6076
- // background: { r: 0, g: 0, b: 0, alpha: 0 }, // Transparent background for padding
6077
- // })
6078
- // .png({
6079
- // quality: 100,
6080
- // compressionLevel: 9,
6081
- // force: true,
6082
- // })
6083
- // .toBuffer();
6084
-
6085
- // return normalizedBuffer.toString('base64'); // Return normalized base64 string
6086
- // }
6087
-
6088
- // async function hasTransparentBackground(filePath) {
6089
- // const image = sharp(filePath);
6090
- // const metadata = await image.metadata();
6091
-
6092
- // // If the image doesn't have an alpha channel at all → no transparency possible
6093
- // if (!metadata.hasAlpha) {
6094
- // return false;
6095
- // }
6096
-
6097
- // // For images with alpha channel, check if any pixel actually has alpha < 255
6098
- // const { data, info } = await image.raw().toBuffer({ resolveWithObject: true });
6099
-
6100
- // // Determine position of alpha channel based on number of channels
6101
- // const channels = info.channels; // 2 (grayscale+alpha), 4 (RGBA), etc.
6102
- // const alphaOffset = channels === 2 ? 1 : channels === 4 ? 3 : -1;
6103
-
6104
- // if (alphaOffset === -1) {
6105
- // // Unusual channel count – be conservative and assume it might have transparency
6106
- // return true;
6107
- // }
6108
-
6109
- // for (let i = alphaOffset; i < data.length; i += channels) {
6110
- // if (data[i] < 255) {
6111
- // return true; // Found at least one transparent/semi-transparent pixel
6112
- // }
6113
- // }
6114
-
6115
- // return false; // Has alpha channel but all pixels are fully opaque
6116
- // }
6117
-
6118
- // async function imageToPngBlob(filePath) {
6119
- // const ext = path.extname(filePath).toLowerCase();
6120
-
6121
- // let buffer;
6122
-
6123
- // let is_transparent = false;
6124
- // if (ext === '.png') {
6125
- // buffer = await fs.promises.readFile(filePath);
6126
- // is_transparent = await hasTransparentBackground(filePath);
6127
- // } else {
6128
- // console.log(`Converting ${path.basename(filePath)} to PNG...`);
6129
- // buffer = await sharp(filePath).png({ quality: 100, compressionLevel: 9, force: true }).toBuffer();
6130
- // }
6131
-
6132
- // // Create a Blob with correct MIME type
6133
-
6134
- // return { is_transparent, image_blob: new Blob([buffer], { type: 'image/png' }) };
6135
- // }
6136
-
6137
6070
  const { app_id, uid, ai_agent_id, tags, account_profile_info } = req;
6138
6071
 
6139
6072
  const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, ai_agent_id);
@@ -6181,47 +6114,6 @@ const create_ai_agent_image = async function (req, job_id, headers) {
6181
6114
  let url = account_doc.account_info.profile_avatar;
6182
6115
 
6183
6116
  try {
6184
- // if (!url) {
6185
- // throw new Error('No URL provided in request');
6186
- // }
6187
-
6188
- // // 3. Download the image to a Buffer
6189
- // const res = await fetch(url);
6190
- // if (!res.ok) {
6191
- // throw new Error(`Failed to fetch image URL: ${res.status} ${res.statusText}`);
6192
- // }
6193
-
6194
- // const arrayBuffer = await res.arrayBuffer();
6195
- // const imageBuffer = Buffer.from(arrayBuffer);
6196
-
6197
- // const tempDir = os.tmpdir();
6198
- // const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
6199
-
6200
- // const inputExt = path.extname(url) || '.jpg';
6201
- // const tempInputPath = path.join(tempDir, `input_${uniqueId}${inputExt}`);
6202
- // const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`); // Output is always PNG (transparent)
6203
-
6204
- // 5. Write the downloaded image to disk
6205
- // fs.writeFileSync(tempInputPath, imageBuffer);
6206
- /////////////////////////////////
6207
-
6208
- // const imageFiles = [tempInputPath];
6209
-
6210
- // const images = await Promise.all(
6211
- // imageFiles.map(async (filePath) => {
6212
- // const img_ret = await imageToPngBlob(filePath);
6213
- // const blob = img_ret.image_blob;
6214
-
6215
- // // OpenAI expects a filename for logging/debugging
6216
- // const filename = path.basename(filePath, path.extname(filePath)) + '.png';
6217
- // blob.name = filename; // Optional but helpful
6218
- // // @ts-ignore – name is allowed in Node 20+
6219
- // blob.lastModified = Date.now();
6220
-
6221
- // return { is_transparent: img_ret.is_transparent, image_blob: blob };
6222
- // }),
6223
- // );
6224
-
6225
6117
  let imageBase64;
6226
6118
  const image_blob_ret = await get_image_blob_from_downloaded_image(url);
6227
6119
  //////////////////
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4551",
3
+ "version": "1.1.4553",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",