Skip to content

Commit 584dbd6

Browse files
fix(web): show limit recovery in the banner stack
1 parent f759432 commit 584dbd6

3 files changed

Lines changed: 98 additions & 83 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UsageLimitRecoveryCard } from "./chat/UsageLimitRecoveryCard";
1+
import { usageLimitRecoveryBannerItem } from "./chat/UsageLimitRecoveryBanner";
22
import {
33
resolveBackgroundDraftWorkspaceOptions,
44
resolveDraftHeroState,
@@ -6966,7 +6966,27 @@ export default function ChatView(props: ChatViewProps) {
69666966
}),
69676967
[feedbackSubmissions, routeThreadKey],
69686968
);
6969+
const limitRecoveryBanner =
6970+
serverRuntime?.status === "failed" &&
6971+
serverRuntime.lastErrorClass === "usage_limit" &&
6972+
activeThreadShell?.latestRun
6973+
? usageLimitRecoveryBannerItem({
6974+
runId: activeThreadShell.latestRun.runId,
6975+
resetAt: serverRuntime.usageLimitResetAt ?? null,
6976+
stoppedAt: activeThreadShell.latestRun.completedAt ?? activeThreadShell.updatedAt,
6977+
recovery: activeThreadShell.limitRecovery ?? null,
6978+
explanation: serverRuntime.lastError,
6979+
onChange: async (limitRecovery) => {
6980+
const result = await updateThreadMetadata({
6981+
environmentId,
6982+
input: { threadId: activeThreadShell.id, limitRecovery },
6983+
});
6984+
if (result._tag === "Failure") throw squashAtomCommandFailure(result);
6985+
},
6986+
})
6987+
: null;
69696988
const composerBannerItems = useMemo<ComposerBannerStackItem[]>(() => {
6989+
const limitRecoveryItems = limitRecoveryBanner === null ? [] : [limitRecoveryBanner];
69706990
const backgroundWorkItems = backgroundWorkBannerItem === null ? [] : [backgroundWorkBannerItem];
69716991
const resumeCompactionItems =
69726992
resumeCompactionBannerItem === null ? [] : [resumeCompactionBannerItem];
@@ -6978,6 +6998,7 @@ export default function ChatView(props: ChatViewProps) {
69786998
if (!localCheckoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) {
69796999
return [
69807000
...feedbackBannerItems,
7001+
...limitRecoveryItems,
69817002
...usageLimitsItems,
69827003
...projectCloneItems,
69837004
...systemComposerBannerItems,
@@ -6989,6 +7010,7 @@ export default function ChatView(props: ChatViewProps) {
69897010
}
69907011
return [
69917012
...feedbackBannerItems,
7013+
...limitRecoveryItems,
69927014
...usageLimitsItems,
69937015
...projectCloneItems,
69947016
...systemComposerBannerItems,
@@ -7038,6 +7060,7 @@ export default function ChatView(props: ChatViewProps) {
70387060
}, [
70397061
activeBranchMismatchKey,
70407062
feedbackBannerItems,
7063+
limitRecoveryBanner,
70417064
handleRestoreThreadBranch,
70427065
isRestoringThreadBranch,
70437066
backgroundWorkBannerItem,
@@ -10357,7 +10380,11 @@ export default function ChatView(props: ChatViewProps) {
1035710380
onOpenProviderSetup={openProviderSetup}
1035810381
/>
1035910382
<ThreadErrorBanner
10360-
error={visibleThreadError}
10383+
error={
10384+
limitRecoveryBanner !== null && visibleThreadError === serverRuntime?.lastError
10385+
? null
10386+
: visibleThreadError
10387+
}
1036110388
errorClass={
1036210389
localServerError === null && visibleThreadError === serverRuntime?.lastError
1036310390
? (serverRuntime?.lastErrorClass ?? null)
@@ -10505,26 +10532,6 @@ export default function ChatView(props: ChatViewProps) {
1050510532
data-chat-composer-stack="true"
1050610533
className="group/composer-stack pointer-events-auto relative z-10 mx-auto w-full max-w-3xl"
1050710534
>
10508-
{serverRuntime?.status === "failed" &&
10509-
serverRuntime.lastErrorClass === "usage_limit" &&
10510-
activeThreadShell?.latestRun ? (
10511-
<UsageLimitRecoveryCard
10512-
key={activeThreadShell.latestRun.runId}
10513-
stoppedAt={
10514-
activeThreadShell.latestRun.completedAt ?? activeThreadShell.updatedAt
10515-
}
10516-
runId={activeThreadShell.latestRun.runId}
10517-
resetAt={serverRuntime.usageLimitResetAt ?? null}
10518-
recovery={activeThreadShell.limitRecovery ?? null}
10519-
onChange={async (limitRecovery) => {
10520-
const result = await updateThreadMetadata({
10521-
environmentId,
10522-
input: { threadId: activeThread.id, limitRecovery },
10523-
});
10524-
if (result._tag === "Failure") throw squashAtomCommandFailure(result);
10525-
}}
10526-
/>
10527-
) : null}
1052810535
{isDraftHeroState ? (
1052910536
<div className="absolute inset-x-0 bottom-full">
1053010537
<div
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { type OrchestrationV2LimitRecovery, type RunId } from "@t3tools/contracts";
2+
import { GaugeIcon } from "lucide-react";
3+
import { useState } from "react";
4+
import { Button } from "../ui/button";
5+
import type { ComposerBannerStackItem } from "./ComposerBannerStack";
6+
7+
type RecoveryProps = {
8+
runId: RunId;
9+
resetAt: string | null;
10+
stoppedAt: string;
11+
recovery: OrchestrationV2LimitRecovery | null;
12+
explanation: string | null;
13+
onChange: (recovery: OrchestrationV2LimitRecovery) => Promise<void>;
14+
};
15+
16+
export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBannerStackItem {
17+
const { runId, resetAt, stoppedAt, recovery, explanation } = props;
18+
const canSchedule = resetAt !== null && Date.parse(resetAt) > Date.parse(stoppedAt);
19+
const scheduled =
20+
recovery?.runId === runId && recovery.resetAt === resetAt && recovery.autoResume;
21+
return {
22+
id: `usage-limit-recovery:${runId}`,
23+
variant: "warning",
24+
priority: "urgent",
25+
icon: <GaugeIcon />,
26+
title: "Usage limit reached",
27+
description: resetAt
28+
? `Resets ${new Date(resetAt).toLocaleString()}`
29+
: "Reset time unavailable; retry manually",
30+
children: (
31+
<div className="space-y-1 text-xs text-muted-foreground">
32+
{explanation ? <p>{explanation}</p> : null}
33+
{scheduled ? <p>Auto-resume is scheduled for the reset.</p> : null}
34+
</div>
35+
),
36+
actions: canSchedule ? <RecoveryActions key={runId} {...props} /> : null,
37+
};
38+
}
39+
40+
function RecoveryActions({ runId, resetAt, recovery, onChange }: RecoveryProps) {
41+
const [pending, setPending] = useState(false);
42+
const [error, setError] = useState<string | null>(null);
43+
const scheduled =
44+
recovery?.runId === runId && recovery.resetAt === resetAt && recovery.autoResume;
45+
async function toggle() {
46+
if (resetAt === null) return;
47+
setPending(true);
48+
setError(null);
49+
try {
50+
await onChange({ runId, resetAt, autoResume: !scheduled });
51+
} catch (cause) {
52+
setError(cause instanceof Error ? cause.message : "Could not change limit recovery.");
53+
} finally {
54+
setPending(false);
55+
}
56+
}
57+
return (
58+
<div className="flex flex-wrap items-center gap-2">
59+
<Button size="xs" variant="ghost" disabled={pending} onClick={() => void toggle()}>
60+
{pending ? "Saving..." : scheduled ? "Cancel auto-resume" : "Resume at reset"}
61+
</Button>
62+
{error ? (
63+
<p role="alert" className="basis-full text-xs text-destructive">
64+
{error}
65+
</p>
66+
) : null}
67+
</div>
68+
);
69+
}

‎apps/web/src/components/chat/UsageLimitRecoveryCard.tsx‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)