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:
@@ -12,6 +12,7 @@ enum AppRouteKind {
|
||||
settings,
|
||||
templates,
|
||||
schedules,
|
||||
artifact,
|
||||
}
|
||||
|
||||
/// One page route: a destination plus the detail, pane and query it opens.
|
||||
@@ -47,6 +48,12 @@ class AppRoute {
|
||||
this.visit,
|
||||
this.decide = false,
|
||||
this.templateKey,
|
||||
this.artifactSequence,
|
||||
this.artifactPath,
|
||||
this.artifactPathEncoded,
|
||||
this.artifactUrl,
|
||||
this.artifactName,
|
||||
this.artifactMediaType,
|
||||
});
|
||||
|
||||
static const pipelines = AppRoute(AppRouteKind.pipelines);
|
||||
@@ -62,6 +69,26 @@ class AppRoute {
|
||||
/// The saved-schedule list, a Settings sub-page on `/schedules`.
|
||||
static const schedules = AppRoute(AppRouteKind.schedules);
|
||||
|
||||
static AppRoute artifact(
|
||||
int runId,
|
||||
int sequence,
|
||||
String path, {
|
||||
String? url,
|
||||
String? name,
|
||||
String? mediaType,
|
||||
}) => _validId(runId) == null || sequence < 0 || path.isEmpty
|
||||
? runs
|
||||
: AppRoute(
|
||||
AppRouteKind.artifact,
|
||||
runId: runId,
|
||||
artifactSequence: sequence,
|
||||
artifactPath: path,
|
||||
artifactPathEncoded: _encodeArtifactPath(path),
|
||||
artifactUrl: url,
|
||||
artifactName: name,
|
||||
artifactMediaType: mediaType,
|
||||
);
|
||||
|
||||
static const run = _RunRouteFactory();
|
||||
|
||||
/// One chat session, or the chat list when [id] is not a session id.
|
||||
@@ -128,6 +155,13 @@ class AppRoute {
|
||||
/// The template whose detail page is open, or null for the gallery.
|
||||
final String? templateKey;
|
||||
|
||||
final int? artifactSequence;
|
||||
final String? artifactPath;
|
||||
final String? artifactPathEncoded;
|
||||
final String? artifactUrl;
|
||||
final String? artifactName;
|
||||
final String? artifactMediaType;
|
||||
|
||||
/// The path the app writes into history for this route.
|
||||
String get path => _routePath(this);
|
||||
|
||||
@@ -157,7 +191,12 @@ class AppRoute {
|
||||
other.stageKey == stageKey &&
|
||||
other.visit == visit &&
|
||||
other.decide == decide &&
|
||||
other.templateKey == templateKey;
|
||||
other.templateKey == templateKey &&
|
||||
other.artifactSequence == artifactSequence &&
|
||||
other.artifactPath == artifactPath &&
|
||||
other.artifactUrl == artifactUrl &&
|
||||
other.artifactName == artifactName &&
|
||||
other.artifactMediaType == artifactMediaType;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
@@ -170,6 +209,11 @@ class AppRoute {
|
||||
visit,
|
||||
decide,
|
||||
templateKey,
|
||||
artifactSequence,
|
||||
artifactPath,
|
||||
artifactUrl,
|
||||
artifactName,
|
||||
artifactMediaType,
|
||||
);
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,6 +5,16 @@ part of 'app_route.dart';
|
||||
const _maxSafe = 9007199254740991;
|
||||
final _digits = RegExp(r'^[0-9]+$');
|
||||
|
||||
String _rawNativePath(Uri uri) {
|
||||
final text = uri.toString();
|
||||
final marker = '${uri.scheme}://${uri.host}';
|
||||
final start = text.indexOf(marker);
|
||||
if (start == -1) return uri.path;
|
||||
final suffix = text.substring(start + marker.length);
|
||||
final end = suffix.indexOf(RegExp(r'[?#]'));
|
||||
return end == -1 ? suffix : suffix.substring(0, end);
|
||||
}
|
||||
|
||||
String _routePath(AppRoute route) => switch (route.kind) {
|
||||
AppRouteKind.pipelines => _pipelinePath(route),
|
||||
AppRouteKind.runs => _runsPath(route),
|
||||
@@ -13,8 +23,15 @@ String _routePath(AppRoute route) => switch (route.kind) {
|
||||
AppRouteKind.settings => '/settings',
|
||||
AppRouteKind.templates => _templatesPath(route),
|
||||
AppRouteKind.schedules => '/schedules',
|
||||
AppRouteKind.artifact => _artifactPath(route),
|
||||
};
|
||||
|
||||
String _artifactPath(AppRoute route) =>
|
||||
'/artifact/${route.runId}/${route.artifactSequence}/${route.artifactPathEncoded ?? _encodeArtifactPath(route.artifactPath ?? '')}';
|
||||
|
||||
String _encodeArtifactPath(String path) =>
|
||||
path.split('/').map(Uri.encodeComponent).join('/');
|
||||
|
||||
String _pipelinePath(AppRoute route) {
|
||||
final id = _validId(route.pipelineId);
|
||||
if (id == null) return '/pipelines';
|
||||
@@ -69,7 +86,9 @@ AppRoute _parseRoute(String location) {
|
||||
if (raw.contains('://')) {
|
||||
final uri = Uri.tryParse(raw);
|
||||
if (uri == null) return AppRoute.pipelines;
|
||||
raw = uri.path;
|
||||
raw = uri.scheme == 'pipelines' && uri.host == 'artifact'
|
||||
? '/artifact${_rawNativePath(uri)}'
|
||||
: uri.path;
|
||||
query = uri.query;
|
||||
}
|
||||
final hash = raw.indexOf('#');
|
||||
@@ -93,10 +112,37 @@ AppRoute _parseRoute(String location) {
|
||||
'settings' => _settingsRoute(segments),
|
||||
'templates' => _templatesRoute(segments),
|
||||
'schedules' when segments.length == 1 => AppRoute.schedules,
|
||||
'artifact' => _artifactRoute(raw),
|
||||
_ => AppRoute.pipelines,
|
||||
};
|
||||
}
|
||||
|
||||
AppRoute _artifactRoute(String raw) {
|
||||
final rawSegments = raw.split('/');
|
||||
final first = rawSegments.isNotEmpty && rawSegments.first.isEmpty ? 1 : 0;
|
||||
if (rawSegments.length - first < 4) return AppRoute.pipelines;
|
||||
final encodedPath = rawSegments.sublist(first + 3).join('/');
|
||||
try {
|
||||
final run = _positiveId(Uri.decodeComponent(rawSegments[first + 1]));
|
||||
final sequence = _number(Uri.decodeComponent(rawSegments[first + 2]));
|
||||
final path = rawSegments
|
||||
.sublist(first + 3)
|
||||
.map(Uri.decodeComponent)
|
||||
.join('/');
|
||||
return run == null || sequence == null || path.isEmpty
|
||||
? AppRoute.pipelines
|
||||
: AppRoute(
|
||||
AppRouteKind.artifact,
|
||||
runId: run,
|
||||
artifactSequence: sequence,
|
||||
artifactPath: path,
|
||||
artifactPathEncoded: encodedPath,
|
||||
);
|
||||
} on ArgumentError {
|
||||
return AppRoute.pipelines;
|
||||
}
|
||||
}
|
||||
|
||||
List<String>? _decodeSegments(String path) {
|
||||
final parts = path.split('/');
|
||||
final first = parts.isNotEmpty && parts.first.isEmpty ? 1 : 0;
|
||||
|
||||
@@ -34,10 +34,22 @@ String routeLocation(Uri uri) {
|
||||
? '/runs${uri.path}'
|
||||
: native && uri.host == 'chat'
|
||||
? '/chat${uri.path}'
|
||||
: native && uri.host == 'artifact'
|
||||
? '/artifact${_rawNativePath(uri)}'
|
||||
: uri.path;
|
||||
return uri.hasQuery ? '$path?${uri.query}' : path;
|
||||
}
|
||||
|
||||
String _rawNativePath(Uri uri) {
|
||||
final text = uri.toString();
|
||||
final marker = '${uri.scheme}://${uri.host}';
|
||||
final start = text.indexOf(marker);
|
||||
if (start == -1) return uri.path;
|
||||
final suffix = text.substring(start + marker.length);
|
||||
final end = suffix.indexOf(RegExp(r'[?#]'));
|
||||
return end == -1 ? suffix : suffix.substring(0, end);
|
||||
}
|
||||
|
||||
/// Owns the app's current route and builds the shell for it.
|
||||
///
|
||||
/// Route changes made by the operator go through [goTo]; the Router reports
|
||||
@@ -49,6 +61,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
this.searchBuilder,
|
||||
this.templatesBuilder,
|
||||
this.schedulesBuilder,
|
||||
this.artifactBuilder,
|
||||
AppRoute initial = AppRoute.pipelines,
|
||||
}) : _route = initial,
|
||||
_searchReturn = initial.kind == AppRouteKind.search
|
||||
@@ -67,6 +80,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
/// restored when this page closes.
|
||||
final Widget Function(BuildContext context)? templatesBuilder;
|
||||
final Widget Function(BuildContext context)? schedulesBuilder;
|
||||
final Widget Function(BuildContext context, AppRoute route)? artifactBuilder;
|
||||
|
||||
/// The Search page above the shell. Search is transient chrome, not a fifth
|
||||
/// tab: the shell stays mounted underneath so closing restores its loaded
|
||||
@@ -78,6 +92,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
static const _searchPageKey = ValueKey<String>('app-search');
|
||||
static const _templatesPageKey = ValueKey<String>('app-templates');
|
||||
static const _schedulesPageKey = ValueKey<String>('app-schedules');
|
||||
static const _artifactPageKey = ValueKey<String>('app-artifact');
|
||||
|
||||
AppRoute _route;
|
||||
|
||||
@@ -140,6 +155,12 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
// so closing restores Settings exactly as it was left.
|
||||
if (templates) _page(_templatesPageKey, templatesBuilder!(context)),
|
||||
if (schedules) _page(_schedulesPageKey, schedulesBuilder!(context)),
|
||||
if (_route.kind == AppRouteKind.artifact && artifactBuilder != null)
|
||||
_page(
|
||||
_artifactPageKey,
|
||||
artifactBuilder!(context, _route),
|
||||
dialog: true,
|
||||
),
|
||||
// Search is a transient full-screen mode, so a full-screen dialog gives
|
||||
// the standard Close/Cancel action instead of a Back chevron.
|
||||
if (searching)
|
||||
@@ -149,6 +170,10 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
if (page.key == _searchPageKey) closeSearch();
|
||||
if (page.key == _templatesPageKey) closeTemplates();
|
||||
if (page.key == _schedulesPageKey) closeSchedules();
|
||||
if (page.key == _artifactPageKey &&
|
||||
_route.kind == AppRouteKind.artifact) {
|
||||
goTo(AppRoute.run(_route.runId!));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ import '../features/attention/runtime/attention_ack_sync.dart';
|
||||
import '../features/attention/runtime/attention_controller.dart';
|
||||
import '../features/attention/runtime/attention_store.dart';
|
||||
import '../features/runs/ui/run_search_selection.dart';
|
||||
import '../features/artifacts/domain/artifact_groups.dart';
|
||||
import '../features/artifacts/domain/artifact_record.dart';
|
||||
import '../features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import '../features/artifacts/domain/gallery_navigation.dart';
|
||||
import '../features/search/domain/search_target.dart';
|
||||
import '../features/settings/settings_screen.dart';
|
||||
import '../features/settings/settings_store.dart';
|
||||
@@ -345,6 +349,19 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
_notifications.onOpenRun = (id) {
|
||||
if (mounted) _delegate.goTo(AppRoute.run(id));
|
||||
};
|
||||
_notifications.onOpenArtifact = (artifact) {
|
||||
if (!mounted) return;
|
||||
_delegate.goTo(
|
||||
AppRoute.artifact(
|
||||
artifact.runId,
|
||||
artifact.sequence,
|
||||
artifact.path,
|
||||
url: artifact.url,
|
||||
name: artifact.name,
|
||||
mediaType: artifact.mediaType,
|
||||
),
|
||||
);
|
||||
};
|
||||
unawaited(_notifications.load());
|
||||
bindAttentionAckSync(_session.gateway, _ackSync);
|
||||
unawaited(_ackSync.load());
|
||||
@@ -360,6 +377,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
initial: initial,
|
||||
templatesBuilder: _buildTemplates,
|
||||
schedulesBuilder: _buildSchedules,
|
||||
artifactBuilder: _buildArtifact,
|
||||
builder: _buildShell,
|
||||
);
|
||||
_delegate.addListener(_routeChanged);
|
||||
@@ -753,7 +771,8 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
// Templates and Schedules are transient Settings sub-pages. Remember the
|
||||
// Settings route under them, so selecting Settings later opens /settings
|
||||
// rather than reopening the sub-page.
|
||||
final subPage = shown.kind == AppRouteKind.templates ||
|
||||
final subPage =
|
||||
shown.kind == AppRouteKind.templates ||
|
||||
shown.kind == AppRouteKind.schedules;
|
||||
_tabLocations.record(subPage ? _delegate.shellRoute : shown);
|
||||
_rememberBodyRoute(_delegate.shellRoute);
|
||||
@@ -841,6 +860,37 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildArtifact(BuildContext context, AppRoute route) {
|
||||
final path = route.artifactPath!;
|
||||
final url = route.artifactUrl?.isNotEmpty == true
|
||||
? route.artifactUrl!
|
||||
: '/artifacts/${route.runId}/${route.artifactSequence}/public/${route.artifactPathEncoded ?? path.split('/').map(Uri.encodeComponent).join('/')}';
|
||||
final name = route.artifactName?.isNotEmpty == true
|
||||
? route.artifactName!
|
||||
: path.split('/').last;
|
||||
final record = ArtifactRecord(
|
||||
name: name,
|
||||
url: url,
|
||||
contentType: route.artifactMediaType?.isNotEmpty == true
|
||||
? route.artifactMediaType!
|
||||
: (path.toLowerCase().endsWith('.md')
|
||||
? 'text/markdown'
|
||||
: 'text/plain'),
|
||||
sizeBytes: 0,
|
||||
raw: <String, dynamic>{'name': name, 'url': url},
|
||||
);
|
||||
final group = ArtifactGroup(
|
||||
stageKey: 'notification',
|
||||
visit: route.artifactSequence!,
|
||||
artifacts: <ArtifactRecord>[record],
|
||||
);
|
||||
return ArtifactViewerPage(
|
||||
groups: <ArtifactGroup>[group],
|
||||
selectedIdentity: artifactVisitIdentityOf(group, record),
|
||||
configuredEndpoint: configuredGatewayEndpoint(_session.gateway),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _shellFor(AppRoute route, _RunIndicators counts) {
|
||||
// Each tab is built from the route it last showed, so switching tabs keeps
|
||||
// an open run, pipeline or chat instead of resetting it.
|
||||
@@ -994,6 +1044,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
// Templates and Schedules are Settings sub-pages, not a fifth tab.
|
||||
AppRouteKind.templates => AppDestination.settings,
|
||||
AppRouteKind.schedules => AppDestination.settings,
|
||||
AppRouteKind.artifact => AppDestination.runs,
|
||||
};
|
||||
|
||||
AppRoute _routeOf(AppDestination destination) => switch (destination) {
|
||||
|
||||
@@ -11,6 +11,7 @@ AppDestination tabForRoute(AppRoute route) => switch (route.kind) {
|
||||
AppRouteKind.runs => AppDestination.runs,
|
||||
AppRouteKind.chat => AppDestination.chat,
|
||||
AppRouteKind.search => AppDestination.search,
|
||||
AppRouteKind.artifact => AppDestination.runs,
|
||||
};
|
||||
|
||||
/// Remembers navigation without retaining modal actions such as run decisions.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user