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
+12
-11
@@ -232,11 +232,12 @@ class Client {
|
||||
/// Subscribes to GET /api/event, yielding each SSE event. The stream ends
|
||||
/// when the connection drops; the caller restarts it with backoff.
|
||||
Stream<Map<String, dynamic>> streamEvents({List<String>? types}) async* {
|
||||
final query = <String, String>{
|
||||
if (types != null) for (final t in types) 'types': t,
|
||||
};
|
||||
final uri = base.resolve('/api/event')
|
||||
.replace(queryParameters: query.isEmpty ? null : query);
|
||||
// `types` repeats: a Map would keep only the last one.
|
||||
var uri = base.resolve('/api/event');
|
||||
if (types != null && types.isNotEmpty) {
|
||||
final q = types.map((t) => 'types=${Uri.encodeQueryComponent(t)}').join('&');
|
||||
uri = Uri.parse('$uri?$q');
|
||||
}
|
||||
final req = await _http.openUrl('GET', uri);
|
||||
req.headers.set('Accept', 'text/event-stream');
|
||||
req.headers.set('Cache-Control', 'no-cache');
|
||||
@@ -297,12 +298,9 @@ class Client {
|
||||
final q = Uri(queryParameters: query ?? {});
|
||||
final uri = base.resolve(path).replace(queryParameters: q.queryParameters.isEmpty ? null : q.queryParameters);
|
||||
final req = await _http.openUrl(method, uri);
|
||||
req.headers.set('Accept', 'application/json');
|
||||
// Every header must be set before the body, which finalizes them.
|
||||
req.headers.set('Accept', path == '/api/event' ? 'text/event-stream' : 'application/json');
|
||||
req.headers.set('User-Agent', 'openchamber-native/0.3');
|
||||
if (body != null) {
|
||||
req.headers.contentType = ContentType.json;
|
||||
req.write(jsonEncode(body));
|
||||
}
|
||||
if (token != null && token!.isNotEmpty) {
|
||||
req.headers.set('Authorization', 'Bearer $token');
|
||||
}
|
||||
@@ -314,9 +312,12 @@ class Client {
|
||||
req.headers.set('x-openchamber-part-shells', 'v1');
|
||||
}
|
||||
if (path == '/api/event') {
|
||||
req.headers.set('Accept', 'text/event-stream');
|
||||
req.headers.set('Cache-Control', 'no-cache');
|
||||
}
|
||||
if (body != null) {
|
||||
req.headers.contentType = ContentType.json;
|
||||
req.write(jsonEncode(body));
|
||||
}
|
||||
final res = await req.close();
|
||||
final bodyBytes = await res.fold<List<int>>(<int>[], (a, b) => a..addAll(b));
|
||||
return _Response(res.statusCode, bodyBytes);
|
||||
|
||||
Reference in new issue
Block a user