@eduardo191labs/opencode-free-pi 0.5.6 → 0.6.0
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/README.md +33 -39
- package/dist/catalog/catalog.js +1 -21
- package/dist/catalog/live.d.ts +55 -0
- package/dist/catalog/live.js +229 -0
- package/dist/catalog/models.d.ts +7 -2
- package/dist/catalog/models.js +10 -10
- package/dist/catalog/registry.js +5 -15
- package/dist/constants.d.ts +7 -15
- package/dist/constants.js +7 -15
- package/dist/logging.js +2 -2
- package/dist/plugin.js +14 -2
- package/dist/session/events.js +2 -3
- package/dist/session/hooks.js +1 -11
- package/dist/state.d.ts +1 -15
- package/dist/state.js +0 -3
- package/dist/tools/vision-queue.d.ts +1 -1
- package/dist/tools/vision-queue.js +5 -5
- package/dist/tools/vision.js +24 -35
- package/dist/tools/web.js +39 -44
- package/dist/types.d.ts +5 -9
- package/dist/utils/data-dir.d.ts +3 -0
- package/dist/utils/data-dir.js +12 -0
- package/package.json +2 -2
- package/src/catalog/catalog.ts +0 -25
- package/src/catalog/live.ts +277 -0
- package/src/catalog/models.ts +19 -12
- package/src/catalog/registry.ts +6 -21
- package/src/constants.ts +7 -18
- package/src/logging.ts +2 -2
- package/src/plugin.ts +20 -2
- package/src/session/events.ts +6 -3
- package/src/session/hooks.ts +0 -17
- package/src/state.ts +0 -18
- package/src/tools/vision-queue.ts +5 -5
- package/src/tools/vision.ts +26 -38
- package/src/tools/web.ts +49 -59
- package/src/types.ts +5 -8
- package/src/utils/data-dir.ts +14 -0
- package/dist/session/cache.d.ts +0 -15
- package/dist/session/cache.js +0 -57
- package/dist/tools/spend-cache.d.ts +0 -15
- package/dist/tools/spend-cache.js +0 -64
- package/dist/utils/cache.d.ts +0 -7
- package/dist/utils/cache.js +0 -45
- package/src/session/cache.ts +0 -82
- package/src/tools/spend-cache.ts +0 -79
- package/src/utils/cache.ts +0 -49
package/src/utils/cache.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/** Best-effort JSON cache on disk for data fetched over the network. */
|
|
2
|
-
|
|
3
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
6
|
-
|
|
7
|
-
type CacheEntry<T> = { at: number; value: T };
|
|
8
|
-
|
|
9
|
-
export function cacheDir(): string {
|
|
10
|
-
const configured = process.env.FREE_PI_CACHE_DIR?.trim();
|
|
11
|
-
if (configured) return configured;
|
|
12
|
-
return join(homedir(), ".cache", "opencode", "free-pi");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function cachePath(name: string): string {
|
|
16
|
-
return join(cacheDir(), name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Reads a cached value when it is younger than `ttlMs`. Never throws. */
|
|
20
|
-
export async function readCache<T>(
|
|
21
|
-
name: string,
|
|
22
|
-
ttlMs: number,
|
|
23
|
-
): Promise<T | undefined> {
|
|
24
|
-
try {
|
|
25
|
-
const raw = await readFile(cachePath(name), "utf8");
|
|
26
|
-
const entry = JSON.parse(raw) as CacheEntry<T>;
|
|
27
|
-
if (!entry || typeof entry.at !== "number") return undefined;
|
|
28
|
-
if (!Number.isFinite(entry.at)) return undefined;
|
|
29
|
-
if (Date.now() - entry.at > ttlMs) return undefined;
|
|
30
|
-
return entry.value;
|
|
31
|
-
} catch {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Writes a value atomically. Never throws. */
|
|
37
|
-
export async function writeCache<T>(name: string, value: T): Promise<void> {
|
|
38
|
-
try {
|
|
39
|
-
const file = cachePath(name);
|
|
40
|
-
await mkdir(dirname(file), { recursive: true });
|
|
41
|
-
const temp = `${file}.${process.pid}.${Math.random()
|
|
42
|
-
.toString(36)
|
|
43
|
-
.slice(2)}.tmp`;
|
|
44
|
-
await writeFile(temp, JSON.stringify({ at: Date.now(), value }), "utf8");
|
|
45
|
-
await rename(temp, file);
|
|
46
|
-
} catch {
|
|
47
|
-
// The cache is an optimization; failures must not affect the plugin.
|
|
48
|
-
}
|
|
49
|
-
}
|