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

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,395 +0,0 @@
1
- # Helper Utilities
2
-
3
- Common utility functions for data formatting, validation, error handling, and performance optimization in FAL operations.
4
-
5
- **Location:** `src/infrastructure/utils/helpers.util.ts`
6
-
7
- ## Overview
8
-
9
- This module provides reusable utility functions used throughout the FAL AI provider. It includes image data formatting, credit cost formatting, prompt sanitization, and timeout management functions.
10
-
11
- ## Purpose
12
-
13
- Simplifies common operations by:
14
- - Formatting image data URIs correctly
15
- - Extracting and validating base64 data
16
- - Formatting credit costs for display
17
- - Sanitizing user prompts
18
- - Managing timeouts with jitter
19
- - Providing consistent data transformations
20
-
21
- ## Import
22
-
23
- ```typescript
24
- import {
25
- formatImageDataUri,
26
- extractBase64,
27
- formatCreditCost,
28
- truncatePrompt,
29
- sanitizePrompt
30
- } from '@umituz/react-native-ai-fal-provider';
31
- ```
32
-
33
- ## Image Data Functions
34
-
35
- ### formatImageDataUri
36
-
37
- Convert base64 string to data URI format.
38
-
39
- **Parameters:**
40
- - `base64`: Base64 string or data URI
41
-
42
- **Returns:** `string` - Properly formatted data URI
43
-
44
- **Usage:**
45
- Use this function to ensure image data is in correct data URI format. Function checks if input is already formatted and only formats if necessary. Prepends `data:image/jpeg;base64,` if not present.
46
-
47
- **Implementation:** See `src/infrastructure/utils/helpers.util.ts`
48
-
49
- ### extractBase64
50
-
51
- Extract raw base64 string from data URI.
52
-
53
- **Parameters:**
54
- - `dataUri`: Data URI string or base64 string
55
-
56
- **Returns:** `string` - Raw base64 string
57
-
58
- **Usage:**
59
- Use this function to extract base64 data from data URI format. Returns input as-is if not a data URI. Useful when API expects raw base64 instead of data URI.
60
-
61
- ### getDataUriExtension
62
-
63
- Extract file extension from data URI.
64
-
65
- **Parameters:**
66
- - `dataUri`: Data URI string
67
-
68
- **Returns:** `string | null` - File extension (e.g., 'jpeg', 'png') or null
69
-
70
- **Usage:**
71
- Use this function to determine image format from data URI. Returns null if input is not a valid data URI. Useful for format validation.
72
-
73
- ### isImageDataUri
74
-
75
- Check if string is an image data URI.
76
-
77
- **Parameters:**
78
- - `str`: String to validate
79
-
80
- **Returns:** `boolean` - True if string is image data URI
81
-
82
- **Usage:**
83
- Use this function to validate image data URI format. Checks for proper data URI prefix and image mime type.
84
-
85
- ## Display Functions
86
-
87
- ### formatCreditCost
88
-
89
- Format credit cost for user display.
90
-
91
- **Parameters:**
92
- - `cost`: Number of credits
93
-
94
- **Returns:** `string` - Formatted cost string
95
-
96
- **Usage:**
97
- Use this function to display credit costs in UI. Formats numbers with appropriate labels. Provides consistent cost display throughout application.
98
-
99
- **Implementation:** See formatting logic in `src/infrastructure/utils/helpers.util.ts`
100
-
101
- ### formatJobDuration
102
-
103
- Format job duration for display.
104
-
105
- **Parameters:**
106
- - `milliseconds`: Duration in milliseconds
107
-
108
- **Returns:** `string` - Formatted duration string
109
-
110
- **Usage:**
111
- Use this function to display job duration in user-friendly format. Shows seconds, minutes, or "In progress" for incomplete jobs.
112
-
113
- **Related:**
114
- - Job format utilities: `src/infrastructure/utils/job-metadata/job-metadata-format.util.ts`
115
-
116
- ## Prompt Functions
117
-
118
- ### truncatePrompt
119
-
120
- Truncate prompt text to maximum length.
121
-
122
- **Parameters:**
123
- - `prompt`: Prompt text to truncate
124
- - `maxLength`: Maximum character length (optional)
125
-
126
- **Returns:** `string` - Truncated prompt with ellipsis if needed
127
-
128
- **Usage:**
129
- Use this function to ensure prompts fit within API limits. Adds ellipsis (...) to truncated text. Preserves original text if under limit.
130
-
131
- ### sanitizePrompt
132
-
133
- Sanitize prompt text for API submission.
134
-
135
- **Parameters:**
136
- - `prompt`: Prompt text to sanitize
137
-
138
- **Returns:** `string` - Sanitized prompt text
139
-
140
- **Usage:**
141
- Use this function to clean user prompts before API submission. Removes problematic characters, normalizes whitespace, and ensures safe text submission.
142
-
143
- ## Time Functions
144
-
145
- ### calculateTimeoutWithJitter
146
-
147
- Add random jitter to timeout value.
148
-
149
- **Parameters:**
150
- - `baseTimeout`: Base timeout in milliseconds
151
- - `jitterPercent`: Percentage of jitter (optional)
152
-
153
- **Returns:** `number` - Timeout with random jitter
154
-
155
- **Usage:**
156
- Use this function to prevent "thundering herd" problem when multiple requests retry simultaneously. Randomizes timeout slightly to distribute load.
157
-
158
- **Implementation:** See jitter calculation in `src/infrastructure/utils/helpers.util.ts`
159
-
160
- ### sleep
161
-
162
- Async sleep/delay function.
163
-
164
- **Parameters:**
165
- - `ms`: Milliseconds to sleep
166
-
167
- **Returns:** `Promise<void>` - Resolves after delay
168
-
169
- **Usage:**
170
- Use this function for delays in retry logic, rate limiting, or async sequencing.
171
-
172
- ## Usage Guidelines
173
-
174
- ### For Image Data Handling
175
-
176
- **Formatting Pattern:**
177
- 1. Receive base64 or data URI from source
178
- 2. Use `formatImageDataUri()` to ensure correct format
179
- 3. Pass formatted data to FAL API
180
- 4. Use `extractBase64()` if API needs raw base64
181
- 5. Use `getDataUriExtension()` for format validation
182
-
183
- **Best Practices:**
184
- - Always format before sending to API
185
- - Validate with `isImageDataUri()` when needed
186
- - Handle both data URI and raw base64 inputs
187
- - Check format requirements in API docs
188
-
189
- ### For Display Formatting
190
-
191
- **Credit Cost Display:**
192
- 1. Get credit cost from model configuration
193
- 2. Use `formatCreditCost()` for display
194
- 3. Show before generation starts
195
- 4. Update when model changes
196
-
197
- **Duration Display:**
198
- 1. Get duration in milliseconds
199
- 2. Use `formatJobDuration()` for display
200
- 3. Handle null for incomplete jobs
201
- 4. Show in user-readable format
202
-
203
- **Related:**
204
- - Job format utilities: `src/infrastructure/utils/job-metadata/job-metadata-format.util.ts`
205
-
206
- ### For Prompt Handling
207
-
208
- **Sanitization Pattern:**
209
- 1. Receive user input prompt
210
- 2. Use `sanitizePrompt()` to clean text
211
- 3. Use `truncatePrompt()` if needed
212
- 4. Pass to FAL API
213
- 5. Store original if needed for display
214
-
215
- **Best Practices:**
216
- - Always sanitize user input
217
- - Truncate to API limits
218
- - Preserve original for display
219
- - Log sanitization if needed
220
-
221
- ### For Retry Logic
222
-
223
- **Timeout Management:**
224
- 1. Get base timeout from configuration
225
- 2. Use `calculateTimeoutWithJitter()` for retries
226
- 3. Use `sleep()` between retries
227
- 4. Implement exponential backoff
228
-
229
- **Jitter Usage:**
230
- - Apply jitter to prevent request clustering
231
- - Use small jitter percentage (5-10%)
232
- - Only apply for retry scenarios
233
- - Keep base timeout reasonable
234
-
235
- ## Best Practices
236
-
237
- ### 1. Always Format Image Data
238
-
239
- Ensure correct image format:
240
- - Use `formatImageDataUri()` before API calls
241
- - Validate with `isImageDataUri()`
242
- - Handle both base64 and data URI inputs
243
- - Check API documentation for format requirements
244
-
245
- ### 2. Validate Before Processing
246
-
247
- Check data before use:
248
- - Use type guard functions
249
- - Validate prompt length
250
- - Check image data format
251
- - Handle invalid data gracefully
252
-
253
- ### 3. Format for Display
254
-
255
- Use formatting functions for UI:
256
- - Format credit costs before display
257
- - Format durations for readability
258
- - Use consistent formatting
259
- - Follow locale conventions
260
-
261
- ### 4. Sanitize User Input
262
-
263
- Clean all user-provided text:
264
- - Sanitize prompts before API calls
265
- - Remove dangerous characters
266
- - Normalize whitespace
267
- - Truncate to limits
268
-
269
- ### 5. Manage Timeouts Properly
270
-
271
- Implement proper timeout handling:
272
- - Use jitter for retries
273
- - Implement exponential backoff
274
- - Use sleep for delays
275
- - Set reasonable timeout values
276
-
277
- ## For AI Agents
278
-
279
- ### When Using Helper Functions
280
-
281
- **DO:**
282
- - Import from package root
283
- - Use `formatImageDataUri()` for images
284
- - Sanitize all user prompts
285
- - Format display values appropriately
286
- - Use jitter for retry timeouts
287
- - Validate data before processing
288
- - Handle edge cases
289
-
290
- **DON'T:**
291
- - Manually format data URIs
292
- - Skip prompt sanitization
293
- - Show raw credit costs
294
- - Hardcode timeout values
295
- - Ignore validation functions
296
- - Create duplicate utility functions
297
- - Assume input format
298
-
299
- ### When Formatting Images
300
-
301
- **DO:**
302
- - Use `formatImageDataUri()` before API
303
- - Validate with `isImageDataUri()`
304
- - Extract base64 when needed
305
- - Check data URI extension
306
- - Handle both input formats
307
- - Follow API format requirements
308
-
309
- **DON'T:**
310
- - Manually construct data URIs
311
- - Assume input format
312
- - Skip validation
313
- - Hardcode mime types
314
- - Ignore format requirements
315
- - Create custom formatting logic
316
-
317
- ### When Handling Prompts
318
-
319
- **DO:**
320
- - Always sanitize user input
321
- - Truncate to API limits
322
- - Use provided functions
323
- - Handle special characters
324
- - Preserve original for display
325
- - Log sanitization
326
-
327
- **DON'T:**
328
- - Skip sanitization
329
- - Exceed API limits
330
- - Manually clean text
331
- - Lose original text
332
- - Allow dangerous characters
333
- - Hardcode limits
334
-
335
- ### When Adding Functions
336
-
337
- **For New Formatting Functions:**
338
- 1. Add to helpers file
339
- 2. Follow existing patterns
340
- 3. Handle edge cases
341
- 4. Update exports
342
- 5. Document in this README
343
- 6. Add tests
344
-
345
- **For New Validation Functions:**
346
- 1. Add type guard if needed
347
- 2. Return boolean for simple validation
348
- 3. Return detailed info if needed
349
- 4. Follow naming conventions
350
- 5. Document usage
351
-
352
- **For New Utility Functions:**
353
- 1. Add to appropriate utility file
354
- 2. Keep functions pure
355
- 3. Handle null/undefined
356
- 4. Use TypeScript types
357
- 5. Document thoroughly
358
-
359
- ## Implementation Notes
360
-
361
- **Location:** `src/infrastructure/utils/helpers.util.ts`
362
-
363
- **Dependencies:**
364
- - No external dependencies
365
- - Pure utility functions
366
- - Used throughout the provider
367
-
368
- **Function Categories:**
369
- - Image data formatting
370
- - Display formatting
371
- - Prompt handling
372
- - Time management
373
- - Data validation
374
-
375
- **Import:**
376
- ```typescript
377
- import {
378
- formatImageDataUri,
379
- extractBase64,
380
- formatCreditCost,
381
- truncatePrompt,
382
- sanitizePrompt
383
- } from '@umituz/react-native-ai-fal-provider';
384
- ```
385
-
386
- **Related:**
387
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
388
- - Job format utilities: `src/infrastructure/utils/job-metadata/job-metadata-format.util.ts`
389
- - Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
390
-
391
- ## Related Documentation
392
-
393
- - [Type Guards](./type-guards.util.README.md)
394
- - [Job Metadata Format](./job-metadata/job-metadata-format.util.README.md)
395
- - [Image Feature Builders](./image-feature-builders.util.README.md)