fix: dark markdown, steadier folds, readable tool details, live refresh
- gpt_markdown renders through its own Material port, whose Theme.of falls back to a light theme: code panels stayed light and their text black in the dark theme. The chat now wraps markdown in a matching `mui.Theme`. - Folding a run changed the height below its header and threw the header out of view. The toggle remembers the header's screen position, corrects the scroll offset, and parks the header at the top when the run is longer than the viewport. - Step details show what a tool actually did: the command and its output for shell steps, the remaining inputs and the result for the rest, in monospace; toolOutput falls back to metadata. A read/write/edit of an image is no longer foldable — its path opens the preview. - The event stream now times out without a heartbeat, so a half-open connection is noticed and reopened; returning to the foreground restarts the stream, refreshes the session list and the open chat, and reloadTail merges the newest page instead of dropping loaded history. - A page shorter than the limit means there is nothing older, so short sessions no longer offer "load earlier". - Version 0.3.4 (code 304).
This commit is contained in:
1 parent
2baa0a2730
commit
32277564f9
9 files changed
+369
-55
No files matched your search
+51
-12
@@ -272,20 +272,32 @@ class AppState extends ChangeNotifier {
|
||||
m.id;
|
||||
}
|
||||
|
||||
StreamSubscription<Map<String, dynamic>>? _events;
|
||||
int _streamGen = 0;
|
||||
|
||||
void _startStream() {
|
||||
final cl = client;
|
||||
if (cl == null) return;
|
||||
final gen = ++_streamGen;
|
||||
_events?.cancel().ignore();
|
||||
Future<void> loop() async {
|
||||
while (client == cl) {
|
||||
try {
|
||||
await for (final ev in cl.streamEvents(types: _eventTypes)) {
|
||||
while (client == cl && gen == _streamGen) {
|
||||
final done = Completer<void>();
|
||||
_events = cl.streamEvents(types: _eventTypes).listen(
|
||||
(ev) {
|
||||
if (client != cl) return;
|
||||
_applyEvent(ev);
|
||||
}
|
||||
} catch (_) {
|
||||
// Connection dropped; fall through to the retry below.
|
||||
}
|
||||
if (client != cl) return;
|
||||
},
|
||||
onError: (Object _) {
|
||||
if (!done.isCompleted) done.complete();
|
||||
},
|
||||
onDone: () {
|
||||
if (!done.isCompleted) done.complete();
|
||||
},
|
||||
cancelOnError: true,
|
||||
);
|
||||
await done.future;
|
||||
if (client != cl || gen != _streamGen) return;
|
||||
error = '连接中断,正在重连…';
|
||||
notifyListeners();
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
@@ -294,6 +306,16 @@ class AppState extends ChangeNotifier {
|
||||
loop();
|
||||
}
|
||||
|
||||
/// Reopens the event stream and refreshes what is on screen. Called when the
|
||||
/// app comes back to the foreground: a socket that died while the process
|
||||
/// was in the background never reports it.
|
||||
Future<void> onResumed() async {
|
||||
if (client == null) return;
|
||||
_startStream();
|
||||
await refreshSessions();
|
||||
if (chat != null) await chat!.reloadTail();
|
||||
}
|
||||
|
||||
void _applyEvent(Map<String, dynamic> ev) {
|
||||
final type = ev['type'] as String? ?? '';
|
||||
final data = ev['data'] as Map<String, dynamic>? ?? {};
|
||||
@@ -492,9 +514,11 @@ class ChatState extends ChangeNotifier {
|
||||
try {
|
||||
final page = await app.client!.listMessages(id, directory: dir);
|
||||
_setMessages(page.data);
|
||||
// A desc page's `next` cursor points at the older side.
|
||||
// A desc page's `next` cursor points at the older side. The server also
|
||||
// hands out a cursor for a page that already holds everything, so a
|
||||
// short page means there is nothing older.
|
||||
olderCursor = page.next;
|
||||
hasMore = page.next != null;
|
||||
hasMore = page.next != null && page.data.length >= _pageSize;
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
await reloadTail();
|
||||
@@ -505,14 +529,29 @@ class ChatState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Refreshes the newest page without dropping the older pages that were
|
||||
/// already loaded; the server's copy wins for messages it returns.
|
||||
Future<void> reloadTail() async {
|
||||
try {
|
||||
final page = await app.client!.listMessages(id, directory: dir);
|
||||
_setMessages(page.data);
|
||||
if (msgs.isEmpty) {
|
||||
_setMessages(page.data);
|
||||
} else {
|
||||
final fresh = {for (final m in page.data) m.id: m};
|
||||
final merged = <Message>[
|
||||
for (final m in msgs) fresh.remove(m.id) ?? m,
|
||||
for (final m in page.data)
|
||||
if (fresh.containsKey(m.id)) m,
|
||||
];
|
||||
msgs = merged;
|
||||
_sortMsgs();
|
||||
}
|
||||
notifyListeners();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static const _pageSize = 30;
|
||||
|
||||
Future<void> loadOlder() async {
|
||||
if (!hasMore || loadingOlder) return;
|
||||
loadingOlder = true;
|
||||
@@ -525,7 +564,7 @@ class ChatState extends ChangeNotifier {
|
||||
msgs = [...older, ...msgs];
|
||||
_sortMsgs();
|
||||
olderCursor = page.next;
|
||||
hasMore = page.next != null;
|
||||
hasMore = page.next != null && page.data.length >= _pageSize;
|
||||
} catch (_) {}
|
||||
loadingOlder = false;
|
||||
notifyListeners();
|
||||
|
||||
Reference in new issue
Block a user