@umituz/react-native-ai-generation-content 1.90.1 → 1.90.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/package.json +1 -4
  2. package/src/domain/interfaces/app-services-auth.interface.ts +27 -0
  3. package/src/domain/interfaces/app-services-composite.interface.ts +29 -0
  4. package/src/domain/interfaces/app-services-optional.interface.ts +42 -0
  5. package/src/domain/interfaces/app-services.interface.ts +0 -79
  6. package/src/domains/background/infrastructure/services/job-poller-index.ts +7 -0
  7. package/src/domains/background/infrastructure/services/job-poller-utils.ts +130 -0
  8. package/src/domains/background/infrastructure/utils/polling-interval.util.ts +1 -1
  9. package/src/domains/background/presentation/hooks/use-background-generation.ts +1 -1
  10. package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +1 -1
  11. package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +34 -8
  12. package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +15 -4
  13. package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +34 -8
  14. package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +19 -8
  15. package/src/domains/creations/domain/types/creation-categories.constants.ts +57 -0
  16. package/src/domains/creations/domain/types/creation-categories.helpers.ts +67 -0
  17. package/src/domains/creations/domain/types/creation-categories.ts +5 -111
  18. package/src/domains/creations/presentation/hooks/creation-validators.ts +31 -29
  19. package/src/domains/creations/presentation/hooks/job-poller-index.ts +10 -0
  20. package/src/domains/creations/presentation/hooks/job-poller-utils.filters.ts +34 -0
  21. package/src/domains/creations/presentation/hooks/job-poller-utils.logger.ts +76 -0
  22. package/src/domains/creations/presentation/hooks/job-poller-utils.stale-handlers.ts +52 -0
  23. package/src/domains/creations/presentation/hooks/job-poller-utils.ts +8 -0
  24. package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +1 -1
  25. package/src/domains/creations/presentation-exports.ts +2 -2
  26. package/src/domains/face-detection/domain/entities/FaceDetection.ts +4 -3
  27. package/src/domains/face-detection/presentation/hooks/useFaceDetection.ts +24 -21
  28. package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-preparation.ts +58 -0
  29. package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-prompt.ts +69 -0
  30. package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-resolution.ts +77 -0
  31. package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple.ts +54 -0
  32. package/src/domains/generation/infrastructure/couple-generation-builder/builder-index.ts +8 -0
  33. package/src/domains/generation/infrastructure/couple-generation-builder/builder-scenario.ts +113 -0
  34. package/src/domains/generation/infrastructure/couple-generation-builder/builder.ts +7 -0
  35. package/src/domains/generation/infrastructure/couple-generation-builder/index.ts +20 -0
  36. package/src/domains/generation/infrastructure/couple-generation-builder/types.ts +44 -0
  37. package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-end-logger.ts +18 -0
  38. package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-start-logger.ts +57 -0
  39. package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-step-logger.ts +106 -0
  40. package/src/domains/generation/infrastructure/couple-generation-builder/utils/index.ts +8 -0
  41. package/src/domains/generation/infrastructure/couple-generation-builder/utils/types.ts +49 -0
  42. package/src/domains/generation/infrastructure/couple-generation-builder/utils.ts +8 -0
  43. package/src/domains/generation/infrastructure/flow/flow-store-actions.ts +105 -0
  44. package/src/domains/generation/infrastructure/flow/flow-store-initial-state.ts +26 -0
  45. package/src/domains/generation/infrastructure/flow/useFlowStore.ts +4 -116
  46. package/src/domains/generation/presentation/useAIGeneration.hook.ts +1 -1
  47. package/src/domains/generation/wizard/infrastructure/strategies/image-generation-strategy-index.ts +7 -0
  48. package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.ts +2 -12
  49. package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.types.ts +11 -0
  50. package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.utils.ts +12 -0
  51. package/src/domains/generation/wizard/infrastructure/strategies/image-generation.strategy.ts +1 -220
  52. package/src/domains/generation/wizard/infrastructure/strategies/image-input-builder.ts +66 -0
  53. package/src/domains/generation/wizard/infrastructure/strategies/image-input-extraction.ts +88 -0
  54. package/src/domains/generation/wizard/infrastructure/strategies/image-input-prompt-builder.ts +75 -0
  55. package/src/domains/generation/wizard/infrastructure/strategies/image-input-style-enhancements.ts +35 -0
  56. package/src/domains/generation/wizard/infrastructure/strategies/image-strategy-factory.ts +42 -0
  57. package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor-index.ts +11 -0
  58. package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor.ts +76 -0
  59. package/src/domains/generation/wizard/infrastructure/strategies/video-generation-input-builder.ts +46 -0
  60. package/src/domains/generation/wizard/infrastructure/strategies/video-generation-result-types.ts +17 -0
  61. package/src/domains/generation/wizard/infrastructure/strategies/video-generation-submission.ts +62 -0
  62. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.audio-extractor.ts +27 -0
  63. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.executor.ts +2 -175
  64. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.input-builder.ts +90 -0
  65. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +3 -108
  66. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.types.ts +0 -129
  67. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.validation.ts +136 -0
  68. package/src/domains/generation/wizard/presentation/hooks/photo-upload/index.ts +39 -0
  69. package/src/domains/generation/wizard/presentation/hooks/photo-upload/types.ts +37 -0
  70. package/src/domains/generation/wizard/presentation/hooks/photo-upload/usePhotoUploadStateLogic.ts +142 -0
  71. package/src/domains/generation/wizard/presentation/hooks/use-video-queue-utils.ts +103 -0
  72. package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.handlers.ts +97 -0
  73. package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.saver.ts +54 -0
  74. package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.ts +22 -87
  75. package/src/domains/generation/wizard/presentation/hooks/usePhotoUploadState.ts +8 -177
  76. package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +1 -295
  77. package/src/domains/generation/wizard/presentation/hooks/useWizardGeneration.ts +1 -1
  78. package/src/domains/generation/wizard/presentation/hooks/video-queue/index.ts +82 -0
  79. package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationCallbacks.ts +120 -0
  80. package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationPolling.ts +76 -0
  81. package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationRefs.ts +65 -0
  82. package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationStart.ts +123 -0
  83. package/src/domains/generation/wizard/presentation/hooks/video-queue-index.ts +9 -0
  84. package/src/domains/image-to-video/domain/types/image-to-video-state.types.ts +11 -4
  85. package/src/domains/text-to-image/domain/types/text-to-image.types.ts +44 -22
  86. package/src/domains/text-to-video/domain/types/request.types.ts +33 -9
  87. package/src/domains/text-to-video/domain/types/state.types.ts +29 -9
  88. package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.handlers.ts +44 -0
  89. package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.ts +5 -51
  90. package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.types.ts +33 -0
  91. package/src/infrastructure/services/generation-orchestrator.service.ts +2 -2
  92. package/src/infrastructure/utils/couple-input-context.ts +13 -0
  93. package/src/infrastructure/utils/couple-input-index.ts +8 -0
  94. package/src/infrastructure/utils/couple-input-refiner.ts +101 -0
  95. package/src/infrastructure/utils/couple-input-resolver.ts +71 -0
  96. package/src/infrastructure/utils/couple-input-types.ts +14 -0
  97. package/src/infrastructure/utils/couple-input.util.ts +3 -176
  98. package/src/infrastructure/utils/photo-generation/photo-preparation.util.ts +1 -1
  99. package/src/infrastructure/validation/base-validator.ts +1 -27
  100. package/src/infrastructure/validation/base-validator.types.ts +32 -0
  101. package/src/presentation/hooks/generation/index.ts +1 -1
  102. package/src/presentation/hooks/generation/orchestrator-abort-logs.ts +48 -0
  103. package/src/presentation/hooks/generation/orchestrator-execution-logs.ts +67 -0
  104. package/src/presentation/hooks/generation/orchestrator-index.ts +14 -0
  105. package/src/presentation/hooks/generation/orchestrator-start-logs.ts +65 -0
  106. package/src/presentation/hooks/generation/orchestrator-state-utils.ts +17 -0
  107. package/src/presentation/hooks/generation/orchestrator-types.ts +55 -0
  108. package/src/presentation/hooks/generation/orchestrator-utils-index.ts +29 -0
  109. package/src/presentation/hooks/generation/orchestrator-utils.ts +25 -0
  110. package/src/presentation/hooks/generation/useDualImageGeneration.ts +1 -1
  111. package/src/presentation/hooks/generation/useImageGeneration.ts +1 -1
  112. package/src/presentation/hooks/generation/useVideoGeneration.ts +1 -1
  113. package/src/shared/hooks/factories/generation-hook-index.ts +12 -0
  114. package/src/shared/hooks/factories/generation-hook-types.ts +47 -0
  115. package/src/shared/hooks/factories/generation-hook-utils.ts +94 -0
  116. package/src/shared/hooks/factories/index.ts +1 -1
  117. package/src/shared/index.ts +1 -1
  118. package/src/shared/utils/calculations/aspect-ratio-calculations.ts +30 -0
  119. package/src/shared/utils/calculations/base64-calculations.ts +26 -0
  120. package/src/shared/utils/calculations/confidence-calculations.ts +21 -0
  121. package/src/shared/utils/calculations/cost-calculations-index.ts +43 -0
  122. package/src/shared/utils/calculations/cost-calculations.ts +25 -0
  123. package/src/shared/utils/calculations/credit-calculations.ts +37 -0
  124. package/src/shared/utils/calculations/index.ts +46 -0
  125. package/src/shared/utils/calculations/math-utilities.ts +32 -0
  126. package/src/shared/utils/calculations/memory-calculations.ts +33 -0
  127. package/src/shared/utils/calculations/pagination-calculations.ts +38 -0
  128. package/src/shared/utils/calculations/percentage-calculations.ts +33 -0
  129. package/src/shared/utils/calculations/time-calculations.ts +99 -0
  130. package/src/shared/utils/credit.ts +1 -1
  131. package/src/shared-kernel/application/hooks/index.ts +8 -0
  132. package/src/shared-kernel/application/hooks/use-feature-state.ts +107 -0
  133. package/src/shared-kernel/application/hooks/use-generation-handler.ts +110 -0
  134. package/src/shared-kernel/base-types/base-callbacks.types.ts +73 -0
  135. package/src/shared-kernel/base-types/base-feature-state.types.ts +77 -0
  136. package/src/shared-kernel/base-types/base-generation.types.ts +69 -0
  137. package/src/shared-kernel/base-types/index.ts +30 -0
  138. package/src/shared-kernel/domain/base-generation-strategy.ts +146 -0
  139. package/src/shared-kernel/domain/index.ts +7 -0
  140. package/src/shared-kernel/index.ts +17 -0
  141. package/src/shared-kernel/infrastructure/validation/common-validators.ts +126 -0
  142. package/src/shared-kernel/infrastructure/validation/common-validators.types.ts +33 -0
  143. package/src/shared-kernel/infrastructure/validation/error-handler.ts +52 -0
  144. package/src/shared-kernel/infrastructure/validation/error-handler.types.ts +38 -0
  145. package/src/shared-kernel/infrastructure/validation/error-handler.utils.ts +79 -0
  146. package/src/shared-kernel/infrastructure/validation/index.ts +28 -0
  147. package/src/domains/background/infrastructure/services/job-poller.service.ts +0 -234
  148. package/src/domains/creations/presentation/hooks/useProcessingJobsPoller.ts +0 -256
  149. package/src/domains/generation/infrastructure/couple-generation-builder.ts +0 -374
  150. package/src/presentation/hooks/generation/orchestrator.ts +0 -276
  151. package/src/shared/hooks/factories/createGenerationHook.ts +0 -253
  152. package/src/shared/utils/calculations.util.ts +0 -366
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Time & Duration Calculations
3
+ */
4
+
5
+ /**
6
+ * Calculate age in milliseconds from a timestamp
7
+ */
8
+ export function calculateAgeMs(timestamp: Date | number): number {
9
+ const time = typeof timestamp === "number" ? timestamp : timestamp.getTime();
10
+ return Date.now() - time;
11
+ }
12
+
13
+ /**
14
+ * Calculate age in seconds from a timestamp
15
+ */
16
+ export function calculateAgeSeconds(timestamp: Date | number): number {
17
+ return Math.floor(calculateAgeMs(timestamp) / 1000);
18
+ }
19
+
20
+ /**
21
+ * Calculate age in minutes from a timestamp
22
+ */
23
+ export function calculateAgeMinutes(timestamp: Date | number): number {
24
+ return Math.floor(calculateAgeSeconds(timestamp) / 60);
25
+ }
26
+
27
+ /**
28
+ * Check if timestamp is older than specified milliseconds
29
+ */
30
+ export function isOlderThan(timestamp: Date | number, maxAgeMs: number): boolean {
31
+ return calculateAgeMs(timestamp) > maxAgeMs;
32
+ }
33
+
34
+ /**
35
+ * Calculate duration between two timestamps in milliseconds
36
+ */
37
+ export function calculateDurationMs(
38
+ startTime: Date | number,
39
+ endTime: Date | number = Date.now()
40
+ ): number {
41
+ const start = typeof startTime === "number" ? startTime : startTime.getTime();
42
+ const end = typeof endTime === "number" ? endTime : endTime.getTime();
43
+ return end - start;
44
+ }
45
+
46
+ /**
47
+ * Format duration in milliseconds to human-readable string
48
+ */
49
+ export function formatDuration(ms: number): string {
50
+ const seconds = Math.floor(ms / 1000);
51
+ const minutes = Math.floor(seconds / 60);
52
+ const hours = Math.floor(minutes / 60);
53
+
54
+ if (hours > 0) {
55
+ return `${hours}h ${minutes % 60}m`;
56
+ }
57
+ if (minutes > 0) {
58
+ return `${minutes}m ${seconds % 60}s`;
59
+ }
60
+ return `${seconds}s`;
61
+ }
62
+
63
+ /**
64
+ * Calculate polling interval with exponential backoff
65
+ */
66
+ export function calculatePollingInterval(options: {
67
+ attempt: number;
68
+ initialIntervalMs: number;
69
+ maxIntervalMs: number;
70
+ backoffMultiplier: number;
71
+ }): number {
72
+ const { attempt, initialIntervalMs, maxIntervalMs, backoffMultiplier } = options;
73
+
74
+ if (attempt === 0) {
75
+ return 0;
76
+ }
77
+
78
+ const interval = initialIntervalMs * Math.pow(backoffMultiplier, attempt - 1);
79
+ return Math.min(interval, maxIntervalMs);
80
+ }
81
+
82
+ /**
83
+ * Calculate estimated total polling time
84
+ */
85
+ export function calculateEstimatedPollingTime(options: {
86
+ maxAttempts: number;
87
+ initialIntervalMs: number;
88
+ maxIntervalMs: number;
89
+ backoffMultiplier: number;
90
+ }): number {
91
+ let total = 0;
92
+ for (let attempt = 1; attempt < options.maxAttempts; attempt++) {
93
+ total += calculatePollingInterval({ ...options, attempt });
94
+ if (total >= options.maxIntervalMs * options.maxAttempts) {
95
+ break;
96
+ }
97
+ }
98
+ return total;
99
+ }
@@ -3,7 +3,7 @@
3
3
  * Provides consistent credit calculation operations
