@umituz/react-native-ai-generation-content 1.17.94 → 1.17.95
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
package/src/index.ts
CHANGED
|
@@ -280,6 +280,7 @@ export type {
|
|
|
280
280
|
UseGenerationCallbacksBuilderOptions,
|
|
281
281
|
AIFeatureCallbacksConfig,
|
|
282
282
|
AIFeatureCallbacks,
|
|
283
|
+
AIFeatureGenerationResult,
|
|
283
284
|
} from "./presentation/hooks";
|
|
284
285
|
|
|
285
286
|
// =============================================================================
|
|
@@ -34,16 +34,19 @@ export interface AIFeatureCallbacksConfig<TRequest = unknown, TResult = unknown>
|
|
|
34
34
|
onError?: (error: string) => void;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Discriminated union result type for generation
|
|
39
|
+
*/
|
|
40
|
+
export type AIFeatureGenerationResult =
|
|
41
|
+
| { success: true; imageUrls: string[] }
|
|
42
|
+
| { success: false; error: string };
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Universal callbacks interface that maps to all feature-specific ones
|
|
39
46
|
*/
|
|
40
47
|
export interface AIFeatureCallbacks<TRequest = unknown, TResult = unknown> {
|
|
41
48
|
// TextToImageCallbacks compatible
|
|
42
|
-
executeGeneration: (request: TRequest) => Promise<
|
|
43
|
-
success: boolean;
|
|
44
|
-
imageUrls?: string[];
|
|
45
|
-
error?: string;
|
|
46
|
-
}>;
|
|
49
|
+
executeGeneration: (request: TRequest) => Promise<AIFeatureGenerationResult>;
|
|
47
50
|
calculateCost: (multiplier?: number, _model?: string | null) => number;
|
|
48
51
|
canAfford: (cost: number) => boolean;
|
|
49
52
|
isAuthenticated: () => boolean;
|
|
@@ -103,7 +106,7 @@ export function useAIFeatureCallbacks<TRequest = unknown, TResult = unknown>(
|
|
|
103
106
|
);
|
|
104
107
|
|
|
105
108
|
const executeGeneration = useCallback(
|
|
106
|
-
async (request: TRequest) => {
|
|
109
|
+
async (request: TRequest): Promise<AIFeatureGenerationResult> => {
|
|
107
110
|
try {
|
|
108
111
|
const result = await executor(request);
|
|
109
112
|
|
|
@@ -117,11 +120,10 @@ export function useAIFeatureCallbacks<TRequest = unknown, TResult = unknown>(
|
|
|
117
120
|
onError?.(result.error);
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
success: result.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
123
|
+
if (result.success) {
|
|
124
|
+
return { success: true, imageUrls: result.imageUrls ?? [] };
|
|
125
|
+
}
|
|
126
|
+
return { success: false, error: result.error ?? "Unknown error" };
|
|
125
127
|
} catch (error) {
|
|
126
128
|
const message = error instanceof Error ? error.message : String(error);
|
|
127
129
|
onError?.(message);
|