@umituz/react-native-ai-generation-content 1.61.0 → 1.61.2
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.61.
|
|
3
|
+
"version": "1.61.2",
|
|
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",
|
|
@@ -4,25 +4,16 @@
|
|
|
4
4
|
* Output: image URL
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { cleanBase64, extractErrorMessage } from "../utils";
|
|
7
|
+
import { extractErrorMessage, validateProvider, prepareImageInputData } from "../utils";
|
|
9
8
|
import { extractImageResult } from "../utils/url-extractor";
|
|
10
9
|
import type { ImageResultExtractor } from "../utils/url-extractor";
|
|
11
|
-
import type { ImageFeatureType
|
|
10
|
+
import type { ImageFeatureType } from "../../domain/interfaces";
|
|
12
11
|
|
|
13
|
-
declare const __DEV__: boolean;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Execution options
|
|
17
|
-
*/
|
|
18
12
|
export interface ExecuteImageFeatureOptions {
|
|
19
13
|
extractResult?: ImageResultExtractor;
|
|
20
14
|
onProgress?: (progress: number) => void;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
/**
|
|
24
|
-
* Execution result
|
|
25
|
-
*/
|
|
26
17
|
export interface ImageFeatureResult {
|
|
27
18
|
success: boolean;
|
|
28
19
|
imageUrl?: string;
|
|
@@ -30,9 +21,6 @@ export interface ImageFeatureResult {
|
|
|
30
21
|
requestId?: string;
|
|
31
22
|
}
|
|
32
23
|
|
|
33
|
-
/**
|
|
34
|
-
* Request data for image features
|
|
35
|
-
*/
|
|
36
24
|
export interface ImageFeatureRequest {
|
|
37
25
|
imageBase64?: string;
|
|
38
26
|
targetImageBase64?: string;
|
|
@@ -48,41 +36,26 @@ export async function executeImageFeature(
|
|
|
48
36
|
request: ImageFeatureRequest,
|
|
49
37
|
options?: ExecuteImageFeatureOptions,
|
|
50
38
|
): Promise<ImageFeatureResult> {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return { success: false, error: "No AI provider configured" };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!provider.isInitialized()) {
|
|
58
|
-
return { success: false, error: "AI provider not initialized" };
|
|
39
|
+
const validation = validateProvider(`Image:${featureType}`);
|
|
40
|
+
if (!validation.success) {
|
|
41
|
+
return { success: false, error: validation.error };
|
|
59
42
|
}
|
|
60
43
|
|
|
44
|
+
const { provider } = validation;
|
|
61
45
|
const { extractResult, onProgress } = options ?? {};
|
|
62
|
-
|
|
63
46
|
const model = provider.getImageFeatureModel(featureType);
|
|
64
47
|
|
|
65
|
-
if (__DEV__) {
|
|
66
|
-
|
|
67
|
-
console.log(`[Image:${featureType}] Provider: ${provider.providerId}, Model: ${model}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
48
|
try {
|
|
71
|
-
const inputData
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
options: request.options,
|
|
78
|
-
};
|
|
79
|
-
|
|
49
|
+
const inputData = prepareImageInputData(
|
|
50
|
+
request.imageBase64 ?? "",
|
|
51
|
+
request.targetImageBase64,
|
|
52
|
+
request.prompt,
|
|
53
|
+
request.options,
|
|
54
|
+
);
|
|
80
55
|
const input = provider.buildImageFeatureInput(featureType, inputData);
|
|
81
56
|
const result = await provider.run(model, input);
|
|
82
57
|
|
|
83
|
-
const
|
|
84
|
-
const imageUrl = extractor(result);
|
|
85
|
-
|
|
58
|
+
const imageUrl = (extractResult ?? extractImageResult)(result);
|
|
86
59
|
onProgress?.(100);
|
|
87
60
|
|
|
88
61
|
if (!imageUrl) {
|
|
@@ -104,6 +77,5 @@ export async function executeImageFeature(
|
|
|
104
77
|
* Check if image features are supported
|
|
105
78
|
*/
|
|
106
79
|
export function hasImageFeatureSupport(): boolean {
|
|
107
|
-
|
|
108
|
-
return provider !== null && provider.isInitialized();
|
|
80
|
+
return validateProvider("ImageFeatureSupport").success;
|
|
109
81
|
}
|
|
@@ -4,137 +4,53 @@
|
|
|
4
4
|
* Output: video URL
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { cleanBase64, extractErrorMessage, checkFalApiError } from "../utils";
|
|
7
|
+
import { extractErrorMessage, checkFalApiError, validateProvider, prepareVideoInputData } from "../utils";
|
|
9
8
|
import { extractVideoResult } from "../utils/url-extractor";
|
|
10
9
|
import { VIDEO_TIMEOUT_MS } from "../constants";
|
|
11
|
-
import type { VideoFeatureType
|
|
12
|
-
import type {
|
|
13
|
-
ExecuteVideoFeatureOptions,
|
|
14
|
-
VideoFeatureResult,
|
|
15
|
-
VideoFeatureRequest,
|
|
16
|
-
} from "./video-feature-executor.types";
|
|
10
|
+
import type { VideoFeatureType } from "../../domain/interfaces";
|
|
11
|
+
import type { ExecuteVideoFeatureOptions, VideoFeatureResult, VideoFeatureRequest } from "./video-feature-executor.types";
|
|
17
12
|
|
|
18
13
|
declare const __DEV__: boolean;
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* Execute any video feature using the active provider
|
|
22
|
-
* Uses subscribe for video features to handle long-running generation with progress updates
|
|
23
17
|
*/
|
|
24
18
|
export async function executeVideoFeature(
|
|
25
19
|
featureType: VideoFeatureType,
|
|
26
20
|
request: VideoFeatureRequest,
|
|
27
21
|
options?: ExecuteVideoFeatureOptions,
|
|
28
22
|
): Promise<VideoFeatureResult> {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
hasTarget: !!request.targetImageBase64,
|
|
33
|
-
promptLength: request.prompt?.length ?? 0,
|
|
34
|
-
options: request.options,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const provider = providerRegistry.getActiveProvider();
|
|
39
|
-
|
|
40
|
-
if (!provider) {
|
|
41
|
-
if (__DEV__) {
|
|
42
|
-
console.log(`[VideoExecutor:${featureType}] ERROR: No provider`);
|
|
43
|
-
}
|
|
44
|
-
return { success: false, error: "No AI provider configured" };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!provider.isInitialized()) {
|
|
48
|
-
if (__DEV__) {
|
|
49
|
-
console.log(`[VideoExecutor:${featureType}] ERROR: Provider not initialized`);
|
|
50
|
-
}
|
|
51
|
-
return { success: false, error: "AI provider not initialized" };
|
|
23
|
+
const validation = validateProvider(`VideoExecutor:${featureType}`);
|
|
24
|
+
if (!validation.success) {
|
|
25
|
+
return { success: false, error: validation.error };
|
|
52
26
|
}
|
|
53
27
|
|
|
28
|
+
const { provider } = validation;
|
|
54
29
|
const { extractResult, onStatusChange } = options ?? {};
|
|
55
|
-
|
|
56
30
|
const model = provider.getVideoFeatureModel(featureType);
|
|
57
31
|
|
|
58
|
-
if (__DEV__) {
|
|
59
|
-
console.log(`[VideoExecutor:${featureType}] Provider: ${provider.providerId}, Model: ${model}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
32
|
try {
|
|
63
|
-
const inputData
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (__DEV__) {
|
|
71
|
-
console.log(`[VideoExecutor:${featureType}] InputData prepared`, {
|
|
72
|
-
sourceSize: inputData.sourceImageBase64 ? `${(inputData.sourceImageBase64.length / 1024).toFixed(1)}KB` : "N/A",
|
|
73
|
-
targetSize: inputData.targetImageBase64 ? `${(inputData.targetImageBase64.length / 1024).toFixed(1)}KB` : "N/A",
|
|
74
|
-
prompt: inputData.prompt?.substring(0, 50) + "...",
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
33
|
+
const inputData = prepareVideoInputData(
|
|
34
|
+
request.sourceImageBase64,
|
|
35
|
+
request.targetImageBase64,
|
|
36
|
+
request.prompt,
|
|
37
|
+
request.options,
|
|
38
|
+
);
|
|
78
39
|
const input = provider.buildVideoFeatureInput(featureType, inputData);
|
|
79
40
|
|
|
80
|
-
if (__DEV__) {
|
|
81
|
-
console.log(`[VideoExecutor:${featureType}] Built input for API`, {
|
|
82
|
-
inputKeys: Object.keys(input),
|
|
83
|
-
hasImageUrl: !!(input as Record<string, unknown>).image_url,
|
|
84
|
-
hasPrompt: !!(input as Record<string, unknown>).prompt,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let statusCount = 0;
|
|
89
41
|
const result = await provider.subscribe(model, input, {
|
|
90
42
|
timeoutMs: VIDEO_TIMEOUT_MS,
|
|
91
|
-
onQueueUpdate: (status) =>
|
|
92
|
-
statusCount++;
|
|
93
|
-
// Log every 10th status update to avoid spam
|
|
94
|
-
if (__DEV__ && statusCount % 10 === 1) {
|
|
95
|
-
console.log(`[VideoExecutor:${featureType}] Queue #${statusCount}:`, status.status);
|
|
96
|
-
}
|
|
97
|
-
onStatusChange?.(status.status);
|
|
98
|
-
},
|
|
43
|
+
onQueueUpdate: (status) => onStatusChange?.(status.status),
|
|
99
44
|
});
|
|
100
45
|
|
|
101
|
-
if (__DEV__) {
|
|
102
|
-
console.log(`[VideoExecutor:${featureType}] API Response received`, {
|
|
103
|
-
totalStatusUpdates: statusCount,
|
|
104
|
-
resultKeys: result ? Object.keys(result as object) : "null",
|
|
105
|
-
resultType: typeof result,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Check for FAL API error in result (may return with COMPLETED status)
|
|
110
46
|
checkFalApiError(result);
|
|
111
47
|
|
|
112
|
-
const
|
|
113
|
-
const videoUrl = extractor(result);
|
|
114
|
-
|
|
115
|
-
if (__DEV__) {
|
|
116
|
-
console.log(`[VideoExecutor:${featureType}] Extracted video URL`, {
|
|
117
|
-
hasVideoUrl: !!videoUrl,
|
|
118
|
-
urlPreview: videoUrl ? videoUrl.substring(0, 80) + "..." : "N/A",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
48
|
+
const videoUrl = (extractResult ?? extractVideoResult)(result);
|
|
121
49
|
|
|
122
50
|
if (!videoUrl) {
|
|
123
|
-
if (__DEV__) {
|
|
124
|
-
console.log(`[VideoExecutor:${featureType}] FAILED: No video URL`, {
|
|
125
|
-
result: JSON.stringify(result).substring(0, 500),
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
51
|
return { success: false, error: "No video in response" };
|
|
129
52
|
}
|
|
130
53
|
|
|
131
|
-
if (__DEV__) {
|
|
132
|
-
console.log(`[VideoExecutor:${featureType}] SUCCESS`, {
|
|
133
|
-
videoUrl: videoUrl.substring(0, 80) + "...",
|
|
134
|
-
requestId: (result as { requestId?: string })?.requestId,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
54
|
return {
|
|
139
55
|
success: true,
|
|
140
56
|
videoUrl,
|
|
@@ -142,12 +58,6 @@ export async function executeVideoFeature(
|
|
|
142
58
|
};
|
|
143
59
|
} catch (error) {
|
|
144
60
|
const message = extractErrorMessage(error, "Processing failed", `Video:${featureType}`);
|
|
145
|
-
if (__DEV__) {
|
|
146
|
-
console.log(`[VideoExecutor:${featureType}] EXCEPTION`, {
|
|
147
|
-
error: message,
|
|
148
|
-
originalError: error instanceof Error ? error.message : String(error),
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
61
|
return { success: false, error: message };
|
|
152
62
|
}
|
|
153
63
|
}
|
|
@@ -156,67 +66,38 @@ export async function executeVideoFeature(
|
|
|
156
66
|
* Check if video features are supported
|
|
157
67
|
*/
|
|
158
68
|
export function hasVideoFeatureSupport(): boolean {
|
|
159
|
-
const
|
|
160
|
-
return
|
|
69
|
+
const validation = validateProvider("VideoFeatureSupport");
|
|
70
|
+
return validation.success;
|
|
161
71
|
}
|
|
162
72
|
|
|
163
73
|
/**
|
|
164
74
|
* Submit a video feature to the queue for background processing
|
|
165
|
-
* Returns immediately with requestId and model for later status polling
|
|
166
75
|
*/
|
|
167
76
|
export async function submitVideoFeatureToQueue(
|
|
168
77
|
featureType: VideoFeatureType,
|
|
169
78
|
request: VideoFeatureRequest,
|
|
170
79
|
): Promise<{ success: boolean; requestId?: string; model?: string; error?: string }> {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
hasTarget: !!request.targetImageBase64,
|
|
175
|
-
promptLength: request.prompt?.length ?? 0,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const provider = providerRegistry.getActiveProvider();
|
|
180
|
-
|
|
181
|
-
if (!provider) {
|
|
182
|
-
return { success: false, error: "No AI provider configured" };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (!provider.isInitialized()) {
|
|
186
|
-
return { success: false, error: "AI provider not initialized" };
|
|
80
|
+
const validation = validateProvider(`VideoExecutor:${featureType}`);
|
|
81
|
+
if (!validation.success) {
|
|
82
|
+
return { success: false, error: validation.error };
|
|
187
83
|
}
|
|
188
84
|
|
|
85
|
+
const { provider } = validation;
|
|
189
86
|
const model = provider.getVideoFeatureModel(featureType);
|
|
190
87
|
|
|
191
88
|
try {
|
|
192
|
-
const inputData
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
89
|
+
const inputData = prepareVideoInputData(
|
|
90
|
+
request.sourceImageBase64,
|
|
91
|
+
request.targetImageBase64,
|
|
92
|
+
request.prompt,
|
|
93
|
+
request.options,
|
|
94
|
+
);
|
|
199
95
|
const input = provider.buildVideoFeatureInput(featureType, inputData);
|
|
200
|
-
|
|
201
96
|
const submission = await provider.submitJob(model, input);
|
|
202
97
|
|
|
203
|
-
|
|
204
|
-
console.log(`[VideoExecutor:${featureType}] QUEUE SUBMITTED`, {
|
|
205
|
-
requestId: submission.requestId,
|
|
206
|
-
model,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
success: true,
|
|
212
|
-
requestId: submission.requestId,
|
|
213
|
-
model,
|
|
214
|
-
};
|
|
98
|
+
return { success: true, requestId: submission.requestId, model };
|
|
215
99
|
} catch (error) {
|
|
216
100
|
const message = extractErrorMessage(error, "Queue submission failed", `Video:${featureType}`);
|
|
217
|
-
if (__DEV__) {
|
|
218
|
-
console.error(`[VideoExecutor:${featureType}] QUEUE EXCEPTION`, { error: message });
|
|
219
|
-
}
|
|
220
101
|
return { success: false, error: message };
|
|
221
102
|
}
|
|
222
103
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Validator Utility
|
|
3
|
+
* Validates provider state and prepares feature inputs
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { providerRegistry } from "../services/provider-registry.service";
|
|
7
|
+
import { cleanBase64 } from "./index";
|
|
8
|
+
import type { IAIProvider, VideoFeatureInputData, ImageFeatureInputData } from "../../domain/interfaces";
|
|
9
|
+
|
|
10
|
+
declare const __DEV__: boolean;
|
|
11
|
+
|
|
12
|
+
export type ProviderValidationResult =
|
|
13
|
+
| { success: true; provider: IAIProvider }
|
|
14
|
+
| { success: false; error: string };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Validate provider is available and initialized
|
|
18
|
+
*/
|
|
19
|
+
export function validateProvider(context: string): ProviderValidationResult {
|
|
20
|
+
const provider = providerRegistry.getActiveProvider();
|
|
21
|
+
|
|
22
|
+
if (!provider) {
|
|
23
|
+
if (__DEV__) {
|
|
24
|
+
console.log(`[${context}] ERROR: No provider`);
|
|
25
|
+
}
|
|
26
|
+
return { success: false, error: "No AI provider configured" };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!provider.isInitialized()) {
|
|
30
|
+
if (__DEV__) {
|
|
31
|
+
console.log(`[${context}] ERROR: Provider not initialized`);
|
|
32
|
+
}
|
|
33
|
+
return { success: false, error: "AI provider not initialized" };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { success: true, provider };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Prepare video feature input data
|
|
41
|
+
*/
|
|
42
|
+
export function prepareVideoInputData(
|
|
43
|
+
sourceImageBase64?: string,
|
|
44
|
+
targetImageBase64?: string,
|
|
45
|
+
prompt?: string,
|
|
46
|
+
options?: Record<string, unknown>,
|
|
47
|
+
): VideoFeatureInputData {
|
|
48
|
+
return {
|
|
49
|
+
sourceImageBase64: cleanBase64(sourceImageBase64),
|
|
50
|
+
targetImageBase64: cleanBase64(targetImageBase64),
|
|
51
|
+
prompt,
|
|
52
|
+
options,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Prepare image feature input data
|
|
58
|
+
*/
|
|
59
|
+
export function prepareImageInputData(
|
|
60
|
+
imageBase64: string,
|
|
61
|
+
targetImageBase64?: string,
|
|
62
|
+
prompt?: string,
|
|
63
|
+
options?: Record<string, unknown>,
|
|
64
|
+
): ImageFeatureInputData {
|
|
65
|
+
return {
|
|
66
|
+
imageBase64: cleanBase64(imageBase64) ?? "",
|
|
67
|
+
targetImageBase64: cleanBase64(targetImageBase64),
|
|
68
|
+
prompt,
|
|
69
|
+
options,
|
|
70
|
+
};
|
|
71
|
+
}
|