4
4
  */
5
5
 
6
- import { calculateCredits as calculateCreditsFromDuration } from "./calculations.util";
6
+ import { calculateCredits as calculateCreditsFromDuration } from "./calculations";
7
7
 
8
8
  /**
9
9
  * Validates if a value is a valid credit amount
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Shared application hooks
3
+ * Exports all shared hooks for use across domains
4
+ */
5
+
6
+ export { useFeatureState } from './use-feature-state';
7
+ export type { GenerationHandlerConfig } from './use-generation-handler';
8
+ export { useGenerationHandler } from './use-generation-handler';
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Shared hook for managing feature state
3
+ * Eliminates duplicate state management across domains
4
+ */
5
+
6
+ import { useState, useCallback, useReducer } from 'react';
7
+ import type {
8
+ BaseFeatureState,
9
+ FeatureStateAction,
10
+ createInitialFeatureState,
11
+ } from '../../base-types';
12
+
13
+ /**
14
+ * Hook for managing feature state with consistent patterns
15
+ * Reduces state management duplication across domains
16
+ */
17
+ export function useFeatureState<TOutput = string>() {
18
+ const [state, dispatch] = useReducer(
19
+ (currentState: BaseFeatureState<TOutput>, action: FeatureStateAction<TOutput>) => {
20
+ switch (action.type) {
21
+ case 'START':
22
+ return {
23
+ ...currentState,
24
+ isProcessing: true,
25
+ progress: 0,
26
+ error: null,
27
+ startedAt: Date.now(),
28
+ jobId: action.jobId,
29
+ } as BaseFeatureState<TOutput> & { startedAt: number; jobId?: string };
30
+
31
+ case 'PROGRESS':
32
+ return {
33
+ ...currentState,
34
+ progress: action.progress,
35
+ progressInfo: {
36
+ progress: action.progress,
37
+ status: action.status,
38
+ },
39
+ };
40
+
41
+ case 'SUCCESS':
42
+ return {
43
+ ...currentState,
44
+ isProcessing: false,
45
+ progress: 1,
46
+ output: action.output,
47
+ completedAt: Date.now(),
48
+ } as BaseFeatureState<TOutput> & { completedAt: number };
49
+
50
+ case 'ERROR':
51
+ return {
52
+ ...currentState,
53
+ isProcessing: false,
54
+ error: action.error,
55
+ };
56
+
57
+ case 'RESET':
58
+ return {
59
+ isProcessing: false,
60
+ progress: 0,
61
+ error: null,
62
+ output: null,
63
+ };
64
+
65
+ default:
66
+ return currentState;
67
+ }
68
+ },
69
+ useState<BaseFeatureState<TOutput>>(() => ({
70
+ isProcessing: false,
71
+ progress: 0,
72
+ error: null,
73
+ output: null,
74
+ }))[0]
75
+ );
76
+
77
+ const startProcessing = useCallback((jobId?: string) => {
78
+ dispatch({ type: 'START', jobId });
79
+ }, []);
80
+
81
+ const updateProgress = useCallback((progress: number, status?: string) => {
82
+ dispatch({ type: 'PROGRESS', progress, status });
83
+ }, []);
84
+
85
+ const setSuccess = useCallback((output: TOutput, metadata?: Record<string, unknown>) => {
86
+ dispatch({ type: 'SUCCESS', output, metadata });
87
+ }, []);
88
+
89
+ const setError = useCallback((error: string) => {
90
+ dispatch({ type: 'ERROR', error });
91
+ }, []);
92
+
93
+ const reset = useCallback(() => {
94
+ dispatch({ type: 'RESET' });
95
+ }, []);
96
+
97
+ return {
98
+ state,
99
+ actions: {
100
+ startProcessing,
101
+ updateProgress,
102
+ setSuccess,
103
+ setError,
104
+ reset,
105
+ },
106
+ };
107
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Shared hook for handling generation operations
3
+ * Eliminates duplicate generation logic across domains
4
+ */
5
+
6
+ import { useCallback } from 'react';
7
+ import type {
8
+ BaseGenerationCallbacks,
9
+ BaseGenerationResult,
10
+ GenerationProgress,
11
+ } from '../../base-types';
12
+
13
+ /**
14
+ * Configuration for generation handler
15
+ */
16
+ export interface GenerationHandlerConfig<TInput, TOutput> {
17
+ /** Function to execute the generation */
18
+ executeGeneration: (input: TInput) => Promise<BaseGenerationResult<TOutput>>;
19
+ /** Optional validation function */
20
+ validateInput?: (input: TInput) => boolean | Promise<boolean>;
21
+ /** Callbacks for generation lifecycle */
22
+ callbacks?: BaseGenerationCallbacks<TOutput>;
23
+ }
24
+
25
+ /**
26
+ * Hook for handling generation operations with consistent patterns
27
+ * Reduces generation logic duplication across domains
28
+ */
29
+ export function useGenerationHandler<TInput, TOutput = string>(
30
+ config: GenerationHandlerConfig<TInput, TOutput>
31
+ ) {
32
+ const { executeGeneration, validateInput, callbacks } = config;
33
+
34
+ const handleGeneration = useCallback(
35
+ async (input: TInput): Promise<BaseGenerationResult<TOutput>> => {
36
+ try {
37
+ // Call onCreditCheck if provided
38
+ if (callbacks?.onCreditCheck) {
39
+ const hasCredits = await callbacks.onCreditCheck();
40
+ if (!hasCredits) {
41
+ callbacks.onShowPaywall?.();
42
+ return {
43
+ success: false,
44
+ error: 'Insufficient credits',
45
+ requestId: '',
46
+ };
47
+ }
48
+ }
49
+
50
+ // Validate input if validator provided
51
+ if (validateInput) {
52
+ const isValid = await validateInput(input);
53
+ if (!isValid) {
54
+ const error = new Error('Invalid input');
55
+ callbacks?.onError?.(error);
56
+ return {
57
+ success: false,
58
+ error: error.message,
59
+ requestId: '',
60
+ };
61
+ }
62
+ }
63
+
64
+ // Call onStart callback
65
+ callbacks?.onStart?.();
66
+
67
+ // Execute generation
68
+ const result = await executeGeneration(input);
69
+
70
+ // Handle result
71
+ if (result.success) {
72
+ callbacks?.onSuccess?.(result);
73
+ callbacks?.onCreditsConsumed?.(1); // Default credit cost
74
+ } else {
75
+ const error = new Error(result.error || 'Generation failed');
76
+ callbacks?.onError?.(error);
77
+ }
78
+
79
+ // Call onComplete
80
+ callbacks?.onComplete?.();
81
+
82
+ return result;
83
+ } catch (error) {
84
+ const err = error instanceof Error ? error : new Error('Unknown error');
85
+ callbacks?.onError?.(err);
86
+ callbacks?.onComplete?.();
87
+
88
+ return {
89
+ success: false,
90
+ error: err.message,
91
+ requestId: '',
92
+ };
93
+ }
94
+ },
95
+ [executeGeneration, validateInput, callbacks]
96
+ );
97
+
98
+ const handleProgress = useCallback(
99
+ (progress: number, status?: string) => {
100
+ const progressInfo: GenerationProgress = { progress, status };
101
+ callbacks?.onProgress?.(progressInfo);
102
+ },
103
+ [callbacks]
104
+ );
105
+
106
+ return {
107
+ handleGeneration,
108
+ handleProgress,
109
+ };
110
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Base callback types for AI generation operations
3
+ * Shared across all generation domains
4
+ */
5
+
6
+ import type { BaseGenerationResult, GenerationProgress } from './base-generation.types';
7
+
8
+ /**
9
+ * Credit-related callbacks for premium features
10
+ */
11
+ export interface CreditCallbacks {
12
+ /** Called when credit check is needed before generation */
13
+ onCreditCheck?: () => Promise<boolean>;
14
+ /** Called when user needs to see paywall */
15
+ onShowPaywall?: () => void;
16
+ /** Called when credits are successfully consumed */
17
+ onCreditsConsumed?: (amount: number) => void;
18
+ }
19
+
20
+ /**
21
+ * Progress callbacks for long-running operations
22
+ */
23
+ export interface ProgressCallbacks {
24
+ /** Called when generation progress updates */
25
+ onProgress?: (progress: GenerationProgress) => void;
26
+ /** Called when operation starts */
27
+ onStart?: () => void;
28
+ /** Called when operation completes (success or failure) */
29
+ onComplete?: () => void;
30
+ }
31
+
32
+ /**
33
+ * Result callbacks for generation operations
34
+ */
35
+ export interface ResultCallbacks<TData = string> {
36
+ /** Called when generation succeeds */
37
+ onSuccess?: (result: BaseGenerationResult<TData>) => void;
38
+ /** Called when generation fails */
39
+ onError?: (error: Error) => void;
40
+ /** Called when generation is cancelled */
41
+ onCancel?: () => void;
42
+ }
43
+
44
+ /**
45
+ * Combined callbacks for generation operations
46
+ * Includes all callback types in a single interface
47
+ */
48
+ export interface BaseGenerationCallbacks<TData = string>
49
+ extends CreditCallbacks,
50
+ ProgressCallbacks,
51
+ ResultCallbacks<TData> {}
52
+
53
+ /**
54
+ * Validation callbacks for input validation
55
+ */
56
+ export interface ValidationCallbacks {
57
+ /** Called when validation fails */
58
+ onValidationFailed?: (errors: Record<string, string>) => void;
59
+ /** Called when input is invalid */
60
+ onInvalidInput?: (field: string, reason: string) => void;
61
+ }
62
+
63
+ /**
64
+ * Lifecycle callbacks for feature components
65
+ */
66
+ export interface LifecycleCallbacks {
67
+ /** Called when component mounts */
68
+ onMount?: () => void;
69
+ /** Called when component unmounts */
70
+ onUnmount?: () => void;
71
+ /** Called when component updates */
72
+ onUpdate?: (prevProps: unknown, nextProps: unknown) => void;
73
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Base feature state types for AI generation features
3
+ * Provides consistent state management across all domains
4
+ */
5
+
6
+ import type { GenerationProgress } from './base-generation.types';
7
+
8
+ /**
9
+ * Base state for all generation features
10
+ * Used by hooks and components for consistent state management
11
+ */
12
+ export interface BaseFeatureState<TOutput = string> {
13
+ /** Whether a generation is currently in progress */
14
+ isProcessing: boolean;
15
+ /** Current generation progress (0-1) */
16
+ progress: number;
17
+ /** Error message if operation failed */
18
+ error: string | null;
19
+ /** Generated output data */
20
+ output: TOutput | null;
21
+ /** Additional progress information */
22
+ progressInfo?: GenerationProgress;
23
+ }
24
+
25
+ /**
26
+ * Feature state with additional metadata
27
+ */
28
+ export interface FeatureStateWithMetadata<TOutput = string> extends BaseFeatureState<TOutput> {
29
+ /** Unique ID for the current generation job */
30
+ jobId?: string;
31
+ /** Timestamp when generation started */
32
+ startedAt?: number;
33
+ /** Timestamp when generation completed */
34
+ completedAt?: number;
35
+ /** Number of retry attempts */
36
+ retryCount?: number;
37
+ }
38
+
39
+ /**
40
+ * Actions that can be performed on feature state
41
+ */
42
+ export type FeatureStateAction<TOutput = string> =
43
+ | { type: 'START'; jobId?: string }
44
+ | { type: 'PROGRESS'; progress: number; status?: string }
45
+ | { type: 'SUCCESS'; output: TOutput; metadata?: Record<string, unknown> }
46
+ | { type: 'ERROR'; error: string }
47
+ | { type: 'RESET' };
48
+
49
+ /**
50
+ * Initial state factory
51
+ */
52
+ export function createInitialFeatureState<TOutput = string>(): BaseFeatureState<TOutput> {
53
+ return {
54
+ isProcessing: false,
55
+ progress: 0,
56
+ error: null,
57
+ output: null,
58
+ };
59
+ }
60
+
61
+ /**
62
+ * Check if feature state is in an error state
63
+ */
64
+ export function isFeatureStateError<TOutput = string>(
65
+ state: BaseFeatureState<TOutput>
66
+ ): boolean {
67
+ return state.error !== null;
68
+ }
69
+
70
+ /**
71
+ * Check if feature state has output
72
+ */
73
+ export function hasFeatureStateOutput<TOutput = string>(
74
+ state: BaseFeatureState<TOutput>
75
+ ): boolean {
76
+ return state.output !== null;
77
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Base types for AI generation operations
3
+ * Shared across all generation domains (text-to-image, text-to-video, image-to-video, etc.)
4
+ */
5
+
6
+ /**
7
+ * Common aspect ratios used across all generation types
8
+ */
9
+ export type AspectRatio = '16:9' | '9:16' | '1:1' | '4:3' | '3:4';
10
+
11
+ /**
12
+ * Base generation options that are common to most generation types
13
+ */
14
+ export interface BaseGenerationOptions {
15
+ /** Output aspect ratio */
16
+ aspectRatio?: AspectRatio;
17
+ /** Number of steps/inference iterations */
18
+ steps?: number;
19
+ /** Guidance scale for generation (0-20 typically) */
20
+ guidanceScale?: number;
21
+ /** Random seed for reproducible results */
22
+ seed?: number;
23
+ /** Number of outputs to generate */
24
+ numOutputs?: number;
25
+ }
26
+
27
+ /**
28
+ * Common generation request metadata
29
+ */
30
+ export interface BaseRequestMeta {
31
+ /** Unique identifier for this request */
32
+ requestId: string;
33
+ /** User ID making the request */
34
+ userId: string;
35
+ /** Timestamp when request was created */
36
+ timestamp: number;
37
+ /** Request priority for queue management */
38
+ priority?: 'low' | 'normal' | 'high';
39
+ }
40
+
41
+ /**
42
+ * Standard generation result structure
43
+ */
44
+ export interface BaseGenerationResult<T = string> {
45
+ /** Whether the generation was successful */
46
+ success: boolean;
47
+ /** Generated content URL or data */
48
+ data?: T;
49
+ /** Error message if generation failed */
50
+ error?: string;
51
+ /** Request identifier */
52
+ requestId: string;
53
+ /** Time taken to complete generation (ms) */
54
+ duration?: number;
55
+ /** Additional metadata */
56
+ metadata?: Record<string, unknown>;
57
+ }
58
+
59
+ /**
60
+ * Generation progress information
61
+ */
62
+ export interface GenerationProgress {
63
+ /** Current progress (0-1) */
64
+ progress: number;
65
+ /** Current status message */
66
+ status?: string;
67
+ /** Estimated time remaining (ms) */
68
+ eta?: number;
69
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared kernel base types
3
+ * Exports all base types for use across domains
4
+ */
5
+
6
+ export type {
7
+ AspectRatio,
8
+ BaseGenerationOptions,
9
+ BaseRequestMeta,
10
+ BaseGenerationResult,
11
+ GenerationProgress,
12
+ } from './base-generation.types';
13
+
14
+ export type {
15
+ BaseFeatureState,
16
+ FeatureStateWithMetadata,
17
+ FeatureStateAction,
18
+ createInitialFeatureState,
19
+ isFeatureStateError,
20
+ hasFeatureStateOutput,
21
+ } from './base-feature-state.types';
22
+
23
+ export type {
24
+ CreditCallbacks,
25
+ ProgressCallbacks,
26
+ ResultCallbacks,
27
+ BaseGenerationCallbacks,
28
+ ValidationCallbacks,
29
+ LifecycleCallbacks,
30
+ } from './base-callbacks.types';