@umituz/react-native-ai-generation-content 1.26.38 → 1.26.40
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/domains/generation/wizard/infrastructure/strategies/image-generation.strategy.ts +11 -11
- package/src/domains/generation/wizard/infrastructure/strategies/index.ts +1 -1
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +13 -13
- package/src/domains/generation/wizard/infrastructure/strategies/wizard-strategy.factory.ts +8 -21
- package/src/domains/generation/wizard/infrastructure/strategies/wizard-strategy.types.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-generation-content",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.40",
|
|
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",
|
package/src/domains/generation/wizard/infrastructure/strategies/image-generation.strategy.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { readFileAsBase64 } from "@umituz/react-native-design-system";
|
|
7
|
-
import type { GenerationStrategy } from "../../../../../presentation/hooks/generation/types";
|
|
8
7
|
import { createCreationsRepository } from "../../../../creations/infrastructure/adapters";
|
|
9
8
|
import type { WizardScenarioData } from "../../presentation/hooks/useWizardGeneration";
|
|
9
|
+
import type { WizardStrategy } from "./wizard-strategy.types";
|
|
10
10
|
import {
|
|
11
11
|
GENERATION_TIMEOUT_MS,
|
|
12
12
|
BASE64_IMAGE_PREFIX,
|
|
@@ -167,23 +167,22 @@ export interface CreateImageStrategyOptions {
|
|
|
167
167
|
readonly collectionName?: string;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
export function createImageStrategy(
|
|
171
|
-
options: CreateImageStrategyOptions,
|
|
172
|
-
): GenerationStrategy<ImageGenerationInput, ImageGenerationResult> {
|
|
170
|
+
export function createImageStrategy(options: CreateImageStrategyOptions): WizardStrategy {
|
|
173
171
|
const { scenario, collectionName = "creations" } = options;
|
|
174
172
|
const repository = createCreationsRepository(collectionName);
|
|
175
173
|
|
|
176
174
|
let lastInputRef: ImageGenerationInput | null = null;
|
|
177
175
|
|
|
178
176
|
return {
|
|
179
|
-
execute: async (input, onProgress) => {
|
|
177
|
+
execute: async (input: unknown, onProgress) => {
|
|
178
|
+
const imageInput = input as ImageGenerationInput;
|
|
180
179
|
if (!scenario.model) {
|
|
181
180
|
throw new Error("Model is required for image generation");
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
lastInputRef =
|
|
183
|
+
lastInputRef = imageInput;
|
|
185
184
|
|
|
186
|
-
const result = await executeImageGeneration(
|
|
185
|
+
const result = await executeImageGeneration(imageInput, scenario.model, onProgress);
|
|
187
186
|
|
|
188
187
|
if (!result.success || !result.imageUrl) {
|
|
189
188
|
throw new Error(result.error || "Image generation failed");
|
|
@@ -194,13 +193,14 @@ export function createImageStrategy(
|
|
|
194
193
|
|
|
195
194
|
getCreditCost: () => 1,
|
|
196
195
|
|
|
197
|
-
save: async (result, uid) => {
|
|
196
|
+
save: async (result: unknown, uid) => {
|
|
198
197
|
const input = lastInputRef;
|
|
199
|
-
|
|
198
|
+
const imageResult = result as { imageUrl?: string };
|
|
199
|
+
if (!input || !scenario?.id || !imageResult.imageUrl) return;
|
|
200
200
|
|
|
201
201
|
const creation = {
|
|
202
202
|
id: `${scenario.id}_${Date.now()}`,
|
|
203
|
-
uri:
|
|
203
|
+
uri: imageResult.imageUrl,
|
|
204
204
|
type: scenario.id,
|
|
205
205
|
prompt: input.prompt,
|
|
206
206
|
createdAt: new Date(),
|
|
@@ -210,7 +210,7 @@ export function createImageStrategy(
|
|
|
210
210
|
scenarioId: scenario.id,
|
|
211
211
|
scenarioTitle: scenario.title || scenario.id,
|
|
212
212
|
},
|
|
213
|
-
output: { imageUrl:
|
|
213
|
+
output: { imageUrl: imageResult.imageUrl },
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
await repository.create(uid, creation);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createWizardStrategy, buildWizardInput } from './wizard-strategy.factory';
|
|
2
|
-
export type { CreateWizardStrategyOptions } from './wizard-strategy.factory';
|
|
2
|
+
export type { CreateWizardStrategyOptions, WizardStrategy } from './wizard-strategy.factory';
|
package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { readFileAsBase64 } from "@umituz/react-native-design-system";
|
|
7
|
-
import type { GenerationStrategy } from "../../../../../presentation/hooks/generation/types";
|
|
8
7
|
import type { VideoFeatureType } from "../../../../../domain/interfaces";
|
|
9
8
|
import { executeVideoFeature } from "../../../../../infrastructure/services/video-feature-executor.service";
|
|
10
9
|
import { createCreationsRepository } from "../../../../creations/infrastructure/adapters";
|
|
11
10
|
import type { WizardScenarioData } from "../../presentation/hooks/useWizardGeneration";
|
|
11
|
+
import type { WizardStrategy } from "./wizard-strategy.types";
|
|
12
12
|
import { PHOTO_KEY_PREFIX, VIDEO_FEATURE_PATTERNS } from "./wizard-strategy.constants";
|
|
13
13
|
|
|
14
14
|
declare const __DEV__: boolean;
|
|
@@ -105,9 +105,7 @@ export interface CreateVideoStrategyOptions {
|
|
|
105
105
|
readonly collectionName?: string;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export function createVideoStrategy(
|
|
109
|
-
options: CreateVideoStrategyOptions,
|
|
110
|
-
): GenerationStrategy<VideoGenerationInput, VideoGenerationResult> {
|
|
108
|
+
export function createVideoStrategy(options: CreateVideoStrategyOptions): WizardStrategy {
|
|
111
109
|
const { scenario, collectionName = "creations" } = options;
|
|
112
110
|
const repository = createCreationsRepository(collectionName);
|
|
113
111
|
const videoFeatureType = getVideoFeatureType(scenario.id);
|
|
@@ -115,15 +113,16 @@ export function createVideoStrategy(
|
|
|
115
113
|
let lastInputRef: VideoGenerationInput | null = null;
|
|
116
114
|
|
|
117
115
|
return {
|
|
118
|
-
execute: async (input, onProgress) => {
|
|
119
|
-
|
|
116
|
+
execute: async (input: unknown, onProgress) => {
|
|
117
|
+
const videoInput = input as VideoGenerationInput;
|
|
118
|
+
lastInputRef = videoInput;
|
|
120
119
|
|
|
121
120
|
const result = await executeVideoFeature(
|
|
122
121
|
videoFeatureType,
|
|
123
122
|
{
|
|
124
|
-
sourceImageBase64:
|
|
125
|
-
targetImageBase64:
|
|
126
|
-
prompt:
|
|
123
|
+
sourceImageBase64: videoInput.sourceImageBase64,
|
|
124
|
+
targetImageBase64: videoInput.targetImageBase64,
|
|
125
|
+
prompt: videoInput.prompt,
|
|
127
126
|
},
|
|
128
127
|
{ onProgress },
|
|
129
128
|
);
|
|
@@ -137,13 +136,14 @@ export function createVideoStrategy(
|
|
|
137
136
|
|
|
138
137
|
getCreditCost: () => 1,
|
|
139
138
|
|
|
140
|
-
save: async (result, uid) => {
|
|
139
|
+
save: async (result: unknown, uid) => {
|
|
141
140
|
const input = lastInputRef;
|
|
142
|
-
|
|
141
|
+
const videoResult = result as { videoUrl?: string };
|
|
142
|
+
if (!input || !scenario?.id || !videoResult.videoUrl) return;
|
|
143
143
|
|
|
144
144
|
const creation = {
|
|
145
145
|
id: `${scenario.id}_${Date.now()}`,
|
|
146
|
-
uri:
|
|
146
|
+
uri: videoResult.videoUrl,
|
|
147
147
|
type: scenario.id,
|
|
148
148
|
prompt: input.prompt,
|
|
149
149
|
createdAt: new Date(),
|
|
@@ -153,7 +153,7 @@ export function createVideoStrategy(
|
|
|
153
153
|
scenarioId: scenario.id,
|
|
154
154
|
scenarioTitle: scenario.title || scenario.id,
|
|
155
155
|
},
|
|
156
|
-
output: { videoUrl:
|
|
156
|
+
output: { videoUrl: videoResult.videoUrl },
|
|
157
157
|
};
|
|
158
158
|
|
|
159
159
|
await repository.create(uid, creation);
|
|
@@ -4,27 +4,16 @@
|
|
|
4
4
|
* Single Responsibility: Only dispatches, doesn't contain business logic
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { GenerationStrategy } from "../../../../../presentation/hooks/generation/types";
|
|
8
7
|
import type { WizardScenarioData } from "../../presentation/hooks/useWizardGeneration";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type ImageGenerationInput,
|
|
13
|
-
type ImageGenerationResult,
|
|
14
|
-
} from "./image-generation.strategy";
|
|
15
|
-
import {
|
|
16
|
-
createVideoStrategy,
|
|
17
|
-
buildVideoInput,
|
|
18
|
-
type VideoGenerationInput,
|
|
19
|
-
type VideoGenerationResult,
|
|
20
|
-
} from "./video-generation.strategy";
|
|
8
|
+
import type { WizardStrategy } from "./wizard-strategy.types";
|
|
9
|
+
import { createImageStrategy, buildImageInput } from "./image-generation.strategy";
|
|
10
|
+
import { createVideoStrategy, buildVideoInput } from "./video-generation.strategy";
|
|
21
11
|
|
|
22
12
|
// ============================================================================
|
|
23
13
|
// Types
|
|
24
14
|
// ============================================================================
|
|
25
15
|
|
|
26
|
-
type
|
|
27
|
-
type WizardGenerationResult = ImageGenerationResult | VideoGenerationResult;
|
|
16
|
+
export type { WizardStrategy } from "./wizard-strategy.types";
|
|
28
17
|
|
|
29
18
|
export interface CreateWizardStrategyOptions {
|
|
30
19
|
readonly scenario: WizardScenarioData;
|
|
@@ -36,17 +25,15 @@ export interface CreateWizardStrategyOptions {
|
|
|
36
25
|
// Strategy Factory
|
|
37
26
|
// ============================================================================
|
|
38
27
|
|
|
39
|
-
export function createWizardStrategy(
|
|
40
|
-
options: CreateWizardStrategyOptions,
|
|
41
|
-
): GenerationStrategy<WizardGenerationInput, WizardGenerationResult> {
|
|
28
|
+
export function createWizardStrategy(options: CreateWizardStrategyOptions): WizardStrategy {
|
|
42
29
|
const { scenario, collectionName } = options;
|
|
43
30
|
const outputType = scenario.outputType || "video";
|
|
44
31
|
|
|
45
32
|
if (outputType === "image") {
|
|
46
|
-
return createImageStrategy({ scenario, collectionName })
|
|
33
|
+
return createImageStrategy({ scenario, collectionName });
|
|
47
34
|
}
|
|
48
35
|
|
|
49
|
-
return createVideoStrategy({ scenario, collectionName })
|
|
36
|
+
return createVideoStrategy({ scenario, collectionName });
|
|
50
37
|
}
|
|
51
38
|
|
|
52
39
|
// ============================================================================
|
|
@@ -56,7 +43,7 @@ export function createWizardStrategy(
|
|
|
56
43
|
export async function buildWizardInput(
|
|
57
44
|
wizardData: Record<string, unknown>,
|
|
58
45
|
scenario: WizardScenarioData,
|
|
59
|
-
): Promise<
|
|
46
|
+
): Promise<unknown> {
|
|
60
47
|
const outputType = scenario.outputType || "video";
|
|
61
48
|
|
|
62
49
|
if (outputType === "image") {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wizard Strategy Types
|
|
3
|
+
* Shared types for all wizard strategies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface WizardStrategy {
|
|
7
|
+
execute: (
|
|
8
|
+
input: unknown,
|
|
9
|
+
onProgress?: (progress: number) => void,
|
|
10
|
+
) => Promise<{ imageUrl?: string; videoUrl?: string }>;
|
|
11
|
+
getCreditCost: () => number;
|
|
12
|
+
save?: (result: unknown, userId: string) => Promise<void>;
|
|
13
|
+
}
|