Open the run's artifact from notifications

Phone and browser notifications that carry an artifact open it full
screen in the artifact viewer, with an Open run action and the preview as
expanded text; pipelines://artifact deep links route to the viewer.
This commit is contained in:
2026-11-12 18:56:26 +00:00
parent d42d7a3534
commit 767643d991
17 changed files with 487 additions and 35 deletions
@@ -65,7 +65,8 @@ AttentionKind? attentionKindOf(dynamic status) {
/// onto a waiting run must not hide a genuine human decision.
AttentionKind? attentionKindForRun(JsonMap run) {
final kind = attentionKindOf(run['status']);
if (kind == AttentionKind.failed && _word(run['failure_kind']) == 'expected') {
if (kind == AttentionKind.failed &&
_word(run['failure_kind']) == 'expected') {
return null;
}
if (kind != AttentionKind.decision) return kind;
@@ -117,6 +118,15 @@ class AttentionEntry {
String get detail => attentionDetail(kind, run);
String get key => attentionKey(runId, kind);
/// Notification metadata attached by newer servers, when present on the
/// run-event summary. Kept optional so older frames retain today's behavior.
dynamic get notificationArtifact => run['artifact'];
String? get notificationPreview {
final value = run['preview'];
return value is String && value.isNotEmpty ? value : null;
}
/// The trimmed title else the pipeline label.
String get label {
final title = '${run['title'] ?? ''}'.trim();
@@ -82,7 +82,9 @@ class WebNotificationBridge implements NotificationBridge {
_NotificationOptions(body: message.body.toJS, tag: message.tag.toJS),
);
final open = onTap;
if (open != null) notification.onclick = (() => open()).toJS;
if (open != null) {
notification.onclick = (() => open()).toJS;
}
return true;
} catch (_) {
// Some browsers can throw even with permission granted; the in-app Needs
@@ -49,6 +49,7 @@ class NotificationController extends ChangeNotifier {
/// The tap seam: the manager sets this to open a run. Nothing here navigates.
void Function(int runId)? onOpenRun;
void Function(NotificationArtifact artifact)? onOpenArtifact;
NotificationLedger _ledger = const NotificationLedger();
NotificationPermissionState _permission =
@@ -208,17 +209,33 @@ class NotificationController extends ChangeNotifier {
if (dismissed.contains(identity)) continue;
if (!canNotify) continue;
final open = onOpenRun;
final rawArtifact = transition.entry.notificationArtifact;
final parsedArtifact = NotificationArtifact.fromJson(rawArtifact);
final artifact = parsedArtifact.isValid ? parsedArtifact : null;
final message = NotificationMessage(
runId: transition.runId,
title: notificationAlertTitle(transition.kind),
body: notificationAlertBody(transition.entry),
tag: identity,
artifact: artifact,
preview: transition.entry.notificationPreview,
runClick: artifact == null
? null
: 'pipelines://run/${transition.runId}',
);
var shown = false;
try {
shown = bridge.show(
message,
onTap: open == null ? null : () => open(transition.runId),
onTap: open == null && onOpenArtifact == null
? null
: () {
if (artifact != null && onOpenArtifact != null) {
onOpenArtifact!(artifact);
} else {
open?.call(transition.runId);
}
},
);
} catch (_) {
shown = false;
@@ -202,6 +202,9 @@ class NotificationMessage {
required this.title,
required this.body,
required this.tag,
this.artifact,
this.preview,
this.runClick,
});
final int? runId;
@@ -209,4 +212,42 @@ class NotificationMessage {
final String title;
final String body;
final String tag;
final NotificationArtifact? artifact;
final String? preview;
final String? runClick;
}
/// The server-provided artifact attached to a notification.
class NotificationArtifact {
const NotificationArtifact({
required this.runId,
required this.sequence,
required this.path,
required this.name,
required this.url,
required this.mediaType,
});
final int runId;
final int sequence;
final String path;
final String name;
final String url;
final String mediaType;
factory NotificationArtifact.fromJson(dynamic value) {
final map = value is Map ? value : const <String, dynamic>{};
String text(String key) => '${map[key] ?? ''}';
int number(String key) => int.tryParse(text(key)) ?? 0;
return NotificationArtifact(
runId: number('run_id'),
sequence: number('sequence'),
path: text('path'),
name: text('name'),
url: text('url'),
mediaType: text('media_type'),
);
}
bool get isValid => runId > 0 && sequence >= 0 && path.isNotEmpty;
}