feat(app): render markdown in chat messages and artifact previews
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../chat/ui/transcript/chat_markdown_view.dart';
|
||||
import '../domain/artifact_groups.dart';
|
||||
import '../domain/artifact_kind.dart';
|
||||
import '../domain/artifact_record.dart';
|
||||
@@ -27,7 +28,8 @@ const String artifactGalleryTitle = 'Artifacts';
|
||||
/// never fetched); any other selection opens a native dialog with the recorded
|
||||
/// name, MIME and size, the visit's capture facts and, only when the recorded
|
||||
/// url resolves through [resolveArtifactUrl], native `Open` and `Copy link`
|
||||
/// actions. It never downloads, shares or filters.
|
||||
/// actions. Markdown previews use the same chat markdown renderer by default.
|
||||
/// It never downloads, shares or filters.
|
||||
class ArtifactGalleryPage extends StatefulWidget {
|
||||
const ArtifactGalleryPage({
|
||||
super.key,
|
||||
@@ -36,7 +38,7 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
this.configuredEndpoint = '',
|
||||
this.openExternal = openArtifactExternally,
|
||||
this.fetch = fetchArtifact,
|
||||
this.markdownBuilder = defaultArtifactMarkdown,
|
||||
this.markdownBuilder = chatMarkdownText,
|
||||
});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
|
||||
@@ -4,12 +4,14 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/artifact_preview.dart';
|
||||
|
||||
/// Renders fetched markdown text for the viewer. The gallery's default builder
|
||||
/// returns plain selectable text, so the viewer is honest before the markdown
|
||||
/// lane supplies a real renderer.
|
||||
typedef ArtifactMarkdownBuilder = Widget Function(String text);
|
||||
/// Renders fetched markdown text for the viewer. It takes the build context so
|
||||
/// a themed markdown renderer can be supplied; the viewer's own default stays
|
||||
/// plain selectable text for a standalone preview.
|
||||
typedef ArtifactMarkdownBuilder =
|
||||
Widget Function(BuildContext context, String text);
|
||||
|
||||
Widget defaultArtifactMarkdown(String text) => SelectableText(text);
|
||||
Widget defaultArtifactMarkdown(BuildContext context, String text) =>
|
||||
SelectableText(text);
|
||||
|
||||
/// The viewer's preview surface for one page.
|
||||
///
|
||||
@@ -62,7 +64,7 @@ class ArtifactPreviewBody extends StatelessWidget {
|
||||
case ArtifactPreviewKind.text:
|
||||
return _ScrollingText(child: SelectableText(text ?? ''));
|
||||
case ArtifactPreviewKind.markdown:
|
||||
return _ScrollingText(child: markdownBuilder(text ?? ''));
|
||||
return _ScrollingText(child: markdownBuilder(context, text ?? ''));
|
||||
case ArtifactPreviewKind.unsupported:
|
||||
case ArtifactPreviewKind.unavailable:
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/chat_transcript.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import '../ui/transcript/chat_markdown_view.dart';
|
||||
import '../ui/transcript/chat_message_view.dart';
|
||||
import 'chat_composer_bar.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
@@ -16,6 +17,10 @@ import 'chat_thread_controller.dart';
|
||||
/// One read-only conversation: the controller's transcript in the order the
|
||||
/// server reports it, rendered by the existing [ChatMessageView].
|
||||
///
|
||||
/// Assistant text goes through [ChatMarkdownView]'s builder, so stored and live
|
||||
/// prose share the supported markdown subset. User text keeps the server's exact
|
||||
/// characters, and reasoning/tool disclosures stay plain text.
|
||||
///
|
||||
/// History and live-subscription failures are separate notices: readable stored
|
||||
/// history must never hide a refused live watch. The shell owns the navigation
|
||||
/// bar, so this view adds only its own Back control and content.
|
||||
@@ -237,7 +242,10 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
Padding(
|
||||
key: ValueKey<String>(keys[index]),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: ChatMessageView(row: rows[index]),
|
||||
child: ChatMessageView(
|
||||
row: rows[index],
|
||||
textBuilder: chatMarkdownText,
|
||||
),
|
||||
),
|
||||
if (_controller.running)
|
||||
Padding(
|
||||
|
||||
Reference in New Issue
Block a user