AI-Studio/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantComponentFactory.cs

52 lines
2.8 KiB
C#

using AIStudio.Tools.PluginSystem.Assistants.DataModel;
namespace AIStudio.Tools.PluginSystem.Assistants;
public class AssistantComponentFactory
{
private static readonly ILogger<AssistantComponentFactory> LOGGER = Program.LOGGER_FACTORY.CreateLogger<AssistantComponentFactory>();
public static IAssistantComponent CreateComponent(
AssistantComponentType type,
Dictionary<string, object> props,
List<IAssistantComponent> children)
{
switch (type)
{
case AssistantComponentType.FORM:
return new AssistantForm { Props = props, Children = children };
case AssistantComponentType.TEXT_AREA:
return new AssistantTextArea { Props = props, Children = children };
case AssistantComponentType.BUTTON:
return new AssistantButton { Props = props, Children = children};
case AssistantComponentType.BUTTON_GROUP:
return new AssistantButtonGroup { Props = props, Children = children };
case AssistantComponentType.DROPDOWN:
return new AssistantDropdown { Props = props, Children = children };
case AssistantComponentType.PROVIDER_SELECTION:
return new AssistantProviderSelection { Props = props, Children = children };
case AssistantComponentType.PROFILE_SELECTION:
return new AssistantProfileSelection { Props = props, Children = children };
case AssistantComponentType.SWITCH:
return new AssistantSwitch { Props = props, Children = children };
case AssistantComponentType.HEADING:
return new AssistantHeading { Props = props, Children = children };
case AssistantComponentType.TEXT:
return new AssistantText { Props = props, Children = children };
case AssistantComponentType.LIST:
return new AssistantList { Props = props, Children = children };
case AssistantComponentType.WEB_CONTENT_READER:
return new AssistantWebContentReader { Props = props, Children = children };
case AssistantComponentType.FILE_CONTENT_READER:
return new AssistantFileContentReader { Props = props, Children = children };
case AssistantComponentType.IMAGE:
return new AssistantImage { Props = props, Children = children };
case AssistantComponentType.COLOR_PICKER:
return new AssistantColorPicker { 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}");
}
}
}