feat(app): render markdown in chat messages and artifact previews

This commit is contained in:
2026-10-22 00:26:36 +01:00
parent 0e323dde10
commit dc6b963170
8 changed files with 926 additions and 12 deletions
@@ -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();