Files
pipelines/app/lib/features/chat/chat_pane_content.dart
T
alan 9695100faa Build chat panes through one content builder
Phase 2.2 of docs/plans/floating-windows.md: buildChatPaneContent wraps a
conversation in the scopes it needs and keys it by the runtime, so the
tiling and (next) a floating window build the same subtree. The tiling uses
it; behaviour is unchanged.
2026-11-10 21:05:41 +00:00

112 lines
4.1 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import '../../core/servers/server_context.dart';
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
import 'chat_runtime.dart';
import 'conversation/chat_thread_view.dart';
import 'conversation/composer_focus_request.dart';
/// Where an open chat is shown and what that place alone decides: its Back,
/// its pane menu, whether it takes pastes, and what follows `/new` and
/// `/close`. Everything else about the chat comes from its [ChatRuntime].
class ChatPanePlacement {
const ChatPanePlacement({
required this.onBack,
required this.onNewSession,
required this.onSessionClosed,
this.syncToken = 0,
this.useNativeBack = false,
this.showBackButton,
this.pasteTarget = false,
this.ownsPasteWhenFocused = false,
this.paneControls,
this.onNextChat,
});
final VoidCallback onBack;
/// `/new` moved the chat to a fresh session (previous id, the new row and
/// the line the new conversation opens on).
final void Function(String previousId, JsonMap session, String notice)
onNewSession;
/// `/close` was accepted.
final VoidCallback onSessionClosed;
/// Advances when the socket is replaced; the conversation re-subscribes.
final int syncToken;
final bool useNativeBack;
final bool? showBackButton;
/// Whether a paste with no field focused goes to this chat.
final bool pasteTarget;
/// Whether this chat takes a paste while it has the keyboard, though it is
/// not the active pane (a chat in a window).
final bool ownsPasteWhenFocused;
/// The pane menu's choices, built in the pane's own context.
final List<Widget> Function(BuildContext paneContext)? paneControls;
final VoidCallback? onNextChat;
}
/// One open chat with the scopes its conversation needs, the same in the
/// Chat destination's tiling and in a floating window. It is keyed by the
/// runtime ([ChatRuntime.viewKey]), so a chat that moves between the two in
/// one frame keeps its live view: transcript, scroll, draft and running turn.
Widget buildChatPaneContent({
required ChatRuntime runtime,
required String sessionId,
required ChatPanePlacement placement,
}) => KeyedSubtree(
key: runtime.viewKey(sessionId),
child: DetailPane(
destination: AppDestination.chat,
implyBack: false,
builder: (context) {
final row = runtime.rowFor(sessionId);
final start = runtime.startNotice;
return ChatComposerFocusScope(
sessionId: sessionId,
requests: runtime.composerFocus,
child: ServerContext.forServer(
context,
runtime.serverIdFor(sessionId),
ChatThreadView(
key: ValueKey<String>('chat-session-$sessionId'),
gateway: runtime.gatewayFor(sessionId),
sessionId: sessionId,
title: '${row?['title'] ?? ''}'.trim(),
session: row,
syncToken: placement.syncToken,
scrollPositions: runtime.scrollPositions,
transcripts: runtime.transcripts,
initialNotice: start != null && start.id == sessionId
? start.notice
: null,
onBack: placement.onBack,
onModelChanged: (applied) =>
runtime.modelChanged(sessionId, applied),
onModeChanged: (mode, name) =>
runtime.acceptMode(sessionId, mode, name),
onEffortChanged: (state) => runtime.acceptEffort(sessionId, state),
onNewSession: placement.onNewSession,
onSessionRenamed: (title) => runtime.acceptRename(sessionId, title),
onSessionClosed: placement.onSessionClosed,
onColorSelected: (color) =>
runtime.sessions.setColor(sessionId, color),
onNextChat: placement.onNextChat,
useNativeBack: placement.useNativeBack,
pasteTarget: placement.pasteTarget,
ownsPasteWhenFocused: placement.ownsPasteWhenFocused,
showBackButton: placement.showBackButton,
paneControls: placement.paneControls?.call(context) ?? const [],
),
),
);
},
),
);