@umituz/react-native-ai-generation-content 1.17.0 → 1.17.1
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 +13 -14
- package/src/domains/creations/domain/entities/Creation.ts +33 -2
- package/src/domains/creations/domain/entities/index.ts +1 -1
- package/src/domains/creations/domain/types/creation-categories.ts +133 -0
- package/src/domains/creations/domain/types/creation-filter.ts +131 -0
- package/src/domains/creations/domain/types/creation-types.ts +63 -0
- package/src/domains/creations/domain/types/index.ts +44 -0
- package/src/domains/creations/domain/utils/creation-helpers.ts +134 -0
- package/src/domains/creations/domain/utils/index.ts +8 -0
- package/src/domains/creations/domain/utils/preview-helpers.ts +84 -0
- package/src/domains/creations/domain/utils/status-helpers.ts +90 -0
- package/src/domains/creations/index.ts +95 -21
- package/src/domains/creations/infrastructure/repositories/CreationsRepository.ts +14 -1
- package/src/domains/creations/presentation/components/CreationActions.tsx +120 -0
- package/src/domains/creations/presentation/components/CreationBadges.tsx +111 -0
- package/src/domains/creations/presentation/components/CreationCard.tsx +201 -102
- package/src/domains/creations/presentation/components/CreationPreview.tsx +117 -0
- package/src/domains/creations/presentation/components/CreationsFilterBar.tsx +254 -0
- package/src/domains/creations/presentation/components/CreationsGrid.tsx +121 -68
- package/src/domains/creations/presentation/components/index.ts +23 -3
- package/src/domains/creations/presentation/hooks/index.ts +1 -0
- package/src/domains/creations/presentation/hooks/useAdvancedFilter.ts +262 -0
- package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +5 -6
- package/src/features/ai-hug/domain/index.ts +5 -0
- package/src/features/ai-hug/domain/types/ai-hug.types.ts +72 -0
- package/src/features/ai-hug/domain/types/index.ts +14 -0
- package/src/features/ai-hug/index.ts +27 -0
- package/src/features/ai-hug/infrastructure/index.ts +5 -0
- package/src/features/ai-hug/infrastructure/services/ai-hug-executor.ts +96 -0
- package/src/features/ai-hug/infrastructure/services/index.ts +6 -0
- package/src/features/ai-hug/presentation/hooks/index.ts +9 -0
- package/src/features/ai-hug/presentation/hooks/useAIHugFeature.ts +157 -0
- package/src/features/ai-hug/presentation/index.ts +5 -0
- package/src/features/ai-kiss/domain/index.ts +5 -0
- package/src/features/ai-kiss/domain/types/ai-kiss.types.ts +72 -0
- package/src/features/ai-kiss/domain/types/index.ts +14 -0
- package/src/features/ai-kiss/index.ts +27 -0
- package/src/features/ai-kiss/infrastructure/index.ts +5 -0
- package/src/features/ai-kiss/infrastructure/services/ai-kiss-executor.ts +96 -0
- package/src/features/ai-kiss/infrastructure/services/index.ts +6 -0
- package/src/features/ai-kiss/presentation/hooks/index.ts +9 -0
- package/src/features/ai-kiss/presentation/hooks/useAIKissFeature.ts +157 -0
- package/src/features/ai-kiss/presentation/index.ts +5 -0
- package/src/features/anime-selfie/domain/index.ts +5 -0
- package/src/features/anime-selfie/domain/types/anime-selfie.types.ts +72 -0
- package/src/features/anime-selfie/domain/types/index.ts +15 -0
- package/src/features/anime-selfie/index.ts +28 -0
- package/src/features/anime-selfie/infrastructure/index.ts +5 -0
- package/src/features/anime-selfie/infrastructure/services/anime-selfie-executor.ts +95 -0
- package/src/features/anime-selfie/infrastructure/services/index.ts +6 -0
- package/src/features/anime-selfie/presentation/hooks/index.ts +9 -0
- package/src/features/anime-selfie/presentation/hooks/useAnimeSelfieFeature.ts +138 -0
- package/src/features/anime-selfie/presentation/index.ts +5 -0
- package/src/features/background/domain/types/index.ts +15 -0
- package/src/features/background/domain/types/replace-background.types.ts +82 -0
- package/src/features/background/index.ts +31 -3
- package/src/features/background/infrastructure/index.ts +5 -0
- package/src/features/background/infrastructure/services/index.ts +6 -0
- package/src/features/background/infrastructure/services/replace-background-executor.ts +95 -0
- package/src/features/background/presentation/hooks/index.ts +6 -1
- package/src/features/background/presentation/hooks/useReplaceBackgroundFeature.ts +160 -0
- package/src/features/face-swap/domain/index.ts +5 -0
- package/src/features/face-swap/domain/types/face-swap.types.ts +72 -0
- package/src/features/face-swap/domain/types/index.ts +14 -0
- package/src/features/face-swap/index.ts +27 -1
- package/src/features/face-swap/infrastructure/index.ts +5 -0
- package/src/features/face-swap/infrastructure/services/face-swap-executor.ts +96 -0
- package/src/features/face-swap/infrastructure/services/index.ts +6 -0
- package/src/features/face-swap/presentation/hooks/index.ts +9 -0
- package/src/features/face-swap/presentation/hooks/useFaceSwapFeature.ts +157 -0
- package/src/features/face-swap/presentation/index.ts +5 -0
- package/src/features/photo-restoration/domain/types/index.ts +2 -5
- package/src/features/photo-restoration/domain/types/photo-restore.types.ts +14 -0
- package/src/features/photo-restoration/index.ts +3 -8
- package/src/features/photo-restoration/infrastructure/services/index.ts +1 -6
- package/src/features/photo-restoration/infrastructure/services/photo-restore-executor.ts +64 -30
- package/src/features/photo-restoration/presentation/hooks/usePhotoRestoreFeature.ts +11 -6
- package/src/features/remove-background/domain/index.ts +5 -0
- package/src/features/remove-background/domain/types/index.ts +14 -0
- package/src/features/remove-background/domain/types/remove-background.types.ts +69 -0
- package/src/features/remove-background/index.ts +27 -0
- package/src/features/remove-background/infrastructure/index.ts +5 -0
- package/src/features/remove-background/infrastructure/services/index.ts +6 -0
- package/src/features/remove-background/infrastructure/services/remove-background-executor.ts +95 -0
- package/src/features/remove-background/presentation/hooks/index.ts +9 -0
- package/src/features/remove-background/presentation/hooks/useRemoveBackgroundFeature.ts +137 -0
- package/src/features/remove-background/presentation/index.ts +5 -0
- package/src/features/remove-object/domain/index.ts +5 -0
- package/src/features/remove-object/domain/types/index.ts +14 -0
- package/src/features/remove-object/domain/types/remove-object.types.ts +77 -0
- package/src/features/remove-object/index.ts +27 -0
- package/src/features/remove-object/infrastructure/index.ts +5 -0
- package/src/features/remove-object/infrastructure/services/index.ts +6 -0
- package/src/features/remove-object/infrastructure/services/remove-object-executor.ts +99 -0
- package/src/features/remove-object/presentation/hooks/index.ts +9 -0
- package/src/features/remove-object/presentation/hooks/useRemoveObjectFeature.ts +168 -0
- package/src/features/remove-object/presentation/index.ts +5 -0
- package/src/features/upscaling/domain/types/index.ts +0 -1
- package/src/features/upscaling/domain/types/upscale.types.ts +14 -0
- package/src/features/upscaling/index.ts +3 -11
- package/src/features/upscaling/infrastructure/services/index.ts +1 -6
- package/src/features/upscaling/infrastructure/services/upscale-executor.ts +64 -30
- package/src/features/upscaling/presentation/hooks/useUpscaleFeature.ts +12 -7
- package/src/index.ts +39 -0
- package/src/types/jsx.d.ts +19 -0
- package/src/features/face-swap/domain/entities.ts +0 -48
- package/src/features/photo-restoration/domain/types/provider.types.ts +0 -23
- package/src/features/photo-restoration/infrastructure/services/photo-restore-provider-registry.ts +0 -77
- package/src/features/upscaling/domain/types/provider.types.ts +0 -23
- package/src/features/upscaling/infrastructure/services/upscale-provider-registry.ts +0 -77
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Background Feature
|
|
3
|
+
* Provider-agnostic background removal feature
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Domain Types
|
|
7
|
+
export type {
|
|
8
|
+
RemoveBackgroundOptions,
|
|
9
|
+
RemoveBackgroundRequest,
|
|
10
|
+
RemoveBackgroundResult,
|
|
11
|
+
RemoveBackgroundFeatureState,
|
|
12
|
+
RemoveBackgroundTranslations,
|
|
13
|
+
RemoveBackgroundFeatureConfig,
|
|
14
|
+
RemoveBackgroundInputBuilder,
|
|
15
|
+
RemoveBackgroundResultExtractor,
|
|
16
|
+
} from "./domain";
|
|
17
|
+
|
|
18
|
+
// Infrastructure Services
|
|
19
|
+
export { executeRemoveBackground, hasRemoveBackgroundSupport } from "./infrastructure";
|
|
20
|
+
export type { ExecuteRemoveBackgroundOptions } from "./infrastructure";
|
|
21
|
+
|
|
22
|
+
// Presentation Hooks
|
|
23
|
+
export { useRemoveBackgroundFeature } from "./presentation";
|
|
24
|
+
export type {
|
|
25
|
+
UseRemoveBackgroundFeatureProps,
|
|
26
|
+
UseRemoveBackgroundFeatureReturn,
|
|
27
|
+
} from "./presentation";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Background Executor
|
|
3
|
+
* Provider-agnostic background removal execution using active AI provider
|
|
4
|
+
* Model and input format are provided via options from app level
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { providerRegistry } from "../../../../infrastructure/services";
|
|
8
|
+
import { cleanBase64 } from "../../../../infrastructure/utils";
|
|
9
|
+
import type {
|
|
10
|
+
RemoveBackgroundRequest,
|
|
11
|
+
RemoveBackgroundResult,
|
|
12
|
+
RemoveBackgroundInputBuilder,
|
|
13
|
+
RemoveBackgroundResultExtractor,
|
|
14
|
+
} from "../../domain/types";
|
|
15
|
+
|
|
16
|
+
declare const __DEV__: boolean;
|
|
17
|
+
|
|
18
|
+
export interface ExecuteRemoveBackgroundOptions {
|
|
19
|
+
model: string;
|
|
20
|
+
buildInput: RemoveBackgroundInputBuilder;
|
|
21
|
+
extractResult?: RemoveBackgroundResultExtractor;
|
|
22
|
+
onProgress?: (progress: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function defaultExtractResult(result: unknown): string | undefined {
|
|
26
|
+
if (typeof result !== "object" || result === null) return undefined;
|
|
27
|
+
|
|
28
|
+
const r = result as Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
if (typeof r.image === "string") return r.image;
|
|
31
|
+
if (Array.isArray(r.images) && r.images[0]?.url) return r.images[0].url;
|
|
32
|
+
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function executeRemoveBackground(
|
|
37
|
+
request: RemoveBackgroundRequest,
|
|
38
|
+
options: ExecuteRemoveBackgroundOptions,
|
|
39
|
+
): Promise<RemoveBackgroundResult> {
|
|
40
|
+
const provider = providerRegistry.getActiveProvider();
|
|
41
|
+
|
|
42
|
+
if (!provider) {
|
|
43
|
+
return { success: false, error: "No AI provider configured" };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!provider.isInitialized()) {
|
|
47
|
+
return { success: false, error: "AI provider not initialized" };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!request.imageBase64) {
|
|
51
|
+
return { success: false, error: "Image base64 is required" };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { model, buildInput, extractResult, onProgress } = options;
|
|
55
|
+
|
|
56
|
+
if (__DEV__) {
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
console.log(`[RemoveBackground] Provider: ${provider.providerId}, Model: ${model}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
onProgress?.(10);
|
|
63
|
+
|
|
64
|
+
const base64 = cleanBase64(request.imageBase64);
|
|
65
|
+
onProgress?.(30);
|
|
66
|
+
|
|
67
|
+
const input = buildInput(base64, request.options);
|
|
68
|
+
onProgress?.(40);
|
|
69
|
+
|
|
70
|
+
const result = await provider.run(model, input);
|
|
71
|
+
onProgress?.(90);
|
|
72
|
+
|
|
73
|
+
const extractor = extractResult || defaultExtractResult;
|
|
74
|
+
const imageUrl = extractor(result);
|
|
75
|
+
onProgress?.(100);
|
|
76
|
+
|
|
77
|
+
if (!imageUrl) {
|
|
78
|
+
return { success: false, error: "No image in response" };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { success: true, imageUrl };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
if (__DEV__) {
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.error("[RemoveBackground] Error:", message);
|
|
87
|
+
}
|
|
88
|
+
return { success: false, error: message };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function hasRemoveBackgroundSupport(): boolean {
|
|
93
|
+
const provider = providerRegistry.getActiveProvider();
|
|
94
|
+
return provider !== null && provider.isInitialized();
|
|
95
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useRemoveBackgroundFeature Hook
|
|
3
|
+
* Manages remove background feature state and actions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useState, useCallback } from "react";
|
|
7
|
+
import { executeRemoveBackground } from "../../infrastructure/services";
|
|
8
|
+
import type {
|
|
9
|
+
RemoveBackgroundFeatureState,
|
|
10
|
+
RemoveBackgroundFeatureConfig,
|
|
11
|
+
RemoveBackgroundResult,
|
|
12
|
+
} from "../../domain/types";
|
|
13
|
+
|
|
14
|
+
declare const __DEV__: boolean;
|
|
15
|
+
|
|
16
|
+
export interface UseRemoveBackgroundFeatureProps {
|
|
17
|
+
config: RemoveBackgroundFeatureConfig;
|
|
18
|
+
userId: string;
|
|
19
|
+
onSelectImage: () => Promise<string | null>;
|
|
20
|
+
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface UseRemoveBackgroundFeatureReturn extends RemoveBackgroundFeatureState {
|
|
24
|
+
selectImage: () => Promise<void>;
|
|
25
|
+
process: () => Promise<void>;
|
|
26
|
+
save: () => Promise<void>;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const initialState: RemoveBackgroundFeatureState = {
|
|
31
|
+
imageUri: null,
|
|
32
|
+
processedUrl: null,
|
|
33
|
+
isProcessing: false,
|
|
34
|
+
progress: 0,
|
|
35
|
+
error: null,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export function useRemoveBackgroundFeature(
|
|
39
|
+
props: UseRemoveBackgroundFeatureProps,
|
|
40
|
+
): UseRemoveBackgroundFeatureReturn {
|
|
41
|
+
const { config, userId, onSelectImage, onSaveImage } = props;
|
|
42
|
+
const [state, setState] = useState<RemoveBackgroundFeatureState>(initialState);
|
|
43
|
+
|
|
44
|
+
const selectImage = useCallback(async () => {
|
|
45
|
+
try {
|
|
46
|
+
const uri = await onSelectImage();
|
|
47
|
+
if (uri) {
|
|
48
|
+
setState((prev) => ({ ...prev, imageUri: uri, error: null }));
|
|
49
|
+
config.onImageSelect?.(uri);
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
setState((prev) => ({ ...prev, error: message }));
|
|
54
|
+
}
|
|
55
|
+
}, [onSelectImage, config]);
|
|
56
|
+
|
|
57
|
+
const handleProgress = useCallback((progress: number) => {
|
|
58
|
+
setState((prev) => ({ ...prev, progress }));
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
const process = useCallback(async () => {
|
|
62
|
+
if (!state.imageUri) return;
|
|
63
|
+
|
|
64
|
+
setState((prev) => ({
|
|
65
|
+
...prev,
|
|
66
|
+
isProcessing: true,
|
|
67
|
+
progress: 0,
|
|
68
|
+
error: null,
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
config.onProcessingStart?.();
|
|
72
|
+
|
|
73
|
+
if (__DEV__) {
|
|
74
|
+
// eslint-disable-next-line no-console
|
|
75
|
+
console.log("[useRemoveBackgroundFeature] Starting background removal process");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
79
|
+
|
|
80
|
+
const result: RemoveBackgroundResult = await executeRemoveBackground(
|
|
81
|
+
{
|
|
82
|
+
imageUri: state.imageUri,
|
|
83
|
+
imageBase64,
|
|
84
|
+
userId,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
model: config.model,
|
|
88
|
+
buildInput: config.buildInput,
|
|
89
|
+
extractResult: config.extractResult,
|
|
90
|
+
onProgress: handleProgress,
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (result.success && result.imageUrl) {
|
|
95
|
+
const url = result.imageUrl;
|
|
96
|
+
setState((prev) => ({
|
|
97
|
+
...prev,
|
|
98
|
+
isProcessing: false,
|
|
99
|
+
processedUrl: url,
|
|
100
|
+
progress: 100,
|
|
101
|
+
}));
|
|
102
|
+
config.onProcessingComplete?.(result);
|
|
103
|
+
} else {
|
|
104
|
+
const errorMessage = result.error || "Processing failed";
|
|
105
|
+
setState((prev) => ({
|
|
106
|
+
...prev,
|
|
107
|
+
isProcessing: false,
|
|
108
|
+
error: errorMessage,
|
|
109
|
+
progress: 0,
|
|
110
|
+
}));
|
|
111
|
+
config.onError?.(errorMessage);
|
|
112
|
+
}
|
|
113
|
+
}, [state.imageUri, userId, config, handleProgress]);
|
|
114
|
+
|
|
115
|
+
const save = useCallback(async () => {
|
|
116
|
+
if (!state.processedUrl) return;
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
await onSaveImage(state.processedUrl);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
122
|
+
setState((prev) => ({ ...prev, error: message }));
|
|
123
|
+
}
|
|
124
|
+
}, [state.processedUrl, onSaveImage]);
|
|
125
|
+
|
|
126
|
+
const reset = useCallback(() => {
|
|
127
|
+
setState(initialState);
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
...state,
|
|
132
|
+
selectImage,
|
|
133
|
+
process,
|
|
134
|
+
save,
|
|
135
|
+
reset,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Object Domain Types Index
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type {
|
|
6
|
+
RemoveObjectOptions,
|
|
7
|
+
RemoveObjectRequest,
|
|
8
|
+
RemoveObjectResult,
|
|
9
|
+
RemoveObjectFeatureState,
|
|
10
|
+
RemoveObjectTranslations,
|
|
11
|
+
RemoveObjectInputBuilder,
|
|
12
|
+
RemoveObjectResultExtractor,
|
|
13
|
+
RemoveObjectFeatureConfig,
|
|
14
|
+
} from "./remove-object.types";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Object Feature Types
|
|
3
|
+
* Request, Result, Config types for object removal (inpainting)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface RemoveObjectOptions {
|
|
7
|
+
prompt?: string;
|
|
8
|
+
maskBase64?: string;
|
|
9
|
+
fillBackground?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RemoveObjectRequest {
|
|
13
|
+
imageUri: string;
|
|
14
|
+
imageBase64?: string;
|
|
15
|
+
maskBase64?: string;
|
|
16
|
+
prompt?: string;
|
|
17
|
+
userId: string;
|
|
18
|
+
options?: RemoveObjectOptions;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RemoveObjectResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
imageUrl?: string;
|
|
24
|
+
imageBase64?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
requestId?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RemoveObjectFeatureState {
|
|
30
|
+
imageUri: string | null;
|
|
31
|
+
maskUri: string | null;
|
|
32
|
+
prompt: string;
|
|
33
|
+
processedUrl: string | null;
|
|
34
|
+
isProcessing: boolean;
|
|
35
|
+
progress: number;
|
|
36
|
+
error: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface RemoveObjectTranslations {
|
|
40
|
+
uploadTitle: string;
|
|
41
|
+
uploadSubtitle: string;
|
|
42
|
+
uploadChange: string;
|
|
43
|
+
uploadAnalyzing: string;
|
|
44
|
+
maskTitle: string;
|
|
45
|
+
maskSubtitle: string;
|
|
46
|
+
promptPlaceholder: string;
|
|
47
|
+
description: string;
|
|
48
|
+
processingText: string;
|
|
49
|
+
processButtonText: string;
|
|
50
|
+
successText: string;
|
|
51
|
+
saveButtonText: string;
|
|
52
|
+
tryAnotherText: string;
|
|
53
|
+
beforeLabel?: string;
|
|
54
|
+
afterLabel?: string;
|
|
55
|
+
compareHint?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type RemoveObjectInputBuilder = (
|
|
59
|
+
base64: string,
|
|
60
|
+
options?: RemoveObjectOptions,
|
|
61
|
+
) => Record<string, unknown>;
|
|
62
|
+
|
|
63
|
+
export type RemoveObjectResultExtractor = (result: unknown) => string | undefined;
|
|
64
|
+
|
|
65
|
+
export interface RemoveObjectFeatureConfig {
|
|
66
|
+
providerId?: string;
|
|
67
|
+
creditCost?: number;
|
|
68
|
+
model: string;
|
|
69
|
+
buildInput: RemoveObjectInputBuilder;
|
|
70
|
+
extractResult?: RemoveObjectResultExtractor;
|
|
71
|
+
prepareImage: (imageUri: string) => Promise<string>;
|
|
72
|
+
onImageSelect?: (uri: string) => void;
|
|
73
|
+
onMaskSelect?: (uri: string) => void;
|
|
74
|
+
onProcessingStart?: () => void;
|
|
75
|
+
onProcessingComplete?: (result: RemoveObjectResult) => void;
|
|
76
|
+
onError?: (error: string) => void;
|
|
77
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Object Feature
|
|
3
|
+
* Provider-agnostic object removal (inpainting) feature
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Domain Types
|
|
7
|
+
export type {
|
|
8
|
+
RemoveObjectOptions,
|
|
9
|
+
RemoveObjectRequest,
|
|
10
|
+
RemoveObjectResult,
|
|
11
|
+
RemoveObjectFeatureState,
|
|
12
|
+
RemoveObjectTranslations,
|
|
13
|
+
RemoveObjectFeatureConfig,
|
|
14
|
+
RemoveObjectInputBuilder,
|
|
15
|
+
RemoveObjectResultExtractor,
|
|
16
|
+
} from "./domain";
|
|
17
|
+
|
|
18
|
+
// Infrastructure Services
|
|
19
|
+
export { executeRemoveObject, hasRemoveObjectSupport } from "./infrastructure";
|
|
20
|
+
export type { ExecuteRemoveObjectOptions } from "./infrastructure";
|
|
21
|
+
|
|
22
|
+
// Presentation Hooks
|
|
23
|
+
export { useRemoveObjectFeature } from "./presentation";
|
|
24
|
+
export type {
|
|
25
|
+
UseRemoveObjectFeatureProps,
|
|
26
|
+
UseRemoveObjectFeatureReturn,
|
|
27
|
+
} from "./presentation";
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Object Executor
|
|
3
|
+
* Provider-agnostic object removal execution using active AI provider
|
|
4
|
+
* Model and input format are provided via options from app level
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { providerRegistry } from "../../../../infrastructure/services";
|
|
8
|
+
import { cleanBase64 } from "../../../../infrastructure/utils";
|
|
9
|
+
import type {
|
|
10
|
+
RemoveObjectRequest,
|
|
11
|
+
RemoveObjectResult,
|
|
12
|
+
RemoveObjectInputBuilder,
|
|
13
|
+
RemoveObjectResultExtractor,
|
|
14
|
+
} from "../../domain/types";
|
|
15
|
+
|
|
16
|
+
declare const __DEV__: boolean;
|
|
17
|
+
|
|
18
|
+
export interface ExecuteRemoveObjectOptions {
|
|
19
|
+
model: string;
|
|
20
|
+
buildInput: RemoveObjectInputBuilder;
|
|
21
|
+
extractResult?: RemoveObjectResultExtractor;
|
|
22
|
+
onProgress?: (progress: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function defaultExtractResult(result: unknown): string | undefined {
|
|
26
|
+
if (typeof result !== "object" || result === null) return undefined;
|
|
27
|
+
|
|
28
|
+
const r = result as Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
if (typeof r.image === "string") return r.image;
|
|
31
|
+
if (Array.isArray(r.images) && r.images[0]?.url) return r.images[0].url;
|
|
32
|
+
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function executeRemoveObject(
|
|
37
|
+
request: RemoveObjectRequest,
|
|
38
|
+
options: ExecuteRemoveObjectOptions,
|
|
39
|
+
): Promise<RemoveObjectResult> {
|
|
40
|
+
const provider = providerRegistry.getActiveProvider();
|
|
41
|
+
|
|
42
|
+
if (!provider) {
|
|
43
|
+
return { success: false, error: "No AI provider configured" };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!provider.isInitialized()) {
|
|
47
|
+
return { success: false, error: "AI provider not initialized" };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!request.imageBase64) {
|
|
51
|
+
return { success: false, error: "Image base64 is required" };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { model, buildInput, extractResult, onProgress } = options;
|
|
55
|
+
|
|
56
|
+
if (__DEV__) {
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
console.log(`[RemoveObject] Provider: ${provider.providerId}, Model: ${model}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
onProgress?.(10);
|
|
63
|
+
|
|
64
|
+
const base64 = cleanBase64(request.imageBase64);
|
|
65
|
+
onProgress?.(30);
|
|
66
|
+
|
|
67
|
+
const input = buildInput(base64, {
|
|
68
|
+
maskBase64: request.maskBase64,
|
|
69
|
+
prompt: request.prompt,
|
|
70
|
+
...request.options,
|
|
71
|
+
});
|
|
72
|
+
onProgress?.(40);
|
|
73
|
+
|
|
74
|
+
const result = await provider.run(model, input);
|
|
75
|
+
onProgress?.(90);
|
|
76
|
+
|
|
77
|
+
const extractor = extractResult || defaultExtractResult;
|
|
78
|
+
const imageUrl = extractor(result);
|
|
79
|
+
onProgress?.(100);
|
|
80
|
+
|
|
81
|
+
if (!imageUrl) {
|
|
82
|
+
return { success: false, error: "No image in response" };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { success: true, imageUrl };
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
88
|
+
if (__DEV__) {
|
|
89
|
+
// eslint-disable-next-line no-console
|
|
90
|
+
console.error("[RemoveObject] Error:", message);
|
|
91
|
+
}
|
|
92
|
+
return { success: false, error: message };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function hasRemoveObjectSupport(): boolean {
|
|
97
|
+
const provider = providerRegistry.getActiveProvider();
|
|
98
|
+
return provider !== null && provider.isInitialized();
|
|
99
|
+
}
|