@umituz/react-native-ai-generation-content 1.20.24 → 1.20.26
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 +1 -1
- package/src/index.ts +1 -1
- package/src/presentation/components/index.ts +2 -0
- package/src/presentation/hooks/generation/index.ts +1 -0
- package/src/presentation/hooks/generation/useAIFeatureGeneration.ts +162 -0
- package/src/presentation/screens/ai-feature/registry.ts +16 -0
- package/src/presentation/screens/ai-feature/types.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-generation-content",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.26",
|
|
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",
|
package/src/index.ts
CHANGED
|
@@ -70,7 +70,7 @@ export {
|
|
|
70
70
|
useGeneration, usePendingJobs, useBackgroundGeneration,
|
|
71
71
|
useGenerationFlow, useAIFeatureCallbacks,
|
|
72
72
|
useAIGenerateState, AIGenerateStep,
|
|
73
|
-
useGenerationOrchestrator, useImageGeneration, useVideoGeneration,
|
|
73
|
+
useGenerationOrchestrator, useImageGeneration, useVideoGeneration, useAIFeatureGeneration,
|
|
74
74
|
createGenerationError, getAlertMessage, parseError,
|
|
75
75
|
} from "./presentation/hooks";
|
|
76
76
|
|
|
@@ -9,7 +9,9 @@ export * from "./StylePresetsGrid";
|
|
|
9
9
|
export * from "./AIGenerationForm";
|
|
10
10
|
export * from "./AIGenerationForm.types";
|
|
11
11
|
export * from "./AIGenerationConfig";
|
|
12
|
+
|
|
12
13
|
export * from "./flows/AIGenerateWizardFlow";
|
|
14
|
+
export * from "./flows/AIGenerateWizardFlow.types";
|
|
13
15
|
|
|
14
16
|
export type { GenerationProgressContentProps } from "./GenerationProgressContent";
|
|
15
17
|
export type { GenerationProgressBarProps } from "./GenerationProgressBar";
|
|
@@ -9,6 +9,7 @@ export { useGenerationOrchestrator } from "./orchestrator";
|
|
|
9
9
|
// Generic feature hooks
|
|
10
10
|
export { useImageGeneration } from "./useImageGeneration";
|
|
11
11
|
export { useVideoGeneration } from "./useVideoGeneration";
|
|
12
|
+
export { useAIFeatureGeneration } from "./useAIFeatureGeneration";
|
|
12
13
|
|
|
13
14
|
// Types
|
|
14
15
|
export type {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { useImageGeneration } from "./useImageGeneration";
|
|
4
|
+
import { useVideoGeneration } from "./useVideoGeneration";
|
|
5
|
+
import { executeImageToVideo } from "../../../features/image-to-video";
|
|
6
|
+
import { executeTextToVideo } from "../../../features/text-to-video";
|
|
7
|
+
import { useGenerationOrchestrator } from "./orchestrator";
|
|
8
|
+
import { prepareImage } from "../../../infrastructure/utils";
|
|
9
|
+
import type { AIFeatureId } from "../../screens/ai-feature/types";
|
|
10
|
+
import type { ImageFeatureType, VideoFeatureType } from "../../../domain/interfaces";
|
|
11
|
+
|
|
12
|
+
interface FeatureGenerationConfig {
|
|
13
|
+
featureType: AIFeatureId;
|
|
14
|
+
userId?: string;
|
|
15
|
+
alertMessages: any;
|
|
16
|
+
onSuccess?: (result: any) => void;
|
|
17
|
+
onError?: (error: any) => void;
|
|
18
|
+
creditCost?: number;
|
|
19
|
+
onCreditsExhausted?: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useAIFeatureGeneration({
|
|
23
|
+
featureType,
|
|
24
|
+
userId,
|
|
25
|
+
alertMessages,
|
|
26
|
+
onSuccess,
|
|
27
|
+
onError,
|
|
28
|
+
creditCost = 1,
|
|
29
|
+
onCreditsExhausted,
|
|
30
|
+
}: FeatureGenerationConfig) {
|
|
31
|
+
|
|
32
|
+
// Hook for standard image features
|
|
33
|
+
const { generate: generateImage } = useImageGeneration({
|
|
34
|
+
featureType: featureType as ImageFeatureType,
|
|
35
|
+
userId,
|
|
36
|
+
processResult: (imageUrl) => imageUrl,
|
|
37
|
+
alertMessages,
|
|
38
|
+
onSuccess,
|
|
39
|
+
onError,
|
|
40
|
+
creditCost,
|
|
41
|
+
onCreditsExhausted,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Hook for standard video features (ai-hug, ai-kiss)
|
|
45
|
+
const { generate: generateVideo } = useVideoGeneration({
|
|
46
|
+
featureType: featureType as VideoFeatureType,
|
|
47
|
+
userId,
|
|
48
|
+
processResult: (videoUrl) => videoUrl,
|
|
49
|
+
alertMessages,
|
|
50
|
+
onSuccess,
|
|
51
|
+
onError,
|
|
52
|
+
creditCost,
|
|
53
|
+
onCreditsExhausted,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Orchestrator for Image-to-Video
|
|
57
|
+
const { generate: generateImageToVideo } = useGenerationOrchestrator(
|
|
58
|
+
{
|
|
59
|
+
execute: async (input: { imageUri: string; prompt: string; duration: number }, onProgress) => {
|
|
60
|
+
const result = await executeImageToVideo(
|
|
61
|
+
{
|
|
62
|
+
imageUri: input.imageUri, // Pass URI directly
|
|
63
|
+
imageBase64: await prepareImage(input.imageUri),
|
|
64
|
+
motionPrompt: input.prompt,
|
|
65
|
+
options: { duration: input.duration },
|
|
66
|
+
userId: userId || "anonymous",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
model: "kling-video", // Default or hardcoded for now, ideal to get from config
|
|
70
|
+
buildInput: (image, prompt, opts) => ({
|
|
71
|
+
image,
|
|
72
|
+
prompt,
|
|
73
|
+
...opts
|
|
74
|
+
}),
|
|
75
|
+
onProgress,
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
if (!result.success || !result.videoUrl) throw new Error(result.error || "Generation failed");
|
|
79
|
+
return result.videoUrl;
|
|
80
|
+
},
|
|
81
|
+
getCreditCost: () => creditCost,
|
|
82
|
+
},
|
|
83
|
+
{ userId, alertMessages, onSuccess, onError, onCreditsExhausted }
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Orchestrator for Text-to-Video
|
|
87
|
+
const { generate: generateTextToVideo } = useGenerationOrchestrator(
|
|
88
|
+
{
|
|
89
|
+
execute: async (input: { prompt: string; duration: number }, onProgress) => {
|
|
90
|
+
const result = await executeTextToVideo(
|
|
91
|
+
{
|
|
92
|
+
prompt: input.prompt,
|
|
93
|
+
options: { duration: input.duration },
|
|
94
|
+
userId: userId || "anonymous",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
model: "kling-video", // Default
|
|
98
|
+
buildInput: (prompt, opts) => ({ prompt, ...opts }),
|
|
99
|
+
onProgress,
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
if (!result.success || !result.videoUrl) throw new Error(result.error || "Generation failed");
|
|
103
|
+
return result.videoUrl;
|
|
104
|
+
},
|
|
105
|
+
getCreditCost: () => creditCost,
|
|
106
|
+
},
|
|
107
|
+
{ userId, alertMessages, onSuccess, onError, onCreditsExhausted }
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const generate = useCallback(async (data: {
|
|
111
|
+
prompt: string;
|
|
112
|
+
style: string;
|
|
113
|
+
duration: number;
|
|
114
|
+
images: { uri: string }[];
|
|
115
|
+
}) => {
|
|
116
|
+
switch (featureType) {
|
|
117
|
+
case "image-to-video":
|
|
118
|
+
if (!data.images[0]?.uri) throw new Error("Image required for image-to-video");
|
|
119
|
+
return await generateImageToVideo({
|
|
120
|
+
imageUri: data.images[0].uri,
|
|
121
|
+
prompt: data.prompt,
|
|
122
|
+
duration: data.duration
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
case "text-to-video":
|
|
126
|
+
return await generateTextToVideo({
|
|
127
|
+
prompt: data.prompt,
|
|
128
|
+
duration: data.duration
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
case "ai-hug":
|
|
132
|
+
case "ai-kiss":
|
|
133
|
+
if (data.images.length < 2) throw new Error("Two images required");
|
|
134
|
+
return await generateVideo({
|
|
135
|
+
sourceImageBase64: await prepareImage(data.images[0].uri),
|
|
136
|
+
targetImageBase64: await prepareImage(data.images[1].uri),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
default:
|
|
140
|
+
// Default to Image Generation
|
|
141
|
+
if (data.images.length > 0) {
|
|
142
|
+
// Single or dual image
|
|
143
|
+
if (data.images.length === 2 && (featureType === "face-swap")) {
|
|
144
|
+
return await generateImage({
|
|
145
|
+
sourceImageBase64: await prepareImage(data.images[0].uri),
|
|
146
|
+
targetImageBase64: await prepareImage(data.images[1].uri),
|
|
147
|
+
options: { style: data.style }
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Single image features
|
|
151
|
+
return await generateImage({
|
|
152
|
+
imageBase64: await prepareImage(data.images[0].uri),
|
|
153
|
+
prompt: data.prompt,
|
|
154
|
+
options: { style: data.style }
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
throw new Error(`Unsupported feature or missing input: ${featureType}`);
|
|
158
|
+
}
|
|
159
|
+
}, [featureType, generateImage, generateVideo, generateImageToVideo, generateTextToVideo]);
|
|
160
|
+
|
|
161
|
+
return { generate };
|
|
162
|
+
}
|
|
@@ -104,6 +104,22 @@ export const AI_FEATURE_CONFIGS: Record<AIFeatureId, AIFeatureConfig> = {
|
|
|
104
104
|
creditType: "image",
|
|
105
105
|
translationPrefix: "ai-kiss",
|
|
106
106
|
},
|
|
107
|
+
|
|
108
|
+
// Generic Video Features
|
|
109
|
+
"image-to-video": {
|
|
110
|
+
id: "image-to-video",
|
|
111
|
+
mode: "single-with-prompt",
|
|
112
|
+
outputType: "video",
|
|
113
|
+
creditType: "video",
|
|
114
|
+
translationPrefix: "image-to-video",
|
|
115
|
+
},
|
|
116
|
+
"text-to-video": {
|
|
117
|
+
id: "text-to-video",
|
|
118
|
+
mode: "text-input",
|
|
119
|
+
outputType: "video",
|
|
120
|
+
creditType: "video",
|
|
121
|
+
translationPrefix: "text-to-video",
|
|
122
|
+
},
|
|
107
123
|
};
|
|
108
124
|
|
|
109
125
|
/**
|