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:
@@ -6,6 +6,7 @@ import 'dart:async';
|
||||
import '../features/runs/domain/run_tab_counts.dart';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -15,6 +16,7 @@ import '../core/transport/pipelines_client.dart';
|
||||
import '../shell/adaptive_shell.dart';
|
||||
import '../shell/destination.dart';
|
||||
import '../features/attention/notify/notification_controller.dart';
|
||||
import '../features/attention/notify/notification_models.dart';
|
||||
import '../features/attention/notify/chat_question_notices.dart';
|
||||
import '../features/attention/notify/agent_notices.dart';
|
||||
import '../features/attention/notify/page_signals.dart';
|
||||
@@ -456,6 +458,11 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
);
|
||||
};
|
||||
unawaited(_notifications.load());
|
||||
// Browsers only show the permission prompt from a user gesture: ask on
|
||||
// the operator's first click anywhere, once, while undecided, so agent
|
||||
// notifications can be real system notifications without a trip to
|
||||
// Settings.
|
||||
GestureBinding.instance.pointerRouter.addGlobalRoute(_askOnFirstPress);
|
||||
bindAttentionAckSync(_session.gateway, _ackSync);
|
||||
unawaited(_ackSync.load());
|
||||
unawaited(_attention.load());
|
||||
@@ -592,8 +599,17 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
}
|
||||
|
||||
void _askOnFirstPress(PointerEvent event) {
|
||||
if (event is! PointerDownEvent || !_notifications.loaded) return;
|
||||
GestureBinding.instance.pointerRouter.removeGlobalRoute(_askOnFirstPress);
|
||||
if (_notifications.permission == NotificationPermissionState.notRequested) {
|
||||
unawaited(_notifications.requestPermission());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
GestureBinding.instance.pointerRouter.removeGlobalRoute(_askOnFirstPress);
|
||||
_tabLocations.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_deliveryHandoff?.dispose();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user