diff --git a/app/MindWork AI Studio/Plugins/assistants/plugin.lua b/app/MindWork AI Studio/Plugins/assistants/plugin.lua index 58176671..3146f75d 100644 --- a/app/MindWork AI Studio/Plugins/assistants/plugin.lua +++ b/app/MindWork AI Studio/Plugins/assistants/plugin.lua @@ -54,15 +54,16 @@ ASSISTANT = { }, { Type = "Dropdown", + ValueType = "string", + Default = { Value = "", Display = "Sprache nicht angeben."} + Items = { + { Value = "de-DE", Display = "Deutsch" }, + { Value = "en-UK", Display = "Englisch (UK)" }, + { Value = "en-US", Display = "Englisch (US)" }, + }, Props = { Name = "language", Label = "Sprache", - Default = "Sprache nicht angeben", - Items = { - { Value = "de-DE", Display = "Deutsch" }, - { Value = "en-UK", Display = "Englisch (UK)" }, - { Value = "en-US", Display = "Englisch (US)" }, - } } }, { diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantComponentFactory.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantComponentFactory.cs new file mode 100644 index 00000000..c558d6b9 --- /dev/null +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantComponentFactory.cs @@ -0,0 +1,31 @@ +using AIStudio.Tools.PluginSystem.Assistants.DataModel; + +namespace AIStudio.Tools.PluginSystem.Assistants; + +public class AssistantComponentFactory +{ + private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(); + + public static IAssistantComponent CreateComponent( + AssistantUiCompontentType type, + Dictionary props, + List children) + { + switch (type) + { + case AssistantUiCompontentType.FORM: + return new AssistantForm { Props = props, Children = children }; + case AssistantUiCompontentType.TEXT_AREA: + return new AssistantTextArea { Props = props, Children = children }; + case AssistantUiCompontentType.BUTTON: + return new AssistantButton { Props = props, Children = children}; + case AssistantUiCompontentType.DROPDOWN: + return new AssistantDropdown { Props = props, Children = children }; + case AssistantUiCompontentType.PROVIDER_SELECTION: + return new AssistantProviderSelection { Props = props, Children = children }; + default: + LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type"); + throw new Exception($"Unknown assistant component type: {type}"); + } + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs index 4d06e6f1..b66fac79 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs @@ -8,17 +8,23 @@ public class AssistantButton : AssistantComponentBase public string Name { - get => this.Props.TryGetValue(nameof(this.Name), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Name), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Name)] = value; } public string Text { - get => this.Props.TryGetValue(nameof(this.Text), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Text), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Text)] = value; } public string Action { - get => this.Props.TryGetValue(nameof(this.Action), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Action), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Action)] = value; } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs index 59ea60f3..fa28202c 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs @@ -5,25 +5,68 @@ public class AssistantDropdown : AssistantComponentBase public override AssistantUiCompontentType Type => AssistantUiCompontentType.DROPDOWN; public Dictionary Props { get; set; } = new(); public List Children { get; set; } = new(); - + public string Name { - get => this.Props.TryGetValue(nameof(this.Name), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Name), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Name)] = value; } public string Label { - get => this.Props.TryGetValue(nameof(this.Label), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Label), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Label)] = value; } - public string Default + public AssistantDropdownItem Default { - get => this.Props.TryGetValue(nameof(this.Default), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get + { + if (this.Props.TryGetValue(nameof(this.Default), out var v) && v is AssistantDropdownItem adi) + return adi; + + return this.Items.Count > 0 ? this.Items[0] : AssistantDropdownItem.Default(); + } set => this.Props[nameof(this.Default)] = value; } + public List Items { - get => this.Props.TryGetValue(nameof(this.Items), out var v) && v is List list ? list : []; + get => this.Props.TryGetValue(nameof(this.Items), out var v) && v is List list + ? list + : []; set => this.Props[nameof(this.Items)] = value; } + + public string ValueType + { + get => this.Props.TryGetValue(nameof(this.ValueType), out var v) + ? v.ToString() ?? "string" + : "string"; + set => this.Props[nameof(this.ValueType)] = value; + } + + public IEnumerable GetParsedDropdownValues() + { + foreach (var item in this.Items) + { + switch (this.ValueType.ToLowerInvariant()) + { + case "int": + if (int.TryParse(item.Value, out var i)) yield return i; + break; + case "double": + if (double.TryParse(item.Value, out var d)) yield return d; + break; + case "bool": + if (bool.TryParse(item.Value, out var b)) yield return b; + break; + default: + yield return item.Value; + break; + } + } + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdownItem.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdownItem.cs index 0f07cc97..91e2831f 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdownItem.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdownItem.cs @@ -4,4 +4,6 @@ public class AssistantDropdownItem { public string Value { get; set; } = string.Empty; public string Display { get; set; } = string.Empty; + + public static AssistantDropdownItem Default() => new() { Value = string.Empty, Display = string.Empty }; } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantProviderSelection.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantProviderSelection.cs index e53095a9..9767cd1b 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantProviderSelection.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantProviderSelection.cs @@ -8,12 +8,16 @@ public class AssistantProviderSelection : AssistantComponentBase public string Name { - get => this.Props.TryGetValue(nameof(this.Name), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Name), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Name)] = value; } public string Label { - get => this.Props.TryGetValue(nameof(this.Label), out var v) ? v.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Label), out var v) + ? v.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Label)] = value; } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs index 9fb7e31a..d51c131f 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs @@ -8,13 +8,17 @@ public class AssistantTextArea : AssistantComponentBase public string Name { - get => this.Props.TryGetValue(nameof(this.Name), out var val) ? val.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Name), out var val) + ? val.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Name)] = value; } public string Label { - get => this.Props.TryGetValue(nameof(this.Label), out var val) ? val.ToString() ?? string.Empty : string.Empty; + get => this.Props.TryGetValue(nameof(this.Label), out var val) + ? val.ToString() ?? string.Empty + : string.Empty; set => this.Props[nameof(this.Label)] = value; } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantUiCompontentType.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantUiCompontentType.cs index 37206a13..73973145 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantUiCompontentType.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantUiCompontentType.cs @@ -5,7 +5,6 @@ public enum AssistantUiCompontentType FORM, TEXT_AREA, BUTTON, - CHECKBOX, DROPDOWN, PROVIDER_SELECTION, } \ No newline at end of file