@umituz/react-native-ai-fal-provider 3.2.27 → 3.2.28

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-fal-provider",
3
- "version": "3.2.27",
3
+ "version": "3.2.28",
4
4
  "description": "FAL AI provider for React Native - implements IAIProvider interface for unified AI generation",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -84,75 +84,73 @@ export async function preprocessInput(
84
84
  }
85
85
 
86
86
 
87
- // Handle image_urls array (for multi-person generation)
88
- if (Array.isArray(result.image_urls) && result.image_urls.length > 0) {
89
- const imageUrls = result.image_urls as unknown[];
90
- const uploadTasks: Array<{ index: number; url: string | Promise<string> }> = [];
91
- const errors: string[] = [];
92
-
93
- for (let i = 0; i < imageUrls.length; i++) {
94
- const imageUrl = imageUrls[i];
95
-
96
- if (!imageUrl) {
97
- errors.push(`image_urls[${i}] is null or undefined`);
98
- continue;
87
+ // Handle image URL arrays (image_urls, input_image_urls)
88
+ for (const arrayField of ["image_urls", "input_image_urls"] as const) {
89
+ if (Array.isArray(result[arrayField]) && (result[arrayField] as unknown[]).length > 0) {
90
+ const imageUrls = result[arrayField] as unknown[];
91
+ const uploadTasks: Array<{ index: number; url: string | Promise<string> }> = [];
92
+ const errors: string[] = [];
93
+
94
+ for (let i = 0; i < imageUrls.length; i++) {
95
+ const imageUrl = imageUrls[i];
96
+
97
+ if (!imageUrl) {
98
+ errors.push(`${arrayField}[${i}] is null or undefined`);
99
+ continue;
100
+ }
101
+
102
+ if (isBase64DataUri(imageUrl)) {
103
+ const uploadPromise = uploadToFalStorage(imageUrl)
104
+ .then((url) => url)
105
+ .catch((error) => {
106
+ const errorMessage = `Failed to upload ${arrayField}[${i}]: ${getErrorMessage(error)}`;
107
+ console.error(`[preprocessInput] ${errorMessage}`);
108
+ errors.push(errorMessage);
109
+ throw new Error(errorMessage);
110
+ });
111
+ uploadTasks.push({ index: i, url: uploadPromise });
112
+ } else if (typeof imageUrl === "string") {
113
+ uploadTasks.push({ index: i, url: imageUrl });
114
+ } else {
115
+ errors.push(`${arrayField}[${i}] has invalid type: ${typeof imageUrl}`);
116
+ }
99
117
  }
100
118
 
101
- if (isBase64DataUri(imageUrl)) {
102
- const uploadPromise = uploadToFalStorage(imageUrl)
103
- .then((url) => url)
104
- .catch((error) => {
105
- const errorMessage = `Failed to upload image_urls[${i}]: ${getErrorMessage(error)}`;
106
- console.error(`[preprocessInput] ${errorMessage}`);
107
- errors.push(errorMessage);
108
- throw new Error(errorMessage);
109
- });
110
- uploadTasks.push({ index: i, url: uploadPromise });
111
- } else if (typeof imageUrl === "string") {
112
- uploadTasks.push({ index: i, url: imageUrl });
113
- } else {
114
- errors.push(`image_urls[${i}] has invalid type: ${typeof imageUrl}`);
119
+ if (errors.length > 0) {
120
+ throw new Error(`Image URL validation failed:\n${errors.join('\n')}`);
115
121
  }
116
- }
117
-
118
- if (errors.length > 0) {
119
- throw new Error(`Image URL validation failed:\n${errors.join('\n')}`);
120
- }
121
122
 
122
- // Validate that we have at least one valid image URL
123
- if (uploadTasks.length === 0) {
124
- throw new Error('image_urls array must contain at least one valid image URL');
125
- }
126
-
127
- // Wait for all uploads using Promise.allSettled to handle failures gracefully
128
- // This ensures all uploads complete before reporting errors
129
- const uploadResults = await Promise.allSettled(
130
- uploadTasks.map((task) => Promise.resolve(task.url))
131
- );
123
+ if (uploadTasks.length === 0) {
124
+ throw new Error(`${arrayField} array must contain at least one valid image URL`);
125
+ }
132
126
 
133
- const processedUrls: string[] = [];
134
- const uploadErrors: string[] = [];
127
+ const uploadResults = await Promise.allSettled(
128
+ uploadTasks.map((task) => Promise.resolve(task.url))
129
+ );
135
130
 
136
- uploadResults.forEach((result, index) => {
137
- if (result.status === 'fulfilled') {
138
- processedUrls.push(result.value);
139
- } else {
140
- uploadErrors.push(
141
- `Upload ${index} failed: ${getErrorMessage(result.reason)}`
131
+ const processedUrls: string[] = [];
132
+ const uploadErrors: string[] = [];
133
+
134
+ uploadResults.forEach((uploadResult, index) => {
135
+ if (uploadResult.status === 'fulfilled') {
136
+ processedUrls.push(uploadResult.value);
137
+ } else {
138
+ uploadErrors.push(
139
+ `Upload ${index} failed: ${getErrorMessage(uploadResult.reason)}`
140
+ );
141
+ }
142
+ });
143
+
144
+ if (uploadErrors.length > 0) {
145
+ console.warn(
146
+ `[input-preprocessor] ${processedUrls.length} of ${uploadTasks.length} uploads succeeded. ` +
147
+ 'Successful uploads remain in FAL storage.'
142
148
  );
149
+ throw new Error(`Image upload failures:\n${uploadErrors.join('\n')}`);
143
150
  }
144
- });
145
151
 
146
- // If any uploads failed, throw with details
147
- if (uploadErrors.length > 0) {
148
- console.warn(
149
- `[input-preprocessor] ${processedUrls.length} of ${uploadTasks.length} uploads succeeded. ` +
150
- 'Successful uploads remain in FAL storage.'
151
- );
152
- throw new Error(`Image upload failures:\n${uploadErrors.join('\n')}`);
152
+ result[arrayField] = processedUrls;
153
153
  }
154
-
155
- result.image_urls = processedUrls;
156
154
  }
157
155
 
158
156
  // Wait for ALL uploads to complete (both individual keys and array)