@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.
|
|
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
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
// Detect MIME type
|
|
63
|
+
const mimeType = detectMimeType(base64Data);
|
|
64
|
+
const extension = getExtensionForMime(mimeType);
|
|
65
|
+
const filename = `upload.${extension}`;
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
72
|
+
// Add data URI prefix for proper encoding
|
|
73
|
+
const dataUri = `data:${mimeType};base64,${rawBase64}`;
|
|
78
74
|
|
|
79
|
-
|
|
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
|
-
|
|
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',
|
|
97
|
+
formData.append('content', dataUri);
|
|
94
98
|
|
|
95
|
-
// __DEV__ log FormData
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
|