@umituz/react-native-ai-gemini-provider 1.14.28 → 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
package/package.json
CHANGED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Domain Layer
|
|
2
|
+
|
|
3
|
+
Core type definitions and constants for the Gemini provider. Contains data structures and constants independent of business logic.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import type {
|
|
9
|
+
GeminiConfig,
|
|
10
|
+
GeminiGenerationConfig,
|
|
11
|
+
GeminiResponse,
|
|
12
|
+
GeminiImageGenerationResult,
|
|
13
|
+
VideoGenerationResult,
|
|
14
|
+
GeminiError,
|
|
15
|
+
GeminiErrorType
|
|
16
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
GEMINI_MODELS,
|
|
20
|
+
DEFAULT_MODELS,
|
|
21
|
+
getGeminiImageFeatureModel,
|
|
22
|
+
getGeminiVideoFeatureModel
|
|
23
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🎯 Purpose
|
|
27
|
+
|
|
28
|
+
Use this layer for type-safe integration with Gemini services. Provides TypeScript interfaces and constants for all operations.
|
|
29
|
+
|
|
30
|
+
**When to use:**
|
|
31
|
+
- Type-check API requests and responses
|
|
32
|
+
- Access model constants and configurations
|
|
33
|
+
- Define function signatures
|
|
34
|
+
- Understand data structures
|
|
35
|
+
- Handle typed errors
|
|
36
|
+
|
|
37
|
+
## 📌 Strategy
|
|
38
|
+
|
|
39
|
+
Domain layer contains NO business logic or external dependencies. These definitions:
|
|
40
|
+
- Provide pure type definitions
|
|
41
|
+
- Define constant values
|
|
42
|
+
- Enable compile-time type checking
|
|
43
|
+
- Document API contracts
|
|
44
|
+
- Remain stable despite code changes
|
|
45
|
+
|
|
46
|
+
**Key Decision**: All domain types have NO external dependencies. This keeps them pure, reusable, and testable.
|
|
47
|
+
|
|
48
|
+
## ⚠️ Rules
|
|
49
|
+
|
|
50
|
+
### Usage Rules
|
|
51
|
+
- **MUST** use types from domain layer
|
|
52
|
+
- **SHOULD** use type imports over value imports
|
|
53
|
+
- **MUST** handle all defined error types
|
|
54
|
+
- **SHOULD** use constants instead of hardcoded values
|
|
55
|
+
- **MUST NOT** use `any` type
|
|
56
|
+
|
|
57
|
+
### Type Safety Rules
|
|
58
|
+
- **MUST** define explicit return types
|
|
59
|
+
- **SHOULD** use strict null checks
|
|
60
|
+
- **MUST** validate runtime data
|
|
61
|
+
- **SHOULD** use discriminated unions for errors
|
|
62
|
+
- **MUST NOT** bypass type checking
|
|
63
|
+
|
|
64
|
+
### Constants Rules
|
|
65
|
+
- **MUST** use defined model constants
|
|
66
|
+
- **SHOULD** use helper functions for model selection
|
|
67
|
+
- **MUST NOT** hardcode model IDs
|
|
68
|
+
- **SHOULD** prefer constants over magic strings
|
|
69
|
+
- **MUST** use valid model IDs from constants
|
|
70
|
+
|
|
71
|
+
## 🤖 AI Agent Guidelines
|
|
72
|
+
|
|
73
|
+
### When Modifying Domain Types
|
|
74
|
+
1. **READ** existing type definitions first
|
|
75
|
+
2. **UNDERSTAND** type relationships
|
|
76
|
+
3. **MAINTAIN** backward compatibility
|
|
77
|
+
4. **UPDATE** all dependent code
|
|
78
|
+
5. **ADD** tests for new types
|
|
79
|
+
|
|
80
|
+
### When Adding New Types
|
|
81
|
+
1. **CHECK** if similar type exists
|
|
82
|
+
2. **FOLLOW** existing naming conventions
|
|
83
|
+
3. **USE** consistent patterns
|
|
84
|
+
4. **DOCUMENT** with JSDoc comments
|
|
85
|
+
5. **EXPORT** from index files
|
|
86
|
+
|
|
87
|
+
### When Adding Constants
|
|
88
|
+
1. **CHECK** if constant already exists
|
|
89
|
+
2. **USE** descriptive names
|
|
90
|
+
3. **GROUP** related constants
|
|
91
|
+
4. **PROVIDE** helper functions
|
|
92
|
+
5. **DOCUMENT** constant values
|
|
93
|
+
|
|
94
|
+
### Code Style Rules
|
|
95
|
+
- **USE** explicit type annotations
|
|
96
|
+
- **AVOID** `any` type
|
|
97
|
+
- **PREFER** readonly where appropriate
|
|
98
|
+
- **USE** discriminated unions
|
|
99
|
+
- **DOCUMENT** complex types
|
|
100
|
+
|
|
101
|
+
## 📦 Available Modules
|
|
102
|
+
|
|
103
|
+
### Type Definitions
|
|
104
|
+
|
|
105
|
+
**Entities**: Core data structures
|
|
106
|
+
|
|
107
|
+
**Refer to**: [`entities/README.md`](./entities/README.md)
|
|
108
|
+
|
|
109
|
+
**Files:**
|
|
110
|
+
- [`entities/gemini.types.ts`](./entities/gemini.types.ts) - Main Gemini types
|
|
111
|
+
- [`entities/error.types.ts`](./entities/error.types.ts) - Error types
|
|
112
|
+
- [`entities/models.ts`](./entities/models.ts) - Model definitions
|
|
113
|
+
- [`entities/video.types.ts`](./entities/video.types.ts) - Video types
|
|
114
|
+
|
|
115
|
+
### Constants
|
|
116
|
+
|
|
117
|
+
**Feature Models**: Model mappings for features
|
|
118
|
+
|
|
119
|
+
**Refer to**: [`constants/README.md`](./constants/README.md)
|
|
120
|
+
|
|
121
|
+
**Files:**
|
|
122
|
+
- [`constants/feature-models.constants.ts`](./constants/feature-models.constants.ts) - Feature model mappings
|
|
123
|
+
- [`constants/models.constants.ts`](./constants/models.constants.ts) - Model constants
|
|
124
|
+
|
|
125
|
+
## 🔗 Related Modules
|
|
126
|
+
|
|
127
|
+
- **Services**: [`../infrastructure/services/README.md`](../infrastructure/services/README.md)
|
|
128
|
+
- **Infrastructure**: [`../infrastructure/README.md`](../infrastructure/README.md)
|
|
129
|
+
- **Providers**: [`../providers/README.md`](../providers/README.md)
|
|
130
|
+
|
|
131
|
+
## 📋 Type Reference
|
|
132
|
+
|
|
133
|
+
### Configuration Types
|
|
134
|
+
|
|
135
|
+
**GeminiConfig**: Client configuration
|
|
136
|
+
- `apiKey`: string (required)
|
|
137
|
+
- `baseUrl`: string (optional)
|
|
138
|
+
- `maxRetries`: number (optional)
|
|
139
|
+
- Various model IDs (optional)
|
|
140
|
+
|
|
141
|
+
**GeminiGenerationConfig**: Generation parameters
|
|
142
|
+
- Compatible with Google SDK
|
|
143
|
+
- Temperature, topP, topK, maxOutputTokens
|
|
144
|
+
- Response schema
|
|
145
|
+
|
|
146
|
+
### Request/Response Types
|
|
147
|
+
|
|
148
|
+
**GeminiContent**: API request structure
|
|
149
|
+
- `parts`: Array of text, inline data, or file data
|
|
150
|
+
- `role`: "user" | "model"
|
|
151
|
+
|
|
152
|
+
**GeminiResponse**: API response structure
|
|
153
|
+
- `candidates`: Generated results
|
|
154
|
+
- `promptFeedback`: Prompt feedback
|
|
155
|
+
- `usageMetadata`: Token usage
|
|
156
|
+
|
|
157
|
+
### Error Types
|
|
158
|
+
|
|
159
|
+
**GeminiError**: Custom error class
|
|
160
|
+
- Extends Error
|
|
161
|
+
- Includes error type and original error
|
|
162
|
+
|
|
163
|
+
**GeminiErrorType**: Error categories
|
|
164
|
+
- API_ERROR, VALIDATION_ERROR, NETWORK_ERROR
|
|
165
|
+
- TIMEOUT_ERROR, RATE_LIMIT_ERROR, PARSING_ERROR
|
|
166
|
+
- QUOTA_EXCEEDED, AUTHENTICATION, SAFETY
|
|
167
|
+
- MODEL_NOT_FOUND, SERVER
|
|
168
|
+
|
|
169
|
+
### Model Constants
|
|
170
|
+
|
|
171
|
+
**GEMINI_MODELS**: All supported models
|
|
172
|
+
- Text models (gemini-2.5-flash-lite, gemini-2.5-pro, etc.)
|
|
173
|
+
- Image models (imagen-4.0-generate-001, etc.)
|
|
174
|
+
- Video models (veo-3.1-fast-generate-preview, etc.)
|
|
175
|
+
|
|
176
|
+
**DEFAULT_MODELS**: Default model selections
|
|
177
|
+
- TEXT: gemini-2.5-flash-lite
|
|
178
|
+
- TEXT_TO_IMAGE: imagen-4.0-generate-001
|
|
179
|
+
- IMAGE_EDIT: gemini-2.5-flash-image
|
|
180
|
+
- VIDEO_GENERATION: veo-3.1-fast-generate-preview
|
|
181
|
+
|
|
182
|
+
## 🎓 Usage Patterns
|
|
183
|
+
|
|
184
|
+
### Type Imports
|
|
185
|
+
1. Import types from package
|
|
186
|
+
2. Use for function parameters
|
|
187
|
+
3. Define return types
|
|
188
|
+
4. Handle typed errors
|
|
189
|
+
5. Validate runtime data
|
|
190
|
+
|
|
191
|
+
### Model Selection
|
|
192
|
+
1. Import model constants
|
|
193
|
+
2. Use helper functions for feature-based selection
|
|
194
|
+
3. Get model ID for specific feature
|
|
195
|
+
4. Use returned ID in service calls
|
|
196
|
+
5. Avoid hardcoded model strings
|
|
197
|
+
|
|
198
|
+
### Error Handling
|
|
199
|
+
1. Catch error from operation
|
|
200
|
+
2. Check if `instanceof GeminiError`
|
|
201
|
+
3. Switch on error.type
|
|
202
|
+
4. Handle each error type appropriately
|
|
203
|
+
5. Provide user feedback
|
|
204
|
+
|
|
205
|
+
### Configuration
|
|
206
|
+
1. Create config object
|
|
207
|
+
2. Use types for validation
|
|
208
|
+
3. Specify model IDs from constants
|
|
209
|
+
4. Include retry and timeout settings
|
|
210
|
+
5. Initialize provider with config
|
|
211
|
+
|
|
212
|
+
## 🚨 Common Pitfalls
|
|
213
|
+
|
|
214
|
+
### Don't
|
|
215
|
+
- Use `any` type to bypass typing
|
|
216
|
+
- Hardcode model IDs
|
|
217
|
+
- Ignore error types
|
|
218
|
+
- Skip runtime validation
|
|
219
|
+
- Use magic strings
|
|
220
|
+
|
|
221
|
+
### Do
|
|
222
|
+
- Use explicit type annotations
|
|
223
|
+
- Import constants for model IDs
|
|
224
|
+
- Check error types
|
|
225
|
+
- Validate runtime data
|
|
226
|
+
- Use helper functions
|
|
227
|
+
- Define proper interfaces
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
**Last Updated**: 2025-01-08
|
|
232
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Domain Constants
|
|
2
|
+
|
|
3
|
+
Constant values and model catalogs for Gemini provider. Contains feature-based model mappings for image and video operations.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
GEMINI_IMAGE_FEATURE_MODELS,
|
|
10
|
+
GEMINI_VIDEO_FEATURE_MODELS,
|
|
11
|
+
getGeminiImageFeatureModel,
|
|
12
|
+
getGeminiVideoFeatureModel,
|
|
13
|
+
getAllFeatureModels
|
|
14
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 🎯 Purpose
|
|
18
|
+
|
|
19
|
+
Use constants to map features to appropriate models. Provides centralized model selection for image and video processing features.
|
|
20
|
+
|
|
21
|
+
**When to use:**
|
|
22
|
+
- Get model ID for specific feature
|
|
23
|
+
- Display available features in UI
|
|
24
|
+
- Validate feature requests
|
|
25
|
+
- Map user features to models
|
|
26
|
+
- List supported operations
|
|
27
|
+
|
|
28
|
+
## 📌 Strategy
|
|
29
|
+
|
|
30
|
+
Features map to specific models. This system:
|
|
31
|
+
- Provides constant feature-to-model mappings
|
|
32
|
+
- Centralizes model configuration
|
|
33
|
+
- Enables feature validation
|
|
34
|
+
- Simplifies model selection
|
|
35
|
+
- Maintains consistency across codebase
|
|
36
|
+
|
|
37
|
+
**Key Decision**: Use feature constants instead of hardcoded model IDs. This enables centralized model management and updates.
|
|
38
|
+
|
|
39
|
+
## ⚠️ Rules
|
|
40
|
+
|
|
41
|
+
### Usage Rules
|
|
42
|
+
- **MUST** use constants for model selection
|
|
43
|
+
- **SHOULD** validate feature before use
|
|
44
|
+
- **MUST** handle unknown features gracefully
|
|
45
|
+
- **SHOULD** check model compatibility
|
|
46
|
+
- **MUST NOT** hardcode model IDs
|
|
47
|
+
|
|
48
|
+
### Feature Selection Rules
|
|
49
|
+
- **MUST** select appropriate model for feature
|
|
50
|
+
- **SHOULD** use getter functions
|
|
51
|
+
- **MUST** validate feature type
|
|
52
|
+
- **SHOULD** handle missing features
|
|
53
|
+
- **MUST** return valid model IDs
|
|
54
|
+
|
|
55
|
+
### Validation Rules
|
|
56
|
+
- **SHOULD** validate feature strings
|
|
57
|
+
- **MUST** check feature exists
|
|
58
|
+
- **SHOULD** provide fallback models
|
|
59
|
+
- **MUST** throw on invalid features
|
|
60
|
+
- **SHOULD** log validation failures
|
|
61
|
+
|
|
62
|
+
### Maintenance Rules
|
|
63
|
+
- **MUST** update constants when models change
|
|
64
|
+
- **SHOULD** document model changes
|
|
65
|
+
- **MUST** maintain backward compatibility
|
|
66
|
+
- **SHOULD** test feature mappings
|
|
67
|
+
- **MUST** update documentation
|
|
68
|
+
|
|
69
|
+
## 🤖 AI Agent Guidelines
|
|
70
|
+
|
|
71
|
+
### When Getting Model for Feature
|
|
72
|
+
1. **CALL** getGeminiImageFeatureModel() or getGeminiVideoFeatureModel()
|
|
73
|
+
2. **VALIDATE** feature exists
|
|
74
|
+
3. **RETURN** model ID
|
|
75
|
+
4. **HANDLE** unknown features
|
|
76
|
+
5. **LOG** model selection
|
|
77
|
+
|
|
78
|
+
### When Listing Features
|
|
79
|
+
1. **CALL** getAllFeatureModels()
|
|
80
|
+
2. **FILTER** by feature type
|
|
81
|
+
3. **DISPLAY** to user
|
|
82
|
+
4. **GROUP** by category
|
|
83
|
+
5. **HANDLE** empty lists
|
|
84
|
+
|
|
85
|
+
### When Validating Features
|
|
86
|
+
1. **CHECK** feature in constants
|
|
87
|
+
2. **VERIFY** model exists
|
|
88
|
+
3. **RETURN** validation result
|
|
89
|
+
4. **PROVIDE** error messages
|
|
90
|
+
5. **SUGGEST** alternatives
|
|
91
|
+
|
|
92
|
+
### Code Style Rules
|
|
93
|
+
- **USE** constants instead of hardcoded values
|
|
94
|
+
- **IMPORT** specific constants needed
|
|
95
|
+
- **VALIDATE** feature inputs
|
|
96
|
+
- **HANDLE** edge cases
|
|
97
|
+
- **DOCUMENT** custom features
|
|
98
|
+
|
|
99
|
+
## 📦 Available Constants
|
|
100
|
+
|
|
101
|
+
### Image Feature Models
|
|
102
|
+
|
|
103
|
+
**Refer to**: [`feature-models.constants.ts`](./feature-models.constants.ts)
|
|
104
|
+
|
|
105
|
+
**Features:**
|
|
106
|
+
- `upscale` - Image upscaling
|
|
107
|
+
- `photo-restore` - Photo restoration
|
|
108
|
+
- `face-swap` - Face swapping
|
|
109
|
+
- `anime-selfie` - Anime style transformation
|
|
110
|
+
- `remove-background` - Background removal
|
|
111
|
+
- `remove-object` - Object removal
|
|
112
|
+
- `hd-touch-up` - HD enhancement
|
|
113
|
+
- `replace-background` - Background replacement
|
|
114
|
+
|
|
115
|
+
**Model**: All use `gemini-2.0-flash-exp`
|
|
116
|
+
|
|
117
|
+
### Video Feature Models
|
|
118
|
+
|
|
119
|
+
**Refer to**: [`feature-models.constants.ts`](./feature-models.constants.ts)
|
|
120
|
+
|
|
121
|
+
**Features:**
|
|
122
|
+
- `ai-hug` - AI hugging effect
|
|
123
|
+
- `ai-kiss` - AI kissing effect
|
|
124
|
+
|
|
125
|
+
**Model**: All use `gemini-2.0-flash-exp`
|
|
126
|
+
|
|
127
|
+
## 🔗 Related Modules
|
|
128
|
+
|
|
129
|
+
- **Domain Entities**: [`../entities/README.md`](../entities/README.md)
|
|
130
|
+
- **Domain README**: [`../README.md`](../README.md)
|
|
131
|
+
- **Model Selector**: [`../../infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md`](../../infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md)
|
|
132
|
+
|
|
133
|
+
## 📋 Feature Reference
|
|
134
|
+
|
|
135
|
+
### Image Editing Features
|
|
136
|
+
- **upscale**: Enlarge image while maintaining quality
|
|
137
|
+
- **photo-restore**: Restore old or damaged photos
|
|
138
|
+
- **face-swap**: Swap faces between images
|
|
139
|
+
- **anime-selfie**: Transform selfie to anime style
|
|
140
|
+
- **remove-background**: Remove image background
|
|
141
|
+
- **remove-object**: Remove specific objects from image
|
|
142
|
+
- **hd-touch-up**: Enhance image quality to HD
|
|
143
|
+
- **replace-background**: Replace image background
|
|
144
|
+
|
|
145
|
+
### Video Features
|
|
146
|
+
- **ai-hug**: Generate video of subjects hugging
|
|
147
|
+
- **ai-kiss**: Generate video of subjects kissing
|
|
148
|
+
|
|
149
|
+
## 🎓 Usage Patterns
|
|
150
|
+
|
|
151
|
+
### Feature-Based Model Selection
|
|
152
|
+
1. Determine feature type (image or video)
|
|
153
|
+
2. Call appropriate getter function
|
|
154
|
+
3. Get model ID for feature
|
|
155
|
+
4. Use model in service call
|
|
156
|
+
5. Handle unknown features
|
|
157
|
+
|
|
158
|
+
### Feature Listing
|
|
159
|
+
1. Call getAllFeatureModels()
|
|
160
|
+
2. Iterate through feature list
|
|
161
|
+
3. Group by category
|
|
162
|
+
4. Display to user
|
|
163
|
+
5. Handle feature selection
|
|
164
|
+
|
|
165
|
+
### Feature Validation
|
|
166
|
+
1. Check feature in constants
|
|
167
|
+
2. Verify model mapping exists
|
|
168
|
+
3. Validate feature type
|
|
169
|
+
4. Return validation result
|
|
170
|
+
5. Provide feedback
|
|
171
|
+
|
|
172
|
+
## 🚨 Common Pitfalls
|
|
173
|
+
|
|
174
|
+
### Don't
|
|
175
|
+
- Hardcode model IDs in application code
|
|
176
|
+
- Use features without validation
|
|
177
|
+
- Assume all features use same model
|
|
178
|
+
- Skip feature existence checks
|
|
179
|
+
- Use invalid feature strings
|
|
180
|
+
|
|
181
|
+
### Do
|
|
182
|
+
- Use constants for model selection
|
|
183
|
+
- Validate features before use
|
|
184
|
+
- Check model mappings
|
|
185
|
+
- Handle unknown features gracefully
|
|
186
|
+
- Update constants when models change
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
**Last Updated**: 2025-01-08
|
|
191
|
+
**See Also**: [AI_GUIDELINES.md](../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Domain Entities
|
|
2
|
+
|
|
3
|
+
Core data structures and type definitions for the Gemini provider. Contains all types required for API communication.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import type {
|
|
9
|
+
GeminiConfig,
|
|
10
|
+
GeminiContent,
|
|
11
|
+
GeminiResponse,
|
|
12
|
+
GeminiImageGenerationResult,
|
|
13
|
+
VideoGenerationResult,
|
|
14
|
+
GeminiError,
|
|
15
|
+
GeminiErrorType
|
|
16
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🎯 Purpose
|
|
20
|
+
|
|
21
|
+
Use these types for type-safe integration with Gemini services. Provides TypeScript interfaces for all API operations.
|
|
22
|
+
|
|
23
|
+
**When to use:**
|
|
24
|
+
- Type-check API requests and responses
|
|
25
|
+
- Define function signatures
|
|
26
|
+
- Validate data structures
|
|
27
|
+
- Understand API response formats
|
|
28
|
+
- Handle typed errors
|
|
29
|
+
|
|
30
|
+
## 📌 Strategy
|
|
31
|
+
|
|
32
|
+
Strong typing prevents runtime errors. These types:
|
|
33
|
+
- Define all API request/response structures
|
|
34
|
+
- Provide type safety for operations
|
|
35
|
+
- Enable autocomplete in IDEs
|
|
36
|
+
- Document API contracts
|
|
37
|
+
- Catch errors at compile time
|
|
38
|
+
|
|
39
|
+
**Key Decision**: All types defined in domain layer have NO external dependencies. This keeps them pure and reusable.
|
|
40
|
+
|
|
41
|
+
## ⚠️ Rules
|
|
42
|
+
|
|
43
|
+
### Usage Rules
|
|
44
|
+
- **MUST** use types from domain layer
|
|
45
|
+
- **SHOULD** prefer type imports over value imports
|
|
46
|
+
- **MUST** handle all error types
|
|
47
|
+
- **SHOULD** use type guards for validation
|
|
48
|
+
- **MUST NOT** use `any` type
|
|
49
|
+
|
|
50
|
+
### Type Safety Rules
|
|
51
|
+
- **MUST** define explicit return types
|
|
52
|
+
- **SHOULD** use strict null checks
|
|
53
|
+
- **MUST** validate runtime data
|
|
54
|
+
- **SHOULD** use discriminated unions for errors
|
|
55
|
+
- **MUST NOT** bypass type checking
|
|
56
|
+
|
|
57
|
+
### Error Handling Rules
|
|
58
|
+
- **MUST** catch and handle `GeminiError`
|
|
59
|
+
- **SHOULD** check error types
|
|
60
|
+
- **MUST** handle all error states
|
|
61
|
+
- **SHOULD** provide type-safe error messages
|
|
62
|
+
- **MUST NOT** ignore error types
|
|
63
|
+
|
|
64
|
+
## 🤖 AI Agent Guidelines
|
|
65
|
+
|
|
66
|
+
### When Modifying Types
|
|
67
|
+
1. **READ** existing type definitions first
|
|
68
|
+
2. **UNDERSTAND** type relationships
|
|
69
|
+
3. **MAINTAIN** backward compatibility
|
|
70
|
+
4. **UPDATE** all usages
|
|
71
|
+
5. **ADD** tests for new types
|
|
72
|
+
|
|
73
|
+
### When Adding New Types
|
|
74
|
+
1. **CHECK** if similar type exists
|
|
75
|
+
2. **FOLLOW** existing naming conventions
|
|
76
|
+
3. **USE** consistent patterns
|
|
77
|
+
4. **DOCUMENT** with JSDoc comments
|
|
78
|
+
5. **EXPORT** from index files
|
|
79
|
+
|
|
80
|
+
### When Fixing Type Bugs
|
|
81
|
+
1. **IDENTIFY** root cause in type definition
|
|
82
|
+
2. **FIX** with minimal changes
|
|
83
|
+
3. **UPDATE** all dependent code
|
|
84
|
+
4. **ADD** type tests
|
|
85
|
+
5. **VERIFY** no breaking changes
|
|
86
|
+
|
|
87
|
+
### Code Style Rules
|
|
88
|
+
- **USE** explicit type annotations
|
|
89
|
+
- **AVOID** `any` type
|
|
90
|
+
- **PREFER** readonly where appropriate
|
|
91
|
+
- **USE** discriminated unions
|
|
92
|
+
- **DOCUMENT** complex types
|
|
93
|
+
|
|
94
|
+
## 📦 Available Types
|
|
95
|
+
|
|
96
|
+
### Configuration Types
|
|
97
|
+
|
|
98
|
+
**GeminiConfig**: Client configuration
|
|
99
|
+
|
|
100
|
+
**Refer to**: [`gemini.types.ts`](./gemini.types.ts)
|
|
101
|
+
|
|
102
|
+
### Request/Response Types
|
|
103
|
+
|
|
104
|
+
**GeminiContent**: API request content structure
|
|
105
|
+
|
|
106
|
+
**GeminiResponse**: API response structure
|
|
107
|
+
|
|
108
|
+
**GeminiCandidate**: Generated candidate results
|
|
109
|
+
|
|
110
|
+
**Refer to**: [`gemini.types.ts`](./gemini.types.ts)
|
|
111
|
+
|
|
112
|
+
### Image Types
|
|
113
|
+
|
|
114
|
+
**GeminiImageGenerationResult**: Image generation result
|
|
115
|
+
|
|
116
|
+
**GeminiImageInput**: Image input structure
|
|
117
|
+
|
|
118
|
+
**Refer to**: [`gemini.types.ts`](./gemini.types.ts)
|
|
119
|
+
|
|
120
|
+
### Video Types
|
|
121
|
+
|
|
122
|
+
**VideoGenerationInput**: Video generation input
|
|
123
|
+
|
|
124
|
+
**VideoGenerationResult**: Video generation result
|
|
125
|
+
|
|
126
|
+
**VideoOperationStatus**: Operation status enum
|
|
127
|
+
|
|
128
|
+
**Refer to**: [`video.types.ts`](./video.types.ts)
|
|
129
|
+
|
|
130
|
+
### Error Types
|
|
131
|
+
|
|
132
|
+
**GeminiError**: Custom error class
|
|
133
|
+
|
|
134
|
+
**GeminiErrorType**: Error type enum
|
|
135
|
+
|
|
136
|
+
**GeminiErrorInfo**: Error information interface
|
|
137
|
+
|
|
138
|
+
**Refer to**: [`error.types.ts`](./error.types.ts)
|
|
139
|
+
|
|
140
|
+
### Model Types
|
|
141
|
+
|
|
142
|
+
**GeminiModel**: Model information
|
|
143
|
+
|
|
144
|
+
**GeminiGenerationConfig**: Generation parameters
|
|
145
|
+
|
|
146
|
+
**Refer to**: [`models.ts`](./models.ts)
|
|
147
|
+
|
|
148
|
+
## 🔗 Related Modules
|
|
149
|
+
|
|
150
|
+
- **Services**: [`../../infrastructure/services/README.md`](../../infrastructure/services/README.md)
|
|
151
|
+
- **Error Utilities**: [`../../infrastructure/utils/ERROR_UTILITIES.md`](../../infrastructure/utils/ERROR_UTILITIES.md)
|
|
152
|
+
- **Constants**: [`../constants/README.md`](../constants/README.md)
|
|
153
|
+
|
|
154
|
+
## 📋 Type Reference
|
|
155
|
+
|
|
156
|
+
### Finish Reason Types
|
|
157
|
+
|
|
158
|
+
Values indicating why generation completed:
|
|
159
|
+
- `STOP` - Normal completion
|
|
160
|
+
- `MAX_TOKENS` - Token limit reached
|
|
161
|
+
- `SAFETY` - Blocked by safety filter
|
|
162
|
+
- `RECITATION` - Copyright detected
|
|
163
|
+
- `OTHER` - Other reasons
|
|
164
|
+
|
|
165
|
+
### Video Operation Status
|
|
166
|
+
|
|
167
|
+
Operation lifecycle states:
|
|
168
|
+
- `queued` - Waiting in queue
|
|
169
|
+
- `processing` - Currently processing
|
|
170
|
+
- `completed` - Successfully finished
|
|
171
|
+
- `failed` - Operation failed
|
|
172
|
+
|
|
173
|
+
### Error Categories
|
|
174
|
+
|
|
175
|
+
Error types for handling:
|
|
176
|
+
- `API_ERROR` - General API errors
|
|
177
|
+
- `VALIDATION_ERROR` - Input validation errors
|
|
178
|
+
- `NETWORK_ERROR` - Network connectivity issues
|
|
179
|
+
- `TIMEOUT_ERROR` - Request timeout
|
|
180
|
+
- `RATE_LIMIT_ERROR` - Too many requests
|
|
181
|
+
- `PARSING_ERROR` - Response parsing failures
|
|
182
|
+
- `QUOTA_EXCEEDED` - API quota exceeded
|
|
183
|
+
- `AUTHENTICATION` - Invalid credentials
|
|
184
|
+
- `SAFETY` - Content safety violations
|
|
185
|
+
- `MODEL_NOT_FOUND` - Invalid model ID
|
|
186
|
+
- `SERVER` - Server errors (5xx)
|
|
187
|
+
|
|
188
|
+
## 🎓 Usage Patterns
|
|
189
|
+
|
|
190
|
+
### Type Imports
|
|
191
|
+
1. Import types from package
|
|
192
|
+
2. Use for function parameters
|
|
193
|
+
3. Define return types
|
|
194
|
+
4. Handle typed errors
|
|
195
|
+
5. Validate runtime data
|
|
196
|
+
|
|
197
|
+
### Error Type Checking
|
|
198
|
+
1. Catch error from operation
|
|
199
|
+
2. Check if `instanceof GeminiError`
|
|
200
|
+
3. Switch on error.type
|
|
201
|
+
4. Handle each error type appropriately
|
|
202
|
+
5. Provide user feedback
|
|
203
|
+
|
|
204
|
+
### Image Type Usage
|
|
205
|
+
1. Use `GeminiImageInput` for image data
|
|
206
|
+
2. Provide base64-encoded images
|
|
207
|
+
3. Specify MIME type
|
|
208
|
+
4. Handle image generation results
|
|
209
|
+
5. Extract image URL or base64
|
|
210
|
+
|
|
211
|
+
### Video Type Usage
|
|
212
|
+
1. Use `VideoGenerationInput` for requests
|
|
213
|
+
2. Monitor `VideoOperationStatus`
|
|
214
|
+
3. Handle progress updates
|
|
215
|
+
4. Extract video URL when complete
|
|
216
|
+
5. Handle errors appropriately
|
|
217
|
+
|
|
218
|
+
## 🚨 Common Pitfalls
|
|
219
|
+
|
|
220
|
+
### Don't
|
|
221
|
+
- Use `any` type to bypass typing
|
|
222
|
+
- Ignore error types
|
|
223
|
+
- Skip type validation
|
|
224
|
+
- Use hardcoded model IDs
|
|
225
|
+
- Forget to handle all error states
|
|
226
|
+
|
|
227
|
+
### Do
|
|
228
|
+
- Use explicit type annotations
|
|
229
|
+
- Check error types
|
|
230
|
+
- Validate runtime data
|
|
231
|
+
- Use type guards
|
|
232
|
+
- Handle all finish reasons
|
|
233
|
+
- Provide type-safe error messages
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
**Last Updated**: 2025-01-08
|
|
238
|
+
**See Also**: [AI_GUIDELINES.md](../../../AI_GUIDELINES.md)
|