* chore: remove dead/unreferenced files across ui, vscode Remove 59 unused source files (components, hooks, lib utils, stores, barrels, and orphaned vscode github modules) that are not imported by any entry-reachable code. Also drop a stale test mock for the removed execCommands module. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * refactor: remove unused exported symbols (types, functions, consts, hooks) Remove exported symbols whose identifier is referenced nowhere in the repository (verified via repo-wide search), across ui types/contracts, lib utilities, sync layer, stores, and components. Also drop the few imports/private helpers orphaned by these removals. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * refactor: remove more unused exports (desktop, shortcuts, worktree, vscode) Continue removing repo-wide unreferenced exported functions, consts and types across lib/desktop, shortcuts, worktreeSessionCreator, sync, and vscode gitService, with cascading orphaned helpers/imports cleaned up. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * chore: add dead-code cleanup tooling * refactor: checkpoint dead-code cleanup * refactor: remove dead-code suppressions --------- Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
108 lines
2.7 KiB
JavaScript
108 lines
2.7 KiB
JavaScript
import { readAuthFile } from '../../opencode/auth.js';
|
|
import {
|
|
getAuthEntry,
|
|
normalizeAuthEntry,
|
|
buildResult,
|
|
toUsageWindow,
|
|
toNumber,
|
|
toTimestamp
|
|
} from '../utils/index.js';
|
|
|
|
export const providerId = 'claude';
|
|
export const providerName = 'Claude';
|
|
const aliases = ['anthropic', 'claude'];
|
|
|
|
export const isConfigured = () => {
|
|
const auth = readAuthFile();
|
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
return Boolean(entry?.access || entry?.token);
|
|
};
|
|
|
|
export const fetchQuota = async () => {
|
|
const auth = readAuthFile();
|
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
const accessToken = entry?.access ?? entry?.token;
|
|
|
|
if (!accessToken) {
|
|
return buildResult({
|
|
providerId,
|
|
providerName,
|
|
ok: false,
|
|
configured: false,
|
|
error: 'Not configured'
|
|
});
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('https://api.anthropic.com/api/oauth/usage', {
|
|
method: 'GET',
|
|
headers: {
|
|
Authorization: `Bearer ${accessToken}`,
|
|
'anthropic-beta': 'oauth-2025-04-20'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
return buildResult({
|
|
providerId,
|
|
providerName,
|
|
ok: false,
|
|
configured: true,
|
|
error: `API error: ${response.status}`
|
|
});
|
|
}
|
|
|
|
const payload = await response.json();
|
|
const windows = {};
|
|
const fiveHour = payload?.five_hour ?? null;
|
|
const sevenDay = payload?.seven_day ?? null;
|
|
const sevenDaySonnet = payload?.seven_day_sonnet ?? null;
|
|
const sevenDayOpus = payload?.seven_day_opus ?? null;
|
|
|
|
if (fiveHour) {
|
|
windows['5h'] = toUsageWindow({
|
|
usedPercent: toNumber(fiveHour.utilization),
|
|
windowSeconds: null,
|
|
resetAt: toTimestamp(fiveHour.resets_at)
|
|
});
|
|
}
|
|
if (sevenDay) {
|
|
windows['7d'] = toUsageWindow({
|
|
usedPercent: toNumber(sevenDay.utilization),
|
|
windowSeconds: null,
|
|
resetAt: toTimestamp(sevenDay.resets_at)
|
|
});
|
|
}
|
|
if (sevenDaySonnet) {
|
|
windows['7d-sonnet'] = toUsageWindow({
|
|
usedPercent: toNumber(sevenDaySonnet.utilization),
|
|
windowSeconds: null,
|
|
resetAt: toTimestamp(sevenDaySonnet.resets_at)
|
|
});
|
|
}
|
|
if (sevenDayOpus) {
|
|
windows['7d-opus'] = toUsageWindow({
|
|
usedPercent: toNumber(sevenDayOpus.utilization),
|
|
windowSeconds: null,
|
|
resetAt: toTimestamp(sevenDayOpus.resets_at)
|
|
});
|
|
}
|
|
|
|
return buildResult({
|
|
providerId,
|
|
providerName,
|
|
ok: true,
|
|
configured: true,
|
|
usage: { windows }
|
|
});
|
|
} catch (error) {
|
|
return buildResult({
|
|
providerId,
|
|
providerName,
|
|
ok: false,
|
|
configured: true,
|
|
error: error instanceof Error ? error.message : 'Request failed'
|
|
});
|
|
}
|
|
};
|