Fixed attached files silently reaching the AI as empty documents (#904)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-08-10 16:37:44 +02:00
1 parent b9ec13edcf
commit 8f8f788896
31 files changed
+1730 -285

No files matched your search

@@ -443,23 +443,31 @@ public partial class AttachDocuments : MSGComponentBase
var mediaPaths = existingPaths.Where(IsTranscribableMedia).ToList();
var regularPaths = existingPaths.Except(mediaPaths).ToList();
var canAddRegularFiles = true;
if (regularPaths.Count > 0)
//
// Only the formats we convert with Pandoc depend on a Pandoc installation. Everything
// else, PDFs in particular, is read by the Rust runtime itself, so those files must stay
// attachable without Pandoc.
//
var canAddPandocFiles = true;
if (regularPaths.Any(FileTypes.RequiresPandoc))
{
var pandocState = await this.PandocAvailabilityService.EnsureAvailabilityAsync(
showSuccessMessage: false,
showDialog: true);
canAddRegularFiles = pandocState.IsAvailable;
canAddPandocFiles = pandocState.IsAvailable;
}
foreach (var path in regularPaths)
{
if (!canAddRegularFiles)
break;
if (!canAddPandocFiles && FileTypes.RequiresPandoc(path))
{
this.Logger.LogWarning("The file '{Path}' needs Pandoc and was not attached.", path);
continue;
}
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(FileExtensionValidation.UseCase.ATTACHING_CONTENT, path, this.ValidateMediaFileTypes, this.Provider))
continue;
this.DocumentPaths.Add(FileAttachment.FromPath(path));
}
@@ -324,8 +324,13 @@ public partial class ReadFileContent : MSGComponentBase
try
{
var fileContent = await UserFile.LoadFileData(filePath, this.RustService, this.DialogService);
await this.ApplyFileContentAsync(fileContent, filePath);
var extraction = await UserFile.LoadFileData(filePath, this.RustService, this.DialogService);
// The failure was already reported by UserFile.LoadFileData, so we only stop here:
if (!extraction.HasUsableContent)
return false;
await this.ApplyFileContentAsync(extraction.Content, filePath);
this.Logger.LogInformation("Successfully loaded file content: {FilePath}", filePath);
return true;
}