Files
pipelines/app/lib/features/chat/ui/sessions/chat_sessions_body.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

169 lines
5.3 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../../../core/error_advice.dart';
import '../../../../ui/status/empty_state.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_harness_setup_state.dart';
import 'session_list_material.dart';
import 'session_pane_menu.dart';
import 'session_row_style.dart';
/// The chat list's state when the server has no chats yet.
const chatListEmptyKey = ValueKey<String>('chat-list-empty');
typedef ChatSessionSection = ({String title, List<JsonMap> sessions});
/// Which list sections are folded away, kept by the list's screen so the
/// keyboard shortcuts and Next chat count only rows on screen. Closed starts
/// folded. It notifies when a section folds or unfolds.
class ChatSectionFolds extends ChangeNotifier {
final Set<String> _folded = {'Closed'};
bool isOpen(String title) => !_folded.contains(title);
void set(String title, bool open) {
final changed = open ? _folded.remove(title) : _folded.add(title);
if (changed) notifyListeners();
}
}
/// Groups the visible sessions the way the server reports them.
class ChatSessionsBody extends StatelessWidget {
const ChatSessionsBody({
super.key,
required this.sessions,
required this.query,
required this.loading,
required this.error,
required this.onOpen,
this.onOpenBeside,
this.draggable = false,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
required this.onRename,
required this.onClose,
required this.onReopen,
required this.onStar,
this.onColor,
required this.onHide,
required this.onClearSearch,
required this.isUnseen,
required this.errorFor,
this.folds,
this.activeSessionId,
this.visibleSessionIds = const {},
this.onDismissError,
this.selectionOnly = false,
this.emptyMessageOverride,
this.onNewChat,
this.onRefresh,
});
/// Starts a chat; an empty list offers it as its next step.
final VoidCallback? onNewChat;
/// Reads the list again; the harness setup state offers it.
final VoidCallback? onRefresh;
/// Reuse list presentation for a picker without mutation menus or gestures.
final bool selectionOnly;
final String? emptyMessageOverride;
final ChatSectionFolds? folds;
final List<JsonMap> sessions;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final String query;
final bool loading;
final String? error;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final bool draggable;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
final SessionPaneMenu? paneMenu;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
final ValueChanged<JsonMap> onStar;
final ValueChanged<JsonMap>? onColor;
final ValueChanged<JsonMap> onHide;
final VoidCallback onClearSearch;
final bool Function(JsonMap) isUnseen;
final String? Function(String sessionId) errorFor;
final ValueChanged<String>? onDismissError;
@override
Widget build(BuildContext context) {
final visible = filterChatSessions(sessions, query);
final sections = chatSessionSections(visible);
final emptyMessage =
emptyMessageOverride ??
(sessions.isEmpty
? error == null
? 'No chats yet. Use New chat to start one.'
: null
: 'No chats match "${query.trim()}".');
if (loading && sessions.isEmpty) return const ChatLoadingIndicator();
// The list's own first-run states. A picker (selectionOnly or an
// override) keeps its one-line message.
final firstRun =
!selectionOnly &&
emptyMessageOverride == null &&
sessions.isEmpty &&
query.trim().isEmpty;
if (firstRun && needsHarnessSetup(error)) {
return ChatHarnessSetupState(onRefresh: onRefresh);
}
if (firstRun && error == null) {
final start = onNewChat;
return EmptyState(
key: chatListEmptyKey,
dense: true,
icon: Icons.forum_outlined,
title: 'No chats yet',
message:
'Talk with a coding agent on your server. Each chat works in a '
'folder you choose and keeps its history here.',
action: start == null
? null
: emptyStateAction(
'Start a chat',
start,
icon: Icons.add_comment_outlined,
),
);
}
final clearSearch = query.trim().isEmpty ? null : onClearSearch;
final duplicateTitles = duplicateChatTitles(visible);
return MaterialSessionList(
selectionOnly: selectionOnly,
sections: sections,
folds: folds,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
onOpenBeside: onOpenBeside,
draggable: draggable,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onStar: onStar,
onColor: onColor,
onHide: onHide,
onClearSearch: clearSearch,
isUnseen: isUnseen,
errorFor: errorFor,
onDismissError: onDismissError,
);
}
}