mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-13 09:21:37 +00:00
Enable support for selecting multiple files
This commit is contained in:
parent
63e14a5e58
commit
b3ca89fdd7
@ -127,17 +127,21 @@ public partial class AttachDocuments : MSGComponentBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedFile = await this.RustService.SelectFile(T("Select a file to attach"));
|
var selectFiles = await this.RustService.SelectFiles(T("Select a file to attach"));
|
||||||
if (selectedFile.UserCancelled)
|
if (selectFiles.UserCancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!File.Exists(selectedFile.SelectedFilePath))
|
foreach (var selectedFilePath in selectFiles.SelectedFilePaths)
|
||||||
return;
|
{
|
||||||
|
if (!File.Exists(selectedFilePath))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(selectedFile.SelectedFilePath))
|
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(selectedFilePath))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.DocumentPaths.Add(selectedFile.SelectedFilePath);
|
this.DocumentPaths.Add(selectedFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||||
await this.OnChange(this.DocumentPaths);
|
await this.OnChange(this.DocumentPaths);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
namespace AIStudio.Tools.Rust;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data structure for selecting multiple files.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="UserCancelled">Was the file selection canceled?</param>
|
||||||
|
/// <param name="SelectedFilePaths">The selected files, if any.</param>
|
||||||
|
public readonly record struct FilesSelectionResponse(bool UserCancelled, IReadOnlyList<string> SelectedFilePaths);
|
||||||
@ -25,17 +25,36 @@ public sealed partial class RustService
|
|||||||
PreviousFile = initialFile is null ? null : new (initialFile),
|
PreviousFile = initialFile is null ? null : new (initialFile),
|
||||||
Filter = filter
|
Filter = filter
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await this.http.PostAsJsonAsync("/select/file", payload, this.jsonRustSerializerOptions);
|
var result = await this.http.PostAsJsonAsync("/select/file", payload, this.jsonRustSerializerOptions);
|
||||||
if (!result.IsSuccessStatusCode)
|
if (!result.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
this.logger!.LogError($"Failed to select a file: '{result.StatusCode}'");
|
this.logger!.LogError($"Failed to select a file: '{result.StatusCode}'");
|
||||||
return new FileSelectionResponse(true, string.Empty);
|
return new FileSelectionResponse(true, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await result.Content.ReadFromJsonAsync<FileSelectionResponse>(this.jsonRustSerializerOptions);
|
return await result.Content.ReadFromJsonAsync<FileSelectionResponse>(this.jsonRustSerializerOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<FilesSelectionResponse> SelectFiles(string title, FileTypeFilter? filter = null, string? initialFile = null)
|
||||||
|
{
|
||||||
|
var payload = new SelectFileOptions
|
||||||
|
{
|
||||||
|
Title = title,
|
||||||
|
PreviousFile = initialFile is null ? null : new (initialFile),
|
||||||
|
Filter = filter
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await this.http.PostAsJsonAsync("/select/files", payload, this.jsonRustSerializerOptions);
|
||||||
|
if (!result.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
this.logger!.LogError($"Failed to select files: '{result.StatusCode}'");
|
||||||
|
return new FilesSelectionResponse(true, Array.Empty<string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
return await result.Content.ReadFromJsonAsync<FilesSelectionResponse>(this.jsonRustSerializerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initiates a dialog to let the user select a file for a writing operation.
|
/// Initiates a dialog to let the user select a file for a writing operation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
- Improved file reading, e.g. for the translation, summarization, and legal assistants, by performing the Pandoc validation in the first step. This prevents unnecessary selection of files that cannot be processed.
|
- Improved file reading, e.g. for the translation, summarization, and legal assistants, by performing the Pandoc validation in the first step. This prevents unnecessary selection of files that cannot be processed.
|
||||||
- Improved the file selection for file attachments in chat and assistant file loading by filtering out audio files. Audio attachments are not yet supported.
|
- Improved the file selection for file attachments in chat and assistant file loading by filtering out audio files. Audio attachments are not yet supported.
|
||||||
- Improved the developer experience by automating localization updates in the filesystem for the selected language in the localization assistant.
|
- Improved the developer experience by automating localization updates in the filesystem for the selected language in the localization assistant.
|
||||||
|
- Improved the file selection so that users can now select multiple files at the same time. This is useful, for example, for document analysis (in preview) or adding file attachments to the chat.
|
||||||
- Fixed a bug in the local data sources info dialog (preview feature) for data directories that could cause the app to crash. The error was caused by a background thread producing data while the frontend attempted to display it.
|
- Fixed a bug in the local data sources info dialog (preview feature) for data directories that could cause the app to crash. The error was caused by a background thread producing data while the frontend attempted to display it.
|
||||||
- Fixed a visual bug where a function's preview status was misaligned. You might have seen it in document analysis or the ERI server assistant.
|
- Fixed a visual bug where a function's preview status was misaligned. You might have seen it in document analysis or the ERI server assistant.
|
||||||
- Fixed a rare bug in the Microsoft Word export for huge documents.
|
- Fixed a rare bug in the Microsoft Word export for huge documents.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user