fix: switching a session's model, and put the model row in the composer
- POST /api/session/:id/model takes the reference under `model`; sending it at the top level was rejected with "Missing key at [model]". - The chat now shows the model/agent row above the input (revealed while typing or running, as dsh-Go does) instead of in the app bar; the draft keeps the same row, with its project chip first. - Thinking levels: /api/model's variants become a 思考 chip and sheet; the choice travels as ModelRef.variant on the switch or the create, and the last level per model is remembered on the device. - The model picker groups providers, adds 收藏 and 最近 (device-local), shows each model's context size and reasoning mark, and collapses sections. - The `/` palette is shared by the chat and the draft (new slash_palette widget); the draft lists commands and skills but not the client-local /compact, which needs an existing session. - 0.3.14 (314).
This commit is contained in:
1 parent
fff6562cbc
commit
7f2f454539
12 files changed
+962
-344
No files matched your search
+37
-216
@@ -11,7 +11,8 @@ import '../api/models.dart';
|
||||
import '../state.dart';
|
||||
import '../widgets/composer_attachment.dart';
|
||||
import '../widgets/markdown_view.dart';
|
||||
import '../widgets/model_picker.dart';
|
||||
import '../widgets/model_controls.dart';
|
||||
import '../widgets/slash_palette.dart';
|
||||
import '../widgets/usage_ring.dart';
|
||||
import 'files_panel.dart';
|
||||
|
||||
@@ -61,6 +62,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
chat.addListener(_onChat);
|
||||
_inputFocus.addListener(_onFocusChanged);
|
||||
// The list is reversed: offset 0 is the newest message (the bottom), and
|
||||
// older pages grow above without moving what is on screen.
|
||||
_scroll.addListener(() {
|
||||
@@ -86,9 +88,14 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onFocusChanged() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
chat.removeListener(_onChat);
|
||||
_inputFocus.removeListener(_onFocusChanged);
|
||||
_draftCtrl.dispose();
|
||||
_inputFocus.dispose();
|
||||
_scroll.dispose();
|
||||
@@ -109,27 +116,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
title: Text(_title(), maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: ActionChip(
|
||||
visualDensity: VisualDensity.compact,
|
||||
avatar: const Icon(Icons.smart_toy_outlined, size: 16),
|
||||
label: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 120),
|
||||
child: Text(_modelLabel(),
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
onPressed: () => showModelPickerSheet(
|
||||
context,
|
||||
app: widget.app,
|
||||
kind: 'model',
|
||||
model: chat.selectedModel ?? widget.session.model,
|
||||
agent: chat.selectedAgent,
|
||||
onModel: (m) => chat.switchModel(m),
|
||||
onAgent: (a) => chat.switchAgent(a),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.view_sidebar_outlined),
|
||||
tooltip: '文件',
|
||||
@@ -1283,49 +1269,14 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
// composer.dart, referenced rather than copied).
|
||||
/// Chinese faces for the first-party commands, as dsh-Go shows them; the
|
||||
/// registry's name is what is sent.
|
||||
static const _slashLabels = {
|
||||
'compact': '压缩',
|
||||
'init': '初始化',
|
||||
'review': '审查',
|
||||
'goal': '目标',
|
||||
'new-extension': '新建扩展',
|
||||
'permission': '权限',
|
||||
'plan': '计划',
|
||||
'feedback': '反馈',
|
||||
};
|
||||
|
||||
static String? _slashLabel(SlashItem item) =>
|
||||
item.skill ? null : _slashLabels[item.name];
|
||||
|
||||
/// Rows for the current draft, or null when the palette is closed. It
|
||||
/// stays up while the command name is being typed and closes once an
|
||||
/// argument has started.
|
||||
List<SlashItem>? _slashMatches() {
|
||||
final text = _draftCtrl.text;
|
||||
if (_slashDismissed == text) return null;
|
||||
final t = text.trimLeft();
|
||||
if (!t.startsWith('/')) return null;
|
||||
if (t.length > 1 && RegExp(r'\s').hasMatch(t.substring(1))) return null;
|
||||
final q = t.substring(1).toLowerCase().trim();
|
||||
final all = chat.slashItems;
|
||||
if (q.isEmpty) return all;
|
||||
bool hit(SlashItem e) {
|
||||
final label = _slashLabel(e) ?? '';
|
||||
return e.name.toLowerCase().contains(q) ||
|
||||
label.toLowerCase().contains(q) ||
|
||||
e.description.toLowerCase().contains(q);
|
||||
}
|
||||
|
||||
final matches = all.where(hit).toList()
|
||||
..sort((a, b) {
|
||||
final ap = a.name.toLowerCase().startsWith(q) ? 0 : 1;
|
||||
final bp = b.name.toLowerCase().startsWith(q) ? 0 : 1;
|
||||
if (ap != bp) return ap - bp;
|
||||
if (a.skill != b.skill) return a.skill ? 1 : -1;
|
||||
return a.name.compareTo(b.name);
|
||||
});
|
||||
return matches;
|
||||
}
|
||||
List<SlashItem>? _slashMatches() => matchSlashItems(
|
||||
items: chat.slashItems,
|
||||
text: _draftCtrl.text,
|
||||
dismissed: _slashDismissed,
|
||||
);
|
||||
|
||||
void _moveSlash(List<SlashItem> items, int delta) {
|
||||
if (items.isEmpty) return;
|
||||
@@ -1373,153 +1324,19 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
/// The palette above the composer: dsh-Go's `/` menu, on the app's theme.
|
||||
Widget _slashPalette(List<SlashItem> items) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final typed = _draftCtrl.text.trimLeft().length > 1;
|
||||
final index = items.isEmpty ? 0 : _slashIndex.clamp(0, items.length - 1);
|
||||
Widget row(IconData icon, String title, String subtitle) => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 14, 14, 14),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
child: Icon(icon, size: 20, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
style: TextStyle(
|
||||
fontSize: 14, color: scheme.onSurface)),
|
||||
if (subtitle.isNotEmpty)
|
||||
Text(subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: scheme.onSurfaceVariant)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return Container(
|
||||
constraints: const BoxConstraints(maxHeight: 56 * 5.5),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: scheme.outlineVariant.withValues(alpha: 0.6)),
|
||||
),
|
||||
child: items.isEmpty
|
||||
? (chat.slashLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
),
|
||||
)
|
||||
: row(Icons.search_off, '没有可用的指令', '这个目录还没有注册指令或技能'))
|
||||
: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 6),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, i) {
|
||||
final item = items[i];
|
||||
final label = _slashLabel(item);
|
||||
final selected = i == index;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: () => _pickSlash(item),
|
||||
child: Container(
|
||||
height: 56,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
selected ? scheme.primary.withValues(alpha: 0.10) : null,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
child: Icon(
|
||||
item.skill
|
||||
? Icons.extension_outlined
|
||||
: Icons.terminal,
|
||||
size: 20,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
if (label != null) ...[
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500)),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Flexible(
|
||||
child: Text('/${item.name}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant)),
|
||||
),
|
||||
if (item.skill) ...[
|
||||
const SizedBox(width: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.secondaryContainer,
|
||||
borderRadius:
|
||||
BorderRadius.circular(6),
|
||||
),
|
||||
child: Text('技能',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color:
|
||||
scheme.onSecondaryContainer)),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (item.description.isNotEmpty)
|
||||
Text(item.description,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (selected && typed)
|
||||
Icon(Icons.keyboard_return,
|
||||
size: 16, color: scheme.onSurfaceVariant),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget _slashPalette(List<SlashItem> items) => SlashPalette(
|
||||
items: items,
|
||||
index: _slashIndex,
|
||||
loading: chat.slashLoading,
|
||||
onPick: _pickSlash,
|
||||
);
|
||||
|
||||
/// dsh-Go shows the model row while the input is in use; an empty, idle
|
||||
/// composer leaves the space to the messages.
|
||||
bool _showModelControls() =>
|
||||
_inputFocus.hasFocus ||
|
||||
_draftCtrl.text.trim().isNotEmpty ||
|
||||
chat.running;
|
||||
|
||||
Widget _composer() {
|
||||
final usage = chat.usageReading();
|
||||
@@ -1532,6 +1349,16 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_showModelControls()) ...[
|
||||
ModelControlsBar(
|
||||
app: widget.app,
|
||||
model: chat.selectedModel ?? widget.session.model,
|
||||
agent: chat.selectedAgent,
|
||||
onModel: (m) => chat.switchModel(m),
|
||||
onAgent: (a) => chat.switchAgent(a),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
if (_attachments.isNotEmpty) _attachmentTray(),
|
||||
if (slash != null) ...[
|
||||
KeyedSubtree(
|
||||
@@ -1716,13 +1543,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
onRemove: (i) => setState(() => _attachments.removeAt(i)),
|
||||
);
|
||||
|
||||
String _modelLabel() {
|
||||
final m = chat.selectedModel ?? widget.session.model;
|
||||
final model = m == null ? '模型' : widget.app.modelName(m);
|
||||
final agent = chat.selectedAgent;
|
||||
return agent.isEmpty ? model : '$model · $agent';
|
||||
}
|
||||
|
||||
Future<void> _send() async {
|
||||
final text = _draftCtrl.text.trim();
|
||||
if (text.isEmpty && _attachments.isEmpty) return;
|
||||
@@ -1771,6 +1591,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------- permissions
|
||||
|
||||
/// The agent's blocking questions sit just above the composer, like the
|
||||
|
||||
Reference in new issue
Block a user