@umituz/react-native-ai-generation-content 1.17.204 → 1.17.205

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.17.204",
3
+ "version": "1.17.205",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -12,3 +12,5 @@ export type {
12
12
  NanoBananaOutputFormat,
13
13
  } from "./domain/types";
14
14
  export { COUPLE_FUTURE_DEFAULTS } from "./domain/types";
15
+ export { useCoupleFutureGeneration } from "./presentation/hooks/useCoupleFutureGeneration";
16
+ export type { UseCoupleFutureGenerationConfig } from "./presentation/hooks/useCoupleFutureGeneration";
@@ -0,0 +1,76 @@
1
+ import { useCallback } from "react";
2
+ import { usePhotoGeneration } from "../../../presentation/hooks/usePhotoGeneration";
3
+ import { executeCoupleFuture } from "../../infrastructure/executor";
4
+ import type { CoupleFutureInput } from "../../domain/types";
5
+ import type { PhotoGenerationConfig, PhotoGenerationError } from "../../../presentation/hooks/photo-generation.types";
6
+ import { createCreationsRepository } from "../../../domains/creations/infrastructure/adapters";
7
+
8
+ export interface UseCoupleFutureGenerationConfig<TInput extends CoupleFutureInput, TResult> {
9
+ userId: string | undefined;
10
+ processResult: (imageUrl: string, input: TInput) => Promise<TResult> | TResult;
11
+ buildCreation?: (result: TResult, input: TInput) => any; // Type 'Creation' if known, otherwise any
12
+ deductCredits?: () => Promise<void>;
13
+ onSuccess?: (result: TResult) => void;
14
+ onError?: (error: string) => void;
15
+ alertMessages: {
16
+ networkError: string;
17
+ policyViolation: string;
18
+ saveFailed: string;
19
+ creditFailed: string;
20
+ unknown: string;
21
+ };
22
+ }
23
+
24
+ export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TResult>(
25
+ config: UseCoupleFutureGenerationConfig<TInput, TResult>
26
+ ) => {
27
+ const {
28
+ userId,
29
+ processResult,
30
+ buildCreation,
31
+ deductCredits,
32
+ onSuccess,
33
+ onError,
34
+ alertMessages,
35
+ } = config;
36
+
37
+ const repository = useCallback(() => createCreationsRepository("creations"), []);
38
+
39
+ const generationConfig: PhotoGenerationConfig<TInput, TResult, void> = {
40
+ generate: async (input: TInput, onProgress?: (progress: number) => void) => {
41
+ const result = await executeCoupleFuture(
42
+ {
43
+ partnerABase64: input.partnerABase64,
44
+ partnerBBase64: input.partnerBBase64,
45
+ prompt: input.prompt,
46
+ },
47
+ { onProgress }
48
+ );
49
+
50
+ if (!result.success || !result.imageUrl) {
51
+ throw new Error(result.error || "Generation failed");
52
+ }
53
+
54
+ return processResult(result.imageUrl, input);
55
+ },
56
+
57
+ save: async (result: TResult, input: TInput) => {
58
+ if (!userId || !buildCreation) {
59
+ return;
60
+ }
61
+ const creation = buildCreation(result, input);
62
+ if (creation) {
63
+ await repository().create(userId, creation);
64
+ }
65
+ },
66
+
67
+ deductCredits,
68
+ onSuccess,
69
+ onError: (error: PhotoGenerationError) => {
70
+ onError?.(error.message);
71
+ },
72
+ alertMessages,
73
+ };
74
+
75
+ return usePhotoGeneration(generationConfig);
76
+ };
@@ -29,7 +29,7 @@ export interface AlertMessages {
29
29
  }
30
30
 
31
31
  export interface PhotoGenerationConfig<TInput, TResult, TSaveInput> {
32
- generate: (input: TInput) => Promise<TResult>;
32
+ generate: (input: TInput, onProgress?: (progress: number) => void) => Promise<TResult>;
33
33
  save?: (result: TResult, input: TInput) => Promise<TSaveInput>;
34
34
  buildMetadata?: (input: TInput) => Record<string, unknown>;
35
35
  checkCredits?: () => Promise<boolean>;
@@ -86,7 +86,10 @@ export const usePhotoGeneration = <TInput, TResult, TSaveInput = unknown>(
86
86
  setState((prev) => ({ ...prev, progress: 20 }));
87
87
 
88
88
  // Generate without timeout - let AI provider handle its own timeout
89
- const result = await generateFn(input);
89
+ // Pass progress callback to allow provider to report real progress
90
+ const result = await generateFn(input, (newProgress) => {
91
+ setState((prev) => ({ ...prev, progress: newProgress }));
92
+ });
90
93
 
91
94
  setState((prev) => ({ ...prev, progress: 60 }));
92
95