@umituz/react-native-ai-fal-provider 2.0.11 → 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.
- package/package.json +2 -4
- package/src/domain/entities/error.types.ts +2 -0
- package/src/domain/types/provider.types.ts +1 -0
- package/src/exports/infrastructure.ts +0 -3
- package/src/exports/presentation.ts +0 -9
- package/src/index.ts +0 -3
- package/src/infrastructure/services/fal-feature-models.ts +3 -1
- package/src/infrastructure/services/fal-provider-subscription.ts +35 -13
- package/src/infrastructure/services/fal-provider.ts +6 -0
- package/src/infrastructure/services/fal-queue-operations.ts +30 -1
- package/src/infrastructure/services/fal-status-mapper.ts +2 -0
- package/src/infrastructure/services/request-store.ts +30 -2
- package/src/infrastructure/utils/cost-tracker.ts +34 -8
- package/src/infrastructure/utils/error-mapper.ts +17 -3
- package/src/infrastructure/utils/fal-storage.util.ts +3 -3
- package/src/infrastructure/utils/image-feature-builders.util.ts +10 -5
- package/src/infrastructure/utils/index.ts +7 -6
- package/src/infrastructure/utils/input-preprocessor.util.ts +1 -1
- package/src/infrastructure/utils/input-validator.util.ts +92 -0
- package/src/infrastructure/utils/type-guards.util.ts +7 -3
- package/src/infrastructure/utils/video-feature-builders.util.ts +6 -3
- package/src/infrastructure/validators/nsfw-validator.ts +62 -4
- package/src/presentation/hooks/index.ts +3 -21
- package/src/presentation/hooks/use-fal-generation.ts +5 -4
- package/src/domain/constants/default-models.constants.README.md +0 -378
- package/src/domain/constants/models/image-to-video.README.md +0 -266
- package/src/domain/constants/models/index.README.md +0 -269
- package/src/domain/constants/models/text-to-image.README.md +0 -237
- package/src/domain/constants/models/text-to-text.README.md +0 -249
- package/src/domain/constants/models/text-to-video.README.md +0 -259
- package/src/domain/constants/models/text-to-voice.README.md +0 -264
- package/src/domain/entities/error.types.README.md +0 -292
- package/src/domain/entities/fal.types.README.md +0 -460
- package/src/domain/types/index.README.md +0 -229
- package/src/domain/types/model-selection.types.README.md +0 -311
- package/src/exports/registry.ts +0 -39
- package/src/index.README.md +0 -420
- package/src/infrastructure/builders/image-feature-builder.README.md +0 -435
- package/src/infrastructure/builders/index.ts +0 -7
- package/src/infrastructure/services/fal-models-service.README.md +0 -293
- package/src/infrastructure/services/fal-provider-subscription.README.md +0 -257
- package/src/infrastructure/services/fal-provider.README.md +0 -474
- package/src/infrastructure/services/fal-status-mapper.README.md +0 -246
- package/src/infrastructure/services/nsfw-content-error.README.md +0 -215
- package/src/infrastructure/utils/base-builders.util.README.md +0 -313
- package/src/infrastructure/utils/cost-tracker-queries.ts +0 -67
- package/src/infrastructure/utils/error-categorizer.README.md +0 -395
- package/src/infrastructure/utils/error-mapper.README.md +0 -367
- package/src/infrastructure/utils/helpers.util.README.md +0 -395
- package/src/infrastructure/utils/image-feature-builders.util.README.md +0 -411
- package/src/infrastructure/utils/index.README.md +0 -338
- package/src/infrastructure/utils/job-metadata/index.README.md +0 -267
- package/src/infrastructure/utils/job-metadata/job-metadata-format.util.README.md +0 -209
- package/src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.README.md +0 -311
- package/src/infrastructure/utils/job-metadata/job-metadata-queries.util.README.md +0 -332
- package/src/infrastructure/utils/job-metadata/job-metadata.types.README.md +0 -446
- package/src/infrastructure/utils/job-metadata.README.md +0 -268
- package/src/infrastructure/utils/timing-helpers.util.ts +0 -56
- package/src/infrastructure/utils/type-guards.util.README.md +0 -371
- package/src/infrastructure/validators/index.README.md +0 -205
- package/src/infrastructure/validators/nsfw-validator.README.md +0 -309
- package/src/presentation/hooks/index.README.md +0 -224
- package/src/presentation/hooks/use-fal-generation.README.md +0 -398
- package/src/presentation/hooks/use-model-capabilities.ts +0 -99
- package/src/presentation/hooks/use-models.README.md +0 -318
- package/src/registry/global-capabilities.ts +0 -75
- package/src/registry/index.ts +0 -50
- package/src/registry/model-registry.service.ts +0 -93
- package/src/registry/model-registry.types.ts +0 -106
- package/src/registry/models/index.ts +0 -6
- package/src/registry/models/sora-2.config.ts +0 -95
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
# FalProvider
|
|
2
|
-
|
|
3
|
-
FAL AI provider service class implementing IAIProvider interface.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/services/fal-provider.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
The `FalProvider` class is the central service for all interactions with FAL AI. It implements the `IAIProvider` interface to provide a provider-agnostic architecture for AI generation operations.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Manages FAL AI API interactions including:
|
|
14
|
-
- Provider initialization and configuration
|
|
15
|
-
- Job submission and status tracking
|
|
16
|
-
- Image and video feature processing
|
|
17
|
-
- Request lifecycle management
|
|
18
|
-
- Error handling and retry logic
|
|
19
|
-
|
|
20
|
-
## Singleton Instance
|
|
21
|
-
|
|
22
|
-
**Import:**
|
|
23
|
-
```typescript
|
|
24
|
-
import { falProvider } from '@umituz/react-native-ai-fal-provider';
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**Usage:**
|
|
28
|
-
Use the exported `falProvider` singleton instance. Do not create new instances with `new FalProvider()`.
|
|
29
|
-
|
|
30
|
-
**Implementation:** See `src/infrastructure/services/fal-provider.ts` for complete class definition
|
|
31
|
-
|
|
32
|
-
## Initialization Methods
|
|
33
|
-
|
|
34
|
-
### initialize
|
|
35
|
-
|
|
36
|
-
Initialize provider with API key and configuration.
|
|
37
|
-
|
|
38
|
-
**Parameters:**
|
|
39
|
-
|
|
40
|
-
| Parameter | Type | Required | Description |
|
|
41
|
-
|-----------|------|----------|-------------|
|
|
42
|
-
| `configData` | `AIProviderConfig` | ✅ Yes | Configuration object |
|
|
43
|
-
|
|
44
|
-
**Config Structure:**
|
|
45
|
-
- `apiKey`: FAL API key (required)
|
|
46
|
-
- `maxRetries`: Maximum retry attempts (optional)
|
|
47
|
-
- `baseDelay`: Base delay for retries in ms (optional)
|
|
48
|
-
- `maxDelay`: Maximum delay for retries in ms (optional)
|
|
49
|
-
|
|
50
|
-
**Usage:**
|
|
51
|
-
Call once at application startup with your FAL API key and optional retry configuration.
|
|
52
|
-
|
|
53
|
-
### isInitialized
|
|
54
|
-
|
|
55
|
-
Check if provider has been initialized.
|
|
56
|
-
|
|
57
|
-
**Returns:** `boolean` - True if provider is initialized
|
|
58
|
-
|
|
59
|
-
**Usage:**
|
|
60
|
-
Use this check before calling provider methods to ensure initialization.
|
|
61
|
-
|
|
62
|
-
### reset
|
|
63
|
-
|
|
64
|
-
Reset provider to initial state.
|
|
65
|
-
|
|
66
|
-
**Usage:**
|
|
67
|
-
Call this to clear all provider state and configuration. Use for cleanup or reinitialization.
|
|
68
|
-
|
|
69
|
-
## Capability Methods
|
|
70
|
-
|
|
71
|
-
### getCapabilities
|
|
72
|
-
|
|
73
|
-
Get provider capabilities for image and video features.
|
|
74
|
-
|
|
75
|
-
**Returns:** `ProviderCapabilities` object containing:
|
|
76
|
-
- `imageFeatures`: Array of supported image feature types
|
|
77
|
-
- `videoFeatures`: Array of supported video feature types
|
|
78
|
-
|
|
79
|
-
**Usage:**
|
|
80
|
-
Use to determine which features are available before attempting to use them.
|
|
81
|
-
|
|
82
|
-
**Related:**
|
|
83
|
-
- Feature model mappings: `src/domain/constants/feature-models.constants.ts`
|
|
84
|
-
|
|
85
|
-
### isFeatureSupported
|
|
86
|
-
|
|
87
|
-
Check if a specific feature is supported.
|
|
88
|
-
|
|
89
|
-
**Parameters:**
|
|
90
|
-
- `feature`: Image or video feature type to check
|
|
91
|
-
|
|
92
|
-
**Returns:** `boolean` - True if feature is supported
|
|
93
|
-
|
|
94
|
-
**Usage:**
|
|
95
|
-
Check feature support before attempting to use image or video features.
|
|
96
|
-
|
|
97
|
-
### getImageFeatureModel
|
|
98
|
-
|
|
99
|
-
Get model ID for an image feature.
|
|
100
|
-
|
|
101
|
-
**Parameters:**
|
|
102
|
-
- `feature`: Image feature type
|
|
103
|
-
|
|
104
|
-
**Returns:** `string` - FAL model ID
|
|
105
|
-
|
|
106
|
-
**Usage:**
|
|
107
|
-
Retrieve the appropriate model ID for image processing features.
|
|
108
|
-
|
|
109
|
-
**Related:**
|
|
110
|
-
- Image feature models: `src/domain/constants/feature-models.constants.ts`
|
|
111
|
-
- Image feature builder: `src/infrastructure/builders/image-feature-builder.ts`
|
|
112
|
-
|
|
113
|
-
### getVideoFeatureModel
|
|
114
|
-
|
|
115
|
-
Get model ID for a video feature.
|
|
116
|
-
|
|
117
|
-
**Parameters:**
|
|
118
|
-
- `feature`: Video feature type
|
|
119
|
-
|
|
120
|
-
**Returns:** `string` - FAL model ID
|
|
121
|
-
|
|
122
|
-
**Usage:**
|
|
123
|
-
Retrieve the appropriate model ID for video generation features.
|
|
124
|
-
|
|
125
|
-
**Related:**
|
|
126
|
-
- Video feature models: `src/domain/constants/feature-models.constants.ts`
|
|
127
|
-
- Video feature builder: `src/infrastructure/builders/video-feature-builder.ts`
|
|
128
|
-
|
|
129
|
-
### buildImageFeatureInput
|
|
130
|
-
|
|
131
|
-
Build input object for image feature.
|
|
132
|
-
|
|
133
|
-
**Parameters:**
|
|
134
|
-
- `feature`: Image feature type
|
|
135
|
-
- `data`: Feature-specific input data
|
|
136
|
-
|
|
137
|
-
**Returns:** `Record<string, unknown>` - Input object for API
|
|
138
|
-
|
|
139
|
-
**Usage:**
|
|
140
|
-
Use to construct properly formatted input objects for image features.
|
|
141
|
-
|
|
142
|
-
**Related:**
|
|
143
|
-
- Input builder utilities: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
144
|
-
- Input types: `src/domain/types/input-builders.types.ts`
|
|
145
|
-
|
|
146
|
-
### buildVideoFeatureInput
|
|
147
|
-
|
|
148
|
-
Build input object for video feature.
|
|
149
|
-
|
|
150
|
-
**Parameters:**
|
|
151
|
-
- `feature`: Video feature type
|
|
152
|
-
- `data`: Feature-specific input data
|
|
153
|
-
|
|
154
|
-
**Returns:** `Record<string, unknown>` - Input object for API
|
|
155
|
-
|
|
156
|
-
**Usage:**
|
|
157
|
-
Use to construct properly formatted input objects for video features.
|
|
158
|
-
|
|
159
|
-
**Related:**
|
|
160
|
-
- Input builder utilities: `src/infrastructure/utils/video-feature-builders.util.ts`
|
|
161
|
-
- Input types: `src/domain/types/input-builders.types.ts`
|
|
162
|
-
|
|
163
|
-
## Job Management Methods
|
|
164
|
-
|
|
165
|
-
### submitJob
|
|
166
|
-
|
|
167
|
-
Submit job to FAL queue.
|
|
168
|
-
|
|
169
|
-
**Parameters:**
|
|
170
|
-
|
|
171
|
-
| Parameter | Type | Required | Description |
|
|
172
|
-
|-----------|------|----------|-------------|
|
|
173
|
-
| `model` | `string` | ✅ Yes | FAL model ID |
|
|
174
|
-
| `input` | `Record<string, unknown>` | ✅ Yes | Job input object |
|
|
175
|
-
|
|
176
|
-
**Returns:** `JobSubmission` object containing:
|
|
177
|
-
- `requestId`: Unique job identifier
|
|
178
|
-
- `statusUrl`: URL to check job status
|
|
179
|
-
- `responseUrl`: URL to get job result
|
|
180
|
-
|
|
181
|
-
**Usage:**
|
|
182
|
-
Use for non-blocking job submission. Combine with status polling for async workflows.
|
|
183
|
-
|
|
184
|
-
### getJobStatus
|
|
185
|
-
|
|
186
|
-
Check job status.
|
|
187
|
-
|
|
188
|
-
**Parameters:**
|
|
189
|
-
|
|
190
|
-
| Parameter | Type | Required | Description |
|
|
191
|
-
|-----------|------|----------|-------------|
|
|
192
|
-
| `model` | `string` | ✅ Yes | FAL model ID |
|
|
193
|
-
| `requestId` | `string` | ✅ Yes | Job request ID |
|
|
194
|
-
|
|
195
|
-
**Returns:** `JobStatus` object with current status and queue position
|
|
196
|
-
|
|
197
|
-
**Usage:**
|
|
198
|
-
Poll this method to track job progress after submission.
|
|
199
|
-
|
|
200
|
-
**Related:**
|
|
201
|
-
- Status mapper: `src/infrastructure/services/fal-status-mapper.ts`
|
|
202
|
-
- Queue status types: `src/domain/entities/fal.types.ts`
|
|
203
|
-
|
|
204
|
-
### getJobResult
|
|
205
|
-
|
|
206
|
-
Get completed job result.
|
|
207
|
-
|
|
208
|
-
**Parameters:**
|
|
209
|
-
|
|
210
|
-
| Parameter | Type | Required | Description |
|
|
211
|
-
|-----------|------|----------|-------------|
|
|
212
|
-
| `model` | `string` | ✅ Yes | FAL model ID |
|
|
213
|
-
| `requestId` | `string` | ✅ Yes | Job request ID |
|
|
214
|
-
|
|
215
|
-
**Returns:** Job result object (type parameter available for typing)
|
|
216
|
-
|
|
217
|
-
**Usage:**
|
|
218
|
-
Call this after job completes to retrieve the final result.
|
|
219
|
-
|
|
220
|
-
### subscribe
|
|
221
|
-
|
|
222
|
-
Submit job and wait for completion with automatic polling.
|
|
223
|
-
|
|
224
|
-
**Parameters:**
|
|
225
|
-
|
|
226
|
-
| Parameter | Type | Required | Description |
|
|
227
|
-
|-----------|------|----------|-------------|
|
|
228
|
-
| `model` | `string` | ✅ Yes | FAL model ID |
|
|
229
|
-
| `input` | `Record<string, unknown>` | ✅ Yes | Job input object |
|
|
230
|
-
| `options` | `SubscribeOptions<T>` | ❌ No | Optional configuration |
|
|
231
|
-
|
|
232
|
-
**Options Structure:**
|
|
233
|
-
- `timeoutMs`: Maximum time to wait for completion
|
|
234
|
-
- `onQueueUpdate`: Callback for status updates during polling
|
|
235
|
-
|
|
236
|
-
**Returns:** Job result object (type parameter available for typing)
|
|
237
|
-
|
|
238
|
-
**Usage:**
|
|
239
|
-
Use for most common use case - submit job and wait for result with automatic retry and polling logic.
|
|
240
|
-
|
|
241
|
-
**Related:**
|
|
242
|
-
- Subscription handler: `src/infrastructure/services/fal-provider-subscription.ts`
|
|
243
|
-
|
|
244
|
-
### run
|
|
245
|
-
|
|
246
|
-
Run job synchronously.
|
|
247
|
-
|
|
248
|
-
**Parameters:**
|
|
249
|
-
|
|
250
|
-
| Parameter | Type | Required | Description |
|
|
251
|
-
|-----------|------|----------|-------------|
|
|
252
|
-
| `model` | `string` | ✅ Yes | FAL model ID |
|
|
253
|
-
| `input` | `Record<string, unknown>` | ✅ Yes | Job input object |
|
|
254
|
-
| `options` | `RunOptions` | ❌ No | Optional configuration |
|
|
255
|
-
|
|
256
|
-
**Returns:** Job result object
|
|
257
|
-
|
|
258
|
-
**Usage:**
|
|
259
|
-
Use for models that support synchronous execution. Faster than subscribe for supported models.
|
|
260
|
-
|
|
261
|
-
## Request Control Methods
|
|
262
|
-
|
|
263
|
-
### cancelCurrentRequest
|
|
264
|
-
|
|
265
|
-
Cancel currently running request.
|
|
266
|
-
|
|
267
|
-
**Usage:**
|
|
268
|
-
Call to abort in-progress requests. Useful for cleanup and user cancellation.
|
|
269
|
-
|
|
270
|
-
### hasRunningRequest
|
|
271
|
-
|
|
272
|
-
Check if there's a running request.
|
|
273
|
-
|
|
274
|
-
**Returns:** `boolean` - True if request is in progress
|
|
275
|
-
|
|
276
|
-
**Usage:**
|
|
277
|
-
Check before starting new requests to prevent conflicts. Use with `cancelCurrentRequest()` for request management.
|
|
278
|
-
|
|
279
|
-
## Usage Guidelines
|
|
280
|
-
|
|
281
|
-
### For Application Setup
|
|
282
|
-
|
|
283
|
-
**Initialization:**
|
|
284
|
-
1. Import `falProvider` singleton
|
|
285
|
-
2. Call `initialize()` at app startup with API key
|
|
286
|
-
3. Check `isInitialized()` before use
|
|
287
|
-
4. Configure retry options as needed
|
|
288
|
-
|
|
289
|
-
**Best Practices:**
|
|
290
|
-
- Initialize once at application startup
|
|
291
|
-
- Store API key securely (environment variable, secure storage)
|
|
292
|
-
- Check initialization status before operations
|
|
293
|
-
- Handle initialization errors gracefully
|
|
294
|
-
|
|
295
|
-
### For Feature Detection
|
|
296
|
-
|
|
297
|
-
**Capability Checking:**
|
|
298
|
-
1. Use `getCapabilities()` to list available features
|
|
299
|
-
2. Use `isFeatureSupported()` before using features
|
|
300
|
-
3. Check specific feature types for UI display
|
|
301
|
-
4. Handle unsupported features gracefully
|
|
302
|
-
|
|
303
|
-
**Feature Models:**
|
|
304
|
-
1. Use `getImageFeatureModel()` for image features
|
|
305
|
-
2. Use `getVideoFeatureModel()` for video features
|
|
306
|
-
3. Build inputs with `buildImageFeatureInput()` or `buildVideoFeatureInput()`
|
|
307
|
-
4. Pass model ID and input to subscribe/run methods
|
|
308
|
-
|
|
309
|
-
**Related:**
|
|
310
|
-
- Feature constants: `src/domain/constants/feature-models.constants.ts`
|
|
311
|
-
- Builder utilities: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
312
|
-
|
|
313
|
-
### For Job Execution
|
|
314
|
-
|
|
315
|
-
**Standard Flow:**
|
|
316
|
-
1. Build input object for model
|
|
317
|
-
2. Call `subscribe()` with model ID and input
|
|
318
|
-
3. Handle result or error
|
|
319
|
-
4. Update UI with result
|
|
320
|
-
|
|
321
|
-
**Advanced Flow:**
|
|
322
|
-
1. Use `submitJob()` for non-blocking submission
|
|
323
|
-
2. Poll `getJobStatus()` for progress updates
|
|
324
|
-
3. Call `getJobResult()` when status is COMPLETED
|
|
325
|
-
4. Handle errors and timeouts appropriately
|
|
326
|
-
|
|
327
|
-
**Related:**
|
|
328
|
-
- Job metadata: `src/infrastructure/utils/job-metadata/index.ts`
|
|
329
|
-
- Status types: `src/domain/entities/fal.types.ts`
|
|
330
|
-
|
|
331
|
-
### For Request Management
|
|
332
|
-
|
|
333
|
-
**Cancellation:**
|
|
334
|
-
1. Check `hasRunningRequest()` before new requests
|
|
335
|
-
2. Call `cancelCurrentRequest()` to abort
|
|
336
|
-
3. Wait briefly before starting new request
|
|
337
|
-
4. Handle cleanup appropriately
|
|
338
|
-
|
|
339
|
-
**Cleanup:**
|
|
340
|
-
1. Cancel running requests on unmount
|
|
341
|
-
2. Call `reset()` if needed to clear state
|
|
342
|
-
3. Release resources appropriately
|
|
343
|
-
4. Handle state reset errors
|
|
344
|
-
|
|
345
|
-
## Best Practices
|
|
346
|
-
|
|
347
|
-
### 1. Use Singleton Instance
|
|
348
|
-
|
|
349
|
-
Always use the exported `falProvider` singleton:
|
|
350
|
-
- Import from package root
|
|
351
|
-
- Don't create new instances
|
|
352
|
-
- Initialize once at startup
|
|
353
|
-
- Share across application
|
|
354
|
-
|
|
355
|
-
### 2. Validate Before Operations
|
|
356
|
-
|
|
357
|
-
Check initialization and feature support:
|
|
358
|
-
- Use `isInitialized()` before operations
|
|
359
|
-
- Use `isFeatureSupported()` before features
|
|
360
|
-
- Handle unsupported features gracefully
|
|
361
|
-
- Provide user feedback for limitations
|
|
362
|
-
|
|
363
|
-
### 3. Handle Request Lifecycle
|
|
364
|
-
|
|
365
|
-
Manage requests properly:
|
|
366
|
-
- Check `hasRunningRequest()` before starting
|
|
367
|
-
- Cancel requests when appropriate
|
|
368
|
-
- Clean up on unmount/exit
|
|
369
|
-
- Handle timeouts and errors
|
|
370
|
-
|
|
371
|
-
### 4. Build Inputs Correctly
|
|
372
|
-
|
|
373
|
-
Use provided builder functions:
|
|
374
|
-
- Use `buildImageFeatureInput()` for images
|
|
375
|
-
- Use `buildVideoFeatureInput()` for videos
|
|
376
|
-
- Follow input type definitions
|
|
377
|
-
- Validate input data structure
|
|
378
|
-
|
|
379
|
-
**Related:**
|
|
380
|
-
- Input types: `src/domain/types/input-builders.types.ts`
|
|
381
|
-
- Builder utilities: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
382
|
-
|
|
383
|
-
### 5. Handle Errors Appropriately
|
|
384
|
-
|
|
385
|
-
Implement comprehensive error handling:
|
|
386
|
-
- Catch and categorize errors
|
|
387
|
-
- Retry when appropriate
|
|
388
|
-
- Display user-friendly messages
|
|
389
|
-
- Log for debugging
|
|
390
|
-
|
|
391
|
-
**Related:**
|
|
392
|
-
- Error mapper: `src/infrastructure/utils/error-mapper.ts`
|
|
393
|
-
- Error categorizer: `src/infrastructure/utils/error-categorizer.ts`
|
|
394
|
-
|
|
395
|
-
## For AI Agents
|
|
396
|
-
|
|
397
|
-
### When Using FalProvider
|
|
398
|
-
|
|
399
|
-
**DO:**
|
|
400
|
-
- Use the singleton `falProvider` instance
|
|
401
|
-
- Initialize at application startup
|
|
402
|
-
- Check `isInitialized()` before operations
|
|
403
|
-
- Use builder functions for inputs
|
|
404
|
-
- Handle errors appropriately
|
|
405
|
-
- Cancel running requests when needed
|
|
406
|
-
- Use `subscribe()` for most operations
|
|
407
|
-
|
|
408
|
-
**DON'T:**
|
|
409
|
-
- Create new instances with `new FalProvider()`
|
|
410
|
-
- Skip initialization check
|
|
411
|
-
- Build input objects manually
|
|
412
|
-
- Ignore running requests
|
|
413
|
-
- Forget error handling
|
|
414
|
-
- Use deprecated methods
|
|
415
|
-
|
|
416
|
-
### When Adding Features
|
|
417
|
-
|
|
418
|
-
**For New Image Features:**
|
|
419
|
-
1. Add feature to `ImageFeatureType` in types
|
|
420
|
-
2. Add model mapping to `feature-models.constants.ts`
|
|
421
|
-
3. Add builder function to `image-feature-builders.util.ts`
|
|
422
|
-
4. Update `buildImageFeatureInput()` if needed
|
|
423
|
-
5. Document feature in this README
|
|
424
|
-
|
|
425
|
-
**For New Video Features:**
|
|
426
|
-
1. Add feature to `VideoFeatureType` in types
|
|
427
|
-
2. Add model mapping to `feature-models.constants.ts`
|
|
428
|
-
3. Add builder function to `video-feature-builders.util.ts`
|
|
429
|
-
4. Update `buildVideoFeatureInput()` if needed
|
|
430
|
-
5. Document feature in this README
|
|
431
|
-
|
|
432
|
-
**For New Provider Methods:**
|
|
433
|
-
1. Add method to `FalProvider` class
|
|
434
|
-
2. Update `IAIProvider` interface if needed
|
|
435
|
-
3. Add error handling and validation
|
|
436
|
-
4. Update this README with usage guidelines
|
|
437
|
-
5. Test with all feature types
|
|
438
|
-
|
|
439
|
-
## Implementation Notes
|
|
440
|
-
|
|
441
|
-
**Location:** `src/infrastructure/services/fal-provider.ts`
|
|
442
|
-
|
|
443
|
-
**Key Methods:**
|
|
444
|
-
- `initialize(config: AIProviderConfig): void`
|
|
445
|
-
- `isInitialized(): boolean`
|
|
446
|
-
- `getCapabilities(): ProviderCapabilities`
|
|
447
|
-
- `subscribe<T>(model, input, options?): Promise<T>`
|
|
448
|
-
- `run<T>(model, input, options?): Promise<T>`
|
|
449
|
-
- `submitJob(model, input): Promise<JobSubmission>`
|
|
450
|
-
- `getJobStatus(model, requestId): Promise<JobStatus>`
|
|
451
|
-
- `getJobResult<T>(model, requestId): Promise<T>`
|
|
452
|
-
- `cancelCurrentRequest(): void`
|
|
453
|
-
- `hasRunningRequest(): boolean`
|
|
454
|
-
- `reset(): void`
|
|
455
|
-
|
|
456
|
-
**Dependencies:**
|
|
457
|
-
- Implements `IAIProvider` interface
|
|
458
|
-
- Uses `@fal-ai/client` for API calls
|
|
459
|
-
- Integrates with error handling utilities
|
|
460
|
-
- Uses job metadata for tracking
|
|
461
|
-
|
|
462
|
-
**Related:**
|
|
463
|
-
- Subscription handler: `src/infrastructure/services/fal-provider-subscription.ts`
|
|
464
|
-
- Provider constants: `src/infrastructure/services/fal-provider.constants.ts`
|
|
465
|
-
- Status mapper: `src/infrastructure/services/fal-status-mapper.ts`
|
|
466
|
-
- Provider types: `src/domain/entities/fal.types.ts`
|
|
467
|
-
|
|
468
|
-
## Related Documentation
|
|
469
|
-
|
|
470
|
-
- [FalProvider Subscription](./fal-provider-subscription.README.md)
|
|
471
|
-
- [FalProvider Constants](./fal-provider.constants.README.md)
|
|
472
|
-
- [Fal Status Mapper](./fal-status-mapper.README.md)
|
|
473
|
-
- [Image Feature Builder](../builders/image-feature-builder.README.md)
|
|
474
|
-
- [Video Feature Builder](../builders/video-feature-builder.README.md)
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
# FAL Status Mapper
|
|
2
|
-
|
|
3
|
-
Maps FAL queue status to standard job status format.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/services/fal-status-mapper.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
This module converts status objects from the FAL API into the standard `JobStatus` format, providing consistency across different AI providers.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Provides status mapping by:
|
|
14
|
-
- Converting FAL status to standard format
|
|
15
|
-
- Normalizing log entries
|
|
16
|
-
- Providing safe defaults
|
|
17
|
-
- Maintaining consistency
|
|
18
|
-
- Supporting status tracking
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import {
|
|
24
|
-
mapFalStatusToJobStatus
|
|
25
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Functions
|
|
29
|
-
|
|
30
|
-
### mapFalStatusToJobStatus
|
|
31
|
-
|
|
32
|
-
Converts FAL queue status to JobStatus format.
|
|
33
|
-
|
|
34
|
-
**Parameters:**
|
|
35
|
-
- `status`: FAL queue status object
|
|
36
|
-
|
|
37
|
-
**Returns:** Standardized job status object
|
|
38
|
-
|
|
39
|
-
**Input Structure (FalQueueStatus):**
|
|
40
|
-
- `status`: FAL status string
|
|
41
|
-
- `requestId`: Request identifier
|
|
42
|
-
- `logs`: Array of log entries (optional)
|
|
43
|
-
- `queuePosition`: Position in queue (optional)
|
|
44
|
-
|
|
45
|
-
**Output Structure (JobStatus):**
|
|
46
|
-
- `status`: Standardized status enum
|
|
47
|
-
- `logs`: Array of standardized log entries
|
|
48
|
-
- `queuePosition`: Position in queue (optional)
|
|
49
|
-
|
|
50
|
-
## Status Mapping
|
|
51
|
-
|
|
52
|
-
### Mapping Table
|
|
53
|
-
|
|
54
|
-
| FAL Status | JobStatus | Description |
|
|
55
|
-
|------------|-----------|-------------|
|
|
56
|
-
| `IN_QUEUE` | `IN_QUEUE` | Job is queued |
|
|
57
|
-
| `IN_PROGRESS` | `IN_PROGRESS` | Job is processing |
|
|
58
|
-
| `COMPLETED` | `COMPLETED` | Job completed successfully |
|
|
59
|
-
| `FAILED` | `FAILED` | Job failed |
|
|
60
|
-
| *(invalid)* | `IN_PROGRESS` | Default fallback |
|
|
61
|
-
|
|
62
|
-
## Log Mapping
|
|
63
|
-
|
|
64
|
-
FAL log entries are mapped to JobLogEntry format:
|
|
65
|
-
|
|
66
|
-
**Transformation:**
|
|
67
|
-
- `message`: Preserved as-is
|
|
68
|
-
- `level`: Defaults to 'info' if missing
|
|
69
|
-
- `timestamp`: Defaults to current time if missing
|
|
70
|
-
|
|
71
|
-
**Safe Defaults:**
|
|
72
|
-
- Missing level → 'info'
|
|
73
|
-
- Missing timestamp → current ISO time
|
|
74
|
-
- Missing logs → empty array
|
|
75
|
-
- Invalid status → 'IN_PROGRESS'
|
|
76
|
-
|
|
77
|
-
## Usage Guidelines
|
|
78
|
-
|
|
79
|
-
### For Status Conversion
|
|
80
|
-
|
|
81
|
-
**Conversion Pattern:**
|
|
82
|
-
1. Receive FAL status from API
|
|
83
|
-
2. Call mapFalStatusToJobStatus
|
|
84
|
-
3. Use standardized status
|
|
85
|
-
4. Display in UI components
|
|
86
|
-
5. Track status changes
|
|
87
|
-
|
|
88
|
-
**Best Practices:**
|
|
89
|
-
- Always map FAL status before use
|
|
90
|
-
- Handle missing log fields
|
|
91
|
-
- Check for invalid status
|
|
92
|
-
- Use safe defaults
|
|
93
|
-
- Validate output if needed
|
|
94
|
-
|
|
95
|
-
### For Status Tracking
|
|
96
|
-
|
|
97
|
-
**Tracking Pattern:**
|
|
98
|
-
1. Map status on each update
|
|
99
|
-
2. Compare with previous status
|
|
100
|
-
3. Detect status changes
|
|
101
|
-
4. Update UI accordingly
|
|
102
|
-
5. Track transitions
|
|
103
|
-
|
|
104
|
-
**Best Practices:**
|
|
105
|
-
- Store mapped status
|
|
106
|
-
- Compare for changes
|
|
107
|
-
- Track status history
|
|
108
|
-
- Calculate durations
|
|
109
|
-
- Update state appropriately
|
|
110
|
-
|
|
111
|
-
## Best Practices
|
|
112
|
-
|
|
113
|
-
### 1. Always Map Status
|
|
114
|
-
|
|
115
|
-
Convert FAL status immediately:
|
|
116
|
-
- Map before storing in state
|
|
117
|
-
- Map before displaying in UI
|
|
118
|
-
- Map before comparing
|
|
119
|
-
- Use mapped status consistently
|
|
120
|
-
- Don't use raw FAL status
|
|
121
|
-
|
|
122
|
-
### 2. Handle Missing Fields
|
|
123
|
-
|
|
124
|
-
Account for optional fields:
|
|
125
|
-
- Check for missing logs
|
|
126
|
-
- Handle missing timestamps
|
|
127
|
-
- Validate log levels
|
|
128
|
-
- Provide safe defaults
|
|
129
|
-
- Don't assume fields exist
|
|
130
|
-
|
|
131
|
-
### 3. Validate Status
|
|
132
|
-
|
|
133
|
-
Check for invalid values:
|
|
134
|
-
- Handle unknown status strings
|
|
135
|
-
- Use fallback for invalid status
|
|
136
|
-
- Log validation failures
|
|
137
|
-
- Provide safe defaults
|
|
138
|
-
- Don't crash on bad data
|
|
139
|
-
|
|
140
|
-
### 4. Track Changes
|
|
141
|
-
|
|
142
|
-
Monitor status transitions:
|
|
143
|
-
- Compare current with previous
|
|
144
|
-
- Detect status changes
|
|
145
|
-
- Calculate transition times
|
|
146
|
-
- Update UI on changes
|
|
147
|
-
- Maintain status history
|
|
148
|
-
|
|
149
|
-
### 5. Use Type Safety
|
|
150
|
-
|
|
151
|
-
Leverage TypeScript types:
|
|
152
|
-
- Use proper type definitions
|
|
153
|
-
- Check instanceof for errors
|
|
154
|
-
- Use type guards
|
|
155
|
-
- Validate input types
|
|
156
|
-
- Maintain type safety
|
|
157
|
-
|
|
158
|
-
## For AI Agents
|
|
159
|
-
|
|
160
|
-
### When Mapping Status
|
|
161
|
-
|
|
162
|
-
**DO:**
|
|
163
|
-
- Map all FAL status objects
|
|
164
|
-
- Handle missing log fields
|
|
165
|
-
- Provide safe defaults
|
|
166
|
-
- Validate output status
|
|
167
|
-
- Use mapped status consistently
|
|
168
|
-
- Check for invalid values
|
|
169
|
-
- Handle errors gracefully
|
|
170
|
-
|
|
171
|
-
**DON'T:**
|
|
172
|
-
- Use raw FAL status
|
|
173
|
-
- Assume all fields exist
|
|
174
|
-
- Skip validation
|
|
175
|
-
- Ignore missing data
|
|
176
|
-
- Use inconsistent formats
|
|
177
|
-
- Create type mismatches
|
|
178
|
-
- Crash on bad data
|
|
179
|
-
|
|
180
|
-
### When Tracking Status
|
|
181
|
-
|
|
182
|
-
**DO:**
|
|
183
|
-
- Store mapped status
|
|
184
|
-
- Compare for changes
|
|
185
|
-
- Track transitions
|
|
186
|
-
- Update UI appropriately
|
|
187
|
-
- Calculate durations
|
|
188
|
-
- Maintain history
|
|
189
|
-
- Handle updates properly
|
|
190
|
-
|
|
191
|
-
**DON'T:**
|
|
192
|
-
- Store raw FAL status
|
|
193
|
-
- Skip comparison logic
|
|
194
|
-
- Ignore transitions
|
|
195
|
-
- Update UI inconsistently
|
|
196
|
-
- Lose status information
|
|
197
|
-
- Create memory leaks
|
|
198
|
-
- Handle updates poorly
|
|
199
|
-
|
|
200
|
-
### When Processing Logs
|
|
201
|
-
|
|
202
|
-
**DO:**
|
|
203
|
-
- Handle missing logs array
|
|
204
|
-
- Provide default timestamps
|
|
205
|
-
- Default log level to 'info'
|
|
206
|
-
- Validate log structure
|
|
207
|
-
- Process logs safely
|
|
208
|
-
- Display log information
|
|
209
|
-
- Handle empty logs
|
|
210
|
-
|
|
211
|
-
**DON'T:**
|
|
212
|
-
- Assume logs exist
|
|
213
|
-
- Skip log processing
|
|
214
|
-
- Ignore missing fields
|
|
215
|
-
- Create unsafe defaults
|
|
216
|
-
- Process logs inconsistently
|
|
217
|
-
- Hide log information
|
|
218
|
-
- Crash on bad logs
|
|
219
|
-
|
|
220
|
-
## Implementation Notes
|
|
221
|
-
|
|
222
|
-
**Location:** `src/infrastructure/services/fal-status-mapper.ts`
|
|
223
|
-
|
|
224
|
-
**Dependencies:**
|
|
225
|
-
- FAL types
|
|
226
|
-
- Job status types
|
|
227
|
-
- No external dependencies
|
|
228
|
-
|
|
229
|
-
**Mapping Logic:**
|
|
230
|
-
- Status string mapping
|
|
231
|
-
- Log entry transformation
|
|
232
|
-
- Safe defaults
|
|
233
|
-
- Fallback handling
|
|
234
|
-
- Type validation
|
|
235
|
-
|
|
236
|
-
**Import:**
|
|
237
|
-
```typescript
|
|
238
|
-
import {
|
|
239
|
-
mapFalStatusToJobStatus
|
|
240
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
**Related:**
|
|
244
|
-
- FAL types: `src/domain/entities/fal.types.ts`
|
|
245
|
-
- Job status: Provider-agnostic job status types
|
|
246
|
-
- Subscription handler: `src/infrastructure/services/fal-provider-subscription.ts`
|