@umituz/react-native-ai-generation-content 1.17.102 → 1.17.103
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/features/text-to-image/presentation/hooks/useGeneration.ts +47 -13
- package/src/infrastructure/config/app-services.config.ts +8 -0
- package/src/infrastructure/utils/feature-utils.ts +16 -4
- package/src/presentation/components/AIGenerationForm.tsx +6 -3
- package/src/presentation/components/buttons/GenerateButton.tsx +10 -4
- package/src/presentation/hooks/useGenerationCallbacksBuilder.ts +6 -1
package/package.json
CHANGED
|
@@ -44,35 +44,56 @@ export function useGeneration(options: UseGenerationOptions): UseGenerationRetur
|
|
|
44
44
|
const totalCost = callbacks.calculateCost(formState.numImages, formState.selectedModel);
|
|
45
45
|
|
|
46
46
|
const handleGenerate = useCallback(async (): Promise<TextToImageGenerationResult | null> => {
|
|
47
|
-
if (__DEV__
|
|
47
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.log("[TextToImage] handleGenerate called");
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
const trimmedPrompt = formState.prompt.trim();
|
|
50
53
|
|
|
51
54
|
if (!trimmedPrompt) {
|
|
52
|
-
if (__DEV__
|
|
55
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.log("[TextToImage] No prompt provided");
|
|
58
|
+
}
|
|
53
59
|
setGenerationState((prev) => ({ ...prev, error: "Prompt is required" }));
|
|
54
60
|
return null;
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
const isAuth = callbacks.isAuthenticated();
|
|
58
|
-
if (__DEV__
|
|
64
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
65
|
+
// eslint-disable-next-line no-console
|
|
66
|
+
console.log("[TextToImage] isAuthenticated:", isAuth);
|
|
67
|
+
}
|
|
59
68
|
|
|
60
69
|
if (!isAuth) {
|
|
61
|
-
if (__DEV__
|
|
70
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.log("[TextToImage] Auth required - calling onAuthRequired");
|
|
73
|
+
}
|
|
62
74
|
callbacks.onAuthRequired?.();
|
|
63
75
|
return null;
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
const affordable = callbacks.canAfford(totalCost);
|
|
67
|
-
if (__DEV__
|
|
79
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
81
|
+
console.log("[TextToImage] canAfford:", affordable, "totalCost:", totalCost);
|
|
82
|
+
}
|
|
68
83
|
|
|
69
84
|
if (!affordable) {
|
|
70
|
-
if (__DEV__
|
|
85
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
86
|
+
// eslint-disable-next-line no-console
|
|
87
|
+
console.log("[TextToImage] Credits required - calling onCreditsRequired");
|
|
88
|
+
}
|
|
71
89
|
callbacks.onCreditsRequired?.(totalCost);
|
|
72
90
|
return null;
|
|
73
91
|
}
|
|
74
92
|
|
|
75
|
-
if (__DEV__
|
|
93
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.log("[TextToImage] Starting generation...");
|
|
96
|
+
}
|
|
76
97
|
setGenerationState({ isGenerating: true, progress: 0, error: null });
|
|
77
98
|
|
|
78
99
|
const request: TextToImageGenerationRequest = {
|
|
@@ -87,26 +108,36 @@ export function useGeneration(options: UseGenerationOptions): UseGenerationRetur
|
|
|
87
108
|
outputFormat: formState.outputFormat,
|
|
88
109
|
};
|
|
89
110
|
|
|
90
|
-
if (__DEV__
|
|
111
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
113
|
+
console.log("[TextToImage] Request:", JSON.stringify(request, null, 2));
|
|
114
|
+
}
|
|
91
115
|
|
|
92
116
|
try {
|
|
93
117
|
const result = await callbacks.executeGeneration(request);
|
|
94
|
-
if (__DEV__) {
|
|
118
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
95
119
|
const logResult = {
|
|
96
120
|
success: result.success,
|
|
97
121
|
imageCount: result.success ? result.imageUrls?.length : 0,
|
|
98
|
-
error: result.success ?
|
|
122
|
+
error: !result.success ? result.error : undefined,
|
|
99
123
|
};
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
100
125
|
console.log("[TextToImage] Result:", JSON.stringify(logResult));
|
|
101
126
|
}
|
|
102
127
|
|
|
103
128
|
if (result.success === true) {
|
|
104
|
-
if (__DEV__
|
|
129
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
130
|
+
// eslint-disable-next-line no-console
|
|
131
|
+
console.log("[TextToImage] Success! Generated", result.imageUrls?.length, "image(s)");
|
|
132
|
+
}
|
|
105
133
|
callbacks.onSuccess?.(result.imageUrls);
|
|
106
134
|
onPromptCleared?.();
|
|
107
135
|
setGenerationState({ isGenerating: false, progress: 100, error: null });
|
|
108
136
|
} else {
|
|
109
|
-
if (__DEV__
|
|
137
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
138
|
+
// eslint-disable-next-line no-console
|
|
139
|
+
console.log("[TextToImage] Generation failed:", result.error);
|
|
140
|
+
}
|
|
110
141
|
setGenerationState({ isGenerating: false, progress: 0, error: result.error });
|
|
111
142
|
callbacks.onError?.(result.error);
|
|
112
143
|
}
|
|
@@ -114,7 +145,10 @@ export function useGeneration(options: UseGenerationOptions): UseGenerationRetur
|
|
|
114
145
|
return result;
|
|
115
146
|
} catch (error) {
|
|
116
147
|
const message = error instanceof Error ? error.message : String(error);
|
|
117
|
-
if (__DEV__
|
|
148
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
149
|
+
// eslint-disable-next-line no-console
|
|
150
|
+
console.error("[TextToImage] Exception:", message);
|
|
151
|
+
}
|
|
118
152
|
setGenerationState({ isGenerating: false, progress: 0, error: message });
|
|
119
153
|
callbacks.onError?.(message);
|
|
120
154
|
return null;
|
|
@@ -24,6 +24,14 @@ const defaultAnalytics = {
|
|
|
24
24
|
* @param services - App-specific service implementations
|
|
25
25
|
*/
|
|
26
26
|
export function configureAppServices(services: IAppServices): void {
|
|
27
|
+
if (appServices !== null) {
|
|
28
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log("[AppServices] Already configured, skipping");
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
28
36
|
// eslint-disable-next-line no-console
|
|
29
37
|
console.log("[AppServices] Configuring app services");
|
|
@@ -23,10 +23,16 @@ export async function prepareImage(uri: string): Promise<string> {
|
|
|
23
23
|
export function createDevCallbacks(featureName: string) {
|
|
24
24
|
return {
|
|
25
25
|
onSuccess: (result: unknown) => {
|
|
26
|
-
if (__DEV__
|
|
26
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.log(`[${featureName}] Success:`, result);
|
|
29
|
+
}
|
|
27
30
|
},
|
|
28
31
|
onError: (error: unknown) => {
|
|
29
|
-
if (__DEV__
|
|
32
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.error(`[${featureName}] Error:`, error);
|
|
35
|
+
}
|
|
30
36
|
},
|
|
31
37
|
};
|
|
32
38
|
}
|
|
@@ -44,7 +50,10 @@ async function checkCreditGuard(cost: number, featureName: string): Promise<bool
|
|
|
44
50
|
const paywallService = getPaywallService();
|
|
45
51
|
|
|
46
52
|
if (!authService.isAuthenticated()) {
|
|
47
|
-
if (__DEV__
|
|
53
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.log(`[${featureName}] Auth required`);
|
|
56
|
+
}
|
|
48
57
|
try {
|
|
49
58
|
authService.requireAuth();
|
|
50
59
|
} catch {
|
|
@@ -55,7 +64,10 @@ async function checkCreditGuard(cost: number, featureName: string): Promise<bool
|
|
|
55
64
|
|
|
56
65
|
const hasCredits = await creditService.checkCredits(cost);
|
|
57
66
|
if (!hasCredits) {
|
|
58
|
-
if (__DEV__
|
|
67
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.log(`[${featureName}] Insufficient credits`);
|
|
70
|
+
}
|
|
59
71
|
paywallService.showPaywall(cost);
|
|
60
72
|
return false;
|
|
61
73
|
}
|
|
@@ -44,15 +44,18 @@ export const AIGenerationForm: React.FC<AIGenerationFormProps> = ({
|
|
|
44
44
|
translations,
|
|
45
45
|
children,
|
|
46
46
|
}) => {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.log("[AIGenerationForm] RENDERING NOW - hideGenerateButton:", hideGenerateButton);
|
|
50
|
+
}
|
|
49
51
|
|
|
50
52
|
const tokens = useAppDesignTokens();
|
|
51
53
|
const isAdvancedVisible = showAdvanced !== undefined ? showAdvanced : true;
|
|
52
54
|
const buttonIsDisabled = onPromptChange ? !prompt?.trim() : false;
|
|
53
55
|
|
|
54
56
|
useEffect(() => {
|
|
55
|
-
if (__DEV__) {
|
|
57
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
56
59
|
console.log("[AIGenerationForm] MOUNTED/UPDATED - prompt:", prompt, "isGenerating:", isGenerating, "buttonIsDisabled:", buttonIsDisabled, "hideGenerateButton:", hideGenerateButton);
|
|
57
60
|
}
|
|
58
61
|
}, [prompt, isGenerating, buttonIsDisabled, hideGenerateButton]);
|
|
@@ -42,8 +42,10 @@ export const GenerateButton: React.FC<GenerateButtonProps> = ({
|
|
|
42
42
|
onAccessoryRightPress,
|
|
43
43
|
style,
|
|
44
44
|
}) => {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
46
|
+
// eslint-disable-next-line no-console
|
|
47
|
+
console.log("[GenerateButton] RENDERING NOW");
|
|
48
|
+
}
|
|
47
49
|
|
|
48
50
|
const tokens = useAppDesignTokens();
|
|
49
51
|
const disabled = isDisabled || isProcessing;
|
|
@@ -51,13 +53,17 @@ export const GenerateButton: React.FC<GenerateButtonProps> = ({
|
|
|
51
53
|
const finalDisplayText = costLabel ? `${displayText} (${costLabel})` : displayText;
|
|
52
54
|
|
|
53
55
|
useEffect(() => {
|
|
54
|
-
if (__DEV__) {
|
|
56
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
55
58
|
console.log("[GenerateButton] MOUNTED/UPDATED - isDisabled:", isDisabled, "isProcessing:", isProcessing, "disabled:", disabled, "text:", text);
|
|
56
59
|
}
|
|
57
60
|
}, [isDisabled, isProcessing, disabled, text]);
|
|
58
61
|
|
|
59
62
|
const handlePress = () => {
|
|
60
|
-
if (__DEV__
|
|
63
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.log("[GenerateButton] PRESSED - disabled:", disabled, "isDisabled:", isDisabled, "isProcessing:", isProcessing);
|
|
66
|
+
}
|
|
61
67
|
if (!disabled) {
|
|
62
68
|
onPress();
|
|
63
69
|
}
|
|
@@ -39,7 +39,11 @@ export function useGenerationCallbacksBuilder<TRequest, TResult>(
|
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
const onAuthRequired = useCallback(() => {
|
|
42
|
-
|
|
42
|
+
if (config.showAuthModal) {
|
|
43
|
+
config.showAuthModal();
|
|
44
|
+
} else {
|
|
45
|
+
config.openPaywall();
|
|
46
|
+
}
|
|
43
47
|
}, [config]);
|
|
44
48
|
|
|
45
49
|
const onCreditsRequired = useCallback(() => {
|
|
@@ -59,6 +63,7 @@ export function useGenerationCallbacksBuilder<TRequest, TResult>(
|
|
|
59
63
|
|
|
60
64
|
if (!canAfford()) {
|
|
61
65
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
66
|
+
// eslint-disable-next-line no-console
|
|
62
67
|
console.log("[Generation] Insufficient credits", {
|
|
63
68
|
balance: config.creditBalance,
|
|
64
69
|
cost: config.creditCost,
|