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
|
@namespace NexusReader.UI.Shared.Components.Organisms
|
||||||
@inject HttpClient Http
|
@inject HttpClient Http
|
||||||
@inject IKnowledgeService KnowledgeService
|
@inject IKnowledgeService KnowledgeService
|
||||||
@inject AuthenticationStateProvider AuthStateProvider
|
|
||||||
@inject IReaderNavigationService NavigationService
|
@inject IReaderNavigationService NavigationService
|
||||||
|
|
||||||
<div class="global-intelligence-sheet @(IsOpen ? "is-open" : "")">
|
<div class="global-intelligence-sheet @(IsOpen ? "is-open" : "")">
|
||||||
@@ -169,8 +168,29 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@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 bool IsOpen { get; set; }
|
||||||
[Parameter] public EventCallback OnClose { get; set; }
|
[Parameter] public EventCallback OnClose { get; set; }
|
||||||
|
[Parameter] public string? TenantId { get; set; }
|
||||||
|
|
||||||
private string _question = string.Empty;
|
private string _question = string.Empty;
|
||||||
private bool _isLoading;
|
private bool _isLoading;
|
||||||
@@ -245,8 +265,7 @@
|
|||||||
ebookId = NavigationService.CurrentEbookId;
|
ebookId = NavigationService.CurrentEbookId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
var tenantId = TenantId ?? "global";
|
||||||
var tenantId = authState.User.FindFirst("TenantId")?.Value ?? "global";
|
|
||||||
|
|
||||||
var result = await KnowledgeService.AskQuestionAsync(userQuestion, tenantId, ebookId);
|
var result = await KnowledgeService.AskQuestionAsync(userQuestion, tenantId, ebookId);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
@@ -293,10 +312,7 @@
|
|||||||
var segments = new List<ResponseSegment>();
|
var segments = new List<ResponseSegment>();
|
||||||
if (string.IsNullOrEmpty(text)) return segments;
|
if (string.IsNullOrEmpty(text)) return segments;
|
||||||
|
|
||||||
var regex = new System.Text.RegularExpressions.Regex(
|
var matches = CitationRegex.Matches(text);
|
||||||
@"\[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);
|
|
||||||
|
|
||||||
int lastIndex = 0;
|
int lastIndex = 0;
|
||||||
foreach (System.Text.RegularExpressions.Match match in matches)
|
foreach (System.Text.RegularExpressions.Match match in matches)
|
||||||
@@ -340,10 +356,10 @@
|
|||||||
if (string.IsNullOrEmpty(text)) return new MarkupString(string.Empty);
|
if (string.IsNullOrEmpty(text)) return new MarkupString(string.Empty);
|
||||||
|
|
||||||
var html = System.Net.WebUtility.HtmlEncode(text);
|
var html = System.Net.WebUtility.HtmlEncode(text);
|
||||||
html = System.Text.RegularExpressions.Regex.Replace(html, @"\*\*(.*?)\*\*", "<strong>$1</strong>");
|
html = BoldRegex.Replace(html, "<strong>$1</strong>");
|
||||||
html = System.Text.RegularExpressions.Regex.Replace(html, @"\*(.*?)\*", "<em>$1</em>");
|
html = ItalicRegex.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 = CodeBlockRegex.Replace(html, "<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 = InlineCodeRegex.Replace(html, "<code class=\"nexus-mobile-inline-code\">$1</code>");
|
||||||
html = html.Replace("\n", "<br />");
|
html = html.Replace("\n", "<br />");
|
||||||
|
|
||||||
return new MarkupString(html);
|
return new MarkupString(html);
|
||||||
|
|||||||
@@ -233,7 +233,7 @@
|
|||||||
OnAssistantClick="OpenAssistant"
|
OnAssistantClick="OpenAssistant"
|
||||||
Checkpoints="@StateService.CurrentCheckpoints" />
|
Checkpoints="@StateService.CurrentCheckpoints" />
|
||||||
|
|
||||||
<GlobalIntelligence IsOpen="@_isAssistantOpen" OnClose="CloseAssistant" />
|
<GlobalIntelligence IsOpen="@_isAssistantOpen" OnClose="CloseAssistant" TenantId="@context.User.FindFirst("TenantId")?.Value" />
|
||||||
}
|
}
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<Authorizing>
|
<Authorizing>
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@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
|
#if DEBUG
|
||||||
private readonly bool _isDebug = true;
|
private readonly bool _isDebug = true;
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user