@umituz/react-native-ai-generation-content 1.10.4 → 1.11.1
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.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "Provider-agnostic AI generation orchestration for React Native",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@tanstack/react-query": ">=5.0.0",
|
|
34
34
|
"@umituz/react-native-animation": "latest",
|
|
35
35
|
"@umituz/react-native-design-system": "latest",
|
|
36
|
+
"@umituz/react-native-offline": "latest",
|
|
36
37
|
"expo-linear-gradient": ">=15.0.0",
|
|
37
38
|
"react": ">=18.0.0",
|
|
38
39
|
"react-native": ">=0.74.0"
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"@tanstack/react-query": "^5.0.0",
|
|
43
44
|
"@umituz/react-native-animation": "latest",
|
|
44
45
|
"@umituz/react-native-design-system": "latest",
|
|
46
|
+
"@umituz/react-native-offline": "latest",
|
|
45
47
|
"@types/react": "~19.1.10",
|
|
46
48
|
"@types/react-native": "^0.73.0",
|
|
47
49
|
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
@@ -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
|
}
|
|
@@ -25,7 +25,6 @@ export interface PhotoGenerationConfig<TInput, TResult, TSaveInput> {
|
|
|
25
25
|
save?: (result: TResult, input: TInput) => Promise<TSaveInput>;
|
|
26
26
|
checkCredits?: () => Promise<boolean>;
|
|
27
27
|
deductCredits?: () => Promise<void>;
|
|
28
|
-
timeout?: number;
|
|
29
28
|
onSuccess?: (result: TResult) => void;
|
|
30
29
|
onError?: (error: PhotoGenerationError) => void;
|
|
31
30
|
onSaveComplete?: (saveResult: TSaveInput) => void;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useState, useCallback, useRef } from "react";
|
|
7
|
+
import { useOfflineStore } from "@umituz/react-native-offline";
|
|
7
8
|
import type {
|
|
8
9
|
PhotoGenerationConfig,
|
|
9
10
|
PhotoGenerationState,
|
|
@@ -11,8 +12,6 @@ import type {
|
|
|
11
12
|
PhotoGenerationStatus,
|
|
12
13
|
} from "./photo-generation.types";
|
|
13
14
|
|
|
14
|
-
const DEFAULT_TIMEOUT = 60000;
|
|
15
|
-
|
|
16
15
|
export interface UsePhotoGenerationReturn<TResult> extends PhotoGenerationState<TResult> {
|
|
17
16
|
generate: <TInput>(input: TInput) => Promise<void>;
|
|
18
17
|
reset: () => void;
|
|
@@ -27,7 +26,6 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
27
26
|
save: saveFn,
|
|
28
27
|
checkCredits,
|
|
29
28
|
deductCredits,
|
|
30
|
-
timeout = DEFAULT_TIMEOUT,
|
|
31
29
|
onSuccess,
|
|
32
30
|
onError,
|
|
33
31
|
onSaveComplete,
|
|
@@ -42,6 +40,7 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
42
40
|
|
|
43
41
|
const [status, setStatus] = useState<PhotoGenerationStatus>("idle");
|
|
44
42
|
const isGeneratingRef = useRef(false);
|
|
43
|
+
const offlineStore = useOfflineStore();
|
|
45
44
|
|
|
46
45
|
const createError = useCallback(
|
|
47
46
|
(
|
|
@@ -68,6 +67,13 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
68
67
|
setStatus("validating");
|
|
69
68
|
|
|
70
69
|
try {
|
|
70
|
+
// Check network connectivity
|
|
71
|
+
const isOnline = offlineStore.getState().isOnline;
|
|
72
|
+
if (!isOnline) {
|
|
73
|
+
throw createError("network_error", "No internet connection");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Check credits
|
|
71
77
|
if (checkCredits) {
|
|
72
78
|
const hasCredits = await checkCredits();
|
|
73
79
|
if (!hasCredits) {
|
|
@@ -78,14 +84,12 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
78
84
|
setStatus("generating");
|
|
79
85
|
setState((prev) => ({ ...prev, progress: 20 }));
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const result = await Promise.race([generateFn(input), timeoutPromise]);
|
|
87
|
+
// Generate without timeout - let AI provider handle its own timeout
|
|
88
|
+
const result = await generateFn(input);
|
|
86
89
|
|
|
87
90
|
setState((prev) => ({ ...prev, progress: 60 }));
|
|
88
91
|
|
|
92
|
+
// Save result
|
|
89
93
|
if (saveFn) {
|
|
90
94
|
setStatus("saving");
|
|
91
95
|
try {
|
|
@@ -102,6 +106,7 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
102
106
|
|
|
103
107
|
setState((prev) => ({ ...prev, progress: 80 }));
|
|
104
108
|
|
|
109
|
+
// Deduct credits after successful generation
|
|
105
110
|
if (deductCredits) {
|
|
106
111
|
try {
|
|
107
112
|
await deductCredits();
|
|
@@ -123,11 +128,9 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
123
128
|
const generationError =
|
|
124
129
|
error.type
|
|
125
130
|
? error
|
|
126
|
-
: error.
|
|
127
|
-
? createError("
|
|
128
|
-
: error.
|
|
129
|
-
? createError("policy_violation", "Content policy violation", error)
|
|
130
|
-
: createError("unknown", error.message || "Generation failed", error);
|
|
131
|
+
: error.name === "ContentPolicyViolationError"
|
|
132
|
+
? createError("policy_violation", "Content policy violation", error)
|
|
133
|
+
: createError("unknown", error.message || "Generation failed", error);
|
|
131
134
|
|
|
132
135
|
setState({
|
|
133
136
|
isGenerating: false,
|
|
@@ -146,11 +149,11 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = any>(
|
|
|
146
149
|
saveFn,
|
|
147
150
|
checkCredits,
|
|
148
151
|
deductCredits,
|
|
149
|
-
timeout,
|
|
150
152
|
onSuccess,
|
|
151
153
|
onError,
|
|
152
154
|
onSaveComplete,
|
|
153
155
|
createError,
|
|
156
|
+
offlineStore,
|
|
154
157
|
],
|
|
155
158
|
);
|
|
156
159
|
|