@umituz/react-native-ai-generation-content 1.83.0 → 1.83.2

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 (84) hide show
  1. package/package.json +1 -1
  2. package/src/core/constants/duration-options.constants.ts +1 -0
  3. package/src/core/constants/index.ts +11 -44
  4. package/src/core/constants/preset-styles.constants.ts +1 -0
  5. package/src/core/constants/script-durations.constants.ts +5 -0
  6. package/src/core/constants/style-options.constants.ts +1 -0
  7. package/src/domains/access-control/hooks/useAIFeatureGate.ts +0 -1
  8. package/src/domains/background/infrastructure/services/job-poller.service.ts +0 -1
  9. package/src/domains/background/infrastructure/utils/result-validation-logic.ts +0 -1
  10. package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +0 -1
  11. package/src/domains/creations/domain/constants/creation-fields.constants.ts +7 -3
  12. package/src/domains/creations/domain/entities/Creation.ts +22 -35
  13. package/src/domains/creations/infrastructure/repositories/CreationsQuery.ts +0 -1
  14. package/src/domains/creations/infrastructure/repositories/CreationsSubscription.ts +0 -1
  15. package/src/domains/creations/infrastructure/repositories/creation-create.operations.ts +1 -0
  16. package/src/domains/creations/infrastructure/repositories/creation-error-handler.util.ts +0 -1
  17. package/src/domains/creations/infrastructure/repositories/creation-update.operations.ts +2 -19
  18. package/src/domains/creations/presentation/components/GalleryHeader.tsx +0 -1
  19. package/src/domains/creations/presentation/hooks/useCreationPersistence.ts +0 -1
  20. package/src/domains/creations/presentation/hooks/useCreationRating.ts +0 -1
  21. package/src/domains/creations/presentation/hooks/useCreations.ts +0 -1
  22. package/src/domains/creations/presentation/hooks/useDeleteCreation.ts +0 -1
  23. package/src/domains/creations/presentation/hooks/useGalleryCallbacks.ts +0 -1
  24. package/src/domains/creations/presentation/hooks/useProcessingJobsPoller.ts +0 -1
  25. package/src/domains/generation/application/feature-registry.ts +0 -1
  26. package/src/domains/generation/application/generation-strategy.factory.ts +0 -1
  27. package/src/domains/generation/infrastructure/executors/executor-factory.ts +0 -1
  28. package/src/domains/generation/infrastructure/executors/image-executor.ts +0 -1
  29. package/src/domains/generation/infrastructure/executors/text-to-image-executor.ts +0 -1
  30. package/src/domains/generation/infrastructure/executors/video-executor.ts +0 -1
  31. package/src/domains/generation/infrastructure/flow/useFlowStore.ts +0 -1
  32. package/src/domains/generation/presentation/useAIGeneration.hook.ts +0 -1
  33. package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.ts +0 -1
  34. package/src/domains/generation/wizard/infrastructure/strategies/shared/photo-extraction.utils.ts +0 -1
  35. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.executor.ts +0 -1
  36. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +0 -1
  37. package/src/domains/generation/wizard/infrastructure/strategies/video-generation.utils.ts +0 -1
  38. package/src/domains/generation/wizard/infrastructure/utils/creation-persistence.types.ts +2 -0
  39. package/src/domains/generation/wizard/infrastructure/utils/creation-save-operations.ts +5 -4
  40. package/src/domains/generation/wizard/infrastructure/utils/creation-update-operations.ts +8 -2
  41. package/src/domains/generation/wizard/presentation/components/GenericWizardFlow.tsx +0 -1
  42. package/src/domains/generation/wizard/presentation/components/step-renderers/renderSelectionStep.tsx +0 -1
  43. package/src/domains/generation/wizard/presentation/hooks/generationExecutor.ts +0 -1
  44. package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.ts +0 -1
  45. package/src/domains/generation/wizard/presentation/hooks/usePhotoUploadState.ts +0 -1
  46. package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +9 -4
  47. package/src/domains/generation/wizard/presentation/hooks/videoQueuePoller.ts +0 -1
  48. package/src/domains/generation/wizard/presentation/screens/SelectionScreen.tsx +0 -1
  49. package/src/domains/generation/wizard/presentation/utilities/validateScenario.ts +0 -1
  50. package/src/domains/image-to-video/presentation/hooks/imageToVideoStrategy.ts +0 -1
  51. package/src/domains/image-to-video/presentation/hooks/useImageToVideoForm.ts +0 -1
  52. package/src/domains/result-preview/presentation/hooks/useResultActions.ts +0 -1
  53. package/src/domains/scenarios/configs/wizard-config-resolver.ts +0 -1
  54. package/src/domains/scenarios/infrastructure/scenario-registry.ts +0 -1
  55. package/src/domains/text-to-image/presentation/hooks/useGeneration.ts +0 -1
  56. package/src/domains/text-to-video/infrastructure/services/text-to-video-executor.ts +0 -1
  57. package/src/domains/text-to-video/presentation/hooks/textToVideoStrategy.ts +0 -1
  58. package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.ts +0 -1
  59. package/src/infrastructure/config/app-services.config.ts +0 -1
  60. package/src/infrastructure/executors/base-executor.ts +0 -1
  61. package/src/infrastructure/http/http-fetch-handler.ts +1 -2
  62. package/src/infrastructure/logging/debug.util.ts +2 -3
  63. package/src/infrastructure/logging/index.ts +1 -1
  64. package/src/infrastructure/providers/generation-config.provider.tsx +0 -1
  65. package/src/infrastructure/services/generation-orchestrator.service.ts +0 -1
  66. package/src/infrastructure/services/multi-image-generation.executor.ts +0 -1
  67. package/src/infrastructure/services/provider-registry.service.ts +0 -2
  68. package/src/infrastructure/services/provider-validator.ts +0 -1
  69. package/src/infrastructure/utils/classifier-helpers.ts +0 -1
  70. package/src/infrastructure/utils/error-classification.ts +0 -1
  71. package/src/infrastructure/utils/error-handlers.ts +1 -2
  72. package/src/infrastructure/utils/error-retry.ts +1 -1
  73. package/src/infrastructure/utils/feature-utils.ts +0 -1
  74. package/src/infrastructure/utils/index.ts +0 -1
  75. package/src/infrastructure/utils/message-extractor.ts +18 -1
  76. package/src/infrastructure/utils/provider-validator.util.ts +0 -1
  77. package/src/infrastructure/utils/url-extractor/rule-executor.ts +0 -1
  78. package/src/presentation/components/buttons/GenerateButton.tsx +0 -1
  79. package/src/presentation/hooks/generation/orchestrator.ts +0 -1
  80. package/src/presentation/hooks/generation/useImagePicker.ts +0 -1
  81. package/src/core/constants/model.constants.ts +0 -11
  82. package/src/core/constants/text-to-image-models.constants.ts +0 -18
  83. package/src/infrastructure/logging/logger.ts +0 -174
  84. package/src/infrastructure/utils/error-extractors.ts +0 -24
