@umituz/react-native-ai-generation-content 1.65.1 → 1.65.3

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.
Files changed (153) hide show
  1. package/package.json +1 -1
  2. package/src/domain/constants/processing-modes-catalog.constants.ts +97 -0
  3. package/src/domain/constants/processing-modes-filters.ts +34 -0
  4. package/src/domain/constants/processing-modes-getters.ts +20 -0
  5. package/src/domain/constants/processing-modes.constants.ts +8 -134
  6. package/src/domain/entities/feature-flow-config.types.ts +17 -0
  7. package/src/domain/entities/flow-actions.types.ts +26 -0
  8. package/src/domain/entities/flow-config-data.types.ts +41 -0
  9. package/src/domain/entities/flow-config.types.ts +17 -169
  10. package/src/domain/entities/flow-configuration.types.ts +44 -0
  11. package/src/domain/entities/flow-state.types.ts +30 -0
  12. package/src/domain/entities/flow-step.types.ts +56 -0
  13. package/src/domain/entities/scenario-step-config.types.ts +32 -0
  14. package/src/domain/entities/step-config.types.ts +14 -129
  15. package/src/domain/entities/step-definition.types.ts +50 -0
  16. package/src/domain/entities/step-input-config.types.ts +36 -0
  17. package/src/domain/entities/step-upload-config.types.ts +17 -0
  18. package/src/domain/interfaces/ai-provider-capabilities.types.ts +27 -0
  19. package/src/domain/interfaces/ai-provider-config.types.ts +30 -0
  20. package/src/domain/interfaces/ai-provider-feature-types.ts +22 -0
  21. package/src/domain/interfaces/ai-provider-input.types.ts +28 -0
  22. package/src/domain/interfaces/ai-provider-progress.types.ts +37 -0
  23. package/src/domain/interfaces/ai-provider-status.types.ts +41 -0
  24. package/src/domain/interfaces/ai-provider.interface.ts +32 -142
  25. package/src/domain/types/result-constructors.ts +20 -0
  26. package/src/domain/types/result-guards.ts +20 -0
  27. package/src/domain/types/result-transformers.ts +36 -0
  28. package/src/domain/types/result-type-definitions.ts +27 -0
  29. package/src/domain/types/result-unwrappers.ts +28 -0
  30. package/src/domain/types/result.types.ts +11 -100
  31. package/src/domains/background/infrastructure/utils/polling-interval.util.ts +3 -8
  32. package/src/domains/background/infrastructure/utils/result-validation-logic.ts +88 -0
  33. package/src/domains/background/infrastructure/utils/result-validator-constants.ts +18 -0
  34. package/src/domains/background/infrastructure/utils/result-validator.types.ts +16 -0
  35. package/src/domains/background/infrastructure/utils/result-validator.util.ts +8 -109
  36. package/src/domains/background/infrastructure/utils/status-checker.types.ts +11 -0
  37. package/src/domains/background/infrastructure/utils/status-checker.util.ts +9 -119
  38. package/src/domains/background/infrastructure/utils/status-error-detector.ts +61 -0
  39. package/src/domains/background/infrastructure/utils/status-extraction-helpers.ts +25 -0
  40. package/src/domains/background/infrastructure/utils/status-predicates.ts +37 -0
  41. package/src/domains/creations/domain-exports.ts +79 -0
  42. package/src/domains/creations/index.ts +9 -169
  43. package/src/domains/creations/infrastructure-exports.ts +9 -0
  44. package/src/domains/creations/presentation-exports.ts +59 -0
  45. package/src/domains/generation/infrastructure/executors/text-to-image-executor.helpers.ts +81 -0
  46. package/src/domains/generation/infrastructure/executors/text-to-image-executor.ts +4 -100
  47. package/src/domains/generation/infrastructure/executors/text-to-image-executor.types.ts +19 -0
  48. package/src/domains/generation/infrastructure/flow/use-flow-store.types.ts +19 -0
  49. package/src/domains/generation/infrastructure/flow/useFlowStore.ts +33 -65
  50. package/src/domains/generation/wizard/domain/entities/wizard-config-builder.ts +75 -0
  51. package/src/domains/generation/wizard/domain/entities/wizard-feature-config.types.ts +29 -0
  52. package/src/domains/generation/wizard/domain/entities/wizard-feature.types.ts +9 -114
  53. package/src/domains/generation/wizard/domain/entities/wizard-presets.constants.ts +23 -0
  54. package/src/domains/generation/wizard/infrastructure/strategies/shared/unified-prompt-builder.ts +1 -1
  55. package/src/domains/generation/wizard/infrastructure/utils/creation-persistence-factory.ts +33 -0
  56. package/src/domains/generation/wizard/infrastructure/utils/creation-persistence.types.ts +22 -0
  57. package/src/domains/generation/wizard/infrastructure/utils/creation-persistence.util.ts +11 -135
  58. package/src/domains/generation/wizard/infrastructure/utils/creation-save-operations.ts +48 -0
  59. package/src/domains/generation/wizard/infrastructure/utils/creation-update-operations.ts +72 -0
  60. package/src/domains/generation/wizard/presentation/hooks/use-video-queue-generation.types.ts +21 -0
  61. package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +14 -35
  62. package/src/domains/image-to-video/domain/types/image-to-video-callbacks.types.ts +33 -0
  63. package/src/domains/image-to-video/domain/types/image-to-video-config.types.ts +29 -0
  64. package/src/domains/image-to-video/domain/types/image-to-video-request.types.ts +31 -0
  65. package/src/domains/image-to-video/domain/types/image-to-video-result.types.ts +17 -0
  66. package/src/domains/image-to-video/domain/types/image-to-video-state.types.ts +24 -0
  67. package/src/domains/image-to-video/domain/types/image-to-video.types.ts +24 -114
  68. package/src/domains/image-to-video/infrastructure/services/image-to-video-executor.ts +26 -99
  69. package/src/domains/image-to-video/infrastructure/services/image-to-video-executor.types.ts +15 -0
  70. package/src/domains/prompts/domain/base/constants.ts +47 -0
  71. package/src/domains/prompts/domain/base/creators.ts +76 -0
  72. package/src/domains/prompts/domain/base/types.ts +10 -0
  73. package/src/domains/prompts/domain/entities/MultiPersonPromptStructure.ts +1 -1
  74. package/src/domains/prompts/index.ts +4 -2
  75. package/src/domains/prompts/infrastructure/services/ImagePromptBuilder.ts +2 -72
  76. package/src/domains/prompts/infrastructure/services/image-prompt-builder.types.ts +17 -0
  77. package/src/domains/result-preview/presentation/types/result-components.types.ts +47 -0
  78. package/src/domains/result-preview/presentation/types/result-creation.types.ts +14 -0
  79. package/src/domains/result-preview/presentation/types/result-data.types.ts +35 -0
  80. package/src/domains/result-preview/presentation/types/result-hooks.types.ts +35 -0
  81. package/src/domains/result-preview/presentation/types/result-preview.types.ts +19 -182
  82. package/src/domains/result-preview/presentation/types/result-screen.types.ts +69 -0
  83. package/src/domains/text-to-image/domain-exports.ts +50 -0
  84. package/src/domains/text-to-image/index.ts +11 -102
  85. package/src/domains/text-to-image/infrastructure-exports.ts +6 -0
  86. package/src/domains/text-to-image/presentation/hooks/useFormState.ts +39 -24
  87. package/src/domains/text-to-image/presentation/hooks/useGeneration.ts +6 -4
  88. package/src/domains/text-to-image/presentation/screens/TextToImageWizardFlow.tsx +5 -3
  89. package/src/domains/text-to-image/presentation-exports.ts +41 -0
  90. package/src/domains/text-to-video/domain/types/action-component.types.ts +15 -0
  91. package/src/domains/text-to-video/domain/types/component.types.ts +16 -103
  92. package/src/domains/text-to-video/domain/types/content-component.types.ts +30 -0
  93. package/src/domains/text-to-video/domain/types/panel-component.types.ts +24 -0
  94. package/src/domains/text-to-video/domain/types/selector-component.types.ts +31 -0
  95. package/src/domains/text-to-video/domain/types/tab-component.types.ts +26 -0
  96. package/src/index.ts +0 -10
  97. package/src/infrastructure/executors/base-executor.ts +40 -112
  98. package/src/infrastructure/executors/base-executor.types.ts +10 -0
  99. package/src/infrastructure/http/http-client-methods.ts +73 -0
  100. package/src/infrastructure/http/http-client.util.ts +8 -163
  101. package/src/infrastructure/http/http-fetch-handler.ts +53 -0
  102. package/src/infrastructure/http/http-methods.constants.ts +23 -0
  103. package/src/infrastructure/http/http-request-executor.ts +49 -0
  104. package/src/infrastructure/http/http-response-parser.ts +53 -0
  105. package/src/infrastructure/orchestration/GenerationOrchestrator.ts +8 -43
  106. package/src/infrastructure/utils/classifier-helpers.ts +36 -0
  107. package/src/infrastructure/utils/content-validators.ts +92 -0
  108. package/src/infrastructure/utils/domain-guards.ts +22 -0
  109. package/src/infrastructure/utils/error-classification.ts +122 -0
  110. package/src/infrastructure/utils/error-classifier.util.ts +8 -181
  111. package/src/infrastructure/utils/error-classifiers.ts +49 -0
  112. package/src/infrastructure/utils/error-extractors.ts +42 -0
  113. package/src/infrastructure/utils/error-factory.ts +25 -0
  114. package/src/infrastructure/utils/error-handlers.ts +51 -0
  115. package/src/infrastructure/utils/error-handling.util.ts +7 -186
  116. package/src/infrastructure/utils/error-message-extractor.util.ts +10 -172
  117. package/src/infrastructure/utils/error-retry.ts +44 -0
  118. package/src/infrastructure/utils/error-types.ts +23 -0
  119. package/src/infrastructure/utils/extraction-types.ts +37 -0
  120. package/src/infrastructure/utils/fal-error-checker.ts +44 -0
  121. package/src/infrastructure/utils/general-validators.ts +64 -0
  122. package/src/infrastructure/utils/id-validators.ts +39 -0
  123. package/src/infrastructure/utils/message-extractor.ts +89 -0
  124. package/src/infrastructure/utils/primitive-guards.ts +66 -0
  125. package/src/infrastructure/utils/result-polling.ts +39 -0
  126. package/src/infrastructure/utils/structure-guards.ts +75 -0
  127. package/src/infrastructure/utils/type-guards.util.ts +22 -149
  128. package/src/infrastructure/utils/validation-types.ts +8 -0
  129. package/src/infrastructure/utils/validation.util.ts +14 -184
  130. package/src/presentation/hooks/ai-feature-callbacks-auth.hooks.ts +43 -0
  131. package/src/presentation/hooks/ai-feature-callbacks-cost.hooks.ts +56 -0
  132. package/src/presentation/hooks/ai-feature-callbacks-execution.hooks.ts +66 -0
  133. package/src/presentation/hooks/ai-feature-callbacks.types.ts +69 -0
  134. package/src/presentation/hooks/generation/use-image-generation.types.ts +39 -0
  135. package/src/presentation/hooks/generation/useImageGeneration.ts +33 -99
  136. package/src/presentation/hooks/generation-flow-navigation.ts +58 -0
  137. package/src/presentation/hooks/generation-flow-updates.ts +67 -0
  138. package/src/presentation/hooks/generation-flow.types.ts +32 -0
  139. package/src/presentation/hooks/useAIFeatureCallbacks.ts +48 -138
  140. package/src/presentation/hooks/useGenerationFlow.ts +40 -136
  141. package/src/presentation/types/flow-config.types.ts +9 -140
  142. package/src/presentation/types/flow-generation-config.types.ts +25 -0
  143. package/src/presentation/types/flow-state.types.ts +16 -0
  144. package/src/presentation/types/flow-step-configs.types.ts +48 -0
  145. package/src/presentation/types/flow-step-data.types.ts +24 -0
  146. package/src/presentation/types/result-actions.types.ts +50 -0
  147. package/src/presentation/types/result-config.types.ts +22 -171
  148. package/src/presentation/types/result-header.types.ts +44 -0
  149. package/src/presentation/types/result-image.types.ts +29 -0
  150. package/src/presentation/types/result-layout.types.ts +26 -0
  151. package/src/presentation/types/result-story.types.ts +42 -0
  152. package/src/domains/prompts/domain/entities/BasePromptStructure.ts +0 -168
  153. package/src/exports/domains.ts +0 -149
