Files
pipelines/app/lib/application/templates_destination.dart
T
alan e72bee3faa First run: empty states with a next step, harness setup instead of errors
- One shared EmptyState (icon on a tonal disc, title, one line, primary
  action) that follows the design tokens; used by Runs (Start your first
  run), Pipelines (Browse templates), Schedules and the chat list (Start a
  chat).
- Chat on a server without an agent harness showed "Bad state: No saved
  machine is connected.": the federated list now keeps the server's own
  refusal, treats an omitted empty list as no chats, and the list shows a
  "Set up an agent" state with the harness setup command and Refresh. New
  chat shows the same step instead of a form that can only be refused.
- A run that fails because no harness CLI exists names the setup command
  beside the raw reason; error advice gains a noHarness kind.
- Templates opened before the app connected stayed on "Not connected";
  it now reads again when the connection arrives. The Pipelines empty state
  links to Templates, which had no entry point in the UI.
- The first-launch walkthrough waits briefly for the connection, so a
  connected web app is no longer told to connect; the empty-server check
  treats omitted lists and no chat harness as empty.

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

141 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
import '../core/api_gateway.dart';
import '../features/templates/screen.dart';
import '../features/templates/ui/template_detail.dart'
show templateDetailBackKey;
import '../shell/destination.dart';
import '../shell/shell_bar.dart';
import '../ui/adaptive/floating_bar_layout.dart';
import '../ui/adaptive/segmented_bar.dart';
import '../ui/adaptive/top_bar_notices.dart';
import 'app_session.dart';
import 'connection_status.dart';
import 'server_endpoint.dart';
/// The Back control of the app-level Templates page.
const templatesPageBackKey = ValueKey<String>('templates-page-back');
/// The Templates destination: the landed gallery over the app's shared gateway.
///
/// The gallery is rendered in embedded mode and publishes its controls to
/// this page's one segmented bar (through a [ShellBarScope] the page owns):
/// the round Back closes the page from the gallery and returns to the gallery
/// from an open template, and Refresh sits in the actions pill. The same
/// honest connection states as the other destinations. No socket is opened
/// here: [session] owns the only connection, and a template read, validate or
/// create request travels over it.
///
/// [onCreated] forwards the server-confirmed detail once, so the caller can
/// invalidate the Pipelines list. This screen never inserts a row itself.
class TemplatesDestination extends StatefulWidget {
const TemplatesDestination({
super.key,
required this.session,
required this.server,
required this.onBack,
this.onCreated,
this.initialKey,
});
final AppSession session;
final ServerEndpoint server;
/// Closes this page and restores the Settings destination underneath.
final VoidCallback onBack;
final ValueChanged<JsonMap>? onCreated;
/// The template detail the route names, or null for the gallery.
final String? initialKey;
@override
State<TemplatesDestination> createState() => _TemplatesDestinationState();
}
class _TemplatesDestinationState extends State<TemplatesDestination> {
final ShellBarRegistry _bar = ShellBarRegistry();
@override
void dispose() {
_bar.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final body = ShellBarScope(
registry: _bar,
destination: AppDestination.settings,
child: AnimatedBuilder(
animation: widget.session,
builder: (context, _) => _body(),
),
);
final bar = ListenableBuilder(
listenable: _bar,
builder: (context, _) => _segmentedBar(),
);
// The page reaches its top edge: the gallery and an open template scroll
// behind the bar and pad their own content by its height.
final page = SafeArea(top: false, bottom: false, child: body);
return Scaffold(
extendBodyBehindAppBar: true,
appBar: _BarSlot(child: bar),
body: page,
);
}
SegmentedBar _segmentedBar() {
final spec = _bar.specFor(AppDestination.settings);
final onDetailBack = spec?.onBack;
return SegmentedBar(
leading: onDetailBack != null
? SegmentedBackButton(
key: templateDetailBackKey,
onPressed: onDetailBack,
)
: SegmentedBackButton(
key: templatesPageBackKey,
onPressed: widget.onBack,
),
title: spec?.title ?? 'Templates',
subtitle: spec?.subtitle,
actions: spec?.actions ?? const [],
);
}
Widget _body() {
final session = widget.session;
if (!session.everConnected) {
return BelowTopBar(
child: ConnectionGate(session: session, server: widget.server),
);
}
// A connection banner stays below the bar; the gallery keeps its place.
return TopBarNotices(
notices: [if (!session.connected) ConnectionBanner(session: session)],
child: TemplatesScreen(
gateway: session.gateway,
embedded: true,
onCreated: widget.onCreated,
initialKey: widget.initialKey,
reloadToken: session.connectionEpoch,
),
);
}
}
/// Gives the scaffold a [SegmentedBar]'s size and obstruction while the bar
/// itself is rebuilt from the published controls.
class _BarSlot extends StatelessWidget implements PreferredSizeWidget {
const _BarSlot({required this.child});
final Widget child;
@override
Size get preferredSize => const SegmentedBar(title: '').preferredSize;
@override
Widget build(BuildContext context) => child;
}