@umituz/react-native-ai-generation-content 1.26.29 → 1.26.31

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.
@@ -1,36 +0,0 @@
1
- /**
2
- * Progress Constants
3
- * Standardized progress values for generation pipelines
4
- */
5
-
6
- /** Image generation progress stages */
7
- export const IMAGE_PROGRESS = {
8
- START: 10,
9
- INPUT_PREPARED: 30,
10
- REQUEST_SENT: 40,
11
- RESULT_RECEIVED: 90,
12
- COMPLETE: 100,
13
- } as const;
14
-
15
- /** Video generation progress stages */
16
- export const VIDEO_PROGRESS = {
17
- START: 5,
18
- INPUT_PREPARED: 10,
19
- REQUEST_SENT: 15,
20
- IN_QUEUE: 20,
21
- IN_PROGRESS: 50,
22
- RESULT_RECEIVED: 90,
23
- COMPLETE: 100,
24
- } as const;
25
-
26
- /** Polling progress stages */
27
- export const POLLING_PROGRESS = {
28
- RESULT_RECEIVED: 90,
29
- COMPLETE: 100,
30
- } as const;
31
-
32
- /** Video generation timeout in milliseconds (5 minutes) */
33
- export const VIDEO_TIMEOUT_MS = 300000;
34
-
35
- /** Maximum consecutive transient errors before failing */
36
- export const MAX_TRANSIENT_ERRORS = 5;
@@ -1,148 +0,0 @@
1
- /**
2
- * Generation Wrapper Service
3
- * Wraps orchestrator with middleware support
4
- * Enables credit checking, moderation, history via middleware pattern
5
- */
6
-
7
- import type {
8
- GenerationRequest,
9
- GenerationResult,
10
- GenerationMiddleware,
11
- MiddlewareContext,
12
- MiddlewareResultContext,
13
- } from "../../domain/entities";
14
- import { generationOrchestrator } from "./generation-orchestrator.service";
15
- import type { OrchestratorConfig } from "./generation-orchestrator.service";
16
-
17
- export interface WrapperConfig {
18
- /** Middleware to execute before/after generation */
19
- middleware?: GenerationMiddleware[];
20
- /** Orchestrator configuration */
21
- orchestratorConfig?: OrchestratorConfig;
22
- }
23
-
24
- class GenerationWrapperService {
25
- private middleware: GenerationMiddleware[] = [];
26
- private orchestratorConfig?: OrchestratorConfig;
27
-
28
- /**
29
- * Configure wrapper with middleware
30
- */
31
- configure(config: WrapperConfig): void {
32
- this.middleware = config.middleware || [];
33
- this.orchestratorConfig = config.orchestratorConfig;
34
-
35
- if (this.orchestratorConfig) {
36
- generationOrchestrator.configure(this.orchestratorConfig);
37
- }
38
- }
39
-
40
- /**
41
- * Add middleware to chain
42
- */
43
- use(middleware: GenerationMiddleware): void {
44
- this.middleware.push(middleware);
45
- }
46
-
47
- /**
48
- * Clear all middleware
49
- */
50
- clearMiddleware(): void {
51
- this.middleware = [];
52
- }
53
-
54
- /**
55
- * Generate with middleware support
56
- */
57
- async generate<T = unknown>(
58
- request: GenerationRequest,
59
- userId?: string,
60
- metadata?: Record<string, unknown>,
61
- ): Promise<GenerationResult<T>> {
62
- const startTime = Date.now();
63
-
64
- const context: MiddlewareContext = {
65
- request,
66
- userId,
67
- metadata,
68
- };
69
-
70
- try {
71
- await this.executeBeforeHooks(context);
72
-
73
- const result = await generationOrchestrator.generate<T>(request);
74
-
75
- const resultContext: MiddlewareResultContext<T> = {
76
- ...context,
77
- result,
78
- };
79
-
80
- await this.executeAfterHooks(resultContext);
81
-
82
- return result;
83
- } catch (error) {
84
- const errorResult: GenerationResult<T> = {
85
- success: false,
86
- error: error instanceof Error ? error.message : String(error),
87
- metadata: {
88
- model: request.model || "unknown",
89
- startTime,
90
- endTime: Date.now(),
91
- duration: Date.now() - startTime,
92
- },
93
- };
94
-
95
- const resultContext: MiddlewareResultContext<T> = {
96
- ...context,
97
- result: errorResult,
98
- };
99
-
100
- await this.executeAfterHooks(resultContext).catch(() => {
101
- // Silent fail on afterHooks error
102
- });
103
-
104
- return errorResult;
105
- }
106
- }
107
-
108
- /**
109
- * Execute all beforeGenerate hooks
110
- */
111
- private async executeBeforeHooks(
112
- context: MiddlewareContext,
113
- ): Promise<void> {
114
- for (const mw of this.middleware) {
115
- if (mw.beforeGenerate) {
116
- await mw.beforeGenerate(context);
117
- }
118
- }
119
- }
120
-
121
- /**
122
- * Execute all afterGenerate hooks
123
- */
124
- private async executeAfterHooks<T>(
125
- context: MiddlewareResultContext<T>,
126
- ): Promise<void> {
127
- for (const mw of this.middleware) {
128
- if (mw.afterGenerate) {
129
- await mw.afterGenerate(context);
130
- }
131
- }
132
- }
133
- }
134
-
135
- export const generationWrapper = new GenerationWrapperService();
136
-
137
- /**
138
- * Create new wrapper instance
139
- */
140
- export function createGenerationWrapper(
141
- config?: WrapperConfig,
142
- ): GenerationWrapperService {
143
- const wrapper = new GenerationWrapperService();
144
- if (config) {
145
- wrapper.configure(config);
146
- }
147
- return wrapper;
148
- }
@@ -1,58 +0,0 @@
1
- /**
2
- * Progress Manager
3
- * Handles progress tracking and updates during generation
4
- */
5
-
6
- import type { GenerationProgress, PollingConfig } from "../../domain/entities";
7
- import type { JobStatus } from "../../domain/interfaces";
8
- import { createProgressTracker } from "../utils/progress-calculator.util";
9
-
10
- export class ProgressManager {
11
- private progressTracker = createProgressTracker();
12
-
13
- updateProgress(
14
- stage: GenerationProgress["stage"],
15
- subProgress: number,
16
- onProgress?: (progress: GenerationProgress) => void,
17
- ): void {
18
- const progress = this.progressTracker.setStatus(stage);
19
- onProgress?.({
20
- stage,
21
- progress: progress + subProgress,
22
- });
23
- }
24
-
25
- updateProgressFromStatus(
26
- status: JobStatus,
27
- attempt: number,
28
- config: PollingConfig,
29
- onProgress?: (progress: GenerationProgress) => void,
30
- ): void {
31
- const baseProgress = 25;
32
- const maxProgress = 85;
33
- const range = maxProgress - baseProgress;
34
-
35
- let progress: number;
36
-
37
- if (status.status === "IN_QUEUE") {
38
- progress = baseProgress + range * 0.2;
39
- } else if (status.status === "IN_PROGRESS") {
40
- const ratio = Math.min(attempt / (config.maxAttempts * 0.7), 1);
41
- progress = baseProgress + range * (0.2 + 0.6 * ratio);
42
- } else {
43
- progress = baseProgress;
44
- }
45
-
46
- onProgress?.({
47
- stage: "generating",
48
- progress: Math.round(progress),
49
- eta: status.eta,
50
- });
51
- }
52
-
53
- reset(): void {
54
- this.progressTracker = createProgressTracker();
55
- }
56
- }
57
-
58
- export const progressManager = new ProgressManager();
@@ -1,336 +0,0 @@
1
- # Infrastructure Wrappers
2
-
3
- Wrapper utilities and enhancements for AI generation operations.
4
-
5
- ## Overview
6
-
7
- The wrappers module provides wrapper utilities that add additional functionality to core AI generation operations, such as language enhancement, moderation, and synchronous execution.
8
-
9
- ## Features
10
-
11
- - Language enhancement for prompts
12
- - Content moderation wrapper
13
- - Synchronous generation support
14
- - Prompt augmentation
15
- - Result filtering
16
-
17
- ## Language Enhancement
18
-
19
- ### enhancePromptWithLanguage
20
-
21
- Enhance prompts with language support:
22
-
23
- ```tsx
24
- import { enhancePromptWithLanguage } from '@umituz/react-native-ai-generation-content';
25
-
26
- // Enhance prompt for better results
27
- const enhanced = enhancePromptWithLanguage({
28
- prompt: 'A beautiful sunset',
29
- targetLanguage: 'en', // Translate to English first
30
- enhance: true, // Add descriptive details
31
- });
32
-
33
- console.log('Enhanced prompt:', enhanced);
34
- // "A beautiful sunset over the ocean with vibrant orange and pink colors,
35
- // captured during golden hour with dramatic cloud formations"
36
- ```
37
-
38
- ### getSupportedLanguages
39
-
40
- Get list of supported languages:
41
-
42
- ```tsx
43
- import { getSupportedLanguages } from '@umituz/react-native-ai-generation-content';
44
-
45
- const languages = getSupportedLanguages();
46
- console.log('Supported languages:', languages);
47
- // [
48
- // { code: 'en', name: 'English' },
49
- // { code: 'es', name: 'Spanish' },
50
- // { code: 'fr', name: 'French' },
51
- // ...
52
- // ]
53
- ```
54
-
55
- ### getLanguageName
56
-
57
- Get language name from code:
58
-
59
- ```tsx
60
- import { getLanguageName } from '@umituz/react-native-ai-generation-content';
61
-
62
- const name = getLanguageName('es');
63
- console.log('Language:', name); // "Spanish"
64
- ```
65
-
66
- ## Content Moderation
67
-
68
- ### ModerationWrapper
69
-
70
- Wrap generation with content moderation:
71
-
72
- ```tsx
73
- import { ModerationWrapper } from '@umituz/react-native-ai-generation-content';
74
-
75
- const wrapper = new ModerationWrapper({
76
- enabled: true,
77
- rules: [
78
- {
79
- id: 'no-violence',
80
- category: 'violence',
81
- severity: 'high',
82
- enabled: true,
83
- action: 'block',
84
- },
85
- {
86
- id: 'no-adult',
87
- category: 'sexual',
88
- severity: 'high',
89
- enabled: true,
90
- action: 'block',
91
- },
92
- ],
93
- onViolation: (result) => {
94
- Alert.alert('Content Warning', result.warning, [
95
- { text: 'OK', onPress: () => console.log('Acknowledged') },
96
- ]);
97
- },
98
- });
99
-
100
- // Wrap generation
101
- const wrapped = wrapper.wrap({
102
- type: 'text-to-image',
103
- generate: async (input) => {
104
- return await generateImage(input);
105
- },
106
- });
107
-
108
- // Execute with moderation
109
- const result = await wrapped.generate({
110
- prompt: 'Your prompt here',
111
- });
112
-
113
- if (result.isModerated) {
114
- console.log('Content was moderated');
115
- console.log('Violations:', result.violations);
116
- } else {
117
- console.log('Content is safe:', result.output);
118
- }
119
- ```
120
-
121
- ### Moderation Result
122
-
123
- ```tsx
124
- interface ModerationResult {
125
- isSafe: boolean;
126
- isModerated: boolean;
127
- violations: {
128
- category: string;
129
- severity: 'low' | 'medium' | 'high';
130
- confidence: number;
131
- }[];
132
- warning?: string;
133
- output?: any;
134
- }
135
- ```
136
-
137
- ## Synchronous Generation
138
-
139
- ### generateSynchronously
140
-
141
- Generate content synchronously (blocks until complete):
142
-
143
- ```tsx
144
- import { generateSynchronously } from '@umituz/react-native-ai-generation-content';
145
-
146
- // ⚠️ Warning: This blocks the thread
147
- const result = await generateSynchronously({
148
- featureType: 'text-to-image',
149
- inputData: {
150
- prompt: 'A sunset',
151
- },
152
- userId: 'user-123',
153
- timeout: 30000, // 30 second timeout
154
- });
155
-
156
- console.log('Result:', result);
157
- ```
158
-
159
- **⚠️ Use with caution**: Synchronous generation blocks the UI thread. Only use for:
160
- - Testing
161
- - Very fast operations
162
- - Background workers
163
-
164
- ### SynchronousGenerationConfig
165
-
166
- ```tsx
167
- interface SynchronousGenerationConfig {
168
- featureType: string;
169
- inputData: any;
170
- userId: string;
171
- providerId?: string;
172
- timeout?: number;
173
- onProgress?: (progress: number) => void;
174
- }
175
- ```
176
-
177
- ## Prompt Augmentation
178
-
179
- ### Auto-Enhance Prompts
180
-
181
- Automatically enhance prompts for better results:
182
-
183
- ```tsx
184
- import { ModerationWrapper } from '@umituz/react-native-ai-generation-content';
185
-
186
- const wrapper = new ModerationWrapper({
187
- enabled: true,
188
- autoEnhance: true,
189
- enhancementOptions: {
190
- addDetail: true,
191
- addStyle: true,
192
- improveGrammar: true,
193
- },
194
- });
195
-
196
- const enhanced = await wrapper.enhancePrompt('A cat');
197
- // "A highly detailed, professional photograph of a beautiful cat,
198
- // with perfect lighting and composition, captured with a DSLR camera"
199
- ```
200
-
201
- ### Style Prompts
202
-
203
- Add style to prompts:
204
-
205
- ```tsx
206
- import { enhancePromptWithLanguage } from '@umituz/react-native-ai-generation-content';
207
-
208
- const styled = enhancePromptWithLanguage({
209
- prompt: 'A sunset',
210
- style: 'photorealistic',
211
- quality: 'high',
212
- });
213
-
214
- // "A photorealistic, high-quality image of a sunset over the ocean,
215
- // with dramatic lighting and vivid colors"
216
- ```
217
-
218
- ## Result Filtering
219
-
220
- ### FilterResults
221
-
222
- Filter and clean generation results:
223
-
224
- ```tsx
225
- import { ModerationWrapper } from '@umituz/react-native-ai-generation-content';
226
-
227
- const wrapper = new ModerationWrapper({
228
- enabled: true,
229
- filterResults: true,
230
- filterOptions: {
231
- removeDuplicates: true,
232
- qualityThreshold: 0.7,
233
- maxResults: 4,
234
- },
235
- });
236
-
237
- const filtered = await wrapper.filterResults(results);
238
- ```
239
-
240
- ## Usage Examples
241
-
242
- ### Complete Moderation Setup
243
-
244
- ```tsx
245
- import { ModerationWrapper } from '@umituz/react-native-ai-generation-content';
246
-
247
- const wrapper = new ModerationWrapper({
248
- enabled: true,
249
- autoEnhance: true,
250
- rules: [
251
- {
252
- id: 'safety',
253
- category: 'violence',
254
- severity: 'high',
255
- enabled: true,
256
- action: 'block',
257
- },
258
- ],
259
- onViolation: (result) => {
260
- Alert.alert('Content Warning', result.warning);
261
- },
262
- });
263
-
264
- const generateWithModeration = wrapper.wrap({
265
- type: 'text-to-image',
266
- generate: async (input) => {
267
- return await generateImage(input);
268
- },
269
- });
270
-
271
- // Use wrapped generation
272
- const result = await generateWithModeration({
273
- prompt: userInput,
274
- });
275
-
276
- if (result.isSafe) {
277
- setImage(result.output.imageUrl);
278
- } else {
279
- showWarning(result.violations);
280
- }
281
- ```
282
-
283
- ### Multi-Language Support
284
-
285
- ```tsx
286
- import { enhancePromptWithLanguage } from '@umituz/react-native-ai-generation-content';
287
-
288
- // User enters prompt in Spanish
289
- const userPrompt = 'Un hermoso atardecer';
290
-
291
- // Enhance and translate to English for AI
292
- const enhanced = enhancePromptWithLanguage({
293
- prompt: userPrompt,
294
- targetLanguage: 'en',
295
- enhance: true,
296
- });
297
-
298
- // Use enhanced prompt for generation
299
- const result = await generateImage({
300
- prompt: enhanced,
301
- });
302
- ```
303
-
304
- ## Best Practices
305
-
306
- 1. **Moderation**: Always enable moderation in production
307
- 2. **Language Enhancement**: Use for non-English prompts
308
- 3. **Synchronous**: Avoid synchronous generation in production
309
- 4. **Rule Configuration**: Customize rules based on your use case
310
- 5. **Violation Handling**: Provide clear feedback to users
311
-
312
- ## Error Handling
313
-
314
- ```tsx
315
- try {
316
- const result = await wrapped.generate({ prompt: '...' });
317
- } catch (error) {
318
- if (error.type === 'MODERATION_ERROR') {
319
- // Content was flagged
320
- showModerationError(error.violations);
321
- } else if (error.type === 'TIMEOUT_ERROR') {
322
- // Generation timed out
323
- showTimeoutError();
324
- }
325
- }
326
- ```
327
-
328
- ## Related
329
-
330
- - [Middleware](../middleware/) - Request/response middleware
331
- - [Services](../services/) - AI generation services
332
- - [Utils](../utils/) - Utility functions
333
-
334
- ## License
335
-
336
- MIT
@@ -1,19 +0,0 @@
1
- /**
2
- * Generation Wrappers
3
- * High-level API wrappers for generation orchestration
4
- */
5
-
6
- export {
7
- enhancePromptWithLanguage,
8
- getSupportedLanguages,
9
- getLanguageName,
10
- } from "./language.wrapper";
11
-
12
- export { ModerationWrapper } from "./moderation.wrapper";
13
- export type { ModerationResult, ModerationConfig } from "./moderation.wrapper";
14
-
15
- export { generateSynchronously } from "./synchronous-generation.wrapper";
16
- export type {
17
- SynchronousGenerationInput,
18
- SynchronousGenerationConfig,
19
- } from "./synchronous-generation.wrapper";
@@ -1,37 +0,0 @@
1
- /**
2
- * Moderation Wrapper
3
- * Generic content moderation interface (app provides implementation)
4
- */
5
-
6
- export interface ModerationResult {
7
- allowed: boolean;
8
- error?: string;
9
- violations?: Array<{
10
- rule: string;
11
- suggestion?: string;
12
- }>;
13
- }
14
-
15
- export interface ModerationConfig {
16
- check: (content: string) => Promise<ModerationResult>;
17
- }
18
-
19
- export class ModerationWrapper {
20
- private static config: ModerationConfig | null = null;
21
-
22
- static configure(config: ModerationConfig): void {
23
- this.config = config;
24
- }
25
-
26
- static async checkContent(content: string): Promise<ModerationResult> {
27
- if (!this.config) {
28
- return { allowed: true };
29
- }
30
-
31
- return this.config.check(content);
32
- }
33
-
34
- static isConfigured(): boolean {
35
- return this.config !== null;
36
- }
37
- }