Rename message tables to message files

This commit is contained in:
Thorsten Sommer 2026-09-23 13:22:25 +02:00
parent fdaa12ab5b
commit 5ce16f3f24
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
5 changed files with 24 additions and 24 deletions

View File

@ -91,12 +91,12 @@
{
<MudMenuItem OnClick="@(() => this.ExportDocument(documentFormat))" Icon="@documentFormat.ToIcon()" Label="@documentFormat.ToName()"/>
}
@if (this.MessageTables.Count > 0)
@if (this.MessageFiles.Count > 0)
{
<MudDivider/>
@foreach (var messageTable in this.MessageTables)
@foreach (var messageFile in this.MessageFiles)
{
<MudMenuItem OnClick="@(() => this.ExportTable(messageTable))" Icon="@messageTable.Format.ToIcon()" Label="@this.ExportLabel(messageTable)"/>
<MudMenuItem OnClick="@(() => this.ExportFile(messageFile))" Icon="@messageFile.Format.ToIcon()" Label="@this.ExportLabel(messageFile)"/>
}
}
<MudDivider/>

View File

@ -125,8 +125,8 @@ public partial class ContentBlockComponent : MSGComponentBase
private int lastRenderHash;
private string cachedMarkdownRenderPlanInput = string.Empty;
private MarkdownRenderPlan cachedMarkdownRenderPlan = MarkdownRenderPlan.EMPTY;
private string cachedMessageTablesInput = string.Empty;
private IReadOnlyList<MessageTable> cachedMessageTables = [];
private string cachedMessageFilesInput = string.Empty;
private IReadOnlyList<MessageFile> cachedMessageFiles = [];
private char csvSeparator = ',';
private ElementReference mathContentContainer;
private SourcesList? sourcesList;
@ -154,19 +154,19 @@ public partial class ContentBlockComponent : MSGComponentBase
/// message, and a block re-renders for reasons which have nothing to do with its text, such as
/// switching the theme, which would parse every message of a long chat again.
/// </remarks>
private IReadOnlyList<MessageTable> MessageTables
private IReadOnlyList<MessageFile> MessageFiles
{
get
{
if (!this.Content.TryGetMarkdownText(out var markdown))
return [];
if (ReferenceEquals(this.cachedMessageTablesInput, markdown) || string.Equals(this.cachedMessageTablesInput, markdown, StringComparison.Ordinal))
return this.cachedMessageTables;
if (ReferenceEquals(this.cachedMessageFilesInput, markdown) || string.Equals(this.cachedMessageFilesInput, markdown, StringComparison.Ordinal))
return this.cachedMessageFiles;
this.cachedMessageTablesInput = markdown;
this.cachedMessageTables = PlainFileExport.ExtractTables(markdown, this.csvSeparator);
return this.cachedMessageTables;
this.cachedMessageFilesInput = markdown;
this.cachedMessageFiles = PlainFileExport.ExtractFiles(markdown, this.csvSeparator);
return this.cachedMessageFiles;
}
}
@ -178,9 +178,9 @@ public partial class ContentBlockComponent : MSGComponentBase
/// one, the user has to be able to tell them apart: the heading above a table does that, unless
/// it is missing or two tables share one, and then we count them.
/// </remarks>
private string ExportLabel(MessageTable table)
private string ExportLabel(MessageFile table)
{
var tables = this.MessageTables;
var tables = this.MessageFiles;
if (tables.Count < 2)
return table.Format.ToName();
@ -221,8 +221,8 @@ public partial class ContentBlockComponent : MSGComponentBase
return;
this.csvSeparator = separator;
this.cachedMessageTablesInput = string.Empty;
this.cachedMessageTables = [];
this.cachedMessageFilesInput = string.Empty;
this.cachedMessageFiles = [];
await this.InvokeAsync(this.StateHasChanged);
}
@ -749,17 +749,17 @@ public partial class ContentBlockComponent : MSGComponentBase
}
/// <summary>
/// Exports one table out of the message, exactly as the menu offered it.
/// Exports one file out of the message, exactly as the menu offered it.
/// </summary>
private async Task ExportTable(MessageTable table)
private async Task ExportFile(MessageFile file)
{
try
{
await PlainFileExport.ToFile(this.RustService, this.EffectiveExportTitle, table.Format, table.Content, table.Caption);
await PlainFileExport.ToFile(this.RustService, this.EffectiveExportTitle, file.Format, file.Content, file.Caption);
}
catch (ArgumentOutOfRangeException e)
{
await this.ReportUnknownExportFormat(e, table.Format);
await this.ReportUnknownExportFormat(e, file.Format);
}
}

View File

@ -1,7 +1,7 @@
namespace AIStudio.Tools;
/// <summary>
/// A table found in a message, ready to be written to a file.
/// A file found in a message, ready to be written: a table the model wrote.
/// </summary>
/// <param name="Ordinal">Which table of the message this is, counting from one. The same table
/// appears once per format we offer for it, so this is what tells two tables apart even when they
@ -9,4 +9,4 @@ namespace AIStudio.Tools;
/// <param name="Caption">What the table is about, taken from its first column heading.</param>
/// <param name="Format">The format this content is written as.</param>
/// <param name="Content">The finished file content.</param>
public sealed record MessageTable(int Ordinal, string Caption, FileExportFormat Format, string Content);
public sealed record MessageFile(int Ordinal, string Caption, FileExportFormat Format, string Content);

View File

@ -27,7 +27,7 @@ public static class PlainFileExport
/// <param name="markdown">The Markdown text of the message.</param>
/// <param name="separator">The separator to write a Markdown table with, see CsvWriter.SeparatorFor.</param>
/// <returns>The tables, or an empty list when the message holds none.</returns>
public static IReadOnlyList<MessageTable> ExtractTables(string markdown, char separator)
public static IReadOnlyList<MessageFile> ExtractFiles(string markdown, char separator)
{
if (string.IsNullOrWhiteSpace(markdown))
return [];
@ -59,7 +59,7 @@ public static class PlainFileExport
return tables.Concat(codeBlocks)
.Where(entry => entry.Content is not null)
.OrderBy(entry => entry.Line)
.Select((entry, index) => new MessageTable(
.Select((entry, index) => new MessageFile(
index + 1,
Caption: HeadingAbove(entry.Line) is { Length: > 0 } heading ? heading : entry.Content!.Value.Fallback,
entry.Content!.Value.Format,

View File

@ -163,7 +163,7 @@ public sealed class IContentExtensionsTests
"| Q1 | 100 |"), TOOL_SOURCE);
content.TryGetMarkdownText(out var markdown);
var tables = PlainFileExport.ExtractTables(markdown, ',');
var tables = PlainFileExport.ExtractFiles(markdown, ',');
Assert.Multiple(() =>
{