2026-03-10 10:45:15 +00:00
|
|
|
using AIStudio.Tools.PluginSystem.Assistants.Icons;
|
2026-03-16 13:15:29 +00:00
|
|
|
using Lua;
|
2026-03-10 10:45:15 +00:00
|
|
|
|
2026-02-24 16:21:50 +00:00
|
|
|
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
|
|
|
|
|
2026-03-19 23:49:21 +00:00
|
|
|
public sealed class AssistantSwitch : StatefulAssistantComponentBase
|
2025-11-11 18:06:44 +00:00
|
|
|
{
|
2026-02-24 10:39:17 +00:00
|
|
|
public override AssistantComponentType Type => AssistantComponentType.SWITCH;
|
2026-03-03 14:44:31 +00:00
|
|
|
public override Dictionary<string, object> Props { get; set; } = new();
|
|
|
|
|
public override List<IAssistantComponent> Children { get; set; } = new();
|
2025-11-11 18:06:44 +00:00
|
|
|
|
|
|
|
|
public string Label
|
|
|
|
|
{
|
2026-02-24 16:21:50 +00:00
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Label));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Label), value);
|
2025-11-11 18:06:44 +00:00
|
|
|
}
|
2026-02-24 16:21:50 +00:00
|
|
|
|
2025-11-11 18:06:44 +00:00
|
|
|
public bool Value
|
|
|
|
|
{
|
2026-03-09 17:56:38 +00:00
|
|
|
get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Value), false);
|
|
|
|
|
set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Value), value);
|
2025-11-11 18:06:44 +00:00
|
|
|
}
|
2026-03-10 10:45:15 +00:00
|
|
|
|
|
|
|
|
public bool Disabled
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Disabled), false);
|
|
|
|
|
set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Disabled), value);
|
|
|
|
|
}
|
2026-03-16 13:15:29 +00:00
|
|
|
|
|
|
|
|
public LuaFunction? OnChanged
|
|
|
|
|
{
|
|
|
|
|
get => this.Props.TryGetValue(nameof(this.OnChanged), out var value) && value is LuaFunction onChanged ? onChanged : null;
|
|
|
|
|
set => AssistantComponentPropHelper.WriteObject(this.Props, nameof(this.OnChanged), value);
|
|
|
|
|
}
|
2026-02-24 16:21:50 +00:00
|
|
|
|
2025-11-11 18:06:44 +00:00
|
|
|
public string LabelOn
|
|
|
|
|
{
|
2026-02-24 16:21:50 +00:00
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.LabelOn));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.LabelOn), value);
|
2025-11-11 18:06:44 +00:00
|
|
|
}
|
2026-02-24 16:21:50 +00:00
|
|
|
|
2025-11-11 18:06:44 +00:00
|
|
|
public string LabelOff
|
|
|
|
|
{
|
2026-02-24 16:21:50 +00:00
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.LabelOff));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.LabelOff), value);
|
|
|
|
|
}
|
2026-03-10 10:45:15 +00:00
|
|
|
|
|
|
|
|
public string LabelPlacement
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.LabelPlacement));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.LabelPlacement), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CheckedColor
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.CheckedColor));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.CheckedColor), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string UncheckedColor
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.UncheckedColor));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.UncheckedColor), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Icon
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Icon));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Icon), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string IconColor
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.IconColor));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.IconColor), value);
|
|
|
|
|
}
|
2026-03-10 12:12:46 +00:00
|
|
|
|
|
|
|
|
public string Class
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Class));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Class), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Style
|
|
|
|
|
{
|
|
|
|
|
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Style));
|
|
|
|
|
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Style), value);
|
|
|
|
|
}
|
2026-02-24 16:21:50 +00:00
|
|
|
|
2026-03-19 23:49:21 +00:00
|
|
|
#region Implementation of IStatefulAssistantComponent
|
|
|
|
|
|
|
|
|
|
public override void InitializeState(AssistantState state)
|
|
|
|
|
{
|
|
|
|
|
if (!state.Bools.ContainsKey(this.Name))
|
|
|
|
|
state.Bools[this.Name] = this.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string UserPromptFallback(AssistantState state)
|
|
|
|
|
{
|
|
|
|
|
var promptFragment = $"{Environment.NewLine}context:{Environment.NewLine}{this.UserPrompt}{Environment.NewLine}---{Environment.NewLine}";
|
2026-03-22 19:41:30 +00:00
|
|
|
state.Bools.TryGetValue(this.Name, out var userDecision);
|
2026-03-19 23:49:21 +00:00
|
|
|
promptFragment += $"user decision: {userDecision}";
|
|
|
|
|
|
|
|
|
|
return promptFragment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2026-03-10 10:45:15 +00:00
|
|
|
public MudBlazor.Color GetColor(string colorString) => Enum.TryParse<Color>(colorString, out var color) ? color : MudBlazor.Color.Inherit;
|
|
|
|
|
public Placement GetLabelPlacement() => Enum.TryParse<Placement>(this.LabelPlacement, out var placement) ? placement : Placement.Right;
|
|
|
|
|
public string GetIconSvg() => MudBlazorIconRegistry.TryGetSvg(this.Icon, out var svg) ? svg : string.Empty;
|
2026-02-24 16:21:50 +00:00
|
|
|
}
|