@umituz/react-native-ai-gemini-provider 1.14.28 → 1.14.30
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 +41 -3
- 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/services/gemini-provider.ts +9 -2
- 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,202 @@
|
|
|
1
|
+
# Core Client Service
|
|
2
|
+
|
|
3
|
+
Low-level communication with Google Gemini SDK. Handles model loading, configuration, and SDK management.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { geminiClientCoreService } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to initialize and configure the Gemini SDK. Manages the underlying Gemini client instance and provides access to configured models.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Initialize Gemini SDK with API key
|
|
17
|
+
- Configure default models for different features
|
|
18
|
+
- Access Gemini model instances directly
|
|
19
|
+
- Update SDK configuration at runtime
|
|
20
|
+
- Validate SDK initialization status
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Core client acts as the foundation for all Gemini operations. This service:
|
|
25
|
+
- Implements singleton pattern for single SDK instance
|
|
26
|
+
- Manages SDK lifecycle (initialization, configuration)
|
|
27
|
+
- Provides typed model instances
|
|
28
|
+
- Handles API key and endpoint configuration
|
|
29
|
+
- Validates initialization before operations
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use singleton pattern to ensure single Gemini SDK instance. All other services use this core client for model access.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** initialize before any Gemini operations
|
|
37
|
+
- **MUST** provide valid API key in configuration
|
|
38
|
+
- **SHOULD** initialize once at application startup
|
|
39
|
+
- **MUST NOT** create multiple instances (use singleton)
|
|
40
|
+
- **SHOULD** validate initialization before use
|
|
41
|
+
|
|
42
|
+
### Configuration Rules
|
|
43
|
+
- **MUST** set API key (required field)
|
|
44
|
+
- **SHOULD** configure appropriate models for features
|
|
45
|
+
- **MUST NOT** expose API keys in logs or errors
|
|
46
|
+
- **SHOULD** set reasonable retry limits
|
|
47
|
+
- **MUST** use valid model IDs
|
|
48
|
+
|
|
49
|
+
### Error Handling Rules
|
|
50
|
+
- **MUST** validate configuration before initialization
|
|
51
|
+
- **MUST** handle initialization errors appropriately
|
|
52
|
+
- **SHOULD** provide clear error messages
|
|
53
|
+
- **MUST** throw errors for invalid API keys
|
|
54
|
+
- **SHOULD** log initialization status in development
|
|
55
|
+
|
|
56
|
+
## 🤖 AI Agent Guidelines
|
|
57
|
+
|
|
58
|
+
### When Modifying This Service
|
|
59
|
+
1. **READ** the implementation file first
|
|
60
|
+
2. **UNDERSTAND** singleton pattern
|
|
61
|
+
3. **MAINTAIN** backward compatibility
|
|
62
|
+
4. **ADD** tests for new functionality
|
|
63
|
+
5. **UPDATE** type definitions
|
|
64
|
+
|
|
65
|
+
### When Adding New Features
|
|
66
|
+
1. **CHECK** if feature exists in other services
|
|
67
|
+
2. **FOLLOW** existing initialization patterns
|
|
68
|
+
3. **USE** established error handling
|
|
69
|
+
4. **DOCUMENT** in type definitions
|
|
70
|
+
5. **ADD** examples to tests (not docs)
|
|
71
|
+
|
|
72
|
+
### When Fixing Bugs
|
|
73
|
+
1. **REPRODUCE** bug locally first
|
|
74
|
+
2. **IDENTIFY** root cause
|
|
75
|
+
3. **FIX** with minimal changes
|
|
76
|
+
4. **ADD** regression test
|
|
77
|
+
5. **VERIFY** all tests pass
|
|
78
|
+
|
|
79
|
+
### Code Style Rules
|
|
80
|
+
- **USE** singleton pattern
|
|
81
|
+
- **VALIDATE** all inputs
|
|
82
|
+
- **THROW** typed errors
|
|
83
|
+
- **LOG** important operations
|
|
84
|
+
- **COMMENT** complex logic only
|
|
85
|
+
|
|
86
|
+
## 📦 Available Methods
|
|
87
|
+
|
|
88
|
+
### `initialize(config)`
|
|
89
|
+
|
|
90
|
+
Initialize Gemini client with configuration.
|
|
91
|
+
|
|
92
|
+
**Refer to**: [`gemini-client-core.service.ts`](./gemini-client-core.service.ts)
|
|
93
|
+
|
|
94
|
+
### `getModel(model)`
|
|
95
|
+
|
|
96
|
+
Get Gemini model instance by ID.
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`gemini-client-core.service.ts`](./gemini-client-core.service.ts)
|
|
99
|
+
|
|
100
|
+
### `getConfig()`
|
|
101
|
+
|
|
102
|
+
Get current configuration.
|
|
103
|
+
|
|
104
|
+
**Refer to**: [`gemini-client-core.service.ts`](./gemini-client-core.service.ts)
|
|
105
|
+
|
|
106
|
+
### `isInitialized()`
|
|
107
|
+
|
|
108
|
+
Check if service is initialized.
|
|
109
|
+
|
|
110
|
+
**Refer to**: [`gemini-client-core.service.ts`](./gemini-client-core.service.ts)
|
|
111
|
+
|
|
112
|
+
### `validateInitialization()`
|
|
113
|
+
|
|
114
|
+
Validate initialization, throw error if not initialized.
|
|
115
|
+
|
|
116
|
+
**Refer to**: [`gemini-client-core.service.ts`](./gemini-client-core.service.ts)
|
|
117
|
+
|
|
118
|
+
### `updateConfig(config)`
|
|
119
|
+
|
|
120
|
+
Update configuration at runtime.
|
|
121
|
+
|
|
122
|
+
**Refer to**: [`gemini-client-core.service.ts`](./gemini-client-core.service.ts)
|
|
123
|
+
|
|
124
|
+
## 🔗 Related Modules
|
|
125
|
+
|
|
126
|
+
- **Domain Types**: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
127
|
+
- **Text Generation**: [`TEXT_GENERATION_SERVICE.md`](./TEXT_GENERATION_SERVICE.md)
|
|
128
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
129
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
130
|
+
|
|
131
|
+
## 📋 Configuration Reference
|
|
132
|
+
|
|
133
|
+
### GeminiConfig
|
|
134
|
+
|
|
135
|
+
Configuration interface definition found in: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
136
|
+
|
|
137
|
+
**Required Fields:**
|
|
138
|
+
- `apiKey`: string - API key from Google Cloud Console
|
|
139
|
+
|
|
140
|
+
**Optional Fields:**
|
|
141
|
+
- `baseUrl`: string - Custom base URL for API requests
|
|
142
|
+
- `maxRetries`: number - Maximum retry attempts (default: 3)
|
|
143
|
+
- `baseDelay`: number - Initial retry delay in ms (default: 1000)
|
|
144
|
+
- `maxDelay`: number - Maximum retry delay in ms (default: 10000)
|
|
145
|
+
- `defaultTimeoutMs`: number - Request timeout in ms
|
|
146
|
+
- `textModel`: string - Default text generation model
|
|
147
|
+
- `textToImageModel`: string - Default image generation model
|
|
148
|
+
- `imageEditModel`: string - Default image editing model
|
|
149
|
+
- `videoGenerationModel`: string - Default video generation model
|
|
150
|
+
|
|
151
|
+
### Supported Models
|
|
152
|
+
|
|
153
|
+
See model IDs in: [`domain/constants/README.md`](../domain/constants/README.md)
|
|
154
|
+
|
|
155
|
+
## 🎓 Usage Patterns
|
|
156
|
+
|
|
157
|
+
### Basic Initialization
|
|
158
|
+
1. Import service
|
|
159
|
+
2. Call `initialize()` with API key
|
|
160
|
+
3. Verify initialization with `isInitialized()`
|
|
161
|
+
4. Use services normally
|
|
162
|
+
|
|
163
|
+
### Advanced Configuration
|
|
164
|
+
1. Prepare configuration object with all settings
|
|
165
|
+
2. Include model IDs for each feature
|
|
166
|
+
3. Set retry and timeout parameters
|
|
167
|
+
4. Call `initialize()` with configuration
|
|
168
|
+
5. Validate initialization succeeded
|
|
169
|
+
|
|
170
|
+
### Runtime Configuration Updates
|
|
171
|
+
1. Check current configuration with `getConfig()`
|
|
172
|
+
2. Prepare partial config update
|
|
173
|
+
3. Call `updateConfig()` with new values
|
|
174
|
+
4. Verify changes applied
|
|
175
|
+
|
|
176
|
+
### Direct Model Access
|
|
177
|
+
1. Ensure service is initialized
|
|
178
|
+
2. Call `getModel()` with model ID
|
|
179
|
+
3. Use returned model instance directly
|
|
180
|
+
4. Handle model errors appropriately
|
|
181
|
+
|
|
182
|
+
## 🚨 Common Pitfalls
|
|
183
|
+
|
|
184
|
+
### Don't
|
|
185
|
+
- Initialize multiple times
|
|
186
|
+
- Create new instances (use singleton)
|
|
187
|
+
- Skip initialization validation
|
|
188
|
+
- Expose API keys in logs
|
|
189
|
+
- Use uninitialized service
|
|
190
|
+
|
|
191
|
+
### Do
|
|
192
|
+
- Initialize once at app startup
|
|
193
|
+
- Use singleton instance
|
|
194
|
+
- Validate before use
|
|
195
|
+
- Handle initialization errors
|
|
196
|
+
- Set appropriate model IDs
|
|
197
|
+
- Configure reasonable timeouts
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
**Last Updated**: 2025-01-08
|
|
202
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Feature Model Selector Service
|
|
2
|
+
|
|
3
|
+
Selects appropriate Gemini models based on feature type. Supports runtime model overrides for flexibility.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { featureModelSelector } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to select the correct AI model for specific features. Provides default model mappings and supports runtime overrides.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Select models for image/video features
|
|
17
|
+
- Override models for testing or optimization
|
|
18
|
+
- A/B test different models
|
|
19
|
+
- Implement feature-based model selection
|
|
20
|
+
- Configure models based on user preferences
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Different AI features require specialized models. This service:
|
|
25
|
+
- Maps features to appropriate default models
|
|
26
|
+
- Supports runtime model overrides
|
|
27
|
+
- Provides type-safe model selection
|
|
28
|
+
- Maintains feature-to-model relationships
|
|
29
|
+
- Enables flexible model configuration
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use feature-based model selection instead of hardcoding model IDs. This allows easy model updates and testing without code changes.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** use valid feature types (ImageFeatureType | VideoFeatureType)
|
|
37
|
+
- **SHOULD** check for existing overrides before setting new ones
|
|
38
|
+
- **MUST** clear overrides after temporary usage
|
|
39
|
+
- **SHOULD** use type-safe feature names
|
|
40
|
+
- **MUST NOT** use string literals for feature names
|
|
41
|
+
|
|
42
|
+
### Override Rules
|
|
43
|
+
- **SHOULD** use overrides sparingly
|
|
44
|
+
- **MUST** clean up overrides when done
|
|
45
|
+
- **SHOULD** check if override already exists
|
|
46
|
+
- **MUST NOT** set permanent overrides app-wide
|
|
47
|
+
- **SHOULD** restore original state after temporary overrides
|
|
48
|
+
|
|
49
|
+
### Configuration Rules
|
|
50
|
+
- **MUST** use valid model IDs
|
|
51
|
+
- **SHOULD** validate model IDs before use
|
|
52
|
+
- **MUST** handle model errors appropriately
|
|
53
|
+
- **SHOULD** log override operations in development
|
|
54
|
+
- **MUST NOT** override with invalid model IDs
|
|
55
|
+
|
|
56
|
+
## 🤖 AI Agent Guidelines
|
|
57
|
+
|
|
58
|
+
### When Modifying This Service
|
|
59
|
+
1. **READ** the implementation file first
|
|
60
|
+
2. **UNDERSTAND** feature-to-model mapping
|
|
61
|
+
3. **MAINTAIN** backward compatibility
|
|
62
|
+
4. **ADD** tests for new functionality
|
|
63
|
+
5. **UPDATE** type definitions
|
|
64
|
+
|
|
65
|
+
### When Adding New Features
|
|
66
|
+
1. **CHECK** if feature type already exists
|
|
67
|
+
2. **FOLLOW** existing patterns
|
|
68
|
+
3. **UPDATE** feature constants
|
|
69
|
+
4. **DOCUMENT** in type definitions
|
|
70
|
+
5. **ADD** examples to tests (not docs)
|
|
71
|
+
|
|
72
|
+
### When Fixing Bugs
|
|
73
|
+
1. **REPRODUCE** bug locally first
|
|
74
|
+
2. **IDENTIFY** root cause
|
|
75
|
+
3. **FIX** with minimal changes
|
|
76
|
+
4. **ADD** regression test
|
|
77
|
+
5. **VERIFY** all tests pass
|
|
78
|
+
|
|
79
|
+
### Code Style Rules
|
|
80
|
+
- **USE** type-safe feature names
|
|
81
|
+
- **VALIDATE** model IDs
|
|
82
|
+
- **LOG** override operations in development
|
|
83
|
+
- **THROW** typed errors for invalid inputs
|
|
84
|
+
- **COMMENT** complex logic only
|
|
85
|
+
|
|
86
|
+
## 📦 Available Methods
|
|
87
|
+
|
|
88
|
+
### `setModelOverride(feature, model)`
|
|
89
|
+
|
|
90
|
+
Set a custom model override for a specific feature.
|
|
91
|
+
|
|
92
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
93
|
+
|
|
94
|
+
### `clearOverrides()`
|
|
95
|
+
|
|
96
|
+
Clear all model overrides and revert to default models.
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
99
|
+
|
|
100
|
+
### `getImageFeatureModel(feature)`
|
|
101
|
+
|
|
102
|
+
Get the model ID for an image feature.
|
|
103
|
+
|
|
104
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
105
|
+
|
|
106
|
+
### `getVideoFeatureModel(feature)`
|
|
107
|
+
|
|
108
|
+
Get the model ID for a video feature.
|
|
109
|
+
|
|
110
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
111
|
+
|
|
112
|
+
### `hasOverride(feature)`
|
|
113
|
+
|
|
114
|
+
Check if a feature has a custom override set.
|
|
115
|
+
|
|
116
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
117
|
+
|
|
118
|
+
## 🔗 Related Modules
|
|
119
|
+
|
|
120
|
+
- **Feature Constants**: [`domain/constants/feature-models.constants.ts`](../domain/constants/feature-models.constants.ts)
|
|
121
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
122
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
123
|
+
|
|
124
|
+
## 📋 Configuration Reference
|
|
125
|
+
|
|
126
|
+
### Supported Image Features
|
|
127
|
+
|
|
128
|
+
- `image-generation` - Text-to-image generation
|
|
129
|
+
- `image-edit` - Image editing and transformation
|
|
130
|
+
- `upscale` - Image upscaling
|
|
131
|
+
- `face-swap` - Face replacement
|
|
132
|
+
- `remove-background` - Background removal
|
|
133
|
+
- `inpainting` - Image inpainting
|
|
134
|
+
- `outpainting` - Image outpainting
|
|
135
|
+
|
|
136
|
+
### Supported Video Features
|
|
137
|
+
|
|
138
|
+
- `video-generation` - Text-to-video generation
|
|
139
|
+
- `video-preview` - Video preview generation
|
|
140
|
+
|
|
141
|
+
### Default Models
|
|
142
|
+
|
|
143
|
+
**Image Features:**
|
|
144
|
+
- `image-generation`: `imagen-3.0-generate-001`
|
|
145
|
+
- `image-edit`: `imagen-3.0-generate-001`
|
|
146
|
+
- `upscale`: `imagen-3.0-capabilities-001`
|
|
147
|
+
- Other features: `imagen-3.0-capabilities-001`
|
|
148
|
+
|
|
149
|
+
**Video Features:**
|
|
150
|
+
- `video-generation`: `veo-3.1-generate-001`
|
|
151
|
+
- `video-preview`: `veo-3.1-fast-generate-preview`
|
|
152
|
+
|
|
153
|
+
## 🎓 Usage Patterns
|
|
154
|
+
|
|
155
|
+
### Basic Model Selection
|
|
156
|
+
1. Import service
|
|
157
|
+
2. Call `getImageFeatureModel()` or `getVideoFeatureModel()` with feature type
|
|
158
|
+
3. Use returned model ID with generation service
|
|
159
|
+
4. Generate content with selected model
|
|
160
|
+
|
|
161
|
+
### Runtime Model Override
|
|
162
|
+
1. Call `setModelOverride()` with feature and custom model
|
|
163
|
+
2. Use feature services normally
|
|
164
|
+
3. All requests now use custom model
|
|
165
|
+
4. Clear override when done
|
|
166
|
+
|
|
167
|
+
### Temporary Override with Cleanup
|
|
168
|
+
1. Save current overrides state
|
|
169
|
+
2. Set temporary override
|
|
170
|
+
3. Execute operation with custom model
|
|
171
|
+
4. Restore original state in finally block
|
|
172
|
+
|
|
173
|
+
### Feature-Based Model Selection
|
|
174
|
+
1. Determine feature type from request
|
|
175
|
+
2. Call appropriate getter method (image vs video)
|
|
176
|
+
3. Receive model ID for feature
|
|
177
|
+
4. Execute generation with selected model
|
|
178
|
+
|
|
179
|
+
### A/B Testing Different Models
|
|
180
|
+
1. Define array of models to test
|
|
181
|
+
2. Loop through models
|
|
182
|
+
3. Set override for each model
|
|
183
|
+
4. Generate content and track results
|
|
184
|
+
5. Clear overrides after testing
|
|
185
|
+
|
|
186
|
+
## 🚨 Common Pitfalls
|
|
187
|
+
|
|
188
|
+
### Don't
|
|
189
|
+
- Set permanent overrides app-wide
|
|
190
|
+
- Forget to clear overrides after use
|
|
191
|
+
- Use string literals for feature names
|
|
192
|
+
- Override without checking existing state
|
|
193
|
+
- Use invalid model IDs
|
|
194
|
+
|
|
195
|
+
### Do
|
|
196
|
+
- Clean up overrides in finally blocks
|
|
197
|
+
- Check for existing overrides before setting
|
|
198
|
+
- Use type-safe feature names
|
|
199
|
+
- Validate model IDs before use
|
|
200
|
+
- Test with different models for optimization
|
|
201
|
+
- Log override operations in development
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
**Last Updated**: 2025-01-08
|
|
206
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Generation Executor Service
|
|
2
|
+
|
|
3
|
+
Service for executing different types of AI generation tasks. Handles text, image, and video generation with a unified interface.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { generationExecutor } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use generation executor to execute AI generation tasks with a unified interface. Automatically detects generation type and routes to appropriate service.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Execute text, image, or video generation
|
|
17
|
+
- Use unified generation interface
|
|
18
|
+
- Handle multiple generation types
|
|
19
|
+
- Simplify service integration
|
|
20
|
+
- Abstract generation complexity
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Unified interface simplifies integration. This service:
|
|
25
|
+
- Detects generation type automatically
|
|
26
|
+
- Routes to appropriate service
|
|
27
|
+
- Provides consistent interface
|
|
28
|
+
- Handles response formatting
|
|
29
|
+
- Simplifies error handling
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use executor for generic generation needs. Use specific services for direct control.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** specify generation type in input
|
|
37
|
+
- **SHOULD** use executor for generic operations
|
|
38
|
+
- **MUST** handle typed responses correctly
|
|
39
|
+
- **SHOULD** validate input parameters
|
|
40
|
+
- **MUST NOT** mix generation types
|
|
41
|
+
|
|
42
|
+
### Type Detection Rules
|
|
43
|
+
- **MUST** specify input type explicitly
|
|
44
|
+
- **SHOULD** use appropriate input structure
|
|
45
|
+
- **MUST** match type to service
|
|
46
|
+
- **SHOULD** validate type compatibility
|
|
47
|
+
- **MUST NOT** rely on implicit detection
|
|
48
|
+
|
|
49
|
+
### Response Rules
|
|
50
|
+
- **MUST** handle response types correctly
|
|
51
|
+
- **SHOULD** validate response structure
|
|
52
|
+
- **MUST** check for errors
|
|
53
|
+
- **SHOULD** parse responses appropriately
|
|
54
|
+
- **MUST NOT** assume response format
|
|
55
|
+
|
|
56
|
+
### Error Handling Rules
|
|
57
|
+
- **MUST** catch generation errors
|
|
58
|
+
- **SHOULD** provide meaningful error messages
|
|
59
|
+
- **MUST** handle service-specific errors
|
|
60
|
+
- **SHOULD** log errors appropriately
|
|
61
|
+
- **MUST NOT** suppress errors
|
|
62
|
+
|
|
63
|
+
## 🤖 AI Agent Guidelines
|
|
64
|
+
|
|
65
|
+
### When Executing Generations
|
|
66
|
+
1. **DETERMINE** generation type
|
|
67
|
+
2. **PREPARE** input structure
|
|
68
|
+
3. **CALL** executeGeneration()
|
|
69
|
+
4. **HANDLE** typed response
|
|
70
|
+
5. **PROCESS** result appropriately
|
|
71
|
+
|
|
72
|
+
### When Using Typed Generations
|
|
73
|
+
1. **SPECIFY** type parameter
|
|
74
|
+
2. **PROVIDE** correct input
|
|
75
|
+
3. **CAST** response appropriately
|
|
76
|
+
4. **VALIDATE** response type
|
|
77
|
+
5. **USE** result safely
|
|
78
|
+
|
|
79
|
+
### When Handling Errors
|
|
80
|
+
1. **WRAP** execution in try-catch
|
|
81
|
+
2. **CHECK** error type
|
|
82
|
+
3. **HANDLE** service-specific errors
|
|
83
|
+
4. **PROVIDE** fallback behavior
|
|
84
|
+
5. **LOG** error details
|
|
85
|
+
|
|
86
|
+
### Code Style Rules
|
|
87
|
+
- **SPECIFY** generation type explicitly
|
|
88
|
+
- **USE** type parameters correctly
|
|
89
|
+
- **HANDLE** all error cases
|
|
90
|
+
- **VALIDATE** input structure
|
|
91
|
+
- **DOCUMENT** generation usage
|
|
92
|
+
|
|
93
|
+
## 📦 Available Service
|
|
94
|
+
|
|
95
|
+
### generationExecutor
|
|
96
|
+
|
|
97
|
+
**Refer to**: [`generation-executor.ts`](./generation-executor.ts)
|
|
98
|
+
|
|
99
|
+
**Methods:**
|
|
100
|
+
- `executeGeneration<T>(model, input, options?)` - Execute generation task
|
|
101
|
+
- `generateWithImages(model, prompt, images)` - Generate with image context
|
|
102
|
+
|
|
103
|
+
## 🔗 Related Modules
|
|
104
|
+
|
|
105
|
+
- **Text Generation**: [`TEXT_GENERATION_SERVICE.md`](./TEXT_GENERATION_SERVICE.md)
|
|
106
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
107
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
108
|
+
- **Job Processor**: [`JOB_PROCESSOR_SERVICE.md`](./JOB_PROCESSOR_SERVICE.md)
|
|
109
|
+
|
|
110
|
+
## 📋 Generation Types
|
|
111
|
+
|
|
112
|
+
### Text Generation
|
|
113
|
+
- Type: `text`
|
|
114
|
+
- Input: `{ type: 'text', prompt: string }`
|
|
115
|
+
- Returns: `{ text: string; response: unknown }`
|
|
116
|
+
|
|
117
|
+
### Image Generation
|
|
118
|
+
- Type: `image`
|
|
119
|
+
- Input: `{ type: 'image', prompt: string }`
|
|
120
|
+
- Returns: `{ imageUrl: string; response: unknown }`
|
|
121
|
+
|
|
122
|
+
### Video Generation
|
|
123
|
+
- Type: `video`
|
|
124
|
+
- Input: `{ type: 'video', prompt: string }`
|
|
125
|
+
- Returns: `{ videoUrl: string; response: unknown }`
|
|
126
|
+
|
|
127
|
+
## 🎓 Usage Patterns
|
|
128
|
+
|
|
129
|
+
### Basic Generation
|
|
130
|
+
1. Determine generation type
|
|
131
|
+
2. Prepare input structure
|
|
132
|
+
3. Call executeGeneration()
|
|
133
|
+
4. Get typed response
|
|
134
|
+
5. Use result
|
|
135
|
+
|
|
136
|
+
### Typed Generation
|
|
137
|
+
1. Specify type parameter
|
|
138
|
+
2. Provide correct input
|
|
139
|
+
3. Execute generation
|
|
140
|
+
4. Validate response type
|
|
141
|
+
5. Use result safely
|
|
142
|
+
|
|
143
|
+
### Image Context Generation
|
|
144
|
+
1. Call generateWithImages()
|
|
145
|
+
2. Provide prompt and images
|
|
146
|
+
3. Get text response
|
|
147
|
+
4. Handle multimodal result
|
|
148
|
+
5. Process response
|
|
149
|
+
|
|
150
|
+
### Error Handling
|
|
151
|
+
1. Wrap execution in try-catch
|
|
152
|
+
2. Check error type
|
|
153
|
+
3. Handle specific errors
|
|
154
|
+
4. Provide fallback
|
|
155
|
+
5. Log errors
|
|
156
|
+
|
|
157
|
+
## 🚨 Common Pitfalls
|
|
158
|
+
|
|
159
|
+
### Don't
|
|
160
|
+
- Skip type specification
|
|
161
|
+
- Mix generation types
|
|
162
|
+
- Assume response format
|
|
163
|
+
- Suppress errors
|
|
164
|
+
- Use wrong input structure
|
|
165
|
+
|
|
166
|
+
### Do
|
|
167
|
+
- Always specify type
|
|
168
|
+
- Use correct input structure
|
|
169
|
+
- Handle all error cases
|
|
170
|
+
- Validate responses
|
|
171
|
+
- Use type parameters correctly
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
**Last Updated**: 2025-01-08
|
|
176
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|