The -X theirs merge of origin/master (v0.5.69) silently reverted five branch-only hunks because upstream had no conflict-region counterpart and simply won the three-way pick: * services/usage.js: re-register the commandcode USAGE handler + import. Without it the dashboard Quota Tracker fell through to 'Usage API not implemented for commandcode'. The handler module (services/usage/commandcode.js) and registry usage block survived; only the dispatch entry was dropped. * ProviderLimits/utils.js: restore parseQuotaData 'commandcode' case (currency-credit rows need unit "$" + remainingPercentage forwarding, else $0.05 balances render as 0%). * profile + providers/[id] pages: restore Math.max(1000, ...) connect timeout floors so a stray '60' is never interpreted as 60ms. * .gitignore: re-add .commandcode/ CLI local state. Verified: tests/unit/commandcode-usage.test.js (6) and usage-dispatch.test.js (2, asserts every provider routes to a real handler) pass standalone; full unit run 1742 pass / 107 fail vs 1738/111 before this fix (remaining failures pre-existing, unrelated).
88 lines
4.2 KiB
JavaScript
88 lines
4.2 KiB
JavaScript
/**
|
|
* Usage Fetcher - Get usage data from provider APIs
|
|
*/
|
|
|
|
import { getGitHubUsage } from "./usage/github.js";
|
|
import { getGeminiUsage, getAntigravityUsage } from "./usage/google.js";
|
|
import { getClaudeUsage } from "./usage/claude.js";
|
|
import { getCodexUsage, consumeCodexRateLimitResetCredit, getCodexRateLimitResetCredits } from "./usage/codex.js";
|
|
|
|
export { consumeCodexRateLimitResetCredit, getCodexRateLimitResetCredits };
|
|
import { getKiroUsage } from "./usage/kiro.js";
|
|
import { getMiniMaxUsage } from "./usage/minimax.js";
|
|
import { getCodeBuddyCnUsage, getCodeBuddyIntlUsage } from "./usage/codebuddy-cn.js";
|
|
import { getXaiUsage } from "./usage/xai.js";
|
|
import { getGrokCliUsage } from "./usage/grok-cli.js";
|
|
import { getKimiUsage } from "./usage/kimi.js";
|
|
import { getDeepseekUsage } from "./usage/deepseek.js";
|
|
import { getCommandCodeUsage } from "./usage/commandcode.js";
|
|
import { getOpenCodeGoUsage } from "./usage/opencode-go.js";
|
|
import { getGroqUsage } from "./usage/groq.js";
|
|
import { getZedUsage } from "./usage/zed.js";
|
|
import { resolveQoderCredentials } from "./qoderModels.js";
|
|
import { getGlmUsage } from "./usage/glm.js";
|
|
import {
|
|
getIflowUsage,
|
|
getOllamaUsage,
|
|
getVercelAiGatewayUsage,
|
|
getQoderUsage,
|
|
} from "./usage/misc.js";
|
|
|
|
/**
|
|
* Get usage data for a provider connection
|
|
* @param {Object} connection - Provider connection with accessToken
|
|
* @returns {Object} Usage data with quotas
|
|
*/
|
|
// provider → usage handler (ctx carries every arg each handler needs)
|
|
const USAGE_HANDLERS = {
|
|
github: (c) => getGitHubUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
"gemini-cli": (c) => getGeminiUsage(c.accessToken, c.providerDataWithProjectId, c.proxyOptions),
|
|
antigravity: (c) => getAntigravityUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
claude: (c) => getClaudeUsage(c.accessToken, c.proxyOptions, { force: c.force }),
|
|
codex: (c) => getCodexUsage(c.accessToken, c.proxyOptions),
|
|
kiro: (c) => getKiroUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
qoder: async (c) => {
|
|
// PAT (pt-...) connections must be exchanged to a job token before the
|
|
// quota endpoint accepts them.
|
|
const resolved = await resolveQoderCredentials(c, c.proxyOptions).catch(() => null);
|
|
return getQoderUsage(resolved?.accessToken || c.accessToken, c.proxyOptions);
|
|
},
|
|
iflow: (c) => getIflowUsage(c.accessToken),
|
|
ollama: (c) => getOllamaUsage(c.apiKey, c.providerSpecificData, c.proxyOptions),
|
|
glm: (c) => getGlmUsage(c.apiKey, c.provider, c.proxyOptions),
|
|
"glm-cn": (c) => getGlmUsage(c.apiKey, c.provider, c.proxyOptions),
|
|
minimax: (c) => getMiniMaxUsage(c.apiKey, c.provider, c.proxyOptions),
|
|
"minimax-cn": (c) => getMiniMaxUsage(c.apiKey, c.provider, c.proxyOptions),
|
|
"vercel-ai-gateway": (c) => getVercelAiGatewayUsage(c.apiKey, c.proxyOptions),
|
|
"codebuddy-cn": (c) => getCodeBuddyCnUsage(c.accessToken, c.apiKey, c.providerSpecificData, c.proxyOptions),
|
|
xai: (c) => getXaiUsage(c.accessToken, c.proxyOptions),
|
|
"codebuddy-intl": (c) => getCodeBuddyIntlUsage(c.accessToken, c.apiKey, c.providerSpecificData, c.proxyOptions),
|
|
"grok-cli": (c) => getGrokCliUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
kimi: (c) => getKimiUsage(c.accessToken, c.apiKey, c.proxyOptions, c.providerSpecificData),
|
|
"opencode-go": (c) => getOpenCodeGoUsage(c.apiKey, c.proxyOptions),
|
|
deepseek: (c) => getDeepseekUsage(c.apiKey, c.proxyOptions),
|
|
commandcode: (c) => getCommandCodeUsage(c.apiKey, c.proxyOptions),
|
|
groq: (c) => getGroqUsage(c.apiKey, c.proxyOptions),
|
|
zed: (c) => getZedUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
};
|
|
|
|
export async function getUsageForProvider(connection, proxyOptions = null, options = {}) {
|
|
const { provider, accessToken, apiKey, providerSpecificData, projectId } = connection;
|
|
const providerDataWithProjectId = {
|
|
...(providerSpecificData || {}),
|
|
...(projectId ? { projectId } : {}),
|
|
};
|
|
|
|
const handler = USAGE_HANDLERS[provider];
|
|
if (!handler) return { message: `Usage API not implemented for ${provider}` };
|
|
return await handler({
|
|
provider,
|
|
accessToken,
|
|
apiKey,
|
|
providerSpecificData,
|
|
providerDataWithProjectId,
|
|
proxyOptions,
|
|
force: options.force === true,
|
|
});
|
|
}
|