@umituz/react-native-ai-generation-content 1.17.102 → 1.17.104

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.17.102",
3
+ "version": "1.17.104",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -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__) console.log("[TextToImage] handleGenerate called");
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__) console.log("[TextToImage] No prompt provided");
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__) console.log("[TextToImage] isAuthenticated:", isAuth);
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__) console.log("[TextToImage] Auth required - calling onAuthRequired");
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__) console.log("[TextToImage] canAfford:", affordable, "totalCost:", totalCost);
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__) console.log("[TextToImage] Credits required - calling onCreditsRequired");
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__) console.log("[TextToImage] Starting generation...");
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__) console.log("[TextToImage] Request:", JSON.stringify(request, null, 2));
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 ? undefined : result.error,
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__) console.log("[TextToImage] Success! Generated", result.imageUrls?.length, "image(s)");
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__) console.log("[TextToImage] Generation failed:", result.error);
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__) console.error("[TextToImage] Exception:", message);
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;
@@ -51,6 +51,7 @@ export {
51
51
  export type {
52
52
  UseTextToVideoFeatureProps,
53
53
  UseTextToVideoFeatureReturn,
54
+ TextToVideoGenerateParams,
54
55
  UseTextToVideoFormProps,
55
56
  UseTextToVideoFormReturn,
56
57
  } from "./presentation";
@@ -7,6 +7,7 @@ export { useTextToVideoFeature } from "./useTextToVideoFeature";
7
7
  export type {
8
8
  UseTextToVideoFeatureProps,
9
9
  UseTextToVideoFeatureReturn,
10
+ TextToVideoGenerateParams,
10
11
  } from "./useTextToVideoFeature";
11
12
 
12
13
  export { useTextToVideoForm } from "./useTextToVideoForm";
@@ -25,10 +25,14 @@ export interface UseTextToVideoFeatureProps {
25
25
  extractResult?: TextToVideoResultExtractor;
26
26
  }
27
27
 
28
+ export interface TextToVideoGenerateParams extends TextToVideoOptions {
29
+ prompt?: string;
30
+ }
31
+
28
32
  export interface UseTextToVideoFeatureReturn {
29
33
  state: TextToVideoFeatureState;
30
34
  setPrompt: (prompt: string) => void;
31
- generate: (options?: TextToVideoOptions) => Promise<TextToVideoResult>;
35
+ generate: (params?: TextToVideoGenerateParams) => Promise<TextToVideoResult>;
32
36
  reset: () => void;
33
37
  isReady: boolean;
34
38
  canGenerate: boolean;
@@ -58,25 +62,44 @@ export function useTextToVideoFeature(
58
62
  );
59
63
 
60
64
  const generate = useCallback(
61
- async (options?: TextToVideoOptions): Promise<TextToVideoResult> => {
62
- if (!state.prompt.trim()) {
65
+ async (params?: TextToVideoGenerateParams): Promise<TextToVideoResult> => {
66
+ const { prompt: paramPrompt, ...options } = params || {};
67
+ const effectivePrompt = paramPrompt?.trim() || state.prompt.trim();
68
+
69
+ if (!effectivePrompt) {
63
70
  const error = "Prompt is required";
64
71
  setState((prev) => ({ ...prev, error }));
65
72
  callbacks.onError?.(error);
73
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
74
+ // eslint-disable-next-line no-console
75
+ console.log("[TextToVideoFeature] Generate failed: Prompt is required");
76
+ }
66
77
  return { success: false, error };
67
78
  }
68
79
 
80
+ if (paramPrompt) {
81
+ setState((prev) => ({ ...prev, prompt: effectivePrompt }));
82
+ }
83
+
69
84
  if (callbacks.onAuthCheck && !callbacks.onAuthCheck()) {
85
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
86
+ // eslint-disable-next-line no-console
87
+ console.log("[TextToVideoFeature] Generate failed: Authentication required");
88
+ }
70
89
  return { success: false, error: "Authentication required" };
71
90
  }
72
91
 
73
- if (callbacks.onCreditCheck && !callbacks.onCreditCheck(config.creditCost)) {
92
+ if (callbacks.onCreditCheck && !(await callbacks.onCreditCheck(config.creditCost))) {
74
93
  callbacks.onShowPaywall?.(config.creditCost);
94
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
95
+ // eslint-disable-next-line no-console
96
+ console.log("[TextToVideoFeature] Generate failed: Insufficient credits");
97
+ }
75
98
  return { success: false, error: "Insufficient credits" };
76
99
  }
77
100
 
78
101
  if (callbacks.onModeration) {
79
- const moderationResult = await callbacks.onModeration(state.prompt);
102
+ const moderationResult = await callbacks.onModeration(effectivePrompt);
80
103
  if (!moderationResult.allowed && moderationResult.warnings.length > 0) {
81
104
  return new Promise((resolve) => {
82
105
  callbacks.onShowModerationWarning?.(
@@ -86,7 +109,7 @@ export function useTextToVideoFeature(
86
109
  resolve({ success: false, error: "Content policy violation" });
87
110
  },
88
111
  async () => {
89
- const result = await executeGeneration(options);
112
+ const result = await executeGeneration(effectivePrompt, options);
90
113
  resolve(result);
91
114
  },
92
115
  );
@@ -94,13 +117,13 @@ export function useTextToVideoFeature(
94
117
  }
95
118
  }
96
119
 
97
- return executeGeneration(options);
120
+ return executeGeneration(effectivePrompt, options);
98
121
  },
99
- [state.prompt, callbacks, config.creditCost, buildInput, extractResult, userId],
122
+ [state.prompt, callbacks, config.creditCost],
100
123
  );
101
124
 
102
125
  const executeGeneration = useCallback(
103
- async (options?: TextToVideoOptions): Promise<TextToVideoResult> => {
126
+ async (prompt: string, options?: TextToVideoOptions): Promise<TextToVideoResult> => {
104
127
  setState((prev) => ({
105
128
  ...prev,
106
129
  isProcessing: true,
@@ -108,13 +131,13 @@ export function useTextToVideoFeature(
108
131
  error: null,
109
132
  }));
110
133
 
111
- if (__DEV__) {
134
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
112
135
  // eslint-disable-next-line no-console
113
- console.log("[TextToVideoFeature] Starting generation");
136
+ console.log("[TextToVideoFeature] Starting generation with prompt:", prompt);
114
137
  }
115
138
 
116
139
  const result = await executeTextToVideo(
117
- { prompt: state.prompt, userId, options },
140
+ { prompt, userId, options },
118
141
  {
119
142
  model: config.model,
120
143
  buildInput,
@@ -147,7 +170,7 @@ export function useTextToVideoFeature(
147
170
 
148
171
  return result;
149
172
  },
150
- [state.prompt, userId, config.model, buildInput, extractResult, callbacks],
173
+ [userId, config.model, buildInput, extractResult, callbacks],
151
174
  );
152
175
 
153
176
  const reset = useCallback(() => {
@@ -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__) console.log(`[${featureName}] Success:`, result);
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__) console.error(`[${featureName}] Error:`, error);
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__) console.log(`[${featureName}] Auth required`);
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__) console.log(`[${featureName}] Insufficient credits`);
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
- // Log immediately on every render
48
- if (__DEV__) console.log("[AIGenerationForm] RENDERING NOW - hideGenerateButton:", hideGenerateButton);
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
- // Log immediately on every render
46
- if (__DEV__) console.log("[GenerateButton] RENDERING NOW");
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__) console.log("[GenerateButton] PRESSED - disabled:", disabled, "isDisabled:", isDisabled, "isProcessing:", isProcessing);
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
- config.showAuthModal ? config.showAuthModal() : config.openPaywall();
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,