@umituz/react-native-ai-fal-provider 2.0.8 → 2.0.10

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-fal-provider",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "FAL AI provider for React Native - implements IAIProvider interface for unified AI generation",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -36,6 +36,7 @@ export interface FalErrorMessages {
36
36
  timeout?: string;
37
37
  api_error?: string;
38
38
  validation?: string;
39
+ image_too_small?: string;
39
40
  content_policy?: string;
40
41
  rate_limit?: string;
41
42
  authentication?: string;
@@ -34,8 +34,6 @@ export interface ReplaceBackgroundOptions {
34
34
 
35
35
  export interface VideoFromImageOptions {
36
36
  readonly prompt?: string;
37
- /** @deprecated Use prompt instead */
38
- readonly motion_prompt?: string;
39
37
  /** Video duration in seconds (model-specific, e.g., 4, 8, 12 for Sora 2) */
40
38
  readonly duration?: number;
41
39
  /** Video resolution */
@@ -33,6 +33,9 @@ export {
33
33
  DEFAULT_TEXT_TO_VOICE_MODELS,
34
34
  DEFAULT_TEXT_TO_VIDEO_MODELS,
35
35
  DEFAULT_IMAGE_TO_VIDEO_MODELS,
36
+ DEFAULT_TEXT_TO_TEXT_MODELS,
37
+ DEFAULT_CREDIT_COSTS,
38
+ DEFAULT_MODEL_IDS,
36
39
  getAllDefaultModels,
37
40
  getDefaultModelsByType,
38
41
  getDefaultModel,
@@ -51,9 +54,24 @@ export type {
51
54
  RemoveObjectOptions,
52
55
  ReplaceBackgroundOptions,
53
56
  VideoFromImageOptions,
57
+ TextToVideoOptions,
54
58
  ModelType,
55
59
  ModelSelectionConfig,
56
60
  ModelSelectionState,
57
61
  ModelSelectionActions,
58
62
  UseModelsReturn,
63
+ ImageFeatureType,
64
+ VideoFeatureType,
65
+ AIProviderConfig,
66
+ AIJobStatusType,
67
+ AILogEntry,
68
+ JobSubmission,
69
+ JobStatus,
70
+ ProviderProgressInfo,
71
+ SubscribeOptions,
72
+ RunOptions,
73
+ ProviderCapabilities,
74
+ ImageFeatureInputData,
75
+ VideoFeatureInputData,
76
+ IAIProvider,
59
77
  } from "../domain/types";
@@ -55,7 +55,7 @@ export function buildImageFeatureInput(
55
55
  case "anime-selfie":
56
56
  return buildKontextStyleTransferInput(imageBase64, {
57
57
  prompt: prompt || (options?.prompt as string) || DEFAULT_ANIME_SELFIE_PROMPT,
58
- guidance_scale: (options?.guidance_scale as number) ?? 4.0,
58
+ guidance_scale: options?.guidance_scale as number | undefined,
59
59
  });
60
60
 
61
61
  default:
@@ -3,14 +3,14 @@
3
3
  * Core builder functions for FAL API
4
4
  */
5
5
 
6
+ import { formatImageDataUri } from "./image-helpers.util";
7
+
6
8
  export function buildSingleImageInput(
7
9
  base64: string,
8
10
  extraParams?: Record<string, unknown>,
9
11
  ): Record<string, unknown> {
10
12
  return {
11
- image_url: base64.startsWith("data:")
12
- ? base64
13
- : `data:image/jpeg;base64,${base64}`,
13
+ image_url: formatImageDataUri(base64),
14
14
  ...extraParams,
15
15
  };
16
16
  }
@@ -20,12 +20,9 @@ export function buildDualImageInput(
20
20
  targetBase64: string,
21
21
  extraParams?: Record<string, unknown>,
22
22
  ): Record<string, unknown> {
23
- const formatImage = (b64: string) =>
24
- b64.startsWith("data:") ? b64 : `data:image/jpeg;base64,${b64}`;
25
-
26
23
  return {
27
- image_url: formatImage(sourceBase64),
28
- second_image_url: formatImage(targetBase64),
24
+ image_url: formatImageDataUri(sourceBase64),
25
+ second_image_url: formatImageDataUri(targetBase64),
29
26
  ...extraParams,
30
27
  };
31
28
  }
@@ -12,14 +12,15 @@ import type {
12
12
  FaceSwapOptions,
13
13
  } from "../../domain/types";
14
14
  import { buildSingleImageInput } from "./base-builders.util";
15
+ import { formatImageDataUri } from "./image-helpers.util";
15
16
 
16
17
  export function buildUpscaleInput(
17
18
  base64: string,
18
19
  options?: UpscaleOptions,
19
20
  ): Record<string, unknown> {
20
21
  return buildSingleImageInput(base64, {
21
- scale: options?.scaleFactor || 2,
22
- face_enhance: options?.enhanceFaces || false,
22
+ scale: options?.scaleFactor ?? 2,
23
+ face_enhance: options?.enhanceFaces ?? false,
23
24
  });
24
25
  }
25
26
 
@@ -28,7 +29,7 @@ export function buildPhotoRestoreInput(
28
29
  options?: PhotoRestoreOptions,
29
30
  ): Record<string, unknown> {
30
31
  return buildSingleImageInput(base64, {
31
- face_enhance: options?.enhanceFaces || true,
32
+ face_enhance: options?.enhanceFaces ?? true,
32
33
  });
33
34
  }
34
35
 
@@ -37,12 +38,9 @@ export function buildFaceSwapInput(
37
38
  targetBase64: string,
38
39
  _options?: FaceSwapOptions,
39
40
  ): Record<string, unknown> {
40
- const formatImage = (b64: string) =>
41
- b64.startsWith("data:") ? b64 : `data:image/jpeg;base64,${b64}`;
42
-
43
41
  return {
44
- base_image_url: formatImage(sourceBase64),
45
- swap_image_url: formatImage(targetBase64),
42
+ base_image_url: formatImageDataUri(sourceBase64),
43
+ swap_image_url: formatImageDataUri(targetBase64),
46
44
  };
47
45
  }
48
46
 
@@ -40,18 +40,30 @@ export {
40
40
  extractBase64,
41
41
  getDataUriExtension,
42
42
  isImageDataUri,
43
+ } from "./image-helpers.util";
44
+
45
+ export {
43
46
  uploadToFalStorage,
44
47
  uploadMultipleToFalStorage,
45
- calculateTimeoutWithJitter,
46
- formatCreditCost,
48
+ } from "./fal-storage.util";
49
+
50
+ export {
47
51
  truncatePrompt,
48
52
  sanitizePrompt,
53
+ } from "./prompt-helpers.util";
54
+
55
+ export {
56
+ calculateTimeoutWithJitter,
57
+ debounce,
58
+ throttle,
59
+ } from "./timing-helpers.util";
60
+
61
+ export {
62
+ formatCreditCost,
49
63
  buildErrorMessage,
50
64
  isDefined,
51
65
  removeNullish,
52
- debounce,
53
- throttle,
54
- } from "./helpers.util";
66
+ } from "./general-helpers.util";
55
67
 
56
68
  export {
57
69
  createJobMetadata,
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import type { FalJobMetadata } from "../job-metadata";
7
+ import { updateJobMetadata } from "../job-metadata";
7
8
  import type { IJobStorage } from "./job-storage-interface";
8
9
 
9
10
  /**
@@ -61,13 +62,6 @@ export async function updateJobStatus(
61
62
  throw new Error(`Job not found: ${requestId}`);
62
63
  }
63
64
 
64
- const updated: FalJobMetadata = {
65
- ...metadata,
66
- status,
67
- updatedAt: new Date().toISOString(),
68
- ...(status === "COMPLETED" || status === "FAILED" ? { completedAt: new Date().toISOString() } : {}),
69
- ...(error ? { error } : {}),
70
- };
71
-
65
+ const updated = updateJobMetadata(metadata, status, error);
72
66
  await saveJobMetadata(storage, updated);
73
67
  }
@@ -9,6 +9,7 @@ import type {
9
9
  TextToVideoOptions,
10
10
  } from "../../domain/types";
11
11
  import { buildSingleImageInput } from "./base-builders.util";
12
+ import { formatImageDataUri } from "./image-helpers.util";
12
13
 
13
14
  export function buildImageToImageInput(
14
15
  base64: string,
@@ -27,12 +28,9 @@ export function buildVideoFromImageInput(
27
28
  base64: string,
28
29
  options?: VideoFromImageOptions,
29
30
  ): Record<string, unknown> {
30
- const formatImage = (b64: string) =>
31
- b64.startsWith("data:") ? b64 : `data:image/jpeg;base64,${b64}`;
32
-
33
31
  return {
34
- prompt: options?.prompt || options?.motion_prompt || "Generate natural motion video",
35
- image_url: formatImage(base64),
32
+ prompt: options?.prompt || "Generate natural motion video",
33
+ image_url: formatImageDataUri(base64),
36
34
  enable_safety_checker: false,
37
35
  ...(options?.duration && { duration: options.duration }),
38
36
  ...(options?.resolution && { resolution: options.resolution }),
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { useState, useCallback, useRef } from "react";
7
7
  import { falProvider } from "../../infrastructure/services/fal-provider";
8
- import { mapFalError, isFalErrorRetryable } from "../../infrastructure/utils/error-mapper";
8
+ import { mapFalError } from "../../infrastructure/utils/error-mapper";
9
9
  import type { FalJobInput, FalQueueStatus, FalLogEntry } from "../../domain/entities/fal.types";
10
10
  import type { FalErrorInfo } from "../../domain/entities/error.types";
11
11
 
@@ -38,7 +38,6 @@ export function useFalGeneration<T = unknown>(
38
38
 
39
39
  const lastRequestRef = useRef<{ endpoint: string; input: FalJobInput } | null>(null);
40
40
  const currentRequestIdRef = useRef<string | null>(null);
41
- const abortControllerRef = useRef<AbortController | null>(null);
42
41
 
43
42
  const generate = useCallback(
44
43
  async (modelEndpoint: string, input: FalJobInput): Promise<T | null> => {
@@ -49,9 +48,6 @@ export function useFalGeneration<T = unknown>(
49
48
  currentRequestIdRef.current = null;
50
49
  setIsCancelling(false);
51
50
 
52
- // Create abort controller for this request
53
- abortControllerRef.current = new AbortController();
54
-
55
51
  try {
56
52
  const result = await falProvider.subscribe<T>(modelEndpoint, input, {
57
53
  timeoutMs: options?.timeoutMs,
@@ -83,7 +79,6 @@ export function useFalGeneration<T = unknown>(
83
79
  } finally {
84
80
  setIsLoading(false);
85
81
  setIsCancelling(false);
86
- abortControllerRef.current = null;
87
82
  }
88
83
  },
89
84
  [options]
@@ -96,10 +91,9 @@ export function useFalGeneration<T = unknown>(
96
91
  }, [generate]);
97
92
 
98
93
  const cancel = useCallback(() => {
99
- if (abortControllerRef.current) {
94
+ if (falProvider.hasRunningRequest()) {
100
95
  setIsCancelling(true);
101
- abortControllerRef.current.abort();
102
- abortControllerRef.current = null;
96
+ falProvider.cancelCurrentRequest();
103
97
  if (typeof __DEV__ !== "undefined" && __DEV__) {
104
98
  console.log("[useFalGeneration] Request cancelled");
105
99
  }
@@ -111,6 +105,7 @@ export function useFalGeneration<T = unknown>(
111
105
  setData(null);
112
106
  setError(null);
113
107
  setIsLoading(false);
108
+ setIsCancelling(false);
114
109
  lastRequestRef.current = null;
115
110
  currentRequestIdRef.current = null;
116
111
  }, [cancel]);
@@ -119,7 +114,7 @@ export function useFalGeneration<T = unknown>(
119
114
  data,
120
115
  error,
121
116
  isLoading,
122
- isRetryable: error ? isFalErrorRetryable(error.originalError) : false,
117
+ isRetryable: error?.retryable ?? false,
123
118
  requestId: currentRequestIdRef.current,
124
119
  isCancelling,
125
120
  generate,
@@ -1,34 +0,0 @@
1
- /**
2
- * Helper Utilities - Re-exports
3
- * Backward compatibility barrel file
4
- */
5
-
6
- export {
7
- formatImageDataUri,
8
- extractBase64,
9
- getDataUriExtension,
10
- isImageDataUri,
11
- } from "./image-helpers.util";
12
-
13
- export {
14
- uploadToFalStorage,
15
- uploadMultipleToFalStorage,
16
- } from "./fal-storage.util";
17
-
18
- export {
19
- truncatePrompt,
20
- sanitizePrompt,
21
- } from "./prompt-helpers.util";
22
-
23
- export {
24
- calculateTimeoutWithJitter,
25
- debounce,
26
- throttle,
27
- } from "./timing-helpers.util";
28
-
29
- export {
30
- formatCreditCost,
31
- buildErrorMessage,
32
- isDefined,
33
- removeNullish,
34
- } from "./general-helpers.util";