vargai 0.4.0-alpha47 → 0.4.0-alpha48
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 +1 -1
- package/src/ai-sdk/providers/fal.ts +39 -21
package/package.json
CHANGED
|
@@ -45,28 +45,46 @@ function createMemoryCache(): CacheStorage {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// TODO: allow passing CacheStorage via providerOptions.fal.cacheStorage for proper serverless support
|
|
48
|
-
function isFilesystemWritable(): boolean {
|
|
49
|
-
try {
|
|
50
|
-
const testPath = `.cache/.write-test-${Date.now()}`;
|
|
51
|
-
Bun.spawnSync(["mkdir", "-p", ".cache"]);
|
|
52
|
-
const result = Bun.spawnSync(["touch", testPath]);
|
|
53
|
-
if (result.exitCode === 0) {
|
|
54
|
-
Bun.spawnSync(["rm", testPath]);
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
} catch {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const USE_FILE_CACHE = isFilesystemWritable();
|
|
64
|
-
|
|
65
48
|
function createFalCache(name: string): CacheStorage {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
let cache: CacheStorage | null = null;
|
|
50
|
+
let useFallback = false;
|
|
51
|
+
const fallback = createMemoryCache();
|
|
52
|
+
|
|
53
|
+
const getCache = () => {
|
|
54
|
+
if (useFallback) return fallback;
|
|
55
|
+
if (!cache) cache = fileCache({ dir: `.cache/${name}` });
|
|
56
|
+
return cache;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
async get(key) {
|
|
61
|
+
if (useFallback) return fallback.get(key);
|
|
62
|
+
try {
|
|
63
|
+
return await getCache().get(key);
|
|
64
|
+
} catch {
|
|
65
|
+
useFallback = true;
|
|
66
|
+
return fallback.get(key);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
async set(key, value, ttl) {
|
|
70
|
+
if (useFallback) return fallback.set(key, value, ttl);
|
|
71
|
+
try {
|
|
72
|
+
await getCache().set(key, value, ttl);
|
|
73
|
+
} catch {
|
|
74
|
+
useFallback = true;
|
|
75
|
+
await fallback.set(key, value, ttl);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async delete(key) {
|
|
79
|
+
if (useFallback) return fallback.delete(key);
|
|
80
|
+
try {
|
|
81
|
+
await getCache().delete(key);
|
|
82
|
+
} catch {
|
|
83
|
+
useFallback = true;
|
|
84
|
+
await fallback.delete(key);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
const pendingStorage = createFalCache("fal-pending");
|