@umituz/react-native-ai-fal-provider 2.3.1 → 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
|
@@ -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
|
-
*
|
|
13
|
+
* Normalize FAL queue status response from snake_case (SDK) to camelCase (internal)
|
|
12
14
|
*/
|
|
13
|
-
function
|
|
15
|
+
function normalizeFalQueueStatus(value: unknown): FalQueueStatus | null {
|
|
14
16
|
if (!value || typeof value !== "object") {
|
|
15
|
-
return
|
|
17
|
+
return null;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
const
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
59
|
+
const raw = await fal.queue.status(model, { requestId, logs: true });
|
|
49
60
|
|
|
50
|
-
|
|
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
|
|
10
|
-
IN_QUEUE: "IN_QUEUE"
|
|
11
|
-
IN_PROGRESS: "IN_PROGRESS"
|
|
12
|
-
COMPLETED: "COMPLETED"
|
|
13
|
-
FAILED: "FAILED"
|
|
14
|
-
} as const
|
|
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
|
|