feat: Introduce Wiki Fixer agent and related functionalities
- Added a new built-in agent, "Wiki Fixer," designed to repair and optimize Wiki pages based on linter issues, with multilingual support for enhanced accessibility. - Implemented a corresponding system prompt detailing the agent's role, mission, and workflow for effective issue resolution. - Introduced new API functions for listing and updating wiki issues, allowing for better management of content conflicts and errors. - Enhanced the frontend with new UI elements to display pending issues and facilitate auto-fixing, improving user interaction with the Wiki content. These changes significantly enhance the agent's capabilities for maintaining the accuracy and quality of Wiki pages, fostering a more reliable knowledge base.
This commit is contained in:
@@ -456,6 +456,18 @@ func (s *agentService) registerTools(
|
||||
toolToRegister = tools.NewWikiReadSourceDocTool(s.knowledgeService, s.chunkService)
|
||||
case tools.ToolWikiFlagIssue:
|
||||
toolToRegister = tools.NewWikiFlagIssueTool(s.wikiPageService, wikiKBIDs)
|
||||
case tools.ToolWikiReadIssue:
|
||||
toolToRegister = tools.NewWikiReadIssueTool(s.wikiPageService, wikiKBIDs)
|
||||
case tools.ToolWikiUpdateIssue:
|
||||
toolToRegister = tools.NewWikiUpdateIssueTool(s.wikiPageService, wikiKBIDs)
|
||||
case tools.ToolWikiWritePage:
|
||||
toolToRegister = tools.NewWikiWritePageTool(s.wikiPageService, wikiKBIDs)
|
||||
case tools.ToolWikiReplaceText:
|
||||
toolToRegister = tools.NewWikiReplaceTextTool(s.wikiPageService, wikiKBIDs)
|
||||
case tools.ToolWikiRenamePage:
|
||||
toolToRegister = tools.NewWikiRenamePageTool(s.wikiPageService, wikiKBIDs)
|
||||
case tools.ToolWikiDeletePage:
|
||||
toolToRegister = tools.NewWikiDeletePageTool(s.wikiPageService, wikiKBIDs)
|
||||
|
||||
default:
|
||||
logger.Warnf(ctx, "Unknown tool: %s", toolName)
|
||||
|
||||
@@ -91,13 +91,20 @@ func (s *sessionService) AgentQA(
|
||||
return fmt.Errorf("failed to get chat model: %w", err)
|
||||
}
|
||||
|
||||
// Get rerank model from custom agent config (only required when knowledge bases are configured)
|
||||
// Get rerank model from custom agent config (only required when knowledge_search is allowed)
|
||||
var rerankModel rerank.Reranker
|
||||
hasKnowledge := len(agentConfig.KnowledgeBases) > 0 || len(agentConfig.KnowledgeIDs) > 0
|
||||
if hasKnowledge {
|
||||
hasKnowledgeSearchTool := false
|
||||
for _, tool := range agentConfig.AllowedTools {
|
||||
if tool == tools.ToolKnowledgeSearch {
|
||||
hasKnowledgeSearchTool = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if hasKnowledgeSearchTool {
|
||||
rerankModelID := req.CustomAgent.Config.RerankModelID
|
||||
if rerankModelID == "" {
|
||||
logger.Warnf(ctx, "No rerank model configured for custom agent %s, but knowledge bases are specified", req.CustomAgent.ID)
|
||||
logger.Warnf(ctx, "No rerank model configured for custom agent %s, but knowledge_search tool is enabled", req.CustomAgent.ID)
|
||||
return errors.New("rerank model (rerank_model_id) is not configured in custom agent settings")
|
||||
}
|
||||
|
||||
@@ -107,7 +114,7 @@ func (s *sessionService) AgentQA(
|
||||
return fmt.Errorf("failed to get rerank model: %w", err)
|
||||
}
|
||||
} else {
|
||||
logger.Infof(ctx, "No knowledge bases configured, skipping rerank model initialization")
|
||||
logger.Infof(ctx, "knowledge_search tool not enabled, skipping rerank model initialization")
|
||||
}
|
||||
|
||||
// Get or create contextManager for this session
|
||||
@@ -225,6 +232,7 @@ func (s *sessionService) buildAgentConfig(
|
||||
// Falls back to global configuration if no specific timeout is set for the agent.
|
||||
if agentConfig.LLMCallTimeout == 0 && s.cfg.Agent != nil && s.cfg.Agent.LLMCallTimeout > 0 {
|
||||
agentConfig.LLMCallTimeout = s.cfg.Agent.LLMCallTimeout
|
||||
RetainRetrievalHistory: customAgent.Config.RetainRetrievalHistory,
|
||||
}
|
||||
|
||||
// Configure skills based on CustomAgentConfig
|
||||
|
||||
@@ -288,6 +288,7 @@ func (s *wikiPageService) GetStats(ctx context.Context, kbID string) (*types.Wik
|
||||
}
|
||||
|
||||
var pendingTasks int64
|
||||
var pendingIssues int64
|
||||
var isActive bool
|
||||
if s.redisClient != nil {
|
||||
pendingTasks, _ = s.redisClient.LLen(ctx, "wiki:pending:"+kbID).Result()
|
||||
@@ -295,6 +296,9 @@ func (s *wikiPageService) GetStats(ctx context.Context, kbID string) (*types.Wik
|
||||
isActive = activeFlag > 0
|
||||
}
|
||||
|
||||
issues, _ := s.ListIssues(ctx, kbID, "", "pending")
|
||||
pendingIssues = int64(len(issues))
|
||||
|
||||
return &types.WikiStats{
|
||||
TotalPages: total,
|
||||
PagesByType: counts,
|
||||
@@ -302,6 +306,7 @@ func (s *wikiPageService) GetStats(ctx context.Context, kbID string) (*types.Wik
|
||||
OrphanCount: orphans,
|
||||
RecentUpdates: recentPages,
|
||||
PendingTasks: pendingTasks,
|
||||
PendingIssues: pendingIssues,
|
||||
IsActive: isActive,
|
||||
}, nil
|
||||
}
|
||||
@@ -498,3 +503,165 @@ func (s *wikiPageService) ListIssues(ctx context.Context, kbID string, slug stri
|
||||
func (s *wikiPageService) UpdateIssueStatus(ctx context.Context, issueID string, status string) error {
|
||||
return s.repo.UpdateIssueStatus(ctx, issueID, status)
|
||||
}
|
||||
|
||||
// InjectCrossLinks scans affected pages and injects [[wiki-links]] for mentions
|
||||
// of other wiki page titles in the content. Pure text replacement, no LLM call.
|
||||
func (s *wikiPageService) InjectCrossLinks(ctx context.Context, kbID string, affectedSlugs []string) {
|
||||
// Build a title→slug lookup from ALL pages in this KB
|
||||
allPages, err := s.ListAllPages(ctx, kbID)
|
||||
if err != nil || len(allPages) < 2 {
|
||||
return
|
||||
}
|
||||
|
||||
type pageRef struct {
|
||||
slug string
|
||||
matchText string
|
||||
}
|
||||
var allRefs []pageRef
|
||||
for _, p := range allPages {
|
||||
if p.PageType == types.WikiPageTypeIndex || p.PageType == types.WikiPageTypeLog {
|
||||
continue
|
||||
}
|
||||
if p.Title != "" {
|
||||
allRefs = append(allRefs, pageRef{slug: p.Slug, matchText: p.Title})
|
||||
}
|
||||
for _, alias := range p.Aliases {
|
||||
if alias != "" {
|
||||
allRefs = append(allRefs, pageRef{slug: p.Slug, matchText: alias})
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(allRefs) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Sort by title length descending
|
||||
for i := 0; i < len(allRefs); i++ {
|
||||
for j := i + 1; j < len(allRefs); j++ {
|
||||
if len([]rune(allRefs[j].matchText)) > len([]rune(allRefs[i].matchText)) {
|
||||
allRefs[i], allRefs[j] = allRefs[j], allRefs[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
affectedSet := make(map[string]bool, len(affectedSlugs))
|
||||
for _, slug := range affectedSlugs {
|
||||
affectedSet[slug] = true
|
||||
}
|
||||
|
||||
var updated int
|
||||
for _, p := range allPages {
|
||||
if !affectedSet[p.Slug] {
|
||||
continue
|
||||
}
|
||||
if p.PageType == types.WikiPageTypeIndex || p.PageType == types.WikiPageTypeLog {
|
||||
continue
|
||||
}
|
||||
|
||||
content := p.Content
|
||||
changed := false
|
||||
|
||||
for _, ref := range allRefs {
|
||||
if ref.slug == p.Slug {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(content, "[["+ref.slug+"|") || strings.Contains(content, "[["+ref.slug+"]]") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(content, ref.matchText) {
|
||||
content = replaceFirstOutsideLinks(content, ref.matchText, "[["+ref.slug+"|"+ref.matchText+"]]")
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
if changed {
|
||||
p.Content = content
|
||||
if _, err := s.UpdatePage(ctx, p); err != nil {
|
||||
logger.Warnf(ctx, "wiki: cross-link injection failed for %s: %v", p.Slug, err)
|
||||
} else {
|
||||
updated++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if updated > 0 {
|
||||
logger.Infof(ctx, "wiki: injected cross-links in %d pages", updated)
|
||||
}
|
||||
}
|
||||
|
||||
// RebuildIndexPage regenerates the index page directory.
|
||||
func (s *wikiPageService) RebuildIndexPage(ctx context.Context, kbID string) error {
|
||||
indexPage, err := s.GetIndex(ctx, kbID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allPages, err := s.ListAllPages(ctx, kbID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
typeOrder := []string{
|
||||
types.WikiPageTypeSummary, types.WikiPageTypeEntity, types.WikiPageTypeConcept,
|
||||
types.WikiPageTypeSynthesis, types.WikiPageTypeComparison,
|
||||
}
|
||||
typeLabels := map[string]string{
|
||||
types.WikiPageTypeSummary: "Summary", types.WikiPageTypeEntity: "Entity",
|
||||
types.WikiPageTypeConcept: "Concept", types.WikiPageTypeSynthesis: "Synthesis",
|
||||
types.WikiPageTypeComparison: "Comparison",
|
||||
}
|
||||
|
||||
grouped := make(map[string][]*types.WikiPage)
|
||||
totalPages := 0
|
||||
for _, p := range allPages {
|
||||
if p.PageType == types.WikiPageTypeIndex || p.PageType == types.WikiPageTypeLog {
|
||||
continue
|
||||
}
|
||||
if p.Status == types.WikiPageStatusArchived {
|
||||
continue
|
||||
}
|
||||
grouped[p.PageType] = append(grouped[p.PageType], p)
|
||||
totalPages++
|
||||
}
|
||||
|
||||
var dir strings.Builder
|
||||
for _, pt := range typeOrder {
|
||||
pages := grouped[pt]
|
||||
if len(pages) == 0 {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(&dir, "\n## %s (%d)\n\n", typeLabels[pt], len(pages))
|
||||
for _, p := range pages {
|
||||
fmt.Fprintf(&dir, "[[%s]] — %s\n", p.Slug, p.Summary)
|
||||
}
|
||||
}
|
||||
for pt, pages := range grouped {
|
||||
inOrder := false
|
||||
for _, o := range typeOrder {
|
||||
if o == pt {
|
||||
inOrder = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if inOrder || len(pages) == 0 {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(&dir, "\n## %s (%d)\n\n", pt, len(pages))
|
||||
for _, p := range pages {
|
||||
fmt.Fprintf(&dir, "[[%s]] — %s\n", p.Slug, p.Summary)
|
||||
}
|
||||
}
|
||||
if totalPages == 0 {
|
||||
dir.WriteString("\n*No wiki pages yet. Upload documents to get started.*\n")
|
||||
}
|
||||
|
||||
intro := indexPage.Summary
|
||||
if intro == "" {
|
||||
intro = "# Wiki Index\n\nThis wiki contains knowledge extracted from uploaded documents.\n"
|
||||
indexPage.Summary = intro
|
||||
}
|
||||
|
||||
indexPage.Content = intro + "\n" + dir.String()
|
||||
_, err = s.UpdatePage(ctx, indexPage)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user