feat: implement dynamic knowledge graph updates and state management services

This commit is contained in:
2026-04-26 14:53:48 +02:00
parent 412320980f
commit 7859c9806f
30 changed files with 668 additions and 153 deletions
@@ -6,4 +6,5 @@ namespace NexusReader.Application.Abstractions.Services;
public interface IKnowledgeService
{
Task<Result<KnowledgePacket>> GetKnowledgeAsync(string text, CancellationToken cancellationToken = default);
Task<Result> ClearCacheAsync(CancellationToken cancellationToken = default);
}
@@ -13,7 +13,9 @@ public record QuizQuestion(
[property: JsonPropertyName("correct_index")] int CorrectIndex
);
public record KnowledgePacket(
[property: JsonPropertyName("concepts")] List<KeyConcept> Concepts,
[property: JsonPropertyName("quizzes")] List<QuizQuestion> Quizzes
);
public record KnowledgePacket
{
[JsonPropertyName("concepts")] public List<KeyConcept> Concepts { get; init; } = new();
[JsonPropertyName("quizzes")] public List<QuizQuestion> Quizzes { get; init; } = new();
[JsonPropertyName("graph")] public NexusReader.Application.Queries.Graph.GraphDataDto? Graph { get; init; }
}
@@ -7,24 +7,9 @@ internal sealed class GetKnowledgeGraphQueryHandler : IQueryHandler<GetKnowledge
{
public Task<Result<GraphDataDto>> Handle(GetKnowledgeGraphQuery request, CancellationToken cancellationToken)
{
var nodes = new List<GraphNodeDto>
{
new("renesans-intro", "Renesans", "Concept"),
new("florencja", "Florencja", "Location"),
new("medyceusze", "Medyceusze", "Entity"),
new("da-vinci-ai", "Leonardo da Vinci", "Person"),
new("humanizm", "Humanizm", "Concept")
};
var nodes = new List<GraphNodeDto>();
var links = new List<GraphLinkDto>();
var links = new List<GraphLinkDto>
{
new("renesans-intro", "florencja", 1),
new("florencja", "medyceusze", 2),
new("medyceusze", "da-vinci-ai", 3),
new("renesans-intro", "humanizm", 1),
new("da-vinci-ai", "humanizm", 2)
};
return Task.FromResult(Result.Ok(new GraphDataDto(nodes, links)));
return Task.FromResult(Result.Ok(new GraphDataDto { Nodes = nodes, Links = links }));
}
}
@@ -2,4 +2,8 @@ namespace NexusReader.Application.Queries.Graph;
public record GraphNodeDto(string Id, string Label, string Group);
public record GraphLinkDto(string Source, string Target, int Value);
public record GraphDataDto(List<GraphNodeDto> Nodes, List<GraphLinkDto> Links);
public record GraphDataDto
{
public List<GraphNodeDto> Nodes { get; init; } = new();
public List<GraphLinkDto> Links { get; init; } = new();
}