Skip to content

Commit 2ddd9fb

Browse files
committed
cleanup
1 parent 84b2830 commit 2ddd9fb

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

src/browser/components/AIView.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { useAIViewKeybinds } from "@/browser/hooks/useAIViewKeybinds";
3636
import { evictModelFromLRU } from "@/browser/hooks/useModelLRU";
3737
import { QueuedMessage } from "./Messages/QueuedMessage";
3838
import { CompactionWarning } from "./CompactionWarning";
39-
import { shouldAutoCompact } from "@/browser/utils/compaction/autoCompactionCheck";
39+
import { checkAutoCompaction } from "@/browser/utils/compaction/autoCompactionCheck";
4040
import { useProviderOptions } from "@/browser/hooks/useProviderOptions";
4141
import { useAutoCompactionSettings } from "../hooks/useAutoCompactionSettings";
4242

@@ -331,7 +331,7 @@ const AIViewInner: React.FC<AIViewProps> = ({
331331
// Get active stream message ID for token counting
332332
const activeStreamMessageId = aggregator.getActiveStreamMessageId();
333333

334-
const autoCompactionCheck = shouldAutoCompact(
334+
const autoCompactionResult = checkAutoCompaction(
335335
workspaceUsage,
336336
currentModel,
337337
use1M,
@@ -340,7 +340,7 @@ const AIViewInner: React.FC<AIViewProps> = ({
340340
);
341341

342342
// Show warning when: shouldShowWarning flag is true AND not currently compacting
343-
const shouldShowCompactionWarning = !isCompacting && autoCompactionCheck.shouldShowWarning;
343+
const shouldShowCompactionWarning = !isCompacting && autoCompactionResult.shouldShowWarning;
344344

345345
// Note: We intentionally do NOT reset autoRetry when streams start.
346346
// If user pressed the interrupt key, autoRetry stays false until they manually retry.
@@ -529,8 +529,8 @@ const AIViewInner: React.FC<AIViewProps> = ({
529529
</div>
530530
{shouldShowCompactionWarning && (
531531
<CompactionWarning
532-
usagePercentage={autoCompactionCheck.usagePercentage}
533-
thresholdPercentage={autoCompactionCheck.thresholdPercentage}
532+
usagePercentage={autoCompactionResult.usagePercentage}
533+
thresholdPercentage={autoCompactionResult.thresholdPercentage}
534534
/>
535535
)}
536536
<ChatInput
@@ -546,7 +546,7 @@ const AIViewInner: React.FC<AIViewProps> = ({
546546
onEditLastUserMessage={() => void handleEditLastUserMessage()}
547547
canInterrupt={canInterrupt}
548548
onReady={handleChatInputReady}
549-
autoCompactionCheck={autoCompactionCheck}
549+
autoCompactionCheck={autoCompactionResult}
550550
/>
551551
</div>
552552

src/browser/utils/compaction/autoCompactionCheck.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface AutoCompactionCheckResult {
2424
shouldShowWarning: boolean;
2525
usagePercentage: number;
2626
thresholdPercentage: number;
27-
enabled: boolean;
2827
}
2928

3029
// Show warning this many percentage points before threshold
@@ -45,53 +44,33 @@ const WARNING_ADVANCE_PERCENT = 10;
4544
* @param warningAdvancePercent - Show warning this many percentage points before threshold (default 10)
4645
* @returns Check result with warning flag and usage percentage
4746
*/
48-
export function shouldAutoCompact(
47+
export function checkAutoCompaction(
4948
usage: WorkspaceUsageState | undefined,
50-
model: string | null | undefined,
49+
model: string | null,
5150
use1M: boolean,
52-
enabled = true,
51+
enabled: boolean,
5352
threshold: number = DEFAULT_AUTO_COMPACTION_THRESHOLD,
5453
warningAdvancePercent: number = WARNING_ADVANCE_PERCENT
5554
): AutoCompactionCheckResult {
5655
const thresholdPercentage = threshold * 100;
5756

5857
// Short-circuit if auto-compaction is disabled
59-
if (!enabled || !model) {
58+
// Or if no usage data yet
59+
if (!enabled || !model || !usage || usage.usageHistory.length === 0) {
6060
return {
6161
shouldShowWarning: false,
6262
usagePercentage: 0,
6363
thresholdPercentage,
64-
enabled: false,
65-
};
66-
}
67-
68-
// No usage data yet - safe default (don't trigger on first message)
69-
if (!usage || usage.usageHistory.length === 0) {
70-
return {
71-
shouldShowWarning: false,
72-
usagePercentage: 0,
73-
thresholdPercentage,
74-
enabled: true,
7564
};
7665
}
7766

7867
// Determine max tokens for this model
7968
const modelStats = getModelStats(model);
8069
const maxTokens = use1M && supports1MContext(model) ? 1_000_000 : modelStats?.max_input_tokens;
70+
const lastUsage = usage.usageHistory[usage.usageHistory.length - 1];
8171

8272
// No max tokens known - safe default (can't calculate percentage)
8373
if (!maxTokens) {
84-
return {
85-
shouldShowWarning: false,
86-
usagePercentage: 0,
87-
thresholdPercentage,
88-
enabled: true,
89-
};
90-
}
91-
92-
// Use last usage entry to calculate current context size (matches UI display)
93-
const lastUsage = usage.usageHistory[usage.usageHistory.length - 1];
94-
if (!lastUsage) {
9574
return {
9675
shouldShowWarning: false,
9776
usagePercentage: 0,
@@ -115,6 +94,5 @@ export function shouldAutoCompact(
11594
shouldShowWarning,
11695
usagePercentage,
11796
thresholdPercentage,
118-
enabled: true,
11997
};
12098
}

0 commit comments

Comments
 (0)