@umituz/react-native-ai-fal-provider 2.2.1 → 2.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-fal-provider",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "FAL AI provider for React Native - implements IAIProvider interface for unified AI generation",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -2,13 +2,7 @@
2
2
  * Domain Types Index
3
3
  */
4
4
 
5
- export type {
6
- ModelType,
7
- ModelSelectionConfig,
8
- ModelSelectionState,
9
- ModelSelectionActions,
10
- UseModelsReturn,
11
- } from "./model-selection.types";
5
+ export type { ModelType } from "./model-selection.types";
12
6
 
13
7
  export type {
14
8
  UpscaleOptions,
@@ -1,14 +1,9 @@
1
1
  /**
2
2
  * Model Selection Types
3
- * Generic types for model selection - applications provide their own model lists
4
3
  */
5
4
 
6
- import type { FalModelConfig } from "../constants/default-models.constants";
7
5
  import type { FalModelType } from "../entities/fal.types";
8
6
 
9
- /**
10
- * Public API model types (subset of FalModelType)
11
- */
12
7
  export type ModelType = Extract<
13
8
  FalModelType,
14
9
  "text-to-image" | "text-to-video" | "image-to-video" | "text-to-voice"
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * FAL Provider - Implements IAIProvider interface
3
- * Orchestrates FAL AI operations with Promise Deduplication
4
3
  */
5
4
 
6
5
  import { fal } from "@fal-ai/client";
@@ -9,10 +8,9 @@ import type {
9
8
  RunOptions, ProviderCapabilities, ImageFeatureType, VideoFeatureType,
10
9
  ImageFeatureInputData, VideoFeatureInputData,
11
10
  } from "../../domain/types";
12
- import type { CostTrackerConfig } from "../../domain/entities/cost-tracking.types";
13
11
  import { DEFAULT_FAL_CONFIG, FAL_CAPABILITIES } from "./fal-provider.constants";
14
12
  import { handleFalSubscription, handleFalRun } from "./fal-provider-subscription";
15
- import { CostTracker, executeWithCostTracking, preprocessInput } from "../utils";
13
+ import { preprocessInput } from "../utils";
16
14
  import {
17
15
  createRequestKey, getExistingRequest, storeRequest,
18
16
  removeRequest, cancelAllRequests, hasActiveRequests,
@@ -26,7 +24,6 @@ export class FalProvider implements IAIProvider {
26
24
 
27
25
  private apiKey: string | null = null;
28
26
  private initialized = false;
29
- private costTracker: CostTracker | null = null;
30
27
 
31
28
  initialize(config: AIProviderConfig): void {
32
29
  this.apiKey = config.apiKey;
@@ -41,22 +38,6 @@ export class FalProvider implements IAIProvider {
41
38
  this.initialized = true;
42
39
  }
43
40
 
44
- enableCostTracking(config?: CostTrackerConfig): void {
45
- this.costTracker = new CostTracker(config);
46
- }
47
-
48
- disableCostTracking(): void {
49
- this.costTracker = null;
50
- }
51
-
52
- isCostTrackingEnabled(): boolean {
53
- return this.costTracker !== null;
54
- }
55
-
56
- getCostTracker(): CostTracker | null {
57
- return this.costTracker;
58
- }
59
-
60
41
  isInitialized(): boolean {
61
42
  return this.initialized;
62
43
  }
@@ -70,19 +51,19 @@ export class FalProvider implements IAIProvider {
70
51
  }
71
52
 
72
53
  getImageFeatureModel(_feature: ImageFeatureType): string {
73
- throw new Error("Feature-specific models are not supported in this provider. Use the main app's feature implementations.");
54
+ throw new Error("Feature-specific models not supported. Use main app's feature implementations.");
74
55
  }
75
56
 
76
57
  buildImageFeatureInput(_feature: ImageFeatureType, _data: ImageFeatureInputData): Record<string, unknown> {
77
- throw new Error("Feature-specific input building is not supported in this provider. Use the main app's feature implementations.");
58
+ throw new Error("Feature-specific input building not supported. Use main app's feature implementations.");
78
59
  }
79
60
 
80
61
  getVideoFeatureModel(_feature: VideoFeatureType): string {
81
- throw new Error("Feature-specific models are not supported in this provider. Use the main app's feature implementations.");
62
+ throw new Error("Feature-specific models not supported. Use main app's feature implementations.");
82
63
  }
83
64
 
84
65
  buildVideoFeatureInput(_feature: VideoFeatureType, _data: VideoFeatureInputData): Record<string, unknown> {
85
- throw new Error("Feature-specific input building is not supported in this provider. Use the main app's feature implementations.");
66
+ throw new Error("Feature-specific input building not supported. Use main app's feature implementations.");
86
67
  }
87
68
 
88
69
  private validateInit(): void {
@@ -97,13 +78,13 @@ export class FalProvider implements IAIProvider {
97
78
 
98
79
  async getJobStatus(model: string, requestId: string): Promise<JobStatus> {
99
80
  this.validateInit();
100
- validateInput(model, {}); // Validate model ID only
81
+ validateInput(model, {});
101
82
  return queueOps.getJobStatus(model, requestId);
102
83
  }
103
84
 
104
85
  async getJobResult<T = unknown>(model: string, requestId: string): Promise<T> {
105
86
  this.validateInit();
106
- validateInput(model, {}); // Validate model ID only
87
+ validateInput(model, {});
107
88
  return queueOps.getJobResult<T>(model, requestId);
108
89
  }
109
90
 
@@ -119,15 +100,10 @@ export class FalProvider implements IAIProvider {
119
100
  const key = createRequestKey(model, processedInput);
120
101
 
121
102
  const existing = getExistingRequest<T>(key);
122
- if (existing) {
123
- return existing.promise;
124
- }
103
+ if (existing) return existing.promise;
125
104
 
126
105
  const abortController = new AbortController();
127
- const tracker = this.costTracker;
128
106
 
129
- // Create promise with resolvers using definite assignment
130
- // This prevents race conditions and ensures type safety
131
107
  let resolvePromise!: (value: T) => void;
132
108
  let rejectPromise!: (error: unknown) => void;
133
109
  const promise = new Promise<T>((resolve, reject) => {
@@ -135,32 +111,17 @@ export class FalProvider implements IAIProvider {
135
111
  rejectPromise = reject;
136
112
  });
137
113
 
138
- // Store promise immediately to enable request deduplication
139
- // Multiple simultaneous calls with same params will get the same promise
140
114
  storeRequest(key, { promise, abortController, createdAt: Date.now() });
141
115
 
142
- // Execute the actual operation and resolve/reject the stored promise
143
- // Note: This promise chain is not awaited - it runs independently
144
- executeWithCostTracking({
145
- tracker,
146
- model,
147
- operation: "subscribe",
148
- execute: () => handleFalSubscription<T>(model, processedInput, options, abortController.signal),
149
- getRequestId: (res) => res.requestId ?? undefined,
150
- })
151
- .then((res) => {
152
- resolvePromise(res.result);
153
- })
154
- .catch((error) => {
155
- rejectPromise(error);
156
- })
116
+ handleFalSubscription<T>(model, processedInput, options, abortController.signal)
117
+ .then((res) => resolvePromise(res.result))
118
+ .catch((error) => rejectPromise(error))
157
119
  .finally(() => {
158
120
  try {
159
121
  removeRequest(key);
160
122
  } catch (cleanupError) {
161
- // Log but don't throw - cleanup errors shouldn't affect the operation result
162
123
  console.error(
163
- `[fal-provider] Error removing request from store: ${key}`,
124
+ `[fal-provider] Error removing request: ${key}`,
164
125
  cleanupError instanceof Error ? cleanupError.message : String(cleanupError)
165
126
  );
166
127
  }
@@ -179,19 +140,13 @@ export class FalProvider implements IAIProvider {
179
140
  throw new Error("Request cancelled by user");
180
141
  }
181
142
 
182
- return executeWithCostTracking({
183
- tracker: this.costTracker,
184
- model,
185
- operation: "run",
186
- execute: () => handleFalRun<T>(model, processedInput, options),
187
- });
143
+ return handleFalRun<T>(model, processedInput, options);
188
144
  }
189
145
 
190
146
  reset(): void {
191
147
  this.cancelCurrentRequest();
192
148
  this.apiKey = null;
193
149
  this.initialized = false;
194
- this.costTracker = null;
195
150
  }
196
151
 
197
152
  cancelCurrentRequest(): void {
@@ -4,7 +4,7 @@
4
4
 
5
5
  export { FalProvider, falProvider } from "./fal-provider";
6
6
  export type { FalProvider as FalProviderType } from "./fal-provider";
7
- export { falModelsService, type FalModelConfig, type ModelSelectionResult } from "./fal-models.service";
7
+ export { falModelsService, type FalModelConfig } from "./fal-models.service";
8
8
  export { NSFWContentError } from "./nsfw-content-error";
9
9
 
10
10
  // Request store exports for advanced use cases