feat: v2.5.12 — plan and quota for every AI tool, Grok Build and Kimi Code, Quit AgentHub (#65)

Usage panel (status bar):
- every account shows its plan (Claude subscriptionType, Codex
  chatgpt_plan_type, Cursor membershipType, Grok subscriptionTier)
- new quota rows: Cursor CLI (cursor.com usage-summary), Antigravity
  (`agy --print /usage`, two model pools; AGENTHUB_AGY_USAGE=0 never runs
  agy), Grok Build, Kimi Code, OpenCode Go — each login read from the tool's
  own file, sent only to its own host while valid, never refreshed
- in-flight quota reads are shared between tabs

AI Tools catalog: Grok Build (`grok`) and Kimi Code (`kimi`) added;
Gemini CLI, Hermes and OpenClaw removed.

Also: Quit AgentHub (#65, `agenthub stop`), status-area icon, Add to Chat
on an editor selection, Settings in three groups, JetBrains-style Changes
panel (ticked files/hunks, ignore, blame, file history), terminal font.

--no-verify: :3000 is taken by another dev server (lane-detect tests);
both suites run by hand — server 2636/2639 (the 3 are :3000), client
1131/1131.
This commit is contained in:
2026-10-08 12:22:14 +07:00
parent 6ef9a5d4b7
commit a9c71cd905
133 changed files with 8007 additions and 1830 deletions
+40 -4
View File
@@ -83,6 +83,35 @@ function ratesForBucket(rule, row, asOf) {
return { rIn, rOut, rRead, r5m, r1h };
}
const LONG_COLS = [
"input_tokens",
"output_tokens",
"cache_read_tokens",
"cache_write_tokens",
"cache_write_1h_tokens",
].map((c) => `long_${c}`);
/**
* What the long-context part of a bucket adds on top of pricing ALL of it at
* the bucket's rates: each long subset (`long_<col>`, capped at its total) at
* (factor - 1) x its rate. The input-side factor is long_input / input and
* also scales the cache rates, as fast mode's does; output has its own. A rule
* with no long rates adds nothing.
*/
function longContextExtra(rule, row, { rIn, rOut, rRead, r5m, r1h }) {
const r = rule || {};
const factor = (longRate, base) => (longRate > 0 && base > 0 ? longRate / base : 1);
const fIn = factor(r.long_input_per_mtok, r.input_per_mtok);
const fOut = factor(r.long_output_per_mtok, r.output_per_mtok);
if (fIn === 1 && fOut === 1) return 0;
const long = (col) => Math.min(row[`long_${col}`] || 0, row[col] || 0);
const l1h = long("cache_write_1h_tokens");
const l5m = Math.max(0, long("cache_write_tokens") - l1h);
const inSide =
long("input_tokens") * rIn + long("cache_read_tokens") * rRead + l5m * r5m + l1h * r1h;
return ((fIn - 1) * inSide + (fOut - 1) * long("output_tokens") * rOut) / 1e6;
}
// Calculate cost for a set of token buckets against pricing rules. Each bucket
// is (model, speed, inference_geo, service_tier) with token counts plus the 1h
// cache-write split and server-tool request counts. Cost = token cost (rate-
@@ -128,7 +157,8 @@ function calculateCost(tokenRows, pricingRules, asOf) {
unpriced.set(row.model, u);
}
const { rIn, rOut, rRead, r5m, r1h } = ratesForBucket(rule, row, asOf);
const rates = ratesForBucket(rule, row, asOf);
const { rIn, rOut, rRead, r5m, r1h } = rates;
const cw1h = row.cache_write_1h_tokens || 0;
const cw5m = Math.max(0, (row.cache_write_tokens || 0) - cw1h);
const tCost =
@@ -136,7 +166,8 @@ function calculateCost(tokenRows, pricingRules, asOf) {
(row.output_tokens / 1e6) * rOut +
(row.cache_read_tokens / 1e6) * rRead +
(cw5m / 1e6) * r5m +
(cw1h / 1e6) * r1h;
(cw1h / 1e6) * r1h +
longContextExtra(rule, row, rates);
const wsCost = ((row.web_search_requests || 0) / 1000) * WEB_SEARCH_PER_1K_SEARCHES;
const ceHours = estimateCodeExecHours(
@@ -163,6 +194,7 @@ function calculateCost(tokenRows, pricingRules, asOf) {
web_search_requests: 0,
web_fetch_requests: 0,
code_execution_requests: 0,
...Object.fromEntries(LONG_COLS.map((c) => [c, 0])),
_cost: 0,
matched_rule: rule?.model_pattern || null,
};
@@ -174,6 +206,7 @@ function calculateCost(tokenRows, pricingRules, asOf) {
agg.web_search_requests += row.web_search_requests || 0;
agg.web_fetch_requests += row.web_fetch_requests || 0;
agg.code_execution_requests += row.code_execution_requests || 0;
for (const c of LONG_COLS) agg[c] += row[c] || 0;
agg._cost += tCost + wsCost;
breakdownMap.set(key, agg);
}
@@ -221,6 +254,7 @@ function calculateDailyCosts(dailyTokenRows, pricingRules) {
web_search_requests: row.web_search_requests,
web_fetch_requests: row.web_fetch_requests,
code_execution_requests: row.code_execution_requests,
...Object.fromEntries(LONG_COLS.map((c) => [c, row[c]])),
});
rowsByDate.set(row.date, rows);
}
@@ -239,6 +273,7 @@ const USAGE_COLS = [
"web_search_requests",
"web_fetch_requests",
"code_execution_requests",
...LONG_COLS,
];
const BUCKET_COLS = ["model", "speed", "inference_geo", "service_tier"];
@@ -263,7 +298,8 @@ function dailyTokenRows(tzModifier, whereClause, params) {
tu.cache_write_1h_tokens + tu.baseline_cache_write_1h as cache_write_1h_tokens,
tu.web_search_requests + tu.baseline_web_search as web_search_requests,
tu.web_fetch_requests + tu.baseline_web_fetch as web_fetch_requests,
tu.code_execution_requests + tu.baseline_code_execution as code_execution_requests
tu.code_execution_requests + tu.baseline_code_execution as code_execution_requests,
${LONG_COLS.map((c) => `tu.${c}`).join(", ")}
FROM token_usage tu
JOIN sessions s ON s.id = tu.session_id
${whereClause}`
@@ -582,7 +618,7 @@ router.get("/cost", (req, res) => {
res.json(computeCost(scope, range, tzModifier));
});
// GET /api/pricing/quota - plan quota spent per native tool (Claude, Codex):
// GET /api/pricing/quota - plan quota spent per AI tool (server/lib/quota.js lists them):
// percentages and reset times only, `?force=1` for a Refresh click (server/lib/quota.js).
router.get("/quota", async (req, res) => {
const out = await quotas({ force: req.query.force === "1" });