|
|
|
@@ -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);
|
|
|
|
|