feat(search/rag): implement NexusSearchBox, dynamic Qdrant collection auto-provisioning, batch vector ingestion, mobile Serilog logging, and resolve 401 auth handler error (#51)
Resolves #52 This Pull Request introduces the **NexusSearchBox** search feature with premium unified styling, implements a robust **dynamic Qdrant collection auto-provisioning and batch-vector ingestion pipeline**, integrates a unified **Serilog logging infrastructure** for the Blazor Hybrid environment (MAUI), and resolves the **401 Unauthorized API header propagation error** inside mobile builds. ### 🚀 Key Implementations #### 1. Premium `NexusSearchBox` & Semantic Search UI * **NexusSearchBox Component:** Created an elegant search-as-you-type search box with smooth key navigation, quick-clearing, and seamless dynamic styling. * **Unified Aesthetics:** Refactored the search box isolated styling to align perfectly with the dashboard's design system using glassmorphism, `--nexus-neon` token gradients, and smooth pulse/fade animations. * **Semantic Search Integration:** Integrated semantic search query dispatching (`SearchLibrarySemanticallyQuery`) and wired up navigation seamlessly through the updated `ReaderNavigationService`. * **Tests Hardening:** Added/adapted query assertions in `QueryTests.cs` to guarantee safe parameterization and error boundary mapping. #### 2. Qdrant Collection Provisioning & Vector Ingestion * **Dynamic Auto-Provisioning:** Implemented dynamic checking and lazy-creation of the `knowledge_units` collection using 768 dimensions and Cosine distance. * **High-Performance Ingestion:** Optimized `ProcessKnowledgeUnitsAsync` with high-performance batch embedding generation using `_embeddingGenerator` and deterministic MD5 GUIDs for stable, duplicate-free upsertion. * **Database Cache Clear Sync:** Integrated Qdrant collection deletion in `ClearCacheAsync` to ensure absolute consistency between the PostgreSQL database cache and vector database indices. #### 3. Cross-Platform MAUI Logging (Serilog Infrastructure) * **Serilog Integration:** Configured cross-platform Serilog routing in `SerilogConfiguration.cs`, streaming diagnostic logs safely across native platforms and the Blazor Webview container. * **Interop Bridge:** Built `BlazorLoggingBridge.cs` to capture web console messages and pipe them directly to the native host logger. * **Demo Interface:** Added an interactive `SerilogDemo.razor` sandbox under Pages. #### 4. Resolving 401 Load Errors (Authentication Handler Flow) * **Authentication Header Handler:** Implemented the `MobileAuthenticationHeaderHandler` to correctly extract, validate, and inject bearer JWT tokens into outbound API requests. * **Configuration-based API Host:** Structured standard API URI routing to use clean configuration bindings in `appsettings.json`. --- ### 🧪 Verification & Build Status * Run `dotnet build` from the solution root: Successfully compiled the full multi-targeted solution (`Liczba błędów: 0`). * All unit and integration tests successfully executed and verified (`dotnet test`). --------- Co-authored-by: Marek Jasiński <jasins.marek@gmail.com> Co-authored-by: Marek Jaisński <jasins.marek@gmail.com> Reviewed-on: #51 Co-authored-by: Antigravity <antigravity@google.com> Co-committed-by: Antigravity <antigravity@google.com>
This commit was merged in pull request #51.
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
@using NexusReader.Application.Abstractions.Services
|
||||
@using NexusReader.Application.Queries.Reader
|
||||
@using NexusReader.Application.Commands.Library
|
||||
@using NexusReader.UI.Shared.Services
|
||||
@using System.Net.Http.Json
|
||||
@inject IEpubMetadataExtractor MetadataExtractor
|
||||
@inject ILogger<BookIngestionModal> Logger
|
||||
@inject HttpClient Http
|
||||
@inject IReaderNavigationService ReaderNavigation
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISyncService SyncService
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@if (IsOpen)
|
||||
@@ -16,20 +18,23 @@
|
||||
<div class="modal-content glass-panel" @onclick:stopPropagation>
|
||||
<div class="modal-header">
|
||||
<h2>Add New Book</h2>
|
||||
<button class="close-btn" @onclick="CloseModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
@if (!IsIngesting && !IsIndexing)
|
||||
{
|
||||
<button class="close-btn" @onclick="CloseModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="parsing-state shimmer" style="@(IsParsing ? "display:flex;" : "display:none;")">
|
||||
<div class="parsing-state shimmer" style="@(IsParsing && !IsIndexing ? "display:flex;" : "display:none;")">
|
||||
<div class="shimmer-content">
|
||||
<div class="spinner"></div>
|
||||
<p>Scanning metadata...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="verification-state" style="@(IsVerifying && !IsParsing ? "display:flex;" : "display:none;")">
|
||||
<div class="verification-state" style="@(IsVerifying && !IsParsing && !IsIndexing ? "display:flex;" : "display:none;")">
|
||||
@if (Metadata != null)
|
||||
{
|
||||
<div class="verification-layout">
|
||||
@@ -74,7 +79,7 @@
|
||||
</div>
|
||||
|
||||
<div class="upload-state @(_isDragging ? "drag-over" : "")"
|
||||
style="@(!IsParsing && !IsVerifying ? "display:flex;" : "display:none;")"
|
||||
style="@(!IsParsing && !IsVerifying && !IsIndexing ? "display:flex;" : "display:none;")"
|
||||
@ondragenter="OnDragEnter"
|
||||
@ondragleave="OnDragLeave">
|
||||
<div class="drop-zone">
|
||||
@@ -87,6 +92,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="indexing-state" style="@(IsIndexing ? "display:flex;" : "display:none;")">
|
||||
<div class="indexing-content">
|
||||
<div class="spinner"></div>
|
||||
<h3>Nexus AI Indexing</h3>
|
||||
<p class="status-msg">@IngestionStatusMessage</p>
|
||||
<div class="progress-bar-container">
|
||||
<div class="progress-bar-fill" style="width: @((IngestionProgressPercent * 100).ToString("F0"))%"></div>
|
||||
</div>
|
||||
<span class="percent">@((IngestionProgressPercent * 100).ToString("F0"))%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if (!string.IsNullOrEmpty(ErrorMessage))
|
||||
{
|
||||
@@ -118,15 +135,61 @@
|
||||
private bool IsParsing { get; set; }
|
||||
private bool IsVerifying { get; set; }
|
||||
private bool IsIngesting { get; set; }
|
||||
private bool IsIndexing { get; set; }
|
||||
private string IngestionStatusMessage { get; set; } = "Initializing...";
|
||||
private double IngestionProgressPercent { get; set; }
|
||||
private Guid IngestedBookId { get; set; } = Guid.Empty;
|
||||
private LocalEpubMetadata? Metadata { get; set; }
|
||||
private string? ErrorMessage { get; set; }
|
||||
private byte[]? _epubBytes;
|
||||
private bool _disposed;
|
||||
|
||||
// Allow up to 50 MB
|
||||
private const long MaxFileSize = 50 * 1024 * 1024;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await SyncService.InitializeAsync();
|
||||
SyncService.OnIngestionProgressReceived += HandleIngestionProgress;
|
||||
}
|
||||
|
||||
private async Task HandleIngestionProgress(string message, double progress)
|
||||
{
|
||||
if (_disposed) return;
|
||||
if (!IsIndexing) return;
|
||||
|
||||
IngestionStatusMessage = message;
|
||||
IngestionProgressPercent = progress;
|
||||
|
||||
if (!_disposed)
|
||||
{
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
if (progress >= 1.0)
|
||||
{
|
||||
// Give the user a moment to see the completion message
|
||||
await Task.Delay(2500);
|
||||
|
||||
if (_disposed) return;
|
||||
|
||||
// Now close the modal and navigate to the book
|
||||
if (IngestedBookId != Guid.Empty)
|
||||
{
|
||||
var bookId = IngestedBookId;
|
||||
await InvokeAsync(async () => {
|
||||
if (_disposed) return;
|
||||
await CloseModal();
|
||||
ReaderNavigation.NavigateToBook(bookId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CloseModal()
|
||||
{
|
||||
if (IsIngesting || IsIndexing) return;
|
||||
|
||||
IsOpen = false;
|
||||
Reset();
|
||||
await IsOpenChanged.InvokeAsync(false);
|
||||
@@ -137,6 +200,10 @@
|
||||
IsParsing = false;
|
||||
IsVerifying = false;
|
||||
IsIngesting = false;
|
||||
IsIndexing = false;
|
||||
IngestionStatusMessage = "Initializing...";
|
||||
IngestionProgressPercent = 0.0;
|
||||
IngestedBookId = Guid.Empty;
|
||||
Metadata = null;
|
||||
ErrorMessage = null;
|
||||
_isDragging = false;
|
||||
@@ -168,10 +235,12 @@
|
||||
using var stream = file.OpenReadStream(MaxFileSize);
|
||||
using var memoryStream = new MemoryStream();
|
||||
await stream.CopyToAsync(memoryStream);
|
||||
if (_disposed) return;
|
||||
_epubBytes = memoryStream.ToArray();
|
||||
|
||||
memoryStream.Position = 0;
|
||||
var result = await MetadataExtractor.ExtractMetadataAsync(memoryStream);
|
||||
if (_disposed) return;
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
@@ -186,12 +255,18 @@
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error uploading EPUB");
|
||||
ErrorMessage = $"An unexpected error occurred: {ex.Message}";
|
||||
if (!_disposed)
|
||||
{
|
||||
ErrorMessage = $"An unexpected error occurred: {ex.Message}";
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParsing = false;
|
||||
StateHasChanged();
|
||||
if (!_disposed)
|
||||
{
|
||||
IsParsing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,39 +289,55 @@
|
||||
);
|
||||
|
||||
var response = await Http.PostAsJsonAsync("api/library/ingest", request);
|
||||
if (_disposed) return;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var result = await response.Content.ReadFromJsonAsync<IngestResult>();
|
||||
if (_disposed) return;
|
||||
if (result != null)
|
||||
{
|
||||
await CloseModal();
|
||||
ReaderNavigation.NavigateToBook(result.Id);
|
||||
IngestedBookId = result.Id;
|
||||
IsVerifying = false;
|
||||
IsIngesting = false;
|
||||
IsIndexing = true;
|
||||
IngestionStatusMessage = "Book saved! Starting background indexing...";
|
||||
IngestionProgressPercent = 0.0;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = await response.Content.ReadAsStringAsync();
|
||||
IsIngesting = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error during ingestion");
|
||||
ErrorMessage = "Failed to save book to library. Please try again.";
|
||||
if (!_disposed)
|
||||
{
|
||||
ErrorMessage = "Failed to save book to library. Please try again.";
|
||||
IsIngesting = false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsIngesting = false;
|
||||
StateHasChanged();
|
||||
if (!_disposed)
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record IngestResult(Guid Id);
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
_disposed = true;
|
||||
SyncService.OnIngestionProgressReceived -= HandleIngestionProgress;
|
||||
// Clear the large byte array so it is eligible for GC even if the component is cached.
|
||||
_epubBytes = null;
|
||||
return ValueTask.CompletedTask;
|
||||
await ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user