@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,200 @@
|
|
|
1
|
+
# Telemetry System
|
|
2
|
+
|
|
3
|
+
Monitoring and logging system for AI operations. Allows applications to track requests, responses, errors, and retries in real-time.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { telemetryHooks } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use telemetry to monitor AI operations in real-time. Provides event-based system for tracking performance, errors, and usage patterns.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Monitor API call performance
|
|
17
|
+
- Track error rates and types
|
|
18
|
+
- Analyze usage patterns
|
|
19
|
+
- Debug AI operations
|
|
20
|
+
- Send events to analytics services
|
|
21
|
+
- Track rate limiting
|
|
22
|
+
|
|
23
|
+
## 📌 Strategy
|
|
24
|
+
|
|
25
|
+
Telemetry provides visibility into AI operations. This system:
|
|
26
|
+
- Uses publish-subscribe pattern for events
|
|
27
|
+
- Supports multiple listeners simultaneously
|
|
28
|
+
- Emits events for all operations
|
|
29
|
+
- Provides timing and metadata
|
|
30
|
+
- Enables custom monitoring solutions
|
|
31
|
+
|
|
32
|
+
**Key Decision**: Subscribe to telemetry events early in application lifecycle. Use events for monitoring, analytics, and debugging.
|
|
33
|
+
|
|
34
|
+
## ⚠️ Rules
|
|
35
|
+
|
|
36
|
+
### Usage Rules
|
|
37
|
+
- **MUST** subscribe to events before operations
|
|
38
|
+
- **SHOULD** unsubscribe when done
|
|
39
|
+
- **MUST NOT** emit sensitive data in events
|
|
40
|
+
- **SHOULD** aggregate metrics for performance
|
|
41
|
+
- **MUST** handle listener errors gracefully
|
|
42
|
+
|
|
43
|
+
### Event Subscription Rules
|
|
44
|
+
- **SHOULD** subscribe at application startup
|
|
45
|
+
- **MUST** store unsubscribe function
|
|
46
|
+
- **SHOULD** handle all event types
|
|
47
|
+
- **MUST NOT** block event emission
|
|
48
|
+
- **SHOULD** filter events as needed
|
|
49
|
+
|
|
50
|
+
### Data Privacy Rules
|
|
51
|
+
- **MUST NOT** log API keys in events
|
|
52
|
+
- **SHOULD NOT** include user data in metadata
|
|
53
|
+
- **MUST** sanitize sensitive information
|
|
54
|
+
- **SHOULD** use anonymized IDs
|
|
55
|
+
- **MUST** comply with privacy policies
|
|
56
|
+
|
|
57
|
+
### Performance Rules
|
|
58
|
+
- **SHOULD** keep listeners lightweight
|
|
59
|
+
- **MUST** avoid expensive operations in listeners
|
|
60
|
+
- **SHOULD** batch event processing
|
|
61
|
+
- **MUST NOT** block main thread
|
|
62
|
+
- **SHOULD** use async operations for heavy processing
|
|
63
|
+
|
|
64
|
+
## 🤖 AI Agent Guidelines
|
|
65
|
+
|
|
66
|
+
### When Adding Telemetry
|
|
67
|
+
1. **SUBSCRIBE** to telemetry events early
|
|
68
|
+
2. **HANDLE** all event types appropriately
|
|
69
|
+
3. **AGGREGATE** metrics for analysis
|
|
70
|
+
4. **SEND** to monitoring/analytics service
|
|
71
|
+
5. **UNSUBSCRIBE** on cleanup
|
|
72
|
+
|
|
73
|
+
### When Creating Custom Monitoring
|
|
74
|
+
1. **DEFINE** metrics to track
|
|
75
|
+
2. **CREATE** data structures for aggregation
|
|
76
|
+
3. **IMPLEMENT** event filtering
|
|
77
|
+
4. **CALCULATE** statistics periodically
|
|
78
|
+
5. **EXPORT** metrics for visualization
|
|
79
|
+
|
|
80
|
+
### When Debugging with Telemetry
|
|
81
|
+
1. **ADD** verbose logging for events
|
|
82
|
+
2. **TRACK** request/response correlation
|
|
83
|
+
3. **MONITOR** error patterns
|
|
84
|
+
4. **ANALYZE** performance metrics
|
|
85
|
+
5. **IDENTIFY** bottlenecks
|
|
86
|
+
|
|
87
|
+
### Code Style Rules
|
|
88
|
+
- **USE** unsubscribe pattern for cleanup
|
|
89
|
+
- **FILTER** events by type or model
|
|
90
|
+
- **AGGREGATE** metrics efficiently
|
|
91
|
+
- **HANDLE** errors in listeners
|
|
92
|
+
- **LOG** important state changes
|
|
93
|
+
|
|
94
|
+
## 📦 Available System
|
|
95
|
+
|
|
96
|
+
### telemetryHooks
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`TelemetryHooks.ts`](./TelemetryHooks.ts)
|
|
99
|
+
|
|
100
|
+
**Singleton instance**
|
|
101
|
+
|
|
102
|
+
**Methods:**
|
|
103
|
+
- `subscribe(listener)` - Add event listener
|
|
104
|
+
- `emit(event)` - Emit custom event
|
|
105
|
+
- `logRequest(model, feature?)` - Log request start
|
|
106
|
+
- `logResponse(model, startTime, feature?, metadata?)` - Log response
|
|
107
|
+
- `logError(model, error, feature?)` - Log error
|
|
108
|
+
- `logRetry(model, attempt, feature?)` - Log retry
|
|
109
|
+
- `clear()` - Clear all listeners
|
|
110
|
+
- `getListenerCount()` - Get active listener count
|
|
111
|
+
|
|
112
|
+
## 🔗 Related Modules
|
|
113
|
+
|
|
114
|
+
- **Infrastructure README**: [`../infrastructure/README.md`](../infrastructure/README.md)
|
|
115
|
+
- **Services**: [`../services/README.md`](../services/README.md)
|
|
116
|
+
- **Interceptors**: [`../interceptors/README.md`](../interceptors/README.md)
|
|
117
|
+
|
|
118
|
+
## 📋 Event Types
|
|
119
|
+
|
|
120
|
+
### Request Event
|
|
121
|
+
Emitted when operation starts.
|
|
122
|
+
- Contains model and feature
|
|
123
|
+
- Includes timestamp
|
|
124
|
+
- No duration yet
|
|
125
|
+
|
|
126
|
+
### Response Event
|
|
127
|
+
Emitted when operation completes.
|
|
128
|
+
- Contains model and feature
|
|
129
|
+
- Includes duration in milliseconds
|
|
130
|
+
- May include metadata (token count, finish reason)
|
|
131
|
+
|
|
132
|
+
### Error Event
|
|
133
|
+
Emitted when operation fails.
|
|
134
|
+
- Contains model and feature
|
|
135
|
+
- Includes error information
|
|
136
|
+
- May include error type
|
|
137
|
+
|
|
138
|
+
### Retry Event
|
|
139
|
+
Emitted when retry is attempted.
|
|
140
|
+
- Contains model and feature
|
|
141
|
+
- Includes attempt number
|
|
142
|
+
- Tracks retry behavior
|
|
143
|
+
|
|
144
|
+
## 🎓 Usage Patterns
|
|
145
|
+
|
|
146
|
+
### Basic Monitoring
|
|
147
|
+
1. Subscribe to telemetry events
|
|
148
|
+
2. Track metrics in event handler
|
|
149
|
+
3. Send to analytics/monitoring service
|
|
150
|
+
4. Aggregate and analyze metrics
|
|
151
|
+
5. Unsubscribe when done
|
|
152
|
+
|
|
153
|
+
### Analytics Integration
|
|
154
|
+
1. Subscribe to telemetry events
|
|
155
|
+
2. Transform events to analytics format
|
|
156
|
+
3. Send to analytics service
|
|
157
|
+
4. Filter sensitive information
|
|
158
|
+
5. Handle errors gracefully
|
|
159
|
+
|
|
160
|
+
### Performance Tracking
|
|
161
|
+
1. Track response times by model
|
|
162
|
+
2. Calculate statistics (avg, min, max)
|
|
163
|
+
3. Monitor trends over time
|
|
164
|
+
4. Alert on slow operations
|
|
165
|
+
5. Generate performance reports
|
|
166
|
+
|
|
167
|
+
### Error Tracking
|
|
168
|
+
1. Subscribe to error events
|
|
169
|
+
2. Categorize errors by type
|
|
170
|
+
3. Track error rates
|
|
171
|
+
4. Send to error tracking service
|
|
172
|
+
5. Monitor for anomalies
|
|
173
|
+
|
|
174
|
+
### Custom Dashboard
|
|
175
|
+
1. Aggregate event data
|
|
176
|
+
2. Calculate statistics
|
|
177
|
+
3. Track model usage
|
|
178
|
+
4. Monitor success rates
|
|
179
|
+
5. Generate dashboard metrics
|
|
180
|
+
|
|
181
|
+
## 🚨 Common Pitfalls
|
|
182
|
+
|
|
183
|
+
### Don't
|
|
184
|
+
- Forget to unsubscribe from events
|
|
185
|
+
- Log sensitive data in events
|
|
186
|
+
- Block event emission with heavy processing
|
|
187
|
+
- Subscribe multiple times without cleanup
|
|
188
|
+
- Emit custom events without proper format
|
|
189
|
+
|
|
190
|
+
### Do
|
|
191
|
+
- Subscribe early in application lifecycle
|
|
192
|
+
- Clean up listeners when done
|
|
193
|
+
- Keep listeners lightweight
|
|
194
|
+
- Aggregate telemetry metrics
|
|
195
|
+
- Handle all event types appropriately
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
**Last Updated**: 2025-01-08
|
|
200
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Data Transformer Utilities
|
|
2
|
+
|
|
3
|
+
Helper functions for transforming and processing Gemini API data. Extracts and converts data formats.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
extractBase64Data,
|
|
10
|
+
extractTextFromResponse
|
|
11
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 🎯 Purpose
|
|
15
|
+
|
|
16
|
+
Use data transformers to extract and convert Gemini API data formats. Handles base64 extraction and text parsing.
|
|
17
|
+
|
|
18
|
+
**When to use:**
|
|
19
|
+
- Extract base64 from data URLs
|
|
20
|
+
- Parse text from API responses
|
|
21
|
+
- Clean up data formats
|
|
22
|
+
- Transform response structures
|
|
23
|
+
- Process multimodal data
|
|
24
|
+
|
|
25
|
+
## 📌 Strategy
|
|
26
|
+
|
|
27
|
+
Data transformation ensures compatibility. This system:
|
|
28
|
+
- Extracts base64 from various formats
|
|
29
|
+
- Parses text from complex responses
|
|
30
|
+
- Handles missing data gracefully
|
|
31
|
+
- Normalizes data structures
|
|
32
|
+
- Simplifies data processing
|
|
33
|
+
|
|
34
|
+
**Key Decision**: Always use transformers for data extraction. Handles edge cases and format variations automatically.
|
|
35
|
+
|
|
36
|
+
## ⚠️ Rules
|
|
37
|
+
|
|
38
|
+
### Extraction Rules
|
|
39
|
+
- **MUST** handle missing data gracefully
|
|
40
|
+
- **SHOULD** validate input format
|
|
41
|
+
- **MUST** return empty string on failure
|
|
42
|
+
- **SHOULD** log extraction errors
|
|
43
|
+
- **MUST NOT** throw on invalid data
|
|
44
|
+
|
|
45
|
+
### Format Rules
|
|
46
|
+
- **MUST** support multiple input formats
|
|
47
|
+
- **SHOULD** detect format automatically
|
|
48
|
+
- **MUST** preserve data integrity
|
|
49
|
+
- **SHOULD** handle encoding correctly
|
|
50
|
+
- **MUST NOT** corrupt data
|
|
51
|
+
|
|
52
|
+
### Validation Rules
|
|
53
|
+
- **SHOULD** validate base64 before use
|
|
54
|
+
- **MUST** check for empty responses
|
|
55
|
+
- **SHOULD** handle malformed data
|
|
56
|
+
- **MUST** provide safe defaults
|
|
57
|
+
- **SHOULD NOT** assume format
|
|
58
|
+
|
|
59
|
+
### Error Handling Rules
|
|
60
|
+
- **MUST** wrap extraction in try-catch
|
|
61
|
+
- **SHOULD** log transformation errors
|
|
62
|
+
- **MUST** return safe defaults
|
|
63
|
+
- **SHOULD NOT** propagate errors
|
|
64
|
+
- **MUST** handle all edge cases
|
|
65
|
+
|
|
66
|
+
## 🤖 AI Agent Guidelines
|
|
67
|
+
|
|
68
|
+
### When Extracting Base64
|
|
69
|
+
1. **CALL** extractBase64Data()
|
|
70
|
+
2. **PROVIDE** data URL or base64
|
|
71
|
+
3. **GET** pure base64 string
|
|
72
|
+
4. **VALIDATE** output
|
|
73
|
+
5. **HANDLE** extraction errors
|
|
74
|
+
|
|
75
|
+
### When Extracting Text
|
|
76
|
+
1. **CALL** extractTextFromResponse()
|
|
77
|
+
2. **PROVIDE** Gemini response object
|
|
78
|
+
3. **GET** concatenated text
|
|
79
|
+
4. **CHECK** for empty results
|
|
80
|
+
5. **HANDLE** missing text
|
|
81
|
+
|
|
82
|
+
### When Transforming Data
|
|
83
|
+
1. **VALIDATE** input format
|
|
84
|
+
2. **CALL** appropriate transformer
|
|
85
|
+
3. **CHECK** output validity
|
|
86
|
+
4. **USE** transformed data
|
|
87
|
+
5. **HANDLE** transformation errors
|
|
88
|
+
|
|
89
|
+
### Code Style Rules
|
|
90
|
+
- **VALIDATE** input before transformation
|
|
91
|
+
- **HANDLE** all edge cases
|
|
92
|
+
- **PROVIDE** safe defaults
|
|
93
|
+
- **LOG** transformation errors
|
|
94
|
+
- **TEST** with various formats
|
|
95
|
+
|
|
96
|
+
## 📦 Available Functions
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`gemini-data-transformer.util.ts`](./gemini-data-transformer.util.ts)
|
|
99
|
+
|
|
100
|
+
### Base64 Extraction
|
|
101
|
+
- `extractBase64Data(base64)` - Extract base64 from data URL
|
|
102
|
+
|
|
103
|
+
### Text Extraction
|
|
104
|
+
- `extractTextFromResponse(response)` - Extract text from Gemini response
|
|
105
|
+
|
|
106
|
+
## 🔗 Related Modules
|
|
107
|
+
|
|
108
|
+
- **Domain Entities**: [`../../domain/entities/README.md`](../../domain/entities/README.md)
|
|
109
|
+
- **Image Edit Service**: [`../services/IMAGE_EDIT_SERVICE.md`](../services/IMAGE_EDIT_SERVICE.md)
|
|
110
|
+
- **Response Formatter**: [`../response/RESPONSE_FORMATTER.md`](../response/RESPONSE_FORMATTER.md)
|
|
111
|
+
|
|
112
|
+
## 📋 Supported Formats
|
|
113
|
+
|
|
114
|
+
### Base64 Input Formats
|
|
115
|
+
- Data URL: `data:image/png;base64,iVBORw0KG...`
|
|
116
|
+
- Pure base64: `iVBORw0KG...`
|
|
117
|
+
- Various MIME types: PNG, JPEG, GIF, WebP
|
|
118
|
+
|
|
119
|
+
### Response Structure
|
|
120
|
+
```typescript
|
|
121
|
+
{
|
|
122
|
+
candidates: [{
|
|
123
|
+
content: {
|
|
124
|
+
parts: [
|
|
125
|
+
{ text: string },
|
|
126
|
+
{ inlineData: { mimeType: string; data: string } }
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
}]
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## 🎓 Usage Patterns
|
|
134
|
+
|
|
135
|
+
### Base64 Extraction
|
|
136
|
+
1. Provide data URL or base64
|
|
137
|
+
2. Call extractBase64Data()
|
|
138
|
+
3. Get pure base64 string
|
|
139
|
+
4. Use in API requests
|
|
140
|
+
5. Handle empty results
|
|
141
|
+
|
|
142
|
+
### Text Extraction
|
|
143
|
+
1. Provide Gemini response object
|
|
144
|
+
2. Call extractTextFromResponse()
|
|
145
|
+
3. Get concatenated text
|
|
146
|
+
4. Use extracted text
|
|
147
|
+
5. Handle empty responses
|
|
148
|
+
|
|
149
|
+
### Data Processing
|
|
150
|
+
1. Validate input format
|
|
151
|
+
2. Transform with utilities
|
|
152
|
+
3. Validate output
|
|
153
|
+
4. Use in application
|
|
154
|
+
5. Handle errors gracefully
|
|
155
|
+
|
|
156
|
+
## 🚨 Common Pitfalls
|
|
157
|
+
|
|
158
|
+
### Don't
|
|
159
|
+
- Assume data format
|
|
160
|
+
- Skip validation
|
|
161
|
+
- Throw on invalid data
|
|
162
|
+
- Ignore empty responses
|
|
163
|
+
- Corrupt data during transformation
|
|
164
|
+
|
|
165
|
+
### Do
|
|
166
|
+
- Validate input format
|
|
167
|
+
- Handle all edge cases
|
|
168
|
+
- Provide safe defaults
|
|
169
|
+
- Test with various formats
|
|
170
|
+
- Handle errors gracefully
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
**Last Updated**: 2025-01-08
|
|
175
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Error Mapper Utility
|
|
2
|
+
|
|
3
|
+
Maps Gemini API errors to standardized error types with retry information. Provides consistent error categorization.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {
|
|
9
|
+
mapGeminiError,
|
|
10
|
+
isGeminiErrorRetryable,
|
|
11
|
+
categorizeGeminiError
|
|
12
|
+
} from '@umituz/react-native-ai-gemini-provider';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 🎯 Purpose
|
|
16
|
+
|
|
17
|
+
Use error mapper to categorize and handle Gemini API errors consistently. Provides retry information and error types.
|
|
18
|
+
|
|
19
|
+
**When to use:**
|
|
20
|
+
- Categorize API errors
|
|
21
|
+
- Determine retry eligibility
|
|
22
|
+
- Handle error responses
|
|
23
|
+
- Implement retry logic
|
|
24
|
+
- Provide user feedback
|
|
25
|
+
|
|
26
|
+
## 📌 Strategy
|
|
27
|
+
|
|
28
|
+
Consistent error handling improves reliability. This utility:
|
|
29
|
+
- Maps errors to standard types
|
|
30
|
+
- Provides retry information
|
|
31
|
+
- Categorizes errors appropriately
|
|
32
|
+
- Includes status codes
|
|
33
|
+
- Simplifies error handling
|
|
34
|
+
|
|
35
|
+
**Key Decision**: Always map errors before handling. Provides consistent error information across the application.
|
|
36
|
+
|
|
37
|
+
## ⚠️ Rules
|
|
38
|
+
|
|
39
|
+
### Error Mapping Rules
|
|
40
|
+
- **MUST** map all API errors
|
|
41
|
+
- **SHOULD** check retry status
|
|
42
|
+
- **MUST** handle unknown errors
|
|
43
|
+
- **SHOULD** preserve error context
|
|
44
|
+
- **MUST NOT** expose sensitive data
|
|
45
|
+
|
|
46
|
+
### Retry Rules
|
|
47
|
+
- **SHOULD** retry retryable errors
|
|
48
|
+
- **MUST** implement backoff
|
|
49
|
+
- **SHOULD** set retry limits
|
|
50
|
+
- **MUST NOT** retry non-retryable errors
|
|
51
|
+
- **SHOULD** track retry attempts
|
|
52
|
+
|
|
53
|
+
### Categorization Rules
|
|
54
|
+
- **MUST** use correct error type
|
|
55
|
+
- **SHOULD** check error category
|
|
56
|
+
- **MUST** handle all categories
|
|
57
|
+
- **SHOULD** provide context
|
|
58
|
+
- **MUST NOT** miscategorize errors
|
|
59
|
+
|
|
60
|
+
### Error Handling Rules
|
|
61
|
+
- **MUST** catch and map errors
|
|
62
|
+
- **SHOULD** log error details
|
|
63
|
+
- **MUST** inform user appropriately
|
|
64
|
+
- **SHOULD** provide recovery options
|
|
65
|
+
- **MUST NOT** suppress errors
|
|
66
|
+
|
|
67
|
+
## 🤖 AI Agent Guidelines
|
|
68
|
+
|
|
69
|
+
### When Mapping Errors
|
|
70
|
+
1. **CATCH** API error
|
|
71
|
+
2. **CALL** mapGeminiError()
|
|
72
|
+
3. **GET** error information
|
|
73
|
+
4. **CHECK** retry status
|
|
74
|
+
5. **HANDLE** appropriately
|
|
75
|
+
|
|
76
|
+
### When Checking Retry Eligibility
|
|
77
|
+
1. **CALL** isGeminiErrorRetryable()
|
|
78
|
+
2. **CHECK** return value
|
|
79
|
+
3. **RETRY** if true
|
|
80
|
+
4. **FAIL** if false
|
|
81
|
+
5. **IMPLEMENT** backoff
|
|
82
|
+
|
|
83
|
+
### When Categorizing Errors
|
|
84
|
+
1. **CALL** categorizeGeminiError()
|
|
85
|
+
2. **GET** error type
|
|
86
|
+
3. **SWITCH** on category
|
|
87
|
+
4. **HANDLE** each case
|
|
88
|
+
5. **PROVIDE** user feedback
|
|
89
|
+
|
|
90
|
+
### Code Style Rules
|
|
91
|
+
- **MAP** all errors consistently
|
|
92
|
+
- **CHECK** retry before retrying
|
|
93
|
+
- **HANDLE** all error types
|
|
94
|
+
- **PROVIDE** clear messages
|
|
95
|
+
- **LOG** error information
|
|
96
|
+
|
|
97
|
+
## 📦 Available Functions
|
|
98
|
+
|
|
99
|
+
**Refer to**: [`error-mapper.util.ts`](./error-mapper.util.ts)
|
|
100
|
+
|
|
101
|
+
### Error Mapping
|
|
102
|
+
- `mapGeminiError(error)` - Map error to GeminiErrorInfo
|
|
103
|
+
- `isGeminiErrorRetryable(error)` - Check if error is retryable
|
|
104
|
+
- `categorizeGeminiError(error)` - Categorize error type
|
|
105
|
+
|
|
106
|
+
## 🔗 Related Modules
|
|
107
|
+
|
|
108
|
+
- **Error Utilities**: [`./ERROR_UTILITIES.md`](./ERROR_UTILITIES.md)
|
|
109
|
+
- **Retry Service**: [`../services/RETRY_SERVICE.md`](../services/RETRY_SERVICE.md)
|
|
110
|
+
- **Domain Types**: [`../../domain/README.md`](../../domain/README.md)
|
|
111
|
+
|
|
112
|
+
## 📋 Error Categories
|
|
113
|
+
|
|
114
|
+
### Retryable Errors
|
|
115
|
+
- `QUOTA_EXCEEDED` - API quota exceeded
|
|
116
|
+
- `RATE_LIMIT` - Rate limit hit
|
|
117
|
+
- `NETWORK` - Network error
|
|
118
|
+
- `TIMEOUT` - Request timeout
|
|
119
|
+
- `SERVER` - Server error (5xx)
|
|
120
|
+
|
|
121
|
+
### Non-Retryable Errors
|
|
122
|
+
- `AUTHENTICATION` - Invalid credentials
|
|
123
|
+
- `SAFETY` - Safety filter triggered
|
|
124
|
+
- `MODEL_NOT_FOUND` - Invalid model
|
|
125
|
+
- `VALIDATION` - Invalid request
|
|
126
|
+
- `UNKNOWN` - Unknown error
|
|
127
|
+
|
|
128
|
+
## 🎓 Usage Patterns
|
|
129
|
+
|
|
130
|
+
### Error Handling
|
|
131
|
+
1. Catch API error
|
|
132
|
+
2. Map to GeminiError
|
|
133
|
+
3. Check retryable status
|
|
134
|
+
4. Retry or fail appropriately
|
|
135
|
+
5. Provide user feedback
|
|
136
|
+
|
|
137
|
+
### Retry Logic
|
|
138
|
+
1. Check isGeminiErrorRetryable()
|
|
139
|
+
2. If true, implement retry
|
|
140
|
+
3. Use exponential backoff
|
|
141
|
+
4. Set retry limit
|
|
142
|
+
5. Fail after max retries
|
|
143
|
+
|
|
144
|
+
### Error Categorization
|
|
145
|
+
1. Call categorizeGeminiError()
|
|
146
|
+
2. Get error type
|
|
147
|
+
3. Switch on type
|
|
148
|
+
4. Handle each case
|
|
149
|
+
5. Provide specific feedback
|
|
150
|
+
|
|
151
|
+
## 🚨 Common Pitfalls
|
|
152
|
+
|
|
153
|
+
### Don't
|
|
154
|
+
- Skip error mapping
|
|
155
|
+
- Retry without checking
|
|
156
|
+
- Ignore error types
|
|
157
|
+
- Suppress errors
|
|
158
|
+
- Expose sensitive data
|
|
159
|
+
|
|
160
|
+
### Do
|
|
161
|
+
- Always map errors
|
|
162
|
+
- Check retry status
|
|
163
|
+
- Handle all categories
|
|
164
|
+
- Provide clear feedback
|
|
165
|
+
- Log error details
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
**Last Updated**: 2025-01-08
|
|
170
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|