@umituz/react-native-ai-generation-content 1.72.4 → 1.72.5

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.72.4",
3
+ "version": "1.72.5",
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",
@@ -17,16 +17,34 @@ import type {
17
17
  AIFeatureGateReturn,
18
18
  } from "../types/access-control.types";
19
19
 
20
+ declare const __DEV__: boolean;
21
+
20
22
  const handlePromiseResult = (
21
23
  result: void | Promise<void>,
22
24
  onSuccess?: () => void,
23
25
  onError?: (error: Error) => void,
24
26
  ): void => {
27
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
28
+ console.log("[AIFeatureGate] handlePromiseResult - isPromise:", result instanceof Promise);
29
+ }
25
30
  if (result instanceof Promise) {
26
31
  result
27
- .then(() => onSuccess?.())
28
- .catch((err) => onError?.(err instanceof Error ? err : new Error(String(err))));
32
+ .then(() => {
33
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
34
+ console.log("[AIFeatureGate] Promise resolved, calling onSuccess");
35
+ }
36
+ onSuccess?.();
37
+ })
38
+ .catch((err) => {
39
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
40
+ console.log("[AIFeatureGate] Promise rejected:", err);
41
+ }
42
+ onError?.(err instanceof Error ? err : new Error(String(err)));
43
+ });
29
44
  } else {
45
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
46
+ console.log("[AIFeatureGate] Sync result, calling onSuccess");
47
+ }
30
48
  onSuccess?.();
31
49
  }
32
50
  };
@@ -62,18 +80,45 @@ export function useAIFeatureGate(options: AIFeatureGateOptions): AIFeatureGateRe
62
80
 
63
81
  const requireFeature = useCallback(
64
82
  (action: () => void | Promise<void>): void => {
83
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
84
+ console.log("[AIFeatureGate] requireFeature called:", {
85
+ isOffline,
86
+ isAuthenticated,
87
+ isCreditsLoaded,
88
+ isPremium,
89
+ creditBalance,
90
+ creditCost,
91
+ hasCredits,
92
+ });
93
+ }
94
+
65
95
  if (isOffline) {
96
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
97
+ console.log("[AIFeatureGate] BLOCKED: User is offline");
98
+ }
66
99
  onNetworkError?.();
67
100
  return;
68
101
  }
69
102
 
70
- if (isAuthenticated && !isCreditsLoaded) return;
103
+ if (isAuthenticated && !isCreditsLoaded) {
104
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
105
+ console.log("[AIFeatureGate] BLOCKED: User authenticated but credits not loaded yet");
106
+ }
107
+ return;
108
+ }
109
+
110
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
111
+ console.log("[AIFeatureGate] Calling requireFeatureFromPackage");
112
+ }
71
113
 
72
114
  requireFeatureFromPackage(() => {
115
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
116
+ console.log("[AIFeatureGate] Inside requireFeatureFromPackage callback - executing action");
117
+ }
73
118
  handlePromiseResult(action(), onSuccess, onError);
74
119
  });
75
120
  },
76
- [isOffline, isAuthenticated, isCreditsLoaded, onNetworkError, requireFeatureFromPackage, onSuccess, onError],
121
+ [isOffline, isAuthenticated, isCreditsLoaded, isPremium, creditBalance, creditCost, hasCredits, onNetworkError, requireFeatureFromPackage, onSuccess, onError],
77
122
  );
78
123
 
79
124
  return {
@@ -39,7 +39,7 @@ export const HierarchicalScenarioListScreen: React.FC<HierarchicalScenarioListSc
39
39
  onSelectScenario,
40
40
  onBack,
41
41
  t,
42
- numColumns = 1,
42
+ numColumns = 2,
43
43
  isLoading = false,
44
44
  }) => {
45
45
  const tokens = useAppDesignTokens();
@@ -133,7 +133,7 @@ export const HierarchicalScenarioListScreen: React.FC<HierarchicalScenarioListSc
133
133
  data={filteredScenarios}
134
134
  numColumns={numColumns}
135
135
  showsVerticalScrollIndicator={false}
136
- columnWrapperStyle={numColumns > 1 ? styles.row : undefined}
136
+ columnWrapperStyle={styles.row}
137
137
  renderItem={renderItem}
138
138
  keyExtractor={(item) => item.id}
139
139
  ListEmptyComponent={isLoading ? LoadingComponent : (filteredScenarios.length === 0 ? ListEmptyComponent : null)}
@@ -62,25 +62,61 @@ export const useGenerationOrchestrator = <TInput, TResult>(
62
62
 
63
63
  const executeGeneration = useCallback(
64
64
  async (input: TInput) => {
65
- const creditDeducted = await deductCredit(strategy.getCreditCost());
66
- if (!creditDeducted) throw createGenerationError("credits", alertMessages.creditFailed);
65
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
66
+ console.log("[Orchestrator] ----------------------------------------");
67
+ console.log("[Orchestrator] executeGeneration() called");
68
+ }
69
+
70
+ const creditCost = strategy.getCreditCost();
71
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
72
+ console.log("[Orchestrator] Deducting credits:", creditCost);
73
+ }
74
+
75
+ const creditDeducted = await deductCredit(creditCost);
76
+ if (!creditDeducted) {
77
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
78
+ console.log("[Orchestrator] ERROR: Credit deduction failed");
79
+ }
80
+ throw createGenerationError("credits", alertMessages.creditFailed);
81
+ }
82
+
83
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
84
+ console.log("[Orchestrator] Credits deducted successfully");
85
+ }
67
86
 
