mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 12:22:34 +03:00
feat(quota): Moonshot Open Platform balance and TPD lock for custom nodes (#12590)
Validado em lote numa worktree combinada com os 9 PRs desta leva sobre o tip de `release/v3.8.51`: `typecheck:core` limpo, `check:provider-consistency` OK (273 entradas REGISTRY, **356** providers canônicos), `check-docs-counts-sync` exit 0 e **300/300** nos testes que a leva toca. O crescimento de arquivo que os PRs empilham uns sobre os outros foi rebaselinado num único registro datado (`_rebaseline_2026_09_03_houminxi_batch`), com a decomposição por arquivo: `providers/page.tsx` +18 (import CSV do #12504 + busca do #12495 no mesmo painel), `accountFallback.ts` +6 (o #12566 sobre o rebaseline que o #12590 já registrou — os dois tocam `checkFallbackError`) e `chatCore.ts` +3 (invalidez de cache de quota no 429 do #12325). As violações restantes (`codex.ts`, `stream.ts`) foram medidas também no tip puro e são drift da base, não desta leva.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { hasSelfAccountQuotaScope, hasSelfUsageScope } from "@/shared/constants/selfServiceScopes";
|
||||
import { USAGE_SUPPORTED_PROVIDERS } from "@/shared/constants/providers";
|
||||
import { supportsProviderQuota } from "@/shared/utils/providerQuotaVisibility";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
type DateLike = number | string | Date | null | undefined;
|
||||
@@ -64,6 +64,7 @@ interface AccountQuotaConnection {
|
||||
id: string;
|
||||
provider: string;
|
||||
lookupFailed?: boolean;
|
||||
providerSpecificData?: unknown;
|
||||
}
|
||||
|
||||
function toNumber(value: unknown, fallback = 0): number {
|
||||
@@ -208,11 +209,14 @@ function normalizePlan(value: unknown): unknown {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isSupportedProvider(provider: string): boolean {
|
||||
return USAGE_SUPPORTED_PROVIDERS.includes(provider as (typeof USAGE_SUPPORTED_PROVIDERS)[number]);
|
||||
function isSupportedProvider(
|
||||
provider: string,
|
||||
connection?: { provider?: string; providerSpecificData?: unknown },
|
||||
): boolean {
|
||||
return supportsProviderQuota(provider, connection);
|
||||
}
|
||||
|
||||
function getConnectionIdentity(value: unknown): { id: string; provider: string } | null {
|
||||
function getConnectionIdentity(value: unknown): AccountQuotaConnection | null {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
||||
const record = value as JsonRecord;
|
||||
if (record.isActive === false) return null;
|
||||
@@ -221,7 +225,11 @@ function getConnectionIdentity(value: unknown): { id: string; provider: string }
|
||||
const provider = typeof record.provider === "string" ? record.provider : "";
|
||||
if (!id || !provider) return null;
|
||||
|
||||
return { id, provider };
|
||||
return {
|
||||
id,
|
||||
provider,
|
||||
providerSpecificData: record.providerSpecificData,
|
||||
};
|
||||
}
|
||||
|
||||
async function listAccountQuotaConnections(
|
||||
@@ -297,7 +305,7 @@ async function resolveConnectionAccountQuota(
|
||||
};
|
||||
}
|
||||
|
||||
if (!isSupportedProvider(connection.provider)) {
|
||||
if (!isSupportedProvider(connection.provider, connection)) {
|
||||
return {
|
||||
provider: connection.provider,
|
||||
connectionId: connection.id,
|
||||
|
||||
Reference in New Issue
Block a user