

























@@ -834,6 +834,34 @@ export async function markAuthProfileFailure(params: {
834834}
835835}
836836837+function buildBlockedProfileUsageStats(params: {
838+previousStats: ProfileUsageStats | undefined;
839+blockedUntil: number;
840+source: AuthProfileBlockedSource;
841+modelId: string | undefined;
842+now: number;
843+}): ProfileUsageStats {
844+const activeBlockedUntil = resolveActiveWindowUntil(
845+params.previousStats?.blockedUntil,
846+params.now,
847+);
848+return {
849+ ...params.previousStats,
850+blockedUntil: Math.max(activeBlockedUntil, params.blockedUntil),
851+blockedReason: "subscription_limit",
852+blockedSource: params.source,
853+blockedModel: params.modelId,
854+cooldownUntil: undefined,
855+cooldownReason: undefined,
856+cooldownModel: undefined,
857+lastFailureAt: params.now,
858+failureCounts: {
859+ ...params.previousStats?.failureCounts,
860+rate_limit: (params.previousStats?.failureCounts?.rate_limit ?? 0) + 1,
861+},
862+};
863+}
864+837865/** Marks a profile blocked until a provider-reported reset timestamp. */
838866export async function markAuthProfileBlockedUntil(params: {
839867store: AuthProfileStore;
@@ -870,22 +898,13 @@ export async function markAuthProfileBlockedUntil(params: {
870898}
871899previousStats = freshStore.usageStats?.[profileId];
872900updateTime = now;
873-const activeBlockedUntil = resolveActiveWindowUntil(previousStats?.blockedUntil, now);
874-nextStats = {
875- ...previousStats,
876-blockedUntil: Math.max(activeBlockedUntil, blockedUntil),
877-blockedReason: "subscription_limit",
878-blockedSource: source,
879-blockedModel: modelId,
880-cooldownUntil: undefined,
881-cooldownReason: undefined,
882-cooldownModel: undefined,
883-lastFailureAt: now,
884-failureCounts: {
885- ...previousStats?.failureCounts,
886-rate_limit: (previousStats?.failureCounts?.rate_limit ?? 0) + 1,
887-},
888-};
901+nextStats = buildBlockedProfileUsageStats({
902+ previousStats,
903+ blockedUntil,
904+ source,
905+ modelId,
906+ now,
907+});
889908updateUsageStatsEntry(freshStore, profileId, () => nextStats as ProfileUsageStats);
890909return true;
891910},
@@ -914,22 +933,13 @@ export async function markAuthProfileBlockedUntil(params: {
914933return;
915934}
916935previousStats = store.usageStats?.[profileId];
917-const activeBlockedUntil = resolveActiveWindowUntil(previousStats?.blockedUntil, now);
918-nextStats = {
919- ...previousStats,
920-blockedUntil: Math.max(activeBlockedUntil, blockedUntil),
921-blockedReason: "subscription_limit",
922-blockedSource: source,
923-blockedModel: modelId,
924-cooldownUntil: undefined,
925-cooldownReason: undefined,
926-cooldownModel: undefined,
927-lastFailureAt: now,
928-failureCounts: {
929- ...previousStats?.failureCounts,
930-rate_limit: (previousStats?.failureCounts?.rate_limit ?? 0) + 1,
931-},
932-};
936+nextStats = buildBlockedProfileUsageStats({
937+ previousStats,
938+ blockedUntil,
939+ source,
940+ modelId,
941+ now,
942+});
933943updateUsageStatsEntry(store, profileId, () => nextStats as ProfileUsageStats);
934944authProfileUsageDeps.saveAuthProfileStore(store, agentDir);
935945logAuthProfileFailureStateChange({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。