@umituz/react-native-ai-gemini-provider 1.14.27 → 1.14.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/domain/README.md +232 -0
- package/src/domain/constants/README.md +191 -0
- package/src/domain/entities/README.md +238 -0
- package/src/infrastructure/README.md +252 -0
- package/src/infrastructure/cache/CACHE_SYSTEM.md +213 -0
- package/src/infrastructure/cache/README.md +213 -0
- package/src/infrastructure/content/CONTENT_BUILDER.md +175 -0
- package/src/infrastructure/content/README.md +175 -0
- package/src/infrastructure/interceptors/README.md +226 -0
- package/src/infrastructure/interceptors/REQUEST_INTERCEPTORS.md +171 -0
- package/src/infrastructure/job/JOB_MANAGER.md +174 -0
- package/src/infrastructure/job/README.md +194 -0
- package/src/infrastructure/response/README.md +187 -0
- package/src/infrastructure/response/RESPONSE_FORMATTER.md +185 -0
- package/src/infrastructure/services/CORE_CLIENT_SERVICE.md +202 -0
- package/src/infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md +206 -0
- package/src/infrastructure/services/GENERATION_EXECUTOR_SERVICE.md +176 -0
- package/src/infrastructure/services/IMAGE_EDIT_SERVICE.md +169 -0
- package/src/infrastructure/services/IMAGE_GENERATION_SERVICE.md +166 -0
- package/src/infrastructure/services/JOB_PROCESSOR_SERVICE.md +174 -0
- package/src/infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md +176 -0
- package/src/infrastructure/services/README.md +233 -0
- package/src/infrastructure/services/RETRY_SERVICE.md +178 -0
- package/src/infrastructure/services/STREAMING_SERVICE.md +166 -0
- package/src/infrastructure/services/STRUCTURED_TEXT_SERVICE.md +175 -0
- package/src/infrastructure/services/TEXT_GENERATION_SERVICE.md +160 -0
- package/src/infrastructure/services/VEO_HTTP_CLIENT_SERVICE.md +179 -0
- package/src/infrastructure/services/VEO_POLLING_SERVICE.md +173 -0
- package/src/infrastructure/services/VIDEO_DOWNLOADER_SERVICE.md +166 -0
- package/src/infrastructure/services/VIDEO_ERROR_HANDLER_SERVICE.md +185 -0
- package/src/infrastructure/services/VIDEO_GENERATION_SERVICE.md +176 -0
- package/src/infrastructure/services/VIDEO_URL_EXTRACTOR_SERVICE.md +186 -0
- package/src/infrastructure/telemetry/README.md +203 -0
- package/src/infrastructure/telemetry/TELEMETRY_SYSTEM.md +200 -0
- package/src/infrastructure/utils/DATA_TRANSFORMER_UTILS.md +175 -0
- package/src/infrastructure/utils/ERROR_MAPPER.md +170 -0
- package/src/infrastructure/utils/ERROR_UTILITIES.md +208 -0
- package/src/infrastructure/utils/IMAGE_PREPARER_UTILS.md +185 -0
- package/src/infrastructure/utils/INPUT_BUILDERS.md +214 -0
- package/src/infrastructure/utils/MODEL_VALIDATION_UTILS.md +189 -0
- package/src/infrastructure/utils/PERFORMANCE_UTILITIES.md +477 -0
- package/src/infrastructure/utils/PERFORMANCE_UTILS.md +219 -0
- package/src/infrastructure/utils/README.md +289 -0
- package/src/presentation/README.md +187 -0
- package/src/presentation/hooks/README.md +188 -0
- package/src/presentation/hooks/USE_GEMINI_HOOK.md +226 -0
- package/src/providers/README.md +247 -0
|
@@ -0,0 +1,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)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# useGemini Hook
|
|
2
|
+
|
|
3
|
+
React hook for Gemini AI text generation with image support. Provides a simple interface for generating content with loading states, error handling, and result management.
|
|
4
|
+
|
|
5
|
+
## 📍 File Path
|
|
6
|
+
|
|
7
|
+
[`use-gemini.ts`](./use-gemini.ts)
|
|
8
|
+
|
|
9
|
+
## 🎯 Purpose
|
|
10
|
+
|
|
11
|
+
Use this hook to integrate Gemini AI text generation into React Native components. Manages state and provides methods for AI operations.
|
|
12
|
+
|
|
13
|
+
**When to use:**
|
|
14
|
+
- Generate AI text in components
|
|
15
|
+
- Implement AI-powered features
|
|
16
|
+
- Create chat interfaces
|
|
17
|
+
- Build AI-assisted forms
|
|
18
|
+
- Add image analysis to UI
|
|
19
|
+
|
|
20
|
+
## 📌 Strategy
|
|
21
|
+
|
|
22
|
+
Hook abstracts complexity of AI operations. This hook:
|
|
23
|
+
- Manages loading, error, and result state
|
|
24
|
+
- Provides simple methods for generation
|
|
25
|
+
- Handles image-based generation
|
|
26
|
+
- Supports configuration and callbacks
|
|
27
|
+
- Enables easy UI integration
|
|
28
|
+
|
|
29
|
+
**Key Decision**: Use this hook for React Native UI components. It provides a clean, React-friendly interface to Gemini AI services.
|
|
30
|
+
|
|
31
|
+
## ⚠️ Rules
|
|
32
|
+
|
|
33
|
+
### Usage Rules
|
|
34
|
+
- **MUST** initialize provider before using hook
|
|
35
|
+
- **MUST** call hook only in React components
|
|
36
|
+
- **SHOULD** handle all states (loading, error, result)
|
|
37
|
+
- **MUST** provide user feedback
|
|
38
|
+
- **SHOULD NOT** use hook outside React functions
|
|
39
|
+
|
|
40
|
+
### State Management Rules
|
|
41
|
+
- **SHOULD** display loading indicators during generation
|
|
42
|
+
- **MUST** handle and display errors
|
|
43
|
+
- **SHOULD** implement success callbacks
|
|
44
|
+
- **MUST** reset state when appropriate
|
|
45
|
+
- **SHOULD** cleanup on unmount
|
|
46
|
+
|
|
47
|
+
### Configuration Rules
|
|
48
|
+
- **MUST** use valid model IDs
|
|
49
|
+
- **SHOULD** select appropriate model for use case
|
|
50
|
+
- **MUST** configure generation parameters appropriately
|
|
51
|
+
- **SHOULD** implement callbacks for side effects
|
|
52
|
+
- **MUST NOT** hardcode model IDs
|
|
53
|
+
|
|
54
|
+
## 🤖 AI Agent Guidelines
|
|
55
|
+
|
|
56
|
+
### When Modifying This Hook
|
|
57
|
+
1. **READ** the implementation file first
|
|
58
|
+
2. **UNDERSTAND** React hook patterns
|
|
59
|
+
3. **MAINTAIN** backward compatibility
|
|
60
|
+
4. **ADD** tests for new functionality
|
|
61
|
+
5. **UPDATE** type definitions
|
|
62
|
+
|
|
63
|
+
### When Adding New Features
|
|
64
|
+
1. **CHECK** if feature exists in hooks or services
|
|
65
|
+
2. **FOLLOW** existing hook patterns
|
|
66
|
+
3. **USE** established error handling
|
|
67
|
+
4. **DOCUMENT** in type definitions
|
|
68
|
+
5. **ADD** examples to tests (not docs)
|
|
69
|
+
|
|
70
|
+
### When Fixing Bugs
|
|
71
|
+
1. **REPRODUCE** bug locally first
|
|
72
|
+
2. **IDENTIFY** root cause
|
|
73
|
+
3. **FIX** with minimal changes
|
|
74
|
+
4. **ADD** regression test
|
|
75
|
+
5. **VERIFY** all tests pass
|
|
76
|
+
|
|
77
|
+
### Code Style Rules
|
|
78
|
+
- **FOLLOW** React hooks rules
|
|
79
|
+
- **USE** useMemo/useCallback for optimization
|
|
80
|
+
- **VALIDATE** inputs
|
|
81
|
+
- **HANDLE** errors gracefully
|
|
82
|
+
- **COMMENT** complex logic only
|
|
83
|
+
|
|
84
|
+
## 📦 Available Methods
|
|
85
|
+
|
|
86
|
+
### Hook Return Values
|
|
87
|
+
|
|
88
|
+
The hook returns an object with:
|
|
89
|
+
- `generate(prompt)`: Generate text from prompt
|
|
90
|
+
- `generateWithImage(prompt, imageBase64, mimeType)`: Generate with image context
|
|
91
|
+
- `result`: Generated text (null if no result)
|
|
92
|
+
- `isGenerating`: Loading state
|
|
93
|
+
- `error`: Error message (null if no error)
|
|
94
|
+
- `reset()`: Clear all state
|
|
95
|
+
|
|
96
|
+
**Refer to**: [`use-gemini.ts`](./use-gemini.ts)
|
|
97
|
+
|
|
98
|
+
## 🔗 Related Modules
|
|
99
|
+
|
|
100
|
+
- **Text Generation Service**: [`../../infrastructure/services/TEXT_GENERATION_SERVICE.md`](../../infrastructure/services/TEXT_GENERATION_SERVICE.md)
|
|
101
|
+
- **Image Edit Service**: [`../../infrastructure/services/IMAGE_EDIT_SERVICE.md`](../../infrastructure/services/IMAGE_EDIT_SERVICE.md)
|
|
102
|
+
- **Hooks Overview**: [`README.md`](./README.md)
|
|
103
|
+
|
|
104
|
+
## 📋 Configuration Reference
|
|
105
|
+
|
|
106
|
+
### UseGeminiOptions
|
|
107
|
+
|
|
108
|
+
Configuration interface found in: [`use-gemini.ts`](./use-gemini.ts)
|
|
109
|
+
|
|
110
|
+
**Options:**
|
|
111
|
+
- `model`: string - Model ID (default: 'gemini-1.5-flash')
|
|
112
|
+
- `generationConfig`: object - Generation parameters (temperature, maxTokens, etc.)
|
|
113
|
+
- `onSuccess`: (result: string) => void - Success callback
|
|
114
|
+
- `onError`: (error: string) => void - Error callback
|
|
115
|
+
|
|
116
|
+
### Model Selection
|
|
117
|
+
|
|
118
|
+
See available models in: [`../../infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md`](../../infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md)
|
|
119
|
+
|
|
120
|
+
## 🎓 Usage Patterns
|
|
121
|
+
|
|
122
|
+
### Basic Text Generation
|
|
123
|
+
1. Import hook in component
|
|
124
|
+
2. Call `useGemini()` hook
|
|
125
|
+
3. Use `generate()` method with prompt
|
|
126
|
+
4. Display `isGenerating`, `error`, and `result` states
|
|
127
|
+
5. Handle user interactions
|
|
128
|
+
|
|
129
|
+
### Custom Model
|
|
130
|
+
1. Import hook
|
|
131
|
+
2. Call `useGemini()` with model option
|
|
132
|
+
3. Select appropriate model ID
|
|
133
|
+
4. Use hook methods normally
|
|
134
|
+
5. Handle responses
|
|
135
|
+
|
|
136
|
+
### With Generation Config
|
|
137
|
+
1. Import hook
|
|
138
|
+
2. Configure `generationConfig` option
|
|
139
|
+
3. Set temperature, max tokens, etc.
|
|
140
|
+
4. Use hook for generation
|
|
141
|
+
5. Handle responses
|
|
142
|
+
|
|
143
|
+
### With Callbacks
|
|
144
|
+
1. Import hook
|
|
145
|
+
2. Implement `onSuccess` callback
|
|
146
|
+
3. Implement `onError` callback
|
|
147
|
+
4. Handle side effects in callbacks
|
|
148
|
+
5. Use hook for generation
|
|
149
|
+
|
|
150
|
+
### Image-Based Generation
|
|
151
|
+
1. Import hook
|
|
152
|
+
2. Prepare base64 image data
|
|
153
|
+
3. Call `generateWithImage()` with prompt and image
|
|
154
|
+
4. Handle loading and result states
|
|
155
|
+
5. Display result
|
|
156
|
+
|
|
157
|
+
### Form Integration
|
|
158
|
+
1. Import hook
|
|
159
|
+
2. Create form with input fields
|
|
160
|
+
3. Call generation on form submit
|
|
161
|
+
4. Display states appropriately
|
|
162
|
+
5. Handle success/error
|
|
163
|
+
|
|
164
|
+
### Chat Interface
|
|
165
|
+
1. Import hook
|
|
166
|
+
2. Maintain messages array in state
|
|
167
|
+
3. Call `generate()` for each user message
|
|
168
|
+
4. Add result to messages
|
|
169
|
+
5. Display conversation
|
|
170
|
+
|
|
171
|
+
### Error Handling
|
|
172
|
+
1. Import hook
|
|
173
|
+
2. Configure `onError` callback
|
|
174
|
+
3. Check error types in callback
|
|
175
|
+
4. Show appropriate messages
|
|
176
|
+
5. Implement retry logic
|
|
177
|
+
|
|
178
|
+
### Auto-Generate on Mount
|
|
179
|
+
1. Import hook
|
|
180
|
+
2. Use `useEffect()` hook
|
|
181
|
+
3. Call `generate()` in effect
|
|
182
|
+
4. Handle result and error
|
|
183
|
+
5. Display to user
|
|
184
|
+
|
|
185
|
+
### Retry Logic
|
|
186
|
+
1. Import hook
|
|
187
|
+
2. Implement retry counter
|
|
188
|
+
3. Call `generate()` with backoff
|
|
189
|
+
4. Track attempts
|
|
190
|
+
5. Handle final failure
|
|
191
|
+
|
|
192
|
+
### Debounced Input
|
|
193
|
+
1. Import hook
|
|
194
|
+
2. Implement debounce utility
|
|
195
|
+
3. Call debounced generation
|
|
196
|
+
4. Handle delayed results
|
|
197
|
+
5. Update UI appropriately
|
|
198
|
+
|
|
199
|
+
### Streaming Simulation
|
|
200
|
+
1. Import hook
|
|
201
|
+
2. Use `generate()` to get result
|
|
202
|
+
3. Implement streaming display effect
|
|
203
|
+
4. Update state progressively
|
|
204
|
+
5. Display to user
|
|
205
|
+
|
|
206
|
+
## 🚨 Common Pitfalls
|
|
207
|
+
|
|
208
|
+
### Don't
|
|
209
|
+
- Forget to check loading state
|
|
210
|
+
- Ignore error states
|
|
211
|
+
- Use hook outside React functions
|
|
212
|
+
- Skip cleanup on unmount
|
|
213
|
+
- Hardcode model IDs
|
|
214
|
+
|
|
215
|
+
### Do
|
|
216
|
+
- Always display loading indicator
|
|
217
|
+
- Handle all error states
|
|
218
|
+
- Implement success callbacks
|
|
219
|
+
- Reset state when needed
|
|
220
|
+
- Provide user feedback
|
|
221
|
+
- Cleanup on unmount
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
**Last Updated**: 2025-01-08
|
|
226
|
+
**See Also**: [AI_GUIDELINES.md](../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Provider Configuration
|
|
2
|
+
|
|
3
|
+
Tier-based AI provider configuration system. Manages model selection, cost optimization, and quality preferences based on subscription tier.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
providerFactory,
|
|
10
|
+
resolveProviderConfig,
|
|
11
|
+
getCostOptimizedConfig,
|
|
12
|
+
getQualityOptimizedConfig
|
|
13
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 🎯 Purpose
|
|
17
|
+
|
|
18
|
+
Use this system to configure AI provider based on subscription tier and user preferences. Automates model selection and optimization.
|
|
19
|
+
|
|
20
|
+
**When to use:**
|
|
21
|
+
- Initialize AI provider for application
|
|
22
|
+
- Configure models based on user tier
|
|
23
|
+
- Optimize costs or quality
|
|
24
|
+
- Manage runtime configuration updates
|
|
25
|
+
- Implement tier-based features
|
|
26
|
+
|
|
27
|
+
## 📌 Strategy
|
|
28
|
+
|
|
29
|
+
Different users need different configurations. This system:
|
|
30
|
+
- Selects appropriate models for subscription tier
|
|
31
|
+
- Balances cost vs quality
|
|
32
|
+
- Provides runtime configuration updates
|
|
33
|
+
- Supports optimization strategies
|
|
34
|
+
- Manages provider lifecycle
|
|
35
|
+
|
|
36
|
+
**Key Decision**: Use tier-based configuration to provide different experiences for free vs premium users while optimizing costs.
|
|
37
|
+
|
|
38
|
+
## ⚠️ Rules
|
|
39
|
+
|
|
40
|
+
### Usage Rules
|
|
41
|
+
- **MUST** initialize provider before any operations
|
|
42
|
+
- **SHOULD** select appropriate tier for user
|
|
43
|
+
- **MUST** provide valid API key
|
|
44
|
+
- **SHOULD** configure preferences appropriately
|
|
45
|
+
- **MUST NOT** reinitialize unnecessarily
|
|
46
|
+
|
|
47
|
+
### Configuration Rules
|
|
48
|
+
- **MUST** use valid subscription tier ("free" | "premium")
|
|
49
|
+
- **SHOULD** set quality preference appropriately
|
|
50
|
+
- **MUST** provide API key (required field)
|
|
51
|
+
- **SHOULD** configure retry limits
|
|
52
|
+
- **MUST NOT** use invalid model IDs
|
|
53
|
+
|
|
54
|
+
### Tier Rules
|
|
55
|
+
- **FREE tier**: Faster models, limited retries
|
|
56
|
+
- **PREMIUM tier**: Higher quality, more retries
|
|
57
|
+
- **SHOULD** match tier to user subscription
|
|
58
|
+
- **MUST** update config when tier changes
|
|
59
|
+
- **SHOULD** optimize based on tier
|
|
60
|
+
|
|
61
|
+
### Strategy Rules
|
|
62
|
+
- **COST strategy**: Cheapest models, no retries
|
|
63
|
+
- **QUALITY strategy**: Best models, more retries
|
|
64
|
+
- **BALANCED strategy**: Tier-based defaults
|
|
65
|
+
- **SHOULD** select strategy based on environment
|
|
66
|
+
- **MUST** align strategy with business goals
|
|
67
|
+
|
|
68
|
+
## 🤖 AI Agent Guidelines
|
|
69
|
+
|
|
70
|
+
### When Modifying Provider System
|
|
71
|
+
1. **READ** existing configuration code first
|
|
72
|
+
2. **UNDERSTAND** tier-based logic
|
|
73
|
+
3. **MAINTAIN** backward compatibility
|
|
74
|
+
4. **ADD** tests for new configurations
|
|
75
|
+
5. **UPDATE** documentation
|
|
76
|
+
|
|
77
|
+
### When Adding New Tiers
|
|
78
|
+
1. **CHECK** business requirements
|
|
79
|
+
2. **DEFINE** tier configuration
|
|
80
|
+
3. **UPDATE** resolution logic
|
|
81
|
+
4. **TEST** tier transitions
|
|
82
|
+
5. **DOCUMENT** tier differences
|
|
83
|
+
|
|
84
|
+
### When Adding Optimization Strategies
|
|
85
|
+
1. **ANALYZE** cost/quality tradeoffs
|
|
86
|
+
2. **DEFINE** strategy rules
|
|
87
|
+
3. **IMPLEMENT** selection logic
|
|
88
|
+
4. **TEST** strategy effectiveness
|
|
89
|
+
5. **DOCUMENT** strategy use cases
|
|
90
|
+
|
|
91
|
+
### Code Style Rules
|
|
92
|
+
- **USE** factory pattern for provider
|
|
93
|
+
- **VALIDATE** configuration inputs
|
|
94
|
+
- **THROW** typed errors for invalid config
|
|
95
|
+
- **LOG** configuration changes
|
|
96
|
+
- **COMMENT** complex logic only
|
|
97
|
+
|
|
98
|
+
## 📦 Available Functions
|
|
99
|
+
|
|
100
|
+
### `providerFactory.initialize(options)`
|
|
101
|
+
|
|
102
|
+
Initialize provider with configuration.
|
|
103
|
+
|
|
104
|
+
**Refer to**: [`ProviderFactory.ts`](./ProviderFactory.ts)
|
|
105
|
+
|
|
106
|
+
### `providerFactory.getConfig()`
|
|
107
|
+
|
|
108
|
+
Get current provider configuration.
|
|
109
|
+
|
|
110
|
+
**Refer to**: [`ProviderFactory.ts`](./ProviderFactory.ts)
|
|
111
|
+
|
|
112
|
+
### `providerFactory.isInitialized()`
|
|
113
|
+
|
|
114
|
+
Check if provider is initialized.
|
|
115
|
+
|
|
116
|
+
**Refer to**: [`ProviderFactory.ts`](./ProviderFactory.ts)
|
|
117
|
+
|
|
118
|
+
### `providerFactory.updateConfig(updates)`
|
|
119
|
+
|
|
120
|
+
Update configuration at runtime.
|
|
121
|
+
|
|
122
|
+
**Refer to**: [`ProviderFactory.ts`](./ProviderFactory.ts)
|
|
123
|
+
|
|
124
|
+
### `resolveProviderConfig(input)`
|
|
125
|
+
|
|
126
|
+
Resolve configuration based on tier and preferences.
|
|
127
|
+
|
|
128
|
+
**Refer to**: [`ProviderConfig.ts`](./ProviderConfig.ts)
|
|
129
|
+
|
|
130
|
+
### `getCostOptimizedConfig(input)`
|
|
131
|
+
|
|
132
|
+
Get cost-optimized configuration.
|
|
133
|
+
|
|
134
|
+
**Refer to**: [`ProviderConfig.ts`](./ProviderConfig.ts)
|
|
135
|
+
|
|
136
|
+
### `getQualityOptimizedConfig(input)`
|
|
137
|
+
|
|
138
|
+
Get quality-optimized configuration.
|
|
139
|
+
|
|
140
|
+
**Refer to**: [`ProviderConfig.ts`](./ProviderConfig.ts)
|
|
141
|
+
|
|
142
|
+
## 🔗 Related Modules
|
|
143
|
+
|
|
144
|
+
- **Core Client**: [`../infrastructure/services/CORE_CLIENT_SERVICE.md`](../infrastructure/services/CORE_CLIENT_SERVICE.md)
|
|
145
|
+
- **Domain Types**: [`../domain/README.md`](../domain/README.md)
|
|
146
|
+
- **Services**: [`../infrastructure/services/README.md`](../infrastructure/services/README.md)
|
|
147
|
+
|
|
148
|
+
## 📋 Configuration Reference
|
|
149
|
+
|
|
150
|
+
### Subscription Tiers
|
|
151
|
+
|
|
152
|
+
**FREE** - Free tier users
|
|
153
|
+
- Faster models (gemini-2.5-flash)
|
|
154
|
+
- Limited retries (1)
|
|
155
|
+
- Shorter timeout (30s)
|
|
156
|
+
|
|
157
|
+
**PREMIUM** - Premium tier users
|
|
158
|
+
- Higher quality models (gemini-3-pro-image)
|
|
159
|
+
- More retries (2)
|
|
160
|
+
- Longer timeout (60s)
|
|
161
|
+
|
|
162
|
+
### Quality Preferences
|
|
163
|
+
|
|
164
|
+
**FAST** - Fast responses
|
|
165
|
+
- Uses fastest models
|
|
166
|
+
|
|
167
|
+
**BALANCED** - Balanced approach
|
|
168
|
+
- Uses tier default models
|
|
169
|
+
|
|
170
|
+
**HIGH** - High quality
|
|
171
|
+
- Uses best available models
|
|
172
|
+
|
|
173
|
+
### Optimization Strategies
|
|
174
|
+
|
|
175
|
+
**COST** - Minimize cost
|
|
176
|
+
- Cheapest models only
|
|
177
|
+
- No retries
|
|
178
|
+
- Use for: Development, testing
|
|
179
|
+
|
|
180
|
+
**QUALITY** - Maximize quality
|
|
181
|
+
- Best models
|
|
182
|
+
- More retries
|
|
183
|
+
- Use for: Production, critical operations
|
|
184
|
+
|
|
185
|
+
**BALANCED** - Tier-based defaults
|
|
186
|
+
- Tier-appropriate models
|
|
187
|
+
- Standard retries
|
|
188
|
+
- Use for: General usage
|
|
189
|
+
|
|
190
|
+
## 🎓 Usage Patterns
|
|
191
|
+
|
|
192
|
+
### Basic Initialization
|
|
193
|
+
1. Import `providerFactory`
|
|
194
|
+
2. Call `initialize()` with API key and tier
|
|
195
|
+
3. Verify initialization
|
|
196
|
+
4. Use AI services normally
|
|
197
|
+
5. Handle errors appropriately
|
|
198
|
+
|
|
199
|
+
### Tier-Based Configuration
|
|
200
|
+
1. Determine user subscription tier
|
|
201
|
+
2. Initialize with appropriate tier
|
|
202
|
+
3. System selects appropriate models
|
|
203
|
+
4. User gets tier-appropriate experience
|
|
204
|
+
5. Update config when tier changes
|
|
205
|
+
|
|
206
|
+
### Runtime Updates
|
|
207
|
+
1. User upgrades/downgrades subscription
|
|
208
|
+
2. Call `updateConfig()` with new tier
|
|
209
|
+
3. Provider updates without reinitialization
|
|
210
|
+
4. New models take effect immediately
|
|
211
|
+
5. Continue operations normally
|
|
212
|
+
|
|
213
|
+
### Environment-Specific Strategy
|
|
214
|
+
1. Check environment (dev/staging/prod)
|
|
215
|
+
2. Select appropriate strategy
|
|
216
|
+
3. Initialize with strategy
|
|
217
|
+
4. Dev uses cost strategy
|
|
218
|
+
5. Prod uses quality strategy
|
|
219
|
+
|
|
220
|
+
### Preference-Based Configuration
|
|
221
|
+
1. Get user preferences from storage
|
|
222
|
+
2. Configure quality preference
|
|
223
|
+
3. Initialize with preferences
|
|
224
|
+
4. System selects models accordingly
|
|
225
|
+
5. User gets preferred experience
|
|
226
|
+
|
|
227
|
+
## 🚨 Common Pitfalls
|
|
228
|
+
|
|
229
|
+
### Don't
|
|
230
|
+
- Initialize provider multiple times
|
|
231
|
+
- Use wrong tier for user
|
|
232
|
+
- Skip API key validation
|
|
233
|
+
- Ignore tier changes
|
|
234
|
+
- Use invalid model IDs
|
|
235
|
+
|
|
236
|
+
### Do
|
|
237
|
+
- Initialize once at startup
|
|
238
|
+
- Match tier to user subscription
|
|
239
|
+
- Update config when tier changes
|
|
240
|
+
- Validate configuration
|
|
241
|
+
- Use appropriate strategies
|
|
242
|
+
- Handle initialization errors
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
**Last Updated**: 2025-01-08
|
|
247
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|