@@ -1,158 +1,48 @@
1
1
  /**
2
- * AI Provider Interface
2
+ * AI Provider Interface - Barrel Export
3
3
  * Provider-agnostic interface for AI generation services
4
+ *
5
+ * Architecture:
6
+ * - Feature Types: ImageFeatureType, VideoFeatureType enums
7
+ * - Configuration: AIProviderConfig for initialization
8
+ * - Status: Job status tracking types
9
+ * - Progress: Progress tracking and callback options
10
+ * - Capabilities: Provider feature support definition
11
+ * - Input: Input data structures for features
12
+ * - Main Interface: Composed IAIProvider using Interface Segregation Principle
4
13
  */
5
14
 
6
- // =============================================================================
7
- // Feature Types (must be defined first for use in other interfaces)
8
- // =============================================================================
15
+ // Feature Types
16
+ export type { ImageFeatureType, VideoFeatureType } from "./ai-provider-feature-types";
9
17
 
10
- /**
11
- * Feature types for image processing (output: image)
12
- */
13
- export type ImageFeatureType =
14
- | "upscale"
15
- | "photo-restore"
16
- | "face-swap"
17
- | "anime-selfie"
18
- | "remove-background"
19
- | "remove-object"
20
- | "hd-touch-up"
21
- | "replace-background";
22
-
23
- /**
24
- * Feature types for video generation (output: video)
25
- */
26
- export type VideoFeatureType =
27
- | "image-to-video"
28
- | "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
- /** Text generation model ID */
41
- textModel?: string;
42
- /** Text-to-image generation model ID */
43
- textToImageModel?: string;
44
- /** Image editing model ID */
45
- imageEditModel?: string;
46
- /** Video generation model ID */
47
- videoGenerationModel?: string;
48
- /** Video feature model mapping - app provides models for each feature */
49
- videoFeatureModels?: Partial<Record<VideoFeatureType, string>>;
50
- /** Image feature model mapping - app provides models for each feature */
51
- imageFeatureModels?: Partial<Record<ImageFeatureType, string>>;
52
- }
18
+ // Configuration
19
+ export type { AIProviderConfig } from "./ai-provider-config.types";
53
20
 
