@umituz/react-native-ai-generation-content 1.90.2 → 1.90.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 +3 -3
- package/src/domain/interfaces/app-services-auth.interface.ts +27 -0
- package/src/domain/interfaces/app-services-composite.interface.ts +29 -0
- package/src/domain/interfaces/app-services-optional.interface.ts +42 -0
- package/src/domain/interfaces/app-services.interface.ts +0 -79
- package/src/domain/interfaces/index.ts +3 -0
- package/src/domains/background/infrastructure/services/job-poller-index.ts +7 -0
- package/src/domains/background/infrastructure/services/job-poller-utils.ts +127 -0
- package/src/domains/background/infrastructure/services/job-poller.service.ts +85 -140
- package/src/domains/background/infrastructure/utils/polling-interval.util.ts +1 -1
- package/src/domains/background/presentation/hooks/use-background-generation.ts +1 -1
- package/src/domains/content-moderation/index.ts +7 -13
- package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +1 -1
- package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +34 -8
- package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +15 -4
- package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +34 -8
- package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +19 -8
- package/src/domains/content-moderation/infrastructure/services/pattern-matcher.service.ts +1 -2
- package/src/domains/creations/domain/types/creation-categories.constants.ts +57 -0
- package/src/domains/creations/domain/types/creation-categories.helpers.ts +67 -0
- package/src/domains/creations/domain/types/creation-categories.ts +7 -114
- package/src/domains/creations/domain/utils/creation-display.util.ts +1 -1
- package/src/domains/creations/domain/utils/status-helpers.ts +1 -1
- package/src/domains/creations/presentation/hooks/creation-validators.ts +31 -29
- package/src/domains/creations/presentation/hooks/job-poller-index.ts +10 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.filters.ts +34 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.logger.ts +76 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.stale-handlers.ts +52 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.ts +8 -0
- package/src/domains/creations/presentation/hooks/useCreations.ts +1 -1
- package/src/domains/creations/presentation/hooks/useProcessingJobsPoller.ts +18 -235
- package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +1 -2
- package/src/domains/creations/presentation-exports.ts +2 -2
- package/src/domains/face-detection/domain/entities/FaceDetection.ts +4 -3
- package/src/domains/face-detection/presentation/hooks/useFaceDetection.ts +24 -21
- package/src/domains/generation/infrastructure/appearance-analysis/index.ts +5 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-preparation.ts +58 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-prompt.ts +69 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-resolution.ts +77 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple.ts +54 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-index.ts +8 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-scenario.ts +112 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder.ts +7 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/index.ts +20 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/types.ts +44 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-end-logger.ts +18 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-start-logger.ts +57 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-step-logger.ts +106 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/index.ts +8 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/types.ts +49 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils.ts +8 -0
- package/src/domains/generation/infrastructure/flow/flow-store-actions.ts +105 -0
- package/src/domains/generation/infrastructure/flow/flow-store-initial-state.ts +26 -0
- package/src/domains/generation/infrastructure/flow/useFlowStore.ts +4 -116
- package/src/domains/generation/presentation/useAIGeneration.hook.ts +1 -1
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation-strategy-index.ts +7 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.ts +2 -12
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.types.ts +11 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.utils.ts +12 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.strategy.ts +1 -220
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-builder.ts +66 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-extraction.ts +88 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-prompt-builder.ts +74 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-style-enhancements.ts +35 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-strategy-factory.ts +41 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor-index.ts +10 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor.ts +76 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-input-builder.ts +46 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-result-types.ts +17 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-submission.ts +61 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.audio-extractor.ts +27 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.executor.ts +2 -176
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.input-builder.ts +90 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +3 -108
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.types.ts +0 -130
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.validation.ts +136 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/index.ts +40 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/types.ts +37 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/usePhotoUploadStateLogic.ts +142 -0
- package/src/domains/generation/wizard/presentation/hooks/use-video-queue-utils.ts +102 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.handlers.ts +97 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.saver.ts +54 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.ts +22 -87
- package/src/domains/generation/wizard/presentation/hooks/usePhotoUploadState.ts +8 -177
- package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +1 -295
- package/src/domains/generation/wizard/presentation/hooks/useWizardGeneration.ts +1 -1
- package/src/domains/generation/wizard/presentation/hooks/video-queue/index.ts +77 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/use-video-queue-utils.ts +123 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationCallbacks.ts +119 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationPolling.ts +75 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationRefs.ts +65 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationStart.ts +123 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue-index.ts +9 -0
- package/src/domains/image-to-video/domain/types/image-to-video-state.types.ts +11 -4
- package/src/domains/text-to-image/domain/constants/index.ts +5 -6
- package/src/domains/text-to-image/domain/types/text-to-image.types.ts +43 -22
- package/src/domains/text-to-video/domain/types/request.types.ts +32 -9
- package/src/domains/text-to-video/domain/types/state.types.ts +22 -22
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.handlers.ts +44 -0
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.ts +5 -51
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.types.ts +33 -0
- package/src/exports/features.ts +1 -1
- package/src/infrastructure/services/generation-orchestrator.service.ts +2 -2
- package/src/infrastructure/utils/couple-input-context.ts +13 -0
- package/src/infrastructure/utils/couple-input-index.ts +9 -0
- package/src/infrastructure/utils/couple-input-photorealistic.ts +40 -0
- package/src/infrastructure/utils/couple-input-refiner.ts +101 -0
- package/src/infrastructure/utils/couple-input-resolver.ts +71 -0
- package/src/infrastructure/utils/couple-input-types.ts +11 -0
- package/src/infrastructure/utils/couple-input.util.ts +3 -176
- package/src/infrastructure/utils/photo-generation/photo-preparation.util.ts +1 -1
- package/src/infrastructure/validation/base-validator.ts +3 -26
- package/src/infrastructure/validation/base-validator.types.ts +32 -0
- package/src/presentation/hooks/generation/index.ts +1 -1
- package/src/presentation/hooks/generation/orchestrator-abort-logs.ts +48 -0
- package/src/presentation/hooks/generation/orchestrator-execution-logs.ts +67 -0
- package/src/presentation/hooks/generation/orchestrator-index.ts +14 -0
- package/src/presentation/hooks/generation/orchestrator-start-logs.ts +65 -0
- package/src/presentation/hooks/generation/orchestrator-state-utils.ts +17 -0
- package/src/presentation/hooks/generation/orchestrator-types.ts +55 -0
- package/src/presentation/hooks/generation/orchestrator-utils-index.ts +29 -0
- package/src/presentation/hooks/generation/orchestrator-utils.ts +25 -0
- package/src/presentation/hooks/generation/useDualImageGeneration.ts +1 -1
- package/src/presentation/hooks/generation/useImageGeneration.ts +1 -1
- package/src/presentation/hooks/generation/useVideoGeneration.ts +1 -1
- package/src/shared/hooks/factories/generation-hook-index.ts +12 -0
- package/src/shared/hooks/factories/generation-hook-types.ts +47 -0
- package/src/shared/hooks/factories/generation-hook-utils.ts +94 -0
- package/src/shared/hooks/factories/index.ts +1 -1
- package/src/shared/index.ts +1 -1
- package/src/shared/utils/calculations/aspect-ratio-calculations.ts +30 -0
- package/src/shared/utils/calculations/base64-calculations.ts +26 -0
- package/src/shared/utils/calculations/confidence-calculations.ts +21 -0
- package/src/shared/utils/calculations/cost-calculations-index.ts +43 -0
- package/src/shared/utils/calculations/cost-calculations.ts +25 -0
- package/src/shared/utils/calculations/credit-calculations.ts +37 -0
- package/src/shared/utils/calculations/index.ts +46 -0
- package/src/shared/utils/calculations/math-utilities.ts +32 -0
- package/src/shared/utils/calculations/memory-calculations.ts +33 -0
- package/src/shared/utils/calculations/pagination-calculations.ts +38 -0
- package/src/shared/utils/calculations/percentage-calculations.ts +33 -0
- package/src/shared/utils/calculations/time-calculations.ts +99 -0
- package/src/shared/utils/credit.ts +1 -1
- package/src/shared-kernel/application/hooks/index.ts +8 -0
- package/src/shared-kernel/application/hooks/use-feature-state.ts +106 -0
- package/src/shared-kernel/application/hooks/use-generation-handler.ts +110 -0
- package/src/shared-kernel/base-types/base-callbacks.types.ts +73 -0
- package/src/shared-kernel/base-types/base-feature-state.types.ts +77 -0
- package/src/shared-kernel/base-types/base-generation.types.ts +69 -0
- package/src/shared-kernel/base-types/index.ts +30 -0
- package/src/shared-kernel/domain/base-generation-strategy.ts +146 -0
- package/src/shared-kernel/domain/index.ts +7 -0
- package/src/shared-kernel/index.ts +17 -0
- package/src/shared-kernel/infrastructure/validation/common-validators.ts +126 -0
- package/src/shared-kernel/infrastructure/validation/common-validators.types.ts +33 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.ts +52 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.types.ts +38 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.utils.ts +79 -0
- package/src/shared-kernel/infrastructure/validation/index.ts +70 -0
- package/src/domains/content-moderation/infrastructure/services/index.ts +0 -8
- package/src/domains/creations/domain/constants/index.ts +0 -12
- package/src/domains/creations/domain/utils/index.ts +0 -12
- package/src/domains/generation/infrastructure/couple-generation-builder.ts +0 -374
- package/src/domains/image-to-video/domain/index.ts +0 -2
- package/src/domains/image-to-video/infrastructure/index.ts +0 -1
- package/src/domains/image-to-video/presentation/index.ts +0 -5
- package/src/domains/text-to-video/domain/index.ts +0 -1
- package/src/domains/text-to-video/presentation/index.ts +0 -7
- package/src/presentation/hooks/generation/orchestrator.ts +0 -276
- package/src/shared/hooks/factories/createGenerationHook.ts +0 -253
- package/src/shared/utils/calculations.util.ts +0 -366
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Validation Utilities - Types
|
|
3
|
+
* Type definitions for base validation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validation result type
|
|
8
|
+
*/
|
|
9
|
+
export interface ValidationResult {
|
|
10
|
+
readonly isValid: boolean;
|
|
11
|
+
readonly errors: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* String validation options
|
|
16
|
+
*/
|
|
17
|
+
export interface StringValidationOptions {
|
|
18
|
+
readonly minLength?: number;
|
|
19
|
+
readonly maxLength?: number;
|
|
20
|
+
readonly pattern?: RegExp;
|
|
21
|
+
readonly allowedCharacters?: RegExp;
|
|
22
|
+
readonly trim?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Numeric validation options
|
|
27
|
+
*/
|
|
28
|
+
export interface NumericValidationOptions {
|
|
29
|
+
readonly min?: number;
|
|
30
|
+
readonly max?: number;
|
|
31
|
+
readonly integer?: boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Abort Logging
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Log abort before start
|
|
7
|
+
*/
|
|
8
|
+
export function logAbortBeforeStart(): void {
|
|
9
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
10
|
+
console.log("[Orchestrator] Aborted before generation started");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Log abort after completion
|
|
16
|
+
*/
|
|
17
|
+
export function logAbortAfterCompletion(): void {
|
|
18
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
19
|
+
console.log("[Orchestrator] Aborted after generation completed");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Log abort before save
|
|
25
|
+
*/
|
|
26
|
+
export function logAbortBeforeSave(): void {
|
|
27
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
28
|
+
console.log("[Orchestrator] Aborted before save");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Log abort before success
|
|
34
|
+
*/
|
|
35
|
+
export function logAbortBeforeSuccess(): void {
|
|
36
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
37
|
+
console.log("[Orchestrator] Aborted before success callback");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Log aborted
|
|
43
|
+
*/
|
|
44
|
+
export function logAborted(): void {
|
|
45
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
46
|
+
console.log("[Orchestrator] Generation aborted");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Execution Logging
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Log state generating
|
|
7
|
+
*/
|
|
8
|
+
export function logStateGenerating(): void {
|
|
9
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
10
|
+
console.log("[Orchestrator] State: generating - calling strategy.execute()");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Log execute completed
|
|
16
|
+
*/
|
|
17
|
+
export function logExecuteCompleted(): void {
|
|
18
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
19
|
+
console.log("[Orchestrator] strategy.execute() completed");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Log state saving
|
|
25
|
+
*/
|
|
26
|
+
export function logStateSaving(): void {
|
|
27
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
28
|
+
console.log("[Orchestrator] Saving result to Firestore");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Log save success
|
|
34
|
+
*/
|
|
35
|
+
export function logSaveSuccess(): void {
|
|
36
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
37
|
+
console.log("[Orchestrator] Result saved successfully");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Log save failed
|
|
43
|
+
*/
|
|
44
|
+
export function logSaveFailed(error: unknown): void {
|
|
45
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
46
|
+
console.log("[Orchestrator] ERROR: Save failed:", error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Log generation success
|
|
52
|
+
*/
|
|
53
|
+
export function logGenerationSuccess(): void {
|
|
54
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
55
|
+
console.log("[Orchestrator] ✅ Generation SUCCESS");
|
|
56
|
+
console.log("[Orchestrator] ========================================");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Log error
|
|
62
|
+
*/
|
|
63
|
+
export function logError(error: unknown): void {
|
|
64
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
65
|
+
console.log("[Orchestrator] Error:", error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator
|
|
3
|
+
* Handles AI generation execution with network check, moderation, credit deduction, and error handling
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { useGenerationOrchestrator } from "./orchestrator";
|
|
7
|
+
export type {
|
|
8
|
+
GenerationStatus,
|
|
9
|
+
GenerationState,
|
|
10
|
+
GenerationError,
|
|
11
|
+
GenerationStrategy,
|
|
12
|
+
GenerationConfig,
|
|
13
|
+
UseGenerationOrchestratorReturn,
|
|
14
|
+
} from "./orchestrator-types";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Start Logging
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Log generation start
|
|
7
|
+
*/
|
|
8
|
+
export function logGenerationStart(input: unknown, userId: string | null, isGenerating: boolean): void {
|
|
9
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
10
|
+
console.log("[Orchestrator] ========================================");
|
|
11
|
+
console.log("[Orchestrator] generate() called with input:", JSON.stringify(input).substring(0, 200));
|
|
12
|
+
console.log("[Orchestrator] isGenerating:", isGenerating);
|
|
13
|
+
console.log("[Orchestrator] userId:", userId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Log already generating state
|
|
19
|
+
*/
|
|
20
|
+
export function logAlreadyGenerating(): void {
|
|
21
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
22
|
+
console.log("[Orchestrator] BLOCKED: Already generating");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Log state change
|
|
28
|
+
*/
|
|
29
|
+
export function logStateChange(state: string): void {
|
|
30
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
31
|
+
console.log("[Orchestrator] State set to '" + state + "', isGenerating: true");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Log online check result
|
|
37
|
+
*/
|
|
38
|
+
export function logOnlineCheck(online: boolean): void {
|
|
39
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
40
|
+
if (online) {
|
|
41
|
+
console.log("[Orchestrator] Online check passed");
|
|
42
|
+
} else {
|
|
43
|
+
console.log("[Orchestrator] ERROR: User is offline");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Log moderation start
|
|
50
|
+
*/
|
|
51
|
+
export function logModerationStart(): void {
|
|
52
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
53
|
+
console.log("[Orchestrator] Starting moderation check");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Log execution start
|
|
59
|
+
*/
|
|
60
|
+
export function logExecutionStart(): void {
|
|
61
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
62
|
+
console.log("[Orchestrator] ----------------------------------------");
|
|
63
|
+
console.log("[Orchestrator] executeGeneration() called");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - State Utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { GenerationState } from "./orchestrator-types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get initial generation state
|
|
9
|
+
*/
|
|
10
|
+
export function getInitialState<T>(): GenerationState<T> {
|
|
11
|
+
return {
|
|
12
|
+
status: "idle",
|
|
13
|
+
isGenerating: false,
|
|
14
|
+
result: null,
|
|
15
|
+
error: null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type GenerationStatus = "idle" | "checking" | "generating" | "saving" | "success" | "error";
|
|
6
|
+
|
|
7
|
+
export interface GenerationState<T> {
|
|
8
|
+
readonly status: GenerationStatus;
|
|
9
|
+
readonly isGenerating: boolean;
|
|
10
|
+
readonly result: T | null;
|
|
11
|
+
readonly error: GenerationError | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface GenerationError {
|
|
15
|
+
readonly type: "network" | "moderation" | "credits" | "generation" | "save" | "unknown";
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly originalError?: Error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GenerationStrategy<TInput, TResult> {
|
|
21
|
+
readonly execute: (input: TInput, signal?: AbortSignal) => Promise<TResult>;
|
|
22
|
+
readonly save?: (result: TResult, userId: string) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GenerationConfig {
|
|
26
|
+
readonly userId: string | null;
|
|
27
|
+
readonly alertMessages: {
|
|
28
|
+
readonly networkError?: string;
|
|
29
|
+
readonly moderationError?: string;
|
|
30
|
+
readonly insufficientCredits?: string;
|
|
31
|
+
readonly generationError?: string;
|
|
32
|
+
readonly saveFailed?: string;
|
|
33
|
+
readonly success?: string;
|
|
34
|
+
};
|
|
35
|
+
readonly onSuccess?: (result: unknown) => Promise<void>;
|
|
36
|
+
readonly onError?: (error: GenerationError) => Promise<void>;
|
|
37
|
+
readonly moderation?: {
|
|
38
|
+
readonly enabled?: boolean;
|
|
39
|
+
readonly onWarning?: (warning: string, onProceed: () => void, onCancel: () => void) => void;
|
|
40
|
+
};
|
|
41
|
+
readonly lifecycle?: {
|
|
42
|
+
readonly onStart?: () => void;
|
|
43
|
+
readonly onComplete?: (status: "success" | "error", result?: unknown, error?: GenerationError) => void;
|
|
44
|
+
readonly completeDelay?: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface UseGenerationOrchestratorReturn<TInput, TResult> {
|
|
49
|
+
readonly generate: (input: TInput) => Promise<TResult | void>;
|
|
50
|
+
readonly reset: () => void;
|
|
51
|
+
readonly status: GenerationStatus;
|
|
52
|
+
readonly isGenerating: boolean;
|
|
53
|
+
readonly result: TResult | null;
|
|
54
|
+
readonly error: GenerationError | null;
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { getInitialState } from "./orchestrator-state-utils";
|
|
6
|
+
export {
|
|
7
|
+
logGenerationStart,
|
|
8
|
+
logAlreadyGenerating,
|
|
9
|
+
logStateChange,
|
|
10
|
+
logOnlineCheck,
|
|
11
|
+
logModerationStart,
|
|
12
|
+
logExecutionStart,
|
|
13
|
+
} from "./orchestrator-start-logs";
|
|
14
|
+
export {
|
|
15
|
+
logAbortBeforeStart,
|
|
16
|
+
logAbortAfterCompletion,
|
|
17
|
+
logAbortBeforeSave,
|
|
18
|
+
logAbortBeforeSuccess,
|
|
19
|
+
logAborted,
|
|
20
|
+
} from "./orchestrator-abort-logs";
|
|
21
|
+
export {
|
|
22
|
+
logStateGenerating,
|
|
23
|
+
logExecuteCompleted,
|
|
24
|
+
logStateSaving,
|
|
25
|
+
logSaveSuccess,
|
|
26
|
+
logSaveFailed,
|
|
27
|
+
logGenerationSuccess,
|
|
28
|
+
logError,
|
|
29
|
+
} from "./orchestrator-execution-logs";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
getInitialState,
|
|
7
|
+
logGenerationStart,
|
|
8
|
+
logAlreadyGenerating,
|
|
9
|
+
logStateChange,
|
|
10
|
+
logOnlineCheck,
|
|
11
|
+
logModerationStart,
|
|
12
|
+
logExecutionStart,
|
|
13
|
+
logAbortBeforeStart,
|
|
14
|
+
logStateGenerating,
|
|
15
|
+
logAbortAfterCompletion,
|
|
16
|
+
logExecuteCompleted,
|
|
17
|
+
logAbortBeforeSave,
|
|
18
|
+
logStateSaving,
|
|
19
|
+
logSaveSuccess,
|
|
20
|
+
logSaveFailed,
|
|
21
|
+
logAbortBeforeSuccess,
|
|
22
|
+
logGenerationSuccess,
|
|
23
|
+
logError,
|
|
24
|
+
logAborted,
|
|
25
|
+
} from "./orchestrator-utils-index";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { useState, useCallback, useMemo } from "react";
|
|
7
7
|
import { saveImageToGallery } from "@umituz/react-native-design-system/media";
|
|
8
8
|
import { useAlert } from "@umituz/react-native-design-system/molecules";
|
|
9
|
-
import { useGenerationOrchestrator } from "./orchestrator";
|
|
9
|
+
import { useGenerationOrchestrator } from "./orchestrator-index";
|
|
10
10
|
import { useImagePicker } from "./useImagePicker";
|
|
11
11
|
import { executeMultiImageGeneration } from "../../../infrastructure/services/multi-image-generation.executor";
|
|
12
12
|
import type { GenerationStrategy } from "./types";
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useMemo, useCallback, useRef } from "react";
|
|
7
|
-
import { useGenerationOrchestrator } from "./orchestrator";
|
|
7
|
+
import { useGenerationOrchestrator } from "./orchestrator-index";
|
|
8
8
|
import type { GenerationStrategy } from "./types";
|
|
9
9
|
import { executeImageFeature } from "../../../infrastructure/services";
|
|
10
10
|
import { createCreationsRepository } from "../../../domains/creations/infrastructure/adapters";
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { useMemo, useCallback, useRef } from "react";
|
|
8
|
-
import { useGenerationOrchestrator } from "./orchestrator";
|
|
8
|
+
import { useGenerationOrchestrator } from "./orchestrator-index";
|
|
9
9
|
import type { GenerationStrategy, AlertMessages } from "./types";
|
|
10
10
|
import { executeVideoFeature } from "../../../infrastructure/services";
|
|
11
11
|
import type { VideoFeatureType } from "../../../domain/interfaces";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Generation Hook Factory
|
|
3
|
+
* Creates type-safe generation hooks with error handling, progress tracking, and abort support
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { createGenerationHook, createGenerationHookWithProgress } from "./createGenerationHook";
|
|
7
|
+
export type {
|
|
8
|
+
GenerationState,
|
|
9
|
+
GenerationCallbacks,
|
|
10
|
+
GenerationHookConfig,
|
|
11
|
+
GenerationHookReturn,
|
|
12
|
+
} from "./generation-hook-types";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Generation Hook Factory - Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generation state
|
|
7
|
+
*/
|
|
8
|
+
export interface GenerationState {
|
|
9
|
+
isGenerating: boolean;
|
|
10
|
+
progress: number;
|
|
11
|
+
error: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generation callbacks
|
|
16
|
+
*/
|
|
17
|
+
export interface GenerationCallbacks<TResult> {
|
|
18
|
+
/** Called when generation succeeds */
|
|
19
|
+
onSuccess?: (result: TResult) => void;
|
|
20
|
+
/** Called when generation fails */
|
|
21
|
+
onError?: (error: string) => void;
|
|
22
|
+
/** Called on progress update */
|
|
23
|
+
onProgress?: (progress: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generation hook configuration
|
|
28
|
+
*/
|
|
29
|
+
export interface GenerationHookConfig<TRequest, TResult> {
|
|
30
|
+
/** Execute the generation request */
|
|
31
|
+
execute: (request: TRequest, signal?: AbortSignal) => Promise<TResult>;
|
|
32
|
+
/** Optional validation before execution */
|
|
33
|
+
validate?: (request: TRequest) => string | null;
|
|
34
|
+
/** Optional transform for errors */
|
|
35
|
+
transformError?: (error: unknown) => string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generation hook return type
|
|
40
|
+
*/
|
|
41
|
+
export interface GenerationHookReturn<TRequest, TResult> {
|
|
42
|
+
generationState: GenerationState;
|
|
43
|
+
handleGenerate: (request: TRequest) => Promise<TResult | null>;
|
|
44
|
+
setProgress: (progress: number) => void;
|
|
45
|
+
setError: (error: string | null) => void;
|
|
46
|
+
abort: () => void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Generation Hook Factory - Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { GenerationState } from "./generation-hook-types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Initial generation state
|
|
9
|
+
*/
|
|
10
|
+
export const INITIAL_STATE: GenerationState = {
|
|
11
|
+
isGenerating: false,
|
|
12
|
+
progress: 0,
|
|
13
|
+
error: null,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create abort handler
|
|
18
|
+
*/
|
|
19
|
+
export function createAbortHandler(
|
|
20
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
21
|
+
setGenerationState: React.Dispatch<React.SetStateAction<GenerationState>>
|
|
22
|
+
): () => void {
|
|
23
|
+
return () => {
|
|
24
|
+
abortControllerRef.current?.abort();
|
|
25
|
+
setGenerationState((prev) => ({
|
|
26
|
+
...prev,
|
|
27
|
+
isGenerating: false,
|
|
28
|
+
error: "Generation aborted",
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create progress setter
|
|
35
|
+
*/
|
|
36
|
+
export function createProgressSetter(
|
|
37
|
+
onProgressRef: React.MutableRefObject<((progress: number) => void) | undefined>,
|
|
38
|
+
setGenerationState: React.Dispatch<React.SetStateAction<GenerationState>>,
|
|
39
|
+
isMountedRef: React.MutableRefObject<boolean>
|
|
40
|
+
): (progress: number) => void {
|
|
41
|
+
return (progress: number) => {
|
|
42
|
+
if (!isMountedRef.current) return;
|
|
43
|
+
setGenerationState((prev) => ({ ...prev, progress }));
|
|
44
|
+
onProgressRef.current?.(progress);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create error setter
|
|
50
|
+
*/
|
|
51
|
+
export function createErrorSetter(
|
|
52
|
+
onErrorRef: React.MutableRefObject<((error: string) => void) | undefined>,
|
|
53
|
+
setGenerationState: React.Dispatch<React.SetStateAction<GenerationState>>,
|
|
54
|
+
isMountedRef: React.MutableRefObject<boolean>
|
|
55
|
+
): (error: string | null) => void {
|
|
56
|
+
return (error: string | null) => {
|
|
57
|
+
if (!isMountedRef.current) return;
|
|
58
|
+
setGenerationState((prev) => ({ ...prev, error, isGenerating: false }));
|
|
59
|
+
if (error) {
|
|
60
|
+
onErrorRef.current?.(error);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create cleanup effect
|
|
67
|
+
*/
|
|
68
|
+
export function createCleanupEffect(
|
|
69
|
+
isMountedRef: React.MutableRefObject<boolean>,
|
|
70
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>
|
|
71
|
+
): () => void {
|
|
72
|
+
return () => {
|
|
73
|
+
isMountedRef.current = false;
|
|
74
|
+
abortControllerRef.current?.abort();
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create callback updater effect
|
|
80
|
+
*/
|
|
81
|
+
export function createCallbackUpdater<T>(
|
|
82
|
+
onSuccessRef: React.MutableRefObject<((result: T) => void) | undefined>,
|
|
83
|
+
onErrorRef: React.MutableRefObject<((error: string) => void) | undefined>,
|
|
84
|
+
onProgressRef: React.MutableRefObject<((progress: number) => void) | undefined>,
|
|
85
|
+
callbacks: {
|
|
86
|
+
onSuccess?: (result: T) => void;
|
|
87
|
+
onError?: (error: string) => void;
|
|
88
|
+
onProgress?: (progress: number) => void;
|
|
89
|
+
}
|
|
90
|
+
): void {
|
|
91
|
+
onSuccessRef.current = callbacks.onSuccess;
|
|
92
|
+
onErrorRef.current = callbacks.onError;
|
|
93
|
+
onProgressRef.current = callbacks.onProgress;
|
|
94
|
+
}
|
package/src/shared/index.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aspect Ratio & Dimension Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate aspect ratio from dimensions
|
|
7
|
+
*/
|
|
8
|
+
export function calculateAspectRatio(width: number, height: number): number {
|
|
9
|
+
return width / height;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calculate height from width and aspect ratio
|
|
14
|
+
*/
|
|
15
|
+
export function calculateHeightFromAspectRatio(
|
|
16
|
+
width: number,
|
|
17
|
+
aspectRatio: number
|
|
18
|
+
): number {
|
|
19
|
+
return Math.round(width / aspectRatio);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Calculate width from height and aspect ratio
|
|
24
|
+
*/
|
|
25
|
+
export function calculateWidthFromAspectRatio(
|
|
26
|
+
height: number,
|
|
27
|
+
aspectRatio: number
|
|
28
|
+
): number {
|
|
29
|
+
return Math.round(height * aspectRatio);
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64 Size Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate base64 size in bytes
|
|
7
|
+
*/
|
|
8
|
+
export function calculateBase64Size(base64: string): number {
|
|
9
|
+
// Remove data URI prefix if present
|
|
10
|
+
const cleanBase64 = base64.replace(/^data:[^;]+;base64,/, "");
|
|
11
|
+
return (cleanBase64.length * 3) / 4;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Calculate base64 size in megabytes
|
|
16
|
+
*/
|
|
17
|
+
export function calculateBase64SizeMB(base64: string): number {
|
|
18
|
+
return calculateBase64Size(base64) / (1024 * 1024);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Calculate if base64 size is within limit
|
|
23
|
+
*/
|
|
24
|
+
export function isBase64SizeWithinLimit(base64: string, maxSizeMB: number): boolean {
|
|
25
|
+
return calculateBase64SizeMB(base64) <= maxSizeMB;
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence Score Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate confidence score from violations with weights
|
|
7
|
+
*/
|
|
8
|
+
export function calculateConfidenceScore(
|
|
9
|
+
violations: readonly { severity: "critical" | "high" | "medium" | "low" }[]
|
|
10
|
+
): number {
|
|
11
|
+
if (violations.length === 0) return 1.0;
|
|
12
|
+
|
|
13
|
+
const weights = { critical: 1.0, high: 0.75, medium: 0.5, low: 0.25 };
|
|
14
|
+
const score = violations.reduce(
|
|
15
|
+
(sum, v) => sum + (weights[v.severity] || 0.25),
|
|
16
|
+
0
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// Normalize by number of violations, capped at 1.0
|
|
20
|
+
return Math.min(1.0, score / Math.max(1, violations.length));
|
|
21
|
+
}
|