@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,215 +0,0 @@
|
|
|
1
|
-
# NSFW Content Error
|
|
2
|
-
|
|
3
|
-
Error class for NSFW (Not Safe For Work) content detection.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/services/nsfw-content-error.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
`NSFWContentError` is a custom error class thrown when AI-generated content violates NSFW or content policy guidelines.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Provides NSFW error handling by:
|
|
14
|
-
- Identifying NSFW content violations
|
|
15
|
-
- Supporting error categorization
|
|
16
|
-
- Enabling specific error handling
|
|
17
|
-
- Facilitating user feedback
|
|
18
|
-
- Preventing inappropriate content
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import {
|
|
24
|
-
NSFWContentError
|
|
25
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Class
|
|
29
|
-
|
|
30
|
-
### NSFWContentError
|
|
31
|
-
|
|
32
|
-
Custom error class for NSFW content detection.
|
|
33
|
-
|
|
34
|
-
**Inheritance:**
|
|
35
|
-
- Extends: `Error`
|
|
36
|
-
- Name: `'NSFWContentError'`
|
|
37
|
-
- Default message: `'NSFW content detected'`
|
|
38
|
-
|
|
39
|
-
**Constructor:**
|
|
40
|
-
- `message`: Optional custom error message
|
|
41
|
-
|
|
42
|
-
**Properties:**
|
|
43
|
-
- `name`: Error class name
|
|
44
|
-
- `message`: Error description
|
|
45
|
-
- `stack`: Call stack (inherited from Error)
|
|
46
|
-
|
|
47
|
-
## Usage Guidelines
|
|
48
|
-
|
|
49
|
-
### For Error Throwing
|
|
50
|
-
|
|
51
|
-
**Throw Pattern:**
|
|
52
|
-
1. Detect NSFW content
|
|
53
|
-
2. Throw NSFWContentError
|
|
54
|
-
3. Provide descriptive message
|
|
55
|
-
4. Let error propagate
|
|
56
|
-
5. Handle at appropriate level
|
|
57
|
-
|
|
58
|
-
**Best Practices:**
|
|
59
|
-
- Use specific, clear messages
|
|
60
|
-
- Explain what was detected
|
|
61
|
-
- Guide users to fix issue
|
|
62
|
-
- Don't use vague messages
|
|
63
|
-
- Be consistent in messaging
|
|
64
|
-
|
|
65
|
-
### For Error Handling
|
|
66
|
-
|
|
67
|
-
**Handling Pattern:**
|
|
68
|
-
1. Catch errors from generation
|
|
69
|
-
2. Check instanceof NSFWContentError
|
|
70
|
-
3. Display user-friendly message
|
|
71
|
-
4. Suggest corrective action
|
|
72
|
-
5. Prevent retry for NSFW
|
|
73
|
-
|
|
74
|
-
**Best Practices:**
|
|
75
|
-
- Check type specifically
|
|
76
|
-
- Show clear error messages
|
|
77
|
-
- Block inappropriate content
|
|
78
|
-
- Don't allow retry
|
|
79
|
-
- Guide user behavior
|
|
80
|
-
|
|
81
|
-
## Best Practices
|
|
82
|
-
|
|
83
|
-
### 1. Use Descriptive Messages
|
|
84
|
-
|
|
85
|
-
Provide clear error messages:
|
|
86
|
-
- Explain what was detected
|
|
87
|
-
- Be specific about violation
|
|
88
|
-
- Use user-friendly language
|
|
89
|
-
- Suggest alternatives
|
|
90
|
-
- Maintain consistent messaging
|
|
91
|
-
|
|
92
|
-
### 2. Handle Separately
|
|
93
|
-
|
|
94
|
-
Treat NSFW errors differently:
|
|
95
|
-
- Catch NSFWContentError specifically
|
|
96
|
-
- Use different UI for NSFW
|
|
97
|
-
- Prevent retry attempts
|
|
98
|
-
- Track NSFW occurrences
|
|
99
|
-
- Inform content policy
|
|
100
|
-
|
|
101
|
-
### 3. Guide Users
|
|
102
|
-
|
|
103
|
-
Help users understand:
|
|
104
|
-
- Explain why content was blocked
|
|
105
|
-
- Describe what violates policy
|
|
106
|
-
- Suggest acceptable alternatives
|
|
107
|
-
- Provide clear guidance
|
|
108
|
-
- Enable quick correction
|
|
109
|
-
|
|
110
|
-
### 4. Track Occurrences
|
|
111
|
-
|
|
112
|
-
Monitor NSFW detection:
|
|
113
|
-
- Log NSFW occurrences
|
|
114
|
-
- Track frequency
|
|
115
|
-
- Identify patterns
|
|
116
|
-
- Implement rate limiting
|
|
117
|
-
- Prevent abuse
|
|
118
|
-
|
|
119
|
-
### 5. Prevent Retry
|
|
120
|
-
|
|
121
|
-
Block NSFW retry attempts:
|
|
122
|
-
- Mark errors as non-retryable
|
|
123
|
-
- Disable retry buttons
|
|
124
|
-
- Show appropriate messaging
|
|
125
|
-
- Enforce content policy
|
|
126
|
-
- Protect service integrity
|
|
127
|
-
|
|
128
|
-
## For AI Agents
|
|
129
|
-
|
|
130
|
-
### When Throwing NSFW Errors
|
|
131
|
-
|
|
132
|
-
**DO:**
|
|
133
|
-
- Throw NSFWContentError for violations
|
|
134
|
-
- Use descriptive messages
|
|
135
|
-
- Explain what was detected
|
|
136
|
-
- Guide users to fix
|
|
137
|
-
- Be specific and clear
|
|
138
|
-
- Maintain consistency
|
|
139
|
-
- Follow content policy
|
|
140
|
-
|
|
141
|
-
**DON'T:**
|
|
142
|
-
- Use generic error types
|
|
143
|
-
- Provide vague messages
|
|
144
|
-
- Skip explanations
|
|
145
|
-
- Leave users confused
|
|
146
|
-
- Use inconsistent messaging
|
|
147
|
-
- Ignore policy guidelines
|
|
148
|
-
- Allow inappropriate content
|
|
149
|
-
|
|
150
|
-
### When Handling NSFW Errors
|
|
151
|
-
|
|
152
|
-
**DO:**
|
|
153
|
-
- Check instanceof NSFWContentError
|
|
154
|
-
- Display user-friendly messages
|
|
155
|
-
- Block retry attempts
|
|
156
|
-
- Track occurrences
|
|
157
|
-
- Inform users clearly
|
|
158
|
-
- Suggest alternatives
|
|
159
|
-
- Follow content policy
|
|
160
|
-
|
|
161
|
-
**DON'T:**
|
|
162
|
-
- Handle like other errors
|
|
163
|
-
- Show technical details
|
|
164
|
-
- Allow retry
|
|
165
|
-
- Skip tracking
|
|
166
|
-
- Confuse users
|
|
167
|
-
- Hide the issue
|
|
168
|
-
- Ignore violations
|
|
169
|
-
|
|
170
|
-
### When Validating Content
|
|
171
|
-
|
|
172
|
-
**DO:**
|
|
173
|
-
- Validate all generated content
|
|
174
|
-
- Check NSFW concepts array
|
|
175
|
-
- Throw error for violations
|
|
176
|
-
- Be consistent in checking
|
|
177
|
-
- Log violations
|
|
178
|
-
- Prevent inappropriate content
|
|
179
|
-
- Update validation regularly
|
|
180
|
-
|
|
181
|
-
**DON'T:**
|
|
182
|
-
- Skip validation
|
|
183
|
-
- Ignore NSFW concepts
|
|
184
|
-
- Allow violations through
|
|
185
|
-
- Be inconsistent
|
|
186
|
-
- Forget logging
|
|
187
|
-
- Allow inappropriate content
|
|
188
|
-
- Use outdated rules
|
|
189
|
-
|
|
190
|
-
## Implementation Notes
|
|
191
|
-
|
|
192
|
-
**Location:** `src/infrastructure/services/nsfw-content-error.ts`
|
|
193
|
-
|
|
194
|
-
**Dependencies:**
|
|
195
|
-
- No external dependencies
|
|
196
|
-
- Extends built-in Error class
|
|
197
|
-
|
|
198
|
-
**Error Characteristics:**
|
|
199
|
-
- Named error class
|
|
200
|
-
- Default and custom messages
|
|
201
|
-
- Stack trace support
|
|
202
|
-
- Type-checkable with instanceof
|
|
203
|
-
- Compatible with try-catch
|
|
204
|
-
|
|
205
|
-
**Import:**
|
|
206
|
-
```typescript
|
|
207
|
-
import {
|
|
208
|
-
NSFWContentError
|
|
209
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
**Related:**
|
|
213
|
-
- NSFW validator: `src/infrastructure/validators/nsfw-validator.ts`
|
|
214
|
-
- Error types: `src/domain/entities/error.types.ts`
|
|
215
|
-
- Error mapper: `src/infrastructure/utils/error-mapper.ts`
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
# Base Builders
|
|
2
|
-
|
|
3
|
-
Base input builder functions for FAL API operations.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/utils/base-builders.util.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
Base builders create standardized input objects for image processing operations. These functions convert raw base64 strings to data URI format and add necessary parameters for FAL API requests.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Simplifies input construction by:
|
|
14
|
-
- Standardizing image input format across operations
|
|
15
|
-
- Converting base64 to data URI automatically
|
|
16
|
-
- Supporting single and dual image inputs
|
|
17
|
-
- Merging optional parameters
|
|
18
|
-
- Providing consistent input structure
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import {
|
|
24
|
-
buildSingleImageInput,
|
|
25
|
-
buildDualImageInput
|
|
26
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Functions
|
|
30
|
-
|
|
31
|
-
### buildSingleImageInput
|
|
32
|
-
|
|
33
|
-
Create input object with single image.
|
|
34
|
-
|
|
35
|
-
**Parameters:**
|
|
36
|
-
- `base64`: Base64 format image (data URI or raw string)
|
|
37
|
-
- `extraParams`: Optional additional parameters
|
|
38
|
-
|
|
39
|
-
**Returns:**
|
|
40
|
-
Input object with:
|
|
41
|
-
- `image_url`: Data URI formatted image
|
|
42
|
-
- `...extraParams`: Additional parameters merged in
|
|
43
|
-
|
|
44
|
-
**Usage:**
|
|
45
|
-
Use to build input for single-image operations. Automatically converts raw base64 to data URI. Preserves existing data URI format. Merges optional parameters into result.
|
|
46
|
-
|
|
47
|
-
**Implementation:** See complete implementation in `src/infrastructure/utils/base-builders.util.ts`
|
|
48
|
-
|
|
49
|
-
**Related:**
|
|
50
|
-
- Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
51
|
-
- Helper utilities: `src/infrastructure/utils/helpers.util.ts`
|
|
52
|
-
|
|
53
|
-
### buildDualImageInput
|
|
54
|
-
|
|
55
|
-
Create input object with two images.
|
|
56
|
-
|
|
57
|
-
**Parameters:**
|
|
58
|
-
- `sourceBase64`: Source image (base64)
|
|
59
|
-
- `targetBase64`: Target image (base64)
|
|
60
|
-
- `extraParams`: Optional additional parameters
|
|
61
|
-
|
|
62
|
-
**Returns:**
|
|
63
|
-
Input object with:
|
|
64
|
-
- `image_url`: Source image as data URI
|
|
65
|
-
- `second_image_url`: Target image as data URI
|
|
66
|
-
- `...extraParams`: Additional parameters merged in
|
|
67
|
-
|
|
68
|
-
**Usage:**
|
|
69
|
-
Use to build input for dual-image operations like face swap. Both images automatically converted to data URI format. Preserves existing data URI format. Merges optional parameters.
|
|
70
|
-
|
|
71
|
-
## Usage Guidelines
|
|
72
|
-
|
|
73
|
-
### For Single Image Operations
|
|
74
|
-
|
|
75
|
-
**Building Pattern:**
|
|
76
|
-
1. Prepare base64 image data or data URI
|
|
77
|
-
2. Call `buildSingleImageInput()` with image
|
|
78
|
-
3. Add optional parameters if needed
|
|
79
|
-
4. Pass result to FAL provider
|
|
80
|
-
5. Handle response appropriately
|
|
81
|
-
|
|
82
|
-
**Best Practices:**
|
|
83
|
-
- Validate image format before building
|
|
84
|
-
- Use data URI format for consistency
|
|
85
|
-
- Add model-specific parameters in extraParams
|
|
86
|
-
- Check model documentation for required parameters
|
|
87
|
-
- Handle optional parameters appropriately
|
|
88
|
-
|
|
89
|
-
**Related:**
|
|
90
|
-
- Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
91
|
-
- Type guards: `src/infrastructure/utils/type-guards.util.ts`
|
|
92
|
-
|
|
93
|
-
### For Dual Image Operations
|
|
94
|
-
|
|
95
|
-
**Building Pattern:**
|
|
96
|
-
1. Prepare both source and target images
|
|
97
|
-
2. Call `buildDualImageInput()` with both images
|
|
98
|
-
3. Add optional parameters if needed
|
|
99
|
-
4. Pass result to FAL provider
|
|
100
|
-
5. Handle response appropriately
|
|
101
|
-
|
|
102
|
-
**Parameter Order:**
|
|
103
|
-
- First parameter: source/target image (depends on model)
|
|
104
|
-
- Second parameter: second image
|
|
105
|
-
- Check model documentation for correct order
|
|
106
|
-
|
|
107
|
-
**Related:**
|
|
108
|
-
- Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
109
|
-
|
|
110
|
-
### For Parameter Configuration
|
|
111
|
-
|
|
112
|
-
**Optional Parameters:**
|
|
113
|
-
- Define in extraParams object
|
|
114
|
-
- Model-specific parameters
|
|
115
|
-
- Type-safe parameter objects recommended
|
|
116
|
-
- Check model documentation for available options
|
|
117
|
-
|
|
118
|
-
**Parameter Merging:**
|
|
119
|
-
- ExtraParams shallow merged into result
|
|
120
|
-
- Image properties not overwritten
|
|
121
|
-
- Use specific parameter names from model docs
|
|
122
|
-
- Test with different parameter combinations
|
|
123
|
-
|
|
124
|
-
### For Pipeline Operations
|
|
125
|
-
|
|
126
|
-
**Sequential Processing:**
|
|
127
|
-
1. Build input for first operation
|
|
128
|
-
2. Get result from first operation
|
|
129
|
-
3. Extract image URL from result
|
|
130
|
-
4. Convert to base64 if needed for next operation
|
|
131
|
-
5. Build input for next operation
|
|
132
|
-
6. Continue through pipeline
|
|
133
|
-
|
|
134
|
-
**Parallel Processing:**
|
|
135
|
-
1. Build inputs for multiple operations
|
|
136
|
-
2. Execute operations in parallel
|
|
137
|
-
3. Wait for all operations to complete
|
|
138
|
-
4. Combine results as needed
|
|
139
|
-
|
|
140
|
-
## Best Practices
|
|
141
|
-
|
|
142
|
-
### 1. Validate Before Building
|
|
143
|
-
|
|
144
|
-
Check image data:
|
|
145
|
-
- Validate base64 format
|
|
146
|
-
- Check image data is not corrupted
|
|
147
|
-
- Ensure minimum resolution requirements
|
|
148
|
-
- Verify image format (JPEG/PNG)
|
|
149
|
-
- Use type guards for validation
|
|
150
|
-
|
|
151
|
-
**Related:**
|
|
152
|
-
- Type guards: `src/infrastructure/utils/type-guards.util.ts`
|
|
153
|
-
- Helper utilities: `src/infrastructure/utils/helpers.util.ts`
|
|
154
|
-
|
|
155
|
-
### 2. Use Data URI Format
|
|
156
|
-
|
|
157
|
-
Maintain consistent format:
|
|
158
|
-
- Builders automatically convert to data URI
|
|
159
|
-
- Use data URI format for all images
|
|
160
|
-
- Preserve existing data URI format
|
|
161
|
-
- Don't double-format images
|
|
162
|
-
- Check format before building
|
|
163
|
-
|
|
164
|
-
### 3. Handle Parameters Correctly
|
|
165
|
-
|
|
166
|
-
Configure model parameters:
|
|
167
|
-
- Add model-specific parameters in extraParams
|
|
168
|
-
- Check documentation for parameter names
|
|
169
|
-
- Use typed parameter objects
|
|
170
|
-
- Provide required parameters
|
|
171
|
-
- Set appropriate defaults
|
|
172
|
-
|
|
173
|
-
### 4. Build Reusable Wrappers
|
|
174
|
-
|
|
175
|
-
Create specialized builders:
|
|
176
|
-
- Wrap base builders for specific operations
|
|
177
|
-
- Add validation in wrapper
|
|
178
|
-
- Set default parameters
|
|
179
|
-
- Simplify common operations
|
|
180
|
-
- Maintain type safety
|
|
181
|
-
|
|
182
|
-
### 5. Test Image Inputs
|
|
183
|
-
|
|
184
|
-
Verify inputs work:
|
|
185
|
-
- Test with real images
|
|
186
|
-
- Check parameter combinations
|
|
187
|
-
- Validate output format
|
|
188
|
-
- Handle edge cases
|
|
189
|
-
- Test with various image sizes
|
|
190
|
-
|
|
191
|
-
## For AI Agents
|
|
192
|
-
|
|
193
|
-
### When Using Base Builders
|
|
194
|
-
|
|
195
|
-
**DO:**
|
|
196
|
-
- Import from package root
|
|
197
|
-
- Validate image data before building
|
|
198
|
-
- Use appropriate builder for image count
|
|
199
|
-
- Add model-specific parameters
|
|
200
|
-
- Check model documentation
|
|
201
|
-
- Handle data URI format correctly
|
|
202
|
-
- Test with sample images
|
|
203
|
-
|
|
204
|
-
**DON'T:**
|
|
205
|
-
- Skip image validation
|
|
206
|
-
- Use wrong builder for image count
|
|
207
|
-
- Ignore model parameter requirements
|
|
208
|
-
- Forget data URI conversion
|
|
209
|
-
- Manually format data URIs
|
|
210
|
-
- Mix up source/target order
|
|
211
|
-
- Skip parameter documentation
|
|
212
|
-
|
|
213
|
-
### When Building Inputs
|
|
214
|
-
|
|
215
|
-
**DO:**
|
|
216
|
-
- Use `buildSingleImageInput()` for single images
|
|
217
|
-
- Use `buildDualImageInput()` for two images
|
|
218
|
-
- Provide base64 or data URI format
|
|
219
|
-
- Add optional parameters in extraParams
|
|
220
|
-
- Validate before building
|
|
221
|
-
- Check model requirements
|
|
222
|
-
- Test output format
|
|
223
|
-
|
|
224
|
-
**DON'T:**
|
|
225
|
-
- Manually construct input objects
|
|
226
|
-
- Skip data URI formatting
|
|
227
|
-
- Forget required parameters
|
|
228
|
-
- Use wrong parameter names
|
|
229
|
-
- Ignore validation
|
|
230
|
-
- Mix up parameter order
|
|
231
|
-
- Create duplicate builders
|
|
232
|
-
|
|
233
|
-
### When Handling Results
|
|
234
|
-
|
|
235
|
-
**DO:**
|
|
236
|
-
- Validate input format
|
|
237
|
-
- Handle image URLs appropriately
|
|
238
|
-
- Extract results correctly
|
|
239
|
-
- Process returned data
|
|
240
|
-
- Handle errors gracefully
|
|
241
|
-
- Log issues for debugging
|
|
242
|
-
- Test with real API
|
|
243
|
-
|
|
244
|
-
**DON'T:**
|
|
245
|
-
- Assume input format
|
|
246
|
-
- Ignore image URLs
|
|
247
|
-
- Skip result validation
|
|
248
|
-
- Process data incorrectly
|
|
249
|
-
- Forget error handling
|
|
250
|
-
- Lose image data
|
|
251
|
-
- Skip API testing
|
|
252
|
-
|
|
253
|
-
### When Adding Builders
|
|
254
|
-
|
|
255
|
-
**For New Base Builders:**
|
|
256
|
-
1. Add function to base builders file
|
|
257
|
-
2. Follow existing patterns
|
|
258
|
-
3. Handle data URI formatting
|
|
259
|
-
4. Support optional parameters
|
|
260
|
-
5. Update exports
|
|
261
|
-
6. Document in this README
|
|
262
|
-
|
|
263
|
-
**For Enhanced Builders:**
|
|
264
|
-
1. Review existing builders
|
|
265
|
-
2. Add validation if needed
|
|
266
|
-
3. Improve error handling
|
|
267
|
-
4. Support new formats
|
|
268
|
-
5. Update TypeScript types
|
|
269
|
-
6. Test with various inputs
|
|
270
|
-
|
|
271
|
-
**For Specialized Builders:**
|
|
272
|
-
1. Wrap base builders appropriately
|
|
273
|
-
2. Add domain-specific logic
|
|
274
|
-
3. Set default parameters
|
|
275
|
-
4. Validate inputs
|
|
276
|
-
5. Export from appropriate module
|
|
277
|
-
6. Document usage patterns
|
|
278
|
-
|
|
279
|
-
## Implementation Notes
|
|
280
|
-
|
|
281
|
-
**Location:** `src/infrastructure/utils/base-builders.util.ts`
|
|
282
|
-
|
|
283
|
-
**Dependencies:**
|
|
284
|
-
- Uses helper utilities from `src/infrastructure/utils/helpers.util.ts`
|
|
285
|
-
- No external dependencies
|
|
286
|
-
- Pure builder functions
|
|
287
|
-
|
|
288
|
-
**Builder Categories:**
|
|
289
|
-
- Single image input builders
|
|
290
|
-
- Dual image input builders
|
|
291
|
-
- Parameter merging utilities
|
|
292
|
-
- Data URI formatting
|
|
293
|
-
|
|
294
|
-
**Import:**
|
|
295
|
-
```typescript
|
|
296
|
-
import {
|
|
297
|
-
buildSingleImageInput,
|
|
298
|
-
buildDualImageInput
|
|
299
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
**Related:**
|
|
303
|
-
- Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
304
|
-
- Video feature builders: `src/infrastructure/utils/video-feature-builders.util.ts`
|
|
305
|
-
- Helper utilities: `src/infrastructure/utils/helpers.util.ts`
|
|
306
|
-
- Type guards: `src/infrastructure/utils/type-guards.util.ts`
|
|
307
|
-
|
|
308
|
-
## Related Documentation
|
|
309
|
-
|
|
310
|
-
- [Image Feature Builders](./image-feature-builders.util.README.md)
|
|
311
|
-
- [Video Feature Builders](./video-feature-builders.util.README.md)
|
|
312
|
-
- [Helper Utilities](./helpers.util.README.md)
|
|
313
|
-
- [Type Guards](./type-guards.util.README.md)
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cost Tracker Queries
|
|
3
|
-
* Query functions for cost history analysis
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { GenerationCost, CostSummary } from "../../domain/entities/cost-tracking.types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Calculate cost summary from history
|
|
10
|
-
*/
|
|
11
|
-
export function calculateCostSummary(
|
|
12
|
-
costHistory: readonly GenerationCost[],
|
|
13
|
-
currency: string
|
|
14
|
-
): CostSummary {
|
|
15
|
-
const completedCosts = costHistory.filter((c) => c.actualCost > 0);
|
|
16
|
-
const totalCost = completedCosts.reduce((sum, c) => sum + c.actualCost, 0);
|
|
17
|
-
const totalGenerations = completedCosts.length;
|
|
18
|
-
const averageCost = totalGenerations > 0 ? totalCost / totalGenerations : 0;
|
|
19
|
-
|
|
20
|
-
const modelBreakdown: Record<string, number> = {};
|
|
21
|
-
const operationBreakdown: Record<string, number> = {};
|
|
22
|
-
|
|
23
|
-
for (const cost of completedCosts) {
|
|
24
|
-
modelBreakdown[cost.model] = (modelBreakdown[cost.model] ?? 0) + cost.actualCost;
|
|
25
|
-
operationBreakdown[cost.operation] = (operationBreakdown[cost.operation] ?? 0) + cost.actualCost;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
totalCost,
|
|
30
|
-
totalGenerations,
|
|
31
|
-
averageCost,
|
|
32
|
-
currency,
|
|
33
|
-
modelBreakdown,
|
|
34
|
-
operationBreakdown,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Filter costs by model
|
|
40
|
-
*/
|
|
41
|
-
export function filterCostsByModel(
|
|
42
|
-
costHistory: readonly GenerationCost[],
|
|
43
|
-
modelId: string
|
|
44
|
-
): GenerationCost[] {
|
|
45
|
-
return costHistory.filter((c) => c.model === modelId);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Filter costs by operation type
|
|
50
|
-
*/
|
|
51
|
-
export function filterCostsByOperation(
|
|
52
|
-
costHistory: readonly GenerationCost[],
|
|
53
|
-
operation: string
|
|
54
|
-
): GenerationCost[] {
|
|
55
|
-
return costHistory.filter((c) => c.operation === operation);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Filter costs by time range
|
|
60
|
-
*/
|
|
61
|
-
export function filterCostsByTimeRange(
|
|
62
|
-
costHistory: readonly GenerationCost[],
|
|
63
|
-
startTime: number,
|
|
64
|
-
endTime: number
|
|
65
|
-
): GenerationCost[] {
|
|
66
|
-
return costHistory.filter((c) => c.timestamp >= startTime && c.timestamp <= endTime);
|
|
67
|
-
}
|