feat: AI-output Markdown, live SSE fixes, faster builds
- render assistant Markdown with gpt_markdown (the same renderer dsh-Go uses): streaming, syntax-highlighted code with copy, tables, LaTeX and task lists, replacing flutter_markdown - fix the event stream: Dart's Map collapsed the repeated `types` query into one value, so only one event type was subscribed and chats never updated; build the query by hand - keep the optimistic prompt on failure out of the transcript and put the text back for a retry - clamp negative turn durations - build: Aliyun Maven mirrors, pre-seeded Gradle 9.5.0, and a complete NDK 28.2 install to avoid multi-hour downloads
This commit is contained in:
1 parent
aee560172c
commit
885a27c6a9
7 files changed
+186
-46
No files matched your search
@@ -6,7 +6,7 @@ import 'dart:typed_data';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:gpt_markdown/gpt_markdown.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
@@ -301,12 +301,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final text = m.content[part].text;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||
child: MarkdownBody(
|
||||
data: text,
|
||||
selectable: true,
|
||||
styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith(
|
||||
p: const TextStyle(fontSize: 15, height: 1.45),
|
||||
),
|
||||
child: GptMarkdown(
|
||||
text,
|
||||
// The server already streams deltas; show them as they arrive.
|
||||
isStreaming: false,
|
||||
style: const TextStyle(fontSize: 15, height: 1.45),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -453,6 +452,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
if (start <= 0) return '';
|
||||
final secs = ((m.completed - start) / 1000).round();
|
||||
if (secs <= 0) return '';
|
||||
if (secs < 60) return '$secs 秒';
|
||||
return '${secs ~/ 60}:${(secs % 60).toString().padLeft(2, '0')}';
|
||||
}
|
||||
@@ -618,11 +618,15 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
images.add(a.path!);
|
||||
}
|
||||
}
|
||||
chat.draft = '';
|
||||
final id = await chat.send(text: text, files: files);
|
||||
if (id == null) {
|
||||
// The prompt failed: keep the text for a retry.
|
||||
_draftCtrl.text = chat.draft;
|
||||
return;
|
||||
}
|
||||
_draftCtrl.clear();
|
||||
setState(() => _attachments = []);
|
||||
final id = await chat.send(text: text, files: files);
|
||||
if (id != null && images.isNotEmpty) {
|
||||
if (images.isNotEmpty) {
|
||||
chat.imagePaths[id] = images;
|
||||
chat.touch();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user