@umituz/react-native-ai-generation-content 1.68.0 → 1.69.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.68.0",
3
+ "version": "1.69.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",
@@ -54,12 +54,15 @@ export function useProcessingJobsPoller(
54
54
 
55
55
  pollJobRef.current = async (creation: Creation) => {
56
56
  if (!userId || !creation.requestId || !creation.model) return;
57
+
57
58
  if (pollingRef.current.has(creation.id)) return;
59
+ pollingRef.current.add(creation.id);
58
60
 
59
61
  const provider = providerRegistry.getActiveProvider();
60
- if (!provider || !provider.isInitialized()) return;
61
-
62
- pollingRef.current.add(creation.id);
62
+ if (!provider || !provider.isInitialized()) {
63
+ pollingRef.current.delete(creation.id);
64
+ return;
65
+ }
63
66
 
64
67
  try {
65
68
  if (typeof __DEV__ !== "undefined" && __DEV__) {
@@ -8,6 +8,7 @@ import { StepType } from "../../../../../domain/entities/flow-config.types";
8
8
  import type { StepDefinition } from "../../../../../domain/entities/flow-config.types";
9
9
  import type { WizardStepConfig } from "../../domain/entities/wizard-step.types";
10
10
  import type { WizardFeatureConfig, ScenarioBasedConfig } from "../../domain/entities/wizard-feature.types";
11
+ import { buildWizardConfigFromScenario } from "../../domain/entities/wizard-feature.types";
11
12
 
12
13
  /**
13
14
  * Convert wizard step config to flow step definition
@@ -104,7 +105,6 @@ export const quickBuildWizard = (
104
105
  featureId: string,
105
106
  scenarioConfig: ScenarioBasedConfig,
106
107
  ): StepDefinition[] => {
107
- const { buildWizardConfigFromScenario } = require("../../domain/entities/wizard-feature.types");
108
108
  const wizardConfig = buildWizardConfigFromScenario(featureId, scenarioConfig);
109
109
  return buildFlowStepsFromWizard(wizardConfig, {
110
110
  includePreview: true,
@@ -27,9 +27,12 @@ export function useGenerationPhase(options?: UseGenerationPhaseOptions): Generat
27
27
  const { queuedDuration = 5000 } = options ?? {};
28
28
 
29
29
  const [phase, setPhase] = useState<GenerationPhase>("queued");
30
- const startTimeRef = useRef(Date.now());
30
+ const startTimeRef = useRef<number>(Date.now());
31
31
 
32
32
  useEffect(() => {
33
+ startTimeRef.current = Date.now();
34
+ setPhase("queued");
35
+
33
36
  const interval = setInterval(() => {
34
37
  const elapsed = Date.now() - startTimeRef.current;
35
38
 
@@ -7,74 +7,34 @@ export class PromptHistoryRepository implements IPromptHistoryRepository {
7
7
  private readonly maxStorageSize = 100;
8
8
 
9
9
  save(prompt: GeneratedPrompt): Promise<AIPromptResult<void>> {
10
- try {
11
- this.storage.push(prompt);
12
- this.trimStorage();
13
- return Promise.resolve({ success: true, data: undefined });
14
- } catch {
15
- return Promise.resolve({
16
- success: false,
17
- error: 'STORAGE_ERROR',
18
- message: 'Failed to save prompt to history'
19
- });
20
- }
10
+ this.storage.push(prompt);
11
+ this.trimStorage();
12
+ return Promise.resolve({ success: true, data: undefined });
21
13
  }
22
14
 
23
15
  findRecent(limit: number = 50): Promise<AIPromptResult<GeneratedPrompt[]>> {
24
- try {
25
- const prompts = this.storage.slice(-limit);
26
- return Promise.resolve({ success: true, data: prompts });
27
- } catch {
28
- return Promise.resolve({
29
- success: false,
30
- error: 'STORAGE_ERROR',
31
- message: 'Failed to retrieve recent prompts'
32
- });
33
- }
16
+ const prompts = this.storage.slice(-limit);
17
+ return Promise.resolve({ success: true, data: prompts });
34
18
  }
35
19
 
36
20
  findByTemplateId(
37
21
  templateId: string,
38
22
  limit: number = 20
39
23
  ): Promise<AIPromptResult<GeneratedPrompt[]>> {
40
- try {
41
- const prompts = this.storage
42
- .filter(prompt => prompt.templateId === templateId)
43
- .slice(-limit);
44
- return Promise.resolve({ success: true, data: prompts });
45
- } catch {
46
- return Promise.resolve({
47
- success: false,
48
- error: 'STORAGE_ERROR',
49
- message: 'Failed to retrieve prompts by template ID'
50
- });
51
- }
24
+ const prompts = this.storage
25
+ .filter(prompt => prompt.templateId === templateId)
26
+ .slice(-limit);
27
+ return Promise.resolve({ success: true, data: prompts });
52
28
  }
53
29
 
54
30
  delete(id: string): Promise<AIPromptResult<void>> {
55
- try {
56
- this.storage = this.storage.filter(prompt => prompt.id !== id);
57
- return Promise.resolve({ success: true, data: undefined });
58
- } catch {
59
- return Promise.resolve({
60
- success: false,
61
- error: 'STORAGE_ERROR',
62
- message: 'Failed to delete prompt'
63
- });
64
- }
31
+ this.storage = this.storage.filter(prompt => prompt.id !== id);
32
+ return Promise.resolve({ success: true, data: undefined });
65
33
  }
66
34
 
67
35
  clear(): Promise<AIPromptResult<void>> {
68
- try {
69
- this.storage = [];
70
- return Promise.resolve({ success: true, data: undefined });
71
- } catch {
72
- return Promise.resolve({
73
- success: false,
74
- error: 'STORAGE_ERROR',
75
- message: 'Failed to clear prompt history'
76
- });
77
- }
36
+ this.storage = [];
37
+ return Promise.resolve({ success: true, data: undefined });
78
38
  }
79
39
 
80
40
  private trimStorage(): void {
@@ -56,5 +56,9 @@ export async function fetchWithTimeout<T>(
56
56
  return createErrorResponse(getErrorMessage(result.error));
57
57
  }
58
58
 
59
- return createSuccessResponse(result.data ?? null as T);
59
+ if (result.data === undefined) {
60
+ return createErrorResponse("No data received from server");
61
+ }
62
+
63
+ return createSuccessResponse(result.data);
60
64
  }
@@ -16,6 +16,11 @@ export function createTimeoutController(
16
16
  }
17
17
 
18
18
  const controller = new AbortController();
19
- setTimeout(() => controller.abort(), timeout);
19
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
20
+
21
+ controller.signal.addEventListener('abort', () => {
22
+ clearTimeout(timeoutId);
23
+ }, { once: true });
24
+
20
25
  return controller;
21
26
  }
@@ -4,8 +4,6 @@
4
4
 
5
5
  import { getErrorMessage } from "./error-extractors";
6
6
 
7
- declare const __DEV__: boolean;
8
-
9
7
  /**
10
8
  * Wraps an async function with error handling
11
9
  */
@@ -25,13 +25,13 @@ export async function retryWithBackoff<T>(
25
25
 
26
26
  let lastError: Error | undefined;
27
27
 
28
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
28
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
29
29
  try {
30
30
  return await operation();
31
31
  } catch (error) {
32
32
  lastError = error instanceof Error ? error : new Error(getErrorMessage(error));
33
33
 
34
- if (attempt === maxRetries || !shouldRetry(lastError)) {
34
+ if (!shouldRetry(lastError)) {
35
35
  throw lastError;
36
36
  }
37
37
 
@@ -40,5 +40,5 @@ export async function retryWithBackoff<T>(
40
40
  }
41
41
  }
42
42
 
43
- throw lastError!;
43
+ throw lastError ?? new Error("Operation failed after retries");
44
44
  }
@@ -11,6 +11,7 @@ export * from "./error-types";
11
11
  export * from "./message-extractor";
12
12
  export * from "./fal-error-checker";
13
13
  export * from "./classifier-helpers";
14
+ export * from "./result-polling";
14
15
  export * from "./validation.util";
15
16
  export * from "../../domains/background/infrastructure/utils/polling-interval.util";
16
17
  export * from "./progress-calculator.util";