@attribute [Route(Routes.ASSISTANT_DYNAMIC)] @using AIStudio.Components @using AIStudio.Settings @using AIStudio.Tools.PluginSystem.Assistants.DataModel @using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout @inherits AssistantBaseCore @foreach (var component in this.RootComponent!.Children) { @this.RenderComponent(component) } @code { private RenderFragment RenderChildren(IEnumerable children) => @ @foreach (var child in children) { @this.RenderComponent(child) } ; private RenderFragment RenderComponent(IAssistantComponent component) => @ @switch (component.Type) { case AssistantComponentType.TEXT_AREA: if (component is AssistantTextArea textArea) { var lines = textArea.IsSingleLine ? 1 : 6; } break; case AssistantComponentType.IMAGE: if (component is AssistantImage assistantImage) { var resolvedSource = this.ResolveImageSource(assistantImage); if (!string.IsNullOrWhiteSpace(resolvedSource)) { var image = assistantImage;
@if (!string.IsNullOrWhiteSpace(image.Caption)) { @image.Caption }
} } break; case AssistantComponentType.WEB_CONTENT_READER: if (component is AssistantWebContentReader webContent && this.webContentFields.TryGetValue(webContent.Name, out var webState)) {
} break; case AssistantComponentType.FILE_CONTENT_READER: if (component is AssistantFileContentReader fileContent && this.fileContentFields.TryGetValue(fileContent.Name, out var fileState)) {
} break; case AssistantComponentType.DROPDOWN: if (component is AssistantDropdown assistantDropdown) { } break; case AssistantComponentType.BUTTON: if (component is AssistantButton assistantButton) { var button = assistantButton;
@button.Text
} break; case AssistantComponentType.BUTTON_GROUP: if (component is AssistantButtonGroup assistantButtonGroup) { var buttonGroup = assistantButtonGroup; @this.RenderChildren(buttonGroup.Children) } break; case AssistantComponentType.LAYOUT_GRID: if (component is AssistantGrid assistantGrid) { var grid = assistantGrid; @this.RenderChildren(grid.Children) } break; case AssistantComponentType.LAYOUT_ITEM: if (component is AssistantItem assistantItem) { @this.RenderLayoutItem(assistantItem) } break; case AssistantComponentType.LAYOUT_PAPER: if (component is AssistantPaper assistantPaper) { var paper = assistantPaper; @this.RenderChildren(paper.Children) } break; case AssistantComponentType.LAYOUT_STACK: if (component is AssistantStack assistantStack) { var stack = assistantStack; @this.RenderChildren(stack.Children) } break; case AssistantComponentType.PROVIDER_SELECTION: if (component is AssistantProviderSelection providerSelection) {
} break; case AssistantComponentType.PROFILE_SELECTION: if (component is AssistantProfileSelection profileSelection) { var selection = profileSelection;
} break; case AssistantComponentType.SWITCH: if (component is AssistantSwitch switchComponent) { var assistantSwitch = switchComponent; var currentValue = this.switchFields[assistantSwitch.Name]; @(currentValue ? assistantSwitch.LabelOn : assistantSwitch.LabelOff) } break; case AssistantComponentType.HEADING: if (component is AssistantHeading assistantHeading) { var heading = assistantHeading; @switch (assistantHeading.Level) { case 1: @heading.Text break; case 2: @heading.Text break; case 3: @heading.Text break; default: @heading.Text break; } } break; case AssistantComponentType.TEXT: if (component is AssistantText assistantText) { var text = assistantText; @text.Content } break; case AssistantComponentType.LIST: if (component is AssistantList assistantList) { var list = assistantList; @foreach (var item in list.Items) { @if (item.Type == "LINK") { @item.Text } else { @item.Text } } } break; case AssistantComponentType.COLOR_PICKER: if (component is AssistantColorPicker assistantColorPicker) { var colorPicker = assistantColorPicker; var variant = colorPicker.GetPickerVariant(); var elevation = variant == PickerVariant.Static ? 6 : 0; var rounded = variant == PickerVariant.Static; } break; }
; private string? GetRawStyle(IAssistantComponent component) { if (!component.Props.TryGetValue("Style", out var rawStyle) || rawStyle is null) return null; return rawStyle as string ?? rawStyle.ToString(); } private string? BuildPaperStyle(AssistantPaper paper) { List styles = []; this.AddStyle(styles, "height", paper.Height); this.AddStyle(styles, "max-height", paper.MaxHeight); this.AddStyle(styles, "min-height", paper.MinHeight); this.AddStyle(styles, "width", paper.Width); this.AddStyle(styles, "max-width", paper.MaxWidth); this.AddStyle(styles, "min-width", paper.MinWidth); var customStyle = this.GetRawStyle(paper); if (!string.IsNullOrWhiteSpace(customStyle)) styles.Add(customStyle.Trim().TrimEnd(';')); return styles.Count == 0 ? null : string.Join("; ", styles); } private RenderFragment RenderLayoutItem(AssistantItem item) => builder => { builder.OpenComponent(0); if (item.Xs.HasValue) builder.AddAttribute(1, "xs", item.Xs.Value); if (item.Sm.HasValue) builder.AddAttribute(2, "sm", item.Sm.Value); if (item.Md.HasValue) builder.AddAttribute(3, "md", item.Md.Value); if (item.Lg.HasValue) builder.AddAttribute(4, "lg", item.Lg.Value); if (item.Xl.HasValue) builder.AddAttribute(5, "xl", item.Xl.Value); if (item.Xxl.HasValue) builder.AddAttribute(6, "xxl", item.Xxl.Value); var itemClass = item.Class; if (!string.IsNullOrWhiteSpace(itemClass)) builder.AddAttribute(7, nameof(MudItem.Class), itemClass); var itemStyle = this.GetOptionalStyle(item.Style); if (!string.IsNullOrWhiteSpace(itemStyle)) builder.AddAttribute(8, nameof(MudItem.Style), itemStyle); builder.AddAttribute(9, nameof(MudItem.ChildContent), this.RenderChildren(item.Children)); builder.CloseComponent(); }; private void AddStyle(List styles, string key, string value) { if (!string.IsNullOrWhiteSpace(value)) styles.Add($"{key}: {value.Trim().TrimEnd(';')}"); } }