@umituz/react-native-ai-generation-content 1.19.0 → 1.19.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-generation-content",
3
- "version": "1.19.0",
3
+ "version": "1.19.2",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -16,6 +16,13 @@ export type {
16
16
  export { COUPLE_FUTURE_DEFAULTS } from "./domain/types";
17
17
  export { useCoupleFutureGeneration } from "./presentation/hooks/useCoupleFutureGeneration";
18
18
  export type { CoupleFutureConfig as UseCoupleFutureGenerationConfig } from "./presentation/hooks/useCoupleFutureGeneration";
19
+ export { useCoupleFutureFlow } from "./presentation/hooks/useCoupleFutureFlow";
20
+ export type {
21
+ CoupleFutureFlowConfig,
22
+ CoupleFutureFlowState,
23
+ CoupleFutureFlowActions,
24
+ CoupleFutureFlowProps,
25
+ } from "./presentation/hooks/useCoupleFutureFlow";
19
26
  export {
20
27
  RomanticMoodSelector,
21
28
  ArtStyleSelector,
@@ -0,0 +1,219 @@
1
+ /**
2
+ * useCoupleFutureFlow Hook
3
+ * Handles couple future wizard flow logic
4
+ */
5
+
6
+ import { useCallback, useEffect, useRef } from "react";
7
+ import { InteractionManager } from "react-native";
8
+ import { useCoupleFutureGeneration } from "./useCoupleFutureGeneration";
9
+ import { buildGenerationInputFromConfig } from "../../infrastructure/generationUtils";
10
+ import type { UploadedImage } from "../../../partner-upload/domain/types";
11
+
12
+ export interface CoupleFutureFlowConfig<TStep, TScenarioId> {
13
+ steps: {
14
+ SCENARIO: TStep;
15
+ SCENARIO_PREVIEW: TStep;
16
+ COUPLE_FEATURE_SELECTOR: TStep;
17
+ TEXT_INPUT: TStep;
18
+ PARTNER_A: TStep;
19
+ PARTNER_B: TStep;
20
+ GENERATING: TStep;
21
+ };
22
+ customScenarioId: TScenarioId;
23
+ }
24
+
25
+ export interface CoupleFutureFlowState<TStep, TScenarioId> {
26
+ step: TStep;
27
+ selectedScenarioId: TScenarioId | null;
28
+ selectedFeature: string | null;
29
+ partnerA: unknown;
30
+ partnerB: unknown;
31
+ partnerAName: string;
32
+ partnerBName: string;
33
+ customPrompt: string | null;
34
+ visualStyle: string | null;
35
+ selection: unknown;
36
+ isProcessing: boolean;
37
+ scenarioConfig: unknown;
38
+ selectedScenarioData: { requiresPhoto?: boolean } | null;
39
+ }
40
+
41
+ export interface CoupleFutureFlowActions<TStep, TScenarioId, TResult> {
42
+ setStep: (step: TStep) => void;
43
+ selectScenario: (id: TScenarioId) => void;
44
+ setPartnerA: (image: unknown) => void;
45
+ setPartnerAName: (name: string) => void;
46
+ setPartnerB: (image: unknown) => void;
47
+ setPartnerBName: (name: string) => void;
48
+ setCustomPrompt: (prompt: string) => void;
49
+ setVisualStyle: (style: string) => void;
50
+ startGeneration: () => void;
51
+ generationSuccess: (result: TResult) => void;
52
+ generationError: (error: string) => void;
53
+ requireFeature: (callback: () => void) => void;
54
+ onNavigateToHistory: () => void;
55
+ }
56
+
57
+ export interface CoupleFutureFlowProps<TStep, TScenarioId, TResult> {
58
+ userId?: string;
59
+ config: CoupleFutureFlowConfig<TStep, TScenarioId>;
60
+ state: CoupleFutureFlowState<TStep, TScenarioId>;
61
+ actions: CoupleFutureFlowActions<TStep, TScenarioId, TResult>;
62
+ generationConfig: {
63
+ visualStyleModifiers: Record<string, string>;
64
+ defaultPartnerAName: string;
65
+ defaultPartnerBName: string;
66
+ };
67
+ alertMessages: {
68
+ networkError: string;
69
+ policyViolation: string;
70
+ saveFailed: string;
71
+ creditFailed: string;
72
+ unknown: string;
73
+ };
74
+ processResult: (imageUrl: string, input: unknown) => TResult;
75
+ buildCreation: (result: TResult, input: unknown) => unknown;
76
+ onCreditsExhausted: () => void;
77
+ }
78
+
79
+ export const useCoupleFutureFlow = <TStep, TScenarioId, TResult>(
80
+ props: CoupleFutureFlowProps<TStep, TScenarioId, TResult>,
81
+ ) => {
82
+ const { config, state, actions, generationConfig, alertMessages } = props;
83
+ const { processResult, buildCreation, onCreditsExhausted, userId } = props;
84
+ const hasStarted = useRef(false);
85
+
86
+ const { generate, isGenerating, progress } =
87
+ useCoupleFutureGeneration<TResult>({
88
+ userId,
89
+ onCreditsExhausted,
90
+ onSuccess: (result) => {
91
+ actions.generationSuccess(result);
92
+ InteractionManager.runAfterInteractions(() => {
93
+ setTimeout(() => actions.onNavigateToHistory(), 300);
94
+ });
95
+ },
96
+ onError: actions.generationError,
97
+ processResult: processResult as never,
98
+ buildCreation: buildCreation as never,
99
+ alertMessages,
100
+ });
101
+
102
+ useEffect(() => {
103
+ if (state.step !== config.steps.GENERATING) {
104
+ hasStarted.current = false;
105
+ return;
106
+ }
107
+ if (!state.isProcessing || hasStarted.current) return;
108
+ hasStarted.current = true;
109
+
110
+ const input = buildGenerationInputFromConfig({
111
+ partnerA: state.partnerA as never,
112
+ partnerB: state.partnerB as never,
113
+ partnerAName: state.partnerAName,
114
+ partnerBName: state.partnerBName,
115
+ scenario: state.scenarioConfig as never,
116
+ customPrompt: state.customPrompt || undefined,
117
+ visualStyle: state.visualStyle || "",
118
+ defaultPartnerAName: generationConfig.defaultPartnerAName,
119
+ defaultPartnerBName: generationConfig.defaultPartnerBName,
120
+ coupleFeatureSelection: state.selection as never,
121
+ visualStyles: generationConfig.visualStyleModifiers,
122
+ customScenarioId: config.customScenarioId as string,
123
+ });
124
+ if (input) generate(input);
125
+ }, [state, config, generationConfig, generate]);
126
+
127
+ const handleScenarioSelect = useCallback(
128
+ (id: string) => {
129
+ actions.selectScenario(id as TScenarioId);
130
+ actions.setStep(config.steps.SCENARIO_PREVIEW);
131
+ },
132
+ [actions, config.steps.SCENARIO_PREVIEW],
133
+ );
134
+
135
+ const handleScenarioPreviewBack = useCallback(
136
+ () => actions.setStep(config.steps.SCENARIO),
137
+ [actions, config.steps.SCENARIO],
138
+ );
139
+
140
+ const handleScenarioPreviewContinue = useCallback(() => {
141
+ if (state.selectedFeature) {
142
+ actions.setStep(config.steps.COUPLE_FEATURE_SELECTOR);
143
+ } else if (
144
+ state.selectedScenarioId === config.customScenarioId ||
145
+ state.selectedScenarioData?.requiresPhoto === false
146
+ ) {
147
+ actions.setStep(config.steps.TEXT_INPUT);
148
+ } else {
149
+ actions.setStep(config.steps.PARTNER_A);
150
+ }
151
+ }, [actions, config, state]);
152
+
153
+ const handlePartnerAContinue = useCallback(
154
+ (image: UploadedImage, name: string) => {
155
+ actions.setPartnerA(image);
156
+ actions.setPartnerAName(name);
157
+ actions.setStep(config.steps.PARTNER_B);
158
+ },
159
+ [actions, config.steps.PARTNER_B],
160
+ );
161
+
162
+ const handlePartnerABack = useCallback(() => {
163
+ actions.setStep(
164
+ state.selectedScenarioId === config.customScenarioId
165
+ ? config.steps.TEXT_INPUT
166
+ : config.steps.SCENARIO_PREVIEW,
167
+ );
168
+ }, [actions, config, state.selectedScenarioId]);
169
+
170
+ const handlePartnerBContinue = useCallback(
171
+ (image: UploadedImage, name: string) => {
172
+ actions.requireFeature(() => {
173
+ actions.setPartnerB(image);
174
+ actions.setPartnerBName(name);
175
+ actions.startGeneration();
176
+ });
177
+ },
178
+ [actions],
179
+ );
180
+
181
+ const handlePartnerBBack = useCallback(
182
+ () => actions.setStep(config.steps.PARTNER_A),
183
+ [actions, config.steps.PARTNER_A],
184
+ );
185
+
186
+ const handleMagicPromptContinue = useCallback(
187
+ (prompt: string, style: string) => {
188
+ actions.setCustomPrompt(prompt);
189
+ actions.setVisualStyle(style);
190
+ if (state.selectedScenarioId === config.customScenarioId) {
191
+ actions.setStep(config.steps.PARTNER_A);
192
+ } else {
193
+ actions.startGeneration();
194
+ }
195
+ },
196
+ [actions, config, state.selectedScenarioId],
197
+ );
198
+
199
+ const handleMagicPromptBack = useCallback(
200
+ () => actions.setStep(config.steps.SCENARIO_PREVIEW),
201
+ [actions, config.steps.SCENARIO_PREVIEW],
202
+ );
203
+
204
+ return {
205
+ isGenerating,
206
+ progress,
207
+ handlers: {
208
+ handleScenarioSelect,
209
+ handleScenarioPreviewBack,
210
+ handleScenarioPreviewContinue,
211
+ handlePartnerAContinue,
212
+ handlePartnerABack,
213
+ handlePartnerBContinue,
214
+ handlePartnerBBack,
215
+ handleMagicPromptContinue,
216
+ handleMagicPromptBack,
217
+ },
218
+ };
219
+ };
@@ -3,7 +3,7 @@
3
3
  * Couple future generation using centralized orchestrator
4
4
  */
5
5
 
6
- import { useMemo, useCallback } from "react";
6
+ import { useMemo, useCallback, useRef } from "react";
7
7
  import {
8
8
  useGenerationOrchestrator,
9
9
  type GenerationStrategy,
@@ -42,9 +42,15 @@ export const useCoupleFutureGeneration = <TResult>(
42
42
  [],
43
43
  );
44
44
 
45
+ // Store input for use in save callback
46
+ const lastInputRef = useRef<CoupleFutureInput | null>(null);
47
+
45
48
  const strategy: GenerationStrategy<CoupleFutureInput, TResult> = useMemo(
46
49
  () => ({
47
50
  execute: async (input, onProgress) => {
51
+ // Store input for save callback
52
+ lastInputRef.current = input;
53
+
48
54
  const result = await executeCoupleFuture(
49
55
  {
50
56
  partnerABase64: input.partnerABase64,
@@ -63,9 +69,12 @@ export const useCoupleFutureGeneration = <TResult>(
63
69
  getCreditCost: () => 1,
64
70
  save: buildCreation
65
71
  ? async (result, uid) => {
66
- const creation = buildCreation(result, {} as CoupleFutureInput);
67
- if (creation) {
68
- await repository.create(uid, creation);
72
+ const input = lastInputRef.current;
73
+ if (input) {
74
+ const creation = buildCreation(result, input);
75
+ if (creation) {
76
+ await repository.create(uid, creation);
77
+ }
69
78
  }
70
79
  }
71
80
  : undefined,