@umituz/react-native-ai-fal-provider 2.0.14 → 2.0.16

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.
Files changed (69) hide show
  1. package/package.json +1 -1
  2. package/src/domain/entities/error.types.ts +2 -0
  3. package/src/domain/types/provider.types.ts +1 -0
  4. package/src/exports/infrastructure.ts +0 -3
  5. package/src/exports/presentation.ts +0 -9
  6. package/src/index.ts +0 -3
  7. package/src/infrastructure/services/fal-feature-models.ts +3 -1
  8. package/src/infrastructure/services/fal-provider-subscription.ts +35 -13
  9. package/src/infrastructure/services/fal-provider.ts +6 -0
  10. package/src/infrastructure/services/fal-queue-operations.ts +30 -1
  11. package/src/infrastructure/services/fal-status-mapper.ts +2 -0
  12. package/src/infrastructure/services/request-store.ts +30 -2
  13. package/src/infrastructure/utils/cost-tracker.ts +34 -8
  14. package/src/infrastructure/utils/error-mapper.ts +17 -3
  15. package/src/infrastructure/utils/image-feature-builders.util.ts +10 -5
  16. package/src/infrastructure/utils/index.ts +7 -6
  17. package/src/infrastructure/utils/input-validator.util.ts +92 -0
  18. package/src/infrastructure/utils/type-guards.util.ts +7 -3
  19. package/src/infrastructure/utils/video-feature-builders.util.ts +6 -3
  20. package/src/infrastructure/validators/nsfw-validator.ts +62 -4
  21. package/src/presentation/hooks/index.ts +3 -21
  22. package/src/presentation/hooks/use-fal-generation.ts +5 -4
  23. package/src/domain/constants/default-models.constants.README.md +0 -378
  24. package/src/domain/constants/models/image-to-video.README.md +0 -266
  25. package/src/domain/constants/models/index.README.md +0 -269
  26. package/src/domain/constants/models/text-to-image.README.md +0 -237
  27. package/src/domain/constants/models/text-to-text.README.md +0 -249
  28. package/src/domain/constants/models/text-to-video.README.md +0 -259
  29. package/src/domain/constants/models/text-to-voice.README.md +0 -264
  30. package/src/domain/entities/error.types.README.md +0 -292
  31. package/src/domain/entities/fal.types.README.md +0 -460
  32. package/src/domain/types/index.README.md +0 -229
  33. package/src/domain/types/model-selection.types.README.md +0 -311
  34. package/src/exports/registry.ts +0 -39
  35. package/src/index.README.md +0 -420
  36. package/src/infrastructure/builders/image-feature-builder.README.md +0 -435
  37. package/src/infrastructure/builders/index.ts +0 -7
  38. package/src/infrastructure/services/fal-models-service.README.md +0 -293
  39. package/src/infrastructure/services/fal-provider-subscription.README.md +0 -257
  40. package/src/infrastructure/services/fal-provider.README.md +0 -474
  41. package/src/infrastructure/services/fal-status-mapper.README.md +0 -246
  42. package/src/infrastructure/services/nsfw-content-error.README.md +0 -215
  43. package/src/infrastructure/utils/base-builders.util.README.md +0 -313
  44. package/src/infrastructure/utils/cost-tracker-queries.ts +0 -67
  45. package/src/infrastructure/utils/error-categorizer.README.md +0 -395
  46. package/src/infrastructure/utils/error-mapper.README.md +0 -367
  47. package/src/infrastructure/utils/helpers.util.README.md +0 -395
  48. package/src/infrastructure/utils/image-feature-builders.util.README.md +0 -411
  49. package/src/infrastructure/utils/index.README.md +0 -338
  50. package/src/infrastructure/utils/job-metadata/index.README.md +0 -267
  51. package/src/infrastructure/utils/job-metadata/job-metadata-format.util.README.md +0 -209
  52. package/src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.README.md +0 -311
  53. package/src/infrastructure/utils/job-metadata/job-metadata-queries.util.README.md +0 -332
  54. package/src/infrastructure/utils/job-metadata/job-metadata.types.README.md +0 -446
  55. package/src/infrastructure/utils/job-metadata.README.md +0 -268
  56. package/src/infrastructure/utils/timing-helpers.util.ts +0 -56
  57. package/src/infrastructure/utils/type-guards.util.README.md +0 -371
  58. package/src/infrastructure/validators/index.README.md +0 -205
  59. package/src/infrastructure/validators/nsfw-validator.README.md +0 -309
  60. package/src/presentation/hooks/index.README.md +0 -224
  61. package/src/presentation/hooks/use-fal-generation.README.md +0 -398
  62. package/src/presentation/hooks/use-model-capabilities.ts +0 -99
  63. package/src/presentation/hooks/use-models.README.md +0 -318
  64. package/src/registry/global-capabilities.ts +0 -75
  65. package/src/registry/index.ts +0 -50
  66. package/src/registry/model-registry.service.ts +0 -93
  67. package/src/registry/model-registry.types.ts +0 -106
  68. package/src/registry/models/index.ts +0 -6
  69. package/src/registry/models/sora-2.config.ts +0 -95
