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>
This commit is contained in:
@@ -17,6 +17,7 @@ class _Gateway implements ApiGateway {
|
||||
final controller = StreamController<JsonMap>.broadcast();
|
||||
List<JsonMap> backlog = [];
|
||||
final calls = <String>[];
|
||||
final sent = <JsonMap>[];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => controller.stream;
|
||||
@@ -24,6 +25,7 @@ class _Gateway implements ApiGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(type);
|
||||
sent.add({'type': type, ...fields});
|
||||
return {
|
||||
'type': 'notifications_subscribed',
|
||||
'notifications': backlog,
|
||||
@@ -140,6 +142,50 @@ void main() {
|
||||
expect(opened, ['ses_1']);
|
||||
});
|
||||
|
||||
test(
|
||||
'a tap clears the notice on the server so other devices drop it',
|
||||
() async {
|
||||
await setUpWith();
|
||||
gateway.controller.add(_push(_notice('a')));
|
||||
await pump();
|
||||
bridge.taps.first!();
|
||||
await pump();
|
||||
expect(opened, ['ses_1']);
|
||||
expect(gateway.sent.last, {
|
||||
'type': 'clear_notifications',
|
||||
'ids': ['chat:ses_1:notify:a'],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test('a clear from the server (another device, or the chat opened) closes '
|
||||
'the system notification here', () async {
|
||||
await setUpWith();
|
||||
gateway.controller.add(_push(_notice('a')));
|
||||
await pump();
|
||||
expect(bridge.shown, hasLength(1));
|
||||
gateway.controller.add({
|
||||
'type': 'notifications_cleared',
|
||||
'ids': ['chat:ses_1:notify:a'],
|
||||
});
|
||||
await pump();
|
||||
expect(bridge.closed, ['chat:ses_1:notify:a']);
|
||||
});
|
||||
|
||||
test(
|
||||
'ids cleared while away close their notifications on resubscribe',
|
||||
() async {
|
||||
await setUpWith();
|
||||
gateway.controller.add({
|
||||
'type': 'notifications_subscribed',
|
||||
'notifications': <JsonMap>[],
|
||||
'ids': ['chat:ses_1:notify:old'],
|
||||
});
|
||||
await pump();
|
||||
expect(bridge.closed, ['chat:ses_1:notify:old']);
|
||||
},
|
||||
);
|
||||
|
||||
test('nothing shows when the chat is already in view', () async {
|
||||
await setUpWith();
|
||||
active = 'ses_1';
|
||||
|
||||
@@ -276,4 +276,7 @@ class _ThrowingBridge implements NotificationBridge {
|
||||
@override
|
||||
bool show(NotificationMessage message, {void Function()? onTap}) =>
|
||||
throw StateError('the browser refused to construct a notification');
|
||||
|
||||
@override
|
||||
void close(String tag) {}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ class FakeNotificationBridge implements NotificationBridge {
|
||||
int requests = 0;
|
||||
final List<NotificationMessage> shown = [];
|
||||
final List<void Function()?> taps = [];
|
||||
final List<String> closed = [];
|
||||
|
||||
@override
|
||||
NotificationEnvironment environment() => NotificationEnvironment(
|
||||
@@ -135,4 +136,7 @@ class FakeNotificationBridge implements NotificationBridge {
|
||||
taps.add(onTap);
|
||||
return accepts;
|
||||
}
|
||||
|
||||
@override
|
||||
void close(String tag) => closed.add(tag);
|
||||
}
|
||||
|
||||
@@ -188,16 +188,34 @@ void main() {
|
||||
expect(find.byKey(const Key('stub-html')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('notify rows say whether the phone was notified', (tester) async {
|
||||
testWidgets('notify rows say where the notification went', (tester) async {
|
||||
await pump(tester, {
|
||||
'id': 'n',
|
||||
'kind': 'notify',
|
||||
'title': 'Build done',
|
||||
'message': 'All green',
|
||||
'delivered': true,
|
||||
'channels': ['apps', 'phone'],
|
||||
});
|
||||
expect(find.text('Notified your phone: Build done'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Notified your apps and phone: Build done'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('All green'), findsOneWidget);
|
||||
for (final (channels, text) in [
|
||||
(['apps'], 'Notified your apps: Build done'),
|
||||
(['phone'], 'Notified your phone: Build done'),
|
||||
(null, 'Notified you: Build done'),
|
||||
]) {
|
||||
await pump(tester, {
|
||||
'id': 'n-$text',
|
||||
'kind': 'notify',
|
||||
'title': 'Build done',
|
||||
'delivered': true,
|
||||
'channels': ?channels,
|
||||
});
|
||||
expect(find.text(text), findsOneWidget);
|
||||
}
|
||||
await pump(tester, {
|
||||
'id': 'n2',
|
||||
'kind': 'notify',
|
||||
@@ -207,7 +225,7 @@ void main() {
|
||||
});
|
||||
expect(
|
||||
find.text(
|
||||
'Phone notification not sent: Build done — notifications are not set up',
|
||||
'Notification not sent: Build done — notifications are not set up',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user