2026-11-21 17:47:04 +08:00
|
|
|
// The composer's two controls: the model pill (model and thinking level in
|
|
|
|
|
// one group) and, separately, the mode (Build / Plan).
|
2026-11-21 17:03:22 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import '../api/models.dart';
|
|
|
|
|
import '../model_prefs.dart';
|
|
|
|
|
import '../state.dart';
|
|
|
|
|
import 'model_picker.dart';
|
2026-11-26 09:04:25 +08:00
|
|
|
import '../l10n.dart';
|
2026-11-21 17:03:22 +08:00
|
|
|
|
2026-11-21 17:47:04 +08:00
|
|
|
/// `deepseek-flash · 高` — model and effort together, as dsh-Go shows them.
|
|
|
|
|
class ModelPill extends StatelessWidget {
|
2026-11-21 17:03:22 +08:00
|
|
|
final AppState app;
|
|
|
|
|
final ModelRef? model;
|
|
|
|
|
final ValueChanged<ModelRef> onModel;
|
|
|
|
|
|
2026-11-21 17:47:04 +08:00
|
|
|
const ModelPill({
|
2026-11-21 17:03:22 +08:00
|
|
|
super.key,
|
|
|
|
|
required this.app,
|
|
|
|
|
required this.model,
|
|
|
|
|
required this.onModel,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-11-21 17:47:04 +08:00
|
|
|
final info = app.modelInfo(model);
|
|
|
|
|
// The server may name the default level "default"; only a level the
|
|
|
|
|
// catalog lists counts as a choice.
|
2026-11-21 17:03:22 +08:00
|
|
|
final effort = model?.variant != null &&
|
|
|
|
|
info != null &&
|
|
|
|
|
info.variants.contains(model!.variant)
|
|
|
|
|
? model!.variant
|
|
|
|
|
: null;
|
2026-11-26 11:48:16 +08:00
|
|
|
final name = model == null ? 'Model' : app.modelName(model!);
|
2026-11-21 17:47:04 +08:00
|
|
|
final label = effort == null ? name : '$name · ${effortLabel(effort)}';
|
|
|
|
|
return _Pill(
|
|
|
|
|
icon: Icons.smart_toy_outlined,
|
|
|
|
|
label: label,
|
|
|
|
|
onTap: () => showModelPickerSheet(
|
|
|
|
|
context,
|
|
|
|
|
app: app,
|
|
|
|
|
model: model,
|
|
|
|
|
onModel: onModel,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The mode is its own control: Build or Plan, not part of the model.
|
|
|
|
|
class ModeChip extends StatelessWidget {
|
|
|
|
|
final AppState app;
|
|
|
|
|
final String agent;
|
|
|
|
|
final ValueChanged<String> onAgent;
|
|
|
|
|
|
|
|
|
|
const ModeChip({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.app,
|
|
|
|
|
required this.agent,
|
|
|
|
|
required this.onAgent,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
static const _modes = ['build', 'plan'];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final current = agent.isEmpty ? _modes.first : agent;
|
2026-11-21 18:32:57 +08:00
|
|
|
return _Pill(
|
|
|
|
|
icon: Icons.tune,
|
|
|
|
|
label: _label(current),
|
|
|
|
|
onTap: () => _open(context, current),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _open(BuildContext context, String current) async {
|
|
|
|
|
final known = [
|
|
|
|
|
for (final a in app.agentList)
|
|
|
|
|
if (a.mode == 'primary' && !a.hidden) a,
|
|
|
|
|
];
|
|
|
|
|
final ids = <String>{..._modes, for (final a in known) a.id};
|
|
|
|
|
final names = {for (final a in known) a.id: a.name};
|
|
|
|
|
final scheme = Theme.of(context).colorScheme;
|
|
|
|
|
final picked = await showModalBottomSheet<String>(
|
|
|
|
|
context: context,
|
|
|
|
|
showDragHandle: true,
|
|
|
|
|
builder: (sheet) => SafeArea(
|
|
|
|
|
top: false,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
const Padding(
|
|
|
|
|
padding: EdgeInsets.fromLTRB(20, 4, 20, 8),
|
2026-11-26 11:48:16 +08:00
|
|
|
child: AppText('Mode',
|
2026-11-21 18:32:57 +08:00
|
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
2026-11-21 17:03:22 +08:00
|
|
|
),
|
2026-11-21 18:32:57 +08:00
|
|
|
for (final id in ids)
|
|
|
|
|
ListTile(
|
|
|
|
|
leading: Icon(
|
|
|
|
|
id == 'plan' ? Icons.map_outlined : Icons.construction_outlined,
|
|
|
|
|
color: id == current ? scheme.primary : null,
|
|
|
|
|
),
|
2026-11-26 09:04:25 +08:00
|
|
|
title: AppText(
|
2026-11-21 18:32:57 +08:00
|
|
|
names[id]?.isNotEmpty == true ? names[id]! : _label(id),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontWeight: id == current ? FontWeight.w700 : FontWeight.w400,
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-11-26 11:48:16 +08:00
|
|
|
subtitle: AppText(id == 'plan' ? 'Plan first without changing files' : 'Build directly',
|
2026-11-21 18:32:57 +08:00
|
|
|
style: const TextStyle(fontSize: 12)),
|
|
|
|
|
trailing: id == current
|
|
|
|
|
? Icon(Icons.check, size: 20, color: scheme.primary)
|
|
|
|
|
: null,
|
|
|
|
|
onTap: () => Navigator.pop(sheet, id),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-11-21 17:47:04 +08:00
|
|
|
),
|
2026-11-21 17:03:22 +08:00
|
|
|
);
|
2026-11-21 18:32:57 +08:00
|
|
|
if (picked != null && picked != current) onAgent(picked);
|
2026-11-21 17:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
2026-11-21 17:47:04 +08:00
|
|
|
static String _label(String id) =>
|
|
|
|
|
id.isEmpty ? 'Build' : id[0].toUpperCase() + id.substring(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _Pill extends StatelessWidget {
|
|
|
|
|
final IconData icon;
|
|
|
|
|
final String label;
|
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
|
|
|
|
|
|
const _Pill({required this.icon, required this.label, this.onTap});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-11-21 17:03:22 +08:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
final scheme = theme.colorScheme;
|
|
|
|
|
return InkWell(
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
child: Container(
|
2026-11-21 17:47:04 +08:00
|
|
|
constraints: const BoxConstraints(minHeight: 30),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
|
color: scheme.onSurface.withValues(alpha: 0.07),
|
|
|
|
|
shape: const StadiumBorder(),
|
2026-11-21 17:03:22 +08:00
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
2026-11-21 17:47:04 +08:00
|
|
|
Icon(icon, size: 14, color: theme.hintColor),
|
2026-11-21 17:03:22 +08:00
|
|
|
const SizedBox(width: 4),
|
2026-11-21 17:47:04 +08:00
|
|
|
Flexible(
|
2026-11-26 11:48:16 +08:00
|
|
|
child: Text(
|
2026-11-21 17:03:22 +08:00
|
|
|
label,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
style: TextStyle(
|
2026-11-21 17:47:04 +08:00
|
|
|
fontSize: 12.5,
|
|
|
|
|
color: scheme.onSurface,
|
2026-11-21 17:03:22 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|