@umituz/react-native-ai-pruna-provider 1.0.26 → 1.0.28

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