@umituz/react-native-ai-generation-content 1.82.3 → 1.82.5

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.82.3",
3
+ "version": "1.82.5",
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",
@@ -39,7 +39,7 @@ function withAbortSignal<T>(
39
39
  signal?.addEventListener("abort", abortHandler, { once: true });
40
40
 
41
41
  // Handle timeout
42
- let timeoutId: NodeJS.Timeout | undefined;
42
+ let timeoutId: ReturnType<typeof setTimeout> | undefined;
43
43
  if (timeoutMs) {
44
44
  timeoutId = setTimeout(() => {
45
45
  reject(new Error(`Operation timeout after ${timeoutMs}ms`));
@@ -8,7 +8,7 @@
8
8
  import { useEffect, useRef, useMemo } from "react";
9
9
  import { providerRegistry } from "../../../../infrastructure/services/provider-registry.service";
10
10
  import { QUEUE_STATUS, CREATION_STATUS } from "../../../../domain/constants/queue-status.constants";
11
- import { DEFAULT_POLL_INTERVAL_MS } from "../../../../infrastructure/constants/polling.constants";
11
+ import { DEFAULT_POLL_INTERVAL_MS, DEFAULT_MAX_POLL_TIME_MS } from "../../../../infrastructure/constants/polling.constants";
12
12
  import {
13
13
  extractResultUrl,
14
14
  type GenerationResult,
@@ -76,6 +76,26 @@ export function useProcessingJobsPoller(
76
76
  if (pollingRef.current.has(creation.id)) return;
77
77
  pollingRef.current.add(creation.id);
78
78
 
79
+ // Stale detection: if creation is older than max poll time, mark as failed
80
+ const ageMs = Date.now() - creation.createdAt.getTime();
81
+ if (ageMs > DEFAULT_MAX_POLL_TIME_MS) {
82
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
83
+ console.log("[ProcessingJobsPoller] Stale job detected, marking as failed:", creation.id, { ageMs });
84
+ }
85
+ try {
86
+ await repository.update(userId, creation.id, {
87
+ status: CREATION_STATUS.FAILED,
88
+ metadata: { error: "Generation timed out" },
89
+ });
90
+ } catch (e) {
91
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
92
+ console.error("[ProcessingJobsPoller] Failed to mark stale job:", e);
93
+ }
94
+ }
95
+ pollingRef.current.delete(creation.id);
96
+ return;
97
+ }
98
+
79
99
  const provider = providerRegistry.getActiveProvider();
80
100
  if (!provider || !provider.isInitialized()) {
81
101
  pollingRef.current.delete(creation.id);
@@ -114,10 +134,15 @@ export function useProcessingJobsPoller(
114
134
  return;
115
135
  }
116
136
 
137
+ const output: Record<string, string | undefined> = {};
138
+ if (urls.imageUrl) output.imageUrl = urls.imageUrl;
139
+ if (urls.videoUrl) output.videoUrl = urls.videoUrl;
140
+ if (urls.thumbnailUrl) output.thumbnailUrl = urls.thumbnailUrl;
141
+
117
142
  await repository.update(userId, creation.id, {
118
143
  status: CREATION_STATUS.COMPLETED,
119
144
  uri,
120
- output: urls,
145
+ output,
121
146
  });
122
147
  } else if (status.status === QUEUE_STATUS.FAILED) {
123
148
  if (typeof __DEV__ !== "undefined" && __DEV__) console.log("[ProcessingJobsPoller] Failed:", creation.id);
@@ -22,4 +22,5 @@ export interface CompletedCreationData {
22
22
  readonly uri: string;
23
23
  readonly imageUrl?: string;
24
24
  readonly videoUrl?: string;
25
+ readonly thumbnailUrl?: string;
25
26
  }
@@ -17,9 +17,10 @@ export async function updateToCompleted(
17
17
  creationId: string,
18
18
  data: CompletedCreationData
19
19
  ): Promise<void> {
20
- const output: { imageUrl?: string; videoUrl?: string } = {};
20
+ const output: { imageUrl?: string; videoUrl?: string; thumbnailUrl?: string } = {};
21
21
  if (data.imageUrl) output.imageUrl = data.imageUrl;
22
22
  if (data.videoUrl) output.videoUrl = data.videoUrl;
23
+ if (data.thumbnailUrl) output.thumbnailUrl = data.thumbnailUrl;
23
24
 
24
25
  await repository.update(userId, creationId, {
25
26
  uri: data.uri,
@@ -3,6 +3,8 @@
3
3
  * Provider-agnostic utilities for extracting generation results
4
4
  */
5
5
 
6
+ import { extractThumbnailUrl } from "../../../../../infrastructure/utils/url-extractor/thumbnail-extractor";
7
+
6
8
  export interface GenerationErrorDetail {
7
9
  msg?: string;
8
10
  type?: string;
@@ -22,6 +24,7 @@ export interface GenerationResult {
22
24
  export interface GenerationUrls {
23
25
  imageUrl?: string;
24
26
  videoUrl?: string;
27
+ thumbnailUrl?: string;
25
28
  }
26
29
 
27
30
  /**
@@ -59,8 +62,10 @@ function checkForErrors(result: GenerationResult): void {
59
62
  export function extractResultUrl(result: GenerationResult): GenerationUrls {
60
63
  checkForErrors(result);
61
64
 
65
+ const thumbnailUrl = extractThumbnailUrl(result);
66
+
62
67
  if (result.video?.url && typeof result.video.url === "string") {
63
- return { videoUrl: result.video.url };
68
+ return { videoUrl: result.video.url, thumbnailUrl };
64
69
  }
65
70
 
66
71
  if (typeof result.output === "string" && result.output.length > 0 && result.output.startsWith("http")) {
@@ -51,7 +51,7 @@ export const usePhotoUploadState = ({
51
51
  }: UsePhotoUploadStateProps): UsePhotoUploadStateReturn => {
52
52
  const [image, setImage] = useState<UploadedImage | null>(initialImage || null);
53
53
  const { pickImage, isLoading } = useMedia();
54
- const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
54
+ const timeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
55
55
 
56
56
  // Use refs to avoid effect re-runs on callback changes
57
57
  const onErrorRef = useRef(onError);
@@ -81,6 +81,7 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
81
81
  uri,
82
82
  imageUrl: urls.imageUrl,
83
83
  videoUrl: urls.videoUrl,
84
+ thumbnailUrl: urls.thumbnailUrl,
84
85
  });
85
86
  if (typeof __DEV__ !== "undefined" && __DEV__) {
86
87
  console.log("[VideoQueue] ✅ Updated completion status in Firestore");
@@ -74,7 +74,7 @@ export function validateVideoUrl(input: unknown): ValidationResult {
74
74
  return urlResult;
75
75
  }
76
76
 
77
- const url = new URL(input);
77
+ const url = new URL(input) as URL & { pathname: string };
78
78
  const validExtensions = [".mp4", ".mov", ".webm", ".gif"];
79
79
  const hasValidExtension = validExtensions.some((ext) =>
80
80
  url.pathname.toLowerCase().endsWith(ext)
@@ -102,7 +102,7 @@ export function validateURL(input: unknown): ValidationResult {
102
102
  }
103
103
 
104
104
  try {
105
- const url = new URL(input);
105
+ const url = new URL(input) as URL & { protocol: string };
106
106
  if (!["http:", "https:"].includes(url.protocol)) {
107
107
  return { isValid: false, errors: ["Only HTTP and HTTPS protocols are allowed"] };
108
108
  }
@@ -25,10 +25,6 @@ export const useGenerationOrchestrator = <TInput, TResult>(
25
25
  ): UseGenerationOrchestratorReturn<TInput, TResult> => {
26
26
  const { userId, alertMessages, onSuccess, onError, moderation, lifecycle } = config;
27
27
 
28
- if (typeof __DEV__ !== "undefined" && __DEV__) {
29
- console.log("[Orchestrator] Hook initialized:", { userId });
30
- }
31
-
32
28
  const [state, setState] = useState<GenerationState<TResult>>(INITIAL_STATE);
33
29
  const isGeneratingRef = useRef(false);
34
30
  const isMountedRef = useRef(true);