@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,395 +0,0 @@
1
- # Error Categorizer
2
-
3
- FAL AI error categorization system for automatic error type detection and retryability determination.
4
-
5
- **Location:** `src/infrastructure/utils/error-categorizer.ts`
6
-
7
- ## Overview
8
-
9
- The error categorizer analyzes raw error messages and determines error type, retryability, and message keys. It uses pattern matching on error messages, status codes, and error structures to categorize errors consistently.
10
-
11
- ## Purpose
12
-
13
- Automates error categorization by:
14
- - Analyzing error messages for patterns
15
- - Determining error types automatically
16
- - Setting retryability flags correctly
17
- - Providing message keys for translations
18
- - Supporting consistent error handling
19
-
20
- ## Import
21
-
22
- ```typescript
23
- import { categorizeFalError } from '@umituz/react-native-ai-fal-provider';
24
- ```
25
-
26
- ## Functions
27
-
28
- ### categorizeFalError
29
-
30
- Analyze and categorize error message.
31
-
32
- **Parameters:**
33
- - `error`: Error object from any source (Error, string, number, unknown)
34
-
35
- **Returns:** `FalErrorCategory` - Categorized error information
36
-
37
- **Structure:**
38
- - `type`: Error type from `FalErrorType` enum
39
- - `messageKey`: i18n translation key for user message
40
- - `retryable`: Boolean indicating if error can be retried
41
-
42
- **Usage:**
43
- Use in catch blocks to automatically categorize errors. The function analyzes error message content, status codes, and error structure to determine the appropriate category.
44
-
45
- **Implementation:** See `src/infrastructure/utils/error-categorizer.ts` for complete categorization logic
46
-
47
- **Related:**
48
- - Error types: `src/domain/entities/error.types.ts`
49
- - Error mapper: `src/infrastructure/utils/error-mapper.ts`
50
-
51
- ## Error Categories
52
-
53
- ### Network Errors
54
-
55
- **Pattern Keywords:** network, fetch, connection, econnrefused, enotfound, etimedout
56
-
57
- **Type:** `FalErrorType.NETWORK`
58
-
59
- **Retryable:** Yes
60
-
61
- **Message Key:** `fal.errors.network`
62
-
63
- **Usage:** Network connectivity errors are temporary and should be retried. Use for connection failures, DNS errors, and network timeouts.
64
-
65
- ### Timeout Errors
66
-
67
- **Pattern Keywords:** timeout, timed out
68
-
69
- **Type:** `FalErrorType.TIMEOUT`
70
-
71
- **Retryable:** Yes
72
-
73
- **Message Key:** `fal.errors.timeout`
74
-
75
- **Usage:** Request timeouts may succeed on retry. Implement with longer timeout on retry.
76
-
77
- ### Validation Errors
78
-
79
- **Pattern Keywords:** validation, invalid, unprocessable, 422, bad request, 400
80
-
81
- **Type:** `FalErrorType.VALIDATION`
82
-
83
- **Retryable:** No
84
-
85
- **Message Key:** `fal.errors.invalid_input`
86
-
87
- **Usage:** Input validation failures require input correction. Do not retry without fixing input.
88
-
89
- ### Content Policy Errors
90
-
91
- **Pattern Keywords:** content_policy, content policy, policy violation, nsfw, inappropriate
92
-
93
- **Type:** `FalErrorType.CONTENT_POLICY`
94
-
95
- **Retryable:** No
96
-
97
- **Message Key:** `fal.errors.nsfw_content`
98
-
99
- **Usage:** Content policy violations require content changes. Do not retry with same content.
100
-
101
- **Related:**
102
- - NSFW validator: `src/infrastructure/validators/nsfw-validator.ts`
103
-
104
- ### Rate Limit Errors
105
-
106
- **Pattern Keywords:** rate limit, too many requests, 429, quota
107
-
108
- **Type:** `FalErrorType.RATE_LIMIT`
109
-
110
- **Retryable:** Yes
111
-
112
- **Message Key:** `fal.errors.rate_limit`
113
-
114
- **Usage:** Rate limit errors require waiting before retry. Implement exponential backoff.
115
-
116
- ### Authentication Errors
117
-
118
- **Pattern Keywords:** unauthorized, 401, forbidden, 403, api key, authentication
119
-
120
- **Type:** `FalErrorType.AUTHENTICATION`
121
-
122
- **Retryable:** No
123
-
124
- **Message Key:** `fal.errors.authentication`
125
-
126
- **Usage:** Authentication failures require valid API key. Do not retry without fixing credentials.
127
-
128
- ### Quota Exceeded Errors
129
-
130
- **Pattern Keywords:** quota exceeded, insufficient credits, billing, payment required, 402
131
-
132
- **Type:** `FalErrorType.QUOTA_EXCEEDED`
133
-
134
- **Retryable:** No
135
-
136
- **Message Key:** `fal.errors.quota_exceeded`
137
-
138
- **Usage:** Quota limits require payment or upgrade. Do not retry without increasing quota.
139
-
140
- ### Model Not Found Errors
141
-
142
- **Pattern Keywords:** model not found, endpoint not found, 404, not found
143
-
144
- **Type:** `FalErrorType.MODEL_UNAVAILABLE`
145
-
146
- **Retryable:** Yes
147
-
148
- **Message Key:** `fal.errors.model_unavailable`
149
-
150
- **Usage:** Model availability issues may be temporary. Retry after checking model availability.
151
-
152
- ### API Errors
153
-
154
- **Pattern Keywords:** api error, 502, 503, 504, 500, internal server error
155
-
156
- **Type:** `FalErrorType.UNKNOWN`
157
-
158
- **Retryable:** Yes
159
-
160
- **Message Key:** `fal.errors.unknown`
161
-
162
- **Usage:** Server errors may be temporary. Retry with backoff.
163
-
164
- ## Categorization Strategy
165
-
166
- ### Pattern Matching
167
-
168
- **Detection Order:**
169
- 1. Check HTTP status codes (401, 403, 404, 422, 429, 500, 502, 503, 504)
170
- 2. Search error message for pattern keywords
171
- 3. Check error type names
172
- 4. Check error codes
173
- 5. Default to unknown type
174
-
175
- **Pattern Priority:**
176
- - Status codes have highest priority
177
- - Specific keywords override general patterns
178
- - First matching pattern wins
179
- - Unknown type is fallback
180
-
181
- **Implementation:** See pattern definitions in `src/infrastructure/utils/error-categorizer.ts`
182
-
183
- ### Retryability Rules
184
-
185
- **Always Retryable:**
186
- - Network errors (temporary connectivity issues)
187
- - Timeout errors (may succeed with longer timeout)
188
- - Rate limit errors (after waiting period)
189
- - Model unavailable errors (temporary)
190
- - API server errors (temporary)
191
-
192
- **Never Retryable:**
193
- - Authentication errors (require credential fix)
194
- - Quota exceeded errors (require payment)
195
- - Validation errors (require input fix)
196
- - Content policy errors (require content change)
197
- - NSFW content errors (require content moderation)
198
-
199
- **Usage:** Use `retryable` flag to determine retry behavior. Implement appropriate backoff for retryable errors.
200
-
201
- ## Usage Guidelines
202
-
203
- ### For Error Handling
204
-
205
- **Standard Pattern:**
206
- 1. Wrap API calls in try-catch
207
- 2. Call `categorizeFalError()` with caught error
208
- 3. Check `type` for specific handling
209
- 4. Check `retryable` before retrying
210
- 5. Use `messageKey` for user display
211
-
212
- **Type-Specific Handling:**
213
- - Authentication: Prompt for API key
214
- - Quota: Show upgrade dialog
215
- - Rate limit: Wait and retry with backoff
216
- - Network: Show connection error, allow retry
217
- - Timeout: Allow retry with longer timeout
218
- - Validation: Show input requirements
219
- - Content policy: Show policy notice
220
-
221
- **Related:**
222
- - Error types: `src/domain/entities/error.types.ts`
223
-
224
- ### For Retry Logic
225
-
226
- **Retryable Errors:**
227
- - Check `retryable` flag before retry
228
- - Implement exponential backoff for rate limits
229
- - Use longer timeouts for timeout errors
230
- - Allow immediate retry for network errors
231
- - Set reasonable retry limits
232
-
233
- **Non-Retryable Errors:**
234
- - Do not automatically retry
235
- - Require user intervention
236
- - Fix underlying issue first
237
- - Provide clear guidance to user
238
-
239
- ### For User Messages
240
-
241
- **Message Key Usage:**
242
- 1. Get `messageKey` from category
243
- 2. Look up translation in i18n system
244
- 3. Display user-friendly message
245
- 4. Include actionable next steps
246
- 5. Contextualize by error type
247
-
248
- **Translation Keys:**
249
- See complete list in error mapper documentation at `src/infrastructure/utils/error-mapper.README.md`
250
-
251
- ## Best Practices
252
-
253
- ### 1. Always Categorize Errors
254
-
255
- Categorize all caught errors:
256
- - Call `categorizeFalError()` in catch blocks
257
- - Use returned category for handling
258
- - Don't manually interpret error messages
259
- - Maintain consistent categorization
260
-
261
- ### 2. Respect Retryability
262
-
263
- Honor the retryable flag:
264
- - Never retry non-retryable errors
265
- - Always check before attempting retry
266
- - Implement appropriate backoff strategies
267
- - Set retry limits for retryable errors
268
-
269
- ### 3. Handle Types Specifically
270
-
271
- Provide type-specific handling:
272
- - Authentication: Request new API key
273
- - Quota: Show payment/upgrade options
274
- - Rate limit: Implement backoff
275
- - Network: Show connectivity message
276
- - Validation: Display input requirements
277
- - Content policy: Show policy details
278
-
279
- ### 4. Use Message Keys
280
-
281
- Leverage message key system:
282
- - Use for i18n translations
283
- - Provide consistent messaging
284
- - Support multiple languages
285
- - Include context in translations
286
-
287
- ### 5. Log Categorization
288
-
289
- Track error categories:
290
- - Log categorized types for analytics
291
- - Monitor error patterns over time
292
- - Identify recurring issues
293
- - Track retry success rates
294
-
295
- ## For AI Agents
296
-
297
- ### When Using Error Categorizer
298
-
299
- **DO:**
300
- - Import from package root
301
- - Categorize all caught errors
302
- - Check retryability flag
303
- - Handle each type appropriately
304
- - Use message keys for display
305
- - Log categorized errors
306
- - Implement type-specific handling
307
-
308
- **DON'T:**
309
- - Manually parse error messages
310
- - Ignore categorization results
311
- - Retry non-retryable errors
312
- - Skip type-specific handling
313
- - Show raw errors to users
314
- - Assume all errors are retryable
315
- - Create duplicate categorization logic
316
-
317
- ### When Handling Errors
318
-
319
- **DO:**
320
- - Wrap all API calls in try-catch
321
- - Call `categorizeFalError()` immediately
322
- - Check `type` for specific handling
323
- - Use `retryable` for retry decisions
324
- - Display user-friendly messages
325
- - Implement proper retry logic
326
- - Log errors with category
327
-
328
- **DON'T:**
329
- - Let errors propagate uncategorized
330
- - Assume error structure
331
- - Implement custom categorization
332
- - Retry without checking retryable
333
- - Show technical messages to users
334
- - Skip error logging
335
- - Use generic error handling
336
-
337
- ### When Adding Error Types
338
-
339
- **For New Error Categories:**
340
- 1. Add type to `FalErrorType` enum in `src/domain/entities/error.types.ts`
341
- 2. Add pattern keywords to categorizer
342
- 3. Set appropriate retryability
343
- 4. Add message key for translations
344
- 5. Update this README
345
- 6. Test categorization
346
-
347
- **For New Pattern Keywords:**
348
- 1. Add keyword to appropriate pattern array
349
- 2. Test keyword matching
350
- 3. Update documentation
351
- 4. Verify categorization works
352
- 5. Add tests for new patterns
353
-
354
- **For Enhanced Categorization:**
355
- 1. Review existing pattern matching
356
- 2. Add new detection methods if needed
357
- 3. Improve categorization accuracy
358
- 4. Update TypeScript types
359
- 5. Document changes thoroughly
360
-
361
- ## Implementation Notes
362
-
363
- **Location:** `src/infrastructure/utils/error-categorizer.ts`
364
-
365
- **Dependencies:**
366
- - Uses error types from `src/domain/entities/error.types.ts`
367
- - No external dependencies
368
- - Pure pattern matching logic
369
-
370
- **Patterns:** Defined in `src/infrastructure/utils/error-categorizer.ts`
371
- - Network patterns
372
- - Timeout patterns
373
- - Validation patterns
374
- - Content policy patterns
375
- - Rate limit patterns
376
- - Authentication patterns
377
- - Quota patterns
378
- - Model availability patterns
379
- - API error patterns
380
-
381
- **Import:**
382
- ```typescript
383
- import { categorizeFalError } from '@umituz/react-native-ai-fal-provider';
384
- ```
385
-
386
- **Related:**
387
- - Error types: `src/domain/entities/error.types.ts`
388
- - Error mapper: `src/infrastructure/utils/error-mapper.ts`
389
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
390
-
391
- ## Related Documentation
392
-
393
- - [Error Types](../../domain/entities/error.types.README.md)
394
- - [Error Mapper](./error-mapper.README.md)
395
- - [Type Guards](./type-guards.util.README.md)