tokenusage-cli 0.1.0 → 0.2.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/CHANGELOG.md +39 -19
- package/LICENSE +22 -22
- package/README.md +94 -94
- package/THIRD_PARTY_NOTICES.md +140 -140
- package/bin/tokenusage.js +69 -69
- package/package.json +59 -59
- package/src/cli.js +146 -134
- package/src/commands/device-login.js +205 -205
- package/src/commands/diagnostics.js +38 -38
- package/src/commands/doctor.js +110 -110
- package/src/commands/init.js +2484 -2436
- package/src/commands/pause.js +77 -0
- package/src/commands/sessions.js +29 -29
- package/src/commands/status.js +1758 -1747
- package/src/commands/sync.js +8048 -7934
- package/src/commands/uninstall.js +322 -312
- package/src/lib/account-usage-dedup.js +267 -267
- package/src/lib/antigravity-paths.js +48 -48
- package/src/lib/ark-agent-plan-limits.js +438 -438
- package/src/lib/ark-coding-plan-limits.js +537 -537
- package/src/lib/async-queue-reader.js +138 -138
- package/src/lib/atomic-json.js +27 -27
- package/src/lib/bearer-token.js +11 -11
- package/src/lib/categorizer-utils.js +232 -232
- package/src/lib/claude-categorizer.js +1343 -1343
- package/src/lib/claude-config.js +279 -279
- package/src/lib/claude-user-identity.js +56 -56
- package/src/lib/cli-ui.js +179 -179
- package/src/lib/cloud-account.js +541 -541
- package/src/lib/cloud-device-token.js +141 -141
- package/src/lib/cloud-sync-prefs.js +14 -14
- package/src/lib/cloud-usage-reset.js +115 -115
- package/src/lib/codex-config.js +595 -595
- package/src/lib/codex-context-breakdown.js +806 -806
- package/src/lib/codex-model-attribution.js +128 -128
- package/src/lib/codex-rollout-parser.js +1471 -1471
- package/src/lib/codex-service-tier.js +49 -49
- package/src/lib/codex-token-refresh.js +140 -140
- package/src/lib/codex-token-usage.js +195 -195
- package/src/lib/codex-usage-record.js +195 -195
- package/src/lib/collection-pause.js +77 -0
- package/src/lib/command-runner.js +313 -313
- package/src/lib/commandcode-limits.js +317 -317
- package/src/lib/context-health.js +124 -124
- package/src/lib/cursor-config.js +605 -605
- package/src/lib/cursor-store.js +1918 -1918
- package/src/lib/debug-flags.js +7 -7
- package/src/lib/devin-limits.js +249 -249
- package/src/lib/devin-usage.js +212 -212
- package/src/lib/diagnostics.js +383 -383
- package/src/lib/doctor.js +385 -385
- package/src/lib/dumate.js +95 -95
- package/src/lib/fs.js +455 -455
- package/src/lib/function-url.js +14 -14
- package/src/lib/gemini-config.js +291 -291
- package/src/lib/git-outcomes.js +243 -243
- package/src/lib/grok-context-breakdown.js +890 -890
- package/src/lib/grok-hook.js +360 -360
- package/src/lib/grok-limits.js +865 -865
- package/src/lib/grok-usage.js +98 -98
- package/src/lib/heatmap-compact.js +114 -114
- package/src/lib/ingest-sanitize.js +41 -41
- package/src/lib/init-flow.js +42 -42
- package/src/lib/install-resolver.js +170 -170
- package/src/lib/jsonl-lines.js +134 -134
- package/src/lib/kimi-model-repair.js +173 -173
- package/src/lib/kimi-profile.js +61 -61
- package/src/lib/kimi-session.js +216 -216
- package/src/lib/local-api.js +3588 -3588
- package/src/lib/machine-id.js +238 -238
- package/src/lib/multi-install-parser.js +113 -113
- package/src/lib/notify-command.js +38 -38
- package/src/lib/omp-hook.js +589 -589
- package/src/lib/openclaw-cli.js +104 -104
- package/src/lib/openclaw-hook.js +375 -375
- package/src/lib/openclaw-session-plugin.js +560 -560
- package/src/lib/opencode-config.js +121 -121
- package/src/lib/opencode-go-limits.js +807 -807
- package/src/lib/outcomes-engine.js +253 -253
- package/src/lib/passive-mode.js +219 -219
- package/src/lib/pet-packages.js +722 -722
- package/src/lib/pricing/curated-overrides.json +822 -822
- package/src/lib/pricing/index.js +379 -379
- package/src/lib/pricing/litellm-fetcher.js +172 -172
- package/src/lib/pricing/matcher.js +456 -456
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/progress.js +76 -76
- package/src/lib/project-usage-purge.js +117 -117
- package/src/lib/prompt.js +24 -24
- package/src/lib/provider-status.js +104 -104
- package/src/lib/proxy-env.js +489 -489
- package/src/lib/proxy-settings.js +163 -163
- package/src/lib/qoder-cn-cli-limits.js +119 -119
- package/src/lib/qoder-limits.js +880 -880
- package/src/lib/quiet-warnings.js +26 -26
- package/src/lib/rollout.js +26005 -25966
- package/src/lib/runtime-config.js +9 -4
- package/src/lib/scan-roots.js +277 -277
- package/src/lib/scheduled-task.js +145 -0
- package/src/lib/sentry.js +231 -231
- package/src/lib/session-analytics.js +2972 -2972
- package/src/lib/session-performance.js +237 -237
- package/src/lib/session-upload.js +379 -379
- package/src/lib/skill-usage.js +267 -267
- package/src/lib/skills-manager.js +1591 -1591
- package/src/lib/source-metadata.js +48 -48
- package/src/lib/sqlite-reader.js +215 -215
- package/src/lib/star-cta.js +73 -73
- package/src/lib/subscription-manager.js +293 -293
- package/src/lib/subscriptions.js +508 -508
- package/src/lib/sync-report.js +138 -0
- package/src/lib/telemetry.js +193 -193
- package/src/lib/tracker-paths.js +16 -16
- package/src/lib/trae-cn-config.js +548 -548
- package/src/lib/trae-db.js +127 -127
- package/src/lib/trae-snapshot.js +230 -230
- package/src/lib/trae-sqlite.js +143 -143
- package/src/lib/trae-usage.js +121 -121
- package/src/lib/upload-queue.js +134 -134
- package/src/lib/upload-throttle.js +171 -171
- package/src/lib/usage-limits.js +4552 -4552
- package/src/lib/wrapped-aggregator.js +236 -236
- package/src/lib/wsl-probe.js +281 -281
- package/src/lib/zcode-limits.js +1172 -1172
- package/src/lib/zcode-reset-credits.js +66 -66
- package/test/audit-fixes.test.js +200 -0
- package/test/cli-smoke.test.js +53 -53
- package/test/collection-controls.test.js +181 -0
- package/test/ingest-sanitize.test.js +162 -162
- package/test/quiet-warnings.test.js +53 -53
- package/test/session-upload.test.js +427 -427
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
// LiteLLM data loader: 24h disk cache + bundled seed snapshot fallback.
|
|
2
|
-
// Fetches from upstream once when cache is missing or stale, then keeps a
|
|
3
|
-
// per-process in-memory map. fetchModelPricing() is async; subsequent reads
|
|
4
|
-
// (lookupPricing in matcher.js) operate on the in-memory map synchronously.
|
|
5
|
-
|
|
6
|
-
const fs = require("node:fs");
|
|
7
|
-
const fsp = require("node:fs/promises");
|
|
8
|
-
const path = require("node:path");
|
|
9
|
-
|
|
10
|
-
const LITELLM_PRICING_URL =
|
|
11
|
-
"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
|
|
12
|
-
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000; // 24h
|
|
13
|
-
const DEFAULT_FETCH_TIMEOUT_MS = 10_000;
|
|
14
|
-
const SEED_SNAPSHOT_PATH = path.resolve(__dirname, "seed-snapshot.json");
|
|
15
|
-
|
|
16
|
-
function readJsonSync(p) {
|
|
17
|
-
const raw = fs.readFileSync(p, "utf8");
|
|
18
|
-
return JSON.parse(raw);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function readJsonAsync(p) {
|
|
22
|
-
const raw = await fsp.readFile(p, "utf8");
|
|
23
|
-
return JSON.parse(raw);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isFresh(stat, ttlMs) {
|
|
27
|
-
if (!stat) return false;
|
|
28
|
-
return Date.now() - stat.mtimeMs < ttlMs;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function statSafe(p) {
|
|
32
|
-
try {
|
|
33
|
-
return await fsp.stat(p);
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (e?.code === "ENOENT") return null;
|
|
36
|
-
throw e;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function loadSeedSnapshot() {
|
|
41
|
-
// Sync read is fine — file is bundled and small (~250KB). Falling back to
|
|
42
|
-
// sync avoids a race with caller's synchronous lookup if seed must answer
|
|
43
|
-
// immediately.
|
|
44
|
-
try {
|
|
45
|
-
return readJsonSync(SEED_SNAPSHOT_PATH);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
// Tolerate missing seed in dev environments where the build script
|
|
48
|
-
// hasn't run yet. Empty data = LiteLLM lookup miss = falls back to
|
|
49
|
-
// CURATED only.
|
|
50
|
-
return {};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function fetchUpstream({ url = LITELLM_PRICING_URL, timeoutMs = DEFAULT_FETCH_TIMEOUT_MS } = {}) {
|
|
55
|
-
const ctrl = new AbortController();
|
|
56
|
-
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
57
|
-
try {
|
|
58
|
-
const res = await fetch(url, { signal: ctrl.signal });
|
|
59
|
-
if (!res.ok) {
|
|
60
|
-
throw new Error(`LiteLLM fetch failed: HTTP ${res.status} ${res.statusText}`);
|
|
61
|
-
}
|
|
62
|
-
return await res.json();
|
|
63
|
-
} finally {
|
|
64
|
-
clearTimeout(timer);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function writeCache(cachePath, data) {
|
|
69
|
-
await fsp.mkdir(path.dirname(cachePath), { recursive: true });
|
|
70
|
-
// Persist only the slimmed shape (4 cost fields) to keep disk small and
|
|
71
|
-
// make the cache file easy to inspect/edit.
|
|
72
|
-
const slim = {};
|
|
73
|
-
let kept = 0;
|
|
74
|
-
for (const [name, entry] of Object.entries(data)) {
|
|
75
|
-
if (!entry || typeof entry !== "object" || name.startsWith("_")) continue;
|
|
76
|
-
const out = {};
|
|
77
|
-
let hasAny = false;
|
|
78
|
-
for (const f of [
|
|
79
|
-
"input_cost_per_token",
|
|
80
|
-
"output_cost_per_token",
|
|
81
|
-
"cache_read_input_token_cost",
|
|
82
|
-
"cache_creation_input_token_cost",
|
|
83
|
-
]) {
|
|
84
|
-
const v = entry[f];
|
|
85
|
-
if (typeof v === "number" && Number.isFinite(v)) {
|
|
86
|
-
out[f] = v;
|
|
87
|
-
hasAny = true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (hasAny) {
|
|
91
|
-
slim[name] = out;
|
|
92
|
-
kept++;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const payload = {
|
|
96
|
-
_meta: {
|
|
97
|
-
source: LITELLM_PRICING_URL,
|
|
98
|
-
cached_at: new Date().toISOString(),
|
|
99
|
-
kept_models: kept,
|
|
100
|
-
},
|
|
101
|
-
...slim,
|
|
102
|
-
};
|
|
103
|
-
await fsp.writeFile(cachePath, JSON.stringify(payload) + "\n");
|
|
104
|
-
return slim;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Public: load LiteLLM data into memory. Resolution chain:
|
|
108
|
-
// 1. disk cache (if mtime < ttl)
|
|
109
|
-
// 2. fetch upstream + write disk cache
|
|
110
|
-
// 3. stale disk cache (network failed)
|
|
111
|
-
// 4. bundled seed snapshot (fresh install / offline)
|
|
112
|
-
async function loadLitellmData({
|
|
113
|
-
cachePath,
|
|
114
|
-
ttlMs = DEFAULT_TTL_MS,
|
|
115
|
-
fetchTimeoutMs = DEFAULT_FETCH_TIMEOUT_MS,
|
|
116
|
-
fetchImpl = fetchUpstream,
|
|
117
|
-
url = LITELLM_PRICING_URL,
|
|
118
|
-
logger = null,
|
|
119
|
-
} = {}) {
|
|
120
|
-
if (!cachePath) {
|
|
121
|
-
throw new Error("loadLitellmData: cachePath is required");
|
|
122
|
-
}
|
|
123
|
-
const log = (level, msg) => {
|
|
124
|
-
if (logger && typeof logger[level] === "function") logger[level](msg);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// 1. Fresh disk cache
|
|
128
|
-
const stat = await statSafe(cachePath);
|
|
129
|
-
if (isFresh(stat, ttlMs)) {
|
|
130
|
-
try {
|
|
131
|
-
const data = await readJsonAsync(cachePath);
|
|
132
|
-
delete data._meta;
|
|
133
|
-
return { data, source: "disk-cache" };
|
|
134
|
-
} catch (e) {
|
|
135
|
-
log("warn", `[pricing] disk cache unreadable: ${e?.message || e}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// 2. Fetch upstream
|
|
140
|
-
try {
|
|
141
|
-
const upstream = await fetchImpl({ url, timeoutMs: fetchTimeoutMs });
|
|
142
|
-
const slim = await writeCache(cachePath, upstream);
|
|
143
|
-
return { data: slim, source: "upstream" };
|
|
144
|
-
} catch (e) {
|
|
145
|
-
log("warn", `[pricing] upstream fetch failed: ${e?.message || e}`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 3. Stale disk cache (better than seed)
|
|
149
|
-
if (stat) {
|
|
150
|
-
try {
|
|
151
|
-
const data = await readJsonAsync(cachePath);
|
|
152
|
-
delete data._meta;
|
|
153
|
-
log("warn", "[pricing] using stale disk cache");
|
|
154
|
-
return { data, source: "stale-cache" };
|
|
155
|
-
} catch (e) {
|
|
156
|
-
log("warn", `[pricing] stale cache unreadable: ${e?.message || e}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 4. Bundled seed snapshot
|
|
161
|
-
const seed = await loadSeedSnapshot();
|
|
162
|
-
delete seed._meta;
|
|
163
|
-
return { data: seed, source: "seed-snapshot" };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
module.exports = {
|
|
167
|
-
LITELLM_PRICING_URL,
|
|
168
|
-
DEFAULT_TTL_MS,
|
|
169
|
-
loadLitellmData,
|
|
170
|
-
loadSeedSnapshot,
|
|
171
|
-
fetchUpstream,
|
|
172
|
-
};
|
|
1
|
+
// LiteLLM data loader: 24h disk cache + bundled seed snapshot fallback.
|
|
2
|
+
// Fetches from upstream once when cache is missing or stale, then keeps a
|
|
3
|
+
// per-process in-memory map. fetchModelPricing() is async; subsequent reads
|
|
4
|
+
// (lookupPricing in matcher.js) operate on the in-memory map synchronously.
|
|
5
|
+
|
|
6
|
+
const fs = require("node:fs");
|
|
7
|
+
const fsp = require("node:fs/promises");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
|
|
10
|
+
const LITELLM_PRICING_URL =
|
|
11
|
+
"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
|
|
12
|
+
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000; // 24h
|
|
13
|
+
const DEFAULT_FETCH_TIMEOUT_MS = 10_000;
|
|
14
|
+
const SEED_SNAPSHOT_PATH = path.resolve(__dirname, "seed-snapshot.json");
|
|
15
|
+
|
|
16
|
+
function readJsonSync(p) {
|
|
17
|
+
const raw = fs.readFileSync(p, "utf8");
|
|
18
|
+
return JSON.parse(raw);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function readJsonAsync(p) {
|
|
22
|
+
const raw = await fsp.readFile(p, "utf8");
|
|
23
|
+
return JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isFresh(stat, ttlMs) {
|
|
27
|
+
if (!stat) return false;
|
|
28
|
+
return Date.now() - stat.mtimeMs < ttlMs;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function statSafe(p) {
|
|
32
|
+
try {
|
|
33
|
+
return await fsp.stat(p);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e?.code === "ENOENT") return null;
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function loadSeedSnapshot() {
|
|
41
|
+
// Sync read is fine — file is bundled and small (~250KB). Falling back to
|
|
42
|
+
// sync avoids a race with caller's synchronous lookup if seed must answer
|
|
43
|
+
// immediately.
|
|
44
|
+
try {
|
|
45
|
+
return readJsonSync(SEED_SNAPSHOT_PATH);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// Tolerate missing seed in dev environments where the build script
|
|
48
|
+
// hasn't run yet. Empty data = LiteLLM lookup miss = falls back to
|
|
49
|
+
// CURATED only.
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function fetchUpstream({ url = LITELLM_PRICING_URL, timeoutMs = DEFAULT_FETCH_TIMEOUT_MS } = {}) {
|
|
55
|
+
const ctrl = new AbortController();
|
|
56
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
57
|
+
try {
|
|
58
|
+
const res = await fetch(url, { signal: ctrl.signal });
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
throw new Error(`LiteLLM fetch failed: HTTP ${res.status} ${res.statusText}`);
|
|
61
|
+
}
|
|
62
|
+
return await res.json();
|
|
63
|
+
} finally {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function writeCache(cachePath, data) {
|
|
69
|
+
await fsp.mkdir(path.dirname(cachePath), { recursive: true });
|
|
70
|
+
// Persist only the slimmed shape (4 cost fields) to keep disk small and
|
|
71
|
+
// make the cache file easy to inspect/edit.
|
|
72
|
+
const slim = {};
|
|
73
|
+
let kept = 0;
|
|
74
|
+
for (const [name, entry] of Object.entries(data)) {
|
|
75
|
+
if (!entry || typeof entry !== "object" || name.startsWith("_")) continue;
|
|
76
|
+
const out = {};
|
|
77
|
+
let hasAny = false;
|
|
78
|
+
for (const f of [
|
|
79
|
+
"input_cost_per_token",
|
|
80
|
+
"output_cost_per_token",
|
|
81
|
+
"cache_read_input_token_cost",
|
|
82
|
+
"cache_creation_input_token_cost",
|
|
83
|
+
]) {
|
|
84
|
+
const v = entry[f];
|
|
85
|
+
if (typeof v === "number" && Number.isFinite(v)) {
|
|
86
|
+
out[f] = v;
|
|
87
|
+
hasAny = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (hasAny) {
|
|
91
|
+
slim[name] = out;
|
|
92
|
+
kept++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const payload = {
|
|
96
|
+
_meta: {
|
|
97
|
+
source: LITELLM_PRICING_URL,
|
|
98
|
+
cached_at: new Date().toISOString(),
|
|
99
|
+
kept_models: kept,
|
|
100
|
+
},
|
|
101
|
+
...slim,
|
|
102
|
+
};
|
|
103
|
+
await fsp.writeFile(cachePath, JSON.stringify(payload) + "\n");
|
|
104
|
+
return slim;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Public: load LiteLLM data into memory. Resolution chain:
|
|
108
|
+
// 1. disk cache (if mtime < ttl)
|
|
109
|
+
// 2. fetch upstream + write disk cache
|
|
110
|
+
// 3. stale disk cache (network failed)
|
|
111
|
+
// 4. bundled seed snapshot (fresh install / offline)
|
|
112
|
+
async function loadLitellmData({
|
|
113
|
+
cachePath,
|
|
114
|
+
ttlMs = DEFAULT_TTL_MS,
|
|
115
|
+
fetchTimeoutMs = DEFAULT_FETCH_TIMEOUT_MS,
|
|
116
|
+
fetchImpl = fetchUpstream,
|
|
117
|
+
url = LITELLM_PRICING_URL,
|
|
118
|
+
logger = null,
|
|
119
|
+
} = {}) {
|
|
120
|
+
if (!cachePath) {
|
|
121
|
+
throw new Error("loadLitellmData: cachePath is required");
|
|
122
|
+
}
|
|
123
|
+
const log = (level, msg) => {
|
|
124
|
+
if (logger && typeof logger[level] === "function") logger[level](msg);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// 1. Fresh disk cache
|
|
128
|
+
const stat = await statSafe(cachePath);
|
|
129
|
+
if (isFresh(stat, ttlMs)) {
|
|
130
|
+
try {
|
|
131
|
+
const data = await readJsonAsync(cachePath);
|
|
132
|
+
delete data._meta;
|
|
133
|
+
return { data, source: "disk-cache" };
|
|
134
|
+
} catch (e) {
|
|
135
|
+
log("warn", `[pricing] disk cache unreadable: ${e?.message || e}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 2. Fetch upstream
|
|
140
|
+
try {
|
|
141
|
+
const upstream = await fetchImpl({ url, timeoutMs: fetchTimeoutMs });
|
|
142
|
+
const slim = await writeCache(cachePath, upstream);
|
|
143
|
+
return { data: slim, source: "upstream" };
|
|
144
|
+
} catch (e) {
|
|
145
|
+
log("warn", `[pricing] upstream fetch failed: ${e?.message || e}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 3. Stale disk cache (better than seed)
|
|
149
|
+
if (stat) {
|
|
150
|
+
try {
|
|
151
|
+
const data = await readJsonAsync(cachePath);
|
|
152
|
+
delete data._meta;
|
|
153
|
+
log("warn", "[pricing] using stale disk cache");
|
|
154
|
+
return { data, source: "stale-cache" };
|
|
155
|
+
} catch (e) {
|
|
156
|
+
log("warn", `[pricing] stale cache unreadable: ${e?.message || e}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 4. Bundled seed snapshot
|
|
161
|
+
const seed = await loadSeedSnapshot();
|
|
162
|
+
delete seed._meta;
|
|
163
|
+
return { data: seed, source: "seed-snapshot" };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
LITELLM_PRICING_URL,
|
|
168
|
+
DEFAULT_TTL_MS,
|
|
169
|
+
loadLitellmData,
|
|
170
|
+
loadSeedSnapshot,
|
|
171
|
+
fetchUpstream,
|
|
172
|
+
};
|