Ollama: replace informational stub with real quota tracker hitting ollama.com/api/usage (session 5h + weekly 7d, 0..1 ratio) and /api/me plan label; bind handler to apiKey + add features.usageApikey so apikey connections work.
Token refresh: add backgroundTokenRefresh scheduler that refreshes OAuth connections within max(provider lead, 30min) of expiry, independent of inbound traffic (10s after boot, then every 5min, unref'd timers, DISABLE_BACKGROUND_TOKEN_REFRESH kill-switch, fail-open per tick/connection). Registered from custom-server.js (listening) and initializeApp.js. checkAndRefreshToken gains opt-in {force} for the scheduler; request path unchanged.
64 lines
3.1 KiB
JavaScript
64 lines
3.1 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 } from "./usage/codebuddy-cn.js";
|
|
import { getGrokCliUsage } from "./usage/grok-cli.js";
|
|
import { getKimiUsage } from "./usage/kimi.js";
|
|
import { getDeepseekUsage } from "./usage/deepseek.js";
|
|
import {
|
|
getQwenUsage,
|
|
getIflowUsage,
|
|
getOllamaUsage,
|
|
getGlmUsage,
|
|
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),
|
|
codex: (c) => getCodexUsage(c.accessToken, c.proxyOptions),
|
|
kiro: (c) => getKiroUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
qoder: (c) => getQoderUsage(c.accessToken, c.proxyOptions),
|
|
qwen: (c) => getQwenUsage(c.accessToken, c.providerSpecificData),
|
|
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),
|
|
"grok-cli": (c) => getGrokCliUsage(c.accessToken, c.providerSpecificData, c.proxyOptions),
|
|
kimi: (c) => getKimiUsage(c.accessToken, c.apiKey, c.proxyOptions, c.providerSpecificData),
|
|
deepseek: (c) => getDeepseekUsage(c.apiKey, c.proxyOptions),
|
|
};
|
|
|
|
export async function getUsageForProvider(connection, proxyOptions = null) {
|
|
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 });
|
|
}
|