feat: fold subagent trees and open them from Agent Task rows
Subagent sessions now render as a collapsed tree in the sidebar: parents with workers get an expand/collapse chevron, expanded child rows sit behind a guide line, and the parent keeps its worker count. The parent of the open subagent expands once so its child is visible. Subagent tool rows in the parent chat (subagent or task) are labeled 子代理, show the description and open the child session on tap; a child outside the loaded page is fetched by id first. Subagent chats are read-only by default with the first-party notice; allowPromptingSubagentSessions permits ordinary subagents, while a Lead's operator-child worker stays read-only until takeover. 0.4.10 (410).
This commit is contained in:
1 parent
cebf09048e
commit
9cbd97d532
10 files changed
+271
-23
No files matched your search
@@ -32,6 +32,11 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
final Set<String> _collapsed = {};
|
||||
bool _showArchived = false;
|
||||
|
||||
/// Parents whose subagents are expanded. Collapsed is the default; the
|
||||
/// parent of the open child expands once so its child is visible.
|
||||
final Set<String> _expandedChildren = {};
|
||||
String? _activeChildParent;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -63,6 +68,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
return ListenableBuilder(
|
||||
listenable: _app,
|
||||
builder: (context, _) {
|
||||
_syncActiveParent();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
@@ -499,11 +505,33 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
]..sort((a, b) => a.created.compareTo(b.created));
|
||||
}
|
||||
|
||||
List<Widget> _rowsWithChildren(Session session, {bool archived = false}) => [
|
||||
_row(session, archived: archived),
|
||||
for (final child in _childrenOf(session, archived: archived))
|
||||
_row(child, archived: archived, child: true),
|
||||
];
|
||||
List<Widget> _rowsWithChildren(Session session, {bool archived = false}) {
|
||||
final rows = <Widget>[_row(session, archived: archived)];
|
||||
if (!_expandedChildren.contains(session.id)) return rows;
|
||||
final theme = Theme.of(context);
|
||||
for (final child in _childrenOf(session, archived: archived)) {
|
||||
rows.add(Container(
|
||||
margin: const EdgeInsets.only(left: 24),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
left: BorderSide(color: theme.dividerColor, width: 1),
|
||||
),
|
||||
),
|
||||
child: _row(child, archived: archived, child: true),
|
||||
));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/// Expands the parent of the open subagent once, so the sidebar shows where
|
||||
/// the child is. Collapsing it by hand stays collapsed until another child
|
||||
/// is opened.
|
||||
void _syncActiveParent() {
|
||||
final parent = _app.chat?.session.parentID;
|
||||
if (parent == _activeChildParent) return;
|
||||
_activeChildParent = parent;
|
||||
if (parent != null) _expandedChildren.add(parent);
|
||||
}
|
||||
|
||||
Widget _row(Session session,
|
||||
{bool archived = false, bool child = false}) {
|
||||
@@ -512,6 +540,8 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
final running = _isActive(session);
|
||||
final selected =
|
||||
!_app.draftOpen && _app.chat?.session.id == session.id;
|
||||
final children = child ? const <Session>[] : _childrenOf(session, archived: archived);
|
||||
final expanded = _expandedChildren.contains(session.id);
|
||||
return Slidable(
|
||||
key: ValueKey('${archived ? 'a' : 's'}-${session.id}'),
|
||||
endActionPane: ActionPane(
|
||||
@@ -551,7 +581,31 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
leading: child
|
||||
? Icon(Icons.smart_toy_outlined,
|
||||
size: 16, color: scheme.onSurfaceVariant)
|
||||
: null,
|
||||
: children.isEmpty
|
||||
? null
|
||||
: SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
expanded
|
||||
? Icons.expand_more
|
||||
: Icons.chevron_right,
|
||||
size: 18),
|
||||
tooltip: expanded ? '收起子代理' : '展开子代理',
|
||||
padding: EdgeInsets.zero,
|
||||
visualDensity: VisualDensity.compact,
|
||||
constraints:
|
||||
const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
onPressed: () => setState(() {
|
||||
if (expanded) {
|
||||
_expandedChildren.remove(session.id);
|
||||
} else {
|
||||
_expandedChildren.add(session.id);
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
session.title.isEmpty ? '(无标题会话)' : session.title,
|
||||
maxLines: 1,
|
||||
|
||||
Reference in new issue
Block a user