@umituz/react-native-ai-generation-content 1.65.6 → 1.65.8
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 +1 -1
- package/src/domains/access-control/hooks/useAIFeatureGate.ts +1 -1
- package/src/domains/background/infrastructure/executors/backgroundJobExecutor.ts +17 -6
- package/src/domains/background/infrastructure/services/job-poller.service.ts +81 -3
- package/src/domains/background/infrastructure/utils/polling-interval.util.ts +1 -4
- package/src/domains/background/presentation/hooks/use-background-generation.ts +17 -6
- package/src/domains/background/presentation/hooks/use-pending-jobs.ts +4 -0
- package/src/domains/creations/infrastructure/repositories/CreationsFetcher.ts +14 -2
- package/src/domains/creations/infrastructure/repositories/CreationsRepository.ts +0 -1
- package/src/domains/creations/infrastructure/repositories/creation-delete.operations.ts +65 -6
- package/src/domains/creations/presentation/hooks/creation-validators.ts +0 -1
- package/src/domains/generation/infrastructure/flow/use-flow-store.types.ts +0 -1
- package/src/domains/generation/infrastructure/flow/useFlow.ts +13 -25
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +5 -3
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.types.ts +84 -0
- package/src/domains/generation/wizard/presentation/hooks/generationExecutor.ts +6 -7
- package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +2 -2
- package/src/domains/image-to-video/domain/types/config.types.ts +3 -0
- package/src/domains/image-to-video/infrastructure/services/image-to-video-executor.ts +6 -3
- package/src/domains/image-to-video/presentation/hooks/imageToVideoStrategy.ts +10 -11
- package/src/domains/image-to-video/presentation/hooks/useFormState.ts +2 -2
- package/src/domains/image-to-video/presentation/hooks/useGeneration.ts +39 -6
- package/src/domains/image-to-video/presentation/hooks/useImageToVideoFeature.ts +19 -14
- package/src/domains/prompts/infrastructure/services/ImagePromptBuilder.ts +7 -1
- package/src/domains/text-to-image/presentation/hooks/useFormState.ts +1 -2
- package/src/domains/text-to-image/presentation/hooks/useGeneration.ts +2 -2
- package/src/domains/text-to-image/presentation/screens/TextToImageWizardFlow.tsx +0 -1
- package/src/domains/text-to-video/infrastructure/services/text-to-video-executor.ts +2 -2
- package/src/index.ts +3 -0
- package/src/infrastructure/executors/base-executor.ts +2 -2
- package/src/infrastructure/executors/index.ts +1 -1
- package/src/infrastructure/http/http-fetch-handler.ts +1 -1
- package/src/infrastructure/http/http-request-executor.ts +1 -1
- package/src/infrastructure/utils/domain-guards.ts +2 -1
- package/src/infrastructure/utils/index.ts +5 -1
- package/src/presentation/hooks/generation/orchestrator.ts +29 -2
- package/src/presentation/hooks/generation/useImageGeneration.ts +3 -0
- package/src/presentation/hooks/use-generation.ts +32 -15
|
@@ -37,27 +37,40 @@ export function useGeneration<T = unknown>(
|
|
|
37
37
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
38
38
|
const [error, setError] = useState<string | null>(null);
|
|
39
39
|
|
|
40
|
+
const abortControllerRef = useRef<AbortController | null>(null);
|
|
40
41
|
const abortRef = useRef(false);
|
|
41
42
|
|
|
42
43
|
// Abort on unmount to prevent state updates after unmount
|
|
43
44
|
useEffect(() => {
|
|
44
45
|
return () => {
|
|
45
46
|
abortRef.current = true;
|
|
47
|
+
abortControllerRef.current?.abort();
|
|
46
48
|
};
|
|
47
49
|
}, []);
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
// Stabilize callbacks to prevent unnecessary re-renders
|
|
52
|
+
const onSuccessRef = useRef(options.onSuccess);
|
|
53
|
+
const onErrorRef = useRef(options.onError);
|
|
54
|
+
const onProgressRef = useRef(options.onProgress);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
onSuccessRef.current = options.onSuccess;
|
|
58
|
+
onErrorRef.current = options.onError;
|
|
59
|
+
onProgressRef.current = options.onProgress;
|
|
60
|
+
}, [options.onSuccess, options.onError, options.onProgress]);
|
|
61
|
+
|
|
62
|
+
const handleProgress = useCallback((prog: GenerationProgress) => {
|
|
63
|
+
if (abortRef.current) return;
|
|
64
|
+
setProgress(prog);
|
|
65
|
+
onProgressRef.current?.(prog);
|
|
66
|
+
}, []);
|
|
57
67
|
|
|
58
68
|
const generate = useCallback(
|
|
59
69
|
async (input: Record<string, unknown>, userId?: string) => {
|
|
70
|
+
// Create new AbortController for this generation
|
|
71
|
+
abortControllerRef.current = new AbortController();
|
|
60
72
|
abortRef.current = false;
|
|
73
|
+
|
|
61
74
|
setIsGenerating(true);
|
|
62
75
|
setError(null);
|
|
63
76
|
setResult(null);
|
|
@@ -70,38 +83,42 @@ export function useGeneration<T = unknown>(
|
|
|
70
83
|
userId,
|
|
71
84
|
capability: options.capability,
|
|
72
85
|
onProgress: handleProgress,
|
|
86
|
+
signal: abortControllerRef.current.signal,
|
|
73
87
|
};
|
|
74
88
|
|
|
75
89
|
const genResult = await generationOrchestrator.generate<T>(request);
|
|
76
90
|
|
|
77
|
-
if (abortRef.current) return;
|
|
91
|
+
if (abortRef.current || abortControllerRef.current.signal.aborted) return;
|
|
78
92
|
|
|
79
93
|
setResult(genResult);
|
|
80
94
|
|
|
81
95
|
if (genResult.success) {
|
|
82
|
-
|
|
96
|
+
onSuccessRef.current?.(genResult);
|
|
83
97
|
} else if (genResult.error) {
|
|
84
98
|
setError(genResult.error);
|
|
85
|
-
|
|
99
|
+
onErrorRef.current?.(genResult.error);
|
|
86
100
|
}
|
|
87
101
|
} catch (err) {
|
|
88
|
-
if (abortRef.current) return;
|
|
102
|
+
if (abortRef.current || abortControllerRef.current?.signal.aborted) return;
|
|
89
103
|
|
|
90
104
|
const errorMessage =
|
|
91
105
|
err instanceof Error ? err.message : "error.unknown";
|
|
92
106
|
setError(errorMessage);
|
|
93
|
-
|
|
107
|
+
onErrorRef.current?.(errorMessage);
|
|
94
108
|
} finally {
|
|
95
|
-
if (!abortRef.current) {
|
|
109
|
+
if (!abortRef.current && !abortControllerRef.current?.signal.aborted) {
|
|
96
110
|
setIsGenerating(false);
|
|
97
111
|
}
|
|
112
|
+
abortControllerRef.current = null;
|
|
98
113
|
}
|
|
99
114
|
},
|
|
100
|
-
[options, handleProgress],
|
|
115
|
+
[options.model, options.capability, handleProgress],
|
|
101
116
|
);
|
|
102
117
|
|
|
103
118
|
const reset = useCallback(() => {
|
|
104
119
|
abortRef.current = true;
|
|
120
|
+
abortControllerRef.current?.abort();
|
|
121
|
+
abortControllerRef.current = null;
|
|
105
122
|
setResult(null);
|
|
106
123
|
setProgress(null);
|
|
107
124
|
setIsGenerating(false);
|