fix(webui): recover model failures and align chat controls
This commit is contained in:
1 parent
688976bcb9
commit
28f6c26946
42 files changed
+646
-82
No files matched your search
@@ -16,7 +16,7 @@ export function ModelFallbackNotice({ model, reauthProvider, reauthProviderLabel
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-center gap-2 rounded-control border border-border/60 bg-muted/40 px-3 py-2 text-xs text-foreground/80 animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none"
|
||||
className="thread-composer-notice mb-2 flex items-center gap-2 rounded-control border border-border/60 bg-muted/40 px-3 py-2 text-xs text-foreground/80 animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none"
|
||||
>
|
||||
<PresetProviderIcon
|
||||
provider={reauthProvider}
|
||||
|
||||
@@ -8,14 +8,16 @@ import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { RecoveryState } from "@/lib/types";
|
||||
import { resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
|
||||
|
||||
interface RecoveryNoticeProps {
|
||||
state: RecoveryState;
|
||||
onContinue: () => Promise<void>;
|
||||
onDismiss: () => Promise<void>;
|
||||
onOpenSettings?: () => void;
|
||||
}
|
||||
|
||||
export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeProps) {
|
||||
export function RecoveryNotice({ state, onContinue, onDismiss, onOpenSettings }: RecoveryNoticeProps) {
|
||||
const { t } = useTranslation();
|
||||
const [pending, setPending] = useState<"continue" | "dismiss" | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -33,14 +35,17 @@ export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeP
|
||||
if (!waiting || hiddenRecoveryId === state.recovery_id) return null;
|
||||
|
||||
const contextUnavailable = state.can_continue === false;
|
||||
const title = state.status === "failed"
|
||||
const modelFailure = state.reason === "model_request_failed"
|
||||
? resolveModelRequestFailureCopy({ errorKind: state.failure_error_kind }, t)
|
||||
: null;
|
||||
const title = modelFailure?.title ?? (state.status === "failed"
|
||||
? t("recovery.failed", { defaultValue: "Task recovery failed" })
|
||||
: t("recovery.interrupted", { defaultValue: "Task interrupted" });
|
||||
const detail = state.status === "failed" || contextUnavailable
|
||||
: t("recovery.interrupted", { defaultValue: "Task interrupted" }));
|
||||
const detail = contextUnavailable || state.status === "failed"
|
||||
? t("recovery.failedHelp", {
|
||||
defaultValue: "The saved task could not be restored safely. Review it before continuing.",
|
||||
})
|
||||
: t("recovery.review", { defaultValue: "Review the task before continuing. Tools will not be replayed automatically." });
|
||||
: modelFailure?.body ?? t("recovery.review", { defaultValue: "Review the task before continuing. Tools will not be replayed automatically." });
|
||||
const run = (action: "continue" | "dismiss") => {
|
||||
setPending(action);
|
||||
setError(null);
|
||||
@@ -60,13 +65,18 @@ export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeP
|
||||
role="alert"
|
||||
aria-live="assertive"
|
||||
data-recovery-status={state.status}
|
||||
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-center gap-3 rounded-control border border-border/70 bg-muted/35 px-3 py-2 text-sm transition-[background-color,border-color,opacity,transform] duration-200 ease-out motion-reduce:transition-none animate-in fade-in-0 slide-in-from-bottom-1 duration-200 motion-reduce:animate-none"
|
||||
className="thread-composer-notice mb-2 flex flex-wrap items-center gap-3 rounded-control border border-border/70 bg-muted/35 px-3 py-2 text-sm transition-[background-color,border-color,opacity,transform] duration-200 ease-out motion-reduce:transition-none animate-in fade-in-0 slide-in-from-bottom-1 duration-200 motion-reduce:animate-none"
|
||||
>
|
||||
<AlertTriangle className="h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="min-w-0 flex-1 basis-48">
|
||||
<p className="font-medium">
|
||||
{title}
|
||||
</p>
|
||||
{modelFailure && onOpenSettings ? (
|
||||
<Button variant="link" size="sm" className="h-auto px-0 py-1" onClick={onOpenSettings}>
|
||||
{t("thread.composer.reauthSettings")}
|
||||
</Button>
|
||||
) : null}
|
||||
<p className={cn(
|
||||
"mt-0.5 text-xs",
|
||||
error ? "text-destructive" : "text-muted-foreground",
|
||||
@@ -74,7 +84,7 @@ export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeP
|
||||
{error ?? detail}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
<div className="ms-auto flex shrink-0 items-center gap-1.5">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { StreamError } from "@/lib/nanobot-client";
|
||||
interface StreamErrorNoticeProps {
|
||||
error: StreamError;
|
||||
onDismiss: () => void;
|
||||
onOpenSettings?: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,7 +18,7 @@ interface StreamErrorNoticeProps {
|
||||
* visible failed message. ``role="alert"`` + ``aria-live="assertive"``
|
||||
* ensures screen readers announce the failure.
|
||||
*/
|
||||
export function StreamErrorNotice({ error, onDismiss }: StreamErrorNoticeProps) {
|
||||
export function StreamErrorNotice({ error, onDismiss, onOpenSettings }: StreamErrorNoticeProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { title, body } = resolveCopy(error, t);
|
||||
@@ -27,7 +28,7 @@ export function StreamErrorNotice({ error, onDismiss }: StreamErrorNoticeProps)
|
||||
role="alert"
|
||||
aria-live="assertive"
|
||||
className={cn(
|
||||
"mb-2 flex items-start gap-2 rounded-lg border border-destructive/30",
|
||||
"thread-composer-notice mb-2 flex items-start gap-2 rounded-control border border-destructive/30",
|
||||
"bg-destructive/10 px-3 py-2 text-[12px] leading-5 text-destructive",
|
||||
"animate-in fade-in-0 slide-in-from-bottom-1",
|
||||
)}
|
||||
@@ -36,9 +37,14 @@ export function StreamErrorNotice({ error, onDismiss }: StreamErrorNoticeProps)
|
||||
className="mt-0.5 h-4 w-4 shrink-0"
|
||||
aria-hidden
|
||||
/>
|
||||
<div className="flex-1">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-medium">{title}</p>
|
||||
<p className="mt-0.5 text-destructive">{body}</p>
|
||||
{error.kind === "model_request_failed" && onOpenSettings ? (
|
||||
<Button variant="link" size="sm" className="h-auto px-0 py-1" onClick={onOpenSettings}>
|
||||
{t("thread.composer.reauthSettings")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
||||
@@ -2565,8 +2565,8 @@ export function ThreadComposer({
|
||||
"thread-composer-surface group/composer relative mx-auto flex w-full flex-col overflow-visible transition-all duration-200",
|
||||
paletteBeside && "col-start-1 row-start-1",
|
||||
isHero
|
||||
? "max-w-[58rem] rounded-prominent bg-muted/80 focus-within:bg-muted dark:bg-card dark:focus-within:bg-white/[0.06]"
|
||||
: "max-w-[49.5rem] rounded-panel bg-muted/80 focus-within:bg-muted dark:bg-card dark:focus-within:bg-white/[0.06]",
|
||||
? "max-w-[var(--composer-content-width,58rem)] rounded-prominent bg-muted/80 focus-within:bg-muted dark:bg-card dark:focus-within:bg-white/[0.06]"
|
||||
: "max-w-[var(--composer-content-width,49.5rem)] rounded-panel bg-muted/80 focus-within:bg-muted dark:bg-card dark:focus-within:bg-white/[0.06]",
|
||||
compactWhenIdle && "thread-composer-collapsible transition-colors motion-reduce:transition-none",
|
||||
interactionDisabled && "opacity-60",
|
||||
sessionDragPreview && "ring-1 ring-primary/25",
|
||||
|
||||
@@ -1862,7 +1862,7 @@ export function ThreadShell({
|
||||
);
|
||||
|
||||
const composer = (
|
||||
<>
|
||||
<div className={composerVariant === "hero" ? "thread-composer-stack is-hero" : "thread-composer-stack"}>
|
||||
{modelFallback?.chatId === chatId && !modelFallback.dismissed ? (
|
||||
<ModelFallbackNotice
|
||||
model={modelFallback.model}
|
||||
@@ -1879,12 +1879,14 @@ export function ThreadShell({
|
||||
state={recoveryState}
|
||||
onContinue={continueRecovery}
|
||||
onDismiss={dismissRecovery}
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
/>
|
||||
) : null}
|
||||
{streamError && !hasInlineDeliveryError(messages, streamError) ? (
|
||||
<StreamErrorNotice
|
||||
error={streamError}
|
||||
onDismiss={dismissStreamError}
|
||||
onOpenSettings={onOpenModelSettings}
|
||||
/>
|
||||
) : null}
|
||||
{session ? (
|
||||
@@ -2001,7 +2003,7 @@ export function ThreadShell({
|
||||
onQuotedContextChange={setQuotedContext}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
|
||||
const emptyState = initialHistoryLoading ? (
|
||||
|
||||
Reference in new issue
Block a user