@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,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moderators Index
|
|
3
|
+
* Exports all content moderators
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { textModerator } from "./text.moderator";
|
|
7
|
+
export { imageModerator } from "./image.moderator";
|
|
8
|
+
export { videoModerator } from "./video.moderator";
|
|
9
|
+
export { voiceModerator } from "./voice.moderator";
|
|
10
|
+
export { BaseModerator, type ModerationResult } from "./base.moderator";
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Content Moderator
|
|
3
|
+
* Validates and moderates text content
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Violation } from "../../../domain/entities/moderation.types";
|
|
7
|
+
import { patternMatcherService } from "../pattern-matcher.service";
|
|
8
|
+
import { rulesRegistry } from "../../rules/rules-registry";
|
|
9
|
+
import { BaseModerator, type ModerationResult } from "./base.moderator";
|
|
10
|
+
|
|
11
|
+
declare const __DEV__: boolean;
|
|
12
|
+
|
|
13
|
+
const DEFAULT_MAX_LENGTH = 10000;
|
|
14
|
+
|
|
15
|
+
const MALICIOUS_CODE_PATTERNS = [
|
|
16
|
+
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
17
|
+
/javascript:/gi,
|
|
18
|
+
/on\w+\s*=/gi,
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const PROMPT_INJECTION_PATTERNS = [
|
|
22
|
+
/ignore\s+(all\s+)?(previous|prior|above)\s+(instructions?|prompts?|rules?)/gi,
|
|
23
|
+
/disregard\s+(all\s+)?(previous|prior|above)\s+(instructions?|prompts?)/gi,
|
|
24
|
+
/forget\s+(all\s+)?(previous|prior|your)\s+(instructions?|prompts?|rules?)/gi,
|
|
25
|
+
/you\s+are\s+now\s+(a|an)\s+/gi,
|
|
26
|
+
/act\s+as\s+(if|though)\s+you/gi,
|
|
27
|
+
/pretend\s+(you\s+are|to\s+be)/gi,
|
|
28
|
+
/bypass\s+(your\s+)?(safety|content|moderation)/gi,
|
|
29
|
+
/override\s+(your\s+)?(restrictions?|limitations?|rules?)/gi,
|
|
30
|
+
/jailbreak/gi,
|
|
31
|
+
/DAN\s*mode/gi,
|
|
32
|
+
/developer\s+mode\s+(enabled|on|activated)/gi,
|
|
33
|
+
/system\s*:\s*/gi,
|
|
34
|
+
/\[system\]/gi,
|
|
35
|
+
/<<\s*sys\s*>>/gi,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
class TextModerator extends BaseModerator {
|
|
39
|
+
private maxLength = DEFAULT_MAX_LENGTH;
|
|
40
|
+
|
|
41
|
+
setMaxLength(length: number): void {
|
|
42
|
+
this.maxLength = length;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
moderate(content: string): ModerationResult {
|
|
46
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log("[TextModerator] moderate() called", {
|
|
49
|
+
contentLength: content?.length ?? 0,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const validationError = this.validate(content);
|
|
54
|
+
if (validationError) {
|
|
55
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.log("[TextModerator] validation failed", {
|
|
58
|
+
ruleId: validationError.ruleId,
|
|
59
|
+
violationType: validationError.violationType,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return { isAllowed: false, violations: [validationError] };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const violations = this.evaluateRules(content);
|
|
66
|
+
|
|
67
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.log("[TextModerator] moderate() completed", {
|
|
70
|
+
isAllowed: violations.length === 0,
|
|
71
|
+
violationsCount: violations.length,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { isAllowed: violations.length === 0, violations };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private validate(content: string): Violation | null {
|
|
79
|
+
if (!content || typeof content !== "string") {
|
|
80
|
+
return this.createViolation("empty-content", "Validation", "empty");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (content.length > this.maxLength) {
|
|
84
|
+
return this.createViolation("too-long", "Validation", "length exceeded");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (this.containsMaliciousCode(content)) {
|
|
88
|
+
return this.createViolation(
|
|
89
|
+
"malicious",
|
|
90
|
+
"Security",
|
|
91
|
+
"malicious code",
|
|
92
|
+
"dangerous_content"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (this.containsPromptInjection(content)) {
|
|
97
|
+
return this.createViolation(
|
|
98
|
+
"prompt-injection",
|
|
99
|
+
"Security",
|
|
100
|
+
"prompt injection",
|
|
101
|
+
"dangerous_content"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private containsMaliciousCode(content: string): boolean {
|
|
109
|
+
return MALICIOUS_CODE_PATTERNS.some((pattern) => pattern.test(content));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private containsPromptInjection(content: string): boolean {
|
|
113
|
+
return PROMPT_INJECTION_PATTERNS.some((pattern) => pattern.test(content));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private evaluateRules(content: string): Violation[] {
|
|
117
|
+
const rules = rulesRegistry.getRulesByContentType("text");
|
|
118
|
+
const violations: Violation[] = [];
|
|
119
|
+
|
|
120
|
+
for (const rule of rules) {
|
|
121
|
+
const matches = patternMatcherService.matchAnyPattern(
|
|
122
|
+
content,
|
|
123
|
+
rule.patterns
|
|
124
|
+
);
|
|
125
|
+
const matched = matches.find((m) => m.matched);
|
|
126
|
+
|
|
127
|
+
if (matched) {
|
|
128
|
+
violations.push({
|
|
129
|
+
ruleId: rule.id,
|
|
130
|
+
ruleName: rule.name,
|
|
131
|
+
violationType: rule.violationType,
|
|
132
|
+
severity: rule.severity,
|
|
133
|
+
matchedPattern: matched.matchedText || "",
|
|
134
|
+
context: content.slice(0, 100),
|
|
135
|
+
suggestion: this.getSuggestion(rule.violationType),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return violations;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const textModerator = new TextModerator();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video Content Moderator
|
|
3
|
+
* Validates and moderates video URIs
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Violation } from "../../../domain/entities/moderation.types";
|
|
7
|
+
import { BaseModerator, type ModerationResult } from "./base.moderator";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_PROTOCOLS = ["http:", "https:", "file:"];
|
|
10
|
+
const DEFAULT_MAX_URI_LENGTH = 2048;
|
|
11
|
+
|
|
12
|
+
class VideoModerator extends BaseModerator {
|
|
13
|
+
private allowedProtocols = DEFAULT_PROTOCOLS;
|
|
14
|
+
private maxUriLength = DEFAULT_MAX_URI_LENGTH;
|
|
15
|
+
|
|
16
|
+
setAllowedProtocols(protocols: string[]): void {
|
|
17
|
+
this.allowedProtocols = protocols;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setMaxUriLength(length: number): void {
|
|
21
|
+
this.maxUriLength = length;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
moderate(videoUri: string): ModerationResult {
|
|
25
|
+
const validationError = this.validate(videoUri);
|
|
26
|
+
if (validationError) {
|
|
27
|
+
return { isAllowed: false, violations: [validationError] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { isAllowed: true, violations: [] };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private validate(uri: string): Violation | null {
|
|
34
|
+
if (!uri || typeof uri !== "string") {
|
|
35
|
+
return this.createViolation("empty-uri", "Video Validation", "empty URI");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (uri.length > this.maxUriLength) {
|
|
39
|
+
return this.createViolation(
|
|
40
|
+
"uri-too-long",
|
|
41
|
+
"Video Validation",
|
|
42
|
+
"URI too long"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!this.hasValidProtocol(uri)) {
|
|
47
|
+
return this.createViolation(
|
|
48
|
+
"invalid-protocol",
|
|
49
|
+
"Video Validation",
|
|
50
|
+
"invalid protocol"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private hasValidProtocol(uri: string): boolean {
|
|
58
|
+
return this.allowedProtocols.some((protocol) =>
|
|
59
|
+
uri.toLowerCase().startsWith(protocol)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const videoModerator = new VideoModerator();
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice Content Moderator
|
|
3
|
+
* Validates and moderates voice/TTS text content
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Violation } from "../../../domain/entities/moderation.types";
|
|
7
|
+
import { patternMatcherService } from "../pattern-matcher.service";
|
|
8
|
+
import { rulesRegistry } from "../../rules/rules-registry";
|
|
9
|
+
import { BaseModerator, type ModerationResult } from "./base.moderator";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_MAX_LENGTH = 5000;
|
|
12
|
+
|
|
13
|
+
class VoiceModerator extends BaseModerator {
|
|
14
|
+
private maxLength = DEFAULT_MAX_LENGTH;
|
|
15
|
+
|
|
16
|
+
setMaxLength(length: number): void {
|
|
17
|
+
this.maxLength = length;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
moderate(text: string): ModerationResult {
|
|
21
|
+
const validationError = this.validate(text);
|
|
22
|
+
if (validationError) {
|
|
23
|
+
return { isAllowed: false, violations: [validationError] };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const violations = this.evaluateRules(text);
|
|
27
|
+
return { isAllowed: violations.length === 0, violations };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private validate(text: string): Violation | null {
|
|
31
|
+
if (!text || typeof text !== "string") {
|
|
32
|
+
return this.createViolation("empty-text", "Voice Validation", "empty");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (text.length > this.maxLength) {
|
|
36
|
+
return this.createViolation(
|
|
37
|
+
"too-long",
|
|
38
|
+
"Voice Validation",
|
|
39
|
+
"length exceeded"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private evaluateRules(text: string): Violation[] {
|
|
47
|
+
const rules = rulesRegistry.getRulesByContentType("voice");
|
|
48
|
+
const violations: Violation[] = [];
|
|
49
|
+
|
|
50
|
+
for (const rule of rules) {
|
|
51
|
+
const matches = patternMatcherService.matchAnyPattern(
|
|
52
|
+
text,
|
|
53
|
+
rule.patterns
|
|
54
|
+
);
|
|
55
|
+
const matched = matches.find((m) => m.matched);
|
|
56
|
+
|
|
57
|
+
if (matched) {
|
|
58
|
+
violations.push({
|
|
59
|
+
ruleId: rule.id,
|
|
60
|
+
ruleName: rule.name,
|
|
61
|
+
violationType: rule.violationType,
|
|
62
|
+
severity: rule.severity,
|
|
63
|
+
matchedPattern: matched.matchedText || "",
|
|
64
|
+
context: text.slice(0, 100),
|
|
65
|
+
suggestion: this.getSuggestion(rule.violationType),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return violations;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const voiceModerator = new VoiceModerator();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Matcher Service
|
|
3
|
+
* Utility service for regex pattern matching
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface PatternMatch {
|
|
7
|
+
pattern: string;
|
|
8
|
+
matched: boolean;
|
|
9
|
+
matchedText?: string;
|
|
10
|
+
position?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class PatternMatcherService {
|
|
14
|
+
matchPattern(content: string, pattern: string): PatternMatch {
|
|
15
|
+
try {
|
|
16
|
+
const regex = new RegExp(pattern, "gi");
|
|
17
|
+
const match = regex.exec(content);
|
|
18
|
+
|
|
19
|
+
if (match) {
|
|
20
|
+
return {
|
|
21
|
+
pattern,
|
|
22
|
+
matched: true,
|
|
23
|
+
matchedText: match[0],
|
|
24
|
+
position: match.index,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return { pattern, matched: false };
|
|
29
|
+
} catch {
|
|
30
|
+
return { pattern, matched: false };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
matchAnyPattern(content: string, patterns: string[]): PatternMatch[] {
|
|
35
|
+
return patterns.map((pattern) => this.matchPattern(content, pattern));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
matchAllPatterns(content: string, patterns: string[]): boolean {
|
|
39
|
+
return patterns.every(
|
|
40
|
+
(pattern) => this.matchPattern(content, pattern).matched
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
hasAnyMatch(content: string, patterns: string[]): boolean {
|
|
45
|
+
return patterns.some(
|
|
46
|
+
(pattern) => this.matchPattern(content, pattern).matched
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const patternMatcherService = new PatternMatcherService();
|
package/src/domains/content-moderation/presentation/exceptions/content-policy-violation.exception.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Policy Violation Exception
|
|
3
|
+
* Custom error class for content policy violations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
Violation,
|
|
8
|
+
ViolationType,
|
|
9
|
+
} from "../../domain/entities/moderation.types";
|
|
10
|
+
|
|
11
|
+
export class ContentPolicyViolationError extends Error {
|
|
12
|
+
public readonly violations: Violation[];
|
|
13
|
+
|
|
14
|
+
constructor(violations: Violation[], message?: string) {
|
|
15
|
+
const defaultMessage = `Content policy violation: ${violations
|
|
16
|
+
.map((v) => v.ruleName)
|
|
17
|
+
.join(", ")}`;
|
|
18
|
+
super(message || defaultMessage);
|
|
19
|
+
this.name = "ContentPolicyViolationError";
|
|
20
|
+
this.violations = violations;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getUserMessage(): string {
|
|
24
|
+
if (this.violations.length === 0) {
|
|
25
|
+
return "Content policy violation detected.";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const firstViolation = this.violations[0];
|
|
29
|
+
return firstViolation?.suggestion || "Please modify your content.";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getViolationTypes(): ViolationType[] {
|
|
33
|
+
return this.violations.map((v) => v.violationType);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
hasViolationType(type: ViolationType): boolean {
|
|
37
|
+
return this.violations.some((v) => v.violationType === type);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getSeverityLevel(): "low" | "medium" | "high" | "critical" {
|
|
41
|
+
const severities = this.violations.map((v) => v.severity);
|
|
42
|
+
|
|
43
|
+
if (severities.includes("critical")) return "critical";
|
|
44
|
+
if (severities.includes("high")) return "high";
|
|
45
|
+
if (severities.includes("medium")) return "medium";
|
|
46
|
+
return "low";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AIPromptCategory } from './types';
|
|
2
|
+
import type { AIPromptVariable, AIPromptSafety, AIPromptVersion } from './value-objects';
|
|
3
|
+
import { createPromptVersion, formatVersion } from './value-objects';
|
|
4
|
+
|
|
5
|
+
export interface AIPromptTemplate {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly description: string;
|
|
9
|
+
readonly category: AIPromptCategory;
|
|
10
|
+
readonly template: string;
|
|
11
|
+
readonly variables: readonly AIPromptVariable[];
|
|
12
|
+
readonly safety: AIPromptSafety;
|
|
13
|
+
readonly version: AIPromptVersion;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CreateAIPromptTemplateParams {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
category: AIPromptCategory;
|
|
21
|
+
template: string;
|
|
22
|
+
variables?: AIPromptVariable[];
|
|
23
|
+
safety: AIPromptSafety;
|
|
24
|
+
version: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const createAIPromptTemplate = (
|
|
28
|
+
params: CreateAIPromptTemplateParams
|
|
29
|
+
): AIPromptTemplate => ({
|
|
30
|
+
id: params.id,
|
|
31
|
+
name: params.name,
|
|
32
|
+
description: params.description,
|
|
33
|
+
category: params.category,
|
|
34
|
+
template: params.template,
|
|
35
|
+
variables: params.variables || [],
|
|
36
|
+
safety: params.safety,
|
|
37
|
+
version: createPromptVersion(params.version),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const updateTemplateVersion = (
|
|
41
|
+
template: AIPromptTemplate,
|
|
42
|
+
newVersion: string
|
|
43
|
+
): AIPromptTemplate => ({
|
|
44
|
+
...template,
|
|
45
|
+
version: createPromptVersion(newVersion),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const getTemplateString = (template: AIPromptTemplate): string => formatVersion(template.version);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AIPromptTemplate } from './AIPromptTemplate';
|
|
2
|
+
|
|
3
|
+
export interface BackgroundRemovalConfig {
|
|
4
|
+
precision: 'fast' | 'accurate' | 'ultra-accurate';
|
|
5
|
+
edgeRefinement: boolean;
|
|
6
|
+
preserveHair: boolean;
|
|
7
|
+
outputFormat: 'png' | 'webp' | 'transparent';
|
|
8
|
+
addNewBackground?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BackgroundRemovalTemplate {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly basePrompt: string;
|
|
16
|
+
readonly variables: BackgroundRemovalVariable[];
|
|
17
|
+
readonly processing: BackgroundRemovalSettings;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface BackgroundRemovalVariable {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
required: boolean;
|
|
24
|
+
options?: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BackgroundRemovalSettings {
|
|
28
|
+
supportedFormats: string[];
|
|
29
|
+
maxResolution: number;
|
|
30
|
+
processingTimes: Record<string, number>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BackgroundRemovalResult {
|
|
34
|
+
template: AIPromptTemplate;
|
|
35
|
+
config: BackgroundRemovalConfig;
|
|
36
|
+
estimatedProcessingTime: number;
|
|
37
|
+
qualityScore: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface DetectedObject {
|
|
41
|
+
type: string;
|
|
42
|
+
confidence: number;
|
|
43
|
+
boundingBox: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const validateBackgroundRemovalConfig = (config: BackgroundRemovalConfig): boolean => {
|
|
52
|
+
return !!(
|
|
53
|
+
config.precision &&
|
|
54
|
+
config.outputFormat &&
|
|
55
|
+
['png', 'webp', 'transparent'].includes(config.outputFormat)
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const createBackgroundRemovalVariable = (
|
|
60
|
+
name: string,
|
|
61
|
+
description: string,
|
|
62
|
+
required: boolean = true,
|
|
63
|
+
options?: string[]
|
|
64
|
+
): BackgroundRemovalVariable => ({
|
|
65
|
+
name,
|
|
66
|
+
description,
|
|
67
|
+
required,
|
|
68
|
+
options,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const getProcessingTime = (precision: BackgroundRemovalConfig['precision']): number => {
|
|
72
|
+
switch (precision) {
|
|
73
|
+
case 'fast': return 2;
|
|
74
|
+
case 'accurate': return 5;
|
|
75
|
+
case 'ultra-accurate': return 10;
|
|
76
|
+
default: return 5;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const getQualityScore = (config: BackgroundRemovalConfig): number => {
|
|
81
|
+
let score = config.edgeRefinement ? 0.9 : 0.7;
|
|
82
|
+
if (config.preserveHair) score += 0.05;
|
|
83
|
+
if (config.precision === 'ultra-accurate') score += 0.15;
|
|
84
|
+
if (config.precision === 'accurate') score += 0.1;
|
|
85
|
+
return Math.min(score, 1.0);
|
|
86
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { AIPromptTemplate } from './AIPromptTemplate';
|
|
2
|
+
|
|
3
|
+
export interface ColorizationConfig {
|
|
4
|
+
targetType: 'black-and-white' | 'sepia' | 'faded' | 'damaged';
|
|
5
|
+
colorMode: 'realistic' | 'vibrant' | 'artistic' | 'vintage';
|
|
6
|
+
preserveOriginal: boolean;
|
|
7
|
+
adjustLighting: boolean;
|
|
8
|
+
skinTonePreservation: boolean;
|
|
9
|
+
era?: '1920s' | '1940s' | '1960s' | '1980s' | 'victorian';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ColorizationTemplate {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly description: string;
|
|
16
|
+
readonly basePrompt: string;
|
|
17
|
+
readonly variables: ColorizationVariable[];
|
|
18
|
+
readonly colorization: ColorizationSettings;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ColorizationVariable {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
required: boolean;
|
|
25
|
+
options?: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ColorizationSettings {
|
|
29
|
+
supportedModes: string[];
|
|
30
|
+
eraPresets: Record<string, string>;
|
|
31
|
+
skinToneAdjustments: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ColorizationResult {
|
|
35
|
+
template: AIPromptTemplate;
|
|
36
|
+
config: ColorizationConfig;
|
|
37
|
+
qualityScore: number;
|
|
38
|
+
colorPalette?: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const validateColorizationConfig = (config: ColorizationConfig): boolean => {
|
|
42
|
+
return !!(
|
|
43
|
+
config.targetType &&
|
|
44
|
+
config.colorMode &&
|
|
45
|
+
['realistic', 'vibrant', 'artistic', 'vintage'].includes(config.colorMode)
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const createColorizationVariable = (
|
|
50
|
+
name: string,
|
|
51
|
+
description: string,
|
|
52
|
+
required: boolean = true,
|
|
53
|
+
options?: string[]
|
|
54
|
+
): ColorizationVariable => ({
|
|
55
|
+
name,
|
|
56
|
+
description,
|
|
57
|
+
required,
|
|
58
|
+
options,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const getColorizationQuality = (config: ColorizationConfig): number => {
|
|
62
|
+
let quality = 0.8;
|
|
63
|
+
|
|
64
|
+
if (config.preserveOriginal) quality += 0.1;
|
|
65
|
+
if (config.skinTonePreservation) quality += 0.05;
|
|
66
|
+
if (config.colorMode === 'realistic') quality += 0.1;
|
|
67
|
+
if (config.targetType === 'black-and-white') quality += 0.05;
|
|
68
|
+
|
|
69
|
+
return Math.min(quality, 1.0);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const getEraDescription = (era?: string): string => {
|
|
73
|
+
switch (era) {
|
|
74
|
+
case '1920s': return '1920s vintage aesthetic with soft colors';
|
|
75
|
+
case '1940s': return '1940s wartime color palette';
|
|
76
|
+
case '1960s': return '1960s vibrant, saturated colors';
|
|
77
|
+
case '1980s': return '1980s neon and pastel tones';
|
|
78
|
+
case 'victorian': return 'Victorian era muted, elegant colors';
|
|
79
|
+
default: return 'Historically appropriate color palette';
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const getSuggestedColorPalette = (
|
|
84
|
+
targetType: ColorizationConfig['targetType'],
|
|
85
|
+
colorMode: ColorizationConfig['colorMode']
|
|
86
|
+
): string[] => {
|
|
87
|
+
switch (targetType) {
|
|
88
|
+
case 'black-and-white':
|
|
89
|
+
return colorMode === 'vibrant'
|
|
90
|
+
? ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7']
|
|
91
|
+
: ['#2C3E50', '#34495E', '#7F8C8D', '#95A5A6', '#BDC3C7'];
|
|
92
|
+
case 'sepia':
|
|
93
|
+
return ['#8B7355', '#A0826D', '#BC9A6A', '#D2B48C', '#DEB887'];
|
|
94
|
+
case 'faded':
|
|
95
|
+
return ['#E27D60', '#41B3A3', '#85DCBA', '#C1E1DC', '#E8DDCB'];
|
|
96
|
+
case 'damaged':
|
|
97
|
+
return ['#C9302C', '#F0AD4E', '#5BC0DE', '#5CB85C'];
|
|
98
|
+
default:
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AIPromptTemplate } from './AIPromptTemplate';
|
|
2
|
+
import type { GeneratedPrompt } from './GeneratedPrompt';
|
|
3
|
+
|
|
4
|
+
export interface FaceSwapConfig {
|
|
5
|
+
preserveIdentity: boolean;
|
|
6
|
+
allowHairStyle: boolean;
|
|
7
|
+
allowAccessories: boolean;
|
|
8
|
+
allowExpression: boolean;
|
|
9
|
+
environment?: string;
|
|
10
|
+
styleName: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface FaceSwapTemplate {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly basePrompt: string;
|
|
18
|
+
readonly variables: FaceSwapTemplateVariable[];
|
|
19
|
+
readonly safety: FaceSwapSafety;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FaceSwapTemplateVariable {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
required: boolean;
|
|
26
|
+
options?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FaceSwapSafety {
|
|
30
|
+
contentFilter: boolean;
|
|
31
|
+
identityPreservation: boolean;
|
|
32
|
+
adultContentFilter: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface FaceSwapGenerationResult {
|
|
36
|
+
template: AIPromptTemplate;
|
|
37
|
+
prompt: GeneratedPrompt;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const validateFaceSwapConfig = (config: FaceSwapConfig): boolean => {
|
|
41
|
+
return !!(config.styleName && config.styleName.trim().length > 0);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const createFaceSwapVariable = (
|
|
45
|
+
name: string,
|
|
46
|
+
description: string,
|
|
47
|
+
required: boolean = true,
|
|
48
|
+
options?: string[]
|
|
49
|
+
): FaceSwapTemplateVariable => ({
|
|
50
|
+
name,
|
|
51
|
+
description,
|
|
52
|
+
required,
|
|
53
|
+
options,
|
|
54
|
+
});
|