feat(knowledge): enhance activity logging for FAQ imports

- Added new actions for FAQ import lifecycle: `faq.import_started`, `faq.import_completed`, and `faq.import_failed`.
- Updated activity details to include success, failure, and skipped counts for FAQ imports.
- Enhanced UI to display additional activity information, including filtering options and clearer summaries.
- Implemented tests to validate the new FAQ import outcomes and activity details.

This commit improves the tracking and visibility of FAQ import activities within the knowledge base, ensuring better audit trails and user feedback.
This commit is contained in:
wizardchen
2026-07-22 20:08:31 +08:00
committed by lyingbug
parent a3a0308b62
commit 5af8eae81d
14 changed files with 650 additions and 100 deletions
+43 -1
View File
@@ -3,12 +3,16 @@ package service
import (
"context"
"encoding/json"
"strings"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
)
const auditScopeKnowledgeBase = "knowledge_base"
const (
auditScopeKnowledgeBase = "knowledge_base"
kbActivitySampleTitleLimit = 5
)
type kbActivityTaskMetadata struct {
TaskID string
@@ -39,6 +43,44 @@ func kbActivityTrigger(ctx context.Context) string {
return "system"
}
// kbActivityAppendSampleTitles adds a bounded, human-readable preview of batch
// mutations into activity details. The first sample is also mirrored as title so
// list views can show what was affected without opening the drawer.
func kbActivityAppendSampleTitles(details map[string]any, titles ...string) {
if details == nil {
return
}
samples := make([]string, 0, kbActivitySampleTitleLimit)
seen := make(map[string]struct{}, kbActivitySampleTitleLimit)
appendSample := func(title string) {
title = strings.TrimSpace(title)
if title == "" {
return
}
if _, ok := seen[title]; ok {
return
}
if len(samples) >= kbActivitySampleTitleLimit {
return
}
seen[title] = struct{}{}
samples = append(samples, title)
}
if existing, ok := details["title"].(string); ok {
appendSample(existing)
}
for _, title := range titles {
appendSample(title)
}
if len(samples) == 0 {
return
}
details["title"] = samples[0]
if len(samples) > 1 {
details["titles"] = samples
}
}
// withKBActivitySuppressed is used for high-volume child mutations inside a
// composite task. The task's bounded summary event remains visible, while one
// sync run cannot flood the audit table with thousands of per-item rows.