@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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Veo HTTP Client Service
|
|
2
|
+
|
|
3
|
+
Makes HTTP requests to Google Veo API for video generation. Initiates video generation operations and queries status.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { veoHttpClient } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to communicate directly with Veo API for video generation operations. Handles HTTP requests for starting and polling video generation.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Start video generation operations
|
|
17
|
+
- Query operation status
|
|
18
|
+
- Access raw Veo API responses
|
|
19
|
+
- Implement custom polling logic
|
|
20
|
+
- Debug video generation issues
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Veo API uses asynchronous operations with polling. This service:
|
|
25
|
+
- Sends HTTP requests to Veo API endpoints
|
|
26
|
+
- Initiates video generation operations
|
|
27
|
+
- Queries operation status
|
|
28
|
+
- Returns raw API responses
|
|
29
|
+
- Implements retry logic for network failures
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use `veo-polling.service.ts` for automatic polling instead of manually polling with this service. This service is for advanced use cases requiring custom polling logic.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** provide valid API key
|
|
37
|
+
- **MUST** use valid Veo model IDs
|
|
38
|
+
- **SHOULD** save operation names for polling
|
|
39
|
+
- **MUST** handle network errors appropriately
|
|
40
|
+
- **SHOULD NOT** poll manually (use polling service)
|
|
41
|
+
|
|
42
|
+
### Request Rules
|
|
43
|
+
- **MUST** provide prompt in instances array
|
|
44
|
+
- **SHOULD** set appropriate aspect ratio
|
|
45
|
+
- **MUST** use supported parameters
|
|
46
|
+
- **SHOULD** include negative prompt when needed
|
|
47
|
+
- **MUST NOT** exceed request size limits
|
|
48
|
+
|
|
49
|
+
### Error Handling Rules
|
|
50
|
+
- **MUST** catch and handle HTTP errors
|
|
51
|
+
- **SHOULD** check operation error field
|
|
52
|
+
- **MUST** validate operation responses
|
|
53
|
+
- **SHOULD** implement retry logic for failures
|
|
54
|
+
- **MUST NOT** expose API keys in errors
|
|
55
|
+
|
|
56
|
+
## 🤖 AI Agent Guidelines
|
|
57
|
+
|
|
58
|
+
### When Modifying This Service
|
|
59
|
+
1. **READ** the implementation file first
|
|
60
|
+
2. **UNDERSTAND** Veo API structure
|
|
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 feature exists in Veo API
|
|
67
|
+
2. **FOLLOW** existing request 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
|
+
- **USE** async/await (no callbacks)
|
|
81
|
+
- **VALIDATE** inputs at function entry
|
|
82
|
+
- **THROW** typed errors (`GeminiError`)
|
|
83
|
+
- **LOG** HTTP requests in development
|
|
84
|
+
- **COMMENT** complex logic only
|
|
85
|
+
|
|
86
|
+
## 📦 Available Methods
|
|
87
|
+
|
|
88
|
+
### `startOperation(model, apiKey, instances, parameters)`
|
|
89
|
+
|
|
90
|
+
Initiate video generation operation.
|
|
91
|
+
|
|
92
|
+
**Refer to**: [`veo-http-client.service.ts`](./veo-http-client.service.ts)
|
|
93
|
+
|
|
94
|
+
### `getOperation(operationName, apiKey, model)`
|
|
95
|
+
|
|
96
|
+
Query operation status.
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`veo-http-client.service.ts`](./veo-http-client.service.ts)
|
|
99
|
+
|
|
100
|
+
## 🔗 Related Modules
|
|
101
|
+
|
|
102
|
+
- **Veo Polling**: [`VEO_POLLING_SERVICE.md`](./VEO_POLLING_SERVICE.md)
|
|
103
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
104
|
+
- **Video Downloader**: [`VIDEO_DOWNLOADER_SERVICE.md`](./VIDEO_DOWNLOADER_SERVICE.md)
|
|
105
|
+
|
|
106
|
+
## 📋 Configuration Reference
|
|
107
|
+
|
|
108
|
+
### VeoOperation
|
|
109
|
+
|
|
110
|
+
Operation response structure defined in: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
111
|
+
|
|
112
|
+
**Fields:**
|
|
113
|
+
- `name`: string - Operation full path
|
|
114
|
+
- `done`: boolean - Completion status
|
|
115
|
+
- `response`: object - Video data (when complete)
|
|
116
|
+
- `metadata`: object - Progress information
|
|
117
|
+
- `error`: object - Error details (if failed)
|
|
118
|
+
|
|
119
|
+
### API Endpoints
|
|
120
|
+
|
|
121
|
+
**Start Operation:**
|
|
122
|
+
- Method: POST
|
|
123
|
+
- URL: `https://generativelanguage.googleapis.com/v1beta/models/{model}:predict`
|
|
124
|
+
- Body: `{ instances: [{ prompt: string }], parameters: { aspectRatio: string } }`
|
|
125
|
+
|
|
126
|
+
**Get Operation:**
|
|
127
|
+
- Method: GET
|
|
128
|
+
- URL: `https://generativelanguage.googleapis.com/v1beta/{operationName}`
|
|
129
|
+
|
|
130
|
+
### Model IDs
|
|
131
|
+
|
|
132
|
+
Supported Veo models: `veo-3.1-fast-generate-preview`, `veo-3.0-generate-001`
|
|
133
|
+
|
|
134
|
+
See: [`domain/constants/README.md`](../domain/constants/README.md)
|
|
135
|
+
|
|
136
|
+
## 🎓 Usage Patterns
|
|
137
|
+
|
|
138
|
+
### Start Video Generation
|
|
139
|
+
1. Import service
|
|
140
|
+
2. Call `startOperation()` with model, API key, and prompt
|
|
141
|
+
3. Save returned operation name
|
|
142
|
+
4. Use operation name for polling
|
|
143
|
+
5. Handle network errors
|
|
144
|
+
|
|
145
|
+
### Query Operation Status
|
|
146
|
+
1. Import service
|
|
147
|
+
2. Call `getOperation()` with operation name
|
|
148
|
+
3. Check `done` field for completion
|
|
149
|
+
4. Check `error` field for failures
|
|
150
|
+
5. Extract video URL from response when complete
|
|
151
|
+
|
|
152
|
+
### Custom Polling Logic
|
|
153
|
+
1. Start operation with `startOperation()`
|
|
154
|
+
2. Poll with `getOperation()` in loop
|
|
155
|
+
3. Check completion status each iteration
|
|
156
|
+
4. Handle progress updates
|
|
157
|
+
5. Exit when complete or failed
|
|
158
|
+
|
|
159
|
+
## 🚨 Common Pitfalls
|
|
160
|
+
|
|
161
|
+
### Don't
|
|
162
|
+
- Poll manually (use veo-polling.service.ts)
|
|
163
|
+
- Forget to save operation name
|
|
164
|
+
- Ignore operation error field
|
|
165
|
+
- Expose API keys in logs
|
|
166
|
+
- Poll too frequently (rate limits)
|
|
167
|
+
|
|
168
|
+
### Do
|
|
169
|
+
- Save operation name immediately
|
|
170
|
+
- Use polling service for automatic polling
|
|
171
|
+
- Check error field in responses
|
|
172
|
+
- Implement backoff between polls
|
|
173
|
+
- Handle network errors gracefully
|
|
174
|
+
- Validate API responses
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
**Last Updated**: 2025-01-08
|
|
179
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Veo Polling Service
|
|
2
|
+
|
|
3
|
+
Tracks video generation operations using polling mechanism. Regularly checks operation status until completion.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { veoPollingService } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to automatically poll video generation operations until completion. Provides progress updates and handles polling logic.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Wait for video generation to complete
|
|
17
|
+
- Track generation progress
|
|
18
|
+
- Provide progress feedback to users
|
|
19
|
+
- Handle long-running operations
|
|
20
|
+
- Implement video generation UI
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Video generation takes time and requires polling. This service:
|
|
25
|
+
- Implements automatic polling with backoff
|
|
26
|
+
- Provides progress callbacks for UI updates
|
|
27
|
+
- Handles operation completion and errors
|
|
28
|
+
- Manages polling intervals and timeouts
|
|
29
|
+
- Simplifies video generation workflow
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use this service instead of manual polling. It handles backoff, timeouts, and progress tracking automatically.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** provide valid operation name
|
|
37
|
+
- **MUST** provide API key and model ID
|
|
38
|
+
- **SHOULD** implement progress callback
|
|
39
|
+
- **MUST** handle polling completion appropriately
|
|
40
|
+
- **SHOULD NOT** implement custom polling logic
|
|
41
|
+
|
|
42
|
+
### Polling Rules
|
|
43
|
+
- **MUST** wait between polls (automatic backoff)
|
|
44
|
+
- **SHOULD** provide progress updates to users
|
|
45
|
+
- **MUST** handle operation errors
|
|
46
|
+
- **SHOULD** implement timeout for long operations
|
|
47
|
+
- **MUST NOT** poll too frequently
|
|
48
|
+
|
|
49
|
+
### Error Handling Rules
|
|
50
|
+
- **MUST** check operation error field
|
|
51
|
+
- **SHOULD** handle polling errors
|
|
52
|
+
- **MUST** throw errors on operation failure
|
|
53
|
+
- **SHOULD** provide user-friendly error messages
|
|
54
|
+
- **MUST NOT** ignore timeout errors
|
|
55
|
+
|
|
56
|
+
## 🤖 AI Agent Guidelines
|
|
57
|
+
|
|
58
|
+
### When Modifying This Service
|
|
59
|
+
1. **READ** the implementation file first
|
|
60
|
+
2. **UNDERSTAND** polling mechanism
|
|
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 feature exists
|
|
67
|
+
2. **FOLLOW** existing polling 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
|
+
- **USE** async/await (no callbacks except onProgress)
|
|
81
|
+
- **VALIDATE** inputs at function entry
|
|
82
|
+
- **THROW** typed errors (`GeminiError`)
|
|
83
|
+
- **LOG** polling operations in development
|
|
84
|
+
- **COMMENT** complex logic only
|
|
85
|
+
|
|
86
|
+
## 📦 Available Methods
|
|
87
|
+
|
|
88
|
+
### `pollOperation(operationName, apiKey, model, onProgress?)`
|
|
89
|
+
|
|
90
|
+
Poll operation until completion with progress updates.
|
|
91
|
+
|
|
92
|
+
**Refer to**: [`veo-polling.service.ts`](./veo-polling.service.ts)
|
|
93
|
+
|
|
94
|
+
## 🔗 Related Modules
|
|
95
|
+
|
|
96
|
+
- **Veo HTTP Client**: [`VEO_HTTP_CLIENT_SERVICE.md`](./VEO_HTTP_CLIENT_SERVICE.md)
|
|
97
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
98
|
+
- **Error Handler**: [`VIDEO_ERROR_HANDLER_SERVICE.md`](./VIDEO_ERROR_HANDLER_SERVICE.md)
|
|
99
|
+
|
|
100
|
+
## 📋 Configuration Reference
|
|
101
|
+
|
|
102
|
+
### Polling Strategy
|
|
103
|
+
|
|
104
|
+
**Polling Intervals:**
|
|
105
|
+
- Initial: Every 2 seconds
|
|
106
|
+
- Backoff: Gradually increases based on progress
|
|
107
|
+
- Maximum: 5 minutes total wait time
|
|
108
|
+
|
|
109
|
+
**Polling Flow:**
|
|
110
|
+
1. Start → Check status
|
|
111
|
+
2. If not complete → Wait 2s → Check again
|
|
112
|
+
3. If progress update → Call onProgress callback
|
|
113
|
+
4. If complete or error → Return result
|
|
114
|
+
5. If timeout → Throw error
|
|
115
|
+
|
|
116
|
+
### Progress Callback
|
|
117
|
+
|
|
118
|
+
Callback receives `VideoGenerationProgress` with:
|
|
119
|
+
- `status`: Operation status (queued, processing, completed, failed)
|
|
120
|
+
- `progress`: Percentage (0-100)
|
|
121
|
+
- `message`: Optional status message
|
|
122
|
+
|
|
123
|
+
## 🎓 Usage Patterns
|
|
124
|
+
|
|
125
|
+
### Basic Polling
|
|
126
|
+
1. Import service
|
|
127
|
+
2. Call `pollOperation()` with operation name from HTTP client
|
|
128
|
+
3. Wait for completion promise to resolve
|
|
129
|
+
4. Extract video URL from result
|
|
130
|
+
5. Handle errors appropriately
|
|
131
|
+
|
|
132
|
+
### With Progress Updates
|
|
133
|
+
1. Import service
|
|
134
|
+
2. Implement `onProgress` callback
|
|
135
|
+
3. Update UI with progress percentage
|
|
136
|
+
4. Display status message to user
|
|
137
|
+
5. Handle completion
|
|
138
|
+
|
|
139
|
+
### With Timeout
|
|
140
|
+
1. Calculate timeout duration
|
|
141
|
+
2. Implement timeout check in progress callback
|
|
142
|
+
3. Throw error if timeout exceeded
|
|
143
|
+
4. Handle timeout error appropriately
|
|
144
|
+
5. Provide user feedback
|
|
145
|
+
|
|
146
|
+
### React Native Integration
|
|
147
|
+
1. Create state for progress and video URL
|
|
148
|
+
2. Start polling on user action
|
|
149
|
+
3. Update state in progress callback
|
|
150
|
+
4. Display progress to user
|
|
151
|
+
5. Show video when complete
|
|
152
|
+
|
|
153
|
+
## 🚨 Common Pitfalls
|
|
154
|
+
|
|
155
|
+
### Don't
|
|
156
|
+
- Implement manual polling (use this service)
|
|
157
|
+
- Ignore progress updates (bad UX)
|
|
158
|
+
- Forget to handle errors
|
|
159
|
+
- Poll without backoff (rate limits)
|
|
160
|
+
- Block UI during polling
|
|
161
|
+
|
|
162
|
+
### Do
|
|
163
|
+
- Always use progress callbacks
|
|
164
|
+
- Update UI with progress
|
|
165
|
+
- Handle all error states
|
|
166
|
+
- Implement cancellation support
|
|
167
|
+
- Provide user feedback
|
|
168
|
+
- Use reasonable timeouts
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
**Last Updated**: 2025-01-08
|
|
173
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Video Downloader Service
|
|
2
|
+
|
|
3
|
+
Utility for downloading videos from authenticated Veo URLs and converting them to base64 data URIs. Veo URLs require authentication via the `x-goog-api-key` header.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { downloadVideoFromVeo } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use video downloader to fetch generated videos from authenticated Veo URLs. Downloads and converts videos to base64 for local use.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Download generated videos from Veo API
|
|
17
|
+
- Convert videos to base64 format
|
|
18
|
+
- Handle authenticated video URLs
|
|
19
|
+
- Prepare videos for local storage
|
|
20
|
+
- Display videos in React Native apps
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Veo URLs require authentication. This service:
|
|
25
|
+
- Adds authentication headers to requests
|
|
26
|
+
- Downloads video data
|
|
27
|
+
- Converts to base64 format
|
|
28
|
+
- Provides file metadata
|
|
29
|
+
- Handles download errors
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Always use downloader for Veo video URLs. Direct requests will fail without authentication.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Download Rules
|
|
36
|
+
- **MUST** provide valid API key
|
|
37
|
+
- **SHOULD** validate video URL format
|
|
38
|
+
- **MUST** handle download errors
|
|
39
|
+
- **SHOULD** check file size limits
|
|
40
|
+
- **MUST NOT** expose API key in errors
|
|
41
|
+
|
|
42
|
+
### Authentication Rules
|
|
43
|
+
- **MUST** include API key in headers
|
|
44
|
+
- **SHOULD** use secure storage for keys
|
|
45
|
+
- **MUST NOT** cache video URLs indefinitely
|
|
46
|
+
- **SHOULD** refresh expired URLs
|
|
47
|
+
- **MUST** handle authentication failures
|
|
48
|
+
|
|
49
|
+
### File Handling Rules
|
|
50
|
+
- **SHOULD** validate video format
|
|
51
|
+
- **MUST** handle large files
|
|
52
|
+
- **SHOULD** compress if needed
|
|
53
|
+
- **MUST** check available storage
|
|
54
|
+
- **SHOULD NOT** block main thread
|
|
55
|
+
|
|
56
|
+
### Error Handling Rules
|
|
57
|
+
- **MUST** handle network errors
|
|
58
|
+
- **SHOULD** retry on transient failures
|
|
59
|
+
- **MUST** provide clear error messages
|
|
60
|
+
- **SHOULD** log download failures
|
|
61
|
+
- **MUST NOT** lose download progress
|
|
62
|
+
|
|
63
|
+
## 🤖 AI Agent Guidelines
|
|
64
|
+
|
|
65
|
+
### When Downloading Videos
|
|
66
|
+
1. **VALIDATE** video URL
|
|
67
|
+
2. **PROVIDE** API key
|
|
68
|
+
3. **CALL** downloadVideoFromVeo()
|
|
69
|
+
4. **HANDLE** download result
|
|
70
|
+
5. **STORE** or display video
|
|
71
|
+
|
|
72
|
+
### When Handling Large Videos
|
|
73
|
+
1. **CHECK** file size before download
|
|
74
|
+
2. **WARN** user about large downloads
|
|
75
|
+
3. **IMPLEMENT** progress tracking
|
|
76
|
+
4. **HANDLE** storage constraints
|
|
77
|
+
5. **PROVIDE** cancellation option
|
|
78
|
+
|
|
79
|
+
### When Handling Errors
|
|
80
|
+
1. **CATCH** download errors
|
|
81
|
+
2. **CHECK** error type
|
|
82
|
+
3. **RETRY** if appropriate
|
|
83
|
+
4. **INFORM** user of failure
|
|
84
|
+
5. **LOG** error details
|
|
85
|
+
|
|
86
|
+
### Code Style Rules
|
|
87
|
+
- **VALIDATE** inputs before download
|
|
88
|
+
- **HANDLE** all error cases
|
|
89
|
+
- **PROVIDE** progress feedback
|
|
90
|
+
- **CLEAN UP** on failure
|
|
91
|
+
- **SECURE** API keys
|
|
92
|
+
|
|
93
|
+
## 📦 Available Function
|
|
94
|
+
|
|
95
|
+
### downloadVideoFromVeo
|
|
96
|
+
|
|
97
|
+
**Refer to**: [`gemini-video-downloader.ts`](./gemini-video-downloader.ts)
|
|
98
|
+
|
|
99
|
+
**Parameters:**
|
|
100
|
+
- `videoUrl`: string - Authenticated Veo video URL
|
|
101
|
+
- `apiKey`: string - Google Cloud API key
|
|
102
|
+
|
|
103
|
+
**Returns:** Promise<VideoDownloadResult>
|
|
104
|
+
- `base64DataUri`: string - Base64 video with data URI prefix
|
|
105
|
+
- `sizeInMB`: number - File size in megabytes
|
|
106
|
+
- `mimeType`: string - Video MIME type
|
|
107
|
+
|
|
108
|
+
## 🔗 Related Modules
|
|
109
|
+
|
|
110
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
111
|
+
- **Veo HTTP Client**: [`VEO_HTTP_CLIENT_SERVICE.md`](./VEO_HTTP_CLIENT_SERVICE.md)
|
|
112
|
+
- **Video URL Extractor**: [`VIDEO_URL_EXTRACTOR_SERVICE.md`](./VIDEO_URL_EXTRACTOR_SERVICE.md)
|
|
113
|
+
|
|
114
|
+
## 📋 Return Type
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface VideoDownloadResult {
|
|
118
|
+
base64DataUri: string; // data:video/mp4;base64,...
|
|
119
|
+
sizeInMB: number; // File size in MB
|
|
120
|
+
mimeType: string; // video/mp4 or video/webm
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 🎓 Usage Patterns
|
|
125
|
+
|
|
126
|
+
### Basic Download
|
|
127
|
+
1. Get video URL from generation response
|
|
128
|
+
2. Call downloadVideoFromVeo()
|
|
129
|
+
3. Get base64 result
|
|
130
|
+
4. Store or display video
|
|
131
|
+
5. Handle errors
|
|
132
|
+
|
|
133
|
+
### Large File Handling
|
|
134
|
+
1. Check file size before download
|
|
135
|
+
2. Warn user if large
|
|
136
|
+
3. Implement progress tracking
|
|
137
|
+
4. Download with cancellation option
|
|
138
|
+
5. Handle storage constraints
|
|
139
|
+
|
|
140
|
+
### Error Recovery
|
|
141
|
+
1. Catch download errors
|
|
142
|
+
2. Check if retryable
|
|
143
|
+
3. Retry with backoff
|
|
144
|
+
4. Inform user of failure
|
|
145
|
+
5. Provide alternative options
|
|
146
|
+
|
|
147
|
+
## 🚨 Common Pitfalls
|
|
148
|
+
|
|
149
|
+
### Don't
|
|
150
|
+
- Use direct fetch for Veo URLs
|
|
151
|
+
- Expose API key in errors
|
|
152
|
+
- Ignore file size limits
|
|
153
|
+
- Block main thread
|
|
154
|
+
- Skip error handling
|
|
155
|
+
|
|
156
|
+
### Do
|
|
157
|
+
- Always use downloader service
|
|
158
|
+
- Secure API keys properly
|
|
159
|
+
- Check file sizes
|
|
160
|
+
- Handle errors gracefully
|
|
161
|
+
- Provide user feedback
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
**Last Updated**: 2025-01-08
|
|
166
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Video Error Handler Service
|
|
2
|
+
|
|
3
|
+
Factory for creating typed video generation errors with retry information. Provides consistent error handling for video generation operations.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { createVideoError } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use video error handler to create typed errors for video generation failures. Provides consistent error handling with retry information.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Create video generation errors
|
|
17
|
+
- Determine retry behavior
|
|
18
|
+
- Handle video operation failures
|
|
19
|
+
- Provide consistent error messages
|
|
20
|
+
- Categorize error types
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Typed errors improve error handling. This service:
|
|
25
|
+
- Categorizes error types
|
|
26
|
+
- Provides retry information
|
|
27
|
+
- Creates consistent error objects
|
|
28
|
+
- Includes status codes
|
|
29
|
+
- Simplifies error handling
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Always use createVideoError for video failures. Provides consistent error handling across video operations.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Error Creation Rules
|
|
36
|
+
- **MUST** specify error type
|
|
37
|
+
- **SHOULD** provide clear messages
|
|
38
|
+
- **MUST** include context information
|
|
39
|
+
- **SHOULD** set retry flag correctly
|
|
40
|
+
- **MUST NOT** expose sensitive data
|
|
41
|
+
|
|
42
|
+
### Error Type Rules
|
|
43
|
+
- **MUST** use appropriate error type
|
|
44
|
+
- **SHOULD** distinguish retryable errors
|
|
45
|
+
- **MUST** match error to situation
|
|
46
|
+
- **SHOULD** provide status codes
|
|
47
|
+
- **MUST NOT** use unknown type unnecessarily
|
|
48
|
+
|
|
49
|
+
### Retry Rules
|
|
50
|
+
- **SHOULD** retry NETWORK errors
|
|
51
|
+
- **SHOULD** retry TIMEOUT errors
|
|
52
|
+
- **MUST NOT** retry VALIDATION errors
|
|
53
|
+
- **SHOULD NOT** retry QUOTA errors
|
|
54
|
+
- **MUST** implement backoff for retries
|
|
55
|
+
|
|
56
|
+
### Error Handling Rules
|
|
57
|
+
- **MUST** catch all video errors
|
|
58
|
+
- **SHOULD** log error details
|
|
59
|
+
- **MUST** inform user appropriately
|
|
60
|
+
- **SHOULD** provide recovery options
|
|
61
|
+
- **MUST NOT** suppress errors
|
|
62
|
+
|
|
63
|
+
## 🤖 AI Agent Guidelines
|
|
64
|
+
|
|
65
|
+
### When Creating Errors
|
|
66
|
+
1. **IDENTIFY** error type
|
|
67
|
+
2. **CREATE** error with createVideoError()
|
|
68
|
+
3. **INCLUDE** relevant context
|
|
69
|
+
4. **SET** retry flag appropriately
|
|
70
|
+
5. **THROW** or return error
|
|
71
|
+
|
|
72
|
+
### When Handling Errors
|
|
73
|
+
1. **CATCH** video generation errors
|
|
74
|
+
2. **CHECK** error type
|
|
75
|
+
3. **DETERMINE** retry eligibility
|
|
76
|
+
4. **INFORM** user appropriately
|
|
77
|
+
5. **PROVIDE** recovery options
|
|
78
|
+
|
|
79
|
+
### When Implementing Retries
|
|
80
|
+
1. **CHECK** error.retryable flag
|
|
81
|
+
2. **IMPLEMENT** exponential backoff
|
|
82
|
+
3. **SET** retry limit
|
|
83
|
+
4. **LOG** retry attempts
|
|
84
|
+
5. **FAIL** after max retries
|
|
85
|
+
|
|
86
|
+
### Code Style Rules
|
|
87
|
+
- **USE** typed error creation
|
|
88
|
+
- **PROVIDE** clear error messages
|
|
89
|
+
- **INCLUDE** relevant context
|
|
90
|
+
- **HANDLE** all error types
|
|
91
|
+
- **LOG** error information
|
|
92
|
+
|
|
93
|
+
## 📦 Available Function
|
|
94
|
+
|
|
95
|
+
### createVideoError
|
|
96
|
+
|
|
97
|
+
**Refer to**: [`gemini-video-error.ts`](./gemini-video-error.ts)
|
|
98
|
+
|
|
99
|
+
**Parameters:**
|
|
100
|
+
- `type`: VideoGenerationErrorType - Error category
|
|
101
|
+
- `message`: string - Human-readable error message
|
|
102
|
+
- `statusCode?`: number - HTTP status code
|
|
103
|
+
|
|
104
|
+
**Returns:** VideoGenerationError
|
|
105
|
+
|
|
106
|
+
## 🔗 Related Modules
|
|
107
|
+
|
|
108
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
109
|
+
- **Error Utilities**: [`../utils/ERROR_UTILITIES.md`](../utils/ERROR_UTILITIES.md)
|
|
110
|
+
- **Retry Service**: [`RETRY_SERVICE.md`](./RETRY_SERVICE.md)
|
|
111
|
+
|
|
112
|
+
## 📋 Error Types
|
|
113
|
+
|
|
114
|
+
### NETWORK
|
|
115
|
+
Network-related errors (retryable)
|
|
116
|
+
|
|
117
|
+
### TIMEOUT
|
|
118
|
+
Request timeout (retryable)
|
|
119
|
+
|
|
120
|
+
### API
|
|
121
|
+
API-level errors (may be retryable)
|
|
122
|
+
|
|
123
|
+
### VALIDATION
|
|
124
|
+
Input validation errors (not retryable)
|
|
125
|
+
|
|
126
|
+
### QUOTA
|
|
127
|
+
Quota/rate limit errors (not retryable)
|
|
128
|
+
|
|
129
|
+
### UNKNOWN
|
|
130
|
+
Uncategorized errors
|
|
131
|
+
|
|
132
|
+
### Retry Behavior
|
|
133
|
+
|
|
134
|
+
| Error Type | Retryable | Description |
|
|
135
|
+
|------------|-----------|-------------|
|
|
136
|
+
| NETWORK | Yes | Transient network issues |
|
|
137
|
+
| TIMEOUT | Yes | Request timeouts |
|
|
138
|
+
| API | Maybe | API-specific errors |
|
|
139
|
+
| VALIDATION | No | Invalid input |
|
|
140
|
+
| QUOTA | No | Rate limit exceeded |
|
|
141
|
+
| UNKNOWN | Maybe | Uncategorized errors |
|
|
142
|
+
|
|
143
|
+
## 🎓 Usage Patterns
|
|
144
|
+
|
|
145
|
+
### Error Creation
|
|
146
|
+
1. Identify error type
|
|
147
|
+
2. Call createVideoError()
|
|
148
|
+
3. Provide message and status
|
|
149
|
+
4. Include context
|
|
150
|
+
5. Throw or return error
|
|
151
|
+
|
|
152
|
+
### Error Handling
|
|
153
|
+
1. Catch video errors
|
|
154
|
+
2. Check error type
|
|
155
|
+
3. Determine retry eligibility
|
|
156
|
+
4. Handle appropriately
|
|
157
|
+
5. Inform user
|
|
158
|
+
|
|
159
|
+
### Retry Logic
|
|
160
|
+
1. Check error.retryable
|
|
161
|
+
2. Implement backoff
|
|
162
|
+
3. Set retry limit
|
|
163
|
+
4. Log attempts
|
|
164
|
+
5. Fail after max retries
|
|
165
|
+
|
|
166
|
+
## 🚨 Common Pitfalls
|
|
167
|
+
|
|
168
|
+
### Don't
|
|
169
|
+
- Use generic errors
|
|
170
|
+
- Skip error type specification
|
|
171
|
+
- Ignore retry flag
|
|
172
|
+
- Expose sensitive data
|
|
173
|
+
- Suppress errors
|
|
174
|
+
|
|
175
|
+
### Do
|
|
176
|
+
- Use typed error creation
|
|
177
|
+
- Specify error type correctly
|
|
178
|
+
- Check retry flag
|
|
179
|
+
- Provide clear messages
|
|
180
|
+
- Handle all error cases
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
**Last Updated**: 2025-01-08
|
|
185
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|