feat: the files sidebar, Markdown thinking, a banner that clears
- The chat's top-right menu only repeated the per-turn menu. It now opens a files sidebar that slides in from the right, the way the official client's right panel does: browse the session directory with a breadcrumb and an up key, filter the current directory, search its subdirectories (bounded, skipping .git/node_modules/build and friends), preview text/code/Markdown/ images, edit and save text files, create files and folders, and download any file through the system save dialog. - The panel's "..." menu carries the official client's "显示被 git 忽略的文件" toggle (the listing asks the server to respect gitignore by default) and a refresh. 项目知识 and 终端 have their tabs, marked as coming later. - Thinking blocks are Markdown too (headings, lists, inline code), rendered with the shared MarkdownView at a smaller, quieter size. - The reconnect banner stayed forever: the stream loop sets it when the SSE connection drops and nothing cleared it. Any event proves the stream is back (the server greets every connection with server.connected), so it now clears the message then. - Markdown rendering moved to lib/widgets/markdown_view.dart, shared by messages, thinking, compaction summaries and file previews. Version 0.3.9 (code 309).
This commit is contained in:
1 parent
b9433c30cb
commit
9b53338908
9 files changed
+1118
-80
No files matched your search
@@ -7,15 +7,12 @@ import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gpt_markdown/gpt_markdown.dart';
|
||||
// gpt_markdown renders through its own Material port; its colours come from
|
||||
// that port's theme, so the chat has to hand it ours.
|
||||
import 'package:material_ui/material_ui.dart' as mui;
|
||||
|
||||
import '../api/client.dart';
|
||||
import '../api/models.dart';
|
||||
import '../state.dart';
|
||||
import '../widgets/markdown_view.dart';
|
||||
import '../widgets/usage_ring.dart';
|
||||
import 'files_panel.dart';
|
||||
|
||||
/// The chat: streaming Markdown, tool rows, composer and sheets.
|
||||
class ChatScreen extends StatefulWidget {
|
||||
@@ -110,9 +107,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
tooltip: '更多操作',
|
||||
onPressed: _footerMenu,
|
||||
icon: const Icon(Icons.view_sidebar_outlined),
|
||||
tooltip: '文件',
|
||||
onPressed: () => showFilesPanel(context, widget.app, widget.session),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -467,37 +464,15 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// gpt_markdown builds its widgets with `material_ui`, whose Theme.of has a
|
||||
/// light fallback: without this the code panel and inline chips stayed light
|
||||
/// (and their text dark) in the dark theme.
|
||||
static mui.ThemeData _mdTheme(ThemeData theme) => mui.ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: theme.brightness,
|
||||
colorScheme: mui.ColorScheme.fromSeed(
|
||||
seedColor: theme.colorScheme.primary,
|
||||
brightness: theme.brightness,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _textRow(String id, int part) {
|
||||
final m = chat.byId[id]!;
|
||||
if (part < 0 || part >= m.content.length) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||
child: _markdown(m.content[part].text),
|
||||
child: MarkdownView(m.content[part].text),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _markdown(String text) => mui.Theme(
|
||||
data: _mdTheme(Theme.of(context)),
|
||||
child: GptMarkdown(
|
||||
text,
|
||||
// The server already streams deltas; show them as they arrive.
|
||||
isStreaming: false,
|
||||
style: const TextStyle(fontSize: 15, height: 1.45),
|
||||
),
|
||||
);
|
||||
|
||||
/// A run of steps: the header, then its rows revealed with an animation.
|
||||
/// Revealing grows the list below the header, so [_Reveal] reports the
|
||||
/// height it just added and the list scrolls by it, keeping the header
|
||||
@@ -758,11 +733,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final theme = Theme.of(context);
|
||||
if (reasoning) {
|
||||
if (p.text.isEmpty) return const SizedBox.shrink();
|
||||
// The model writes Markdown here too; render it as such, a touch
|
||||
// smaller and quieter than the answer.
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(10, 2, 10, 8),
|
||||
child: SelectableText(p.text,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5, height: 1.45, color: theme.hintColor)),
|
||||
child: MarkdownView(p.text, fontSize: 12.5, color: theme.hintColor),
|
||||
);
|
||||
}
|
||||
final input = p.state?.input ?? const <String, dynamic>{};
|
||||
@@ -1094,7 +1069,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: summary.isEmpty
|
||||
? Text(running ? '正在生成摘要…' : '(摘要为空)',
|
||||
style: TextStyle(fontSize: 13, color: theme.hintColor))
|
||||
: _markdown(summary),
|
||||
: MarkdownView(summary, fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -1201,43 +1176,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _footerMenu() {
|
||||
final chat_ = chat;
|
||||
Message? last;
|
||||
for (var i = chat_.msgs.length - 1; i >= 0; i--) {
|
||||
if (chat_.msgs[i].type == 'assistant' && chat_.msgs[i].completed > 0) {
|
||||
last = chat_.msgs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (last == null) return;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('复制回答'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_copyText(last!.partText);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('从这里分叉'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
chat_.fork();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _copyText(String text) async {
|
||||
if (text.trim().isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('没有可复制的文字')));
|
||||
|
||||
Reference in new issue
Block a user