@umituz/react-native-ai-fal-provider 3.0.2 → 3.1.1

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": "3.0.2",
3
+ "version": "3.1.1",
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",
@@ -111,3 +111,11 @@ export {
111
111
 
112
112
  export type { FalJobMetadata, IJobStorage } from "../infrastructure/utils";
113
113
  export { InMemoryJobStorage } from "../infrastructure/utils";
114
+
115
+ // Pricing Utilities
116
+ export {
117
+ calculateVideoCredits,
118
+ calculateImageCredits,
119
+ calculateCreditsFromConfig,
120
+ } from "../infrastructure/utils";
121
+ export type { GenerationResolution } from "../infrastructure/utils";
@@ -105,3 +105,10 @@ export {
105
105
 
106
106
  export { FalGenerationStateManager } from "./fal-generation-state-manager.util";
107
107
  export type { GenerationState } from "./fal-generation-state-manager.util";
108
+
109
+ export {
110
+ calculateVideoCredits,
111
+ calculateImageCredits,
112
+ calculateCreditsFromConfig,
113
+ } from "./pricing/fal-pricing.util";
114
+ export type { GenerationResolution } from "./pricing/fal-pricing.util";
@@ -0,0 +1,53 @@
1
+ import type { VideoModelConfig } from "@umituz/react-native-ai-generation-content";
2
+
3
+ /**
4
+ * FAL AI Pricing Utilities
5
+ * Single Responsibility: Credit calculations for FAL AI generation
6
+ *
7
+ * Pricing:
8
+ * - 480p video: $0.05/sec
9
+ * - 720p video: $0.07/sec
10
+ * - Image with input: +$0.002
11
+ * - Image generation: $0.03
12
+ * Markup: 3.5x, Credit price: $0.10
13
+ */
14
+
15
+ const COSTS = {
16
+ VIDEO_480P_PER_SECOND: 0.05,
17
+ VIDEO_720P_PER_SECOND: 0.07,
18
+ IMAGE_INPUT: 0.002,
19
+ IMAGE: 0.03,
20
+ } as const;
21
+
22
+ const MARKUP = 3.5;
23
+ const CREDIT_PRICE = 0.1;
24
+
25
+ export type GenerationResolution = "480p" | "720p";
26
+
27
+ export function calculateVideoCredits(
28
+ duration: number,
29
+ resolution: GenerationResolution,
30
+ hasImageInput: boolean = false,
31
+ ): number {
32
+ const costPerSec =
33
+ resolution === "480p"
34
+ ? COSTS.VIDEO_480P_PER_SECOND
35
+ : COSTS.VIDEO_720P_PER_SECOND;
36
+ let cost = costPerSec * duration;
37
+ if (hasImageInput) cost += COSTS.IMAGE_INPUT;
38
+ return Math.ceil((cost * MARKUP) / CREDIT_PRICE);
39
+ }
40
+
41
+ export function calculateImageCredits(): number {
42
+ return Math.ceil((COSTS.IMAGE * MARKUP) / CREDIT_PRICE);
43
+ }
44
+
45
+ export function calculateCreditsFromConfig(
46
+ config: VideoModelConfig,
47
+ duration: number,
48
+ resolution: string,
49
+ ): number {
50
+ const costPerSec = config.pricing.costPerSecond[resolution] ?? 0;
51
+ const cost = costPerSec * duration;
52
+ return Math.max(1, Math.ceil((cost * MARKUP) / CREDIT_PRICE));
53
+ }