mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-07 15:52:52 +03:00
* chore(usage): extract crof, nanogpt, qoder, opencode, deepseek, bailian, vertex, xiaomi-mimo, xai, github usage fetchers into usage/* leaves Decompose services/usage.ts (god-file phase 1): move the remaining per-provider usage fetcher/parser logic into co-located leaves under open-sse/services/usage/ so usage.ts becomes a thin dispatcher (imports + USAGE_FETCHER_PROVIDERS + getUsageForProvider switch + __testing re-exports). New leaves (each a pure data transform or independent fetcher, no orchestration): - usage/github.ts getGitHubUsage, formatGitHubQuotaSnapshot, inferGitHubPlanName, shouldDisplayGitHubQuota - usage/crof.ts getCrofUsage - usage/nanogpt.ts getNanoGptUsage - usage/qoder.ts getQoderUsage, parseQoderUserStatusUsage - usage/opencode.ts getOpencodeUsage - usage/deepseek.ts getDeepseekUsage - usage/bailian.ts getBailianCodingPlanUsage - usage/vertex.ts getVertexUsage - usage/xiaomi-mimo.ts getXiaomiMimoUsage - usage/xai.ts getXaiUsage usage.ts re-exports parseQoderUserStatusUsage (named) and threads every helper the existing __testing contract exposes (usage-utils / usage-service-hardening / qoder-usage-quota / xiaomi-mimo-selftrack / xai-usage / vertex-spend suites read them from services/usage). External importers unchanged. open-sse/services/usage.ts: 1065 -> 256 lines (cap 800). npm run check:file-size: OK. typecheck:core: OK. eslint: clean. check:cycles: OK. Added characterization tests (tests/unit/usage-<provider>-split.test.ts) that import each leaf directly and pin its export surface + key edges, mirroring the existing usage-quota-core-split / usage-scalars-split pattern. * docs(changelog): add fragment for this PR
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
/**
|
|
* usage/deepseek.ts — DeepSeek usage fetcher.
|
|
*
|
|
* Extracted from services/usage.ts (god-file decomposition): the DeepSeek family —
|
|
* delegates to the dedicated deepseekQuotaFetcher and shapes the balance result
|
|
* into the standard `{ plan, quotas }` usage response (all balances surfaced as
|
|
* credits-style entries). Depends only on the sibling scalar/quota leaves +
|
|
* fetchDeepseekQuota — no host coupling — so it lives as a co-located provider
|
|
* leaf. usage.ts imports getDeepseekUsage (dispatcher). Behavior-preserving move.
|
|
*/
|
|
|
|
import { fetchDeepseekQuota, type DeepseekQuota } from "../deepseekQuotaFetcher.ts";
|
|
import { type UsageQuota } from "./quota.ts";
|
|
|
|
/**
|
|
* DeepSeek Usage
|
|
* Fetches balance from the DeepSeek balance API.
|
|
* Returns all balances (USD and CNY) as "credits" for credits-style UI display.
|
|
*/
|
|
export async function getDeepseekUsage(connectionId: string, apiKey: string) {
|
|
try {
|
|
const connection = { apiKey };
|
|
const quota = await fetchDeepseekQuota(connectionId, connection);
|
|
|
|
if (!quota) {
|
|
return { message: "DeepSeek API key not available. Add a key to view usage." };
|
|
}
|
|
|
|
const deepseekQuota = quota as DeepseekQuota;
|
|
const { balances, isAvailable, limitReached } = deepseekQuota;
|
|
|
|
const quotas: Record<string, UsageQuota> = {};
|
|
|
|
// Show all balances as credits-style entries (e.g., credits_usd, credits_cny)
|
|
// The UI will display them as "🪙 Balance (USD) $50.00"
|
|
for (const balanceInfo of balances) {
|
|
const key = `credits_${balanceInfo.currency.toLowerCase()}`;
|
|
quotas[key] = {
|
|
used: 0,
|
|
total: 0,
|
|
remaining: balanceInfo.balance,
|
|
remainingPercentage: 100,
|
|
resetAt: null,
|
|
unlimited: true,
|
|
currency: balanceInfo.currency,
|
|
grantedBalance: balanceInfo.grantedBalance,
|
|
toppedUpBalance: balanceInfo.toppedUpBalance,
|
|
};
|
|
}
|
|
|
|
const plan = isAvailable ? "DeepSeek" : "DeepSeek (Insufficient Balance)";
|
|
|
|
return {
|
|
plan,
|
|
quotas,
|
|
isAvailable,
|
|
limitReached,
|
|
};
|
|
} catch (error) {
|
|
return { message: `DeepSeek error: ${(error as Error).message}` };
|
|
}
|
|
}
|