@umituz/react-native-ai-generation-content 1.12.2 → 1.12.4

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 (55) hide show
  1. package/package.json +6 -1
  2. package/src/domains/content-moderation/domain/entities/moderation.types.ts +84 -0
  3. package/src/domains/content-moderation/domain/interfaces/content-filter.interface.ts +24 -0
  4. package/src/domains/content-moderation/index.ts +67 -0
  5. package/src/domains/content-moderation/infrastructure/rules/default-rules.data.ts +144 -0
  6. package/src/domains/content-moderation/infrastructure/rules/rules-registry.ts +75 -0
  7. package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +150 -0
  8. package/src/domains/content-moderation/infrastructure/services/index.ts +8 -0
  9. package/src/domains/content-moderation/infrastructure/services/moderators/base.moderator.ts +62 -0
  10. package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +64 -0
  11. package/src/domains/content-moderation/infrastructure/services/moderators/index.ts +10 -0
  12. package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +144 -0
  13. package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +64 -0
  14. package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +74 -0
  15. package/src/domains/content-moderation/infrastructure/services/pattern-matcher.service.ts +51 -0
  16. package/src/domains/content-moderation/presentation/exceptions/content-policy-violation.exception.ts +48 -0
  17. package/src/domains/prompts/domain/entities/AIPromptTemplate.ts +48 -0
  18. package/src/domains/prompts/domain/entities/BackgroundRemovalConfig.ts +86 -0
  19. package/src/domains/prompts/domain/entities/ColorizationConfig.ts +101 -0
  20. package/src/domains/prompts/domain/entities/FaceSwapConfig.ts +54 -0
  21. package/src/domains/prompts/domain/entities/FuturePredictionConfig.ts +93 -0
  22. package/src/domains/prompts/domain/entities/GeneratedPrompt.ts +32 -0
  23. package/src/domains/prompts/domain/entities/ImageEnhancementConfig.ts +93 -0
  24. package/src/domains/prompts/domain/entities/PhotoRestorationConfig.ts +64 -0
  25. package/src/domains/prompts/domain/entities/StyleTransferConfig.ts +80 -0
  26. package/src/domains/prompts/domain/entities/TextGenerationConfig.ts +100 -0
  27. package/src/domains/prompts/domain/entities/types.ts +27 -0
  28. package/src/domains/prompts/domain/entities/value-objects.ts +33 -0
  29. package/src/domains/prompts/domain/repositories/IAIPromptServices.ts +106 -0
  30. package/src/domains/prompts/domain/repositories/IPromptHistoryRepository.ts +10 -0
  31. package/src/domains/prompts/domain/repositories/ITemplateRepository.ts +11 -0
  32. package/src/domains/prompts/index.ts +318 -0
  33. package/src/domains/prompts/infrastructure/repositories/PromptHistoryRepository.ts +85 -0
  34. package/src/domains/prompts/infrastructure/repositories/TemplateRepository.ts +77 -0
  35. package/src/domains/prompts/infrastructure/services/BackgroundRemovalService.ts +209 -0
  36. package/src/domains/prompts/infrastructure/services/ColorizationService.ts +232 -0
  37. package/src/domains/prompts/infrastructure/services/FaceSwapService.ts +198 -0
  38. package/src/domains/prompts/infrastructure/services/FuturePredictionService.ts +176 -0
  39. package/src/domains/prompts/infrastructure/services/ImageEnhancementService.ts +181 -0
  40. package/src/domains/prompts/infrastructure/services/PhotoRestorationService.ts +160 -0
  41. package/src/domains/prompts/infrastructure/services/PromptGenerationService.ts +59 -0
  42. package/src/domains/prompts/infrastructure/services/StyleTransferService.ts +194 -0
  43. package/src/domains/prompts/infrastructure/services/TextGenerationService.ts +241 -0
  44. package/src/domains/prompts/presentation/hooks/useAIServices.ts +213 -0
  45. package/src/domains/prompts/presentation/hooks/useAsyncState.ts +56 -0
  46. package/src/domains/prompts/presentation/hooks/useFaceSwap.ts +100 -0
  47. package/src/domains/prompts/presentation/hooks/useImageEnhancement.ts +100 -0
  48. package/src/domains/prompts/presentation/hooks/usePhotoRestoration.ts +100 -0
  49. package/src/domains/prompts/presentation/hooks/usePromptGeneration.ts +144 -0
  50. package/src/domains/prompts/presentation/hooks/useStyleTransfer.ts +125 -0
  51. package/src/domains/prompts/presentation/hooks/useTemplateRepository.ts +113 -0
  52. package/src/domains/prompts/presentation/theme/theme.ts +16 -0
  53. package/src/domains/prompts/presentation/theme/types.ts +82 -0
  54. package/src/domains/prompts/presentation/theme/utils.ts +24 -0
  55. package/src/index.ts +12 -0
