@umituz/react-native-ai-generation-content 1.60.0 → 1.61.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,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-generation-content",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.61.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",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.ts",
|
|
9
|
+
"./core": "./src/core/index.ts",
|
|
9
10
|
"./prompts": "./src/domains/prompts/index.ts",
|
|
10
11
|
"./content-moderation": "./src/domains/content-moderation/index.ts",
|
|
11
12
|
"./creations": "./src/domains/creations/index.ts",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @umituz/react-native-ai-generation-content/core
|
|
3
|
+
*
|
|
4
|
+
* Core types for AI generation providers.
|
|
5
|
+
* This module contains ONLY types and utilities - no implementation details.
|
|
6
|
+
*
|
|
7
|
+
* Use this subpath for provider implementations:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type { IAIProvider, AIProviderConfig } from "@umituz/react-native-ai-generation-content/core";
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @module @umituz/react-native-ai-generation-content/core
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Result Pattern
|
|
16
|
+
export type { Result, Success, Failure } from "./types/result.types";
|
|
17
|
+
export {
|
|
18
|
+
success,
|
|
19
|
+
failure,
|
|
20
|
+
isSuccess,
|
|
21
|
+
isFailure,
|
|
22
|
+
mapResult,
|
|
23
|
+
andThen,
|
|
24
|
+
unwrap,
|
|
25
|
+
unwrapOr,
|
|
26
|
+
} from "./types/result.types";
|
|
27
|
+
|
|
28
|
+
// Error Types
|
|
29
|
+
export { AIErrorType } from "./types/error.types";
|
|
30
|
+
export type { AIErrorInfo, AIErrorMessages } from "./types/error.types";
|
|
31
|
+
|
|
32
|
+
// Provider Types
|
|
33
|
+
export type {
|
|
34
|
+
// Feature Types
|
|
35
|
+
ImageFeatureType,
|
|
36
|
+
VideoFeatureType,
|
|
37
|
+
// Config
|
|
38
|
+
AIProviderConfig,
|
|
39
|
+
// Status
|
|
40
|
+
AIJobStatusType,
|
|
41
|
+
AILogEntry,
|
|
42
|
+
JobSubmission,
|
|
43
|
+
JobStatus,
|
|
44
|
+
// Progress
|
|
45
|
+
ProviderProgressInfo,
|
|
46
|
+
SubscribeOptions,
|
|
47
|
+
RunOptions,
|
|
48
|
+
// Capabilities
|
|
49
|
+
ProviderCapabilities,
|
|
50
|
+
// Input Data
|
|
51
|
+
ImageFeatureInputData,
|
|
52
|
+
VideoFeatureInputData,
|
|
53
|
+
// Provider Interfaces
|
|
54
|
+
IAIProviderLifecycle,
|
|
55
|
+
IAIProviderCapabilities,
|
|
56
|
+
IAIProviderJobManager,
|
|
57
|
+
IAIProviderExecutor,
|
|
58
|
+
IAIProviderImageFeatures,
|
|
59
|
+
IAIProviderVideoFeatures,
|
|
60
|
+
IAIProvider,
|
|
61
|
+
} from "./types/provider.types";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Generation Error Types
|
|
3
|
+
* Provider-agnostic error classification
|
|
4
|
+
*
|
|
5
|
+
* @module @umituz/react-native-ai-generation-content/core
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export enum AIErrorType {
|
|
9
|
+
NETWORK = "NETWORK",
|
|
10
|
+
RATE_LIMIT = "RATE_LIMIT",
|
|
11
|
+
AUTHENTICATION = "AUTHENTICATION",
|
|
12
|
+
VALIDATION = "VALIDATION",
|
|
13
|
+
CONTENT_POLICY = "CONTENT_POLICY",
|
|
14
|
+
SERVER = "SERVER",
|
|
15
|
+
TIMEOUT = "TIMEOUT",
|
|
16
|
+
UNKNOWN = "UNKNOWN",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AIErrorInfo {
|
|
20
|
+
type: AIErrorType;
|
|
21
|
+
messageKey: string;
|
|
22
|
+
retryable: boolean;
|
|
23
|
+
originalError?: unknown;
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AIErrorMessages {
|
|
28
|
+
[AIErrorType.NETWORK]: string;
|
|
29
|
+
[AIErrorType.RATE_LIMIT]: string;
|
|
30
|
+
[AIErrorType.AUTHENTICATION]: string;
|
|
31
|
+
[AIErrorType.VALIDATION]: string;
|
|
32
|
+
[AIErrorType.CONTENT_POLICY]: string;
|
|
33
|
+
[AIErrorType.SERVER]: string;
|
|
34
|
+
[AIErrorType.TIMEOUT]: string;
|
|
35
|
+
[AIErrorType.UNKNOWN]: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider Types
|
|
3
|
+
* Core interfaces for AI generation providers
|
|
4
|
+
*
|
|
5
|
+
* @module @umituz/react-native-ai-generation-content/core
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Feature Types
|
|
10
|
+
// =============================================================================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Feature types for image processing (output: image)
|
|
14
|
+
*/
|
|
15
|
+
export type ImageFeatureType =
|
|
16
|
+
| "upscale"
|
|
17
|
+
| "photo-restore"
|
|
18
|
+
| "face-swap"
|
|
19
|
+
| "anime-selfie"
|
|
20
|
+
| "remove-background"
|
|
21
|
+
| "remove-object"
|
|
22
|
+
| "hd-touch-up"
|
|
23
|
+
| "replace-background";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Feature types for video generation (output: video)
|
|
27
|
+
*/
|
|
28
|
+
export type VideoFeatureType = "image-to-video" | "text-to-video";
|
|
29
|
+
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// Provider Configuration
|
|
32
|
+
// =============================================================================
|
|
33
|
+
|
|
34
|
+
export interface AIProviderConfig {
|
|
35
|
+
apiKey: string;
|
|
36
|
+
maxRetries?: number;
|
|
37
|
+
baseDelay?: number;
|
|
38
|
+
maxDelay?: number;
|
|
39
|
+
defaultTimeoutMs?: number;
|
|
40
|
+
textModel?: string;
|
|
41
|
+
textToImageModel?: string;
|
|
42
|
+
imageEditModel?: string;
|
|
43
|
+
videoGenerationModel?: string;
|
|
44
|
+
videoFeatureModels?: Partial<Record<VideoFeatureType, string>>;
|
|
45
|
+
imageFeatureModels?: Partial<Record<ImageFeatureType, string>>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// Status Types
|
|
50
|
+
// =============================================================================
|
|
51
|
+
|
|
52
|
+
export type AIJobStatusType =
|
|
53
|
+
| "IN_QUEUE"
|
|
54
|
+
| "IN_PROGRESS"
|
|
55
|
+
| "COMPLETED"
|
|
56
|
+
| "FAILED";
|
|
57
|
+
|
|
58
|
+
export interface AILogEntry {
|
|
59
|
+
message: string;
|
|
60
|
+
level: "info" | "warn" | "error";
|
|
61
|
+
timestamp?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface JobSubmission {
|
|
65
|
+
requestId: string;
|
|
66
|
+
statusUrl?: string;
|
|
67
|
+
responseUrl?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface JobStatus {
|
|
71
|
+
status: AIJobStatusType;
|
|
72
|
+
logs?: AILogEntry[];
|
|
73
|
+
queuePosition?: number;
|
|
74
|
+
eta?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// =============================================================================
|
|
78
|
+
// Progress & Options
|
|
79
|
+
// =============================================================================
|
|
80
|
+
|
|
81
|
+
export interface ProviderProgressInfo {
|
|
82
|
+
progress: number;
|
|
83
|
+
status?: AIJobStatusType;
|
|
84
|
+
message?: string;
|
|
85
|
+
estimatedTimeRemaining?: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SubscribeOptions<T = unknown> {
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
onQueueUpdate?: (status: JobStatus) => void;
|
|
91
|
+
onProgress?: (progress: ProviderProgressInfo) => void;
|
|
92
|
+
onResult?: (result: T) => void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface RunOptions {
|
|
96
|
+
onProgress?: (progress: ProviderProgressInfo) => void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// =============================================================================
|
|
100
|
+
// Capabilities
|
|
101
|
+
// =============================================================================
|
|
102
|
+
|
|
103
|
+
export interface ProviderCapabilities {
|
|
104
|
+
imageFeatures: readonly ImageFeatureType[];
|
|
105
|
+
videoFeatures: readonly VideoFeatureType[];
|
|
106
|
+
textToImage: boolean;
|
|
107
|
+
textToVideo: boolean;
|
|
108
|
+
imageToVideo: boolean;
|
|
109
|
+
textToVoice: boolean;
|
|
110
|
+
textToText: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// =============================================================================
|
|
114
|
+
// Feature Input Data
|
|
115
|
+
// =============================================================================
|
|
116
|
+
|
|
117
|
+
export interface ImageFeatureInputData {
|
|
118
|
+
imageBase64: string;
|
|
119
|
+
targetImageBase64?: string;
|
|
120
|
+
prompt?: string;
|
|
121
|
+
options?: Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface VideoFeatureInputData {
|
|
125
|
+
sourceImageBase64?: string;
|
|
126
|
+
targetImageBase64?: string;
|
|
127
|
+
prompt?: string;
|
|
128
|
+
options?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Provider Sub-Interfaces (Interface Segregation Principle)
|
|
133
|
+
// =============================================================================
|
|
134
|
+
|
|
135
|
+
export interface IAIProviderLifecycle {
|
|
136
|
+
initialize(config: AIProviderConfig): void;
|
|
137
|
+
isInitialized(): boolean;
|
|
138
|
+
reset(): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface IAIProviderCapabilities {
|
|
142
|
+
getCapabilities(): ProviderCapabilities;
|
|
143
|
+
isFeatureSupported(feature: ImageFeatureType | VideoFeatureType): boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface IAIProviderJobManager {
|
|
147
|
+
submitJob(
|
|
148
|
+
model: string,
|
|
149
|
+
input: Record<string, unknown>,
|
|
150
|
+
): Promise<JobSubmission>;
|
|
151
|
+
getJobStatus(model: string, requestId: string): Promise<JobStatus>;
|
|
152
|
+
getJobResult<T = unknown>(model: string, requestId: string): Promise<T>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface IAIProviderExecutor {
|
|
156
|
+
subscribe<T = unknown>(
|
|
157
|
+
model: string,
|
|
158
|
+
input: Record<string, unknown>,
|
|
159
|
+
options?: SubscribeOptions<T>,
|
|
160
|
+
): Promise<T>;
|
|
161
|
+
run<T = unknown>(
|
|
162
|
+
model: string,
|
|
163
|
+
input: Record<string, unknown>,
|
|
164
|
+
options?: RunOptions,
|
|
165
|
+
): Promise<T>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface IAIProviderImageFeatures {
|
|
169
|
+
getImageFeatureModel(feature: ImageFeatureType): string;
|
|
170
|
+
buildImageFeatureInput(
|
|
171
|
+
feature: ImageFeatureType,
|
|
172
|
+
data: ImageFeatureInputData,
|
|
173
|
+
): Record<string, unknown>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface IAIProviderVideoFeatures {
|
|
177
|
+
getVideoFeatureModel(feature: VideoFeatureType): string;
|
|
178
|
+
buildVideoFeatureInput(
|
|
179
|
+
feature: VideoFeatureType,
|
|
180
|
+
data: VideoFeatureInputData,
|
|
181
|
+
): Record<string, unknown>;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// =============================================================================
|
|
185
|
+
// Main Provider Interface
|
|
186
|
+
// =============================================================================
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Main AI Provider Interface
|
|
190
|
+
* Composition of segregated interfaces following SOLID principles
|
|
191
|
+
*/
|
|
192
|
+
export interface IAIProvider
|
|
193
|
+
extends IAIProviderLifecycle,
|
|
194
|
+
IAIProviderCapabilities,
|
|
195
|
+
IAIProviderJobManager,
|
|
196
|
+
IAIProviderExecutor,
|
|
197
|
+
IAIProviderImageFeatures,
|
|
198
|
+
IAIProviderVideoFeatures {
|
|
199
|
+
readonly providerId: string;
|
|
200
|
+
readonly providerName: string;
|
|
201
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Type Pattern for Functional Error Handling
|
|
3
|
+
* Inspired by Rust's Result<T, E> type
|
|
4
|
+
*
|
|
5
|
+
* @module @umituz/react-native-ai-generation-content/core
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Success result containing a value of type T
|
|
10
|
+
*/
|
|
11
|
+
export interface Success<T> {
|
|
12
|
+
success: true;
|
|
13
|
+
value: T;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Failure result containing an error of type E
|
|
18
|
+
*/
|
|
19
|
+
export interface Failure<E> {
|
|
20
|
+
success: false;
|
|
21
|
+
error: E;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Result type that can be either Success or Failure
|
|
26
|
+
* Forces explicit error handling at compile time
|
|
27
|
+
*/
|
|
28
|
+
export type Result<T, E = string> = Success<T> | Failure<E>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a successful result
|
|
32
|
+
*/
|
|
33
|
+
export function success<T>(value: T): Success<T> {
|
|
34
|
+
return { success: true, value };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a failed result
|
|
39
|
+
*/
|
|
40
|
+
export function failure<E>(error: E): Failure<E> {
|
|
41
|
+
return { success: false, error };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Type guard to check if result is successful
|
|
46
|
+
*/
|
|
47
|
+
export function isSuccess<T, E>(result: Result<T, E>): result is Success<T> {
|
|
48
|
+
return result.success === true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type guard to check if result is a failure
|
|
53
|
+
*/
|
|
54
|
+
export function isFailure<T, E>(result: Result<T, E>): result is Failure<E> {
|
|
55
|
+
return result.success === false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Map a successful result to a new value
|
|
60
|
+
*/
|
|
61
|
+
export function mapResult<T, U, E>(
|
|
62
|
+
result: Result<T, E>,
|
|
63
|
+
fn: (value: T) => U,
|
|
64
|
+
): Result<U, E> {
|
|
65
|
+
if (isSuccess(result)) {
|
|
66
|
+
return success(fn(result.value));
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Chain async operations on Result types
|
|
73
|
+
*/
|
|
74
|
+
export async function andThen<T, U, E>(
|
|
75
|
+
result: Result<T, E>,
|
|
76
|
+
fn: (value: T) => Promise<Result<U, E>>,
|
|
77
|
+
): Promise<Result<U, E>> {
|
|
78
|
+
if (isSuccess(result)) {
|
|
79
|
+
return fn(result.value);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Unwrap a result, throwing if it's a failure
|
|
86
|
+
*/
|
|
87
|
+
export function unwrap<T, E>(result: Result<T, E>): T {
|
|
88
|
+
if (isSuccess(result)) {
|
|
89
|
+
return result.value;
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Called unwrap on a failure: ${String(result.error)}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Unwrap a result or return a default value
|
|
96
|
+
*/
|
|
97
|
+
export function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {
|
|
98
|
+
if (isSuccess(result)) {
|
|
99
|
+
return result.value;
|
|
100
|
+
}
|
|
101
|
+
return defaultValue;
|
|
102
|
+
}
|