@umituz/react-native-ai-gemini-provider 1.14.27 → 1.14.29
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 +1 -1
- package/src/domain/README.md +232 -0
- package/src/domain/constants/README.md +191 -0
- package/src/domain/entities/README.md +238 -0
- package/src/infrastructure/README.md +252 -0
- package/src/infrastructure/cache/CACHE_SYSTEM.md +213 -0
- package/src/infrastructure/cache/README.md +213 -0
- package/src/infrastructure/content/CONTENT_BUILDER.md +175 -0
- package/src/infrastructure/content/README.md +175 -0
- package/src/infrastructure/interceptors/README.md +226 -0
- package/src/infrastructure/interceptors/REQUEST_INTERCEPTORS.md +171 -0
- package/src/infrastructure/job/JOB_MANAGER.md +174 -0
- package/src/infrastructure/job/README.md +194 -0
- package/src/infrastructure/response/README.md +187 -0
- package/src/infrastructure/response/RESPONSE_FORMATTER.md +185 -0
- package/src/infrastructure/services/CORE_CLIENT_SERVICE.md +202 -0
- package/src/infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md +206 -0
- package/src/infrastructure/services/GENERATION_EXECUTOR_SERVICE.md +176 -0
- package/src/infrastructure/services/IMAGE_EDIT_SERVICE.md +169 -0
- package/src/infrastructure/services/IMAGE_GENERATION_SERVICE.md +166 -0
- package/src/infrastructure/services/JOB_PROCESSOR_SERVICE.md +174 -0
- package/src/infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md +176 -0
- package/src/infrastructure/services/README.md +233 -0
- package/src/infrastructure/services/RETRY_SERVICE.md +178 -0
- package/src/infrastructure/services/STREAMING_SERVICE.md +166 -0
- package/src/infrastructure/services/STRUCTURED_TEXT_SERVICE.md +175 -0
- package/src/infrastructure/services/TEXT_GENERATION_SERVICE.md +160 -0
- package/src/infrastructure/services/VEO_HTTP_CLIENT_SERVICE.md +179 -0
- package/src/infrastructure/services/VEO_POLLING_SERVICE.md +173 -0
- package/src/infrastructure/services/VIDEO_DOWNLOADER_SERVICE.md +166 -0
- package/src/infrastructure/services/VIDEO_ERROR_HANDLER_SERVICE.md +185 -0
- package/src/infrastructure/services/VIDEO_GENERATION_SERVICE.md +176 -0
- package/src/infrastructure/services/VIDEO_URL_EXTRACTOR_SERVICE.md +186 -0
- package/src/infrastructure/telemetry/README.md +203 -0
- package/src/infrastructure/telemetry/TELEMETRY_SYSTEM.md +200 -0
- package/src/infrastructure/utils/DATA_TRANSFORMER_UTILS.md +175 -0
- package/src/infrastructure/utils/ERROR_MAPPER.md +170 -0
- package/src/infrastructure/utils/ERROR_UTILITIES.md +208 -0
- package/src/infrastructure/utils/IMAGE_PREPARER_UTILS.md +185 -0
- package/src/infrastructure/utils/INPUT_BUILDERS.md +214 -0
- package/src/infrastructure/utils/MODEL_VALIDATION_UTILS.md +189 -0
- package/src/infrastructure/utils/PERFORMANCE_UTILITIES.md +477 -0
- package/src/infrastructure/utils/PERFORMANCE_UTILS.md +219 -0
- package/src/infrastructure/utils/README.md +289 -0
- package/src/presentation/README.md +187 -0
- package/src/presentation/hooks/README.md +188 -0
- package/src/presentation/hooks/USE_GEMINI_HOOK.md +226 -0
- package/src/providers/README.md +247 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Error Utilities
|
|
2
|
+
|
|
3
|
+
Utilities for managing and standardizing Gemini API errors. Provides error categorization, retry detection, and user-friendly messaging.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
mapGeminiError,
|
|
10
|
+
isGeminiErrorRetryable,
|
|
11
|
+
categorizeGeminiError,
|
|
12
|
+
createGeminiError
|
|
13
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 🎯 Purpose
|
|
17
|
+
|
|
18
|
+
Use these utilities to handle Gemini API errors consistently. Provides error categorization, retry logic, and user-friendly messaging.
|
|
19
|
+
|
|
20
|
+
**When to use:**
|
|
21
|
+
- Categorize API errors by type
|
|
22
|
+
- Determine if errors are retryable
|
|
23
|
+
- Create user-friendly error messages
|
|
24
|
+
- Implement retry logic
|
|
25
|
+
- Log errors for monitoring
|
|
26
|
+
|
|
27
|
+
## 📌 Strategy
|
|
28
|
+
|
|
29
|
+
Consistent error handling improves UX and debugging. These utilities:
|
|
30
|
+
- Categorize errors into standard types
|
|
31
|
+
- Identify retryable vs non-retryable errors
|
|
32
|
+
- Provide structured error information
|
|
33
|
+
- Enable intelligent retry logic
|
|
34
|
+
- Support error analytics and monitoring
|
|
35
|
+
|
|
36
|
+
**Key Decision**: Use error categorization to determine retry logic. Only retry transient errors (network, rate limit, server errors), not permanent errors (auth, validation, safety).
|
|
37
|
+
|
|
38
|
+
## ⚠️ Rules
|
|
39
|
+
|
|
40
|
+
### Usage Rules
|
|
41
|
+
- **MUST** categorize errors before handling
|
|
42
|
+
- **SHOULD** check retryable status before retrying
|
|
43
|
+
- **MUST** provide user-friendly messages
|
|
44
|
+
- **SHOULD** log errors for debugging
|
|
45
|
+
- **MUST NOT** expose API keys in errors
|
|
46
|
+
|
|
47
|
+
### Error Handling Rules
|
|
48
|
+
- **MUST** use `isGeminiErrorRetryable()` before retrying
|
|
49
|
+
- **SHOULD** use `categorizeGeminiError()` for error handling
|
|
50
|
+
- **MUST** handle permanent errors appropriately (no retry)
|
|
51
|
+
- **SHOULD** implement user-friendly error messages
|
|
52
|
+
- **MUST** log errors with full context
|
|
53
|
+
|
|
54
|
+
### Retry Rules
|
|
55
|
+
- **WILL RETRY**: QUOTA_EXCEEDED, RATE_LIMIT, NETWORK, TIMEOUT, SERVER (5xx)
|
|
56
|
+
- **WILL NOT RETRY**: AUTHENTICATION, SAFETY, VALIDATION, MODEL_NOT_FOUND
|
|
57
|
+
|
|
58
|
+
## 🤖 AI Agent Guidelines
|
|
59
|
+
|
|
60
|
+
### When Modifying These Utilities
|
|
61
|
+
1. **READ** the implementation file first
|
|
62
|
+
2. **UNDERSTAND** error patterns
|
|
63
|
+
3. **MAINTAIN** backward compatibility
|
|
64
|
+
4. **ADD** tests for new error patterns
|
|
65
|
+
5. **UPDATE** type definitions
|
|
66
|
+
|
|
67
|
+
### When Adding New Features
|
|
68
|
+
1. **CHECK** if similar error handling exists
|
|
69
|
+
2. **FOLLOW** existing patterns
|
|
70
|
+
3. **ADD** new error patterns to mapper
|
|
71
|
+
4. **DOCUMENT** in type definitions
|
|
72
|
+
5. **ADD** examples to tests (not docs)
|
|
73
|
+
|
|
74
|
+
### When Fixing Bugs
|
|
75
|
+
1. **REPRODUCE** bug locally first
|
|
76
|
+
2. **IDENTIFY** root cause
|
|
77
|
+
3. **FIX** with minimal changes
|
|
78
|
+
4. **ADD** regression test
|
|
79
|
+
5. **VERIFY** all tests pass
|
|
80
|
+
|
|
81
|
+
### Code Style Rules
|
|
82
|
+
- **VALIDATE** error inputs
|
|
83
|
+
- **THROW** typed errors (`GeminiError`)
|
|
84
|
+
- **LOG** error categorization
|
|
85
|
+
- **COMMENT** complex pattern matching
|
|
86
|
+
- **USE** consistent error types
|
|
87
|
+
|
|
88
|
+
## 📦 Available Functions
|
|
89
|
+
|
|
90
|
+
### `mapGeminiError(error)`
|
|
91
|
+
|
|
92
|
+
Convert Gemini API errors to standard format.
|
|
93
|
+
|
|
94
|
+
**Refer to**: [`error-mapper.util.ts`](./error-mapper.util.ts)
|
|
95
|
+
|
|
96
|
+
### `isGeminiErrorRetryable(error)`
|
|
97
|
+
|
|
98
|
+
Check if error is retryable.
|
|
99
|
+
|
|
100
|
+
**Refer to**: [`error-mapper.util.ts`](./error-mapper.util.ts)
|
|
101
|
+
|
|
102
|
+
### `categorizeGeminiError(error)`
|
|
103
|
+
|
|
104
|
+
Determine error category.
|
|
105
|
+
|
|
106
|
+
**Refer to**: [`error-mapper.util.ts`](./error-mapper.util.ts)
|
|
107
|
+
|
|
108
|
+
### `createGeminiError(error)`
|
|
109
|
+
|
|
110
|
+
Create `GeminiError` instance.
|
|
111
|
+
|
|
112
|
+
**Refer to**: [`error-mapper.util.ts`](./error-mapper.util.ts)
|
|
113
|
+
|
|
114
|
+
## 🔗 Related Modules
|
|
115
|
+
|
|
116
|
+
- **Error Types**: [`domain/entities/error.types.ts`](../domain/entities/error.types.ts)
|
|
117
|
+
- **Retry Service**: [`RETRY_SERVICE.md`](../infrastructure/services/RETRY_SERVICE.md)
|
|
118
|
+
- **Error Mapper**: [`ERROR_MAPPER.md`](./ERROR_MAPPER.md)
|
|
119
|
+
|
|
120
|
+
## 📋 Configuration Reference
|
|
121
|
+
|
|
122
|
+
### GeminiErrorType Categories
|
|
123
|
+
|
|
124
|
+
| Error Type | Description | Retry | Example Message |
|
|
125
|
+
|------------|-------------|-------|-----------------|
|
|
126
|
+
| `QUOTA_EXCEEDED` | Quota exceeded | ✅ | "Quota exceeded" |
|
|
127
|
+
| `RATE_LIMIT` | Rate limit | ✅ | "Too many requests" |
|
|
128
|
+
| `AUTHENTICATION` | Authentication failed | ❌ | "Invalid API key" |
|
|
129
|
+
| `SAFETY` | Safety blocked | ❌ | "Content blocked" |
|
|
130
|
+
| `MODEL_NOT_FOUND` | Model not found | ❌ | "Model not found" |
|
|
131
|
+
| `NETWORK` | Network error | ✅ | "Network error" |
|
|
132
|
+
| `TIMEOUT` | Request timeout | ✅ | "Request timeout" |
|
|
133
|
+
| `SERVER` | Server error (5xx) | ✅ | "Internal server error" |
|
|
134
|
+
| `VALIDATION` | Validation error | ❌ | "Invalid request" |
|
|
135
|
+
| `UNKNOWN` | Unknown error | ❌ | "Unknown error" |
|
|
136
|
+
|
|
137
|
+
### Error Patterns
|
|
138
|
+
|
|
139
|
+
Error mapper searches for these patterns in error messages:
|
|
140
|
+
- **Quota**: "quota", "resource exhausted", "429"
|
|
141
|
+
- **Rate Limit**: "rate limit", "too many requests"
|
|
142
|
+
- **Auth**: "unauthorized", "invalid api key", "401", "403"
|
|
143
|
+
- **Safety**: "safety", "blocked", "harmful"
|
|
144
|
+
- **Not Found**: "model not found", "404"
|
|
145
|
+
- **Network**: "network", "fetch failed", "connection"
|
|
146
|
+
- **Timeout**: "timeout", "timed out"
|
|
147
|
+
- **Server**: "500", "502", "503", "504", "internal server"
|
|
148
|
+
- **Validation**: "invalid", "bad request", "400"
|
|
149
|
+
|
|
150
|
+
## 🎓 Usage Patterns
|
|
151
|
+
|
|
152
|
+
### Retry Logic
|
|
153
|
+
1. Catch error from API call
|
|
154
|
+
2. Check `isGeminiErrorRetryable()`
|
|
155
|
+
3. If retryable and max retries not reached, retry with backoff
|
|
156
|
+
4. If non-retryable or max retries reached, handle error
|
|
157
|
+
5. Provide user feedback
|
|
158
|
+
|
|
159
|
+
### Error Categorization
|
|
160
|
+
1. Catch error from operation
|
|
161
|
+
2. Call `categorizeGeminiError()` to get error type
|
|
162
|
+
3. Switch on error type for handling
|
|
163
|
+
4. Show appropriate user message per type
|
|
164
|
+
5. Log error with full context
|
|
165
|
+
|
|
166
|
+
### User-Friendly Messages
|
|
167
|
+
1. Categorize error using `categorizeGeminiError()`
|
|
168
|
+
2. Map error type to user-friendly message
|
|
169
|
+
3. Display message to user
|
|
170
|
+
4. Provide actionable next steps when possible
|
|
171
|
+
5. Log technical details separately
|
|
172
|
+
|
|
173
|
+
### Error Analytics
|
|
174
|
+
1. Categorize each error
|
|
175
|
+
2. Track error counts by type
|
|
176
|
+
3. Calculate error rates
|
|
177
|
+
4. Send to analytics service
|
|
178
|
+
5. Monitor error trends
|
|
179
|
+
|
|
180
|
+
### Conditional Retry
|
|
181
|
+
1. Attempt operation
|
|
182
|
+
2. On error, check if retryable
|
|
183
|
+
3. If retryable, calculate backoff delay
|
|
184
|
+
4. Wait for backoff period
|
|
185
|
+
5. Retry operation or fail after max attempts
|
|
186
|
+
|
|
187
|
+
## 🚨 Common Pitfalls
|
|
188
|
+
|
|
189
|
+
### Don't
|
|
190
|
+
- Retry non-retryable errors (auth, validation, safety)
|
|
191
|
+
- Show technical error messages to users
|
|
192
|
+
- Ignore error categorization
|
|
193
|
+
- Forget to log errors
|
|
194
|
+
- Expose API keys in error messages
|
|
195
|
+
|
|
196
|
+
### Do
|
|
197
|
+
- Always check error type before handling
|
|
198
|
+
- Use retryable status for retry logic
|
|
199
|
+
- Provide user-friendly messages
|
|
200
|
+
- Log errors with full context
|
|
201
|
+
- Track errors for analytics
|
|
202
|
+
- Implement exponential backoff for retries
|
|
203
|
+
- Handle permanent errors appropriately
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
**Last Updated**: 2025-01-08
|
|
208
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Image Preparer Utility
|
|
2
|
+
|
|
3
|
+
Helper functions for preparing images for Gemini API. Handles URI to base64 conversion and MIME type detection.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
prepareImageFromUri,
|
|
10
|
+
prepareImage,
|
|
11
|
+
isValidBase64
|
|
12
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 🎯 Purpose
|
|
16
|
+
|
|
17
|
+
Use image preparer to convert image URIs to base64 format. Handles various URI types and MIME type detection.
|
|
18
|
+
|
|
19
|
+
**When to use:**
|
|
20
|
+
- Convert image URIs to base64
|
|
21
|
+
- Detect MIME types from URIs
|
|
22
|
+
- Prepare images for API upload
|
|
23
|
+
- Validate base64 data
|
|
24
|
+
- Handle React Native image selection
|
|
25
|
+
|
|
26
|
+
## 📌 Strategy
|
|
27
|
+
|
|
28
|
+
Image preparation ensures compatibility. This utility:
|
|
29
|
+
- Converts various URI formats to base64
|
|
30
|
+
- Detects MIME types automatically
|
|
31
|
+
- Validates base64 data
|
|
32
|
+
- Handles different image sources
|
|
33
|
+
- Simplifies image processing
|
|
34
|
+
|
|
35
|
+
**Key Decision**: Always use preparer for image data. Handles URI conversion and MIME detection automatically.
|
|
36
|
+
|
|
37
|
+
## ⚠️ Rules
|
|
38
|
+
|
|
39
|
+
### Conversion Rules
|
|
40
|
+
- **MUST** validate URI before conversion
|
|
41
|
+
- **SHOULD** handle various URI formats
|
|
42
|
+
- **MUST** detect MIME type correctly
|
|
43
|
+
- **SHOULD** validate output base64
|
|
44
|
+
- **MUST NOT** lose data integrity
|
|
45
|
+
|
|
46
|
+
### Validation Rules
|
|
47
|
+
- **SHOULD** validate base64 format
|
|
48
|
+
- **MUST** check for empty data
|
|
49
|
+
- **SHOULD** validate MIME types
|
|
50
|
+
- **MUST** handle validation errors
|
|
51
|
+
- **SHOULD NOT** accept invalid data
|
|
52
|
+
|
|
53
|
+
### URI Handling Rules
|
|
54
|
+
- **MUST** support various URI types
|
|
55
|
+
- **SHOULD** detect format automatically
|
|
56
|
+
- **MUST** handle network URIs
|
|
57
|
+
- **SHOULD** cache conversions when possible
|
|
58
|
+
- **MUST NOT** fail silently
|
|
59
|
+
|
|
60
|
+
### Performance Rules
|
|
61
|
+
- **SHOULD** cache prepared images
|
|
62
|
+
- **MUST** handle large images efficiently
|
|
63
|
+
- **SHOULD** optimize when needed
|
|
64
|
+
- **MUST NOT** block main thread
|
|
65
|
+
- **SHOULD** handle concurrent requests
|
|
66
|
+
|
|
67
|
+
## 🤖 AI Agent Guidelines
|
|
68
|
+
|
|
69
|
+
### When Preparing Images
|
|
70
|
+
1. **CALL** prepareImageFromUri()
|
|
71
|
+
2. **PROVIDE** image URI
|
|
72
|
+
3. **WAIT** for conversion
|
|
73
|
+
4. **VALIDATE** output
|
|
74
|
+
5. **HANDLE** errors gracefully
|
|
75
|
+
|
|
76
|
+
### When Validating Base64
|
|
77
|
+
1. **CALL** isValidBase64()
|
|
78
|
+
2. **PROVIDE** base64 string
|
|
79
|
+
3. **CHECK** return value
|
|
80
|
+
4. **HANDLE** invalid data
|
|
81
|
+
5. **PROVIDE** clear feedback
|
|
82
|
+
|
|
83
|
+
### When Processing Multiple Images
|
|
84
|
+
1. **PREPARE** images in parallel
|
|
85
|
+
2. **USE** Promise.all()
|
|
86
|
+
3. **VALIDATE** all results
|
|
87
|
+
4. **CACHE** prepared images
|
|
88
|
+
5. **HANDLE** partial failures
|
|
89
|
+
|
|
90
|
+
### Code Style Rules
|
|
91
|
+
- **VALIDATE** input URIs
|
|
92
|
+
- **HANDLE** conversion errors
|
|
93
|
+
- **CACHE** when appropriate
|
|
94
|
+
- **VALIDATE** output data
|
|
95
|
+
- **LOG** preparation issues
|
|
96
|
+
|
|
97
|
+
## 📦 Available Functions
|
|
98
|
+
|
|
99
|
+
**Refer to**: [`image-preparer.util.ts`](./image-preparer.util.ts)
|
|
100
|
+
|
|
101
|
+
### Image Preparation
|
|
102
|
+
- `prepareImageFromUri(uri)` - Convert URI to base64
|
|
103
|
+
- `prepareImage(uri)` - Alias for prepareImageFromUri
|
|
104
|
+
|
|
105
|
+
### Validation
|
|
106
|
+
- `isValidBase64(str)` - Validate base64 format
|
|
107
|
+
|
|
108
|
+
## 🔗 Related Modules
|
|
109
|
+
|
|
110
|
+
- **Data Transformer**: [`./DATA_TRANSFORMER_UTILS.md`](./DATA_TRANSFORMER_UTILS.md)
|
|
111
|
+
- **Input Builders**: [`./INPUT_BUILDERS.md`](./INPUT_BUILDERS.md)
|
|
112
|
+
- **Image Edit Service**: [`../services/IMAGE_EDIT_SERVICE.md`](../services/IMAGE_EDIT_SERVICE.md)
|
|
113
|
+
|
|
114
|
+
## 📋 Supported Formats
|
|
115
|
+
|
|
116
|
+
### URI Types
|
|
117
|
+
- Data URL: `data:image/png;base64,...`
|
|
118
|
+
- HTTP/HTTPS URL: `https://example.com/image.jpg`
|
|
119
|
+
- File URI: `file:///path/to/image.png`
|
|
120
|
+
- React Native Asset: Asset paths
|
|
121
|
+
|
|
122
|
+
### MIME Types
|
|
123
|
+
- JPEG: `.jpg`, `.jpeg` → `image/jpeg`
|
|
124
|
+
- PNG: `.png` → `image/png`
|
|
125
|
+
- GIF: `.gif` → `image/gif`
|
|
126
|
+
- WebP: `.webp` → `image/webp`
|
|
127
|
+
|
|
128
|
+
### Return Type
|
|
129
|
+
```typescript
|
|
130
|
+
{
|
|
131
|
+
base64: string; // Pure base64 (no data URL)
|
|
132
|
+
mimeType: string; // Detected MIME type
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 🎓 Usage Patterns
|
|
137
|
+
|
|
138
|
+
### Basic Preparation
|
|
139
|
+
1. Provide image URI
|
|
140
|
+
2. Call prepareImageFromUri()
|
|
141
|
+
3. Get base64 and MIME type
|
|
142
|
+
4. Use in API request
|
|
143
|
+
5. Handle errors
|
|
144
|
+
|
|
145
|
+
### Image Picker Integration
|
|
146
|
+
1. Get URI from image picker
|
|
147
|
+
2. Call prepareImageFromUri()
|
|
148
|
+
3. Validate prepared image
|
|
149
|
+
4. Use in service call
|
|
150
|
+
5. Display to user
|
|
151
|
+
|
|
152
|
+
### Multiple Images
|
|
153
|
+
1. Collect all image URIs
|
|
154
|
+
2. Prepare in parallel
|
|
155
|
+
3. Validate all results
|
|
156
|
+
4. Use in batch operations
|
|
157
|
+
5. Handle partial failures
|
|
158
|
+
|
|
159
|
+
### Base64 Validation
|
|
160
|
+
1. Get base64 string
|
|
161
|
+
2. Call isValidBase64()
|
|
162
|
+
3. Check validation result
|
|
163
|
+
4. Use or reject data
|
|
164
|
+
5. Provide feedback
|
|
165
|
+
|
|
166
|
+
## 🚨 Common Pitfalls
|
|
167
|
+
|
|
168
|
+
### Don't
|
|
169
|
+
- Skip validation of prepared images
|
|
170
|
+
- Assume URI format
|
|
171
|
+
- Forget to handle errors
|
|
172
|
+
- Use unvalidated base64
|
|
173
|
+
- Block main thread with large images
|
|
174
|
+
|
|
175
|
+
### Do
|
|
176
|
+
- Always validate output
|
|
177
|
+
- Handle various URI formats
|
|
178
|
+
- Cache prepared images
|
|
179
|
+
- Handle errors gracefully
|
|
180
|
+
- Optimize for performance
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
**Last Updated**: 2025-01-08
|
|
185
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Input Builders
|
|
2
|
+
|
|
3
|
+
Helper functions for building Gemini API inputs for image and video processing features. Creates properly formatted prompts and image arrays.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
buildUpscaleInput,
|
|
10
|
+
buildPhotoRestoreInput,
|
|
11
|
+
buildRemoveBackgroundInput,
|
|
12
|
+
buildReplaceBackgroundInput,
|
|
13
|
+
buildFaceSwapInput,
|
|
14
|
+
buildSingleImageInput,
|
|
15
|
+
buildDualImageInput
|
|
16
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🎯 Purpose
|
|
20
|
+
|
|
21
|
+
Use input builders to create properly formatted inputs for image and video features. Simplifies prompt engineering and image data preparation.
|
|
22
|
+
|
|
23
|
+
**When to use:**
|
|
24
|
+
- Build inputs for image editing features
|
|
25
|
+
- Create prompts for video generation
|
|
26
|
+
- Format image data correctly
|
|
27
|
+
- Combine multiple images
|
|
28
|
+
- Simplify feature integration
|
|
29
|
+
|
|
30
|
+
## 📌 Strategy
|
|
31
|
+
|
|
32
|
+
Input builders encapsulate prompt complexity. This system:
|
|
33
|
+
- Creates optimized prompts for features
|
|
34
|
+
- Formats image data correctly
|
|
35
|
+
- Handles single and multiple images
|
|
36
|
+
- Provides consistent interface
|
|
37
|
+
- Simplifies feature usage
|
|
38
|
+
|
|
39
|
+
**Key Decision**: Always use input builders for image/video features. Ensures correct prompt engineering and data formatting.
|
|
40
|
+
|
|
41
|
+
## ⚠️ Rules
|
|
42
|
+
|
|
43
|
+
### Usage Rules
|
|
44
|
+
- **MUST** use builders for image/video features
|
|
45
|
+
- **SHOULD** provide valid base64 data
|
|
46
|
+
- **MUST** check required parameters
|
|
47
|
+
- **SHOULD** handle missing options
|
|
48
|
+
- **MUST NOT** create inputs manually
|
|
49
|
+
|
|
50
|
+
### Data Rules
|
|
51
|
+
- **MUST** provide valid base64 strings
|
|
52
|
+
- **SHOULD** validate image data
|
|
53
|
+
- **MUST** include correct MIME types
|
|
54
|
+
- **SHOULD** handle encoding errors
|
|
55
|
+
- **MUST NOT** pass invalid data
|
|
56
|
+
|
|
57
|
+
### Prompt Rules
|
|
58
|
+
- **MUST** use builder-generated prompts
|
|
59
|
+
- **SHOULD NOT** modify builder prompts
|
|
60
|
+
- **MUST** follow prompt patterns
|
|
61
|
+
- **SHOULD** test prompt effectiveness
|
|
62
|
+
- **MUST NOT** hardcode prompts
|
|
63
|
+
|
|
64
|
+
### Options Rules
|
|
65
|
+
- **SHOULD** provide appropriate options
|
|
66
|
+
- **MUST** check required parameters
|
|
67
|
+
- **SHOULD** use default values wisely
|
|
68
|
+
- **MUST** validate option values
|
|
69
|
+
- **SHOULD NOT** ignore option validation
|
|
70
|
+
|
|
71
|
+
## 🤖 AI Agent Guidelines
|
|
72
|
+
|
|
73
|
+
### When Building Inputs
|
|
74
|
+
1. **SELECT** appropriate builder function
|
|
75
|
+
2. **PROVIDE** valid base64 data
|
|
76
|
+
3. **CONFIGURE** options if needed
|
|
77
|
+
4. **USE** returned prompt and images
|
|
78
|
+
5. **HANDLE** builder errors
|
|
79
|
+
|
|
80
|
+
### When Using Image Features
|
|
81
|
+
1. **PREPARE** image base64 data
|
|
82
|
+
2. **CALL** appropriate builder
|
|
83
|
+
3. **USE** prompt from builder
|
|
84
|
+
4. **PASS** images array to service
|
|
85
|
+
5. **HANDLE** service response
|
|
86
|
+
|
|
87
|
+
### When Creating Custom Builders
|
|
88
|
+
1. **ANALYZE** existing builders
|
|
89
|
+
2. **FOLLOW** builder pattern
|
|
90
|
+
3. **CREATE** optimized prompt
|
|
91
|
+
4. **RETURN** consistent structure
|
|
92
|
+
5. **TEST** builder thoroughly
|
|
93
|
+
|
|
94
|
+
### Code Style Rules
|
|
95
|
+
- **USE** builders instead of manual input
|
|
96
|
+
- **VALIDATE** input data
|
|
97
|
+
- **HANDLE** missing options
|
|
98
|
+
- **FOLLOW** builder patterns
|
|
99
|
+
- **TEST** builder output
|
|
100
|
+
|
|
101
|
+
## 📦 Available Builders
|
|
102
|
+
|
|
103
|
+
### Single Image Builders
|
|
104
|
+
|
|
105
|
+
**Refer to**: [`image-feature-builders.util.ts`](./image-feature-builders.util.ts)
|
|
106
|
+
|
|
107
|
+
- `buildUpscaleInput(base64, options?)` - Image upscaling
|
|
108
|
+
- `buildPhotoRestoreInput(base64, options?)` - Photo restoration
|
|
109
|
+
- `buildAnimeSelfieInput(base64, options?)` - Anime style transformation
|
|
110
|
+
- `buildRemoveBackgroundInput(base64, options?)` - Background removal
|
|
111
|
+
- `buildRemoveObjectInput(base64, options?)` - Object removal
|
|
112
|
+
- `buildReplaceBackgroundInput(base64, options)` - Background replacement
|
|
113
|
+
- `buildHDTouchUpInput(base64, options?)` - HD enhancement
|
|
114
|
+
|
|
115
|
+
### Dual Image Builders
|
|
116
|
+
|
|
117
|
+
**Refer to**: [`image-feature-builders.util.ts`](./image-feature-builders.util.ts)
|
|
118
|
+
|
|
119
|
+
- `buildFaceSwapInput(sourceBase64, targetBase64, options?)` - Face swapping
|
|
120
|
+
|
|
121
|
+
### Video Builders
|
|
122
|
+
|
|
123
|
+
**Refer to**: [`video-feature-builders.util.ts`](./video-feature-builders.util.ts)
|
|
124
|
+
|
|
125
|
+
- `buildAIHugInput(base64, options?)` - AI hugging effect
|
|
126
|
+
- `buildAIKissInput(base64, options?)` - AI kissing effect
|
|
127
|
+
- `buildVideoFromDualImagesInput(base64a, base64b, options?)` - Dual image to video
|
|
128
|
+
|
|
129
|
+
### Base Builders
|
|
130
|
+
|
|
131
|
+
**Refer to**: [`base-input-builders.util.ts`](./base-input-builders.util.ts)
|
|
132
|
+
|
|
133
|
+
- `buildSingleImageInput(base64, prompt)` - Single image input
|
|
134
|
+
- `buildDualImageInput(base64a, base64b, prompt)` - Dual image input
|
|
135
|
+
|
|
136
|
+
## 🔗 Related Modules
|
|
137
|
+
|
|
138
|
+
- **Image Edit Service**: [`../services/IMAGE_EDIT_SERVICE.md`](../services/IMAGE_EDIT_SERVICE.md)
|
|
139
|
+
- **Image Preparer Utils**: [`../utils/IMAGE_PREPARER_UTILS.md`](../utils/IMAGE_PREPARER_UTILS.md)
|
|
140
|
+
- **Content Builder**: [`../content/README.md`](../content/README.md)
|
|
141
|
+
|
|
142
|
+
## 📋 Builder Return Type
|
|
143
|
+
|
|
144
|
+
All builders return:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
{
|
|
148
|
+
prompt: string;
|
|
149
|
+
images: Array<{
|
|
150
|
+
base64: string;
|
|
151
|
+
mimeType: string;
|
|
152
|
+
}>;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
This structure is compatible with `geminiImageEditService.editImage()`.
|
|
157
|
+
|
|
158
|
+
## 🎓 Usage Patterns
|
|
159
|
+
|
|
160
|
+
### Basic Feature Usage
|
|
161
|
+
1. Prepare image base64 data
|
|
162
|
+
2. Call appropriate builder function
|
|
163
|
+
3. Configure options if needed
|
|
164
|
+
4. Use returned prompt and images
|
|
165
|
+
5. Call image edit service
|
|
166
|
+
|
|
167
|
+
### Single Image Processing
|
|
168
|
+
1. Get image base64 string
|
|
169
|
+
2. Call single-image builder
|
|
170
|
+
3. Pass prompt and images to service
|
|
171
|
+
4. Handle service response
|
|
172
|
+
5. Display result
|
|
173
|
+
|
|
174
|
+
### Dual Image Processing
|
|
175
|
+
1. Get both image base64 strings
|
|
176
|
+
2. Call dual-image builder
|
|
177
|
+
3. Use returned input structure
|
|
178
|
+
4. Call appropriate service
|
|
179
|
+
5. Handle response
|
|
180
|
+
|
|
181
|
+
### Batch Processing
|
|
182
|
+
1. Prepare all images
|
|
183
|
+
2. Call builder for each image
|
|
184
|
+
3. Process inputs in sequence
|
|
185
|
+
4. Collect all results
|
|
186
|
+
5. Return batch results
|
|
187
|
+
|
|
188
|
+
### Custom Features
|
|
189
|
+
1. Analyze existing builders
|
|
190
|
+
2. Create custom builder function
|
|
191
|
+
3. Follow builder pattern
|
|
192
|
+
4. Return consistent structure
|
|
193
|
+
5. Test thoroughly
|
|
194
|
+
|
|
195
|
+
## 🚨 Common Pitfalls
|
|
196
|
+
|
|
197
|
+
### Don't
|
|
198
|
+
- Create inputs manually
|
|
199
|
+
- Modify builder prompts
|
|
200
|
+
- Skip builder functions
|
|
201
|
+
- Hardcode prompts
|
|
202
|
+
- Use invalid base64 data
|
|
203
|
+
|
|
204
|
+
### Do
|
|
205
|
+
- Always use input builders
|
|
206
|
+
- Follow builder patterns
|
|
207
|
+
- Validate input data
|
|
208
|
+
- Use builder-generated prompts
|
|
209
|
+
- Test builder output
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
**Last Updated**: 2025-01-08
|
|
214
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|