54
- // =============================================================================
55
21
  // Status Types
56
- // =============================================================================
57
-
58
- export type AIJobStatusType =
59
- | "IN_QUEUE"
60
- | "IN_PROGRESS"
61
- | "COMPLETED"
62
- | "FAILED";
63
-
64
- export interface AILogEntry {
65
- message: string;
66
- level: "info" | "warn" | "error";
67
- timestamp?: string;
68
- }
69
-
70
- export interface JobSubmission {
71
- requestId: string;
72
- statusUrl?: string;
73
- responseUrl?: string;
74
- }
75
-
76
- export interface JobStatus {
77
- status: AIJobStatusType;
78
- logs?: AILogEntry[];
79
- queuePosition?: number;
80
- eta?: number;
81
- }
22
+ export type {
23
+ AIJobStatusType,
24
+ AILogEntry,
25
+ JobSubmission,
26
+ JobStatus,
27
+ } from "./ai-provider-status.types";
82
28
 
83
- // =============================================================================
84
29
  // Progress & Options
85
- // =============================================================================
86
-
87
- export interface ProviderProgressInfo {
88
- /** Progress percentage (0-100) */
89
- progress: number;
90
- /** Current job status */
91
- status?: AIJobStatusType;
92
- /** Human-readable message */
93
- message?: string;
94
- /** Estimated time remaining in ms */
95
- estimatedTimeRemaining?: number;
96
- }
97
-
98
- export interface SubscribeOptions<T = unknown> {
99
- timeoutMs?: number;
100
- onQueueUpdate?: (status: JobStatus) => void;
101
- onProgress?: (progress: ProviderProgressInfo) => void;
102
- onResult?: (result: T) => void;
103
- }
104
-
105
- export interface RunOptions {
106
- onProgress?: (progress: ProviderProgressInfo) => void;
107
- }
30
+ export type {
31
+ ProviderProgressInfo,
32
+ SubscribeOptions,
33
+ RunOptions,
34
+ } from "./ai-provider-progress.types";
108
35
 
