Merge main into macos-self-update

This commit is contained in:
2026-11-13 14:34:21 +00:00
56 changed files with 1972 additions and 130 deletions
@@ -91,6 +91,7 @@ Widget buildChatPaneContent({
sessionId: sessionId,
title: '${row?['title'] ?? ''}'.trim(),
session: row,
initialDraft: runtime.pendingDrafts.remove(sessionId),
syncToken: placement.syncToken,
scrollPositions: runtime.scrollPositions,
transcripts: runtime.transcripts,
+10
View File
@@ -96,6 +96,16 @@ class ChatRuntime extends ChangeNotifier {
/// link) resolves the same row without a second list request.
final Map<String, JsonMap> opened = {};
/// Drafts seeded by an external action such as Open in chat. They are
/// consumed by the first composer for that session.
final Map<String, String> pendingDrafts = {};
/// Chats an external action (Open in chat) opened for the operator to work
/// in: the chat screen shows each beside the active chat rather than in
/// its place, makes it active and puts the keyboard in its composer once
/// it is on screen.
final Set<String> openedForWork = {};
/// Each row as the list last reported it (without its live `running`), so
/// [adoptRows] adopts only what a re-read changed.
final Map<String, JsonMap> _listed = {};
@@ -2,6 +2,8 @@ part of 'screen.dart';
/// Pane layout, focus and route publication for one Chat destination visit.
mixin _ChatScreenWorkspace on State<ChatScreen> {
final _sessionsKey = GlobalKey<ChatSessionsScreenState>();
Map<String, JsonMap> get _openedSessions;
ChatComposerFocusRequests get _composerFocus;
ChatPaneCommands get _paneCommands;
@@ -46,6 +48,10 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
activeSessionId: selected,
visibleSessionIds: _visibleSidebarSessions,
onOpen: _openSidebarSession,
onNewChat: () {
final state = _sessionsKey.currentState;
if (state != null) unawaited(state.newChat());
},
onExpand: () => _setSidebarMode(ChatSidebarMode.expanded),
),
],
@@ -80,6 +86,25 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
ChatSectionFolds get _foldsForSidebar;
void _openSidebarSession(JsonMap session);
void _dropSession(
ChatWorkspacePane target,
Object data,
ChatWorkspaceDropZone zone,
) {
if (data is! JsonMap) return;
final sessionId = '${data['id'] ?? ''}';
if (sessionId.isEmpty) return;
final windows = widget.windows;
final floating = windows?.windows
.where((window) => window.contentId == sessionId)
.firstOrNull;
if (floating != null) windows!.manager.close(floating.id);
_openedSessions[sessionId] = data;
_workspaceVisible = true;
_workspace.dropSession(sessionId, target.id, zone);
_composerFocus.request(sessionId);
}
final ChatWorkspaceController _workspace = ChatWorkspaceController();
ChatOpenWorkspaceController? _openWorkspace;
bool _applyingServerWorkspace = false;
@@ -278,14 +303,12 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
String? _publishedWorkspaceSession;
String _workspaceSignature = '';
/// Ctrl+Tab cycles the floating chat windows while any is shown, from the
/// tiling as well (see [ChatWindows]). With none shown it cycles the
/// retained panes, even when the sidebar or toolbar owns focus, and over a
/// single pane it does nothing: it never brings up a chat that is not
/// visible in the tiling. Command+Tab stays with the operating system's
/// application switcher. While the app's terminal is shown, Ctrl+Tab moves
/// between its tabs instead. A floating window that is not a chat, or any
/// other window holding the keyboard, keeps the key.
/// Ctrl+Tab cycles a single tiled pane through the open chats in sidebar
/// order. The pane is replaced in place so its retained view keeps the
/// transcript and draft. With multiple panes it cycles those panes. A
/// focused floating chat window handles the key itself (see [ChatWindows]).
/// Command+Tab stays with the operating system's application switcher, and
/// the terminal keeps Ctrl+Tab for its own tabs.
bool _cycleChatKey(KeyEvent event) {
final keyboard = HardwareKeyboard.instance;
if (event is! KeyDownEvent ||
@@ -298,8 +321,48 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
!_chatOwnsKeyboard()) {
return false;
}
if (widget.windows?.raiseTopFromTiling() ?? false) return true;
if (!_workspaceVisible || _workspace.paneCount < 2) return false;
if (!_workspaceVisible || _workspace.paneCount == 0) return false;
if (_workspace.paneCount == 1) {
final pane = _workspace.activePane;
if (pane == null) return false;
final floating = widget.windows?.floatingSessionIds.toSet() ?? const {};
final sessions = chatSessionsShown(
_sessionsForSidebar.sessions
.where(
(row) =>
row['closed_at'] == null &&
row['closed'] != true &&
!floating.contains('${row['id'] ?? ''}'),
)
.toList(),
query: '',
// Cycling is independent of a collapsed section: the sidebar's
// ordering is still used, but every open-chat row remains reachable.
isOpen: (_) => true,
);
final active = sessions.indexWhere(
(row) => '${row['id'] ?? ''}' == pane.sessionId,
);
if (sessions.length < 2 || active < 0) return false;
final direction = keyboard.isShiftPressed ? -1 : 1;
final target = sessions[(active + direction) % sessions.length];
final targetId = '${target['id'] ?? ''}';
if (targetId.isEmpty) return false;
_workspace.replacePaneSession(pane.id, targetId);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted ||
!_workspaceVisible ||
_workspace.activePane?.sessionId != targetId) {
return;
}
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
if (destination == null || destination == AppDestination.chat) {
_composerFocus.request(targetId);
}
});
WidgetsBinding.instance.ensureVisualUpdate();
return true;
}
final panes = _workspace.panes;
final active = panes.indexWhere(
(pane) => pane.id == _workspace.activePaneId,
@@ -467,6 +530,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
paneTitle: (pane) =>
'${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
onDrop: _dropSession,
paneBuilder: (context, pane, active) {
final scope = ChatWorkspacePaneScope.maybeOf(context);
final topShared = scope?.topEdgeShared ?? false;
@@ -114,6 +114,7 @@ class ChatThreadView extends StatefulWidget {
this.scrollPositions,
this.transcripts,
this.initialNotice,
this.initialDraft,
this.onNewSession,
this.onSessionRenamed,
this.onSessionClosed,
@@ -157,6 +158,9 @@ class ChatThreadView extends StatefulWidget {
/// the `/new` notice for a session it just created and opened.
final String? initialNotice;
/// A draft supplied by an external deep action; it is never sent.
final String? initialDraft;
/// `/new` moved this chat to a fresh native session; the destination swaps
/// the row in place, opens the new id with the notice and refreshes the
/// list. Without a destination the notice shows here instead.
@@ -528,6 +532,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
onAccepted: (send, queued) =>
_controller.promptAccepted(send.operationId, queued: queued),
);
if (widget.initialDraft != null) {
unawaited(composer.setDraft(widget.initialDraft!));
}
// A message a previous visit sent but never saw accepted comes back as
// "Not sent" unless the history read shows the server has it.
unawaited(
+31 -1
View File
@@ -354,6 +354,34 @@ class _ChatScreenState extends State<ChatScreen>
widget.onBack?.call();
}
/// Opens the chat the route names. A chat opened for work from elsewhere
/// (Open in chat) goes beside the active chat on a wide layout instead of
/// replacing it, and takes the keyboard once its composer is built.
void _openRouted(String id) {
if (!_runtime.openedForWork.remove(id)) {
_workspace.open(id);
return;
}
final beside =
!_page.open &&
showsListBesideDetail(context) &&
_workspace.paneCount > 0 &&
!_workspace.holdsSession(id);
if (beside) {
_workspace.splitActive(id, ChatSplitAxis.horizontal);
} else {
_workspace.open(id);
}
_composerFocus.request(id);
// The composer may be built a frame later (a new pane, a switched tab);
// ask again then so the request is never lost to the switch.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && _workspace.activePane?.sessionId == id) {
_composerFocus.request(id);
}
});
}
/// On a phone the open chat is a real page above the main screen.
final DetailPageHost _page = DetailPageHost();
@@ -379,7 +407,7 @@ class _ChatScreenState extends State<ChatScreen>
if (id != null && id.isNotEmpty) {
_workspaceVisible = true;
_publishedWorkspaceSession = id;
_workspace.open(id);
_openRouted(id);
} else if (widget.onSessionSelected != null) {
_workspaceVisible = false;
}
@@ -485,12 +513,14 @@ class _ChatScreenState extends State<ChatScreen>
// The session list pads its first row by the bar's height itself, so it
// scrolls behind the shell's floating bar like the other lists.
final sessions = ChatSessionsScreen(
key: _sessionsKey,
gateway: widget.gateway,
embedded: true,
syncToken: widget.syncToken,
controller: _sessions,
folds: _folds,
onOpen: _openBySelection,
draggable: beside,
onOpenBeside: beside ? _openBeside : null,
onOpenBelow: _openBelow,
onFloat: _floatsHere ? _floatSession : null,
@@ -23,6 +23,7 @@ class ChatCompactSidebar extends StatelessWidget {
required this.activeSessionId,
this.visibleSessionIds = const {},
required this.onOpen,
required this.onNewChat,
required this.onExpand,
this.navigation,
});
@@ -31,6 +32,7 @@ class ChatCompactSidebar extends StatelessWidget {
final String? activeSessionId;
final Set<String> visibleSessionIds;
final ValueChanged<JsonMap> onOpen;
final VoidCallback onNewChat;
final VoidCallback onExpand;
final Widget? navigation;
static const width = 72.0;
@@ -82,6 +84,38 @@ class ChatCompactSidebar extends StatelessWidget {
final color =
chatColorShade(context, chatSessionColor(row)) ??
Theme.of(context).colorScheme.primary;
final button = _button(
context,
details,
ExcludeSemantics(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatCompactAvatar(
title: title,
color: color,
active: selected,
visible: visible,
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
),
if (machineName case final name?)
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall,
),
],
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: selected,
);
return ChatVisibilityMarker(
sessionId: id,
color: color,
@@ -92,37 +126,29 @@ class ChatCompactSidebar extends StatelessWidget {
? Duration.zero
: const Duration(milliseconds: 200),
color: selected ? Colors.transparent : color.withValues(alpha: .07),
child: _button(
context,
details,
ExcludeSemantics(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatCompactAvatar(
title: title,
color: color,
active: selected,
visible: visible,
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
),
if (machineName case final name?)
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall,
),
],
child: Draggable<JsonMap>(
// A mouse drags at once (a click still opens the chat); the chip
// follows the pointer.
dragAnchorStrategy: pointerDragAnchorStrategy,
data: row,
feedback: Material(
elevation: 4,
borderRadius: BorderRadius.circular(20),
child: Chip(
avatar: ChatCompactAvatar(
title: title,
color: color,
active: false,
visible: false,
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
),
label: Text(title),
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: selected,
childWhenDragging: Opacity(opacity: .35, child: button),
child: button,
),
),
);
@@ -135,6 +161,7 @@ class ChatCompactSidebar extends StatelessWidget {
width: width,
child: Column(
children: [
_button(context, 'New chat', const Icon(Icons.add), onNewChat),
_button(
context,
'Expand chat list',
@@ -33,6 +33,7 @@ class ChatSessionsBody extends StatelessWidget {
required this.error,
required this.onOpen,
this.onOpenBeside,
this.draggable = false,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
@@ -65,6 +66,7 @@ class ChatSessionsBody extends StatelessWidget {
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;
@@ -104,6 +106,7 @@ class ChatSessionsBody extends StatelessWidget {
duplicateTitles: duplicateTitles,
onOpen: onOpen,
onOpenBeside: onOpenBeside,
draggable: draggable,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
paneMenu: paneMenu,
@@ -33,6 +33,7 @@ class ChatSessionsScreen extends StatefulWidget {
required this.gateway,
required this.onOpen,
this.onOpenBeside,
this.draggable = false,
this.onOpenBelow,
this.onFloat,
this.paneMenu,
@@ -52,6 +53,7 @@ class ChatSessionsScreen extends StatefulWidget {
/// Optional split-pane actions; absent when the host cannot offer a split.
final ValueChanged<JsonMap>? onOpenBeside;
final bool draggable;
final ValueChanged<JsonMap>? onOpenBelow;
/// Floats the chat in a window over the app; absent when it cannot.
@@ -98,10 +100,10 @@ class ChatSessionsScreen extends StatefulWidget {
final ChatSectionFolds? folds;
@override
State<ChatSessionsScreen> createState() => _ChatSessionsScreenState();
ChatSessionsScreenState createState() => ChatSessionsScreenState();
}
class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
class ChatSessionsScreenState extends State<ChatSessionsScreen> {
late final ChatSessionsController _controller =
(widget.controller ??
ChatSessionsController(
@@ -233,6 +235,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
if (session != null && mounted) widget.onOpen(session);
}
/// Starts the same machine picker and create dialog used by the list action.
Future<void> newChat() => _newChat();
void _markOpened(JsonMap session) =>
unawaited(_controller.markOpened(session));
@@ -333,6 +338,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
onOpenBeside: widget.onOpenBeside == null
? null
: _openBeside,
draggable: widget.draggable,
onOpenBelow: widget.onOpenBelow == null
? null
: _openBelow,
@@ -88,6 +88,7 @@ SessionListItem chatSessionRowItem(
required Set<String> duplicateTitles,
required bool Function(JsonMap) isUnseen,
required ValueChanged<JsonMap> onOpen,
bool draggable = false,
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
@@ -112,6 +113,7 @@ SessionListItem chatSessionRowItem(
unseen: isUnseen(session),
divider: divider,
onOpen: onOpen,
draggable: draggable,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
@@ -14,6 +14,7 @@ class MaterialSessionList extends StatelessWidget {
required this.emptyMessage,
required this.duplicateTitles,
required this.onOpen,
this.draggable = false,
this.onOpenBeside,
this.onOpenBelow,
this.onFloat,
@@ -42,6 +43,7 @@ class MaterialSessionList extends StatelessWidget {
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
final bool draggable;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap>? onFloat;
@@ -117,6 +119,7 @@ class MaterialSessionList extends StatelessWidget {
duplicateTitles: duplicateTitles,
isUnseen: isUnseen,
onOpen: onOpen,
draggable: draggable,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
@@ -44,12 +44,14 @@ class ChatSessionRow extends StatelessWidget {
this.duplicateTitles = const {},
this.onLongPress,
this.selectionOnly = false,
this.draggable = false,
});
final JsonMap session;
/// A choosing surface keeps the normal row content but offers only opening.
final bool selectionOnly;
final bool draggable;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
@@ -78,7 +80,27 @@ class ChatSessionRow extends StatelessWidget {
color: tint == null ? background : Color.alphaBlend(tint, background),
marker: marker,
markerWidth: visible ? (selected ? 10 : 3) : 0,
child: _marked(context, id, marker, accent),
child: draggable
? Draggable<JsonMap>(
// A mouse drags at once (a click still opens the chat); the chip
// follows the pointer.
dragAnchorStrategy: pointerDragAnchorStrategy,
data: session,
feedback: Material(
elevation: 4,
borderRadius: BorderRadius.circular(20),
child: Chip(
avatar: ChatSessionAvatar(session: session),
label: Text(chatSessionTitle(session)),
),
),
childWhenDragging: Opacity(
opacity: .35,
child: _marked(context, id, marker, accent),
),
child: _marked(context, id, marker, accent),
)
: _marked(context, id, marker, accent),
);
}
@@ -21,6 +21,7 @@ Widget memoChatSessionRow({
required bool unseen,
required bool divider,
required ValueChanged<JsonMap> onOpen,
bool draggable = false,
ValueChanged<JsonMap>? onOpenBeside,
ValueChanged<JsonMap>? onOpenBelow,
ValueChanged<JsonMap>? onFloat,
@@ -43,6 +44,7 @@ Widget memoChatSessionRow({
unseen,
divider,
onOpen,
draggable,
onOpenBeside,
onOpenBelow,
onFloat,
@@ -63,6 +65,7 @@ Widget memoChatSessionRow({
unseen: unseen,
divider: divider,
onOpen: onOpen,
draggable: draggable,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onFloat: onFloat,
@@ -17,12 +17,14 @@ import 'chat_pane_switch_motion.dart';
import 'chat_pane_backdrop.dart';
import 'chat_pane_dim.dart';
import 'chat_workspace_pane_scope.dart';
import 'chat_workspace_drop.dart';
import 'chat_workspace_surface.dart';
import '../../../ui/input/keyboard_owner.dart';
export 'chat_workspace_controller.dart';
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
export 'chat_workspace_pane_scope.dart';
export 'chat_workspace_drop.dart';
typedef ChatWorkspacePaneBuilder =
Widget Function(BuildContext context, ChatWorkspacePane pane, bool active);
@@ -35,6 +37,7 @@ class ChatWorkspace extends StatefulWidget {
required this.controller,
required this.paneBuilder,
this.onFocusPane,
this.onDrop,
this.shortcutsEnabled = true,
this.singlePane = false,
this.mobilePeeks = false,
@@ -71,6 +74,7 @@ class ChatWorkspace extends StatefulWidget {
/// Keyboard navigation only: the owner can focus the target composer.
/// Pointer activation leaves text-selection and pointer focus alone.
final ValueChanged<ChatWorkspacePane>? onFocusPane;
final void Function(ChatWorkspacePane, Object, ChatWorkspaceDropZone)? onDrop;
@override
State<ChatWorkspace> createState() => _ChatWorkspaceState();
@@ -393,6 +397,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
sharedEdges,
moveTargets[pane.id],
),
onDrop: widget.onDrop,
);
},
),
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
import 'chat_workspace_nodes.dart';
import 'chat_workspace_reconcile.dart';
import 'chat_workspace_snapshot.dart';
import 'chat_workspace_drop.dart';
export 'chat_workspace_nodes.dart';
@@ -237,6 +238,73 @@ class ChatWorkspaceController extends ChangeNotifier {
_changed();
}
/// Places a dragged chat into a pane without ever creating a duplicate.
void dropSession(
String sessionId,
String targetPaneId,
ChatWorkspaceDropZone zone,
) {
if (sessionId.isEmpty || _root == null) return;
final target = panes.where((pane) => pane.id == targetPaneId).firstOrNull;
if (target == null) return;
final source = panes
.where((pane) => pane.sessionId == sessionId)
.firstOrNull;
if (source?.id == target.id) {
activate(target.id);
return;
}
if (zone == ChatWorkspaceDropZone.replace) {
if (source == null) {
_root = _replace(
_root!,
target.id,
ChatWorkspacePane(target.id, sessionId),
);
} else {
_root = swapChatWorkspacePanes(_root!, source, target);
}
_active = target.id;
_changed();
return;
}
if (source != null) close(source.id);
final axis = zone == ChatWorkspaceDropZone.right
? ChatSplitAxis.horizontal
: ChatSplitAxis.vertical;
final current = panes.where((pane) => pane.id == target.id).firstOrNull;
if (current == null) return;
_root = _replace(
_root!,
current.id,
ChatWorkspaceSplit(
_id('split'),
axis,
current,
ChatWorkspacePane(_id('pane'), sessionId),
),
);
_active = panes.last.id;
_changed();
}
/// Replaces a pane after its caller has already validated [newId]. Unlike
/// [replaceSession], this does not ask the window host to show a floating
/// chat; keyboard cycling filters those chats before calling this method.
void replacePaneSession(String paneId, String newId) {
if (newId.isEmpty) return;
final pane = panes.where((p) => p.id == paneId).firstOrNull;
if (pane == null) return;
final existing = panes.where((p) => p.sessionId == newId).firstOrNull;
if (existing != null) {
close(pane.id);
activate(existing.id);
return;
}
_root = _replace(_root!, pane.id, ChatWorkspacePane(pane.id, newId));
_changed();
}
ChatWorkspaceNode _replace(
ChatWorkspaceNode node,
String id,
@@ -0,0 +1,134 @@
import 'package:flutter/material.dart';
import 'chat_workspace_nodes.dart';
enum ChatWorkspaceDropZone { replace, right, bottom }
class ChatWorkspaceDropTarget extends StatefulWidget {
const ChatWorkspaceDropTarget({
super.key,
required this.pane,
required this.rect,
required this.onDrop,
});
final ChatWorkspacePane pane;
final Rect rect;
final void Function(ChatWorkspacePane, Object, ChatWorkspaceDropZone) onDrop;
@override
State<ChatWorkspaceDropTarget> createState() =>
_ChatWorkspaceDropTargetState();
}
class _ChatWorkspaceDropTargetState extends State<ChatWorkspaceDropTarget> {
ChatWorkspaceDropZone? _zone;
ChatWorkspaceDropZone _zoneAt(Offset local) {
if (local.dx >= widget.rect.width * .75) {
return ChatWorkspaceDropZone.right;
}
if (local.dy >= widget.rect.height * .75) {
return ChatWorkspaceDropZone.bottom;
}
return ChatWorkspaceDropZone.replace;
}
@override
Widget build(BuildContext context) => DragTarget<Object>(
onWillAcceptWithDetails: (_) => true,
onMove: (details) {
final box = context.findRenderObject() as RenderBox?;
if (box == null) return;
final zone = _zoneAt(box.globalToLocal(details.offset));
if (_zone != zone) setState(() => _zone = zone);
},
onLeave: (_) {
if (mounted) setState(() => _zone = null);
},
onAcceptWithDetails: (details) {
final box = context.findRenderObject() as RenderBox?;
final zone = box == null
? ChatWorkspaceDropZone.replace
: _zoneAt(box.globalToLocal(details.offset));
setState(() => _zone = null);
widget.onDrop(widget.pane, details.data, zone);
},
builder: (context, candidates, rejected) {
final zone = _zone;
if (zone == null) return const SizedBox.expand();
final scheme = Theme.of(context).colorScheme;
final (alignment, width, height, icon, label) = switch (zone) {
ChatWorkspaceDropZone.replace => (
Alignment.center,
1.0,
1.0,
Icons.swap_horiz,
'Show here',
),
ChatWorkspaceDropZone.right => (
Alignment.centerRight,
.5,
1.0,
Icons.vertical_split_outlined,
'Open to the right',
),
ChatWorkspaceDropZone.bottom => (
Alignment.bottomCenter,
1.0,
.5,
Icons.horizontal_split_outlined,
'Open below',
),
};
// Only the area that will receive the chat is marked: the whole pane
// to replace its chat, or the half a new split will take.
return IgnorePointer(
child: Align(
alignment: alignment,
child: FractionallySizedBox(
widthFactor: width,
heightFactor: height,
child: Padding(
padding: const EdgeInsets.all(8),
child: DecoratedBox(
key: ValueKey('chat-drop-zone-${zone.name}'),
decoration: BoxDecoration(
color: scheme.primary.withValues(alpha: .14),
border: Border.all(color: scheme.primary, width: 2),
borderRadius: BorderRadius.circular(16),
),
child: Center(
child: DecoratedBox(
decoration: BoxDecoration(
color: scheme.primaryContainer,
borderRadius: BorderRadius.circular(24),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 10,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, color: scheme.onPrimaryContainer),
const SizedBox(width: 8),
Text(
label,
style: Theme.of(context).textTheme.labelLarge
?.copyWith(color: scheme.onPrimaryContainer),
),
],
),
),
),
),
),
),
),
),
);
},
);
}
@@ -13,6 +13,7 @@ import 'chat_motion_viewport.dart';
import 'chat_workspace_controller.dart';
import 'chat_workspace_divider.dart';
import 'chat_workspace_geometry.dart';
import 'chat_workspace_drop.dart';
/// Rendering only: retained live panes stay stable siblings, while the outgoing
/// picture and mobile drag target sit alongside them in the same clipped stack.
@@ -30,6 +31,7 @@ Widget chatWorkspaceSurface({
required List<ChatWorkspacePane> panes,
required Widget Function(ChatWorkspacePane) paneView,
Widget Function(ChatWorkspacePane)? stageStrip,
void Function(ChatWorkspacePane, Object, ChatWorkspaceDropZone)? onDrop,
}) {
final moving = Listenable.merge([
motion.animation,
@@ -145,6 +147,17 @@ Widget chatWorkspaceSurface({
rect: stage.rectFor(layout.stageId)!,
size: size,
),
if (!collapsed && mobile == null && onDrop != null)
for (final pane in panes)
if (geometry.panes[pane.id] case final rect?)
Positioned.fromRect(
rect: rect,
child: ChatWorkspaceDropTarget(
pane: pane,
rect: rect,
onDrop: onDrop,
),
),
if (mobile?.peekId != null && !motion.isAnimating)
Positioned(
top: mobile!.contentHeight - 12,
@@ -224,6 +224,7 @@ class PipelineRun {
required this.createdAt,
required this.finishedAt,
required this.executing,
this.workspace = '',
});
factory PipelineRun.fromJson(PipelineJson json) => PipelineRun(
@@ -233,6 +234,7 @@ class PipelineRun {
createdAt: _string(json['created_at']),
finishedAt: _string(json['finished_at']),
executing: json['executing'] == true,
workspace: '${json['workspace'] ?? ''}',
);
final int id;
@@ -241,6 +243,7 @@ class PipelineRun {
final String createdAt;
final String finishedAt;
final bool executing;
final String workspace;
}
/// Timestamps decide recency; a higher run id breaks an exact tie or two bad
+15 -2
View File
@@ -41,6 +41,8 @@ class PipelinesScreen extends StatefulWidget {
this.initialPipelineId,
this.initialVersion = 0,
this.initialStageKey,
this.onOpenInChat,
this.onOpenPipelineInChat,
});
final ApiGateway gateway;
@@ -87,6 +89,10 @@ class PipelinesScreen extends StatefulWidget {
/// pane; a key the pinned version does not declare opens the Graph tab with
/// nothing selected. Null keeps the ordinary default tab.
final String? initialStageKey;
final Future<void> Function(BuildContext, PipelineDetail, PipelineRun?)?
onOpenInChat;
final Future<void> Function(BuildContext, PipelineSummary, PipelineRun?)?
onOpenPipelineInChat;
@override
State<PipelinesScreen> createState() => _PipelinesScreenState();
@@ -235,6 +241,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
showBack: false,
onRunStarted: widget.onRunStarted,
onViewPipelineRuns: widget.onViewPipelineRuns,
onOpenInChat: widget.onOpenInChat,
stageKey: stageKey,
stagePipelineId: widget.initialPipelineId,
stageVersion: widget.initialVersion,
@@ -252,12 +259,18 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
);
if (!wide) {
return ContentWidth(
child: PipelineListPanel(controller: _controller),
child: PipelineListPanel(
controller: _controller,
onOpenInChat: widget.onOpenPipelineInChat,
),
);
}
return ListDetailPanes(
list: ContentWidth(
child: PipelineListPanel(controller: _controller),
child: PipelineListPanel(
controller: _controller,
onOpenInChat: widget.onOpenPipelineInChat,
),
),
detailIdentity: _controller.selectedId,
detail: _controller.hasSelection
@@ -18,17 +18,29 @@ String archiveConfirmation(String name) =>
Widget pipelineActionsMenu(
BuildContext context,
PipelinesController controller,
PipelineDetail detail,
) {
PipelineDetail detail, {
Future<void> Function(BuildContext, PipelineDetail, PipelineRun?)?
onOpenInChat,
}) {
final archived = detail.archived;
final label = archived ? 'Unarchive' : 'Archive…';
void run(BuildContext context) =>
archiveOrUnarchive(context, controller, detail);
return SegmentedOverflowAction(
overflowEntry: SegmentedOverflowEntry(
label: archived ? 'Unarchive pipeline' : 'Archive pipeline…',
label: 'Pipeline actions',
icon: Icons.archive_outlined,
onPressed: () => run(context),
choices: [
SegmentedMenuChoice(
label: archived ? 'Unarchive pipeline' : 'Archive pipeline…',
onSelected: () => run(context),
),
if (onOpenInChat != null)
SegmentedMenuChoice(
label: 'Open in chat',
onSelected: () => onOpenInChat(context, detail, null),
),
],
),
child: AppOverflowMenu<bool>(
key: const Key('pipeline-actions-menu'),
@@ -40,8 +52,15 @@ Widget pipelineActionsMenu(
value: true,
label: label,
),
if (onOpenInChat != null)
const AppMenuAction<bool>(
value: false,
label: 'Open in chat',
icon: Icons.chat_bubble_outline,
),
],
onSelected: (context, _) => run(context),
onSelected: (context, value) =>
value ? run(context) : onOpenInChat!(context, detail, null),
),
);
}
@@ -45,6 +45,7 @@ class PipelineDetailPanel extends StatefulWidget {
this.stagePipelineId,
this.stageVersion = 0,
this.stageRequest = 0,
this.onOpenInChat,
}) : assert(
stageKey == null || stagePipelineId != null,
'a routed stage names the pipeline it belongs to',
@@ -77,6 +78,8 @@ class PipelineDetailPanel extends StatefulWidget {
/// definition pane even though the pinned detail may be re-read in place. A
/// later version switch from this screen is not a new route request.
final int stageRequest;
final Future<void> Function(BuildContext, PipelineDetail, PipelineRun?)?
onOpenInChat;
@override
State<PipelineDetailPanel> createState() => _PipelineDetailPanelState();
@@ -420,7 +423,18 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
onRunStarted: widget.onRunStarted,
inBar: true,
),
pipelineActionsMenu(context, _controller, detail),
pipelineActionsMenu(
context,
_controller,
detail,
onOpenInChat: widget.onOpenInChat == null
? null
: (context, detail, _) => widget.onOpenInChat!(
context,
detail,
_controller.latestRuns[detail.id],
),
),
];
Widget _source(BuildContext context, PipelineDetail detail) {
@@ -14,6 +14,7 @@ import '../pipelines_controller.dart';
import 'pipeline_controls.dart';
import 'pipeline_filter_page.dart';
import 'pipeline_scope_control.dart';
import '../../../ui/layout/app_overflow_menu.dart';
/// The list's horizontal rhythm, matching the web's toolbar and row inset
/// (`var(--space-s)`: 12px). The detail pane keeps its own content padding.
@@ -21,9 +22,15 @@ const double kPipelineListInset = 12;
/// The left/top pane: filter and sort controls, then the truthful list states.
class PipelineListPanel extends StatelessWidget {
const PipelineListPanel({super.key, required this.controller});
const PipelineListPanel({
super.key,
required this.controller,
this.onOpenInChat,
});
final PipelinesController controller;
final Future<void> Function(BuildContext, PipelineSummary, PipelineRun?)?
onOpenInChat;
@override
Widget build(BuildContext context) {
@@ -264,6 +271,22 @@ class PipelineListPanel extends StatelessWidget {
: Text(
ServerContext.metadata(context, runStateLabel(badge.state)),
),
menu: onOpenInChat == null
? null
: AppOverflowMenu<bool>(
key: Key('pipeline-row-more-menu-${pipeline.id}'),
label: 'Pipeline actions',
sheetTitle: pipeline.displayName,
actions: const [
AppMenuAction<bool>(
value: true,
label: 'Open in chat',
icon: Icons.chat_bubble_outline,
),
],
onSelected: (context, _) =>
onOpenInChat!(context, pipeline, run),
),
);
},
);
+4
View File
@@ -53,6 +53,7 @@ class RunsScreen extends StatefulWidget {
this.attention,
this.sortStore = const SharedPreferencesRunsSortStore(),
this.pendingRunStore = const SharedPreferencesPendingRunStore(''),
this.onOpenInChat,
});
final ApiGateway gateway;
@@ -103,6 +104,7 @@ class RunsScreen extends StatefulWidget {
/// Where a New run's pending launch intent persists, under the same endpoint
/// scope the Pipelines tab uses. Tests inject a memory store.
final PendingRunStore pendingRunStore;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
@override
State<RunsScreen> createState() => _RunsScreenState();
@@ -300,6 +302,7 @@ class _RunsScreenState extends State<RunsScreen> {
onBack: onBack,
onRunOpened: _select,
onOpenPipeline: widget.onOpenPipeline,
onOpenInChat: widget.onOpenInChat,
initialStageKey: widget.initialStageKey,
initialVisit: widget.initialVisit,
);
@@ -354,6 +357,7 @@ class _RunsScreenState extends State<RunsScreen> {
attentionNow: widget.attentionNow,
notifications: widget.notifications,
attention: widget.attention,
onOpenInChat: widget.onOpenInChat,
),
),
);
@@ -24,6 +24,7 @@ class RunDetailView extends StatefulWidget {
this.onOpenPipeline,
this.initialStageKey,
this.initialVisit,
this.onOpenInChat,
});
final RunsController controller;
@@ -44,6 +45,7 @@ class RunDetailView extends StatefulWidget {
/// plain detail.
final String? initialStageKey;
final int? initialVisit;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
@override
State<RunDetailView> createState() => _RunDetailViewState();
@@ -114,6 +116,7 @@ class _RunDetailViewState extends State<RunDetailView> {
onRunChanged: widget.controller.acceptRunDetail,
onRunOpened: widget.onRunOpened,
onDeleted: widget.controller.applyDeletion,
onOpenInChat: widget.onOpenInChat,
);
if (inShellBar) {
return ShellBar(
+8 -1
View File
@@ -35,6 +35,7 @@ class RunListRow extends StatelessWidget {
this.checked = false,
this.onToggle,
this.onLongPress,
this.onOpenInChat,
});
final JsonMap run;
@@ -56,6 +57,7 @@ class RunListRow extends StatelessWidget {
/// Enters select mode from a touch long-press.
final VoidCallback? onLongPress;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
@override
Widget build(BuildContext context) {
@@ -140,13 +142,18 @@ class RunListRow extends StatelessWidget {
!selecting &&
gateway != null &&
onRunChanged != null &&
showRunMoreMenu(run, deletable: onDeleted != null)
showRunMoreMenu(
run,
deletable: onDeleted != null,
canOpenInChat: onOpenInChat != null,
)
? RunMoreMenu(
run: run,
gateway: gateway!,
onRunChanged: onRunChanged!,
onRunOpened: onRunOpened,
onDeleted: onDeleted,
onOpenInChat: onOpenInChat,
menuKey: ValueKey('run-list-more-menu-$id'),
)
: null,
+24 -3
View File
@@ -16,14 +16,21 @@ import '../domain/run_models.dart' show runIdentity;
const runMoreMenuKey = ValueKey<String>('run-more-menu');
const deleteRunActionKey = ValueKey<String>('run-delete-action');
const deleteRunActionLabel = 'Delete run';
const openRunInChatActionKey = ValueKey<String>('run-open-in-chat-action');
const openRunInChatActionLabel = 'Open in chat';
/// Whether the run has anything for its more menu. [deletable] says the host
/// can apply a deletion, so a finished run offers Delete run.
bool showRunMoreMenu(JsonMap run, {bool deletable = false}) =>
bool showRunMoreMenu(
JsonMap run, {
bool deletable = false,
bool canOpenInChat = false,
}) =>
runTitleId(run) != null ||
canScheduleRun(run) ||
_canRetry(run) ||
(deletable && runIsDeletable(run));
(deletable && runIsDeletable(run)) ||
canOpenInChat;
/// The run's own name for its action sheet: its title or pipeline, else
/// `Run <id>`, as its list row shows it.
@@ -34,7 +41,7 @@ String runMoreMenuTitle(JsonMap run) {
bool _canRetry(JsonMap run) => retryRunId(run) != null && canRetryRun(run);
enum _RunMoreItem { retry, rename, schedule, delete }
enum _RunMoreItem { retry, rename, schedule, delete, openInChat }
/// Each item keeps the key its standalone button had.
Key _keyOf(_RunMoreItem item) => switch (item) {
@@ -42,6 +49,7 @@ Key _keyOf(_RunMoreItem item) => switch (item) {
_RunMoreItem.rename => runTitleActionKey,
_RunMoreItem.schedule => scheduleRunActionKey,
_RunMoreItem.delete => deleteRunActionKey,
_RunMoreItem.openInChat => openRunInChatActionKey,
};
/// The run detail's more menu: Retry (failed runs only), Rename and Schedule
@@ -56,6 +64,7 @@ class RunMoreMenu extends StatefulWidget {
required this.onRunChanged,
this.onRunOpened,
this.onDeleted,
this.onOpenInChat,
this.menuKey = runMoreMenuKey,
});
@@ -68,6 +77,7 @@ class RunMoreMenu extends StatefulWidget {
/// Applies an answered deletion; without it the menu offers no Delete run.
final ValueChanged<RunsDeletion>? onDeleted;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
/// Detail menus retain the shared key; list rows supply a per-run key.
final Key menuKey;
@@ -86,6 +96,8 @@ class _RunMoreMenuState extends State<RunMoreMenu> {
if (canScheduleRun(run)) (_RunMoreItem.schedule, scheduleRunActionLabel),
if (widget.onDeleted != null && runIsDeletable(run))
(_RunMoreItem.delete, deleteRunActionLabel),
if (widget.onOpenInChat != null)
(_RunMoreItem.openInChat, openRunInChatActionLabel),
];
void _pick(BuildContext context, _RunMoreItem item) {
@@ -117,6 +129,8 @@ class _RunMoreMenuState extends State<RunMoreMenu> {
gateway: widget.gateway,
onDeleted: widget.onDeleted!,
);
case _RunMoreItem.openInChat:
widget.onOpenInChat!(context, run);
}
}
@@ -131,6 +145,13 @@ class _RunMoreMenuState extends State<RunMoreMenu> {
key: _keyOf(item),
value: item,
label: label,
icon: switch (item) {
_RunMoreItem.retry => Icons.replay,
_RunMoreItem.rename => Icons.edit_outlined,
_RunMoreItem.schedule => Icons.schedule,
_RunMoreItem.delete => Icons.delete_outline,
_RunMoreItem.openInChat => Icons.chat_bubble_outline,
},
destructive: item == _RunMoreItem.delete,
),
],
+5 -1
View File
@@ -32,10 +32,12 @@ class RunsList extends StatelessWidget {
this.notifications,
this.attention,
this.active = true,
this.onOpenInChat,
});
/// False while a run detail covers the list; the bar is then the run's.
final bool active;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
final RunsController controller;
final ValueChanged<num> onSelected;
@@ -166,7 +168,8 @@ class RunsList extends StatelessWidget {
// A server with no runs at all is not a filter problem: say what the list
// is for and where its first run comes from. A free-text query counts as
// a filter too, so a search on an empty server reads as "nothing found".
final noRunsAtAll = controller.runs.isEmpty &&
final noRunsAtAll =
controller.runs.isEmpty &&
controller.activeFilterCount == 0 &&
controller.query.trim().isEmpty;
return BelowTopBar(
@@ -340,6 +343,7 @@ class RunsList extends StatelessWidget {
gateway: controller.repository.gateway,
onRunChanged: controller.acceptRunDetail,
onRunOpened: onSelected,
onOpenInChat: onOpenInChat,
);
}
}
@@ -156,10 +156,10 @@ class KeyboardShortcutRegistry {
if (!web)
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Cycle chat panes and floating chats',
action: 'Cycle chats and floating chat panes',
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
caveat:
'While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
'With one tiled pane, cycles open sidebar chats (excluding closed, hidden and floating chats); with multiple panes, cycles panes. While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
),
const KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
@@ -0,0 +1,186 @@
import 'package:flutter/material.dart';
import '../../application/open_in_chat_preferences.dart';
import '../../core/api_gateway.dart';
import '../chat/data/chat_repository.dart';
import 'settings_group.dart';
/// The harness and model Open in chat (a run's or pipeline's More menu)
/// starts its chats with. The server lists models only for an existing chat,
/// so a harness's models come from its most recent chat; with none, only the
/// harness default is offered.
class SettingsOpenInChatSection extends StatefulWidget {
const SettingsOpenInChatSection({super.key, required this.gateway});
final ApiGateway gateway;
@override
State<SettingsOpenInChatSection> createState() =>
_SettingsOpenInChatSectionState();
}
class _SettingsOpenInChatSectionState extends State<SettingsOpenInChatSection> {
late final ChatRepository _chats = ChatRepository(widget.gateway);
OpenInChatPreferences _chosen = const OpenInChatPreferences();
List<String>? _harnesses;
List<JsonMap> _models = const [];
bool _loadingModels = false;
String? _error;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
try {
final chosen = await OpenInChatPreferences.load(widget.gateway);
final harnesses = await _chats.backends();
if (!mounted) return;
setState(() {
_chosen = chosen;
_harnesses = harnesses;
});
await _loadModels(chosen.harness);
} catch (error) {
if (mounted) setState(() => _error = '$error');
}
}
/// The models of [harness]'s most recent chat, or none.
Future<void> _loadModels(String harness) async {
setState(() {
_models = const [];
_loadingModels = harness.isNotEmpty;
});
if (harness.isEmpty) return;
try {
final sessions = await _chats.sessions();
final latest =
sessions.where((session) => session['backend'] == harness).toList()
..sort(
(a, b) => '${b['updated_at'] ?? ''}'.compareTo(
'${a['updated_at'] ?? ''}',
),
);
final models = latest.isEmpty
? const <JsonMap>[]
: await _chats.models('${latest.first['id']}');
if (mounted && _chosen.harness == harness) {
setState(() {
_models = models;
_loadingModels = false;
});
}
} catch (_) {
if (mounted) setState(() => _loadingModels = false);
}
}
Future<void> _save(OpenInChatPreferences next) async {
setState(() => _chosen = next);
await next.save(widget.gateway);
}
@override
Widget build(BuildContext context) {
final harnesses = _harnesses;
final error = _error;
return SettingsGroup(
title: 'Open in chat',
footer: Text(
'Used when a run or pipeline is opened in a new chat. Models come '
"from this harness's most recent chat.",
),
children: [
if (error != null)
ListTile(
leading: const Icon(Icons.error_outline),
title: const Text('Could not load the harnesses'),
subtitle: Text(error),
trailing: TextButton(
onPressed: () {
setState(() => _error = null);
_load();
},
child: const Text('Retry'),
),
)
else if (harnesses == null)
const ListTile(
leading: SizedBox.square(
dimension: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
title: Text('Loading harnesses…'),
)
else ...[
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: DropdownMenu<String>(
key: const Key('open-in-chat-harness'),
expandedInsets: EdgeInsets.zero,
label: const Text('Harness'),
initialSelection: harnesses.contains(_chosen.harness)
? _chosen.harness
: '',
dropdownMenuEntries: [
const DropdownMenuEntry(value: '', label: 'Default'),
for (final harness in harnesses)
DropdownMenuEntry(value: harness, label: harness),
],
onSelected: (harness) async {
final value = harness ?? '';
if (value == _chosen.harness) return;
await _save(OpenInChatPreferences(harness: value));
await _loadModels(value);
},
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
child: DropdownMenu<String>(
key: ValueKey('open-in-chat-model-${_chosen.harness}'),
expandedInsets: EdgeInsets.zero,
enabled: _chosen.harness.isNotEmpty && !_loadingModels,
label: Text(_loadingModels ? 'Loading models…' : 'Model'),
initialSelection: _chosen.hasModel
? '${_chosen.provider}/${_chosen.model}'
: '',
dropdownMenuEntries: [
const DropdownMenuEntry(value: '', label: 'Harness default'),
if (_chosen.hasModel &&
!_models.any(
(m) =>
'${m['provider']}/${m['id']}' ==
'${_chosen.provider}/${_chosen.model}',
))
DropdownMenuEntry(
value: '${_chosen.provider}/${_chosen.model}',
label: _chosen.model,
),
for (final model in _models)
DropdownMenuEntry(
value: '${model['provider']}/${model['id']}',
label: '${model['name'] ?? model['id']}',
),
],
onSelected: (value) {
final picked = value ?? '';
final slash = picked.indexOf('/');
_save(
OpenInChatPreferences(
harness: _chosen.harness,
provider: slash < 0 ? '' : picked.substring(0, slash),
model: slash < 0 ? '' : picked.substring(slash + 1),
),
);
},
),
),
],
],
);
}
}
@@ -106,6 +106,13 @@ extension _SettingsPageSections on _SettingsScreenState {
workspaceField: _workspaceField,
),
),
SettingsSection(
id: 'open-in-chat',
title: 'Open in chat',
keywords: 'open in chat run pipeline harness model default new chat',
lazy: true,
builder: (_) => SettingsOpenInChatSection(gateway: widget.client),
),
if (widget.notifications case final notifications?)
SettingsSection(
id: 'notifications',
@@ -43,6 +43,7 @@ import 'settings_row.dart';
import 'settings_read_aloud_section.dart';
import '../chat/speech/speech_controller.dart';
import 'settings_open_in_chat_section.dart';
part 'settings_page_sections.dart';
/// The Settings destination: one searchable page of grouped Material sections.