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
@@ -0,0 +1,195 @@
|
||||
// The `/` palette above a composer, shared by the chat and the new-session
|
||||
// draft: commands and skills of one directory, filtered as the name is typed.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../state.dart';
|
||||
|
||||
const _slashLabels = {
|
||||
'compact': '压缩',
|
||||
'init': '初始化',
|
||||
'review': '审查',
|
||||
'goal': '目标',
|
||||
'new-extension': '新建扩展',
|
||||
'permission': '权限',
|
||||
'plan': '计划',
|
||||
'feedback': '反馈',
|
||||
};
|
||||
|
||||
String? slashLabel(SlashItem item) =>
|
||||
item.skill ? null : _slashLabels[item.name];
|
||||
|
||||
/// Rows for a draft, or null when the palette should stay closed. It stays
|
||||
/// up while only the command name is typed and closes once an argument
|
||||
/// starts, unless the same text was dismissed with Esc.
|
||||
List<SlashItem>? matchSlashItems({
|
||||
required List<SlashItem> items,
|
||||
required String text,
|
||||
String? dismissed,
|
||||
}) {
|
||||
if (dismissed == text) return null;
|
||||
final trimmed = text.trimLeft();
|
||||
if (!trimmed.startsWith('/')) return null;
|
||||
if (trimmed.length > 1 && RegExp(r'\s').hasMatch(trimmed.substring(1))) {
|
||||
return null;
|
||||
}
|
||||
final query = trimmed.substring(1).toLowerCase().trim();
|
||||
if (query.isEmpty) return items;
|
||||
bool hit(SlashItem item) {
|
||||
final label = slashLabel(item) ?? '';
|
||||
return item.name.toLowerCase().contains(query) ||
|
||||
label.toLowerCase().contains(query) ||
|
||||
item.description.toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
return items.where(hit).toList()
|
||||
..sort((a, b) {
|
||||
final aPrefix = a.name.toLowerCase().startsWith(query) ? 0 : 1;
|
||||
final bPrefix = b.name.toLowerCase().startsWith(query) ? 0 : 1;
|
||||
if (aPrefix != bPrefix) return aPrefix - bPrefix;
|
||||
if (a.skill != b.skill) return a.skill ? 1 : -1;
|
||||
return a.name.compareTo(b.name);
|
||||
});
|
||||
}
|
||||
|
||||
/// The panel itself: rows with an icon, the command and its description.
|
||||
class SlashPalette extends StatelessWidget {
|
||||
final List<SlashItem> items;
|
||||
final int index;
|
||||
final bool loading;
|
||||
final ValueChanged<SlashItem> onPick;
|
||||
|
||||
const SlashPalette({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.index,
|
||||
required this.loading,
|
||||
required this.onPick,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final selected = items.isEmpty ? 0 : index.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
|
||||
? (loading
|
||||
? 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 isSelected = i == selected;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: () => onPick(item),
|
||||
child: Container(
|
||||
height: 56,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? 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: [
|
||||
Text('/${item.name}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: scheme.onSurface)),
|
||||
if (label != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Text(label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant)),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (item.description.isNotEmpty)
|
||||
Text(item.description,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user