@@ -0,0 +1,232 @@
1
+ import type { IColorizationService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ ColorizationConfig,
4
+ } from '../../domain/entities/ColorizationConfig';
5
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
+ import type { AIPromptResult } from '../../domain/entities/types';
7
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
+ import {
9
+ validateColorizationConfig,
10
+ getColorizationQuality,
11
+ getEraDescription,
12
+ getSuggestedColorPalette
13
+ } from '../../domain/entities/ColorizationConfig';
14
+ import { PromptGenerationService } from '../services/PromptGenerationService';
15
+
16
+ const createColorizationBaseTemplate = (config?: {
17
+ targetType?: string;
18
+ colorMode?: string;
19
+ }): string => {
20
+ const {
21
+ targetType = 'black-and-white',
22
+ colorMode = 'realistic'
23
+ } = config || {};
24
+
25
+ return `
26
+ You are an expert AI colorization specialist.
27
+ This is a PHOTO COLORIZATION task, not image generation.
28
+
29
+ COLORIZATION OBJECTIVES:
30
+ - Add appropriate colors to ${targetType} images
31
+ - Apply ${colorMode} color treatment while preserving authenticity
32
+ - Maintain original composition and details
33
+ - Create natural, pleasing color relationships
34
+
35
+ COLORIZATION PRINCIPLES:
36
+ - Research appropriate color schemes for image era/content
37
+ - Apply colors that match scene context and lighting
38
+ - Preserve details and textures while adding color
39
+ - Ensure color harmony and balance throughout image
40
+
41
+ ${colorMode === 'realistic' ?
42
+ `REALISTIC COLORIZATION:
43
+ - Use historically accurate colors when appropriate
44
+ - Consider natural lighting conditions
45
+ - Apply realistic skin tones and environmental colors
46
+ - Maintain photographic authenticity` :
47
+ colorMode === 'vibrant' ?
48
+ `VIBRANT COLORIZATION:
49
+ - Use rich, saturated colors for visual impact
50
+ - Create bold color contrasts and relationships
51
+ - Apply artistic color interpretations
52
+ - Enhance visual interest and appeal` :
53
+ colorMode === 'artistic' ?
54
+ `ARTISTIC COLORIZATION:
55
+ - Apply creative color interpretations
56
+ - Use expressive color choices and combinations
57
+ - Create mood and atmosphere through color
58
+ - Allow artistic freedom in color selection` :
59
+ `VINTAGE COLORIZATION:
60
+ - Use period-appropriate color palettes
61
+ - Apply aged, authentic color treatments
62
+ - Maintain historical color sensibilities
63
+ - Create nostalgic, time-appropriate appearance`}
64
+
65
+ TECHNICAL REQUIREMENTS:
66
+ - Preserve edges and details during color application
67
+ - Apply colors smoothly and naturally
68
+ - Consider lighting and shadow relationships
69
+ - Maintain image quality and resolution
70
+
71
+ SAFETY CONSTRAINTS:
72
+ - Do not alter content or composition
73
+ - Preserve important details and features
74
+ - Avoid inappropriate or unrealistic colors
75
+ - Maintain appropriate content standards
76
+
77
+ OUTPUT:
78
+ Beautifully colorized version of the original ${targetType} image,
79
+ with ${colorMode} color treatment that enhances rather than dominates.
80
+ `.trim();
81
+ };
82
+
83
+ export class ColorizationService implements IColorizationService {
84
+ private promptService: PromptGenerationService;
85
+
86
+ constructor() {
87
+ this.promptService = new PromptGenerationService();
88
+ }
89
+
90
+ async generateTemplate(config: ColorizationConfig): Promise<AIPromptResult<AIPromptTemplate>> {
91
+ try {
92
+ if (!this.validateConfig(config)) {
93
+ return {
94
+ success: false,
95
+ error: 'VALIDATION_ERROR',
96
+ message: 'Invalid colorization configuration'
97
+ };
98
+ }
99
+
100
+ const template = this.createColorizationTemplate(config);
101
+ return { success: true, data: template };
102
+ } catch (error) {
103
+ return {
104
+ success: false,
105
+ error: 'GENERATION_FAILED',
106
+ message: 'Failed to generate colorization template'
107
+ };
108
+ }
109
+ }
110
+
111
+ async generatePrompt(
112
+ template: AIPromptTemplate,
113
+ config: ColorizationConfig
114
+ ): Promise<AIPromptResult<string>> {
115
+ const variables = {
116
+ targetType: config.targetType,
117
+ colorMode: config.colorMode,
118
+ preserveOriginal: config.preserveOriginal,
119
+ adjustLighting: config.adjustLighting,
120
+ skinTonePreservation: config.skinTonePreservation,
121
+ era: config.era || '',
122
+ qualityScore: getColorizationQuality(config),
123
+ colorPalette: this.getColorPalette(config),
124
+ };
125
+
126
+ return this.promptService.generateFromTemplate(template, variables);
127
+ }
128
+
129
+ validateConfig(config: ColorizationConfig): boolean {
130
+ return validateColorizationConfig(config);
131
+ }
132
+
133
+ getColorPalette(config: ColorizationConfig): string[] {
134
+ return getSuggestedColorPalette(config.targetType, config.colorMode);
135
+ }
136
+
137
+ getQualityScore(config: ColorizationConfig): number {
138
+ return getColorizationQuality(config);
139
+ }
140
+
141
+ private createColorizationTemplate(config: ColorizationConfig): AIPromptTemplate {
142
+ const templateId = `colorization-${config.targetType}-${config.colorMode}`;
143
+
144
+ const baseTemplate = createColorizationBaseTemplate({
145
+ targetType: config.targetType,
146
+ colorMode: config.colorMode,
147
+ });
148
+
149
+ return createAIPromptTemplate({
150
+ id: templateId,
151
+ name: `Colorization: ${config.targetType} to ${config.colorMode}`,
152
+ description: `Colorize ${config.targetType} images with ${config.colorMode} treatment`,
153
+ category: 'colorization',
154
+ template: `${baseTemplate}
155
+
156
+ COLORIZATION CONFIGURATION:
157
+ - Target Type: ${config.targetType}
158
+ - Color Mode: ${config.colorMode}
159
+ - Preserve Original: ${config.preserveOriginal}
160
+ - Adjust Lighting: ${config.adjustLighting}
161
+ - Skin Tone Preservation: ${config.skinTonePreservation}
162
+ ${config.era ? `- Era: ${config.era}` : ''}
163
+
164
+ COLOR REQUIREMENTS:
165
+ ${this.getColorRequirements(config)}
166
+
167
+ ${config.era ? `ERA-SPECIFIC GUIDELINES:
168
+ ${getEraDescription(config.era)}
169
+
170
+ ` : ''}QUALITY EXPECTATIONS:
171
+ - Quality Score: ${Math.round(getColorizationQuality(config) * 100)}%
172
+ - Color Mode: ${config.colorMode} treatment applied
173
+ - Preserved Elements: ${config.preserveOriginal ? 'Original content preserved' : 'Enhanced interpretation'}
174
+ - Skin Handling: ${config.skinTonePreservation ? 'Natural tones preserved' : 'Artistic interpretation allowed'}
175
+
176
+ ${this.getColorPalette(config).length > 0 ? `
177
+ SUGGESTED COLOR PALETTE:
178
+ ${this.getColorPalette(config).join(', ')}
179
+
180
+ ` : ''}EXPECTED RESULT:
181
+ Professionally colorized ${config.targetType} image,
182
+ with ${config.colorMode} color treatment,
183
+ ${config.skinTonePreservation ? 'maintaining natural appearance' : 'allowing artistic interpretation'}.
184
+ `.trim(),
185
+ variables: [],
186
+ safety: {
187
+ contentFilter: true,
188
+ adultContentFilter: true,
189
+ violenceFilter: true,
190
+ hateSpeechFilter: true,
191
+ copyrightFilter: true,
192
+ },
193
+ version: '1.0.0',
194
+ });
195
+ }
196
+
197
+ private getColorRequirements(config: ColorizationConfig): string {
198
+ const requirements: string[] = [];
199
+
200
+ if (config.targetType === 'black-and-white') {
201
+ requirements.push('- Add natural colors to monochrome image');
202
+ requirements.push('- Consider original grayscale values for color mapping');
203
+ }
204
+
205
+ if (config.targetType === 'sepia') {
206
+ requirements.push('- Refresh and enhance sepia-toned image');
207
+ requirements.push('- Maintain vintage character while adding color');
208
+ }
209
+
210
+ if (config.colorMode === 'realistic') {
211
+ requirements.push('- Use historically and naturally accurate colors');
212
+ requirements.push('- Apply appropriate skin tones and environmental colors');
213
+ }
214
+
215
+ if (config.colorMode === 'vibrant') {
216
+ requirements.push('- Use rich, saturated colors for visual impact');
217
+ requirements.push('- Create bold color contrasts and relationships');
218
+ }
219
+
220
+ if (config.adjustLighting) {
221
+ requirements.push('- Adjust colors for optimal lighting conditions');
222
+ requirements.push('- Ensure appropriate contrast and brightness');
223
+ }
224
+
225
+ if (config.skinTonePreservation) {
226
+ requirements.push('- Maintain natural, appropriate skin tones');
227
+ requirements.push('- Avoid unrealistic or inappropriate skin colors');
228
+ }
229
+
230
+ return requirements.join('\n') || '- Apply appropriate color treatment based on configuration';
231
+ }
232
+ }
@@ -0,0 +1,198 @@
1
+ import type { IFaceSwapService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ AIPromptTemplate
4
+ } from '../../domain/entities/AIPromptTemplate';
5
+ import type {
6
+ FaceSwapConfig,
7
+ FaceSwapGenerationResult,
8
+ FaceSwapSafety
9
+ } from '../../domain/entities/FaceSwapConfig';
10
+ import type { AIPromptCategory } from '../../domain/entities/types';
11
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
12
+ import { validateFaceSwapConfig } from '../../domain/entities/FaceSwapConfig';
13
+ import type { AIPromptResult } from '../../domain/entities/types';
14
+ import { PromptGenerationService } from '../services/PromptGenerationService';
15
+
16
+ const DEFAULT_FACE_SWAP_SAFETY: FaceSwapSafety = {
17
+ contentFilter: true,
18
+ identityPreservation: true,
19
+ adultContentFilter: true,
20
+ };
21
+
22
+ const createFaceSwapBaseTemplate = (config?: {
23
+ targetPerson?: string;
24
+ transformationType?: string;
25
+ quality?: string;
26
+ }): string => {
27
+ const {
28
+ targetPerson = 'SAME PERSON',
29
+ transformationType = 'transformation',
30
+ quality = 'App Store–ready'
31
+ } = config || {};
32
+
33
+ return `
34
+ You are an expert AI photo editor.
35
+ This is a PHOTO EDITING task, not text-to-image generation.
36
+
37
+ IDENTITY PRESERVATION (CRITICAL):
38
+ The output must clearly depict the ${targetPerson} from the uploaded photo.
39
+ The person must remain recognizable after transformation.
40
+
41
+ FACE IDENTITY (DO NOT CHANGE):
42
+ - Facial bone structure and proportions
43
+ - Eye shape and eye color
44
+ - Nose shape and size
45
+ - Lip shape and proportions
46
+ - Skin tone and natural facial texture
47
+
48
+ ALLOWED NON-DESTRUCTIVE CHANGES:
49
+ - Hair style and hair color (wig-like or costume-based)
50
+ - Facial hair (beard, mustache) as costume elements
51
+ - Accessories (hats, glasses, headwear)
52
+ - Subtle expression adjustments that do NOT alter facial structure
53
+ - Costume makeup that does NOT reshape the face
54
+
55
+ STRICTLY FORBIDDEN:
56
+ - Face replacement or face swapping with another identity
57
+ - Changing the person into a different real individual
58
+ - Changing gender or ethnicity
59
+ - Extreme age transformation
60
+ - Distorted faces or unrealistic anatomy
61
+
62
+ SAFETY CONSTRAINTS:
63
+ Do NOT add nudity, sexual content, violence, weapons, drugs, political or religious symbols,
64
+ copyrighted characters, celebrities, text overlays, logos, or watermarks.
65
+
66
+ STYLE & QUALITY:
67
+ - Realistic photographic style
68
+ - High-quality, natural lighting
69
+ - Clean, premium, ${quality} result
70
+
71
+ FINAL RULE:
72
+ This is a fictional, cosmetic ${transformationType} for entertainment only.
73
+ `.trim();
74
+ };
75
+
76
+ export class FaceSwapService implements IFaceSwapService {
77
+ private promptService: PromptGenerationService;
78
+ private availableStyles: string[] = [];
79
+
80
+ constructor() {
81
+ this.promptService = new PromptGenerationService();
82
+ this.initializeDefaultStyles();
83
+ }
84
+
85
+ async generateTemplate(config: FaceSwapConfig): Promise<AIPromptResult<AIPromptTemplate>> {
86
+ try {
87
+ if (!this.validateConfig(config)) {
88
+ return {
89
+ success: false,
90
+ error: 'INVALID_VARIABLES',
91
+ message: 'Invalid face swap configuration'
92
+ };
93
+ }
94
+
95
+ const template = this.createFaceSwapTemplate(config);
96
+ return { success: true, data: template };
97
+ } catch (error) {
98
+ return {
99
+ success: false,
100
+ error: 'GENERATION_FAILED',
101
+ message: 'Failed to generate face swap template'
102
+ };
103
+ }
104
+ }
105
+
106
+ async generatePrompt(
107
+ template: AIPromptTemplate,
108
+ config: FaceSwapConfig
109
+ ): Promise<AIPromptResult<string>> {
110
+ const variables = {
111
+ styleName: config.styleName,
112
+ environment: config.environment || 'Neutral studio background',
113
+ preserveIdentity: config.preserveIdentity,
114
+ allowHairStyle: config.allowHairStyle,
115
+ allowAccessories: config.allowAccessories,
116
+ allowExpression: config.allowExpression,
117
+ };
118
+
119
+ return this.promptService.generateFromTemplate(template, variables);
120
+ }
121
+
122
+ validateConfig(config: FaceSwapConfig): boolean {
123
+ return validateFaceSwapConfig(config);
124
+ }
125
+
126
+ async getAvailableStyles(): Promise<string[]> {
127
+ return Promise.resolve([...this.availableStyles]);
128
+ }
129
+
130
+ private initializeDefaultStyles(): void {
131
+ this.availableStyles = [];
132
+ }
133
+
134
+ public registerStyle(style: string): void {
135
+ if (!this.availableStyles.includes(style)) {
136
+ this.availableStyles.push(style);
137
+ }
138
+ }
139
+
140
+ public registerStyles(styles: string[]): void {
141
+ styles.forEach(style => this.registerStyle(style));
142
+ }
143
+
144
+ public clearStyles(): void {
145
+ this.availableStyles = [];
146
+ }
147
+
148
+ private createFaceSwapTemplate(config: FaceSwapConfig): AIPromptTemplate {
149
+ const templateId = `face-swap-${config.styleName.toLowerCase().replace(/\s+/g, '-')}`;
150
+
151
+ return createAIPromptTemplate({
152
+ id: templateId,
153
+ name: `Face Swap: ${config.styleName}`,
154
+ description: `Transform face into ${config.styleName} style`,
155
+ category: 'face-swap' as AIPromptCategory,
156
+ template: this.buildFaceSwapTemplate(config),
157
+ variables: [],
158
+ safety: {
159
+ contentFilter: DEFAULT_FACE_SWAP_SAFETY.contentFilter,
160
+ adultContentFilter: DEFAULT_FACE_SWAP_SAFETY.adultContentFilter,
161
+ violenceFilter: true,
162
+ hateSpeechFilter: true,
163
+ copyrightFilter: true,
164
+ },
165
+ version: '1.0.0',
166
+ });
167
+ }
168
+
169
+ private buildFaceSwapTemplate(config: FaceSwapConfig): string {
170
+ const baseTemplate = createFaceSwapBaseTemplate({
171
+ targetPerson: 'SAME PERSON',
172
+ transformationType: 'transformation',
173
+ quality: 'App Store–ready',
174
+ });
175
+
176
+ return `${baseTemplate}
177
+
178
+ STYLE NAME:
179
+ ${config.styleName}
180
+
181
+ TRANSFORMATION GOAL:
182
+ Transform the same person into this ${config.styleName} style
183
+ ${config.preserveIdentity ? 'while preserving their facial identity.' : ''}
184
+
185
+ ENVIRONMENT:
186
+ ${config.environment || 'Neutral studio background'}
187
+
188
+ EXPRESSION:
189
+ - Natural expression
190
+ - Subtle and natural, without changing facial structure
191
+
192
+ OUTPUT:
193
+ The same person from the uploaded photo,
194
+ clearly recognizable,
195
+ realistically transformed into a ${config.styleName} style.
196
+ `.trim();
197
+ }
198
+ }
@@ -0,0 +1,176 @@
1
+ import type { IFuturePredictionService } from '../../domain/repositories/IAIPromptServices';
2
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
3
+ import type { AIPromptResult } from '../../domain/entities/types';
4
+ import type {
5
+ FuturePredictionConfig,
6
+ FuturePredictionResult,
7
+ } from '../../domain/entities/FuturePredictionConfig';
8
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
9
+ import {
10
+ validateFuturePredictionConfig,
11
+ getFutureYear,
12
+ } from '../../domain/entities/FuturePredictionConfig';
13
+ import { PromptGenerationService } from './PromptGenerationService';
14
+
15
+ const IMAGE_PROMPT_TEMPLATE = `
16
+ Generate a single high-quality, photorealistic image of {{subjectA}}{{#if subjectB}} and {{subjectB}}{{/if}}.
17
+ Role/Relationship: {{subjectRole}}
18
+ Context/Scenario: {{scenarioTitle}}
19
+ Additional Details: {{promptModifier}}
20
+
21
+ Requirements:
22
+ - Maintain facial identity and key features of the individual(s) provided in input images.
23
+ - Ensure lighting, environment, and skin tones are realistic and consistent.
24
+ - Style: High detail, professional photography, 4k resolution.
25
+ - No text, watermarks, or artificial artifacts.
26
+ `.trim();
27
+
28
+ const STORY_PROMPT_TEMPLATE = `
29
+ Write a short, engaging, and evocative description for a future scene.
30
+ Subjects: {{subjectA}}{{#if subjectB}} and {{subjectB}}{{/if}}
31
+ Role: {{subjectRole}}
32
+ Scenario: {{scenarioTitle}}
33
+ Atmosphere/Tone: {{tone}}
34
+ Context: {{promptModifier}}
35
+ Imaginary Year: {{futureYear}}
36
+
37
+ Style:
38
+ - 2-3 sentences max.
39
+ - Be vivid and imaginative.
40
+ - Do not use hashtags.
41
+ {{#if language}}Please respond in {{language}} language.{{/if}}
42
+ `.trim();
43
+
44
+ export class FuturePredictionService implements IFuturePredictionService {
45
+ private promptService: PromptGenerationService;
46
+
47
+ constructor() {
48
+ this.promptService = new PromptGenerationService();
49
+ }
50
+
51
+ async generateTemplate(
52
+ config: FuturePredictionConfig
53
+ ): Promise<AIPromptResult<AIPromptTemplate>> {
54
+ if (!this.validateConfig(config)) {
55
+ return {
56
+ success: false,
57
+ error: 'VALIDATION_ERROR',
58
+ message: 'Invalid future prediction configuration',
59
+ };
60
+ }
61
+
62
+ const template = this.createTemplate(config);
63
+ return { success: true, data: template };
64
+ }
65
+
66
+ async generatePrompts(
67
+ config: FuturePredictionConfig
68
+ ): Promise<AIPromptResult<FuturePredictionResult>> {
69
+ if (!this.validateConfig(config)) {
70
+ return {
71
+ success: false,
72
+ error: 'VALIDATION_ERROR',
73
+ message: 'Invalid configuration',
74
+ };
75
+ }
76
+
77
+ const imagePrompt = this.buildImagePrompt(config);
78
+ const storyPrompt = this.buildStoryPrompt(config);
79
+
80
+ return {
81
+ success: true,
82
+ data: {
83
+ imagePrompt,
84
+ storyPrompt,
85
+ metadata: {
86
+ scenarioId: config.scenarioId,
87
+ personCount: config.settings.personCount,
88
+ language: config.settings.language,
89
+ generatedAt: Date.now(),
90
+ },
91
+ },
92
+ };
93
+ }
94
+
95
+ validateConfig(config: FuturePredictionConfig): boolean {
96
+ return validateFuturePredictionConfig(config);
97
+ }
98
+
99
+ buildImagePrompt(config: FuturePredictionConfig): string {
100
+ const subjectRole = config.settings.subjectRole || 'individuals';
101
+
102
+ return IMAGE_PROMPT_TEMPLATE
103
+ .replace(/{{subjectA}}/g, config.subjectA)
104
+ .replace(/{{subjectB}}/g, config.subjectB || '')
105
+ .replace(/{{#if subjectB}} and {{subjectB}}{{\/if}}/g, config.subjectB ? ` and ${config.subjectB}` : '')
106
+ .replace(/{{subjectRole}}/g, subjectRole)
107
+ .replace(/{{scenarioTitle}}/g, config.scenarioTitle)
108
+ .replace(/{{promptModifier}}/g, config.promptModifier);
109
+ }
110
+
111
+ buildStoryPrompt(config: FuturePredictionConfig): string {
112
+ const futureYear = config.settings.year || getFutureYear();
113
+ const tone = config.settings.tone || 'neutral';
114
+ const subjectRole = config.settings.subjectRole || 'individuals';
115
+
116
+ let prompt = STORY_PROMPT_TEMPLATE
117
+ .replace(/{{subjectA}}/g, config.subjectA)
118
+ .replace(/{{subjectB}}/g, config.subjectB || '')
119
+ .replace(/{{#if subjectB}} and {{subjectB}}{{\/if}}/g, config.subjectB ? ` and ${config.subjectB}` : '')
120
+ .replace(/{{subjectRole}}/g, subjectRole)
121
+ .replace(/{{scenarioTitle}}/g, config.scenarioTitle)
122
+ .replace(/{{tone}}/g, tone)
123
+ .replace(/{{promptModifier}}/g, config.promptModifier)
124
+ .replace(/{{futureYear}}/g, String(futureYear));
125
+
126
+ if (config.settings.language && config.settings.language !== 'en') {
127
+ prompt = prompt.replace(
128
+ /{{#if language}}(.*?){{\/if}}/g,
129
+ `$1`.replace(/{{language}}/g, this.getLanguageName(config.settings.language))
130
+ );
131
+ } else {
132
+ prompt = prompt.replace(/{{#if language}}.*?{{\/if}}/g, '');
133
+ }
134
+
135
+ return prompt.trim();
136
+ }
137
+
138
+ private createTemplate(config: FuturePredictionConfig): AIPromptTemplate {
139
+ return createAIPromptTemplate({
140
+ id: `future-prediction-${config.scenarioId}`,
141
+ name: `Future Prediction: ${config.scenarioTitle}`,
142
+ description: `Generate future prediction for ${config.scenarioId} scenario`,
143
+ category: 'future-prediction',
144
+ template: this.buildImagePrompt(config),
145
+ variables: [],
146
+ safety: {
147
+ contentFilter: true,
148
+ adultContentFilter: true,
149
+ violenceFilter: true,
150
+ hateSpeechFilter: true,
151
+ copyrightFilter: true,
152
+ },
153
+ version: '1.0.0',
154
+ });
155
+ }
156
+
157
+ private getLanguageName(code: string): string {
158
+ const languages: Record<string, string> = {
159
+ tr: 'Turkish',
160
+ es: 'Spanish',
161
+ fr: 'French',
162
+ de: 'German',
163
+ it: 'Italian',
164
+ pt: 'Portuguese',
165
+ ru: 'Russian',
166
+ ja: 'Japanese',
167
+ ko: 'Korean',
168
+ zh: 'Chinese',
169
+ ar: 'Arabic',
170
+ hi: 'Hindi',
171
+ th: 'Thai',
172
+ vi: 'Vietnamese',
173
+ };
174
+ return languages[code] || 'English';
175
+ }
176
+ }