Agent notifications are system notifications, never in-app toasts

An agent's notify call now always posts an OS notification when permitted,
whatever app is in front (only skipped while that chat is open in the
focused page); no toast or chime. Without permission the tab title counts
it. The browser's permission prompt is shown on the operator's first click.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 16:32:29 +00:00
parent e05b2f07dc
commit 355a5767fb
4 changed files with 71 additions and 73 deletions
@@ -115,14 +115,11 @@ class AgentNoticeDelivery {
/// Decides how [notice] is delivered.
///
/// A focused page shows a toast, or nothing when the notice's chat is already
/// in view. A page the operator is not looking at gets a system notification
/// when [canNotify] (permission granted) and a count in the tab title; a low
/// priority notice only raises a system notification when the page is hidden,
/// and otherwise waits as a toast. Without system notifications (denied, not
/// asked, or an insecure http page) the toast, the title count and, for
/// default and high priority, a short chime carry it. A [replay] (missed while
/// disconnected) never chimes.
/// An agent's notification is a system (OS) notification whenever the
/// browser or OS allows one, whatever app is in front; the only exception is
/// the operator already looking at that chat in a focused page. There is no
/// in-app toast or sound. Without permission (not asked yet, denied, or an
/// insecure http page) only the tab title counts it until the page is focused.
AgentNoticeDelivery agentNoticeDelivery({
required AgentNotice notice,
required PagePresence presence,
@@ -130,14 +127,8 @@ AgentNoticeDelivery agentNoticeDelivery({
required bool canNotify,
bool replay = false,
}) {
if (presence == PagePresence.focused) {
return AgentNoticeDelivery(toast: !chatInView);
}
final system = canNotify && (!notice.low || presence == PagePresence.hidden);
return AgentNoticeDelivery(
system: system,
toast: !system,
badge: true,
chime: !system && !notice.low && !replay,
);
final looking = presence == PagePresence.focused && chatInView;
if (looking) return const AgentNoticeDelivery();
if (canNotify) return const AgentNoticeDelivery(system: true);
return AgentNoticeDelivery(badge: presence != PagePresence.focused);
}
@@ -162,14 +162,15 @@ class AgentNotices {
);
final headline = notice.headline(chat);
void open() => openChat(notice.sessionId);
var toast = delivery.toast;
if (delivery.system && !_showSystem(notice, headline, open)) toast = true;
if (toast) {
var badge = delivery.badge;
// A system notification the OS refused is counted in the tab title.
if (delivery.system && !_showSystem(notice, headline, open)) badge = true;
if (delivery.toast) {
showToast(
AgentToast(headline: headline, message: notice.message, open: open),
);
}
if (delivery.badge && page.presence != PagePresence.focused) {
if (badge && page.presence != PagePresence.focused) {
_badge++;
page.setBadge(_badge);
}