Files
pipelines/app/lib/application/runs_destination.dart
T
alan c316bc9bc8 Chat and runs: tell a slow client to resync instead of dropping it silently; join queued deltas
A chat subscriber whose queue fills is detached and its writer ends the
stream with a resync frame (the app re-attaches and re-reads history); a run
subscriber gets a final runs_resync and the app subscribes again and
re-reads the Runs list and open detail. Consecutive text/reasoning deltas of
one part are joined in a chat subscriber's queue; joined numbered frames carry
seq_from and delta_lens so the app trims exactly the prefix a history page
already holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:39:38 +00:00

121 lines
4.1 KiB
Dart

import 'package:flutter/material.dart';
import '../features/attention/notify/notification_controller.dart';
import '../features/attention/runtime/attention_controller.dart';
import '../features/pipelines/pending_run_store.dart';
import '../features/runs/screen.dart';
import '../features/runs/ui/run_pipeline_link.dart';
import '../ui/adaptive/top_bar_notices.dart';
import 'app_session.dart';
import 'connection_status.dart';
import 'pending_run_scope.dart';
import 'server_endpoint.dart';
import '../core/api_gateway.dart';
/// The Runs destination: the loaded screen plus an honest connection status.
///
/// Before the first successful connection there is nothing to show, so the
/// destination is a full connection screen. After that the screen stays
/// mounted through drops and reconnects: a status banner reports reconnecting
/// or not live, and the screen reloads in place without losing the open run.
class RunsDestination extends StatelessWidget {
const RunsDestination({
super.key,
required this.session,
required this.server,
this.initialRunId,
this.initialPipelineId,
this.initialStageKey,
this.initialVisit,
this.initialDecide = false,
this.onRunSelected,
this.onBack,
this.onPipelineFilterChanged,
this.onOpenPipeline,
this.listRefreshToken = 0,
this.notifications,
this.attention,
this.onOpenInChat,
this.onSendToChat,
});
final AppSession session;
final ServerEndpoint server;
final int? initialRunId;
final int? initialPipelineId;
/// The stage key and optional visit a `/runs/:id/stage/:key[?visit=N]` route
/// names. They reach the detail only through [RunsScreen]; the destination
/// does not read the route itself.
final String? initialStageKey;
final int? initialVisit;
/// The route's `?action=decide`. Forwarded as-is; the loaded screen decides
/// from the run's own detail whether a prompt exists.
final bool initialDecide;
final ValueChanged<int>? onRunSelected;
final ValueChanged<int?>? onBack;
final ValueChanged<int?>? onPipelineFilterChanged;
final OpenPipeline? onOpenPipeline;
/// Advances when a launch was accepted elsewhere. The mounted Runs screen
/// re-reads its list once; no row is inserted locally.
final int listRefreshToken;
/// The app-level notification capability shared with Settings.
final NotificationController? notifications;
/// The app-level attention controller the shell's Runs tab badge reads.
final AttentionController? attention;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
final Future<void> Function(BuildContext, JsonMap, String)? onSendToChat;
@override
Widget build(BuildContext context) => AnimatedBuilder(
animation: session,
builder: (context, _) {
if ((server.requiresConfiguration || server.error != null) &&
session.endpoint == null) {
return ConnectionGate(session: session, server: server);
}
if (!session.everConnected) {
if (session.connected) return _runsScreen();
return ConnectionGate(session: session, server: server);
}
// The banner stays below the top bar; without it the runs reach the top
// edge and scroll behind the bar.
return TopBarNotices(
notices: [
if (!session.connected ||
session.subscription == RunSubscriptionState.refused)
ConnectionBanner(session: session),
],
child: _runsScreen(),
);
},
);
Widget _runsScreen() => RunsScreen(
gateway: session.gateway,
initialRunId: initialRunId,
initialPipelineId: initialPipelineId,
initialStageKey: initialStageKey,
initialVisit: initialVisit,
initialDecide: initialDecide,
syncToken: session.runsEpoch,
listRefreshToken: listRefreshToken,
notifications: notifications,
attention: attention,
pendingRunStore: SharedPreferencesPendingRunStore(
pendingRunScope(session.gateway, server),
),
onRunSelected: onRunSelected,
onBack: onBack,
onPipelineFilterChanged: onPipelineFilterChanged,
onOpenPipeline: onOpenPipeline,
onOpenInChat: onOpenInChat,
onSendToChat: onSendToChat,
);
}