fix(webui): make browser notification failures actionable

This commit is contained in:
Xubin Ren authored and chengyongru committed 2026-10-20 13:45:04 +08:00
1 parent 909b277e7a
commit 7b2af031c0
30 files changed
+919 -96

No files matched your search

-30
View File
@@ -1,10 +1,8 @@
import { acceptsCompactionPhase } from "../../../packages/client-events/notifications";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useThreadVisibility } from "@/hooks/useThreadVisibility";
import { useClient } from "@/providers/ClientProvider";
import { resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
import { hasPendingAgentActivity } from "@/lib/activity-timeline";
import type { StreamError } from "@/lib/nanobot-client";
import {
@@ -22,7 +20,6 @@ import type {
UIMessageTurnFields,
} from "@/lib/thread-event-projection";
import { formatQuotedUserMessage } from "@/lib/user-message-quote";
import { readLocalPreferences } from "@/lib/local-preferences";
import { playTurnCompleteSound } from "@/lib/notification-sound";
import type {
InboundEvent,
@@ -176,7 +173,6 @@ export function useNanobotStream(
const threadVisible = useThreadVisibility();
const threadVisibleRef = useRef(threadVisible);
threadVisibleRef.current = threadVisible;
const { t } = useTranslation();
const initialRunStartedAt = chatId ? client.getRunStartedAt(chatId) : null;
const [messages, setRenderedMessages] = useState<UIMessage[]>(initialMessages);
const messagesRef = useRef(messages);
@@ -216,16 +212,6 @@ export function useNanobotStream(
const dismissStreamError = useCallback(() => setStreamError(null), []);
const notifyInBackground = useCallback((body: string) => {
if (
typeof Notification === "undefined"
|| Notification.permission !== "granted"
|| document.visibilityState === "visible"
|| !readLocalPreferences().browserNotifications
) return;
new Notification("nanobot", { body });
}, []);
const clearPendingStreamWork = useCallback(() => {
if (streamFrameRef.current !== null) {
window.cancelAnimationFrame(streamFrameRef.current);
@@ -816,13 +802,6 @@ export function useNanobotStream(
: null;
if (modelFailure) setStreamError(modelFailure);
applyProjectionEvent(ev);
notifyInBackground(
modelFailure
? resolveModelRequestFailureCopy(modelFailure, t).body
: ev.outcome === "failed"
? ev.failure_message || "This turn failed and has ended."
: t("recovery.completed", { defaultValue: "Task completed" }),
);
playTurnCompleteSound();
onTurnEnd?.();
return;
@@ -859,13 +838,6 @@ export function useNanobotStream(
clearPendingStreamWork();
closeActiveAssistantStream();
clearActivitySegment();
if (ev.status !== "recovered") {
notifyInBackground(
ev.status === "failed"
? t("recovery.failed", { defaultValue: "Task recovery failed" })
: t("recovery.interrupted", { defaultValue: "Task interrupted" }),
);
}
}
return;
}
@@ -927,12 +899,10 @@ export function useNanobotStream(
clearPendingStreamWork,
flushPendingStreamEvents,
isSideChannelEvent,
notifyInBackground,
onTurnEnd,
onStreamDetach,
schedulePendingStreamFlush,
setMessages,
t,
]);
const send = useCallback(