@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,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)
@@ -0,0 +1,176 @@
1
+ # Video Generation Service
2
+
3
+ Generates videos from text prompts and images using Google Veo API.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import { geminiVideoGenerationService } from '@umituz/react-native-ai-gemini-provider';
9
+ ```
10
+
11
+ ## 🎯 Purpose
12
+
13
+ Use this service to generate AI-powered videos from text descriptions or images. Supports text-to-video and image-to-video generation with progress tracking using Veo models.
14
+
15
+ **When to use:**
16
+ - Generate videos from text descriptions
17
+ - Animate existing images
18
+ - Create video content for applications
19
+ - Product visualization and motion graphics
20
+
21
+ ## 📌 Strategy
22
+
23
+ Video generation is an async, long-running operation that requires special handling. This service:
24
+ - Implements automatic polling for operation status
25
+ - Provides progress callbacks for UI feedback
26
+ - Supports multiple aspect ratios for different platforms
27
+ - Handles video download and URL generation
28
+ - Manages queuing and processing states
29
+
30
+ **Key Decision**: Video generation uses polling mechanism since processing takes time. The service automatically handles status checks and provides progress updates through callbacks.
31
+
32
+ ## ⚠️ Rules
33
+
34
+ ### Usage Rules
35
+ - **MUST** initialize provider with API key before use
36
+ - **MUST** handle async operation completion
37
+ - **SHOULD** implement progress callbacks for UX
38
+ - **MUST NOT** assume immediate results
39
+ - **MUST** handle video generation errors appropriately
40
+
41
+ ### Prompt Rules
42
+ - **SHOULD** describe motion and action clearly
43
+ - **SHOULD** specify camera movements
44
+ - **MUST NOT** exceed 2000 character limit
45
+ - **SHOULD** include atmosphere and mood details
46
+
47
+ ### Configuration Rules
48
+ - **MUST** use valid model IDs (veo-3.1-fast-generate-preview)
49
+ - **SHOULD** select appropriate aspect ratio for platform
50
+ - **MUST** respect content safety guidelines
51
+ - **SHOULD** set reasonable timeout expectations
52
+
53
+ ### Error Handling Rules
54
+ - **MUST** catch and handle `GeminiError`
55
+ - **MUST** check `result.status` for completion
56
+ - **MUST** handle `result.error` for failures
57
+ - **SHOULD** provide user-friendly error messages
58
+ - **MUST NOT** expose API keys in errors
59
+
60
+ ## 🤖 AI Agent Guidelines
61
+
62
+ ### When Modifying This Service
63
+ 1. **READ** the implementation file first
64
+ 2. **UNDERSTAND** polling mechanism
65
+ 3. **MAINTAIN** backward compatibility
66
+ 4. **ADD** tests for new functionality
67
+ 5. **UPDATE** type definitions
68
+
69
+ ### When Adding New Features
70
+ 1. **CHECK** if similar feature exists in video services
71
+ 2. **FOLLOW** existing patterns
72
+ 3. **USE** established error handling
73
+ 4. **DOCUMENT** in type definitions
74
+ 5. **ADD** examples to tests (not docs)
75
+
76
+ ### When Fixing Bugs
77
+ 1. **REPRODUCE** bug locally first
78
+ 2. **IDENTIFY** root cause
79
+ 3. **FIX** with minimal changes
80
+ 4. **ADD** regression test
81
+ 5. **VERIFY** all tests pass
82
+
83
+ ### Code Style Rules
84
+ - **USE** async/await (no callbacks except onProgress)
85
+ - **VALIDATE** inputs at function entry
86
+ - **THROW** typed errors (`GeminiError`)
87
+ - **LOG** important operations
88
+ - **COMMENT** complex logic only
89
+
90
+ ## 📦 Available Methods
91
+
92
+ ### `generateTextToVideo(input, onProgress?)`
93
+
94
+ Generate video from text prompt.
95
+
96
+ **Refer to**: [`gemini-video-generation.service.ts`](./gemini-video-generation.service.ts)
97
+
98
+ ### `generateVideo(input, onProgress?)`
99
+
100
+ Generate video from text and/or image.
101
+
102
+ **Refer to**: [`gemini-video-generation.service.ts`](./gemini-video-generation.service.ts)
103
+
104
+ ## 🔗 Related Modules
105
+
106
+ - **Domain Types**: [`domain/entities/README.md`](../domain/entities/README.md)
107
+ - **Veo HTTP Client**: [`VEO_HTTP_CLIENT_SERVICE.md`](./VEO_HTTP_CLIENT_SERVICE.md)
108
+ - **Veo Polling**: [`VEO_POLLING_SERVICE.md`](./VEO_POLLING_SERVICE.md)
109
+ - **Video Downloader**: [`VIDEO_DOWNLOADER_SERVICE.md`](./VIDEO_DOWNLOADER_SERVICE.md)
110
+ - **Video Error Handler**: [`VIDEO_ERROR_HANDLER_SERVICE.md`](./VIDEO_ERROR_HANDLER_SERVICE.md)
111
+
112
+ ## 📋 Configuration Reference
113
+
114
+ ### Generation Config
115
+ See: [`domain/entities/README.md`](../domain/entities/README.md)
116
+
117
+ ### Model Selection
118
+ - Current model: `veo-3.1-fast-generate-preview`
119
+ - Aspect ratios: `16:9` | `9:16` | `1:1` | `4:3`
120
+ - Resolution: Up to 4K
121
+ - Duration: Auto-determined by model
122
+
123
+ ### Error Types
124
+ See: [`ERROR_UTILITIES.md`](../infrastructure/utils/ERROR_UTILITIES.md)
125
+
126
+ ## 🎓 Usage Patterns
127
+
128
+ ### Basic Text-to-Video
129
+ 1. Import service
130
+ 2. Call `generateTextToVideo()` with prompt and options
131
+ 3. Provide `onProgress` callback for UI updates
132
+ 4. Handle response (contains `videoUrl`, `status`, `progress`)
133
+ 5. Display video or handle errors
134
+
135
+ ### Image-to-Video
136
+ 1. Import service
137
+ 2. Prepare base64-encoded image
138
+ 3. Call `generateVideo()` with prompt and image
139
+ 4. Monitor progress through callback
140
+ 5. Download or display result video
141
+
142
+ ### With Progress Tracking
143
+ 1. Implement progress callback function
144
+ 2. Update UI with progress percentage and status
145
+ 3. Handle status changes: queued → processing → completed/failed
146
+ 4. Show appropriate loading states
147
+ 5. Display final video or error message
148
+
149
+ ### With Negative Prompts
150
+ 1. Prepare main prompt describing desired content
151
+ 2. Add negative prompt for unwanted elements
152
+ 3. Call generation method with both prompts
153
+ 4. Handle result as normal
154
+
155
+ ## 🚨 Common Pitfalls
156
+
157
+ ### Don't
158
+ - Assume immediate video generation (takes minutes)
159
+ - Ignore progress callbacks (bad UX)
160
+ - Forget to handle failed status
161
+ - Use extremely long prompts (>2000 chars)
162
+ - Expect all videos to have same duration
163
+
164
+ ### Do
165
+ - Implement progress tracking
166
+ - Handle all status states (queued, processing, completed, failed)
167
+ - Provide loading feedback to users
168
+ - Use descriptive prompts with motion details
169
+ - Specify camera movements and atmosphere
170
+ - Handle timeouts appropriately
171
+ - Consider aspect ratio for target platform
172
+
173
+ ---
174
+
175
+ **Last Updated**: 2025-01-08
176
+ **See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
@@ -0,0 +1,186 @@
1
+ # Video URL Extractor Service
2
+
3
+ Utility for extracting video URLs from Veo API operation responses. Handles multiple response formats from different Veo API versions.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import { extractVideoUrl } from '@umituz/react-native-ai-gemini-provider';
9
+ ```
10
+
11
+ ## 🎯 Purpose
12
+
13
+ Use video URL extractor to get video URLs from Veo operation responses. Handles multiple API response formats transparently.
14
+
15
+ **When to use:**
16
+ - Extract video URLs from Veo responses
17
+ - Handle different API versions
18
+ - Parse operation results
19
+ - Get download URLs
20
+ - Process video generation responses
21
+
22
+ ## 📌 Strategy
23
+
24
+ Veo API has multiple response formats. This utility:
25
+ - Handles all response format variations
26
+ - Extracts URLs transparently
27
+ - Provides null safety
28
+ - Supports API version changes
29
+ - Simplifies response parsing
30
+
31
+ **Key Decision**: Always use extractor for Veo responses. Handles format variations automatically.
32
+
33
+ ## ⚠️ Rules
34
+
35
+ ### Extraction Rules
36
+ - **MUST** handle all response formats
37
+ - **SHOULD** validate operation object
38
+ - **MUST** return null if URL not found
39
+ - **SHOULD** log unexpected formats
40
+ - **MUST NOT** throw on missing URL
41
+
42
+ ### Validation Rules
43
+ - **SHOULD** check operation structure
44
+ - **MUST** validate URL format
45
+ - **SHOULD** handle null responses
46
+ - **MUST** verify URL accessibility
47
+ - **SHOULD NOT** assume format
48
+
49
+ ### Error Handling Rules
50
+ - **MUST** return null on failure
51
+ - **SHOULD** log parsing errors
52
+ - **MUST NOT** throw exceptions
53
+ - **SHOULD** handle malformed responses
54
+ - **MUST** provide graceful degradation
55
+
56
+ ### URL Handling Rules
57
+ - **MUST** validate URL strings
58
+ - **SHOULD** check URL scheme
59
+ - **MUST** handle authentication requirements
60
+ - **SHOULD NOT** expose sensitive data
61
+ - **MUST** preserve URL parameters
62
+
63
+ ## 🤖 AI Agent Guidelines
64
+
65
+ ### When Extracting URLs
66
+ 1. **PROVIDE** operation object
67
+ 2. **CALL** extractVideoUrl()
68
+ 3. **CHECK** return value
69
+ 4. **HANDLE** null result
70
+ 5. **USE** URL or report error
71
+
72
+ ### When Handling Missing URLs
73
+ 1. **CHECK** if result is null
74
+ 2. **LOG** response structure
75
+ 3. **VERIFY** operation completed
76
+ 4. **REPORT** error to user
77
+ 5. **PROVIDE** recovery options
78
+
79
+ ### When Validating Responses
80
+ 1. **CHECK** operation object structure
81
+ 2. **LOOK** for expected fields
82
+ 3. **HANDLE** format variations
83
+ 4. **LOG** unexpected formats
84
+ 5. **UPDATE** for new API versions
85
+
86
+ ### Code Style Rules
87
+ - **VALIDATE** input structure
88
+ - **HANDLE** all format variations
89
+ - **RETURN** null for missing URLs
90
+ - **LOG** unexpected structures
91
+ - **TEST** with various formats
92
+
93
+ ## 📦 Available Function
94
+
95
+ ### extractVideoUrl
96
+
97
+ **Refer to**: [`gemini-video-url-extractor.ts`](./gemini-video-url-extractor.ts)
98
+
99
+ **Parameters:**
100
+ - `operation`: VeoOperation - Veo operation response object
101
+
102
+ **Returns:** string | null - Video URL if found, otherwise null
103
+
104
+ ## 🔗 Related Modules
105
+
106
+ - **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
107
+ - **Video Downloader**: [`VIDEO_DOWNLOADER_SERVICE.md`](./VIDEO_DOWNLOADER_SERVICE.md)
108
+ - **Veo Polling**: [`VEO_POLLING_SERVICE.md`](./VEO_POLLING_SERVICE.md)
109
+
110
+ ## 📋 Supported Response Formats
111
+
112
+ ### Format 1: New SDK Format
113
+ ```typescript
114
+ {
115
+ response: {
116
+ generatedVideos: [{
117
+ video: { uri: "https://..." }
118
+ }]
119
+ }
120
+ }
121
+ ```
122
+
123
+ ### Format 2: Alternative SDK Format
124
+ ```typescript
125
+ {
126
+ response: {
127
+ generatedVideos: [{
128
+ uri: "https://..."
129
+ }]
130
+ }
131
+ }
132
+ ```
133
+
134
+ ### Format 3: Legacy Format
135
+ ```typescript
136
+ {
137
+ done: true,
138
+ response: {
139
+ videoUri: "https://..."
140
+ }
141
+ }
142
+ ```
143
+
144
+ ## 🎓 Usage Patterns
145
+
146
+ ### URL Extraction
147
+ 1. Get operation response
148
+ 2. Call extractVideoUrl()
149
+ 3. Check if URL exists
150
+ 4. Use URL for download
151
+ 5. Handle missing URL
152
+
153
+ ### Format Handling
154
+ 1. Provide operation object
155
+ 2. Extract URL transparently
156
+ 3. Handle any format variation
157
+ 4. Get URL or null
158
+ 5. Process result accordingly
159
+
160
+ ### Error Handling
161
+ 1. Call extractor
162
+ 2. Check for null result
163
+ 3. Log response structure if missing
164
+ 4. Report error to user
165
+ 5. Provide recovery options
166
+
167
+ ## 🚨 Common Pitfalls
168
+
169
+ ### Don't
170
+ - Assume specific response format
171
+ - Throw on missing URL
172
+ - Skip null checking
173
+ - Hardcode response paths
174
+ - Ignore format variations
175
+
176
+ ### Do
177
+ - Always check for null
178
+ - Handle all formats
179
+ - Log unexpected structures
180
+ - Return null gracefully
181
+ - Test with various responses
182
+
183
+ ---
184
+
185
+ **Last Updated**: 2025-01-08
186
+ **See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)