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
+456
-333
No files matched your search
@@ -5,6 +5,17 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 0.3.15 输入框两行折叠、模型与思考成组、模式独立(分支 `flutter`)
|
||||||
|
|
||||||
|
| 项 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 输入框折叠动画 | 新增 `lib/widgets/composer_box.dart`:未获焦点时是单行(附件键在左、输入框、上下文环、发送键在右),获得焦点时平滑展开为两行(上为输入框,下为附件键/模型/模式/环/发送键),失焦后收回单行;输入框用 `GlobalKey` 在两种布局间搬移,保留焦点与输入连接。参照 dsh-Go `Composer` 的 `footer` + `_ComposerRows` + `AnimationController` 做法 |
|
||||||
|
| 模型与思考强度成组 | 模型 chip 直接显示 `模型 · 思考档位`(如 `deepseek-flash · 高`),点开同一个面板:选模型后若该模型有 variants,底部出现思考强度选择,选完一次提交;最近使用的档位记在本机。草稿页与聊天页共用 `ModelPill` |
|
||||||
|
| 模式独立 | 原「智能体」chip 改为独立的 `ModeChip`(Build / Plan),与模型 chip 并列,不再把智能体与模型放在同一行组里;仍通过 `switchAgent` / 草稿的 `agent` 提交 |
|
||||||
|
| 草稿页 | 同样使用两行折叠 `ComposerBox`;项目 chip 单独在输入框上方始终可见(草稿页没有会话,模型/模式放在折叠的第二行);斜杠面板、快捷键保持不变 |
|
||||||
|
| 版本 | **0.3.15(code 315)** |
|
||||||
|
---
|
||||||
|
|
||||||
## 0.3.14 模型切换修复、输入框模型行、思考强度与模型面板(分支 `flutter`)
|
## 0.3.14 模型切换修复、输入框模型行、思考强度与模型面板(分支 `flutter`)
|
||||||
|
|
||||||
| 项 | 结果 |
|
| 项 | 结果 |
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
|
|||||||
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
||||||
Flutter to compare mobile UI maturity.
|
Flutter to compare mobile UI maturity.
|
||||||
|
|
||||||
Status: 0.3.14 — servers (passwordless / password login, HTTP/HTTPS and
|
Status: 0.3.15 — servers (passwordless / password login, HTTP/HTTPS and
|
||||||
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
|
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
|
||||||
events, chat with streaming Markdown and full history paging, tool steps
|
events, chat with streaming Markdown and full history paging, tool steps
|
||||||
grouped per turn (icon, one-line summary, foldable run) with image previews, a
|
grouped per turn (icon, one-line summary, foldable run) with image previews, a
|
||||||
@@ -18,8 +18,9 @@ show their progress and can be cancelled. The panel is a tab row with its own
|
|||||||
close button, and each tab has its own header row. Starting a session opens a
|
close button, and each tab has its own header row. Starting a session opens a
|
||||||
draft that only creates the session on the first send; the session list is
|
draft that only creates the session on the first send; the session list is
|
||||||
grouped by project with date captions, pins, archive and swipe actions. The
|
grouped by project with date captions, pins, archive and swipe actions. The
|
||||||
model and thinking level sit in the composer (revealed while typing), and the
|
composer folds to one line when unfocused and opens into two rows on focus (as
|
||||||
picker groups providers, favourites, recents and context size. A
|
in dsh-Go): the model and its thinking level form one pill, the Build/Plan mode
|
||||||
|
a separate chip. The picker groups providers, favourites, recents and context size. A
|
||||||
phone opens the session list as the left drawer and a wide window (tablet,
|
phone opens the session list as the left drawer and a wide window (tablet,
|
||||||
desktop) shows it beside the chat. Android 7.0 (API 24)+, plus a Linux desktop
|
desktop) shows it beside the chat. Android 7.0 (API 24)+, plus a Linux desktop
|
||||||
target used for local testing.
|
target used for local testing.
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import '../api/models.dart';
|
|||||||
import '../state.dart';
|
import '../state.dart';
|
||||||
import '../widgets/composer_attachment.dart';
|
import '../widgets/composer_attachment.dart';
|
||||||
import '../widgets/markdown_view.dart';
|
import '../widgets/markdown_view.dart';
|
||||||
|
import '../widgets/composer_box.dart';
|
||||||
import '../widgets/model_controls.dart';
|
import '../widgets/model_controls.dart';
|
||||||
import '../widgets/slash_palette.dart';
|
import '../widgets/slash_palette.dart';
|
||||||
import '../widgets/usage_ring.dart';
|
import '../widgets/usage_ring.dart';
|
||||||
@@ -1331,13 +1332,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
onPick: _pickSlash,
|
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() {
|
Widget _composer() {
|
||||||
final usage = chat.usageReading();
|
final usage = chat.usageReading();
|
||||||
final scheme = Theme.of(context).colorScheme;
|
final scheme = Theme.of(context).colorScheme;
|
||||||
@@ -1349,16 +1343,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
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 (_attachments.isNotEmpty) _attachmentTray(),
|
||||||
if (slash != null) ...[
|
if (slash != null) ...[
|
||||||
KeyedSubtree(
|
KeyedSubtree(
|
||||||
@@ -1367,36 +1351,15 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
],
|
],
|
||||||
Container(
|
ComposerBox(
|
||||||
key: const ValueKey('composer-bar'),
|
|
||||||
padding: const EdgeInsets.all(6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: scheme.surfaceContainerHighest,
|
|
||||||
borderRadius: BorderRadius.circular(26),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
_roundKey(
|
|
||||||
icon: Icons.attach_file,
|
|
||||||
label: '添加附件',
|
|
||||||
onTap: _pickFiles,
|
|
||||||
busy: _attaching,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
controller: _draftCtrl,
|
controller: _draftCtrl,
|
||||||
focusNode: _inputFocus,
|
focusNode: _inputFocus,
|
||||||
minLines: 1,
|
hint: chat.running ? '生成中,仍可输入…' : '发消息…',
|
||||||
maxLines: 5,
|
maxLines: 5,
|
||||||
keyboardType: TextInputType.multiline,
|
// While the palette is up, the keyboard's action key picks the
|
||||||
// While the palette is up, the keyboard's action key
|
// highlighted row instead of writing a newline.
|
||||||
// picks the highlighted row instead of writing a
|
textInputAction:
|
||||||
// newline.
|
slash != null ? TextInputAction.send : TextInputAction.newline,
|
||||||
textInputAction: slash != null
|
|
||||||
? TextInputAction.send
|
|
||||||
: TextInputAction.newline,
|
|
||||||
onSubmitted: slash == null || slashRows.isEmpty
|
onSubmitted: slash == null || slashRows.isEmpty
|
||||||
? null
|
? null
|
||||||
: (_) => _pickSlash(
|
: (_) => _pickSlash(
|
||||||
@@ -1409,15 +1372,14 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
}
|
}
|
||||||
if (v.trimLeft().startsWith('/')) chat.ensureSlash();
|
if (v.trimLeft().startsWith('/')) chat.ensureSlash();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
// A soft keyboard whose action key still writes a
|
// A soft keyboard whose action key still writes a newline
|
||||||
// newline commits the highlighted row instead of
|
// commits the highlighted row instead of leaving a stray blank
|
||||||
// leaving a stray blank line in the draft.
|
// line in the draft.
|
||||||
if (slash != null && v.endsWith('\n')) {
|
if (slash != null && v.endsWith('\n')) {
|
||||||
final trimmed = v.trimRight();
|
final trimmed = v.trimRight();
|
||||||
_draftCtrl.value = TextEditingValue(
|
_draftCtrl.value = TextEditingValue(
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
selection:
|
selection: TextSelection.collapsed(offset: trimmed.length),
|
||||||
TextSelection.collapsed(offset: trimmed.length),
|
|
||||||
);
|
);
|
||||||
chat.draft = trimmed;
|
chat.draft = trimmed;
|
||||||
final rows = _slashMatches() ?? const <SlashItem>[];
|
final rows = _slashMatches() ?? const <SlashItem>[];
|
||||||
@@ -1426,43 +1388,54 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: const TextStyle(fontSize: 15, height: 1.45),
|
leading: _roundKey(
|
||||||
decoration: InputDecoration(
|
icon: Icons.attach_file,
|
||||||
hintText: chat.running ? '生成中,仍可输入…' : '发消息…',
|
label: '添加附件',
|
||||||
hintMaxLines: 1,
|
onTap: _pickFiles,
|
||||||
isDense: true,
|
busy: _attaching,
|
||||||
border: InputBorder.none,
|
|
||||||
contentPadding: const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
),
|
||||||
|
model: ModelPill(
|
||||||
|
app: widget.app,
|
||||||
|
model: chat.selectedModel ?? widget.session.model,
|
||||||
|
onModel: (m) => chat.switchModel(m),
|
||||||
),
|
),
|
||||||
|
mode: ModeChip(
|
||||||
|
app: widget.app,
|
||||||
|
agent: chat.selectedAgent,
|
||||||
|
onAgent: (a) => chat.switchAgent(a),
|
||||||
),
|
),
|
||||||
if (usage.$5)
|
accessory: usage.$5
|
||||||
InkWell(
|
? InkWell(
|
||||||
onTap: () => _usageSheet(context),
|
onTap: () => _usageSheet(context),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
UsageRing(pct: usage.$4, size: 16, accent: scheme.primary),
|
UsageRing(
|
||||||
|
pct: usage.$4,
|
||||||
|
size: 16,
|
||||||
|
accent: scheme.primary),
|
||||||
const SizedBox(width: 3),
|
const SizedBox(width: 3),
|
||||||
Text('${usage.$4.round()}%',
|
Text('${usage.$4.round()}%',
|
||||||
style: TextStyle(fontSize: 12, color: scheme.onSurfaceVariant)),
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: scheme.onSurfaceVariant)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
const SizedBox(width: 2),
|
: null,
|
||||||
_roundKey(
|
trailing: _roundKey(
|
||||||
icon: chat.running ? Icons.stop_rounded : Icons.arrow_upward_rounded,
|
icon: chat.running
|
||||||
|
? Icons.stop_rounded
|
||||||
|
: Icons.arrow_upward_rounded,
|
||||||
label: chat.running ? '停止' : '发送',
|
label: chat.running ? '停止' : '发送',
|
||||||
filled: true,
|
filled: true,
|
||||||
enabled: chat.running || canSend,
|
enabled: chat.running || canSend,
|
||||||
onTap: chat.running ? chat.stop : _send,
|
onTap: chat.running ? chat.stop : _send,
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
|||||||
import '../api/models.dart';
|
import '../api/models.dart';
|
||||||
import '../state.dart';
|
import '../state.dart';
|
||||||
import '../widgets/composer_attachment.dart';
|
import '../widgets/composer_attachment.dart';
|
||||||
|
import '../widgets/composer_box.dart';
|
||||||
import '../widgets/model_controls.dart';
|
import '../widgets/model_controls.dart';
|
||||||
import '../widgets/slash_palette.dart';
|
import '../widgets/slash_palette.dart';
|
||||||
import 'files_panel.dart';
|
import 'files_panel.dart';
|
||||||
@@ -244,16 +245,11 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
|||||||
fontSize: 12.5, color: scheme.error),
|
fontSize: 12.5, color: scheme.error),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ModelControlsBar(
|
Align(
|
||||||
app: widget.app,
|
alignment: Alignment.centerLeft,
|
||||||
model: draft.model,
|
child: _projectChip(draft),
|
||||||
agent: draft.agent,
|
|
||||||
leading: _projectChip(draft),
|
|
||||||
onModel: (m) => widget.app.updateDraftModel(m),
|
|
||||||
onAgent: (a) =>
|
|
||||||
widget.app.updateDraftModel(null, agent: a),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 4),
|
||||||
if (_attachments.isNotEmpty)
|
if (_attachments.isNotEmpty)
|
||||||
AttachmentTray(
|
AttachmentTray(
|
||||||
items: _attachments,
|
items: _attachments,
|
||||||
@@ -305,32 +301,13 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
|||||||
final sending = widget.app.sendingDraft;
|
final sending = widget.app.sendingDraft;
|
||||||
final slash = _slashMatches();
|
final slash = _slashMatches();
|
||||||
final slashRows = slash ?? const <SlashItem>[];
|
final slashRows = slash ?? const <SlashItem>[];
|
||||||
Widget body = Container(
|
Widget body = ComposerBox(
|
||||||
padding: const EdgeInsets.all(6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: scheme.surfaceContainerHighest,
|
|
||||||
borderRadius: BorderRadius.circular(26),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
_roundKey(
|
|
||||||
icon: Icons.attach_file,
|
|
||||||
label: '添加附件',
|
|
||||||
onTap: _pickFiles,
|
|
||||||
busy: _attaching,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
controller: _text,
|
controller: _text,
|
||||||
focusNode: _inputFocus,
|
focusNode: _inputFocus,
|
||||||
minLines: 1,
|
hint: '规划、构建或提问',
|
||||||
maxLines: 5,
|
maxLines: 5,
|
||||||
keyboardType: TextInputType.multiline,
|
textInputAction:
|
||||||
textInputAction: slash != null
|
slash != null ? TextInputAction.send : TextInputAction.newline,
|
||||||
? TextInputAction.send
|
|
||||||
: TextInputAction.newline,
|
|
||||||
onSubmitted: slash == null || slashRows.isEmpty
|
onSubmitted: slash == null || slashRows.isEmpty
|
||||||
? null
|
? null
|
||||||
: (_) => _pickSlash(
|
: (_) => _pickSlash(
|
||||||
@@ -356,17 +333,43 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
decoration: const InputDecoration(
|
leading: _roundKey(
|
||||||
isCollapsed: true,
|
icon: Icons.attach_file,
|
||||||
border: InputBorder.none,
|
label: '添加附件',
|
||||||
hintText: '规划、构建或提问',
|
onTap: _pickFiles,
|
||||||
contentPadding: EdgeInsets.symmetric(vertical: 8),
|
busy: _attaching,
|
||||||
),
|
),
|
||||||
|
model: ModelPill(
|
||||||
|
app: widget.app,
|
||||||
|
model: _draft.model,
|
||||||
|
onModel: (m) => widget.app.updateDraftModel(m),
|
||||||
),
|
),
|
||||||
|
mode: ModeChip(
|
||||||
|
app: widget.app,
|
||||||
|
agent: _draft.agent,
|
||||||
|
onAgent: (a) => widget.app.updateDraftModel(null, agent: a),
|
||||||
|
),
|
||||||
|
trailing: InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(18),
|
||||||
|
onTap: sending || !_canSend ? null : _send,
|
||||||
|
child: Container(
|
||||||
|
width: 36,
|
||||||
|
height: 36,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: _canSend || sending ? scheme.primary : scheme.surface,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: sending
|
||||||
|
? SizedBox(
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2, color: scheme.onPrimary))
|
||||||
|
: Icon(Icons.arrow_upward,
|
||||||
|
size: 20,
|
||||||
|
color: _canSend ? scheme.onPrimary : theme.hintColor),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
|
||||||
_sendKey(theme, sending),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return Column(
|
return Column(
|
||||||
@@ -437,34 +440,6 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _sendKey(ThemeData theme, bool sending) {
|
|
||||||
final scheme = theme.colorScheme;
|
|
||||||
return InkWell(
|
|
||||||
borderRadius: BorderRadius.circular(18),
|
|
||||||
onTap: sending || !_canSend ? null : _send,
|
|
||||||
child: Container(
|
|
||||||
width: 36,
|
|
||||||
height: 36,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: _canSend || sending
|
|
||||||
? scheme.primary
|
|
||||||
: scheme.surface,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: sending
|
|
||||||
? SizedBox(
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2, color: scheme.onPrimary))
|
|
||||||
: Icon(Icons.arrow_upward,
|
|
||||||
size: 20,
|
|
||||||
color: _canSend ? scheme.onPrimary : theme.hintColor),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _pickProject() async {
|
Future<void> _pickProject() async {
|
||||||
final app = widget.app;
|
final app = widget.app;
|
||||||
await app.refreshProjects();
|
await app.refreshProjects();
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
// The input capsule. Focus opens it into two rows — the text above, the
|
||||||
|
// model / mode / keys below — and losing focus folds it back to one line, the
|
||||||
|
// way dsh-Go's composer behaves. The field keeps its state across the two
|
||||||
|
// layouts through a GlobalKey.
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ComposerBox extends StatefulWidget {
|
||||||
|
final TextEditingController controller;
|
||||||
|
final FocusNode focusNode;
|
||||||
|
final String hint;
|
||||||
|
final int maxLines;
|
||||||
|
final ValueChanged<String>? onChanged;
|
||||||
|
final ValueChanged<String>? onSubmitted;
|
||||||
|
final TextInputAction textInputAction;
|
||||||
|
|
||||||
|
/// The attach key; shown on the text's line when folded and on the second
|
||||||
|
/// row when open.
|
||||||
|
final Widget leading;
|
||||||
|
|
||||||
|
/// Model (and thinking level) pill, second row.
|
||||||
|
final Widget? model;
|
||||||
|
|
||||||
|
/// The mode (Build / Plan), second row and separate from [model].
|
||||||
|
final Widget? mode;
|
||||||
|
|
||||||
|
/// The context ring, right of the keys.
|
||||||
|
final Widget? accessory;
|
||||||
|
|
||||||
|
/// Send or stop.
|
||||||
|
final Widget trailing;
|
||||||
|
|
||||||
|
const ComposerBox({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
required this.focusNode,
|
||||||
|
required this.hint,
|
||||||
|
required this.leading,
|
||||||
|
required this.trailing,
|
||||||
|
this.model,
|
||||||
|
this.mode,
|
||||||
|
this.accessory,
|
||||||
|
this.maxLines = 5,
|
||||||
|
this.onChanged,
|
||||||
|
this.onSubmitted,
|
||||||
|
this.textInputAction = TextInputAction.newline,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ComposerBox> createState() => _ComposerBoxState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ComposerBoxState extends State<ComposerBox> {
|
||||||
|
// The editor moves between the one-line row and the two-line column; a
|
||||||
|
// GlobalKey carries its state (and its input connection) across the swap.
|
||||||
|
final GlobalKey _fieldKey = GlobalKey();
|
||||||
|
bool _open = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
widget.focusNode.addListener(_onFocus);
|
||||||
|
_open = widget.focusNode.hasFocus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
widget.focusNode.removeListener(_onFocus);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onFocus() {
|
||||||
|
final open = widget.focusNode.hasFocus;
|
||||||
|
if (open == _open) return;
|
||||||
|
setState(() => _open = open);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _field() {
|
||||||
|
return TextField(
|
||||||
|
key: _fieldKey,
|
||||||
|
controller: widget.controller,
|
||||||
|
focusNode: widget.focusNode,
|
||||||
|
minLines: 1,
|
||||||
|
maxLines: widget.maxLines,
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
|
textInputAction: widget.textInputAction,
|
||||||
|
onChanged: widget.onChanged,
|
||||||
|
onSubmitted: widget.onSubmitted,
|
||||||
|
style: const TextStyle(fontSize: 15, height: 1.45),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: widget.hint,
|
||||||
|
hintMaxLines: 1,
|
||||||
|
isDense: true,
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: const EdgeInsets.symmetric(vertical: 6),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
final accessory = widget.accessory;
|
||||||
|
return AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
padding: const EdgeInsets.all(6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: scheme.surfaceContainerHighest,
|
||||||
|
borderRadius: BorderRadius.circular(_open ? 20 : 26),
|
||||||
|
),
|
||||||
|
child: AnimatedSize(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: _open
|
||||||
|
? Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(6, 0, 6, 2),
|
||||||
|
child: _field(),
|
||||||
|
),
|
||||||
|
_secondRow(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
widget.leading,
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Expanded(child: _field()),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
if (accessory != null) ...[
|
||||||
|
accessory,
|
||||||
|
const SizedBox(width: 2),
|
||||||
|
],
|
||||||
|
widget.trailing,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _secondRow() {
|
||||||
|
final accessory = widget.accessory;
|
||||||
|
// The row fades and rises a little as the composer opens.
|
||||||
|
return TweenAnimationBuilder<double>(
|
||||||
|
tween: Tween(begin: 0, end: 1),
|
||||||
|
duration: const Duration(milliseconds: 220),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
builder: (context, t, child) => Opacity(
|
||||||
|
opacity: t,
|
||||||
|
child: Transform.translate(
|
||||||
|
offset: Offset(0, (1 - t) * 4),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(0, 2, 0, 0),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
widget.leading,
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
if (widget.model != null)
|
||||||
|
Flexible(
|
||||||
|
fit: FlexFit.loose,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: widget.model!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
if (widget.mode != null) widget.mode!,
|
||||||
|
const Spacer(),
|
||||||
|
if (accessory != null) ...[
|
||||||
|
accessory,
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
],
|
||||||
|
widget.trailing,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// The composer's model row, shared by the chat and the new-session draft:
|
// The composer's two controls: the model pill (model and thinking level in
|
||||||
// the model/agent chip, the thinking level when the model has one, and any
|
// one group) and, separately, the mode (Build / Plan).
|
||||||
// leading chip the screen adds (the draft's project).
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../api/models.dart';
|
import '../api/models.dart';
|
||||||
@@ -8,113 +7,132 @@ import '../model_prefs.dart';
|
|||||||
import '../state.dart';
|
import '../state.dart';
|
||||||
import 'model_picker.dart';
|
import 'model_picker.dart';
|
||||||
|
|
||||||
class ModelControlsBar extends StatelessWidget {
|
/// `deepseek-flash · 高` — model and effort together, as dsh-Go shows them.
|
||||||
|
class ModelPill extends StatelessWidget {
|
||||||
final AppState app;
|
final AppState app;
|
||||||
final ModelRef? model;
|
final ModelRef? model;
|
||||||
final String agent;
|
|
||||||
final ValueChanged<ModelRef> onModel;
|
final ValueChanged<ModelRef> onModel;
|
||||||
final ValueChanged<String> onAgent;
|
|
||||||
|
|
||||||
/// Shown first, e.g. the project chip on the draft.
|
const ModelPill({
|
||||||
final Widget? leading;
|
|
||||||
|
|
||||||
const ModelControlsBar({
|
|
||||||
super.key,
|
super.key,
|
||||||
required this.app,
|
required this.app,
|
||||||
required this.model,
|
required this.model,
|
||||||
required this.agent,
|
|
||||||
required this.onModel,
|
required this.onModel,
|
||||||
required this.onAgent,
|
|
||||||
this.leading,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ModelInfo? get _info => app.modelInfo(model);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final info = _info;
|
final info = app.modelInfo(model);
|
||||||
final modelLabel = model == null
|
// The server may name the default level "default"; only a level the
|
||||||
? '模型'
|
// catalog lists counts as a choice.
|
||||||
: (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 &&
|
final effort = model?.variant != null &&
|
||||||
info != null &&
|
info != null &&
|
||||||
info.variants.contains(model!.variant)
|
info.variants.contains(model!.variant)
|
||||||
? model!.variant
|
? model!.variant
|
||||||
: null;
|
: null;
|
||||||
return Wrap(
|
final name = model == null ? '模型' : app.modelName(model!);
|
||||||
spacing: 6,
|
final label = effort == null ? name : '$name · ${effortLabel(effort)}';
|
||||||
runSpacing: 4,
|
return _Pill(
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
|
||||||
if (leading != null) leading!,
|
|
||||||
_chip(
|
|
||||||
context,
|
|
||||||
icon: Icons.smart_toy_outlined,
|
icon: Icons.smart_toy_outlined,
|
||||||
label: modelLabel,
|
label: label,
|
||||||
onTap: () => showModelPickerSheet(
|
onTap: () => showModelPickerSheet(
|
||||||
context,
|
context,
|
||||||
app: app,
|
app: app,
|
||||||
kind: 'model',
|
|
||||||
model: model,
|
model: model,
|
||||||
agent: agent,
|
|
||||||
onModel: onModel,
|
onModel: onModel,
|
||||||
onAgent: onAgent,
|
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
return PopupMenuButton<String>(
|
||||||
|
tooltip: '模式',
|
||||||
|
initialValue: current,
|
||||||
|
onSelected: onAgent,
|
||||||
|
itemBuilder: (_) {
|
||||||
|
final known = [
|
||||||
|
for (final a in app.agentList)
|
||||||
|
if (a.mode == 'primary' && !a.hidden) a,
|
||||||
|
];
|
||||||
|
final ids = {
|
||||||
|
..._modes,
|
||||||
|
for (final a in known) a.id,
|
||||||
|
};
|
||||||
|
return [
|
||||||
|
for (final id in ids)
|
||||||
|
PopupMenuItem(
|
||||||
|
value: id,
|
||||||
|
child: Text(_label(id),
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight:
|
||||||
|
id == current ? FontWeight.w700 : FontWeight.w400)),
|
||||||
),
|
),
|
||||||
if (hasEffort)
|
];
|
||||||
_chip(
|
},
|
||||||
context,
|
child: _Pill(
|
||||||
icon: Icons.psychology_outlined,
|
icon: Icons.tune,
|
||||||
label: '思考·${effortLabel(effort)}',
|
label: _label(current),
|
||||||
active: effort != null,
|
onTap: 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,
|
static String _label(String id) =>
|
||||||
{required IconData icon,
|
id.isEmpty ? 'Build' : id[0].toUpperCase() + id.substring(1);
|
||||||
required String label,
|
}
|
||||||
required VoidCallback onTap,
|
|
||||||
bool active = false}) {
|
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) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final scheme = theme.colorScheme;
|
final scheme = theme.colorScheme;
|
||||||
return InkWell(
|
return InkWell(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 5),
|
constraints: const BoxConstraints(minHeight: 30),
|
||||||
decoration: BoxDecoration(
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||||
color: active
|
decoration: ShapeDecoration(
|
||||||
? scheme.primary.withValues(alpha: 0.14)
|
color: scheme.onSurface.withValues(alpha: 0.07),
|
||||||
: scheme.surfaceContainerHighest,
|
shape: const StadiumBorder(),
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(icon, size: 14, color: active ? scheme.primary : theme.hintColor),
|
Icon(icon, size: 14, color: theme.hintColor),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
ConstrainedBox(
|
Flexible(
|
||||||
constraints: const BoxConstraints(maxWidth: 210),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
label,
|
label,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12.5,
|
||||||
color: active ? scheme.primary : theme.hintColor,
|
color: scheme.onSurface,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
+87
-129
@@ -1,6 +1,6 @@
|
|||||||
// The model / agent picker, shared by the chat composer and the new-session
|
// The model picker: favourites, recents, models grouped by provider with their
|
||||||
// draft: favourites, recents, models grouped by provider with their context
|
// context size, and — when a model has them — its thinking levels, chosen in
|
||||||
// size, and the thinking level of the chosen model.
|
// the same sheet because model and effort are one selection.
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../api/models.dart';
|
import '../api/models.dart';
|
||||||
@@ -10,11 +10,8 @@ import '../state.dart';
|
|||||||
Future<void> showModelPickerSheet(
|
Future<void> showModelPickerSheet(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required AppState app,
|
required AppState app,
|
||||||
required String kind,
|
|
||||||
required ModelRef? model,
|
required ModelRef? model,
|
||||||
required String agent,
|
|
||||||
required ValueChanged<ModelRef> onModel,
|
required ValueChanged<ModelRef> onModel,
|
||||||
required ValueChanged<String> onAgent,
|
|
||||||
}) async {
|
}) async {
|
||||||
app.refreshModels();
|
app.refreshModels();
|
||||||
await ModelPrefs.instance.ensureLoaded();
|
await ModelPrefs.instance.ensureLoaded();
|
||||||
@@ -28,61 +25,9 @@ Future<void> showModelPickerSheet(
|
|||||||
maxChildSize: 0.95,
|
maxChildSize: 0.95,
|
||||||
builder: (context, controller) => _PickerSheet(
|
builder: (context, controller) => _PickerSheet(
|
||||||
app: app,
|
app: app,
|
||||||
kind: kind,
|
|
||||||
model: model,
|
model: model,
|
||||||
agent: agent,
|
|
||||||
scrollController: controller,
|
scrollController: controller,
|
||||||
onModel: onModel,
|
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 {
|
class _PickerSheet extends StatefulWidget {
|
||||||
final AppState app;
|
final AppState app;
|
||||||
final String kind;
|
|
||||||
final ModelRef? model;
|
final ModelRef? model;
|
||||||
final String agent;
|
|
||||||
final ScrollController scrollController;
|
final ScrollController scrollController;
|
||||||
final ValueChanged<ModelRef> onModel;
|
final ValueChanged<ModelRef> onModel;
|
||||||
final ValueChanged<String> onAgent;
|
|
||||||
|
|
||||||
const _PickerSheet({
|
const _PickerSheet({
|
||||||
required this.app,
|
required this.app,
|
||||||
required this.kind,
|
|
||||||
required this.model,
|
required this.model,
|
||||||
required this.agent,
|
|
||||||
required this.scrollController,
|
required this.scrollController,
|
||||||
required this.onModel,
|
required this.onModel,
|
||||||
required this.onAgent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -112,10 +51,14 @@ class _PickerSheet extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PickerSheetState extends State<_PickerSheet> {
|
class _PickerSheetState extends State<_PickerSheet> {
|
||||||
late String _kind = widget.kind;
|
|
||||||
String _filter = '';
|
String _filter = '';
|
||||||
final Set<String> _collapsed = {};
|
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;
|
ModelPrefs get _prefs => ModelPrefs.instance;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -124,26 +67,10 @@ class _PickerSheetState extends State<_PickerSheet> {
|
|||||||
listenable: widget.app,
|
listenable: widget.app,
|
||||||
builder: (context, _) => Column(
|
builder: (context, _) => Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
const Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 4),
|
padding: EdgeInsets.fromLTRB(12, 12, 12, 4),
|
||||||
child: Text(_kind == 'agent' ? '选择智能体' : '选择模型',
|
child: Text('选择模型',
|
||||||
style: const TextStyle(
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
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();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
@@ -155,48 +82,15 @@ class _PickerSheetState extends State<_PickerSheet> {
|
|||||||
isDense: true),
|
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() {
|
Widget _models() {
|
||||||
final app = widget.app;
|
final all = widget.app.modelList;
|
||||||
final all = app.modelList;
|
|
||||||
if (all.isEmpty) {
|
if (all.isEmpty) {
|
||||||
return const Center(child: Text('正在载入模型…'));
|
return const Center(child: Text('正在载入模型…'));
|
||||||
}
|
}
|
||||||
@@ -218,11 +112,10 @@ class _PickerSheetState extends State<_PickerSheet> {
|
|||||||
for (final key in _prefs.favorites)
|
for (final key in _prefs.favorites)
|
||||||
if (byKey[key] != null) byKey[key]!,
|
if (byKey[key] != null) byKey[key]!,
|
||||||
]..sort((a, b) => a.name.compareTo(b.name));
|
]..sort((a, b) => a.name.compareTo(b.name));
|
||||||
final recentKeys = [
|
final recents = [
|
||||||
for (final key in _prefs.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>>{};
|
final providers = <String, List<ModelInfo>>{};
|
||||||
for (final model in matching) {
|
for (final model in matching) {
|
||||||
@@ -258,10 +151,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ListView(
|
return ListView(controller: widget.scrollController, children: children);
|
||||||
controller: widget.scrollController,
|
|
||||||
children: children,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _sectionHeader(String label, String key, {int? count}) {
|
Widget _sectionHeader(String label, String key, {int? count}) {
|
||||||
@@ -360,7 +250,75 @@ class _PickerSheetState extends State<_PickerSheet> {
|
|||||||
: null;
|
: null;
|
||||||
await _prefs.rememberModel(key);
|
await _prefs.rememberModel(key);
|
||||||
if (!mounted) return;
|
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));
|
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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,7 +2,7 @@ name: openchamber
|
|||||||
description: "A lightweight OpenChamber client for phones."
|
description: "A lightweight OpenChamber client for phones."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.3.14+314
|
version: 0.3.15+315
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.14.0
|
sdk: ^3.14.0
|
||||||
|
|||||||
Reference in new issue
Block a user