109
- // =============================================================================
110
36
  // Capabilities
111
- // =============================================================================
112
-
113
- export interface ProviderCapabilities {
114
- /** Supported image features */
115
- imageFeatures: readonly ImageFeatureType[];
116
- /** Supported video features */
117
- videoFeatures: readonly VideoFeatureType[];
118
- /** Supports text-to-image generation */
119
- textToImage: boolean;
120
- /** Supports text-to-video generation */
121
- textToVideo: boolean;
122
- /** Supports image-to-video generation */
123
- imageToVideo: boolean;
124
- /** Supports text-to-voice generation */
125
- textToVoice: boolean;
126
- /** Supports text-to-text (LLM) generation */
127
- textToText: boolean;
128
- }
129
-
130
- // =============================================================================
131
- // Feature Input Data
132
- // =============================================================================
133
-
134
- export interface ImageFeatureInputData {
135
- imageBase64: string;
136
- targetImageBase64?: string;
137
- prompt?: string;
138
- options?: Record<string, unknown>;
139
- }
140
-
141
- export interface VideoFeatureInputData {
142
- /** Source image (required for image-to-video, optional for text-to-video) */
143
- sourceImageBase64?: string;
144
- /** Target image (optional, used for dual-image features) */
145
- targetImageBase64?: string;
146
- /** Generation prompt (required for text-to-video) */
147
- prompt?: string;
148
- /** Additional generation options */
149
- options?: Record<string, unknown>;
150
- }
37
+ export type { ProviderCapabilities } from "./ai-provider-capabilities.types";
151
38
 