@@ -1,435 +0,0 @@
1
- # Image Features
2
-
3
- Input builder functions for image processing and editing features.
4
-
5
- **Location:** `src/infrastructure/builders/image-feature-builder.ts`
6
-
7
- ## Overview
8
-
9
- This module provides builder functions for constructing inputs to FAL AI image processing models. It supports various image features including upscaling, restoration, face swapping, background manipulation, and style transfer.
10
-
11
- ## Purpose
12
-
13
- Simplifies image feature integration by:
14
- - Providing type-safe input builders
15
- - Abstracting complex API parameter structures
16
- - Supporting consistent input formatting
17
- - Validating image data requirements
18
- - Enabling feature-specific options
19
-
20
- ## Supported Features
21
-
22
- | Feature | Model ID | Description |
23
- |---------|----------|-------------|
24
- | `upscale` | `fal-ai/clarity-upscaler` | Increase image quality and size |
25
- | `photo-restore` | `fal-ai/aura-sr` | Restore old or low-quality photos |
26
- | `face-swap` | `fal-ai/face-swap` | Swap faces between two images |
27
- | `anime-selfie` | `fal-ai/flux-pro/kontext` | Transform selfie to anime style |
28
- | `remove-background` | `fal-ai/birefnet` | Remove image background |
29
- | `remove-object` | `fal-ai/fooocus/inpaint` | Remove and inpaint objects |
30
- | `hd-touch-up` | `fal-ai/clarity-upscaler` | HD enhancement and improvement |
31
- | `replace-background` | `fal-ai/bria/background/replace` | Replace image background |
32
-
33
- ## Import
34
-
35
- ```typescript
36
- import {
37
- buildUpscaleInput,
38
- buildPhotoRestoreInput,
39
- buildFaceSwapInput,
40
- buildRemoveBackgroundInput,
41
- buildRemoveObjectInput,
42
- buildHDTouchUpInput,
43
- buildReplaceBackgroundInput,
44
- buildKontextStyleTransferInput
45
- } from '@umituz/react-native-ai-fal-provider';
46
- ```
47
-
48
- ## Builder Functions
49
-
50
- ### buildUpscaleInput
51
-
52
- Build input for image upscaling.
53
-
54
- **Parameters:**
55
- - `image`: Base64 image data or data URI
56
- - `options`: Upscale options (optional)
57
- - `scaleFactor`: 2 or 4 (default: 2)
58
- - `enhanceFaces`: Enable face enhancement (default: false)
59
-
60
- **Returns:** Formatted input object for upscaling model
61
-
62
- **Usage:**
63
- Use to increase image resolution and quality. Supports 2x and 4x scaling. Optional face enhancement for portraits.
64
-
65
- **Related:**
66
- - Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
67
-
68
- ### buildPhotoRestoreInput
69
-
70
- Build input for photo restoration.
71
-
72
- **Parameters:**
73
- - `image`: Base64 image data or data URI
74
- - `options`: Restoration options (optional)
75
- - `enhanceFaces`: Enable face enhancement (default: false)
76
-
77
- **Returns:** Formatted input object for restoration model
78
-
79
- **Usage:**
80
- Use to restore old or damaged photos. Enhances quality and sharpness. Optional face enhancement for portrait restoration.
81
-
82
- ### buildFaceSwapInput
83
-
84
- Build input for face swapping.
85
-
86
- **Parameters:**
87
- - `sourceImage`: Target image (base64 or data URI)
88
- - `targetImage`: Source image with face to swap (base64 or data URI)
89
-
90
- **Returns:** Formatted input object for face swap model
91
-
92
- **Usage:**
93
- Use to swap faces between two images. First image is target, second image provides the face.
94
-
95
- ### buildRemoveBackgroundInput
96
-
97
- Build input for background removal.
98
-
99
- **Parameters:**
100
- - `image`: Base64 image data or data URI
101
-
102
- **Returns:** Formatted input object for background removal model
103
-
104
- **Usage:**
105
- Use to remove image background automatically. Returns PNG format with transparent background.
106
-
107
- ### buildRemoveObjectInput
108
-
109
- Build input for object removal.
110
-
111
- **Parameters:**
112
- - `image`: Base64 image data or data URI
113
- - `options`: Removal options (optional)
114
- - `mask`: Base64 mask of area to remove
115
- - `prompt`: Description for fill content
116
-
117
- **Returns:** Formatted input object for object removal model
118
-
119
- **Usage:**
120
- Use to remove objects and fill the area. Provide mask to specify removal area. Prompt describes desired fill content.
121
-
122
- ### buildHDTouchUpInput
123
-
124
- Build input for HD enhancement.
125
-
126
- **Parameters:**
127
- - `image`: Base64 image data or data URI
128
- - `options`: Enhancement options (optional)
129
- - `scaleFactor`: 2 or 4 (default: 2)
130
- - `enhanceFaces`: Enable face enhancement (default: false)
131
-
132
- **Returns:** Formatted input object for HD enhancement model
133
-
134
- **Usage:**
135
- Use for high-definition image enhancement. Combines upscaling with quality improvements.
136
-
137
- ### buildReplaceBackgroundInput
138
-
139
- Build input for background replacement.
140
-
141
- **Parameters:**
142
- - `image`: Base64 image data or data URI
143
- - `options`: Replacement options
144
- - `prompt`: Description of new background
145
-
146
- **Returns:** Formatted input object for background replacement model
147
-
148
- **Usage:**
149
- Use to replace image background with AI-generated scene. Prompt describes desired new background.
150
-
151
- ### buildKontextStyleTransferInput
152
-
153
- Build input for style transfer.
154
-
155
- **Parameters:**
156
- - `image`: Base64 image data or data URI
157
- - `options`: Style transfer options
158
- - `prompt`: Style description
159
- - `guidance_scale`: Style strength (optional)
160
-
161
- **Returns:** Formatted input object for style transfer model
162
-
163
- **Usage:**
164
- Use to transform image style (e.g., anime conversion). Prompt describes desired artistic style.
165
-
166
- ## Usage Guidelines
167
-
168
- ### For Image Processing
169
-
170
- **Processing Pattern:**
171
- 1. Select appropriate builder function for feature
172
- 2. Prepare base64 image data or data URI
173
- 3. Configure options for feature
174
- 4. Build input using selected function
175
- 5. Pass input to FAL provider subscribe method
176
- 6. Handle result appropriately
177
-
178
- **Best Practices:**
179
- - Use appropriate image format (JPEG/PNG)
180
- - Ensure minimum resolution (512x512 recommended)
181
- - Use data URI format for consistency
182
- - Validate image data before building
183
- - Handle errors appropriately
184
-
185
- **Related:**
186
- - Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
187
- - Helper utilities: `src/infrastructure/utils/helpers.util.ts`
188
-
189
- ### For Face Operations
190
-
191
- **Face Swap Usage:**
192
- 1. Prepare source and target images
193
- 2. Call `buildFaceSwapInput()` with both images
194
- 3. Submit to face swap model
195
- 4. Handle swapped result
196
-
197
- **Face Enhancement:**
198
- - Use `enhanceFaces` option in upscaling
199
- - Use `enhanceFaces` option in photo restoration
200
- - Best results with clear portrait images
201
- - May not work well with group photos
202
-
203
- ### For Background Operations
204
-
205
- **Background Removal:**
206
- 1. Use `buildRemoveBackgroundInput()` with image
207
- 2. Submit to background removal model
208
- 3. Receive PNG with transparent background
209
- 4. Compose over new background if needed
210
-
211
- **Background Replacement:**
212
- 1. Use `buildReplaceBackgroundInput()` with image and prompt
213
- 2. Describe desired background clearly
214
- 3. Submit to background replacement model
215
- 4. Receive image with new background
216
-
217
- **Related:**
218
- - Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
219
-
220
- ### For Object Removal
221
-
222
- **Removal Pattern:**
223
- 1. Create mask for area to remove (white = remove, black = keep)
224
- 2. Prepare base64 image data
225
- 3. Use `buildRemoveObjectInput()` with image and mask
226
- 4. Optionally provide prompt for fill content
227
- 5. Submit to object removal model
228
- 6. Receive result with object removed and filled
229
-
230
- **Mask Creation:**
231
- - Binary mask where white (255) indicates removal area
232
- - Black (0) indicates area to preserve
233
- - Can be created programmatically or manually
234
- - Size must match input image
235
-
236
- ### For Style Transfer
237
-
238
- **Style Transfer Pattern:**
239
- 1. Prepare base64 source image
240
- 2. Write clear style description prompt
241
- 3. Use `buildKontextStyleTransferInput()` with image and prompt
242
- 4. Optionally set guidance scale for style strength
243
- 5. Submit to style transfer model
244
- 6. Receive stylized result
245
-
246
- **Prompt Writing:**
247
- - Be specific about desired style
248
- - Include artistic details and colors
249
- - Mention mood or atmosphere
250
- - Reference art styles if applicable
251
-
252
- ## Best Practices
253
-
254
- ### 1. Prepare Images Properly
255
-
256
- Ensure image quality:
257
- - Use minimum 512x512 resolution when possible
258
- - Provide clear, well-lit source images
259
- - Use appropriate image format (JPEG/PNG)
260
- - Convert to data URI format
261
- - Validate base64 encoding
262
-
263
- **Related:**
264
- - Helper utilities: `src/infrastructure/utils/helpers.util.ts`
265
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
266
-
267
- ### 2. Use Appropriate Options
268
-
269
- Configure features correctly:
270
- - Select correct scale factor for upscaling
271
- - Enable face enhancement for portraits
272
- - Provide clear prompts for AI generation
273
- - Create accurate masks for object removal
274
- - Set appropriate guidance scales
275
-
276
- ### 3. Handle Results Appropriately
277
-
278
- Process feature results:
279
- - Handle PNG format for transparent backgrounds
280
- - Compose images for background replacement
281
- - Display swapped images correctly
282
- - Show before/after comparisons
283
- - Save processed images appropriately
284
-
285
- ### 4. Validate Before Processing
286
-
287
- Check input data:
288
- - Validate base64 image format
289
- - Check image resolution requirements
290
- - Verify image data is not corrupted
291
- - Ensure correct image format
292
- - Test with sample images
293
-
294
- **Related:**
295
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
296
-
297
- ### 5. Consider Processing Time
298
-
299
- Manage user expectations:
300
- - Inform users about processing time
301
- - Show progress indicators
302
- - Handle timeouts appropriately
303
- - Queue multiple operations
304
- - Provide cancellation options
305
-
306
- ## For AI Agents
307
-
308
- ### When Using Image Builders
309
-
310
- **DO:**
311
- - Import from package root
312
- - Use appropriate builder for each feature
313
- - Validate image data before building
314
- - Use data URI format consistently
315
- - Handle feature-specific options
316
- - Check model requirements
317
- - Format images properly
318
-
319
- **DON'T:**
320
- - Use wrong builder for feature
321
- - Skip image validation
322
- - Ignore format requirements
323
- - Forget optional parameters
324
- - Assume all features same options
325
- - Process invalid images
326
- - Mix up source and target images
327
-
328
- ### When Building Inputs
329
-
330
- **DO:**
331
- - Use correct builder function
332
- - Provide required parameters
333
- - Configure options appropriately
334
- - Validate image format
335
- - Check resolution requirements
336
- - Handle base64 encoding
337
- - Test with sample images
338
-
339
- **DON'T:**
340
- - Use generic builders
341
- - Skip required parameters
342
- - Ignore model requirements
343
- - Forget data URI format
344
- - Process corrupted images
345
- - Assume default options
346
- - Mix up parameter order
347
-
348
- ### When Handling Results
349
-
350
- **DO:**
351
- - Handle PNG format for transparency
352
- - Display results appropriately
353
- - Save processed images
354
- - Show before/after when applicable
355
- - Handle errors gracefully
356
- - Validate result format
357
- - Inform user of processing time
358
-
359
- **DON'T:**
360
- - Assume JPEG format always
361
- - Display invalid results
362
- - Forget to handle transparency
363
- - Ignore feature-specific formats
364
- - Skip error handling
365
- - Lose original images
366
- - Mislead user about capabilities
367
-
368
- ### When Adding Features
369
-
370
- **For New Image Features:**
371
- 1. Add builder function to module
372
- 2. Define options interface
373
- 3. Document feature and model
374
- 4. Update exports
375
- 5. Add tests
376
- 6. Update this README
377
-
378
- **For Enhanced Options:**
379
- 1. Review existing option interfaces
380
- 2. Add new options appropriately
381
- 3. Set sensible defaults
382
- 4. Update TypeScript types
383
- 5. Document new options
384
- 6. Test with various inputs
385
-
386
- **For New Integrations:**
387
- 1. Research FAL model requirements
388
- 2. Design builder interface
389
- 3. Implement builder function
390
- 4. Test with real API
391
- 5. Document usage patterns
392
- 6. Update related code
393
-
394
- ## Implementation Notes
395
-
396
- **Location:** `src/infrastructure/builders/image-feature-builder.ts`
397
-
398
- **Dependencies:**
399
- - Uses helper utilities from `src/infrastructure/utils/helpers.util.ts`
400
- - Integrates with FAL provider
401
- - No external dependencies
402
-
403
- **Builder Categories:**
404
- - Image enhancement (upscale, photo restore, HD touch-up)
405
- - Face manipulation (face swap)
406
- - Background operations (remove, replace)
407
- - Object manipulation (remove object)
408
- - Style transfer (anime selfie)
409
-
410
- **Import:**
411
- ```typescript
412
- import {
413
- buildUpscaleInput,
414
- buildPhotoRestoreInput,
415
- buildFaceSwapInput,
416
- buildRemoveBackgroundInput,
417
- buildRemoveObjectInput,
418
- buildHDTouchUpInput,
419
- buildReplaceBackgroundInput,
420
- buildKontextStyleTransferInput
421
- } from '@umituz/react-native-ai-fal-provider';
422
- ```
423
-
424
- **Related:**
425
- - Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
426
- - Helper utilities: `src/infrastructure/utils/helpers.util.ts`
427
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
428
- - FAL provider: `src/infrastructure/services/fal-provider.ts`
429
-
430
- ## Related Documentation
431
-
432
- - [Image Feature Builders](../utils/image-feature-builders.util.README.md)
433
- - [Helper Utilities](../utils/helpers.util.README.md)
434
- - [Type Guards](../utils/type-guards.util.README.md)
435
- - [FAL Provider](../services/fal-provider.README.md)
@@ -1,7 +0,0 @@
1
- /**
2
- * Builders Module
3
- * Exports all builder functions
4
- */
5
-
6
- export { buildImageFeatureInput } from "./image-feature-builder";
7
- export { buildVideoFeatureInput } from "./video-feature-builder";