@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.
Files changed (49) hide show
  1. package/package.json +41 -3
  2. package/src/domain/README.md +232 -0
  3. package/src/domain/constants/README.md +191 -0
  4. package/src/domain/entities/README.md +238 -0
  5. package/src/infrastructure/README.md +252 -0
  6. package/src/infrastructure/cache/CACHE_SYSTEM.md +213 -0
  7. package/src/infrastructure/cache/README.md +213 -0
  8. package/src/infrastructure/content/CONTENT_BUILDER.md +175 -0
  9. package/src/infrastructure/content/README.md +175 -0
  10. package/src/infrastructure/interceptors/README.md +226 -0
  11. package/src/infrastructure/interceptors/REQUEST_INTERCEPTORS.md +171 -0
  12. package/src/infrastructure/job/JOB_MANAGER.md +174 -0
  13. package/src/infrastructure/job/README.md +194 -0
  14. package/src/infrastructure/response/README.md +187 -0
  15. package/src/infrastructure/response/RESPONSE_FORMATTER.md +185 -0
  16. package/src/infrastructure/services/CORE_CLIENT_SERVICE.md +202 -0
  17. package/src/infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md +206 -0
  18. package/src/infrastructure/services/GENERATION_EXECUTOR_SERVICE.md +176 -0
  19. package/src/infrastructure/services/IMAGE_EDIT_SERVICE.md +169 -0
  20. package/src/infrastructure/services/IMAGE_GENERATION_SERVICE.md +166 -0
  21. package/src/infrastructure/services/JOB_PROCESSOR_SERVICE.md +174 -0
  22. package/src/infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md +176 -0
  23. package/src/infrastructure/services/README.md +233 -0
  24. package/src/infrastructure/services/RETRY_SERVICE.md +178 -0
  25. package/src/infrastructure/services/STREAMING_SERVICE.md +166 -0
  26. package/src/infrastructure/services/STRUCTURED_TEXT_SERVICE.md +175 -0
  27. package/src/infrastructure/services/TEXT_GENERATION_SERVICE.md +160 -0
  28. package/src/infrastructure/services/VEO_HTTP_CLIENT_SERVICE.md +179 -0
  29. package/src/infrastructure/services/VEO_POLLING_SERVICE.md +173 -0
  30. package/src/infrastructure/services/VIDEO_DOWNLOADER_SERVICE.md +166 -0
  31. package/src/infrastructure/services/VIDEO_ERROR_HANDLER_SERVICE.md +185 -0
  32. package/src/infrastructure/services/VIDEO_GENERATION_SERVICE.md +176 -0
  33. package/src/infrastructure/services/VIDEO_URL_EXTRACTOR_SERVICE.md +186 -0
  34. package/src/infrastructure/services/gemini-provider.ts +9 -2
  35. package/src/infrastructure/telemetry/README.md +203 -0
  36. package/src/infrastructure/telemetry/TELEMETRY_SYSTEM.md +200 -0
  37. package/src/infrastructure/utils/DATA_TRANSFORMER_UTILS.md +175 -0
  38. package/src/infrastructure/utils/ERROR_MAPPER.md +170 -0
  39. package/src/infrastructure/utils/ERROR_UTILITIES.md +208 -0
  40. package/src/infrastructure/utils/IMAGE_PREPARER_UTILS.md +185 -0
  41. package/src/infrastructure/utils/INPUT_BUILDERS.md +214 -0
  42. package/src/infrastructure/utils/MODEL_VALIDATION_UTILS.md +189 -0
  43. package/src/infrastructure/utils/PERFORMANCE_UTILITIES.md +477 -0
  44. package/src/infrastructure/utils/PERFORMANCE_UTILS.md +219 -0
  45. package/src/infrastructure/utils/README.md +289 -0
  46. package/src/presentation/README.md +187 -0
  47. package/src/presentation/hooks/README.md +188 -0
  48. package/src/presentation/hooks/USE_GEMINI_HOOK.md +226 -0
  49. package/src/providers/README.md +247 -0
