@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.
- package/package.json +6 -1
- package/src/domains/content-moderation/domain/entities/moderation.types.ts +84 -0
- package/src/domains/content-moderation/domain/interfaces/content-filter.interface.ts +24 -0
- package/src/domains/content-moderation/index.ts +67 -0
- package/src/domains/content-moderation/infrastructure/rules/default-rules.data.ts +144 -0
- package/src/domains/content-moderation/infrastructure/rules/rules-registry.ts +75 -0
- package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +150 -0
- package/src/domains/content-moderation/infrastructure/services/index.ts +8 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/base.moderator.ts +62 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +64 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/index.ts +10 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +144 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +64 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +74 -0
- package/src/domains/content-moderation/infrastructure/services/pattern-matcher.service.ts +51 -0
- package/src/domains/content-moderation/presentation/exceptions/content-policy-violation.exception.ts +48 -0
- package/src/domains/prompts/domain/entities/AIPromptTemplate.ts +48 -0
- package/src/domains/prompts/domain/entities/BackgroundRemovalConfig.ts +86 -0
- package/src/domains/prompts/domain/entities/ColorizationConfig.ts +101 -0
- package/src/domains/prompts/domain/entities/FaceSwapConfig.ts +54 -0
- package/src/domains/prompts/domain/entities/FuturePredictionConfig.ts +93 -0
- package/src/domains/prompts/domain/entities/GeneratedPrompt.ts +32 -0
- package/src/domains/prompts/domain/entities/ImageEnhancementConfig.ts +93 -0
- package/src/domains/prompts/domain/entities/PhotoRestorationConfig.ts +64 -0
- package/src/domains/prompts/domain/entities/StyleTransferConfig.ts +80 -0
- package/src/domains/prompts/domain/entities/TextGenerationConfig.ts +100 -0
- package/src/domains/prompts/domain/entities/types.ts +27 -0
- package/src/domains/prompts/domain/entities/value-objects.ts +33 -0
- package/src/domains/prompts/domain/repositories/IAIPromptServices.ts +106 -0
- package/src/domains/prompts/domain/repositories/IPromptHistoryRepository.ts +10 -0
- package/src/domains/prompts/domain/repositories/ITemplateRepository.ts +11 -0
- package/src/domains/prompts/index.ts +318 -0
- package/src/domains/prompts/infrastructure/repositories/PromptHistoryRepository.ts +85 -0
- package/src/domains/prompts/infrastructure/repositories/TemplateRepository.ts +77 -0
- package/src/domains/prompts/infrastructure/services/BackgroundRemovalService.ts +209 -0
- package/src/domains/prompts/infrastructure/services/ColorizationService.ts +232 -0
- package/src/domains/prompts/infrastructure/services/FaceSwapService.ts +198 -0
- package/src/domains/prompts/infrastructure/services/FuturePredictionService.ts +176 -0
- package/src/domains/prompts/infrastructure/services/ImageEnhancementService.ts +181 -0
- package/src/domains/prompts/infrastructure/services/PhotoRestorationService.ts +160 -0
- package/src/domains/prompts/infrastructure/services/PromptGenerationService.ts +59 -0
- package/src/domains/prompts/infrastructure/services/StyleTransferService.ts +194 -0
- package/src/domains/prompts/infrastructure/services/TextGenerationService.ts +241 -0
- package/src/domains/prompts/presentation/hooks/useAIServices.ts +213 -0
- package/src/domains/prompts/presentation/hooks/useAsyncState.ts +56 -0
- package/src/domains/prompts/presentation/hooks/useFaceSwap.ts +100 -0
- package/src/domains/prompts/presentation/hooks/useImageEnhancement.ts +100 -0
- package/src/domains/prompts/presentation/hooks/usePhotoRestoration.ts +100 -0
- package/src/domains/prompts/presentation/hooks/usePromptGeneration.ts +144 -0
- package/src/domains/prompts/presentation/hooks/useStyleTransfer.ts +125 -0
- package/src/domains/prompts/presentation/hooks/useTemplateRepository.ts +113 -0
- package/src/domains/prompts/presentation/theme/theme.ts +16 -0
- package/src/domains/prompts/presentation/theme/types.ts +82 -0
- package/src/domains/prompts/presentation/theme/utils.ts +24 -0
- package/src/index.ts +12 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import type { ImageEnhancementConfig, EnhancementAdjustments } from '../../domain/entities/ImageEnhancementConfig';
|
|
3
|
+
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
4
|
+
import type { IImageEnhancementService } from '../../domain/repositories/IAIPromptServices';
|
|
5
|
+
import type { ITemplateRepository } from '../../domain/repositories/ITemplateRepository';
|
|
6
|
+
import type { IPromptHistoryRepository } from '../../domain/repositories/IPromptHistoryRepository';
|
|
7
|
+
import { createGeneratedPrompt } from '../../domain/entities/GeneratedPrompt';
|
|
8
|
+
import { useAsyncState } from './useAsyncState';
|
|
9
|
+
|
|
10
|
+
export interface ImageEnhancementResult {
|
|
11
|
+
template: AIPromptTemplate;
|
|
12
|
+
config: ImageEnhancementConfig;
|
|
13
|
+
adjustments: EnhancementAdjustments;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UseImageEnhancementState {
|
|
17
|
+
generatedPrompt: string | null;
|
|
18
|
+
lastResult: ImageEnhancementResult | null;
|
|
19
|
+
adjustments: EnhancementAdjustments | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface UseImageEnhancementActions {
|
|
23
|
+
enhanceImage: (config: ImageEnhancementConfig) => Promise<void>;
|
|
24
|
+
calculateAdjustments: (config: ImageEnhancementConfig) => EnhancementAdjustments;
|
|
25
|
+
clearPrompt: () => void;
|
|
26
|
+
reset: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const useImageEnhancement = (
|
|
30
|
+
service: IImageEnhancementService,
|
|
31
|
+
templateRepository: ITemplateRepository,
|
|
32
|
+
historyRepository: IPromptHistoryRepository
|
|
33
|
+
): UseImageEnhancementState & UseImageEnhancementActions => {
|
|
34
|
+
const {
|
|
35
|
+
data: lastResult,
|
|
36
|
+
setData: setResult,
|
|
37
|
+
clearError,
|
|
38
|
+
setError,
|
|
39
|
+
} = useAsyncState<ImageEnhancementResult>(null);
|
|
40
|
+
|
|
41
|
+
const enhanceImage = useCallback(async (config: ImageEnhancementConfig): Promise<void> => {
|
|
42
|
+
clearError();
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const templateResult = await service.generateTemplate(config);
|
|
46
|
+
if (!templateResult.success || !templateResult.data) {
|
|
47
|
+
setError('Failed to generate template');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const promptResult = await service.generatePrompt(templateResult.data, config);
|
|
52
|
+
if (!promptResult.success) {
|
|
53
|
+
setError('Failed to generate enhancement prompt');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const generatedPrompt = createGeneratedPrompt({
|
|
58
|
+
templateId: templateResult.data.id,
|
|
59
|
+
generatedText: promptResult.data,
|
|
60
|
+
variables: {} as Record<string, unknown>,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await historyRepository.save(generatedPrompt);
|
|
64
|
+
|
|
65
|
+
const enhancementResult: ImageEnhancementResult = {
|
|
66
|
+
template: templateResult.data,
|
|
67
|
+
config,
|
|
68
|
+
adjustments: service.calculateAdjustments(config),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
setResult(enhancementResult);
|
|
72
|
+
} catch {
|
|
73
|
+
setError('An unexpected error occurred during image enhancement');
|
|
74
|
+
}
|
|
75
|
+
}, [service, historyRepository, setError, setResult, clearError]);
|
|
76
|
+
|
|
77
|
+
const calculateAdjustments = useCallback((config: ImageEnhancementConfig): EnhancementAdjustments => {
|
|
78
|
+
return service.calculateAdjustments(config);
|
|
79
|
+
}, [service]);
|
|
80
|
+
|
|
81
|
+
const clearPrompt = useCallback(() => {
|
|
82
|
+
setResult(null);
|
|
83
|
+
clearError();
|
|
84
|
+
}, [setResult, clearError]);
|
|
85
|
+
|
|
86
|
+
const reset = useCallback(() => {
|
|
87
|
+
setResult(null);
|
|
88
|
+
clearError();
|
|
89
|
+
}, [setResult, clearError]);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
generatedPrompt: null,
|
|
93
|
+
lastResult,
|
|
94
|
+
adjustments: lastResult?.adjustments || null,
|
|
95
|
+
enhanceImage,
|
|
96
|
+
calculateAdjustments,
|
|
97
|
+
clearPrompt,
|
|
98
|
+
reset,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import type { PhotoRestorationConfig } from '../../domain/entities/PhotoRestorationConfig';
|
|
3
|
+
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
4
|
+
import type { IPhotoRestorationService } from '../../domain/repositories/IAIPromptServices';
|
|
5
|
+
import type { ITemplateRepository } from '../../domain/repositories/ITemplateRepository';
|
|
6
|
+
import type { IPromptHistoryRepository } from '../../domain/repositories/IPromptHistoryRepository';
|
|
7
|
+
import { createGeneratedPrompt } from '../../domain/entities/GeneratedPrompt';
|
|
8
|
+
import { useAsyncState } from './useAsyncState';
|
|
9
|
+
|
|
10
|
+
export interface PhotoRestorationResult {
|
|
11
|
+
template: AIPromptTemplate;
|
|
12
|
+
config: PhotoRestorationConfig;
|
|
13
|
+
estimatedQuality: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UsePhotoRestorationState {
|
|
17
|
+
generatedPrompt: string | null;
|
|
18
|
+
lastResult: PhotoRestorationResult | null;
|
|
19
|
+
estimatedQuality: number | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface UsePhotoRestorationActions {
|
|
23
|
+
restorePhoto: (config: PhotoRestorationConfig) => Promise<void>;
|
|
24
|
+
estimateQuality: (config: PhotoRestorationConfig) => number;
|
|
25
|
+
clearPrompt: () => void;
|
|
26
|
+
reset: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const usePhotoRestoration = (
|
|
30
|
+
service: IPhotoRestorationService,
|
|
31
|
+
templateRepository: ITemplateRepository,
|
|
32
|
+
historyRepository: IPromptHistoryRepository
|
|
33
|
+
): UsePhotoRestorationState & UsePhotoRestorationActions => {
|
|
34
|
+
const {
|
|
35
|
+
data: lastResult,
|
|
36
|
+
setData: setResult,
|
|
37
|
+
clearError,
|
|
38
|
+
setError,
|
|
39
|
+
} = useAsyncState<PhotoRestorationResult>(null);
|
|
40
|
+
|
|
41
|
+
const restorePhoto = useCallback(async (config: PhotoRestorationConfig): Promise<void> => {
|
|
42
|
+
clearError();
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const templateResult = await service.generateTemplate(config);
|
|
46
|
+
if (!templateResult.success || !templateResult.data) {
|
|
47
|
+
setError('Failed to generate template');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const promptResult = await service.generatePrompt(templateResult.data, config);
|
|
52
|
+
if (!promptResult.success) {
|
|
53
|
+
setError('Failed to generate restoration prompt');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const generatedPrompt = createGeneratedPrompt({
|
|
58
|
+
templateId: templateResult.data.id,
|
|
59
|
+
generatedText: promptResult.data,
|
|
60
|
+
variables: {} as Record<string, unknown>,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await historyRepository.save(generatedPrompt);
|
|
64
|
+
|
|
65
|
+
const restorationResult: PhotoRestorationResult = {
|
|
66
|
+
template: templateResult.data,
|
|
67
|
+
config,
|
|
68
|
+
estimatedQuality: service.estimateQuality(config),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
setResult(restorationResult);
|
|
72
|
+
} catch {
|
|
73
|
+
setError('An unexpected error occurred during photo restoration');
|
|
74
|
+
}
|
|
75
|
+
}, [service, historyRepository, setError, setResult, clearError]);
|
|
76
|
+
|
|
77
|
+
const estimateQuality = useCallback((config: PhotoRestorationConfig): number => {
|
|
78
|
+
return service.estimateQuality(config);
|
|
79
|
+
}, [service]);
|
|
80
|
+
|
|
81
|
+
const clearPrompt = useCallback(() => {
|
|
82
|
+
setResult(null);
|
|
83
|
+
clearError();
|
|
84
|
+
}, [setResult, clearError]);
|
|
85
|
+
|
|
86
|
+
const reset = useCallback(() => {
|
|
87
|
+
setResult(null);
|
|
88
|
+
clearError();
|
|
89
|
+
}, [setResult, clearError]);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
generatedPrompt: null,
|
|
93
|
+
lastResult,
|
|
94
|
+
estimatedQuality: lastResult?.estimatedQuality || null,
|
|
95
|
+
restorePhoto,
|
|
96
|
+
estimateQuality,
|
|
97
|
+
clearPrompt,
|
|
98
|
+
reset,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
3
|
+
import type { IPromptGenerationService } from '../../domain/repositories/IAIPromptServices';
|
|
4
|
+
import type { ITemplateRepository } from '../../domain/repositories/ITemplateRepository';
|
|
5
|
+
import type { IPromptHistoryRepository } from '../../domain/repositories/IPromptHistoryRepository';
|
|
6
|
+
import type { GeneratedPrompt } from '../../domain/entities/GeneratedPrompt';
|
|
7
|
+
import { createGeneratedPrompt } from '../../domain/entities/GeneratedPrompt';
|
|
8
|
+
import { useAsyncState } from './useAsyncState';
|
|
9
|
+
|
|
10
|
+
export interface UsePromptGenerationState {
|
|
11
|
+
generatedPrompt: GeneratedPrompt | null;
|
|
12
|
+
history: GeneratedPrompt[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UsePromptGenerationActions {
|
|
16
|
+
generatePrompt: (
|
|
17
|
+
templateId: string,
|
|
18
|
+
variables: Record<string, unknown>
|
|
19
|
+
) => Promise<void>;
|
|
20
|
+
loadHistory: (limit?: number) => Promise<void>;
|
|
21
|
+
clearHistory: () => Promise<void>;
|
|
22
|
+
saveToHistory: (prompt: GeneratedPrompt) => Promise<void>;
|
|
23
|
+
clearPrompt: () => void;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const usePromptGeneration = (
|
|
28
|
+
templateRepository: ITemplateRepository,
|
|
29
|
+
promptService: IPromptGenerationService,
|
|
30
|
+
historyRepository: IPromptHistoryRepository
|
|
31
|
+
): UsePromptGenerationState & UsePromptGenerationActions => {
|
|
32
|
+
const {
|
|
33
|
+
data: generatedPrompt,
|
|
34
|
+
loading,
|
|
35
|
+
error,
|
|
36
|
+
setError,
|
|
37
|
+
setData: setGeneratedPrompt,
|
|
38
|
+
clearError,
|
|
39
|
+
} = useAsyncState<GeneratedPrompt>(null);
|
|
40
|
+
|
|
41
|
+
const [history, setHistory] = useState<GeneratedPrompt[]>([]);
|
|
42
|
+
|
|
43
|
+
const generatePrompt = useCallback(
|
|
44
|
+
async (templateId: string, variables: Record<string, unknown>): Promise<void> => {
|
|
45
|
+
clearError();
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const templateResult = await templateRepository.findById(templateId);
|
|
49
|
+
if (!templateResult.success || !templateResult.data) {
|
|
50
|
+
setError('Template not found');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const promptResult = await promptService.generateFromTemplate(
|
|
55
|
+
templateResult.data,
|
|
56
|
+
variables
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (!promptResult.success) {
|
|
60
|
+
setError(('message' in promptResult && promptResult.message) || 'Failed to generate prompt');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const newPrompt = createGeneratedPrompt({
|
|
65
|
+
templateId,
|
|
66
|
+
generatedText: promptResult.data,
|
|
67
|
+
variables,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await historyRepository.save(newPrompt);
|
|
71
|
+
setGeneratedPrompt(newPrompt);
|
|
72
|
+
|
|
73
|
+
await loadHistory(50);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
setError('An unexpected error occurred');
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[templateRepository, promptService, historyRepository, setGeneratedPrompt, setError, clearError]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const loadHistory = useCallback(
|
|
82
|
+
async (limit: number = 50): Promise<void> => {
|
|
83
|
+
clearError();
|
|
84
|
+
try {
|
|
85
|
+
const result = await historyRepository.findRecent(limit);
|
|
86
|
+
if (result.success) {
|
|
87
|
+
setHistory(result.data);
|
|
88
|
+
} else {
|
|
89
|
+
setError(('message' in result && result.message) || 'Failed to load history');
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
setError('Failed to load history');
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
[historyRepository, setHistory, setError, clearError]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const clearHistory = useCallback(async (): Promise<void> => {
|
|
99
|
+
clearError();
|
|
100
|
+
try {
|
|
101
|
+
await historyRepository.clear();
|
|
102
|
+
setHistory([]);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
setError('Failed to clear history');
|
|
105
|
+
}
|
|
106
|
+
}, [historyRepository, setHistory, setError, clearError]);
|
|
107
|
+
|
|
108
|
+
const saveToHistory = useCallback(
|
|
109
|
+
async (prompt: GeneratedPrompt): Promise<void> => {
|
|
110
|
+
clearError();
|
|
111
|
+
try {
|
|
112
|
+
await historyRepository.save(prompt);
|
|
113
|
+
await loadHistory(50);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
setError('Failed to save to history');
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[historyRepository, loadHistory, setError, clearError]
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const clearPrompt = useCallback(() => {
|
|
122
|
+
setGeneratedPrompt(null);
|
|
123
|
+
clearError();
|
|
124
|
+
}, [setGeneratedPrompt, clearError]);
|
|
125
|
+
|
|
126
|
+
const reset = useCallback(() => {
|
|
127
|
+
setGeneratedPrompt(null);
|
|
128
|
+
setHistory([]);
|
|
129
|
+
clearError();
|
|
130
|
+
}, [setGeneratedPrompt, setHistory, clearError]);
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
generatedPrompt,
|
|
134
|
+
history,
|
|
135
|
+
loading,
|
|
136
|
+
error,
|
|
137
|
+
generatePrompt,
|
|
138
|
+
loadHistory,
|
|
139
|
+
clearHistory,
|
|
140
|
+
saveToHistory,
|
|
141
|
+
clearPrompt,
|
|
142
|
+
reset,
|
|
143
|
+
} as UsePromptGenerationState & UsePromptGenerationActions;
|
|
144
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import type { StyleTransferConfig } from '../../domain/entities/StyleTransferConfig';
|
|
3
|
+
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
4
|
+
import type { IStyleTransferService } from '../../domain/repositories/IAIPromptServices';
|
|
5
|
+
import { StyleTransferService } from '../../infrastructure/services/StyleTransferService';
|
|
6
|
+
import type { ITemplateRepository } from '../../domain/repositories/ITemplateRepository';
|
|
7
|
+
import type { IPromptHistoryRepository } from '../../domain/repositories/IPromptHistoryRepository';
|
|
8
|
+
import { createGeneratedPrompt } from '../../domain/entities/GeneratedPrompt';
|
|
9
|
+
import { useAsyncState } from './useAsyncState';
|
|
10
|
+
|
|
11
|
+
export interface StyleTransferResult {
|
|
12
|
+
template: AIPromptTemplate;
|
|
13
|
+
config: StyleTransferConfig;
|
|
14
|
+
appliedStyle: string;
|
|
15
|
+
expectedQuality: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface UseStyleTransferState {
|
|
19
|
+
generatedPrompt: string | null;
|
|
20
|
+
lastResult: StyleTransferResult | null;
|
|
21
|
+
availableStyles: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UseStyleTransferActions {
|
|
25
|
+
transferStyle: (config: StyleTransferConfig) => Promise<void>;
|
|
26
|
+
getAvailableStyles: () => Promise<string[]>;
|
|
27
|
+
registerStyle: (style: string) => void;
|
|
28
|
+
clearPrompt: () => void;
|
|
29
|
+
reset: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const useStyleTransfer = (
|
|
33
|
+
service: IStyleTransferService,
|
|
34
|
+
templateRepository: ITemplateRepository,
|
|
35
|
+
historyRepository: IPromptHistoryRepository
|
|
36
|
+
): UseStyleTransferState & UseStyleTransferActions => {
|
|
37
|
+
const {
|
|
38
|
+
data: lastResult,
|
|
39
|
+
setData: setResult,
|
|
40
|
+
clearError,
|
|
41
|
+
setError,
|
|
42
|
+
} = useAsyncState<StyleTransferResult>(null);
|
|
43
|
+
|
|
44
|
+
const [availableStyles, setAvailableStyles] = useState<string[]>([]);
|
|
45
|
+
|
|
46
|
+
const transferStyle = useCallback(async (config: StyleTransferConfig): Promise<void> => {
|
|
47
|
+
clearError();
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const templateResult = await service.generateTemplate(config);
|
|
51
|
+
if (!templateResult.success || !templateResult.data) {
|
|
52
|
+
setError('Failed to generate template');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const promptResult = await service.generatePrompt(templateResult.data, config);
|
|
57
|
+
if (!promptResult.success) {
|
|
58
|
+
setError('Failed to generate style transfer prompt');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const generatedPrompt = createGeneratedPrompt({
|
|
63
|
+
templateId: templateResult.data.id,
|
|
64
|
+
generatedText: promptResult.data,
|
|
65
|
+
variables: {} as Record<string, unknown>,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await historyRepository.save(generatedPrompt);
|
|
69
|
+
|
|
70
|
+
const transferResult: StyleTransferResult = {
|
|
71
|
+
template: templateResult.data,
|
|
72
|
+
config,
|
|
73
|
+
appliedStyle: config.targetStyle,
|
|
74
|
+
expectedQuality: Math.round(config.styleStrength * 100),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
setResult(transferResult);
|
|
78
|
+
} catch {
|
|
79
|
+
setError('An unexpected error occurred during style transfer');
|
|
80
|
+
}
|
|
81
|
+
}, [service, historyRepository, setError, setResult, clearError]);
|
|
82
|
+
|
|
83
|
+
const getAvailableStyles = useCallback(async (): Promise<string[]> => {
|
|
84
|
+
try {
|
|
85
|
+
const styles = await service.getAvailableStyles();
|
|
86
|
+
setAvailableStyles(styles);
|
|
87
|
+
return styles;
|
|
88
|
+
} catch {
|
|
89
|
+
setError('Failed to load available styles');
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
}, [service, setError]);
|
|
93
|
+
|
|
94
|
+
const registerStyle = useCallback((style: string): void => {
|
|
95
|
+
if (service instanceof StyleTransferService) {
|
|
96
|
+
service.registerStyle(style);
|
|
97
|
+
setAvailableStyles(prev => [...prev, style]);
|
|
98
|
+
}
|
|
99
|
+
}, [service]);
|
|
100
|
+
|
|
101
|
+
const clearPrompt = useCallback(() => {
|
|
102
|
+
setResult(null);
|
|
103
|
+
clearError();
|
|
104
|
+
}, [setResult, clearError]);
|
|
105
|
+
|
|
106
|
+
const reset = useCallback(() => {
|
|
107
|
+
setResult(null);
|
|
108
|
+
clearError();
|
|
109
|
+
}, [setResult, clearError]);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
getAvailableStyles();
|
|
113
|
+
}, [getAvailableStyles]);
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
generatedPrompt: null,
|
|
117
|
+
lastResult,
|
|
118
|
+
availableStyles,
|
|
119
|
+
transferStyle,
|
|
120
|
+
getAvailableStyles,
|
|
121
|
+
registerStyle,
|
|
122
|
+
clearPrompt,
|
|
123
|
+
reset,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
3
|
+
import type { AIPromptCategory, AIPromptResult } from '../../domain/entities/types';
|
|
4
|
+
import type { ITemplateRepository } from '../../domain/repositories/ITemplateRepository';
|
|
5
|
+
import { useAsyncState } from './useAsyncState';
|
|
6
|
+
|
|
7
|
+
export interface UseTemplateState {
|
|
8
|
+
templates: AIPromptTemplate[];
|
|
9
|
+
currentTemplate: AIPromptTemplate | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface UseTemplateActions {
|
|
13
|
+
loadAllTemplates: () => Promise<void>;
|
|
14
|
+
loadTemplateById: (id: string) => Promise<AIPromptTemplate | null>;
|
|
15
|
+
loadTemplatesByCategory: (category: AIPromptCategory) => Promise<AIPromptTemplate[]>;
|
|
16
|
+
saveTemplate: (template: AIPromptTemplate) => Promise<void>;
|
|
17
|
+
deleteTemplate: (id: string) => Promise<void>;
|
|
18
|
+
setCurrentTemplate: (template: AIPromptTemplate | null) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useTemplateRepository = (
|
|
22
|
+
repository: ITemplateRepository
|
|
23
|
+
): UseTemplateState & UseTemplateActions => {
|
|
24
|
+
const {
|
|
25
|
+
data: templates,
|
|
26
|
+
setData: setTemplates,
|
|
27
|
+
loading,
|
|
28
|
+
error,
|
|
29
|
+
setError,
|
|
30
|
+
clearError,
|
|
31
|
+
} = useAsyncState<AIPromptTemplate[]>([]);
|
|
32
|
+
|
|
33
|
+
const [currentTemplate, setCurrentTemplate] = useState<AIPromptTemplate | null>(null);
|
|
34
|
+
|
|
35
|
+
const loadAllTemplates = useCallback(async (): Promise<void> => {
|
|
36
|
+
clearError();
|
|
37
|
+
const result = await repository.findAll();
|
|
38
|
+
|
|
39
|
+
if (result.success) {
|
|
40
|
+
setTemplates(result.data);
|
|
41
|
+
} else {
|
|
42
|
+
setError(('message' in result && result.message) || 'Failed to load templates');
|
|
43
|
+
}
|
|
44
|
+
}, [repository, setTemplates, setError, clearError]);
|
|
45
|
+
|
|
46
|
+
const loadTemplateById = useCallback(async (id: string): Promise<AIPromptTemplate | null> => {
|
|
47
|
+
clearError();
|
|
48
|
+
const result = await repository.findById(id);
|
|
49
|
+
|
|
50
|
+
if (result.success) {
|
|
51
|
+
setCurrentTemplate(result.data);
|
|
52
|
+
return result.data;
|
|
53
|
+
} else {
|
|
54
|
+
setError(('message' in result && result.message) || 'Failed to load template');
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}, [repository, setError, clearError]);
|
|
58
|
+
|
|
59
|
+
const loadTemplatesByCategory = useCallback(
|
|
60
|
+
async (category: AIPromptCategory): Promise<AIPromptTemplate[]> => {
|
|
61
|
+
clearError();
|
|
62
|
+
const result = await repository.findByCategory(category);
|
|
63
|
+
|
|
64
|
+
if (result.success) {
|
|
65
|
+
setTemplates(result.data);
|
|
66
|
+
return result.data;
|
|
67
|
+
} else {
|
|
68
|
+
setError(('message' in result && result.message) || 'Failed to load templates by category');
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[repository, setTemplates, setError, clearError]
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const saveTemplate = useCallback(async (template: AIPromptTemplate): Promise<void> => {
|
|
76
|
+
clearError();
|
|
77
|
+
const result = await repository.save(template);
|
|
78
|
+
|
|
79
|
+
if (result.success) {
|
|
80
|
+
loadAllTemplates();
|
|
81
|
+
} else {
|
|
82
|
+
setError(('message' in result && result.message) || 'Failed to save template');
|
|
83
|
+
}
|
|
84
|
+
}, [repository, loadAllTemplates, setError, clearError]);
|
|
85
|
+
|
|
86
|
+
const deleteTemplate = useCallback(async (id: string): Promise<void> => {
|
|
87
|
+
clearError();
|
|
88
|
+
const result = await repository.delete(id);
|
|
89
|
+
|
|
90
|
+
if (result.success) {
|
|
91
|
+
if (currentTemplate?.id === id) {
|
|
92
|
+
setCurrentTemplate(null);
|
|
93
|
+
}
|
|
94
|
+
loadAllTemplates();
|
|
95
|
+
} else {
|
|
96
|
+
setError(('message' in result && result.message) || 'Failed to delete template');
|
|
97
|
+
}
|
|
98
|
+
}, [repository, currentTemplate, loadAllTemplates, setError, clearError]);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
templates: templates || [],
|
|
102
|
+
currentTemplate,
|
|
103
|
+
loading,
|
|
104
|
+
error,
|
|
105
|
+
loadAllTemplates,
|
|
106
|
+
loadTemplateById,
|
|
107
|
+
loadTemplatesByCategory,
|
|
108
|
+
saveTemplate,
|
|
109
|
+
deleteTemplate,
|
|
110
|
+
setCurrentTemplate,
|
|
111
|
+
clearError,
|
|
112
|
+
} as UseTemplateState & UseTemplateActions;
|
|
113
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Theme } from './types';
|
|
2
|
+
import { defaultTheme } from './types';
|
|
3
|
+
|
|
4
|
+
let currentTheme = defaultTheme;
|
|
5
|
+
|
|
6
|
+
export const useTheme = (): Theme => currentTheme;
|
|
7
|
+
|
|
8
|
+
export const setTheme = (theme: Partial<Theme>): void => {
|
|
9
|
+
currentTheme = { ...currentTheme, ...theme };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getTheme = (): Theme => currentTheme;
|
|
13
|
+
|
|
14
|
+
export const resetTheme = (): void => {
|
|
15
|
+
currentTheme = defaultTheme;
|
|
16
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface ThemeColors {
|
|
2
|
+
primary: string;
|
|
3
|
+
secondary: string;
|
|
4
|
+
background: string;
|
|
5
|
+
surface: string;
|
|
6
|
+
text: string;
|
|
7
|
+
textSecondary: string;
|
|
8
|
+
border: string;
|
|
9
|
+
error: string;
|
|
10
|
+
warning: string;
|
|
11
|
+
success: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ThemeSpacing {
|
|
15
|
+
xs: number;
|
|
16
|
+
sm: number;
|
|
17
|
+
md: number;
|
|
18
|
+
lg: number;
|
|
19
|
+
xl: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ThemeTypography {
|
|
23
|
+
heading: {
|
|
24
|
+
fontSize: number;
|
|
25
|
+
fontWeight: string;
|
|
26
|
+
};
|
|
27
|
+
body: {
|
|
28
|
+
fontSize: number;
|
|
29
|
+
fontWeight: string;
|
|
30
|
+
};
|
|
31
|
+
caption: {
|
|
32
|
+
fontSize: number;
|
|
33
|
+
fontWeight: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Theme {
|
|
38
|
+
colors: ThemeColors;
|
|
39
|
+
spacing: ThemeSpacing;
|
|
40
|
+
typography: ThemeTypography;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const createTheme = (customTheme?: Partial<Theme>): Theme => ({
|
|
44
|
+
colors: {
|
|
45
|
+
primary: '#007AFF',
|
|
46
|
+
secondary: '#5856D6',
|
|
47
|
+
background: '#FFFFFF',
|
|
48
|
+
surface: '#F2F2F7',
|
|
49
|
+
text: '#000000',
|
|
50
|
+
textSecondary: '#8E8E93',
|
|
51
|
+
border: '#C6C6C8',
|
|
52
|
+
error: '#FF3B30',
|
|
53
|
+
warning: '#FF9500',
|
|
54
|
+
success: '#34C759',
|
|
55
|
+
...customTheme?.colors,
|
|
56
|
+
},
|
|
57
|
+
spacing: {
|
|
58
|
+
xs: 4,
|
|
59
|
+
sm: 8,
|
|
60
|
+
md: 16,
|
|
61
|
+
lg: 24,
|
|
62
|
+
xl: 32,
|
|
63
|
+
...customTheme?.spacing,
|
|
64
|
+
},
|
|
65
|
+
typography: {
|
|
66
|
+
heading: {
|
|
67
|
+
fontSize: 24,
|
|
68
|
+
fontWeight: 'bold',
|
|
69
|
+
},
|
|
70
|
+
body: {
|
|
71
|
+
fontSize: 16,
|
|
72
|
+
fontWeight: 'normal',
|
|
73
|
+
},
|
|
74
|
+
caption: {
|
|
75
|
+
fontSize: 12,
|
|
76
|
+
fontWeight: 'normal',
|
|
77
|
+
},
|
|
78
|
+
...customTheme?.typography,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const defaultTheme = createTheme();
|