chore(beta-deploy): refactor GlobalIntelligence for AOT/Regex compliance and apply CSS polish
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
@namespace NexusReader.UI.Shared.Components.Organisms
|
||||
@inject HttpClient Http
|
||||
@inject IKnowledgeService KnowledgeService
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject IReaderNavigationService NavigationService
|
||||
|
||||
<div class="global-intelligence-sheet @(IsOpen ? "is-open" : "")">
|
||||
@@ -169,8 +168,29 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private static readonly System.Text.RegularExpressions.Regex CitationRegex = new(
|
||||
@"\[Source ID:\s*([^\]]+)\]|\[([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\]",
|
||||
System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
private static readonly System.Text.RegularExpressions.Regex BoldRegex = new(
|
||||
@"\*\*(.*?)\*\*",
|
||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
private static readonly System.Text.RegularExpressions.Regex ItalicRegex = new(
|
||||
@"\*(.*?)\*",
|
||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
private static readonly System.Text.RegularExpressions.Regex CodeBlockRegex = new(
|
||||
@"```(?:[a-zA-Z0-9+#]+)?\s*([\s\S]*?)\s*```",
|
||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
private static readonly System.Text.RegularExpressions.Regex InlineCodeRegex = new(
|
||||
@"`(.*?)`",
|
||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
[Parameter] public bool IsOpen { get; set; }
|
||||
[Parameter] public EventCallback OnClose { get; set; }
|
||||
[Parameter] public string? TenantId { get; set; }
|
||||
|
||||
private string _question = string.Empty;
|
||||
private bool _isLoading;
|
||||
@@ -245,8 +265,7 @@
|
||||
ebookId = NavigationService.CurrentEbookId;
|
||||
}
|
||||
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
var tenantId = authState.User.FindFirst("TenantId")?.Value ?? "global";
|
||||
var tenantId = TenantId ?? "global";
|
||||
|
||||
var result = await KnowledgeService.AskQuestionAsync(userQuestion, tenantId, ebookId);
|
||||
if (result.IsSuccess)
|
||||
@@ -293,10 +312,7 @@
|
||||
var segments = new List<ResponseSegment>();
|
||||
if (string.IsNullOrEmpty(text)) return segments;
|
||||
|
||||
var regex = new System.Text.RegularExpressions.Regex(
|
||||
@"\[Source ID:\s*([^\]]+)\]|\[([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\]",
|
||||
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
||||
var matches = regex.Matches(text);
|
||||
var matches = CitationRegex.Matches(text);
|
||||
|
||||
int lastIndex = 0;
|
||||
foreach (System.Text.RegularExpressions.Match match in matches)
|
||||
@@ -340,10 +356,10 @@
|
||||
if (string.IsNullOrEmpty(text)) return new MarkupString(string.Empty);
|
||||
|
||||
var html = System.Net.WebUtility.HtmlEncode(text);
|
||||
html = System.Text.RegularExpressions.Regex.Replace(html, @"\*\*(.*?)\*\*", "<strong>$1</strong>");
|
||||
html = System.Text.RegularExpressions.Regex.Replace(html, @"\*(.*?)\*", "<em>$1</em>");
|
||||
html = System.Text.RegularExpressions.Regex.Replace(html, @"```(?:[a-zA-Z0-9+#]+)?\s*([\s\S]*?)\s*```", "<pre class=\"nexus-mobile-code-block\"><code>$1</code></pre>");
|
||||
html = System.Text.RegularExpressions.Regex.Replace(html, @"`(.*?)`", "<code class=\"nexus-mobile-inline-code\">$1</code>");
|
||||
html = BoldRegex.Replace(html, "<strong>$1</strong>");
|
||||
html = ItalicRegex.Replace(html, "<em>$1</em>");
|
||||
html = CodeBlockRegex.Replace(html, "<pre class=\"nexus-mobile-code-block\"><code>$1</code></pre>");
|
||||
html = InlineCodeRegex.Replace(html, "<code class=\"nexus-mobile-inline-code\">$1</code>");
|
||||
html = html.Replace("\n", "<br />");
|
||||
|
||||
return new MarkupString(html);
|
||||
|
||||
@@ -233,7 +233,7 @@
|
||||
OnAssistantClick="OpenAssistant"
|
||||
Checkpoints="@StateService.CurrentCheckpoints" />
|
||||
|
||||
<GlobalIntelligence IsOpen="@_isAssistantOpen" OnClose="CloseAssistant" />
|
||||
<GlobalIntelligence IsOpen="@_isAssistantOpen" OnClose="CloseAssistant" TenantId="@context.User.FindFirst("TenantId")?.Value" />
|
||||
}
|
||||
</Authorized>
|
||||
<Authorizing>
|
||||
|
||||
@@ -101,6 +101,8 @@ else
|
||||
}
|
||||
|
||||
@code {
|
||||
// Compile-time check ensures _isDebug is baked as false in Release/Test/Production builds,
|
||||
// which completely bypasses/strips rendering of the diagnostic UI and avoids exposing internal controls.
|
||||
#if DEBUG
|
||||
private readonly bool _isDebug = true;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user