@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,169 @@
|
|
|
1
|
+
# Image Edit Service
|
|
2
|
+
|
|
3
|
+
Edits and transforms images using Gemini API. Supports background removal, object removal, face swap, and image enhancements.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { geminiImageEditService } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to edit and transform existing images with AI. Supports background removal, object deletion, style transfer, image enhancement, and various image manipulation operations.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Remove or replace image backgrounds
|
|
17
|
+
- Remove unwanted objects from images
|
|
18
|
+
- Enhance image quality (upscale, denoise, restore)
|
|
19
|
+
- Apply style transformations (anime, artistic styles)
|
|
20
|
+
- Face swapping and image compositing
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Image editing requires both visual and textual understanding. This service:
|
|
25
|
+
- Uses multimodal models (gemini-2.5-flash-image)
|
|
26
|
+
- Accepts base64-encoded images as input
|
|
27
|
+
- Returns edited images with text descriptions
|
|
28
|
+
- Supports both single and multiple image inputs
|
|
29
|
+
- Handles image-specific response formats
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Image editing uses TEXT + IMAGE response modalities. The service returns both edited image data and explanatory text when applicable.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** initialize provider with API key before use
|
|
37
|
+
- **MUST** provide base64-encoded images
|
|
38
|
+
- **SHOULD** use specific, clear prompts
|
|
39
|
+
- **MUST NOT** exceed image size limits
|
|
40
|
+
- **MUST** handle image editing errors appropriately
|
|
41
|
+
|
|
42
|
+
### Prompt Rules
|
|
43
|
+
- **SHOULD** clearly describe desired edit
|
|
44
|
+
- **MUST** specify what to keep vs remove
|
|
45
|
+
- **SHOULD** include fill instructions for removals
|
|
46
|
+
- **MUST NOT** request prohibited content
|
|
47
|
+
|
|
48
|
+
### Configuration Rules
|
|
49
|
+
- **MUST** use valid model IDs (gemini-2.5-flash-image)
|
|
50
|
+
- **SHOULD** optimize image size before sending
|
|
51
|
+
- **MUST** respect content safety guidelines
|
|
52
|
+
- **SHOULD** implement retry logic for failures
|
|
53
|
+
|
|
54
|
+
### Error Handling Rules
|
|
55
|
+
- **MUST** catch and handle `GeminiError`
|
|
56
|
+
- **MUST** provide user-friendly error messages
|
|
57
|
+
- **SHOULD** log errors for debugging
|
|
58
|
+
- **MUST NOT** expose API keys in errors
|
|
59
|
+
|
|
60
|
+
## 🤖 AI Agent Guidelines
|
|
61
|
+
|
|
62
|
+
### When Modifying This Service
|
|
63
|
+
1. **READ** the implementation file first
|
|
64
|
+
2. **UNDERSTAND** multimodal response format
|
|
65
|
+
3. **MAINTAIN** backward compatibility
|
|
66
|
+
4. **ADD** tests for new functionality
|
|
67
|
+
5. **UPDATE** type definitions
|
|
68
|
+
|
|
69
|
+
### When Adding New Features
|
|
70
|
+
1. **CHECK** if similar feature exists in image services
|
|
71
|
+
2. **FOLLOW** existing patterns
|
|
72
|
+
3. **USE** established error handling
|
|
73
|
+
4. **DOCUMENT** in type definitions
|
|
74
|
+
5. **ADD** examples to tests (not docs)
|
|
75
|
+
|
|
76
|
+
### When Fixing Bugs
|
|
77
|
+
1. **REPRODUCE** bug locally first
|
|
78
|
+
2. **IDENTIFY** root cause
|
|
79
|
+
3. **FIX** with minimal changes
|
|
80
|
+
4. **ADD** regression test
|
|
81
|
+
5. **VERIFY** all tests pass
|
|
82
|
+
|
|
83
|
+
### Code Style Rules
|
|
84
|
+
- **USE** async/await (no callbacks)
|
|
85
|
+
- **VALIDATE** inputs at function entry
|
|
86
|
+
- **THROW** typed errors (`GeminiError`)
|
|
87
|
+
- **LOG** important operations
|
|
88
|
+
- **COMMENT** complex logic only
|
|
89
|
+
|
|
90
|
+
## 📦 Available Methods
|
|
91
|
+
|
|
92
|
+
### `editImage(prompt, images)`
|
|
93
|
+
|
|
94
|
+
Edit images with text instructions.
|
|
95
|
+
|
|
96
|
+
**Refer to**: [`gemini-image-edit.service.ts`](./gemini-image-edit.service.ts)
|
|
97
|
+
|
|
98
|
+
## 🔗 Related Modules
|
|
99
|
+
|
|
100
|
+
- **Domain Types**: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
101
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
102
|
+
- **Core Client**: [`CORE_CLIENT_SERVICE.md`](./CORE_CLIENT_SERVICE.md)
|
|
103
|
+
- **Image Preparers**: [`IMAGE_PREPARER_UTILS.md`](../infrastructure/utils/IMAGE_PREPARER_UTILS.md)
|
|
104
|
+
|
|
105
|
+
## 📋 Configuration Reference
|
|
106
|
+
|
|
107
|
+
### Generation Config
|
|
108
|
+
See: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
109
|
+
|
|
110
|
+
### Model Selection
|
|
111
|
+
- Current model: `gemini-2.5-flash-image`
|
|
112
|
+
- Response modalities: TEXT + IMAGE
|
|
113
|
+
- Output format: PNG (typically)
|
|
114
|
+
|
|
115
|
+
### Error Types
|
|
116
|
+
See: [`ERROR_UTILITIES.md`](../infrastructure/utils/ERROR_UTILITIES.md)
|
|
117
|
+
|
|
118
|
+
## 🎓 Usage Patterns
|
|
119
|
+
|
|
120
|
+
### Background Removal
|
|
121
|
+
1. Import service
|
|
122
|
+
2. Prepare base64-encoded image
|
|
123
|
+
3. Call `editImage()` with removal prompt
|
|
124
|
+
4. Handle response (contains `imageUrl`, `imageBase64`)
|
|
125
|
+
5. Display or save edited image
|
|
126
|
+
|
|
127
|
+
### Object Removal
|
|
128
|
+
1. Import service
|
|
129
|
+
2. Prepare base64-encoded image
|
|
130
|
+
3. Create prompt describing object to remove and fill instructions
|
|
131
|
+
4. Call `editImage()` with prompt and image
|
|
132
|
+
5. Handle result showing edited image
|
|
133
|
+
|
|
134
|
+
### Background Replacement
|
|
135
|
+
1. Import service
|
|
136
|
+
2. Prepare base64-encoded image
|
|
137
|
+
3. Create prompt describing new background
|
|
138
|
+
4. Specify to keep main subject
|
|
139
|
+
5. Call `editImage()` with detailed prompt
|
|
140
|
+
6. Handle response
|
|
141
|
+
|
|
142
|
+
### Image Enhancement
|
|
143
|
+
1. Import service
|
|
144
|
+
2. Prepare base64-encoded image
|
|
145
|
+
3. Create enhancement prompt (brightness, contrast, etc.)
|
|
146
|
+
4. Call `editImage()` with prompt and image
|
|
147
|
+
5. Handle enhanced result
|
|
148
|
+
|
|
149
|
+
## 🚨 Common Pitfalls
|
|
150
|
+
|
|
151
|
+
### Don't
|
|
152
|
+
- Use vague prompts ("remove this")
|
|
153
|
+
- Forget to specify fill instructions
|
|
154
|
+
- Send extremely large images
|
|
155
|
+
- Expect perfect results on complex edits
|
|
156
|
+
- Ignore safety filters
|
|
157
|
+
|
|
158
|
+
### Do
|
|
159
|
+
- Be specific about what to edit
|
|
160
|
+
- Describe how to fill removed areas
|
|
161
|
+
- Optimize image size before sending
|
|
162
|
+
- Handle multimodal responses (text + image)
|
|
163
|
+
- Implement retry logic
|
|
164
|
+
- Test with various image types
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
**Last Updated**: 2025-01-08
|
|
169
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Image Generation Service
|
|
2
|
+
|
|
3
|
+
Generates images from text prompts using Google Imagen API.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { geminiImageGenerationService } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to generate AI-powered images from text descriptions. Supports creating photorealistic images, artistic renderings, and various visual styles using Imagen 4.0 model.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Generate images from text descriptions
|
|
17
|
+
- Create visual content for applications
|
|
18
|
+
- Generate artistic or photorealistic imagery
|
|
19
|
+
- Product visualization and concept art
|
|
20
|
+
|
|
21
|
+
## 📌 Strategy
|
|
22
|
+
|
|
23
|
+
Image generation requires specialized handling compared to text generation. This service:
|
|
24
|
+
- Uses Imagen 4.0 model specifically for images
|
|
25
|
+
- Returns base64-encoded image data
|
|
26
|
+
- Handles image-specific response formats
|
|
27
|
+
- Integrates with retry logic for reliability
|
|
28
|
+
- Validates prompt content for safety
|
|
29
|
+
|
|
30
|
+
**Key Decision**: Images are returned as base64 data URLs for React Native compatibility. Use `imageBase64` for raw data or `imageUrl` for React Native Image component.
|
|
31
|
+
|
|
32
|
+
## ⚠️ Rules
|
|
33
|
+
|
|
34
|
+
### Usage Rules
|
|
35
|
+
- **MUST** initialize provider with API key before use
|
|
36
|
+
- **MUST** handle image data appropriately (display or save)
|
|
37
|
+
- **MUST NOT** exceed API rate limits
|
|
38
|
+
- **SHOULD** provide detailed prompts for better results
|
|
39
|
+
- **MUST** handle image generation errors appropriately
|
|
40
|
+
|
|
41
|
+
### Prompt Rules
|
|
42
|
+
- **SHOULD** be descriptive and specific
|
|
43
|
+
- **SHOULD** include style and lighting information
|
|
44
|
+
- **MUST NOT** include prohibited content
|
|
45
|
+
- **SHOULD** follow prompt templates for consistency
|
|
46
|
+
|
|
47
|
+
### Configuration Rules
|
|
48
|
+
- **MUST** use valid model IDs
|
|
49
|
+
- **SHOULD** configure aspect ratio appropriately (currently 1:1 only)
|
|
50
|
+
- **MUST** respect content safety guidelines
|
|
51
|
+
- **SHOULD** implement retry logic for failures
|
|
52
|
+
|
|
53
|
+
### Error Handling Rules
|
|
54
|
+
- **MUST** catch and handle `GeminiError`
|
|
55
|
+
- **MUST** provide user-friendly error messages
|
|
56
|
+
- **SHOULD** log errors for debugging
|
|
57
|
+
- **MUST NOT** expose API keys in errors
|
|
58
|
+
|
|
59
|
+
## 🤖 AI Agent Guidelines
|
|
60
|
+
|
|
61
|
+
### When Modifying This Service
|
|
62
|
+
1. **READ** the implementation file first
|
|
63
|
+
2. **UNDERSTAND** image response format
|
|
64
|
+
3. **MAINTAIN** backward compatibility
|
|
65
|
+
4. **ADD** tests for new functionality
|
|
66
|
+
5. **UPDATE** type definitions
|
|
67
|
+
|
|
68
|
+
### When Adding New Features
|
|
69
|
+
1. **CHECK** if similar feature exists in image services
|
|
70
|
+
2. **FOLLOW** existing patterns
|
|
71
|
+
3. **USE** established error handling
|
|
72
|
+
4. **DOCUMENT** in type definitions
|
|
73
|
+
5. **ADD** examples to tests (not docs)
|
|
74
|
+
|
|
75
|
+
### When Fixing Bugs
|
|
76
|
+
1. **REPRODUCE** bug locally first
|
|
77
|
+
2. **IDENTIFY** root cause
|
|
78
|
+
3. **FIX** with minimal changes
|
|
79
|
+
4. **ADD** regression test
|
|
80
|
+
5. **VERIFY** all tests pass
|
|
81
|
+
|
|
82
|
+
### Code Style Rules
|
|
83
|
+
- **USE** async/await (no callbacks)
|
|
84
|
+
- **VALIDATE** inputs at function entry
|
|
85
|
+
- **THROW** typed errors (`GeminiError`)
|
|
86
|
+
- **LOG** important operations
|
|
87
|
+
- **COMMENT** complex logic only
|
|
88
|
+
|
|
89
|
+
## 📦 Available Methods
|
|
90
|
+
|
|
91
|
+
### `generateImage(prompt, images?, config?)`
|
|
92
|
+
|
|
93
|
+
Generate an image from text prompt.
|
|
94
|
+
|
|
95
|
+
**Refer to**: [`gemini-image-generation.service.ts`](./gemini-image-generation.service.ts)
|
|
96
|
+
|
|
97
|
+
## 🔗 Related Modules
|
|
98
|
+
|
|
99
|
+
- **Domain Types**: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
100
|
+
- **Image Edit Service**: [`IMAGE_EDIT_SERVICE.md`](./IMAGE_EDIT_SERVICE.md)
|
|
101
|
+
- **Core Client**: [`CORE_CLIENT_SERVICE.md`](./CORE_CLIENT_SERVICE.md)
|
|
102
|
+
- **Retry Service**: [`RETRY_SERVICE.md`](./RETRY_SERVICE.md)
|
|
103
|
+
|
|
104
|
+
## 📋 Configuration Reference
|
|
105
|
+
|
|
106
|
+
### Generation Config
|
|
107
|
+
See: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
108
|
+
|
|
109
|
+
### Model Selection
|
|
110
|
+
- Current model: `imagen-4.0-generate-001`
|
|
111
|
+
- Aspect ratio: 1:1 (only supported ratio)
|
|
112
|
+
- Format: `image/png`
|
|
113
|
+
- Encoding: Base64
|
|
114
|
+
|
|
115
|
+
### Error Types
|
|
116
|
+
See: [`ERROR_UTILITIES.md`](../infrastructure/utils/ERROR_UTILITIES.md)
|
|
117
|
+
|
|
118
|
+
## 🎓 Usage Patterns
|
|
119
|
+
|
|
120
|
+
### Basic Image Generation
|
|
121
|
+
1. Import service
|
|
122
|
+
2. Call `generateImage()` with descriptive prompt
|
|
123
|
+
3. Handle response (contains `imageUrl`, `imageBase64`, `mimeType`)
|
|
124
|
+
4. Display image in React Native Image component
|
|
125
|
+
5. Handle errors appropriately
|
|
126
|
+
|
|
127
|
+
### With Retry Logic
|
|
128
|
+
1. Wrap call in retry mechanism
|
|
129
|
+
2. Configure max retries and delays
|
|
130
|
+
3. Handle retryable errors (network, rate limits)
|
|
131
|
+
4. Provide feedback to user during retries
|
|
132
|
+
|
|
133
|
+
### Saving Generated Images
|
|
134
|
+
1. Generate image using service
|
|
135
|
+
2. Extract `imageBase64` from result
|
|
136
|
+
3. Save to filesystem using React Native FS
|
|
137
|
+
4. Handle file system errors
|
|
138
|
+
|
|
139
|
+
### Uploading Generated Images
|
|
140
|
+
1. Generate image using service
|
|
141
|
+
2. Extract base64 data
|
|
142
|
+
3. Convert to appropriate format
|
|
143
|
+
4. Upload to server/storage
|
|
144
|
+
5. Handle upload errors
|
|
145
|
+
|
|
146
|
+
## 🚨 Common Pitfalls
|
|
147
|
+
|
|
148
|
+
### Don't
|
|
149
|
+
- Use vague or generic prompts
|
|
150
|
+
- Ignore error handling
|
|
151
|
+
- Assume immediate results (generation takes time)
|
|
152
|
+
- Exceed rate limits
|
|
153
|
+
- Try to edit images with this service (use IMAGE_EDIT_SERVICE)
|
|
154
|
+
|
|
155
|
+
### Do
|
|
156
|
+
- Provide detailed, specific prompts
|
|
157
|
+
- Include style and lighting information
|
|
158
|
+
- Handle all error types
|
|
159
|
+
- Implement loading states
|
|
160
|
+
- Use image edit service for modifications
|
|
161
|
+
- Cache generated images appropriately
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
**Last Updated**: 2025-01-08
|
|
166
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Job Processor Service
|
|
2
|
+
|
|
3
|
+
Service for handling asynchronous AI generation jobs. Manages job submission, status tracking, and result retrieval with automatic async processing.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { jobProcessor } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use job processor to handle long-running AI operations asynchronously. Submit jobs, track status, and retrieve results when ready.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Process long-running operations
|
|
17
|
+
- Track job status over time
|
|
18
|
+
- Implement async job management
|
|
19
|
+
- Handle video generation
|
|
20
|
+
- Manage background processing
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Async processing improves UX. This service:
|
|
25
|
+
- Manages job lifecycle
|
|
26
|
+
- Tracks status changes
|
|
27
|
+
- Stores results for retrieval
|
|
28
|
+
- Handles polling automatically
|
|
29
|
+
- Provides job management
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use job processor for operations taking > 30 seconds. Poll for status instead of blocking.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Job Submission Rules
|
|
36
|
+
- **MUST** save request ID after submission
|
|
37
|
+
- **SHOULD** validate input before submission
|
|
38
|
+
- **MUST** handle submission errors
|
|
39
|
+
- **SHOULD** track submitted jobs
|
|
40
|
+
- **MUST NOT** lose request IDs
|
|
41
|
+
|
|
42
|
+
### Status Tracking Rules
|
|
43
|
+
- **MUST** poll status periodically
|
|
44
|
+
- **SHOULD** implement exponential backoff
|
|
45
|
+
- **MUST** handle status changes
|
|
46
|
+
- **SHOULD** monitor job progress
|
|
47
|
+
- **MUST NOT** poll too frequently
|
|
48
|
+
|
|
49
|
+
### Result Retrieval Rules
|
|
50
|
+
- **SHOULD** verify job completion
|
|
51
|
+
- **MUST** handle retrieval errors
|
|
52
|
+
- **SHOULD** validate result format
|
|
53
|
+
- **MUST** clear old results
|
|
54
|
+
- **SHOULD NOT** retrieve incomplete jobs
|
|
55
|
+
|
|
56
|
+
### Cleanup Rules
|
|
57
|
+
- **SHOULD** clear completed jobs
|
|
58
|
+
- **MUST** handle cleanup errors
|
|
59
|
+
- **SHOULD** implement job expiration
|
|
60
|
+
- **MUST** manage memory usage
|
|
61
|
+
- **SHOULD NOT** accumulate old jobs
|
|
62
|
+
|
|
63
|
+
## 🤖 AI Agent Guidelines
|
|
64
|
+
|
|
65
|
+
### When Submitting Jobs
|
|
66
|
+
1. **VALIDATE** input parameters
|
|
67
|
+
2. **CALL** submitJob()
|
|
68
|
+
3. **SAVE** request ID
|
|
69
|
+
4. **TRACK** job status
|
|
70
|
+
5. **HANDLE** submission errors
|
|
71
|
+
|
|
72
|
+
### When Tracking Status
|
|
73
|
+
1. **POLL** getJobStatus() periodically
|
|
74
|
+
2. **IMPLEMENT** exponential backoff
|
|
75
|
+
3. **CHECK** status changes
|
|
76
|
+
4. **UPDATE** UI accordingly
|
|
77
|
+
5. **HANDLE** completion
|
|
78
|
+
|
|
79
|
+
### When Retrieving Results
|
|
80
|
+
1. **VERIFY** job completion
|
|
81
|
+
2. **CALL** getJobResult()
|
|
82
|
+
3. **VALIDATE** result format
|
|
83
|
+
4. **USE** result data
|
|
84
|
+
5. **CLEAR** job data
|
|
85
|
+
|
|
86
|
+
### Code Style Rules
|
|
87
|
+
- **SAVE** request IDs persistently
|
|
88
|
+
- **IMPLEMENT** polling with timeout
|
|
89
|
+
- **HANDLE** all status cases
|
|
90
|
+
- **CLEAN UP** old jobs
|
|
91
|
+
- **LOG** job lifecycle events
|
|
92
|
+
|
|
93
|
+
## 📦 Available Service
|
|
94
|
+
|
|
95
|
+
### jobProcessor
|
|
96
|
+
|
|
97
|
+
**Refer to**: [`job-processor.ts`](./job-processor.ts)
|
|
98
|
+
|
|
99
|
+
**Methods:**
|
|
100
|
+
- `submitJob(model, input)` - Submit async job
|
|
101
|
+
- `getJobStatus(model, requestId)` - Get job status
|
|
102
|
+
- `getJobResult(model, requestId)` - Get job result
|
|
103
|
+
- `clear()` - Clear all jobs
|
|
104
|
+
|
|
105
|
+
## 🔗 Related Modules
|
|
106
|
+
|
|
107
|
+
- **Job Manager**: [`../../job/README.md`](../../job/README.md)
|
|
108
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
109
|
+
- **Generation Executor**: [`GENERATION_EXECUTOR_SERVICE.md`](./GENERATION_EXECUTOR_SERVICE.md)
|
|
110
|
+
|
|
111
|
+
## 📋 Job States
|
|
112
|
+
|
|
113
|
+
### IN_QUEUE
|
|
114
|
+
Job is queued, waiting to start.
|
|
115
|
+
|
|
116
|
+
### PROCESSING
|
|
117
|
+
Job is currently being processed.
|
|
118
|
+
|
|
119
|
+
### COMPLETED
|
|
120
|
+
Job finished successfully with result.
|
|
121
|
+
|
|
122
|
+
### FAILED
|
|
123
|
+
Job failed with error.
|
|
124
|
+
|
|
125
|
+
## 🎓 Usage Patterns
|
|
126
|
+
|
|
127
|
+
### Job Submission
|
|
128
|
+
1. Validate input parameters
|
|
129
|
+
2. Call submitJob()
|
|
130
|
+
3. Save request ID
|
|
131
|
+
4. Display submission status
|
|
132
|
+
5. Begin polling
|
|
133
|
+
|
|
134
|
+
### Status Polling
|
|
135
|
+
1. Poll getJobStatus() periodically
|
|
136
|
+
2. Implement exponential backoff
|
|
137
|
+
3. Update UI with status
|
|
138
|
+
4. Handle completion/failure
|
|
139
|
+
5. Stop polling when done
|
|
140
|
+
|
|
141
|
+
### Result Retrieval
|
|
142
|
+
1. Verify job completion
|
|
143
|
+
2. Call getJobResult()
|
|
144
|
+
3. Validate result format
|
|
145
|
+
4. Use result data
|
|
146
|
+
5. Clear job data
|
|
147
|
+
|
|
148
|
+
### Job Cleanup
|
|
149
|
+
1. Track job completion time
|
|
150
|
+
2. Clear old completed jobs
|
|
151
|
+
3. Remove failed jobs
|
|
152
|
+
4. Manage memory usage
|
|
153
|
+
5. Implement expiration
|
|
154
|
+
|
|
155
|
+
## 🚨 Common Pitfalls
|
|
156
|
+
|
|
157
|
+
### Don't
|
|
158
|
+
- Lose request IDs
|
|
159
|
+
- Poll too frequently
|
|
160
|
+
- Skip error handling
|
|
161
|
+
- Forget to clean up jobs
|
|
162
|
+
- Block on job submission
|
|
163
|
+
|
|
164
|
+
### Do
|
|
165
|
+
- Save request IDs persistently
|
|
166
|
+
- Implement exponential backoff
|
|
167
|
+
- Handle all job states
|
|
168
|
+
- Clean up completed jobs
|
|
169
|
+
- Provide user feedback
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
**Last Updated**: 2025-01-08
|
|
174
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Provider Initializer Service
|
|
2
|
+
|
|
3
|
+
Service for initializing and configuring the Gemini Provider. Handles setup of the core client with provider-specific configuration.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { providerInitializer } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use provider initializer to configure and set up the Gemini provider before using any services. Initializes core client with API keys and configuration.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Initialize provider on application startup
|
|
17
|
+
- Configure retry and timeout settings
|
|
18
|
+
- Set default models for different features
|
|
19
|
+
- Reset provider for testing
|
|
20
|
+
- Verify initialization status
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Provider must be initialized before any AI operations. This service:
|
|
25
|
+
- Initializes singleton core client
|
|
26
|
+
- Configures retry and timeout behavior
|
|
27
|
+
- Sets default models for features
|
|
28
|
+
- Prevents duplicate initialization
|
|
29
|
+
- Provides reset capability for testing
|
|
30
|
+
- Validates configuration
|
|
31
|
+
|
|
32
|
+
**Key Decision**: Initialize provider once at application startup. Use `isInitialized()` to verify before operations.
|
|
33
|
+
|
|
34
|
+
## ⚠️ Rules
|
|
35
|
+
|
|
36
|
+
### Initialization Rules
|
|
37
|
+
- **MUST** initialize before using any service
|
|
38
|
+
- **SHOULD** initialize on app startup
|
|
39
|
+
- **MUST** provide valid API key
|
|
40
|
+
- **SHOULD** check initialization status
|
|
41
|
+
- **MUST NOT** reinitialize unnecessarily
|
|
42
|
+
|
|
43
|
+
### Configuration Rules
|
|
44
|
+
- **MUST** provide API key (required field)
|
|
45
|
+
- **SHOULD** set appropriate retry limits
|
|
46
|
+
- **MUST** configure timeouts appropriately
|
|
47
|
+
- **SHOULD** use environment variables for secrets
|
|
48
|
+
- **MUST NOT** hardcode API keys
|
|
49
|
+
|
|
50
|
+
### API Key Rules
|
|
51
|
+
- **MUST** store API keys securely
|
|
52
|
+
- **SHOULD** use environment variables
|
|
53
|
+
- **MUST NOT** commit API keys to version control
|
|
54
|
+
- **SHOULD** rotate keys periodically
|
|
55
|
+
- **MUST** validate key format
|
|
56
|
+
|
|
57
|
+
### Reset Rules
|
|
58
|
+
- **SHOULD** only reset for testing
|
|
59
|
+
- **MUST NOT** reset in production
|
|
60
|
+
- **SHOULD** reinitialize after reset
|
|
61
|
+
- **MUST** handle reset errors
|
|
62
|
+
- **SHOULD** warn before resetting
|
|
63
|
+
|
|
64
|
+
## 🤖 AI Agent Guidelines
|
|
65
|
+
|
|
66
|
+
### When Initializing Provider
|
|
67
|
+
1. **CALL** initialize() with configuration
|
|
68
|
+
2. **PROVIDE** valid API key
|
|
69
|
+
3. **SET** appropriate retry/timeout values
|
|
70
|
+
4. **CONFIGURE** default models
|
|
71
|
+
5. **VERIFY** initialization success
|
|
72
|
+
|
|
73
|
+
### When Checking Status
|
|
74
|
+
1. **CALL** isInitialized() before operations
|
|
75
|
+
2. **THROW** error if not initialized
|
|
76
|
+
3. **INITIALIZE** if not ready
|
|
77
|
+
4. **LOG** initialization status
|
|
78
|
+
5. **HANDLE** initialization errors
|
|
79
|
+
|
|
80
|
+
### When Resetting Provider
|
|
81
|
+
1. **USE** only in test environments
|
|
82
|
+
2. **CALL** reset() to clear state
|
|
83
|
+
3. **REINITIALIZE** with new config
|
|
84
|
+
4. **VERIFY** reset success
|
|
85
|
+
5. **CLEAN UP** resources
|
|
86
|
+
|
|
87
|
+
### Code Style Rules
|
|
88
|
+
- **INITIALIZE** early in app lifecycle
|
|
89
|
+
- **VALIDATE** configuration before initialization
|
|
90
|
+
- **HANDLE** initialization errors
|
|
91
|
+
- **LOG** initialization in development
|
|
92
|
+
- **USE** environment variables for secrets
|
|
93
|
+
|
|
94
|
+
## 📦 Available Service
|
|
95
|
+
|
|
96
|
+
### providerInitializer
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`provider-initializer.ts`](./provider-initializer.ts)
|
|
99
|
+
|
|
100
|
+
**Singleton instance**
|
|
101
|
+
|
|
102
|
+
**Methods:**
|
|
103
|
+
- `initialize(config)` - Initialize provider with configuration
|
|
104
|
+
- `isInitialized()` - Check if provider is initialized
|
|
105
|
+
- `reset()` - Reset provider state
|
|
106
|
+
|
|
107
|
+
## 🔗 Related Modules
|
|
108
|
+
|
|
109
|
+
- **Core Client**: [`CORE_CLIENT_SERVICE.md`](./CORE_CLIENT_SERVICE.md)
|
|
110
|
+
- **Domain Types**: [`../../domain/README.md`](../../domain/README.md)
|
|
111
|
+
- **Services README**: [`./README.md`](./README.md)
|
|
112
|
+
|
|
113
|
+
## 📋 Configuration
|
|
114
|
+
|
|
115
|
+
### Required Fields
|
|
116
|
+
- `apiKey`: Google Cloud API key
|
|
117
|
+
|
|
118
|
+
### Optional Fields
|
|
119
|
+
- `maxRetries`: Maximum retry attempts (default: from core config)
|
|
120
|
+
- `baseDelay`: Base delay for retries in ms (default: from core config)
|
|
121
|
+
- `maxDelay`: Maximum delay for retries in ms (default: from core config)
|
|
122
|
+
- `defaultTimeoutMs`: Default timeout for requests in ms (default: from core config)
|
|
123
|
+
- `textModel`: Default model for text generation
|
|
124
|
+
- `textToImageModel`: Default model for image generation
|
|
125
|
+
- `imageEditModel`: Default model for image editing
|
|
126
|
+
|
|
127
|
+
## 🎓 Usage Patterns
|
|
128
|
+
|
|
129
|
+
### Basic Initialization
|
|
130
|
+
1. Import providerInitializer
|
|
131
|
+
2. Call initialize() with API key
|
|
132
|
+
3. Verify initialization success
|
|
133
|
+
4. Use Gemini services normally
|
|
134
|
+
5. Handle initialization errors
|
|
135
|
+
|
|
136
|
+
### Full Configuration
|
|
137
|
+
1. Create configuration object
|
|
138
|
+
2. Set API key and models
|
|
139
|
+
3. Configure retry/timeout values
|
|
140
|
+
4. Initialize provider
|
|
141
|
+
5. Verify all settings
|
|
142
|
+
|
|
143
|
+
### React Native Integration
|
|
144
|
+
1. Import in App component
|
|
145
|
+
2. Initialize in useEffect
|
|
146
|
+
3. Set loading state
|
|
147
|
+
4. Handle errors
|
|
148
|
+
5. Render app when ready
|
|
149
|
+
|
|
150
|
+
### Environment-Based Configuration
|
|
151
|
+
1. Detect environment (dev/prod)
|
|
152
|
+
2. Select appropriate configuration
|
|
153
|
+
3. Initialize with environment settings
|
|
154
|
+
4. Log configuration in development
|
|
155
|
+
5. Use appropriate models
|
|
156
|
+
|
|
157
|
+
## 🚨 Common Pitfalls
|
|
158
|
+
|
|
159
|
+
### Don't
|
|
160
|
+
- Initialize provider before every operation
|
|
161
|
+
- Hardcode API keys in source code
|
|
162
|
+
- Skip initialization status checks
|
|
163
|
+
- Use invalid API keys
|
|
164
|
+
- Reset provider in production
|
|
165
|
+
|
|
166
|
+
### Do
|
|
167
|
+
- Initialize once at app startup
|
|
168
|
+
- Use environment variables for API keys
|
|
169
|
+
- Check initialization status before use
|
|
170
|
+
- Validate configuration format
|
|
171
|
+
- Handle initialization errors gracefully
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
**Last Updated**: 2025-01-08
|
|
176
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|