@umituz/react-native-design-system 2.8.8 → 2.8.9

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 (65) hide show
  1. package/package.json +6 -1
  2. package/src/exports/media.ts +1 -0
  3. package/src/index.ts +5 -0
  4. package/src/media/domain/entities/CardMultimedia.types.README.md +129 -0
  5. package/src/media/domain/entities/CardMultimedia.types.ts +105 -0
  6. package/src/media/domain/entities/Media.README.md +80 -0
  7. package/src/media/domain/entities/Media.ts +139 -0
  8. package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +144 -0
  9. package/src/media/domain/entities/MultimediaFlashcardTypes.ts +105 -0
  10. package/src/media/domain/utils/MediaUtils.README.md +178 -0
  11. package/src/media/domain/utils/MediaUtils.ts +82 -0
  12. package/src/media/index.ts +70 -0
  13. package/src/media/index.ts.README.md +191 -0
  14. package/src/media/infrastructure/services/CardMediaGenerationService.README.md +99 -0
  15. package/src/media/infrastructure/services/CardMediaGenerationService.ts +101 -0
  16. package/src/media/infrastructure/services/CardMediaOptimizerService.README.md +167 -0
  17. package/src/media/infrastructure/services/CardMediaOptimizerService.ts +36 -0
  18. package/src/media/infrastructure/services/CardMediaUploadService.README.md +123 -0
  19. package/src/media/infrastructure/services/CardMediaUploadService.ts +67 -0
  20. package/src/media/infrastructure/services/CardMediaValidationService.README.md +134 -0
  21. package/src/media/infrastructure/services/CardMediaValidationService.ts +81 -0
  22. package/src/media/infrastructure/services/CardMultimediaService.README.md +176 -0
  23. package/src/media/infrastructure/services/CardMultimediaService.ts +97 -0
  24. package/src/media/infrastructure/services/MediaGenerationService.README.md +142 -0
  25. package/src/media/infrastructure/services/MediaGenerationService.ts +80 -0
  26. package/src/media/infrastructure/services/MediaOptimizerService.README.md +145 -0
  27. package/src/media/infrastructure/services/MediaOptimizerService.ts +32 -0
  28. package/src/media/infrastructure/services/MediaPickerService.README.md +106 -0
  29. package/src/media/infrastructure/services/MediaPickerService.ts +173 -0
  30. package/src/media/infrastructure/services/MediaSaveService.README.md +120 -0
  31. package/src/media/infrastructure/services/MediaSaveService.ts +154 -0
  32. package/src/media/infrastructure/services/MediaUploadService.README.md +135 -0
  33. package/src/media/infrastructure/services/MediaUploadService.ts +62 -0
  34. package/src/media/infrastructure/services/MediaValidationService.README.md +135 -0
  35. package/src/media/infrastructure/services/MediaValidationService.ts +61 -0
  36. package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +142 -0
  37. package/src/media/infrastructure/services/MultimediaFlashcardService.ts +95 -0
  38. package/src/media/infrastructure/utils/mediaHelpers.README.md +96 -0
  39. package/src/media/infrastructure/utils/mediaHelpers.ts +82 -0
  40. package/src/media/infrastructure/utils/mediaPickerMappers.README.md +129 -0
  41. package/src/media/infrastructure/utils/mediaPickerMappers.ts +76 -0
  42. package/src/media/presentation/hooks/card-multimedia.types.README.md +177 -0
  43. package/src/media/presentation/hooks/card-multimedia.types.ts +51 -0
  44. package/src/media/presentation/hooks/multimedia.types.README.md +201 -0
  45. package/src/media/presentation/hooks/multimedia.types.ts +51 -0
  46. package/src/media/presentation/hooks/useCardMediaGeneration.README.md +164 -0
  47. package/src/media/presentation/hooks/useCardMediaGeneration.ts +124 -0
  48. package/src/media/presentation/hooks/useCardMediaUpload.README.md +153 -0
  49. package/src/media/presentation/hooks/useCardMediaUpload.ts +86 -0
  50. package/src/media/presentation/hooks/useCardMediaValidation.README.md +176 -0
  51. package/src/media/presentation/hooks/useCardMediaValidation.ts +101 -0
  52. package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +158 -0
  53. package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +104 -0
  54. package/src/media/presentation/hooks/useMedia.README.md +94 -0
  55. package/src/media/presentation/hooks/useMedia.ts +186 -0
  56. package/src/media/presentation/hooks/useMediaGeneration.README.md +118 -0
  57. package/src/media/presentation/hooks/useMediaGeneration.ts +101 -0
  58. package/src/media/presentation/hooks/useMediaUpload.README.md +108 -0
  59. package/src/media/presentation/hooks/useMediaUpload.ts +86 -0
  60. package/src/media/presentation/hooks/useMediaValidation.README.md +134 -0
  61. package/src/media/presentation/hooks/useMediaValidation.ts +93 -0
  62. package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +141 -0
  63. package/src/media/presentation/hooks/useMultimediaFlashcard.ts +103 -0
  64. package/src/storage/infrastructure/repositories/__tests__/AsyncStorageRepository.test.ts +1 -1
  65. package/src/storage/infrastructure/repositories/__tests__/BaseStorageOperations.test.ts +1 -1
