@umituz/react-native-ai-fal-provider 2.3.0 → 2.3.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-fal-provider",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
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",
@@ -78,13 +78,11 @@ export class FalProvider implements IAIProvider {
78
78
 
79
79
  async getJobStatus(model: string, requestId: string): Promise<JobStatus> {
80
80
  this.validateInit();
81
- validateInput(model, {});
82
81
  return queueOps.getJobStatus(model, requestId);
83
82
  }
84
83
 
85
84
  async getJobResult<T = unknown>(model: string, requestId: string): Promise<T> {
86
85
  this.validateInit();
87
- validateInput(model, {});
88
86
  return queueOps.getJobResult<T>(model, requestId);
89
87
  }
90
88
 
@@ -5,30 +5,41 @@
5
5
  import { fal } from "@fal-ai/client";
6
6
  import type { JobSubmission, JobStatus } from "../../domain/types";
7
7
  import type { FalQueueStatus } from "../../domain/entities/fal.types";
8
- import { mapFalStatusToJobStatus } from "./fal-status-mapper";
8
+ import { mapFalStatusToJobStatus, FAL_QUEUE_STATUSES } from "./fal-status-mapper";
9
+
10
+ const VALID_STATUSES = Object.values(FAL_QUEUE_STATUSES) as string[];
9
11
 
10
12
  /**
11
- * Validate and cast FAL queue status response
13
+ * Normalize FAL queue status response from snake_case (SDK) to camelCase (internal)
12
14
  */
13
- function isValidFalQueueStatus(value: unknown): value is FalQueueStatus {
15
+ function normalizeFalQueueStatus(value: unknown): FalQueueStatus | null {
14
16
  if (!value || typeof value !== "object") {
15
- return false;
17
+ return null;
16
18
  }
17
19
 
18
- const status = value as Partial<FalQueueStatus>;
19
- const validStatuses = ["IN_QUEUE", "IN_PROGRESS", "COMPLETED", "FAILED"];
20
+ const raw = value as Record<string, unknown>;
21
+
22
+ if (typeof raw.status !== "string" || !VALID_STATUSES.includes(raw.status)) {
23
+ return null;
24
+ }
20
25
 
21
- return (
22
- typeof status.status === "string" &&
23
- validStatuses.includes(status.status) &&
24
- typeof status.requestId === "string"
25
- );
26
+ // FAL SDK returns snake_case (request_id, queue_position)
27
+ const requestId = (raw.request_id ?? raw.requestId) as string | undefined;
28
+ if (typeof requestId !== "string") {
29
+ return null;
30
+ }
31
+
32
+ return {
33
+ status: raw.status as FalQueueStatus["status"],
34
+ requestId,
35
+ queuePosition: (raw.queue_position ?? raw.queuePosition) as number | undefined,
36
+ logs: Array.isArray(raw.logs) ? raw.logs : undefined,
37
+ };
26
38
  }
27
39
 
28
40
  export async function submitJob(model: string, input: Record<string, unknown>): Promise<JobSubmission> {
29
41
  const result = await fal.queue.submit(model, { input });
30
42
 
31
- // Validate required fields from FAL API response
32
43
  if (!result?.request_id) {
33
44
  throw new Error(`FAL API response missing request_id for model ${model}`);
34
45
  }
@@ -45,9 +56,10 @@ export async function submitJob(model: string, input: Record<string, unknown>):
45
56
  }
46
57
 
47
58
  export async function getJobStatus(model: string, requestId: string): Promise<JobStatus> {
48
- const status = await fal.queue.status(model, { requestId, logs: true });
59
+ const raw = await fal.queue.status(model, { requestId, logs: true });
49
60
 
50
- if (!isValidFalQueueStatus(status)) {
61
+ const status = normalizeFalQueueStatus(raw);
62
+ if (!status) {
51
63
  throw new Error(
52
64
  `Invalid FAL queue status response for model ${model}, requestId ${requestId}`
53
65
  );
@@ -65,7 +77,6 @@ export async function getJobResult<T = unknown>(model: string, requestId: string
65
77
  );
66
78
  }
67
79
 
68
- // Type guard: ensure result.data exists before casting
69
80
  if (!('data' in result)) {
70
81
  throw new Error(
71
82
  `Invalid FAL queue result for model ${model}, requestId ${requestId}: Missing 'data' property`
@@ -6,12 +6,16 @@
6
6
  import type { JobStatus, AIJobStatusType } from "../../domain/types";
7
7
  import type { FalQueueStatus, FalLogEntry } from "../../domain/entities/fal.types";
8
8
 
9
- const STATUS_MAP = {
10
- IN_QUEUE: "IN_QUEUE" as const,
11
- IN_PROGRESS: "IN_PROGRESS" as const,
12
- COMPLETED: "COMPLETED" as const,
13
- FAILED: "FAILED" as const,
14
- } as const satisfies Record<string, AIJobStatusType>;
9
+ export const FAL_QUEUE_STATUSES = {
10
+ IN_QUEUE: "IN_QUEUE",
11
+ IN_PROGRESS: "IN_PROGRESS",
12
+ COMPLETED: "COMPLETED",
13
+ FAILED: "FAILED",
14
+ } as const;
15
+
16
+ export type FalQueueStatusKey = keyof typeof FAL_QUEUE_STATUSES;
17
+
18
+ const STATUS_MAP = FAL_QUEUE_STATUSES satisfies Record<string, AIJobStatusType>;
15
19
 
16
20
  const DEFAULT_STATUS: AIJobStatusType = "IN_PROGRESS";
17
21