Files
pipelines/app/lib/features/attention/notify/notification_bridge.dart
T
alan b91ef04ab0 Notifications: agent notify reaches every device and clears everywhere
- Server: chat ntfy messages carry a sequence id derived from their app id;
  clearing a chat app notification also clears it in ntfy (PUT
  /<topic>/<seq>/clear, verified on ntfy v2.38.1).
- Server: a turn that sent an agent notify does not also send chat_reply.
- notify tool and MCP instructions: Pipelines already notifies at reply end
  and for questions/approvals; notify is for mid-turn or background news.
- Shown notify items carry channels (apps/phone); the transcript row says
  where it went.
- App: NotificationBridge.close(tag); web closes tracked Notifications and
  tells other tabs over a BroadcastChannel; native bridge cancels by tag and
  now supports macOS. AgentNotices closes on notifications_cleared and on
  resubscribe cleared ids, and a tap sends clear_notifications.
- Docs: skill, chat reference, ntfy/notifications docs, app note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:49:31 +00:00

37 lines
1.7 KiB
Dart

import 'notification_bridge_stub.dart'
if (dart.library.js_interop) 'notification_bridge_web.dart'
if (dart.library.io) 'notification_bridge_io.dart'
as impl;
import 'notification_models.dart';
/// Where the notification capability actually posts.
///
/// The controller depends on this, not on any platform, so the dedupe, the
/// permission rules and the content are all testable without a browser. A bridge
/// answers the platform's real facts and never guesses: [environment] returns
/// what the platform says (including "unsupported"), [requestPermission] is only
/// called from an explicit gesture, and [show] reports whether the platform
/// accepted the notification.
abstract interface class NotificationBridge {
/// The platform's own facts: support, secure context and permission word.
NotificationEnvironment environment();
/// Asks the platform, from an explicit operator gesture, and returns its own
/// answer word. Never a guess, and never called by the controller on its own.
Future<String> requestPermission();
/// Shows one notification, attaching [onTap] as its tap intent when given.
/// Returns whether the platform accepted it. A notification with the same
/// [NotificationMessage.tag] replaces the earlier one.
bool show(NotificationMessage message, {void Function()? onTap});
/// Removes the notification this device shows for [tag], if any: it was
/// read or cleared on this or another device. Unknown tags are ignored.
void close(String tag);
}
/// The bridge for the current platform: the browser `Notification` on the web,
/// an honest "unsupported" elsewhere.
NotificationBridge createNotificationBridge() =>
impl.createNotificationBridge();