@@ -6,7 +6,6 @@
6
6
 
7
7
  import { useState, useCallback, useEffect, useRef } from "react";
8
8
 
9
- declare const __DEV__: boolean;
10
9
  import { useMedia, MediaQuality, MediaValidationError, MEDIA_CONSTANTS } from "@umituz/react-native-design-system";
11
10
  import type { UploadedImage } from "../../../../../presentation/hooks/generation/useAIGenerateState";
12
11
 
@@ -4,7 +4,6 @@
4
4
 
5
5
  import { useEffect, useRef, useCallback, useState } from "react";
6
6
 
7
- declare const __DEV__: boolean;
8
7
  import { pollQueueStatus } from "./videoQueuePoller";
9
8
  import {
10
9
  DEFAULT_POLL_INTERVAL_MS,
@@ -96,6 +95,7 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
96
95
  imageUrl: urls.imageUrl,
97
96
  videoUrl: urls.videoUrl,
98
97
  thumbnailUrl: urls.thumbnailUrl,
98
+ generationStartedAt: pollStartTimeRef.current ?? undefined,
99
99
  });
100
100
  if (typeof __DEV__ !== "undefined" && __DEV__) {
101
101
  console.log("[VideoQueue] ✅ Updated completion status in Firestore");
@@ -205,7 +205,7 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
205
205
  const resolution = typeof inputData?.resolution === "string" ? inputData.resolution : undefined;
206
206
  const aspectRatio = typeof inputData?.aspectRatio === "string" ? inputData.aspectRatio : undefined;
207
207
 
208
- creationId = await persistence.saveAsProcessing(userId, {
208
+ const result = await persistence.saveAsProcessing(userId, {
209
209
  scenarioId: scenario.id,
210
210
  scenarioTitle: scenario.title || scenario.id,
211
211
  prompt,
@@ -216,7 +216,10 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
216
216
  provider: "fal",
217
217
  outputType: scenario.outputType,
218
218
  });
219
+ creationId = result.creationId;
219
220
  creationIdRef.current = creationId;
221
+ // Record the actual DB-level start time for accurate durationMs
222
+ pollStartTimeRef.current = result.startedAt.getTime();
220
223
  } catch (error) {
221
224
  if (typeof __DEV__ !== "undefined" && __DEV__) {
222
225
  console.error("[VideoQueue] Failed to save processing creation:", error);
@@ -264,8 +267,10 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
264
267
  }
265
268
  }
266
269
 
267
- // Start polling: record start time, then poll immediately + on interval
268
- pollStartTimeRef.current = Date.now();
270
+ // Start polling: use DB-level startedAt if available, otherwise fallback to now
271
+ if (pollStartTimeRef.current === null) {
272
+ pollStartTimeRef.current = Date.now();
273
+ }
269
274
  pollingRef.current = setInterval(() => void pollStatusRef.current(), DEFAULT_POLL_INTERVAL_MS);
270
275
  void pollStatusRef.current();
271
276
  },
@@ -3,7 +3,6 @@ import { extractResultUrl, type GenerationUrls, type GenerationResult } from "./
3
3
  import { QUEUE_STATUS } from "../../../../../domain/constants/queue-status.constants";
4
4
  import { DEFAULT_MAX_CONSECUTIVE_ERRORS } from "../../../../../infrastructure/constants/polling.constants";
5
5
 
6
- declare const __DEV__: boolean;
7
6
 
8
7
  /**
9
8
  * Extract meaningful error message from various error formats.
@@ -23,7 +23,6 @@ export type {
23
23
  SelectionScreenProps,
24
24
  } from "./SelectionScreen.types";
25
25
 
26
- declare const __DEV__: boolean;
27
26
 
28
27
  export const SelectionScreen: React.FC<SelectionScreenProps> = ({
29
28
  stepId,
@@ -6,7 +6,6 @@
6
6
 
7
7
  import type { WizardScenarioData } from "../hooks/useWizardGeneration";
8
8
 
9
- declare const __DEV__: boolean;
10
9
 
11
10
  export interface ScenarioValidationResult {
12
11
  isValid: boolean;
@@ -1,6 +1,5 @@
1
1
  import { executeImageToVideo } from "../../infrastructure/services";
2
2
 
3
- declare const __DEV__: boolean;
4
3
  import type { GenerationStrategy } from "../../../../presentation/hooks/generation";
5
4
  import type {
6
5
  ImageToVideoFeatureConfig,
@@ -5,7 +5,6 @@
5
5
 
6
6
  import { useMemo, useCallback } from "react";
7
7
 
8
- declare const __DEV__: boolean;
9
8
  import { useFormState, type UseFormStateOptions } from "./useFormState";
10
9
  import { useGeneration } from "./useGeneration";
11
10
  import type {
@@ -5,7 +5,6 @@
5
5
 
6
6
  import { useState, useCallback } from "react";
7
7
 
8
- declare const __DEV__: boolean;
9
8
  import * as MediaLibrary from "expo-media-library";
10
9
  import * as Sharing from "expo-sharing";
11
10
  import {
@@ -9,7 +9,6 @@ import { WizardInputType, type WizardConfigOptions } from "./wizard-input.types"
9
9
  import { detectWizardInputType, SCENARIO_TO_WIZARD_INPUT_MAP } from "./wizard-input-detector";
10
10
  import { getConfigFactory } from "./wizard-step-factories";
11
11
 
12
- declare const __DEV__: boolean;
13
12
 
14
13
  const scenarioWizardConfigs: Record<string, WizardFeatureConfig> = {};
15
14
 
@@ -6,7 +6,6 @@
6
6
 
7
7
  import type { Scenario, ScenarioOutputType } from "../domain/Scenario";
8
8
 
9
- declare const __DEV__: boolean;
10
9
 
11
10
  /** Configured scenario with required outputType */
12
11
  export interface ConfiguredScenario extends Scenario {
@@ -16,7 +16,6 @@ import type {
16
16
  TextToImageGenerationRequest,
17
17
  } from "../../domain/types";
18
18
 
19
- declare const __DEV__: boolean;
20
19
 
21
20
  export interface UseGenerationOptions {
22
21
  formState: TextToImageFormState;
@@ -17,7 +17,6 @@ import type {
17
17
  TextToVideoResultExtractor,
18
18
  } from "../../domain/types";
19
19
 
20
- declare const __DEV__: boolean;
21
20
 
22
21
  /**
23
22
  * Options for text-to-video execution
@@ -1,6 +1,5 @@
1
1
  import { executeTextToVideo } from "../../infrastructure/services";
2
2
 
3
- declare const __DEV__: boolean;
4
3
  import type { GenerationStrategy } from "../../../../presentation/hooks/generation";
5
4
  import type {
6
5
  TextToVideoConfig,
@@ -10,7 +10,6 @@ import type {
10
10
  } from "../../domain/types";
11
11
  import { INITIAL_FORM_STATE } from "../../domain/types";
12
12
 
13
- declare const __DEV__: boolean;
14
13
 
15
14
  export interface UseTextToVideoFormProps {
16
15
  initialValues?: Partial<TextToVideoFormState>;
@@ -5,7 +5,6 @@
5
5
 
6
6
  import type { IAppServices, PartialAppServices } from "../../domain/interfaces/app-services.interface";
7
7
 
8
- declare const __DEV__: boolean;
9
8
 
10
9
  let appServices: IAppServices | null = null;
11
10
 
@@ -7,7 +7,6 @@ import { failure, success, type Result } from "../../domain/types/result.types";
7
7
  import type { IAIProvider } from "../../domain/interfaces";
8
8
  import type { BaseExecutorOptions } from "./base-executor.types";
9
9
 
10
- declare const __DEV__: boolean;
11
10
 
12
11
  export abstract class BaseExecutor<TRequest, TResult, TOutput> {
13
12
  protected readonly logPrefix: string;
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { withErrorHandling } from "../utils/error-handlers";
7
- import { getErrorMessage } from "../utils/error-extractors";
7
+ import { getErrorMessage } from "../utils/message-extractor";
8
8
  import { retryWithBackoff } from "../utils/error-retry";
9
9
  import { isNetworkError } from "../utils/error-classifiers";
10
10
  import { env } from "../config/env.config";
@@ -12,7 +12,6 @@ import type { RequestOptions, ApiResponse } from "./api-client.types";
12
12
  import { executeRequest, isSuccessResponse, extractErrorMessage } from "./http-request-executor";
13
13
  import { parseResponse, createSuccessResponse, createErrorResponse } from "./http-response-parser";
14
14
 
15
- declare const __DEV__: boolean;
16
15
 
17
16
  /**
18
17
  * Fetches data with timeout, retry, and error handling
@@ -9,9 +9,8 @@ export interface DebugOptions {
9
9
  readonly tag?: string;
10
10
  }
11
11
 
12
- declare const __DEV__: boolean;
13
-
14
- const isDev = typeof __DEV__ !== "undefined" && __DEV__;
12
+ /** Single source of truth for development environment detection */
13
+ export const isDev = typeof __DEV__ !== "undefined" && __DEV__;
15
14
 
16
15
  function formatMessage(tag: string | undefined, message: string): string {
17
16
  return tag ? `[${tag}] ${message}` : message;
@@ -2,5 +2,5 @@
2
2
  * Logging utilities
3
3
  */
4
4
 
5
- export { debug } from "./debug.util";
5
+ export { debug, isDev } from "./debug.util";
6
6
  export type { DebugOptions } from "./debug.util";
@@ -6,7 +6,6 @@
6
6
 
7
7
  import React, { createContext, useContext, useCallback, useMemo, type ReactNode } from "react";
8
8
 
9
- declare const __DEV__: boolean;
10
9
 
11
10
  export interface GenerationModels {
12
11
  readonly imageMultiRef?: string;
@@ -13,7 +13,6 @@ 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
 
16
- declare const __DEV__: boolean;
17
16
 
18
17
  export interface OrchestratorConfig {
19
18
  polling?: Partial<PollingConfig>;
@@ -8,7 +8,6 @@ import { formatBase64 } from "../utils/base64.util";
8
8
  import { validateURL } from "../validation/base-validator";
9
9
  import { env } from "../config/env.config";
10
10
 
11
- declare const __DEV__: boolean;
12
11
 
13
12
  /** Generation timeout in milliseconds */
14
13
  const GENERATION_TIMEOUT_MS = env.generationMultiImageTimeoutMs;
@@ -5,8 +5,6 @@
5
5
 
6
6
  import type { IAIProvider } from "../../domain/interfaces";
7
7
 
8
- declare const __DEV__: boolean | undefined;
9
-
10
8
  class ProviderRegistry {
11
9
  private providers: Map<string, IAIProvider> = new Map();
12
10
  private activeProviderId: string | null = null;
@@ -6,7 +6,6 @@
6
6
  import type { IAIProvider } from "../../domain/interfaces";
7
7
  import { providerRegistry } from "./provider-registry.service";
8
8
 
9
- declare const __DEV__: boolean;
10
9
 
11
10
  export class ProviderValidator {
12
11
  getProvider(): IAIProvider {
@@ -4,7 +4,6 @@
4
4
 
5
5
  import type { AIErrorInfo } from "../../domain/entities";
6
6
 
7
- declare const __DEV__: boolean;
8
7
 
9
8
  export function matchesPatterns(message: string, patterns: readonly string[]): boolean {
10
9
  const lowerMessage = message.toLowerCase();
@@ -13,7 +13,6 @@ import {
13
13
  } from "./error-patterns.constants";
14
14
  import { matchesPatterns, getStatusCode, logClassification } from "./classifier-helpers";
15
15
 
16
- declare const __DEV__: boolean;
17
16
 
18
17
  export function classifyError(error: unknown): AIErrorInfo {
19
18
  const message = error instanceof Error ? error.message : String(error);
@@ -2,7 +2,7 @@
2
2
  * Error Handling Utilities
3
3
  */
4
4
 
5
- import { getErrorMessage } from "./error-extractors";
5
+ import { getErrorMessage } from "./message-extractor";
6
6
 
7
7
  /**
8
8
  * Sanitizes error message to prevent information disclosure
@@ -50,5 +50,4 @@ export async function withErrorHandling<T>(
50
50
  }
51
51
  }
52
52
 
53
- declare const __DEV__: boolean;
54
53
 
@@ -2,7 +2,7 @@
2
2
  * Error Retry Utilities
3
3
  */
4
4
 
5
- import { getErrorMessage } from "./error-extractors";
5
+ import { getErrorMessage } from "./message-extractor";
6
6
 
7
7
  /**
8
8
  * Retry function with exponential backoff
@@ -7,7 +7,6 @@ import { readFileAsBase64 } from "@umituz/react-native-design-system";
7
7
  import { getAuthService, getCreditService, getPaywallService, isAppServicesConfigured } from "../config/app-services.config";
8
8
  import { env } from "../config/env.config";
9
9
 
10
- declare const __DEV__: boolean;
11
10
 
12
11
  export type ImageSelector = () => Promise<string | null>;
13
12
  export type VideoSaver = (uri: string) => Promise<void>;
@@ -4,7 +4,6 @@
4
4
 
5
5
  export * from "./error-classification";
6
6
  export * from "./error-classifiers";
7
- export * from "./error-extractors";
8
7
  export * from "./error-handlers";
9
8
  export * from "./error-factory";
10
9
  export * from "./error-types";
@@ -4,7 +4,24 @@
4
4
 
5
5
  import { GenerationErrorType, isGenerationError } from "./error-factory";
6
6
 
7
- declare const __DEV__: boolean;
7
+ /**
8
+ * Safely extracts error message from unknown error type
9
+ * Generic utility for any error - no domain-specific logic
10
+ */
11
+ export function getErrorMessage(error: unknown, prefix?: string): string {
12
+ let message = "An unknown error occurred";
13
+
14
+ if (error instanceof Error) {
15
+ message = error.message;
16
+ } else if (typeof error === "string") {
17
+ message = error;
18
+ } else if (error && typeof error === "object" && "message" in error) {
19
+ message = String((error as { message: unknown }).message);
20
+ }
21
+
22
+ return prefix ? `${prefix}: ${message}` : message;
23
+ }
24
+
8
25
 
9
26
  /**
10
27
  * Get translation key from error (returns key if GenerationError, null otherwise)
@@ -7,7 +7,6 @@ import { providerRegistry } from "../services/provider-registry.service";
7
7
  import { cleanBase64 } from "./index";
8
8
  import type { IAIProvider, VideoFeatureInputData, ImageFeatureInputData } from "../../domain/interfaces";
9
9
 
10
- declare const __DEV__: boolean;
11
10
 
12
11
  export type ProviderValidationResult =
13
12
  | { success: true; provider: IAIProvider }
@@ -6,7 +6,6 @@
6
6
 
7
7
  import type { ExtractionRule } from "./extraction-rules";
8
8
 
9
- declare const __DEV__: boolean;
10
9
 
11
10
  /**
12
11
  * Get value from object by path array
@@ -27,7 +27,6 @@ export interface GenerateButtonProps {
27
27
  readonly style?: ViewStyle;
28
28
  }
29
29
 
30
- declare const __DEV__: boolean;
31
30
 
32
31
  export const GenerateButton: React.FC<GenerateButtonProps> = ({
33
32
  isDisabled = false,
@@ -15,7 +15,6 @@ import type {
15
15
  UseGenerationOrchestratorReturn,
16
16
  } from "./types";
17
17
 
18
- declare const __DEV__: boolean;
19
18
 
20
19
  const INITIAL_STATE = { status: "idle" as const, isGenerating: false, result: null, error: null };
21
20
 
@@ -7,7 +7,6 @@ import { useState, useCallback } from "react";
7
7
  import { MediaPickerService, MediaQuality } from "@umituz/react-native-design-system";
8
8
  import { prepareImage } from "../../../infrastructure/utils/feature-utils";
9
9
 
10
- declare const __DEV__: boolean;
11
10
 
12
11
  export interface ImagePickerState {
13
12
  readonly uri: string | null;
@@ -1,11 +0,0 @@
1
- /**
2
- * AI Model Constants
3
- * Single Source of Truth for all AI model IDs
4
- */
5
-
6
- export const DEFAULT_MODELS = {
7
- TEXT_TO_IMAGE: "xai/grok-imagine-image",
8
- TEXT_TO_VIDEO: "fal-ai/ltx-video",
9
- IMAGE_TO_VIDEO: "fal-ai/ltx-video",
10
- SCENARIO_VIDEO: "fal-ai/ltx-video",
11
- } as const;
@@ -1,18 +0,0 @@
1
- /**
2
- * Text-to-Image Models Configuration
3
- */
4
-
5
- import type { FalModelConfig } from "@umituz/react-native-ai-fal-provider";
6
-
7
- export const TEXT_TO_IMAGE_MODELS: FalModelConfig[] = [
8
- {
9
- id: "xai/grok-imagine-image",
10
- name: "Grok Imagine",
11
- type: "text-to-image",
12
- isDefault: true,
13
- isActive: true,
14
- pricing: { freeUserCost: 0.5, premiumUserCost: 0.25 },
15
- description: "X.AI's cost-effective text-to-image generation ($0.02/image)",
16
- order: 1,
17
- },
18
- ];
@@ -1,174 +0,0 @@
1
- /**
2
- * Production-Ready Logging Utility
3
- * Provides structured logging with levels and context
4
- */
5
-
6
- declare const __DEV__: boolean;
7
-
8
- export enum LogLevel {
9
- DEBUG = 0,
10
- INFO = 1,
11
- WARN = 2,
12
- ERROR = 3,
13
- NONE = 4,
14
- }
15
-
16
- export interface LogContext {
17
- readonly [key: string]: unknown;
18
- }
19
-
20
- export interface LogEntry {
21
- readonly level: LogLevel;
22
- readonly timestamp: number;
23
- readonly message: string;
24
- readonly context?: LogContext;
25
- readonly error?: Error;
26
- }
27
-
28
- class Logger {
29
- private minLevel: LogLevel;
30
- private logs: LogEntry[] = [];
31
- private maxLogs = 1000;
32
-
33
- constructor() {
34
- // In production, only log WARN and ERROR
35
- this.minLevel =
36
- typeof __DEV__ !== "undefined" && __DEV__ ? LogLevel.DEBUG : LogLevel.WARN;
37
- }
38
-
39
- setMinLevel(level: LogLevel): void {
40
- this.minLevel = level;
41
- }
42
-
43
- private shouldLog(level: LogLevel): boolean {
44
- return level >= this.minLevel;
45
- }
46
-
47
- private addLog(entry: LogEntry): void {
48
- this.logs.push(entry);
49
- // Keep only last maxLogs entries
50
- if (this.logs.length > this.maxLogs) {
51
- this.logs.shift();
52
- }
53
- }
54
-
55
- debug(message: string, context?: LogContext): void {
56
- if (!this.shouldLog(LogLevel.DEBUG)) return;
57
-
58
- const entry: LogEntry = {
59
- level: LogLevel.DEBUG,
60
- timestamp: Date.now(),
61
- message,
62
- context,
63
- };
64
-
65
- this.addLog(entry);
66
-
67
- if (typeof __DEV__ !== "undefined" && __DEV__) {
68
- console.log(`[DEBUG] ${message}`, context || "");
69
- }
70
- }
71
-
72
- info(message: string, context?: LogContext): void {
73
- if (!this.shouldLog(LogLevel.INFO)) return;
74
-
75
- const entry: LogEntry = {
76
- level: LogLevel.INFO,
77
- timestamp: Date.now(),
78
- message,
79
- context,
80
- };
81
-
82
- this.addLog(entry);
83
-
84
- if (typeof __DEV__ !== "undefined" && __DEV__) {
85
- console.info(`[INFO] ${message}`, context || "");
86
- }
87
- }
88
-
89
- warn(message: string, context?: LogContext): void {
90
- if (!this.shouldLog(LogLevel.WARN)) return;
91
-
92
- const entry: LogEntry = {
93
- level: LogLevel.WARN,
94
- timestamp: Date.now(),
95
- message,
96
- context,
97
- };
98
-
99
- this.addLog(entry);
100
- console.warn(`[WARN] ${message}`, context || "");
101
- }
102
-
103
- error(message: string, error?: Error | unknown, context?: LogContext): void {
104
- if (!this.shouldLog(LogLevel.ERROR)) return;
105
-
106
- const errorObj =
107
- error instanceof Error ? error : error ? new Error(String(error)) : undefined;
108
-
109
- const entry: LogEntry = {
110
- level: LogLevel.ERROR,
111
- timestamp: Date.now(),
112
- message,
113
- context,
114
- error: errorObj,
115
- };
116
-
117
- this.addLog(entry);
118
- console.error(`[ERROR] ${message}`, errorObj || "", context || "");
119
- }
120
-
121
- getLogs(level?: LogLevel): readonly LogEntry[] {
122
- if (level !== undefined) {
123
- return this.logs.filter((log) => log.level >= level);
124
- }
125
- return this.logs;
126
- }
127
-
128
- clearLogs(): void {
129
- this.logs = [];
130
- }
131
-
132
- // Convenience methods for specific domains
133
- processing(message: string, context?: LogContext): void {
134
- this.debug(`[Processing] ${message}`, context);
135
- }
136
-
137
- generation(message: string, context?: LogContext): void {
138
- this.debug(`[Generation] ${message}`, context);
139
- }
140
-
141
- polling(message: string, context?: LogContext): void {
142
- this.debug(`[Polling] ${message}`, context);
143
- }
144
-
145
- moderation(message: string, context?: LogContext): void {
146
- this.info(`[Moderation] ${message}`, context);
147
- }
148
-
149
- network(message: string, context?: LogContext): void {
150
- this.info(`[Network] ${message}`, context);
151
- }
152
-
153
- storage(message: string, context?: LogContext): void {
154
- this.debug(`[Storage] ${message}`, context);
155
- }
156
-
157
- validation(message: string, context?: LogContext): void {
158
- this.warn(`[Validation] ${message}`, context);
159
- }
160
- }
161
-
162
- // Singleton instance
163
- export const logger = new Logger();
164
-
165
- // Development helper
166
- export function setDevelopmentMode(): void {
167
- logger.setMinLevel(LogLevel.DEBUG);
168
- }
169
-
170
- // Production helper
171
- export function setProductionMode(): void {
172
- logger.setMinLevel(LogLevel.WARN);
173
- }
174
-
@@ -1,24 +0,0 @@
1
- /**
2
- * Error Message Extraction
3
- */
4
-
5
- /**
6
- * Safely extracts error message from unknown error type
7
- * @param error - The error to extract message from
8
- * @param prefix - Optional prefix to prepend to error message
9
- * @returns The extracted error message with optional prefix
10
- */
11
- export function getErrorMessage(error: unknown, prefix?: string): string {
12
- let message = "An unknown error occurred";
13
-
14
- if (error instanceof Error) {
15
- message = error.message;
16
- } else if (typeof error === "string") {
17
- message = error;
18
- } else if (error && typeof error === "object" && "message" in error) {
19
- message = String(error.message);
20
- }
21
-
22
- return prefix ? `${prefix}: ${message}` : message;
23
- }
24
-