fix(quota): show all Z.ai usage windows
This commit is contained in:
@@ -222,7 +222,10 @@ const resolveGoogleWindow = (sourceId: GoogleAuthSource['sourceId'], resetAt: nu
|
||||
return { label: 'daily', seconds: GOOGLE_DAILY_WINDOW_SECONDS } as const;
|
||||
};
|
||||
|
||||
const ZAI_TOKEN_WINDOW_SECONDS: Record<number, number> = { 3: 3600 };
|
||||
const ZAI_TOKEN_WINDOW_SECONDS: Record<number, number> = {
|
||||
3: 60 * 60,
|
||||
6: 7 * 24 * 60 * 60,
|
||||
};
|
||||
|
||||
const readAuthFile = (): AuthFile => {
|
||||
if (!fs.existsSync(AUTH_FILE)) {
|
||||
@@ -1592,14 +1595,13 @@ const fetchZaiQuota = async (): Promise<ProviderResult> => {
|
||||
|
||||
const payload = await response.json() as ZaiPayload;
|
||||
const limits = Array.isArray(payload?.data?.limits) ? payload.data.limits : [];
|
||||
const tokensLimit = limits.find((limit: Record<string, unknown>) => limit?.type === 'TOKENS_LIMIT');
|
||||
const windowSeconds = resolveWindowSeconds(tokensLimit as Record<string, unknown> | undefined);
|
||||
const windowLabel = resolveWindowLabel(windowSeconds);
|
||||
const resetAt = tokensLimit?.nextResetTime ? normalizeTimestamp(tokensLimit.nextResetTime) : null;
|
||||
const usedPercent = typeof tokensLimit?.percentage === 'number' ? tokensLimit.percentage : null;
|
||||
|
||||
const windows: Record<string, UsageWindow> = {};
|
||||
if (tokensLimit) {
|
||||
for (const tokensLimit of limits.filter((limit) => limit?.type === 'TOKENS_LIMIT')) {
|
||||
const windowSeconds = resolveWindowSeconds(tokensLimit as Record<string, unknown>);
|
||||
const windowLabel = resolveWindowLabel(windowSeconds);
|
||||
const resetAt = tokensLimit.nextResetTime ? normalizeTimestamp(tokensLimit.nextResetTime) : null;
|
||||
const usedPercent = typeof tokensLimit.percentage === 'number' ? tokensLimit.percentage : null;
|
||||
|
||||
windows[windowLabel] = toUsageWindow({
|
||||
usedPercent,
|
||||
windowSeconds,
|
||||
@@ -1607,6 +1609,15 @@ const fetchZaiQuota = async (): Promise<ProviderResult> => {
|
||||
});
|
||||
}
|
||||
|
||||
const mcpToolsTimeLimit = limits.find((limit) => limit?.type === 'TIME_LIMIT');
|
||||
if (mcpToolsTimeLimit) {
|
||||
windows['MCP Tools'] = toUsageWindow({
|
||||
usedPercent: typeof mcpToolsTimeLimit.percentage === 'number' ? mcpToolsTimeLimit.percentage : null,
|
||||
windowSeconds: 30 * 24 * 60 * 60,
|
||||
resetAt: mcpToolsTimeLimit.nextResetTime ? normalizeTimestamp(mcpToolsTimeLimit.nextResetTime) : null,
|
||||
});
|
||||
}
|
||||
|
||||
return buildResult({
|
||||
providerId: 'zai-coding-plan',
|
||||
providerName: 'z.ai',
|
||||
|
||||
Reference in New Issue
Block a user