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,126 @@
|
||||
// The composer's model row, shared by the chat and the new-session draft:
|
||||
// the model/agent chip, the thinking level when the model has one, and any
|
||||
// leading chip the screen adds (the draft's project).
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
import '../model_prefs.dart';
|
||||
import '../state.dart';
|
||||
import 'model_picker.dart';
|
||||
|
||||
class ModelControlsBar extends StatelessWidget {
|
||||
final AppState app;
|
||||
final ModelRef? model;
|
||||
final String agent;
|
||||
final ValueChanged<ModelRef> onModel;
|
||||
final ValueChanged<String> onAgent;
|
||||
|
||||
/// Shown first, e.g. the project chip on the draft.
|
||||
final Widget? leading;
|
||||
|
||||
const ModelControlsBar({
|
||||
super.key,
|
||||
required this.app,
|
||||
required this.model,
|
||||
required this.agent,
|
||||
required this.onModel,
|
||||
required this.onAgent,
|
||||
this.leading,
|
||||
});
|
||||
|
||||
ModelInfo? get _info => app.modelInfo(model);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final info = _info;
|
||||
final modelLabel = model == null
|
||||
? '模型'
|
||||
: (agent.isEmpty ? app.modelName(model!) : '${app.modelName(model!)} · $agent');
|
||||
final hasEffort = info != null && info.hasEffort;
|
||||
// The server may name the default level "default"; the picker only knows
|
||||
// the variants the catalog lists, so anything else counts as no effort.
|
||||
final effort = model?.variant != null &&
|
||||
info != null &&
|
||||
info.variants.contains(model!.variant)
|
||||
? model!.variant
|
||||
: null;
|
||||
return Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (leading != null) leading!,
|
||||
_chip(
|
||||
context,
|
||||
icon: Icons.smart_toy_outlined,
|
||||
label: modelLabel,
|
||||
onTap: () => showModelPickerSheet(
|
||||
context,
|
||||
app: app,
|
||||
kind: 'model',
|
||||
model: model,
|
||||
agent: agent,
|
||||
onModel: onModel,
|
||||
onAgent: onAgent,
|
||||
),
|
||||
),
|
||||
if (hasEffort)
|
||||
_chip(
|
||||
context,
|
||||
icon: Icons.psychology_outlined,
|
||||
label: '思考·${effortLabel(effort)}',
|
||||
active: effort != null,
|
||||
onTap: () => showEffortSheet(
|
||||
context,
|
||||
variants: info.variants,
|
||||
value: effort,
|
||||
modelName: info.name,
|
||||
onPick: (variant) => onModel(
|
||||
ModelRef(model!.id, model!.providerId, variant)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chip(BuildContext context,
|
||||
{required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
bool active = false}) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: active
|
||||
? scheme.primary.withValues(alpha: 0.14)
|
||||
: scheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: active ? scheme.primary : theme.hintColor),
|
||||
const SizedBox(width: 4),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 210),
|
||||
child: Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: active ? scheme.primary : theme.hintColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user