Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions apps/web/src/components/chat/UsageLimitRecoveryBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { GaugeIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { Button } from "../ui/button";
import { toastManager } from "../ui/toast";
import type { ComposerBannerStackItem } from "./ComposerBannerStack";

type RecoveryProps = {
Expand Down Expand Up @@ -35,7 +36,6 @@ export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBann

function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: RecoveryProps) {
const [pending, setPending] = useState(false);
const [error, setError] = useState<string | null>(null);
const [nowMs, setNowMs] = useState(() => Date.now());
useEffect(() => {
const delay = Date.parse(resetAt ?? "") - Math.max(nowMs, Date.now());
Expand All @@ -56,25 +56,34 @@ function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: R
async function toggle(action: "resume" | "snooze") {
if (resetAt === null) return;
if (action === "snooze" && !snoozed && Date.parse(resetAt) <= Date.now()) {
setError("The reset time has passed. Retry the thread manually.");
toastManager.add({
type: "error",
title: "Could not snooze thread",
description: "The reset time has passed. Retry the thread manually.",
});
setNowMs(Date.now());
return;
}
setPending(true);
setError(null);
try {
await onChange({
runId,
resetAt,
...(action === "resume" ? { autoResume: !scheduled } : { snooze: !snoozed }),
});
} catch (cause) {
setError(cause instanceof Error ? cause.message : "Could not change limit recovery.");
toastManager.add({
type: "error",
title: action === "resume" ? "Could not change auto-resume" : "Could not snooze thread",
description: cause instanceof Error ? cause.message : "An error occurred.",
});
}
setPending(false);
}
// Failures go to a toast: the actions column is auto-sized, so inline error
// text would widen it and crush the title.
return (
<div className="flex flex-wrap items-center gap-2">
<>
<Button size="xs" variant="ghost" disabled={pending} onClick={() => void toggle("resume")}>
{pending ? "Saving..." : scheduled ? "Cancel auto-resume" : "Resume at reset"}
</Button>
Expand All @@ -88,11 +97,6 @@ function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: R
{pending ? "Saving..." : "Snooze until reset"}
</Button>
) : null}
{error ? (
<p role="alert" className="basis-full text-xs text-destructive">
{error}
</p>
) : null}
</div>
</>
);
}
Loading