n8n-nodes-vlm 2.0.2 → 2.0.4

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.
@@ -266,7 +266,10 @@ class VLMComplexityWorkflow {
266
266
  documents = items.map((item, index) => {
267
267
  const doc = {
268
268
  pageContent: JSON.stringify(item.json),
269
- metadata: { _itemIndex: index },
269
+ metadata: {
270
+ _itemIndex: index,
271
+ _originalBinary: item.binary, // Preserve original binary data
272
+ },
270
273
  };
271
274
  // Extract binary image data from n8n item.binary
272
275
  if (item.binary) {
@@ -279,6 +282,7 @@ class VLMComplexityWorkflow {
279
282
  // Add base64 image with data URI format
280
283
  if (base64Data) {
281
284
  doc.base64Image = `data:${data.mimeType};base64,${base64Data}`;
285
+ doc.metadata._binaryKey = binaryKey; // Remember which binary key was used
282
286
  this.logger.debug(`Extracted image from binary '${binaryKey}' (${data.mimeType}) for item ${index}`);
283
287
  break; // Use first image found
284
288
  }
@@ -332,21 +336,67 @@ class VLMComplexityWorkflow {
332
336
  // Format output based on outputFormat option
333
337
  if (outputFormat === 'items') {
334
338
  // Return each document as a separate item
335
- return [classifiedDocs.map((doc) => ({ json: doc }))];
339
+ return [
340
+ classifiedDocs.map((doc) => {
341
+ // Flatten structure for better n8n usability
342
+ const flattenedJson = {
343
+ // Classification results (top level for visibility)
344
+ complexityClass: doc._complexityClass,
345
+ complexityConfidence: doc._complexityConfidence,
346
+ processingTime: doc._processingTime,
347
+ modelUsed: doc._modelUsed,
348
+ // Document content
349
+ content: doc.pageContent,
350
+ // Original metadata (if any)
351
+ ...(doc.metadata && doc.metadata._itemIndex !== undefined ? { itemIndex: doc.metadata._itemIndex } : {}),
352
+ ...(doc._originalIndex !== undefined ? { originalIndex: doc._originalIndex } : {}),
353
+ };
354
+ const outputItem = { json: flattenedJson };
355
+ // Restore original binary data if it was preserved
356
+ if (doc.metadata && doc.metadata._originalBinary) {
357
+ outputItem.binary = doc.metadata._originalBinary;
358
+ }
359
+ return outputItem;
360
+ }),
361
+ ];
336
362
  }
337
363
  else if (outputFormat === 'original') {
338
- // Maintain original structure but add classifications
339
- const outputItems = items.map((item) => ({
340
- json: {
364
+ // Maintain original structure but add flattened classification metadata
365
+ const outputItems = items.map((item, index) => {
366
+ // Find classification for this item
367
+ const itemClassification = classifiedDocs.find((doc) => { var _a; return ((_a = doc.metadata) === null || _a === void 0 ? void 0 : _a._itemIndex) === index || doc._originalIndex === index; });
368
+ const enhancedJson = {
341
369
  ...item.json,
342
- _classifications: classifiedDocs,
343
- },
344
- }));
370
+ };
371
+ // Add classification metadata at top level
372
+ if (itemClassification) {
373
+ enhancedJson.complexityClass = itemClassification._complexityClass;
374
+ enhancedJson.complexityConfidence = itemClassification._complexityConfidence;
375
+ enhancedJson.processingTime = itemClassification._processingTime;
376
+ enhancedJson.modelUsed = itemClassification._modelUsed;
377
+ }
378
+ return {
379
+ json: enhancedJson,
380
+ binary: item.binary, // Preserve original binaries
381
+ };
382
+ });
345
383
  return [outputItems];
346
384
  }
347
385
  else {
348
- // Default: return documents array
349
- return [[{ json: { documents: classifiedDocs } }]];
386
+ // Default: return documents array with flattened structure
387
+ const flattenedDocs = classifiedDocs.map((doc) => {
388
+ var _a;
389
+ return ({
390
+ complexityClass: doc._complexityClass,
391
+ complexityConfidence: doc._complexityConfidence,
392
+ processingTime: doc._processingTime,
393
+ modelUsed: doc._modelUsed,
394
+ content: doc.pageContent,
395
+ itemIndex: (_a = doc.metadata) === null || _a === void 0 ? void 0 : _a._itemIndex,
396
+ originalIndex: doc._originalIndex,
397
+ });
398
+ });
399
+ return [[{ json: { documents: flattenedDocs } }]];
350
400
  }
351
401
  }
352
402
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-vlm",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Vision-Language Models for n8n - Lightweight specialized VLMs for document analysis and classification",
5
5
  "main": "index.js",
6
6
  "author": "Gabriel BRUMENT",