@umituz/react-native-ai-pruna-provider 1.0.15 → 1.0.18

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.15",
3
+ "version": "1.0.18",
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",
@@ -0,0 +1 @@
1
+ declare const __DEV__: boolean;
@@ -130,7 +130,30 @@ export async function submitPrediction(
130
130
  const startTime = Date.now();
131
131
 
132
132
  const requestBody = { input };
133
- generationLogCollector.log(sessionId, TAG, `Request body: ${JSON.stringify(requestBody).substring(0, 200)}...`);
133
+
134
+ // __DEV__ detailed request logging
135
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
136
+ const inputSummary: Record<string, string> = {};
137
+ for (const [key, value] of Object.entries(input)) {
138
+ if (typeof value === 'string' && value.length > 100) {
139
+ inputSummary[key] = `[string ${value.length} chars]`;
140
+ } else if (Array.isArray(value)) {
141
+ inputSummary[key] = `[array ${value.length} items]`;
142
+ } else {
143
+ inputSummary[key] = JSON.stringify(value);
144
+ }
145
+ }
146
+ console.log(`[DEV] [${TAG}] Request details:`, {
147
+ url: PRUNA_PREDICTIONS_URL,
148
+ model,
149
+ modelHeader: model,
150
+ bodyTopLevelKeys: Object.keys(requestBody),
151
+ inputKeys: Object.keys(input),
152
+ inputSummary,
153
+ });
154
+ }
155
+
156
+ generationLogCollector.log(sessionId, TAG, `Request: model=${model}, bodyKeys=${JSON.stringify(Object.keys(requestBody))}, inputKeys=${JSON.stringify(Object.keys(input))}`);
134
157
 
135
158
  const response = await fetch(PRUNA_PREDICTIONS_URL, {
136
159
  method: 'POST',
@@ -156,6 +179,18 @@ export async function submitPrediction(
156
179
 
157
180
  generationLogCollector.error(sessionId, TAG, `Prediction failed (${response.status}): ${errorMessage}`);
158
181
 
182
+ // __DEV__ detailed error logging
183
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
184
+ console.error(`[DEV] [${TAG}] Prediction FAILED:`, {
185
+ status: response.status,
186
+ statusText: response.statusText,
187
+ errorMessage,
188
+ rawBody: rawBody.substring(0, 500),
189
+ model,
190
+ inputKeys: Object.keys(input),
191
+ });
192
+ }
193
+
159
194
  const error = new Error(errorMessage);
160
195
  (error as Error & { statusCode?: number }).statusCode = response.status;
161
196
  throw error;
@@ -171,6 +206,15 @@ export async function submitPrediction(
171
206
  status: result.status,
172
207
  });
173
208
 
209
+ // __DEV__ response logging
210
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
211
+ console.log(`[DEV] [${TAG}] Prediction SUCCESS in ${elapsed}ms:`, {
212
+ hasUri: !!extractUri(result),
213
+ status: result.status,
214
+ responseKeys: Object.keys(result),
215
+ });
216
+ }
217
+
174
218
  return result;
175
219
  }
176
220
 
@@ -37,11 +37,11 @@ export async function buildModelInput(
37
37
  }
38
38
 
39
39
  if (model === 'p-image-edit') {
40
- return buildImageEditInput(prompt, aspectRatio, input, sessionId);
40
+ return await buildImageEditInput(prompt, aspectRatio, input, apiKey, sessionId);
41
41
  }
42
42
 
43
43
  if (model === 'p-video') {
44
- return buildVideoInput(prompt, aspectRatio, input, apiKey, sessionId);
44
+ return await buildVideoInput(prompt, aspectRatio, input, apiKey, sessionId);
45
45
  }
46
46
 
47
47
  throw new Error(`Unknown Pruna model: ${model}`);
@@ -62,42 +62,52 @@ function buildImageInput(
62
62
  return payload;
63
63
  }
64
64
 
65
- function buildImageEditInput(
65
+ async function buildImageEditInput(
66
66
  prompt: string,
67
67
  aspectRatio: PrunaAspectRatio,
68
68
  input: Record<string, unknown>,
69
+ apiKey: string,
69
70
  sessionId: string,
70
- ): Record<string, unknown> {
71
- // p-image-edit expects images array (base64 with data URI prefix or HTTPS URLs)
72
- // Base64 format: data:image/jpeg;base64,{base64_string}
73
- let images: string[];
74
-
75
- const ensureDataUriPrefix = (img: string): string => {
76
- if (img.startsWith('http')) return img; // Already a URL
77
- if (img.startsWith('data:')) return img; // Already has data URI prefix
78
- // Add data URI prefix for raw base64
79
- return `data:image/jpeg;base64,${img}`;
80
- };
71
+ ): Promise<Record<string, unknown>> {
72
+ // p-image-edit requires uploaded file URLs, not base64
73
+ // First upload all images to Pruna storage, then use the URLs
74
+ let rawImages: string[];
81
75
 
82
76
  if (Array.isArray(input.images)) {
83
77
  const validImages = (input.images as unknown[]).filter((img): img is string => typeof img === 'string');
84
78
  if (validImages.length === 0) {
85
79
  throw new Error("Image array is empty or contains no valid strings for p-image-edit.");
86
80
  }
87
- images = validImages.map(ensureDataUriPrefix);
81
+ rawImages = validImages;
88
82
  } else if (typeof input.image === 'string') {
89
- images = [ensureDataUriPrefix(input.image as string)];
83
+ rawImages = [input.image as string];
90
84
  } else if (typeof input.image_url === 'string') {
91
- images = [ensureDataUriPrefix(input.image_url as string)];
85
+ rawImages = [input.image_url as string];
92
86
  } else if (Array.isArray(input.image_urls)) {
93
- images = (input.image_urls as string[]).map(ensureDataUriPrefix);
87
+ rawImages = input.image_urls as string[];
94
88
  } else {
95
89
  throw new Error("Image is required for p-image-edit. Provide 'image', 'images', 'image_url', or 'image_urls'.");
96
90
  }
97
91
 
98
- generationLogCollector.log(sessionId, TAG, `p-image-edit: ${images.length} image(s) prepared`);
92
+ generationLogCollector.log(sessionId, TAG, `p-image-edit: uploading ${rawImages.length} image(s) to Pruna storage...`);
93
+
94
+ // Upload all images and get URLs
95
+ const imageUrls: string[] = [];
96
+ for (let i = 0; i < rawImages.length; i++) {
97
+ const rawImage = rawImages[i];
98
+ generationLogCollector.log(sessionId, TAG, `p-image-edit: uploading image ${i + 1}/${rawImages.length}...`);
99
+ const url = await uploadFileToStorage(rawImage, apiKey, sessionId);
100
+ imageUrls.push(url);
101
+ }
99
102
 
100
- const payload: Record<string, unknown> = { images, prompt, aspect_ratio: aspectRatio };
103
+ generationLogCollector.log(sessionId, TAG, `p-image-edit: all ${imageUrls.length} image(s) uploaded successfully`);
104
+
105
+ const payload: Record<string, unknown> = {
106
+ images: imageUrls,
107
+ prompt,
108
+ aspect_ratio: aspectRatio,
109
+ reference_image: "1", // Required by Pruna API for p-image-edit
110
+ };
101
111
 
102
112
  if (input.seed !== undefined) payload.seed = input.seed;
103
113
  if (input.disable_safety_checker !== undefined) payload.disable_safety_checker = input.disable_safety_checker;