@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
@@ -5,17 +5,75 @@
5
5
 
6
6
  import { NSFWContentError } from "../services/nsfw-content-error";
7
7
 
8
- declare const __DEV__: boolean;
8
+ declare const __DEV__: boolean | undefined;
9
9
 
10
+ /**
11
+ * Check if value indicates NSFW content
12
+ */
13
+ function isNSFWIndicator(value: unknown): boolean {
14
+ if (typeof value === "boolean") {
15
+ return value === true;
16
+ }
17
+ if (typeof value === "number") {
18
+ return value > 0;
19
+ }
20
+ if (typeof value === "string") {
21
+ const lower = value.toLowerCase();
22
+ return lower === "true" || lower === "yes" || lower === "nsfw";
23
+ }
24
+ return false;
25
+ }
26
+
27
+ /**
28
+ * Validate result for NSFW content across multiple response formats
29
+ */
10
30
  export function validateNSFWContent(result: Record<string, unknown>): void {
31
+ // Format 1: has_nsfw_concepts array (FAL standard format)
11
32
  const nsfwConcepts = result?.has_nsfw_concepts as boolean[] | undefined;
12
-
13
33
  if (nsfwConcepts && Array.isArray(nsfwConcepts)) {
14
34
  const hasNSFW = nsfwConcepts.some((value) => value === true);
15
-
16
35
  if (hasNSFW) {
17
36
  if (typeof __DEV__ !== "undefined" && __DEV__) {
18
- console.log("[FalProvider] NSFW content detected, rejecting result");
37
+ console.log("[FalProvider] NSFW content detected (has_nsfw_concepts), rejecting result");
38
+ }
39
+ throw new NSFWContentError();
40
+ }
41
+ }
42
+
43
+ // Format 2: nsfw_detected boolean
44
+ const nsfwDetected = result?.nsfw_detected;
45
+ if (nsfwDetected !== undefined && isNSFWIndicator(nsfwDetected)) {
46
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
47
+ console.log("[FalProvider] NSFW content detected (nsfw_detected), rejecting result");
48
+ }
49
+ throw new NSFWContentError();
50
+ }
51
+
52
+ // Format 3: is_nsfw boolean
53
+ const isNsfw = result?.is_nsfw;
54
+ if (isNsfw !== undefined && isNSFWIndicator(isNsfw)) {
55
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
56
+ console.log("[FalProvider] NSFW content detected (is_nsfw), rejecting result");
57
+ }
58
+ throw new NSFWContentError();
59
+ }
60
+
61
+ // Format 4: nsfw_score number (> 0.5 threshold)
62
+ const nsfwScore = result?.nsfw_score as number | undefined;
63
+ if (typeof nsfwScore === "number" && nsfwScore > 0.5) {
64
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
65
+ console.log("[FalProvider] NSFW content detected (nsfw_score: " + nsfwScore + "), rejecting result");
66
+ }
67
+ throw new NSFWContentError();
68
+ }
69
+
70
+ // Format 5: content_policy_violation object
71
+ const policyViolation = result?.content_policy_violation as { type: string; severity?: string } | undefined;
72
+ if (policyViolation && typeof policyViolation === "object") {
73
+ const type = (policyViolation.type || "").toLowerCase();
74
+ if (type.includes("nsfw") || type.includes("adult") || type.includes("explicit")) {
75
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
76
+ console.log("[FalProvider] Content policy violation detected:", policyViolation);
19
77
  }
20
78
  throw new NSFWContentError();
21
79
  }
@@ -1,27 +1,9 @@
1
1
  /**
2
- * Hooks Index
3
- * Exports all React hooks
2
+ * Presentation Layer Hooks Index
4
3
  */
5
4
 
6
5
  export { useFalGeneration } from "./use-fal-generation";
7
- export type {
8
- UseFalGenerationOptions,
9
- UseFalGenerationResult,
10
- } from "./use-fal-generation";
11
-
12
6
  export { useModels } from "./use-models";
13
- export type { UseModelsProps } from "./use-models";
14
7
 
