feat(commandcode): quota usage dashboard, CLI-parity request, and connect timeout fixes

- Add CommandCode usage handler mirroring the official CLI /usage
  (whoami → credits/subscriptions → summary) with 5h/weekly/monthly
  quota rows, registered in services/usage.js and registry config
- Parse commandcode quota rows in ProviderLimits (remainingPercentage + $ unit)
- Match official CLI request shape: x-command-code-version 1.10.0,
  User-Agent cli, and config.environment '${platform}-${arch}, Node.js ${version}'
- Fix connect timeout unit confusion: both profile and provider pages
  now use ms with a 1s minimum guard (prevents 60ms footgun)
- Fix fetchT0 ReferenceError in base.js error path and log fetch
  diagnostics only on upstream failure
- Quota Tracker defaults to the Active account filter
- Ignore .commandcode/ CLI local state
This commit is contained in:
2026-08-04 22:34:13 +07:00
parent fcd3dcb409
commit c5ce1ef140
11 changed files with 483 additions and 14 deletions

View File

@@ -288,9 +288,11 @@ export default function ProfilePage() {
const handleGlobalTimeoutChange = async (e) => {
const raw = e.target.value.replace(/[^0-9]/g, "");
const numTimeout = parseInt(raw, 10);
// Enforce a sane minimum (1s) so a stray "60" never becomes a 60ms
// connect timeout — same guard as the per-provider timeout input.
const patchValue =
raw !== "" && Number.isFinite(numTimeout) && numTimeout > 0
? numTimeout
? Math.max(1000, numTimeout)
: null;
try {

View File

@@ -438,7 +438,7 @@ export default function ProviderDetailPage() {
const thinkingCfg =
(settingsData.providerThinking || {})[providerId] || {};
setThinkingMode(thinkingCfg.mode || "auto");
// Load per-provider connect timeout
// Load per-provider connect timeout (ms)
const timeoutCfg =
(settingsData.providerTimeouts || {})[providerId] || {};
setProviderTimeout(
@@ -577,15 +577,13 @@ export default function ProviderDetailPage() {
const settingsData = settingsRes.ok ? await settingsRes.json() : {};
const current = settingsData.providerTimeouts || {};
const updated = { ...current };
if (!ms || ms === "") {
delete updated[providerId];
const timeoutMs = parseInt(ms, 10);
if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
// Stored in ms; enforce a sane minimum (1s) so a stray "60" means
// 60 SECONDS-worth of protection — never a 60ms connect timeout.
updated[providerId] = { timeoutMs: Math.max(1000, timeoutMs) };
} else {
const timeoutMs = parseInt(ms, 10);
if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
updated[providerId] = { timeoutMs };
} else {
delete updated[providerId];
}
delete updated[providerId];
}
await fetch("/api/settings", {
method: "PATCH",

View File

@@ -147,7 +147,7 @@ export default function ProviderLimits() {
const [proxyPools, setProxyPools] = useState([]);
const [providerFilter, setProviderFilter] = useState("all");
const [providerOptions, setProviderOptions] = useState([]);
const [accountFilter, setAccountFilter] = useState("all");
const [accountFilter, setAccountFilter] = useState("active");
const [quotaSortMode, setQuotaSortMode] = useState("default");
const [quotaVisibility, setQuotaVisibility] = useState({});
const [expiringFirst, setExpiringFirst] = useState(false);

View File

@@ -564,6 +564,24 @@ export function parseQuotaData(provider, data) {
}
break;
case "commandcode":
// CommandCode reports currency credits (5-hour/weekly windows + monthly
// credits) with used/total in dollars. Forward remainingPercentage (the
// UI would otherwise render "$0.05" balances as "0%") and unit "$".
if (data.quotas) {
Object.entries(data.quotas).forEach(([name, quota]) => {
normalizedQuotas.push({
name,
used: quota.used || 0,
total: quota.total || 0,
unit: quota.unit || "$",
resetAt: quota.resetAt || null,
remainingPercentage: quota.remainingPercentage,
});
});
}
break;
default:
// Generic fallback for unknown providers
if (data.quotas) {