mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 23:38:00 +00:00
Added assistant plugins (#659)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
1 parent
a573409a24
commit
f6a128f2e4
100 files changed
+10146
-85
No files matched your search
@@ -0,0 +1,590 @@
|
||||
@attribute [Route(Routes.ASSISTANT_DYNAMIC)]
|
||||
@using AIStudio.Agents.AssistantAudit
|
||||
@using AIStudio.Tools.PluginSystem.Assistants.DataModel
|
||||
@using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout
|
||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.NoSettingsPanel>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(this.securityMessage))
|
||||
{
|
||||
<MudPaper Class="pa-4 ma-4" Elevation="0">
|
||||
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Square="false" Elevation="6" Class="pa-4">
|
||||
@this.securityMessage
|
||||
</MudAlert>
|
||||
@if (this.assistantPlugin is not null)
|
||||
{
|
||||
<div class="mt-4">
|
||||
<AssistantPluginSecurityCard Plugin="@this.assistantPlugin"/>
|
||||
</div>
|
||||
}
|
||||
</MudPaper>
|
||||
}
|
||||
else if (this.RootComponent is null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning">
|
||||
@this.T("No assistant plugin are currently installed.")
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (this.audit is not null && this.audit.Level is not AssistantAuditLevel.SAFE)
|
||||
{
|
||||
<MudPaper Class="pa-4 ma-4" Elevation="0">
|
||||
<MudAlert Severity="@this.audit.Level.GetSeverity()" Variant="Variant.Filled" Square="false" Elevation="6" Class="pa-4">
|
||||
<strong>@this.audit.Level.GetName().ToUpperInvariant(): </strong>@this.audit.Summary
|
||||
</MudAlert>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
@foreach (var component in this.RootComponent.Children)
|
||||
{
|
||||
@this.RenderComponent(component)
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
private RenderFragment RenderSwitch(AssistantSwitch assistantSwitch) => @<MudSwitch T="bool"
|
||||
Value="@this.assistantState.Booleans[assistantSwitch.Name]"
|
||||
ValueChanged="@(value => this.ExecuteSwitchChangedAsync(assistantSwitch, value))"
|
||||
LabelPlacement="@assistantSwitch.GetLabelPlacement()"
|
||||
Color="@AssistantSwitch.GetColor(assistantSwitch.CheckedColor)"
|
||||
UncheckedColor="@AssistantSwitch.GetColor(assistantSwitch.UncheckedColor)"
|
||||
ThumbIcon="@assistantSwitch.GetIconSvg()"
|
||||
ThumbIconColor="@AssistantSwitch.GetColor(assistantSwitch.IconColor)"
|
||||
Disabled="@(assistantSwitch.Disabled || this.IsSwitchActionRunning(assistantSwitch.Name))"
|
||||
Class="@assistantSwitch.Class"
|
||||
Style="@GetOptionalStyle(assistantSwitch.Style)">
|
||||
@(this.assistantState.Booleans[assistantSwitch.Name] ? assistantSwitch.LabelOn : assistantSwitch.LabelOff)
|
||||
</MudSwitch>;
|
||||
}
|
||||
|
||||
@code {private RenderFragment RenderChildren(IEnumerable<IAssistantComponent> children) => @<text>
|
||||
@foreach (var child in children)
|
||||
{
|
||||
@this.RenderComponent(child)
|
||||
}
|
||||
</text>;
|
||||
|
||||
private RenderFragment RenderComponent(IAssistantComponent component) => @<text>
|
||||
@switch (component.Type)
|
||||
{
|
||||
case AssistantComponentType.TEXT_AREA:
|
||||
if (component is AssistantTextArea textArea)
|
||||
{
|
||||
var lines = textArea.IsSingleLine ? 1 : 6;
|
||||
var autoGrow = !textArea.IsSingleLine;
|
||||
|
||||
<MudTextField T="string"
|
||||
Text="@this.assistantState.Text[textArea.Name]"
|
||||
TextChanged="@(value => this.assistantState.Text[textArea.Name] = value)"
|
||||
Label="@textArea.Label"
|
||||
HelperText="@textArea.HelperText"
|
||||
HelperTextOnFocus="@textArea.HelperTextOnFocus"
|
||||
ReadOnly="@textArea.ReadOnly"
|
||||
Counter="@textArea.Counter"
|
||||
MaxLength="@textArea.MaxLength"
|
||||
Immediate="@textArea.IsImmediate"
|
||||
Adornment="@textArea.GetAdornmentPos()"
|
||||
AdornmentIcon="@AssistantComponentPropHelper.GetIconSvg(textArea.AdornmentIcon)"
|
||||
AdornmentText="@textArea.AdornmentText"
|
||||
AdornmentColor="@textArea.GetAdornmentColor()"
|
||||
Variant="Variant.Outlined"
|
||||
Lines="@lines"
|
||||
AutoGrow="@autoGrow"
|
||||
MaxLines="12"
|
||||
Class='@MergeClass(textArea.Class, "mb-3")'
|
||||
Style="@GetOptionalStyle(textArea.Style)" />
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.IMAGE:
|
||||
if (component is AssistantImage assistantImage)
|
||||
{
|
||||
var resolvedSource = this.ResolveImageSource(assistantImage);
|
||||
if (!string.IsNullOrWhiteSpace(resolvedSource))
|
||||
{
|
||||
var image = assistantImage;
|
||||
<div Class="mb-4">
|
||||
<MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@GetOptionalStyle(image.Style)" Elevation="20" />
|
||||
@if (!string.IsNullOrWhiteSpace(image.Caption))
|
||||
{
|
||||
<MudText Typo="Typo.caption" Align="Align.Center">@image.Caption</MudText>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.WEB_CONTENT_READER:
|
||||
if (component is AssistantWebContentReader webContent)
|
||||
{
|
||||
var webState = this.assistantState.WebContent[webContent.Name];
|
||||
<div class="@webContent.Class" style="@GetOptionalStyle(webContent.Style)">
|
||||
<ReadWebContent @bind-Content="@webState.Content"
|
||||
ProviderSettings="@this.providerSettings"
|
||||
@bind-AgentIsRunning="@webState.AgentIsRunning"
|
||||
@bind-Preselect="@webState.Preselect"
|
||||
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent" />
|
||||
</div>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.FILE_CONTENT_READER:
|
||||
if (component is AssistantFileContentReader fileContent)
|
||||
{
|
||||
var fileState = this.assistantState.FileContent[fileContent.Name];
|
||||
<div class="@fileContent.Class" style="@GetOptionalStyle(fileContent.Style)">
|
||||
<ReadFileContent @bind-FileContent="@fileState.Content" />
|
||||
</div>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.DROPDOWN:
|
||||
if (component is AssistantDropdown assistantDropdown)
|
||||
{
|
||||
if (assistantDropdown.IsMultiselect)
|
||||
{
|
||||
<DynamicAssistantDropdown Items="@assistantDropdown.Items"
|
||||
SelectedValues="@this.assistantState.MultiSelect[assistantDropdown.Name]"
|
||||
SelectedValuesChanged="@this.CreateMultiselectDropdownChangedCallback(assistantDropdown.Name)"
|
||||
Default="@assistantDropdown.Default"
|
||||
Label="@assistantDropdown.Label"
|
||||
HelperText="@assistantDropdown.HelperText"
|
||||
OpenIcon="@AssistantComponentPropHelper.GetIconSvg(assistantDropdown.OpenIcon)"
|
||||
CloseIcon="@AssistantComponentPropHelper.GetIconSvg(assistantDropdown.CloseIcon)"
|
||||
IconColor="@AssistantComponentPropHelper.GetColor(assistantDropdown.IconColor, Color.Default)"
|
||||
IconPosition="@AssistantComponentPropHelper.GetAdornment(assistantDropdown.IconPositon, Adornment.End)"
|
||||
Variant="@AssistantComponentPropHelper.GetVariant(assistantDropdown.Variant, Variant.Outlined)"
|
||||
IsMultiselect="@true"
|
||||
HasSelectAll="@assistantDropdown.HasSelectAll"
|
||||
SelectAllText="@assistantDropdown.SelectAllText"
|
||||
Class="@assistantDropdown.Class"
|
||||
Style="@GetOptionalStyle(assistantDropdown.Style)" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<DynamicAssistantDropdown Items="@assistantDropdown.Items"
|
||||
Value="@this.assistantState.SingleSelect[assistantDropdown.Name]"
|
||||
ValueChanged="@(value => this.assistantState.SingleSelect[assistantDropdown.Name] = value)"
|
||||
Default="@assistantDropdown.Default"
|
||||
Label="@assistantDropdown.Label"
|
||||
HelperText="@assistantDropdown.HelperText"
|
||||
OpenIcon="@AssistantComponentPropHelper.GetIconSvg(assistantDropdown.OpenIcon)"
|
||||
CloseIcon="@AssistantComponentPropHelper.GetIconSvg(assistantDropdown.CloseIcon)"
|
||||
IconColor="@AssistantComponentPropHelper.GetColor(assistantDropdown.IconColor, Color.Default)"
|
||||
IconPosition="@AssistantComponentPropHelper.GetAdornment(assistantDropdown.IconPositon, Adornment.End)"
|
||||
Variant="@AssistantComponentPropHelper.GetVariant(assistantDropdown.Variant, Variant.Outlined)"
|
||||
HasSelectAll="@assistantDropdown.HasSelectAll"
|
||||
SelectAllText="@assistantDropdown.SelectAllText"
|
||||
Class="@assistantDropdown.Class"
|
||||
Style="@GetOptionalStyle(assistantDropdown.Style)" />
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.BUTTON:
|
||||
if (component is AssistantButton assistantButton)
|
||||
{
|
||||
var button = assistantButton;
|
||||
var icon = AssistantComponentPropHelper.GetIconSvg(button.StartIcon);
|
||||
var iconColor = AssistantComponentPropHelper.GetColor(button.IconColor, Color.Inherit);
|
||||
var color = AssistantComponentPropHelper.GetColor(button.Color, Color.Default);
|
||||
var size = AssistantComponentPropHelper.GetComponentSize(button.Size, Size.Medium);
|
||||
var iconSize = AssistantComponentPropHelper.GetComponentSize(button.IconSize, Size.Medium);
|
||||
var variant = button.GetButtonVariant();
|
||||
var disabled = this.IsButtonActionRunning(button.Name);
|
||||
var buttonClass = MergeClass(button.Class, "");
|
||||
var style = GetOptionalStyle(button.Style);
|
||||
|
||||
if (!button.IsIconButton)
|
||||
{
|
||||
<MudButton Variant="@variant"
|
||||
Color="@color"
|
||||
OnClick="@(() => this.ExecuteButtonActionAsync(button))"
|
||||
Size="@size"
|
||||
FullWidth="@button.IsFullWidth"
|
||||
StartIcon="@icon"
|
||||
EndIcon="@AssistantComponentPropHelper.GetIconSvg(button.EndIcon)"
|
||||
IconColor="@iconColor"
|
||||
IconSize="@iconSize"
|
||||
Disabled="@disabled"
|
||||
Class="@buttonClass"
|
||||
Style="@style">
|
||||
@button.Text
|
||||
</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudIconButton Icon="@icon"
|
||||
Color="@color"
|
||||
Variant="@variant"
|
||||
Size="@size"
|
||||
OnClick="@(() => this.ExecuteButtonActionAsync(button))"
|
||||
Disabled="@disabled"
|
||||
Class="@buttonClass"
|
||||
Style="@style" />
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.BUTTON_GROUP:
|
||||
if (component is AssistantButtonGroup assistantButtonGroup)
|
||||
{
|
||||
var buttonGroup = assistantButtonGroup;
|
||||
<MudButtonGroup Variant="@buttonGroup.GetVariant()"
|
||||
Color="@AssistantComponentPropHelper.GetColor(buttonGroup.Color, Color.Default)"
|
||||
Size="@AssistantComponentPropHelper.GetComponentSize(buttonGroup.Size, Size.Medium)"
|
||||
OverrideStyles="@buttonGroup.OverrideStyles"
|
||||
Vertical="@buttonGroup.Vertical"
|
||||
DropShadow="@buttonGroup.DropShadow"
|
||||
Class='@MergeClass(buttonGroup.Class, "mb-3")'
|
||||
Style="@GetOptionalStyle(buttonGroup.Style)">
|
||||
@this.RenderChildren(buttonGroup.Children)
|
||||
</MudButtonGroup>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.LAYOUT_GRID:
|
||||
if (component is AssistantGrid assistantGrid)
|
||||
{
|
||||
var grid = assistantGrid;
|
||||
<MudGrid Justify="@(AssistantComponentPropHelper.GetJustify(grid.Justify) ?? Justify.FlexStart)"
|
||||
Spacing="@grid.Spacing"
|
||||
Class="@grid.Class"
|
||||
Style="@GetOptionalStyle(grid.Style)">
|
||||
@this.RenderChildren(grid.Children)
|
||||
</MudGrid>
|
||||
}
|
||||
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;
|
||||
<MudPaper Elevation="@paper.Elevation"
|
||||
Outlined="@paper.IsOutlined"
|
||||
Square="@paper.IsSquare"
|
||||
Class="@paper.Class"
|
||||
Style="@this.BuildPaperStyle(paper)">
|
||||
@this.RenderChildren(paper.Children)
|
||||
</MudPaper>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.LAYOUT_STACK:
|
||||
if (component is AssistantStack assistantStack)
|
||||
{
|
||||
var stack = assistantStack;
|
||||
<MudStack Row="@stack.IsRow"
|
||||
Reverse="@stack.IsReverse"
|
||||
Breakpoint="@AssistantComponentPropHelper.GetBreakpoint(stack.Breakpoint, Breakpoint.None)"
|
||||
AlignItems="@(AssistantComponentPropHelper.GetItemsAlignment(stack.Align) ?? AlignItems.Stretch)"
|
||||
Justify="@(AssistantComponentPropHelper.GetJustify(stack.Justify) ?? Justify.FlexStart)"
|
||||
StretchItems="@(AssistantComponentPropHelper.GetStretching(stack.Stretch) ?? StretchItems.None)"
|
||||
Wrap="@(AssistantComponentPropHelper.GetWrap(stack.Wrap) ?? Wrap.Wrap)"
|
||||
Spacing="@stack.Spacing"
|
||||
Class="@stack.Class"
|
||||
Style="@GetOptionalStyle(stack.Style)">
|
||||
@this.RenderChildren(stack.Children)
|
||||
</MudStack>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.LAYOUT_ACCORDION:
|
||||
if (component is AssistantAccordion assistantAccordion)
|
||||
{
|
||||
var accordion = assistantAccordion;
|
||||
<MudExpansionPanels MultiExpansion="@accordion.AllowMultiSelection"
|
||||
Dense="@accordion.IsDense"
|
||||
Outlined="@accordion.HasOutline"
|
||||
Square="@accordion.IsSquare"
|
||||
Elevation="@accordion.Elevation"
|
||||
Gutters="@accordion.HasSectionPaddings"
|
||||
Class="@MergeClass(accordion.Class, "my-6")"
|
||||
Style="@GetOptionalStyle(accordion.Style)">
|
||||
@this.RenderChildren(accordion.Children)
|
||||
</MudExpansionPanels>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.LAYOUT_ACCORDION_SECTION:
|
||||
if (component is AssistantAccordionSection assistantAccordionSection)
|
||||
{
|
||||
var accordionSection = assistantAccordionSection;
|
||||
var textColor = accordionSection.IsDisabled ? Color.Info : AssistantComponentPropHelper.GetColor(accordionSection.HeaderColor, Color.Inherit);
|
||||
<MudExpansionPanel KeepContentAlive="@accordionSection.KeepContentAlive"
|
||||
disabled="@accordionSection.IsDisabled"
|
||||
Expanded="@accordionSection.IsExpanded"
|
||||
Dense="@accordionSection.IsDense"
|
||||
Gutters="@accordionSection.HasInnerPadding"
|
||||
HideIcon="@accordionSection.HideIcon"
|
||||
Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.ExpandIcon)"
|
||||
MaxHeight="@accordionSection.MaxHeight"
|
||||
Class="@accordionSection.Class"
|
||||
Style="@GetOptionalStyle(accordionSection.Style)">
|
||||
<TitleContent>
|
||||
<div class="d-flex">
|
||||
<MudIcon Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.HeaderIcon)" class="mr-3"></MudIcon>
|
||||
<MudText Align="@AssistantComponentPropHelper.GetAlignment(accordionSection.HeaderAlign)"
|
||||
Color="@textColor"
|
||||
Typo="@AssistantComponentPropHelper.GetTypography(accordionSection.HeaderTypo)">
|
||||
@accordionSection.HeaderText
|
||||
</MudText>
|
||||
</div>
|
||||
</TitleContent>
|
||||
<ChildContent>
|
||||
@this.RenderChildren(accordionSection.Children)
|
||||
</ChildContent>
|
||||
</MudExpansionPanel>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.PROVIDER_SELECTION:
|
||||
if (component is AssistantProviderSelection providerSelection)
|
||||
{
|
||||
<div class="@providerSelection.Class" style="@GetOptionalStyle(providerSelection.Style)">
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider" />
|
||||
</div>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.PROFILE_SELECTION:
|
||||
if (component is AssistantProfileSelection profileSelection)
|
||||
{
|
||||
var selection = profileSelection;
|
||||
<div class="@selection.Class" style="@GetOptionalStyle(selection.Style)">
|
||||
<ProfileFormSelection Validation="@(profile => this.ValidateProfileSelection(selection, profile))" @bind-Profile="@this.currentProfile" />
|
||||
</div>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.SWITCH:
|
||||
if (component is AssistantSwitch switchComponent)
|
||||
{
|
||||
var assistantSwitch = switchComponent;
|
||||
|
||||
if (string.IsNullOrEmpty(assistantSwitch.Label))
|
||||
{
|
||||
@this.RenderSwitch(assistantSwitch)
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudField Label="@assistantSwitch.Label" Variant="Variant.Outlined" Class="mb-3" Disabled="@assistantSwitch.Disabled">
|
||||
@this.RenderSwitch(assistantSwitch)
|
||||
</MudField>
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.HEADING:
|
||||
if (component is AssistantHeading assistantHeading)
|
||||
{
|
||||
var heading = assistantHeading;
|
||||
var typo = heading.Level switch
|
||||
{
|
||||
1 => Typo.h4,
|
||||
2 => Typo.h5,
|
||||
3 => Typo.h6,
|
||||
_ => Typo.h5
|
||||
};
|
||||
|
||||
<MudText Typo="@typo" Class="@heading.Class" Style="@GetOptionalStyle(heading.Style)">@heading.Text</MudText>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.TEXT:
|
||||
if (component is AssistantText assistantText)
|
||||
{
|
||||
var text = assistantText;
|
||||
<MudText Typo="Typo.body1" Class='@MergeClass(text.Class, "mb-3")' Style="@GetOptionalStyle(text.Style)">@text.Content</MudText>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.LIST:
|
||||
if (component is AssistantList assistantList)
|
||||
{
|
||||
var list = assistantList;
|
||||
<MudList T="string" Class='@MergeClass(list.Class, "mb-6")' Style="@GetOptionalStyle(list.Style)">
|
||||
@foreach (var item in list.Items)
|
||||
{
|
||||
var iconColor = AssistantComponentPropHelper.GetColor(item.IconColor, Color.Default);
|
||||
|
||||
@if (item.Type == "LINK")
|
||||
{
|
||||
<MudListItem T="string" Icon="@Icons.Material.Filled.Link" IconColor="@iconColor" Target="_blank" Href="@item.Href">@item.Text</MudListItem>
|
||||
}
|
||||
else
|
||||
{
|
||||
var icon = !string.IsNullOrEmpty(item.Icon) ? AssistantComponentPropHelper.GetIconSvg(item.Icon) : string.Empty;
|
||||
<MudListItem T="string" Icon="@icon" IconColor="@iconColor">@item.Text</MudListItem>
|
||||
}
|
||||
}
|
||||
</MudList>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.COLOR_PICKER:
|
||||
if (component is AssistantColorPicker assistantColorPicker)
|
||||
{
|
||||
var colorPicker = assistantColorPicker;
|
||||
var variant = colorPicker.GetPickerVariant();
|
||||
var rounded = variant == PickerVariant.Static;
|
||||
|
||||
<MudItem Class="d-flex">
|
||||
<MudColorPicker Text="@this.assistantState.Colors[colorPicker.Name]"
|
||||
TextChanged="@(value => this.assistantState.Colors[colorPicker.Name] = value)"
|
||||
Label="@colorPicker.Label"
|
||||
Placeholder="@colorPicker.Placeholder"
|
||||
ShowAlpha="@colorPicker.ShowAlpha"
|
||||
ShowToolbar="@colorPicker.ShowToolbar"
|
||||
ShowModeSwitch="@colorPicker.ShowModeSwitch"
|
||||
PickerVariant="@variant"
|
||||
Rounded="@rounded"
|
||||
Elevation="@colorPicker.Elevation"
|
||||
Style="@($"color: {this.assistantState.Colors[colorPicker.Name]};{colorPicker.Style}")"
|
||||
Class="@MergeClass(colorPicker.Class, "mb-3")" />
|
||||
</MudItem>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.DATE_PICKER:
|
||||
if (component is AssistantDatePicker assistantDatePicker)
|
||||
{
|
||||
var datePicker = assistantDatePicker;
|
||||
var format = datePicker.GetDateFormat();
|
||||
|
||||
<MudPaper Class="d-flex" Elevation="0">
|
||||
<MudDatePicker Date="@datePicker.ParseValue(this.assistantState.Dates[datePicker.Name])"
|
||||
DateChanged="@(value => this.assistantState.Dates[datePicker.Name] = datePicker.FormatValue(value))"
|
||||
Label="@datePicker.Label"
|
||||
Color="@AssistantComponentPropHelper.GetColor(datePicker.Color, Color.Primary)"
|
||||
Placeholder="@datePicker.Placeholder"
|
||||
HelperText="@datePicker.HelperText"
|
||||
DateFormat="@format"
|
||||
Elevation="@datePicker.Elevation"
|
||||
PickerVariant="@AssistantComponentPropHelper.GetPickerVariant(datePicker.PickerVariant, PickerVariant.Static)"
|
||||
Variant="Variant.Outlined"
|
||||
Class='@MergeClass(datePicker.Class, "mb-3")'
|
||||
Style="@GetOptionalStyle(datePicker.Style)"
|
||||
/>
|
||||
</MudPaper>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.DATE_RANGE_PICKER:
|
||||
if (component is AssistantDateRangePicker assistantDateRangePicker)
|
||||
{
|
||||
var dateRangePicker = assistantDateRangePicker;
|
||||
var format = dateRangePicker.GetDateFormat();
|
||||
|
||||
<MudPaper Class="d-flex" Elevation="0">
|
||||
@* ReSharper disable CSharpWarnings::CS8619 *@
|
||||
<MudDateRangePicker DateRange="@dateRangePicker.ParseValue(this.assistantState.DateRanges[dateRangePicker.Name])"
|
||||
DateRangeChanged="@(value => this.assistantState.DateRanges[dateRangePicker.Name] = dateRangePicker.FormatValue(value))"
|
||||
Label="@dateRangePicker.Label"
|
||||
Color="@AssistantComponentPropHelper.GetColor(dateRangePicker.Color, Color.Primary)"
|
||||
PlaceholderStart="@dateRangePicker.PlaceholderStart"
|
||||
PlaceholderEnd="@dateRangePicker.PlaceholderEnd"
|
||||
HelperText="@dateRangePicker.HelperText"
|
||||
DateFormat="@format"
|
||||
PickerVariant="@AssistantComponentPropHelper.GetPickerVariant(dateRangePicker.PickerVariant, PickerVariant.Static)"
|
||||
Elevation="@dateRangePicker.Elevation"
|
||||
Variant="Variant.Outlined"
|
||||
Class='@MergeClass(dateRangePicker.Class, "mb-3")'
|
||||
Style="@GetOptionalStyle(dateRangePicker.Style)"
|
||||
/>
|
||||
@* ReSharper restore CSharpWarnings::CS8619 *@
|
||||
</MudPaper>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantComponentType.TIME_PICKER:
|
||||
if (component is AssistantTimePicker assistantTimePicker)
|
||||
{
|
||||
var timePicker = assistantTimePicker;
|
||||
var format = timePicker.GetTimeFormat();
|
||||
|
||||
<MudPaper Class="d-flex" Elevation="0">
|
||||
<MudTimePicker Time="@timePicker.ParseValue(this.assistantState.Times[timePicker.Name])"
|
||||
TimeChanged="@(value => this.assistantState.Times[timePicker.Name] = timePicker.FormatValue(value))"
|
||||
Label="@timePicker.Label"
|
||||
Color="@AssistantComponentPropHelper.GetColor(timePicker.Color, Color.Primary)"
|
||||
Placeholder="@timePicker.Placeholder"
|
||||
HelperText="@timePicker.HelperText"
|
||||
TimeFormat="@format"
|
||||
AmPm="@timePicker.AmPm"
|
||||
PickerVariant="@AssistantComponentPropHelper.GetPickerVariant(timePicker.PickerVariant, PickerVariant.Static)"
|
||||
Elevation="@timePicker.Elevation"
|
||||
Variant="Variant.Outlined"
|
||||
Class='@MergeClass(timePicker.Class, "mb-3")'
|
||||
Style="@GetOptionalStyle(timePicker.Style)"/>
|
||||
</MudPaper>
|
||||
}
|
||||
break;
|
||||
}
|
||||
</text>;
|
||||
|
||||
private string? BuildPaperStyle(AssistantPaper paper)
|
||||
{
|
||||
List<string> 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 = paper.Style;
|
||||
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<MudItem>(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 = 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<string> styles, string key, string value)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
styles.Add($"{key}: {value.Trim().TrimEnd(';')}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
using System.Text;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.PluginSystem.Assistants;
|
||||
using AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
||||
using Lua;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
namespace AIStudio.Assistants.Dynamic;
|
||||
|
||||
public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
|
||||
{
|
||||
[Parameter]
|
||||
public AssistantForm? RootComponent { get; set; }
|
||||
|
||||
protected override string Title => this.title;
|
||||
protected override string Description => this.description;
|
||||
protected override string SystemPrompt => this.systemPrompt;
|
||||
protected override bool AllowProfiles => this.allowProfiles;
|
||||
protected override bool ShowProfileSelection => this.showFooterProfileSelection;
|
||||
protected override string SubmitText => this.submitText;
|
||||
protected override Func<Task> SubmitAction => this.Submit;
|
||||
protected override bool SubmitDisabled => this.isSecurityBlocked;
|
||||
// Dynamic assistants do not have dedicated settings yet.
|
||||
// Reuse chat-level provider filtering/preselection instead of NONE.
|
||||
protected override Tools.Components Component => Tools.Components.CHAT;
|
||||
|
||||
private string title = string.Empty;
|
||||
private string description = string.Empty;
|
||||
private string systemPrompt = string.Empty;
|
||||
private bool allowProfiles = true;
|
||||
private string submitText = string.Empty;
|
||||
private bool showFooterProfileSelection = true;
|
||||
private PluginAssistants? assistantPlugin;
|
||||
|
||||
private readonly AssistantState assistantState = new();
|
||||
private readonly Dictionary<string, string> imageCache = new();
|
||||
private readonly HashSet<string> executingButtonActions = [];
|
||||
private readonly HashSet<string> executingSwitchActions = [];
|
||||
private string pluginPath = string.Empty;
|
||||
private PluginAssistantAudit? audit;
|
||||
private string securityMessage = string.Empty;
|
||||
private bool isSecurityBlocked;
|
||||
private const string ASSISTANT_QUERY_KEY = "assistantId";
|
||||
|
||||
#region Implementation of AssistantBase
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var pluginAssistant = this.ResolveAssistantPlugin();
|
||||
if (pluginAssistant is null)
|
||||
{
|
||||
this.Logger.LogWarning("AssistantDynamic could not resolve a registered assistant plugin.");
|
||||
base.OnInitialized();
|
||||
return;
|
||||
}
|
||||
|
||||
this.assistantPlugin = pluginAssistant;
|
||||
this.RootComponent = pluginAssistant.RootComponent;
|
||||
this.title = pluginAssistant.AssistantTitle;
|
||||
this.description = pluginAssistant.AssistantDescription;
|
||||
this.systemPrompt = pluginAssistant.SystemPrompt;
|
||||
this.submitText = pluginAssistant.SubmitText;
|
||||
this.allowProfiles = pluginAssistant.AllowProfiles;
|
||||
this.showFooterProfileSelection = !pluginAssistant.HasEmbeddedProfileSelection;
|
||||
this.pluginPath = pluginAssistant.PluginPath;
|
||||
var pluginHash = pluginAssistant.ComputeAuditHash();
|
||||
this.audit = this.SettingsManager.ConfigurationData.AssistantPluginAudits.FirstOrDefault(x => x.PluginId == pluginAssistant.Id && x.PluginHash == pluginHash);
|
||||
|
||||
var securityState = PluginAssistantSecurityResolver.Resolve(this.SettingsManager, pluginAssistant);
|
||||
if (!securityState.CanStartAssistant)
|
||||
{
|
||||
this.assistantPlugin = pluginAssistant;
|
||||
this.securityMessage = securityState.Description;
|
||||
this.isSecurityBlocked = true;
|
||||
base.OnInitialized();
|
||||
return;
|
||||
}
|
||||
|
||||
var rootComponent = this.RootComponent;
|
||||
if (rootComponent is not null)
|
||||
{
|
||||
this.InitializeComponentState(rootComponent.Children);
|
||||
}
|
||||
|
||||
base.OnInitialized();
|
||||
}
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
this.assistantState.Clear();
|
||||
|
||||
var rootComponent = this.RootComponent;
|
||||
if (rootComponent is not null)
|
||||
this.InitializeComponentState(rootComponent.Children);
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
// Dynamic assistants have arbitrary fields supplied via plugins, so there
|
||||
// isn't a built-in settings section to prefill values. Always return
|
||||
// false to keep the plugin-specified defaults.
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of dynamic plugin init
|
||||
|
||||
private PluginAssistants? ResolveAssistantPlugin()
|
||||
{
|
||||
var pluginAssistants = PluginFactory.RunningPlugins.OfType<PluginAssistants>()
|
||||
.Where(plugin => this.SettingsManager.IsPluginEnabled(plugin))
|
||||
.ToList();
|
||||
if (pluginAssistants.Count == 0)
|
||||
return null;
|
||||
|
||||
var requestedPluginId = this.TryGetAssistantIdFromQuery();
|
||||
if (requestedPluginId is not { } id) return pluginAssistants.First();
|
||||
|
||||
var requestedPlugin = pluginAssistants.FirstOrDefault(p => p.Id == id);
|
||||
return requestedPlugin ?? pluginAssistants.First();
|
||||
}
|
||||
|
||||
private Guid? TryGetAssistantIdFromQuery()
|
||||
{
|
||||
var uri = this.NavigationManager.ToAbsoluteUri(this.NavigationManager.Uri);
|
||||
if (string.IsNullOrWhiteSpace(uri.Query))
|
||||
return null;
|
||||
|
||||
var query = QueryHelpers.ParseQuery(uri.Query);
|
||||
if (!query.TryGetValue(ASSISTANT_QUERY_KEY, out var values))
|
||||
return null;
|
||||
|
||||
var value = values.FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return null;
|
||||
|
||||
if (Guid.TryParse(value, out var assistantId))
|
||||
return assistantId;
|
||||
|
||||
this.Logger.LogWarning("AssistantDynamic query parameter '{Parameter}' is not a valid GUID.", value);
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string ResolveImageSource(AssistantImage image)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(image.Src))
|
||||
return string.Empty;
|
||||
|
||||
if (this.imageCache.TryGetValue(image.Src, out var cached) && !string.IsNullOrWhiteSpace(cached))
|
||||
return cached;
|
||||
|
||||
var resolved = image.ResolveSource(this.pluginPath);
|
||||
this.imageCache[image.Src] = resolved;
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private async Task<string> CollectUserPromptAsync()
|
||||
{
|
||||
if (this.assistantPlugin?.HasCustomPromptBuilder != true) return this.CollectUserPromptFallback();
|
||||
|
||||
var input = this.BuildPromptInput();
|
||||
var prompt = await this.assistantPlugin.TryBuildPromptAsync(input, this.cancellationTokenSource?.Token ?? CancellationToken.None);
|
||||
return !string.IsNullOrWhiteSpace(prompt) ? prompt : this.CollectUserPromptFallback();
|
||||
}
|
||||
|
||||
private LuaTable BuildPromptInput()
|
||||
{
|
||||
var rootComponent = this.RootComponent;
|
||||
var state = rootComponent is not null
|
||||
? this.assistantState.ToLuaTable(rootComponent.Children)
|
||||
: new LuaTable();
|
||||
|
||||
var profile = new LuaTable
|
||||
{
|
||||
["Name"] = this.currentProfile.Name,
|
||||
["NeedToKnow"] = this.currentProfile.NeedToKnow,
|
||||
["Actions"] = this.currentProfile.Actions,
|
||||
["Num"] = this.currentProfile.Num,
|
||||
};
|
||||
|
||||
state["profile"] = profile;
|
||||
return state;
|
||||
}
|
||||
|
||||
private string CollectUserPromptFallback()
|
||||
{
|
||||
var prompt = string.Empty;
|
||||
var rootComponent = this.RootComponent;
|
||||
return rootComponent is null ? prompt : this.CollectUserPromptFallback(rootComponent.Children);
|
||||
}
|
||||
|
||||
private void InitializeComponentState(IEnumerable<IAssistantComponent> components)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is IStatefulAssistantComponent statefulComponent)
|
||||
statefulComponent.InitializeState(this.assistantState);
|
||||
|
||||
if (component.Children.Count > 0)
|
||||
this.InitializeComponentState(component.Children);
|
||||
}
|
||||
}
|
||||
|
||||
private static string MergeClass(string customClass, string fallback)
|
||||
{
|
||||
var trimmedCustom = customClass.Trim();
|
||||
var trimmedFallback = fallback.Trim();
|
||||
if (string.IsNullOrEmpty(trimmedCustom))
|
||||
return trimmedFallback;
|
||||
|
||||
return string.IsNullOrEmpty(trimmedFallback) ? trimmedCustom : $"{trimmedCustom} {trimmedFallback}";
|
||||
}
|
||||
|
||||
private static string GetOptionalStyle(string? style) => string.IsNullOrWhiteSpace(style) ? string.Empty : style;
|
||||
|
||||
private bool IsButtonActionRunning(string buttonName) => this.executingButtonActions.Contains(buttonName);
|
||||
private bool IsSwitchActionRunning(string switchName) => this.executingSwitchActions.Contains(switchName);
|
||||
|
||||
private async Task ExecuteButtonActionAsync(AssistantButton button)
|
||||
{
|
||||
if (this.assistantPlugin is null || button.Action is null || string.IsNullOrWhiteSpace(button.Name))
|
||||
return;
|
||||
|
||||
if (!this.executingButtonActions.Add(button.Name))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var input = this.BuildPromptInput();
|
||||
var cancellationToken = this.cancellationTokenSource?.Token ?? CancellationToken.None;
|
||||
var result = await this.assistantPlugin.TryInvokeButtonActionAsync(button, input, cancellationToken);
|
||||
if (result is not null)
|
||||
this.ApplyActionResult(result, AssistantComponentType.BUTTON);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.executingButtonActions.Remove(button.Name);
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteSwitchChangedAsync(AssistantSwitch switchComponent, bool value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(switchComponent.Name))
|
||||
return;
|
||||
|
||||
this.assistantState.Booleans[switchComponent.Name] = value;
|
||||
|
||||
if (this.assistantPlugin is null || switchComponent.OnChanged is null)
|
||||
{
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.executingSwitchActions.Add(switchComponent.Name))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var input = this.BuildPromptInput();
|
||||
var cancellationToken = this.cancellationTokenSource?.Token ?? CancellationToken.None;
|
||||
var result = await this.assistantPlugin.TryInvokeSwitchChangedAsync(switchComponent, input, cancellationToken);
|
||||
if (result is not null)
|
||||
this.ApplyActionResult(result, AssistantComponentType.SWITCH);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.executingSwitchActions.Remove(switchComponent.Name);
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyActionResult(LuaTable result, AssistantComponentType sourceType)
|
||||
{
|
||||
if (!result.TryGetValue("state", out var statesValue))
|
||||
return;
|
||||
|
||||
if (!statesValue.TryRead<LuaTable>(out var stateTable))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback returned a non-table 'state' value. The result is ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var component in stateTable)
|
||||
{
|
||||
if (!component.Key.TryRead<string>(out var componentName) || string.IsNullOrWhiteSpace(componentName))
|
||||
continue;
|
||||
|
||||
if (!component.Value.TryRead<LuaTable>(out var componentUpdate))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback returned a non-table update for '{componentName}'. The result is ignored.");
|
||||
continue;
|
||||
}
|
||||
|
||||
this.TryApplyComponentUpdate(componentName, componentUpdate, sourceType);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryApplyComponentUpdate(string componentName, LuaTable componentUpdate, AssistantComponentType sourceType)
|
||||
{
|
||||
if (componentUpdate.TryGetValue("Value", out var value))
|
||||
this.TryApplyFieldUpdate(componentName, value, sourceType);
|
||||
|
||||
if (!componentUpdate.TryGetValue("Props", out var propsValue))
|
||||
return;
|
||||
|
||||
if (!propsValue.TryRead<LuaTable>(out var propsTable))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback returned a non-table 'Props' value for '{componentName}'. The props update is ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
var rootComponent = this.RootComponent;
|
||||
if (rootComponent is null || !TryFindNamedComponent(rootComponent.Children, componentName, out var component))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback tried to update props of unknown component '{componentName}'. The props update is ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.ApplyPropUpdates(component, propsTable, sourceType);
|
||||
}
|
||||
|
||||
private void TryApplyFieldUpdate(string fieldName, LuaValue value, AssistantComponentType sourceType)
|
||||
{
|
||||
if (this.assistantState.TryApplyValue(fieldName, value, out var expectedType))
|
||||
return;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(expectedType))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback tried to write an invalid value to '{fieldName}'. Expected {expectedType}.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback tried to update unknown field '{fieldName}'. The value is ignored.");
|
||||
}
|
||||
|
||||
private void ApplyPropUpdates(IAssistantComponent component, LuaTable propsTable, AssistantComponentType sourceType)
|
||||
{
|
||||
var propSpec = ComponentPropSpecs.SPECS.GetValueOrDefault(component.Type);
|
||||
|
||||
foreach (var prop in propsTable)
|
||||
{
|
||||
if (!prop.Key.TryRead<string>(out var propName) || string.IsNullOrWhiteSpace(propName))
|
||||
continue;
|
||||
|
||||
if (propSpec is not null && propSpec.NonWriteable.Contains(propName, StringComparer.Ordinal))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback tried to update non-writeable prop '{propName}' on component '{GetComponentName(component)}'. The value is ignored.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AssistantLuaConversion.TryReadScalarOrStructuredValue(prop.Value, out var convertedValue))
|
||||
{
|
||||
this.Logger.LogWarning($"Assistant {sourceType} callback returned an unsupported value for prop '{propName}' on component '{GetComponentName(component)}'. The props update is ignored.");
|
||||
continue;
|
||||
}
|
||||
|
||||
component.Props[propName] = convertedValue;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryFindNamedComponent(IEnumerable<IAssistantComponent> components, string componentName, out IAssistantComponent component)
|
||||
{
|
||||
foreach (var candidate in components)
|
||||
{
|
||||
if (candidate is INamedAssistantComponent named && string.Equals(named.Name, componentName, StringComparison.Ordinal))
|
||||
{
|
||||
component = candidate;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (candidate.Children.Count > 0 && TryFindNamedComponent(candidate.Children, componentName, out component))
|
||||
return true;
|
||||
}
|
||||
|
||||
component = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GetComponentName(IAssistantComponent component) => component is INamedAssistantComponent named ? named.Name : component.Type.ToString();
|
||||
|
||||
private EventCallback<HashSet<string>> CreateMultiselectDropdownChangedCallback(string fieldName) =>
|
||||
EventCallback.Factory.Create<HashSet<string>>(this, values =>
|
||||
{
|
||||
this.assistantState.MultiSelect[fieldName] = values;
|
||||
});
|
||||
|
||||
private string? ValidateProfileSelection(AssistantProfileSelection profileSelection, Profile? profile)
|
||||
{
|
||||
if (profile != null && profile != Profile.NO_PROFILE) return null;
|
||||
return !string.IsNullOrWhiteSpace(profileSelection.ValidationMessage) ? profileSelection.ValidationMessage : this.T("Please select one of your profiles.");
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (this.assistantPlugin is not null)
|
||||
{
|
||||
var securityState = PluginAssistantSecurityResolver.Resolve(this.SettingsManager, this.assistantPlugin);
|
||||
if (!securityState.CanStartAssistant)
|
||||
return;
|
||||
}
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(await this.CollectUserPromptAsync());
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
|
||||
private string CollectUserPromptFallback(IEnumerable<IAssistantComponent> components)
|
||||
{
|
||||
var prompt = new StringBuilder();
|
||||
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is IStatefulAssistantComponent statefulComponent)
|
||||
prompt.Append(statefulComponent.UserPromptFallback(this.assistantState));
|
||||
|
||||
if (component.Children.Count > 0)
|
||||
{
|
||||
prompt.Append(this.CollectUserPromptFallback(component.Children));
|
||||
}
|
||||
}
|
||||
|
||||
return prompt.Append(Environment.NewLine).ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace AIStudio.Assistants.Dynamic;
|
||||
|
||||
public sealed class FileContentState
|
||||
{
|
||||
public string Content { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Assistants.Dynamic;
|
||||
|
||||
public sealed class WebContentState
|
||||
{
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public bool Preselect { get; set; }
|
||||
public bool PreselectContentCleanerAgent { get; set; }
|
||||
public bool AgentIsRunning { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user