Skip to content

Commit 549e95b

Browse files
committed
refactor: extract runtime preemptive quota helper
1 parent 08e44fe commit 549e95b

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ import {
182182
sanitizeResponseHeadersForLog,
183183
} from "./lib/runtime/metrics.js";
184184
import { runOAuthBrowserFlow } from "./lib/runtime/oauth-browser-flow.js";
185+
import { applyRuntimePreemptiveQuotaSettings } from "./lib/runtime/preemptive-quota.js";
185186
import { ensureRuntimeRefreshGuardian } from "./lib/runtime/refresh-guardian.js";
186187
import { ensureRuntimeSessionAffinity } from "./lib/runtime/session-affinity.js";
187188
import { showRuntimeToast } from "./lib/runtime/toast.js";
@@ -521,13 +522,12 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
521522
const applyPreemptiveQuotaSettings = (
522523
pluginConfig: ReturnType<typeof loadPluginConfig>,
523524
): void => {
524-
preemptiveQuotaScheduler.configure({
525-
enabled: getPreemptiveQuotaEnabled(pluginConfig),
526-
remainingPercentThresholdPrimary:
527-
getPreemptiveQuotaRemainingPercent5h(pluginConfig),
528-
remainingPercentThresholdSecondary:
529-
getPreemptiveQuotaRemainingPercent7d(pluginConfig),
530-
maxDeferralMs: getPreemptiveQuotaMaxDeferralMs(pluginConfig),
525+
applyRuntimePreemptiveQuotaSettings(pluginConfig, {
526+
configure: (options) => preemptiveQuotaScheduler.configure(options),
527+
getPreemptiveQuotaEnabled,
528+
getPreemptiveQuotaRemainingPercent5h,
529+
getPreemptiveQuotaRemainingPercent7d,
530+
getPreemptiveQuotaMaxDeferralMs,
531531
});
532532
};
533533

lib/runtime/preemptive-quota.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function applyRuntimePreemptiveQuotaSettings<TConfig>(
2+
pluginConfig: TConfig,
3+
deps: {
4+
configure: (options: {
5+
enabled: boolean;
6+
remainingPercentThresholdPrimary: number;
7+
remainingPercentThresholdSecondary: number;
8+
maxDeferralMs: number;
9+
}) => void;
10+
getPreemptiveQuotaEnabled: (config: TConfig) => boolean;
11+
getPreemptiveQuotaRemainingPercent5h: (config: TConfig) => number;
12+
getPreemptiveQuotaRemainingPercent7d: (config: TConfig) => number;
13+
getPreemptiveQuotaMaxDeferralMs: (config: TConfig) => number;
14+
},
15+
): void {
16+
deps.configure({
17+
enabled: deps.getPreemptiveQuotaEnabled(pluginConfig),
18+
remainingPercentThresholdPrimary:
19+
deps.getPreemptiveQuotaRemainingPercent5h(pluginConfig),
20+
remainingPercentThresholdSecondary:
21+
deps.getPreemptiveQuotaRemainingPercent7d(pluginConfig),
22+
maxDeferralMs: deps.getPreemptiveQuotaMaxDeferralMs(pluginConfig),
23+
});
24+
}

0 commit comments

Comments
 (0)