@umituz/react-native-ai-pruna-provider 1.0.25 → 1.0.27

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-pruna-provider",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Pruna AI provider for React Native - implements IAIProvider interface for unified AI generation",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -33,7 +33,6 @@
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@umituz/react-native-ai-generation-content": ">=1.70.0",
36
- "@umituz/react-native-design-system": ">=1.0.0",
37
36
  "expo": ">=54.0.0",
38
37
  "react": ">=19.0.0",
39
38
  "react-native": ">=0.81.4"
@@ -16,10 +16,6 @@ import { PRUNA_BASE_URL, PRUNA_PREDICTIONS_URL, PRUNA_FILES_URL, UPLOAD_CONFIG }
16
16
  import { generationLogCollector } from "../utils/log-collector";
17
17
  import { detectMimeType } from "../utils/mime-detection.util";
18
18
  import { getExtensionForMime } from "../utils/constants/mime.constants";
19
- import {
20
- base64ToTempFile,
21
- deleteTempFile,
22
- } from "@umituz/react-native-design-system/filesystem";
23
19
 
24
20
  const TAG = 'pruna-api';
25
21
 
@@ -57,46 +53,54 @@ export async function uploadFileToStorage(
57
53
  });
58
54
  }
59
55
 
60
- // Use design system filesystem to create temp file (React Native compatible)
61
- const tempUri = await base64ToTempFile(base64Data);
62
-
63
- if (!tempUri) {
64
- throw new Error("Failed to create temporary file from base64 data");
56
+ // Already a URL return as-is
57
+ if (base64Data.startsWith('http')) {
58
+ generationLogCollector.log(sessionId, TAG, 'File already a URL, skipping upload');
59
+ return base64Data;
65
60
  }
66
61
 
67
- try {
68
- // Fetch the temp file to get a Blob
69
- const response = await fetch(tempUri);
70
- const blob = await response.blob();
62
+ // Detect MIME type
63
+ const mimeType = detectMimeType(base64Data);
64
+ const extension = getExtensionForMime(mimeType);
65
+ const filename = `upload.${extension}`;
71
66
 
72
- // Use blob's MIME type (more accurate than base64 detection)
73
- const actualMimeType = blob.type || 'image/jpeg';
74
- const extension = getExtensionForMime(actualMimeType);
75
- const filename = `upload.${extension}`;
67
+ // Strip data URI prefix if present to get raw base64
68
+ const rawBase64 = base64Data.includes('base64,')
69
+ ? base64Data.split('base64,')[1]
70
+ : base64Data;
76
71
 
77
- generationLogCollector.log(sessionId, TAG, `Temp file created (${blob.size} bytes, type: ${actualMimeType}), uploading to Pruna as ${filename}...`);
72
+ // Add data URI prefix for proper encoding
73
+ const dataUri = `data:${mimeType};base64,${rawBase64}`;
78
74
 
79
- // __DEV__ detailed blob logging
80
- if (typeof __DEV__ !== 'undefined' && __DEV__) {
81
- console.log(`[DEV] [${TAG}] Blob details:`, {
82
- tempUri,
83
- blobSize: blob.size,
84
- blobType: blob.type,
85
- actualMimeType,
86
- extension,
87
- filename,
88
- });
89
- }
75
+ generationLogCollector.log(sessionId, TAG, `Uploading as data URI (${mimeType}, ${extension})...`);
90
76
 
91
- // Create FormData with the blob AND proper filename with extension
77
+ // __DEV__ log upload details
78
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
79
+ console.log(`[DEV] [${TAG}] Data URI upload:`, {
80
+ mimeType,
81
+ extension,
82
+ filename,
83
+ base64Length: rawBase64.length,
84
+ dataUriPrefix: dataUri.substring(0, 50) + '...',
85
+ });
86
+ }
87
+
88
+ const startTime = Date.now();
89
+
90
+ // Apply timeout to prevent indefinite hangs
91
+ const uploadController = new AbortController();
92
+ const timeoutId = setTimeout(() => uploadController.abort(), UPLOAD_CONFIG.timeoutMs);
93
+
94
+ try {
95
+ // Create FormData with data URI string (React Native compatible)
92
96
  const formData = new FormData();
93
- formData.append('content', blob, filename);
97
+ formData.append('content', dataUri);
94
98
 
95
- // __DEV__ log FormData entries (if possible)
99
+ // __DEV__ log FormData
96
100
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
97
- console.log(`[DEV] [${TAG}] FormData created:`, {
101
+ console.log(`[DEV] [${TAG}] FormData created (data URI format):`, {
98
102
  hasContent: formData.has('content'),
99
- filename,
103
+ dataUriLength: dataUri.length,
100
104
  });
101
105
  }
102
106
 
@@ -138,12 +142,7 @@ export async function uploadFileToStorage(
138
142
  clearTimeout(timeoutId);
139
143
  }
140
144
  } finally {
141
- // Cleanup temp file
142
- try {
143
- await deleteTempFile(tempUri);
144
- } catch (cleanupError) {
145
- generationLogCollector.warn(sessionId, TAG, `Failed to delete temp file: ${cleanupError}`);
146
- }
145
+ // No temp file cleanup needed (using data URI directly)
147
146
  }
148
147
  }
149
148
 
@@ -135,6 +135,7 @@ async function buildImageEditInput(
135
135
  images: imageUrls,
136
136
  prompt,
137
137
  aspect_ratio: aspectRatio,
138
+ reference_image: "1", // Required by Pruna API per documentation
138
139
  };
139
140
 
140
141
  if (input.seed !== undefined) payload.seed = input.seed;