@umituz/react-native-ai-generation-content 1.10.4 → 1.11.0
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
|
@@ -15,7 +15,7 @@ export interface PhotoGenerationResult<TResult = any> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface PhotoGenerationError {
|
|
18
|
-
type: "
|
|
18
|
+
type: "network_error" | "policy_violation" | "save_failed" | "credit_failed" | "unknown";
|
|
19
19
|
message: string;
|
|
20
20
|
originalError?: Error;
|
|
21
21
|
}
|
|
@@ -24,8 +24,8 @@ export interface PhotoGenerationConfig<TInput, TResult, TSaveInput> {
|
|
|
24
24
|
generate: (input: TInput) => Promise<TResult>;
|
|
25
25
|
save?: (result: TResult, input: TInput) => Promise<TSaveInput>;
|
|
26
26
|
checkCredits?: () => Promise<boolean>;
|
|
27
|
+
checkNetwork?: () => Promise<boolean>;
|
|
27
28
|
deductCredits?: () => Promise<void>;
|
|
28
|
-
timeout?: number;
|
|
29
29
|
onSuccess?: (result: TResult) => void;
|
|
30
30
|
onError?: (error: PhotoGenerationError) => void;
|
|
31
31
|
onSaveComplete?: (saveResult: TSaveInput) => void;
|
|
@@ -11,8 +11,6 @@ import type {
|
|
|
11
11
|
PhotoGenerationStatus,
|
|
12
12
|
} from "./photo-generation.types";
|
|
13
13
|
|
|
14
|
-
const DEFAULT_TIMEOUT = 60000;
|
|
15
|
-
|
|
16
14
|
export interface UsePhotoGenerationReturn<TResult> extends PhotoGenerationState<TResult> {
|
|
17
15
|
generate: <TInput>(input: TInput) => Promise<void>;
|
|
18
16
|
reset: () => void;
|
|
@@ -26,8 +24,8 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
26
24
|
generate: generateFn,
|
|
27
25
|
save: saveFn,
|
|
28
26
|
checkCredits,
|
|
27
|
+
checkNetwork,
|
|
29
28
|
deductCredits,
|
|
30
|
-
timeout = DEFAULT_TIMEOUT,
|
|
31
29
|
onSuccess,
|
|
32
30
|
onError,
|
|
33
31
|
onSaveComplete,
|
|
@@ -68,6 +66,15 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
68
66
|
setStatus("validating");
|
|
69
67
|
|
|
70
68
|
try {
|
|
69
|
+
// Check network connectivity
|
|
70
|
+
if (checkNetwork) {
|
|
71
|
+
const isOnline = await checkNetwork();
|
|
72
|
+
if (!isOnline) {
|
|
73
|
+
throw createError("network_error", "No internet connection");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Check credits
|
|
71
78
|
if (checkCredits) {
|
|
72
79
|
const hasCredits = await checkCredits();
|
|
73
80
|
if (!hasCredits) {
|
|
@@ -78,14 +85,12 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
78
85
|
setStatus("generating");
|
|
79
86
|
setState((prev) => ({ ...prev, progress: 20 }));
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const result = await Promise.race([generateFn(input), timeoutPromise]);
|
|
88
|
+
// Generate without timeout - let AI provider handle its own timeout
|
|
89
|
+
const result = await generateFn(input);
|
|
86
90
|
|
|
87
91
|
setState((prev) => ({ ...prev, progress: 60 }));
|
|
88
92
|
|
|
93
|
+
// Save result
|
|
89
94
|
if (saveFn) {
|
|
90
95
|
setStatus("saving");
|
|
91
96
|
try {
|
|
@@ -102,6 +107,7 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
102
107
|
|
|
103
108
|
setState((prev) => ({ ...prev, progress: 80 }));
|
|
104
109
|
|
|
110
|
+
// Deduct credits after successful generation
|
|
105
111
|
if (deductCredits) {
|
|
106
112
|
try {
|
|
107
113
|
await deductCredits();
|
|
@@ -123,11 +129,9 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
123
129
|
const generationError =
|
|
124
130
|
error.type
|
|
125
131
|
? error
|
|
126
|
-
: error.
|
|
127
|
-
? createError("
|
|
128
|
-
: error.
|
|
129
|
-
? createError("policy_violation", "Content policy violation", error)
|
|
130
|
-
: createError("unknown", error.message || "Generation failed", error);
|
|
132
|
+
: error.name === "ContentPolicyViolationError"
|
|
133
|
+
? createError("policy_violation", "Content policy violation", error)
|
|
134
|
+
: createError("unknown", error.message || "Generation failed", error);
|
|
131
135
|
|
|
132
136
|
setState({
|
|
133
137
|
isGenerating: false,
|
|
@@ -145,8 +149,8 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
145
149
|
generateFn,
|
|
146
150
|
saveFn,
|
|
147
151
|
checkCredits,
|
|
152
|
+
checkNetwork,
|
|
148
153
|
deductCredits,
|
|
149
|
-
timeout,
|
|
150
154
|
onSuccess,
|
|
151
155
|
onError,
|
|
152
156
|
onSaveComplete,
|