@umituz/react-native-ai-generation-content 1.28.6 → 1.28.8
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.28.
|
|
3
|
+
"version": "1.28.8",
|
|
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",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { providerRegistry } from "./provider-registry.service";
|
|
8
|
-
import { cleanBase64, extractErrorMessage } from "../utils";
|
|
8
|
+
import { cleanBase64, extractErrorMessage, checkFalApiError } from "../utils";
|
|
9
9
|
import { extractVideoResult } from "../utils/url-extractor";
|
|
10
10
|
import { VIDEO_TIMEOUT_MS } from "../constants";
|
|
11
11
|
import type { VideoFeatureType, VideoFeatureInputData } from "../../domain/interfaces";
|
|
@@ -17,6 +17,21 @@ import type {
|
|
|
17
17
|
|
|
18
18
|
declare const __DEV__: boolean;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Calculate progress based on elapsed time
|
|
22
|
+
* Video generation typically takes 2-5 minutes
|
|
23
|
+
* Progress goes from 10% to 90% over the expected duration
|
|
24
|
+
*/
|
|
25
|
+
function calculateTimeBasedProgress(startTime: number, expectedDurationMs: number = 180000): number {
|
|
26
|
+
const elapsed = Date.now() - startTime;
|
|
27
|
+
const progressRange = 80; // Progress from 10% to 90%
|
|
28
|
+
const baseProgress = 10;
|
|
29
|
+
|
|
30
|
+
// Calculate progress based on elapsed time (capped at 90%)
|
|
31
|
+
const timeProgress = Math.min((elapsed / expectedDurationMs) * progressRange, progressRange);
|
|
32
|
+
return Math.round(baseProgress + timeProgress);
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
/**
|
|
21
36
|
* Execute any video feature using the active provider
|
|
22
37
|
* Uses subscribe for video features to handle long-running generation with progress updates
|
|
@@ -54,6 +69,9 @@ export async function executeVideoFeature(
|
|
|
54
69
|
|
|
55
70
|
const input = provider.buildVideoFeatureInput(featureType, inputData);
|
|
56
71
|
|
|
72
|
+
// Track start time for progress calculation
|
|
73
|
+
const startTime = Date.now();
|
|
74
|
+
|
|
57
75
|
const result = await provider.subscribe(model, input, {
|
|
58
76
|
timeoutMs: VIDEO_TIMEOUT_MS,
|
|
59
77
|
onQueueUpdate: (status) => {
|
|
@@ -61,9 +79,18 @@ export async function executeVideoFeature(
|
|
|
61
79
|
console.log(`[Video:${featureType}] Queue status:`, status.status);
|
|
62
80
|
}
|
|
63
81
|
onStatusChange?.(status.status);
|
|
82
|
+
|
|
83
|
+
// Calculate and report progress based on elapsed time
|
|
84
|
+
if (status.status === "IN_PROGRESS" && onProgress) {
|
|
85
|
+
const progress = calculateTimeBasedProgress(startTime);
|
|
86
|
+
onProgress(progress);
|
|
87
|
+
}
|
|
64
88
|
},
|
|
65
89
|
});
|
|
66
90
|
|
|
91
|
+
// Check for FAL API error in result (may return with COMPLETED status)
|
|
92
|
+
checkFalApiError(result);
|
|
93
|
+
|
|
67
94
|
const extractor = extractResult ?? extractVideoResult;
|
|
68
95
|
const videoUrl = extractor(result);
|
|
69
96
|
|
|
@@ -5,6 +5,48 @@
|
|
|
5
5
|
|
|
6
6
|
declare const __DEV__: boolean;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* FAL API error detail item
|
|
10
|
+
*/
|
|
11
|
+
interface FalErrorDetail {
|
|
12
|
+
readonly msg?: string;
|
|
13
|
+
readonly type?: string;
|
|
14
|
+
readonly loc?: string[];
|
|
15
|
+
readonly input?: string;
|
|
16
|
+
readonly url?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if result contains a FAL API error response
|
|
21
|
+
* FAL sometimes returns errors with COMPLETED status
|
|
22
|
+
*/
|
|
23
|
+
export function checkFalApiError(result: unknown): void {
|
|
24
|
+
if (!result || typeof result !== "object") return;
|
|
25
|
+
|
|
26
|
+
const resultObj = result as { detail?: FalErrorDetail[] };
|
|
27
|
+
|
|
28
|
+
// FAL API error format: {detail: [{msg, type, loc}]}
|
|
29
|
+
if (Array.isArray(resultObj.detail) && resultObj.detail.length > 0) {
|
|
30
|
+
const firstError = resultObj.detail[0];
|
|
31
|
+
const errorType = firstError?.type || "unknown";
|
|
32
|
+
const errorMsg = firstError?.msg || "Unknown API error";
|
|
33
|
+
|
|
34
|
+
if (__DEV__) {
|
|
35
|
+
console.error("[FalApiError] Detected error in result:", {
|
|
36
|
+
type: errorType,
|
|
37
|
+
message: errorMsg,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Throw specific error based on type
|
|
42
|
+
if (errorType === "content_policy_violation") {
|
|
43
|
+
throw new Error(`Content policy violation: ${errorMsg}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw new Error(errorMsg);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
8
50
|
/**
|
|
9
51
|
* Extract error message from FAL API and other error formats
|
|
10
52
|
* Supports: Error instances, FAL API errors, generic objects
|
|
@@ -25,10 +25,13 @@ export const AUTH_ERROR_PATTERNS = [
|
|
|
25
25
|
|
|
26
26
|
export const CONTENT_POLICY_PATTERNS = [
|
|
27
27
|
"content policy",
|
|
28
|
+
"content_policy_violation",
|
|
29
|
+
"policy violation",
|
|
28
30
|
"safety",
|
|
29
31
|
"moderation",
|
|
30
32
|
"inappropriate",
|
|
31
33
|
"blocked",
|
|
34
|
+
"flagged by a content checker",
|
|
32
35
|
] as const;
|
|
33
36
|
|
|
34
37
|
export const SERVER_ERROR_PATTERNS = [
|