68
87
  setState((prev) => ({ ...prev, status: "generating" }));
69
- if (typeof __DEV__ !== "undefined" && __DEV__) console.log("[Orchestrator] Starting generation");
88
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
89
+ console.log("[Orchestrator] State: generating - calling strategy.execute()");
90
+ }
70
91
 
71
92
  const result = await strategy.execute(input);
93
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
94
+ console.log("[Orchestrator] strategy.execute() completed");
95
+ }
72
96
 
73
97
  if (strategy.save && userId) {
74
98
  if (isMountedRef.current) setState((prev) => ({ ...prev, status: "saving" }));
99
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
100
+ console.log("[Orchestrator] Saving result to Firestore");
101
+ }
75
102
  try {
76
103
  await strategy.save(result, userId);
104
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
105
+ console.log("[Orchestrator] Result saved successfully");
106
+ }
77
107
  } catch (saveErr) {
108
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
109
+ console.log("[Orchestrator] ERROR: Save failed:", saveErr);
110
+ }
78
111
  throw createGenerationError("save", alertMessages.saveFailed, saveErr instanceof Error ? saveErr : undefined);
79
112
  }
80
113
  }
81
114
 
82
115
  if (isMountedRef.current) setState({ status: "success", isGenerating: false, result, error: null });
83
- if (typeof __DEV__ !== "undefined" && __DEV__) console.log("[Orchestrator] Generation SUCCESS");
116
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
117
+ console.log("[Orchestrator] ✅ Generation SUCCESS");
118
+ console.log("[Orchestrator] ========================================");
119
+ }
84
120
 
85
121
  if (alertMessages.success) showSuccess("Success", alertMessages.success);
86
122
  onSuccess?.(result);
@@ -92,41 +128,81 @@ export const useGenerationOrchestrator = <TInput, TResult>(
92
128
 
93
129
  const generate = useCallback(
94
130
  async (input: TInput) => {
95
- if (typeof __DEV__ !== "undefined" && __DEV__) console.log("[Orchestrator] generate() called");
96
- if (isGeneratingRef.current) return;
131
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
132
+ console.log("[Orchestrator] ========================================");
133
+ console.log("[Orchestrator] generate() called with input:", JSON.stringify(input).substring(0, 200));
134
+ console.log("[Orchestrator] isGenerating:", isGeneratingRef.current);
135
+ console.log("[Orchestrator] userId:", userId);
136
+ }
137
+
138
+ if (isGeneratingRef.current) {
139
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
140
+ console.log("[Orchestrator] BLOCKED: Already generating");
141
+ }
142
+ return;
143
+ }
97
144
 
98
145
  // Create new AbortController for this generation
99
146
  abortControllerRef.current = new AbortController();
100
147
  isGeneratingRef.current = true;
101
148
  setState({ ...INITIAL_STATE, status: "checking", isGenerating: true });
102
149
 
150
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
151
+ console.log("[Orchestrator] State set to 'checking', isGenerating: true");
152
+ }
153
+
103
154
  try {
104
155
  // Check online status inside the try block to avoid dependency on offlineStore.isOnline
105
156
  if (!offlineStore.isOnline) {
157
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
158
+ console.log("[Orchestrator] ERROR: User is offline");
159
+ }
106
160
  throw createGenerationError("network", alertMessages.networkError);
107
161
  }
108
162
 
163
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
164
+ console.log("[Orchestrator] Online check passed");
165
+ }
166
+
109
167
  // Check if aborted
110
168
  if (abortControllerRef.current.signal.aborted) {
169
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
170
+ console.log("[Orchestrator] ERROR: Generation aborted (1)");
171
+ }
111
172
  throw new Error("Generation aborted");
112
173
  }
113
174
 
114
175
  // Pre-validate credits before generation to catch concurrent consumption
115
176
  const creditCost = strategy.getCreditCost();
177
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
178
+ console.log("[Orchestrator] Checking credits - cost:", creditCost);
179
+ }
180
+
116
181
  const hasEnoughCredits = await checkCredits(creditCost);
117
182
  if (!hasEnoughCredits) {
118
183
  if (typeof __DEV__ !== "undefined" && __DEV__) {
119
- console.log("[Orchestrator] Pre-validation: insufficient credits");
184
+ console.log("[Orchestrator] ERROR: Pre-validation failed - insufficient credits");
120
185
  }
121
186
  onCreditsExhausted?.();
122
187
  throw createGenerationError("credits", alertMessages.creditFailed);
123
188
  }
124
189
 
190
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
191
+ console.log("[Orchestrator] Credit check passed");
192
+ }
193
+
125
194
  // Check if aborted before moderation
126
195
  if (abortControllerRef.current.signal.aborted) {
196
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
197
+ console.log("[Orchestrator] ERROR: Generation aborted (2)");
198
+ }
127
199
  throw new Error("Generation aborted");
128
200
  }
129
201
 
202
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
203
+ console.log("[Orchestrator] Starting moderation check");
204
+ }
205
+
130
206
  return await handleModeration({
131
207
  input,
132
208
  moderation,