Skip to content

Commit 875404b

Browse files
committed
style: improve code readability with better formatting
- Format long `baseQuery` calls with try/finally blocks in providers.ts - Restructure hook destructuring and replace manual ref updates with useEffect in ProviderUsageIndicator.tsx - Minor formatting fix in stats reader (to_lowercase)
1 parent 72a89b1 commit 875404b

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

refact-agent/engine/src/stats/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub fn aggregate_summary(events: &[LlmCallEvent], from: Option<&str>, to: Option
343343
}
344344
day_acc.total_duration_ms += event.duration_ms;
345345

346-
let mode_acc = by_mode_map.entry(event.mode.clone()).or_insert_with(|| ModeAcc {
346+
let mode_acc = by_mode_map.entry(event.mode.to_lowercase()).or_insert_with(|| ModeAcc {
347347
total_calls: 0,
348348
total_tokens: 0,
349349
total_cost_usd: 0.0,

refact-agent/gui/src/components/UsageCounter/ProviderUsageIndicator.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,24 @@ const ProviderIndicator: React.FC<{
202202
);
203203

204204
export const ProviderUsageIndicator: React.FC = () => {
205-
const { data: claudeUsage, refetch: refetchClaude } =
206-
useGetClaudeCodeUsageQuery(undefined, {
207-
pollingInterval: 30_000,
208-
});
205+
const { data: claudeUsage } = useGetClaudeCodeUsageQuery(undefined, {
206+
pollingInterval: 30_000,
207+
});
209208

210-
const { data: codexUsage, refetch: refetchCodex } =
211-
useGetOpenAICodexUsageQuery(undefined, {
212-
pollingInterval: 30_000,
213-
});
214-
215-
useEffect(() => {
216-
void refetchClaude();
217-
void refetchCodex();
218-
}, [refetchClaude, refetchCodex]);
209+
const { data: codexUsage } = useGetOpenAICodexUsageQuery(undefined, {
210+
pollingInterval: 30_000,
211+
});
219212

220213
const lastClaudeRef = useRef(claudeUsage);
221214
const lastCodexRef = useRef(codexUsage);
222-
if (claudeUsage !== undefined) lastClaudeRef.current = claudeUsage;
223-
if (codexUsage !== undefined) lastCodexRef.current = codexUsage;
215+
216+
useEffect(() => {
217+
if (claudeUsage !== undefined) lastClaudeRef.current = claudeUsage;
218+
}, [claudeUsage]);
219+
220+
useEffect(() => {
221+
if (codexUsage !== undefined) lastCodexRef.current = codexUsage;
222+
}, [codexUsage]);
224223

225224
const stickyClaudeUsage = lastClaudeRef.current;
226225
const stickyCodexUsage = lastCodexRef.current;

refact-agent/gui/src/services/refact/providers.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,19 @@ export const providersApi = createApi({
563563

564564
const controller = new AbortController();
565565
const timeoutId = setTimeout(() => controller.abort(), 10_000);
566-
const result = await baseQuery({
567-
...extraOptions,
568-
method: "GET",
569-
url,
570-
credentials: "same-origin",
571-
redirect: "follow",
572-
signal: controller.signal,
573-
});
574-
clearTimeout(timeoutId);
566+
let result: Awaited<ReturnType<typeof baseQuery>>;
567+
try {
568+
result = await baseQuery({
569+
...extraOptions,
570+
method: "GET",
571+
url,
572+
credentials: "same-origin",
573+
redirect: "follow",
574+
signal: controller.signal,
575+
});
576+
} finally {
577+
clearTimeout(timeoutId);
578+
}
575579

576580
if (result.error) {
577581
return { error: result.error };
@@ -600,15 +604,19 @@ export const providersApi = createApi({
600604

601605
const controller = new AbortController();
602606
const timeoutId = setTimeout(() => controller.abort(), 10_000);
603-
const result = await baseQuery({
604-
...extraOptions,
605-
method: "GET",
606-
url,
607-
credentials: "same-origin",
608-
redirect: "follow",
609-
signal: controller.signal,
610-
});
611-
clearTimeout(timeoutId);
607+
let result: Awaited<ReturnType<typeof baseQuery>>;
608+
try {
609+
result = await baseQuery({
610+
...extraOptions,
611+
method: "GET",
612+
url,
613+
credentials: "same-origin",
614+
redirect: "follow",
615+
signal: controller.signal,
616+
});
617+
} finally {
618+
clearTimeout(timeoutId);
619+
}
612620

613621
if (result.error) {
614622
return { error: result.error };

0 commit comments

Comments
 (0)