Heimdall Gitea / Build and tests (pull_request) Failing after 2m10s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
125 lines
4.8 KiB
Plaintext
125 lines
4.8 KiB
Plaintext
@namespace Heimdall.Web.Components.Settings
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
@inject Heimdall.Web.Services.UiText Text
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
|
|
<div class="d-flex align-center mb-3">
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
|
<i class="fas fa-brain mr-2"></i> @Text["AiSettingsSection_Title"]
|
|
</MudText>
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">@Text["AiSettingsSection_Detection"]</MudChip>
|
|
</div>
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
|
@Text["AiSettingsSection_Description"]
|
|
</MudText>
|
|
|
|
<MudGrid>
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="@Text["AiSettingsSection_CpaiUrl"]" Variant="Variant.Outlined"
|
|
Value="@GetValue("ai.cpaiurl")"
|
|
ValueChanged="OnCpaiUrlChanged"
|
|
HelperText="@Text["AiSettingsSection_CpaiHelp"]" />
|
|
</MudItem>
|
|
<MudItem xs="12" md="6">
|
|
<MudTextField T="string" Label="@Text["AiSettingsSection_OllamaUrl"]" Variant="Variant.Outlined"
|
|
Value="@GetValue("ai.ollamaurl")"
|
|
ValueChanged="OnOllamaUrlChanged"
|
|
HelperText="@Text["AiSettingsSection_OllamaHelp"]" />
|
|
</MudItem>
|
|
<MudItem xs="12">
|
|
<MudSwitch T="bool"
|
|
Value="@(GetValue("ai.detection.enabled")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
|
|
ValueChanged="OnDetectionEnabledChanged"
|
|
Color="Color.Primary"
|
|
Label="@Text["AiSettingsSection_Enabled"]"
|
|
HelperText="@Text["AiSettingsSection_EnabledHelp"]" />
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
<div class="d-flex align-center mt-3">
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Radar"
|
|
OnClick="TestAiAsync" Disabled="@_testing">
|
|
@(_testing ? Text["AiSettingsSection_Testing"] : Text["AiSettingsSection_Test"])
|
|
</MudButton>
|
|
</div>
|
|
@if (_testResult is not null)
|
|
{
|
|
<MudAlert Severity="@(_testResult.Success ? Severity.Success : Severity.Warning)" Class="mt-3" Variant="Variant.Outlined">
|
|
<strong>@_testResult.Status</strong> — @_testResult.Message
|
|
</MudAlert>
|
|
}
|
|
</MudPaper>
|
|
|
|
@code {
|
|
private List<AppSettingItem> _settings = [];
|
|
private bool _testing;
|
|
private TestActionResult? _testResult;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_settings = await Api.GetSettingsAsync();
|
|
}
|
|
catch
|
|
{
|
|
_settings = [];
|
|
}
|
|
}
|
|
|
|
private string? GetValue(string key)
|
|
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
|
|
|
|
private Task OnCpaiUrlChanged(string v) => SaveValueAsync("ai.cpaiurl", v);
|
|
private Task OnOllamaUrlChanged(string v) => SaveValueAsync("ai.ollamaurl", v);
|
|
private Task OnDetectionEnabledChanged(bool v) => SaveValueAsync("ai.detection.enabled", v ? "true" : "false");
|
|
|
|
private async Task TestAiAsync()
|
|
{
|
|
_testing = true;
|
|
_testResult = null;
|
|
try
|
|
{
|
|
_testResult = await Api.TestAiAsync() ?? new TestActionResult(false, Text["AiSettingsSection_TestUnavailable"]);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_testResult = new TestActionResult(false, string.Format(Text["AiSettingsSection_TestFailed"], ex.Message));
|
|
}
|
|
finally
|
|
{
|
|
_testing = false;
|
|
}
|
|
}
|
|
|
|
private async Task SaveValueAsync(string key, string? value)
|
|
{
|
|
value ??= string.Empty;
|
|
var existing = _settings.FirstOrDefault(s => s.Key == key);
|
|
try
|
|
{
|
|
if (existing is null)
|
|
{
|
|
await Api.CreateSettingAsync(new CreateAppSettingRequest(
|
|
Key: key, Value: value,
|
|
Category: "ai",
|
|
Description: key, ValueType: "string", AllowedValues: null, AgentScoped: true));
|
|
}
|
|
else
|
|
{
|
|
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
|
|
Value: value, Description: existing.Description ?? key,
|
|
Category: "ai", ValueType: "string", AllowedValues: null, AgentScoped: null));
|
|
}
|
|
_settings = await Api.GetSettingsAsync();
|
|
Snackbar.Add(string.Format(Text["AiSettingsSection_SettingUpdated"], key), Severity.Success);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add(string.Format(Text["AiSettingsSection_SettingUpdateFailed"], ex.Message), Severity.Error);
|
|
}
|
|
}
|
|
}
|