tokenusage-cli 0.4.3 → 0.4.5
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 +66 -0
- package/THIRD_PARTY_NOTICES.md +17 -2
- package/package.json +4 -4
- package/src/commands/init.js +8 -1
- package/src/commands/reconcile.js +17 -5
- package/src/commands/status.js +4 -0
- package/src/commands/sync.js +36 -1
- package/src/lib/cursor-config.js +5 -1
- package/src/lib/deepseek-limits.js +280 -0
- package/src/lib/deepseek-status.js +157 -0
- package/src/lib/doctor.js +50 -0
- package/src/lib/grok-limits.js +40 -1
- package/src/lib/ingest-sanitize.js +9 -0
- package/src/lib/pricing/curated-overrides.json +627 -0
- package/src/lib/pricing/index.js +16 -0
- package/src/lib/pricing-coverage.js +205 -0
- package/src/lib/project-key.js +23 -0
- package/src/lib/provider-api-key-store.js +111 -0
- package/src/lib/provider-status.js +14 -2
- package/src/lib/qoder-limits.js +4 -1
- package/src/lib/rollout.js +308 -58
- package/src/lib/scheduled-task.js +7 -1
- package/src/lib/session-analytics.js +52 -2
- package/src/lib/session-upload.js +25 -12
- package/src/lib/upload-queue.js +4 -1
- package/src/lib/usage-limits.js +536 -22
package/src/lib/pricing/index.js
CHANGED
|
@@ -41,10 +41,12 @@ const DEEPSEEK_TIME_PRICED_MODELS = [
|
|
|
41
41
|
// ensurePricingLoaded() (e.g. tests, vite mock startup, edge functions) still
|
|
42
42
|
// get LiteLLM-backed pricing instead of all-zero. ensurePricingLoaded() will
|
|
43
43
|
// later upgrade this to fresh disk cache or upstream data.
|
|
44
|
+
let seedMeta = null;
|
|
44
45
|
function loadSeedSync() {
|
|
45
46
|
try {
|
|
46
47
|
const raw = fs.readFileSync(SEED_SNAPSHOT_PATH, "utf8");
|
|
47
48
|
const parsed = JSON.parse(raw);
|
|
49
|
+
seedMeta = parsed._meta && typeof parsed._meta === "object" ? parsed._meta : null;
|
|
48
50
|
delete parsed._meta;
|
|
49
51
|
return parsed;
|
|
50
52
|
} catch (e) {
|
|
@@ -109,6 +111,19 @@ function getPricingRevision() {
|
|
|
109
111
|
return state.revision;
|
|
110
112
|
}
|
|
111
113
|
|
|
114
|
+
// Read-only snapshot of where pricing data came from and how stale it is.
|
|
115
|
+
// Surfaced by `status --json` so a $0 cost can be triaged as "not collected"
|
|
116
|
+
// vs "not priced" without digging into cache files (docs/upstream-comparison-plan.md §1 A3).
|
|
117
|
+
function getPricingMeta() {
|
|
118
|
+
return {
|
|
119
|
+
source: state.source,
|
|
120
|
+
seed_generated_at: seedMeta && typeof seedMeta.generated_at === "string" ? seedMeta.generated_at : null,
|
|
121
|
+
litellm_models: Object.keys(state.litellmPerMillionMap).length,
|
|
122
|
+
curated_exact: Object.keys(curatedOverrides.exact || {}).length,
|
|
123
|
+
curated_fuzzy: Array.isArray(curatedOverrides.fuzzy) ? curatedOverrides.fuzzy.length : 0,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
112
127
|
function getModelPricing(model, opts = {}) {
|
|
113
128
|
if (!model) return ZERO_PRICING;
|
|
114
129
|
let lookupSource = null;
|
|
@@ -366,6 +381,7 @@ const MODEL_PRICING = curatedOverrides.exact;
|
|
|
366
381
|
module.exports = {
|
|
367
382
|
ensurePricingLoaded,
|
|
368
383
|
getPricingRevision,
|
|
384
|
+
getPricingMeta,
|
|
369
385
|
getModelPricing,
|
|
370
386
|
getModelPricingInfo,
|
|
371
387
|
getRowPricing,
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Read-only pricing-coverage and unknown-model alignment analysis over the
|
|
4
|
+
// local last-wins queue baseline (queue.jsonl). Used by `doctor`
|
|
5
|
+
// (docs/upstream-comparison-plan.md §2 B3 + §3 C2 dry-run). This module never
|
|
6
|
+
// writes anything; the alignment preview is a dry-run projection only and does
|
|
7
|
+
// NOT change any bucket's stored or displayed model.
|
|
8
|
+
|
|
9
|
+
const fs = require("node:fs/promises");
|
|
10
|
+
|
|
11
|
+
const { iterateQueueLines } = require("./upload-queue");
|
|
12
|
+
const { normalizeQueueRow } = require("./queue-row-normalize");
|
|
13
|
+
const { getModelPricingInfo } = require("./pricing");
|
|
14
|
+
|
|
15
|
+
const DEFAULT_WINDOW_DAYS = 7;
|
|
16
|
+
const TOP_UNPRICED_LIMIT = 10;
|
|
17
|
+
const TOP_MOVES_LIMIT = 10;
|
|
18
|
+
|
|
19
|
+
// Same bucket identity as reconcile (hour_start|source|model last-wins), minus
|
|
20
|
+
// the upload sanitization: this is a local read-side analysis, not an upload.
|
|
21
|
+
async function readLastWinsBuckets({ queuePath, fromMs, toMs }) {
|
|
22
|
+
let handle;
|
|
23
|
+
try {
|
|
24
|
+
handle = await fs.open(queuePath, "r");
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error?.code === "ENOENT") return [];
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
const buckets = new Map();
|
|
30
|
+
try {
|
|
31
|
+
const stat = await handle.stat();
|
|
32
|
+
for await (const record of iterateQueueLines(handle, 0, stat.size)) {
|
|
33
|
+
// A producer may be mid-write; an incomplete tail is not yet queued data.
|
|
34
|
+
if (!record.complete) break;
|
|
35
|
+
const line = record.bytes.toString("utf8");
|
|
36
|
+
if (!line.trim()) continue;
|
|
37
|
+
let raw;
|
|
38
|
+
try {
|
|
39
|
+
raw = JSON.parse(line);
|
|
40
|
+
} catch (_error) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
|
|
44
|
+
// Control records (account session states / watermarks) are not buckets.
|
|
45
|
+
if (Object.hasOwn(raw, "kind")) continue;
|
|
46
|
+
const hourMs = typeof raw.hour_start === "string" ? Date.parse(raw.hour_start) : NaN;
|
|
47
|
+
if (!Number.isFinite(hourMs) || hourMs < fromMs || hourMs >= toMs) continue;
|
|
48
|
+
const source = (typeof raw.source === "string" ? raw.source.trim().toLowerCase() : "") || "codex";
|
|
49
|
+
const model = (typeof raw.model === "string" ? raw.model.trim() : "") || "unknown";
|
|
50
|
+
const row = normalizeQueueRow({
|
|
51
|
+
...raw,
|
|
52
|
+
source,
|
|
53
|
+
model,
|
|
54
|
+
hour_start: new Date(hourMs).toISOString(),
|
|
55
|
+
});
|
|
56
|
+
buckets.set(`${row.hour_start}|${source}|${model}`, {
|
|
57
|
+
hour_start: row.hour_start,
|
|
58
|
+
source,
|
|
59
|
+
model,
|
|
60
|
+
total_tokens: Number(row.total_tokens) || 0,
|
|
61
|
+
conversation_count: Number(row.conversation_count) || 0,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} finally {
|
|
65
|
+
await handle.close();
|
|
66
|
+
}
|
|
67
|
+
return [...buckets.values()];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// "Covered" = priced or known-free (subscription/local); "unpriced" = the
|
|
71
|
+
// pricing engine has no entry for the model at all (the $0 that matters).
|
|
72
|
+
// Zero-token unpriced buckets (e.g. qoder-cn credits-only rows) are counted
|
|
73
|
+
// separately: they carry no cost error, so they must not crowd top_unpriced.
|
|
74
|
+
function analyzePricingCoverage(buckets) {
|
|
75
|
+
let coveredBuckets = 0;
|
|
76
|
+
let coveredTokens = 0;
|
|
77
|
+
let totalTokens = 0;
|
|
78
|
+
let zeroTokenUnpricedBuckets = 0;
|
|
79
|
+
const unpricedByModel = new Map();
|
|
80
|
+
for (const bucket of buckets) {
|
|
81
|
+
const info = getModelPricingInfo(bucket.model, { source: bucket.source });
|
|
82
|
+
const covered = info.status === "priced" || info.status === "free";
|
|
83
|
+
totalTokens += bucket.total_tokens;
|
|
84
|
+
if (covered) {
|
|
85
|
+
coveredBuckets += 1;
|
|
86
|
+
coveredTokens += bucket.total_tokens;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (bucket.total_tokens === 0) {
|
|
90
|
+
zeroTokenUnpricedBuckets += 1;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const entry = unpricedByModel.get(bucket.model) || {
|
|
94
|
+
model: bucket.model,
|
|
95
|
+
total_tokens: 0,
|
|
96
|
+
buckets: 0,
|
|
97
|
+
sources: new Set(),
|
|
98
|
+
};
|
|
99
|
+
entry.total_tokens += bucket.total_tokens;
|
|
100
|
+
entry.buckets += 1;
|
|
101
|
+
entry.sources.add(bucket.source);
|
|
102
|
+
unpricedByModel.set(bucket.model, entry);
|
|
103
|
+
}
|
|
104
|
+
const topUnpriced = [...unpricedByModel.values()]
|
|
105
|
+
.sort((a, b) => b.total_tokens - a.total_tokens || a.model.localeCompare(b.model))
|
|
106
|
+
.slice(0, TOP_UNPRICED_LIMIT)
|
|
107
|
+
.map((entry) => ({
|
|
108
|
+
model: entry.model,
|
|
109
|
+
total_tokens: entry.total_tokens,
|
|
110
|
+
buckets: entry.buckets,
|
|
111
|
+
sources: [...entry.sources].sort(),
|
|
112
|
+
}));
|
|
113
|
+
const actionableUnpriced = [...unpricedByModel.values()].reduce((sum, entry) => sum + entry.buckets, 0);
|
|
114
|
+
return {
|
|
115
|
+
buckets: buckets.length,
|
|
116
|
+
covered_buckets: coveredBuckets,
|
|
117
|
+
unpriced_buckets: actionableUnpriced,
|
|
118
|
+
zero_token_unpriced_buckets: zeroTokenUnpricedBuckets,
|
|
119
|
+
bucket_coverage: buckets.length ? coveredBuckets / buckets.length : 1,
|
|
120
|
+
total_tokens: totalTokens,
|
|
121
|
+
covered_tokens: coveredTokens,
|
|
122
|
+
token_coverage: totalTokens ? coveredTokens / totalTokens : 1,
|
|
123
|
+
top_unpriced: topUnpriced,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// C2 dry-run (juejin align-unknown.ts idea): for every (source, hour) group
|
|
128
|
+
// that contains both "unknown" rows and known-model rows, the unknown tokens
|
|
129
|
+
// WOULD be re-attributed to the dominant known model of that group. Groups
|
|
130
|
+
// with only unknown rows are unresolvable. Nothing here is applied anywhere.
|
|
131
|
+
function previewUnknownAlignment(buckets) {
|
|
132
|
+
const groups = new Map();
|
|
133
|
+
for (const bucket of buckets) {
|
|
134
|
+
const key = `${bucket.source}|${bucket.hour_start}`;
|
|
135
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
136
|
+
groups.get(key).push(bucket);
|
|
137
|
+
}
|
|
138
|
+
let unknownBuckets = 0;
|
|
139
|
+
let unknownTokens = 0;
|
|
140
|
+
let alignableBuckets = 0;
|
|
141
|
+
let alignableTokens = 0;
|
|
142
|
+
let unresolvableBuckets = 0;
|
|
143
|
+
let unresolvableTokens = 0;
|
|
144
|
+
const moves = [];
|
|
145
|
+
for (const group of groups.values()) {
|
|
146
|
+
const unknownRows = group.filter((row) => row.model.trim().toLowerCase() === "unknown");
|
|
147
|
+
if (!unknownRows.length) continue;
|
|
148
|
+
const knownRows = group.filter((row) => row.model.trim().toLowerCase() !== "unknown");
|
|
149
|
+
let dominant = null;
|
|
150
|
+
for (const row of knownRows) {
|
|
151
|
+
if (!dominant || row.total_tokens > dominant.total_tokens) dominant = row;
|
|
152
|
+
}
|
|
153
|
+
for (const row of unknownRows) {
|
|
154
|
+
unknownBuckets += 1;
|
|
155
|
+
unknownTokens += row.total_tokens;
|
|
156
|
+
if (dominant) {
|
|
157
|
+
alignableBuckets += 1;
|
|
158
|
+
alignableTokens += row.total_tokens;
|
|
159
|
+
moves.push({
|
|
160
|
+
source: row.source,
|
|
161
|
+
hour_start: row.hour_start,
|
|
162
|
+
unknown_tokens: row.total_tokens,
|
|
163
|
+
target_model: dominant.model,
|
|
164
|
+
target_tokens: dominant.total_tokens,
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
unresolvableBuckets += 1;
|
|
168
|
+
unresolvableTokens += row.total_tokens;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
moves.sort((a, b) => b.unknown_tokens - a.unknown_tokens);
|
|
173
|
+
return {
|
|
174
|
+
unknown_buckets: unknownBuckets,
|
|
175
|
+
unknown_tokens: unknownTokens,
|
|
176
|
+
alignable_buckets: alignableBuckets,
|
|
177
|
+
alignable_tokens: alignableTokens,
|
|
178
|
+
unresolvable_buckets: unresolvableBuckets,
|
|
179
|
+
unresolvable_tokens: unresolvableTokens,
|
|
180
|
+
top_moves: moves.slice(0, TOP_MOVES_LIMIT),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function collectPricingCoverage({ queuePath, days = DEFAULT_WINDOW_DAYS, now = () => new Date() } = {}) {
|
|
185
|
+
const windowDays = Number.isFinite(days) && days > 0 ? days : DEFAULT_WINDOW_DAYS;
|
|
186
|
+
const toMs = now().getTime();
|
|
187
|
+
const fromMs = toMs - windowDays * 86_400_000;
|
|
188
|
+
const buckets = await readLastWinsBuckets({ queuePath, fromMs, toMs });
|
|
189
|
+
return {
|
|
190
|
+
window: {
|
|
191
|
+
days: windowDays,
|
|
192
|
+
from: new Date(fromMs).toISOString(),
|
|
193
|
+
to: new Date(toMs).toISOString(),
|
|
194
|
+
},
|
|
195
|
+
coverage: analyzePricingCoverage(buckets),
|
|
196
|
+
unknown_alignment_preview: previewUnknownAlignment(buckets),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
module.exports = {
|
|
201
|
+
collectPricingCoverage,
|
|
202
|
+
readLastWinsBuckets,
|
|
203
|
+
analyzePricingCoverage,
|
|
204
|
+
previewUnknownAlignment,
|
|
205
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Contract v2 (docs/cli-contract.md §2.4): the server keeps only the project
|
|
4
|
+
// basename for both hourly buckets and sessions. The CLI must apply the same
|
|
5
|
+
// rule before it writes a queue row or keys a reconciliation baseline —
|
|
6
|
+
// otherwise `owner/repo` and `repo` are two different local identities while
|
|
7
|
+
// the cloud stores one, which under-counts same-basename repos and makes
|
|
8
|
+
// reconcile report permanent false drift.
|
|
9
|
+
//
|
|
10
|
+
// This is the single implementation shared by the hourly writer, the session
|
|
11
|
+
// uploader and reconcile.
|
|
12
|
+
function basenameKey(value) {
|
|
13
|
+
const raw = String(value || "").replace(/[\\/]+$/, "");
|
|
14
|
+
if (!raw || raw === "." || raw === "..") return null;
|
|
15
|
+
const base = raw.split(/[\\/]/).pop().trim();
|
|
16
|
+
if (!base || base === "." || base === "..") return null;
|
|
17
|
+
// Control characters are rejected server-side; strip instead of failing.
|
|
18
|
+
// eslint-disable-next-line no-control-regex
|
|
19
|
+
const clean = base.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 120);
|
|
20
|
+
return clean || null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { basenameKey };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Provider API keys saved outside the process environment.
|
|
4
|
+
//
|
|
5
|
+
// The launch environment is a shared, machine-wide namespace: a
|
|
6
|
+
// `launchctl setenv DEEPSEEK_API_KEY` reaches every launchd app on the
|
|
7
|
+
// machine (that is how a global key silently unlocked another app's field in
|
|
8
|
+
// #837). Keys entered outside the shell are therefore persisted here instead,
|
|
9
|
+
// in a 0600 JSON file under the tracker data dir next to
|
|
10
|
+
// cloud-device-token.json.
|
|
11
|
+
//
|
|
12
|
+
// The environment variable still wins when set, so headless installs and
|
|
13
|
+
// wrapper-launched apps keep working; the store is the durable default for
|
|
14
|
+
// users who never touch a terminal.
|
|
15
|
+
|
|
16
|
+
const fssync = require("node:fs");
|
|
17
|
+
const path = require("node:path");
|
|
18
|
+
const { ensureDir, writeFileAtomic, chmod600IfPossible } = require("./fs");
|
|
19
|
+
|
|
20
|
+
const PROVIDER_KEY_FILES = {
|
|
21
|
+
"deepseek": "deepseek-api-key.json",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const PROVIDER_ENV_NAMES = {
|
|
25
|
+
"deepseek": "DEEPSEEK_API_KEY",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const MIN_API_KEY_LENGTH = 8;
|
|
29
|
+
const MAX_API_KEY_LENGTH = 4096;
|
|
30
|
+
|
|
31
|
+
function isProviderId(provider) {
|
|
32
|
+
return typeof provider === "string" && Object.prototype.hasOwnProperty.call(PROVIDER_KEY_FILES, provider);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function envNameForProvider(provider) {
|
|
36
|
+
return isProviderId(provider) ? PROVIDER_ENV_NAMES[provider] : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function resolveProviderKeyDir({ trackerDir, home } = {}) {
|
|
40
|
+
if (typeof trackerDir === "string" && trackerDir.trim()) return trackerDir.trim();
|
|
41
|
+
if (typeof home === "string" && home.trim()) {
|
|
42
|
+
return path.join(home.trim(), ".tokenusage", "tracker");
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function resolveProviderKeyPath({ provider, trackerDir, home } = {}) {
|
|
48
|
+
if (!isProviderId(provider)) return null;
|
|
49
|
+
const dir = resolveProviderKeyDir({ trackerDir, home });
|
|
50
|
+
if (!dir) return null;
|
|
51
|
+
return path.join(dir, PROVIDER_KEY_FILES[provider]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const API_KEY_FORBIDDEN_CHARS_RE = new RegExp("[\\s\\u0000-\\u001f\\u007f]");
|
|
55
|
+
|
|
56
|
+
// Keys are opaque bearer tokens. Reject anything that cannot be pasted into an
|
|
57
|
+
// Authorization header verbatim (internal whitespace/control characters) and
|
|
58
|
+
// keep an upper bound so a mis-pasted blob cannot bloat the auth file.
|
|
59
|
+
function normalizeApiKey(value) {
|
|
60
|
+
if (typeof value !== "string") return "";
|
|
61
|
+
const trimmed = value.trim();
|
|
62
|
+
if (trimmed.length < MIN_API_KEY_LENGTH || trimmed.length > MAX_API_KEY_LENGTH) return "";
|
|
63
|
+
if (API_KEY_FORBIDDEN_CHARS_RE.test(trimmed)) return "";
|
|
64
|
+
return trimmed;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Never throws: a missing, unreadable, or malformed store must degrade to
|
|
68
|
+
// "no stored key" so a limits fetch can still fall back to env/cookie/CLI.
|
|
69
|
+
function readStoredApiKey({ provider, trackerDir, home } = {}) {
|
|
70
|
+
const filePath = resolveProviderKeyPath({ provider, trackerDir, home });
|
|
71
|
+
if (!filePath) return "";
|
|
72
|
+
let raw;
|
|
73
|
+
try {
|
|
74
|
+
raw = fssync.readFileSync(filePath, "utf8");
|
|
75
|
+
} catch {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = JSON.parse(raw);
|
|
81
|
+
} catch {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
return normalizeApiKey(parsed?.apiKey);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function writeStoredApiKey({ provider, trackerDir, home, apiKey } = {}) {
|
|
88
|
+
const filePath = resolveProviderKeyPath({ provider, trackerDir, home });
|
|
89
|
+
if (!filePath) throw new Error("No tracker data directory available for the API key.");
|
|
90
|
+
const normalized = normalizeApiKey(apiKey);
|
|
91
|
+
if (!normalized) throw new Error("Invalid API key.");
|
|
92
|
+
await ensureDir(path.dirname(filePath));
|
|
93
|
+
const contents = `${JSON.stringify({ apiKey: normalized, updatedAt: new Date().toISOString() }, null, 2)}\n`;
|
|
94
|
+
await writeFileAtomic(filePath, contents, { mode: 0o600 });
|
|
95
|
+
// writeFileAtomic only applies `mode` to newly created files; an existing
|
|
96
|
+
// store with looser permissions must still end up private.
|
|
97
|
+
await chmod600IfPossible(filePath);
|
|
98
|
+
return filePath;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
PROVIDER_KEY_FILES,
|
|
103
|
+
PROVIDER_ENV_NAMES,
|
|
104
|
+
isProviderId,
|
|
105
|
+
envNameForProvider,
|
|
106
|
+
resolveProviderKeyDir,
|
|
107
|
+
resolveProviderKeyPath,
|
|
108
|
+
normalizeApiKey,
|
|
109
|
+
readStoredApiKey,
|
|
110
|
+
writeStoredApiKey,
|
|
111
|
+
};
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// Statuspage.io contract (`/api/v2/status.json`):
|
|
10
10
|
// { "page": { "updated_at": ISO }, "status": { "indicator": "none|minor|major|critical", "description": "..." } }
|
|
11
11
|
|
|
12
|
+
const { parseDeepSeekStatusPage } = require("./deepseek-status");
|
|
13
|
+
|
|
12
14
|
const STATUS_PROBE_TIMEOUT_MS = 6_000;
|
|
13
15
|
// Status pages change on incident timescales; 5 minutes keeps the limits
|
|
14
16
|
// poll (2-min TTL upstream) from hammering statuspage.io every cycle.
|
|
@@ -23,6 +25,13 @@ const STATUS_PAGE_SPECS = {
|
|
|
23
25
|
apiUrl: "https://status.claude.com/api/v2/status.json",
|
|
24
26
|
pageUrl: "https://status.claude.com",
|
|
25
27
|
},
|
|
28
|
+
deepseek: {
|
|
29
|
+
// Flashcat-hosted Next.js page: no public JSON API and no CORS. Relayed
|
|
30
|
+
// server-side here; `format` switches the fetch to HTML + RSC parsing.
|
|
31
|
+
apiUrl: "https://status.deepseek.com/",
|
|
32
|
+
pageUrl: "https://status.deepseek.com",
|
|
33
|
+
format: "deepseek-rsc",
|
|
34
|
+
},
|
|
26
35
|
};
|
|
27
36
|
|
|
28
37
|
const VALID_INDICATORS = new Set(["none", "minor", "major", "critical"]);
|
|
@@ -70,11 +79,14 @@ async function fetchProviderServiceStatus(providerId, { fetchImpl = fetch, nowMs
|
|
|
70
79
|
try {
|
|
71
80
|
const res = await fetchImpl(spec.apiUrl, {
|
|
72
81
|
method: "GET",
|
|
73
|
-
headers: { Accept: "application/json" },
|
|
82
|
+
headers: { Accept: spec.format === "deepseek-rsc" ? "text/html" : "application/json" },
|
|
74
83
|
signal: controller.signal,
|
|
75
84
|
});
|
|
76
85
|
if (res.ok) {
|
|
77
|
-
|
|
86
|
+
const payload = spec.format === "deepseek-rsc"
|
|
87
|
+
? parseDeepSeekStatusPage(await res.text())
|
|
88
|
+
: await res.json();
|
|
89
|
+
data = normalizeStatusPayload(payload, spec, nowMs);
|
|
78
90
|
}
|
|
79
91
|
} finally {
|
|
80
92
|
clearTimeout(timer);
|
package/src/lib/qoder-limits.js
CHANGED
|
@@ -38,7 +38,10 @@ const QODER_COSY_VERSION = "1.0.22";
|
|
|
38
38
|
const QODER_ACTIVITY_CACHE_FILE = "qoder-activity-cache.json";
|
|
39
39
|
const QODER_ACTIVITY_CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
40
40
|
const QODER_LIMITS_CACHE_FILE = "qoder-usage-limits-cache.json";
|
|
41
|
-
|
|
41
|
+
// Stale-serve TTL unified to 12h across every limits cache (2026-11-03, rationale
|
|
42
|
+
// in usage-limits.js's cursor note). The promotional activity cache above stays
|
|
43
|
+
// at 24h — it feeds campaign buckets, not quota readings.
|
|
44
|
+
const QODER_LIMITS_CACHE_MAX_AGE_MS = 12 * 60 * 60 * 1000;
|
|
42
45
|
const QODER_LIMITS_CACHE_UNKNOWN_RESET_TTL_MS = 12 * 60 * 60 * 1000;
|
|
43
46
|
const QODER_SERVER_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
44
47
|
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDA8iMH5c02LilrsERw9t6Pv5Nc
|