Skip to content

Commit cab5b24

Browse files
authored
feat(sessions): add compact option to stale conversation cost warning (#3154)
1 parent 7c1f4cc commit cab5b24

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

packages/ui/src/features/sessions/components/SessionView.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,12 @@ export function SessionView({
643643
lastActivityAt={staleGate.lastActivityAt}
644644
costUsd={staleGate.costUsd}
645645
onContinue={staleGate.onContinue}
646+
onCompact={() => {
647+
// Acknowledge so the gate clears and the dialog
648+
// closes, then trigger the agent's manual compaction.
649+
staleGate.onContinue();
650+
onSendPrompt("/compact");
651+
}}
646652
onOpenChange={staleGate.onDialogOpenChange}
647653
/>
648654
<PromptInput

packages/ui/src/features/sessions/components/StaleConversationCostDialog.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface StaleConversationCostDialogProps {
1010
/** Cumulative session cost so far, when the gateway reports it. */
1111
costUsd: number | null;
1212
onContinue: () => void;
13+
/** Compact the history in place (runs `/compact`) instead of reloading it whole. */
14+
onCompact: () => void;
1315
onOpenChange: (open: boolean) => void;
1416
}
1517

@@ -19,6 +21,7 @@ export function StaleConversationCostDialog({
1921
lastActivityAt,
2022
costUsd,
2123
onContinue,
24+
onCompact,
2225
onOpenChange,
2326
}: StaleConversationCostDialogProps) {
2427
const activity =
@@ -40,8 +43,9 @@ export function StaleConversationCostDialog({
4043
message re-processes the whole conversation at full input price
4144
instead of the ~10% cached rate
4245
{costUsd !== null ? ` (≈$${costUsd.toFixed(2)} spent so far)` : ""}.
43-
Starting a new conversation avoids the cost — continue only if you
44-
need this thread's context.
46+
Compacting summarizes the history so you keep this thread's context at
47+
a fraction of the size, or start a new conversation to avoid the cost
48+
entirely.
4549
</AlertDialog.Description>
4650

4751
<Flex justify="end" gap="2" mt="4">
@@ -51,10 +55,15 @@ export function StaleConversationCostDialog({
5155
</Button>
5256
</AlertDialog.Cancel>
5357
<AlertDialog.Action>
54-
<Button variant="solid" size="1" onClick={onContinue}>
58+
<Button variant="soft" color="gray" size="1" onClick={onContinue}>
5559
Continue anyway
5660
</Button>
5761
</AlertDialog.Action>
62+
<AlertDialog.Action>
63+
<Button variant="solid" size="1" onClick={onCompact}>
64+
Compact instead
65+
</Button>
66+
</AlertDialog.Action>
5867
</Flex>
5968
</AlertDialog.Content>
6069
</AlertDialog.Root>

0 commit comments

Comments
 (0)