Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
feat: Implement auto-linked content updates in wiki page management
wizardchenc5494f612b6f
diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vueindex 33f843860..104cf5e08 100644--- a/frontend/src/views/knowledge/KnowledgeBase.vue+++ b/frontend/src/views/knowledge/KnowledgeBase.vue@@ -69,12 +69,17 @@ const onWikiStatusChange = (payload: { pendingTasks: number; isActive: boolean;}let wikiStatusTimer: ReturnType<typeof setInterval> | null = null+let wikiStatusProbeTimers: Array<ReturnType<typeof setTimeout>> = []const stopWikiStatusPolling = () => {if (wikiStatusTimer) {clearInterval(wikiStatusTimer)wikiStatusTimer = null}}+const clearWikiStatusProbes = () => {+ wikiStatusProbeTimers.forEach(t => clearTimeout(t))+ wikiStatusProbeTimers = []+}const fetchWikiStatusOnce = async () => {if (!kbId.value || !isWiki.value) returntry {@@ -96,14 +101,31 @@ const fetchWikiStatusOnce = async () => {}} catch (_) { /* ignore */ }}+// 用户刚触发了一个上传 / reparse / URL 导入之类的动作后,后台通常要过+// 一小段时间才会把 wiki 任务真正塞进队列;如果这时空闲轮询刚好停了,+// 面包屑的"索引中"会延迟很久才亮起。所以这里安排几次退避重试,+// 主动把面包屑的 loading 尽快点亮,一旦探测到任务就会走正常的 5s 轮询。+const scheduleWikiStatusProbes = () => {+ if (!kbId.value || !isWiki.value) return+ clearWikiStatusProbes()+ const delays = [500, 2000, 5000, 10000]+ delays.forEach(delay => {+ const timer = setTimeout(() => { fetchWikiStatusOnce() }, delay)+ wikiStatusProbeTimers.push(timer)+ })+}watch([kbId, isWiki], ([newKbId, newIsWiki]) => {stopWikiStatusPolling()+ clearWikiStatusProbes()wikiStatus.value = { pendingTasks: 0, isActive: false, pendingIssues: 0 }if (newKbId && newIsWiki) {fetchWikiStatusOnce()}}, { immediate: true })-onUnmounted(stopWikiStatusPolling)+onUnmounted(() => {+ stopWikiStatusPolling()+ clearWikiStatusProbes()+})const missingStorageEngine = computed(() => {if (!kbInfo.value || isFAQ.value) return falseconst spc = kbInfo.value.storage_provider_config@@ -737,6 +759,8 @@ const handleFileUploaded = (event: CustomEvent) => {page = 1; // Reset page counter when reloading files after uploadloadKnowledgeFiles(uploadedKbId);loadTags(uploadedKbId);+ // 启动几次探测,尽快让面包屑的"索引中"亮起。+ scheduleWikiStatusProbes();}};@@ -1541,6 +1565,8 @@ const rebuildConfirm = async () => {MessagePlugin.success(t('knowledgeBase.rebuildSubmitted'));page = 1; // Reset page counter when reloading files after reparseloadKnowledgeFiles(kbId.value);+ // reparse 同样会触发 wiki 重入队,探测一下让面包屑尽快亮起。+ scheduleWikiStatusProbes();} catch (error: any) {MessagePlugin.error(error?.message || t('knowledgeBase.rebuildFailed'));}diff --git a/frontend/src/views/knowledge/wiki/WikiBrowser.vue b/frontend/src/views/knowledge/wiki/WikiBrowser.vueindex 19f539e85..ef5409139 100644--- a/frontend/src/views/knowledge/wiki/WikiBrowser.vue+++ b/frontend/src/views/knowledge/wiki/WikiBrowser.vue@@ -2140,6 +2140,27 @@ onUnmounted(() => {color: var(--td-text-color-primary);}+.wiki-reader-aliases {+ display: flex;+ align-items: center;+ flex-wrap: wrap;+ gap: 6px 8px;+ margin: 0 0 10px;+ font-size: 13px;+ line-height: 1.4;+}++.wiki-alias-label {+ color: var(--td-text-color-placeholder);+ font-size: 13px;+ line-height: 1.4;+}++.wiki-alias-tag {+ // Slight vertical nudge so the tag baseline lines up with the label.+ vertical-align: middle;+}+.wiki-reader-meta {display: flex;align-items: center;diff --git a/internal/application/repository/wiki_page.go b/internal/application/repository/wiki_page.goindex c5eef574a..f1686b8a4 100644--- a/internal/application/repository/wiki_page.go+++ b/internal/application/repository/wiki_page.go@@ -59,6 +59,30 @@ func (r *wikiPageRepository) Update(ctx context.Context, page *types.WikiPage) ereturn nil}+// UpdateAutoLinkedContent persists content changes produced by the automatic+// link decorators (cross-link injection, dead-link cleanup) without bumping+// `version`. These passes rewrite the same revision with wiki-link markup+// added or removed; treating them as real edits would make newly-ingested+// pages appear as v2 on first view and confuse users who expect `version` to+// correspond to the number of intentional revisions.+func (r *wikiPageRepository) UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error {+ result := r.db.WithContext(ctx).+ Model(page).+ Where("id = ?", page.ID).+ Updates(map[string]interface{}{+ "content": page.Content,+ "out_links": page.OutLinks,+ "updated_at": page.UpdatedAt,+ })+ if result.Error != nil {+ return result.Error+ }+ if result.RowsAffected == 0 {+ return ErrWikiPageNotFound+ }+ return nil+}+// UpdateMeta updates bookkeeping / provenance fields WITHOUT incrementing the// version number. "Content" for versioning purposes is the user-visible page// body (title/content/summary/page_type/status); everything else — links,diff --git a/internal/application/service/wiki_ingest.go b/internal/application/service/wiki_ingest.goindex 53b180346..f0d9027e9 100644--- a/internal/application/service/wiki_ingest.go+++ b/internal/application/service/wiki_ingest.go@@ -460,7 +460,7 @@ func (s *wikiIngestService) cleanDeadLinks(ctx context.Context, kbID string) {if changed {p.Content = content- if _, err := s.wikiService.UpdatePage(ctx, p); err != nil {+ if err := s.wikiService.UpdateAutoLinkedContent(ctx, p); err != nil {logger.Warnf(ctx, "wiki: failed to clean dead links in page %s: %v", p.Slug, err)} else {cleaned++@@ -509,7 +509,7 @@ func (s *wikiIngestService) injectCrossLinks(ctx context.Context, kbID string, acontinue}p.Content = newContent- if _, err := s.wikiService.UpdatePage(ctx, p); err != nil {+ if err := s.wikiService.UpdateAutoLinkedContent(ctx, p); err != nil {logger.Warnf(ctx, "wiki ingest: cross-link injection failed for %s: %v", p.Slug, err)continue}diff --git a/internal/application/service/wiki_lint.go b/internal/application/service/wiki_lint.goindex 273f309b0..b06a38b77 100644--- a/internal/application/service/wiki_lint.go+++ b/internal/application/service/wiki_lint.go@@ -339,7 +339,7 @@ func (s *WikiLintService) AutoFix(ctx context.Context, kbID string) (int, error)}target := issue.TargetSlugpage.Content = strings.ReplaceAll(page.Content, "[["+target+"]]", target)- if _, err := s.wikiService.UpdatePage(ctx, page); err == nil {+ if err := s.wikiService.UpdateAutoLinkedContent(ctx, page); err == nil {fixed++}diff --git a/internal/application/service/wiki_page.go b/internal/application/service/wiki_page.goindex 4f1e26189..20a4cd085 100644--- a/internal/application/service/wiki_page.go+++ b/internal/application/service/wiki_page.go@@ -144,6 +144,33 @@ func (s *wikiPageService) UpdatePageMeta(ctx context.Context, page *types.WikiPareturn s.repo.UpdateMeta(ctx, page)}+// UpdateAutoLinkedContent persists content produced by machine-only link+// decorators (cross-link injection / dead-link cleanup) without bumping+// `version`. Out-links are re-parsed from the new body and bidirectional+// in-link references on target pages are refreshed so link navigation stays+// consistent — only the user-facing revision counter is preserved.+func (s *wikiPageService) UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error {+ existing, err := s.repo.GetBySlug(ctx, page.KnowledgeBaseID, page.Slug)+ if err != nil {+ return fmt.Errorf("get existing page: %w", err)+ }++ oldOutLinks := existing.OutLinks++ existing.Content = page.Content+ existing.OutLinks = s.parseOutLinks(existing.Content)+ existing.UpdatedAt = time.Now()++ if err := s.repo.UpdateAutoLinkedContent(ctx, existing); err != nil {+ return fmt.Errorf("update auto-linked content: %w", err)+ }++ s.removeInLinks(ctx, existing.KnowledgeBaseID, existing.Slug, oldOutLinks)+ s.updateInLinks(ctx, existing.KnowledgeBaseID, existing.Slug, existing.OutLinks)++ return nil+}+// GetPageBySlug retrieves a wiki page by its slugfunc (s *wikiPageService) GetPageBySlug(ctx context.Context, kbID string, slug string) (*types.WikiPage, error) {return s.repo.GetBySlug(ctx, kbID, slug)@@ -573,7 +600,7 @@ func (s *wikiPageService) InjectCrossLinks(ctx context.Context, kbID string, affcontinue}p.Content = newContent- if _, err := s.UpdatePage(ctx, p); err != nil {+ if err := s.UpdateAutoLinkedContent(ctx, p); err != nil {logger.Warnf(ctx, "wiki: cross-link injection failed for %s: %v", p.Slug, err)continue}diff --git a/internal/types/interfaces/wiki_page.go b/internal/types/interfaces/wiki_page.goindex f2d3ad7c4..ca10dd68a 100644--- a/internal/types/interfaces/wiki_page.go+++ b/internal/types/interfaces/wiki_page.go@@ -27,6 +27,15 @@ type WikiPageService interface {// ref changes driven by internal reconciliation.UpdatePageMeta(ctx context.Context, page *types.WikiPage) error+ // UpdateAutoLinkedContent persists content changes that come from+ // machine-only link decoration — cross-link injection and dead-link+ // cleanup — without bumping `version`. Out-links are re-parsed from the+ // new body and bidirectional in-link references on target pages are+ // refreshed. Conceptually the body still represents the same revision+ // the user saw before, just with wiki-link markup added or stripped, so+ // surfacing a version bump to end users is misleading.+ UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error+// GetPageBySlug retrieves a wiki page by its slug within a knowledge base.GetPageBySlug(ctx context.Context, kbID string, slug string) (*types.WikiPage, error)@@ -103,6 +112,13 @@ type WikiPageRepository interface {// unchanged body, and status-only transitions.UpdateMeta(ctx context.Context, page *types.WikiPage) error+ // UpdateAutoLinkedContent rewrites `content`, `out_links` and+ // `updated_at` in place while leaving `version` untouched. Intended for+ // machine-only link markup changes (cross-link injection / dead-link+ // cleanup) so the first-ingest page doesn't jump to v2 just because the+ // post-processor added a `[[...]]` wrapper.+ UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error+// GetByID retrieves a wiki page by its unique ID.GetByID(ctx context.Context, id string) (*types.WikiPage, error)