Complete chat file previews downloads and explorer actions

This commit is contained in:
2026-11-07 01:44:42 +00:00
parent 81955059de
commit 84a03bea8d
32 changed files with 1349 additions and 140 deletions
@@ -198,7 +198,16 @@ bool isMarkdownArtifact(String contentType, String name) {
/// How the viewer presents an artifact in-app, or [none] when it only offers
/// Open/Download.
enum ArtifactPreviewFormat { image, video, markdown, text, table, html, none }
enum ArtifactPreviewFormat {
image,
video,
audio,
markdown,
text,
table,
html,
none,
}
/// The one rule for in-app previews, shared by the gallery's paging and the
/// viewer's fetch plan. Images and videos come from the content type; markdown
@@ -210,6 +219,7 @@ ArtifactPreviewFormat artifactPreviewFormat(String contentType, String name) {
if (isVideoContentType(contentType)) return ArtifactPreviewFormat.video;
final mime = contentType.split(';').first.trim().toLowerCase();
final ext = _extensionOf(name);
if (mime.startsWith('audio/')) return ArtifactPreviewFormat.audio;
if (mime == 'text/markdown' || ext == 'md' || ext == 'markdown') {
return ArtifactPreviewFormat.markdown;
}
@@ -12,6 +12,9 @@ enum ArtifactPreviewKind {
/// fetched as bytes, never autoplayed), as the web viewer does.
video,
/// A same-origin audio file, played with the shared media controller.
audio,
/// A CSV/TSV drawn as a table from its fetched text.
table,
@@ -68,13 +71,16 @@ const String artifactPreviewExternalUrl =
/// Classifies [artifact] against the configured server origin.
///
/// The format comes from [artifactPreviewFormat]: images are drawn from the
/// The format comes from [format] (the shared [artifactPreviewFormat] unless a
/// caller such as the chat Files panel has its own rule): images are drawn from the
/// resolved bytes, a video plays from the resolved url, markdown goes to the
/// injected builder and the text family is selectable monospace text.
/// Everything else is explicitly unsupported rather than faked.
ArtifactPreviewPlan planArtifactPreview({
required ArtifactRecord artifact,
required String configuredEndpoint,
ArtifactPreviewFormat Function(String contentType, String name) format =
artifactPreviewFormat,
}) {
if (!artifact.hasUrl) {
return const ArtifactPreviewPlan(
@@ -98,12 +104,10 @@ ArtifactPreviewPlan planArtifactPreview({
message: artifactPreviewExternalUrl,
);
}
final kind = switch (artifactPreviewFormat(
artifact.contentType,
artifact.name,
)) {
final kind = switch (format(artifact.contentType, artifact.name)) {
ArtifactPreviewFormat.image => ArtifactPreviewKind.image,
ArtifactPreviewFormat.video => ArtifactPreviewKind.video,
ArtifactPreviewFormat.audio => ArtifactPreviewKind.audio,
ArtifactPreviewFormat.markdown => ArtifactPreviewKind.markdown,
ArtifactPreviewFormat.text => ArtifactPreviewKind.text,
ArtifactPreviewFormat.table => ArtifactPreviewKind.table,