@umituz/react-native-ai-generation-content 1.17.112 → 1.17.113
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/domains/creations/infrastructure/repositories/CreationsWriter.ts +18 -1
- package/src/domains/creations/presentation/components/CreationVideoPreview.tsx +1 -1
- package/src/features/text-to-video/infrastructure/services/text-to-video-executor.ts +34 -4
- package/src/features/text-to-video/presentation/hooks/useTextToVideoFeature.ts +69 -44
package/package.json
CHANGED
|
@@ -12,6 +12,11 @@ export class CreationsWriter {
|
|
|
12
12
|
constructor(private readonly pathResolver: FirestorePathResolver) { }
|
|
13
13
|
|
|
14
14
|
async create(userId: string, creation: Creation): Promise<void> {
|
|
15
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.log("[CreationsWriter] create() start", { userId, creationId: creation.id });
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
const docRef = this.pathResolver.getDocRef(userId, creation.id);
|
|
16
21
|
if (!docRef) throw new Error("Firestore not initialized");
|
|
17
22
|
|
|
@@ -27,7 +32,19 @@ export class CreationsWriter {
|
|
|
27
32
|
output: creation.output,
|
|
28
33
|
};
|
|
29
34
|
|
|
30
|
-
|
|
35
|
+
try {
|
|
36
|
+
await setDoc(docRef, data);
|
|
37
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.log("[CreationsWriter] create() success", { creationId: creation.id });
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.error("[CreationsWriter] create() error", error);
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
31
48
|
}
|
|
32
49
|
|
|
33
50
|
async update(
|
|
@@ -49,13 +49,26 @@ export async function executeTextToVideo(
|
|
|
49
49
|
request: TextToVideoRequest,
|
|
50
50
|
options: ExecuteTextToVideoOptions,
|
|
51
51
|
): Promise<TextToVideoResult> {
|
|
52
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.log("[TextToVideoExecutor] executeTextToVideo() called");
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
const provider = providerRegistry.getActiveProvider();
|
|
53
58
|
|
|
54
59
|
if (!provider) {
|
|
60
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
console.error("[TextToVideoExecutor] No AI provider configured");
|
|
63
|
+
}
|
|
55
64
|
return { success: false, error: "No AI provider configured" };
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
if (!provider.isInitialized()) {
|
|
68
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.error("[TextToVideoExecutor] AI provider not initialized");
|
|
71
|
+
}
|
|
59
72
|
return { success: false, error: "AI provider not initialized" };
|
|
60
73
|
}
|
|
61
74
|
|
|
@@ -65,27 +78,44 @@ export async function executeTextToVideo(
|
|
|
65
78
|
|
|
66
79
|
const { model, buildInput, extractResult, onProgress } = options;
|
|
67
80
|
|
|
68
|
-
if (__DEV__) {
|
|
81
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
69
82
|
// eslint-disable-next-line no-console
|
|
70
|
-
console.log(`[
|
|
83
|
+
console.log(`[TextToVideoExecutor] Provider: ${provider.providerId}, Model: ${model}`);
|
|
71
84
|
}
|
|
72
85
|
|
|
73
86
|
try {
|
|
74
87
|
onProgress?.(5);
|
|
88
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
89
|
+
// eslint-disable-next-line no-console
|
|
90
|
+
console.log("[TextToVideoExecutor] Starting provider.run()...");
|
|
91
|
+
}
|
|
75
92
|
|
|
76
93
|
const input = buildInput(request.prompt, request.options);
|
|
77
94
|
|
|
78
95
|
const result = await provider.run(model, input, {
|
|
79
96
|
onProgress: (progress) => {
|
|
97
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.log("[TextToVideoExecutor] Progress:", progress);
|
|
100
|
+
}
|
|
80
101
|
onProgress?.(progress);
|
|
81
102
|
},
|
|
82
103
|
});
|
|
83
104
|
|
|
105
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.log("[TextToVideoExecutor] provider.run() completed", result);
|
|
108
|
+
}
|
|
109
|
+
|
|
84
110
|
const extractor = extractResult || defaultExtractResult;
|
|
85
111
|
const extracted = extractor(result);
|
|
86
112
|
onProgress?.(100);
|
|
87
113
|
|
|
88
114
|
if (!extracted?.videoUrl) {
|
|
115
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
116
|
+
// eslint-disable-next-line no-console
|
|
117
|
+
console.error("[TextToVideoExecutor] No video URL in response");
|
|
118
|
+
}
|
|
89
119
|
return { success: false, error: "No video in response" };
|
|
90
120
|
}
|
|
91
121
|
|
|
@@ -96,9 +126,9 @@ export async function executeTextToVideo(
|
|
|
96
126
|
};
|
|
97
127
|
} catch (error) {
|
|
98
128
|
const message = error instanceof Error ? error.message : String(error);
|
|
99
|
-
if (__DEV__) {
|
|
129
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
100
130
|
// eslint-disable-next-line no-console
|
|
101
|
-
console.error("[
|
|
131
|
+
console.error("[TextToVideoExecutor] Error:", message);
|
|
102
132
|
}
|
|
103
133
|
return { success: false, error: message };
|
|
104
134
|
}
|
|
@@ -139,67 +139,92 @@ export function useTextToVideoFeature(
|
|
|
139
139
|
console.log("[TextToVideoFeature] Starting generation with prompt:", prompt, "creationId:", creationId);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
// Create "processing" creation at start
|
|
142
|
+
// Create "processing" creation at start (fire-and-forget to not block generation)
|
|
143
143
|
if (callbacks.onGenerationStart) {
|
|
144
|
-
|
|
144
|
+
callbacks.onGenerationStart({
|
|
145
145
|
creationId,
|
|
146
146
|
type: "text-to-video",
|
|
147
147
|
prompt,
|
|
148
148
|
metadata: options as Record<string, unknown> | undefined,
|
|
149
|
+
}).catch((err) => {
|
|
150
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
151
|
+
// eslint-disable-next-line no-console
|
|
152
|
+
console.warn("[TextToVideoFeature] onGenerationStart failed:", err);
|
|
153
|
+
}
|
|
149
154
|
});
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
buildInput,
|
|
157
|
-
extractResult,
|
|
158
|
-
onProgress: (progress) => {
|
|
159
|
-
setState((prev) => ({ ...prev, progress }));
|
|
160
|
-
callbacks.onProgress?.(progress);
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
if (result.success && result.videoUrl) {
|
|
166
|
-
setState((prev) => ({
|
|
167
|
-
...prev,
|
|
168
|
-
videoUrl: result.videoUrl ?? null,
|
|
169
|
-
thumbnailUrl: result.thumbnailUrl ?? null,
|
|
170
|
-
isProcessing: false,
|
|
171
|
-
progress: 100,
|
|
172
|
-
}));
|
|
157
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
158
|
+
// eslint-disable-next-line no-console
|
|
159
|
+
console.log("[TextToVideoFeature] Starting executeTextToVideo...");
|
|
160
|
+
}
|
|
173
161
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
162
|
+
try {
|
|
163
|
+
const result = await executeTextToVideo(
|
|
164
|
+
{ prompt, userId, options },
|
|
165
|
+
{
|
|
166
|
+
model: config.model,
|
|
167
|
+
buildInput,
|
|
168
|
+
extractResult,
|
|
169
|
+
onProgress: (progress) => {
|
|
170
|
+
setState((prev) => ({ ...prev, progress }));
|
|
171
|
+
callbacks.onProgress?.(progress);
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (result.success && result.videoUrl) {
|
|
177
|
+
setState((prev) => ({
|
|
178
|
+
...prev,
|
|
179
|
+
videoUrl: result.videoUrl ?? null,
|
|
180
|
+
thumbnailUrl: result.thumbnailUrl ?? null,
|
|
181
|
+
isProcessing: false,
|
|
182
|
+
progress: 100,
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
// Deduct credits after successful generation
|
|
186
|
+
if (callbacks.onCreditDeduct) {
|
|
187
|
+
await callbacks.onCreditDeduct(config.creditCost);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Update creation to completed after successful generation
|
|
191
|
+
if (callbacks.onCreationSave) {
|
|
192
|
+
await callbacks.onCreationSave({
|
|
193
|
+
creationId,
|
|
194
|
+
type: "text-to-video",
|
|
195
|
+
videoUrl: result.videoUrl,
|
|
196
|
+
thumbnailUrl: result.thumbnailUrl,
|
|
197
|
+
prompt,
|
|
198
|
+
metadata: options as Record<string, unknown> | undefined,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
callbacks.onGenerate?.(result);
|
|
203
|
+
} else {
|
|
204
|
+
const error = result.error || "Generation failed";
|
|
205
|
+
setState((prev) => ({
|
|
206
|
+
...prev,
|
|
207
|
+
isProcessing: false,
|
|
208
|
+
error,
|
|
209
|
+
}));
|
|
210
|
+
callbacks.onError?.(error);
|
|
177
211
|
}
|
|
178
212
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
thumbnailUrl: result.thumbnailUrl,
|
|
186
|
-
prompt,
|
|
187
|
-
metadata: options as Record<string, unknown> | undefined,
|
|
188
|
-
});
|
|
213
|
+
return result;
|
|
214
|
+
} catch (err) {
|
|
215
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
216
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
217
|
+
// eslint-disable-next-line no-console
|
|
218
|
+
console.error("[TextToVideoFeature] Generation error:", errorMessage);
|
|
189
219
|
}
|
|
190
|
-
|
|
191
|
-
callbacks.onGenerate?.(result);
|
|
192
|
-
} else {
|
|
193
|
-
const error = result.error || "Generation failed";
|
|
194
220
|
setState((prev) => ({
|
|
195
221
|
...prev,
|
|
196
222
|
isProcessing: false,
|
|
197
|
-
error,
|
|
223
|
+
error: errorMessage,
|
|
198
224
|
}));
|
|
199
|
-
callbacks.onError?.(
|
|
225
|
+
callbacks.onError?.(errorMessage);
|
|
226
|
+
return { success: false, error: errorMessage };
|
|
200
227
|
}
|
|
201
|
-
|
|
202
|
-
return result;
|
|
203
228
|
},
|
|
204
229
|
[userId, config.model, buildInput, extractResult, callbacks],
|
|
205
230
|
);
|