diff --git a/app/MindWork AI Studio/Assistants/Dynamic/FileAttachmentState.cs b/app/MindWork AI Studio/Assistants/Dynamic/FileAttachmentState.cs new file mode 100644 index 00000000..9bda173e --- /dev/null +++ b/app/MindWork AI Studio/Assistants/Dynamic/FileAttachmentState.cs @@ -0,0 +1,8 @@ +using AIStudio.Chat; + +namespace AIStudio.Assistants.Dynamic; + +public sealed class FileAttachmentState +{ + public HashSet DocumentPaths { get; set; } = []; +} diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs index 23adc194..9fd0b5f8 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs @@ -1,4 +1,5 @@ using AIStudio.Assistants.Dynamic; +using AIStudio.Chat; using Lua; namespace AIStudio.Tools.PluginSystem.Assistants.DataModel; @@ -11,6 +12,7 @@ public sealed class AssistantState public readonly Dictionary Booleans = new(StringComparer.Ordinal); public readonly Dictionary WebContent = new(StringComparer.Ordinal); public readonly Dictionary FileContent = new(StringComparer.Ordinal); + public readonly Dictionary FileAttachments = new(StringComparer.Ordinal); public readonly Dictionary Colors = new(StringComparer.Ordinal); public readonly Dictionary Dates = new(StringComparer.Ordinal); public readonly Dictionary DateRanges = new(StringComparer.Ordinal); @@ -24,6 +26,7 @@ public sealed class AssistantState this.Booleans.Clear(); this.WebContent.Clear(); this.FileContent.Clear(); + this.FileAttachments.Clear(); this.Colors.Clear(); this.Dates.Clear(); this.DateRanges.Clear(); @@ -43,6 +46,7 @@ public sealed class AssistantState CopyDictionary(other.Booleans, this.Booleans); CopyDictionary(other.WebContent, this.WebContent); CopyDictionary(other.FileContent, this.FileContent); + CopyDictionary(other.FileAttachments, this.FileAttachments); CopyDictionary(other.Colors, this.Colors); CopyDictionary(other.Dates, this.Dates); CopyDictionary(other.DateRanges, this.DateRanges); @@ -143,6 +147,22 @@ public sealed class AssistantState return true; } + if (this.FileAttachments.TryGetValue(fieldName, out var fileAttachmentState)) + { + expectedType = "string[]"; + if (value.TryRead(out var fileAttachmentTable)) + { + fileAttachmentState.DocumentPaths = ReadFileAttachmentValues(fileAttachmentTable); + return true; + } + + if (!value.TryRead(out var fileAttachmentValue)) + return false; + + fileAttachmentState.DocumentPaths = string.IsNullOrWhiteSpace(fileAttachmentValue) ? [] : [FileAttachment.FromPath(fileAttachmentValue)]; + return true; + } + if (this.Colors.ContainsKey(fieldName)) { expectedType = "string"; @@ -231,6 +251,11 @@ public sealed class AssistantState return webContentValue.Content; if (this.FileContent.TryGetValue(name, out var fileContentValue)) return fileContentValue.Content; + if (this.FileAttachments.TryGetValue(name, out var fileAttachmentsValue)) + return AssistantLuaConversion.CreateLuaArray( + fileAttachmentsValue.DocumentPaths + .OrderBy(static attachment => attachment.FilePath, StringComparer.Ordinal) + .Select(static attachment => attachment.FilePath)); if (this.Colors.TryGetValue(name, out var colorValue)) return colorValue; if (this.Dates.TryGetValue(name, out var dateValue)) @@ -299,4 +324,17 @@ public sealed class AssistantState return parsedValues; } + + private static HashSet ReadFileAttachmentValues(LuaTable values) + { + var parsedValues = new HashSet(); + + foreach (var entry in values) + { + if (entry.Value.TryRead(out var value) && !string.IsNullOrWhiteSpace(value)) + parsedValues.Add(FileAttachment.FromPath(value)); + } + + return parsedValues; + } }