@umituz/react-native-ai-generation-content 1.67.4 → 1.69.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 +1 -1
- package/src/domains/creations/domain/utils/index.ts +5 -1
- package/src/domains/creations/presentation/hooks/useProcessingJobsPoller.ts +6 -3
- package/src/domains/generation/infrastructure/flow/useFlow.ts +5 -3
- package/src/domains/generation/wizard/infrastructure/builders/dynamic-step-builder.ts +1 -1
- package/src/domains/generation/wizard/presentation/hooks/useGenerationPhase.ts +4 -1
- package/src/domains/prompts/infrastructure/repositories/PromptHistoryRepository.ts +13 -53
- package/src/infrastructure/http/http-fetch-handler.ts +14 -3
- package/src/infrastructure/http/timeout.util.ts +6 -1
- package/src/infrastructure/services/generation-orchestrator.service.ts +1 -1
- package/src/infrastructure/utils/error-classifiers.ts +1 -27
- package/src/infrastructure/utils/error-extractors.ts +1 -20
- package/src/infrastructure/utils/error-handlers.ts +0 -28
- package/src/infrastructure/utils/error-retry.ts +3 -3
- package/src/infrastructure/utils/index.ts +10 -4
- package/src/domains/creations/domain/utils/creation-helpers.ts +0 -12
- package/src/infrastructure/utils/api-client.util.ts +0 -16
- package/src/infrastructure/utils/error-classifier.util.ts +0 -12
- package/src/infrastructure/utils/error-handling.util.ts +0 -11
- package/src/infrastructure/utils/error-message-extractor.util.ts +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-generation-content",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.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",
|
|
@@ -5,4 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
export * from "./status-helpers";
|
|
7
7
|
export * from "./preview-helpers";
|
|
8
|
-
export * from "./creation-
|
|
8
|
+
export * from "./creation-id.util";
|
|
9
|
+
export * from "./creation-display.util";
|
|
10
|
+
export * from "./creation-search.util";
|
|
11
|
+
export * from "./creation-sort.util";
|
|
12
|
+
export * from "./creation-format.util";
|
|
@@ -54,12 +54,15 @@ export function useProcessingJobsPoller(
|
|
|
54
54
|
|
|
55
55
|
pollJobRef.current = async (creation: Creation) => {
|
|
56
56
|
if (!userId || !creation.requestId || !creation.model) return;
|
|
57
|
+
|
|
57
58
|
if (pollingRef.current.has(creation.id)) return;
|
|
59
|
+
pollingRef.current.add(creation.id);
|
|
58
60
|
|
|
59
61
|
const provider = providerRegistry.getActiveProvider();
|
|
60
|
-
if (!provider || !provider.isInitialized())
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
if (!provider || !provider.isInitialized()) {
|
|
63
|
+
pollingRef.current.delete(creation.id);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
63
66
|
|
|
64
67
|
try {
|
|
65
68
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
@@ -104,8 +104,10 @@ export const useFlow = (config: UseFlowConfig): UseFlowReturn => {
|
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
declare const __DEV__: boolean;
|
|
108
|
+
|
|
109
109
|
export const resetFlowStore = () => {
|
|
110
|
-
|
|
110
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
111
|
+
console.warn('resetFlowStore is deprecated. Each component now maintains its own flow store instance.');
|
|
112
|
+
}
|
|
111
113
|
};
|
|
@@ -8,6 +8,7 @@ import { StepType } from "../../../../../domain/entities/flow-config.types";
|
|
|
8
8
|
import type { StepDefinition } from "../../../../../domain/entities/flow-config.types";
|
|
9
9
|
import type { WizardStepConfig } from "../../domain/entities/wizard-step.types";
|
|
10
10
|
import type { WizardFeatureConfig, ScenarioBasedConfig } from "../../domain/entities/wizard-feature.types";
|
|
11
|
+
import { buildWizardConfigFromScenario } from "../../domain/entities/wizard-feature.types";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Convert wizard step config to flow step definition
|
|
@@ -104,7 +105,6 @@ export const quickBuildWizard = (
|
|
|
104
105
|
featureId: string,
|
|
105
106
|
scenarioConfig: ScenarioBasedConfig,
|
|
106
107
|
): StepDefinition[] => {
|
|
107
|
-
const { buildWizardConfigFromScenario } = require("../../domain/entities/wizard-feature.types");
|
|
108
108
|
const wizardConfig = buildWizardConfigFromScenario(featureId, scenarioConfig);
|
|
109
109
|
return buildFlowStepsFromWizard(wizardConfig, {
|
|
110
110
|
includePreview: true,
|
|
@@ -27,9 +27,12 @@ export function useGenerationPhase(options?: UseGenerationPhaseOptions): Generat
|
|
|
27
27
|
const { queuedDuration = 5000 } = options ?? {};
|
|
28
28
|
|
|
29
29
|
const [phase, setPhase] = useState<GenerationPhase>("queued");
|
|
30
|
-
const startTimeRef = useRef(Date.now());
|
|
30
|
+
const startTimeRef = useRef<number>(Date.now());
|
|
31
31
|
|
|
32
32
|
useEffect(() => {
|
|
33
|
+
startTimeRef.current = Date.now();
|
|
34
|
+
setPhase("queued");
|
|
35
|
+
|
|
33
36
|
const interval = setInterval(() => {
|
|
34
37
|
const elapsed = Date.now() - startTimeRef.current;
|
|
35
38
|
|
|
@@ -7,74 +7,34 @@ export class PromptHistoryRepository implements IPromptHistoryRepository {
|
|
|
7
7
|
private readonly maxStorageSize = 100;
|
|
8
8
|
|
|
9
9
|
save(prompt: GeneratedPrompt): Promise<AIPromptResult<void>> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return Promise.resolve({ success: true, data: undefined });
|
|
14
|
-
} catch {
|
|
15
|
-
return Promise.resolve({
|
|
16
|
-
success: false,
|
|
17
|
-
error: 'STORAGE_ERROR',
|
|
18
|
-
message: 'Failed to save prompt to history'
|
|
19
|
-
});
|
|
20
|
-
}
|
|
10
|
+
this.storage.push(prompt);
|
|
11
|
+
this.trimStorage();
|
|
12
|
+
return Promise.resolve({ success: true, data: undefined });
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
findRecent(limit: number = 50): Promise<AIPromptResult<GeneratedPrompt[]>> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return Promise.resolve({ success: true, data: prompts });
|
|
27
|
-
} catch {
|
|
28
|
-
return Promise.resolve({
|
|
29
|
-
success: false,
|
|
30
|
-
error: 'STORAGE_ERROR',
|
|
31
|
-
message: 'Failed to retrieve recent prompts'
|
|
32
|
-
});
|
|
33
|
-
}
|
|
16
|
+
const prompts = this.storage.slice(-limit);
|
|
17
|
+
return Promise.resolve({ success: true, data: prompts });
|
|
34
18
|
}
|
|
35
19
|
|
|
36
20
|
findByTemplateId(
|
|
37
21
|
templateId: string,
|
|
38
22
|
limit: number = 20
|
|
39
23
|
): Promise<AIPromptResult<GeneratedPrompt[]>> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return Promise.resolve({ success: true, data: prompts });
|
|
45
|
-
} catch {
|
|
46
|
-
return Promise.resolve({
|
|
47
|
-
success: false,
|
|
48
|
-
error: 'STORAGE_ERROR',
|
|
49
|
-
message: 'Failed to retrieve prompts by template ID'
|
|
50
|
-
});
|
|
51
|
-
}
|
|
24
|
+
const prompts = this.storage
|
|
25
|
+
.filter(prompt => prompt.templateId === templateId)
|
|
26
|
+
.slice(-limit);
|
|
27
|
+
return Promise.resolve({ success: true, data: prompts });
|
|
52
28
|
}
|
|
53
29
|
|
|
54
30
|
delete(id: string): Promise<AIPromptResult<void>> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return Promise.resolve({ success: true, data: undefined });
|
|
58
|
-
} catch {
|
|
59
|
-
return Promise.resolve({
|
|
60
|
-
success: false,
|
|
61
|
-
error: 'STORAGE_ERROR',
|
|
62
|
-
message: 'Failed to delete prompt'
|
|
63
|
-
});
|
|
64
|
-
}
|
|
31
|
+
this.storage = this.storage.filter(prompt => prompt.id !== id);
|
|
32
|
+
return Promise.resolve({ success: true, data: undefined });
|
|
65
33
|
}
|
|
66
34
|
|
|
67
35
|
clear(): Promise<AIPromptResult<void>> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return Promise.resolve({ success: true, data: undefined });
|
|
71
|
-
} catch {
|
|
72
|
-
return Promise.resolve({
|
|
73
|
-
success: false,
|
|
74
|
-
error: 'STORAGE_ERROR',
|
|
75
|
-
message: 'Failed to clear prompt history'
|
|
76
|
-
});
|
|
77
|
-
}
|
|
36
|
+
this.storage = [];
|
|
37
|
+
return Promise.resolve({ success: true, data: undefined });
|
|
78
38
|
}
|
|
79
39
|
|
|
80
40
|
private trimStorage(): void {
|
|
@@ -3,12 +3,17 @@
|
|
|
3
3
|
* Infrastructure: Orchestrates request execution with error handling
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { withErrorHandling
|
|
6
|
+
import { withErrorHandling } from "../utils/error-handlers";
|
|
7
|
+
import { getErrorMessage } from "../utils/error-extractors";
|
|
8
|
+
import { retryWithBackoff } from "../utils/error-retry";
|
|
9
|
+
import { isNetworkError } from "../utils/error-classifiers";
|
|
7
10
|
import { env } from "../config/env.config";
|
|
8
11
|
import type { RequestOptions, ApiResponse } from "./api-client.types";
|
|
9
12
|
import { executeRequest, isSuccessResponse, extractErrorMessage } from "./http-request-executor";
|
|
10
13
|
import { parseResponse, createSuccessResponse, createErrorResponse } from "./http-response-parser";
|
|
11
14
|
|
|
15
|
+
declare const __DEV__: boolean;
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Fetches data with timeout, retry, and error handling
|
|
14
19
|
*/
|
|
@@ -41,7 +46,9 @@ export async function fetchWithTimeout<T>(
|
|
|
41
46
|
return operation();
|
|
42
47
|
},
|
|
43
48
|
(error) => {
|
|
44
|
-
|
|
49
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
50
|
+
console.error("[API Client] Request failed:", error);
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
);
|
|
47
54
|
|
|
@@ -49,5 +56,9 @@ export async function fetchWithTimeout<T>(
|
|
|
49
56
|
return createErrorResponse(getErrorMessage(result.error));
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
if (result.data === undefined) {
|
|
60
|
+
return createErrorResponse("No data received from server");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return createSuccessResponse(result.data);
|
|
53
64
|
}
|
|
@@ -16,6 +16,11 @@ export function createTimeoutController(
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const controller = new AbortController();
|
|
19
|
-
setTimeout(() => controller.abort(), timeout);
|
|
19
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
20
|
+
|
|
21
|
+
controller.signal.addEventListener('abort', () => {
|
|
22
|
+
clearTimeout(timeoutId);
|
|
23
|
+
}, { once: true });
|
|
24
|
+
|
|
20
25
|
return controller;
|
|
21
26
|
}
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
GenerationResult,
|
|
10
10
|
PollingConfig,
|
|
11
11
|
} from "../../domain/entities";
|
|
12
|
-
import { classifyError } from "../utils/error-
|
|
12
|
+
import { classifyError } from "../utils/error-classification";
|
|
13
13
|
import { pollJob } from "../../domains/background/infrastructure/services/job-poller.service";
|
|
14
14
|
import { ProviderValidator } from "./provider-validator";
|
|
15
15
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error Classification Utilities
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { isError
|
|
5
|
+
import { isError } from "./error-types";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Checks if error is a network error
|
|
@@ -21,29 +21,3 @@ export function isNetworkError(error: unknown): boolean {
|
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
* Checks if error is a validation error
|
|
26
|
-
*/
|
|
27
|
-
export function isValidationError(error: unknown): boolean {
|
|
28
|
-
if (isAppError(error)) {
|
|
29
|
-
return error.code?.toLowerCase().includes("validation") || false;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Checks if error is an authentication error
|
|
36
|
-
*/
|
|
37
|
-
export function isAuthError(error: unknown): boolean {
|
|
38
|
-
if (!isError(error)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const message = error.message.toLowerCase();
|
|
43
|
-
return (
|
|
44
|
-
message.includes("unauthorized") ||
|
|
45
|
-
message.includes("authentication") ||
|
|
46
|
-
message.includes("forbidden") ||
|
|
47
|
-
message.includes("token")
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error Message Extraction
|
|
2
|
+
* Error Message Extraction
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { AppError } from "./error-types";
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* Safely extracts error message from unknown error type
|
|
9
7
|
*/
|
|
@@ -23,20 +21,3 @@ export function getErrorMessage(error: unknown): string {
|
|
|
23
21
|
return "An unknown error occurred";
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
/**
|
|
27
|
-
* Creates a standardized application error
|
|
28
|
-
*/
|
|
29
|
-
export function createAppError(
|
|
30
|
-
message: string,
|
|
31
|
-
options: {
|
|
32
|
-
code?: string;
|
|
33
|
-
statusCode?: number;
|
|
34
|
-
originalError?: unknown;
|
|
35
|
-
} = {}
|
|
36
|
-
): AppError {
|
|
37
|
-
const error = new Error(message) as AppError;
|
|
38
|
-
error.code = options.code;
|
|
39
|
-
error.statusCode = options.statusCode;
|
|
40
|
-
error.originalError = options.originalError;
|
|
41
|
-
return error;
|
|
42
|
-
}
|
|
@@ -21,31 +21,3 @@ export async function withErrorHandling<T>(
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
* Safely executes a function and returns null on error
|
|
26
|
-
*/
|
|
27
|
-
export function safeExecute<T>(
|
|
28
|
-
operation: () => T,
|
|
29
|
-
fallback: T = null as T
|
|
30
|
-
): T {
|
|
31
|
-
try {
|
|
32
|
-
return operation();
|
|
33
|
-
} catch {
|
|
34
|
-
return fallback;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Logs error with context
|
|
40
|
-
*/
|
|
41
|
-
export function logError(
|
|
42
|
-
error: unknown,
|
|
43
|
-
context?: string
|
|
44
|
-
): void {
|
|
45
|
-
const message = getErrorMessage(error);
|
|
46
|
-
const contextPrefix = context ? `[${context}]` : "";
|
|
47
|
-
|
|
48
|
-
if (typeof console !== "undefined" && console.error) {
|
|
49
|
-
console.error(`${contextPrefix} Error:`, message, error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -25,13 +25,13 @@ export async function retryWithBackoff<T>(
|
|
|
25
25
|
|
|
26
26
|
let lastError: Error | undefined;
|
|
27
27
|
|
|
28
|
-
for (let attempt = 0; attempt
|
|
28
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
29
29
|
try {
|
|
30
30
|
return await operation();
|
|
31
31
|
} catch (error) {
|
|
32
32
|
lastError = error instanceof Error ? error : new Error(getErrorMessage(error));
|
|
33
33
|
|
|
34
|
-
if (
|
|
34
|
+
if (!shouldRetry(lastError)) {
|
|
35
35
|
throw lastError;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -40,5 +40,5 @@ export async function retryWithBackoff<T>(
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
throw lastError
|
|
43
|
+
throw lastError ?? new Error("Operation failed after retries");
|
|
44
44
|
}
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
* Infrastructure Utils
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export * from "./error-
|
|
6
|
-
export * from "./error-
|
|
7
|
-
export * from "./error-
|
|
5
|
+
export * from "./error-classification";
|
|
6
|
+
export * from "./error-classifiers";
|
|
7
|
+
export * from "./error-extractors";
|
|
8
|
+
export * from "./error-handlers";
|
|
9
|
+
export * from "./error-factory";
|
|
10
|
+
export * from "./error-types";
|
|
11
|
+
export * from "./message-extractor";
|
|
12
|
+
export * from "./fal-error-checker";
|
|
13
|
+
export * from "./classifier-helpers";
|
|
14
|
+
export * from "./result-polling";
|
|
8
15
|
export * from "./validation.util";
|
|
9
|
-
export * from "./api-client.util";
|
|
10
16
|
export * from "../../domains/background/infrastructure/utils/polling-interval.util";
|
|
11
17
|
export * from "./progress-calculator.util";
|
|
12
18
|
export * from "./progress.utils";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creation Helpers
|
|
3
|
-
* Central export point for creation utility functions
|
|
4
|
-
* @deprecated Individual utilities split into focused modules for better maintainability
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Re-export all utilities for backward compatibility
|
|
8
|
-
export * from "./creation-id.util";
|
|
9
|
-
export * from "./creation-display.util";
|
|
10
|
-
export * from "./creation-search.util";
|
|
11
|
-
export * from "./creation-sort.util";
|
|
12
|
-
export * from "./creation-format.util";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Client Utilities (Deprecated - Use /infrastructure/http instead)
|
|
3
|
-
* @deprecated Import from @umituz/react-native-ai-generation-content/infrastructure/http instead
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type { RequestOptions, ApiResponse } from "../http/api-client.types";
|
|
7
|
-
export {
|
|
8
|
-
get,
|
|
9
|
-
post,
|
|
10
|
-
put,
|
|
11
|
-
del,
|
|
12
|
-
patch,
|
|
13
|
-
fetchWithTimeout,
|
|
14
|
-
buildQueryString,
|
|
15
|
-
appendQueryParams,
|
|
16
|
-
} from "../http";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error Classifier Utility - Barrel Export
|
|
3
|
-
* Classifies errors for retry and user feedback decisions
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { matchesPatterns, getStatusCode, logClassification } from "./classifier-helpers";
|
|
7
|
-
export {
|
|
8
|
-
classifyError,
|
|
9
|
-
isTransientError,
|
|
10
|
-
isPermanentError,
|
|
11
|
-
} from "./error-classification";
|
|
12
|
-
export { isResultNotReady } from "./result-polling";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized Error Handling Utilities - Barrel Export
|
|
3
|
-
* Provides consistent error handling patterns across the application
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type { AppError } from "./error-types";
|
|
7
|
-
export { isError, isAppError } from "./error-types";
|
|
8
|
-
export { getErrorMessage, createAppError } from "./error-extractors";
|
|
9
|
-
export { withErrorHandling, safeExecute, logError } from "./error-handlers";
|
|
10
|
-
export { isNetworkError, isValidationError, isAuthError } from "./error-classifiers";
|
|
11
|
-
export { retryWithBackoff } from "./error-retry";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error Message Extractor - Barrel Export
|
|
3
|
-
* Extracts error messages from various API error formats
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type {
|
|
7
|
-
FalErrorDetail,
|
|
8
|
-
GenerationErrorTypeValue,
|
|
9
|
-
GenerationError,
|
|
10
|
-
} from "./extraction-types";
|
|
11
|
-
export { GenerationErrorType } from "./extraction-types";
|
|
12
|
-
export { createGenerationError, isGenerationError } from "./error-factory";
|
|
13
|
-
export { checkFalApiError } from "./fal-error-checker";
|
|
14
|
-
export { extractErrorMessage, getErrorTranslationKey } from "./message-extractor";
|