@umituz/react-native-ai-generation-content 1.17.105 → 1.17.106
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/domain/interfaces/ai-provider.interface.ts +9 -1
- package/src/features/text-to-image/presentation/hooks/useGeneration.ts +1 -1
- package/src/features/text-to-video/domain/types/callback.types.ts +10 -1
- package/src/features/text-to-video/domain/types/index.ts +1 -0
- package/src/features/text-to-video/infrastructure/services/text-to-video-executor.ts +6 -4
- package/src/features/text-to-video/presentation/hooks/useTextToVideoFeature.ts +17 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -50,6 +50,10 @@ export interface SubscribeOptions<T = unknown> {
|
|
|
50
50
|
onResult?: (result: T) => void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export interface RunOptions {
|
|
54
|
+
onProgress?: (progress: number) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
/**
|
|
54
58
|
* Feature types for image processing (output: image)
|
|
55
59
|
*/
|
|
@@ -116,7 +120,11 @@ export interface IAIProvider {
|
|
|
116
120
|
options?: SubscribeOptions<T>,
|
|
117
121
|
): Promise<T>;
|
|
118
122
|
|
|
119
|
-
run<T = unknown>(
|
|
123
|
+
run<T = unknown>(
|
|
124
|
+
model: string,
|
|
125
|
+
input: Record<string, unknown>,
|
|
126
|
+
options?: RunOptions,
|
|
127
|
+
): Promise<T>;
|
|
120
128
|
|
|
121
129
|
reset(): void;
|
|
122
130
|
|
|
@@ -119,7 +119,7 @@ export function useGeneration(options: UseGenerationOptions): UseGenerationRetur
|
|
|
119
119
|
const logResult = {
|
|
120
120
|
success: result.success,
|
|
121
121
|
imageCount: result.success ? result.imageUrls?.length : 0,
|
|
122
|
-
error:
|
|
122
|
+
error: result.success === false ? result.error : undefined,
|
|
123
123
|
};
|
|
124
124
|
// eslint-disable-next-line no-console
|
|
125
125
|
console.log("[TextToImage] Result:", JSON.stringify(logResult));
|
|
@@ -19,11 +19,20 @@ export interface ProjectData {
|
|
|
19
19
|
style: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export interface CreationData {
|
|
23
|
+
type: "text-to-video";
|
|
24
|
+
videoUrl: string;
|
|
25
|
+
thumbnailUrl?: string;
|
|
26
|
+
prompt: string;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export interface TextToVideoCallbacks {
|
|
23
31
|
onCreditCheck?: (cost: number) => Promise<boolean>;
|
|
32
|
+
onCreditDeduct?: (cost: number) => Promise<void>;
|
|
24
33
|
onAuthCheck?: () => boolean;
|
|
25
34
|
onModeration?: (prompt: string) => Promise<VideoModerationResult>;
|
|
26
|
-
|
|
35
|
+
onCreationSave?: (data: CreationData) => Promise<void>;
|
|
27
36
|
onGenerate?: (result: TextToVideoResult) => void;
|
|
28
37
|
onError?: (error: string) => void;
|
|
29
38
|
onProgress?: (progress: number) => void;
|
|
@@ -71,13 +71,15 @@ export async function executeTextToVideo(
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
|
-
onProgress?.(
|
|
74
|
+
onProgress?.(5);
|
|
75
75
|
|
|
76
76
|
const input = buildInput(request.prompt, request.options);
|
|
77
|
-
onProgress?.(20);
|
|
78
77
|
|
|
79
|
-
const result = await provider.run(model, input
|
|
80
|
-
|
|
78
|
+
const result = await provider.run(model, input, {
|
|
79
|
+
onProgress: (progress) => {
|
|
80
|
+
onProgress?.(progress);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
81
83
|
|
|
82
84
|
const extractor = extractResult || defaultExtractResult;
|
|
83
85
|
const extracted = extractor(result);
|
|
@@ -157,6 +157,23 @@ export function useTextToVideoFeature(
|
|
|
157
157
|
isProcessing: false,
|
|
158
158
|
progress: 100,
|
|
159
159
|
}));
|
|
160
|
+
|
|
161
|
+
// Deduct credits after successful generation
|
|
162
|
+
if (callbacks.onCreditDeduct) {
|
|
163
|
+
await callbacks.onCreditDeduct(config.creditCost);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Save creation after successful generation
|
|
167
|
+
if (callbacks.onCreationSave) {
|
|
168
|
+
await callbacks.onCreationSave({
|
|
169
|
+
type: "text-to-video",
|
|
170
|
+
videoUrl: result.videoUrl,
|
|
171
|
+
thumbnailUrl: result.thumbnailUrl,
|
|
172
|
+
prompt,
|
|
173
|
+
metadata: options as Record<string, unknown> | undefined,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
160
177
|
callbacks.onGenerate?.(result);
|
|
161
178
|
} else {
|
|
162
179
|
const error = result.error || "Generation failed";
|