@umituz/react-native-ai-generation-content 1.17.164 → 1.17.166

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.164",
3
+ "version": "1.17.166",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -22,7 +22,6 @@ export class CreationsWriter {
22
22
 
23
23
  const data: CreationDocument = {
24
24
  type: creation.type,
25
- prompt: creation.prompt,
26
25
  uri: creation.uri,
27
26
  createdAt: creation.createdAt,
28
27
  metadata: creation.metadata || {},
@@ -30,6 +29,7 @@ export class CreationsWriter {
30
29
  isFavorite: creation.isFavorite || false,
31
30
  status: creation.status,
32
31
  output: creation.output ?? null,
32
+ ...(creation.prompt !== undefined && { prompt: creation.prompt }),
33
33
  };
34
34
 
35
35
  try {
@@ -102,24 +102,19 @@ export interface BaseDualImageTranslations {
102
102
  */
103
103
  export type ImageResultExtractor = (result: unknown) => string | undefined;
104
104
 
105
- /**
106
- * Base processing start data for persistence
107
- */
108
- export interface BaseProcessingStartData {
109
- creationId: string;
110
- }
111
-
112
105
  /**
113
106
  * Single image processing start data
114
107
  */
115
- export interface SingleImageProcessingStartData extends BaseProcessingStartData {
108
+ export interface SingleImageProcessingStartData {
109
+ creationId: string;
116
110
  imageUri: string;
117
111
  }
118
112
 
119
113
  /**
120
114
  * Dual image processing start data
121
115
  */
122
- export interface DualImageProcessingStartData extends BaseProcessingStartData {
116
+ export interface DualImageProcessingStartData {
117
+ creationId: string;
123
118
  sourceImageUri: string;
124
119
  targetImageUri: string;
125
120
  }
@@ -134,15 +129,12 @@ export interface BaseImageResultWithCreationId extends BaseImageResult {
134
129
  /**
135
130
  * Base config for all image features
136
131
  */
137
- export interface BaseImageConfig<
138
- TResult extends BaseImageResult = BaseImageResult,
139
- TStartData extends BaseProcessingStartData = BaseProcessingStartData,
140
- > {
132
+ export interface BaseImageConfig<TResult extends BaseImageResult = BaseImageResult> {
141
133
  featureType: ImageFeatureType;
142
134
  creditCost?: number;
143
135
  extractResult?: ImageResultExtractor;
144
136
  prepareImage: (imageUri: string) => Promise<string>;
145
- onProcessingStart?: (data: TStartData) => void;
137
+ onProcessingStart?: (data: { creationId: string; [key: string]: unknown }) => void;
146
138
  onProcessingComplete?: (result: TResult) => void;
147
139
  onError?: (error: string, creationId?: string) => void;
148
140
  }
@@ -151,7 +143,7 @@ export interface BaseImageConfig<
151
143
  * Config for single image features
152
144
  */
153
145
  export interface SingleImageConfig<TResult extends BaseImageResult = BaseImageResult>
154
- extends BaseImageConfig<TResult, SingleImageProcessingStartData> {
146
+ extends BaseImageConfig<TResult> {
155
147
  onImageSelect?: (uri: string) => void;
156
148
  }
157
149
 
@@ -159,7 +151,7 @@ export interface SingleImageConfig<TResult extends BaseImageResult = BaseImageRe
159
151
  * Config for dual image features
160
152
  */
161
153
  export interface DualImageConfig<TResult extends BaseImageResult = BaseImageResult>
162
- extends BaseImageConfig<TResult, DualImageProcessingStartData> {
154
+ extends BaseImageConfig<TResult> {
163
155
  onSourceImageSelect?: (uri: string) => void;
164
156
  onTargetImageSelect?: (uri: string) => void;
165
157
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { useState, useCallback, useRef } from "react";
7
- import { generateCreationId } from "@umituz/react-native-uuid";
7
+ import { generateUUID } from "@umituz/react-native-uuid";
8
8
  import { executeImageFeature } from "../../../../infrastructure/services";
9
9
  import type {
10
10
  BaseDualImageState,
@@ -80,7 +80,7 @@ export function useDualImageFeature<
80
80
  if (!canProceed) return;
81
81
  }
82
82
 
83
- const creationId = generateCreationId();
83
+ const creationId = generateUUID();
84
84
  creationIdRef.current = creationId;
85
85
 
86
86
  setState((prev) => ({
@@ -119,7 +119,7 @@ export function useDualImageFeature<
119
119
  processedUrl: result.imageUrl!,
120
120
  progress: 100,
121
121
  }));
122
- config.onProcessingComplete?.({ ...result, creationId } as TResult);
122
+ config.onProcessingComplete?.({ ...result, creationId } as unknown as TResult);
123
123
  } else {
124
124
  const errorMessage = result.error || "Processing failed";
125
125
  setState((prev) => ({
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { useState, useCallback, useRef } from "react";
7
- import { generateCreationId } from "@umituz/react-native-uuid";
7
+ import { generateUUID } from "@umituz/react-native-uuid";
8
8
  import { executeImageFeature } from "../../../../infrastructure/services";
9
9
  import type {
10
10
  BaseImageWithPromptState,
@@ -108,7 +108,7 @@ export function useImageWithPromptFeature<
108
108
  return;
109
109
  }
110
110
 
111
- const creationId = generateCreationId();
111
+ const creationId = generateUUID();
112
112
  creationIdRef.current = creationId;
113
113
 
114
114
  setState((prev) => ({
@@ -140,7 +140,7 @@ export function useImageWithPromptFeature<
140
140
  processedUrl: result.imageUrl!,
141
141
  progress: 100,
142
142
  }));
143
- config.onProcessingComplete?.({ ...result, creationId } as TResult);
143
+ config.onProcessingComplete?.({ ...result, creationId } as unknown as TResult);
144
144
  } else {
145
145
  const errorMessage = result.error || "Processing failed";
146
146
  setState((prev) => ({
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { useState, useCallback, useRef } from "react";
7
- import { generateCreationId } from "@umituz/react-native-uuid";
7
+ import { generateUUID } from "@umituz/react-native-uuid";
8
8
  import { executeImageFeature } from "../../../../infrastructure/services";
9
9
  import type {
10
10
  BaseSingleImageState,
@@ -62,7 +62,7 @@ export function useSingleImageFeature<
62
62
  if (!canProceed) return;
63
63
  }
64
64
 
65
- const creationId = generateCreationId();
65
+ const creationId = generateUUID();
66
66
  creationIdRef.current = creationId;
67
67
 
68
68
  setState((prev) => ({
@@ -94,7 +94,7 @@ export function useSingleImageFeature<
94
94
  processedUrl: result.imageUrl!,
95
95
  progress: 100,
96
96
  }));
97
- config.onProcessingComplete?.({ ...result, creationId } as TResult);
97
+ config.onProcessingComplete?.({ ...result, creationId } as unknown as TResult);
98
98
  } else {
99
99
  const errorMessage = result.error || "Processing failed";
100
100
  setState((prev) => ({
@@ -57,7 +57,7 @@ export interface PhotoRestoreFeatureConfig {
57
57
  extractResult?: PhotoRestoreResultExtractor;
58
58
  prepareImage: (imageUri: string) => Promise<string>;
59
59
  onImageSelect?: (uri: string) => void;
60
- onProcessingStart?: () => void;
61
- onProcessingComplete?: (result: PhotoRestoreResult) => void;
62
- onError?: (error: string) => void;
60
+ onProcessingStart?: (data: { creationId: string; imageUri: string }) => void;
61
+ onProcessingComplete?: (result: PhotoRestoreResult & { creationId?: string }) => void;
62
+ onError?: (error: string, creationId?: string) => void;
63
63
  }
@@ -3,7 +3,8 @@
3
3
  * Manages photo restore feature state and actions
4
4
  */
5
5
 
6
- import { useState, useCallback } from "react";
6
+ import { useState, useCallback, useRef } from "react";
7
+ import { generateUUID } from "@umituz/react-native-uuid";
7
8
  import { executeImageFeature } from "../../../../infrastructure/services";
8
9
  import type {
9
10
  PhotoRestoreFeatureState,
@@ -38,6 +39,7 @@ export function usePhotoRestoreFeature(
38
39
  ): UsePhotoRestoreFeatureReturn {
39
40
  const { config, onSelectImage, onSaveImage, onBeforeProcess } = props;
40
41
  const [state, setState] = useState<PhotoRestoreFeatureState>(initialState);
42
+ const creationIdRef = useRef<string | null>(null);
41
43
 
42
44
  const selectImage = useCallback(async () => {
43
45
  try {
@@ -64,6 +66,9 @@ export function usePhotoRestoreFeature(
64
66
  if (!canProceed) return;
65
67
  }
66
68
 
69
+ const creationId = generateUUID();
70
+ creationIdRef.current = creationId;
71
+
67
72
  setState((prev) => ({
68
73
  ...prev,
69
74
  isProcessing: true,
@@ -71,33 +76,44 @@ export function usePhotoRestoreFeature(
71
76
  error: null,
72
77
  }));
73
78
 
74
- config.onProcessingStart?.();
75
-
76
- const imageBase64 = await config.prepareImage(state.imageUri);
77
-
78
- const result = await executeImageFeature(
79
- "photo-restore",
80
- { imageBase64 },
81
- { extractResult: config.extractResult, onProgress: handleProgress },
82
- );
79
+ config.onProcessingStart?.({ creationId, imageUri: state.imageUri });
83
80
 
84
- if (result.success && result.imageUrl) {
85
- setState((prev) => ({
86
- ...prev,
87
- isProcessing: false,
88
- processedUrl: result.imageUrl!,
89
- progress: 100,
90
- }));
91
- config.onProcessingComplete?.(result as PhotoRestoreResult);
92
- } else {
93
- const errorMessage = result.error || "Processing failed";
81
+ try {
82
+ const imageBase64 = await config.prepareImage(state.imageUri);
83
+
84
+ const result = await executeImageFeature(
85
+ "photo-restore",
86
+ { imageBase64 },
87
+ { extractResult: config.extractResult, onProgress: handleProgress },
88
+ );
89
+
90
+ if (result.success && result.imageUrl) {
91
+ setState((prev) => ({
92
+ ...prev,
93
+ isProcessing: false,
94
+ processedUrl: result.imageUrl!,
95
+ progress: 100,
96
+ }));
97
+ config.onProcessingComplete?.({ ...result, creationId } as PhotoRestoreResult & { creationId?: string });
98
+ } else {
99
+ const errorMessage = result.error || "Processing failed";
100
+ setState((prev) => ({
101
+ ...prev,
102
+ isProcessing: false,
103
+ error: errorMessage,
104
+ progress: 0,
105
+ }));
106
+ config.onError?.(errorMessage, creationId);
107
+ }
108
+ } catch (error) {
109
+ const message = error instanceof Error ? error.message : String(error);
94
110
  setState((prev) => ({
95
111
  ...prev,
96
112
  isProcessing: false,
97
- error: errorMessage,
113
+ error: message,
98
114
  progress: 0,
99
115
  }));
100
- config.onError?.(errorMessage);
116
+ config.onError?.(message, creationIdRef.current ?? undefined);
101
117
  }
102
118
  }, [state.imageUri, config, handleProgress, onBeforeProcess]);
103
119
 
@@ -63,7 +63,7 @@ export interface RemoveObjectFeatureConfig {
63
63
  prepareImage: (imageUri: string) => Promise<string>;
64
64
  onImageSelect?: (uri: string) => void;
65
65
  onMaskSelect?: (uri: string) => void;
66
- onProcessingStart?: () => void;
67
- onProcessingComplete?: (result: RemoveObjectResult) => void;
68
- onError?: (error: string) => void;
66
+ onProcessingStart?: (data: { creationId: string; imageUri: string }) => void;
67
+ onProcessingComplete?: (result: RemoveObjectResult & { creationId?: string }) => void;
68
+ onError?: (error: string, creationId?: string) => void;
69
69
  }
@@ -3,7 +3,8 @@
3
3
  * Manages remove object feature state and actions
4
4
  */
5
5
 
6
- import { useState, useCallback } from "react";
6
+ import { useState, useCallback, useRef } from "react";
7
+ import { generateUUID } from "@umituz/react-native-uuid";
7
8
  import { executeImageFeature } from "../../../../infrastructure/services";
8
9
  import type {
9
10
  RemoveObjectFeatureState,
@@ -43,6 +44,7 @@ export function useRemoveObjectFeature(
43
44
  ): UseRemoveObjectFeatureReturn {
44
45
  const { config, onSelectImage, onSelectMask, onSaveImage, onBeforeProcess } = props;
45
46
  const [state, setState] = useState<RemoveObjectFeatureState>(initialState);
47
+ const creationIdRef = useRef<string | null>(null);
46
48
 
47
49
  const selectImage = useCallback(async () => {
48
50
  try {
@@ -88,6 +90,9 @@ export function useRemoveObjectFeature(
88
90
  if (!canProceed) return;
89
91
  }
90
92
 
93
+ const creationId = generateUUID();
94
+ creationIdRef.current = creationId;
95
+
91
96
  setState((prev) => ({
92
97
  ...prev,
93
98
  isProcessing: true,
@@ -95,40 +100,51 @@ export function useRemoveObjectFeature(
95
100
  error: null,
96
101
  }));
97
102
 
98
- config.onProcessingStart?.();
99
-
100
- const imageBase64 = await config.prepareImage(state.imageUri);
101
- const maskBase64 = state.maskUri
102
- ? await config.prepareImage(state.maskUri)
103
- : undefined;
104
-
105
- const result = await executeImageFeature(
106
- "remove-object",
107
- {
108
- imageBase64,
109
- targetImageBase64: maskBase64,
110
- prompt: state.prompt || undefined,
111
- },
112
- { extractResult: config.extractResult, onProgress: handleProgress },
113
- );
103
+ config.onProcessingStart?.({ creationId, imageUri: state.imageUri });
114
104
 
115
- if (result.success && result.imageUrl) {
116
- setState((prev) => ({
117
- ...prev,
118
- isProcessing: false,
119
- processedUrl: result.imageUrl!,
120
- progress: 100,
121
- }));
122
- config.onProcessingComplete?.(result as RemoveObjectResult);
123
- } else {
124
- const errorMessage = result.error || "Processing failed";
105
+ try {
106
+ const imageBase64 = await config.prepareImage(state.imageUri);
107
+ const maskBase64 = state.maskUri
108
+ ? await config.prepareImage(state.maskUri)
109
+ : undefined;
110
+
111
+ const result = await executeImageFeature(
112
+ "remove-object",
113
+ {
114
+ imageBase64,
115
+ targetImageBase64: maskBase64,
116
+ prompt: state.prompt || undefined,
117
+ },
118
+ { extractResult: config.extractResult, onProgress: handleProgress },
119
+ );
120
+
121
+ if (result.success && result.imageUrl) {
122
+ setState((prev) => ({
123
+ ...prev,
124
+ isProcessing: false,
125
+ processedUrl: result.imageUrl!,
126
+ progress: 100,
127
+ }));
128
+ config.onProcessingComplete?.({ ...result, creationId } as RemoveObjectResult & { creationId?: string });
129
+ } else {
130
+ const errorMessage = result.error || "Processing failed";
131
+ setState((prev) => ({
132
+ ...prev,
133
+ isProcessing: false,
134
+ error: errorMessage,
135
+ progress: 0,
136
+ }));
137
+ config.onError?.(errorMessage, creationId);
138
+ }
139
+ } catch (error) {
140
+ const message = error instanceof Error ? error.message : String(error);
125
141
  setState((prev) => ({
126
142
  ...prev,
127
143
  isProcessing: false,
128
- error: errorMessage,
144
+ error: message,
129
145
  progress: 0,
130
146
  }));
131
- config.onError?.(errorMessage);
147
+ config.onError?.(message, creationIdRef.current ?? undefined);
132
148
  }
133
149
  }, [state.imageUri, state.maskUri, state.prompt, config, handleProgress, onBeforeProcess]);
134
150