@umituz/react-native-ai-generation-content 1.52.2 → 1.54.0

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.52.2",
3
+ "version": "1.54.0",
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",
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Video Generation Strategy
3
3
  * Handles video-specific generation logic (execution only)
4
+ * Uses clean prompts for Sora 2 - no complex identity preservation text
4
5
  */
5
6
 
6
7
  import {
7
8
  executeVideoFeature,
8
9
  submitVideoFeatureToQueue,
9
10
  } from "../../../../../infrastructure/services/video-feature-executor.service";
10
- import { buildUnifiedPrompt } from "./shared/unified-prompt-builder";
11
11
  import type { WizardScenarioData } from "../../presentation/hooks/useWizardGeneration";
12
12
  import type { WizardStrategy } from "./wizard-strategy.types";
13
13
  import { VIDEO_PROCESSING_PROMPTS } from "./wizard-strategy.constants";
@@ -36,12 +36,12 @@ export async function buildVideoInput(
36
36
  throw new Error(validation.errorKey ?? "error.generation.invalidInput");
37
37
  }
38
38
 
39
- let basePrompt = extractPrompt(wizardData, scenario.aiPrompt);
39
+ let finalPrompt = extractPrompt(wizardData, scenario.aiPrompt);
40
40
 
41
- if (!basePrompt) {
41
+ if (!finalPrompt) {
42
42
  const defaultPrompt = VIDEO_PROCESSING_PROMPTS[scenario.id];
43
43
  if (defaultPrompt) {
44
- basePrompt = defaultPrompt;
44
+ finalPrompt = defaultPrompt;
45
45
  } else {
46
46
  if (typeof __DEV__ !== "undefined" && __DEV__) {
47
47
  console.error("[VideoStrategy] No prompt found for scenario:", scenario.id);
@@ -51,17 +51,11 @@ export async function buildVideoInput(
51
51
  }
52
52
  }
53
53
 
54
- // Build unified prompt with face preservation
55
- const finalPrompt = buildUnifiedPrompt({
56
- basePrompt,
57
- photoCount: photos.length,
58
- interactionStyle: scenario.interactionStyle as string | undefined,
59
- });
60
-
54
+ // For video generation with Sora 2, use clean prompt directly
55
+ // No need for complex identity preservation text - Sora 2 handles this natively
61
56
  if (typeof __DEV__ !== "undefined" && __DEV__) {
62
- console.log("[VideoStrategy] Prompt built", {
63
- baseLength: basePrompt.length,
64
- finalLength: finalPrompt.length,
57
+ console.log("[VideoStrategy] Using clean prompt for Sora 2", {
58
+ promptLength: finalPrompt.length,
65
59
  photoCount: photos.length,
66
60
  });
67
61
  }
@@ -16,6 +16,42 @@ interface FalErrorDetail {
16
16
  readonly url?: string;
17
17
  }
18
18
 
19
+ /**
20
+ * Error types for user-friendly messages
21
+ */
22
+ export const GenerationErrorType = {
23
+ CONTENT_POLICY: "content_policy",
24
+ VALIDATION: "validation",
25
+ NETWORK: "network",
26
+ TIMEOUT: "timeout",
27
+ RATE_LIMIT: "rate_limit",
28
+ QUOTA_EXCEEDED: "quota_exceeded",
29
+ UNKNOWN: "unknown",
30
+ } as const;
31
+
32
+ export type GenerationErrorTypeValue = typeof GenerationErrorType[keyof typeof GenerationErrorType];
33
+
34
+ /**
35
+ * Structured generation error
36
+ */
37
+ export interface GenerationError extends Error {
38
+ readonly errorType: GenerationErrorTypeValue;
39
+ readonly translationKey: string;
40
+ }
41
+
42
+ /**
43
+ * Create a structured generation error
44
+ */
45
+ function createGenerationError(
46
+ type: GenerationErrorTypeValue,
47
+ message: string,
48
+ ): GenerationError {
49
+ const error = new Error(message) as GenerationError;
50
+ (error as { errorType: GenerationErrorTypeValue }).errorType = type;
51
+ (error as { translationKey: string }).translationKey = `error.generation.${type}`;
52
+ return error;
53
+ }
54
+
19
55
  /**
20
56
  * Check if result contains a FAL API error response
21
57
  * FAL sometimes returns errors with COMPLETED status
@@ -40,22 +76,74 @@ export function checkFalApiError(result: unknown): void {
40
76
 
41
77
  // Throw specific error based on type
42
78
  if (errorType === "content_policy_violation") {
43
- throw new Error(`Content policy violation: ${errorMsg}`);
79
+ throw createGenerationError(GenerationErrorType.CONTENT_POLICY, errorMsg);
80
+ }
81
+
82
+ if (errorType === "validation_error" || errorType.includes("validation")) {
83
+ throw createGenerationError(GenerationErrorType.VALIDATION, errorMsg);
44
84
  }
45
85
 
46
- throw new Error(errorMsg);
86
+ throw createGenerationError(GenerationErrorType.UNKNOWN, errorMsg);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Check if error is a GenerationError with translation key
92
+ */
93
+ export function isGenerationError(error: unknown): error is GenerationError {
94
+ return error instanceof Error && "errorType" in error && "translationKey" in error;
95
+ }
96
+
97
+ /**
98
+ * Get translation key from error (returns key if GenerationError, null otherwise)
99
+ */
100
+ export function getErrorTranslationKey(error: unknown): string | null {
101
+ if (isGenerationError(error)) {
102
+ return error.translationKey;
103
+ }
104
+
105
+ // Check for content policy in error message
106
+ const message = error instanceof Error ? error.message : String(error);
107
+ const lowerMessage = message.toLowerCase();
108
+
109
+ if (lowerMessage.includes("content_policy") || lowerMessage.includes("policy violation")) {
110
+ return `error.generation.${GenerationErrorType.CONTENT_POLICY}`;
111
+ }
112
+
113
+ if (lowerMessage.includes("rate limit") || lowerMessage.includes("429")) {
114
+ return `error.generation.${GenerationErrorType.RATE_LIMIT}`;
115
+ }
116
+
117
+ if (lowerMessage.includes("timeout") || lowerMessage.includes("timed out")) {
118
+ return `error.generation.${GenerationErrorType.TIMEOUT}`;
119
+ }
120
+
121
+ if (lowerMessage.includes("network") || lowerMessage.includes("connection")) {
122
+ return `error.generation.${GenerationErrorType.NETWORK}`;
47
123
  }
124
+
125
+ return null;
48
126
  }
49
127
 
50
128
  /**
51
129
  * Extract error message from FAL API and other error formats
52
130
  * Supports: Error instances, FAL API errors, generic objects
131
+ * Returns translation key if available, otherwise original message
53
132
  */
54
133
  export function extractErrorMessage(
55
134
  error: unknown,
56
135
  defaultMessage = "Processing failed",
57
136
  debugPrefix?: string,
58
137
  ): string {
138
+ // First check if this is a GenerationError with translation key
139
+ const translationKey = getErrorTranslationKey(error);
140
+ if (translationKey) {
141
+ if (__DEV__ && debugPrefix) {
142
+ console.error(`[${debugPrefix}] Error (translation key):`, translationKey);
143
+ }
144
+ return translationKey;
145
+ }
146
+
59
147
  let message = defaultMessage;
60
148
 
61
149
  if (error instanceof Error) {
@@ -65,6 +153,11 @@ export function extractErrorMessage(
65
153
 
66
154
  // FAL API error format: {detail: [{msg, type, loc}]}
67
155
  if (Array.isArray(errObj.detail) && errObj.detail[0]?.msg) {
156
+ const detailType = errObj.detail[0]?.type;
157
+ // Check for content policy in FAL API response
158
+ if (detailType === "content_policy_violation") {
159
+ return `error.generation.${GenerationErrorType.CONTENT_POLICY}`;
160
+ }
68
161
  message = String(errObj.detail[0].msg);
69
162
  } else if (errObj.detail) {
70
163
  message = JSON.stringify(errObj.detail);