add: gitea tools

This commit is contained in:
h z
2025-05-08 01:14:41 +01:00
parent a97c71caaf
commit 7f81caf1fb

View File

@@ -3,6 +3,7 @@
@rendermode InteractiveServer
@inject IChatSessionService ChatSessionService
@inject NavigationManager NavigationManager
@inject IJSRuntime JSRuntime
@using Alchegos.HCI.Models
@using Alchegos.HCI.Services
@implements IAsyncDisposable
@@ -15,7 +16,10 @@
<input @bind="currentSessionIdInput" placeholder="Enter or Generate Session ID" />
<button @onclick="LoadSession" disabled="@isLoading">Load / Start Session</button>
<button @onclick="GenerateSessionId" disabled="@isLoading">Generate New ID</button>
<input @bind="externalWebhookUrl" placeholder="Server url">
<input @bind="externalWebhookUrl"
@bind:event="oninput"
@onchange="SaveWebhookUrlToLocalStorage"
placeholder="Server url">
@if (!string.IsNullOrEmpty(activeSessionId))
{
<span>Active Session: @activeSessionId</span>
@@ -64,10 +68,26 @@ else if (sessionLoadAttempted)
private bool isLoading = false;
private bool sessionLoadAttempted = false;
private string externalWebhookUrl { get; set; } = string.Empty;
private const string WebhookUrlStorageKey = "chatPage_externalWebhookUrl";
private bool _hasLoadedFromLocalStorage = false;
private string? _previousSessionId = null;
protected override void OnInitialized()
{
if (!string.IsNullOrEmpty(InitialSessionId))
currentSessionIdInput = InitialSessionId;
}
/*protected override async Task OnInitializedAsync()
{
Console.WriteLine("--- OnInitializedAsync START ---");
externalWebhookUrl = await JSRuntime.InvokeAsync<string>("localStorage.getItem", WebhookUrlStorageKey) ?? string.Empty;
Console.WriteLine($"Loaded externalWebhookUrl from localStorage: '{externalWebhookUrl}'");
if (!string.IsNullOrEmpty(InitialSessionId))
currentSessionIdInput = InitialSessionId;
Console.WriteLine("--- OnInitializedAsync END ---");
}*/
protected override async Task OnParametersSetAsync()
{
Console.WriteLine($"--- OnParametersSetAsync START. InitialSessionId: {InitialSessionId} ---");
@@ -97,8 +117,6 @@ else if (sessionLoadAttempted)
}
else
Console.WriteLine("!!! Failed to get/create session in OnParametersSetAsync!");
isLoading = false;
Console.WriteLine("--- OnParametersSetAsync END. isLoading set to false ---");
@@ -124,16 +142,39 @@ else if (sessionLoadAttempted)
}
}
protected override void OnInitialized()
{
if (!string.IsNullOrEmpty(InitialSessionId))
currentSessionIdInput = InitialSessionId;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && !string.IsNullOrEmpty(activeSessionId))
if (firstRender && !string.IsNullOrEmpty(activeSessionId) && !_hasLoadedFromLocalStorage)
{
await RegisterCallbacksAsync();
try
{
externalWebhookUrl = await JSRuntime.InvokeAsync<string>("localStorage.getItem", WebhookUrlStorageKey) ?? string.Empty;
Console.WriteLine($"Loaded externalWebhookUrl from localStorage: '{externalWebhookUrl}'");
_hasLoadedFromLocalStorage = true;
StateHasChanged();
}
catch (Exception ex)
{
Console.WriteLine($"Error loading from localStorage in OnAfterRenderAsync: {ex.Message}");
}
await base.OnAfterRenderAsync(firstRender);
}
}
private async Task SaveWebhookUrlToLocalStorage()
{
try
{
await JSRuntime.InvokeVoidAsync("localStorage.setItem", WebhookUrlStorageKey, externalWebhookUrl);
}
catch (Exception ex)
{
Console.WriteLine($"Error saving to localStorage: {ex.Message}");
}
}