@@ -0,0 +1,134 @@
1
+ # CardMediaValidationService
2
+
3
+ ## Purpose
4
+ Service that validates flashcard media files before upload, checking file size, type, and media-specific properties with detailed error, warning, and recommendation reporting.
5
+
6
+ ## File Location
7
+ `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMediaValidationService`
8
+
9
+ ## Strategy
10
+ - Validate media files before upload operations
11
+ - Check file size against maximum limits (50 MB hard limit)
12
+ - Validate file type compatibility (image, audio, video)
13
+ - Provide media-specific warnings (large images, long videos)
14
+ - Generate actionable recommendations for optimization
15
+ - Return structured validation results with errors, warnings, and recommendations
16
+ - Support asynchronous validation operations
17
+ - Format file sizes in human-readable format
18
+
19
+ ## Forbidden
20
+ - **DO NOT** upload files with validation errors
21
+ - **DO NOT** ignore validation warnings about performance impact
22
+ - **DO NOT** bypass validation for any media upload
23
+ - **DO NOT** allow unsupported file types
24
+ - **DO NOT** proceed when file size exceeds maximum
25
+ - **DO NOT** suppress error messages
26
+ - **DO NOT** assume all validations will pass
27
+ - **DO NOT** skip validation for "trusted" sources
28
+
29
+ ## Rules
30
+ 1. Maximum file size is 50 MB (hard error)
31
+ 2. Large file warning is triggered at 10 MB+
32
+ 3. Very large image warning is triggered at 5 MB+
33
+ 4. Long audio/video warning is triggered at 5 minutes (300 seconds)
34
+ 5. Supported image types: image/jpeg, image/png, image/webp
35
+ 6. Supported audio types: audio/mp3, audio/wav, audio/m4a
36
+ 7. Supported video types: video/mp4, video/mov
37
+ 8. Unsupported file types must return error
38
+ 9. Validation must be asynchronous operation
39
+ 10. Warnings must not block upload but inform user
40
+ 11. Recommendations must provide actionable improvement steps
41
+ 12. File size must be checked in bytes
42
+ 13. Validation result must include isValid boolean flag
43
+
44
+ ## AI Agent Guidelines
45
+
46
+ When working with CardMediaValidationService:
47
+
48
+ 1. **Always Validate**: Never upload without validation first
49
+ 2. **Check isValid**: Block upload if isValid is false
50
+ 3. **Handle Errors**: Show error messages to user and prevent upload
51
+ 4. **Show Warnings**: Display warnings but allow user to proceed
52
+ 5. **Provide Recommendations**: Show optimization suggestions
53
+ 6. **Media-Specific Checks**: Apply different rules for each media type
54
+ 7. **User Communication**: Present validation results clearly
55
+
56
+ ### Validation Workflow
57
+
58
+ - **Step 1 - Validate**: Run validation before any upload
59
+ - **Step 2 - Check Errors**: If errors exist, show and stop
60
+ - **Step 3 - Show Warnings**: Display warnings, ask user to confirm
61
+ - **Step 4 - Show Recommendations**: Present optimization suggestions
62
+ - **Step 5 - Proceed or Stop**: Allow upload if valid, stop if invalid
63
+
64
+ ### Error Handling
65
+
66
+ - **File Size Errors**:
67
+ - "File size (X MB) exceeds maximum allowed size (50 MB)"
68
+ - Must prevent upload operation
69
+ - User must reduce file size
70
+
71
+ - **File Type Errors**:
72
+ - "Unsupported file type: [type]"
73
+ - Must prevent upload operation
74
+ - User must convert to supported format
75
+
76
+ ### Warning Handling
77
+
78
+ - **Large File Warning** (10+ MB):
79
+ - "Large file size may impact performance"
80
+ - Allow upload with user confirmation
81
+ - Recommend compression
82
+
83
+ - **Large Image Warning** (5+ MB):
84
+ - "Very large image may cause performance issues"
85
+ - Allow upload with user confirmation
86
+ - Recommend resizing to under 5 MB
87
+
88
+ - **Long Content Warning** (5+ minutes):
89
+ - "Long audio/video files may impact app performance"
90
+ - Allow upload with user confirmation
91
+ - Recommend trimming to under 5 minutes
92
+
93
+ ### Recommendation Patterns
94
+
95
+ - **For Large Files**: "Consider compressing file"
96
+ - **For Large Images**: "Consider resizing image to under 5MB"
97
+ - **For Long Content**: "Consider trimming to under 5 minutes"
98
+ - **For Format**: Recommend MP3 for audio, MP4 for video
99
+ - **For Resolution**: Recommend 1920x1080 or smaller
100
+
101
+ ### Media-Specific Validation
102
+
103
+ - **Images**:
104
+ - Check MIME type against supported formats
105
+ - Warn if size > 5 MB
106
+ - Recommend JPEG for better compression
107
+ - Consider resolution checks (optional)
108
+
109
+ - **Audio**:
110
+ - Check MIME type against supported formats
111
+ - Warn if duration > 5 minutes
112
+ - Recommend MP3 format
113
+ - Consider bitrate checks (optional)
114
+
115
+ - **Video**:
116
+ - Check MIME type against supported formats
117
+ - Warn if duration > 5 minutes
118
+ - Recommend MP4 format
119
+ - Consider resolution checks (optional)
120
+
121
+ ### User Communication
122
+
123
+ - Display errors prominently (block upload)
124
+ - Show warnings with clear impact explanation
125
+ - Present recommendations as actionable steps
126
+ - Allow user to decide on warnings
127
+ - Format file sizes in MB/KB for readability
128
+ - Group messages by severity (errors, warnings, recommendations)
129
+
130
+ ## Dependencies
131
+ - CardMediaValidation type for validation results
132
+ - File size constants for limits
133
+ - MIME type validation utilities
134
+ - Media type detection helpers
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Card Media Validation Service
3
+ * Handles media file validation before upload
4
+ */
5
+
6
+ import { formatFileSize } from "../utils/mediaHelpers";
7
+ import type { CardMediaValidation } from "../../domain/entities/CardMultimedia.types";
8
+ import { getMediaDuration } from "../utils/mediaHelpers";
9
+
10
+ export class CardMediaValidationService {
11
+ /**
12
+ * Validate media file before upload
13
+ */
14
+ async validateMedia(file: any): Promise<CardMediaValidation> {
15
+ try {
16
+ const errors: string[] = [];
17
+ const warnings: string[] = [];
18
+ const recommendations: string[] = [];
19
+
20
+ // File size validation
21
+ const maxSize = 50 * 1024 * 1024; // 50MB
22
+ if (file.size > maxSize) {
23
+ errors.push(
24
+ `File size (${formatFileSize(file.size)}) exceeds maximum allowed size (${formatFileSize(maxSize)})`,
25
+ );
26
+ } else if (file.size > 10 * 1024 * 1024) {
27
+ // 10MB
28
+ warnings.push(`Large file size may impact performance`);
29
+ recommendations.push("Consider compressing file");
30
+ }
31
+
32
+ // File type validation
33
+ const supportedTypes = [
34
+ "image/jpeg",
35
+ "image/png",
36
+ "image/webp",
37
+ "audio/mp3",
38
+ "audio/wav",
39
+ "audio/m4a",
40
+ "video/mp4",
41
+ "video/mov",
42
+ ];
43
+
44
+ if (!supportedTypes.includes(file.type)) {
45
+ errors.push(`Unsupported file type: ${file.type}`);
46
+ }
47
+
48
+ // Media-specific validations
49
+ if (file.type.startsWith("image/")) {
50
+ if (file.size > 5 * 1024 * 1024) {
51
+ // 5MB for images
52
+ warnings.push("Very large image may cause performance issues");
53
+ recommendations.push("Consider resizing image to under 5MB");
54
+ }
55
+ }
56
+
57
+ if (file.type.startsWith("audio/") || file.type.startsWith("video/")) {
58
+ const duration = await getMediaDuration(file);
59
+ if (duration && duration > 300) {
60
+ // 5 minutes
61
+ warnings.push("Long audio/video files may impact app performance");
62
+ recommendations.push("Consider trimming to under 5 minutes");
63
+ }
64
+ }
65
+
66
+ return {
67
+ isValid: errors.length === 0,
68
+ errors,
69
+ warnings,
70
+ recommendations,
71
+ };
72
+ } catch (error) {
73
+ return {
74
+ isValid: false,
75
+ errors: [error instanceof Error ? error.message : "Validation failed"],
76
+ warnings: [],
77
+ recommendations: [],
78
+ };
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,176 @@
1
+ # CardMultimediaService
2
+
3
+ ## Purpose
4
+ Central service for managing all media operations in card-based applications, combining upload, generation, validation, and optimization capabilities through a singleton instance with card-specific media support.
5
+
6
+ ## File Location
7
+ `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMultimediaService`
8
+
9
+ ## Strategy
10
+ - Provide unified interface for all card media operations
11
+ - Coordinate upload, generation, validation, and optimization services
12
+ - Maintain singleton pattern for resource efficiency
13
+ - Support card-specific media requirements (front/back/both positions)
14
+ - Simplify media management for card applications
15
+ - Enable batch operations for card sets
16
+ - Provide consistent API across all media operations
17
+ - Handle card-specific metadata and associations
18
+
19
+ ## Forbidden
20
+ - **DO NOT** create multiple service instances (use singleton only)
21
+ - **DO NOT** call media operations without validation
22
+ - **DO NOT** assume AI generation is always available
23
+ - **DO NOT** ignore optimization recommendations
24
+ - **DO NOT** bypass singleton pattern with direct service instantiation
25
+ - **DO NOT** proceed without error handling for any operation
26
+ - **DO NOT** mix card media with non-card media types
27
+ - **DO NOT** assume all operations will succeed
28
+ - **DO NOT** ignore card-specific position requirements
29
+
30
+ ## Rules
31
+ 1. MUST use getInstance() to retrieve service instance
32
+ 2. MUST NOT create new instances with constructor
33
+ 3. MUST maintain single instance across application lifecycle
34
+ 4. MUST validate media before upload operations
35
+ 5. MUST support CardMediaAttachment and CardMediaPosition types
36
+ 6. MUST handle position attribute (front/back/both) correctly
37
+ 7. MUST handle all operation failures gracefully
38
+ 8. MUST provide consistent interface through all methods
39
+ 9. MUST initialize all sub-services on first use
40
+ 10. MUST coordinate between sub-services for complex operations
41
+ 11. MUST handle asynchronous operations properly
42
+ 12. MUST return appropriate error messages for failures
43
+ 13. MUST support card-specific media constraints
44
+
45
+ ## AI Agent Guidelines
46
+
47
+ When working with CardMultimediaService:
48
+
49
+ 1. **Singleton Pattern**: Always use getInstance(), never constructor
50
+ 2. **Validation First**: Validate before upload or generation
51
+ 3. **Position Awareness**: Always consider card position (front/back/both)
52
+ 4. **Operation Flow**: Follow validate -> upload/generate -> optimize -> store
53
+ 5. **Error Handling**: Handle errors at each step appropriately
54
+ 6. **Resource Management**: Rely on singleton for efficient resource use
55
+ 7. **Type Safety**: Use CardMediaAttachment and CardMediaPosition types
56
+ 8. **Card Context**: Maintain card-specific context throughout operations
57
+
58
+ ### Card Creation Workflow
59
+
60
+ - **Step 1 - Get Instance**: `CardMultimediaService.getInstance()`
61
+ - **Step 2 - Select File**: Pick file from device or camera
62
+ - **Step 3 - Validate**: Run validation, check results
63
+ - **Step 4 - Upload**: Upload if validation passes
64
+ - **Step 5 - Set Position**: Assign position (front/back/both)
65
+ - **Step 6 - Optimize** (Optional): Optimize if file is large
66
+ - **Step 7 - Store**: Save attachment with card data
67
+ - **Step 8 - Handle Errors**: Provide feedback at each step
68
+
69
+ ### Media Upload with Position
70
+
71
+ - Use for user-selected media on card sides
72
+ - Always validate before uploading
73
+ - Set position based on card side (front/back/both)
74
+ - Consider compression for large files
75
+ - Store returned attachment with card
76
+ - Handle upload failures with user feedback
77
+
78
+ ### AI Content Generation for Cards
79
+
80
+ - Use for text-to-image or text-to-audio generation
81
+ - Validate prompts before generation
82
+ - Check credit/balance availability
83
+ - Set position based on use case (front for questions, back for answers)
84
+ - Handle generation failures gracefully
85
+ - Store successful attachments with card
86
+
87
+ ### Position Management
88
+
89
+ - **Front**: Media displayed on card front side
90
+ - Typically contains questions or prompts
91
+ - Often uses text-to-image generation
92
+ - May require higher quality
93
+
94
+ - **Back**: Media displayed on card back side
95
+ - Typically contains answers or explanations
96
+ - Often uses text-to-audio generation
97
+ - Can be more compressed
98
+
99
+ - **Both**: Media used on both sides
100
+ - Shared content between sides
101
+ - Less common but supported
102
+ - Maintain consistency across sides
103
+
104
+ ### Media Optimization for Cards
105
+
106
+ - Use when file size impacts performance
107
+ - Choose quality level based on position (front = higher, back = lower)
108
+ - Consider card importance and frequency of use
109
+ - Calculate expected size reduction
110
+ - Preserve position through optimization
111
+ - Update card with optimized media
112
+
113
+ ### Media Deletion for Cards
114
+
115
+ - Verify media ownership before deletion
116
+ - Check card associations and dependencies
117
+ - Confirm deletion with user if needed
118
+ - Delete from all storage locations
119
+ - Update card references
120
+ - Handle missing files gracefully
121
+
122
+ ### Batch Operations for Card Sets
123
+
124
+ - For multiple cards, use same service instance
125
+ - Process uploads/generations in sequence
126
+ - Collect results before saving
127
+ - Handle partial failures appropriately
128
+ - Consider parallel operations for independent media
129
+ - Track progress for user feedback
130
+ - Maintain position consistency across cards
131
+
132
+ ### Error Handling Patterns
133
+
134
+ - **Validation Errors**: Show to user, block upload
135
+ - **Upload Errors**: Retry or allow alternative file
136
+ - **Generation Errors**: Check credits, try different prompt
137
+ - **Optimization Errors**: Continue with original media
138
+ - **Deletion Errors**: Log error, notify user
139
+ - **Position Errors**: Validate position before operations
140
+ - **Network Errors**: Show connection message, allow retry
141
+
142
+ ### Card-Specific Considerations
143
+
144
+ - **Front Media**: Often focal point, prioritize quality
145
+ - **Back Media**: Secondary content, can be more compressed
146
+ - **Both Position**: Ensure quality works for both sides
147
+ - **Multiple Media**: Support multiple attachments per card
148
+ - **Position Validation**: Validate media type compatibility with position
149
+ - **Card Associations**: Maintain references between media and cards
150
+
151
+ ### Service Coordination
152
+
153
+ The service automatically coordinates:
154
+ - CardMediaUploadService handles file uploads
155
+ - CardMediaGenerationService handles AI generation
156
+ - CardMediaValidationService checks file validity
157
+ - CardMediaOptimizerService handles compression
158
+ - All services work together with card-specific requirements
159
+
160
+ ### Performance Considerations
161
+
162
+ - Singleton reduces memory footprint
163
+ - Single instance maintains state efficiently
164
+ - Sub-services initialized once
165
+ - All operations are asynchronous
166
+ - Consider lazy loading for large card sets
167
+ - Cache media URLs when possible
168
+ - Optimize media based on card usage patterns
169
+
170
+ ## Dependencies
171
+ - CardMediaUploadService for upload operations
172
+ - CardMediaGenerationService for AI generation (including image-search)
173
+ - CardMediaValidationService for validation
174
+ - CardMediaOptimizerService for optimization
175
+ - CardMediaAttachment type from domain layer
176
+ - CardMediaPosition type for card-side placement
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Card Multimedia Flashcard Service
3
+ * Media attachments for flashcards - Main entry point
4
+ */
5
+
6
+ import type {
7
+ CardMediaAttachment,
8
+ CardMediaGenerationRequest,
9
+ CardMediaGenerationResult,
10
+ CardMediaCompressionOptions,
11
+ CardMediaValidation,
12
+ CardMultimediaFlashcardService as ICardMultimediaFlashcardService,
13
+ } from "../../domain/entities/CardMultimedia.types";
14
+ import { CardMediaUploadService } from "./CardMediaUploadService";
15
+ import { CardMediaGenerationService } from "./CardMediaGenerationService";
16
+ import { CardMediaValidationService } from "./CardMediaValidationService";
17
+ import { CardMediaOptimizerService } from "./CardMediaOptimizerService";
18
+
19
+ export class CardMultimediaFlashcardService implements ICardMultimediaFlashcardService {
20
+ private static instance: CardMultimediaFlashcardService;
21
+ private uploadService: CardMediaUploadService;
22
+ private generationService: CardMediaGenerationService;
23
+ private validationService: CardMediaValidationService;
24
+ private optimizerService: CardMediaOptimizerService;
25
+
26
+ private constructor() {
27
+ this.uploadService = new CardMediaUploadService();
28
+ this.generationService = new CardMediaGenerationService();
29
+ this.validationService = new CardMediaValidationService();
30
+ this.optimizerService = new CardMediaOptimizerService();
31
+ }
32
+
33
+ static getInstance(): CardMultimediaFlashcardService {
34
+ if (!CardMultimediaFlashcardService.instance) {
35
+ CardMultimediaFlashcardService.instance =
36
+ new CardMultimediaFlashcardService();
37
+ }
38
+ return CardMultimediaFlashcardService.instance;
39
+ }
40
+
41
+ /**
42
+ * Upload media file with optional compression
43
+ */
44
+ async uploadMedia(
45
+ file: any,
46
+ options?: CardMediaCompressionOptions,
47
+ ): Promise<CardMediaAttachment> {
48
+ return this.uploadService.uploadMedia(file, options);
49
+ }
50
+
51
+ /**
52
+ * Generate media from AI (text-to-image, text-to-audio, etc.)
53
+ */
54
+ async generateMedia(
55
+ request: CardMediaGenerationRequest,
56
+ ): Promise<CardMediaGenerationResult> {
57
+ return this.generationService.generateMedia(request);
58
+ }
59
+
60
+ /**
61
+ * Validate media file before upload
62
+ */
63
+ async validateMedia(file: any): Promise<CardMediaValidation> {
64
+ return this.validationService.validateMedia(file);
65
+ }
66
+
67
+ /**
68
+ * Optimize media file
69
+ */
70
+ async optimizeMedia(
71
+ attachment: CardMediaAttachment,
72
+ options: CardMediaCompressionOptions,
73
+ ): Promise<CardMediaAttachment> {
74
+ return this.optimizerService.optimizeMedia(attachment, options);
75
+ }
76
+
77
+ /**
78
+ * Delete media attachment
79
+ */
80
+ async deleteMedia(attachmentId: string): Promise<void> {
81
+ return this.optimizerService.deleteMedia(attachmentId);
82
+ }
83
+
84
+ /**
85
+ * Get media URL
86
+ */
87
+ async getMediaUrl(attachmentId: string): Promise<string> {
88
+ return this.uploadService.getMediaUrl(attachmentId);
89
+ }
90
+
91
+ /**
92
+ * Download media to local storage
93
+ */
94
+ async downloadMedia(attachmentId: string): Promise<string> {
95
+ return this.uploadService.downloadMedia(attachmentId);
96
+ }
97
+ }
@@ -0,0 +1,142 @@
1
+ # MediaGenerationService
2
+
3
+ ## Purpose
4
+ Provides AI-powered media generation capabilities including text-to-image and text-to-audio generation with credit/balance management.
5
+
6
+ ## File Location
7
+ `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/MediaGenerationService`
8
+
9
+ ## Strategy
10
+
11
+ ### Core Purpose
12
+ - Generate images from text descriptions (text-to-image)
13
+ - Generate audio from text (text-to-audio)
14
+ - Support multiple result generation
15
+ - Track processing time and performance
16
+ - Manage generation costs/credits
17
+
18
+ ### Usage Scenarios
19
+ - AI-generated visual content for cards
20
+ - Text-to-speech conversion
21
+ - Creative content generation
22
+ - Localization and voice-over creation
23
+ - Dynamic asset generation
24
+
25
+ ### Integration Points
26
+ - AI-powered content creation workflows
27
+ - Text-to-speech features
28
+ - Automated asset generation
29
+ - Creative assistance tools
30
+ - Educational content generation
31
+
32
+ ## Forbidden
33
+
34
+ ### MUST NOT
35
+ - Generate without sufficient credits/balance
36
+ - Assume generation always succeeds
37
+ - Generate inappropriate or harmful content
38
+ - Ignore rate limiting or API constraints
39
+ - Cache generated content without validation
40
+ - Generate without user prompt input
41
+
42
+ ### MUST NEVER
43
+ - Expose API keys or credentials
44
+ - Allow unlimited free generation
45
+ - Ignore generation failures
46
+ - Bypass credit/balance checks
47
+ - Generate without proper error handling
48
+ - Assume instant generation results
49
+
50
+ ## Rules
51
+
52
+ ### Generation Operations
53
+ - MUST validate prompt before generation
54
+ - MUST check sufficient credits/balance
55
+ - MUST handle generation failures
56
+ - MUST track processing time
57
+ - MUST return unique request ID
58
+ - MUST respect result limits (maxResults)
59
+
60
+ ### Text-to-Image Generation
61
+ - MUST support style options
62
+ - MUST support aspect ratio options
63
+ - MUST generate multiple results if requested
64
+ - MUST validate image generation parameters
65
+ - MUST handle generation timeouts
66
+
67
+ ### Text-to-Audio Generation
68
+ - MUST support voice options
69
+ - MUST support language selection
70
+ - MUST support speed adjustment
71
+ - MUST return audio duration
72
+ - MUST validate audio parameters
73
+
74
+ ### Credit Management
75
+ - MUST deduct credits per generation
76
+ - MUST track credit usage in results
77
+ - MUST validate credit availability
78
+ - MUST prevent generation with insufficient credits
79
+ - MUST report credits used in result
80
+
81
+ ### Return Values
82
+ - MUST include success status
83
+ - MUST include generated media attachments
84
+ - MUST include credits used
85
+ - MUST include processing time
86
+ - MUST include unique request ID
87
+ - MUST include error details on failure
88
+
89
+ ### Error Handling
90
+ - MUST handle insufficient credits
91
+ - MUST handle generation timeouts
92
+ - MUST handle invalid prompts
93
+ - MUST handle API failures
94
+ - MUST provide meaningful error messages
95
+ - MUST allow retry after appropriate delay
96
+
97
+ ## AI Agent Guidelines
98
+
99
+ ### When Implementing Generation Features
100
+ 1. Always validate prompt input
101
+ 2. Check credit/balance before generation
102
+ 3. Set appropriate timeouts
103
+ 4. Handle both success and failure cases
104
+ 5. Track and report processing metrics
105
+
106
+ ### When Working with Text-to-Image
107
+ - Support common aspect ratios (16:9, 4:3, 1:1)
108
+ - Provide style presets (realistic, artistic, etc.)
109
+ - Limit max results to reasonable number
110
+ - Validate image generation parameters
111
+
112
+ ### When Working with Text-to-Audio
113
+ - Support common languages
114
+ - Provide voice options (male, female)
115
+ - Allow speed adjustment (0.5-2.0)
116
+ - Return accurate duration
117
+
118
+ ### When Adding Features
119
+ - Add new generation types with validation
120
+ - Extend options without breaking compatibility
121
+ - Add new credit tiers carefully
122
+ - Support batch generation if needed
123
+ - Add content filtering if required
124
+
125
+ ### When Refactoring
126
+ - Keep generation API stable
127
+ - Preserve credit calculation logic
128
+ - Maintain request ID generation
129
+ - Don't change result structure
130
+ - Add deprecation warnings for breaking changes
131
+
132
+ ### Common Patterns to Follow
133
+ - Validate prompt -> Check credits -> Generate -> Return result
134
+ - Handle timeout -> Retry if appropriate -> Return error
135
+ - Calculate credits -> Deduct -> Track usage
136
+ - Always wrap in try-catch for unexpected errors
137
+ - Provide user feedback for generation status
138
+
139
+ ## Dependencies
140
+
141
+ - Domain types: MediaAttachment, MediaGenerationRequest, MediaGenerationResult, MediaType, MediaPosition from MultimediaFlashcardTypes
142
+ - No external library dependencies (uses native APIs)