152
- // =============================================================================
153
- // Provider Interface (Composition using Interface Segregation Principle)
154
- // =============================================================================
39
+ // Input Data
40
+ export type {
41
+ ImageFeatureInputData,
42
+ VideoFeatureInputData,
43
+ } from "./ai-provider-input.types";
155
44
 
45
+ // Main Interface Composition (Interface Segregation Principle)
156
46
  import type { IAIProviderLifecycle } from "./provider-lifecycle.interface";
157
47
  import type { IAIProviderCapabilities } from "./provider-capabilities.interface";
158
48
  import type { IAIProviderJobManager } from "../../domains/background/domain/interfaces/provider-job-manager.interface";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Result Constructors
3
+ * Domain Service: Factory functions for creating Result types
4
+ */
5
+
6
+ import type { Success, Failure } from "./result-type-definitions";
7
+
8
+ /**
9
+ * Create a successful result
10
+ */
11
+ export function success<T>(value: T): Success<T> {
12
+ return { success: true, value };
13
+ }
14
+
15
+ /**
16
+ * Create a failed result
17
+ */
18
+ export function failure<E>(error: E): Failure<E> {
19
+ return { success: false, error };
20
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Result Type Guards
3
+ * Domain Service: Type guards for Result pattern
4
+ */
5
+
6
+ import type { Result, Success, Failure } from "./result-type-definitions";
7
+
8
+ /**
9
+ * Type guard to check if result is successful
10
+ */
11
+ export function isSuccess<T, E>(result: Result<T, E>): result is Success<T> {
12
+ return result.success === true;
13
+ }
14
+
15
+ /**
16
+ * Type guard to check if result is a failure
17
+ */
18
+ export function isFailure<T, E>(result: Result<T, E>): result is Failure<E> {
19
+ return result.success === false;
20
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Result Transformers
3
+ * Domain Service: Transform and chain Result types
4
+ */
5
+
6
+ import type { Result } from "./result-type-definitions";
7
+ import { isSuccess } from "./result-guards";
8
+ import { success } from "./result-constructors";
9
+
10
+ /**
11
+ * Map a successful result to a new value
12
+ * If result is failure, returns the failure unchanged
13
+ */
14
+ export function mapResult<T, U, E>(
15
+ result: Result<T, E>,
16
+ fn: (value: T) => U
17
+ ): Result<U, E> {
18
+ if (isSuccess(result)) {
19
+ return success(fn(result.value));
20
+ }
21
+ return result;
22
+ }
23
+
24
+ /**
25
+ * Chain async operations on Result types
26
+ * Similar to Promise.then() but for Result
27
+ */
28
+ export async function andThen<T, U, E>(
29
+ result: Result<T, E>,
30
+ fn: (value: T) => Promise<Result<U, E>>
31
+ ): Promise<Result<U, E>> {
32
+ if (isSuccess(result)) {
33
+ return fn(result.value);
34
+ }
35
+ return result;
36
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Result Type Definitions
3
+ * Domain: Core types for functional error handling
4
+ * Inspired by Rust's Result<T, E> type
5
+ */
6
+
7
+ /**
8
+ * Success result containing a value of type T
9
+ */
10
+ export interface Success<T> {
11
+ success: true;
12
+ value: T;
13
+ }
14
+
15
+ /**
16
+ * Failure result containing an error of type E
17
+ */
18
+ export interface Failure<E> {
19
+ success: false;
20
+ error: E;
21
+ }
22
+
23
+ /**
24
+ * Result type that can be either Success or Failure
25
+ * Forces explicit error handling at compile time
26
+ */
27
+ export type Result<T, E = string> = Success<T> | Failure<E>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Result Unwrappers
3
+ * Domain Service: Unwrap Result types to values
4
+ */
5
+
6
+ import type { Result } from "./result-type-definitions";
7
+ import { isSuccess } from "./result-guards";
8
+
9
+ /**
10
+ * Unwrap a result, throwing if it's a failure
11
+ * Use only when you're certain the result is successful
12
+ */
13
+ export function unwrap<T, E>(result: Result<T, E>): T {
14
+ if (isSuccess(result)) {
15
+ return result.value;
16
+ }
17
+ throw new Error(`Called unwrap on a failure: ${String(result.error)}`);
18
+ }
19
+
20
+ /**
21
+ * Unwrap a result or return a default value
22
+ */
23
+ export function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {
24
+ if (isSuccess(result)) {
25
+ return result.value;
26
+ }
27
+ return defaultValue;
28
+ }
@@ -1,105 +1,16 @@
1
1
  /**
2
- * Result Type Pattern for Functional Error Handling
3
- * Inspired by Rust's Result<T, E> type
2
+ * Result Type Pattern - Barrel Export
3
+ * Functional error handling inspired by Rust's Result<T, E>
4
+ *
5
+ * Architecture:
6
+ * - Domain: Type definitions (Success, Failure, Result)
7
+ * - Domain Services: Constructors, guards, transformers, unwrappers
4
8
  *
5
9
  * @see https://arg-software.medium.com/functional-error-handling-in-typescript-with-the-result-pattern-5b96a5abb6d3
6
10
  */
7
11
 
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
- * If result is failure, returns the failure unchanged
61
- */
62
- export function mapResult<T, U, E>(
63
- result: Result<T, E>,
64
- fn: (value: T) => U,
65
- ): Result<U, E> {
66
- if (isSuccess(result)) {
67
- return success(fn(result.value));
68
- }
69
- return result;
70
- }
71
-
72
- /**
73
- * Chain async operations on Result types
74
- * Similar to Promise.then() but for Result
75
- */
76
- export async function andThen<T, U, E>(
77
- result: Result<T, E>,
78
- fn: (value: T) => Promise<Result<U, E>>,
79
- ): Promise<Result<U, E>> {
80
- if (isSuccess(result)) {
81
- return fn(result.value);
82
- }
83
- return result;
84
- }
85
-
86
- /**
87
- * Unwrap a result, throwing if it's a failure
88
- * Use only when you're certain the result is successful
89
- */
90
- export function unwrap<T, E>(result: Result<T, E>): T {
91
- if (isSuccess(result)) {
92
- return result.value;
93
- }
94
- throw new Error(`Called unwrap on a failure: ${String(result.error)}`);
95
- }
96
-
97
- /**
98
- * Unwrap a result or return a default value
99
- */
100
- export function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {
101
- if (isSuccess(result)) {
102
- return result.value;
103
- }
104
- return defaultValue;
105
- }
12
+ export type { Success, Failure, Result } from "./result-type-definitions";
13
+ export { success, failure } from "./result-constructors";
14
+ export { isSuccess, isFailure } from "./result-guards";
15
+ export { mapResult, andThen } from "./result-transformers";
16
+ export { unwrap, unwrapOr } from "./result-unwrappers";
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Polling Interval Calculator
3
- * Calculates polling intervals with exponential backoff
4
3
  */
5
4
 
6
5
  import {
@@ -10,16 +9,12 @@ import {
10
9
 
11
10
  export interface IntervalOptions {
12
11
  attempt: number;
13
- config?: Partial<PollingConfig>;
12
+ config: PollingConfig;
14
13
  }
15
14
 
16
15
  export function calculatePollingInterval(options: IntervalOptions): number {
17
16
  const { attempt, config } = options;
18
- const {
19
- initialIntervalMs = DEFAULT_POLLING_CONFIG.initialIntervalMs,
20
- maxIntervalMs = DEFAULT_POLLING_CONFIG.maxIntervalMs,
21
- backoffMultiplier = DEFAULT_POLLING_CONFIG.backoffMultiplier,
22
- } = config ?? {};
17
+ const { initialIntervalMs, maxIntervalMs, backoffMultiplier } = config;
23
18
 
24
19
  if (attempt === 0) {
25
20
  return 0;
@@ -27,4 +22,4 @@ export function calculatePollingInterval(options: IntervalOptions): number {
27
22
 
28
23
  const interval = initialIntervalMs * Math.pow(backoffMultiplier, attempt - 1);
29
24
  return Math.min(interval, maxIntervalMs);
30
- }
25
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Result Validation Logic
3
+ * Infrastructure: Validates job results
4
+ */
5
+
6
+ import type { ResultValidation, ValidateResultOptions } from "./result-validator.types";
7
+ import { DEFAULT_OUTPUT_FIELDS } from "./result-validator-constants";
8
+
9
+ declare const __DEV__: boolean;
10
+
11
+ /**
12
+ * Validate job result and detect errors
13
+ * Checks for error fields even if job status was COMPLETED
14
+ */
15
+ export function validateResult(
16
+ result: unknown,
17
+ options?: ValidateResultOptions
18
+ ): ResultValidation {
19
+ const { outputFields = DEFAULT_OUTPUT_FIELDS, allowEmpty = false } =
20
+ options ?? {};
21
+
22
+ if (result === null || result === undefined) {
23
+ return {
24
+ isValid: allowEmpty,
25
+ hasError: !allowEmpty,
26
+ errorMessage: allowEmpty ? undefined : "Result is empty",
27
+ hasOutput: false,
28
+ };
29
+ }
30
+
31
+ if (typeof result !== "object") {
32
+ return {
33
+ isValid: true,
34
+ hasError: false,
35
+ hasOutput: true,
36
+ };
37
+ }
38
+
39
+ const resultObj = result as Record<string, unknown>;
40
+
41
+ const errorValue = resultObj.error || resultObj.detail;
42
+ const errorString = errorValue ? String(errorValue).toLowerCase() : "";
43
+
44
+ const hasInternalServerError =
45
+ errorString.includes("internal server error") ||
46
+ errorString.includes("500") ||
47
+ errorString === "internal server error";
48
+
49
+ const isEmpty = Object.keys(resultObj).length === 0;
50
+
51
+ const hasOutput = outputFields.some((field) => {
52
+ const value = resultObj[field];
53
+ if (!value) return false;
54
+
55
+ if (typeof value === "object" && value !== null) {
56
+ const nested = value as Record<string, unknown>;
57
+ const nestedKeys = Object.keys(nested);
58
+ return !!(
59
+ nested.url ||
60
+ nested.image_url ||
61
+ nested.video_url ||
62
+ nestedKeys.length > 0
63
+ );
64
+ }
65
+
66
+ return true;
67
+ });
68
+
69
+ const hasError =
70
+ hasInternalServerError || (isEmpty && !hasOutput && !allowEmpty);
71
+
72
+ const validation: ResultValidation = {
73
+ isValid: !hasError && (hasOutput || allowEmpty),
74
+ hasError,
75
+ errorMessage: hasError && errorValue ? String(errorValue) : undefined,
76
+ hasOutput,
77
+ };
78
+
79
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
80
+ console.log("[ResultValidator] Validation result:", {
81
+ isValid: validation.isValid,
82
+ hasOutput: validation.hasOutput,
83
+ hasError: validation.hasError,
84
+ });
85
+ }
86
+
87
+ return validation;
88
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Result Validator Constants
3
+ * Domain: Known output field names
4
+ */
5
+
6
+ export const DEFAULT_OUTPUT_FIELDS = [
7
+ "data",
8
+ "output",
9
+ "image",
10
+ "image_url",
11
+ "images",
12
+ "video",
13
+ "video_url",
14
+ "url",
15
+ "result",
16
+ "text",
17
+ "content",
18
+ ] as const;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Result Validator Types
3
+ * Domain: Value objects for result validation
4
+ */
5
+
6
+ export interface ResultValidation {
7
+ isValid: boolean;
8
+ hasError: boolean;
9
+ errorMessage?: string;
10
+ hasOutput: boolean;
11
+ }
12
+
13
+ export interface ValidateResultOptions {
14
+ outputFields?: string[];
15
+ allowEmpty?: boolean;
16
+ }