ui: fold the composer to one line until it has focus
dsh-Go opens the input into two rows only while focused: the text above, the model / mode / keys below, folding back when focus leaves. ComposerBox keeps the field across the two layouts with a GlobalKey and animates the swap. Model and thinking level are now one control (ModelPill shows "model · effort" and the sheet offers the level after choosing a model); Build/Plan is a separate ModeChip. The draft page uses the same box, with its project chip above it. 0.3.15 (315).
This commit is contained in:
1 parent
7f2f454539
commit
ea3b1f0f5e
8 files changed
+553
-430
No files matched your search
+87
-129
@@ -1,6 +1,6 @@
|
||||
// The model / agent picker, shared by the chat composer and the new-session
|
||||
// draft: favourites, recents, models grouped by provider with their context
|
||||
// size, and the thinking level of the chosen model.
|
||||
// The model picker: favourites, recents, models grouped by provider with their
|
||||
// context size, and — when a model has them — its thinking levels, chosen in
|
||||
// the same sheet because model and effort are one selection.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
@@ -10,11 +10,8 @@ import '../state.dart';
|
||||
Future<void> showModelPickerSheet(
|
||||
BuildContext context, {
|
||||
required AppState app,
|
||||
required String kind,
|
||||
required ModelRef? model,
|
||||
required String agent,
|
||||
required ValueChanged<ModelRef> onModel,
|
||||
required ValueChanged<String> onAgent,
|
||||
}) async {
|
||||
app.refreshModels();
|
||||
await ModelPrefs.instance.ensureLoaded();
|
||||
@@ -28,61 +25,9 @@ Future<void> showModelPickerSheet(
|
||||
maxChildSize: 0.95,
|
||||
builder: (context, controller) => _PickerSheet(
|
||||
app: app,
|
||||
kind: kind,
|
||||
model: model,
|
||||
agent: agent,
|
||||
scrollController: controller,
|
||||
onModel: onModel,
|
||||
onAgent: onAgent,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The thinking levels of one model, as a small sheet.
|
||||
Future<void> showEffortSheet(
|
||||
BuildContext context, {
|
||||
required List<String> variants,
|
||||
required String? value,
|
||||
required String modelName,
|
||||
required ValueChanged<String?> onPick,
|
||||
}) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 2),
|
||||
child: Text('思考强度',
|
||||
style:
|
||||
const TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Text(modelName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: Theme.of(context).hintColor)),
|
||||
),
|
||||
for (final option in <String?>[null, ...variants])
|
||||
ListTile(
|
||||
dense: true,
|
||||
title: Text(effortLabel(option)),
|
||||
trailing: (value ?? '') == (option ?? '')
|
||||
? Icon(Icons.check,
|
||||
size: 18, color: Theme.of(context).colorScheme.primary)
|
||||
: null,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
onPick(option);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -90,21 +35,15 @@ Future<void> showEffortSheet(
|
||||
|
||||
class _PickerSheet extends StatefulWidget {
|
||||
final AppState app;
|
||||
final String kind;
|
||||
final ModelRef? model;
|
||||
final String agent;
|
||||
final ScrollController scrollController;
|
||||
final ValueChanged<ModelRef> onModel;
|
||||
final ValueChanged<String> onAgent;
|
||||
|
||||
const _PickerSheet({
|
||||
required this.app,
|
||||
required this.kind,
|
||||
required this.model,
|
||||
required this.agent,
|
||||
required this.scrollController,
|
||||
required this.onModel,
|
||||
required this.onAgent,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -112,10 +51,14 @@ class _PickerSheet extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PickerSheetState extends State<_PickerSheet> {
|
||||
late String _kind = widget.kind;
|
||||
String _filter = '';
|
||||
final Set<String> _collapsed = {};
|
||||
|
||||
/// The model whose thinking level the bottom panel is offering; null hides
|
||||
/// the panel.
|
||||
ModelInfo? _effortModel;
|
||||
String? _effortVariant;
|
||||
|
||||
ModelPrefs get _prefs => ModelPrefs.instance;
|
||||
|
||||
@override
|
||||
@@ -124,26 +67,10 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
listenable: widget.app,
|
||||
builder: (context, _) => Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 4),
|
||||
child: Text(_kind == 'agent' ? '选择智能体' : '选择模型',
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: SegmentedButton<String>(
|
||||
segments: const [
|
||||
ButtonSegment(value: 'model', label: Text('模型')),
|
||||
ButtonSegment(value: 'agent', label: Text('智能体')),
|
||||
],
|
||||
selected: {_kind},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: (s) {
|
||||
setState(() => _kind = s.first);
|
||||
widget.app.refreshModels();
|
||||
},
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(12, 12, 12, 4),
|
||||
child: Text('选择模型',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
@@ -155,48 +82,15 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
isDense: true),
|
||||
),
|
||||
),
|
||||
Expanded(child: _kind == 'agent' ? _agents() : _models()),
|
||||
Expanded(child: _models()),
|
||||
if (_effortModel != null) _effortPanel(_effortModel!),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- agents
|
||||
|
||||
Widget _agents() {
|
||||
final filter = _filter.toLowerCase();
|
||||
final agents = [
|
||||
for (final a in widget.app.agentList)
|
||||
if (a.mode == 'primary' && !a.hidden)
|
||||
if (filter.isEmpty || a.name.toLowerCase().contains(filter)) a,
|
||||
];
|
||||
if (agents.isEmpty) return const Center(child: Text('没有结果'));
|
||||
return ListView.builder(
|
||||
controller: widget.scrollController,
|
||||
itemCount: agents.length,
|
||||
itemBuilder: (context, i) {
|
||||
final agent = agents[i];
|
||||
return ListTile(
|
||||
dense: true,
|
||||
title: Text(agent.name),
|
||||
trailing: widget.agent == agent.id
|
||||
? Icon(Icons.check,
|
||||
size: 18, color: Theme.of(context).colorScheme.primary)
|
||||
: null,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
widget.onAgent(agent.id);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- models
|
||||
|
||||
Widget _models() {
|
||||
final app = widget.app;
|
||||
final all = app.modelList;
|
||||
final all = widget.app.modelList;
|
||||
if (all.isEmpty) {
|
||||
return const Center(child: Text('正在载入模型…'));
|
||||
}
|
||||
@@ -218,11 +112,10 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
for (final key in _prefs.favorites)
|
||||
if (byKey[key] != null) byKey[key]!,
|
||||
]..sort((a, b) => a.name.compareTo(b.name));
|
||||
final recentKeys = [
|
||||
final recents = [
|
||||
for (final key in _prefs.recents)
|
||||
if (byKey[key] != null && !_prefs.favorites.contains(key)) key,
|
||||
if (byKey[key] != null && !_prefs.favorites.contains(key)) byKey[key]!,
|
||||
];
|
||||
final recents = [for (final key in recentKeys) byKey[key]!];
|
||||
|
||||
final providers = <String, List<ModelInfo>>{};
|
||||
for (final model in matching) {
|
||||
@@ -258,10 +151,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return ListView(
|
||||
controller: widget.scrollController,
|
||||
children: children,
|
||||
);
|
||||
return ListView(controller: widget.scrollController, children: children);
|
||||
}
|
||||
|
||||
Widget _sectionHeader(String label, String key, {int? count}) {
|
||||
@@ -360,7 +250,75 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
: null;
|
||||
await _prefs.rememberModel(key);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
// Model and effort are one choice: apply the model with its remembered
|
||||
// level, then let the level be changed without leaving the sheet.
|
||||
widget.onModel(ModelRef(model.id, model.providerId, variant));
|
||||
if (model.hasEffort) {
|
||||
setState(() {
|
||||
_effortModel = model;
|
||||
_effortVariant = variant;
|
||||
});
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickEffort(ModelInfo model, String? variant) async {
|
||||
final key = ModelPrefs.keyFor(model.providerId, model.id);
|
||||
await _prefs.rememberEffort(key, variant);
|
||||
widget.onModel(ModelRef(model.id, model.providerId, variant));
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
Widget _effortPanel(ModelInfo model) {
|
||||
final theme = Theme.of(context);
|
||||
final options = <String?>[null, ...model.variants];
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: theme.dividerColor.withValues(alpha: 0.6))),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('思考强度',
|
||||
style: TextStyle(
|
||||
fontSize: 13, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(model.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('完成'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
for (final option in options)
|
||||
ChoiceChip(
|
||||
label: Text(effortLabel(option),
|
||||
style: const TextStyle(fontSize: 12.5)),
|
||||
selected: (_effortVariant ?? '') == (option ?? ''),
|
||||
onSelected: (_) => _pickEffort(model, option),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user