@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,226 @@
1
+ # Interceptors Module
2
+
3
+ Middleware system for transforming requests and responses. Manages authentication, logging, transformation, and other cross-cutting concerns from a central location.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import {
9
+ requestInterceptors,
10
+ responseInterceptors
11
+ } from '@umituz/react-native-ai-gemini-provider';
12
+ ```
13
+
14
+ ## 🎯 Purpose
15
+
16
+ Use interceptors to modify API requests before sending and responses after receiving. Provides centralized middleware for authentication, logging, validation, caching, and data transformation.
17
+
18
+ **When to use:**
19
+ - Add authentication headers to requests
20
+ - Log and monitor API calls
21
+ - Transform request/response data
22
+ - Implement rate limiting
23
+ - Validate payloads
24
+ - Add custom headers
25
+ - Cache responses
26
+ - Handle errors globally
27
+ - Enrich response data
28
+
29
+ ## 📌 Strategy
30
+
31
+ Interceptors provide a clean separation of concerns. This system:
32
+ - Executes request interceptors in order (first added runs first)
33
+ - Executes response interceptors in reverse order (last added runs first)
34
+ - Returns unsubscribe functions for cleanup
35
+ - Supports async interceptors
36
+ - Maintains immutability of context
37
+ - Enables composable middleware chains
38
+
39
+ **Key Decision**: Use interceptors for cross-cutting concerns. Keep business logic in services, use interceptors for operational concerns like logging, auth, and transformation.
40
+
41
+ ## ⚠️ Rules
42
+
43
+ ### Usage Rules
44
+ - **MUST** return modified context from interceptors
45
+ - **SHOULD** handle errors in interceptors gracefully
46
+ - **MUST** unsubscribe from interceptors when done
47
+ - **SHOULD NOT** block execution excessively
48
+ - **MUST** maintain execution order dependency
49
+
50
+ ### Request Interceptor Rules
51
+ - **MUST** return RequestContext object
52
+ - **SHOULD** validate inputs in interceptors
53
+ - **MUST NOT** mutate original context directly
54
+ - **SHOULD** handle async operations properly
55
+ - **MUST NOT** throw errors from interceptors
56
+
57
+ ### Response Interceptor Rules
58
+ - **MUST** return ResponseContext object
59
+ - **SHOULD** check for errors in responses
60
+ - **MUST NOT** expose sensitive data
61
+ - **SHOULD** transform data appropriately
62
+ - **MUST** handle undefined responses
63
+
64
+ ### Best Practices Rules
65
+ - **SHOULD** add logging interceptor first
66
+ - **MUST** clean up interceptors on unmount
67
+ - **SHOULD NOT** create circular dependencies
68
+ - **MUST** return new context objects
69
+ - **SHOULD** keep interceptors lightweight
70
+
71
+ ## 🤖 AI Agent Guidelines
72
+
73
+ ### When Adding Interceptors
74
+ 1. **READ** existing interceptor patterns first
75
+ 2. **UNDERSTAND** execution order (request: FIFO, response: LIFO)
76
+ 3. **IMPLEMENT** error handling
77
+ 4. **RETURN** modified context
78
+ 5. **TEST** interceptor in isolation
79
+
80
+ ### When Removing Interceptors
81
+ 1. **CALL** unsubscribe function
82
+ 2. **VERIFY** no memory leaks
83
+ 3. **UPDATE** dependent code
84
+ 4. **TEST** after removal
85
+ 5. **DOCUMENT** removal reason
86
+
87
+ ### When Debugging Interceptors
88
+ 1. **ADD** debug interceptor at start/end of chain
89
+ 2. **LOG** context before/after modifications
90
+ 3. **CHECK** execution order
91
+ 4. **VERIFY** context immutability
92
+ 5. **TEST** with various scenarios
93
+
94
+ ### Code Style Rules
95
+ - **USE** async/await for async operations
96
+ - **RETURN** new context objects (spread operator)
97
+ - **HANDLE** errors with try-catch
98
+ - **LOG** important operations
99
+ - **COMMENT** complex transformation logic
100
+
101
+ ## 📦 Available Interceptors
102
+
103
+ ### Request Interceptors
104
+
105
+ **Refer to**: [`RequestInterceptors.ts`](./RequestInterceptors.ts)
106
+
107
+ **Methods:**
108
+ - `use(interceptor)` - Add interceptor
109
+ - `apply(context)` - Apply all interceptors
110
+ - `clear()` - Clear all interceptors
111
+ - `count()` - Get interceptor count
112
+
113
+ **Execution Order:** First added runs first (FIFO)
114
+
115
+ ### Response Interceptors
116
+
117
+ **Refer to**: [`ResponseInterceptors.ts`](./ResponseInterceptors.ts)
118
+
119
+ **Methods:**
120
+ - `use(interceptor)` - Add interceptor
121
+ - `apply(context)` - Apply all interceptors
122
+ - `clear()` - Clear all interceptors
123
+ - `count()` - Get interceptor count
124
+
125
+ **Execution Order:** Last added runs first (LIFO)
126
+
127
+ ## 🔗 Related Modules
128
+
129
+ - **Infrastructure README**: [`../infrastructure/README.md`](../infrastructure/README.md)
130
+ - **Services**: [`../services/README.md`](../services/README.md)
131
+ - **Telemetry**: [`../telemetry/README.md`](../telemetry/README.md)
132
+
133
+ ## 📋 Interceptor Patterns
134
+
135
+ ### Authentication Pattern
136
+ 1. Add interceptor before operations
137
+ 2. Inject API key/token into context
138
+ 3. Return modified context
139
+ 4. Handle missing credentials
140
+ 5. Clean up interceptor when done
141
+
142
+ ### Logging Pattern
143
+ 1. Add interceptor at start of chain
144
+ 2. Log request/response details
145
+ 3. Include timing information
146
+ 4. Return context unchanged
147
+ 5. Avoid logging sensitive data
148
+
149
+ ### Transformation Pattern
150
+ 1. Add interceptor for specific transformation
151
+ 2. Extract data from context
152
+ 3. Apply transformation logic
153
+ 4. Return new context with transformed data
154
+ 5. Handle transformation errors
155
+
156
+ ### Caching Pattern
157
+ 1. Add response interceptor
158
+ 2. Check response status
159
+ 3. Cache successful responses
160
+ 4. Return context unchanged
161
+ 5. Handle cache errors gracefully
162
+
163
+ ### Validation Pattern
164
+ 1. Add request interceptor
165
+ 2. Validate context payload
166
+ 3. Check required fields
167
+ 4. Throw on validation failure
168
+ 5. Return context if valid
169
+
170
+ ## 🎓 Usage Patterns
171
+
172
+ ### Request Interception
173
+ 1. Import `requestInterceptors`
174
+ 2. Call `use()` with interceptor function
175
+ 3. Modify and return RequestContext
176
+ 4. Store unsubscribe function
177
+ 5. Call unsubscribe on cleanup
178
+
179
+ ### Response Interception
180
+ 1. Import `responseInterceptors`
181
+ 2. Call `use()` with interceptor function
182
+ 3. Modify and return ResponseContext
183
+ 4. Store unsubscribe function
184
+ 5. Call unsubscribe on cleanup
185
+
186
+ ### Chained Interceptors
187
+ 1. Add interceptors in desired order
188
+ 2. Request: First added runs first
189
+ 3. Response: Last added runs first
190
+ 4. Store all unsubscribe functions
191
+ 5. Clean up all on unmount
192
+
193
+ ### Conditional Interceptors
194
+ 1. Check environment/conditions
195
+ 2. Add interceptor only if needed
196
+ 3. Return early from interceptor if not applicable
197
+ 4. Keep conditional logic simple
198
+ 5. Test both conditional paths
199
+
200
+ ### Async Interceptors
201
+ 1. Make interceptor function async
202
+ 2. Use await for async operations
203
+ 3. Handle async errors
204
+ 4. Return modified context
205
+ 5. Test async behavior
206
+
207
+ ## 🚨 Common Pitfalls
208
+
209
+ ### Don't
210
+ - Mutate original context object
211
+ - Forget to unsubscribe from interceptors
212
+ - Block execution with heavy operations
213
+ - Throw errors from interceptors
214
+ - Create circular dependencies between interceptors
215
+
216
+ ### Do
217
+ - Return new context objects
218
+ - Clean up interceptors when done
219
+ - Keep interceptors lightweight
220
+ - Handle errors gracefully
221
+ - Follow execution order rules
222
+
223
+ ---
224
+
225
+ **Last Updated**: 2025-01-08
226
+ **See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
@@ -0,0 +1,171 @@
1
+ # Request Interceptors
2
+
3
+ Middleware system for modifying AI requests before they're sent to the API. Allows applications to add custom logic, logging, authentication, and request transformation.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import { requestInterceptors } from '@umituz/react-native-ai-gemini-provider';
9
+ ```
10
+
11
+ ## 🎯 Purpose
12
+
13
+ Use request interceptors to modify API requests before sending. Provides middleware for authentication, logging, validation, caching, and data transformation.
14
+
15
+ **When to use:**
16
+ - Add authentication headers to requests
17
+ - Log and monitor API calls
18
+ - Transform request data
19
+ - Implement rate limiting
20
+ - Validate payloads
21
+ - Add custom headers
22
+
23
+ ## 📌 Strategy
24
+
25
+ Interceptors provide clean separation of concerns. This system:
26
+ - Executes request interceptors in order
27
+ - Returns unsubscribe functions for cleanup
28
+ - Supports async interceptors
29
+ - Maintains immutability of context
30
+ - Enables composable middleware chains
31
+
32
+ **Key Decision**: Use interceptors for cross-cutting concerns. Keep business logic in services, use interceptors for operational concerns.
33
+
34
+ ## ⚠️ Rules
35
+
36
+ ### Usage Rules
37
+ - **MUST** return modified context from interceptors
38
+ - **SHOULD** handle errors in interceptors gracefully
39
+ - **MUST** unsubscribe from interceptors when done
40
+ - **SHOULD NOT** block execution excessively
41
+ - **MUST** maintain execution order dependency
42
+
43
+ ### Request Interceptor Rules
44
+ - **MUST** return RequestContext object
45
+ - **SHOULD** validate inputs in interceptors
46
+ - **MUST NOT** mutate original context directly
47
+ - **SHOULD** handle async operations properly
48
+ - **MUST NOT** throw errors from interceptors
49
+
50
+ ### Best Practices Rules
51
+ - **SHOULD** add logging interceptor first
52
+ - **MUST** clean up interceptors on unmount
53
+ - **SHOULD NOT** create circular dependencies
54
+ - **MUST** return new context objects
55
+ - **SHOULD** keep interceptors lightweight
56
+
57
+ ## 🤖 AI Agent Guidelines
58
+
59
+ ### When Adding Interceptors
60
+ 1. **READ** existing interceptor patterns first
61
+ 2. **UNDERSTAND** execution order (FIFO)
62
+ 3. **IMPLEMENT** error handling
63
+ 4. **RETURN** modified context
64
+ 5. **TEST** interceptor in isolation
65
+
66
+ ### When Removing Interceptors
67
+ 1. **CALL** unsubscribe function
68
+ 2. **VERIFY** no memory leaks
69
+ 3. **UPDATE** dependent code
70
+ 4. **TEST** after removal
71
+ 5. **DOCUMENT** removal reason
72
+
73
+ ### When Debugging Interceptors
74
+ 1. **ADD** debug interceptor at start/end of chain
75
+ 2. **LOG** context before/after modifications
76
+ 3. **CHECK** execution order
77
+ 4. **VERIFY** context immutability
78
+ 5. **TEST** with various scenarios
79
+
80
+ ### Code Style Rules
81
+ - **USE** async/await for async operations
82
+ - **RETURN** new context objects (spread operator)
83
+ - **HANDLE** errors with try-catch
84
+ - **LOG** important operations
85
+ - **COMMENT** complex transformation logic
86
+
87
+ ## 📦 Available Class
88
+
89
+ ### requestInterceptors
90
+
91
+ **Refer to**: [`RequestInterceptors.ts`](./RequestInterceptors.ts)
92
+
93
+ **Methods:**
94
+ - `use(interceptor)` - Add interceptor
95
+ - `apply(context)` - Apply all interceptors
96
+ - `clear()` - Clear all interceptors
97
+ - `count()` - Get interceptor count
98
+
99
+ **Execution Order:** First added runs first (FIFO)
100
+
101
+ ## 🔗 Related Modules
102
+
103
+ - **Response Interceptors**: [`ResponseInterceptors.ts`](./ResponseInterceptors.ts)
104
+ - **Infrastructure README**: [`../infrastructure/README.md`](../infrastructure/README.md)
105
+ - **Services**: [`../services/README.md`](../services/README.md)
106
+
107
+ ## 📋 Interceptor Patterns
108
+
109
+ ### Authentication Pattern
110
+ 1. Add interceptor before operations
111
+ 2. Inject API key/token into context
112
+ 3. Return modified context
113
+ 4. Handle missing credentials
114
+ 5. Clean up interceptor when done
115
+
116
+ ### Logging Pattern
117
+ 1. Add interceptor at start of chain
118
+ 2. Log request/response details
119
+ 3. Include timing information
120
+ 4. Return context unchanged
121
+ 5. Avoid logging sensitive data
122
+
123
+ ### Transformation Pattern
124
+ 1. Add interceptor for specific transformation
125
+ 2. Extract data from context
126
+ 3. Apply transformation logic
127
+ 4. Return new context with transformed data
128
+ 5. Handle transformation errors
129
+
130
+ ## 🎓 Usage Patterns
131
+
132
+ ### Request Interception
133
+ 1. Import `requestInterceptors`
134
+ 2. Call `use()` with interceptor function
135
+ 3. Modify and return RequestContext
136
+ 4. Store unsubscribe function
137
+ 5. Call unsubscribe on cleanup
138
+
139
+ ### Chained Interceptors
140
+ 1. Add interceptors in desired order
141
+ 2. Request: First added runs first
142
+ 3. Store all unsubscribe functions
143
+ 4. Clean up all on unmount
144
+
145
+ ### Conditional Interceptors
146
+ 1. Check environment/conditions
147
+ 2. Add interceptor only if needed
148
+ 3. Return early from interceptor if not applicable
149
+ 4. Keep conditional logic simple
150
+ 5. Test both conditional paths
151
+
152
+ ## 🚨 Common Pitfalls
153
+
154
+ ### Don't
155
+ - Mutate original context object
156
+ - Forget to unsubscribe from interceptors
157
+ - Block execution with heavy operations
158
+ - Throw errors from interceptors
159
+ - Create circular dependencies between interceptors
160
+
161
+ ### Do
162
+ - Return new context objects
163
+ - Clean up interceptors when done
164
+ - Keep interceptors lightweight
165
+ - Handle errors gracefully
166
+ - Follow execution order rules
167
+
168
+ ---
169
+
170
+ **Last Updated**: 2025-01-08
171
+ **See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
@@ -0,0 +1,174 @@
1
+ # Job Manager
2
+
3
+ Handles async job submission, tracking, and status management for AI generation tasks.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import { JobManager } from '@umituz/react-native-ai-gemini-provider';
9
+ ```
10
+
11
+ ## 🎯 Purpose
12
+
13
+ Use job manager to handle long-running AI operations asynchronously. Manages job lifecycle, status tracking, and result retrieval.
14
+
15
+ **When to use:**
16
+ - Submit long-running AI operations
17
+ - Track job status over time
18
+ - Implement polling for completion
19
+ - Manage async job lifecycles
20
+ - Retrieve results when ready
21
+
22
+ ## 📌 Strategy
23
+
24
+ Job manager abstracts async operation complexity. This system:
25
+ - Generates unique job IDs
26
+ - Tracks job status through lifecycle
27
+ - Stores results for retrieval
28
+ - Handles errors gracefully
29
+ - Supports status polling
30
+
31
+ **Key Decision**: Use job manager for video generation and other long-running operations. Poll for status instead of blocking.
32
+
33
+ ## ⚠️ Rules
34
+
35
+ ### Usage Rules
36
+ - **MUST** save job ID after submission
37
+ - **SHOULD** check job status before getting result
38
+ - **MUST** handle job completion and failure
39
+ - **SHOULD** implement polling for long operations
40
+ - **MUST NOT** lose job IDs
41
+
42
+ ### Job Lifecycle Rules
43
+ - **JOBS** start as IN_QUEUE
44
+ - **MUST** update status through lifecycle
45
+ - **SHOULD** set result or error on completion
46
+ - **MUST** handle all status transitions
47
+ - **SHOULD** clean up completed jobs
48
+
49
+ ### Error Handling Rules
50
+ - **MUST** set job error on failure
51
+ - **SHOULD** propagate errors to callers
52
+ - **MUST** handle timeout scenarios
53
+ - **SHOULD** log job failures
54
+ - **MUST NOT** leave jobs in invalid state
55
+
56
+ ### Polling Rules
57
+ - **SHOULD** poll with appropriate intervals
58
+ - **MUST** implement timeout for polling
59
+ - **SHOULD** handle polling errors
60
+ - **MUST** stop polling on completion
61
+ - **SHOULD NOT** poll too frequently
62
+
63
+ ## 🤖 AI Agent Guidelines
64
+
65
+ ### When Submitting Jobs
66
+ 1. **CALL** submitJob() with model and input
67
+ 2. **SAVE** returned job ID
68
+ 3. **TRACK** job status
69
+ 4. **HANDLE** completion/error
70
+ 5. **RETRIEVE** result when ready
71
+
72
+ ### When Polling Jobs
73
+ 1. **IMPLEMENT** polling loop with timeout
74
+ 2. **CHECK** job status each iteration
75
+ 3. **WAIT** between polls (exponential backoff)
76
+ 4. **RETURN** result on completion
77
+ 5. **THROW** on timeout or failure
78
+
79
+ ### When Managing Job Lifecycle
80
+ 1. **UPDATE** status appropriately
81
+ 2. **SET** result on success
82
+ 3. **SET** error on failure
83
+ 4. **VERIFY** state transitions
84
+ 5. **CLEAN UP** old jobs
85
+
86
+ ### Code Style Rules
87
+ - **USE** descriptive job inputs
88
+ - **HANDLE** all job status cases
89
+ - **IMPLEMENT** polling with timeout
90
+ - **LOG** job state changes
91
+ - **VALIDATE** job IDs
92
+
93
+ ## 📦 Available Class
94
+
95
+ ### JobManager
96
+
97
+ **Refer to**: [`JobManager.ts`](./JobManager.ts)
98
+
99
+ **Methods:**
100
+ - `submitJob(model, input)` - Submit new job
101
+ - `getJobStatus(requestId)` - Get job status
102
+ - `getJobResult(requestId)` - Get job result
103
+ - `updateJobStatus(requestId, status)` - Update job status
104
+ - `setJobResult(requestId, result)` - Set job result
105
+ - `setJobError(requestId, error)` - Set job error
106
+ - `getJob(requestId)` - Get job details
107
+ - `clear()` - Clear all jobs
108
+
109
+ ## 🔗 Related Modules
110
+
111
+ - **Video Generation Service**: [`../services/VIDEO_GENERATION_SERVICE.md`](../services/VIDEO_GENERATION_SERVICE.md)
112
+ - **Job Processor**: [`../services/JOB_PROCESSOR_SERVICE.md`](../services/JOB_PROCESSOR_SERVICE.md)
113
+ - **Infrastructure README**: [`../infrastructure/README.md`](../infrastructure/README.md)
114
+
115
+ ## 📋 Job Status Types
116
+
117
+ ### IN_QUEUE
118
+ Job is queued, waiting to start.
119
+
120
+ ### PROCESSING
121
+ Job is currently being processed.
122
+
123
+ ### COMPLETED
124
+ Job finished successfully with result.
125
+
126
+ ### FAILED
127
+ Job failed with error.
128
+
129
+ ### CANCELLED
130
+ Job was cancelled before completion.
131
+
132
+ ## 🎓 Usage Patterns
133
+
134
+ ### Job Submission
135
+ 1. Create JobManager instance
136
+ 2. Call submitJob() with model and input
137
+ 3. Store returned job ID
138
+ 4. Monitor job status
139
+ 5. Retrieve result when complete
140
+
141
+ ### Status Polling
142
+ 1. Submit job and get ID
143
+ 2. Poll job status periodically
144
+ 3. Check for COMPLETED or FAILED
145
+ 4. Implement timeout
146
+ 5. Return result or throw error
147
+
148
+ ### Job Lifecycle Management
149
+ 1. Submit job to manager
150
+ 2. Update status to PROCESSING
151
+ 3. Perform operation
152
+ 4. Set result or error
153
+ 5. Handle completion
154
+
155
+ ## 🚨 Common Pitfalls
156
+
157
+ ### Don't
158
+ - Lose job ID after submission
159
+ - Call getJobResult() without checking status
160
+ - Poll too frequently
161
+ - Forget to implement timeout
162
+ - Leave completed jobs in queue
163
+
164
+ ### Do
165
+ - Always save job ID
166
+ - Check status before getting result
167
+ - Use exponential backoff for polling
168
+ - Implement timeout for polling
169
+ - Clean up completed jobs
170
+
171
+ ---
172
+
173
+ **Last Updated**: 2025-01-08
174
+ **See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)