@umituz/react-native-ai-pruna-provider 1.0.29 → 1.0.31

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.29",
3
+ "version": "1.0.31",
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",
@@ -86,15 +86,27 @@ export async function uploadFileToStorage(
86
86
  const timeoutId = setTimeout(() => uploadController.abort(), UPLOAD_CONFIG.timeoutMs);
87
87
 
88
88
  try {
89
- // Create FormData with data URI string (React Native compatible)
89
+ // Create FormData with file object format (React Native compatible)
90
90
  const formData = new FormData();
91
- formData.append('content', dataUri);
91
+
92
+ // React Native expects {uri, type, name} format for file uploads
93
+ const fileObject = {
94
+ uri: dataUri,
95
+ type: mimeType,
96
+ name: 'upload.jpg',
97
+ } as any;
98
+
99
+ formData.append('content', fileObject);
92
100
 
93
101
  // __DEV__ log FormData
94
102
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
95
- console.log(`[DEV] [${TAG}] FormData created (data URI format):`, {
103
+ console.log(`[DEV] [${TAG}] FormData created (file object format):`, {
96
104
  hasContent: formData.has('content'),
97
- dataUriLength: dataUri.length,
105
+ fileObject: {
106
+ uri: fileObject.uri.substring(0, 50) + '...',
107
+ type: fileObject.type,
108
+ name: fileObject.name,
109
+ },
98
110
  });
99
111
  }
100
112
 
@@ -105,6 +117,18 @@ export async function uploadFileToStorage(
105
117
  const timeoutId = setTimeout(() => uploadController.abort(), UPLOAD_CONFIG.timeoutMs);
106
118
 
107
119
  try {
120
+ // __DEV__ log request details
121
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
122
+ console.log(`[DEV] [${TAG}] Sending upload request:`, {
123
+ url: PRUNA_FILES_URL,
124
+ method: 'POST',
125
+ headers: {
126
+ 'apikey': apiKey.substring(0, 15) + '...',
127
+ },
128
+ formDataKeys: Array.from(formData.keys()),
129
+ });
130
+ }
131
+
108
132
  const uploadResponse = await fetch(PRUNA_FILES_URL, {
109
133
  method: 'POST',
110
134
  headers: { 'apikey': apiKey },
@@ -113,9 +137,51 @@ export async function uploadFileToStorage(
113
137
  });
114
138
 
115
139
  if (!uploadResponse.ok) {
116
- const err = await uploadResponse.json().catch(() => ({ message: uploadResponse.statusText }));
117
- const errorMessage = (err as { message?: string }).message || `File upload error: ${uploadResponse.status}`;
140
+ // Get response details for debugging
141
+ const statusText = uploadResponse.statusText;
142
+ const status = uploadResponse.status;
143
+
144
+ // Try to get error details from response
145
+ let rawBody = '';
146
+ let errorDetails: Record<string, unknown> = {};
147
+
148
+ try {
149
+ rawBody = await uploadResponse.text();
150
+ if (rawBody) {
151
+ try {
152
+ errorDetails = JSON.parse(rawBody) as Record<string, unknown>;
153
+ } catch {
154
+ // If not JSON, keep raw text
155
+ }
156
+ }
157
+ } catch {
158
+ // If reading body fails, continue with status info
159
+ }
160
+
161
+ const errorMessage = (errorDetails as { message?: string; detail?: string; error?: string }).message ||
162
+ (errorDetails as { detail?: string }).detail ||
163
+ (errorDetails as { error?: string }).error ||
164
+ rawBody ||
165
+ `File upload error: ${status}`;
166
+
118
167
  generationLogCollector.error(sessionId, TAG, `File upload failed: ${errorMessage}`);
168
+
169
+ // __DEV__ detailed error logging
170
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
171
+ console.error(`[DEV] [${TAG}] File upload FAILED:`, {
172
+ status,
173
+ statusText,
174
+ errorMessage,
175
+ rawBody: rawBody.substring(0, 1000),
176
+ errorDetails,
177
+ url: PRUNA_FILES_URL,
178
+ formDataPreview: {
179
+ hasContent: formData.has('content'),
180
+ contentType: formData.get('content')?.toString().substring(0, 100) + '...',
181
+ },
182
+ });
183
+ }
184
+
119
185
  throw new Error(errorMessage);
120
186
  }
121
187
 
@@ -125,6 +191,17 @@ export async function uploadFileToStorage(
125
191
  const elapsed = Date.now() - startTime;
126
192
  generationLogCollector.log(sessionId, TAG, `File upload completed in ${elapsed}ms → ${fileUrl}`);
127
193
 
194
+ // __DEV__ log response details
195
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
196
+ console.log(`[DEV] [${TAG}] File upload SUCCESS:`, {
197
+ elapsedMs: elapsed,
198
+ fileId: data.id,
199
+ fileUrl,
200
+ urls: data.urls,
201
+ responseKeys: Object.keys(data),
202
+ });
203
+ }
204
+
128
205
  return fileUrl;
129
206
  } catch (error) {
130
207
  if (error instanceof Error && error.name === 'AbortError') {