@umituz/react-native-ai-generation-content 1.72.37 → 1.73.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.72.37",
3
+ "version": "1.73.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",
@@ -9,6 +9,7 @@ import type { StepType } from "../../../../../domain/entities/flow-config.types"
9
9
  import type { WizardFeatureConfig } from "../../domain/entities/wizard-feature.types";
10
10
  import type { WizardScenarioData } from "../hooks/useWizardGeneration";
11
11
  import type { AlertMessages } from "../../../../../presentation/hooks/generation/types";
12
+ import type { GenerationErrorInfo } from "./WizardFlow.types";
12
13
  import { validateScenario } from "../utilities/validateScenario";
13
14
  import { WizardFlowContent } from "./WizardFlowContent";
14
15
  import {
@@ -33,7 +34,7 @@ export interface GenericWizardFlowProps {
33
34
  proceedToGenerating: () => void,
34
35
  ) => void;
35
36
  readonly onGenerationComplete?: (result: unknown) => void;
36
- readonly onGenerationError?: (error: string) => void;
37
+ readonly onGenerationError?: (error: string, errorInfo?: GenerationErrorInfo) => void;
37
38
  readonly onCreditsExhausted?: () => void;
38
39
  readonly onBack?: () => void;
39
40
  readonly onTryAgain?: () => void;
@@ -4,6 +4,18 @@
4
4
 
5
5
  import type { AlertMessages } from "../../../../../presentation/hooks/generation/types";
6
6
 
7
+ /**
8
+ * Error information with refund eligibility
9
+ */
10
+ export interface GenerationErrorInfo {
11
+ /** Error message */
12
+ message: string;
13
+ /** Whether credits should be refunded for this error */
14
+ shouldRefund: boolean;
15
+ /** Human-readable error type for logging */
16
+ errorType?: string;
17
+ }
18
+
7
19
  export interface BaseWizardFlowProps {
8
20
  /** Model ID for generation */
9
21
  readonly model: string;
@@ -15,8 +27,8 @@ export interface BaseWizardFlowProps {
15
27
  readonly onNetworkError?: () => void;
16
28
  /** Called when generation completes */
17
29
  readonly onGenerationComplete?: () => void;
18
- /** Called on generation error */
19
- readonly onGenerationError?: (error: string) => void;
30
+ /** Called on generation error with refund eligibility info */
31
+ readonly onGenerationError?: (error: string, errorInfo?: GenerationErrorInfo) => void;
20
32
  /** Called when back is pressed on first step */
21
33
  readonly onBack: () => void;
22
34
  /** Translation function */
@@ -4,6 +4,8 @@ import { StepType, type StepDefinition } from "../../../../../domain/entities/fl
4
4
  import type { UploadedImage } from "../../../../../presentation/hooks/generation/useAIGenerateState";
5
5
  import type { Creation } from "../../../../creations/domain/entities/Creation";
6
6
  import { isCreation } from "./typeGuards";
7
+ import { classifyError } from "../../../../../infrastructure/utils/error-classification";
8
+ import type { GenerationErrorInfo } from "../components/WizardFlow.types";
7
9
 
8
10
  export interface UseWizardFlowHandlersProps {
9
11
  readonly currentStepIndex: number;
@@ -23,7 +25,7 @@ export interface UseWizardFlowHandlersProps {
23
25
  readonly setShowRatingPicker: (show: boolean) => void;
24
26
  readonly onGenerationStart?: (data: Record<string, unknown>, proceed: () => void) => void;
25
27
  readonly onGenerationComplete?: (result: unknown) => void;
26
- readonly onGenerationError?: (error: string) => void;
28
+ readonly onGenerationError?: (error: string, errorInfo?: GenerationErrorInfo) => void;
27
29
  readonly onBack?: () => void;
28
30
  }
29
31
 
@@ -66,8 +68,17 @@ export function useWizardFlowHandlers(props: UseWizardFlowHandlersProps) {
66
68
  (errorMessage: string) => {
67
69
  const safeErrorMessage = errorMessage?.trim() || "error.generation.unknown";
68
70
  const displayMessage = safeErrorMessage.startsWith("error.") ? t(safeErrorMessage) : safeErrorMessage;
71
+
72
+ // Classify error to determine refund eligibility
73
+ const errorClassification = classifyError(errorMessage);
74
+ const errorInfo: GenerationErrorInfo = {
75
+ message: safeErrorMessage,
76
+ shouldRefund: errorClassification.retryable ?? false,
77
+ errorType: errorClassification.type,
78
+ };
79
+
69
80
  alert.show(AlertType.ERROR, AlertMode.MODAL, t("common.error"), displayMessage);
70
- onGenerationError?.(safeErrorMessage);
81
+ onGenerationError?.(safeErrorMessage, errorInfo);
71
82
  onBack?.();
72
83
  },
73
84
  [alert, t, onGenerationError, onBack],
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { AlertMessages } from "../../../../presentation/hooks/generation/types";
6
+ import type { GenerationErrorInfo } from "../../../generation/wizard/presentation/components/WizardFlow.types";
6
7
 
7
8
  export interface TextToImageWizardFlowProps {
8
9
  readonly model: string;
@@ -14,7 +15,7 @@ export interface TextToImageWizardFlowProps {
14
15
  readonly onShowAuthModal: (callback: () => void) => void;
15
16
  readonly onShowPaywall: () => void;
16
17
  readonly onGenerationComplete?: () => void;
17
- readonly onGenerationError?: (error: string) => void;
18
+ readonly onGenerationError?: (error: string, errorInfo?: GenerationErrorInfo) => void;
18
19
  readonly onBack: () => void;
19
20
  readonly t: (key: string) => string;
20
21
  readonly alertMessages?: AlertMessages;
@@ -50,7 +50,8 @@ export function classifyError(error: unknown): AIErrorInfo {
50
50
  });
51
51
  }
52
52
 
53
- if (matchesPatterns(message, CONTENT_POLICY_PATTERNS)) {
53
+ // 422 = Content Policy Violation (Fal AI and other providers)
54
+ if (statusCode === 422 || matchesPatterns(message, CONTENT_POLICY_PATTERNS)) {
54
55
  return logClassification({
55
56
  type: AIErrorType.CONTENT_POLICY,
56
57
  messageKey: "error.contentPolicy",
@@ -34,6 +34,8 @@ export const CONTENT_POLICY_PATTERNS = [
34
34
  "content blocked",
35
35
  "blocked by",
36
36
  "flagged by a content checker",
37
+ " 422",
38
+ "422 ",
37
39
  ] as const;
38
40
 
39
41
  export const VALIDATION_ERROR_PATTERNS = [