vargai 0.4.0-alpha40 → 0.4.0-alpha41

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
@@ -68,7 +68,7 @@
68
68
  "sharp": "^0.34.5",
69
69
  "zod": "^4.2.1"
70
70
  },
71
- "version": "0.4.0-alpha40",
71
+ "version": "0.4.0-alpha41",
72
72
  "exports": {
73
73
  ".": "./src/index.ts",
74
74
  "./ai": "./src/ai-sdk/index.ts",
@@ -11,6 +11,7 @@ import {
11
11
  type TranscriptionModelV3CallOptions,
12
12
  } from "@ai-sdk/provider";
13
13
  import { fal } from "@fal-ai/client";
14
+ import { uploadBuffer as uploadToR2 } from "../../providers/storage";
14
15
  import { fileCache } from "../file-cache";
15
16
  import type { VideoModelV3, VideoModelV3CallOptions } from "../video-model";
16
17
 
@@ -22,10 +23,12 @@ interface PendingRequest {
22
23
 
23
24
  const pendingStorage = fileCache({ dir: ".cache/fal-pending" });
24
25
 
25
- const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
26
- const FAL_TIMEOUT_MS = process.env.FAL_TIMEOUT_MS
27
- ? Number.parseInt(process.env.FAL_TIMEOUT_MS, 10)
28
- : DEFAULT_TIMEOUT_MS;
26
+ const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
27
+ const FAL_TIMEOUT_MS = (() => {
28
+ if (!process.env.FAL_TIMEOUT_MS) return DEFAULT_TIMEOUT_MS;
29
+ const parsed = Number.parseInt(process.env.FAL_TIMEOUT_MS, 10);
30
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_TIMEOUT_MS;
31
+ })();
29
32
 
30
33
  const VIDEO_MODELS: Record<string, { t2v: string; i2v: string }> = {
31
34
  // Kling v2.6 - latest with native audio generation
@@ -180,6 +183,21 @@ function detectImageType(bytes: Uint8Array): string | undefined {
180
183
  return undefined;
181
184
  }
182
185
 
186
+ function getExtFromMediaType(mediaType: string): string {
187
+ const map: Record<string, string> = {
188
+ "image/png": "png",
189
+ "image/jpeg": "jpg",
190
+ "image/gif": "gif",
191
+ "image/webp": "webp",
192
+ "video/mp4": "mp4",
193
+ "video/webm": "webm",
194
+ "audio/mpeg": "mp3",
195
+ "audio/wav": "wav",
196
+ "audio/ogg": "ogg",
197
+ };
198
+ return map[mediaType] ?? "bin";
199
+ }
200
+
183
201
  async function fileToUrl(file: ImageModelV3File): Promise<string> {
184
202
  if (file.type === "url") return file.url;
185
203
  const data = file.data;
@@ -187,13 +205,18 @@ async function fileToUrl(file: ImageModelV3File): Promise<string> {
187
205
  typeof data === "string"
188
206
  ? Uint8Array.from(atob(data), (c) => c.charCodeAt(0))
189
207
  : data;
190
- // Use mediaType from file if available, otherwise detect from bytes or default to png
191
208
  const mediaType = file.mediaType ?? detectImageType(bytes) ?? "image/png";
192
- return fal.storage.upload(new Blob([bytes], { type: mediaType }));
209
+ const ext = getExtFromMediaType(mediaType);
210
+ const hash = Bun.hash(bytes).toString(16);
211
+ const key = `fal-uploads/${hash}.${ext}`;
212
+ return uploadToR2(bytes, key, mediaType);
193
213
  }
194
214
 
195
215
  async function uploadBuffer(buffer: ArrayBuffer): Promise<string> {
196
- return fal.storage.upload(new Blob([buffer]));
216
+ const bytes = new Uint8Array(buffer);
217
+ const hash = Bun.hash(bytes).toString(16);
218
+ const key = `fal-uploads/${hash}.bin`;
219
+ return uploadToR2(bytes, key);
197
220
  }
198
221
 
199
222
  export function computePendingKey(