@@ -0,0 +1,289 @@
1
+ # Utils
2
+
3
+ Utility functions and tools for Gemini provider. Handles error management, performance monitoring, data transformation, model validation, image preparation, and input building.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import {
9
+ // Error handling
10
+ mapGeminiError,
11
+ isGeminiErrorRetryable,
12
+ categorizeGeminiError,
13
+ createGeminiError,
14
+
15
+ // Model validation
16
+ isValidModel,
17
+ validateModel,
18
+ getSafeModel,
19
+ getModelCategory,
20
+ getAllValidModels,
21
+
22
+ // Performance
23
+ measureAsync,
24
+ measureSync,
25
+ debounce,
26
+ throttle,
27
+ performanceTracker,
28
+
29
+ // Data transformation
30
+ extractBase64Data,
31
+ extractTextFromResponse,
32
+
33
+ // Image preparation
34
+ prepareImageFromUri,
35
+ prepareImage,
36
+ isValidBase64,
37
+
38
+ // Input builders
39
+ buildUpscaleInput,
40
+ buildPhotoRestoreInput,
41
+ buildRemoveBackgroundInput,
42
+ buildReplaceBackgroundInput
43
+ } from '@umituz/react-native-ai-gemini-provider';
44
+ ```
45
+
46
+ ## 🎯 Purpose
47
+
48
+ Use utility functions for common operations across the provider. Provides error handling, validation, performance monitoring, and data transformation capabilities.
49
+
50
+ **When to use:**
51
+ - Validate model IDs
52
+ - Handle API errors
53
+ - Monitor performance
54
+ - Transform data formats
55
+ - Prepare images for processing
56
+ - Build complex inputs
57
+ - Measure operation duration
58
+ - Debounce/throttle functions
59
+
60
+ ## 📌 Strategy
61
+
62
+ Utilities provide reusable, composable functions. This system:
63
+ - Separates concerns from business logic
64
+ - Provides consistent error handling
65
+ - Enables performance monitoring
66
+ - Simplifies data transformations
67
+ - Validates inputs centrally
68
+ - Builds complex inputs from simple data
69
+
70
+ **Key Decision**: Use utility functions for cross-cutting concerns. Keep services focused on business logic, use utils for operational tasks.
71
+
72
+ ## ⚠️ Rules
73
+
74
+ ### Error Handling Rules
75
+ - **MUST** catch and categorize all API errors
76
+ - **SHOULD** use typed GeminiError instances
77
+ - **MUST** check retryable status before retrying
78
+ - **SHOULD** log errors appropriately
79
+ - **MUST NOT** expose sensitive data in errors
80
+
81
+ ### Model Validation Rules
82
+ - **MUST** validate model IDs before use
83
+ - **SHOULD** use safe fallbacks for invalid models
84
+ - **MUST** check model category for features
85
+ - **SHOULD** validate early in request flow
86
+ - **MUST NOT** allow arbitrary model IDs
87
+
88
+ ### Performance Rules
89
+ - **SHOULD** measure critical operations
90
+ - **MUST** track performance metrics
91
+ - **SHOULD** use debounce/throttle for frequent calls
92
+ - **MUST NOT** impact performance with monitoring
93
+ - **SHOULD** aggregate metrics over time
94
+
95
+ ### Data Transformation Rules
96
+ - **MUST** validate input data format
97
+ - **SHOULD** handle edge cases (null, undefined)
98
+ - **MUST** sanitize sensitive information
99
+ - **SHOULD** preserve data integrity
100
+ - **MUST** handle transformation errors
101
+
102
+ ### Image Preparation Rules
103
+ - **MUST** validate base64 format
104
+ - **SHOULD** handle different image formats
105
+ - **MUST** extract MIME type correctly
106
+ - **SHOULD** handle large images efficiently
107
+ - **MUST** validate image data
108
+
109
+ ## 🤖 AI Agent Guidelines
110
+
111
+ ### When Handling Errors
112
+ 1. **CATCH** errors from API calls
113
+ 2. **MAP** to GeminiError using mapGeminiError()
114
+ 3. **CHECK** if retryable using isGeminiErrorRetryable()
115
+ 4. **CATEGORIZE** error type
116
+ 5. **HANDLE** appropriately (retry or fail)
117
+
118
+ ### When Validating Models
119
+ 1. **CHECK** model validity with isValidModel()
120
+ 2. **GET** safe model with getSafeModel()
121
+ 3. **DETERMINE** model category
122
+ 4. **VALIDATE** category supports feature
123
+ 5. **USE** validated model in requests
124
+
125
+ ### When Measuring Performance
126
+ 1. **WRAP** operation with measureAsync()
127
+ 2. **RECORD** duration with performanceTracker
128
+ 3. **ANALYZE** metrics periodically
129
+ 4. **IDENTIFY** slow operations
130
+ 5. **OPTIMIZE** based on data
131
+
132
+ ### When Preparing Images
133
+ 1. **VALIDATE** image source (URI or base64)
134
+ 2. **EXTRACT** base64 data if needed
135
+ 3. **DETERMINE** MIME type
136
+ 4. **PREPARE** image object
137
+ 5. **HANDLE** preparation errors
138
+
139
+ ### Code Style Rules
140
+ - **USE** appropriate utility for each task
141
+ - **VALIDATE** inputs early
142
+ - **HANDLE** all error cases
143
+ - **LOG** important operations
144
+ - **COMMENT** complex transformations
145
+
146
+ ## 📦 Available Utilities
147
+
148
+ ### Error Management
149
+
150
+ **Refer to**: [`ERROR_UTILITIES.md`](./ERROR_UTILITIES.md)
151
+
152
+ **Functions:**
153
+ - `mapGeminiError(error)` - Map error to GeminiError
154
+ - `isGeminiErrorRetryable(error)` - Check if error is retryable
155
+ - `categorizeGeminiError(error)` - Categorize error type
156
+ - `createGeminiError(error)` - Create GeminiError instance
157
+
158
+ ### Model Validation
159
+
160
+ **Refer to**: [`MODEL_VALIDATION_UTILS.md`](./MODEL_VALIDATION_UTILS.md)
161
+
162
+ **Functions:**
163
+ - `isValidModel(model)` - Check if model ID is valid
164
+ - `validateModel(model)` - Validate or throw error
165
+ - `getSafeModel(model, defaultType)` - Get safe model with fallback
166
+ - `getModelCategory(model)` - Get model category
167
+ - `getAllValidModels()` - Get all valid model IDs
168
+
169
+ ### Performance Tools
170
+
171
+ **Refer to**: [`PERFORMANCE_UTILS.md`](./PERFORMANCE_UTILS.md)
172
+
173
+ **Functions:**
174
+ - `measureAsync(operation, metadata?)` - Measure async operation
175
+ - `measureSync(operation, metadata?)` - Measure sync operation
176
+ - `debounce(func, wait)` - Create debounced function
177
+ - `throttle(func, limit)` - Create throttled function
178
+
179
+ **Classes:**
180
+ - `PerformanceTimer` - Timer for operations
181
+ - `performanceTracker` - Global performance tracker
182
+
183
+ ### Data Transformation
184
+
185
+ **Refer to**: [`DATA_TRANSFORMER_UTILS.md`](./DATA_TRANSFORMER_UTILS.md)
186
+
187
+ **Functions:**
188
+ - `extractBase64Data(base64)` - Extract base64 from data URL
189
+ - `extractTextFromResponse(response)` - Extract text from Gemini response
190
+
191
+ ### Image Preparation
192
+
193
+ **Refer to**: [`IMAGE_PREPARER_UTILS.md`](./IMAGE_PREPARER_UTILS.md)
194
+
195
+ **Functions:**
196
+ - `prepareImageFromUri(uri)` - Prepare image from URI
197
+ - `prepareImage(base64, mimeType)` - Prepare image from base64
198
+ - `isValidBase64(base64)` - Validate base64 format
199
+
200
+ ### Input Builders
201
+
202
+ **Refer to**: [`INPUT_BUILDERS.md`](./INPUT_BUILDERS.md)
203
+
204
+ **Single Image Features:**
205
+ - `buildUpscaleInput(base64, options?)` - Build upscale input
206
+ - `buildPhotoRestoreInput(base64, options?)` - Build photo restore input
207
+ - `buildRemoveBackgroundInput(base64, options?)` - Build remove background input
208
+ - `buildReplaceBackgroundInput(base64, options)` - Build replace background input
209
+
210
+ **Dual Image Features:**
211
+ - `buildFaceSwapInput(sourceBase64, targetBase64, options?)` - Build face swap input
212
+
213
+ **Video Features:**
214
+ - `buildAIHugInput(base64, options?)` - Build AI hug input
215
+ - `buildAIKissInput(base64, options?)` - Build AI kiss input
216
+ - `buildVideoFromDualImagesInput(base64a, base64b, options?)` - Build dual image video input
217
+
218
+ ## 🔗 Related Modules
219
+
220
+ - **Infrastructure README**: [`../infrastructure/README.md`](../infrastructure/README.md)
221
+ - **Services**: [`../services/README.md`](../services/README.md)
222
+ - **Domain Types**: [`../../domain/README.md`](../../domain/README.md)
223
+
224
+ ## 📋 Error Categories
225
+
226
+ ### Retryable Errors
227
+ - `QUOTA_EXCEEDED` - API quota exceeded
228
+ - `RATE_LIMIT` - Rate limit hit
229
+ - `NETWORK` - Network error
230
+ - `TIMEOUT` - Request timeout
231
+ - `SERVER` - Server error (5xx)
232
+
233
+ ### Non-Retryable Errors
234
+ - `AUTHENTICATION` - Invalid credentials
235
+ - `SAFETY` - Safety filter triggered
236
+ - `MODEL_NOT_FOUND` - Invalid model
237
+ - `VALIDATION` - Invalid request
238
+ - `UNKNOWN` - Unknown error
239
+
240
+ ## 🎓 Usage Patterns
241
+
242
+ ### Error Handling Pattern
243
+ 1. Catch API error
244
+ 2. Map to GeminiError
245
+ 3. Check if retryable
246
+ 4. Retry or fail appropriately
247
+ 5. Log error for debugging
248
+
249
+ ### Model Validation Pattern
250
+ 1. Get user input for model
251
+ 2. Validate with isValidModel()
252
+ 3. Get safe model with fallback
253
+ 4. Check model category
254
+ 5. Use validated model
255
+
256
+ ### Performance Measurement Pattern
257
+ 1. Wrap operation with measureAsync()
258
+ 2. Record duration to performanceTracker
259
+ 3. Analyze metrics periodically
260
+ 4. Identify optimization opportunities
261
+ 5. Iterate on improvements
262
+
263
+ ### Image Processing Pattern
264
+ 1. Validate image source
265
+ 2. Prepare image with utilities
266
+ 3. Build input for feature
267
+ 4. Send to image service
268
+ 5. Handle result/errors
269
+
270
+ ## 🚨 Common Pitfalls
271
+
272
+ ### Don't
273
+ - Skip model validation
274
+ - Ignore error types
275
+ - Measure too frequently (performance impact)
276
+ - Mutate input data
277
+ - Assume all models support all features
278
+
279
+ ### Do
280
+ - Always validate model IDs
281
+ - Handle all error categories
282
+ - Use debounce/throttle for frequent operations
283
+ - Keep transformations pure
284
+ - Check model capabilities
285
+
286
+ ---
287
+
288
+ **Last Updated**: 2025-01-08
289
+ **See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
@@ -0,0 +1,187 @@
1
+ # Presentation Layer
2
+
3
+ Bridge between UI layer and service layer. Contains React components and hooks for UI integration.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import { useGemini } from '@umituz/react-native-ai-gemini-provider';
9
+ ```
10
+
11
+ ## 🎯 Purpose
12
+
13
+ Use presentation layer to integrate AI functionality into React Native UI. Provides React hooks and state management.
14
+
15
+ **When to use:**
16
+ - Add AI features to React Native components
17
+ - Manage AI operation state in UI
18
+ - Handle loading and error states
19
+ - Create AI-powered user interfaces
20
+ - Build chat interfaces and forms
21
+
22
+ ## 📌 Strategy
23
+
24
+ Presentation layer abstracts service complexity. This layer:
25
+ - Provides React hooks for AI operations
26
+ - Manages loading, error, and result states
27
+ - Handles component lifecycle
28
+ - Simplifies UI integration
29
+ - Enables reactive AI interactions
30
+
31
+ **Key Decision**: Use hooks for React Native UI components. They provide clean, declarative integration with AI services.
32
+
33
+ ## ⚠️ Rules
34
+
35
+ ### Usage Rules
36
+ - **MUST** initialize provider before using hooks
37
+ - **SHOULD** use hooks only in React components
38
+ - **MUST** handle loading and error states
39
+ - **SHOULD** implement cleanup on unmount
40
+ - **MUST NOT** use hooks outside React functions
41
+
42
+ ### State Management Rules
43
+ - **SHOULD** display loading indicators
44
+ - **MUST** handle and display errors
45
+ - **SHOULD** implement success callbacks
46
+ - **MUST** reset state when appropriate
47
+ - **SHOULD NOT** ignore state changes
48
+
49
+ ### UI Integration Rules
50
+ - **MUST** provide user feedback during operations
51
+ - **SHOULD** disable controls during loading
52
+ - **MUST** handle all error states gracefully
53
+ - **SHOULD** update UI progressively
54
+ - **MUST NOT** block UI thread
55
+
56
+ ### Performance Rules
57
+ - **SHOULD** implement cleanup on unmount
58
+ - **MUST** cancel operations on unmount
59
+ - **SHOULD** use memoization where appropriate
60
+ - **MUST NOT** create memory leaks
61
+ - **SHOULD** optimize re-renders
62
+
63
+ ## 🤖 AI Agent Guidelines
64
+
65
+ ### When Modifying Presentation Layer
66
+ 1. **READ** existing hooks first
67
+ 2. **UNDERSTAND** React patterns
68
+ 3. **MAINTAIN** backward compatibility
69
+ 4. **ADD** tests for new functionality
70
+ 5. **UPDATE** documentation
71
+
72
+ ### When Adding New Hooks
73
+ 1. **CHECK** if similar hook exists
74
+ 2. **FOLLOW** existing hook patterns
75
+ 3. **USE** established state management
76
+ 4. **DOCUMENT** in hook documentation
77
+ 5. **ADD** examples to tests (not docs)
78
+
79
+ ### When Creating Components
80
+ 1. **FOLLOW** React best practices
81
+ 2. **USE** hooks for state management
82
+ 3. **HANDLE** all edge cases
83
+ 4. **PROVIDE** TypeScript types
84
+ 5. **TEST** component behavior
85
+
86
+ ### Code Style Rules
87
+ - **FOLLOW** React hooks rules
88
+ - **USE** useMemo/useCallback for optimization
89
+ - **VALIDATE** props
90
+ - **HANDLE** errors gracefully
91
+ - **COMMENT** complex logic only
92
+
93
+ ## 📦 Available Modules
94
+
95
+ ### React Hooks
96
+
97
+ **useGemini**: Main hook for AI text generation
98
+
99
+ **Refer to**: [`hooks/README.md`](./hooks/README.md)
100
+
101
+ **Files:**
102
+ - [`hooks/use-gemini.ts`](./hooks/use-gemini.ts) - Hook implementation
103
+ - [`hooks/USE_GEMINI_HOOK.md`](./hooks/USE_GEMINI_HOOK.md) - Detailed documentation
104
+
105
+ ## 🔗 Related Modules
106
+
107
+ - **Services**: [`../infrastructure/services/README.md`](../infrastructure/services/README.md)
108
+ - **Domain Types**: [`../domain/README.md`](../domain/README.md)
109
+ - **Providers**: [`../providers/README.md`](../providers/README.md)
110
+
111
+ ## 📋 Hook Features
112
+
113
+ ### State Management
114
+ - `result`: Generated content
115
+ - `isGenerating`: Loading state
116
+ - `error`: Error message
117
+ - `reset`: Clear all state
118
+
119
+ ### Methods
120
+ - `generate(prompt)`: Generate text from prompt
121
+ - `generateWithImage(prompt, image, mimeType)`: Generate with image context
122
+ - `reset()`: Clear all state
123
+
124
+ ### Configuration
125
+ - `model`: Model ID to use
126
+ - `generationConfig`: Generation parameters
127
+ - `onSuccess`: Success callback
128
+ - `onError`: Error callback
129
+
130
+ ## 🎓 Usage Patterns
131
+
132
+ ### Basic Integration
133
+ 1. Import hook in component
134
+ 2. Call `useGemini()` hook
135
+ 3. Use returned methods and state
136
+ 4. Display loading, error, and result states
137
+ 5. Handle user interactions
138
+
139
+ ### Chat Interface
140
+ 1. Use hook for AI responses
141
+ 2. Maintain messages array in state
142
+ 3. Call `generate()` on user input
143
+ 4. Update messages with result
144
+ 5. Display conversation
145
+
146
+ ### Form Integration
147
+ 1. Integrate hook with form
148
+ 2. Call generation on form submit
149
+ 3. Disable form during generation
150
+ 4. Display errors appropriately
151
+ 5. Handle success/failure
152
+
153
+ ### Image Analysis
154
+ 1. Use `generateWithImage()` method
155
+ 2. Provide base64 image data
156
+ 3. Handle loading and result states
157
+ 4. Display analysis result
158
+ 5. Handle errors
159
+
160
+ ### State Resetting
161
+ 1. Use `reset()` to clear state
162
+ 2. Implement cleanup on unmount
163
+ 3. Reset before new operations
164
+ 4. Clear previous results
165
+ 5. Handle user actions
166
+
167
+ ## 🚨 Common Pitfalls
168
+
169
+ ### Don't
170
+ - Use hooks outside React functions
171
+ - Forget to handle loading states
172
+ - Ignore error states
173
+ - Skip cleanup on unmount
174
+ - Block UI during operations
175
+
176
+ ### Do
177
+ - Always handle loading and error states
178
+ - Provide user feedback
179
+ - Implement cleanup
180
+ - Disable controls during loading
181
+ - Reset state appropriately
182
+ - Handle all edge cases
183
+
184
+ ---
185
+
186
+ **Last Updated**: 2025-01-08
187
+ **See Also**: [AI_GUIDELINES.md](../../../AI_GUIDELINES.md)
@@ -0,0 +1,188 @@
1
+ # React Hooks Overview
2
+
3
+ React hooks for integrating Gemini AI functionality into React Native applications.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import { useGemini } from '@umituz/react-native-ai-gemini-provider';
9
+ ```
10
+
11
+ ## 🎯 Purpose
12
+
13
+ Use React hooks to easily integrate Gemini AI functionality into React Native components. Provides state management for AI operations.
14
+
15
+ **When to use:**
16
+ - Add text generation to components
17
+ - Implement AI-powered features
18
+ - Handle AI state in React components
19
+ - Create chat interfaces
20
+ - Build AI-assisted forms
21
+
22
+ ## 📌 Strategy
23
+
24
+ React hooks simplify AI integration by managing state automatically. These hooks:
25
+ - Manage loading, error, and result states
26
+ - Provide callbacks for success/error handling
27
+ - Support configuration and model selection
28
+ - Handle lifecycle and cleanup
29
+ - Enable type-safe AI operations
30
+
31
+ **Key Decision**: Use hooks for React Native UI components. Use services directly for non-UI logic or complex state management needs.
32
+
33
+ ## ⚠️ Rules
34
+
35
+ ### Usage Rules
36
+ - **MUST** initialize provider before using hooks
37
+ - **SHOULD** use hooks only in React components
38
+ - **MUST** handle loading and error states
39
+ - **SHOULD** implement cleanup on unmount
40
+ - **MUST NOT** use hooks outside React functions
41
+
42
+ ### State Management Rules
43
+ - **SHOULD** display loading indicators
44
+ - **MUST** handle errors appropriately
45
+ - **SHOULD** provide user feedback
46
+ - **MUST** reset state when needed
47
+ - **SHOULD NOT** ignore error states
48
+
49
+ ### Configuration Rules
50
+ - **SHOULD** select appropriate model for use case
51
+ - **MUST** use valid model IDs
52
+ - **SHOULD** configure generation parameters appropriately
53
+ - **MUST** validate inputs before generation
54
+ - **SHOULD** implement success/error callbacks
55
+
56
+ ## 🤖 AI Agent Guidelines
57
+
58
+ ### When Modifying These Hooks
59
+ 1. **READ** the implementation file first
60
+ 2. **UNDERSTAND** React hook patterns
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 similar hook exists
67
+ 2. **FOLLOW** existing hook 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
+ - **FOLLOW** React hooks rules
81
+ - **VALIDATE** inputs at hook entry
82
+ - **HANDLE** errors gracefully
83
+ - **LOG** important operations
84
+ - **COMMENT** complex logic only
85
+
86
+ ## 📦 Available Hooks
87
+
88
+ ### `useGemini(options?)`
89
+
90
+ React hook for text and image-based generation with Gemini AI.
91
+
92
+ **Refer to**: [`use-gemini.ts`](./use-gemini.ts)
93
+
94
+ **Detailed documentation**: [`USE_GEMINI_HOOK.md`](./USE_GEMINI_HOOK.md)
95
+
96
+ ## 🔗 Related Modules
97
+
98
+ - **Text Generation Service**: [`../../infrastructure/services/TEXT_GENERATION_SERVICE.md`](../../infrastructure/services/TEXT_GENERATION_SERVICE.md)
99
+ - **Domain Types**: [`../../domain/entities/README.md`](../../domain/entities/README.md)
100
+ - **Provider Initialization**: [`../../infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md`](../../infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md)
101
+
102
+ ## 📋 Configuration Reference
103
+
104
+ ### UseGeminiOptions
105
+
106
+ Configuration options found in: [`use-gemini.ts`](./use-gemini.ts)
107
+
108
+ **Optional Fields:**
109
+ - `model`: string - Model ID to use
110
+ - `generationConfig`: object - Generation parameters
111
+ - `onSuccess`: (result: string) => void - Success callback
112
+ - `onError`: (error: string) => void - Error callback
113
+
114
+ ### Return Values
115
+
116
+ Hook returns object with:
117
+ - `generate`: (prompt: string) => Promise<void> - Start text generation
118
+ - `generateWithImage`: (prompt, imageBase64, mimeType) => Promise<void> - Start image-based generation
119
+ - `result`: string | null - Generated text
120
+ - `isGenerating`: boolean - Loading state
121
+ - `error`: string | null - Error message
122
+ - `reset`: () => void - Reset all state
123
+
124
+ ## 🎓 Usage Patterns
125
+
126
+ ### Basic Text Generation
127
+ 1. Import hook in component
128
+ 2. Call `useGemini()` hook
129
+ 3. Use `generate()` with prompt
130
+ 4. Display loading, error, and result states
131
+ 5. Handle user interactions
132
+
133
+ ### With Model Selection
134
+ 1. Import hook
135
+ 2. Call `useGemini()` with model option
136
+ 3. Select appropriate model for use case
137
+ 4. Use hook methods normally
138
+ 5. Handle responses
139
+
140
+ ### With Callbacks
141
+ 1. Import hook
142
+ 2. Configure `onSuccess` callback
143
+ 3. Configure `onError` callback
144
+ 4. Use hook for generation
145
+ 5. Handle callbacks appropriately
146
+
147
+ ### Image Analysis
148
+ 1. Import hook
149
+ 2. Use `generateWithImage()` method
150
+ 3. Provide prompt and base64 image data
151
+ 4. Handle image analysis result
152
+ 5. Display result to user
153
+
154
+ ### Chat Interface
155
+ 1. Import hook
156
+ 2. Manage messages array in component state
157
+ 3. Call `generate()` for each user message
158
+ 4. Update messages on result
159
+ 5. Display conversation
160
+
161
+ ### State Management
162
+ 1. Import hook
163
+ 2. Use `reset()` to clear state
164
+ 3. Implement cleanup on unmount
165
+ 4. Handle loading and error states
166
+ 5. Provide user feedback
167
+
168
+ ## 🚨 Common Pitfalls
169
+
170
+ ### Don't
171
+ - Use hooks outside React functions
172
+ - Forget to handle loading states
173
+ - Ignore error states
174
+ - Skip cleanup on unmount
175
+ - Use wrong model for use case
176
+
177
+ ### Do
178
+ - Always handle loading and error states
179
+ - Provide user feedback
180
+ - Implement cleanup
181
+ - Select appropriate models
182
+ - Use callbacks for side effects
183
+ - Reset state when needed
184
+
185
+ ---
186
+
187
+ **Last Updated**: 2025-01-08
188
+ **See Also**: [AI_GUIDELINES.md](../../../AI_GUIDELINES.md)