@umituz/react-native-ai-pruna-provider 1.0.19 → 1.0.21

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.19",
3
+ "version": "1.0.21",
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,6 +33,7 @@
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",
36
37
  "expo": ">=54.0.0",
37
38
  "react": ">=19.0.0",
38
39
  "react-native": ">=0.81.4"
@@ -16,12 +16,16 @@ 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";
19
23
 
20
24
  const TAG = 'pruna-api';
21
25
 
22
26
  /**
23
27
  * Upload a base64 file (image or audio) to Pruna's file storage.
24
- * p-video requires file URLs (not raw base64).
28
+ * Uses design system filesystem for React Native compatibility.
25
29
  * Returns the HTTPS file URL to use in predictions.
26
30
  */
27
31
  export async function uploadFileToStorage(
@@ -42,63 +46,67 @@ export async function uploadFileToStorage(
42
46
 
43
47
  generationLogCollector.log(sessionId, TAG, 'Uploading file to Pruna storage...');
44
48
 
45
- // Strip data URI prefix if present
46
- const raw = base64Data.includes('base64,') ? base64Data.split('base64,')[1] : base64Data;
49
+ // Use design system filesystem to create temp file (React Native compatible)
50
+ const tempUri = await base64ToTempFile(base64Data);
47
51
 
48
- let binaryStr: string;
49
- try {
50
- binaryStr = atob(raw);
51
- } catch {
52
- throw new Error("Invalid file format. Please provide base64 or a valid URL.");
52
+ if (!tempUri) {
53
+ throw new Error("Failed to create temporary file from base64 data");
53
54
  }
54
55
 
55
- const bytes = new Uint8Array(binaryStr.length);
56
- for (let i = 0; i < binaryStr.length; i++) {
57
- bytes[i] = binaryStr.charCodeAt(i);
58
- }
56
+ try {
57
+ // Fetch the temp file to get a Blob
58
+ const response = await fetch(tempUri);
59
+ const blob = await response.blob();
60
+ generationLogCollector.log(sessionId, TAG, `Temp file created (${blob.size} bytes), uploading to Pruna...`);
59
61
 
60
- const mime = detectMimeType(bytes);
61
- const ext = getExtensionForMime(mime);
62
- const blob = new Blob([bytes], { type: mime });
63
- const formData = new FormData();
64
- formData.append('content', blob, `upload.${ext}`);
62
+ // Create FormData with the blob
63
+ const formData = new FormData();
64
+ formData.append('content', blob, 'upload');
65
65
 
66
- const startTime = Date.now();
66
+ const startTime = Date.now();
67
67
 
68
- // Apply timeout to prevent indefinite hangs
69
- const uploadController = new AbortController();
70
- const timeoutId = setTimeout(() => uploadController.abort(), UPLOAD_CONFIG.timeoutMs);
68
+ // Apply timeout to prevent indefinite hangs
69
+ const uploadController = new AbortController();
70
+ const timeoutId = setTimeout(() => uploadController.abort(), UPLOAD_CONFIG.timeoutMs);
71
71
 
72
- try {
73
- const response = await fetch(PRUNA_FILES_URL, {
74
- method: 'POST',
75
- headers: { 'apikey': apiKey },
76
- body: formData,
77
- signal: uploadController.signal,
78
- });
72
+ try {
73
+ const uploadResponse = await fetch(PRUNA_FILES_URL, {
74
+ method: 'POST',
75
+ headers: { 'apikey': apiKey },
76
+ body: formData,
77
+ signal: uploadController.signal,
78
+ });
79
79
 
80
- if (!response.ok) {
81
- const err = await response.json().catch(() => ({ message: response.statusText }));
82
- const errorMessage = (err as { message?: string }).message || `File upload error: ${response.status}`;
83
- generationLogCollector.error(sessionId, TAG, `File upload failed: ${errorMessage}`);
84
- throw new Error(errorMessage);
85
- }
80
+ if (!uploadResponse.ok) {
81
+ const err = await uploadResponse.json().catch(() => ({ message: uploadResponse.statusText }));
82
+ const errorMessage = (err as { message?: string }).message || `File upload error: ${uploadResponse.status}`;
83
+ generationLogCollector.error(sessionId, TAG, `File upload failed: ${errorMessage}`);
84
+ throw new Error(errorMessage);
85
+ }
86
86
 
87
- const data: PrunaFileUploadResponse = await response.json();
88
- const fileUrl = data.urls?.get || `${PRUNA_FILES_URL}/${data.id}`;
87
+ const data: PrunaFileUploadResponse = await uploadResponse.json();
88
+ const fileUrl = data.urls?.get || `${PRUNA_FILES_URL}/${data.id}`;
89
89
 
90
- const elapsed = Date.now() - startTime;
91
- generationLogCollector.log(sessionId, TAG, `File upload completed in ${elapsed}ms → ${fileUrl}`);
90
+ const elapsed = Date.now() - startTime;
91
+ generationLogCollector.log(sessionId, TAG, `File upload completed in ${elapsed}ms → ${fileUrl}`);
92
92
 
93
- return fileUrl;
94
- } catch (error) {
95
- if (error instanceof Error && error.name === 'AbortError') {
96
- generationLogCollector.error(sessionId, TAG, `File upload timed out after ${UPLOAD_CONFIG.timeoutMs}ms`);
97
- throw new Error(`File upload timed out after ${UPLOAD_CONFIG.timeoutMs}ms`);
93
+ return fileUrl;
94
+ } catch (error) {
95
+ if (error instanceof Error && error.name === 'AbortError') {
96
+ generationLogCollector.error(sessionId, TAG, `File upload timed out after ${UPLOAD_CONFIG.timeoutMs}ms`);
97
+ throw new Error(`File upload timed out after ${UPLOAD_CONFIG.timeoutMs}ms`);
98
+ }
99
+ throw error;
100
+ } finally {
101
+ clearTimeout(timeoutId);
98
102
  }
99
- throw error;
100
103
  } finally {
101
- clearTimeout(timeoutId);
104
+ // Cleanup temp file
105
+ try {
106
+ await deleteTempFile(tempUri);
107
+ } catch (cleanupError) {
108
+ generationLogCollector.warn(sessionId, TAG, `Failed to delete temp file: ${cleanupError}`);
109
+ }
102
110
  }
103
111
  }
104
112