@umituz/react-native-ai-generation-content 1.17.23 → 1.17.25
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 +1 -1
- package/src/domain/interfaces/ai-provider.interface.ts +66 -0
- package/src/features/ai-hug/domain/types/ai-hug.types.ts +4 -13
- package/src/features/ai-hug/domain/types/index.ts +0 -1
- package/src/features/ai-hug/index.ts +1 -6
- package/src/features/ai-hug/presentation/components/AIHugFeature.tsx +14 -22
- package/src/features/ai-hug/presentation/hooks/useAIHugFeature.ts +16 -35
- package/src/features/ai-kiss/domain/types/ai-kiss.types.ts +4 -13
- package/src/features/ai-kiss/domain/types/index.ts +0 -1
- package/src/features/ai-kiss/index.ts +1 -6
- package/src/features/ai-kiss/presentation/components/AIKissFeature.tsx +13 -20
- package/src/features/ai-kiss/presentation/hooks/useAIKissFeature.ts +16 -35
- package/src/features/anime-selfie/domain/types/anime-selfie.types.ts +0 -8
- package/src/features/anime-selfie/domain/types/index.ts +0 -1
- package/src/features/anime-selfie/index.ts +0 -5
- package/src/features/anime-selfie/presentation/components/AnimeSelfieFeature.tsx +0 -3
- package/src/features/anime-selfie/presentation/hooks/useAnimeSelfieFeature.ts +9 -27
- package/src/features/face-swap/domain/types/face-swap.types.ts +0 -9
- package/src/features/face-swap/domain/types/index.ts +0 -1
- package/src/features/face-swap/index.ts +0 -5
- package/src/features/face-swap/presentation/components/FaceSwapFeature.tsx +0 -3
- package/src/features/face-swap/presentation/hooks/useFaceSwapFeature.ts +9 -28
- package/src/features/hd-touch-up/domain/types/hd-touch-up.types.ts +0 -8
- package/src/features/hd-touch-up/domain/types/index.ts +0 -1
- package/src/features/hd-touch-up/index.ts +0 -5
- package/src/features/hd-touch-up/presentation/components/HDTouchUpFeature.tsx +0 -3
- package/src/features/hd-touch-up/presentation/hooks/useHDTouchUpFeature.ts +9 -26
- package/src/features/photo-restoration/domain/types/index.ts +0 -1
- package/src/features/photo-restoration/domain/types/photo-restore.types.ts +0 -8
- package/src/features/photo-restoration/index.ts +0 -5
- package/src/features/photo-restoration/presentation/components/PhotoRestoreFeature.tsx +0 -4
- package/src/features/photo-restoration/presentation/hooks/usePhotoRestoreFeature.ts +9 -26
- package/src/features/remove-background/domain/types/index.ts +0 -1
- package/src/features/remove-background/domain/types/remove-background.types.ts +0 -8
- package/src/features/remove-background/index.ts +0 -5
- package/src/features/remove-background/presentation/components/RemoveBackgroundFeature.tsx +0 -3
- package/src/features/remove-background/presentation/hooks/useRemoveBackgroundFeature.ts +9 -26
- package/src/features/remove-object/domain/types/index.ts +0 -1
- package/src/features/remove-object/domain/types/remove-object.types.ts +0 -8
- package/src/features/remove-object/index.ts +0 -5
- package/src/features/remove-object/presentation/components/RemoveObjectFeature.tsx +0 -3
- package/src/features/remove-object/presentation/hooks/useRemoveObjectFeature.ts +9 -24
- package/src/features/replace-background/domain/types/index.ts +0 -1
- package/src/features/replace-background/domain/types/replace-background.types.ts +0 -9
- package/src/features/replace-background/index.ts +55 -82
- package/src/features/replace-background/infrastructure/constants/prompts.constants.ts +6 -6
- package/src/features/replace-background/infrastructure/index.ts +2 -2
- package/src/features/replace-background/presentation/components/ReplaceBackgroundFeature.tsx +0 -3
- package/src/features/replace-background/presentation/hooks/useReplaceBackgroundFeature.ts +8 -23
- package/src/features/text-to-video/domain/types/callback.types.ts +3 -3
- package/src/features/text-to-video/domain/types/index.ts +1 -1
- package/src/features/text-to-video/index.ts +1 -1
- package/src/features/text-to-video/presentation/hooks/useTextToVideoFeature.ts +1 -1
- package/src/features/upscaling/domain/types/upscale.types.ts +0 -8
- package/src/features/upscaling/index.ts +0 -5
- package/src/features/upscaling/presentation/components/UpscaleFeature.tsx +0 -4
- package/src/features/upscaling/presentation/hooks/useUpscaleFeature.ts +8 -23
- package/src/index.ts +4 -0
- package/src/infrastructure/services/image-feature-executor.service.ts +143 -0
- package/src/infrastructure/services/index.ts +20 -0
- package/src/infrastructure/services/video-feature-executor.service.ts +140 -0
- package/src/features/ai-hug/infrastructure/index.ts +0 -5
- package/src/features/ai-hug/infrastructure/services/ai-hug-executor.ts +0 -96
- package/src/features/ai-hug/infrastructure/services/index.ts +0 -6
- package/src/features/ai-kiss/infrastructure/index.ts +0 -5
- package/src/features/ai-kiss/infrastructure/services/ai-kiss-executor.ts +0 -96
- package/src/features/ai-kiss/infrastructure/services/index.ts +0 -6
- package/src/features/anime-selfie/infrastructure/index.ts +0 -5
- package/src/features/anime-selfie/infrastructure/services/anime-selfie-executor.ts +0 -95
- package/src/features/anime-selfie/infrastructure/services/index.ts +0 -6
- package/src/features/face-swap/infrastructure/index.ts +0 -5
- package/src/features/face-swap/infrastructure/services/face-swap-executor.ts +0 -96
- package/src/features/face-swap/infrastructure/services/index.ts +0 -6
- package/src/features/hd-touch-up/infrastructure/index.ts +0 -1
- package/src/features/hd-touch-up/infrastructure/services/hd-touch-up-executor.ts +0 -97
- package/src/features/hd-touch-up/infrastructure/services/index.ts +0 -2
- package/src/features/photo-restoration/infrastructure/index.ts +0 -1
- package/src/features/photo-restoration/infrastructure/services/index.ts +0 -2
- package/src/features/photo-restoration/infrastructure/services/photo-restore-executor.ts +0 -98
- package/src/features/remove-background/infrastructure/index.ts +0 -5
- package/src/features/remove-background/infrastructure/services/index.ts +0 -6
- package/src/features/remove-background/infrastructure/services/remove-background-executor.ts +0 -95
- package/src/features/remove-object/infrastructure/index.ts +0 -5
- package/src/features/remove-object/infrastructure/services/index.ts +0 -6
- package/src/features/remove-object/infrastructure/services/remove-object-executor.ts +0 -99
- package/src/features/replace-background/infrastructure/services/index.ts +0 -6
- package/src/features/replace-background/infrastructure/services/replace-background-executor.ts +0 -95
- package/src/features/upscaling/infrastructure/index.ts +0 -1
- package/src/features/upscaling/infrastructure/services/index.ts +0 -2
- package/src/features/upscaling/infrastructure/services/upscale-executor.ts +0 -98
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useState, useCallback } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { executeImageFeature } from "../../../../infrastructure/services";
|
|
8
8
|
import type {
|
|
9
9
|
UpscaleFeatureState,
|
|
10
10
|
UpscaleFeatureConfig,
|
|
11
11
|
UpscaleResult,
|
|
12
12
|
} from "../../domain/types";
|
|
13
13
|
|
|
14
|
-
declare const __DEV__: boolean;
|
|
15
|
-
|
|
16
14
|
export interface UseUpscaleFeatureProps {
|
|
17
15
|
config: UpscaleFeatureConfig;
|
|
18
|
-
userId: string;
|
|
19
16
|
onSelectImage: () => Promise<string | null>;
|
|
20
17
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
21
18
|
}
|
|
@@ -38,7 +35,7 @@ const initialState: UpscaleFeatureState = {
|
|
|
38
35
|
export function useUpscaleFeature(
|
|
39
36
|
props: UseUpscaleFeatureProps,
|
|
40
37
|
): UseUpscaleFeatureReturn {
|
|
41
|
-
const { config,
|
|
38
|
+
const { config, onSelectImage, onSaveImage } = props;
|
|
42
39
|
const [state, setState] = useState<UpscaleFeatureState>(initialState);
|
|
43
40
|
|
|
44
41
|
const selectImage = useCallback(async () => {
|
|
@@ -70,37 +67,25 @@ export function useUpscaleFeature(
|
|
|
70
67
|
|
|
71
68
|
config.onProcessingStart?.();
|
|
72
69
|
|
|
73
|
-
if (__DEV__) {
|
|
74
|
-
// eslint-disable-next-line no-console
|
|
75
|
-
console.log("[useUpscaleFeature] Starting upscale process");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
70
|
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
79
71
|
|
|
80
|
-
const result
|
|
72
|
+
const result = await executeImageFeature(
|
|
73
|
+
"upscale",
|
|
81
74
|
{
|
|
82
|
-
imageUri: state.imageUri,
|
|
83
75
|
imageBase64,
|
|
84
|
-
userId,
|
|
85
76
|
options: { scaleFactor: config.defaultScaleFactor || 2 },
|
|
86
77
|
},
|
|
87
|
-
{
|
|
88
|
-
model: config.model,
|
|
89
|
-
buildInput: config.buildInput,
|
|
90
|
-
extractResult: config.extractResult,
|
|
91
|
-
onProgress: handleProgress,
|
|
92
|
-
},
|
|
78
|
+
{ extractResult: config.extractResult, onProgress: handleProgress },
|
|
93
79
|
);
|
|
94
80
|
|
|
95
81
|
if (result.success && result.imageUrl) {
|
|
96
|
-
const url = result.imageUrl;
|
|
97
82
|
setState((prev) => ({
|
|
98
83
|
...prev,
|
|
99
84
|
isProcessing: false,
|
|
100
|
-
processedUrl:
|
|
85
|
+
processedUrl: result.imageUrl!,
|
|
101
86
|
progress: 100,
|
|
102
87
|
}));
|
|
103
|
-
config.onProcessingComplete?.(result);
|
|
88
|
+
config.onProcessingComplete?.(result as UpscaleResult);
|
|
104
89
|
} else {
|
|
105
90
|
const errorMessage = result.error || "Processing failed";
|
|
106
91
|
setState((prev) => ({
|
|
@@ -111,7 +96,7 @@ export function useUpscaleFeature(
|
|
|
111
96
|
}));
|
|
112
97
|
config.onError?.(errorMessage);
|
|
113
98
|
}
|
|
114
|
-
}, [state.imageUri,
|
|
99
|
+
}, [state.imageUri, config, handleProgress]);
|
|
115
100
|
|
|
116
101
|
const save = useCallback(async () => {
|
|
117
102
|
if (!state.processedUrl) return;
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Feature Executor
|
|
3
|
+
* Single entry point for all image feature executions
|
|
4
|
+
* Output: image URL
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { providerRegistry } from "./provider-registry.service";
|
|
8
|
+
import { cleanBase64 } from "../utils";
|
|
9
|
+
import type { ImageFeatureType, ImageFeatureInputData } from "../../domain/interfaces";
|
|
10
|
+
|
|
11
|
+
declare const __DEV__: boolean;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Result extractor function type
|
|
15
|
+
*/
|
|
16
|
+
export type ImageResultExtractor = (result: unknown) => string | undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Execution options
|
|
20
|
+
*/
|
|
21
|
+
export interface ExecuteImageFeatureOptions {
|
|
22
|
+
extractResult?: ImageResultExtractor;
|
|
23
|
+
onProgress?: (progress: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Execution result
|
|
28
|
+
*/
|
|
29
|
+
export interface ImageFeatureResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
imageUrl?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
requestId?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Request data for image features
|
|
38
|
+
*/
|
|
39
|
+
export interface ImageFeatureRequest {
|
|
40
|
+
imageBase64?: string;
|
|
41
|
+
targetImageBase64?: string;
|
|
42
|
+
prompt?: string;
|
|
43
|
+
options?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Default result extractor - handles common response formats
|
|
48
|
+
*/
|
|
49
|
+
function defaultExtractImageResult(result: unknown): string | undefined {
|
|
50
|
+
if (typeof result !== "object" || result === null) return undefined;
|
|
51
|
+
|
|
52
|
+
const r = result as Record<string, unknown>;
|
|
53
|
+
|
|
54
|
+
if (typeof r.image === "string") return r.image;
|
|
55
|
+
if (typeof r.imageUrl === "string") return r.imageUrl;
|
|
56
|
+
if (typeof r.output === "string") return r.output;
|
|
57
|
+
if (Array.isArray(r.images) && typeof r.images[0]?.url === "string") {
|
|
58
|
+
return r.images[0].url;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Execute any image feature using the active provider
|
|
66
|
+
*/
|
|
67
|
+
export async function executeImageFeature(
|
|
68
|
+
featureType: ImageFeatureType,
|
|
69
|
+
request: ImageFeatureRequest,
|
|
70
|
+
options?: ExecuteImageFeatureOptions,
|
|
71
|
+
): Promise<ImageFeatureResult> {
|
|
72
|
+
const provider = providerRegistry.getActiveProvider();
|
|
73
|
+
|
|
74
|
+
if (!provider) {
|
|
75
|
+
return { success: false, error: "No AI provider configured" };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!provider.isInitialized()) {
|
|
79
|
+
return { success: false, error: "AI provider not initialized" };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { extractResult, onProgress } = options ?? {};
|
|
83
|
+
|
|
84
|
+
const model = provider.getImageFeatureModel(featureType);
|
|
85
|
+
|
|
86
|
+
if (__DEV__) {
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
88
|
+
console.log(`[Image:${featureType}] Provider: ${provider.providerId}, Model: ${model}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
onProgress?.(10);
|
|
93
|
+
|
|
94
|
+
const inputData: ImageFeatureInputData = {
|
|
95
|
+
imageBase64: request.imageBase64 ? cleanBase64(request.imageBase64) : "",
|
|
96
|
+
targetImageBase64: request.targetImageBase64
|
|
97
|
+
? cleanBase64(request.targetImageBase64)
|
|
98
|
+
: undefined,
|
|
99
|
+
prompt: request.prompt,
|
|
100
|
+
options: request.options,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
onProgress?.(30);
|
|
104
|
+
|
|
105
|
+
const input = provider.buildImageFeatureInput(featureType, inputData);
|
|
106
|
+
|
|
107
|
+
onProgress?.(40);
|
|
108
|
+
|
|
109
|
+
const result = await provider.run(model, input);
|
|
110
|
+
|
|
111
|
+
onProgress?.(90);
|
|
112
|
+
|
|
113
|
+
const extractor = extractResult ?? defaultExtractImageResult;
|
|
114
|
+
const imageUrl = extractor(result);
|
|
115
|
+
|
|
116
|
+
onProgress?.(100);
|
|
117
|
+
|
|
118
|
+
if (!imageUrl) {
|
|
119
|
+
return { success: false, error: "No image in response" };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
imageUrl,
|
|
125
|
+
requestId: (result as { requestId?: string })?.requestId,
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
129
|
+
if (__DEV__) {
|
|
130
|
+
// eslint-disable-next-line no-console
|
|
131
|
+
console.error(`[Image:${featureType}] Error:`, message);
|
|
132
|
+
}
|
|
133
|
+
return { success: false, error: message };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Check if image features are supported
|
|
139
|
+
*/
|
|
140
|
+
export function hasImageFeatureSupport(): boolean {
|
|
141
|
+
const provider = providerRegistry.getActiveProvider();
|
|
142
|
+
return provider !== null && provider.isInitialized();
|
|
143
|
+
}
|
|
@@ -12,3 +12,23 @@ export {
|
|
|
12
12
|
createGenerationWrapper,
|
|
13
13
|
} from "./generation-wrapper.service";
|
|
14
14
|
export type { WrapperConfig } from "./generation-wrapper.service";
|
|
15
|
+
export {
|
|
16
|
+
executeImageFeature,
|
|
17
|
+
hasImageFeatureSupport,
|
|
18
|
+
} from "./image-feature-executor.service";
|
|
19
|
+
export type {
|
|
20
|
+
ImageResultExtractor,
|
|
21
|
+
ExecuteImageFeatureOptions,
|
|
22
|
+
ImageFeatureResult,
|
|
23
|
+
ImageFeatureRequest,
|
|
24
|
+
} from "./image-feature-executor.service";
|
|
25
|
+
export {
|
|
26
|
+
executeVideoFeature,
|
|
27
|
+
hasVideoFeatureSupport,
|
|
28
|
+
} from "./video-feature-executor.service";
|
|
29
|
+
export type {
|
|
30
|
+
VideoResultExtractor,
|
|
31
|
+
ExecuteVideoFeatureOptions,
|
|
32
|
+
VideoFeatureResult,
|
|
33
|
+
VideoFeatureRequest,
|
|
34
|
+
} from "./video-feature-executor.service";
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video Feature Executor
|
|
3
|
+
* Single entry point for all video feature executions
|
|
4
|
+
* Output: video URL
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { providerRegistry } from "./provider-registry.service";
|
|
8
|
+
import { cleanBase64 } from "../utils";
|
|
9
|
+
import type { VideoFeatureType, VideoFeatureInputData } from "../../domain/interfaces";
|
|
10
|
+
|
|
11
|
+
declare const __DEV__: boolean;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Result extractor function type
|
|
15
|
+
*/
|
|
16
|
+
export type VideoResultExtractor = (result: unknown) => string | undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Execution options
|
|
20
|
+
*/
|
|
21
|
+
export interface ExecuteVideoFeatureOptions {
|
|
22
|
+
extractResult?: VideoResultExtractor;
|
|
23
|
+
onProgress?: (progress: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Execution result
|
|
28
|
+
*/
|
|
29
|
+
export interface VideoFeatureResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
videoUrl?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
requestId?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Request data for video features
|
|
38
|
+
*/
|
|
39
|
+
export interface VideoFeatureRequest {
|
|
40
|
+
sourceImageBase64: string;
|
|
41
|
+
targetImageBase64: string;
|
|
42
|
+
prompt?: string;
|
|
43
|
+
options?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Default result extractor - handles common response formats
|
|
48
|
+
*/
|
|
49
|
+
function defaultExtractVideoResult(result: unknown): string | undefined {
|
|
50
|
+
if (typeof result !== "object" || result === null) return undefined;
|
|
51
|
+
|
|
52
|
+
const r = result as Record<string, unknown>;
|
|
53
|
+
|
|
54
|
+
if (typeof r.video === "string") return r.video;
|
|
55
|
+
if (typeof r.videoUrl === "string") return r.videoUrl;
|
|
56
|
+
if (typeof r.video_url === "string") return r.video_url;
|
|
57
|
+
if (typeof r.output === "string") return r.output;
|
|
58
|
+
if (typeof r.url === "string") return r.url;
|
|
59
|
+
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Execute any video feature using the active provider
|
|
65
|
+
*/
|
|
66
|
+
export async function executeVideoFeature(
|
|
67
|
+
featureType: VideoFeatureType,
|
|
68
|
+
request: VideoFeatureRequest,
|
|
69
|
+
options?: ExecuteVideoFeatureOptions,
|
|
70
|
+
): Promise<VideoFeatureResult> {
|
|
71
|
+
const provider = providerRegistry.getActiveProvider();
|
|
72
|
+
|
|
73
|
+
if (!provider) {
|
|
74
|
+
return { success: false, error: "No AI provider configured" };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!provider.isInitialized()) {
|
|
78
|
+
return { success: false, error: "AI provider not initialized" };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const { extractResult, onProgress } = options ?? {};
|
|
82
|
+
|
|
83
|
+
const model = provider.getVideoFeatureModel(featureType);
|
|
84
|
+
|
|
85
|
+
if (__DEV__) {
|
|
86
|
+
// eslint-disable-next-line no-console
|
|
87
|
+
console.log(`[Video:${featureType}] Provider: ${provider.providerId}, Model: ${model}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
onProgress?.(10);
|
|
92
|
+
|
|
93
|
+
const inputData: VideoFeatureInputData = {
|
|
94
|
+
sourceImageBase64: cleanBase64(request.sourceImageBase64),
|
|
95
|
+
targetImageBase64: cleanBase64(request.targetImageBase64),
|
|
96
|
+
prompt: request.prompt,
|
|
97
|
+
options: request.options,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
onProgress?.(30);
|
|
101
|
+
|
|
102
|
+
const input = provider.buildVideoFeatureInput(featureType, inputData);
|
|
103
|
+
|
|
104
|
+
onProgress?.(40);
|
|
105
|
+
|
|
106
|
+
const result = await provider.run(model, input);
|
|
107
|
+
|
|
108
|
+
onProgress?.(90);
|
|
109
|
+
|
|
110
|
+
const extractor = extractResult ?? defaultExtractVideoResult;
|
|
111
|
+
const videoUrl = extractor(result);
|
|
112
|
+
|
|
113
|
+
onProgress?.(100);
|
|
114
|
+
|
|
115
|
+
if (!videoUrl) {
|
|
116
|
+
return { success: false, error: "No video in response" };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
videoUrl,
|
|
122
|
+
requestId: (result as { requestId?: string })?.requestId,
|
|
123
|
+
};
|
|
124
|
+
} catch (error) {
|
|
125
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
126
|
+
if (__DEV__) {
|
|
127
|
+
// eslint-disable-next-line no-console
|
|
128
|
+
console.error(`[Video:${featureType}] Error:`, message);
|
|
129
|
+
}
|
|
130
|
+
return { success: false, error: message };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Check if video features are supported
|
|
136
|
+
*/
|
|
137
|
+
export function hasVideoFeatureSupport(): boolean {
|
|
138
|
+
const provider = providerRegistry.getActiveProvider();
|
|
139
|
+
return provider !== null && provider.isInitialized();
|
|
140
|
+
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI Hug Executor
|
|
3
|
-
* Provider-agnostic AI hug 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
|
-
AIHugRequest,
|
|
11
|
-
AIHugResult,
|
|
12
|
-
AIHugInputBuilder,
|
|
13
|
-
AIHugResultExtractor,
|
|
14
|
-
} from "../../domain/types";
|
|
15
|
-
|
|
16
|
-
declare const __DEV__: boolean;
|
|
17
|
-
|
|
18
|
-
export interface ExecuteAIHugOptions {
|
|
19
|
-
model: string;
|
|
20
|
-
buildInput: AIHugInputBuilder;
|
|
21
|
-
extractResult?: AIHugResultExtractor;
|
|
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 executeAIHug(
|
|
37
|
-
request: AIHugRequest,
|
|
38
|
-
options: ExecuteAIHugOptions,
|
|
39
|
-
): Promise<AIHugResult> {
|
|
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.sourceImageBase64 || !request.targetImageBase64) {
|
|
51
|
-
return { success: false, error: "Both source and target image base64 are required" };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { model, buildInput, extractResult, onProgress } = options;
|
|
55
|
-
|
|
56
|
-
if (__DEV__) {
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.log(`[AIHug] Provider: ${provider.providerId}, Model: ${model}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
onProgress?.(10);
|
|
63
|
-
|
|
64
|
-
const sourceBase64 = cleanBase64(request.sourceImageBase64);
|
|
65
|
-
const targetBase64 = cleanBase64(request.targetImageBase64);
|
|
66
|
-
onProgress?.(30);
|
|
67
|
-
|
|
68
|
-
const input = buildInput(sourceBase64, targetBase64, request.options);
|
|
69
|
-
onProgress?.(40);
|
|
70
|
-
|
|
71
|
-
const result = await provider.run(model, input);
|
|
72
|
-
onProgress?.(90);
|
|
73
|
-
|
|
74
|
-
const extractor = extractResult || defaultExtractResult;
|
|
75
|
-
const imageUrl = extractor(result);
|
|
76
|
-
onProgress?.(100);
|
|
77
|
-
|
|
78
|
-
if (!imageUrl) {
|
|
79
|
-
return { success: false, error: "No image in response" };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return { success: true, imageUrl };
|
|
83
|
-
} catch (error) {
|
|
84
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
-
if (__DEV__) {
|
|
86
|
-
// eslint-disable-next-line no-console
|
|
87
|
-
console.error("[AIHug] Error:", message);
|
|
88
|
-
}
|
|
89
|
-
return { success: false, error: message };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function hasAIHugSupport(): boolean {
|
|
94
|
-
const provider = providerRegistry.getActiveProvider();
|
|
95
|
-
return provider !== null && provider.isInitialized();
|
|
96
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI Kiss Executor
|
|
3
|
-
* Provider-agnostic AI kiss 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
|
-
AIKissRequest,
|
|
11
|
-
AIKissResult,
|
|
12
|
-
AIKissInputBuilder,
|
|
13
|
-
AIKissResultExtractor,
|
|
14
|
-
} from "../../domain/types";
|
|
15
|
-
|
|
16
|
-
declare const __DEV__: boolean;
|
|
17
|
-
|
|
18
|
-
export interface ExecuteAIKissOptions {
|
|
19
|
-
model: string;
|
|
20
|
-
buildInput: AIKissInputBuilder;
|
|
21
|
-
extractResult?: AIKissResultExtractor;
|
|
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 executeAIKiss(
|
|
37
|
-
request: AIKissRequest,
|
|
38
|
-
options: ExecuteAIKissOptions,
|
|
39
|
-
): Promise<AIKissResult> {
|
|
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.sourceImageBase64 || !request.targetImageBase64) {
|
|
51
|
-
return { success: false, error: "Both source and target image base64 are required" };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { model, buildInput, extractResult, onProgress } = options;
|
|
55
|
-
|
|
56
|
-
if (__DEV__) {
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.log(`[AIKiss] Provider: ${provider.providerId}, Model: ${model}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
onProgress?.(10);
|
|
63
|
-
|
|
64
|
-
const sourceBase64 = cleanBase64(request.sourceImageBase64);
|
|
65
|
-
const targetBase64 = cleanBase64(request.targetImageBase64);
|
|
66
|
-
onProgress?.(30);
|
|
67
|
-
|
|
68
|
-
const input = buildInput(sourceBase64, targetBase64, request.options);
|
|
69
|
-
onProgress?.(40);
|
|
70
|
-
|
|
71
|
-
const result = await provider.run(model, input);
|
|
72
|
-
onProgress?.(90);
|
|
73
|
-
|
|
74
|
-
const extractor = extractResult || defaultExtractResult;
|
|
75
|
-
const imageUrl = extractor(result);
|
|
76
|
-
onProgress?.(100);
|
|
77
|
-
|
|
78
|
-
if (!imageUrl) {
|
|
79
|
-
return { success: false, error: "No image in response" };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return { success: true, imageUrl };
|
|
83
|
-
} catch (error) {
|
|
84
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
-
if (__DEV__) {
|
|
86
|
-
// eslint-disable-next-line no-console
|
|
87
|
-
console.error("[AIKiss] Error:", message);
|
|
88
|
-
}
|
|
89
|
-
return { success: false, error: message };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function hasAIKissSupport(): boolean {
|
|
94
|
-
const provider = providerRegistry.getActiveProvider();
|
|
95
|
-
return provider !== null && provider.isInitialized();
|
|
96
|
-
}
|