@umituz/react-native-ai-pruna-provider 1.0.20 → 1.0.22

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.20",
3
+ "version": "1.0.22",
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,70 +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 to get raw base64
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
- // Decode base64 to get binary data
49
- let binaryStr: string;
50
- try {
51
- binaryStr = atob(raw);
52
- } catch {
53
- throw new Error("Invalid file format. Please provide base64 or a valid URL.");
54
- }
55
-
56
- // Convert to byte array for MIME detection
57
- const bytes = new Uint8Array(binaryStr.length);
58
- for (let i = 0; i < binaryStr.length; i++) {
59
- bytes[i] = binaryStr.charCodeAt(i);
52
+ if (!tempUri) {
53
+ throw new Error("Failed to create temporary file from base64 data");
60
54
  }
61
55
 
62
- const mime = detectMimeType(bytes);
63
- const ext = getExtensionForMime(mime);
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...`);
64
61
 
65
- // React Native FormData: use object format with uri (data URI)
66
- const formData = new FormData();
67
- formData.append('content', {
68
- uri: base64Data.startsWith('data:') ? base64Data : `data:${mime};base64,${raw}`,
69
- type: mime,
70
- name: `upload.${ext}`,
71
- } as any);
62
+ // Create FormData with the blob
63
+ const formData = new FormData();
64
+ formData.append('content', blob, 'upload');
72
65
 
73
- const startTime = Date.now();
66
+ const startTime = Date.now();
74
67
 
75
- // Apply timeout to prevent indefinite hangs
76
- const uploadController = new AbortController();
77
- 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);
78
71
 
79
- try {
80
- const response = await fetch(PRUNA_FILES_URL, {
81
- method: 'POST',
82
- headers: { 'apikey': apiKey },
83
- body: formData,
84
- signal: uploadController.signal,
85
- });
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
+ });
86
79
 
87
- if (!response.ok) {
88
- const err = await response.json().catch(() => ({ message: response.statusText }));
89
- const errorMessage = (err as { message?: string }).message || `File upload error: ${response.status}`;
90
- generationLogCollector.error(sessionId, TAG, `File upload failed: ${errorMessage}`);
91
- throw new Error(errorMessage);
92
- }
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
+ }
93
86
 
94
- const data: PrunaFileUploadResponse = await response.json();
95
- 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}`;
96
89
 
97
- const elapsed = Date.now() - startTime;
98
- 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}`);
99
92
 
100
- return fileUrl;
101
- } catch (error) {
102
- if (error instanceof Error && error.name === 'AbortError') {
103
- generationLogCollector.error(sessionId, TAG, `File upload timed out after ${UPLOAD_CONFIG.timeoutMs}ms`);
104
- 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);
105
102
  }
106
- throw error;
107
103
  } finally {
108
- 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
+ }
109
110
  }
110
111
  }
111
112
 
@@ -106,7 +106,6 @@ async function buildImageEditInput(
106
106
  images: imageUrls,
107
107
  prompt,
108
108
  aspect_ratio: aspectRatio,
109
- reference_image: "1", // Required by Pruna API for p-image-edit
110
109
  };
111
110
 
112
111
  if (input.seed !== undefined) payload.seed = input.seed;