@umituz/react-native-ai-pruna-provider 1.0.26 → 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.26",
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,45 +53,54 @@ export async function uploadFileToStorage(
57
53
  });
58
54
  }
59
55
 
60
- // Detect MIME type BEFORE creating temp file (needed for FormData)
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;
60
+ }
61
+
62
+ // Detect MIME type
61
63
  const mimeType = detectMimeType(base64Data);
62
64
  const extension = getExtensionForMime(mimeType);
63
65
  const filename = `upload.${extension}`;
64
66
 
65
- // Use design system filesystem to create temp file (React Native compatible)
66
- const tempUri = await base64ToTempFile(base64Data, filename);
67
+ // Strip data URI prefix if present to get raw base64
68
+ const rawBase64 = base64Data.includes('base64,')
69
+ ? base64Data.split('base64,')[1]
70
+ : base64Data;
67
71
 
68
- if (!tempUri) {
69
- throw new Error("Failed to create temporary file from base64 data");
70
- }
72
+ // Add data URI prefix for proper encoding
73
+ const dataUri = `data:${mimeType};base64,${rawBase64}`;
71
74
 
72
- generationLogCollector.log(sessionId, TAG, `Temp file created, uploading to Pruna as ${filename}...`);
75
+ generationLogCollector.log(sessionId, TAG, `Uploading as data URI (${mimeType}, ${extension})...`);
73
76
 
74
- // __DEV__ detailed file info
77
+ // __DEV__ log upload details
75
78
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
76
- console.log(`[DEV] [${TAG}] File details:`, {
77
- tempUri,
78
- filename,
79
+ console.log(`[DEV] [${TAG}] Data URI upload:`, {
79
80
  mimeType,
80
81
  extension,
82
+ filename,
83
+ base64Length: rawBase64.length,
84
+ dataUriPrefix: dataUri.substring(0, 50) + '...',
81
85
  });
82
86
  }
83
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
+
84
94
  try {
85
- // React Native FormData file upload format (uri + type + name)
95
+ // Create FormData with data URI string (React Native compatible)
86
96
  const formData = new FormData();
87
- formData.append('content', {
88
- uri: tempUri,
89
- type: mimeType,
90
- name: filename,
91
- } as any);
97
+ formData.append('content', dataUri);
92
98
 
93
99
  // __DEV__ log FormData
94
100
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
95
- console.log(`[DEV] [${TAG}] FormData created (RN file format):`, {
96
- filename,
97
- mimeType,
101
+ console.log(`[DEV] [${TAG}] FormData created (data URI format):`, {
98
102
  hasContent: formData.has('content'),
103
+ dataUriLength: dataUri.length,
99
104
  });
100
105
  }
101
106
 
@@ -137,12 +142,7 @@ export async function uploadFileToStorage(
137
142
  clearTimeout(timeoutId);
138
143
  }
139
144
  } finally {
140
- // Cleanup temp file
141
- try {
142
- await deleteTempFile(tempUri);
143
- } catch (cleanupError) {
144
- generationLogCollector.warn(sessionId, TAG, `Failed to delete temp file: ${cleanupError}`);
145
- }
145
+ // No temp file cleanup needed (using data URI directly)
146
146
  }
147
147
  }
148
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;