15
- export {
16
- useModelCapabilities,
17
- useVideoDurations,
18
- useVideoResolutions,
19
- useAspectRatios,
20
- } from "./use-model-capabilities";
21
- export type {
22
- UseModelCapabilitiesOptions,
23
- UseModelCapabilitiesReturn,
24
- UseVideoDurationsReturn,
25
- UseVideoResolutionsReturn,
26
- UseAspectRatiosReturn,
27
- } from "./use-model-capabilities";
8
+ export type { UseFalGenerationOptions, UseFalGenerationResult } from "./use-fal-generation";
9
+ export type { UseModelsProps, UseModelsReturn } from "./use-models";
@@ -52,13 +52,14 @@ export function useFalGeneration<T = unknown>(
52
52
  const result = await falProvider.subscribe<T>(modelEndpoint, input, {
53
53
  timeoutMs: options?.timeoutMs,
54
54
  onQueueUpdate: (status) => {
55
- // Note: requestId is tracked internally by falProvider subscribe
56
- // and exposed via the requestId ref, not from status object
57
- const currentRequestId = currentRequestIdRef.current ?? "";
55
+ // Update requestId ref when we receive it from status
56
+ if (status.requestId) {
57
+ currentRequestIdRef.current = status.requestId;
58
+ }
58
59
  // Map JobStatus to FalQueueStatus for backward compatibility
59
60
  options?.onProgress?.({
60
61
  status: status.status,
61
- requestId: currentRequestId,
62
+ requestId: status.requestId ?? currentRequestIdRef.current ?? "",
62
63
  logs: status.logs?.map((log: FalLogEntry) => ({
63
64
  message: log.message,
64
65
  level: log.level,
@@ -1,378 +0,0 @@
1
- # Default Models Constants
2
-
3
- Default FAL AI models and model management constants.
4
-
5
- **Location:** `src/domain/constants/default-models.constants.ts`
6
-
7
- ## Overview
8
-
9
- This module contains definitions for all FAL AI models, their default selections, and helper functions for model management.
10
-
11
- ## Purpose
12
-
13
- Centralizes model configuration by:
14
- - Defining all available FAL models
15
- - Providing default model selections
16
- - Supporting model lookup by ID and type
17
- - Managing model pricing information
18
- - Enabling model filtering and sorting
19
-
20
- ## Import
21
-
22
- ```typescript
23
- import {
24
- getAllDefaultModels,
25
- getDefaultModelsByType,
26
- getDefaultModel,
27
- findModelById
28
- } from '@umituz/react-native-ai-fal-provider';
29
- ```
30
-
31
- ## Constants
32
-
33
- ### DEFAULT_CREDIT_COSTS
34
-
35
- Default credit costs for each model type.
36
-
37
- **Values:**
38
- - `text-to-image`: 2 credits per generation
39
- - `text-to-video`: 20 credits per generation
40
- - `image-to-video`: 20 credits per generation
41
- - `text-to-voice`: 3 credits per generation
42
-
43
- **Usage:**
44
- Use to calculate generation costs before processing. Display costs to users. Implement credit tracking.
45
-
46
- **Implementation:** See constant definition in `src/domain/constants/default-models.constants.ts`
47
-
48
- ### DEFAULT_MODEL_IDS
49
-
50
- Default model IDs for each model type.
51
-
52
- **Values:**
53
- - `text-to-image`: `fal-ai/flux/schnell`
54
- - `text-to-video`: `fal-ai/minimax-video`
55
- - `image-to-video`: `fal-ai/kling-video/v1.5/pro/image-to-video`
56
- - `text-to-voice`: `fal-ai/playai/tts/v3`
57
-
58
- **Usage:**
59
- Use to get default model for each type. Provides fallback when no model selected. Maintains consistency across application.
60
-
61
- ### Model Lists
62
-
63
- **Available Model Collections:**
64
- - `DEFAULT_TEXT_TO_IMAGE_MODELS`: Flux Schnell, Flux Dev, Flux Pro
65
- - `DEFAULT_TEXT_TO_VIDEO_MODELS`: Hunyuan, MiniMax, Kling 1.5, Mochi
66
- - `DEFAULT_IMAGE_TO_VIDEO_MODELS`: Kling I2V
67
- - `DEFAULT_TEXT_TO_VOICE_MODELS`: PlayAI TTS v3, ElevenLabs TTS
68
- - `DEFAULT_TEXT_TO_TEXT_MODELS`: Llama 3 8B Instruct
69
-
70
- **Usage:**
71
- Access specific model lists by type. Filter models for UI display. Get pricing information. Check model availability.
72
-
73
- **Related:**
74
- - Model types: `src/domain/types/model-selection.types.ts`
75
- - Feature models: `src/domain/constants/feature-models.constants.ts`
76
-
77
- ## Functions
78
-
79
- ### getAllDefaultModels
80
-
81
- Get all default models.
82
-
83
- **Returns:** Array of all model configurations
84
-
85
- **Usage:**
86
- Use to retrieve complete model list. Display all available models. Implement model selection UI. Filter models by type or status.
87
-
88
- **Related:**
89
- - useModels hook: `src/presentation/hooks/use-models.ts`
90
-
91
- ### getDefaultModelsByType
92
-
93
- Get default models for specific type.
94
-
95
- **Parameters:**
96
- - `type`: Model type (`text-to-image`, `text-to-video`, etc.)
97
-
98
- **Returns:** Array of model configurations for specified type
99
-
100
- **Usage:**
101
- Use to get models for specific generation type. Filter models by category. Display type-specific model lists. Implement model type selection.
102
-
103
- **Related:**
104
- - Model types: `src/domain/types/model-selection.types.ts`
105
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
106
-
107
- ### getDefaultModel
108
-
109
- Get default model for a type.
110
-
111
- **Parameters:**
112
- - `type`: Model type
113
-
114
- **Returns:** Default model configuration or undefined
115
-
116
- **Usage:**
117
- Use to get recommended model for type. Provides fallback model. Pre-selects default in UI. Ensures valid model selection.
118
-
119
- **Related:**
120
- - Model selection types: `src/domain/types/model-selection.types.ts`
121
-
122
- ### findModelById
123
-
124
- Find model by ID.
125
-
126
- **Parameters:**
127
- - `id`: Model identifier string
128
-
129
- **Returns:** Model configuration or undefined
130
-
131
- **Usage:**
132
- Use to lookup model by ID. Validate model IDs. Get model details. Check model existence.
133
-
134
- ## Usage Guidelines
135
-
136
- ### For Model Selection
137
-
138
- **Selection Pattern:**
139
- 1. Get all models using `getAllDefaultModels()`
140
- 2. Filter by type using `getDefaultModelsByType()`
141
- 3. Display models in UI
142
- 4. Allow user selection
143
- 5. Use `getDefaultModel()` for default selection
144
-
145
- **Best Practices:**
146
- - Show pricing information to users
147
- - Indicate default models
148
- - Display model descriptions
149
- - Support model comparison
150
- - Enable filtering by cost or quality
151
-
152
- **Related:**
153
- - useModels hook: `src/presentation/hooks/use-models.ts`
154
-
155
- ### For Cost Calculation
156
-
157
- **Cost Calculation Pattern:**
158
- 1. Get model configuration
159
- 2. Access pricing information
160
- 3. Calculate cost based on usage
161
- 4. Display cost to user before generation
162
- 5. Track credit usage
163
-
164
- **Pricing Structure:**
165
- - Free user costs defined per model
166
- - Premium user costs defined per model
167
- - Costs vary by model quality
168
- - Video models typically cost more
169
-
170
- ### For Model Filtering
171
-
172
- **Filtering Options:**
173
- - Filter by model type
174
- - Filter by active status
175
- - Filter by pricing tier
176
- - Sort by cost or quality
177
- - Sort by display order
178
-
179
- **Common Filters:**
180
- - Active models only: `model.isActive !== false`
181
- - Default models only: `model.isDefault === true`
182
- - Type-specific: Use `getDefaultModelsByType()`
183
- - Cost-based: Sort by `pricing.freeUserCost`
184
-
185
- ### For Model Management
186
-
187
- **Management Patterns:**
188
- 1. Use constants for model IDs
189
- 2. Look up models by ID
190
- 3. Validate model selections
191
- 4. Check model availability
192
- 5. Handle missing models gracefully
193
-
194
- **Best Practices:**
195
- - Always validate model IDs
196
- - Provide fallback models
197
- - Handle undefined returns
198
- - Log model lookup failures
199
- - Update model lists regularly
200
-
201
- ## Best Practices
202
-
203
- ### 1. Use Constants for Model IDs
204
-
205
- Avoid hardcoded model strings:
206
- - Import from constants module
207
- - Use defined model IDs
208
- - Maintain single source of truth
209
- - Update models in one place
210
- - Prevent typos in model IDs
211
-
212
- ### 2. Validate Model Selections
213
-
214
- Check model validity before use:
215
- - Validate model ID format
216
- - Check model exists
217
- - Verify model type matches
218
- - Ensure model is active
219
- - Handle invalid selections
220
-
221
- **Related:**
222
- - Type guards: `src/infrastructure/utils/type-guards.util.ts`
223
-
224
- ### 3. Show Pricing Information
225
-
226
- Display costs to users:
227
- - Show credit cost before generation
228
- - Compare model costs
229
- - Indicate premium vs free costs
230
- - Calculate total batch costs
231
- - Warn about expensive operations
232
-
233
- **Related:**
234
- - Helper utilities: `src/infrastructure/utils/helpers.util.ts`
235
-
236
- ### 4. Provide Model Choices
237
-
238
- Let users select models:
239
- - Show all available models
240
- - Indicate default selection
241
- - Display model capabilities
242
- - Compare pricing
243
- - Filter by type or cost
244
-
245
- ### 5. Handle Missing Models
246
-
247
- Graceful degradation for missing models:
248
- - Check if model exists
249
- - Provide fallback models
250
- - Log missing model warnings
251
- - Inform user of unavailability
252
- - Update model lists regularly
253
-
254
- ## For AI Agents
255
-
256
- ### When Using Model Constants
257
-
258
- **DO:**
259
- - Import from package root
260
- - Use constants for model IDs
261
- - Validate model selections
262
- - Check model existence
263
- - Provide fallback models
264
- - Show pricing information
265
- - Handle undefined returns
266
-
267
- **DON'T:**
268
- - Hardcode model IDs
269
- - Skip model validation
270
- - Assume model exists
271
- - Ignore pricing information
272
- - Forget fallback options
273
- - Use outdated model lists
274
- - Create duplicate model definitions
275
-
276
- ### When Selecting Models
277
-
278
- **DO:**
279
- - Use `getDefaultModel()` for defaults
280
- - Filter by type with `getDefaultModelsByType()`
281
- - Look up models with `findModelById()`
282
- - Validate model before use
283
- - Check pricing information
284
- - Show model details to users
285
- - Handle missing models
286
-
287
- **DON'T:**
288
- - Hardcode model selections
289
- - Skip type validation
290
- - Ignore model availability
291
- - Forget to check pricing
292
- - Hide model information
293
- - Assume default exists
294
- - Use invalid model IDs
295
-
296
- ### When Calculating Costs
297
-
298
- **DO:**
299
- - Use pricing from model config
300
- - Calculate before generation
301
- - Show costs to users
302
- - Consider user tier (free/premium)
303
- - Track credit usage
304
- - Warn about expensive operations
305
- - Calculate batch costs
306
-
307
- **DON'T:**
308
- - Skip cost calculation
309
- - Hide pricing from users
310
- - Ignore user tier differences
311
- - Forget credit tracking
312
- - Assume costs are zero
313
- - Calculate after generation
314
- - Use incorrect pricing
315
-
316
- ### When Adding Models
317
-
318
- **For New Model Definitions:**
319
- 1. Add model to appropriate type list
320
- 2. Define model configuration
321
- 3. Set pricing information
322
- 4. Mark default if applicable
323
- 5. Update this README
324
- 6. Test model availability
325
-
326
- **For Model Updates:**
327
- 1. Update pricing information
328
- 2. Change default selections
329
- 3. Add or remove models
330
- 4. Update model descriptions
331
- 5. Test with real API
332
- 6. Update documentation
333
-
334
- **For Enhanced Filtering:**
335
- 1. Add filter options
336
- 2. Support new sort orders
337
- 3. Add pricing tiers
338
- 4. Update TypeScript types
339
- 5. Document filter behavior
340
- 6. Test filtering logic
341
-
342
- ## Implementation Notes
343
-
344
- **Location:** `src/domain/constants/default-models.constants.ts`
345
-
346
- **Dependencies:**
347
- - Uses model types from `src/domain/types/model-selection.types.ts`
348
- - No external dependencies
349
- - Pure constant definitions
350
-
351
- **Model Categories:**
352
- - Text-to-image models (Flux family)
353
- - Text-to-video models (Hunyuan, MiniMax, Kling, Mochi)
354
- - Image-to-video models (Kling I2V)
355
- - Text-to-voice models (PlayAI, ElevenLabs)
356
- - Text-to-text models (Llama)
357
-
358
- **Import:**
359
- ```typescript
360
- import {
361
- getAllDefaultModels,
362
- getDefaultModelsByType,
363
- getDefaultModel,
364
- findModelById
365
- } from '@umituz/react-native-ai-fal-provider';
366
- ```
367
-
368
- **Related:**
369
- - Model selection types: `src/domain/types/model-selection.types.ts`
370
- - Feature models: `src/domain/constants/feature-models.constants.ts`
371
- - useModels hook: `src/presentation/hooks/use-models.ts`
372
- - Model-specific constants: `src/domain/constants/models/`
373
-
374
- ## Related Documentation
375
-
376
- - [Model Selection Types](../types/model-selection.types.README.md)
377
- - [Feature Models Constants](./feature-models.constants.README.md)
378
- - [useModels Hook](../../presentation/hooks/use-models.README.md)